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