Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #pragma once |
| 18 | |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 19 | #include <compositionengine/Display.h> |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 20 | #include <compositionengine/LayerFECompositionState.h> |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 21 | #include <compositionengine/OutputLayer.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 22 | #include <compositionengine/impl/CompositionEngine.h> |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 23 | #include <compositionengine/impl/Display.h> |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 24 | #include <compositionengine/impl/OutputLayerCompositionState.h> |
Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 25 | #include <compositionengine/mock/DisplaySurface.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 26 | |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 27 | #include "BufferQueueLayer.h" |
| 28 | #include "BufferStateLayer.h" |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 29 | #include "ContainerLayer.h" |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 30 | #include "DisplayDevice.h" |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame] | 31 | #include "EffectLayer.h" |
Ady Abraham | c581d3c | 2020-08-06 17:34:27 -0700 | [diff] [blame] | 32 | #include "FakeVsyncConfiguration.h" |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 33 | #include "Layer.h" |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 34 | #include "NativeWindowSurface.h" |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 35 | #include "Scheduler/MessageQueue.h" |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 36 | #include "Scheduler/RefreshRateConfigs.h" |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 37 | #include "StartPropertySetThread.h" |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 38 | #include "SurfaceFlinger.h" |
Lloyd Pique | 24f3bfe | 2019-10-02 19:29:10 -0700 | [diff] [blame] | 39 | #include "SurfaceFlingerDefaultFactory.h" |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 40 | #include "SurfaceInterceptor.h" |
Dominik Laskowski | 7c9dbf9 | 2019-08-01 17:57:31 -0700 | [diff] [blame] | 41 | #include "TestableScheduler.h" |
Ady Abraham | abc2760 | 2020-04-08 17:20:29 -0700 | [diff] [blame] | 42 | #include "mock/DisplayHardware/MockDisplay.h" |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 43 | #include "mock/MockDisplayIdGenerator.h" |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame] | 44 | |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 45 | namespace android { |
| 46 | |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 47 | class EventThread; |
| 48 | |
Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 49 | namespace renderengine { |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 50 | |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 51 | class RenderEngine; |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 52 | |
| 53 | } // namespace renderengine |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 54 | |
| 55 | namespace Hwc2 { |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 56 | |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 57 | class Composer; |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 58 | |
| 59 | } // namespace Hwc2 |
| 60 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 61 | namespace hal = android::hardware::graphics::composer::hal; |
| 62 | |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 63 | namespace surfaceflinger::test { |
| 64 | |
| 65 | class Factory final : public surfaceflinger::Factory { |
| 66 | public: |
| 67 | ~Factory() = default; |
| 68 | |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 69 | std::unique_ptr<HWComposer> createHWComposer(const std::string&) override { |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 70 | return nullptr; |
| 71 | } |
| 72 | |
| 73 | std::unique_ptr<MessageQueue> createMessageQueue() override { |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 74 | return std::make_unique<android::impl::MessageQueue>(); |
| 75 | } |
| 76 | |
Ady Abraham | 8287e85 | 2020-08-12 14:44:58 -0700 | [diff] [blame] | 77 | std::unique_ptr<scheduler::VsyncConfiguration> createVsyncConfiguration( |
Ady Abraham | 9e16a48 | 2019-12-03 17:19:41 -0800 | [diff] [blame] | 78 | const scheduler::RefreshRateConfigs& /*refreshRateConfigs*/) override { |
Ana Krulec | 757f63a | 2019-01-25 10:46:18 -0800 | [diff] [blame] | 79 | return std::make_unique<scheduler::FakePhaseOffsets>(); |
| 80 | } |
| 81 | |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 82 | std::unique_ptr<Scheduler> createScheduler(const scheduler::RefreshRateConfigs&, |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 83 | ISchedulerCallback&) override { |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 84 | return nullptr; |
| 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 | |
| 151 | using CreateBufferQueueFunction = |
| 152 | std::function<void(sp<IGraphicBufferProducer>* /* outProducer */, |
| 153 | sp<IGraphicBufferConsumer>* /* outConsumer */, |
| 154 | bool /* consumerIsSurfaceFlinger */)>; |
| 155 | CreateBufferQueueFunction mCreateBufferQueue; |
| 156 | |
| 157 | using CreateNativeWindowSurfaceFunction = |
| 158 | std::function<std::unique_ptr<surfaceflinger::NativeWindowSurface>( |
| 159 | const sp<IGraphicBufferProducer>&)>; |
| 160 | CreateNativeWindowSurfaceFunction mCreateNativeWindowSurface; |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 161 | |
| 162 | using CreateCompositionEngineFunction = |
| 163 | std::function<std::unique_ptr<compositionengine::CompositionEngine>()>; |
| 164 | CreateCompositionEngineFunction mCreateCompositionEngine; |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 165 | }; |
| 166 | |
| 167 | } // namespace surfaceflinger::test |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 168 | |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 169 | class TestableSurfaceFlinger final : private ISchedulerCallback { |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 170 | public: |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 171 | using HotplugEvent = SurfaceFlinger::HotplugEvent; |
| 172 | |
Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 173 | SurfaceFlinger* flinger() { return mFlinger.get(); } |
Dominik Laskowski | 7c9dbf9 | 2019-08-01 17:57:31 -0700 | [diff] [blame] | 174 | TestableScheduler* scheduler() { return mScheduler; } |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 175 | mock::DisplayIdGenerator<GpuVirtualDisplayId>& gpuVirtualDisplayIdGenerator() { |
| 176 | return mGpuVirtualDisplayIdGenerator; |
| 177 | } |
Dominik Laskowski | 7c9dbf9 | 2019-08-01 17:57:31 -0700 | [diff] [blame] | 178 | |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 179 | // Extend this as needed for accessing SurfaceFlinger private (and public) |
| 180 | // functions. |
| 181 | |
Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 182 | void setupRenderEngine(std::unique_ptr<renderengine::RenderEngine> renderEngine) { |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 183 | mFlinger->mCompositionEngine->setRenderEngine(std::move(renderEngine)); |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | void setupComposer(std::unique_ptr<Hwc2::Composer> composer) { |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 187 | mFlinger->mCompositionEngine->setHwComposer( |
| 188 | std::make_unique<impl::HWComposer>(std::move(composer))); |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 189 | } |
| 190 | |
Alec Mouri | e4034bb | 2019-11-19 12:45:54 -0800 | [diff] [blame] | 191 | void setupTimeStats(const std::shared_ptr<TimeStats>& timeStats) { |
| 192 | mFlinger->mCompositionEngine->setTimeStats(timeStats); |
| 193 | } |
| 194 | |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 195 | // The ISchedulerCallback argument can be nullptr for a no-op implementation. |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 196 | void setupScheduler(std::unique_ptr<scheduler::VsyncController> vsyncController, |
| 197 | std::unique_ptr<scheduler::VSyncTracker> vsyncTracker, |
Dominik Laskowski | 7c9dbf9 | 2019-08-01 17:57:31 -0700 | [diff] [blame] | 198 | std::unique_ptr<EventThread> appEventThread, |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 199 | std::unique_ptr<EventThread> sfEventThread, |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 200 | ISchedulerCallback* callback = nullptr, bool hasMultipleConfigs = false) { |
Ady Abraham | abc2760 | 2020-04-08 17:20:29 -0700 | [diff] [blame] | 201 | std::vector<std::shared_ptr<const HWC2::Display::Config>> configs{ |
| 202 | HWC2::Display::Config::Builder(mDisplay, 0) |
Dominik Laskowski | 983f2b5 | 2020-06-25 16:54:06 -0700 | [diff] [blame] | 203 | .setVsyncPeriod(16'666'667) |
Ady Abraham | abc2760 | 2020-04-08 17:20:29 -0700 | [diff] [blame] | 204 | .setConfigGroup(0) |
| 205 | .build()}; |
| 206 | |
Dominik Laskowski | 983f2b5 | 2020-06-25 16:54:06 -0700 | [diff] [blame] | 207 | if (hasMultipleConfigs) { |
| 208 | configs.emplace_back(HWC2::Display::Config::Builder(mDisplay, 1) |
| 209 | .setVsyncPeriod(11'111'111) |
| 210 | .setConfigGroup(0) |
| 211 | .build()); |
| 212 | } |
| 213 | |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 214 | mFlinger->mRefreshRateConfigs = std::make_unique< |
Ana Krulec | 3f6a206 | 2020-01-23 15:48:01 -0800 | [diff] [blame] | 215 | scheduler::RefreshRateConfigs>(configs, /*currentConfig=*/HwcConfigIndexType(0)); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 216 | mFlinger->mRefreshRateStats = std::make_unique< |
| 217 | scheduler::RefreshRateStats>(*mFlinger->mRefreshRateConfigs, *mFlinger->mTimeStats, |
| 218 | /*currentConfig=*/HwcConfigIndexType(0), |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 219 | /*powerMode=*/hal::PowerMode::OFF); |
Ady Abraham | 8287e85 | 2020-08-12 14:44:58 -0700 | [diff] [blame] | 220 | mFlinger->mVsyncConfiguration = |
| 221 | mFactory.createVsyncConfiguration(*mFlinger->mRefreshRateConfigs); |
| 222 | mFlinger->mVsyncModulator.emplace(mFlinger->mVsyncConfiguration->getCurrentConfigs()); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 223 | |
Dominik Laskowski | 983f2b5 | 2020-06-25 16:54:06 -0700 | [diff] [blame] | 224 | constexpr bool kUseContentDetectionV2 = false; |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 225 | mScheduler = new TestableScheduler(std::move(vsyncController), std::move(vsyncTracker), |
| 226 | *mFlinger->mRefreshRateConfigs, *(callback ?: this), |
| 227 | kUseContentDetectionV2); |
Dominik Laskowski | 7c9dbf9 | 2019-08-01 17:57:31 -0700 | [diff] [blame] | 228 | |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 229 | mFlinger->mAppConnectionHandle = mScheduler->createConnection(std::move(appEventThread)); |
| 230 | mFlinger->mSfConnectionHandle = mScheduler->createConnection(std::move(sfEventThread)); |
Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 231 | resetScheduler(mScheduler); |
Dominik Laskowski | 7c9dbf9 | 2019-08-01 17:57:31 -0700 | [diff] [blame] | 232 | } |
| 233 | |
Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 234 | void resetScheduler(Scheduler* scheduler) { mFlinger->mScheduler.reset(scheduler); } |
| 235 | |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 236 | using CreateBufferQueueFunction = surfaceflinger::test::Factory::CreateBufferQueueFunction; |
Lloyd Pique | 5b36f3f | 2018-01-17 11:57:07 -0800 | [diff] [blame] | 237 | void setCreateBufferQueueFunction(CreateBufferQueueFunction f) { |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 238 | mFactory.mCreateBufferQueue = f; |
Lloyd Pique | 5b36f3f | 2018-01-17 11:57:07 -0800 | [diff] [blame] | 239 | } |
| 240 | |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 241 | using CreateNativeWindowSurfaceFunction = |
| 242 | surfaceflinger::test::Factory::CreateNativeWindowSurfaceFunction; |
Lloyd Pique | 0b1fe70 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 243 | void setCreateNativeWindowSurface(CreateNativeWindowSurfaceFunction f) { |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 244 | mFactory.mCreateNativeWindowSurface = f; |
Lloyd Pique | 0b1fe70 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 245 | } |
| 246 | |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 247 | void setInternalDisplayPrimaries(const ui::DisplayPrimaries& primaries) { |
| 248 | memcpy(&mFlinger->mInternalDisplayPrimaries, &primaries, sizeof(ui::DisplayPrimaries)); |
| 249 | } |
| 250 | |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 251 | static auto& mutableLayerCurrentState(const sp<Layer>& layer) { return layer->mCurrentState; } |
| 252 | static auto& mutableLayerDrawingState(const sp<Layer>& layer) { return layer->mDrawingState; } |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 253 | |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 254 | auto& mutableStateLock() { return mFlinger->mStateLock; } |
| 255 | |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 256 | static auto findOutputLayerForDisplay(const sp<Layer>& layer, |
| 257 | const sp<const DisplayDevice>& display) { |
| 258 | return layer->findOutputLayerForDisplay(display.get()); |
| 259 | } |
| 260 | |
| 261 | static void setLayerSidebandStream(const sp<Layer>& layer, |
| 262 | const sp<NativeHandle>& sidebandStream) { |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 263 | layer->mDrawingState.sidebandStream = sidebandStream; |
Lloyd Pique | 0b785d8 | 2018-12-04 17:25:27 -0800 | [diff] [blame] | 264 | layer->mSidebandStream = sidebandStream; |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 265 | layer->editCompositionState()->sidebandStream = sidebandStream; |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 266 | } |
| 267 | |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 268 | void setLayerCompositionType(const sp<Layer>& layer, hal::Composition type) { |
| 269 | auto outputLayer = findOutputLayerForDisplay(layer, mFlinger->getDefaultDisplayDevice()); |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 270 | LOG_ALWAYS_FATAL_IF(!outputLayer); |
| 271 | auto& state = outputLayer->editState(); |
| 272 | LOG_ALWAYS_FATAL_IF(!outputLayer->getState().hwc); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 273 | (*state.hwc).hwcCompositionType = type; |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 274 | } |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 275 | |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 276 | static void setLayerPotentialCursor(const sp<Layer>& layer, bool potentialCursor) { |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 277 | layer->mPotentialCursor = potentialCursor; |
| 278 | } |
| 279 | |
Garfield Tan | de619fa | 2020-10-02 17:13:53 -0700 | [diff] [blame] | 280 | static void setLayerDrawingParent(const sp<Layer>& layer, const sp<Layer>& drawingParent) { |
| 281 | layer->mDrawingParent = drawingParent; |
| 282 | } |
| 283 | |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 284 | /* ------------------------------------------------------------------------ |
| 285 | * Forwarding for functions being tested |
| 286 | */ |
Lloyd Pique | 0b1fe70 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 287 | |
Lloyd Pique | a482f99 | 2018-01-22 19:00:34 -0800 | [diff] [blame] | 288 | auto createDisplay(const String8& displayName, bool secure) { |
| 289 | return mFlinger->createDisplay(displayName, secure); |
| 290 | } |
| 291 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 292 | auto destroyDisplay(const sp<IBinder>& displayToken) { |
| 293 | return mFlinger->destroyDisplay(displayToken); |
| 294 | } |
Lloyd Pique | a482f99 | 2018-01-22 19:00:34 -0800 | [diff] [blame] | 295 | |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 296 | auto setupNewDisplayDeviceInternal( |
| 297 | const wp<IBinder>& displayToken, |
| 298 | std::shared_ptr<compositionengine::Display> compositionDisplay, |
| 299 | const DisplayDeviceState& state, |
| 300 | const sp<compositionengine::DisplaySurface>& dispSurface, |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 301 | const sp<IGraphicBufferProducer>& producer) NO_THREAD_SAFETY_ANALYSIS { |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 302 | return mFlinger->setupNewDisplayDeviceInternal(displayToken, compositionDisplay, state, |
| 303 | dispSurface, producer); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 304 | } |
| 305 | |
Lloyd Pique | 0b1fe70 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 306 | auto handleTransactionLocked(uint32_t transactionFlags) { |
Vishnu Nair | fa5f8df | 2019-02-13 17:02:51 -0800 | [diff] [blame] | 307 | Mutex::Autolock _l(mFlinger->mStateLock); |
Lloyd Pique | 0b1fe70 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 308 | return mFlinger->handleTransactionLocked(transactionFlags); |
| 309 | } |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 310 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 311 | auto onHotplugReceived(int32_t sequenceId, hal::HWDisplayId display, |
| 312 | hal::Connection connection) { |
Lloyd Pique | 6cf1103 | 2018-01-22 18:57:44 -0800 | [diff] [blame] | 313 | return mFlinger->onHotplugReceived(sequenceId, display, connection); |
| 314 | } |
| 315 | |
Vishnu Nair | ce5d0cc | 2019-02-28 14:38:41 -0800 | [diff] [blame] | 316 | auto setDisplayStateLocked(const DisplayState& s) { |
| 317 | Mutex::Autolock _l(mFlinger->mStateLock); |
| 318 | return mFlinger->setDisplayStateLocked(s); |
| 319 | } |
Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 320 | |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 321 | // Allow reading display state without locking, as if called on the SF main thread. |
| 322 | auto onInitializeDisplays() NO_THREAD_SAFETY_ANALYSIS { |
| 323 | return mFlinger->onInitializeDisplays(); |
| 324 | } |
Lloyd Pique | 86016da | 2018-03-01 16:09:38 -0800 | [diff] [blame] | 325 | |
Lais Andrade | 3a6e47d | 2020-04-02 11:20:16 +0100 | [diff] [blame] | 326 | auto notifyPowerBoost(int32_t boostId) { return mFlinger->notifyPowerBoost(boostId); } |
| 327 | |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 328 | // Allow reading display state without locking, as if called on the SF main thread. |
| 329 | auto setPowerModeInternal(const sp<DisplayDevice>& display, |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 330 | hal::PowerMode mode) NO_THREAD_SAFETY_ANALYSIS { |
Dominik Laskowski | e977409 | 2018-12-11 10:04:24 -0800 | [diff] [blame] | 331 | return mFlinger->setPowerModeInternal(display, mode); |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 332 | } |
| 333 | |
Adithya Srinivasan | 5f683cf | 2020-09-15 14:21:04 -0700 | [diff] [blame] | 334 | auto onMessageReceived(int32_t what) { |
| 335 | return mFlinger->onMessageReceived(what, /*vsyncId=*/0, systemTime()); |
| 336 | } |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 337 | |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 338 | auto renderScreenImplLocked(const RenderArea& renderArea, |
| 339 | SurfaceFlinger::TraverseLayersFunction traverseLayers, |
chaviw | c6ad8af | 2020-08-03 11:33:30 -0700 | [diff] [blame] | 340 | const sp<GraphicBuffer>& buffer, bool forSystem, int* outSyncFd, |
| 341 | bool regionSampling) { |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 342 | ScreenCaptureResults captureResults; |
chaviw | c6ad8af | 2020-08-03 11:33:30 -0700 | [diff] [blame] | 343 | return mFlinger->renderScreenImplLocked(renderArea, traverseLayers, buffer, forSystem, |
| 344 | outSyncFd, regionSampling, captureResults); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 345 | } |
| 346 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 347 | auto traverseLayersInLayerStack(ui::LayerStack layerStack, int32_t uid, |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 348 | const LayerVector::Visitor& visitor) { |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 349 | return mFlinger->SurfaceFlinger::traverseLayersInLayerStack(layerStack, uid, visitor); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 350 | } |
| 351 | |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 352 | auto getDisplayNativePrimaries(const sp<IBinder>& displayToken, |
| 353 | ui::DisplayPrimaries &primaries) { |
| 354 | return mFlinger->SurfaceFlinger::getDisplayNativePrimaries(displayToken, primaries); |
| 355 | } |
| 356 | |
Arthur Hung | 1bedccb | 2020-09-24 10:09:25 +0000 | [diff] [blame] | 357 | auto& getTransactionQueue() { return mFlinger->mTransactionQueues; } |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 358 | |
Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 359 | auto setTransactionState(int64_t frameTimelineVsyncId, const Vector<ComposerState>& states, |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 360 | const Vector<DisplayState>& displays, uint32_t flags, |
| 361 | const sp<IBinder>& applyToken, |
| 362 | const InputWindowCommands& inputWindowCommands, |
| 363 | int64_t desiredPresentTime, const client_cache_t& uncacheBuffer, |
| 364 | bool hasListenerCallbacks, |
Pablo Gamito | 7eb7ee7 | 2020-08-05 10:57:05 +0000 | [diff] [blame] | 365 | std::vector<ListenerCallbacks>& listenerCallbacks, |
| 366 | uint64_t transactionId) { |
Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 367 | return mFlinger->setTransactionState(frameTimelineVsyncId, states, displays, flags, |
| 368 | applyToken, inputWindowCommands, desiredPresentTime, |
| 369 | uncacheBuffer, hasListenerCallbacks, listenerCallbacks, |
Pablo Gamito | 7eb7ee7 | 2020-08-05 10:57:05 +0000 | [diff] [blame] | 370 | transactionId); |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 371 | } |
| 372 | |
Arthur Hung | 1bedccb | 2020-09-24 10:09:25 +0000 | [diff] [blame] | 373 | auto flushTransactionQueues() { return mFlinger->flushTransactionQueues(); }; |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 374 | |
Eduardo Rocha | ac86719 | 2020-09-14 20:12:17 +0000 | [diff] [blame] | 375 | auto onTransact(uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) { |
| 376 | return mFlinger->onTransact(code, data, reply, flags); |
| 377 | } |
| 378 | |
Lloyd Pique | 86016da | 2018-03-01 16:09:38 -0800 | [diff] [blame] | 379 | /* ------------------------------------------------------------------------ |
| 380 | * Read-only access to private data to assert post-conditions. |
| 381 | */ |
| 382 | |
| 383 | const auto& getAnimFrameTracker() const { return mFlinger->mAnimFrameTracker; } |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 384 | const auto& getHasPoweredOff() const { return mFlinger->mHasPoweredOff; } |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 385 | const auto& getVisibleRegionsDirty() const { return mFlinger->mVisibleRegionsDirty; } |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 386 | auto& getHwComposer() const { |
| 387 | return static_cast<impl::HWComposer&>(mFlinger->getHwComposer()); |
| 388 | } |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 389 | auto& getCompositionEngine() const { return mFlinger->getCompositionEngine(); } |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 390 | |
Lloyd Pique | 86016da | 2018-03-01 16:09:38 -0800 | [diff] [blame] | 391 | const auto& getCompositorTiming() const { return mFlinger->getBE().mCompositorTiming; } |
| 392 | |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 393 | /* ------------------------------------------------------------------------ |
| 394 | * Read-write access to private data to set up preconditions and assert |
| 395 | * post-conditions. |
| 396 | */ |
Lloyd Pique | 0b1fe70 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 397 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 398 | auto& mutableHasWideColorDisplay() { return SurfaceFlinger::hasWideColorDisplay; } |
Peiyong Lin | 13effd1 | 2018-07-24 17:01:47 -0700 | [diff] [blame] | 399 | auto& mutableUseColorManagement() { return SurfaceFlinger::useColorManagement; } |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 400 | |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 401 | auto& mutableCurrentState() { return mFlinger->mCurrentState; } |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 402 | auto& mutableDisplayColorSetting() { return mFlinger->mDisplayColorSetting; } |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 403 | auto& mutableDisplays() { return mFlinger->mDisplays; } |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 404 | auto& mutableDrawingState() { return mFlinger->mDrawingState; } |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 405 | auto& mutableEventQueue() { return mFlinger->mEventQueue; } |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 406 | auto& mutableGeometryInvalid() { return mFlinger->mGeometryInvalid; } |
Lloyd Pique | 0b1fe70 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 407 | auto& mutableInterceptor() { return mFlinger->mInterceptor; } |
Lloyd Pique | 6cf1103 | 2018-01-22 18:57:44 -0800 | [diff] [blame] | 408 | auto& mutableMainThreadId() { return mFlinger->mMainThreadId; } |
Lloyd Pique | 0b1fe70 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 409 | auto& mutablePendingHotplugEvents() { return mFlinger->mPendingHotplugEvents; } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 410 | auto& mutablePhysicalDisplayTokens() { return mFlinger->mPhysicalDisplayTokens; } |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 411 | auto& mutableTexturePool() { return mFlinger->mTexturePool; } |
Lloyd Pique | 0b1fe70 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 412 | auto& mutableTransactionFlags() { return mFlinger->mTransactionFlags; } |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 413 | auto& mutableUseHwcVirtualDisplays() { return mFlinger->mUseHwcVirtualDisplays; } |
Peiyong Lin | 74ca2f4 | 2019-01-14 19:36:57 -0800 | [diff] [blame] | 414 | auto& mutablePowerAdvisor() { return mFlinger->mPowerAdvisor; } |
Lloyd Pique | 4fe2940 | 2019-08-12 16:51:24 -0700 | [diff] [blame] | 415 | auto& mutableDebugDisableHWC() { return mFlinger->mDebugDisableHWC; } |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 416 | |
Lloyd Pique | 6cf1103 | 2018-01-22 18:57:44 -0800 | [diff] [blame] | 417 | auto& mutableComposerSequenceId() { return mFlinger->getBE().mComposerSequenceId; } |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 418 | auto& mutableHwcDisplayData() { return getHwComposer().mDisplayData; } |
| 419 | auto& mutableHwcPhysicalDisplayIdMap() { return getHwComposer().mPhysicalDisplayIdMap; } |
| 420 | auto& mutableInternalHwcDisplayId() { return getHwComposer().mInternalHwcDisplayId; } |
| 421 | auto& mutableExternalHwcDisplayId() { return getHwComposer().mExternalHwcDisplayId; } |
Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 422 | auto& mutableUseFrameRateApi() { return mFlinger->useFrameRateApi; } |
Lloyd Pique | a618d85 | 2018-01-17 11:52:30 -0800 | [diff] [blame] | 423 | |
Valerie Hau | 09e6005 | 2019-12-15 14:51:15 -0800 | [diff] [blame] | 424 | auto fromHandle(const sp<IBinder>& handle) { |
Valerie Hau | 09e6005 | 2019-12-15 14:51:15 -0800 | [diff] [blame] | 425 | return mFlinger->fromHandle(handle); |
| 426 | } |
| 427 | |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 428 | ~TestableSurfaceFlinger() { |
| 429 | // All these pointer and container clears help ensure that GMock does |
| 430 | // not report a leaked object, since the SurfaceFlinger instance may |
| 431 | // still be referenced by something despite our best efforts to destroy |
| 432 | // it after each test is done. |
| 433 | mutableDisplays().clear(); |
Ady Abraham | 2939f09 | 2019-03-04 17:44:06 -0800 | [diff] [blame] | 434 | mutableCurrentState().displays.clear(); |
| 435 | mutableDrawingState().displays.clear(); |
Lloyd Pique | 0b1fe70 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 436 | mutableEventQueue().reset(); |
Pablo Gamito | 5cfc6e5 | 2020-09-10 11:18:03 +0000 | [diff] [blame] | 437 | mutableInterceptor().clear(); |
Lloyd Pique | 2eb71eb | 2019-08-13 13:23:03 -0700 | [diff] [blame] | 438 | mFlinger->mScheduler.reset(); |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 439 | mFlinger->mCompositionEngine->setHwComposer(std::unique_ptr<HWComposer>()); |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 440 | mFlinger->mCompositionEngine->setRenderEngine( |
| 441 | std::unique_ptr<renderengine::RenderEngine>()); |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 442 | } |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 443 | |
Lloyd Pique | a618d85 | 2018-01-17 11:52:30 -0800 | [diff] [blame] | 444 | /* ------------------------------------------------------------------------ |
| 445 | * Wrapper classes for Read-write access to private data to set up |
| 446 | * preconditions and assert post-conditions. |
| 447 | */ |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 448 | struct HWC2Display : public HWC2::impl::Display { |
Peiyong Lin | 74ca2f4 | 2019-01-14 19:36:57 -0800 | [diff] [blame] | 449 | HWC2Display(Hwc2::Composer& composer, |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 450 | const std::unordered_set<hal::Capability>& capabilities, hal::HWDisplayId id, |
| 451 | hal::DisplayType type) |
Peiyong Lin | 74ca2f4 | 2019-01-14 19:36:57 -0800 | [diff] [blame] | 452 | : HWC2::impl::Display(composer, capabilities, id, type) {} |
Lloyd Pique | a618d85 | 2018-01-17 11:52:30 -0800 | [diff] [blame] | 453 | ~HWC2Display() { |
| 454 | // Prevents a call to disable vsyncs. |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 455 | mType = hal::DisplayType::INVALID; |
Lloyd Pique | a618d85 | 2018-01-17 11:52:30 -0800 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | auto& mutableIsConnected() { return this->mIsConnected; } |
| 459 | auto& mutableConfigs() { return this->mConfigs; } |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 460 | auto& mutableLayers() { return this->mLayers; } |
Lloyd Pique | a618d85 | 2018-01-17 11:52:30 -0800 | [diff] [blame] | 461 | }; |
| 462 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 463 | class FakeHwcDisplayInjector { |
| 464 | public: |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 465 | static constexpr hal::HWDisplayId DEFAULT_HWC_DISPLAY_ID = 1000; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 466 | static constexpr int32_t DEFAULT_WIDTH = 1920; |
| 467 | static constexpr int32_t DEFAULT_HEIGHT = 1280; |
| 468 | static constexpr int32_t DEFAULT_REFRESH_RATE = 16'666'666; |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 469 | static constexpr int32_t DEFAULT_CONFIG_GROUP = 7; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 470 | static constexpr int32_t DEFAULT_DPI = 320; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 471 | static constexpr hal::HWConfigId DEFAULT_ACTIVE_CONFIG = 0; |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 472 | static constexpr hal::PowerMode DEFAULT_POWER_MODE = hal::PowerMode::ON; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 473 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 474 | FakeHwcDisplayInjector(HalDisplayId displayId, hal::DisplayType hwcDisplayType, |
| 475 | bool isPrimary) |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 476 | : mDisplayId(displayId), mHwcDisplayType(hwcDisplayType), mIsPrimary(isPrimary) {} |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 477 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 478 | auto& setHwcDisplayId(hal::HWDisplayId displayId) { |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 479 | mHwcDisplayId = displayId; |
| 480 | return *this; |
| 481 | } |
| 482 | |
| 483 | auto& setWidth(int32_t width) { |
| 484 | mWidth = width; |
| 485 | return *this; |
| 486 | } |
| 487 | |
| 488 | auto& setHeight(int32_t height) { |
| 489 | mHeight = height; |
| 490 | return *this; |
| 491 | } |
| 492 | |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 493 | auto& setRefreshRate(int32_t refreshRate) { |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 494 | mRefreshRate = refreshRate; |
| 495 | return *this; |
| 496 | } |
| 497 | |
| 498 | auto& setDpiX(int32_t dpi) { |
| 499 | mDpiX = dpi; |
| 500 | return *this; |
| 501 | } |
| 502 | |
| 503 | auto& setDpiY(int32_t dpi) { |
| 504 | mDpiY = dpi; |
| 505 | return *this; |
| 506 | } |
| 507 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 508 | auto& setActiveConfig(hal::HWConfigId config) { |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 509 | mActiveConfig = config; |
| 510 | return *this; |
| 511 | } |
| 512 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 513 | auto& setCapabilities(const std::unordered_set<hal::Capability>* capabilities) { |
Lloyd Pique | e22f033 | 2018-07-16 16:35:56 -0700 | [diff] [blame] | 514 | mCapabilities = capabilities; |
| 515 | return *this; |
| 516 | } |
| 517 | |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 518 | auto& setPowerMode(hal::PowerMode mode) { |
Peiyong Lin | 1336e6e | 2019-05-28 09:23:50 -0700 | [diff] [blame] | 519 | mPowerMode = mode; |
| 520 | return *this; |
| 521 | } |
| 522 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 523 | void inject(TestableSurfaceFlinger* flinger, Hwc2::Composer* composer) { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 524 | static const std::unordered_set<hal::Capability> defaultCapabilities; |
Lloyd Pique | e22f033 | 2018-07-16 16:35:56 -0700 | [diff] [blame] | 525 | if (mCapabilities == nullptr) mCapabilities = &defaultCapabilities; |
| 526 | |
| 527 | // Caution - Make sure that any values passed by reference here do |
| 528 | // not refer to an instance owned by FakeHwcDisplayInjector. This |
| 529 | // class has temporary lifetime, while the constructed HWC2::Display |
| 530 | // is much longer lived. |
Peiyong Lin | 74ca2f4 | 2019-01-14 19:36:57 -0800 | [diff] [blame] | 531 | auto display = std::make_unique<HWC2Display>(*composer, *mCapabilities, mHwcDisplayId, |
| 532 | mHwcDisplayType); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 533 | |
| 534 | auto config = HWC2::Display::Config::Builder(*display, mActiveConfig); |
| 535 | config.setWidth(mWidth); |
| 536 | config.setHeight(mHeight); |
| 537 | config.setVsyncPeriod(mRefreshRate); |
| 538 | config.setDpiX(mDpiX); |
| 539 | config.setDpiY(mDpiY); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 540 | config.setConfigGroup(mConfigGroup); |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 541 | display->mutableConfigs().emplace(static_cast<int32_t>(mActiveConfig), config.build()); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 542 | display->mutableIsConnected() = true; |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 543 | display->setPowerMode(mPowerMode); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 544 | |
Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 545 | flinger->mutableHwcDisplayData()[mDisplayId].hwcDisplay = std::move(display); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 546 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 547 | if (mHwcDisplayType == hal::DisplayType::PHYSICAL) { |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 548 | const auto physicalId = PhysicalDisplayId::tryCast(mDisplayId); |
| 549 | LOG_ALWAYS_FATAL_IF(!physicalId); |
| 550 | flinger->mutableHwcPhysicalDisplayIdMap().emplace(mHwcDisplayId, *physicalId); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 551 | (mIsPrimary ? flinger->mutableInternalHwcDisplayId() |
| 552 | : flinger->mutableExternalHwcDisplayId()) = mHwcDisplayId; |
| 553 | } |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | private: |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 557 | const HalDisplayId mDisplayId; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 558 | const hal::DisplayType mHwcDisplayType; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 559 | const bool mIsPrimary; |
| 560 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 561 | hal::HWDisplayId mHwcDisplayId = DEFAULT_HWC_DISPLAY_ID; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 562 | int32_t mWidth = DEFAULT_WIDTH; |
| 563 | int32_t mHeight = DEFAULT_HEIGHT; |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 564 | int32_t mRefreshRate = DEFAULT_REFRESH_RATE; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 565 | int32_t mDpiX = DEFAULT_DPI; |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 566 | int32_t mConfigGroup = DEFAULT_CONFIG_GROUP; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 567 | int32_t mDpiY = DEFAULT_DPI; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 568 | hal::HWConfigId mActiveConfig = DEFAULT_ACTIVE_CONFIG; |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 569 | hal::PowerMode mPowerMode = DEFAULT_POWER_MODE; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 570 | const std::unordered_set<hal::Capability>* mCapabilities = nullptr; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 571 | }; |
| 572 | |
| 573 | class FakeDisplayDeviceInjector { |
| 574 | public: |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 575 | FakeDisplayDeviceInjector(TestableSurfaceFlinger& flinger, |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 576 | std::shared_ptr<compositionengine::Display> compositionDisplay, |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 577 | std::optional<DisplayConnectionType> connectionType, |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 578 | std::optional<hal::HWDisplayId> hwcDisplayId, bool isPrimary) |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 579 | : mFlinger(flinger), |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 580 | mCreationArgs(flinger.mFlinger.get(), mDisplayToken, compositionDisplay), |
| 581 | mHwcDisplayId(hwcDisplayId) { |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 582 | mCreationArgs.connectionType = connectionType; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 583 | mCreationArgs.isPrimary = isPrimary; |
| 584 | } |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 585 | |
| 586 | sp<IBinder> token() const { return mDisplayToken; } |
| 587 | |
| 588 | DisplayDeviceState& mutableDrawingDisplayState() { |
| 589 | return mFlinger.mutableDrawingState().displays.editValueFor(mDisplayToken); |
| 590 | } |
| 591 | |
| 592 | DisplayDeviceState& mutableCurrentDisplayState() { |
| 593 | return mFlinger.mutableCurrentState().displays.editValueFor(mDisplayToken); |
| 594 | } |
| 595 | |
Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 596 | const auto& getDrawingDisplayState() { |
| 597 | return mFlinger.mutableDrawingState().displays.valueFor(mDisplayToken); |
| 598 | } |
| 599 | |
| 600 | const auto& getCurrentDisplayState() { |
| 601 | return mFlinger.mutableCurrentState().displays.valueFor(mDisplayToken); |
| 602 | } |
| 603 | |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 604 | auto& mutableDisplayDevice() { return mFlinger.mutableDisplays()[mDisplayToken]; } |
Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 605 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 606 | auto& setNativeWindow(const sp<ANativeWindow>& nativeWindow) { |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 607 | mCreationArgs.nativeWindow = nativeWindow; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 608 | return *this; |
| 609 | } |
| 610 | |
Lloyd Pique | 542307f | 2018-10-19 13:24:08 -0700 | [diff] [blame] | 611 | auto& setDisplaySurface(const sp<compositionengine::DisplaySurface>& displaySurface) { |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 612 | mCreationArgs.displaySurface = displaySurface; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 613 | return *this; |
| 614 | } |
| 615 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 616 | auto& setSecure(bool secure) { |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 617 | mCreationArgs.isSecure = secure; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 618 | return *this; |
| 619 | } |
| 620 | |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 621 | auto& setPowerMode(hal::PowerMode mode) { |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 622 | mCreationArgs.initialPowerMode = mode; |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 623 | return *this; |
| 624 | } |
| 625 | |
Valerie Hau | 9758ae0 | 2018-10-09 16:05:09 -0700 | [diff] [blame] | 626 | auto& setHwcColorModes( |
| 627 | const std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>> |
| 628 | hwcColorModes) { |
| 629 | mCreationArgs.hwcColorModes = hwcColorModes; |
| 630 | return *this; |
| 631 | } |
| 632 | |
| 633 | auto& setHasWideColorGamut(bool hasWideColorGamut) { |
| 634 | mCreationArgs.hasWideColorGamut = hasWideColorGamut; |
| 635 | return *this; |
| 636 | } |
| 637 | |
Lloyd Pique | 3305047 | 2019-12-19 17:12:44 -0800 | [diff] [blame] | 638 | auto& setPhysicalOrientation(ui::Rotation orientation) { |
| 639 | mCreationArgs.physicalOrientation = orientation; |
| 640 | return *this; |
| 641 | } |
| 642 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 643 | sp<DisplayDevice> inject() { |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 644 | const auto displayId = mCreationArgs.compositionDisplay->getDisplayId(); |
| 645 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 646 | DisplayDeviceState state; |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 647 | if (const auto type = mCreationArgs.connectionType) { |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 648 | LOG_ALWAYS_FATAL_IF(!displayId); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 649 | const auto physicalId = PhysicalDisplayId::tryCast(*displayId); |
| 650 | LOG_ALWAYS_FATAL_IF(!physicalId); |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 651 | LOG_ALWAYS_FATAL_IF(!mHwcDisplayId); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 652 | state.physical = {.id = *physicalId, .type = *type, .hwcDisplayId = *mHwcDisplayId}; |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 653 | } |
| 654 | |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 655 | state.isSecure = mCreationArgs.isSecure; |
| 656 | |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 657 | sp<DisplayDevice> device = new DisplayDevice(mCreationArgs); |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 658 | mFlinger.mutableDisplays().emplace(mDisplayToken, device); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 659 | mFlinger.mutableCurrentState().displays.add(mDisplayToken, state); |
| 660 | mFlinger.mutableDrawingState().displays.add(mDisplayToken, state); |
| 661 | |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 662 | if (const auto& physical = state.physical) { |
| 663 | mFlinger.mutablePhysicalDisplayTokens()[physical->id] = mDisplayToken; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | return device; |
| 667 | } |
| 668 | |
| 669 | private: |
| 670 | TestableSurfaceFlinger& mFlinger; |
| 671 | sp<BBinder> mDisplayToken = new BBinder(); |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 672 | DisplayDeviceCreationArgs mCreationArgs; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 673 | const std::optional<hal::HWDisplayId> mHwcDisplayId; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 674 | }; |
| 675 | |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 676 | private: |
| 677 | void setVsyncEnabled(bool) override {} |
| 678 | void changeRefreshRate(const Scheduler::RefreshRate&, Scheduler::ConfigEvent) override {} |
| 679 | void repaintEverythingForHWC() override {} |
| 680 | void kernelTimerChanged(bool) override {} |
| 681 | |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 682 | surfaceflinger::test::Factory mFactory; |
| 683 | sp<SurfaceFlinger> mFlinger = new SurfaceFlinger(mFactory, SurfaceFlinger::SkipInitialization); |
Dominik Laskowski | 7c9dbf9 | 2019-08-01 17:57:31 -0700 | [diff] [blame] | 684 | TestableScheduler* mScheduler = nullptr; |
Ady Abraham | abc2760 | 2020-04-08 17:20:29 -0700 | [diff] [blame] | 685 | Hwc2::mock::Display mDisplay; |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 686 | mock::DisplayIdGenerator<GpuVirtualDisplayId> mGpuVirtualDisplayIdGenerator; |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 687 | }; |
| 688 | |
| 689 | } // namespace android |