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