blob: c29042f7b8b54c19ba687c83887e76831202d435 [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
chaviw98318de2021-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
114bool BufferLayer::isVisible() const {
Dominik Laskowskif7a09ed2019-10-07 13:54:18 -0700115 return !isHiddenByPolicy() && getAlpha() > 0.0f &&
chaviwd62d3062019-09-04 14:48:02 -0700116 (mBufferInfo.mBuffer != nullptr || mSidebandStream != nullptr);
David Sodman0c69cad2017-08-21 12:12:51 -0700117}
118
119bool BufferLayer::isFixedSize() const {
120 return getEffectiveScalingMode() != NATIVE_WINDOW_SCALING_MODE_FREEZE;
121}
122
Lloyd Piquea83776c2019-01-29 18:42:32 -0800123bool BufferLayer::usesSourceCrop() const {
124 return true;
125}
126
David Sodman0c69cad2017-08-21 12:12:51 -0700127static constexpr mat4 inverseOrientation(uint32_t transform) {
David Sodman41fdfc92017-11-06 16:09:56 -0800128 const mat4 flipH(-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1);
129 const mat4 flipV(1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1);
130 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 -0700131 mat4 tr;
132
133 if (transform & NATIVE_WINDOW_TRANSFORM_ROT_90) {
134 tr = tr * rot90;
135 }
136 if (transform & NATIVE_WINDOW_TRANSFORM_FLIP_H) {
137 tr = tr * flipH;
138 }
139 if (transform & NATIVE_WINDOW_TRANSFORM_FLIP_V) {
140 tr = tr * flipV;
141 }
142 return inverse(tr);
143}
144
Vishnu Nair9b079a22020-01-21 14:36:08 -0800145std::optional<compositionengine::LayerFE::LayerSettings> BufferLayer::prepareClientComposition(
Lloyd Piquef16688f2019-02-19 17:47:57 -0800146 compositionengine::LayerFE::ClientCompositionTargetSettings& targetSettings) {
David Sodman0c69cad2017-08-21 12:12:51 -0700147 ATRACE_CALL();
Lloyd Piquef16688f2019-02-19 17:47:57 -0800148
Vishnu Nair9b079a22020-01-21 14:36:08 -0800149 std::optional<compositionengine::LayerFE::LayerSettings> result =
150 Layer::prepareClientComposition(targetSettings);
Lloyd Piquef16688f2019-02-19 17:47:57 -0800151 if (!result) {
152 return result;
153 }
154
Sally Qidf3da512021-07-08 17:27:02 +0000155 if (CC_UNLIKELY(mBufferInfo.mBuffer == 0) && mSidebandStream != nullptr) {
156 // For surfaceview of tv sideband, there is no activeBuffer
157 // in bufferqueue, we need return LayerSettings.
158 return result;
David Sodman0c69cad2017-08-21 12:12:51 -0700159 }
Ady Abraham7a60afb2021-03-29 13:20:55 -0700160 const bool blackOutLayer = (isProtected() && !targetSettings.supportsProtectedContent) ||
yuhui.zhanga102ff92021-04-09 14:45:51 +0800161 ((isSecure() || isProtected()) && !targetSettings.isSecure);
Ady Abraham7a60afb2021-03-29 13:20:55 -0700162 const bool bufferCanBeUsedAsHwTexture =
Alec Mouria90a5702021-04-16 16:36:21 +0000163 mBufferInfo.mBuffer->getBuffer()->getUsage() & GraphicBuffer::USAGE_HW_TEXTURE;
Lloyd Piquede196652020-01-22 17:29:58 -0800164 compositionengine::LayerFE::LayerSettings& layer = *result;
Ady Abraham7a60afb2021-03-29 13:20:55 -0700165 if (blackOutLayer || !bufferCanBeUsedAsHwTexture) {
166 ALOGE_IF(!bufferCanBeUsedAsHwTexture, "%s is blacked out as buffer is not gpu readable",
167 mName.c_str());
Vishnu Nairb87d94f2020-02-13 09:17:36 -0800168 prepareClearClientComposition(layer, true /* blackout */);
169 return layer;
David Sodman0c69cad2017-08-21 12:12:51 -0700170 }
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000171
Vishnu Nairb87d94f2020-02-13 09:17:36 -0800172 const State& s(getDrawingState());
173 layer.source.buffer.buffer = mBufferInfo.mBuffer;
174 layer.source.buffer.isOpaque = isOpaque(s);
175 layer.source.buffer.fence = mBufferInfo.mFence;
176 layer.source.buffer.textureName = mTextureName;
177 layer.source.buffer.usePremultipliedAlpha = getPremultipledAlpha();
178 layer.source.buffer.isY410BT2020 = isHdrY410();
179 bool hasSmpte2086 = mBufferInfo.mHdrMetadata.validTypes & HdrMetadata::SMPTE2086;
180 bool hasCta861_3 = mBufferInfo.mHdrMetadata.validTypes & HdrMetadata::CTA861_3;
John Reckac09e452021-04-07 16:35:37 -0400181 float maxLuminance = 0.f;
182 if (hasSmpte2086 && hasCta861_3) {
183 maxLuminance = std::min(mBufferInfo.mHdrMetadata.smpte2086.maxLuminance,
184 mBufferInfo.mHdrMetadata.cta8613.maxContentLightLevel);
185 } else if (hasSmpte2086) {
186 maxLuminance = mBufferInfo.mHdrMetadata.smpte2086.maxLuminance;
187 } else if (hasCta861_3) {
188 maxLuminance = mBufferInfo.mHdrMetadata.cta8613.maxContentLightLevel;
189 } else {
190 switch (layer.sourceDataspace & HAL_DATASPACE_TRANSFER_MASK) {
191 case HAL_DATASPACE_TRANSFER_ST2084:
192 case HAL_DATASPACE_TRANSFER_HLG:
193 // Behavior-match previous releases for HDR content
194 maxLuminance = defaultMaxLuminance;
195 break;
196 }
197 }
198 layer.source.buffer.maxLuminanceNits = maxLuminance;
Vishnu Nairb87d94f2020-02-13 09:17:36 -0800199 layer.frameNumber = mCurrentFrameNumber;
Alec Mouria90a5702021-04-16 16:36:21 +0000200 layer.bufferId = mBufferInfo.mBuffer ? mBufferInfo.mBuffer->getBuffer()->getId() : 0;
Vishnu Nairb87d94f2020-02-13 09:17:36 -0800201
Vishnu Naire7f79c52020-10-29 14:45:03 -0700202 const bool useFiltering =
203 targetSettings.needsFiltering || mNeedsFiltering || bufferNeedsFiltering();
Vishnu Nairb87d94f2020-02-13 09:17:36 -0800204
205 // Query the texture matrix given our current filtering mode.
206 float textureMatrix[16];
207 getDrawingTransformMatrix(useFiltering, textureMatrix);
208
209 if (getTransformToDisplayInverse()) {
210 /*
211 * the code below applies the primary display's inverse transform to
212 * the texture transform
213 */
214 uint32_t transform = DisplayDevice::getPrimaryDisplayRotationFlags();
215 mat4 tr = inverseOrientation(transform);
216
217 /**
218 * TODO(b/36727915): This is basically a hack.
219 *
220 * Ensure that regardless of the parent transformation,
221 * this buffer is always transformed from native display
222 * orientation to display orientation. For example, in the case
223 * of a camera where the buffer remains in native orientation,
224 * we want the pixels to always be upright.
225 */
226 sp<Layer> p = mDrawingParent.promote();
227 if (p != nullptr) {
228 const auto parentTransform = p->getTransform();
229 tr = tr * inverseOrientation(parentTransform.getOrientation());
230 }
231
232 // and finally apply it to the original texture matrix
233 const mat4 texTransform(mat4(static_cast<const float*>(textureMatrix)) * tr);
234 memcpy(textureMatrix, texTransform.asArray(), sizeof(textureMatrix));
235 }
236
237 const Rect win{getBounds()};
238 float bufferWidth = getBufferSize(s).getWidth();
239 float bufferHeight = getBufferSize(s).getHeight();
240
241 // BufferStateLayers can have a "buffer size" of [0, 0, -1, -1] when no display frame has
242 // been set and there is no parent layer bounds. In that case, the scale is meaningless so
243 // ignore them.
244 if (!getBufferSize(s).isValid()) {
245 bufferWidth = float(win.right) - float(win.left);
246 bufferHeight = float(win.bottom) - float(win.top);
247 }
248
249 const float scaleHeight = (float(win.bottom) - float(win.top)) / bufferHeight;
250 const float scaleWidth = (float(win.right) - float(win.left)) / bufferWidth;
251 const float translateY = float(win.top) / bufferHeight;
252 const float translateX = float(win.left) / bufferWidth;
253
254 // Flip y-coordinates because GLConsumer expects OpenGL convention.
255 mat4 tr = mat4::translate(vec4(.5, .5, 0, 1)) * mat4::scale(vec4(1, -1, 1, 1)) *
256 mat4::translate(vec4(-.5, -.5, 0, 1)) *
257 mat4::translate(vec4(translateX, translateY, 0, 1)) *
258 mat4::scale(vec4(scaleWidth, scaleHeight, 1.0, 1.0));
259
260 layer.source.buffer.useTextureFiltering = useFiltering;
261 layer.source.buffer.textureTransform = mat4(static_cast<const float*>(textureMatrix)) * tr;
262
Vishnu Nair9b079a22020-01-21 14:36:08 -0800263 return layer;
David Sodman0c69cad2017-08-21 12:12:51 -0700264}
265
Marissa Wallfd668622018-05-10 10:21:13 -0700266bool BufferLayer::isHdrY410() const {
267 // pixel format is HDR Y410 masquerading as RGBA_1010102
chaviw4244e032019-09-04 11:27:49 -0700268 return (mBufferInfo.mDataspace == ui::Dataspace::BT2020_ITU_PQ &&
269 mBufferInfo.mApi == NATIVE_WINDOW_API_MEDIA &&
chaviwdebadb82020-03-26 14:57:24 -0700270 mBufferInfo.mPixelFormat == HAL_PIXEL_FORMAT_RGBA_1010102);
David Sodmaneb085e02017-10-05 18:49:04 -0700271}
272
Lloyd Piquede196652020-01-22 17:29:58 -0800273sp<compositionengine::LayerFE> BufferLayer::getCompositionEngineLayerFE() const {
274 return asLayerFE();
275}
276
277compositionengine::LayerFECompositionState* BufferLayer::editCompositionState() {
278 return mCompositionState.get();
279}
280
281const compositionengine::LayerFECompositionState* BufferLayer::getCompositionState() const {
282 return mCompositionState.get();
283}
284
285void BufferLayer::preparePerFrameCompositionState() {
286 Layer::preparePerFrameCompositionState();
David Sodman0c69cad2017-08-21 12:12:51 -0700287
288 // Sideband layers
Lloyd Piquede196652020-01-22 17:29:58 -0800289 auto* compositionState = editCompositionState();
290 if (compositionState->sidebandStream.get()) {
291 compositionState->compositionType = Hwc2::IComposerClient::Composition::SIDEBAND;
Robert Carra6bb2bc2020-04-08 11:03:23 -0700292 return;
David Sodman15094112018-10-11 09:39:37 -0700293 } else {
Lloyd Piquef5275482019-01-29 18:42:42 -0800294 // Normal buffer layers
Lloyd Piquede196652020-01-22 17:29:58 -0800295 compositionState->hdrMetadata = mBufferInfo.mHdrMetadata;
296 compositionState->compositionType = mPotentialCursor
Lloyd Piquef5275482019-01-29 18:42:42 -0800297 ? Hwc2::IComposerClient::Composition::CURSOR
298 : Hwc2::IComposerClient::Composition::DEVICE;
David Sodman0c69cad2017-08-21 12:12:51 -0700299 }
Robert Carra6bb2bc2020-04-08 11:03:23 -0700300
Alec Mouria90a5702021-04-16 16:36:21 +0000301 compositionState->buffer = mBufferInfo.mBuffer->getBuffer();
Robert Carra6bb2bc2020-04-08 11:03:23 -0700302 compositionState->bufferSlot = (mBufferInfo.mBufferSlot == BufferQueue::INVALID_BUFFER_SLOT)
303 ? 0
304 : mBufferInfo.mBufferSlot;
305 compositionState->acquireFence = mBufferInfo.mFence;
David Sodman0c69cad2017-08-21 12:12:51 -0700306}
307
Marissa Wallfd668622018-05-10 10:21:13 -0700308bool BufferLayer::onPreComposition(nsecs_t refreshStartTime) {
chaviwd62d3062019-09-04 14:48:02 -0700309 if (mBufferInfo.mBuffer != nullptr) {
Marissa Wallfd668622018-05-10 10:21:13 -0700310 Mutex::Autolock lock(mFrameEventHistoryMutex);
311 mFrameEventHistory.addPreComposition(mCurrentFrameNumber, refreshStartTime);
David Sodman0c69cad2017-08-21 12:12:51 -0700312 }
Marissa Wallfd668622018-05-10 10:21:13 -0700313 mRefreshPending = false;
314 return hasReadyFrame();
David Sodman0c69cad2017-08-21 12:12:51 -0700315}
Ady Abraham8b9e6122021-01-26 19:11:45 -0800316namespace {
317TimeStats::SetFrameRateVote frameRateToSetFrameRateVotePayload(Layer::FrameRate frameRate) {
318 using FrameRateCompatibility = TimeStats::SetFrameRateVote::FrameRateCompatibility;
319 using Seamlessness = TimeStats::SetFrameRateVote::Seamlessness;
320 const auto frameRateCompatibility = [frameRate] {
321 switch (frameRate.type) {
322 case Layer::FrameRateCompatibility::Default:
323 return FrameRateCompatibility::Default;
324 case Layer::FrameRateCompatibility::ExactOrMultiple:
325 return FrameRateCompatibility::ExactOrMultiple;
326 default:
327 return FrameRateCompatibility::Undefined;
328 }
329 }();
330
331 const auto seamlessness = [frameRate] {
332 switch (frameRate.seamlessness) {
333 case scheduler::Seamlessness::OnlySeamless:
334 return Seamlessness::ShouldBeSeamless;
335 case scheduler::Seamlessness::SeamedAndSeamless:
336 return Seamlessness::NotRequired;
337 default:
338 return Seamlessness::Undefined;
339 }
340 }();
341
342 return TimeStats::SetFrameRateVote{.frameRate = frameRate.rate.getValue(),
343 .frameRateCompatibility = frameRateCompatibility,
344 .seamlessness = seamlessness};
345}
346} // namespace
David Sodman0c69cad2017-08-21 12:12:51 -0700347
Dominik Laskowskib7251f42020-04-20 17:42:59 -0700348bool BufferLayer::onPostComposition(const DisplayDevice* display,
Dominik Laskowski075d3172018-05-24 15:50:06 -0700349 const std::shared_ptr<FenceTime>& glDoneFence,
Marissa Wallfd668622018-05-10 10:21:13 -0700350 const std::shared_ptr<FenceTime>& presentFence,
351 const CompositorTiming& compositorTiming) {
352 // mFrameLatencyNeeded is true when a new frame was latched for the
353 // composition.
chaviw74b03172019-08-19 11:09:03 -0700354 if (!mBufferInfo.mFrameLatencyNeeded) return false;
Marissa Wallfd668622018-05-10 10:21:13 -0700355
356 // Update mFrameEventHistory.
Dan Stoza436ccf32018-06-21 12:10:12 -0700357 {
Marissa Wallfd668622018-05-10 10:21:13 -0700358 Mutex::Autolock lock(mFrameEventHistoryMutex);
359 mFrameEventHistory.addPostComposition(mCurrentFrameNumber, glDoneFence, presentFence,
360 compositorTiming);
Valerie Hau93d5a5e2020-02-13 14:50:01 -0800361 finalizeFrameEventHistory(glDoneFence, compositorTiming);
David Sodman0c69cad2017-08-21 12:12:51 -0700362 }
363
Marissa Wallfd668622018-05-10 10:21:13 -0700364 // Update mFrameTracker.
chaviw4244e032019-09-04 11:27:49 -0700365 nsecs_t desiredPresentTime = mBufferInfo.mDesiredPresentTime;
Marissa Wallfd668622018-05-10 10:21:13 -0700366 mFrameTracker.setDesiredPresentTime(desiredPresentTime);
367
Yiwei Zhang1a88c402019-11-18 10:43:58 -0800368 const int32_t layerId = getSequence();
369 mFlinger->mTimeStats->setDesiredTime(layerId, mCurrentFrameNumber, desiredPresentTime);
Marissa Wallfd668622018-05-10 10:21:13 -0700370
Dominik Laskowskib7251f42020-04-20 17:42:59 -0700371 const auto outputLayer = findOutputLayerForDisplay(display);
Adithya Srinivasanb69e0762019-11-11 18:39:53 -0800372 if (outputLayer && outputLayer->requiresClientComposition()) {
373 nsecs_t clientCompositionTimestamp = outputLayer->getState().clientCompositionTimestamp;
374 mFlinger->mFrameTracer->traceTimestamp(layerId, getCurrentBufferId(), mCurrentFrameNumber,
375 clientCompositionTimestamp,
376 FrameTracer::FrameEvent::FALLBACK_COMPOSITION);
Adithya Srinivasanb6a2fa12021-03-13 00:23:09 +0000377 // Update the SurfaceFrames in the drawing state
378 if (mDrawingState.bufferSurfaceFrameTX) {
379 mDrawingState.bufferSurfaceFrameTX->setGpuComposition();
380 }
381 for (auto& [token, surfaceFrame] : mDrawingState.bufferlessSurfaceFramesTX) {
382 surfaceFrame->setGpuComposition();
383 }
Adithya Srinivasanb69e0762019-11-11 18:39:53 -0800384 }
385
chaviw4244e032019-09-04 11:27:49 -0700386 std::shared_ptr<FenceTime> frameReadyFence = mBufferInfo.mFenceTime;
Marissa Wallfd668622018-05-10 10:21:13 -0700387 if (frameReadyFence->isValid()) {
388 mFrameTracker.setFrameReadyFence(std::move(frameReadyFence));
389 } else {
390 // There was no fence for this frame, so assume that it was ready
391 // to be presented at the desired present time.
392 mFrameTracker.setFrameReadyTime(desiredPresentTime);
Dominik Laskowski45de9bd2018-06-11 17:44:10 -0700393 }
Marissa Wallfd668622018-05-10 10:21:13 -0700394
Alec Mouri7d436ec2021-01-27 20:40:50 -0800395 const Fps refreshRate = mFlinger->mRefreshRateConfigs->getCurrentRefreshRate().getFps();
396 const std::optional<Fps> renderRate = mFlinger->mScheduler->getFrameRateOverride(getOwnerUid());
Marissa Wallfd668622018-05-10 10:21:13 -0700397 if (presentFence->isValid()) {
Alec Mouri7d436ec2021-01-27 20:40:50 -0800398 mFlinger->mTimeStats->setPresentFence(layerId, mCurrentFrameNumber, presentFence,
Ady Abraham8b9e6122021-01-26 19:11:45 -0800399 refreshRate, renderRate,
400 frameRateToSetFrameRateVotePayload(
Adithya Srinivasan58069dc2021-06-04 20:37:02 +0000401 mDrawingState.frameRate),
402 getGameMode());
Yiwei Zhang1a88c402019-11-18 10:43:58 -0800403 mFlinger->mFrameTracer->traceFence(layerId, getCurrentBufferId(), mCurrentFrameNumber,
Mikael Pessa90092f42019-08-26 17:22:04 -0700404 presentFence, FrameTracer::FrameEvent::PRESENT_FENCE);
Marissa Wallfd668622018-05-10 10:21:13 -0700405 mFrameTracker.setActualPresentFence(std::shared_ptr<FenceTime>(presentFence));
Dominik Laskowskib7251f42020-04-20 17:42:59 -0700406 } else if (!display) {
407 // Do nothing.
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200408 } else if (const auto displayId = PhysicalDisplayId::tryCast(display->getId());
Dominik Laskowskib7251f42020-04-20 17:42:59 -0700409 displayId && mFlinger->getHwComposer().isConnected(*displayId)) {
Marissa Wallfd668622018-05-10 10:21:13 -0700410 // The HWC doesn't support present fences, so use the refresh
411 // timestamp instead.
Marin Shalamanov045b7002021-01-07 16:56:24 +0100412 const nsecs_t actualPresentTime = display->getRefreshTimestamp();
Alec Mouri7d436ec2021-01-27 20:40:50 -0800413 mFlinger->mTimeStats->setPresentTime(layerId, mCurrentFrameNumber, actualPresentTime,
Ady Abraham8b9e6122021-01-26 19:11:45 -0800414 refreshRate, renderRate,
415 frameRateToSetFrameRateVotePayload(
Adithya Srinivasan58069dc2021-06-04 20:37:02 +0000416 mDrawingState.frameRate),
417 getGameMode());
Yiwei Zhang1a88c402019-11-18 10:43:58 -0800418 mFlinger->mFrameTracer->traceTimestamp(layerId, getCurrentBufferId(), mCurrentFrameNumber,
Mikael Pessa90092f42019-08-26 17:22:04 -0700419 actualPresentTime,
420 FrameTracer::FrameEvent::PRESENT_FENCE);
Marissa Wallfd668622018-05-10 10:21:13 -0700421 mFrameTracker.setActualPresentTime(actualPresentTime);
422 }
423
424 mFrameTracker.advanceFrame();
chaviw74b03172019-08-19 11:09:03 -0700425 mBufferInfo.mFrameLatencyNeeded = false;
Marissa Wallfd668622018-05-10 10:21:13 -0700426 return true;
David Sodman0c69cad2017-08-21 12:12:51 -0700427}
428
chaviwdebadb82020-03-26 14:57:24 -0700429void BufferLayer::gatherBufferInfo() {
430 mBufferInfo.mPixelFormat =
Alec Mouria90a5702021-04-16 16:36:21 +0000431 !mBufferInfo.mBuffer ? PIXEL_FORMAT_NONE : mBufferInfo.mBuffer->getBuffer()->format;
chaviwdebadb82020-03-26 14:57:24 -0700432 mBufferInfo.mFrameLatencyNeeded = true;
433}
434
Ady Abraham63a3e592021-01-06 10:47:15 -0800435bool BufferLayer::shouldPresentNow(nsecs_t expectedPresentTime) const {
436 // If this is not a valid vsync for the layer's uid, return and try again later
437 const bool isVsyncValidForUid =
438 mFlinger->mScheduler->isVsyncValid(expectedPresentTime, mOwnerUid);
439 if (!isVsyncValidForUid) {
440 ATRACE_NAME("!isVsyncValidForUid");
441 return false;
442 }
443
444 // AutoRefresh layers and sideband streams should always be presented
445 if (getSidebandStreamChanged() || getAutoRefresh()) {
446 return true;
447 }
448
Ady Abraham63a3e592021-01-06 10:47:15 -0800449 // If this layer doesn't have a frame is shouldn't be presented
450 if (!hasFrameUpdate()) {
451 return false;
452 }
453
454 // Defer to the derived class to decide whether the next buffer is due for
455 // presentation.
456 return isBufferDue(expectedPresentTime);
457}
458
Dominik Laskowskia8955dd2019-07-10 10:19:09 -0700459bool BufferLayer::latchBuffer(bool& recomputeVisibleRegions, nsecs_t latchTime,
460 nsecs_t expectedPresentTime) {
Marissa Wallfd668622018-05-10 10:21:13 -0700461 ATRACE_CALL();
David Sodman0c69cad2017-08-21 12:12:51 -0700462
Vishnu Nair6194e2e2019-02-06 12:58:39 -0800463 bool refreshRequired = latchSidebandStream(recomputeVisibleRegions);
David Sodman0c69cad2017-08-21 12:12:51 -0700464
Vishnu Nair6194e2e2019-02-06 12:58:39 -0800465 if (refreshRequired) {
466 return refreshRequired;
David Sodman0c69cad2017-08-21 12:12:51 -0700467 }
468
Marissa Wallfd668622018-05-10 10:21:13 -0700469 if (!hasReadyFrame()) {
Vishnu Nair6194e2e2019-02-06 12:58:39 -0800470 return false;
David Sodman0c69cad2017-08-21 12:12:51 -0700471 }
David Sodman0c69cad2017-08-21 12:12:51 -0700472
Marissa Wallfd668622018-05-10 10:21:13 -0700473 // if we've already called updateTexImage() without going through
474 // a composition step, we have to skip this layer at this point
475 // because we cannot call updateTeximage() without a corresponding
476 // compositionComplete() call.
477 // we'll trigger an update in onPreComposition().
478 if (mRefreshPending) {
Vishnu Nair6194e2e2019-02-06 12:58:39 -0800479 return false;
Marissa Wallfd668622018-05-10 10:21:13 -0700480 }
481
482 // If the head buffer's acquire fence hasn't signaled yet, return and
483 // try again later
484 if (!fenceHasSignaled()) {
Ady Abraham09bd3922019-04-08 10:44:56 -0700485 ATRACE_NAME("!fenceHasSignaled()");
David Sodman0c69cad2017-08-21 12:12:51 -0700486 mFlinger->signalLayerUpdate();
Vishnu Nair6194e2e2019-02-06 12:58:39 -0800487 return false;
Marissa Wallfd668622018-05-10 10:21:13 -0700488 }
489
490 // Capture the old state of the layer for comparisons later
491 const State& s(getDrawingState());
492 const bool oldOpacity = isOpaque(s);
chaviwd62d3062019-09-04 14:48:02 -0700493
494 BufferInfo oldBufferInfo = mBufferInfo;
Marissa Wallfd668622018-05-10 10:21:13 -0700495
Dominik Laskowskia8955dd2019-07-10 10:19:09 -0700496 status_t err = updateTexImage(recomputeVisibleRegions, latchTime, expectedPresentTime);
Marissa Wallfd668622018-05-10 10:21:13 -0700497 if (err != NO_ERROR) {
Vishnu Nair6194e2e2019-02-06 12:58:39 -0800498 return false;
Marissa Wallfd668622018-05-10 10:21:13 -0700499 }
500
501 err = updateActiveBuffer();
502 if (err != NO_ERROR) {
Vishnu Nair6194e2e2019-02-06 12:58:39 -0800503 return false;
Marissa Wallfd668622018-05-10 10:21:13 -0700504 }
505
Marissa Wallfd668622018-05-10 10:21:13 -0700506 err = updateFrameNumber(latchTime);
507 if (err != NO_ERROR) {
Vishnu Nair6194e2e2019-02-06 12:58:39 -0800508 return false;
Marissa Wallfd668622018-05-10 10:21:13 -0700509 }
510
chaviw4244e032019-09-04 11:27:49 -0700511 gatherBufferInfo();
512
Marissa Wallfd668622018-05-10 10:21:13 -0700513 mRefreshPending = true;
chaviwd62d3062019-09-04 14:48:02 -0700514 if (oldBufferInfo.mBuffer == nullptr) {
Marissa Wallfd668622018-05-10 10:21:13 -0700515 // the first time we receive a buffer, we need to trigger a
516 // geometry invalidation.
517 recomputeVisibleRegions = true;
518 }
519
chaviw4244e032019-09-04 11:27:49 -0700520 if ((mBufferInfo.mCrop != oldBufferInfo.mCrop) ||
521 (mBufferInfo.mTransform != oldBufferInfo.mTransform) ||
522 (mBufferInfo.mScaleMode != oldBufferInfo.mScaleMode) ||
523 (mBufferInfo.mTransformToDisplayInverse != oldBufferInfo.mTransformToDisplayInverse)) {
Marissa Wallfd668622018-05-10 10:21:13 -0700524 recomputeVisibleRegions = true;
525 }
526
chaviwd62d3062019-09-04 14:48:02 -0700527 if (oldBufferInfo.mBuffer != nullptr) {
Alec Mouria90a5702021-04-16 16:36:21 +0000528 uint32_t bufWidth = mBufferInfo.mBuffer->getBuffer()->getWidth();
529 uint32_t bufHeight = mBufferInfo.mBuffer->getBuffer()->getHeight();
530 if (bufWidth != uint32_t(oldBufferInfo.mBuffer->getBuffer()->width) ||
531 bufHeight != uint32_t(oldBufferInfo.mBuffer->getBuffer()->height)) {
Marissa Wallfd668622018-05-10 10:21:13 -0700532 recomputeVisibleRegions = true;
533 }
534 }
535
536 if (oldOpacity != isOpaque(s)) {
537 recomputeVisibleRegions = true;
538 }
539
Vishnu Nair6194e2e2019-02-06 12:58:39 -0800540 return true;
Marissa Wallfd668622018-05-10 10:21:13 -0700541}
542
Marissa Wallfd668622018-05-10 10:21:13 -0700543bool BufferLayer::hasReadyFrame() const {
Marissa Wall024a1912018-08-13 13:55:35 -0700544 return hasFrameUpdate() || getSidebandStreamChanged() || getAutoRefresh();
Marissa Wallfd668622018-05-10 10:21:13 -0700545}
546
547uint32_t BufferLayer::getEffectiveScalingMode() const {
chaviw4244e032019-09-04 11:27:49 -0700548 return mBufferInfo.mScaleMode;
Marissa Wallfd668622018-05-10 10:21:13 -0700549}
550
551bool BufferLayer::isProtected() const {
Alec Mouria90a5702021-04-16 16:36:21 +0000552 return (mBufferInfo.mBuffer != nullptr) &&
553 (mBufferInfo.mBuffer->getBuffer()->getUsage() & GRALLOC_USAGE_PROTECTED);
Marissa Wallfd668622018-05-10 10:21:13 -0700554}
555
David Sodman0c69cad2017-08-21 12:12:51 -0700556// As documented in libhardware header, formats in the range
557// 0x100 - 0x1FF are specific to the HAL implementation, and
558// are known to have no alpha channel
559// TODO: move definition for device-specific range into
560// hardware.h, instead of using hard-coded values here.
561#define HARDWARE_IS_DEVICE_FORMAT(f) ((f) >= 0x100 && (f) <= 0x1FF)
562
563bool BufferLayer::getOpacityForFormat(uint32_t format) {
564 if (HARDWARE_IS_DEVICE_FORMAT(format)) {
565 return true;
566 }
567 switch (format) {
568 case HAL_PIXEL_FORMAT_RGBA_8888:
569 case HAL_PIXEL_FORMAT_BGRA_8888:
570 case HAL_PIXEL_FORMAT_RGBA_FP16:
571 case HAL_PIXEL_FORMAT_RGBA_1010102:
572 return false;
573 }
574 // in all other case, we have no blending (also for unknown formats)
575 return true;
576}
577
Dominik Laskowskib7251f42020-04-20 17:42:59 -0700578bool BufferLayer::needsFiltering(const DisplayDevice* display) const {
579 const auto outputLayer = findOutputLayerForDisplay(display);
Lloyd Pique37c2c9b2018-12-04 17:25:10 -0800580 if (outputLayer == nullptr) {
Lloyd Piquef16688f2019-02-19 17:47:57 -0800581 return false;
Lloyd Pique37c2c9b2018-12-04 17:25:10 -0800582 }
583
Lloyd Piquef16688f2019-02-19 17:47:57 -0800584 // We need filtering if the sourceCrop rectangle size does not match the
585 // displayframe rectangle size (not a 1:1 render)
Lloyd Pique37c2c9b2018-12-04 17:25:10 -0800586 const auto& compositionState = outputLayer->getState();
587 const auto displayFrame = compositionState.displayFrame;
588 const auto sourceCrop = compositionState.sourceCrop;
Lloyd Piquef16688f2019-02-19 17:47:57 -0800589 return sourceCrop.getHeight() != displayFrame.getHeight() ||
Peiyong Linc2020ca2019-01-10 11:36:12 -0800590 sourceCrop.getWidth() != displayFrame.getWidth();
Chia-I Wu692e0832018-06-05 15:46:58 -0700591}
592
Dominik Laskowskib7251f42020-04-20 17:42:59 -0700593bool BufferLayer::needsFilteringForScreenshots(const DisplayDevice* display,
Alec Mouri5a6d8572020-03-23 23:56:15 -0700594 const ui::Transform& inverseParentTransform) const {
Dominik Laskowskib7251f42020-04-20 17:42:59 -0700595 const auto outputLayer = findOutputLayerForDisplay(display);
Alec Mouri5a6d8572020-03-23 23:56:15 -0700596 if (outputLayer == nullptr) {
597 return false;
598 }
599
600 // We need filtering if the sourceCrop rectangle size does not match the
601 // viewport rectangle size (not a 1:1 render)
602 const auto& compositionState = outputLayer->getState();
Dominik Laskowskib7251f42020-04-20 17:42:59 -0700603 const ui::Transform& displayTransform = display->getTransform();
Alec Mouri5a6d8572020-03-23 23:56:15 -0700604 const ui::Transform inverseTransform = inverseParentTransform * displayTransform.inverse();
605 // Undo the transformation of the displayFrame so that we're back into
606 // layer-stack space.
607 const Rect frame = inverseTransform.transform(compositionState.displayFrame);
608 const FloatRect sourceCrop = compositionState.sourceCrop;
609
610 int32_t frameHeight = frame.getHeight();
611 int32_t frameWidth = frame.getWidth();
612 // If the display transform had a rotational component then undo the
613 // rotation so that the orientation matches the source crop.
614 if (displayTransform.getOrientation() & ui::Transform::ROT_90) {
615 std::swap(frameHeight, frameWidth);
616 }
617 return sourceCrop.getHeight() != frameHeight || sourceCrop.getWidth() != frameWidth;
618}
619
Dominik Laskowskia8955dd2019-07-10 10:19:09 -0700620uint64_t BufferLayer::getHeadFrameNumber(nsecs_t expectedPresentTime) const {
Lloyd Pique0449b0f2018-12-20 16:23:45 -0800621 if (hasFrameUpdate()) {
Dominik Laskowskia8955dd2019-07-10 10:19:09 -0700622 return getFrameNumber(expectedPresentTime);
David Sodman0c69cad2017-08-21 12:12:51 -0700623 } else {
624 return mCurrentFrameNumber;
625 }
626}
627
Vishnu Nair60356342018-11-13 13:00:45 -0800628Rect BufferLayer::getBufferSize(const State& s) const {
629 // If we have a sideband stream, or we are scaling the buffer then return the layer size since
630 // we cannot determine the buffer size.
631 if ((s.sidebandStream != nullptr) ||
632 (getEffectiveScalingMode() != NATIVE_WINDOW_SCALING_MODE_FREEZE)) {
633 return Rect(getActiveWidth(s), getActiveHeight(s));
634 }
635
chaviwd62d3062019-09-04 14:48:02 -0700636 if (mBufferInfo.mBuffer == nullptr) {
Vishnu Nair60356342018-11-13 13:00:45 -0800637 return Rect::INVALID_RECT;
638 }
639
Alec Mouria90a5702021-04-16 16:36:21 +0000640 uint32_t bufWidth = mBufferInfo.mBuffer->getBuffer()->getWidth();
641 uint32_t bufHeight = mBufferInfo.mBuffer->getBuffer()->getHeight();
Vishnu Nair60356342018-11-13 13:00:45 -0800642
643 // Undo any transformations on the buffer and return the result.
chaviw4244e032019-09-04 11:27:49 -0700644 if (mBufferInfo.mTransform & ui::Transform::ROT_90) {
Vishnu Nair60356342018-11-13 13:00:45 -0800645 std::swap(bufWidth, bufHeight);
646 }
647
Lloyd Pique0449b0f2018-12-20 16:23:45 -0800648 if (getTransformToDisplayInverse()) {
Dominik Laskowski718f9602019-11-09 20:01:35 -0800649 uint32_t invTransform = DisplayDevice::getPrimaryDisplayRotationFlags();
Vishnu Nair60356342018-11-13 13:00:45 -0800650 if (invTransform & ui::Transform::ROT_90) {
651 std::swap(bufWidth, bufHeight);
652 }
653 }
654
655 return Rect(bufWidth, bufHeight);
656}
657
Vishnu Nair4351ad52019-02-11 14:13:02 -0800658FloatRect BufferLayer::computeSourceBounds(const FloatRect& parentBounds) const {
659 const State& s(getDrawingState());
660
661 // If we have a sideband stream, or we are scaling the buffer then return the layer size since
662 // we cannot determine the buffer size.
663 if ((s.sidebandStream != nullptr) ||
664 (getEffectiveScalingMode() != NATIVE_WINDOW_SCALING_MODE_FREEZE)) {
665 return FloatRect(0, 0, getActiveWidth(s), getActiveHeight(s));
666 }
667
chaviwd62d3062019-09-04 14:48:02 -0700668 if (mBufferInfo.mBuffer == nullptr) {
Vishnu Nair4351ad52019-02-11 14:13:02 -0800669 return parentBounds;
670 }
671
Alec Mouria90a5702021-04-16 16:36:21 +0000672 uint32_t bufWidth = mBufferInfo.mBuffer->getBuffer()->getWidth();
673 uint32_t bufHeight = mBufferInfo.mBuffer->getBuffer()->getHeight();
Vishnu Nair4351ad52019-02-11 14:13:02 -0800674
675 // Undo any transformations on the buffer and return the result.
chaviw4244e032019-09-04 11:27:49 -0700676 if (mBufferInfo.mTransform & ui::Transform::ROT_90) {
Vishnu Nair4351ad52019-02-11 14:13:02 -0800677 std::swap(bufWidth, bufHeight);
678 }
679
680 if (getTransformToDisplayInverse()) {
Dominik Laskowski718f9602019-11-09 20:01:35 -0800681 uint32_t invTransform = DisplayDevice::getPrimaryDisplayRotationFlags();
Vishnu Nair4351ad52019-02-11 14:13:02 -0800682 if (invTransform & ui::Transform::ROT_90) {
683 std::swap(bufWidth, bufHeight);
684 }
685 }
686
687 return FloatRect(0, 0, bufWidth, bufHeight);
688}
689
chaviw49a108c2019-08-12 11:23:06 -0700690void BufferLayer::latchAndReleaseBuffer() {
691 mRefreshPending = false;
692 if (hasReadyFrame()) {
693 bool ignored = false;
694 latchBuffer(ignored, systemTime(), 0 /* expectedPresentTime */);
695 }
696 releasePendingBuffer(systemTime());
697}
698
chaviw4244e032019-09-04 11:27:49 -0700699PixelFormat BufferLayer::getPixelFormat() const {
700 return mBufferInfo.mPixelFormat;
701}
702
703bool BufferLayer::getTransformToDisplayInverse() const {
704 return mBufferInfo.mTransformToDisplayInverse;
705}
706
707Rect BufferLayer::getBufferCrop() const {
708 // this is the crop rectangle that applies to the buffer
709 // itself (as opposed to the window)
710 if (!mBufferInfo.mCrop.isEmpty()) {
711 // if the buffer crop is defined, we use that
712 return mBufferInfo.mCrop;
chaviwd62d3062019-09-04 14:48:02 -0700713 } else if (mBufferInfo.mBuffer != nullptr) {
chaviw4244e032019-09-04 11:27:49 -0700714 // otherwise we use the whole buffer
Alec Mouria90a5702021-04-16 16:36:21 +0000715 return mBufferInfo.mBuffer->getBuffer()->getBounds();
chaviw4244e032019-09-04 11:27:49 -0700716 } else {
717 // if we don't have a buffer yet, we use an empty/invalid crop
718 return Rect();
719 }
720}
721
722uint32_t BufferLayer::getBufferTransform() const {
723 return mBufferInfo.mTransform;
724}
725
726ui::Dataspace BufferLayer::getDataSpace() const {
727 return mBufferInfo.mDataspace;
728}
729
730ui::Dataspace BufferLayer::translateDataspace(ui::Dataspace dataspace) {
731 ui::Dataspace updatedDataspace = dataspace;
732 // translate legacy dataspaces to modern dataspaces
733 switch (dataspace) {
734 case ui::Dataspace::SRGB:
735 updatedDataspace = ui::Dataspace::V0_SRGB;
736 break;
737 case ui::Dataspace::SRGB_LINEAR:
738 updatedDataspace = ui::Dataspace::V0_SRGB_LINEAR;
739 break;
740 case ui::Dataspace::JFIF:
741 updatedDataspace = ui::Dataspace::V0_JFIF;
742 break;
743 case ui::Dataspace::BT601_625:
744 updatedDataspace = ui::Dataspace::V0_BT601_625;
745 break;
746 case ui::Dataspace::BT601_525:
747 updatedDataspace = ui::Dataspace::V0_BT601_525;
748 break;
749 case ui::Dataspace::BT709:
750 updatedDataspace = ui::Dataspace::V0_BT709;
751 break;
752 default:
753 break;
754 }
755
756 return updatedDataspace;
757}
758
chaviwd62d3062019-09-04 14:48:02 -0700759sp<GraphicBuffer> BufferLayer::getBuffer() const {
Alec Mouria90a5702021-04-16 16:36:21 +0000760 return mBufferInfo.mBuffer ? mBufferInfo.mBuffer->getBuffer() : nullptr;
chaviwd62d3062019-09-04 14:48:02 -0700761}
762
chaviwf83ce182019-09-12 14:43:08 -0700763void BufferLayer::getDrawingTransformMatrix(bool filteringEnabled, float outMatrix[16]) {
Alec Mouria90a5702021-04-16 16:36:21 +0000764 GLConsumer::computeTransformMatrix(outMatrix,
765 mBufferInfo.mBuffer ? mBufferInfo.mBuffer->getBuffer()
766 : nullptr,
767 mBufferInfo.mCrop, mBufferInfo.mTransform, filteringEnabled);
chaviwf83ce182019-09-12 14:43:08 -0700768}
769
chaviwb4c6e582019-08-16 14:35:07 -0700770void BufferLayer::setInitialValuesForClone(const sp<Layer>& clonedFrom) {
771 Layer::setInitialValuesForClone(clonedFrom);
772
773 sp<BufferLayer> bufferClonedFrom = static_cast<BufferLayer*>(clonedFrom.get());
774 mPremultipliedAlpha = bufferClonedFrom->mPremultipliedAlpha;
775 mPotentialCursor = bufferClonedFrom->mPotentialCursor;
776 mProtectedByApp = bufferClonedFrom->mProtectedByApp;
chaviw74b03172019-08-19 11:09:03 -0700777
778 updateCloneBufferInfo();
779}
780
781void BufferLayer::updateCloneBufferInfo() {
782 if (!isClone() || !isClonedFromAlive()) {
783 return;
784 }
785
786 sp<BufferLayer> clonedFrom = static_cast<BufferLayer*>(getClonedFrom().get());
787 mBufferInfo = clonedFrom->mBufferInfo;
788 mSidebandStream = clonedFrom->mSidebandStream;
789 surfaceDamageRegion = clonedFrom->surfaceDamageRegion;
790 mCurrentFrameNumber = clonedFrom->mCurrentFrameNumber.load();
791 mPreviousFrameNumber = clonedFrom->mPreviousFrameNumber;
792
793 // After buffer info is updated, the drawingState from the real layer needs to be copied into
794 // the cloned. This is because some properties of drawingState can change when latchBuffer is
chaviwaf87b3e2019-10-01 16:59:28 -0700795 // called. However, copying the drawingState would also overwrite the cloned layer's relatives
796 // and touchableRegionCrop. Therefore, temporarily store the relatives so they can be set in
797 // the cloned drawingState again.
chaviw74b03172019-08-19 11:09:03 -0700798 wp<Layer> tmpZOrderRelativeOf = mDrawingState.zOrderRelativeOf;
799 SortedVector<wp<Layer>> tmpZOrderRelatives = mDrawingState.zOrderRelatives;
chaviwaf87b3e2019-10-01 16:59:28 -0700800 wp<Layer> tmpTouchableRegionCrop = mDrawingState.touchableRegionCrop;
chaviw98318de2021-05-19 16:45:23 -0500801 WindowInfo tmpInputInfo = mDrawingState.inputInfo;
chaviwaf87b3e2019-10-01 16:59:28 -0700802
chaviw74b03172019-08-19 11:09:03 -0700803 mDrawingState = clonedFrom->mDrawingState;
chaviwaf87b3e2019-10-01 16:59:28 -0700804
805 mDrawingState.touchableRegionCrop = tmpTouchableRegionCrop;
chaviw74b03172019-08-19 11:09:03 -0700806 mDrawingState.zOrderRelativeOf = tmpZOrderRelativeOf;
807 mDrawingState.zOrderRelatives = tmpZOrderRelatives;
chaviwaf87b3e2019-10-01 16:59:28 -0700808 mDrawingState.inputInfo = tmpInputInfo;
chaviwb4c6e582019-08-16 14:35:07 -0700809}
810
Dominik Laskowskib7251f42020-04-20 17:42:59 -0700811void BufferLayer::setTransformHint(ui::Transform::RotationFlags displayTransformHint) {
Vishnu Nair6213bd92020-05-08 17:42:25 -0700812 mTransformHint = getFixedTransformHint();
813 if (mTransformHint == ui::Transform::ROT_INVALID) {
814 mTransformHint = displayTransformHint;
815 }
816}
817
Vishnu Naire7f79c52020-10-29 14:45:03 -0700818bool BufferLayer::bufferNeedsFiltering() const {
819 return isFixedSize();
820}
821
David Sodman0c69cad2017-08-21 12:12:51 -0700822} // namespace android
823
824#if defined(__gl_h_)
825#error "don't include gl/gl.h in this file"
826#endif
827
828#if defined(__gl2_h_)
829#error "don't include gl2/gl2.h in this file"
830#endif
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -0800831
832// TODO(b/129481165): remove the #pragma below and fix conversion issues
833#pragma clang diagnostic pop // ignored "-Wconversion"