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