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 | |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 17 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
Melody Hsu | e4ef87f | 2024-03-26 23:54:45 +0000 | [diff] [blame] | 18 | |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 19 | #pragma clang diagnostic push |
| 20 | #pragma clang diagnostic ignored "-Wconversion" |
| 21 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 22 | //#define LOG_NDEBUG 0 |
| 23 | #undef LOG_TAG |
| 24 | #define LOG_TAG "Layer" |
Jamie Gennis | 1c8e95c | 2012-02-23 19:27:23 -0800 | [diff] [blame] | 25 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
| 26 | |
[1;3C | 2b9fc25 | 2021-02-04 16:16:50 -0800 | [diff] [blame] | 27 | #include <android-base/properties.h> |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 28 | #include <android-base/stringprintf.h> |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 29 | #include <binder/IPCThreadState.h> |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 30 | #include <common/trace.h> |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 31 | #include <compositionengine/CompositionEngine.h> |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 32 | #include <compositionengine/Display.h> |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 33 | #include <compositionengine/LayerFECompositionState.h> |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 34 | #include <compositionengine/OutputLayer.h> |
| 35 | #include <compositionengine/impl/OutputLayerCompositionState.h> |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 36 | #include <cutils/compiler.h> |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 37 | #include <cutils/native_handle.h> |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 38 | #include <cutils/properties.h> |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 39 | #include <ftl/enum.h> |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 40 | #include <ftl/fake_guard.h> |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 41 | #include <gui/BufferItem.h> |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 42 | #include <gui/Surface.h> |
Alec Mouri | e60041e | 2019-06-14 18:59:51 -0700 | [diff] [blame] | 43 | #include <math.h> |
chaviw | 250bcbb | 2020-08-05 11:17:54 -0700 | [diff] [blame] | 44 | #include <private/android_filesystem_config.h> |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 45 | #include <renderengine/RenderEngine.h> |
Alec Mouri | e60041e | 2019-06-14 18:59:51 -0700 | [diff] [blame] | 46 | #include <stdint.h> |
| 47 | #include <stdlib.h> |
| 48 | #include <sys/types.h> |
Alec Mouri | dda07d9 | 2022-04-25 22:39:25 +0000 | [diff] [blame] | 49 | #include <system/graphics-base-v1.0.h> |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 50 | #include <ui/DebugUtils.h> |
Vishnu Nair | fed7c12 | 2023-03-18 01:54:43 +0000 | [diff] [blame] | 51 | #include <ui/FloatRect.h> |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 52 | #include <ui/GraphicBuffer.h> |
Sally Qi | f6918d4 | 2023-08-07 15:28:30 -0700 | [diff] [blame] | 53 | #include <ui/HdrRenderTypeUtils.h> |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 54 | #include <ui/PixelFormat.h> |
Vishnu Nair | fed7c12 | 2023-03-18 01:54:43 +0000 | [diff] [blame] | 55 | #include <ui/Rect.h> |
| 56 | #include <ui/Transform.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | #include <utils/Errors.h> |
| 58 | #include <utils/Log.h> |
Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 59 | #include <utils/NativeHandle.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | #include <utils/StopWatch.h> |
| 61 | |
Alec Mouri | e60041e | 2019-06-14 18:59:51 -0700 | [diff] [blame] | 62 | #include <algorithm> |
Vishnu Nair | 71fcf91 | 2022-10-18 09:14:20 -0700 | [diff] [blame] | 63 | #include <optional> |
Alec Mouri | e60041e | 2019-06-14 18:59:51 -0700 | [diff] [blame] | 64 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 65 | #include "DisplayDevice.h" |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 66 | #include "DisplayHardware/HWComposer.h" |
Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 67 | #include "FrameTimeline.h" |
Mikael Pessa | 90092f4 | 2019-08-26 17:22:04 -0700 | [diff] [blame] | 68 | #include "FrameTracer/FrameTracer.h" |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 69 | #include "FrontEnd/LayerCreationArgs.h" |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 70 | #include "FrontEnd/LayerHandle.h" |
Melody Hsu | e4ef87f | 2024-03-26 23:54:45 +0000 | [diff] [blame] | 71 | #include "Layer.h" |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 72 | #include "LayerProtoHelper.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 73 | #include "SurfaceFlinger.h" |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame] | 74 | #include "TimeStats/TimeStats.h" |
Melody Hsu | e4ef87f | 2024-03-26 23:54:45 +0000 | [diff] [blame] | 75 | #include "TransactionCallbackInvoker.h" |
Robert Carr | 3e2a299 | 2021-06-11 13:42:55 -0700 | [diff] [blame] | 76 | #include "TunnelModeEnabledReporter.h" |
Alec Mouri | 9892aac | 2023-12-11 21:16:59 +0000 | [diff] [blame] | 77 | #include "Utils/FenceUtils.h" |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 78 | |
David Sodman | 41fdfc9 | 2017-11-06 16:09:56 -0800 | [diff] [blame] | 79 | #define DEBUG_RESIZE 0 |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 80 | #define EARLY_RELEASE_ENABLED false |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 81 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | namespace android { |
Alec Mouri | 9892aac | 2023-12-11 21:16:59 +0000 | [diff] [blame] | 83 | using namespace std::chrono_literals; |
Marin Shalamanov | 1876e2e | 2020-12-04 13:23:59 +0100 | [diff] [blame] | 84 | namespace { |
| 85 | constexpr int kDumpTableRowLength = 159; |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 86 | |
Prabir Pradhan | da0f62c | 2022-07-22 19:53:04 +0000 | [diff] [blame] | 87 | const ui::Transform kIdentityTransform; |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 88 | |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 89 | TimeStats::SetFrameRateVote frameRateToSetFrameRateVotePayload(Layer::FrameRate frameRate) { |
| 90 | using FrameRateCompatibility = TimeStats::SetFrameRateVote::FrameRateCompatibility; |
| 91 | using Seamlessness = TimeStats::SetFrameRateVote::Seamlessness; |
| 92 | const auto frameRateCompatibility = [frameRate] { |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 93 | switch (frameRate.vote.type) { |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 94 | case Layer::FrameRateCompatibility::Default: |
| 95 | return FrameRateCompatibility::Default; |
| 96 | case Layer::FrameRateCompatibility::ExactOrMultiple: |
| 97 | return FrameRateCompatibility::ExactOrMultiple; |
| 98 | default: |
| 99 | return FrameRateCompatibility::Undefined; |
| 100 | } |
| 101 | }(); |
| 102 | |
| 103 | const auto seamlessness = [frameRate] { |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 104 | switch (frameRate.vote.seamlessness) { |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 105 | case scheduler::Seamlessness::OnlySeamless: |
| 106 | return Seamlessness::ShouldBeSeamless; |
| 107 | case scheduler::Seamlessness::SeamedAndSeamless: |
| 108 | return Seamlessness::NotRequired; |
| 109 | default: |
| 110 | return Seamlessness::Undefined; |
| 111 | } |
| 112 | }(); |
| 113 | |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 114 | return TimeStats::SetFrameRateVote{.frameRate = frameRate.vote.rate.getValue(), |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 115 | .frameRateCompatibility = frameRateCompatibility, |
| 116 | .seamlessness = seamlessness}; |
| 117 | } |
| 118 | |
Marin Shalamanov | 1876e2e | 2020-12-04 13:23:59 +0100 | [diff] [blame] | 119 | } // namespace |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 120 | |
Dominik Laskowski | 2f01d77 | 2022-03-23 16:01:29 -0700 | [diff] [blame] | 121 | using namespace ftl::flag_operators; |
| 122 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 123 | using base::StringAppendF; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 124 | using frontend::LayerSnapshot; |
| 125 | using frontend::RoundedCornerState; |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 126 | using gui::GameMode; |
| 127 | using gui::LayerMetadata; |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 128 | using gui::WindowInfo; |
Vishnu Nair | 494a2e4 | 2023-11-10 17:21:19 -0800 | [diff] [blame] | 129 | using ui::Size; |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 130 | |
Dominik Laskowski | 2f01d77 | 2022-03-23 16:01:29 -0700 | [diff] [blame] | 131 | using PresentState = frametimeline::SurfaceFrame::PresentState; |
| 132 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 133 | Layer::Layer(const surfaceflinger::LayerCreationArgs& args) |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 134 | : sequence(args.sequence), |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 135 | mFlinger(sp<SurfaceFlinger>::fromExisting(args.flinger)), |
Arthur Hung | 23e0750 | 2021-10-15 11:58:19 +0000 | [diff] [blame] | 136 | mName(base::StringPrintf("%s#%d", args.name.c_str(), sequence)), |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 137 | mWindowType(static_cast<WindowInfo::Type>( |
Vishnu Nair | dc83d4b | 2024-08-15 16:29:20 +0000 | [diff] [blame] | 138 | args.metadata.getInt32(gui::METADATA_WINDOW_TYPE, 0))) { |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 139 | ALOGV("Creating Layer %s", getDebugName()); |
| 140 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 141 | mDrawingState.crop.makeInvalid(); |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 142 | mDrawingState.sequence = 0; |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 143 | mDrawingState.transform.set(0, 0); |
| 144 | mDrawingState.frameNumber = 0; |
Alec Mouri | 21d9432 | 2023-10-17 19:51:39 +0000 | [diff] [blame] | 145 | mDrawingState.previousFrameNumber = 0; |
Vishnu Nair | 6322121 | 2023-04-06 15:17:37 -0700 | [diff] [blame] | 146 | mDrawingState.barrierFrameNumber = 0; |
| 147 | mDrawingState.producerId = 0; |
| 148 | mDrawingState.barrierProducerId = 0; |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 149 | mDrawingState.bufferTransform = 0; |
| 150 | mDrawingState.transformToDisplayInverse = false; |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 151 | mDrawingState.acquireFence = sp<Fence>::make(-1); |
| 152 | mDrawingState.acquireFenceTime = std::make_shared<FenceTime>(mDrawingState.acquireFence); |
Alec Mouri | 74c7ae1 | 2023-03-26 02:57:47 +0000 | [diff] [blame] | 153 | mDrawingState.dataspace = ui::Dataspace::V0_SRGB; |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 154 | mDrawingState.metadata = args.metadata; |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 155 | mDrawingState.frameTimelineInfo = {}; |
| 156 | mDrawingState.postTime = -1; |
Leon Scroggins III | 1af0fb6 | 2023-03-02 14:21:44 -0500 | [diff] [blame] | 157 | mFrameTracker.setDisplayRefreshPeriod( |
| 158 | args.flinger->mScheduler->getPacesetterVsyncPeriod().ns()); |
Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 159 | |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 160 | mOwnerUid = args.ownerUid; |
| 161 | mOwnerPid = args.ownerPid; |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 162 | mOwnerAppId = mOwnerUid % PER_USER_RANGE; |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 163 | |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 164 | mPotentialCursor = args.flags & ISurfaceComposerClient::eCursorWindow; |
Vishnu Nair | dc83d4b | 2024-08-15 16:29:20 +0000 | [diff] [blame] | 165 | mLayerFEs.emplace_back(frontend::LayerHierarchy::TraversalPath{static_cast<uint32_t>(sequence)}, |
| 166 | args.flinger->getFactory().createLayerFE(mName, this)); |
Dominik Laskowski | 7584836 | 2019-11-11 17:57:20 -0800 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | void Layer::onFirstRef() { |
| 170 | mFlinger->onLayerFirstRef(this); |
Dan Stoza | 436ccf3 | 2018-06-21 12:10:12 -0700 | [diff] [blame] | 171 | } |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 172 | |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 173 | Layer::~Layer() { |
Patrick Williams | 70093fd | 2022-12-12 16:51:52 +0000 | [diff] [blame] | 174 | LOG_ALWAYS_FATAL_IF(std::this_thread::get_id() != mFlinger->mMainThreadId, |
| 175 | "Layer destructor called off the main thread."); |
| 176 | |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 177 | if (mBufferInfo.mBuffer != nullptr) { |
| 178 | callReleaseBufferCallback(mDrawingState.releaseBufferListener, |
| 179 | mBufferInfo.mBuffer->getBuffer(), mBufferInfo.mFrameNumber, |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 180 | mBufferInfo.mFence); |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 181 | } |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 182 | const int32_t layerId = getSequence(); |
| 183 | mFlinger->mTimeStats->onDestroy(layerId); |
| 184 | mFlinger->mFrameTracer->onDestroy(layerId); |
| 185 | |
Jorim Jaggi | 10c985e | 2018-10-23 11:17:45 +0000 | [diff] [blame] | 186 | mFrameTracker.logAndResetStats(mName); |
chaviw | 74d90ad | 2019-04-26 14:45:26 -0700 | [diff] [blame] | 187 | mFlinger->onLayerDestroyed(this); |
Robert Carr | 3e2a299 | 2021-06-11 13:42:55 -0700 | [diff] [blame] | 188 | |
Alec Mouri | d05a745 | 2024-09-20 13:44:02 +0000 | [diff] [blame^] | 189 | const auto currentTime = std::chrono::steady_clock::now(); |
| 190 | if (mBufferInfo.mTimeSinceDataspaceUpdate > std::chrono::steady_clock::time_point::min()) { |
| 191 | mFlinger->mLayerEvents.emplace_back(mOwnerUid, getSequence(), mBufferInfo.mDataspace, |
| 192 | std::chrono::duration_cast<std::chrono::milliseconds>( |
| 193 | currentTime - |
| 194 | mBufferInfo.mTimeSinceDataspaceUpdate)); |
| 195 | } |
| 196 | |
Robert Carr | 3e2a299 | 2021-06-11 13:42:55 -0700 | [diff] [blame] | 197 | if (mDrawingState.sidebandStream != nullptr) { |
| 198 | mFlinger->mTunnelModeEnabledReporter->decrementTunnelModeCount(); |
| 199 | } |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 200 | if (hasTrustedPresentationListener()) { |
| 201 | mFlinger->mNumTrustedPresentationListeners--; |
Vishnu Nair | 781d725 | 2023-01-30 18:16:01 +0000 | [diff] [blame] | 202 | updateTrustedPresentationState(nullptr, nullptr, -1 /* time_in_ms */, true /* leaveState*/); |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 203 | } |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 204 | } |
| 205 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 206 | // --------------------------------------------------------------------------- |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 207 | // set-up |
| 208 | // --------------------------------------------------------------------------- |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 209 | sp<IBinder> Layer::getHandle() { |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 210 | Mutex::Autolock _l(mLock); |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 211 | if (mGetHandleCalled) { |
| 212 | ALOGE("Get handle called twice" ); |
| 213 | return nullptr; |
| 214 | } |
| 215 | mGetHandleCalled = true; |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 216 | mHandleAlive = true; |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 217 | return sp<LayerHandle>::make(mFlinger, sp<Layer>::fromExisting(this)); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | // --------------------------------------------------------------------------- |
| 221 | // h/w composer set-up |
| 222 | // --------------------------------------------------------------------------- |
| 223 | |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 224 | // No early returns. |
Vishnu Nair | 781d725 | 2023-01-30 18:16:01 +0000 | [diff] [blame] | 225 | void Layer::updateTrustedPresentationState(const DisplayDevice* display, |
| 226 | const frontend::LayerSnapshot* snapshot, |
| 227 | int64_t time_in_ms, bool leaveState) { |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 228 | if (!hasTrustedPresentationListener()) { |
| 229 | return; |
| 230 | } |
| 231 | const bool lastState = mLastComputedTrustedPresentationState; |
| 232 | mLastComputedTrustedPresentationState = false; |
| 233 | |
| 234 | if (!leaveState) { |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 235 | const auto outputLayer = findOutputLayerForDisplay(display, snapshot->path); |
Chavi Weingarten | 545da0e | 2023-02-09 14:55:57 +0000 | [diff] [blame] | 236 | if (outputLayer != nullptr) { |
| 237 | if (outputLayer->getState().coveredRegionExcludingDisplayOverlays) { |
| 238 | Region coveredRegion = |
| 239 | *outputLayer->getState().coveredRegionExcludingDisplayOverlays; |
| 240 | mLastComputedTrustedPresentationState = |
| 241 | computeTrustedPresentationState(snapshot->geomLayerBounds, |
| 242 | snapshot->sourceBounds(), coveredRegion, |
| 243 | snapshot->transformedBounds, |
| 244 | snapshot->alpha, |
| 245 | snapshot->geomLayerTransform, |
| 246 | mTrustedPresentationThresholds); |
| 247 | } else { |
| 248 | ALOGE("CoveredRegionExcludingDisplayOverlays was not set for %s. Don't compute " |
| 249 | "TrustedPresentationState", |
| 250 | getDebugName()); |
| 251 | } |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 252 | } |
| 253 | } |
| 254 | const bool newState = mLastComputedTrustedPresentationState; |
| 255 | if (lastState && !newState) { |
| 256 | // We were in the trusted presentation state, but now we left it, |
| 257 | // emit the callback if needed |
| 258 | if (mLastReportedTrustedPresentationState) { |
| 259 | mLastReportedTrustedPresentationState = false; |
| 260 | mTrustedPresentationListener.invoke(false); |
| 261 | } |
| 262 | // Reset the timer |
| 263 | mEnteredTrustedPresentationStateTime = -1; |
| 264 | } else if (!lastState && newState) { |
| 265 | // We were not in the trusted presentation state, but we entered it, begin the timer |
| 266 | // and make sure this gets called at least once more! |
| 267 | mEnteredTrustedPresentationStateTime = time_in_ms; |
| 268 | mFlinger->forceFutureUpdate(mTrustedPresentationThresholds.stabilityRequirementMs * 1.5); |
| 269 | } |
| 270 | |
| 271 | // Has the timer elapsed, but we are still in the state? Emit a callback if needed |
| 272 | if (!mLastReportedTrustedPresentationState && newState && |
| 273 | (time_in_ms - mEnteredTrustedPresentationStateTime > |
| 274 | mTrustedPresentationThresholds.stabilityRequirementMs)) { |
| 275 | mLastReportedTrustedPresentationState = true; |
| 276 | mTrustedPresentationListener.invoke(true); |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | /** |
| 281 | * See SurfaceComposerClient.h: setTrustedPresentationCallback for discussion |
| 282 | * of how the parameters and thresholds are interpreted. The general spirit is |
| 283 | * to produce an upper bound on the amount of the buffer which was presented. |
| 284 | */ |
| 285 | bool Layer::computeTrustedPresentationState(const FloatRect& bounds, const FloatRect& sourceBounds, |
| 286 | const Region& coveredRegion, |
| 287 | const FloatRect& screenBounds, float alpha, |
| 288 | const ui::Transform& effectiveTransform, |
| 289 | const TrustedPresentationThresholds& thresholds) { |
| 290 | if (alpha < thresholds.minAlpha) { |
| 291 | return false; |
| 292 | } |
| 293 | if (sourceBounds.getWidth() == 0 || sourceBounds.getHeight() == 0) { |
| 294 | return false; |
| 295 | } |
| 296 | if (screenBounds.getWidth() == 0 || screenBounds.getHeight() == 0) { |
| 297 | return false; |
| 298 | } |
| 299 | |
| 300 | const float sx = effectiveTransform.dsdx(); |
| 301 | const float sy = effectiveTransform.dsdy(); |
| 302 | float fractionRendered = std::min(sx * sy, 1.0f); |
| 303 | |
| 304 | float boundsOverSourceW = bounds.getWidth() / (float)sourceBounds.getWidth(); |
| 305 | float boundsOverSourceH = bounds.getHeight() / (float)sourceBounds.getHeight(); |
| 306 | fractionRendered *= boundsOverSourceW * boundsOverSourceH; |
| 307 | |
Chavi Weingarten | 545da0e | 2023-02-09 14:55:57 +0000 | [diff] [blame] | 308 | Region tJunctionFreeRegion = Region::createTJunctionFreeRegion(coveredRegion); |
| 309 | // Compute the size of all the rects since they may be disconnected. |
| 310 | float coveredSize = 0; |
| 311 | for (auto rect = tJunctionFreeRegion.begin(); rect < tJunctionFreeRegion.end(); rect++) { |
| 312 | float size = rect->width() * rect->height(); |
| 313 | coveredSize += size; |
| 314 | } |
| 315 | |
| 316 | fractionRendered *= (1 - (coveredSize / (screenBounds.getWidth() * screenBounds.getHeight()))); |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 317 | |
| 318 | if (fractionRendered < thresholds.minFractionRendered) { |
| 319 | return false; |
| 320 | } |
| 321 | |
| 322 | return true; |
| 323 | } |
| 324 | |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 325 | Rect Layer::getCroppedBufferSize(const State& s) const { |
| 326 | Rect size = getBufferSize(s); |
| 327 | Rect crop = getCrop(s); |
| 328 | if (!crop.isEmpty() && size.isValid()) { |
| 329 | size.intersect(crop, &size); |
| 330 | } else if (!crop.isEmpty()) { |
| 331 | size = crop; |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 332 | } |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 333 | return size; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 334 | } |
| 335 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 336 | const char* Layer::getDebugName() const { |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 337 | return mName.c_str(); |
David Sodman | 4b7c4bc | 2017-11-17 12:13:59 -0800 | [diff] [blame] | 338 | } |
| 339 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 340 | // --------------------------------------------------------------------------- |
| 341 | // drawing... |
| 342 | // --------------------------------------------------------------------------- |
| 343 | |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 344 | aidl::android::hardware::graphics::composer3::Composition Layer::getCompositionType( |
| 345 | const DisplayDevice& display) const { |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 346 | const auto outputLayer = findOutputLayerForDisplay(&display); |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 347 | return getCompositionType(outputLayer); |
| 348 | } |
| 349 | |
| 350 | aidl::android::hardware::graphics::composer3::Composition Layer::getCompositionType( |
| 351 | const compositionengine::OutputLayer* outputLayer) const { |
Alec Mouri | 6b9e991 | 2020-01-21 10:50:24 -0800 | [diff] [blame] | 352 | if (outputLayer == nullptr) { |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 353 | return aidl::android::hardware::graphics::composer3::Composition::INVALID; |
Alec Mouri | 6b9e991 | 2020-01-21 10:50:24 -0800 | [diff] [blame] | 354 | } |
| 355 | if (outputLayer->getState().hwc) { |
| 356 | return (*outputLayer->getState().hwc).hwcCompositionType; |
| 357 | } else { |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 358 | return aidl::android::hardware::graphics::composer3::Composition::CLIENT; |
Alec Mouri | 6b9e991 | 2020-01-21 10:50:24 -0800 | [diff] [blame] | 359 | } |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 360 | } |
| 361 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 362 | // ---------------------------------------------------------------------------- |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 363 | // transaction |
| 364 | // ---------------------------------------------------------------------------- |
Ady Abraham | 8372988 | 2018-12-07 12:26:48 -0800 | [diff] [blame] | 365 | |
Vishnu Nair | c1d19d7 | 2023-08-10 12:35:11 -0700 | [diff] [blame] | 366 | void Layer::commitTransaction() { |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 367 | // Set the present state for all bufferlessSurfaceFramesTX to Presented. The |
| 368 | // bufferSurfaceFrameTX will be presented in latchBuffer. |
| 369 | for (auto& [token, surfaceFrame] : mDrawingState.bufferlessSurfaceFramesTX) { |
| 370 | if (surfaceFrame->getPresentState() != PresentState::Presented) { |
| 371 | // With applyPendingStates, we could end up having presented surfaceframes from previous |
| 372 | // states |
Vishnu Nair | 7fe69ed | 2023-02-13 10:13:26 -0800 | [diff] [blame] | 373 | surfaceFrame->setPresentState(PresentState::Presented, mLastLatchTime); |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 374 | mFlinger->mFrameTimeline->addSurfaceFrame(surfaceFrame); |
| 375 | } |
| 376 | } |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 377 | mDrawingState.bufferlessSurfaceFramesTX.clear(); |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 378 | } |
| 379 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 380 | void Layer::setTransactionFlags(uint32_t mask) { |
| 381 | mTransactionFlags |= mask; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 382 | } |
| 383 | |
chaviw | 2571450 | 2021-02-11 10:01:08 -0800 | [diff] [blame] | 384 | bool Layer::setCrop(const Rect& crop) { |
Vishnu Nair | ea04b6f | 2022-08-19 21:28:17 +0000 | [diff] [blame] | 385 | if (mDrawingState.crop == crop) return false; |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 386 | mDrawingState.sequence++; |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 387 | mDrawingState.crop = crop; |
Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 388 | |
Sally Qi | 81d95e6 | 2022-03-21 19:41:33 -0700 | [diff] [blame] | 389 | setTransactionFlags(eTransactionNeeded); |
| 390 | return true; |
| 391 | } |
| 392 | |
Ady Abraham | aae5ed5 | 2020-06-26 09:32:43 -0700 | [diff] [blame] | 393 | bool Layer::isLayerFocusedBasedOnPriority(int32_t priority) { |
| 394 | return priority == PRIORITY_FOCUSED_WITH_MODE || priority == PRIORITY_FOCUSED_WITHOUT_MODE; |
| 395 | }; |
| 396 | |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 397 | void Layer::setFrameTimelineVsyncForBufferTransaction(const FrameTimelineInfo& info, |
Vishnu Nair | 39a74a9 | 2024-07-29 19:01:50 +0000 | [diff] [blame] | 398 | nsecs_t postTime, gui::GameMode gameMode) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 399 | mDrawingState.postTime = postTime; |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 400 | |
| 401 | // Check if one of the bufferlessSurfaceFramesTX contains the same vsyncId. This can happen if |
| 402 | // there are two transactions with the same token, the first one without a buffer and the |
| 403 | // second one with a buffer. We promote the bufferlessSurfaceFrame to a bufferSurfaceFrameTX |
| 404 | // in that case. |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 405 | auto it = mDrawingState.bufferlessSurfaceFramesTX.find(info.vsyncId); |
| 406 | if (it != mDrawingState.bufferlessSurfaceFramesTX.end()) { |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 407 | // Promote the bufferlessSurfaceFrame to a bufferSurfaceFrameTX |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 408 | mDrawingState.bufferSurfaceFrameTX = it->second; |
| 409 | mDrawingState.bufferlessSurfaceFramesTX.erase(it); |
| 410 | mDrawingState.bufferSurfaceFrameTX->promoteToBuffer(); |
| 411 | mDrawingState.bufferSurfaceFrameTX->setActualQueueTime(postTime); |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 412 | } else { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 413 | mDrawingState.bufferSurfaceFrameTX = |
Vishnu Nair | 39a74a9 | 2024-07-29 19:01:50 +0000 | [diff] [blame] | 414 | createSurfaceFrameForBuffer(info, postTime, mTransactionName, gameMode); |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 415 | } |
Ady Abraham | 5a3e356 | 2023-06-07 10:32:08 -0700 | [diff] [blame] | 416 | |
Vishnu Nair | 39a74a9 | 2024-07-29 19:01:50 +0000 | [diff] [blame] | 417 | setFrameTimelineVsyncForSkippedFrames(info, postTime, mTransactionName, gameMode); |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | void Layer::setFrameTimelineVsyncForBufferlessTransaction(const FrameTimelineInfo& info, |
Vishnu Nair | 39a74a9 | 2024-07-29 19:01:50 +0000 | [diff] [blame] | 421 | nsecs_t postTime, |
| 422 | gui::GameMode gameMode) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 423 | mDrawingState.frameTimelineInfo = info; |
| 424 | mDrawingState.postTime = postTime; |
Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 425 | setTransactionFlags(eTransactionNeeded); |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 426 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 427 | if (const auto& bufferSurfaceFrameTX = mDrawingState.bufferSurfaceFrameTX; |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 428 | bufferSurfaceFrameTX != nullptr) { |
| 429 | if (bufferSurfaceFrameTX->getToken() == info.vsyncId) { |
| 430 | // BufferSurfaceFrame takes precedence over BufferlessSurfaceFrame. If the same token is |
| 431 | // being used for BufferSurfaceFrame, don't create a new one. |
| 432 | return; |
| 433 | } |
| 434 | } |
| 435 | // For Transactions without a buffer, we create only one SurfaceFrame per vsyncId. If multiple |
| 436 | // transactions use the same vsyncId, we just treat them as one SurfaceFrame (unless they are |
| 437 | // targeting different vsyncs). |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 438 | auto it = mDrawingState.bufferlessSurfaceFramesTX.find(info.vsyncId); |
| 439 | if (it == mDrawingState.bufferlessSurfaceFramesTX.end()) { |
Vishnu Nair | 39a74a9 | 2024-07-29 19:01:50 +0000 | [diff] [blame] | 440 | auto surfaceFrame = createSurfaceFrameForTransaction(info, postTime, gameMode); |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 441 | mDrawingState.bufferlessSurfaceFramesTX[info.vsyncId] = surfaceFrame; |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 442 | } else { |
| 443 | if (it->second->getPresentState() == PresentState::Presented) { |
| 444 | // If the SurfaceFrame was already presented, its safe to overwrite it since it must |
| 445 | // have been from previous vsync. |
Vishnu Nair | 39a74a9 | 2024-07-29 19:01:50 +0000 | [diff] [blame] | 446 | it->second = createSurfaceFrameForTransaction(info, postTime, gameMode); |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 447 | } |
| 448 | } |
Ady Abraham | 5a3e356 | 2023-06-07 10:32:08 -0700 | [diff] [blame] | 449 | |
Vishnu Nair | 39a74a9 | 2024-07-29 19:01:50 +0000 | [diff] [blame] | 450 | setFrameTimelineVsyncForSkippedFrames(info, postTime, mTransactionName, gameMode); |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | void Layer::addSurfaceFrameDroppedForBuffer( |
Ady Abraham | 5a3e356 | 2023-06-07 10:32:08 -0700 | [diff] [blame] | 454 | std::shared_ptr<frametimeline::SurfaceFrame>& surfaceFrame, nsecs_t dropTime) { |
| 455 | surfaceFrame->setDropTime(dropTime); |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 456 | surfaceFrame->setPresentState(PresentState::Dropped); |
| 457 | mFlinger->mFrameTimeline->addSurfaceFrame(surfaceFrame); |
| 458 | } |
| 459 | |
| 460 | void Layer::addSurfaceFramePresentedForBuffer( |
| 461 | std::shared_ptr<frametimeline::SurfaceFrame>& surfaceFrame, nsecs_t acquireFenceTime, |
| 462 | nsecs_t currentLatchTime) { |
| 463 | surfaceFrame->setAcquireFenceTime(acquireFenceTime); |
| 464 | surfaceFrame->setPresentState(PresentState::Presented, mLastLatchTime); |
| 465 | mFlinger->mFrameTimeline->addSurfaceFrame(surfaceFrame); |
Vishnu Nair | a156f48 | 2023-02-22 00:23:38 +0000 | [diff] [blame] | 466 | updateLastLatchTime(currentLatchTime); |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | std::shared_ptr<frametimeline::SurfaceFrame> Layer::createSurfaceFrameForTransaction( |
Vishnu Nair | 39a74a9 | 2024-07-29 19:01:50 +0000 | [diff] [blame] | 470 | const FrameTimelineInfo& info, nsecs_t postTime, gui::GameMode gameMode) { |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 471 | auto surfaceFrame = |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 472 | mFlinger->mFrameTimeline->createSurfaceFrameForToken(info, mOwnerPid, mOwnerUid, |
| 473 | getSequence(), mName, |
Adithya Srinivasan | 785addd | 2021-03-09 00:38:00 +0000 | [diff] [blame] | 474 | mTransactionName, |
Vishnu Nair | 39a74a9 | 2024-07-29 19:01:50 +0000 | [diff] [blame] | 475 | /*isBuffer*/ false, gameMode); |
Rachel Lee | ed511ef | 2021-10-11 15:09:51 -0700 | [diff] [blame] | 476 | surfaceFrame->setActualStartTime(info.startTimeNanos); |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 477 | // For Transactions, the post time is considered to be both queue and acquire fence time. |
| 478 | surfaceFrame->setActualQueueTime(postTime); |
| 479 | surfaceFrame->setAcquireFenceTime(postTime); |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 480 | const auto fps = mFlinger->mScheduler->getFrameRateOverride(getOwnerUid()); |
| 481 | if (fps) { |
Alec Mouri | 819f630 | 2021-02-12 15:37:21 -0800 | [diff] [blame] | 482 | surfaceFrame->setRenderRate(*fps); |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 483 | } |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 484 | return surfaceFrame; |
| 485 | } |
| 486 | |
| 487 | std::shared_ptr<frametimeline::SurfaceFrame> Layer::createSurfaceFrameForBuffer( |
Vishnu Nair | 39a74a9 | 2024-07-29 19:01:50 +0000 | [diff] [blame] | 488 | const FrameTimelineInfo& info, nsecs_t queueTime, std::string debugName, |
| 489 | gui::GameMode gameMode) { |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 490 | auto surfaceFrame = |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 491 | mFlinger->mFrameTimeline->createSurfaceFrameForToken(info, mOwnerPid, mOwnerUid, |
Adithya Srinivasan | 785addd | 2021-03-09 00:38:00 +0000 | [diff] [blame] | 492 | getSequence(), mName, debugName, |
Vishnu Nair | 39a74a9 | 2024-07-29 19:01:50 +0000 | [diff] [blame] | 493 | /*isBuffer*/ true, gameMode); |
Rachel Lee | ed511ef | 2021-10-11 15:09:51 -0700 | [diff] [blame] | 494 | surfaceFrame->setActualStartTime(info.startTimeNanos); |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 495 | // For buffers, acquire fence time will set during latch. |
| 496 | surfaceFrame->setActualQueueTime(queueTime); |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 497 | const auto fps = mFlinger->mScheduler->getFrameRateOverride(getOwnerUid()); |
| 498 | if (fps) { |
Alec Mouri | 819f630 | 2021-02-12 15:37:21 -0800 | [diff] [blame] | 499 | surfaceFrame->setRenderRate(*fps); |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 500 | } |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 501 | return surfaceFrame; |
Ady Abraham | 74e1756 | 2020-08-24 18:18:19 -0700 | [diff] [blame] | 502 | } |
| 503 | |
Ady Abraham | 5a3e356 | 2023-06-07 10:32:08 -0700 | [diff] [blame] | 504 | void Layer::setFrameTimelineVsyncForSkippedFrames(const FrameTimelineInfo& info, nsecs_t postTime, |
Vishnu Nair | 39a74a9 | 2024-07-29 19:01:50 +0000 | [diff] [blame] | 505 | std::string debugName, gui::GameMode gameMode) { |
Ady Abraham | 5a3e356 | 2023-06-07 10:32:08 -0700 | [diff] [blame] | 506 | if (info.skippedFrameVsyncId == FrameTimelineInfo::INVALID_VSYNC_ID) { |
| 507 | return; |
| 508 | } |
| 509 | |
| 510 | FrameTimelineInfo skippedFrameTimelineInfo = info; |
| 511 | skippedFrameTimelineInfo.vsyncId = info.skippedFrameVsyncId; |
| 512 | |
| 513 | auto surfaceFrame = |
| 514 | mFlinger->mFrameTimeline->createSurfaceFrameForToken(skippedFrameTimelineInfo, |
| 515 | mOwnerPid, mOwnerUid, |
| 516 | getSequence(), mName, debugName, |
Vishnu Nair | 39a74a9 | 2024-07-29 19:01:50 +0000 | [diff] [blame] | 517 | /*isBuffer*/ false, gameMode); |
Ady Abraham | 5a3e356 | 2023-06-07 10:32:08 -0700 | [diff] [blame] | 518 | surfaceFrame->setActualStartTime(skippedFrameTimelineInfo.skippedFrameStartTimeNanos); |
| 519 | // For Transactions, the post time is considered to be both queue and acquire fence time. |
| 520 | surfaceFrame->setActualQueueTime(postTime); |
| 521 | surfaceFrame->setAcquireFenceTime(postTime); |
| 522 | const auto fps = mFlinger->mScheduler->getFrameRateOverride(getOwnerUid()); |
| 523 | if (fps) { |
| 524 | surfaceFrame->setRenderRate(*fps); |
| 525 | } |
Ady Abraham | 5a3e356 | 2023-06-07 10:32:08 -0700 | [diff] [blame] | 526 | addSurfaceFrameDroppedForBuffer(surfaceFrame, postTime); |
| 527 | } |
| 528 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 529 | bool Layer::setFrameRateForLayerTree(FrameRate frameRate, const scheduler::LayerProps& layerProps, |
| 530 | nsecs_t now) { |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 531 | if (mDrawingState.frameRateForLayerTree == frameRate) { |
| 532 | return false; |
| 533 | } |
| 534 | |
| 535 | mDrawingState.frameRateForLayerTree = frameRate; |
| 536 | mFlinger->mScheduler |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 537 | ->recordLayerHistory(sequence, layerProps, now, now, |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 538 | scheduler::LayerHistory::LayerUpdateType::SetFrameRate); |
Ady Abraham | a850c18 | 2021-08-04 13:04:37 -0700 | [diff] [blame] | 539 | return true; |
Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 540 | } |
| 541 | |
Ady Abraham | 59fd8ff | 2021-04-15 20:13:30 -0700 | [diff] [blame] | 542 | Layer::FrameRate Layer::getFrameRateForLayerTree() const { |
| 543 | return getDrawingState().frameRateForLayerTree; |
| 544 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 545 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 546 | // ---------------------------------------------------------------------------- |
| 547 | // debugging |
| 548 | // ---------------------------------------------------------------------------- |
| 549 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 550 | void Layer::miniDumpHeader(std::string& result) { |
Marin Shalamanov | 1876e2e | 2020-12-04 13:23:59 +0100 | [diff] [blame] | 551 | result.append(kDumpTableRowLength, '-'); |
| 552 | result.append("\n"); |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 553 | result.append(" Layer name\n"); |
| 554 | result.append(" Z | "); |
Ady Abraham | 8f1ee7f | 2019-04-05 10:32:50 -0700 | [diff] [blame] | 555 | result.append(" Window Type | "); |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 556 | result.append(" Comp Type | "); |
Yichi Chen | 6ca3519 | 2018-05-29 12:20:43 +0800 | [diff] [blame] | 557 | result.append(" Transform | "); |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 558 | result.append(" Disp Frame (LTRB) | "); |
Ady Abraham | be23e6a | 2020-05-04 14:51:16 -0700 | [diff] [blame] | 559 | result.append(" Source Crop (LTRB) | "); |
Marin Shalamanov | 1876e2e | 2020-12-04 13:23:59 +0100 | [diff] [blame] | 560 | result.append(" Frame Rate (Explicit) (Seamlessness) [Focused]\n"); |
| 561 | result.append(kDumpTableRowLength, '-'); |
| 562 | result.append("\n"); |
Ady Abraham | be23e6a | 2020-05-04 14:51:16 -0700 | [diff] [blame] | 563 | } |
| 564 | |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 565 | void Layer::miniDump(std::string& result, const frontend::LayerSnapshot& snapshot, |
| 566 | const DisplayDevice& display) const { |
| 567 | const auto outputLayer = findOutputLayerForDisplay(&display, snapshot.path); |
| 568 | if (!outputLayer) { |
| 569 | return; |
| 570 | } |
| 571 | |
| 572 | StringAppendF(&result, " %s\n", snapshot.debugName.c_str()); |
| 573 | StringAppendF(&result, " %10zu | ", snapshot.globalZ); |
| 574 | StringAppendF(&result, " %10d | ", |
| 575 | snapshot.layerMetadata.getInt32(gui::METADATA_WINDOW_TYPE, 0)); |
| 576 | StringAppendF(&result, "%10s | ", toString(getCompositionType(outputLayer)).c_str()); |
| 577 | const auto& outputLayerState = outputLayer->getState(); |
| 578 | StringAppendF(&result, "%10s | ", toString(outputLayerState.bufferTransform).c_str()); |
| 579 | const Rect& frame = outputLayerState.displayFrame; |
| 580 | StringAppendF(&result, "%4d %4d %4d %4d | ", frame.left, frame.top, frame.right, frame.bottom); |
| 581 | const FloatRect& crop = outputLayerState.sourceCrop; |
| 582 | StringAppendF(&result, "%6.1f %6.1f %6.1f %6.1f | ", crop.left, crop.top, crop.right, |
| 583 | crop.bottom); |
| 584 | const auto frameRate = snapshot.frameRate; |
Ady Abraham | 77d406d | 2023-11-22 15:00:23 -0800 | [diff] [blame] | 585 | std::string frameRateStr; |
| 586 | if (frameRate.vote.rate.isValid()) { |
| 587 | StringAppendF(&frameRateStr, "%.2f", frameRate.vote.rate.getValue()); |
| 588 | } |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 589 | if (frameRate.vote.rate.isValid() || frameRate.vote.type != FrameRateCompatibility::Default) { |
Ady Abraham | 77d406d | 2023-11-22 15:00:23 -0800 | [diff] [blame] | 590 | StringAppendF(&result, "%6s %15s %17s", frameRateStr.c_str(), |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 591 | ftl::enum_string(frameRate.vote.type).c_str(), |
| 592 | ftl::enum_string(frameRate.vote.seamlessness).c_str()); |
Ady Abraham | 77d406d | 2023-11-22 15:00:23 -0800 | [diff] [blame] | 593 | } else if (frameRate.category != FrameRateCategory::Default) { |
| 594 | StringAppendF(&result, "%6s %15s %17s", frameRateStr.c_str(), |
| 595 | (std::string("Cat::") + ftl::enum_string(frameRate.category)).c_str(), |
| 596 | ftl::enum_string(frameRate.vote.seamlessness).c_str()); |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 597 | } else { |
| 598 | result.append(41, ' '); |
| 599 | } |
| 600 | |
| 601 | const auto focused = isLayerFocusedBasedOnPriority(snapshot.frameRateSelectionPriority); |
| 602 | StringAppendF(&result, " [%s]\n", focused ? "*" : " "); |
| 603 | |
| 604 | result.append(kDumpTableRowLength, '-'); |
| 605 | result.append("\n"); |
| 606 | } |
| 607 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 608 | void Layer::dumpFrameStats(std::string& result) const { |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 609 | mFrameTracker.dumpStats(result); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 610 | } |
| 611 | |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 612 | void Layer::clearFrameStats() { |
| 613 | mFrameTracker.clearStats(); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 614 | } |
| 615 | |
Jamie Gennis | 6547ff4 | 2013-07-16 20:12:42 -0700 | [diff] [blame] | 616 | void Layer::logFrameStats() { |
| 617 | mFrameTracker.logAndResetStats(mName); |
| 618 | } |
| 619 | |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 620 | void Layer::getFrameStats(FrameStats* outStats) const { |
| 621 | mFrameTracker.getStats(outStats); |
| 622 | } |
| 623 | |
Brian Anderson | 5ea5e59 | 2016-12-01 16:54:33 -0800 | [diff] [blame] | 624 | void Layer::onDisconnect() { |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 625 | const int32_t layerId = getSequence(); |
| 626 | mFlinger->mTimeStats->onDestroy(layerId); |
| 627 | mFlinger->mFrameTracer->onDestroy(layerId); |
Brian Anderson | 5ea5e59 | 2016-12-01 16:54:33 -0800 | [diff] [blame] | 628 | } |
| 629 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 630 | void Layer::writeCompositionStateToProto(perfetto::protos::LayerProto* layerProto, |
| 631 | ui::LayerStack layerStack) { |
Vishnu Nair | ea6ff81 | 2023-02-27 17:41:39 +0000 | [diff] [blame] | 632 | ftl::FakeGuard guard(mFlinger->mStateLock); // Called from the main thread. |
Vishnu Nair | 2f65e97 | 2023-04-04 16:36:28 +0000 | [diff] [blame] | 633 | ftl::FakeGuard mainThreadGuard(kMainThreadContext); |
Vishnu Nair | ea6ff81 | 2023-02-27 17:41:39 +0000 | [diff] [blame] | 634 | |
| 635 | // Only populate for the primary display. |
Vishnu Nair | 2f65e97 | 2023-04-04 16:36:28 +0000 | [diff] [blame] | 636 | if (const auto display = mFlinger->getDisplayFromLayerStack(layerStack)) { |
Vishnu Nair | ea6ff81 | 2023-02-27 17:41:39 +0000 | [diff] [blame] | 637 | const auto compositionType = getCompositionType(*display); |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 638 | layerProto->set_hwc_composition_type( |
| 639 | static_cast<perfetto::protos::HwcCompositionType>(compositionType)); |
Vishnu Nair | 2f65e97 | 2023-04-04 16:36:28 +0000 | [diff] [blame] | 640 | LayerProtoHelper::writeToProto(getVisibleRegion(display), |
Vishnu Nair | ea6ff81 | 2023-02-27 17:41:39 +0000 | [diff] [blame] | 641 | [&]() { return layerProto->mutable_visible_region(); }); |
| 642 | } |
| 643 | } |
| 644 | |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 645 | compositionengine::OutputLayer* Layer::findOutputLayerForDisplay( |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 646 | const DisplayDevice* display) const { |
| 647 | if (!display) return nullptr; |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 648 | sp<LayerFE> layerFE; |
| 649 | frontend::LayerHierarchy::TraversalPath path{.id = static_cast<uint32_t>(sequence)}; |
| 650 | for (auto& [p, layer] : mLayerFEs) { |
| 651 | if (p == path) { |
| 652 | layerFE = layer; |
| 653 | } |
| 654 | } |
| 655 | |
| 656 | if (!layerFE) return nullptr; |
| 657 | return display->getCompositionDisplay()->getOutputLayerForLayer(layerFE); |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 658 | } |
| 659 | |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 660 | compositionengine::OutputLayer* Layer::findOutputLayerForDisplay( |
| 661 | const DisplayDevice* display, const frontend::LayerHierarchy::TraversalPath& path) const { |
| 662 | if (!display) return nullptr; |
| 663 | sp<LayerFE> layerFE; |
| 664 | for (auto& [p, layer] : mLayerFEs) { |
| 665 | if (p == path) { |
| 666 | layerFE = layer; |
| 667 | } |
| 668 | } |
| 669 | |
| 670 | if (!layerFE) return nullptr; |
| 671 | return display->getCompositionDisplay()->getOutputLayerForLayer(layerFE); |
| 672 | } |
| 673 | |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 674 | Region Layer::getVisibleRegion(const DisplayDevice* display) const { |
| 675 | const auto outputLayer = findOutputLayerForDisplay(display); |
| 676 | return outputLayer ? outputLayer->getState().visibleRegion : Region(); |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 677 | } |
| 678 | |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 679 | void Layer::callReleaseBufferCallback(const sp<ITransactionCompletedListener>& listener, |
| 680 | const sp<GraphicBuffer>& buffer, uint64_t framenumber, |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 681 | const sp<Fence>& releaseFence) { |
Patrick Williams | 7c9fa27 | 2024-08-30 12:38:43 +0000 | [diff] [blame] | 682 | if (!listener && !mBufferReleaseChannel) { |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 683 | return; |
| 684 | } |
Patrick Williams | 7c9fa27 | 2024-08-30 12:38:43 +0000 | [diff] [blame] | 685 | |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 686 | SFTRACE_FORMAT_INSTANT("callReleaseBufferCallback %s - %" PRIu64, getDebugName(), framenumber); |
Patrick Williams | 7c9fa27 | 2024-08-30 12:38:43 +0000 | [diff] [blame] | 687 | |
| 688 | ReleaseCallbackId callbackId{buffer->getId(), framenumber}; |
| 689 | const sp<Fence>& fence = releaseFence ? releaseFence : Fence::NO_FENCE; |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 690 | uint32_t currentMaxAcquiredBufferCount = |
| 691 | mFlinger->getMaxAcquiredBufferCountForCurrentRefreshRate(mOwnerUid); |
Patrick Williams | 7c9fa27 | 2024-08-30 12:38:43 +0000 | [diff] [blame] | 692 | |
| 693 | if (listener) { |
| 694 | listener->onReleaseBuffer(callbackId, fence, currentMaxAcquiredBufferCount); |
| 695 | } |
| 696 | |
| 697 | if (mBufferReleaseChannel) { |
| 698 | mBufferReleaseChannel->writeReleaseFence(callbackId, fence, currentMaxAcquiredBufferCount); |
| 699 | } |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 700 | } |
| 701 | |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 702 | sp<CallbackHandle> Layer::findCallbackHandle() { |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 703 | // If we are displayed on multiple displays in a single composition cycle then we would |
| 704 | // need to do careful tracking to enable the use of the mLastClientCompositionFence. |
| 705 | // For example we can only use it if all the displays are client comp, and we need |
| 706 | // to merge all the client comp fences. We could do this, but for now we just |
| 707 | // disable the optimization when a layer is composed on multiple displays. |
| 708 | if (mClearClientCompositionFenceOnLayerDisplayed) { |
| 709 | mLastClientCompositionFence = nullptr; |
| 710 | } else { |
| 711 | mClearClientCompositionFenceOnLayerDisplayed = true; |
| 712 | } |
| 713 | |
| 714 | // The previous release fence notifies the client that SurfaceFlinger is done with the previous |
| 715 | // buffer that was presented on this layer. The first transaction that came in this frame that |
| 716 | // replaced the previous buffer on this layer needs this release fence, because the fence will |
| 717 | // let the client know when that previous buffer is removed from the screen. |
| 718 | // |
| 719 | // Every other transaction on this layer does not need a release fence because no other |
| 720 | // Transactions that were set on this layer this frame are going to have their preceding buffer |
| 721 | // removed from the display this frame. |
| 722 | // |
| 723 | // For example, if we have 3 transactions this frame. The first transaction doesn't contain a |
| 724 | // buffer so it doesn't need a previous release fence because the layer still needs the previous |
| 725 | // buffer. The second transaction contains a buffer so it needs a previous release fence because |
| 726 | // the previous buffer will be released this frame. The third transaction also contains a |
| 727 | // buffer. It replaces the buffer in the second transaction. The buffer in the second |
| 728 | // transaction will now no longer be presented so it is released immediately and the third |
| 729 | // transaction doesn't need a previous release fence. |
| 730 | sp<CallbackHandle> ch; |
| 731 | for (auto& handle : mDrawingState.callbackHandles) { |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 732 | if (handle->releasePreviousBuffer && mPreviousReleaseBufferEndpoint == handle->listener) { |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 733 | ch = handle; |
| 734 | break; |
| 735 | } |
| 736 | } |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 737 | return ch; |
| 738 | } |
| 739 | |
| 740 | void Layer::prepareReleaseCallbacks(ftl::Future<FenceResult> futureFenceResult, |
| 741 | ui::LayerStack layerStack) { |
| 742 | sp<CallbackHandle> ch = findCallbackHandle(); |
| 743 | |
| 744 | if (ch != nullptr) { |
| 745 | ch->previousReleaseCallbackId = mPreviousReleaseCallbackId; |
| 746 | ch->previousReleaseFences.emplace_back(std::move(futureFenceResult)); |
| 747 | ch->name = mName; |
| 748 | } else { |
Melody Hsu | e4ef87f | 2024-03-26 23:54:45 +0000 | [diff] [blame] | 749 | // If we didn't get a release callback yet (e.g. some scenarios when capturing |
| 750 | // screenshots asynchronously) then make sure we don't drop the fence. |
| 751 | // Older fences for the same layer stack can be dropped when a new fence arrives. |
| 752 | // An assumption here is that RenderEngine performs work sequentially, so an |
| 753 | // incoming fence will not fire before an existing fence. |
| 754 | mAdditionalPreviousReleaseFences.emplace_or_replace(layerStack, |
| 755 | std::move(futureFenceResult)); |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | if (mBufferInfo.mBuffer) { |
| 759 | mPreviouslyPresentedLayerStacks.push_back(layerStack); |
| 760 | } |
| 761 | |
| 762 | if (mDrawingState.frameNumber > 0) { |
| 763 | mDrawingState.previousFrameNumber = mDrawingState.frameNumber; |
| 764 | } |
| 765 | } |
| 766 | |
| 767 | void Layer::onLayerDisplayed(ftl::SharedFuture<FenceResult> futureFenceResult, |
| 768 | ui::LayerStack layerStack, |
| 769 | std::function<FenceResult(FenceResult)>&& continuation) { |
| 770 | sp<CallbackHandle> ch = findCallbackHandle(); |
Alec Mouri | 9892aac | 2023-12-11 21:16:59 +0000 | [diff] [blame] | 771 | |
| 772 | if (!FlagManager::getInstance().screenshot_fence_preservation() && continuation) { |
| 773 | futureFenceResult = ftl::Future(futureFenceResult).then(std::move(continuation)).share(); |
| 774 | } |
| 775 | |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 776 | if (ch != nullptr) { |
| 777 | ch->previousReleaseCallbackId = mPreviousReleaseCallbackId; |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 778 | ch->previousSharedReleaseFences.emplace_back(std::move(futureFenceResult)); |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 779 | ch->name = mName; |
Alec Mouri | 9892aac | 2023-12-11 21:16:59 +0000 | [diff] [blame] | 780 | } else if (FlagManager::getInstance().screenshot_fence_preservation()) { |
| 781 | // If we didn't get a release callback yet, e.g. some scenarios when capturing screenshots |
| 782 | // asynchronously, then make sure we don't drop the fence. |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 783 | mPreviousReleaseFenceAndContinuations.emplace_back(std::move(futureFenceResult), |
| 784 | std::move(continuation)); |
Alec Mouri | 9892aac | 2023-12-11 21:16:59 +0000 | [diff] [blame] | 785 | std::vector<FenceAndContinuation> mergedFences; |
| 786 | sp<Fence> prevFence = nullptr; |
| 787 | // For a layer that's frequently screenshotted, try to merge fences to make sure we don't |
| 788 | // grow unbounded. |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 789 | for (const auto& futureAndContinuation : mPreviousReleaseFenceAndContinuations) { |
| 790 | auto result = futureAndContinuation.future.wait_for(0s); |
Alec Mouri | 9892aac | 2023-12-11 21:16:59 +0000 | [diff] [blame] | 791 | if (result != std::future_status::ready) { |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 792 | mergedFences.emplace_back(futureAndContinuation); |
Alec Mouri | 9892aac | 2023-12-11 21:16:59 +0000 | [diff] [blame] | 793 | continue; |
| 794 | } |
| 795 | |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 796 | mergeFence(getDebugName(), |
| 797 | futureAndContinuation.chain().get().value_or(Fence::NO_FENCE), prevFence); |
Alec Mouri | 9892aac | 2023-12-11 21:16:59 +0000 | [diff] [blame] | 798 | } |
| 799 | if (prevFence != nullptr) { |
| 800 | mergedFences.emplace_back(ftl::yield(FenceResult(std::move(prevFence))).share()); |
| 801 | } |
| 802 | |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 803 | mPreviousReleaseFenceAndContinuations.swap(mergedFences); |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 804 | } |
Alec Mouri | 9892aac | 2023-12-11 21:16:59 +0000 | [diff] [blame] | 805 | |
Vishnu Nair | 316b7f4 | 2023-10-13 23:44:46 +0000 | [diff] [blame] | 806 | if (mBufferInfo.mBuffer) { |
| 807 | mPreviouslyPresentedLayerStacks.push_back(layerStack); |
| 808 | } |
Alec Mouri | 21d9432 | 2023-10-17 19:51:39 +0000 | [diff] [blame] | 809 | |
| 810 | if (mDrawingState.frameNumber > 0) { |
| 811 | mDrawingState.previousFrameNumber = mDrawingState.frameNumber; |
| 812 | } |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 813 | } |
| 814 | |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 815 | void Layer::releasePendingBuffer(nsecs_t dequeueReadyTime) { |
| 816 | for (const auto& handle : mDrawingState.callbackHandles) { |
Patrick Williams | 7c9fa27 | 2024-08-30 12:38:43 +0000 | [diff] [blame] | 817 | handle->bufferReleaseChannel = mBufferReleaseChannel; |
Melody Hsu | 9af3070 | 2024-04-17 18:23:43 +0000 | [diff] [blame] | 818 | handle->transformHint = mTransformHint; |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 819 | handle->dequeueReadyTime = dequeueReadyTime; |
| 820 | handle->currentMaxAcquiredBufferCount = |
| 821 | mFlinger->getMaxAcquiredBufferCountForCurrentRefreshRate(mOwnerUid); |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 822 | SFTRACE_FORMAT_INSTANT("releasePendingBuffer %s - %" PRIu64, getDebugName(), |
| 823 | handle->previousReleaseCallbackId.framenumber); |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 824 | } |
| 825 | |
| 826 | for (auto& handle : mDrawingState.callbackHandles) { |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 827 | if (handle->releasePreviousBuffer && mPreviousReleaseBufferEndpoint == handle->listener) { |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 828 | handle->previousReleaseCallbackId = mPreviousReleaseCallbackId; |
| 829 | break; |
| 830 | } |
| 831 | } |
| 832 | |
Pascal Mütschard | d56514e | 2024-05-24 17:37:13 +0200 | [diff] [blame] | 833 | mFlinger->getTransactionCallbackInvoker().addCallbackHandles(mDrawingState.callbackHandles); |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 834 | mDrawingState.callbackHandles = {}; |
| 835 | } |
| 836 | |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 837 | bool Layer::setTransform(uint32_t transform) { |
| 838 | if (mDrawingState.bufferTransform == transform) return false; |
| 839 | mDrawingState.bufferTransform = transform; |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 840 | setTransactionFlags(eTransactionNeeded); |
| 841 | return true; |
| 842 | } |
| 843 | |
| 844 | bool Layer::setTransformToDisplayInverse(bool transformToDisplayInverse) { |
| 845 | if (mDrawingState.transformToDisplayInverse == transformToDisplayInverse) return false; |
| 846 | mDrawingState.sequence++; |
| 847 | mDrawingState.transformToDisplayInverse = transformToDisplayInverse; |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 848 | setTransactionFlags(eTransactionNeeded); |
| 849 | return true; |
| 850 | } |
| 851 | |
Dorin Drimus | e5374e5 | 2023-08-02 17:52:43 +0000 | [diff] [blame] | 852 | void Layer::releasePreviousBuffer() { |
| 853 | mReleasePreviousBuffer = true; |
| 854 | if (!mBufferInfo.mBuffer || |
| 855 | (!mDrawingState.buffer->hasSameBuffer(*mBufferInfo.mBuffer) || |
| 856 | mDrawingState.frameNumber != mBufferInfo.mFrameNumber)) { |
| 857 | // If mDrawingState has a buffer, and we are about to update again |
| 858 | // before swapping to drawing state, then the first buffer will be |
| 859 | // dropped and we should decrement the pending buffer count and |
| 860 | // call any release buffer callbacks if set. |
| 861 | callReleaseBufferCallback(mDrawingState.releaseBufferListener, |
| 862 | mDrawingState.buffer->getBuffer(), mDrawingState.frameNumber, |
| 863 | mDrawingState.acquireFence); |
Dominic Lemire | 95c4ecc | 2024-07-09 12:06:18 -0700 | [diff] [blame] | 864 | const int32_t layerId = getSequence(); |
| 865 | mFlinger->mTimeStats->removeTimeRecord(layerId, mDrawingState.frameNumber); |
Dorin Drimus | e5374e5 | 2023-08-02 17:52:43 +0000 | [diff] [blame] | 866 | decrementPendingBufferCount(); |
| 867 | if (mDrawingState.bufferSurfaceFrameTX != nullptr && |
| 868 | mDrawingState.bufferSurfaceFrameTX->getPresentState() != PresentState::Presented) { |
| 869 | addSurfaceFrameDroppedForBuffer(mDrawingState.bufferSurfaceFrameTX, systemTime()); |
| 870 | mDrawingState.bufferSurfaceFrameTX.reset(); |
| 871 | } |
| 872 | } else if (EARLY_RELEASE_ENABLED && mLastClientCompositionFence != nullptr) { |
| 873 | callReleaseBufferCallback(mDrawingState.releaseBufferListener, |
| 874 | mDrawingState.buffer->getBuffer(), mDrawingState.frameNumber, |
| 875 | mLastClientCompositionFence); |
| 876 | mLastClientCompositionFence = nullptr; |
| 877 | } |
| 878 | } |
| 879 | |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 880 | void Layer::resetDrawingStateBufferInfo() { |
| 881 | mDrawingState.producerId = 0; |
| 882 | mDrawingState.frameNumber = 0; |
Alec Mouri | 21d9432 | 2023-10-17 19:51:39 +0000 | [diff] [blame] | 883 | mDrawingState.previousFrameNumber = 0; |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 884 | mDrawingState.releaseBufferListener = nullptr; |
| 885 | mDrawingState.buffer = nullptr; |
| 886 | mDrawingState.acquireFence = sp<Fence>::make(-1); |
| 887 | mDrawingState.acquireFenceTime = std::make_unique<FenceTime>(mDrawingState.acquireFence); |
| 888 | mCallbackHandleAcquireTimeOrFence = mDrawingState.acquireFenceTime->getSignalTime(); |
| 889 | mDrawingState.releaseBufferEndpoint = nullptr; |
| 890 | } |
| 891 | |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 892 | bool Layer::setBuffer(std::shared_ptr<renderengine::ExternalTexture>& buffer, |
| 893 | const BufferData& bufferData, nsecs_t postTime, nsecs_t desiredPresentTime, |
Vishnu Nair | 39a74a9 | 2024-07-29 19:01:50 +0000 | [diff] [blame] | 894 | bool isAutoTimestamp, const FrameTimelineInfo& info, gui::GameMode gameMode) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 895 | SFTRACE_FORMAT("setBuffer %s - hasBuffer=%s", getDebugName(), (buffer ? "true" : "false")); |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 896 | |
| 897 | const bool frameNumberChanged = |
| 898 | bufferData.flags.test(BufferData::BufferDataChange::frameNumberChanged); |
| 899 | const uint64_t frameNumber = |
| 900 | frameNumberChanged ? bufferData.frameNumber : mDrawingState.frameNumber + 1; |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 901 | SFTRACE_FORMAT_INSTANT("setBuffer %s - %" PRIu64, getDebugName(), frameNumber); |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 902 | |
| 903 | if (mDrawingState.buffer) { |
Dorin Drimus | e5374e5 | 2023-08-02 17:52:43 +0000 | [diff] [blame] | 904 | releasePreviousBuffer(); |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 905 | } else if (buffer) { |
Vishnu Nair | c09c023 | 2023-03-02 03:22:35 +0000 | [diff] [blame] | 906 | // if we are latching a buffer for the first time then clear the mLastLatchTime since |
| 907 | // we don't want to incorrectly classify a frame if we miss the desired present time. |
| 908 | updateLastLatchTime(0); |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 909 | } |
| 910 | |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 911 | mDrawingState.desiredPresentTime = desiredPresentTime; |
| 912 | mDrawingState.isAutoTimestamp = isAutoTimestamp; |
| 913 | mDrawingState.latchedVsyncId = info.vsyncId; |
Ady Abraham | 5526916 | 2023-05-09 11:26:06 -0700 | [diff] [blame] | 914 | mDrawingState.useVsyncIdForRefreshRateSelection = info.useForRefreshRateSelection; |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 915 | if (!buffer) { |
| 916 | resetDrawingStateBufferInfo(); |
| 917 | setTransactionFlags(eTransactionNeeded); |
| 918 | mDrawingState.bufferSurfaceFrameTX = nullptr; |
Vishnu Nair | 39a74a9 | 2024-07-29 19:01:50 +0000 | [diff] [blame] | 919 | setFrameTimelineVsyncForBufferlessTransaction(info, postTime, gameMode); |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 920 | return true; |
Dorin Drimus | e5374e5 | 2023-08-02 17:52:43 +0000 | [diff] [blame] | 921 | } else { |
| 922 | // release sideband stream if it exists and a non null buffer is being set |
| 923 | if (mDrawingState.sidebandStream != nullptr) { |
Vishnu Nair | 39a74a9 | 2024-07-29 19:01:50 +0000 | [diff] [blame] | 924 | setSidebandStream(nullptr, info, postTime, gameMode); |
Dorin Drimus | e5374e5 | 2023-08-02 17:52:43 +0000 | [diff] [blame] | 925 | } |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 926 | } |
| 927 | |
Vishnu Nair | d1f7498 | 2023-06-15 20:16:51 -0700 | [diff] [blame] | 928 | if ((mDrawingState.producerId > bufferData.producerId) || |
| 929 | ((mDrawingState.producerId == bufferData.producerId) && |
| 930 | (mDrawingState.frameNumber > frameNumber))) { |
| 931 | ALOGE("Out of order buffers detected for %s producedId=%d frameNumber=%" PRIu64 |
| 932 | " -> producedId=%d frameNumber=%" PRIu64, |
| 933 | getDebugName(), mDrawingState.producerId, mDrawingState.frameNumber, |
| 934 | bufferData.producerId, frameNumber); |
| 935 | TransactionTraceWriter::getInstance().invoke("out_of_order_buffers_", /*overwrite=*/false); |
| 936 | } |
| 937 | |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 938 | mDrawingState.producerId = bufferData.producerId; |
Vishnu Nair | 6322121 | 2023-04-06 15:17:37 -0700 | [diff] [blame] | 939 | mDrawingState.barrierProducerId = |
| 940 | std::max(mDrawingState.producerId, mDrawingState.barrierProducerId); |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 941 | mDrawingState.frameNumber = frameNumber; |
Vishnu Nair | 6322121 | 2023-04-06 15:17:37 -0700 | [diff] [blame] | 942 | mDrawingState.barrierFrameNumber = |
| 943 | std::max(mDrawingState.frameNumber, mDrawingState.barrierFrameNumber); |
| 944 | |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 945 | mDrawingState.releaseBufferListener = bufferData.releaseBufferListener; |
| 946 | mDrawingState.buffer = std::move(buffer); |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 947 | mDrawingState.acquireFence = bufferData.flags.test(BufferData::BufferDataChange::fenceChanged) |
| 948 | ? bufferData.acquireFence |
| 949 | : Fence::NO_FENCE; |
| 950 | mDrawingState.acquireFenceTime = std::make_unique<FenceTime>(mDrawingState.acquireFence); |
| 951 | if (mDrawingState.acquireFenceTime->getSignalTime() == Fence::SIGNAL_TIME_PENDING) { |
| 952 | // We latched this buffer unsiganled, so we need to pass the acquire fence |
| 953 | // on the callback instead of just the acquire time, since it's unknown at |
| 954 | // this point. |
| 955 | mCallbackHandleAcquireTimeOrFence = mDrawingState.acquireFence; |
| 956 | } else { |
| 957 | mCallbackHandleAcquireTimeOrFence = mDrawingState.acquireFenceTime->getSignalTime(); |
| 958 | } |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 959 | setTransactionFlags(eTransactionNeeded); |
| 960 | |
| 961 | const int32_t layerId = getSequence(); |
| 962 | mFlinger->mTimeStats->setPostTime(layerId, mDrawingState.frameNumber, getName().c_str(), |
Vishnu Nair | 39a74a9 | 2024-07-29 19:01:50 +0000 | [diff] [blame] | 963 | mOwnerUid, postTime, gameMode); |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 964 | |
Vishnu Nair | 39a74a9 | 2024-07-29 19:01:50 +0000 | [diff] [blame] | 965 | setFrameTimelineVsyncForBufferTransaction(info, postTime, gameMode); |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 966 | |
Nergi Rahardi | 39f510f | 2024-05-23 15:16:54 +0900 | [diff] [blame] | 967 | if (bufferData.dequeueTime > 0) { |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 968 | const uint64_t bufferId = mDrawingState.buffer->getId(); |
| 969 | mFlinger->mFrameTracer->traceNewLayer(layerId, getName().c_str()); |
Nergi Rahardi | 39f510f | 2024-05-23 15:16:54 +0900 | [diff] [blame] | 970 | mFlinger->mFrameTracer->traceTimestamp(layerId, bufferId, frameNumber, |
| 971 | bufferData.dequeueTime, |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 972 | FrameTracer::FrameEvent::DEQUEUE); |
| 973 | mFlinger->mFrameTracer->traceTimestamp(layerId, bufferId, frameNumber, postTime, |
| 974 | FrameTracer::FrameEvent::QUEUE); |
| 975 | } |
| 976 | |
| 977 | mDrawingState.releaseBufferEndpoint = bufferData.releaseBufferEndpoint; |
Arthur Hung | c70bee2 | 2023-06-02 01:35:52 +0000 | [diff] [blame] | 978 | |
| 979 | // If the layer had been updated a TextureView, this would make sure the present time could be |
| 980 | // same to TextureView update when it's a small dirty, and get the correct heuristic rate. |
Jerry Chang | 3667800 | 2023-11-29 16:56:17 +0000 | [diff] [blame] | 981 | if (mFlinger->mScheduler->supportSmallDirtyDetection(mOwnerAppId)) { |
Arthur Hung | c70bee2 | 2023-06-02 01:35:52 +0000 | [diff] [blame] | 982 | if (mDrawingState.useVsyncIdForRefreshRateSelection) { |
| 983 | mUsedVsyncIdForRefreshRateSelection = true; |
| 984 | } |
| 985 | } |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 986 | return true; |
| 987 | } |
| 988 | |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 989 | void Layer::setDesiredPresentTime(nsecs_t desiredPresentTime, bool isAutoTimestamp) { |
| 990 | mDrawingState.desiredPresentTime = desiredPresentTime; |
| 991 | mDrawingState.isAutoTimestamp = isAutoTimestamp; |
| 992 | } |
| 993 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 994 | void Layer::recordLayerHistoryBufferUpdate(const scheduler::LayerProps& layerProps, nsecs_t now) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 995 | SFTRACE_CALL(); |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 996 | const nsecs_t presentTime = [&] { |
Ady Abraham | 5526916 | 2023-05-09 11:26:06 -0700 | [diff] [blame] | 997 | if (!mDrawingState.isAutoTimestamp) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 998 | SFTRACE_FORMAT_INSTANT("desiredPresentTime"); |
Ady Abraham | 5526916 | 2023-05-09 11:26:06 -0700 | [diff] [blame] | 999 | return mDrawingState.desiredPresentTime; |
| 1000 | } |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 1001 | |
Ady Abraham | 5526916 | 2023-05-09 11:26:06 -0700 | [diff] [blame] | 1002 | if (mDrawingState.useVsyncIdForRefreshRateSelection) { |
| 1003 | const auto prediction = |
| 1004 | mFlinger->mFrameTimeline->getTokenManager()->getPredictionsForToken( |
| 1005 | mDrawingState.latchedVsyncId); |
| 1006 | if (prediction.has_value()) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 1007 | SFTRACE_FORMAT_INSTANT("predictedPresentTime"); |
Arthur Hung | c70bee2 | 2023-06-02 01:35:52 +0000 | [diff] [blame] | 1008 | mMaxTimeForUseVsyncId = prediction->presentTime + |
| 1009 | scheduler::LayerHistory::kMaxPeriodForHistory.count(); |
Ady Abraham | 5526916 | 2023-05-09 11:26:06 -0700 | [diff] [blame] | 1010 | return prediction->presentTime; |
| 1011 | } |
| 1012 | } |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 1013 | |
Jerry Chang | 3667800 | 2023-11-29 16:56:17 +0000 | [diff] [blame] | 1014 | if (!mFlinger->mScheduler->supportSmallDirtyDetection(mOwnerAppId)) { |
Arthur Hung | c70bee2 | 2023-06-02 01:35:52 +0000 | [diff] [blame] | 1015 | return static_cast<nsecs_t>(0); |
| 1016 | } |
| 1017 | |
| 1018 | // If the layer is not an application and didn't set an explicit rate or desiredPresentTime, |
| 1019 | // return "0" to tell the layer history that it will use the max refresh rate without |
| 1020 | // calculating the adaptive rate. |
| 1021 | if (mWindowType != WindowInfo::Type::APPLICATION && |
| 1022 | mWindowType != WindowInfo::Type::BASE_APPLICATION) { |
| 1023 | return static_cast<nsecs_t>(0); |
| 1024 | } |
| 1025 | |
| 1026 | // Return the valid present time only when the layer potentially updated a TextureView so |
| 1027 | // LayerHistory could heuristically calculate the rate if the UI is continually updating. |
| 1028 | if (mUsedVsyncIdForRefreshRateSelection) { |
| 1029 | const auto prediction = |
| 1030 | mFlinger->mFrameTimeline->getTokenManager()->getPredictionsForToken( |
| 1031 | mDrawingState.latchedVsyncId); |
| 1032 | if (prediction.has_value()) { |
| 1033 | if (mMaxTimeForUseVsyncId >= prediction->presentTime) { |
| 1034 | return prediction->presentTime; |
| 1035 | } |
| 1036 | mUsedVsyncIdForRefreshRateSelection = false; |
| 1037 | } |
| 1038 | } |
| 1039 | |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 1040 | return static_cast<nsecs_t>(0); |
| 1041 | }(); |
Ady Abraham | 5526916 | 2023-05-09 11:26:06 -0700 | [diff] [blame] | 1042 | |
Vishnu Nair | 2665ca9 | 2024-07-09 22:08:15 +0000 | [diff] [blame] | 1043 | if (SFTRACE_ENABLED() && presentTime > 0) { |
Ady Abraham | 5526916 | 2023-05-09 11:26:06 -0700 | [diff] [blame] | 1044 | const auto presentIn = TimePoint::fromNs(presentTime) - TimePoint::now(); |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 1045 | SFTRACE_FORMAT_INSTANT("presentIn %s", to_string(presentIn).c_str()); |
Ady Abraham | 5526916 | 2023-05-09 11:26:06 -0700 | [diff] [blame] | 1046 | } |
| 1047 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 1048 | mFlinger->mScheduler->recordLayerHistory(sequence, layerProps, presentTime, now, |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 1049 | scheduler::LayerHistory::LayerUpdateType::Buffer); |
| 1050 | } |
| 1051 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 1052 | void Layer::recordLayerHistoryAnimationTx(const scheduler::LayerProps& layerProps, nsecs_t now) { |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 1053 | const nsecs_t presentTime = |
| 1054 | mDrawingState.isAutoTimestamp ? 0 : mDrawingState.desiredPresentTime; |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 1055 | mFlinger->mScheduler->recordLayerHistory(sequence, layerProps, presentTime, now, |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 1056 | scheduler::LayerHistory::LayerUpdateType::AnimationTX); |
| 1057 | } |
| 1058 | |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1059 | bool Layer::setDataspace(ui::Dataspace dataspace) { |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1060 | if (mDrawingState.dataspace == dataspace) return false; |
| 1061 | mDrawingState.dataspace = dataspace; |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1062 | setTransactionFlags(eTransactionNeeded); |
| 1063 | return true; |
| 1064 | } |
| 1065 | |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 1066 | bool Layer::setExtendedRangeBrightness(float currentBufferRatio, float desiredRatio) { |
Sally Qi | 963049b | 2023-03-23 14:06:21 -0700 | [diff] [blame] | 1067 | if (mDrawingState.currentHdrSdrRatio == currentBufferRatio && |
| 1068 | mDrawingState.desiredHdrSdrRatio == desiredRatio) |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 1069 | return false; |
Sally Qi | 963049b | 2023-03-23 14:06:21 -0700 | [diff] [blame] | 1070 | mDrawingState.currentHdrSdrRatio = currentBufferRatio; |
| 1071 | mDrawingState.desiredHdrSdrRatio = desiredRatio; |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 1072 | setTransactionFlags(eTransactionNeeded); |
| 1073 | return true; |
| 1074 | } |
| 1075 | |
Alec Mouri | 1b0d4e1 | 2024-02-12 22:27:19 +0000 | [diff] [blame] | 1076 | bool Layer::setDesiredHdrHeadroom(float desiredRatio) { |
| 1077 | if (mDrawingState.desiredHdrSdrRatio == desiredRatio) return false; |
| 1078 | mDrawingState.desiredHdrSdrRatio = desiredRatio; |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1079 | setTransactionFlags(eTransactionNeeded); |
| 1080 | return true; |
| 1081 | } |
| 1082 | |
Dorin Drimus | e5374e5 | 2023-08-02 17:52:43 +0000 | [diff] [blame] | 1083 | bool Layer::setSidebandStream(const sp<NativeHandle>& sidebandStream, const FrameTimelineInfo& info, |
Vishnu Nair | 39a74a9 | 2024-07-29 19:01:50 +0000 | [diff] [blame] | 1084 | nsecs_t postTime, gui::GameMode gameMode) { |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1085 | if (mDrawingState.sidebandStream == sidebandStream) return false; |
| 1086 | |
| 1087 | if (mDrawingState.sidebandStream != nullptr && sidebandStream == nullptr) { |
| 1088 | mFlinger->mTunnelModeEnabledReporter->decrementTunnelModeCount(); |
| 1089 | } else if (sidebandStream != nullptr) { |
| 1090 | mFlinger->mTunnelModeEnabledReporter->incrementTunnelModeCount(); |
| 1091 | } |
| 1092 | |
| 1093 | mDrawingState.sidebandStream = sidebandStream; |
Dorin Drimus | e5374e5 | 2023-08-02 17:52:43 +0000 | [diff] [blame] | 1094 | if (sidebandStream != nullptr && mDrawingState.buffer != nullptr) { |
| 1095 | releasePreviousBuffer(); |
| 1096 | resetDrawingStateBufferInfo(); |
| 1097 | mDrawingState.bufferSurfaceFrameTX = nullptr; |
Vishnu Nair | 39a74a9 | 2024-07-29 19:01:50 +0000 | [diff] [blame] | 1098 | setFrameTimelineVsyncForBufferlessTransaction(info, postTime, gameMode); |
Dorin Drimus | e5374e5 | 2023-08-02 17:52:43 +0000 | [diff] [blame] | 1099 | } |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1100 | setTransactionFlags(eTransactionNeeded); |
| 1101 | if (!mSidebandStreamChanged.exchange(true)) { |
| 1102 | // mSidebandStreamChanged was false |
| 1103 | mFlinger->onLayerUpdate(); |
| 1104 | } |
| 1105 | return true; |
| 1106 | } |
| 1107 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 1108 | bool Layer::setTransactionCompletedListeners(const std::vector<sp<CallbackHandle>>& handles, |
| 1109 | bool willPresent) { |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1110 | // If there is no handle, we will not send a callback so reset mReleasePreviousBuffer and return |
| 1111 | if (handles.empty()) { |
| 1112 | mReleasePreviousBuffer = false; |
| 1113 | return false; |
| 1114 | } |
| 1115 | |
Pascal Muetschard | 81cef29 | 2023-02-06 12:18:52 +0100 | [diff] [blame] | 1116 | std::deque<sp<CallbackHandle>> remainingHandles; |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1117 | for (const auto& handle : handles) { |
| 1118 | // If this transaction set a buffer on this layer, release its previous buffer |
| 1119 | handle->releasePreviousBuffer = mReleasePreviousBuffer; |
| 1120 | |
| 1121 | // If this layer will be presented in this frame |
| 1122 | if (willPresent) { |
| 1123 | // If this transaction set an acquire fence on this layer, set its acquire time |
| 1124 | handle->acquireTimeOrFence = mCallbackHandleAcquireTimeOrFence; |
| 1125 | handle->frameNumber = mDrawingState.frameNumber; |
Alec Mouri | 21d9432 | 2023-10-17 19:51:39 +0000 | [diff] [blame] | 1126 | handle->previousFrameNumber = mDrawingState.previousFrameNumber; |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 1127 | if (FlagManager::getInstance().ce_fence_promise() && |
Alec Mouri | 9892aac | 2023-12-11 21:16:59 +0000 | [diff] [blame] | 1128 | mPreviousReleaseBufferEndpoint == handle->listener) { |
Melody Hsu | e4ef87f | 2024-03-26 23:54:45 +0000 | [diff] [blame] | 1129 | // Add fence from previous screenshot now so that it can be dispatched to the |
Alec Mouri | 9892aac | 2023-12-11 21:16:59 +0000 | [diff] [blame] | 1130 | // client. |
Melody Hsu | e4ef87f | 2024-03-26 23:54:45 +0000 | [diff] [blame] | 1131 | for (auto& [_, future] : mAdditionalPreviousReleaseFences) { |
| 1132 | handle->previousReleaseFences.emplace_back(std::move(future)); |
Alec Mouri | 9892aac | 2023-12-11 21:16:59 +0000 | [diff] [blame] | 1133 | } |
| 1134 | mAdditionalPreviousReleaseFences.clear(); |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 1135 | } else if (FlagManager::getInstance().screenshot_fence_preservation() && |
| 1136 | mPreviousReleaseBufferEndpoint == handle->listener) { |
| 1137 | // Add fences from previous screenshots now so that they can be dispatched to the |
| 1138 | // client. |
| 1139 | for (const auto& futureAndContinution : mPreviousReleaseFenceAndContinuations) { |
| 1140 | handle->previousSharedReleaseFences.emplace_back(futureAndContinution.chain()); |
| 1141 | } |
| 1142 | mPreviousReleaseFenceAndContinuations.clear(); |
Alec Mouri | 9892aac | 2023-12-11 21:16:59 +0000 | [diff] [blame] | 1143 | } |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1144 | // Store so latched time and release fence can be set |
| 1145 | mDrawingState.callbackHandles.push_back(handle); |
| 1146 | |
| 1147 | } else { // If this layer will NOT need to be relatched and presented this frame |
Pascal Muetschard | 81cef29 | 2023-02-06 12:18:52 +0100 | [diff] [blame] | 1148 | // Queue this handle to be notified below. |
| 1149 | remainingHandles.push_back(handle); |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1150 | } |
| 1151 | } |
| 1152 | |
Pascal Muetschard | 81cef29 | 2023-02-06 12:18:52 +0100 | [diff] [blame] | 1153 | if (!remainingHandles.empty()) { |
| 1154 | // Notify the transaction completed threads these handles are done. These are only the |
| 1155 | // handles that were not added to the mDrawingState, which will be notified later. |
Pascal Mütschard | d56514e | 2024-05-24 17:37:13 +0200 | [diff] [blame] | 1156 | mFlinger->getTransactionCallbackInvoker().addCallbackHandles(remainingHandles); |
Pascal Muetschard | 81cef29 | 2023-02-06 12:18:52 +0100 | [diff] [blame] | 1157 | } |
| 1158 | |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1159 | mReleasePreviousBuffer = false; |
| 1160 | mCallbackHandleAcquireTimeOrFence = -1; |
| 1161 | |
| 1162 | return willPresent; |
| 1163 | } |
| 1164 | |
| 1165 | Rect Layer::getBufferSize(const State& /*s*/) const { |
| 1166 | // for buffer state layers we use the display frame size as the buffer size. |
| 1167 | |
| 1168 | if (mBufferInfo.mBuffer == nullptr) { |
| 1169 | return Rect::INVALID_RECT; |
| 1170 | } |
| 1171 | |
| 1172 | uint32_t bufWidth = mBufferInfo.mBuffer->getWidth(); |
| 1173 | uint32_t bufHeight = mBufferInfo.mBuffer->getHeight(); |
| 1174 | |
| 1175 | // Undo any transformations on the buffer and return the result. |
| 1176 | if (mBufferInfo.mTransform & ui::Transform::ROT_90) { |
| 1177 | std::swap(bufWidth, bufHeight); |
| 1178 | } |
| 1179 | |
| 1180 | if (getTransformToDisplayInverse()) { |
Leon Scroggins III | 85d4b22 | 2023-05-09 13:58:18 -0400 | [diff] [blame] | 1181 | uint32_t invTransform = SurfaceFlinger::getActiveDisplayRotationFlags(); |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1182 | if (invTransform & ui::Transform::ROT_90) { |
| 1183 | std::swap(bufWidth, bufHeight); |
| 1184 | } |
| 1185 | } |
| 1186 | |
| 1187 | return Rect(0, 0, static_cast<int32_t>(bufWidth), static_cast<int32_t>(bufHeight)); |
| 1188 | } |
| 1189 | |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1190 | bool Layer::fenceHasSignaled() const { |
| 1191 | if (SurfaceFlinger::enableLatchUnsignaledConfig != LatchUnsignaledConfig::Disabled) { |
| 1192 | return true; |
| 1193 | } |
| 1194 | |
| 1195 | const bool fenceSignaled = |
| 1196 | getDrawingState().acquireFence->getStatus() == Fence::Status::Signaled; |
| 1197 | if (!fenceSignaled) { |
| 1198 | mFlinger->mTimeStats->incrementLatchSkipped(getSequence(), |
| 1199 | TimeStats::LatchSkipReason::LateAcquire); |
| 1200 | } |
| 1201 | |
| 1202 | return fenceSignaled; |
| 1203 | } |
| 1204 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 1205 | void Layer::onPreComposition(nsecs_t refreshStartTime) { |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1206 | for (const auto& handle : mDrawingState.callbackHandles) { |
| 1207 | handle->refreshStartTime = refreshStartTime; |
| 1208 | } |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1209 | } |
| 1210 | |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1211 | bool Layer::latchSidebandStream(bool& recomputeVisibleRegions) { |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1212 | if (mSidebandStreamChanged.exchange(false)) { |
| 1213 | const State& s(getDrawingState()); |
| 1214 | // mSidebandStreamChanged was true |
| 1215 | mSidebandStream = s.sidebandStream; |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1216 | if (mSidebandStream != nullptr) { |
| 1217 | setTransactionFlags(eTransactionNeeded); |
| 1218 | mFlinger->setTransactionFlags(eTraversalNeeded); |
| 1219 | } |
| 1220 | recomputeVisibleRegions = true; |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1221 | return true; |
| 1222 | } |
| 1223 | return false; |
| 1224 | } |
| 1225 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 1226 | void Layer::updateTexImage(nsecs_t latchTime, bool bgColorOnly) { |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1227 | const State& s(getDrawingState()); |
| 1228 | |
| 1229 | if (!s.buffer) { |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 1230 | if (bgColorOnly || mBufferInfo.mBuffer) { |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1231 | for (auto& handle : mDrawingState.callbackHandles) { |
| 1232 | handle->latchTime = latchTime; |
| 1233 | } |
| 1234 | } |
| 1235 | return; |
| 1236 | } |
| 1237 | |
| 1238 | for (auto& handle : mDrawingState.callbackHandles) { |
| 1239 | if (handle->frameNumber == mDrawingState.frameNumber) { |
| 1240 | handle->latchTime = latchTime; |
| 1241 | } |
| 1242 | } |
| 1243 | |
| 1244 | const int32_t layerId = getSequence(); |
| 1245 | const uint64_t bufferId = mDrawingState.buffer->getId(); |
| 1246 | const uint64_t frameNumber = mDrawingState.frameNumber; |
| 1247 | const auto acquireFence = std::make_shared<FenceTime>(mDrawingState.acquireFence); |
| 1248 | mFlinger->mTimeStats->setAcquireFence(layerId, frameNumber, acquireFence); |
| 1249 | mFlinger->mTimeStats->setLatchTime(layerId, frameNumber, latchTime); |
| 1250 | |
| 1251 | mFlinger->mFrameTracer->traceFence(layerId, bufferId, frameNumber, acquireFence, |
| 1252 | FrameTracer::FrameEvent::ACQUIRE_FENCE); |
| 1253 | mFlinger->mFrameTracer->traceTimestamp(layerId, bufferId, frameNumber, latchTime, |
| 1254 | FrameTracer::FrameEvent::LATCH); |
| 1255 | |
| 1256 | auto& bufferSurfaceFrame = mDrawingState.bufferSurfaceFrameTX; |
| 1257 | if (bufferSurfaceFrame != nullptr && |
| 1258 | bufferSurfaceFrame->getPresentState() != PresentState::Presented) { |
| 1259 | // Update only if the bufferSurfaceFrame wasn't already presented. A Presented |
| 1260 | // bufferSurfaceFrame could be seen here if a pending state was applied successfully and we |
| 1261 | // are processing the next state. |
| 1262 | addSurfaceFramePresentedForBuffer(bufferSurfaceFrame, |
| 1263 | mDrawingState.acquireFenceTime->getSignalTime(), |
| 1264 | latchTime); |
| 1265 | mDrawingState.bufferSurfaceFrameTX.reset(); |
| 1266 | } |
| 1267 | |
| 1268 | std::deque<sp<CallbackHandle>> remainingHandles; |
| 1269 | mFlinger->getTransactionCallbackInvoker() |
| 1270 | .addOnCommitCallbackHandles(mDrawingState.callbackHandles, remainingHandles); |
| 1271 | mDrawingState.callbackHandles = remainingHandles; |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1272 | } |
| 1273 | |
| 1274 | void Layer::gatherBufferInfo() { |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 1275 | mPreviousReleaseCallbackId = {getCurrentBufferId(), mBufferInfo.mFrameNumber}; |
| 1276 | mPreviousReleaseBufferEndpoint = mBufferInfo.mReleaseBufferEndpoint; |
| 1277 | if (!mDrawingState.buffer) { |
| 1278 | mBufferInfo = {}; |
| 1279 | return; |
| 1280 | } |
| 1281 | |
| 1282 | if ((!mBufferInfo.mBuffer || !mDrawingState.buffer->hasSameBuffer(*mBufferInfo.mBuffer))) { |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1283 | decrementPendingBufferCount(); |
| 1284 | } |
| 1285 | |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1286 | mBufferInfo.mBuffer = mDrawingState.buffer; |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 1287 | mBufferInfo.mReleaseBufferEndpoint = mDrawingState.releaseBufferEndpoint; |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1288 | mBufferInfo.mFence = mDrawingState.acquireFence; |
| 1289 | mBufferInfo.mFrameNumber = mDrawingState.frameNumber; |
| 1290 | mBufferInfo.mPixelFormat = |
| 1291 | !mBufferInfo.mBuffer ? PIXEL_FORMAT_NONE : mBufferInfo.mBuffer->getPixelFormat(); |
| 1292 | mBufferInfo.mFrameLatencyNeeded = true; |
| 1293 | mBufferInfo.mDesiredPresentTime = mDrawingState.desiredPresentTime; |
| 1294 | mBufferInfo.mFenceTime = std::make_shared<FenceTime>(mDrawingState.acquireFence); |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1295 | mBufferInfo.mTransform = mDrawingState.bufferTransform; |
| 1296 | auto lastDataspace = mBufferInfo.mDataspace; |
| 1297 | mBufferInfo.mDataspace = translateDataspace(mDrawingState.dataspace); |
Alec Mouri | 74c7ae1 | 2023-03-26 02:57:47 +0000 | [diff] [blame] | 1298 | if (mBufferInfo.mBuffer != nullptr) { |
| 1299 | auto& mapper = GraphicBufferMapper::get(); |
| 1300 | // TODO: We should measure if it's faster to do a blind write if we're on newer api levels |
| 1301 | // and don't need to possibly remaps buffers. |
| 1302 | ui::Dataspace dataspace = ui::Dataspace::UNKNOWN; |
| 1303 | status_t err = OK; |
| 1304 | { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 1305 | SFTRACE_NAME("getDataspace"); |
Alec Mouri | 74c7ae1 | 2023-03-26 02:57:47 +0000 | [diff] [blame] | 1306 | err = mapper.getDataspace(mBufferInfo.mBuffer->getBuffer()->handle, &dataspace); |
| 1307 | } |
| 1308 | if (err != OK || dataspace != mBufferInfo.mDataspace) { |
| 1309 | { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 1310 | SFTRACE_NAME("setDataspace"); |
Alec Mouri | 74c7ae1 | 2023-03-26 02:57:47 +0000 | [diff] [blame] | 1311 | err = mapper.setDataspace(mBufferInfo.mBuffer->getBuffer()->handle, |
| 1312 | static_cast<ui::Dataspace>(mBufferInfo.mDataspace)); |
| 1313 | } |
| 1314 | |
| 1315 | // Some GPU drivers may cache gralloc metadata which means before we composite we need |
| 1316 | // to upsert RenderEngine's caches. Put in a special workaround to be backwards |
| 1317 | // compatible with old vendors, with a ticking clock. |
| 1318 | static const int32_t kVendorVersion = |
Alec Mouri | 8a06fb7 | 2023-11-16 22:07:13 +0000 | [diff] [blame] | 1319 | base::GetIntProperty("ro.board.api_level", __ANDROID_API_FUTURE__); |
Alec Mouri | 74c7ae1 | 2023-03-26 02:57:47 +0000 | [diff] [blame] | 1320 | if (const auto format = |
| 1321 | static_cast<aidl::android::hardware::graphics::common::PixelFormat>( |
| 1322 | mBufferInfo.mBuffer->getPixelFormat()); |
| 1323 | err == OK && kVendorVersion < __ANDROID_API_U__ && |
| 1324 | (format == |
| 1325 | aidl::android::hardware::graphics::common::PixelFormat:: |
| 1326 | IMPLEMENTATION_DEFINED || |
| 1327 | format == aidl::android::hardware::graphics::common::PixelFormat::YCBCR_420_888 || |
| 1328 | format == aidl::android::hardware::graphics::common::PixelFormat::YV12 || |
| 1329 | format == aidl::android::hardware::graphics::common::PixelFormat::YCBCR_P010)) { |
| 1330 | mBufferInfo.mBuffer->remapBuffer(); |
| 1331 | } |
| 1332 | } |
| 1333 | } |
Alec Mouri | d05a745 | 2024-09-20 13:44:02 +0000 | [diff] [blame^] | 1334 | if (lastDataspace != mBufferInfo.mDataspace || |
| 1335 | mBufferInfo.mTimeSinceDataspaceUpdate == std::chrono::steady_clock::time_point::min()) { |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 1336 | mFlinger->mHdrLayerInfoChanged = true; |
Alec Mouri | d05a745 | 2024-09-20 13:44:02 +0000 | [diff] [blame^] | 1337 | const auto currentTime = std::chrono::steady_clock::now(); |
| 1338 | if (mBufferInfo.mTimeSinceDataspaceUpdate > std::chrono::steady_clock::time_point::min()) { |
| 1339 | mFlinger->mLayerEvents |
| 1340 | .emplace_back(mOwnerUid, getSequence(), lastDataspace, |
| 1341 | std::chrono::duration_cast<std::chrono::milliseconds>( |
| 1342 | currentTime - mBufferInfo.mTimeSinceDataspaceUpdate)); |
| 1343 | } |
| 1344 | mBufferInfo.mTimeSinceDataspaceUpdate = currentTime; |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 1345 | } |
Sally Qi | 963049b | 2023-03-23 14:06:21 -0700 | [diff] [blame] | 1346 | if (mBufferInfo.mDesiredHdrSdrRatio != mDrawingState.desiredHdrSdrRatio) { |
| 1347 | mBufferInfo.mDesiredHdrSdrRatio = mDrawingState.desiredHdrSdrRatio; |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 1348 | mFlinger->mHdrLayerInfoChanged = true; |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1349 | } |
| 1350 | mBufferInfo.mCrop = computeBufferCrop(mDrawingState); |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1351 | mBufferInfo.mTransformToDisplayInverse = mDrawingState.transformToDisplayInverse; |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1352 | } |
| 1353 | |
| 1354 | Rect Layer::computeBufferCrop(const State& s) { |
| 1355 | if (s.buffer && !s.bufferCrop.isEmpty()) { |
| 1356 | Rect bufferCrop; |
| 1357 | s.buffer->getBounds().intersect(s.bufferCrop, &bufferCrop); |
| 1358 | return bufferCrop; |
| 1359 | } else if (s.buffer) { |
| 1360 | return s.buffer->getBounds(); |
| 1361 | } else { |
| 1362 | return s.bufferCrop; |
| 1363 | } |
| 1364 | } |
| 1365 | |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1366 | void Layer::decrementPendingBufferCount() { |
| 1367 | int32_t pendingBuffers = --mPendingBufferTransactions; |
| 1368 | tracePendingBufferCount(pendingBuffers); |
| 1369 | } |
| 1370 | |
| 1371 | void Layer::tracePendingBufferCount(int32_t pendingBuffers) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 1372 | SFTRACE_INT(mBlastTransactionName.c_str(), pendingBuffers); |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1373 | } |
| 1374 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 1375 | sp<LayerFE> Layer::getCompositionEngineLayerFE( |
| 1376 | const frontend::LayerHierarchy::TraversalPath& path) { |
| 1377 | for (auto& [p, layerFE] : mLayerFEs) { |
| 1378 | if (p == path) { |
| 1379 | return layerFE; |
| 1380 | } |
| 1381 | } |
Lloyd Pique | 70ddc67 | 2024-04-30 18:20:40 -0700 | [diff] [blame] | 1382 | auto layerFE = mFlinger->getFactory().createLayerFE(mName, this); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 1383 | mLayerFEs.emplace_back(path, layerFE); |
| 1384 | return layerFE; |
| 1385 | } |
| 1386 | |
Leon Scroggins III | 5b58149 | 2023-10-31 14:29:41 -0400 | [diff] [blame] | 1387 | void Layer::onCompositionPresented(const DisplayDevice* display, |
| 1388 | const std::shared_ptr<FenceTime>& glDoneFence, |
| 1389 | const std::shared_ptr<FenceTime>& presentFence, |
Vishnu Nair | 39a74a9 | 2024-07-29 19:01:50 +0000 | [diff] [blame] | 1390 | const CompositorTiming& compositorTiming, |
| 1391 | gui::GameMode gameMode) { |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1392 | // mFrameLatencyNeeded is true when a new frame was latched for the |
| 1393 | // composition. |
| 1394 | if (!mBufferInfo.mFrameLatencyNeeded) return; |
| 1395 | |
| 1396 | for (const auto& handle : mDrawingState.callbackHandles) { |
| 1397 | handle->gpuCompositionDoneFence = glDoneFence; |
| 1398 | handle->compositorTiming = compositorTiming; |
| 1399 | } |
| 1400 | |
| 1401 | // Update mFrameTracker. |
| 1402 | nsecs_t desiredPresentTime = mBufferInfo.mDesiredPresentTime; |
| 1403 | mFrameTracker.setDesiredPresentTime(desiredPresentTime); |
| 1404 | |
| 1405 | const int32_t layerId = getSequence(); |
| 1406 | mFlinger->mTimeStats->setDesiredTime(layerId, mCurrentFrameNumber, desiredPresentTime); |
| 1407 | |
| 1408 | const auto outputLayer = findOutputLayerForDisplay(display); |
| 1409 | if (outputLayer && outputLayer->requiresClientComposition()) { |
| 1410 | nsecs_t clientCompositionTimestamp = outputLayer->getState().clientCompositionTimestamp; |
| 1411 | mFlinger->mFrameTracer->traceTimestamp(layerId, getCurrentBufferId(), mCurrentFrameNumber, |
| 1412 | clientCompositionTimestamp, |
| 1413 | FrameTracer::FrameEvent::FALLBACK_COMPOSITION); |
| 1414 | // Update the SurfaceFrames in the drawing state |
| 1415 | if (mDrawingState.bufferSurfaceFrameTX) { |
| 1416 | mDrawingState.bufferSurfaceFrameTX->setGpuComposition(); |
| 1417 | } |
| 1418 | for (auto& [token, surfaceFrame] : mDrawingState.bufferlessSurfaceFramesTX) { |
| 1419 | surfaceFrame->setGpuComposition(); |
| 1420 | } |
| 1421 | } |
| 1422 | |
| 1423 | std::shared_ptr<FenceTime> frameReadyFence = mBufferInfo.mFenceTime; |
| 1424 | if (frameReadyFence->isValid()) { |
| 1425 | mFrameTracker.setFrameReadyFence(std::move(frameReadyFence)); |
| 1426 | } else { |
| 1427 | // There was no fence for this frame, so assume that it was ready |
| 1428 | // to be presented at the desired present time. |
| 1429 | mFrameTracker.setFrameReadyTime(desiredPresentTime); |
| 1430 | } |
| 1431 | |
| 1432 | if (display) { |
Dominik Laskowski | fe749dc | 2024-07-26 10:09:31 -0400 | [diff] [blame] | 1433 | const auto activeMode = display->refreshRateSelector().getActiveMode(); |
| 1434 | const Fps refreshRate = activeMode.fps; |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1435 | const std::optional<Fps> renderRate = |
| 1436 | mFlinger->mScheduler->getFrameRateOverride(getOwnerUid()); |
| 1437 | |
Alec Mouri | 7c1d8b5 | 2023-08-29 20:14:46 +0000 | [diff] [blame] | 1438 | const auto vote = frameRateToSetFrameRateVotePayload(getFrameRateForLayerTree()); |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1439 | |
| 1440 | if (presentFence->isValid()) { |
| 1441 | mFlinger->mTimeStats->setPresentFence(layerId, mCurrentFrameNumber, presentFence, |
| 1442 | refreshRate, renderRate, vote, gameMode); |
| 1443 | mFlinger->mFrameTracer->traceFence(layerId, getCurrentBufferId(), mCurrentFrameNumber, |
| 1444 | presentFence, |
| 1445 | FrameTracer::FrameEvent::PRESENT_FENCE); |
| 1446 | mFrameTracker.setActualPresentFence(std::shared_ptr<FenceTime>(presentFence)); |
| 1447 | } else if (const auto displayId = PhysicalDisplayId::tryCast(display->getId()); |
| 1448 | displayId && mFlinger->getHwComposer().isConnected(*displayId)) { |
Dominik Laskowski | dc2bb80 | 2022-09-28 16:02:59 -0400 | [diff] [blame] | 1449 | // The HWC doesn't support present fences, so use the present timestamp instead. |
| 1450 | const nsecs_t presentTimestamp = |
| 1451 | mFlinger->getHwComposer().getPresentTimestamp(*displayId); |
| 1452 | |
| 1453 | const nsecs_t now = systemTime(CLOCK_MONOTONIC); |
Dominik Laskowski | fe749dc | 2024-07-26 10:09:31 -0400 | [diff] [blame] | 1454 | const nsecs_t vsyncPeriod = |
| 1455 | mFlinger->getHwComposer() |
| 1456 | .getDisplayVsyncPeriod(*displayId) |
| 1457 | .value_opt() |
| 1458 | .value_or(activeMode.modePtr->getVsyncRate().getPeriodNsecs()); |
| 1459 | |
Dominik Laskowski | dc2bb80 | 2022-09-28 16:02:59 -0400 | [diff] [blame] | 1460 | const nsecs_t actualPresentTime = now - ((now - presentTimestamp) % vsyncPeriod); |
| 1461 | |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1462 | mFlinger->mTimeStats->setPresentTime(layerId, mCurrentFrameNumber, actualPresentTime, |
| 1463 | refreshRate, renderRate, vote, gameMode); |
| 1464 | mFlinger->mFrameTracer->traceTimestamp(layerId, getCurrentBufferId(), |
| 1465 | mCurrentFrameNumber, actualPresentTime, |
| 1466 | FrameTracer::FrameEvent::PRESENT_FENCE); |
| 1467 | mFrameTracker.setActualPresentTime(actualPresentTime); |
| 1468 | } |
| 1469 | } |
| 1470 | |
| 1471 | mFrameTracker.advanceFrame(); |
| 1472 | mBufferInfo.mFrameLatencyNeeded = false; |
| 1473 | } |
| 1474 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 1475 | bool Layer::latchBufferImpl(bool& recomputeVisibleRegions, nsecs_t latchTime, bool bgColorOnly) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 1476 | SFTRACE_FORMAT_INSTANT("latchBuffer %s - %" PRIu64, getDebugName(), |
| 1477 | getDrawingState().frameNumber); |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1478 | |
| 1479 | bool refreshRequired = latchSidebandStream(recomputeVisibleRegions); |
| 1480 | |
| 1481 | if (refreshRequired) { |
| 1482 | return refreshRequired; |
| 1483 | } |
| 1484 | |
| 1485 | // If the head buffer's acquire fence hasn't signaled yet, return and |
| 1486 | // try again later |
| 1487 | if (!fenceHasSignaled()) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 1488 | SFTRACE_NAME("!fenceHasSignaled()"); |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1489 | mFlinger->onLayerUpdate(); |
| 1490 | return false; |
| 1491 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 1492 | updateTexImage(latchTime, bgColorOnly); |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1493 | |
| 1494 | // Capture the old state of the layer for comparisons later |
| 1495 | BufferInfo oldBufferInfo = mBufferInfo; |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1496 | mPreviousFrameNumber = mCurrentFrameNumber; |
| 1497 | mCurrentFrameNumber = mDrawingState.frameNumber; |
| 1498 | gatherBufferInfo(); |
| 1499 | |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 1500 | if (mBufferInfo.mBuffer) { |
| 1501 | // We latched a buffer that will be presented soon. Clear the previously presented layer |
| 1502 | // stack list. |
| 1503 | mPreviouslyPresentedLayerStacks.clear(); |
| 1504 | } |
| 1505 | |
| 1506 | if (mDrawingState.buffer == nullptr) { |
| 1507 | const bool bufferReleased = oldBufferInfo.mBuffer != nullptr; |
| 1508 | recomputeVisibleRegions = bufferReleased; |
| 1509 | return bufferReleased; |
| 1510 | } |
| 1511 | |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1512 | if (oldBufferInfo.mBuffer == nullptr) { |
| 1513 | // the first time we receive a buffer, we need to trigger a |
| 1514 | // geometry invalidation. |
| 1515 | recomputeVisibleRegions = true; |
| 1516 | } |
| 1517 | |
| 1518 | if ((mBufferInfo.mCrop != oldBufferInfo.mCrop) || |
| 1519 | (mBufferInfo.mTransform != oldBufferInfo.mTransform) || |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1520 | (mBufferInfo.mTransformToDisplayInverse != oldBufferInfo.mTransformToDisplayInverse)) { |
| 1521 | recomputeVisibleRegions = true; |
| 1522 | } |
| 1523 | |
| 1524 | if (oldBufferInfo.mBuffer != nullptr) { |
| 1525 | uint32_t bufWidth = mBufferInfo.mBuffer->getWidth(); |
| 1526 | uint32_t bufHeight = mBufferInfo.mBuffer->getHeight(); |
| 1527 | if (bufWidth != oldBufferInfo.mBuffer->getWidth() || |
| 1528 | bufHeight != oldBufferInfo.mBuffer->getHeight()) { |
| 1529 | recomputeVisibleRegions = true; |
| 1530 | } |
| 1531 | } |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1532 | return true; |
| 1533 | } |
| 1534 | |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1535 | bool Layer::getTransformToDisplayInverse() const { |
| 1536 | return mBufferInfo.mTransformToDisplayInverse; |
| 1537 | } |
| 1538 | |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1539 | ui::Dataspace Layer::translateDataspace(ui::Dataspace dataspace) { |
| 1540 | ui::Dataspace updatedDataspace = dataspace; |
| 1541 | // translate legacy dataspaces to modern dataspaces |
| 1542 | switch (dataspace) { |
Alec Mouri | 74c7ae1 | 2023-03-26 02:57:47 +0000 | [diff] [blame] | 1543 | // Treat unknown dataspaces as V0_sRGB |
| 1544 | case ui::Dataspace::UNKNOWN: |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1545 | case ui::Dataspace::SRGB: |
| 1546 | updatedDataspace = ui::Dataspace::V0_SRGB; |
| 1547 | break; |
| 1548 | case ui::Dataspace::SRGB_LINEAR: |
| 1549 | updatedDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
| 1550 | break; |
| 1551 | case ui::Dataspace::JFIF: |
| 1552 | updatedDataspace = ui::Dataspace::V0_JFIF; |
| 1553 | break; |
| 1554 | case ui::Dataspace::BT601_625: |
| 1555 | updatedDataspace = ui::Dataspace::V0_BT601_625; |
| 1556 | break; |
| 1557 | case ui::Dataspace::BT601_525: |
| 1558 | updatedDataspace = ui::Dataspace::V0_BT601_525; |
| 1559 | break; |
| 1560 | case ui::Dataspace::BT709: |
| 1561 | updatedDataspace = ui::Dataspace::V0_BT709; |
| 1562 | break; |
| 1563 | default: |
| 1564 | break; |
| 1565 | } |
| 1566 | |
| 1567 | return updatedDataspace; |
| 1568 | } |
| 1569 | |
| 1570 | sp<GraphicBuffer> Layer::getBuffer() const { |
| 1571 | return mBufferInfo.mBuffer ? mBufferInfo.mBuffer->getBuffer() : nullptr; |
| 1572 | } |
| 1573 | |
Chavi Weingarten | 328a831 | 2023-01-26 21:17:52 +0000 | [diff] [blame] | 1574 | bool Layer::setTrustedPresentationInfo(TrustedPresentationThresholds const& thresholds, |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 1575 | TrustedPresentationListener const& listener) { |
| 1576 | bool hadTrustedPresentationListener = hasTrustedPresentationListener(); |
| 1577 | mTrustedPresentationListener = listener; |
| 1578 | mTrustedPresentationThresholds = thresholds; |
| 1579 | bool haveTrustedPresentationListener = hasTrustedPresentationListener(); |
| 1580 | if (!hadTrustedPresentationListener && haveTrustedPresentationListener) { |
| 1581 | mFlinger->mNumTrustedPresentationListeners++; |
| 1582 | } else if (hadTrustedPresentationListener && !haveTrustedPresentationListener) { |
| 1583 | mFlinger->mNumTrustedPresentationListeners--; |
| 1584 | } |
Chavi Weingarten | 328a831 | 2023-01-26 21:17:52 +0000 | [diff] [blame] | 1585 | |
| 1586 | // Reset trusted presentation states to ensure we start the time again. |
| 1587 | mEnteredTrustedPresentationStateTime = -1; |
| 1588 | mLastReportedTrustedPresentationState = false; |
| 1589 | mLastComputedTrustedPresentationState = false; |
| 1590 | |
| 1591 | // If there's a new trusted presentation listener, the code needs to go through the composite |
| 1592 | // path to ensure it recomutes the current state and invokes the TrustedPresentationListener if |
| 1593 | // we're already in the requested state. |
| 1594 | return haveTrustedPresentationListener; |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 1595 | } |
| 1596 | |
Patrick Williams | 7c9fa27 | 2024-08-30 12:38:43 +0000 | [diff] [blame] | 1597 | void Layer::setBufferReleaseChannel( |
| 1598 | const std::shared_ptr<gui::BufferReleaseChannel::ProducerEndpoint>& channel) { |
| 1599 | mBufferReleaseChannel = channel; |
| 1600 | } |
| 1601 | |
Vishnu Nair | a156f48 | 2023-02-22 00:23:38 +0000 | [diff] [blame] | 1602 | void Layer::updateLastLatchTime(nsecs_t latchTime) { |
| 1603 | mLastLatchTime = latchTime; |
| 1604 | } |
| 1605 | |
Vishnu Nair | dc83d4b | 2024-08-15 16:29:20 +0000 | [diff] [blame] | 1606 | void Layer::setIsSmallDirty(frontend::LayerSnapshot* snapshot) { |
Jerry Chang | 3667800 | 2023-11-29 16:56:17 +0000 | [diff] [blame] | 1607 | if (!mFlinger->mScheduler->supportSmallDirtyDetection(mOwnerAppId)) { |
Vishnu Nair | dc83d4b | 2024-08-15 16:29:20 +0000 | [diff] [blame] | 1608 | snapshot->isSmallDirty = false; |
Arthur Hung | c70bee2 | 2023-06-02 01:35:52 +0000 | [diff] [blame] | 1609 | return; |
| 1610 | } |
| 1611 | |
| 1612 | if (mWindowType != WindowInfo::Type::APPLICATION && |
| 1613 | mWindowType != WindowInfo::Type::BASE_APPLICATION) { |
Vishnu Nair | dc83d4b | 2024-08-15 16:29:20 +0000 | [diff] [blame] | 1614 | snapshot->isSmallDirty = false; |
Arthur Hung | c70bee2 | 2023-06-02 01:35:52 +0000 | [diff] [blame] | 1615 | return; |
| 1616 | } |
Arthur Hung | 69f9522 | 2023-10-04 07:39:02 +0000 | [diff] [blame] | 1617 | |
Vishnu Nair | dc83d4b | 2024-08-15 16:29:20 +0000 | [diff] [blame] | 1618 | Rect bounds = snapshot->surfaceDamage.getBounds(); |
Arthur Hung | c70bee2 | 2023-06-02 01:35:52 +0000 | [diff] [blame] | 1619 | if (!bounds.isValid()) { |
Vishnu Nair | dc83d4b | 2024-08-15 16:29:20 +0000 | [diff] [blame] | 1620 | snapshot->isSmallDirty = false; |
Arthur Hung | c70bee2 | 2023-06-02 01:35:52 +0000 | [diff] [blame] | 1621 | return; |
| 1622 | } |
| 1623 | |
Arthur Hung | 69f9522 | 2023-10-04 07:39:02 +0000 | [diff] [blame] | 1624 | // Transform to screen space. |
Vishnu Nair | dc83d4b | 2024-08-15 16:29:20 +0000 | [diff] [blame] | 1625 | bounds = snapshot->localTransform.transform(bounds); |
Arthur Hung | 69f9522 | 2023-10-04 07:39:02 +0000 | [diff] [blame] | 1626 | |
Arthur Hung | c70bee2 | 2023-06-02 01:35:52 +0000 | [diff] [blame] | 1627 | // If the damage region is a small dirty, this could give the hint for the layer history that |
| 1628 | // it could suppress the heuristic rate when calculating. |
Vishnu Nair | dc83d4b | 2024-08-15 16:29:20 +0000 | [diff] [blame] | 1629 | snapshot->isSmallDirty = |
| 1630 | mFlinger->mScheduler->isSmallDirtyArea(mOwnerAppId, |
| 1631 | bounds.getWidth() * bounds.getHeight()); |
Arthur Hung | 69f9522 | 2023-10-04 07:39:02 +0000 | [diff] [blame] | 1632 | } |
| 1633 | |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 1634 | } // namespace android |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 1635 | |
| 1636 | #if defined(__gl_h_) |
| 1637 | #error "don't include gl/gl.h in this file" |
| 1638 | #endif |
| 1639 | |
| 1640 | #if defined(__gl2_h_) |
| 1641 | #error "don't include gl2/gl2.h in this file" |
| 1642 | #endif |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 1643 | |
| 1644 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 1645 | #pragma clang diagnostic pop // ignored "-Wconversion" |