SF: Move/Refactor Layer::setPerFrameData
Moves functionality out of ColorLayer, BufferLayer, BufferStateLayer and
BufferQueueLayer related to setting the per-frame data.
Instead each of the front-end classes now implements a minimal function
to set the per-frame state into the LayerFECompositionState structure.
compositionengine::OutputLayer now takes care of sending the state to
the HWC, and in particular with detecting when client composition needs
to be forced due to lack of HWC support (though the front-end can also
set a flag to force client composition for a few things it knows about).
SurfaceFlinger::calculateWorkingSet is also refactored to work with the
changes made, and prepare it to be moved over to CompositionEngine.
Test: atest libsurfaceflinger_unittest libcompositionengine_test
Test: atest CtsColorModeTestCases
Test: atest CtsDisplayTestCases
Test: atest CtsGraphicsTestCases
Test: atest CtsUiRenderingTestCases
Test: atest CtsViewTestCases
Test: atest android.media.cts.EncodeVirtualDisplayWithCompositionTest
Bug: 121291683
Change-Id: I2cb0442f68ec5c5f65f5b4cb418dda4c42e5dc39
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index 414c8dd..c3da653 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -242,20 +242,6 @@
// h/w composer set-up
// ---------------------------------------------------------------------------
-bool Layer::hasHwcLayer(const sp<const DisplayDevice>& displayDevice) {
- auto outputLayer = findOutputLayerForDisplay(displayDevice);
- LOG_FATAL_IF(!outputLayer);
- return outputLayer->getState().hwc && (*outputLayer->getState().hwc).hwcLayer != nullptr;
-}
-
-HWC2::Layer* Layer::getHwcLayer(const sp<const DisplayDevice>& displayDevice) {
- auto outputLayer = findOutputLayerForDisplay(displayDevice);
- if (!outputLayer || !outputLayer->getState().hwc) {
- return nullptr;
- }
- return (*outputLayer->getState().hwc).hwcLayer.get();
-}
-
Rect Layer::getContentCrop() const {
// this is the crop rectangle that applies to the buffer
// itself (as opposed to the window)
@@ -454,29 +440,38 @@
compositionState.appId = appId;
}
+void Layer::latchPerFrameState(compositionengine::LayerFECompositionState& compositionState) const {
+ compositionState.forceClientComposition = false;
+
+ // TODO(lpique): b/121291683 Remove this one we are sure we don't need the
+ // value recomputed / set every frame.
+ compositionState.geomVisibleRegion = visibleRegion;
+
+ compositionState.isColorspaceAgnostic = isColorSpaceAgnostic();
+ compositionState.dataspace = mCurrentDataSpace;
+ compositionState.colorTransform = getColorTransform();
+ compositionState.colorTransformIsIdentity = !hasColorTransform();
+ compositionState.surfaceDamage = surfaceDamageRegion;
+
+ // Force client composition for special cases known only to the front-end.
+ if (isHdrY410() || getRoundedCornerState().radius > 0.0f) {
+ compositionState.forceClientComposition = true;
+ }
+}
+
void Layer::latchCompositionState(compositionengine::LayerFECompositionState& compositionState,
bool includeGeometry) const {
if (includeGeometry) {
latchGeometry(compositionState);
}
+
+ latchPerFrameState(compositionState);
}
const char* Layer::getDebugName() const {
return mName.string();
}
-void Layer::forceClientComposition(const sp<DisplayDevice>& display) {
- const auto outputLayer = findOutputLayerForDisplay(display);
- LOG_FATAL_IF(!outputLayer);
- outputLayer->editState().forceClientComposition = true;
-}
-
-bool Layer::getForceClientComposition(const sp<DisplayDevice>& display) {
- const auto outputLayer = findOutputLayerForDisplay(display);
- LOG_FATAL_IF(!outputLayer);
- return outputLayer->getState().forceClientComposition;
-}
-
void Layer::updateCursorPosition(const sp<const DisplayDevice>& display) {
const auto outputLayer = findOutputLayerForDisplay(display);
LOG_FATAL_IF(!outputLayer);
@@ -563,29 +558,6 @@
return true;
}
-void Layer::setCompositionType(const sp<const DisplayDevice>& display,
- Hwc2::IComposerClient::Composition type) {
- const auto outputLayer = findOutputLayerForDisplay(display);
- LOG_FATAL_IF(!outputLayer);
- LOG_FATAL_IF(!outputLayer->getState().hwc);
- auto& compositionState = outputLayer->editState();
-
- ALOGV("setCompositionType(%" PRIx64 ", %s, %d)", ((*compositionState.hwc).hwcLayer)->getId(),
- toString(type).c_str(), 1);
- if ((*compositionState.hwc).hwcCompositionType != type) {
- ALOGV(" actually setting");
- (*compositionState.hwc).hwcCompositionType = type;
-
- auto error = (*compositionState.hwc)
- .hwcLayer->setCompositionType(static_cast<HWC2::Composition>(type));
- ALOGE_IF(error != HWC2::Error::None,
- "[%s] Failed to set "
- "composition type %s: %s (%d)",
- mName.string(), toString(type).c_str(), to_string(error).c_str(),
- static_cast<int32_t>(error));
- }
-}
-
Hwc2::IComposerClient::Composition Layer::getCompositionType(
const sp<const DisplayDevice>& display) const {
const auto outputLayer = findOutputLayerForDisplay(display);