blob: 896b4340f1b8c78d1c9eeb9074c7f0072942270b [file] [log] [blame]
John Reck113e0822014-03-18 09:22:59 -07001/*
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 Reck113e0822014-03-18 09:22:59 -070017#include "RenderNode.h"
18
John Recke4267ea2014-06-03 15:53:15 -070019#include "DamageAccumulator.h"
John Reck113e0822014-03-18 09:22:59 -070020#include "Debug.h"
Tom Hudson2dc236b2014-10-15 15:46:42 -040021#include "TreeInfo.h"
John Reck1bcacfd2017-11-03 10:12:19 -070022#include "VectorDrawable.h"
23#include "renderstate/RenderState.h"
24#include "renderthread/CanvasContext.h"
John Reck2de950d2017-01-25 10:58:30 -080025#include "utils/FatVector.h"
Chris Craike0bb87d2014-04-22 17:55:41 -070026#include "utils/MathUtils.h"
sergeyvc3849aa2016-08-08 13:22:06 -070027#include "utils/StringUtils.h"
Chris Craik70850ea2014-11-18 10:49:23 -080028#include "utils/TraceUtils.h"
John Reck113e0822014-03-18 09:22:59 -070029
Derek Sollenberger579317d2017-08-29 16:33:49 -040030#include <SkPathOps.h>
John Reck77c40102015-10-26 15:49:47 -070031#include <algorithm>
32#include <sstream>
33#include <string>
34
John Reck113e0822014-03-18 09:22:59 -070035namespace android {
36namespace uirenderer {
37
John Reck2de950d2017-01-25 10:58:30 -080038// Used for tree mutations that are purely destructive.
39// Generic tree mutations should use MarkAndSweepObserver instead
40class ImmediateRemoved : public TreeObserver {
41public:
42 explicit ImmediateRemoved(TreeInfo* info) : mTreeInfo(info) {}
43
John Reck1bcacfd2017-11-03 10:12:19 -070044 void onMaybeRemovedFromTree(RenderNode* node) override { node->onRemovedFromTree(mTreeInfo); }
John Reck2de950d2017-01-25 10:58:30 -080045
46private:
47 TreeInfo* mTreeInfo;
48};
49
John Reck8de65a82014-04-09 15:23:38 -070050RenderNode::RenderNode()
John Reckff941dc2014-05-14 16:34:14 -070051 : mDirtyPropertyFields(0)
Chris Craik003cc3d2015-10-16 10:24:55 -070052 , mNeedsDisplayListSync(false)
53 , mDisplayList(nullptr)
54 , mStagingDisplayList(nullptr)
John Reck68bfe0a2014-06-24 15:34:58 -070055 , mAnimatorManager(*this)
John Reck1bcacfd2017-11-03 10:12:19 -070056 , mParentCount(0) {}
John Reck113e0822014-03-18 09:22:59 -070057
58RenderNode::~RenderNode() {
John Reck2de950d2017-01-25 10:58:30 -080059 ImmediateRemoved observer(nullptr);
60 deleteDisplayList(observer);
Chris Craik003cc3d2015-10-16 10:24:55 -070061 delete mStagingDisplayList;
Derek Sollenberger0df62092016-09-27 16:04:42 -040062 LOG_ALWAYS_FATAL_IF(hasLayer(), "layer missed detachment!");
John Reck113e0822014-03-18 09:22:59 -070063}
64
John Reck2de950d2017-01-25 10:58:30 -080065void RenderNode::setStagingDisplayList(DisplayList* displayList) {
66 mValid = (displayList != nullptr);
Chris Craik003cc3d2015-10-16 10:24:55 -070067 mNeedsDisplayListSync = true;
68 delete mStagingDisplayList;
69 mStagingDisplayList = displayList;
John Reck113e0822014-03-18 09:22:59 -070070}
71
72/**
73 * This function is a simplified version of replay(), where we simply retrieve and log the
74 * display list. This function should remain in sync with the replay() function.
75 */
sergeyvc3849aa2016-08-08 13:22:06 -070076void RenderNode::output() {
77 LogcatStream strout;
78 strout << "Root";
79 output(strout, 0);
80}
81
82void RenderNode::output(std::ostream& output, uint32_t level) {
83 output << " (" << getName() << " " << this
John Reck1bcacfd2017-11-03 10:12:19 -070084 << (MathUtils::isZero(properties().getAlpha()) ? ", zero alpha" : "")
85 << (properties().hasShadow() ? ", casting shadow" : "")
86 << (isRenderable() ? "" : ", empty")
87 << (properties().getProjectBackwards() ? ", projected" : "")
88 << (hasLayer() ? ", on HW Layer" : "") << ")" << std::endl;
sergeyvc3849aa2016-08-08 13:22:06 -070089
90 properties().debugOutputProperties(output, level + 1);
Chris Craik91eff222016-02-22 13:39:33 -080091
92 if (mDisplayList) {
Stan Ilievd2172372017-02-09 16:59:27 -050093 mDisplayList->output(output, level);
Chris Craik91eff222016-02-22 13:39:33 -080094 }
sergeyvc3849aa2016-08-08 13:22:06 -070095 output << std::string(level * 2, ' ') << "/RenderNode(" << getName() << " " << this << ")";
96 output << std::endl;
Chris Craik91eff222016-02-22 13:39:33 -080097}
John Reck113e0822014-03-18 09:22:59 -070098
John Reckfe5e7b72014-05-23 17:42:28 -070099int RenderNode::getDebugSize() {
100 int size = sizeof(RenderNode);
Chris Craik003cc3d2015-10-16 10:24:55 -0700101 if (mStagingDisplayList) {
102 size += mStagingDisplayList->getUsedSize();
John Reckfe5e7b72014-05-23 17:42:28 -0700103 }
Chris Craik003cc3d2015-10-16 10:24:55 -0700104 if (mDisplayList && mDisplayList != mStagingDisplayList) {
105 size += mDisplayList->getUsedSize();
John Reckfe5e7b72014-05-23 17:42:28 -0700106 }
107 return size;
108}
109
John Reckf4198b72014-04-09 17:00:04 -0700110void RenderNode::prepareTree(TreeInfo& info) {
111 ATRACE_CALL();
Chris Craik69e5adf2014-08-14 13:34:01 -0700112 LOG_ALWAYS_FATAL_IF(!info.damageAccumulator, "DamageAccumulator missing");
John Reck2de950d2017-01-25 10:58:30 -0800113 MarkAndSweepRemoved observer(&info);
John Reckf4198b72014-04-09 17:00:04 -0700114
John Reck1072fff2018-04-12 15:20:09 -0700115 prepareTreeImpl(observer, info, false);
John Reckf4198b72014-04-09 17:00:04 -0700116}
117
John Reck68bfe0a2014-06-24 15:34:58 -0700118void RenderNode::addAnimator(const sp<BaseRenderNodeAnimator>& animator) {
119 mAnimatorManager.addAnimator(animator);
120}
121
Doris Liu8b083202016-02-19 21:46:06 +0000122void RenderNode::removeAnimator(const sp<BaseRenderNodeAnimator>& animator) {
123 mAnimatorManager.removeAnimator(animator);
124}
125
John Recke4267ea2014-06-03 15:53:15 -0700126void RenderNode::damageSelf(TreeInfo& info) {
John Reckce9f3082014-06-17 16:18:09 -0700127 if (isRenderable()) {
John Reck293e8682014-06-17 10:34:02 -0700128 if (properties().getClipDamageToBounds()) {
John Recka447d292014-06-11 18:39:44 -0700129 info.damageAccumulator->dirty(0, 0, properties().getWidth(), properties().getHeight());
130 } else {
131 // Hope this is big enough?
132 // TODO: Get this from the display list ops or something
John Reckc1288232015-08-12 13:39:11 -0700133 info.damageAccumulator->dirty(DIRTY_MIN, DIRTY_MIN, DIRTY_MAX, DIRTY_MAX);
John Recka447d292014-06-11 18:39:44 -0700134 }
John Recke4267ea2014-06-03 15:53:15 -0700135 }
136}
137
John Recka7c2ea22014-08-08 13:21:00 -0700138void RenderNode::prepareLayer(TreeInfo& info, uint32_t dirtyMask) {
Chris Craik856f0cc2015-04-21 15:13:29 -0700139 LayerType layerType = properties().effectiveLayerType();
Chris Craik182952f2015-03-09 14:17:29 -0700140 if (CC_UNLIKELY(layerType == LayerType::RenderLayer)) {
John Recka7c2ea22014-08-08 13:21:00 -0700141 // Damage applied so far needs to affect our parent, but does not require
142 // the layer to be updated. So we pop/push here to clear out the current
143 // damage and get a clean state for display list or children updates to
144 // affect, which will require the layer to be updated
145 info.damageAccumulator->popTransform();
146 info.damageAccumulator->pushTransform(this);
147 if (dirtyMask & DISPLAY_LIST) {
148 damageSelf(info);
149 }
John Reck25fbb3f2014-06-12 13:46:45 -0700150 }
151}
152
153void RenderNode::pushLayerUpdate(TreeInfo& info) {
Chris Craik856f0cc2015-04-21 15:13:29 -0700154 LayerType layerType = properties().effectiveLayerType();
John Reck25fbb3f2014-06-12 13:46:45 -0700155 // If we are not a layer OR we cannot be rendered (eg, view was detached)
156 // we need to destroy any Layers we may have had previously
John Reck1bcacfd2017-11-03 10:12:19 -0700157 if (CC_LIKELY(layerType != LayerType::RenderLayer) || CC_UNLIKELY(!isRenderable()) ||
158 CC_UNLIKELY(properties().getWidth() == 0) || CC_UNLIKELY(properties().getHeight() == 0) ||
159 CC_UNLIKELY(!properties().fitsOnLayer())) {
Derek Sollenberger0df62092016-09-27 16:04:42 -0400160 if (CC_UNLIKELY(hasLayer())) {
Derek Sollenberger28a4d992018-09-20 13:37:24 -0400161 this->setLayerSurface(nullptr);
John Reck25fbb3f2014-06-12 13:46:45 -0700162 }
163 return;
164 }
165
Stan Iliev216b1572018-03-26 14:29:50 -0400166 if (info.canvasContext.createOrUpdateLayer(this, *info.damageAccumulator, info.errorHandler)) {
Chris Craik9fded232015-11-11 16:42:34 -0800167 damageSelf(info);
Chris Craik69e5adf2014-08-14 13:34:01 -0700168 }
169
Derek Sollenberger0df62092016-09-27 16:04:42 -0400170 if (!hasLayer()) {
John Reckc25e5062014-06-18 14:21:29 -0700171 return;
172 }
173
Derek Sollenberger6a21ca52016-09-28 13:39:55 -0400174 SkRect dirty;
175 info.damageAccumulator->peekAtDirty(&dirty);
Chris Craik0b7e8242015-10-28 16:50:44 -0700176 info.layerUpdateQueue->enqueueLayerWithDamage(this, dirty);
John Reck998a6d82014-08-28 15:35:53 -0700177
Chris Craike2e53a72015-10-28 15:55:40 -0700178 // There might be prefetched layers that need to be accounted for.
179 // That might be us, so tell CanvasContext that this layer is in the
180 // tree and should not be destroyed.
181 info.canvasContext.markLayerInUse(this);
John Reck25fbb3f2014-06-12 13:46:45 -0700182}
183
Chris Craika766cb22015-06-08 16:49:43 -0700184/**
185 * Traverse down the the draw tree to prepare for a frame.
186 *
187 * MODE_FULL = UI Thread-driven (thus properties must be synced), otherwise RT driven
188 *
189 * While traversing down the tree, functorsNeedLayer flag is set to true if anything that uses the
190 * stencil buffer may be needed. Views that use a functor to draw will be forced onto a layer.
191 */
John Reck2de950d2017-01-25 10:58:30 -0800192void RenderNode::prepareTreeImpl(TreeObserver& observer, TreeInfo& info, bool functorsNeedLayer) {
John Recka447d292014-06-11 18:39:44 -0700193 info.damageAccumulator->pushTransform(this);
John Reckf47a5942014-06-30 16:20:04 -0700194
John Reckdcba6722014-07-08 13:59:49 -0700195 if (info.mode == TreeInfo::MODE_FULL) {
John Reck25fbb3f2014-06-12 13:46:45 -0700196 pushStagingPropertiesChanges(info);
John Recke45b1fd2014-04-15 09:50:16 -0700197 }
John Reck9eb9f6f2014-08-21 11:23:05 -0700198 uint32_t animatorDirtyMask = 0;
199 if (CC_LIKELY(info.runAnimations)) {
200 animatorDirtyMask = mAnimatorManager.animate(info);
201 }
Chris Craika766cb22015-06-08 16:49:43 -0700202
John Reck3f725f02015-06-16 10:29:31 -0700203 bool willHaveFunctor = false;
Chris Craik003cc3d2015-10-16 10:24:55 -0700204 if (info.mode == TreeInfo::MODE_FULL && mStagingDisplayList) {
Derek Sollenberger0df62092016-09-27 16:04:42 -0400205 willHaveFunctor = mStagingDisplayList->hasFunctor();
Chris Craik003cc3d2015-10-16 10:24:55 -0700206 } else if (mDisplayList) {
Derek Sollenberger0df62092016-09-27 16:04:42 -0400207 willHaveFunctor = mDisplayList->hasFunctor();
John Reck3f725f02015-06-16 10:29:31 -0700208 }
John Reck1bcacfd2017-11-03 10:12:19 -0700209 bool childFunctorsNeedLayer =
210 mProperties.prepareForFunctorPresence(willHaveFunctor, functorsNeedLayer);
Chris Craika766cb22015-06-08 16:49:43 -0700211
John Reckf6481082016-02-02 15:18:23 -0800212 if (CC_UNLIKELY(mPositionListener.get())) {
213 mPositionListener->onPositionUpdated(*this, info);
214 }
215
John Recka7c2ea22014-08-08 13:21:00 -0700216 prepareLayer(info, animatorDirtyMask);
John Reckdcba6722014-07-08 13:59:49 -0700217 if (info.mode == TreeInfo::MODE_FULL) {
John Reck2de950d2017-01-25 10:58:30 -0800218 pushStagingDisplayListChanges(observer, info);
John Reck25fbb3f2014-06-12 13:46:45 -0700219 }
John Reck25fbb3f2014-06-12 13:46:45 -0700220
Doris Liu07c056d2016-06-13 12:52:44 -0700221 if (mDisplayList) {
Derek Sollenberger0df62092016-09-27 16:04:42 -0400222 info.out.hasFunctors |= mDisplayList->hasFunctor();
John Reck1bcacfd2017-11-03 10:12:19 -0700223 bool isDirty = mDisplayList->prepareListAndChildren(
224 observer, info, childFunctorsNeedLayer,
225 [](RenderNode* child, TreeObserver& observer, TreeInfo& info,
226 bool functorsNeedLayer) {
227 child->prepareTreeImpl(observer, info, functorsNeedLayer);
228 });
Derek Sollenberger0df62092016-09-27 16:04:42 -0400229 if (isDirty) {
230 damageSelf(info);
Doris Liu718cd3e2016-05-17 16:50:31 -0700231 }
Doris Liu718cd3e2016-05-17 16:50:31 -0700232 }
Doris Liub51b2862016-08-01 19:56:47 -0700233 pushLayerUpdate(info);
Doris Liu718cd3e2016-05-17 16:50:31 -0700234
John Recka447d292014-06-11 18:39:44 -0700235 info.damageAccumulator->popTransform();
John Reckf4198b72014-04-09 17:00:04 -0700236}
237
Chris Craikb565df12015-10-05 13:00:52 -0700238void RenderNode::syncProperties() {
239 mProperties = mStagingProperties;
240}
241
John Reck25fbb3f2014-06-12 13:46:45 -0700242void RenderNode::pushStagingPropertiesChanges(TreeInfo& info) {
John Reckff941dc2014-05-14 16:34:14 -0700243 // Push the animators first so that setupStartValueIfNecessary() is called
244 // before properties() is trampled by stagingProperties(), as they are
245 // required by some animators.
John Reck9eb9f6f2014-08-21 11:23:05 -0700246 if (CC_LIKELY(info.runAnimations)) {
John Reck119907c2014-08-14 09:02:01 -0700247 mAnimatorManager.pushStaging();
John Reck9eb9f6f2014-08-21 11:23:05 -0700248 }
John Reckff941dc2014-05-14 16:34:14 -0700249 if (mDirtyPropertyFields) {
250 mDirtyPropertyFields = 0;
John Recke4267ea2014-06-03 15:53:15 -0700251 damageSelf(info);
John Recka447d292014-06-11 18:39:44 -0700252 info.damageAccumulator->popTransform();
Chris Craikb565df12015-10-05 13:00:52 -0700253 syncProperties();
John Recke4267ea2014-06-03 15:53:15 -0700254 // We could try to be clever and only re-damage if the matrix changed.
255 // However, we don't need to worry about that. The cost of over-damaging
256 // here is only going to be a single additional map rect of this node
257 // plus a rect join(). The parent's transform (and up) will only be
258 // performed once.
John Recka447d292014-06-11 18:39:44 -0700259 info.damageAccumulator->pushTransform(this);
John Recke4267ea2014-06-03 15:53:15 -0700260 damageSelf(info);
John Reckff941dc2014-05-14 16:34:14 -0700261 }
John Reck25fbb3f2014-06-12 13:46:45 -0700262}
263
John Reck2de950d2017-01-25 10:58:30 -0800264void RenderNode::syncDisplayList(TreeObserver& observer, TreeInfo* info) {
Chris Craikb565df12015-10-05 13:00:52 -0700265 // Make sure we inc first so that we don't fluctuate between 0 and 1,
266 // which would thrash the layer cache
Chris Craik003cc3d2015-10-16 10:24:55 -0700267 if (mStagingDisplayList) {
John Reck1bcacfd2017-11-03 10:12:19 -0700268 mStagingDisplayList->updateChildren([](RenderNode* child) { child->incParentRefCount(); });
Chris Craikb565df12015-10-05 13:00:52 -0700269 }
John Reck2de950d2017-01-25 10:58:30 -0800270 deleteDisplayList(observer, info);
Chris Craik003cc3d2015-10-16 10:24:55 -0700271 mDisplayList = mStagingDisplayList;
272 mStagingDisplayList = nullptr;
273 if (mDisplayList) {
Derek Sollenberger0df62092016-09-27 16:04:42 -0400274 mDisplayList->syncContents();
John Reck8f45d4a2018-08-15 10:17:12 -0700275 if (CC_UNLIKELY(Properties::forceDarkMode)) {
276 auto usage = usageHint();
277 if (usage == UsageHint::Unknown) {
278 if (mDisplayList->mChildNodes.size() > 1) {
279 usage = UsageHint::Background;
280 } else if (mDisplayList->mChildNodes.size() == 1 &&
281 mDisplayList->mChildNodes.front().getRenderNode()->usageHint() !=
282 UsageHint::Background) {
283 usage = UsageHint::Background;
284 }
285 }
286 mDisplayList->mDisplayList.applyColorTransform(
287 usage == UsageHint::Background ? ColorTransform::Dark : ColorTransform::Light);
288 }
Chris Craikb565df12015-10-05 13:00:52 -0700289 }
290}
291
John Reck2de950d2017-01-25 10:58:30 -0800292void RenderNode::pushStagingDisplayListChanges(TreeObserver& observer, TreeInfo& info) {
Chris Craik003cc3d2015-10-16 10:24:55 -0700293 if (mNeedsDisplayListSync) {
294 mNeedsDisplayListSync = false;
John Reck5c9d7172014-10-22 11:32:27 -0700295 // Damage with the old display list first then the new one to catch any
296 // changes in isRenderable or, in the future, bounds
297 damageSelf(info);
John Reck2de950d2017-01-25 10:58:30 -0800298 syncDisplayList(observer, &info);
John Recke4267ea2014-06-03 15:53:15 -0700299 damageSelf(info);
John Reck8de65a82014-04-09 15:23:38 -0700300 }
John Reck8de65a82014-04-09 15:23:38 -0700301}
302
John Reck2de950d2017-01-25 10:58:30 -0800303void RenderNode::deleteDisplayList(TreeObserver& observer, TreeInfo* info) {
Chris Craik003cc3d2015-10-16 10:24:55 -0700304 if (mDisplayList) {
John Reck1bcacfd2017-11-03 10:12:19 -0700305 mDisplayList->updateChildren(
306 [&observer, info](RenderNode* child) { child->decParentRefCount(observer, info); });
Derek Sollenberger0df62092016-09-27 16:04:42 -0400307 if (!mDisplayList->reuseDisplayList(this, info ? &info->canvasContext : nullptr)) {
308 delete mDisplayList;
John Reckdcba6722014-07-08 13:59:49 -0700309 }
310 }
Chris Craik003cc3d2015-10-16 10:24:55 -0700311 mDisplayList = nullptr;
John Reckdcba6722014-07-08 13:59:49 -0700312}
313
John Reck2de950d2017-01-25 10:58:30 -0800314void RenderNode::destroyHardwareResources(TreeInfo* info) {
Derek Sollenberger0df62092016-09-27 16:04:42 -0400315 if (hasLayer()) {
Derek Sollenberger28a4d992018-09-20 13:37:24 -0400316 this->setLayerSurface(nullptr);
John Reckdcba6722014-07-08 13:59:49 -0700317 }
John Reck3afd6372017-01-30 10:15:48 -0800318 setStagingDisplayList(nullptr);
319
320 ImmediateRemoved observer(info);
321 deleteDisplayList(observer, info);
John Reck2de950d2017-01-25 10:58:30 -0800322}
323
324void RenderNode::destroyLayers() {
325 if (hasLayer()) {
Derek Sollenberger28a4d992018-09-20 13:37:24 -0400326 this->setLayerSurface(nullptr);
John Reck2de950d2017-01-25 10:58:30 -0800327 }
328 if (mDisplayList) {
John Reck1bcacfd2017-11-03 10:12:19 -0700329 mDisplayList->updateChildren([](RenderNode* child) { child->destroyLayers(); });
John Reck2de950d2017-01-25 10:58:30 -0800330 }
331}
332
333void RenderNode::decParentRefCount(TreeObserver& observer, TreeInfo* info) {
334 LOG_ALWAYS_FATAL_IF(!mParentCount, "already 0!");
335 mParentCount--;
336 if (!mParentCount) {
337 observer.onMaybeRemovedFromTree(this);
338 if (CC_UNLIKELY(mPositionListener.get())) {
339 mPositionListener->onPositionLost(*this, info);
John Reckdcba6722014-07-08 13:59:49 -0700340 }
341 }
342}
343
John Reck2de950d2017-01-25 10:58:30 -0800344void RenderNode::onRemovedFromTree(TreeInfo* info) {
345 destroyHardwareResources(info);
346}
347
348void RenderNode::clearRoot() {
349 ImmediateRemoved observer(nullptr);
350 decParentRefCount(observer);
John Reckdcba6722014-07-08 13:59:49 -0700351}
352
John Reck113e0822014-03-18 09:22:59 -0700353/**
354 * Apply property-based transformations to input matrix
355 *
356 * If true3dTransform is set to true, the transform applied to the input matrix will use true 4x4
357 * matrix computation instead of the Skia 3x3 matrix + camera hackery.
358 */
Chris Craik69e5adf2014-08-14 13:34:01 -0700359void RenderNode::applyViewPropertyTransforms(mat4& matrix, bool true3dTransform) const {
John Reckd0a0b2a2014-03-20 16:28:56 -0700360 if (properties().getLeft() != 0 || properties().getTop() != 0) {
361 matrix.translate(properties().getLeft(), properties().getTop());
John Reck113e0822014-03-18 09:22:59 -0700362 }
John Reckd0a0b2a2014-03-20 16:28:56 -0700363 if (properties().getStaticMatrix()) {
364 mat4 stat(*properties().getStaticMatrix());
John Reck113e0822014-03-18 09:22:59 -0700365 matrix.multiply(stat);
John Reckd0a0b2a2014-03-20 16:28:56 -0700366 } else if (properties().getAnimationMatrix()) {
367 mat4 anim(*properties().getAnimationMatrix());
John Reck113e0822014-03-18 09:22:59 -0700368 matrix.multiply(anim);
369 }
Chris Craike0bb87d2014-04-22 17:55:41 -0700370
Chris Craikcc39e162014-04-25 18:34:11 -0700371 bool applyTranslationZ = true3dTransform && !MathUtils::isZero(properties().getZ());
Chris Craike0bb87d2014-04-22 17:55:41 -0700372 if (properties().hasTransformMatrix() || applyTranslationZ) {
John Reckf7483e32014-04-11 08:54:47 -0700373 if (properties().isTransformTranslateOnly()) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700374 matrix.translate(properties().getTranslationX(), properties().getTranslationY(),
John Reck1bcacfd2017-11-03 10:12:19 -0700375 true3dTransform ? properties().getZ() : 0.0f);
John Reck113e0822014-03-18 09:22:59 -0700376 } else {
377 if (!true3dTransform) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700378 matrix.multiply(*properties().getTransformMatrix());
John Reck113e0822014-03-18 09:22:59 -0700379 } else {
380 mat4 true3dMat;
John Reck1bcacfd2017-11-03 10:12:19 -0700381 true3dMat.loadTranslate(properties().getPivotX() + properties().getTranslationX(),
382 properties().getPivotY() + properties().getTranslationY(),
383 properties().getZ());
John Reckd0a0b2a2014-03-20 16:28:56 -0700384 true3dMat.rotate(properties().getRotationX(), 1, 0, 0);
385 true3dMat.rotate(properties().getRotationY(), 0, 1, 0);
386 true3dMat.rotate(properties().getRotation(), 0, 0, 1);
387 true3dMat.scale(properties().getScaleX(), properties().getScaleY(), 1);
388 true3dMat.translate(-properties().getPivotX(), -properties().getPivotY());
John Reck113e0822014-03-18 09:22:59 -0700389
390 matrix.multiply(true3dMat);
391 }
392 }
393 }
394}
395
Derek Sollenberger579317d2017-08-29 16:33:49 -0400396const SkPath* RenderNode::getClippedOutline(const SkRect& clipRect) const {
397 const SkPath* outlinePath = properties().getOutline().getPath();
398 const uint32_t outlineID = outlinePath->getGenerationID();
399
400 if (outlineID != mClippedOutlineCache.outlineID || clipRect != mClippedOutlineCache.clipRect) {
401 // update the cache keys
402 mClippedOutlineCache.outlineID = outlineID;
403 mClippedOutlineCache.clipRect = clipRect;
404
405 // update the cache value by recomputing a new path
406 SkPath clipPath;
407 clipPath.addRect(clipRect);
408 Op(*outlinePath, clipPath, kIntersect_SkPathOp, &mClippedOutlineCache.clippedOutline);
Derek Sollenberger579317d2017-08-29 16:33:49 -0400409 }
410 return &mClippedOutlineCache.clippedOutline;
411}
412
John Reck113e0822014-03-18 09:22:59 -0700413} /* namespace uirenderer */
414} /* namespace android */