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