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