blob: d3364a09290dae437793c7ba66f29561b2f24cef [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,
chaviw214c89d2019-09-04 16:03:53 -070032 int32_t overrideScalingMode, bool transformToDisplayInverse)
33 : mFront(front),
34 mCurrent(current),
35 mRecomputeVisibleRegions(recomputeVisibleRegions),
36 mStickyTransformSet(stickySet),
37 mName(name),
38 mOverrideScalingMode(overrideScalingMode),
39 mTransformToDisplayInverse(transformToDisplayInverse) {}
Fabien Sanglard7b1563a2016-10-13 12:05:28 -070040
41bool LayerRejecter::reject(const sp<GraphicBuffer>& buf, const BufferItem& item) {
Peiyong Lin566a3b42018-01-09 18:22:43 -080042 if (buf == nullptr) {
Fabien Sanglard7b1563a2016-10-13 12:05:28 -070043 return false;
44 }
45
46 uint32_t bufWidth = buf->getWidth();
47 uint32_t bufHeight = buf->getHeight();
48
49 // check that we received a buffer of the right size
50 // (Take the buffer's orientation into account)
Peiyong Linefefaac2018-08-17 12:27:51 -070051 if (item.mTransform & ui::Transform::ROT_90) {
Peiyong Lin3db42342018-08-16 09:15:59 -070052 std::swap(bufWidth, bufHeight);
Fabien Sanglard7b1563a2016-10-13 12:05:28 -070053 }
54
Robert Carr35f0dda2018-05-03 15:47:23 -070055 if (mTransformToDisplayInverse) {
Dominik Laskowski718f9602019-11-09 20:01:35 -080056 uint32_t invTransform = DisplayDevice::getPrimaryDisplayRotationFlags();
Peiyong Linefefaac2018-08-17 12:27:51 -070057 if (invTransform & ui::Transform::ROT_90) {
Peiyong Lin3db42342018-08-16 09:15:59 -070058 std::swap(bufWidth, bufHeight);
Robert Carr35f0dda2018-05-03 15:47:23 -070059 }
60 }
61
Fabien Sanglard7b1563a2016-10-13 12:05:28 -070062 int actualScalingMode = mOverrideScalingMode >= 0 ? mOverrideScalingMode : item.mScalingMode;
63 bool isFixedSize = actualScalingMode != NATIVE_WINDOW_SCALING_MODE_FREEZE;
Marissa Wallf58c14b2018-07-24 10:50:43 -070064 if (mFront.active_legacy != mFront.requested_legacy) {
65 if (isFixedSize ||
66 (bufWidth == mFront.requested_legacy.w && bufHeight == mFront.requested_legacy.h)) {
Fabien Sanglard7b1563a2016-10-13 12:05:28 -070067 // Here we pretend the transaction happened by updating the
68 // current and drawing states. Drawing state is only accessed
69 // in this thread, no need to have it locked
Marissa Wallf58c14b2018-07-24 10:50:43 -070070 mFront.active_legacy = mFront.requested_legacy;
Fabien Sanglard7b1563a2016-10-13 12:05:28 -070071
72 // We also need to update the current state so that
73 // we don't end-up overwriting the drawing state with
74 // this stale current state during the next transaction
75 //
76 // NOTE: We don't need to hold the transaction lock here
Marissa Wallf58c14b2018-07-24 10:50:43 -070077 // because State::active_legacy is only accessed from this thread.
78 mCurrent.active_legacy = mFront.active_legacy;
Fabien Sanglard7b1563a2016-10-13 12:05:28 -070079 mCurrent.modified = true;
80
81 // recompute visible region
82 mRecomputeVisibleRegions = true;
Robert Carr7bf247e2017-05-18 14:02:49 -070083
Marissa Wallf58c14b2018-07-24 10:50:43 -070084 if (mFront.crop_legacy != mFront.requestedCrop_legacy) {
85 mFront.crop_legacy = mFront.requestedCrop_legacy;
86 mCurrent.crop_legacy = mFront.requestedCrop_legacy;
Robert Carr7bf247e2017-05-18 14:02:49 -070087 mRecomputeVisibleRegions = true;
88 }
Fabien Sanglard7b1563a2016-10-13 12:05:28 -070089 }
90
91 ALOGD_IF(DEBUG_RESIZE,
92 "[%s] latchBuffer/reject: buffer (%ux%u, tr=%02x), scalingMode=%d\n"
Marissa Wall61c58622018-07-18 10:12:20 -070093 " drawing={ active_legacy ={ wh={%4u,%4u} crop_legacy={%4d,%4d,%4d,%4d} "
94 "(%4d,%4d) "
Fabien Sanglard7b1563a2016-10-13 12:05:28 -070095 "}\n"
Marissa Wallf58c14b2018-07-24 10:50:43 -070096 " requested_legacy={ wh={%4u,%4u} }}\n",
Dominik Laskowski87a07e42019-10-10 20:38:02 -070097 mName.c_str(), bufWidth, bufHeight, item.mTransform, item.mScalingMode,
Marissa Wallf58c14b2018-07-24 10:50:43 -070098 mFront.active_legacy.w, mFront.active_legacy.h, mFront.crop_legacy.left,
99 mFront.crop_legacy.top, mFront.crop_legacy.right, mFront.crop_legacy.bottom,
100 mFront.crop_legacy.getWidth(), mFront.crop_legacy.getHeight(),
101 mFront.requested_legacy.w, mFront.requested_legacy.h);
Fabien Sanglard7b1563a2016-10-13 12:05:28 -0700102 }
103
104 if (!isFixedSize && !mStickyTransformSet) {
Marissa Wallf58c14b2018-07-24 10:50:43 -0700105 if (mFront.active_legacy.w != bufWidth || mFront.active_legacy.h != bufHeight) {
Fabien Sanglard7b1563a2016-10-13 12:05:28 -0700106 // reject this buffer
107 ALOGE("[%s] rejecting buffer: "
Marissa Wallf58c14b2018-07-24 10:50:43 -0700108 "bufWidth=%d, bufHeight=%d, front.active_legacy.{w=%d, h=%d}",
Dominik Laskowski87a07e42019-10-10 20:38:02 -0700109 mName.c_str(), bufWidth, bufHeight, mFront.active_legacy.w,
110 mFront.active_legacy.h);
Fabien Sanglard7b1563a2016-10-13 12:05:28 -0700111 return true;
112 }
113 }
114
115 // if the transparent region has changed (this test is
116 // conservative, but that's fine, worst case we're doing
117 // a bit of extra work), we latch the new one and we
118 // trigger a visible-region recompute.
Robert Carr7bf247e2017-05-18 14:02:49 -0700119 //
120 // We latch the transparent region here, instead of above where we latch
121 // the rest of the geometry because it is only content but not necessarily
122 // resize dependent.
Marissa Wallf58c14b2018-07-24 10:50:43 -0700123 if (!mFront.activeTransparentRegion_legacy.isTriviallyEqual(
124 mFront.requestedTransparentRegion_legacy)) {
125 mFront.activeTransparentRegion_legacy = mFront.requestedTransparentRegion_legacy;
Fabien Sanglard7b1563a2016-10-13 12:05:28 -0700126
127 // We also need to update the current state so that
128 // we don't end-up overwriting the drawing state with
129 // this stale current state during the next transaction
130 //
131 // NOTE: We don't need to hold the transaction lock here
Marissa Wallf58c14b2018-07-24 10:50:43 -0700132 // because State::active_legacy is only accessed from this thread.
133 mCurrent.activeTransparentRegion_legacy = mFront.activeTransparentRegion_legacy;
Fabien Sanglard7b1563a2016-10-13 12:05:28 -0700134
135 // recompute visible region
136 mRecomputeVisibleRegions = true;
137 }
138
Fabien Sanglard7b1563a2016-10-13 12:05:28 -0700139 return false;
140}
141
Mathias Agopiana9347642017-02-13 16:42:28 -0800142} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -0800143
144// TODO(b/129481165): remove the #pragma below and fix conversion issues
145#pragma clang diagnostic pop // ignored "-Wconversion"