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 | |
| 17 | #pragma once |
| 18 | |
Dominik Laskowski | 83bd771 | 2022-01-07 14:30:53 -0800 | [diff] [blame] | 19 | #include <algorithm> |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 20 | #include <chrono> |
Dominik Laskowski | 83bd771 | 2022-01-07 14:30:53 -0800 | [diff] [blame] | 21 | #include <variant> |
| 22 | |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 23 | #include <compositionengine/Display.h> |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 24 | #include <compositionengine/LayerFECompositionState.h> |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 25 | #include <compositionengine/OutputLayer.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 26 | #include <compositionengine/impl/CompositionEngine.h> |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 27 | #include <compositionengine/impl/Display.h> |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 28 | #include <compositionengine/impl/OutputLayerCompositionState.h> |
Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 29 | #include <compositionengine/mock/DisplaySurface.h> |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 30 | #include <ftl/fake_guard.h> |
chaviw | 0ef7caa | 2021-01-05 11:04:50 -0800 | [diff] [blame] | 31 | #include <gui/ScreenCaptureResults.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 32 | |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 33 | #include "DisplayDevice.h" |
Ady Abraham | c581d3c | 2020-08-06 17:34:27 -0700 | [diff] [blame] | 34 | #include "FakeVsyncConfiguration.h" |
Adithya Srinivasan | 2db3c1b | 2020-11-18 12:43:17 -0800 | [diff] [blame] | 35 | #include "FrameTracer/FrameTracer.h" |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 36 | #include "Layer.h" |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 37 | #include "NativeWindowSurface.h" |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 38 | #include "Scheduler/MessageQueue.h" |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 39 | #include "Scheduler/RefreshRateConfigs.h" |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 40 | #include "StartPropertySetThread.h" |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 41 | #include "SurfaceFlinger.h" |
Lloyd Pique | 24f3bfe | 2019-10-02 19:29:10 -0700 | [diff] [blame] | 42 | #include "SurfaceFlingerDefaultFactory.h" |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 43 | #include "SurfaceInterceptor.h" |
Dominik Laskowski | 7c9dbf9 | 2019-08-01 17:57:31 -0700 | [diff] [blame] | 44 | #include "TestableScheduler.h" |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 45 | #include "mock/DisplayHardware/MockComposer.h" |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 46 | #include "mock/DisplayHardware/MockDisplayMode.h" |
Adithya Srinivasan | 0118967 | 2020-10-20 14:23:05 -0700 | [diff] [blame] | 47 | #include "mock/MockFrameTimeline.h" |
Adithya Srinivasan | 2db3c1b | 2020-11-18 12:43:17 -0800 | [diff] [blame] | 48 | #include "mock/MockFrameTracer.h" |
Dominik Laskowski | 83bd771 | 2022-01-07 14:30:53 -0800 | [diff] [blame] | 49 | #include "mock/MockSchedulerCallback.h" |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame] | 50 | |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 51 | namespace android { |
| 52 | |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 53 | class EventThread; |
| 54 | |
Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 55 | namespace renderengine { |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 56 | |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 57 | class RenderEngine; |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 58 | |
| 59 | } // namespace renderengine |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 60 | |
| 61 | namespace Hwc2 { |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 62 | |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 63 | class Composer; |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 64 | |
| 65 | } // namespace Hwc2 |
| 66 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 67 | namespace hal = android::hardware::graphics::composer::hal; |
| 68 | |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 69 | namespace surfaceflinger::test { |
| 70 | |
| 71 | class Factory final : public surfaceflinger::Factory { |
| 72 | public: |
| 73 | ~Factory() = default; |
| 74 | |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 75 | std::unique_ptr<HWComposer> createHWComposer(const std::string&) override { |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 76 | return nullptr; |
| 77 | } |
| 78 | |
Ady Abraham | 8287e85 | 2020-08-12 14:44:58 -0700 | [diff] [blame] | 79 | std::unique_ptr<scheduler::VsyncConfiguration> createVsyncConfiguration( |
Marin Shalamanov | 526c338 | 2020-12-10 15:22:29 +0100 | [diff] [blame] | 80 | Fps /*currentRefreshRate*/) override { |
Ana Krulec | 757f63a | 2019-01-25 10:46:18 -0800 | [diff] [blame] | 81 | return std::make_unique<scheduler::FakePhaseOffsets>(); |
| 82 | } |
| 83 | |
Pablo Gamito | c351d6f | 2020-09-17 15:34:26 +0000 | [diff] [blame] | 84 | sp<SurfaceInterceptor> createSurfaceInterceptor() override { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 85 | return sp<android::impl::SurfaceInterceptor>::make(); |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | sp<StartPropertySetThread> createStartPropertySetThread(bool timestampPropertyValue) override { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 89 | return sp<StartPropertySetThread>::make(timestampPropertyValue); |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 92 | sp<DisplayDevice> createDisplayDevice(DisplayDeviceCreationArgs& creationArgs) override { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 93 | return sp<DisplayDevice>::make(creationArgs); |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | sp<GraphicBuffer> createGraphicBuffer(uint32_t width, uint32_t height, PixelFormat format, |
| 97 | uint32_t layerCount, uint64_t usage, |
| 98 | std::string requestorName) override { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 99 | return sp<GraphicBuffer>::make(width, height, format, layerCount, usage, requestorName); |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | void createBufferQueue(sp<IGraphicBufferProducer>* outProducer, |
| 103 | sp<IGraphicBufferConsumer>* outConsumer, |
| 104 | bool consumerIsSurfaceFlinger) override { |
Lloyd Pique | e300b31 | 2019-10-03 13:03:45 -0700 | [diff] [blame] | 105 | if (!mCreateBufferQueue) { |
| 106 | BufferQueue::createBufferQueue(outProducer, outConsumer, consumerIsSurfaceFlinger); |
| 107 | return; |
| 108 | } |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 109 | mCreateBufferQueue(outProducer, outConsumer, consumerIsSurfaceFlinger); |
| 110 | } |
| 111 | |
| 112 | std::unique_ptr<surfaceflinger::NativeWindowSurface> createNativeWindowSurface( |
| 113 | const sp<IGraphicBufferProducer>& producer) override { |
| 114 | if (!mCreateNativeWindowSurface) return nullptr; |
| 115 | return mCreateNativeWindowSurface(producer); |
| 116 | } |
| 117 | |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 118 | std::unique_ptr<compositionengine::CompositionEngine> createCompositionEngine() override { |
| 119 | return compositionengine::impl::createCompositionEngine(); |
| 120 | } |
| 121 | |
Patrick Williams | 83f36b2 | 2022-09-14 17:57:35 +0000 | [diff] [blame] | 122 | sp<Layer> createBufferStateLayer(const LayerCreationArgs&) override { return nullptr; } |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 123 | |
Patrick Williams | 46b61b9 | 2022-09-01 17:25:49 +0000 | [diff] [blame] | 124 | sp<Layer> createEffectLayer(const LayerCreationArgs&) override { return nullptr; } |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 125 | |
Adithya Srinivasan | 2db3c1b | 2020-11-18 12:43:17 -0800 | [diff] [blame] | 126 | std::unique_ptr<FrameTracer> createFrameTracer() override { |
| 127 | return std::make_unique<mock::FrameTracer>(); |
| 128 | } |
| 129 | |
Adithya Srinivasan | 0118967 | 2020-10-20 14:23:05 -0700 | [diff] [blame] | 130 | std::unique_ptr<frametimeline::FrameTimeline> createFrameTimeline( |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 131 | std::shared_ptr<TimeStats> timeStats, pid_t surfaceFlingerPid = 0) override { |
| 132 | return std::make_unique<mock::FrameTimeline>(timeStats, surfaceFlingerPid); |
Adithya Srinivasan | 0118967 | 2020-10-20 14:23:05 -0700 | [diff] [blame] | 133 | } |
| 134 | |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 135 | using CreateBufferQueueFunction = |
| 136 | std::function<void(sp<IGraphicBufferProducer>* /* outProducer */, |
| 137 | sp<IGraphicBufferConsumer>* /* outConsumer */, |
| 138 | bool /* consumerIsSurfaceFlinger */)>; |
| 139 | CreateBufferQueueFunction mCreateBufferQueue; |
| 140 | |
| 141 | using CreateNativeWindowSurfaceFunction = |
| 142 | std::function<std::unique_ptr<surfaceflinger::NativeWindowSurface>( |
| 143 | const sp<IGraphicBufferProducer>&)>; |
| 144 | CreateNativeWindowSurfaceFunction mCreateNativeWindowSurface; |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 145 | |
| 146 | using CreateCompositionEngineFunction = |
| 147 | std::function<std::unique_ptr<compositionengine::CompositionEngine>()>; |
| 148 | CreateCompositionEngineFunction mCreateCompositionEngine; |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 149 | }; |
| 150 | |
| 151 | } // namespace surfaceflinger::test |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 152 | |
Dominik Laskowski | 83bd771 | 2022-01-07 14:30:53 -0800 | [diff] [blame] | 153 | class TestableSurfaceFlinger { |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 154 | public: |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 155 | using HotplugEvent = SurfaceFlinger::HotplugEvent; |
| 156 | |
Vishnu Nair | 4df8eb6 | 2022-02-17 15:32:02 -0800 | [diff] [blame] | 157 | TestableSurfaceFlinger(sp<SurfaceFlinger> flinger = nullptr) : mFlinger(flinger) { |
| 158 | if (!mFlinger) { |
| 159 | mFlinger = sp<SurfaceFlinger>::make(mFactory, SurfaceFlinger::SkipInitialization); |
| 160 | } |
Ady Abraham | e9ebce0 | 2022-02-03 12:05:06 -0800 | [diff] [blame] | 161 | } |
| 162 | |
Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 163 | SurfaceFlinger* flinger() { return mFlinger.get(); } |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 164 | scheduler::TestableScheduler* scheduler() { return mScheduler; } |
Dominik Laskowski | 7c9dbf9 | 2019-08-01 17:57:31 -0700 | [diff] [blame] | 165 | |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 166 | // Extend this as needed for accessing SurfaceFlinger private (and public) |
| 167 | // functions. |
| 168 | |
Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 169 | void setupRenderEngine(std::unique_ptr<renderengine::RenderEngine> renderEngine) { |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 170 | mFlinger->mCompositionEngine->setRenderEngine(std::move(renderEngine)); |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | void setupComposer(std::unique_ptr<Hwc2::Composer> composer) { |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 174 | mFlinger->mCompositionEngine->setHwComposer( |
| 175 | std::make_unique<impl::HWComposer>(std::move(composer))); |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 176 | } |
| 177 | |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 178 | void setupPowerAdvisor(std::unique_ptr<Hwc2::PowerAdvisor> powerAdvisor) { |
| 179 | mFlinger->mPowerAdvisor = std::move(powerAdvisor); |
| 180 | } |
| 181 | |
Alec Mouri | e4034bb | 2019-11-19 12:45:54 -0800 | [diff] [blame] | 182 | void setupTimeStats(const std::shared_ptr<TimeStats>& timeStats) { |
| 183 | mFlinger->mCompositionEngine->setTimeStats(timeStats); |
| 184 | } |
| 185 | |
Dominik Laskowski | 83bd771 | 2022-01-07 14:30:53 -0800 | [diff] [blame] | 186 | enum class SchedulerCallbackImpl { kNoOp, kMock }; |
| 187 | |
| 188 | static constexpr struct OneDisplayMode { |
| 189 | } kOneDisplayMode; |
| 190 | |
| 191 | static constexpr struct TwoDisplayModes { |
| 192 | } kTwoDisplayModes; |
| 193 | |
| 194 | using RefreshRateConfigsPtr = std::shared_ptr<scheduler::RefreshRateConfigs>; |
| 195 | |
| 196 | using DisplayModesVariant = |
| 197 | std::variant<OneDisplayMode, TwoDisplayModes, RefreshRateConfigsPtr>; |
| 198 | |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 199 | void setupScheduler(std::unique_ptr<scheduler::VsyncController> vsyncController, |
| 200 | std::unique_ptr<scheduler::VSyncTracker> vsyncTracker, |
Dominik Laskowski | 7c9dbf9 | 2019-08-01 17:57:31 -0700 | [diff] [blame] | 201 | std::unique_ptr<EventThread> appEventThread, |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 202 | std::unique_ptr<EventThread> sfEventThread, |
Dominik Laskowski | 83bd771 | 2022-01-07 14:30:53 -0800 | [diff] [blame] | 203 | SchedulerCallbackImpl callbackImpl = SchedulerCallbackImpl::kNoOp, |
Vishnu Nair | 4df8eb6 | 2022-02-17 15:32:02 -0800 | [diff] [blame] | 204 | DisplayModesVariant modesVariant = kOneDisplayMode, |
| 205 | bool useNiceMock = false) { |
Dominik Laskowski | 83bd771 | 2022-01-07 14:30:53 -0800 | [diff] [blame] | 206 | RefreshRateConfigsPtr configs; |
| 207 | if (std::holds_alternative<RefreshRateConfigsPtr>(modesVariant)) { |
| 208 | configs = std::move(std::get<RefreshRateConfigsPtr>(modesVariant)); |
| 209 | } else { |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 210 | constexpr DisplayModeId kModeId60{0}; |
| 211 | DisplayModes modes = makeModes(mock::createDisplayMode(kModeId60, 60_Hz)); |
Ady Abraham | abc2760 | 2020-04-08 17:20:29 -0700 | [diff] [blame] | 212 | |
Dominik Laskowski | 83bd771 | 2022-01-07 14:30:53 -0800 | [diff] [blame] | 213 | if (std::holds_alternative<TwoDisplayModes>(modesVariant)) { |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 214 | constexpr DisplayModeId kModeId90{1}; |
| 215 | modes.try_emplace(kModeId90, mock::createDisplayMode(kModeId90, 90_Hz)); |
Dominik Laskowski | 83bd771 | 2022-01-07 14:30:53 -0800 | [diff] [blame] | 216 | } |
| 217 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 218 | configs = std::make_shared<scheduler::RefreshRateConfigs>(modes, kModeId60); |
Dominik Laskowski | 983f2b5 | 2020-06-25 16:54:06 -0700 | [diff] [blame] | 219 | } |
| 220 | |
Dominik Laskowski | f8734e0 | 2022-08-26 09:06:59 -0700 | [diff] [blame] | 221 | const auto fps = FTL_FAKE_GUARD(kMainThreadContext, configs->getActiveMode().getFps()); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 222 | mFlinger->mVsyncConfiguration = mFactory.createVsyncConfiguration(fps); |
Ady Abraham | 23ea9da | 2021-07-14 16:32:56 -0700 | [diff] [blame] | 223 | mFlinger->mVsyncModulator = sp<scheduler::VsyncModulator>::make( |
| 224 | mFlinger->mVsyncConfiguration->getCurrentConfigs()); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 225 | |
Marin Shalamanov | 68a9409 | 2020-11-24 17:48:00 +0100 | [diff] [blame] | 226 | mFlinger->mRefreshRateStats = |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 227 | std::make_unique<scheduler::RefreshRateStats>(*mFlinger->mTimeStats, fps, |
Dominik Laskowski | 83bd771 | 2022-01-07 14:30:53 -0800 | [diff] [blame] | 228 | hal::PowerMode::OFF); |
| 229 | |
| 230 | using Callback = scheduler::ISchedulerCallback; |
| 231 | Callback& callback = callbackImpl == SchedulerCallbackImpl::kNoOp |
| 232 | ? static_cast<Callback&>(mNoOpSchedulerCallback) |
| 233 | : static_cast<Callback&>(mSchedulerCallback); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 234 | |
Vishnu Nair | 4df8eb6 | 2022-02-17 15:32:02 -0800 | [diff] [blame] | 235 | if (useNiceMock) { |
| 236 | mScheduler = |
| 237 | new testing::NiceMock<scheduler::TestableScheduler>(std::move(vsyncController), |
| 238 | std::move(vsyncTracker), |
| 239 | std::move(configs), |
| 240 | callback); |
| 241 | } else { |
| 242 | mScheduler = new scheduler::TestableScheduler(std::move(vsyncController), |
| 243 | std::move(vsyncTracker), |
| 244 | std::move(configs), callback); |
| 245 | } |
Dominik Laskowski | 7c9dbf9 | 2019-08-01 17:57:31 -0700 | [diff] [blame] | 246 | |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 247 | mFlinger->mAppConnectionHandle = mScheduler->createConnection(std::move(appEventThread)); |
| 248 | mFlinger->mSfConnectionHandle = mScheduler->createConnection(std::move(sfEventThread)); |
Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 249 | resetScheduler(mScheduler); |
Dominik Laskowski | 7c9dbf9 | 2019-08-01 17:57:31 -0700 | [diff] [blame] | 250 | } |
| 251 | |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 252 | void resetScheduler(scheduler::Scheduler* scheduler) { mFlinger->mScheduler.reset(scheduler); } |
Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 253 | |
Dominik Laskowski | 83bd771 | 2022-01-07 14:30:53 -0800 | [diff] [blame] | 254 | scheduler::TestableScheduler& mutableScheduler() { return *mScheduler; } |
| 255 | scheduler::mock::SchedulerCallback& mockSchedulerCallback() { return mSchedulerCallback; } |
Ady Abraham | 44e9f3b | 2021-02-16 15:22:58 -0800 | [diff] [blame] | 256 | |
Ady Abraham | 2739e83 | 2022-02-14 17:42:00 -0800 | [diff] [blame] | 257 | auto& mutableVsyncModulator() { return mFlinger->mVsyncModulator; } |
| 258 | |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 259 | using CreateBufferQueueFunction = surfaceflinger::test::Factory::CreateBufferQueueFunction; |
Lloyd Pique | 5b36f3f | 2018-01-17 11:57:07 -0800 | [diff] [blame] | 260 | void setCreateBufferQueueFunction(CreateBufferQueueFunction f) { |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 261 | mFactory.mCreateBufferQueue = f; |
Lloyd Pique | 5b36f3f | 2018-01-17 11:57:07 -0800 | [diff] [blame] | 262 | } |
| 263 | |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 264 | using CreateNativeWindowSurfaceFunction = |
| 265 | surfaceflinger::test::Factory::CreateNativeWindowSurfaceFunction; |
Lloyd Pique | 0b1fe70 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 266 | void setCreateNativeWindowSurface(CreateNativeWindowSurfaceFunction f) { |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 267 | mFactory.mCreateNativeWindowSurface = f; |
Lloyd Pique | 0b1fe70 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 268 | } |
| 269 | |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 270 | void setInternalDisplayPrimaries(const ui::DisplayPrimaries& primaries) { |
| 271 | memcpy(&mFlinger->mInternalDisplayPrimaries, &primaries, sizeof(ui::DisplayPrimaries)); |
| 272 | } |
| 273 | |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 274 | static auto& mutableLayerDrawingState(const sp<Layer>& layer) { return layer->mDrawingState; } |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 275 | |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 276 | auto& mutableStateLock() { return mFlinger->mStateLock; } |
| 277 | |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 278 | static auto findOutputLayerForDisplay(const sp<Layer>& layer, |
| 279 | const sp<const DisplayDevice>& display) { |
| 280 | return layer->findOutputLayerForDisplay(display.get()); |
| 281 | } |
| 282 | |
| 283 | static void setLayerSidebandStream(const sp<Layer>& layer, |
| 284 | const sp<NativeHandle>& sidebandStream) { |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 285 | layer->mDrawingState.sidebandStream = sidebandStream; |
Lloyd Pique | 0b785d8 | 2018-12-04 17:25:27 -0800 | [diff] [blame] | 286 | layer->mSidebandStream = sidebandStream; |
Vishnu Nair | bedb44b | 2022-08-02 21:47:40 +0000 | [diff] [blame] | 287 | layer->editLayerSnapshot()->sidebandStream = sidebandStream; |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 288 | } |
| 289 | |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 290 | void setLayerCompositionType(const sp<Layer>& layer, |
| 291 | aidl::android::hardware::graphics::composer3::Composition type) { |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 292 | auto outputLayer = findOutputLayerForDisplay(layer, mFlinger->getDefaultDisplayDevice()); |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 293 | LOG_ALWAYS_FATAL_IF(!outputLayer); |
| 294 | auto& state = outputLayer->editState(); |
| 295 | LOG_ALWAYS_FATAL_IF(!outputLayer->getState().hwc); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 296 | (*state.hwc).hwcCompositionType = type; |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 297 | } |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 298 | |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 299 | static void setLayerPotentialCursor(const sp<Layer>& layer, bool potentialCursor) { |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 300 | layer->mPotentialCursor = potentialCursor; |
| 301 | } |
| 302 | |
Garfield Tan | de619fa | 2020-10-02 17:13:53 -0700 | [diff] [blame] | 303 | static void setLayerDrawingParent(const sp<Layer>& layer, const sp<Layer>& drawingParent) { |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 304 | layer->mDrawingParent = drawingParent; |
Garfield Tan | de619fa | 2020-10-02 17:13:53 -0700 | [diff] [blame] | 305 | } |
| 306 | |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 307 | void setPowerHintSessionMode(bool early, bool late) { |
| 308 | mFlinger->mPowerHintSessionMode = {.late = late, .early = early}; |
| 309 | } |
| 310 | |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 311 | /* ------------------------------------------------------------------------ |
| 312 | * Forwarding for functions being tested |
| 313 | */ |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 314 | |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 315 | void configure() { mFlinger->configure(); } |
| 316 | |
| 317 | void configureAndCommit() { |
| 318 | configure(); |
| 319 | commitTransactionsLocked(eDisplayTransactionNeeded); |
| 320 | } |
| 321 | |
| 322 | TimePoint commit(TimePoint frameTime, VsyncId vsyncId, TimePoint expectedVsyncTime) { |
| 323 | mFlinger->commit(frameTime, vsyncId, expectedVsyncTime); |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 324 | return frameTime; |
| 325 | } |
| 326 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 327 | TimePoint commit(TimePoint frameTime, VsyncId vsyncId) { |
| 328 | return commit(frameTime, vsyncId, frameTime + Period(10ms)); |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 329 | } |
| 330 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 331 | TimePoint commit() { |
| 332 | const TimePoint frameTime = scheduler::SchedulerClock::now(); |
| 333 | return commit(frameTime, kVsyncId); |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 334 | } |
| 335 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 336 | void commitAndComposite(TimePoint frameTime, VsyncId vsyncId, TimePoint expectedVsyncTime) { |
| 337 | mFlinger->composite(commit(frameTime, vsyncId, expectedVsyncTime), vsyncId); |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 338 | } |
| 339 | |
Ady Abraham | 302ebed | 2022-03-07 16:03:41 -0800 | [diff] [blame] | 340 | void commitAndComposite() { mFlinger->composite(commit(), kVsyncId); } |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 341 | |
Lloyd Pique | a482f99 | 2018-01-22 19:00:34 -0800 | [diff] [blame] | 342 | auto createDisplay(const String8& displayName, bool secure) { |
| 343 | return mFlinger->createDisplay(displayName, secure); |
| 344 | } |
| 345 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 346 | auto destroyDisplay(const sp<IBinder>& displayToken) { |
| 347 | return mFlinger->destroyDisplay(displayToken); |
| 348 | } |
Lloyd Pique | a482f99 | 2018-01-22 19:00:34 -0800 | [diff] [blame] | 349 | |
Marin Shalamanov | c7e9f82 | 2021-11-16 20:07:55 +0100 | [diff] [blame] | 350 | auto getDisplay(const sp<IBinder>& displayToken) { |
| 351 | Mutex::Autolock lock(mFlinger->mStateLock); |
| 352 | return mFlinger->getDisplayDeviceLocked(displayToken); |
| 353 | } |
| 354 | |
Dominik Laskowski | 1394860 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 355 | void enableHalVirtualDisplays(bool enable) { mFlinger->enableHalVirtualDisplays(enable); } |
| 356 | |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 357 | auto setupNewDisplayDeviceInternal( |
| 358 | const wp<IBinder>& displayToken, |
| 359 | std::shared_ptr<compositionengine::Display> compositionDisplay, |
| 360 | const DisplayDeviceState& state, |
| 361 | const sp<compositionengine::DisplaySurface>& dispSurface, |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 362 | const sp<IGraphicBufferProducer>& producer) NO_THREAD_SAFETY_ANALYSIS { |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 363 | return mFlinger->setupNewDisplayDeviceInternal(displayToken, compositionDisplay, state, |
| 364 | dispSurface, producer); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 365 | } |
| 366 | |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 367 | void commitTransactionsLocked(uint32_t transactionFlags) { |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 368 | Mutex::Autolock lock(mFlinger->mStateLock); |
Dominik Laskowski | f8734e0 | 2022-08-26 09:06:59 -0700 | [diff] [blame] | 369 | ftl::FakeGuard guard(kMainThreadContext); |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 370 | mFlinger->commitTransactionsLocked(transactionFlags); |
Lloyd Pique | 0b1fe70 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 371 | } |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 372 | |
Dominik Laskowski | ebc8d3a | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 373 | void onComposerHalHotplug(hal::HWDisplayId hwcDisplayId, hal::Connection connection) { |
| 374 | mFlinger->onComposerHalHotplug(hwcDisplayId, connection); |
Lloyd Pique | 6cf1103 | 2018-01-22 18:57:44 -0800 | [diff] [blame] | 375 | } |
| 376 | |
Vishnu Nair | ce5d0cc | 2019-02-28 14:38:41 -0800 | [diff] [blame] | 377 | auto setDisplayStateLocked(const DisplayState& s) { |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 378 | Mutex::Autolock lock(mFlinger->mStateLock); |
Vishnu Nair | ce5d0cc | 2019-02-28 14:38:41 -0800 | [diff] [blame] | 379 | return mFlinger->setDisplayStateLocked(s); |
| 380 | } |
Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 381 | |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 382 | // Allow reading display state without locking, as if called on the SF main thread. |
| 383 | auto onInitializeDisplays() NO_THREAD_SAFETY_ANALYSIS { |
| 384 | return mFlinger->onInitializeDisplays(); |
| 385 | } |
Lloyd Pique | 86016da | 2018-03-01 16:09:38 -0800 | [diff] [blame] | 386 | |
Lais Andrade | 3a6e47d | 2020-04-02 11:20:16 +0100 | [diff] [blame] | 387 | auto notifyPowerBoost(int32_t boostId) { return mFlinger->notifyPowerBoost(boostId); } |
| 388 | |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 389 | auto setDisplayBrightness(const sp<IBinder>& display, |
| 390 | const gui::DisplayBrightness& brightness) { |
| 391 | return mFlinger->setDisplayBrightness(display, brightness); |
| 392 | } |
| 393 | |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 394 | // Allow reading display state without locking, as if called on the SF main thread. |
| 395 | auto setPowerModeInternal(const sp<DisplayDevice>& display, |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 396 | hal::PowerMode mode) NO_THREAD_SAFETY_ANALYSIS { |
Dominik Laskowski | e977409 | 2018-12-11 10:04:24 -0800 | [diff] [blame] | 397 | return mFlinger->setPowerModeInternal(display, mode); |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 398 | } |
| 399 | |
Robert Carr | 12a3b9b | 2022-03-10 09:55:29 -0800 | [diff] [blame] | 400 | auto renderScreenImpl(const RenderArea& renderArea, |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 401 | SurfaceFlinger::TraverseLayersFunction traverseLayers, |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 402 | const std::shared_ptr<renderengine::ExternalTexture>& buffer, |
| 403 | bool forSystem, bool regionSampling) { |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 404 | ScreenCaptureResults captureResults; |
Robert Carr | 12a3b9b | 2022-03-10 09:55:29 -0800 | [diff] [blame] | 405 | return mFlinger->renderScreenImpl(renderArea, traverseLayers, buffer, forSystem, |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 406 | regionSampling, false /* grayscale */, |
| 407 | captureResults); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 408 | } |
| 409 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 410 | auto traverseLayersInLayerStack(ui::LayerStack layerStack, int32_t uid, |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 411 | const LayerVector::Visitor& visitor) { |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 412 | return mFlinger->SurfaceFlinger::traverseLayersInLayerStack(layerStack, uid, visitor); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 413 | } |
| 414 | |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 415 | auto getDisplayNativePrimaries(const sp<IBinder>& displayToken, |
| 416 | ui::DisplayPrimaries &primaries) { |
| 417 | return mFlinger->SurfaceFlinger::getDisplayNativePrimaries(displayToken, primaries); |
| 418 | } |
| 419 | |
Vishnu Nair | 60d902e | 2022-07-20 02:55:37 +0000 | [diff] [blame] | 420 | auto& getTransactionQueue() { return mFlinger->mLocklessTransactionQueue; } |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 421 | auto& getPendingTransactionQueue() { return mFlinger->mPendingTransactionQueues; } |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 422 | |
Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 423 | auto setTransactionState( |
| 424 | const FrameTimelineInfo& frameTimelineInfo, const Vector<ComposerState>& states, |
| 425 | const Vector<DisplayState>& displays, uint32_t flags, const sp<IBinder>& applyToken, |
| 426 | const InputWindowCommands& inputWindowCommands, int64_t desiredPresentTime, |
| 427 | bool isAutoTimestamp, const client_cache_t& uncacheBuffer, bool hasListenerCallbacks, |
| 428 | std::vector<ListenerCallbacks>& listenerCallbacks, uint64_t transactionId) { |
| 429 | return mFlinger->setTransactionState(frameTimelineInfo, states, displays, flags, applyToken, |
| 430 | inputWindowCommands, desiredPresentTime, |
Ady Abraham | f0c5649 | 2020-12-17 18:04:15 -0800 | [diff] [blame] | 431 | isAutoTimestamp, uncacheBuffer, hasListenerCallbacks, |
| 432 | listenerCallbacks, transactionId); |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 433 | } |
| 434 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 435 | auto flushTransactionQueues() { |
| 436 | return FTL_FAKE_GUARD(kMainThreadContext, mFlinger->flushTransactionQueues(kVsyncId)); |
| 437 | } |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 438 | |
Eduardo Rocha | ac86719 | 2020-09-14 20:12:17 +0000 | [diff] [blame] | 439 | auto onTransact(uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) { |
| 440 | return mFlinger->onTransact(code, data, reply, flags); |
| 441 | } |
| 442 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 443 | auto getGpuContextPriority() { return mFlinger->getGpuContextPriority(); } |
Ana Krulec | 31f2b3c | 2020-12-14 14:30:09 -0800 | [diff] [blame] | 444 | |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 445 | auto calculateMaxAcquiredBufferCount(Fps refreshRate, |
| 446 | std::chrono::nanoseconds presentLatency) const { |
| 447 | return SurfaceFlinger::calculateMaxAcquiredBufferCount(refreshRate, presentLatency); |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 448 | } |
| 449 | |
Marin Shalamanov | c7e9f82 | 2021-11-16 20:07:55 +0100 | [diff] [blame] | 450 | auto setDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, ui::DisplayModeId defaultMode, |
| 451 | bool allowGroupSwitching, float primaryRefreshRateMin, |
| 452 | float primaryRefreshRateMax, float appRequestRefreshRateMin, |
| 453 | float appRequestRefreshRateMax) { |
| 454 | return mFlinger->setDesiredDisplayModeSpecs(displayToken, defaultMode, allowGroupSwitching, |
| 455 | primaryRefreshRateMin, primaryRefreshRateMax, |
| 456 | appRequestRefreshRateMin, |
| 457 | appRequestRefreshRateMax); |
| 458 | } |
| 459 | |
| 460 | void onActiveDisplayChanged(const sp<DisplayDevice>& activeDisplay) { |
| 461 | Mutex::Autolock lock(mFlinger->mStateLock); |
Dominik Laskowski | f8734e0 | 2022-08-26 09:06:59 -0700 | [diff] [blame] | 462 | ftl::FakeGuard guard(kMainThreadContext); |
Marin Shalamanov | c7e9f82 | 2021-11-16 20:07:55 +0100 | [diff] [blame] | 463 | mFlinger->onActiveDisplayChangedLocked(activeDisplay); |
| 464 | } |
| 465 | |
Vishnu Nair | 4df8eb6 | 2022-02-17 15:32:02 -0800 | [diff] [blame] | 466 | auto createLayer(LayerCreationArgs& args, sp<IBinder>* outHandle, |
| 467 | const sp<IBinder>& parentHandle, int32_t* outLayerId, |
| 468 | const sp<Layer>& parentLayer, uint32_t* outTransformHint) { |
| 469 | return mFlinger->createLayer(args, outHandle, parentHandle, outLayerId, parentLayer, |
| 470 | outTransformHint); |
| 471 | } |
| 472 | |
| 473 | auto mirrorLayer(const LayerCreationArgs& args, const sp<IBinder>& mirrorFromHandle, |
| 474 | sp<IBinder>* outHandle, int32_t* outLayerId) { |
| 475 | return mFlinger->mirrorLayer(args, mirrorFromHandle, outHandle, outLayerId); |
| 476 | } |
| 477 | |
Vishnu Nair | 0a4fb00 | 2022-08-08 02:40:42 +0000 | [diff] [blame] | 478 | void updateLayerMetadataSnapshot() { mFlinger->updateLayerMetadataSnapshot(); } |
| 479 | |
Lloyd Pique | 86016da | 2018-03-01 16:09:38 -0800 | [diff] [blame] | 480 | /* ------------------------------------------------------------------------ |
| 481 | * Read-only access to private data to assert post-conditions. |
| 482 | */ |
| 483 | |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 484 | const auto& getVisibleRegionsDirty() const { return mFlinger->mVisibleRegionsDirty; } |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 485 | auto& getHwComposer() const { |
| 486 | return static_cast<impl::HWComposer&>(mFlinger->getHwComposer()); |
| 487 | } |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 488 | auto& getCompositionEngine() const { return mFlinger->getCompositionEngine(); } |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 489 | |
Adithya Srinivasan | b238cd5 | 2021-02-04 17:54:05 +0000 | [diff] [blame] | 490 | mock::FrameTracer* getFrameTracer() const { |
| 491 | return static_cast<mock::FrameTracer*>(mFlinger->mFrameTracer.get()); |
| 492 | } |
| 493 | |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 494 | /* ------------------------------------------------------------------------ |
| 495 | * Read-write access to private data to set up preconditions and assert |
| 496 | * post-conditions. |
| 497 | */ |
Lloyd Pique | 0b1fe70 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 498 | |
Dominik Laskowski | eb62731 | 2022-04-07 09:13:16 -0700 | [diff] [blame] | 499 | const auto& displays() const { return mFlinger->mDisplays; } |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 500 | const auto& physicalDisplays() const { return mFlinger->mPhysicalDisplays; } |
Dominik Laskowski | eb62731 | 2022-04-07 09:13:16 -0700 | [diff] [blame] | 501 | const auto& currentState() const { return mFlinger->mCurrentState; } |
| 502 | const auto& drawingState() const { return mFlinger->mDrawingState; } |
| 503 | const auto& transactionFlags() const { return mFlinger->mTransactionFlags; } |
Dominik Laskowski | bab5128 | 2022-08-12 09:28:55 -0700 | [diff] [blame] | 504 | |
Dominik Laskowski | eb62731 | 2022-04-07 09:13:16 -0700 | [diff] [blame] | 505 | const auto& hwcPhysicalDisplayIdMap() const { return getHwComposer().mPhysicalDisplayIdMap; } |
Dominik Laskowski | bab5128 | 2022-08-12 09:28:55 -0700 | [diff] [blame] | 506 | const auto& hwcDisplayData() const { return getHwComposer().mDisplayData; } |
Dominik Laskowski | eb62731 | 2022-04-07 09:13:16 -0700 | [diff] [blame] | 507 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 508 | auto& mutableSupportsWideColor() { return mFlinger->mSupportsWideColor; } |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 509 | |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 510 | auto& mutableCurrentState() { return mFlinger->mCurrentState; } |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 511 | auto& mutableDisplayColorSetting() { return mFlinger->mDisplayColorSetting; } |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 512 | auto& mutableDisplays() { return mFlinger->mDisplays; } |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 513 | auto& mutablePhysicalDisplays() { return mFlinger->mPhysicalDisplays; } |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 514 | auto& mutableDrawingState() { return mFlinger->mDrawingState; } |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 515 | auto& mutableGeometryDirty() { return mFlinger->mGeometryDirty; } |
Lloyd Pique | 0b1fe70 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 516 | auto& mutableInterceptor() { return mFlinger->mInterceptor; } |
Lloyd Pique | 6cf1103 | 2018-01-22 18:57:44 -0800 | [diff] [blame] | 517 | auto& mutableMainThreadId() { return mFlinger->mMainThreadId; } |
Lloyd Pique | 0b1fe70 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 518 | auto& mutablePendingHotplugEvents() { return mFlinger->mPendingHotplugEvents; } |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 519 | auto& mutableTexturePool() { return mFlinger->mTexturePool; } |
Lloyd Pique | 0b1fe70 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 520 | auto& mutableTransactionFlags() { return mFlinger->mTransactionFlags; } |
Lloyd Pique | 4fe2940 | 2019-08-12 16:51:24 -0700 | [diff] [blame] | 521 | auto& mutableDebugDisableHWC() { return mFlinger->mDebugDisableHWC; } |
Garfield Tan | 9c9c191 | 2021-07-19 12:02:16 -0700 | [diff] [blame] | 522 | auto& mutableMaxRenderTargetSize() { return mFlinger->mMaxRenderTargetSize; } |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 523 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 524 | auto& mutableHwcDisplayData() { return getHwComposer().mDisplayData; } |
| 525 | auto& mutableHwcPhysicalDisplayIdMap() { return getHwComposer().mPhysicalDisplayIdMap; } |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 526 | auto& mutablePrimaryHwcDisplayId() { return getHwComposer().mPrimaryHwcDisplayId; } |
Ady Abraham | adc914c | 2021-10-13 17:04:27 -0700 | [diff] [blame] | 527 | auto& mutableActiveDisplayToken() { return mFlinger->mActiveDisplayToken; } |
Lloyd Pique | a618d85 | 2018-01-17 11:52:30 -0800 | [diff] [blame] | 528 | |
Valerie Hau | 09e6005 | 2019-12-15 14:51:15 -0800 | [diff] [blame] | 529 | auto fromHandle(const sp<IBinder>& handle) { |
Valerie Hau | 09e6005 | 2019-12-15 14:51:15 -0800 | [diff] [blame] | 530 | return mFlinger->fromHandle(handle); |
| 531 | } |
| 532 | |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 533 | ~TestableSurfaceFlinger() { |
| 534 | // All these pointer and container clears help ensure that GMock does |
| 535 | // not report a leaked object, since the SurfaceFlinger instance may |
| 536 | // still be referenced by something despite our best efforts to destroy |
| 537 | // it after each test is done. |
| 538 | mutableDisplays().clear(); |
Ady Abraham | 2939f09 | 2019-03-04 17:44:06 -0800 | [diff] [blame] | 539 | mutableCurrentState().displays.clear(); |
| 540 | mutableDrawingState().displays.clear(); |
Pablo Gamito | 5cfc6e5 | 2020-09-10 11:18:03 +0000 | [diff] [blame] | 541 | mutableInterceptor().clear(); |
Lloyd Pique | 2eb71eb | 2019-08-13 13:23:03 -0700 | [diff] [blame] | 542 | mFlinger->mScheduler.reset(); |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 543 | mFlinger->mCompositionEngine->setHwComposer(std::unique_ptr<HWComposer>()); |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 544 | mFlinger->mCompositionEngine->setRenderEngine( |
| 545 | std::unique_ptr<renderengine::RenderEngine>()); |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 546 | } |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 547 | |
Lloyd Pique | a618d85 | 2018-01-17 11:52:30 -0800 | [diff] [blame] | 548 | /* ------------------------------------------------------------------------ |
| 549 | * Wrapper classes for Read-write access to private data to set up |
| 550 | * preconditions and assert post-conditions. |
| 551 | */ |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 552 | struct HWC2Display : public HWC2::impl::Display { |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 553 | HWC2Display( |
| 554 | Hwc2::Composer& composer, |
| 555 | const std::unordered_set<aidl::android::hardware::graphics::composer3::Capability>& |
| 556 | capabilities, |
| 557 | hal::HWDisplayId id, hal::DisplayType type) |
Peiyong Lin | 74ca2f4 | 2019-01-14 19:36:57 -0800 | [diff] [blame] | 558 | : HWC2::impl::Display(composer, capabilities, id, type) {} |
Lloyd Pique | a618d85 | 2018-01-17 11:52:30 -0800 | [diff] [blame] | 559 | ~HWC2Display() { |
| 560 | // Prevents a call to disable vsyncs. |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 561 | mType = hal::DisplayType::INVALID; |
Lloyd Pique | a618d85 | 2018-01-17 11:52:30 -0800 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | auto& mutableIsConnected() { return this->mIsConnected; } |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 565 | auto& mutableLayers() { return this->mLayers; } |
Lloyd Pique | a618d85 | 2018-01-17 11:52:30 -0800 | [diff] [blame] | 566 | }; |
| 567 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 568 | class FakeHwcDisplayInjector { |
| 569 | public: |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 570 | static constexpr hal::HWDisplayId DEFAULT_HWC_DISPLAY_ID = 1000; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 571 | static constexpr ui::Size DEFAULT_RESOLUTION{1920, 1280}; |
Marin Shalamanov | c7e9f82 | 2021-11-16 20:07:55 +0100 | [diff] [blame] | 572 | static constexpr int32_t DEFAULT_VSYNC_PERIOD = 16'666'667; |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 573 | static constexpr int32_t DEFAULT_CONFIG_GROUP = 7; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 574 | static constexpr int32_t DEFAULT_DPI = 320; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 575 | static constexpr hal::HWConfigId DEFAULT_ACTIVE_CONFIG = 0; |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 576 | static constexpr hal::PowerMode DEFAULT_POWER_MODE = hal::PowerMode::ON; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 577 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 578 | FakeHwcDisplayInjector(HalDisplayId displayId, hal::DisplayType hwcDisplayType, |
| 579 | bool isPrimary) |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 580 | : mDisplayId(displayId), mHwcDisplayType(hwcDisplayType), mIsPrimary(isPrimary) {} |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 581 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 582 | auto& setHwcDisplayId(hal::HWDisplayId displayId) { |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 583 | mHwcDisplayId = displayId; |
| 584 | return *this; |
| 585 | } |
| 586 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 587 | auto& setResolution(ui::Size resolution) { |
| 588 | mResolution = resolution; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 589 | return *this; |
| 590 | } |
| 591 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 592 | auto& setVsyncPeriod(nsecs_t vsyncPeriod) { |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 593 | mVsyncPeriod = vsyncPeriod; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 594 | return *this; |
| 595 | } |
| 596 | |
| 597 | auto& setDpiX(int32_t dpi) { |
| 598 | mDpiX = dpi; |
| 599 | return *this; |
| 600 | } |
| 601 | |
| 602 | auto& setDpiY(int32_t dpi) { |
| 603 | mDpiY = dpi; |
| 604 | return *this; |
| 605 | } |
| 606 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 607 | auto& setActiveConfig(hal::HWConfigId config) { |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 608 | mActiveConfig = config; |
| 609 | return *this; |
| 610 | } |
| 611 | |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 612 | auto& setCapabilities( |
| 613 | const std::unordered_set<aidl::android::hardware::graphics::composer3::Capability>* |
| 614 | capabilities) { |
Lloyd Pique | e22f033 | 2018-07-16 16:35:56 -0700 | [diff] [blame] | 615 | mCapabilities = capabilities; |
| 616 | return *this; |
| 617 | } |
| 618 | |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 619 | auto& setPowerMode(hal::PowerMode mode) { |
Peiyong Lin | 1336e6e | 2019-05-28 09:23:50 -0700 | [diff] [blame] | 620 | mPowerMode = mode; |
| 621 | return *this; |
| 622 | } |
| 623 | |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 624 | void inject(TestableSurfaceFlinger* flinger, Hwc2::mock::Composer* composer) { |
| 625 | using ::testing::_; |
| 626 | using ::testing::DoAll; |
| 627 | using ::testing::Return; |
| 628 | using ::testing::SetArgPointee; |
| 629 | |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 630 | static const std::unordered_set< |
| 631 | aidl::android::hardware::graphics::composer3::Capability> |
| 632 | defaultCapabilities; |
Lloyd Pique | e22f033 | 2018-07-16 16:35:56 -0700 | [diff] [blame] | 633 | if (mCapabilities == nullptr) mCapabilities = &defaultCapabilities; |
| 634 | |
| 635 | // Caution - Make sure that any values passed by reference here do |
| 636 | // not refer to an instance owned by FakeHwcDisplayInjector. This |
| 637 | // class has temporary lifetime, while the constructed HWC2::Display |
| 638 | // is much longer lived. |
Peiyong Lin | 74ca2f4 | 2019-01-14 19:36:57 -0800 | [diff] [blame] | 639 | auto display = std::make_unique<HWC2Display>(*composer, *mCapabilities, mHwcDisplayId, |
| 640 | mHwcDisplayType); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 641 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 642 | display->mutableIsConnected() = true; |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 643 | display->setPowerMode(mPowerMode); |
Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 644 | flinger->mutableHwcDisplayData()[mDisplayId].hwcDisplay = std::move(display); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 645 | |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 646 | EXPECT_CALL(*composer, getDisplayConfigs(mHwcDisplayId, _)) |
| 647 | .WillRepeatedly( |
| 648 | DoAll(SetArgPointee<1>(std::vector<hal::HWConfigId>{mActiveConfig}), |
| 649 | Return(hal::Error::NONE))); |
| 650 | |
| 651 | EXPECT_CALL(*composer, |
| 652 | getDisplayAttribute(mHwcDisplayId, mActiveConfig, hal::Attribute::WIDTH, _)) |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 653 | .WillRepeatedly(DoAll(SetArgPointee<3>(mResolution.getWidth()), |
| 654 | Return(hal::Error::NONE))); |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 655 | |
| 656 | EXPECT_CALL(*composer, |
| 657 | getDisplayAttribute(mHwcDisplayId, mActiveConfig, hal::Attribute::HEIGHT, |
| 658 | _)) |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 659 | .WillRepeatedly(DoAll(SetArgPointee<3>(mResolution.getHeight()), |
| 660 | Return(hal::Error::NONE))); |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 661 | |
| 662 | EXPECT_CALL(*composer, |
| 663 | getDisplayAttribute(mHwcDisplayId, mActiveConfig, |
| 664 | hal::Attribute::VSYNC_PERIOD, _)) |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 665 | .WillRepeatedly(DoAll(SetArgPointee<3>(static_cast<int32_t>(mVsyncPeriod)), |
| 666 | Return(hal::Error::NONE))); |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 667 | |
| 668 | EXPECT_CALL(*composer, |
| 669 | getDisplayAttribute(mHwcDisplayId, mActiveConfig, hal::Attribute::DPI_X, _)) |
| 670 | .WillRepeatedly(DoAll(SetArgPointee<3>(mDpiX), Return(hal::Error::NONE))); |
| 671 | |
| 672 | EXPECT_CALL(*composer, |
| 673 | getDisplayAttribute(mHwcDisplayId, mActiveConfig, hal::Attribute::DPI_Y, _)) |
| 674 | .WillRepeatedly(DoAll(SetArgPointee<3>(mDpiY), Return(hal::Error::NONE))); |
| 675 | |
| 676 | EXPECT_CALL(*composer, |
| 677 | getDisplayAttribute(mHwcDisplayId, mActiveConfig, |
| 678 | hal::Attribute::CONFIG_GROUP, _)) |
| 679 | .WillRepeatedly( |
| 680 | DoAll(SetArgPointee<3>(mConfigGroup), Return(hal::Error::NONE))); |
Marin Shalamanov | 3ea1d60 | 2020-12-16 19:59:39 +0100 | [diff] [blame] | 681 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 682 | if (mHwcDisplayType == hal::DisplayType::PHYSICAL) { |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 683 | const auto physicalId = PhysicalDisplayId::tryCast(mDisplayId); |
| 684 | LOG_ALWAYS_FATAL_IF(!physicalId); |
| 685 | flinger->mutableHwcPhysicalDisplayIdMap().emplace(mHwcDisplayId, *physicalId); |
Marin Shalamanov | 6e84017 | 2020-12-14 22:13:28 +0100 | [diff] [blame] | 686 | if (mIsPrimary) { |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 687 | flinger->mutablePrimaryHwcDisplayId() = mHwcDisplayId; |
Marin Shalamanov | 6e84017 | 2020-12-14 22:13:28 +0100 | [diff] [blame] | 688 | } else { |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 689 | // If there is an external HWC display, there should always be a primary ID |
Marin Shalamanov | 6e84017 | 2020-12-14 22:13:28 +0100 | [diff] [blame] | 690 | // as well. Set it to some arbitrary value. |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 691 | auto& primaryId = flinger->mutablePrimaryHwcDisplayId(); |
| 692 | if (!primaryId) primaryId = mHwcDisplayId - 1; |
Marin Shalamanov | 6e84017 | 2020-12-14 22:13:28 +0100 | [diff] [blame] | 693 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 694 | } |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 695 | } |
| 696 | |
| 697 | private: |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 698 | const HalDisplayId mDisplayId; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 699 | const hal::DisplayType mHwcDisplayType; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 700 | const bool mIsPrimary; |
| 701 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 702 | hal::HWDisplayId mHwcDisplayId = DEFAULT_HWC_DISPLAY_ID; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 703 | ui::Size mResolution = DEFAULT_RESOLUTION; |
| 704 | nsecs_t mVsyncPeriod = DEFAULT_VSYNC_PERIOD; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 705 | int32_t mDpiX = DEFAULT_DPI; |
| 706 | int32_t mDpiY = DEFAULT_DPI; |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 707 | int32_t mConfigGroup = DEFAULT_CONFIG_GROUP; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 708 | hal::HWConfigId mActiveConfig = DEFAULT_ACTIVE_CONFIG; |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 709 | hal::PowerMode mPowerMode = DEFAULT_POWER_MODE; |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 710 | const std::unordered_set<aidl::android::hardware::graphics::composer3::Capability>* |
| 711 | mCapabilities = nullptr; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 712 | }; |
| 713 | |
| 714 | class FakeDisplayDeviceInjector { |
| 715 | public: |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 716 | FakeDisplayDeviceInjector(TestableSurfaceFlinger& flinger, |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 717 | std::shared_ptr<compositionengine::Display> display, |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 718 | std::optional<ui::DisplayConnectionType> connectionType, |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 719 | std::optional<hal::HWDisplayId> hwcDisplayId, bool isPrimary) |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 720 | : mFlinger(flinger), |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 721 | mCreationArgs(flinger.mFlinger, flinger.mFlinger->getHwComposer(), mDisplayToken, |
| 722 | display), |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 723 | mConnectionType(connectionType), |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 724 | mHwcDisplayId(hwcDisplayId) { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 725 | mCreationArgs.isPrimary = isPrimary; |
linpeter | 1c69cd3 | 2022-07-13 19:20:48 +0800 | [diff] [blame] | 726 | mCreationArgs.initialPowerMode = hal::PowerMode::ON; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 727 | } |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 728 | |
| 729 | sp<IBinder> token() const { return mDisplayToken; } |
| 730 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 731 | auto physicalDisplay() const { |
| 732 | return ftl::Optional(mCreationArgs.compositionDisplay->getDisplayId()) |
| 733 | .and_then(&PhysicalDisplayId::tryCast) |
| 734 | .and_then(display::getPhysicalDisplay(mFlinger.physicalDisplays())); |
| 735 | } |
| 736 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 737 | DisplayDeviceState& mutableDrawingDisplayState() { |
| 738 | return mFlinger.mutableDrawingState().displays.editValueFor(mDisplayToken); |
| 739 | } |
| 740 | |
| 741 | DisplayDeviceState& mutableCurrentDisplayState() { |
| 742 | return mFlinger.mutableCurrentState().displays.editValueFor(mDisplayToken); |
| 743 | } |
| 744 | |
Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 745 | const auto& getDrawingDisplayState() { |
| 746 | return mFlinger.mutableDrawingState().displays.valueFor(mDisplayToken); |
| 747 | } |
| 748 | |
| 749 | const auto& getCurrentDisplayState() { |
| 750 | return mFlinger.mutableCurrentState().displays.valueFor(mDisplayToken); |
| 751 | } |
| 752 | |
Dominik Laskowski | eb62731 | 2022-04-07 09:13:16 -0700 | [diff] [blame] | 753 | const sp<DisplayDevice>& mutableDisplayDevice() { |
| 754 | return mFlinger.mutableDisplays().get(mDisplayToken)->get(); |
| 755 | } |
Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 756 | |
Dominik Laskowski | 83bd771 | 2022-01-07 14:30:53 -0800 | [diff] [blame] | 757 | // If `configs` is nullptr, the injector creates RefreshRateConfigs from the `modes`. |
| 758 | // Otherwise, it uses `configs`, which the caller must create using the same `modes`. |
| 759 | // |
| 760 | // TODO(b/182939859): Once `modes` can be retrieved from RefreshRateConfigs, remove |
| 761 | // the `configs` parameter in favor of an alternative setRefreshRateConfigs API. |
| 762 | auto& setDisplayModes(DisplayModes modes, DisplayModeId activeModeId, |
| 763 | std::shared_ptr<scheduler::RefreshRateConfigs> configs = nullptr) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 764 | mDisplayModes = std::move(modes); |
Dominik Laskowski | 83bd771 | 2022-01-07 14:30:53 -0800 | [diff] [blame] | 765 | mCreationArgs.activeModeId = activeModeId; |
| 766 | mCreationArgs.refreshRateConfigs = std::move(configs); |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 767 | return *this; |
| 768 | } |
| 769 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 770 | auto& setNativeWindow(const sp<ANativeWindow>& nativeWindow) { |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 771 | mCreationArgs.nativeWindow = nativeWindow; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 772 | return *this; |
| 773 | } |
| 774 | |
Lloyd Pique | 542307f | 2018-10-19 13:24:08 -0700 | [diff] [blame] | 775 | auto& setDisplaySurface(const sp<compositionengine::DisplaySurface>& displaySurface) { |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 776 | mCreationArgs.displaySurface = displaySurface; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 777 | return *this; |
| 778 | } |
| 779 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 780 | auto& setSecure(bool secure) { |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 781 | mCreationArgs.isSecure = secure; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 782 | return *this; |
| 783 | } |
| 784 | |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 785 | auto& setPowerMode(hal::PowerMode mode) { |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 786 | mCreationArgs.initialPowerMode = mode; |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 787 | return *this; |
| 788 | } |
| 789 | |
Valerie Hau | 9758ae0 | 2018-10-09 16:05:09 -0700 | [diff] [blame] | 790 | auto& setHwcColorModes( |
| 791 | const std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>> |
| 792 | hwcColorModes) { |
| 793 | mCreationArgs.hwcColorModes = hwcColorModes; |
| 794 | return *this; |
| 795 | } |
| 796 | |
| 797 | auto& setHasWideColorGamut(bool hasWideColorGamut) { |
| 798 | mCreationArgs.hasWideColorGamut = hasWideColorGamut; |
| 799 | return *this; |
| 800 | } |
| 801 | |
Lloyd Pique | 3305047 | 2019-12-19 17:12:44 -0800 | [diff] [blame] | 802 | auto& setPhysicalOrientation(ui::Rotation orientation) { |
| 803 | mCreationArgs.physicalOrientation = orientation; |
| 804 | return *this; |
| 805 | } |
| 806 | |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 807 | sp<DisplayDevice> inject() NO_THREAD_SAFETY_ANALYSIS { |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 808 | const auto displayId = mCreationArgs.compositionDisplay->getDisplayId(); |
| 809 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 810 | auto& modes = mDisplayModes; |
Dominik Laskowski | 83bd771 | 2022-01-07 14:30:53 -0800 | [diff] [blame] | 811 | auto& activeModeId = mCreationArgs.activeModeId; |
| 812 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 813 | if (displayId && !mCreationArgs.refreshRateConfigs) { |
| 814 | if (const auto physicalId = PhysicalDisplayId::tryCast(*displayId)) { |
| 815 | if (modes.empty()) { |
| 816 | constexpr DisplayModeId kModeId{0}; |
| 817 | DisplayModePtr mode = |
| 818 | DisplayMode::Builder(FakeHwcDisplayInjector::DEFAULT_ACTIVE_CONFIG) |
| 819 | .setId(kModeId) |
| 820 | .setPhysicalDisplayId(*physicalId) |
| 821 | .setResolution(FakeHwcDisplayInjector::DEFAULT_RESOLUTION) |
| 822 | .setVsyncPeriod( |
| 823 | FakeHwcDisplayInjector::DEFAULT_VSYNC_PERIOD) |
| 824 | .setDpiX(FakeHwcDisplayInjector::DEFAULT_DPI) |
| 825 | .setDpiY(FakeHwcDisplayInjector::DEFAULT_DPI) |
| 826 | .setGroup(FakeHwcDisplayInjector::DEFAULT_CONFIG_GROUP) |
| 827 | .build(); |
Dominik Laskowski | 83bd771 | 2022-01-07 14:30:53 -0800 | [diff] [blame] | 828 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 829 | modes = ftl::init::map(kModeId, std::move(mode)); |
| 830 | activeModeId = kModeId; |
| 831 | } |
| 832 | |
| 833 | mCreationArgs.refreshRateConfigs = |
| 834 | std::make_shared<scheduler::RefreshRateConfigs>(modes, activeModeId); |
| 835 | } |
Dominik Laskowski | 83bd771 | 2022-01-07 14:30:53 -0800 | [diff] [blame] | 836 | } |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 837 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 838 | sp<DisplayDevice> display = sp<DisplayDevice>::make(mCreationArgs); |
| 839 | mFlinger.mutableDisplays().emplace_or_replace(mDisplayToken, display); |
| 840 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 841 | DisplayDeviceState state; |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 842 | state.isSecure = mCreationArgs.isSecure; |
| 843 | |
| 844 | if (mConnectionType) { |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 845 | LOG_ALWAYS_FATAL_IF(!displayId); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 846 | const auto physicalId = PhysicalDisplayId::tryCast(*displayId); |
| 847 | LOG_ALWAYS_FATAL_IF(!physicalId); |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 848 | LOG_ALWAYS_FATAL_IF(!mHwcDisplayId); |
Marin Shalamanov | c7e9f82 | 2021-11-16 20:07:55 +0100 | [diff] [blame] | 849 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 850 | const auto activeMode = modes.get(activeModeId); |
| 851 | LOG_ALWAYS_FATAL_IF(!activeMode); |
Dominik Laskowski | 83bd771 | 2022-01-07 14:30:53 -0800 | [diff] [blame] | 852 | |
Marin Shalamanov | c7e9f82 | 2021-11-16 20:07:55 +0100 | [diff] [blame] | 853 | state.physical = {.id = *physicalId, |
Marin Shalamanov | c7e9f82 | 2021-11-16 20:07:55 +0100 | [diff] [blame] | 854 | .hwcDisplayId = *mHwcDisplayId, |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 855 | .activeMode = activeMode->get()}; |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 856 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 857 | const auto it = mFlinger.mutablePhysicalDisplays() |
| 858 | .emplace_or_replace(*physicalId, mDisplayToken, *physicalId, |
| 859 | *mConnectionType, std::move(modes), |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 860 | ui::ColorModes(), std::nullopt) |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 861 | .first; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 862 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 863 | display->setActiveMode(activeModeId, it->second.snapshot()); |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 864 | } |
Dominik Laskowski | eb62731 | 2022-04-07 09:13:16 -0700 | [diff] [blame] | 865 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 866 | mFlinger.mutableCurrentState().displays.add(mDisplayToken, state); |
| 867 | mFlinger.mutableDrawingState().displays.add(mDisplayToken, state); |
| 868 | |
Dominik Laskowski | 83bd771 | 2022-01-07 14:30:53 -0800 | [diff] [blame] | 869 | return display; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 870 | } |
| 871 | |
| 872 | private: |
| 873 | TestableSurfaceFlinger& mFlinger; |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 874 | sp<BBinder> mDisplayToken = sp<BBinder>::make(); |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 875 | DisplayDeviceCreationArgs mCreationArgs; |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 876 | DisplayModes mDisplayModes; |
| 877 | const std::optional<ui::DisplayConnectionType> mConnectionType; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 878 | const std::optional<hal::HWDisplayId> mHwcDisplayId; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 879 | }; |
| 880 | |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 881 | private: |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 882 | static constexpr VsyncId kVsyncId{123}; |
Ady Abraham | 302ebed | 2022-03-07 16:03:41 -0800 | [diff] [blame] | 883 | |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 884 | surfaceflinger::test::Factory mFactory; |
Vishnu Nair | 4df8eb6 | 2022-02-17 15:32:02 -0800 | [diff] [blame] | 885 | sp<SurfaceFlinger> mFlinger; |
Dominik Laskowski | 83bd771 | 2022-01-07 14:30:53 -0800 | [diff] [blame] | 886 | scheduler::mock::SchedulerCallback mSchedulerCallback; |
| 887 | scheduler::mock::NoOpSchedulerCallback mNoOpSchedulerCallback; |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 888 | scheduler::TestableScheduler* mScheduler = nullptr; |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 889 | }; |
| 890 | |
| 891 | } // namespace android |