blob: 1c0263ba0bb8451b3b45f42d266ac8e13041331b [file] [log] [blame]
Fabien Sanglard7b1563a2016-10-13 12:05:28 -07001/*
2 * Copyright (C) 2011 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
Fabien Sanglard7b1563a2016-10-13 12:05:28 -070021#include "LayerRejecter.h"
22
Mathias Agopiana9347642017-02-13 16:42:28 -080023#include <gui/BufferItem.h>
Mathias Agopian6a3c05b2017-04-27 20:06:55 -070024#include <system/window.h>
Mathias Agopiana9347642017-02-13 16:42:28 -080025
Fabien Sanglard7b1563a2016-10-13 12:05:28 -070026#define DEBUG_RESIZE 0
27
28namespace android {
29
chaviw214c89d2019-09-04 16:03:53 -070030LayerRejecter::LayerRejecter(Layer::State& front, Layer::State& current,
Dominik Laskowski87a07e42019-10-10 20:38:02 -070031 bool& recomputeVisibleRegions, bool stickySet, const std::string& name,
Robert Carr916b0362020-10-06 13:53:03 -070032 bool transformToDisplayInverse)
chaviw214c89d2019-09-04 16:03:53 -070033 : mFront(front),
34 mCurrent(current),
35 mRecomputeVisibleRegions(recomputeVisibleRegions),
36 mStickyTransformSet(stickySet),
37 mName(name),
chaviw214c89d2019-09-04 16:03:53 -070038 mTransformToDisplayInverse(transformToDisplayInverse) {}
Fabien Sanglard7b1563a2016-10-13 12:05:28 -070039
40bool LayerRejecter::reject(const sp<GraphicBuffer>& buf, const BufferItem& item) {
Peiyong Lin566a3b42018-01-09 18:22:43 -080041 if (buf == nullptr) {
Fabien Sanglard7b1563a2016-10-13 12:05:28 -070042 return false;
43 }
44
45 uint32_t bufWidth = buf->getWidth();
46 uint32_t bufHeight = buf->getHeight();
47
48 // check that we received a buffer of the right size
49 // (Take the buffer's orientation into account)
Peiyong Linefefaac2018-08-17 12:27:51 -070050 if (item.mTransform & ui::Transform::ROT_90) {
Peiyong Lin3db42342018-08-16 09:15:59 -070051 std::swap(bufWidth, bufHeight);
Fabien Sanglard7b1563a2016-10-13 12:05:28 -070052 }
53
Robert Carr35f0dda2018-05-03 15:47:23 -070054 if (mTransformToDisplayInverse) {
Dominik Laskowski718f9602019-11-09 20:01:35 -080055 uint32_t invTransform = DisplayDevice::getPrimaryDisplayRotationFlags();
Peiyong Linefefaac2018-08-17 12:27:51 -070056 if (invTransform & ui::Transform::ROT_90) {
Peiyong Lin3db42342018-08-16 09:15:59 -070057 std::swap(bufWidth, bufHeight);
Robert Carr35f0dda2018-05-03 15:47:23 -070058 }
59 }
60
Robert Carr916b0362020-10-06 13:53:03 -070061 int actualScalingMode = item.mScalingMode;
Fabien Sanglard7b1563a2016-10-13 12:05:28 -070062 bool isFixedSize = actualScalingMode != NATIVE_WINDOW_SCALING_MODE_FREEZE;
Marissa Wallf58c14b2018-07-24 10:50:43 -070063 if (mFront.active_legacy != mFront.requested_legacy) {
64 if (isFixedSize ||
65 (bufWidth == mFront.requested_legacy.w && bufHeight == mFront.requested_legacy.h)) {
Fabien Sanglard7b1563a2016-10-13 12:05:28 -070066 // Here we pretend the transaction happened by updating the
67 // current and drawing states. Drawing state is only accessed
68 // in this thread, no need to have it locked
Marissa Wallf58c14b2018-07-24 10:50:43 -070069 mFront.active_legacy = mFront.requested_legacy;
Fabien Sanglard7b1563a2016-10-13 12:05:28 -070070
71 // We also need to update the current state so that
72 // we don't end-up overwriting the drawing state with
73 // this stale current state during the next transaction
74 //
75 // NOTE: We don't need to hold the transaction lock here
Marissa Wallf58c14b2018-07-24 10:50:43 -070076 // because State::active_legacy is only accessed from this thread.
77 mCurrent.active_legacy = mFront.active_legacy;
Fabien Sanglard7b1563a2016-10-13 12:05:28 -070078 mCurrent.modified = true;
79
80 // recompute visible region
81 mRecomputeVisibleRegions = true;
Robert Carr7bf247e2017-05-18 14:02:49 -070082
chaviw25714502021-02-11 10:01:08 -080083 if (mFront.crop != mFront.requestedCrop) {
84 mFront.crop = mFront.requestedCrop;
85 mCurrent.crop = mFront.requestedCrop;
Robert Carr7bf247e2017-05-18 14:02:49 -070086 mRecomputeVisibleRegions = true;
87 }
Fabien Sanglard7b1563a2016-10-13 12:05:28 -070088 }
89
90 ALOGD_IF(DEBUG_RESIZE,
91 "[%s] latchBuffer/reject: buffer (%ux%u, tr=%02x), scalingMode=%d\n"
chaviw25714502021-02-11 10:01:08 -080092 " drawing={ active_legacy ={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} "
Marissa Wall61c58622018-07-18 10:12:20 -070093 "(%4d,%4d) "
Fabien Sanglard7b1563a2016-10-13 12:05:28 -070094 "}\n"
Marissa Wallf58c14b2018-07-24 10:50:43 -070095 " requested_legacy={ wh={%4u,%4u} }}\n",
Dominik Laskowski87a07e42019-10-10 20:38:02 -070096 mName.c_str(), bufWidth, bufHeight, item.mTransform, item.mScalingMode,
chaviw25714502021-02-11 10:01:08 -080097 mFront.active_legacy.w, mFront.active_legacy.h, mFront.crop.left, mFront.crop.top,
98 mFront.crop.right, mFront.crop.bottom, mFront.crop.getWidth(),
99 mFront.crop.getHeight(), mFront.requested_legacy.w, mFront.requested_legacy.h);
Fabien Sanglard7b1563a2016-10-13 12:05:28 -0700100 }
101
102 if (!isFixedSize && !mStickyTransformSet) {
Marissa Wallf58c14b2018-07-24 10:50:43 -0700103 if (mFront.active_legacy.w != bufWidth || mFront.active_legacy.h != bufHeight) {
Fabien Sanglard7b1563a2016-10-13 12:05:28 -0700104 // reject this buffer
105 ALOGE("[%s] rejecting buffer: "
Marissa Wallf58c14b2018-07-24 10:50:43 -0700106 "bufWidth=%d, bufHeight=%d, front.active_legacy.{w=%d, h=%d}",
Dominik Laskowski87a07e42019-10-10 20:38:02 -0700107 mName.c_str(), bufWidth, bufHeight, mFront.active_legacy.w,
108 mFront.active_legacy.h);
Fabien Sanglard7b1563a2016-10-13 12:05:28 -0700109 return true;
110 }
111 }
112
113 // if the transparent region has changed (this test is
114 // conservative, but that's fine, worst case we're doing
115 // a bit of extra work), we latch the new one and we
116 // trigger a visible-region recompute.
Robert Carr7bf247e2017-05-18 14:02:49 -0700117 //
118 // We latch the transparent region here, instead of above where we latch
119 // the rest of the geometry because it is only content but not necessarily
120 // resize dependent.
Arthur Hungd9a25c42020-03-03 18:59:19 +0800121 if (!mFront.activeTransparentRegion_legacy.hasSameRects(
Marissa Wallf58c14b2018-07-24 10:50:43 -0700122 mFront.requestedTransparentRegion_legacy)) {
123 mFront.activeTransparentRegion_legacy = mFront.requestedTransparentRegion_legacy;
Fabien Sanglard7b1563a2016-10-13 12:05:28 -0700124
125 // We also need to update the current state so that
126 // we don't end-up overwriting the drawing state with
127 // this stale current state during the next transaction
128 //
129 // NOTE: We don't need to hold the transaction lock here
Marissa Wallf58c14b2018-07-24 10:50:43 -0700130 // because State::active_legacy is only accessed from this thread.
131 mCurrent.activeTransparentRegion_legacy = mFront.activeTransparentRegion_legacy;
Fabien Sanglard7b1563a2016-10-13 12:05:28 -0700132
133 // recompute visible region
134 mRecomputeVisibleRegions = true;
135 }
136
Fabien Sanglard7b1563a2016-10-13 12:05:28 -0700137 return false;
138}
139
Mathias Agopiana9347642017-02-13 16:42:28 -0800140} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -0800141
142// TODO(b/129481165): remove the #pragma below and fix conversion issues
143#pragma clang diagnostic pop // ignored "-Wconversion"