From 9028885f9e8b7db3ac48d525975d0008e666fa6e Mon Sep 17 00:00:00 2001 From: Vishnu Nair Date: Tue, 11 May 2021 21:59:27 -0700 Subject: Add more rounded corners tests Bug: 185597146 Test: atest LayerTypeAndRenderTypeTransactionTests/LayerTypeAndRenderTypeTransactionTest --rerun-until-failure 100 Change-Id: I989d0cdb7014321c24e2d76c9020486eb50352d5 --- .../LayerTypeAndRenderTypeTransaction_test.cpp | 192 +++++++++++++++++++++ 1 file changed, 192 insertions(+) diff --git a/services/surfaceflinger/tests/LayerTypeAndRenderTypeTransaction_test.cpp b/services/surfaceflinger/tests/LayerTypeAndRenderTypeTransaction_test.cpp index 2828d61a76..43d957cf7a 100644 --- a/services/surfaceflinger/tests/LayerTypeAndRenderTypeTransaction_test.cpp +++ b/services/surfaceflinger/tests/LayerTypeAndRenderTypeTransaction_test.cpp @@ -273,6 +273,198 @@ TEST_P(LayerTypeAndRenderTypeTransactionTest, SetCornerRadiusChildCrop) { } } +TEST_P(LayerTypeAndRenderTypeTransactionTest, SetCornerRadiusBufferRotationTransform) { + sp layer; + sp parent; + ASSERT_NO_FATAL_FAILURE( + parent = LayerTransactionTest::createLayer("parent", 0, 0, + ISurfaceComposerClient::eFXSurfaceEffect)); + + const uint32_t bufferWidth = 1500; + const uint32_t bufferHeight = 300; + + const uint32_t layerWidth = 300; + const uint32_t layerHeight = 1500; + + const uint32_t testArea = 4; + const float cornerRadius = 120.0f; + ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", bufferWidth, bufferHeight)); + ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED, bufferWidth, bufferHeight)); + + Transaction() + .reparent(layer, parent) + .setColor(parent, half3(0, 1, 0)) + .setCrop(parent, Rect(0, 0, layerWidth, layerHeight)) + .setCornerRadius(parent, cornerRadius) + + .setTransform(layer, ui::Transform::ROT_90) + .setDestinationFrame(layer, Rect(0, 0, layerWidth, layerHeight)) + .apply(); + { + auto shot = getScreenCapture(); + // Corners are transparent + // top-left + shot->expectColor(Rect(0, 0, testArea, testArea), Color::BLACK); + // top-right + shot->expectColor(Rect(layerWidth - testArea, 0, layerWidth, testArea), Color::BLACK); + // bottom-left + shot->expectColor(Rect(0, layerHeight - testArea, testArea, layerHeight), Color::BLACK); + // bottom-right + shot->expectColor(Rect(layerWidth - testArea, layerHeight - testArea, layerWidth, + layerHeight), + Color::BLACK); + + // Area after corner radius is solid + // top-left to top-right under the corner + shot->expectColor(Rect(0, cornerRadius, layerWidth, cornerRadius + testArea), Color::RED); + // bottom-left to bottom-right above the corner + shot->expectColor(Rect(0, layerHeight - cornerRadius - testArea, layerWidth, + layerHeight - cornerRadius), + Color::RED); + // left side after the corner + shot->expectColor(Rect(cornerRadius, 0, cornerRadius + testArea, layerHeight), Color::RED); + // right side before the corner + shot->expectColor(Rect(layerWidth - cornerRadius - testArea, 0, layerWidth - cornerRadius, + layerHeight), + Color::RED); + } +} + +TEST_P(LayerTypeAndRenderTypeTransactionTest, SetCornerRadiusBufferCropTransform) { + sp layer; + sp parent; + ASSERT_NO_FATAL_FAILURE( + parent = LayerTransactionTest::createLayer("parent", 0, 0, + ISurfaceComposerClient::eFXSurfaceEffect)); + + const uint32_t bufferWidth = 150 * 2; + const uint32_t bufferHeight = 750 * 2; + + const Rect bufferCrop(0, 0, 150, 750); + + const uint32_t layerWidth = 300; + const uint32_t layerHeight = 1500; + + const uint32_t testArea = 4; + const float cornerRadius = 120.0f; + ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", bufferWidth, bufferHeight)); + ASSERT_NO_FATAL_FAILURE(fillLayerQuadrant(layer, bufferWidth, bufferHeight, Color::RED, + Color::BLACK, Color::GREEN, Color::BLUE)); + + Transaction() + .reparent(layer, parent) + .setColor(parent, half3(0, 1, 0)) + .setCrop(parent, Rect(0, 0, layerWidth, layerHeight)) + .setCornerRadius(parent, cornerRadius) + + .setBufferCrop(layer, bufferCrop) + .setDestinationFrame(layer, Rect(0, 0, layerWidth, layerHeight)) + .apply(); + { + auto shot = getScreenCapture(); + // Corners are transparent + // top-left + shot->expectColor(Rect(0, 0, testArea, testArea), Color::BLACK); + // top-right + shot->expectColor(Rect(layerWidth - testArea, 0, layerWidth, testArea), Color::BLACK); + // bottom-left + shot->expectColor(Rect(0, layerHeight - testArea, testArea, layerHeight), Color::BLACK); + // bottom-right + shot->expectColor(Rect(layerWidth - testArea, layerHeight - testArea, layerWidth, + layerHeight), + Color::BLACK); + + // Area after corner radius is solid + // since the buffer is scaled, there will blending so adjust some of the bounds when + // checking. + float adjustedCornerRadius = cornerRadius + 15; + float adjustedLayerHeight = layerHeight - 15; + float adjustedLayerWidth = layerWidth - 15; + + // top-left to top-right under the corner + shot->expectColor(Rect(15, adjustedCornerRadius, adjustedLayerWidth, + adjustedCornerRadius + testArea), + Color::RED); + // bottom-left to bottom-right above the corner + shot->expectColor(Rect(15, adjustedLayerHeight - adjustedCornerRadius - testArea, + adjustedLayerWidth, adjustedLayerHeight - adjustedCornerRadius), + Color::RED); + // left side after the corner + shot->expectColor(Rect(adjustedCornerRadius, 15, adjustedCornerRadius + testArea, + adjustedLayerHeight), + Color::RED); + // right side before the corner + shot->expectColor(Rect(adjustedLayerWidth - adjustedCornerRadius - testArea, 15, + adjustedLayerWidth - adjustedCornerRadius, adjustedLayerHeight), + Color::RED); + } +} + +TEST_P(LayerTypeAndRenderTypeTransactionTest, SetCornerRadiusChildBufferRotationTransform) { + sp layer; + sp parent; + ASSERT_NO_FATAL_FAILURE( + parent = LayerTransactionTest::createLayer("parent", 0, 0, + ISurfaceComposerClient::eFXSurfaceEffect)); + + const uint32_t bufferWidth = 1500; + const uint32_t bufferHeight = 300; + + const uint32_t layerWidth = 300; + const uint32_t layerHeight = 1500; + + const uint32_t testArea = 4; + const float cornerRadius = 120.0f; + ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", bufferWidth, bufferHeight)); + ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::BLUE, bufferWidth, bufferHeight)); + + sp child; + ASSERT_NO_FATAL_FAILURE(child = createLayer("child", bufferWidth, bufferHeight)); + ASSERT_NO_FATAL_FAILURE(fillLayerColor(child, Color::RED, bufferWidth, bufferHeight)); + + Transaction() + .reparent(layer, parent) + .reparent(child, layer) + .setColor(parent, half3(0, 1, 0)) + .setCrop(parent, Rect(0, 0, layerWidth, layerHeight)) + .setCornerRadius(parent, cornerRadius) /* */ + + .setTransform(layer, ui::Transform::ROT_90) + .setDestinationFrame(layer, Rect(0, 0, layerWidth, layerHeight)) + + .setTransform(child, ui::Transform::ROT_90) + .setDestinationFrame(child, Rect(0, 0, layerWidth, layerHeight)) + .apply(); + { + auto shot = getScreenCapture(); + // Corners are transparent + // top-left + shot->expectColor(Rect(0, 0, testArea, testArea), Color::BLACK); + // top-right + shot->expectColor(Rect(layerWidth - testArea, 0, layerWidth, testArea), Color::BLACK); + // bottom-left + shot->expectColor(Rect(0, layerHeight - testArea, testArea, layerHeight), Color::BLACK); + // bottom-right + shot->expectColor(Rect(layerWidth - testArea, layerHeight - testArea, layerWidth, + layerHeight), + Color::BLACK); + + // Area after corner radius is solid + // top-left to top-right under the corner + shot->expectColor(Rect(0, cornerRadius, layerWidth, cornerRadius + testArea), Color::RED); + // bottom-left to bottom-right above the corner + shot->expectColor(Rect(0, layerHeight - cornerRadius - testArea, layerWidth, + layerHeight - cornerRadius), + Color::RED); + // left side after the corner + shot->expectColor(Rect(cornerRadius, 0, cornerRadius + testArea, layerHeight), Color::RED); + // right side before the corner + shot->expectColor(Rect(layerWidth - cornerRadius - testArea, 0, layerWidth - cornerRadius, + layerHeight), + Color::RED); + } +} + TEST_P(LayerTypeAndRenderTypeTransactionTest, SetBackgroundBlurRadiusSimple) { if (!deviceSupportsBlurs()) GTEST_SKIP(); if (!deviceUsesSkiaRenderEngine()) GTEST_SKIP(); -- cgit v1.2.3-59-g8ed1b