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