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