John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 17 | #include "RenderNode.h" |
| 18 | |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 19 | #include "DamageAccumulator.h" |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 20 | #include "Debug.h" |
Huihong Luo | ec68b7c | 2021-06-25 21:54:16 -0700 | [diff] [blame] | 21 | #include "Properties.h" |
Tom Hudson | 2dc236b | 2014-10-15 15:46:42 -0400 | [diff] [blame] | 22 | #include "TreeInfo.h" |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 23 | #include "VectorDrawable.h" |
Derek Sollenberger | 5d0ca63 | 2019-07-19 16:17:12 -0400 | [diff] [blame] | 24 | #include "private/hwui/WebViewFunctor.h" |
Fedor Kudasov | 86bd214 | 2019-06-18 15:51:57 +0100 | [diff] [blame] | 25 | #ifdef __ANDROID__ |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 26 | #include "renderthread/CanvasContext.h" |
Fedor Kudasov | 86bd214 | 2019-06-18 15:51:57 +0100 | [diff] [blame] | 27 | #else |
| 28 | #include "DamageAccumulator.h" |
| 29 | #include "pipeline/skia/SkiaDisplayList.h" |
| 30 | #endif |
rnlee | ce9762b | 2021-05-21 15:40:53 -0700 | [diff] [blame] | 31 | #include <gui/TraceUtils.h> |
Chris Craik | e0bb87d | 2014-04-22 17:55:41 -0700 | [diff] [blame] | 32 | #include "utils/MathUtils.h" |
sergeyv | c3849aa | 2016-08-08 13:22:06 -0700 | [diff] [blame] | 33 | #include "utils/StringUtils.h" |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 34 | |
Derek Sollenberger | 579317d4 | 2017-08-29 16:33:49 -0400 | [diff] [blame] | 35 | #include <SkPathOps.h> |
John Reck | 77c4010 | 2015-10-26 15:49:47 -0700 | [diff] [blame] | 36 | #include <algorithm> |
John Reck | f96b284 | 2018-11-29 09:44:10 -0800 | [diff] [blame] | 37 | #include <atomic> |
John Reck | 77c4010 | 2015-10-26 15:49:47 -0700 | [diff] [blame] | 38 | #include <sstream> |
| 39 | #include <string> |
Jagadeesh Pakaravoor | b624af3 | 2020-05-01 00:01:40 +0000 | [diff] [blame] | 40 | #include <ui/FatVector.h> |
John Reck | 77c4010 | 2015-10-26 15:49:47 -0700 | [diff] [blame] | 41 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 42 | namespace android { |
| 43 | namespace uirenderer { |
| 44 | |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 45 | // Used for tree mutations that are purely destructive. |
| 46 | // Generic tree mutations should use MarkAndSweepObserver instead |
| 47 | class ImmediateRemoved : public TreeObserver { |
| 48 | public: |
| 49 | explicit ImmediateRemoved(TreeInfo* info) : mTreeInfo(info) {} |
| 50 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 51 | void onMaybeRemovedFromTree(RenderNode* node) override { node->onRemovedFromTree(mTreeInfo); } |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 52 | |
| 53 | private: |
| 54 | TreeInfo* mTreeInfo; |
| 55 | }; |
| 56 | |
John Reck | f96b284 | 2018-11-29 09:44:10 -0800 | [diff] [blame] | 57 | static int64_t generateId() { |
| 58 | static std::atomic<int64_t> sNextId{1}; |
| 59 | return sNextId++; |
| 60 | } |
| 61 | |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 62 | RenderNode::RenderNode() |
John Reck | f96b284 | 2018-11-29 09:44:10 -0800 | [diff] [blame] | 63 | : mUniqueId(generateId()) |
| 64 | , mDirtyPropertyFields(0) |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 65 | , mNeedsDisplayListSync(false) |
| 66 | , mDisplayList(nullptr) |
| 67 | , mStagingDisplayList(nullptr) |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 68 | , mAnimatorManager(*this) |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 69 | , mParentCount(0) {} |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 70 | |
| 71 | RenderNode::~RenderNode() { |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 72 | ImmediateRemoved observer(nullptr); |
| 73 | deleteDisplayList(observer); |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 74 | LOG_ALWAYS_FATAL_IF(hasLayer(), "layer missed detachment!"); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 75 | } |
| 76 | |
John Reck | be67195 | 2021-01-13 22:39:32 -0500 | [diff] [blame] | 77 | void RenderNode::setStagingDisplayList(DisplayList&& newData) { |
| 78 | mValid = newData.isValid(); |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 79 | mNeedsDisplayListSync = true; |
John Reck | be67195 | 2021-01-13 22:39:32 -0500 | [diff] [blame] | 80 | mStagingDisplayList = std::move(newData); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 81 | } |
| 82 | |
John Reck | dc1a696 | 2021-01-12 13:56:07 -0500 | [diff] [blame] | 83 | void RenderNode::discardStagingDisplayList() { |
John Reck | be67195 | 2021-01-13 22:39:32 -0500 | [diff] [blame] | 84 | setStagingDisplayList(DisplayList()); |
John Reck | dc1a696 | 2021-01-12 13:56:07 -0500 | [diff] [blame] | 85 | } |
| 86 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 87 | /** |
| 88 | * This function is a simplified version of replay(), where we simply retrieve and log the |
| 89 | * display list. This function should remain in sync with the replay() function. |
| 90 | */ |
sergeyv | c3849aa | 2016-08-08 13:22:06 -0700 | [diff] [blame] | 91 | void RenderNode::output() { |
| 92 | LogcatStream strout; |
| 93 | strout << "Root"; |
| 94 | output(strout, 0); |
| 95 | } |
| 96 | |
| 97 | void RenderNode::output(std::ostream& output, uint32_t level) { |
| 98 | output << " (" << getName() << " " << this |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 99 | << (MathUtils::isZero(properties().getAlpha()) ? ", zero alpha" : "") |
| 100 | << (properties().hasShadow() ? ", casting shadow" : "") |
| 101 | << (isRenderable() ? "" : ", empty") |
| 102 | << (properties().getProjectBackwards() ? ", projected" : "") |
| 103 | << (hasLayer() ? ", on HW Layer" : "") << ")" << std::endl; |
sergeyv | c3849aa | 2016-08-08 13:22:06 -0700 | [diff] [blame] | 104 | |
| 105 | properties().debugOutputProperties(output, level + 1); |
Chris Craik | 91eff22 | 2016-02-22 13:39:33 -0800 | [diff] [blame] | 106 | |
John Reck | be67195 | 2021-01-13 22:39:32 -0500 | [diff] [blame] | 107 | mDisplayList.output(output, level); |
sergeyv | c3849aa | 2016-08-08 13:22:06 -0700 | [diff] [blame] | 108 | output << std::string(level * 2, ' ') << "/RenderNode(" << getName() << " " << this << ")"; |
| 109 | output << std::endl; |
Chris Craik | 91eff22 | 2016-02-22 13:39:33 -0800 | [diff] [blame] | 110 | } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 111 | |
John Reck | 183e138 | 2019-10-09 13:41:18 -0700 | [diff] [blame] | 112 | int RenderNode::getUsageSize() { |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 113 | int size = sizeof(RenderNode); |
John Reck | be67195 | 2021-01-13 22:39:32 -0500 | [diff] [blame] | 114 | size += mStagingDisplayList.getUsedSize(); |
| 115 | size += mDisplayList.getUsedSize(); |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 116 | return size; |
| 117 | } |
| 118 | |
John Reck | 183e138 | 2019-10-09 13:41:18 -0700 | [diff] [blame] | 119 | int RenderNode::getAllocatedSize() { |
| 120 | int size = sizeof(RenderNode); |
John Reck | be67195 | 2021-01-13 22:39:32 -0500 | [diff] [blame] | 121 | size += mStagingDisplayList.getAllocatedSize(); |
| 122 | size += mDisplayList.getAllocatedSize(); |
John Reck | 183e138 | 2019-10-09 13:41:18 -0700 | [diff] [blame] | 123 | return size; |
| 124 | } |
| 125 | |
| 126 | |
John Reck | f4198b7 | 2014-04-09 17:00:04 -0700 | [diff] [blame] | 127 | void RenderNode::prepareTree(TreeInfo& info) { |
| 128 | ATRACE_CALL(); |
Chris Craik | 69e5adf | 2014-08-14 13:34:01 -0700 | [diff] [blame] | 129 | LOG_ALWAYS_FATAL_IF(!info.damageAccumulator, "DamageAccumulator missing"); |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 130 | MarkAndSweepRemoved observer(&info); |
John Reck | f4198b7 | 2014-04-09 17:00:04 -0700 | [diff] [blame] | 131 | |
John Reck | 1423e13 | 2018-09-21 14:30:19 -0700 | [diff] [blame] | 132 | const int before = info.disableForceDark; |
John Reck | 1072fff | 2018-04-12 15:20:09 -0700 | [diff] [blame] | 133 | prepareTreeImpl(observer, info, false); |
John Reck | 1423e13 | 2018-09-21 14:30:19 -0700 | [diff] [blame] | 134 | LOG_ALWAYS_FATAL_IF(before != info.disableForceDark, "Mis-matched force dark"); |
John Reck | f4198b7 | 2014-04-09 17:00:04 -0700 | [diff] [blame] | 135 | } |
| 136 | |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 137 | void RenderNode::addAnimator(const sp<BaseRenderNodeAnimator>& animator) { |
| 138 | mAnimatorManager.addAnimator(animator); |
| 139 | } |
| 140 | |
Doris Liu | 8b08320 | 2016-02-19 21:46:06 +0000 | [diff] [blame] | 141 | void RenderNode::removeAnimator(const sp<BaseRenderNodeAnimator>& animator) { |
| 142 | mAnimatorManager.removeAnimator(animator); |
| 143 | } |
| 144 | |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 145 | void RenderNode::damageSelf(TreeInfo& info) { |
John Reck | ce9f308 | 2014-06-17 16:18:09 -0700 | [diff] [blame] | 146 | if (isRenderable()) { |
John Reck | f1aa7909e | 2019-03-07 17:01:08 -0800 | [diff] [blame] | 147 | mDamageGenerationId = info.damageGenerationId; |
John Reck | 293e868 | 2014-06-17 10:34:02 -0700 | [diff] [blame] | 148 | if (properties().getClipDamageToBounds()) { |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 149 | info.damageAccumulator->dirty(0, 0, properties().getWidth(), properties().getHeight()); |
| 150 | } else { |
| 151 | // Hope this is big enough? |
| 152 | // TODO: Get this from the display list ops or something |
John Reck | c128823 | 2015-08-12 13:39:11 -0700 | [diff] [blame] | 153 | info.damageAccumulator->dirty(DIRTY_MIN, DIRTY_MIN, DIRTY_MAX, DIRTY_MAX); |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 154 | } |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 155 | } |
| 156 | } |
| 157 | |
John Reck | a7c2ea2 | 2014-08-08 13:21:00 -0700 | [diff] [blame] | 158 | void RenderNode::prepareLayer(TreeInfo& info, uint32_t dirtyMask) { |
Chris Craik | 856f0cc | 2015-04-21 15:13:29 -0700 | [diff] [blame] | 159 | LayerType layerType = properties().effectiveLayerType(); |
Chris Craik | 182952f | 2015-03-09 14:17:29 -0700 | [diff] [blame] | 160 | if (CC_UNLIKELY(layerType == LayerType::RenderLayer)) { |
John Reck | a7c2ea2 | 2014-08-08 13:21:00 -0700 | [diff] [blame] | 161 | // Damage applied so far needs to affect our parent, but does not require |
| 162 | // the layer to be updated. So we pop/push here to clear out the current |
| 163 | // damage and get a clean state for display list or children updates to |
| 164 | // affect, which will require the layer to be updated |
| 165 | info.damageAccumulator->popTransform(); |
| 166 | info.damageAccumulator->pushTransform(this); |
| 167 | if (dirtyMask & DISPLAY_LIST) { |
| 168 | damageSelf(info); |
| 169 | } |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 170 | } |
| 171 | } |
| 172 | |
| 173 | void RenderNode::pushLayerUpdate(TreeInfo& info) { |
Fedor Kudasov | 86bd214 | 2019-06-18 15:51:57 +0100 | [diff] [blame] | 174 | #ifdef __ANDROID__ // Layoutlib does not support CanvasContext and Layers |
Chris Craik | 856f0cc | 2015-04-21 15:13:29 -0700 | [diff] [blame] | 175 | LayerType layerType = properties().effectiveLayerType(); |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 176 | // If we are not a layer OR we cannot be rendered (eg, view was detached) |
| 177 | // we need to destroy any Layers we may have had previously |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 178 | if (CC_LIKELY(layerType != LayerType::RenderLayer) || CC_UNLIKELY(!isRenderable()) || |
| 179 | CC_UNLIKELY(properties().getWidth() == 0) || CC_UNLIKELY(properties().getHeight() == 0) || |
| 180 | CC_UNLIKELY(!properties().fitsOnLayer())) { |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 181 | if (CC_UNLIKELY(hasLayer())) { |
Derek Sollenberger | 28a4d99 | 2018-09-20 13:37:24 -0400 | [diff] [blame] | 182 | this->setLayerSurface(nullptr); |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 183 | } |
| 184 | return; |
| 185 | } |
| 186 | |
Stan Iliev | 216b157 | 2018-03-26 14:29:50 -0400 | [diff] [blame] | 187 | if (info.canvasContext.createOrUpdateLayer(this, *info.damageAccumulator, info.errorHandler)) { |
Chris Craik | 9fded23 | 2015-11-11 16:42:34 -0800 | [diff] [blame] | 188 | damageSelf(info); |
Chris Craik | 69e5adf | 2014-08-14 13:34:01 -0700 | [diff] [blame] | 189 | } |
| 190 | |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 191 | if (!hasLayer()) { |
John Reck | c25e506 | 2014-06-18 14:21:29 -0700 | [diff] [blame] | 192 | return; |
| 193 | } |
| 194 | |
Derek Sollenberger | 6a21ca5 | 2016-09-28 13:39:55 -0400 | [diff] [blame] | 195 | SkRect dirty; |
| 196 | info.damageAccumulator->peekAtDirty(&dirty); |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 197 | info.layerUpdateQueue->enqueueLayerWithDamage(this, dirty); |
Nader Jawad | 197743f | 2021-04-19 19:45:13 -0700 | [diff] [blame] | 198 | if (!dirty.isEmpty()) { |
| 199 | mStretchMask.markDirty(); |
| 200 | } |
John Reck | 998a6d8 | 2014-08-28 15:35:53 -0700 | [diff] [blame] | 201 | |
Chris Craik | e2e53a7 | 2015-10-28 15:55:40 -0700 | [diff] [blame] | 202 | // There might be prefetched layers that need to be accounted for. |
| 203 | // That might be us, so tell CanvasContext that this layer is in the |
| 204 | // tree and should not be destroyed. |
| 205 | info.canvasContext.markLayerInUse(this); |
Fedor Kudasov | 86bd214 | 2019-06-18 15:51:57 +0100 | [diff] [blame] | 206 | #endif |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 207 | } |
| 208 | |
Chris Craik | a766cb2 | 2015-06-08 16:49:43 -0700 | [diff] [blame] | 209 | /** |
| 210 | * Traverse down the the draw tree to prepare for a frame. |
| 211 | * |
| 212 | * MODE_FULL = UI Thread-driven (thus properties must be synced), otherwise RT driven |
| 213 | * |
| 214 | * While traversing down the tree, functorsNeedLayer flag is set to true if anything that uses the |
| 215 | * stencil buffer may be needed. Views that use a functor to draw will be forced onto a layer. |
| 216 | */ |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 217 | void RenderNode::prepareTreeImpl(TreeObserver& observer, TreeInfo& info, bool functorsNeedLayer) { |
John Reck | f1aa7909e | 2019-03-07 17:01:08 -0800 | [diff] [blame] | 218 | if (mDamageGenerationId == info.damageGenerationId) { |
| 219 | // We hit the same node a second time in the same tree. We don't know the minimal |
| 220 | // damage rect anymore, so just push the biggest we can onto our parent's transform |
| 221 | // We push directly onto parent in case we are clipped to bounds but have moved position. |
| 222 | info.damageAccumulator->dirty(DIRTY_MIN, DIRTY_MIN, DIRTY_MAX, DIRTY_MAX); |
| 223 | } |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 224 | info.damageAccumulator->pushTransform(this); |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 225 | |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 226 | if (info.mode == TreeInfo::MODE_FULL) { |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 227 | pushStagingPropertiesChanges(info); |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 228 | } |
John Reck | 1423e13 | 2018-09-21 14:30:19 -0700 | [diff] [blame] | 229 | |
| 230 | if (!mProperties.getAllowForceDark()) { |
| 231 | info.disableForceDark++; |
| 232 | } |
John Reck | 5d53a75 | 2021-02-08 19:22:59 -0500 | [diff] [blame] | 233 | if (!mProperties.layerProperties().getStretchEffect().isEmpty()) { |
| 234 | info.stretchEffectCount++; |
| 235 | } |
John Reck | 1423e13 | 2018-09-21 14:30:19 -0700 | [diff] [blame] | 236 | |
John Reck | 9eb9f6f | 2014-08-21 11:23:05 -0700 | [diff] [blame] | 237 | uint32_t animatorDirtyMask = 0; |
| 238 | if (CC_LIKELY(info.runAnimations)) { |
| 239 | animatorDirtyMask = mAnimatorManager.animate(info); |
| 240 | } |
Chris Craik | a766cb2 | 2015-06-08 16:49:43 -0700 | [diff] [blame] | 241 | |
John Reck | 3f725f0 | 2015-06-16 10:29:31 -0700 | [diff] [blame] | 242 | bool willHaveFunctor = false; |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 243 | if (info.mode == TreeInfo::MODE_FULL && mStagingDisplayList) { |
John Reck | be67195 | 2021-01-13 22:39:32 -0500 | [diff] [blame] | 244 | willHaveFunctor = mStagingDisplayList.hasFunctor(); |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 245 | } else if (mDisplayList) { |
John Reck | be67195 | 2021-01-13 22:39:32 -0500 | [diff] [blame] | 246 | willHaveFunctor = mDisplayList.hasFunctor(); |
John Reck | 3f725f0 | 2015-06-16 10:29:31 -0700 | [diff] [blame] | 247 | } |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 248 | bool childFunctorsNeedLayer = |
| 249 | mProperties.prepareForFunctorPresence(willHaveFunctor, functorsNeedLayer); |
Chris Craik | a766cb2 | 2015-06-08 16:49:43 -0700 | [diff] [blame] | 250 | |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 251 | if (CC_UNLIKELY(mPositionListener.get())) { |
| 252 | mPositionListener->onPositionUpdated(*this, info); |
| 253 | } |
| 254 | |
John Reck | a7c2ea2 | 2014-08-08 13:21:00 -0700 | [diff] [blame] | 255 | prepareLayer(info, animatorDirtyMask); |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 256 | if (info.mode == TreeInfo::MODE_FULL) { |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 257 | pushStagingDisplayListChanges(observer, info); |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 258 | } |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 259 | |
Doris Liu | 07c056d | 2016-06-13 12:52:44 -0700 | [diff] [blame] | 260 | if (mDisplayList) { |
John Reck | be67195 | 2021-01-13 22:39:32 -0500 | [diff] [blame] | 261 | info.out.hasFunctors |= mDisplayList.hasFunctor(); |
Nader Jawad | 2dc632a | 2021-03-29 18:51:29 -0700 | [diff] [blame] | 262 | mHasHolePunches = mDisplayList.hasHolePunches(); |
John Reck | be67195 | 2021-01-13 22:39:32 -0500 | [diff] [blame] | 263 | bool isDirty = mDisplayList.prepareListAndChildren( |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 264 | observer, info, childFunctorsNeedLayer, |
Nader Jawad | 2dc632a | 2021-03-29 18:51:29 -0700 | [diff] [blame] | 265 | [this](RenderNode* child, TreeObserver& observer, TreeInfo& info, |
| 266 | bool functorsNeedLayer) { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 267 | child->prepareTreeImpl(observer, info, functorsNeedLayer); |
Nader Jawad | 2dc632a | 2021-03-29 18:51:29 -0700 | [diff] [blame] | 268 | mHasHolePunches |= child->hasHolePunches(); |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 269 | }); |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 270 | if (isDirty) { |
| 271 | damageSelf(info); |
Doris Liu | 718cd3e | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 272 | } |
Nader Jawad | 2dc632a | 2021-03-29 18:51:29 -0700 | [diff] [blame] | 273 | } else { |
| 274 | mHasHolePunches = false; |
Doris Liu | 718cd3e | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 275 | } |
Doris Liu | b51b286 | 2016-08-01 19:56:47 -0700 | [diff] [blame] | 276 | pushLayerUpdate(info); |
Doris Liu | 718cd3e | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 277 | |
John Reck | 1423e13 | 2018-09-21 14:30:19 -0700 | [diff] [blame] | 278 | if (!mProperties.getAllowForceDark()) { |
| 279 | info.disableForceDark--; |
| 280 | } |
John Reck | 5d53a75 | 2021-02-08 19:22:59 -0500 | [diff] [blame] | 281 | if (!mProperties.layerProperties().getStretchEffect().isEmpty()) { |
| 282 | info.stretchEffectCount--; |
| 283 | } |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 284 | info.damageAccumulator->popTransform(); |
John Reck | f4198b7 | 2014-04-09 17:00:04 -0700 | [diff] [blame] | 285 | } |
| 286 | |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 287 | void RenderNode::syncProperties() { |
| 288 | mProperties = mStagingProperties; |
| 289 | } |
| 290 | |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 291 | void RenderNode::pushStagingPropertiesChanges(TreeInfo& info) { |
John Reck | 097e1d3 | 2019-06-12 15:01:51 -0700 | [diff] [blame] | 292 | if (mPositionListenerDirty) { |
| 293 | mPositionListener = std::move(mStagingPositionListener); |
| 294 | mStagingPositionListener = nullptr; |
| 295 | mPositionListenerDirty = false; |
| 296 | } |
| 297 | |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 298 | // Push the animators first so that setupStartValueIfNecessary() is called |
| 299 | // before properties() is trampled by stagingProperties(), as they are |
| 300 | // required by some animators. |
John Reck | 9eb9f6f | 2014-08-21 11:23:05 -0700 | [diff] [blame] | 301 | if (CC_LIKELY(info.runAnimations)) { |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 302 | mAnimatorManager.pushStaging(); |
John Reck | 9eb9f6f | 2014-08-21 11:23:05 -0700 | [diff] [blame] | 303 | } |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 304 | if (mDirtyPropertyFields) { |
| 305 | mDirtyPropertyFields = 0; |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 306 | damageSelf(info); |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 307 | info.damageAccumulator->popTransform(); |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 308 | syncProperties(); |
Nader Jawad | 197743f | 2021-04-19 19:45:13 -0700 | [diff] [blame] | 309 | |
Nader Jawad | 6aff481 | 2021-06-09 10:14:43 -0700 | [diff] [blame] | 310 | auto& layerProperties = mProperties.layerProperties(); |
| 311 | const StretchEffect& stagingStretch = layerProperties.getStretchEffect(); |
Nader Jawad | 197743f | 2021-04-19 19:45:13 -0700 | [diff] [blame] | 312 | if (stagingStretch.isEmpty()) { |
| 313 | mStretchMask.clear(); |
| 314 | } |
Nader Jawad | 6aff481 | 2021-06-09 10:14:43 -0700 | [diff] [blame] | 315 | |
| 316 | if (layerProperties.getImageFilter() == nullptr) { |
| 317 | mSnapshotResult.snapshot = nullptr; |
| 318 | mTargetImageFilter = nullptr; |
| 319 | } |
| 320 | |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 321 | // We could try to be clever and only re-damage if the matrix changed. |
| 322 | // However, we don't need to worry about that. The cost of over-damaging |
| 323 | // here is only going to be a single additional map rect of this node |
| 324 | // plus a rect join(). The parent's transform (and up) will only be |
| 325 | // performed once. |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 326 | info.damageAccumulator->pushTransform(this); |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 327 | damageSelf(info); |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 328 | } |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 329 | } |
| 330 | |
Nader Jawad | 6aff481 | 2021-06-09 10:14:43 -0700 | [diff] [blame] | 331 | std::optional<RenderNode::SnapshotResult> RenderNode::updateSnapshotIfRequired( |
| 332 | GrRecordingContext* context, |
| 333 | const SkImageFilter* imageFilter, |
| 334 | const SkIRect& clipBounds |
| 335 | ) { |
| 336 | auto* layerSurface = getLayerSurface(); |
| 337 | if (layerSurface == nullptr) { |
| 338 | return std::nullopt; |
| 339 | } |
| 340 | |
| 341 | sk_sp<SkImage> snapshot = layerSurface->makeImageSnapshot(); |
| 342 | const auto subset = SkIRect::MakeWH(properties().getWidth(), |
| 343 | properties().getHeight()); |
| 344 | // If we don't have an ImageFilter just return the snapshot |
| 345 | if (imageFilter == nullptr) { |
| 346 | mSnapshotResult.snapshot = snapshot; |
| 347 | mSnapshotResult.outSubset = subset; |
| 348 | mSnapshotResult.outOffset = SkIPoint::Make(0.0f, 0.0f); |
| 349 | mImageFilterClipBounds = clipBounds; |
| 350 | mTargetImageFilter = nullptr; |
| 351 | } else if (mSnapshotResult.snapshot == nullptr || |
| 352 | imageFilter != mTargetImageFilter.get() || |
| 353 | mImageFilterClipBounds != clipBounds) { |
| 354 | // Otherwise create a new snapshot with the given filter and snapshot |
| 355 | mSnapshotResult.snapshot = |
| 356 | snapshot->makeWithFilter(context, |
| 357 | imageFilter, |
| 358 | subset, |
| 359 | clipBounds, |
| 360 | &mSnapshotResult.outSubset, |
| 361 | &mSnapshotResult.outOffset); |
| 362 | mTargetImageFilter = sk_ref_sp(imageFilter); |
| 363 | mImageFilterClipBounds = clipBounds; |
| 364 | } |
| 365 | |
| 366 | return mSnapshotResult; |
| 367 | } |
| 368 | |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 369 | void RenderNode::syncDisplayList(TreeObserver& observer, TreeInfo* info) { |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 370 | // Make sure we inc first so that we don't fluctuate between 0 and 1, |
| 371 | // which would thrash the layer cache |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 372 | if (mStagingDisplayList) { |
John Reck | be67195 | 2021-01-13 22:39:32 -0500 | [diff] [blame] | 373 | mStagingDisplayList.updateChildren([](RenderNode* child) { child->incParentRefCount(); }); |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 374 | } |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 375 | deleteDisplayList(observer, info); |
John Reck | be67195 | 2021-01-13 22:39:32 -0500 | [diff] [blame] | 376 | mDisplayList = std::move(mStagingDisplayList); |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 377 | if (mDisplayList) { |
John Reck | 283bb46 | 2018-12-13 16:40:14 -0800 | [diff] [blame] | 378 | WebViewSyncData syncData { |
| 379 | .applyForceDark = info && !info->disableForceDark |
| 380 | }; |
John Reck | be67195 | 2021-01-13 22:39:32 -0500 | [diff] [blame] | 381 | mDisplayList.syncContents(syncData); |
John Reck | 3b4510cd | 2018-09-27 17:39:45 -0700 | [diff] [blame] | 382 | handleForceDark(info); |
| 383 | } |
| 384 | } |
John Reck | f3c724f | 2018-09-20 13:00:04 -0700 | [diff] [blame] | 385 | |
John Reck | 3b4510cd | 2018-09-27 17:39:45 -0700 | [diff] [blame] | 386 | void RenderNode::handleForceDark(android::uirenderer::TreeInfo *info) { |
| 387 | if (CC_LIKELY(!info || info->disableForceDark)) { |
| 388 | return; |
| 389 | } |
| 390 | auto usage = usageHint(); |
John Reck | be67195 | 2021-01-13 22:39:32 -0500 | [diff] [blame] | 391 | FatVector<RenderNode*, 6> children; |
| 392 | mDisplayList.updateChildren([&children](RenderNode* node) { |
| 393 | children.push_back(node); |
| 394 | }); |
| 395 | if (mDisplayList.hasText()) { |
John Reck | 3b4510cd | 2018-09-27 17:39:45 -0700 | [diff] [blame] | 396 | usage = UsageHint::Foreground; |
| 397 | } |
| 398 | if (usage == UsageHint::Unknown) { |
| 399 | if (children.size() > 1) { |
| 400 | usage = UsageHint::Background; |
| 401 | } else if (children.size() == 1 && |
John Reck | be67195 | 2021-01-13 22:39:32 -0500 | [diff] [blame] | 402 | children.front()->usageHint() != |
John Reck | 3b4510cd | 2018-09-27 17:39:45 -0700 | [diff] [blame] | 403 | UsageHint::Background) { |
| 404 | usage = UsageHint::Background; |
John Reck | 8f45d4a | 2018-08-15 10:17:12 -0700 | [diff] [blame] | 405 | } |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 406 | } |
John Reck | 3b4510cd | 2018-09-27 17:39:45 -0700 | [diff] [blame] | 407 | if (children.size() > 1) { |
| 408 | // Crude overlap check |
| 409 | SkRect drawn = SkRect::MakeEmpty(); |
| 410 | for (auto iter = children.rbegin(); iter != children.rend(); ++iter) { |
John Reck | be67195 | 2021-01-13 22:39:32 -0500 | [diff] [blame] | 411 | const auto& child = *iter; |
John Reck | 3b4510cd | 2018-09-27 17:39:45 -0700 | [diff] [blame] | 412 | // We use stagingProperties here because we haven't yet sync'd the children |
| 413 | SkRect bounds = SkRect::MakeXYWH(child->stagingProperties().getX(), child->stagingProperties().getY(), |
| 414 | child->stagingProperties().getWidth(), child->stagingProperties().getHeight()); |
| 415 | if (bounds.contains(drawn)) { |
| 416 | // This contains everything drawn after it, so make it a background |
| 417 | child->setUsageHint(UsageHint::Background); |
| 418 | } |
| 419 | drawn.join(bounds); |
| 420 | } |
| 421 | } |
John Reck | be67195 | 2021-01-13 22:39:32 -0500 | [diff] [blame] | 422 | mDisplayList.applyColorTransform( |
John Reck | 3b4510cd | 2018-09-27 17:39:45 -0700 | [diff] [blame] | 423 | usage == UsageHint::Background ? ColorTransform::Dark : ColorTransform::Light); |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 424 | } |
| 425 | |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 426 | void RenderNode::pushStagingDisplayListChanges(TreeObserver& observer, TreeInfo& info) { |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 427 | if (mNeedsDisplayListSync) { |
| 428 | mNeedsDisplayListSync = false; |
John Reck | 5c9d717 | 2014-10-22 11:32:27 -0700 | [diff] [blame] | 429 | // Damage with the old display list first then the new one to catch any |
| 430 | // changes in isRenderable or, in the future, bounds |
| 431 | damageSelf(info); |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 432 | syncDisplayList(observer, &info); |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 433 | damageSelf(info); |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 434 | } |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 435 | } |
| 436 | |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 437 | void RenderNode::deleteDisplayList(TreeObserver& observer, TreeInfo* info) { |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 438 | if (mDisplayList) { |
John Reck | be67195 | 2021-01-13 22:39:32 -0500 | [diff] [blame] | 439 | mDisplayList.updateChildren( |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 440 | [&observer, info](RenderNode* child) { child->decParentRefCount(observer, info); }); |
John Reck | be67195 | 2021-01-13 22:39:32 -0500 | [diff] [blame] | 441 | mDisplayList.clear(this); |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 442 | } |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 443 | } |
| 444 | |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 445 | void RenderNode::destroyHardwareResources(TreeInfo* info) { |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 446 | if (hasLayer()) { |
Derek Sollenberger | 28a4d99 | 2018-09-20 13:37:24 -0400 | [diff] [blame] | 447 | this->setLayerSurface(nullptr); |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 448 | } |
John Reck | be67195 | 2021-01-13 22:39:32 -0500 | [diff] [blame] | 449 | discardStagingDisplayList(); |
John Reck | 3afd637 | 2017-01-30 10:15:48 -0800 | [diff] [blame] | 450 | |
| 451 | ImmediateRemoved observer(info); |
| 452 | deleteDisplayList(observer, info); |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | void RenderNode::destroyLayers() { |
| 456 | if (hasLayer()) { |
Derek Sollenberger | 28a4d99 | 2018-09-20 13:37:24 -0400 | [diff] [blame] | 457 | this->setLayerSurface(nullptr); |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 458 | } |
Nader Jawad | b502ad7 | 2021-06-17 14:10:04 -0700 | [diff] [blame] | 459 | |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 460 | if (mDisplayList) { |
John Reck | be67195 | 2021-01-13 22:39:32 -0500 | [diff] [blame] | 461 | mDisplayList.updateChildren([](RenderNode* child) { child->destroyLayers(); }); |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 462 | } |
| 463 | } |
| 464 | |
| 465 | void RenderNode::decParentRefCount(TreeObserver& observer, TreeInfo* info) { |
| 466 | LOG_ALWAYS_FATAL_IF(!mParentCount, "already 0!"); |
| 467 | mParentCount--; |
| 468 | if (!mParentCount) { |
| 469 | observer.onMaybeRemovedFromTree(this); |
| 470 | if (CC_UNLIKELY(mPositionListener.get())) { |
| 471 | mPositionListener->onPositionLost(*this, info); |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 472 | } |
| 473 | } |
| 474 | } |
| 475 | |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 476 | void RenderNode::onRemovedFromTree(TreeInfo* info) { |
Huihong Luo | ec68b7c | 2021-06-25 21:54:16 -0700 | [diff] [blame] | 477 | if (Properties::enableWebViewOverlays && mDisplayList) { |
| 478 | mDisplayList.onRemovedFromTree(); |
| 479 | } |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 480 | destroyHardwareResources(info); |
| 481 | } |
| 482 | |
| 483 | void RenderNode::clearRoot() { |
| 484 | ImmediateRemoved observer(nullptr); |
| 485 | decParentRefCount(observer); |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 486 | } |
| 487 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 488 | /** |
| 489 | * Apply property-based transformations to input matrix |
| 490 | * |
| 491 | * If true3dTransform is set to true, the transform applied to the input matrix will use true 4x4 |
| 492 | * matrix computation instead of the Skia 3x3 matrix + camera hackery. |
| 493 | */ |
Chris Craik | 69e5adf | 2014-08-14 13:34:01 -0700 | [diff] [blame] | 494 | void RenderNode::applyViewPropertyTransforms(mat4& matrix, bool true3dTransform) const { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 495 | if (properties().getLeft() != 0 || properties().getTop() != 0) { |
| 496 | matrix.translate(properties().getLeft(), properties().getTop()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 497 | } |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 498 | if (properties().getStaticMatrix()) { |
| 499 | mat4 stat(*properties().getStaticMatrix()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 500 | matrix.multiply(stat); |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 501 | } else if (properties().getAnimationMatrix()) { |
| 502 | mat4 anim(*properties().getAnimationMatrix()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 503 | matrix.multiply(anim); |
| 504 | } |
Chris Craik | e0bb87d | 2014-04-22 17:55:41 -0700 | [diff] [blame] | 505 | |
Chris Craik | cc39e16 | 2014-04-25 18:34:11 -0700 | [diff] [blame] | 506 | bool applyTranslationZ = true3dTransform && !MathUtils::isZero(properties().getZ()); |
Chris Craik | e0bb87d | 2014-04-22 17:55:41 -0700 | [diff] [blame] | 507 | if (properties().hasTransformMatrix() || applyTranslationZ) { |
John Reck | f7483e3 | 2014-04-11 08:54:47 -0700 | [diff] [blame] | 508 | if (properties().isTransformTranslateOnly()) { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 509 | matrix.translate(properties().getTranslationX(), properties().getTranslationY(), |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 510 | true3dTransform ? properties().getZ() : 0.0f); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 511 | } else { |
| 512 | if (!true3dTransform) { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 513 | matrix.multiply(*properties().getTransformMatrix()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 514 | } else { |
| 515 | mat4 true3dMat; |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 516 | true3dMat.loadTranslate(properties().getPivotX() + properties().getTranslationX(), |
| 517 | properties().getPivotY() + properties().getTranslationY(), |
| 518 | properties().getZ()); |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 519 | true3dMat.rotate(properties().getRotationX(), 1, 0, 0); |
| 520 | true3dMat.rotate(properties().getRotationY(), 0, 1, 0); |
| 521 | true3dMat.rotate(properties().getRotation(), 0, 0, 1); |
| 522 | true3dMat.scale(properties().getScaleX(), properties().getScaleY(), 1); |
| 523 | true3dMat.translate(-properties().getPivotX(), -properties().getPivotY()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 524 | |
| 525 | matrix.multiply(true3dMat); |
| 526 | } |
| 527 | } |
| 528 | } |
John Reck | 8ed00dc | 2021-05-10 13:09:27 -0400 | [diff] [blame] | 529 | |
Nader Jawad | 93d6e24 | 2021-05-17 18:12:29 -0700 | [diff] [blame] | 530 | if (Properties::getStretchEffectBehavior() == StretchEffectBehavior::UniformScale) { |
John Reck | 8ed00dc | 2021-05-10 13:09:27 -0400 | [diff] [blame] | 531 | const StretchEffect& stretch = properties().layerProperties().getStretchEffect(); |
| 532 | if (!stretch.isEmpty()) { |
| 533 | matrix.multiply( |
| 534 | stretch.makeLinearStretch(properties().getWidth(), properties().getHeight())); |
| 535 | } |
| 536 | } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 537 | } |
| 538 | |
Derek Sollenberger | 579317d4 | 2017-08-29 16:33:49 -0400 | [diff] [blame] | 539 | const SkPath* RenderNode::getClippedOutline(const SkRect& clipRect) const { |
| 540 | const SkPath* outlinePath = properties().getOutline().getPath(); |
| 541 | const uint32_t outlineID = outlinePath->getGenerationID(); |
| 542 | |
| 543 | if (outlineID != mClippedOutlineCache.outlineID || clipRect != mClippedOutlineCache.clipRect) { |
| 544 | // update the cache keys |
| 545 | mClippedOutlineCache.outlineID = outlineID; |
| 546 | mClippedOutlineCache.clipRect = clipRect; |
| 547 | |
| 548 | // update the cache value by recomputing a new path |
| 549 | SkPath clipPath; |
| 550 | clipPath.addRect(clipRect); |
| 551 | Op(*outlinePath, clipPath, kIntersect_SkPathOp, &mClippedOutlineCache.clippedOutline); |
Derek Sollenberger | 579317d4 | 2017-08-29 16:33:49 -0400 | [diff] [blame] | 552 | } |
| 553 | return &mClippedOutlineCache.clippedOutline; |
| 554 | } |
| 555 | |
John Reck | f96b284 | 2018-11-29 09:44:10 -0800 | [diff] [blame] | 556 | using StringBuffer = FatVector<char, 128>; |
| 557 | |
| 558 | template <typename... T> |
John Reck | 7af5b2c | 2018-12-05 13:36:20 -0800 | [diff] [blame] | 559 | // TODO:__printflike(2, 3) |
| 560 | // Doesn't work because the warning doesn't understand string_view and doesn't like that |
| 561 | // it's not a C-style variadic function. |
John Reck | f96b284 | 2018-11-29 09:44:10 -0800 | [diff] [blame] | 562 | static void format(StringBuffer& buffer, const std::string_view& format, T... args) { |
| 563 | buffer.resize(buffer.capacity()); |
| 564 | while (1) { |
| 565 | int needed = snprintf(buffer.data(), buffer.size(), |
| 566 | format.data(), std::forward<T>(args)...); |
| 567 | if (needed < 0) { |
| 568 | buffer[0] = '\0'; |
| 569 | buffer.resize(1); |
| 570 | return; |
| 571 | } |
| 572 | if (needed < buffer.size()) { |
| 573 | buffer.resize(needed + 1); |
| 574 | return; |
| 575 | } |
John Reck | 7af5b2c | 2018-12-05 13:36:20 -0800 | [diff] [blame] | 576 | // If we're doing a heap alloc anyway might as well give it some slop |
| 577 | buffer.resize(needed + 100); |
John Reck | f96b284 | 2018-11-29 09:44:10 -0800 | [diff] [blame] | 578 | } |
| 579 | } |
| 580 | |
| 581 | void RenderNode::markDrawStart(SkCanvas& canvas) { |
| 582 | StringBuffer buffer; |
John Reck | 7af5b2c | 2018-12-05 13:36:20 -0800 | [diff] [blame] | 583 | format(buffer, "RenderNode(id=%" PRId64 ", name='%s')", uniqueId(), getName()); |
John Reck | f96b284 | 2018-11-29 09:44:10 -0800 | [diff] [blame] | 584 | canvas.drawAnnotation(SkRect::MakeWH(getWidth(), getHeight()), buffer.data(), nullptr); |
| 585 | } |
| 586 | |
| 587 | void RenderNode::markDrawEnd(SkCanvas& canvas) { |
| 588 | StringBuffer buffer; |
John Reck | 7af5b2c | 2018-12-05 13:36:20 -0800 | [diff] [blame] | 589 | format(buffer, "/RenderNode(id=%" PRId64 ", name='%s')", uniqueId(), getName()); |
John Reck | f96b284 | 2018-11-29 09:44:10 -0800 | [diff] [blame] | 590 | canvas.drawAnnotation(SkRect::MakeWH(getWidth(), getHeight()), buffer.data(), nullptr); |
| 591 | } |
| 592 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 593 | } /* namespace uirenderer */ |
| 594 | } /* namespace android */ |