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 | |
| 19 | #include <compositionengine/DisplayCreationArgs.h> |
| 20 | #include <compositionengine/impl/Display.h> |
| 21 | #include <compositionengine/mock/CompositionEngine.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 22 | #include <gtest/gtest.h> |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 23 | |
| 24 | #include "MockHWComposer.h" |
| 25 | |
| 26 | namespace android::compositionengine { |
| 27 | namespace { |
| 28 | |
| 29 | using testing::ReturnRef; |
| 30 | using testing::StrictMock; |
| 31 | |
| 32 | constexpr DisplayId DEFAULT_DISPLAY_ID = DisplayId{42}; |
| 33 | |
| 34 | class DisplayTest : public testing::Test { |
| 35 | public: |
| 36 | ~DisplayTest() override = default; |
| 37 | |
| 38 | StrictMock<android::mock::HWComposer> mHwComposer; |
| 39 | StrictMock<mock::CompositionEngine> mCompositionEngine; |
| 40 | impl::Display mDisplay{mCompositionEngine, |
| 41 | DisplayCreationArgsBuilder().setDisplayId(DEFAULT_DISPLAY_ID).build()}; |
| 42 | }; |
| 43 | |
| 44 | /* ------------------------------------------------------------------------ |
| 45 | * Basic construction |
| 46 | */ |
| 47 | |
| 48 | TEST_F(DisplayTest, canInstantiateDisplay) { |
| 49 | { |
| 50 | constexpr DisplayId display1 = DisplayId{123u}; |
| 51 | auto display = |
| 52 | impl::createDisplay(mCompositionEngine, |
| 53 | DisplayCreationArgsBuilder().setDisplayId(display1).build()); |
| 54 | EXPECT_FALSE(display->isSecure()); |
| 55 | EXPECT_FALSE(display->isVirtual()); |
| 56 | EXPECT_EQ(display1, display->getId()); |
| 57 | } |
| 58 | |
| 59 | { |
| 60 | constexpr DisplayId display2 = DisplayId{546u}; |
| 61 | auto display = impl::createDisplay(mCompositionEngine, |
| 62 | DisplayCreationArgsBuilder() |
| 63 | .setIsSecure(true) |
| 64 | .setDisplayId(display2) |
| 65 | .build()); |
| 66 | EXPECT_TRUE(display->isSecure()); |
| 67 | EXPECT_FALSE(display->isVirtual()); |
| 68 | EXPECT_EQ(display2, display->getId()); |
| 69 | } |
| 70 | |
| 71 | { |
| 72 | constexpr DisplayId display3 = DisplayId{789u}; |
| 73 | auto display = impl::createDisplay(mCompositionEngine, |
| 74 | DisplayCreationArgsBuilder() |
| 75 | .setIsVirtual(true) |
| 76 | .setDisplayId(display3) |
| 77 | .build()); |
| 78 | EXPECT_FALSE(display->isSecure()); |
| 79 | EXPECT_TRUE(display->isVirtual()); |
| 80 | EXPECT_EQ(display3, display->getId()); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | /* ------------------------------------------------------------------------ |
| 85 | * Display::disconnect() |
| 86 | */ |
| 87 | |
| 88 | TEST_F(DisplayTest, disconnectDisconnectsDisplay) { |
| 89 | EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer)); |
| 90 | |
| 91 | // The first call to disconnect will disconnect the display with the HWC and |
| 92 | // set mHwcId to -1. |
| 93 | EXPECT_CALL(mHwComposer, disconnectDisplay(DEFAULT_DISPLAY_ID)).Times(1); |
| 94 | mDisplay.disconnect(); |
| 95 | EXPECT_FALSE(mDisplay.getId()); |
| 96 | |
| 97 | // Subsequent calls will do nothing, |
| 98 | EXPECT_CALL(mHwComposer, disconnectDisplay(DEFAULT_DISPLAY_ID)).Times(0); |
| 99 | mDisplay.disconnect(); |
| 100 | EXPECT_FALSE(mDisplay.getId()); |
| 101 | } |
| 102 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 103 | /* ------------------------------------------------------------------------ |
| 104 | * Display::setColorTransform() |
| 105 | */ |
| 106 | |
| 107 | TEST_F(DisplayTest, setColorTransformSetsTransform) { |
| 108 | // Identity matrix sets an identity state value |
| 109 | const mat4 identity; |
| 110 | |
| 111 | EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer)); |
| 112 | |
| 113 | EXPECT_CALL(mHwComposer, setColorTransform(DEFAULT_DISPLAY_ID, identity)).Times(1); |
| 114 | |
| 115 | mDisplay.setColorTransform(identity); |
| 116 | |
| 117 | EXPECT_EQ(HAL_COLOR_TRANSFORM_IDENTITY, mDisplay.getState().colorTransform); |
| 118 | |
| 119 | // Non-identity matrix sets a non-identity state value |
| 120 | const mat4 nonIdentity = mat4() * 2; |
| 121 | |
| 122 | EXPECT_CALL(mHwComposer, setColorTransform(DEFAULT_DISPLAY_ID, nonIdentity)).Times(1); |
| 123 | |
| 124 | mDisplay.setColorTransform(nonIdentity); |
| 125 | |
| 126 | EXPECT_EQ(HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX, mDisplay.getState().colorTransform); |
| 127 | } |
| 128 | |
| 129 | /* ------------------------------------------------------------------------ |
| 130 | * Display::setColorMode() |
| 131 | */ |
| 132 | |
| 133 | TEST_F(DisplayTest, setColorModeSetsModeUnlessNoChange) { |
| 134 | EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer)); |
| 135 | |
| 136 | // These values are expected to be the initial state. |
| 137 | ASSERT_EQ(ui::ColorMode::NATIVE, mDisplay.getState().colorMode); |
| 138 | ASSERT_EQ(ui::Dataspace::UNKNOWN, mDisplay.getState().dataspace); |
| 139 | ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mDisplay.getState().renderIntent); |
| 140 | |
| 141 | // Otherwise if the values are unchanged, nothing happens |
| 142 | mDisplay.setColorMode(ui::ColorMode::NATIVE, ui::Dataspace::UNKNOWN, |
| 143 | ui::RenderIntent::COLORIMETRIC); |
| 144 | |
| 145 | EXPECT_EQ(ui::ColorMode::NATIVE, mDisplay.getState().colorMode); |
| 146 | EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay.getState().dataspace); |
| 147 | EXPECT_EQ(ui::RenderIntent::COLORIMETRIC, mDisplay.getState().renderIntent); |
| 148 | |
| 149 | // Otherwise if the values are different, updates happen |
| 150 | EXPECT_CALL(mHwComposer, |
| 151 | setActiveColorMode(DEFAULT_DISPLAY_ID, ui::ColorMode::BT2100_PQ, |
| 152 | ui::RenderIntent::TONE_MAP_COLORIMETRIC)) |
| 153 | .Times(1); |
| 154 | |
| 155 | mDisplay.setColorMode(ui::ColorMode::BT2100_PQ, ui::Dataspace::SRGB, |
| 156 | ui::RenderIntent::TONE_MAP_COLORIMETRIC); |
| 157 | |
| 158 | EXPECT_EQ(ui::ColorMode::BT2100_PQ, mDisplay.getState().colorMode); |
| 159 | EXPECT_EQ(ui::Dataspace::SRGB, mDisplay.getState().dataspace); |
| 160 | EXPECT_EQ(ui::RenderIntent::TONE_MAP_COLORIMETRIC, mDisplay.getState().renderIntent); |
| 161 | } |
| 162 | |
| 163 | TEST_F(DisplayTest, setColorModeDoesNothingForVirtualDisplay) { |
| 164 | impl::Display virtualDisplay{mCompositionEngine, |
| 165 | DisplayCreationArgs{false, true, DEFAULT_DISPLAY_ID}}; |
| 166 | |
| 167 | virtualDisplay.setColorMode(ui::ColorMode::BT2100_PQ, ui::Dataspace::SRGB, |
| 168 | ui::RenderIntent::TONE_MAP_COLORIMETRIC); |
| 169 | |
| 170 | EXPECT_EQ(ui::ColorMode::NATIVE, virtualDisplay.getState().colorMode); |
| 171 | EXPECT_EQ(ui::Dataspace::UNKNOWN, virtualDisplay.getState().dataspace); |
| 172 | EXPECT_EQ(ui::RenderIntent::COLORIMETRIC, virtualDisplay.getState().renderIntent); |
| 173 | } |
| 174 | |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 175 | } // namespace |
| 176 | } // namespace android::compositionengine |