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