| Fabien Sanglard | 7b1563a | 2016-10-13 12:05:28 -0700 | [diff] [blame] | 1 | /* | 
 | 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 Agopian | a934764 | 2017-02-13 16:42:28 -0800 | [diff] [blame] | 19 | #include <gui/BufferItem.h> | 
| Mathias Agopian | 6a3c05b | 2017-04-27 20:06:55 -0700 | [diff] [blame] | 20 | #include <system/window.h> | 
| Mathias Agopian | a934764 | 2017-02-13 16:42:28 -0800 | [diff] [blame] | 21 |  | 
| Fabien Sanglard | 7b1563a | 2016-10-13 12:05:28 -0700 | [diff] [blame] | 22 | #include "clz.h" | 
 | 23 |  | 
 | 24 | #define DEBUG_RESIZE 0 | 
 | 25 |  | 
 | 26 | namespace android { | 
 | 27 |  | 
 | 28 | LayerRejecter::LayerRejecter(Layer::State& front, | 
 | 29 |                              Layer::State& current, | 
 | 30 |                              bool& recomputeVisibleRegions, | 
 | 31 |                              bool stickySet, | 
 | 32 |                              const char* name, | 
 | 33 |                              int32_t overrideScalingMode, | 
| Robert Carr | 35f0dda | 2018-05-03 15:47:23 -0700 | [diff] [blame] | 34 |                              bool transformToDisplayInverse, | 
| Fabien Sanglard | 7b1563a | 2016-10-13 12:05:28 -0700 | [diff] [blame] | 35 |                              bool& freezePositionUpdates) | 
 | 36 |   : mFront(front), | 
 | 37 |     mCurrent(current), | 
 | 38 |     mRecomputeVisibleRegions(recomputeVisibleRegions), | 
 | 39 |     mStickyTransformSet(stickySet), | 
 | 40 |     mName(name), | 
 | 41 |     mOverrideScalingMode(overrideScalingMode), | 
| Robert Carr | 35f0dda | 2018-05-03 15:47:23 -0700 | [diff] [blame] | 42 |     mTransformToDisplayInverse(transformToDisplayInverse), | 
| Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 43 |     mFreezeGeometryUpdates(freezePositionUpdates) {} | 
| Fabien Sanglard | 7b1563a | 2016-10-13 12:05:28 -0700 | [diff] [blame] | 44 |  | 
 | 45 | bool LayerRejecter::reject(const sp<GraphicBuffer>& buf, const BufferItem& item) { | 
| Peiyong Lin | 566a3b4 | 2018-01-09 18:22:43 -0800 | [diff] [blame] | 46 |     if (buf == nullptr) { | 
| Fabien Sanglard | 7b1563a | 2016-10-13 12:05:28 -0700 | [diff] [blame] | 47 |         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 Carr | 35f0dda | 2018-05-03 15:47:23 -0700 | [diff] [blame] | 59 |     if (mTransformToDisplayInverse) { | 
 | 60 |         uint32_t invTransform = DisplayDevice::getPrimaryDisplayOrientationTransform(); | 
 | 61 |         if (invTransform & Transform::ROT_90) { | 
 | 62 |             swap(bufWidth, bufHeight); | 
 | 63 |         } | 
 | 64 |     } | 
 | 65 |  | 
| Fabien Sanglard | 7b1563a | 2016-10-13 12:05:28 -0700 | [diff] [blame] | 66 |     int actualScalingMode = mOverrideScalingMode >= 0 ? mOverrideScalingMode : item.mScalingMode; | 
 | 67 |     bool isFixedSize = actualScalingMode != NATIVE_WINDOW_SCALING_MODE_FREEZE; | 
 | 68 |     if (mFront.active != mFront.requested) { | 
 | 69 |         if (isFixedSize || (bufWidth == mFront.requested.w && bufHeight == mFront.requested.h)) { | 
 | 70 |             // Here we pretend the transaction happened by updating the | 
 | 71 |             // current and drawing states. Drawing state is only accessed | 
 | 72 |             // in this thread, no need to have it locked | 
 | 73 |             mFront.active = mFront.requested; | 
 | 74 |  | 
 | 75 |             // We also need to update the current state so that | 
 | 76 |             // we don't end-up overwriting the drawing state with | 
 | 77 |             // this stale current state during the next transaction | 
 | 78 |             // | 
 | 79 |             // NOTE: We don't need to hold the transaction lock here | 
 | 80 |             // because State::active is only accessed from this thread. | 
 | 81 |             mCurrent.active = mFront.active; | 
 | 82 |             mCurrent.modified = true; | 
 | 83 |  | 
 | 84 |             // recompute visible region | 
 | 85 |             mRecomputeVisibleRegions = true; | 
| Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 86 |  | 
 | 87 |             mFreezeGeometryUpdates = false; | 
 | 88 |  | 
 | 89 |             if (mFront.crop != mFront.requestedCrop) { | 
 | 90 |                 mFront.crop = mFront.requestedCrop; | 
 | 91 |                 mCurrent.crop = mFront.requestedCrop; | 
 | 92 |                 mRecomputeVisibleRegions = true; | 
 | 93 |             } | 
 | 94 |             if (mFront.finalCrop != mFront.requestedFinalCrop) { | 
 | 95 |                 mFront.finalCrop = mFront.requestedFinalCrop; | 
 | 96 |                 mCurrent.finalCrop = mFront.requestedFinalCrop; | 
 | 97 |                 mRecomputeVisibleRegions = true; | 
 | 98 |             } | 
| Fabien Sanglard | 7b1563a | 2016-10-13 12:05:28 -0700 | [diff] [blame] | 99 |         } | 
 | 100 |  | 
 | 101 |         ALOGD_IF(DEBUG_RESIZE, | 
 | 102 |                  "[%s] latchBuffer/reject: buffer (%ux%u, tr=%02x), scalingMode=%d\n" | 
 | 103 |                  "  drawing={ active   ={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) " | 
 | 104 |                  "}\n" | 
 | 105 |                  "            requested={ wh={%4u,%4u} }}\n", | 
 | 106 |                  mName, bufWidth, bufHeight, item.mTransform, item.mScalingMode, mFront.active.w, | 
 | 107 |                  mFront.active.h, mFront.crop.left, mFront.crop.top, mFront.crop.right, | 
 | 108 |                  mFront.crop.bottom, mFront.crop.getWidth(), mFront.crop.getHeight(), | 
 | 109 |                  mFront.requested.w, mFront.requested.h); | 
 | 110 |     } | 
 | 111 |  | 
 | 112 |     if (!isFixedSize && !mStickyTransformSet) { | 
 | 113 |         if (mFront.active.w != bufWidth || mFront.active.h != bufHeight) { | 
 | 114 |             // reject this buffer | 
 | 115 |             ALOGE("[%s] rejecting buffer: " | 
 | 116 |                   "bufWidth=%d, bufHeight=%d, front.active.{w=%d, h=%d}", | 
 | 117 |                   mName, bufWidth, bufHeight, mFront.active.w, mFront.active.h); | 
 | 118 |             return true; | 
 | 119 |         } | 
 | 120 |     } | 
 | 121 |  | 
 | 122 |     // if the transparent region has changed (this test is | 
 | 123 |     // conservative, but that's fine, worst case we're doing | 
 | 124 |     // a bit of extra work), we latch the new one and we | 
 | 125 |     // trigger a visible-region recompute. | 
| Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 126 |     // | 
 | 127 |     // We latch the transparent region here, instead of above where we latch | 
 | 128 |     // the rest of the geometry because it is only content but not necessarily | 
 | 129 |     // resize dependent. | 
| Fabien Sanglard | 7b1563a | 2016-10-13 12:05:28 -0700 | [diff] [blame] | 130 |     if (!mFront.activeTransparentRegion.isTriviallyEqual(mFront.requestedTransparentRegion)) { | 
 | 131 |         mFront.activeTransparentRegion = mFront.requestedTransparentRegion; | 
 | 132 |  | 
 | 133 |         // We also need to update the current state so that | 
 | 134 |         // we don't end-up overwriting the drawing state with | 
 | 135 |         // this stale current state during the next transaction | 
 | 136 |         // | 
 | 137 |         // NOTE: We don't need to hold the transaction lock here | 
 | 138 |         // because State::active is only accessed from this thread. | 
 | 139 |         mCurrent.activeTransparentRegion = mFront.activeTransparentRegion; | 
 | 140 |  | 
 | 141 |         // recompute visible region | 
 | 142 |         mRecomputeVisibleRegions = true; | 
 | 143 |     } | 
 | 144 |  | 
| Fabien Sanglard | 7b1563a | 2016-10-13 12:05:28 -0700 | [diff] [blame] | 145 |     return false; | 
 | 146 | } | 
 | 147 |  | 
| Mathias Agopian | a934764 | 2017-02-13 16:42:28 -0800 | [diff] [blame] | 148 | }  // namespace android |