core/overlaylayer.cpp \
core/nesteddisplay.cpp \
display/displayplanemanager.cpp \
+ display/displayplanestate.cpp \
display/displayqueue.cpp \
display/vblankeventhandler.cpp \
display/virtualdisplay.cpp \
core/nesteddisplay.cpp \
display/displayqueue.cpp \
display/displayplanemanager.cpp \
+ display/displayplanestate.cpp \
display/vblankeventhandler.cpp \
display/virtualdisplay.cpp \
utils/fdhandler.cpp \
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();
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<CompositionRegion> &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);
}
// 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<NativeSurface *>().swap(last_plane.GetSurfaces());
+ last_plane.ReleaseSurfaces();
force_buffer = true;
}
ValidateFinalLayers(composition, layers);
for (DisplayPlaneState &plane : composition) {
if (plane.NeedsOffScreenComposition()) {
- const std::vector<size_t> &source_layers = plane.source_layers();
+ const std::vector<size_t> &source_layers = plane.GetSourceLayers();
size_t layers_size = source_layers.size();
bool useplanescalar = plane.IsUsingPlaneScalar();
for (size_t i = 0; i < layers_size; i++) {
std::vector<OverlayPlane> 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<size_t> &source = temp.source_layers();
+ const std::vector<size_t> &source = temp.GetSourceLayers();
size_t total_layers = source.size();
ValidateForDisplayScaling(
temp, commit_planes, &(layers.at(source.at(total_layers - 1))), true);
for (DisplayPlaneState &plane : composition) {
if (plane.NeedsOffScreenComposition()) {
render_layers = true;
- const std::vector<size_t> &source_layers = plane.source_layers();
+ const std::vector<size_t> &source_layers = plane.GetSourceLayers();
size_t layers_size = source_layers.size();
bool useplanescalar = plane.IsUsingPlaneScalar();
for (size_t i = 0; i < layers_size; i++) {
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;
std::vector<CompositionRegion> &comp_regions = plane->GetCompositionRegion();
std::vector<CompositionRegion>().swap(comp_regions);
- std::vector<NativeSurface *> &surfaces = plane->GetSurfaces();
+ const std::vector<NativeSurface *> &surfaces = plane->GetSurfaces();
size_t size = surfaces.size();
const HwcRect<int> ¤t_rect = plane->GetDisplayFrame();
for (size_t i = 0; i < size; i++) {
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();
std::vector<OverlayPlane>().swap(commit_planes);
for (DisplayPlaneState &temp : composition) {
commit_planes.emplace_back(
- OverlayPlane(temp.plane(), temp.GetOverlayLayer()));
+ OverlayPlane(temp.GetDisplayPlane(), temp.GetOverlayLayer()));
}
}
void DisplayPlaneManager::ValidateForDisplayScaling(
DisplayPlaneState &last_plane, std::vector<OverlayPlane> &commit_planes,
OverlayLayer *current_layer, bool ignore_format) {
- size_t total_layers = last_plane.source_layers().size();
- std::vector<NativeSurface *> &surfaces = last_plane.GetSurfaces();
+ size_t total_layers = last_plane.GetSourceLayers().size();
+ const std::vector<NativeSurface *> &surfaces = last_plane.GetSurfaces();
size_t size = surfaces.size();
if (last_plane.IsUsingPlaneScalar()) {
// return.
if (!ignore_format &&
(current_layer->GetPlaneTransform() == HWCTransform::kIdentity) &&
- last_plane.plane()->IsSupportedFormat(
+ last_plane.GetDisplayPlane()->IsSupportedFormat(
current_layer->GetBuffer()->GetFormat())) {
return;
}
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();
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_) {
}
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.
--- /dev/null
+/*
+// 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<int> &DisplayPlaneState::GetDisplayFrame() const {
+ return display_frame_;
+}
+
+const HwcRect<float> &DisplayPlaneState::GetSourceCrop() const {
+ return source_crop_;
+}
+
+void DisplayPlaneState::SetSourceCrop(const HwcRect<float> &crop) {
+ source_crop_ = crop;
+}
+
+void DisplayPlaneState::ResetSourceRectToDisplayFrame() {
+ source_crop_ = HwcRect<float>(display_frame_);
+}
+
+void DisplayPlaneState::AddLayer(const OverlayLayer *layer) {
+ const HwcRect<int> &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<float>(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<size_t> &source_layers,
+ const std::vector<OverlayLayer> &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<int> &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<float>(display_frame_);
+ } else {
+ for (const int &index : source_layers) {
+ source_layers_.emplace_back(index);
+ }
+ }
+}
+
+void DisplayPlaneState::UpdateDisplayFrame(const HwcRect<int> &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<float>(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<NativeSurface *> &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<NativeSurface *> 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<NativeSurface *> &DisplayPlaneState::GetSurfaces() const {
+ return surfaces_;
+}
+
+void DisplayPlaneState::ReleaseSurfaces() {
+ for (NativeSurface *surface : surfaces_) {
+ surface->SetInUse(false);
+ }
+
+ std::vector<NativeSurface *>().swap(surfaces_);
+}
+
+DisplayPlane *DisplayPlaneState::GetDisplayPlane() const {
+ return plane_;
+}
+
+const std::vector<size_t> &DisplayPlaneState::GetSourceLayers() const {
+ return source_layers_;
+}
+
+std::vector<CompositionRegion> &DisplayPlaneState::GetCompositionRegion() {
+ return composition_region_;
+}
+
+const std::vector<CompositionRegion> &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
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<int> &GetDisplayFrame() const {
- return display_frame_;
- }
-
- const HwcRect<float> &GetSourceCrop() const {
- return source_crop_;
- }
-
- void SetSourceCrop(const HwcRect<float> &crop) {
- source_crop_ = crop;
- }
-
- void ResetSourceRectToDisplayFrame() {
- source_crop_ = HwcRect<float>(display_frame_);
- }
-
- void AddLayer(const OverlayLayer *layer) {
- const HwcRect<int> &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<float>(display_frame_);
- }
+ DisplayPlaneState(DisplayPlane *plane, OverlayLayer *layer, uint32_t index);
+
+ // Copies plane state from state.
+ void CopyState(DisplayPlaneState &state);
+
+ void SetSourceCrop(const HwcRect<float> &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
// other cases.
void AddLayers(const std::vector<size_t> &source_layers,
const std::vector<OverlayLayer> &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<int> &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<float>(display_frame_);
- } else {
- for (const int &index : source_layers) {
- source_layers_.emplace_back(index);
- }
- }
- }
-
- void UpdateDisplayFrame(const HwcRect<int> &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<float>(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<NativeSurface *> &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<int> &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<NativeSurface *> 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<NativeSurface *> &GetSurfaces() const {
- return surfaces_;
- }
-
- std::vector<NativeSurface *> &GetSurfaces() {
- return surfaces_;
- }
-
- DisplayPlane *plane() const {
- return plane_;
- }
-
- const std::vector<size_t> &source_layers() const {
- return source_layers_;
- }
-
- std::vector<CompositionRegion> &GetCompositionRegion() {
- return composition_region_;
- }
-
- const std::vector<CompositionRegion> &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<NativeSurface *> &surfaces,
+ bool swap_front_buffer);
+
+ const HwcRect<int> &GetDisplayFrame() const;
+
+ const HwcRect<float> &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<NativeSurface *> &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<size_t> &GetSourceLayers() const;
+
+ std::vector<CompositionRegion> &GetCompositionRegion();
+
+ const std::vector<CompositionRegion> &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 {
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;
}
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<size_t>& source_layers = last_plane.source_layers();
+ const std::vector<size_t>& source_layers = last_plane.GetSourceLayers();
HwcRect<int> surface_damage = HwcRect<int>(0, 0, 0, 0);
size_t layers_size = source_layers.size();
// we need to clear the surface.
last_plane.TransferSurfaces(plane.GetSurfaces(),
content_changed || clear_surface);
- std::vector<NativeSurface*>& surfaces = last_plane.GetSurfaces();
+ const std::vector<NativeSurface*>& surfaces = last_plane.GetSurfaces();
size_t size = surfaces.size();
if (clear_surface || update_rect) {
content_changed = true;
if (last_plane.GetSurfaces().size() == 3) {
if (!clear_surface) {
HwcRect<int> last_damage;
- std::vector<NativeSurface*>& surfaces = last_plane.GetSurfaces();
+ const std::vector<NativeSurface*>& 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)
}
} 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_);
}
plane.SetApplyEffects(apply_effects);
- std::vector<NativeSurface*>& surfaces = plane.GetSurfaces();
+ const std::vector<NativeSurface*>& 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.
// 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<NativeSurface*>().swap(plane.GetSurfaces());
- const std::vector<size_t>& source = plane.source_layers();
+ plane.ReleaseSurfaces();
+ const std::vector<size_t>& source = plane.GetSourceLayers();
plane.SetOverlayLayer(&(layers.at(source.at(0))));
}
}
void DisplayQueue::UpdateSurfaceInUse(
bool in_use, DisplayPlaneStateList& current_composition_planes) {
for (DisplayPlaneState& plane_state : current_composition_planes) {
- std::vector<NativeSurface*>& surfaces = plane_state.GetSurfaces();
+ const std::vector<NativeSurface*>& surfaces = plane_state.GetSurfaces();
for (NativeSurface* surface : surfaces) {
surface->SetInUse(in_use);
}
void DisplayQueue::UpdateOnScreenSurfaces() {
for (DisplayPlaneState& plane_state : previous_plane_state_) {
- std::vector<NativeSurface*>& surfaces = plane_state.GetSurfaces();
+ const std::vector<NativeSurface*>& surfaces = plane_state.GetSurfaces();
if (surfaces.empty())
continue;
void DisplayQueue::RecyclePreviousPlaneSurfaces() {
for (DisplayPlaneState& plane_state : previous_plane_state_) {
- std::vector<NativeSurface*>& surfaces = plane_state.GetSurfaces();
+ const std::vector<NativeSurface*>& surfaces = plane_state.GetSurfaces();
if (surfaces.empty())
continue;
void DisplayQueue::SaveOnScreenSurfaces(
DisplayPlaneStateList& current_composition_planes) {
for (DisplayPlaneState& plane_state : current_composition_planes) {
- std::vector<NativeSurface*>& surfaces = plane_state.GetSurfaces();
+ const std::vector<NativeSurface*>& surfaces = plane_state.GetSurfaces();
if (surfaces.empty())
continue;
void DisplayQueue::SetReleaseFenceToLayers(
int32_t fence, std::vector<HwcLayer*>& source_layers) const {
for (const DisplayPlaneState& plane : previous_plane_state_) {
- const std::vector<size_t>& layers = plane.source_layers();
+ const std::vector<size_t>& layers = plane.GetSourceLayers();
size_t size = layers.size();
int32_t release_fence = -1;
if (plane.Scanout() && !plane.SurfaceRecycled()) {
}
#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<size_t> &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<size_t> &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)
}
for (const DisplayPlaneState &comp_plane : comp_planes) {
- DrmPlane *plane = static_cast<DrmPlane *>(comp_plane.plane());
+ DrmPlane *plane = static_cast<DrmPlane *>(comp_plane.GetDisplayPlane());
const OverlayLayer *layer = comp_plane.GetOverlayLayer();
int32_t fence = layer->GetAcquireFence();
if (fence > 0) {
}
for (const DisplayPlaneState &comp_plane : previous_composition_planes) {
- DrmPlane *plane = static_cast<DrmPlane *>(comp_plane.plane());
+ DrmPlane *plane = static_cast<DrmPlane *>(comp_plane.GetDisplayPlane());
if (plane->InUse())
continue;
IHOTPLUGEVENTTRACE("Disable: Disabling Display: %p", this);
for (const DisplayPlaneState &comp_plane : composition_planes) {
- DrmPlane *plane = static_cast<DrmPlane *>(comp_plane.plane());
+ DrmPlane *plane = static_cast<DrmPlane *>(comp_plane.GetDisplayPlane());
plane->SetInUse(false);
plane->SetNativeFence(-1);
}