blob: eaf54e38ec20701b25fd2f8538b873d3fcbdf3c2 [file] [log] [blame]
Valerie Hau9cfc6d82019-09-23 13:54:07 -07001/*
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 Abrahamb0dbdaa2020-01-06 16:19:42 -080017// TODO(b/129481165): remove the #pragma below and fix conversion issues
18#pragma clang diagnostic push
19#pragma clang diagnostic ignored "-Wconversion"
20
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -080021#include <ui/DisplayState.h>
22
Valerie Hau9cfc6d82019-09-23 13:54:07 -070023#include "LayerTransactionTest.h"
24
25namespace android {
26
27using android::hardware::graphics::common::V1_1::BufferUsage;
28
29::testing::Environment* const binderEnv =
30 ::testing::AddGlobalTestEnvironment(new BinderEnvironment());
31
32class MultiDisplayLayerBoundsTest : public LayerTransactionTest {
33protected:
34 virtual void SetUp() {
35 LayerTransactionTest::SetUp();
36 ASSERT_EQ(NO_ERROR, mClient->initCheck());
37
38 mMainDisplay = SurfaceComposerClient::getInternalDisplayToken();
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -080039 SurfaceComposerClient::getDisplayState(mMainDisplay, &mMainDisplayState);
Marin Shalamanova7fe3042021-01-29 21:02:08 +010040 SurfaceComposerClient::getActiveDisplayMode(mMainDisplay, &mMainDisplayMode);
Valerie Hau9cfc6d82019-09-23 13:54:07 -070041
42 sp<IGraphicBufferConsumer> consumer;
43 BufferQueue::createBufferQueue(&mProducer, &consumer);
44 consumer->setConsumerName(String8("Virtual disp consumer"));
Marin Shalamanova7fe3042021-01-29 21:02:08 +010045 consumer->setDefaultBufferSize(mMainDisplayMode.resolution.getWidth(),
46 mMainDisplayMode.resolution.getHeight());
Valerie Hau9cfc6d82019-09-23 13:54:07 -070047 }
48
49 virtual void TearDown() {
50 SurfaceComposerClient::destroyDisplay(mVirtualDisplay);
51 LayerTransactionTest::TearDown();
52 mColorLayer = 0;
53 }
54
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -080055 void createDisplay(const ui::Size& layerStackSize, uint32_t layerStack) {
Valerie Hau9cfc6d82019-09-23 13:54:07 -070056 mVirtualDisplay =
57 SurfaceComposerClient::createDisplay(String8("VirtualDisplay"), false /*secure*/);
58 asTransaction([&](Transaction& t) {
59 t.setDisplaySurface(mVirtualDisplay, mProducer);
60 t.setDisplayLayerStack(mVirtualDisplay, layerStack);
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -080061 t.setDisplayProjection(mVirtualDisplay, mMainDisplayState.orientation,
Marin Shalamanova7fe3042021-01-29 21:02:08 +010062 Rect(layerStackSize), Rect(mMainDisplayMode.resolution));
Valerie Hau9cfc6d82019-09-23 13:54:07 -070063 });
64 }
65
66 void createColorLayer(uint32_t layerStack) {
67 mColorLayer =
68 createSurface(mClient, "ColorLayer", 0 /* buffer width */, 0 /* buffer height */,
Vishnu Nairfa247b12020-02-11 08:58:26 -080069 PIXEL_FORMAT_RGBA_8888, ISurfaceComposerClient::eFXSurfaceEffect);
Valerie Hau9cfc6d82019-09-23 13:54:07 -070070 ASSERT_TRUE(mColorLayer != nullptr);
71 ASSERT_TRUE(mColorLayer->isValid());
72 asTransaction([&](Transaction& t) {
73 t.setLayerStack(mColorLayer, layerStack);
74 t.setCrop_legacy(mColorLayer, Rect(0, 0, 30, 40));
75 t.setLayer(mColorLayer, INT32_MAX - 2);
76 t.setColor(mColorLayer,
77 half3{mExpectedColor.r / 255.0f, mExpectedColor.g / 255.0f,
78 mExpectedColor.b / 255.0f});
79 t.show(mColorLayer);
80 });
81 }
82
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -080083 ui::DisplayState mMainDisplayState;
Marin Shalamanova7fe3042021-01-29 21:02:08 +010084 ui::DisplayMode mMainDisplayMode;
Valerie Hau9cfc6d82019-09-23 13:54:07 -070085 sp<IBinder> mMainDisplay;
86 sp<IBinder> mVirtualDisplay;
87 sp<IGraphicBufferProducer> mProducer;
88 sp<SurfaceControl> mColorLayer;
89 Color mExpectedColor = {63, 63, 195, 255};
90};
91
92TEST_F(MultiDisplayLayerBoundsTest, RenderLayerInVirtualDisplay) {
Marin Shalamanov6ad317c2020-07-29 23:34:07 +020093 createDisplay(mMainDisplayState.layerStackSpaceRect, 1 /* layerStack */);
Valerie Hau9cfc6d82019-09-23 13:54:07 -070094 createColorLayer(1 /* layerStack */);
95
96 asTransaction([&](Transaction& t) { t.setPosition(mColorLayer, 10, 10); });
97
98 // Verify color layer does not render on main display.
99 std::unique_ptr<ScreenCapture> sc;
100 ScreenCapture::captureScreen(&sc, mMainDisplay);
101 sc->expectColor(Rect(10, 10, 40, 50), {0, 0, 0, 255});
102 sc->expectColor(Rect(0, 0, 9, 9), {0, 0, 0, 255});
103
104 // Verify color layer renders correctly on virtual display.
105 ScreenCapture::captureScreen(&sc, mVirtualDisplay);
106 sc->expectColor(Rect(10, 10, 40, 50), mExpectedColor);
Alec Mouri5a6d8572020-03-23 23:56:15 -0700107 sc->expectColor(Rect(1, 1, 9, 9), {0, 0, 0, 255});
Valerie Hau9cfc6d82019-09-23 13:54:07 -0700108}
109
110TEST_F(MultiDisplayLayerBoundsTest, RenderLayerInMirroredVirtualDisplay) {
111 // Create a display and set its layer stack to the main display's layer stack so
112 // the contents of the main display are mirrored on to the virtual display.
113
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200114 // Assumption here is that the new mirrored display has the same layer stack rect as the
Valerie Hau9cfc6d82019-09-23 13:54:07 -0700115 // primary display that it is mirroring.
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200116 createDisplay(mMainDisplayState.layerStackSpaceRect, 0 /* layerStack */);
Valerie Hau9cfc6d82019-09-23 13:54:07 -0700117 createColorLayer(0 /* layerStack */);
118
119 asTransaction([&](Transaction& t) { t.setPosition(mColorLayer, 10, 10); });
120
121 // Verify color layer renders correctly on main display and it is mirrored on the
122 // virtual display.
123 std::unique_ptr<ScreenCapture> sc;
124 ScreenCapture::captureScreen(&sc, mMainDisplay);
125 sc->expectColor(Rect(10, 10, 40, 50), mExpectedColor);
126 sc->expectColor(Rect(0, 0, 9, 9), {0, 0, 0, 255});
127
128 ScreenCapture::captureScreen(&sc, mVirtualDisplay);
129 sc->expectColor(Rect(10, 10, 40, 50), mExpectedColor);
130 sc->expectColor(Rect(0, 0, 9, 9), {0, 0, 0, 255});
131}
132
133} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -0800134
135// TODO(b/129481165): remove the #pragma below and fix conversion issues
136#pragma clang diagnostic pop // ignored "-Wconversion"