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