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