blob: 136cdc03f77ada4d08fe49f2b9c7ad672dc0090b [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
17#include "LayerRejecter.h"
18
Mathias Agopiana9347642017-02-13 16:42:28 -080019#include <gui/BufferItem.h>
Mathias Agopian6a3c05b2017-04-27 20:06:55 -070020#include <system/window.h>
Mathias Agopiana9347642017-02-13 16:42:28 -080021
Fabien Sanglard7b1563a2016-10-13 12:05:28 -070022#define DEBUG_RESIZE 0
23
24namespace android {
25
26LayerRejecter::LayerRejecter(Layer::State& front,
27 Layer::State& current,
28 bool& recomputeVisibleRegions,
29 bool stickySet,
30 const char* name,
31 int32_t overrideScalingMode,
Robert Carr35f0dda2018-05-03 15:47:23 -070032 bool transformToDisplayInverse,
Fabien Sanglard7b1563a2016-10-13 12:05:28 -070033 bool& freezePositionUpdates)
34 : mFront(front),
35 mCurrent(current),
36 mRecomputeVisibleRegions(recomputeVisibleRegions),
37 mStickyTransformSet(stickySet),
38 mName(name),
39 mOverrideScalingMode(overrideScalingMode),
Robert Carr35f0dda2018-05-03 15:47:23 -070040 mTransformToDisplayInverse(transformToDisplayInverse),
Robert Carr7bf247e2017-05-18 14:02:49 -070041 mFreezeGeometryUpdates(freezePositionUpdates) {}
Fabien Sanglard7b1563a2016-10-13 12:05:28 -070042
43bool LayerRejecter::reject(const sp<GraphicBuffer>& buf, const BufferItem& item) {
Peiyong Lin566a3b42018-01-09 18:22:43 -080044 if (buf == nullptr) {
Fabien Sanglard7b1563a2016-10-13 12:05:28 -070045 return false;
46 }
47
48 uint32_t bufWidth = buf->getWidth();
49 uint32_t bufHeight = buf->getHeight();
50
51 // check that we received a buffer of the right size
52 // (Take the buffer's orientation into account)
Peiyong Linefefaac2018-08-17 12:27:51 -070053 if (item.mTransform & ui::Transform::ROT_90) {
Peiyong Lin3db42342018-08-16 09:15:59 -070054 std::swap(bufWidth, bufHeight);
Fabien Sanglard7b1563a2016-10-13 12:05:28 -070055 }
56
Robert Carr35f0dda2018-05-03 15:47:23 -070057 if (mTransformToDisplayInverse) {
58 uint32_t invTransform = DisplayDevice::getPrimaryDisplayOrientationTransform();
Peiyong Linefefaac2018-08-17 12:27:51 -070059 if (invTransform & ui::Transform::ROT_90) {
Peiyong Lin3db42342018-08-16 09:15:59 -070060 std::swap(bufWidth, bufHeight);
Robert Carr35f0dda2018-05-03 15:47:23 -070061 }
62 }
63
Fabien Sanglard7b1563a2016-10-13 12:05:28 -070064 int actualScalingMode = mOverrideScalingMode >= 0 ? mOverrideScalingMode : item.mScalingMode;
65 bool isFixedSize = actualScalingMode != NATIVE_WINDOW_SCALING_MODE_FREEZE;
Marissa Wallf58c14b2018-07-24 10:50:43 -070066 if (mFront.active_legacy != mFront.requested_legacy) {
67 if (isFixedSize ||
68 (bufWidth == mFront.requested_legacy.w && bufHeight == mFront.requested_legacy.h)) {
Fabien Sanglard7b1563a2016-10-13 12:05:28 -070069 // Here we pretend the transaction happened by updating the
70 // current and drawing states. Drawing state is only accessed
71 // in this thread, no need to have it locked
Marissa Wallf58c14b2018-07-24 10:50:43 -070072 mFront.active_legacy = mFront.requested_legacy;
Fabien Sanglard7b1563a2016-10-13 12:05:28 -070073
74 // We also need to update the current state so that
75 // we don't end-up overwriting the drawing state with
76 // this stale current state during the next transaction
77 //
78 // NOTE: We don't need to hold the transaction lock here
Marissa Wallf58c14b2018-07-24 10:50:43 -070079 // because State::active_legacy is only accessed from this thread.
80 mCurrent.active_legacy = mFront.active_legacy;
Fabien Sanglard7b1563a2016-10-13 12:05:28 -070081 mCurrent.modified = true;
82
83 // recompute visible region
84 mRecomputeVisibleRegions = true;
Robert Carr7bf247e2017-05-18 14:02:49 -070085
86 mFreezeGeometryUpdates = false;
87
Marissa Wallf58c14b2018-07-24 10:50:43 -070088 if (mFront.crop_legacy != mFront.requestedCrop_legacy) {
89 mFront.crop_legacy = mFront.requestedCrop_legacy;
90 mCurrent.crop_legacy = mFront.requestedCrop_legacy;
Robert Carr7bf247e2017-05-18 14:02:49 -070091 mRecomputeVisibleRegions = true;
92 }
Marissa Wallf58c14b2018-07-24 10:50:43 -070093 if (mFront.finalCrop_legacy != mFront.requestedFinalCrop_legacy) {
94 mFront.finalCrop_legacy = mFront.requestedFinalCrop_legacy;
95 mCurrent.finalCrop_legacy = mFront.requestedFinalCrop_legacy;
Robert Carr7bf247e2017-05-18 14:02:49 -070096 mRecomputeVisibleRegions = true;
97 }
Fabien Sanglard7b1563a2016-10-13 12:05:28 -070098 }
99
100 ALOGD_IF(DEBUG_RESIZE,
101 "[%s] latchBuffer/reject: buffer (%ux%u, tr=%02x), scalingMode=%d\n"
Marissa Wall61c58622018-07-18 10:12:20 -0700102 " drawing={ active_legacy ={ wh={%4u,%4u} crop_legacy={%4d,%4d,%4d,%4d} "
103 "(%4d,%4d) "
Fabien Sanglard7b1563a2016-10-13 12:05:28 -0700104 "}\n"
Marissa Wallf58c14b2018-07-24 10:50:43 -0700105 " requested_legacy={ wh={%4u,%4u} }}\n",
106 mName, bufWidth, bufHeight, item.mTransform, item.mScalingMode,
107 mFront.active_legacy.w, mFront.active_legacy.h, mFront.crop_legacy.left,
108 mFront.crop_legacy.top, mFront.crop_legacy.right, mFront.crop_legacy.bottom,
109 mFront.crop_legacy.getWidth(), mFront.crop_legacy.getHeight(),
110 mFront.requested_legacy.w, mFront.requested_legacy.h);
Fabien Sanglard7b1563a2016-10-13 12:05:28 -0700111 }
112
113 if (!isFixedSize && !mStickyTransformSet) {
Marissa Wallf58c14b2018-07-24 10:50:43 -0700114 if (mFront.active_legacy.w != bufWidth || mFront.active_legacy.h != bufHeight) {
Fabien Sanglard7b1563a2016-10-13 12:05:28 -0700115 // reject this buffer
116 ALOGE("[%s] rejecting buffer: "
Marissa Wallf58c14b2018-07-24 10:50:43 -0700117 "bufWidth=%d, bufHeight=%d, front.active_legacy.{w=%d, h=%d}",
118 mName, bufWidth, bufHeight, mFront.active_legacy.w, mFront.active_legacy.h);
Fabien Sanglard7b1563a2016-10-13 12:05:28 -0700119 return true;
120 }
121 }
122
123 // if the transparent region has changed (this test is
124 // conservative, but that's fine, worst case we're doing
125 // a bit of extra work), we latch the new one and we
126 // trigger a visible-region recompute.
Robert Carr7bf247e2017-05-18 14:02:49 -0700127 //
128 // We latch the transparent region here, instead of above where we latch
129 // the rest of the geometry because it is only content but not necessarily
130 // resize dependent.
Marissa Wallf58c14b2018-07-24 10:50:43 -0700131 if (!mFront.activeTransparentRegion_legacy.isTriviallyEqual(
132 mFront.requestedTransparentRegion_legacy)) {
133 mFront.activeTransparentRegion_legacy = mFront.requestedTransparentRegion_legacy;
Fabien Sanglard7b1563a2016-10-13 12:05:28 -0700134
135 // We also need to update the current state so that
136 // we don't end-up overwriting the drawing state with
137 // this stale current state during the next transaction
138 //
139 // NOTE: We don't need to hold the transaction lock here
Marissa Wallf58c14b2018-07-24 10:50:43 -0700140 // because State::active_legacy is only accessed from this thread.
141 mCurrent.activeTransparentRegion_legacy = mFront.activeTransparentRegion_legacy;
Fabien Sanglard7b1563a2016-10-13 12:05:28 -0700142
143 // recompute visible region
144 mRecomputeVisibleRegions = true;
145 }
146
Fabien Sanglard7b1563a2016-10-13 12:05:28 -0700147 return false;
148}
149
Mathias Agopiana9347642017-02-13 16:42:28 -0800150} // namespace android