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