blob: 16bea4711c6f245bbf9ab2d3bf74a46000cae113 [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"
Ady Abrahamc581d3c2020-08-06 17:34:27 -070032#include "FakeVsyncConfiguration.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
Lloyd Pique90c115d2018-09-18 21:39:42 -070068 std::unique_ptr<HWComposer> createHWComposer(const std::string&) override {
Lloyd Pique90c115d2018-09-18 21:39:42 -070069 return nullptr;
70 }
71
72 std::unique_ptr<MessageQueue> createMessageQueue() override {
Lloyd Pique90c115d2018-09-18 21:39:42 -070073 return std::make_unique<android::impl::MessageQueue>();
74 }
75
Ady Abraham8287e852020-08-12 14:44:58 -070076 std::unique_ptr<scheduler::VsyncConfiguration> createVsyncConfiguration(
Ady Abraham9e16a482019-12-03 17:19:41 -080077 const scheduler::RefreshRateConfigs& /*refreshRateConfigs*/) override {
Ana Krulec757f63a2019-01-25 10:46:18 -080078 return std::make_unique<scheduler::FakePhaseOffsets>();
79 }
80
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070081 std::unique_ptr<Scheduler> createScheduler(const scheduler::RefreshRateConfigs&,
Ady Abraham3a77a7b2019-12-02 18:46:59 -080082 ISchedulerCallback&) override {
Lloyd Pique90c115d2018-09-18 21:39:42 -070083 return nullptr;
84 }
85
Pablo Gamito5cfc6e52020-09-10 11:18:03 +000086 sp<SurfaceInterceptor> createSurfaceInterceptor(SurfaceFlinger* flinger) override {
87 return new android::impl::SurfaceInterceptor(flinger);
Lloyd Pique90c115d2018-09-18 21:39:42 -070088 }
89
90 sp<StartPropertySetThread> createStartPropertySetThread(bool timestampPropertyValue) override {
Lloyd Pique90c115d2018-09-18 21:39:42 -070091 return new StartPropertySetThread(timestampPropertyValue);
92 }
93
Lloyd Pique9370a482019-10-03 17:58:30 -070094 sp<DisplayDevice> createDisplayDevice(DisplayDeviceCreationArgs& creationArgs) override {
95 return new DisplayDevice(creationArgs);
Lloyd Pique90c115d2018-09-18 21:39:42 -070096 }
97
98 sp<GraphicBuffer> createGraphicBuffer(uint32_t width, uint32_t height, PixelFormat format,
99 uint32_t layerCount, uint64_t usage,
100 std::string requestorName) override {
Lloyd Pique90c115d2018-09-18 21:39:42 -0700101 return new GraphicBuffer(width, height, format, layerCount, usage, requestorName);
102 }
103
104 void createBufferQueue(sp<IGraphicBufferProducer>* outProducer,
105 sp<IGraphicBufferConsumer>* outConsumer,
106 bool consumerIsSurfaceFlinger) override {
Lloyd Piquee300b312019-10-03 13:03:45 -0700107 if (!mCreateBufferQueue) {
108 BufferQueue::createBufferQueue(outProducer, outConsumer, consumerIsSurfaceFlinger);
109 return;
110 }
Lloyd Pique90c115d2018-09-18 21:39:42 -0700111 mCreateBufferQueue(outProducer, outConsumer, consumerIsSurfaceFlinger);
112 }
113
Lloyd Piquee300b312019-10-03 13:03:45 -0700114 sp<IGraphicBufferProducer> createMonitoredProducer(const sp<IGraphicBufferProducer>& producer,
115 const sp<SurfaceFlinger>& flinger,
116 const wp<Layer>& layer) override {
117 return new MonitoredProducer(producer, flinger, layer);
118 }
119
120 sp<BufferLayerConsumer> createBufferLayerConsumer(const sp<IGraphicBufferConsumer>& consumer,
121 renderengine::RenderEngine& renderEngine,
122 uint32_t textureName, Layer* layer) override {
123 return new BufferLayerConsumer(consumer, renderEngine, textureName, layer);
124 }
125
Lloyd Pique90c115d2018-09-18 21:39:42 -0700126 std::unique_ptr<surfaceflinger::NativeWindowSurface> createNativeWindowSurface(
127 const sp<IGraphicBufferProducer>& producer) override {
128 if (!mCreateNativeWindowSurface) return nullptr;
129 return mCreateNativeWindowSurface(producer);
130 }
131
Lloyd Pique70d91362018-10-18 16:02:55 -0700132 std::unique_ptr<compositionengine::CompositionEngine> createCompositionEngine() override {
133 return compositionengine::impl::createCompositionEngine();
134 }
135
Lloyd Pique90c115d2018-09-18 21:39:42 -0700136 sp<BufferQueueLayer> createBufferQueueLayer(const LayerCreationArgs&) override {
Lloyd Pique90c115d2018-09-18 21:39:42 -0700137 return nullptr;
138 }
139
140 sp<BufferStateLayer> createBufferStateLayer(const LayerCreationArgs&) override {
Lloyd Pique90c115d2018-09-18 21:39:42 -0700141 return nullptr;
142 }
143
Vishnu Nairfa247b12020-02-11 08:58:26 -0800144 sp<EffectLayer> createEffectLayer(const LayerCreationArgs&) override { return nullptr; }
Lloyd Pique90c115d2018-09-18 21:39:42 -0700145
146 sp<ContainerLayer> createContainerLayer(const LayerCreationArgs&) override {
Lloyd Pique90c115d2018-09-18 21:39:42 -0700147 return nullptr;
148 }
149
150 using CreateBufferQueueFunction =
151 std::function<void(sp<IGraphicBufferProducer>* /* outProducer */,
152 sp<IGraphicBufferConsumer>* /* outConsumer */,
153 bool /* consumerIsSurfaceFlinger */)>;
154 CreateBufferQueueFunction mCreateBufferQueue;
155
156 using CreateNativeWindowSurfaceFunction =
157 std::function<std::unique_ptr<surfaceflinger::NativeWindowSurface>(
158 const sp<IGraphicBufferProducer>&)>;
159 CreateNativeWindowSurfaceFunction mCreateNativeWindowSurface;
Lloyd Pique70d91362018-10-18 16:02:55 -0700160
161 using CreateCompositionEngineFunction =
162 std::function<std::unique_ptr<compositionengine::CompositionEngine>()>;
163 CreateCompositionEngineFunction mCreateCompositionEngine;
Lloyd Pique90c115d2018-09-18 21:39:42 -0700164};
165
166} // namespace surfaceflinger::test
Lloyd Piquee39cad22017-12-20 17:01:29 -0800167
Dominik Laskowski8b01cc02020-07-14 19:02:41 -0700168class TestableSurfaceFlinger final : private ISchedulerCallback {
Lloyd Piquef58625d2017-12-19 13:22:33 -0800169public:
Dominik Laskowskib7251f42020-04-20 17:42:59 -0700170 using HotplugEvent = SurfaceFlinger::HotplugEvent;
171
Dominik Laskowskif7a09ed2019-10-07 13:54:18 -0700172 SurfaceFlinger* flinger() { return mFlinger.get(); }
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700173 TestableScheduler* scheduler() { return mScheduler; }
174
Lloyd Piquef58625d2017-12-19 13:22:33 -0800175 // Extend this as needed for accessing SurfaceFlinger private (and public)
176 // functions.
177
Peiyong Lin833074a2018-08-28 11:53:54 -0700178 void setupRenderEngine(std::unique_ptr<renderengine::RenderEngine> renderEngine) {
Lloyd Piqueb97e04f2018-10-18 17:07:05 -0700179 mFlinger->mCompositionEngine->setRenderEngine(std::move(renderEngine));
Lloyd Piquee39cad22017-12-20 17:01:29 -0800180 }
181
182 void setupComposer(std::unique_ptr<Hwc2::Composer> composer) {
Lloyd Pique441d5042018-10-18 16:49:51 -0700183 mFlinger->mCompositionEngine->setHwComposer(
184 std::make_unique<impl::HWComposer>(std::move(composer)));
Lloyd Piquee39cad22017-12-20 17:01:29 -0800185 }
186
Alec Mourie4034bb2019-11-19 12:45:54 -0800187 void setupTimeStats(const std::shared_ptr<TimeStats>& timeStats) {
188 mFlinger->mCompositionEngine->setTimeStats(timeStats);
189 }
190
Dominik Laskowski8b01cc02020-07-14 19:02:41 -0700191 // The ISchedulerCallback argument can be nullptr for a no-op implementation.
Ady Abraham8cb21882020-08-26 18:22:05 -0700192 void setupScheduler(std::unique_ptr<scheduler::VsyncController> vsyncController,
193 std::unique_ptr<scheduler::VSyncTracker> vsyncTracker,
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700194 std::unique_ptr<EventThread> appEventThread,
Ady Abraham8a82ba62020-01-17 12:43:17 -0800195 std::unique_ptr<EventThread> sfEventThread,
Dominik Laskowski8b01cc02020-07-14 19:02:41 -0700196 ISchedulerCallback* callback = nullptr, bool hasMultipleConfigs = false) {
Ady Abrahamabc27602020-04-08 17:20:29 -0700197 std::vector<std::shared_ptr<const HWC2::Display::Config>> configs{
198 HWC2::Display::Config::Builder(mDisplay, 0)
Dominik Laskowski983f2b52020-06-25 16:54:06 -0700199 .setVsyncPeriod(16'666'667)
Ady Abrahamabc27602020-04-08 17:20:29 -0700200 .setConfigGroup(0)
201 .build()};
202
Dominik Laskowski983f2b52020-06-25 16:54:06 -0700203 if (hasMultipleConfigs) {
204 configs.emplace_back(HWC2::Display::Config::Builder(mDisplay, 1)
205 .setVsyncPeriod(11'111'111)
206 .setConfigGroup(0)
207 .build());
208 }
209
Ady Abraham2139f732019-11-13 18:56:40 -0800210 mFlinger->mRefreshRateConfigs = std::make_unique<
Ana Krulec3f6a2062020-01-23 15:48:01 -0800211 scheduler::RefreshRateConfigs>(configs, /*currentConfig=*/HwcConfigIndexType(0));
Ady Abraham2139f732019-11-13 18:56:40 -0800212 mFlinger->mRefreshRateStats = std::make_unique<
213 scheduler::RefreshRateStats>(*mFlinger->mRefreshRateConfigs, *mFlinger->mTimeStats,
214 /*currentConfig=*/HwcConfigIndexType(0),
Peiyong Lin65248e02020-04-18 21:15:07 -0700215 /*powerMode=*/hal::PowerMode::OFF);
Ady Abraham8287e852020-08-12 14:44:58 -0700216 mFlinger->mVsyncConfiguration =
217 mFactory.createVsyncConfiguration(*mFlinger->mRefreshRateConfigs);
218 mFlinger->mVsyncModulator.emplace(mFlinger->mVsyncConfiguration->getCurrentConfigs());
Steven Thomas2bbaabe2019-08-28 16:08:35 -0700219
Dominik Laskowski983f2b52020-06-25 16:54:06 -0700220 constexpr bool kUseContentDetectionV2 = false;
Ady Abraham8cb21882020-08-26 18:22:05 -0700221 mScheduler = new TestableScheduler(std::move(vsyncController), std::move(vsyncTracker),
222 *mFlinger->mRefreshRateConfigs, *(callback ?: this),
223 kUseContentDetectionV2);
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700224
Dominik Laskowski98041832019-08-01 18:35:59 -0700225 mFlinger->mAppConnectionHandle = mScheduler->createConnection(std::move(appEventThread));
226 mFlinger->mSfConnectionHandle = mScheduler->createConnection(std::move(sfEventThread));
Dominik Laskowskif7a09ed2019-10-07 13:54:18 -0700227 resetScheduler(mScheduler);
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700228 }
229
Dominik Laskowskif7a09ed2019-10-07 13:54:18 -0700230 void resetScheduler(Scheduler* scheduler) { mFlinger->mScheduler.reset(scheduler); }
231
Lloyd Pique90c115d2018-09-18 21:39:42 -0700232 using CreateBufferQueueFunction = surfaceflinger::test::Factory::CreateBufferQueueFunction;
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800233 void setCreateBufferQueueFunction(CreateBufferQueueFunction f) {
Lloyd Pique90c115d2018-09-18 21:39:42 -0700234 mFactory.mCreateBufferQueue = f;
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800235 }
236
Lloyd Pique90c115d2018-09-18 21:39:42 -0700237 using CreateNativeWindowSurfaceFunction =
238 surfaceflinger::test::Factory::CreateNativeWindowSurfaceFunction;
Lloyd Pique0b1fe702018-01-22 18:03:16 -0800239 void setCreateNativeWindowSurface(CreateNativeWindowSurfaceFunction f) {
Lloyd Pique90c115d2018-09-18 21:39:42 -0700240 mFactory.mCreateNativeWindowSurface = f;
Lloyd Pique0b1fe702018-01-22 18:03:16 -0800241 }
242
Daniel Solomon42d04562019-01-20 21:03:19 -0800243 void setInternalDisplayPrimaries(const ui::DisplayPrimaries& primaries) {
244 memcpy(&mFlinger->mInternalDisplayPrimaries, &primaries, sizeof(ui::DisplayPrimaries));
245 }
246
Dominik Laskowskib7251f42020-04-20 17:42:59 -0700247 static auto& mutableLayerCurrentState(const sp<Layer>& layer) { return layer->mCurrentState; }
248 static auto& mutableLayerDrawingState(const sp<Layer>& layer) { return layer->mDrawingState; }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700249
Valerie Haud251afb2019-03-29 14:19:02 -0700250 auto& mutableStateLock() { return mFlinger->mStateLock; }
251
Dominik Laskowskib7251f42020-04-20 17:42:59 -0700252 static auto findOutputLayerForDisplay(const sp<Layer>& layer,
253 const sp<const DisplayDevice>& display) {
254 return layer->findOutputLayerForDisplay(display.get());
255 }
256
257 static void setLayerSidebandStream(const sp<Layer>& layer,
258 const sp<NativeHandle>& sidebandStream) {
Lloyd Pique0449b0f2018-12-20 16:23:45 -0800259 layer->mDrawingState.sidebandStream = sidebandStream;
Lloyd Pique0b785d82018-12-04 17:25:27 -0800260 layer->mSidebandStream = sidebandStream;
Lloyd Piquede196652020-01-22 17:29:58 -0800261 layer->editCompositionState()->sidebandStream = sidebandStream;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700262 }
263
Dominik Laskowskib7251f42020-04-20 17:42:59 -0700264 void setLayerCompositionType(const sp<Layer>& layer, hal::Composition type) {
265 auto outputLayer = findOutputLayerForDisplay(layer, mFlinger->getDefaultDisplayDevice());
Lloyd Pique37c2c9b2018-12-04 17:25:10 -0800266 LOG_ALWAYS_FATAL_IF(!outputLayer);
267 auto& state = outputLayer->editState();
268 LOG_ALWAYS_FATAL_IF(!outputLayer->getState().hwc);
Peiyong Line9d809e2020-04-14 13:10:48 -0700269 (*state.hwc).hwcCompositionType = type;
Dominik Laskowskib7251f42020-04-20 17:42:59 -0700270 }
Lloyd Pique37c2c9b2018-12-04 17:25:10 -0800271
Dominik Laskowskib7251f42020-04-20 17:42:59 -0700272 static void setLayerPotentialCursor(const sp<Layer>& layer, bool potentialCursor) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700273 layer->mPotentialCursor = potentialCursor;
274 }
275
Lloyd Piquef58625d2017-12-19 13:22:33 -0800276 /* ------------------------------------------------------------------------
277 * Forwarding for functions being tested
278 */
Lloyd Pique0b1fe702018-01-22 18:03:16 -0800279
Lloyd Piquea482f992018-01-22 19:00:34 -0800280 auto createDisplay(const String8& displayName, bool secure) {
281 return mFlinger->createDisplay(displayName, secure);
282 }
283
Dominik Laskowskieecd6592018-05-29 10:25:41 -0700284 auto destroyDisplay(const sp<IBinder>& displayToken) {
285 return mFlinger->destroyDisplay(displayToken);
286 }
Lloyd Piquea482f992018-01-22 19:00:34 -0800287
Lloyd Pique9370a482019-10-03 17:58:30 -0700288 auto setupNewDisplayDeviceInternal(
289 const wp<IBinder>& displayToken,
290 std::shared_ptr<compositionengine::Display> compositionDisplay,
291 const DisplayDeviceState& state,
292 const sp<compositionengine::DisplaySurface>& dispSurface,
Dominik Laskowski0a1435d2020-04-21 00:27:31 -0700293 const sp<IGraphicBufferProducer>& producer) NO_THREAD_SAFETY_ANALYSIS {
Lloyd Pique9370a482019-10-03 17:58:30 -0700294 return mFlinger->setupNewDisplayDeviceInternal(displayToken, compositionDisplay, state,
295 dispSurface, producer);
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800296 }
297
Lloyd Pique0b1fe702018-01-22 18:03:16 -0800298 auto handleTransactionLocked(uint32_t transactionFlags) {
Vishnu Nairfa5f8df2019-02-13 17:02:51 -0800299 Mutex::Autolock _l(mFlinger->mStateLock);
Lloyd Pique0b1fe702018-01-22 18:03:16 -0800300 return mFlinger->handleTransactionLocked(transactionFlags);
301 }
Lloyd Piquef58625d2017-12-19 13:22:33 -0800302
Peiyong Line9d809e2020-04-14 13:10:48 -0700303 auto onHotplugReceived(int32_t sequenceId, hal::HWDisplayId display,
304 hal::Connection connection) {
Lloyd Pique6cf11032018-01-22 18:57:44 -0800305 return mFlinger->onHotplugReceived(sequenceId, display, connection);
306 }
307
Vishnu Nairce5d0cc2019-02-28 14:38:41 -0800308 auto setDisplayStateLocked(const DisplayState& s) {
309 Mutex::Autolock _l(mFlinger->mStateLock);
310 return mFlinger->setDisplayStateLocked(s);
311 }
Lloyd Pique9d9cf402018-02-16 17:47:13 -0800312
Dominik Laskowski83b88212018-12-11 13:34:06 -0800313 // Allow reading display state without locking, as if called on the SF main thread.
314 auto onInitializeDisplays() NO_THREAD_SAFETY_ANALYSIS {
315 return mFlinger->onInitializeDisplays();
316 }
Lloyd Pique86016da2018-03-01 16:09:38 -0800317
Lais Andrade3a6e47d2020-04-02 11:20:16 +0100318 auto notifyPowerBoost(int32_t boostId) { return mFlinger->notifyPowerBoost(boostId); }
319
Dominik Laskowski83b88212018-12-11 13:34:06 -0800320 // Allow reading display state without locking, as if called on the SF main thread.
321 auto setPowerModeInternal(const sp<DisplayDevice>& display,
Peiyong Lin65248e02020-04-18 21:15:07 -0700322 hal::PowerMode mode) NO_THREAD_SAFETY_ANALYSIS {
Dominik Laskowskie9774092018-12-11 10:04:24 -0800323 return mFlinger->setPowerModeInternal(display, mode);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -0800324 }
325
Ady Abraham0ed31c92020-04-16 11:48:45 -0700326 auto onMessageReceived(int32_t what) { return mFlinger->onMessageReceived(what, systemTime()); }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700327
chaviw426b5c02020-07-27 11:20:15 -0700328 auto renderScreenImplLocked(const RenderArea& renderArea,
329 SurfaceFlinger::TraverseLayersFunction traverseLayers,
chaviwc6ad8af2020-08-03 11:33:30 -0700330 const sp<GraphicBuffer>& buffer, bool forSystem, int* outSyncFd,
331 bool regionSampling) {
chaviw426b5c02020-07-27 11:20:15 -0700332 ScreenCaptureResults captureResults;
chaviwc6ad8af2020-08-03 11:33:30 -0700333 return mFlinger->renderScreenImplLocked(renderArea, traverseLayers, buffer, forSystem,
334 outSyncFd, regionSampling, captureResults);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700335 }
336
chaviw4b9d5e12020-08-04 18:30:35 -0700337 auto traverseLayersInLayerStack(ui::LayerStack layerStack, int32_t uid,
Marin Shalamanov1c434292020-06-12 01:47:29 +0200338 const LayerVector::Visitor& visitor) {
chaviw4b9d5e12020-08-04 18:30:35 -0700339 return mFlinger->SurfaceFlinger::traverseLayersInLayerStack(layerStack, uid, visitor);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700340 }
341
Daniel Solomon42d04562019-01-20 21:03:19 -0800342 auto getDisplayNativePrimaries(const sp<IBinder>& displayToken,
343 ui::DisplayPrimaries &primaries) {
344 return mFlinger->SurfaceFlinger::getDisplayNativePrimaries(displayToken, primaries);
345 }
346
Valerie Haud251afb2019-03-29 14:19:02 -0700347 auto& getTransactionQueue() { return mFlinger->mTransactionQueues; }
348
349 auto setTransactionState(const Vector<ComposerState>& states,
350 const Vector<DisplayState>& displays, uint32_t flags,
351 const sp<IBinder>& applyToken,
352 const InputWindowCommands& inputWindowCommands,
353 int64_t desiredPresentTime, const client_cache_t& uncacheBuffer,
354 bool hasListenerCallbacks,
355 std::vector<ListenerCallbacks>& listenerCallbacks) {
356 return mFlinger->setTransactionState(states, displays, flags, applyToken,
357 inputWindowCommands, desiredPresentTime, uncacheBuffer,
358 hasListenerCallbacks, listenerCallbacks);
359 }
360
361 auto flushTransactionQueues() { return mFlinger->flushTransactionQueues(); };
362
Eduardo Rochaac867192020-09-14 20:12:17 +0000363 auto onTransact(uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) {
364 return mFlinger->onTransact(code, data, reply, flags);
365 }
366
Lloyd Pique86016da2018-03-01 16:09:38 -0800367 /* ------------------------------------------------------------------------
368 * Read-only access to private data to assert post-conditions.
369 */
370
371 const auto& getAnimFrameTracker() const { return mFlinger->mAnimFrameTracker; }
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -0800372 const auto& getHasPoweredOff() const { return mFlinger->mHasPoweredOff; }
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -0800373 const auto& getVisibleRegionsDirty() const { return mFlinger->mVisibleRegionsDirty; }
Lloyd Pique441d5042018-10-18 16:49:51 -0700374 auto& getHwComposer() const {
375 return static_cast<impl::HWComposer&>(mFlinger->getHwComposer());
376 }
Lloyd Pique9370a482019-10-03 17:58:30 -0700377 auto& getCompositionEngine() const { return mFlinger->getCompositionEngine(); }
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -0800378
Lloyd Pique86016da2018-03-01 16:09:38 -0800379 const auto& getCompositorTiming() const { return mFlinger->getBE().mCompositorTiming; }
380
Lloyd Piquef58625d2017-12-19 13:22:33 -0800381 /* ------------------------------------------------------------------------
382 * Read-write access to private data to set up preconditions and assert
383 * post-conditions.
384 */
Lloyd Pique0b1fe702018-01-22 18:03:16 -0800385
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800386 auto& mutableHasWideColorDisplay() { return SurfaceFlinger::hasWideColorDisplay; }
Peiyong Lin13effd12018-07-24 17:01:47 -0700387 auto& mutableUseColorManagement() { return SurfaceFlinger::useColorManagement; }
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800388
Lloyd Piquee39cad22017-12-20 17:01:29 -0800389 auto& mutableCurrentState() { return mFlinger->mCurrentState; }
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800390 auto& mutableDisplayColorSetting() { return mFlinger->mDisplayColorSetting; }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700391 auto& mutableDisplays() { return mFlinger->mDisplays; }
Lloyd Piquee39cad22017-12-20 17:01:29 -0800392 auto& mutableDrawingState() { return mFlinger->mDrawingState; }
Lloyd Piquee39cad22017-12-20 17:01:29 -0800393 auto& mutableEventQueue() { return mFlinger->mEventQueue; }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700394 auto& mutableGeometryInvalid() { return mFlinger->mGeometryInvalid; }
Lloyd Pique0b1fe702018-01-22 18:03:16 -0800395 auto& mutableInterceptor() { return mFlinger->mInterceptor; }
Lloyd Pique6cf11032018-01-22 18:57:44 -0800396 auto& mutableMainThreadId() { return mFlinger->mMainThreadId; }
Lloyd Pique0b1fe702018-01-22 18:03:16 -0800397 auto& mutablePendingHotplugEvents() { return mFlinger->mPendingHotplugEvents; }
Dominik Laskowski075d3172018-05-24 15:50:06 -0700398 auto& mutablePhysicalDisplayTokens() { return mFlinger->mPhysicalDisplayTokens; }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700399 auto& mutableTexturePool() { return mFlinger->mTexturePool; }
Lloyd Pique0b1fe702018-01-22 18:03:16 -0800400 auto& mutableTransactionFlags() { return mFlinger->mTransactionFlags; }
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800401 auto& mutableUseHwcVirtualDisplays() { return mFlinger->mUseHwcVirtualDisplays; }
Peiyong Lin74ca2f42019-01-14 19:36:57 -0800402 auto& mutablePowerAdvisor() { return mFlinger->mPowerAdvisor; }
Lloyd Pique4fe29402019-08-12 16:51:24 -0700403 auto& mutableDebugDisableHWC() { return mFlinger->mDebugDisableHWC; }
Lloyd Piquee39cad22017-12-20 17:01:29 -0800404
Lloyd Pique6cf11032018-01-22 18:57:44 -0800405 auto& mutableComposerSequenceId() { return mFlinger->getBE().mComposerSequenceId; }
Lloyd Pique441d5042018-10-18 16:49:51 -0700406 auto& mutableHwcDisplayData() { return getHwComposer().mDisplayData; }
407 auto& mutableHwcPhysicalDisplayIdMap() { return getHwComposer().mPhysicalDisplayIdMap; }
408 auto& mutableInternalHwcDisplayId() { return getHwComposer().mInternalHwcDisplayId; }
409 auto& mutableExternalHwcDisplayId() { return getHwComposer().mExternalHwcDisplayId; }
Ady Abraham60e42ea2020-03-09 19:17:31 -0700410 auto& mutableUseFrameRateApi() { return mFlinger->useFrameRateApi; }
Lloyd Piquea618d852018-01-17 11:52:30 -0800411
Valerie Hau09e60052019-12-15 14:51:15 -0800412 auto fromHandle(const sp<IBinder>& handle) {
Valerie Hau09e60052019-12-15 14:51:15 -0800413 return mFlinger->fromHandle(handle);
414 }
415
Lloyd Piquee39cad22017-12-20 17:01:29 -0800416 ~TestableSurfaceFlinger() {
417 // All these pointer and container clears help ensure that GMock does
418 // not report a leaked object, since the SurfaceFlinger instance may
419 // still be referenced by something despite our best efforts to destroy
420 // it after each test is done.
421 mutableDisplays().clear();
Ady Abraham2939f092019-03-04 17:44:06 -0800422 mutableCurrentState().displays.clear();
423 mutableDrawingState().displays.clear();
Lloyd Pique0b1fe702018-01-22 18:03:16 -0800424 mutableEventQueue().reset();
Pablo Gamito5cfc6e52020-09-10 11:18:03 +0000425 mutableInterceptor().clear();
Lloyd Pique2eb71eb2019-08-13 13:23:03 -0700426 mFlinger->mScheduler.reset();
Lloyd Pique441d5042018-10-18 16:49:51 -0700427 mFlinger->mCompositionEngine->setHwComposer(std::unique_ptr<HWComposer>());
Lloyd Piqueb97e04f2018-10-18 17:07:05 -0700428 mFlinger->mCompositionEngine->setRenderEngine(
429 std::unique_ptr<renderengine::RenderEngine>());
Lloyd Piquee39cad22017-12-20 17:01:29 -0800430 }
Lloyd Piquef58625d2017-12-19 13:22:33 -0800431
Lloyd Piquea618d852018-01-17 11:52:30 -0800432 /* ------------------------------------------------------------------------
433 * Wrapper classes for Read-write access to private data to set up
434 * preconditions and assert post-conditions.
435 */
Ana Krulec4593b692019-01-11 22:07:25 -0800436 struct HWC2Display : public HWC2::impl::Display {
Peiyong Lin74ca2f42019-01-14 19:36:57 -0800437 HWC2Display(Hwc2::Composer& composer,
Peiyong Line9d809e2020-04-14 13:10:48 -0700438 const std::unordered_set<hal::Capability>& capabilities, hal::HWDisplayId id,
439 hal::DisplayType type)
Peiyong Lin74ca2f42019-01-14 19:36:57 -0800440 : HWC2::impl::Display(composer, capabilities, id, type) {}
Lloyd Piquea618d852018-01-17 11:52:30 -0800441 ~HWC2Display() {
442 // Prevents a call to disable vsyncs.
Peiyong Line9d809e2020-04-14 13:10:48 -0700443 mType = hal::DisplayType::INVALID;
Lloyd Piquea618d852018-01-17 11:52:30 -0800444 }
445
446 auto& mutableIsConnected() { return this->mIsConnected; }
447 auto& mutableConfigs() { return this->mConfigs; }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700448 auto& mutableLayers() { return this->mLayers; }
Lloyd Piquea618d852018-01-17 11:52:30 -0800449 };
450
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800451 class FakeHwcDisplayInjector {
452 public:
Peiyong Line9d809e2020-04-14 13:10:48 -0700453 static constexpr hal::HWDisplayId DEFAULT_HWC_DISPLAY_ID = 1000;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800454 static constexpr int32_t DEFAULT_WIDTH = 1920;
455 static constexpr int32_t DEFAULT_HEIGHT = 1280;
456 static constexpr int32_t DEFAULT_REFRESH_RATE = 16'666'666;
Ady Abraham2139f732019-11-13 18:56:40 -0800457 static constexpr int32_t DEFAULT_CONFIG_GROUP = 7;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800458 static constexpr int32_t DEFAULT_DPI = 320;
Peiyong Line9d809e2020-04-14 13:10:48 -0700459 static constexpr hal::HWConfigId DEFAULT_ACTIVE_CONFIG = 0;
Peiyong Lin65248e02020-04-18 21:15:07 -0700460 static constexpr hal::PowerMode DEFAULT_POWER_MODE = hal::PowerMode::ON;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800461
Peiyong Line9d809e2020-04-14 13:10:48 -0700462 FakeHwcDisplayInjector(DisplayId displayId, hal::DisplayType hwcDisplayType, bool isPrimary)
Dominik Laskowski075d3172018-05-24 15:50:06 -0700463 : mDisplayId(displayId), mHwcDisplayType(hwcDisplayType), mIsPrimary(isPrimary) {}
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800464
Peiyong Line9d809e2020-04-14 13:10:48 -0700465 auto& setHwcDisplayId(hal::HWDisplayId displayId) {
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800466 mHwcDisplayId = displayId;
467 return *this;
468 }
469
470 auto& setWidth(int32_t width) {
471 mWidth = width;
472 return *this;
473 }
474
475 auto& setHeight(int32_t height) {
476 mHeight = height;
477 return *this;
478 }
479
Ady Abraham8a82ba62020-01-17 12:43:17 -0800480 auto& setRefreshRate(int32_t refreshRate) {
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800481 mRefreshRate = refreshRate;
482 return *this;
483 }
484
485 auto& setDpiX(int32_t dpi) {
486 mDpiX = dpi;
487 return *this;
488 }
489
490 auto& setDpiY(int32_t dpi) {
491 mDpiY = dpi;
492 return *this;
493 }
494
Peiyong Line9d809e2020-04-14 13:10:48 -0700495 auto& setActiveConfig(hal::HWConfigId config) {
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800496 mActiveConfig = config;
497 return *this;
498 }
499
Peiyong Line9d809e2020-04-14 13:10:48 -0700500 auto& setCapabilities(const std::unordered_set<hal::Capability>* capabilities) {
Lloyd Piquee22f0332018-07-16 16:35:56 -0700501 mCapabilities = capabilities;
502 return *this;
503 }
504
Peiyong Lin65248e02020-04-18 21:15:07 -0700505 auto& setPowerMode(hal::PowerMode mode) {
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700506 mPowerMode = mode;
507 return *this;
508 }
509
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800510 void inject(TestableSurfaceFlinger* flinger, Hwc2::Composer* composer) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700511 static const std::unordered_set<hal::Capability> defaultCapabilities;
Lloyd Piquee22f0332018-07-16 16:35:56 -0700512 if (mCapabilities == nullptr) mCapabilities = &defaultCapabilities;
513
514 // Caution - Make sure that any values passed by reference here do
515 // not refer to an instance owned by FakeHwcDisplayInjector. This
516 // class has temporary lifetime, while the constructed HWC2::Display
517 // is much longer lived.
Peiyong Lin74ca2f42019-01-14 19:36:57 -0800518 auto display = std::make_unique<HWC2Display>(*composer, *mCapabilities, mHwcDisplayId,
519 mHwcDisplayType);
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800520
521 auto config = HWC2::Display::Config::Builder(*display, mActiveConfig);
522 config.setWidth(mWidth);
523 config.setHeight(mHeight);
524 config.setVsyncPeriod(mRefreshRate);
525 config.setDpiX(mDpiX);
526 config.setDpiY(mDpiY);
Ady Abraham2139f732019-11-13 18:56:40 -0800527 config.setConfigGroup(mConfigGroup);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800528 display->mutableConfigs().emplace(static_cast<int32_t>(mActiveConfig), config.build());
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800529 display->mutableIsConnected() = true;
Peiyong Lin65248e02020-04-18 21:15:07 -0700530 display->setPowerMode(mPowerMode);
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800531
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800532 flinger->mutableHwcDisplayData()[mDisplayId].hwcDisplay = std::move(display);
Dominik Laskowski075d3172018-05-24 15:50:06 -0700533
Peiyong Line9d809e2020-04-14 13:10:48 -0700534 if (mHwcDisplayType == hal::DisplayType::PHYSICAL) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700535 flinger->mutableHwcPhysicalDisplayIdMap().emplace(mHwcDisplayId, mDisplayId);
536 (mIsPrimary ? flinger->mutableInternalHwcDisplayId()
537 : flinger->mutableExternalHwcDisplayId()) = mHwcDisplayId;
538 }
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800539 }
540
541 private:
Dominik Laskowski075d3172018-05-24 15:50:06 -0700542 const DisplayId mDisplayId;
Peiyong Line9d809e2020-04-14 13:10:48 -0700543 const hal::DisplayType mHwcDisplayType;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700544 const bool mIsPrimary;
545
Peiyong Line9d809e2020-04-14 13:10:48 -0700546 hal::HWDisplayId mHwcDisplayId = DEFAULT_HWC_DISPLAY_ID;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800547 int32_t mWidth = DEFAULT_WIDTH;
548 int32_t mHeight = DEFAULT_HEIGHT;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800549 int32_t mRefreshRate = DEFAULT_REFRESH_RATE;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800550 int32_t mDpiX = DEFAULT_DPI;
Ady Abraham2139f732019-11-13 18:56:40 -0800551 int32_t mConfigGroup = DEFAULT_CONFIG_GROUP;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800552 int32_t mDpiY = DEFAULT_DPI;
Peiyong Line9d809e2020-04-14 13:10:48 -0700553 hal::HWConfigId mActiveConfig = DEFAULT_ACTIVE_CONFIG;
Peiyong Lin65248e02020-04-18 21:15:07 -0700554 hal::PowerMode mPowerMode = DEFAULT_POWER_MODE;
Peiyong Line9d809e2020-04-14 13:10:48 -0700555 const std::unordered_set<hal::Capability>* mCapabilities = nullptr;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800556 };
557
558 class FakeDisplayDeviceInjector {
559 public:
Dominik Laskowski075d3172018-05-24 15:50:06 -0700560 FakeDisplayDeviceInjector(TestableSurfaceFlinger& flinger,
Lloyd Pique9370a482019-10-03 17:58:30 -0700561 std::shared_ptr<compositionengine::Display> compositionDisplay,
Dominik Laskowski55c85402020-01-21 16:25:47 -0800562 std::optional<DisplayConnectionType> connectionType,
Peiyong Line9d809e2020-04-14 13:10:48 -0700563 std::optional<hal::HWDisplayId> hwcDisplayId, bool isPrimary)
Lloyd Pique9370a482019-10-03 17:58:30 -0700564 : mFlinger(flinger),
Marin Shalamanov700e6392020-02-12 20:22:26 +0100565 mCreationArgs(flinger.mFlinger.get(), mDisplayToken, compositionDisplay),
566 mHwcDisplayId(hwcDisplayId) {
Dominik Laskowski55c85402020-01-21 16:25:47 -0800567 mCreationArgs.connectionType = connectionType;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700568 mCreationArgs.isPrimary = isPrimary;
569 }
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800570
571 sp<IBinder> token() const { return mDisplayToken; }
572
573 DisplayDeviceState& mutableDrawingDisplayState() {
574 return mFlinger.mutableDrawingState().displays.editValueFor(mDisplayToken);
575 }
576
577 DisplayDeviceState& mutableCurrentDisplayState() {
578 return mFlinger.mutableCurrentState().displays.editValueFor(mDisplayToken);
579 }
580
Lloyd Pique9d9cf402018-02-16 17:47:13 -0800581 const auto& getDrawingDisplayState() {
582 return mFlinger.mutableDrawingState().displays.valueFor(mDisplayToken);
583 }
584
585 const auto& getCurrentDisplayState() {
586 return mFlinger.mutableCurrentState().displays.valueFor(mDisplayToken);
587 }
588
Dominik Laskowski9fae1022018-05-29 13:17:40 -0700589 auto& mutableDisplayDevice() { return mFlinger.mutableDisplays()[mDisplayToken]; }
Lloyd Pique9d9cf402018-02-16 17:47:13 -0800590
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800591 auto& setNativeWindow(const sp<ANativeWindow>& nativeWindow) {
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700592 mCreationArgs.nativeWindow = nativeWindow;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800593 return *this;
594 }
595
Lloyd Pique542307f2018-10-19 13:24:08 -0700596 auto& setDisplaySurface(const sp<compositionengine::DisplaySurface>& displaySurface) {
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700597 mCreationArgs.displaySurface = displaySurface;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800598 return *this;
599 }
600
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800601 auto& setSecure(bool secure) {
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700602 mCreationArgs.isSecure = secure;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800603 return *this;
604 }
605
Peiyong Lin65248e02020-04-18 21:15:07 -0700606 auto& setPowerMode(hal::PowerMode mode) {
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700607 mCreationArgs.initialPowerMode = mode;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700608 return *this;
609 }
610
Valerie Hau9758ae02018-10-09 16:05:09 -0700611 auto& setHwcColorModes(
612 const std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>>
613 hwcColorModes) {
614 mCreationArgs.hwcColorModes = hwcColorModes;
615 return *this;
616 }
617
618 auto& setHasWideColorGamut(bool hasWideColorGamut) {
619 mCreationArgs.hasWideColorGamut = hasWideColorGamut;
620 return *this;
621 }
622
Lloyd Pique33050472019-12-19 17:12:44 -0800623 auto& setPhysicalOrientation(ui::Rotation orientation) {
624 mCreationArgs.physicalOrientation = orientation;
625 return *this;
626 }
627
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800628 sp<DisplayDevice> inject() {
Lloyd Pique9370a482019-10-03 17:58:30 -0700629 const auto displayId = mCreationArgs.compositionDisplay->getDisplayId();
630
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800631 DisplayDeviceState state;
Dominik Laskowski55c85402020-01-21 16:25:47 -0800632 if (const auto type = mCreationArgs.connectionType) {
Lloyd Pique9370a482019-10-03 17:58:30 -0700633 LOG_ALWAYS_FATAL_IF(!displayId);
Marin Shalamanov700e6392020-02-12 20:22:26 +0100634 LOG_ALWAYS_FATAL_IF(!mHwcDisplayId);
Marin Shalamanova524a092020-07-27 21:39:55 +0200635 state.physical = {.id = static_cast<PhysicalDisplayId>(*displayId),
636 .type = *type,
637 .hwcDisplayId = *mHwcDisplayId};
Dominik Laskowski55c85402020-01-21 16:25:47 -0800638 }
639
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700640 state.isSecure = mCreationArgs.isSecure;
641
Lloyd Pique9370a482019-10-03 17:58:30 -0700642 sp<DisplayDevice> device = new DisplayDevice(mCreationArgs);
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700643 mFlinger.mutableDisplays().emplace(mDisplayToken, device);
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800644 mFlinger.mutableCurrentState().displays.add(mDisplayToken, state);
645 mFlinger.mutableDrawingState().displays.add(mDisplayToken, state);
646
Dominik Laskowski55c85402020-01-21 16:25:47 -0800647 if (const auto& physical = state.physical) {
648 mFlinger.mutablePhysicalDisplayTokens()[physical->id] = mDisplayToken;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800649 }
650
651 return device;
652 }
653
654 private:
655 TestableSurfaceFlinger& mFlinger;
656 sp<BBinder> mDisplayToken = new BBinder();
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700657 DisplayDeviceCreationArgs mCreationArgs;
Peiyong Line9d809e2020-04-14 13:10:48 -0700658 const std::optional<hal::HWDisplayId> mHwcDisplayId;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800659 };
660
Dominik Laskowski8b01cc02020-07-14 19:02:41 -0700661private:
662 void setVsyncEnabled(bool) override {}
663 void changeRefreshRate(const Scheduler::RefreshRate&, Scheduler::ConfigEvent) override {}
664 void repaintEverythingForHWC() override {}
665 void kernelTimerChanged(bool) override {}
666
Lloyd Pique90c115d2018-09-18 21:39:42 -0700667 surfaceflinger::test::Factory mFactory;
668 sp<SurfaceFlinger> mFlinger = new SurfaceFlinger(mFactory, SurfaceFlinger::SkipInitialization);
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700669 TestableScheduler* mScheduler = nullptr;
Ady Abrahamabc27602020-04-08 17:20:29 -0700670 Hwc2::mock::Display mDisplay;
Lloyd Piquef58625d2017-12-19 13:22:33 -0800671};
672
673} // namespace android