blob: 256e048feecf5ef9d5a5bf4488a866d8b2a851b0 [file] [log] [blame]
Lloyd Piquef58625d2017-12-19 13:22:33 -08001/*
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
Lloyd Pique37c2c9b2018-12-04 17:25:10 -080019#include <compositionengine/Display.h>
Lloyd Pique9755fb72019-03-26 14:44:40 -070020#include <compositionengine/LayerFECompositionState.h>
Lloyd Pique37c2c9b2018-12-04 17:25:10 -080021#include <compositionengine/OutputLayer.h>
Lloyd Pique70d91362018-10-18 16:02:55 -070022#include <compositionengine/impl/CompositionEngine.h>
Lloyd Pique9370a482019-10-03 17:58:30 -070023#include <compositionengine/impl/Display.h>
Lloyd Pique37c2c9b2018-12-04 17:25:10 -080024#include <compositionengine/impl/OutputLayerCompositionState.h>
Dominik Laskowskif7a09ed2019-10-07 13:54:18 -070025#include <compositionengine/mock/DisplaySurface.h>
Lloyd Pique70d91362018-10-18 16:02:55 -070026
Lloyd Pique90c115d2018-09-18 21:39:42 -070027#include "BufferQueueLayer.h"
28#include "BufferStateLayer.h"
Lloyd Pique90c115d2018-09-18 21:39:42 -070029#include "ContainerLayer.h"
Lloyd Piquef58625d2017-12-19 13:22:33 -080030#include "DisplayDevice.h"
Vishnu Nairfa247b12020-02-11 08:58:26 -080031#include "EffectLayer.h"
Ana Krulec757f63a2019-01-25 10:46:18 -080032#include "FakePhaseOffsets.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070033#include "Layer.h"
Lloyd Pique90c115d2018-09-18 21:39:42 -070034#include "NativeWindowSurface.h"
Dominik Laskowski9dab3432019-03-27 13:21:10 -070035#include "Scheduler/MessageQueue.h"
Steven Thomas2bbaabe2019-08-28 16:08:35 -070036#include "Scheduler/RefreshRateConfigs.h"
Lloyd Pique90c115d2018-09-18 21:39:42 -070037#include "StartPropertySetThread.h"
Lloyd Piquef58625d2017-12-19 13:22:33 -080038#include "SurfaceFlinger.h"
Lloyd Pique24f3bfe2019-10-02 19:29:10 -070039#include "SurfaceFlingerDefaultFactory.h"
Lloyd Pique90c115d2018-09-18 21:39:42 -070040#include "SurfaceInterceptor.h"
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -070041#include "TestableScheduler.h"
Ady Abrahamabc27602020-04-08 17:20:29 -070042#include "mock/DisplayHardware/MockDisplay.h"
Yiwei Zhang7e666a52018-11-15 13:33:42 -080043
Lloyd Piquef58625d2017-12-19 13:22:33 -080044namespace android {
45
Lloyd Piquee39cad22017-12-20 17:01:29 -080046class EventThread;
47
Peiyong Lin833074a2018-08-28 11:53:54 -070048namespace renderengine {
Lloyd Pique90c115d2018-09-18 21:39:42 -070049
Lloyd Piquee39cad22017-12-20 17:01:29 -080050class RenderEngine;
Lloyd Pique90c115d2018-09-18 21:39:42 -070051
52} // namespace renderengine
Lloyd Piquee39cad22017-12-20 17:01:29 -080053
54namespace Hwc2 {
Lloyd Pique90c115d2018-09-18 21:39:42 -070055
Lloyd Piquee39cad22017-12-20 17:01:29 -080056class Composer;
Lloyd Pique90c115d2018-09-18 21:39:42 -070057
58} // namespace Hwc2
59
Peiyong Line9d809e2020-04-14 13:10:48 -070060namespace hal = android::hardware::graphics::composer::hal;
61
Lloyd Pique90c115d2018-09-18 21:39:42 -070062namespace surfaceflinger::test {
63
64class Factory final : public surfaceflinger::Factory {
65public:
66 ~Factory() = default;
67
Dominik Laskowski98041832019-08-01 18:35:59 -070068 std::unique_ptr<DispSync> createDispSync(const char*, bool) override {
Lloyd Pique90c115d2018-09-18 21:39:42 -070069 return nullptr;
70 }
71
72 std::unique_ptr<EventControlThread> createEventControlThread(
73 std::function<void(bool)>) override {
Lloyd Pique90c115d2018-09-18 21:39:42 -070074 return nullptr;
75 }
76
77 std::unique_ptr<HWComposer> createHWComposer(const std::string&) override {
Lloyd Pique90c115d2018-09-18 21:39:42 -070078 return nullptr;
79 }
80
81 std::unique_ptr<MessageQueue> createMessageQueue() override {
Lloyd Pique90c115d2018-09-18 21:39:42 -070082 return std::make_unique<android::impl::MessageQueue>();
83 }
84
Ady Abraham9e16a482019-12-03 17:19:41 -080085 std::unique_ptr<scheduler::PhaseConfiguration> createPhaseConfiguration(
86 const scheduler::RefreshRateConfigs& /*refreshRateConfigs*/) override {
Ana Krulec757f63a2019-01-25 10:46:18 -080087 return std::make_unique<scheduler::FakePhaseOffsets>();
88 }
89
Ady Abraham09bd3922019-04-08 10:44:56 -070090 std::unique_ptr<Scheduler> createScheduler(std::function<void(bool)>,
Ady Abraham3a77a7b2019-12-02 18:46:59 -080091 const scheduler::RefreshRateConfigs&,
92 ISchedulerCallback&) override {
Lloyd Pique90c115d2018-09-18 21:39:42 -070093 return nullptr;
94 }
95
96 std::unique_ptr<SurfaceInterceptor> createSurfaceInterceptor(SurfaceFlinger* flinger) override {
Lloyd Pique90c115d2018-09-18 21:39:42 -070097 return std::make_unique<android::impl::SurfaceInterceptor>(flinger);
98 }
99
100 sp<StartPropertySetThread> createStartPropertySetThread(bool timestampPropertyValue) override {
Lloyd Pique90c115d2018-09-18 21:39:42 -0700101 return new StartPropertySetThread(timestampPropertyValue);
102 }
103
Lloyd Pique9370a482019-10-03 17:58:30 -0700104 sp<DisplayDevice> createDisplayDevice(DisplayDeviceCreationArgs& creationArgs) override {
105 return new DisplayDevice(creationArgs);
Lloyd Pique90c115d2018-09-18 21:39:42 -0700106 }
107
108 sp<GraphicBuffer> createGraphicBuffer(uint32_t width, uint32_t height, PixelFormat format,
109 uint32_t layerCount, uint64_t usage,
110 std::string requestorName) override {
Lloyd Pique90c115d2018-09-18 21:39:42 -0700111 return new GraphicBuffer(width, height, format, layerCount, usage, requestorName);
112 }
113
114 void createBufferQueue(sp<IGraphicBufferProducer>* outProducer,
115 sp<IGraphicBufferConsumer>* outConsumer,
116 bool consumerIsSurfaceFlinger) override {
Lloyd Piquee300b312019-10-03 13:03:45 -0700117 if (!mCreateBufferQueue) {
118 BufferQueue::createBufferQueue(outProducer, outConsumer, consumerIsSurfaceFlinger);
119 return;
120 }
Lloyd Pique90c115d2018-09-18 21:39:42 -0700121 mCreateBufferQueue(outProducer, outConsumer, consumerIsSurfaceFlinger);
122 }
123
Lloyd Piquee300b312019-10-03 13:03:45 -0700124 sp<IGraphicBufferProducer> createMonitoredProducer(const sp<IGraphicBufferProducer>& producer,
125 const sp<SurfaceFlinger>& flinger,
126 const wp<Layer>& layer) override {
127 return new MonitoredProducer(producer, flinger, layer);
128 }
129
130 sp<BufferLayerConsumer> createBufferLayerConsumer(const sp<IGraphicBufferConsumer>& consumer,
131 renderengine::RenderEngine& renderEngine,
132 uint32_t textureName, Layer* layer) override {
133 return new BufferLayerConsumer(consumer, renderEngine, textureName, layer);
134 }
135
Lloyd Pique90c115d2018-09-18 21:39:42 -0700136 std::unique_ptr<surfaceflinger::NativeWindowSurface> createNativeWindowSurface(
137 const sp<IGraphicBufferProducer>& producer) override {
138 if (!mCreateNativeWindowSurface) return nullptr;
139 return mCreateNativeWindowSurface(producer);
140 }
141
Lloyd Pique70d91362018-10-18 16:02:55 -0700142 std::unique_ptr<compositionengine::CompositionEngine> createCompositionEngine() override {
143 return compositionengine::impl::createCompositionEngine();
144 }
145
Lloyd Pique90c115d2018-09-18 21:39:42 -0700146 sp<BufferQueueLayer> createBufferQueueLayer(const LayerCreationArgs&) override {
Lloyd Pique90c115d2018-09-18 21:39:42 -0700147 return nullptr;
148 }
149
150 sp<BufferStateLayer> createBufferStateLayer(const LayerCreationArgs&) override {
Lloyd Pique90c115d2018-09-18 21:39:42 -0700151 return nullptr;
152 }
153
Vishnu Nairfa247b12020-02-11 08:58:26 -0800154 sp<EffectLayer> createEffectLayer(const LayerCreationArgs&) override { return nullptr; }
Lloyd Pique90c115d2018-09-18 21:39:42 -0700155
156 sp<ContainerLayer> createContainerLayer(const LayerCreationArgs&) override {
Lloyd Pique90c115d2018-09-18 21:39:42 -0700157 return nullptr;
158 }
159
160 using CreateBufferQueueFunction =
161 std::function<void(sp<IGraphicBufferProducer>* /* outProducer */,
162 sp<IGraphicBufferConsumer>* /* outConsumer */,
163 bool /* consumerIsSurfaceFlinger */)>;
164 CreateBufferQueueFunction mCreateBufferQueue;
165
166 using CreateNativeWindowSurfaceFunction =
167 std::function<std::unique_ptr<surfaceflinger::NativeWindowSurface>(
168 const sp<IGraphicBufferProducer>&)>;
169 CreateNativeWindowSurfaceFunction mCreateNativeWindowSurface;
Lloyd Pique70d91362018-10-18 16:02:55 -0700170
171 using CreateCompositionEngineFunction =
172 std::function<std::unique_ptr<compositionengine::CompositionEngine>()>;
173 CreateCompositionEngineFunction mCreateCompositionEngine;
Lloyd Pique90c115d2018-09-18 21:39:42 -0700174};
175
176} // namespace surfaceflinger::test
Lloyd Piquee39cad22017-12-20 17:01:29 -0800177
Lloyd Piquef58625d2017-12-19 13:22:33 -0800178class TestableSurfaceFlinger {
179public:
Dominik Laskowskib7251f42020-04-20 17:42:59 -0700180 using HotplugEvent = SurfaceFlinger::HotplugEvent;
181
Dominik Laskowskif7a09ed2019-10-07 13:54:18 -0700182 SurfaceFlinger* flinger() { return mFlinger.get(); }
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700183 TestableScheduler* scheduler() { return mScheduler; }
184
Lloyd Piquef58625d2017-12-19 13:22:33 -0800185 // Extend this as needed for accessing SurfaceFlinger private (and public)
186 // functions.
187
Peiyong Lin833074a2018-08-28 11:53:54 -0700188 void setupRenderEngine(std::unique_ptr<renderengine::RenderEngine> renderEngine) {
Lloyd Piqueb97e04f2018-10-18 17:07:05 -0700189 mFlinger->mCompositionEngine->setRenderEngine(std::move(renderEngine));
Lloyd Piquee39cad22017-12-20 17:01:29 -0800190 }
191
192 void setupComposer(std::unique_ptr<Hwc2::Composer> composer) {
Lloyd Pique441d5042018-10-18 16:49:51 -0700193 mFlinger->mCompositionEngine->setHwComposer(
194 std::make_unique<impl::HWComposer>(std::move(composer)));
Lloyd Piquee39cad22017-12-20 17:01:29 -0800195 }
196
Alec Mourie4034bb2019-11-19 12:45:54 -0800197 void setupTimeStats(const std::shared_ptr<TimeStats>& timeStats) {
198 mFlinger->mCompositionEngine->setTimeStats(timeStats);
199 }
200
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700201 void setupScheduler(std::unique_ptr<DispSync> primaryDispSync,
202 std::unique_ptr<EventControlThread> eventControlThread,
203 std::unique_ptr<EventThread> appEventThread,
Ady Abraham8a82ba62020-01-17 12:43:17 -0800204 std::unique_ptr<EventThread> sfEventThread,
Dominik Laskowski983f2b52020-06-25 16:54:06 -0700205 bool hasMultipleConfigs = false) {
Ady Abrahamabc27602020-04-08 17:20:29 -0700206 std::vector<std::shared_ptr<const HWC2::Display::Config>> configs{
207 HWC2::Display::Config::Builder(mDisplay, 0)
Dominik Laskowski983f2b52020-06-25 16:54:06 -0700208 .setVsyncPeriod(16'666'667)
Ady Abrahamabc27602020-04-08 17:20:29 -0700209 .setConfigGroup(0)
210 .build()};
211
Dominik Laskowski983f2b52020-06-25 16:54:06 -0700212 if (hasMultipleConfigs) {
213 configs.emplace_back(HWC2::Display::Config::Builder(mDisplay, 1)
214 .setVsyncPeriod(11'111'111)
215 .setConfigGroup(0)
216 .build());
217 }
218
Ady Abraham2139f732019-11-13 18:56:40 -0800219 mFlinger->mRefreshRateConfigs = std::make_unique<
Ana Krulec3f6a2062020-01-23 15:48:01 -0800220 scheduler::RefreshRateConfigs>(configs, /*currentConfig=*/HwcConfigIndexType(0));
Ady Abraham2139f732019-11-13 18:56:40 -0800221 mFlinger->mRefreshRateStats = std::make_unique<
222 scheduler::RefreshRateStats>(*mFlinger->mRefreshRateConfigs, *mFlinger->mTimeStats,
223 /*currentConfig=*/HwcConfigIndexType(0),
Peiyong Lin65248e02020-04-18 21:15:07 -0700224 /*powerMode=*/hal::PowerMode::OFF);
Ady Abraham9e16a482019-12-03 17:19:41 -0800225 mFlinger->mPhaseConfiguration =
226 mFactory.createPhaseConfiguration(*mFlinger->mRefreshRateConfigs);
Steven Thomas2bbaabe2019-08-28 16:08:35 -0700227
Dominik Laskowski983f2b52020-06-25 16:54:06 -0700228 constexpr bool kUseContentDetectionV2 = false;
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700229 mScheduler =
230 new TestableScheduler(std::move(primaryDispSync), std::move(eventControlThread),
Dominik Laskowski983f2b52020-06-25 16:54:06 -0700231 *mFlinger->mRefreshRateConfigs, kUseContentDetectionV2);
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700232
Dominik Laskowski98041832019-08-01 18:35:59 -0700233 mFlinger->mAppConnectionHandle = mScheduler->createConnection(std::move(appEventThread));
234 mFlinger->mSfConnectionHandle = mScheduler->createConnection(std::move(sfEventThread));
Dominik Laskowskif7a09ed2019-10-07 13:54:18 -0700235 resetScheduler(mScheduler);
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700236
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700237 mFlinger->mVSyncModulator.emplace(*mScheduler, mFlinger->mAppConnectionHandle,
238 mFlinger->mSfConnectionHandle,
Ady Abraham9e16a482019-12-03 17:19:41 -0800239 mFlinger->mPhaseConfiguration->getCurrentOffsets());
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700240 }
241
Dominik Laskowskif7a09ed2019-10-07 13:54:18 -0700242 void resetScheduler(Scheduler* scheduler) { mFlinger->mScheduler.reset(scheduler); }
243
Lloyd Pique90c115d2018-09-18 21:39:42 -0700244 using CreateBufferQueueFunction = surfaceflinger::test::Factory::CreateBufferQueueFunction;
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800245 void setCreateBufferQueueFunction(CreateBufferQueueFunction f) {
Lloyd Pique90c115d2018-09-18 21:39:42 -0700246 mFactory.mCreateBufferQueue = f;
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800247 }
248
Lloyd Pique90c115d2018-09-18 21:39:42 -0700249 using CreateNativeWindowSurfaceFunction =
250 surfaceflinger::test::Factory::CreateNativeWindowSurfaceFunction;
Lloyd Pique0b1fe702018-01-22 18:03:16 -0800251 void setCreateNativeWindowSurface(CreateNativeWindowSurfaceFunction f) {
Lloyd Pique90c115d2018-09-18 21:39:42 -0700252 mFactory.mCreateNativeWindowSurface = f;
Lloyd Pique0b1fe702018-01-22 18:03:16 -0800253 }
254
Daniel Solomon42d04562019-01-20 21:03:19 -0800255 void setInternalDisplayPrimaries(const ui::DisplayPrimaries& primaries) {
256 memcpy(&mFlinger->mInternalDisplayPrimaries, &primaries, sizeof(ui::DisplayPrimaries));
257 }
258
Dominik Laskowskib7251f42020-04-20 17:42:59 -0700259 static auto& mutableLayerCurrentState(const sp<Layer>& layer) { return layer->mCurrentState; }
260 static auto& mutableLayerDrawingState(const sp<Layer>& layer) { return layer->mDrawingState; }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700261
Valerie Haud251afb2019-03-29 14:19:02 -0700262 auto& mutableStateLock() { return mFlinger->mStateLock; }
263
Dominik Laskowskib7251f42020-04-20 17:42:59 -0700264 static auto findOutputLayerForDisplay(const sp<Layer>& layer,
265 const sp<const DisplayDevice>& display) {
266 return layer->findOutputLayerForDisplay(display.get());
267 }
268
269 static void setLayerSidebandStream(const sp<Layer>& layer,
270 const sp<NativeHandle>& sidebandStream) {
Lloyd Pique0449b0f2018-12-20 16:23:45 -0800271 layer->mDrawingState.sidebandStream = sidebandStream;
Lloyd Pique0b785d82018-12-04 17:25:27 -0800272 layer->mSidebandStream = sidebandStream;
Lloyd Piquede196652020-01-22 17:29:58 -0800273 layer->editCompositionState()->sidebandStream = sidebandStream;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700274 }
275
Dominik Laskowskib7251f42020-04-20 17:42:59 -0700276 void setLayerCompositionType(const sp<Layer>& layer, hal::Composition type) {
277 auto outputLayer = findOutputLayerForDisplay(layer, mFlinger->getDefaultDisplayDevice());
Lloyd Pique37c2c9b2018-12-04 17:25:10 -0800278 LOG_ALWAYS_FATAL_IF(!outputLayer);
279 auto& state = outputLayer->editState();
280 LOG_ALWAYS_FATAL_IF(!outputLayer->getState().hwc);
Peiyong Line9d809e2020-04-14 13:10:48 -0700281 (*state.hwc).hwcCompositionType = type;
Dominik Laskowskib7251f42020-04-20 17:42:59 -0700282 }
Lloyd Pique37c2c9b2018-12-04 17:25:10 -0800283
Dominik Laskowskib7251f42020-04-20 17:42:59 -0700284 static void setLayerPotentialCursor(const sp<Layer>& layer, bool potentialCursor) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700285 layer->mPotentialCursor = potentialCursor;
286 }
287
Lloyd Piquef58625d2017-12-19 13:22:33 -0800288 /* ------------------------------------------------------------------------
289 * Forwarding for functions being tested
290 */
Lloyd Pique0b1fe702018-01-22 18:03:16 -0800291
Lloyd Piquea482f992018-01-22 19:00:34 -0800292 auto createDisplay(const String8& displayName, bool secure) {
293 return mFlinger->createDisplay(displayName, secure);
294 }
295
Dominik Laskowskieecd6592018-05-29 10:25:41 -0700296 auto destroyDisplay(const sp<IBinder>& displayToken) {
297 return mFlinger->destroyDisplay(displayToken);
298 }
Lloyd Piquea482f992018-01-22 19:00:34 -0800299
Dominik Laskowski0a1435d2020-04-21 00:27:31 -0700300 auto resetDisplayState() NO_THREAD_SAFETY_ANALYSIS { return mFlinger->resetDisplayState(); }
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -0800301
Lloyd Pique9370a482019-10-03 17:58:30 -0700302 auto setupNewDisplayDeviceInternal(
303 const wp<IBinder>& displayToken,
304 std::shared_ptr<compositionengine::Display> compositionDisplay,
305 const DisplayDeviceState& state,
306 const sp<compositionengine::DisplaySurface>& dispSurface,
Dominik Laskowski0a1435d2020-04-21 00:27:31 -0700307 const sp<IGraphicBufferProducer>& producer) NO_THREAD_SAFETY_ANALYSIS {
Lloyd Pique9370a482019-10-03 17:58:30 -0700308 return mFlinger->setupNewDisplayDeviceInternal(displayToken, compositionDisplay, state,
309 dispSurface, producer);
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800310 }
311
Lloyd Pique0b1fe702018-01-22 18:03:16 -0800312 auto handleTransactionLocked(uint32_t transactionFlags) {
Vishnu Nairfa5f8df2019-02-13 17:02:51 -0800313 Mutex::Autolock _l(mFlinger->mStateLock);
Lloyd Pique0b1fe702018-01-22 18:03:16 -0800314 return mFlinger->handleTransactionLocked(transactionFlags);
315 }
Lloyd Piquef58625d2017-12-19 13:22:33 -0800316
Peiyong Line9d809e2020-04-14 13:10:48 -0700317 auto onHotplugReceived(int32_t sequenceId, hal::HWDisplayId display,
318 hal::Connection connection) {
Lloyd Pique6cf11032018-01-22 18:57:44 -0800319 return mFlinger->onHotplugReceived(sequenceId, display, connection);
320 }
321
Vishnu Nairce5d0cc2019-02-28 14:38:41 -0800322 auto setDisplayStateLocked(const DisplayState& s) {
323 Mutex::Autolock _l(mFlinger->mStateLock);
324 return mFlinger->setDisplayStateLocked(s);
325 }
Lloyd Pique9d9cf402018-02-16 17:47:13 -0800326
Dominik Laskowski83b88212018-12-11 13:34:06 -0800327 // Allow reading display state without locking, as if called on the SF main thread.
328 auto onInitializeDisplays() NO_THREAD_SAFETY_ANALYSIS {
329 return mFlinger->onInitializeDisplays();
330 }
Lloyd Pique86016da2018-03-01 16:09:38 -0800331
Lais Andrade3a6e47d2020-04-02 11:20:16 +0100332 auto notifyPowerBoost(int32_t boostId) { return mFlinger->notifyPowerBoost(boostId); }
333
Dominik Laskowski83b88212018-12-11 13:34:06 -0800334 // Allow reading display state without locking, as if called on the SF main thread.
335 auto setPowerModeInternal(const sp<DisplayDevice>& display,
Peiyong Lin65248e02020-04-18 21:15:07 -0700336 hal::PowerMode mode) NO_THREAD_SAFETY_ANALYSIS {
Dominik Laskowskie9774092018-12-11 10:04:24 -0800337 return mFlinger->setPowerModeInternal(display, mode);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -0800338 }
339
Ady Abraham0ed31c92020-04-16 11:48:45 -0700340 auto onMessageReceived(int32_t what) { return mFlinger->onMessageReceived(what, systemTime()); }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700341
Ana Krulecfc874ae2020-02-22 15:39:32 -0800342 auto captureScreenImplLocked(const RenderArea& renderArea,
343 SurfaceFlinger::TraverseLayersFunction traverseLayers,
344 const sp<GraphicBuffer>& buffer, bool useIdentityTransform,
Lucas Dupin9d763b72020-04-20 18:42:31 -0700345 bool forSystem, int* outSyncFd, bool regionSampling) {
Robert Carr108b2c72019-04-02 16:32:58 -0700346 bool ignored;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700347 return mFlinger->captureScreenImplLocked(renderArea, traverseLayers, buffer,
Robert Carr108b2c72019-04-02 16:32:58 -0700348 useIdentityTransform, forSystem, outSyncFd,
Lucas Dupin9d763b72020-04-20 18:42:31 -0700349 regionSampling, ignored);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700350 }
351
Marin Shalamanov1c434292020-06-12 01:47:29 +0200352 auto traverseLayersInLayerStack(ui::LayerStack layerStack,
353 const LayerVector::Visitor& visitor) {
354 return mFlinger->SurfaceFlinger::traverseLayersInLayerStack(layerStack, visitor);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700355 }
356
Daniel Solomon42d04562019-01-20 21:03:19 -0800357 auto getDisplayNativePrimaries(const sp<IBinder>& displayToken,
358 ui::DisplayPrimaries &primaries) {
359 return mFlinger->SurfaceFlinger::getDisplayNativePrimaries(displayToken, primaries);
360 }
361
Valerie Haud251afb2019-03-29 14:19:02 -0700362 auto& getTransactionQueue() { return mFlinger->mTransactionQueues; }
363
364 auto setTransactionState(const Vector<ComposerState>& states,
365 const Vector<DisplayState>& displays, uint32_t flags,
366 const sp<IBinder>& applyToken,
367 const InputWindowCommands& inputWindowCommands,
368 int64_t desiredPresentTime, const client_cache_t& uncacheBuffer,
369 bool hasListenerCallbacks,
370 std::vector<ListenerCallbacks>& listenerCallbacks) {
371 return mFlinger->setTransactionState(states, displays, flags, applyToken,
372 inputWindowCommands, desiredPresentTime, uncacheBuffer,
373 hasListenerCallbacks, listenerCallbacks);
374 }
375
376 auto flushTransactionQueues() { return mFlinger->flushTransactionQueues(); };
377
Lloyd Pique86016da2018-03-01 16:09:38 -0800378 /* ------------------------------------------------------------------------
379 * Read-only access to private data to assert post-conditions.
380 */
381
382 const auto& getAnimFrameTracker() const { return mFlinger->mAnimFrameTracker; }
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -0800383 const auto& getHasPoweredOff() const { return mFlinger->mHasPoweredOff; }
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -0800384 const auto& getVisibleRegionsDirty() const { return mFlinger->mVisibleRegionsDirty; }
Lloyd Pique441d5042018-10-18 16:49:51 -0700385 auto& getHwComposer() const {
386 return static_cast<impl::HWComposer&>(mFlinger->getHwComposer());
387 }
Lloyd Pique9370a482019-10-03 17:58:30 -0700388 auto& getCompositionEngine() const { return mFlinger->getCompositionEngine(); }
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -0800389
Lloyd Pique86016da2018-03-01 16:09:38 -0800390 const auto& getCompositorTiming() const { return mFlinger->getBE().mCompositorTiming; }
391
Lloyd Piquef58625d2017-12-19 13:22:33 -0800392 /* ------------------------------------------------------------------------
393 * Read-write access to private data to set up preconditions and assert
394 * post-conditions.
395 */
Lloyd Pique0b1fe702018-01-22 18:03:16 -0800396
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800397 auto& mutableHasWideColorDisplay() { return SurfaceFlinger::hasWideColorDisplay; }
Peiyong Lin13effd12018-07-24 17:01:47 -0700398 auto& mutableUseColorManagement() { return SurfaceFlinger::useColorManagement; }
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800399
Lloyd Piquee39cad22017-12-20 17:01:29 -0800400 auto& mutableCurrentState() { return mFlinger->mCurrentState; }
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800401 auto& mutableDisplayColorSetting() { return mFlinger->mDisplayColorSetting; }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700402 auto& mutableDisplays() { return mFlinger->mDisplays; }
Lloyd Piquee39cad22017-12-20 17:01:29 -0800403 auto& mutableDrawingState() { return mFlinger->mDrawingState; }
Lloyd Piquee39cad22017-12-20 17:01:29 -0800404 auto& mutableEventQueue() { return mFlinger->mEventQueue; }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700405 auto& mutableGeometryInvalid() { return mFlinger->mGeometryInvalid; }
Lloyd Pique0b1fe702018-01-22 18:03:16 -0800406 auto& mutableInterceptor() { return mFlinger->mInterceptor; }
Lloyd Pique6cf11032018-01-22 18:57:44 -0800407 auto& mutableMainThreadId() { return mFlinger->mMainThreadId; }
Lloyd Pique0b1fe702018-01-22 18:03:16 -0800408 auto& mutablePendingHotplugEvents() { return mFlinger->mPendingHotplugEvents; }
Dominik Laskowski075d3172018-05-24 15:50:06 -0700409 auto& mutablePhysicalDisplayTokens() { return mFlinger->mPhysicalDisplayTokens; }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700410 auto& mutableTexturePool() { return mFlinger->mTexturePool; }
Lloyd Pique0b1fe702018-01-22 18:03:16 -0800411 auto& mutableTransactionFlags() { return mFlinger->mTransactionFlags; }
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800412 auto& mutableUseHwcVirtualDisplays() { return mFlinger->mUseHwcVirtualDisplays; }
Peiyong Lin74ca2f42019-01-14 19:36:57 -0800413 auto& mutablePowerAdvisor() { return mFlinger->mPowerAdvisor; }
Lloyd Pique4fe29402019-08-12 16:51:24 -0700414 auto& mutableDebugDisableHWC() { return mFlinger->mDebugDisableHWC; }
Lloyd Piquee39cad22017-12-20 17:01:29 -0800415
Lloyd Pique6cf11032018-01-22 18:57:44 -0800416 auto& mutableComposerSequenceId() { return mFlinger->getBE().mComposerSequenceId; }
Lloyd Pique441d5042018-10-18 16:49:51 -0700417 auto& mutableHwcDisplayData() { return getHwComposer().mDisplayData; }
418 auto& mutableHwcPhysicalDisplayIdMap() { return getHwComposer().mPhysicalDisplayIdMap; }
419 auto& mutableInternalHwcDisplayId() { return getHwComposer().mInternalHwcDisplayId; }
420 auto& mutableExternalHwcDisplayId() { return getHwComposer().mExternalHwcDisplayId; }
Ady Abraham60e42ea2020-03-09 19:17:31 -0700421 auto& mutableUseFrameRateApi() { return mFlinger->useFrameRateApi; }
Lloyd Piquea618d852018-01-17 11:52:30 -0800422
Valerie Hau09e60052019-12-15 14:51:15 -0800423 auto fromHandle(const sp<IBinder>& handle) {
Valerie Hau09e60052019-12-15 14:51:15 -0800424 return mFlinger->fromHandle(handle);
425 }
426
Lloyd Piquee39cad22017-12-20 17:01:29 -0800427 ~TestableSurfaceFlinger() {
428 // All these pointer and container clears help ensure that GMock does
429 // not report a leaked object, since the SurfaceFlinger instance may
430 // still be referenced by something despite our best efforts to destroy
431 // it after each test is done.
432 mutableDisplays().clear();
Ady Abraham2939f092019-03-04 17:44:06 -0800433 mutableCurrentState().displays.clear();
434 mutableDrawingState().displays.clear();
Lloyd Pique0b1fe702018-01-22 18:03:16 -0800435 mutableEventQueue().reset();
Lloyd Pique0b1fe702018-01-22 18:03:16 -0800436 mutableInterceptor().reset();
Lloyd Pique2eb71eb2019-08-13 13:23:03 -0700437 mFlinger->mScheduler.reset();
Lloyd Pique441d5042018-10-18 16:49:51 -0700438 mFlinger->mCompositionEngine->setHwComposer(std::unique_ptr<HWComposer>());
Lloyd Piqueb97e04f2018-10-18 17:07:05 -0700439 mFlinger->mCompositionEngine->setRenderEngine(
440 std::unique_ptr<renderengine::RenderEngine>());
Lloyd Piquee39cad22017-12-20 17:01:29 -0800441 }
Lloyd Piquef58625d2017-12-19 13:22:33 -0800442
Lloyd Piquea618d852018-01-17 11:52:30 -0800443 /* ------------------------------------------------------------------------
444 * Wrapper classes for Read-write access to private data to set up
445 * preconditions and assert post-conditions.
446 */
Ana Krulec4593b692019-01-11 22:07:25 -0800447 struct HWC2Display : public HWC2::impl::Display {
Peiyong Lin74ca2f42019-01-14 19:36:57 -0800448 HWC2Display(Hwc2::Composer& composer,
Peiyong Line9d809e2020-04-14 13:10:48 -0700449 const std::unordered_set<hal::Capability>& capabilities, hal::HWDisplayId id,
450 hal::DisplayType type)
Peiyong Lin74ca2f42019-01-14 19:36:57 -0800451 : HWC2::impl::Display(composer, capabilities, id, type) {}
Lloyd Piquea618d852018-01-17 11:52:30 -0800452 ~HWC2Display() {
453 // Prevents a call to disable vsyncs.
Peiyong Line9d809e2020-04-14 13:10:48 -0700454 mType = hal::DisplayType::INVALID;
Lloyd Piquea618d852018-01-17 11:52:30 -0800455 }
456
457 auto& mutableIsConnected() { return this->mIsConnected; }
458 auto& mutableConfigs() { return this->mConfigs; }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700459 auto& mutableLayers() { return this->mLayers; }
Lloyd Piquea618d852018-01-17 11:52:30 -0800460 };
461
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800462 class FakeHwcDisplayInjector {
463 public:
Peiyong Line9d809e2020-04-14 13:10:48 -0700464 static constexpr hal::HWDisplayId DEFAULT_HWC_DISPLAY_ID = 1000;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800465 static constexpr int32_t DEFAULT_WIDTH = 1920;
466 static constexpr int32_t DEFAULT_HEIGHT = 1280;
467 static constexpr int32_t DEFAULT_REFRESH_RATE = 16'666'666;
Ady Abraham2139f732019-11-13 18:56:40 -0800468 static constexpr int32_t DEFAULT_CONFIG_GROUP = 7;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800469 static constexpr int32_t DEFAULT_DPI = 320;
Peiyong Line9d809e2020-04-14 13:10:48 -0700470 static constexpr hal::HWConfigId DEFAULT_ACTIVE_CONFIG = 0;
Peiyong Lin65248e02020-04-18 21:15:07 -0700471 static constexpr hal::PowerMode DEFAULT_POWER_MODE = hal::PowerMode::ON;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800472
Peiyong Line9d809e2020-04-14 13:10:48 -0700473 FakeHwcDisplayInjector(DisplayId displayId, hal::DisplayType hwcDisplayType, bool isPrimary)
Dominik Laskowski075d3172018-05-24 15:50:06 -0700474 : mDisplayId(displayId), mHwcDisplayType(hwcDisplayType), mIsPrimary(isPrimary) {}
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800475
Peiyong Line9d809e2020-04-14 13:10:48 -0700476 auto& setHwcDisplayId(hal::HWDisplayId displayId) {
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800477 mHwcDisplayId = displayId;
478 return *this;
479 }
480
481 auto& setWidth(int32_t width) {
482 mWidth = width;
483 return *this;
484 }
485
486 auto& setHeight(int32_t height) {
487 mHeight = height;
488 return *this;
489 }
490
Ady Abraham8a82ba62020-01-17 12:43:17 -0800491 auto& setRefreshRate(int32_t refreshRate) {
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800492 mRefreshRate = refreshRate;
493 return *this;
494 }
495
496 auto& setDpiX(int32_t dpi) {
497 mDpiX = dpi;
498 return *this;
499 }
500
501 auto& setDpiY(int32_t dpi) {
502 mDpiY = dpi;
503 return *this;
504 }
505
Peiyong Line9d809e2020-04-14 13:10:48 -0700506 auto& setActiveConfig(hal::HWConfigId config) {
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800507 mActiveConfig = config;
508 return *this;
509 }
510
Peiyong Line9d809e2020-04-14 13:10:48 -0700511 auto& setCapabilities(const std::unordered_set<hal::Capability>* capabilities) {
Lloyd Piquee22f0332018-07-16 16:35:56 -0700512 mCapabilities = capabilities;
513 return *this;
514 }
515
Peiyong Lin65248e02020-04-18 21:15:07 -0700516 auto& setPowerMode(hal::PowerMode mode) {
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700517 mPowerMode = mode;
518 return *this;
519 }
520
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800521 void inject(TestableSurfaceFlinger* flinger, Hwc2::Composer* composer) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700522 static const std::unordered_set<hal::Capability> defaultCapabilities;
Lloyd Piquee22f0332018-07-16 16:35:56 -0700523 if (mCapabilities == nullptr) mCapabilities = &defaultCapabilities;
524
525 // Caution - Make sure that any values passed by reference here do
526 // not refer to an instance owned by FakeHwcDisplayInjector. This
527 // class has temporary lifetime, while the constructed HWC2::Display
528 // is much longer lived.
Peiyong Lin74ca2f42019-01-14 19:36:57 -0800529 auto display = std::make_unique<HWC2Display>(*composer, *mCapabilities, mHwcDisplayId,
530 mHwcDisplayType);
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800531
532 auto config = HWC2::Display::Config::Builder(*display, mActiveConfig);
533 config.setWidth(mWidth);
534 config.setHeight(mHeight);
535 config.setVsyncPeriod(mRefreshRate);
536 config.setDpiX(mDpiX);
537 config.setDpiY(mDpiY);
Ady Abraham2139f732019-11-13 18:56:40 -0800538 config.setConfigGroup(mConfigGroup);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800539 display->mutableConfigs().emplace(static_cast<int32_t>(mActiveConfig), config.build());
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800540 display->mutableIsConnected() = true;
Peiyong Lin65248e02020-04-18 21:15:07 -0700541 display->setPowerMode(mPowerMode);
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800542
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800543 flinger->mutableHwcDisplayData()[mDisplayId].hwcDisplay = std::move(display);
Dominik Laskowski075d3172018-05-24 15:50:06 -0700544
Peiyong Line9d809e2020-04-14 13:10:48 -0700545 if (mHwcDisplayType == hal::DisplayType::PHYSICAL) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700546 flinger->mutableHwcPhysicalDisplayIdMap().emplace(mHwcDisplayId, mDisplayId);
547 (mIsPrimary ? flinger->mutableInternalHwcDisplayId()
548 : flinger->mutableExternalHwcDisplayId()) = mHwcDisplayId;
549 }
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800550 }
551
552 private:
Dominik Laskowski075d3172018-05-24 15:50:06 -0700553 const DisplayId mDisplayId;
Peiyong Line9d809e2020-04-14 13:10:48 -0700554 const hal::DisplayType mHwcDisplayType;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700555 const bool mIsPrimary;
556
Peiyong Line9d809e2020-04-14 13:10:48 -0700557 hal::HWDisplayId mHwcDisplayId = DEFAULT_HWC_DISPLAY_ID;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800558 int32_t mWidth = DEFAULT_WIDTH;
559 int32_t mHeight = DEFAULT_HEIGHT;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800560 int32_t mRefreshRate = DEFAULT_REFRESH_RATE;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800561 int32_t mDpiX = DEFAULT_DPI;
Ady Abraham2139f732019-11-13 18:56:40 -0800562 int32_t mConfigGroup = DEFAULT_CONFIG_GROUP;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800563 int32_t mDpiY = DEFAULT_DPI;
Peiyong Line9d809e2020-04-14 13:10:48 -0700564 hal::HWConfigId mActiveConfig = DEFAULT_ACTIVE_CONFIG;
Peiyong Lin65248e02020-04-18 21:15:07 -0700565 hal::PowerMode mPowerMode = DEFAULT_POWER_MODE;
Peiyong Line9d809e2020-04-14 13:10:48 -0700566 const std::unordered_set<hal::Capability>* mCapabilities = nullptr;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800567 };
568
569 class FakeDisplayDeviceInjector {
570 public:
Dominik Laskowski075d3172018-05-24 15:50:06 -0700571 FakeDisplayDeviceInjector(TestableSurfaceFlinger& flinger,
Lloyd Pique9370a482019-10-03 17:58:30 -0700572 std::shared_ptr<compositionengine::Display> compositionDisplay,
Dominik Laskowski55c85402020-01-21 16:25:47 -0800573 std::optional<DisplayConnectionType> connectionType,
Peiyong Line9d809e2020-04-14 13:10:48 -0700574 std::optional<hal::HWDisplayId> hwcDisplayId, bool isPrimary)
Lloyd Pique9370a482019-10-03 17:58:30 -0700575 : mFlinger(flinger),
Marin Shalamanov700e6392020-02-12 20:22:26 +0100576 mCreationArgs(flinger.mFlinger.get(), mDisplayToken, compositionDisplay),
577 mHwcDisplayId(hwcDisplayId) {
Dominik Laskowski55c85402020-01-21 16:25:47 -0800578 mCreationArgs.connectionType = connectionType;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700579 mCreationArgs.isPrimary = isPrimary;
580 }
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800581
582 sp<IBinder> token() const { return mDisplayToken; }
583
584 DisplayDeviceState& mutableDrawingDisplayState() {
585 return mFlinger.mutableDrawingState().displays.editValueFor(mDisplayToken);
586 }
587
588 DisplayDeviceState& mutableCurrentDisplayState() {
589 return mFlinger.mutableCurrentState().displays.editValueFor(mDisplayToken);
590 }
591
Lloyd Pique9d9cf402018-02-16 17:47:13 -0800592 const auto& getDrawingDisplayState() {
593 return mFlinger.mutableDrawingState().displays.valueFor(mDisplayToken);
594 }
595
596 const auto& getCurrentDisplayState() {
597 return mFlinger.mutableCurrentState().displays.valueFor(mDisplayToken);
598 }
599
Dominik Laskowski9fae1022018-05-29 13:17:40 -0700600 auto& mutableDisplayDevice() { return mFlinger.mutableDisplays()[mDisplayToken]; }
Lloyd Pique9d9cf402018-02-16 17:47:13 -0800601
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800602 auto& setNativeWindow(const sp<ANativeWindow>& nativeWindow) {
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700603 mCreationArgs.nativeWindow = nativeWindow;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800604 return *this;
605 }
606
Lloyd Pique542307f2018-10-19 13:24:08 -0700607 auto& setDisplaySurface(const sp<compositionengine::DisplaySurface>& displaySurface) {
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700608 mCreationArgs.displaySurface = displaySurface;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800609 return *this;
610 }
611
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800612 auto& setSecure(bool secure) {
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700613 mCreationArgs.isSecure = secure;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800614 return *this;
615 }
616
Peiyong Lin65248e02020-04-18 21:15:07 -0700617 auto& setPowerMode(hal::PowerMode mode) {
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700618 mCreationArgs.initialPowerMode = mode;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700619 return *this;
620 }
621
Valerie Hau9758ae02018-10-09 16:05:09 -0700622 auto& setHwcColorModes(
623 const std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>>
624 hwcColorModes) {
625 mCreationArgs.hwcColorModes = hwcColorModes;
626 return *this;
627 }
628
629 auto& setHasWideColorGamut(bool hasWideColorGamut) {
630 mCreationArgs.hasWideColorGamut = hasWideColorGamut;
631 return *this;
632 }
633
Lloyd Pique33050472019-12-19 17:12:44 -0800634 auto& setPhysicalOrientation(ui::Rotation orientation) {
635 mCreationArgs.physicalOrientation = orientation;
636 return *this;
637 }
638
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800639 sp<DisplayDevice> inject() {
Lloyd Pique9370a482019-10-03 17:58:30 -0700640 const auto displayId = mCreationArgs.compositionDisplay->getDisplayId();
641
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800642 DisplayDeviceState state;
Dominik Laskowski55c85402020-01-21 16:25:47 -0800643 if (const auto type = mCreationArgs.connectionType) {
Lloyd Pique9370a482019-10-03 17:58:30 -0700644 LOG_ALWAYS_FATAL_IF(!displayId);
Marin Shalamanov700e6392020-02-12 20:22:26 +0100645 LOG_ALWAYS_FATAL_IF(!mHwcDisplayId);
Marin Shalamanov7ce87642020-05-06 13:45:58 +0200646 state.physical = {.id = *displayId, .type = *type, .hwcDisplayId = *mHwcDisplayId};
Dominik Laskowski55c85402020-01-21 16:25:47 -0800647 }
648
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700649 state.isSecure = mCreationArgs.isSecure;
650
Lloyd Pique9370a482019-10-03 17:58:30 -0700651 sp<DisplayDevice> device = new DisplayDevice(mCreationArgs);
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700652 mFlinger.mutableDisplays().emplace(mDisplayToken, device);
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800653 mFlinger.mutableCurrentState().displays.add(mDisplayToken, state);
654 mFlinger.mutableDrawingState().displays.add(mDisplayToken, state);
655
Dominik Laskowski55c85402020-01-21 16:25:47 -0800656 if (const auto& physical = state.physical) {
657 mFlinger.mutablePhysicalDisplayTokens()[physical->id] = mDisplayToken;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800658 }
659
660 return device;
661 }
662
663 private:
664 TestableSurfaceFlinger& mFlinger;
665 sp<BBinder> mDisplayToken = new BBinder();
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700666 DisplayDeviceCreationArgs mCreationArgs;
Peiyong Line9d809e2020-04-14 13:10:48 -0700667 const std::optional<hal::HWDisplayId> mHwcDisplayId;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800668 };
669
Lloyd Pique90c115d2018-09-18 21:39:42 -0700670 surfaceflinger::test::Factory mFactory;
671 sp<SurfaceFlinger> mFlinger = new SurfaceFlinger(mFactory, SurfaceFlinger::SkipInitialization);
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700672 TestableScheduler* mScheduler = nullptr;
Ady Abrahamabc27602020-04-08 17:20:29 -0700673 Hwc2::mock::Display mDisplay;
Lloyd Piquef58625d2017-12-19 13:22:33 -0800674};
675
676} // namespace android