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