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