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