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