blob: 2bc0605e95a4febb2df4ea60e72adcf8dbed22cc [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
19#include "clz.h"
20
21#define DEBUG_RESIZE 0
22
23namespace android {
24
25LayerRejecter::LayerRejecter(Layer::State& front,
26 Layer::State& current,
27 bool& recomputeVisibleRegions,
28 bool stickySet,
29 const char* name,
30 int32_t overrideScalingMode,
31 bool& freezePositionUpdates)
32 : mFront(front),
33 mCurrent(current),
34 mRecomputeVisibleRegions(recomputeVisibleRegions),
35 mStickyTransformSet(stickySet),
36 mName(name),
37 mOverrideScalingMode(overrideScalingMode),
38 mFreezePositionUpdates(freezePositionUpdates) {}
39
40bool LayerRejecter::reject(const sp<GraphicBuffer>& buf, const BufferItem& item) {
41 if (buf == NULL) {
42 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)
50 if (item.mTransform & Transform::ROT_90) {
51 swap(bufWidth, bufHeight);
52 }
53
54 int actualScalingMode = mOverrideScalingMode >= 0 ? mOverrideScalingMode : item.mScalingMode;
55 bool isFixedSize = actualScalingMode != NATIVE_WINDOW_SCALING_MODE_FREEZE;
56 if (mFront.active != mFront.requested) {
57 if (isFixedSize || (bufWidth == mFront.requested.w && bufHeight == mFront.requested.h)) {
58 // Here we pretend the transaction happened by updating the
59 // current and drawing states. Drawing state is only accessed
60 // in this thread, no need to have it locked
61 mFront.active = mFront.requested;
62
63 // We also need to update the current state so that
64 // we don't end-up overwriting the drawing state with
65 // this stale current state during the next transaction
66 //
67 // NOTE: We don't need to hold the transaction lock here
68 // because State::active is only accessed from this thread.
69 mCurrent.active = mFront.active;
70 mCurrent.modified = true;
71
72 // recompute visible region
73 mRecomputeVisibleRegions = true;
74 }
75
76 ALOGD_IF(DEBUG_RESIZE,
77 "[%s] latchBuffer/reject: buffer (%ux%u, tr=%02x), scalingMode=%d\n"
78 " drawing={ active ={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) "
79 "}\n"
80 " requested={ wh={%4u,%4u} }}\n",
81 mName, bufWidth, bufHeight, item.mTransform, item.mScalingMode, mFront.active.w,
82 mFront.active.h, mFront.crop.left, mFront.crop.top, mFront.crop.right,
83 mFront.crop.bottom, mFront.crop.getWidth(), mFront.crop.getHeight(),
84 mFront.requested.w, mFront.requested.h);
85 }
86
87 if (!isFixedSize && !mStickyTransformSet) {
88 if (mFront.active.w != bufWidth || mFront.active.h != bufHeight) {
89 // reject this buffer
90 ALOGE("[%s] rejecting buffer: "
91 "bufWidth=%d, bufHeight=%d, front.active.{w=%d, h=%d}",
92 mName, bufWidth, bufHeight, mFront.active.w, mFront.active.h);
93 return true;
94 }
95 }
96
97 // if the transparent region has changed (this test is
98 // conservative, but that's fine, worst case we're doing
99 // a bit of extra work), we latch the new one and we
100 // trigger a visible-region recompute.
101 if (!mFront.activeTransparentRegion.isTriviallyEqual(mFront.requestedTransparentRegion)) {
102 mFront.activeTransparentRegion = mFront.requestedTransparentRegion;
103
104 // We also need to update the current state so that
105 // we don't end-up overwriting the drawing state with
106 // this stale current state during the next transaction
107 //
108 // NOTE: We don't need to hold the transaction lock here
109 // because State::active is only accessed from this thread.
110 mCurrent.activeTransparentRegion = mFront.activeTransparentRegion;
111
112 // recompute visible region
113 mRecomputeVisibleRegions = true;
114 }
115
116 if (mFront.crop != mFront.requestedCrop) {
117 mFront.crop = mFront.requestedCrop;
118 mCurrent.crop = mFront.requestedCrop;
119 mRecomputeVisibleRegions = true;
120 }
121 mFreezePositionUpdates = false;
122
123 return false;
124}
125
126} // namespace android