blob: fd0ca822c664d3bf0f24cc48e433aa98d1af38d8 [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#include "clz.h"
23
24#define DEBUG_RESIZE 0
25
26namespace android {
27
28LayerRejecter::LayerRejecter(Layer::State& front,
29 Layer::State& current,
30 bool& recomputeVisibleRegions,
31 bool stickySet,
32 const char* name,
33 int32_t overrideScalingMode,
Robert Carr35f0dda2018-05-03 15:47:23 -070034 bool transformToDisplayInverse,
Fabien Sanglard7b1563a2016-10-13 12:05:28 -070035 bool& freezePositionUpdates)
36 : mFront(front),
37 mCurrent(current),
38 mRecomputeVisibleRegions(recomputeVisibleRegions),
39 mStickyTransformSet(stickySet),
40 mName(name),
41 mOverrideScalingMode(overrideScalingMode),
Robert Carr35f0dda2018-05-03 15:47:23 -070042 mTransformToDisplayInverse(transformToDisplayInverse),
Robert Carr7bf247e2017-05-18 14:02:49 -070043 mFreezeGeometryUpdates(freezePositionUpdates) {}
Fabien Sanglard7b1563a2016-10-13 12:05:28 -070044
45bool LayerRejecter::reject(const sp<GraphicBuffer>& buf, const BufferItem& item) {
Peiyong Lin566a3b42018-01-09 18:22:43 -080046 if (buf == nullptr) {
Fabien Sanglard7b1563a2016-10-13 12:05:28 -070047 return false;
48 }
49
50 uint32_t bufWidth = buf->getWidth();
51 uint32_t bufHeight = buf->getHeight();
52
53 // check that we received a buffer of the right size
54 // (Take the buffer's orientation into account)
55 if (item.mTransform & Transform::ROT_90) {
56 swap(bufWidth, bufHeight);
57 }
58
Robert Carr35f0dda2018-05-03 15:47:23 -070059 if (mTransformToDisplayInverse) {
60 uint32_t invTransform = DisplayDevice::getPrimaryDisplayOrientationTransform();
61 if (invTransform & Transform::ROT_90) {
62 swap(bufWidth, bufHeight);
63 }
64 }
65
Fabien Sanglard7b1563a2016-10-13 12:05:28 -070066 int actualScalingMode = mOverrideScalingMode >= 0 ? mOverrideScalingMode : item.mScalingMode;
67 bool isFixedSize = actualScalingMode != NATIVE_WINDOW_SCALING_MODE_FREEZE;
Marissa Wallf58c14b2018-07-24 10:50:43 -070068 if (mFront.active_legacy != mFront.requested_legacy) {
69 if (isFixedSize ||
70 (bufWidth == mFront.requested_legacy.w && bufHeight == mFront.requested_legacy.h)) {
Fabien Sanglard7b1563a2016-10-13 12:05:28 -070071 // Here we pretend the transaction happened by updating the
72 // current and drawing states. Drawing state is only accessed
73 // in this thread, no need to have it locked
Marissa Wallf58c14b2018-07-24 10:50:43 -070074 mFront.active_legacy = mFront.requested_legacy;
Fabien Sanglard7b1563a2016-10-13 12:05:28 -070075
76 // We also need to update the current state so that
77 // we don't end-up overwriting the drawing state with
78 // this stale current state during the next transaction
79 //
80 // NOTE: We don't need to hold the transaction lock here
Marissa Wallf58c14b2018-07-24 10:50:43 -070081 // because State::active_legacy is only accessed from this thread.
82 mCurrent.active_legacy = mFront.active_legacy;
Fabien Sanglard7b1563a2016-10-13 12:05:28 -070083 mCurrent.modified = true;
84
85 // recompute visible region
86 mRecomputeVisibleRegions = true;
Robert Carr7bf247e2017-05-18 14:02:49 -070087
88 mFreezeGeometryUpdates = false;
89
Marissa Wallf58c14b2018-07-24 10:50:43 -070090 if (mFront.crop_legacy != mFront.requestedCrop_legacy) {
91 mFront.crop_legacy = mFront.requestedCrop_legacy;
92 mCurrent.crop_legacy = mFront.requestedCrop_legacy;
Robert Carr7bf247e2017-05-18 14:02:49 -070093 mRecomputeVisibleRegions = true;
94 }
Marissa Wallf58c14b2018-07-24 10:50:43 -070095 if (mFront.finalCrop_legacy != mFront.requestedFinalCrop_legacy) {
96 mFront.finalCrop_legacy = mFront.requestedFinalCrop_legacy;
97 mCurrent.finalCrop_legacy = mFront.requestedFinalCrop_legacy;
Robert Carr7bf247e2017-05-18 14:02:49 -070098 mRecomputeVisibleRegions = true;
99 }
Fabien Sanglard7b1563a2016-10-13 12:05:28 -0700100 }
101
102 ALOGD_IF(DEBUG_RESIZE,
103 "[%s] latchBuffer/reject: buffer (%ux%u, tr=%02x), scalingMode=%d\n"
104 " drawing={ active ={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) "
105 "}\n"
Marissa Wallf58c14b2018-07-24 10:50:43 -0700106 " requested_legacy={ wh={%4u,%4u} }}\n",
107 mName, bufWidth, bufHeight, item.mTransform, item.mScalingMode,
108 mFront.active_legacy.w, mFront.active_legacy.h, mFront.crop_legacy.left,
109 mFront.crop_legacy.top, mFront.crop_legacy.right, mFront.crop_legacy.bottom,
110 mFront.crop_legacy.getWidth(), mFront.crop_legacy.getHeight(),
111 mFront.requested_legacy.w, mFront.requested_legacy.h);
Fabien Sanglard7b1563a2016-10-13 12:05:28 -0700112 }
113
114 if (!isFixedSize && !mStickyTransformSet) {
Marissa Wallf58c14b2018-07-24 10:50:43 -0700115 if (mFront.active_legacy.w != bufWidth || mFront.active_legacy.h != bufHeight) {
Fabien Sanglard7b1563a2016-10-13 12:05:28 -0700116 // reject this buffer
117 ALOGE("[%s] rejecting buffer: "
Marissa Wallf58c14b2018-07-24 10:50:43 -0700118 "bufWidth=%d, bufHeight=%d, front.active_legacy.{w=%d, h=%d}",
119 mName, bufWidth, bufHeight, mFront.active_legacy.w, mFront.active_legacy.h);
Fabien Sanglard7b1563a2016-10-13 12:05:28 -0700120 return true;
121 }
122 }
123
124 // if the transparent region has changed (this test is
125 // conservative, but that's fine, worst case we're doing
126 // a bit of extra work), we latch the new one and we
127 // trigger a visible-region recompute.
Robert Carr7bf247e2017-05-18 14:02:49 -0700128 //
129 // We latch the transparent region here, instead of above where we latch
130 // the rest of the geometry because it is only content but not necessarily
131 // resize dependent.
Marissa Wallf58c14b2018-07-24 10:50:43 -0700132 if (!mFront.activeTransparentRegion_legacy.isTriviallyEqual(
133 mFront.requestedTransparentRegion_legacy)) {
134 mFront.activeTransparentRegion_legacy = mFront.requestedTransparentRegion_legacy;
Fabien Sanglard7b1563a2016-10-13 12:05:28 -0700135
136 // We also need to update the current state so that
137 // we don't end-up overwriting the drawing state with
138 // this stale current state during the next transaction
139 //
140 // NOTE: We don't need to hold the transaction lock here
Marissa Wallf58c14b2018-07-24 10:50:43 -0700141 // because State::active_legacy is only accessed from this thread.
142 mCurrent.activeTransparentRegion_legacy = mFront.activeTransparentRegion_legacy;
Fabien Sanglard7b1563a2016-10-13 12:05:28 -0700143
144 // recompute visible region
145 mRecomputeVisibleRegions = true;
146 }
147
Fabien Sanglard7b1563a2016-10-13 12:05:28 -0700148 return false;
149}
150
Mathias Agopiana9347642017-02-13 16:42:28 -0800151} // namespace android