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