| 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 |  | 
| Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 17 | // TODO(b/129481165): remove the #pragma below and fix conversion issues | 
|  | 18 | #pragma clang diagnostic push | 
|  | 19 | #pragma clang diagnostic ignored "-Wconversion" | 
|  | 20 |  | 
| Fabien Sanglard | 7b1563a | 2016-10-13 12:05:28 -0700 | [diff] [blame] | 21 | #include "LayerRejecter.h" | 
|  | 22 |  | 
| Mathias Agopian | a934764 | 2017-02-13 16:42:28 -0800 | [diff] [blame] | 23 | #include <gui/BufferItem.h> | 
| Mathias Agopian | 6a3c05b | 2017-04-27 20:06:55 -0700 | [diff] [blame] | 24 | #include <system/window.h> | 
| Mathias Agopian | a934764 | 2017-02-13 16:42:28 -0800 | [diff] [blame] | 25 |  | 
| Fabien Sanglard | 7b1563a | 2016-10-13 12:05:28 -0700 | [diff] [blame] | 26 | #define DEBUG_RESIZE 0 | 
|  | 27 |  | 
|  | 28 | namespace android { | 
|  | 29 |  | 
| chaviw | 214c89d | 2019-09-04 16:03:53 -0700 | [diff] [blame] | 30 | LayerRejecter::LayerRejecter(Layer::State& front, Layer::State& current, | 
| Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 31 | bool& recomputeVisibleRegions, bool stickySet, const std::string& name, | 
| Robert Carr | 916b036 | 2020-10-06 13:53:03 -0700 | [diff] [blame] | 32 | bool transformToDisplayInverse) | 
| chaviw | 214c89d | 2019-09-04 16:03:53 -0700 | [diff] [blame] | 33 | : mFront(front), | 
|  | 34 | mCurrent(current), | 
|  | 35 | mRecomputeVisibleRegions(recomputeVisibleRegions), | 
|  | 36 | mStickyTransformSet(stickySet), | 
|  | 37 | mName(name), | 
| chaviw | 214c89d | 2019-09-04 16:03:53 -0700 | [diff] [blame] | 38 | mTransformToDisplayInverse(transformToDisplayInverse) {} | 
| Fabien Sanglard | 7b1563a | 2016-10-13 12:05:28 -0700 | [diff] [blame] | 39 |  | 
|  | 40 | bool LayerRejecter::reject(const sp<GraphicBuffer>& buf, const BufferItem& item) { | 
| Peiyong Lin | 566a3b4 | 2018-01-09 18:22:43 -0800 | [diff] [blame] | 41 | if (buf == nullptr) { | 
| Fabien Sanglard | 7b1563a | 2016-10-13 12:05:28 -0700 | [diff] [blame] | 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) | 
| Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 50 | if (item.mTransform & ui::Transform::ROT_90) { | 
| Peiyong Lin | 3db4234 | 2018-08-16 09:15:59 -0700 | [diff] [blame] | 51 | std::swap(bufWidth, bufHeight); | 
| Fabien Sanglard | 7b1563a | 2016-10-13 12:05:28 -0700 | [diff] [blame] | 52 | } | 
|  | 53 |  | 
| Robert Carr | 35f0dda | 2018-05-03 15:47:23 -0700 | [diff] [blame] | 54 | if (mTransformToDisplayInverse) { | 
| Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 55 | uint32_t invTransform = DisplayDevice::getPrimaryDisplayRotationFlags(); | 
| Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 56 | if (invTransform & ui::Transform::ROT_90) { | 
| Peiyong Lin | 3db4234 | 2018-08-16 09:15:59 -0700 | [diff] [blame] | 57 | std::swap(bufWidth, bufHeight); | 
| Robert Carr | 35f0dda | 2018-05-03 15:47:23 -0700 | [diff] [blame] | 58 | } | 
|  | 59 | } | 
|  | 60 |  | 
| Robert Carr | 916b036 | 2020-10-06 13:53:03 -0700 | [diff] [blame] | 61 | int actualScalingMode = item.mScalingMode; | 
| Fabien Sanglard | 7b1563a | 2016-10-13 12:05:28 -0700 | [diff] [blame] | 62 | bool isFixedSize = actualScalingMode != NATIVE_WINDOW_SCALING_MODE_FREEZE; | 
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 63 | if (mFront.active_legacy != mFront.requested_legacy) { | 
|  | 64 | if (isFixedSize || | 
|  | 65 | (bufWidth == mFront.requested_legacy.w && bufHeight == mFront.requested_legacy.h)) { | 
| Fabien Sanglard | 7b1563a | 2016-10-13 12:05:28 -0700 | [diff] [blame] | 66 | // Here we pretend the transaction happened by updating the | 
|  | 67 | // current and drawing states. Drawing state is only accessed | 
|  | 68 | // in this thread, no need to have it locked | 
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 69 | mFront.active_legacy = mFront.requested_legacy; | 
| Fabien Sanglard | 7b1563a | 2016-10-13 12:05:28 -0700 | [diff] [blame] | 70 |  | 
|  | 71 | // We also need to update the current state so that | 
|  | 72 | // we don't end-up overwriting the drawing state with | 
|  | 73 | // this stale current state during the next transaction | 
|  | 74 | // | 
|  | 75 | // NOTE: We don't need to hold the transaction lock here | 
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 76 | // because State::active_legacy is only accessed from this thread. | 
|  | 77 | mCurrent.active_legacy = mFront.active_legacy; | 
| Fabien Sanglard | 7b1563a | 2016-10-13 12:05:28 -0700 | [diff] [blame] | 78 | mCurrent.modified = true; | 
|  | 79 |  | 
|  | 80 | // recompute visible region | 
|  | 81 | mRecomputeVisibleRegions = true; | 
| Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 82 |  | 
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 83 | if (mFront.crop_legacy != mFront.requestedCrop_legacy) { | 
|  | 84 | mFront.crop_legacy = mFront.requestedCrop_legacy; | 
|  | 85 | mCurrent.crop_legacy = mFront.requestedCrop_legacy; | 
| Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 86 | mRecomputeVisibleRegions = true; | 
|  | 87 | } | 
| Fabien Sanglard | 7b1563a | 2016-10-13 12:05:28 -0700 | [diff] [blame] | 88 | } | 
|  | 89 |  | 
|  | 90 | ALOGD_IF(DEBUG_RESIZE, | 
|  | 91 | "[%s] latchBuffer/reject: buffer (%ux%u, tr=%02x), scalingMode=%d\n" | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 92 | "  drawing={ active_legacy   ={ wh={%4u,%4u} crop_legacy={%4d,%4d,%4d,%4d} " | 
|  | 93 | "(%4d,%4d) " | 
| Fabien Sanglard | 7b1563a | 2016-10-13 12:05:28 -0700 | [diff] [blame] | 94 | "}\n" | 
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 95 | "            requested_legacy={ wh={%4u,%4u} }}\n", | 
| Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 96 | mName.c_str(), bufWidth, bufHeight, item.mTransform, item.mScalingMode, | 
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 97 | mFront.active_legacy.w, mFront.active_legacy.h, mFront.crop_legacy.left, | 
|  | 98 | mFront.crop_legacy.top, mFront.crop_legacy.right, mFront.crop_legacy.bottom, | 
|  | 99 | mFront.crop_legacy.getWidth(), mFront.crop_legacy.getHeight(), | 
|  | 100 | mFront.requested_legacy.w, mFront.requested_legacy.h); | 
| Fabien Sanglard | 7b1563a | 2016-10-13 12:05:28 -0700 | [diff] [blame] | 101 | } | 
|  | 102 |  | 
|  | 103 | if (!isFixedSize && !mStickyTransformSet) { | 
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 104 | if (mFront.active_legacy.w != bufWidth || mFront.active_legacy.h != bufHeight) { | 
| Fabien Sanglard | 7b1563a | 2016-10-13 12:05:28 -0700 | [diff] [blame] | 105 | // reject this buffer | 
|  | 106 | ALOGE("[%s] rejecting buffer: " | 
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 107 | "bufWidth=%d, bufHeight=%d, front.active_legacy.{w=%d, h=%d}", | 
| Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 108 | mName.c_str(), bufWidth, bufHeight, mFront.active_legacy.w, | 
|  | 109 | mFront.active_legacy.h); | 
| Fabien Sanglard | 7b1563a | 2016-10-13 12:05:28 -0700 | [diff] [blame] | 110 | return true; | 
|  | 111 | } | 
|  | 112 | } | 
|  | 113 |  | 
|  | 114 | // if the transparent region has changed (this test is | 
|  | 115 | // conservative, but that's fine, worst case we're doing | 
|  | 116 | // a bit of extra work), we latch the new one and we | 
|  | 117 | // trigger a visible-region recompute. | 
| Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 118 | // | 
|  | 119 | // We latch the transparent region here, instead of above where we latch | 
|  | 120 | // the rest of the geometry because it is only content but not necessarily | 
|  | 121 | // resize dependent. | 
| Arthur Hung | d9a25c4 | 2020-03-03 18:59:19 +0800 | [diff] [blame] | 122 | if (!mFront.activeTransparentRegion_legacy.hasSameRects( | 
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 123 | mFront.requestedTransparentRegion_legacy)) { | 
|  | 124 | mFront.activeTransparentRegion_legacy = mFront.requestedTransparentRegion_legacy; | 
| Fabien Sanglard | 7b1563a | 2016-10-13 12:05:28 -0700 | [diff] [blame] | 125 |  | 
|  | 126 | // We also need to update the current state so that | 
|  | 127 | // we don't end-up overwriting the drawing state with | 
|  | 128 | // this stale current state during the next transaction | 
|  | 129 | // | 
|  | 130 | // NOTE: We don't need to hold the transaction lock here | 
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 131 | // because State::active_legacy is only accessed from this thread. | 
|  | 132 | mCurrent.activeTransparentRegion_legacy = mFront.activeTransparentRegion_legacy; | 
| Fabien Sanglard | 7b1563a | 2016-10-13 12:05:28 -0700 | [diff] [blame] | 133 |  | 
|  | 134 | // recompute visible region | 
|  | 135 | mRecomputeVisibleRegions = true; | 
|  | 136 | } | 
|  | 137 |  | 
| Fabien Sanglard | 7b1563a | 2016-10-13 12:05:28 -0700 | [diff] [blame] | 138 | return false; | 
|  | 139 | } | 
|  | 140 |  | 
| Mathias Agopian | a934764 | 2017-02-13 16:42:28 -0800 | [diff] [blame] | 141 | }  // namespace android | 
| Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 142 |  | 
|  | 143 | // TODO(b/129481165): remove the #pragma below and fix conversion issues | 
|  | 144 | #pragma clang diagnostic pop // ignored "-Wconversion" |