1*38e8c45fSAndroid Build Coastguard Worker /* 2*38e8c45fSAndroid Build Coastguard Worker * Copyright (C) 2007 The Android Open Source Project 3*38e8c45fSAndroid Build Coastguard Worker * 4*38e8c45fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*38e8c45fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*38e8c45fSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*38e8c45fSAndroid Build Coastguard Worker * 8*38e8c45fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*38e8c45fSAndroid Build Coastguard Worker * 10*38e8c45fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 11*38e8c45fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*38e8c45fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 13*38e8c45fSAndroid Build Coastguard Worker * limitations under the License. 14*38e8c45fSAndroid Build Coastguard Worker */ 15*38e8c45fSAndroid Build Coastguard Worker 16*38e8c45fSAndroid Build Coastguard Worker #pragma once 17*38e8c45fSAndroid Build Coastguard Worker 18*38e8c45fSAndroid Build Coastguard Worker #include <sys/types.h> 19*38e8c45fSAndroid Build Coastguard Worker 20*38e8c45fSAndroid Build Coastguard Worker /* 21*38e8c45fSAndroid Build Coastguard Worker * NOTE: Make sure this file doesn't include anything from <gl/ > or <gl2/ > 22*38e8c45fSAndroid Build Coastguard Worker */ 23*38e8c45fSAndroid Build Coastguard Worker 24*38e8c45fSAndroid Build Coastguard Worker #include <android-base/stringprintf.h> 25*38e8c45fSAndroid Build Coastguard Worker #include <android-base/strings.h> 26*38e8c45fSAndroid Build Coastguard Worker #include <android-base/thread_annotations.h> 27*38e8c45fSAndroid Build Coastguard Worker #include <android/gui/ActivePicture.h> 28*38e8c45fSAndroid Build Coastguard Worker #include <android/gui/BnSurfaceComposer.h> 29*38e8c45fSAndroid Build Coastguard Worker #include <android/gui/DisplayStatInfo.h> 30*38e8c45fSAndroid Build Coastguard Worker #include <android/gui/DisplayState.h> 31*38e8c45fSAndroid Build Coastguard Worker #include <android/gui/IActivePictureListener.h> 32*38e8c45fSAndroid Build Coastguard Worker #include <android/gui/IJankListener.h> 33*38e8c45fSAndroid Build Coastguard Worker #include <android/gui/ISurfaceComposerClient.h> 34*38e8c45fSAndroid Build Coastguard Worker #include <common/trace.h> 35*38e8c45fSAndroid Build Coastguard Worker #include <cutils/atomic.h> 36*38e8c45fSAndroid Build Coastguard Worker #include <cutils/compiler.h> 37*38e8c45fSAndroid Build Coastguard Worker #include <ftl/algorithm.h> 38*38e8c45fSAndroid Build Coastguard Worker #include <ftl/future.h> 39*38e8c45fSAndroid Build Coastguard Worker #include <ftl/non_null.h> 40*38e8c45fSAndroid Build Coastguard Worker #include <gui/BufferQueue.h> 41*38e8c45fSAndroid Build Coastguard Worker #include <gui/CompositorTiming.h> 42*38e8c45fSAndroid Build Coastguard Worker #include <gui/FrameTimestamps.h> 43*38e8c45fSAndroid Build Coastguard Worker #include <gui/ISurfaceComposer.h> 44*38e8c45fSAndroid Build Coastguard Worker #include <gui/ITransactionCompletedListener.h> 45*38e8c45fSAndroid Build Coastguard Worker #include <gui/LayerState.h> 46*38e8c45fSAndroid Build Coastguard Worker #include <layerproto/LayerProtoHeader.h> 47*38e8c45fSAndroid Build Coastguard Worker #include <math/mat4.h> 48*38e8c45fSAndroid Build Coastguard Worker #include <renderengine/LayerSettings.h> 49*38e8c45fSAndroid Build Coastguard Worker #include <serviceutils/PriorityDumper.h> 50*38e8c45fSAndroid Build Coastguard Worker #include <system/graphics.h> 51*38e8c45fSAndroid Build Coastguard Worker #include <ui/DisplayMap.h> 52*38e8c45fSAndroid Build Coastguard Worker #include <ui/FenceTime.h> 53*38e8c45fSAndroid Build Coastguard Worker #include <ui/PixelFormat.h> 54*38e8c45fSAndroid Build Coastguard Worker #include <ui/Size.h> 55*38e8c45fSAndroid Build Coastguard Worker #include <utils/Errors.h> 56*38e8c45fSAndroid Build Coastguard Worker #include <utils/KeyedVector.h> 57*38e8c45fSAndroid Build Coastguard Worker #include <utils/RefBase.h> 58*38e8c45fSAndroid Build Coastguard Worker #include <utils/SortedVector.h> 59*38e8c45fSAndroid Build Coastguard Worker #include <utils/threads.h> 60*38e8c45fSAndroid Build Coastguard Worker 61*38e8c45fSAndroid Build Coastguard Worker #include <compositionengine/OutputColorSetting.h> 62*38e8c45fSAndroid Build Coastguard Worker #include <compositionengine/impl/OutputCompositionState.h> 63*38e8c45fSAndroid Build Coastguard Worker #include <scheduler/Fps.h> 64*38e8c45fSAndroid Build Coastguard Worker #include <scheduler/PresentLatencyTracker.h> 65*38e8c45fSAndroid Build Coastguard Worker #include <scheduler/Time.h> 66*38e8c45fSAndroid Build Coastguard Worker #include <scheduler/TransactionSchedule.h> 67*38e8c45fSAndroid Build Coastguard Worker #include <scheduler/interface/CompositionCoverage.h> 68*38e8c45fSAndroid Build Coastguard Worker #include <scheduler/interface/ICompositor.h> 69*38e8c45fSAndroid Build Coastguard Worker #include <ui/FenceResult.h> 70*38e8c45fSAndroid Build Coastguard Worker 71*38e8c45fSAndroid Build Coastguard Worker #include <common/FlagManager.h> 72*38e8c45fSAndroid Build Coastguard Worker #include "ActivePictureUpdater.h" 73*38e8c45fSAndroid Build Coastguard Worker #include "BackgroundExecutor.h" 74*38e8c45fSAndroid Build Coastguard Worker #include "Display/DisplayModeController.h" 75*38e8c45fSAndroid Build Coastguard Worker #include "Display/PhysicalDisplay.h" 76*38e8c45fSAndroid Build Coastguard Worker #include "Display/VirtualDisplaySnapshot.h" 77*38e8c45fSAndroid Build Coastguard Worker #include "DisplayDevice.h" 78*38e8c45fSAndroid Build Coastguard Worker #include "DisplayHardware/HWC2.h" 79*38e8c45fSAndroid Build Coastguard Worker #include "DisplayIdGenerator.h" 80*38e8c45fSAndroid Build Coastguard Worker #include "Effects/Daltonizer.h" 81*38e8c45fSAndroid Build Coastguard Worker #include "FrontEnd/DisplayInfo.h" 82*38e8c45fSAndroid Build Coastguard Worker #include "FrontEnd/LayerCreationArgs.h" 83*38e8c45fSAndroid Build Coastguard Worker #include "FrontEnd/LayerLifecycleManager.h" 84*38e8c45fSAndroid Build Coastguard Worker #include "FrontEnd/LayerSnapshot.h" 85*38e8c45fSAndroid Build Coastguard Worker #include "FrontEnd/LayerSnapshotBuilder.h" 86*38e8c45fSAndroid Build Coastguard Worker #include "FrontEnd/TransactionHandler.h" 87*38e8c45fSAndroid Build Coastguard Worker #include "LayerVector.h" 88*38e8c45fSAndroid Build Coastguard Worker #include "MutexUtils.h" 89*38e8c45fSAndroid Build Coastguard Worker #include "PowerAdvisor/PowerAdvisor.h" 90*38e8c45fSAndroid Build Coastguard Worker #include "Scheduler/ISchedulerCallback.h" 91*38e8c45fSAndroid Build Coastguard Worker #include "Scheduler/RefreshRateSelector.h" 92*38e8c45fSAndroid Build Coastguard Worker #include "Scheduler/Scheduler.h" 93*38e8c45fSAndroid Build Coastguard Worker #include "SurfaceFlingerFactory.h" 94*38e8c45fSAndroid Build Coastguard Worker #include "ThreadContext.h" 95*38e8c45fSAndroid Build Coastguard Worker #include "Tracing/LayerTracing.h" 96*38e8c45fSAndroid Build Coastguard Worker #include "Tracing/TransactionTracing.h" 97*38e8c45fSAndroid Build Coastguard Worker #include "TransactionCallbackInvoker.h" 98*38e8c45fSAndroid Build Coastguard Worker #include "TransactionState.h" 99*38e8c45fSAndroid Build Coastguard Worker #include "Utils/OnceFuture.h" 100*38e8c45fSAndroid Build Coastguard Worker 101*38e8c45fSAndroid Build Coastguard Worker #include <algorithm> 102*38e8c45fSAndroid Build Coastguard Worker #include <atomic> 103*38e8c45fSAndroid Build Coastguard Worker #include <cstdint> 104*38e8c45fSAndroid Build Coastguard Worker #include <functional> 105*38e8c45fSAndroid Build Coastguard Worker #include <map> 106*38e8c45fSAndroid Build Coastguard Worker #include <memory> 107*38e8c45fSAndroid Build Coastguard Worker #include <mutex> 108*38e8c45fSAndroid Build Coastguard Worker #include <optional> 109*38e8c45fSAndroid Build Coastguard Worker #include <queue> 110*38e8c45fSAndroid Build Coastguard Worker #include <set> 111*38e8c45fSAndroid Build Coastguard Worker #include <string> 112*38e8c45fSAndroid Build Coastguard Worker #include <thread> 113*38e8c45fSAndroid Build Coastguard Worker #include <type_traits> 114*38e8c45fSAndroid Build Coastguard Worker #include <unordered_map> 115*38e8c45fSAndroid Build Coastguard Worker #include <unordered_set> 116*38e8c45fSAndroid Build Coastguard Worker #include <utility> 117*38e8c45fSAndroid Build Coastguard Worker #include <vector> 118*38e8c45fSAndroid Build Coastguard Worker 119*38e8c45fSAndroid Build Coastguard Worker #include <aidl/android/hardware/graphics/common/DisplayDecorationSupport.h> 120*38e8c45fSAndroid Build Coastguard Worker #include <aidl/android/hardware/graphics/common/DisplayHotplugEvent.h> 121*38e8c45fSAndroid Build Coastguard Worker #include <aidl/android/hardware/graphics/composer3/RefreshRateChangedDebugData.h> 122*38e8c45fSAndroid Build Coastguard Worker #include "Client.h" 123*38e8c45fSAndroid Build Coastguard Worker 124*38e8c45fSAndroid Build Coastguard Worker using namespace android::surfaceflinger; 125*38e8c45fSAndroid Build Coastguard Worker 126*38e8c45fSAndroid Build Coastguard Worker namespace android { 127*38e8c45fSAndroid Build Coastguard Worker 128*38e8c45fSAndroid Build Coastguard Worker class EventThread; 129*38e8c45fSAndroid Build Coastguard Worker class FlagManager; 130*38e8c45fSAndroid Build Coastguard Worker class FpsReporter; 131*38e8c45fSAndroid Build Coastguard Worker class TunnelModeEnabledReporter; 132*38e8c45fSAndroid Build Coastguard Worker class HdrLayerInfoReporter; 133*38e8c45fSAndroid Build Coastguard Worker class HWComposer; 134*38e8c45fSAndroid Build Coastguard Worker class IGraphicBufferProducer; 135*38e8c45fSAndroid Build Coastguard Worker class Layer; 136*38e8c45fSAndroid Build Coastguard Worker class MessageBase; 137*38e8c45fSAndroid Build Coastguard Worker class RefreshRateOverlay; 138*38e8c45fSAndroid Build Coastguard Worker class RegionSamplingThread; 139*38e8c45fSAndroid Build Coastguard Worker class RenderArea; 140*38e8c45fSAndroid Build Coastguard Worker class TimeStats; 141*38e8c45fSAndroid Build Coastguard Worker class FrameTracer; 142*38e8c45fSAndroid Build Coastguard Worker class ScreenCapturer; 143*38e8c45fSAndroid Build Coastguard Worker class WindowInfosListenerInvoker; 144*38e8c45fSAndroid Build Coastguard Worker 145*38e8c45fSAndroid Build Coastguard Worker using ::aidl::android::hardware::drm::HdcpLevels; 146*38e8c45fSAndroid Build Coastguard Worker using ::aidl::android::hardware::graphics::common::DisplayHotplugEvent; 147*38e8c45fSAndroid Build Coastguard Worker using ::aidl::android::hardware::graphics::composer3::RefreshRateChangedDebugData; 148*38e8c45fSAndroid Build Coastguard Worker using frontend::TransactionHandler; 149*38e8c45fSAndroid Build Coastguard Worker using gui::CaptureArgs; 150*38e8c45fSAndroid Build Coastguard Worker using gui::DisplayCaptureArgs; 151*38e8c45fSAndroid Build Coastguard Worker using gui::IRegionSamplingListener; 152*38e8c45fSAndroid Build Coastguard Worker using gui::LayerCaptureArgs; 153*38e8c45fSAndroid Build Coastguard Worker using gui::ScreenCaptureResults; 154*38e8c45fSAndroid Build Coastguard Worker 155*38e8c45fSAndroid Build Coastguard Worker namespace frametimeline { 156*38e8c45fSAndroid Build Coastguard Worker class FrameTimeline; 157*38e8c45fSAndroid Build Coastguard Worker } 158*38e8c45fSAndroid Build Coastguard Worker 159*38e8c45fSAndroid Build Coastguard Worker namespace os { 160*38e8c45fSAndroid Build Coastguard Worker class IInputFlinger; 161*38e8c45fSAndroid Build Coastguard Worker } 162*38e8c45fSAndroid Build Coastguard Worker 163*38e8c45fSAndroid Build Coastguard Worker namespace compositionengine { 164*38e8c45fSAndroid Build Coastguard Worker class DisplaySurface; 165*38e8c45fSAndroid Build Coastguard Worker class OutputLayer; 166*38e8c45fSAndroid Build Coastguard Worker 167*38e8c45fSAndroid Build Coastguard Worker struct CompositionRefreshArgs; 168*38e8c45fSAndroid Build Coastguard Worker } // namespace compositionengine 169*38e8c45fSAndroid Build Coastguard Worker 170*38e8c45fSAndroid Build Coastguard Worker namespace renderengine { 171*38e8c45fSAndroid Build Coastguard Worker class RenderEngine; 172*38e8c45fSAndroid Build Coastguard Worker } // namespace renderengine 173*38e8c45fSAndroid Build Coastguard Worker 174*38e8c45fSAndroid Build Coastguard Worker enum { 175*38e8c45fSAndroid Build Coastguard Worker eTransactionNeeded = 0x01, 176*38e8c45fSAndroid Build Coastguard Worker eTraversalNeeded = 0x02, 177*38e8c45fSAndroid Build Coastguard Worker eDisplayTransactionNeeded = 0x04, 178*38e8c45fSAndroid Build Coastguard Worker eTransformHintUpdateNeeded = 0x08, 179*38e8c45fSAndroid Build Coastguard Worker eTransactionFlushNeeded = 0x10, 180*38e8c45fSAndroid Build Coastguard Worker eInputInfoUpdateNeeded = 0x20, 181*38e8c45fSAndroid Build Coastguard Worker eTransactionMask = 0x3f, 182*38e8c45fSAndroid Build Coastguard Worker }; 183*38e8c45fSAndroid Build Coastguard Worker 184*38e8c45fSAndroid Build Coastguard Worker // Latch Unsignaled buffer behaviours 185*38e8c45fSAndroid Build Coastguard Worker enum class LatchUnsignaledConfig { 186*38e8c45fSAndroid Build Coastguard Worker // All buffers are latched signaled. 187*38e8c45fSAndroid Build Coastguard Worker Disabled, 188*38e8c45fSAndroid Build Coastguard Worker 189*38e8c45fSAndroid Build Coastguard Worker // Latch unsignaled is permitted when a single layer is updated in a frame, 190*38e8c45fSAndroid Build Coastguard Worker // and the update includes just a buffer update (i.e. no sync transactions 191*38e8c45fSAndroid Build Coastguard Worker // or geometry changes). 192*38e8c45fSAndroid Build Coastguard Worker // Latch unsignaled is also only permitted when a single transaction is ready 193*38e8c45fSAndroid Build Coastguard Worker // to be applied. If we pass an unsignaled fence to HWC, HWC might miss presenting 194*38e8c45fSAndroid Build Coastguard Worker // the frame if the fence does not fire in time. If we apply another transaction, 195*38e8c45fSAndroid Build Coastguard Worker // we may penalize the other transaction unfairly. 196*38e8c45fSAndroid Build Coastguard Worker AutoSingleLayer, 197*38e8c45fSAndroid Build Coastguard Worker 198*38e8c45fSAndroid Build Coastguard Worker // All buffers are latched unsignaled. This behaviour is discouraged as it 199*38e8c45fSAndroid Build Coastguard Worker // can break sync transactions, stall the display and cause undesired side effects. 200*38e8c45fSAndroid Build Coastguard Worker // This is equivalent to ignoring the acquire fence when applying transactions. 201*38e8c45fSAndroid Build Coastguard Worker Always, 202*38e8c45fSAndroid Build Coastguard Worker }; 203*38e8c45fSAndroid Build Coastguard Worker 204*38e8c45fSAndroid Build Coastguard Worker struct DisplayRenderAreaBuilder; 205*38e8c45fSAndroid Build Coastguard Worker struct LayerRenderAreaBuilder; 206*38e8c45fSAndroid Build Coastguard Worker 207*38e8c45fSAndroid Build Coastguard Worker using DisplayColorSetting = compositionengine::OutputColorSetting; 208*38e8c45fSAndroid Build Coastguard Worker 209*38e8c45fSAndroid Build Coastguard Worker class SurfaceFlinger : public BnSurfaceComposer, 210*38e8c45fSAndroid Build Coastguard Worker public PriorityDumper, 211*38e8c45fSAndroid Build Coastguard Worker private IBinder::DeathRecipient, 212*38e8c45fSAndroid Build Coastguard Worker private HWC2::ComposerCallback, 213*38e8c45fSAndroid Build Coastguard Worker private ICompositor, 214*38e8c45fSAndroid Build Coastguard Worker private scheduler::ISchedulerCallback, 215*38e8c45fSAndroid Build Coastguard Worker private compositionengine::ICEPowerCallback { 216*38e8c45fSAndroid Build Coastguard Worker public: 217*38e8c45fSAndroid Build Coastguard Worker struct SkipInitializationTag {}; 218*38e8c45fSAndroid Build Coastguard Worker 219*38e8c45fSAndroid Build Coastguard Worker SurfaceFlinger(surfaceflinger::Factory&, SkipInitializationTag) ANDROID_API; 220*38e8c45fSAndroid Build Coastguard Worker explicit SurfaceFlinger(surfaceflinger::Factory&) ANDROID_API; 221*38e8c45fSAndroid Build Coastguard Worker 222*38e8c45fSAndroid Build Coastguard Worker // set main thread scheduling policy 223*38e8c45fSAndroid Build Coastguard Worker static status_t setSchedFifo(bool enabled) ANDROID_API; 224*38e8c45fSAndroid Build Coastguard Worker 225*38e8c45fSAndroid Build Coastguard Worker // set main thread scheduling attributes 226*38e8c45fSAndroid Build Coastguard Worker static status_t setSchedAttr(bool enabled); 227*38e8c45fSAndroid Build Coastguard Worker getServiceName()228*38e8c45fSAndroid Build Coastguard Worker static char const* getServiceName() ANDROID_API { return "SurfaceFlinger"; } 229*38e8c45fSAndroid Build Coastguard Worker 230*38e8c45fSAndroid Build Coastguard Worker // If fences from sync Framework are supported. 231*38e8c45fSAndroid Build Coastguard Worker static bool hasSyncFramework; 232*38e8c45fSAndroid Build Coastguard Worker 233*38e8c45fSAndroid Build Coastguard Worker // The offset in nanoseconds to use when VsyncController timestamps present fence 234*38e8c45fSAndroid Build Coastguard Worker // signaling time. 235*38e8c45fSAndroid Build Coastguard Worker static int64_t dispSyncPresentTimeOffset; 236*38e8c45fSAndroid Build Coastguard Worker 237*38e8c45fSAndroid Build Coastguard Worker // Some hardware can do RGB->YUV conversion more efficiently in hardware 238*38e8c45fSAndroid Build Coastguard Worker // controlled by HWC than in hardware controlled by the video encoder. 239*38e8c45fSAndroid Build Coastguard Worker // This instruct VirtualDisplaySurface to use HWC for such conversion on 240*38e8c45fSAndroid Build Coastguard Worker // GL composition. 241*38e8c45fSAndroid Build Coastguard Worker static bool useHwcForRgbToYuv; 242*38e8c45fSAndroid Build Coastguard Worker 243*38e8c45fSAndroid Build Coastguard Worker // Controls the number of buffers SurfaceFlinger will allocate for use in 244*38e8c45fSAndroid Build Coastguard Worker // FramebufferSurface 245*38e8c45fSAndroid Build Coastguard Worker static int64_t maxFrameBufferAcquiredBuffers; 246*38e8c45fSAndroid Build Coastguard Worker 247*38e8c45fSAndroid Build Coastguard Worker // Controls the minimum acquired buffers SurfaceFlinger will suggest via 248*38e8c45fSAndroid Build Coastguard Worker // ISurfaceComposer.getMaxAcquiredBufferCount(). 249*38e8c45fSAndroid Build Coastguard Worker static int64_t minAcquiredBuffers; 250*38e8c45fSAndroid Build Coastguard Worker 251*38e8c45fSAndroid Build Coastguard Worker // Controls the maximum width and height in pixels that the graphics pipeline can support for 252*38e8c45fSAndroid Build Coastguard Worker // GPU fallback composition. For example, 8k devices with 4k GPUs, or 4k devices with 2k GPUs. 253*38e8c45fSAndroid Build Coastguard Worker static uint32_t maxGraphicsWidth; 254*38e8c45fSAndroid Build Coastguard Worker static uint32_t maxGraphicsHeight; 255*38e8c45fSAndroid Build Coastguard Worker 256*38e8c45fSAndroid Build Coastguard Worker static bool useContextPriority; 257*38e8c45fSAndroid Build Coastguard Worker 258*38e8c45fSAndroid Build Coastguard Worker // The data space and pixel format that SurfaceFlinger expects hardware composer 259*38e8c45fSAndroid Build Coastguard Worker // to composite efficiently. Meaning under most scenarios, hardware composer 260*38e8c45fSAndroid Build Coastguard Worker // will accept layers with the data space and pixel format. 261*38e8c45fSAndroid Build Coastguard Worker static ui::Dataspace defaultCompositionDataspace; 262*38e8c45fSAndroid Build Coastguard Worker static ui::PixelFormat defaultCompositionPixelFormat; 263*38e8c45fSAndroid Build Coastguard Worker 264*38e8c45fSAndroid Build Coastguard Worker // The data space and pixel format that SurfaceFlinger expects hardware composer 265*38e8c45fSAndroid Build Coastguard Worker // to composite efficiently for wide color gamut surfaces. Meaning under most scenarios, 266*38e8c45fSAndroid Build Coastguard Worker // hardware composer will accept layers with the data space and pixel format. 267*38e8c45fSAndroid Build Coastguard Worker static ui::Dataspace wideColorGamutCompositionDataspace; 268*38e8c45fSAndroid Build Coastguard Worker static ui::PixelFormat wideColorGamutCompositionPixelFormat; 269*38e8c45fSAndroid Build Coastguard Worker 270*38e8c45fSAndroid Build Coastguard Worker static constexpr SkipInitializationTag SkipInitialization; 271*38e8c45fSAndroid Build Coastguard Worker 272*38e8c45fSAndroid Build Coastguard Worker static LatchUnsignaledConfig enableLatchUnsignaledConfig; 273*38e8c45fSAndroid Build Coastguard Worker 274*38e8c45fSAndroid Build Coastguard Worker // must be called before clients can connect 275*38e8c45fSAndroid Build Coastguard Worker void init() ANDROID_API; 276*38e8c45fSAndroid Build Coastguard Worker 277*38e8c45fSAndroid Build Coastguard Worker // starts SurfaceFlinger main loop in the current thread 278*38e8c45fSAndroid Build Coastguard Worker void run() ANDROID_API; 279*38e8c45fSAndroid Build Coastguard Worker 280*38e8c45fSAndroid Build Coastguard Worker // Indicates frame activity, i.e. whether commit and/or composite is taking place. 281*38e8c45fSAndroid Build Coastguard Worker enum class FrameHint { kNone, kActive }; 282*38e8c45fSAndroid Build Coastguard Worker 283*38e8c45fSAndroid Build Coastguard Worker // Schedule commit of transactions on the main thread ahead of the next VSYNC. 284*38e8c45fSAndroid Build Coastguard Worker void scheduleCommit(FrameHint, Duration workDurationSlack = Duration::fromNs(0)); 285*38e8c45fSAndroid Build Coastguard Worker // As above, but also force composite regardless if transactions were committed. 286*38e8c45fSAndroid Build Coastguard Worker void scheduleComposite(FrameHint); 287*38e8c45fSAndroid Build Coastguard Worker // As above, but also force dirty geometry to repaint. 288*38e8c45fSAndroid Build Coastguard Worker void scheduleRepaint(); 289*38e8c45fSAndroid Build Coastguard Worker // Schedule sampling independently from commit or composite. 290*38e8c45fSAndroid Build Coastguard Worker void scheduleSample(); 291*38e8c45fSAndroid Build Coastguard Worker getFactory()292*38e8c45fSAndroid Build Coastguard Worker surfaceflinger::Factory& getFactory() { return mFactory; } 293*38e8c45fSAndroid Build Coastguard Worker 294*38e8c45fSAndroid Build Coastguard Worker // The CompositionEngine encapsulates all composition related interfaces and actions. 295*38e8c45fSAndroid Build Coastguard Worker compositionengine::CompositionEngine& getCompositionEngine() const; 296*38e8c45fSAndroid Build Coastguard Worker 297*38e8c45fSAndroid Build Coastguard Worker renderengine::RenderEngine& getRenderEngine() const; 298*38e8c45fSAndroid Build Coastguard Worker 299*38e8c45fSAndroid Build Coastguard Worker void onLayerFirstRef(Layer*); 300*38e8c45fSAndroid Build Coastguard Worker void onLayerDestroyed(Layer*); 301*38e8c45fSAndroid Build Coastguard Worker void onLayerUpdate(); 302*38e8c45fSAndroid Build Coastguard Worker 303*38e8c45fSAndroid Build Coastguard Worker // Called when all clients have released all their references to 304*38e8c45fSAndroid Build Coastguard Worker // this layer. The layer may still be kept alive by its parents but 305*38e8c45fSAndroid Build Coastguard Worker // the client can no longer modify this layer directly. 306*38e8c45fSAndroid Build Coastguard Worker void onHandleDestroyed(sp<Layer>& layer, uint32_t layerId); 307*38e8c45fSAndroid Build Coastguard Worker getTransactionCallbackInvoker()308*38e8c45fSAndroid Build Coastguard Worker TransactionCallbackInvoker& getTransactionCallbackInvoker() { 309*38e8c45fSAndroid Build Coastguard Worker return mTransactionCallbackInvoker; 310*38e8c45fSAndroid Build Coastguard Worker } 311*38e8c45fSAndroid Build Coastguard Worker 312*38e8c45fSAndroid Build Coastguard Worker // If set, disables reusing client composition buffers. This can be set by 313*38e8c45fSAndroid Build Coastguard Worker // debug.sf.disable_client_composition_cache 314*38e8c45fSAndroid Build Coastguard Worker bool mDisableClientCompositionCache = false; 315*38e8c45fSAndroid Build Coastguard Worker 316*38e8c45fSAndroid Build Coastguard Worker // Disables expensive rendering for all displays 317*38e8c45fSAndroid Build Coastguard Worker // This is scheduled on the main thread 318*38e8c45fSAndroid Build Coastguard Worker void disableExpensiveRendering(); 319*38e8c45fSAndroid Build Coastguard Worker 320*38e8c45fSAndroid Build Coastguard Worker // If set, composition engine tries to predict the composition strategy provided by HWC 321*38e8c45fSAndroid Build Coastguard Worker // based on the previous frame. If the strategy can be predicted, gpu composition will 322*38e8c45fSAndroid Build Coastguard Worker // run parallel to the hwc validateDisplay call and re-run if the predition is incorrect. 323*38e8c45fSAndroid Build Coastguard Worker bool mPredictCompositionStrategy = false; 324*38e8c45fSAndroid Build Coastguard Worker 325*38e8c45fSAndroid Build Coastguard Worker // If true, then any layer with a SMPTE 170M transfer function is decoded using the sRGB 326*38e8c45fSAndroid Build Coastguard Worker // transfer instead. This is mainly to preserve legacy behavior, where implementations treated 327*38e8c45fSAndroid Build Coastguard Worker // SMPTE 170M as sRGB prior to color management being implemented, and now implementations rely 328*38e8c45fSAndroid Build Coastguard Worker // on this behavior to increase contrast for some media sources. 329*38e8c45fSAndroid Build Coastguard Worker bool mTreat170mAsSrgb = false; 330*38e8c45fSAndroid Build Coastguard Worker 331*38e8c45fSAndroid Build Coastguard Worker // If true, then screenshots with an enhanced render intent will dim in gamma space. 332*38e8c45fSAndroid Build Coastguard Worker // The purpose is to ensure that screenshots appear correct during system animations for devices 333*38e8c45fSAndroid Build Coastguard Worker // that require that dimming must occur in gamma space. 334*38e8c45fSAndroid Build Coastguard Worker bool mDimInGammaSpaceForEnhancedScreenshots = false; 335*38e8c45fSAndroid Build Coastguard Worker 336*38e8c45fSAndroid Build Coastguard Worker // Allows to ignore physical orientation provided through hwc API in favour of 337*38e8c45fSAndroid Build Coastguard Worker // 'ro.surface_flinger.primary_display_orientation'. 338*38e8c45fSAndroid Build Coastguard Worker // TODO(b/246793311): Clean up a temporary property 339*38e8c45fSAndroid Build Coastguard Worker bool mIgnoreHwcPhysicalDisplayOrientation = false; 340*38e8c45fSAndroid Build Coastguard Worker 341*38e8c45fSAndroid Build Coastguard Worker void forceFutureUpdate(int delayInMs); 342*38e8c45fSAndroid Build Coastguard Worker const DisplayDevice* getDisplayFromLayerStack(ui::LayerStack) 343*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mStateLock, kMainThreadContext); 344*38e8c45fSAndroid Build Coastguard Worker 345*38e8c45fSAndroid Build Coastguard Worker // TODO (b/259407931): Remove. 346*38e8c45fSAndroid Build Coastguard Worker // TODO (b/281857977): This should be annotated with REQUIRES(kMainThreadContext), but this 347*38e8c45fSAndroid Build Coastguard Worker // would require thread safety annotations throughout the frontend (in particular Layer and 348*38e8c45fSAndroid Build Coastguard Worker // LayerFE). getActiveDisplayRotationFlags()349*38e8c45fSAndroid Build Coastguard Worker static ui::Transform::RotationFlags getActiveDisplayRotationFlags() { 350*38e8c45fSAndroid Build Coastguard Worker return sActiveDisplayRotationFlags; 351*38e8c45fSAndroid Build Coastguard Worker } 352*38e8c45fSAndroid Build Coastguard Worker 353*38e8c45fSAndroid Build Coastguard Worker protected: 354*38e8c45fSAndroid Build Coastguard Worker // We're reference counted, never destroy SurfaceFlinger directly 355*38e8c45fSAndroid Build Coastguard Worker virtual ~SurfaceFlinger(); 356*38e8c45fSAndroid Build Coastguard Worker 357*38e8c45fSAndroid Build Coastguard Worker virtual void processDisplayAdded(const wp<IBinder>& displayToken, const DisplayDeviceState&) 358*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mStateLock); 359*38e8c45fSAndroid Build Coastguard Worker 360*38e8c45fSAndroid Build Coastguard Worker virtual std::shared_ptr<renderengine::ExternalTexture> getExternalTextureFromBufferData( 361*38e8c45fSAndroid Build Coastguard Worker BufferData& bufferData, const char* layerName, uint64_t transactionId); 362*38e8c45fSAndroid Build Coastguard Worker 363*38e8c45fSAndroid Build Coastguard Worker // Returns true if any display matches a `bool(const DisplayDevice&)` predicate. 364*38e8c45fSAndroid Build Coastguard Worker template <typename Predicate> hasDisplay(Predicate p)365*38e8c45fSAndroid Build Coastguard Worker bool hasDisplay(Predicate p) const REQUIRES(mStateLock) { 366*38e8c45fSAndroid Build Coastguard Worker return static_cast<bool>(findDisplay(p)); 367*38e8c45fSAndroid Build Coastguard Worker } 368*38e8c45fSAndroid Build Coastguard Worker exceedsMaxRenderTargetSize(uint32_t width,uint32_t height)369*38e8c45fSAndroid Build Coastguard Worker bool exceedsMaxRenderTargetSize(uint32_t width, uint32_t height) const { 370*38e8c45fSAndroid Build Coastguard Worker return width > mMaxRenderTargetSize || height > mMaxRenderTargetSize; 371*38e8c45fSAndroid Build Coastguard Worker } 372*38e8c45fSAndroid Build Coastguard Worker 373*38e8c45fSAndroid Build Coastguard Worker private: 374*38e8c45fSAndroid Build Coastguard Worker friend class BufferLayer; 375*38e8c45fSAndroid Build Coastguard Worker friend class Client; 376*38e8c45fSAndroid Build Coastguard Worker friend class FpsReporter; 377*38e8c45fSAndroid Build Coastguard Worker friend class TunnelModeEnabledReporter; 378*38e8c45fSAndroid Build Coastguard Worker friend class Layer; 379*38e8c45fSAndroid Build Coastguard Worker friend class RefreshRateOverlay; 380*38e8c45fSAndroid Build Coastguard Worker friend class RegionSamplingThread; 381*38e8c45fSAndroid Build Coastguard Worker friend class LayerRenderArea; 382*38e8c45fSAndroid Build Coastguard Worker friend class SurfaceComposerAIDL; 383*38e8c45fSAndroid Build Coastguard Worker friend class DisplayRenderArea; 384*38e8c45fSAndroid Build Coastguard Worker 385*38e8c45fSAndroid Build Coastguard Worker // For unit tests 386*38e8c45fSAndroid Build Coastguard Worker friend class TestableSurfaceFlinger; 387*38e8c45fSAndroid Build Coastguard Worker friend class TransactionApplicationTest; 388*38e8c45fSAndroid Build Coastguard Worker friend class TunnelModeEnabledReporterTest; 389*38e8c45fSAndroid Build Coastguard Worker 390*38e8c45fSAndroid Build Coastguard Worker using TransactionSchedule = scheduler::TransactionSchedule; 391*38e8c45fSAndroid Build Coastguard Worker using GetLayerSnapshotsFunction = std::function<std::vector<std::pair<Layer*, sp<LayerFE>>>()>; 392*38e8c45fSAndroid Build Coastguard Worker using RenderAreaBuilderVariant = std::variant<DisplayRenderAreaBuilder, LayerRenderAreaBuilder>; 393*38e8c45fSAndroid Build Coastguard Worker using DumpArgs = Vector<String16>; 394*38e8c45fSAndroid Build Coastguard Worker using Dumper = std::function<void(const DumpArgs&, bool asProto, std::string&)>; 395*38e8c45fSAndroid Build Coastguard Worker 396*38e8c45fSAndroid Build Coastguard Worker class State { 397*38e8c45fSAndroid Build Coastguard Worker public: State(LayerVector::StateSet set)398*38e8c45fSAndroid Build Coastguard Worker explicit State(LayerVector::StateSet set) : stateSet(set) {} 399*38e8c45fSAndroid Build Coastguard Worker State& operator=(const State& other) { 400*38e8c45fSAndroid Build Coastguard Worker // We explicitly don't copy stateSet so that, e.g., mDrawingState 401*38e8c45fSAndroid Build Coastguard Worker // always uses the Drawing StateSet. 402*38e8c45fSAndroid Build Coastguard Worker displays = other.displays; 403*38e8c45fSAndroid Build Coastguard Worker colorMatrixChanged = other.colorMatrixChanged; 404*38e8c45fSAndroid Build Coastguard Worker if (colorMatrixChanged) { 405*38e8c45fSAndroid Build Coastguard Worker colorMatrix = other.colorMatrix; 406*38e8c45fSAndroid Build Coastguard Worker } 407*38e8c45fSAndroid Build Coastguard Worker globalShadowSettings = other.globalShadowSettings; 408*38e8c45fSAndroid Build Coastguard Worker 409*38e8c45fSAndroid Build Coastguard Worker return *this; 410*38e8c45fSAndroid Build Coastguard Worker } 411*38e8c45fSAndroid Build Coastguard Worker 412*38e8c45fSAndroid Build Coastguard Worker const LayerVector::StateSet stateSet = LayerVector::StateSet::Invalid; 413*38e8c45fSAndroid Build Coastguard Worker 414*38e8c45fSAndroid Build Coastguard Worker // TODO(b/241285876): Replace deprecated DefaultKeyedVector with ftl::SmallMap. 415*38e8c45fSAndroid Build Coastguard Worker DefaultKeyedVector<wp<IBinder>, DisplayDeviceState> displays; 416*38e8c45fSAndroid Build Coastguard Worker getDisplayIndex(PhysicalDisplayId displayId)417*38e8c45fSAndroid Build Coastguard Worker std::optional<size_t> getDisplayIndex(PhysicalDisplayId displayId) const { 418*38e8c45fSAndroid Build Coastguard Worker for (size_t i = 0; i < displays.size(); i++) { 419*38e8c45fSAndroid Build Coastguard Worker const auto& state = displays.valueAt(i); 420*38e8c45fSAndroid Build Coastguard Worker if (state.physical && state.physical->id == displayId) { 421*38e8c45fSAndroid Build Coastguard Worker return i; 422*38e8c45fSAndroid Build Coastguard Worker } 423*38e8c45fSAndroid Build Coastguard Worker } 424*38e8c45fSAndroid Build Coastguard Worker 425*38e8c45fSAndroid Build Coastguard Worker return {}; 426*38e8c45fSAndroid Build Coastguard Worker } 427*38e8c45fSAndroid Build Coastguard Worker 428*38e8c45fSAndroid Build Coastguard Worker bool colorMatrixChanged = true; 429*38e8c45fSAndroid Build Coastguard Worker mat4 colorMatrix; 430*38e8c45fSAndroid Build Coastguard Worker 431*38e8c45fSAndroid Build Coastguard Worker ShadowSettings globalShadowSettings; 432*38e8c45fSAndroid Build Coastguard Worker }; 433*38e8c45fSAndroid Build Coastguard Worker 434*38e8c45fSAndroid Build Coastguard Worker // Keeps track of pending buffers per layer handle in the transaction queue or current/drawing 435*38e8c45fSAndroid Build Coastguard Worker // state before the buffers are latched. The layer owns the atomic counters and decrements the 436*38e8c45fSAndroid Build Coastguard Worker // count in the main thread when dropping or latching a buffer. 437*38e8c45fSAndroid Build Coastguard Worker // 438*38e8c45fSAndroid Build Coastguard Worker // The binder threads increment the same counter when a new transaction containing a buffer is 439*38e8c45fSAndroid Build Coastguard Worker // added to the transaction queue. The map is updated with the layer handle lifecycle updates. 440*38e8c45fSAndroid Build Coastguard Worker // This is done to avoid lock contention with the main thread. 441*38e8c45fSAndroid Build Coastguard Worker class BufferCountTracker { 442*38e8c45fSAndroid Build Coastguard Worker public: increment(uint32_t layerId)443*38e8c45fSAndroid Build Coastguard Worker void increment(uint32_t layerId) { 444*38e8c45fSAndroid Build Coastguard Worker std::lock_guard<std::mutex> lock(mLock); 445*38e8c45fSAndroid Build Coastguard Worker auto it = mCounterByLayerId.find(layerId); 446*38e8c45fSAndroid Build Coastguard Worker if (it != mCounterByLayerId.end()) { 447*38e8c45fSAndroid Build Coastguard Worker auto [name, pendingBuffers] = it->second; 448*38e8c45fSAndroid Build Coastguard Worker int32_t count = ++(*pendingBuffers); 449*38e8c45fSAndroid Build Coastguard Worker SFTRACE_INT(name.c_str(), count); 450*38e8c45fSAndroid Build Coastguard Worker } else { 451*38e8c45fSAndroid Build Coastguard Worker ALOGW("Layer ID not found! %d", layerId); 452*38e8c45fSAndroid Build Coastguard Worker } 453*38e8c45fSAndroid Build Coastguard Worker } 454*38e8c45fSAndroid Build Coastguard Worker add(uint32_t layerId,const std::string & name,std::atomic<int32_t> * counter)455*38e8c45fSAndroid Build Coastguard Worker void add(uint32_t layerId, const std::string& name, std::atomic<int32_t>* counter) { 456*38e8c45fSAndroid Build Coastguard Worker std::lock_guard<std::mutex> lock(mLock); 457*38e8c45fSAndroid Build Coastguard Worker mCounterByLayerId[layerId] = std::make_pair(name, counter); 458*38e8c45fSAndroid Build Coastguard Worker } 459*38e8c45fSAndroid Build Coastguard Worker remove(uint32_t layerId)460*38e8c45fSAndroid Build Coastguard Worker void remove(uint32_t layerId) { 461*38e8c45fSAndroid Build Coastguard Worker std::lock_guard<std::mutex> lock(mLock); 462*38e8c45fSAndroid Build Coastguard Worker mCounterByLayerId.erase(layerId); 463*38e8c45fSAndroid Build Coastguard Worker } 464*38e8c45fSAndroid Build Coastguard Worker 465*38e8c45fSAndroid Build Coastguard Worker private: 466*38e8c45fSAndroid Build Coastguard Worker std::mutex mLock; 467*38e8c45fSAndroid Build Coastguard Worker std::unordered_map<uint32_t, std::pair<std::string, std::atomic<int32_t>*>> 468*38e8c45fSAndroid Build Coastguard Worker mCounterByLayerId GUARDED_BY(mLock); 469*38e8c45fSAndroid Build Coastguard Worker }; 470*38e8c45fSAndroid Build Coastguard Worker 471*38e8c45fSAndroid Build Coastguard Worker enum class BootStage { 472*38e8c45fSAndroid Build Coastguard Worker BOOTLOADER, 473*38e8c45fSAndroid Build Coastguard Worker BOOTANIMATION, 474*38e8c45fSAndroid Build Coastguard Worker FINISHED, 475*38e8c45fSAndroid Build Coastguard Worker }; 476*38e8c45fSAndroid Build Coastguard Worker 477*38e8c45fSAndroid Build Coastguard Worker template <typename F, std::enable_if_t<!std::is_member_function_pointer_v<F>>* = nullptr> dumper(F && dump)478*38e8c45fSAndroid Build Coastguard Worker static Dumper dumper(F&& dump) { 479*38e8c45fSAndroid Build Coastguard Worker using namespace std::placeholders; 480*38e8c45fSAndroid Build Coastguard Worker return std::bind(std::forward<F>(dump), _3); 481*38e8c45fSAndroid Build Coastguard Worker } 482*38e8c45fSAndroid Build Coastguard Worker lockedDumper(Dumper dump)483*38e8c45fSAndroid Build Coastguard Worker Dumper lockedDumper(Dumper dump) { 484*38e8c45fSAndroid Build Coastguard Worker return [this, dump](const DumpArgs& args, bool asProto, std::string& result) -> void { 485*38e8c45fSAndroid Build Coastguard Worker TimedLock lock(mStateLock, s2ns(1), __func__); 486*38e8c45fSAndroid Build Coastguard Worker if (!lock.locked()) { 487*38e8c45fSAndroid Build Coastguard Worker base::StringAppendF(&result, "Dumping without lock after timeout: %s (%d)\n", 488*38e8c45fSAndroid Build Coastguard Worker strerror(-lock.status), lock.status); 489*38e8c45fSAndroid Build Coastguard Worker } 490*38e8c45fSAndroid Build Coastguard Worker dump(args, asProto, result); 491*38e8c45fSAndroid Build Coastguard Worker }; 492*38e8c45fSAndroid Build Coastguard Worker } 493*38e8c45fSAndroid Build Coastguard Worker 494*38e8c45fSAndroid Build Coastguard Worker template <typename F, std::enable_if_t<std::is_member_function_pointer_v<F>>* = nullptr> dumper(F dump)495*38e8c45fSAndroid Build Coastguard Worker Dumper dumper(F dump) { 496*38e8c45fSAndroid Build Coastguard Worker using namespace std::placeholders; 497*38e8c45fSAndroid Build Coastguard Worker return lockedDumper(std::bind(dump, this, _3)); 498*38e8c45fSAndroid Build Coastguard Worker } 499*38e8c45fSAndroid Build Coastguard Worker 500*38e8c45fSAndroid Build Coastguard Worker template <typename F> argsDumper(F dump)501*38e8c45fSAndroid Build Coastguard Worker Dumper argsDumper(F dump) { 502*38e8c45fSAndroid Build Coastguard Worker using namespace std::placeholders; 503*38e8c45fSAndroid Build Coastguard Worker return lockedDumper(std::bind(dump, this, _1, _3)); 504*38e8c45fSAndroid Build Coastguard Worker } 505*38e8c45fSAndroid Build Coastguard Worker 506*38e8c45fSAndroid Build Coastguard Worker template <typename F> protoDumper(F dump)507*38e8c45fSAndroid Build Coastguard Worker Dumper protoDumper(F dump) { 508*38e8c45fSAndroid Build Coastguard Worker using namespace std::placeholders; 509*38e8c45fSAndroid Build Coastguard Worker return lockedDumper(std::bind(dump, this, _1, _2, _3)); 510*38e8c45fSAndroid Build Coastguard Worker } 511*38e8c45fSAndroid Build Coastguard Worker mainThreadDumperImpl(Dumper dumper)512*38e8c45fSAndroid Build Coastguard Worker Dumper mainThreadDumperImpl(Dumper dumper) { 513*38e8c45fSAndroid Build Coastguard Worker return [this, dumper](const DumpArgs& args, bool asProto, std::string& result) -> void { 514*38e8c45fSAndroid Build Coastguard Worker mScheduler 515*38e8c45fSAndroid Build Coastguard Worker ->schedule( 516*38e8c45fSAndroid Build Coastguard Worker [&args, asProto, &result, dumper]() FTL_FAKE_GUARD(kMainThreadContext) 517*38e8c45fSAndroid Build Coastguard Worker FTL_FAKE_GUARD(mStateLock) { dumper(args, asProto, result); }) 518*38e8c45fSAndroid Build Coastguard Worker .get(); 519*38e8c45fSAndroid Build Coastguard Worker }; 520*38e8c45fSAndroid Build Coastguard Worker } 521*38e8c45fSAndroid Build Coastguard Worker 522*38e8c45fSAndroid Build Coastguard Worker template <typename F, std::enable_if_t<std::is_member_function_pointer_v<F>>* = nullptr> mainThreadDumper(F dump)523*38e8c45fSAndroid Build Coastguard Worker Dumper mainThreadDumper(F dump) { 524*38e8c45fSAndroid Build Coastguard Worker using namespace std::placeholders; 525*38e8c45fSAndroid Build Coastguard Worker return mainThreadDumperImpl(std::bind(dump, this, _3)); 526*38e8c45fSAndroid Build Coastguard Worker } 527*38e8c45fSAndroid Build Coastguard Worker 528*38e8c45fSAndroid Build Coastguard Worker template <typename F, std::enable_if_t<std::is_member_function_pointer_v<F>>* = nullptr> argsMainThreadDumper(F dump)529*38e8c45fSAndroid Build Coastguard Worker Dumper argsMainThreadDumper(F dump) { 530*38e8c45fSAndroid Build Coastguard Worker using namespace std::placeholders; 531*38e8c45fSAndroid Build Coastguard Worker return mainThreadDumperImpl(std::bind(dump, this, _1, _3)); 532*38e8c45fSAndroid Build Coastguard Worker } 533*38e8c45fSAndroid Build Coastguard Worker 534*38e8c45fSAndroid Build Coastguard Worker // Maximum allowed number of display frames that can be set through backdoor 535*38e8c45fSAndroid Build Coastguard Worker static const int MAX_ALLOWED_DISPLAY_FRAMES = 2048; 536*38e8c45fSAndroid Build Coastguard Worker 537*38e8c45fSAndroid Build Coastguard Worker static const size_t MAX_LAYERS = 4096; 538*38e8c45fSAndroid Build Coastguard Worker 539*38e8c45fSAndroid Build Coastguard Worker static bool callingThreadHasUnscopedSurfaceFlingerAccess(bool usePermissionCache = true) 540*38e8c45fSAndroid Build Coastguard Worker EXCLUDES(mStateLock); 541*38e8c45fSAndroid Build Coastguard Worker 542*38e8c45fSAndroid Build Coastguard Worker // IBinder overrides: 543*38e8c45fSAndroid Build Coastguard Worker status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) override; dump(int fd,const Vector<String16> & args)544*38e8c45fSAndroid Build Coastguard Worker status_t dump(int fd, const Vector<String16>& args) override { return priorityDump(fd, args); } 545*38e8c45fSAndroid Build Coastguard Worker 546*38e8c45fSAndroid Build Coastguard Worker // ISurfaceComposer implementation: 547*38e8c45fSAndroid Build Coastguard Worker sp<IBinder> createVirtualDisplay(const std::string& displayName, bool isSecure, 548*38e8c45fSAndroid Build Coastguard Worker const std::string& uniqueId, 549*38e8c45fSAndroid Build Coastguard Worker float requestedRefreshRate = 0.0f); 550*38e8c45fSAndroid Build Coastguard Worker status_t destroyVirtualDisplay(const sp<IBinder>& displayToken); getPhysicalDisplayIds()551*38e8c45fSAndroid Build Coastguard Worker std::vector<PhysicalDisplayId> getPhysicalDisplayIds() const EXCLUDES(mStateLock) { 552*38e8c45fSAndroid Build Coastguard Worker Mutex::Autolock lock(mStateLock); 553*38e8c45fSAndroid Build Coastguard Worker return getPhysicalDisplayIdsLocked(); 554*38e8c45fSAndroid Build Coastguard Worker } 555*38e8c45fSAndroid Build Coastguard Worker 556*38e8c45fSAndroid Build Coastguard Worker sp<IBinder> getPhysicalDisplayToken(PhysicalDisplayId displayId) const; 557*38e8c45fSAndroid Build Coastguard Worker status_t setTransactionState( 558*38e8c45fSAndroid Build Coastguard Worker const FrameTimelineInfo& frameTimelineInfo, Vector<ComposerState>& state, 559*38e8c45fSAndroid Build Coastguard Worker Vector<DisplayState>& displays, uint32_t flags, const sp<IBinder>& applyToken, 560*38e8c45fSAndroid Build Coastguard Worker InputWindowCommands inputWindowCommands, int64_t desiredPresentTime, 561*38e8c45fSAndroid Build Coastguard Worker bool isAutoTimestamp, const std::vector<client_cache_t>& uncacheBuffers, 562*38e8c45fSAndroid Build Coastguard Worker bool hasListenerCallbacks, const std::vector<ListenerCallbacks>& listenerCallbacks, 563*38e8c45fSAndroid Build Coastguard Worker uint64_t transactionId, const std::vector<uint64_t>& mergedTransactionIds) override; 564*38e8c45fSAndroid Build Coastguard Worker void bootFinished(); 565*38e8c45fSAndroid Build Coastguard Worker status_t getSupportedFrameTimestamps(std::vector<FrameEvent>* outSupported) const; 566*38e8c45fSAndroid Build Coastguard Worker sp<IDisplayEventConnection> createDisplayEventConnection( 567*38e8c45fSAndroid Build Coastguard Worker gui::ISurfaceComposer::VsyncSource vsyncSource = 568*38e8c45fSAndroid Build Coastguard Worker gui::ISurfaceComposer::VsyncSource::eVsyncSourceApp, 569*38e8c45fSAndroid Build Coastguard Worker EventRegistrationFlags eventRegistration = {}, 570*38e8c45fSAndroid Build Coastguard Worker const sp<IBinder>& layerHandle = nullptr); 571*38e8c45fSAndroid Build Coastguard Worker 572*38e8c45fSAndroid Build Coastguard Worker void captureDisplay(const DisplayCaptureArgs&, const sp<IScreenCaptureListener>&); 573*38e8c45fSAndroid Build Coastguard Worker void captureDisplay(DisplayId, const CaptureArgs&, const sp<IScreenCaptureListener>&); 574*38e8c45fSAndroid Build Coastguard Worker ScreenCaptureResults captureLayersSync(const LayerCaptureArgs&); 575*38e8c45fSAndroid Build Coastguard Worker void captureLayers(const LayerCaptureArgs&, const sp<IScreenCaptureListener>&); 576*38e8c45fSAndroid Build Coastguard Worker 577*38e8c45fSAndroid Build Coastguard Worker status_t getDisplayStats(const sp<IBinder>& displayToken, DisplayStatInfo* stats); 578*38e8c45fSAndroid Build Coastguard Worker status_t getDisplayState(const sp<IBinder>& displayToken, ui::DisplayState*) 579*38e8c45fSAndroid Build Coastguard Worker EXCLUDES(mStateLock); 580*38e8c45fSAndroid Build Coastguard Worker status_t getStaticDisplayInfo(int64_t displayId, ui::StaticDisplayInfo*) EXCLUDES(mStateLock); 581*38e8c45fSAndroid Build Coastguard Worker status_t getDynamicDisplayInfoFromId(int64_t displayId, ui::DynamicDisplayInfo*) 582*38e8c45fSAndroid Build Coastguard Worker EXCLUDES(mStateLock); 583*38e8c45fSAndroid Build Coastguard Worker status_t getDynamicDisplayInfoFromToken(const sp<IBinder>& displayToken, 584*38e8c45fSAndroid Build Coastguard Worker ui::DynamicDisplayInfo*) EXCLUDES(mStateLock); 585*38e8c45fSAndroid Build Coastguard Worker void getDynamicDisplayInfoInternal(ui::DynamicDisplayInfo*&, const sp<DisplayDevice>&, 586*38e8c45fSAndroid Build Coastguard Worker const display::DisplaySnapshot&); 587*38e8c45fSAndroid Build Coastguard Worker status_t getDisplayNativePrimaries(const sp<IBinder>& displayToken, ui::DisplayPrimaries&); 588*38e8c45fSAndroid Build Coastguard Worker status_t setActiveColorMode(const sp<IBinder>& displayToken, ui::ColorMode colorMode); 589*38e8c45fSAndroid Build Coastguard Worker status_t getBootDisplayModeSupport(bool* outSupport) const; 590*38e8c45fSAndroid Build Coastguard Worker status_t setBootDisplayMode(const sp<display::DisplayToken>&, DisplayModeId); 591*38e8c45fSAndroid Build Coastguard Worker status_t getOverlaySupport(gui::OverlayProperties* outProperties) const; 592*38e8c45fSAndroid Build Coastguard Worker status_t clearBootDisplayMode(const sp<IBinder>& displayToken); 593*38e8c45fSAndroid Build Coastguard Worker status_t getHdrConversionCapabilities( 594*38e8c45fSAndroid Build Coastguard Worker std::vector<gui::HdrConversionCapability>* hdrConversionCapaabilities) const; 595*38e8c45fSAndroid Build Coastguard Worker status_t setHdrConversionStrategy(const gui::HdrConversionStrategy& hdrConversionStrategy, 596*38e8c45fSAndroid Build Coastguard Worker int32_t*); 597*38e8c45fSAndroid Build Coastguard Worker status_t getHdrOutputConversionSupport(bool* outSupport) const; 598*38e8c45fSAndroid Build Coastguard Worker void setAutoLowLatencyMode(const sp<IBinder>& displayToken, bool on); 599*38e8c45fSAndroid Build Coastguard Worker void setGameContentType(const sp<IBinder>& displayToken, bool on); 600*38e8c45fSAndroid Build Coastguard Worker status_t getMaxLayerPictureProfiles(const sp<IBinder>& displayToken, int32_t* outMaxProfiles); 601*38e8c45fSAndroid Build Coastguard Worker void setPowerMode(const sp<IBinder>& displayToken, int mode); 602*38e8c45fSAndroid Build Coastguard Worker status_t overrideHdrTypes(const sp<IBinder>& displayToken, 603*38e8c45fSAndroid Build Coastguard Worker const std::vector<ui::Hdr>& hdrTypes); 604*38e8c45fSAndroid Build Coastguard Worker status_t onPullAtom(const int32_t atomId, std::vector<uint8_t>* pulledData, bool* success); 605*38e8c45fSAndroid Build Coastguard Worker status_t getCompositionPreference(ui::Dataspace* outDataspace, ui::PixelFormat* outPixelFormat, 606*38e8c45fSAndroid Build Coastguard Worker ui::Dataspace* outWideColorGamutDataspace, 607*38e8c45fSAndroid Build Coastguard Worker ui::PixelFormat* outWideColorGamutPixelFormat) const; 608*38e8c45fSAndroid Build Coastguard Worker status_t getDisplayedContentSamplingAttributes(const sp<IBinder>& displayToken, 609*38e8c45fSAndroid Build Coastguard Worker ui::PixelFormat* outFormat, 610*38e8c45fSAndroid Build Coastguard Worker ui::Dataspace* outDataspace, 611*38e8c45fSAndroid Build Coastguard Worker uint8_t* outComponentMask) const; 612*38e8c45fSAndroid Build Coastguard Worker status_t setDisplayContentSamplingEnabled(const sp<IBinder>& displayToken, bool enable, 613*38e8c45fSAndroid Build Coastguard Worker uint8_t componentMask, uint64_t maxFrames); 614*38e8c45fSAndroid Build Coastguard Worker status_t getDisplayedContentSample(const sp<IBinder>& displayToken, uint64_t maxFrames, 615*38e8c45fSAndroid Build Coastguard Worker uint64_t timestamp, DisplayedFrameStats* outStats) const; 616*38e8c45fSAndroid Build Coastguard Worker status_t getProtectedContentSupport(bool* outSupported) const; 617*38e8c45fSAndroid Build Coastguard Worker status_t isWideColorDisplay(const sp<IBinder>& displayToken, bool* outIsWideColorDisplay) const; 618*38e8c45fSAndroid Build Coastguard Worker status_t addRegionSamplingListener(const Rect& samplingArea, const sp<IBinder>& stopLayerHandle, 619*38e8c45fSAndroid Build Coastguard Worker const sp<IRegionSamplingListener>& listener); 620*38e8c45fSAndroid Build Coastguard Worker status_t removeRegionSamplingListener(const sp<IRegionSamplingListener>& listener); 621*38e8c45fSAndroid Build Coastguard Worker status_t addFpsListener(int32_t taskId, const sp<gui::IFpsListener>& listener); 622*38e8c45fSAndroid Build Coastguard Worker status_t removeFpsListener(const sp<gui::IFpsListener>& listener); 623*38e8c45fSAndroid Build Coastguard Worker status_t addTunnelModeEnabledListener(const sp<gui::ITunnelModeEnabledListener>& listener); 624*38e8c45fSAndroid Build Coastguard Worker status_t removeTunnelModeEnabledListener(const sp<gui::ITunnelModeEnabledListener>& listener); 625*38e8c45fSAndroid Build Coastguard Worker status_t setDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, 626*38e8c45fSAndroid Build Coastguard Worker const gui::DisplayModeSpecs&); 627*38e8c45fSAndroid Build Coastguard Worker status_t getDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, gui::DisplayModeSpecs*); 628*38e8c45fSAndroid Build Coastguard Worker status_t getDisplayBrightnessSupport(const sp<IBinder>& displayToken, bool* outSupport) const; 629*38e8c45fSAndroid Build Coastguard Worker status_t setDisplayBrightness(const sp<IBinder>& displayToken, 630*38e8c45fSAndroid Build Coastguard Worker const gui::DisplayBrightness& brightness); 631*38e8c45fSAndroid Build Coastguard Worker status_t addHdrLayerInfoListener(const sp<IBinder>& displayToken, 632*38e8c45fSAndroid Build Coastguard Worker const sp<gui::IHdrLayerInfoListener>& listener); 633*38e8c45fSAndroid Build Coastguard Worker status_t removeHdrLayerInfoListener(const sp<IBinder>& displayToken, 634*38e8c45fSAndroid Build Coastguard Worker const sp<gui::IHdrLayerInfoListener>& listener); 635*38e8c45fSAndroid Build Coastguard Worker status_t notifyPowerBoost(int32_t boostId); 636*38e8c45fSAndroid Build Coastguard Worker status_t setGlobalShadowSettings(const half4& ambientColor, const half4& spotColor, 637*38e8c45fSAndroid Build Coastguard Worker float lightPosY, float lightPosZ, float lightRadius); 638*38e8c45fSAndroid Build Coastguard Worker status_t getDisplayDecorationSupport( 639*38e8c45fSAndroid Build Coastguard Worker const sp<IBinder>& displayToken, 640*38e8c45fSAndroid Build Coastguard Worker std::optional<aidl::android::hardware::graphics::common::DisplayDecorationSupport>* 641*38e8c45fSAndroid Build Coastguard Worker outSupport) const; 642*38e8c45fSAndroid Build Coastguard Worker status_t setFrameRate(const sp<IGraphicBufferProducer>& surface, float frameRate, 643*38e8c45fSAndroid Build Coastguard Worker int8_t compatibility, int8_t changeFrameRateStrategy); 644*38e8c45fSAndroid Build Coastguard Worker 645*38e8c45fSAndroid Build Coastguard Worker status_t setFrameTimelineInfo(const sp<IGraphicBufferProducer>& surface, 646*38e8c45fSAndroid Build Coastguard Worker const gui::FrameTimelineInfo& frameTimelineInfo); 647*38e8c45fSAndroid Build Coastguard Worker 648*38e8c45fSAndroid Build Coastguard Worker status_t setGameModeFrameRateOverride(uid_t uid, float frameRate); 649*38e8c45fSAndroid Build Coastguard Worker 650*38e8c45fSAndroid Build Coastguard Worker status_t setGameDefaultFrameRateOverride(uid_t uid, float frameRate); 651*38e8c45fSAndroid Build Coastguard Worker 652*38e8c45fSAndroid Build Coastguard Worker status_t updateSmallAreaDetection(std::vector<std::pair<int32_t, float>>& uidThresholdMappings); 653*38e8c45fSAndroid Build Coastguard Worker 654*38e8c45fSAndroid Build Coastguard Worker status_t setSmallAreaDetectionThreshold(int32_t appId, float threshold); 655*38e8c45fSAndroid Build Coastguard Worker 656*38e8c45fSAndroid Build Coastguard Worker int getGpuContextPriority(); 657*38e8c45fSAndroid Build Coastguard Worker 658*38e8c45fSAndroid Build Coastguard Worker status_t getMaxAcquiredBufferCount(int* buffers) const; 659*38e8c45fSAndroid Build Coastguard Worker 660*38e8c45fSAndroid Build Coastguard Worker status_t addWindowInfosListener(const sp<gui::IWindowInfosListener>& windowInfosListener, 661*38e8c45fSAndroid Build Coastguard Worker gui::WindowInfosListenerInfo* outResult); 662*38e8c45fSAndroid Build Coastguard Worker status_t removeWindowInfosListener( 663*38e8c45fSAndroid Build Coastguard Worker const sp<gui::IWindowInfosListener>& windowInfosListener) const; 664*38e8c45fSAndroid Build Coastguard Worker 665*38e8c45fSAndroid Build Coastguard Worker status_t getStalledTransactionInfo( 666*38e8c45fSAndroid Build Coastguard Worker int pid, std::optional<TransactionHandler::StalledTransactionInfo>& result); 667*38e8c45fSAndroid Build Coastguard Worker 668*38e8c45fSAndroid Build Coastguard Worker void updateHdcpLevels(hal::HWDisplayId hwcDisplayId, int32_t connectedLevel, int32_t maxLevel); 669*38e8c45fSAndroid Build Coastguard Worker 670*38e8c45fSAndroid Build Coastguard Worker void setActivePictureListener(const sp<gui::IActivePictureListener>& listener); 671*38e8c45fSAndroid Build Coastguard Worker 672*38e8c45fSAndroid Build Coastguard Worker // IBinder::DeathRecipient overrides: 673*38e8c45fSAndroid Build Coastguard Worker void binderDied(const wp<IBinder>& who) override; 674*38e8c45fSAndroid Build Coastguard Worker 675*38e8c45fSAndroid Build Coastguard Worker // HWC2::ComposerCallback overrides: 676*38e8c45fSAndroid Build Coastguard Worker void onComposerHalVsync(hal::HWDisplayId, nsecs_t timestamp, 677*38e8c45fSAndroid Build Coastguard Worker std::optional<hal::VsyncPeriodNanos>) override; 678*38e8c45fSAndroid Build Coastguard Worker void onComposerHalHotplugEvent(hal::HWDisplayId, DisplayHotplugEvent) override; 679*38e8c45fSAndroid Build Coastguard Worker void onComposerHalRefresh(hal::HWDisplayId) override; 680*38e8c45fSAndroid Build Coastguard Worker void onComposerHalVsyncPeriodTimingChanged(hal::HWDisplayId, 681*38e8c45fSAndroid Build Coastguard Worker const hal::VsyncPeriodChangeTimeline&) override; 682*38e8c45fSAndroid Build Coastguard Worker void onComposerHalSeamlessPossible(hal::HWDisplayId) override; 683*38e8c45fSAndroid Build Coastguard Worker void onComposerHalVsyncIdle(hal::HWDisplayId) override; 684*38e8c45fSAndroid Build Coastguard Worker void onRefreshRateChangedDebug(const RefreshRateChangedDebugData&) override; 685*38e8c45fSAndroid Build Coastguard Worker void onComposerHalHdcpLevelsChanged(hal::HWDisplayId, const HdcpLevels& levels) override; 686*38e8c45fSAndroid Build Coastguard Worker 687*38e8c45fSAndroid Build Coastguard Worker // ICompositor overrides: 688*38e8c45fSAndroid Build Coastguard Worker void configure() override REQUIRES(kMainThreadContext); 689*38e8c45fSAndroid Build Coastguard Worker bool commit(PhysicalDisplayId pacesetterId, const scheduler::FrameTargets&) override 690*38e8c45fSAndroid Build Coastguard Worker REQUIRES(kMainThreadContext); 691*38e8c45fSAndroid Build Coastguard Worker CompositeResultsPerDisplay composite(PhysicalDisplayId pacesetterId, 692*38e8c45fSAndroid Build Coastguard Worker const scheduler::FrameTargeters&) override 693*38e8c45fSAndroid Build Coastguard Worker REQUIRES(kMainThreadContext); 694*38e8c45fSAndroid Build Coastguard Worker 695*38e8c45fSAndroid Build Coastguard Worker void sample() override; 696*38e8c45fSAndroid Build Coastguard Worker 697*38e8c45fSAndroid Build Coastguard Worker // ISchedulerCallback overrides: 698*38e8c45fSAndroid Build Coastguard Worker void requestHardwareVsync(PhysicalDisplayId, bool) override; 699*38e8c45fSAndroid Build Coastguard Worker void requestDisplayModes(std::vector<display::DisplayModeRequest>) override; 700*38e8c45fSAndroid Build Coastguard Worker void kernelTimerChanged(bool expired) override; 701*38e8c45fSAndroid Build Coastguard Worker void onChoreographerAttached() override; 702*38e8c45fSAndroid Build Coastguard Worker void onExpectedPresentTimePosted(TimePoint expectedPresentTime, ftl::NonNull<DisplayModePtr>, 703*38e8c45fSAndroid Build Coastguard Worker Fps renderRate) override; 704*38e8c45fSAndroid Build Coastguard Worker void onCommitNotComposited() override 705*38e8c45fSAndroid Build Coastguard Worker REQUIRES(kMainThreadContext); 706*38e8c45fSAndroid Build Coastguard Worker void vrrDisplayIdle(bool idle) override; 707*38e8c45fSAndroid Build Coastguard Worker 708*38e8c45fSAndroid Build Coastguard Worker // ICEPowerCallback overrides: 709*38e8c45fSAndroid Build Coastguard Worker void notifyCpuLoadUp() override; 710*38e8c45fSAndroid Build Coastguard Worker 711*38e8c45fSAndroid Build Coastguard Worker using KernelIdleTimerController = scheduler::RefreshRateSelector::KernelIdleTimerController; 712*38e8c45fSAndroid Build Coastguard Worker 713*38e8c45fSAndroid Build Coastguard Worker // Get the controller and timeout that will help decide how the kernel idle timer will be 714*38e8c45fSAndroid Build Coastguard Worker // configured and what value to use as the timeout. 715*38e8c45fSAndroid Build Coastguard Worker std::pair<std::optional<KernelIdleTimerController>, std::chrono::milliseconds> 716*38e8c45fSAndroid Build Coastguard Worker getKernelIdleTimerProperties(PhysicalDisplayId) REQUIRES(mStateLock); 717*38e8c45fSAndroid Build Coastguard Worker 718*38e8c45fSAndroid Build Coastguard Worker // Show spinner with refresh rate overlay 719*38e8c45fSAndroid Build Coastguard Worker bool mRefreshRateOverlaySpinner = false; 720*38e8c45fSAndroid Build Coastguard Worker // Show render rate with refresh rate overlay 721*38e8c45fSAndroid Build Coastguard Worker bool mRefreshRateOverlayRenderRate = false; 722*38e8c45fSAndroid Build Coastguard Worker // Show render rate overlay offseted to the middle of the screen (e.g. for circular displays) 723*38e8c45fSAndroid Build Coastguard Worker bool mRefreshRateOverlayShowInMiddle = false; 724*38e8c45fSAndroid Build Coastguard Worker // Show hdr sdr ratio overlay 725*38e8c45fSAndroid Build Coastguard Worker bool mHdrSdrRatioOverlay = false; 726*38e8c45fSAndroid Build Coastguard Worker 727*38e8c45fSAndroid Build Coastguard Worker void setDesiredMode(display::DisplayModeRequest&&) REQUIRES(mStateLock); 728*38e8c45fSAndroid Build Coastguard Worker 729*38e8c45fSAndroid Build Coastguard Worker status_t setActiveModeFromBackdoor(const sp<display::DisplayToken>&, DisplayModeId, Fps minFps, 730*38e8c45fSAndroid Build Coastguard Worker Fps maxFps); 731*38e8c45fSAndroid Build Coastguard Worker 732*38e8c45fSAndroid Build Coastguard Worker void initiateDisplayModeChanges() REQUIRES(kMainThreadContext) REQUIRES(mStateLock); 733*38e8c45fSAndroid Build Coastguard Worker void finalizeDisplayModeChange(PhysicalDisplayId) REQUIRES(kMainThreadContext) 734*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mStateLock); 735*38e8c45fSAndroid Build Coastguard Worker 736*38e8c45fSAndroid Build Coastguard Worker void dropModeRequest(PhysicalDisplayId) REQUIRES(kMainThreadContext); 737*38e8c45fSAndroid Build Coastguard Worker void applyActiveMode(PhysicalDisplayId) REQUIRES(kMainThreadContext); 738*38e8c45fSAndroid Build Coastguard Worker 739*38e8c45fSAndroid Build Coastguard Worker // Called on the main thread in response to setPowerMode() 740*38e8c45fSAndroid Build Coastguard Worker void setPowerModeInternal(const sp<DisplayDevice>& display, hal::PowerMode mode) 741*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mStateLock, kMainThreadContext); 742*38e8c45fSAndroid Build Coastguard Worker 743*38e8c45fSAndroid Build Coastguard Worker // Returns the preferred mode for PhysicalDisplayId if the Scheduler has selected one for that 744*38e8c45fSAndroid Build Coastguard Worker // display. Falls back to the display's defaultModeId otherwise. 745*38e8c45fSAndroid Build Coastguard Worker ftl::Optional<scheduler::FrameRateMode> getPreferredDisplayMode( 746*38e8c45fSAndroid Build Coastguard Worker PhysicalDisplayId, DisplayModeId defaultModeId) const REQUIRES(mStateLock); 747*38e8c45fSAndroid Build Coastguard Worker 748*38e8c45fSAndroid Build Coastguard Worker status_t setDesiredDisplayModeSpecsInternal( 749*38e8c45fSAndroid Build Coastguard Worker const sp<DisplayDevice>&, const scheduler::RefreshRateSelector::PolicyVariant&) 750*38e8c45fSAndroid Build Coastguard Worker EXCLUDES(mStateLock) REQUIRES(kMainThreadContext); 751*38e8c45fSAndroid Build Coastguard Worker 752*38e8c45fSAndroid Build Coastguard Worker // TODO(b/241285191): Look up RefreshRateSelector on Scheduler to remove redundant parameter. 753*38e8c45fSAndroid Build Coastguard Worker status_t applyRefreshRateSelectorPolicy(PhysicalDisplayId, 754*38e8c45fSAndroid Build Coastguard Worker const scheduler::RefreshRateSelector&) 755*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mStateLock, kMainThreadContext); 756*38e8c45fSAndroid Build Coastguard Worker 757*38e8c45fSAndroid Build Coastguard Worker void commitTransactions() REQUIRES(kMainThreadContext, mStateLock); 758*38e8c45fSAndroid Build Coastguard Worker void commitTransactionsLocked(uint32_t transactionFlags) 759*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mStateLock, kMainThreadContext); 760*38e8c45fSAndroid Build Coastguard Worker void doCommitTransactions() REQUIRES(mStateLock); 761*38e8c45fSAndroid Build Coastguard Worker 762*38e8c45fSAndroid Build Coastguard Worker std::vector<std::pair<Layer*, LayerFE*>> moveSnapshotsToCompositionArgs( 763*38e8c45fSAndroid Build Coastguard Worker compositionengine::CompositionRefreshArgs& refreshArgs, bool cursorOnly) 764*38e8c45fSAndroid Build Coastguard Worker REQUIRES(kMainThreadContext); 765*38e8c45fSAndroid Build Coastguard Worker void moveSnapshotsFromCompositionArgs(compositionengine::CompositionRefreshArgs& refreshArgs, 766*38e8c45fSAndroid Build Coastguard Worker const std::vector<std::pair<Layer*, LayerFE*>>& layers) 767*38e8c45fSAndroid Build Coastguard Worker REQUIRES(kMainThreadContext); 768*38e8c45fSAndroid Build Coastguard Worker // Return true if we must composite this frame 769*38e8c45fSAndroid Build Coastguard Worker bool updateLayerSnapshots(VsyncId vsyncId, nsecs_t frameTimeNs, bool transactionsFlushed, 770*38e8c45fSAndroid Build Coastguard Worker bool& out) REQUIRES(kMainThreadContext); 771*38e8c45fSAndroid Build Coastguard Worker void updateLayerHistory(nsecs_t now) REQUIRES(kMainThreadContext); 772*38e8c45fSAndroid Build Coastguard Worker 773*38e8c45fSAndroid Build Coastguard Worker void updateInputFlinger(VsyncId vsyncId, TimePoint frameTime) REQUIRES(kMainThreadContext); 774*38e8c45fSAndroid Build Coastguard Worker void persistDisplayBrightness(bool needsComposite) REQUIRES(kMainThreadContext); 775*38e8c45fSAndroid Build Coastguard Worker void buildWindowInfos(std::vector<gui::WindowInfo>& outWindowInfos, 776*38e8c45fSAndroid Build Coastguard Worker std::vector<gui::DisplayInfo>& outDisplayInfos) 777*38e8c45fSAndroid Build Coastguard Worker REQUIRES(kMainThreadContext); 778*38e8c45fSAndroid Build Coastguard Worker void commitInputWindowCommands() REQUIRES(mStateLock); 779*38e8c45fSAndroid Build Coastguard Worker void updateCursorAsync() REQUIRES(kMainThreadContext); 780*38e8c45fSAndroid Build Coastguard Worker 781*38e8c45fSAndroid Build Coastguard Worker void initScheduler(const sp<const DisplayDevice>&) REQUIRES(kMainThreadContext, mStateLock); 782*38e8c45fSAndroid Build Coastguard Worker 783*38e8c45fSAndroid Build Coastguard Worker /* 784*38e8c45fSAndroid Build Coastguard Worker * Transactions 785*38e8c45fSAndroid Build Coastguard Worker */ 786*38e8c45fSAndroid Build Coastguard Worker bool applyTransactionState(const FrameTimelineInfo& info, 787*38e8c45fSAndroid Build Coastguard Worker std::vector<ResolvedComposerState>& state, 788*38e8c45fSAndroid Build Coastguard Worker Vector<DisplayState>& displays, uint32_t flags, 789*38e8c45fSAndroid Build Coastguard Worker const InputWindowCommands& inputWindowCommands, 790*38e8c45fSAndroid Build Coastguard Worker const int64_t desiredPresentTime, bool isAutoTimestamp, 791*38e8c45fSAndroid Build Coastguard Worker const std::vector<uint64_t>& uncacheBufferIds, 792*38e8c45fSAndroid Build Coastguard Worker const int64_t postTime, bool hasListenerCallbacks, 793*38e8c45fSAndroid Build Coastguard Worker const std::vector<ListenerCallbacks>& listenerCallbacks, 794*38e8c45fSAndroid Build Coastguard Worker int originPid, int originUid, uint64_t transactionId) 795*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mStateLock, kMainThreadContext); 796*38e8c45fSAndroid Build Coastguard Worker // Flush pending transactions that were presented after desiredPresentTime. 797*38e8c45fSAndroid Build Coastguard Worker // For test only 798*38e8c45fSAndroid Build Coastguard Worker bool flushTransactionQueues() REQUIRES(kMainThreadContext); 799*38e8c45fSAndroid Build Coastguard Worker 800*38e8c45fSAndroid Build Coastguard Worker bool applyTransactions(std::vector<TransactionState>&) REQUIRES(kMainThreadContext); 801*38e8c45fSAndroid Build Coastguard Worker bool applyAndCommitDisplayTransactionStatesLocked(std::vector<TransactionState>& transactions) 802*38e8c45fSAndroid Build Coastguard Worker REQUIRES(kMainThreadContext, mStateLock); 803*38e8c45fSAndroid Build Coastguard Worker 804*38e8c45fSAndroid Build Coastguard Worker // Returns true if there is at least one transaction that needs to be flushed 805*38e8c45fSAndroid Build Coastguard Worker bool transactionFlushNeeded() REQUIRES(kMainThreadContext); 806*38e8c45fSAndroid Build Coastguard Worker void addTransactionReadyFilters() REQUIRES(kMainThreadContext); 807*38e8c45fSAndroid Build Coastguard Worker TransactionHandler::TransactionReadiness transactionReadyTimelineCheck( 808*38e8c45fSAndroid Build Coastguard Worker const TransactionHandler::TransactionFlushState& flushState) 809*38e8c45fSAndroid Build Coastguard Worker REQUIRES(kMainThreadContext); 810*38e8c45fSAndroid Build Coastguard Worker TransactionHandler::TransactionReadiness transactionReadyBufferCheck( 811*38e8c45fSAndroid Build Coastguard Worker const TransactionHandler::TransactionFlushState& flushState) 812*38e8c45fSAndroid Build Coastguard Worker REQUIRES(kMainThreadContext); 813*38e8c45fSAndroid Build Coastguard Worker 814*38e8c45fSAndroid Build Coastguard Worker uint32_t updateLayerCallbacksAndStats(const FrameTimelineInfo&, ResolvedComposerState&, 815*38e8c45fSAndroid Build Coastguard Worker int64_t desiredPresentTime, bool isAutoTimestamp, 816*38e8c45fSAndroid Build Coastguard Worker int64_t postTime, uint64_t transactionId) 817*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mStateLock, kMainThreadContext); 818*38e8c45fSAndroid Build Coastguard Worker uint32_t getTransactionFlags() const; 819*38e8c45fSAndroid Build Coastguard Worker 820*38e8c45fSAndroid Build Coastguard Worker // Sets the masked bits, and schedules a commit if needed. 821*38e8c45fSAndroid Build Coastguard Worker void setTransactionFlags(uint32_t mask, TransactionSchedule = TransactionSchedule::Late, 822*38e8c45fSAndroid Build Coastguard Worker const sp<IBinder>& applyToken = nullptr, 823*38e8c45fSAndroid Build Coastguard Worker FrameHint = FrameHint::kActive); 824*38e8c45fSAndroid Build Coastguard Worker 825*38e8c45fSAndroid Build Coastguard Worker // Clears and returns the masked bits. 826*38e8c45fSAndroid Build Coastguard Worker uint32_t clearTransactionFlags(uint32_t mask); 827*38e8c45fSAndroid Build Coastguard Worker 828*38e8c45fSAndroid Build Coastguard Worker static LatchUnsignaledConfig getLatchUnsignaledConfig(); 829*38e8c45fSAndroid Build Coastguard Worker bool shouldLatchUnsignaled(const layer_state_t&, size_t numStates, bool firstTransaction) const; 830*38e8c45fSAndroid Build Coastguard Worker bool applyTransactionsLocked(std::vector<TransactionState>& transactions) 831*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mStateLock, kMainThreadContext); 832*38e8c45fSAndroid Build Coastguard Worker uint32_t setDisplayStateLocked(const DisplayState& s) REQUIRES(mStateLock); 833*38e8c45fSAndroid Build Coastguard Worker uint32_t addInputWindowCommands(const InputWindowCommands& inputWindowCommands) 834*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mStateLock); 835*38e8c45fSAndroid Build Coastguard Worker bool frameIsEarly(TimePoint expectedPresentTime, VsyncId) const; 836*38e8c45fSAndroid Build Coastguard Worker 837*38e8c45fSAndroid Build Coastguard Worker /* 838*38e8c45fSAndroid Build Coastguard Worker * Layer management 839*38e8c45fSAndroid Build Coastguard Worker */ 840*38e8c45fSAndroid Build Coastguard Worker status_t createLayer(LayerCreationArgs& args, gui::CreateSurfaceResult& outResult); 841*38e8c45fSAndroid Build Coastguard Worker 842*38e8c45fSAndroid Build Coastguard Worker status_t createBufferStateLayer(LayerCreationArgs& args, sp<IBinder>* outHandle, 843*38e8c45fSAndroid Build Coastguard Worker sp<Layer>* outLayer); 844*38e8c45fSAndroid Build Coastguard Worker 845*38e8c45fSAndroid Build Coastguard Worker status_t createEffectLayer(const LayerCreationArgs& args, sp<IBinder>* outHandle, 846*38e8c45fSAndroid Build Coastguard Worker sp<Layer>* outLayer); 847*38e8c45fSAndroid Build Coastguard Worker 848*38e8c45fSAndroid Build Coastguard Worker status_t mirrorLayer(const LayerCreationArgs& args, const sp<IBinder>& mirrorFromHandle, 849*38e8c45fSAndroid Build Coastguard Worker gui::CreateSurfaceResult& outResult); 850*38e8c45fSAndroid Build Coastguard Worker 851*38e8c45fSAndroid Build Coastguard Worker status_t mirrorDisplay(DisplayId displayId, const LayerCreationArgs& args, 852*38e8c45fSAndroid Build Coastguard Worker gui::CreateSurfaceResult& outResult); 853*38e8c45fSAndroid Build Coastguard Worker 854*38e8c45fSAndroid Build Coastguard Worker // add a layer to SurfaceFlinger 855*38e8c45fSAndroid Build Coastguard Worker status_t addClientLayer(LayerCreationArgs& args, const sp<IBinder>& handle, 856*38e8c45fSAndroid Build Coastguard Worker const sp<Layer>& layer, const wp<Layer>& parentLayer, 857*38e8c45fSAndroid Build Coastguard Worker uint32_t* outTransformHint); 858*38e8c45fSAndroid Build Coastguard Worker 859*38e8c45fSAndroid Build Coastguard Worker // Creates a promise for a future release fence for a layer. This allows for 860*38e8c45fSAndroid Build Coastguard Worker // the layer to keep track of when its buffer can be released. 861*38e8c45fSAndroid Build Coastguard Worker void attachReleaseFenceFutureToLayer(Layer* layer, LayerFE* layerFE, ui::LayerStack layerStack); 862*38e8c45fSAndroid Build Coastguard Worker 863*38e8c45fSAndroid Build Coastguard Worker // Checks if a protected layer exists in a list of layers. 864*38e8c45fSAndroid Build Coastguard Worker bool layersHasProtectedLayer(const std::vector<std::pair<Layer*, sp<LayerFE>>>& layers) const; 865*38e8c45fSAndroid Build Coastguard Worker 866*38e8c45fSAndroid Build Coastguard Worker using OutputCompositionState = compositionengine::impl::OutputCompositionState; 867*38e8c45fSAndroid Build Coastguard Worker 868*38e8c45fSAndroid Build Coastguard Worker std::optional<OutputCompositionState> getSnapshotsFromMainThread( 869*38e8c45fSAndroid Build Coastguard Worker RenderAreaBuilderVariant& renderAreaBuilder, 870*38e8c45fSAndroid Build Coastguard Worker GetLayerSnapshotsFunction getLayerSnapshotsFn, 871*38e8c45fSAndroid Build Coastguard Worker std::vector<std::pair<Layer*, sp<LayerFE>>>& layers); 872*38e8c45fSAndroid Build Coastguard Worker 873*38e8c45fSAndroid Build Coastguard Worker void captureScreenCommon(RenderAreaBuilderVariant, GetLayerSnapshotsFunction, 874*38e8c45fSAndroid Build Coastguard Worker ui::Size bufferSize, ui::PixelFormat, bool allowProtected, 875*38e8c45fSAndroid Build Coastguard Worker bool grayscale, bool attachGainmap, const sp<IScreenCaptureListener>&); 876*38e8c45fSAndroid Build Coastguard Worker 877*38e8c45fSAndroid Build Coastguard Worker std::optional<OutputCompositionState> getDisplayStateFromRenderAreaBuilder( 878*38e8c45fSAndroid Build Coastguard Worker RenderAreaBuilderVariant& renderAreaBuilder) REQUIRES(kMainThreadContext); 879*38e8c45fSAndroid Build Coastguard Worker 880*38e8c45fSAndroid Build Coastguard Worker ftl::SharedFuture<FenceResult> captureScreenshot( 881*38e8c45fSAndroid Build Coastguard Worker const RenderAreaBuilderVariant& renderAreaBuilder, 882*38e8c45fSAndroid Build Coastguard Worker const std::shared_ptr<renderengine::ExternalTexture>& buffer, bool regionSampling, 883*38e8c45fSAndroid Build Coastguard Worker bool grayscale, bool isProtected, bool attachGainmap, 884*38e8c45fSAndroid Build Coastguard Worker const sp<IScreenCaptureListener>& captureListener, 885*38e8c45fSAndroid Build Coastguard Worker std::optional<OutputCompositionState>& displayState, 886*38e8c45fSAndroid Build Coastguard Worker std::vector<std::pair<Layer*, sp<LayerFE>>>& layers); 887*38e8c45fSAndroid Build Coastguard Worker 888*38e8c45fSAndroid Build Coastguard Worker ftl::SharedFuture<FenceResult> renderScreenImpl( 889*38e8c45fSAndroid Build Coastguard Worker const RenderArea*, const std::shared_ptr<renderengine::ExternalTexture>&, 890*38e8c45fSAndroid Build Coastguard Worker bool regionSampling, bool grayscale, bool isProtected, ScreenCaptureResults&, 891*38e8c45fSAndroid Build Coastguard Worker std::optional<OutputCompositionState>& displayState, 892*38e8c45fSAndroid Build Coastguard Worker std::vector<std::pair<Layer*, sp<LayerFE>>>& layers); 893*38e8c45fSAndroid Build Coastguard Worker 894*38e8c45fSAndroid Build Coastguard Worker void readPersistentProperties(); 895*38e8c45fSAndroid Build Coastguard Worker 896*38e8c45fSAndroid Build Coastguard Worker uint32_t getMaxAcquiredBufferCountForCurrentRefreshRate(uid_t uid) const; 897*38e8c45fSAndroid Build Coastguard Worker 898*38e8c45fSAndroid Build Coastguard Worker /* 899*38e8c45fSAndroid Build Coastguard Worker * Display and layer stack management 900*38e8c45fSAndroid Build Coastguard Worker */ 901*38e8c45fSAndroid Build Coastguard Worker 902*38e8c45fSAndroid Build Coastguard Worker // Called during boot and restart after system_server death, setting the stage for bootanimation 903*38e8c45fSAndroid Build Coastguard Worker // before DisplayManager takes over. 904*38e8c45fSAndroid Build Coastguard Worker void initializeDisplays() REQUIRES(kMainThreadContext); 905*38e8c45fSAndroid Build Coastguard Worker getDisplayDeviceLocked(const wp<IBinder> & displayToken)906*38e8c45fSAndroid Build Coastguard Worker sp<const DisplayDevice> getDisplayDeviceLocked(const wp<IBinder>& displayToken) const 907*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mStateLock) { 908*38e8c45fSAndroid Build Coastguard Worker return const_cast<SurfaceFlinger*>(this)->getDisplayDeviceLocked(displayToken); 909*38e8c45fSAndroid Build Coastguard Worker } 910*38e8c45fSAndroid Build Coastguard Worker getDisplayDeviceLocked(const wp<IBinder> & displayToken)911*38e8c45fSAndroid Build Coastguard Worker sp<DisplayDevice> getDisplayDeviceLocked(const wp<IBinder>& displayToken) REQUIRES(mStateLock) { 912*38e8c45fSAndroid Build Coastguard Worker return mDisplays.get(displayToken) 913*38e8c45fSAndroid Build Coastguard Worker .or_else(ftl::static_ref<sp<DisplayDevice>>([] { return nullptr; })) 914*38e8c45fSAndroid Build Coastguard Worker .value(); 915*38e8c45fSAndroid Build Coastguard Worker } 916*38e8c45fSAndroid Build Coastguard Worker getDisplayDeviceLocked(PhysicalDisplayId id)917*38e8c45fSAndroid Build Coastguard Worker sp<const DisplayDevice> getDisplayDeviceLocked(PhysicalDisplayId id) const 918*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mStateLock) { 919*38e8c45fSAndroid Build Coastguard Worker return const_cast<SurfaceFlinger*>(this)->getDisplayDeviceLocked(id); 920*38e8c45fSAndroid Build Coastguard Worker } 921*38e8c45fSAndroid Build Coastguard Worker getDisplayDeviceLocked(PhysicalDisplayId id)922*38e8c45fSAndroid Build Coastguard Worker sp<DisplayDevice> getDisplayDeviceLocked(PhysicalDisplayId id) REQUIRES(mStateLock) { 923*38e8c45fSAndroid Build Coastguard Worker if (const auto token = getPhysicalDisplayTokenLocked(id)) { 924*38e8c45fSAndroid Build Coastguard Worker return getDisplayDeviceLocked(token); 925*38e8c45fSAndroid Build Coastguard Worker } 926*38e8c45fSAndroid Build Coastguard Worker return nullptr; 927*38e8c45fSAndroid Build Coastguard Worker } 928*38e8c45fSAndroid Build Coastguard Worker getDisplayDeviceLocked(DisplayId id)929*38e8c45fSAndroid Build Coastguard Worker sp<const DisplayDevice> getDisplayDeviceLocked(DisplayId id) const REQUIRES(mStateLock) { 930*38e8c45fSAndroid Build Coastguard Worker // TODO(b/182939859): Replace tokens with IDs for display lookup. 931*38e8c45fSAndroid Build Coastguard Worker return findDisplay([id](const auto& display) { return display.getId() == id; }); 932*38e8c45fSAndroid Build Coastguard Worker } 933*38e8c45fSAndroid Build Coastguard Worker getCompositionDisplayLocked(DisplayId id)934*38e8c45fSAndroid Build Coastguard Worker std::shared_ptr<compositionengine::Display> getCompositionDisplayLocked(DisplayId id) const 935*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mStateLock) { 936*38e8c45fSAndroid Build Coastguard Worker if (const auto display = getDisplayDeviceLocked(id)) { 937*38e8c45fSAndroid Build Coastguard Worker return display->getCompositionDisplay(); 938*38e8c45fSAndroid Build Coastguard Worker } 939*38e8c45fSAndroid Build Coastguard Worker return nullptr; 940*38e8c45fSAndroid Build Coastguard Worker } 941*38e8c45fSAndroid Build Coastguard Worker 942*38e8c45fSAndroid Build Coastguard Worker // Returns the primary display or (for foldables) the active display. getDefaultDisplayDeviceLocked()943*38e8c45fSAndroid Build Coastguard Worker sp<const DisplayDevice> getDefaultDisplayDeviceLocked() const REQUIRES(mStateLock) { 944*38e8c45fSAndroid Build Coastguard Worker return const_cast<SurfaceFlinger*>(this)->getDefaultDisplayDeviceLocked(); 945*38e8c45fSAndroid Build Coastguard Worker } 946*38e8c45fSAndroid Build Coastguard Worker getDefaultDisplayDeviceLocked()947*38e8c45fSAndroid Build Coastguard Worker sp<DisplayDevice> getDefaultDisplayDeviceLocked() REQUIRES(mStateLock) { 948*38e8c45fSAndroid Build Coastguard Worker return getDisplayDeviceLocked(mActiveDisplayId); 949*38e8c45fSAndroid Build Coastguard Worker } 950*38e8c45fSAndroid Build Coastguard Worker getDefaultDisplayDevice()951*38e8c45fSAndroid Build Coastguard Worker sp<const DisplayDevice> getDefaultDisplayDevice() const EXCLUDES(mStateLock) { 952*38e8c45fSAndroid Build Coastguard Worker Mutex::Autolock lock(mStateLock); 953*38e8c45fSAndroid Build Coastguard Worker return getDefaultDisplayDeviceLocked(); 954*38e8c45fSAndroid Build Coastguard Worker } 955*38e8c45fSAndroid Build Coastguard Worker 956*38e8c45fSAndroid Build Coastguard Worker using DisplayDeviceAndSnapshot = std::pair<sp<DisplayDevice>, display::DisplaySnapshotRef>; 957*38e8c45fSAndroid Build Coastguard Worker 958*38e8c45fSAndroid Build Coastguard Worker // Combinator for ftl::Optional<PhysicalDisplay>::and_then. getDisplayDeviceAndSnapshot()959*38e8c45fSAndroid Build Coastguard Worker auto getDisplayDeviceAndSnapshot() REQUIRES(mStateLock) { 960*38e8c45fSAndroid Build Coastguard Worker return [this](const display::PhysicalDisplay& display) REQUIRES( 961*38e8c45fSAndroid Build Coastguard Worker mStateLock) -> ftl::Optional<DisplayDeviceAndSnapshot> { 962*38e8c45fSAndroid Build Coastguard Worker if (auto device = getDisplayDeviceLocked(display.snapshot().displayId())) { 963*38e8c45fSAndroid Build Coastguard Worker return std::make_pair(std::move(device), display.snapshotRef()); 964*38e8c45fSAndroid Build Coastguard Worker } 965*38e8c45fSAndroid Build Coastguard Worker 966*38e8c45fSAndroid Build Coastguard Worker return {}; 967*38e8c45fSAndroid Build Coastguard Worker }; 968*38e8c45fSAndroid Build Coastguard Worker } 969*38e8c45fSAndroid Build Coastguard Worker 970*38e8c45fSAndroid Build Coastguard Worker // Returns the first display that matches a `bool(const DisplayDevice&)` predicate. 971*38e8c45fSAndroid Build Coastguard Worker template <typename Predicate> findDisplay(Predicate p)972*38e8c45fSAndroid Build Coastguard Worker sp<DisplayDevice> findDisplay(Predicate p) const REQUIRES(mStateLock) { 973*38e8c45fSAndroid Build Coastguard Worker const auto it = std::find_if(mDisplays.begin(), mDisplays.end(), 974*38e8c45fSAndroid Build Coastguard Worker [&](const auto& pair) 975*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mStateLock) { return p(*pair.second); }); 976*38e8c45fSAndroid Build Coastguard Worker 977*38e8c45fSAndroid Build Coastguard Worker return it == mDisplays.end() ? nullptr : it->second; 978*38e8c45fSAndroid Build Coastguard Worker } 979*38e8c45fSAndroid Build Coastguard Worker 980*38e8c45fSAndroid Build Coastguard Worker std::vector<PhysicalDisplayId> getPhysicalDisplayIdsLocked() const REQUIRES(mStateLock); 981*38e8c45fSAndroid Build Coastguard Worker 982*38e8c45fSAndroid Build Coastguard Worker // mark a region of a layer stack dirty. this updates the dirty 983*38e8c45fSAndroid Build Coastguard Worker // region of all screens presenting this layer stack. 984*38e8c45fSAndroid Build Coastguard Worker void invalidateLayerStack(const ui::LayerFilter& layerFilter, const Region& dirty); 985*38e8c45fSAndroid Build Coastguard Worker makeLayerFilterForDisplay(DisplayId displayId,ui::LayerStack layerStack)986*38e8c45fSAndroid Build Coastguard Worker ui::LayerFilter makeLayerFilterForDisplay(DisplayId displayId, ui::LayerStack layerStack) 987*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mStateLock) { 988*38e8c45fSAndroid Build Coastguard Worker return {layerStack, 989*38e8c45fSAndroid Build Coastguard Worker PhysicalDisplayId::tryCast(displayId) 990*38e8c45fSAndroid Build Coastguard Worker .and_then(display::getPhysicalDisplay(mPhysicalDisplays)) 991*38e8c45fSAndroid Build Coastguard Worker .transform(&display::PhysicalDisplay::isInternal) 992*38e8c45fSAndroid Build Coastguard Worker .value_or(false)}; 993*38e8c45fSAndroid Build Coastguard Worker } 994*38e8c45fSAndroid Build Coastguard Worker 995*38e8c45fSAndroid Build Coastguard Worker /* 996*38e8c45fSAndroid Build Coastguard Worker * H/W composer 997*38e8c45fSAndroid Build Coastguard Worker */ 998*38e8c45fSAndroid Build Coastguard Worker // The following thread safety rules apply when accessing HWComposer: 999*38e8c45fSAndroid Build Coastguard Worker // 1. When reading display state from HWComposer on the main thread, it's not necessary to 1000*38e8c45fSAndroid Build Coastguard Worker // acquire mStateLock. 1001*38e8c45fSAndroid Build Coastguard Worker // 2. When accessing HWComposer on a thread other than the main thread, we always 1002*38e8c45fSAndroid Build Coastguard Worker // need to acquire mStateLock. This is because the main thread could be 1003*38e8c45fSAndroid Build Coastguard Worker // in the process of writing display state, e.g. creating or destroying a display. 1004*38e8c45fSAndroid Build Coastguard Worker HWComposer& getHwComposer() const; 1005*38e8c45fSAndroid Build Coastguard Worker 1006*38e8c45fSAndroid Build Coastguard Worker /* 1007*38e8c45fSAndroid Build Coastguard Worker * Compositing 1008*38e8c45fSAndroid Build Coastguard Worker */ 1009*38e8c45fSAndroid Build Coastguard Worker void onCompositionPresented(PhysicalDisplayId pacesetterId, const scheduler::FrameTargeters&, 1010*38e8c45fSAndroid Build Coastguard Worker nsecs_t presentStartTime) REQUIRES(kMainThreadContext); 1011*38e8c45fSAndroid Build Coastguard Worker 1012*38e8c45fSAndroid Build Coastguard Worker /* 1013*38e8c45fSAndroid Build Coastguard Worker * Display management 1014*38e8c45fSAndroid Build Coastguard Worker */ 1015*38e8c45fSAndroid Build Coastguard Worker std::pair<DisplayModes, DisplayModePtr> loadDisplayModes(PhysicalDisplayId) const 1016*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mStateLock); 1017*38e8c45fSAndroid Build Coastguard Worker 1018*38e8c45fSAndroid Build Coastguard Worker // TODO(b/241285876): Move to DisplayConfigurator. 1019*38e8c45fSAndroid Build Coastguard Worker // 1020*38e8c45fSAndroid Build Coastguard Worker // Returns whether displays have been added/changed/removed, i.e. whether ICompositor should 1021*38e8c45fSAndroid Build Coastguard Worker // commit display transactions. 1022*38e8c45fSAndroid Build Coastguard Worker bool configureLocked() REQUIRES(mStateLock) REQUIRES(kMainThreadContext) 1023*38e8c45fSAndroid Build Coastguard Worker EXCLUDES(mHotplugMutex); 1024*38e8c45fSAndroid Build Coastguard Worker 1025*38e8c45fSAndroid Build Coastguard Worker // Returns the active mode ID, or nullopt on hotplug failure. 1026*38e8c45fSAndroid Build Coastguard Worker std::optional<DisplayModeId> processHotplugConnect(PhysicalDisplayId, hal::HWDisplayId, 1027*38e8c45fSAndroid Build Coastguard Worker DisplayIdentificationInfo&&, 1028*38e8c45fSAndroid Build Coastguard Worker const char* displayString) 1029*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mStateLock, kMainThreadContext); 1030*38e8c45fSAndroid Build Coastguard Worker void processHotplugDisconnect(PhysicalDisplayId, const char* displayString) 1031*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mStateLock, kMainThreadContext); 1032*38e8c45fSAndroid Build Coastguard Worker 1033*38e8c45fSAndroid Build Coastguard Worker sp<DisplayDevice> setupNewDisplayDeviceInternal( 1034*38e8c45fSAndroid Build Coastguard Worker const wp<IBinder>& displayToken, 1035*38e8c45fSAndroid Build Coastguard Worker std::shared_ptr<compositionengine::Display> compositionDisplay, 1036*38e8c45fSAndroid Build Coastguard Worker const DisplayDeviceState& state, 1037*38e8c45fSAndroid Build Coastguard Worker const sp<compositionengine::DisplaySurface>& displaySurface, 1038*38e8c45fSAndroid Build Coastguard Worker const sp<IGraphicBufferProducer>& producer) REQUIRES(mStateLock); 1039*38e8c45fSAndroid Build Coastguard Worker void processDisplayChangesLocked() REQUIRES(mStateLock, kMainThreadContext); 1040*38e8c45fSAndroid Build Coastguard Worker void processDisplayRemoved(const wp<IBinder>& displayToken) 1041*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mStateLock, kMainThreadContext); 1042*38e8c45fSAndroid Build Coastguard Worker void processDisplayChanged(const wp<IBinder>& displayToken, 1043*38e8c45fSAndroid Build Coastguard Worker const DisplayDeviceState& currentState, 1044*38e8c45fSAndroid Build Coastguard Worker const DisplayDeviceState& drawingState) 1045*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mStateLock, kMainThreadContext); 1046*38e8c45fSAndroid Build Coastguard Worker 1047*38e8c45fSAndroid Build Coastguard Worker /* 1048*38e8c45fSAndroid Build Coastguard Worker * Display identification 1049*38e8c45fSAndroid Build Coastguard Worker */ getPhysicalDisplayTokenLocked(PhysicalDisplayId displayId)1050*38e8c45fSAndroid Build Coastguard Worker sp<display::DisplayToken> getPhysicalDisplayTokenLocked(PhysicalDisplayId displayId) const 1051*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mStateLock) { 1052*38e8c45fSAndroid Build Coastguard Worker return mPhysicalDisplays.get(displayId) 1053*38e8c45fSAndroid Build Coastguard Worker .transform([](const display::PhysicalDisplay& display) { return display.token(); }) 1054*38e8c45fSAndroid Build Coastguard Worker .or_else([] { return std::optional<sp<display::DisplayToken>>(nullptr); }) 1055*38e8c45fSAndroid Build Coastguard Worker .value(); 1056*38e8c45fSAndroid Build Coastguard Worker } 1057*38e8c45fSAndroid Build Coastguard Worker 1058*38e8c45fSAndroid Build Coastguard Worker std::optional<PhysicalDisplayId> getPhysicalDisplayIdLocked( 1059*38e8c45fSAndroid Build Coastguard Worker const sp<display::DisplayToken>&) const REQUIRES(mStateLock); 1060*38e8c45fSAndroid Build Coastguard Worker 1061*38e8c45fSAndroid Build Coastguard Worker // Returns the first display connected at boot. 1062*38e8c45fSAndroid Build Coastguard Worker // 1063*38e8c45fSAndroid Build Coastguard Worker // TODO(b/229851933): SF conflates the primary display with the first display connected at boot, 1064*38e8c45fSAndroid Build Coastguard Worker // which typically has DisplayConnectionType::Internal. (Theoretically, it must be an internal 1065*38e8c45fSAndroid Build Coastguard Worker // display because SF does not support disconnecting it, though in practice HWC may circumvent 1066*38e8c45fSAndroid Build Coastguard Worker // this limitation.) getPrimaryDisplayTokenLocked()1067*38e8c45fSAndroid Build Coastguard Worker sp<IBinder> getPrimaryDisplayTokenLocked() const REQUIRES(mStateLock) { 1068*38e8c45fSAndroid Build Coastguard Worker return getPhysicalDisplayTokenLocked(getPrimaryDisplayIdLocked()); 1069*38e8c45fSAndroid Build Coastguard Worker } 1070*38e8c45fSAndroid Build Coastguard Worker getPrimaryDisplayIdLocked()1071*38e8c45fSAndroid Build Coastguard Worker PhysicalDisplayId getPrimaryDisplayIdLocked() const REQUIRES(mStateLock) { 1072*38e8c45fSAndroid Build Coastguard Worker return getHwComposer().getPrimaryDisplayId(); 1073*38e8c45fSAndroid Build Coastguard Worker } 1074*38e8c45fSAndroid Build Coastguard Worker 1075*38e8c45fSAndroid Build Coastguard Worker // Toggles use of HAL/GPU virtual displays. 1076*38e8c45fSAndroid Build Coastguard Worker void enableHalVirtualDisplays(bool); 1077*38e8c45fSAndroid Build Coastguard Worker 1078*38e8c45fSAndroid Build Coastguard Worker // Virtual display lifecycle for ID generation and HAL allocation. 1079*38e8c45fSAndroid Build Coastguard Worker VirtualDisplayId acquireVirtualDisplay(ui::Size, ui::PixelFormat, const std::string& uniqueId) 1080*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mStateLock); 1081*38e8c45fSAndroid Build Coastguard Worker template <typename ID> acquireVirtualDisplaySnapshot(ID displayId,const std::string & uniqueId)1082*38e8c45fSAndroid Build Coastguard Worker void acquireVirtualDisplaySnapshot(ID displayId, const std::string& uniqueId) { 1083*38e8c45fSAndroid Build Coastguard Worker std::lock_guard lock(mVirtualDisplaysMutex); 1084*38e8c45fSAndroid Build Coastguard Worker const bool emplace_success = 1085*38e8c45fSAndroid Build Coastguard Worker mVirtualDisplays.try_emplace(displayId, displayId, uniqueId).second; 1086*38e8c45fSAndroid Build Coastguard Worker if (!emplace_success) { 1087*38e8c45fSAndroid Build Coastguard Worker ALOGW("%s: Virtual display snapshot with the same ID already exists", __func__); 1088*38e8c45fSAndroid Build Coastguard Worker } 1089*38e8c45fSAndroid Build Coastguard Worker } 1090*38e8c45fSAndroid Build Coastguard Worker 1091*38e8c45fSAndroid Build Coastguard Worker void releaseVirtualDisplay(VirtualDisplayId); 1092*38e8c45fSAndroid Build Coastguard Worker void releaseVirtualDisplaySnapshot(VirtualDisplayId displayId); 1093*38e8c45fSAndroid Build Coastguard Worker 1094*38e8c45fSAndroid Build Coastguard Worker // Returns a display other than `mActiveDisplayId` that can be activated, if any. 1095*38e8c45fSAndroid Build Coastguard Worker sp<DisplayDevice> getActivatableDisplay() const REQUIRES(mStateLock, kMainThreadContext); 1096*38e8c45fSAndroid Build Coastguard Worker 1097*38e8c45fSAndroid Build Coastguard Worker void onActiveDisplayChangedLocked(const DisplayDevice* inactiveDisplayPtr, 1098*38e8c45fSAndroid Build Coastguard Worker const DisplayDevice& activeDisplay) 1099*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mStateLock, kMainThreadContext); 1100*38e8c45fSAndroid Build Coastguard Worker 1101*38e8c45fSAndroid Build Coastguard Worker void onActiveDisplaySizeChanged(const DisplayDevice&); 1102*38e8c45fSAndroid Build Coastguard Worker 1103*38e8c45fSAndroid Build Coastguard Worker /* 1104*38e8c45fSAndroid Build Coastguard Worker * Debugging & dumpsys 1105*38e8c45fSAndroid Build Coastguard Worker */ 1106*38e8c45fSAndroid Build Coastguard Worker void dumpAll(const DumpArgs& args, const std::string& compositionLayers, 1107*38e8c45fSAndroid Build Coastguard Worker std::string& result) const EXCLUDES(mStateLock); 1108*38e8c45fSAndroid Build Coastguard Worker void dumpHwcLayersMinidump(std::string& result) const REQUIRES(mStateLock, kMainThreadContext); 1109*38e8c45fSAndroid Build Coastguard Worker 1110*38e8c45fSAndroid Build Coastguard Worker void appendSfConfigString(std::string& result) const; 1111*38e8c45fSAndroid Build Coastguard Worker void listLayers(std::string& result) const REQUIRES(kMainThreadContext); 1112*38e8c45fSAndroid Build Coastguard Worker void dumpStats(const DumpArgs& args, std::string& result) const 1113*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mStateLock, kMainThreadContext); 1114*38e8c45fSAndroid Build Coastguard Worker void clearStats(const DumpArgs& args, std::string& result) REQUIRES(kMainThreadContext); 1115*38e8c45fSAndroid Build Coastguard Worker void dumpTimeStats(const DumpArgs& args, bool asProto, std::string& result) const; 1116*38e8c45fSAndroid Build Coastguard Worker void dumpFrameTimeline(const DumpArgs& args, std::string& result) const; 1117*38e8c45fSAndroid Build Coastguard Worker void logFrameStats(TimePoint now) REQUIRES(kMainThreadContext); 1118*38e8c45fSAndroid Build Coastguard Worker 1119*38e8c45fSAndroid Build Coastguard Worker void dumpScheduler(std::string& result) const REQUIRES(mStateLock); 1120*38e8c45fSAndroid Build Coastguard Worker void dumpEvents(std::string& result) const REQUIRES(mStateLock); 1121*38e8c45fSAndroid Build Coastguard Worker void dumpVsync(std::string& result) const REQUIRES(mStateLock); 1122*38e8c45fSAndroid Build Coastguard Worker 1123*38e8c45fSAndroid Build Coastguard Worker void dumpCompositionDisplays(std::string& result) const REQUIRES(mStateLock); 1124*38e8c45fSAndroid Build Coastguard Worker void dumpDisplays(std::string& result) const REQUIRES(mStateLock); 1125*38e8c45fSAndroid Build Coastguard Worker void dumpDisplayIdentificationData(std::string& result) const REQUIRES(mStateLock); 1126*38e8c45fSAndroid Build Coastguard Worker void dumpRawDisplayIdentificationData(const DumpArgs&, std::string& result) const; 1127*38e8c45fSAndroid Build Coastguard Worker void dumpWideColorInfo(std::string& result) const REQUIRES(mStateLock); 1128*38e8c45fSAndroid Build Coastguard Worker void dumpHdrInfo(std::string& result) const REQUIRES(mStateLock); 1129*38e8c45fSAndroid Build Coastguard Worker void dumpFrontEnd(std::string& result) REQUIRES(kMainThreadContext); 1130*38e8c45fSAndroid Build Coastguard Worker void dumpVisibleFrontEnd(std::string& result) REQUIRES(mStateLock, kMainThreadContext); 1131*38e8c45fSAndroid Build Coastguard Worker 1132*38e8c45fSAndroid Build Coastguard Worker perfetto::protos::LayersProto dumpDrawingStateProto(uint32_t traceFlags) const 1133*38e8c45fSAndroid Build Coastguard Worker REQUIRES(kMainThreadContext); 1134*38e8c45fSAndroid Build Coastguard Worker google::protobuf::RepeatedPtrField<perfetto::protos::DisplayProto> dumpDisplayProto() const; 1135*38e8c45fSAndroid Build Coastguard Worker void doActiveLayersTracingIfNeeded(bool isCompositionComputed, bool visibleRegionDirty, 1136*38e8c45fSAndroid Build Coastguard Worker TimePoint, VsyncId) REQUIRES(kMainThreadContext); 1137*38e8c45fSAndroid Build Coastguard Worker perfetto::protos::LayersSnapshotProto takeLayersSnapshotProto(uint32_t flags, TimePoint, 1138*38e8c45fSAndroid Build Coastguard Worker VsyncId, bool visibleRegionDirty) 1139*38e8c45fSAndroid Build Coastguard Worker REQUIRES(kMainThreadContext); 1140*38e8c45fSAndroid Build Coastguard Worker 1141*38e8c45fSAndroid Build Coastguard Worker // Dumps state from HW Composer 1142*38e8c45fSAndroid Build Coastguard Worker void dumpHwc(std::string& result) const; 1143*38e8c45fSAndroid Build Coastguard Worker perfetto::protos::LayersProto dumpProtoFromMainThread( 1144*38e8c45fSAndroid Build Coastguard Worker uint32_t traceFlags = LayerTracing::TRACE_ALL) EXCLUDES(mStateLock); 1145*38e8c45fSAndroid Build Coastguard Worker void dumpPlannerInfo(const DumpArgs& args, std::string& result) const REQUIRES(mStateLock); 1146*38e8c45fSAndroid Build Coastguard Worker 1147*38e8c45fSAndroid Build Coastguard Worker status_t doDump(int fd, const DumpArgs& args, bool asProto); 1148*38e8c45fSAndroid Build Coastguard Worker 1149*38e8c45fSAndroid Build Coastguard Worker status_t dumpCritical(int fd, const DumpArgs&, bool asProto); 1150*38e8c45fSAndroid Build Coastguard Worker dumpAll(int fd,const DumpArgs & args,bool asProto)1151*38e8c45fSAndroid Build Coastguard Worker status_t dumpAll(int fd, const DumpArgs& args, bool asProto) override { 1152*38e8c45fSAndroid Build Coastguard Worker return doDump(fd, args, asProto); 1153*38e8c45fSAndroid Build Coastguard Worker } 1154*38e8c45fSAndroid Build Coastguard Worker 1155*38e8c45fSAndroid Build Coastguard Worker static mat4 calculateColorMatrix(float saturation); 1156*38e8c45fSAndroid Build Coastguard Worker 1157*38e8c45fSAndroid Build Coastguard Worker void updateColorMatrixLocked(); 1158*38e8c45fSAndroid Build Coastguard Worker 1159*38e8c45fSAndroid Build Coastguard Worker // Verify that transaction is being called by an approved process: 1160*38e8c45fSAndroid Build Coastguard Worker // either AID_GRAPHICS or AID_SYSTEM. 1161*38e8c45fSAndroid Build Coastguard Worker status_t CheckTransactCodeCredentials(uint32_t code); 1162*38e8c45fSAndroid Build Coastguard Worker 1163*38e8c45fSAndroid Build Coastguard Worker // Add transaction to the Transaction Queue 1164*38e8c45fSAndroid Build Coastguard Worker 1165*38e8c45fSAndroid Build Coastguard Worker /* 1166*38e8c45fSAndroid Build Coastguard Worker * Generic Layer Metadata 1167*38e8c45fSAndroid Build Coastguard Worker */ 1168*38e8c45fSAndroid Build Coastguard Worker const std::unordered_map<std::string, uint32_t>& getGenericLayerMetadataKeyMap() const; 1169*38e8c45fSAndroid Build Coastguard Worker 1170*38e8c45fSAndroid Build Coastguard Worker static int calculateMaxAcquiredBufferCount(Fps refreshRate, 1171*38e8c45fSAndroid Build Coastguard Worker std::chrono::nanoseconds presentLatency); 1172*38e8c45fSAndroid Build Coastguard Worker int getMaxAcquiredBufferCountForRefreshRate(Fps refreshRate) const; 1173*38e8c45fSAndroid Build Coastguard Worker 1174*38e8c45fSAndroid Build Coastguard Worker bool isHdrLayer(const frontend::LayerSnapshot& snapshot) const; 1175*38e8c45fSAndroid Build Coastguard Worker 1176*38e8c45fSAndroid Build Coastguard Worker ui::Rotation getPhysicalDisplayOrientation(DisplayId, bool isPrimary) const 1177*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mStateLock); 1178*38e8c45fSAndroid Build Coastguard Worker void traverseLegacyLayers(const LayerVector::Visitor& visitor) const 1179*38e8c45fSAndroid Build Coastguard Worker REQUIRES(kMainThreadContext); 1180*38e8c45fSAndroid Build Coastguard Worker 1181*38e8c45fSAndroid Build Coastguard Worker void initBootProperties(); 1182*38e8c45fSAndroid Build Coastguard Worker void initTransactionTraceWriter(); 1183*38e8c45fSAndroid Build Coastguard Worker 1184*38e8c45fSAndroid Build Coastguard Worker surfaceflinger::Factory& mFactory; 1185*38e8c45fSAndroid Build Coastguard Worker pid_t mPid; 1186*38e8c45fSAndroid Build Coastguard Worker 1187*38e8c45fSAndroid Build Coastguard Worker // TODO: b/328459745 - Encapsulate in a SystemProperties object. 1188*38e8c45fSAndroid Build Coastguard Worker utils::OnceFuture mInitBootPropsFuture; 1189*38e8c45fSAndroid Build Coastguard Worker 1190*38e8c45fSAndroid Build Coastguard Worker utils::OnceFuture mRenderEnginePrimeCacheFuture; 1191*38e8c45fSAndroid Build Coastguard Worker 1192*38e8c45fSAndroid Build Coastguard Worker // mStateLock has conventions related to the current thread, because only 1193*38e8c45fSAndroid Build Coastguard Worker // the main thread should modify variables protected by mStateLock. 1194*38e8c45fSAndroid Build Coastguard Worker // - read access from a non-main thread must lock mStateLock, since the main 1195*38e8c45fSAndroid Build Coastguard Worker // thread may modify these variables. 1196*38e8c45fSAndroid Build Coastguard Worker // - write access from a non-main thread is not permitted. 1197*38e8c45fSAndroid Build Coastguard Worker // - read access from the main thread can use an ftl::FakeGuard, since other 1198*38e8c45fSAndroid Build Coastguard Worker // threads must not modify these variables. 1199*38e8c45fSAndroid Build Coastguard Worker // - write access from the main thread must lock mStateLock, since another 1200*38e8c45fSAndroid Build Coastguard Worker // thread may be reading these variables. 1201*38e8c45fSAndroid Build Coastguard Worker mutable Mutex mStateLock; 1202*38e8c45fSAndroid Build Coastguard Worker State mCurrentState{LayerVector::StateSet::Current}; 1203*38e8c45fSAndroid Build Coastguard Worker std::atomic<int32_t> mTransactionFlags = 0; 1204*38e8c45fSAndroid Build Coastguard Worker std::atomic<uint32_t> mUniqueTransactionId = 1; 1205*38e8c45fSAndroid Build Coastguard Worker 1206*38e8c45fSAndroid Build Coastguard Worker // Buffers that have been discarded by clients and need to be evicted from per-layer caches so 1207*38e8c45fSAndroid Build Coastguard Worker // the graphics memory can be immediately freed. 1208*38e8c45fSAndroid Build Coastguard Worker std::vector<uint64_t> mBufferIdsToUncache; 1209*38e8c45fSAndroid Build Coastguard Worker 1210*38e8c45fSAndroid Build Coastguard Worker // global color transform states 1211*38e8c45fSAndroid Build Coastguard Worker Daltonizer mDaltonizer; 1212*38e8c45fSAndroid Build Coastguard Worker float mGlobalSaturationFactor = 1.0f; 1213*38e8c45fSAndroid Build Coastguard Worker mat4 mClientColorMatrix; 1214*38e8c45fSAndroid Build Coastguard Worker 1215*38e8c45fSAndroid Build Coastguard Worker // protected by mStateLock (but we could use another lock) 1216*38e8c45fSAndroid Build Coastguard Worker bool mLayersRemoved = false; 1217*38e8c45fSAndroid Build Coastguard Worker bool mLayersAdded = false; 1218*38e8c45fSAndroid Build Coastguard Worker 1219*38e8c45fSAndroid Build Coastguard Worker std::atomic_bool mMustComposite = false; 1220*38e8c45fSAndroid Build Coastguard Worker std::atomic_bool mGeometryDirty = false; 1221*38e8c45fSAndroid Build Coastguard Worker 1222*38e8c45fSAndroid Build Coastguard Worker // constant members (no synchronization needed for access) 1223*38e8c45fSAndroid Build Coastguard Worker const nsecs_t mBootTime = systemTime(); 1224*38e8c45fSAndroid Build Coastguard Worker bool mIsUserBuild = true; 1225*38e8c45fSAndroid Build Coastguard Worker bool mHasReliablePresentFences = false; 1226*38e8c45fSAndroid Build Coastguard Worker 1227*38e8c45fSAndroid Build Coastguard Worker // Can only accessed from the main thread, these members 1228*38e8c45fSAndroid Build Coastguard Worker // don't need synchronization 1229*38e8c45fSAndroid Build Coastguard Worker State mDrawingState{LayerVector::StateSet::Drawing}; 1230*38e8c45fSAndroid Build Coastguard Worker bool mVisibleRegionsDirty = false; 1231*38e8c45fSAndroid Build Coastguard Worker 1232*38e8c45fSAndroid Build Coastguard Worker bool mHdrLayerInfoChanged = false; 1233*38e8c45fSAndroid Build Coastguard Worker 1234*38e8c45fSAndroid Build Coastguard Worker struct LayerEvent { 1235*38e8c45fSAndroid Build Coastguard Worker uid_t uid; 1236*38e8c45fSAndroid Build Coastguard Worker int32_t layerId; 1237*38e8c45fSAndroid Build Coastguard Worker ui::Dataspace dataspace; 1238*38e8c45fSAndroid Build Coastguard Worker std::chrono::milliseconds timeSinceLastEvent; 1239*38e8c45fSAndroid Build Coastguard Worker }; 1240*38e8c45fSAndroid Build Coastguard Worker std::vector<LayerEvent> mLayerEvents; 1241*38e8c45fSAndroid Build Coastguard Worker 1242*38e8c45fSAndroid Build Coastguard Worker // Used to ensure we omit a callback when HDR layer info listener is newly added but the 1243*38e8c45fSAndroid Build Coastguard Worker // scene hasn't changed 1244*38e8c45fSAndroid Build Coastguard Worker bool mAddingHDRLayerInfoListener = false; 1245*38e8c45fSAndroid Build Coastguard Worker bool mIgnoreHdrCameraLayers = false; 1246*38e8c45fSAndroid Build Coastguard Worker 1247*38e8c45fSAndroid Build Coastguard Worker // Set during transaction application stage to track if the input info or children 1248*38e8c45fSAndroid Build Coastguard Worker // for a layer has changed. 1249*38e8c45fSAndroid Build Coastguard Worker // TODO: Also move visibleRegions over to a boolean system. 1250*38e8c45fSAndroid Build Coastguard Worker bool mUpdateInputInfo = false; 1251*38e8c45fSAndroid Build Coastguard Worker bool mSomeChildrenChanged; 1252*38e8c45fSAndroid Build Coastguard Worker bool mUpdateAttachedChoreographer = false; 1253*38e8c45fSAndroid Build Coastguard Worker 1254*38e8c45fSAndroid Build Coastguard Worker struct LayerIntHash { operatorLayerIntHash1255*38e8c45fSAndroid Build Coastguard Worker size_t operator()(const std::pair<sp<Layer>, gui::GameMode>& k) const { 1256*38e8c45fSAndroid Build Coastguard Worker return std::hash<Layer*>()(k.first.get()) ^ 1257*38e8c45fSAndroid Build Coastguard Worker std::hash<int32_t>()(static_cast<int32_t>(k.second)); 1258*38e8c45fSAndroid Build Coastguard Worker } 1259*38e8c45fSAndroid Build Coastguard Worker }; 1260*38e8c45fSAndroid Build Coastguard Worker 1261*38e8c45fSAndroid Build Coastguard Worker // TODO(b/238781169) validate these on composition 1262*38e8c45fSAndroid Build Coastguard Worker // Tracks layers that have pending frames which are candidates for being 1263*38e8c45fSAndroid Build Coastguard Worker // latched. 1264*38e8c45fSAndroid Build Coastguard Worker std::unordered_set<std::pair<sp<Layer>, gui::GameMode>, LayerIntHash> mLayersWithQueuedFrames; 1265*38e8c45fSAndroid Build Coastguard Worker std::unordered_set<sp<Layer>, SpHash<Layer>> mLayersWithBuffersRemoved; 1266*38e8c45fSAndroid Build Coastguard Worker 1267*38e8c45fSAndroid Build Coastguard Worker // Sorted list of layers that were composed during previous frame. This is used to 1268*38e8c45fSAndroid Build Coastguard Worker // avoid an expensive traversal of the layer hierarchy when there are no 1269*38e8c45fSAndroid Build Coastguard Worker // visible region changes. Because this is a list of strong pointers, this will 1270*38e8c45fSAndroid Build Coastguard Worker // extend the life of the layer but this list is only updated in the main thread. 1271*38e8c45fSAndroid Build Coastguard Worker std::vector<sp<Layer>> mPreviouslyComposedLayers; 1272*38e8c45fSAndroid Build Coastguard Worker 1273*38e8c45fSAndroid Build Coastguard Worker BootStage mBootStage = BootStage::BOOTLOADER; 1274*38e8c45fSAndroid Build Coastguard Worker 1275*38e8c45fSAndroid Build Coastguard Worker struct HotplugEvent { 1276*38e8c45fSAndroid Build Coastguard Worker hal::HWDisplayId hwcDisplayId; 1277*38e8c45fSAndroid Build Coastguard Worker hal::Connection connection = hal::Connection::INVALID; 1278*38e8c45fSAndroid Build Coastguard Worker }; 1279*38e8c45fSAndroid Build Coastguard Worker 1280*38e8c45fSAndroid Build Coastguard Worker bool mIsHdcpViaNegVsync = false; 1281*38e8c45fSAndroid Build Coastguard Worker 1282*38e8c45fSAndroid Build Coastguard Worker std::mutex mHotplugMutex; 1283*38e8c45fSAndroid Build Coastguard Worker std::vector<HotplugEvent> mPendingHotplugEvents GUARDED_BY(mHotplugMutex); 1284*38e8c45fSAndroid Build Coastguard Worker 1285*38e8c45fSAndroid Build Coastguard Worker // Displays are composited in `mDisplays` order. Internal displays are inserted at boot and 1286*38e8c45fSAndroid Build Coastguard Worker // never removed, so take precedence over external and virtual displays. 1287*38e8c45fSAndroid Build Coastguard Worker // 1288*38e8c45fSAndroid Build Coastguard Worker // May be read from any thread, but must only be written from the main thread. 1289*38e8c45fSAndroid Build Coastguard Worker ui::DisplayMap<wp<IBinder>, const sp<DisplayDevice>> mDisplays GUARDED_BY(mStateLock); 1290*38e8c45fSAndroid Build Coastguard Worker 1291*38e8c45fSAndroid Build Coastguard Worker display::PhysicalDisplays mPhysicalDisplays GUARDED_BY(mStateLock); 1292*38e8c45fSAndroid Build Coastguard Worker 1293*38e8c45fSAndroid Build Coastguard Worker mutable std::mutex mVirtualDisplaysMutex; 1294*38e8c45fSAndroid Build Coastguard Worker ftl::SmallMap<VirtualDisplayId, const display::VirtualDisplaySnapshot, 2> mVirtualDisplays 1295*38e8c45fSAndroid Build Coastguard Worker GUARDED_BY(mVirtualDisplaysMutex); 1296*38e8c45fSAndroid Build Coastguard Worker 1297*38e8c45fSAndroid Build Coastguard Worker // The inner or outer display for foldables, while unfolded or folded, respectively. 1298*38e8c45fSAndroid Build Coastguard Worker std::atomic<PhysicalDisplayId> mActiveDisplayId; 1299*38e8c45fSAndroid Build Coastguard Worker 1300*38e8c45fSAndroid Build Coastguard Worker display::DisplayModeController mDisplayModeController; 1301*38e8c45fSAndroid Build Coastguard Worker 1302*38e8c45fSAndroid Build Coastguard Worker struct { 1303*38e8c45fSAndroid Build Coastguard Worker DisplayIdGenerator<GpuVirtualDisplayId> gpu; 1304*38e8c45fSAndroid Build Coastguard Worker std::optional<DisplayIdGenerator<HalVirtualDisplayId>> hal; 1305*38e8c45fSAndroid Build Coastguard Worker } mVirtualDisplayIdGenerators; 1306*38e8c45fSAndroid Build Coastguard Worker 1307*38e8c45fSAndroid Build Coastguard Worker std::atomic_uint mDebugFlashDelay = 0; 1308*38e8c45fSAndroid Build Coastguard Worker std::atomic_bool mDebugDisableHWC = false; 1309*38e8c45fSAndroid Build Coastguard Worker std::atomic_bool mDebugDisableTransformHint = false; 1310*38e8c45fSAndroid Build Coastguard Worker std::atomic<nsecs_t> mDebugInTransaction = 0; 1311*38e8c45fSAndroid Build Coastguard Worker std::atomic_bool mForceFullDamage = false; 1312*38e8c45fSAndroid Build Coastguard Worker 1313*38e8c45fSAndroid Build Coastguard Worker bool mLayerCachingEnabled = false; 1314*38e8c45fSAndroid Build Coastguard Worker bool mBackpressureGpuComposition = false; 1315*38e8c45fSAndroid Build Coastguard Worker 1316*38e8c45fSAndroid Build Coastguard Worker LayerTracing mLayerTracing; 1317*38e8c45fSAndroid Build Coastguard Worker std::optional<TransactionTracing> mTransactionTracing; 1318*38e8c45fSAndroid Build Coastguard Worker 1319*38e8c45fSAndroid Build Coastguard Worker const std::shared_ptr<TimeStats> mTimeStats; 1320*38e8c45fSAndroid Build Coastguard Worker const std::unique_ptr<FrameTracer> mFrameTracer; 1321*38e8c45fSAndroid Build Coastguard Worker const std::unique_ptr<frametimeline::FrameTimeline> mFrameTimeline; 1322*38e8c45fSAndroid Build Coastguard Worker 1323*38e8c45fSAndroid Build Coastguard Worker VsyncId mLastCommittedVsyncId; 1324*38e8c45fSAndroid Build Coastguard Worker 1325*38e8c45fSAndroid Build Coastguard Worker // If blurs should be enabled on this device. 1326*38e8c45fSAndroid Build Coastguard Worker bool mSupportsBlur = false; 1327*38e8c45fSAndroid Build Coastguard Worker 1328*38e8c45fSAndroid Build Coastguard Worker TransactionCallbackInvoker mTransactionCallbackInvoker; 1329*38e8c45fSAndroid Build Coastguard Worker 1330*38e8c45fSAndroid Build Coastguard Worker std::atomic<size_t> mNumLayers = 0; 1331*38e8c45fSAndroid Build Coastguard Worker 1332*38e8c45fSAndroid Build Coastguard Worker // to linkToDeath 1333*38e8c45fSAndroid Build Coastguard Worker sp<IBinder> mWindowManager; 1334*38e8c45fSAndroid Build Coastguard Worker // We want to avoid multiple calls to BOOT_FINISHED as they come in on 1335*38e8c45fSAndroid Build Coastguard Worker // different threads without a lock and could trigger unsynchronized writes to 1336*38e8c45fSAndroid Build Coastguard Worker // to mWindowManager or mInputFlinger 1337*38e8c45fSAndroid Build Coastguard Worker std::atomic<bool> mBootFinished = false; 1338*38e8c45fSAndroid Build Coastguard Worker 1339*38e8c45fSAndroid Build Coastguard Worker std::thread::id mMainThreadId = std::this_thread::get_id(); 1340*38e8c45fSAndroid Build Coastguard Worker 1341*38e8c45fSAndroid Build Coastguard Worker DisplayColorSetting mDisplayColorSetting = DisplayColorSetting::kEnhanced; 1342*38e8c45fSAndroid Build Coastguard Worker 1343*38e8c45fSAndroid Build Coastguard Worker // Color mode forced by setting persist.sys.sf.color_mode, it must: 1344*38e8c45fSAndroid Build Coastguard Worker // 1. not be NATIVE color mode, NATIVE color mode means no forced color mode; 1345*38e8c45fSAndroid Build Coastguard Worker // 2. be one of the supported color modes returned by hardware composer, otherwise 1346*38e8c45fSAndroid Build Coastguard Worker // it will not be respected. 1347*38e8c45fSAndroid Build Coastguard Worker // persist.sys.sf.color_mode will only take effect when persist.sys.sf.native_mode 1348*38e8c45fSAndroid Build Coastguard Worker // is not set to 1. 1349*38e8c45fSAndroid Build Coastguard Worker // This property can be used to force SurfaceFlinger to always pick a certain color mode. 1350*38e8c45fSAndroid Build Coastguard Worker ui::ColorMode mForceColorMode = ui::ColorMode::NATIVE; 1351*38e8c45fSAndroid Build Coastguard Worker 1352*38e8c45fSAndroid Build Coastguard Worker // Whether to enable wide color gamut (e.g. Display P3) for internal displays that support it. 1353*38e8c45fSAndroid Build Coastguard Worker // If false, wide color modes are filtered out for all internal displays. 1354*38e8c45fSAndroid Build Coastguard Worker bool mSupportsWideColor = false; 1355*38e8c45fSAndroid Build Coastguard Worker 1356*38e8c45fSAndroid Build Coastguard Worker ui::Dataspace mDefaultCompositionDataspace; 1357*38e8c45fSAndroid Build Coastguard Worker ui::Dataspace mWideColorGamutCompositionDataspace; 1358*38e8c45fSAndroid Build Coastguard Worker 1359*38e8c45fSAndroid Build Coastguard Worker std::unique_ptr<renderengine::RenderEngine> mRenderEngine; 1360*38e8c45fSAndroid Build Coastguard Worker std::atomic<int> mNumTrustedPresentationListeners = 0; 1361*38e8c45fSAndroid Build Coastguard Worker 1362*38e8c45fSAndroid Build Coastguard Worker std::unique_ptr<compositionengine::CompositionEngine> mCompositionEngine; 1363*38e8c45fSAndroid Build Coastguard Worker 1364*38e8c45fSAndroid Build Coastguard Worker CompositionCoveragePerDisplay mCompositionCoverage; 1365*38e8c45fSAndroid Build Coastguard Worker 1366*38e8c45fSAndroid Build Coastguard Worker // mMaxRenderTargetSize is only set once in init() so it doesn't need to be protected by 1367*38e8c45fSAndroid Build Coastguard Worker // any mutex. 1368*38e8c45fSAndroid Build Coastguard Worker size_t mMaxRenderTargetSize{1}; 1369*38e8c45fSAndroid Build Coastguard Worker 1370*38e8c45fSAndroid Build Coastguard Worker const std::string mHwcServiceName; 1371*38e8c45fSAndroid Build Coastguard Worker 1372*38e8c45fSAndroid Build Coastguard Worker std::unique_ptr<scheduler::Scheduler> mScheduler; 1373*38e8c45fSAndroid Build Coastguard Worker 1374*38e8c45fSAndroid Build Coastguard Worker scheduler::PresentLatencyTracker mPresentLatencyTracker GUARDED_BY(kMainThreadContext); 1375*38e8c45fSAndroid Build Coastguard Worker 1376*38e8c45fSAndroid Build Coastguard Worker bool mLumaSampling = true; 1377*38e8c45fSAndroid Build Coastguard Worker sp<RegionSamplingThread> mRegionSamplingThread; 1378*38e8c45fSAndroid Build Coastguard Worker sp<FpsReporter> mFpsReporter; 1379*38e8c45fSAndroid Build Coastguard Worker sp<TunnelModeEnabledReporter> mTunnelModeEnabledReporter; 1380*38e8c45fSAndroid Build Coastguard Worker ui::DisplayPrimaries mInternalDisplayPrimaries; 1381*38e8c45fSAndroid Build Coastguard Worker 1382*38e8c45fSAndroid Build Coastguard Worker const float mEmulatedDisplayDensity; 1383*38e8c45fSAndroid Build Coastguard Worker const float mInternalDisplayDensity; 1384*38e8c45fSAndroid Build Coastguard Worker 1385*38e8c45fSAndroid Build Coastguard Worker // Should only be accessed by the main thread. 1386*38e8c45fSAndroid Build Coastguard Worker sp<os::IInputFlinger> mInputFlinger; 1387*38e8c45fSAndroid Build Coastguard Worker InputWindowCommands mInputWindowCommands; 1388*38e8c45fSAndroid Build Coastguard Worker 1389*38e8c45fSAndroid Build Coastguard Worker std::unique_ptr<adpf::PowerAdvisor> mPowerAdvisor; 1390*38e8c45fSAndroid Build Coastguard Worker 1391*38e8c45fSAndroid Build Coastguard Worker void enableRefreshRateOverlay(bool enable) REQUIRES(mStateLock, kMainThreadContext); 1392*38e8c45fSAndroid Build Coastguard Worker 1393*38e8c45fSAndroid Build Coastguard Worker void enableHdrSdrRatioOverlay(bool enable) REQUIRES(mStateLock, kMainThreadContext); 1394*38e8c45fSAndroid Build Coastguard Worker 1395*38e8c45fSAndroid Build Coastguard Worker // Flag used to set override desired display mode from backdoor 1396*38e8c45fSAndroid Build Coastguard Worker bool mDebugDisplayModeSetByBackdoor = false; 1397*38e8c45fSAndroid Build Coastguard Worker 1398*38e8c45fSAndroid Build Coastguard Worker // Tracks the number of maximum queued buffers by layer owner Uid. 1399*38e8c45fSAndroid Build Coastguard Worker using BufferStuffingMap = ftl::SmallMap<uid_t, uint32_t, 10>; 1400*38e8c45fSAndroid Build Coastguard Worker BufferCountTracker mBufferCountTracker; 1401*38e8c45fSAndroid Build Coastguard Worker 1402*38e8c45fSAndroid Build Coastguard Worker std::unordered_map<DisplayId, sp<HdrLayerInfoReporter>> mHdrLayerInfoListeners 1403*38e8c45fSAndroid Build Coastguard Worker GUARDED_BY(mStateLock); 1404*38e8c45fSAndroid Build Coastguard Worker 1405*38e8c45fSAndroid Build Coastguard Worker sp<gui::IActivePictureListener> mActivePictureListener GUARDED_BY(mStateLock); 1406*38e8c45fSAndroid Build Coastguard Worker bool mHaveNewActivePictureListener GUARDED_BY(mStateLock); 1407*38e8c45fSAndroid Build Coastguard Worker ActivePictureUpdater mActivePictureUpdater GUARDED_BY(kMainThreadContext); 1408*38e8c45fSAndroid Build Coastguard Worker 1409*38e8c45fSAndroid Build Coastguard Worker std::atomic<ui::Transform::RotationFlags> mActiveDisplayTransformHint; 1410*38e8c45fSAndroid Build Coastguard Worker 1411*38e8c45fSAndroid Build Coastguard Worker // Must only be accessed on the main thread. 1412*38e8c45fSAndroid Build Coastguard Worker // TODO (b/259407931): Remove. 1413*38e8c45fSAndroid Build Coastguard Worker static ui::Transform::RotationFlags sActiveDisplayRotationFlags; 1414*38e8c45fSAndroid Build Coastguard Worker isRefreshRateOverlayEnabled()1415*38e8c45fSAndroid Build Coastguard Worker bool isRefreshRateOverlayEnabled() const REQUIRES(mStateLock) { 1416*38e8c45fSAndroid Build Coastguard Worker return hasDisplay( 1417*38e8c45fSAndroid Build Coastguard Worker [](const auto& display) { return display.isRefreshRateOverlayEnabled(); }); 1418*38e8c45fSAndroid Build Coastguard Worker } isHdrSdrRatioOverlayEnabled()1419*38e8c45fSAndroid Build Coastguard Worker bool isHdrSdrRatioOverlayEnabled() const REQUIRES(mStateLock) { 1420*38e8c45fSAndroid Build Coastguard Worker return hasDisplay( 1421*38e8c45fSAndroid Build Coastguard Worker [](const auto& display) { return display.isHdrSdrRatioOverlayEnabled(); }); 1422*38e8c45fSAndroid Build Coastguard Worker } 1423*38e8c45fSAndroid Build Coastguard Worker std::function<std::vector<std::pair<Layer*, sp<LayerFE>>>()> getLayerSnapshotsForScreenshots( 1424*38e8c45fSAndroid Build Coastguard Worker std::optional<ui::LayerStack> layerStack, uint32_t uid, 1425*38e8c45fSAndroid Build Coastguard Worker std::function<bool(const frontend::LayerSnapshot&, bool& outStopTraversal)> 1426*38e8c45fSAndroid Build Coastguard Worker snapshotFilterFn); 1427*38e8c45fSAndroid Build Coastguard Worker std::function<std::vector<std::pair<Layer*, sp<LayerFE>>>()> getLayerSnapshotsForScreenshots( 1428*38e8c45fSAndroid Build Coastguard Worker std::optional<ui::LayerStack> layerStack, uint32_t uid, 1429*38e8c45fSAndroid Build Coastguard Worker std::unordered_set<uint32_t> excludeLayerIds); 1430*38e8c45fSAndroid Build Coastguard Worker std::function<std::vector<std::pair<Layer*, sp<LayerFE>>>()> getLayerSnapshotsForScreenshots( 1431*38e8c45fSAndroid Build Coastguard Worker uint32_t rootLayerId, uint32_t uid, std::unordered_set<uint32_t> excludeLayerIds, 1432*38e8c45fSAndroid Build Coastguard Worker bool childrenOnly, const std::optional<FloatRect>& optionalParentCrop); 1433*38e8c45fSAndroid Build Coastguard Worker 1434*38e8c45fSAndroid Build Coastguard Worker const sp<WindowInfosListenerInvoker> mWindowInfosListenerInvoker; 1435*38e8c45fSAndroid Build Coastguard Worker 1436*38e8c45fSAndroid Build Coastguard Worker // returns the framerate of the layer with the given sequence ID getLayerFramerate(nsecs_t now,int32_t id)1437*38e8c45fSAndroid Build Coastguard Worker float getLayerFramerate(nsecs_t now, int32_t id) const { 1438*38e8c45fSAndroid Build Coastguard Worker return mScheduler->getLayerFramerate(now, id); 1439*38e8c45fSAndroid Build Coastguard Worker } 1440*38e8c45fSAndroid Build Coastguard Worker 1441*38e8c45fSAndroid Build Coastguard Worker bool mPowerHintSessionEnabled; 1442*38e8c45fSAndroid Build Coastguard Worker // Whether a display should be turned on when initialized 1443*38e8c45fSAndroid Build Coastguard Worker bool mSkipPowerOnForQuiescent; 1444*38e8c45fSAndroid Build Coastguard Worker 1445*38e8c45fSAndroid Build Coastguard Worker // used for omitting vsync callbacks to apps when the display is not updatable 1446*38e8c45fSAndroid Build Coastguard Worker int mRefreshableDisplays GUARDED_BY(mStateLock) = 0; 1447*38e8c45fSAndroid Build Coastguard Worker void incRefreshableDisplays() REQUIRES(mStateLock); 1448*38e8c45fSAndroid Build Coastguard Worker void decRefreshableDisplays() REQUIRES(mStateLock); 1449*38e8c45fSAndroid Build Coastguard Worker 1450*38e8c45fSAndroid Build Coastguard Worker frontend::LayerLifecycleManager mLayerLifecycleManager GUARDED_BY(kMainThreadContext); 1451*38e8c45fSAndroid Build Coastguard Worker frontend::LayerHierarchyBuilder mLayerHierarchyBuilder GUARDED_BY(kMainThreadContext); 1452*38e8c45fSAndroid Build Coastguard Worker frontend::LayerSnapshotBuilder mLayerSnapshotBuilder GUARDED_BY(kMainThreadContext); 1453*38e8c45fSAndroid Build Coastguard Worker 1454*38e8c45fSAndroid Build Coastguard Worker mutable std::mutex mCreatedLayersLock; 1455*38e8c45fSAndroid Build Coastguard Worker std::vector<sp<Layer>> mCreatedLayers GUARDED_BY(mCreatedLayersLock); 1456*38e8c45fSAndroid Build Coastguard Worker std::vector<std::pair<uint32_t, std::string>> mDestroyedHandles GUARDED_BY(mCreatedLayersLock); 1457*38e8c45fSAndroid Build Coastguard Worker std::vector<std::unique_ptr<frontend::RequestedLayerState>> mNewLayers 1458*38e8c45fSAndroid Build Coastguard Worker GUARDED_BY(mCreatedLayersLock); 1459*38e8c45fSAndroid Build Coastguard Worker std::vector<LayerCreationArgs> mNewLayerArgs GUARDED_BY(mCreatedLayersLock); 1460*38e8c45fSAndroid Build Coastguard Worker // These classes do not store any client state but help with managing transaction callbacks 1461*38e8c45fSAndroid Build Coastguard Worker // and stats. 1462*38e8c45fSAndroid Build Coastguard Worker std::unordered_map<uint32_t, sp<Layer>> mLegacyLayers GUARDED_BY(kMainThreadContext); 1463*38e8c45fSAndroid Build Coastguard Worker 1464*38e8c45fSAndroid Build Coastguard Worker TransactionHandler mTransactionHandler GUARDED_BY(kMainThreadContext); 1465*38e8c45fSAndroid Build Coastguard Worker ui::DisplayMap<ui::LayerStack, frontend::DisplayInfo> mFrontEndDisplayInfos 1466*38e8c45fSAndroid Build Coastguard Worker GUARDED_BY(kMainThreadContext); 1467*38e8c45fSAndroid Build Coastguard Worker bool mFrontEndDisplayInfosChanged GUARDED_BY(kMainThreadContext) = false; 1468*38e8c45fSAndroid Build Coastguard Worker 1469*38e8c45fSAndroid Build Coastguard Worker // WindowInfo ids visible during the last commit. 1470*38e8c45fSAndroid Build Coastguard Worker std::unordered_set<int32_t> mVisibleWindowIds GUARDED_BY(kMainThreadContext); 1471*38e8c45fSAndroid Build Coastguard Worker 1472*38e8c45fSAndroid Build Coastguard Worker // Mirroring 1473*38e8c45fSAndroid Build Coastguard Worker // Map of displayid to mirrorRoot 1474*38e8c45fSAndroid Build Coastguard Worker ftl::SmallMap<int64_t, sp<SurfaceControl>, 3> mMirrorMapForDebug; 1475*38e8c45fSAndroid Build Coastguard Worker 1476*38e8c45fSAndroid Build Coastguard Worker // NotifyExpectedPresentHint 1477*38e8c45fSAndroid Build Coastguard Worker enum class NotifyExpectedPresentHintStatus { 1478*38e8c45fSAndroid Build Coastguard Worker // Represents that framework can start sending hint if required. 1479*38e8c45fSAndroid Build Coastguard Worker Start, 1480*38e8c45fSAndroid Build Coastguard Worker // Represents that the hint is already sent. 1481*38e8c45fSAndroid Build Coastguard Worker Sent, 1482*38e8c45fSAndroid Build Coastguard Worker // Represents that the hint will be scheduled with a new frame. 1483*38e8c45fSAndroid Build Coastguard Worker ScheduleOnPresent, 1484*38e8c45fSAndroid Build Coastguard Worker // Represents that a hint will be sent instantly by scheduling on the main thread. 1485*38e8c45fSAndroid Build Coastguard Worker ScheduleOnTx 1486*38e8c45fSAndroid Build Coastguard Worker }; 1487*38e8c45fSAndroid Build Coastguard Worker struct NotifyExpectedPresentData { 1488*38e8c45fSAndroid Build Coastguard Worker TimePoint lastExpectedPresentTimestamp{}; 1489*38e8c45fSAndroid Build Coastguard Worker Fps lastFrameInterval{}; 1490*38e8c45fSAndroid Build Coastguard Worker // hintStatus is read and write from multiple threads such as 1491*38e8c45fSAndroid Build Coastguard Worker // main thread, EventThread. And is atomic for that reason. 1492*38e8c45fSAndroid Build Coastguard Worker std::atomic<NotifyExpectedPresentHintStatus> hintStatus = 1493*38e8c45fSAndroid Build Coastguard Worker NotifyExpectedPresentHintStatus::Start; 1494*38e8c45fSAndroid Build Coastguard Worker }; 1495*38e8c45fSAndroid Build Coastguard Worker std::unordered_map<PhysicalDisplayId, NotifyExpectedPresentData> mNotifyExpectedPresentMap; 1496*38e8c45fSAndroid Build Coastguard Worker void sendNotifyExpectedPresentHint(PhysicalDisplayId displayId) override 1497*38e8c45fSAndroid Build Coastguard Worker REQUIRES(kMainThreadContext); 1498*38e8c45fSAndroid Build Coastguard Worker void scheduleNotifyExpectedPresentHint(PhysicalDisplayId displayId, 1499*38e8c45fSAndroid Build Coastguard Worker VsyncId vsyncId = VsyncId{ 1500*38e8c45fSAndroid Build Coastguard Worker FrameTimelineInfo::INVALID_VSYNC_ID}); 1501*38e8c45fSAndroid Build Coastguard Worker void notifyExpectedPresentIfRequired(PhysicalDisplayId, Period vsyncPeriod, 1502*38e8c45fSAndroid Build Coastguard Worker TimePoint expectedPresentTime, Fps frameInterval, 1503*38e8c45fSAndroid Build Coastguard Worker std::optional<Period> timeoutOpt); 1504*38e8c45fSAndroid Build Coastguard Worker 1505*38e8c45fSAndroid Build Coastguard Worker void sfdo_enableRefreshRateOverlay(bool active); 1506*38e8c45fSAndroid Build Coastguard Worker void sfdo_setDebugFlash(int delay); 1507*38e8c45fSAndroid Build Coastguard Worker void sfdo_scheduleComposite(); 1508*38e8c45fSAndroid Build Coastguard Worker void sfdo_scheduleCommit(); 1509*38e8c45fSAndroid Build Coastguard Worker void sfdo_forceClientComposition(bool enabled); 1510*38e8c45fSAndroid Build Coastguard Worker }; 1511*38e8c45fSAndroid Build Coastguard Worker 1512*38e8c45fSAndroid Build Coastguard Worker class SurfaceComposerAIDL : public gui::BnSurfaceComposer { 1513*38e8c45fSAndroid Build Coastguard Worker public: SurfaceComposerAIDL(sp<SurfaceFlinger> sf)1514*38e8c45fSAndroid Build Coastguard Worker explicit SurfaceComposerAIDL(sp<SurfaceFlinger> sf) : mFlinger(std::move(sf)) {} 1515*38e8c45fSAndroid Build Coastguard Worker 1516*38e8c45fSAndroid Build Coastguard Worker binder::Status bootFinished() override; 1517*38e8c45fSAndroid Build Coastguard Worker binder::Status createDisplayEventConnection( 1518*38e8c45fSAndroid Build Coastguard Worker VsyncSource vsyncSource, EventRegistration eventRegistration, 1519*38e8c45fSAndroid Build Coastguard Worker const sp<IBinder>& layerHandle, 1520*38e8c45fSAndroid Build Coastguard Worker sp<gui::IDisplayEventConnection>* outConnection) override; 1521*38e8c45fSAndroid Build Coastguard Worker binder::Status createConnection(sp<gui::ISurfaceComposerClient>* outClient) override; 1522*38e8c45fSAndroid Build Coastguard Worker binder::Status createVirtualDisplay(const std::string& displayName, bool isSecure, 1523*38e8c45fSAndroid Build Coastguard Worker const std::string& uniqueId, float requestedRefreshRate, 1524*38e8c45fSAndroid Build Coastguard Worker sp<IBinder>* outDisplay) override; 1525*38e8c45fSAndroid Build Coastguard Worker binder::Status destroyVirtualDisplay(const sp<IBinder>& displayToken) override; 1526*38e8c45fSAndroid Build Coastguard Worker binder::Status getPhysicalDisplayIds(std::vector<int64_t>* outDisplayIds) override; 1527*38e8c45fSAndroid Build Coastguard Worker binder::Status getPhysicalDisplayToken(int64_t displayId, sp<IBinder>* outDisplay) override; 1528*38e8c45fSAndroid Build Coastguard Worker binder::Status setPowerMode(const sp<IBinder>& display, int mode) override; 1529*38e8c45fSAndroid Build Coastguard Worker binder::Status getSupportedFrameTimestamps(std::vector<FrameEvent>* outSupported) override; 1530*38e8c45fSAndroid Build Coastguard Worker binder::Status getDisplayStats(const sp<IBinder>& display, 1531*38e8c45fSAndroid Build Coastguard Worker gui::DisplayStatInfo* outStatInfo) override; 1532*38e8c45fSAndroid Build Coastguard Worker binder::Status getDisplayState(const sp<IBinder>& display, 1533*38e8c45fSAndroid Build Coastguard Worker gui::DisplayState* outState) override; 1534*38e8c45fSAndroid Build Coastguard Worker binder::Status getStaticDisplayInfo(int64_t displayId, 1535*38e8c45fSAndroid Build Coastguard Worker gui::StaticDisplayInfo* outInfo) override; 1536*38e8c45fSAndroid Build Coastguard Worker binder::Status getDynamicDisplayInfoFromId(int64_t displayId, 1537*38e8c45fSAndroid Build Coastguard Worker gui::DynamicDisplayInfo* outInfo) override; 1538*38e8c45fSAndroid Build Coastguard Worker binder::Status getDynamicDisplayInfoFromToken(const sp<IBinder>& display, 1539*38e8c45fSAndroid Build Coastguard Worker gui::DynamicDisplayInfo* outInfo) override; 1540*38e8c45fSAndroid Build Coastguard Worker binder::Status getDisplayNativePrimaries(const sp<IBinder>& display, 1541*38e8c45fSAndroid Build Coastguard Worker gui::DisplayPrimaries* outPrimaries) override; 1542*38e8c45fSAndroid Build Coastguard Worker binder::Status setActiveColorMode(const sp<IBinder>& display, int colorMode) override; 1543*38e8c45fSAndroid Build Coastguard Worker binder::Status setBootDisplayMode(const sp<IBinder>& display, int displayModeId) override; 1544*38e8c45fSAndroid Build Coastguard Worker binder::Status clearBootDisplayMode(const sp<IBinder>& display) override; 1545*38e8c45fSAndroid Build Coastguard Worker binder::Status getBootDisplayModeSupport(bool* outMode) override; 1546*38e8c45fSAndroid Build Coastguard Worker binder::Status getOverlaySupport(gui::OverlayProperties* outProperties) override; 1547*38e8c45fSAndroid Build Coastguard Worker binder::Status getHdrConversionCapabilities( 1548*38e8c45fSAndroid Build Coastguard Worker std::vector<gui::HdrConversionCapability>*) override; 1549*38e8c45fSAndroid Build Coastguard Worker binder::Status setHdrConversionStrategy(const gui::HdrConversionStrategy& hdrConversionStrategy, 1550*38e8c45fSAndroid Build Coastguard Worker int32_t*) override; 1551*38e8c45fSAndroid Build Coastguard Worker binder::Status getHdrOutputConversionSupport(bool* outSupport) override; 1552*38e8c45fSAndroid Build Coastguard Worker binder::Status setAutoLowLatencyMode(const sp<IBinder>& display, bool on) override; 1553*38e8c45fSAndroid Build Coastguard Worker binder::Status setGameContentType(const sp<IBinder>& display, bool on) override; 1554*38e8c45fSAndroid Build Coastguard Worker binder::Status getMaxLayerPictureProfiles(const sp<IBinder>& display, 1555*38e8c45fSAndroid Build Coastguard Worker int32_t* outMaxProfiles) override; 1556*38e8c45fSAndroid Build Coastguard Worker binder::Status captureDisplay(const DisplayCaptureArgs&, 1557*38e8c45fSAndroid Build Coastguard Worker const sp<IScreenCaptureListener>&) override; 1558*38e8c45fSAndroid Build Coastguard Worker binder::Status captureDisplayById(int64_t, const CaptureArgs&, 1559*38e8c45fSAndroid Build Coastguard Worker const sp<IScreenCaptureListener>&) override; 1560*38e8c45fSAndroid Build Coastguard Worker binder::Status captureLayers(const LayerCaptureArgs&, 1561*38e8c45fSAndroid Build Coastguard Worker const sp<IScreenCaptureListener>&) override; 1562*38e8c45fSAndroid Build Coastguard Worker binder::Status captureLayersSync(const LayerCaptureArgs&, ScreenCaptureResults* results); 1563*38e8c45fSAndroid Build Coastguard Worker 1564*38e8c45fSAndroid Build Coastguard Worker // TODO(b/239076119): Remove deprecated AIDL. clearAnimationFrameStats()1565*38e8c45fSAndroid Build Coastguard Worker [[deprecated]] binder::Status clearAnimationFrameStats() override { 1566*38e8c45fSAndroid Build Coastguard Worker return binder::Status::ok(); 1567*38e8c45fSAndroid Build Coastguard Worker } getAnimationFrameStats(gui::FrameStats *)1568*38e8c45fSAndroid Build Coastguard Worker [[deprecated]] binder::Status getAnimationFrameStats(gui::FrameStats*) override { 1569*38e8c45fSAndroid Build Coastguard Worker return binder::Status::ok(); 1570*38e8c45fSAndroid Build Coastguard Worker } 1571*38e8c45fSAndroid Build Coastguard Worker 1572*38e8c45fSAndroid Build Coastguard Worker binder::Status overrideHdrTypes(const sp<IBinder>& display, 1573*38e8c45fSAndroid Build Coastguard Worker const std::vector<int32_t>& hdrTypes) override; 1574*38e8c45fSAndroid Build Coastguard Worker binder::Status onPullAtom(int32_t atomId, gui::PullAtomData* outPullData) override; 1575*38e8c45fSAndroid Build Coastguard Worker binder::Status getCompositionPreference(gui::CompositionPreference* outPref) override; 1576*38e8c45fSAndroid Build Coastguard Worker binder::Status getDisplayedContentSamplingAttributes( 1577*38e8c45fSAndroid Build Coastguard Worker const sp<IBinder>& display, gui::ContentSamplingAttributes* outAttrs) override; 1578*38e8c45fSAndroid Build Coastguard Worker binder::Status setDisplayContentSamplingEnabled(const sp<IBinder>& display, bool enable, 1579*38e8c45fSAndroid Build Coastguard Worker int8_t componentMask, 1580*38e8c45fSAndroid Build Coastguard Worker int64_t maxFrames) override; 1581*38e8c45fSAndroid Build Coastguard Worker binder::Status getDisplayedContentSample(const sp<IBinder>& display, int64_t maxFrames, 1582*38e8c45fSAndroid Build Coastguard Worker int64_t timestamp, 1583*38e8c45fSAndroid Build Coastguard Worker gui::DisplayedFrameStats* outStats) override; 1584*38e8c45fSAndroid Build Coastguard Worker binder::Status getProtectedContentSupport(bool* outSupporte) override; 1585*38e8c45fSAndroid Build Coastguard Worker binder::Status isWideColorDisplay(const sp<IBinder>& token, 1586*38e8c45fSAndroid Build Coastguard Worker bool* outIsWideColorDisplay) override; 1587*38e8c45fSAndroid Build Coastguard Worker binder::Status addRegionSamplingListener( 1588*38e8c45fSAndroid Build Coastguard Worker const gui::ARect& samplingArea, const sp<IBinder>& stopLayerHandle, 1589*38e8c45fSAndroid Build Coastguard Worker const sp<gui::IRegionSamplingListener>& listener) override; 1590*38e8c45fSAndroid Build Coastguard Worker binder::Status removeRegionSamplingListener( 1591*38e8c45fSAndroid Build Coastguard Worker const sp<gui::IRegionSamplingListener>& listener) override; 1592*38e8c45fSAndroid Build Coastguard Worker binder::Status addFpsListener(int32_t taskId, const sp<gui::IFpsListener>& listener) override; 1593*38e8c45fSAndroid Build Coastguard Worker binder::Status removeFpsListener(const sp<gui::IFpsListener>& listener) override; 1594*38e8c45fSAndroid Build Coastguard Worker binder::Status addTunnelModeEnabledListener( 1595*38e8c45fSAndroid Build Coastguard Worker const sp<gui::ITunnelModeEnabledListener>& listener) override; 1596*38e8c45fSAndroid Build Coastguard Worker binder::Status removeTunnelModeEnabledListener( 1597*38e8c45fSAndroid Build Coastguard Worker const sp<gui::ITunnelModeEnabledListener>& listener) override; 1598*38e8c45fSAndroid Build Coastguard Worker binder::Status setDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, 1599*38e8c45fSAndroid Build Coastguard Worker const gui::DisplayModeSpecs&) override; 1600*38e8c45fSAndroid Build Coastguard Worker binder::Status getDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, 1601*38e8c45fSAndroid Build Coastguard Worker gui::DisplayModeSpecs* outSpecs) override; 1602*38e8c45fSAndroid Build Coastguard Worker binder::Status getDisplayBrightnessSupport(const sp<IBinder>& displayToken, 1603*38e8c45fSAndroid Build Coastguard Worker bool* outSupport) override; 1604*38e8c45fSAndroid Build Coastguard Worker binder::Status setDisplayBrightness(const sp<IBinder>& displayToken, 1605*38e8c45fSAndroid Build Coastguard Worker const gui::DisplayBrightness& brightness) override; 1606*38e8c45fSAndroid Build Coastguard Worker binder::Status addHdrLayerInfoListener(const sp<IBinder>& displayToken, 1607*38e8c45fSAndroid Build Coastguard Worker const sp<gui::IHdrLayerInfoListener>& listener) override; 1608*38e8c45fSAndroid Build Coastguard Worker binder::Status removeHdrLayerInfoListener( 1609*38e8c45fSAndroid Build Coastguard Worker const sp<IBinder>& displayToken, 1610*38e8c45fSAndroid Build Coastguard Worker const sp<gui::IHdrLayerInfoListener>& listener) override; 1611*38e8c45fSAndroid Build Coastguard Worker 1612*38e8c45fSAndroid Build Coastguard Worker binder::Status notifyPowerBoost(int boostId) override; 1613*38e8c45fSAndroid Build Coastguard Worker binder::Status setGlobalShadowSettings(const gui::Color& ambientColor, 1614*38e8c45fSAndroid Build Coastguard Worker const gui::Color& spotColor, float lightPosY, 1615*38e8c45fSAndroid Build Coastguard Worker float lightPosZ, float lightRadius) override; 1616*38e8c45fSAndroid Build Coastguard Worker binder::Status getDisplayDecorationSupport( 1617*38e8c45fSAndroid Build Coastguard Worker const sp<IBinder>& displayToken, 1618*38e8c45fSAndroid Build Coastguard Worker std::optional<gui::DisplayDecorationSupport>* outSupport) override; 1619*38e8c45fSAndroid Build Coastguard Worker binder::Status setGameModeFrameRateOverride(int32_t uid, float frameRate) override; 1620*38e8c45fSAndroid Build Coastguard Worker binder::Status setGameDefaultFrameRateOverride(int32_t uid, float frameRate) override; 1621*38e8c45fSAndroid Build Coastguard Worker binder::Status enableRefreshRateOverlay(bool active) override; 1622*38e8c45fSAndroid Build Coastguard Worker binder::Status setDebugFlash(int delay) override; 1623*38e8c45fSAndroid Build Coastguard Worker binder::Status scheduleComposite() override; 1624*38e8c45fSAndroid Build Coastguard Worker binder::Status scheduleCommit() override; 1625*38e8c45fSAndroid Build Coastguard Worker binder::Status forceClientComposition(bool enabled) override; 1626*38e8c45fSAndroid Build Coastguard Worker binder::Status updateSmallAreaDetection(const std::vector<int32_t>& appIds, 1627*38e8c45fSAndroid Build Coastguard Worker const std::vector<float>& thresholds) override; 1628*38e8c45fSAndroid Build Coastguard Worker binder::Status setSmallAreaDetectionThreshold(int32_t appId, float threshold) override; 1629*38e8c45fSAndroid Build Coastguard Worker binder::Status getGpuContextPriority(int32_t* outPriority) override; 1630*38e8c45fSAndroid Build Coastguard Worker binder::Status getMaxAcquiredBufferCount(int32_t* buffers) override; 1631*38e8c45fSAndroid Build Coastguard Worker binder::Status addWindowInfosListener(const sp<gui::IWindowInfosListener>& windowInfosListener, 1632*38e8c45fSAndroid Build Coastguard Worker gui::WindowInfosListenerInfo* outInfo) override; 1633*38e8c45fSAndroid Build Coastguard Worker binder::Status removeWindowInfosListener( 1634*38e8c45fSAndroid Build Coastguard Worker const sp<gui::IWindowInfosListener>& windowInfosListener) override; 1635*38e8c45fSAndroid Build Coastguard Worker binder::Status getStalledTransactionInfo( 1636*38e8c45fSAndroid Build Coastguard Worker int pid, std::optional<gui::StalledTransactionInfo>* outInfo) override; 1637*38e8c45fSAndroid Build Coastguard Worker binder::Status getSchedulingPolicy(gui::SchedulingPolicy* outPolicy) override; 1638*38e8c45fSAndroid Build Coastguard Worker binder::Status notifyShutdown() override; 1639*38e8c45fSAndroid Build Coastguard Worker binder::Status addJankListener(const sp<IBinder>& layer, 1640*38e8c45fSAndroid Build Coastguard Worker const sp<gui::IJankListener>& listener) override; 1641*38e8c45fSAndroid Build Coastguard Worker binder::Status flushJankData(int32_t layerId) override; 1642*38e8c45fSAndroid Build Coastguard Worker binder::Status removeJankListener(int32_t layerId, const sp<gui::IJankListener>& listener, 1643*38e8c45fSAndroid Build Coastguard Worker int64_t afterVsync) override; 1644*38e8c45fSAndroid Build Coastguard Worker binder::Status setActivePictureListener(const sp<gui::IActivePictureListener>& listener); 1645*38e8c45fSAndroid Build Coastguard Worker binder::Status clearActivePictureListener(); 1646*38e8c45fSAndroid Build Coastguard Worker 1647*38e8c45fSAndroid Build Coastguard Worker private: 1648*38e8c45fSAndroid Build Coastguard Worker static const constexpr bool kUsePermissionCache = true; 1649*38e8c45fSAndroid Build Coastguard Worker status_t checkAccessPermission(bool usePermissionCache = kUsePermissionCache); 1650*38e8c45fSAndroid Build Coastguard Worker status_t checkControlDisplayBrightnessPermission(); 1651*38e8c45fSAndroid Build Coastguard Worker status_t checkReadFrameBufferPermission(); 1652*38e8c45fSAndroid Build Coastguard Worker status_t checkObservePictureProfilesPermission(); 1653*38e8c45fSAndroid Build Coastguard Worker static void getDynamicDisplayInfoInternal(ui::DynamicDisplayInfo& info, 1654*38e8c45fSAndroid Build Coastguard Worker gui::DynamicDisplayInfo*& outInfo); 1655*38e8c45fSAndroid Build Coastguard Worker 1656*38e8c45fSAndroid Build Coastguard Worker private: 1657*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceFlinger> mFlinger; 1658*38e8c45fSAndroid Build Coastguard Worker }; 1659*38e8c45fSAndroid Build Coastguard Worker 1660*38e8c45fSAndroid Build Coastguard Worker } // namespace android 1661