blob: cd2d45493827b64da3ec16858230cecfe6c25170 [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
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070019#include <compositionengine/DisplayColorProfileCreationArgs.h>
Lloyd Pique45a165a2018-10-19 11:54:47 -070020#include <compositionengine/DisplayCreationArgs.h>
Lloyd Pique31cb2942018-10-19 17:23:03 -070021#include <compositionengine/DisplaySurface.h>
22#include <compositionengine/RenderSurfaceCreationArgs.h>
Lloyd Pique45a165a2018-10-19 11:54:47 -070023#include <compositionengine/impl/Display.h>
24#include <compositionengine/mock/CompositionEngine.h>
Lloyd Pique31cb2942018-10-19 17:23:03 -070025#include <compositionengine/mock/RenderSurface.h>
Lloyd Pique32cbe282018-10-19 13:09:22 -070026#include <gtest/gtest.h>
Lloyd Pique31cb2942018-10-19 17:23:03 -070027#include <system/window.h>
Lloyd Pique45a165a2018-10-19 11:54:47 -070028
29#include "MockHWComposer.h"
30
31namespace android::compositionengine {
32namespace {
33
Lloyd Pique31cb2942018-10-19 17:23:03 -070034using testing::Return;
Lloyd Pique45a165a2018-10-19 11:54:47 -070035using testing::ReturnRef;
36using testing::StrictMock;
37
38constexpr DisplayId DEFAULT_DISPLAY_ID = DisplayId{42};
39
40class DisplayTest : public testing::Test {
41public:
42 ~DisplayTest() override = default;
43
44 StrictMock<android::mock::HWComposer> mHwComposer;
45 StrictMock<mock::CompositionEngine> mCompositionEngine;
46 impl::Display mDisplay{mCompositionEngine,
47 DisplayCreationArgsBuilder().setDisplayId(DEFAULT_DISPLAY_ID).build()};
48};
49
50/* ------------------------------------------------------------------------
51 * Basic construction
52 */
53
54TEST_F(DisplayTest, canInstantiateDisplay) {
55 {
56 constexpr DisplayId display1 = DisplayId{123u};
57 auto display =
58 impl::createDisplay(mCompositionEngine,
59 DisplayCreationArgsBuilder().setDisplayId(display1).build());
60 EXPECT_FALSE(display->isSecure());
61 EXPECT_FALSE(display->isVirtual());
62 EXPECT_EQ(display1, display->getId());
63 }
64
65 {
66 constexpr DisplayId display2 = DisplayId{546u};
67 auto display = impl::createDisplay(mCompositionEngine,
68 DisplayCreationArgsBuilder()
69 .setIsSecure(true)
70 .setDisplayId(display2)
71 .build());
72 EXPECT_TRUE(display->isSecure());
73 EXPECT_FALSE(display->isVirtual());
74 EXPECT_EQ(display2, display->getId());
75 }
76
77 {
78 constexpr DisplayId display3 = DisplayId{789u};
79 auto display = impl::createDisplay(mCompositionEngine,
80 DisplayCreationArgsBuilder()
81 .setIsVirtual(true)
82 .setDisplayId(display3)
83 .build());
84 EXPECT_FALSE(display->isSecure());
85 EXPECT_TRUE(display->isVirtual());
86 EXPECT_EQ(display3, display->getId());
87 }
88}
89
90/* ------------------------------------------------------------------------
91 * Display::disconnect()
92 */
93
94TEST_F(DisplayTest, disconnectDisconnectsDisplay) {
95 EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer));
96
97 // The first call to disconnect will disconnect the display with the HWC and
98 // set mHwcId to -1.
99 EXPECT_CALL(mHwComposer, disconnectDisplay(DEFAULT_DISPLAY_ID)).Times(1);
100 mDisplay.disconnect();
101 EXPECT_FALSE(mDisplay.getId());
102
103 // Subsequent calls will do nothing,
104 EXPECT_CALL(mHwComposer, disconnectDisplay(DEFAULT_DISPLAY_ID)).Times(0);
105 mDisplay.disconnect();
106 EXPECT_FALSE(mDisplay.getId());
107}
108
Lloyd Pique32cbe282018-10-19 13:09:22 -0700109/* ------------------------------------------------------------------------
110 * Display::setColorTransform()
111 */
112
113TEST_F(DisplayTest, setColorTransformSetsTransform) {
114 // Identity matrix sets an identity state value
115 const mat4 identity;
116
117 EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer));
118
119 EXPECT_CALL(mHwComposer, setColorTransform(DEFAULT_DISPLAY_ID, identity)).Times(1);
120
121 mDisplay.setColorTransform(identity);
122
123 EXPECT_EQ(HAL_COLOR_TRANSFORM_IDENTITY, mDisplay.getState().colorTransform);
124
125 // Non-identity matrix sets a non-identity state value
126 const mat4 nonIdentity = mat4() * 2;
127
128 EXPECT_CALL(mHwComposer, setColorTransform(DEFAULT_DISPLAY_ID, nonIdentity)).Times(1);
129
130 mDisplay.setColorTransform(nonIdentity);
131
132 EXPECT_EQ(HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX, mDisplay.getState().colorTransform);
133}
134
135/* ------------------------------------------------------------------------
136 * Display::setColorMode()
137 */
138
139TEST_F(DisplayTest, setColorModeSetsModeUnlessNoChange) {
Lloyd Pique31cb2942018-10-19 17:23:03 -0700140 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
141 mDisplay.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
142
Lloyd Pique32cbe282018-10-19 13:09:22 -0700143 EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer));
144
145 // These values are expected to be the initial state.
146 ASSERT_EQ(ui::ColorMode::NATIVE, mDisplay.getState().colorMode);
147 ASSERT_EQ(ui::Dataspace::UNKNOWN, mDisplay.getState().dataspace);
148 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mDisplay.getState().renderIntent);
149
150 // Otherwise if the values are unchanged, nothing happens
151 mDisplay.setColorMode(ui::ColorMode::NATIVE, ui::Dataspace::UNKNOWN,
152 ui::RenderIntent::COLORIMETRIC);
153
154 EXPECT_EQ(ui::ColorMode::NATIVE, mDisplay.getState().colorMode);
155 EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay.getState().dataspace);
156 EXPECT_EQ(ui::RenderIntent::COLORIMETRIC, mDisplay.getState().renderIntent);
157
158 // Otherwise if the values are different, updates happen
Lloyd Piqueef958122019-02-05 18:00:12 -0800159 EXPECT_CALL(*renderSurface, setBufferDataspace(ui::Dataspace::DISPLAY_P3)).Times(1);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700160 EXPECT_CALL(mHwComposer,
Lloyd Piqueef958122019-02-05 18:00:12 -0800161 setActiveColorMode(DEFAULT_DISPLAY_ID, ui::ColorMode::DISPLAY_P3,
Lloyd Pique32cbe282018-10-19 13:09:22 -0700162 ui::RenderIntent::TONE_MAP_COLORIMETRIC))
163 .Times(1);
164
Lloyd Piqueef958122019-02-05 18:00:12 -0800165 mDisplay.setColorMode(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
Lloyd Pique32cbe282018-10-19 13:09:22 -0700166 ui::RenderIntent::TONE_MAP_COLORIMETRIC);
167
Lloyd Piqueef958122019-02-05 18:00:12 -0800168 EXPECT_EQ(ui::ColorMode::DISPLAY_P3, mDisplay.getState().colorMode);
169 EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mDisplay.getState().dataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700170 EXPECT_EQ(ui::RenderIntent::TONE_MAP_COLORIMETRIC, mDisplay.getState().renderIntent);
171}
172
173TEST_F(DisplayTest, setColorModeDoesNothingForVirtualDisplay) {
174 impl::Display virtualDisplay{mCompositionEngine,
175 DisplayCreationArgs{false, true, DEFAULT_DISPLAY_ID}};
176
Lloyd Piqueef958122019-02-05 18:00:12 -0800177 virtualDisplay.setColorMode(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
Lloyd Pique32cbe282018-10-19 13:09:22 -0700178 ui::RenderIntent::TONE_MAP_COLORIMETRIC);
179
180 EXPECT_EQ(ui::ColorMode::NATIVE, virtualDisplay.getState().colorMode);
181 EXPECT_EQ(ui::Dataspace::UNKNOWN, virtualDisplay.getState().dataspace);
182 EXPECT_EQ(ui::RenderIntent::COLORIMETRIC, virtualDisplay.getState().renderIntent);
183}
184
Lloyd Pique31cb2942018-10-19 17:23:03 -0700185/* ------------------------------------------------------------------------
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700186 * Display::createDisplayColorProfile()
187 */
188
189TEST_F(DisplayTest, createDisplayColorProfileSetsDisplayColorProfile) {
190 EXPECT_TRUE(mDisplay.getDisplayColorProfile() == nullptr);
191 mDisplay.createDisplayColorProfile(
192 DisplayColorProfileCreationArgs{false, HdrCapabilities(), 0,
193 DisplayColorProfileCreationArgs::HwcColorModes()});
194 EXPECT_TRUE(mDisplay.getDisplayColorProfile() != nullptr);
195}
196
197/* ------------------------------------------------------------------------
Lloyd Pique31cb2942018-10-19 17:23:03 -0700198 * Display::createRenderSurface()
199 */
200
201TEST_F(DisplayTest, createRenderSurfaceSetsRenderSurface) {
202 EXPECT_TRUE(mDisplay.getRenderSurface() == nullptr);
203 mDisplay.createRenderSurface(RenderSurfaceCreationArgs{640, 480, nullptr, nullptr});
204 EXPECT_TRUE(mDisplay.getRenderSurface() != nullptr);
205}
206
Lloyd Pique45a165a2018-10-19 11:54:47 -0700207} // namespace
208} // namespace android::compositionengine