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