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