blob: e525e2af9bf0cb627cbc264a35670963ee43c41f [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
Valerie Hau9cfc6d82019-09-23 13:54:07 -070021#include "LayerTransactionTest.h"
22
23namespace android {
24
25using android::hardware::graphics::common::V1_1::BufferUsage;
26
27::testing::Environment* const binderEnv =
28 ::testing::AddGlobalTestEnvironment(new BinderEnvironment());
29
30class MultiDisplayLayerBoundsTest : public LayerTransactionTest {
31protected:
32 virtual void SetUp() {
33 LayerTransactionTest::SetUp();
34 ASSERT_EQ(NO_ERROR, mClient->initCheck());
35
36 mMainDisplay = SurfaceComposerClient::getInternalDisplayToken();
37 SurfaceComposerClient::getDisplayInfo(mMainDisplay, &mMainDisplayInfo);
38
39 sp<IGraphicBufferConsumer> consumer;
40 BufferQueue::createBufferQueue(&mProducer, &consumer);
41 consumer->setConsumerName(String8("Virtual disp consumer"));
42 consumer->setDefaultBufferSize(mMainDisplayInfo.w, mMainDisplayInfo.h);
43 }
44
45 virtual void TearDown() {
46 SurfaceComposerClient::destroyDisplay(mVirtualDisplay);
47 LayerTransactionTest::TearDown();
48 mColorLayer = 0;
49 }
50
51 void createDisplay(const Rect& layerStackRect, uint32_t layerStack) {
52 mVirtualDisplay =
53 SurfaceComposerClient::createDisplay(String8("VirtualDisplay"), false /*secure*/);
54 asTransaction([&](Transaction& t) {
55 t.setDisplaySurface(mVirtualDisplay, mProducer);
56 t.setDisplayLayerStack(mVirtualDisplay, layerStack);
57 t.setDisplayProjection(mVirtualDisplay, mMainDisplayInfo.orientation, layerStackRect,
58 Rect(mMainDisplayInfo.w, mMainDisplayInfo.h));
59 });
60 }
61
62 void createColorLayer(uint32_t layerStack) {
63 mColorLayer =
64 createSurface(mClient, "ColorLayer", 0 /* buffer width */, 0 /* buffer height */,
65 PIXEL_FORMAT_RGBA_8888, ISurfaceComposerClient::eFXSurfaceColor);
66 ASSERT_TRUE(mColorLayer != nullptr);
67 ASSERT_TRUE(mColorLayer->isValid());
68 asTransaction([&](Transaction& t) {
69 t.setLayerStack(mColorLayer, layerStack);
70 t.setCrop_legacy(mColorLayer, Rect(0, 0, 30, 40));
71 t.setLayer(mColorLayer, INT32_MAX - 2);
72 t.setColor(mColorLayer,
73 half3{mExpectedColor.r / 255.0f, mExpectedColor.g / 255.0f,
74 mExpectedColor.b / 255.0f});
75 t.show(mColorLayer);
76 });
77 }
78
79 DisplayInfo mMainDisplayInfo;
80 sp<IBinder> mMainDisplay;
81 sp<IBinder> mVirtualDisplay;
82 sp<IGraphicBufferProducer> mProducer;
83 sp<SurfaceControl> mColorLayer;
84 Color mExpectedColor = {63, 63, 195, 255};
85};
86
87TEST_F(MultiDisplayLayerBoundsTest, RenderLayerInVirtualDisplay) {
88 createDisplay({mMainDisplayInfo.viewportW, mMainDisplayInfo.viewportH}, 1 /* layerStack */);
89 createColorLayer(1 /* layerStack */);
90
91 asTransaction([&](Transaction& t) { t.setPosition(mColorLayer, 10, 10); });
92
93 // Verify color layer does not render on main display.
94 std::unique_ptr<ScreenCapture> sc;
95 ScreenCapture::captureScreen(&sc, mMainDisplay);
96 sc->expectColor(Rect(10, 10, 40, 50), {0, 0, 0, 255});
97 sc->expectColor(Rect(0, 0, 9, 9), {0, 0, 0, 255});
98
99 // Verify color layer renders correctly on virtual display.
100 ScreenCapture::captureScreen(&sc, mVirtualDisplay);
101 sc->expectColor(Rect(10, 10, 40, 50), mExpectedColor);
102 sc->expectColor(Rect(1, 1, 9, 9), {0, 0, 0, 0});
103}
104
105TEST_F(MultiDisplayLayerBoundsTest, RenderLayerInMirroredVirtualDisplay) {
106 // Create a display and set its layer stack to the main display's layer stack so
107 // the contents of the main display are mirrored on to the virtual display.
108
109 // Assumption here is that the new mirrored display has the same viewport as the
110 // primary display that it is mirroring.
111 createDisplay({mMainDisplayInfo.viewportW, mMainDisplayInfo.viewportH}, 0 /* layerStack */);
112 createColorLayer(0 /* layerStack */);
113
114 asTransaction([&](Transaction& t) { t.setPosition(mColorLayer, 10, 10); });
115
116 // Verify color layer renders correctly on main display and it is mirrored on the
117 // virtual display.
118 std::unique_ptr<ScreenCapture> sc;
119 ScreenCapture::captureScreen(&sc, mMainDisplay);
120 sc->expectColor(Rect(10, 10, 40, 50), mExpectedColor);
121 sc->expectColor(Rect(0, 0, 9, 9), {0, 0, 0, 255});
122
123 ScreenCapture::captureScreen(&sc, mVirtualDisplay);
124 sc->expectColor(Rect(10, 10, 40, 50), mExpectedColor);
125 sc->expectColor(Rect(0, 0, 9, 9), {0, 0, 0, 255});
126}
127
128} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -0800129
130// TODO(b/129481165): remove the #pragma below and fix conversion issues
131#pragma clang diagnostic pop // ignored "-Wconversion"