From: Kalyan Kondapally Date: Sat, 23 Dec 2017 02:22:36 +0000 (-0800) Subject: Rework DisplayPlaneState API. X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=7fc2d5f8e286b2e3fbcacb29e682bded13b89040;p=android-x86%2Fexternal-IA-Hardware-Composer.git Rework DisplayPlaneState API. This is to make sure they align with rest of the classes in code base. Jira: None. Test: Build passes on Android. Signed-off-by: Kalyan Kondapally --- diff --git a/common/Android.mk b/common/Android.mk index 3de0cce..dc592bf 100644 --- a/common/Android.mk +++ b/common/Android.mk @@ -79,6 +79,7 @@ LOCAL_SRC_FILES := \ core/overlaylayer.cpp \ core/nesteddisplay.cpp \ display/displayplanemanager.cpp \ + display/displayplanestate.cpp \ display/displayqueue.cpp \ display/vblankeventhandler.cpp \ display/virtualdisplay.cpp \ diff --git a/common/Makefile.sources b/common/Makefile.sources index 84f735e..0febdbf 100644 --- a/common/Makefile.sources +++ b/common/Makefile.sources @@ -14,6 +14,7 @@ common_SOURCES = \ core/nesteddisplay.cpp \ display/displayqueue.cpp \ display/displayplanemanager.cpp \ + display/displayplanestate.cpp \ display/vblankeventhandler.cpp \ display/virtualdisplay.cpp \ utils/fdhandler.cpp \ diff --git a/common/compositor/compositor.cpp b/common/compositor/compositor.cpp index d24c852..61d40bc 100644 --- a/common/compositor/compositor.cpp +++ b/common/compositor/compositor.cpp @@ -66,12 +66,12 @@ bool Compositor::Draw(DisplayPlaneStateList &comp_planes, for (DisplayPlaneState &plane : comp_planes) { if (plane.Scanout()) { dedicated_layers.insert(dedicated_layers.end(), - plane.source_layers().begin(), - plane.source_layers().end()); + plane.GetSourceLayers().begin(), + plane.GetSourceLayers().end()); } else if (plane.IsVideoPlane()) { dedicated_layers.insert(dedicated_layers.end(), - plane.source_layers().begin(), - plane.source_layers().end()); + plane.GetSourceLayers().begin(), + plane.GetSourceLayers().end()); media_state.emplace_back(); DrawState &state = media_state.back(); state.surface_ = plane.GetOffScreenTarget(); @@ -79,14 +79,14 @@ bool Compositor::Draw(DisplayPlaneStateList &comp_planes, lock_.lock(); media_state.colors_ = colors_; lock_.unlock(); - const OverlayLayer &layer = layers[plane.source_layers().at(0)]; + const OverlayLayer &layer = layers[plane.GetSourceLayers().at(0)]; media_state.layer_ = &layer; } else if (plane.NeedsOffScreenComposition()) { comp = &plane; std::vector &comp_regions = plane.GetCompositionRegion(); if (comp_regions.empty()) { - SeparateLayers(dedicated_layers, comp->source_layers(), display_frame, + SeparateLayers(dedicated_layers, comp->GetSourceLayers(), display_frame, comp_regions); } diff --git a/common/display/displayplanemanager.cpp b/common/display/displayplanemanager.cpp index dcc0f62..6f9c04a 100644 --- a/common/display/displayplanemanager.cpp +++ b/common/display/displayplanemanager.cpp @@ -192,10 +192,9 @@ bool DisplayPlaneManager::ValidateLayers( // In this case we need to fallback to 3Dcomposition till Media // backend adds support for multiple layers. bool force_buffer = false; - if (is_video && last_plane.source_layers().size() > 1 && + if (is_video && last_plane.GetSourceLayers().size() > 1 && last_plane.GetOffScreenTarget()) { - last_plane.GetOffScreenTarget()->SetInUse(false); - std::vector().swap(last_plane.GetSurfaces()); + last_plane.ReleaseSurfaces(); force_buffer = true; } @@ -220,7 +219,7 @@ bool DisplayPlaneManager::ValidateLayers( ValidateFinalLayers(composition, layers); for (DisplayPlaneState &plane : composition) { if (plane.NeedsOffScreenComposition()) { - const std::vector &source_layers = plane.source_layers(); + const std::vector &source_layers = plane.GetSourceLayers(); size_t layers_size = source_layers.size(); bool useplanescalar = plane.IsUsingPlaneScalar(); for (size_t i = 0; i < layers_size; i++) { @@ -243,10 +242,10 @@ bool DisplayPlaneManager::ReValidateLayers(std::vector &layers, std::vector commit_planes; for (DisplayPlaneState &temp : composition) { commit_planes.emplace_back( - OverlayPlane(temp.plane(), temp.GetOverlayLayer())); + OverlayPlane(temp.GetDisplayPlane(), temp.GetOverlayLayer())); // Check if we can still need/use scalar for this plane. if (temp.IsUsingPlaneScalar()) { - const std::vector &source = temp.source_layers(); + const std::vector &source = temp.GetSourceLayers(); size_t total_layers = source.size(); ValidateForDisplayScaling( temp, commit_planes, &(layers.at(source.at(total_layers - 1))), true); @@ -260,7 +259,7 @@ bool DisplayPlaneManager::ReValidateLayers(std::vector &layers, for (DisplayPlaneState &plane : composition) { if (plane.NeedsOffScreenComposition()) { render_layers = true; - const std::vector &source_layers = plane.source_layers(); + const std::vector &source_layers = plane.GetSourceLayers(); size_t layers_size = source_layers.size(); bool useplanescalar = plane.IsUsingPlaneScalar(); for (size_t i = 0; i < layers_size; i++) { @@ -286,7 +285,8 @@ DisplayPlaneState *DisplayPlaneManager::GetLastUsedOverlay( size_t size = composition.size(); for (size_t i = size; i > 0; i--) { DisplayPlaneState &plane = composition.at(i - 1); - if ((cursor_plane_ == plane.plane()) && (!cursor_plane_->IsUniversal())) + if ((cursor_plane_ == plane.GetDisplayPlane()) && + (!cursor_plane_->IsUniversal())) continue; last_plane = &plane; @@ -309,7 +309,7 @@ void DisplayPlaneManager::PreparePlaneForCursor(DisplayPlaneState *plane, std::vector &comp_regions = plane->GetCompositionRegion(); std::vector().swap(comp_regions); - std::vector &surfaces = plane->GetSurfaces(); + const std::vector &surfaces = plane->GetSurfaces(); size_t size = surfaces.size(); const HwcRect ¤t_rect = plane->GetDisplayFrame(); for (size_t i = 0; i < size; i++) { @@ -332,7 +332,7 @@ bool DisplayPlaneManager::ValidateCursorLayer( bool is_video = last_plane->IsVideoPlane(); for (DisplayPlaneState &temp : composition) { commit_planes.emplace_back( - OverlayPlane(temp.plane(), temp.GetOverlayLayer())); + OverlayPlane(temp.GetDisplayPlane(), temp.GetOverlayLayer())); } uint32_t total_size = cursor_layers.size(); @@ -369,7 +369,7 @@ bool DisplayPlaneManager::ValidateCursorLayer( std::vector().swap(commit_planes); for (DisplayPlaneState &temp : composition) { commit_planes.emplace_back( - OverlayPlane(temp.plane(), temp.GetOverlayLayer())); + OverlayPlane(temp.GetDisplayPlane(), temp.GetOverlayLayer())); } } @@ -408,8 +408,8 @@ bool DisplayPlaneManager::ValidateCursorLayer( void DisplayPlaneManager::ValidateForDisplayScaling( DisplayPlaneState &last_plane, std::vector &commit_planes, OverlayLayer *current_layer, bool ignore_format) { - size_t total_layers = last_plane.source_layers().size(); - std::vector &surfaces = last_plane.GetSurfaces(); + size_t total_layers = last_plane.GetSourceLayers().size(); + const std::vector &surfaces = last_plane.GetSurfaces(); size_t size = surfaces.size(); if (last_plane.IsUsingPlaneScalar()) { @@ -446,7 +446,7 @@ void DisplayPlaneManager::ValidateForDisplayScaling( // return. if (!ignore_format && (current_layer->GetPlaneTransform() == HWCTransform::kIdentity) && - last_plane.plane()->IsSupportedFormat( + last_plane.GetDisplayPlane()->IsSupportedFormat( current_layer->GetBuffer()->GetFormat())) { return; } @@ -500,7 +500,7 @@ void DisplayPlaneManager::ValidateForDisplayScaling( last_overlay_plane.layer = last_plane.GetOverlayLayer(); bool fall_back = - FallbacktoGPU(last_plane.plane(), + FallbacktoGPU(last_plane.GetDisplayPlane(), last_plane.GetOffScreenTarget()->GetLayer(), commit_planes); if (fall_back) { last_plane.ResetSourceRectToDisplayFrame(); @@ -551,9 +551,9 @@ void DisplayPlaneManager::EnsureOffScreenTarget(DisplayPlaneState &plane) { uint32_t preferred_format = 0; uint32_t usage = hwcomposer::kLayerNormal; if (video_separate) { - preferred_format = plane.plane()->GetPreferredVideoFormat(); + preferred_format = plane.GetDisplayPlane()->GetPreferredVideoFormat(); } else { - preferred_format = plane.plane()->GetPreferredFormat(); + preferred_format = plane.GetDisplayPlane()->GetPreferredFormat(); } for (auto &fb : surfaces_) { @@ -593,7 +593,7 @@ void DisplayPlaneManager::ValidateFinalLayers( } commit_planes.emplace_back( - OverlayPlane(plane.plane(), plane.GetOverlayLayer())); + OverlayPlane(plane.GetDisplayPlane(), plane.GetOverlayLayer())); } // If this combination fails just fall back to 3D for all layers. diff --git a/common/display/displayplanestate.cpp b/common/display/displayplanestate.cpp new file mode 100644 index 0000000..96229dd --- /dev/null +++ b/common/display/displayplanestate.cpp @@ -0,0 +1,311 @@ +/* +// Copyright (c) 2016 Intel Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +*/ + +#include "displayplanestate.h" + +namespace hwcomposer { + +DisplayPlaneState::DisplayPlaneState(DisplayPlane *plane, OverlayLayer *layer, + uint32_t index) + : plane_(plane), layer_(layer) { + source_layers_.emplace_back(index); + display_frame_ = layer->GetDisplayFrame(); + source_crop_ = layer->GetSourceCrop(); + if (layer->IsCursorLayer()) { + type_ = PlaneType::kCursor; + has_cursor_layer_ = true; + } +} + +void DisplayPlaneState::CopyState(DisplayPlaneState &state) { + has_cursor_layer_ = state.has_cursor_layer_; + type_ = state.type_; + use_plane_scalar_ = state.use_plane_scalar_; + plane_ = state.plane_; + state_ = state.state_; + source_crop_ = state.source_crop_; + display_frame_ = state.display_frame_; + apply_effects_ = state.apply_effects_; + plane_->SetInUse(true); + // We don't copy recycled_surface_ state as this + // should be determined in DisplayQueue for every frame. +} + +const HwcRect &DisplayPlaneState::GetDisplayFrame() const { + return display_frame_; +} + +const HwcRect &DisplayPlaneState::GetSourceCrop() const { + return source_crop_; +} + +void DisplayPlaneState::SetSourceCrop(const HwcRect &crop) { + source_crop_ = crop; +} + +void DisplayPlaneState::ResetSourceRectToDisplayFrame() { + source_crop_ = HwcRect(display_frame_); +} + +void DisplayPlaneState::AddLayer(const OverlayLayer *layer) { + const HwcRect &display_frame = layer->GetDisplayFrame(); + display_frame_.left = std::min(display_frame_.left, display_frame.left); + display_frame_.top = std::min(display_frame_.top, display_frame.top); + display_frame_.right = std::max(display_frame_.right, display_frame.right); + display_frame_.bottom = std::max(display_frame_.bottom, display_frame.bottom); + + source_layers_.emplace_back(layer->GetZorder()); + + state_ = State::kRender; + has_cursor_layer_ = layer->IsCursorLayer(); + + if (source_layers_.size() == 1 && has_cursor_layer_) { + type_ = PlaneType::kCursor; + } else { + // TODO: Add checks for Video type once our + // Media backend can support compositing more + // than one layer together. + type_ = PlaneType::kNormal; + apply_effects_ = false; + } + + if (!use_plane_scalar_) + source_crop_ = HwcRect(display_frame_); +} + +// This API should be called only when Cursor layer is being +// added, is part of layers displayed by plane or is being +// removed in this frame. AddLayers should be used in all +// other cases. +void DisplayPlaneState::AddLayers(const std::vector &source_layers, + const std::vector &layers, + bool ignore_cursor_layer) { + if (ignore_cursor_layer) { + size_t lsize = layers.size(); + size_t size = source_layers.size(); + source_layers_.reserve(size); + has_cursor_layer_ = false; + bool initialized = false; + for (const size_t &index : source_layers) { + if (index >= lsize) { + continue; + } + + const OverlayLayer &layer = layers.at(index); + const HwcRect &df = layer.GetDisplayFrame(); + if (!initialized) { + display_frame_ = df; + initialized = true; + } else { + display_frame_.left = std::min(display_frame_.left, df.left); + display_frame_.top = std::min(display_frame_.top, df.top); + display_frame_.right = std::max(display_frame_.right, df.right); + display_frame_.bottom = std::max(display_frame_.bottom, df.bottom); + } + + source_layers_.emplace_back(index); + } + + if (!use_plane_scalar_) + source_crop_ = HwcRect(display_frame_); + } else { + for (const int &index : source_layers) { + source_layers_.emplace_back(index); + } + } +} + +void DisplayPlaneState::UpdateDisplayFrame(const HwcRect &display_frame) { + display_frame_.left = std::min(display_frame_.left, display_frame.left); + display_frame_.top = std::min(display_frame_.top, display_frame.top); + display_frame_.right = std::max(display_frame_.right, display_frame.right); + display_frame_.bottom = std::max(display_frame_.bottom, display_frame.bottom); + + if (!use_plane_scalar_) + source_crop_ = HwcRect(display_frame_); +} + +void DisplayPlaneState::ForceGPURendering() { + state_ = State::kRender; +} + +void DisplayPlaneState::SetOverlayLayer(const OverlayLayer *layer) { + layer_ = layer; +} + +void DisplayPlaneState::ReUseOffScreenTarget() { + recycled_surface_ = true; +} + +bool DisplayPlaneState::SurfaceRecycled() const { + return recycled_surface_; +} + +const OverlayLayer *DisplayPlaneState::GetOverlayLayer() const { + return layer_; +} + +void DisplayPlaneState::SetOffScreenTarget(NativeSurface *target) { + surfaces_.emplace(surfaces_.begin(), target); +} + +NativeSurface *DisplayPlaneState::GetOffScreenTarget() const { + if (surfaces_.size() == 0) { + return NULL; + } + + return surfaces_.at(0); +} + +void DisplayPlaneState::TransferSurfaces( + const std::vector &surfaces, bool swap_front_buffer) { + size_t size = surfaces.size(); + source_layers_.reserve(size); + if (size < 3 || !swap_front_buffer) { + for (uint32_t i = 0; i < size; i++) { + surfaces_.emplace_back(surfaces.at(i)); + } + } else { + // Lets make sure front buffer is now back in the list. + surfaces_.emplace_back(surfaces.at(1)); + surfaces_.emplace_back(surfaces.at(2)); + surfaces_.emplace_back(surfaces.at(0)); + } + + NativeSurface *surface = surfaces_.at(0); + surface->SetInUse(true); + SetOverlayLayer(surface->GetLayer()); + + if (surfaces_.size() == 3) { + surface_swapped_ = swap_front_buffer; + } else { + // We will be using an empty buffer, no need to + // swap buffer in this case. + surface_swapped_ = true; + } +} + +void DisplayPlaneState::SwapSurfaceIfNeeded() { + if (surface_swapped_) { + return; + } + + std::vector temp; + temp.reserve(surfaces_.size()); + temp.emplace_back(surfaces_.at(1)); + temp.emplace_back(surfaces_.at(2)); + temp.emplace_back(surfaces_.at(0)); + temp.swap(surfaces_); + surface_swapped_ = true; + NativeSurface *surface = surfaces_.at(0); + surface->SetInUse(true); + SetOverlayLayer(surface->GetLayer()); +} + +const std::vector &DisplayPlaneState::GetSurfaces() const { + return surfaces_; +} + +void DisplayPlaneState::ReleaseSurfaces() { + for (NativeSurface *surface : surfaces_) { + surface->SetInUse(false); + } + + std::vector().swap(surfaces_); +} + +DisplayPlane *DisplayPlaneState::GetDisplayPlane() const { + return plane_; +} + +const std::vector &DisplayPlaneState::GetSourceLayers() const { + return source_layers_; +} + +std::vector &DisplayPlaneState::GetCompositionRegion() { + return composition_region_; +} + +const std::vector &DisplayPlaneState::GetCompositionRegion() + const { + return composition_region_; +} + +bool DisplayPlaneState::IsCursorPlane() const { + return type_ == PlaneType::kCursor; +} + +bool DisplayPlaneState::HasCursorLayer() const { + return has_cursor_layer_; +} + +bool DisplayPlaneState::IsVideoPlane() const { + return type_ == PlaneType::kVideo; +} + +void DisplayPlaneState::SetVideoPlane() { + type_ = PlaneType::kVideo; +} + +void DisplayPlaneState::UsePlaneScalar(bool enable) { + use_plane_scalar_ = enable; +} + +bool DisplayPlaneState::IsUsingPlaneScalar() const { + return use_plane_scalar_; +} + +void DisplayPlaneState::SetApplyEffects(bool apply_effects) { + apply_effects_ = apply_effects; + // Doesn't have any impact on planes which + // are not meant for video purpose. + if (type_ != PlaneType::kVideo) { + apply_effects_ = false; + } +} + +bool DisplayPlaneState::ApplyEffects() const { + return apply_effects_; +} + +bool DisplayPlaneState::Scanout() const { + if (recycled_surface_) { + return true; + } + + if (apply_effects_) { + return false; + } + + return state_ == State::kScanout; +} + +bool DisplayPlaneState::NeedsOffScreenComposition() { + if (state_ == State::kRender) + return true; + + if (recycled_surface_) { + return true; + } + + if (apply_effects_) { + return true; + } + + return false; +} + +} // namespace hwcomposer diff --git a/common/display/displayplanestate.h b/common/display/displayplanestate.h index 1534993..96d1d6f 100644 --- a/common/display/displayplanestate.h +++ b/common/display/displayplanestate.h @@ -39,73 +39,16 @@ class DisplayPlaneState { DisplayPlaneState() = default; DisplayPlaneState(DisplayPlaneState &&rhs) = default; DisplayPlaneState &operator=(DisplayPlaneState &&other) = default; - DisplayPlaneState(DisplayPlane *plane, OverlayLayer *layer, uint32_t index) - : plane_(plane), layer_(layer) { - source_layers_.emplace_back(index); - display_frame_ = layer->GetDisplayFrame(); - source_crop_ = layer->GetSourceCrop(); - if (layer->IsCursorLayer()) { - type_ = PlaneType::kCursor; - has_cursor_layer_ = true; - } - } - - void CopyState(DisplayPlaneState &state) { - has_cursor_layer_ = state.has_cursor_layer_; - type_ = state.type_; - use_plane_scalar_ = state.use_plane_scalar_; - plane_ = state.plane_; - state_ = state.state_; - source_crop_ = state.source_crop_; - display_frame_ = state.display_frame_; - apply_effects_ = state.apply_effects_; - plane_->SetInUse(true); - // We don't copy recycled_surface_ state as this - // should be determined in DisplayQueue for every frame. - } - - const HwcRect &GetDisplayFrame() const { - return display_frame_; - } - - const HwcRect &GetSourceCrop() const { - return source_crop_; - } - - void SetSourceCrop(const HwcRect &crop) { - source_crop_ = crop; - } - - void ResetSourceRectToDisplayFrame() { - source_crop_ = HwcRect(display_frame_); - } - - void AddLayer(const OverlayLayer *layer) { - const HwcRect &display_frame = layer->GetDisplayFrame(); - display_frame_.left = std::min(display_frame_.left, display_frame.left); - display_frame_.top = std::min(display_frame_.top, display_frame.top); - display_frame_.right = std::max(display_frame_.right, display_frame.right); - display_frame_.bottom = - std::max(display_frame_.bottom, display_frame.bottom); - - source_layers_.emplace_back(layer->GetZorder()); - - state_ = State::kRender; - has_cursor_layer_ = layer->IsCursorLayer(); - - if (source_layers_.size() == 1 && has_cursor_layer_) { - type_ = PlaneType::kCursor; - } else { - // TODO: Add checks for Video type once our - // Media backend can support compositing more - // than one layer together. - type_ = PlaneType::kNormal; - apply_effects_ = false; - } - - if (!use_plane_scalar_) - source_crop_ = HwcRect(display_frame_); - } + DisplayPlaneState(DisplayPlane *plane, OverlayLayer *layer, uint32_t index); + + // Copies plane state from state. + void CopyState(DisplayPlaneState &state); + + void SetSourceCrop(const HwcRect &crop); + + void ResetSourceRectToDisplayFrame(); + + void AddLayer(const OverlayLayer *layer); // This API should be called only when Cursor layer is being // added, is part of layers displayed by plane or is being @@ -113,229 +56,95 @@ class DisplayPlaneState { // other cases. void AddLayers(const std::vector &source_layers, const std::vector &layers, - bool ignore_cursor_layer) { - if (ignore_cursor_layer) { - size_t lsize = layers.size(); - size_t size = source_layers.size(); - source_layers_.reserve(size); - has_cursor_layer_ = false; - bool initialized = false; - for (const size_t &index : source_layers) { - if (index >= lsize) { - continue; - } - - const OverlayLayer &layer = layers.at(index); - const HwcRect &df = layer.GetDisplayFrame(); - if (!initialized) { - display_frame_ = df; - initialized = true; - } else { - display_frame_.left = std::min(display_frame_.left, df.left); - display_frame_.top = std::min(display_frame_.top, df.top); - display_frame_.right = std::max(display_frame_.right, df.right); - display_frame_.bottom = std::max(display_frame_.bottom, df.bottom); - } - - source_layers_.emplace_back(index); - } - - if (!use_plane_scalar_) - source_crop_ = HwcRect(display_frame_); - } else { - for (const int &index : source_layers) { - source_layers_.emplace_back(index); - } - } - } - - void UpdateDisplayFrame(const HwcRect &display_frame) { - display_frame_.left = std::min(display_frame_.left, display_frame.left); - display_frame_.top = std::min(display_frame_.top, display_frame.top); - display_frame_.right = std::max(display_frame_.right, display_frame.right); - display_frame_.bottom = - std::max(display_frame_.bottom, display_frame.bottom); - - if (!use_plane_scalar_) - source_crop_ = HwcRect(display_frame_); - } - - void ForceGPURendering() { - state_ = State::kRender; - } - - void SetOverlayLayer(const OverlayLayer *layer) { - layer_ = layer; - } - - void ReUseOffScreenTarget() { - recycled_surface_ = true; - } - - bool SurfaceRecycled() const { - return recycled_surface_; - } - - const OverlayLayer *GetOverlayLayer() const { - return layer_; - } - - void SetOffScreenTarget(NativeSurface *target) { - surfaces_.emplace(surfaces_.begin(), target); - } - - NativeSurface *GetOffScreenTarget() const { - if (surfaces_.size() == 0) { - return NULL; - } - - return surfaces_.at(0); - } + bool ignore_cursor_layer); - void TransferSurfaces(const std::vector &surfaces, - bool swap_front_buffer) { - size_t size = surfaces.size(); - source_layers_.reserve(size); - if (size < 3 || !swap_front_buffer) { - for (uint32_t i = 0; i < size; i++) { - surfaces_.emplace_back(surfaces.at(i)); - } - } else { - // Lets make sure front buffer is now back in the list. - surfaces_.emplace_back(surfaces.at(1)); - surfaces_.emplace_back(surfaces.at(2)); - surfaces_.emplace_back(surfaces.at(0)); - } - - NativeSurface *surface = surfaces_.at(0); - surface->SetInUse(true); - SetOverlayLayer(surface->GetLayer()); - - if (surfaces_.size() == 3) { - surface_swapped_ = swap_front_buffer; - } else { - // We will be using an empty buffer, no need to - // swap buffer in this case. - surface_swapped_ = true; - } - } + // Updates Display frame rect of this plane to include + // display_frame. + void UpdateDisplayFrame(const HwcRect &display_frame); + + // Forces GPU Rendering of content for this plane. + void ForceGPURendering(); + + // Set's layer to be scanned out for this plane. This layer + // can be associated with NativeSurface in case the content + // need's to be rendered before being scanned out. + void SetOverlayLayer(const OverlayLayer *layer); + + // Reuses last shown surface for current frame. + void ReUseOffScreenTarget(); // This will be called by DisplayPlaneManager when adding // cursor layer to any existing overlay. - void SwapSurfaceIfNeeded() { - if (surface_swapped_) { - return; - } - - std::vector temp; - temp.reserve(surfaces_.size()); - temp.emplace_back(surfaces_.at(1)); - temp.emplace_back(surfaces_.at(2)); - temp.emplace_back(surfaces_.at(0)); - temp.swap(surfaces_); - surface_swapped_ = true; - NativeSurface *surface = surfaces_.at(0); - surface->SetInUse(true); - SetOverlayLayer(surface->GetLayer()); - } - - const std::vector &GetSurfaces() const { - return surfaces_; - } - - std::vector &GetSurfaces() { - return surfaces_; - } - - DisplayPlane *plane() const { - return plane_; - } - - const std::vector &source_layers() const { - return source_layers_; - } - - std::vector &GetCompositionRegion() { - return composition_region_; - } - - const std::vector &GetCompositionRegion() const { - return composition_region_; - } - - bool IsCursorPlane() const { - return type_ == PlaneType::kCursor; - } - - bool HasCursorLayer() const { - return has_cursor_layer_; - } - - bool IsVideoPlane() const { - return type_ == PlaneType::kVideo; - } - - void SetVideoPlane() { - type_ = PlaneType::kVideo; - } - - void UsePlaneScalar(bool enable) { - use_plane_scalar_ = enable; - } - - bool IsUsingPlaneScalar() const { - return use_plane_scalar_; - } + void SwapSurfaceIfNeeded(); + + // SetOffcreen Surface for this plane. + void SetOffScreenTarget(NativeSurface *target); + + // Moves surfaces to this plane. If swap_front_buffer + // is true we would swap the buffer first in surfaces to + // last. + void TransferSurfaces(const std::vector &surfaces, + bool swap_front_buffer); + + const HwcRect &GetDisplayFrame() const; + + const HwcRect &GetSourceCrop() const; + + bool SurfaceRecycled() const; + + const OverlayLayer *GetOverlayLayer() const; + + NativeSurface *GetOffScreenTarget() const; + + // Returns all NativeSurfaces associated with this plane. + // These can be empty if the plane doesn't need to go + // through any composition pass before being scanned out. + const std::vector &GetSurfaces() const; + + // Marks all surfaces used by this plane as not in use + // and removes surfaces from this plane. After this call + // this plane will not have have any associated offscreen + // surfaces. + void ReleaseSurfaces(); + + DisplayPlane *GetDisplayPlane() const; + + // Returns source layers for this plane. + const std::vector &GetSourceLayers() const; + + std::vector &GetCompositionRegion(); + + const std::vector &GetCompositionRegion() const; + + bool IsCursorPlane() const; + + bool HasCursorLayer() const; + + bool IsVideoPlane() const; + + void SetVideoPlane(); + + void UsePlaneScalar(bool enable); + + bool IsUsingPlaneScalar() const; // This state means that the content scanned out // by this plane needs to be post processed to // take into account any video effects. - void SetApplyEffects(bool apply_effects) { - apply_effects_ = apply_effects; - // Doesn't have any impact on planes which - // are not meant for video purpose. - if (type_ != PlaneType::kVideo) { - apply_effects_ = false; - } - } + void SetApplyEffects(bool apply_effects); // Returns true if layer associated with this // plane needs to be processed to apply needed // video effects. - bool ApplyEffects() const { - return apply_effects_; - } + bool ApplyEffects() const; // Returns true if layer associated with // this plane can be scanned out directly. - bool Scanout() const { - if (recycled_surface_) { - return true; - } - - if (apply_effects_) { - return false; - } - - return state_ == State::kScanout; - } + bool Scanout() const; // 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; - } + bool NeedsOffScreenComposition(); private: enum class PlaneType : int32_t { diff --git a/common/display/displayqueue.cpp b/common/display/displayqueue.cpp index f720854..ac085c5 100644 --- a/common/display/displayqueue.cpp +++ b/common/display/displayqueue.cpp @@ -127,7 +127,7 @@ void DisplayQueue::GetCachedLayers(const std::vector& layers, bool needs_revalidation = false; for (DisplayPlaneState& plane : previous_plane_state_) { if (cursor_layer_removed && plane.IsCursorPlane()) { - plane.plane()->SetInUse(false); + plane.GetDisplayPlane()->SetInUse(false); continue; } @@ -143,12 +143,12 @@ void DisplayQueue::GetCachedLayers(const std::vector& layers, composition->emplace_back(); DisplayPlaneState& last_plane = composition->back(); last_plane.CopyState(plane); - last_plane.AddLayers(plane.source_layers(), layers, cursor_layer_removed); + last_plane.AddLayers(plane.GetSourceLayers(), layers, cursor_layer_removed); if (plane.NeedsOffScreenComposition()) { bool content_changed = false; bool update_rect = false; - const std::vector& source_layers = last_plane.source_layers(); + const std::vector& source_layers = last_plane.GetSourceLayers(); HwcRect surface_damage = HwcRect(0, 0, 0, 0); size_t layers_size = source_layers.size(); @@ -194,7 +194,7 @@ void DisplayQueue::GetCachedLayers(const std::vector& layers, // we need to clear the surface. last_plane.TransferSurfaces(plane.GetSurfaces(), content_changed || clear_surface); - std::vector& surfaces = last_plane.GetSurfaces(); + const std::vector& surfaces = last_plane.GetSurfaces(); size_t size = surfaces.size(); if (clear_surface || update_rect) { content_changed = true; @@ -225,7 +225,8 @@ void DisplayQueue::GetCachedLayers(const std::vector& layers, if (last_plane.GetSurfaces().size() == 3) { if (!clear_surface) { HwcRect last_damage; - std::vector& surfaces = last_plane.GetSurfaces(); + const std::vector& surfaces = + last_plane.GetSurfaces(); // Calculate Surface damage for the current surface. This should // be always equal to current surface damage + damage of last // two surfaces.(We use tripple buffering for our internal surfaces) @@ -253,7 +254,7 @@ void DisplayQueue::GetCachedLayers(const std::vector& layers, } } else { const OverlayLayer* layer = - &(*(layers.begin() + last_plane.source_layers().front())); + &(*(layers.begin() + last_plane.GetSourceLayers().front())); OverlayBuffer* buffer = layer->GetBuffer(); if (buffer->GetFb() == 0) { layer->GetBuffer()->CreateFrameBuffer(gpu_fd_); @@ -687,7 +688,7 @@ void DisplayQueue::SetMediaEffectsState( } plane.SetApplyEffects(apply_effects); - std::vector& surfaces = plane.GetSurfaces(); + const std::vector& surfaces = plane.GetSurfaces(); // Handle case where we enable effects but video plane is currently // scanned out directly. In this case we will need to ensure we // have a offscreen surface to render to. @@ -698,12 +699,8 @@ void DisplayQueue::SetMediaEffectsState( // scanned out directly. In this case we will need to delete all // offscreen surfaces and set the right overlayer layer to the // plane. - for (NativeSurface* surface : surfaces) { - surface->SetInUse(false); - } - - std::vector().swap(plane.GetSurfaces()); - const std::vector& source = plane.source_layers(); + plane.ReleaseSurfaces(); + const std::vector& source = plane.GetSourceLayers(); plane.SetOverlayLayer(&(layers.at(source.at(0)))); } } @@ -712,7 +709,7 @@ void DisplayQueue::SetMediaEffectsState( void DisplayQueue::UpdateSurfaceInUse( bool in_use, DisplayPlaneStateList& current_composition_planes) { for (DisplayPlaneState& plane_state : current_composition_planes) { - std::vector& surfaces = plane_state.GetSurfaces(); + const std::vector& surfaces = plane_state.GetSurfaces(); for (NativeSurface* surface : surfaces) { surface->SetInUse(in_use); } @@ -721,7 +718,7 @@ void DisplayQueue::UpdateSurfaceInUse( void DisplayQueue::UpdateOnScreenSurfaces() { for (DisplayPlaneState& plane_state : previous_plane_state_) { - std::vector& surfaces = plane_state.GetSurfaces(); + const std::vector& surfaces = plane_state.GetSurfaces(); if (surfaces.empty()) continue; @@ -745,7 +742,7 @@ void DisplayQueue::UpdateOnScreenSurfaces() { void DisplayQueue::RecyclePreviousPlaneSurfaces() { for (DisplayPlaneState& plane_state : previous_plane_state_) { - std::vector& surfaces = plane_state.GetSurfaces(); + const std::vector& surfaces = plane_state.GetSurfaces(); if (surfaces.empty()) continue; @@ -762,7 +759,7 @@ void DisplayQueue::RecyclePreviousPlaneSurfaces() { void DisplayQueue::SaveOnScreenSurfaces( DisplayPlaneStateList& current_composition_planes) { for (DisplayPlaneState& plane_state : current_composition_planes) { - std::vector& surfaces = plane_state.GetSurfaces(); + const std::vector& surfaces = plane_state.GetSurfaces(); if (surfaces.empty()) continue; @@ -790,7 +787,7 @@ void DisplayQueue::IgnoreCompositionResults( void DisplayQueue::SetReleaseFenceToLayers( int32_t fence, std::vector& source_layers) const { for (const DisplayPlaneState& plane : previous_plane_state_) { - const std::vector& layers = plane.source_layers(); + const std::vector& layers = plane.GetSourceLayers(); size_t size = layers.size(); int32_t release_fence = -1; if (plane.Scanout() && !plane.SurfaceRecycled()) { diff --git a/common/utils/hwctrace.h b/common/utils/hwctrace.h index 731918c..ae202e0 100644 --- a/common/utils/hwctrace.h +++ b/common/utils/hwctrace.h @@ -172,47 +172,47 @@ class TraceFunc { } #ifdef ENABLE_DISPLAY_DUMP -#define DUMP_CURRENT_COMPOSITION_PLANES() \ - static int frame_ = 0; \ - frame_++; \ - DUMPTRACE( \ - "Dumping DisplayPlaneState of Current Composition planes " \ - "-----------------------------"); \ - DUMPTRACE("Frame: %d", frame_); \ - DUMPTRACE("Total Layers for this Frame: %d", layers.size()); \ - DUMPTRACE("Total Planes in use for this Frame: %d", \ - current_composition_planes.size()); \ - int plane_index = 1; \ - for (DisplayPlaneState & comp_plane : current_composition_planes) { \ - DUMPTRACE("Composition Plane State for Index: %d", plane_index); \ - const std::vector &source_layers = comp_plane.source_layers(); \ - if (comp_plane.NeedsOffScreenComposition()) { \ - DUMPTRACE("DisplayPlane state: kRender. Total layers: %lu", \ - source_layers.size()); \ - DUMPTRACE("Layers Index:"); \ - for (size_t primary_index : source_layers) { \ - DUMPTRACE("index: %d", primary_index); \ - layers.at(primary_index).Dump(); \ - } \ - } else if (comp_plane.Scanout()) { \ - if (source_layers.size() > 1 && !comp_plane.SurfaceRecycled()) \ - DUMPTRACE( \ - "Plane has more than one layer associated when its type is " \ - "kScanout. This needs to be fixed."); \ - DUMPTRACE("DisplayPlane State: kScanout. Total layers: %lu", \ - source_layers.size()); \ - DUMPTRACE("Layers Index:"); \ - for (size_t overlay_index : source_layers) { \ - DUMPTRACE("index: %d", overlay_index); \ - layers.at(overlay_index).Dump(); \ - } \ - } \ - comp_plane.plane()->Dump(); \ - DUMPTRACE("Composition Plane State ends for Index: %d\n", plane_index); \ - plane_index++; \ - } \ - DUMPTRACE( \ - "Dumping DisplayPlaneState of Current Composition planes ends. " \ +#define DUMP_CURRENT_COMPOSITION_PLANES() \ + static int frame_ = 0; \ + frame_++; \ + DUMPTRACE( \ + "Dumping DisplayPlaneState of Current Composition planes " \ + "-----------------------------"); \ + DUMPTRACE("Frame: %d", frame_); \ + DUMPTRACE("Total Layers for this Frame: %d", layers.size()); \ + DUMPTRACE("Total Planes in use for this Frame: %d", \ + current_composition_planes.size()); \ + int plane_index = 1; \ + for (DisplayPlaneState & comp_plane : current_composition_planes) { \ + DUMPTRACE("Composition Plane State for Index: %d", plane_index); \ + const std::vector &source_layers = comp_plane.GetSourceLayers(); \ + if (comp_plane.NeedsOffScreenComposition()) { \ + DUMPTRACE("DisplayPlane state: kRender. Total layers: %lu", \ + source_layers.size()); \ + DUMPTRACE("Layers Index:"); \ + for (size_t primary_index : source_layers) { \ + DUMPTRACE("index: %d", primary_index); \ + layers.at(primary_index).Dump(); \ + } \ + } else if (comp_plane.Scanout()) { \ + if (source_layers.size() > 1 && !comp_plane.SurfaceRecycled()) \ + DUMPTRACE( \ + "Plane has more than one layer associated when its type is " \ + "kScanout. This needs to be fixed."); \ + DUMPTRACE("DisplayPlane State: kScanout. Total layers: %lu", \ + source_layers.size()); \ + DUMPTRACE("Layers Index:"); \ + for (size_t overlay_index : source_layers) { \ + DUMPTRACE("index: %d", overlay_index); \ + layers.at(overlay_index).Dump(); \ + } \ + } \ + comp_plane.GetDisplayPlane()->Dump(); \ + DUMPTRACE("Composition Plane State ends for Index: %d\n", plane_index); \ + plane_index++; \ + } \ + DUMPTRACE( \ + "Dumping DisplayPlaneState of Current Composition planes ends. " \ "-----------------------------\n"); #else #define DUMP_CURRENT_COMPOSITION_PLANES() ((void)0) diff --git a/wsi/drm/drmdisplay.cpp b/wsi/drm/drmdisplay.cpp index d192a12..d3c73ce 100644 --- a/wsi/drm/drmdisplay.cpp +++ b/wsi/drm/drmdisplay.cpp @@ -318,7 +318,7 @@ bool DrmDisplay::CommitFrame( } for (const DisplayPlaneState &comp_plane : comp_planes) { - DrmPlane *plane = static_cast(comp_plane.plane()); + DrmPlane *plane = static_cast(comp_plane.GetDisplayPlane()); const OverlayLayer *layer = comp_plane.GetOverlayLayer(); int32_t fence = layer->GetAcquireFence(); if (fence > 0) { @@ -331,7 +331,7 @@ bool DrmDisplay::CommitFrame( } for (const DisplayPlaneState &comp_plane : previous_composition_planes) { - DrmPlane *plane = static_cast(comp_plane.plane()); + DrmPlane *plane = static_cast(comp_plane.GetDisplayPlane()); if (plane->InUse()) continue; @@ -637,7 +637,7 @@ void DrmDisplay::Disable(const DisplayPlaneStateList &composition_planes) { IHOTPLUGEVENTTRACE("Disable: Disabling Display: %p", this); for (const DisplayPlaneState &comp_plane : composition_planes) { - DrmPlane *plane = static_cast(comp_plane.plane()); + DrmPlane *plane = static_cast(comp_plane.GetDisplayPlane()); plane->SetInUse(false); plane->SetNativeFence(-1); }