blob: 494b61c51c450890515f4d13a59706539f92f2d3 [file] [log] [blame]
David Sodman0c69cad2017-08-21 12:12:51 -07001/*
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
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -080017// TODO(b/129481165): remove the #pragma below and fix conversion issues
18#pragma clang diagnostic push
19#pragma clang diagnostic ignored "-Wconversion"
20
David Sodman0c69cad2017-08-21 12:12:51 -070021//#define LOG_NDEBUG 0
22#undef LOG_TAG
23#define LOG_TAG "BufferLayer"
24#define ATRACE_TAG ATRACE_TAG_GRAPHICS
25
Alec Mourie60041e2019-06-14 18:59:51 -070026#include "BufferLayer.h"
Lloyd Piquefeb73d72018-12-04 17:23:44 -080027
28#include <compositionengine/CompositionEngine.h>
Lloyd Piquef5275482019-01-29 18:42:42 -080029#include <compositionengine/LayerFECompositionState.h>
Lloyd Pique37c2c9b2018-12-04 17:25:10 -080030#include <compositionengine/OutputLayer.h>
31#include <compositionengine/impl/OutputLayerCompositionState.h>
Lloyd Piquefeb73d72018-12-04 17:23:44 -080032#include <cutils/compiler.h>
33#include <cutils/native_handle.h>
34#include <cutils/properties.h>
35#include <gui/BufferItem.h>
36#include <gui/BufferQueue.h>
chaviwf83ce182019-09-12 14:43:08 -070037#include <gui/GLConsumer.h>
Lloyd Piquefeb73d72018-12-04 17:23:44 -080038#include <gui/LayerDebugInfo.h>
39#include <gui/Surface.h>
40#include <renderengine/RenderEngine.h>
41#include <ui/DebugUtils.h>
42#include <utils/Errors.h>
43#include <utils/Log.h>
44#include <utils/NativeHandle.h>
45#include <utils/StopWatch.h>
46#include <utils/Trace.h>
47
Alec Mourie60041e2019-06-14 18:59:51 -070048#include <cmath>
49#include <cstdlib>
50#include <mutex>
51#include <sstream>
52
David Sodman0c69cad2017-08-21 12:12:51 -070053#include "Colorizer.h"
54#include "DisplayDevice.h"
Mikael Pessa90092f42019-08-26 17:22:04 -070055#include "FrameTracer/FrameTracer.h"
David Sodman0c69cad2017-08-21 12:12:51 -070056#include "LayerRejecter.h"
Yiwei Zhang7e666a52018-11-15 13:33:42 -080057#include "TimeStats/TimeStats.h"
58
David Sodman0c69cad2017-08-21 12:12:51 -070059namespace android {
60
chaviw3277faf2021-05-19 16:45:23 -050061using gui::WindowInfo;
62
John Reckac09e452021-04-07 16:35:37 -040063static constexpr float defaultMaxLuminance = 1000.0;
Peiyong Lin1a70eca2019-11-15 09:33:33 -080064
Lloyd Pique42ab75e2018-09-12 20:46:03 -070065BufferLayer::BufferLayer(const LayerCreationArgs& args)
Lloyd Piquefeb73d72018-12-04 17:23:44 -080066 : Layer(args),
chaviwb4c6e582019-08-16 14:35:07 -070067 mTextureName(args.textureName),
Lloyd Piquede196652020-01-22 17:29:58 -080068 mCompositionState{mFlinger->getCompositionEngine().createLayerFECompositionState()} {
Dominik Laskowski87a07e42019-10-10 20:38:02 -070069 ALOGV("Creating Layer %s", getDebugName());
David Sodman0c69cad2017-08-21 12:12:51 -070070
Lloyd Pique42ab75e2018-09-12 20:46:03 -070071 mPremultipliedAlpha = !(args.flags & ISurfaceComposerClient::eNonPremultiplied);
David Sodman0c69cad2017-08-21 12:12:51 -070072
Lloyd Pique42ab75e2018-09-12 20:46:03 -070073 mPotentialCursor = args.flags & ISurfaceComposerClient::eCursorWindow;
74 mProtectedByApp = args.flags & ISurfaceComposerClient::eProtectedByApp;
David Sodman0c69cad2017-08-21 12:12:51 -070075}
76
77BufferLayer::~BufferLayer() {
chaviwb4c6e582019-08-16 14:35:07 -070078 if (!isClone()) {
79 // The original layer and the clone layer share the same texture. Therefore, only one of
80 // the layers, in this case the original layer, needs to handle the deletion. The original
81 // layer and the clone should be removed at the same time so there shouldn't be any issue
82 // with the clone layer trying to use the deleted texture.
83 mFlinger->deleteTextureAsync(mTextureName);
84 }
Yiwei Zhang1a88c402019-11-18 10:43:58 -080085 const int32_t layerId = getSequence();
86 mFlinger->mTimeStats->onDestroy(layerId);
87 mFlinger->mFrameTracer->onDestroy(layerId);
David Sodman0c69cad2017-08-21 12:12:51 -070088}
89
David Sodmaneb085e02017-10-05 18:49:04 -070090void BufferLayer::useSurfaceDamage() {
91 if (mFlinger->mForceFullDamage) {
92 surfaceDamageRegion = Region::INVALID_REGION;
93 } else {
chaviw4244e032019-09-04 11:27:49 -070094 surfaceDamageRegion = mBufferInfo.mSurfaceDamage;
David Sodmaneb085e02017-10-05 18:49:04 -070095 }
96}
97
98void BufferLayer::useEmptyDamage() {
99 surfaceDamageRegion.clear();
100}
101
Marissa Wallfd668622018-05-10 10:21:13 -0700102bool BufferLayer::isOpaque(const Layer::State& s) const {
103 // if we don't have a buffer or sidebandStream yet, we're translucent regardless of the
104 // layer's opaque flag.
chaviwd62d3062019-09-04 14:48:02 -0700105 if ((mSidebandStream == nullptr) && (mBufferInfo.mBuffer == nullptr)) {
Marissa Wallfd668622018-05-10 10:21:13 -0700106 return false;
107 }
108
109 // if the layer has the opaque flag, then we're always opaque,
110 // otherwise we use the current buffer's format.
111 return ((s.flags & layer_state_t::eLayerOpaque) != 0) || getOpacityForFormat(getPixelFormat());
David Sodman0c69cad2017-08-21 12:12:51 -0700112}
113
Arthur Hungfb2ebce2021-10-04 14:08:48 +0000114bool BufferLayer::canReceiveInput() const {
115 return !isHiddenByPolicy() && (mBufferInfo.mBuffer == nullptr || getAlpha() > 0.0f);
116}
117
David Sodman0c69cad2017-08-21 12:12:51 -0700118bool BufferLayer::isVisible() const {
Dominik Laskowskif7a09ed2019-10-07 13:54:18 -0700119 return !isHiddenByPolicy() && getAlpha() > 0.0f &&
chaviwd62d3062019-09-04 14:48:02 -0700120 (mBufferInfo.mBuffer != nullptr || mSidebandStream != nullptr);
David Sodman0c69cad2017-08-21 12:12:51 -0700121}
122
123bool BufferLayer::isFixedSize() const {
124 return getEffectiveScalingMode() != NATIVE_WINDOW_SCALING_MODE_FREEZE;
125}
126
Lloyd Piquea83776c2019-01-29 18:42:32 -0800127bool BufferLayer::usesSourceCrop() const {
128 return true;
129}
130
David Sodman0c69cad2017-08-21 12:12:51 -0700131static constexpr mat4 inverseOrientation(uint32_t transform) {
David Sodman41fdfc92017-11-06 16:09:56 -0800132 const mat4 flipH(-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1);
133 const mat4 flipV(1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1);
134 const mat4 rot90(0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1);
David Sodman0c69cad2017-08-21 12:12:51 -0700135 mat4 tr;
136
137 if (transform & NATIVE_WINDOW_TRANSFORM_ROT_90) {
138 tr = tr * rot90;
139 }
140 if (transform & NATIVE_WINDOW_TRANSFORM_FLIP_H) {
141 tr = tr * flipH;
142 }
143 if (transform & NATIVE_WINDOW_TRANSFORM_FLIP_V) {
144 tr = tr * flipV;
145 }
146 return inverse(tr);
147}
148
Vishnu Nair9b079a22020-01-21 14:36:08 -0800149std::optional<compositionengine::LayerFE::LayerSettings> BufferLayer::prepareClientComposition(
Lloyd Piquef16688f2019-02-19 17:47:57 -0800150 compositionengine::LayerFE::ClientCompositionTargetSettings& targetSettings) {
David Sodman0c69cad2017-08-21 12:12:51 -0700151 ATRACE_CALL();
Lloyd Piquef16688f2019-02-19 17:47:57 -0800152
Vishnu Nair9b079a22020-01-21 14:36:08 -0800153 std::optional<compositionengine::LayerFE::LayerSettings> result =
154 Layer::prepareClientComposition(targetSettings);
Lloyd Piquef16688f2019-02-19 17:47:57 -0800155 if (!result) {
156 return result;
157 }
158
Sally Qidf3da512021-07-08 17:27:02 +0000159 if (CC_UNLIKELY(mBufferInfo.mBuffer == 0) && mSidebandStream != nullptr) {
160 // For surfaceview of tv sideband, there is no activeBuffer
161 // in bufferqueue, we need return LayerSettings.
162 return result;
David Sodman0c69cad2017-08-21 12:12:51 -0700163 }
Ady Abraham7a60afb2021-03-29 13:20:55 -0700164 const bool blackOutLayer = (isProtected() && !targetSettings.supportsProtectedContent) ||
yuhui.zhanga102ff92021-04-09 14:45:51 +0800165 ((isSecure() || isProtected()) && !targetSettings.isSecure);
Ady Abraham7a60afb2021-03-29 13:20:55 -0700166 const bool bufferCanBeUsedAsHwTexture =
Alec Mouria90a5702021-04-16 16:36:21 +0000167 mBufferInfo.mBuffer->getBuffer()->getUsage() & GraphicBuffer::USAGE_HW_TEXTURE;
Lloyd Piquede196652020-01-22 17:29:58 -0800168 compositionengine::LayerFE::LayerSettings& layer = *result;
Ady Abraham7a60afb2021-03-29 13:20:55 -0700169 if (blackOutLayer || !bufferCanBeUsedAsHwTexture) {
170 ALOGE_IF(!bufferCanBeUsedAsHwTexture, "%s is blacked out as buffer is not gpu readable",
171 mName.c_str());
Vishnu Nairb87d94f2020-02-13 09:17:36 -0800172 prepareClearClientComposition(layer, true /* blackout */);
173 return layer;
David Sodman0c69cad2017-08-21 12:12:51 -0700174 }
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000175
Vishnu Nairb87d94f2020-02-13 09:17:36 -0800176 const State& s(getDrawingState());
177 layer.source.buffer.buffer = mBufferInfo.mBuffer;
178 layer.source.buffer.isOpaque = isOpaque(s);
179 layer.source.buffer.fence = mBufferInfo.mFence;
180 layer.source.buffer.textureName = mTextureName;
181 layer.source.buffer.usePremultipliedAlpha = getPremultipledAlpha();
182 layer.source.buffer.isY410BT2020 = isHdrY410();
183 bool hasSmpte2086 = mBufferInfo.mHdrMetadata.validTypes & HdrMetadata::SMPTE2086;
184 bool hasCta861_3 = mBufferInfo.mHdrMetadata.validTypes & HdrMetadata::CTA861_3;
John Reckac09e452021-04-07 16:35:37 -0400185 float maxLuminance = 0.f;
186 if (hasSmpte2086 && hasCta861_3) {
187 maxLuminance = std::min(mBufferInfo.mHdrMetadata.smpte2086.maxLuminance,
188 mBufferInfo.mHdrMetadata.cta8613.maxContentLightLevel);
189 } else if (hasSmpte2086) {
190 maxLuminance = mBufferInfo.mHdrMetadata.smpte2086.maxLuminance;
191 } else if (hasCta861_3) {
192 maxLuminance = mBufferInfo.mHdrMetadata.cta8613.maxContentLightLevel;
193 } else {
194 switch (layer.sourceDataspace & HAL_DATASPACE_TRANSFER_MASK) {
195 case HAL_DATASPACE_TRANSFER_ST2084:
196 case HAL_DATASPACE_TRANSFER_HLG:
197 // Behavior-match previous releases for HDR content
198 maxLuminance = defaultMaxLuminance;
199 break;
200 }
201 }
202 layer.source.buffer.maxLuminanceNits = maxLuminance;
Vishnu Nairb87d94f2020-02-13 09:17:36 -0800203 layer.frameNumber = mCurrentFrameNumber;
Alec Mouria90a5702021-04-16 16:36:21 +0000204 layer.bufferId = mBufferInfo.mBuffer ? mBufferInfo.mBuffer->getBuffer()->getId() : 0;
Vishnu Nairb87d94f2020-02-13 09:17:36 -0800205
Vishnu Naire7f79c52020-10-29 14:45:03 -0700206 const bool useFiltering =
207 targetSettings.needsFiltering || mNeedsFiltering || bufferNeedsFiltering();
Vishnu Nairb87d94f2020-02-13 09:17:36 -0800208
209 // Query the texture matrix given our current filtering mode.
210 float textureMatrix[16];
211 getDrawingTransformMatrix(useFiltering, textureMatrix);
212
213 if (getTransformToDisplayInverse()) {
214 /*
215 * the code below applies the primary display's inverse transform to
216 * the texture transform
217 */
218 uint32_t transform = DisplayDevice::getPrimaryDisplayRotationFlags();
219 mat4 tr = inverseOrientation(transform);
220
221 /**
222 * TODO(b/36727915): This is basically a hack.
223 *
224 * Ensure that regardless of the parent transformation,
225 * this buffer is always transformed from native display
226 * orientation to display orientation. For example, in the case
227 * of a camera where the buffer remains in native orientation,
228 * we want the pixels to always be upright.
229 */
Rob Carrc6d2d2b2021-10-25 16:51:49 +0000230 sp<Layer> p = mDrawingParent.promote();
Vishnu Nairb87d94f2020-02-13 09:17:36 -0800231 if (p != nullptr) {
232 const auto parentTransform = p->getTransform();
233 tr = tr * inverseOrientation(parentTransform.getOrientation());
234 }
235
236 // and finally apply it to the original texture matrix
237 const mat4 texTransform(mat4(static_cast<const float*>(textureMatrix)) * tr);
238 memcpy(textureMatrix, texTransform.asArray(), sizeof(textureMatrix));
239 }
240
241 const Rect win{getBounds()};
242 float bufferWidth = getBufferSize(s).getWidth();
243 float bufferHeight = getBufferSize(s).getHeight();
244
245 // BufferStateLayers can have a "buffer size" of [0, 0, -1, -1] when no display frame has
246 // been set and there is no parent layer bounds. In that case, the scale is meaningless so
247 // ignore them.
248 if (!getBufferSize(s).isValid()) {
249 bufferWidth = float(win.right) - float(win.left);
250 bufferHeight = float(win.bottom) - float(win.top);
251 }
252
253 const float scaleHeight = (float(win.bottom) - float(win.top)) / bufferHeight;
254 const float scaleWidth = (float(win.right) - float(win.left)) / bufferWidth;
255 const float translateY = float(win.top) / bufferHeight;
256 const float translateX = float(win.left) / bufferWidth;
257
258 // Flip y-coordinates because GLConsumer expects OpenGL convention.
259 mat4 tr = mat4::translate(vec4(.5, .5, 0, 1)) * mat4::scale(vec4(1, -1, 1, 1)) *
260 mat4::translate(vec4(-.5, -.5, 0, 1)) *
261 mat4::translate(vec4(translateX, translateY, 0, 1)) *
262 mat4::scale(vec4(scaleWidth, scaleHeight, 1.0, 1.0));
263
264 layer.source.buffer.useTextureFiltering = useFiltering;
265 layer.source.buffer.textureTransform = mat4(static_cast<const float*>(textureMatrix)) * tr;
266
Vishnu Nair9b079a22020-01-21 14:36:08 -0800267 return layer;
David Sodman0c69cad2017-08-21 12:12:51 -0700268}
269
Marissa Wallfd668622018-05-10 10:21:13 -0700270bool BufferLayer::isHdrY410() const {
271 // pixel format is HDR Y410 masquerading as RGBA_1010102
chaviw4244e032019-09-04 11:27:49 -0700272 return (mBufferInfo.mDataspace == ui::Dataspace::BT2020_ITU_PQ &&
273 mBufferInfo.mApi == NATIVE_WINDOW_API_MEDIA &&
chaviwdebadb82020-03-26 14:57:24 -0700274 mBufferInfo.mPixelFormat == HAL_PIXEL_FORMAT_RGBA_1010102);
David Sodmaneb085e02017-10-05 18:49:04 -0700275}
276
Lloyd Piquede196652020-01-22 17:29:58 -0800277sp<compositionengine::LayerFE> BufferLayer::getCompositionEngineLayerFE() const {
278 return asLayerFE();
279}
280
281compositionengine::LayerFECompositionState* BufferLayer::editCompositionState() {
282 return mCompositionState.get();
283}
284
285const compositionengine::LayerFECompositionState* BufferLayer::getCompositionState() const {
286 return mCompositionState.get();
287}
288
289void BufferLayer::preparePerFrameCompositionState() {
290 Layer::preparePerFrameCompositionState();
David Sodman0c69cad2017-08-21 12:12:51 -0700291
292 // Sideband layers
Lloyd Piquede196652020-01-22 17:29:58 -0800293 auto* compositionState = editCompositionState();
baocheng sun9691b9c2021-08-03 19:27:06 +0800294 if (compositionState->sidebandStream.get() && !compositionState->sidebandStreamHasFrame) {
Lloyd Piquede196652020-01-22 17:29:58 -0800295 compositionState->compositionType = Hwc2::IComposerClient::Composition::SIDEBAND;
Robert Carra6bb2bc2020-04-08 11:03:23 -0700296 return;
David Sodman15094112018-10-11 09:39:37 -0700297 } else {
Lloyd Piquef5275482019-01-29 18:42:42 -0800298 // Normal buffer layers
Lloyd Piquede196652020-01-22 17:29:58 -0800299 compositionState->hdrMetadata = mBufferInfo.mHdrMetadata;
300 compositionState->compositionType = mPotentialCursor
Lloyd Piquef5275482019-01-29 18:42:42 -0800301 ? Hwc2::IComposerClient::Composition::CURSOR
302 : Hwc2::IComposerClient::Composition::DEVICE;
David Sodman0c69cad2017-08-21 12:12:51 -0700303 }
Robert Carra6bb2bc2020-04-08 11:03:23 -0700304
Alec Mouria90a5702021-04-16 16:36:21 +0000305 compositionState->buffer = mBufferInfo.mBuffer->getBuffer();
Robert Carra6bb2bc2020-04-08 11:03:23 -0700306 compositionState->bufferSlot = (mBufferInfo.mBufferSlot == BufferQueue::INVALID_BUFFER_SLOT)
307 ? 0
308 : mBufferInfo.mBufferSlot;
309 compositionState->acquireFence = mBufferInfo.mFence;
baocheng sun9691b9c2021-08-03 19:27:06 +0800310 compositionState->sidebandStreamHasFrame = false;
David Sodman0c69cad2017-08-21 12:12:51 -0700311}
312
Marissa Wallfd668622018-05-10 10:21:13 -0700313bool BufferLayer::onPreComposition(nsecs_t refreshStartTime) {
chaviwd62d3062019-09-04 14:48:02 -0700314 if (mBufferInfo.mBuffer != nullptr) {
Marissa Wallfd668622018-05-10 10:21:13 -0700315 Mutex::Autolock lock(mFrameEventHistoryMutex);
316 mFrameEventHistory.addPreComposition(mCurrentFrameNumber, refreshStartTime);
David Sodman0c69cad2017-08-21 12:12:51 -0700317 }
Marissa Wallfd668622018-05-10 10:21:13 -0700318 mRefreshPending = false;
319 return hasReadyFrame();
David Sodman0c69cad2017-08-21 12:12:51 -0700320}
Ady Abraham8b9e6122021-01-26 19:11:45 -0800321namespace {
322TimeStats::SetFrameRateVote frameRateToSetFrameRateVotePayload(Layer::FrameRate frameRate) {
323 using FrameRateCompatibility = TimeStats::SetFrameRateVote::FrameRateCompatibility;
324 using Seamlessness = TimeStats::SetFrameRateVote::Seamlessness;
325 const auto frameRateCompatibility = [frameRate] {
326 switch (frameRate.type) {
327 case Layer::FrameRateCompatibility::Default:
328 return FrameRateCompatibility::Default;
329 case Layer::FrameRateCompatibility::ExactOrMultiple:
330 return FrameRateCompatibility::ExactOrMultiple;
331 default:
332 return FrameRateCompatibility::Undefined;
333 }
334 }();
335
336 const auto seamlessness = [frameRate] {
337 switch (frameRate.seamlessness) {
338 case scheduler::Seamlessness::OnlySeamless:
339 return Seamlessness::ShouldBeSeamless;
340 case scheduler::Seamlessness::SeamedAndSeamless:
341 return Seamlessness::NotRequired;
342 default:
343 return Seamlessness::Undefined;
344 }
345 }();
346
347 return TimeStats::SetFrameRateVote{.frameRate = frameRate.rate.getValue(),
348 .frameRateCompatibility = frameRateCompatibility,
349 .seamlessness = seamlessness};
350}
351} // namespace
David Sodman0c69cad2017-08-21 12:12:51 -0700352
Alec Mouri1dc4bfa2021-10-01 16:31:08 -0700353void BufferLayer::onPostComposition(const DisplayDevice* display,
Dominik Laskowski075d3172018-05-24 15:50:06 -0700354 const std::shared_ptr<FenceTime>& glDoneFence,
Marissa Wallfd668622018-05-10 10:21:13 -0700355 const std::shared_ptr<FenceTime>& presentFence,
356 const CompositorTiming& compositorTiming) {
357 // mFrameLatencyNeeded is true when a new frame was latched for the
358 // composition.
Alec Mouri1dc4bfa2021-10-01 16:31:08 -0700359 if (!mBufferInfo.mFrameLatencyNeeded) return;
Marissa Wallfd668622018-05-10 10:21:13 -0700360
361 // Update mFrameEventHistory.
Dan Stoza436ccf32018-06-21 12:10:12 -0700362 {
Marissa Wallfd668622018-05-10 10:21:13 -0700363 Mutex::Autolock lock(mFrameEventHistoryMutex);
364 mFrameEventHistory.addPostComposition(mCurrentFrameNumber, glDoneFence, presentFence,
365 compositorTiming);
Valerie Hau93d5a5e2020-02-13 14:50:01 -0800366 finalizeFrameEventHistory(glDoneFence, compositorTiming);
David Sodman0c69cad2017-08-21 12:12:51 -0700367 }
368
Marissa Wallfd668622018-05-10 10:21:13 -0700369 // Update mFrameTracker.
chaviw4244e032019-09-04 11:27:49 -0700370 nsecs_t desiredPresentTime = mBufferInfo.mDesiredPresentTime;
Marissa Wallfd668622018-05-10 10:21:13 -0700371 mFrameTracker.setDesiredPresentTime(desiredPresentTime);
372
Yiwei Zhang1a88c402019-11-18 10:43:58 -0800373 const int32_t layerId = getSequence();
374 mFlinger->mTimeStats->setDesiredTime(layerId, mCurrentFrameNumber, desiredPresentTime);
Marissa Wallfd668622018-05-10 10:21:13 -0700375
Dominik Laskowskib7251f42020-04-20 17:42:59 -0700376 const auto outputLayer = findOutputLayerForDisplay(display);
Adithya Srinivasanb69e0762019-11-11 18:39:53 -0800377 if (outputLayer && outputLayer->requiresClientComposition()) {
378 nsecs_t clientCompositionTimestamp = outputLayer->getState().clientCompositionTimestamp;
379 mFlinger->mFrameTracer->traceTimestamp(layerId, getCurrentBufferId(), mCurrentFrameNumber,
380 clientCompositionTimestamp,
381 FrameTracer::FrameEvent::FALLBACK_COMPOSITION);
Adithya Srinivasanb6a2fa12021-03-13 00:23:09 +0000382 // Update the SurfaceFrames in the drawing state
383 if (mDrawingState.bufferSurfaceFrameTX) {
384 mDrawingState.bufferSurfaceFrameTX->setGpuComposition();
385 }
386 for (auto& [token, surfaceFrame] : mDrawingState.bufferlessSurfaceFramesTX) {
387 surfaceFrame->setGpuComposition();
388 }
Adithya Srinivasanb69e0762019-11-11 18:39:53 -0800389 }
390
chaviw4244e032019-09-04 11:27:49 -0700391 std::shared_ptr<FenceTime> frameReadyFence = mBufferInfo.mFenceTime;
Marissa Wallfd668622018-05-10 10:21:13 -0700392 if (frameReadyFence->isValid()) {
393 mFrameTracker.setFrameReadyFence(std::move(frameReadyFence));
394 } else {
395 // There was no fence for this frame, so assume that it was ready
396 // to be presented at the desired present time.
397 mFrameTracker.setFrameReadyTime(desiredPresentTime);
Dominik Laskowski45de9bd2018-06-11 17:44:10 -0700398 }
Marissa Wallfd668622018-05-10 10:21:13 -0700399
Ady Abraham39d5eeb2021-07-07 15:49:21 -0700400 if (display) {
401 const Fps refreshRate = display->refreshRateConfigs().getCurrentRefreshRate().getFps();
402 const std::optional<Fps> renderRate =
403 mFlinger->mScheduler->getFrameRateOverride(getOwnerUid());
Dominik Laskowskif5d0ea52021-09-26 17:27:01 -0700404
405 const auto vote = frameRateToSetFrameRateVotePayload(mDrawingState.frameRate);
406 const auto gameMode = getGameMode();
407
Ady Abraham39d5eeb2021-07-07 15:49:21 -0700408 if (presentFence->isValid()) {
409 mFlinger->mTimeStats->setPresentFence(layerId, mCurrentFrameNumber, presentFence,
Dominik Laskowskif5d0ea52021-09-26 17:27:01 -0700410 refreshRate, renderRate, vote, gameMode);
Ady Abraham39d5eeb2021-07-07 15:49:21 -0700411 mFlinger->mFrameTracer->traceFence(layerId, getCurrentBufferId(), mCurrentFrameNumber,
412 presentFence,
Mikael Pessa90092f42019-08-26 17:22:04 -0700413 FrameTracer::FrameEvent::PRESENT_FENCE);
Ady Abraham39d5eeb2021-07-07 15:49:21 -0700414 mFrameTracker.setActualPresentFence(std::shared_ptr<FenceTime>(presentFence));
415 } else if (const auto displayId = PhysicalDisplayId::tryCast(display->getId());
416 displayId && mFlinger->getHwComposer().isConnected(*displayId)) {
417 // The HWC doesn't support present fences, so use the refresh
418 // timestamp instead.
419 const nsecs_t actualPresentTime = display->getRefreshTimestamp();
420 mFlinger->mTimeStats->setPresentTime(layerId, mCurrentFrameNumber, actualPresentTime,
Dominik Laskowskif5d0ea52021-09-26 17:27:01 -0700421 refreshRate, renderRate, vote, gameMode);
Ady Abraham39d5eeb2021-07-07 15:49:21 -0700422 mFlinger->mFrameTracer->traceTimestamp(layerId, getCurrentBufferId(),
423 mCurrentFrameNumber, actualPresentTime,
424 FrameTracer::FrameEvent::PRESENT_FENCE);
425 mFrameTracker.setActualPresentTime(actualPresentTime);
426 }
Marissa Wallfd668622018-05-10 10:21:13 -0700427 }
428
429 mFrameTracker.advanceFrame();
chaviw74b03172019-08-19 11:09:03 -0700430 mBufferInfo.mFrameLatencyNeeded = false;
David Sodman0c69cad2017-08-21 12:12:51 -0700431}
432
chaviwdebadb82020-03-26 14:57:24 -0700433void BufferLayer::gatherBufferInfo() {
434 mBufferInfo.mPixelFormat =
Alec Mouria90a5702021-04-16 16:36:21 +0000435 !mBufferInfo.mBuffer ? PIXEL_FORMAT_NONE : mBufferInfo.mBuffer->getBuffer()->format;
chaviwdebadb82020-03-26 14:57:24 -0700436 mBufferInfo.mFrameLatencyNeeded = true;
437}
438
Ady Abraham63a3e592021-01-06 10:47:15 -0800439bool BufferLayer::shouldPresentNow(nsecs_t expectedPresentTime) const {
440 // If this is not a valid vsync for the layer's uid, return and try again later
441 const bool isVsyncValidForUid =
442 mFlinger->mScheduler->isVsyncValid(expectedPresentTime, mOwnerUid);
443 if (!isVsyncValidForUid) {
444 ATRACE_NAME("!isVsyncValidForUid");
445 return false;
446 }
447
448 // AutoRefresh layers and sideband streams should always be presented
449 if (getSidebandStreamChanged() || getAutoRefresh()) {
450 return true;
451 }
452
Ady Abraham63a3e592021-01-06 10:47:15 -0800453 // If this layer doesn't have a frame is shouldn't be presented
454 if (!hasFrameUpdate()) {
455 return false;
456 }
457
458 // Defer to the derived class to decide whether the next buffer is due for
459 // presentation.
460 return isBufferDue(expectedPresentTime);
461}
462
Dominik Laskowskia8955dd2019-07-10 10:19:09 -0700463bool BufferLayer::latchBuffer(bool& recomputeVisibleRegions, nsecs_t latchTime,
464 nsecs_t expectedPresentTime) {
Marissa Wallfd668622018-05-10 10:21:13 -0700465 ATRACE_CALL();
David Sodman0c69cad2017-08-21 12:12:51 -0700466
Vishnu Nair6194e2e2019-02-06 12:58:39 -0800467 bool refreshRequired = latchSidebandStream(recomputeVisibleRegions);
David Sodman0c69cad2017-08-21 12:12:51 -0700468
Vishnu Nair6194e2e2019-02-06 12:58:39 -0800469 if (refreshRequired) {
470 return refreshRequired;
David Sodman0c69cad2017-08-21 12:12:51 -0700471 }
472
Marissa Wallfd668622018-05-10 10:21:13 -0700473 if (!hasReadyFrame()) {
Vishnu Nair6194e2e2019-02-06 12:58:39 -0800474 return false;
David Sodman0c69cad2017-08-21 12:12:51 -0700475 }
David Sodman0c69cad2017-08-21 12:12:51 -0700476
Marissa Wallfd668622018-05-10 10:21:13 -0700477 // if we've already called updateTexImage() without going through
478 // a composition step, we have to skip this layer at this point
479 // because we cannot call updateTeximage() without a corresponding
480 // compositionComplete() call.
481 // we'll trigger an update in onPreComposition().
482 if (mRefreshPending) {
Vishnu Nair6194e2e2019-02-06 12:58:39 -0800483 return false;
Marissa Wallfd668622018-05-10 10:21:13 -0700484 }
485
486 // If the head buffer's acquire fence hasn't signaled yet, return and
487 // try again later
488 if (!fenceHasSignaled()) {
Ady Abraham09bd3922019-04-08 10:44:56 -0700489 ATRACE_NAME("!fenceHasSignaled()");
Dominik Laskowskie0e0cde2021-07-30 10:42:05 -0700490 mFlinger->onLayerUpdate();
Vishnu Nair6194e2e2019-02-06 12:58:39 -0800491 return false;
Marissa Wallfd668622018-05-10 10:21:13 -0700492 }
493
494 // Capture the old state of the layer for comparisons later
495 const State& s(getDrawingState());
496 const bool oldOpacity = isOpaque(s);
chaviwd62d3062019-09-04 14:48:02 -0700497
498 BufferInfo oldBufferInfo = mBufferInfo;
Marissa Wallfd668622018-05-10 10:21:13 -0700499
Dominik Laskowskia8955dd2019-07-10 10:19:09 -0700500 status_t err = updateTexImage(recomputeVisibleRegions, latchTime, expectedPresentTime);
Marissa Wallfd668622018-05-10 10:21:13 -0700501 if (err != NO_ERROR) {
Vishnu Nair6194e2e2019-02-06 12:58:39 -0800502 return false;
Marissa Wallfd668622018-05-10 10:21:13 -0700503 }
504
505 err = updateActiveBuffer();
506 if (err != NO_ERROR) {
Vishnu Nair6194e2e2019-02-06 12:58:39 -0800507 return false;
Marissa Wallfd668622018-05-10 10:21:13 -0700508 }
509
Marissa Wallfd668622018-05-10 10:21:13 -0700510 err = updateFrameNumber(latchTime);
511 if (err != NO_ERROR) {
Vishnu Nair6194e2e2019-02-06 12:58:39 -0800512 return false;
Marissa Wallfd668622018-05-10 10:21:13 -0700513 }
514
chaviw4244e032019-09-04 11:27:49 -0700515 gatherBufferInfo();
516
Marissa Wallfd668622018-05-10 10:21:13 -0700517 mRefreshPending = true;
chaviwd62d3062019-09-04 14:48:02 -0700518 if (oldBufferInfo.mBuffer == nullptr) {
Marissa Wallfd668622018-05-10 10:21:13 -0700519 // the first time we receive a buffer, we need to trigger a
520 // geometry invalidation.
521 recomputeVisibleRegions = true;
522 }
523
chaviw4244e032019-09-04 11:27:49 -0700524 if ((mBufferInfo.mCrop != oldBufferInfo.mCrop) ||
525 (mBufferInfo.mTransform != oldBufferInfo.mTransform) ||
526 (mBufferInfo.mScaleMode != oldBufferInfo.mScaleMode) ||
527 (mBufferInfo.mTransformToDisplayInverse != oldBufferInfo.mTransformToDisplayInverse)) {
Marissa Wallfd668622018-05-10 10:21:13 -0700528 recomputeVisibleRegions = true;
529 }
530
chaviwd62d3062019-09-04 14:48:02 -0700531 if (oldBufferInfo.mBuffer != nullptr) {
Alec Mouria90a5702021-04-16 16:36:21 +0000532 uint32_t bufWidth = mBufferInfo.mBuffer->getBuffer()->getWidth();
533 uint32_t bufHeight = mBufferInfo.mBuffer->getBuffer()->getHeight();
534 if (bufWidth != uint32_t(oldBufferInfo.mBuffer->getBuffer()->width) ||
535 bufHeight != uint32_t(oldBufferInfo.mBuffer->getBuffer()->height)) {
Marissa Wallfd668622018-05-10 10:21:13 -0700536 recomputeVisibleRegions = true;
537 }
538 }
539
540 if (oldOpacity != isOpaque(s)) {
541 recomputeVisibleRegions = true;
542 }
543
Vishnu Nair6194e2e2019-02-06 12:58:39 -0800544 return true;
Marissa Wallfd668622018-05-10 10:21:13 -0700545}
546
Marissa Wallfd668622018-05-10 10:21:13 -0700547bool BufferLayer::hasReadyFrame() const {
Marissa Wall024a1912018-08-13 13:55:35 -0700548 return hasFrameUpdate() || getSidebandStreamChanged() || getAutoRefresh();
Marissa Wallfd668622018-05-10 10:21:13 -0700549}
550
551uint32_t BufferLayer::getEffectiveScalingMode() const {
chaviw4244e032019-09-04 11:27:49 -0700552 return mBufferInfo.mScaleMode;
Marissa Wallfd668622018-05-10 10:21:13 -0700553}
554
555bool BufferLayer::isProtected() const {
Alec Mouria90a5702021-04-16 16:36:21 +0000556 return (mBufferInfo.mBuffer != nullptr) &&
557 (mBufferInfo.mBuffer->getBuffer()->getUsage() & GRALLOC_USAGE_PROTECTED);
Marissa Wallfd668622018-05-10 10:21:13 -0700558}
559
David Sodman0c69cad2017-08-21 12:12:51 -0700560// As documented in libhardware header, formats in the range
561// 0x100 - 0x1FF are specific to the HAL implementation, and
562// are known to have no alpha channel
563// TODO: move definition for device-specific range into
564// hardware.h, instead of using hard-coded values here.
565#define HARDWARE_IS_DEVICE_FORMAT(f) ((f) >= 0x100 && (f) <= 0x1FF)
566
567bool BufferLayer::getOpacityForFormat(uint32_t format) {
568 if (HARDWARE_IS_DEVICE_FORMAT(format)) {
569 return true;
570 }
571 switch (format) {
572 case HAL_PIXEL_FORMAT_RGBA_8888:
573 case HAL_PIXEL_FORMAT_BGRA_8888:
574 case HAL_PIXEL_FORMAT_RGBA_FP16:
575 case HAL_PIXEL_FORMAT_RGBA_1010102:
576 return false;
577 }
578 // in all other case, we have no blending (also for unknown formats)
579 return true;
580}
581
Dominik Laskowskib7251f42020-04-20 17:42:59 -0700582bool BufferLayer::needsFiltering(const DisplayDevice* display) const {
583 const auto outputLayer = findOutputLayerForDisplay(display);
Lloyd Pique37c2c9b2018-12-04 17:25:10 -0800584 if (outputLayer == nullptr) {
Lloyd Piquef16688f2019-02-19 17:47:57 -0800585 return false;
Lloyd Pique37c2c9b2018-12-04 17:25:10 -0800586 }
587
Lloyd Piquef16688f2019-02-19 17:47:57 -0800588 // We need filtering if the sourceCrop rectangle size does not match the
589 // displayframe rectangle size (not a 1:1 render)
Lloyd Pique37c2c9b2018-12-04 17:25:10 -0800590 const auto& compositionState = outputLayer->getState();
591 const auto displayFrame = compositionState.displayFrame;
592 const auto sourceCrop = compositionState.sourceCrop;
Lloyd Piquef16688f2019-02-19 17:47:57 -0800593 return sourceCrop.getHeight() != displayFrame.getHeight() ||
Peiyong Linc2020ca2019-01-10 11:36:12 -0800594 sourceCrop.getWidth() != displayFrame.getWidth();
Chia-I Wu692e0832018-06-05 15:46:58 -0700595}
596
Dominik Laskowskib7251f42020-04-20 17:42:59 -0700597bool BufferLayer::needsFilteringForScreenshots(const DisplayDevice* display,
Alec Mouri5a6d8572020-03-23 23:56:15 -0700598 const ui::Transform& inverseParentTransform) const {
Dominik Laskowskib7251f42020-04-20 17:42:59 -0700599 const auto outputLayer = findOutputLayerForDisplay(display);
Alec Mouri5a6d8572020-03-23 23:56:15 -0700600 if (outputLayer == nullptr) {
601 return false;
602 }
603
604 // We need filtering if the sourceCrop rectangle size does not match the
605 // viewport rectangle size (not a 1:1 render)
606 const auto& compositionState = outputLayer->getState();
Dominik Laskowskib7251f42020-04-20 17:42:59 -0700607 const ui::Transform& displayTransform = display->getTransform();
Alec Mouri5a6d8572020-03-23 23:56:15 -0700608 const ui::Transform inverseTransform = inverseParentTransform * displayTransform.inverse();
609 // Undo the transformation of the displayFrame so that we're back into
610 // layer-stack space.
611 const Rect frame = inverseTransform.transform(compositionState.displayFrame);
612 const FloatRect sourceCrop = compositionState.sourceCrop;
613
614 int32_t frameHeight = frame.getHeight();
615 int32_t frameWidth = frame.getWidth();
616 // If the display transform had a rotational component then undo the
617 // rotation so that the orientation matches the source crop.
618 if (displayTransform.getOrientation() & ui::Transform::ROT_90) {
619 std::swap(frameHeight, frameWidth);
620 }
621 return sourceCrop.getHeight() != frameHeight || sourceCrop.getWidth() != frameWidth;
622}
623
Vishnu Nair60356342018-11-13 13:00:45 -0800624Rect BufferLayer::getBufferSize(const State& s) const {
625 // If we have a sideband stream, or we are scaling the buffer then return the layer size since
626 // we cannot determine the buffer size.
627 if ((s.sidebandStream != nullptr) ||
628 (getEffectiveScalingMode() != NATIVE_WINDOW_SCALING_MODE_FREEZE)) {
629 return Rect(getActiveWidth(s), getActiveHeight(s));
630 }
631
chaviwd62d3062019-09-04 14:48:02 -0700632 if (mBufferInfo.mBuffer == nullptr) {
Vishnu Nair60356342018-11-13 13:00:45 -0800633 return Rect::INVALID_RECT;
634 }
635
Alec Mouria90a5702021-04-16 16:36:21 +0000636 uint32_t bufWidth = mBufferInfo.mBuffer->getBuffer()->getWidth();
637 uint32_t bufHeight = mBufferInfo.mBuffer->getBuffer()->getHeight();
Vishnu Nair60356342018-11-13 13:00:45 -0800638
639 // Undo any transformations on the buffer and return the result.
chaviw4244e032019-09-04 11:27:49 -0700640 if (mBufferInfo.mTransform & ui::Transform::ROT_90) {
Vishnu Nair60356342018-11-13 13:00:45 -0800641 std::swap(bufWidth, bufHeight);
642 }
643
Lloyd Pique0449b0f2018-12-20 16:23:45 -0800644 if (getTransformToDisplayInverse()) {
Dominik Laskowski718f9602019-11-09 20:01:35 -0800645 uint32_t invTransform = DisplayDevice::getPrimaryDisplayRotationFlags();
Vishnu Nair60356342018-11-13 13:00:45 -0800646 if (invTransform & ui::Transform::ROT_90) {
647 std::swap(bufWidth, bufHeight);
648 }
649 }
650
651 return Rect(bufWidth, bufHeight);
652}
653
Vishnu Nair4351ad52019-02-11 14:13:02 -0800654FloatRect BufferLayer::computeSourceBounds(const FloatRect& parentBounds) const {
655 const State& s(getDrawingState());
656
657 // If we have a sideband stream, or we are scaling the buffer then return the layer size since
658 // we cannot determine the buffer size.
659 if ((s.sidebandStream != nullptr) ||
660 (getEffectiveScalingMode() != NATIVE_WINDOW_SCALING_MODE_FREEZE)) {
661 return FloatRect(0, 0, getActiveWidth(s), getActiveHeight(s));
662 }
663
chaviwd62d3062019-09-04 14:48:02 -0700664 if (mBufferInfo.mBuffer == nullptr) {
Vishnu Nair4351ad52019-02-11 14:13:02 -0800665 return parentBounds;
666 }
667
Alec Mouria90a5702021-04-16 16:36:21 +0000668 uint32_t bufWidth = mBufferInfo.mBuffer->getBuffer()->getWidth();
669 uint32_t bufHeight = mBufferInfo.mBuffer->getBuffer()->getHeight();
Vishnu Nair4351ad52019-02-11 14:13:02 -0800670
671 // Undo any transformations on the buffer and return the result.
chaviw4244e032019-09-04 11:27:49 -0700672 if (mBufferInfo.mTransform & ui::Transform::ROT_90) {
Vishnu Nair4351ad52019-02-11 14:13:02 -0800673 std::swap(bufWidth, bufHeight);
674 }
675
676 if (getTransformToDisplayInverse()) {
Dominik Laskowski718f9602019-11-09 20:01:35 -0800677 uint32_t invTransform = DisplayDevice::getPrimaryDisplayRotationFlags();
Vishnu Nair4351ad52019-02-11 14:13:02 -0800678 if (invTransform & ui::Transform::ROT_90) {
679 std::swap(bufWidth, bufHeight);
680 }
681 }
682
683 return FloatRect(0, 0, bufWidth, bufHeight);
684}
685
chaviw49a108c2019-08-12 11:23:06 -0700686void BufferLayer::latchAndReleaseBuffer() {
687 mRefreshPending = false;
688 if (hasReadyFrame()) {
689 bool ignored = false;
690 latchBuffer(ignored, systemTime(), 0 /* expectedPresentTime */);
691 }
692 releasePendingBuffer(systemTime());
693}
694
chaviw4244e032019-09-04 11:27:49 -0700695PixelFormat BufferLayer::getPixelFormat() const {
696 return mBufferInfo.mPixelFormat;
697}
698
699bool BufferLayer::getTransformToDisplayInverse() const {
700 return mBufferInfo.mTransformToDisplayInverse;
701}
702
703Rect BufferLayer::getBufferCrop() const {
704 // this is the crop rectangle that applies to the buffer
705 // itself (as opposed to the window)
706 if (!mBufferInfo.mCrop.isEmpty()) {
707 // if the buffer crop is defined, we use that
708 return mBufferInfo.mCrop;
chaviwd62d3062019-09-04 14:48:02 -0700709 } else if (mBufferInfo.mBuffer != nullptr) {
chaviw4244e032019-09-04 11:27:49 -0700710 // otherwise we use the whole buffer
Alec Mouria90a5702021-04-16 16:36:21 +0000711 return mBufferInfo.mBuffer->getBuffer()->getBounds();
chaviw4244e032019-09-04 11:27:49 -0700712 } else {
713 // if we don't have a buffer yet, we use an empty/invalid crop
714 return Rect();
715 }
716}
717
718uint32_t BufferLayer::getBufferTransform() const {
719 return mBufferInfo.mTransform;
720}
721
722ui::Dataspace BufferLayer::getDataSpace() const {
723 return mBufferInfo.mDataspace;
724}
725
726ui::Dataspace BufferLayer::translateDataspace(ui::Dataspace dataspace) {
727 ui::Dataspace updatedDataspace = dataspace;
728 // translate legacy dataspaces to modern dataspaces
729 switch (dataspace) {
730 case ui::Dataspace::SRGB:
731 updatedDataspace = ui::Dataspace::V0_SRGB;
732 break;
733 case ui::Dataspace::SRGB_LINEAR:
734 updatedDataspace = ui::Dataspace::V0_SRGB_LINEAR;
735 break;
736 case ui::Dataspace::JFIF:
737 updatedDataspace = ui::Dataspace::V0_JFIF;
738 break;
739 case ui::Dataspace::BT601_625:
740 updatedDataspace = ui::Dataspace::V0_BT601_625;
741 break;
742 case ui::Dataspace::BT601_525:
743 updatedDataspace = ui::Dataspace::V0_BT601_525;
744 break;
745 case ui::Dataspace::BT709:
746 updatedDataspace = ui::Dataspace::V0_BT709;
747 break;
748 default:
749 break;
750 }
751
752 return updatedDataspace;
753}
754
chaviwd62d3062019-09-04 14:48:02 -0700755sp<GraphicBuffer> BufferLayer::getBuffer() const {
Alec Mouria90a5702021-04-16 16:36:21 +0000756 return mBufferInfo.mBuffer ? mBufferInfo.mBuffer->getBuffer() : nullptr;
chaviwd62d3062019-09-04 14:48:02 -0700757}
758
chaviwf83ce182019-09-12 14:43:08 -0700759void BufferLayer::getDrawingTransformMatrix(bool filteringEnabled, float outMatrix[16]) {
Alec Mouria90a5702021-04-16 16:36:21 +0000760 GLConsumer::computeTransformMatrix(outMatrix,
761 mBufferInfo.mBuffer ? mBufferInfo.mBuffer->getBuffer()
762 : nullptr,
763 mBufferInfo.mCrop, mBufferInfo.mTransform, filteringEnabled);
chaviwf83ce182019-09-12 14:43:08 -0700764}
765
chaviwb4c6e582019-08-16 14:35:07 -0700766void BufferLayer::setInitialValuesForClone(const sp<Layer>& clonedFrom) {
767 Layer::setInitialValuesForClone(clonedFrom);
768
769 sp<BufferLayer> bufferClonedFrom = static_cast<BufferLayer*>(clonedFrom.get());
770 mPremultipliedAlpha = bufferClonedFrom->mPremultipliedAlpha;
771 mPotentialCursor = bufferClonedFrom->mPotentialCursor;
772 mProtectedByApp = bufferClonedFrom->mProtectedByApp;
chaviw74b03172019-08-19 11:09:03 -0700773
774 updateCloneBufferInfo();
775}
776
777void BufferLayer::updateCloneBufferInfo() {
778 if (!isClone() || !isClonedFromAlive()) {
779 return;
780 }
781
782 sp<BufferLayer> clonedFrom = static_cast<BufferLayer*>(getClonedFrom().get());
783 mBufferInfo = clonedFrom->mBufferInfo;
784 mSidebandStream = clonedFrom->mSidebandStream;
785 surfaceDamageRegion = clonedFrom->surfaceDamageRegion;
786 mCurrentFrameNumber = clonedFrom->mCurrentFrameNumber.load();
787 mPreviousFrameNumber = clonedFrom->mPreviousFrameNumber;
788
789 // After buffer info is updated, the drawingState from the real layer needs to be copied into
790 // the cloned. This is because some properties of drawingState can change when latchBuffer is
chaviwaf87b3e2019-10-01 16:59:28 -0700791 // called. However, copying the drawingState would also overwrite the cloned layer's relatives
792 // and touchableRegionCrop. Therefore, temporarily store the relatives so they can be set in
793 // the cloned drawingState again.
chaviw74b03172019-08-19 11:09:03 -0700794 wp<Layer> tmpZOrderRelativeOf = mDrawingState.zOrderRelativeOf;
795 SortedVector<wp<Layer>> tmpZOrderRelatives = mDrawingState.zOrderRelatives;
chaviwaf87b3e2019-10-01 16:59:28 -0700796 wp<Layer> tmpTouchableRegionCrop = mDrawingState.touchableRegionCrop;
chaviw3277faf2021-05-19 16:45:23 -0500797 WindowInfo tmpInputInfo = mDrawingState.inputInfo;
chaviwaf87b3e2019-10-01 16:59:28 -0700798
Vishnu Nair3bb11d02021-11-26 09:24:11 -0800799 cloneDrawingState(clonedFrom.get());
chaviwaf87b3e2019-10-01 16:59:28 -0700800
801 mDrawingState.touchableRegionCrop = tmpTouchableRegionCrop;
chaviw74b03172019-08-19 11:09:03 -0700802 mDrawingState.zOrderRelativeOf = tmpZOrderRelativeOf;
803 mDrawingState.zOrderRelatives = tmpZOrderRelatives;
chaviwaf87b3e2019-10-01 16:59:28 -0700804 mDrawingState.inputInfo = tmpInputInfo;
chaviwb4c6e582019-08-16 14:35:07 -0700805}
806
Dominik Laskowskib7251f42020-04-20 17:42:59 -0700807void BufferLayer::setTransformHint(ui::Transform::RotationFlags displayTransformHint) {
Vishnu Nair6213bd92020-05-08 17:42:25 -0700808 mTransformHint = getFixedTransformHint();
809 if (mTransformHint == ui::Transform::ROT_INVALID) {
810 mTransformHint = displayTransformHint;
811 }
812}
813
Vishnu Naire7f79c52020-10-29 14:45:03 -0700814bool BufferLayer::bufferNeedsFiltering() const {
815 return isFixedSize();
816}
817
David Sodman0c69cad2017-08-21 12:12:51 -0700818} // namespace android
819
820#if defined(__gl_h_)
821#error "don't include gl/gl.h in this file"
822#endif
823
824#if defined(__gl2_h_)
825#error "don't include gl2/gl2.h in this file"
826#endif
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -0800827
828// TODO(b/129481165): remove the #pragma below and fix conversion issues
829#pragma clang diagnostic pop // ignored "-Wconversion"