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