Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 17 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 18 | #pragma clang diagnostic push |
| 19 | #pragma clang diagnostic ignored "-Wconversion" |
| 20 | |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 21 | #include <ui/DisplayState.h> |
| 22 | |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 23 | #include "LayerTransactionTest.h" |
| 24 | |
| 25 | namespace android { |
| 26 | |
| 27 | using android::hardware::graphics::common::V1_1::BufferUsage; |
| 28 | |
| 29 | ::testing::Environment* const binderEnv = |
| 30 | ::testing::AddGlobalTestEnvironment(new BinderEnvironment()); |
| 31 | |
| 32 | class MultiDisplayLayerBoundsTest : public LayerTransactionTest { |
| 33 | protected: |
| 34 | virtual void SetUp() { |
| 35 | LayerTransactionTest::SetUp(); |
| 36 | ASSERT_EQ(NO_ERROR, mClient->initCheck()); |
| 37 | |
Huihong Luo | 31b5ac2 | 2022-08-15 20:38:10 -0700 | [diff] [blame^] | 38 | const auto ids = SurfaceComposerClient::getPhysicalDisplayIds(); |
| 39 | ASSERT_FALSE(ids.empty()); |
| 40 | mMainDisplay = SurfaceComposerClient::getPhysicalDisplayToken(ids.front()); |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 41 | SurfaceComposerClient::getDisplayState(mMainDisplay, &mMainDisplayState); |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 42 | SurfaceComposerClient::getActiveDisplayMode(mMainDisplay, &mMainDisplayMode); |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 43 | |
| 44 | sp<IGraphicBufferConsumer> consumer; |
| 45 | BufferQueue::createBufferQueue(&mProducer, &consumer); |
| 46 | consumer->setConsumerName(String8("Virtual disp consumer")); |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 47 | consumer->setDefaultBufferSize(mMainDisplayMode.resolution.getWidth(), |
| 48 | mMainDisplayMode.resolution.getHeight()); |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | virtual void TearDown() { |
| 52 | SurfaceComposerClient::destroyDisplay(mVirtualDisplay); |
| 53 | LayerTransactionTest::TearDown(); |
| 54 | mColorLayer = 0; |
| 55 | } |
| 56 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 57 | void createDisplay(const ui::Size& layerStackSize, ui::LayerStack layerStack) { |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 58 | mVirtualDisplay = |
| 59 | SurfaceComposerClient::createDisplay(String8("VirtualDisplay"), false /*secure*/); |
| 60 | asTransaction([&](Transaction& t) { |
| 61 | t.setDisplaySurface(mVirtualDisplay, mProducer); |
| 62 | t.setDisplayLayerStack(mVirtualDisplay, layerStack); |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 63 | t.setDisplayProjection(mVirtualDisplay, mMainDisplayState.orientation, |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 64 | Rect(layerStackSize), Rect(mMainDisplayMode.resolution)); |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 65 | }); |
| 66 | } |
| 67 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 68 | void createColorLayer(ui::LayerStack layerStack) { |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 69 | mColorLayer = |
| 70 | createSurface(mClient, "ColorLayer", 0 /* buffer width */, 0 /* buffer height */, |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame] | 71 | PIXEL_FORMAT_RGBA_8888, ISurfaceComposerClient::eFXSurfaceEffect); |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 72 | ASSERT_TRUE(mColorLayer != nullptr); |
| 73 | ASSERT_TRUE(mColorLayer->isValid()); |
| 74 | asTransaction([&](Transaction& t) { |
| 75 | t.setLayerStack(mColorLayer, layerStack); |
chaviw | 2571450 | 2021-02-11 10:01:08 -0800 | [diff] [blame] | 76 | t.setCrop(mColorLayer, Rect(0, 0, 30, 40)); |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 77 | t.setLayer(mColorLayer, INT32_MAX - 2); |
| 78 | t.setColor(mColorLayer, |
| 79 | half3{mExpectedColor.r / 255.0f, mExpectedColor.g / 255.0f, |
| 80 | mExpectedColor.b / 255.0f}); |
| 81 | t.show(mColorLayer); |
| 82 | }); |
| 83 | } |
| 84 | |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 85 | ui::DisplayState mMainDisplayState; |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 86 | ui::DisplayMode mMainDisplayMode; |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 87 | sp<IBinder> mMainDisplay; |
| 88 | sp<IBinder> mVirtualDisplay; |
| 89 | sp<IGraphicBufferProducer> mProducer; |
| 90 | sp<SurfaceControl> mColorLayer; |
| 91 | Color mExpectedColor = {63, 63, 195, 255}; |
| 92 | }; |
| 93 | |
| 94 | TEST_F(MultiDisplayLayerBoundsTest, RenderLayerInVirtualDisplay) { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 95 | constexpr ui::LayerStack kLayerStack{1u}; |
| 96 | createDisplay(mMainDisplayState.layerStackSpaceRect, kLayerStack); |
| 97 | createColorLayer(kLayerStack); |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 98 | |
| 99 | asTransaction([&](Transaction& t) { t.setPosition(mColorLayer, 10, 10); }); |
| 100 | |
| 101 | // Verify color layer does not render on main display. |
| 102 | std::unique_ptr<ScreenCapture> sc; |
| 103 | ScreenCapture::captureScreen(&sc, mMainDisplay); |
| 104 | sc->expectColor(Rect(10, 10, 40, 50), {0, 0, 0, 255}); |
| 105 | sc->expectColor(Rect(0, 0, 9, 9), {0, 0, 0, 255}); |
| 106 | |
| 107 | // Verify color layer renders correctly on virtual display. |
| 108 | ScreenCapture::captureScreen(&sc, mVirtualDisplay); |
| 109 | sc->expectColor(Rect(10, 10, 40, 50), mExpectedColor); |
Alec Mouri | 5a6d857 | 2020-03-23 23:56:15 -0700 | [diff] [blame] | 110 | sc->expectColor(Rect(1, 1, 9, 9), {0, 0, 0, 255}); |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | TEST_F(MultiDisplayLayerBoundsTest, RenderLayerInMirroredVirtualDisplay) { |
| 114 | // Create a display and set its layer stack to the main display's layer stack so |
| 115 | // the contents of the main display are mirrored on to the virtual display. |
| 116 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 117 | // Assumption here is that the new mirrored display has the same layer stack rect as the |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 118 | // primary display that it is mirroring. |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 119 | createDisplay(mMainDisplayState.layerStackSpaceRect, ui::DEFAULT_LAYER_STACK); |
| 120 | createColorLayer(ui::DEFAULT_LAYER_STACK); |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 121 | |
| 122 | asTransaction([&](Transaction& t) { t.setPosition(mColorLayer, 10, 10); }); |
| 123 | |
| 124 | // Verify color layer renders correctly on main display and it is mirrored on the |
| 125 | // virtual display. |
| 126 | std::unique_ptr<ScreenCapture> sc; |
| 127 | ScreenCapture::captureScreen(&sc, mMainDisplay); |
| 128 | sc->expectColor(Rect(10, 10, 40, 50), mExpectedColor); |
| 129 | sc->expectColor(Rect(0, 0, 9, 9), {0, 0, 0, 255}); |
| 130 | |
| 131 | ScreenCapture::captureScreen(&sc, mVirtualDisplay); |
| 132 | sc->expectColor(Rect(10, 10, 40, 50), mExpectedColor); |
| 133 | sc->expectColor(Rect(0, 0, 9, 9), {0, 0, 0, 255}); |
| 134 | } |
| 135 | |
| 136 | } // namespace android |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 137 | |
| 138 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 139 | #pragma clang diagnostic pop // ignored "-Wconversion" |