blob: 15ca718481fe965aec92e839aa8315bf26cea324 [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"
Chris Craikb565df12015-10-05 13:00:52 -070021#if HWUI_NEW_OPS
22#include "RecordedOp.h"
Chris Craik0b7e8242015-10-28 16:50:44 -070023#include "BakedOpRenderer.h"
Chris Craikb565df12015-10-05 13:00:52 -070024#endif
John Reck113e0822014-03-18 09:22:59 -070025#include "DisplayListOp.h"
John Reck25fbb3f2014-06-12 13:46:45 -070026#include "LayerRenderer.h"
27#include "OpenGLRenderer.h"
Tom Hudson2dc236b2014-10-15 15:46:42 -040028#include "TreeInfo.h"
Chris Craike0bb87d2014-04-22 17:55:41 -070029#include "utils/MathUtils.h"
Chris Craik70850ea2014-11-18 10:49:23 -080030#include "utils/TraceUtils.h"
John Reck998a6d82014-08-28 15:35:53 -070031#include "renderthread/CanvasContext.h"
John Reck113e0822014-03-18 09:22:59 -070032
John Recke248bd12015-08-05 13:53:53 -070033#include "protos/hwui.pb.h"
34#include "protos/ProtoHelpers.h"
35
John Reck77c40102015-10-26 15:49:47 -070036#include <SkCanvas.h>
37
38#include <algorithm>
39#include <sstream>
40#include <string>
41
John Reck113e0822014-03-18 09:22:59 -070042namespace android {
43namespace uirenderer {
44
John Reck443a7142014-09-04 17:40:05 -070045void RenderNode::debugDumpLayers(const char* prefix) {
Chris Craik0b7e8242015-10-28 16:50:44 -070046#if HWUI_NEW_OPS
47 LOG_ALWAYS_FATAL("TODO: dump layer");
48#else
John Reck443a7142014-09-04 17:40:05 -070049 if (mLayer) {
50 ALOGD("%sNode %p (%s) has layer %p (fbo = %u, wasBuildLayered = %s)",
51 prefix, this, getName(), mLayer, mLayer->getFbo(),
52 mLayer->wasBuildLayered ? "true" : "false");
53 }
Chris Craik0b7e8242015-10-28 16:50:44 -070054#endif
Chris Craik003cc3d2015-10-16 10:24:55 -070055 if (mDisplayList) {
Chris Craikb36af872015-10-16 14:23:12 -070056 for (auto&& child : mDisplayList->getChildren()) {
Chris Craik10ed6922015-10-15 10:55:15 -070057 child->renderNode->debugDumpLayers(prefix);
John Reck443a7142014-09-04 17:40:05 -070058 }
59 }
60}
61
John Reck8de65a82014-04-09 15:23:38 -070062RenderNode::RenderNode()
John Reckff941dc2014-05-14 16:34:14 -070063 : mDirtyPropertyFields(0)
Chris Craik003cc3d2015-10-16 10:24:55 -070064 , mNeedsDisplayListSync(false)
65 , mDisplayList(nullptr)
66 , mStagingDisplayList(nullptr)
John Reck68bfe0a2014-06-24 15:34:58 -070067 , mAnimatorManager(*this)
John Reckdcba6722014-07-08 13:59:49 -070068 , mParentCount(0) {
John Reck113e0822014-03-18 09:22:59 -070069}
70
71RenderNode::~RenderNode() {
Chris Craik003cc3d2015-10-16 10:24:55 -070072 deleteDisplayList();
73 delete mStagingDisplayList;
Chris Craik0b7e8242015-10-28 16:50:44 -070074#if HWUI_NEW_OPS
75 LOG_ALWAYS_FATAL_IF(mLayer, "layer missed detachment!");
76#else
John Reck0e89e2b2014-10-31 14:49:06 -070077 if (mLayer) {
78 ALOGW("Memory Warning: Layer %p missed its detachment, held on to for far too long!", mLayer);
79 mLayer->postDecStrong();
Chris Craikd41c4d82015-01-05 15:51:13 -080080 mLayer = nullptr;
John Reck0e89e2b2014-10-31 14:49:06 -070081 }
Chris Craik0b7e8242015-10-28 16:50:44 -070082#endif
John Reck113e0822014-03-18 09:22:59 -070083}
84
Chris Craik003cc3d2015-10-16 10:24:55 -070085void RenderNode::setStagingDisplayList(DisplayList* displayList) {
86 mNeedsDisplayListSync = true;
87 delete mStagingDisplayList;
88 mStagingDisplayList = displayList;
John Reck9dea0d52015-10-27 10:04:38 -070089 // If mParentCount == 0 we are the sole reference to this RenderNode,
90 // so immediately free the old display list
91 if (!mParentCount && !mStagingDisplayList) {
92 deleteDisplayList();
93 }
John Reck113e0822014-03-18 09:22:59 -070094}
95
96/**
97 * This function is a simplified version of replay(), where we simply retrieve and log the
98 * display list. This function should remain in sync with the replay() function.
99 */
100void RenderNode::output(uint32_t level) {
Chris Craikbf72eb82015-06-08 11:30:44 -0700101 ALOGD("%*sStart display list (%p, %s%s%s%s%s%s)", (level - 1) * 2, "", this,
Chris Craikb5a54352014-11-21 14:54:35 -0800102 getName(),
Chris Craik43a1d312015-05-27 11:28:14 -0700103 (MathUtils::isZero(properties().getAlpha()) ? ", zero alpha" : ""),
Chris Craikb5a54352014-11-21 14:54:35 -0800104 (properties().hasShadow() ? ", casting shadow" : ""),
105 (isRenderable() ? "" : ", empty"),
Chris Craikbf72eb82015-06-08 11:30:44 -0700106 (properties().getProjectBackwards() ? ", projected" : ""),
Chris Craikd41c4d82015-01-05 15:51:13 -0800107 (mLayer != nullptr ? ", on HW Layer" : ""));
John Reck113e0822014-03-18 09:22:59 -0700108 ALOGD("%*s%s %d", level * 2, "", "Save",
109 SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag);
110
John Reckd0a0b2a2014-03-20 16:28:56 -0700111 properties().debugOutputProperties(level);
Chris Craik10ed6922015-10-15 10:55:15 -0700112
Chris Craik003cc3d2015-10-16 10:24:55 -0700113 if (mDisplayList) {
Chris Craik10ed6922015-10-15 10:55:15 -0700114#if HWUI_NEW_OPS
115 LOG_ALWAYS_FATAL("op dumping unsupported");
116#else
Chris Craik8afd0f22014-08-21 17:41:57 -0700117 // TODO: consider printing the chunk boundaries here
Chris Craik003cc3d2015-10-16 10:24:55 -0700118 for (auto&& op : mDisplayList->getOps()) {
Chris Craik10ed6922015-10-15 10:55:15 -0700119 op->output(level, DisplayListOp::kOpLogFlag_Recurse);
John Reckdc0349b2014-08-06 15:28:07 -0700120 }
Chris Craik10ed6922015-10-15 10:55:15 -0700121#endif
John Reck113e0822014-03-18 09:22:59 -0700122 }
123
Chris Craik3f0854292014-04-15 16:18:08 -0700124 ALOGD("%*sDone (%p, %s)", (level - 1) * 2, "", this, getName());
John Reck113e0822014-03-18 09:22:59 -0700125}
126
John Recke248bd12015-08-05 13:53:53 -0700127void RenderNode::copyTo(proto::RenderNode *pnode) {
128 pnode->set_id(static_cast<uint64_t>(
129 reinterpret_cast<uintptr_t>(this)));
130 pnode->set_name(mName.string(), mName.length());
131
132 proto::RenderProperties* pprops = pnode->mutable_properties();
133 pprops->set_left(properties().getLeft());
134 pprops->set_top(properties().getTop());
135 pprops->set_right(properties().getRight());
136 pprops->set_bottom(properties().getBottom());
137 pprops->set_clip_flags(properties().getClippingFlags());
138 pprops->set_alpha(properties().getAlpha());
139 pprops->set_translation_x(properties().getTranslationX());
140 pprops->set_translation_y(properties().getTranslationY());
141 pprops->set_translation_z(properties().getTranslationZ());
142 pprops->set_elevation(properties().getElevation());
143 pprops->set_rotation(properties().getRotation());
144 pprops->set_rotation_x(properties().getRotationX());
145 pprops->set_rotation_y(properties().getRotationY());
146 pprops->set_scale_x(properties().getScaleX());
147 pprops->set_scale_y(properties().getScaleY());
148 pprops->set_pivot_x(properties().getPivotX());
149 pprops->set_pivot_y(properties().getPivotY());
150 pprops->set_has_overlapping_rendering(properties().getHasOverlappingRendering());
151 pprops->set_pivot_explicitly_set(properties().isPivotExplicitlySet());
152 pprops->set_project_backwards(properties().getProjectBackwards());
153 pprops->set_projection_receiver(properties().isProjectionReceiver());
154 set(pprops->mutable_clip_bounds(), properties().getClipBounds());
155
156 const Outline& outline = properties().getOutline();
157 if (outline.getType() != Outline::Type::None) {
158 proto::Outline* poutline = pprops->mutable_outline();
159 poutline->clear_path();
160 if (outline.getType() == Outline::Type::Empty) {
161 poutline->set_type(proto::Outline_Type_Empty);
162 } else if (outline.getType() == Outline::Type::ConvexPath) {
163 poutline->set_type(proto::Outline_Type_ConvexPath);
164 if (const SkPath* path = outline.getPath()) {
165 set(poutline->mutable_path(), *path);
166 }
167 } else if (outline.getType() == Outline::Type::RoundRect) {
168 poutline->set_type(proto::Outline_Type_RoundRect);
169 } else {
170 ALOGW("Uknown outline type! %d", static_cast<int>(outline.getType()));
171 poutline->set_type(proto::Outline_Type_None);
172 }
173 poutline->set_should_clip(outline.getShouldClip());
174 poutline->set_alpha(outline.getAlpha());
175 poutline->set_radius(outline.getRadius());
176 set(poutline->mutable_bounds(), outline.getBounds());
177 } else {
178 pprops->clear_outline();
179 }
180
181 const RevealClip& revealClip = properties().getRevealClip();
182 if (revealClip.willClip()) {
183 proto::RevealClip* prevealClip = pprops->mutable_reveal_clip();
184 prevealClip->set_x(revealClip.getX());
185 prevealClip->set_y(revealClip.getY());
186 prevealClip->set_radius(revealClip.getRadius());
187 } else {
188 pprops->clear_reveal_clip();
189 }
190
191 pnode->clear_children();
Chris Craik003cc3d2015-10-16 10:24:55 -0700192 if (mDisplayList) {
Chris Craikb36af872015-10-16 14:23:12 -0700193 for (auto&& child : mDisplayList->getChildren()) {
Chris Craikb565df12015-10-05 13:00:52 -0700194 child->renderNode->copyTo(pnode->add_children());
John Recke248bd12015-08-05 13:53:53 -0700195 }
196 }
197}
198
John Reckfe5e7b72014-05-23 17:42:28 -0700199int RenderNode::getDebugSize() {
200 int size = sizeof(RenderNode);
Chris Craik003cc3d2015-10-16 10:24:55 -0700201 if (mStagingDisplayList) {
202 size += mStagingDisplayList->getUsedSize();
John Reckfe5e7b72014-05-23 17:42:28 -0700203 }
Chris Craik003cc3d2015-10-16 10:24:55 -0700204 if (mDisplayList && mDisplayList != mStagingDisplayList) {
205 size += mDisplayList->getUsedSize();
John Reckfe5e7b72014-05-23 17:42:28 -0700206 }
207 return size;
208}
209
John Reckf4198b72014-04-09 17:00:04 -0700210void RenderNode::prepareTree(TreeInfo& info) {
211 ATRACE_CALL();
Chris Craik69e5adf2014-08-14 13:34:01 -0700212 LOG_ALWAYS_FATAL_IF(!info.damageAccumulator, "DamageAccumulator missing");
John Reckf4198b72014-04-09 17:00:04 -0700213
Chris Craika766cb22015-06-08 16:49:43 -0700214 // Functors don't correctly handle stencil usage of overdraw debugging - shove 'em in a layer.
215 bool functorsNeedLayer = Properties::debugOverdraw;
216
217 prepareTreeImpl(info, functorsNeedLayer);
John Reckf4198b72014-04-09 17:00:04 -0700218}
219
John Reck68bfe0a2014-06-24 15:34:58 -0700220void RenderNode::addAnimator(const sp<BaseRenderNodeAnimator>& animator) {
221 mAnimatorManager.addAnimator(animator);
222}
223
John Recke4267ea2014-06-03 15:53:15 -0700224void RenderNode::damageSelf(TreeInfo& info) {
John Reckce9f3082014-06-17 16:18:09 -0700225 if (isRenderable()) {
John Reck293e8682014-06-17 10:34:02 -0700226 if (properties().getClipDamageToBounds()) {
John Recka447d292014-06-11 18:39:44 -0700227 info.damageAccumulator->dirty(0, 0, properties().getWidth(), properties().getHeight());
228 } else {
229 // Hope this is big enough?
230 // TODO: Get this from the display list ops or something
John Reckc1288232015-08-12 13:39:11 -0700231 info.damageAccumulator->dirty(DIRTY_MIN, DIRTY_MIN, DIRTY_MAX, DIRTY_MAX);
John Recka447d292014-06-11 18:39:44 -0700232 }
John Recke4267ea2014-06-03 15:53:15 -0700233 }
234}
235
John Recka7c2ea22014-08-08 13:21:00 -0700236void RenderNode::prepareLayer(TreeInfo& info, uint32_t dirtyMask) {
Chris Craik856f0cc2015-04-21 15:13:29 -0700237 LayerType layerType = properties().effectiveLayerType();
Chris Craik182952f2015-03-09 14:17:29 -0700238 if (CC_UNLIKELY(layerType == LayerType::RenderLayer)) {
John Recka7c2ea22014-08-08 13:21:00 -0700239 // Damage applied so far needs to affect our parent, but does not require
240 // the layer to be updated. So we pop/push here to clear out the current
241 // damage and get a clean state for display list or children updates to
242 // affect, which will require the layer to be updated
243 info.damageAccumulator->popTransform();
244 info.damageAccumulator->pushTransform(this);
245 if (dirtyMask & DISPLAY_LIST) {
246 damageSelf(info);
247 }
John Reck25fbb3f2014-06-12 13:46:45 -0700248 }
249}
250
Chris Craik0b7e8242015-10-28 16:50:44 -0700251layer_t* createLayer(RenderState& renderState, uint32_t width, uint32_t height) {
252#if HWUI_NEW_OPS
Chris Craik8d2cf942015-11-02 14:52:21 -0800253 return BakedOpRenderer::createOffscreenBuffer(renderState, width, height);
Chris Craik0b7e8242015-10-28 16:50:44 -0700254#else
255 return LayerRenderer::createRenderLayer(renderState, width, height);
256#endif
257}
258
259void destroyLayer(layer_t* layer) {
260#if HWUI_NEW_OPS
261 BakedOpRenderer::destroyOffscreenBuffer(layer);
262#else
263 LayerRenderer::destroyLayer(layer);
264#endif
265}
266
John Reck25fbb3f2014-06-12 13:46:45 -0700267void RenderNode::pushLayerUpdate(TreeInfo& info) {
Chris Craik856f0cc2015-04-21 15:13:29 -0700268 LayerType layerType = properties().effectiveLayerType();
John Reck25fbb3f2014-06-12 13:46:45 -0700269 // If we are not a layer OR we cannot be rendered (eg, view was detached)
270 // we need to destroy any Layers we may have had previously
Chris Craik182952f2015-03-09 14:17:29 -0700271 if (CC_LIKELY(layerType != LayerType::RenderLayer) || CC_UNLIKELY(!isRenderable())) {
John Reck25fbb3f2014-06-12 13:46:45 -0700272 if (CC_UNLIKELY(mLayer)) {
Chris Craik0b7e8242015-10-28 16:50:44 -0700273 destroyLayer(mLayer);
Chris Craikd41c4d82015-01-05 15:51:13 -0800274 mLayer = nullptr;
John Reck25fbb3f2014-06-12 13:46:45 -0700275 }
276 return;
277 }
278
Chris Craik69e5adf2014-08-14 13:34:01 -0700279 bool transformUpdateNeeded = false;
John Reck25fbb3f2014-06-12 13:46:45 -0700280 if (!mLayer) {
Chris Craik0b7e8242015-10-28 16:50:44 -0700281 mLayer = createLayer(info.canvasContext.getRenderState(), getWidth(), getHeight());
282 damageSelf(info);
283 transformUpdateNeeded = true;
284#if HWUI_NEW_OPS
Chris Craik76caecf2015-11-02 19:17:45 -0800285 } else if (mLayer->viewportWidth != (uint32_t) getWidth()
286 || mLayer->viewportHeight != (uint32_t)getHeight()) {
287 // TODO: allow node's layer to grow larger
288 if ((uint32_t)getWidth() > mLayer->texture.width
289 || (uint32_t)getHeight() > mLayer->texture.height) {
Chris Craik0b7e8242015-10-28 16:50:44 -0700290#else
John Reck25fbb3f2014-06-12 13:46:45 -0700291 } else if (mLayer->layer.getWidth() != getWidth() || mLayer->layer.getHeight() != getHeight()) {
John Reckc25e5062014-06-18 14:21:29 -0700292 if (!LayerRenderer::resizeLayer(mLayer, getWidth(), getHeight())) {
Chris Craik0b7e8242015-10-28 16:50:44 -0700293#endif
294 destroyLayer(mLayer);
Chris Craikd41c4d82015-01-05 15:51:13 -0800295 mLayer = nullptr;
John Reckc25e5062014-06-18 14:21:29 -0700296 }
John Reck25fbb3f2014-06-12 13:46:45 -0700297 damageSelf(info);
Chris Craik69e5adf2014-08-14 13:34:01 -0700298 transformUpdateNeeded = true;
299 }
300
John Reck25fbb3f2014-06-12 13:46:45 -0700301 SkRect dirty;
302 info.damageAccumulator->peekAtDirty(&dirty);
John Reck25fbb3f2014-06-12 13:46:45 -0700303
John Reckc25e5062014-06-18 14:21:29 -0700304 if (!mLayer) {
John Reck0e89e2b2014-10-31 14:49:06 -0700305 Caches::getInstance().dumpMemoryUsage();
John Reckc25e5062014-06-18 14:21:29 -0700306 if (info.errorHandler) {
John Reck77c40102015-10-26 15:49:47 -0700307 std::ostringstream err;
308 err << "Unable to create layer for " << getName();
Chris Craik76caecf2015-11-02 19:17:45 -0800309 const int maxTextureSize = Caches::getInstance().maxTextureSize;
John Reck77c40102015-10-26 15:49:47 -0700310 if (getWidth() > maxTextureSize || getHeight() > maxTextureSize) {
311 err << ", size " << getWidth() << "x" << getHeight()
312 << " exceeds max size " << maxTextureSize;
313 } else {
314 err << ", see logcat for more info";
315 }
316 info.errorHandler->onError(err.str());
John Reckc25e5062014-06-18 14:21:29 -0700317 }
318 return;
319 }
320
Chris Craikc71bfca2014-08-21 10:18:58 -0700321 if (transformUpdateNeeded) {
322 // update the transform in window of the layer to reset its origin wrt light source position
323 Matrix4 windowTransform;
324 info.damageAccumulator->computeCurrentTransform(&windowTransform);
Chris Craik0b7e8242015-10-28 16:50:44 -0700325#if HWUI_NEW_OPS
326 // TODO: update layer transform (perhaps as part of enqueueLayerWithDamage)
327#else
Chris Craikc71bfca2014-08-21 10:18:58 -0700328 mLayer->setWindowTransform(windowTransform);
Chris Craik0b7e8242015-10-28 16:50:44 -0700329#endif
Chris Craikc71bfca2014-08-21 10:18:58 -0700330 }
John Reckc79eabc2014-08-05 11:03:42 -0700331
Chris Craik0b7e8242015-10-28 16:50:44 -0700332#if HWUI_NEW_OPS
333 info.layerUpdateQueue->enqueueLayerWithDamage(this, dirty);
334#else
John Reckc79eabc2014-08-05 11:03:42 -0700335 if (dirty.intersect(0, 0, getWidth(), getHeight())) {
Mike Reed71487eb2014-11-19 16:13:20 -0500336 dirty.roundOut(&dirty);
John Reck25fbb3f2014-06-12 13:46:45 -0700337 mLayer->updateDeferred(this, dirty.fLeft, dirty.fTop, dirty.fRight, dirty.fBottom);
338 }
339 // This is not inside the above if because we may have called
340 // updateDeferred on a previous prepare pass that didn't have a renderer
341 if (info.renderer && mLayer->deferredUpdateScheduled) {
342 info.renderer->pushLayerUpdate(mLayer);
343 }
Chris Craik0b7e8242015-10-28 16:50:44 -0700344#endif
John Reck998a6d82014-08-28 15:35:53 -0700345
Chris Craike2e53a72015-10-28 15:55:40 -0700346 // There might be prefetched layers that need to be accounted for.
347 // That might be us, so tell CanvasContext that this layer is in the
348 // tree and should not be destroyed.
349 info.canvasContext.markLayerInUse(this);
John Reck25fbb3f2014-06-12 13:46:45 -0700350}
351
Chris Craika766cb22015-06-08 16:49:43 -0700352/**
353 * Traverse down the the draw tree to prepare for a frame.
354 *
355 * MODE_FULL = UI Thread-driven (thus properties must be synced), otherwise RT driven
356 *
357 * While traversing down the tree, functorsNeedLayer flag is set to true if anything that uses the
358 * stencil buffer may be needed. Views that use a functor to draw will be forced onto a layer.
359 */
360void RenderNode::prepareTreeImpl(TreeInfo& info, bool functorsNeedLayer) {
John Recka447d292014-06-11 18:39:44 -0700361 info.damageAccumulator->pushTransform(this);
John Reckf47a5942014-06-30 16:20:04 -0700362
John Reckdcba6722014-07-08 13:59:49 -0700363 if (info.mode == TreeInfo::MODE_FULL) {
John Reck25fbb3f2014-06-12 13:46:45 -0700364 pushStagingPropertiesChanges(info);
John Recke45b1fd2014-04-15 09:50:16 -0700365 }
John Reck9eb9f6f2014-08-21 11:23:05 -0700366 uint32_t animatorDirtyMask = 0;
367 if (CC_LIKELY(info.runAnimations)) {
368 animatorDirtyMask = mAnimatorManager.animate(info);
369 }
Chris Craika766cb22015-06-08 16:49:43 -0700370
John Reck3f725f02015-06-16 10:29:31 -0700371 bool willHaveFunctor = false;
Chris Craik003cc3d2015-10-16 10:24:55 -0700372 if (info.mode == TreeInfo::MODE_FULL && mStagingDisplayList) {
Chris Craikb36af872015-10-16 14:23:12 -0700373 willHaveFunctor = !mStagingDisplayList->getFunctors().empty();
Chris Craik003cc3d2015-10-16 10:24:55 -0700374 } else if (mDisplayList) {
Chris Craikb36af872015-10-16 14:23:12 -0700375 willHaveFunctor = !mDisplayList->getFunctors().empty();
John Reck3f725f02015-06-16 10:29:31 -0700376 }
Chris Craika766cb22015-06-08 16:49:43 -0700377 bool childFunctorsNeedLayer = mProperties.prepareForFunctorPresence(
378 willHaveFunctor, functorsNeedLayer);
379
John Recka7c2ea22014-08-08 13:21:00 -0700380 prepareLayer(info, animatorDirtyMask);
John Reckdcba6722014-07-08 13:59:49 -0700381 if (info.mode == TreeInfo::MODE_FULL) {
John Reck25fbb3f2014-06-12 13:46:45 -0700382 pushStagingDisplayListChanges(info);
383 }
Chris Craik003cc3d2015-10-16 10:24:55 -0700384 prepareSubTree(info, childFunctorsNeedLayer, mDisplayList);
John Reck25fbb3f2014-06-12 13:46:45 -0700385 pushLayerUpdate(info);
386
John Recka447d292014-06-11 18:39:44 -0700387 info.damageAccumulator->popTransform();
John Reckf4198b72014-04-09 17:00:04 -0700388}
389
Chris Craikb565df12015-10-05 13:00:52 -0700390void RenderNode::syncProperties() {
391 mProperties = mStagingProperties;
392}
393
John Reck25fbb3f2014-06-12 13:46:45 -0700394void RenderNode::pushStagingPropertiesChanges(TreeInfo& info) {
John Reckff941dc2014-05-14 16:34:14 -0700395 // Push the animators first so that setupStartValueIfNecessary() is called
396 // before properties() is trampled by stagingProperties(), as they are
397 // required by some animators.
John Reck9eb9f6f2014-08-21 11:23:05 -0700398 if (CC_LIKELY(info.runAnimations)) {
John Reck119907c2014-08-14 09:02:01 -0700399 mAnimatorManager.pushStaging();
John Reck9eb9f6f2014-08-21 11:23:05 -0700400 }
John Reckff941dc2014-05-14 16:34:14 -0700401 if (mDirtyPropertyFields) {
402 mDirtyPropertyFields = 0;
John Recke4267ea2014-06-03 15:53:15 -0700403 damageSelf(info);
John Recka447d292014-06-11 18:39:44 -0700404 info.damageAccumulator->popTransform();
Chris Craikb565df12015-10-05 13:00:52 -0700405 syncProperties();
Chris Craik0b7e8242015-10-28 16:50:44 -0700406#if !HWUI_NEW_OPS
John Reck25fbb3f2014-06-12 13:46:45 -0700407 applyLayerPropertiesToLayer(info);
Chris Craik0b7e8242015-10-28 16:50:44 -0700408#endif
John Recke4267ea2014-06-03 15:53:15 -0700409 // We could try to be clever and only re-damage if the matrix changed.
410 // However, we don't need to worry about that. The cost of over-damaging
411 // here is only going to be a single additional map rect of this node
412 // plus a rect join(). The parent's transform (and up) will only be
413 // performed once.
John Recka447d292014-06-11 18:39:44 -0700414 info.damageAccumulator->pushTransform(this);
John Recke4267ea2014-06-03 15:53:15 -0700415 damageSelf(info);
John Reckff941dc2014-05-14 16:34:14 -0700416 }
John Reck25fbb3f2014-06-12 13:46:45 -0700417}
418
Chris Craik0b7e8242015-10-28 16:50:44 -0700419#if !HWUI_NEW_OPS
Andreas Gampe64bb4132014-11-22 00:35:09 +0000420void RenderNode::applyLayerPropertiesToLayer(TreeInfo& info) {
John Reck25fbb3f2014-06-12 13:46:45 -0700421 if (CC_LIKELY(!mLayer)) return;
422
423 const LayerProperties& props = properties().layerProperties();
424 mLayer->setAlpha(props.alpha(), props.xferMode());
425 mLayer->setColorFilter(props.colorFilter());
426 mLayer->setBlend(props.needsBlending());
427}
Chris Craik0b7e8242015-10-28 16:50:44 -0700428#endif
John Reck25fbb3f2014-06-12 13:46:45 -0700429
Chris Craikb565df12015-10-05 13:00:52 -0700430void RenderNode::syncDisplayList() {
431 // Make sure we inc first so that we don't fluctuate between 0 and 1,
432 // which would thrash the layer cache
Chris Craik003cc3d2015-10-16 10:24:55 -0700433 if (mStagingDisplayList) {
Chris Craikb36af872015-10-16 14:23:12 -0700434 for (auto&& child : mStagingDisplayList->getChildren()) {
Chris Craikb565df12015-10-05 13:00:52 -0700435 child->renderNode->incParentRefCount();
436 }
437 }
Chris Craik003cc3d2015-10-16 10:24:55 -0700438 deleteDisplayList();
439 mDisplayList = mStagingDisplayList;
440 mStagingDisplayList = nullptr;
441 if (mDisplayList) {
Chris Craikb36af872015-10-16 14:23:12 -0700442 for (size_t i = 0; i < mDisplayList->getFunctors().size(); i++) {
443 (*mDisplayList->getFunctors()[i])(DrawGlInfo::kModeSync, nullptr);
Chris Craikb565df12015-10-05 13:00:52 -0700444 }
445 }
446}
447
John Reck25fbb3f2014-06-12 13:46:45 -0700448void RenderNode::pushStagingDisplayListChanges(TreeInfo& info) {
Chris Craik003cc3d2015-10-16 10:24:55 -0700449 if (mNeedsDisplayListSync) {
450 mNeedsDisplayListSync = false;
John Reck5c9d7172014-10-22 11:32:27 -0700451 // Damage with the old display list first then the new one to catch any
452 // changes in isRenderable or, in the future, bounds
453 damageSelf(info);
Chris Craikb565df12015-10-05 13:00:52 -0700454 syncDisplayList();
John Recke4267ea2014-06-03 15:53:15 -0700455 damageSelf(info);
John Reck8de65a82014-04-09 15:23:38 -0700456 }
John Reck8de65a82014-04-09 15:23:38 -0700457}
458
Chris Craik003cc3d2015-10-16 10:24:55 -0700459void RenderNode::deleteDisplayList() {
460 if (mDisplayList) {
Chris Craikb36af872015-10-16 14:23:12 -0700461 for (auto&& child : mDisplayList->getChildren()) {
Chris Craikb565df12015-10-05 13:00:52 -0700462 child->renderNode->decParentRefCount();
John Reckdcba6722014-07-08 13:59:49 -0700463 }
464 }
Chris Craik003cc3d2015-10-16 10:24:55 -0700465 delete mDisplayList;
466 mDisplayList = nullptr;
John Reckdcba6722014-07-08 13:59:49 -0700467}
468
Chris Craik003cc3d2015-10-16 10:24:55 -0700469void RenderNode::prepareSubTree(TreeInfo& info, bool functorsNeedLayer, DisplayList* subtree) {
John Reck8de65a82014-04-09 15:23:38 -0700470 if (subtree) {
John Reck860d1552014-04-11 19:15:05 -0700471 TextureCache& cache = Caches::getInstance().textureCache;
Chris Craikb36af872015-10-16 14:23:12 -0700472 info.out.hasFunctors |= subtree->getFunctors().size();
473 for (auto&& bitmapResource : subtree->getBitmapResources()) {
Chris Craike2e53a72015-10-28 15:55:40 -0700474 void* ownerToken = &info.canvasContext;
475 info.prepareTextures = cache.prefetchAndMarkInUse(ownerToken, bitmapResource);
John Reckf4198b72014-04-09 17:00:04 -0700476 }
Chris Craikb36af872015-10-16 14:23:12 -0700477 for (auto&& op : subtree->getChildren()) {
Chris Craikb565df12015-10-05 13:00:52 -0700478 RenderNode* childNode = op->renderNode;
479#if HWUI_NEW_OPS
480 info.damageAccumulator->pushTransform(&op->localMatrix);
481 bool childFunctorsNeedLayer = functorsNeedLayer; // TODO! || op->mRecordedWithPotentialStencilClip;
482#else
John Recka447d292014-06-11 18:39:44 -0700483 info.damageAccumulator->pushTransform(&op->mTransformFromParent);
Chris Craika766cb22015-06-08 16:49:43 -0700484 bool childFunctorsNeedLayer = functorsNeedLayer
485 // Recorded with non-rect clip, or canvas-rotated by parent
486 || op->mRecordedWithPotentialStencilClip;
Chris Craikb565df12015-10-05 13:00:52 -0700487#endif
Chris Craika766cb22015-06-08 16:49:43 -0700488 childNode->prepareTreeImpl(info, childFunctorsNeedLayer);
John Recka447d292014-06-11 18:39:44 -0700489 info.damageAccumulator->popTransform();
John Reck5bf11bb2014-03-25 10:22:09 -0700490 }
John Reck113e0822014-03-18 09:22:59 -0700491 }
492}
493
John Reckdcba6722014-07-08 13:59:49 -0700494void RenderNode::destroyHardwareResources() {
495 if (mLayer) {
Chris Craik0b7e8242015-10-28 16:50:44 -0700496 destroyLayer(mLayer);
Chris Craikd41c4d82015-01-05 15:51:13 -0800497 mLayer = nullptr;
John Reckdcba6722014-07-08 13:59:49 -0700498 }
Chris Craik003cc3d2015-10-16 10:24:55 -0700499 if (mDisplayList) {
Chris Craikb36af872015-10-16 14:23:12 -0700500 for (auto&& child : mDisplayList->getChildren()) {
Chris Craikb565df12015-10-05 13:00:52 -0700501 child->renderNode->destroyHardwareResources();
John Reckdcba6722014-07-08 13:59:49 -0700502 }
Chris Craik003cc3d2015-10-16 10:24:55 -0700503 if (mNeedsDisplayListSync) {
John Reckdcba6722014-07-08 13:59:49 -0700504 // Next prepare tree we are going to push a new display list, so we can
505 // drop our current one now
Chris Craik003cc3d2015-10-16 10:24:55 -0700506 deleteDisplayList();
John Reckdcba6722014-07-08 13:59:49 -0700507 }
508 }
509}
510
511void RenderNode::decParentRefCount() {
512 LOG_ALWAYS_FATAL_IF(!mParentCount, "already 0!");
513 mParentCount--;
514 if (!mParentCount) {
515 // If a child of ours is being attached to our parent then this will incorrectly
516 // destroy its hardware resources. However, this situation is highly unlikely
517 // and the failure is "just" that the layer is re-created, so this should
518 // be safe enough
519 destroyHardwareResources();
520 }
521}
522
Chris Craik76caecf2015-11-02 19:17:45 -0800523bool RenderNode::applyViewProperties(CanvasState& canvasState, LinearAllocator& allocator) const {
Chris Craikb565df12015-10-05 13:00:52 -0700524 const Outline& outline = properties().getOutline();
525 if (properties().getAlpha() <= 0
526 || (outline.getShouldClip() && outline.isEmpty())
527 || properties().getScaleX() == 0
528 || properties().getScaleY() == 0) {
529 return false; // rejected
530 }
531
532 if (properties().getLeft() != 0 || properties().getTop() != 0) {
533 canvasState.translate(properties().getLeft(), properties().getTop());
534 }
535 if (properties().getStaticMatrix()) {
536 canvasState.concatMatrix(*properties().getStaticMatrix());
537 } else if (properties().getAnimationMatrix()) {
538 canvasState.concatMatrix(*properties().getAnimationMatrix());
539 }
540 if (properties().hasTransformMatrix()) {
541 if (properties().isTransformTranslateOnly()) {
542 canvasState.translate(properties().getTranslationX(), properties().getTranslationY());
543 } else {
544 canvasState.concatMatrix(*properties().getTransformMatrix());
545 }
546 }
Chris Craik76caecf2015-11-02 19:17:45 -0800547
548 const bool isLayer = properties().effectiveLayerType() != LayerType::None;
549 int clipFlags = properties().getClippingFlags();
550 if (properties().getAlpha() < 1) {
551 if (isLayer) {
552 clipFlags &= ~CLIP_TO_BOUNDS; // bounds clipping done by layer
553 }
554 if (CC_LIKELY(isLayer || !properties().getHasOverlappingRendering())) {
555 // simply scale rendering content's alpha
556 canvasState.scaleAlpha(properties().getAlpha());
557 } else {
558 // savelayer needed to create an offscreen buffer
559 Rect layerBounds(0, 0, getWidth(), getHeight());
560 if (clipFlags) {
561 properties().getClippingRectForFlags(clipFlags, &layerBounds);
562 clipFlags = 0; // all clipping done by savelayer
563 }
564 LOG_ALWAYS_FATAL("TODO: savelayer");
565 }
566
567 if (CC_UNLIKELY(ATRACE_ENABLED() && properties().promotedToLayer())) {
568 // pretend alpha always causes savelayer to warn about
569 // performance problem affecting old versions
570 ATRACE_FORMAT("%s alpha caused saveLayer %dx%d", getName(), getWidth(), getHeight());
571 }
572 }
573 if (clipFlags) {
574 Rect clipRect;
575 properties().getClippingRectForFlags(clipFlags, &clipRect);
576 canvasState.clipRect(clipRect.left, clipRect.top, clipRect.right, clipRect.bottom,
577 SkRegion::kIntersect_Op);
578 }
579
580 // TODO: support nesting round rect clips
581 if (mProperties.getRevealClip().willClip()) {
582 Rect bounds;
583 mProperties.getRevealClip().getBounds(&bounds);
584 canvasState.setClippingRoundRect(allocator,
585 bounds, mProperties.getRevealClip().getRadius());
586 } else if (mProperties.getOutline().willClip()) {
587 canvasState.setClippingOutline(allocator, &(mProperties.getOutline()));
588 }
Chris Craikb565df12015-10-05 13:00:52 -0700589 return !canvasState.quickRejectConservative(
590 0, 0, properties().getWidth(), properties().getHeight());
591}
592
John Reck113e0822014-03-18 09:22:59 -0700593/*
594 * For property operations, we pass a savecount of 0, since the operations aren't part of the
595 * displaylist, and thus don't have to compensate for the record-time/playback-time discrepancy in
John Reckd0a0b2a2014-03-20 16:28:56 -0700596 * base saveCount (i.e., how RestoreToCount uses saveCount + properties().getCount())
John Reck113e0822014-03-18 09:22:59 -0700597 */
598#define PROPERTY_SAVECOUNT 0
599
600template <class T>
Chris Craikb265e2c2014-03-27 15:50:09 -0700601void RenderNode::setViewProperties(OpenGLRenderer& renderer, T& handler) {
John Reck113e0822014-03-18 09:22:59 -0700602#if DEBUG_DISPLAY_LIST
Chris Craikb265e2c2014-03-27 15:50:09 -0700603 properties().debugOutputProperties(handler.level() + 1);
John Reck113e0822014-03-18 09:22:59 -0700604#endif
John Reckd0a0b2a2014-03-20 16:28:56 -0700605 if (properties().getLeft() != 0 || properties().getTop() != 0) {
606 renderer.translate(properties().getLeft(), properties().getTop());
John Reck113e0822014-03-18 09:22:59 -0700607 }
John Reckd0a0b2a2014-03-20 16:28:56 -0700608 if (properties().getStaticMatrix()) {
Derek Sollenberger13908822013-12-10 12:28:58 -0500609 renderer.concatMatrix(*properties().getStaticMatrix());
John Reckd0a0b2a2014-03-20 16:28:56 -0700610 } else if (properties().getAnimationMatrix()) {
Derek Sollenberger13908822013-12-10 12:28:58 -0500611 renderer.concatMatrix(*properties().getAnimationMatrix());
John Reck113e0822014-03-18 09:22:59 -0700612 }
John Reckf7483e32014-04-11 08:54:47 -0700613 if (properties().hasTransformMatrix()) {
614 if (properties().isTransformTranslateOnly()) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700615 renderer.translate(properties().getTranslationX(), properties().getTranslationY());
John Reck113e0822014-03-18 09:22:59 -0700616 } else {
John Reckd0a0b2a2014-03-20 16:28:56 -0700617 renderer.concatMatrix(*properties().getTransformMatrix());
John Reck113e0822014-03-18 09:22:59 -0700618 }
619 }
Chris Craik856f0cc2015-04-21 15:13:29 -0700620 const bool isLayer = properties().effectiveLayerType() != LayerType::None;
Chris Craika753f4c2014-07-24 12:39:17 -0700621 int clipFlags = properties().getClippingFlags();
John Reckd0a0b2a2014-03-20 16:28:56 -0700622 if (properties().getAlpha() < 1) {
John Reck25fbb3f2014-06-12 13:46:45 -0700623 if (isLayer) {
Chris Craika753f4c2014-07-24 12:39:17 -0700624 clipFlags &= ~CLIP_TO_BOUNDS; // bounds clipping done by layer
John Reck113e0822014-03-18 09:22:59 -0700625 }
Chris Craik4e9d9b22015-06-12 11:07:23 -0700626 if (CC_LIKELY(isLayer || !properties().getHasOverlappingRendering())) {
627 // simply scale rendering content's alpha
628 renderer.scaleAlpha(properties().getAlpha());
629 } else {
630 // savelayer needed to create an offscreen buffer
631 Rect layerBounds(0, 0, getWidth(), getHeight());
632 if (clipFlags) {
633 properties().getClippingRectForFlags(clipFlags, &layerBounds);
634 clipFlags = 0; // all clipping done by savelayer
635 }
636 SaveLayerOp* op = new (handler.allocator()) SaveLayerOp(
637 layerBounds.left, layerBounds.top,
638 layerBounds.right, layerBounds.bottom,
639 (int) (properties().getAlpha() * 255),
640 SkCanvas::kHasAlphaLayer_SaveFlag | SkCanvas::kClipToLayer_SaveFlag);
641 handler(op, PROPERTY_SAVECOUNT, properties().getClipToBounds());
642 }
Chris Craik1a0808e2015-05-13 16:33:04 -0700643
644 if (CC_UNLIKELY(ATRACE_ENABLED() && properties().promotedToLayer())) {
Chris Craik4e9d9b22015-06-12 11:07:23 -0700645 // pretend alpha always causes savelayer to warn about
646 // performance problem affecting old versions
Chris Craik1a0808e2015-05-13 16:33:04 -0700647 ATRACE_FORMAT("%s alpha caused saveLayer %dx%d", getName(),
648 static_cast<int>(getWidth()),
649 static_cast<int>(getHeight()));
650 }
John Reck113e0822014-03-18 09:22:59 -0700651 }
Chris Craika753f4c2014-07-24 12:39:17 -0700652 if (clipFlags) {
653 Rect clipRect;
654 properties().getClippingRectForFlags(clipFlags, &clipRect);
Chris Craik8c271ca2014-03-25 10:33:01 -0700655 ClipRectOp* op = new (handler.allocator()) ClipRectOp(
Chris Craika753f4c2014-07-24 12:39:17 -0700656 clipRect.left, clipRect.top, clipRect.right, clipRect.bottom,
657 SkRegion::kIntersect_Op);
John Reckd0a0b2a2014-03-20 16:28:56 -0700658 handler(op, PROPERTY_SAVECOUNT, properties().getClipToBounds());
John Reck113e0822014-03-18 09:22:59 -0700659 }
Chris Craik8c271ca2014-03-25 10:33:01 -0700660
Chris Craike83cbd42014-09-03 17:52:24 -0700661 // TODO: support nesting round rect clips
Chris Craikaf4d04c2014-07-29 12:50:14 -0700662 if (mProperties.getRevealClip().willClip()) {
663 Rect bounds;
664 mProperties.getRevealClip().getBounds(&bounds);
665 renderer.setClippingRoundRect(handler.allocator(), bounds, mProperties.getRevealClip().getRadius());
666 } else if (mProperties.getOutline().willClip()) {
667 renderer.setClippingOutline(handler.allocator(), &(mProperties.getOutline()));
John Reck113e0822014-03-18 09:22:59 -0700668 }
669}
670
671/**
672 * Apply property-based transformations to input matrix
673 *
674 * If true3dTransform is set to true, the transform applied to the input matrix will use true 4x4
675 * matrix computation instead of the Skia 3x3 matrix + camera hackery.
676 */
Chris Craik69e5adf2014-08-14 13:34:01 -0700677void RenderNode::applyViewPropertyTransforms(mat4& matrix, bool true3dTransform) const {
John Reckd0a0b2a2014-03-20 16:28:56 -0700678 if (properties().getLeft() != 0 || properties().getTop() != 0) {
679 matrix.translate(properties().getLeft(), properties().getTop());
John Reck113e0822014-03-18 09:22:59 -0700680 }
John Reckd0a0b2a2014-03-20 16:28:56 -0700681 if (properties().getStaticMatrix()) {
682 mat4 stat(*properties().getStaticMatrix());
John Reck113e0822014-03-18 09:22:59 -0700683 matrix.multiply(stat);
John Reckd0a0b2a2014-03-20 16:28:56 -0700684 } else if (properties().getAnimationMatrix()) {
685 mat4 anim(*properties().getAnimationMatrix());
John Reck113e0822014-03-18 09:22:59 -0700686 matrix.multiply(anim);
687 }
Chris Craike0bb87d2014-04-22 17:55:41 -0700688
Chris Craikcc39e162014-04-25 18:34:11 -0700689 bool applyTranslationZ = true3dTransform && !MathUtils::isZero(properties().getZ());
Chris Craike0bb87d2014-04-22 17:55:41 -0700690 if (properties().hasTransformMatrix() || applyTranslationZ) {
John Reckf7483e32014-04-11 08:54:47 -0700691 if (properties().isTransformTranslateOnly()) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700692 matrix.translate(properties().getTranslationX(), properties().getTranslationY(),
Chris Craikcc39e162014-04-25 18:34:11 -0700693 true3dTransform ? properties().getZ() : 0.0f);
John Reck113e0822014-03-18 09:22:59 -0700694 } else {
695 if (!true3dTransform) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700696 matrix.multiply(*properties().getTransformMatrix());
John Reck113e0822014-03-18 09:22:59 -0700697 } else {
698 mat4 true3dMat;
699 true3dMat.loadTranslate(
John Reckd0a0b2a2014-03-20 16:28:56 -0700700 properties().getPivotX() + properties().getTranslationX(),
701 properties().getPivotY() + properties().getTranslationY(),
Chris Craikcc39e162014-04-25 18:34:11 -0700702 properties().getZ());
John Reckd0a0b2a2014-03-20 16:28:56 -0700703 true3dMat.rotate(properties().getRotationX(), 1, 0, 0);
704 true3dMat.rotate(properties().getRotationY(), 0, 1, 0);
705 true3dMat.rotate(properties().getRotation(), 0, 0, 1);
706 true3dMat.scale(properties().getScaleX(), properties().getScaleY(), 1);
707 true3dMat.translate(-properties().getPivotX(), -properties().getPivotY());
John Reck113e0822014-03-18 09:22:59 -0700708
709 matrix.multiply(true3dMat);
710 }
711 }
712 }
713}
714
715/**
716 * Organizes the DisplayList hierarchy to prepare for background projection reordering.
717 *
718 * This should be called before a call to defer() or drawDisplayList()
719 *
720 * Each DisplayList that serves as a 3d root builds its list of composited children,
721 * which are flagged to not draw in the standard draw loop.
722 */
723void RenderNode::computeOrdering() {
Chris Craikb565df12015-10-05 13:00:52 -0700724#if !HWUI_NEW_OPS
John Reck113e0822014-03-18 09:22:59 -0700725 ATRACE_CALL();
726 mProjectedNodes.clear();
727
728 // TODO: create temporary DDLOp and call computeOrderingImpl on top DisplayList so that
729 // transform properties are applied correctly to top level children
Chris Craik003cc3d2015-10-16 10:24:55 -0700730 if (mDisplayList == nullptr) return;
Chris Craikb36af872015-10-16 14:23:12 -0700731 for (unsigned int i = 0; i < mDisplayList->getChildren().size(); i++) {
732 DrawRenderNodeOp* childOp = mDisplayList->getChildren()[i];
Chris Craikb565df12015-10-05 13:00:52 -0700733 childOp->renderNode->computeOrderingImpl(childOp, &mProjectedNodes, &mat4::identity());
John Reck113e0822014-03-18 09:22:59 -0700734 }
Chris Craikb565df12015-10-05 13:00:52 -0700735#endif
John Reck113e0822014-03-18 09:22:59 -0700736}
737
738void RenderNode::computeOrderingImpl(
Chris Craika7090e02014-06-20 16:01:00 -0700739 DrawRenderNodeOp* opState,
John Reck272a6852015-07-29 16:48:58 -0700740 std::vector<DrawRenderNodeOp*>* compositedChildrenOfProjectionSurface,
John Reck113e0822014-03-18 09:22:59 -0700741 const mat4* transformFromProjectionSurface) {
Chris Craikb565df12015-10-05 13:00:52 -0700742#if !HWUI_NEW_OPS
John Reck113e0822014-03-18 09:22:59 -0700743 mProjectedNodes.clear();
Chris Craik003cc3d2015-10-16 10:24:55 -0700744 if (mDisplayList == nullptr || mDisplayList->isEmpty()) return;
John Reck113e0822014-03-18 09:22:59 -0700745
746 // TODO: should avoid this calculation in most cases
747 // TODO: just calculate single matrix, down to all leaf composited elements
748 Matrix4 localTransformFromProjectionSurface(*transformFromProjectionSurface);
749 localTransformFromProjectionSurface.multiply(opState->mTransformFromParent);
750
John Reckd0a0b2a2014-03-20 16:28:56 -0700751 if (properties().getProjectBackwards()) {
John Reck113e0822014-03-18 09:22:59 -0700752 // composited projectee, flag for out of order draw, save matrix, and store in proj surface
753 opState->mSkipInOrderDraw = true;
Chris Craik7c85c542015-08-19 15:10:24 -0700754 opState->mTransformFromCompositingAncestor = localTransformFromProjectionSurface;
John Reck272a6852015-07-29 16:48:58 -0700755 compositedChildrenOfProjectionSurface->push_back(opState);
John Reck113e0822014-03-18 09:22:59 -0700756 } else {
757 // standard in order draw
758 opState->mSkipInOrderDraw = false;
759 }
760
Chris Craikb36af872015-10-16 14:23:12 -0700761 if (mDisplayList->getChildren().size() > 0) {
Chris Craik003cc3d2015-10-16 10:24:55 -0700762 const bool isProjectionReceiver = mDisplayList->projectionReceiveIndex >= 0;
John Reck113e0822014-03-18 09:22:59 -0700763 bool haveAppliedPropertiesToProjection = false;
Chris Craikb36af872015-10-16 14:23:12 -0700764 for (unsigned int i = 0; i < mDisplayList->getChildren().size(); i++) {
765 DrawRenderNodeOp* childOp = mDisplayList->getChildren()[i];
Chris Craikb565df12015-10-05 13:00:52 -0700766 RenderNode* child = childOp->renderNode;
John Reck113e0822014-03-18 09:22:59 -0700767
John Reck272a6852015-07-29 16:48:58 -0700768 std::vector<DrawRenderNodeOp*>* projectionChildren = nullptr;
Chris Craikd41c4d82015-01-05 15:51:13 -0800769 const mat4* projectionTransform = nullptr;
John Reckd0a0b2a2014-03-20 16:28:56 -0700770 if (isProjectionReceiver && !child->properties().getProjectBackwards()) {
Chris Craikbf72eb82015-06-08 11:30:44 -0700771 // if receiving projections, collect projecting descendant
John Reck113e0822014-03-18 09:22:59 -0700772
Chris Craikbf72eb82015-06-08 11:30:44 -0700773 // Note that if a direct descendant is projecting backwards, we pass its
774 // grandparent projection collection, since it shouldn't project onto its
John Reck113e0822014-03-18 09:22:59 -0700775 // parent, where it will already be drawing.
776 projectionChildren = &mProjectedNodes;
777 projectionTransform = &mat4::identity();
778 } else {
779 if (!haveAppliedPropertiesToProjection) {
780 applyViewPropertyTransforms(localTransformFromProjectionSurface);
781 haveAppliedPropertiesToProjection = true;
782 }
783 projectionChildren = compositedChildrenOfProjectionSurface;
784 projectionTransform = &localTransformFromProjectionSurface;
785 }
Derek Sollenbergerf2932592015-08-13 14:59:33 -0400786 child->computeOrderingImpl(childOp, projectionChildren, projectionTransform);
John Reck113e0822014-03-18 09:22:59 -0700787 }
788 }
Chris Craikb565df12015-10-05 13:00:52 -0700789#endif
John Reck113e0822014-03-18 09:22:59 -0700790}
791
792class DeferOperationHandler {
793public:
794 DeferOperationHandler(DeferStateStruct& deferStruct, int level)
795 : mDeferStruct(deferStruct), mLevel(level) {}
796 inline void operator()(DisplayListOp* operation, int saveCount, bool clipToBounds) {
797 operation->defer(mDeferStruct, saveCount, mLevel, clipToBounds);
798 }
799 inline LinearAllocator& allocator() { return *(mDeferStruct.mAllocator); }
Andreas Gampe64bb4132014-11-22 00:35:09 +0000800 inline void startMark(const char* name) {} // do nothing
Chris Craikb265e2c2014-03-27 15:50:09 -0700801 inline void endMark() {}
802 inline int level() { return mLevel; }
803 inline int replayFlags() { return mDeferStruct.mReplayFlags; }
Chris Craik74669862014-08-07 17:27:30 -0700804 inline SkPath* allocPathForFrame() { return mDeferStruct.allocPathForFrame(); }
John Reck113e0822014-03-18 09:22:59 -0700805
806private:
807 DeferStateStruct& mDeferStruct;
808 const int mLevel;
809};
810
Chris Craik80d49022014-06-20 15:03:43 -0700811void RenderNode::defer(DeferStateStruct& deferStruct, const int level) {
John Reck113e0822014-03-18 09:22:59 -0700812 DeferOperationHandler handler(deferStruct, level);
Chris Craikb265e2c2014-03-27 15:50:09 -0700813 issueOperations<DeferOperationHandler>(deferStruct.mRenderer, handler);
John Reck113e0822014-03-18 09:22:59 -0700814}
815
816class ReplayOperationHandler {
817public:
818 ReplayOperationHandler(ReplayStateStruct& replayStruct, int level)
819 : mReplayStruct(replayStruct), mLevel(level) {}
820 inline void operator()(DisplayListOp* operation, int saveCount, bool clipToBounds) {
821#if DEBUG_DISPLAY_LIST_OPS_AS_EVENTS
Chris Craik3f0854292014-04-15 16:18:08 -0700822 mReplayStruct.mRenderer.eventMark(operation->name());
John Reck113e0822014-03-18 09:22:59 -0700823#endif
824 operation->replay(mReplayStruct, saveCount, mLevel, clipToBounds);
825 }
826 inline LinearAllocator& allocator() { return *(mReplayStruct.mAllocator); }
Chris Craikb265e2c2014-03-27 15:50:09 -0700827 inline void startMark(const char* name) {
828 mReplayStruct.mRenderer.startMark(name);
829 }
830 inline void endMark() {
831 mReplayStruct.mRenderer.endMark();
Chris Craikb265e2c2014-03-27 15:50:09 -0700832 }
833 inline int level() { return mLevel; }
834 inline int replayFlags() { return mReplayStruct.mReplayFlags; }
Chris Craik74669862014-08-07 17:27:30 -0700835 inline SkPath* allocPathForFrame() { return mReplayStruct.allocPathForFrame(); }
John Reck113e0822014-03-18 09:22:59 -0700836
837private:
838 ReplayStateStruct& mReplayStruct;
839 const int mLevel;
840};
841
Chris Craik80d49022014-06-20 15:03:43 -0700842void RenderNode::replay(ReplayStateStruct& replayStruct, const int level) {
John Reck113e0822014-03-18 09:22:59 -0700843 ReplayOperationHandler handler(replayStruct, level);
Chris Craikb265e2c2014-03-27 15:50:09 -0700844 issueOperations<ReplayOperationHandler>(replayStruct.mRenderer, handler);
John Reck113e0822014-03-18 09:22:59 -0700845}
846
Chris Craik003cc3d2015-10-16 10:24:55 -0700847void RenderNode::buildZSortedChildList(const DisplayList::Chunk& chunk,
John Reck272a6852015-07-29 16:48:58 -0700848 std::vector<ZDrawRenderNodeOpPair>& zTranslatedNodes) {
Chris Craikb565df12015-10-05 13:00:52 -0700849#if !HWUI_NEW_OPS
Chris Craik8afd0f22014-08-21 17:41:57 -0700850 if (chunk.beginChildIndex == chunk.endChildIndex) return;
John Reck113e0822014-03-18 09:22:59 -0700851
Chris Craik8afd0f22014-08-21 17:41:57 -0700852 for (unsigned int i = chunk.beginChildIndex; i < chunk.endChildIndex; i++) {
Chris Craikb36af872015-10-16 14:23:12 -0700853 DrawRenderNodeOp* childOp = mDisplayList->getChildren()[i];
Chris Craikb565df12015-10-05 13:00:52 -0700854 RenderNode* child = childOp->renderNode;
Chris Craikcc39e162014-04-25 18:34:11 -0700855 float childZ = child->properties().getZ();
John Reck113e0822014-03-18 09:22:59 -0700856
Chris Craik8afd0f22014-08-21 17:41:57 -0700857 if (!MathUtils::isZero(childZ) && chunk.reorderChildren) {
John Reck272a6852015-07-29 16:48:58 -0700858 zTranslatedNodes.push_back(ZDrawRenderNodeOpPair(childZ, childOp));
John Reck113e0822014-03-18 09:22:59 -0700859 childOp->mSkipInOrderDraw = true;
John Reckd0a0b2a2014-03-20 16:28:56 -0700860 } else if (!child->properties().getProjectBackwards()) {
John Reck113e0822014-03-18 09:22:59 -0700861 // regular, in order drawing DisplayList
862 childOp->mSkipInOrderDraw = false;
863 }
864 }
865
Chris Craik8afd0f22014-08-21 17:41:57 -0700866 // Z sort any 3d children (stable-ness makes z compare fall back to standard drawing order)
John Reck113e0822014-03-18 09:22:59 -0700867 std::stable_sort(zTranslatedNodes.begin(), zTranslatedNodes.end());
Chris Craikb565df12015-10-05 13:00:52 -0700868#endif
John Reck113e0822014-03-18 09:22:59 -0700869}
870
Chris Craikb265e2c2014-03-27 15:50:09 -0700871template <class T>
872void RenderNode::issueDrawShadowOperation(const Matrix4& transformFromParent, T& handler) {
Chris Craik77b5cad2014-07-30 18:23:07 -0700873 if (properties().getAlpha() <= 0.0f
874 || properties().getOutline().getAlpha() <= 0.0f
Teng-Hui Zhu8d0ec382015-10-01 16:49:16 -0700875 || !properties().getOutline().getPath()
876 || properties().getScaleX() == 0
877 || properties().getScaleY() == 0) {
Chris Craik77b5cad2014-07-30 18:23:07 -0700878 // no shadow to draw
879 return;
880 }
Chris Craikb265e2c2014-03-27 15:50:09 -0700881
882 mat4 shadowMatrixXY(transformFromParent);
883 applyViewPropertyTransforms(shadowMatrixXY);
884
885 // Z matrix needs actual 3d transformation, so mapped z values will be correct
886 mat4 shadowMatrixZ(transformFromParent);
887 applyViewPropertyTransforms(shadowMatrixZ, true);
888
Chris Craik74669862014-08-07 17:27:30 -0700889 const SkPath* casterOutlinePath = properties().getOutline().getPath();
Chris Craikaf4d04c2014-07-29 12:50:14 -0700890 const SkPath* revealClipPath = properties().getRevealClip().getPath();
Chris Craik61317322014-05-21 13:03:52 -0700891 if (revealClipPath && revealClipPath->isEmpty()) return;
892
Chris Craik77b5cad2014-07-30 18:23:07 -0700893 float casterAlpha = properties().getAlpha() * properties().getOutline().getAlpha();
Chris Craik74669862014-08-07 17:27:30 -0700894
Chris Craik74669862014-08-07 17:27:30 -0700895
Chris Craikfaa79ff2014-12-01 13:44:21 -0800896 // holds temporary SkPath to store the result of intersections
Chris Craikd41c4d82015-01-05 15:51:13 -0800897 SkPath* frameAllocatedPath = nullptr;
Chris Craikfaa79ff2014-12-01 13:44:21 -0800898 const SkPath* outlinePath = casterOutlinePath;
899
900 // intersect the outline with the reveal clip, if present
901 if (revealClipPath) {
902 frameAllocatedPath = handler.allocPathForFrame();
903
Tom Hudson02a26302015-06-24 11:32:42 -0400904 Op(*outlinePath, *revealClipPath, kIntersect_SkPathOp, frameAllocatedPath);
Chris Craikfaa79ff2014-12-01 13:44:21 -0800905 outlinePath = frameAllocatedPath;
906 }
907
908 // intersect the outline with the clipBounds, if present
909 if (properties().getClippingFlags() & CLIP_TO_CLIP_BOUNDS) {
910 if (!frameAllocatedPath) {
911 frameAllocatedPath = handler.allocPathForFrame();
912 }
913
914 Rect clipBounds;
915 properties().getClippingRectForFlags(CLIP_TO_CLIP_BOUNDS, &clipBounds);
916 SkPath clipBoundsPath;
917 clipBoundsPath.addRect(clipBounds.left, clipBounds.top,
918 clipBounds.right, clipBounds.bottom);
919
Tom Hudson02a26302015-06-24 11:32:42 -0400920 Op(*outlinePath, clipBoundsPath, kIntersect_SkPathOp, frameAllocatedPath);
Chris Craik74669862014-08-07 17:27:30 -0700921 outlinePath = frameAllocatedPath;
922 }
923
Chris Craikb265e2c2014-03-27 15:50:09 -0700924 DisplayListOp* shadowOp = new (handler.allocator()) DrawShadowOp(
Chris Craik74669862014-08-07 17:27:30 -0700925 shadowMatrixXY, shadowMatrixZ, casterAlpha, outlinePath);
Chris Craikb265e2c2014-03-27 15:50:09 -0700926 handler(shadowOp, PROPERTY_SAVECOUNT, properties().getClipToBounds());
927}
928
John Reck113e0822014-03-18 09:22:59 -0700929#define SHADOW_DELTA 0.1f
930
931template <class T>
Chris Craikc3e75f92014-08-27 15:34:52 -0700932void RenderNode::issueOperationsOf3dChildren(ChildrenSelectMode mode,
John Reck272a6852015-07-29 16:48:58 -0700933 const Matrix4& initialTransform, const std::vector<ZDrawRenderNodeOpPair>& zTranslatedNodes,
Chris Craikc3e75f92014-08-27 15:34:52 -0700934 OpenGLRenderer& renderer, T& handler) {
John Reck113e0822014-03-18 09:22:59 -0700935 const int size = zTranslatedNodes.size();
936 if (size == 0
Chris Craikb9ce116d2015-08-20 15:14:06 -0700937 || (mode == ChildrenSelectMode::NegativeZChildren && zTranslatedNodes[0].key > 0.0f)
938 || (mode == ChildrenSelectMode::PositiveZChildren && zTranslatedNodes[size - 1].key < 0.0f)) {
John Reck113e0822014-03-18 09:22:59 -0700939 // no 3d children to draw
940 return;
941 }
942
Chris Craikc3e75f92014-08-27 15:34:52 -0700943 // Apply the base transform of the parent of the 3d children. This isolates
944 // 3d children of the current chunk from transformations made in previous chunks.
945 int rootRestoreTo = renderer.save(SkCanvas::kMatrix_SaveFlag);
Chris Craik6daa13c2015-08-19 13:32:12 -0700946 renderer.setGlobalMatrix(initialTransform);
Chris Craikc3e75f92014-08-27 15:34:52 -0700947
John Reck113e0822014-03-18 09:22:59 -0700948 /**
949 * Draw shadows and (potential) casters mostly in order, but allow the shadows of casters
950 * with very similar Z heights to draw together.
951 *
952 * This way, if Views A & B have the same Z height and are both casting shadows, the shadows are
953 * underneath both, and neither's shadow is drawn on top of the other.
954 */
955 const size_t nonNegativeIndex = findNonNegativeIndex(zTranslatedNodes);
956 size_t drawIndex, shadowIndex, endIndex;
Chris Craikb9ce116d2015-08-20 15:14:06 -0700957 if (mode == ChildrenSelectMode::NegativeZChildren) {
John Reck113e0822014-03-18 09:22:59 -0700958 drawIndex = 0;
959 endIndex = nonNegativeIndex;
960 shadowIndex = endIndex; // draw no shadows
961 } else {
962 drawIndex = nonNegativeIndex;
963 endIndex = size;
964 shadowIndex = drawIndex; // potentially draw shadow for each pos Z child
965 }
Chris Craik3f0854292014-04-15 16:18:08 -0700966
967 DISPLAY_LIST_LOGD("%*s%d %s 3d children:", (handler.level() + 1) * 2, "",
968 endIndex - drawIndex, mode == kNegativeZChildren ? "negative" : "positive");
969
John Reck113e0822014-03-18 09:22:59 -0700970 float lastCasterZ = 0.0f;
971 while (shadowIndex < endIndex || drawIndex < endIndex) {
972 if (shadowIndex < endIndex) {
Chris Craika7090e02014-06-20 16:01:00 -0700973 DrawRenderNodeOp* casterOp = zTranslatedNodes[shadowIndex].value;
Chris Craikb565df12015-10-05 13:00:52 -0700974 RenderNode* caster = casterOp->renderNode;
John Reck113e0822014-03-18 09:22:59 -0700975 const float casterZ = zTranslatedNodes[shadowIndex].key;
976 // attempt to render the shadow if the caster about to be drawn is its caster,
977 // OR if its caster's Z value is similar to the previous potential caster
978 if (shadowIndex == drawIndex || casterZ - lastCasterZ < SHADOW_DELTA) {
Chris Craikb265e2c2014-03-27 15:50:09 -0700979 caster->issueDrawShadowOperation(casterOp->mTransformFromParent, handler);
John Reck113e0822014-03-18 09:22:59 -0700980
981 lastCasterZ = casterZ; // must do this even if current caster not casting a shadow
982 shadowIndex++;
983 continue;
984 }
985 }
986
987 // only the actual child DL draw needs to be in save/restore,
988 // since it modifies the renderer's matrix
989 int restoreTo = renderer.save(SkCanvas::kMatrix_SaveFlag);
990
Chris Craika7090e02014-06-20 16:01:00 -0700991 DrawRenderNodeOp* childOp = zTranslatedNodes[drawIndex].value;
John Reck113e0822014-03-18 09:22:59 -0700992
993 renderer.concatMatrix(childOp->mTransformFromParent);
994 childOp->mSkipInOrderDraw = false; // this is horrible, I'm so sorry everyone
John Reckd0a0b2a2014-03-20 16:28:56 -0700995 handler(childOp, renderer.getSaveCount() - 1, properties().getClipToBounds());
John Reck113e0822014-03-18 09:22:59 -0700996 childOp->mSkipInOrderDraw = true;
997
998 renderer.restoreToCount(restoreTo);
999 drawIndex++;
1000 }
Chris Craikc3e75f92014-08-27 15:34:52 -07001001 renderer.restoreToCount(rootRestoreTo);
John Reck113e0822014-03-18 09:22:59 -07001002}
1003
1004template <class T>
Chris Craikb265e2c2014-03-27 15:50:09 -07001005void RenderNode::issueOperationsOfProjectedChildren(OpenGLRenderer& renderer, T& handler) {
Chris Craik3f0854292014-04-15 16:18:08 -07001006 DISPLAY_LIST_LOGD("%*s%d projected children:", (handler.level() + 1) * 2, "", mProjectedNodes.size());
1007 const SkPath* projectionReceiverOutline = properties().getOutline().getPath();
Chris Craik3f0854292014-04-15 16:18:08 -07001008 int restoreTo = renderer.getSaveCount();
1009
Chris Craikb3cca872014-08-08 18:42:51 -07001010 LinearAllocator& alloc = handler.allocator();
1011 handler(new (alloc) SaveOp(SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag),
1012 PROPERTY_SAVECOUNT, properties().getClipToBounds());
1013
1014 // Transform renderer to match background we're projecting onto
1015 // (by offsetting canvas by translationX/Y of background rendernode, since only those are set)
1016 const DisplayListOp* op =
Chris Craik10ed6922015-10-15 10:55:15 -07001017#if HWUI_NEW_OPS
1018 nullptr;
1019 LOG_ALWAYS_FATAL("unsupported");
1020#else
Chris Craik003cc3d2015-10-16 10:24:55 -07001021 (mDisplayList->getOps()[mDisplayList->projectionReceiveIndex]);
Chris Craik10ed6922015-10-15 10:55:15 -07001022#endif
Chris Craikb3cca872014-08-08 18:42:51 -07001023 const DrawRenderNodeOp* backgroundOp = reinterpret_cast<const DrawRenderNodeOp*>(op);
Chris Craikb565df12015-10-05 13:00:52 -07001024 const RenderProperties& backgroundProps = backgroundOp->renderNode->properties();
Chris Craikb3cca872014-08-08 18:42:51 -07001025 renderer.translate(backgroundProps.getTranslationX(), backgroundProps.getTranslationY());
1026
Chris Craik6fe991e52015-10-20 09:39:42 -07001027 // If the projection receiver has an outline, we mask projected content to it
Chris Craikfca52b752015-04-28 11:45:59 -07001028 // (which we know, apriori, are all tessellated paths)
1029 renderer.setProjectionPathMask(alloc, projectionReceiverOutline);
Chris Craik3f0854292014-04-15 16:18:08 -07001030
1031 // draw projected nodes
John Reck113e0822014-03-18 09:22:59 -07001032 for (size_t i = 0; i < mProjectedNodes.size(); i++) {
Chris Craika7090e02014-06-20 16:01:00 -07001033 DrawRenderNodeOp* childOp = mProjectedNodes[i];
John Reck113e0822014-03-18 09:22:59 -07001034
1035 // matrix save, concat, and restore can be done safely without allocating operations
1036 int restoreTo = renderer.save(SkCanvas::kMatrix_SaveFlag);
1037 renderer.concatMatrix(childOp->mTransformFromCompositingAncestor);
1038 childOp->mSkipInOrderDraw = false; // this is horrible, I'm so sorry everyone
John Reckd0a0b2a2014-03-20 16:28:56 -07001039 handler(childOp, renderer.getSaveCount() - 1, properties().getClipToBounds());
John Reck113e0822014-03-18 09:22:59 -07001040 childOp->mSkipInOrderDraw = true;
1041 renderer.restoreToCount(restoreTo);
1042 }
Chris Craik3f0854292014-04-15 16:18:08 -07001043
Chris Craikfca52b752015-04-28 11:45:59 -07001044 handler(new (alloc) RestoreToCountOp(restoreTo),
1045 PROPERTY_SAVECOUNT, properties().getClipToBounds());
John Reck113e0822014-03-18 09:22:59 -07001046}
1047
1048/**
1049 * This function serves both defer and replay modes, and will organize the displayList's component
1050 * operations for a single frame:
1051 *
1052 * Every 'simple' state operation that affects just the matrix and alpha (or other factors of
1053 * DeferredDisplayState) may be issued directly to the renderer, but complex operations (with custom
1054 * defer logic) and operations in displayListOps are issued through the 'handler' which handles the
1055 * defer vs replay logic, per operation
1056 */
1057template <class T>
Chris Craikb265e2c2014-03-27 15:50:09 -07001058void RenderNode::issueOperations(OpenGLRenderer& renderer, T& handler) {
Chris Craik003cc3d2015-10-16 10:24:55 -07001059 if (mDisplayList->isEmpty()) {
Chris Craikbf72eb82015-06-08 11:30:44 -07001060 DISPLAY_LIST_LOGD("%*sEmpty display list (%p, %s)", handler.level() * 2, "",
1061 this, getName());
Chris Craik06451282014-07-21 10:25:54 -07001062 return;
1063 }
1064
Chris Craik0b7e8242015-10-28 16:50:44 -07001065#if HWUI_NEW_OPS
1066 const bool drawLayer = false;
1067#else
Chris Craik51d6a3d2014-12-22 17:16:56 -08001068 const bool drawLayer = (mLayer && (&renderer != mLayer->renderer.get()));
Chris Craik0b7e8242015-10-28 16:50:44 -07001069#endif
John Reck25fbb3f2014-06-12 13:46:45 -07001070 // If we are updating the contents of mLayer, we don't want to apply any of
1071 // the RenderNode's properties to this issueOperations pass. Those will all
1072 // be applied when the layer is drawn, aka when this is true.
1073 const bool useViewProperties = (!mLayer || drawLayer);
Chris Craik06451282014-07-21 10:25:54 -07001074 if (useViewProperties) {
1075 const Outline& outline = properties().getOutline();
Teng-Hui Zhu8d0ec382015-10-01 16:49:16 -07001076 if (properties().getAlpha() <= 0
1077 || (outline.getShouldClip() && outline.isEmpty())
1078 || properties().getScaleX() == 0
1079 || properties().getScaleY() == 0) {
Chris Craikbf72eb82015-06-08 11:30:44 -07001080 DISPLAY_LIST_LOGD("%*sRejected display list (%p, %s)", handler.level() * 2, "",
1081 this, getName());
Chris Craik06451282014-07-21 10:25:54 -07001082 return;
1083 }
John Reck113e0822014-03-18 09:22:59 -07001084 }
1085
Chris Craik3f0854292014-04-15 16:18:08 -07001086 handler.startMark(getName());
Chris Craikb265e2c2014-03-27 15:50:09 -07001087
John Reck113e0822014-03-18 09:22:59 -07001088#if DEBUG_DISPLAY_LIST
Chris Craik3f0854292014-04-15 16:18:08 -07001089 const Rect& clipRect = renderer.getLocalClipBounds();
1090 DISPLAY_LIST_LOGD("%*sStart display list (%p, %s), localClipBounds: %.0f, %.0f, %.0f, %.0f",
Chris Craik03188872015-02-02 18:39:33 -08001091 handler.level() * 2, "", this, getName(),
Chris Craik3f0854292014-04-15 16:18:08 -07001092 clipRect.left, clipRect.top, clipRect.right, clipRect.bottom);
John Reck113e0822014-03-18 09:22:59 -07001093#endif
1094
1095 LinearAllocator& alloc = handler.allocator();
1096 int restoreTo = renderer.getSaveCount();
1097 handler(new (alloc) SaveOp(SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag),
John Reckd0a0b2a2014-03-20 16:28:56 -07001098 PROPERTY_SAVECOUNT, properties().getClipToBounds());
John Reck113e0822014-03-18 09:22:59 -07001099
Chris Craikbf72eb82015-06-08 11:30:44 -07001100 DISPLAY_LIST_LOGD("%*sSave %d %d", (handler.level() + 1) * 2, "",
John Reck113e0822014-03-18 09:22:59 -07001101 SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag, restoreTo);
1102
John Reck25fbb3f2014-06-12 13:46:45 -07001103 if (useViewProperties) {
1104 setViewProperties<T>(renderer, handler);
1105 }
John Reck113e0822014-03-18 09:22:59 -07001106
Chris Craik10ed6922015-10-15 10:55:15 -07001107#if HWUI_NEW_OPS
1108 LOG_ALWAYS_FATAL("legacy op traversal not supported");
1109#else
Chris Craik8c271ca2014-03-25 10:33:01 -07001110 bool quickRejected = properties().getClipToBounds()
1111 && renderer.quickRejectConservative(0, 0, properties().getWidth(), properties().getHeight());
John Reck113e0822014-03-18 09:22:59 -07001112 if (!quickRejected) {
Chris Craikc3e75f92014-08-27 15:34:52 -07001113 Matrix4 initialTransform(*(renderer.currentTransform()));
Tom Hudsonac7b6d32015-06-30 11:26:13 -04001114 renderer.setBaseTransform(initialTransform);
Chris Craikc3e75f92014-08-27 15:34:52 -07001115
John Reck25fbb3f2014-06-12 13:46:45 -07001116 if (drawLayer) {
Chris Craik3aadd602015-08-20 12:41:40 -07001117 handler(new (alloc) DrawLayerOp(mLayer),
John Reck25fbb3f2014-06-12 13:46:45 -07001118 renderer.getSaveCount() - 1, properties().getClipToBounds());
1119 } else {
Chris Craikc166b6c2014-09-05 19:55:30 -07001120 const int saveCountOffset = renderer.getSaveCount() - 1;
Chris Craik003cc3d2015-10-16 10:24:55 -07001121 const int projectionReceiveIndex = mDisplayList->projectionReceiveIndex;
1122 for (size_t chunkIndex = 0; chunkIndex < mDisplayList->getChunks().size(); chunkIndex++) {
1123 const DisplayList::Chunk& chunk = mDisplayList->getChunks()[chunkIndex];
John Reck113e0822014-03-18 09:22:59 -07001124
John Reck272a6852015-07-29 16:48:58 -07001125 std::vector<ZDrawRenderNodeOpPair> zTranslatedNodes;
Chris Craik8afd0f22014-08-21 17:41:57 -07001126 buildZSortedChildList(chunk, zTranslatedNodes);
1127
Chris Craikb9ce116d2015-08-20 15:14:06 -07001128 issueOperationsOf3dChildren(ChildrenSelectMode::NegativeZChildren,
Chris Craikc3e75f92014-08-27 15:34:52 -07001129 initialTransform, zTranslatedNodes, renderer, handler);
1130
Andreas Gampeedaecc12014-11-10 20:54:07 -08001131 for (size_t opIndex = chunk.beginOpIndex; opIndex < chunk.endOpIndex; opIndex++) {
Chris Craik003cc3d2015-10-16 10:24:55 -07001132 DisplayListOp *op = mDisplayList->getOps()[opIndex];
Chris Craik80d49022014-06-20 15:03:43 -07001133#if DEBUG_DISPLAY_LIST
Chris Craik03188872015-02-02 18:39:33 -08001134 op->output(handler.level() + 1);
Chris Craik80d49022014-06-20 15:03:43 -07001135#endif
Chris Craik8afd0f22014-08-21 17:41:57 -07001136 handler(op, saveCountOffset, properties().getClipToBounds());
John Reck113e0822014-03-18 09:22:59 -07001137
John Reck272a6852015-07-29 16:48:58 -07001138 if (CC_UNLIKELY(!mProjectedNodes.empty() && projectionReceiveIndex >= 0 &&
Andreas Gampeedaecc12014-11-10 20:54:07 -08001139 opIndex == static_cast<size_t>(projectionReceiveIndex))) {
Chris Craik8afd0f22014-08-21 17:41:57 -07001140 issueOperationsOfProjectedChildren(renderer, handler);
1141 }
John Reck25fbb3f2014-06-12 13:46:45 -07001142 }
John Reck113e0822014-03-18 09:22:59 -07001143
Chris Craikb9ce116d2015-08-20 15:14:06 -07001144 issueOperationsOf3dChildren(ChildrenSelectMode::PositiveZChildren,
Chris Craikc3e75f92014-08-27 15:34:52 -07001145 initialTransform, zTranslatedNodes, renderer, handler);
Chris Craik8afd0f22014-08-21 17:41:57 -07001146 }
John Reck25fbb3f2014-06-12 13:46:45 -07001147 }
John Reck113e0822014-03-18 09:22:59 -07001148 }
Chris Craik10ed6922015-10-15 10:55:15 -07001149#endif
John Reck113e0822014-03-18 09:22:59 -07001150
Chris Craikbf72eb82015-06-08 11:30:44 -07001151 DISPLAY_LIST_LOGD("%*sRestoreToCount %d", (handler.level() + 1) * 2, "", restoreTo);
John Reck113e0822014-03-18 09:22:59 -07001152 handler(new (alloc) RestoreToCountOp(restoreTo),
John Reckd0a0b2a2014-03-20 16:28:56 -07001153 PROPERTY_SAVECOUNT, properties().getClipToBounds());
Chris Craikb265e2c2014-03-27 15:50:09 -07001154
Chris Craikbf72eb82015-06-08 11:30:44 -07001155 DISPLAY_LIST_LOGD("%*sDone (%p, %s)", handler.level() * 2, "", this, getName());
Chris Craikb265e2c2014-03-27 15:50:09 -07001156 handler.endMark();
John Reck113e0822014-03-18 09:22:59 -07001157}
1158
1159} /* namespace uirenderer */
1160} /* namespace android */