Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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 | |
| 17 | #undef LOG_TAG |
| 18 | #define LOG_TAG "LibSurfaceFlingerUnittests" |
| 19 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 20 | #include <type_traits> |
| 21 | |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 22 | #include <gmock/gmock.h> |
| 23 | #include <gtest/gtest.h> |
| 24 | |
| 25 | #include <log/log.h> |
| 26 | |
Valerie Hau | 9758ae0 | 2018-10-09 16:05:09 -0700 | [diff] [blame] | 27 | #include <ui/DebugUtils.h> |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 28 | |
| 29 | #include "DisplayIdentificationTest.h" |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 30 | #include "TestableSurfaceFlinger.h" |
Lloyd Pique | cbe0001 | 2018-02-02 15:40:42 -0800 | [diff] [blame] | 31 | #include "mock/DisplayHardware/MockComposer.h" |
| 32 | #include "mock/DisplayHardware/MockDisplaySurface.h" |
Lloyd Pique | 41be5d2 | 2018-06-21 13:11:48 -0700 | [diff] [blame] | 33 | #include "mock/MockDispSync.h" |
Lloyd Pique | cbe0001 | 2018-02-02 15:40:42 -0800 | [diff] [blame] | 34 | #include "mock/MockEventControlThread.h" |
| 35 | #include "mock/MockEventThread.h" |
| 36 | #include "mock/MockMessageQueue.h" |
| 37 | #include "mock/MockNativeWindowSurface.h" |
| 38 | #include "mock/MockSurfaceInterceptor.h" |
| 39 | #include "mock/RenderEngine/MockRenderEngine.h" |
| 40 | #include "mock/gui/MockGraphicBufferConsumer.h" |
| 41 | #include "mock/gui/MockGraphicBufferProducer.h" |
| 42 | #include "mock/system/window/MockNativeWindow.h" |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 43 | |
| 44 | namespace android { |
| 45 | namespace { |
| 46 | |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 47 | using testing::_; |
| 48 | using testing::ByMove; |
| 49 | using testing::DoAll; |
| 50 | using testing::Mock; |
| 51 | using testing::Return; |
| 52 | using testing::SetArgPointee; |
| 53 | |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 54 | using android::Hwc2::ColorMode; |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 55 | using android::Hwc2::Error; |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 56 | using android::Hwc2::Hdr; |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 57 | using android::Hwc2::IComposer; |
| 58 | using android::Hwc2::IComposerClient; |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 59 | using android::Hwc2::PerFrameMetadataKey; |
| 60 | using android::Hwc2::RenderIntent; |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 61 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 62 | using FakeDisplayDeviceInjector = TestableSurfaceFlinger::FakeDisplayDeviceInjector; |
| 63 | using FakeHwcDisplayInjector = TestableSurfaceFlinger::FakeHwcDisplayInjector; |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 64 | using HotplugEvent = TestableSurfaceFlinger::HotplugEvent; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 65 | using HWC2Display = TestableSurfaceFlinger::HWC2Display; |
Lloyd Pique | bc79209 | 2018-01-17 11:52:30 -0800 | [diff] [blame] | 66 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 67 | constexpr int32_t DEFAULT_REFRESH_RATE = 16'666'666; |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 68 | constexpr int32_t DEFAULT_DPI = 320; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 69 | constexpr int DEFAULT_VIRTUAL_DISPLAY_SURFACE_FORMAT = HAL_PIXEL_FORMAT_RGB_565; |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 70 | |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 71 | constexpr int HWC_POWER_MODE_LEET = 1337; // An out of range power mode value |
| 72 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 73 | /* ------------------------------------------------------------------------ |
| 74 | * Boolean avoidance |
| 75 | * |
| 76 | * To make calls and template instantiations more readable, we define some |
| 77 | * local enums along with an implicit bool conversion. |
| 78 | */ |
| 79 | |
| 80 | #define BOOL_SUBSTITUTE(TYPENAME) enum class TYPENAME : bool { FALSE = false, TRUE = true }; |
| 81 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 82 | BOOL_SUBSTITUTE(Async); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 83 | BOOL_SUBSTITUTE(Critical); |
| 84 | BOOL_SUBSTITUTE(Primary); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 85 | BOOL_SUBSTITUTE(Secure); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 86 | BOOL_SUBSTITUTE(Virtual); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 87 | |
| 88 | /* ------------------------------------------------------------------------ |
| 89 | * |
| 90 | */ |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 91 | |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 92 | class DisplayTransactionTest : public testing::Test { |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 93 | public: |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 94 | DisplayTransactionTest(); |
| 95 | ~DisplayTransactionTest() override; |
| 96 | |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 97 | // -------------------------------------------------------------------- |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 98 | // Mock/Fake injection |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 99 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 100 | void injectMockComposer(int virtualDisplayCount); |
| 101 | void injectFakeBufferQueueFactory(); |
| 102 | void injectFakeNativeWindowSurfaceFactory(); |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 103 | |
| 104 | // -------------------------------------------------------------------- |
| 105 | // Postcondition helpers |
| 106 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 107 | bool hasPhysicalHwcDisplay(hwc2_display_t hwcDisplayId); |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 108 | bool hasTransactionFlagSet(int flag); |
| 109 | bool hasDisplayDevice(sp<IBinder> displayToken); |
| 110 | sp<DisplayDevice> getDisplayDevice(sp<IBinder> displayToken); |
| 111 | bool hasCurrentDisplayState(sp<IBinder> displayToken); |
| 112 | const DisplayDeviceState& getCurrentDisplayState(sp<IBinder> displayToken); |
| 113 | bool hasDrawingDisplayState(sp<IBinder> displayToken); |
| 114 | const DisplayDeviceState& getDrawingDisplayState(sp<IBinder> displayToken); |
| 115 | |
| 116 | // -------------------------------------------------------------------- |
| 117 | // Test instances |
Lloyd Pique | 5b36f3f | 2018-01-17 11:57:07 -0800 | [diff] [blame] | 118 | |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 119 | TestableSurfaceFlinger mFlinger; |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 120 | mock::EventThread* mEventThread = new mock::EventThread(); |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 121 | mock::EventControlThread* mEventControlThread = new mock::EventControlThread(); |
Alec Mouri | ba013fa | 2018-10-16 12:43:11 -0700 | [diff] [blame] | 122 | sp<mock::NativeWindow> mNativeWindow = new mock::NativeWindow(); |
Alec Mouri | 0a9c7b8 | 2018-11-16 13:05:25 -0800 | [diff] [blame] | 123 | sp<GraphicBuffer> mBuffer = new GraphicBuffer(); |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 124 | |
| 125 | // These mocks are created by the test, but are destroyed by SurfaceFlinger |
| 126 | // by virtue of being stored into a std::unique_ptr. However we still need |
| 127 | // to keep a reference to them for use in setting up call expectations. |
Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 128 | renderengine::mock::RenderEngine* mRenderEngine = new renderengine::mock::RenderEngine(); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 129 | Hwc2::mock::Composer* mComposer = nullptr; |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 130 | mock::MessageQueue* mMessageQueue = new mock::MessageQueue(); |
| 131 | mock::SurfaceInterceptor* mSurfaceInterceptor = new mock::SurfaceInterceptor(); |
Lloyd Pique | 41be5d2 | 2018-06-21 13:11:48 -0700 | [diff] [blame] | 132 | mock::DispSync* mPrimaryDispSync = new mock::DispSync(); |
Lloyd Pique | 5b36f3f | 2018-01-17 11:57:07 -0800 | [diff] [blame] | 133 | |
| 134 | // These mocks are created only when expected to be created via a factory. |
| 135 | sp<mock::GraphicBufferConsumer> mConsumer; |
| 136 | sp<mock::GraphicBufferProducer> mProducer; |
Lloyd Pique | 2209836 | 2018-09-13 11:46:49 -0700 | [diff] [blame] | 137 | surfaceflinger::mock::NativeWindowSurface* mNativeWindowSurface = nullptr; |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 138 | }; |
| 139 | |
| 140 | DisplayTransactionTest::DisplayTransactionTest() { |
| 141 | const ::testing::TestInfo* const test_info = |
| 142 | ::testing::UnitTest::GetInstance()->current_test_info(); |
| 143 | ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name()); |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 144 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 145 | // Default to no wide color display support configured |
| 146 | mFlinger.mutableHasWideColorDisplay() = false; |
Peiyong Lin | 13effd1 | 2018-07-24 17:01:47 -0700 | [diff] [blame] | 147 | mFlinger.mutableUseColorManagement() = false; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 148 | mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::UNMANAGED; |
| 149 | |
| 150 | // Default to using HWC virtual displays |
| 151 | mFlinger.mutableUseHwcVirtualDisplays() = true; |
| 152 | |
Lloyd Pique | 5b36f3f | 2018-01-17 11:57:07 -0800 | [diff] [blame] | 153 | mFlinger.setCreateBufferQueueFunction([](auto, auto, auto) { |
| 154 | ADD_FAILURE() << "Unexpected request to create a buffer queue."; |
| 155 | }); |
| 156 | |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 157 | mFlinger.setCreateNativeWindowSurface([](auto) { |
| 158 | ADD_FAILURE() << "Unexpected request to create a native window surface."; |
| 159 | return nullptr; |
| 160 | }); |
| 161 | |
| 162 | mFlinger.mutableEventControlThread().reset(mEventControlThread); |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 163 | mFlinger.mutableEventThread().reset(mEventThread); |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 164 | mFlinger.mutableEventQueue().reset(mMessageQueue); |
Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 165 | mFlinger.setupRenderEngine(std::unique_ptr<renderengine::RenderEngine>(mRenderEngine)); |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 166 | mFlinger.mutableInterceptor().reset(mSurfaceInterceptor); |
Lloyd Pique | 41be5d2 | 2018-06-21 13:11:48 -0700 | [diff] [blame] | 167 | mFlinger.mutablePrimaryDispSync().reset(mPrimaryDispSync); |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 168 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 169 | injectMockComposer(0); |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | DisplayTransactionTest::~DisplayTransactionTest() { |
| 173 | const ::testing::TestInfo* const test_info = |
| 174 | ::testing::UnitTest::GetInstance()->current_test_info(); |
| 175 | ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name()); |
| 176 | } |
| 177 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 178 | void DisplayTransactionTest::injectMockComposer(int virtualDisplayCount) { |
| 179 | mComposer = new Hwc2::mock::Composer(); |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 180 | EXPECT_CALL(*mComposer, getCapabilities()) |
| 181 | .WillOnce(Return(std::vector<IComposer::Capability>())); |
| 182 | EXPECT_CALL(*mComposer, getMaxVirtualDisplayCount()).WillOnce(Return(virtualDisplayCount)); |
| 183 | mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer)); |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 184 | |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 185 | Mock::VerifyAndClear(mComposer); |
| 186 | } |
| 187 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 188 | void DisplayTransactionTest::injectFakeBufferQueueFactory() { |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 189 | // This setup is only expected once per test. |
| 190 | ASSERT_TRUE(mConsumer == nullptr && mProducer == nullptr); |
| 191 | |
Lloyd Pique | 5b36f3f | 2018-01-17 11:57:07 -0800 | [diff] [blame] | 192 | mConsumer = new mock::GraphicBufferConsumer(); |
| 193 | mProducer = new mock::GraphicBufferProducer(); |
| 194 | |
| 195 | mFlinger.setCreateBufferQueueFunction([this](auto outProducer, auto outConsumer, bool) { |
| 196 | *outProducer = mProducer; |
| 197 | *outConsumer = mConsumer; |
| 198 | }); |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 199 | } |
Lloyd Pique | 5b36f3f | 2018-01-17 11:57:07 -0800 | [diff] [blame] | 200 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 201 | void DisplayTransactionTest::injectFakeNativeWindowSurfaceFactory() { |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 202 | // This setup is only expected once per test. |
| 203 | ASSERT_TRUE(mNativeWindowSurface == nullptr); |
| 204 | |
Lloyd Pique | 2209836 | 2018-09-13 11:46:49 -0700 | [diff] [blame] | 205 | mNativeWindowSurface = new surfaceflinger::mock::NativeWindowSurface(); |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 206 | |
Lloyd Pique | 2209836 | 2018-09-13 11:46:49 -0700 | [diff] [blame] | 207 | mFlinger.setCreateNativeWindowSurface([this](auto) { |
| 208 | return std::unique_ptr<surfaceflinger::NativeWindowSurface>(mNativeWindowSurface); |
| 209 | }); |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 210 | } |
| 211 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 212 | bool DisplayTransactionTest::hasPhysicalHwcDisplay(hwc2_display_t hwcDisplayId) { |
| 213 | return mFlinger.mutableHwcPhysicalDisplayIdMap().count(hwcDisplayId) == 1; |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | bool DisplayTransactionTest::hasTransactionFlagSet(int flag) { |
| 217 | return mFlinger.mutableTransactionFlags() & flag; |
| 218 | } |
| 219 | |
| 220 | bool DisplayTransactionTest::hasDisplayDevice(sp<IBinder> displayToken) { |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 221 | return mFlinger.mutableDisplays().count(displayToken) == 1; |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | sp<DisplayDevice> DisplayTransactionTest::getDisplayDevice(sp<IBinder> displayToken) { |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 225 | return mFlinger.mutableDisplays()[displayToken]; |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | bool DisplayTransactionTest::hasCurrentDisplayState(sp<IBinder> displayToken) { |
| 229 | return mFlinger.mutableCurrentState().displays.indexOfKey(displayToken) >= 0; |
| 230 | } |
| 231 | |
| 232 | const DisplayDeviceState& DisplayTransactionTest::getCurrentDisplayState(sp<IBinder> displayToken) { |
| 233 | return mFlinger.mutableCurrentState().displays.valueFor(displayToken); |
| 234 | } |
| 235 | |
| 236 | bool DisplayTransactionTest::hasDrawingDisplayState(sp<IBinder> displayToken) { |
| 237 | return mFlinger.mutableDrawingState().displays.indexOfKey(displayToken) >= 0; |
| 238 | } |
| 239 | |
| 240 | const DisplayDeviceState& DisplayTransactionTest::getDrawingDisplayState(sp<IBinder> displayToken) { |
| 241 | return mFlinger.mutableDrawingState().displays.valueFor(displayToken); |
| 242 | } |
| 243 | |
| 244 | /* ------------------------------------------------------------------------ |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 245 | * |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 246 | */ |
| 247 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 248 | template <typename PhysicalDisplay> |
| 249 | struct PhysicalDisplayId {}; |
| 250 | |
Dominik Laskowski | 3415776 | 2018-10-31 13:07:19 -0700 | [diff] [blame] | 251 | template <DisplayId::Type displayId> |
| 252 | using VirtualDisplayId = std::integral_constant<DisplayId::Type, displayId>; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 253 | |
| 254 | struct NoDisplayId {}; |
| 255 | |
| 256 | template <typename> |
| 257 | struct IsPhysicalDisplayId : std::bool_constant<false> {}; |
| 258 | |
| 259 | template <typename PhysicalDisplay> |
| 260 | struct IsPhysicalDisplayId<PhysicalDisplayId<PhysicalDisplay>> : std::bool_constant<true> {}; |
| 261 | |
| 262 | template <typename> |
| 263 | struct DisplayIdGetter; |
| 264 | |
| 265 | template <typename PhysicalDisplay> |
| 266 | struct DisplayIdGetter<PhysicalDisplayId<PhysicalDisplay>> { |
| 267 | static std::optional<DisplayId> get() { |
| 268 | if (!PhysicalDisplay::HAS_IDENTIFICATION_DATA) { |
| 269 | return getFallbackDisplayId(static_cast<bool>(PhysicalDisplay::PRIMARY) |
| 270 | ? HWC_DISPLAY_PRIMARY |
| 271 | : HWC_DISPLAY_EXTERNAL); |
| 272 | } |
| 273 | |
| 274 | const auto info = |
| 275 | parseDisplayIdentificationData(PhysicalDisplay::PORT, |
| 276 | PhysicalDisplay::GET_IDENTIFICATION_DATA()); |
| 277 | return info ? std::make_optional(info->id) : std::nullopt; |
| 278 | } |
| 279 | }; |
| 280 | |
Dominik Laskowski | 3415776 | 2018-10-31 13:07:19 -0700 | [diff] [blame] | 281 | template <DisplayId::Type displayId> |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 282 | struct DisplayIdGetter<VirtualDisplayId<displayId>> { |
Dominik Laskowski | 3415776 | 2018-10-31 13:07:19 -0700 | [diff] [blame] | 283 | static std::optional<DisplayId> get() { return DisplayId{displayId}; } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 284 | }; |
| 285 | |
| 286 | template <> |
| 287 | struct DisplayIdGetter<NoDisplayId> { |
| 288 | static std::optional<DisplayId> get() { return {}; } |
| 289 | }; |
| 290 | |
| 291 | // DisplayIdType can be: |
| 292 | // 1) PhysicalDisplayId<...> for generated ID of physical display backed by HWC. |
| 293 | // 2) VirtualDisplayId<...> for hard-coded ID of virtual display backed by HWC. |
| 294 | // 3) NoDisplayId for virtual display without HWC backing. |
| 295 | template <typename DisplayIdType, int width, int height, Critical critical, Async async, |
| 296 | Secure secure, Primary primary, int grallocUsage> |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 297 | struct DisplayVariant { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 298 | using DISPLAY_ID = DisplayIdGetter<DisplayIdType>; |
| 299 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 300 | // The display width and height |
| 301 | static constexpr int WIDTH = width; |
| 302 | static constexpr int HEIGHT = height; |
| 303 | |
| 304 | static constexpr int GRALLOC_USAGE = grallocUsage; |
| 305 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 306 | // Whether the display is virtual or physical |
| 307 | static constexpr Virtual VIRTUAL = |
| 308 | IsPhysicalDisplayId<DisplayIdType>{} ? Virtual::FALSE : Virtual::TRUE; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 309 | |
| 310 | // When creating native window surfaces for the framebuffer, whether those should be critical |
| 311 | static constexpr Critical CRITICAL = critical; |
| 312 | |
| 313 | // When creating native window surfaces for the framebuffer, whether those should be async |
| 314 | static constexpr Async ASYNC = async; |
| 315 | |
| 316 | // Whether the display should be treated as secure |
| 317 | static constexpr Secure SECURE = secure; |
| 318 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 319 | // Whether the display is primary |
| 320 | static constexpr Primary PRIMARY = primary; |
| 321 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 322 | static auto makeFakeExistingDisplayInjector(DisplayTransactionTest* test) { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 323 | auto injector = |
| 324 | FakeDisplayDeviceInjector(test->mFlinger, DISPLAY_ID::get(), |
| 325 | static_cast<bool>(VIRTUAL), static_cast<bool>(PRIMARY)); |
| 326 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 327 | injector.setSecure(static_cast<bool>(SECURE)); |
Alec Mouri | ba013fa | 2018-10-16 12:43:11 -0700 | [diff] [blame] | 328 | injector.setNativeWindow(test->mNativeWindow); |
| 329 | |
| 330 | // Creating a DisplayDevice requires getting default dimensions from the |
| 331 | // native window. |
| 332 | EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _)) |
| 333 | .WillRepeatedly(DoAll(SetArgPointee<1>(WIDTH), Return(0))); |
| 334 | EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _)) |
| 335 | .WillRepeatedly(DoAll(SetArgPointee<1>(HEIGHT), Return(0))); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 336 | return injector; |
| 337 | } |
| 338 | |
| 339 | // Called by tests to set up any native window creation call expectations. |
| 340 | static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) { |
| 341 | EXPECT_CALL(*test->mNativeWindowSurface, getNativeWindow()) |
| 342 | .WillOnce(Return(test->mNativeWindow)); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 343 | |
Alec Mouri | ba013fa | 2018-10-16 12:43:11 -0700 | [diff] [blame] | 344 | EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _)) |
| 345 | .WillRepeatedly(DoAll(SetArgPointee<1>(WIDTH), Return(0))); |
| 346 | EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _)) |
| 347 | .WillRepeatedly(DoAll(SetArgPointee<1>(HEIGHT), Return(0))); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | static void setupFramebufferConsumerBufferQueueCallExpectations(DisplayTransactionTest* test) { |
| 351 | EXPECT_CALL(*test->mConsumer, consumerConnect(_, false)).WillOnce(Return(NO_ERROR)); |
| 352 | EXPECT_CALL(*test->mConsumer, setConsumerName(_)).WillRepeatedly(Return(NO_ERROR)); |
| 353 | EXPECT_CALL(*test->mConsumer, setConsumerUsageBits(GRALLOC_USAGE)) |
| 354 | .WillRepeatedly(Return(NO_ERROR)); |
| 355 | EXPECT_CALL(*test->mConsumer, setDefaultBufferSize(WIDTH, HEIGHT)) |
| 356 | .WillRepeatedly(Return(NO_ERROR)); |
| 357 | EXPECT_CALL(*test->mConsumer, setMaxAcquiredBufferCount(_)) |
| 358 | .WillRepeatedly(Return(NO_ERROR)); |
| 359 | } |
| 360 | |
| 361 | static void setupFramebufferProducerBufferQueueCallExpectations(DisplayTransactionTest* test) { |
| 362 | EXPECT_CALL(*test->mProducer, allocateBuffers(0, 0, 0, 0)).WillRepeatedly(Return()); |
| 363 | } |
| 364 | }; |
| 365 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 366 | template <hwc2_display_t hwcDisplayId, HWC2::DisplayType hwcDisplayType, typename DisplayVariant, |
| 367 | typename PhysicalDisplay = void> |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 368 | struct HwcDisplayVariant { |
| 369 | // The display id supplied by the HWC |
| 370 | static constexpr hwc2_display_t HWC_DISPLAY_ID = hwcDisplayId; |
| 371 | |
| 372 | // The HWC display type |
| 373 | static constexpr HWC2::DisplayType HWC_DISPLAY_TYPE = hwcDisplayType; |
| 374 | |
| 375 | // The HWC active configuration id |
Lloyd Pique | 3c085a0 | 2018-05-09 19:38:32 -0700 | [diff] [blame] | 376 | static constexpr int HWC_ACTIVE_CONFIG_ID = 2001; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 377 | |
| 378 | static void injectPendingHotplugEvent(DisplayTransactionTest* test, |
| 379 | HWC2::Connection connection) { |
| 380 | test->mFlinger.mutablePendingHotplugEvents().emplace_back( |
| 381 | HotplugEvent{HWC_DISPLAY_ID, connection}); |
| 382 | } |
| 383 | |
| 384 | // Called by tests to inject a HWC display setup |
| 385 | static void injectHwcDisplay(DisplayTransactionTest* test) { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 386 | const auto displayId = DisplayVariant::DISPLAY_ID::get(); |
| 387 | ASSERT_TRUE(displayId); |
| 388 | FakeHwcDisplayInjector(*displayId, HWC_DISPLAY_TYPE, |
| 389 | static_cast<bool>(DisplayVariant::PRIMARY)) |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 390 | .setHwcDisplayId(HWC_DISPLAY_ID) |
| 391 | .setWidth(DisplayVariant::WIDTH) |
| 392 | .setHeight(DisplayVariant::HEIGHT) |
| 393 | .setActiveConfig(HWC_ACTIVE_CONFIG_ID) |
| 394 | .inject(&test->mFlinger, test->mComposer); |
| 395 | } |
| 396 | |
| 397 | static void setupHwcHotplugCallExpectations(DisplayTransactionTest* test) { |
| 398 | EXPECT_CALL(*test->mComposer, getDisplayType(HWC_DISPLAY_ID, _)) |
| 399 | .WillOnce(DoAll(SetArgPointee<1>(static_cast<IComposerClient::DisplayType>( |
| 400 | HWC_DISPLAY_TYPE)), |
| 401 | Return(Error::NONE))); |
| 402 | EXPECT_CALL(*test->mComposer, setClientTargetSlotCount(_)).WillOnce(Return(Error::NONE)); |
| 403 | EXPECT_CALL(*test->mComposer, getDisplayConfigs(HWC_DISPLAY_ID, _)) |
| 404 | .WillOnce(DoAll(SetArgPointee<1>(std::vector<unsigned>{HWC_ACTIVE_CONFIG_ID}), |
| 405 | Return(Error::NONE))); |
| 406 | EXPECT_CALL(*test->mComposer, |
| 407 | getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID, |
| 408 | IComposerClient::Attribute::WIDTH, _)) |
| 409 | .WillOnce(DoAll(SetArgPointee<3>(DisplayVariant::WIDTH), Return(Error::NONE))); |
| 410 | EXPECT_CALL(*test->mComposer, |
| 411 | getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID, |
| 412 | IComposerClient::Attribute::HEIGHT, _)) |
| 413 | .WillOnce(DoAll(SetArgPointee<3>(DisplayVariant::HEIGHT), Return(Error::NONE))); |
| 414 | EXPECT_CALL(*test->mComposer, |
| 415 | getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID, |
| 416 | IComposerClient::Attribute::VSYNC_PERIOD, _)) |
| 417 | .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_REFRESH_RATE), Return(Error::NONE))); |
| 418 | EXPECT_CALL(*test->mComposer, |
| 419 | getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID, |
| 420 | IComposerClient::Attribute::DPI_X, _)) |
| 421 | .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_DPI), Return(Error::NONE))); |
| 422 | EXPECT_CALL(*test->mComposer, |
| 423 | getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID, |
| 424 | IComposerClient::Attribute::DPI_Y, _)) |
| 425 | .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_DPI), Return(Error::NONE))); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 426 | |
| 427 | if (PhysicalDisplay::HAS_IDENTIFICATION_DATA) { |
| 428 | EXPECT_CALL(*test->mComposer, getDisplayIdentificationData(HWC_DISPLAY_ID, _, _)) |
| 429 | .WillOnce(DoAll(SetArgPointee<1>(PhysicalDisplay::PORT), |
| 430 | SetArgPointee<2>(PhysicalDisplay::GET_IDENTIFICATION_DATA()), |
| 431 | Return(Error::NONE))); |
| 432 | } else { |
| 433 | EXPECT_CALL(*test->mComposer, getDisplayIdentificationData(HWC_DISPLAY_ID, _, _)) |
| 434 | .WillOnce(Return(Error::UNSUPPORTED)); |
| 435 | } |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | // Called by tests to set up HWC call expectations |
| 439 | static void setupHwcGetActiveConfigCallExpectations(DisplayTransactionTest* test) { |
| 440 | EXPECT_CALL(*test->mComposer, getActiveConfig(HWC_DISPLAY_ID, _)) |
Lloyd Pique | 3c085a0 | 2018-05-09 19:38:32 -0700 | [diff] [blame] | 441 | .WillRepeatedly(DoAll(SetArgPointee<1>(HWC_ACTIVE_CONFIG_ID), Return(Error::NONE))); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 442 | } |
| 443 | }; |
| 444 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 445 | // Physical displays are expected to be synchronous, secure, and have a HWC display for output. |
| 446 | constexpr uint32_t GRALLOC_USAGE_PHYSICAL_DISPLAY = |
| 447 | GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_FB; |
| 448 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 449 | template <hwc2_display_t hwcDisplayId, typename PhysicalDisplay, int width, int height, |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 450 | Critical critical> |
| 451 | struct PhysicalDisplayVariant |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 452 | : DisplayVariant<PhysicalDisplayId<PhysicalDisplay>, width, height, critical, Async::FALSE, |
| 453 | Secure::TRUE, PhysicalDisplay::PRIMARY, GRALLOC_USAGE_PHYSICAL_DISPLAY>, |
| 454 | HwcDisplayVariant<hwcDisplayId, HWC2::DisplayType::Physical, |
| 455 | DisplayVariant<PhysicalDisplayId<PhysicalDisplay>, width, height, |
| 456 | critical, Async::FALSE, Secure::TRUE, |
| 457 | PhysicalDisplay::PRIMARY, GRALLOC_USAGE_PHYSICAL_DISPLAY>, |
| 458 | PhysicalDisplay> {}; |
| 459 | |
| 460 | template <bool hasIdentificationData> |
| 461 | struct PrimaryDisplay { |
| 462 | static constexpr Primary PRIMARY = Primary::TRUE; |
| 463 | static constexpr uint8_t PORT = 255; |
| 464 | static constexpr bool HAS_IDENTIFICATION_DATA = hasIdentificationData; |
| 465 | static constexpr auto GET_IDENTIFICATION_DATA = getInternalEdid; |
| 466 | }; |
| 467 | |
| 468 | template <bool hasIdentificationData> |
| 469 | struct ExternalDisplay { |
| 470 | static constexpr Primary PRIMARY = Primary::FALSE; |
| 471 | static constexpr uint8_t PORT = 254; |
| 472 | static constexpr bool HAS_IDENTIFICATION_DATA = hasIdentificationData; |
| 473 | static constexpr auto GET_IDENTIFICATION_DATA = getExternalEdid; |
| 474 | }; |
| 475 | |
| 476 | struct TertiaryDisplay { |
| 477 | static constexpr Primary PRIMARY = Primary::FALSE; |
| 478 | }; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 479 | |
| 480 | // A primary display is a physical display that is critical |
| 481 | using PrimaryDisplayVariant = |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 482 | PhysicalDisplayVariant<1001, PrimaryDisplay<false>, 3840, 2160, Critical::TRUE>; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 483 | |
| 484 | // An external display is physical display that is not critical. |
| 485 | using ExternalDisplayVariant = |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 486 | PhysicalDisplayVariant<1002, ExternalDisplay<false>, 1920, 1280, Critical::FALSE>; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 487 | |
| 488 | using TertiaryDisplayVariant = |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 489 | PhysicalDisplayVariant<1003, TertiaryDisplay, 1600, 1200, Critical::FALSE>; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 490 | |
| 491 | // A virtual display not supported by the HWC. |
| 492 | constexpr uint32_t GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY = 0; |
| 493 | |
| 494 | template <int width, int height, Secure secure> |
| 495 | struct NonHwcVirtualDisplayVariant |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 496 | : DisplayVariant<NoDisplayId, width, height, Critical::FALSE, Async::TRUE, secure, |
| 497 | Primary::FALSE, GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY> { |
| 498 | using Base = DisplayVariant<NoDisplayId, width, height, Critical::FALSE, Async::TRUE, secure, |
| 499 | Primary::FALSE, GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY>; |
| 500 | |
| 501 | static void injectHwcDisplay(DisplayTransactionTest*) {} |
| 502 | |
| 503 | static void setupHwcGetActiveConfigCallExpectations(DisplayTransactionTest* test) { |
| 504 | EXPECT_CALL(*test->mComposer, getActiveConfig(_, _)).Times(0); |
| 505 | } |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 506 | |
| 507 | static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) { |
| 508 | Base::setupNativeWindowSurfaceCreationCallExpectations(test); |
| 509 | EXPECT_CALL(*test->mNativeWindow, setSwapInterval(0)).Times(1); |
| 510 | } |
| 511 | }; |
| 512 | |
| 513 | // A virtual display supported by the HWC. |
| 514 | constexpr uint32_t GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY = GRALLOC_USAGE_HW_COMPOSER; |
| 515 | |
| 516 | template <int width, int height, Secure secure> |
| 517 | struct HwcVirtualDisplayVariant |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 518 | : DisplayVariant<VirtualDisplayId<42>, width, height, Critical::FALSE, Async::TRUE, secure, |
| 519 | Primary::FALSE, GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY>, |
| 520 | HwcDisplayVariant< |
| 521 | 1010, HWC2::DisplayType::Virtual, |
| 522 | DisplayVariant<VirtualDisplayId<42>, width, height, Critical::FALSE, Async::TRUE, |
| 523 | secure, Primary::FALSE, GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY>> { |
| 524 | using Base = DisplayVariant<VirtualDisplayId<42>, width, height, Critical::FALSE, Async::TRUE, |
| 525 | secure, Primary::FALSE, GRALLOC_USAGE_HW_COMPOSER>; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 526 | using Self = HwcVirtualDisplayVariant<width, height, secure>; |
| 527 | |
| 528 | static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) { |
| 529 | Base::setupNativeWindowSurfaceCreationCallExpectations(test); |
| 530 | EXPECT_CALL(*test->mNativeWindow, setSwapInterval(0)).Times(1); |
| 531 | } |
| 532 | |
| 533 | static void setupHwcVirtualDisplayCreationCallExpectations(DisplayTransactionTest* test) { |
| 534 | EXPECT_CALL(*test->mComposer, createVirtualDisplay(Base::WIDTH, Base::HEIGHT, _, _)) |
| 535 | .WillOnce(DoAll(SetArgPointee<3>(Self::HWC_DISPLAY_ID), Return(Error::NONE))); |
| 536 | EXPECT_CALL(*test->mComposer, setClientTargetSlotCount(_)).WillOnce(Return(Error::NONE)); |
| 537 | } |
| 538 | }; |
| 539 | |
| 540 | // For this variant, SurfaceFlinger should not configure itself with wide |
| 541 | // display support, so the display should not be configured for wide-color |
| 542 | // support. |
| 543 | struct WideColorSupportNotConfiguredVariant { |
| 544 | static constexpr bool WIDE_COLOR_SUPPORTED = false; |
| 545 | |
| 546 | static void injectConfigChange(DisplayTransactionTest* test) { |
| 547 | test->mFlinger.mutableHasWideColorDisplay() = false; |
Peiyong Lin | 13effd1 | 2018-07-24 17:01:47 -0700 | [diff] [blame] | 548 | test->mFlinger.mutableUseColorManagement() = false; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 549 | test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::UNMANAGED; |
| 550 | } |
| 551 | |
| 552 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
| 553 | EXPECT_CALL(*test->mComposer, getColorModes(_, _)).Times(0); |
| 554 | EXPECT_CALL(*test->mComposer, getRenderIntents(_, _, _)).Times(0); |
| 555 | EXPECT_CALL(*test->mComposer, setColorMode(_, _, _)).Times(0); |
| 556 | } |
| 557 | }; |
| 558 | |
| 559 | // For this variant, SurfaceFlinger should configure itself with wide display |
| 560 | // support, and the display should respond with an non-empty list of supported |
| 561 | // color modes. Wide-color support should be configured. |
| 562 | template <typename Display> |
| 563 | struct WideColorP3ColorimetricSupportedVariant { |
| 564 | static constexpr bool WIDE_COLOR_SUPPORTED = true; |
| 565 | |
| 566 | static void injectConfigChange(DisplayTransactionTest* test) { |
Peiyong Lin | 13effd1 | 2018-07-24 17:01:47 -0700 | [diff] [blame] | 567 | test->mFlinger.mutableUseColorManagement() = true; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 568 | test->mFlinger.mutableHasWideColorDisplay() = true; |
| 569 | test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::UNMANAGED; |
| 570 | } |
| 571 | |
| 572 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
| 573 | EXPECT_CALL(*test->mComposer, getColorModes(Display::HWC_DISPLAY_ID, _)) |
| 574 | .WillOnce(DoAll(SetArgPointee<1>(std::vector<ColorMode>({ColorMode::DISPLAY_P3})), |
| 575 | Return(Error::NONE))); |
| 576 | EXPECT_CALL(*test->mComposer, |
| 577 | getRenderIntents(Display::HWC_DISPLAY_ID, ColorMode::DISPLAY_P3, _)) |
| 578 | .WillOnce(DoAll(SetArgPointee<2>( |
| 579 | std::vector<RenderIntent>({RenderIntent::COLORIMETRIC})), |
| 580 | Return(Error::NONE))); |
| 581 | EXPECT_CALL(*test->mComposer, |
| 582 | setColorMode(Display::HWC_DISPLAY_ID, ColorMode::SRGB, |
| 583 | RenderIntent::COLORIMETRIC)) |
| 584 | .WillOnce(Return(Error::NONE)); |
| 585 | } |
| 586 | }; |
| 587 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 588 | // For this variant, SurfaceFlinger should configure itself with wide display |
| 589 | // support, but the display should respond with an empty list of supported color |
| 590 | // modes. Wide-color support for the display should not be configured. |
| 591 | template <typename Display> |
| 592 | struct WideColorNotSupportedVariant { |
| 593 | static constexpr bool WIDE_COLOR_SUPPORTED = false; |
| 594 | |
| 595 | static void injectConfigChange(DisplayTransactionTest* test) { |
Peiyong Lin | 13effd1 | 2018-07-24 17:01:47 -0700 | [diff] [blame] | 596 | test->mFlinger.mutableUseColorManagement() = true; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 597 | test->mFlinger.mutableHasWideColorDisplay() = true; |
| 598 | } |
| 599 | |
| 600 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
| 601 | EXPECT_CALL(*test->mComposer, getColorModes(Display::HWC_DISPLAY_ID, _)) |
| 602 | .WillOnce(DoAll(SetArgPointee<1>(std::vector<ColorMode>()), Return(Error::NONE))); |
Chia-I Wu | 614e142 | 2018-05-23 02:17:03 -0700 | [diff] [blame] | 603 | EXPECT_CALL(*test->mComposer, setColorMode(_, _, _)).Times(0); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 604 | } |
| 605 | }; |
| 606 | |
| 607 | // For this variant, the display is not a HWC display, so no HDR support should |
| 608 | // be configured. |
| 609 | struct NonHwcDisplayHdrSupportVariant { |
| 610 | static constexpr bool HDR10_SUPPORTED = false; |
| 611 | static constexpr bool HDR_HLG_SUPPORTED = false; |
| 612 | static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false; |
| 613 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
| 614 | EXPECT_CALL(*test->mComposer, getHdrCapabilities(_, _, _, _, _)).Times(0); |
| 615 | } |
| 616 | }; |
| 617 | |
| 618 | // For this variant, the composer should respond with a non-empty list of HDR |
| 619 | // modes containing HDR10, so HDR10 support should be configured. |
| 620 | template <typename Display> |
| 621 | struct Hdr10SupportedVariant { |
| 622 | static constexpr bool HDR10_SUPPORTED = true; |
| 623 | static constexpr bool HDR_HLG_SUPPORTED = false; |
| 624 | static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false; |
| 625 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
| 626 | EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _)) |
| 627 | .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::HDR10})), |
| 628 | Return(Error::NONE))); |
| 629 | } |
| 630 | }; |
| 631 | |
| 632 | // For this variant, the composer should respond with a non-empty list of HDR |
| 633 | // modes containing HLG, so HLG support should be configured. |
| 634 | template <typename Display> |
| 635 | struct HdrHlgSupportedVariant { |
| 636 | static constexpr bool HDR10_SUPPORTED = false; |
| 637 | static constexpr bool HDR_HLG_SUPPORTED = true; |
| 638 | static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false; |
| 639 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
| 640 | EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _)) |
| 641 | .WillOnce( |
| 642 | DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::HLG})), Return(Error::NONE))); |
| 643 | } |
| 644 | }; |
| 645 | |
| 646 | // For this variant, the composer should respond with a non-empty list of HDR |
| 647 | // modes containing DOLBY_VISION, so DOLBY_VISION support should be configured. |
| 648 | template <typename Display> |
| 649 | struct HdrDolbyVisionSupportedVariant { |
| 650 | static constexpr bool HDR10_SUPPORTED = false; |
| 651 | static constexpr bool HDR_HLG_SUPPORTED = false; |
| 652 | static constexpr bool HDR_DOLBY_VISION_SUPPORTED = true; |
| 653 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
| 654 | EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _)) |
| 655 | .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::DOLBY_VISION})), |
| 656 | Return(Error::NONE))); |
| 657 | } |
| 658 | }; |
| 659 | |
| 660 | // For this variant, the composer should respond with am empty list of HDR |
| 661 | // modes, so no HDR support should be configured. |
| 662 | template <typename Display> |
| 663 | struct HdrNotSupportedVariant { |
| 664 | static constexpr bool HDR10_SUPPORTED = false; |
| 665 | static constexpr bool HDR_HLG_SUPPORTED = false; |
| 666 | static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false; |
| 667 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
| 668 | EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _)) |
| 669 | .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>()), Return(Error::NONE))); |
| 670 | } |
| 671 | }; |
| 672 | |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 673 | struct NonHwcPerFrameMetadataSupportVariant { |
| 674 | static constexpr int PER_FRAME_METADATA_KEYS = 0; |
| 675 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
Chia-I Wu | d7e01d7 | 2018-06-21 13:39:09 +0800 | [diff] [blame] | 676 | EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(_)).Times(0); |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 677 | } |
| 678 | }; |
| 679 | |
| 680 | template <typename Display> |
| 681 | struct NoPerFrameMetadataSupportVariant { |
| 682 | static constexpr int PER_FRAME_METADATA_KEYS = 0; |
| 683 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
Chia-I Wu | d7e01d7 | 2018-06-21 13:39:09 +0800 | [diff] [blame] | 684 | EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID)) |
| 685 | .WillOnce(Return(std::vector<PerFrameMetadataKey>())); |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 686 | } |
| 687 | }; |
| 688 | |
| 689 | template <typename Display> |
| 690 | struct Smpte2086PerFrameMetadataSupportVariant { |
| 691 | static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::SMPTE2086; |
| 692 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
Chia-I Wu | d7e01d7 | 2018-06-21 13:39:09 +0800 | [diff] [blame] | 693 | EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID)) |
| 694 | .WillOnce(Return(std::vector<PerFrameMetadataKey>({ |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 695 | PerFrameMetadataKey::DISPLAY_RED_PRIMARY_X, |
| 696 | PerFrameMetadataKey::DISPLAY_RED_PRIMARY_Y, |
| 697 | PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_X, |
| 698 | PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_Y, |
| 699 | PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_X, |
| 700 | PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_Y, |
| 701 | PerFrameMetadataKey::WHITE_POINT_X, |
| 702 | PerFrameMetadataKey::WHITE_POINT_Y, |
| 703 | PerFrameMetadataKey::MAX_LUMINANCE, |
| 704 | PerFrameMetadataKey::MIN_LUMINANCE, |
Chia-I Wu | d7e01d7 | 2018-06-21 13:39:09 +0800 | [diff] [blame] | 705 | }))); |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 706 | } |
| 707 | }; |
| 708 | |
| 709 | template <typename Display> |
| 710 | struct Cta861_3_PerFrameMetadataSupportVariant { |
| 711 | static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::CTA861_3; |
| 712 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
Chia-I Wu | d7e01d7 | 2018-06-21 13:39:09 +0800 | [diff] [blame] | 713 | EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID)) |
| 714 | .WillOnce(Return(std::vector<PerFrameMetadataKey>({ |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 715 | PerFrameMetadataKey::MAX_CONTENT_LIGHT_LEVEL, |
| 716 | PerFrameMetadataKey::MAX_FRAME_AVERAGE_LIGHT_LEVEL, |
Chia-I Wu | d7e01d7 | 2018-06-21 13:39:09 +0800 | [diff] [blame] | 717 | }))); |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 718 | } |
| 719 | }; |
| 720 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 721 | /* ------------------------------------------------------------------------ |
| 722 | * Typical display configurations to test |
| 723 | */ |
| 724 | |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 725 | template <typename DisplayPolicy, typename WideColorSupportPolicy, typename HdrSupportPolicy, |
| 726 | typename PerFrameMetadataSupportPolicy> |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 727 | struct Case { |
| 728 | using Display = DisplayPolicy; |
| 729 | using WideColorSupport = WideColorSupportPolicy; |
| 730 | using HdrSupport = HdrSupportPolicy; |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 731 | using PerFrameMetadataSupport = PerFrameMetadataSupportPolicy; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 732 | }; |
| 733 | |
| 734 | using SimplePrimaryDisplayCase = |
| 735 | Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>, |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 736 | HdrNotSupportedVariant<PrimaryDisplayVariant>, |
| 737 | NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 738 | using SimpleExternalDisplayCase = |
| 739 | Case<ExternalDisplayVariant, WideColorNotSupportedVariant<ExternalDisplayVariant>, |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 740 | HdrNotSupportedVariant<ExternalDisplayVariant>, |
| 741 | NoPerFrameMetadataSupportVariant<ExternalDisplayVariant>>; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 742 | using SimpleTertiaryDisplayCase = |
| 743 | Case<TertiaryDisplayVariant, WideColorNotSupportedVariant<TertiaryDisplayVariant>, |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 744 | HdrNotSupportedVariant<TertiaryDisplayVariant>, |
| 745 | NoPerFrameMetadataSupportVariant<TertiaryDisplayVariant>>; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 746 | using NonHwcVirtualDisplayCase = |
| 747 | Case<NonHwcVirtualDisplayVariant<1024, 768, Secure::FALSE>, |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 748 | WideColorSupportNotConfiguredVariant, NonHwcDisplayHdrSupportVariant, |
| 749 | NonHwcPerFrameMetadataSupportVariant>; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 750 | using SimpleHwcVirtualDisplayVariant = HwcVirtualDisplayVariant<1024, 768, Secure::TRUE>; |
| 751 | using HwcVirtualDisplayCase = |
| 752 | Case<SimpleHwcVirtualDisplayVariant, WideColorSupportNotConfiguredVariant, |
Lloyd Pique | 438e9e7 | 2018-09-04 18:06:08 -0700 | [diff] [blame] | 753 | HdrNotSupportedVariant<SimpleHwcVirtualDisplayVariant>, |
tangrobin | 6753a02 | 2018-08-10 10:58:54 +0800 | [diff] [blame] | 754 | NoPerFrameMetadataSupportVariant<SimpleHwcVirtualDisplayVariant>>; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 755 | using WideColorP3ColorimetricDisplayCase = |
| 756 | Case<PrimaryDisplayVariant, WideColorP3ColorimetricSupportedVariant<PrimaryDisplayVariant>, |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 757 | HdrNotSupportedVariant<PrimaryDisplayVariant>, |
| 758 | NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 759 | using Hdr10DisplayCase = |
| 760 | Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>, |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 761 | Hdr10SupportedVariant<PrimaryDisplayVariant>, |
| 762 | NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 763 | using HdrHlgDisplayCase = |
| 764 | Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>, |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 765 | HdrHlgSupportedVariant<PrimaryDisplayVariant>, |
| 766 | NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 767 | using HdrDolbyVisionDisplayCase = |
| 768 | Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>, |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 769 | HdrDolbyVisionSupportedVariant<PrimaryDisplayVariant>, |
| 770 | NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>; |
| 771 | using HdrSmpte2086DisplayCase = |
| 772 | Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>, |
| 773 | HdrNotSupportedVariant<PrimaryDisplayVariant>, |
| 774 | Smpte2086PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>; |
| 775 | using HdrCta861_3_DisplayCase = |
| 776 | Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>, |
| 777 | HdrNotSupportedVariant<PrimaryDisplayVariant>, |
| 778 | Cta861_3_PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>; |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 779 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 780 | /* ------------------------------------------------------------------------ |
Lloyd Pique | 6cf1103 | 2018-01-22 18:57:44 -0800 | [diff] [blame] | 781 | * |
| 782 | * SurfaceFlinger::onHotplugReceived |
| 783 | */ |
| 784 | |
| 785 | TEST_F(DisplayTransactionTest, hotplugEnqueuesEventsForDisplayTransaction) { |
| 786 | constexpr int currentSequenceId = 123; |
Dominik Laskowski | a2edf61 | 2018-06-01 13:15:16 -0700 | [diff] [blame] | 787 | constexpr hwc2_display_t hwcDisplayId1 = 456; |
| 788 | constexpr hwc2_display_t hwcDisplayId2 = 654; |
Lloyd Pique | 6cf1103 | 2018-01-22 18:57:44 -0800 | [diff] [blame] | 789 | |
| 790 | // -------------------------------------------------------------------- |
| 791 | // Preconditions |
| 792 | |
| 793 | // Set the current sequence id for accepted events |
| 794 | mFlinger.mutableComposerSequenceId() = currentSequenceId; |
| 795 | |
| 796 | // Set the main thread id so that the current thread does not appear to be |
| 797 | // the main thread. |
| 798 | mFlinger.mutableMainThreadId() = std::thread::id(); |
| 799 | |
| 800 | // -------------------------------------------------------------------- |
| 801 | // Call Expectations |
| 802 | |
| 803 | // We expect invalidate() to be invoked once to trigger display transaction |
| 804 | // processing. |
| 805 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); |
| 806 | |
| 807 | // -------------------------------------------------------------------- |
| 808 | // Invocation |
| 809 | |
| 810 | // Simulate two hotplug events (a connect and a disconnect) |
Dominik Laskowski | a2edf61 | 2018-06-01 13:15:16 -0700 | [diff] [blame] | 811 | mFlinger.onHotplugReceived(currentSequenceId, hwcDisplayId1, HWC2::Connection::Connected); |
| 812 | mFlinger.onHotplugReceived(currentSequenceId, hwcDisplayId2, HWC2::Connection::Disconnected); |
Lloyd Pique | 6cf1103 | 2018-01-22 18:57:44 -0800 | [diff] [blame] | 813 | |
| 814 | // -------------------------------------------------------------------- |
| 815 | // Postconditions |
| 816 | |
| 817 | // The display transaction needed flag should be set. |
| 818 | EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded)); |
| 819 | |
| 820 | // All events should be in the pending event queue. |
| 821 | const auto& pendingEvents = mFlinger.mutablePendingHotplugEvents(); |
| 822 | ASSERT_EQ(2u, pendingEvents.size()); |
Dominik Laskowski | a2edf61 | 2018-06-01 13:15:16 -0700 | [diff] [blame] | 823 | EXPECT_EQ(hwcDisplayId1, pendingEvents[0].hwcDisplayId); |
Lloyd Pique | 6cf1103 | 2018-01-22 18:57:44 -0800 | [diff] [blame] | 824 | EXPECT_EQ(HWC2::Connection::Connected, pendingEvents[0].connection); |
Dominik Laskowski | a2edf61 | 2018-06-01 13:15:16 -0700 | [diff] [blame] | 825 | EXPECT_EQ(hwcDisplayId2, pendingEvents[1].hwcDisplayId); |
Lloyd Pique | 6cf1103 | 2018-01-22 18:57:44 -0800 | [diff] [blame] | 826 | EXPECT_EQ(HWC2::Connection::Disconnected, pendingEvents[1].connection); |
| 827 | } |
| 828 | |
| 829 | TEST_F(DisplayTransactionTest, hotplugDiscardsUnexpectedEvents) { |
| 830 | constexpr int currentSequenceId = 123; |
| 831 | constexpr int otherSequenceId = 321; |
| 832 | constexpr hwc2_display_t displayId = 456; |
| 833 | |
| 834 | // -------------------------------------------------------------------- |
| 835 | // Preconditions |
| 836 | |
| 837 | // Set the current sequence id for accepted events |
| 838 | mFlinger.mutableComposerSequenceId() = currentSequenceId; |
| 839 | |
| 840 | // Set the main thread id so that the current thread does not appear to be |
| 841 | // the main thread. |
| 842 | mFlinger.mutableMainThreadId() = std::thread::id(); |
| 843 | |
| 844 | // -------------------------------------------------------------------- |
| 845 | // Call Expectations |
| 846 | |
| 847 | // We do not expect any calls to invalidate(). |
| 848 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(0); |
| 849 | |
| 850 | // -------------------------------------------------------------------- |
| 851 | // Invocation |
| 852 | |
| 853 | // Call with an unexpected sequence id |
| 854 | mFlinger.onHotplugReceived(otherSequenceId, displayId, HWC2::Connection::Invalid); |
| 855 | |
| 856 | // -------------------------------------------------------------------- |
| 857 | // Postconditions |
| 858 | |
| 859 | // The display transaction needed flag should not be set |
| 860 | EXPECT_FALSE(hasTransactionFlagSet(eDisplayTransactionNeeded)); |
| 861 | |
| 862 | // There should be no pending events |
| 863 | EXPECT_TRUE(mFlinger.mutablePendingHotplugEvents().empty()); |
| 864 | } |
| 865 | |
| 866 | TEST_F(DisplayTransactionTest, hotplugProcessesEnqueuedEventsIfCalledOnMainThread) { |
| 867 | constexpr int currentSequenceId = 123; |
| 868 | constexpr hwc2_display_t displayId1 = 456; |
| 869 | |
| 870 | // -------------------------------------------------------------------- |
| 871 | // Note: |
| 872 | // -------------------------------------------------------------------- |
| 873 | // This test case is a bit tricky. We want to verify that |
| 874 | // onHotplugReceived() calls processDisplayHotplugEventsLocked(), but we |
| 875 | // don't really want to provide coverage for everything the later function |
| 876 | // does as there are specific tests for it. |
| 877 | // -------------------------------------------------------------------- |
| 878 | |
| 879 | // -------------------------------------------------------------------- |
| 880 | // Preconditions |
| 881 | |
| 882 | // Set the current sequence id for accepted events |
| 883 | mFlinger.mutableComposerSequenceId() = currentSequenceId; |
| 884 | |
| 885 | // Set the main thread id so that the current thread does appear to be the |
| 886 | // main thread. |
| 887 | mFlinger.mutableMainThreadId() = std::this_thread::get_id(); |
| 888 | |
| 889 | // -------------------------------------------------------------------- |
| 890 | // Call Expectations |
| 891 | |
| 892 | // We expect invalidate() to be invoked once to trigger display transaction |
| 893 | // processing. |
| 894 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); |
| 895 | |
| 896 | // -------------------------------------------------------------------- |
| 897 | // Invocation |
| 898 | |
| 899 | // Simulate a disconnect on a display id that is not connected. This should |
| 900 | // be enqueued by onHotplugReceived(), and dequeued by |
| 901 | // processDisplayHotplugEventsLocked(), but then ignored as invalid. |
| 902 | mFlinger.onHotplugReceived(currentSequenceId, displayId1, HWC2::Connection::Disconnected); |
| 903 | |
| 904 | // -------------------------------------------------------------------- |
| 905 | // Postconditions |
| 906 | |
| 907 | // The display transaction needed flag should be set. |
| 908 | EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded)); |
| 909 | |
| 910 | // There should be no event queued on return, as it should have been |
| 911 | // processed. |
| 912 | EXPECT_TRUE(mFlinger.mutablePendingHotplugEvents().empty()); |
| 913 | } |
| 914 | |
| 915 | /* ------------------------------------------------------------------------ |
Lloyd Pique | a482f99 | 2018-01-22 19:00:34 -0800 | [diff] [blame] | 916 | * SurfaceFlinger::createDisplay |
| 917 | */ |
| 918 | |
| 919 | TEST_F(DisplayTransactionTest, createDisplaySetsCurrentStateForNonsecureDisplay) { |
| 920 | const String8 name("virtual.test"); |
| 921 | |
| 922 | // -------------------------------------------------------------------- |
| 923 | // Call Expectations |
| 924 | |
| 925 | // The call should notify the interceptor that a display was created. |
| 926 | EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1); |
| 927 | |
| 928 | // -------------------------------------------------------------------- |
| 929 | // Invocation |
| 930 | |
| 931 | sp<IBinder> displayToken = mFlinger.createDisplay(name, false); |
| 932 | |
| 933 | // -------------------------------------------------------------------- |
| 934 | // Postconditions |
| 935 | |
| 936 | // The display should have been added to the current state |
| 937 | ASSERT_TRUE(hasCurrentDisplayState(displayToken)); |
| 938 | const auto& display = getCurrentDisplayState(displayToken); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 939 | EXPECT_TRUE(display.isVirtual()); |
| 940 | EXPECT_FALSE(display.isSecure); |
Lloyd Pique | a482f99 | 2018-01-22 19:00:34 -0800 | [diff] [blame] | 941 | EXPECT_EQ(name.string(), display.displayName); |
| 942 | |
| 943 | // -------------------------------------------------------------------- |
| 944 | // Cleanup conditions |
| 945 | |
| 946 | // Destroying the display invalidates the display state. |
| 947 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); |
| 948 | } |
| 949 | |
| 950 | TEST_F(DisplayTransactionTest, createDisplaySetsCurrentStateForSecureDisplay) { |
| 951 | const String8 name("virtual.test"); |
| 952 | |
| 953 | // -------------------------------------------------------------------- |
| 954 | // Call Expectations |
| 955 | |
| 956 | // The call should notify the interceptor that a display was created. |
| 957 | EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1); |
| 958 | |
| 959 | // -------------------------------------------------------------------- |
| 960 | // Invocation |
| 961 | |
| 962 | sp<IBinder> displayToken = mFlinger.createDisplay(name, true); |
| 963 | |
| 964 | // -------------------------------------------------------------------- |
| 965 | // Postconditions |
| 966 | |
| 967 | // The display should have been added to the current state |
| 968 | ASSERT_TRUE(hasCurrentDisplayState(displayToken)); |
| 969 | const auto& display = getCurrentDisplayState(displayToken); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 970 | EXPECT_TRUE(display.isVirtual()); |
| 971 | EXPECT_TRUE(display.isSecure); |
Lloyd Pique | a482f99 | 2018-01-22 19:00:34 -0800 | [diff] [blame] | 972 | EXPECT_EQ(name.string(), display.displayName); |
| 973 | |
| 974 | // -------------------------------------------------------------------- |
| 975 | // Cleanup conditions |
| 976 | |
| 977 | // Destroying the display invalidates the display state. |
| 978 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); |
| 979 | } |
| 980 | |
| 981 | /* ------------------------------------------------------------------------ |
| 982 | * SurfaceFlinger::destroyDisplay |
| 983 | */ |
| 984 | |
| 985 | TEST_F(DisplayTransactionTest, destroyDisplayClearsCurrentStateForDisplay) { |
| 986 | using Case = NonHwcVirtualDisplayCase; |
| 987 | |
| 988 | // -------------------------------------------------------------------- |
| 989 | // Preconditions |
| 990 | |
| 991 | // A virtual display exists |
| 992 | auto existing = Case::Display::makeFakeExistingDisplayInjector(this); |
| 993 | existing.inject(); |
| 994 | |
| 995 | // -------------------------------------------------------------------- |
| 996 | // Call Expectations |
| 997 | |
| 998 | // The call should notify the interceptor that a display was created. |
| 999 | EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1); |
| 1000 | |
| 1001 | // Destroying the display invalidates the display state. |
| 1002 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); |
| 1003 | |
| 1004 | // -------------------------------------------------------------------- |
| 1005 | // Invocation |
| 1006 | |
| 1007 | mFlinger.destroyDisplay(existing.token()); |
| 1008 | |
| 1009 | // -------------------------------------------------------------------- |
| 1010 | // Postconditions |
| 1011 | |
| 1012 | // The display should have been removed from the current state |
| 1013 | EXPECT_FALSE(hasCurrentDisplayState(existing.token())); |
| 1014 | |
| 1015 | // Ths display should still exist in the drawing state |
| 1016 | EXPECT_TRUE(hasDrawingDisplayState(existing.token())); |
| 1017 | |
| 1018 | // The display transaction needed flasg should be set |
| 1019 | EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded)); |
| 1020 | } |
| 1021 | |
| 1022 | TEST_F(DisplayTransactionTest, destroyDisplayHandlesUnknownDisplay) { |
| 1023 | // -------------------------------------------------------------------- |
| 1024 | // Preconditions |
| 1025 | |
| 1026 | sp<BBinder> displayToken = new BBinder(); |
| 1027 | |
| 1028 | // -------------------------------------------------------------------- |
| 1029 | // Invocation |
| 1030 | |
| 1031 | mFlinger.destroyDisplay(displayToken); |
| 1032 | } |
| 1033 | |
| 1034 | /* ------------------------------------------------------------------------ |
Lloyd Pique | d6fbb8a | 2018-01-22 19:08:36 -0800 | [diff] [blame] | 1035 | * SurfaceFlinger::resetDisplayState |
| 1036 | */ |
| 1037 | |
| 1038 | TEST_F(DisplayTransactionTest, resetDisplayStateClearsState) { |
| 1039 | using Case = NonHwcVirtualDisplayCase; |
| 1040 | |
| 1041 | // -------------------------------------------------------------------- |
| 1042 | // Preconditions |
| 1043 | |
| 1044 | // vsync is enabled and available |
| 1045 | mFlinger.mutablePrimaryHWVsyncEnabled() = true; |
| 1046 | mFlinger.mutableHWVsyncAvailable() = true; |
| 1047 | |
| 1048 | // A display exists |
| 1049 | auto existing = Case::Display::makeFakeExistingDisplayInjector(this); |
| 1050 | existing.inject(); |
| 1051 | |
| 1052 | // -------------------------------------------------------------------- |
| 1053 | // Call Expectations |
| 1054 | |
| 1055 | // The call disable vsyncs |
| 1056 | EXPECT_CALL(*mEventControlThread, setVsyncEnabled(false)).Times(1); |
| 1057 | |
Lloyd Pique | 41be5d2 | 2018-06-21 13:11:48 -0700 | [diff] [blame] | 1058 | // The call ends any display resyncs |
| 1059 | EXPECT_CALL(*mPrimaryDispSync, endResync()).Times(1); |
| 1060 | |
Lloyd Pique | d6fbb8a | 2018-01-22 19:08:36 -0800 | [diff] [blame] | 1061 | // -------------------------------------------------------------------- |
| 1062 | // Invocation |
| 1063 | |
| 1064 | mFlinger.resetDisplayState(); |
| 1065 | |
| 1066 | // -------------------------------------------------------------------- |
| 1067 | // Postconditions |
| 1068 | |
| 1069 | // vsyncs should be off and not available. |
| 1070 | EXPECT_FALSE(mFlinger.mutablePrimaryHWVsyncEnabled()); |
| 1071 | EXPECT_FALSE(mFlinger.mutableHWVsyncAvailable()); |
| 1072 | |
| 1073 | // The display should have been removed from the display map. |
| 1074 | EXPECT_FALSE(hasDisplayDevice(existing.token())); |
| 1075 | |
| 1076 | // The display should still exist in the current state |
| 1077 | EXPECT_TRUE(hasCurrentDisplayState(existing.token())); |
| 1078 | |
| 1079 | // The display should have been removed from the drawing state |
| 1080 | EXPECT_FALSE(hasDrawingDisplayState(existing.token())); |
| 1081 | } |
| 1082 | |
| 1083 | /* ------------------------------------------------------------------------ |
Valerie Hau | 9758ae0 | 2018-10-09 16:05:09 -0700 | [diff] [blame] | 1084 | * DisplayDevice::GetBestColorMode |
| 1085 | */ |
| 1086 | class GetBestColorModeTest : public DisplayTransactionTest { |
| 1087 | public: |
Dominik Laskowski | 3415776 | 2018-10-31 13:07:19 -0700 | [diff] [blame] | 1088 | static constexpr DisplayId DEFAULT_DISPLAY_ID = DisplayId{777}; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1089 | |
Valerie Hau | 9758ae0 | 2018-10-09 16:05:09 -0700 | [diff] [blame] | 1090 | GetBestColorModeTest() |
| 1091 | : DisplayTransactionTest(), |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1092 | mInjector(FakeDisplayDeviceInjector(mFlinger, DEFAULT_DISPLAY_ID, false /* isVirtual */, |
| 1093 | true /* isPrimary */)) {} |
Valerie Hau | 9758ae0 | 2018-10-09 16:05:09 -0700 | [diff] [blame] | 1094 | |
| 1095 | void setHasWideColorGamut(bool hasWideColorGamut) { mHasWideColorGamut = hasWideColorGamut; } |
| 1096 | |
| 1097 | void addHwcColorModesMapping(ui::ColorMode colorMode, |
| 1098 | std::vector<ui::RenderIntent> renderIntents) { |
| 1099 | mHwcColorModes[colorMode] = renderIntents; |
| 1100 | } |
| 1101 | |
| 1102 | void setInputDataspace(ui::Dataspace dataspace) { mInputDataspace = dataspace; } |
| 1103 | |
| 1104 | void setInputRenderIntent(ui::RenderIntent renderIntent) { mInputRenderIntent = renderIntent; } |
| 1105 | |
| 1106 | void getBestColorMode() { |
| 1107 | mInjector.setHwcColorModes(mHwcColorModes); |
| 1108 | mInjector.setHasWideColorGamut(mHasWideColorGamut); |
Alec Mouri | ba013fa | 2018-10-16 12:43:11 -0700 | [diff] [blame] | 1109 | mInjector.setNativeWindow(mNativeWindow); |
| 1110 | |
| 1111 | // Creating a DisplayDevice requires getting default dimensions from the |
| 1112 | // native window. |
| 1113 | EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_WIDTH, _)) |
| 1114 | .WillRepeatedly(DoAll(SetArgPointee<1>(1080 /* arbitrary */), Return(0))); |
| 1115 | EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _)) |
| 1116 | .WillRepeatedly(DoAll(SetArgPointee<1>(1920 /* arbitrary */), Return(0))); |
Alec Mouri | 4efb6c2 | 2018-11-16 13:07:47 -0800 | [diff] [blame] | 1117 | EXPECT_CALL(*mNativeWindow, perform(9)).Times(1); |
Alec Mouri | 0a9c7b8 | 2018-11-16 13:05:25 -0800 | [diff] [blame] | 1118 | EXPECT_CALL(*mNativeWindow, perform(13)).Times(1); |
Alec Mouri | 4efb6c2 | 2018-11-16 13:07:47 -0800 | [diff] [blame] | 1119 | EXPECT_CALL(*mNativeWindow, perform(30)).Times(1); |
Valerie Hau | 9758ae0 | 2018-10-09 16:05:09 -0700 | [diff] [blame] | 1120 | auto displayDevice = mInjector.inject(); |
| 1121 | |
| 1122 | displayDevice->getBestColorMode(mInputDataspace, mInputRenderIntent, &mOutDataspace, |
| 1123 | &mOutColorMode, &mOutRenderIntent); |
| 1124 | } |
| 1125 | |
| 1126 | ui::Dataspace mOutDataspace; |
| 1127 | ui::ColorMode mOutColorMode; |
| 1128 | ui::RenderIntent mOutRenderIntent; |
| 1129 | |
| 1130 | private: |
| 1131 | ui::Dataspace mInputDataspace; |
| 1132 | ui::RenderIntent mInputRenderIntent; |
| 1133 | bool mHasWideColorGamut = false; |
| 1134 | std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>> mHwcColorModes; |
| 1135 | FakeDisplayDeviceInjector mInjector; |
| 1136 | }; |
| 1137 | |
| 1138 | TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeSRGB) { |
| 1139 | addHwcColorModesMapping(ui::ColorMode::SRGB, |
| 1140 | std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC)); |
| 1141 | setInputDataspace(ui::Dataspace::DISPLAY_P3); |
| 1142 | setInputRenderIntent(ui::RenderIntent::COLORIMETRIC); |
| 1143 | setHasWideColorGamut(true); |
| 1144 | |
| 1145 | getBestColorMode(); |
| 1146 | |
Peiyong Lin | 14724e6 | 2018-12-05 07:27:30 -0800 | [diff] [blame^] | 1147 | ASSERT_EQ(ui::Dataspace::V0_SRGB, mOutDataspace); |
Valerie Hau | 9758ae0 | 2018-10-09 16:05:09 -0700 | [diff] [blame] | 1148 | ASSERT_EQ(ui::ColorMode::SRGB, mOutColorMode); |
| 1149 | ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent); |
| 1150 | } |
| 1151 | |
| 1152 | TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeDisplayP3) { |
| 1153 | addHwcColorModesMapping(ui::ColorMode::DISPLAY_P3, |
| 1154 | std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC)); |
| 1155 | addHwcColorModesMapping(ui::ColorMode::SRGB, |
| 1156 | std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC)); |
| 1157 | addHwcColorModesMapping(ui::ColorMode::DISPLAY_BT2020, |
| 1158 | std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC)); |
| 1159 | setInputDataspace(ui::Dataspace::DISPLAY_P3); |
| 1160 | setInputRenderIntent(ui::RenderIntent::COLORIMETRIC); |
| 1161 | setHasWideColorGamut(true); |
| 1162 | |
| 1163 | getBestColorMode(); |
| 1164 | |
| 1165 | ASSERT_EQ(ui::Dataspace::DISPLAY_P3, mOutDataspace); |
| 1166 | ASSERT_EQ(ui::ColorMode::DISPLAY_P3, mOutColorMode); |
| 1167 | ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent); |
| 1168 | } |
| 1169 | |
| 1170 | TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeDISPLAY_BT2020) { |
| 1171 | addHwcColorModesMapping(ui::ColorMode::DISPLAY_BT2020, |
| 1172 | std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC)); |
| 1173 | setInputDataspace(ui::Dataspace::DISPLAY_P3); |
| 1174 | setInputRenderIntent(ui::RenderIntent::COLORIMETRIC); |
| 1175 | setHasWideColorGamut(true); |
| 1176 | |
| 1177 | getBestColorMode(); |
| 1178 | |
| 1179 | ASSERT_EQ(ui::Dataspace::DISPLAY_BT2020, mOutDataspace); |
| 1180 | ASSERT_EQ(ui::ColorMode::DISPLAY_BT2020, mOutColorMode); |
| 1181 | ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent); |
| 1182 | } |
| 1183 | |
| 1184 | /* ------------------------------------------------------------------------ |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1185 | * SurfaceFlinger::setupNewDisplayDeviceInternal |
| 1186 | */ |
| 1187 | |
| 1188 | class SetupNewDisplayDeviceInternalTest : public DisplayTransactionTest { |
| 1189 | public: |
| 1190 | template <typename T> |
| 1191 | void setupNewDisplayDeviceInternalTest(); |
| 1192 | }; |
| 1193 | |
| 1194 | template <typename Case> |
| 1195 | void SetupNewDisplayDeviceInternalTest::setupNewDisplayDeviceInternalTest() { |
| 1196 | const sp<BBinder> displayToken = new BBinder(); |
| 1197 | const sp<mock::DisplaySurface> displaySurface = new mock::DisplaySurface(); |
| 1198 | const sp<mock::GraphicBufferProducer> producer = new mock::GraphicBufferProducer(); |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 1199 | |
| 1200 | // -------------------------------------------------------------------- |
| 1201 | // Preconditions |
| 1202 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1203 | // Wide color displays support is configured appropriately |
| 1204 | Case::WideColorSupport::injectConfigChange(this); |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 1205 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1206 | // The display is setup with the HWC. |
| 1207 | Case::Display::injectHwcDisplay(this); |
| 1208 | |
| 1209 | // SurfaceFlinger will use a test-controlled factory for native window |
| 1210 | // surfaces. |
| 1211 | injectFakeNativeWindowSurfaceFactory(); |
| 1212 | |
| 1213 | // -------------------------------------------------------------------- |
| 1214 | // Call Expectations |
| 1215 | |
| 1216 | // Various native window calls will be made. |
| 1217 | Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this); |
Lloyd Pique | 3c085a0 | 2018-05-09 19:38:32 -0700 | [diff] [blame] | 1218 | Case::Display::setupHwcGetActiveConfigCallExpectations(this); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1219 | Case::WideColorSupport::setupComposerCallExpectations(this); |
| 1220 | Case::HdrSupport::setupComposerCallExpectations(this); |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 1221 | Case::PerFrameMetadataSupport::setupComposerCallExpectations(this); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1222 | |
| 1223 | // -------------------------------------------------------------------- |
| 1224 | // Invocation |
| 1225 | |
| 1226 | DisplayDeviceState state; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1227 | state.displayId = static_cast<bool>(Case::Display::VIRTUAL) ? std::nullopt |
| 1228 | : Case::Display::DISPLAY_ID::get(); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1229 | state.isSecure = static_cast<bool>(Case::Display::SECURE); |
| 1230 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1231 | auto device = |
| 1232 | mFlinger.setupNewDisplayDeviceInternal(displayToken, Case::Display::DISPLAY_ID::get(), |
| 1233 | state, displaySurface, producer); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1234 | |
| 1235 | // -------------------------------------------------------------------- |
| 1236 | // Postconditions |
| 1237 | |
| 1238 | ASSERT_TRUE(device != nullptr); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1239 | EXPECT_EQ(Case::Display::DISPLAY_ID::get(), device->getId()); |
| 1240 | EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), device->isVirtual()); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1241 | EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure()); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1242 | EXPECT_EQ(static_cast<bool>(Case::Display::PRIMARY), device->isPrimary()); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1243 | EXPECT_EQ(Case::Display::WIDTH, device->getWidth()); |
| 1244 | EXPECT_EQ(Case::Display::HEIGHT, device->getHeight()); |
| 1245 | EXPECT_EQ(Case::WideColorSupport::WIDE_COLOR_SUPPORTED, device->hasWideColorGamut()); |
| 1246 | EXPECT_EQ(Case::HdrSupport::HDR10_SUPPORTED, device->hasHDR10Support()); |
| 1247 | EXPECT_EQ(Case::HdrSupport::HDR_HLG_SUPPORTED, device->hasHLGSupport()); |
| 1248 | EXPECT_EQ(Case::HdrSupport::HDR_DOLBY_VISION_SUPPORTED, device->hasDolbyVisionSupport()); |
Lloyd Pique | 3c085a0 | 2018-05-09 19:38:32 -0700 | [diff] [blame] | 1249 | // Note: This is not Case::Display::HWC_ACTIVE_CONFIG_ID as the ids are |
| 1250 | // remapped, and the test only ever sets up one config. If there were an error |
| 1251 | // looking up the remapped index, device->getActiveConfig() would be -1 instead. |
| 1252 | EXPECT_EQ(0, device->getActiveConfig()); |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 1253 | EXPECT_EQ(Case::PerFrameMetadataSupport::PER_FRAME_METADATA_KEYS, |
| 1254 | device->getSupportedPerFrameMetadata()); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1255 | } |
| 1256 | |
| 1257 | TEST_F(SetupNewDisplayDeviceInternalTest, createSimplePrimaryDisplay) { |
| 1258 | setupNewDisplayDeviceInternalTest<SimplePrimaryDisplayCase>(); |
| 1259 | } |
| 1260 | |
| 1261 | TEST_F(SetupNewDisplayDeviceInternalTest, createSimpleExternalDisplay) { |
| 1262 | setupNewDisplayDeviceInternalTest<SimpleExternalDisplayCase>(); |
| 1263 | } |
| 1264 | |
| 1265 | TEST_F(SetupNewDisplayDeviceInternalTest, createNonHwcVirtualDisplay) { |
| 1266 | setupNewDisplayDeviceInternalTest<NonHwcVirtualDisplayCase>(); |
| 1267 | } |
| 1268 | |
| 1269 | TEST_F(SetupNewDisplayDeviceInternalTest, createHwcVirtualDisplay) { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1270 | using Case = HwcVirtualDisplayCase; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1271 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1272 | // Insert display data so that the HWC thinks it created the virtual display. |
| 1273 | const auto displayId = Case::Display::DISPLAY_ID::get(); |
| 1274 | ASSERT_TRUE(displayId); |
Dominik Laskowski | 1af4793 | 2018-11-12 10:20:46 -0800 | [diff] [blame] | 1275 | mFlinger.mutableHwcDisplayData().try_emplace(*displayId); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1276 | |
| 1277 | setupNewDisplayDeviceInternalTest<Case>(); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1278 | } |
| 1279 | |
| 1280 | TEST_F(SetupNewDisplayDeviceInternalTest, createWideColorP3Display) { |
| 1281 | setupNewDisplayDeviceInternalTest<WideColorP3ColorimetricDisplayCase>(); |
| 1282 | } |
| 1283 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1284 | TEST_F(SetupNewDisplayDeviceInternalTest, createHdr10Display) { |
| 1285 | setupNewDisplayDeviceInternalTest<Hdr10DisplayCase>(); |
| 1286 | } |
| 1287 | |
| 1288 | TEST_F(SetupNewDisplayDeviceInternalTest, createHdrHlgDisplay) { |
| 1289 | setupNewDisplayDeviceInternalTest<HdrHlgDisplayCase>(); |
| 1290 | } |
| 1291 | |
| 1292 | TEST_F(SetupNewDisplayDeviceInternalTest, createHdrDolbyVisionDisplay) { |
| 1293 | setupNewDisplayDeviceInternalTest<HdrDolbyVisionDisplayCase>(); |
| 1294 | } |
| 1295 | |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 1296 | TEST_F(SetupNewDisplayDeviceInternalTest, createHdrSmpte2086DisplayCase) { |
| 1297 | setupNewDisplayDeviceInternalTest<HdrSmpte2086DisplayCase>(); |
| 1298 | } |
| 1299 | |
| 1300 | TEST_F(SetupNewDisplayDeviceInternalTest, createHdrCta816_3_DisplayCase) { |
| 1301 | setupNewDisplayDeviceInternalTest<HdrCta861_3_DisplayCase>(); |
| 1302 | } |
| 1303 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1304 | /* ------------------------------------------------------------------------ |
| 1305 | * SurfaceFlinger::handleTransactionLocked(eDisplayTransactionNeeded) |
| 1306 | */ |
| 1307 | |
| 1308 | class HandleTransactionLockedTest : public DisplayTransactionTest { |
| 1309 | public: |
| 1310 | template <typename Case> |
| 1311 | void setupCommonPreconditions(); |
| 1312 | |
| 1313 | template <typename Case> |
| 1314 | void setupCommonCallExpectationsForConnectProcessing(); |
| 1315 | |
| 1316 | template <typename Case> |
| 1317 | void setupCommonCallExpectationsForDisconnectProcessing(); |
| 1318 | |
| 1319 | template <typename Case> |
| 1320 | void processesHotplugConnectCommon(); |
| 1321 | |
| 1322 | template <typename Case> |
| 1323 | void ignoresHotplugConnectCommon(); |
| 1324 | |
| 1325 | template <typename Case> |
| 1326 | void processesHotplugDisconnectCommon(); |
| 1327 | |
| 1328 | template <typename Case> |
| 1329 | void verifyDisplayIsConnected(const sp<IBinder>& displayToken); |
| 1330 | |
| 1331 | template <typename Case> |
| 1332 | void verifyPhysicalDisplayIsConnected(); |
| 1333 | |
| 1334 | void verifyDisplayIsNotConnected(const sp<IBinder>& displayToken); |
| 1335 | }; |
| 1336 | |
| 1337 | template <typename Case> |
| 1338 | void HandleTransactionLockedTest::setupCommonPreconditions() { |
| 1339 | // Wide color displays support is configured appropriately |
| 1340 | Case::WideColorSupport::injectConfigChange(this); |
| 1341 | |
| 1342 | // SurfaceFlinger will use a test-controlled factory for BufferQueues |
| 1343 | injectFakeBufferQueueFactory(); |
| 1344 | |
| 1345 | // SurfaceFlinger will use a test-controlled factory for native window |
| 1346 | // surfaces. |
| 1347 | injectFakeNativeWindowSurfaceFactory(); |
| 1348 | } |
| 1349 | |
| 1350 | template <typename Case> |
| 1351 | void HandleTransactionLockedTest::setupCommonCallExpectationsForConnectProcessing() { |
| 1352 | Case::Display::setupHwcHotplugCallExpectations(this); |
| 1353 | |
| 1354 | Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this); |
| 1355 | Case::Display::setupFramebufferProducerBufferQueueCallExpectations(this); |
| 1356 | Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this); |
| 1357 | Case::Display::setupHwcGetActiveConfigCallExpectations(this); |
| 1358 | |
| 1359 | Case::WideColorSupport::setupComposerCallExpectations(this); |
| 1360 | Case::HdrSupport::setupComposerCallExpectations(this); |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 1361 | Case::PerFrameMetadataSupport::setupComposerCallExpectations(this); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1362 | |
| 1363 | EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1); |
Dominik Laskowski | 00a6fa2 | 2018-06-06 16:42:02 -0700 | [diff] [blame] | 1364 | EXPECT_CALL(*mEventThread, |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1365 | onHotplugReceived(static_cast<bool>(Case::Display::PRIMARY) |
Dominik Laskowski | 00a6fa2 | 2018-06-06 16:42:02 -0700 | [diff] [blame] | 1366 | ? EventThread::DisplayType::Primary |
| 1367 | : EventThread::DisplayType::External, |
| 1368 | true)) |
| 1369 | .Times(1); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1370 | } |
| 1371 | |
| 1372 | template <typename Case> |
| 1373 | void HandleTransactionLockedTest::setupCommonCallExpectationsForDisconnectProcessing() { |
| 1374 | EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1); |
Dominik Laskowski | 00a6fa2 | 2018-06-06 16:42:02 -0700 | [diff] [blame] | 1375 | EXPECT_CALL(*mEventThread, |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1376 | onHotplugReceived(static_cast<bool>(Case::Display::PRIMARY) |
Dominik Laskowski | 00a6fa2 | 2018-06-06 16:42:02 -0700 | [diff] [blame] | 1377 | ? EventThread::DisplayType::Primary |
| 1378 | : EventThread::DisplayType::External, |
| 1379 | false)) |
| 1380 | .Times(1); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1381 | } |
| 1382 | |
| 1383 | template <typename Case> |
| 1384 | void HandleTransactionLockedTest::verifyDisplayIsConnected(const sp<IBinder>& displayToken) { |
| 1385 | // The display device should have been set up in the list of displays. |
| 1386 | ASSERT_TRUE(hasDisplayDevice(displayToken)); |
| 1387 | const auto& device = getDisplayDevice(displayToken); |
| 1388 | EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure()); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1389 | EXPECT_EQ(static_cast<bool>(Case::Display::PRIMARY), device->isPrimary()); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1390 | |
| 1391 | // The display should have been set up in the current display state |
| 1392 | ASSERT_TRUE(hasCurrentDisplayState(displayToken)); |
| 1393 | const auto& current = getCurrentDisplayState(displayToken); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1394 | EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), current.isVirtual()); |
| 1395 | EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL) ? std::nullopt |
| 1396 | : Case::Display::DISPLAY_ID::get(), |
| 1397 | current.displayId); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1398 | |
| 1399 | // The display should have been set up in the drawing display state |
| 1400 | ASSERT_TRUE(hasDrawingDisplayState(displayToken)); |
| 1401 | const auto& draw = getDrawingDisplayState(displayToken); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1402 | EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), draw.isVirtual()); |
| 1403 | EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL) ? std::nullopt |
| 1404 | : Case::Display::DISPLAY_ID::get(), |
| 1405 | draw.displayId); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1406 | } |
| 1407 | |
| 1408 | template <typename Case> |
| 1409 | void HandleTransactionLockedTest::verifyPhysicalDisplayIsConnected() { |
| 1410 | // HWComposer should have an entry for the display |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1411 | EXPECT_TRUE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID)); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1412 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1413 | // SF should have a display token. |
| 1414 | const auto displayId = Case::Display::DISPLAY_ID::get(); |
| 1415 | ASSERT_TRUE(displayId); |
| 1416 | ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 1); |
| 1417 | auto& displayToken = mFlinger.mutablePhysicalDisplayTokens()[*displayId]; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1418 | |
| 1419 | verifyDisplayIsConnected<Case>(displayToken); |
| 1420 | } |
| 1421 | |
| 1422 | void HandleTransactionLockedTest::verifyDisplayIsNotConnected(const sp<IBinder>& displayToken) { |
| 1423 | EXPECT_FALSE(hasDisplayDevice(displayToken)); |
| 1424 | EXPECT_FALSE(hasCurrentDisplayState(displayToken)); |
| 1425 | EXPECT_FALSE(hasDrawingDisplayState(displayToken)); |
| 1426 | } |
| 1427 | |
| 1428 | template <typename Case> |
| 1429 | void HandleTransactionLockedTest::processesHotplugConnectCommon() { |
| 1430 | // -------------------------------------------------------------------- |
| 1431 | // Preconditions |
| 1432 | |
| 1433 | setupCommonPreconditions<Case>(); |
| 1434 | |
| 1435 | // A hotplug connect event is enqueued for a display |
| 1436 | Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected); |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 1437 | |
| 1438 | // -------------------------------------------------------------------- |
| 1439 | // Call Expectations |
| 1440 | |
| 1441 | EXPECT_CALL(*mComposer, isUsingVrComposer()).WillOnce(Return(false)); |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 1442 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1443 | setupCommonCallExpectationsForConnectProcessing<Case>(); |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 1444 | |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 1445 | // -------------------------------------------------------------------- |
| 1446 | // Invocation |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 1447 | |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 1448 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 1449 | |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 1450 | // -------------------------------------------------------------------- |
| 1451 | // Postconditions |
| 1452 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1453 | verifyPhysicalDisplayIsConnected<Case>(); |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 1454 | |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 1455 | // -------------------------------------------------------------------- |
| 1456 | // Cleanup conditions |
| 1457 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1458 | EXPECT_CALL(*mComposer, |
| 1459 | setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE)) |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 1460 | .WillOnce(Return(Error::NONE)); |
| 1461 | EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR)); |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 1462 | } |
| 1463 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1464 | template <typename Case> |
| 1465 | void HandleTransactionLockedTest::ignoresHotplugConnectCommon() { |
| 1466 | // -------------------------------------------------------------------- |
| 1467 | // Preconditions |
| 1468 | |
| 1469 | setupCommonPreconditions<Case>(); |
| 1470 | |
| 1471 | // A hotplug connect event is enqueued for a display |
| 1472 | Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected); |
| 1473 | |
| 1474 | // -------------------------------------------------------------------- |
| 1475 | // Invocation |
| 1476 | |
| 1477 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
| 1478 | |
| 1479 | // -------------------------------------------------------------------- |
| 1480 | // Postconditions |
| 1481 | |
| 1482 | // HWComposer should not have an entry for the display |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1483 | EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID)); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1484 | } |
| 1485 | |
| 1486 | template <typename Case> |
| 1487 | void HandleTransactionLockedTest::processesHotplugDisconnectCommon() { |
| 1488 | // -------------------------------------------------------------------- |
| 1489 | // Preconditions |
| 1490 | |
| 1491 | setupCommonPreconditions<Case>(); |
| 1492 | |
| 1493 | // A hotplug disconnect event is enqueued for a display |
| 1494 | Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected); |
| 1495 | |
| 1496 | // The display is already completely set up. |
| 1497 | Case::Display::injectHwcDisplay(this); |
| 1498 | auto existing = Case::Display::makeFakeExistingDisplayInjector(this); |
| 1499 | existing.inject(); |
| 1500 | |
| 1501 | // -------------------------------------------------------------------- |
| 1502 | // Call Expectations |
| 1503 | |
| 1504 | EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false)); |
Lloyd Pique | 438e9e7 | 2018-09-04 18:06:08 -0700 | [diff] [blame] | 1505 | EXPECT_CALL(*mComposer, getDisplayIdentificationData(Case::Display::HWC_DISPLAY_ID, _, _)) |
| 1506 | .Times(0); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1507 | |
| 1508 | setupCommonCallExpectationsForDisconnectProcessing<Case>(); |
| 1509 | |
| 1510 | // -------------------------------------------------------------------- |
| 1511 | // Invocation |
| 1512 | |
| 1513 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
| 1514 | |
| 1515 | // -------------------------------------------------------------------- |
| 1516 | // Postconditions |
| 1517 | |
| 1518 | // HWComposer should not have an entry for the display |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1519 | EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID)); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1520 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1521 | // SF should not have a display token. |
| 1522 | const auto displayId = Case::Display::DISPLAY_ID::get(); |
| 1523 | ASSERT_TRUE(displayId); |
| 1524 | ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 0); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1525 | |
| 1526 | // The existing token should have been removed |
| 1527 | verifyDisplayIsNotConnected(existing.token()); |
| 1528 | } |
| 1529 | |
| 1530 | TEST_F(HandleTransactionLockedTest, processesHotplugConnectPrimaryDisplay) { |
| 1531 | processesHotplugConnectCommon<SimplePrimaryDisplayCase>(); |
| 1532 | } |
| 1533 | |
| 1534 | TEST_F(HandleTransactionLockedTest, |
| 1535 | processesHotplugConnectPrimaryDisplayWithExternalAlreadyConnected) { |
| 1536 | // Inject an external display. |
| 1537 | ExternalDisplayVariant::injectHwcDisplay(this); |
| 1538 | |
| 1539 | processesHotplugConnectCommon<SimplePrimaryDisplayCase>(); |
| 1540 | } |
| 1541 | |
| 1542 | TEST_F(HandleTransactionLockedTest, processesHotplugConnectExternalDisplay) { |
| 1543 | // Inject a primary display. |
| 1544 | PrimaryDisplayVariant::injectHwcDisplay(this); |
| 1545 | |
| 1546 | processesHotplugConnectCommon<SimpleExternalDisplayCase>(); |
| 1547 | } |
| 1548 | |
| 1549 | TEST_F(HandleTransactionLockedTest, ignoresHotplugConnectIfPrimaryAndExternalAlreadyConnected) { |
| 1550 | // Inject both a primary and external display. |
| 1551 | PrimaryDisplayVariant::injectHwcDisplay(this); |
| 1552 | ExternalDisplayVariant::injectHwcDisplay(this); |
| 1553 | |
| 1554 | EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false)); |
| 1555 | |
| 1556 | ignoresHotplugConnectCommon<SimpleTertiaryDisplayCase>(); |
| 1557 | } |
| 1558 | |
| 1559 | TEST_F(HandleTransactionLockedTest, ignoresHotplugConnectIfExternalForVrComposer) { |
| 1560 | // Inject a primary display. |
| 1561 | PrimaryDisplayVariant::injectHwcDisplay(this); |
| 1562 | |
| 1563 | EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(true)); |
| 1564 | |
| 1565 | ignoresHotplugConnectCommon<SimpleExternalDisplayCase>(); |
| 1566 | } |
| 1567 | |
| 1568 | TEST_F(HandleTransactionLockedTest, processHotplugDisconnectPrimaryDisplay) { |
| 1569 | processesHotplugDisconnectCommon<SimplePrimaryDisplayCase>(); |
| 1570 | } |
| 1571 | |
| 1572 | TEST_F(HandleTransactionLockedTest, processHotplugDisconnectExternalDisplay) { |
| 1573 | processesHotplugDisconnectCommon<SimpleExternalDisplayCase>(); |
| 1574 | } |
| 1575 | |
| 1576 | TEST_F(HandleTransactionLockedTest, processesHotplugConnectThenDisconnectPrimary) { |
| 1577 | using Case = SimplePrimaryDisplayCase; |
| 1578 | |
| 1579 | // -------------------------------------------------------------------- |
| 1580 | // Preconditions |
| 1581 | |
| 1582 | setupCommonPreconditions<Case>(); |
| 1583 | |
| 1584 | // A hotplug connect event is enqueued for a display |
| 1585 | Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected); |
| 1586 | // A hotplug disconnect event is also enqueued for the same display |
| 1587 | Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected); |
| 1588 | |
| 1589 | // -------------------------------------------------------------------- |
| 1590 | // Call Expectations |
| 1591 | |
| 1592 | EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false)); |
| 1593 | |
| 1594 | setupCommonCallExpectationsForConnectProcessing<Case>(); |
| 1595 | setupCommonCallExpectationsForDisconnectProcessing<Case>(); |
| 1596 | |
| 1597 | EXPECT_CALL(*mComposer, |
| 1598 | setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE)) |
| 1599 | .WillOnce(Return(Error::NONE)); |
| 1600 | EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR)); |
| 1601 | |
| 1602 | // -------------------------------------------------------------------- |
| 1603 | // Invocation |
| 1604 | |
| 1605 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
| 1606 | |
| 1607 | // -------------------------------------------------------------------- |
| 1608 | // Postconditions |
| 1609 | |
| 1610 | // HWComposer should not have an entry for the display |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1611 | EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID)); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1612 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1613 | // SF should not have a display token. |
| 1614 | const auto displayId = Case::Display::DISPLAY_ID::get(); |
| 1615 | ASSERT_TRUE(displayId); |
| 1616 | ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 0); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1617 | } |
| 1618 | |
| 1619 | TEST_F(HandleTransactionLockedTest, processesHotplugDisconnectThenConnectPrimary) { |
| 1620 | using Case = SimplePrimaryDisplayCase; |
| 1621 | |
| 1622 | // -------------------------------------------------------------------- |
| 1623 | // Preconditions |
| 1624 | |
| 1625 | setupCommonPreconditions<Case>(); |
| 1626 | |
| 1627 | // The display is already completely set up. |
| 1628 | Case::Display::injectHwcDisplay(this); |
| 1629 | auto existing = Case::Display::makeFakeExistingDisplayInjector(this); |
| 1630 | existing.inject(); |
| 1631 | |
| 1632 | // A hotplug disconnect event is enqueued for a display |
| 1633 | Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected); |
| 1634 | // A hotplug connect event is also enqueued for the same display |
| 1635 | Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected); |
| 1636 | |
| 1637 | // -------------------------------------------------------------------- |
| 1638 | // Call Expectations |
| 1639 | |
| 1640 | EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false)); |
| 1641 | |
| 1642 | setupCommonCallExpectationsForConnectProcessing<Case>(); |
| 1643 | setupCommonCallExpectationsForDisconnectProcessing<Case>(); |
| 1644 | |
| 1645 | // -------------------------------------------------------------------- |
| 1646 | // Invocation |
| 1647 | |
| 1648 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
| 1649 | |
| 1650 | // -------------------------------------------------------------------- |
| 1651 | // Postconditions |
| 1652 | |
| 1653 | // The existing token should have been removed |
| 1654 | verifyDisplayIsNotConnected(existing.token()); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1655 | const auto displayId = Case::Display::DISPLAY_ID::get(); |
| 1656 | ASSERT_TRUE(displayId); |
| 1657 | ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 1); |
| 1658 | EXPECT_NE(existing.token(), mFlinger.mutablePhysicalDisplayTokens()[*displayId]); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1659 | |
| 1660 | // A new display should be connected in its place |
| 1661 | |
| 1662 | verifyPhysicalDisplayIsConnected<Case>(); |
| 1663 | |
| 1664 | // -------------------------------------------------------------------- |
| 1665 | // Cleanup conditions |
| 1666 | |
| 1667 | EXPECT_CALL(*mComposer, |
| 1668 | setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE)) |
| 1669 | .WillOnce(Return(Error::NONE)); |
| 1670 | EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR)); |
| 1671 | } |
| 1672 | |
| 1673 | TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAdded) { |
| 1674 | using Case = HwcVirtualDisplayCase; |
| 1675 | |
| 1676 | // -------------------------------------------------------------------- |
| 1677 | // Preconditions |
| 1678 | |
| 1679 | // The HWC supports at least one virtual display |
| 1680 | injectMockComposer(1); |
| 1681 | |
| 1682 | setupCommonPreconditions<Case>(); |
| 1683 | |
| 1684 | // A virtual display was added to the current state, and it has a |
| 1685 | // surface(producer) |
| 1686 | sp<BBinder> displayToken = new BBinder(); |
Lloyd Pique | 4c2ac02 | 2018-04-27 12:08:03 -0700 | [diff] [blame] | 1687 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1688 | DisplayDeviceState state; |
| 1689 | state.isSecure = static_cast<bool>(Case::Display::SECURE); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1690 | |
| 1691 | sp<mock::GraphicBufferProducer> surface{new mock::GraphicBufferProducer()}; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1692 | state.surface = surface; |
| 1693 | mFlinger.mutableCurrentState().displays.add(displayToken, state); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1694 | |
| 1695 | // -------------------------------------------------------------------- |
| 1696 | // Call Expectations |
| 1697 | |
| 1698 | Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this); |
| 1699 | Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this); |
| 1700 | |
| 1701 | EXPECT_CALL(*surface, query(NATIVE_WINDOW_WIDTH, _)) |
| 1702 | .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::WIDTH), Return(NO_ERROR))); |
| 1703 | EXPECT_CALL(*surface, query(NATIVE_WINDOW_HEIGHT, _)) |
| 1704 | .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::HEIGHT), Return(NO_ERROR))); |
| 1705 | EXPECT_CALL(*surface, query(NATIVE_WINDOW_FORMAT, _)) |
| 1706 | .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_VIRTUAL_DISPLAY_SURFACE_FORMAT), |
| 1707 | Return(NO_ERROR))); |
| 1708 | EXPECT_CALL(*surface, query(NATIVE_WINDOW_CONSUMER_USAGE_BITS, _)) |
| 1709 | .WillRepeatedly(DoAll(SetArgPointee<1>(0), Return(NO_ERROR))); |
| 1710 | |
| 1711 | EXPECT_CALL(*surface, setAsyncMode(true)).Times(1); |
| 1712 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1713 | EXPECT_CALL(*mProducer, disconnect(_, _)).Times(1); |
| 1714 | |
| 1715 | Case::Display::setupHwcVirtualDisplayCreationCallExpectations(this); |
| 1716 | Case::WideColorSupport::setupComposerCallExpectations(this); |
| 1717 | Case::HdrSupport::setupComposerCallExpectations(this); |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 1718 | Case::PerFrameMetadataSupport::setupComposerCallExpectations(this); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1719 | |
| 1720 | // -------------------------------------------------------------------- |
| 1721 | // Invocation |
| 1722 | |
| 1723 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
| 1724 | |
| 1725 | // -------------------------------------------------------------------- |
| 1726 | // Postconditions |
| 1727 | |
| 1728 | // The display device should have been set up in the list of displays. |
| 1729 | verifyDisplayIsConnected<Case>(displayToken); |
| 1730 | |
| 1731 | // -------------------------------------------------------------------- |
| 1732 | // Cleanup conditions |
| 1733 | |
| 1734 | EXPECT_CALL(*mComposer, destroyVirtualDisplay(Case::Display::HWC_DISPLAY_ID)) |
| 1735 | .WillOnce(Return(Error::NONE)); |
| 1736 | EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR)); |
| 1737 | } |
| 1738 | |
| 1739 | TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAddedWithNoSurface) { |
| 1740 | using Case = HwcVirtualDisplayCase; |
| 1741 | |
| 1742 | // -------------------------------------------------------------------- |
| 1743 | // Preconditions |
| 1744 | |
| 1745 | // The HWC supports at least one virtual display |
| 1746 | injectMockComposer(1); |
| 1747 | |
| 1748 | setupCommonPreconditions<Case>(); |
| 1749 | |
| 1750 | // A virtual display was added to the current state, but it does not have a |
| 1751 | // surface. |
| 1752 | sp<BBinder> displayToken = new BBinder(); |
| 1753 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1754 | DisplayDeviceState state; |
| 1755 | state.isSecure = static_cast<bool>(Case::Display::SECURE); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1756 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1757 | mFlinger.mutableCurrentState().displays.add(displayToken, state); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1758 | |
| 1759 | // -------------------------------------------------------------------- |
| 1760 | // Call Expectations |
| 1761 | |
| 1762 | // -------------------------------------------------------------------- |
| 1763 | // Invocation |
| 1764 | |
| 1765 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
| 1766 | |
| 1767 | // -------------------------------------------------------------------- |
| 1768 | // Postconditions |
| 1769 | |
| 1770 | // There will not be a display device set up. |
| 1771 | EXPECT_FALSE(hasDisplayDevice(displayToken)); |
| 1772 | |
| 1773 | // The drawing display state will be set from the current display state. |
| 1774 | ASSERT_TRUE(hasDrawingDisplayState(displayToken)); |
| 1775 | const auto& draw = getDrawingDisplayState(displayToken); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1776 | EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), draw.isVirtual()); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1777 | } |
| 1778 | |
| 1779 | TEST_F(HandleTransactionLockedTest, processesVirtualDisplayRemoval) { |
| 1780 | using Case = HwcVirtualDisplayCase; |
| 1781 | |
| 1782 | // -------------------------------------------------------------------- |
| 1783 | // Preconditions |
| 1784 | |
| 1785 | // A virtual display is set up but is removed from the current state. |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1786 | const auto displayId = Case::Display::DISPLAY_ID::get(); |
| 1787 | ASSERT_TRUE(displayId); |
Dominik Laskowski | 1af4793 | 2018-11-12 10:20:46 -0800 | [diff] [blame] | 1788 | mFlinger.mutableHwcDisplayData().try_emplace(*displayId); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1789 | Case::Display::injectHwcDisplay(this); |
| 1790 | auto existing = Case::Display::makeFakeExistingDisplayInjector(this); |
| 1791 | existing.inject(); |
| 1792 | mFlinger.mutableCurrentState().displays.removeItem(existing.token()); |
| 1793 | |
| 1794 | // -------------------------------------------------------------------- |
| 1795 | // Call Expectations |
| 1796 | |
| 1797 | EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false)); |
| 1798 | |
| 1799 | // -------------------------------------------------------------------- |
| 1800 | // Invocation |
| 1801 | |
| 1802 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
| 1803 | |
| 1804 | // -------------------------------------------------------------------- |
| 1805 | // Postconditions |
| 1806 | |
| 1807 | // The existing token should have been removed |
| 1808 | verifyDisplayIsNotConnected(existing.token()); |
| 1809 | } |
| 1810 | |
Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 1811 | TEST_F(HandleTransactionLockedTest, processesDisplayLayerStackChanges) { |
| 1812 | using Case = NonHwcVirtualDisplayCase; |
| 1813 | |
| 1814 | constexpr uint32_t oldLayerStack = 0u; |
| 1815 | constexpr uint32_t newLayerStack = 123u; |
| 1816 | |
| 1817 | // -------------------------------------------------------------------- |
| 1818 | // Preconditions |
| 1819 | |
| 1820 | // A display is set up |
| 1821 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 1822 | display.inject(); |
| 1823 | |
| 1824 | // There is a change to the layerStack state |
| 1825 | display.mutableDrawingDisplayState().layerStack = oldLayerStack; |
| 1826 | display.mutableCurrentDisplayState().layerStack = newLayerStack; |
| 1827 | |
| 1828 | // -------------------------------------------------------------------- |
| 1829 | // Invocation |
| 1830 | |
| 1831 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
| 1832 | |
| 1833 | // -------------------------------------------------------------------- |
| 1834 | // Postconditions |
| 1835 | |
Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 1836 | EXPECT_EQ(newLayerStack, display.mutableDisplayDevice()->getLayerStack()); |
Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 1837 | } |
| 1838 | |
| 1839 | TEST_F(HandleTransactionLockedTest, processesDisplayTransformChanges) { |
| 1840 | using Case = NonHwcVirtualDisplayCase; |
| 1841 | |
| 1842 | constexpr int oldTransform = 0; |
| 1843 | constexpr int newTransform = 2; |
| 1844 | |
| 1845 | // -------------------------------------------------------------------- |
| 1846 | // Preconditions |
| 1847 | |
| 1848 | // A display is set up |
| 1849 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 1850 | display.inject(); |
| 1851 | |
| 1852 | // There is a change to the orientation state |
| 1853 | display.mutableDrawingDisplayState().orientation = oldTransform; |
| 1854 | display.mutableCurrentDisplayState().orientation = newTransform; |
| 1855 | |
| 1856 | // -------------------------------------------------------------------- |
| 1857 | // Invocation |
| 1858 | |
| 1859 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
| 1860 | |
| 1861 | // -------------------------------------------------------------------- |
| 1862 | // Postconditions |
| 1863 | |
Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 1864 | EXPECT_EQ(newTransform, display.mutableDisplayDevice()->getOrientation()); |
Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 1865 | } |
| 1866 | |
| 1867 | TEST_F(HandleTransactionLockedTest, processesDisplayViewportChanges) { |
| 1868 | using Case = NonHwcVirtualDisplayCase; |
| 1869 | |
| 1870 | const Rect oldViewport(0, 0, 0, 0); |
| 1871 | const Rect newViewport(0, 0, 123, 456); |
| 1872 | |
| 1873 | // -------------------------------------------------------------------- |
| 1874 | // Preconditions |
| 1875 | |
| 1876 | // A display is set up |
| 1877 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 1878 | display.inject(); |
| 1879 | |
| 1880 | // There is a change to the viewport state |
| 1881 | display.mutableDrawingDisplayState().viewport = oldViewport; |
| 1882 | display.mutableCurrentDisplayState().viewport = newViewport; |
| 1883 | |
| 1884 | // -------------------------------------------------------------------- |
| 1885 | // Invocation |
| 1886 | |
| 1887 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
| 1888 | |
| 1889 | // -------------------------------------------------------------------- |
| 1890 | // Postconditions |
| 1891 | |
Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 1892 | EXPECT_EQ(newViewport, display.mutableDisplayDevice()->getViewport()); |
Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 1893 | } |
| 1894 | |
| 1895 | TEST_F(HandleTransactionLockedTest, processesDisplayFrameChanges) { |
| 1896 | using Case = NonHwcVirtualDisplayCase; |
| 1897 | |
| 1898 | const Rect oldFrame(0, 0, 0, 0); |
| 1899 | const Rect newFrame(0, 0, 123, 456); |
| 1900 | |
| 1901 | // -------------------------------------------------------------------- |
| 1902 | // Preconditions |
| 1903 | |
| 1904 | // A display is set up |
| 1905 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 1906 | display.inject(); |
| 1907 | |
| 1908 | // There is a change to the viewport state |
| 1909 | display.mutableDrawingDisplayState().frame = oldFrame; |
| 1910 | display.mutableCurrentDisplayState().frame = newFrame; |
| 1911 | |
| 1912 | // -------------------------------------------------------------------- |
| 1913 | // Invocation |
| 1914 | |
| 1915 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
| 1916 | |
| 1917 | // -------------------------------------------------------------------- |
| 1918 | // Postconditions |
| 1919 | |
Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 1920 | EXPECT_EQ(newFrame, display.mutableDisplayDevice()->getFrame()); |
Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 1921 | } |
| 1922 | |
| 1923 | TEST_F(HandleTransactionLockedTest, processesDisplayWidthChanges) { |
| 1924 | using Case = NonHwcVirtualDisplayCase; |
| 1925 | |
| 1926 | constexpr int oldWidth = 0; |
| 1927 | constexpr int oldHeight = 10; |
| 1928 | constexpr int newWidth = 123; |
| 1929 | |
| 1930 | // -------------------------------------------------------------------- |
| 1931 | // Preconditions |
| 1932 | |
| 1933 | // A display is set up |
| 1934 | auto nativeWindow = new mock::NativeWindow(); |
| 1935 | auto displaySurface = new mock::DisplaySurface(); |
Alec Mouri | 0a9c7b8 | 2018-11-16 13:05:25 -0800 | [diff] [blame] | 1936 | sp<GraphicBuffer> buf = new GraphicBuffer(); |
Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 1937 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 1938 | display.setNativeWindow(nativeWindow); |
| 1939 | display.setDisplaySurface(displaySurface); |
Alec Mouri | 0a9c7b8 | 2018-11-16 13:05:25 -0800 | [diff] [blame] | 1940 | // Setup injection expections |
| 1941 | EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_WIDTH, _)) |
| 1942 | .WillOnce(DoAll(SetArgPointee<1>(oldWidth), Return(0))); |
| 1943 | EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_HEIGHT, _)) |
| 1944 | .WillOnce(DoAll(SetArgPointee<1>(oldHeight), Return(0))); |
Alec Mouri | 4efb6c2 | 2018-11-16 13:07:47 -0800 | [diff] [blame] | 1945 | EXPECT_CALL(*nativeWindow, perform(9)).Times(1); |
Alec Mouri | 0a9c7b8 | 2018-11-16 13:05:25 -0800 | [diff] [blame] | 1946 | EXPECT_CALL(*nativeWindow, perform(13)).Times(1); |
Alec Mouri | 4efb6c2 | 2018-11-16 13:07:47 -0800 | [diff] [blame] | 1947 | EXPECT_CALL(*nativeWindow, perform(30)).Times(1); |
Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 1948 | display.inject(); |
| 1949 | |
| 1950 | // There is a change to the viewport state |
| 1951 | display.mutableDrawingDisplayState().width = oldWidth; |
| 1952 | display.mutableDrawingDisplayState().height = oldHeight; |
| 1953 | display.mutableCurrentDisplayState().width = newWidth; |
| 1954 | display.mutableCurrentDisplayState().height = oldHeight; |
| 1955 | |
| 1956 | // -------------------------------------------------------------------- |
| 1957 | // Call Expectations |
| 1958 | |
Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 1959 | EXPECT_CALL(*displaySurface, resizeBuffers(newWidth, oldHeight)).Times(1); |
Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 1960 | |
| 1961 | // -------------------------------------------------------------------- |
| 1962 | // Invocation |
| 1963 | |
| 1964 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
| 1965 | } |
| 1966 | |
| 1967 | TEST_F(HandleTransactionLockedTest, processesDisplayHeightChanges) { |
| 1968 | using Case = NonHwcVirtualDisplayCase; |
| 1969 | |
| 1970 | constexpr int oldWidth = 0; |
| 1971 | constexpr int oldHeight = 10; |
| 1972 | constexpr int newHeight = 123; |
| 1973 | |
| 1974 | // -------------------------------------------------------------------- |
| 1975 | // Preconditions |
| 1976 | |
| 1977 | // A display is set up |
| 1978 | auto nativeWindow = new mock::NativeWindow(); |
| 1979 | auto displaySurface = new mock::DisplaySurface(); |
Alec Mouri | 0a9c7b8 | 2018-11-16 13:05:25 -0800 | [diff] [blame] | 1980 | sp<GraphicBuffer> buf = new GraphicBuffer(); |
Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 1981 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 1982 | display.setNativeWindow(nativeWindow); |
| 1983 | display.setDisplaySurface(displaySurface); |
Alec Mouri | 0a9c7b8 | 2018-11-16 13:05:25 -0800 | [diff] [blame] | 1984 | // Setup injection expections |
| 1985 | EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_WIDTH, _)) |
| 1986 | .WillOnce(DoAll(SetArgPointee<1>(oldWidth), Return(0))); |
| 1987 | EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_HEIGHT, _)) |
| 1988 | .WillOnce(DoAll(SetArgPointee<1>(oldHeight), Return(0))); |
Alec Mouri | 4efb6c2 | 2018-11-16 13:07:47 -0800 | [diff] [blame] | 1989 | EXPECT_CALL(*nativeWindow, perform(9)).Times(1); |
Alec Mouri | 0a9c7b8 | 2018-11-16 13:05:25 -0800 | [diff] [blame] | 1990 | EXPECT_CALL(*nativeWindow, perform(13)).Times(1); |
Alec Mouri | 4efb6c2 | 2018-11-16 13:07:47 -0800 | [diff] [blame] | 1991 | EXPECT_CALL(*nativeWindow, perform(30)).Times(1); |
Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 1992 | display.inject(); |
| 1993 | |
| 1994 | // There is a change to the viewport state |
| 1995 | display.mutableDrawingDisplayState().width = oldWidth; |
| 1996 | display.mutableDrawingDisplayState().height = oldHeight; |
| 1997 | display.mutableCurrentDisplayState().width = oldWidth; |
| 1998 | display.mutableCurrentDisplayState().height = newHeight; |
| 1999 | |
| 2000 | // -------------------------------------------------------------------- |
| 2001 | // Call Expectations |
| 2002 | |
Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 2003 | EXPECT_CALL(*displaySurface, resizeBuffers(oldWidth, newHeight)).Times(1); |
Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 2004 | |
| 2005 | // -------------------------------------------------------------------- |
| 2006 | // Invocation |
| 2007 | |
| 2008 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
| 2009 | } |
| 2010 | |
Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 2011 | /* ------------------------------------------------------------------------ |
| 2012 | * SurfaceFlinger::setDisplayStateLocked |
| 2013 | */ |
| 2014 | |
| 2015 | TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingWithUnknownDisplay) { |
| 2016 | // -------------------------------------------------------------------- |
| 2017 | // Preconditions |
| 2018 | |
| 2019 | // We have an unknown display token not associated with a known display |
| 2020 | sp<BBinder> displayToken = new BBinder(); |
| 2021 | |
| 2022 | // The requested display state references the unknown display. |
| 2023 | DisplayState state; |
| 2024 | state.what = DisplayState::eLayerStackChanged; |
| 2025 | state.token = displayToken; |
| 2026 | state.layerStack = 456; |
| 2027 | |
| 2028 | // -------------------------------------------------------------------- |
| 2029 | // Invocation |
| 2030 | |
| 2031 | uint32_t flags = mFlinger.setDisplayStateLocked(state); |
| 2032 | |
| 2033 | // -------------------------------------------------------------------- |
| 2034 | // Postconditions |
| 2035 | |
| 2036 | // The returned flags are empty |
| 2037 | EXPECT_EQ(0u, flags); |
| 2038 | |
| 2039 | // The display token still doesn't match anything known. |
| 2040 | EXPECT_FALSE(hasCurrentDisplayState(displayToken)); |
| 2041 | } |
| 2042 | |
Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 2043 | TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingWhenNoChanges) { |
| 2044 | using Case = SimplePrimaryDisplayCase; |
| 2045 | |
| 2046 | // -------------------------------------------------------------------- |
| 2047 | // Preconditions |
| 2048 | |
| 2049 | // A display is already set up |
| 2050 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2051 | display.inject(); |
| 2052 | |
| 2053 | // No changes are made to the display |
| 2054 | DisplayState state; |
| 2055 | state.what = 0; |
| 2056 | state.token = display.token(); |
| 2057 | |
| 2058 | // -------------------------------------------------------------------- |
| 2059 | // Invocation |
| 2060 | |
| 2061 | uint32_t flags = mFlinger.setDisplayStateLocked(state); |
| 2062 | |
| 2063 | // -------------------------------------------------------------------- |
| 2064 | // Postconditions |
| 2065 | |
| 2066 | // The returned flags are empty |
| 2067 | EXPECT_EQ(0u, flags); |
| 2068 | } |
| 2069 | |
| 2070 | TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfSurfaceDidNotChange) { |
| 2071 | using Case = SimplePrimaryDisplayCase; |
| 2072 | |
| 2073 | // -------------------------------------------------------------------- |
| 2074 | // Preconditions |
| 2075 | |
| 2076 | // A display is already set up |
| 2077 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2078 | display.inject(); |
| 2079 | |
| 2080 | // There is a surface that can be set. |
| 2081 | sp<mock::GraphicBufferProducer> surface = new mock::GraphicBufferProducer(); |
| 2082 | |
| 2083 | // The current display state has the surface set |
| 2084 | display.mutableCurrentDisplayState().surface = surface; |
| 2085 | |
| 2086 | // The incoming request sets the same surface |
| 2087 | DisplayState state; |
| 2088 | state.what = DisplayState::eSurfaceChanged; |
| 2089 | state.token = display.token(); |
| 2090 | state.surface = surface; |
| 2091 | |
| 2092 | // -------------------------------------------------------------------- |
| 2093 | // Invocation |
| 2094 | |
| 2095 | uint32_t flags = mFlinger.setDisplayStateLocked(state); |
| 2096 | |
| 2097 | // -------------------------------------------------------------------- |
| 2098 | // Postconditions |
| 2099 | |
| 2100 | // The returned flags are empty |
| 2101 | EXPECT_EQ(0u, flags); |
| 2102 | |
| 2103 | // The current display state is unchanged. |
| 2104 | EXPECT_EQ(surface.get(), display.getCurrentDisplayState().surface.get()); |
| 2105 | } |
| 2106 | |
| 2107 | TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfSurfaceChanged) { |
| 2108 | using Case = SimplePrimaryDisplayCase; |
| 2109 | |
| 2110 | // -------------------------------------------------------------------- |
| 2111 | // Preconditions |
| 2112 | |
| 2113 | // A display is already set up |
| 2114 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2115 | display.inject(); |
| 2116 | |
| 2117 | // There is a surface that can be set. |
| 2118 | sp<mock::GraphicBufferProducer> surface = new mock::GraphicBufferProducer(); |
| 2119 | |
| 2120 | // The current display state does not have a surface |
| 2121 | display.mutableCurrentDisplayState().surface = nullptr; |
| 2122 | |
| 2123 | // The incoming request sets a surface |
| 2124 | DisplayState state; |
| 2125 | state.what = DisplayState::eSurfaceChanged; |
| 2126 | state.token = display.token(); |
| 2127 | state.surface = surface; |
| 2128 | |
| 2129 | // -------------------------------------------------------------------- |
| 2130 | // Invocation |
| 2131 | |
| 2132 | uint32_t flags = mFlinger.setDisplayStateLocked(state); |
| 2133 | |
| 2134 | // -------------------------------------------------------------------- |
| 2135 | // Postconditions |
| 2136 | |
| 2137 | // The returned flags indicate a transaction is needed |
| 2138 | EXPECT_EQ(eDisplayTransactionNeeded, flags); |
| 2139 | |
| 2140 | // The current display layer stack state is set to the new value |
| 2141 | EXPECT_EQ(surface.get(), display.getCurrentDisplayState().surface.get()); |
| 2142 | } |
| 2143 | |
| 2144 | TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfLayerStackDidNotChange) { |
| 2145 | using Case = SimplePrimaryDisplayCase; |
| 2146 | |
| 2147 | // -------------------------------------------------------------------- |
| 2148 | // Preconditions |
| 2149 | |
| 2150 | // A display is already set up |
| 2151 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2152 | display.inject(); |
| 2153 | |
| 2154 | // The display has a layer stack set |
| 2155 | display.mutableCurrentDisplayState().layerStack = 456u; |
| 2156 | |
| 2157 | // The incoming request sets the same layer stack |
| 2158 | DisplayState state; |
| 2159 | state.what = DisplayState::eLayerStackChanged; |
| 2160 | state.token = display.token(); |
| 2161 | state.layerStack = 456u; |
| 2162 | |
| 2163 | // -------------------------------------------------------------------- |
| 2164 | // Invocation |
| 2165 | |
| 2166 | uint32_t flags = mFlinger.setDisplayStateLocked(state); |
| 2167 | |
| 2168 | // -------------------------------------------------------------------- |
| 2169 | // Postconditions |
| 2170 | |
| 2171 | // The returned flags are empty |
| 2172 | EXPECT_EQ(0u, flags); |
| 2173 | |
| 2174 | // The current display state is unchanged |
| 2175 | EXPECT_EQ(456u, display.getCurrentDisplayState().layerStack); |
| 2176 | } |
| 2177 | |
| 2178 | TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfLayerStackChanged) { |
| 2179 | using Case = SimplePrimaryDisplayCase; |
| 2180 | |
| 2181 | // -------------------------------------------------------------------- |
| 2182 | // Preconditions |
| 2183 | |
| 2184 | // A display is set up |
| 2185 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2186 | display.inject(); |
| 2187 | |
| 2188 | // The display has a layer stack set |
| 2189 | display.mutableCurrentDisplayState().layerStack = 654u; |
| 2190 | |
| 2191 | // The incoming request sets a different layer stack |
| 2192 | DisplayState state; |
| 2193 | state.what = DisplayState::eLayerStackChanged; |
| 2194 | state.token = display.token(); |
| 2195 | state.layerStack = 456u; |
| 2196 | |
| 2197 | // -------------------------------------------------------------------- |
| 2198 | // Invocation |
| 2199 | |
| 2200 | uint32_t flags = mFlinger.setDisplayStateLocked(state); |
| 2201 | |
| 2202 | // -------------------------------------------------------------------- |
| 2203 | // Postconditions |
| 2204 | |
| 2205 | // The returned flags indicate a transaction is needed |
| 2206 | EXPECT_EQ(eDisplayTransactionNeeded, flags); |
| 2207 | |
| 2208 | // The desired display state has been set to the new value. |
| 2209 | EXPECT_EQ(456u, display.getCurrentDisplayState().layerStack); |
| 2210 | } |
| 2211 | |
| 2212 | TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfProjectionDidNotChange) { |
| 2213 | using Case = SimplePrimaryDisplayCase; |
| 2214 | constexpr int initialOrientation = 180; |
| 2215 | const Rect initialFrame = {1, 2, 3, 4}; |
| 2216 | const Rect initialViewport = {5, 6, 7, 8}; |
| 2217 | |
| 2218 | // -------------------------------------------------------------------- |
| 2219 | // Preconditions |
| 2220 | |
| 2221 | // A display is set up |
| 2222 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2223 | display.inject(); |
| 2224 | |
| 2225 | // The current display state projection state is all set |
| 2226 | display.mutableCurrentDisplayState().orientation = initialOrientation; |
| 2227 | display.mutableCurrentDisplayState().frame = initialFrame; |
| 2228 | display.mutableCurrentDisplayState().viewport = initialViewport; |
| 2229 | |
| 2230 | // The incoming request sets the same projection state |
| 2231 | DisplayState state; |
| 2232 | state.what = DisplayState::eDisplayProjectionChanged; |
| 2233 | state.token = display.token(); |
| 2234 | state.orientation = initialOrientation; |
| 2235 | state.frame = initialFrame; |
| 2236 | state.viewport = initialViewport; |
| 2237 | |
| 2238 | // -------------------------------------------------------------------- |
| 2239 | // Invocation |
| 2240 | |
| 2241 | uint32_t flags = mFlinger.setDisplayStateLocked(state); |
| 2242 | |
| 2243 | // -------------------------------------------------------------------- |
| 2244 | // Postconditions |
| 2245 | |
| 2246 | // The returned flags are empty |
| 2247 | EXPECT_EQ(0u, flags); |
| 2248 | |
| 2249 | // The current display state is unchanged |
| 2250 | EXPECT_EQ(initialOrientation, display.getCurrentDisplayState().orientation); |
| 2251 | |
| 2252 | EXPECT_EQ(initialFrame, display.getCurrentDisplayState().frame); |
| 2253 | EXPECT_EQ(initialViewport, display.getCurrentDisplayState().viewport); |
| 2254 | } |
| 2255 | |
| 2256 | TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfOrientationChanged) { |
| 2257 | using Case = SimplePrimaryDisplayCase; |
| 2258 | constexpr int initialOrientation = 90; |
| 2259 | constexpr int desiredOrientation = 180; |
| 2260 | |
| 2261 | // -------------------------------------------------------------------- |
| 2262 | // Preconditions |
| 2263 | |
| 2264 | // A display is set up |
| 2265 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2266 | display.inject(); |
| 2267 | |
| 2268 | // The current display state has an orientation set |
| 2269 | display.mutableCurrentDisplayState().orientation = initialOrientation; |
| 2270 | |
| 2271 | // The incoming request sets a different orientation |
| 2272 | DisplayState state; |
| 2273 | state.what = DisplayState::eDisplayProjectionChanged; |
| 2274 | state.token = display.token(); |
| 2275 | state.orientation = desiredOrientation; |
| 2276 | |
| 2277 | // -------------------------------------------------------------------- |
| 2278 | // Invocation |
| 2279 | |
| 2280 | uint32_t flags = mFlinger.setDisplayStateLocked(state); |
| 2281 | |
| 2282 | // -------------------------------------------------------------------- |
| 2283 | // Postconditions |
| 2284 | |
| 2285 | // The returned flags indicate a transaction is needed |
| 2286 | EXPECT_EQ(eDisplayTransactionNeeded, flags); |
| 2287 | |
| 2288 | // The current display state has the new value. |
| 2289 | EXPECT_EQ(desiredOrientation, display.getCurrentDisplayState().orientation); |
| 2290 | } |
| 2291 | |
| 2292 | TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfFrameChanged) { |
| 2293 | using Case = SimplePrimaryDisplayCase; |
| 2294 | const Rect initialFrame = {0, 0, 0, 0}; |
| 2295 | const Rect desiredFrame = {5, 6, 7, 8}; |
| 2296 | |
| 2297 | // -------------------------------------------------------------------- |
| 2298 | // Preconditions |
| 2299 | |
| 2300 | // A display is set up |
| 2301 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2302 | display.inject(); |
| 2303 | |
| 2304 | // The current display state does not have a frame |
| 2305 | display.mutableCurrentDisplayState().frame = initialFrame; |
| 2306 | |
| 2307 | // The incoming request sets a frame |
| 2308 | DisplayState state; |
| 2309 | state.what = DisplayState::eDisplayProjectionChanged; |
| 2310 | state.token = display.token(); |
| 2311 | state.frame = desiredFrame; |
| 2312 | |
| 2313 | // -------------------------------------------------------------------- |
| 2314 | // Invocation |
| 2315 | |
| 2316 | uint32_t flags = mFlinger.setDisplayStateLocked(state); |
| 2317 | |
| 2318 | // -------------------------------------------------------------------- |
| 2319 | // Postconditions |
| 2320 | |
| 2321 | // The returned flags indicate a transaction is needed |
| 2322 | EXPECT_EQ(eDisplayTransactionNeeded, flags); |
| 2323 | |
| 2324 | // The current display state has the new value. |
| 2325 | EXPECT_EQ(desiredFrame, display.getCurrentDisplayState().frame); |
| 2326 | } |
| 2327 | |
| 2328 | TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfViewportChanged) { |
| 2329 | using Case = SimplePrimaryDisplayCase; |
| 2330 | const Rect initialViewport = {0, 0, 0, 0}; |
| 2331 | const Rect desiredViewport = {5, 6, 7, 8}; |
| 2332 | |
| 2333 | // -------------------------------------------------------------------- |
| 2334 | // Preconditions |
| 2335 | |
| 2336 | // A display is set up |
| 2337 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2338 | display.inject(); |
| 2339 | |
| 2340 | // The current display state does not have a viewport |
| 2341 | display.mutableCurrentDisplayState().viewport = initialViewport; |
| 2342 | |
| 2343 | // The incoming request sets a viewport |
| 2344 | DisplayState state; |
| 2345 | state.what = DisplayState::eDisplayProjectionChanged; |
| 2346 | state.token = display.token(); |
| 2347 | state.viewport = desiredViewport; |
| 2348 | |
| 2349 | // -------------------------------------------------------------------- |
| 2350 | // Invocation |
| 2351 | |
| 2352 | uint32_t flags = mFlinger.setDisplayStateLocked(state); |
| 2353 | |
| 2354 | // -------------------------------------------------------------------- |
| 2355 | // Postconditions |
| 2356 | |
| 2357 | // The returned flags indicate a transaction is needed |
| 2358 | EXPECT_EQ(eDisplayTransactionNeeded, flags); |
| 2359 | |
| 2360 | // The current display state has the new value. |
| 2361 | EXPECT_EQ(desiredViewport, display.getCurrentDisplayState().viewport); |
| 2362 | } |
| 2363 | |
| 2364 | TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfSizeDidNotChange) { |
| 2365 | using Case = SimplePrimaryDisplayCase; |
| 2366 | constexpr uint32_t initialWidth = 1024; |
| 2367 | constexpr uint32_t initialHeight = 768; |
| 2368 | |
| 2369 | // -------------------------------------------------------------------- |
| 2370 | // Preconditions |
| 2371 | |
| 2372 | // A display is set up |
| 2373 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2374 | display.inject(); |
| 2375 | |
| 2376 | // The current display state has a size set |
| 2377 | display.mutableCurrentDisplayState().width = initialWidth; |
| 2378 | display.mutableCurrentDisplayState().height = initialHeight; |
| 2379 | |
| 2380 | // The incoming request sets the same display size |
| 2381 | DisplayState state; |
| 2382 | state.what = DisplayState::eDisplaySizeChanged; |
| 2383 | state.token = display.token(); |
| 2384 | state.width = initialWidth; |
| 2385 | state.height = initialHeight; |
| 2386 | |
| 2387 | // -------------------------------------------------------------------- |
| 2388 | // Invocation |
| 2389 | |
| 2390 | uint32_t flags = mFlinger.setDisplayStateLocked(state); |
| 2391 | |
| 2392 | // -------------------------------------------------------------------- |
| 2393 | // Postconditions |
| 2394 | |
| 2395 | // The returned flags are empty |
| 2396 | EXPECT_EQ(0u, flags); |
| 2397 | |
| 2398 | // The current display state is unchanged |
| 2399 | EXPECT_EQ(initialWidth, display.getCurrentDisplayState().width); |
| 2400 | EXPECT_EQ(initialHeight, display.getCurrentDisplayState().height); |
| 2401 | } |
| 2402 | |
| 2403 | TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfWidthChanged) { |
| 2404 | using Case = SimplePrimaryDisplayCase; |
| 2405 | constexpr uint32_t initialWidth = 0; |
| 2406 | constexpr uint32_t desiredWidth = 1024; |
| 2407 | |
| 2408 | // -------------------------------------------------------------------- |
| 2409 | // Preconditions |
| 2410 | |
| 2411 | // A display is set up |
| 2412 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2413 | display.inject(); |
| 2414 | |
| 2415 | // The display does not yet have a width |
| 2416 | display.mutableCurrentDisplayState().width = initialWidth; |
| 2417 | |
| 2418 | // The incoming request sets a display width |
| 2419 | DisplayState state; |
| 2420 | state.what = DisplayState::eDisplaySizeChanged; |
| 2421 | state.token = display.token(); |
| 2422 | state.width = desiredWidth; |
| 2423 | |
| 2424 | // -------------------------------------------------------------------- |
| 2425 | // Invocation |
| 2426 | |
| 2427 | uint32_t flags = mFlinger.setDisplayStateLocked(state); |
| 2428 | |
| 2429 | // -------------------------------------------------------------------- |
| 2430 | // Postconditions |
| 2431 | |
| 2432 | // The returned flags indicate a transaction is needed |
| 2433 | EXPECT_EQ(eDisplayTransactionNeeded, flags); |
| 2434 | |
| 2435 | // The current display state has the new value. |
| 2436 | EXPECT_EQ(desiredWidth, display.getCurrentDisplayState().width); |
| 2437 | } |
| 2438 | |
| 2439 | TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfHeightChanged) { |
| 2440 | using Case = SimplePrimaryDisplayCase; |
| 2441 | constexpr uint32_t initialHeight = 0; |
| 2442 | constexpr uint32_t desiredHeight = 768; |
| 2443 | |
| 2444 | // -------------------------------------------------------------------- |
| 2445 | // Preconditions |
| 2446 | |
| 2447 | // A display is set up |
| 2448 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2449 | display.inject(); |
| 2450 | |
| 2451 | // The display does not yet have a height |
| 2452 | display.mutableCurrentDisplayState().height = initialHeight; |
| 2453 | |
| 2454 | // The incoming request sets a display height |
| 2455 | DisplayState state; |
| 2456 | state.what = DisplayState::eDisplaySizeChanged; |
| 2457 | state.token = display.token(); |
| 2458 | state.height = desiredHeight; |
| 2459 | |
| 2460 | // -------------------------------------------------------------------- |
| 2461 | // Invocation |
| 2462 | |
| 2463 | uint32_t flags = mFlinger.setDisplayStateLocked(state); |
| 2464 | |
| 2465 | // -------------------------------------------------------------------- |
| 2466 | // Postconditions |
| 2467 | |
| 2468 | // The returned flags indicate a transaction is needed |
| 2469 | EXPECT_EQ(eDisplayTransactionNeeded, flags); |
| 2470 | |
| 2471 | // The current display state has the new value. |
| 2472 | EXPECT_EQ(desiredHeight, display.getCurrentDisplayState().height); |
| 2473 | } |
| 2474 | |
Lloyd Pique | 86016da | 2018-03-01 16:09:38 -0800 | [diff] [blame] | 2475 | /* ------------------------------------------------------------------------ |
| 2476 | * SurfaceFlinger::onInitializeDisplays |
| 2477 | */ |
| 2478 | |
| 2479 | TEST_F(DisplayTransactionTest, onInitializeDisplaysSetsUpPrimaryDisplay) { |
| 2480 | using Case = SimplePrimaryDisplayCase; |
| 2481 | |
| 2482 | // -------------------------------------------------------------------- |
| 2483 | // Preconditions |
| 2484 | |
| 2485 | // A primary display is set up |
| 2486 | Case::Display::injectHwcDisplay(this); |
| 2487 | auto primaryDisplay = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2488 | primaryDisplay.inject(); |
| 2489 | |
| 2490 | // -------------------------------------------------------------------- |
| 2491 | // Call Expectations |
| 2492 | |
| 2493 | // We expect the surface interceptor to possibly be used, but we treat it as |
| 2494 | // disabled since it is called as a side effect rather than directly by this |
| 2495 | // function. |
| 2496 | EXPECT_CALL(*mSurfaceInterceptor, isEnabled()).WillOnce(Return(false)); |
| 2497 | |
| 2498 | // We expect a call to get the active display config. |
| 2499 | Case::Display::setupHwcGetActiveConfigCallExpectations(this); |
| 2500 | |
| 2501 | // We expect invalidate() to be invoked once to trigger display transaction |
| 2502 | // processing. |
| 2503 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); |
| 2504 | |
| 2505 | // -------------------------------------------------------------------- |
| 2506 | // Invocation |
| 2507 | |
| 2508 | mFlinger.onInitializeDisplays(); |
| 2509 | |
| 2510 | // -------------------------------------------------------------------- |
| 2511 | // Postconditions |
| 2512 | |
| 2513 | // The primary display should have a current state |
| 2514 | ASSERT_TRUE(hasCurrentDisplayState(primaryDisplay.token())); |
| 2515 | const auto& primaryDisplayState = getCurrentDisplayState(primaryDisplay.token()); |
| 2516 | // The layer stack state should be set to zero |
| 2517 | EXPECT_EQ(0u, primaryDisplayState.layerStack); |
| 2518 | // The orientation state should be set to zero |
| 2519 | EXPECT_EQ(0, primaryDisplayState.orientation); |
| 2520 | |
| 2521 | // The frame state should be set to INVALID |
| 2522 | EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.frame); |
| 2523 | |
| 2524 | // The viewport state should be set to INVALID |
| 2525 | EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.viewport); |
| 2526 | |
| 2527 | // The width and height should both be zero |
| 2528 | EXPECT_EQ(0u, primaryDisplayState.width); |
| 2529 | EXPECT_EQ(0u, primaryDisplayState.height); |
| 2530 | |
| 2531 | // The display should be set to HWC_POWER_MODE_NORMAL |
| 2532 | ASSERT_TRUE(hasDisplayDevice(primaryDisplay.token())); |
| 2533 | auto displayDevice = primaryDisplay.mutableDisplayDevice(); |
| 2534 | EXPECT_EQ(HWC_POWER_MODE_NORMAL, displayDevice->getPowerMode()); |
| 2535 | |
| 2536 | // The display refresh period should be set in the frame tracker. |
| 2537 | FrameStats stats; |
| 2538 | mFlinger.getAnimFrameTracker().getStats(&stats); |
| 2539 | EXPECT_EQ(DEFAULT_REFRESH_RATE, stats.refreshPeriodNano); |
| 2540 | |
| 2541 | // The display transaction needed flag should be set. |
| 2542 | EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded)); |
| 2543 | |
| 2544 | // The compositor timing should be set to default values |
| 2545 | const auto& compositorTiming = mFlinger.getCompositorTiming(); |
| 2546 | EXPECT_EQ(-DEFAULT_REFRESH_RATE, compositorTiming.deadline); |
| 2547 | EXPECT_EQ(DEFAULT_REFRESH_RATE, compositorTiming.interval); |
| 2548 | EXPECT_EQ(DEFAULT_REFRESH_RATE, compositorTiming.presentLatency); |
| 2549 | } |
| 2550 | |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 2551 | /* ------------------------------------------------------------------------ |
| 2552 | * SurfaceFlinger::setPowerModeInternal |
| 2553 | */ |
| 2554 | |
| 2555 | // Used when we simulate a display that supports doze. |
Peiyong Lin | ed531a3 | 2018-10-26 18:27:56 -0700 | [diff] [blame] | 2556 | template <typename Display> |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 2557 | struct DozeIsSupportedVariant { |
| 2558 | static constexpr bool DOZE_SUPPORTED = true; |
| 2559 | static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE = |
| 2560 | IComposerClient::PowerMode::DOZE; |
| 2561 | static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND = |
| 2562 | IComposerClient::PowerMode::DOZE_SUSPEND; |
Peiyong Lin | ed531a3 | 2018-10-26 18:27:56 -0700 | [diff] [blame] | 2563 | |
| 2564 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
| 2565 | EXPECT_CALL(*test->mComposer, getDisplayCapabilities(Display::HWC_DISPLAY_ID, _)) |
| 2566 | .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>( |
| 2567 | {Hwc2::DisplayCapability::DOZE})), |
| 2568 | Return(Error::NONE))); |
| 2569 | } |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 2570 | }; |
| 2571 | |
Peiyong Lin | ed531a3 | 2018-10-26 18:27:56 -0700 | [diff] [blame] | 2572 | template <typename Display> |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 2573 | // Used when we simulate a display that does not support doze. |
| 2574 | struct DozeNotSupportedVariant { |
| 2575 | static constexpr bool DOZE_SUPPORTED = false; |
| 2576 | static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE = |
| 2577 | IComposerClient::PowerMode::ON; |
| 2578 | static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND = |
| 2579 | IComposerClient::PowerMode::ON; |
Peiyong Lin | ed531a3 | 2018-10-26 18:27:56 -0700 | [diff] [blame] | 2580 | |
| 2581 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
| 2582 | EXPECT_CALL(*test->mComposer, getDisplayCapabilities(Display::HWC_DISPLAY_ID, _)) |
| 2583 | .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>({})), |
| 2584 | Return(Error::NONE))); |
| 2585 | } |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 2586 | }; |
| 2587 | |
| 2588 | struct EventThreadBaseSupportedVariant { |
| 2589 | static void setupEventAndEventControlThreadNoCallExpectations(DisplayTransactionTest* test) { |
| 2590 | // The event control thread should not be notified. |
| 2591 | EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(_)).Times(0); |
| 2592 | |
| 2593 | // The event thread should not be notified. |
| 2594 | EXPECT_CALL(*test->mEventThread, onScreenReleased()).Times(0); |
| 2595 | EXPECT_CALL(*test->mEventThread, onScreenAcquired()).Times(0); |
| 2596 | } |
| 2597 | }; |
| 2598 | |
| 2599 | struct EventThreadNotSupportedVariant : public EventThreadBaseSupportedVariant { |
| 2600 | static void setupAcquireAndEnableVsyncCallExpectations(DisplayTransactionTest* test) { |
| 2601 | // These calls are only expected for the primary display. |
| 2602 | |
| 2603 | // Instead expect no calls. |
| 2604 | setupEventAndEventControlThreadNoCallExpectations(test); |
| 2605 | } |
| 2606 | |
| 2607 | static void setupReleaseAndDisableVsyncCallExpectations(DisplayTransactionTest* test) { |
| 2608 | // These calls are only expected for the primary display. |
| 2609 | |
| 2610 | // Instead expect no calls. |
| 2611 | setupEventAndEventControlThreadNoCallExpectations(test); |
| 2612 | } |
| 2613 | }; |
| 2614 | |
| 2615 | struct EventThreadIsSupportedVariant : public EventThreadBaseSupportedVariant { |
| 2616 | static void setupAcquireAndEnableVsyncCallExpectations(DisplayTransactionTest* test) { |
| 2617 | // The event control thread should be notified to enable vsyncs |
| 2618 | EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(true)).Times(1); |
| 2619 | |
| 2620 | // The event thread should be notified that the screen was acquired. |
| 2621 | EXPECT_CALL(*test->mEventThread, onScreenAcquired()).Times(1); |
| 2622 | } |
| 2623 | |
| 2624 | static void setupReleaseAndDisableVsyncCallExpectations(DisplayTransactionTest* test) { |
| 2625 | // There should be a call to setVsyncEnabled(false) |
| 2626 | EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(false)).Times(1); |
| 2627 | |
| 2628 | // The event thread should not be notified that the screen was released. |
| 2629 | EXPECT_CALL(*test->mEventThread, onScreenReleased()).Times(1); |
| 2630 | } |
| 2631 | }; |
| 2632 | |
Lloyd Pique | 41be5d2 | 2018-06-21 13:11:48 -0700 | [diff] [blame] | 2633 | struct DispSyncIsSupportedVariant { |
| 2634 | static void setupBeginResyncCallExpectations(DisplayTransactionTest* test) { |
| 2635 | EXPECT_CALL(*test->mPrimaryDispSync, reset()).Times(1); |
| 2636 | EXPECT_CALL(*test->mPrimaryDispSync, setPeriod(DEFAULT_REFRESH_RATE)).Times(1); |
| 2637 | EXPECT_CALL(*test->mPrimaryDispSync, beginResync()).Times(1); |
| 2638 | } |
| 2639 | |
| 2640 | static void setupEndResyncCallExpectations(DisplayTransactionTest* test) { |
| 2641 | EXPECT_CALL(*test->mPrimaryDispSync, endResync()).Times(1); |
| 2642 | } |
| 2643 | }; |
| 2644 | |
| 2645 | struct DispSyncNotSupportedVariant { |
| 2646 | static void setupBeginResyncCallExpectations(DisplayTransactionTest* /* test */) {} |
| 2647 | |
| 2648 | static void setupEndResyncCallExpectations(DisplayTransactionTest* /* test */) {} |
| 2649 | }; |
| 2650 | |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 2651 | // -------------------------------------------------------------------- |
| 2652 | // Note: |
| 2653 | // |
| 2654 | // There are a large number of transitions we could test, however we only test a |
| 2655 | // selected subset which provides complete test coverage of the implementation. |
| 2656 | // -------------------------------------------------------------------- |
| 2657 | |
| 2658 | template <int initialPowerMode, int targetPowerMode> |
| 2659 | struct TransitionVariantCommon { |
| 2660 | static constexpr auto INITIAL_POWER_MODE = initialPowerMode; |
| 2661 | static constexpr auto TARGET_POWER_MODE = targetPowerMode; |
| 2662 | |
| 2663 | static void verifyPostconditions(DisplayTransactionTest*) {} |
| 2664 | }; |
| 2665 | |
| 2666 | struct TransitionOffToOnVariant |
| 2667 | : public TransitionVariantCommon<HWC_POWER_MODE_OFF, HWC_POWER_MODE_NORMAL> { |
| 2668 | template <typename Case> |
| 2669 | static void setupCallExpectations(DisplayTransactionTest* test) { |
| 2670 | Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON); |
| 2671 | Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test); |
Lloyd Pique | 41be5d2 | 2018-06-21 13:11:48 -0700 | [diff] [blame] | 2672 | Case::DispSync::setupBeginResyncCallExpectations(test); |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 2673 | Case::setupRepaintEverythingCallExpectations(test); |
| 2674 | } |
| 2675 | |
| 2676 | static void verifyPostconditions(DisplayTransactionTest* test) { |
| 2677 | EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty()); |
| 2678 | EXPECT_TRUE(test->mFlinger.getHasPoweredOff()); |
| 2679 | } |
| 2680 | }; |
| 2681 | |
| 2682 | struct TransitionOffToDozeSuspendVariant |
| 2683 | : public TransitionVariantCommon<HWC_POWER_MODE_OFF, HWC_POWER_MODE_DOZE_SUSPEND> { |
| 2684 | template <typename Case> |
| 2685 | static void setupCallExpectations(DisplayTransactionTest* test) { |
| 2686 | Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND); |
| 2687 | Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test); |
| 2688 | Case::setupRepaintEverythingCallExpectations(test); |
| 2689 | } |
| 2690 | |
| 2691 | static void verifyPostconditions(DisplayTransactionTest* test) { |
| 2692 | EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty()); |
| 2693 | EXPECT_TRUE(test->mFlinger.getHasPoweredOff()); |
| 2694 | } |
| 2695 | }; |
| 2696 | |
| 2697 | struct TransitionOnToOffVariant |
| 2698 | : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_OFF> { |
| 2699 | template <typename Case> |
| 2700 | static void setupCallExpectations(DisplayTransactionTest* test) { |
| 2701 | Case::EventThread::setupReleaseAndDisableVsyncCallExpectations(test); |
Lloyd Pique | 41be5d2 | 2018-06-21 13:11:48 -0700 | [diff] [blame] | 2702 | Case::DispSync::setupEndResyncCallExpectations(test); |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 2703 | Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::OFF); |
| 2704 | } |
| 2705 | |
| 2706 | static void verifyPostconditions(DisplayTransactionTest* test) { |
| 2707 | EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty()); |
| 2708 | } |
| 2709 | }; |
| 2710 | |
| 2711 | struct TransitionDozeSuspendToOffVariant |
| 2712 | : public TransitionVariantCommon<HWC_POWER_MODE_DOZE_SUSPEND, HWC_POWER_MODE_OFF> { |
| 2713 | template <typename Case> |
| 2714 | static void setupCallExpectations(DisplayTransactionTest* test) { |
| 2715 | Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test); |
| 2716 | Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::OFF); |
| 2717 | } |
| 2718 | |
| 2719 | static void verifyPostconditions(DisplayTransactionTest* test) { |
| 2720 | EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty()); |
| 2721 | } |
| 2722 | }; |
| 2723 | |
| 2724 | struct TransitionOnToDozeVariant |
| 2725 | : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_DOZE> { |
| 2726 | template <typename Case> |
| 2727 | static void setupCallExpectations(DisplayTransactionTest* test) { |
| 2728 | Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test); |
| 2729 | Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE); |
| 2730 | } |
| 2731 | }; |
| 2732 | |
| 2733 | struct TransitionDozeSuspendToDozeVariant |
| 2734 | : public TransitionVariantCommon<HWC_POWER_MODE_DOZE_SUSPEND, HWC_POWER_MODE_DOZE> { |
| 2735 | template <typename Case> |
| 2736 | static void setupCallExpectations(DisplayTransactionTest* test) { |
| 2737 | Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test); |
Lloyd Pique | 41be5d2 | 2018-06-21 13:11:48 -0700 | [diff] [blame] | 2738 | Case::DispSync::setupBeginResyncCallExpectations(test); |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 2739 | Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE); |
| 2740 | } |
| 2741 | }; |
| 2742 | |
| 2743 | struct TransitionDozeToOnVariant |
| 2744 | : public TransitionVariantCommon<HWC_POWER_MODE_DOZE, HWC_POWER_MODE_NORMAL> { |
| 2745 | template <typename Case> |
| 2746 | static void setupCallExpectations(DisplayTransactionTest* test) { |
| 2747 | Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test); |
| 2748 | Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON); |
| 2749 | } |
| 2750 | }; |
| 2751 | |
| 2752 | struct TransitionDozeSuspendToOnVariant |
| 2753 | : public TransitionVariantCommon<HWC_POWER_MODE_DOZE_SUSPEND, HWC_POWER_MODE_NORMAL> { |
| 2754 | template <typename Case> |
| 2755 | static void setupCallExpectations(DisplayTransactionTest* test) { |
| 2756 | Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test); |
Lloyd Pique | 41be5d2 | 2018-06-21 13:11:48 -0700 | [diff] [blame] | 2757 | Case::DispSync::setupBeginResyncCallExpectations(test); |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 2758 | Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON); |
| 2759 | } |
| 2760 | }; |
| 2761 | |
| 2762 | struct TransitionOnToDozeSuspendVariant |
| 2763 | : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_DOZE_SUSPEND> { |
| 2764 | template <typename Case> |
| 2765 | static void setupCallExpectations(DisplayTransactionTest* test) { |
| 2766 | Case::EventThread::setupReleaseAndDisableVsyncCallExpectations(test); |
Lloyd Pique | 41be5d2 | 2018-06-21 13:11:48 -0700 | [diff] [blame] | 2767 | Case::DispSync::setupEndResyncCallExpectations(test); |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 2768 | Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND); |
| 2769 | } |
| 2770 | }; |
| 2771 | |
| 2772 | struct TransitionOnToUnknownVariant |
| 2773 | : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_LEET> { |
| 2774 | template <typename Case> |
| 2775 | static void setupCallExpectations(DisplayTransactionTest* test) { |
| 2776 | Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test); |
| 2777 | Case::setupNoComposerPowerModeCallExpectations(test); |
| 2778 | } |
| 2779 | }; |
| 2780 | |
| 2781 | // -------------------------------------------------------------------- |
| 2782 | // Note: |
| 2783 | // |
| 2784 | // Rather than testing the cartesian product of of |
| 2785 | // DozeIsSupported/DozeNotSupported with all other options, we use one for one |
| 2786 | // display type, and the other for another display type. |
| 2787 | // -------------------------------------------------------------------- |
| 2788 | |
| 2789 | template <typename DisplayVariant, typename DozeVariant, typename EventThreadVariant, |
Lloyd Pique | 41be5d2 | 2018-06-21 13:11:48 -0700 | [diff] [blame] | 2790 | typename DispSyncVariant, typename TransitionVariant> |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 2791 | struct DisplayPowerCase { |
| 2792 | using Display = DisplayVariant; |
| 2793 | using Doze = DozeVariant; |
| 2794 | using EventThread = EventThreadVariant; |
Lloyd Pique | 41be5d2 | 2018-06-21 13:11:48 -0700 | [diff] [blame] | 2795 | using DispSync = DispSyncVariant; |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 2796 | using Transition = TransitionVariant; |
| 2797 | |
| 2798 | static auto injectDisplayWithInitialPowerMode(DisplayTransactionTest* test, int mode) { |
| 2799 | Display::injectHwcDisplay(test); |
| 2800 | auto display = Display::makeFakeExistingDisplayInjector(test); |
| 2801 | display.inject(); |
| 2802 | display.mutableDisplayDevice()->setPowerMode(mode); |
| 2803 | return display; |
| 2804 | } |
| 2805 | |
| 2806 | static void setInitialPrimaryHWVsyncEnabled(DisplayTransactionTest* test, bool enabled) { |
| 2807 | test->mFlinger.mutablePrimaryHWVsyncEnabled() = enabled; |
| 2808 | } |
| 2809 | |
| 2810 | static void setupRepaintEverythingCallExpectations(DisplayTransactionTest* test) { |
| 2811 | EXPECT_CALL(*test->mMessageQueue, invalidate()).Times(1); |
| 2812 | } |
| 2813 | |
| 2814 | static void setupSurfaceInterceptorCallExpectations(DisplayTransactionTest* test, int mode) { |
| 2815 | EXPECT_CALL(*test->mSurfaceInterceptor, isEnabled()).WillOnce(Return(true)); |
| 2816 | EXPECT_CALL(*test->mSurfaceInterceptor, savePowerModeUpdate(_, mode)).Times(1); |
| 2817 | } |
| 2818 | |
| 2819 | static void setupComposerCallExpectations(DisplayTransactionTest* test, |
| 2820 | IComposerClient::PowerMode mode) { |
| 2821 | // Any calls to get the active config will return a default value. |
| 2822 | EXPECT_CALL(*test->mComposer, getActiveConfig(Display::HWC_DISPLAY_ID, _)) |
| 2823 | .WillRepeatedly(DoAll(SetArgPointee<1>(Display::HWC_ACTIVE_CONFIG_ID), |
| 2824 | Return(Error::NONE))); |
| 2825 | |
| 2826 | // Any calls to get whether the display supports dozing will return the value set by the |
| 2827 | // policy variant. |
| 2828 | EXPECT_CALL(*test->mComposer, getDozeSupport(Display::HWC_DISPLAY_ID, _)) |
| 2829 | .WillRepeatedly(DoAll(SetArgPointee<1>(Doze::DOZE_SUPPORTED), Return(Error::NONE))); |
| 2830 | |
| 2831 | EXPECT_CALL(*test->mComposer, setPowerMode(Display::HWC_DISPLAY_ID, mode)).Times(1); |
| 2832 | } |
| 2833 | |
| 2834 | static void setupNoComposerPowerModeCallExpectations(DisplayTransactionTest* test) { |
| 2835 | EXPECT_CALL(*test->mComposer, setPowerMode(Display::HWC_DISPLAY_ID, _)).Times(0); |
| 2836 | } |
| 2837 | }; |
| 2838 | |
| 2839 | // A sample configuration for the primary display. |
| 2840 | // In addition to having event thread support, we emulate doze support. |
| 2841 | template <typename TransitionVariant> |
Peiyong Lin | ed531a3 | 2018-10-26 18:27:56 -0700 | [diff] [blame] | 2842 | using PrimaryDisplayPowerCase = |
| 2843 | DisplayPowerCase<PrimaryDisplayVariant, DozeIsSupportedVariant<PrimaryDisplayVariant>, |
| 2844 | EventThreadIsSupportedVariant, DispSyncIsSupportedVariant, |
| 2845 | TransitionVariant>; |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 2846 | |
| 2847 | // A sample configuration for the external display. |
| 2848 | // In addition to not having event thread support, we emulate not having doze |
| 2849 | // support. |
| 2850 | template <typename TransitionVariant> |
Peiyong Lin | ed531a3 | 2018-10-26 18:27:56 -0700 | [diff] [blame] | 2851 | using ExternalDisplayPowerCase = |
| 2852 | DisplayPowerCase<ExternalDisplayVariant, DozeNotSupportedVariant<ExternalDisplayVariant>, |
| 2853 | EventThreadNotSupportedVariant, DispSyncNotSupportedVariant, |
| 2854 | TransitionVariant>; |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 2855 | |
| 2856 | class SetPowerModeInternalTest : public DisplayTransactionTest { |
| 2857 | public: |
| 2858 | template <typename Case> |
| 2859 | void transitionDisplayCommon(); |
| 2860 | }; |
| 2861 | |
| 2862 | template <int PowerMode> |
| 2863 | struct PowerModeInitialVSyncEnabled : public std::false_type {}; |
| 2864 | |
| 2865 | template <> |
| 2866 | struct PowerModeInitialVSyncEnabled<HWC_POWER_MODE_NORMAL> : public std::true_type {}; |
| 2867 | |
| 2868 | template <> |
| 2869 | struct PowerModeInitialVSyncEnabled<HWC_POWER_MODE_DOZE> : public std::true_type {}; |
| 2870 | |
| 2871 | template <typename Case> |
| 2872 | void SetPowerModeInternalTest::transitionDisplayCommon() { |
| 2873 | // -------------------------------------------------------------------- |
| 2874 | // Preconditions |
| 2875 | |
Peiyong Lin | ed531a3 | 2018-10-26 18:27:56 -0700 | [diff] [blame] | 2876 | Case::Doze::setupComposerCallExpectations(this); |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 2877 | auto display = |
| 2878 | Case::injectDisplayWithInitialPowerMode(this, Case::Transition::INITIAL_POWER_MODE); |
| 2879 | Case::setInitialPrimaryHWVsyncEnabled(this, |
| 2880 | PowerModeInitialVSyncEnabled< |
| 2881 | Case::Transition::INITIAL_POWER_MODE>::value); |
| 2882 | |
| 2883 | // -------------------------------------------------------------------- |
| 2884 | // Call Expectations |
| 2885 | |
| 2886 | Case::setupSurfaceInterceptorCallExpectations(this, Case::Transition::TARGET_POWER_MODE); |
| 2887 | Case::Transition::template setupCallExpectations<Case>(this); |
| 2888 | |
| 2889 | // -------------------------------------------------------------------- |
| 2890 | // Invocation |
| 2891 | |
| 2892 | mFlinger.setPowerModeInternal(display.mutableDisplayDevice(), |
| 2893 | Case::Transition::TARGET_POWER_MODE); |
| 2894 | |
| 2895 | // -------------------------------------------------------------------- |
| 2896 | // Postconditions |
| 2897 | |
| 2898 | Case::Transition::verifyPostconditions(this); |
| 2899 | } |
| 2900 | |
| 2901 | TEST_F(SetPowerModeInternalTest, setPowerModeInternalDoesNothingIfNoChange) { |
| 2902 | using Case = SimplePrimaryDisplayCase; |
| 2903 | |
| 2904 | // -------------------------------------------------------------------- |
| 2905 | // Preconditions |
| 2906 | |
| 2907 | // A primary display device is set up |
| 2908 | Case::Display::injectHwcDisplay(this); |
| 2909 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2910 | display.inject(); |
| 2911 | |
Dominik Laskowski | a2edf61 | 2018-06-01 13:15:16 -0700 | [diff] [blame] | 2912 | // The display is already set to HWC_POWER_MODE_NORMAL |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 2913 | display.mutableDisplayDevice()->setPowerMode(HWC_POWER_MODE_NORMAL); |
| 2914 | |
| 2915 | // -------------------------------------------------------------------- |
| 2916 | // Invocation |
| 2917 | |
| 2918 | mFlinger.setPowerModeInternal(display.mutableDisplayDevice(), HWC_POWER_MODE_NORMAL); |
| 2919 | |
| 2920 | // -------------------------------------------------------------------- |
| 2921 | // Postconditions |
| 2922 | |
| 2923 | EXPECT_EQ(HWC_POWER_MODE_NORMAL, display.mutableDisplayDevice()->getPowerMode()); |
| 2924 | } |
| 2925 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 2926 | TEST_F(SetPowerModeInternalTest, setPowerModeInternalDoesNothingIfVirtualDisplay) { |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 2927 | using Case = HwcVirtualDisplayCase; |
| 2928 | |
| 2929 | // -------------------------------------------------------------------- |
| 2930 | // Preconditions |
| 2931 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2932 | // Insert display data so that the HWC thinks it created the virtual display. |
| 2933 | const auto displayId = Case::Display::DISPLAY_ID::get(); |
| 2934 | ASSERT_TRUE(displayId); |
Dominik Laskowski | 1af4793 | 2018-11-12 10:20:46 -0800 | [diff] [blame] | 2935 | mFlinger.mutableHwcDisplayData().try_emplace(*displayId); |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 2936 | |
| 2937 | // A virtual display device is set up |
| 2938 | Case::Display::injectHwcDisplay(this); |
| 2939 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2940 | display.inject(); |
| 2941 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 2942 | // The display is set to HWC_POWER_MODE_NORMAL |
| 2943 | getDisplayDevice(display.token())->setPowerMode(HWC_POWER_MODE_NORMAL); |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 2944 | |
| 2945 | // -------------------------------------------------------------------- |
| 2946 | // Invocation |
| 2947 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 2948 | mFlinger.setPowerModeInternal(display.mutableDisplayDevice(), HWC_POWER_MODE_OFF); |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 2949 | |
| 2950 | // -------------------------------------------------------------------- |
| 2951 | // Postconditions |
| 2952 | |
| 2953 | EXPECT_EQ(HWC_POWER_MODE_NORMAL, display.mutableDisplayDevice()->getPowerMode()); |
| 2954 | } |
| 2955 | |
| 2956 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToOnPrimaryDisplay) { |
| 2957 | transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOffToOnVariant>>(); |
| 2958 | } |
| 2959 | |
| 2960 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToDozeSuspendPrimaryDisplay) { |
| 2961 | transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOffToDozeSuspendVariant>>(); |
| 2962 | } |
| 2963 | |
| 2964 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToOffPrimaryDisplay) { |
| 2965 | transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToOffVariant>>(); |
| 2966 | } |
| 2967 | |
| 2968 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOffPrimaryDisplay) { |
| 2969 | transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToOffVariant>>(); |
| 2970 | } |
| 2971 | |
| 2972 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozePrimaryDisplay) { |
| 2973 | transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToDozeVariant>>(); |
| 2974 | } |
| 2975 | |
| 2976 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToDozePrimaryDisplay) { |
| 2977 | transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToDozeVariant>>(); |
| 2978 | } |
| 2979 | |
| 2980 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeToOnPrimaryDisplay) { |
| 2981 | transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeToOnVariant>>(); |
| 2982 | } |
| 2983 | |
| 2984 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOnPrimaryDisplay) { |
| 2985 | transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToOnVariant>>(); |
| 2986 | } |
| 2987 | |
| 2988 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeSuspendPrimaryDisplay) { |
| 2989 | transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToDozeSuspendVariant>>(); |
| 2990 | } |
| 2991 | |
| 2992 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToUnknownPrimaryDisplay) { |
| 2993 | transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToUnknownVariant>>(); |
| 2994 | } |
| 2995 | |
| 2996 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToOnExternalDisplay) { |
| 2997 | transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOffToOnVariant>>(); |
| 2998 | } |
| 2999 | |
| 3000 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToDozeSuspendExternalDisplay) { |
| 3001 | transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOffToDozeSuspendVariant>>(); |
| 3002 | } |
| 3003 | |
| 3004 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToOffExternalDisplay) { |
| 3005 | transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToOffVariant>>(); |
| 3006 | } |
| 3007 | |
| 3008 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOffExternalDisplay) { |
| 3009 | transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToOffVariant>>(); |
| 3010 | } |
| 3011 | |
| 3012 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeExternalDisplay) { |
| 3013 | transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToDozeVariant>>(); |
| 3014 | } |
| 3015 | |
| 3016 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToDozeExternalDisplay) { |
| 3017 | transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToDozeVariant>>(); |
| 3018 | } |
| 3019 | |
| 3020 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeToOnExternalDisplay) { |
| 3021 | transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeToOnVariant>>(); |
| 3022 | } |
| 3023 | |
| 3024 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOnExternalDisplay) { |
| 3025 | transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToOnVariant>>(); |
| 3026 | } |
| 3027 | |
| 3028 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeSuspendExternalDisplay) { |
| 3029 | transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToDozeSuspendVariant>>(); |
| 3030 | } |
| 3031 | |
| 3032 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToUnknownExternalDisplay) { |
| 3033 | transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToUnknownVariant>>(); |
| 3034 | } |
| 3035 | |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 3036 | } // namespace |
| 3037 | } // namespace android |