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