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