From dbf07a32fe627532fdb0bf3f984d76a52b015ccd Mon Sep 17 00:00:00 2001 From: Kalyan Kondapally Date: Mon, 18 Dec 2017 19:20:23 -0800 Subject: [PATCH] Remove Composition state in displayplanestate. We are now having too many combinations and will get bit more complicated when we start adding under/over scaling support completely. Let's hide all this different combination complexity in DisplayPlaneState and add API to query if offscreen composition is needed for displayplane. Jira: None. Test: No new regressions on Android. Signed-off-by: Kalyan Kondapally --- common/compositor/compositor.cpp | 3 +-- common/display/displayplanemanager.cpp | 15 ++++++--------- common/display/displayplanestate.h | 35 +++++++++++++++++++++++----------- common/display/displayqueue.cpp | 4 +--- 4 files changed, 32 insertions(+), 25 deletions(-) diff --git a/common/compositor/compositor.cpp b/common/compositor/compositor.cpp index f2897f8..d0d54df 100644 --- a/common/compositor/compositor.cpp +++ b/common/compositor/compositor.cpp @@ -81,8 +81,7 @@ bool Compositor::Draw(DisplayPlaneStateList &comp_planes, lock_.unlock(); const OverlayLayer &layer = layers[plane.source_layers().at(0)]; media_state.layer_ = &layer; - } else if (plane.GetCompositionState() == - DisplayPlaneState::State::kRender) { + } else if (plane.NeedsOffScreenComposition()) { comp = &plane; std::vector &comp_regions = plane.GetCompositionRegion(); diff --git a/common/display/displayplanemanager.cpp b/common/display/displayplanemanager.cpp index b0c5861..03f46c0 100644 --- a/common/display/displayplanemanager.cpp +++ b/common/display/displayplanemanager.cpp @@ -138,9 +138,7 @@ bool DisplayPlaneManager::ValidateLayers( #endif DisplayPlaneState &last_plane = composition.back(); OverlayLayer *previous_layer = NULL; - if (previous_layer && - last_plane.GetCompositionState() == - DisplayPlaneState::State::kRender) { + if (previous_layer && last_plane.NeedsOffScreenComposition()) { ValidateForDisplayScaling(composition.back(), commit_planes, previous_layer); render_layers = true; @@ -197,7 +195,7 @@ bool DisplayPlaneManager::ValidateLayers( last_plane.AddLayer(previous_layer); } - if (last_plane.GetCompositionState() == DisplayPlaneState::State::kRender) { + if (last_plane.NeedsOffScreenComposition()) { if (previous_layer) { // In this case we need to fallback to 3Dcomposition till Media // backend adds support for multiple layers. @@ -229,7 +227,7 @@ bool DisplayPlaneManager::ValidateLayers( if (render_layers) { ValidateFinalLayers(composition, layers); for (DisplayPlaneState &plane : composition) { - if (plane.GetCompositionState() == DisplayPlaneState::State::kRender) { + if (plane.NeedsOffScreenComposition()) { const std::vector &source_layers = plane.source_layers(); size_t layers_size = source_layers.size(); bool useplanescalar = plane.IsUsingPlaneScalar(); @@ -268,7 +266,7 @@ bool DisplayPlaneManager::ReValidateLayers(std::vector &layers, if (plane_handler_->TestCommit(commit_planes)) { *request_full_validation = false; for (DisplayPlaneState &plane : composition) { - if (plane.GetCompositionState() == DisplayPlaneState::State::kRender) { + if (plane.NeedsOffScreenComposition()) { render_layers = true; const std::vector &source_layers = plane.source_layers(); size_t layers_size = source_layers.size(); @@ -631,8 +629,7 @@ void DisplayPlaneManager::ValidateFinalLayers( DisplayPlaneStateList &composition, std::vector &layers) { std::vector commit_planes; for (DisplayPlaneState &plane : composition) { - if (plane.GetCompositionState() == DisplayPlaneState::State::kRender && - !plane.GetOffScreenTarget()) { + if (plane.NeedsOffScreenComposition() && !plane.GetOffScreenTarget()) { EnsureOffScreenTarget(plane); } @@ -645,7 +642,7 @@ void DisplayPlaneManager::ValidateFinalLayers( // We start off with Primary plane. DisplayPlane *current_plane = primary_plane_; for (DisplayPlaneState &plane : composition) { - if (plane.GetCompositionState() == DisplayPlaneState::State::kRender) { + if (plane.GetOffScreenTarget()) { plane.GetOffScreenTarget()->SetInUse(false); } } diff --git a/common/display/displayplanestate.h b/common/display/displayplanestate.h index ede05c4..1534993 100644 --- a/common/display/displayplanestate.h +++ b/common/display/displayplanestate.h @@ -36,12 +36,6 @@ typedef std::vector DisplayPlaneStateList; class DisplayPlaneState { public: - enum class State : int32_t { - kScanout, // Scanout the layer directly. - kRender, // Needs to render the contents to - // layer before scanning out. - }; - DisplayPlaneState() = default; DisplayPlaneState(DisplayPlaneState &&rhs) = default; DisplayPlaneState &operator=(DisplayPlaneState &&other) = default; @@ -70,10 +64,6 @@ class DisplayPlaneState { // should be determined in DisplayQueue for every frame. } - State GetCompositionState() const { - return state_; - } - const HwcRect &GetDisplayFrame() const { return display_frame_; } @@ -179,7 +169,6 @@ class DisplayPlaneState { } void ReUseOffScreenTarget() { - state_ = State::kScanout; recycled_surface_ = true; } @@ -331,12 +320,36 @@ class DisplayPlaneState { return state_ == State::kScanout; } + // Returns true if offscreen composition + // is needed for this plane. + bool NeedsOffScreenComposition() { + if (state_ == State::kRender) + return true; + + if (recycled_surface_) { + return true; + } + + if (apply_effects_) { + return true; + } + + return false; + } + private: enum class PlaneType : int32_t { kCursor, // Plane is compositing only Cursor. kVideo, // Plane is compositing only Media content. kNormal // Plane is compositing different types of content. }; + + enum class State : int32_t { + kScanout, // Scanout the layer directly. + kRender, // Needs to render the contents to + // layer before scanning out. + }; + State state_ = State::kScanout; DisplayPlane *plane_ = NULL; const OverlayLayer *layer_ = NULL; diff --git a/common/display/displayqueue.cpp b/common/display/displayqueue.cpp index 6e91340..3e3626a 100644 --- a/common/display/displayqueue.cpp +++ b/common/display/displayqueue.cpp @@ -125,8 +125,6 @@ void DisplayQueue::GetCachedLayers(const std::vector& layers, bool ignore_commit = !cursor_layer_removed; bool needs_revalidation = false; for (DisplayPlaneState& plane : previous_plane_state_) { - bool plane_state_render = - plane.GetCompositionState() == DisplayPlaneState::State::kRender; if (cursor_layer_removed && plane.IsCursorPlane()) { plane.plane()->SetInUse(false); continue; @@ -138,7 +136,7 @@ void DisplayQueue::GetCachedLayers(const std::vector& layers, last_plane.CopyState(plane); last_plane.AddLayers(plane.source_layers(), layers, cursor_layer_removed); - if (plane_state_render || plane.SurfaceRecycled() || plane.ApplyEffects()) { + if (plane.NeedsOffScreenComposition()) { bool content_changed = false; bool update_source_rect = false; const std::vector& source_layers = last_plane.source_layers(); -- 2.11.0