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