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