| 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 |  | 
|  | 20 | #include <gmock/gmock.h> | 
|  | 21 | #include <gtest/gtest.h> | 
|  | 22 |  | 
|  | 23 | #include <log/log.h> | 
|  | 24 |  | 
|  | 25 | #include "TestableSurfaceFlinger.h" | 
| Lloyd Pique | cbe0001 | 2018-02-02 15:40:42 -0800 | [diff] [blame] | 26 | #include "mock/DisplayHardware/MockComposer.h" | 
|  | 27 | #include "mock/DisplayHardware/MockDisplaySurface.h" | 
|  | 28 | #include "mock/MockEventControlThread.h" | 
|  | 29 | #include "mock/MockEventThread.h" | 
|  | 30 | #include "mock/MockMessageQueue.h" | 
|  | 31 | #include "mock/MockNativeWindowSurface.h" | 
|  | 32 | #include "mock/MockSurfaceInterceptor.h" | 
|  | 33 | #include "mock/RenderEngine/MockRenderEngine.h" | 
|  | 34 | #include "mock/gui/MockGraphicBufferConsumer.h" | 
|  | 35 | #include "mock/gui/MockGraphicBufferProducer.h" | 
|  | 36 | #include "mock/system/window/MockNativeWindow.h" | 
| Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 37 |  | 
|  | 38 | namespace android { | 
|  | 39 | namespace { | 
|  | 40 |  | 
| Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 41 | using testing::_; | 
|  | 42 | using testing::ByMove; | 
|  | 43 | using testing::DoAll; | 
|  | 44 | using testing::Mock; | 
|  | 45 | using testing::Return; | 
|  | 46 | using testing::SetArgPointee; | 
|  | 47 |  | 
|  | 48 | using android::hardware::graphics::common::V1_0::Hdr; | 
| Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 49 | using android::hardware::graphics::common::V1_1::ColorMode; | 
| Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 50 | using android::Hwc2::Error; | 
|  | 51 | using android::Hwc2::IComposer; | 
|  | 52 | using android::Hwc2::IComposerClient; | 
| Lloyd Pique | fc12f56 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 53 | using android::Hwc2::RenderIntent; | 
| Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 54 |  | 
| Lloyd Pique | fc12f56 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 55 | using FakeDisplayDeviceInjector = TestableSurfaceFlinger::FakeDisplayDeviceInjector; | 
|  | 56 | using FakeHwcDisplayInjector = TestableSurfaceFlinger::FakeHwcDisplayInjector; | 
| Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 57 | using HotplugEvent = TestableSurfaceFlinger::HotplugEvent; | 
| Lloyd Pique | fc12f56 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 58 | using HWC2Display = TestableSurfaceFlinger::HWC2Display; | 
| Lloyd Pique | bc79209 | 2018-01-17 11:52:30 -0800 | [diff] [blame] | 59 |  | 
| Lloyd Pique | fc12f56 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 60 | constexpr int32_t DEFAULT_REFRESH_RATE = 16'666'666; | 
| Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 61 | constexpr int32_t DEFAULT_DPI = 320; | 
| Lloyd Pique | fc12f56 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 62 | constexpr int DEFAULT_VIRTUAL_DISPLAY_SURFACE_FORMAT = HAL_PIXEL_FORMAT_RGB_565; | 
| Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 63 |  | 
| Lloyd Pique | fc12f56 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 64 | /* ------------------------------------------------------------------------ | 
|  | 65 | * Boolean avoidance | 
|  | 66 | * | 
|  | 67 | * To make calls and template instantiations more readable, we define some | 
|  | 68 | * local enums along with an implicit bool conversion. | 
|  | 69 | */ | 
|  | 70 |  | 
|  | 71 | #define BOOL_SUBSTITUTE(TYPENAME) enum class TYPENAME : bool { FALSE = false, TRUE = true }; | 
|  | 72 |  | 
|  | 73 | BOOL_SUBSTITUTE(Critical); | 
|  | 74 | BOOL_SUBSTITUTE(Async); | 
|  | 75 | BOOL_SUBSTITUTE(Secure); | 
|  | 76 |  | 
|  | 77 | /* ------------------------------------------------------------------------ | 
|  | 78 | * | 
|  | 79 | */ | 
| Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 80 |  | 
| Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 81 | class DisplayTransactionTest : public testing::Test { | 
| Lloyd Pique | fc12f56 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 82 | public: | 
| Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 83 | DisplayTransactionTest(); | 
|  | 84 | ~DisplayTransactionTest() override; | 
|  | 85 |  | 
| Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 86 | // -------------------------------------------------------------------- | 
| Lloyd Pique | fc12f56 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 87 | // Mock/Fake injection | 
| Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 88 |  | 
| Lloyd Pique | fc12f56 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 89 | void injectMockComposer(int virtualDisplayCount); | 
|  | 90 | void injectFakeBufferQueueFactory(); | 
|  | 91 | void injectFakeNativeWindowSurfaceFactory(); | 
| Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 92 |  | 
|  | 93 | // -------------------------------------------------------------------- | 
|  | 94 | // Postcondition helpers | 
|  | 95 |  | 
| Lloyd Pique | fc12f56 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 96 | bool hasHwcDisplay(hwc2_display_t displayId); | 
| Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 97 | bool hasTransactionFlagSet(int flag); | 
|  | 98 | bool hasDisplayDevice(sp<IBinder> displayToken); | 
|  | 99 | sp<DisplayDevice> getDisplayDevice(sp<IBinder> displayToken); | 
|  | 100 | bool hasCurrentDisplayState(sp<IBinder> displayToken); | 
|  | 101 | const DisplayDeviceState& getCurrentDisplayState(sp<IBinder> displayToken); | 
|  | 102 | bool hasDrawingDisplayState(sp<IBinder> displayToken); | 
|  | 103 | const DisplayDeviceState& getDrawingDisplayState(sp<IBinder> displayToken); | 
|  | 104 |  | 
|  | 105 | // -------------------------------------------------------------------- | 
|  | 106 | // Test instances | 
| Lloyd Pique | 5b36f3f | 2018-01-17 11:57:07 -0800 | [diff] [blame] | 107 |  | 
| Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 108 | TestableSurfaceFlinger mFlinger; | 
| Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 109 | mock::EventThread* mEventThread = new mock::EventThread(); | 
| Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 110 | mock::EventControlThread* mEventControlThread = new mock::EventControlThread(); | 
| Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 111 |  | 
|  | 112 | // These mocks are created by the test, but are destroyed by SurfaceFlinger | 
|  | 113 | // by virtue of being stored into a std::unique_ptr. However we still need | 
|  | 114 | // to keep a reference to them for use in setting up call expectations. | 
|  | 115 | RE::mock::RenderEngine* mRenderEngine = new RE::mock::RenderEngine(); | 
| Lloyd Pique | fc12f56 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 116 | Hwc2::mock::Composer* mComposer = nullptr; | 
| Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 117 | mock::MessageQueue* mMessageQueue = new mock::MessageQueue(); | 
|  | 118 | mock::SurfaceInterceptor* mSurfaceInterceptor = new mock::SurfaceInterceptor(); | 
| Lloyd Pique | 5b36f3f | 2018-01-17 11:57:07 -0800 | [diff] [blame] | 119 |  | 
|  | 120 | // These mocks are created only when expected to be created via a factory. | 
|  | 121 | sp<mock::GraphicBufferConsumer> mConsumer; | 
|  | 122 | sp<mock::GraphicBufferProducer> mProducer; | 
| Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 123 | mock::NativeWindowSurface* mNativeWindowSurface = nullptr; | 
|  | 124 | sp<mock::NativeWindow> mNativeWindow; | 
|  | 125 | RE::mock::Surface* mRenderSurface = nullptr; | 
| Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 126 | }; | 
|  | 127 |  | 
|  | 128 | DisplayTransactionTest::DisplayTransactionTest() { | 
|  | 129 | const ::testing::TestInfo* const test_info = | 
|  | 130 | ::testing::UnitTest::GetInstance()->current_test_info(); | 
|  | 131 | 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] | 132 |  | 
| Lloyd Pique | fc12f56 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 133 | // Default to no wide color display support configured | 
|  | 134 | mFlinger.mutableHasWideColorDisplay() = false; | 
|  | 135 | mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::UNMANAGED; | 
|  | 136 |  | 
|  | 137 | // Default to using HWC virtual displays | 
|  | 138 | mFlinger.mutableUseHwcVirtualDisplays() = true; | 
|  | 139 |  | 
| Lloyd Pique | 5b36f3f | 2018-01-17 11:57:07 -0800 | [diff] [blame] | 140 | mFlinger.setCreateBufferQueueFunction([](auto, auto, auto) { | 
|  | 141 | ADD_FAILURE() << "Unexpected request to create a buffer queue."; | 
|  | 142 | }); | 
|  | 143 |  | 
| Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 144 | mFlinger.setCreateNativeWindowSurface([](auto) { | 
|  | 145 | ADD_FAILURE() << "Unexpected request to create a native window surface."; | 
|  | 146 | return nullptr; | 
|  | 147 | }); | 
|  | 148 |  | 
|  | 149 | mFlinger.mutableEventControlThread().reset(mEventControlThread); | 
| Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 150 | mFlinger.mutableEventThread().reset(mEventThread); | 
| Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 151 | mFlinger.mutableEventQueue().reset(mMessageQueue); | 
| Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 152 | mFlinger.setupRenderEngine(std::unique_ptr<RE::RenderEngine>(mRenderEngine)); | 
| Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 153 | mFlinger.mutableInterceptor().reset(mSurfaceInterceptor); | 
| Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 154 |  | 
| Lloyd Pique | fc12f56 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 155 | injectMockComposer(0); | 
| Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 156 | } | 
|  | 157 |  | 
|  | 158 | DisplayTransactionTest::~DisplayTransactionTest() { | 
|  | 159 | const ::testing::TestInfo* const test_info = | 
|  | 160 | ::testing::UnitTest::GetInstance()->current_test_info(); | 
|  | 161 | ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name()); | 
|  | 162 | } | 
|  | 163 |  | 
| Lloyd Pique | fc12f56 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 164 | void DisplayTransactionTest::injectMockComposer(int virtualDisplayCount) { | 
|  | 165 | mComposer = new Hwc2::mock::Composer(); | 
| Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 166 | EXPECT_CALL(*mComposer, getCapabilities()) | 
|  | 167 | .WillOnce(Return(std::vector<IComposer::Capability>())); | 
|  | 168 | EXPECT_CALL(*mComposer, getMaxVirtualDisplayCount()).WillOnce(Return(virtualDisplayCount)); | 
|  | 169 | mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer)); | 
| Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 170 |  | 
| Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 171 | Mock::VerifyAndClear(mComposer); | 
|  | 172 | } | 
|  | 173 |  | 
| Lloyd Pique | fc12f56 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 174 | void DisplayTransactionTest::injectFakeBufferQueueFactory() { | 
| Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 175 | // This setup is only expected once per test. | 
|  | 176 | ASSERT_TRUE(mConsumer == nullptr && mProducer == nullptr); | 
|  | 177 |  | 
| Lloyd Pique | 5b36f3f | 2018-01-17 11:57:07 -0800 | [diff] [blame] | 178 | mConsumer = new mock::GraphicBufferConsumer(); | 
|  | 179 | mProducer = new mock::GraphicBufferProducer(); | 
|  | 180 |  | 
|  | 181 | mFlinger.setCreateBufferQueueFunction([this](auto outProducer, auto outConsumer, bool) { | 
|  | 182 | *outProducer = mProducer; | 
|  | 183 | *outConsumer = mConsumer; | 
|  | 184 | }); | 
| Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 185 | } | 
| Lloyd Pique | 5b36f3f | 2018-01-17 11:57:07 -0800 | [diff] [blame] | 186 |  | 
| Lloyd Pique | fc12f56 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 187 | void DisplayTransactionTest::injectFakeNativeWindowSurfaceFactory() { | 
| Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 188 | // This setup is only expected once per test. | 
|  | 189 | ASSERT_TRUE(mNativeWindowSurface == nullptr); | 
|  | 190 |  | 
|  | 191 | mNativeWindowSurface = new mock::NativeWindowSurface(); | 
|  | 192 | mNativeWindow = new mock::NativeWindow(); | 
|  | 193 |  | 
|  | 194 | mFlinger.setCreateNativeWindowSurface( | 
|  | 195 | [this](auto) { return std::unique_ptr<NativeWindowSurface>(mNativeWindowSurface); }); | 
| Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 196 | } | 
|  | 197 |  | 
| Lloyd Pique | fc12f56 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 198 | bool DisplayTransactionTest::hasHwcDisplay(hwc2_display_t displayId) { | 
|  | 199 | return mFlinger.mutableHwcDisplaySlots().count(displayId) == 1; | 
| Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 200 | } | 
|  | 201 |  | 
|  | 202 | bool DisplayTransactionTest::hasTransactionFlagSet(int flag) { | 
|  | 203 | return mFlinger.mutableTransactionFlags() & flag; | 
|  | 204 | } | 
|  | 205 |  | 
|  | 206 | bool DisplayTransactionTest::hasDisplayDevice(sp<IBinder> displayToken) { | 
|  | 207 | return mFlinger.mutableDisplays().indexOfKey(displayToken) >= 0; | 
|  | 208 | } | 
|  | 209 |  | 
|  | 210 | sp<DisplayDevice> DisplayTransactionTest::getDisplayDevice(sp<IBinder> displayToken) { | 
|  | 211 | return mFlinger.mutableDisplays().valueFor(displayToken); | 
|  | 212 | } | 
|  | 213 |  | 
|  | 214 | bool DisplayTransactionTest::hasCurrentDisplayState(sp<IBinder> displayToken) { | 
|  | 215 | return mFlinger.mutableCurrentState().displays.indexOfKey(displayToken) >= 0; | 
|  | 216 | } | 
|  | 217 |  | 
|  | 218 | const DisplayDeviceState& DisplayTransactionTest::getCurrentDisplayState(sp<IBinder> displayToken) { | 
|  | 219 | return mFlinger.mutableCurrentState().displays.valueFor(displayToken); | 
|  | 220 | } | 
|  | 221 |  | 
|  | 222 | bool DisplayTransactionTest::hasDrawingDisplayState(sp<IBinder> displayToken) { | 
|  | 223 | return mFlinger.mutableDrawingState().displays.indexOfKey(displayToken) >= 0; | 
|  | 224 | } | 
|  | 225 |  | 
|  | 226 | const DisplayDeviceState& DisplayTransactionTest::getDrawingDisplayState(sp<IBinder> displayToken) { | 
|  | 227 | return mFlinger.mutableDrawingState().displays.valueFor(displayToken); | 
|  | 228 | } | 
|  | 229 |  | 
|  | 230 | /* ------------------------------------------------------------------------ | 
| Lloyd Pique | fc12f56 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 231 | * | 
| Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 232 | */ | 
|  | 233 |  | 
| Lloyd Pique | fc12f56 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 234 | template <DisplayDevice::DisplayType type, DisplayDevice::DisplayType hwcId, int width, int height, | 
|  | 235 | Critical critical, Async async, Secure secure, int grallocUsage> | 
|  | 236 | struct DisplayVariant { | 
|  | 237 | // The display width and height | 
|  | 238 | static constexpr int WIDTH = width; | 
|  | 239 | static constexpr int HEIGHT = height; | 
|  | 240 |  | 
|  | 241 | static constexpr int GRALLOC_USAGE = grallocUsage; | 
|  | 242 |  | 
|  | 243 | // The type for this display | 
|  | 244 | static constexpr DisplayDevice::DisplayType TYPE = type; | 
|  | 245 | static constexpr DisplayDevice::DisplayType HWCOMPOSER_ID = hwcId; | 
|  | 246 |  | 
|  | 247 | // When creating native window surfaces for the framebuffer, whether those should be critical | 
|  | 248 | static constexpr Critical CRITICAL = critical; | 
|  | 249 |  | 
|  | 250 | // When creating native window surfaces for the framebuffer, whether those should be async | 
|  | 251 | static constexpr Async ASYNC = async; | 
|  | 252 |  | 
|  | 253 | // Whether the display should be treated as secure | 
|  | 254 | static constexpr Secure SECURE = secure; | 
|  | 255 |  | 
|  | 256 | static auto makeFakeExistingDisplayInjector(DisplayTransactionTest* test) { | 
|  | 257 | auto injector = FakeDisplayDeviceInjector(test->mFlinger, TYPE, HWCOMPOSER_ID); | 
|  | 258 | injector.setSecure(static_cast<bool>(SECURE)); | 
|  | 259 | return injector; | 
|  | 260 | } | 
|  | 261 |  | 
|  | 262 | // Called by tests to set up any native window creation call expectations. | 
|  | 263 | static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) { | 
|  | 264 | EXPECT_CALL(*test->mNativeWindowSurface, getNativeWindow()) | 
|  | 265 | .WillOnce(Return(test->mNativeWindow)); | 
|  | 266 | EXPECT_CALL(*test->mNativeWindow, perform(19)).WillRepeatedly(Return(NO_ERROR)); | 
|  | 267 |  | 
|  | 268 | // For simplicity, we only expect to create a single render surface for | 
|  | 269 | // each test. | 
|  | 270 | ASSERT_TRUE(test->mRenderSurface == nullptr); | 
|  | 271 | test->mRenderSurface = new RE::mock::Surface(); | 
|  | 272 | EXPECT_CALL(*test->mRenderEngine, createSurface()) | 
|  | 273 | .WillOnce(Return(ByMove(std::unique_ptr<RE::Surface>(test->mRenderSurface)))); | 
|  | 274 | EXPECT_CALL(*test->mRenderSurface, setAsync(static_cast<bool>(ASYNC))).Times(1); | 
|  | 275 | EXPECT_CALL(*test->mRenderSurface, setCritical(static_cast<bool>(CRITICAL))).Times(1); | 
|  | 276 | EXPECT_CALL(*test->mRenderSurface, setNativeWindow(test->mNativeWindow.get())).Times(1); | 
|  | 277 | EXPECT_CALL(*test->mRenderSurface, queryWidth()).WillOnce(Return(WIDTH)); | 
|  | 278 | EXPECT_CALL(*test->mRenderSurface, queryHeight()).WillOnce(Return(HEIGHT)); | 
|  | 279 | } | 
|  | 280 |  | 
|  | 281 | static void setupFramebufferConsumerBufferQueueCallExpectations(DisplayTransactionTest* test) { | 
|  | 282 | EXPECT_CALL(*test->mConsumer, consumerConnect(_, false)).WillOnce(Return(NO_ERROR)); | 
|  | 283 | EXPECT_CALL(*test->mConsumer, setConsumerName(_)).WillRepeatedly(Return(NO_ERROR)); | 
|  | 284 | EXPECT_CALL(*test->mConsumer, setConsumerUsageBits(GRALLOC_USAGE)) | 
|  | 285 | .WillRepeatedly(Return(NO_ERROR)); | 
|  | 286 | EXPECT_CALL(*test->mConsumer, setDefaultBufferSize(WIDTH, HEIGHT)) | 
|  | 287 | .WillRepeatedly(Return(NO_ERROR)); | 
|  | 288 | EXPECT_CALL(*test->mConsumer, setMaxAcquiredBufferCount(_)) | 
|  | 289 | .WillRepeatedly(Return(NO_ERROR)); | 
|  | 290 | } | 
|  | 291 |  | 
|  | 292 | static void setupFramebufferProducerBufferQueueCallExpectations(DisplayTransactionTest* test) { | 
|  | 293 | EXPECT_CALL(*test->mProducer, allocateBuffers(0, 0, 0, 0)).WillRepeatedly(Return()); | 
|  | 294 | } | 
|  | 295 | }; | 
|  | 296 |  | 
|  | 297 | template <hwc2_display_t hwcDisplayId, HWC2::DisplayType hwcDisplayType, typename DisplayVariant> | 
|  | 298 | struct HwcDisplayVariant { | 
|  | 299 | // The display id supplied by the HWC | 
|  | 300 | static constexpr hwc2_display_t HWC_DISPLAY_ID = hwcDisplayId; | 
|  | 301 |  | 
|  | 302 | // The HWC display type | 
|  | 303 | static constexpr HWC2::DisplayType HWC_DISPLAY_TYPE = hwcDisplayType; | 
|  | 304 |  | 
|  | 305 | // The HWC active configuration id | 
|  | 306 | // TODO(b/69807179): SurfaceFlinger does not correctly get the active | 
|  | 307 | // config. Once it does, change this to non-zero so that it is properly | 
|  | 308 | // covered. | 
|  | 309 | // static constexpr int HWC_ACTIVE_CONFIG_ID = 2001; | 
|  | 310 | static constexpr int HWC_ACTIVE_CONFIG_ID = 0; | 
|  | 311 |  | 
|  | 312 | static void injectPendingHotplugEvent(DisplayTransactionTest* test, | 
|  | 313 | HWC2::Connection connection) { | 
|  | 314 | test->mFlinger.mutablePendingHotplugEvents().emplace_back( | 
|  | 315 | HotplugEvent{HWC_DISPLAY_ID, connection}); | 
|  | 316 | } | 
|  | 317 |  | 
|  | 318 | // Called by tests to inject a HWC display setup | 
|  | 319 | static void injectHwcDisplay(DisplayTransactionTest* test) { | 
|  | 320 | FakeHwcDisplayInjector(DisplayVariant::TYPE, HWC_DISPLAY_TYPE) | 
|  | 321 | .setHwcDisplayId(HWC_DISPLAY_ID) | 
|  | 322 | .setWidth(DisplayVariant::WIDTH) | 
|  | 323 | .setHeight(DisplayVariant::HEIGHT) | 
|  | 324 | .setActiveConfig(HWC_ACTIVE_CONFIG_ID) | 
|  | 325 | .inject(&test->mFlinger, test->mComposer); | 
|  | 326 | } | 
|  | 327 |  | 
|  | 328 | static void setupHwcHotplugCallExpectations(DisplayTransactionTest* test) { | 
|  | 329 | EXPECT_CALL(*test->mComposer, getDisplayType(HWC_DISPLAY_ID, _)) | 
|  | 330 | .WillOnce(DoAll(SetArgPointee<1>(static_cast<IComposerClient::DisplayType>( | 
|  | 331 | HWC_DISPLAY_TYPE)), | 
|  | 332 | Return(Error::NONE))); | 
|  | 333 | EXPECT_CALL(*test->mComposer, setClientTargetSlotCount(_)).WillOnce(Return(Error::NONE)); | 
|  | 334 | EXPECT_CALL(*test->mComposer, getDisplayConfigs(HWC_DISPLAY_ID, _)) | 
|  | 335 | .WillOnce(DoAll(SetArgPointee<1>(std::vector<unsigned>{HWC_ACTIVE_CONFIG_ID}), | 
|  | 336 | Return(Error::NONE))); | 
|  | 337 | EXPECT_CALL(*test->mComposer, | 
|  | 338 | getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID, | 
|  | 339 | IComposerClient::Attribute::WIDTH, _)) | 
|  | 340 | .WillOnce(DoAll(SetArgPointee<3>(DisplayVariant::WIDTH), Return(Error::NONE))); | 
|  | 341 | EXPECT_CALL(*test->mComposer, | 
|  | 342 | getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID, | 
|  | 343 | IComposerClient::Attribute::HEIGHT, _)) | 
|  | 344 | .WillOnce(DoAll(SetArgPointee<3>(DisplayVariant::HEIGHT), Return(Error::NONE))); | 
|  | 345 | EXPECT_CALL(*test->mComposer, | 
|  | 346 | getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID, | 
|  | 347 | IComposerClient::Attribute::VSYNC_PERIOD, _)) | 
|  | 348 | .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_REFRESH_RATE), Return(Error::NONE))); | 
|  | 349 | EXPECT_CALL(*test->mComposer, | 
|  | 350 | getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID, | 
|  | 351 | IComposerClient::Attribute::DPI_X, _)) | 
|  | 352 | .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_DPI), Return(Error::NONE))); | 
|  | 353 | EXPECT_CALL(*test->mComposer, | 
|  | 354 | getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID, | 
|  | 355 | IComposerClient::Attribute::DPI_Y, _)) | 
|  | 356 | .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_DPI), Return(Error::NONE))); | 
|  | 357 | } | 
|  | 358 |  | 
|  | 359 | // Called by tests to set up HWC call expectations | 
|  | 360 | static void setupHwcGetActiveConfigCallExpectations(DisplayTransactionTest* test) { | 
|  | 361 | EXPECT_CALL(*test->mComposer, getActiveConfig(HWC_DISPLAY_ID, _)) | 
|  | 362 | .WillOnce(DoAll(SetArgPointee<1>(HWC_ACTIVE_CONFIG_ID), Return(Error::NONE))); | 
|  | 363 | } | 
|  | 364 | }; | 
|  | 365 |  | 
|  | 366 | struct NonHwcDisplayVariant { | 
|  | 367 | static constexpr int HWC_ACTIVE_CONFIG_ID = 0; | 
|  | 368 |  | 
|  | 369 | static void injectHwcDisplay(DisplayTransactionTest*) {} | 
|  | 370 |  | 
|  | 371 | static void setupHwcGetActiveConfigCallExpectations(DisplayTransactionTest* test) { | 
|  | 372 | EXPECT_CALL(*test->mComposer, getActiveConfig(_, _)).Times(0); | 
|  | 373 | } | 
|  | 374 | }; | 
|  | 375 |  | 
|  | 376 | // Physical displays are expected to be synchronous, secure, and have a HWC display for output. | 
|  | 377 | constexpr uint32_t GRALLOC_USAGE_PHYSICAL_DISPLAY = | 
|  | 378 | GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_FB; | 
|  | 379 |  | 
|  | 380 | template <hwc2_display_t hwcDisplayId, DisplayDevice::DisplayType type, int width, int height, | 
|  | 381 | Critical critical> | 
|  | 382 | struct PhysicalDisplayVariant | 
|  | 383 | : public DisplayVariant<type, type, width, height, critical, Async::FALSE, Secure::TRUE, | 
|  | 384 | GRALLOC_USAGE_PHYSICAL_DISPLAY>, | 
|  | 385 | public HwcDisplayVariant<hwcDisplayId, HWC2::DisplayType::Physical, | 
|  | 386 | DisplayVariant<type, type, width, height, critical, Async::FALSE, | 
|  | 387 | Secure::TRUE, GRALLOC_USAGE_PHYSICAL_DISPLAY>> {}; | 
|  | 388 |  | 
| Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 389 | // An invalid display | 
|  | 390 | using InvalidDisplayVariant = | 
|  | 391 | DisplayVariant<DisplayDevice::DISPLAY_ID_INVALID, DisplayDevice::DISPLAY_ID_INVALID, 0, 0, | 
|  | 392 | Critical::FALSE, Async::FALSE, Secure::FALSE, 0>; | 
|  | 393 |  | 
| Lloyd Pique | fc12f56 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 394 | // A primary display is a physical display that is critical | 
|  | 395 | using PrimaryDisplayVariant = | 
|  | 396 | PhysicalDisplayVariant<1001, DisplayDevice::DISPLAY_PRIMARY, 3840, 2160, Critical::TRUE>; | 
|  | 397 |  | 
|  | 398 | // An external display is physical display that is not critical. | 
|  | 399 | using ExternalDisplayVariant = | 
|  | 400 | PhysicalDisplayVariant<1002, DisplayDevice::DISPLAY_EXTERNAL, 1920, 1280, Critical::FALSE>; | 
|  | 401 |  | 
|  | 402 | using TertiaryDisplayVariant = | 
|  | 403 | PhysicalDisplayVariant<1003, DisplayDevice::DISPLAY_EXTERNAL, 1600, 1200, Critical::FALSE>; | 
|  | 404 |  | 
|  | 405 | // A virtual display not supported by the HWC. | 
|  | 406 | constexpr uint32_t GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY = 0; | 
|  | 407 |  | 
|  | 408 | template <int width, int height, Secure secure> | 
|  | 409 | struct NonHwcVirtualDisplayVariant | 
|  | 410 | : public DisplayVariant<DisplayDevice::DISPLAY_VIRTUAL, DisplayDevice::DISPLAY_ID_INVALID, | 
|  | 411 | width, height, Critical::FALSE, Async::TRUE, secure, | 
|  | 412 | GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY>, | 
|  | 413 | public NonHwcDisplayVariant { | 
|  | 414 | using Base = DisplayVariant<DisplayDevice::DISPLAY_VIRTUAL, DisplayDevice::DISPLAY_ID_INVALID, | 
|  | 415 | width, height, Critical::FALSE, Async::TRUE, secure, | 
|  | 416 | GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY>; | 
|  | 417 |  | 
|  | 418 | static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) { | 
|  | 419 | Base::setupNativeWindowSurfaceCreationCallExpectations(test); | 
|  | 420 | EXPECT_CALL(*test->mNativeWindow, setSwapInterval(0)).Times(1); | 
|  | 421 | } | 
|  | 422 | }; | 
|  | 423 |  | 
|  | 424 | // A virtual display supported by the HWC. | 
|  | 425 | constexpr uint32_t GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY = GRALLOC_USAGE_HW_COMPOSER; | 
|  | 426 |  | 
|  | 427 | template <int width, int height, Secure secure> | 
|  | 428 | struct HwcVirtualDisplayVariant | 
|  | 429 | : public DisplayVariant<DisplayDevice::DISPLAY_VIRTUAL, DisplayDevice::DISPLAY_VIRTUAL, width, | 
|  | 430 | height, Critical::FALSE, Async::TRUE, secure, | 
|  | 431 | GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY>, | 
|  | 432 | public HwcDisplayVariant<1010, HWC2::DisplayType::Virtual, | 
|  | 433 | NonHwcVirtualDisplayVariant<width, height, secure>> { | 
|  | 434 | using Base = | 
|  | 435 | DisplayVariant<DisplayDevice::DISPLAY_VIRTUAL, DisplayDevice::DISPLAY_VIRTUAL, width, | 
|  | 436 | height, Critical::FALSE, Async::TRUE, secure, GRALLOC_USAGE_HW_COMPOSER>; | 
|  | 437 | using Self = HwcVirtualDisplayVariant<width, height, secure>; | 
|  | 438 |  | 
|  | 439 | static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) { | 
|  | 440 | Base::setupNativeWindowSurfaceCreationCallExpectations(test); | 
|  | 441 | EXPECT_CALL(*test->mNativeWindow, setSwapInterval(0)).Times(1); | 
|  | 442 | } | 
|  | 443 |  | 
|  | 444 | static void setupHwcVirtualDisplayCreationCallExpectations(DisplayTransactionTest* test) { | 
|  | 445 | EXPECT_CALL(*test->mComposer, createVirtualDisplay(Base::WIDTH, Base::HEIGHT, _, _)) | 
|  | 446 | .WillOnce(DoAll(SetArgPointee<3>(Self::HWC_DISPLAY_ID), Return(Error::NONE))); | 
|  | 447 | EXPECT_CALL(*test->mComposer, setClientTargetSlotCount(_)).WillOnce(Return(Error::NONE)); | 
|  | 448 | } | 
|  | 449 | }; | 
|  | 450 |  | 
|  | 451 | // For this variant, SurfaceFlinger should not configure itself with wide | 
|  | 452 | // display support, so the display should not be configured for wide-color | 
|  | 453 | // support. | 
|  | 454 | struct WideColorSupportNotConfiguredVariant { | 
|  | 455 | static constexpr bool WIDE_COLOR_SUPPORTED = false; | 
|  | 456 |  | 
|  | 457 | static void injectConfigChange(DisplayTransactionTest* test) { | 
|  | 458 | test->mFlinger.mutableHasWideColorDisplay() = false; | 
|  | 459 | test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::UNMANAGED; | 
|  | 460 | } | 
|  | 461 |  | 
|  | 462 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { | 
|  | 463 | EXPECT_CALL(*test->mComposer, getColorModes(_, _)).Times(0); | 
|  | 464 | EXPECT_CALL(*test->mComposer, getRenderIntents(_, _, _)).Times(0); | 
|  | 465 | EXPECT_CALL(*test->mComposer, setColorMode(_, _, _)).Times(0); | 
|  | 466 | } | 
|  | 467 | }; | 
|  | 468 |  | 
|  | 469 | // For this variant, SurfaceFlinger should configure itself with wide display | 
|  | 470 | // support, and the display should respond with an non-empty list of supported | 
|  | 471 | // color modes. Wide-color support should be configured. | 
|  | 472 | template <typename Display> | 
|  | 473 | struct WideColorP3ColorimetricSupportedVariant { | 
|  | 474 | static constexpr bool WIDE_COLOR_SUPPORTED = true; | 
|  | 475 |  | 
|  | 476 | static void injectConfigChange(DisplayTransactionTest* test) { | 
|  | 477 | test->mFlinger.mutableHasWideColorDisplay() = true; | 
|  | 478 | test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::UNMANAGED; | 
|  | 479 | } | 
|  | 480 |  | 
|  | 481 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { | 
|  | 482 | EXPECT_CALL(*test->mComposer, getColorModes(Display::HWC_DISPLAY_ID, _)) | 
|  | 483 | .WillOnce(DoAll(SetArgPointee<1>(std::vector<ColorMode>({ColorMode::DISPLAY_P3})), | 
|  | 484 | Return(Error::NONE))); | 
|  | 485 | EXPECT_CALL(*test->mComposer, | 
|  | 486 | getRenderIntents(Display::HWC_DISPLAY_ID, ColorMode::DISPLAY_P3, _)) | 
|  | 487 | .WillOnce(DoAll(SetArgPointee<2>( | 
|  | 488 | std::vector<RenderIntent>({RenderIntent::COLORIMETRIC})), | 
|  | 489 | Return(Error::NONE))); | 
|  | 490 | EXPECT_CALL(*test->mComposer, | 
|  | 491 | setColorMode(Display::HWC_DISPLAY_ID, ColorMode::SRGB, | 
|  | 492 | RenderIntent::COLORIMETRIC)) | 
|  | 493 | .WillOnce(Return(Error::NONE)); | 
|  | 494 | } | 
|  | 495 | }; | 
|  | 496 |  | 
|  | 497 | // For this variant, SurfaceFlinger should configure itself with wide color | 
|  | 498 | // display support, and the display should respond with an non-empty list of | 
|  | 499 | // supported color modes. | 
|  | 500 | template <typename Display> | 
|  | 501 | struct WideColorP3EnhanceSupportedVariant { | 
|  | 502 | static constexpr bool WIDE_COLOR_SUPPORTED = true; | 
|  | 503 |  | 
|  | 504 | static void injectConfigChange(DisplayTransactionTest* test) { | 
|  | 505 | test->mFlinger.mutableHasWideColorDisplay() = true; | 
|  | 506 | test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::ENHANCED; | 
|  | 507 | } | 
|  | 508 |  | 
|  | 509 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { | 
|  | 510 | EXPECT_CALL(*test->mComposer, getColorModes(Display::HWC_DISPLAY_ID, _)) | 
|  | 511 | .WillOnce(DoAll(SetArgPointee<1>(std::vector<ColorMode>({ColorMode::DISPLAY_P3})), | 
|  | 512 | Return(Error::NONE))); | 
|  | 513 | EXPECT_CALL(*test->mComposer, | 
|  | 514 | getRenderIntents(Display::HWC_DISPLAY_ID, ColorMode::DISPLAY_P3, _)) | 
|  | 515 | .WillOnce( | 
|  | 516 | DoAll(SetArgPointee<2>(std::vector<RenderIntent>({RenderIntent::ENHANCE})), | 
|  | 517 | Return(Error::NONE))); | 
|  | 518 | EXPECT_CALL(*test->mComposer, | 
|  | 519 | setColorMode(Display::HWC_DISPLAY_ID, ColorMode::SRGB, RenderIntent::ENHANCE)) | 
|  | 520 | .WillOnce(Return(Error::NONE)); | 
|  | 521 | } | 
|  | 522 | }; | 
|  | 523 |  | 
|  | 524 | // For this variant, SurfaceFlinger should configure itself with wide display | 
|  | 525 | // support, but the display should respond with an empty list of supported color | 
|  | 526 | // modes. Wide-color support for the display should not be configured. | 
|  | 527 | template <typename Display> | 
|  | 528 | struct WideColorNotSupportedVariant { | 
|  | 529 | static constexpr bool WIDE_COLOR_SUPPORTED = false; | 
|  | 530 |  | 
|  | 531 | static void injectConfigChange(DisplayTransactionTest* test) { | 
|  | 532 | test->mFlinger.mutableHasWideColorDisplay() = true; | 
|  | 533 | } | 
|  | 534 |  | 
|  | 535 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { | 
|  | 536 | EXPECT_CALL(*test->mComposer, getColorModes(Display::HWC_DISPLAY_ID, _)) | 
|  | 537 | .WillOnce(DoAll(SetArgPointee<1>(std::vector<ColorMode>()), Return(Error::NONE))); | 
|  | 538 | EXPECT_CALL(*test->mComposer, | 
|  | 539 | setColorMode(Display::HWC_DISPLAY_ID, ColorMode::NATIVE, | 
|  | 540 | RenderIntent::COLORIMETRIC)) | 
|  | 541 | .WillOnce(Return(Error::NONE)); | 
|  | 542 | } | 
|  | 543 | }; | 
|  | 544 |  | 
|  | 545 | // For this variant, the display is not a HWC display, so no HDR support should | 
|  | 546 | // be configured. | 
|  | 547 | struct NonHwcDisplayHdrSupportVariant { | 
|  | 548 | static constexpr bool HDR10_SUPPORTED = false; | 
|  | 549 | static constexpr bool HDR_HLG_SUPPORTED = false; | 
|  | 550 | static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false; | 
|  | 551 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { | 
|  | 552 | EXPECT_CALL(*test->mComposer, getHdrCapabilities(_, _, _, _, _)).Times(0); | 
|  | 553 | } | 
|  | 554 | }; | 
|  | 555 |  | 
|  | 556 | // For this variant, the composer should respond with a non-empty list of HDR | 
|  | 557 | // modes containing HDR10, so HDR10 support should be configured. | 
|  | 558 | template <typename Display> | 
|  | 559 | struct Hdr10SupportedVariant { | 
|  | 560 | static constexpr bool HDR10_SUPPORTED = true; | 
|  | 561 | static constexpr bool HDR_HLG_SUPPORTED = false; | 
|  | 562 | static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false; | 
|  | 563 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { | 
|  | 564 | EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _)) | 
|  | 565 | .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::HDR10})), | 
|  | 566 | Return(Error::NONE))); | 
|  | 567 | } | 
|  | 568 | }; | 
|  | 569 |  | 
|  | 570 | // For this variant, the composer should respond with a non-empty list of HDR | 
|  | 571 | // modes containing HLG, so HLG support should be configured. | 
|  | 572 | template <typename Display> | 
|  | 573 | struct HdrHlgSupportedVariant { | 
|  | 574 | static constexpr bool HDR10_SUPPORTED = false; | 
|  | 575 | static constexpr bool HDR_HLG_SUPPORTED = true; | 
|  | 576 | static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false; | 
|  | 577 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { | 
|  | 578 | EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _)) | 
|  | 579 | .WillOnce( | 
|  | 580 | DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::HLG})), Return(Error::NONE))); | 
|  | 581 | } | 
|  | 582 | }; | 
|  | 583 |  | 
|  | 584 | // For this variant, the composer should respond with a non-empty list of HDR | 
|  | 585 | // modes containing DOLBY_VISION, so DOLBY_VISION support should be configured. | 
|  | 586 | template <typename Display> | 
|  | 587 | struct HdrDolbyVisionSupportedVariant { | 
|  | 588 | static constexpr bool HDR10_SUPPORTED = false; | 
|  | 589 | static constexpr bool HDR_HLG_SUPPORTED = false; | 
|  | 590 | static constexpr bool HDR_DOLBY_VISION_SUPPORTED = true; | 
|  | 591 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { | 
|  | 592 | EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _)) | 
|  | 593 | .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::DOLBY_VISION})), | 
|  | 594 | Return(Error::NONE))); | 
|  | 595 | } | 
|  | 596 | }; | 
|  | 597 |  | 
|  | 598 | // For this variant, the composer should respond with am empty list of HDR | 
|  | 599 | // modes, so no HDR support should be configured. | 
|  | 600 | template <typename Display> | 
|  | 601 | struct HdrNotSupportedVariant { | 
|  | 602 | static constexpr bool HDR10_SUPPORTED = false; | 
|  | 603 | static constexpr bool HDR_HLG_SUPPORTED = false; | 
|  | 604 | static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false; | 
|  | 605 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { | 
|  | 606 | EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _)) | 
|  | 607 | .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>()), Return(Error::NONE))); | 
|  | 608 | } | 
|  | 609 | }; | 
|  | 610 |  | 
|  | 611 | /* ------------------------------------------------------------------------ | 
|  | 612 | * Typical display configurations to test | 
|  | 613 | */ | 
|  | 614 |  | 
|  | 615 | template <typename DisplayPolicy, typename WideColorSupportPolicy, typename HdrSupportPolicy> | 
|  | 616 | struct Case { | 
|  | 617 | using Display = DisplayPolicy; | 
|  | 618 | using WideColorSupport = WideColorSupportPolicy; | 
|  | 619 | using HdrSupport = HdrSupportPolicy; | 
|  | 620 | }; | 
|  | 621 |  | 
|  | 622 | using SimplePrimaryDisplayCase = | 
|  | 623 | Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>, | 
|  | 624 | HdrNotSupportedVariant<PrimaryDisplayVariant>>; | 
|  | 625 | using SimpleExternalDisplayCase = | 
|  | 626 | Case<ExternalDisplayVariant, WideColorNotSupportedVariant<ExternalDisplayVariant>, | 
|  | 627 | HdrNotSupportedVariant<ExternalDisplayVariant>>; | 
|  | 628 | using SimpleTertiaryDisplayCase = | 
|  | 629 | Case<TertiaryDisplayVariant, WideColorNotSupportedVariant<TertiaryDisplayVariant>, | 
|  | 630 | HdrNotSupportedVariant<TertiaryDisplayVariant>>; | 
|  | 631 | using NonHwcVirtualDisplayCase = | 
|  | 632 | Case<NonHwcVirtualDisplayVariant<1024, 768, Secure::FALSE>, | 
|  | 633 | WideColorSupportNotConfiguredVariant, NonHwcDisplayHdrSupportVariant>; | 
|  | 634 | using SimpleHwcVirtualDisplayVariant = HwcVirtualDisplayVariant<1024, 768, Secure::TRUE>; | 
|  | 635 | using HwcVirtualDisplayCase = | 
|  | 636 | Case<SimpleHwcVirtualDisplayVariant, WideColorSupportNotConfiguredVariant, | 
|  | 637 | HdrNotSupportedVariant<SimpleHwcVirtualDisplayVariant>>; | 
|  | 638 | using WideColorP3ColorimetricDisplayCase = | 
|  | 639 | Case<PrimaryDisplayVariant, WideColorP3ColorimetricSupportedVariant<PrimaryDisplayVariant>, | 
|  | 640 | HdrNotSupportedVariant<PrimaryDisplayVariant>>; | 
|  | 641 | using WideColorP3EnhanceDisplayCase = | 
|  | 642 | Case<PrimaryDisplayVariant, WideColorP3EnhanceSupportedVariant<PrimaryDisplayVariant>, | 
|  | 643 | HdrNotSupportedVariant<PrimaryDisplayVariant>>; | 
|  | 644 | using Hdr10DisplayCase = | 
|  | 645 | Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>, | 
|  | 646 | Hdr10SupportedVariant<PrimaryDisplayVariant>>; | 
|  | 647 | using HdrHlgDisplayCase = | 
|  | 648 | Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>, | 
|  | 649 | HdrHlgSupportedVariant<PrimaryDisplayVariant>>; | 
|  | 650 | using HdrDolbyVisionDisplayCase = | 
|  | 651 | Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>, | 
|  | 652 | HdrDolbyVisionSupportedVariant<PrimaryDisplayVariant>>; | 
| Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 653 | using InvalidDisplayCase = Case<InvalidDisplayVariant, WideColorSupportNotConfiguredVariant, | 
|  | 654 | NonHwcDisplayHdrSupportVariant>; | 
| Lloyd Pique | fc12f56 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 655 |  | 
|  | 656 | /* ------------------------------------------------------------------------ | 
| Lloyd Pique | 6cf1103 | 2018-01-22 18:57:44 -0800 | [diff] [blame] | 657 | * | 
|  | 658 | * SurfaceFlinger::onHotplugReceived | 
|  | 659 | */ | 
|  | 660 |  | 
|  | 661 | TEST_F(DisplayTransactionTest, hotplugEnqueuesEventsForDisplayTransaction) { | 
|  | 662 | constexpr int currentSequenceId = 123; | 
|  | 663 | constexpr hwc2_display_t displayId1 = 456; | 
|  | 664 | constexpr hwc2_display_t displayId2 = 654; | 
|  | 665 |  | 
|  | 666 | // -------------------------------------------------------------------- | 
|  | 667 | // Preconditions | 
|  | 668 |  | 
|  | 669 | // Set the current sequence id for accepted events | 
|  | 670 | mFlinger.mutableComposerSequenceId() = currentSequenceId; | 
|  | 671 |  | 
|  | 672 | // Set the main thread id so that the current thread does not appear to be | 
|  | 673 | // the main thread. | 
|  | 674 | mFlinger.mutableMainThreadId() = std::thread::id(); | 
|  | 675 |  | 
|  | 676 | // -------------------------------------------------------------------- | 
|  | 677 | // Call Expectations | 
|  | 678 |  | 
|  | 679 | // We expect invalidate() to be invoked once to trigger display transaction | 
|  | 680 | // processing. | 
|  | 681 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); | 
|  | 682 |  | 
|  | 683 | // -------------------------------------------------------------------- | 
|  | 684 | // Invocation | 
|  | 685 |  | 
|  | 686 | // Simulate two hotplug events (a connect and a disconnect) | 
|  | 687 | mFlinger.onHotplugReceived(currentSequenceId, displayId1, HWC2::Connection::Connected); | 
|  | 688 | mFlinger.onHotplugReceived(currentSequenceId, displayId2, HWC2::Connection::Disconnected); | 
|  | 689 |  | 
|  | 690 | // -------------------------------------------------------------------- | 
|  | 691 | // Postconditions | 
|  | 692 |  | 
|  | 693 | // The display transaction needed flag should be set. | 
|  | 694 | EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded)); | 
|  | 695 |  | 
|  | 696 | // All events should be in the pending event queue. | 
|  | 697 | const auto& pendingEvents = mFlinger.mutablePendingHotplugEvents(); | 
|  | 698 | ASSERT_EQ(2u, pendingEvents.size()); | 
|  | 699 | EXPECT_EQ(displayId1, pendingEvents[0].display); | 
|  | 700 | EXPECT_EQ(HWC2::Connection::Connected, pendingEvents[0].connection); | 
|  | 701 | EXPECT_EQ(displayId2, pendingEvents[1].display); | 
|  | 702 | EXPECT_EQ(HWC2::Connection::Disconnected, pendingEvents[1].connection); | 
|  | 703 | } | 
|  | 704 |  | 
|  | 705 | TEST_F(DisplayTransactionTest, hotplugDiscardsUnexpectedEvents) { | 
|  | 706 | constexpr int currentSequenceId = 123; | 
|  | 707 | constexpr int otherSequenceId = 321; | 
|  | 708 | constexpr hwc2_display_t displayId = 456; | 
|  | 709 |  | 
|  | 710 | // -------------------------------------------------------------------- | 
|  | 711 | // Preconditions | 
|  | 712 |  | 
|  | 713 | // Set the current sequence id for accepted events | 
|  | 714 | mFlinger.mutableComposerSequenceId() = currentSequenceId; | 
|  | 715 |  | 
|  | 716 | // Set the main thread id so that the current thread does not appear to be | 
|  | 717 | // the main thread. | 
|  | 718 | mFlinger.mutableMainThreadId() = std::thread::id(); | 
|  | 719 |  | 
|  | 720 | // -------------------------------------------------------------------- | 
|  | 721 | // Call Expectations | 
|  | 722 |  | 
|  | 723 | // We do not expect any calls to invalidate(). | 
|  | 724 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(0); | 
|  | 725 |  | 
|  | 726 | // -------------------------------------------------------------------- | 
|  | 727 | // Invocation | 
|  | 728 |  | 
|  | 729 | // Call with an unexpected sequence id | 
|  | 730 | mFlinger.onHotplugReceived(otherSequenceId, displayId, HWC2::Connection::Invalid); | 
|  | 731 |  | 
|  | 732 | // -------------------------------------------------------------------- | 
|  | 733 | // Postconditions | 
|  | 734 |  | 
|  | 735 | // The display transaction needed flag should not be set | 
|  | 736 | EXPECT_FALSE(hasTransactionFlagSet(eDisplayTransactionNeeded)); | 
|  | 737 |  | 
|  | 738 | // There should be no pending events | 
|  | 739 | EXPECT_TRUE(mFlinger.mutablePendingHotplugEvents().empty()); | 
|  | 740 | } | 
|  | 741 |  | 
|  | 742 | TEST_F(DisplayTransactionTest, hotplugProcessesEnqueuedEventsIfCalledOnMainThread) { | 
|  | 743 | constexpr int currentSequenceId = 123; | 
|  | 744 | constexpr hwc2_display_t displayId1 = 456; | 
|  | 745 |  | 
|  | 746 | // -------------------------------------------------------------------- | 
|  | 747 | // Note: | 
|  | 748 | // -------------------------------------------------------------------- | 
|  | 749 | // This test case is a bit tricky. We want to verify that | 
|  | 750 | // onHotplugReceived() calls processDisplayHotplugEventsLocked(), but we | 
|  | 751 | // don't really want to provide coverage for everything the later function | 
|  | 752 | // does as there are specific tests for it. | 
|  | 753 | // -------------------------------------------------------------------- | 
|  | 754 |  | 
|  | 755 | // -------------------------------------------------------------------- | 
|  | 756 | // Preconditions | 
|  | 757 |  | 
|  | 758 | // Set the current sequence id for accepted events | 
|  | 759 | mFlinger.mutableComposerSequenceId() = currentSequenceId; | 
|  | 760 |  | 
|  | 761 | // Set the main thread id so that the current thread does appear to be the | 
|  | 762 | // main thread. | 
|  | 763 | mFlinger.mutableMainThreadId() = std::this_thread::get_id(); | 
|  | 764 |  | 
|  | 765 | // -------------------------------------------------------------------- | 
|  | 766 | // Call Expectations | 
|  | 767 |  | 
|  | 768 | // We expect invalidate() to be invoked once to trigger display transaction | 
|  | 769 | // processing. | 
|  | 770 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); | 
|  | 771 |  | 
|  | 772 | // -------------------------------------------------------------------- | 
|  | 773 | // Invocation | 
|  | 774 |  | 
|  | 775 | // Simulate a disconnect on a display id that is not connected. This should | 
|  | 776 | // be enqueued by onHotplugReceived(), and dequeued by | 
|  | 777 | // processDisplayHotplugEventsLocked(), but then ignored as invalid. | 
|  | 778 | mFlinger.onHotplugReceived(currentSequenceId, displayId1, HWC2::Connection::Disconnected); | 
|  | 779 |  | 
|  | 780 | // -------------------------------------------------------------------- | 
|  | 781 | // Postconditions | 
|  | 782 |  | 
|  | 783 | // The display transaction needed flag should be set. | 
|  | 784 | EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded)); | 
|  | 785 |  | 
|  | 786 | // There should be no event queued on return, as it should have been | 
|  | 787 | // processed. | 
|  | 788 | EXPECT_TRUE(mFlinger.mutablePendingHotplugEvents().empty()); | 
|  | 789 | } | 
|  | 790 |  | 
|  | 791 | /* ------------------------------------------------------------------------ | 
| Lloyd Pique | a482f99 | 2018-01-22 19:00:34 -0800 | [diff] [blame] | 792 | * SurfaceFlinger::createDisplay | 
|  | 793 | */ | 
|  | 794 |  | 
|  | 795 | TEST_F(DisplayTransactionTest, createDisplaySetsCurrentStateForNonsecureDisplay) { | 
|  | 796 | const String8 name("virtual.test"); | 
|  | 797 |  | 
|  | 798 | // -------------------------------------------------------------------- | 
|  | 799 | // Call Expectations | 
|  | 800 |  | 
|  | 801 | // The call should notify the interceptor that a display was created. | 
|  | 802 | EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1); | 
|  | 803 |  | 
|  | 804 | // -------------------------------------------------------------------- | 
|  | 805 | // Invocation | 
|  | 806 |  | 
|  | 807 | sp<IBinder> displayToken = mFlinger.createDisplay(name, false); | 
|  | 808 |  | 
|  | 809 | // -------------------------------------------------------------------- | 
|  | 810 | // Postconditions | 
|  | 811 |  | 
|  | 812 | // The display should have been added to the current state | 
|  | 813 | ASSERT_TRUE(hasCurrentDisplayState(displayToken)); | 
|  | 814 | const auto& display = getCurrentDisplayState(displayToken); | 
|  | 815 | EXPECT_EQ(DisplayDevice::DISPLAY_VIRTUAL, display.type); | 
|  | 816 | EXPECT_EQ(false, display.isSecure); | 
|  | 817 | EXPECT_EQ(name.string(), display.displayName); | 
|  | 818 |  | 
|  | 819 | // -------------------------------------------------------------------- | 
|  | 820 | // Cleanup conditions | 
|  | 821 |  | 
|  | 822 | // Destroying the display invalidates the display state. | 
|  | 823 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); | 
|  | 824 | } | 
|  | 825 |  | 
|  | 826 | TEST_F(DisplayTransactionTest, createDisplaySetsCurrentStateForSecureDisplay) { | 
|  | 827 | const String8 name("virtual.test"); | 
|  | 828 |  | 
|  | 829 | // -------------------------------------------------------------------- | 
|  | 830 | // Call Expectations | 
|  | 831 |  | 
|  | 832 | // The call should notify the interceptor that a display was created. | 
|  | 833 | EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1); | 
|  | 834 |  | 
|  | 835 | // -------------------------------------------------------------------- | 
|  | 836 | // Invocation | 
|  | 837 |  | 
|  | 838 | sp<IBinder> displayToken = mFlinger.createDisplay(name, true); | 
|  | 839 |  | 
|  | 840 | // -------------------------------------------------------------------- | 
|  | 841 | // Postconditions | 
|  | 842 |  | 
|  | 843 | // The display should have been added to the current state | 
|  | 844 | ASSERT_TRUE(hasCurrentDisplayState(displayToken)); | 
|  | 845 | const auto& display = getCurrentDisplayState(displayToken); | 
|  | 846 | EXPECT_EQ(DisplayDevice::DISPLAY_VIRTUAL, display.type); | 
|  | 847 | EXPECT_EQ(true, display.isSecure); | 
|  | 848 | EXPECT_EQ(name.string(), display.displayName); | 
|  | 849 |  | 
|  | 850 | // -------------------------------------------------------------------- | 
|  | 851 | // Cleanup conditions | 
|  | 852 |  | 
|  | 853 | // Destroying the display invalidates the display state. | 
|  | 854 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); | 
|  | 855 | } | 
|  | 856 |  | 
|  | 857 | /* ------------------------------------------------------------------------ | 
|  | 858 | * SurfaceFlinger::destroyDisplay | 
|  | 859 | */ | 
|  | 860 |  | 
|  | 861 | TEST_F(DisplayTransactionTest, destroyDisplayClearsCurrentStateForDisplay) { | 
|  | 862 | using Case = NonHwcVirtualDisplayCase; | 
|  | 863 |  | 
|  | 864 | // -------------------------------------------------------------------- | 
|  | 865 | // Preconditions | 
|  | 866 |  | 
|  | 867 | // A virtual display exists | 
|  | 868 | auto existing = Case::Display::makeFakeExistingDisplayInjector(this); | 
|  | 869 | existing.inject(); | 
|  | 870 |  | 
|  | 871 | // -------------------------------------------------------------------- | 
|  | 872 | // Call Expectations | 
|  | 873 |  | 
|  | 874 | // The call should notify the interceptor that a display was created. | 
|  | 875 | EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1); | 
|  | 876 |  | 
|  | 877 | // Destroying the display invalidates the display state. | 
|  | 878 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); | 
|  | 879 |  | 
|  | 880 | // -------------------------------------------------------------------- | 
|  | 881 | // Invocation | 
|  | 882 |  | 
|  | 883 | mFlinger.destroyDisplay(existing.token()); | 
|  | 884 |  | 
|  | 885 | // -------------------------------------------------------------------- | 
|  | 886 | // Postconditions | 
|  | 887 |  | 
|  | 888 | // The display should have been removed from the current state | 
|  | 889 | EXPECT_FALSE(hasCurrentDisplayState(existing.token())); | 
|  | 890 |  | 
|  | 891 | // Ths display should still exist in the drawing state | 
|  | 892 | EXPECT_TRUE(hasDrawingDisplayState(existing.token())); | 
|  | 893 |  | 
|  | 894 | // The display transaction needed flasg should be set | 
|  | 895 | EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded)); | 
|  | 896 | } | 
|  | 897 |  | 
|  | 898 | TEST_F(DisplayTransactionTest, destroyDisplayHandlesUnknownDisplay) { | 
|  | 899 | // -------------------------------------------------------------------- | 
|  | 900 | // Preconditions | 
|  | 901 |  | 
|  | 902 | sp<BBinder> displayToken = new BBinder(); | 
|  | 903 |  | 
|  | 904 | // -------------------------------------------------------------------- | 
|  | 905 | // Invocation | 
|  | 906 |  | 
|  | 907 | mFlinger.destroyDisplay(displayToken); | 
|  | 908 | } | 
|  | 909 |  | 
|  | 910 | /* ------------------------------------------------------------------------ | 
| Lloyd Pique | d6fbb8a | 2018-01-22 19:08:36 -0800 | [diff] [blame] | 911 | * SurfaceFlinger::resetDisplayState | 
|  | 912 | */ | 
|  | 913 |  | 
|  | 914 | TEST_F(DisplayTransactionTest, resetDisplayStateClearsState) { | 
|  | 915 | using Case = NonHwcVirtualDisplayCase; | 
|  | 916 |  | 
|  | 917 | // -------------------------------------------------------------------- | 
|  | 918 | // Preconditions | 
|  | 919 |  | 
|  | 920 | // vsync is enabled and available | 
|  | 921 | mFlinger.mutablePrimaryHWVsyncEnabled() = true; | 
|  | 922 | mFlinger.mutableHWVsyncAvailable() = true; | 
|  | 923 |  | 
|  | 924 | // A display exists | 
|  | 925 | auto existing = Case::Display::makeFakeExistingDisplayInjector(this); | 
|  | 926 | existing.inject(); | 
|  | 927 |  | 
|  | 928 | // -------------------------------------------------------------------- | 
|  | 929 | // Call Expectations | 
|  | 930 |  | 
|  | 931 | // The call disable vsyncs | 
|  | 932 | EXPECT_CALL(*mEventControlThread, setVsyncEnabled(false)).Times(1); | 
|  | 933 |  | 
|  | 934 | // The call clears the current render engine surface | 
|  | 935 | EXPECT_CALL(*mRenderEngine, resetCurrentSurface()); | 
|  | 936 |  | 
|  | 937 | // -------------------------------------------------------------------- | 
|  | 938 | // Invocation | 
|  | 939 |  | 
|  | 940 | mFlinger.resetDisplayState(); | 
|  | 941 |  | 
|  | 942 | // -------------------------------------------------------------------- | 
|  | 943 | // Postconditions | 
|  | 944 |  | 
|  | 945 | // vsyncs should be off and not available. | 
|  | 946 | EXPECT_FALSE(mFlinger.mutablePrimaryHWVsyncEnabled()); | 
|  | 947 | EXPECT_FALSE(mFlinger.mutableHWVsyncAvailable()); | 
|  | 948 |  | 
|  | 949 | // The display should have been removed from the display map. | 
|  | 950 | EXPECT_FALSE(hasDisplayDevice(existing.token())); | 
|  | 951 |  | 
|  | 952 | // The display should still exist in the current state | 
|  | 953 | EXPECT_TRUE(hasCurrentDisplayState(existing.token())); | 
|  | 954 |  | 
|  | 955 | // The display should have been removed from the drawing state | 
|  | 956 | EXPECT_FALSE(hasDrawingDisplayState(existing.token())); | 
|  | 957 | } | 
|  | 958 |  | 
|  | 959 | /* ------------------------------------------------------------------------ | 
| Lloyd Pique | fc12f56 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 960 | * SurfaceFlinger::setupNewDisplayDeviceInternal | 
|  | 961 | */ | 
|  | 962 |  | 
|  | 963 | class SetupNewDisplayDeviceInternalTest : public DisplayTransactionTest { | 
|  | 964 | public: | 
|  | 965 | template <typename T> | 
|  | 966 | void setupNewDisplayDeviceInternalTest(); | 
|  | 967 | }; | 
|  | 968 |  | 
|  | 969 | template <typename Case> | 
|  | 970 | void SetupNewDisplayDeviceInternalTest::setupNewDisplayDeviceInternalTest() { | 
|  | 971 | const sp<BBinder> displayToken = new BBinder(); | 
|  | 972 | const sp<mock::DisplaySurface> displaySurface = new mock::DisplaySurface(); | 
|  | 973 | const sp<mock::GraphicBufferProducer> producer = new mock::GraphicBufferProducer(); | 
| Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 974 |  | 
|  | 975 | // -------------------------------------------------------------------- | 
|  | 976 | // Preconditions | 
|  | 977 |  | 
| Lloyd Pique | fc12f56 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 978 | // Wide color displays support is configured appropriately | 
|  | 979 | Case::WideColorSupport::injectConfigChange(this); | 
| Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 980 |  | 
| Lloyd Pique | fc12f56 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 981 | // The display is setup with the HWC. | 
|  | 982 | Case::Display::injectHwcDisplay(this); | 
|  | 983 |  | 
|  | 984 | // SurfaceFlinger will use a test-controlled factory for native window | 
|  | 985 | // surfaces. | 
|  | 986 | injectFakeNativeWindowSurfaceFactory(); | 
|  | 987 |  | 
|  | 988 | // -------------------------------------------------------------------- | 
|  | 989 | // Call Expectations | 
|  | 990 |  | 
|  | 991 | // Various native window calls will be made. | 
|  | 992 | Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this); | 
|  | 993 |  | 
|  | 994 | // TODO(b/69807179): SurfaceFlinger does not correctly get the active config. | 
|  | 995 | // Case::Display::setupHwcGetActiveConfigCallExpectations(this) | 
|  | 996 |  | 
|  | 997 | Case::WideColorSupport::setupComposerCallExpectations(this); | 
|  | 998 | Case::HdrSupport::setupComposerCallExpectations(this); | 
|  | 999 |  | 
|  | 1000 | // -------------------------------------------------------------------- | 
|  | 1001 | // Invocation | 
|  | 1002 |  | 
|  | 1003 | auto state = DisplayDeviceState(Case::Display::TYPE, static_cast<bool>(Case::Display::SECURE)); | 
|  | 1004 | auto device = mFlinger.setupNewDisplayDeviceInternal(displayToken, Case::Display::TYPE, state, | 
|  | 1005 | displaySurface, producer); | 
|  | 1006 |  | 
|  | 1007 | // -------------------------------------------------------------------- | 
|  | 1008 | // Postconditions | 
|  | 1009 |  | 
|  | 1010 | ASSERT_TRUE(device != nullptr); | 
|  | 1011 | EXPECT_EQ(Case::Display::TYPE, device->getDisplayType()); | 
|  | 1012 | EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure()); | 
|  | 1013 | EXPECT_EQ(Case::Display::WIDTH, device->getWidth()); | 
|  | 1014 | EXPECT_EQ(Case::Display::HEIGHT, device->getHeight()); | 
|  | 1015 | EXPECT_EQ(Case::WideColorSupport::WIDE_COLOR_SUPPORTED, device->hasWideColorGamut()); | 
|  | 1016 | EXPECT_EQ(Case::HdrSupport::HDR10_SUPPORTED, device->hasHDR10Support()); | 
|  | 1017 | EXPECT_EQ(Case::HdrSupport::HDR_HLG_SUPPORTED, device->hasHLGSupport()); | 
|  | 1018 | EXPECT_EQ(Case::HdrSupport::HDR_DOLBY_VISION_SUPPORTED, device->hasDolbyVisionSupport()); | 
|  | 1019 | EXPECT_EQ(Case::Display::HWC_ACTIVE_CONFIG_ID, device->getActiveConfig()); | 
|  | 1020 | } | 
|  | 1021 |  | 
|  | 1022 | TEST_F(SetupNewDisplayDeviceInternalTest, createSimplePrimaryDisplay) { | 
|  | 1023 | setupNewDisplayDeviceInternalTest<SimplePrimaryDisplayCase>(); | 
|  | 1024 | } | 
|  | 1025 |  | 
|  | 1026 | TEST_F(SetupNewDisplayDeviceInternalTest, createSimpleExternalDisplay) { | 
|  | 1027 | setupNewDisplayDeviceInternalTest<SimpleExternalDisplayCase>(); | 
|  | 1028 | } | 
|  | 1029 |  | 
|  | 1030 | TEST_F(SetupNewDisplayDeviceInternalTest, createNonHwcVirtualDisplay) { | 
|  | 1031 | setupNewDisplayDeviceInternalTest<NonHwcVirtualDisplayCase>(); | 
|  | 1032 | } | 
|  | 1033 |  | 
|  | 1034 | TEST_F(SetupNewDisplayDeviceInternalTest, createHwcVirtualDisplay) { | 
|  | 1035 | // We need to resize this so that the HWC thinks the virtual display | 
|  | 1036 | // is something it created. | 
|  | 1037 | mFlinger.mutableHwcDisplayData().resize(3); | 
|  | 1038 |  | 
|  | 1039 | setupNewDisplayDeviceInternalTest<HwcVirtualDisplayCase>(); | 
|  | 1040 | } | 
|  | 1041 |  | 
|  | 1042 | TEST_F(SetupNewDisplayDeviceInternalTest, createWideColorP3Display) { | 
|  | 1043 | setupNewDisplayDeviceInternalTest<WideColorP3ColorimetricDisplayCase>(); | 
|  | 1044 | } | 
|  | 1045 |  | 
|  | 1046 | TEST_F(SetupNewDisplayDeviceInternalTest, createWideColorP3EnhanceDisplay) { | 
|  | 1047 | setupNewDisplayDeviceInternalTest<WideColorP3EnhanceDisplayCase>(); | 
|  | 1048 | } | 
|  | 1049 |  | 
|  | 1050 | TEST_F(SetupNewDisplayDeviceInternalTest, createHdr10Display) { | 
|  | 1051 | setupNewDisplayDeviceInternalTest<Hdr10DisplayCase>(); | 
|  | 1052 | } | 
|  | 1053 |  | 
|  | 1054 | TEST_F(SetupNewDisplayDeviceInternalTest, createHdrHlgDisplay) { | 
|  | 1055 | setupNewDisplayDeviceInternalTest<HdrHlgDisplayCase>(); | 
|  | 1056 | } | 
|  | 1057 |  | 
|  | 1058 | TEST_F(SetupNewDisplayDeviceInternalTest, createHdrDolbyVisionDisplay) { | 
|  | 1059 | setupNewDisplayDeviceInternalTest<HdrDolbyVisionDisplayCase>(); | 
|  | 1060 | } | 
|  | 1061 |  | 
|  | 1062 | /* ------------------------------------------------------------------------ | 
|  | 1063 | * SurfaceFlinger::handleTransactionLocked(eDisplayTransactionNeeded) | 
|  | 1064 | */ | 
|  | 1065 |  | 
|  | 1066 | class HandleTransactionLockedTest : public DisplayTransactionTest { | 
|  | 1067 | public: | 
|  | 1068 | template <typename Case> | 
|  | 1069 | void setupCommonPreconditions(); | 
|  | 1070 |  | 
|  | 1071 | template <typename Case> | 
|  | 1072 | void setupCommonCallExpectationsForConnectProcessing(); | 
|  | 1073 |  | 
|  | 1074 | template <typename Case> | 
|  | 1075 | void setupCommonCallExpectationsForDisconnectProcessing(); | 
|  | 1076 |  | 
|  | 1077 | template <typename Case> | 
|  | 1078 | void processesHotplugConnectCommon(); | 
|  | 1079 |  | 
|  | 1080 | template <typename Case> | 
|  | 1081 | void ignoresHotplugConnectCommon(); | 
|  | 1082 |  | 
|  | 1083 | template <typename Case> | 
|  | 1084 | void processesHotplugDisconnectCommon(); | 
|  | 1085 |  | 
|  | 1086 | template <typename Case> | 
|  | 1087 | void verifyDisplayIsConnected(const sp<IBinder>& displayToken); | 
|  | 1088 |  | 
|  | 1089 | template <typename Case> | 
|  | 1090 | void verifyPhysicalDisplayIsConnected(); | 
|  | 1091 |  | 
|  | 1092 | void verifyDisplayIsNotConnected(const sp<IBinder>& displayToken); | 
|  | 1093 | }; | 
|  | 1094 |  | 
|  | 1095 | template <typename Case> | 
|  | 1096 | void HandleTransactionLockedTest::setupCommonPreconditions() { | 
|  | 1097 | // Wide color displays support is configured appropriately | 
|  | 1098 | Case::WideColorSupport::injectConfigChange(this); | 
|  | 1099 |  | 
|  | 1100 | // SurfaceFlinger will use a test-controlled factory for BufferQueues | 
|  | 1101 | injectFakeBufferQueueFactory(); | 
|  | 1102 |  | 
|  | 1103 | // SurfaceFlinger will use a test-controlled factory for native window | 
|  | 1104 | // surfaces. | 
|  | 1105 | injectFakeNativeWindowSurfaceFactory(); | 
|  | 1106 | } | 
|  | 1107 |  | 
|  | 1108 | template <typename Case> | 
|  | 1109 | void HandleTransactionLockedTest::setupCommonCallExpectationsForConnectProcessing() { | 
|  | 1110 | Case::Display::setupHwcHotplugCallExpectations(this); | 
|  | 1111 |  | 
|  | 1112 | Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this); | 
|  | 1113 | Case::Display::setupFramebufferProducerBufferQueueCallExpectations(this); | 
|  | 1114 | Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this); | 
|  | 1115 | Case::Display::setupHwcGetActiveConfigCallExpectations(this); | 
|  | 1116 |  | 
|  | 1117 | Case::WideColorSupport::setupComposerCallExpectations(this); | 
|  | 1118 | Case::HdrSupport::setupComposerCallExpectations(this); | 
|  | 1119 |  | 
|  | 1120 | EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1); | 
|  | 1121 | EXPECT_CALL(*mEventThread, onHotplugReceived(Case::Display::TYPE, true)).Times(1); | 
|  | 1122 | } | 
|  | 1123 |  | 
|  | 1124 | template <typename Case> | 
|  | 1125 | void HandleTransactionLockedTest::setupCommonCallExpectationsForDisconnectProcessing() { | 
|  | 1126 | EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1); | 
|  | 1127 | EXPECT_CALL(*mEventThread, onHotplugReceived(Case::Display::TYPE, false)).Times(1); | 
|  | 1128 | } | 
|  | 1129 |  | 
|  | 1130 | template <typename Case> | 
|  | 1131 | void HandleTransactionLockedTest::verifyDisplayIsConnected(const sp<IBinder>& displayToken) { | 
|  | 1132 | // The display device should have been set up in the list of displays. | 
|  | 1133 | ASSERT_TRUE(hasDisplayDevice(displayToken)); | 
|  | 1134 | const auto& device = getDisplayDevice(displayToken); | 
|  | 1135 | EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure()); | 
|  | 1136 | EXPECT_EQ(Case::Display::TYPE == DisplayDevice::DISPLAY_PRIMARY, device->isPrimary()); | 
|  | 1137 |  | 
|  | 1138 | // The display should have been set up in the current display state | 
|  | 1139 | ASSERT_TRUE(hasCurrentDisplayState(displayToken)); | 
|  | 1140 | const auto& current = getCurrentDisplayState(displayToken); | 
|  | 1141 | EXPECT_EQ(Case::Display::TYPE, current.type); | 
|  | 1142 |  | 
|  | 1143 | // The display should have been set up in the drawing display state | 
|  | 1144 | ASSERT_TRUE(hasDrawingDisplayState(displayToken)); | 
|  | 1145 | const auto& draw = getDrawingDisplayState(displayToken); | 
|  | 1146 | EXPECT_EQ(Case::Display::TYPE, draw.type); | 
|  | 1147 | } | 
|  | 1148 |  | 
|  | 1149 | template <typename Case> | 
|  | 1150 | void HandleTransactionLockedTest::verifyPhysicalDisplayIsConnected() { | 
|  | 1151 | // HWComposer should have an entry for the display | 
|  | 1152 | EXPECT_TRUE(hasHwcDisplay(Case::Display::HWC_DISPLAY_ID)); | 
|  | 1153 |  | 
|  | 1154 | // The display should be set up as a built-in display. | 
|  | 1155 | static_assert(0 <= Case::Display::TYPE && | 
|  | 1156 | Case::Display::TYPE < DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES, | 
|  | 1157 | "Must use a valid physical display type index for the fixed-size array"); | 
|  | 1158 | auto& displayToken = mFlinger.mutableBuiltinDisplays()[Case::Display::TYPE]; | 
|  | 1159 | ASSERT_TRUE(displayToken != nullptr); | 
|  | 1160 |  | 
|  | 1161 | verifyDisplayIsConnected<Case>(displayToken); | 
|  | 1162 | } | 
|  | 1163 |  | 
|  | 1164 | void HandleTransactionLockedTest::verifyDisplayIsNotConnected(const sp<IBinder>& displayToken) { | 
|  | 1165 | EXPECT_FALSE(hasDisplayDevice(displayToken)); | 
|  | 1166 | EXPECT_FALSE(hasCurrentDisplayState(displayToken)); | 
|  | 1167 | EXPECT_FALSE(hasDrawingDisplayState(displayToken)); | 
|  | 1168 | } | 
|  | 1169 |  | 
|  | 1170 | template <typename Case> | 
|  | 1171 | void HandleTransactionLockedTest::processesHotplugConnectCommon() { | 
|  | 1172 | // -------------------------------------------------------------------- | 
|  | 1173 | // Preconditions | 
|  | 1174 |  | 
|  | 1175 | setupCommonPreconditions<Case>(); | 
|  | 1176 |  | 
|  | 1177 | // A hotplug connect event is enqueued for a display | 
|  | 1178 | Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected); | 
| Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 1179 |  | 
|  | 1180 | // -------------------------------------------------------------------- | 
|  | 1181 | // Call Expectations | 
|  | 1182 |  | 
|  | 1183 | EXPECT_CALL(*mComposer, isUsingVrComposer()).WillOnce(Return(false)); | 
| Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 1184 |  | 
| Lloyd Pique | fc12f56 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1185 | setupCommonCallExpectationsForConnectProcessing<Case>(); | 
| Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 1186 |  | 
| Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 1187 | // -------------------------------------------------------------------- | 
|  | 1188 | // Invocation | 
| Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 1189 |  | 
| Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 1190 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); | 
| Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 1191 |  | 
| Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 1192 | // -------------------------------------------------------------------- | 
|  | 1193 | // Postconditions | 
|  | 1194 |  | 
| Lloyd Pique | fc12f56 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1195 | verifyPhysicalDisplayIsConnected<Case>(); | 
| Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 1196 |  | 
| Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 1197 | // -------------------------------------------------------------------- | 
|  | 1198 | // Cleanup conditions | 
|  | 1199 |  | 
| Lloyd Pique | fc12f56 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1200 | EXPECT_CALL(*mComposer, | 
|  | 1201 | setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE)) | 
| Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 1202 | .WillOnce(Return(Error::NONE)); | 
|  | 1203 | EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR)); | 
| Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 1204 | } | 
|  | 1205 |  | 
| Lloyd Pique | fc12f56 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1206 | template <typename Case> | 
|  | 1207 | void HandleTransactionLockedTest::ignoresHotplugConnectCommon() { | 
|  | 1208 | // -------------------------------------------------------------------- | 
|  | 1209 | // Preconditions | 
|  | 1210 |  | 
|  | 1211 | setupCommonPreconditions<Case>(); | 
|  | 1212 |  | 
|  | 1213 | // A hotplug connect event is enqueued for a display | 
|  | 1214 | Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected); | 
|  | 1215 |  | 
|  | 1216 | // -------------------------------------------------------------------- | 
|  | 1217 | // Invocation | 
|  | 1218 |  | 
|  | 1219 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); | 
|  | 1220 |  | 
|  | 1221 | // -------------------------------------------------------------------- | 
|  | 1222 | // Postconditions | 
|  | 1223 |  | 
|  | 1224 | // HWComposer should not have an entry for the display | 
|  | 1225 | EXPECT_FALSE(hasHwcDisplay(Case::Display::HWC_DISPLAY_ID)); | 
|  | 1226 | } | 
|  | 1227 |  | 
|  | 1228 | template <typename Case> | 
|  | 1229 | void HandleTransactionLockedTest::processesHotplugDisconnectCommon() { | 
|  | 1230 | // -------------------------------------------------------------------- | 
|  | 1231 | // Preconditions | 
|  | 1232 |  | 
|  | 1233 | setupCommonPreconditions<Case>(); | 
|  | 1234 |  | 
|  | 1235 | // A hotplug disconnect event is enqueued for a display | 
|  | 1236 | Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected); | 
|  | 1237 |  | 
|  | 1238 | // The display is already completely set up. | 
|  | 1239 | Case::Display::injectHwcDisplay(this); | 
|  | 1240 | auto existing = Case::Display::makeFakeExistingDisplayInjector(this); | 
|  | 1241 | existing.inject(); | 
|  | 1242 |  | 
|  | 1243 | // -------------------------------------------------------------------- | 
|  | 1244 | // Call Expectations | 
|  | 1245 |  | 
|  | 1246 | EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false)); | 
|  | 1247 |  | 
|  | 1248 | setupCommonCallExpectationsForDisconnectProcessing<Case>(); | 
|  | 1249 |  | 
|  | 1250 | // -------------------------------------------------------------------- | 
|  | 1251 | // Invocation | 
|  | 1252 |  | 
|  | 1253 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); | 
|  | 1254 |  | 
|  | 1255 | // -------------------------------------------------------------------- | 
|  | 1256 | // Postconditions | 
|  | 1257 |  | 
|  | 1258 | // HWComposer should not have an entry for the display | 
|  | 1259 | EXPECT_FALSE(hasHwcDisplay(Case::Display::HWC_DISPLAY_ID)); | 
|  | 1260 |  | 
|  | 1261 | // The display should not be set up as a built-in display. | 
|  | 1262 | ASSERT_TRUE(0 <= Case::Display::TYPE && | 
|  | 1263 | Case::Display::TYPE < DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES); | 
|  | 1264 | auto displayToken = mFlinger.mutableBuiltinDisplays()[Case::Display::TYPE]; | 
|  | 1265 | EXPECT_TRUE(displayToken == nullptr); | 
|  | 1266 |  | 
|  | 1267 | // The existing token should have been removed | 
|  | 1268 | verifyDisplayIsNotConnected(existing.token()); | 
|  | 1269 | } | 
|  | 1270 |  | 
|  | 1271 | TEST_F(HandleTransactionLockedTest, processesHotplugConnectPrimaryDisplay) { | 
|  | 1272 | processesHotplugConnectCommon<SimplePrimaryDisplayCase>(); | 
|  | 1273 | } | 
|  | 1274 |  | 
|  | 1275 | TEST_F(HandleTransactionLockedTest, | 
|  | 1276 | processesHotplugConnectPrimaryDisplayWithExternalAlreadyConnected) { | 
|  | 1277 | // Inject an external display. | 
|  | 1278 | ExternalDisplayVariant::injectHwcDisplay(this); | 
|  | 1279 |  | 
|  | 1280 | processesHotplugConnectCommon<SimplePrimaryDisplayCase>(); | 
|  | 1281 | } | 
|  | 1282 |  | 
|  | 1283 | TEST_F(HandleTransactionLockedTest, processesHotplugConnectExternalDisplay) { | 
|  | 1284 | // Inject a primary display. | 
|  | 1285 | PrimaryDisplayVariant::injectHwcDisplay(this); | 
|  | 1286 |  | 
|  | 1287 | processesHotplugConnectCommon<SimpleExternalDisplayCase>(); | 
|  | 1288 | } | 
|  | 1289 |  | 
|  | 1290 | TEST_F(HandleTransactionLockedTest, ignoresHotplugConnectIfPrimaryAndExternalAlreadyConnected) { | 
|  | 1291 | // Inject both a primary and external display. | 
|  | 1292 | PrimaryDisplayVariant::injectHwcDisplay(this); | 
|  | 1293 | ExternalDisplayVariant::injectHwcDisplay(this); | 
|  | 1294 |  | 
|  | 1295 | EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false)); | 
|  | 1296 |  | 
|  | 1297 | ignoresHotplugConnectCommon<SimpleTertiaryDisplayCase>(); | 
|  | 1298 | } | 
|  | 1299 |  | 
|  | 1300 | TEST_F(HandleTransactionLockedTest, ignoresHotplugConnectIfExternalForVrComposer) { | 
|  | 1301 | // Inject a primary display. | 
|  | 1302 | PrimaryDisplayVariant::injectHwcDisplay(this); | 
|  | 1303 |  | 
|  | 1304 | EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(true)); | 
|  | 1305 |  | 
|  | 1306 | ignoresHotplugConnectCommon<SimpleExternalDisplayCase>(); | 
|  | 1307 | } | 
|  | 1308 |  | 
|  | 1309 | TEST_F(HandleTransactionLockedTest, processHotplugDisconnectPrimaryDisplay) { | 
|  | 1310 | processesHotplugDisconnectCommon<SimplePrimaryDisplayCase>(); | 
|  | 1311 | } | 
|  | 1312 |  | 
|  | 1313 | TEST_F(HandleTransactionLockedTest, processHotplugDisconnectExternalDisplay) { | 
|  | 1314 | processesHotplugDisconnectCommon<SimpleExternalDisplayCase>(); | 
|  | 1315 | } | 
|  | 1316 |  | 
|  | 1317 | TEST_F(HandleTransactionLockedTest, processesHotplugConnectThenDisconnectPrimary) { | 
|  | 1318 | using Case = SimplePrimaryDisplayCase; | 
|  | 1319 |  | 
|  | 1320 | // -------------------------------------------------------------------- | 
|  | 1321 | // Preconditions | 
|  | 1322 |  | 
|  | 1323 | setupCommonPreconditions<Case>(); | 
|  | 1324 |  | 
|  | 1325 | // A hotplug connect event is enqueued for a display | 
|  | 1326 | Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected); | 
|  | 1327 | // A hotplug disconnect event is also enqueued for the same display | 
|  | 1328 | Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected); | 
|  | 1329 |  | 
|  | 1330 | // -------------------------------------------------------------------- | 
|  | 1331 | // Call Expectations | 
|  | 1332 |  | 
|  | 1333 | EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false)); | 
|  | 1334 |  | 
|  | 1335 | setupCommonCallExpectationsForConnectProcessing<Case>(); | 
|  | 1336 | setupCommonCallExpectationsForDisconnectProcessing<Case>(); | 
|  | 1337 |  | 
|  | 1338 | EXPECT_CALL(*mComposer, | 
|  | 1339 | setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE)) | 
|  | 1340 | .WillOnce(Return(Error::NONE)); | 
|  | 1341 | EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR)); | 
|  | 1342 |  | 
|  | 1343 | // -------------------------------------------------------------------- | 
|  | 1344 | // Invocation | 
|  | 1345 |  | 
|  | 1346 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); | 
|  | 1347 |  | 
|  | 1348 | // -------------------------------------------------------------------- | 
|  | 1349 | // Postconditions | 
|  | 1350 |  | 
|  | 1351 | // HWComposer should not have an entry for the display | 
|  | 1352 | EXPECT_FALSE(hasHwcDisplay(Case::Display::HWC_DISPLAY_ID)); | 
|  | 1353 |  | 
|  | 1354 | // The display should not be set up as a primary built-in display. | 
|  | 1355 | ASSERT_TRUE(0 <= Case::Display::TYPE && | 
|  | 1356 | Case::Display::TYPE < DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES); | 
|  | 1357 | auto displayToken = mFlinger.mutableBuiltinDisplays()[Case::Display::TYPE]; | 
|  | 1358 | EXPECT_TRUE(displayToken == nullptr); | 
|  | 1359 | } | 
|  | 1360 |  | 
|  | 1361 | TEST_F(HandleTransactionLockedTest, processesHotplugDisconnectThenConnectPrimary) { | 
|  | 1362 | using Case = SimplePrimaryDisplayCase; | 
|  | 1363 |  | 
|  | 1364 | // -------------------------------------------------------------------- | 
|  | 1365 | // Preconditions | 
|  | 1366 |  | 
|  | 1367 | setupCommonPreconditions<Case>(); | 
|  | 1368 |  | 
|  | 1369 | // The display is already completely set up. | 
|  | 1370 | Case::Display::injectHwcDisplay(this); | 
|  | 1371 | auto existing = Case::Display::makeFakeExistingDisplayInjector(this); | 
|  | 1372 | existing.inject(); | 
|  | 1373 |  | 
|  | 1374 | // A hotplug disconnect event is enqueued for a display | 
|  | 1375 | Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected); | 
|  | 1376 | // A hotplug connect event is also enqueued for the same display | 
|  | 1377 | Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected); | 
|  | 1378 |  | 
|  | 1379 | // -------------------------------------------------------------------- | 
|  | 1380 | // Call Expectations | 
|  | 1381 |  | 
|  | 1382 | EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false)); | 
|  | 1383 |  | 
|  | 1384 | setupCommonCallExpectationsForConnectProcessing<Case>(); | 
|  | 1385 | setupCommonCallExpectationsForDisconnectProcessing<Case>(); | 
|  | 1386 |  | 
|  | 1387 | // -------------------------------------------------------------------- | 
|  | 1388 | // Invocation | 
|  | 1389 |  | 
|  | 1390 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); | 
|  | 1391 |  | 
|  | 1392 | // -------------------------------------------------------------------- | 
|  | 1393 | // Postconditions | 
|  | 1394 |  | 
|  | 1395 | // The existing token should have been removed | 
|  | 1396 | verifyDisplayIsNotConnected(existing.token()); | 
|  | 1397 | static_assert(0 <= Case::Display::TYPE && | 
|  | 1398 | Case::Display::TYPE < DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES, | 
|  | 1399 | "Display type must be a built-in display"); | 
|  | 1400 | EXPECT_NE(existing.token(), mFlinger.mutableBuiltinDisplays()[Case::Display::TYPE]); | 
|  | 1401 |  | 
|  | 1402 | // A new display should be connected in its place | 
|  | 1403 |  | 
|  | 1404 | verifyPhysicalDisplayIsConnected<Case>(); | 
|  | 1405 |  | 
|  | 1406 | // -------------------------------------------------------------------- | 
|  | 1407 | // Cleanup conditions | 
|  | 1408 |  | 
|  | 1409 | EXPECT_CALL(*mComposer, | 
|  | 1410 | setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE)) | 
|  | 1411 | .WillOnce(Return(Error::NONE)); | 
|  | 1412 | EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR)); | 
|  | 1413 | } | 
|  | 1414 |  | 
|  | 1415 | TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAdded) { | 
|  | 1416 | using Case = HwcVirtualDisplayCase; | 
|  | 1417 |  | 
|  | 1418 | // -------------------------------------------------------------------- | 
|  | 1419 | // Preconditions | 
|  | 1420 |  | 
|  | 1421 | // The HWC supports at least one virtual display | 
|  | 1422 | injectMockComposer(1); | 
|  | 1423 |  | 
|  | 1424 | setupCommonPreconditions<Case>(); | 
|  | 1425 |  | 
|  | 1426 | // A virtual display was added to the current state, and it has a | 
|  | 1427 | // surface(producer) | 
|  | 1428 | sp<BBinder> displayToken = new BBinder(); | 
|  | 1429 | DisplayDeviceState info(Case::Display::TYPE, static_cast<bool>(Case::Display::SECURE)); | 
|  | 1430 | sp<mock::GraphicBufferProducer> surface{new mock::GraphicBufferProducer()}; | 
|  | 1431 | info.surface = surface; | 
|  | 1432 | mFlinger.mutableCurrentState().displays.add(displayToken, info); | 
|  | 1433 |  | 
|  | 1434 | // -------------------------------------------------------------------- | 
|  | 1435 | // Call Expectations | 
|  | 1436 |  | 
|  | 1437 | Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this); | 
|  | 1438 | Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this); | 
|  | 1439 |  | 
|  | 1440 | EXPECT_CALL(*surface, query(NATIVE_WINDOW_WIDTH, _)) | 
|  | 1441 | .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::WIDTH), Return(NO_ERROR))); | 
|  | 1442 | EXPECT_CALL(*surface, query(NATIVE_WINDOW_HEIGHT, _)) | 
|  | 1443 | .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::HEIGHT), Return(NO_ERROR))); | 
|  | 1444 | EXPECT_CALL(*surface, query(NATIVE_WINDOW_FORMAT, _)) | 
|  | 1445 | .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_VIRTUAL_DISPLAY_SURFACE_FORMAT), | 
|  | 1446 | Return(NO_ERROR))); | 
|  | 1447 | EXPECT_CALL(*surface, query(NATIVE_WINDOW_CONSUMER_USAGE_BITS, _)) | 
|  | 1448 | .WillRepeatedly(DoAll(SetArgPointee<1>(0), Return(NO_ERROR))); | 
|  | 1449 |  | 
|  | 1450 | EXPECT_CALL(*surface, setAsyncMode(true)).Times(1); | 
|  | 1451 |  | 
|  | 1452 | EXPECT_CALL(*mProducer, connect(_, _, _, _)).Times(1); | 
|  | 1453 | EXPECT_CALL(*mProducer, disconnect(_, _)).Times(1); | 
|  | 1454 |  | 
|  | 1455 | Case::Display::setupHwcVirtualDisplayCreationCallExpectations(this); | 
|  | 1456 | Case::WideColorSupport::setupComposerCallExpectations(this); | 
|  | 1457 | Case::HdrSupport::setupComposerCallExpectations(this); | 
|  | 1458 |  | 
|  | 1459 | // -------------------------------------------------------------------- | 
|  | 1460 | // Invocation | 
|  | 1461 |  | 
|  | 1462 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); | 
|  | 1463 |  | 
|  | 1464 | // -------------------------------------------------------------------- | 
|  | 1465 | // Postconditions | 
|  | 1466 |  | 
|  | 1467 | // The display device should have been set up in the list of displays. | 
|  | 1468 | verifyDisplayIsConnected<Case>(displayToken); | 
|  | 1469 |  | 
|  | 1470 | // -------------------------------------------------------------------- | 
|  | 1471 | // Cleanup conditions | 
|  | 1472 |  | 
|  | 1473 | EXPECT_CALL(*mComposer, destroyVirtualDisplay(Case::Display::HWC_DISPLAY_ID)) | 
|  | 1474 | .WillOnce(Return(Error::NONE)); | 
|  | 1475 | EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR)); | 
|  | 1476 | } | 
|  | 1477 |  | 
|  | 1478 | TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAddedWithNoSurface) { | 
|  | 1479 | using Case = HwcVirtualDisplayCase; | 
|  | 1480 |  | 
|  | 1481 | // -------------------------------------------------------------------- | 
|  | 1482 | // Preconditions | 
|  | 1483 |  | 
|  | 1484 | // The HWC supports at least one virtual display | 
|  | 1485 | injectMockComposer(1); | 
|  | 1486 |  | 
|  | 1487 | setupCommonPreconditions<Case>(); | 
|  | 1488 |  | 
|  | 1489 | // A virtual display was added to the current state, but it does not have a | 
|  | 1490 | // surface. | 
|  | 1491 | sp<BBinder> displayToken = new BBinder(); | 
|  | 1492 | DisplayDeviceState info(Case::Display::TYPE, static_cast<bool>(Case::Display::SECURE)); | 
|  | 1493 | mFlinger.mutableCurrentState().displays.add(displayToken, info); | 
|  | 1494 |  | 
|  | 1495 | // -------------------------------------------------------------------- | 
|  | 1496 | // Call Expectations | 
|  | 1497 |  | 
|  | 1498 | // -------------------------------------------------------------------- | 
|  | 1499 | // Invocation | 
|  | 1500 |  | 
|  | 1501 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); | 
|  | 1502 |  | 
|  | 1503 | // -------------------------------------------------------------------- | 
|  | 1504 | // Postconditions | 
|  | 1505 |  | 
|  | 1506 | // There will not be a display device set up. | 
|  | 1507 | EXPECT_FALSE(hasDisplayDevice(displayToken)); | 
|  | 1508 |  | 
|  | 1509 | // The drawing display state will be set from the current display state. | 
|  | 1510 | ASSERT_TRUE(hasDrawingDisplayState(displayToken)); | 
|  | 1511 | const auto& draw = getDrawingDisplayState(displayToken); | 
|  | 1512 | EXPECT_EQ(Case::Display::TYPE, draw.type); | 
|  | 1513 | } | 
|  | 1514 |  | 
|  | 1515 | TEST_F(HandleTransactionLockedTest, processesVirtualDisplayRemoval) { | 
|  | 1516 | using Case = HwcVirtualDisplayCase; | 
|  | 1517 |  | 
|  | 1518 | // -------------------------------------------------------------------- | 
|  | 1519 | // Preconditions | 
|  | 1520 |  | 
|  | 1521 | // A virtual display is set up but is removed from the current state. | 
|  | 1522 | mFlinger.mutableHwcDisplayData().resize(3); | 
|  | 1523 | Case::Display::injectHwcDisplay(this); | 
|  | 1524 | auto existing = Case::Display::makeFakeExistingDisplayInjector(this); | 
|  | 1525 | existing.inject(); | 
|  | 1526 | mFlinger.mutableCurrentState().displays.removeItem(existing.token()); | 
|  | 1527 |  | 
|  | 1528 | // -------------------------------------------------------------------- | 
|  | 1529 | // Call Expectations | 
|  | 1530 |  | 
|  | 1531 | EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false)); | 
|  | 1532 |  | 
|  | 1533 | // -------------------------------------------------------------------- | 
|  | 1534 | // Invocation | 
|  | 1535 |  | 
|  | 1536 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); | 
|  | 1537 |  | 
|  | 1538 | // -------------------------------------------------------------------- | 
|  | 1539 | // Postconditions | 
|  | 1540 |  | 
|  | 1541 | // The existing token should have been removed | 
|  | 1542 | verifyDisplayIsNotConnected(existing.token()); | 
|  | 1543 | } | 
|  | 1544 |  | 
| Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 1545 | TEST_F(HandleTransactionLockedTest, processesDisplayLayerStackChanges) { | 
|  | 1546 | using Case = NonHwcVirtualDisplayCase; | 
|  | 1547 |  | 
|  | 1548 | constexpr uint32_t oldLayerStack = 0u; | 
|  | 1549 | constexpr uint32_t newLayerStack = 123u; | 
|  | 1550 |  | 
|  | 1551 | // -------------------------------------------------------------------- | 
|  | 1552 | // Preconditions | 
|  | 1553 |  | 
|  | 1554 | // A display is set up | 
|  | 1555 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); | 
|  | 1556 | display.inject(); | 
|  | 1557 |  | 
|  | 1558 | // There is a change to the layerStack state | 
|  | 1559 | display.mutableDrawingDisplayState().layerStack = oldLayerStack; | 
|  | 1560 | display.mutableCurrentDisplayState().layerStack = newLayerStack; | 
|  | 1561 |  | 
|  | 1562 | // -------------------------------------------------------------------- | 
|  | 1563 | // Invocation | 
|  | 1564 |  | 
|  | 1565 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); | 
|  | 1566 |  | 
|  | 1567 | // -------------------------------------------------------------------- | 
|  | 1568 | // Postconditions | 
|  | 1569 |  | 
| Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 1570 | EXPECT_EQ(newLayerStack, display.mutableDisplayDevice()->getLayerStack()); | 
| Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 1571 | } | 
|  | 1572 |  | 
|  | 1573 | TEST_F(HandleTransactionLockedTest, processesDisplayTransformChanges) { | 
|  | 1574 | using Case = NonHwcVirtualDisplayCase; | 
|  | 1575 |  | 
|  | 1576 | constexpr int oldTransform = 0; | 
|  | 1577 | constexpr int newTransform = 2; | 
|  | 1578 |  | 
|  | 1579 | // -------------------------------------------------------------------- | 
|  | 1580 | // Preconditions | 
|  | 1581 |  | 
|  | 1582 | // A display is set up | 
|  | 1583 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); | 
|  | 1584 | display.inject(); | 
|  | 1585 |  | 
|  | 1586 | // There is a change to the orientation state | 
|  | 1587 | display.mutableDrawingDisplayState().orientation = oldTransform; | 
|  | 1588 | display.mutableCurrentDisplayState().orientation = newTransform; | 
|  | 1589 |  | 
|  | 1590 | // -------------------------------------------------------------------- | 
|  | 1591 | // Invocation | 
|  | 1592 |  | 
|  | 1593 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); | 
|  | 1594 |  | 
|  | 1595 | // -------------------------------------------------------------------- | 
|  | 1596 | // Postconditions | 
|  | 1597 |  | 
| Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 1598 | EXPECT_EQ(newTransform, display.mutableDisplayDevice()->getOrientation()); | 
| Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 1599 | } | 
|  | 1600 |  | 
|  | 1601 | TEST_F(HandleTransactionLockedTest, processesDisplayViewportChanges) { | 
|  | 1602 | using Case = NonHwcVirtualDisplayCase; | 
|  | 1603 |  | 
|  | 1604 | const Rect oldViewport(0, 0, 0, 0); | 
|  | 1605 | const Rect newViewport(0, 0, 123, 456); | 
|  | 1606 |  | 
|  | 1607 | // -------------------------------------------------------------------- | 
|  | 1608 | // Preconditions | 
|  | 1609 |  | 
|  | 1610 | // A display is set up | 
|  | 1611 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); | 
|  | 1612 | display.inject(); | 
|  | 1613 |  | 
|  | 1614 | // There is a change to the viewport state | 
|  | 1615 | display.mutableDrawingDisplayState().viewport = oldViewport; | 
|  | 1616 | display.mutableCurrentDisplayState().viewport = newViewport; | 
|  | 1617 |  | 
|  | 1618 | // -------------------------------------------------------------------- | 
|  | 1619 | // Invocation | 
|  | 1620 |  | 
|  | 1621 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); | 
|  | 1622 |  | 
|  | 1623 | // -------------------------------------------------------------------- | 
|  | 1624 | // Postconditions | 
|  | 1625 |  | 
| Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 1626 | EXPECT_EQ(newViewport, display.mutableDisplayDevice()->getViewport()); | 
| Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 1627 | } | 
|  | 1628 |  | 
|  | 1629 | TEST_F(HandleTransactionLockedTest, processesDisplayFrameChanges) { | 
|  | 1630 | using Case = NonHwcVirtualDisplayCase; | 
|  | 1631 |  | 
|  | 1632 | const Rect oldFrame(0, 0, 0, 0); | 
|  | 1633 | const Rect newFrame(0, 0, 123, 456); | 
|  | 1634 |  | 
|  | 1635 | // -------------------------------------------------------------------- | 
|  | 1636 | // Preconditions | 
|  | 1637 |  | 
|  | 1638 | // A display is set up | 
|  | 1639 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); | 
|  | 1640 | display.inject(); | 
|  | 1641 |  | 
|  | 1642 | // There is a change to the viewport state | 
|  | 1643 | display.mutableDrawingDisplayState().frame = oldFrame; | 
|  | 1644 | display.mutableCurrentDisplayState().frame = newFrame; | 
|  | 1645 |  | 
|  | 1646 | // -------------------------------------------------------------------- | 
|  | 1647 | // Invocation | 
|  | 1648 |  | 
|  | 1649 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); | 
|  | 1650 |  | 
|  | 1651 | // -------------------------------------------------------------------- | 
|  | 1652 | // Postconditions | 
|  | 1653 |  | 
| Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 1654 | EXPECT_EQ(newFrame, display.mutableDisplayDevice()->getFrame()); | 
| Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 1655 | } | 
|  | 1656 |  | 
|  | 1657 | TEST_F(HandleTransactionLockedTest, processesDisplayWidthChanges) { | 
|  | 1658 | using Case = NonHwcVirtualDisplayCase; | 
|  | 1659 |  | 
|  | 1660 | constexpr int oldWidth = 0; | 
|  | 1661 | constexpr int oldHeight = 10; | 
|  | 1662 | constexpr int newWidth = 123; | 
|  | 1663 |  | 
|  | 1664 | // -------------------------------------------------------------------- | 
|  | 1665 | // Preconditions | 
|  | 1666 |  | 
|  | 1667 | // A display is set up | 
|  | 1668 | auto nativeWindow = new mock::NativeWindow(); | 
|  | 1669 | auto displaySurface = new mock::DisplaySurface(); | 
|  | 1670 | auto renderSurface = new RE::mock::Surface(); | 
|  | 1671 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); | 
|  | 1672 | display.setNativeWindow(nativeWindow); | 
|  | 1673 | display.setDisplaySurface(displaySurface); | 
|  | 1674 | display.setRenderSurface(std::unique_ptr<RE::Surface>(renderSurface)); | 
|  | 1675 | display.inject(); | 
|  | 1676 |  | 
|  | 1677 | // There is a change to the viewport state | 
|  | 1678 | display.mutableDrawingDisplayState().width = oldWidth; | 
|  | 1679 | display.mutableDrawingDisplayState().height = oldHeight; | 
|  | 1680 | display.mutableCurrentDisplayState().width = newWidth; | 
|  | 1681 | display.mutableCurrentDisplayState().height = oldHeight; | 
|  | 1682 |  | 
|  | 1683 | // -------------------------------------------------------------------- | 
|  | 1684 | // Call Expectations | 
|  | 1685 |  | 
|  | 1686 | EXPECT_CALL(*renderSurface, setNativeWindow(nullptr)).Times(1); | 
|  | 1687 | EXPECT_CALL(*displaySurface, resizeBuffers(newWidth, oldHeight)).Times(1); | 
|  | 1688 | EXPECT_CALL(*renderSurface, setNativeWindow(nativeWindow)).Times(1); | 
|  | 1689 | EXPECT_CALL(*renderSurface, queryWidth()).WillOnce(Return(newWidth)); | 
|  | 1690 | EXPECT_CALL(*renderSurface, queryHeight()).WillOnce(Return(oldHeight)); | 
|  | 1691 |  | 
|  | 1692 | // -------------------------------------------------------------------- | 
|  | 1693 | // Invocation | 
|  | 1694 |  | 
|  | 1695 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); | 
|  | 1696 | } | 
|  | 1697 |  | 
|  | 1698 | TEST_F(HandleTransactionLockedTest, processesDisplayHeightChanges) { | 
|  | 1699 | using Case = NonHwcVirtualDisplayCase; | 
|  | 1700 |  | 
|  | 1701 | constexpr int oldWidth = 0; | 
|  | 1702 | constexpr int oldHeight = 10; | 
|  | 1703 | constexpr int newHeight = 123; | 
|  | 1704 |  | 
|  | 1705 | // -------------------------------------------------------------------- | 
|  | 1706 | // Preconditions | 
|  | 1707 |  | 
|  | 1708 | // A display is set up | 
|  | 1709 | auto nativeWindow = new mock::NativeWindow(); | 
|  | 1710 | auto displaySurface = new mock::DisplaySurface(); | 
|  | 1711 | auto renderSurface = new RE::mock::Surface(); | 
|  | 1712 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); | 
|  | 1713 | display.setNativeWindow(nativeWindow); | 
|  | 1714 | display.setDisplaySurface(displaySurface); | 
|  | 1715 | display.setRenderSurface(std::unique_ptr<RE::Surface>(renderSurface)); | 
|  | 1716 | display.inject(); | 
|  | 1717 |  | 
|  | 1718 | // There is a change to the viewport state | 
|  | 1719 | display.mutableDrawingDisplayState().width = oldWidth; | 
|  | 1720 | display.mutableDrawingDisplayState().height = oldHeight; | 
|  | 1721 | display.mutableCurrentDisplayState().width = oldWidth; | 
|  | 1722 | display.mutableCurrentDisplayState().height = newHeight; | 
|  | 1723 |  | 
|  | 1724 | // -------------------------------------------------------------------- | 
|  | 1725 | // Call Expectations | 
|  | 1726 |  | 
|  | 1727 | EXPECT_CALL(*renderSurface, setNativeWindow(nullptr)).Times(1); | 
|  | 1728 | EXPECT_CALL(*displaySurface, resizeBuffers(oldWidth, newHeight)).Times(1); | 
|  | 1729 | EXPECT_CALL(*renderSurface, setNativeWindow(nativeWindow)).Times(1); | 
|  | 1730 | EXPECT_CALL(*renderSurface, queryWidth()).WillOnce(Return(oldWidth)); | 
|  | 1731 | EXPECT_CALL(*renderSurface, queryHeight()).WillOnce(Return(newHeight)); | 
|  | 1732 |  | 
|  | 1733 | // -------------------------------------------------------------------- | 
|  | 1734 | // Invocation | 
|  | 1735 |  | 
|  | 1736 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); | 
|  | 1737 | } | 
|  | 1738 |  | 
| Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 1739 | /* ------------------------------------------------------------------------ | 
|  | 1740 | * SurfaceFlinger::setDisplayStateLocked | 
|  | 1741 | */ | 
|  | 1742 |  | 
|  | 1743 | TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingWithUnknownDisplay) { | 
|  | 1744 | // -------------------------------------------------------------------- | 
|  | 1745 | // Preconditions | 
|  | 1746 |  | 
|  | 1747 | // We have an unknown display token not associated with a known display | 
|  | 1748 | sp<BBinder> displayToken = new BBinder(); | 
|  | 1749 |  | 
|  | 1750 | // The requested display state references the unknown display. | 
|  | 1751 | DisplayState state; | 
|  | 1752 | state.what = DisplayState::eLayerStackChanged; | 
|  | 1753 | state.token = displayToken; | 
|  | 1754 | state.layerStack = 456; | 
|  | 1755 |  | 
|  | 1756 | // -------------------------------------------------------------------- | 
|  | 1757 | // Invocation | 
|  | 1758 |  | 
|  | 1759 | uint32_t flags = mFlinger.setDisplayStateLocked(state); | 
|  | 1760 |  | 
|  | 1761 | // -------------------------------------------------------------------- | 
|  | 1762 | // Postconditions | 
|  | 1763 |  | 
|  | 1764 | // The returned flags are empty | 
|  | 1765 | EXPECT_EQ(0u, flags); | 
|  | 1766 |  | 
|  | 1767 | // The display token still doesn't match anything known. | 
|  | 1768 | EXPECT_FALSE(hasCurrentDisplayState(displayToken)); | 
|  | 1769 | } | 
|  | 1770 |  | 
|  | 1771 | TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingWithInvalidDisplay) { | 
|  | 1772 | using Case = InvalidDisplayCase; | 
|  | 1773 |  | 
|  | 1774 | // -------------------------------------------------------------------- | 
|  | 1775 | // Preconditions | 
|  | 1776 |  | 
|  | 1777 | // An invalid display is set up | 
|  | 1778 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); | 
|  | 1779 | display.inject(); | 
|  | 1780 |  | 
|  | 1781 | // The invalid display has some state | 
|  | 1782 | display.mutableCurrentDisplayState().layerStack = 654u; | 
|  | 1783 |  | 
|  | 1784 | // The requested display state tries to change the display state. | 
|  | 1785 | DisplayState state; | 
|  | 1786 | state.what = DisplayState::eLayerStackChanged; | 
|  | 1787 | state.token = display.token(); | 
|  | 1788 | state.layerStack = 456; | 
|  | 1789 |  | 
|  | 1790 | // -------------------------------------------------------------------- | 
|  | 1791 | // Invocation | 
|  | 1792 |  | 
|  | 1793 | uint32_t flags = mFlinger.setDisplayStateLocked(state); | 
|  | 1794 |  | 
|  | 1795 | // -------------------------------------------------------------------- | 
|  | 1796 | // Postconditions | 
|  | 1797 |  | 
|  | 1798 | // The returned flags are empty | 
|  | 1799 | EXPECT_EQ(0u, flags); | 
|  | 1800 |  | 
|  | 1801 | // The current display layer stack value is unchanged. | 
|  | 1802 | EXPECT_EQ(654u, getCurrentDisplayState(display.token()).layerStack); | 
|  | 1803 | } | 
|  | 1804 |  | 
|  | 1805 | TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingWhenNoChanges) { | 
|  | 1806 | using Case = SimplePrimaryDisplayCase; | 
|  | 1807 |  | 
|  | 1808 | // -------------------------------------------------------------------- | 
|  | 1809 | // Preconditions | 
|  | 1810 |  | 
|  | 1811 | // A display is already set up | 
|  | 1812 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); | 
|  | 1813 | display.inject(); | 
|  | 1814 |  | 
|  | 1815 | // No changes are made to the display | 
|  | 1816 | DisplayState state; | 
|  | 1817 | state.what = 0; | 
|  | 1818 | state.token = display.token(); | 
|  | 1819 |  | 
|  | 1820 | // -------------------------------------------------------------------- | 
|  | 1821 | // Invocation | 
|  | 1822 |  | 
|  | 1823 | uint32_t flags = mFlinger.setDisplayStateLocked(state); | 
|  | 1824 |  | 
|  | 1825 | // -------------------------------------------------------------------- | 
|  | 1826 | // Postconditions | 
|  | 1827 |  | 
|  | 1828 | // The returned flags are empty | 
|  | 1829 | EXPECT_EQ(0u, flags); | 
|  | 1830 | } | 
|  | 1831 |  | 
|  | 1832 | TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfSurfaceDidNotChange) { | 
|  | 1833 | using Case = SimplePrimaryDisplayCase; | 
|  | 1834 |  | 
|  | 1835 | // -------------------------------------------------------------------- | 
|  | 1836 | // Preconditions | 
|  | 1837 |  | 
|  | 1838 | // A display is already set up | 
|  | 1839 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); | 
|  | 1840 | display.inject(); | 
|  | 1841 |  | 
|  | 1842 | // There is a surface that can be set. | 
|  | 1843 | sp<mock::GraphicBufferProducer> surface = new mock::GraphicBufferProducer(); | 
|  | 1844 |  | 
|  | 1845 | // The current display state has the surface set | 
|  | 1846 | display.mutableCurrentDisplayState().surface = surface; | 
|  | 1847 |  | 
|  | 1848 | // The incoming request sets the same surface | 
|  | 1849 | DisplayState state; | 
|  | 1850 | state.what = DisplayState::eSurfaceChanged; | 
|  | 1851 | state.token = display.token(); | 
|  | 1852 | state.surface = surface; | 
|  | 1853 |  | 
|  | 1854 | // -------------------------------------------------------------------- | 
|  | 1855 | // Invocation | 
|  | 1856 |  | 
|  | 1857 | uint32_t flags = mFlinger.setDisplayStateLocked(state); | 
|  | 1858 |  | 
|  | 1859 | // -------------------------------------------------------------------- | 
|  | 1860 | // Postconditions | 
|  | 1861 |  | 
|  | 1862 | // The returned flags are empty | 
|  | 1863 | EXPECT_EQ(0u, flags); | 
|  | 1864 |  | 
|  | 1865 | // The current display state is unchanged. | 
|  | 1866 | EXPECT_EQ(surface.get(), display.getCurrentDisplayState().surface.get()); | 
|  | 1867 | } | 
|  | 1868 |  | 
|  | 1869 | TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfSurfaceChanged) { | 
|  | 1870 | using Case = SimplePrimaryDisplayCase; | 
|  | 1871 |  | 
|  | 1872 | // -------------------------------------------------------------------- | 
|  | 1873 | // Preconditions | 
|  | 1874 |  | 
|  | 1875 | // A display is already set up | 
|  | 1876 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); | 
|  | 1877 | display.inject(); | 
|  | 1878 |  | 
|  | 1879 | // There is a surface that can be set. | 
|  | 1880 | sp<mock::GraphicBufferProducer> surface = new mock::GraphicBufferProducer(); | 
|  | 1881 |  | 
|  | 1882 | // The current display state does not have a surface | 
|  | 1883 | display.mutableCurrentDisplayState().surface = nullptr; | 
|  | 1884 |  | 
|  | 1885 | // The incoming request sets a surface | 
|  | 1886 | DisplayState state; | 
|  | 1887 | state.what = DisplayState::eSurfaceChanged; | 
|  | 1888 | state.token = display.token(); | 
|  | 1889 | state.surface = surface; | 
|  | 1890 |  | 
|  | 1891 | // -------------------------------------------------------------------- | 
|  | 1892 | // Invocation | 
|  | 1893 |  | 
|  | 1894 | uint32_t flags = mFlinger.setDisplayStateLocked(state); | 
|  | 1895 |  | 
|  | 1896 | // -------------------------------------------------------------------- | 
|  | 1897 | // Postconditions | 
|  | 1898 |  | 
|  | 1899 | // The returned flags indicate a transaction is needed | 
|  | 1900 | EXPECT_EQ(eDisplayTransactionNeeded, flags); | 
|  | 1901 |  | 
|  | 1902 | // The current display layer stack state is set to the new value | 
|  | 1903 | EXPECT_EQ(surface.get(), display.getCurrentDisplayState().surface.get()); | 
|  | 1904 | } | 
|  | 1905 |  | 
|  | 1906 | TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfLayerStackDidNotChange) { | 
|  | 1907 | using Case = SimplePrimaryDisplayCase; | 
|  | 1908 |  | 
|  | 1909 | // -------------------------------------------------------------------- | 
|  | 1910 | // Preconditions | 
|  | 1911 |  | 
|  | 1912 | // A display is already set up | 
|  | 1913 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); | 
|  | 1914 | display.inject(); | 
|  | 1915 |  | 
|  | 1916 | // The display has a layer stack set | 
|  | 1917 | display.mutableCurrentDisplayState().layerStack = 456u; | 
|  | 1918 |  | 
|  | 1919 | // The incoming request sets the same layer stack | 
|  | 1920 | DisplayState state; | 
|  | 1921 | state.what = DisplayState::eLayerStackChanged; | 
|  | 1922 | state.token = display.token(); | 
|  | 1923 | state.layerStack = 456u; | 
|  | 1924 |  | 
|  | 1925 | // -------------------------------------------------------------------- | 
|  | 1926 | // Invocation | 
|  | 1927 |  | 
|  | 1928 | uint32_t flags = mFlinger.setDisplayStateLocked(state); | 
|  | 1929 |  | 
|  | 1930 | // -------------------------------------------------------------------- | 
|  | 1931 | // Postconditions | 
|  | 1932 |  | 
|  | 1933 | // The returned flags are empty | 
|  | 1934 | EXPECT_EQ(0u, flags); | 
|  | 1935 |  | 
|  | 1936 | // The current display state is unchanged | 
|  | 1937 | EXPECT_EQ(456u, display.getCurrentDisplayState().layerStack); | 
|  | 1938 | } | 
|  | 1939 |  | 
|  | 1940 | TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfLayerStackChanged) { | 
|  | 1941 | using Case = SimplePrimaryDisplayCase; | 
|  | 1942 |  | 
|  | 1943 | // -------------------------------------------------------------------- | 
|  | 1944 | // Preconditions | 
|  | 1945 |  | 
|  | 1946 | // A display is set up | 
|  | 1947 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); | 
|  | 1948 | display.inject(); | 
|  | 1949 |  | 
|  | 1950 | // The display has a layer stack set | 
|  | 1951 | display.mutableCurrentDisplayState().layerStack = 654u; | 
|  | 1952 |  | 
|  | 1953 | // The incoming request sets a different layer stack | 
|  | 1954 | DisplayState state; | 
|  | 1955 | state.what = DisplayState::eLayerStackChanged; | 
|  | 1956 | state.token = display.token(); | 
|  | 1957 | state.layerStack = 456u; | 
|  | 1958 |  | 
|  | 1959 | // -------------------------------------------------------------------- | 
|  | 1960 | // Invocation | 
|  | 1961 |  | 
|  | 1962 | uint32_t flags = mFlinger.setDisplayStateLocked(state); | 
|  | 1963 |  | 
|  | 1964 | // -------------------------------------------------------------------- | 
|  | 1965 | // Postconditions | 
|  | 1966 |  | 
|  | 1967 | // The returned flags indicate a transaction is needed | 
|  | 1968 | EXPECT_EQ(eDisplayTransactionNeeded, flags); | 
|  | 1969 |  | 
|  | 1970 | // The desired display state has been set to the new value. | 
|  | 1971 | EXPECT_EQ(456u, display.getCurrentDisplayState().layerStack); | 
|  | 1972 | } | 
|  | 1973 |  | 
|  | 1974 | TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfProjectionDidNotChange) { | 
|  | 1975 | using Case = SimplePrimaryDisplayCase; | 
|  | 1976 | constexpr int initialOrientation = 180; | 
|  | 1977 | const Rect initialFrame = {1, 2, 3, 4}; | 
|  | 1978 | const Rect initialViewport = {5, 6, 7, 8}; | 
|  | 1979 |  | 
|  | 1980 | // -------------------------------------------------------------------- | 
|  | 1981 | // Preconditions | 
|  | 1982 |  | 
|  | 1983 | // A display is set up | 
|  | 1984 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); | 
|  | 1985 | display.inject(); | 
|  | 1986 |  | 
|  | 1987 | // The current display state projection state is all set | 
|  | 1988 | display.mutableCurrentDisplayState().orientation = initialOrientation; | 
|  | 1989 | display.mutableCurrentDisplayState().frame = initialFrame; | 
|  | 1990 | display.mutableCurrentDisplayState().viewport = initialViewport; | 
|  | 1991 |  | 
|  | 1992 | // The incoming request sets the same projection state | 
|  | 1993 | DisplayState state; | 
|  | 1994 | state.what = DisplayState::eDisplayProjectionChanged; | 
|  | 1995 | state.token = display.token(); | 
|  | 1996 | state.orientation = initialOrientation; | 
|  | 1997 | state.frame = initialFrame; | 
|  | 1998 | state.viewport = initialViewport; | 
|  | 1999 |  | 
|  | 2000 | // -------------------------------------------------------------------- | 
|  | 2001 | // Invocation | 
|  | 2002 |  | 
|  | 2003 | uint32_t flags = mFlinger.setDisplayStateLocked(state); | 
|  | 2004 |  | 
|  | 2005 | // -------------------------------------------------------------------- | 
|  | 2006 | // Postconditions | 
|  | 2007 |  | 
|  | 2008 | // The returned flags are empty | 
|  | 2009 | EXPECT_EQ(0u, flags); | 
|  | 2010 |  | 
|  | 2011 | // The current display state is unchanged | 
|  | 2012 | EXPECT_EQ(initialOrientation, display.getCurrentDisplayState().orientation); | 
|  | 2013 |  | 
|  | 2014 | EXPECT_EQ(initialFrame, display.getCurrentDisplayState().frame); | 
|  | 2015 | EXPECT_EQ(initialViewport, display.getCurrentDisplayState().viewport); | 
|  | 2016 | } | 
|  | 2017 |  | 
|  | 2018 | TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfOrientationChanged) { | 
|  | 2019 | using Case = SimplePrimaryDisplayCase; | 
|  | 2020 | constexpr int initialOrientation = 90; | 
|  | 2021 | constexpr int desiredOrientation = 180; | 
|  | 2022 |  | 
|  | 2023 | // -------------------------------------------------------------------- | 
|  | 2024 | // Preconditions | 
|  | 2025 |  | 
|  | 2026 | // A display is set up | 
|  | 2027 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); | 
|  | 2028 | display.inject(); | 
|  | 2029 |  | 
|  | 2030 | // The current display state has an orientation set | 
|  | 2031 | display.mutableCurrentDisplayState().orientation = initialOrientation; | 
|  | 2032 |  | 
|  | 2033 | // The incoming request sets a different orientation | 
|  | 2034 | DisplayState state; | 
|  | 2035 | state.what = DisplayState::eDisplayProjectionChanged; | 
|  | 2036 | state.token = display.token(); | 
|  | 2037 | state.orientation = desiredOrientation; | 
|  | 2038 |  | 
|  | 2039 | // -------------------------------------------------------------------- | 
|  | 2040 | // Invocation | 
|  | 2041 |  | 
|  | 2042 | uint32_t flags = mFlinger.setDisplayStateLocked(state); | 
|  | 2043 |  | 
|  | 2044 | // -------------------------------------------------------------------- | 
|  | 2045 | // Postconditions | 
|  | 2046 |  | 
|  | 2047 | // The returned flags indicate a transaction is needed | 
|  | 2048 | EXPECT_EQ(eDisplayTransactionNeeded, flags); | 
|  | 2049 |  | 
|  | 2050 | // The current display state has the new value. | 
|  | 2051 | EXPECT_EQ(desiredOrientation, display.getCurrentDisplayState().orientation); | 
|  | 2052 | } | 
|  | 2053 |  | 
|  | 2054 | TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfFrameChanged) { | 
|  | 2055 | using Case = SimplePrimaryDisplayCase; | 
|  | 2056 | const Rect initialFrame = {0, 0, 0, 0}; | 
|  | 2057 | const Rect desiredFrame = {5, 6, 7, 8}; | 
|  | 2058 |  | 
|  | 2059 | // -------------------------------------------------------------------- | 
|  | 2060 | // Preconditions | 
|  | 2061 |  | 
|  | 2062 | // A display is set up | 
|  | 2063 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); | 
|  | 2064 | display.inject(); | 
|  | 2065 |  | 
|  | 2066 | // The current display state does not have a frame | 
|  | 2067 | display.mutableCurrentDisplayState().frame = initialFrame; | 
|  | 2068 |  | 
|  | 2069 | // The incoming request sets a frame | 
|  | 2070 | DisplayState state; | 
|  | 2071 | state.what = DisplayState::eDisplayProjectionChanged; | 
|  | 2072 | state.token = display.token(); | 
|  | 2073 | state.frame = desiredFrame; | 
|  | 2074 |  | 
|  | 2075 | // -------------------------------------------------------------------- | 
|  | 2076 | // Invocation | 
|  | 2077 |  | 
|  | 2078 | uint32_t flags = mFlinger.setDisplayStateLocked(state); | 
|  | 2079 |  | 
|  | 2080 | // -------------------------------------------------------------------- | 
|  | 2081 | // Postconditions | 
|  | 2082 |  | 
|  | 2083 | // The returned flags indicate a transaction is needed | 
|  | 2084 | EXPECT_EQ(eDisplayTransactionNeeded, flags); | 
|  | 2085 |  | 
|  | 2086 | // The current display state has the new value. | 
|  | 2087 | EXPECT_EQ(desiredFrame, display.getCurrentDisplayState().frame); | 
|  | 2088 | } | 
|  | 2089 |  | 
|  | 2090 | TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfViewportChanged) { | 
|  | 2091 | using Case = SimplePrimaryDisplayCase; | 
|  | 2092 | const Rect initialViewport = {0, 0, 0, 0}; | 
|  | 2093 | const Rect desiredViewport = {5, 6, 7, 8}; | 
|  | 2094 |  | 
|  | 2095 | // -------------------------------------------------------------------- | 
|  | 2096 | // Preconditions | 
|  | 2097 |  | 
|  | 2098 | // A display is set up | 
|  | 2099 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); | 
|  | 2100 | display.inject(); | 
|  | 2101 |  | 
|  | 2102 | // The current display state does not have a viewport | 
|  | 2103 | display.mutableCurrentDisplayState().viewport = initialViewport; | 
|  | 2104 |  | 
|  | 2105 | // The incoming request sets a viewport | 
|  | 2106 | DisplayState state; | 
|  | 2107 | state.what = DisplayState::eDisplayProjectionChanged; | 
|  | 2108 | state.token = display.token(); | 
|  | 2109 | state.viewport = desiredViewport; | 
|  | 2110 |  | 
|  | 2111 | // -------------------------------------------------------------------- | 
|  | 2112 | // Invocation | 
|  | 2113 |  | 
|  | 2114 | uint32_t flags = mFlinger.setDisplayStateLocked(state); | 
|  | 2115 |  | 
|  | 2116 | // -------------------------------------------------------------------- | 
|  | 2117 | // Postconditions | 
|  | 2118 |  | 
|  | 2119 | // The returned flags indicate a transaction is needed | 
|  | 2120 | EXPECT_EQ(eDisplayTransactionNeeded, flags); | 
|  | 2121 |  | 
|  | 2122 | // The current display state has the new value. | 
|  | 2123 | EXPECT_EQ(desiredViewport, display.getCurrentDisplayState().viewport); | 
|  | 2124 | } | 
|  | 2125 |  | 
|  | 2126 | TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfSizeDidNotChange) { | 
|  | 2127 | using Case = SimplePrimaryDisplayCase; | 
|  | 2128 | constexpr uint32_t initialWidth = 1024; | 
|  | 2129 | constexpr uint32_t initialHeight = 768; | 
|  | 2130 |  | 
|  | 2131 | // -------------------------------------------------------------------- | 
|  | 2132 | // Preconditions | 
|  | 2133 |  | 
|  | 2134 | // A display is set up | 
|  | 2135 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); | 
|  | 2136 | display.inject(); | 
|  | 2137 |  | 
|  | 2138 | // The current display state has a size set | 
|  | 2139 | display.mutableCurrentDisplayState().width = initialWidth; | 
|  | 2140 | display.mutableCurrentDisplayState().height = initialHeight; | 
|  | 2141 |  | 
|  | 2142 | // The incoming request sets the same display size | 
|  | 2143 | DisplayState state; | 
|  | 2144 | state.what = DisplayState::eDisplaySizeChanged; | 
|  | 2145 | state.token = display.token(); | 
|  | 2146 | state.width = initialWidth; | 
|  | 2147 | state.height = initialHeight; | 
|  | 2148 |  | 
|  | 2149 | // -------------------------------------------------------------------- | 
|  | 2150 | // Invocation | 
|  | 2151 |  | 
|  | 2152 | uint32_t flags = mFlinger.setDisplayStateLocked(state); | 
|  | 2153 |  | 
|  | 2154 | // -------------------------------------------------------------------- | 
|  | 2155 | // Postconditions | 
|  | 2156 |  | 
|  | 2157 | // The returned flags are empty | 
|  | 2158 | EXPECT_EQ(0u, flags); | 
|  | 2159 |  | 
|  | 2160 | // The current display state is unchanged | 
|  | 2161 | EXPECT_EQ(initialWidth, display.getCurrentDisplayState().width); | 
|  | 2162 | EXPECT_EQ(initialHeight, display.getCurrentDisplayState().height); | 
|  | 2163 | } | 
|  | 2164 |  | 
|  | 2165 | TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfWidthChanged) { | 
|  | 2166 | using Case = SimplePrimaryDisplayCase; | 
|  | 2167 | constexpr uint32_t initialWidth = 0; | 
|  | 2168 | constexpr uint32_t desiredWidth = 1024; | 
|  | 2169 |  | 
|  | 2170 | // -------------------------------------------------------------------- | 
|  | 2171 | // Preconditions | 
|  | 2172 |  | 
|  | 2173 | // A display is set up | 
|  | 2174 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); | 
|  | 2175 | display.inject(); | 
|  | 2176 |  | 
|  | 2177 | // The display does not yet have a width | 
|  | 2178 | display.mutableCurrentDisplayState().width = initialWidth; | 
|  | 2179 |  | 
|  | 2180 | // The incoming request sets a display width | 
|  | 2181 | DisplayState state; | 
|  | 2182 | state.what = DisplayState::eDisplaySizeChanged; | 
|  | 2183 | state.token = display.token(); | 
|  | 2184 | state.width = desiredWidth; | 
|  | 2185 |  | 
|  | 2186 | // -------------------------------------------------------------------- | 
|  | 2187 | // Invocation | 
|  | 2188 |  | 
|  | 2189 | uint32_t flags = mFlinger.setDisplayStateLocked(state); | 
|  | 2190 |  | 
|  | 2191 | // -------------------------------------------------------------------- | 
|  | 2192 | // Postconditions | 
|  | 2193 |  | 
|  | 2194 | // The returned flags indicate a transaction is needed | 
|  | 2195 | EXPECT_EQ(eDisplayTransactionNeeded, flags); | 
|  | 2196 |  | 
|  | 2197 | // The current display state has the new value. | 
|  | 2198 | EXPECT_EQ(desiredWidth, display.getCurrentDisplayState().width); | 
|  | 2199 | } | 
|  | 2200 |  | 
|  | 2201 | TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfHeightChanged) { | 
|  | 2202 | using Case = SimplePrimaryDisplayCase; | 
|  | 2203 | constexpr uint32_t initialHeight = 0; | 
|  | 2204 | constexpr uint32_t desiredHeight = 768; | 
|  | 2205 |  | 
|  | 2206 | // -------------------------------------------------------------------- | 
|  | 2207 | // Preconditions | 
|  | 2208 |  | 
|  | 2209 | // A display is set up | 
|  | 2210 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); | 
|  | 2211 | display.inject(); | 
|  | 2212 |  | 
|  | 2213 | // The display does not yet have a height | 
|  | 2214 | display.mutableCurrentDisplayState().height = initialHeight; | 
|  | 2215 |  | 
|  | 2216 | // The incoming request sets a display height | 
|  | 2217 | DisplayState state; | 
|  | 2218 | state.what = DisplayState::eDisplaySizeChanged; | 
|  | 2219 | state.token = display.token(); | 
|  | 2220 | state.height = desiredHeight; | 
|  | 2221 |  | 
|  | 2222 | // -------------------------------------------------------------------- | 
|  | 2223 | // Invocation | 
|  | 2224 |  | 
|  | 2225 | uint32_t flags = mFlinger.setDisplayStateLocked(state); | 
|  | 2226 |  | 
|  | 2227 | // -------------------------------------------------------------------- | 
|  | 2228 | // Postconditions | 
|  | 2229 |  | 
|  | 2230 | // The returned flags indicate a transaction is needed | 
|  | 2231 | EXPECT_EQ(eDisplayTransactionNeeded, flags); | 
|  | 2232 |  | 
|  | 2233 | // The current display state has the new value. | 
|  | 2234 | EXPECT_EQ(desiredHeight, display.getCurrentDisplayState().height); | 
|  | 2235 | } | 
|  | 2236 |  | 
| Lloyd Pique | 86016da | 2018-03-01 16:09:38 -0800 | [diff] [blame] | 2237 | /* ------------------------------------------------------------------------ | 
|  | 2238 | * SurfaceFlinger::onInitializeDisplays | 
|  | 2239 | */ | 
|  | 2240 |  | 
|  | 2241 | TEST_F(DisplayTransactionTest, onInitializeDisplaysSetsUpPrimaryDisplay) { | 
|  | 2242 | using Case = SimplePrimaryDisplayCase; | 
|  | 2243 |  | 
|  | 2244 | // -------------------------------------------------------------------- | 
|  | 2245 | // Preconditions | 
|  | 2246 |  | 
|  | 2247 | // A primary display is set up | 
|  | 2248 | Case::Display::injectHwcDisplay(this); | 
|  | 2249 | auto primaryDisplay = Case::Display::makeFakeExistingDisplayInjector(this); | 
|  | 2250 | primaryDisplay.inject(); | 
|  | 2251 |  | 
|  | 2252 | // -------------------------------------------------------------------- | 
|  | 2253 | // Call Expectations | 
|  | 2254 |  | 
|  | 2255 | // We expect the surface interceptor to possibly be used, but we treat it as | 
|  | 2256 | // disabled since it is called as a side effect rather than directly by this | 
|  | 2257 | // function. | 
|  | 2258 | EXPECT_CALL(*mSurfaceInterceptor, isEnabled()).WillOnce(Return(false)); | 
|  | 2259 |  | 
|  | 2260 | // We expect a call to get the active display config. | 
|  | 2261 | Case::Display::setupHwcGetActiveConfigCallExpectations(this); | 
|  | 2262 |  | 
|  | 2263 | // We expect invalidate() to be invoked once to trigger display transaction | 
|  | 2264 | // processing. | 
|  | 2265 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); | 
|  | 2266 |  | 
|  | 2267 | // -------------------------------------------------------------------- | 
|  | 2268 | // Invocation | 
|  | 2269 |  | 
|  | 2270 | mFlinger.onInitializeDisplays(); | 
|  | 2271 |  | 
|  | 2272 | // -------------------------------------------------------------------- | 
|  | 2273 | // Postconditions | 
|  | 2274 |  | 
|  | 2275 | // The primary display should have a current state | 
|  | 2276 | ASSERT_TRUE(hasCurrentDisplayState(primaryDisplay.token())); | 
|  | 2277 | const auto& primaryDisplayState = getCurrentDisplayState(primaryDisplay.token()); | 
|  | 2278 | // The layer stack state should be set to zero | 
|  | 2279 | EXPECT_EQ(0u, primaryDisplayState.layerStack); | 
|  | 2280 | // The orientation state should be set to zero | 
|  | 2281 | EXPECT_EQ(0, primaryDisplayState.orientation); | 
|  | 2282 |  | 
|  | 2283 | // The frame state should be set to INVALID | 
|  | 2284 | EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.frame); | 
|  | 2285 |  | 
|  | 2286 | // The viewport state should be set to INVALID | 
|  | 2287 | EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.viewport); | 
|  | 2288 |  | 
|  | 2289 | // The width and height should both be zero | 
|  | 2290 | EXPECT_EQ(0u, primaryDisplayState.width); | 
|  | 2291 | EXPECT_EQ(0u, primaryDisplayState.height); | 
|  | 2292 |  | 
|  | 2293 | // The display should be set to HWC_POWER_MODE_NORMAL | 
|  | 2294 | ASSERT_TRUE(hasDisplayDevice(primaryDisplay.token())); | 
|  | 2295 | auto displayDevice = primaryDisplay.mutableDisplayDevice(); | 
|  | 2296 | EXPECT_EQ(HWC_POWER_MODE_NORMAL, displayDevice->getPowerMode()); | 
|  | 2297 |  | 
|  | 2298 | // The display refresh period should be set in the frame tracker. | 
|  | 2299 | FrameStats stats; | 
|  | 2300 | mFlinger.getAnimFrameTracker().getStats(&stats); | 
|  | 2301 | EXPECT_EQ(DEFAULT_REFRESH_RATE, stats.refreshPeriodNano); | 
|  | 2302 |  | 
|  | 2303 | // The display transaction needed flag should be set. | 
|  | 2304 | EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded)); | 
|  | 2305 |  | 
|  | 2306 | // The compositor timing should be set to default values | 
|  | 2307 | const auto& compositorTiming = mFlinger.getCompositorTiming(); | 
|  | 2308 | EXPECT_EQ(-DEFAULT_REFRESH_RATE, compositorTiming.deadline); | 
|  | 2309 | EXPECT_EQ(DEFAULT_REFRESH_RATE, compositorTiming.interval); | 
|  | 2310 | EXPECT_EQ(DEFAULT_REFRESH_RATE, compositorTiming.presentLatency); | 
|  | 2311 | } | 
|  | 2312 |  | 
| Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 2313 | } // namespace | 
|  | 2314 | } // namespace android |