diff options
author | Roman Stratiienko <roman.o.stratiienko@globallogic.com> | 2021-09-29 13:00:29 +0300 |
---|---|---|
committer | Roman Stratiienko <roman.o.stratiienko@globallogic.com> | 2021-09-29 13:00:29 +0300 |
commit | 863a3c207e73001ab5f4ee84c71d21c8fcb8086c (patch) | |
tree | 74bc1d4b8c0c42e129a29b3513ace8689cebc993 /compositor/DrmDisplayCompositor.cpp | |
parent | 24a4c180c2844c74ff6f17dfc91680783f373a07 (diff) | |
download | drm-hwcomposer-863a3c207e73001ab5f4ee84c71d21c8fcb8086c.tar.gz drm-hwcomposer-863a3c207e73001ab5f4ee84c71d21c8fcb8086c.tar.bz2 drm-hwcomposer-863a3c207e73001ab5f4ee84c71d21c8fcb8086c.zip |
drm_hwcomposer: Handle all HWC2 callbacks in DrmHwcTwo.{h,cpp}
Part of frontend isolation activities.
1. Use HWC2 HAL types only inside DrmHwcTwo.{h,cpp}.
2. Use single lock for all callbacks.
3. Communicate with other drm_dwc components using std::function
without any locking.
Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
Diffstat (limited to 'compositor/DrmDisplayCompositor.cpp')
-rw-r--r-- | compositor/DrmDisplayCompositor.cpp | 55 |
1 files changed, 19 insertions, 36 deletions
diff --git a/compositor/DrmDisplayCompositor.cpp b/compositor/DrmDisplayCompositor.cpp index 08d998c..5ad2de2 100644 --- a/compositor/DrmDisplayCompositor.cpp +++ b/compositor/DrmDisplayCompositor.cpp @@ -49,20 +49,6 @@ std::ostream &operator<<(std::ostream &str, FlatteningState state) { return str << flattenting_state_str[static_cast<int>(state)]; } -class CompositorVsyncCallback : public VsyncCallback { - public: - explicit CompositorVsyncCallback(DrmDisplayCompositor *compositor) - : compositor_(compositor) { - } - - void Callback(int display, int64_t timestamp) override { - compositor_->Vsync(display, timestamp); - } - - private: - DrmDisplayCompositor *compositor_; -}; - DrmDisplayCompositor::DrmDisplayCompositor() : resource_manager_(nullptr), display_(-1), @@ -103,7 +89,10 @@ DrmDisplayCompositor::~DrmDisplayCompositor() { pthread_mutex_destroy(&lock_); } -int DrmDisplayCompositor::Init(ResourceManager *resource_manager, int display) { +auto DrmDisplayCompositor::Init(ResourceManager *resource_manager, int display, + std::function<void()> client_refresh_callback) + -> int { + client_refresh_callback_ = std::move(client_refresh_callback); resource_manager_ = resource_manager; display_ = display; DrmDevice *drm = resource_manager_->GetDrmDevice(display); @@ -118,9 +107,19 @@ int DrmDisplayCompositor::Init(ResourceManager *resource_manager, int display) { } planner_ = Planner::CreateInstance(drm); - vsync_worker_.Init(drm, display_); - auto callback = std::make_shared<CompositorVsyncCallback>(this); - vsync_worker_.RegisterCallback(callback); + vsync_worker_.Init(drm, display_, [this](int64_t timestamp) { + AutoLock lock(&lock_, "DrmDisplayCompositor::Init()"); + if (lock.Lock()) + return; + flatten_countdown_--; + if (!CountdownExpired()) + return; + lock.Unlock(); + int ret = FlattenActiveComposition(); + ALOGV("scene flattening triggered for display %d at timestamp %" PRIu64 + " result = %d \n", + display_, timestamp, ret); + }); initialized_ = true; return 0; @@ -445,9 +444,7 @@ bool DrmDisplayCompositor::IsFlatteningNeeded() const { } int DrmDisplayCompositor::FlattenOnClient() { - const std::lock_guard<std::mutex> lock(refresh_callback_lock); - - if (refresh_callback_hook_ && refresh_callback_data_) { + if (client_refresh_callback_) { { AutoLock lock(&lock_, __func__); if (!IsFlatteningNeeded()) { @@ -463,7 +460,7 @@ int DrmDisplayCompositor::FlattenOnClient() { "No writeback connector available, " "falling back to client composition"); SetFlattening(FlatteningState::kClientRequested); - refresh_callback_hook_(refresh_callback_data_, display_); + client_refresh_callback_(); return 0; } @@ -479,20 +476,6 @@ bool DrmDisplayCompositor::CountdownExpired() const { return flatten_countdown_ <= 0; } -void DrmDisplayCompositor::Vsync(int display, int64_t timestamp) { - AutoLock lock(&lock_, __func__); - if (lock.Lock()) - return; - flatten_countdown_--; - if (!CountdownExpired()) - return; - lock.Unlock(); - int ret = FlattenActiveComposition(); - ALOGV("scene flattening triggered for display %d at timestamp %" PRIu64 - " result = %d \n", - display, timestamp, ret); -} - void DrmDisplayCompositor::Dump(std::ostringstream *out) const { int ret = pthread_mutex_lock(&lock_); if (ret) |