Fix filtering for screenshotting custom displays.
Previously, filtering was computed for screenshots by checking if
filtering was required for the DisplayDevice itself. That's correct for
rendering custom display sizes since we need to upsample to the
physical panel, but it's wrong for screenshotting to an output buffer
where the logical transform does not involve a scale. Instead, we want
to compare the source crop with the destination buffer size when
determining whether we need to apply linear filtering.
As part of this, some of the rendering math is now simpler. Rather than
setting DisplaySettings::physicalDisplay and DisplaySettings::clip to be
the same and explicitly computing the transform matrix in RenderEngine,
we instead set DisplaySettings::clip to be the logical viewport. Then
the global transform is implicitly applied as part of mapping the output
in glViewport. This is because if the logical display is smaller than
the screen size, with the previous behavior applying the global transform
will scale up the layer stack to the physical display size. But if we
want pixel-accurate screenshots we will need to downsample back down to
the logical display size, which may cause errors. The math simplification
will avoid that scenario entirely.
This also means that screenshot code needs to be adjusted - some callers
pass in a cropping rectangle that assumes the display screenshot is
captured in portrait orientation. Other callers pass in a cropping
rectangle relative to a particular layer's coordinate space. For each of
those paths, the cropping rectangle must be transformed to the logical
display space.
This has also discovered a bug in setting the background fill of the
screenshot, which has now been fixed.
Bug: 129101431
Test: adb shell screepcap
Test: Modify wm size and density, and run
SurfaceViewTests#testMovingWhiteSurfaceView
Test: Capture screenshots through vysor
Test: Capture screenshots on Pixel 3XL with notch hide
Test: Physically capture screenshots
Test: Display rotations
Test: SurfaceFlinger_test
Test: librenderengine_test
Test: libsurfaceflinger_unittest
Test: libcompositionengine_test
Change-Id: I7f4e98d4c5aa53a995fd7da70078a2e5ea43b14f
diff --git a/libs/renderengine/gl/GLESRenderEngine.cpp b/libs/renderengine/gl/GLESRenderEngine.cpp
index e73f245..d56a82f 100644
--- a/libs/renderengine/gl/GLESRenderEngine.cpp
+++ b/libs/renderengine/gl/GLESRenderEngine.cpp
@@ -795,6 +795,7 @@
// Firstly, we need to convert the coordination from layer native coordination space to
// device coordination space.
+ // TODO(143929254): Verify that this transformation is correct
const auto transformMatrix = display.globalTransform * layer.geometry.positionTransform;
const vec4 leftTopCoordinate(bounds.left, bounds.top, 1.0, 1.0);
const vec4 rightBottomCoordinate(bounds.right, bounds.bottom, 1.0, 1.0);
@@ -1015,8 +1016,8 @@
setOutputDataSpace(display.outputDataspace);
setDisplayMaxLuminance(display.maxLuminance);
- mat4 projectionMatrix = mState.projectionMatrix * display.globalTransform;
- mState.projectionMatrix = projectionMatrix;
+ const mat4 projectionMatrix =
+ ui::Transform(display.orientation).asMatrix4() * mState.projectionMatrix;
if (!display.clearRegion.isEmpty()) {
glDisable(GL_BLEND);
fillRegionWithColor(display.clearRegion, 0.0, 0.0, 0.0, 1.0);
diff --git a/libs/renderengine/include/renderengine/DisplaySettings.h b/libs/renderengine/include/renderengine/DisplaySettings.h
index c4a29a9..c0766ab 100644
--- a/libs/renderengine/include/renderengine/DisplaySettings.h
+++ b/libs/renderengine/include/renderengine/DisplaySettings.h
@@ -41,6 +41,13 @@
Rect clip = Rect::INVALID_RECT;
// Global transform to apply to all layers.
+ // The global transform is assumed to automatically apply when projecting
+ // the clip rectangle onto the physical display; however, this should be
+ // explicitly provided to perform CPU-side optimizations such as computing
+ // scissor rectangles for rounded corners which require transformation to
+ // the phsical display space.
+ //
+ // This transform is also assumed to include the orientation flag below.
mat4 globalTransform = mat4();
// Maximum luminance pulled from the display's HDR capabilities.
@@ -60,7 +67,10 @@
// rendered layers.
Region clearRegion = Region::INVALID_REGION;
- // The orientation of the physical display.
+ // An additional orientation flag to be applied after clipping the output.
+ // By way of example, this may be used for supporting fullscreen screenshot
+ // capture of a device in landscape while the buffer is in portrait
+ // orientation.
uint32_t orientation = ui::Transform::ROT_0;
};
diff --git a/libs/renderengine/tests/RenderEngineTest.cpp b/libs/renderengine/tests/RenderEngineTest.cpp
index afcbc50..ce9131d 100644
--- a/libs/renderengine/tests/RenderEngineTest.cpp
+++ b/libs/renderengine/tests/RenderEngineTest.cpp
@@ -298,7 +298,7 @@
void fillBufferPhysicalOffset();
template <typename SourceVariant>
- void fillBufferCheckers(mat4 transform);
+ void fillBufferCheckers(uint32_t rotation);
template <typename SourceVariant>
void fillBufferCheckersRotate0();
@@ -509,12 +509,12 @@
}
template <typename SourceVariant>
-void RenderEngineTest::fillBufferCheckers(mat4 transform) {
+void RenderEngineTest::fillBufferCheckers(uint32_t orientationFlag) {
renderengine::DisplaySettings settings;
settings.physicalDisplay = fullscreenRect();
// Here logical space is 2x2
settings.clip = Rect(2, 2);
- settings.globalTransform = transform;
+ settings.orientation = orientationFlag;
std::vector<const renderengine::LayerSettings*> layers;
@@ -545,7 +545,7 @@
template <typename SourceVariant>
void RenderEngineTest::fillBufferCheckersRotate0() {
- fillBufferCheckers<SourceVariant>(mat4());
+ fillBufferCheckers<SourceVariant>(ui::Transform::ROT_0);
expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2), 255, 0, 0,
255);
expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, 0, DEFAULT_DISPLAY_WIDTH,
@@ -561,8 +561,7 @@
template <typename SourceVariant>
void RenderEngineTest::fillBufferCheckersRotate90() {
- mat4 matrix = mat4(0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 2, 0, 0, 1);
- fillBufferCheckers<SourceVariant>(matrix);
+ fillBufferCheckers<SourceVariant>(ui::Transform::ROT_90);
expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2), 0, 255, 0,
255);
expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, 0, DEFAULT_DISPLAY_WIDTH,
@@ -578,8 +577,7 @@
template <typename SourceVariant>
void RenderEngineTest::fillBufferCheckersRotate180() {
- mat4 matrix = mat4(-1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 2, 2, 0, 1);
- fillBufferCheckers<SourceVariant>(matrix);
+ fillBufferCheckers<SourceVariant>(ui::Transform::ROT_180);
expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2), 0, 0, 0,
0);
expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, 0, DEFAULT_DISPLAY_WIDTH,
@@ -595,8 +593,7 @@
template <typename SourceVariant>
void RenderEngineTest::fillBufferCheckersRotate270() {
- mat4 matrix = mat4(0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 1);
- fillBufferCheckers<SourceVariant>(matrix);
+ fillBufferCheckers<SourceVariant>(ui::Transform::ROT_270);
expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2), 0, 0, 255,
255);
expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, 0, DEFAULT_DISPLAY_WIDTH,
@@ -928,7 +925,7 @@
// Here logical space is 4x4
settings.clip = Rect(4, 4);
settings.globalTransform = mat4::scale(vec4(2, 4, 0, 1));
- settings.clearRegion = Region(Rect(1, 1));
+ settings.clearRegion = Region(Rect(2, 4));
std::vector<const renderengine::LayerSettings*> layers;
// dummy layer, without bounds should not render anything
renderengine::LayerSettings layer;