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