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 | |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 333 | void setPowerHintSessionMode(bool early, bool late) { |
| 334 | mFlinger->mPowerHintSessionMode = {.late = late, .early = early}; |
| 335 | } |
| 336 | |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 337 | /* ------------------------------------------------------------------------ |
| 338 | * Forwarding for functions being tested |
| 339 | */ |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 340 | |
| 341 | nsecs_t commit(nsecs_t frameTime, int64_t vsyncId, nsecs_t expectedVSyncTime) { |
| 342 | mFlinger->commit(frameTime, vsyncId, expectedVSyncTime); |
| 343 | return frameTime; |
| 344 | } |
| 345 | |
| 346 | nsecs_t commit(nsecs_t frameTime, int64_t vsyncId) { |
| 347 | std::chrono::nanoseconds period = 10ms; |
| 348 | return commit(frameTime, vsyncId, frameTime + period.count()); |
| 349 | } |
| 350 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 351 | nsecs_t commit() { |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 352 | const nsecs_t now = systemTime(); |
| 353 | const nsecs_t expectedVsyncTime = now + 10'000'000; |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 354 | return commit(now, kVsyncId, expectedVsyncTime); |
| 355 | } |
| 356 | |
| 357 | void commitAndComposite(const nsecs_t frameTime, const int64_t vsyncId, |
| 358 | const nsecs_t expectedVsyncTime) { |
| 359 | mFlinger->composite(commit(frameTime, vsyncId, expectedVsyncTime), kVsyncId); |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 360 | } |
| 361 | |
Ady Abraham | 302ebed | 2022-03-07 16:03:41 -0800 | [diff] [blame] | 362 | void commitAndComposite() { mFlinger->composite(commit(), kVsyncId); } |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 363 | |
Lloyd Pique | a482f99 | 2018-01-22 19:00:34 -0800 | [diff] [blame] | 364 | auto createDisplay(const String8& displayName, bool secure) { |
| 365 | return mFlinger->createDisplay(displayName, secure); |
| 366 | } |
| 367 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 368 | auto destroyDisplay(const sp<IBinder>& displayToken) { |
| 369 | return mFlinger->destroyDisplay(displayToken); |
| 370 | } |
Lloyd Pique | a482f99 | 2018-01-22 19:00:34 -0800 | [diff] [blame] | 371 | |
Marin Shalamanov | c7e9f82 | 2021-11-16 20:07:55 +0100 | [diff] [blame] | 372 | auto getDisplay(const sp<IBinder>& displayToken) { |
| 373 | Mutex::Autolock lock(mFlinger->mStateLock); |
| 374 | return mFlinger->getDisplayDeviceLocked(displayToken); |
| 375 | } |
| 376 | |
Dominik Laskowski | 1394860 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 377 | void enableHalVirtualDisplays(bool enable) { mFlinger->enableHalVirtualDisplays(enable); } |
| 378 | |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 379 | auto setupNewDisplayDeviceInternal( |
| 380 | const wp<IBinder>& displayToken, |
| 381 | std::shared_ptr<compositionengine::Display> compositionDisplay, |
| 382 | const DisplayDeviceState& state, |
| 383 | const sp<compositionengine::DisplaySurface>& dispSurface, |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 384 | const sp<IGraphicBufferProducer>& producer) NO_THREAD_SAFETY_ANALYSIS { |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 385 | return mFlinger->setupNewDisplayDeviceInternal(displayToken, compositionDisplay, state, |
| 386 | dispSurface, producer); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 387 | } |
| 388 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 389 | auto commitTransactionsLocked(uint32_t transactionFlags) { |
| 390 | Mutex::Autolock lock(mFlinger->mStateLock); |
| 391 | return mFlinger->commitTransactionsLocked(transactionFlags); |
Lloyd Pique | 0b1fe70 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 392 | } |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 393 | |
Dominik Laskowski | ebc8d3a | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 394 | void onComposerHalHotplug(hal::HWDisplayId hwcDisplayId, hal::Connection connection) { |
| 395 | mFlinger->onComposerHalHotplug(hwcDisplayId, connection); |
Lloyd Pique | 6cf1103 | 2018-01-22 18:57:44 -0800 | [diff] [blame] | 396 | } |
| 397 | |
Vishnu Nair | ce5d0cc | 2019-02-28 14:38:41 -0800 | [diff] [blame] | 398 | auto setDisplayStateLocked(const DisplayState& s) { |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 399 | Mutex::Autolock lock(mFlinger->mStateLock); |
Vishnu Nair | ce5d0cc | 2019-02-28 14:38:41 -0800 | [diff] [blame] | 400 | return mFlinger->setDisplayStateLocked(s); |
| 401 | } |
Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 402 | |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 403 | // Allow reading display state without locking, as if called on the SF main thread. |
| 404 | auto onInitializeDisplays() NO_THREAD_SAFETY_ANALYSIS { |
| 405 | return mFlinger->onInitializeDisplays(); |
| 406 | } |
Lloyd Pique | 86016da | 2018-03-01 16:09:38 -0800 | [diff] [blame] | 407 | |
Lais Andrade | 3a6e47d | 2020-04-02 11:20:16 +0100 | [diff] [blame] | 408 | auto notifyPowerBoost(int32_t boostId) { return mFlinger->notifyPowerBoost(boostId); } |
| 409 | |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 410 | auto setDisplayBrightness(const sp<IBinder>& display, |
| 411 | const gui::DisplayBrightness& brightness) { |
| 412 | return mFlinger->setDisplayBrightness(display, brightness); |
| 413 | } |
| 414 | |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 415 | // Allow reading display state without locking, as if called on the SF main thread. |
| 416 | auto setPowerModeInternal(const sp<DisplayDevice>& display, |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 417 | hal::PowerMode mode) NO_THREAD_SAFETY_ANALYSIS { |
Dominik Laskowski | e977409 | 2018-12-11 10:04:24 -0800 | [diff] [blame] | 418 | return mFlinger->setPowerModeInternal(display, mode); |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 419 | } |
| 420 | |
Robert Carr | 12a3b9b | 2022-03-10 09:55:29 -0800 | [diff] [blame] | 421 | auto renderScreenImpl(const RenderArea& renderArea, |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 422 | SurfaceFlinger::TraverseLayersFunction traverseLayers, |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 423 | const std::shared_ptr<renderengine::ExternalTexture>& buffer, |
| 424 | bool forSystem, bool regionSampling) { |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 425 | ScreenCaptureResults captureResults; |
Robert Carr | 12a3b9b | 2022-03-10 09:55:29 -0800 | [diff] [blame] | 426 | return mFlinger->renderScreenImpl(renderArea, traverseLayers, buffer, forSystem, |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 427 | regionSampling, false /* grayscale */, |
| 428 | captureResults); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 429 | } |
| 430 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 431 | auto traverseLayersInLayerStack(ui::LayerStack layerStack, int32_t uid, |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 432 | const LayerVector::Visitor& visitor) { |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 433 | return mFlinger->SurfaceFlinger::traverseLayersInLayerStack(layerStack, uid, visitor); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 434 | } |
| 435 | |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 436 | auto getDisplayNativePrimaries(const sp<IBinder>& displayToken, |
| 437 | ui::DisplayPrimaries &primaries) { |
| 438 | return mFlinger->SurfaceFlinger::getDisplayNativePrimaries(displayToken, primaries); |
| 439 | } |
| 440 | |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 441 | auto& getTransactionQueue() { return mFlinger->mTransactionQueue; } |
| 442 | auto& getPendingTransactionQueue() { return mFlinger->mPendingTransactionQueues; } |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 443 | auto& getTransactionCommittedSignals() { return mFlinger->mTransactionCommittedSignals; } |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 444 | |
Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 445 | auto setTransactionState( |
| 446 | const FrameTimelineInfo& frameTimelineInfo, const Vector<ComposerState>& states, |
| 447 | const Vector<DisplayState>& displays, uint32_t flags, const sp<IBinder>& applyToken, |
| 448 | const InputWindowCommands& inputWindowCommands, int64_t desiredPresentTime, |
| 449 | bool isAutoTimestamp, const client_cache_t& uncacheBuffer, bool hasListenerCallbacks, |
| 450 | std::vector<ListenerCallbacks>& listenerCallbacks, uint64_t transactionId) { |
| 451 | return mFlinger->setTransactionState(frameTimelineInfo, states, displays, flags, applyToken, |
| 452 | inputWindowCommands, desiredPresentTime, |
Ady Abraham | f0c5649 | 2020-12-17 18:04:15 -0800 | [diff] [blame] | 453 | isAutoTimestamp, uncacheBuffer, hasListenerCallbacks, |
| 454 | listenerCallbacks, transactionId); |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 455 | } |
| 456 | |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 457 | auto flushTransactionQueues() { return mFlinger->flushTransactionQueues(0); }; |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 458 | |
Eduardo Rocha | ac86719 | 2020-09-14 20:12:17 +0000 | [diff] [blame] | 459 | auto onTransact(uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) { |
| 460 | return mFlinger->onTransact(code, data, reply, flags); |
| 461 | } |
| 462 | |
Ana Krulec | 31f2b3c | 2020-12-14 14:30:09 -0800 | [diff] [blame] | 463 | auto getGPUContextPriority() { return mFlinger->getGPUContextPriority(); } |
| 464 | |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 465 | auto calculateMaxAcquiredBufferCount(Fps refreshRate, |
| 466 | std::chrono::nanoseconds presentLatency) const { |
| 467 | return SurfaceFlinger::calculateMaxAcquiredBufferCount(refreshRate, presentLatency); |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 468 | } |
| 469 | |
Marin Shalamanov | c7e9f82 | 2021-11-16 20:07:55 +0100 | [diff] [blame] | 470 | auto setDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, ui::DisplayModeId defaultMode, |
| 471 | bool allowGroupSwitching, float primaryRefreshRateMin, |
| 472 | float primaryRefreshRateMax, float appRequestRefreshRateMin, |
| 473 | float appRequestRefreshRateMax) { |
| 474 | return mFlinger->setDesiredDisplayModeSpecs(displayToken, defaultMode, allowGroupSwitching, |
| 475 | primaryRefreshRateMin, primaryRefreshRateMax, |
| 476 | appRequestRefreshRateMin, |
| 477 | appRequestRefreshRateMax); |
| 478 | } |
| 479 | |
| 480 | void onActiveDisplayChanged(const sp<DisplayDevice>& activeDisplay) { |
| 481 | Mutex::Autolock lock(mFlinger->mStateLock); |
| 482 | mFlinger->onActiveDisplayChangedLocked(activeDisplay); |
| 483 | } |
| 484 | |
Vishnu Nair | 4df8eb6 | 2022-02-17 15:32:02 -0800 | [diff] [blame] | 485 | auto createLayer(LayerCreationArgs& args, sp<IBinder>* outHandle, |
| 486 | const sp<IBinder>& parentHandle, int32_t* outLayerId, |
| 487 | const sp<Layer>& parentLayer, uint32_t* outTransformHint) { |
| 488 | return mFlinger->createLayer(args, outHandle, parentHandle, outLayerId, parentLayer, |
| 489 | outTransformHint); |
| 490 | } |
| 491 | |
| 492 | auto mirrorLayer(const LayerCreationArgs& args, const sp<IBinder>& mirrorFromHandle, |
| 493 | sp<IBinder>* outHandle, int32_t* outLayerId) { |
| 494 | return mFlinger->mirrorLayer(args, mirrorFromHandle, outHandle, outLayerId); |
| 495 | } |
| 496 | |
Lloyd Pique | 86016da | 2018-03-01 16:09:38 -0800 | [diff] [blame] | 497 | /* ------------------------------------------------------------------------ |
| 498 | * Read-only access to private data to assert post-conditions. |
| 499 | */ |
| 500 | |
| 501 | const auto& getAnimFrameTracker() const { return mFlinger->mAnimFrameTracker; } |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 502 | const auto& getHasPoweredOff() const { return mFlinger->mHasPoweredOff; } |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 503 | const auto& getVisibleRegionsDirty() const { return mFlinger->mVisibleRegionsDirty; } |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 504 | auto& getHwComposer() const { |
| 505 | return static_cast<impl::HWComposer&>(mFlinger->getHwComposer()); |
| 506 | } |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 507 | auto& getCompositionEngine() const { return mFlinger->getCompositionEngine(); } |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 508 | |
Lloyd Pique | 86016da | 2018-03-01 16:09:38 -0800 | [diff] [blame] | 509 | const auto& getCompositorTiming() const { return mFlinger->getBE().mCompositorTiming; } |
| 510 | |
Adithya Srinivasan | b238cd5 | 2021-02-04 17:54:05 +0000 | [diff] [blame] | 511 | mock::FrameTracer* getFrameTracer() const { |
| 512 | return static_cast<mock::FrameTracer*>(mFlinger->mFrameTracer.get()); |
| 513 | } |
| 514 | |
Ady Abraham | e9ebce0 | 2022-02-03 12:05:06 -0800 | [diff] [blame] | 515 | nsecs_t getAnimationTransactionTimeout() const { |
| 516 | return mFlinger->mAnimationTransactionTimeout; |
| 517 | } |
| 518 | |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 519 | /* ------------------------------------------------------------------------ |
| 520 | * Read-write access to private data to set up preconditions and assert |
| 521 | * post-conditions. |
| 522 | */ |
Lloyd Pique | 0b1fe70 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 523 | |
Dominik Laskowski | eb62731 | 2022-04-07 09:13:16 -0700 | [diff] [blame] | 524 | const auto& displays() const { return mFlinger->mDisplays; } |
| 525 | const auto& currentState() const { return mFlinger->mCurrentState; } |
| 526 | const auto& drawingState() const { return mFlinger->mDrawingState; } |
| 527 | const auto& transactionFlags() const { return mFlinger->mTransactionFlags; } |
| 528 | const auto& hwcPhysicalDisplayIdMap() const { return getHwComposer().mPhysicalDisplayIdMap; } |
| 529 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 530 | auto& mutableHasWideColorDisplay() { return SurfaceFlinger::hasWideColorDisplay; } |
| 531 | |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 532 | auto& mutableCurrentState() { return mFlinger->mCurrentState; } |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 533 | auto& mutableDisplayColorSetting() { return mFlinger->mDisplayColorSetting; } |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 534 | auto& mutableDisplays() { return mFlinger->mDisplays; } |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 535 | auto& mutableDrawingState() { return mFlinger->mDrawingState; } |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 536 | auto& mutableGeometryDirty() { return mFlinger->mGeometryDirty; } |
Lloyd Pique | 0b1fe70 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 537 | auto& mutableInterceptor() { return mFlinger->mInterceptor; } |
Lloyd Pique | 6cf1103 | 2018-01-22 18:57:44 -0800 | [diff] [blame] | 538 | auto& mutableMainThreadId() { return mFlinger->mMainThreadId; } |
Lloyd Pique | 0b1fe70 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 539 | auto& mutablePendingHotplugEvents() { return mFlinger->mPendingHotplugEvents; } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 540 | auto& mutablePhysicalDisplayTokens() { return mFlinger->mPhysicalDisplayTokens; } |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 541 | auto& mutableTexturePool() { return mFlinger->mTexturePool; } |
Lloyd Pique | 0b1fe70 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 542 | auto& mutableTransactionFlags() { return mFlinger->mTransactionFlags; } |
Lloyd Pique | 4fe2940 | 2019-08-12 16:51:24 -0700 | [diff] [blame] | 543 | auto& mutableDebugDisableHWC() { return mFlinger->mDebugDisableHWC; } |
Garfield Tan | 9c9c191 | 2021-07-19 12:02:16 -0700 | [diff] [blame] | 544 | auto& mutableMaxRenderTargetSize() { return mFlinger->mMaxRenderTargetSize; } |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 545 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 546 | auto& mutableHwcDisplayData() { return getHwComposer().mDisplayData; } |
| 547 | auto& mutableHwcPhysicalDisplayIdMap() { return getHwComposer().mPhysicalDisplayIdMap; } |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 548 | auto& mutablePrimaryHwcDisplayId() { return getHwComposer().mPrimaryHwcDisplayId; } |
Ady Abraham | adc914c | 2021-10-13 17:04:27 -0700 | [diff] [blame] | 549 | auto& mutableActiveDisplayToken() { return mFlinger->mActiveDisplayToken; } |
Lloyd Pique | a618d85 | 2018-01-17 11:52:30 -0800 | [diff] [blame] | 550 | |
Valerie Hau | 09e6005 | 2019-12-15 14:51:15 -0800 | [diff] [blame] | 551 | auto fromHandle(const sp<IBinder>& handle) { |
Valerie Hau | 09e6005 | 2019-12-15 14:51:15 -0800 | [diff] [blame] | 552 | return mFlinger->fromHandle(handle); |
| 553 | } |
| 554 | |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 555 | ~TestableSurfaceFlinger() { |
| 556 | // All these pointer and container clears help ensure that GMock does |
| 557 | // not report a leaked object, since the SurfaceFlinger instance may |
| 558 | // still be referenced by something despite our best efforts to destroy |
| 559 | // it after each test is done. |
| 560 | mutableDisplays().clear(); |
Ady Abraham | 2939f09 | 2019-03-04 17:44:06 -0800 | [diff] [blame] | 561 | mutableCurrentState().displays.clear(); |
| 562 | mutableDrawingState().displays.clear(); |
Pablo Gamito | 5cfc6e5 | 2020-09-10 11:18:03 +0000 | [diff] [blame] | 563 | mutableInterceptor().clear(); |
Lloyd Pique | 2eb71eb | 2019-08-13 13:23:03 -0700 | [diff] [blame] | 564 | mFlinger->mScheduler.reset(); |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 565 | mFlinger->mCompositionEngine->setHwComposer(std::unique_ptr<HWComposer>()); |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 566 | mFlinger->mCompositionEngine->setRenderEngine( |
| 567 | std::unique_ptr<renderengine::RenderEngine>()); |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 568 | } |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 569 | |
Lloyd Pique | a618d85 | 2018-01-17 11:52:30 -0800 | [diff] [blame] | 570 | /* ------------------------------------------------------------------------ |
| 571 | * Wrapper classes for Read-write access to private data to set up |
| 572 | * preconditions and assert post-conditions. |
| 573 | */ |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 574 | struct HWC2Display : public HWC2::impl::Display { |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 575 | HWC2Display( |
| 576 | Hwc2::Composer& composer, |
| 577 | const std::unordered_set<aidl::android::hardware::graphics::composer3::Capability>& |
| 578 | capabilities, |
| 579 | hal::HWDisplayId id, hal::DisplayType type) |
Peiyong Lin | 74ca2f4 | 2019-01-14 19:36:57 -0800 | [diff] [blame] | 580 | : HWC2::impl::Display(composer, capabilities, id, type) {} |
Lloyd Pique | a618d85 | 2018-01-17 11:52:30 -0800 | [diff] [blame] | 581 | ~HWC2Display() { |
| 582 | // Prevents a call to disable vsyncs. |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 583 | mType = hal::DisplayType::INVALID; |
Lloyd Pique | a618d85 | 2018-01-17 11:52:30 -0800 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | auto& mutableIsConnected() { return this->mIsConnected; } |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 587 | auto& mutableLayers() { return this->mLayers; } |
Lloyd Pique | a618d85 | 2018-01-17 11:52:30 -0800 | [diff] [blame] | 588 | }; |
| 589 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 590 | class FakeHwcDisplayInjector { |
| 591 | public: |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 592 | static constexpr hal::HWDisplayId DEFAULT_HWC_DISPLAY_ID = 1000; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 593 | static constexpr ui::Size DEFAULT_RESOLUTION{1920, 1280}; |
Marin Shalamanov | c7e9f82 | 2021-11-16 20:07:55 +0100 | [diff] [blame] | 594 | static constexpr int32_t DEFAULT_VSYNC_PERIOD = 16'666'667; |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 595 | static constexpr int32_t DEFAULT_CONFIG_GROUP = 7; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 596 | static constexpr int32_t DEFAULT_DPI = 320; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 597 | static constexpr hal::HWConfigId DEFAULT_ACTIVE_CONFIG = 0; |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 598 | static constexpr hal::PowerMode DEFAULT_POWER_MODE = hal::PowerMode::ON; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 599 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 600 | FakeHwcDisplayInjector(HalDisplayId displayId, hal::DisplayType hwcDisplayType, |
| 601 | bool isPrimary) |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 602 | : mDisplayId(displayId), mHwcDisplayType(hwcDisplayType), mIsPrimary(isPrimary) {} |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 603 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 604 | auto& setHwcDisplayId(hal::HWDisplayId displayId) { |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 605 | mHwcDisplayId = displayId; |
| 606 | return *this; |
| 607 | } |
| 608 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 609 | auto& setResolution(ui::Size resolution) { |
| 610 | mResolution = resolution; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 611 | return *this; |
| 612 | } |
| 613 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 614 | auto& setVsyncPeriod(nsecs_t vsyncPeriod) { |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 615 | mVsyncPeriod = vsyncPeriod; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 616 | return *this; |
| 617 | } |
| 618 | |
| 619 | auto& setDpiX(int32_t dpi) { |
| 620 | mDpiX = dpi; |
| 621 | return *this; |
| 622 | } |
| 623 | |
| 624 | auto& setDpiY(int32_t dpi) { |
| 625 | mDpiY = dpi; |
| 626 | return *this; |
| 627 | } |
| 628 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 629 | auto& setActiveConfig(hal::HWConfigId config) { |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 630 | mActiveConfig = config; |
| 631 | return *this; |
| 632 | } |
| 633 | |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 634 | auto& setCapabilities( |
| 635 | const std::unordered_set<aidl::android::hardware::graphics::composer3::Capability>* |
| 636 | capabilities) { |
Lloyd Pique | e22f033 | 2018-07-16 16:35:56 -0700 | [diff] [blame] | 637 | mCapabilities = capabilities; |
| 638 | return *this; |
| 639 | } |
| 640 | |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 641 | auto& setPowerMode(hal::PowerMode mode) { |
Peiyong Lin | 1336e6e | 2019-05-28 09:23:50 -0700 | [diff] [blame] | 642 | mPowerMode = mode; |
| 643 | return *this; |
| 644 | } |
| 645 | |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 646 | void inject(TestableSurfaceFlinger* flinger, Hwc2::mock::Composer* composer) { |
| 647 | using ::testing::_; |
| 648 | using ::testing::DoAll; |
| 649 | using ::testing::Return; |
| 650 | using ::testing::SetArgPointee; |
| 651 | |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 652 | static const std::unordered_set< |
| 653 | aidl::android::hardware::graphics::composer3::Capability> |
| 654 | defaultCapabilities; |
Lloyd Pique | e22f033 | 2018-07-16 16:35:56 -0700 | [diff] [blame] | 655 | if (mCapabilities == nullptr) mCapabilities = &defaultCapabilities; |
| 656 | |
| 657 | // Caution - Make sure that any values passed by reference here do |
| 658 | // not refer to an instance owned by FakeHwcDisplayInjector. This |
| 659 | // class has temporary lifetime, while the constructed HWC2::Display |
| 660 | // is much longer lived. |
Peiyong Lin | 74ca2f4 | 2019-01-14 19:36:57 -0800 | [diff] [blame] | 661 | auto display = std::make_unique<HWC2Display>(*composer, *mCapabilities, mHwcDisplayId, |
| 662 | mHwcDisplayType); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 663 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 664 | display->mutableIsConnected() = true; |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 665 | display->setPowerMode(mPowerMode); |
Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 666 | flinger->mutableHwcDisplayData()[mDisplayId].hwcDisplay = std::move(display); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 667 | |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 668 | EXPECT_CALL(*composer, getDisplayConfigs(mHwcDisplayId, _)) |
| 669 | .WillRepeatedly( |
| 670 | DoAll(SetArgPointee<1>(std::vector<hal::HWConfigId>{mActiveConfig}), |
| 671 | Return(hal::Error::NONE))); |
| 672 | |
| 673 | EXPECT_CALL(*composer, |
| 674 | getDisplayAttribute(mHwcDisplayId, mActiveConfig, hal::Attribute::WIDTH, _)) |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 675 | .WillRepeatedly(DoAll(SetArgPointee<3>(mResolution.getWidth()), |
| 676 | Return(hal::Error::NONE))); |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 677 | |
| 678 | EXPECT_CALL(*composer, |
| 679 | getDisplayAttribute(mHwcDisplayId, mActiveConfig, hal::Attribute::HEIGHT, |
| 680 | _)) |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 681 | .WillRepeatedly(DoAll(SetArgPointee<3>(mResolution.getHeight()), |
| 682 | Return(hal::Error::NONE))); |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 683 | |
| 684 | EXPECT_CALL(*composer, |
| 685 | getDisplayAttribute(mHwcDisplayId, mActiveConfig, |
| 686 | hal::Attribute::VSYNC_PERIOD, _)) |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 687 | .WillRepeatedly(DoAll(SetArgPointee<3>(static_cast<int32_t>(mVsyncPeriod)), |
| 688 | Return(hal::Error::NONE))); |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 689 | |
| 690 | EXPECT_CALL(*composer, |
| 691 | getDisplayAttribute(mHwcDisplayId, mActiveConfig, hal::Attribute::DPI_X, _)) |
| 692 | .WillRepeatedly(DoAll(SetArgPointee<3>(mDpiX), Return(hal::Error::NONE))); |
| 693 | |
| 694 | EXPECT_CALL(*composer, |
| 695 | getDisplayAttribute(mHwcDisplayId, mActiveConfig, hal::Attribute::DPI_Y, _)) |
| 696 | .WillRepeatedly(DoAll(SetArgPointee<3>(mDpiY), Return(hal::Error::NONE))); |
| 697 | |
| 698 | EXPECT_CALL(*composer, |
| 699 | getDisplayAttribute(mHwcDisplayId, mActiveConfig, |
| 700 | hal::Attribute::CONFIG_GROUP, _)) |
| 701 | .WillRepeatedly( |
| 702 | DoAll(SetArgPointee<3>(mConfigGroup), Return(hal::Error::NONE))); |
Marin Shalamanov | 3ea1d60 | 2020-12-16 19:59:39 +0100 | [diff] [blame] | 703 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 704 | if (mHwcDisplayType == hal::DisplayType::PHYSICAL) { |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 705 | const auto physicalId = PhysicalDisplayId::tryCast(mDisplayId); |
| 706 | LOG_ALWAYS_FATAL_IF(!physicalId); |
| 707 | flinger->mutableHwcPhysicalDisplayIdMap().emplace(mHwcDisplayId, *physicalId); |
Marin Shalamanov | 6e84017 | 2020-12-14 22:13:28 +0100 | [diff] [blame] | 708 | if (mIsPrimary) { |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 709 | flinger->mutablePrimaryHwcDisplayId() = mHwcDisplayId; |
Marin Shalamanov | 6e84017 | 2020-12-14 22:13:28 +0100 | [diff] [blame] | 710 | } else { |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 711 | // 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] | 712 | // as well. Set it to some arbitrary value. |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 713 | auto& primaryId = flinger->mutablePrimaryHwcDisplayId(); |
| 714 | if (!primaryId) primaryId = mHwcDisplayId - 1; |
Marin Shalamanov | 6e84017 | 2020-12-14 22:13:28 +0100 | [diff] [blame] | 715 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 716 | } |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | private: |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 720 | const HalDisplayId mDisplayId; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 721 | const hal::DisplayType mHwcDisplayType; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 722 | const bool mIsPrimary; |
| 723 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 724 | hal::HWDisplayId mHwcDisplayId = DEFAULT_HWC_DISPLAY_ID; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 725 | ui::Size mResolution = DEFAULT_RESOLUTION; |
| 726 | nsecs_t mVsyncPeriod = DEFAULT_VSYNC_PERIOD; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 727 | int32_t mDpiX = DEFAULT_DPI; |
| 728 | int32_t mDpiY = DEFAULT_DPI; |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 729 | int32_t mConfigGroup = DEFAULT_CONFIG_GROUP; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 730 | hal::HWConfigId mActiveConfig = DEFAULT_ACTIVE_CONFIG; |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 731 | hal::PowerMode mPowerMode = DEFAULT_POWER_MODE; |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 732 | const std::unordered_set<aidl::android::hardware::graphics::composer3::Capability>* |
| 733 | mCapabilities = nullptr; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 734 | }; |
| 735 | |
| 736 | class FakeDisplayDeviceInjector { |
| 737 | public: |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 738 | FakeDisplayDeviceInjector(TestableSurfaceFlinger& flinger, |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 739 | std::shared_ptr<compositionengine::Display> display, |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 740 | std::optional<ui::DisplayConnectionType> connectionType, |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 741 | std::optional<hal::HWDisplayId> hwcDisplayId, bool isPrimary) |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 742 | : mFlinger(flinger), |
Marin Shalamanov | 12c9e5a | 2021-01-07 00:25:35 +0100 | [diff] [blame] | 743 | mCreationArgs(flinger.mFlinger.get(), flinger.mFlinger->getHwComposer(), |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 744 | mDisplayToken, display), |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 745 | mHwcDisplayId(hwcDisplayId) { |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 746 | mCreationArgs.connectionType = connectionType; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 747 | mCreationArgs.isPrimary = isPrimary; |
| 748 | } |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 749 | |
| 750 | sp<IBinder> token() const { return mDisplayToken; } |
| 751 | |
| 752 | DisplayDeviceState& mutableDrawingDisplayState() { |
| 753 | return mFlinger.mutableDrawingState().displays.editValueFor(mDisplayToken); |
| 754 | } |
| 755 | |
| 756 | DisplayDeviceState& mutableCurrentDisplayState() { |
| 757 | return mFlinger.mutableCurrentState().displays.editValueFor(mDisplayToken); |
| 758 | } |
| 759 | |
Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 760 | const auto& getDrawingDisplayState() { |
| 761 | return mFlinger.mutableDrawingState().displays.valueFor(mDisplayToken); |
| 762 | } |
| 763 | |
| 764 | const auto& getCurrentDisplayState() { |
| 765 | return mFlinger.mutableCurrentState().displays.valueFor(mDisplayToken); |
| 766 | } |
| 767 | |
Dominik Laskowski | eb62731 | 2022-04-07 09:13:16 -0700 | [diff] [blame] | 768 | const sp<DisplayDevice>& mutableDisplayDevice() { |
| 769 | return mFlinger.mutableDisplays().get(mDisplayToken)->get(); |
| 770 | } |
Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 771 | |
Dominik Laskowski | 83bd771 | 2022-01-07 14:30:53 -0800 | [diff] [blame] | 772 | // If `configs` is nullptr, the injector creates RefreshRateConfigs from the `modes`. |
| 773 | // Otherwise, it uses `configs`, which the caller must create using the same `modes`. |
| 774 | // |
| 775 | // TODO(b/182939859): Once `modes` can be retrieved from RefreshRateConfigs, remove |
| 776 | // the `configs` parameter in favor of an alternative setRefreshRateConfigs API. |
| 777 | auto& setDisplayModes(DisplayModes modes, DisplayModeId activeModeId, |
| 778 | std::shared_ptr<scheduler::RefreshRateConfigs> configs = nullptr) { |
| 779 | mCreationArgs.supportedModes = std::move(modes); |
| 780 | mCreationArgs.activeModeId = activeModeId; |
| 781 | mCreationArgs.refreshRateConfigs = std::move(configs); |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 782 | return *this; |
| 783 | } |
| 784 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 785 | auto& setNativeWindow(const sp<ANativeWindow>& nativeWindow) { |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 786 | mCreationArgs.nativeWindow = nativeWindow; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 787 | return *this; |
| 788 | } |
| 789 | |
Lloyd Pique | 542307f | 2018-10-19 13:24:08 -0700 | [diff] [blame] | 790 | auto& setDisplaySurface(const sp<compositionengine::DisplaySurface>& displaySurface) { |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 791 | mCreationArgs.displaySurface = displaySurface; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 792 | return *this; |
| 793 | } |
| 794 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 795 | auto& setSecure(bool secure) { |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 796 | mCreationArgs.isSecure = secure; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 797 | return *this; |
| 798 | } |
| 799 | |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 800 | auto& setPowerMode(hal::PowerMode mode) { |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 801 | mCreationArgs.initialPowerMode = mode; |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 802 | return *this; |
| 803 | } |
| 804 | |
Valerie Hau | 9758ae0 | 2018-10-09 16:05:09 -0700 | [diff] [blame] | 805 | auto& setHwcColorModes( |
| 806 | const std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>> |
| 807 | hwcColorModes) { |
| 808 | mCreationArgs.hwcColorModes = hwcColorModes; |
| 809 | return *this; |
| 810 | } |
| 811 | |
| 812 | auto& setHasWideColorGamut(bool hasWideColorGamut) { |
| 813 | mCreationArgs.hasWideColorGamut = hasWideColorGamut; |
| 814 | return *this; |
| 815 | } |
| 816 | |
Lloyd Pique | 3305047 | 2019-12-19 17:12:44 -0800 | [diff] [blame] | 817 | auto& setPhysicalOrientation(ui::Rotation orientation) { |
| 818 | mCreationArgs.physicalOrientation = orientation; |
| 819 | return *this; |
| 820 | } |
| 821 | |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 822 | sp<DisplayDevice> inject() NO_THREAD_SAFETY_ANALYSIS { |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 823 | const auto displayId = mCreationArgs.compositionDisplay->getDisplayId(); |
| 824 | |
Dominik Laskowski | 83bd771 | 2022-01-07 14:30:53 -0800 | [diff] [blame] | 825 | auto& modes = mCreationArgs.supportedModes; |
| 826 | auto& activeModeId = mCreationArgs.activeModeId; |
| 827 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 828 | if (displayId && !mCreationArgs.refreshRateConfigs) { |
| 829 | if (const auto physicalId = PhysicalDisplayId::tryCast(*displayId)) { |
| 830 | if (modes.empty()) { |
| 831 | constexpr DisplayModeId kModeId{0}; |
| 832 | DisplayModePtr mode = |
| 833 | DisplayMode::Builder(FakeHwcDisplayInjector::DEFAULT_ACTIVE_CONFIG) |
| 834 | .setId(kModeId) |
| 835 | .setPhysicalDisplayId(*physicalId) |
| 836 | .setResolution(FakeHwcDisplayInjector::DEFAULT_RESOLUTION) |
| 837 | .setVsyncPeriod( |
| 838 | FakeHwcDisplayInjector::DEFAULT_VSYNC_PERIOD) |
| 839 | .setDpiX(FakeHwcDisplayInjector::DEFAULT_DPI) |
| 840 | .setDpiY(FakeHwcDisplayInjector::DEFAULT_DPI) |
| 841 | .setGroup(FakeHwcDisplayInjector::DEFAULT_CONFIG_GROUP) |
| 842 | .build(); |
Dominik Laskowski | 83bd771 | 2022-01-07 14:30:53 -0800 | [diff] [blame] | 843 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 844 | modes = ftl::init::map(kModeId, std::move(mode)); |
| 845 | activeModeId = kModeId; |
| 846 | } |
| 847 | |
| 848 | mCreationArgs.refreshRateConfigs = |
| 849 | std::make_shared<scheduler::RefreshRateConfigs>(modes, activeModeId); |
| 850 | } |
Dominik Laskowski | 83bd771 | 2022-01-07 14:30:53 -0800 | [diff] [blame] | 851 | } |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 852 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 853 | DisplayDeviceState state; |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 854 | if (const auto type = mCreationArgs.connectionType) { |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 855 | LOG_ALWAYS_FATAL_IF(!displayId); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 856 | const auto physicalId = PhysicalDisplayId::tryCast(*displayId); |
| 857 | LOG_ALWAYS_FATAL_IF(!physicalId); |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 858 | LOG_ALWAYS_FATAL_IF(!mHwcDisplayId); |
Marin Shalamanov | c7e9f82 | 2021-11-16 20:07:55 +0100 | [diff] [blame] | 859 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 860 | const auto activeMode = modes.get(activeModeId); |
| 861 | LOG_ALWAYS_FATAL_IF(!activeMode); |
Dominik Laskowski | 83bd771 | 2022-01-07 14:30:53 -0800 | [diff] [blame] | 862 | |
Marin Shalamanov | c7e9f82 | 2021-11-16 20:07:55 +0100 | [diff] [blame] | 863 | state.physical = {.id = *physicalId, |
| 864 | .type = *type, |
| 865 | .hwcDisplayId = *mHwcDisplayId, |
| 866 | .deviceProductInfo = {}, |
Dominik Laskowski | 83bd771 | 2022-01-07 14:30:53 -0800 | [diff] [blame] | 867 | .supportedModes = modes, |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 868 | .activeMode = activeMode->get()}; |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 869 | } |
| 870 | |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 871 | state.isSecure = mCreationArgs.isSecure; |
| 872 | |
Dominik Laskowski | 83bd771 | 2022-01-07 14:30:53 -0800 | [diff] [blame] | 873 | sp<DisplayDevice> display = sp<DisplayDevice>::make(mCreationArgs); |
| 874 | if (!display->isVirtual()) { |
| 875 | display->setActiveMode(activeModeId); |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 876 | } |
Dominik Laskowski | eb62731 | 2022-04-07 09:13:16 -0700 | [diff] [blame] | 877 | mFlinger.mutableDisplays().emplace_or_replace(mDisplayToken, display); |
| 878 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 879 | mFlinger.mutableCurrentState().displays.add(mDisplayToken, state); |
| 880 | mFlinger.mutableDrawingState().displays.add(mDisplayToken, state); |
| 881 | |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 882 | if (const auto& physical = state.physical) { |
Dominik Laskowski | eb62731 | 2022-04-07 09:13:16 -0700 | [diff] [blame] | 883 | mFlinger.mutablePhysicalDisplayTokens().emplace_or_replace(physical->id, |
| 884 | mDisplayToken); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 885 | } |
| 886 | |
Dominik Laskowski | 83bd771 | 2022-01-07 14:30:53 -0800 | [diff] [blame] | 887 | return display; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 888 | } |
| 889 | |
| 890 | private: |
| 891 | TestableSurfaceFlinger& mFlinger; |
| 892 | sp<BBinder> mDisplayToken = new BBinder(); |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 893 | DisplayDeviceCreationArgs mCreationArgs; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 894 | const std::optional<hal::HWDisplayId> mHwcDisplayId; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 895 | }; |
| 896 | |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 897 | private: |
Ady Abraham | 302ebed | 2022-03-07 16:03:41 -0800 | [diff] [blame] | 898 | constexpr static int64_t kVsyncId = 123; |
| 899 | |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 900 | surfaceflinger::test::Factory mFactory; |
Vishnu Nair | 4df8eb6 | 2022-02-17 15:32:02 -0800 | [diff] [blame] | 901 | sp<SurfaceFlinger> mFlinger; |
Dominik Laskowski | 83bd771 | 2022-01-07 14:30:53 -0800 | [diff] [blame] | 902 | scheduler::mock::SchedulerCallback mSchedulerCallback; |
| 903 | scheduler::mock::NoOpSchedulerCallback mNoOpSchedulerCallback; |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 904 | scheduler::TestableScheduler* mScheduler = nullptr; |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 905 | }; |
| 906 | |
| 907 | } // namespace android |