| 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 | 9370a48 | 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> | 
| chaviw | 0ef7caa | 2021-01-05 11:04:50 -0800 | [diff] [blame] | 26 | #include <gui/ScreenCaptureResults.h> | 
| Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 27 |  | 
| Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 28 | #include "BufferQueueLayer.h" | 
|  | 29 | #include "BufferStateLayer.h" | 
| Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 30 | #include "ContainerLayer.h" | 
| Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 31 | #include "DisplayDevice.h" | 
| Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame] | 32 | #include "EffectLayer.h" | 
| Ady Abraham | c581d3c | 2020-08-06 17:34:27 -0700 | [diff] [blame] | 33 | #include "FakeVsyncConfiguration.h" | 
| Adithya Srinivasan | 2db3c1b | 2020-11-18 12:43:17 -0800 | [diff] [blame] | 34 | #include "FrameTracer/FrameTracer.h" | 
| Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 35 | #include "Layer.h" | 
| Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 36 | #include "NativeWindowSurface.h" | 
| Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 37 | #include "Scheduler/MessageQueue.h" | 
| Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 38 | #include "Scheduler/RefreshRateConfigs.h" | 
| Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 39 | #include "StartPropertySetThread.h" | 
| Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 40 | #include "SurfaceFlinger.h" | 
| Lloyd Pique | 24f3bfe | 2019-10-02 19:29:10 -0700 | [diff] [blame] | 41 | #include "SurfaceFlingerDefaultFactory.h" | 
| Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 42 | #include "SurfaceInterceptor.h" | 
| Dominik Laskowski | 7c9dbf9 | 2019-08-01 17:57:31 -0700 | [diff] [blame] | 43 | #include "TestableScheduler.h" | 
| Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 44 | #include "mock/DisplayHardware/MockComposer.h" | 
| Adithya Srinivasan | 0118967 | 2020-10-20 14:23:05 -0700 | [diff] [blame] | 45 | #include "mock/MockFrameTimeline.h" | 
| Adithya Srinivasan | 2db3c1b | 2020-11-18 12:43:17 -0800 | [diff] [blame] | 46 | #include "mock/MockFrameTracer.h" | 
| Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame] | 47 |  | 
| Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 48 | namespace android { | 
|  | 49 |  | 
| Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 50 | class EventThread; | 
|  | 51 |  | 
| Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 52 | namespace renderengine { | 
| Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 53 |  | 
| Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 54 | class RenderEngine; | 
| Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 55 |  | 
|  | 56 | } // namespace renderengine | 
| Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 57 |  | 
|  | 58 | namespace Hwc2 { | 
| Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 59 |  | 
| Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 60 | class Composer; | 
| Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 61 |  | 
|  | 62 | } // namespace Hwc2 | 
|  | 63 |  | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 64 | namespace hal = android::hardware::graphics::composer::hal; | 
|  | 65 |  | 
| Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 66 | namespace surfaceflinger::test { | 
|  | 67 |  | 
|  | 68 | class Factory final : public surfaceflinger::Factory { | 
|  | 69 | public: | 
|  | 70 | ~Factory() = default; | 
|  | 71 |  | 
| Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 72 | std::unique_ptr<HWComposer> createHWComposer(const std::string&) override { | 
| Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 73 | return nullptr; | 
|  | 74 | } | 
|  | 75 |  | 
|  | 76 | std::unique_ptr<MessageQueue> createMessageQueue() override { | 
| Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 77 | return std::make_unique<android::impl::MessageQueue>(); | 
|  | 78 | } | 
|  | 79 |  | 
| Ady Abraham | 8287e85 | 2020-08-12 14:44:58 -0700 | [diff] [blame] | 80 | std::unique_ptr<scheduler::VsyncConfiguration> createVsyncConfiguration( | 
| Marin Shalamanov | 526c338 | 2020-12-10 15:22:29 +0100 | [diff] [blame] | 81 | Fps /*currentRefreshRate*/) override { | 
| Ana Krulec | 757f63a | 2019-01-25 10:46:18 -0800 | [diff] [blame] | 82 | return std::make_unique<scheduler::FakePhaseOffsets>(); | 
|  | 83 | } | 
|  | 84 |  | 
| Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 85 | std::unique_ptr<Scheduler> createScheduler( | 
|  | 86 | const std::shared_ptr<scheduler::RefreshRateConfigs>&, ISchedulerCallback&) override { | 
| Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 87 | return nullptr; | 
|  | 88 | } | 
|  | 89 |  | 
| Pablo Gamito | c351d6f | 2020-09-17 15:34:26 +0000 | [diff] [blame] | 90 | sp<SurfaceInterceptor> createSurfaceInterceptor() override { | 
|  | 91 | return new android::impl::SurfaceInterceptor(); | 
| Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 92 | } | 
|  | 93 |  | 
|  | 94 | sp<StartPropertySetThread> createStartPropertySetThread(bool timestampPropertyValue) override { | 
| Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 95 | return new StartPropertySetThread(timestampPropertyValue); | 
|  | 96 | } | 
|  | 97 |  | 
| Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 98 | sp<DisplayDevice> createDisplayDevice(DisplayDeviceCreationArgs& creationArgs) override { | 
|  | 99 | return new DisplayDevice(creationArgs); | 
| Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 100 | } | 
|  | 101 |  | 
|  | 102 | sp<GraphicBuffer> createGraphicBuffer(uint32_t width, uint32_t height, PixelFormat format, | 
|  | 103 | uint32_t layerCount, uint64_t usage, | 
|  | 104 | std::string requestorName) override { | 
| Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 105 | return new GraphicBuffer(width, height, format, layerCount, usage, requestorName); | 
|  | 106 | } | 
|  | 107 |  | 
|  | 108 | void createBufferQueue(sp<IGraphicBufferProducer>* outProducer, | 
|  | 109 | sp<IGraphicBufferConsumer>* outConsumer, | 
|  | 110 | bool consumerIsSurfaceFlinger) override { | 
| Lloyd Pique | e300b31 | 2019-10-03 13:03:45 -0700 | [diff] [blame] | 111 | if (!mCreateBufferQueue) { | 
|  | 112 | BufferQueue::createBufferQueue(outProducer, outConsumer, consumerIsSurfaceFlinger); | 
|  | 113 | return; | 
|  | 114 | } | 
| Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 115 | mCreateBufferQueue(outProducer, outConsumer, consumerIsSurfaceFlinger); | 
|  | 116 | } | 
|  | 117 |  | 
| Lloyd Pique | e300b31 | 2019-10-03 13:03:45 -0700 | [diff] [blame] | 118 | sp<IGraphicBufferProducer> createMonitoredProducer(const sp<IGraphicBufferProducer>& producer, | 
|  | 119 | const sp<SurfaceFlinger>& flinger, | 
|  | 120 | const wp<Layer>& layer) override { | 
|  | 121 | return new MonitoredProducer(producer, flinger, layer); | 
|  | 122 | } | 
|  | 123 |  | 
|  | 124 | sp<BufferLayerConsumer> createBufferLayerConsumer(const sp<IGraphicBufferConsumer>& consumer, | 
|  | 125 | renderengine::RenderEngine& renderEngine, | 
|  | 126 | uint32_t textureName, Layer* layer) override { | 
|  | 127 | return new BufferLayerConsumer(consumer, renderEngine, textureName, layer); | 
|  | 128 | } | 
|  | 129 |  | 
| Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 130 | std::unique_ptr<surfaceflinger::NativeWindowSurface> createNativeWindowSurface( | 
|  | 131 | const sp<IGraphicBufferProducer>& producer) override { | 
|  | 132 | if (!mCreateNativeWindowSurface) return nullptr; | 
|  | 133 | return mCreateNativeWindowSurface(producer); | 
|  | 134 | } | 
|  | 135 |  | 
| Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 136 | std::unique_ptr<compositionengine::CompositionEngine> createCompositionEngine() override { | 
|  | 137 | return compositionengine::impl::createCompositionEngine(); | 
|  | 138 | } | 
|  | 139 |  | 
| Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 140 | sp<BufferQueueLayer> createBufferQueueLayer(const LayerCreationArgs&) override { | 
| Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 141 | return nullptr; | 
|  | 142 | } | 
|  | 143 |  | 
|  | 144 | sp<BufferStateLayer> createBufferStateLayer(const LayerCreationArgs&) override { | 
| Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 145 | return nullptr; | 
|  | 146 | } | 
|  | 147 |  | 
| Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame] | 148 | sp<EffectLayer> createEffectLayer(const LayerCreationArgs&) override { return nullptr; } | 
| Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 149 |  | 
|  | 150 | sp<ContainerLayer> createContainerLayer(const LayerCreationArgs&) override { | 
| Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 151 | return nullptr; | 
|  | 152 | } | 
|  | 153 |  | 
| Adithya Srinivasan | 2db3c1b | 2020-11-18 12:43:17 -0800 | [diff] [blame] | 154 | std::unique_ptr<FrameTracer> createFrameTracer() override { | 
|  | 155 | return std::make_unique<mock::FrameTracer>(); | 
|  | 156 | } | 
|  | 157 |  | 
| Adithya Srinivasan | 0118967 | 2020-10-20 14:23:05 -0700 | [diff] [blame] | 158 | std::unique_ptr<frametimeline::FrameTimeline> createFrameTimeline( | 
| Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 159 | std::shared_ptr<TimeStats> timeStats, pid_t surfaceFlingerPid = 0) override { | 
|  | 160 | return std::make_unique<mock::FrameTimeline>(timeStats, surfaceFlingerPid); | 
| Adithya Srinivasan | 0118967 | 2020-10-20 14:23:05 -0700 | [diff] [blame] | 161 | } | 
|  | 162 |  | 
| Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 163 | using CreateBufferQueueFunction = | 
|  | 164 | std::function<void(sp<IGraphicBufferProducer>* /* outProducer */, | 
|  | 165 | sp<IGraphicBufferConsumer>* /* outConsumer */, | 
|  | 166 | bool /* consumerIsSurfaceFlinger */)>; | 
|  | 167 | CreateBufferQueueFunction mCreateBufferQueue; | 
|  | 168 |  | 
|  | 169 | using CreateNativeWindowSurfaceFunction = | 
|  | 170 | std::function<std::unique_ptr<surfaceflinger::NativeWindowSurface>( | 
|  | 171 | const sp<IGraphicBufferProducer>&)>; | 
|  | 172 | CreateNativeWindowSurfaceFunction mCreateNativeWindowSurface; | 
| Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 173 |  | 
|  | 174 | using CreateCompositionEngineFunction = | 
|  | 175 | std::function<std::unique_ptr<compositionengine::CompositionEngine>()>; | 
|  | 176 | CreateCompositionEngineFunction mCreateCompositionEngine; | 
| Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 177 | }; | 
|  | 178 |  | 
|  | 179 | } // namespace surfaceflinger::test | 
| Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 180 |  | 
| Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 181 | class TestableSurfaceFlinger final : private ISchedulerCallback { | 
| Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 182 | public: | 
| Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 183 | using HotplugEvent = SurfaceFlinger::HotplugEvent; | 
|  | 184 |  | 
| Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 185 | SurfaceFlinger* flinger() { return mFlinger.get(); } | 
| Dominik Laskowski | 7c9dbf9 | 2019-08-01 17:57:31 -0700 | [diff] [blame] | 186 | TestableScheduler* scheduler() { return mScheduler; } | 
|  | 187 |  | 
| Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 188 | // Extend this as needed for accessing SurfaceFlinger private (and public) | 
|  | 189 | // functions. | 
|  | 190 |  | 
| Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 191 | void setupRenderEngine(std::unique_ptr<renderengine::RenderEngine> renderEngine) { | 
| Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 192 | mFlinger->mCompositionEngine->setRenderEngine(std::move(renderEngine)); | 
| Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 193 | } | 
|  | 194 |  | 
|  | 195 | void setupComposer(std::unique_ptr<Hwc2::Composer> composer) { | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 196 | mFlinger->mCompositionEngine->setHwComposer( | 
|  | 197 | std::make_unique<impl::HWComposer>(std::move(composer))); | 
| Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 198 | } | 
|  | 199 |  | 
| Alec Mouri | e4034bb | 2019-11-19 12:45:54 -0800 | [diff] [blame] | 200 | void setupTimeStats(const std::shared_ptr<TimeStats>& timeStats) { | 
|  | 201 | mFlinger->mCompositionEngine->setTimeStats(timeStats); | 
|  | 202 | } | 
|  | 203 |  | 
| Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 204 | // The ISchedulerCallback argument can be nullptr for a no-op implementation. | 
| Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 205 | void setupScheduler(std::unique_ptr<scheduler::VsyncController> vsyncController, | 
|  | 206 | std::unique_ptr<scheduler::VSyncTracker> vsyncTracker, | 
| Dominik Laskowski | 7c9dbf9 | 2019-08-01 17:57:31 -0700 | [diff] [blame] | 207 | std::unique_ptr<EventThread> appEventThread, | 
| Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 208 | std::unique_ptr<EventThread> sfEventThread, | 
| Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 209 | ISchedulerCallback* callback = nullptr, bool hasMultipleModes = false) { | 
|  | 210 | DisplayModes modes{DisplayMode::Builder(0) | 
|  | 211 | .setId(DisplayModeId(0)) | 
| Ady Abraham | f3e81d2 | 2021-06-23 17:43:41 -0700 | [diff] [blame] | 212 | .setPhysicalDisplayId(PhysicalDisplayId(0)) | 
| Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 213 | .setVsyncPeriod(16'666'667) | 
|  | 214 | .setGroup(0) | 
|  | 215 | .build()}; | 
| Ady Abraham | abc2760 | 2020-04-08 17:20:29 -0700 | [diff] [blame] | 216 |  | 
| Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 217 | if (hasMultipleModes) { | 
|  | 218 | modes.emplace_back(DisplayMode::Builder(1) | 
|  | 219 | .setId(DisplayModeId(1)) | 
| Ady Abraham | f3e81d2 | 2021-06-23 17:43:41 -0700 | [diff] [blame] | 220 | .setPhysicalDisplayId(PhysicalDisplayId(0)) | 
| Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 221 | .setVsyncPeriod(11'111'111) | 
|  | 222 | .setGroup(0) | 
|  | 223 | .build()); | 
| Dominik Laskowski | 983f2b5 | 2020-06-25 16:54:06 -0700 | [diff] [blame] | 224 | } | 
|  | 225 |  | 
| Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 226 | const auto currMode = DisplayModeId(0); | 
| Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 227 | mRefreshRateConfigs = std::make_shared<scheduler::RefreshRateConfigs>(modes, currMode); | 
|  | 228 | const auto currFps = mRefreshRateConfigs->getCurrentRefreshRate().getFps(); | 
|  | 229 | mFlinger->mVsyncConfiguration = mFactory.createVsyncConfiguration(currFps); | 
| Ady Abraham | 23ea9da | 2021-07-14 16:32:56 -0700 | [diff] [blame] | 230 | mFlinger->mVsyncModulator = sp<scheduler::VsyncModulator>::make( | 
|  | 231 | mFlinger->mVsyncConfiguration->getCurrentConfigs()); | 
| Marin Shalamanov | 68a9409 | 2020-11-24 17:48:00 +0100 | [diff] [blame] | 232 | mFlinger->mRefreshRateStats = | 
|  | 233 | std::make_unique<scheduler::RefreshRateStats>(*mFlinger->mTimeStats, currFps, | 
|  | 234 | /*powerMode=*/hal::PowerMode::OFF); | 
| Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 235 |  | 
| Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 236 | mScheduler = new TestableScheduler(std::move(vsyncController), std::move(vsyncTracker), | 
| Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 237 | mRefreshRateConfigs, *(callback ?: this)); | 
| Dominik Laskowski | 7c9dbf9 | 2019-08-01 17:57:31 -0700 | [diff] [blame] | 238 |  | 
| Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 239 | mFlinger->mAppConnectionHandle = mScheduler->createConnection(std::move(appEventThread)); | 
|  | 240 | mFlinger->mSfConnectionHandle = mScheduler->createConnection(std::move(sfEventThread)); | 
| Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 241 | resetScheduler(mScheduler); | 
| Dominik Laskowski | 7c9dbf9 | 2019-08-01 17:57:31 -0700 | [diff] [blame] | 242 | } | 
|  | 243 |  | 
| Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 244 | void resetScheduler(Scheduler* scheduler) { mFlinger->mScheduler.reset(scheduler); } | 
|  | 245 |  | 
| Ady Abraham | 44e9f3b | 2021-02-16 15:22:58 -0800 | [diff] [blame] | 246 | TestableScheduler& mutableScheduler() const { return *mScheduler; } | 
|  | 247 |  | 
| Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 248 | using CreateBufferQueueFunction = surfaceflinger::test::Factory::CreateBufferQueueFunction; | 
| Lloyd Pique | 5b36f3f | 2018-01-17 11:57:07 -0800 | [diff] [blame] | 249 | void setCreateBufferQueueFunction(CreateBufferQueueFunction f) { | 
| Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 250 | mFactory.mCreateBufferQueue = f; | 
| Lloyd Pique | 5b36f3f | 2018-01-17 11:57:07 -0800 | [diff] [blame] | 251 | } | 
|  | 252 |  | 
| Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 253 | using CreateNativeWindowSurfaceFunction = | 
|  | 254 | surfaceflinger::test::Factory::CreateNativeWindowSurfaceFunction; | 
| Lloyd Pique | 0b1fe70 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 255 | void setCreateNativeWindowSurface(CreateNativeWindowSurfaceFunction f) { | 
| Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 256 | mFactory.mCreateNativeWindowSurface = f; | 
| Lloyd Pique | 0b1fe70 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 257 | } | 
|  | 258 |  | 
| Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 259 | void setInternalDisplayPrimaries(const ui::DisplayPrimaries& primaries) { | 
|  | 260 | memcpy(&mFlinger->mInternalDisplayPrimaries, &primaries, sizeof(ui::DisplayPrimaries)); | 
|  | 261 | } | 
|  | 262 |  | 
| Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 263 | static auto& mutableLayerDrawingState(const sp<Layer>& layer) { return layer->mDrawingState; } | 
| Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 264 |  | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 265 | auto& mutableStateLock() { return mFlinger->mStateLock; } | 
|  | 266 |  | 
| Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 267 | static auto findOutputLayerForDisplay(const sp<Layer>& layer, | 
|  | 268 | const sp<const DisplayDevice>& display) { | 
|  | 269 | return layer->findOutputLayerForDisplay(display.get()); | 
|  | 270 | } | 
|  | 271 |  | 
|  | 272 | static void setLayerSidebandStream(const sp<Layer>& layer, | 
|  | 273 | const sp<NativeHandle>& sidebandStream) { | 
| Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 274 | layer->mDrawingState.sidebandStream = sidebandStream; | 
| Lloyd Pique | 0b785d8 | 2018-12-04 17:25:27 -0800 | [diff] [blame] | 275 | layer->mSidebandStream = sidebandStream; | 
| Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 276 | layer->editCompositionState()->sidebandStream = sidebandStream; | 
| Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 277 | } | 
|  | 278 |  | 
| Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 279 | void setLayerCompositionType(const sp<Layer>& layer, hal::Composition type) { | 
|  | 280 | auto outputLayer = findOutputLayerForDisplay(layer, mFlinger->getDefaultDisplayDevice()); | 
| Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 281 | LOG_ALWAYS_FATAL_IF(!outputLayer); | 
|  | 282 | auto& state = outputLayer->editState(); | 
|  | 283 | LOG_ALWAYS_FATAL_IF(!outputLayer->getState().hwc); | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 284 | (*state.hwc).hwcCompositionType = type; | 
| Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 285 | } | 
| Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 286 |  | 
| Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 287 | static void setLayerPotentialCursor(const sp<Layer>& layer, bool potentialCursor) { | 
| Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 288 | layer->mPotentialCursor = potentialCursor; | 
|  | 289 | } | 
|  | 290 |  | 
| Garfield Tan | de619fa | 2020-10-02 17:13:53 -0700 | [diff] [blame] | 291 | static void setLayerDrawingParent(const sp<Layer>& layer, const sp<Layer>& drawingParent) { | 
|  | 292 | layer->mDrawingParent = drawingParent; | 
|  | 293 | } | 
|  | 294 |  | 
| Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 295 | /* ------------------------------------------------------------------------ | 
|  | 296 | * Forwarding for functions being tested | 
|  | 297 | */ | 
| Lloyd Pique | 0b1fe70 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 298 |  | 
| Lloyd Pique | a482f99 | 2018-01-22 19:00:34 -0800 | [diff] [blame] | 299 | auto createDisplay(const String8& displayName, bool secure) { | 
|  | 300 | return mFlinger->createDisplay(displayName, secure); | 
|  | 301 | } | 
|  | 302 |  | 
| Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 303 | auto destroyDisplay(const sp<IBinder>& displayToken) { | 
|  | 304 | return mFlinger->destroyDisplay(displayToken); | 
|  | 305 | } | 
| Lloyd Pique | a482f99 | 2018-01-22 19:00:34 -0800 | [diff] [blame] | 306 |  | 
| Dominik Laskowski | 1394860 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 307 | void enableHalVirtualDisplays(bool enable) { mFlinger->enableHalVirtualDisplays(enable); } | 
|  | 308 |  | 
| Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 309 | auto setupNewDisplayDeviceInternal( | 
|  | 310 | const wp<IBinder>& displayToken, | 
|  | 311 | std::shared_ptr<compositionengine::Display> compositionDisplay, | 
|  | 312 | const DisplayDeviceState& state, | 
|  | 313 | const sp<compositionengine::DisplaySurface>& dispSurface, | 
| Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 314 | const sp<IGraphicBufferProducer>& producer) NO_THREAD_SAFETY_ANALYSIS { | 
| Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 315 | return mFlinger->setupNewDisplayDeviceInternal(displayToken, compositionDisplay, state, | 
|  | 316 | dispSurface, producer); | 
| Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 317 | } | 
|  | 318 |  | 
| Lloyd Pique | 0b1fe70 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 319 | auto handleTransactionLocked(uint32_t transactionFlags) { | 
| Vishnu Nair | fa5f8df | 2019-02-13 17:02:51 -0800 | [diff] [blame] | 320 | Mutex::Autolock _l(mFlinger->mStateLock); | 
| Lloyd Pique | 0b1fe70 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 321 | return mFlinger->handleTransactionLocked(transactionFlags); | 
|  | 322 | } | 
| Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 323 |  | 
| Dominik Laskowski | ebc8d3a | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 324 | void onComposerHalHotplug(hal::HWDisplayId hwcDisplayId, hal::Connection connection) { | 
|  | 325 | mFlinger->onComposerHalHotplug(hwcDisplayId, connection); | 
| Lloyd Pique | 6cf1103 | 2018-01-22 18:57:44 -0800 | [diff] [blame] | 326 | } | 
|  | 327 |  | 
| Vishnu Nair | ce5d0cc | 2019-02-28 14:38:41 -0800 | [diff] [blame] | 328 | auto setDisplayStateLocked(const DisplayState& s) { | 
|  | 329 | Mutex::Autolock _l(mFlinger->mStateLock); | 
|  | 330 | return mFlinger->setDisplayStateLocked(s); | 
|  | 331 | } | 
| Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 332 |  | 
| Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 333 | // Allow reading display state without locking, as if called on the SF main thread. | 
|  | 334 | auto onInitializeDisplays() NO_THREAD_SAFETY_ANALYSIS { | 
|  | 335 | return mFlinger->onInitializeDisplays(); | 
|  | 336 | } | 
| Lloyd Pique | 86016da | 2018-03-01 16:09:38 -0800 | [diff] [blame] | 337 |  | 
| Lais Andrade | 3a6e47d | 2020-04-02 11:20:16 +0100 | [diff] [blame] | 338 | auto notifyPowerBoost(int32_t boostId) { return mFlinger->notifyPowerBoost(boostId); } | 
|  | 339 |  | 
| Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 340 | // Allow reading display state without locking, as if called on the SF main thread. | 
|  | 341 | auto setPowerModeInternal(const sp<DisplayDevice>& display, | 
| Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 342 | hal::PowerMode mode) NO_THREAD_SAFETY_ANALYSIS { | 
| Dominik Laskowski | e977409 | 2018-12-11 10:04:24 -0800 | [diff] [blame] | 343 | return mFlinger->setPowerModeInternal(display, mode); | 
| Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 344 | } | 
|  | 345 |  | 
| Adithya Srinivasan | 5f683cf | 2020-09-15 14:21:04 -0700 | [diff] [blame] | 346 | auto onMessageReceived(int32_t what) { | 
|  | 347 | return mFlinger->onMessageReceived(what, /*vsyncId=*/0, systemTime()); | 
|  | 348 | } | 
| Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 349 |  | 
| chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 350 | auto renderScreenImplLocked(const RenderArea& renderArea, | 
|  | 351 | SurfaceFlinger::TraverseLayersFunction traverseLayers, | 
| Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 352 | const std::shared_ptr<renderengine::ExternalTexture>& buffer, | 
|  | 353 | bool forSystem, bool regionSampling) { | 
| chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 354 | ScreenCaptureResults captureResults; | 
| chaviw | c6ad8af | 2020-08-03 11:33:30 -0700 | [diff] [blame] | 355 | return mFlinger->renderScreenImplLocked(renderArea, traverseLayers, buffer, forSystem, | 
| chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 356 | regionSampling, false /* grayscale */, | 
|  | 357 | captureResults); | 
| Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 358 | } | 
|  | 359 |  | 
| chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 360 | auto traverseLayersInLayerStack(ui::LayerStack layerStack, int32_t uid, | 
| Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 361 | const LayerVector::Visitor& visitor) { | 
| chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 362 | return mFlinger->SurfaceFlinger::traverseLayersInLayerStack(layerStack, uid, visitor); | 
| Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 363 | } | 
|  | 364 |  | 
| Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 365 | auto getDisplayNativePrimaries(const sp<IBinder>& displayToken, | 
|  | 366 | ui::DisplayPrimaries &primaries) { | 
|  | 367 | return mFlinger->SurfaceFlinger::getDisplayNativePrimaries(displayToken, primaries); | 
|  | 368 | } | 
|  | 369 |  | 
| Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 370 | auto& getTransactionQueue() { return mFlinger->mTransactionQueue; } | 
|  | 371 | auto& getPendingTransactionQueue() { return mFlinger->mPendingTransactionQueues; } | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 372 |  | 
| Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 373 | auto setTransactionState( | 
|  | 374 | const FrameTimelineInfo& frameTimelineInfo, const Vector<ComposerState>& states, | 
|  | 375 | const Vector<DisplayState>& displays, uint32_t flags, const sp<IBinder>& applyToken, | 
|  | 376 | const InputWindowCommands& inputWindowCommands, int64_t desiredPresentTime, | 
|  | 377 | bool isAutoTimestamp, const client_cache_t& uncacheBuffer, bool hasListenerCallbacks, | 
|  | 378 | std::vector<ListenerCallbacks>& listenerCallbacks, uint64_t transactionId) { | 
|  | 379 | return mFlinger->setTransactionState(frameTimelineInfo, states, displays, flags, applyToken, | 
|  | 380 | inputWindowCommands, desiredPresentTime, | 
| Ady Abraham | f0c5649 | 2020-12-17 18:04:15 -0800 | [diff] [blame] | 381 | isAutoTimestamp, uncacheBuffer, hasListenerCallbacks, | 
|  | 382 | listenerCallbacks, transactionId); | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 383 | } | 
|  | 384 |  | 
| Zhuoyao Zhang | 3d3540d | 2021-01-14 05:14:54 +0000 | [diff] [blame] | 385 | auto flushTransactionQueues() { return mFlinger->flushTransactionQueues(); }; | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 386 |  | 
| Eduardo Rocha | ac86719 | 2020-09-14 20:12:17 +0000 | [diff] [blame] | 387 | auto onTransact(uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) { | 
|  | 388 | return mFlinger->onTransact(code, data, reply, flags); | 
|  | 389 | } | 
|  | 390 |  | 
| Ana Krulec | 31f2b3c | 2020-12-14 14:30:09 -0800 | [diff] [blame] | 391 | auto getGPUContextPriority() { return mFlinger->getGPUContextPriority(); } | 
|  | 392 |  | 
| Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 393 | auto calculateMaxAcquiredBufferCount(Fps refreshRate, | 
|  | 394 | std::chrono::nanoseconds presentLatency) const { | 
|  | 395 | return SurfaceFlinger::calculateMaxAcquiredBufferCount(refreshRate, presentLatency); | 
| Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 396 | } | 
|  | 397 |  | 
| Lloyd Pique | 86016da | 2018-03-01 16:09:38 -0800 | [diff] [blame] | 398 | /* ------------------------------------------------------------------------ | 
|  | 399 | * Read-only access to private data to assert post-conditions. | 
|  | 400 | */ | 
|  | 401 |  | 
|  | 402 | const auto& getAnimFrameTracker() const { return mFlinger->mAnimFrameTracker; } | 
| Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 403 | const auto& getHasPoweredOff() const { return mFlinger->mHasPoweredOff; } | 
| Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 404 | const auto& getVisibleRegionsDirty() const { return mFlinger->mVisibleRegionsDirty; } | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 405 | auto& getHwComposer() const { | 
|  | 406 | return static_cast<impl::HWComposer&>(mFlinger->getHwComposer()); | 
|  | 407 | } | 
| Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 408 | auto& getCompositionEngine() const { return mFlinger->getCompositionEngine(); } | 
| Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 409 |  | 
| Lloyd Pique | 86016da | 2018-03-01 16:09:38 -0800 | [diff] [blame] | 410 | const auto& getCompositorTiming() const { return mFlinger->getBE().mCompositorTiming; } | 
|  | 411 |  | 
| Adithya Srinivasan | b238cd5 | 2021-02-04 17:54:05 +0000 | [diff] [blame] | 412 | mock::FrameTracer* getFrameTracer() const { | 
|  | 413 | return static_cast<mock::FrameTracer*>(mFlinger->mFrameTracer.get()); | 
|  | 414 | } | 
|  | 415 |  | 
| Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 416 | /* ------------------------------------------------------------------------ | 
|  | 417 | * Read-write access to private data to set up preconditions and assert | 
|  | 418 | * post-conditions. | 
|  | 419 | */ | 
| Lloyd Pique | 0b1fe70 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 420 |  | 
| Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 421 | auto& mutableHasWideColorDisplay() { return SurfaceFlinger::hasWideColorDisplay; } | 
| Peiyong Lin | 13effd1 | 2018-07-24 17:01:47 -0700 | [diff] [blame] | 422 | auto& mutableUseColorManagement() { return SurfaceFlinger::useColorManagement; } | 
| Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 423 |  | 
| Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 424 | auto& mutableCurrentState() { return mFlinger->mCurrentState; } | 
| Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 425 | auto& mutableDisplayColorSetting() { return mFlinger->mDisplayColorSetting; } | 
| Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 426 | auto& mutableDisplays() { return mFlinger->mDisplays; } | 
| Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 427 | auto& mutableDrawingState() { return mFlinger->mDrawingState; } | 
| Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 428 | auto& mutableEventQueue() { return mFlinger->mEventQueue; } | 
| Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 429 | auto& mutableGeometryInvalid() { return mFlinger->mGeometryInvalid; } | 
| Lloyd Pique | 0b1fe70 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 430 | auto& mutableInterceptor() { return mFlinger->mInterceptor; } | 
| Lloyd Pique | 6cf1103 | 2018-01-22 18:57:44 -0800 | [diff] [blame] | 431 | auto& mutableMainThreadId() { return mFlinger->mMainThreadId; } | 
| Lloyd Pique | 0b1fe70 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 432 | auto& mutablePendingHotplugEvents() { return mFlinger->mPendingHotplugEvents; } | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 433 | auto& mutablePhysicalDisplayTokens() { return mFlinger->mPhysicalDisplayTokens; } | 
| Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 434 | auto& mutableTexturePool() { return mFlinger->mTexturePool; } | 
| Lloyd Pique | 0b1fe70 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 435 | auto& mutableTransactionFlags() { return mFlinger->mTransactionFlags; } | 
| Peiyong Lin | 74ca2f4 | 2019-01-14 19:36:57 -0800 | [diff] [blame] | 436 | auto& mutablePowerAdvisor() { return mFlinger->mPowerAdvisor; } | 
| Lloyd Pique | 4fe2940 | 2019-08-12 16:51:24 -0700 | [diff] [blame] | 437 | auto& mutableDebugDisableHWC() { return mFlinger->mDebugDisableHWC; } | 
| Garfield Tan | 9c9c191 | 2021-07-19 12:02:16 -0700 | [diff] [blame] | 438 | auto& mutableMaxRenderTargetSize() { return mFlinger->mMaxRenderTargetSize; } | 
| Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 439 |  | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 440 | auto& mutableHwcDisplayData() { return getHwComposer().mDisplayData; } | 
|  | 441 | auto& mutableHwcPhysicalDisplayIdMap() { return getHwComposer().mPhysicalDisplayIdMap; } | 
|  | 442 | auto& mutableInternalHwcDisplayId() { return getHwComposer().mInternalHwcDisplayId; } | 
|  | 443 | auto& mutableExternalHwcDisplayId() { return getHwComposer().mExternalHwcDisplayId; } | 
| Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 444 | auto& mutableUseFrameRateApi() { return mFlinger->useFrameRateApi; } | 
| Lloyd Pique | a618d85 | 2018-01-17 11:52:30 -0800 | [diff] [blame] | 445 |  | 
| Valerie Hau | 09e6005 | 2019-12-15 14:51:15 -0800 | [diff] [blame] | 446 | auto fromHandle(const sp<IBinder>& handle) { | 
| Valerie Hau | 09e6005 | 2019-12-15 14:51:15 -0800 | [diff] [blame] | 447 | return mFlinger->fromHandle(handle); | 
|  | 448 | } | 
|  | 449 |  | 
| Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 450 | ~TestableSurfaceFlinger() { | 
|  | 451 | // All these pointer and container clears help ensure that GMock does | 
|  | 452 | // not report a leaked object, since the SurfaceFlinger instance may | 
|  | 453 | // still be referenced by something despite our best efforts to destroy | 
|  | 454 | // it after each test is done. | 
|  | 455 | mutableDisplays().clear(); | 
| Ady Abraham | 2939f09 | 2019-03-04 17:44:06 -0800 | [diff] [blame] | 456 | mutableCurrentState().displays.clear(); | 
|  | 457 | mutableDrawingState().displays.clear(); | 
| Lloyd Pique | 0b1fe70 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 458 | mutableEventQueue().reset(); | 
| Pablo Gamito | 5cfc6e5 | 2020-09-10 11:18:03 +0000 | [diff] [blame] | 459 | mutableInterceptor().clear(); | 
| Lloyd Pique | 2eb71eb | 2019-08-13 13:23:03 -0700 | [diff] [blame] | 460 | mFlinger->mScheduler.reset(); | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 461 | mFlinger->mCompositionEngine->setHwComposer(std::unique_ptr<HWComposer>()); | 
| Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 462 | mFlinger->mCompositionEngine->setRenderEngine( | 
|  | 463 | std::unique_ptr<renderengine::RenderEngine>()); | 
| Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 464 | } | 
| Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 465 |  | 
| Lloyd Pique | a618d85 | 2018-01-17 11:52:30 -0800 | [diff] [blame] | 466 | /* ------------------------------------------------------------------------ | 
|  | 467 | * Wrapper classes for Read-write access to private data to set up | 
|  | 468 | * preconditions and assert post-conditions. | 
|  | 469 | */ | 
| Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 470 | struct HWC2Display : public HWC2::impl::Display { | 
| Peiyong Lin | 74ca2f4 | 2019-01-14 19:36:57 -0800 | [diff] [blame] | 471 | HWC2Display(Hwc2::Composer& composer, | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 472 | const std::unordered_set<hal::Capability>& capabilities, hal::HWDisplayId id, | 
|  | 473 | hal::DisplayType type) | 
| Peiyong Lin | 74ca2f4 | 2019-01-14 19:36:57 -0800 | [diff] [blame] | 474 | : HWC2::impl::Display(composer, capabilities, id, type) {} | 
| Lloyd Pique | a618d85 | 2018-01-17 11:52:30 -0800 | [diff] [blame] | 475 | ~HWC2Display() { | 
|  | 476 | // Prevents a call to disable vsyncs. | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 477 | mType = hal::DisplayType::INVALID; | 
| Lloyd Pique | a618d85 | 2018-01-17 11:52:30 -0800 | [diff] [blame] | 478 | } | 
|  | 479 |  | 
|  | 480 | auto& mutableIsConnected() { return this->mIsConnected; } | 
| Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 481 | auto& mutableLayers() { return this->mLayers; } | 
| Lloyd Pique | a618d85 | 2018-01-17 11:52:30 -0800 | [diff] [blame] | 482 | }; | 
|  | 483 |  | 
| Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 484 | class FakeHwcDisplayInjector { | 
|  | 485 | public: | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 486 | static constexpr hal::HWDisplayId DEFAULT_HWC_DISPLAY_ID = 1000; | 
| Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 487 | static constexpr int32_t DEFAULT_WIDTH = 1920; | 
|  | 488 | static constexpr int32_t DEFAULT_HEIGHT = 1280; | 
| Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 489 | static constexpr int32_t DEFAULT_VSYNC_PERIOD = 16'666'666; | 
| Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 490 | static constexpr int32_t DEFAULT_CONFIG_GROUP = 7; | 
| Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 491 | static constexpr int32_t DEFAULT_DPI = 320; | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 492 | static constexpr hal::HWConfigId DEFAULT_ACTIVE_CONFIG = 0; | 
| Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 493 | static constexpr hal::PowerMode DEFAULT_POWER_MODE = hal::PowerMode::ON; | 
| Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 494 |  | 
| Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 495 | FakeHwcDisplayInjector(HalDisplayId displayId, hal::DisplayType hwcDisplayType, | 
|  | 496 | bool isPrimary) | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 497 | : mDisplayId(displayId), mHwcDisplayType(hwcDisplayType), mIsPrimary(isPrimary) {} | 
| Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 498 |  | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 499 | auto& setHwcDisplayId(hal::HWDisplayId displayId) { | 
| Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 500 | mHwcDisplayId = displayId; | 
|  | 501 | return *this; | 
|  | 502 | } | 
|  | 503 |  | 
|  | 504 | auto& setWidth(int32_t width) { | 
|  | 505 | mWidth = width; | 
|  | 506 | return *this; | 
|  | 507 | } | 
|  | 508 |  | 
|  | 509 | auto& setHeight(int32_t height) { | 
|  | 510 | mHeight = height; | 
|  | 511 | return *this; | 
|  | 512 | } | 
|  | 513 |  | 
| Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 514 | auto& setVsyncPeriod(int32_t vsyncPeriod) { | 
|  | 515 | mVsyncPeriod = vsyncPeriod; | 
| Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 516 | return *this; | 
|  | 517 | } | 
|  | 518 |  | 
|  | 519 | auto& setDpiX(int32_t dpi) { | 
|  | 520 | mDpiX = dpi; | 
|  | 521 | return *this; | 
|  | 522 | } | 
|  | 523 |  | 
|  | 524 | auto& setDpiY(int32_t dpi) { | 
|  | 525 | mDpiY = dpi; | 
|  | 526 | return *this; | 
|  | 527 | } | 
|  | 528 |  | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 529 | auto& setActiveConfig(hal::HWConfigId config) { | 
| Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 530 | mActiveConfig = config; | 
|  | 531 | return *this; | 
|  | 532 | } | 
|  | 533 |  | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 534 | auto& setCapabilities(const std::unordered_set<hal::Capability>* capabilities) { | 
| Lloyd Pique | e22f033 | 2018-07-16 16:35:56 -0700 | [diff] [blame] | 535 | mCapabilities = capabilities; | 
|  | 536 | return *this; | 
|  | 537 | } | 
|  | 538 |  | 
| Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 539 | auto& setPowerMode(hal::PowerMode mode) { | 
| Peiyong Lin | 1336e6e | 2019-05-28 09:23:50 -0700 | [diff] [blame] | 540 | mPowerMode = mode; | 
|  | 541 | return *this; | 
|  | 542 | } | 
|  | 543 |  | 
| Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 544 | void inject(TestableSurfaceFlinger* flinger, Hwc2::mock::Composer* composer) { | 
|  | 545 | using ::testing::_; | 
|  | 546 | using ::testing::DoAll; | 
|  | 547 | using ::testing::Return; | 
|  | 548 | using ::testing::SetArgPointee; | 
|  | 549 |  | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 550 | static const std::unordered_set<hal::Capability> defaultCapabilities; | 
| Lloyd Pique | e22f033 | 2018-07-16 16:35:56 -0700 | [diff] [blame] | 551 | if (mCapabilities == nullptr) mCapabilities = &defaultCapabilities; | 
|  | 552 |  | 
|  | 553 | // Caution - Make sure that any values passed by reference here do | 
|  | 554 | // not refer to an instance owned by FakeHwcDisplayInjector. This | 
|  | 555 | // class has temporary lifetime, while the constructed HWC2::Display | 
|  | 556 | // is much longer lived. | 
| Peiyong Lin | 74ca2f4 | 2019-01-14 19:36:57 -0800 | [diff] [blame] | 557 | auto display = std::make_unique<HWC2Display>(*composer, *mCapabilities, mHwcDisplayId, | 
|  | 558 | mHwcDisplayType); | 
| Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 559 |  | 
| Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 560 | display->mutableIsConnected() = true; | 
| Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 561 | display->setPowerMode(mPowerMode); | 
| Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 562 | flinger->mutableHwcDisplayData()[mDisplayId].hwcDisplay = std::move(display); | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 563 |  | 
| Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 564 | EXPECT_CALL(*composer, getDisplayConfigs(mHwcDisplayId, _)) | 
|  | 565 | .WillRepeatedly( | 
|  | 566 | DoAll(SetArgPointee<1>(std::vector<hal::HWConfigId>{mActiveConfig}), | 
|  | 567 | Return(hal::Error::NONE))); | 
|  | 568 |  | 
|  | 569 | EXPECT_CALL(*composer, | 
|  | 570 | getDisplayAttribute(mHwcDisplayId, mActiveConfig, hal::Attribute::WIDTH, _)) | 
|  | 571 | .WillRepeatedly(DoAll(SetArgPointee<3>(mWidth), Return(hal::Error::NONE))); | 
|  | 572 |  | 
|  | 573 | EXPECT_CALL(*composer, | 
|  | 574 | getDisplayAttribute(mHwcDisplayId, mActiveConfig, hal::Attribute::HEIGHT, | 
|  | 575 | _)) | 
|  | 576 | .WillRepeatedly(DoAll(SetArgPointee<3>(mHeight), Return(hal::Error::NONE))); | 
|  | 577 |  | 
|  | 578 | EXPECT_CALL(*composer, | 
|  | 579 | getDisplayAttribute(mHwcDisplayId, mActiveConfig, | 
|  | 580 | hal::Attribute::VSYNC_PERIOD, _)) | 
|  | 581 | .WillRepeatedly( | 
|  | 582 | DoAll(SetArgPointee<3>(mVsyncPeriod), Return(hal::Error::NONE))); | 
|  | 583 |  | 
|  | 584 | EXPECT_CALL(*composer, | 
|  | 585 | getDisplayAttribute(mHwcDisplayId, mActiveConfig, hal::Attribute::DPI_X, _)) | 
|  | 586 | .WillRepeatedly(DoAll(SetArgPointee<3>(mDpiX), Return(hal::Error::NONE))); | 
|  | 587 |  | 
|  | 588 | EXPECT_CALL(*composer, | 
|  | 589 | getDisplayAttribute(mHwcDisplayId, mActiveConfig, hal::Attribute::DPI_Y, _)) | 
|  | 590 | .WillRepeatedly(DoAll(SetArgPointee<3>(mDpiY), Return(hal::Error::NONE))); | 
|  | 591 |  | 
|  | 592 | EXPECT_CALL(*composer, | 
|  | 593 | getDisplayAttribute(mHwcDisplayId, mActiveConfig, | 
|  | 594 | hal::Attribute::CONFIG_GROUP, _)) | 
|  | 595 | .WillRepeatedly( | 
|  | 596 | DoAll(SetArgPointee<3>(mConfigGroup), Return(hal::Error::NONE))); | 
| Marin Shalamanov | 3ea1d60 | 2020-12-16 19:59:39 +0100 | [diff] [blame] | 597 |  | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 598 | if (mHwcDisplayType == hal::DisplayType::PHYSICAL) { | 
| Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 599 | const auto physicalId = PhysicalDisplayId::tryCast(mDisplayId); | 
|  | 600 | LOG_ALWAYS_FATAL_IF(!physicalId); | 
|  | 601 | flinger->mutableHwcPhysicalDisplayIdMap().emplace(mHwcDisplayId, *physicalId); | 
| Marin Shalamanov | 6e84017 | 2020-12-14 22:13:28 +0100 | [diff] [blame] | 602 | if (mIsPrimary) { | 
|  | 603 | flinger->mutableInternalHwcDisplayId() = mHwcDisplayId; | 
|  | 604 | } else { | 
|  | 605 | // If there is an external HWC display there should always be an internal ID | 
|  | 606 | // as well. Set it to some arbitrary value. | 
|  | 607 | auto& internalId = flinger->mutableInternalHwcDisplayId(); | 
|  | 608 | if (!internalId) internalId = mHwcDisplayId - 1; | 
|  | 609 | flinger->mutableExternalHwcDisplayId() = mHwcDisplayId; | 
|  | 610 | } | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 611 | } | 
| Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 612 | } | 
|  | 613 |  | 
|  | 614 | private: | 
| Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 615 | const HalDisplayId mDisplayId; | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 616 | const hal::DisplayType mHwcDisplayType; | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 617 | const bool mIsPrimary; | 
|  | 618 |  | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 619 | hal::HWDisplayId mHwcDisplayId = DEFAULT_HWC_DISPLAY_ID; | 
| Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 620 | int32_t mWidth = DEFAULT_WIDTH; | 
|  | 621 | int32_t mHeight = DEFAULT_HEIGHT; | 
| Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 622 | int32_t mVsyncPeriod = DEFAULT_VSYNC_PERIOD; | 
| Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 623 | int32_t mDpiX = DEFAULT_DPI; | 
|  | 624 | int32_t mDpiY = DEFAULT_DPI; | 
| Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 625 | int32_t mConfigGroup = DEFAULT_CONFIG_GROUP; | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 626 | hal::HWConfigId mActiveConfig = DEFAULT_ACTIVE_CONFIG; | 
| Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 627 | hal::PowerMode mPowerMode = DEFAULT_POWER_MODE; | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 628 | const std::unordered_set<hal::Capability>* mCapabilities = nullptr; | 
| Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 629 | }; | 
|  | 630 |  | 
|  | 631 | class FakeDisplayDeviceInjector { | 
|  | 632 | public: | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 633 | FakeDisplayDeviceInjector(TestableSurfaceFlinger& flinger, | 
| Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 634 | std::shared_ptr<compositionengine::Display> compositionDisplay, | 
| Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 635 | std::optional<ui::DisplayConnectionType> connectionType, | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 636 | std::optional<hal::HWDisplayId> hwcDisplayId, bool isPrimary) | 
| Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 637 | : mFlinger(flinger), | 
| Marin Shalamanov | 12c9e5a | 2021-01-07 00:25:35 +0100 | [diff] [blame] | 638 | mCreationArgs(flinger.mFlinger.get(), flinger.mFlinger->getHwComposer(), | 
|  | 639 | mDisplayToken, compositionDisplay), | 
| Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 640 | mHwcDisplayId(hwcDisplayId) { | 
| Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 641 | mCreationArgs.connectionType = connectionType; | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 642 | mCreationArgs.isPrimary = isPrimary; | 
| Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 643 |  | 
|  | 644 | mActiveModeId = DisplayModeId(0); | 
|  | 645 | DisplayModePtr activeMode = | 
|  | 646 | DisplayMode::Builder(FakeHwcDisplayInjector::DEFAULT_ACTIVE_CONFIG) | 
|  | 647 | .setId(mActiveModeId) | 
| Ady Abraham | f3e81d2 | 2021-06-23 17:43:41 -0700 | [diff] [blame] | 648 | .setPhysicalDisplayId(PhysicalDisplayId(0)) | 
| Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 649 | .setWidth(FakeHwcDisplayInjector::DEFAULT_WIDTH) | 
|  | 650 | .setHeight(FakeHwcDisplayInjector::DEFAULT_HEIGHT) | 
|  | 651 | .setVsyncPeriod(FakeHwcDisplayInjector::DEFAULT_VSYNC_PERIOD) | 
|  | 652 | .setDpiX(FakeHwcDisplayInjector::DEFAULT_DPI) | 
|  | 653 | .setDpiY(FakeHwcDisplayInjector::DEFAULT_DPI) | 
| Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 654 | .setGroup(0) | 
| Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 655 | .build(); | 
|  | 656 |  | 
|  | 657 | DisplayModes modes{activeMode}; | 
|  | 658 | mCreationArgs.supportedModes = modes; | 
| Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 659 | mCreationArgs.refreshRateConfigs = flinger.mRefreshRateConfigs; | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 660 | } | 
| Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 661 |  | 
|  | 662 | sp<IBinder> token() const { return mDisplayToken; } | 
|  | 663 |  | 
|  | 664 | DisplayDeviceState& mutableDrawingDisplayState() { | 
|  | 665 | return mFlinger.mutableDrawingState().displays.editValueFor(mDisplayToken); | 
|  | 666 | } | 
|  | 667 |  | 
|  | 668 | DisplayDeviceState& mutableCurrentDisplayState() { | 
|  | 669 | return mFlinger.mutableCurrentState().displays.editValueFor(mDisplayToken); | 
|  | 670 | } | 
|  | 671 |  | 
| Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 672 | const auto& getDrawingDisplayState() { | 
|  | 673 | return mFlinger.mutableDrawingState().displays.valueFor(mDisplayToken); | 
|  | 674 | } | 
|  | 675 |  | 
|  | 676 | const auto& getCurrentDisplayState() { | 
|  | 677 | return mFlinger.mutableCurrentState().displays.valueFor(mDisplayToken); | 
|  | 678 | } | 
|  | 679 |  | 
| Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 680 | auto& mutableDisplayDevice() { return mFlinger.mutableDisplays()[mDisplayToken]; } | 
| Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 681 |  | 
| Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 682 | auto& setActiveMode(DisplayModeId mode) { | 
|  | 683 | mActiveModeId = mode; | 
|  | 684 | return *this; | 
|  | 685 | } | 
|  | 686 |  | 
|  | 687 | auto& setSupportedModes(DisplayModes mode) { | 
|  | 688 | mCreationArgs.supportedModes = mode; | 
|  | 689 | return *this; | 
|  | 690 | } | 
|  | 691 |  | 
| Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 692 | auto& setNativeWindow(const sp<ANativeWindow>& nativeWindow) { | 
| Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 693 | mCreationArgs.nativeWindow = nativeWindow; | 
| Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 694 | return *this; | 
|  | 695 | } | 
|  | 696 |  | 
| Lloyd Pique | 542307f | 2018-10-19 13:24:08 -0700 | [diff] [blame] | 697 | auto& setDisplaySurface(const sp<compositionengine::DisplaySurface>& displaySurface) { | 
| Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 698 | mCreationArgs.displaySurface = displaySurface; | 
| Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 699 | return *this; | 
|  | 700 | } | 
|  | 701 |  | 
| Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 702 | auto& setSecure(bool secure) { | 
| Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 703 | mCreationArgs.isSecure = secure; | 
| Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 704 | return *this; | 
|  | 705 | } | 
|  | 706 |  | 
| Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 707 | auto& setPowerMode(hal::PowerMode mode) { | 
| Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 708 | mCreationArgs.initialPowerMode = mode; | 
| Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 709 | return *this; | 
|  | 710 | } | 
|  | 711 |  | 
| Valerie Hau | 9758ae0 | 2018-10-09 16:05:09 -0700 | [diff] [blame] | 712 | auto& setHwcColorModes( | 
|  | 713 | const std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>> | 
|  | 714 | hwcColorModes) { | 
|  | 715 | mCreationArgs.hwcColorModes = hwcColorModes; | 
|  | 716 | return *this; | 
|  | 717 | } | 
|  | 718 |  | 
|  | 719 | auto& setHasWideColorGamut(bool hasWideColorGamut) { | 
|  | 720 | mCreationArgs.hasWideColorGamut = hasWideColorGamut; | 
|  | 721 | return *this; | 
|  | 722 | } | 
|  | 723 |  | 
| Lloyd Pique | 3305047 | 2019-12-19 17:12:44 -0800 | [diff] [blame] | 724 | auto& setPhysicalOrientation(ui::Rotation orientation) { | 
|  | 725 | mCreationArgs.physicalOrientation = orientation; | 
|  | 726 | return *this; | 
|  | 727 | } | 
|  | 728 |  | 
| Ady Abraham | b493739 | 2021-06-23 18:05:03 -0700 | [diff] [blame] | 729 | sp<DisplayDevice> inject() NO_THREAD_SAFETY_ANALYSIS { | 
| Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 730 | const auto displayId = mCreationArgs.compositionDisplay->getDisplayId(); | 
|  | 731 |  | 
| Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 732 | DisplayDeviceState state; | 
| Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 733 | if (const auto type = mCreationArgs.connectionType) { | 
| Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 734 | LOG_ALWAYS_FATAL_IF(!displayId); | 
| Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 735 | const auto physicalId = PhysicalDisplayId::tryCast(*displayId); | 
|  | 736 | LOG_ALWAYS_FATAL_IF(!physicalId); | 
| Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 737 | LOG_ALWAYS_FATAL_IF(!mHwcDisplayId); | 
| Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 738 | state.physical = {.id = *physicalId, .type = *type, .hwcDisplayId = *mHwcDisplayId}; | 
| Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 739 | } | 
|  | 740 |  | 
| Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 741 | state.isSecure = mCreationArgs.isSecure; | 
|  | 742 |  | 
| Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 743 | sp<DisplayDevice> device = new DisplayDevice(mCreationArgs); | 
| Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 744 | if (!device->isVirtual()) { | 
|  | 745 | device->setActiveMode(mActiveModeId); | 
|  | 746 | } | 
| Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 747 | mFlinger.mutableDisplays().emplace(mDisplayToken, device); | 
| Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 748 | mFlinger.mutableCurrentState().displays.add(mDisplayToken, state); | 
|  | 749 | mFlinger.mutableDrawingState().displays.add(mDisplayToken, state); | 
|  | 750 |  | 
| Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 751 | if (const auto& physical = state.physical) { | 
|  | 752 | mFlinger.mutablePhysicalDisplayTokens()[physical->id] = mDisplayToken; | 
| Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 753 | } | 
|  | 754 |  | 
|  | 755 | return device; | 
|  | 756 | } | 
|  | 757 |  | 
|  | 758 | private: | 
|  | 759 | TestableSurfaceFlinger& mFlinger; | 
|  | 760 | sp<BBinder> mDisplayToken = new BBinder(); | 
| Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 761 | DisplayDeviceCreationArgs mCreationArgs; | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 762 | const std::optional<hal::HWDisplayId> mHwcDisplayId; | 
| Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 763 | DisplayModeId mActiveModeId; | 
| Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 764 | }; | 
|  | 765 |  | 
| Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 766 | private: | 
|  | 767 | void setVsyncEnabled(bool) override {} | 
| Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 768 | void changeRefreshRate(const Scheduler::RefreshRate&, Scheduler::ModeEvent) override {} | 
| Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 769 | void repaintEverythingForHWC() override {} | 
|  | 770 | void kernelTimerChanged(bool) override {} | 
| Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 771 | void triggerOnFrameRateOverridesChanged() {} | 
| Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 772 |  | 
| Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 773 | surfaceflinger::test::Factory mFactory; | 
|  | 774 | sp<SurfaceFlinger> mFlinger = new SurfaceFlinger(mFactory, SurfaceFlinger::SkipInitialization); | 
| Dominik Laskowski | 7c9dbf9 | 2019-08-01 17:57:31 -0700 | [diff] [blame] | 775 | TestableScheduler* mScheduler = nullptr; | 
| Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 776 | std::shared_ptr<scheduler::RefreshRateConfigs> mRefreshRateConfigs; | 
| Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 777 | }; | 
|  | 778 |  | 
|  | 779 | } // namespace android |