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