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