blob: 589fdc35aad78ab76e3f4111a399c9d74cb6585f [file] [log] [blame]
Lloyd Pique45a165a2018-10-19 11:54:47 -07001/*
2 * Copyright 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
Lloyd Pique45a165a2018-10-19 11:54:47 -070017#include <cmath>
18
19#include <compositionengine/DisplayCreationArgs.h>
Lloyd Pique31cb2942018-10-19 17:23:03 -070020#include <compositionengine/DisplaySurface.h>
21#include <compositionengine/RenderSurfaceCreationArgs.h>
Lloyd Pique45a165a2018-10-19 11:54:47 -070022#include <compositionengine/impl/Display.h>
23#include <compositionengine/mock/CompositionEngine.h>
Lloyd Pique31cb2942018-10-19 17:23:03 -070024#include <compositionengine/mock/RenderSurface.h>
Lloyd Pique32cbe282018-10-19 13:09:22 -070025#include <gtest/gtest.h>
Lloyd Pique31cb2942018-10-19 17:23:03 -070026#include <system/window.h>
Lloyd Pique45a165a2018-10-19 11:54:47 -070027
28#include "MockHWComposer.h"
29
30namespace android::compositionengine {
31namespace {
32
Lloyd Pique31cb2942018-10-19 17:23:03 -070033using testing::Return;
Lloyd Pique45a165a2018-10-19 11:54:47 -070034using testing::ReturnRef;
35using testing::StrictMock;
36
37constexpr DisplayId DEFAULT_DISPLAY_ID = DisplayId{42};
38
39class DisplayTest : public testing::Test {
40public:
41 ~DisplayTest() override = default;
42
43 StrictMock<android::mock::HWComposer> mHwComposer;
44 StrictMock<mock::CompositionEngine> mCompositionEngine;
45 impl::Display mDisplay{mCompositionEngine,
46 DisplayCreationArgsBuilder().setDisplayId(DEFAULT_DISPLAY_ID).build()};
47};
48
49/* ------------------------------------------------------------------------
50 * Basic construction
51 */
52
53TEST_F(DisplayTest, canInstantiateDisplay) {
54 {
55 constexpr DisplayId display1 = DisplayId{123u};
56 auto display =
57 impl::createDisplay(mCompositionEngine,
58 DisplayCreationArgsBuilder().setDisplayId(display1).build());
59 EXPECT_FALSE(display->isSecure());
60 EXPECT_FALSE(display->isVirtual());
61 EXPECT_EQ(display1, display->getId());
62 }
63
64 {
65 constexpr DisplayId display2 = DisplayId{546u};
66 auto display = impl::createDisplay(mCompositionEngine,
67 DisplayCreationArgsBuilder()
68 .setIsSecure(true)
69 .setDisplayId(display2)
70 .build());
71 EXPECT_TRUE(display->isSecure());
72 EXPECT_FALSE(display->isVirtual());
73 EXPECT_EQ(display2, display->getId());
74 }
75
76 {
77 constexpr DisplayId display3 = DisplayId{789u};
78 auto display = impl::createDisplay(mCompositionEngine,
79 DisplayCreationArgsBuilder()
80 .setIsVirtual(true)
81 .setDisplayId(display3)
82 .build());
83 EXPECT_FALSE(display->isSecure());
84 EXPECT_TRUE(display->isVirtual());
85 EXPECT_EQ(display3, display->getId());
86 }
87}
88
89/* ------------------------------------------------------------------------
90 * Display::disconnect()
91 */
92
93TEST_F(DisplayTest, disconnectDisconnectsDisplay) {
94 EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer));
95
96 // The first call to disconnect will disconnect the display with the HWC and
97 // set mHwcId to -1.
98 EXPECT_CALL(mHwComposer, disconnectDisplay(DEFAULT_DISPLAY_ID)).Times(1);
99 mDisplay.disconnect();
100 EXPECT_FALSE(mDisplay.getId());
101
102 // Subsequent calls will do nothing,
103 EXPECT_CALL(mHwComposer, disconnectDisplay(DEFAULT_DISPLAY_ID)).Times(0);
104 mDisplay.disconnect();
105 EXPECT_FALSE(mDisplay.getId());
106}
107
Lloyd Pique32cbe282018-10-19 13:09:22 -0700108/* ------------------------------------------------------------------------
109 * Display::setColorTransform()
110 */
111
112TEST_F(DisplayTest, setColorTransformSetsTransform) {
113 // Identity matrix sets an identity state value
114 const mat4 identity;
115
116 EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer));
117
118 EXPECT_CALL(mHwComposer, setColorTransform(DEFAULT_DISPLAY_ID, identity)).Times(1);
119
120 mDisplay.setColorTransform(identity);
121
122 EXPECT_EQ(HAL_COLOR_TRANSFORM_IDENTITY, mDisplay.getState().colorTransform);
123
124 // Non-identity matrix sets a non-identity state value
125 const mat4 nonIdentity = mat4() * 2;
126
127 EXPECT_CALL(mHwComposer, setColorTransform(DEFAULT_DISPLAY_ID, nonIdentity)).Times(1);
128
129 mDisplay.setColorTransform(nonIdentity);
130
131 EXPECT_EQ(HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX, mDisplay.getState().colorTransform);
132}
133
134/* ------------------------------------------------------------------------
135 * Display::setColorMode()
136 */
137
138TEST_F(DisplayTest, setColorModeSetsModeUnlessNoChange) {
Lloyd Pique31cb2942018-10-19 17:23:03 -0700139 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
140 mDisplay.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
141
Lloyd Pique32cbe282018-10-19 13:09:22 -0700142 EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer));
143
144 // These values are expected to be the initial state.
145 ASSERT_EQ(ui::ColorMode::NATIVE, mDisplay.getState().colorMode);
146 ASSERT_EQ(ui::Dataspace::UNKNOWN, mDisplay.getState().dataspace);
147 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mDisplay.getState().renderIntent);
148
149 // Otherwise if the values are unchanged, nothing happens
150 mDisplay.setColorMode(ui::ColorMode::NATIVE, ui::Dataspace::UNKNOWN,
151 ui::RenderIntent::COLORIMETRIC);
152
153 EXPECT_EQ(ui::ColorMode::NATIVE, mDisplay.getState().colorMode);
154 EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay.getState().dataspace);
155 EXPECT_EQ(ui::RenderIntent::COLORIMETRIC, mDisplay.getState().renderIntent);
156
157 // Otherwise if the values are different, updates happen
Lloyd Pique31cb2942018-10-19 17:23:03 -0700158 EXPECT_CALL(*renderSurface, setBufferDataspace(ui::Dataspace::SRGB)).Times(1);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700159 EXPECT_CALL(mHwComposer,
160 setActiveColorMode(DEFAULT_DISPLAY_ID, ui::ColorMode::BT2100_PQ,
161 ui::RenderIntent::TONE_MAP_COLORIMETRIC))
162 .Times(1);
163
164 mDisplay.setColorMode(ui::ColorMode::BT2100_PQ, ui::Dataspace::SRGB,
165 ui::RenderIntent::TONE_MAP_COLORIMETRIC);
166
167 EXPECT_EQ(ui::ColorMode::BT2100_PQ, mDisplay.getState().colorMode);
168 EXPECT_EQ(ui::Dataspace::SRGB, mDisplay.getState().dataspace);
169 EXPECT_EQ(ui::RenderIntent::TONE_MAP_COLORIMETRIC, mDisplay.getState().renderIntent);
170}
171
172TEST_F(DisplayTest, setColorModeDoesNothingForVirtualDisplay) {
173 impl::Display virtualDisplay{mCompositionEngine,
174 DisplayCreationArgs{false, true, DEFAULT_DISPLAY_ID}};
175
176 virtualDisplay.setColorMode(ui::ColorMode::BT2100_PQ, ui::Dataspace::SRGB,
177 ui::RenderIntent::TONE_MAP_COLORIMETRIC);
178
179 EXPECT_EQ(ui::ColorMode::NATIVE, virtualDisplay.getState().colorMode);
180 EXPECT_EQ(ui::Dataspace::UNKNOWN, virtualDisplay.getState().dataspace);
181 EXPECT_EQ(ui::RenderIntent::COLORIMETRIC, virtualDisplay.getState().renderIntent);
182}
183
Lloyd Pique31cb2942018-10-19 17:23:03 -0700184/* ------------------------------------------------------------------------
185 * Display::createRenderSurface()
186 */
187
188TEST_F(DisplayTest, createRenderSurfaceSetsRenderSurface) {
189 EXPECT_TRUE(mDisplay.getRenderSurface() == nullptr);
190 mDisplay.createRenderSurface(RenderSurfaceCreationArgs{640, 480, nullptr, nullptr});
191 EXPECT_TRUE(mDisplay.getRenderSurface() != nullptr);
192}
193
Lloyd Pique45a165a2018-10-19 11:54:47 -0700194} // namespace
195} // namespace android::compositionengine