Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #pragma once |
| 18 | |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 19 | #include <compositionengine/Display.h> |
Lloyd Pique | 0b785d8 | 2018-12-04 17:25:27 -0800 | [diff] [blame] | 20 | #include <compositionengine/Layer.h> |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 21 | #include <compositionengine/LayerFECompositionState.h> |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 22 | #include <compositionengine/OutputLayer.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 23 | #include <compositionengine/impl/CompositionEngine.h> |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 24 | #include <compositionengine/impl/OutputLayerCompositionState.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 25 | |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 26 | #include "BufferQueueLayer.h" |
| 27 | #include "BufferStateLayer.h" |
| 28 | #include "ColorLayer.h" |
| 29 | #include "ContainerLayer.h" |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 30 | #include "DisplayDevice.h" |
Ana Krulec | 757f63a | 2019-01-25 10:46:18 -0800 | [diff] [blame] | 31 | #include "FakePhaseOffsets.h" |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 32 | #include "Layer.h" |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 33 | #include "NativeWindowSurface.h" |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 34 | #include "Scheduler/MessageQueue.h" |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 35 | #include "Scheduler/RefreshRateConfigs.h" |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 36 | #include "StartPropertySetThread.h" |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 37 | #include "SurfaceFlinger.h" |
Lloyd Pique | 24f3bfe | 2019-10-02 19:29:10 -0700 | [diff] [blame^] | 38 | #include "SurfaceFlingerDefaultFactory.h" |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 39 | #include "SurfaceInterceptor.h" |
Dominik Laskowski | 7c9dbf9 | 2019-08-01 17:57:31 -0700 | [diff] [blame] | 40 | #include "TestableScheduler.h" |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame] | 41 | |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 42 | namespace android { |
| 43 | |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 44 | class EventThread; |
| 45 | |
Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 46 | namespace renderengine { |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 47 | |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 48 | class RenderEngine; |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 49 | |
| 50 | } // namespace renderengine |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 51 | |
| 52 | namespace Hwc2 { |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 53 | |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 54 | class Composer; |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 55 | |
| 56 | } // namespace Hwc2 |
| 57 | |
| 58 | namespace surfaceflinger::test { |
| 59 | |
| 60 | class Factory final : public surfaceflinger::Factory { |
| 61 | public: |
| 62 | ~Factory() = default; |
| 63 | |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 64 | std::unique_ptr<DispSync> createDispSync(const char*, bool) override { |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 65 | // TODO: Use test-fixture controlled factory |
| 66 | return nullptr; |
| 67 | } |
| 68 | |
| 69 | std::unique_ptr<EventControlThread> createEventControlThread( |
| 70 | std::function<void(bool)>) override { |
| 71 | // TODO: Use test-fixture controlled factory |
| 72 | return nullptr; |
| 73 | } |
| 74 | |
| 75 | std::unique_ptr<HWComposer> createHWComposer(const std::string&) override { |
| 76 | // TODO: Use test-fixture controlled factory |
| 77 | return nullptr; |
| 78 | } |
| 79 | |
| 80 | std::unique_ptr<MessageQueue> createMessageQueue() override { |
| 81 | // TODO: Use test-fixture controlled factory |
| 82 | return std::make_unique<android::impl::MessageQueue>(); |
| 83 | } |
| 84 | |
Ana Krulec | 757f63a | 2019-01-25 10:46:18 -0800 | [diff] [blame] | 85 | std::unique_ptr<scheduler::PhaseOffsets> createPhaseOffsets() override { |
| 86 | return std::make_unique<scheduler::FakePhaseOffsets>(); |
| 87 | } |
| 88 | |
Ady Abraham | 09bd392 | 2019-04-08 10:44:56 -0700 | [diff] [blame] | 89 | std::unique_ptr<Scheduler> createScheduler(std::function<void(bool)>, |
| 90 | const scheduler::RefreshRateConfigs&) override { |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 91 | // TODO: Use test-fixture controlled factory |
| 92 | return nullptr; |
| 93 | } |
| 94 | |
| 95 | std::unique_ptr<SurfaceInterceptor> createSurfaceInterceptor(SurfaceFlinger* flinger) override { |
| 96 | // TODO: Use test-fixture controlled factory |
| 97 | return std::make_unique<android::impl::SurfaceInterceptor>(flinger); |
| 98 | } |
| 99 | |
| 100 | sp<StartPropertySetThread> createStartPropertySetThread(bool timestampPropertyValue) override { |
| 101 | // TODO: Use test-fixture controlled factory |
| 102 | return new StartPropertySetThread(timestampPropertyValue); |
| 103 | } |
| 104 | |
| 105 | sp<DisplayDevice> createDisplayDevice(DisplayDeviceCreationArgs&& creationArgs) override { |
| 106 | // TODO: Use test-fixture controlled factory |
| 107 | return new DisplayDevice(std::move(creationArgs)); |
| 108 | } |
| 109 | |
| 110 | sp<GraphicBuffer> createGraphicBuffer(uint32_t width, uint32_t height, PixelFormat format, |
| 111 | uint32_t layerCount, uint64_t usage, |
| 112 | std::string requestorName) override { |
| 113 | // TODO: Use test-fixture controlled factory |
| 114 | return new GraphicBuffer(width, height, format, layerCount, usage, requestorName); |
| 115 | } |
| 116 | |
| 117 | void createBufferQueue(sp<IGraphicBufferProducer>* outProducer, |
| 118 | sp<IGraphicBufferConsumer>* outConsumer, |
| 119 | bool consumerIsSurfaceFlinger) override { |
| 120 | if (!mCreateBufferQueue) return; |
| 121 | mCreateBufferQueue(outProducer, outConsumer, consumerIsSurfaceFlinger); |
| 122 | } |
| 123 | |
| 124 | std::unique_ptr<surfaceflinger::NativeWindowSurface> createNativeWindowSurface( |
| 125 | const sp<IGraphicBufferProducer>& producer) override { |
| 126 | if (!mCreateNativeWindowSurface) return nullptr; |
| 127 | return mCreateNativeWindowSurface(producer); |
| 128 | } |
| 129 | |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 130 | std::unique_ptr<compositionengine::CompositionEngine> createCompositionEngine() override { |
| 131 | return compositionengine::impl::createCompositionEngine(); |
| 132 | } |
| 133 | |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 134 | sp<BufferQueueLayer> createBufferQueueLayer(const LayerCreationArgs&) override { |
| 135 | // TODO: Use test-fixture controlled factory |
| 136 | return nullptr; |
| 137 | } |
| 138 | |
| 139 | sp<BufferStateLayer> createBufferStateLayer(const LayerCreationArgs&) override { |
| 140 | // TODO: Use test-fixture controlled factory |
| 141 | return nullptr; |
| 142 | } |
| 143 | |
| 144 | sp<ColorLayer> createColorLayer(const LayerCreationArgs&) override { |
| 145 | // TODO: Use test-fixture controlled factory |
| 146 | return nullptr; |
| 147 | } |
| 148 | |
| 149 | sp<ContainerLayer> createContainerLayer(const LayerCreationArgs&) override { |
| 150 | // TODO: Use test-fixture controlled factory |
| 151 | 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 Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 164 | |
| 165 | using CreateCompositionEngineFunction = |
| 166 | std::function<std::unique_ptr<compositionengine::CompositionEngine>()>; |
| 167 | CreateCompositionEngineFunction mCreateCompositionEngine; |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 168 | }; |
| 169 | |
| 170 | } // namespace surfaceflinger::test |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 171 | |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 172 | class TestableSurfaceFlinger { |
| 173 | public: |
Dominik Laskowski | 7c9dbf9 | 2019-08-01 17:57:31 -0700 | [diff] [blame] | 174 | TestableScheduler* scheduler() { return mScheduler; } |
| 175 | |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 176 | // Extend this as needed for accessing SurfaceFlinger private (and public) |
| 177 | // functions. |
| 178 | |
Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 179 | void setupRenderEngine(std::unique_ptr<renderengine::RenderEngine> renderEngine) { |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 180 | mFlinger->mCompositionEngine->setRenderEngine(std::move(renderEngine)); |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | void setupComposer(std::unique_ptr<Hwc2::Composer> composer) { |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 184 | mFlinger->mCompositionEngine->setHwComposer( |
| 185 | std::make_unique<impl::HWComposer>(std::move(composer))); |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 186 | } |
| 187 | |
Dominik Laskowski | 7c9dbf9 | 2019-08-01 17:57:31 -0700 | [diff] [blame] | 188 | void setupScheduler(std::unique_ptr<DispSync> primaryDispSync, |
| 189 | std::unique_ptr<EventControlThread> eventControlThread, |
| 190 | std::unique_ptr<EventThread> appEventThread, |
| 191 | std::unique_ptr<EventThread> sfEventThread) { |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 192 | std::vector<scheduler::RefreshRateConfigs::InputConfig> configs{{/*hwcId=*/0, 16666667}}; |
| 193 | mFlinger->mRefreshRateConfigs = |
| 194 | std::make_unique<scheduler::RefreshRateConfigs>(/*refreshRateSwitching=*/false, |
| 195 | configs, /*currentConfig=*/0); |
| 196 | mFlinger->mRefreshRateStats = |
| 197 | std::make_unique<scheduler::RefreshRateStats>(*mFlinger->mRefreshRateConfigs, |
| 198 | *mFlinger->mTimeStats, |
| 199 | /*currentConfig=*/0, |
| 200 | /*powerMode=*/HWC_POWER_MODE_OFF); |
| 201 | |
Dominik Laskowski | 7c9dbf9 | 2019-08-01 17:57:31 -0700 | [diff] [blame] | 202 | mScheduler = |
| 203 | new TestableScheduler(std::move(primaryDispSync), std::move(eventControlThread), |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 204 | *mFlinger->mRefreshRateConfigs); |
Dominik Laskowski | 7c9dbf9 | 2019-08-01 17:57:31 -0700 | [diff] [blame] | 205 | |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 206 | mFlinger->mAppConnectionHandle = mScheduler->createConnection(std::move(appEventThread)); |
| 207 | mFlinger->mSfConnectionHandle = mScheduler->createConnection(std::move(sfEventThread)); |
Dominik Laskowski | 7c9dbf9 | 2019-08-01 17:57:31 -0700 | [diff] [blame] | 208 | |
| 209 | mFlinger->mScheduler.reset(mScheduler); |
| 210 | mFlinger->mVSyncModulator.emplace(*mScheduler, mFlinger->mAppConnectionHandle, |
| 211 | mFlinger->mSfConnectionHandle, |
| 212 | mFlinger->mPhaseOffsets->getCurrentOffsets()); |
| 213 | } |
| 214 | |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 215 | using CreateBufferQueueFunction = surfaceflinger::test::Factory::CreateBufferQueueFunction; |
Lloyd Pique | 5b36f3f | 2018-01-17 11:57:07 -0800 | [diff] [blame] | 216 | void setCreateBufferQueueFunction(CreateBufferQueueFunction f) { |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 217 | mFactory.mCreateBufferQueue = f; |
Lloyd Pique | 5b36f3f | 2018-01-17 11:57:07 -0800 | [diff] [blame] | 218 | } |
| 219 | |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 220 | using CreateNativeWindowSurfaceFunction = |
| 221 | surfaceflinger::test::Factory::CreateNativeWindowSurfaceFunction; |
Lloyd Pique | 0b1fe70 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 222 | void setCreateNativeWindowSurface(CreateNativeWindowSurfaceFunction f) { |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 223 | mFactory.mCreateNativeWindowSurface = f; |
Lloyd Pique | 0b1fe70 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 224 | } |
| 225 | |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 226 | void setInternalDisplayPrimaries(const ui::DisplayPrimaries& primaries) { |
| 227 | memcpy(&mFlinger->mInternalDisplayPrimaries, &primaries, sizeof(ui::DisplayPrimaries)); |
| 228 | } |
| 229 | |
Lloyd Pique | 0b1fe70 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 230 | using HotplugEvent = SurfaceFlinger::HotplugEvent; |
| 231 | |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 232 | auto& mutableLayerCurrentState(sp<Layer> layer) { return layer->mCurrentState; } |
| 233 | auto& mutableLayerDrawingState(sp<Layer> layer) { return layer->mDrawingState; } |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 234 | |
| 235 | void setLayerSidebandStream(sp<Layer> layer, sp<NativeHandle> sidebandStream) { |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 236 | layer->mDrawingState.sidebandStream = sidebandStream; |
Lloyd Pique | 0b785d8 | 2018-12-04 17:25:27 -0800 | [diff] [blame] | 237 | layer->mSidebandStream = sidebandStream; |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 238 | layer->getCompositionLayer()->editFEState().sidebandStream = sidebandStream; |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 239 | } |
| 240 | |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 241 | void setLayerCompositionType(sp<Layer> layer, HWC2::Composition type) { |
| 242 | auto outputLayer = layer->findOutputLayerForDisplay(mFlinger->getDefaultDisplayDevice()); |
| 243 | LOG_ALWAYS_FATAL_IF(!outputLayer); |
| 244 | auto& state = outputLayer->editState(); |
| 245 | LOG_ALWAYS_FATAL_IF(!outputLayer->getState().hwc); |
| 246 | (*state.hwc).hwcCompositionType = static_cast<Hwc2::IComposerClient::Composition>(type); |
| 247 | }; |
| 248 | |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 249 | void setLayerPotentialCursor(sp<Layer> layer, bool potentialCursor) { |
| 250 | layer->mPotentialCursor = potentialCursor; |
| 251 | } |
| 252 | |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 253 | /* ------------------------------------------------------------------------ |
| 254 | * Forwarding for functions being tested |
| 255 | */ |
Lloyd Pique | 0b1fe70 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 256 | |
Lloyd Pique | a482f99 | 2018-01-22 19:00:34 -0800 | [diff] [blame] | 257 | auto createDisplay(const String8& displayName, bool secure) { |
| 258 | return mFlinger->createDisplay(displayName, secure); |
| 259 | } |
| 260 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 261 | auto destroyDisplay(const sp<IBinder>& displayToken) { |
| 262 | return mFlinger->destroyDisplay(displayToken); |
| 263 | } |
Lloyd Pique | a482f99 | 2018-01-22 19:00:34 -0800 | [diff] [blame] | 264 | |
Lloyd Pique | d6fbb8a | 2018-01-22 19:08:36 -0800 | [diff] [blame] | 265 | auto resetDisplayState() { return mFlinger->resetDisplayState(); } |
| 266 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 267 | auto setupNewDisplayDeviceInternal(const wp<IBinder>& displayToken, |
| 268 | const std::optional<DisplayId>& displayId, |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 269 | const DisplayDeviceState& state, |
Lloyd Pique | 542307f | 2018-10-19 13:24:08 -0700 | [diff] [blame] | 270 | const sp<compositionengine::DisplaySurface>& dispSurface, |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 271 | const sp<IGraphicBufferProducer>& producer) { |
Dominik Laskowski | 7e04546 | 2018-05-30 13:02:02 -0700 | [diff] [blame] | 272 | return mFlinger->setupNewDisplayDeviceInternal(displayToken, displayId, state, dispSurface, |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 273 | producer); |
| 274 | } |
| 275 | |
Lloyd Pique | 0b1fe70 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 276 | auto handleTransactionLocked(uint32_t transactionFlags) { |
Vishnu Nair | fa5f8df | 2019-02-13 17:02:51 -0800 | [diff] [blame] | 277 | Mutex::Autolock _l(mFlinger->mStateLock); |
Lloyd Pique | 0b1fe70 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 278 | return mFlinger->handleTransactionLocked(transactionFlags); |
| 279 | } |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 280 | |
Lloyd Pique | 6cf1103 | 2018-01-22 18:57:44 -0800 | [diff] [blame] | 281 | auto onHotplugReceived(int32_t sequenceId, hwc2_display_t display, |
| 282 | HWC2::Connection connection) { |
| 283 | return mFlinger->onHotplugReceived(sequenceId, display, connection); |
| 284 | } |
| 285 | |
Vishnu Nair | ce5d0cc | 2019-02-28 14:38:41 -0800 | [diff] [blame] | 286 | auto setDisplayStateLocked(const DisplayState& s) { |
| 287 | Mutex::Autolock _l(mFlinger->mStateLock); |
| 288 | return mFlinger->setDisplayStateLocked(s); |
| 289 | } |
Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 290 | |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 291 | // Allow reading display state without locking, as if called on the SF main thread. |
| 292 | auto onInitializeDisplays() NO_THREAD_SAFETY_ANALYSIS { |
| 293 | return mFlinger->onInitializeDisplays(); |
| 294 | } |
Lloyd Pique | 86016da | 2018-03-01 16:09:38 -0800 | [diff] [blame] | 295 | |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 296 | // Allow reading display state without locking, as if called on the SF main thread. |
| 297 | auto setPowerModeInternal(const sp<DisplayDevice>& display, |
| 298 | int mode) NO_THREAD_SAFETY_ANALYSIS { |
Dominik Laskowski | e977409 | 2018-12-11 10:04:24 -0800 | [diff] [blame] | 299 | return mFlinger->setPowerModeInternal(display, mode); |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 300 | } |
| 301 | |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 302 | auto onMessageReceived(int32_t what) { return mFlinger->onMessageReceived(what); } |
| 303 | |
Robert Carr | 108b2c7 | 2019-04-02 16:32:58 -0700 | [diff] [blame] | 304 | auto captureScreenImplLocked( |
| 305 | const RenderArea& renderArea, SurfaceFlinger::TraverseLayersFunction traverseLayers, |
| 306 | ANativeWindowBuffer* buffer, bool useIdentityTransform, bool forSystem, int* outSyncFd) { |
| 307 | bool ignored; |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 308 | return mFlinger->captureScreenImplLocked(renderArea, traverseLayers, buffer, |
Robert Carr | 108b2c7 | 2019-04-02 16:32:58 -0700 | [diff] [blame] | 309 | useIdentityTransform, forSystem, outSyncFd, |
| 310 | ignored); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 311 | } |
| 312 | |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 313 | auto traverseLayersInDisplay(const sp<const DisplayDevice>& display, |
| 314 | const LayerVector::Visitor& visitor) { |
| 315 | return mFlinger->SurfaceFlinger::traverseLayersInDisplay(display, visitor); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 316 | } |
| 317 | |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 318 | auto getDisplayNativePrimaries(const sp<IBinder>& displayToken, |
| 319 | ui::DisplayPrimaries &primaries) { |
| 320 | return mFlinger->SurfaceFlinger::getDisplayNativePrimaries(displayToken, primaries); |
| 321 | } |
| 322 | |
Lloyd Pique | 86016da | 2018-03-01 16:09:38 -0800 | [diff] [blame] | 323 | /* ------------------------------------------------------------------------ |
| 324 | * Read-only access to private data to assert post-conditions. |
| 325 | */ |
| 326 | |
| 327 | const auto& getAnimFrameTracker() const { return mFlinger->mAnimFrameTracker; } |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 328 | const auto& getHasPoweredOff() const { return mFlinger->mHasPoweredOff; } |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 329 | const auto& getVisibleRegionsDirty() const { return mFlinger->mVisibleRegionsDirty; } |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 330 | auto& getHwComposer() const { |
| 331 | return static_cast<impl::HWComposer&>(mFlinger->getHwComposer()); |
| 332 | } |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 333 | |
Lloyd Pique | 86016da | 2018-03-01 16:09:38 -0800 | [diff] [blame] | 334 | const auto& getCompositorTiming() const { return mFlinger->getBE().mCompositorTiming; } |
| 335 | |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 336 | /* ------------------------------------------------------------------------ |
| 337 | * Read-write access to private data to set up preconditions and assert |
| 338 | * post-conditions. |
| 339 | */ |
Lloyd Pique | 0b1fe70 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 340 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 341 | auto& mutableHasWideColorDisplay() { return SurfaceFlinger::hasWideColorDisplay; } |
Chia-I Wu | 304d9cd | 2018-08-27 14:38:14 -0700 | [diff] [blame] | 342 | auto& mutablePrimaryDisplayOrientation() { return SurfaceFlinger::primaryDisplayOrientation; } |
Peiyong Lin | 13effd1 | 2018-07-24 17:01:47 -0700 | [diff] [blame] | 343 | auto& mutableUseColorManagement() { return SurfaceFlinger::useColorManagement; } |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 344 | |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 345 | auto& mutableCurrentState() { return mFlinger->mCurrentState; } |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 346 | auto& mutableDisplayColorSetting() { return mFlinger->mDisplayColorSetting; } |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 347 | auto& mutableDisplays() { return mFlinger->mDisplays; } |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 348 | auto& mutableDrawingState() { return mFlinger->mDrawingState; } |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 349 | auto& mutableEventQueue() { return mFlinger->mEventQueue; } |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 350 | auto& mutableGeometryInvalid() { return mFlinger->mGeometryInvalid; } |
Lloyd Pique | 0b1fe70 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 351 | auto& mutableInterceptor() { return mFlinger->mInterceptor; } |
Lloyd Pique | 6cf1103 | 2018-01-22 18:57:44 -0800 | [diff] [blame] | 352 | auto& mutableMainThreadId() { return mFlinger->mMainThreadId; } |
Lloyd Pique | 0b1fe70 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 353 | auto& mutablePendingHotplugEvents() { return mFlinger->mPendingHotplugEvents; } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 354 | auto& mutablePhysicalDisplayTokens() { return mFlinger->mPhysicalDisplayTokens; } |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 355 | auto& mutableTexturePool() { return mFlinger->mTexturePool; } |
Lloyd Pique | 0b1fe70 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 356 | auto& mutableTransactionFlags() { return mFlinger->mTransactionFlags; } |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 357 | auto& mutableUseHwcVirtualDisplays() { return mFlinger->mUseHwcVirtualDisplays; } |
Peiyong Lin | 74ca2f4 | 2019-01-14 19:36:57 -0800 | [diff] [blame] | 358 | auto& mutablePowerAdvisor() { return mFlinger->mPowerAdvisor; } |
Lloyd Pique | 4fe2940 | 2019-08-12 16:51:24 -0700 | [diff] [blame] | 359 | auto& mutableDebugDisableHWC() { return mFlinger->mDebugDisableHWC; } |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 360 | |
Lloyd Pique | 6cf1103 | 2018-01-22 18:57:44 -0800 | [diff] [blame] | 361 | auto& mutableComposerSequenceId() { return mFlinger->getBE().mComposerSequenceId; } |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 362 | auto& mutableHwcDisplayData() { return getHwComposer().mDisplayData; } |
| 363 | auto& mutableHwcPhysicalDisplayIdMap() { return getHwComposer().mPhysicalDisplayIdMap; } |
| 364 | auto& mutableInternalHwcDisplayId() { return getHwComposer().mInternalHwcDisplayId; } |
| 365 | auto& mutableExternalHwcDisplayId() { return getHwComposer().mExternalHwcDisplayId; } |
Lloyd Pique | a618d85 | 2018-01-17 11:52:30 -0800 | [diff] [blame] | 366 | |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 367 | ~TestableSurfaceFlinger() { |
| 368 | // All these pointer and container clears help ensure that GMock does |
| 369 | // not report a leaked object, since the SurfaceFlinger instance may |
| 370 | // still be referenced by something despite our best efforts to destroy |
| 371 | // it after each test is done. |
| 372 | mutableDisplays().clear(); |
Ady Abraham | 2939f09 | 2019-03-04 17:44:06 -0800 | [diff] [blame] | 373 | mutableCurrentState().displays.clear(); |
| 374 | mutableDrawingState().displays.clear(); |
Lloyd Pique | 0b1fe70 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 375 | mutableEventQueue().reset(); |
Lloyd Pique | 0b1fe70 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 376 | mutableInterceptor().reset(); |
Lloyd Pique | 2eb71eb | 2019-08-13 13:23:03 -0700 | [diff] [blame] | 377 | mFlinger->mScheduler.reset(); |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 378 | mFlinger->mCompositionEngine->setHwComposer(std::unique_ptr<HWComposer>()); |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 379 | mFlinger->mCompositionEngine->setRenderEngine( |
| 380 | std::unique_ptr<renderengine::RenderEngine>()); |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 381 | } |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 382 | |
Lloyd Pique | a618d85 | 2018-01-17 11:52:30 -0800 | [diff] [blame] | 383 | /* ------------------------------------------------------------------------ |
| 384 | * Wrapper classes for Read-write access to private data to set up |
| 385 | * preconditions and assert post-conditions. |
| 386 | */ |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 387 | struct HWC2Display : public HWC2::impl::Display { |
Peiyong Lin | 74ca2f4 | 2019-01-14 19:36:57 -0800 | [diff] [blame] | 388 | HWC2Display(Hwc2::Composer& composer, |
Lloyd Pique | a618d85 | 2018-01-17 11:52:30 -0800 | [diff] [blame] | 389 | const std::unordered_set<HWC2::Capability>& capabilities, hwc2_display_t id, |
| 390 | HWC2::DisplayType type) |
Peiyong Lin | 74ca2f4 | 2019-01-14 19:36:57 -0800 | [diff] [blame] | 391 | : HWC2::impl::Display(composer, capabilities, id, type) {} |
Lloyd Pique | a618d85 | 2018-01-17 11:52:30 -0800 | [diff] [blame] | 392 | ~HWC2Display() { |
| 393 | // Prevents a call to disable vsyncs. |
| 394 | mType = HWC2::DisplayType::Invalid; |
| 395 | } |
| 396 | |
| 397 | auto& mutableIsConnected() { return this->mIsConnected; } |
| 398 | auto& mutableConfigs() { return this->mConfigs; } |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 399 | auto& mutableLayers() { return this->mLayers; } |
Lloyd Pique | a618d85 | 2018-01-17 11:52:30 -0800 | [diff] [blame] | 400 | }; |
| 401 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 402 | class FakeHwcDisplayInjector { |
| 403 | public: |
| 404 | static constexpr hwc2_display_t DEFAULT_HWC_DISPLAY_ID = 1000; |
| 405 | static constexpr int32_t DEFAULT_WIDTH = 1920; |
| 406 | static constexpr int32_t DEFAULT_HEIGHT = 1280; |
| 407 | static constexpr int32_t DEFAULT_REFRESH_RATE = 16'666'666; |
| 408 | static constexpr int32_t DEFAULT_DPI = 320; |
| 409 | static constexpr int32_t DEFAULT_ACTIVE_CONFIG = 0; |
Peiyong Lin | 1336e6e | 2019-05-28 09:23:50 -0700 | [diff] [blame] | 410 | static constexpr int32_t DEFAULT_POWER_MODE = 2; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 411 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 412 | FakeHwcDisplayInjector(DisplayId displayId, HWC2::DisplayType hwcDisplayType, |
| 413 | bool isPrimary) |
| 414 | : mDisplayId(displayId), mHwcDisplayType(hwcDisplayType), mIsPrimary(isPrimary) {} |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 415 | |
| 416 | auto& setHwcDisplayId(hwc2_display_t displayId) { |
| 417 | mHwcDisplayId = displayId; |
| 418 | return *this; |
| 419 | } |
| 420 | |
| 421 | auto& setWidth(int32_t width) { |
| 422 | mWidth = width; |
| 423 | return *this; |
| 424 | } |
| 425 | |
| 426 | auto& setHeight(int32_t height) { |
| 427 | mHeight = height; |
| 428 | return *this; |
| 429 | } |
| 430 | |
| 431 | auto& setRefreshRate(int32_t refreshRate) { |
| 432 | mRefreshRate = refreshRate; |
| 433 | return *this; |
| 434 | } |
| 435 | |
| 436 | auto& setDpiX(int32_t dpi) { |
| 437 | mDpiX = dpi; |
| 438 | return *this; |
| 439 | } |
| 440 | |
| 441 | auto& setDpiY(int32_t dpi) { |
| 442 | mDpiY = dpi; |
| 443 | return *this; |
| 444 | } |
| 445 | |
| 446 | auto& setActiveConfig(int32_t config) { |
| 447 | mActiveConfig = config; |
| 448 | return *this; |
| 449 | } |
| 450 | |
Lloyd Pique | e22f033 | 2018-07-16 16:35:56 -0700 | [diff] [blame] | 451 | auto& setCapabilities(const std::unordered_set<HWC2::Capability>* capabilities) { |
| 452 | mCapabilities = capabilities; |
| 453 | return *this; |
| 454 | } |
| 455 | |
Peiyong Lin | 1336e6e | 2019-05-28 09:23:50 -0700 | [diff] [blame] | 456 | auto& setPowerMode(int mode) { |
| 457 | mPowerMode = mode; |
| 458 | return *this; |
| 459 | } |
| 460 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 461 | void inject(TestableSurfaceFlinger* flinger, Hwc2::Composer* composer) { |
Lloyd Pique | e22f033 | 2018-07-16 16:35:56 -0700 | [diff] [blame] | 462 | static const std::unordered_set<HWC2::Capability> defaultCapabilities; |
| 463 | if (mCapabilities == nullptr) mCapabilities = &defaultCapabilities; |
| 464 | |
| 465 | // Caution - Make sure that any values passed by reference here do |
| 466 | // not refer to an instance owned by FakeHwcDisplayInjector. This |
| 467 | // class has temporary lifetime, while the constructed HWC2::Display |
| 468 | // is much longer lived. |
Peiyong Lin | 74ca2f4 | 2019-01-14 19:36:57 -0800 | [diff] [blame] | 469 | auto display = std::make_unique<HWC2Display>(*composer, *mCapabilities, mHwcDisplayId, |
| 470 | mHwcDisplayType); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 471 | |
| 472 | auto config = HWC2::Display::Config::Builder(*display, mActiveConfig); |
| 473 | config.setWidth(mWidth); |
| 474 | config.setHeight(mHeight); |
| 475 | config.setVsyncPeriod(mRefreshRate); |
| 476 | config.setDpiX(mDpiX); |
| 477 | config.setDpiY(mDpiY); |
| 478 | display->mutableConfigs().emplace(mActiveConfig, config.build()); |
| 479 | display->mutableIsConnected() = true; |
Peiyong Lin | 1336e6e | 2019-05-28 09:23:50 -0700 | [diff] [blame] | 480 | display->setPowerMode(static_cast<HWC2::PowerMode>(mPowerMode)); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 481 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 482 | flinger->mutableHwcDisplayData()[mDisplayId].hwcDisplay = display.get(); |
| 483 | |
| 484 | if (mHwcDisplayType == HWC2::DisplayType::Physical) { |
| 485 | flinger->mutableHwcPhysicalDisplayIdMap().emplace(mHwcDisplayId, mDisplayId); |
| 486 | (mIsPrimary ? flinger->mutableInternalHwcDisplayId() |
| 487 | : flinger->mutableExternalHwcDisplayId()) = mHwcDisplayId; |
| 488 | } |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 489 | |
| 490 | flinger->mFakeHwcDisplays.push_back(std::move(display)); |
| 491 | } |
| 492 | |
| 493 | private: |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 494 | const DisplayId mDisplayId; |
| 495 | const HWC2::DisplayType mHwcDisplayType; |
| 496 | const bool mIsPrimary; |
| 497 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 498 | hwc2_display_t mHwcDisplayId = DEFAULT_HWC_DISPLAY_ID; |
| 499 | int32_t mWidth = DEFAULT_WIDTH; |
| 500 | int32_t mHeight = DEFAULT_HEIGHT; |
| 501 | int32_t mRefreshRate = DEFAULT_REFRESH_RATE; |
| 502 | int32_t mDpiX = DEFAULT_DPI; |
| 503 | int32_t mDpiY = DEFAULT_DPI; |
| 504 | int32_t mActiveConfig = DEFAULT_ACTIVE_CONFIG; |
Peiyong Lin | 1336e6e | 2019-05-28 09:23:50 -0700 | [diff] [blame] | 505 | int32_t mPowerMode = DEFAULT_POWER_MODE; |
Lloyd Pique | e22f033 | 2018-07-16 16:35:56 -0700 | [diff] [blame] | 506 | const std::unordered_set<HWC2::Capability>* mCapabilities = nullptr; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 507 | }; |
| 508 | |
| 509 | class FakeDisplayDeviceInjector { |
| 510 | public: |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 511 | FakeDisplayDeviceInjector(TestableSurfaceFlinger& flinger, |
| 512 | const std::optional<DisplayId>& displayId, bool isVirtual, |
| 513 | bool isPrimary) |
| 514 | : mFlinger(flinger), mCreationArgs(flinger.mFlinger.get(), mDisplayToken, displayId) { |
| 515 | mCreationArgs.isVirtual = isVirtual; |
| 516 | mCreationArgs.isPrimary = isPrimary; |
| 517 | } |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 518 | |
| 519 | sp<IBinder> token() const { return mDisplayToken; } |
| 520 | |
| 521 | DisplayDeviceState& mutableDrawingDisplayState() { |
| 522 | return mFlinger.mutableDrawingState().displays.editValueFor(mDisplayToken); |
| 523 | } |
| 524 | |
| 525 | DisplayDeviceState& mutableCurrentDisplayState() { |
| 526 | return mFlinger.mutableCurrentState().displays.editValueFor(mDisplayToken); |
| 527 | } |
| 528 | |
Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 529 | const auto& getDrawingDisplayState() { |
| 530 | return mFlinger.mutableDrawingState().displays.valueFor(mDisplayToken); |
| 531 | } |
| 532 | |
| 533 | const auto& getCurrentDisplayState() { |
| 534 | return mFlinger.mutableCurrentState().displays.valueFor(mDisplayToken); |
| 535 | } |
| 536 | |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 537 | auto& mutableDisplayDevice() { return mFlinger.mutableDisplays()[mDisplayToken]; } |
Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 538 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 539 | auto& setNativeWindow(const sp<ANativeWindow>& nativeWindow) { |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 540 | mCreationArgs.nativeWindow = nativeWindow; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 541 | return *this; |
| 542 | } |
| 543 | |
Lloyd Pique | 542307f | 2018-10-19 13:24:08 -0700 | [diff] [blame] | 544 | auto& setDisplaySurface(const sp<compositionengine::DisplaySurface>& displaySurface) { |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 545 | mCreationArgs.displaySurface = displaySurface; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 546 | return *this; |
| 547 | } |
| 548 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 549 | auto& setSecure(bool secure) { |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 550 | mCreationArgs.isSecure = secure; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 551 | return *this; |
| 552 | } |
| 553 | |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 554 | auto& setPowerMode(int mode) { |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 555 | mCreationArgs.initialPowerMode = mode; |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 556 | return *this; |
| 557 | } |
| 558 | |
Valerie Hau | 9758ae0 | 2018-10-09 16:05:09 -0700 | [diff] [blame] | 559 | auto& setHwcColorModes( |
| 560 | const std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>> |
| 561 | hwcColorModes) { |
| 562 | mCreationArgs.hwcColorModes = hwcColorModes; |
| 563 | return *this; |
| 564 | } |
| 565 | |
| 566 | auto& setHasWideColorGamut(bool hasWideColorGamut) { |
| 567 | mCreationArgs.hasWideColorGamut = hasWideColorGamut; |
| 568 | return *this; |
| 569 | } |
| 570 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 571 | sp<DisplayDevice> inject() { |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 572 | DisplayDeviceState state; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 573 | state.displayId = mCreationArgs.isVirtual ? std::nullopt : mCreationArgs.displayId; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 574 | state.isSecure = mCreationArgs.isSecure; |
| 575 | |
| 576 | sp<DisplayDevice> device = new DisplayDevice(std::move(mCreationArgs)); |
| 577 | mFlinger.mutableDisplays().emplace(mDisplayToken, device); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 578 | mFlinger.mutableCurrentState().displays.add(mDisplayToken, state); |
| 579 | mFlinger.mutableDrawingState().displays.add(mDisplayToken, state); |
| 580 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 581 | if (!mCreationArgs.isVirtual) { |
| 582 | LOG_ALWAYS_FATAL_IF(!state.displayId); |
| 583 | mFlinger.mutablePhysicalDisplayTokens()[*state.displayId] = mDisplayToken; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | return device; |
| 587 | } |
| 588 | |
| 589 | private: |
| 590 | TestableSurfaceFlinger& mFlinger; |
| 591 | sp<BBinder> mDisplayToken = new BBinder(); |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 592 | DisplayDeviceCreationArgs mCreationArgs; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 593 | }; |
| 594 | |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 595 | surfaceflinger::test::Factory mFactory; |
| 596 | sp<SurfaceFlinger> mFlinger = new SurfaceFlinger(mFactory, SurfaceFlinger::SkipInitialization); |
Dominik Laskowski | 7c9dbf9 | 2019-08-01 17:57:31 -0700 | [diff] [blame] | 597 | TestableScheduler* mScheduler = nullptr; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 598 | |
| 599 | // We need to keep a reference to these so they are properly destroyed. |
| 600 | std::vector<std::unique_ptr<HWC2Display>> mFakeHwcDisplays; |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 601 | }; |
| 602 | |
| 603 | } // namespace android |