blob: 8972907b83401d108a71f4708f14af9cda0e9a45 [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
Lloyd Pique90c115d2018-09-18 21:39:42 -070072 std::unique_ptr<HWComposer> createHWComposer(const std::string&) override {
Lloyd Pique90c115d2018-09-18 21:39:42 -070073 return nullptr;
74 }
75
76 std::unique_ptr<MessageQueue> createMessageQueue() override {
Lloyd Pique90c115d2018-09-18 21:39:42 -070077 return std::make_unique<android::impl::MessageQueue>();
78 }
79
Ady Abraham9e16a482019-12-03 17:19:41 -080080 std::unique_ptr<scheduler::PhaseConfiguration> createPhaseConfiguration(
81 const scheduler::RefreshRateConfigs& /*refreshRateConfigs*/) override {
Ana Krulec757f63a2019-01-25 10:46:18 -080082 return std::make_unique<scheduler::FakePhaseOffsets>();
83 }
84
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070085 std::unique_ptr<Scheduler> createScheduler(const scheduler::RefreshRateConfigs&,
Ady Abraham3a77a7b2019-12-02 18:46:59 -080086 ISchedulerCallback&) override {
Lloyd Pique90c115d2018-09-18 21:39:42 -070087 return nullptr;
88 }
89
90 std::unique_ptr<SurfaceInterceptor> createSurfaceInterceptor(SurfaceFlinger* flinger) override {
Lloyd Pique90c115d2018-09-18 21:39:42 -070091 return std::make_unique<android::impl::SurfaceInterceptor>(flinger);
92 }
93
94 sp<StartPropertySetThread> createStartPropertySetThread(bool timestampPropertyValue) override {
Lloyd Pique90c115d2018-09-18 21:39:42 -070095 return new StartPropertySetThread(timestampPropertyValue);
96 }
97
Lloyd Pique9370a482019-10-03 17:58:30 -070098 sp<DisplayDevice> createDisplayDevice(DisplayDeviceCreationArgs& creationArgs) override {
99 return new DisplayDevice(creationArgs);
Lloyd Pique90c115d2018-09-18 21:39:42 -0700100 }
101
102 sp<GraphicBuffer> createGraphicBuffer(uint32_t width, uint32_t height, PixelFormat format,
103 uint32_t layerCount, uint64_t usage,
104 std::string requestorName) override {
Lloyd Pique90c115d2018-09-18 21:39:42 -0700105 return new GraphicBuffer(width, height, format, layerCount, usage, requestorName);
106 }
107
108 void createBufferQueue(sp<IGraphicBufferProducer>* outProducer,
109 sp<IGraphicBufferConsumer>* outConsumer,
110 bool consumerIsSurfaceFlinger) override {
Lloyd Piquee300b312019-10-03 13:03:45 -0700111 if (!mCreateBufferQueue) {
112 BufferQueue::createBufferQueue(outProducer, outConsumer, consumerIsSurfaceFlinger);
113 return;
114 }
Lloyd Pique90c115d2018-09-18 21:39:42 -0700115 mCreateBufferQueue(outProducer, outConsumer, consumerIsSurfaceFlinger);
116 }
117
Lloyd Piquee300b312019-10-03 13:03:45 -0700118 sp<IGraphicBufferProducer> createMonitoredProducer(const sp<IGraphicBufferProducer>& producer,
119 const sp<SurfaceFlinger>& flinger,
120 const wp<Layer>& layer) override {
121 return new MonitoredProducer(producer, flinger, layer);
122 }
123
124 sp<BufferLayerConsumer> createBufferLayerConsumer(const sp<IGraphicBufferConsumer>& consumer,
125 renderengine::RenderEngine& renderEngine,
126 uint32_t textureName, Layer* layer) override {
127 return new BufferLayerConsumer(consumer, renderEngine, textureName, layer);
128 }
129
Lloyd Pique90c115d2018-09-18 21:39:42 -0700130 std::unique_ptr<surfaceflinger::NativeWindowSurface> createNativeWindowSurface(
131 const sp<IGraphicBufferProducer>& producer) override {
132 if (!mCreateNativeWindowSurface) return nullptr;
133 return mCreateNativeWindowSurface(producer);
134 }
135
Lloyd Pique70d91362018-10-18 16:02:55 -0700136 std::unique_ptr<compositionengine::CompositionEngine> createCompositionEngine() override {
137 return compositionengine::impl::createCompositionEngine();
138 }
139
Lloyd Pique90c115d2018-09-18 21:39:42 -0700140 sp<BufferQueueLayer> createBufferQueueLayer(const LayerCreationArgs&) override {
Lloyd Pique90c115d2018-09-18 21:39:42 -0700141 return nullptr;
142 }
143
144 sp<BufferStateLayer> createBufferStateLayer(const LayerCreationArgs&) override {
Lloyd Pique90c115d2018-09-18 21:39:42 -0700145 return nullptr;
146 }
147
Vishnu Nairfa247b12020-02-11 08:58:26 -0800148 sp<EffectLayer> createEffectLayer(const LayerCreationArgs&) override { return nullptr; }
Lloyd Pique90c115d2018-09-18 21:39:42 -0700149
150 sp<ContainerLayer> createContainerLayer(const LayerCreationArgs&) override {
Lloyd Pique90c115d2018-09-18 21:39:42 -0700151 return nullptr;
152 }
153
154 using CreateBufferQueueFunction =
155 std::function<void(sp<IGraphicBufferProducer>* /* outProducer */,
156 sp<IGraphicBufferConsumer>* /* outConsumer */,
157 bool /* consumerIsSurfaceFlinger */)>;
158 CreateBufferQueueFunction mCreateBufferQueue;
159
160 using CreateNativeWindowSurfaceFunction =
161 std::function<std::unique_ptr<surfaceflinger::NativeWindowSurface>(
162 const sp<IGraphicBufferProducer>&)>;
163 CreateNativeWindowSurfaceFunction mCreateNativeWindowSurface;
Lloyd Pique70d91362018-10-18 16:02:55 -0700164
165 using CreateCompositionEngineFunction =
166 std::function<std::unique_ptr<compositionengine::CompositionEngine>()>;
167 CreateCompositionEngineFunction mCreateCompositionEngine;
Lloyd Pique90c115d2018-09-18 21:39:42 -0700168};
169
170} // namespace surfaceflinger::test
Lloyd Piquee39cad22017-12-20 17:01:29 -0800171
Dominik Laskowski8b01cc02020-07-14 19:02:41 -0700172class TestableSurfaceFlinger final : private ISchedulerCallback {
Lloyd Piquef58625d2017-12-19 13:22:33 -0800173public:
Dominik Laskowskib7251f42020-04-20 17:42:59 -0700174 using HotplugEvent = SurfaceFlinger::HotplugEvent;
175
Dominik Laskowskif7a09ed2019-10-07 13:54:18 -0700176 SurfaceFlinger* flinger() { return mFlinger.get(); }
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700177 TestableScheduler* scheduler() { return mScheduler; }
178
Lloyd Piquef58625d2017-12-19 13:22:33 -0800179 // Extend this as needed for accessing SurfaceFlinger private (and public)
180 // functions.
181
Peiyong Lin833074a2018-08-28 11:53:54 -0700182 void setupRenderEngine(std::unique_ptr<renderengine::RenderEngine> renderEngine) {
Lloyd Piqueb97e04f2018-10-18 17:07:05 -0700183 mFlinger->mCompositionEngine->setRenderEngine(std::move(renderEngine));
Lloyd Piquee39cad22017-12-20 17:01:29 -0800184 }
185
186 void setupComposer(std::unique_ptr<Hwc2::Composer> composer) {
Lloyd Pique441d5042018-10-18 16:49:51 -0700187 mFlinger->mCompositionEngine->setHwComposer(
188 std::make_unique<impl::HWComposer>(std::move(composer)));
Lloyd Piquee39cad22017-12-20 17:01:29 -0800189 }
190
Alec Mourie4034bb2019-11-19 12:45:54 -0800191 void setupTimeStats(const std::shared_ptr<TimeStats>& timeStats) {
192 mFlinger->mCompositionEngine->setTimeStats(timeStats);
193 }
194
Dominik Laskowski8b01cc02020-07-14 19:02:41 -0700195 // The ISchedulerCallback argument can be nullptr for a no-op implementation.
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700196 void setupScheduler(std::unique_ptr<DispSync> primaryDispSync,
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700197 std::unique_ptr<EventThread> appEventThread,
Ady Abraham8a82ba62020-01-17 12:43:17 -0800198 std::unique_ptr<EventThread> sfEventThread,
Dominik Laskowski8b01cc02020-07-14 19:02:41 -0700199 ISchedulerCallback* callback = nullptr, bool hasMultipleConfigs = false) {
Ady Abrahamabc27602020-04-08 17:20:29 -0700200 std::vector<std::shared_ptr<const HWC2::Display::Config>> configs{
201 HWC2::Display::Config::Builder(mDisplay, 0)
Dominik Laskowski983f2b52020-06-25 16:54:06 -0700202 .setVsyncPeriod(16'666'667)
Ady Abrahamabc27602020-04-08 17:20:29 -0700203 .setConfigGroup(0)
204 .build()};
205
Dominik Laskowski983f2b52020-06-25 16:54:06 -0700206 if (hasMultipleConfigs) {
207 configs.emplace_back(HWC2::Display::Config::Builder(mDisplay, 1)
208 .setVsyncPeriod(11'111'111)
209 .setConfigGroup(0)
210 .build());
211 }
212
Ady Abraham2139f732019-11-13 18:56:40 -0800213 mFlinger->mRefreshRateConfigs = std::make_unique<
Ana Krulec3f6a2062020-01-23 15:48:01 -0800214 scheduler::RefreshRateConfigs>(configs, /*currentConfig=*/HwcConfigIndexType(0));
Ady Abraham2139f732019-11-13 18:56:40 -0800215 mFlinger->mRefreshRateStats = std::make_unique<
216 scheduler::RefreshRateStats>(*mFlinger->mRefreshRateConfigs, *mFlinger->mTimeStats,
217 /*currentConfig=*/HwcConfigIndexType(0),
Peiyong Lin65248e02020-04-18 21:15:07 -0700218 /*powerMode=*/hal::PowerMode::OFF);
Ady Abraham9e16a482019-12-03 17:19:41 -0800219 mFlinger->mPhaseConfiguration =
220 mFactory.createPhaseConfiguration(*mFlinger->mRefreshRateConfigs);
Steven Thomas2bbaabe2019-08-28 16:08:35 -0700221
Dominik Laskowski983f2b52020-06-25 16:54:06 -0700222 constexpr bool kUseContentDetectionV2 = false;
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700223 mScheduler =
Dominik Laskowski8b01cc02020-07-14 19:02:41 -0700224 new TestableScheduler(std::move(primaryDispSync), *mFlinger->mRefreshRateConfigs,
225 *(callback ?: this), kUseContentDetectionV2);
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700226
Dominik Laskowski98041832019-08-01 18:35:59 -0700227 mFlinger->mAppConnectionHandle = mScheduler->createConnection(std::move(appEventThread));
228 mFlinger->mSfConnectionHandle = mScheduler->createConnection(std::move(sfEventThread));
Dominik Laskowskif7a09ed2019-10-07 13:54:18 -0700229 resetScheduler(mScheduler);
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700230
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700231 mFlinger->mVSyncModulator.emplace(*mScheduler, mFlinger->mAppConnectionHandle,
232 mFlinger->mSfConnectionHandle,
Ady Abraham9e16a482019-12-03 17:19:41 -0800233 mFlinger->mPhaseConfiguration->getCurrentOffsets());
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700234 }
235
Dominik Laskowskif7a09ed2019-10-07 13:54:18 -0700236 void resetScheduler(Scheduler* scheduler) { mFlinger->mScheduler.reset(scheduler); }
237
Lloyd Pique90c115d2018-09-18 21:39:42 -0700238 using CreateBufferQueueFunction = surfaceflinger::test::Factory::CreateBufferQueueFunction;
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800239 void setCreateBufferQueueFunction(CreateBufferQueueFunction f) {
Lloyd Pique90c115d2018-09-18 21:39:42 -0700240 mFactory.mCreateBufferQueue = f;
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800241 }
242
Lloyd Pique90c115d2018-09-18 21:39:42 -0700243 using CreateNativeWindowSurfaceFunction =
244 surfaceflinger::test::Factory::CreateNativeWindowSurfaceFunction;
Lloyd Pique0b1fe702018-01-22 18:03:16 -0800245 void setCreateNativeWindowSurface(CreateNativeWindowSurfaceFunction f) {
Lloyd Pique90c115d2018-09-18 21:39:42 -0700246 mFactory.mCreateNativeWindowSurface = f;
Lloyd Pique0b1fe702018-01-22 18:03:16 -0800247 }
248
Daniel Solomon42d04562019-01-20 21:03:19 -0800249 void setInternalDisplayPrimaries(const ui::DisplayPrimaries& primaries) {
250 memcpy(&mFlinger->mInternalDisplayPrimaries, &primaries, sizeof(ui::DisplayPrimaries));
251 }
252
Dominik Laskowskib7251f42020-04-20 17:42:59 -0700253 static auto& mutableLayerCurrentState(const sp<Layer>& layer) { return layer->mCurrentState; }
254 static auto& mutableLayerDrawingState(const sp<Layer>& layer) { return layer->mDrawingState; }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700255
Valerie Haud251afb2019-03-29 14:19:02 -0700256 auto& mutableStateLock() { return mFlinger->mStateLock; }
257
Dominik Laskowskib7251f42020-04-20 17:42:59 -0700258 static auto findOutputLayerForDisplay(const sp<Layer>& layer,
259 const sp<const DisplayDevice>& display) {
260 return layer->findOutputLayerForDisplay(display.get());
261 }
262
263 static void setLayerSidebandStream(const sp<Layer>& layer,
264 const sp<NativeHandle>& sidebandStream) {
Lloyd Pique0449b0f2018-12-20 16:23:45 -0800265 layer->mDrawingState.sidebandStream = sidebandStream;
Lloyd Pique0b785d82018-12-04 17:25:27 -0800266 layer->mSidebandStream = sidebandStream;
Lloyd Piquede196652020-01-22 17:29:58 -0800267 layer->editCompositionState()->sidebandStream = sidebandStream;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700268 }
269
Dominik Laskowskib7251f42020-04-20 17:42:59 -0700270 void setLayerCompositionType(const sp<Layer>& layer, hal::Composition type) {
271 auto outputLayer = findOutputLayerForDisplay(layer, mFlinger->getDefaultDisplayDevice());
Lloyd Pique37c2c9b2018-12-04 17:25:10 -0800272 LOG_ALWAYS_FATAL_IF(!outputLayer);
273 auto& state = outputLayer->editState();
274 LOG_ALWAYS_FATAL_IF(!outputLayer->getState().hwc);
Peiyong Line9d809e2020-04-14 13:10:48 -0700275 (*state.hwc).hwcCompositionType = type;
Dominik Laskowskib7251f42020-04-20 17:42:59 -0700276 }
Lloyd Pique37c2c9b2018-12-04 17:25:10 -0800277
Dominik Laskowskib7251f42020-04-20 17:42:59 -0700278 static void setLayerPotentialCursor(const sp<Layer>& layer, bool potentialCursor) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700279 layer->mPotentialCursor = potentialCursor;
280 }
281
Lloyd Piquef58625d2017-12-19 13:22:33 -0800282 /* ------------------------------------------------------------------------
283 * Forwarding for functions being tested
284 */
Lloyd Pique0b1fe702018-01-22 18:03:16 -0800285
Lloyd Piquea482f992018-01-22 19:00:34 -0800286 auto createDisplay(const String8& displayName, bool secure) {
287 return mFlinger->createDisplay(displayName, secure);
288 }
289
Dominik Laskowskieecd6592018-05-29 10:25:41 -0700290 auto destroyDisplay(const sp<IBinder>& displayToken) {
291 return mFlinger->destroyDisplay(displayToken);
292 }
Lloyd Piquea482f992018-01-22 19:00:34 -0800293
Dominik Laskowski0a1435d2020-04-21 00:27:31 -0700294 auto resetDisplayState() NO_THREAD_SAFETY_ANALYSIS { return mFlinger->resetDisplayState(); }
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -0800295
Lloyd Pique9370a482019-10-03 17:58:30 -0700296 auto setupNewDisplayDeviceInternal(
297 const wp<IBinder>& displayToken,
298 std::shared_ptr<compositionengine::Display> compositionDisplay,
299 const DisplayDeviceState& state,
300 const sp<compositionengine::DisplaySurface>& dispSurface,
Dominik Laskowski0a1435d2020-04-21 00:27:31 -0700301 const sp<IGraphicBufferProducer>& producer) NO_THREAD_SAFETY_ANALYSIS {
Lloyd Pique9370a482019-10-03 17:58:30 -0700302 return mFlinger->setupNewDisplayDeviceInternal(displayToken, compositionDisplay, state,
303 dispSurface, producer);
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800304 }
305
Lloyd Pique0b1fe702018-01-22 18:03:16 -0800306 auto handleTransactionLocked(uint32_t transactionFlags) {
Vishnu Nairfa5f8df2019-02-13 17:02:51 -0800307 Mutex::Autolock _l(mFlinger->mStateLock);
Lloyd Pique0b1fe702018-01-22 18:03:16 -0800308 return mFlinger->handleTransactionLocked(transactionFlags);
309 }
Lloyd Piquef58625d2017-12-19 13:22:33 -0800310
Peiyong Line9d809e2020-04-14 13:10:48 -0700311 auto onHotplugReceived(int32_t sequenceId, hal::HWDisplayId display,
312 hal::Connection connection) {
Lloyd Pique6cf11032018-01-22 18:57:44 -0800313 return mFlinger->onHotplugReceived(sequenceId, display, connection);
314 }
315
Vishnu Nairce5d0cc2019-02-28 14:38:41 -0800316 auto setDisplayStateLocked(const DisplayState& s) {
317 Mutex::Autolock _l(mFlinger->mStateLock);
318 return mFlinger->setDisplayStateLocked(s);
319 }
Lloyd Pique9d9cf402018-02-16 17:47:13 -0800320
Dominik Laskowski83b88212018-12-11 13:34:06 -0800321 // Allow reading display state without locking, as if called on the SF main thread.
322 auto onInitializeDisplays() NO_THREAD_SAFETY_ANALYSIS {
323 return mFlinger->onInitializeDisplays();
324 }
Lloyd Pique86016da2018-03-01 16:09:38 -0800325
Lais Andrade3a6e47d2020-04-02 11:20:16 +0100326 auto notifyPowerBoost(int32_t boostId) { return mFlinger->notifyPowerBoost(boostId); }
327
Dominik Laskowski83b88212018-12-11 13:34:06 -0800328 // Allow reading display state without locking, as if called on the SF main thread.
329 auto setPowerModeInternal(const sp<DisplayDevice>& display,
Peiyong Lin65248e02020-04-18 21:15:07 -0700330 hal::PowerMode mode) NO_THREAD_SAFETY_ANALYSIS {
Dominik Laskowskie9774092018-12-11 10:04:24 -0800331 return mFlinger->setPowerModeInternal(display, mode);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -0800332 }
333
Ady Abraham0ed31c92020-04-16 11:48:45 -0700334 auto onMessageReceived(int32_t what) { return mFlinger->onMessageReceived(what, systemTime()); }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700335
chaviw426b5c02020-07-27 11:20:15 -0700336 auto renderScreenImplLocked(const RenderArea& renderArea,
337 SurfaceFlinger::TraverseLayersFunction traverseLayers,
338 const sp<GraphicBuffer>& buffer, bool useIdentityTransform,
339 bool forSystem, int* outSyncFd, bool regionSampling) {
340 ScreenCaptureResults captureResults;
341 return mFlinger->renderScreenImplLocked(renderArea, traverseLayers, buffer,
342 useIdentityTransform, forSystem, outSyncFd,
343 regionSampling, captureResults);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700344 }
345
chaviw4b9d5e12020-08-04 18:30:35 -0700346 auto traverseLayersInLayerStack(ui::LayerStack layerStack, int32_t uid,
Marin Shalamanov1c434292020-06-12 01:47:29 +0200347 const LayerVector::Visitor& visitor) {
chaviw4b9d5e12020-08-04 18:30:35 -0700348 return mFlinger->SurfaceFlinger::traverseLayersInLayerStack(layerStack, uid, visitor);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700349 }
350
Daniel Solomon42d04562019-01-20 21:03:19 -0800351 auto getDisplayNativePrimaries(const sp<IBinder>& displayToken,
352 ui::DisplayPrimaries &primaries) {
353 return mFlinger->SurfaceFlinger::getDisplayNativePrimaries(displayToken, primaries);
354 }
355
Valerie Haud251afb2019-03-29 14:19:02 -0700356 auto& getTransactionQueue() { return mFlinger->mTransactionQueues; }
357
358 auto setTransactionState(const Vector<ComposerState>& states,
359 const Vector<DisplayState>& displays, uint32_t flags,
360 const sp<IBinder>& applyToken,
361 const InputWindowCommands& inputWindowCommands,
362 int64_t desiredPresentTime, const client_cache_t& uncacheBuffer,
363 bool hasListenerCallbacks,
364 std::vector<ListenerCallbacks>& listenerCallbacks) {
365 return mFlinger->setTransactionState(states, displays, flags, applyToken,
366 inputWindowCommands, desiredPresentTime, uncacheBuffer,
367 hasListenerCallbacks, listenerCallbacks);
368 }
369
370 auto flushTransactionQueues() { return mFlinger->flushTransactionQueues(); };
371
Lloyd Pique86016da2018-03-01 16:09:38 -0800372 /* ------------------------------------------------------------------------
373 * Read-only access to private data to assert post-conditions.
374 */
375
376 const auto& getAnimFrameTracker() const { return mFlinger->mAnimFrameTracker; }
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -0800377 const auto& getHasPoweredOff() const { return mFlinger->mHasPoweredOff; }
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -0800378 const auto& getVisibleRegionsDirty() const { return mFlinger->mVisibleRegionsDirty; }
Lloyd Pique441d5042018-10-18 16:49:51 -0700379 auto& getHwComposer() const {
380 return static_cast<impl::HWComposer&>(mFlinger->getHwComposer());
381 }
Lloyd Pique9370a482019-10-03 17:58:30 -0700382 auto& getCompositionEngine() const { return mFlinger->getCompositionEngine(); }
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -0800383
Lloyd Pique86016da2018-03-01 16:09:38 -0800384 const auto& getCompositorTiming() const { return mFlinger->getBE().mCompositorTiming; }
385
Lloyd Piquef58625d2017-12-19 13:22:33 -0800386 /* ------------------------------------------------------------------------
387 * Read-write access to private data to set up preconditions and assert
388 * post-conditions.
389 */
Lloyd Pique0b1fe702018-01-22 18:03:16 -0800390
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800391 auto& mutableHasWideColorDisplay() { return SurfaceFlinger::hasWideColorDisplay; }
Peiyong Lin13effd12018-07-24 17:01:47 -0700392 auto& mutableUseColorManagement() { return SurfaceFlinger::useColorManagement; }
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800393
Lloyd Piquee39cad22017-12-20 17:01:29 -0800394 auto& mutableCurrentState() { return mFlinger->mCurrentState; }
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800395 auto& mutableDisplayColorSetting() { return mFlinger->mDisplayColorSetting; }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700396 auto& mutableDisplays() { return mFlinger->mDisplays; }
Lloyd Piquee39cad22017-12-20 17:01:29 -0800397 auto& mutableDrawingState() { return mFlinger->mDrawingState; }
Lloyd Piquee39cad22017-12-20 17:01:29 -0800398 auto& mutableEventQueue() { return mFlinger->mEventQueue; }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700399 auto& mutableGeometryInvalid() { return mFlinger->mGeometryInvalid; }
Lloyd Pique0b1fe702018-01-22 18:03:16 -0800400 auto& mutableInterceptor() { return mFlinger->mInterceptor; }
Lloyd Pique6cf11032018-01-22 18:57:44 -0800401 auto& mutableMainThreadId() { return mFlinger->mMainThreadId; }
Lloyd Pique0b1fe702018-01-22 18:03:16 -0800402 auto& mutablePendingHotplugEvents() { return mFlinger->mPendingHotplugEvents; }
Dominik Laskowski075d3172018-05-24 15:50:06 -0700403 auto& mutablePhysicalDisplayTokens() { return mFlinger->mPhysicalDisplayTokens; }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700404 auto& mutableTexturePool() { return mFlinger->mTexturePool; }
Lloyd Pique0b1fe702018-01-22 18:03:16 -0800405 auto& mutableTransactionFlags() { return mFlinger->mTransactionFlags; }
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800406 auto& mutableUseHwcVirtualDisplays() { return mFlinger->mUseHwcVirtualDisplays; }
Peiyong Lin74ca2f42019-01-14 19:36:57 -0800407 auto& mutablePowerAdvisor() { return mFlinger->mPowerAdvisor; }
Lloyd Pique4fe29402019-08-12 16:51:24 -0700408 auto& mutableDebugDisableHWC() { return mFlinger->mDebugDisableHWC; }
Lloyd Piquee39cad22017-12-20 17:01:29 -0800409
Lloyd Pique6cf11032018-01-22 18:57:44 -0800410 auto& mutableComposerSequenceId() { return mFlinger->getBE().mComposerSequenceId; }
Lloyd Pique441d5042018-10-18 16:49:51 -0700411 auto& mutableHwcDisplayData() { return getHwComposer().mDisplayData; }
412 auto& mutableHwcPhysicalDisplayIdMap() { return getHwComposer().mPhysicalDisplayIdMap; }
413 auto& mutableInternalHwcDisplayId() { return getHwComposer().mInternalHwcDisplayId; }
414 auto& mutableExternalHwcDisplayId() { return getHwComposer().mExternalHwcDisplayId; }
Ady Abraham60e42ea2020-03-09 19:17:31 -0700415 auto& mutableUseFrameRateApi() { return mFlinger->useFrameRateApi; }
Lloyd Piquea618d852018-01-17 11:52:30 -0800416
Valerie Hau09e60052019-12-15 14:51:15 -0800417 auto fromHandle(const sp<IBinder>& handle) {
Valerie Hau09e60052019-12-15 14:51:15 -0800418 return mFlinger->fromHandle(handle);
419 }
420
Lloyd Piquee39cad22017-12-20 17:01:29 -0800421 ~TestableSurfaceFlinger() {
422 // All these pointer and container clears help ensure that GMock does
423 // not report a leaked object, since the SurfaceFlinger instance may
424 // still be referenced by something despite our best efforts to destroy
425 // it after each test is done.
426 mutableDisplays().clear();
Ady Abraham2939f092019-03-04 17:44:06 -0800427 mutableCurrentState().displays.clear();
428 mutableDrawingState().displays.clear();
Lloyd Pique0b1fe702018-01-22 18:03:16 -0800429 mutableEventQueue().reset();
Lloyd Pique0b1fe702018-01-22 18:03:16 -0800430 mutableInterceptor().reset();
Lloyd Pique2eb71eb2019-08-13 13:23:03 -0700431 mFlinger->mScheduler.reset();
Lloyd Pique441d5042018-10-18 16:49:51 -0700432 mFlinger->mCompositionEngine->setHwComposer(std::unique_ptr<HWComposer>());
Lloyd Piqueb97e04f2018-10-18 17:07:05 -0700433 mFlinger->mCompositionEngine->setRenderEngine(
434 std::unique_ptr<renderengine::RenderEngine>());
Lloyd Piquee39cad22017-12-20 17:01:29 -0800435 }
Lloyd Piquef58625d2017-12-19 13:22:33 -0800436
Lloyd Piquea618d852018-01-17 11:52:30 -0800437 /* ------------------------------------------------------------------------
438 * Wrapper classes for Read-write access to private data to set up
439 * preconditions and assert post-conditions.
440 */
Ana Krulec4593b692019-01-11 22:07:25 -0800441 struct HWC2Display : public HWC2::impl::Display {
Peiyong Lin74ca2f42019-01-14 19:36:57 -0800442 HWC2Display(Hwc2::Composer& composer,
Peiyong Line9d809e2020-04-14 13:10:48 -0700443 const std::unordered_set<hal::Capability>& capabilities, hal::HWDisplayId id,
444 hal::DisplayType type)
Peiyong Lin74ca2f42019-01-14 19:36:57 -0800445 : HWC2::impl::Display(composer, capabilities, id, type) {}
Lloyd Piquea618d852018-01-17 11:52:30 -0800446 ~HWC2Display() {
447 // Prevents a call to disable vsyncs.
Peiyong Line9d809e2020-04-14 13:10:48 -0700448 mType = hal::DisplayType::INVALID;
Lloyd Piquea618d852018-01-17 11:52:30 -0800449 }
450
451 auto& mutableIsConnected() { return this->mIsConnected; }
452 auto& mutableConfigs() { return this->mConfigs; }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700453 auto& mutableLayers() { return this->mLayers; }
Lloyd Piquea618d852018-01-17 11:52:30 -0800454 };
455
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800456 class FakeHwcDisplayInjector {
457 public:
Peiyong Line9d809e2020-04-14 13:10:48 -0700458 static constexpr hal::HWDisplayId DEFAULT_HWC_DISPLAY_ID = 1000;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800459 static constexpr int32_t DEFAULT_WIDTH = 1920;
460 static constexpr int32_t DEFAULT_HEIGHT = 1280;
461 static constexpr int32_t DEFAULT_REFRESH_RATE = 16'666'666;
Ady Abraham2139f732019-11-13 18:56:40 -0800462 static constexpr int32_t DEFAULT_CONFIG_GROUP = 7;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800463 static constexpr int32_t DEFAULT_DPI = 320;
Peiyong Line9d809e2020-04-14 13:10:48 -0700464 static constexpr hal::HWConfigId DEFAULT_ACTIVE_CONFIG = 0;
Peiyong Lin65248e02020-04-18 21:15:07 -0700465 static constexpr hal::PowerMode DEFAULT_POWER_MODE = hal::PowerMode::ON;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800466
Peiyong Line9d809e2020-04-14 13:10:48 -0700467 FakeHwcDisplayInjector(DisplayId displayId, hal::DisplayType hwcDisplayType, bool isPrimary)
Dominik Laskowski075d3172018-05-24 15:50:06 -0700468 : mDisplayId(displayId), mHwcDisplayType(hwcDisplayType), mIsPrimary(isPrimary) {}
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800469
Peiyong Line9d809e2020-04-14 13:10:48 -0700470 auto& setHwcDisplayId(hal::HWDisplayId displayId) {
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800471 mHwcDisplayId = displayId;
472 return *this;
473 }
474
475 auto& setWidth(int32_t width) {
476 mWidth = width;
477 return *this;
478 }
479
480 auto& setHeight(int32_t height) {
481 mHeight = height;
482 return *this;
483 }
484
Ady Abraham8a82ba62020-01-17 12:43:17 -0800485 auto& setRefreshRate(int32_t refreshRate) {
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800486 mRefreshRate = refreshRate;
487 return *this;
488 }
489
490 auto& setDpiX(int32_t dpi) {
491 mDpiX = dpi;
492 return *this;
493 }
494
495 auto& setDpiY(int32_t dpi) {
496 mDpiY = dpi;
497 return *this;
498 }
499
Peiyong Line9d809e2020-04-14 13:10:48 -0700500 auto& setActiveConfig(hal::HWConfigId config) {
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800501 mActiveConfig = config;
502 return *this;
503 }
504
Peiyong Line9d809e2020-04-14 13:10:48 -0700505 auto& setCapabilities(const std::unordered_set<hal::Capability>* capabilities) {
Lloyd Piquee22f0332018-07-16 16:35:56 -0700506 mCapabilities = capabilities;
507 return *this;
508 }
509
Peiyong Lin65248e02020-04-18 21:15:07 -0700510 auto& setPowerMode(hal::PowerMode mode) {
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700511 mPowerMode = mode;
512 return *this;
513 }
514
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800515 void inject(TestableSurfaceFlinger* flinger, Hwc2::Composer* composer) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700516 static const std::unordered_set<hal::Capability> defaultCapabilities;
Lloyd Piquee22f0332018-07-16 16:35:56 -0700517 if (mCapabilities == nullptr) mCapabilities = &defaultCapabilities;
518
519 // Caution - Make sure that any values passed by reference here do
520 // not refer to an instance owned by FakeHwcDisplayInjector. This
521 // class has temporary lifetime, while the constructed HWC2::Display
522 // is much longer lived.
Peiyong Lin74ca2f42019-01-14 19:36:57 -0800523 auto display = std::make_unique<HWC2Display>(*composer, *mCapabilities, mHwcDisplayId,
524 mHwcDisplayType);
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800525
526 auto config = HWC2::Display::Config::Builder(*display, mActiveConfig);
527 config.setWidth(mWidth);
528 config.setHeight(mHeight);
529 config.setVsyncPeriod(mRefreshRate);
530 config.setDpiX(mDpiX);
531 config.setDpiY(mDpiY);
Ady Abraham2139f732019-11-13 18:56:40 -0800532 config.setConfigGroup(mConfigGroup);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800533 display->mutableConfigs().emplace(static_cast<int32_t>(mActiveConfig), config.build());
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800534 display->mutableIsConnected() = true;
Peiyong Lin65248e02020-04-18 21:15:07 -0700535 display->setPowerMode(mPowerMode);
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800536
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800537 flinger->mutableHwcDisplayData()[mDisplayId].hwcDisplay = std::move(display);
Dominik Laskowski075d3172018-05-24 15:50:06 -0700538
Peiyong Line9d809e2020-04-14 13:10:48 -0700539 if (mHwcDisplayType == hal::DisplayType::PHYSICAL) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700540 flinger->mutableHwcPhysicalDisplayIdMap().emplace(mHwcDisplayId, mDisplayId);
541 (mIsPrimary ? flinger->mutableInternalHwcDisplayId()
542 : flinger->mutableExternalHwcDisplayId()) = mHwcDisplayId;
543 }
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800544 }
545
546 private:
Dominik Laskowski075d3172018-05-24 15:50:06 -0700547 const DisplayId mDisplayId;
Peiyong Line9d809e2020-04-14 13:10:48 -0700548 const hal::DisplayType mHwcDisplayType;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700549 const bool mIsPrimary;
550
Peiyong Line9d809e2020-04-14 13:10:48 -0700551 hal::HWDisplayId mHwcDisplayId = DEFAULT_HWC_DISPLAY_ID;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800552 int32_t mWidth = DEFAULT_WIDTH;
553 int32_t mHeight = DEFAULT_HEIGHT;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800554 int32_t mRefreshRate = DEFAULT_REFRESH_RATE;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800555 int32_t mDpiX = DEFAULT_DPI;
Ady Abraham2139f732019-11-13 18:56:40 -0800556 int32_t mConfigGroup = DEFAULT_CONFIG_GROUP;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800557 int32_t mDpiY = DEFAULT_DPI;
Peiyong Line9d809e2020-04-14 13:10:48 -0700558 hal::HWConfigId mActiveConfig = DEFAULT_ACTIVE_CONFIG;
Peiyong Lin65248e02020-04-18 21:15:07 -0700559 hal::PowerMode mPowerMode = DEFAULT_POWER_MODE;
Peiyong Line9d809e2020-04-14 13:10:48 -0700560 const std::unordered_set<hal::Capability>* mCapabilities = nullptr;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800561 };
562
563 class FakeDisplayDeviceInjector {
564 public:
Dominik Laskowski075d3172018-05-24 15:50:06 -0700565 FakeDisplayDeviceInjector(TestableSurfaceFlinger& flinger,
Lloyd Pique9370a482019-10-03 17:58:30 -0700566 std::shared_ptr<compositionengine::Display> compositionDisplay,
Dominik Laskowski55c85402020-01-21 16:25:47 -0800567 std::optional<DisplayConnectionType> connectionType,
Peiyong Line9d809e2020-04-14 13:10:48 -0700568 std::optional<hal::HWDisplayId> hwcDisplayId, bool isPrimary)
Lloyd Pique9370a482019-10-03 17:58:30 -0700569 : mFlinger(flinger),
Marin Shalamanov700e6392020-02-12 20:22:26 +0100570 mCreationArgs(flinger.mFlinger.get(), mDisplayToken, compositionDisplay),
571 mHwcDisplayId(hwcDisplayId) {
Dominik Laskowski55c85402020-01-21 16:25:47 -0800572 mCreationArgs.connectionType = connectionType;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700573 mCreationArgs.isPrimary = isPrimary;
574 }
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800575
576 sp<IBinder> token() const { return mDisplayToken; }
577
578 DisplayDeviceState& mutableDrawingDisplayState() {
579 return mFlinger.mutableDrawingState().displays.editValueFor(mDisplayToken);
580 }
581
582 DisplayDeviceState& mutableCurrentDisplayState() {
583 return mFlinger.mutableCurrentState().displays.editValueFor(mDisplayToken);
584 }
585
Lloyd Pique9d9cf402018-02-16 17:47:13 -0800586 const auto& getDrawingDisplayState() {
587 return mFlinger.mutableDrawingState().displays.valueFor(mDisplayToken);
588 }
589
590 const auto& getCurrentDisplayState() {
591 return mFlinger.mutableCurrentState().displays.valueFor(mDisplayToken);
592 }
593
Dominik Laskowski9fae1022018-05-29 13:17:40 -0700594 auto& mutableDisplayDevice() { return mFlinger.mutableDisplays()[mDisplayToken]; }
Lloyd Pique9d9cf402018-02-16 17:47:13 -0800595
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800596 auto& setNativeWindow(const sp<ANativeWindow>& nativeWindow) {
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700597 mCreationArgs.nativeWindow = nativeWindow;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800598 return *this;
599 }
600
Lloyd Pique542307f2018-10-19 13:24:08 -0700601 auto& setDisplaySurface(const sp<compositionengine::DisplaySurface>& displaySurface) {
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700602 mCreationArgs.displaySurface = displaySurface;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800603 return *this;
604 }
605
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800606 auto& setSecure(bool secure) {
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700607 mCreationArgs.isSecure = secure;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800608 return *this;
609 }
610
Peiyong Lin65248e02020-04-18 21:15:07 -0700611 auto& setPowerMode(hal::PowerMode mode) {
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700612 mCreationArgs.initialPowerMode = mode;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700613 return *this;
614 }
615
Valerie Hau9758ae02018-10-09 16:05:09 -0700616 auto& setHwcColorModes(
617 const std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>>
618 hwcColorModes) {
619 mCreationArgs.hwcColorModes = hwcColorModes;
620 return *this;
621 }
622
623 auto& setHasWideColorGamut(bool hasWideColorGamut) {
624 mCreationArgs.hasWideColorGamut = hasWideColorGamut;
625 return *this;
626 }
627
Lloyd Pique33050472019-12-19 17:12:44 -0800628 auto& setPhysicalOrientation(ui::Rotation orientation) {
629 mCreationArgs.physicalOrientation = orientation;
630 return *this;
631 }
632
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800633 sp<DisplayDevice> inject() {
Lloyd Pique9370a482019-10-03 17:58:30 -0700634 const auto displayId = mCreationArgs.compositionDisplay->getDisplayId();
635
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800636 DisplayDeviceState state;
Dominik Laskowski55c85402020-01-21 16:25:47 -0800637 if (const auto type = mCreationArgs.connectionType) {
Lloyd Pique9370a482019-10-03 17:58:30 -0700638 LOG_ALWAYS_FATAL_IF(!displayId);
Marin Shalamanov700e6392020-02-12 20:22:26 +0100639 LOG_ALWAYS_FATAL_IF(!mHwcDisplayId);
Marin Shalamanova524a092020-07-27 21:39:55 +0200640 state.physical = {.id = static_cast<PhysicalDisplayId>(*displayId),
641 .type = *type,
642 .hwcDisplayId = *mHwcDisplayId};
Dominik Laskowski55c85402020-01-21 16:25:47 -0800643 }
644
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700645 state.isSecure = mCreationArgs.isSecure;
646
Lloyd Pique9370a482019-10-03 17:58:30 -0700647 sp<DisplayDevice> device = new DisplayDevice(mCreationArgs);
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700648 mFlinger.mutableDisplays().emplace(mDisplayToken, device);
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800649 mFlinger.mutableCurrentState().displays.add(mDisplayToken, state);
650 mFlinger.mutableDrawingState().displays.add(mDisplayToken, state);
651
Dominik Laskowski55c85402020-01-21 16:25:47 -0800652 if (const auto& physical = state.physical) {
653 mFlinger.mutablePhysicalDisplayTokens()[physical->id] = mDisplayToken;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800654 }
655
656 return device;
657 }
658
659 private:
660 TestableSurfaceFlinger& mFlinger;
661 sp<BBinder> mDisplayToken = new BBinder();
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700662 DisplayDeviceCreationArgs mCreationArgs;
Peiyong Line9d809e2020-04-14 13:10:48 -0700663 const std::optional<hal::HWDisplayId> mHwcDisplayId;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800664 };
665
Dominik Laskowski8b01cc02020-07-14 19:02:41 -0700666private:
667 void setVsyncEnabled(bool) override {}
668 void changeRefreshRate(const Scheduler::RefreshRate&, Scheduler::ConfigEvent) override {}
669 void repaintEverythingForHWC() override {}
670 void kernelTimerChanged(bool) override {}
671
Lloyd Pique90c115d2018-09-18 21:39:42 -0700672 surfaceflinger::test::Factory mFactory;
673 sp<SurfaceFlinger> mFlinger = new SurfaceFlinger(mFactory, SurfaceFlinger::SkipInitialization);
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700674 TestableScheduler* mScheduler = nullptr;
Ady Abrahamabc27602020-04-08 17:20:29 -0700675 Hwc2::mock::Display mDisplay;
Lloyd Piquef58625d2017-12-19 13:22:33 -0800676};
677
678} // namespace android