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