Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 1 | /* |
| 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 Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 17 | #include <cmath> |
| 18 | |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 19 | #include <compositionengine/DisplayColorProfileCreationArgs.h> |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 20 | #include <compositionengine/DisplayCreationArgs.h> |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 21 | #include <compositionengine/DisplaySurface.h> |
| 22 | #include <compositionengine/RenderSurfaceCreationArgs.h> |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 23 | #include <compositionengine/impl/Display.h> |
| 24 | #include <compositionengine/mock/CompositionEngine.h> |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 25 | #include <compositionengine/mock/DisplayColorProfile.h> |
chaviw | 8beb414 | 2019-04-11 13:09:05 -0700 | [diff] [blame] | 26 | #include <compositionengine/mock/NativeWindow.h> |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 27 | #include <compositionengine/mock/RenderSurface.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 28 | #include <gtest/gtest.h> |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 29 | |
| 30 | #include "MockHWComposer.h" |
| 31 | |
| 32 | namespace android::compositionengine { |
| 33 | namespace { |
| 34 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 35 | using testing::_; |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 36 | using testing::Return; |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 37 | using testing::ReturnRef; |
| 38 | using testing::StrictMock; |
| 39 | |
| 40 | constexpr DisplayId DEFAULT_DISPLAY_ID = DisplayId{42}; |
| 41 | |
| 42 | class DisplayTest : public testing::Test { |
| 43 | public: |
| 44 | ~DisplayTest() override = default; |
| 45 | |
| 46 | StrictMock<android::mock::HWComposer> mHwComposer; |
| 47 | StrictMock<mock::CompositionEngine> mCompositionEngine; |
chaviw | 8beb414 | 2019-04-11 13:09:05 -0700 | [diff] [blame] | 48 | sp<mock::NativeWindow> mNativeWindow = new StrictMock<mock::NativeWindow>(); |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 49 | impl::Display mDisplay{mCompositionEngine, |
| 50 | DisplayCreationArgsBuilder().setDisplayId(DEFAULT_DISPLAY_ID).build()}; |
| 51 | }; |
| 52 | |
| 53 | /* ------------------------------------------------------------------------ |
| 54 | * Basic construction |
| 55 | */ |
| 56 | |
| 57 | TEST_F(DisplayTest, canInstantiateDisplay) { |
| 58 | { |
| 59 | constexpr DisplayId display1 = DisplayId{123u}; |
| 60 | auto display = |
| 61 | impl::createDisplay(mCompositionEngine, |
| 62 | DisplayCreationArgsBuilder().setDisplayId(display1).build()); |
| 63 | EXPECT_FALSE(display->isSecure()); |
| 64 | EXPECT_FALSE(display->isVirtual()); |
| 65 | EXPECT_EQ(display1, display->getId()); |
| 66 | } |
| 67 | |
| 68 | { |
| 69 | constexpr DisplayId display2 = DisplayId{546u}; |
| 70 | auto display = impl::createDisplay(mCompositionEngine, |
| 71 | DisplayCreationArgsBuilder() |
| 72 | .setIsSecure(true) |
| 73 | .setDisplayId(display2) |
| 74 | .build()); |
| 75 | EXPECT_TRUE(display->isSecure()); |
| 76 | EXPECT_FALSE(display->isVirtual()); |
| 77 | EXPECT_EQ(display2, display->getId()); |
| 78 | } |
| 79 | |
| 80 | { |
| 81 | constexpr DisplayId display3 = DisplayId{789u}; |
| 82 | auto display = impl::createDisplay(mCompositionEngine, |
| 83 | DisplayCreationArgsBuilder() |
| 84 | .setIsVirtual(true) |
| 85 | .setDisplayId(display3) |
| 86 | .build()); |
| 87 | EXPECT_FALSE(display->isSecure()); |
| 88 | EXPECT_TRUE(display->isVirtual()); |
| 89 | EXPECT_EQ(display3, display->getId()); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | /* ------------------------------------------------------------------------ |
| 94 | * Display::disconnect() |
| 95 | */ |
| 96 | |
| 97 | TEST_F(DisplayTest, disconnectDisconnectsDisplay) { |
| 98 | EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer)); |
| 99 | |
| 100 | // The first call to disconnect will disconnect the display with the HWC and |
| 101 | // set mHwcId to -1. |
| 102 | EXPECT_CALL(mHwComposer, disconnectDisplay(DEFAULT_DISPLAY_ID)).Times(1); |
| 103 | mDisplay.disconnect(); |
| 104 | EXPECT_FALSE(mDisplay.getId()); |
| 105 | |
| 106 | // Subsequent calls will do nothing, |
| 107 | EXPECT_CALL(mHwComposer, disconnectDisplay(DEFAULT_DISPLAY_ID)).Times(0); |
| 108 | mDisplay.disconnect(); |
| 109 | EXPECT_FALSE(mDisplay.getId()); |
| 110 | } |
| 111 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 112 | /* ------------------------------------------------------------------------ |
| 113 | * Display::setColorTransform() |
| 114 | */ |
| 115 | |
| 116 | TEST_F(DisplayTest, setColorTransformSetsTransform) { |
| 117 | // Identity matrix sets an identity state value |
| 118 | const mat4 identity; |
| 119 | |
| 120 | EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer)); |
| 121 | |
| 122 | EXPECT_CALL(mHwComposer, setColorTransform(DEFAULT_DISPLAY_ID, identity)).Times(1); |
| 123 | |
| 124 | mDisplay.setColorTransform(identity); |
| 125 | |
| 126 | EXPECT_EQ(HAL_COLOR_TRANSFORM_IDENTITY, mDisplay.getState().colorTransform); |
| 127 | |
| 128 | // Non-identity matrix sets a non-identity state value |
| 129 | const mat4 nonIdentity = mat4() * 2; |
| 130 | |
| 131 | EXPECT_CALL(mHwComposer, setColorTransform(DEFAULT_DISPLAY_ID, nonIdentity)).Times(1); |
| 132 | |
| 133 | mDisplay.setColorTransform(nonIdentity); |
| 134 | |
| 135 | EXPECT_EQ(HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX, mDisplay.getState().colorTransform); |
| 136 | } |
| 137 | |
| 138 | /* ------------------------------------------------------------------------ |
| 139 | * Display::setColorMode() |
| 140 | */ |
| 141 | |
| 142 | TEST_F(DisplayTest, setColorModeSetsModeUnlessNoChange) { |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 143 | mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>(); |
| 144 | mDisplay.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface)); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 145 | mock::DisplayColorProfile* colorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 146 | mDisplay.setDisplayColorProfileForTest(std::unique_ptr<DisplayColorProfile>(colorProfile)); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 147 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 148 | EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer)); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 149 | EXPECT_CALL(*colorProfile, getTargetDataspace(_, _, _)) |
| 150 | .WillRepeatedly(Return(ui::Dataspace::UNKNOWN)); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 151 | |
| 152 | // These values are expected to be the initial state. |
| 153 | ASSERT_EQ(ui::ColorMode::NATIVE, mDisplay.getState().colorMode); |
| 154 | ASSERT_EQ(ui::Dataspace::UNKNOWN, mDisplay.getState().dataspace); |
| 155 | ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mDisplay.getState().renderIntent); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 156 | ASSERT_EQ(ui::Dataspace::UNKNOWN, mDisplay.getState().targetDataspace); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 157 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 158 | // If the set values are unchanged, nothing happens |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 159 | mDisplay.setColorMode(ui::ColorMode::NATIVE, ui::Dataspace::UNKNOWN, |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 160 | ui::RenderIntent::COLORIMETRIC, ui::Dataspace::UNKNOWN); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 161 | |
| 162 | EXPECT_EQ(ui::ColorMode::NATIVE, mDisplay.getState().colorMode); |
| 163 | EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay.getState().dataspace); |
| 164 | EXPECT_EQ(ui::RenderIntent::COLORIMETRIC, mDisplay.getState().renderIntent); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 165 | EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay.getState().targetDataspace); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 166 | |
| 167 | // Otherwise if the values are different, updates happen |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 168 | EXPECT_CALL(*renderSurface, setBufferDataspace(ui::Dataspace::DISPLAY_P3)).Times(1); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 169 | EXPECT_CALL(mHwComposer, |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 170 | setActiveColorMode(DEFAULT_DISPLAY_ID, ui::ColorMode::DISPLAY_P3, |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 171 | ui::RenderIntent::TONE_MAP_COLORIMETRIC)) |
| 172 | .Times(1); |
| 173 | |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 174 | mDisplay.setColorMode(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3, |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 175 | ui::RenderIntent::TONE_MAP_COLORIMETRIC, ui::Dataspace::UNKNOWN); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 176 | |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 177 | EXPECT_EQ(ui::ColorMode::DISPLAY_P3, mDisplay.getState().colorMode); |
| 178 | EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mDisplay.getState().dataspace); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 179 | EXPECT_EQ(ui::RenderIntent::TONE_MAP_COLORIMETRIC, mDisplay.getState().renderIntent); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 180 | EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay.getState().targetDataspace); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | TEST_F(DisplayTest, setColorModeDoesNothingForVirtualDisplay) { |
| 184 | impl::Display virtualDisplay{mCompositionEngine, |
| 185 | DisplayCreationArgs{false, true, DEFAULT_DISPLAY_ID}}; |
| 186 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 187 | mock::DisplayColorProfile* colorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 188 | virtualDisplay.setDisplayColorProfileForTest( |
| 189 | std::unique_ptr<DisplayColorProfile>(colorProfile)); |
| 190 | |
| 191 | EXPECT_CALL(*colorProfile, |
| 192 | getTargetDataspace(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3, |
| 193 | ui::Dataspace::UNKNOWN)) |
| 194 | .WillOnce(Return(ui::Dataspace::UNKNOWN)); |
| 195 | |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 196 | virtualDisplay.setColorMode(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3, |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 197 | ui::RenderIntent::TONE_MAP_COLORIMETRIC, ui::Dataspace::UNKNOWN); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 198 | |
| 199 | EXPECT_EQ(ui::ColorMode::NATIVE, virtualDisplay.getState().colorMode); |
| 200 | EXPECT_EQ(ui::Dataspace::UNKNOWN, virtualDisplay.getState().dataspace); |
| 201 | EXPECT_EQ(ui::RenderIntent::COLORIMETRIC, virtualDisplay.getState().renderIntent); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 202 | EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay.getState().targetDataspace); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 203 | } |
| 204 | |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 205 | /* ------------------------------------------------------------------------ |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 206 | * Display::createDisplayColorProfile() |
| 207 | */ |
| 208 | |
| 209 | TEST_F(DisplayTest, createDisplayColorProfileSetsDisplayColorProfile) { |
| 210 | EXPECT_TRUE(mDisplay.getDisplayColorProfile() == nullptr); |
| 211 | mDisplay.createDisplayColorProfile( |
| 212 | DisplayColorProfileCreationArgs{false, HdrCapabilities(), 0, |
| 213 | DisplayColorProfileCreationArgs::HwcColorModes()}); |
| 214 | EXPECT_TRUE(mDisplay.getDisplayColorProfile() != nullptr); |
| 215 | } |
| 216 | |
| 217 | /* ------------------------------------------------------------------------ |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 218 | * Display::createRenderSurface() |
| 219 | */ |
| 220 | |
| 221 | TEST_F(DisplayTest, createRenderSurfaceSetsRenderSurface) { |
chaviw | 8beb414 | 2019-04-11 13:09:05 -0700 | [diff] [blame] | 222 | EXPECT_CALL(*mNativeWindow, disconnect(NATIVE_WINDOW_API_EGL)).WillRepeatedly(Return(NO_ERROR)); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 223 | EXPECT_TRUE(mDisplay.getRenderSurface() == nullptr); |
chaviw | 8beb414 | 2019-04-11 13:09:05 -0700 | [diff] [blame] | 224 | mDisplay.createRenderSurface(RenderSurfaceCreationArgs{640, 480, mNativeWindow, nullptr}); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 225 | EXPECT_TRUE(mDisplay.getRenderSurface() != nullptr); |
| 226 | } |
| 227 | |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 228 | } // namespace |
| 229 | } // namespace android::compositionengine |