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