Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | //#define LOG_NDEBUG 0 |
| 18 | #undef LOG_TAG |
| 19 | #define LOG_TAG "BufferStateLayer" |
| 20 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
| 21 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 22 | #include "BufferStateLayer.h" |
| 23 | |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 24 | #include <limits> |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 25 | |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 26 | #include <FrameTimeline/FrameTimeline.h> |
Vishnu Nair | a72f6c0 | 2022-07-01 05:33:08 +0000 | [diff] [blame] | 27 | #include <compositionengine/CompositionEngine.h> |
Marissa Wall | 947d34e | 2019-03-29 14:03:53 -0700 | [diff] [blame] | 28 | #include <gui/BufferQueue.h> |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 29 | #include <private/gui/SyncFeatures.h> |
Peiyong Lin | cbc184f | 2018-08-22 13:24:10 -0700 | [diff] [blame] | 30 | #include <renderengine/Image.h> |
Robert Carr | 38d2500 | 2021-06-11 14:30:09 -0700 | [diff] [blame] | 31 | #include "TunnelModeEnabledReporter.h" |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 32 | |
Chavi Weingarten | d00e0f7 | 2022-07-14 15:59:20 +0000 | [diff] [blame] | 33 | #include <gui/TraceUtils.h> |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame] | 34 | #include "EffectLayer.h" |
Adithya Srinivasan | b238cd5 | 2021-02-04 17:54:05 +0000 | [diff] [blame] | 35 | #include "FrameTracer/FrameTracer.h" |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 36 | #include "TimeStats/TimeStats.h" |
Valerie Hau | 0bc0915 | 2018-12-20 07:42:47 -0800 | [diff] [blame] | 37 | |
Robert Carr | b645049 | 2022-06-23 11:17:16 -0700 | [diff] [blame] | 38 | #define EARLY_RELEASE_ENABLED false |
| 39 | |
Vishnu Nair | a72f6c0 | 2022-07-01 05:33:08 +0000 | [diff] [blame] | 40 | #include <compositionengine/LayerFECompositionState.h> |
| 41 | #include <compositionengine/OutputLayer.h> |
| 42 | #include <compositionengine/impl/OutputLayerCompositionState.h> |
| 43 | #include <cutils/compiler.h> |
| 44 | #include <cutils/native_handle.h> |
| 45 | #include <cutils/properties.h> |
| 46 | #include <gui/BufferItem.h> |
| 47 | #include <gui/BufferQueue.h> |
| 48 | #include <gui/GLConsumer.h> |
| 49 | #include <gui/LayerDebugInfo.h> |
| 50 | #include <gui/Surface.h> |
| 51 | #include <renderengine/RenderEngine.h> |
| 52 | #include <ui/DebugUtils.h> |
| 53 | #include <utils/Errors.h> |
| 54 | #include <utils/Log.h> |
| 55 | #include <utils/NativeHandle.h> |
| 56 | #include <utils/StopWatch.h> |
| 57 | #include <utils/Trace.h> |
| 58 | |
| 59 | #include <cmath> |
| 60 | #include <cstdlib> |
| 61 | #include <mutex> |
| 62 | #include <sstream> |
| 63 | |
| 64 | #include "Colorizer.h" |
| 65 | #include "DisplayDevice.h" |
| 66 | #include "FrameTracer/FrameTracer.h" |
| 67 | #include "TimeStats/TimeStats.h" |
| 68 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 69 | namespace android { |
| 70 | |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 71 | using PresentState = frametimeline::SurfaceFrame::PresentState; |
Vishnu Nair | a72f6c0 | 2022-07-01 05:33:08 +0000 | [diff] [blame] | 72 | using gui::WindowInfo; |
Vishnu Nair | a72f6c0 | 2022-07-01 05:33:08 +0000 | [diff] [blame] | 73 | namespace { |
| 74 | static constexpr float defaultMaxLuminance = 1000.0; |
Vishnu Nair | 397a0e3 | 2022-07-26 00:01:48 +0000 | [diff] [blame] | 75 | |
| 76 | constexpr mat4 inverseOrientation(uint32_t transform) { |
| 77 | const mat4 flipH(-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1); |
| 78 | const mat4 flipV(1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1); |
| 79 | const mat4 rot90(0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1); |
| 80 | mat4 tr; |
| 81 | |
| 82 | if (transform & NATIVE_WINDOW_TRANSFORM_ROT_90) { |
| 83 | tr = tr * rot90; |
| 84 | } |
| 85 | if (transform & NATIVE_WINDOW_TRANSFORM_FLIP_H) { |
| 86 | tr = tr * flipH; |
| 87 | } |
| 88 | if (transform & NATIVE_WINDOW_TRANSFORM_FLIP_V) { |
| 89 | tr = tr * flipV; |
| 90 | } |
| 91 | return inverse(tr); |
| 92 | } |
| 93 | |
| 94 | bool assignTransform(ui::Transform* dst, ui::Transform& from) { |
| 95 | if (*dst == from) { |
| 96 | return false; |
| 97 | } |
| 98 | *dst = from; |
| 99 | return true; |
| 100 | } |
| 101 | |
| 102 | TimeStats::SetFrameRateVote frameRateToSetFrameRateVotePayload(Layer::FrameRate frameRate) { |
| 103 | using FrameRateCompatibility = TimeStats::SetFrameRateVote::FrameRateCompatibility; |
| 104 | using Seamlessness = TimeStats::SetFrameRateVote::Seamlessness; |
| 105 | const auto frameRateCompatibility = [frameRate] { |
| 106 | switch (frameRate.type) { |
| 107 | case Layer::FrameRateCompatibility::Default: |
| 108 | return FrameRateCompatibility::Default; |
| 109 | case Layer::FrameRateCompatibility::ExactOrMultiple: |
| 110 | return FrameRateCompatibility::ExactOrMultiple; |
| 111 | default: |
| 112 | return FrameRateCompatibility::Undefined; |
| 113 | } |
| 114 | }(); |
| 115 | |
| 116 | const auto seamlessness = [frameRate] { |
| 117 | switch (frameRate.seamlessness) { |
| 118 | case scheduler::Seamlessness::OnlySeamless: |
| 119 | return Seamlessness::ShouldBeSeamless; |
| 120 | case scheduler::Seamlessness::SeamedAndSeamless: |
| 121 | return Seamlessness::NotRequired; |
| 122 | default: |
| 123 | return Seamlessness::Undefined; |
| 124 | } |
| 125 | }(); |
| 126 | |
| 127 | return TimeStats::SetFrameRateVote{.frameRate = frameRate.rate.getValue(), |
| 128 | .frameRateCompatibility = frameRateCompatibility, |
| 129 | .seamlessness = seamlessness}; |
| 130 | } |
Vishnu Nair | a72f6c0 | 2022-07-01 05:33:08 +0000 | [diff] [blame] | 131 | } // namespace |
| 132 | |
Marissa Wall | 947d34e | 2019-03-29 14:03:53 -0700 | [diff] [blame] | 133 | BufferStateLayer::BufferStateLayer(const LayerCreationArgs& args) |
Vishnu Nair | a72f6c0 | 2022-07-01 05:33:08 +0000 | [diff] [blame] | 134 | : Layer(args), |
| 135 | mTextureName(args.textureName), |
| 136 | mCompositionState{mFlinger->getCompositionEngine().createLayerFECompositionState()}, |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 137 | mHwcSlotGenerator(sp<HwcSlotGenerator>::make()) { |
Vishnu Nair | a72f6c0 | 2022-07-01 05:33:08 +0000 | [diff] [blame] | 138 | ALOGV("Creating Layer %s", getDebugName()); |
| 139 | |
| 140 | mPremultipliedAlpha = !(args.flags & ISurfaceComposerClient::eNonPremultiplied); |
Vishnu Nair | a72f6c0 | 2022-07-01 05:33:08 +0000 | [diff] [blame] | 141 | mPotentialCursor = args.flags & ISurfaceComposerClient::eCursorWindow; |
| 142 | mProtectedByApp = args.flags & ISurfaceComposerClient::eProtectedByApp; |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 143 | mDrawingState.dataspace = ui::Dataspace::V0_SRGB; |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 144 | } |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 145 | |
Alec Mouri | 4545a8a | 2019-08-08 20:05:32 -0700 | [diff] [blame] | 146 | BufferStateLayer::~BufferStateLayer() { |
chaviw | b4c6e58 | 2019-08-16 14:35:07 -0700 | [diff] [blame] | 147 | // The original layer and the clone layer share the same texture and buffer. Therefore, only |
| 148 | // one of the layers, in this case the original layer, needs to handle the deletion. The |
| 149 | // original layer and the clone should be removed at the same time so there shouldn't be any |
| 150 | // issue with the clone layer trying to use the texture. |
Vishnu Nair | 3bb11d0 | 2021-11-26 09:24:11 -0800 | [diff] [blame] | 151 | if (mBufferInfo.mBuffer != nullptr) { |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 152 | callReleaseBufferCallback(mDrawingState.releaseBufferListener, |
Vishnu Nair | 4ba0c2e | 2021-06-24 11:27:17 -0700 | [diff] [blame] | 153 | mBufferInfo.mBuffer->getBuffer(), mBufferInfo.mFrameNumber, |
chaviw | 69058fb | 2021-09-27 09:37:30 -0500 | [diff] [blame] | 154 | mBufferInfo.mFence, |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 155 | mFlinger->getMaxAcquiredBufferCountForCurrentRefreshRate( |
| 156 | mOwnerUid)); |
Alec Mouri | 4545a8a | 2019-08-08 20:05:32 -0700 | [diff] [blame] | 157 | } |
Vishnu Nair | a72f6c0 | 2022-07-01 05:33:08 +0000 | [diff] [blame] | 158 | if (!isClone()) { |
| 159 | // The original layer and the clone layer share the same texture. Therefore, only one of |
| 160 | // the layers, in this case the original layer, needs to handle the deletion. The original |
| 161 | // layer and the clone should be removed at the same time so there shouldn't be any issue |
| 162 | // with the clone layer trying to use the deleted texture. |
| 163 | mFlinger->deleteTextureAsync(mTextureName); |
| 164 | } |
| 165 | const int32_t layerId = getSequence(); |
| 166 | mFlinger->mTimeStats->onDestroy(layerId); |
| 167 | mFlinger->mFrameTracer->onDestroy(layerId); |
Alec Mouri | 4545a8a | 2019-08-08 20:05:32 -0700 | [diff] [blame] | 168 | } |
| 169 | |
Vishnu Nair | 397a0e3 | 2022-07-26 00:01:48 +0000 | [diff] [blame] | 170 | void BufferStateLayer::callReleaseBufferCallback(const sp<ITransactionCompletedListener>& listener, |
| 171 | const sp<GraphicBuffer>& buffer, |
| 172 | uint64_t framenumber, |
| 173 | const sp<Fence>& releaseFence, |
| 174 | uint32_t currentMaxAcquiredBufferCount) { |
| 175 | if (!listener) { |
| 176 | return; |
| 177 | } |
| 178 | ATRACE_FORMAT_INSTANT("callReleaseBufferCallback %s - %" PRIu64, getDebugName(), framenumber); |
| 179 | listener->onReleaseBuffer({buffer->getId(), framenumber}, |
| 180 | releaseFence ? releaseFence : Fence::NO_FENCE, |
| 181 | currentMaxAcquiredBufferCount); |
| 182 | } |
| 183 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 184 | // ----------------------------------------------------------------------- |
| 185 | // Interface implementation for Layer |
| 186 | // ----------------------------------------------------------------------- |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 187 | void BufferStateLayer::onLayerDisplayed(ftl::SharedFuture<FenceResult> futureFenceResult) { |
Robert Carr | c2f8413 | 2022-03-09 16:26:43 -0800 | [diff] [blame] | 188 | // If we are displayed on multiple displays in a single composition cycle then we would |
| 189 | // need to do careful tracking to enable the use of the mLastClientCompositionFence. |
| 190 | // For example we can only use it if all the displays are client comp, and we need |
| 191 | // to merge all the client comp fences. We could do this, but for now we just |
| 192 | // disable the optimization when a layer is composed on multiple displays. |
Robert Carr | 05da008 | 2022-05-25 23:29:34 -0700 | [diff] [blame] | 193 | if (mClearClientCompositionFenceOnLayerDisplayed) { |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 194 | mLastClientCompositionFence = nullptr; |
Robert Carr | c2f8413 | 2022-03-09 16:26:43 -0800 | [diff] [blame] | 195 | } else { |
Robert Carr | 05da008 | 2022-05-25 23:29:34 -0700 | [diff] [blame] | 196 | mClearClientCompositionFenceOnLayerDisplayed = true; |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 197 | } |
| 198 | |
Marissa Wall | 5a68a77 | 2018-12-22 17:43:42 -0800 | [diff] [blame] | 199 | // The previous release fence notifies the client that SurfaceFlinger is done with the previous |
| 200 | // buffer that was presented on this layer. The first transaction that came in this frame that |
| 201 | // replaced the previous buffer on this layer needs this release fence, because the fence will |
| 202 | // let the client know when that previous buffer is removed from the screen. |
| 203 | // |
| 204 | // Every other transaction on this layer does not need a release fence because no other |
| 205 | // Transactions that were set on this layer this frame are going to have their preceeding buffer |
| 206 | // removed from the display this frame. |
| 207 | // |
| 208 | // For example, if we have 3 transactions this frame. The first transaction doesn't contain a |
| 209 | // buffer so it doesn't need a previous release fence because the layer still needs the previous |
| 210 | // buffer. The second transaction contains a buffer so it needs a previous release fence because |
| 211 | // the previous buffer will be released this frame. The third transaction also contains a |
| 212 | // buffer. It replaces the buffer in the second transaction. The buffer in the second |
| 213 | // transaction will now no longer be presented so it is released immediately and the third |
| 214 | // transaction doesn't need a previous release fence. |
Robert Carr | 8d95853 | 2020-11-10 14:09:16 -0800 | [diff] [blame] | 215 | sp<CallbackHandle> ch; |
Marissa Wall | 5a68a77 | 2018-12-22 17:43:42 -0800 | [diff] [blame] | 216 | for (auto& handle : mDrawingState.callbackHandles) { |
chaviw | 0b06a8d | 2021-08-06 11:49:08 -0500 | [diff] [blame] | 217 | if (handle->releasePreviousBuffer && |
| 218 | mDrawingState.releaseBufferEndpoint == handle->listener) { |
Robert Carr | 8d95853 | 2020-11-10 14:09:16 -0800 | [diff] [blame] | 219 | ch = handle; |
Marissa Wall | 5a68a77 | 2018-12-22 17:43:42 -0800 | [diff] [blame] | 220 | break; |
| 221 | } |
| 222 | } |
Valerie Hau | bf78464 | 2020-01-29 07:25:23 -0800 | [diff] [blame] | 223 | |
Mikael Pessa | 2e1608f | 2019-07-19 11:25:35 -0700 | [diff] [blame] | 224 | // Prevent tracing the same release multiple times. |
| 225 | if (mPreviousFrameNumber != mPreviousReleasedFrameNumber) { |
Mikael Pessa | 2e1608f | 2019-07-19 11:25:35 -0700 | [diff] [blame] | 226 | mPreviousReleasedFrameNumber = mPreviousFrameNumber; |
| 227 | } |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 228 | |
| 229 | if (ch != nullptr) { |
| 230 | ch->previousReleaseCallbackId = mPreviousReleaseCallbackId; |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 231 | ch->previousReleaseFences.emplace_back(std::move(futureFenceResult)); |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 232 | ch->name = mName; |
| 233 | } |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 234 | } |
| 235 | |
Jorim Jaggi | 9c03b50 | 2020-11-24 23:51:31 +0100 | [diff] [blame] | 236 | void BufferStateLayer::onSurfaceFrameCreated( |
| 237 | const std::shared_ptr<frametimeline::SurfaceFrame>& surfaceFrame) { |
Adithya Srinivasan | d17c7da | 2021-03-05 20:43:32 +0000 | [diff] [blame] | 238 | while (mPendingJankClassifications.size() >= kPendingClassificationMaxSurfaceFrames) { |
| 239 | // Too many SurfaceFrames pending classification. The front of the deque is probably not |
| 240 | // tracked by FrameTimeline and will never be presented. This will only result in a memory |
| 241 | // leak. |
| 242 | ALOGW("Removing the front of pending jank deque from layer - %s to prevent memory leak", |
| 243 | mName.c_str()); |
Adithya Srinivasan | 785addd | 2021-03-09 00:38:00 +0000 | [diff] [blame] | 244 | std::string miniDump = mPendingJankClassifications.front()->miniDump(); |
| 245 | ALOGD("Head SurfaceFrame mini dump\n%s", miniDump.c_str()); |
Adithya Srinivasan | d17c7da | 2021-03-05 20:43:32 +0000 | [diff] [blame] | 246 | mPendingJankClassifications.pop_front(); |
| 247 | } |
Jorim Jaggi | 9c03b50 | 2020-11-24 23:51:31 +0100 | [diff] [blame] | 248 | mPendingJankClassifications.emplace_back(surfaceFrame); |
| 249 | } |
| 250 | |
Valerie Hau | bf78464 | 2020-01-29 07:25:23 -0800 | [diff] [blame] | 251 | void BufferStateLayer::releasePendingBuffer(nsecs_t dequeueReadyTime) { |
Valerie Hau | 32cdc1f | 2019-10-21 14:45:54 -0700 | [diff] [blame] | 252 | for (const auto& handle : mDrawingState.callbackHandles) { |
| 253 | handle->transformHint = mTransformHint; |
Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 254 | handle->dequeueReadyTime = dequeueReadyTime; |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 255 | handle->currentMaxAcquiredBufferCount = |
| 256 | mFlinger->getMaxAcquiredBufferCountForCurrentRefreshRate(mOwnerUid); |
Chavi Weingarten | d00e0f7 | 2022-07-14 15:59:20 +0000 | [diff] [blame] | 257 | ATRACE_FORMAT_INSTANT("releasePendingBuffer %s - %" PRIu64, getDebugName(), |
| 258 | handle->previousReleaseCallbackId.framenumber); |
Valerie Hau | 32cdc1f | 2019-10-21 14:45:54 -0700 | [diff] [blame] | 259 | } |
| 260 | |
Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 261 | for (auto& handle : mDrawingState.callbackHandles) { |
chaviw | 0b06a8d | 2021-08-06 11:49:08 -0500 | [diff] [blame] | 262 | if (handle->releasePreviousBuffer && |
| 263 | mDrawingState.releaseBufferEndpoint == handle->listener) { |
Vishnu Nair | 4ba0c2e | 2021-06-24 11:27:17 -0700 | [diff] [blame] | 264 | handle->previousReleaseCallbackId = mPreviousReleaseCallbackId; |
Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 265 | break; |
| 266 | } |
| 267 | } |
| 268 | |
Jorim Jaggi | 9c03b50 | 2020-11-24 23:51:31 +0100 | [diff] [blame] | 269 | std::vector<JankData> jankData; |
| 270 | jankData.reserve(mPendingJankClassifications.size()); |
| 271 | while (!mPendingJankClassifications.empty() |
| 272 | && mPendingJankClassifications.front()->getJankType()) { |
| 273 | std::shared_ptr<frametimeline::SurfaceFrame> surfaceFrame = |
| 274 | mPendingJankClassifications.front(); |
| 275 | mPendingJankClassifications.pop_front(); |
| 276 | jankData.emplace_back( |
| 277 | JankData(surfaceFrame->getToken(), surfaceFrame->getJankType().value())); |
| 278 | } |
| 279 | |
Robert Carr | 3d1047b | 2021-09-20 18:22:32 -0700 | [diff] [blame] | 280 | mFlinger->getTransactionCallbackInvoker().addCallbackHandles( |
Jorim Jaggi | 9c03b50 | 2020-11-24 23:51:31 +0100 | [diff] [blame] | 281 | mDrawingState.callbackHandles, jankData); |
Marissa Wall | 5a68a77 | 2018-12-22 17:43:42 -0800 | [diff] [blame] | 282 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 283 | sp<Fence> releaseFence = Fence::NO_FENCE; |
| 284 | for (auto& handle : mDrawingState.callbackHandles) { |
| 285 | if (handle->releasePreviousBuffer && |
| 286 | mDrawingState.releaseBufferEndpoint == handle->listener) { |
| 287 | releaseFence = |
| 288 | handle->previousReleaseFence ? handle->previousReleaseFence : Fence::NO_FENCE; |
| 289 | break; |
| 290 | } |
| 291 | } |
| 292 | |
Marissa Wall | 5a68a77 | 2018-12-22 17:43:42 -0800 | [diff] [blame] | 293 | mDrawingState.callbackHandles = {}; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 294 | } |
| 295 | |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 296 | bool BufferStateLayer::willPresentCurrentTransaction() const { |
| 297 | // Returns true if the most recent Transaction applied to CurrentState will be presented. |
Robert Carr | 321e83c | 2019-08-19 15:49:30 -0700 | [diff] [blame] | 298 | return (getSidebandStreamChanged() || getAutoRefresh() || |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 299 | (mDrawingState.modified && |
| 300 | (mDrawingState.buffer != nullptr || mDrawingState.bgColorLayer != nullptr))); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 301 | } |
| 302 | |
Chavi Weingarten | a5aedbd | 2021-04-09 13:37:33 +0000 | [diff] [blame] | 303 | Rect BufferStateLayer::getCrop(const Layer::State& s) const { |
| 304 | return s.crop; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | bool BufferStateLayer::setTransform(uint32_t transform) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 308 | if (mDrawingState.bufferTransform == transform) return false; |
| 309 | mDrawingState.bufferTransform = transform; |
| 310 | mDrawingState.modified = true; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 311 | setTransactionFlags(eTransactionNeeded); |
| 312 | return true; |
| 313 | } |
| 314 | |
| 315 | bool BufferStateLayer::setTransformToDisplayInverse(bool transformToDisplayInverse) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 316 | if (mDrawingState.transformToDisplayInverse == transformToDisplayInverse) return false; |
| 317 | mDrawingState.sequence++; |
| 318 | mDrawingState.transformToDisplayInverse = transformToDisplayInverse; |
| 319 | mDrawingState.modified = true; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 320 | setTransactionFlags(eTransactionNeeded); |
| 321 | return true; |
| 322 | } |
| 323 | |
| 324 | bool BufferStateLayer::setCrop(const Rect& crop) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 325 | if (mDrawingState.crop == crop) return false; |
| 326 | mDrawingState.sequence++; |
| 327 | mDrawingState.crop = crop; |
Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 328 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 329 | mDrawingState.modified = true; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 330 | setTransactionFlags(eTransactionNeeded); |
| 331 | return true; |
| 332 | } |
| 333 | |
chaviw | f3f40fe | 2021-04-27 15:54:02 -0500 | [diff] [blame] | 334 | bool BufferStateLayer::setBufferCrop(const Rect& bufferCrop) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 335 | if (mDrawingState.bufferCrop == bufferCrop) return false; |
chaviw | f3f40fe | 2021-04-27 15:54:02 -0500 | [diff] [blame] | 336 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 337 | mDrawingState.sequence++; |
| 338 | mDrawingState.bufferCrop = bufferCrop; |
chaviw | f3f40fe | 2021-04-27 15:54:02 -0500 | [diff] [blame] | 339 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 340 | mDrawingState.modified = true; |
chaviw | f3f40fe | 2021-04-27 15:54:02 -0500 | [diff] [blame] | 341 | setTransactionFlags(eTransactionNeeded); |
| 342 | return true; |
| 343 | } |
| 344 | |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 345 | bool BufferStateLayer::setDestinationFrame(const Rect& destinationFrame) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 346 | if (mDrawingState.destinationFrame == destinationFrame) return false; |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 347 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 348 | mDrawingState.sequence++; |
| 349 | mDrawingState.destinationFrame = destinationFrame; |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 350 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 351 | mDrawingState.modified = true; |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 352 | setTransactionFlags(eTransactionNeeded); |
| 353 | return true; |
| 354 | } |
| 355 | |
| 356 | // Translate destination frame into scale and position. If a destination frame is not set, use the |
| 357 | // provided scale and position |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 358 | bool BufferStateLayer::updateGeometry() { |
Vishnu Nair | d2aaab1 | 2022-02-10 14:49:09 -0800 | [diff] [blame] | 359 | if ((mDrawingState.flags & layer_state_t::eIgnoreDestinationFrame) || |
| 360 | mDrawingState.destinationFrame.isEmpty()) { |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 361 | // If destination frame is not set, use the requested transform set via |
| 362 | // BufferStateLayer::setPosition and BufferStateLayer::setMatrix. |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 363 | return assignTransform(&mDrawingState.transform, mRequestedTransform); |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 364 | } |
| 365 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 366 | Rect destRect = mDrawingState.destinationFrame; |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 367 | int32_t destW = destRect.width(); |
| 368 | int32_t destH = destRect.height(); |
| 369 | if (destRect.left < 0) { |
| 370 | destRect.left = 0; |
| 371 | destRect.right = destW; |
| 372 | } |
| 373 | if (destRect.top < 0) { |
| 374 | destRect.top = 0; |
| 375 | destRect.bottom = destH; |
| 376 | } |
| 377 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 378 | if (!mDrawingState.buffer) { |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 379 | ui::Transform t; |
| 380 | t.set(destRect.left, destRect.top); |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 381 | return assignTransform(&mDrawingState.transform, t); |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 382 | } |
| 383 | |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 384 | uint32_t bufferWidth = mDrawingState.buffer->getWidth(); |
| 385 | uint32_t bufferHeight = mDrawingState.buffer->getHeight(); |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 386 | // Undo any transformations on the buffer. |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 387 | if (mDrawingState.bufferTransform & ui::Transform::ROT_90) { |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 388 | std::swap(bufferWidth, bufferHeight); |
| 389 | } |
| 390 | uint32_t invTransform = DisplayDevice::getPrimaryDisplayRotationFlags(); |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 391 | if (mDrawingState.transformToDisplayInverse) { |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 392 | if (invTransform & ui::Transform::ROT_90) { |
| 393 | std::swap(bufferWidth, bufferHeight); |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | float sx = destW / static_cast<float>(bufferWidth); |
| 398 | float sy = destH / static_cast<float>(bufferHeight); |
| 399 | ui::Transform t; |
| 400 | t.set(sx, 0, 0, sy); |
| 401 | t.set(destRect.left, destRect.top); |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 402 | return assignTransform(&mDrawingState.transform, t); |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 403 | } |
| 404 | |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 405 | bool BufferStateLayer::setMatrix(const layer_state_t::matrix22_t& matrix) { |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 406 | if (mRequestedTransform.dsdx() == matrix.dsdx && mRequestedTransform.dtdy() == matrix.dtdy && |
| 407 | mRequestedTransform.dtdx() == matrix.dtdx && mRequestedTransform.dsdy() == matrix.dsdy) { |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 408 | return false; |
| 409 | } |
| 410 | |
Chavi Weingarten | a5aedbd | 2021-04-09 13:37:33 +0000 | [diff] [blame] | 411 | ui::Transform t; |
| 412 | t.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy); |
| 413 | |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 414 | mRequestedTransform.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy); |
chaviw | 9a93ea6 | 2021-03-11 16:44:42 -0600 | [diff] [blame] | 415 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 416 | mDrawingState.sequence++; |
| 417 | mDrawingState.modified = true; |
chaviw | 9a93ea6 | 2021-03-11 16:44:42 -0600 | [diff] [blame] | 418 | setTransactionFlags(eTransactionNeeded); |
Chavi Weingarten | a5aedbd | 2021-04-09 13:37:33 +0000 | [diff] [blame] | 419 | |
| 420 | return true; |
| 421 | } |
| 422 | |
| 423 | bool BufferStateLayer::setPosition(float x, float y) { |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 424 | if (mRequestedTransform.tx() == x && mRequestedTransform.ty() == y) { |
Chavi Weingarten | a5aedbd | 2021-04-09 13:37:33 +0000 | [diff] [blame] | 425 | return false; |
| 426 | } |
| 427 | |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 428 | mRequestedTransform.set(x, y); |
Chavi Weingarten | a5aedbd | 2021-04-09 13:37:33 +0000 | [diff] [blame] | 429 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 430 | mDrawingState.sequence++; |
| 431 | mDrawingState.modified = true; |
Chavi Weingarten | a5aedbd | 2021-04-09 13:37:33 +0000 | [diff] [blame] | 432 | setTransactionFlags(eTransactionNeeded); |
| 433 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 434 | return true; |
| 435 | } |
| 436 | |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 437 | bool BufferStateLayer::setBuffer(std::shared_ptr<renderengine::ExternalTexture>& buffer, |
| 438 | const BufferData& bufferData, nsecs_t postTime, |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 439 | nsecs_t desiredPresentTime, bool isAutoTimestamp, |
chaviw | ba4320c | 2021-09-15 15:20:53 -0500 | [diff] [blame] | 440 | std::optional<nsecs_t> dequeueTime, |
| 441 | const FrameTimelineInfo& info) { |
Alex Chau | cf6b4b4 | 2021-12-07 10:48:52 +0000 | [diff] [blame] | 442 | ATRACE_CALL(); |
Robert Carr | 0c1966e | 2020-10-19 12:12:08 -0700 | [diff] [blame] | 443 | |
chaviw | ba4320c | 2021-09-15 15:20:53 -0500 | [diff] [blame] | 444 | if (!buffer) { |
| 445 | return false; |
| 446 | } |
| 447 | |
| 448 | const bool frameNumberChanged = |
| 449 | bufferData.flags.test(BufferData::BufferDataChange::frameNumberChanged); |
| 450 | const uint64_t frameNumber = |
| 451 | frameNumberChanged ? bufferData.frameNumber : mDrawingState.frameNumber + 1; |
| 452 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 453 | if (mDrawingState.buffer) { |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 454 | mReleasePreviousBuffer = true; |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 455 | if (!mBufferInfo.mBuffer || |
| 456 | (!mDrawingState.buffer->hasSameBuffer(*mBufferInfo.mBuffer) || |
| 457 | mDrawingState.frameNumber != mBufferInfo.mFrameNumber)) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 458 | // If mDrawingState has a buffer, and we are about to update again |
Robert Carr | 7121caf | 2020-12-15 13:07:32 -0800 | [diff] [blame] | 459 | // before swapping to drawing state, then the first buffer will be |
Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 460 | // dropped and we should decrement the pending buffer count and |
| 461 | // call any release buffer callbacks if set. |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 462 | callReleaseBufferCallback(mDrawingState.releaseBufferListener, |
Vishnu Nair | 4ba0c2e | 2021-06-24 11:27:17 -0700 | [diff] [blame] | 463 | mDrawingState.buffer->getBuffer(), mDrawingState.frameNumber, |
chaviw | 69058fb | 2021-09-27 09:37:30 -0500 | [diff] [blame] | 464 | mDrawingState.acquireFence, |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 465 | mFlinger->getMaxAcquiredBufferCountForCurrentRefreshRate( |
| 466 | mOwnerUid)); |
Robert Carr | 7121caf | 2020-12-15 13:07:32 -0800 | [diff] [blame] | 467 | decrementPendingBufferCount(); |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 468 | if (mDrawingState.bufferSurfaceFrameTX != nullptr && |
| 469 | mDrawingState.bufferSurfaceFrameTX->getPresentState() != PresentState::Presented) { |
| 470 | addSurfaceFrameDroppedForBuffer(mDrawingState.bufferSurfaceFrameTX); |
| 471 | mDrawingState.bufferSurfaceFrameTX.reset(); |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 472 | } |
Robert Carr | b645049 | 2022-06-23 11:17:16 -0700 | [diff] [blame] | 473 | } else if (EARLY_RELEASE_ENABLED && mLastClientCompositionFence != nullptr) { |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 474 | callReleaseBufferCallback(mDrawingState.releaseBufferListener, |
| 475 | mDrawingState.buffer->getBuffer(), mDrawingState.frameNumber, |
chaviw | 69058fb | 2021-09-27 09:37:30 -0500 | [diff] [blame] | 476 | mLastClientCompositionFence, |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 477 | mFlinger->getMaxAcquiredBufferCountForCurrentRefreshRate( |
chaviw | 69058fb | 2021-09-27 09:37:30 -0500 | [diff] [blame] | 478 | mOwnerUid)); |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 479 | mLastClientCompositionFence = nullptr; |
Robert Carr | 7121caf | 2020-12-15 13:07:32 -0800 | [diff] [blame] | 480 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 481 | } |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 482 | |
| 483 | mDrawingState.frameNumber = frameNumber; |
chaviw | ba4320c | 2021-09-15 15:20:53 -0500 | [diff] [blame] | 484 | mDrawingState.releaseBufferListener = bufferData.releaseBufferListener; |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 485 | mDrawingState.buffer = std::move(buffer); |
chaviw | ba4320c | 2021-09-15 15:20:53 -0500 | [diff] [blame] | 486 | mDrawingState.clientCacheId = bufferData.cachedBuffer; |
| 487 | |
| 488 | mDrawingState.acquireFence = bufferData.flags.test(BufferData::BufferDataChange::fenceChanged) |
| 489 | ? bufferData.acquireFence |
| 490 | : Fence::NO_FENCE; |
| 491 | mDrawingState.acquireFenceTime = std::make_unique<FenceTime>(mDrawingState.acquireFence); |
Ady Abraham | 461296a | 2022-01-21 11:11:31 -0800 | [diff] [blame] | 492 | if (mDrawingState.acquireFenceTime->getSignalTime() == Fence::SIGNAL_TIME_PENDING) { |
| 493 | // We latched this buffer unsiganled, so we need to pass the acquire fence |
| 494 | // on the callback instead of just the acquire time, since it's unknown at |
| 495 | // this point. |
| 496 | mCallbackHandleAcquireTimeOrFence = mDrawingState.acquireFence; |
| 497 | } else { |
| 498 | mCallbackHandleAcquireTimeOrFence = mDrawingState.acquireFenceTime->getSignalTime(); |
| 499 | } |
chaviw | ba4320c | 2021-09-15 15:20:53 -0500 | [diff] [blame] | 500 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 501 | mDrawingState.modified = true; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 502 | setTransactionFlags(eTransactionNeeded); |
Ady Abraham | 09bd392 | 2019-04-08 10:44:56 -0700 | [diff] [blame] | 503 | |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 504 | const int32_t layerId = getSequence(); |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 505 | mFlinger->mTimeStats->setPostTime(layerId, mDrawingState.frameNumber, getName().c_str(), |
Adithya Srinivasan | 58069dc | 2021-06-04 20:37:02 +0000 | [diff] [blame] | 506 | mOwnerUid, postTime, getGameMode()); |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 507 | mDrawingState.desiredPresentTime = desiredPresentTime; |
| 508 | mDrawingState.isAutoTimestamp = isAutoTimestamp; |
Ady Abraham | 09bd392 | 2019-04-08 10:44:56 -0700 | [diff] [blame] | 509 | |
Ady Abraham | b7f1556 | 2021-03-15 18:34:08 -0700 | [diff] [blame] | 510 | const nsecs_t presentTime = [&] { |
| 511 | if (!isAutoTimestamp) return desiredPresentTime; |
| 512 | |
| 513 | const auto prediction = |
| 514 | mFlinger->mFrameTimeline->getTokenManager()->getPredictionsForToken(info.vsyncId); |
| 515 | if (prediction.has_value()) return prediction->presentTime; |
| 516 | |
| 517 | return static_cast<nsecs_t>(0); |
| 518 | }(); |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 519 | |
| 520 | using LayerUpdateType = scheduler::LayerHistory::LayerUpdateType; |
| 521 | mFlinger->mScheduler->recordLayerHistory(this, presentTime, LayerUpdateType::Buffer); |
Ady Abraham | 09bd392 | 2019-04-08 10:44:56 -0700 | [diff] [blame] | 522 | |
Adithya Srinivasan | 891004e | 2021-02-12 20:20:47 +0000 | [diff] [blame] | 523 | setFrameTimelineVsyncForBufferTransaction(info, postTime); |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 524 | |
Vishnu Nair | 26c4976 | 2022-01-18 22:58:52 +0000 | [diff] [blame] | 525 | if (dequeueTime && *dequeueTime != 0) { |
| 526 | const uint64_t bufferId = mDrawingState.buffer->getId(); |
Adithya Srinivasan | b238cd5 | 2021-02-04 17:54:05 +0000 | [diff] [blame] | 527 | mFlinger->mFrameTracer->traceNewLayer(layerId, getName().c_str()); |
| 528 | mFlinger->mFrameTracer->traceTimestamp(layerId, bufferId, frameNumber, *dequeueTime, |
| 529 | FrameTracer::FrameEvent::DEQUEUE); |
| 530 | mFlinger->mFrameTracer->traceTimestamp(layerId, bufferId, frameNumber, postTime, |
| 531 | FrameTracer::FrameEvent::QUEUE); |
| 532 | } |
Chavi Weingarten | a5aedbd | 2021-04-09 13:37:33 +0000 | [diff] [blame] | 533 | |
chaviw | ba4320c | 2021-09-15 15:20:53 -0500 | [diff] [blame] | 534 | mDrawingState.releaseBufferEndpoint = bufferData.releaseBufferEndpoint; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 535 | return true; |
| 536 | } |
| 537 | |
| 538 | bool BufferStateLayer::setDataspace(ui::Dataspace dataspace) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 539 | if (mDrawingState.dataspace == dataspace) return false; |
| 540 | mDrawingState.dataspace = dataspace; |
| 541 | mDrawingState.modified = true; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 542 | setTransactionFlags(eTransactionNeeded); |
| 543 | return true; |
| 544 | } |
| 545 | |
| 546 | bool BufferStateLayer::setHdrMetadata(const HdrMetadata& hdrMetadata) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 547 | if (mDrawingState.hdrMetadata == hdrMetadata) return false; |
| 548 | mDrawingState.hdrMetadata = hdrMetadata; |
| 549 | mDrawingState.modified = true; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 550 | setTransactionFlags(eTransactionNeeded); |
| 551 | return true; |
| 552 | } |
| 553 | |
| 554 | bool BufferStateLayer::setSurfaceDamageRegion(const Region& surfaceDamage) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 555 | mDrawingState.surfaceDamageRegion = surfaceDamage; |
| 556 | mDrawingState.modified = true; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 557 | setTransactionFlags(eTransactionNeeded); |
| 558 | return true; |
| 559 | } |
| 560 | |
| 561 | bool BufferStateLayer::setApi(int32_t api) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 562 | if (mDrawingState.api == api) return false; |
| 563 | mDrawingState.api = api; |
| 564 | mDrawingState.modified = true; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 565 | setTransactionFlags(eTransactionNeeded); |
| 566 | return true; |
| 567 | } |
| 568 | |
| 569 | bool BufferStateLayer::setSidebandStream(const sp<NativeHandle>& sidebandStream) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 570 | if (mDrawingState.sidebandStream == sidebandStream) return false; |
Robert Carr | 3e2a299 | 2021-06-11 13:42:55 -0700 | [diff] [blame] | 571 | |
| 572 | if (mDrawingState.sidebandStream != nullptr && sidebandStream == nullptr) { |
| 573 | mFlinger->mTunnelModeEnabledReporter->decrementTunnelModeCount(); |
| 574 | } else if (sidebandStream != nullptr) { |
| 575 | mFlinger->mTunnelModeEnabledReporter->incrementTunnelModeCount(); |
| 576 | } |
| 577 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 578 | mDrawingState.sidebandStream = sidebandStream; |
| 579 | mDrawingState.modified = true; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 580 | setTransactionFlags(eTransactionNeeded); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 581 | if (!mSidebandStreamChanged.exchange(true)) { |
| 582 | // mSidebandStreamChanged was false |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 583 | mFlinger->onLayerUpdate(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 584 | } |
| 585 | return true; |
| 586 | } |
| 587 | |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 588 | bool BufferStateLayer::setTransactionCompletedListeners( |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 589 | const std::vector<sp<CallbackHandle>>& handles) { |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 590 | // If there is no handle, we will not send a callback so reset mReleasePreviousBuffer and return |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 591 | if (handles.empty()) { |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 592 | mReleasePreviousBuffer = false; |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 593 | return false; |
| 594 | } |
| 595 | |
| 596 | const bool willPresent = willPresentCurrentTransaction(); |
| 597 | |
| 598 | for (const auto& handle : handles) { |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 599 | // If this transaction set a buffer on this layer, release its previous buffer |
| 600 | handle->releasePreviousBuffer = mReleasePreviousBuffer; |
| 601 | |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 602 | // If this layer will be presented in this frame |
| 603 | if (willPresent) { |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 604 | // If this transaction set an acquire fence on this layer, set its acquire time |
Ady Abraham | 461296a | 2022-01-21 11:11:31 -0800 | [diff] [blame] | 605 | handle->acquireTimeOrFence = mCallbackHandleAcquireTimeOrFence; |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 606 | handle->frameNumber = mDrawingState.frameNumber; |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 607 | |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 608 | // Store so latched time and release fence can be set |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 609 | mDrawingState.callbackHandles.push_back(handle); |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 610 | |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 611 | } else { // If this layer will NOT need to be relatched and presented this frame |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 612 | // Notify the transaction completed thread this handle is done |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 613 | mFlinger->getTransactionCallbackInvoker().registerUnpresentedCallbackHandle(handle); |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 614 | } |
| 615 | } |
| 616 | |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 617 | mReleasePreviousBuffer = false; |
Ady Abraham | 461296a | 2022-01-21 11:11:31 -0800 | [diff] [blame] | 618 | mCallbackHandleAcquireTimeOrFence = -1; |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 619 | |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 620 | return willPresent; |
| 621 | } |
| 622 | |
rnlee | ed20fa4 | 2021-08-10 18:00:03 -0700 | [diff] [blame] | 623 | Rect BufferStateLayer::getBufferSize(const State& /*s*/) const { |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 624 | // for buffer state layers we use the display frame size as the buffer size. |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 625 | |
chaviw | 7e72caf | 2020-12-02 16:50:43 -0800 | [diff] [blame] | 626 | if (mBufferInfo.mBuffer == nullptr) { |
| 627 | return Rect::INVALID_RECT; |
| 628 | } |
| 629 | |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 630 | uint32_t bufWidth = mBufferInfo.mBuffer->getWidth(); |
| 631 | uint32_t bufHeight = mBufferInfo.mBuffer->getHeight(); |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 632 | |
| 633 | // Undo any transformations on the buffer and return the result. |
| 634 | if (mBufferInfo.mTransform & ui::Transform::ROT_90) { |
| 635 | std::swap(bufWidth, bufHeight); |
| 636 | } |
| 637 | |
| 638 | if (getTransformToDisplayInverse()) { |
| 639 | uint32_t invTransform = DisplayDevice::getPrimaryDisplayRotationFlags(); |
| 640 | if (invTransform & ui::Transform::ROT_90) { |
| 641 | std::swap(bufWidth, bufHeight); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 642 | } |
| 643 | } |
| 644 | |
rnlee | ed20fa4 | 2021-08-10 18:00:03 -0700 | [diff] [blame] | 645 | return Rect(0, 0, static_cast<int32_t>(bufWidth), static_cast<int32_t>(bufHeight)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 646 | } |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 647 | |
| 648 | FloatRect BufferStateLayer::computeSourceBounds(const FloatRect& parentBounds) const { |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 649 | if (mBufferInfo.mBuffer == nullptr) { |
| 650 | return parentBounds; |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 651 | } |
| 652 | |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 653 | return getBufferSize(getDrawingState()).toFloatRect(); |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 654 | } |
| 655 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 656 | // ----------------------------------------------------------------------- |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 657 | bool BufferStateLayer::fenceHasSignaled() const { |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 658 | if (SurfaceFlinger::enableLatchUnsignaledConfig != LatchUnsignaledConfig::Disabled) { |
Huihong Luo | 86c80e3 | 2021-06-16 15:41:07 -0700 | [diff] [blame] | 659 | return true; |
| 660 | } |
| 661 | |
Alec Mouri | 91f6df3 | 2020-01-30 08:48:58 -0800 | [diff] [blame] | 662 | const bool fenceSignaled = |
| 663 | getDrawingState().acquireFence->getStatus() == Fence::Status::Signaled; |
| 664 | if (!fenceSignaled) { |
| 665 | mFlinger->mTimeStats->incrementLatchSkipped(getSequence(), |
| 666 | TimeStats::LatchSkipReason::LateAcquire); |
| 667 | } |
| 668 | |
| 669 | return fenceSignaled; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 670 | } |
| 671 | |
Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 672 | bool BufferStateLayer::onPreComposition(nsecs_t refreshStartTime) { |
| 673 | for (const auto& handle : mDrawingState.callbackHandles) { |
| 674 | handle->refreshStartTime = refreshStartTime; |
| 675 | } |
Vishnu Nair | a72f6c0 | 2022-07-01 05:33:08 +0000 | [diff] [blame] | 676 | return hasReadyFrame(); |
Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 677 | } |
| 678 | |
Vishnu Nair | cf26a0a | 2020-11-13 12:56:20 -0800 | [diff] [blame] | 679 | void BufferStateLayer::setAutoRefresh(bool autoRefresh) { |
Vishnu Nair | 86653e9 | 2021-11-03 17:19:36 -0700 | [diff] [blame] | 680 | mDrawingState.autoRefresh = autoRefresh; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 681 | } |
| 682 | |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 683 | bool BufferStateLayer::latchSidebandStream(bool& recomputeVisibleRegions) { |
baocheng sun | a663c2b | 2021-05-13 18:51:28 +0800 | [diff] [blame] | 684 | // We need to update the sideband stream if the layer has both a buffer and a sideband stream. |
baocheng sun | 9691b9c | 2021-08-03 19:27:06 +0800 | [diff] [blame] | 685 | editCompositionState()->sidebandStreamHasFrame = hasFrameUpdate() && mSidebandStream.get(); |
baocheng sun | a663c2b | 2021-05-13 18:51:28 +0800 | [diff] [blame] | 686 | |
baocheng sun | 9691b9c | 2021-08-03 19:27:06 +0800 | [diff] [blame] | 687 | if (mSidebandStreamChanged.exchange(false)) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 688 | const State& s(getDrawingState()); |
| 689 | // mSidebandStreamChanged was true |
Lloyd Pique | 0b785d8 | 2018-12-04 17:25:27 -0800 | [diff] [blame] | 690 | mSidebandStream = s.sidebandStream; |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 691 | editCompositionState()->sidebandStream = mSidebandStream; |
Lloyd Pique | 0b785d8 | 2018-12-04 17:25:27 -0800 | [diff] [blame] | 692 | if (mSidebandStream != nullptr) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 693 | setTransactionFlags(eTransactionNeeded); |
| 694 | mFlinger->setTransactionFlags(eTraversalNeeded); |
| 695 | } |
| 696 | recomputeVisibleRegions = true; |
| 697 | |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 698 | return true; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 699 | } |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 700 | return false; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 701 | } |
| 702 | |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 703 | bool BufferStateLayer::hasFrameUpdate() const { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 704 | const State& c(getDrawingState()); |
Robert Carr | 315f3c7 | 2021-06-24 21:58:09 -0700 | [diff] [blame] | 705 | return (mDrawingStateModified || mDrawingState.modified) && (c.buffer != nullptr || c.bgColorLayer != nullptr); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 706 | } |
| 707 | |
Vishnu Nair | 397a0e3 | 2022-07-26 00:01:48 +0000 | [diff] [blame] | 708 | void BufferStateLayer::updateTexImage(nsecs_t latchTime) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 709 | const State& s(getDrawingState()); |
| 710 | |
| 711 | if (!s.buffer) { |
Valerie Hau | aa19456 | 2019-02-05 16:21:38 -0800 | [diff] [blame] | 712 | if (s.bgColorLayer) { |
| 713 | for (auto& handle : mDrawingState.callbackHandles) { |
| 714 | handle->latchTime = latchTime; |
| 715 | } |
| 716 | } |
Vishnu Nair | 397a0e3 | 2022-07-26 00:01:48 +0000 | [diff] [blame] | 717 | return; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 718 | } |
| 719 | |
Marissa Wall | 5a68a77 | 2018-12-22 17:43:42 -0800 | [diff] [blame] | 720 | for (auto& handle : mDrawingState.callbackHandles) { |
Vishnu Nair | 935590e | 2021-02-10 13:05:52 -0800 | [diff] [blame] | 721 | if (handle->frameNumber == mDrawingState.frameNumber) { |
| 722 | handle->latchTime = latchTime; |
| 723 | } |
Marissa Wall | 5a68a77 | 2018-12-22 17:43:42 -0800 | [diff] [blame] | 724 | } |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 725 | |
Vishnu Nair | ea0de00 | 2020-11-17 17:42:37 -0800 | [diff] [blame] | 726 | const int32_t layerId = getSequence(); |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 727 | const uint64_t bufferId = mDrawingState.buffer->getId(); |
Adithya Srinivasan | b238cd5 | 2021-02-04 17:54:05 +0000 | [diff] [blame] | 728 | const uint64_t frameNumber = mDrawingState.frameNumber; |
| 729 | const auto acquireFence = std::make_shared<FenceTime>(mDrawingState.acquireFence); |
| 730 | mFlinger->mTimeStats->setAcquireFence(layerId, frameNumber, acquireFence); |
| 731 | mFlinger->mTimeStats->setLatchTime(layerId, frameNumber, latchTime); |
| 732 | |
| 733 | mFlinger->mFrameTracer->traceFence(layerId, bufferId, frameNumber, acquireFence, |
| 734 | FrameTracer::FrameEvent::ACQUIRE_FENCE); |
| 735 | mFlinger->mFrameTracer->traceTimestamp(layerId, bufferId, frameNumber, latchTime, |
| 736 | FrameTracer::FrameEvent::LATCH); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 737 | |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 738 | auto& bufferSurfaceFrame = mDrawingState.bufferSurfaceFrameTX; |
| 739 | if (bufferSurfaceFrame != nullptr && |
| 740 | bufferSurfaceFrame->getPresentState() != PresentState::Presented) { |
| 741 | // Update only if the bufferSurfaceFrame wasn't already presented. A Presented |
| 742 | // bufferSurfaceFrame could be seen here if a pending state was applied successfully and we |
| 743 | // are processing the next state. |
| 744 | addSurfaceFramePresentedForBuffer(bufferSurfaceFrame, |
Ady Abraham | 6c1b7ac | 2021-03-31 16:56:03 -0700 | [diff] [blame] | 745 | mDrawingState.acquireFenceTime->getSignalTime(), |
| 746 | latchTime); |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 747 | mDrawingState.bufferSurfaceFrameTX.reset(); |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 748 | } |
| 749 | |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 750 | std::deque<sp<CallbackHandle>> remainingHandles; |
| 751 | mFlinger->getTransactionCallbackInvoker() |
Robert Carr | 3d1047b | 2021-09-20 18:22:32 -0700 | [diff] [blame] | 752 | .addOnCommitCallbackHandles(mDrawingState.callbackHandles, remainingHandles); |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 753 | mDrawingState.callbackHandles = remainingHandles; |
| 754 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 755 | mDrawingStateModified = false; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 756 | } |
| 757 | |
Vishnu Nair | 397a0e3 | 2022-07-26 00:01:48 +0000 | [diff] [blame] | 758 | void BufferStateLayer::gatherBufferInfo() { |
| 759 | if (!mBufferInfo.mBuffer || !mDrawingState.buffer->hasSameBuffer(*mBufferInfo.mBuffer)) { |
chaviw | df3c5e8 | 2021-01-07 13:00:37 -0800 | [diff] [blame] | 760 | decrementPendingBufferCount(); |
| 761 | } |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 762 | |
Vishnu Nair | 4ba0c2e | 2021-06-24 11:27:17 -0700 | [diff] [blame] | 763 | mPreviousReleaseCallbackId = {getCurrentBufferId(), mBufferInfo.mFrameNumber}; |
Vishnu Nair | 397a0e3 | 2022-07-26 00:01:48 +0000 | [diff] [blame] | 764 | mBufferInfo.mBuffer = mDrawingState.buffer; |
| 765 | mBufferInfo.mFence = mDrawingState.acquireFence; |
| 766 | mBufferInfo.mFrameNumber = mDrawingState.frameNumber; |
Vishnu Nair | a72f6c0 | 2022-07-01 05:33:08 +0000 | [diff] [blame] | 767 | mBufferInfo.mPixelFormat = |
| 768 | !mBufferInfo.mBuffer ? PIXEL_FORMAT_NONE : mBufferInfo.mBuffer->getPixelFormat(); |
| 769 | mBufferInfo.mFrameLatencyNeeded = true; |
Vishnu Nair | 397a0e3 | 2022-07-26 00:01:48 +0000 | [diff] [blame] | 770 | mBufferInfo.mDesiredPresentTime = mDrawingState.desiredPresentTime; |
| 771 | mBufferInfo.mFenceTime = std::make_shared<FenceTime>(mDrawingState.acquireFence); |
| 772 | mBufferInfo.mFence = mDrawingState.acquireFence; |
| 773 | mBufferInfo.mTransform = mDrawingState.bufferTransform; |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 774 | auto lastDataspace = mBufferInfo.mDataspace; |
Vishnu Nair | 397a0e3 | 2022-07-26 00:01:48 +0000 | [diff] [blame] | 775 | mBufferInfo.mDataspace = translateDataspace(mDrawingState.dataspace); |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 776 | if (lastDataspace != mBufferInfo.mDataspace) { |
| 777 | mFlinger->mSomeDataspaceChanged = true; |
| 778 | } |
Vishnu Nair | 397a0e3 | 2022-07-26 00:01:48 +0000 | [diff] [blame] | 779 | mBufferInfo.mCrop = computeBufferCrop(mDrawingState); |
chaviw | 4244e03 | 2019-09-04 11:27:49 -0700 | [diff] [blame] | 780 | mBufferInfo.mScaleMode = NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW; |
Vishnu Nair | 397a0e3 | 2022-07-26 00:01:48 +0000 | [diff] [blame] | 781 | mBufferInfo.mSurfaceDamage = mDrawingState.surfaceDamageRegion; |
| 782 | mBufferInfo.mHdrMetadata = mDrawingState.hdrMetadata; |
| 783 | mBufferInfo.mApi = mDrawingState.api; |
| 784 | mBufferInfo.mTransformToDisplayInverse = mDrawingState.transformToDisplayInverse; |
| 785 | mBufferInfo.mBufferSlot = mHwcSlotGenerator->getHwcCacheSlot(mDrawingState.clientCacheId); |
Robert Carr | 916b036 | 2020-10-06 13:53:03 -0700 | [diff] [blame] | 786 | } |
| 787 | |
Vishnu Nair | 5cc9ac0 | 2021-04-19 13:23:38 -0700 | [diff] [blame] | 788 | Rect BufferStateLayer::computeBufferCrop(const State& s) { |
chaviw | f3f40fe | 2021-04-27 15:54:02 -0500 | [diff] [blame] | 789 | if (s.buffer && !s.bufferCrop.isEmpty()) { |
| 790 | Rect bufferCrop; |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 791 | s.buffer->getBounds().intersect(s.bufferCrop, &bufferCrop); |
chaviw | f3f40fe | 2021-04-27 15:54:02 -0500 | [diff] [blame] | 792 | return bufferCrop; |
| 793 | } else if (s.buffer) { |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 794 | return s.buffer->getBounds(); |
chaviw | f3f40fe | 2021-04-27 15:54:02 -0500 | [diff] [blame] | 795 | } else { |
| 796 | return s.bufferCrop; |
chaviw | 4244e03 | 2019-09-04 11:27:49 -0700 | [diff] [blame] | 797 | } |
chaviw | 4244e03 | 2019-09-04 11:27:49 -0700 | [diff] [blame] | 798 | } |
| 799 | |
chaviw | b4c6e58 | 2019-08-16 14:35:07 -0700 | [diff] [blame] | 800 | sp<Layer> BufferStateLayer::createClone() { |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 801 | LayerCreationArgs args(mFlinger.get(), nullptr, mName + " (Mirror)", 0, LayerMetadata()); |
chaviw | b4c6e58 | 2019-08-16 14:35:07 -0700 | [diff] [blame] | 802 | args.textureName = mTextureName; |
Lloyd Pique | 1c3a5eb | 2019-10-03 13:07:08 -0700 | [diff] [blame] | 803 | sp<BufferStateLayer> layer = mFlinger->getFactory().createBufferStateLayer(args); |
chaviw | b4c6e58 | 2019-08-16 14:35:07 -0700 | [diff] [blame] | 804 | layer->mHwcSlotGenerator = mHwcSlotGenerator; |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 805 | layer->setInitialValuesForClone(sp<Layer>::fromExisting(this)); |
chaviw | b4c6e58 | 2019-08-16 14:35:07 -0700 | [diff] [blame] | 806 | return layer; |
| 807 | } |
Valerie Hau | 92bf548 | 2020-02-10 09:49:08 -0800 | [diff] [blame] | 808 | |
Vishnu Nair | e7f79c5 | 2020-10-29 14:45:03 -0700 | [diff] [blame] | 809 | bool BufferStateLayer::bufferNeedsFiltering() const { |
| 810 | const State& s(getDrawingState()); |
| 811 | if (!s.buffer) { |
| 812 | return false; |
| 813 | } |
| 814 | |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 815 | int32_t bufferWidth = static_cast<int32_t>(s.buffer->getWidth()); |
| 816 | int32_t bufferHeight = static_cast<int32_t>(s.buffer->getHeight()); |
Vishnu Nair | e7f79c5 | 2020-10-29 14:45:03 -0700 | [diff] [blame] | 817 | |
| 818 | // Undo any transformations on the buffer and return the result. |
chaviw | 766c9c5 | 2021-02-10 17:36:47 -0800 | [diff] [blame] | 819 | if (s.bufferTransform & ui::Transform::ROT_90) { |
Vishnu Nair | e7f79c5 | 2020-10-29 14:45:03 -0700 | [diff] [blame] | 820 | std::swap(bufferWidth, bufferHeight); |
| 821 | } |
| 822 | |
| 823 | if (s.transformToDisplayInverse) { |
| 824 | uint32_t invTransform = DisplayDevice::getPrimaryDisplayRotationFlags(); |
| 825 | if (invTransform & ui::Transform::ROT_90) { |
| 826 | std::swap(bufferWidth, bufferHeight); |
| 827 | } |
| 828 | } |
| 829 | |
| 830 | const Rect layerSize{getBounds()}; |
Yiwei Zhang | 22ca2c4 | 2022-07-07 07:00:16 +0000 | [diff] [blame] | 831 | int32_t layerWidth = layerSize.getWidth(); |
| 832 | int32_t layerHeight = layerSize.getHeight(); |
| 833 | |
| 834 | // Align the layer orientation with the buffer before comparism |
| 835 | if (mTransformHint & ui::Transform::ROT_90) { |
| 836 | std::swap(layerWidth, layerHeight); |
| 837 | } |
| 838 | |
| 839 | return layerWidth != bufferWidth || layerHeight != bufferHeight; |
Vishnu Nair | e7f79c5 | 2020-10-29 14:45:03 -0700 | [diff] [blame] | 840 | } |
Robert Carr | 7121caf | 2020-12-15 13:07:32 -0800 | [diff] [blame] | 841 | |
Robert Carr | 7121caf | 2020-12-15 13:07:32 -0800 | [diff] [blame] | 842 | void BufferStateLayer::decrementPendingBufferCount() { |
Vishnu Nair | 8eda69e | 2021-02-26 10:42:10 -0800 | [diff] [blame] | 843 | int32_t pendingBuffers = --mPendingBufferTransactions; |
| 844 | tracePendingBufferCount(pendingBuffers); |
Robert Carr | 7121caf | 2020-12-15 13:07:32 -0800 | [diff] [blame] | 845 | } |
| 846 | |
Vishnu Nair | 8eda69e | 2021-02-26 10:42:10 -0800 | [diff] [blame] | 847 | void BufferStateLayer::tracePendingBufferCount(int32_t pendingBuffers) { |
| 848 | ATRACE_INT(mBlastTransactionName.c_str(), pendingBuffers); |
Robert Carr | 7121caf | 2020-12-15 13:07:32 -0800 | [diff] [blame] | 849 | } |
| 850 | |
Robert Carr | 7121caf | 2020-12-15 13:07:32 -0800 | [diff] [blame] | 851 | |
chaviw | 39d0147 | 2021-04-08 14:26:24 -0500 | [diff] [blame] | 852 | /* |
| 853 | * We don't want to send the layer's transform to input, but rather the |
| 854 | * parent's transform. This is because BufferStateLayer's transform is |
| 855 | * information about how the buffer is placed on screen. The parent's |
| 856 | * transform makes more sense to send since it's information about how the |
| 857 | * layer is placed on screen. This transform is used by input to determine |
| 858 | * how to go from screen space back to window space. |
| 859 | */ |
| 860 | ui::Transform BufferStateLayer::getInputTransform() const { |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 861 | sp<Layer> parent = mDrawingParent.promote(); |
chaviw | 39d0147 | 2021-04-08 14:26:24 -0500 | [diff] [blame] | 862 | if (parent == nullptr) { |
| 863 | return ui::Transform(); |
| 864 | } |
| 865 | |
| 866 | return parent->getTransform(); |
| 867 | } |
| 868 | |
| 869 | /** |
| 870 | * Similar to getInputTransform, we need to update the bounds to include the transform. |
| 871 | * This is because bounds for BSL doesn't include buffer transform, where the input assumes |
| 872 | * that's already included. |
| 873 | */ |
| 874 | Rect BufferStateLayer::getInputBounds() const { |
| 875 | Rect bufferBounds = getCroppedBufferSize(getDrawingState()); |
| 876 | if (mDrawingState.transform.getType() == ui::Transform::IDENTITY || !bufferBounds.isValid()) { |
| 877 | return bufferBounds; |
| 878 | } |
| 879 | return mDrawingState.transform.transform(bufferBounds); |
| 880 | } |
| 881 | |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 882 | bool BufferStateLayer::simpleBufferUpdate(const layer_state_t& s) const { |
| 883 | const uint64_t requiredFlags = layer_state_t::eBufferChanged; |
| 884 | |
| 885 | const uint64_t deniedFlags = layer_state_t::eProducerDisconnect | layer_state_t::eLayerChanged | |
| 886 | layer_state_t::eRelativeLayerChanged | layer_state_t::eTransparentRegionChanged | |
| 887 | layer_state_t::eFlagsChanged | layer_state_t::eBlurRegionsChanged | |
| 888 | layer_state_t::eLayerStackChanged | layer_state_t::eAutoRefreshChanged | |
| 889 | layer_state_t::eReparent; |
| 890 | |
| 891 | const uint64_t allowedFlags = layer_state_t::eHasListenerCallbacksChanged | |
| 892 | layer_state_t::eFrameRateSelectionPriority | layer_state_t::eFrameRateChanged | |
| 893 | layer_state_t::eSurfaceDamageRegionChanged | layer_state_t::eApiChanged | |
| 894 | layer_state_t::eMetadataChanged | layer_state_t::eDropInputModeChanged | |
| 895 | layer_state_t::eInputInfoChanged; |
| 896 | |
| 897 | if ((s.what & requiredFlags) != requiredFlags) { |
| 898 | ALOGV("%s: false [missing required flags 0x%" PRIx64 "]", __func__, |
| 899 | (s.what | requiredFlags) & ~s.what); |
| 900 | return false; |
| 901 | } |
| 902 | |
| 903 | if (s.what & deniedFlags) { |
| 904 | ALOGV("%s: false [has denied flags 0x%" PRIx64 "]", __func__, s.what & deniedFlags); |
| 905 | return false; |
| 906 | } |
| 907 | |
| 908 | if (s.what & allowedFlags) { |
| 909 | ALOGV("%s: [has allowed flags 0x%" PRIx64 "]", __func__, s.what & allowedFlags); |
| 910 | } |
| 911 | |
| 912 | if (s.what & layer_state_t::ePositionChanged) { |
| 913 | if (mRequestedTransform.tx() != s.x || mRequestedTransform.ty() != s.y) { |
| 914 | ALOGV("%s: false [ePositionChanged changed]", __func__); |
| 915 | return false; |
| 916 | } |
| 917 | } |
| 918 | |
| 919 | if (s.what & layer_state_t::eAlphaChanged) { |
| 920 | if (mDrawingState.color.a != s.alpha) { |
| 921 | ALOGV("%s: false [eAlphaChanged changed]", __func__); |
| 922 | return false; |
| 923 | } |
| 924 | } |
| 925 | |
| 926 | if (s.what & layer_state_t::eColorTransformChanged) { |
| 927 | if (mDrawingState.colorTransform != s.colorTransform) { |
| 928 | ALOGV("%s: false [eColorTransformChanged changed]", __func__); |
| 929 | return false; |
| 930 | } |
| 931 | } |
| 932 | |
| 933 | if (s.what & layer_state_t::eBackgroundColorChanged) { |
| 934 | if (mDrawingState.bgColorLayer || s.bgColorAlpha != 0) { |
| 935 | ALOGV("%s: false [eBackgroundColorChanged changed]", __func__); |
| 936 | return false; |
| 937 | } |
| 938 | } |
| 939 | |
| 940 | if (s.what & layer_state_t::eMatrixChanged) { |
| 941 | if (mRequestedTransform.dsdx() != s.matrix.dsdx || |
| 942 | mRequestedTransform.dtdy() != s.matrix.dtdy || |
| 943 | mRequestedTransform.dtdx() != s.matrix.dtdx || |
| 944 | mRequestedTransform.dsdy() != s.matrix.dsdy) { |
| 945 | ALOGV("%s: false [eMatrixChanged changed]", __func__); |
| 946 | return false; |
| 947 | } |
| 948 | } |
| 949 | |
| 950 | if (s.what & layer_state_t::eCornerRadiusChanged) { |
| 951 | if (mDrawingState.cornerRadius != s.cornerRadius) { |
| 952 | ALOGV("%s: false [eCornerRadiusChanged changed]", __func__); |
| 953 | return false; |
| 954 | } |
| 955 | } |
| 956 | |
| 957 | if (s.what & layer_state_t::eBackgroundBlurRadiusChanged) { |
| 958 | if (mDrawingState.backgroundBlurRadius != static_cast<int>(s.backgroundBlurRadius)) { |
| 959 | ALOGV("%s: false [eBackgroundBlurRadiusChanged changed]", __func__); |
| 960 | return false; |
| 961 | } |
| 962 | } |
| 963 | |
| 964 | if (s.what & layer_state_t::eTransformChanged) { |
| 965 | if (mDrawingState.bufferTransform != s.transform) { |
| 966 | ALOGV("%s: false [eTransformChanged changed]", __func__); |
| 967 | return false; |
| 968 | } |
| 969 | } |
| 970 | |
| 971 | if (s.what & layer_state_t::eTransformToDisplayInverseChanged) { |
| 972 | if (mDrawingState.transformToDisplayInverse != s.transformToDisplayInverse) { |
| 973 | ALOGV("%s: false [eTransformToDisplayInverseChanged changed]", __func__); |
| 974 | return false; |
| 975 | } |
| 976 | } |
| 977 | |
| 978 | if (s.what & layer_state_t::eCropChanged) { |
| 979 | if (mDrawingState.crop != s.crop) { |
| 980 | ALOGV("%s: false [eCropChanged changed]", __func__); |
| 981 | return false; |
| 982 | } |
| 983 | } |
| 984 | |
| 985 | if (s.what & layer_state_t::eDataspaceChanged) { |
| 986 | if (mDrawingState.dataspace != s.dataspace) { |
| 987 | ALOGV("%s: false [eDataspaceChanged changed]", __func__); |
| 988 | return false; |
| 989 | } |
| 990 | } |
| 991 | |
| 992 | if (s.what & layer_state_t::eHdrMetadataChanged) { |
| 993 | if (mDrawingState.hdrMetadata != s.hdrMetadata) { |
| 994 | ALOGV("%s: false [eHdrMetadataChanged changed]", __func__); |
| 995 | return false; |
| 996 | } |
| 997 | } |
| 998 | |
| 999 | if (s.what & layer_state_t::eSidebandStreamChanged) { |
| 1000 | if (mDrawingState.sidebandStream != s.sidebandStream) { |
| 1001 | ALOGV("%s: false [eSidebandStreamChanged changed]", __func__); |
| 1002 | return false; |
| 1003 | } |
| 1004 | } |
| 1005 | |
| 1006 | if (s.what & layer_state_t::eColorSpaceAgnosticChanged) { |
| 1007 | if (mDrawingState.colorSpaceAgnostic != s.colorSpaceAgnostic) { |
| 1008 | ALOGV("%s: false [eColorSpaceAgnosticChanged changed]", __func__); |
| 1009 | return false; |
| 1010 | } |
| 1011 | } |
| 1012 | |
| 1013 | if (s.what & layer_state_t::eShadowRadiusChanged) { |
| 1014 | if (mDrawingState.shadowRadius != s.shadowRadius) { |
| 1015 | ALOGV("%s: false [eShadowRadiusChanged changed]", __func__); |
| 1016 | return false; |
| 1017 | } |
| 1018 | } |
| 1019 | |
| 1020 | if (s.what & layer_state_t::eFixedTransformHintChanged) { |
| 1021 | if (mDrawingState.fixedTransformHint != s.fixedTransformHint) { |
| 1022 | ALOGV("%s: false [eFixedTransformHintChanged changed]", __func__); |
| 1023 | return false; |
| 1024 | } |
| 1025 | } |
| 1026 | |
| 1027 | if (s.what & layer_state_t::eTrustedOverlayChanged) { |
| 1028 | if (mDrawingState.isTrustedOverlay != s.isTrustedOverlay) { |
| 1029 | ALOGV("%s: false [eTrustedOverlayChanged changed]", __func__); |
| 1030 | return false; |
| 1031 | } |
| 1032 | } |
| 1033 | |
| 1034 | if (s.what & layer_state_t::eStretchChanged) { |
| 1035 | StretchEffect temp = s.stretchEffect; |
| 1036 | temp.sanitize(); |
| 1037 | if (mDrawingState.stretchEffect != temp) { |
| 1038 | ALOGV("%s: false [eStretchChanged changed]", __func__); |
| 1039 | return false; |
| 1040 | } |
| 1041 | } |
| 1042 | |
| 1043 | if (s.what & layer_state_t::eBufferCropChanged) { |
| 1044 | if (mDrawingState.bufferCrop != s.bufferCrop) { |
| 1045 | ALOGV("%s: false [eBufferCropChanged changed]", __func__); |
| 1046 | return false; |
| 1047 | } |
| 1048 | } |
| 1049 | |
| 1050 | if (s.what & layer_state_t::eDestinationFrameChanged) { |
| 1051 | if (mDrawingState.destinationFrame != s.destinationFrame) { |
| 1052 | ALOGV("%s: false [eDestinationFrameChanged changed]", __func__); |
| 1053 | return false; |
| 1054 | } |
| 1055 | } |
| 1056 | |
Sally Qi | 81d95e6 | 2022-03-21 19:41:33 -0700 | [diff] [blame] | 1057 | if (s.what & layer_state_t::eDimmingEnabledChanged) { |
| 1058 | if (mDrawingState.dimmingEnabled != s.dimmingEnabled) { |
| 1059 | ALOGV("%s: false [eDimmingEnabledChanged changed]", __func__); |
| 1060 | return false; |
| 1061 | } |
| 1062 | } |
| 1063 | |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 1064 | ALOGV("%s: true", __func__); |
| 1065 | return true; |
| 1066 | } |
| 1067 | |
Vishnu Nair | a72f6c0 | 2022-07-01 05:33:08 +0000 | [diff] [blame] | 1068 | void BufferStateLayer::useSurfaceDamage() { |
| 1069 | if (mFlinger->mForceFullDamage) { |
| 1070 | surfaceDamageRegion = Region::INVALID_REGION; |
| 1071 | } else { |
| 1072 | surfaceDamageRegion = mBufferInfo.mSurfaceDamage; |
| 1073 | } |
| 1074 | } |
| 1075 | |
| 1076 | void BufferStateLayer::useEmptyDamage() { |
| 1077 | surfaceDamageRegion.clear(); |
| 1078 | } |
| 1079 | |
| 1080 | bool BufferStateLayer::isOpaque(const Layer::State& s) const { |
| 1081 | // if we don't have a buffer or sidebandStream yet, we're translucent regardless of the |
| 1082 | // layer's opaque flag. |
| 1083 | if ((mSidebandStream == nullptr) && (mBufferInfo.mBuffer == nullptr)) { |
| 1084 | return false; |
| 1085 | } |
| 1086 | |
| 1087 | // if the layer has the opaque flag, then we're always opaque, |
| 1088 | // otherwise we use the current buffer's format. |
| 1089 | return ((s.flags & layer_state_t::eLayerOpaque) != 0) || getOpacityForFormat(getPixelFormat()); |
| 1090 | } |
| 1091 | |
| 1092 | bool BufferStateLayer::canReceiveInput() const { |
| 1093 | return !isHiddenByPolicy() && (mBufferInfo.mBuffer == nullptr || getAlpha() > 0.0f); |
| 1094 | } |
| 1095 | |
| 1096 | bool BufferStateLayer::isVisible() const { |
| 1097 | return !isHiddenByPolicy() && getAlpha() > 0.0f && |
| 1098 | (mBufferInfo.mBuffer != nullptr || mSidebandStream != nullptr); |
| 1099 | } |
| 1100 | |
Vishnu Nair | a72f6c0 | 2022-07-01 05:33:08 +0000 | [diff] [blame] | 1101 | std::optional<compositionengine::LayerFE::LayerSettings> BufferStateLayer::prepareClientComposition( |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 1102 | compositionengine::LayerFE::ClientCompositionTargetSettings& targetSettings) const { |
| 1103 | std::optional<compositionengine::LayerFE::LayerSettings> layerSettings = |
| 1104 | prepareClientCompositionInternal(targetSettings); |
| 1105 | // Nothing to render. |
| 1106 | if (!layerSettings) { |
| 1107 | return {}; |
| 1108 | } |
| 1109 | |
| 1110 | // HWC requests to clear this layer. |
| 1111 | if (targetSettings.clearContent) { |
| 1112 | prepareClearClientComposition(*layerSettings, false /* blackout */); |
| 1113 | return *layerSettings; |
| 1114 | } |
| 1115 | |
| 1116 | // set the shadow for the layer if needed |
| 1117 | prepareShadowClientComposition(*layerSettings, targetSettings.viewport); |
| 1118 | |
| 1119 | return *layerSettings; |
| 1120 | } |
| 1121 | |
| 1122 | std::optional<compositionengine::LayerFE::LayerSettings> |
| 1123 | BufferStateLayer::prepareClientCompositionInternal( |
| 1124 | compositionengine::LayerFE::ClientCompositionTargetSettings& targetSettings) const { |
Vishnu Nair | a72f6c0 | 2022-07-01 05:33:08 +0000 | [diff] [blame] | 1125 | ATRACE_CALL(); |
| 1126 | |
| 1127 | std::optional<compositionengine::LayerFE::LayerSettings> result = |
| 1128 | Layer::prepareClientComposition(targetSettings); |
| 1129 | if (!result) { |
| 1130 | return result; |
| 1131 | } |
| 1132 | |
| 1133 | if (CC_UNLIKELY(mBufferInfo.mBuffer == 0) && mSidebandStream != nullptr) { |
| 1134 | // For surfaceview of tv sideband, there is no activeBuffer |
| 1135 | // in bufferqueue, we need return LayerSettings. |
| 1136 | return result; |
| 1137 | } |
| 1138 | const bool blackOutLayer = (isProtected() && !targetSettings.supportsProtectedContent) || |
| 1139 | ((isSecure() || isProtected()) && !targetSettings.isSecure); |
| 1140 | const bool bufferCanBeUsedAsHwTexture = |
| 1141 | mBufferInfo.mBuffer->getUsage() & GraphicBuffer::USAGE_HW_TEXTURE; |
| 1142 | compositionengine::LayerFE::LayerSettings& layer = *result; |
| 1143 | if (blackOutLayer || !bufferCanBeUsedAsHwTexture) { |
| 1144 | ALOGE_IF(!bufferCanBeUsedAsHwTexture, "%s is blacked out as buffer is not gpu readable", |
| 1145 | mName.c_str()); |
| 1146 | prepareClearClientComposition(layer, true /* blackout */); |
| 1147 | return layer; |
| 1148 | } |
| 1149 | |
| 1150 | const State& s(getDrawingState()); |
| 1151 | layer.source.buffer.buffer = mBufferInfo.mBuffer; |
| 1152 | layer.source.buffer.isOpaque = isOpaque(s); |
| 1153 | layer.source.buffer.fence = mBufferInfo.mFence; |
| 1154 | layer.source.buffer.textureName = mTextureName; |
| 1155 | layer.source.buffer.usePremultipliedAlpha = getPremultipledAlpha(); |
| 1156 | layer.source.buffer.isY410BT2020 = isHdrY410(); |
| 1157 | bool hasSmpte2086 = mBufferInfo.mHdrMetadata.validTypes & HdrMetadata::SMPTE2086; |
| 1158 | bool hasCta861_3 = mBufferInfo.mHdrMetadata.validTypes & HdrMetadata::CTA861_3; |
| 1159 | float maxLuminance = 0.f; |
| 1160 | if (hasSmpte2086 && hasCta861_3) { |
| 1161 | maxLuminance = std::min(mBufferInfo.mHdrMetadata.smpte2086.maxLuminance, |
| 1162 | mBufferInfo.mHdrMetadata.cta8613.maxContentLightLevel); |
| 1163 | } else if (hasSmpte2086) { |
| 1164 | maxLuminance = mBufferInfo.mHdrMetadata.smpte2086.maxLuminance; |
| 1165 | } else if (hasCta861_3) { |
| 1166 | maxLuminance = mBufferInfo.mHdrMetadata.cta8613.maxContentLightLevel; |
| 1167 | } else { |
| 1168 | switch (layer.sourceDataspace & HAL_DATASPACE_TRANSFER_MASK) { |
| 1169 | case HAL_DATASPACE_TRANSFER_ST2084: |
| 1170 | case HAL_DATASPACE_TRANSFER_HLG: |
| 1171 | // Behavior-match previous releases for HDR content |
| 1172 | maxLuminance = defaultMaxLuminance; |
| 1173 | break; |
| 1174 | } |
| 1175 | } |
| 1176 | layer.source.buffer.maxLuminanceNits = maxLuminance; |
| 1177 | layer.frameNumber = mCurrentFrameNumber; |
| 1178 | layer.bufferId = mBufferInfo.mBuffer ? mBufferInfo.mBuffer->getId() : 0; |
| 1179 | |
| 1180 | const bool useFiltering = |
| 1181 | targetSettings.needsFiltering || mNeedsFiltering || bufferNeedsFiltering(); |
| 1182 | |
| 1183 | // Query the texture matrix given our current filtering mode. |
| 1184 | float textureMatrix[16]; |
| 1185 | getDrawingTransformMatrix(useFiltering, textureMatrix); |
| 1186 | |
| 1187 | if (getTransformToDisplayInverse()) { |
| 1188 | /* |
| 1189 | * the code below applies the primary display's inverse transform to |
| 1190 | * the texture transform |
| 1191 | */ |
| 1192 | uint32_t transform = DisplayDevice::getPrimaryDisplayRotationFlags(); |
| 1193 | mat4 tr = inverseOrientation(transform); |
| 1194 | |
| 1195 | /** |
| 1196 | * TODO(b/36727915): This is basically a hack. |
| 1197 | * |
| 1198 | * Ensure that regardless of the parent transformation, |
| 1199 | * this buffer is always transformed from native display |
| 1200 | * orientation to display orientation. For example, in the case |
| 1201 | * of a camera where the buffer remains in native orientation, |
| 1202 | * we want the pixels to always be upright. |
| 1203 | */ |
| 1204 | sp<Layer> p = mDrawingParent.promote(); |
| 1205 | if (p != nullptr) { |
| 1206 | const auto parentTransform = p->getTransform(); |
| 1207 | tr = tr * inverseOrientation(parentTransform.getOrientation()); |
| 1208 | } |
| 1209 | |
| 1210 | // and finally apply it to the original texture matrix |
| 1211 | const mat4 texTransform(mat4(static_cast<const float*>(textureMatrix)) * tr); |
| 1212 | memcpy(textureMatrix, texTransform.asArray(), sizeof(textureMatrix)); |
| 1213 | } |
| 1214 | |
| 1215 | const Rect win{getBounds()}; |
| 1216 | float bufferWidth = getBufferSize(s).getWidth(); |
| 1217 | float bufferHeight = getBufferSize(s).getHeight(); |
| 1218 | |
| 1219 | // BufferStateLayers can have a "buffer size" of [0, 0, -1, -1] when no display frame has |
| 1220 | // been set and there is no parent layer bounds. In that case, the scale is meaningless so |
| 1221 | // ignore them. |
| 1222 | if (!getBufferSize(s).isValid()) { |
| 1223 | bufferWidth = float(win.right) - float(win.left); |
| 1224 | bufferHeight = float(win.bottom) - float(win.top); |
| 1225 | } |
| 1226 | |
| 1227 | const float scaleHeight = (float(win.bottom) - float(win.top)) / bufferHeight; |
| 1228 | const float scaleWidth = (float(win.right) - float(win.left)) / bufferWidth; |
| 1229 | const float translateY = float(win.top) / bufferHeight; |
| 1230 | const float translateX = float(win.left) / bufferWidth; |
| 1231 | |
| 1232 | // Flip y-coordinates because GLConsumer expects OpenGL convention. |
| 1233 | mat4 tr = mat4::translate(vec4(.5f, .5f, 0.f, 1.f)) * mat4::scale(vec4(1.f, -1.f, 1.f, 1.f)) * |
| 1234 | mat4::translate(vec4(-.5f, -.5f, 0.f, 1.f)) * |
| 1235 | mat4::translate(vec4(translateX, translateY, 0.f, 1.f)) * |
| 1236 | mat4::scale(vec4(scaleWidth, scaleHeight, 1.0f, 1.0f)); |
| 1237 | |
| 1238 | layer.source.buffer.useTextureFiltering = useFiltering; |
| 1239 | layer.source.buffer.textureTransform = mat4(static_cast<const float*>(textureMatrix)) * tr; |
| 1240 | |
| 1241 | return layer; |
| 1242 | } |
| 1243 | |
| 1244 | bool BufferStateLayer::isHdrY410() const { |
| 1245 | // pixel format is HDR Y410 masquerading as RGBA_1010102 |
| 1246 | return (mBufferInfo.mDataspace == ui::Dataspace::BT2020_ITU_PQ && |
| 1247 | mBufferInfo.mApi == NATIVE_WINDOW_API_MEDIA && |
| 1248 | mBufferInfo.mPixelFormat == HAL_PIXEL_FORMAT_RGBA_1010102); |
| 1249 | } |
| 1250 | |
| 1251 | sp<compositionengine::LayerFE> BufferStateLayer::getCompositionEngineLayerFE() const { |
| 1252 | return asLayerFE(); |
| 1253 | } |
| 1254 | |
| 1255 | compositionengine::LayerFECompositionState* BufferStateLayer::editCompositionState() { |
| 1256 | return mCompositionState.get(); |
| 1257 | } |
| 1258 | |
| 1259 | const compositionengine::LayerFECompositionState* BufferStateLayer::getCompositionState() const { |
| 1260 | return mCompositionState.get(); |
| 1261 | } |
| 1262 | |
| 1263 | void BufferStateLayer::preparePerFrameCompositionState() { |
| 1264 | Layer::preparePerFrameCompositionState(); |
| 1265 | |
| 1266 | // Sideband layers |
| 1267 | auto* compositionState = editCompositionState(); |
| 1268 | if (compositionState->sidebandStream.get() && !compositionState->sidebandStreamHasFrame) { |
| 1269 | compositionState->compositionType = |
| 1270 | aidl::android::hardware::graphics::composer3::Composition::SIDEBAND; |
| 1271 | return; |
| 1272 | } else if ((mDrawingState.flags & layer_state_t::eLayerIsDisplayDecoration) != 0) { |
| 1273 | compositionState->compositionType = |
| 1274 | aidl::android::hardware::graphics::composer3::Composition::DISPLAY_DECORATION; |
| 1275 | } else { |
| 1276 | // Normal buffer layers |
| 1277 | compositionState->hdrMetadata = mBufferInfo.mHdrMetadata; |
| 1278 | compositionState->compositionType = mPotentialCursor |
| 1279 | ? aidl::android::hardware::graphics::composer3::Composition::CURSOR |
| 1280 | : aidl::android::hardware::graphics::composer3::Composition::DEVICE; |
| 1281 | } |
| 1282 | |
| 1283 | compositionState->buffer = getBuffer(); |
| 1284 | compositionState->bufferSlot = (mBufferInfo.mBufferSlot == BufferQueue::INVALID_BUFFER_SLOT) |
| 1285 | ? 0 |
| 1286 | : mBufferInfo.mBufferSlot; |
| 1287 | compositionState->acquireFence = mBufferInfo.mFence; |
| 1288 | compositionState->frameNumber = mBufferInfo.mFrameNumber; |
| 1289 | compositionState->sidebandStreamHasFrame = false; |
| 1290 | } |
| 1291 | |
Vishnu Nair | a72f6c0 | 2022-07-01 05:33:08 +0000 | [diff] [blame] | 1292 | void BufferStateLayer::onPostComposition(const DisplayDevice* display, |
| 1293 | const std::shared_ptr<FenceTime>& glDoneFence, |
| 1294 | const std::shared_ptr<FenceTime>& presentFence, |
| 1295 | const CompositorTiming& compositorTiming) { |
| 1296 | // mFrameLatencyNeeded is true when a new frame was latched for the |
| 1297 | // composition. |
| 1298 | if (!mBufferInfo.mFrameLatencyNeeded) return; |
| 1299 | |
Vishnu Nair | 397a0e3 | 2022-07-26 00:01:48 +0000 | [diff] [blame] | 1300 | for (const auto& handle : mDrawingState.callbackHandles) { |
| 1301 | handle->gpuCompositionDoneFence = glDoneFence; |
| 1302 | handle->compositorTiming = compositorTiming; |
| 1303 | } |
Vishnu Nair | a72f6c0 | 2022-07-01 05:33:08 +0000 | [diff] [blame] | 1304 | |
| 1305 | // Update mFrameTracker. |
| 1306 | nsecs_t desiredPresentTime = mBufferInfo.mDesiredPresentTime; |
| 1307 | mFrameTracker.setDesiredPresentTime(desiredPresentTime); |
| 1308 | |
| 1309 | const int32_t layerId = getSequence(); |
| 1310 | mFlinger->mTimeStats->setDesiredTime(layerId, mCurrentFrameNumber, desiredPresentTime); |
| 1311 | |
| 1312 | const auto outputLayer = findOutputLayerForDisplay(display); |
| 1313 | if (outputLayer && outputLayer->requiresClientComposition()) { |
| 1314 | nsecs_t clientCompositionTimestamp = outputLayer->getState().clientCompositionTimestamp; |
| 1315 | mFlinger->mFrameTracer->traceTimestamp(layerId, getCurrentBufferId(), mCurrentFrameNumber, |
| 1316 | clientCompositionTimestamp, |
| 1317 | FrameTracer::FrameEvent::FALLBACK_COMPOSITION); |
| 1318 | // Update the SurfaceFrames in the drawing state |
| 1319 | if (mDrawingState.bufferSurfaceFrameTX) { |
| 1320 | mDrawingState.bufferSurfaceFrameTX->setGpuComposition(); |
| 1321 | } |
| 1322 | for (auto& [token, surfaceFrame] : mDrawingState.bufferlessSurfaceFramesTX) { |
| 1323 | surfaceFrame->setGpuComposition(); |
| 1324 | } |
| 1325 | } |
| 1326 | |
| 1327 | std::shared_ptr<FenceTime> frameReadyFence = mBufferInfo.mFenceTime; |
| 1328 | if (frameReadyFence->isValid()) { |
| 1329 | mFrameTracker.setFrameReadyFence(std::move(frameReadyFence)); |
| 1330 | } else { |
| 1331 | // There was no fence for this frame, so assume that it was ready |
| 1332 | // to be presented at the desired present time. |
| 1333 | mFrameTracker.setFrameReadyTime(desiredPresentTime); |
| 1334 | } |
| 1335 | |
| 1336 | if (display) { |
| 1337 | const Fps refreshRate = display->refreshRateConfigs().getActiveMode()->getFps(); |
| 1338 | const std::optional<Fps> renderRate = |
| 1339 | mFlinger->mScheduler->getFrameRateOverride(getOwnerUid()); |
| 1340 | |
| 1341 | const auto vote = frameRateToSetFrameRateVotePayload(mDrawingState.frameRate); |
| 1342 | const auto gameMode = getGameMode(); |
| 1343 | |
| 1344 | if (presentFence->isValid()) { |
| 1345 | mFlinger->mTimeStats->setPresentFence(layerId, mCurrentFrameNumber, presentFence, |
| 1346 | refreshRate, renderRate, vote, gameMode); |
| 1347 | mFlinger->mFrameTracer->traceFence(layerId, getCurrentBufferId(), mCurrentFrameNumber, |
| 1348 | presentFence, |
| 1349 | FrameTracer::FrameEvent::PRESENT_FENCE); |
| 1350 | mFrameTracker.setActualPresentFence(std::shared_ptr<FenceTime>(presentFence)); |
| 1351 | } else if (const auto displayId = PhysicalDisplayId::tryCast(display->getId()); |
| 1352 | displayId && mFlinger->getHwComposer().isConnected(*displayId)) { |
| 1353 | // The HWC doesn't support present fences, so use the refresh |
| 1354 | // timestamp instead. |
| 1355 | const nsecs_t actualPresentTime = display->getRefreshTimestamp(); |
| 1356 | mFlinger->mTimeStats->setPresentTime(layerId, mCurrentFrameNumber, actualPresentTime, |
| 1357 | refreshRate, renderRate, vote, gameMode); |
| 1358 | mFlinger->mFrameTracer->traceTimestamp(layerId, getCurrentBufferId(), |
| 1359 | mCurrentFrameNumber, actualPresentTime, |
| 1360 | FrameTracer::FrameEvent::PRESENT_FENCE); |
| 1361 | mFrameTracker.setActualPresentTime(actualPresentTime); |
| 1362 | } |
| 1363 | } |
| 1364 | |
| 1365 | mFrameTracker.advanceFrame(); |
| 1366 | mBufferInfo.mFrameLatencyNeeded = false; |
| 1367 | } |
| 1368 | |
Vishnu Nair | 397a0e3 | 2022-07-26 00:01:48 +0000 | [diff] [blame] | 1369 | bool BufferStateLayer::latchBuffer(bool& recomputeVisibleRegions, nsecs_t latchTime) { |
Vishnu Nair | a72f6c0 | 2022-07-01 05:33:08 +0000 | [diff] [blame] | 1370 | ATRACE_FORMAT_INSTANT("latchBuffer %s - %" PRIu64, getDebugName(), |
| 1371 | getDrawingState().frameNumber); |
| 1372 | |
| 1373 | bool refreshRequired = latchSidebandStream(recomputeVisibleRegions); |
| 1374 | |
| 1375 | if (refreshRequired) { |
| 1376 | return refreshRequired; |
| 1377 | } |
| 1378 | |
| 1379 | // If the head buffer's acquire fence hasn't signaled yet, return and |
| 1380 | // try again later |
| 1381 | if (!fenceHasSignaled()) { |
| 1382 | ATRACE_NAME("!fenceHasSignaled()"); |
| 1383 | mFlinger->onLayerUpdate(); |
| 1384 | return false; |
| 1385 | } |
| 1386 | |
Vishnu Nair | 397a0e3 | 2022-07-26 00:01:48 +0000 | [diff] [blame] | 1387 | updateTexImage(latchTime); |
| 1388 | if (mDrawingState.buffer == nullptr) { |
| 1389 | return false; |
| 1390 | } |
| 1391 | |
Vishnu Nair | a72f6c0 | 2022-07-01 05:33:08 +0000 | [diff] [blame] | 1392 | // Capture the old state of the layer for comparisons later |
Vishnu Nair | a72f6c0 | 2022-07-01 05:33:08 +0000 | [diff] [blame] | 1393 | BufferInfo oldBufferInfo = mBufferInfo; |
Vishnu Nair | 397a0e3 | 2022-07-26 00:01:48 +0000 | [diff] [blame] | 1394 | const bool oldOpacity = isOpaque(mDrawingState); |
| 1395 | mPreviousFrameNumber = mCurrentFrameNumber; |
| 1396 | mCurrentFrameNumber = mDrawingState.frameNumber; |
Vishnu Nair | a72f6c0 | 2022-07-01 05:33:08 +0000 | [diff] [blame] | 1397 | gatherBufferInfo(); |
| 1398 | |
| 1399 | if (oldBufferInfo.mBuffer == nullptr) { |
| 1400 | // the first time we receive a buffer, we need to trigger a |
| 1401 | // geometry invalidation. |
| 1402 | recomputeVisibleRegions = true; |
| 1403 | } |
| 1404 | |
| 1405 | if ((mBufferInfo.mCrop != oldBufferInfo.mCrop) || |
| 1406 | (mBufferInfo.mTransform != oldBufferInfo.mTransform) || |
| 1407 | (mBufferInfo.mScaleMode != oldBufferInfo.mScaleMode) || |
| 1408 | (mBufferInfo.mTransformToDisplayInverse != oldBufferInfo.mTransformToDisplayInverse)) { |
| 1409 | recomputeVisibleRegions = true; |
| 1410 | } |
| 1411 | |
| 1412 | if (oldBufferInfo.mBuffer != nullptr) { |
| 1413 | uint32_t bufWidth = mBufferInfo.mBuffer->getWidth(); |
| 1414 | uint32_t bufHeight = mBufferInfo.mBuffer->getHeight(); |
| 1415 | if (bufWidth != oldBufferInfo.mBuffer->getWidth() || |
| 1416 | bufHeight != oldBufferInfo.mBuffer->getHeight()) { |
| 1417 | recomputeVisibleRegions = true; |
| 1418 | } |
| 1419 | } |
| 1420 | |
Vishnu Nair | 397a0e3 | 2022-07-26 00:01:48 +0000 | [diff] [blame] | 1421 | if (oldOpacity != isOpaque(mDrawingState)) { |
Vishnu Nair | a72f6c0 | 2022-07-01 05:33:08 +0000 | [diff] [blame] | 1422 | recomputeVisibleRegions = true; |
| 1423 | } |
| 1424 | |
| 1425 | return true; |
| 1426 | } |
| 1427 | |
| 1428 | bool BufferStateLayer::hasReadyFrame() const { |
| 1429 | return hasFrameUpdate() || getSidebandStreamChanged() || getAutoRefresh(); |
| 1430 | } |
| 1431 | |
| 1432 | bool BufferStateLayer::isProtected() const { |
| 1433 | return (mBufferInfo.mBuffer != nullptr) && |
| 1434 | (mBufferInfo.mBuffer->getUsage() & GRALLOC_USAGE_PROTECTED); |
| 1435 | } |
| 1436 | |
| 1437 | // As documented in libhardware header, formats in the range |
| 1438 | // 0x100 - 0x1FF are specific to the HAL implementation, and |
| 1439 | // are known to have no alpha channel |
| 1440 | // TODO: move definition for device-specific range into |
| 1441 | // hardware.h, instead of using hard-coded values here. |
| 1442 | #define HARDWARE_IS_DEVICE_FORMAT(f) ((f) >= 0x100 && (f) <= 0x1FF) |
| 1443 | |
| 1444 | bool BufferStateLayer::getOpacityForFormat(PixelFormat format) { |
| 1445 | if (HARDWARE_IS_DEVICE_FORMAT(format)) { |
| 1446 | return true; |
| 1447 | } |
| 1448 | switch (format) { |
| 1449 | case PIXEL_FORMAT_RGBA_8888: |
| 1450 | case PIXEL_FORMAT_BGRA_8888: |
| 1451 | case PIXEL_FORMAT_RGBA_FP16: |
| 1452 | case PIXEL_FORMAT_RGBA_1010102: |
| 1453 | case PIXEL_FORMAT_R_8: |
| 1454 | return false; |
| 1455 | } |
| 1456 | // in all other case, we have no blending (also for unknown formats) |
| 1457 | return true; |
| 1458 | } |
| 1459 | |
| 1460 | bool BufferStateLayer::needsFiltering(const DisplayDevice* display) const { |
| 1461 | const auto outputLayer = findOutputLayerForDisplay(display); |
| 1462 | if (outputLayer == nullptr) { |
| 1463 | return false; |
| 1464 | } |
| 1465 | |
| 1466 | // We need filtering if the sourceCrop rectangle size does not match the |
| 1467 | // displayframe rectangle size (not a 1:1 render) |
| 1468 | const auto& compositionState = outputLayer->getState(); |
| 1469 | const auto displayFrame = compositionState.displayFrame; |
| 1470 | const auto sourceCrop = compositionState.sourceCrop; |
| 1471 | return sourceCrop.getHeight() != displayFrame.getHeight() || |
| 1472 | sourceCrop.getWidth() != displayFrame.getWidth(); |
| 1473 | } |
| 1474 | |
| 1475 | bool BufferStateLayer::needsFilteringForScreenshots( |
| 1476 | const DisplayDevice* display, const ui::Transform& inverseParentTransform) const { |
| 1477 | const auto outputLayer = findOutputLayerForDisplay(display); |
| 1478 | if (outputLayer == nullptr) { |
| 1479 | return false; |
| 1480 | } |
| 1481 | |
| 1482 | // We need filtering if the sourceCrop rectangle size does not match the |
| 1483 | // viewport rectangle size (not a 1:1 render) |
| 1484 | const auto& compositionState = outputLayer->getState(); |
| 1485 | const ui::Transform& displayTransform = display->getTransform(); |
| 1486 | const ui::Transform inverseTransform = inverseParentTransform * displayTransform.inverse(); |
| 1487 | // Undo the transformation of the displayFrame so that we're back into |
| 1488 | // layer-stack space. |
| 1489 | const Rect frame = inverseTransform.transform(compositionState.displayFrame); |
| 1490 | const FloatRect sourceCrop = compositionState.sourceCrop; |
| 1491 | |
| 1492 | int32_t frameHeight = frame.getHeight(); |
| 1493 | int32_t frameWidth = frame.getWidth(); |
| 1494 | // If the display transform had a rotational component then undo the |
| 1495 | // rotation so that the orientation matches the source crop. |
| 1496 | if (displayTransform.getOrientation() & ui::Transform::ROT_90) { |
| 1497 | std::swap(frameHeight, frameWidth); |
| 1498 | } |
| 1499 | return sourceCrop.getHeight() != frameHeight || sourceCrop.getWidth() != frameWidth; |
| 1500 | } |
| 1501 | |
| 1502 | void BufferStateLayer::latchAndReleaseBuffer() { |
| 1503 | if (hasReadyFrame()) { |
| 1504 | bool ignored = false; |
Vishnu Nair | 397a0e3 | 2022-07-26 00:01:48 +0000 | [diff] [blame] | 1505 | latchBuffer(ignored, systemTime()); |
Vishnu Nair | a72f6c0 | 2022-07-01 05:33:08 +0000 | [diff] [blame] | 1506 | } |
| 1507 | releasePendingBuffer(systemTime()); |
| 1508 | } |
| 1509 | |
| 1510 | PixelFormat BufferStateLayer::getPixelFormat() const { |
| 1511 | return mBufferInfo.mPixelFormat; |
| 1512 | } |
| 1513 | |
| 1514 | bool BufferStateLayer::getTransformToDisplayInverse() const { |
| 1515 | return mBufferInfo.mTransformToDisplayInverse; |
| 1516 | } |
| 1517 | |
| 1518 | Rect BufferStateLayer::getBufferCrop() const { |
| 1519 | // this is the crop rectangle that applies to the buffer |
| 1520 | // itself (as opposed to the window) |
| 1521 | if (!mBufferInfo.mCrop.isEmpty()) { |
| 1522 | // if the buffer crop is defined, we use that |
| 1523 | return mBufferInfo.mCrop; |
| 1524 | } else if (mBufferInfo.mBuffer != nullptr) { |
| 1525 | // otherwise we use the whole buffer |
| 1526 | return mBufferInfo.mBuffer->getBounds(); |
| 1527 | } else { |
| 1528 | // if we don't have a buffer yet, we use an empty/invalid crop |
| 1529 | return Rect(); |
| 1530 | } |
| 1531 | } |
| 1532 | |
| 1533 | uint32_t BufferStateLayer::getBufferTransform() const { |
| 1534 | return mBufferInfo.mTransform; |
| 1535 | } |
| 1536 | |
| 1537 | ui::Dataspace BufferStateLayer::getDataSpace() const { |
| 1538 | return mBufferInfo.mDataspace; |
| 1539 | } |
| 1540 | |
| 1541 | ui::Dataspace BufferStateLayer::translateDataspace(ui::Dataspace dataspace) { |
| 1542 | ui::Dataspace updatedDataspace = dataspace; |
| 1543 | // translate legacy dataspaces to modern dataspaces |
| 1544 | switch (dataspace) { |
| 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> BufferStateLayer::getBuffer() const { |
| 1571 | return mBufferInfo.mBuffer ? mBufferInfo.mBuffer->getBuffer() : nullptr; |
| 1572 | } |
| 1573 | |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 1574 | void BufferStateLayer::getDrawingTransformMatrix(bool filteringEnabled, float outMatrix[16]) const { |
Vishnu Nair | a72f6c0 | 2022-07-01 05:33:08 +0000 | [diff] [blame] | 1575 | sp<GraphicBuffer> buffer = getBuffer(); |
| 1576 | if (!buffer) { |
| 1577 | ALOGE("Buffer should not be null!"); |
| 1578 | return; |
| 1579 | } |
| 1580 | GLConsumer::computeTransformMatrix(outMatrix, buffer->getWidth(), buffer->getHeight(), |
| 1581 | buffer->getPixelFormat(), mBufferInfo.mCrop, |
| 1582 | mBufferInfo.mTransform, filteringEnabled); |
| 1583 | } |
| 1584 | |
| 1585 | void BufferStateLayer::setInitialValuesForClone(const sp<Layer>& clonedFrom) { |
| 1586 | Layer::setInitialValuesForClone(clonedFrom); |
| 1587 | |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 1588 | sp<BufferStateLayer> bufferClonedFrom = |
| 1589 | sp<BufferStateLayer>::fromExisting(static_cast<BufferStateLayer*>(clonedFrom.get())); |
Vishnu Nair | a72f6c0 | 2022-07-01 05:33:08 +0000 | [diff] [blame] | 1590 | mPremultipliedAlpha = bufferClonedFrom->mPremultipliedAlpha; |
| 1591 | mPotentialCursor = bufferClonedFrom->mPotentialCursor; |
| 1592 | mProtectedByApp = bufferClonedFrom->mProtectedByApp; |
| 1593 | |
| 1594 | updateCloneBufferInfo(); |
| 1595 | } |
| 1596 | |
| 1597 | void BufferStateLayer::updateCloneBufferInfo() { |
| 1598 | if (!isClone() || !isClonedFromAlive()) { |
| 1599 | return; |
| 1600 | } |
| 1601 | |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 1602 | sp<BufferStateLayer> clonedFrom = sp<BufferStateLayer>::fromExisting( |
| 1603 | static_cast<BufferStateLayer*>(getClonedFrom().get())); |
Vishnu Nair | a72f6c0 | 2022-07-01 05:33:08 +0000 | [diff] [blame] | 1604 | mBufferInfo = clonedFrom->mBufferInfo; |
| 1605 | mSidebandStream = clonedFrom->mSidebandStream; |
| 1606 | surfaceDamageRegion = clonedFrom->surfaceDamageRegion; |
| 1607 | mCurrentFrameNumber = clonedFrom->mCurrentFrameNumber.load(); |
| 1608 | mPreviousFrameNumber = clonedFrom->mPreviousFrameNumber; |
| 1609 | |
| 1610 | // After buffer info is updated, the drawingState from the real layer needs to be copied into |
| 1611 | // the cloned. This is because some properties of drawingState can change when latchBuffer is |
| 1612 | // called. However, copying the drawingState would also overwrite the cloned layer's relatives |
| 1613 | // and touchableRegionCrop. Therefore, temporarily store the relatives so they can be set in |
| 1614 | // the cloned drawingState again. |
| 1615 | wp<Layer> tmpZOrderRelativeOf = mDrawingState.zOrderRelativeOf; |
| 1616 | SortedVector<wp<Layer>> tmpZOrderRelatives = mDrawingState.zOrderRelatives; |
| 1617 | wp<Layer> tmpTouchableRegionCrop = mDrawingState.touchableRegionCrop; |
| 1618 | WindowInfo tmpInputInfo = mDrawingState.inputInfo; |
| 1619 | |
| 1620 | cloneDrawingState(clonedFrom.get()); |
| 1621 | |
| 1622 | mDrawingState.touchableRegionCrop = tmpTouchableRegionCrop; |
| 1623 | mDrawingState.zOrderRelativeOf = tmpZOrderRelativeOf; |
| 1624 | mDrawingState.zOrderRelatives = tmpZOrderRelatives; |
| 1625 | mDrawingState.inputInfo = tmpInputInfo; |
| 1626 | } |
| 1627 | |
| 1628 | void BufferStateLayer::setTransformHint(ui::Transform::RotationFlags displayTransformHint) { |
| 1629 | mTransformHint = getFixedTransformHint(); |
| 1630 | if (mTransformHint == ui::Transform::ROT_INVALID) { |
| 1631 | mTransformHint = displayTransformHint; |
| 1632 | } |
| 1633 | } |
| 1634 | |
| 1635 | const std::shared_ptr<renderengine::ExternalTexture>& BufferStateLayer::getExternalTexture() const { |
| 1636 | return mBufferInfo.mBuffer; |
| 1637 | } |
| 1638 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1639 | } // namespace android |