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 * Unless required by applicable law or agreed to in writing, software 11*38e8c45fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*38e8c45fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*38e8c45fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*38e8c45fSAndroid Build Coastguard Worker * limitations under the License. 15*38e8c45fSAndroid Build Coastguard Worker */ 16*38e8c45fSAndroid Build Coastguard Worker 17*38e8c45fSAndroid Build Coastguard Worker #pragma once 18*38e8c45fSAndroid Build Coastguard Worker 19*38e8c45fSAndroid Build Coastguard Worker #include <android/gui/DropInputMode.h> 20*38e8c45fSAndroid Build Coastguard Worker #include <android/gui/ISurfaceComposerClient.h> 21*38e8c45fSAndroid Build Coastguard Worker #include <com_android_graphics_surfaceflinger_flags.h> 22*38e8c45fSAndroid Build Coastguard Worker #include <ftl/small_map.h> 23*38e8c45fSAndroid Build Coastguard Worker #include <gui/BufferQueue.h> 24*38e8c45fSAndroid Build Coastguard Worker #include <gui/LayerState.h> 25*38e8c45fSAndroid Build Coastguard Worker #include <gui/WindowInfo.h> 26*38e8c45fSAndroid Build Coastguard Worker #include <layerproto/LayerProtoHeader.h> 27*38e8c45fSAndroid Build Coastguard Worker #include <math/vec4.h> 28*38e8c45fSAndroid Build Coastguard Worker #include <sys/types.h> 29*38e8c45fSAndroid Build Coastguard Worker #include <ui/BlurRegion.h> 30*38e8c45fSAndroid Build Coastguard Worker #include <ui/DisplayMap.h> 31*38e8c45fSAndroid Build Coastguard Worker #include <ui/FloatRect.h> 32*38e8c45fSAndroid Build Coastguard Worker #include <ui/FrameStats.h> 33*38e8c45fSAndroid Build Coastguard Worker #include <ui/GraphicBuffer.h> 34*38e8c45fSAndroid Build Coastguard Worker #include <ui/LayerStack.h> 35*38e8c45fSAndroid Build Coastguard Worker #include <ui/PixelFormat.h> 36*38e8c45fSAndroid Build Coastguard Worker #include <ui/Region.h> 37*38e8c45fSAndroid Build Coastguard Worker #include <ui/StretchEffect.h> 38*38e8c45fSAndroid Build Coastguard Worker #include <ui/Transform.h> 39*38e8c45fSAndroid Build Coastguard Worker #include <utils/RefBase.h> 40*38e8c45fSAndroid Build Coastguard Worker #include <utils/Timers.h> 41*38e8c45fSAndroid Build Coastguard Worker 42*38e8c45fSAndroid Build Coastguard Worker #include <compositionengine/LayerFE.h> 43*38e8c45fSAndroid Build Coastguard Worker #include <compositionengine/LayerFECompositionState.h> 44*38e8c45fSAndroid Build Coastguard Worker #include <scheduler/Fps.h> 45*38e8c45fSAndroid Build Coastguard Worker #include <scheduler/Seamlessness.h> 46*38e8c45fSAndroid Build Coastguard Worker 47*38e8c45fSAndroid Build Coastguard Worker #include <cstdint> 48*38e8c45fSAndroid Build Coastguard Worker #include <functional> 49*38e8c45fSAndroid Build Coastguard Worker #include <optional> 50*38e8c45fSAndroid Build Coastguard Worker #include <vector> 51*38e8c45fSAndroid Build Coastguard Worker 52*38e8c45fSAndroid Build Coastguard Worker #include "Client.h" 53*38e8c45fSAndroid Build Coastguard Worker #include "DisplayHardware/HWComposer.h" 54*38e8c45fSAndroid Build Coastguard Worker #include "FrameTracker.h" 55*38e8c45fSAndroid Build Coastguard Worker #include "LayerFE.h" 56*38e8c45fSAndroid Build Coastguard Worker #include "LayerVector.h" 57*38e8c45fSAndroid Build Coastguard Worker #include "Scheduler/LayerInfo.h" 58*38e8c45fSAndroid Build Coastguard Worker #include "SurfaceFlinger.h" 59*38e8c45fSAndroid Build Coastguard Worker #include "TransactionCallbackInvoker.h" 60*38e8c45fSAndroid Build Coastguard Worker 61*38e8c45fSAndroid Build Coastguard Worker using namespace android::surfaceflinger; 62*38e8c45fSAndroid Build Coastguard Worker 63*38e8c45fSAndroid Build Coastguard Worker namespace android { 64*38e8c45fSAndroid Build Coastguard Worker 65*38e8c45fSAndroid Build Coastguard Worker class Client; 66*38e8c45fSAndroid Build Coastguard Worker class Colorizer; 67*38e8c45fSAndroid Build Coastguard Worker class DisplayDevice; 68*38e8c45fSAndroid Build Coastguard Worker class GraphicBuffer; 69*38e8c45fSAndroid Build Coastguard Worker class SurfaceFlinger; 70*38e8c45fSAndroid Build Coastguard Worker 71*38e8c45fSAndroid Build Coastguard Worker namespace compositionengine { 72*38e8c45fSAndroid Build Coastguard Worker class OutputLayer; 73*38e8c45fSAndroid Build Coastguard Worker struct LayerFECompositionState; 74*38e8c45fSAndroid Build Coastguard Worker } 75*38e8c45fSAndroid Build Coastguard Worker 76*38e8c45fSAndroid Build Coastguard Worker namespace frametimeline { 77*38e8c45fSAndroid Build Coastguard Worker class SurfaceFrame; 78*38e8c45fSAndroid Build Coastguard Worker } // namespace frametimeline 79*38e8c45fSAndroid Build Coastguard Worker 80*38e8c45fSAndroid Build Coastguard Worker class Layer : public virtual RefBase { 81*38e8c45fSAndroid Build Coastguard Worker public: 82*38e8c45fSAndroid Build Coastguard Worker // The following constants represent priority of the window. SF uses this information when 83*38e8c45fSAndroid Build Coastguard Worker // deciding which window has a priority when deciding about the refresh rate of the screen. 84*38e8c45fSAndroid Build Coastguard Worker // Priority 0 is considered the highest priority. -1 means that the priority is unset. 85*38e8c45fSAndroid Build Coastguard Worker static constexpr int32_t PRIORITY_UNSET = -1; 86*38e8c45fSAndroid Build Coastguard Worker // Windows that are in focus and voted for the preferred mode ID 87*38e8c45fSAndroid Build Coastguard Worker static constexpr int32_t PRIORITY_FOCUSED_WITH_MODE = 0; 88*38e8c45fSAndroid Build Coastguard Worker // // Windows that are in focus, but have not requested a specific mode ID. 89*38e8c45fSAndroid Build Coastguard Worker static constexpr int32_t PRIORITY_FOCUSED_WITHOUT_MODE = 1; 90*38e8c45fSAndroid Build Coastguard Worker // Windows that are not in focus, but voted for a specific mode ID. 91*38e8c45fSAndroid Build Coastguard Worker static constexpr int32_t PRIORITY_NOT_FOCUSED_WITH_MODE = 2; 92*38e8c45fSAndroid Build Coastguard Worker 93*38e8c45fSAndroid Build Coastguard Worker using FrameRate = scheduler::LayerInfo::FrameRate; 94*38e8c45fSAndroid Build Coastguard Worker using FrameRateCompatibility = scheduler::FrameRateCompatibility; 95*38e8c45fSAndroid Build Coastguard Worker using FrameRateSelectionStrategy = scheduler::LayerInfo::FrameRateSelectionStrategy; 96*38e8c45fSAndroid Build Coastguard Worker 97*38e8c45fSAndroid Build Coastguard Worker struct State { 98*38e8c45fSAndroid Build Coastguard Worker int32_t sequence; // changes when visible regions can change 99*38e8c45fSAndroid Build Coastguard Worker // Crop is expressed in layer space coordinate. 100*38e8c45fSAndroid Build Coastguard Worker FloatRect crop; 101*38e8c45fSAndroid Build Coastguard Worker LayerMetadata metadata; 102*38e8c45fSAndroid Build Coastguard Worker 103*38e8c45fSAndroid Build Coastguard Worker ui::Dataspace dataspace; 104*38e8c45fSAndroid Build Coastguard Worker 105*38e8c45fSAndroid Build Coastguard Worker uint64_t frameNumber; 106*38e8c45fSAndroid Build Coastguard Worker uint64_t previousFrameNumber; 107*38e8c45fSAndroid Build Coastguard Worker // high watermark framenumber to use to check for barriers to protect ourselves 108*38e8c45fSAndroid Build Coastguard Worker // from out of order transactions 109*38e8c45fSAndroid Build Coastguard Worker uint64_t barrierFrameNumber; 110*38e8c45fSAndroid Build Coastguard Worker ui::Transform transform; 111*38e8c45fSAndroid Build Coastguard Worker 112*38e8c45fSAndroid Build Coastguard Worker uint32_t producerId = 0; 113*38e8c45fSAndroid Build Coastguard Worker // high watermark producerId to use to check for barriers to protect ourselves 114*38e8c45fSAndroid Build Coastguard Worker // from out of order transactions 115*38e8c45fSAndroid Build Coastguard Worker uint32_t barrierProducerId = 0; 116*38e8c45fSAndroid Build Coastguard Worker 117*38e8c45fSAndroid Build Coastguard Worker uint32_t bufferTransform; 118*38e8c45fSAndroid Build Coastguard Worker bool transformToDisplayInverse; 119*38e8c45fSAndroid Build Coastguard Worker Region transparentRegionHint; 120*38e8c45fSAndroid Build Coastguard Worker std::shared_ptr<renderengine::ExternalTexture> buffer; 121*38e8c45fSAndroid Build Coastguard Worker sp<Fence> acquireFence; 122*38e8c45fSAndroid Build Coastguard Worker std::shared_ptr<FenceTime> acquireFenceTime; 123*38e8c45fSAndroid Build Coastguard Worker sp<NativeHandle> sidebandStream; 124*38e8c45fSAndroid Build Coastguard Worker mat4 colorTransform; 125*38e8c45fSAndroid Build Coastguard Worker 126*38e8c45fSAndroid Build Coastguard Worker // The deque of callback handles for this frame. The back of the deque contains the most 127*38e8c45fSAndroid Build Coastguard Worker // recent callback handle. 128*38e8c45fSAndroid Build Coastguard Worker std::deque<sp<CallbackHandle>> callbackHandles; 129*38e8c45fSAndroid Build Coastguard Worker nsecs_t desiredPresentTime = 0; 130*38e8c45fSAndroid Build Coastguard Worker bool isAutoTimestamp = true; 131*38e8c45fSAndroid Build Coastguard Worker 132*38e8c45fSAndroid Build Coastguard Worker // The combined frame rate of parents / children of this layer 133*38e8c45fSAndroid Build Coastguard Worker FrameRate frameRateForLayerTree; 134*38e8c45fSAndroid Build Coastguard Worker 135*38e8c45fSAndroid Build Coastguard Worker // The vsync info that was used to start the transaction 136*38e8c45fSAndroid Build Coastguard Worker FrameTimelineInfo frameTimelineInfo; 137*38e8c45fSAndroid Build Coastguard Worker 138*38e8c45fSAndroid Build Coastguard Worker // When the transaction was posted 139*38e8c45fSAndroid Build Coastguard Worker nsecs_t postTime; 140*38e8c45fSAndroid Build Coastguard Worker sp<ITransactionCompletedListener> releaseBufferListener; 141*38e8c45fSAndroid Build Coastguard Worker // SurfaceFrame that tracks the timeline of Transactions that contain a Buffer. Only one 142*38e8c45fSAndroid Build Coastguard Worker // such SurfaceFrame exists because only one buffer can be presented on the layer per vsync. 143*38e8c45fSAndroid Build Coastguard Worker // If multiple buffers are queued, the prior ones will be dropped, along with the 144*38e8c45fSAndroid Build Coastguard Worker // SurfaceFrame that's tracking them. 145*38e8c45fSAndroid Build Coastguard Worker std::shared_ptr<frametimeline::SurfaceFrame> bufferSurfaceFrameTX; 146*38e8c45fSAndroid Build Coastguard Worker // A map of token(frametimelineVsyncId) to the SurfaceFrame that's tracking a transaction 147*38e8c45fSAndroid Build Coastguard Worker // that contains the token. Only one SurfaceFrame exisits for transactions that share the 148*38e8c45fSAndroid Build Coastguard Worker // same token, unless they are presented in different vsyncs. 149*38e8c45fSAndroid Build Coastguard Worker std::unordered_map<int64_t, std::shared_ptr<frametimeline::SurfaceFrame>> 150*38e8c45fSAndroid Build Coastguard Worker bufferlessSurfaceFramesTX; 151*38e8c45fSAndroid Build Coastguard Worker // An arbitrary threshold for the number of BufferlessSurfaceFrames in the state. Used to 152*38e8c45fSAndroid Build Coastguard Worker // trigger a warning if the number of SurfaceFrames crosses the threshold. 153*38e8c45fSAndroid Build Coastguard Worker static constexpr uint32_t kStateSurfaceFramesThreshold = 25; 154*38e8c45fSAndroid Build Coastguard Worker Rect bufferCrop; 155*38e8c45fSAndroid Build Coastguard Worker Rect destinationFrame; 156*38e8c45fSAndroid Build Coastguard Worker sp<IBinder> releaseBufferEndpoint; 157*38e8c45fSAndroid Build Coastguard Worker bool autoRefresh = false; 158*38e8c45fSAndroid Build Coastguard Worker float currentHdrSdrRatio = 1.f; 159*38e8c45fSAndroid Build Coastguard Worker float desiredHdrSdrRatio = -1.f; 160*38e8c45fSAndroid Build Coastguard Worker int64_t latchedVsyncId = 0; 161*38e8c45fSAndroid Build Coastguard Worker bool useVsyncIdForRefreshRateSelection = false; 162*38e8c45fSAndroid Build Coastguard Worker }; 163*38e8c45fSAndroid Build Coastguard Worker 164*38e8c45fSAndroid Build Coastguard Worker explicit Layer(const surfaceflinger::LayerCreationArgs& args); 165*38e8c45fSAndroid Build Coastguard Worker virtual ~Layer(); 166*38e8c45fSAndroid Build Coastguard Worker 167*38e8c45fSAndroid Build Coastguard Worker static bool isLayerFocusedBasedOnPriority(int32_t priority); 168*38e8c45fSAndroid Build Coastguard Worker static void miniDumpHeader(std::string& result); 169*38e8c45fSAndroid Build Coastguard Worker 170*38e8c45fSAndroid Build Coastguard Worker // This second set of geometry attributes are controlled by 171*38e8c45fSAndroid Build Coastguard Worker // setGeometryAppliesWithResize, and their default mode is to be 172*38e8c45fSAndroid Build Coastguard Worker // immediate. If setGeometryAppliesWithResize is specified 173*38e8c45fSAndroid Build Coastguard Worker // while a resize is pending, then update of these attributes will 174*38e8c45fSAndroid Build Coastguard Worker // be delayed until the resize completes. 175*38e8c45fSAndroid Build Coastguard Worker 176*38e8c45fSAndroid Build Coastguard Worker // Buffer space 177*38e8c45fSAndroid Build Coastguard Worker bool setCrop(const FloatRect& crop); 178*38e8c45fSAndroid Build Coastguard Worker 179*38e8c45fSAndroid Build Coastguard Worker bool setTransform(uint32_t /*transform*/); 180*38e8c45fSAndroid Build Coastguard Worker bool setTransformToDisplayInverse(bool /*transformToDisplayInverse*/); 181*38e8c45fSAndroid Build Coastguard Worker bool setBuffer(std::shared_ptr<renderengine::ExternalTexture>& /* buffer */, 182*38e8c45fSAndroid Build Coastguard Worker const BufferData& /* bufferData */, nsecs_t /* postTime */, 183*38e8c45fSAndroid Build Coastguard Worker nsecs_t /*desiredPresentTime*/, bool /*isAutoTimestamp*/, 184*38e8c45fSAndroid Build Coastguard Worker const FrameTimelineInfo& /*info*/, gui::GameMode gameMode); 185*38e8c45fSAndroid Build Coastguard Worker void setDesiredPresentTime(nsecs_t /*desiredPresentTime*/, bool /*isAutoTimestamp*/); 186*38e8c45fSAndroid Build Coastguard Worker bool setDataspace(ui::Dataspace /*dataspace*/); 187*38e8c45fSAndroid Build Coastguard Worker bool setExtendedRangeBrightness(float currentBufferRatio, float desiredRatio); 188*38e8c45fSAndroid Build Coastguard Worker bool setDesiredHdrHeadroom(float desiredRatio); 189*38e8c45fSAndroid Build Coastguard Worker bool setSidebandStream(const sp<NativeHandle>& /*sidebandStream*/, 190*38e8c45fSAndroid Build Coastguard Worker const FrameTimelineInfo& /* info*/, nsecs_t /* postTime */, 191*38e8c45fSAndroid Build Coastguard Worker gui::GameMode gameMode); 192*38e8c45fSAndroid Build Coastguard Worker bool setTransactionCompletedListeners(const std::vector<sp<CallbackHandle>>& /*handles*/, 193*38e8c45fSAndroid Build Coastguard Worker bool willPresent); 194*38e8c45fSAndroid Build Coastguard Worker 195*38e8c45fSAndroid Build Coastguard Worker sp<LayerFE> getCompositionEngineLayerFE(const frontend::LayerHierarchy::TraversalPath&); 196*38e8c45fSAndroid Build Coastguard Worker 197*38e8c45fSAndroid Build Coastguard Worker // If we have received a new buffer this frame, we will pass its surface 198*38e8c45fSAndroid Build Coastguard Worker // damage down to hardware composer. Otherwise, we must send a region with 199*38e8c45fSAndroid Build Coastguard Worker // one empty rect. 200*38e8c45fSAndroid Build Coastguard Worker Region getVisibleRegion(const DisplayDevice*) const; 201*38e8c45fSAndroid Build Coastguard Worker void updateLastLatchTime(nsecs_t latchtime); 202*38e8c45fSAndroid Build Coastguard Worker getCrop(const Layer::State & s)203*38e8c45fSAndroid Build Coastguard Worker Rect getCrop(const Layer::State& s) const { return Rect(s.crop); } 204*38e8c45fSAndroid Build Coastguard Worker 205*38e8c45fSAndroid Build Coastguard Worker // from graphics API 206*38e8c45fSAndroid Build Coastguard Worker static ui::Dataspace translateDataspace(ui::Dataspace dataspace); 207*38e8c45fSAndroid Build Coastguard Worker uint64_t mPreviousFrameNumber = 0; 208*38e8c45fSAndroid Build Coastguard Worker 209*38e8c45fSAndroid Build Coastguard Worker void onCompositionPresented(const DisplayDevice*, 210*38e8c45fSAndroid Build Coastguard Worker const std::shared_ptr<FenceTime>& /*glDoneFence*/, 211*38e8c45fSAndroid Build Coastguard Worker const std::shared_ptr<FenceTime>& /*presentFence*/, 212*38e8c45fSAndroid Build Coastguard Worker const CompositorTiming&, gui::GameMode gameMode); 213*38e8c45fSAndroid Build Coastguard Worker 214*38e8c45fSAndroid Build Coastguard Worker // If a buffer was replaced this frame, release the former buffer 215*38e8c45fSAndroid Build Coastguard Worker void releasePendingBuffer(nsecs_t /*dequeueReadyTime*/); 216*38e8c45fSAndroid Build Coastguard Worker 217*38e8c45fSAndroid Build Coastguard Worker /* 218*38e8c45fSAndroid Build Coastguard Worker * latchBuffer - called each time the screen is redrawn and returns whether 219*38e8c45fSAndroid Build Coastguard Worker * the visible regions need to be recomputed (this is a fairly heavy 220*38e8c45fSAndroid Build Coastguard Worker * operation, so this should be set only if needed). Typically this is used 221*38e8c45fSAndroid Build Coastguard Worker * to figure out if the content or size of a surface has changed. 222*38e8c45fSAndroid Build Coastguard Worker */ 223*38e8c45fSAndroid Build Coastguard Worker bool latchBufferImpl(bool& /*recomputeVisibleRegions*/, nsecs_t /*latchTime*/, 224*38e8c45fSAndroid Build Coastguard Worker bool bgColorOnly); 225*38e8c45fSAndroid Build Coastguard Worker 226*38e8c45fSAndroid Build Coastguard Worker sp<GraphicBuffer> getBuffer() const; 227*38e8c45fSAndroid Build Coastguard Worker /** 228*38e8c45fSAndroid Build Coastguard Worker * Returns active buffer size in the correct orientation. Buffer size is determined by undoing 229*38e8c45fSAndroid Build Coastguard Worker * any buffer transformations. Returns Rect::INVALID_RECT if the layer has no buffer or the 230*38e8c45fSAndroid Build Coastguard Worker * layer does not have a display frame and its parent is not bounded. 231*38e8c45fSAndroid Build Coastguard Worker */ 232*38e8c45fSAndroid Build Coastguard Worker Rect getBufferSize(const Layer::State&) const; 233*38e8c45fSAndroid Build Coastguard Worker 234*38e8c45fSAndroid Build Coastguard Worker FrameRate getFrameRateForLayerTree() const; 235*38e8c45fSAndroid Build Coastguard Worker 236*38e8c45fSAndroid Build Coastguard Worker bool getTransformToDisplayInverse() const; 237*38e8c45fSAndroid Build Coastguard Worker 238*38e8c45fSAndroid Build Coastguard Worker // Implements RefBase. 239*38e8c45fSAndroid Build Coastguard Worker void onFirstRef() override; 240*38e8c45fSAndroid Build Coastguard Worker 241*38e8c45fSAndroid Build Coastguard Worker struct BufferInfo { 242*38e8c45fSAndroid Build Coastguard Worker nsecs_t mDesiredPresentTime; 243*38e8c45fSAndroid Build Coastguard Worker std::shared_ptr<FenceTime> mFenceTime; 244*38e8c45fSAndroid Build Coastguard Worker sp<Fence> mFence; 245*38e8c45fSAndroid Build Coastguard Worker uint32_t mTransform{0}; 246*38e8c45fSAndroid Build Coastguard Worker ui::Dataspace mDataspace{ui::Dataspace::UNKNOWN}; 247*38e8c45fSAndroid Build Coastguard Worker std::chrono::steady_clock::time_point mTimeSinceDataspaceUpdate = 248*38e8c45fSAndroid Build Coastguard Worker std::chrono::steady_clock::time_point::min(); 249*38e8c45fSAndroid Build Coastguard Worker Rect mCrop; 250*38e8c45fSAndroid Build Coastguard Worker PixelFormat mPixelFormat{PIXEL_FORMAT_NONE}; 251*38e8c45fSAndroid Build Coastguard Worker bool mTransformToDisplayInverse{false}; 252*38e8c45fSAndroid Build Coastguard Worker std::shared_ptr<renderengine::ExternalTexture> mBuffer; 253*38e8c45fSAndroid Build Coastguard Worker uint64_t mFrameNumber; 254*38e8c45fSAndroid Build Coastguard Worker sp<IBinder> mReleaseBufferEndpoint; 255*38e8c45fSAndroid Build Coastguard Worker bool mFrameLatencyNeeded{false}; 256*38e8c45fSAndroid Build Coastguard Worker float mDesiredHdrSdrRatio = -1.f; 257*38e8c45fSAndroid Build Coastguard Worker }; 258*38e8c45fSAndroid Build Coastguard Worker 259*38e8c45fSAndroid Build Coastguard Worker BufferInfo mBufferInfo; 260*38e8c45fSAndroid Build Coastguard Worker std::shared_ptr<gui::BufferReleaseChannel::ProducerEndpoint> mBufferReleaseChannel; 261*38e8c45fSAndroid Build Coastguard Worker 262*38e8c45fSAndroid Build Coastguard Worker bool fenceHasSignaled() const; 263*38e8c45fSAndroid Build Coastguard Worker void onPreComposition(nsecs_t refreshStartTime); 264*38e8c45fSAndroid Build Coastguard Worker 265*38e8c45fSAndroid Build Coastguard Worker // Tracks mLastClientCompositionFence and gets the callback handle for this layer. 266*38e8c45fSAndroid Build Coastguard Worker sp<CallbackHandle> findCallbackHandle(); 267*38e8c45fSAndroid Build Coastguard Worker 268*38e8c45fSAndroid Build Coastguard Worker // Adds the future release fence to a list of fences that are used to release the 269*38e8c45fSAndroid Build Coastguard Worker // last presented buffer. Also keeps track of the layerstack in a list of previous 270*38e8c45fSAndroid Build Coastguard Worker // layerstacks that have been presented. 271*38e8c45fSAndroid Build Coastguard Worker void prepareReleaseCallbacks(ftl::Future<FenceResult>, ui::LayerStack layerStack); 272*38e8c45fSAndroid Build Coastguard Worker setWasClientComposed(const sp<Fence> & fence)273*38e8c45fSAndroid Build Coastguard Worker void setWasClientComposed(const sp<Fence>& fence) { 274*38e8c45fSAndroid Build Coastguard Worker mLastClientCompositionFence = fence; 275*38e8c45fSAndroid Build Coastguard Worker mClearClientCompositionFenceOnLayerDisplayed = false; 276*38e8c45fSAndroid Build Coastguard Worker } 277*38e8c45fSAndroid Build Coastguard Worker 278*38e8c45fSAndroid Build Coastguard Worker const char* getDebugName() const; 279*38e8c45fSAndroid Build Coastguard Worker 280*38e8c45fSAndroid Build Coastguard Worker static bool computeTrustedPresentationState(const FloatRect& bounds, 281*38e8c45fSAndroid Build Coastguard Worker const FloatRect& sourceBounds, 282*38e8c45fSAndroid Build Coastguard Worker const Region& coveredRegion, 283*38e8c45fSAndroid Build Coastguard Worker const FloatRect& screenBounds, float, 284*38e8c45fSAndroid Build Coastguard Worker const ui::Transform&, 285*38e8c45fSAndroid Build Coastguard Worker const TrustedPresentationThresholds&); 286*38e8c45fSAndroid Build Coastguard Worker void updateTrustedPresentationState(const DisplayDevice* display, 287*38e8c45fSAndroid Build Coastguard Worker const frontend::LayerSnapshot* snapshot, int64_t time_in_ms, 288*38e8c45fSAndroid Build Coastguard Worker bool leaveState); 289*38e8c45fSAndroid Build Coastguard Worker hasTrustedPresentationListener()290*38e8c45fSAndroid Build Coastguard Worker inline bool hasTrustedPresentationListener() { 291*38e8c45fSAndroid Build Coastguard Worker return mTrustedPresentationListener.callbackInterface != nullptr; 292*38e8c45fSAndroid Build Coastguard Worker } 293*38e8c45fSAndroid Build Coastguard Worker 294*38e8c45fSAndroid Build Coastguard Worker // Sets the masked bits. 295*38e8c45fSAndroid Build Coastguard Worker void setTransactionFlags(uint32_t mask); 296*38e8c45fSAndroid Build Coastguard Worker getSequence()297*38e8c45fSAndroid Build Coastguard Worker int32_t getSequence() const { return sequence; } 298*38e8c45fSAndroid Build Coastguard Worker 299*38e8c45fSAndroid Build Coastguard Worker // For tracing. 300*38e8c45fSAndroid Build Coastguard Worker // TODO: Replace with raw buffer id from buffer metadata when that becomes available. 301*38e8c45fSAndroid Build Coastguard Worker // GraphicBuffer::getId() does not provide a reliable global identifier. Since the traces 302*38e8c45fSAndroid Build Coastguard Worker // creates its tracks by buffer id and has no way of associating a buffer back to the process 303*38e8c45fSAndroid Build Coastguard Worker // that created it, the current implementation is only sufficient for cases where a buffer is 304*38e8c45fSAndroid Build Coastguard Worker // only used within a single layer. getCurrentBufferId()305*38e8c45fSAndroid Build Coastguard Worker uint64_t getCurrentBufferId() const { return getBuffer() ? getBuffer()->getId() : 0; } 306*38e8c45fSAndroid Build Coastguard Worker 307*38e8c45fSAndroid Build Coastguard Worker void writeCompositionStateToProto(perfetto::protos::LayerProto* layerProto, 308*38e8c45fSAndroid Build Coastguard Worker ui::LayerStack layerStack); 309*38e8c45fSAndroid Build Coastguard Worker getDrawingState()310*38e8c45fSAndroid Build Coastguard Worker inline const State& getDrawingState() const { return mDrawingState; } getDrawingState()311*38e8c45fSAndroid Build Coastguard Worker inline State& getDrawingState() { return mDrawingState; } 312*38e8c45fSAndroid Build Coastguard Worker 313*38e8c45fSAndroid Build Coastguard Worker void miniDump(std::string& result, const frontend::LayerSnapshot&, const DisplayDevice&) const; 314*38e8c45fSAndroid Build Coastguard Worker void dumpFrameStats(std::string& result) const; 315*38e8c45fSAndroid Build Coastguard Worker void clearFrameStats(); 316*38e8c45fSAndroid Build Coastguard Worker void logFrameStats(); 317*38e8c45fSAndroid Build Coastguard Worker void getFrameStats(FrameStats* outStats) const; 318*38e8c45fSAndroid Build Coastguard Worker void onDisconnect(); 319*38e8c45fSAndroid Build Coastguard Worker onHandleDestroyed()320*38e8c45fSAndroid Build Coastguard Worker bool onHandleDestroyed() { return mHandleAlive = false; } 321*38e8c45fSAndroid Build Coastguard Worker 322*38e8c45fSAndroid Build Coastguard Worker /** 323*38e8c45fSAndroid Build Coastguard Worker * Returns the cropped buffer size or the layer crop if the layer has no buffer. Return 324*38e8c45fSAndroid Build Coastguard Worker * INVALID_RECT if the layer has no buffer and no crop. 325*38e8c45fSAndroid Build Coastguard Worker * A layer with an invalid buffer size and no crop is considered to be boundless. The layer 326*38e8c45fSAndroid Build Coastguard Worker * bounds are constrained by its parent bounds. 327*38e8c45fSAndroid Build Coastguard Worker */ 328*38e8c45fSAndroid Build Coastguard Worker Rect getCroppedBufferSize(const Layer::State& s) const; 329*38e8c45fSAndroid Build Coastguard Worker 330*38e8c45fSAndroid Build Coastguard Worker void setFrameTimelineVsyncForBufferTransaction(const FrameTimelineInfo& info, nsecs_t postTime, 331*38e8c45fSAndroid Build Coastguard Worker gui::GameMode gameMode); 332*38e8c45fSAndroid Build Coastguard Worker void setFrameTimelineVsyncForBufferlessTransaction(const FrameTimelineInfo& info, 333*38e8c45fSAndroid Build Coastguard Worker nsecs_t postTime, gui::GameMode gameMode); 334*38e8c45fSAndroid Build Coastguard Worker 335*38e8c45fSAndroid Build Coastguard Worker void addSurfaceFrameDroppedForBuffer(std::shared_ptr<frametimeline::SurfaceFrame>& surfaceFrame, 336*38e8c45fSAndroid Build Coastguard Worker nsecs_t dropTime); 337*38e8c45fSAndroid Build Coastguard Worker void addSurfaceFramePresentedForBuffer( 338*38e8c45fSAndroid Build Coastguard Worker std::shared_ptr<frametimeline::SurfaceFrame>& surfaceFrame, nsecs_t acquireFenceTime, 339*38e8c45fSAndroid Build Coastguard Worker nsecs_t currentLatchTime); 340*38e8c45fSAndroid Build Coastguard Worker 341*38e8c45fSAndroid Build Coastguard Worker std::shared_ptr<frametimeline::SurfaceFrame> createSurfaceFrameForTransaction( 342*38e8c45fSAndroid Build Coastguard Worker const FrameTimelineInfo& info, nsecs_t postTime, gui::GameMode gameMode); 343*38e8c45fSAndroid Build Coastguard Worker std::shared_ptr<frametimeline::SurfaceFrame> createSurfaceFrameForBuffer( 344*38e8c45fSAndroid Build Coastguard Worker const FrameTimelineInfo& info, nsecs_t queueTime, std::string debugName, 345*38e8c45fSAndroid Build Coastguard Worker gui::GameMode gameMode); 346*38e8c45fSAndroid Build Coastguard Worker void setFrameTimelineVsyncForSkippedFrames(const FrameTimelineInfo& info, nsecs_t postTime, 347*38e8c45fSAndroid Build Coastguard Worker std::string debugName, gui::GameMode gameMode); 348*38e8c45fSAndroid Build Coastguard Worker 349*38e8c45fSAndroid Build Coastguard Worker bool setTrustedPresentationInfo(TrustedPresentationThresholds const& thresholds, 350*38e8c45fSAndroid Build Coastguard Worker TrustedPresentationListener const& listener); 351*38e8c45fSAndroid Build Coastguard Worker void setBufferReleaseChannel( 352*38e8c45fSAndroid Build Coastguard Worker const std::shared_ptr<gui::BufferReleaseChannel::ProducerEndpoint>& channel); 353*38e8c45fSAndroid Build Coastguard Worker 354*38e8c45fSAndroid Build Coastguard Worker // Creates a new handle each time, so we only expect 355*38e8c45fSAndroid Build Coastguard Worker // this to be called once. 356*38e8c45fSAndroid Build Coastguard Worker sp<IBinder> getHandle(); getName()357*38e8c45fSAndroid Build Coastguard Worker const std::string& getName() const { return mName; } 358*38e8c45fSAndroid Build Coastguard Worker getOwnerUid()359*38e8c45fSAndroid Build Coastguard Worker virtual uid_t getOwnerUid() const { return mOwnerUid; } 360*38e8c45fSAndroid Build Coastguard Worker 361*38e8c45fSAndroid Build Coastguard Worker // Used to check if mUsedVsyncIdForRefreshRateSelection should be expired when it stop updating. 362*38e8c45fSAndroid Build Coastguard Worker nsecs_t mMaxTimeForUseVsyncId = 0; 363*38e8c45fSAndroid Build Coastguard Worker // True when DrawState.useVsyncIdForRefreshRateSelection previously set to true during updating 364*38e8c45fSAndroid Build Coastguard Worker // buffer. 365*38e8c45fSAndroid Build Coastguard Worker bool mUsedVsyncIdForRefreshRateSelection{false}; 366*38e8c45fSAndroid Build Coastguard Worker 367*38e8c45fSAndroid Build Coastguard Worker // Layer serial number. This gives layers an explicit ordering, so we 368*38e8c45fSAndroid Build Coastguard Worker // have a stable sort order when their layer stack and Z-order are 369*38e8c45fSAndroid Build Coastguard Worker // the same. 370*38e8c45fSAndroid Build Coastguard Worker const int32_t sequence; 371*38e8c45fSAndroid Build Coastguard Worker 372*38e8c45fSAndroid Build Coastguard Worker // See mPendingBufferTransactions 373*38e8c45fSAndroid Build Coastguard Worker void decrementPendingBufferCount(); getPendingBufferCounter()374*38e8c45fSAndroid Build Coastguard Worker std::atomic<int32_t>* getPendingBufferCounter() { return &mPendingBuffers; } getPendingBufferCounterName()375*38e8c45fSAndroid Build Coastguard Worker std::string getPendingBufferCounterName() { return mBlastTransactionName; } 376*38e8c45fSAndroid Build Coastguard Worker void callReleaseBufferCallback(const sp<ITransactionCompletedListener>& listener, 377*38e8c45fSAndroid Build Coastguard Worker const sp<GraphicBuffer>& buffer, uint64_t framenumber, 378*38e8c45fSAndroid Build Coastguard Worker const sp<Fence>& releaseFence); 379*38e8c45fSAndroid Build Coastguard Worker bool setFrameRateForLayerTree(FrameRate, const scheduler::LayerProps&, nsecs_t now); 380*38e8c45fSAndroid Build Coastguard Worker void recordLayerHistoryBufferUpdate(const scheduler::LayerProps&, nsecs_t now); 381*38e8c45fSAndroid Build Coastguard Worker void recordLayerHistoryAnimationTx(const scheduler::LayerProps&, nsecs_t now); hasBuffer()382*38e8c45fSAndroid Build Coastguard Worker bool hasBuffer() const { return mBufferInfo.mBuffer != nullptr; } setTransformHint(std::optional<ui::Transform::RotationFlags> transformHint)383*38e8c45fSAndroid Build Coastguard Worker void setTransformHint(std::optional<ui::Transform::RotationFlags> transformHint) { 384*38e8c45fSAndroid Build Coastguard Worker mTransformHint = transformHint; 385*38e8c45fSAndroid Build Coastguard Worker } 386*38e8c45fSAndroid Build Coastguard Worker void commitTransaction(); 387*38e8c45fSAndroid Build Coastguard Worker // Keeps track of the previously presented layer stacks. This is used to get 388*38e8c45fSAndroid Build Coastguard Worker // the release fences from the correct displays when we release the last buffer 389*38e8c45fSAndroid Build Coastguard Worker // from the layer. 390*38e8c45fSAndroid Build Coastguard Worker std::vector<ui::LayerStack> mPreviouslyPresentedLayerStacks; 391*38e8c45fSAndroid Build Coastguard Worker 392*38e8c45fSAndroid Build Coastguard Worker // Release fences for buffers that have not yet received a release 393*38e8c45fSAndroid Build Coastguard Worker // callback. A release callback may not be given when capturing 394*38e8c45fSAndroid Build Coastguard Worker // screenshots asynchronously. There may be no buffer update for the 395*38e8c45fSAndroid Build Coastguard Worker // layer, but the layer will still be composited on the screen in every 396*38e8c45fSAndroid Build Coastguard Worker // frame. Kepping track of these fences ensures that they are not dropped 397*38e8c45fSAndroid Build Coastguard Worker // and can be dispatched to the client at a later time. Older fences are 398*38e8c45fSAndroid Build Coastguard Worker // dropped when a layer stack receives a new fence. 399*38e8c45fSAndroid Build Coastguard Worker // TODO(b/300533018): Track fence per multi-instance RenderEngine 400*38e8c45fSAndroid Build Coastguard Worker ftl::SmallMap<ui::LayerStack, ftl::Future<FenceResult>, ui::kDisplayCapacity> 401*38e8c45fSAndroid Build Coastguard Worker mAdditionalPreviousReleaseFences; 402*38e8c45fSAndroid Build Coastguard Worker 403*38e8c45fSAndroid Build Coastguard Worker // Exposed so SurfaceFlinger can assert that it's held 404*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceFlinger> mFlinger; 405*38e8c45fSAndroid Build Coastguard Worker 406*38e8c45fSAndroid Build Coastguard Worker // Check if the damage region is a small dirty. 407*38e8c45fSAndroid Build Coastguard Worker void setIsSmallDirty(frontend::LayerSnapshot* snapshot); 408*38e8c45fSAndroid Build Coastguard Worker 409*38e8c45fSAndroid Build Coastguard Worker protected: 410*38e8c45fSAndroid Build Coastguard Worker // For unit tests 411*38e8c45fSAndroid Build Coastguard Worker friend class TestableSurfaceFlinger; 412*38e8c45fSAndroid Build Coastguard Worker friend class FpsReporterTest; 413*38e8c45fSAndroid Build Coastguard Worker friend class RefreshRateSelectionTest; 414*38e8c45fSAndroid Build Coastguard Worker friend class SetFrameRateTest; 415*38e8c45fSAndroid Build Coastguard Worker friend class TransactionFrameTracerTest; 416*38e8c45fSAndroid Build Coastguard Worker friend class TransactionSurfaceFrameTest; 417*38e8c45fSAndroid Build Coastguard Worker 418*38e8c45fSAndroid Build Coastguard Worker void gatherBufferInfo(); 419*38e8c45fSAndroid Build Coastguard Worker 420*38e8c45fSAndroid Build Coastguard Worker compositionengine::OutputLayer* findOutputLayerForDisplay(const DisplayDevice*) const; 421*38e8c45fSAndroid Build Coastguard Worker compositionengine::OutputLayer* findOutputLayerForDisplay( 422*38e8c45fSAndroid Build Coastguard Worker const DisplayDevice*, const frontend::LayerHierarchy::TraversalPath& path) const; 423*38e8c45fSAndroid Build Coastguard Worker 424*38e8c45fSAndroid Build Coastguard Worker const std::string mName; 425*38e8c45fSAndroid Build Coastguard Worker const std::string mTransactionName{"TX - " + mName}; 426*38e8c45fSAndroid Build Coastguard Worker 427*38e8c45fSAndroid Build Coastguard Worker // These are only accessed by the main thread. 428*38e8c45fSAndroid Build Coastguard Worker State mDrawingState; 429*38e8c45fSAndroid Build Coastguard Worker 430*38e8c45fSAndroid Build Coastguard Worker TrustedPresentationThresholds mTrustedPresentationThresholds; 431*38e8c45fSAndroid Build Coastguard Worker TrustedPresentationListener mTrustedPresentationListener; 432*38e8c45fSAndroid Build Coastguard Worker bool mLastComputedTrustedPresentationState = false; 433*38e8c45fSAndroid Build Coastguard Worker bool mLastReportedTrustedPresentationState = false; 434*38e8c45fSAndroid Build Coastguard Worker int64_t mEnteredTrustedPresentationStateTime = -1; 435*38e8c45fSAndroid Build Coastguard Worker 436*38e8c45fSAndroid Build Coastguard Worker uint32_t mTransactionFlags{0}; 437*38e8c45fSAndroid Build Coastguard Worker 438*38e8c45fSAndroid Build Coastguard Worker // Leverages FrameTimeline to generate FrameStats. Since FrameTimeline already has the data, 439*38e8c45fSAndroid Build Coastguard Worker // statistical history needs to only be tracked by count of frames. 440*38e8c45fSAndroid Build Coastguard Worker // TODO: Deprecate the '--latency-clear' and get rid of this. 441*38e8c45fSAndroid Build Coastguard Worker std::atomic<uint16_t> mFrameStatsHistorySize; 442*38e8c45fSAndroid Build Coastguard Worker // Timestamp history for UIAutomation. Thread safe. 443*38e8c45fSAndroid Build Coastguard Worker FrameTracker mDeprecatedFrameTracker; 444*38e8c45fSAndroid Build Coastguard Worker 445*38e8c45fSAndroid Build Coastguard Worker // main thread 446*38e8c45fSAndroid Build Coastguard Worker sp<NativeHandle> mSidebandStream; 447*38e8c45fSAndroid Build Coastguard Worker 448*38e8c45fSAndroid Build Coastguard Worker // We encode unset as -1. 449*38e8c45fSAndroid Build Coastguard Worker std::atomic<uint64_t> mCurrentFrameNumber{0}; 450*38e8c45fSAndroid Build Coastguard Worker 451*38e8c45fSAndroid Build Coastguard Worker // protected by mLock 452*38e8c45fSAndroid Build Coastguard Worker mutable Mutex mLock; 453*38e8c45fSAndroid Build Coastguard Worker 454*38e8c45fSAndroid Build Coastguard Worker // This layer can be a cursor on some displays. 455*38e8c45fSAndroid Build Coastguard Worker bool mPotentialCursor{false}; 456*38e8c45fSAndroid Build Coastguard Worker 457*38e8c45fSAndroid Build Coastguard Worker // Window types from WindowManager.LayoutParams 458*38e8c45fSAndroid Build Coastguard Worker const gui::WindowInfo::Type mWindowType; 459*38e8c45fSAndroid Build Coastguard Worker 460*38e8c45fSAndroid Build Coastguard Worker // The owner of the layer. If created from a non system process, it will be the calling uid. 461*38e8c45fSAndroid Build Coastguard Worker // If created from a system process, the value can be passed in. 462*38e8c45fSAndroid Build Coastguard Worker uid_t mOwnerUid; 463*38e8c45fSAndroid Build Coastguard Worker 464*38e8c45fSAndroid Build Coastguard Worker // The owner pid of the layer. If created from a non system process, it will be the calling pid. 465*38e8c45fSAndroid Build Coastguard Worker // If created from a system process, the value can be passed in. 466*38e8c45fSAndroid Build Coastguard Worker pid_t mOwnerPid; 467*38e8c45fSAndroid Build Coastguard Worker 468*38e8c45fSAndroid Build Coastguard Worker int32_t mOwnerAppId; 469*38e8c45fSAndroid Build Coastguard Worker 470*38e8c45fSAndroid Build Coastguard Worker // Keeps track of the time SF latched the last buffer from this layer. 471*38e8c45fSAndroid Build Coastguard Worker // Used in buffer stuffing analysis in FrameTimeline. 472*38e8c45fSAndroid Build Coastguard Worker nsecs_t mLastLatchTime = 0; 473*38e8c45fSAndroid Build Coastguard Worker 474*38e8c45fSAndroid Build Coastguard Worker sp<Fence> mLastClientCompositionFence; 475*38e8c45fSAndroid Build Coastguard Worker bool mClearClientCompositionFenceOnLayerDisplayed = false; 476*38e8c45fSAndroid Build Coastguard Worker private: 477*38e8c45fSAndroid Build Coastguard Worker // Range of uids allocated for a user. 478*38e8c45fSAndroid Build Coastguard Worker // This value is taken from android.os.UserHandle#PER_USER_RANGE. 479*38e8c45fSAndroid Build Coastguard Worker static constexpr int32_t PER_USER_RANGE = 100000; 480*38e8c45fSAndroid Build Coastguard Worker 481*38e8c45fSAndroid Build Coastguard Worker friend class SlotGenerationTest; 482*38e8c45fSAndroid Build Coastguard Worker friend class TransactionFrameTracerTest; 483*38e8c45fSAndroid Build Coastguard Worker friend class TransactionSurfaceFrameTest; 484*38e8c45fSAndroid Build Coastguard Worker getSidebandStreamChanged()485*38e8c45fSAndroid Build Coastguard Worker bool getSidebandStreamChanged() const { return mSidebandStreamChanged; } 486*38e8c45fSAndroid Build Coastguard Worker 487*38e8c45fSAndroid Build Coastguard Worker std::atomic<bool> mSidebandStreamChanged{false}; 488*38e8c45fSAndroid Build Coastguard Worker 489*38e8c45fSAndroid Build Coastguard Worker aidl::android::hardware::graphics::composer3::Composition getCompositionType( 490*38e8c45fSAndroid Build Coastguard Worker const DisplayDevice&) const; 491*38e8c45fSAndroid Build Coastguard Worker aidl::android::hardware::graphics::composer3::Composition getCompositionType( 492*38e8c45fSAndroid Build Coastguard Worker const compositionengine::OutputLayer*) const; 493*38e8c45fSAndroid Build Coastguard Worker 494*38e8c45fSAndroid Build Coastguard Worker inline void tracePendingBufferCount(int32_t pendingBuffers); 495*38e8c45fSAndroid Build Coastguard Worker 496*38e8c45fSAndroid Build Coastguard Worker // Latch sideband stream and returns true if the dirty region should be updated. 497*38e8c45fSAndroid Build Coastguard Worker bool latchSidebandStream(bool& recomputeVisibleRegions); 498*38e8c45fSAndroid Build Coastguard Worker 499*38e8c45fSAndroid Build Coastguard Worker void updateTexImage(nsecs_t latchTime, bool bgColorOnly = false); 500*38e8c45fSAndroid Build Coastguard Worker 501*38e8c45fSAndroid Build Coastguard Worker // Crop that applies to the buffer 502*38e8c45fSAndroid Build Coastguard Worker Rect computeBufferCrop(const State& s); 503*38e8c45fSAndroid Build Coastguard Worker 504*38e8c45fSAndroid Build Coastguard Worker void callReleaseBufferCallback(const sp<ITransactionCompletedListener>& listener, 505*38e8c45fSAndroid Build Coastguard Worker const sp<GraphicBuffer>& buffer, uint64_t framenumber, 506*38e8c45fSAndroid Build Coastguard Worker const sp<Fence>& releaseFence, 507*38e8c45fSAndroid Build Coastguard Worker uint32_t currentMaxAcquiredBufferCount); 508*38e8c45fSAndroid Build Coastguard Worker hasBufferOrSidebandStream()509*38e8c45fSAndroid Build Coastguard Worker bool hasBufferOrSidebandStream() const { 510*38e8c45fSAndroid Build Coastguard Worker return ((mSidebandStream != nullptr) || (mBufferInfo.mBuffer != nullptr)); 511*38e8c45fSAndroid Build Coastguard Worker } 512*38e8c45fSAndroid Build Coastguard Worker hasBufferOrSidebandStreamInDrawing()513*38e8c45fSAndroid Build Coastguard Worker bool hasBufferOrSidebandStreamInDrawing() const { 514*38e8c45fSAndroid Build Coastguard Worker return ((mDrawingState.sidebandStream != nullptr) || (mDrawingState.buffer != nullptr)); 515*38e8c45fSAndroid Build Coastguard Worker } 516*38e8c45fSAndroid Build Coastguard Worker 517*38e8c45fSAndroid Build Coastguard Worker bool mGetHandleCalled = false; 518*38e8c45fSAndroid Build Coastguard Worker 519*38e8c45fSAndroid Build Coastguard Worker // The inherited shadow radius after taking into account the layer hierarchy. This is the 520*38e8c45fSAndroid Build Coastguard Worker // final shadow radius for this layer. If a shadow is specified for a layer, then effective 521*38e8c45fSAndroid Build Coastguard Worker // shadow radius is the set shadow radius, otherwise its the parent's shadow radius. 522*38e8c45fSAndroid Build Coastguard Worker float mEffectiveShadowRadius = 0.f; 523*38e8c45fSAndroid Build Coastguard Worker 524*38e8c45fSAndroid Build Coastguard Worker // Game mode for the layer. Set by WindowManagerShell and recorded by SurfaceFlingerStats. 525*38e8c45fSAndroid Build Coastguard Worker gui::GameMode mGameMode = gui::GameMode::Unsupported; 526*38e8c45fSAndroid Build Coastguard Worker 527*38e8c45fSAndroid Build Coastguard Worker bool mIsAtRoot = false; 528*38e8c45fSAndroid Build Coastguard Worker 529*38e8c45fSAndroid Build Coastguard Worker uint32_t mLayerCreationFlags; 530*38e8c45fSAndroid Build Coastguard Worker 531*38e8c45fSAndroid Build Coastguard Worker void releasePreviousBuffer(); 532*38e8c45fSAndroid Build Coastguard Worker void resetDrawingStateBufferInfo(); 533*38e8c45fSAndroid Build Coastguard Worker 534*38e8c45fSAndroid Build Coastguard Worker // Transform hint provided to the producer. This must be accessed holding 535*38e8c45fSAndroid Build Coastguard Worker // the mStateLock. 536*38e8c45fSAndroid Build Coastguard Worker std::optional<ui::Transform::RotationFlags> mTransformHint = std::nullopt; 537*38e8c45fSAndroid Build Coastguard Worker 538*38e8c45fSAndroid Build Coastguard Worker ReleaseCallbackId mPreviousReleaseCallbackId = ReleaseCallbackId::INVALID_ID; 539*38e8c45fSAndroid Build Coastguard Worker sp<IBinder> mPreviousReleaseBufferEndpoint; 540*38e8c45fSAndroid Build Coastguard Worker 541*38e8c45fSAndroid Build Coastguard Worker bool mReleasePreviousBuffer = false; 542*38e8c45fSAndroid Build Coastguard Worker 543*38e8c45fSAndroid Build Coastguard Worker // Stores the last set acquire fence signal time used to populate the callback handle's acquire 544*38e8c45fSAndroid Build Coastguard Worker // time. 545*38e8c45fSAndroid Build Coastguard Worker std::variant<nsecs_t, sp<Fence>> mCallbackHandleAcquireTimeOrFence = -1; 546*38e8c45fSAndroid Build Coastguard Worker 547*38e8c45fSAndroid Build Coastguard Worker const std::string mBlastTransactionName{"BufferTX - " + mName}; 548*38e8c45fSAndroid Build Coastguard Worker // This integer is incremented everytime a buffer arrives at the server for this layer, 549*38e8c45fSAndroid Build Coastguard Worker // and decremented when a buffer is dropped or latched. When changed the integer is exported 550*38e8c45fSAndroid Build Coastguard Worker // to systrace with SFTRACE_INT and mBlastTransactionName. This way when debugging perf it is 551*38e8c45fSAndroid Build Coastguard Worker // possible to see when a buffer arrived at the server, and in which frame it latched. 552*38e8c45fSAndroid Build Coastguard Worker // 553*38e8c45fSAndroid Build Coastguard Worker // You can understand the trace this way: 554*38e8c45fSAndroid Build Coastguard Worker // - If the integer increases, a buffer arrived at the server. 555*38e8c45fSAndroid Build Coastguard Worker // - If the integer decreases in latchBuffer, that buffer was latched 556*38e8c45fSAndroid Build Coastguard Worker // - If the integer decreases in setBuffer, a buffer was dropped 557*38e8c45fSAndroid Build Coastguard Worker std::atomic<int32_t> mPendingBuffers{0}; 558*38e8c45fSAndroid Build Coastguard Worker 559*38e8c45fSAndroid Build Coastguard Worker // Contains requested position and matrix updates. This will be applied if the client does 560*38e8c45fSAndroid Build Coastguard Worker // not specify a destination frame. 561*38e8c45fSAndroid Build Coastguard Worker ui::Transform mRequestedTransform; 562*38e8c45fSAndroid Build Coastguard Worker 563*38e8c45fSAndroid Build Coastguard Worker std::vector<std::pair<frontend::LayerHierarchy::TraversalPath, sp<LayerFE>>> mLayerFEs; 564*38e8c45fSAndroid Build Coastguard Worker bool mHandleAlive = false; getTimeline()565*38e8c45fSAndroid Build Coastguard Worker std::optional<std::reference_wrapper<frametimeline::FrameTimeline>> getTimeline() const { 566*38e8c45fSAndroid Build Coastguard Worker return *mFlinger->mFrameTimeline; 567*38e8c45fSAndroid Build Coastguard Worker } 568*38e8c45fSAndroid Build Coastguard Worker }; 569*38e8c45fSAndroid Build Coastguard Worker 570*38e8c45fSAndroid Build Coastguard Worker std::ostream& operator<<(std::ostream& stream, const Layer::FrameRate& rate); 571*38e8c45fSAndroid Build Coastguard Worker 572*38e8c45fSAndroid Build Coastguard Worker } // namespace android 573