blob: 9ac76a4339e1c0ad5ace0e66516ea8885dc0cb81 [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 <algorithm>
37#include <sstream>
38#include <string>
39
John Reck113e0822014-03-18 09:22:59 -070040namespace android {
41namespace uirenderer {
42
John Reck443a7142014-09-04 17:40:05 -070043void RenderNode::debugDumpLayers(const char* prefix) {
Chris Craik0b7e8242015-10-28 16:50:44 -070044#if HWUI_NEW_OPS
45 LOG_ALWAYS_FATAL("TODO: dump layer");
46#else
John Reck443a7142014-09-04 17:40:05 -070047 if (mLayer) {
48 ALOGD("%sNode %p (%s) has layer %p (fbo = %u, wasBuildLayered = %s)",
49 prefix, this, getName(), mLayer, mLayer->getFbo(),
50 mLayer->wasBuildLayered ? "true" : "false");
51 }
Chris Craik0b7e8242015-10-28 16:50:44 -070052#endif
Chris Craik003cc3d2015-10-16 10:24:55 -070053 if (mDisplayList) {
Chris Craikb36af872015-10-16 14:23:12 -070054 for (auto&& child : mDisplayList->getChildren()) {
Chris Craik10ed6922015-10-15 10:55:15 -070055 child->renderNode->debugDumpLayers(prefix);
John Reck443a7142014-09-04 17:40:05 -070056 }
57 }
58}
59
John Reck8de65a82014-04-09 15:23:38 -070060RenderNode::RenderNode()
John Reckff941dc2014-05-14 16:34:14 -070061 : mDirtyPropertyFields(0)
Chris Craik003cc3d2015-10-16 10:24:55 -070062 , mNeedsDisplayListSync(false)
63 , mDisplayList(nullptr)
64 , mStagingDisplayList(nullptr)
John Reck68bfe0a2014-06-24 15:34:58 -070065 , mAnimatorManager(*this)
John Reckdcba6722014-07-08 13:59:49 -070066 , mParentCount(0) {
John Reck113e0822014-03-18 09:22:59 -070067}
68
69RenderNode::~RenderNode() {
Chris Craik003cc3d2015-10-16 10:24:55 -070070 deleteDisplayList();
71 delete mStagingDisplayList;
Chris Craik0b7e8242015-10-28 16:50:44 -070072#if HWUI_NEW_OPS
73 LOG_ALWAYS_FATAL_IF(mLayer, "layer missed detachment!");
74#else
John Reck0e89e2b2014-10-31 14:49:06 -070075 if (mLayer) {
76 ALOGW("Memory Warning: Layer %p missed its detachment, held on to for far too long!", mLayer);
77 mLayer->postDecStrong();
Chris Craikd41c4d82015-01-05 15:51:13 -080078 mLayer = nullptr;
John Reck0e89e2b2014-10-31 14:49:06 -070079 }
Chris Craik0b7e8242015-10-28 16:50:44 -070080#endif
John Reck113e0822014-03-18 09:22:59 -070081}
82
Chris Craik003cc3d2015-10-16 10:24:55 -070083void RenderNode::setStagingDisplayList(DisplayList* displayList) {
84 mNeedsDisplayListSync = true;
85 delete mStagingDisplayList;
86 mStagingDisplayList = displayList;
John Reck9dea0d52015-10-27 10:04:38 -070087 // If mParentCount == 0 we are the sole reference to this RenderNode,
88 // so immediately free the old display list
89 if (!mParentCount && !mStagingDisplayList) {
90 deleteDisplayList();
91 }
John Reck113e0822014-03-18 09:22:59 -070092}
93
94/**
95 * This function is a simplified version of replay(), where we simply retrieve and log the
96 * display list. This function should remain in sync with the replay() function.
97 */
98void RenderNode::output(uint32_t level) {
Chris Craikbf72eb82015-06-08 11:30:44 -070099 ALOGD("%*sStart display list (%p, %s%s%s%s%s%s)", (level - 1) * 2, "", this,
Chris Craikb5a54352014-11-21 14:54:35 -0800100 getName(),
Chris Craik43a1d312015-05-27 11:28:14 -0700101 (MathUtils::isZero(properties().getAlpha()) ? ", zero alpha" : ""),
Chris Craikb5a54352014-11-21 14:54:35 -0800102 (properties().hasShadow() ? ", casting shadow" : ""),
103 (isRenderable() ? "" : ", empty"),
Chris Craikbf72eb82015-06-08 11:30:44 -0700104 (properties().getProjectBackwards() ? ", projected" : ""),
Chris Craikd41c4d82015-01-05 15:51:13 -0800105 (mLayer != nullptr ? ", on HW Layer" : ""));
Florin Malitaeecff562015-12-21 10:43:01 -0500106 ALOGD("%*s%s %d", level * 2, "", "Save", SaveFlags::MatrixClip);
John Reck113e0822014-03-18 09:22:59 -0700107
John Reckd0a0b2a2014-03-20 16:28:56 -0700108 properties().debugOutputProperties(level);
Chris Craik10ed6922015-10-15 10:55:15 -0700109
Chris Craik003cc3d2015-10-16 10:24:55 -0700110 if (mDisplayList) {
Chris Craik10ed6922015-10-15 10:55:15 -0700111#if HWUI_NEW_OPS
112 LOG_ALWAYS_FATAL("op dumping unsupported");
113#else
Chris Craik8afd0f22014-08-21 17:41:57 -0700114 // TODO: consider printing the chunk boundaries here
Chris Craik003cc3d2015-10-16 10:24:55 -0700115 for (auto&& op : mDisplayList->getOps()) {
Chris Craik10ed6922015-10-15 10:55:15 -0700116 op->output(level, DisplayListOp::kOpLogFlag_Recurse);
John Reckdc0349b2014-08-06 15:28:07 -0700117 }
Chris Craik10ed6922015-10-15 10:55:15 -0700118#endif
John Reck113e0822014-03-18 09:22:59 -0700119 }
120
Chris Craik3f0854292014-04-15 16:18:08 -0700121 ALOGD("%*sDone (%p, %s)", (level - 1) * 2, "", this, getName());
John Reck113e0822014-03-18 09:22:59 -0700122}
123
John Recke248bd12015-08-05 13:53:53 -0700124void RenderNode::copyTo(proto::RenderNode *pnode) {
125 pnode->set_id(static_cast<uint64_t>(
126 reinterpret_cast<uintptr_t>(this)));
127 pnode->set_name(mName.string(), mName.length());
128
129 proto::RenderProperties* pprops = pnode->mutable_properties();
130 pprops->set_left(properties().getLeft());
131 pprops->set_top(properties().getTop());
132 pprops->set_right(properties().getRight());
133 pprops->set_bottom(properties().getBottom());
134 pprops->set_clip_flags(properties().getClippingFlags());
135 pprops->set_alpha(properties().getAlpha());
136 pprops->set_translation_x(properties().getTranslationX());
137 pprops->set_translation_y(properties().getTranslationY());
138 pprops->set_translation_z(properties().getTranslationZ());
139 pprops->set_elevation(properties().getElevation());
140 pprops->set_rotation(properties().getRotation());
141 pprops->set_rotation_x(properties().getRotationX());
142 pprops->set_rotation_y(properties().getRotationY());
143 pprops->set_scale_x(properties().getScaleX());
144 pprops->set_scale_y(properties().getScaleY());
145 pprops->set_pivot_x(properties().getPivotX());
146 pprops->set_pivot_y(properties().getPivotY());
147 pprops->set_has_overlapping_rendering(properties().getHasOverlappingRendering());
148 pprops->set_pivot_explicitly_set(properties().isPivotExplicitlySet());
149 pprops->set_project_backwards(properties().getProjectBackwards());
150 pprops->set_projection_receiver(properties().isProjectionReceiver());
151 set(pprops->mutable_clip_bounds(), properties().getClipBounds());
152
153 const Outline& outline = properties().getOutline();
154 if (outline.getType() != Outline::Type::None) {
155 proto::Outline* poutline = pprops->mutable_outline();
156 poutline->clear_path();
157 if (outline.getType() == Outline::Type::Empty) {
158 poutline->set_type(proto::Outline_Type_Empty);
159 } else if (outline.getType() == Outline::Type::ConvexPath) {
160 poutline->set_type(proto::Outline_Type_ConvexPath);
161 if (const SkPath* path = outline.getPath()) {
162 set(poutline->mutable_path(), *path);
163 }
164 } else if (outline.getType() == Outline::Type::RoundRect) {
165 poutline->set_type(proto::Outline_Type_RoundRect);
166 } else {
167 ALOGW("Uknown outline type! %d", static_cast<int>(outline.getType()));
168 poutline->set_type(proto::Outline_Type_None);
169 }
170 poutline->set_should_clip(outline.getShouldClip());
171 poutline->set_alpha(outline.getAlpha());
172 poutline->set_radius(outline.getRadius());
173 set(poutline->mutable_bounds(), outline.getBounds());
174 } else {
175 pprops->clear_outline();
176 }
177
178 const RevealClip& revealClip = properties().getRevealClip();
179 if (revealClip.willClip()) {
180 proto::RevealClip* prevealClip = pprops->mutable_reveal_clip();
181 prevealClip->set_x(revealClip.getX());
182 prevealClip->set_y(revealClip.getY());
183 prevealClip->set_radius(revealClip.getRadius());
184 } else {
185 pprops->clear_reveal_clip();
186 }
187
188 pnode->clear_children();
Chris Craik003cc3d2015-10-16 10:24:55 -0700189 if (mDisplayList) {
Chris Craikb36af872015-10-16 14:23:12 -0700190 for (auto&& child : mDisplayList->getChildren()) {
Chris Craikb565df12015-10-05 13:00:52 -0700191 child->renderNode->copyTo(pnode->add_children());
John Recke248bd12015-08-05 13:53:53 -0700192 }
193 }
194}
195
John Reckfe5e7b72014-05-23 17:42:28 -0700196int RenderNode::getDebugSize() {
197 int size = sizeof(RenderNode);
Chris Craik003cc3d2015-10-16 10:24:55 -0700198 if (mStagingDisplayList) {
199 size += mStagingDisplayList->getUsedSize();
John Reckfe5e7b72014-05-23 17:42:28 -0700200 }
Chris Craik003cc3d2015-10-16 10:24:55 -0700201 if (mDisplayList && mDisplayList != mStagingDisplayList) {
202 size += mDisplayList->getUsedSize();
John Reckfe5e7b72014-05-23 17:42:28 -0700203 }
204 return size;
205}
206
John Reckf4198b72014-04-09 17:00:04 -0700207void RenderNode::prepareTree(TreeInfo& info) {
208 ATRACE_CALL();
Chris Craik69e5adf2014-08-14 13:34:01 -0700209 LOG_ALWAYS_FATAL_IF(!info.damageAccumulator, "DamageAccumulator missing");
John Reckf4198b72014-04-09 17:00:04 -0700210
Chris Craika766cb22015-06-08 16:49:43 -0700211 // Functors don't correctly handle stencil usage of overdraw debugging - shove 'em in a layer.
212 bool functorsNeedLayer = Properties::debugOverdraw;
213
214 prepareTreeImpl(info, functorsNeedLayer);
John Reckf4198b72014-04-09 17:00:04 -0700215}
216
John Reck68bfe0a2014-06-24 15:34:58 -0700217void RenderNode::addAnimator(const sp<BaseRenderNodeAnimator>& animator) {
218 mAnimatorManager.addAnimator(animator);
219}
220
Doris Liu8b083202016-02-19 21:46:06 +0000221void RenderNode::removeAnimator(const sp<BaseRenderNodeAnimator>& animator) {
222 mAnimatorManager.removeAnimator(animator);
223}
224
John Recke4267ea2014-06-03 15:53:15 -0700225void RenderNode::damageSelf(TreeInfo& info) {
John Reckce9f3082014-06-17 16:18:09 -0700226 if (isRenderable()) {
John Reck293e8682014-06-17 10:34:02 -0700227 if (properties().getClipDamageToBounds()) {
John Recka447d292014-06-11 18:39:44 -0700228 info.damageAccumulator->dirty(0, 0, properties().getWidth(), properties().getHeight());
229 } else {
230 // Hope this is big enough?
231 // TODO: Get this from the display list ops or something
John Reckc1288232015-08-12 13:39:11 -0700232 info.damageAccumulator->dirty(DIRTY_MIN, DIRTY_MIN, DIRTY_MAX, DIRTY_MAX);
John Recka447d292014-06-11 18:39:44 -0700233 }
John Recke4267ea2014-06-03 15:53:15 -0700234 }
235}
236
John Recka7c2ea22014-08-08 13:21:00 -0700237void RenderNode::prepareLayer(TreeInfo& info, uint32_t dirtyMask) {
Chris Craik856f0cc2015-04-21 15:13:29 -0700238 LayerType layerType = properties().effectiveLayerType();
Chris Craik182952f2015-03-09 14:17:29 -0700239 if (CC_UNLIKELY(layerType == LayerType::RenderLayer)) {
John Recka7c2ea22014-08-08 13:21:00 -0700240 // Damage applied so far needs to affect our parent, but does not require
241 // the layer to be updated. So we pop/push here to clear out the current
242 // damage and get a clean state for display list or children updates to
243 // affect, which will require the layer to be updated
244 info.damageAccumulator->popTransform();
245 info.damageAccumulator->pushTransform(this);
246 if (dirtyMask & DISPLAY_LIST) {
247 damageSelf(info);
248 }
John Reck25fbb3f2014-06-12 13:46:45 -0700249 }
250}
251
Chris Craik9fded232015-11-11 16:42:34 -0800252static layer_t* createLayer(RenderState& renderState, uint32_t width, uint32_t height) {
Chris Craik0b7e8242015-10-28 16:50:44 -0700253#if HWUI_NEW_OPS
Chris Craik9fded232015-11-11 16:42:34 -0800254 return renderState.layerPool().get(renderState, width, height);
Chris Craik0b7e8242015-10-28 16:50:44 -0700255#else
256 return LayerRenderer::createRenderLayer(renderState, width, height);
257#endif
258}
259
Chris Craik9fded232015-11-11 16:42:34 -0800260static void destroyLayer(layer_t* layer) {
Chris Craik0b7e8242015-10-28 16:50:44 -0700261#if HWUI_NEW_OPS
Chris Craik9fded232015-11-11 16:42:34 -0800262 RenderState& renderState = layer->renderState;
263 renderState.layerPool().putOrDelete(layer);
Chris Craik0b7e8242015-10-28 16:50:44 -0700264#else
265 LayerRenderer::destroyLayer(layer);
266#endif
267}
268
Chris Craik9fded232015-11-11 16:42:34 -0800269static bool layerMatchesWidthAndHeight(layer_t* layer, int width, int height) {
270#if HWUI_NEW_OPS
271 return layer->viewportWidth == (uint32_t) width && layer->viewportHeight == (uint32_t)height;
272#else
273 return layer->layer.getWidth() == width && layer->layer.getHeight() == height;
274#endif
275}
276
John Reck25fbb3f2014-06-12 13:46:45 -0700277void RenderNode::pushLayerUpdate(TreeInfo& info) {
Chris Craik856f0cc2015-04-21 15:13:29 -0700278 LayerType layerType = properties().effectiveLayerType();
John Reck25fbb3f2014-06-12 13:46:45 -0700279 // If we are not a layer OR we cannot be rendered (eg, view was detached)
280 // we need to destroy any Layers we may have had previously
Chris Craik182952f2015-03-09 14:17:29 -0700281 if (CC_LIKELY(layerType != LayerType::RenderLayer) || CC_UNLIKELY(!isRenderable())) {
John Reck25fbb3f2014-06-12 13:46:45 -0700282 if (CC_UNLIKELY(mLayer)) {
Chris Craik0b7e8242015-10-28 16:50:44 -0700283 destroyLayer(mLayer);
Chris Craikd41c4d82015-01-05 15:51:13 -0800284 mLayer = nullptr;
John Reck25fbb3f2014-06-12 13:46:45 -0700285 }
286 return;
287 }
288
Chris Craik69e5adf2014-08-14 13:34:01 -0700289 bool transformUpdateNeeded = false;
John Reck25fbb3f2014-06-12 13:46:45 -0700290 if (!mLayer) {
Chris Craik9fded232015-11-11 16:42:34 -0800291 mLayer = createLayer(info.canvasContext.getRenderState(), getWidth(), getHeight());
Chris Craikf559bd12015-11-18 14:42:00 -0800292#if !HWUI_NEW_OPS
293 applyLayerPropertiesToLayer(info);
294#endif
Chris Craik9fded232015-11-11 16:42:34 -0800295 damageSelf(info);
296 transformUpdateNeeded = true;
297 } else if (!layerMatchesWidthAndHeight(mLayer, getWidth(), getHeight())) {
Chris Craik0b7e8242015-10-28 16:50:44 -0700298#if HWUI_NEW_OPS
Chris Craik9fded232015-11-11 16:42:34 -0800299 RenderState& renderState = mLayer->renderState;
300 if (properties().fitsOnLayer()) {
301 mLayer = renderState.layerPool().resize(mLayer, getWidth(), getHeight());
302 } else {
Chris Craik0b7e8242015-10-28 16:50:44 -0700303#else
John Reckc25e5062014-06-18 14:21:29 -0700304 if (!LayerRenderer::resizeLayer(mLayer, getWidth(), getHeight())) {
Chris Craik0b7e8242015-10-28 16:50:44 -0700305#endif
306 destroyLayer(mLayer);
Chris Craikd41c4d82015-01-05 15:51:13 -0800307 mLayer = nullptr;
John Reckc25e5062014-06-18 14:21:29 -0700308 }
John Reck25fbb3f2014-06-12 13:46:45 -0700309 damageSelf(info);
Chris Craik69e5adf2014-08-14 13:34:01 -0700310 transformUpdateNeeded = true;
311 }
312
John Reck25fbb3f2014-06-12 13:46:45 -0700313 SkRect dirty;
314 info.damageAccumulator->peekAtDirty(&dirty);
John Reck25fbb3f2014-06-12 13:46:45 -0700315
John Reckc25e5062014-06-18 14:21:29 -0700316 if (!mLayer) {
John Reck0e89e2b2014-10-31 14:49:06 -0700317 Caches::getInstance().dumpMemoryUsage();
John Reckc25e5062014-06-18 14:21:29 -0700318 if (info.errorHandler) {
John Reck77c40102015-10-26 15:49:47 -0700319 std::ostringstream err;
320 err << "Unable to create layer for " << getName();
Chris Craik76caecf2015-11-02 19:17:45 -0800321 const int maxTextureSize = Caches::getInstance().maxTextureSize;
John Reck77c40102015-10-26 15:49:47 -0700322 if (getWidth() > maxTextureSize || getHeight() > maxTextureSize) {
323 err << ", size " << getWidth() << "x" << getHeight()
324 << " exceeds max size " << maxTextureSize;
325 } else {
326 err << ", see logcat for more info";
327 }
328 info.errorHandler->onError(err.str());
John Reckc25e5062014-06-18 14:21:29 -0700329 }
330 return;
331 }
332
Chris Craik98787e62015-11-13 10:55:30 -0800333 if (transformUpdateNeeded && mLayer) {
Chris Craikc71bfca2014-08-21 10:18:58 -0700334 // update the transform in window of the layer to reset its origin wrt light source position
335 Matrix4 windowTransform;
336 info.damageAccumulator->computeCurrentTransform(&windowTransform);
337 mLayer->setWindowTransform(windowTransform);
338 }
John Reckc79eabc2014-08-05 11:03:42 -0700339
Chris Craik0b7e8242015-10-28 16:50:44 -0700340#if HWUI_NEW_OPS
341 info.layerUpdateQueue->enqueueLayerWithDamage(this, dirty);
342#else
John Reckc79eabc2014-08-05 11:03:42 -0700343 if (dirty.intersect(0, 0, getWidth(), getHeight())) {
Mike Reed71487eb2014-11-19 16:13:20 -0500344 dirty.roundOut(&dirty);
John Reck25fbb3f2014-06-12 13:46:45 -0700345 mLayer->updateDeferred(this, dirty.fLeft, dirty.fTop, dirty.fRight, dirty.fBottom);
346 }
347 // This is not inside the above if because we may have called
348 // updateDeferred on a previous prepare pass that didn't have a renderer
349 if (info.renderer && mLayer->deferredUpdateScheduled) {
350 info.renderer->pushLayerUpdate(mLayer);
351 }
Chris Craik0b7e8242015-10-28 16:50:44 -0700352#endif
John Reck998a6d82014-08-28 15:35:53 -0700353
Chris Craike2e53a72015-10-28 15:55:40 -0700354 // There might be prefetched layers that need to be accounted for.
355 // That might be us, so tell CanvasContext that this layer is in the
356 // tree and should not be destroyed.
357 info.canvasContext.markLayerInUse(this);
John Reck25fbb3f2014-06-12 13:46:45 -0700358}
359
Chris Craika766cb22015-06-08 16:49:43 -0700360/**
361 * Traverse down the the draw tree to prepare for a frame.
362 *
363 * MODE_FULL = UI Thread-driven (thus properties must be synced), otherwise RT driven
364 *
365 * While traversing down the tree, functorsNeedLayer flag is set to true if anything that uses the
366 * stencil buffer may be needed. Views that use a functor to draw will be forced onto a layer.
367 */
368void RenderNode::prepareTreeImpl(TreeInfo& info, bool functorsNeedLayer) {
John Recka447d292014-06-11 18:39:44 -0700369 info.damageAccumulator->pushTransform(this);
John Reckf47a5942014-06-30 16:20:04 -0700370
John Reckdcba6722014-07-08 13:59:49 -0700371 if (info.mode == TreeInfo::MODE_FULL) {
John Reck25fbb3f2014-06-12 13:46:45 -0700372 pushStagingPropertiesChanges(info);
John Recke45b1fd2014-04-15 09:50:16 -0700373 }
John Reck9eb9f6f2014-08-21 11:23:05 -0700374 uint32_t animatorDirtyMask = 0;
375 if (CC_LIKELY(info.runAnimations)) {
376 animatorDirtyMask = mAnimatorManager.animate(info);
377 }
Chris Craika766cb22015-06-08 16:49:43 -0700378
John Reck3f725f02015-06-16 10:29:31 -0700379 bool willHaveFunctor = false;
Chris Craik003cc3d2015-10-16 10:24:55 -0700380 if (info.mode == TreeInfo::MODE_FULL && mStagingDisplayList) {
Chris Craikb36af872015-10-16 14:23:12 -0700381 willHaveFunctor = !mStagingDisplayList->getFunctors().empty();
Chris Craik003cc3d2015-10-16 10:24:55 -0700382 } else if (mDisplayList) {
Chris Craikb36af872015-10-16 14:23:12 -0700383 willHaveFunctor = !mDisplayList->getFunctors().empty();
John Reck3f725f02015-06-16 10:29:31 -0700384 }
Chris Craika766cb22015-06-08 16:49:43 -0700385 bool childFunctorsNeedLayer = mProperties.prepareForFunctorPresence(
386 willHaveFunctor, functorsNeedLayer);
387
John Reckf6481082016-02-02 15:18:23 -0800388 if (CC_UNLIKELY(mPositionListener.get())) {
389 mPositionListener->onPositionUpdated(*this, info);
390 }
391
John Recka7c2ea22014-08-08 13:21:00 -0700392 prepareLayer(info, animatorDirtyMask);
John Reckdcba6722014-07-08 13:59:49 -0700393 if (info.mode == TreeInfo::MODE_FULL) {
John Reck25fbb3f2014-06-12 13:46:45 -0700394 pushStagingDisplayListChanges(info);
395 }
Chris Craik003cc3d2015-10-16 10:24:55 -0700396 prepareSubTree(info, childFunctorsNeedLayer, mDisplayList);
John Reck25fbb3f2014-06-12 13:46:45 -0700397 pushLayerUpdate(info);
398
John Recka447d292014-06-11 18:39:44 -0700399 info.damageAccumulator->popTransform();
John Reckf4198b72014-04-09 17:00:04 -0700400}
401
Chris Craikb565df12015-10-05 13:00:52 -0700402void RenderNode::syncProperties() {
403 mProperties = mStagingProperties;
404}
405
John Reck25fbb3f2014-06-12 13:46:45 -0700406void RenderNode::pushStagingPropertiesChanges(TreeInfo& info) {
John Reckff941dc2014-05-14 16:34:14 -0700407 // Push the animators first so that setupStartValueIfNecessary() is called
408 // before properties() is trampled by stagingProperties(), as they are
409 // required by some animators.
John Reck9eb9f6f2014-08-21 11:23:05 -0700410 if (CC_LIKELY(info.runAnimations)) {
John Reck119907c2014-08-14 09:02:01 -0700411 mAnimatorManager.pushStaging();
John Reck9eb9f6f2014-08-21 11:23:05 -0700412 }
John Reckff941dc2014-05-14 16:34:14 -0700413 if (mDirtyPropertyFields) {
414 mDirtyPropertyFields = 0;
John Recke4267ea2014-06-03 15:53:15 -0700415 damageSelf(info);
John Recka447d292014-06-11 18:39:44 -0700416 info.damageAccumulator->popTransform();
Chris Craikb565df12015-10-05 13:00:52 -0700417 syncProperties();
Chris Craik0b7e8242015-10-28 16:50:44 -0700418#if !HWUI_NEW_OPS
John Reck25fbb3f2014-06-12 13:46:45 -0700419 applyLayerPropertiesToLayer(info);
Chris Craik0b7e8242015-10-28 16:50:44 -0700420#endif
John Recke4267ea2014-06-03 15:53:15 -0700421 // We could try to be clever and only re-damage if the matrix changed.
422 // However, we don't need to worry about that. The cost of over-damaging
423 // here is only going to be a single additional map rect of this node
424 // plus a rect join(). The parent's transform (and up) will only be
425 // performed once.
John Recka447d292014-06-11 18:39:44 -0700426 info.damageAccumulator->pushTransform(this);
John Recke4267ea2014-06-03 15:53:15 -0700427 damageSelf(info);
John Reckff941dc2014-05-14 16:34:14 -0700428 }
John Reck25fbb3f2014-06-12 13:46:45 -0700429}
430
Chris Craik0b7e8242015-10-28 16:50:44 -0700431#if !HWUI_NEW_OPS
Andreas Gampe64bb4132014-11-22 00:35:09 +0000432void RenderNode::applyLayerPropertiesToLayer(TreeInfo& info) {
John Reck25fbb3f2014-06-12 13:46:45 -0700433 if (CC_LIKELY(!mLayer)) return;
434
435 const LayerProperties& props = properties().layerProperties();
436 mLayer->setAlpha(props.alpha(), props.xferMode());
437 mLayer->setColorFilter(props.colorFilter());
438 mLayer->setBlend(props.needsBlending());
439}
Chris Craik0b7e8242015-10-28 16:50:44 -0700440#endif
John Reck25fbb3f2014-06-12 13:46:45 -0700441
Chris Craikb565df12015-10-05 13:00:52 -0700442void RenderNode::syncDisplayList() {
443 // Make sure we inc first so that we don't fluctuate between 0 and 1,
444 // which would thrash the layer cache
Chris Craik003cc3d2015-10-16 10:24:55 -0700445 if (mStagingDisplayList) {
Chris Craikb36af872015-10-16 14:23:12 -0700446 for (auto&& child : mStagingDisplayList->getChildren()) {
Chris Craikb565df12015-10-05 13:00:52 -0700447 child->renderNode->incParentRefCount();
448 }
449 }
Chris Craik003cc3d2015-10-16 10:24:55 -0700450 deleteDisplayList();
451 mDisplayList = mStagingDisplayList;
452 mStagingDisplayList = nullptr;
453 if (mDisplayList) {
Chris Craikb36af872015-10-16 14:23:12 -0700454 for (size_t i = 0; i < mDisplayList->getFunctors().size(); i++) {
455 (*mDisplayList->getFunctors()[i])(DrawGlInfo::kModeSync, nullptr);
Chris Craikb565df12015-10-05 13:00:52 -0700456 }
457 }
458}
459
John Reck25fbb3f2014-06-12 13:46:45 -0700460void RenderNode::pushStagingDisplayListChanges(TreeInfo& info) {
Chris Craik003cc3d2015-10-16 10:24:55 -0700461 if (mNeedsDisplayListSync) {
462 mNeedsDisplayListSync = false;
John Reck5c9d7172014-10-22 11:32:27 -0700463 // Damage with the old display list first then the new one to catch any
464 // changes in isRenderable or, in the future, bounds
465 damageSelf(info);
Chris Craikb565df12015-10-05 13:00:52 -0700466 syncDisplayList();
John Recke4267ea2014-06-03 15:53:15 -0700467 damageSelf(info);
John Reck8de65a82014-04-09 15:23:38 -0700468 }
John Reck8de65a82014-04-09 15:23:38 -0700469}
470
Chris Craik003cc3d2015-10-16 10:24:55 -0700471void RenderNode::deleteDisplayList() {
472 if (mDisplayList) {
Chris Craikb36af872015-10-16 14:23:12 -0700473 for (auto&& child : mDisplayList->getChildren()) {
Chris Craikb565df12015-10-05 13:00:52 -0700474 child->renderNode->decParentRefCount();
John Reckdcba6722014-07-08 13:59:49 -0700475 }
476 }
Chris Craik003cc3d2015-10-16 10:24:55 -0700477 delete mDisplayList;
478 mDisplayList = nullptr;
John Reckdcba6722014-07-08 13:59:49 -0700479}
480
Chris Craik003cc3d2015-10-16 10:24:55 -0700481void RenderNode::prepareSubTree(TreeInfo& info, bool functorsNeedLayer, DisplayList* subtree) {
John Reck8de65a82014-04-09 15:23:38 -0700482 if (subtree) {
John Reck860d1552014-04-11 19:15:05 -0700483 TextureCache& cache = Caches::getInstance().textureCache;
Chris Craikb36af872015-10-16 14:23:12 -0700484 info.out.hasFunctors |= subtree->getFunctors().size();
485 for (auto&& bitmapResource : subtree->getBitmapResources()) {
Chris Craike2e53a72015-10-28 15:55:40 -0700486 void* ownerToken = &info.canvasContext;
487 info.prepareTextures = cache.prefetchAndMarkInUse(ownerToken, bitmapResource);
John Reckf4198b72014-04-09 17:00:04 -0700488 }
Chris Craikb36af872015-10-16 14:23:12 -0700489 for (auto&& op : subtree->getChildren()) {
Chris Craikb565df12015-10-05 13:00:52 -0700490 RenderNode* childNode = op->renderNode;
491#if HWUI_NEW_OPS
492 info.damageAccumulator->pushTransform(&op->localMatrix);
493 bool childFunctorsNeedLayer = functorsNeedLayer; // TODO! || op->mRecordedWithPotentialStencilClip;
494#else
Chris Craik8d1f2122015-11-24 16:40:09 -0800495 info.damageAccumulator->pushTransform(&op->localMatrix);
Chris Craika766cb22015-06-08 16:49:43 -0700496 bool childFunctorsNeedLayer = functorsNeedLayer
497 // Recorded with non-rect clip, or canvas-rotated by parent
498 || op->mRecordedWithPotentialStencilClip;
Chris Craikb565df12015-10-05 13:00:52 -0700499#endif
Chris Craika766cb22015-06-08 16:49:43 -0700500 childNode->prepareTreeImpl(info, childFunctorsNeedLayer);
John Recka447d292014-06-11 18:39:44 -0700501 info.damageAccumulator->popTransform();
John Reck5bf11bb2014-03-25 10:22:09 -0700502 }
John Reck113e0822014-03-18 09:22:59 -0700503 }
504}
505
John Reckdcba6722014-07-08 13:59:49 -0700506void RenderNode::destroyHardwareResources() {
507 if (mLayer) {
Chris Craik0b7e8242015-10-28 16:50:44 -0700508 destroyLayer(mLayer);
Chris Craikd41c4d82015-01-05 15:51:13 -0800509 mLayer = nullptr;
John Reckdcba6722014-07-08 13:59:49 -0700510 }
Chris Craik003cc3d2015-10-16 10:24:55 -0700511 if (mDisplayList) {
Chris Craikb36af872015-10-16 14:23:12 -0700512 for (auto&& child : mDisplayList->getChildren()) {
Chris Craikb565df12015-10-05 13:00:52 -0700513 child->renderNode->destroyHardwareResources();
John Reckdcba6722014-07-08 13:59:49 -0700514 }
Chris Craik003cc3d2015-10-16 10:24:55 -0700515 if (mNeedsDisplayListSync) {
John Reckdcba6722014-07-08 13:59:49 -0700516 // Next prepare tree we are going to push a new display list, so we can
517 // drop our current one now
Chris Craik003cc3d2015-10-16 10:24:55 -0700518 deleteDisplayList();
John Reckdcba6722014-07-08 13:59:49 -0700519 }
520 }
521}
522
523void RenderNode::decParentRefCount() {
524 LOG_ALWAYS_FATAL_IF(!mParentCount, "already 0!");
525 mParentCount--;
526 if (!mParentCount) {
527 // If a child of ours is being attached to our parent then this will incorrectly
528 // destroy its hardware resources. However, this situation is highly unlikely
529 // and the failure is "just" that the layer is re-created, so this should
530 // be safe enough
531 destroyHardwareResources();
532 }
533}
534
John Reck113e0822014-03-18 09:22:59 -0700535/*
536 * For property operations, we pass a savecount of 0, since the operations aren't part of the
537 * displaylist, and thus don't have to compensate for the record-time/playback-time discrepancy in
John Reckd0a0b2a2014-03-20 16:28:56 -0700538 * base saveCount (i.e., how RestoreToCount uses saveCount + properties().getCount())
John Reck113e0822014-03-18 09:22:59 -0700539 */
540#define PROPERTY_SAVECOUNT 0
541
542template <class T>
Chris Craikb265e2c2014-03-27 15:50:09 -0700543void RenderNode::setViewProperties(OpenGLRenderer& renderer, T& handler) {
John Reck113e0822014-03-18 09:22:59 -0700544#if DEBUG_DISPLAY_LIST
Chris Craikb265e2c2014-03-27 15:50:09 -0700545 properties().debugOutputProperties(handler.level() + 1);
John Reck113e0822014-03-18 09:22:59 -0700546#endif
John Reckd0a0b2a2014-03-20 16:28:56 -0700547 if (properties().getLeft() != 0 || properties().getTop() != 0) {
548 renderer.translate(properties().getLeft(), properties().getTop());
John Reck113e0822014-03-18 09:22:59 -0700549 }
John Reckd0a0b2a2014-03-20 16:28:56 -0700550 if (properties().getStaticMatrix()) {
Derek Sollenberger13908822013-12-10 12:28:58 -0500551 renderer.concatMatrix(*properties().getStaticMatrix());
John Reckd0a0b2a2014-03-20 16:28:56 -0700552 } else if (properties().getAnimationMatrix()) {
Derek Sollenberger13908822013-12-10 12:28:58 -0500553 renderer.concatMatrix(*properties().getAnimationMatrix());
John Reck113e0822014-03-18 09:22:59 -0700554 }
John Reckf7483e32014-04-11 08:54:47 -0700555 if (properties().hasTransformMatrix()) {
556 if (properties().isTransformTranslateOnly()) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700557 renderer.translate(properties().getTranslationX(), properties().getTranslationY());
John Reck113e0822014-03-18 09:22:59 -0700558 } else {
John Reckd0a0b2a2014-03-20 16:28:56 -0700559 renderer.concatMatrix(*properties().getTransformMatrix());
John Reck113e0822014-03-18 09:22:59 -0700560 }
561 }
Chris Craik856f0cc2015-04-21 15:13:29 -0700562 const bool isLayer = properties().effectiveLayerType() != LayerType::None;
Chris Craika753f4c2014-07-24 12:39:17 -0700563 int clipFlags = properties().getClippingFlags();
John Reckd0a0b2a2014-03-20 16:28:56 -0700564 if (properties().getAlpha() < 1) {
John Reck25fbb3f2014-06-12 13:46:45 -0700565 if (isLayer) {
Chris Craika753f4c2014-07-24 12:39:17 -0700566 clipFlags &= ~CLIP_TO_BOUNDS; // bounds clipping done by layer
John Reck113e0822014-03-18 09:22:59 -0700567 }
Chris Craik4e9d9b22015-06-12 11:07:23 -0700568 if (CC_LIKELY(isLayer || !properties().getHasOverlappingRendering())) {
569 // simply scale rendering content's alpha
570 renderer.scaleAlpha(properties().getAlpha());
571 } else {
572 // savelayer needed to create an offscreen buffer
573 Rect layerBounds(0, 0, getWidth(), getHeight());
574 if (clipFlags) {
575 properties().getClippingRectForFlags(clipFlags, &layerBounds);
576 clipFlags = 0; // all clipping done by savelayer
577 }
578 SaveLayerOp* op = new (handler.allocator()) SaveLayerOp(
579 layerBounds.left, layerBounds.top,
580 layerBounds.right, layerBounds.bottom,
581 (int) (properties().getAlpha() * 255),
Florin Malitaeecff562015-12-21 10:43:01 -0500582 SaveFlags::HasAlphaLayer | SaveFlags::ClipToLayer);
Chris Craik4e9d9b22015-06-12 11:07:23 -0700583 handler(op, PROPERTY_SAVECOUNT, properties().getClipToBounds());
584 }
Chris Craik1a0808e2015-05-13 16:33:04 -0700585
586 if (CC_UNLIKELY(ATRACE_ENABLED() && properties().promotedToLayer())) {
Chris Craik4e9d9b22015-06-12 11:07:23 -0700587 // pretend alpha always causes savelayer to warn about
588 // performance problem affecting old versions
Chris Craik1a0808e2015-05-13 16:33:04 -0700589 ATRACE_FORMAT("%s alpha caused saveLayer %dx%d", getName(),
590 static_cast<int>(getWidth()),
591 static_cast<int>(getHeight()));
592 }
John Reck113e0822014-03-18 09:22:59 -0700593 }
Chris Craika753f4c2014-07-24 12:39:17 -0700594 if (clipFlags) {
595 Rect clipRect;
596 properties().getClippingRectForFlags(clipFlags, &clipRect);
Chris Craik8c271ca2014-03-25 10:33:01 -0700597 ClipRectOp* op = new (handler.allocator()) ClipRectOp(
Chris Craika753f4c2014-07-24 12:39:17 -0700598 clipRect.left, clipRect.top, clipRect.right, clipRect.bottom,
599 SkRegion::kIntersect_Op);
John Reckd0a0b2a2014-03-20 16:28:56 -0700600 handler(op, PROPERTY_SAVECOUNT, properties().getClipToBounds());
John Reck113e0822014-03-18 09:22:59 -0700601 }
Chris Craik8c271ca2014-03-25 10:33:01 -0700602
Chris Craike83cbd42014-09-03 17:52:24 -0700603 // TODO: support nesting round rect clips
Chris Craikaf4d04c2014-07-29 12:50:14 -0700604 if (mProperties.getRevealClip().willClip()) {
605 Rect bounds;
606 mProperties.getRevealClip().getBounds(&bounds);
607 renderer.setClippingRoundRect(handler.allocator(), bounds, mProperties.getRevealClip().getRadius());
608 } else if (mProperties.getOutline().willClip()) {
609 renderer.setClippingOutline(handler.allocator(), &(mProperties.getOutline()));
John Reck113e0822014-03-18 09:22:59 -0700610 }
611}
612
613/**
614 * Apply property-based transformations to input matrix
615 *
616 * If true3dTransform is set to true, the transform applied to the input matrix will use true 4x4
617 * matrix computation instead of the Skia 3x3 matrix + camera hackery.
618 */
Chris Craik69e5adf2014-08-14 13:34:01 -0700619void RenderNode::applyViewPropertyTransforms(mat4& matrix, bool true3dTransform) const {
John Reckd0a0b2a2014-03-20 16:28:56 -0700620 if (properties().getLeft() != 0 || properties().getTop() != 0) {
621 matrix.translate(properties().getLeft(), properties().getTop());
John Reck113e0822014-03-18 09:22:59 -0700622 }
John Reckd0a0b2a2014-03-20 16:28:56 -0700623 if (properties().getStaticMatrix()) {
624 mat4 stat(*properties().getStaticMatrix());
John Reck113e0822014-03-18 09:22:59 -0700625 matrix.multiply(stat);
John Reckd0a0b2a2014-03-20 16:28:56 -0700626 } else if (properties().getAnimationMatrix()) {
627 mat4 anim(*properties().getAnimationMatrix());
John Reck113e0822014-03-18 09:22:59 -0700628 matrix.multiply(anim);
629 }
Chris Craike0bb87d2014-04-22 17:55:41 -0700630
Chris Craikcc39e162014-04-25 18:34:11 -0700631 bool applyTranslationZ = true3dTransform && !MathUtils::isZero(properties().getZ());
Chris Craike0bb87d2014-04-22 17:55:41 -0700632 if (properties().hasTransformMatrix() || applyTranslationZ) {
John Reckf7483e32014-04-11 08:54:47 -0700633 if (properties().isTransformTranslateOnly()) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700634 matrix.translate(properties().getTranslationX(), properties().getTranslationY(),
Chris Craikcc39e162014-04-25 18:34:11 -0700635 true3dTransform ? properties().getZ() : 0.0f);
John Reck113e0822014-03-18 09:22:59 -0700636 } else {
637 if (!true3dTransform) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700638 matrix.multiply(*properties().getTransformMatrix());
John Reck113e0822014-03-18 09:22:59 -0700639 } else {
640 mat4 true3dMat;
641 true3dMat.loadTranslate(
John Reckd0a0b2a2014-03-20 16:28:56 -0700642 properties().getPivotX() + properties().getTranslationX(),
643 properties().getPivotY() + properties().getTranslationY(),
Chris Craikcc39e162014-04-25 18:34:11 -0700644 properties().getZ());
John Reckd0a0b2a2014-03-20 16:28:56 -0700645 true3dMat.rotate(properties().getRotationX(), 1, 0, 0);
646 true3dMat.rotate(properties().getRotationY(), 0, 1, 0);
647 true3dMat.rotate(properties().getRotation(), 0, 0, 1);
648 true3dMat.scale(properties().getScaleX(), properties().getScaleY(), 1);
649 true3dMat.translate(-properties().getPivotX(), -properties().getPivotY());
John Reck113e0822014-03-18 09:22:59 -0700650
651 matrix.multiply(true3dMat);
652 }
653 }
654 }
655}
656
657/**
658 * Organizes the DisplayList hierarchy to prepare for background projection reordering.
659 *
660 * This should be called before a call to defer() or drawDisplayList()
661 *
662 * Each DisplayList that serves as a 3d root builds its list of composited children,
663 * which are flagged to not draw in the standard draw loop.
664 */
665void RenderNode::computeOrdering() {
666 ATRACE_CALL();
667 mProjectedNodes.clear();
668
669 // TODO: create temporary DDLOp and call computeOrderingImpl on top DisplayList so that
670 // transform properties are applied correctly to top level children
Chris Craik003cc3d2015-10-16 10:24:55 -0700671 if (mDisplayList == nullptr) return;
Chris Craikb36af872015-10-16 14:23:12 -0700672 for (unsigned int i = 0; i < mDisplayList->getChildren().size(); i++) {
Chris Craik8d1f2122015-11-24 16:40:09 -0800673 renderNodeOp_t* childOp = mDisplayList->getChildren()[i];
Chris Craikb565df12015-10-05 13:00:52 -0700674 childOp->renderNode->computeOrderingImpl(childOp, &mProjectedNodes, &mat4::identity());
John Reck113e0822014-03-18 09:22:59 -0700675 }
676}
677
678void RenderNode::computeOrderingImpl(
Chris Craik8d1f2122015-11-24 16:40:09 -0800679 renderNodeOp_t* opState,
680 std::vector<renderNodeOp_t*>* compositedChildrenOfProjectionSurface,
John Reck113e0822014-03-18 09:22:59 -0700681 const mat4* transformFromProjectionSurface) {
682 mProjectedNodes.clear();
Chris Craik003cc3d2015-10-16 10:24:55 -0700683 if (mDisplayList == nullptr || mDisplayList->isEmpty()) return;
John Reck113e0822014-03-18 09:22:59 -0700684
685 // TODO: should avoid this calculation in most cases
686 // TODO: just calculate single matrix, down to all leaf composited elements
687 Matrix4 localTransformFromProjectionSurface(*transformFromProjectionSurface);
Chris Craik8d1f2122015-11-24 16:40:09 -0800688 localTransformFromProjectionSurface.multiply(opState->localMatrix);
John Reck113e0822014-03-18 09:22:59 -0700689
John Reckd0a0b2a2014-03-20 16:28:56 -0700690 if (properties().getProjectBackwards()) {
John Reck113e0822014-03-18 09:22:59 -0700691 // composited projectee, flag for out of order draw, save matrix, and store in proj surface
Chris Craik8d1f2122015-11-24 16:40:09 -0800692 opState->skipInOrderDraw = true;
693 opState->transformFromCompositingAncestor = localTransformFromProjectionSurface;
John Reck272a6852015-07-29 16:48:58 -0700694 compositedChildrenOfProjectionSurface->push_back(opState);
John Reck113e0822014-03-18 09:22:59 -0700695 } else {
696 // standard in order draw
Chris Craik8d1f2122015-11-24 16:40:09 -0800697 opState->skipInOrderDraw = false;
John Reck113e0822014-03-18 09:22:59 -0700698 }
699
Chris Craikb36af872015-10-16 14:23:12 -0700700 if (mDisplayList->getChildren().size() > 0) {
Chris Craik003cc3d2015-10-16 10:24:55 -0700701 const bool isProjectionReceiver = mDisplayList->projectionReceiveIndex >= 0;
John Reck113e0822014-03-18 09:22:59 -0700702 bool haveAppliedPropertiesToProjection = false;
Chris Craikb36af872015-10-16 14:23:12 -0700703 for (unsigned int i = 0; i < mDisplayList->getChildren().size(); i++) {
Chris Craik8d1f2122015-11-24 16:40:09 -0800704 renderNodeOp_t* childOp = mDisplayList->getChildren()[i];
Chris Craikb565df12015-10-05 13:00:52 -0700705 RenderNode* child = childOp->renderNode;
John Reck113e0822014-03-18 09:22:59 -0700706
Chris Craik8d1f2122015-11-24 16:40:09 -0800707 std::vector<renderNodeOp_t*>* projectionChildren = nullptr;
Chris Craikd41c4d82015-01-05 15:51:13 -0800708 const mat4* projectionTransform = nullptr;
John Reckd0a0b2a2014-03-20 16:28:56 -0700709 if (isProjectionReceiver && !child->properties().getProjectBackwards()) {
Chris Craikbf72eb82015-06-08 11:30:44 -0700710 // if receiving projections, collect projecting descendant
John Reck113e0822014-03-18 09:22:59 -0700711
Chris Craikbf72eb82015-06-08 11:30:44 -0700712 // Note that if a direct descendant is projecting backwards, we pass its
713 // grandparent projection collection, since it shouldn't project onto its
John Reck113e0822014-03-18 09:22:59 -0700714 // parent, where it will already be drawing.
715 projectionChildren = &mProjectedNodes;
716 projectionTransform = &mat4::identity();
717 } else {
718 if (!haveAppliedPropertiesToProjection) {
719 applyViewPropertyTransforms(localTransformFromProjectionSurface);
720 haveAppliedPropertiesToProjection = true;
721 }
722 projectionChildren = compositedChildrenOfProjectionSurface;
723 projectionTransform = &localTransformFromProjectionSurface;
724 }
Derek Sollenbergerf2932592015-08-13 14:59:33 -0400725 child->computeOrderingImpl(childOp, projectionChildren, projectionTransform);
John Reck113e0822014-03-18 09:22:59 -0700726 }
727 }
John Reck113e0822014-03-18 09:22:59 -0700728}
729
730class DeferOperationHandler {
731public:
732 DeferOperationHandler(DeferStateStruct& deferStruct, int level)
733 : mDeferStruct(deferStruct), mLevel(level) {}
734 inline void operator()(DisplayListOp* operation, int saveCount, bool clipToBounds) {
735 operation->defer(mDeferStruct, saveCount, mLevel, clipToBounds);
736 }
737 inline LinearAllocator& allocator() { return *(mDeferStruct.mAllocator); }
Andreas Gampe64bb4132014-11-22 00:35:09 +0000738 inline void startMark(const char* name) {} // do nothing
Chris Craikb265e2c2014-03-27 15:50:09 -0700739 inline void endMark() {}
740 inline int level() { return mLevel; }
741 inline int replayFlags() { return mDeferStruct.mReplayFlags; }
Chris Craik74669862014-08-07 17:27:30 -0700742 inline SkPath* allocPathForFrame() { return mDeferStruct.allocPathForFrame(); }
John Reck113e0822014-03-18 09:22:59 -0700743
744private:
745 DeferStateStruct& mDeferStruct;
746 const int mLevel;
747};
748
Chris Craik80d49022014-06-20 15:03:43 -0700749void RenderNode::defer(DeferStateStruct& deferStruct, const int level) {
John Reck113e0822014-03-18 09:22:59 -0700750 DeferOperationHandler handler(deferStruct, level);
Chris Craikb265e2c2014-03-27 15:50:09 -0700751 issueOperations<DeferOperationHandler>(deferStruct.mRenderer, handler);
John Reck113e0822014-03-18 09:22:59 -0700752}
753
754class ReplayOperationHandler {
755public:
756 ReplayOperationHandler(ReplayStateStruct& replayStruct, int level)
757 : mReplayStruct(replayStruct), mLevel(level) {}
758 inline void operator()(DisplayListOp* operation, int saveCount, bool clipToBounds) {
759#if DEBUG_DISPLAY_LIST_OPS_AS_EVENTS
Chris Craik3f0854292014-04-15 16:18:08 -0700760 mReplayStruct.mRenderer.eventMark(operation->name());
John Reck113e0822014-03-18 09:22:59 -0700761#endif
762 operation->replay(mReplayStruct, saveCount, mLevel, clipToBounds);
763 }
764 inline LinearAllocator& allocator() { return *(mReplayStruct.mAllocator); }
Chris Craikb265e2c2014-03-27 15:50:09 -0700765 inline void startMark(const char* name) {
766 mReplayStruct.mRenderer.startMark(name);
767 }
768 inline void endMark() {
769 mReplayStruct.mRenderer.endMark();
Chris Craikb265e2c2014-03-27 15:50:09 -0700770 }
771 inline int level() { return mLevel; }
772 inline int replayFlags() { return mReplayStruct.mReplayFlags; }
Chris Craik74669862014-08-07 17:27:30 -0700773 inline SkPath* allocPathForFrame() { return mReplayStruct.allocPathForFrame(); }
John Reck113e0822014-03-18 09:22:59 -0700774
775private:
776 ReplayStateStruct& mReplayStruct;
777 const int mLevel;
778};
779
Chris Craik80d49022014-06-20 15:03:43 -0700780void RenderNode::replay(ReplayStateStruct& replayStruct, const int level) {
John Reck113e0822014-03-18 09:22:59 -0700781 ReplayOperationHandler handler(replayStruct, level);
Chris Craikb265e2c2014-03-27 15:50:09 -0700782 issueOperations<ReplayOperationHandler>(replayStruct.mRenderer, handler);
John Reck113e0822014-03-18 09:22:59 -0700783}
784
Chris Craik003cc3d2015-10-16 10:24:55 -0700785void RenderNode::buildZSortedChildList(const DisplayList::Chunk& chunk,
John Reck272a6852015-07-29 16:48:58 -0700786 std::vector<ZDrawRenderNodeOpPair>& zTranslatedNodes) {
Chris Craikb565df12015-10-05 13:00:52 -0700787#if !HWUI_NEW_OPS
Chris Craik8afd0f22014-08-21 17:41:57 -0700788 if (chunk.beginChildIndex == chunk.endChildIndex) return;
John Reck113e0822014-03-18 09:22:59 -0700789
Chris Craik8afd0f22014-08-21 17:41:57 -0700790 for (unsigned int i = chunk.beginChildIndex; i < chunk.endChildIndex; i++) {
Chris Craikb36af872015-10-16 14:23:12 -0700791 DrawRenderNodeOp* childOp = mDisplayList->getChildren()[i];
Chris Craikb565df12015-10-05 13:00:52 -0700792 RenderNode* child = childOp->renderNode;
Chris Craikcc39e162014-04-25 18:34:11 -0700793 float childZ = child->properties().getZ();
John Reck113e0822014-03-18 09:22:59 -0700794
Chris Craik8afd0f22014-08-21 17:41:57 -0700795 if (!MathUtils::isZero(childZ) && chunk.reorderChildren) {
John Reck272a6852015-07-29 16:48:58 -0700796 zTranslatedNodes.push_back(ZDrawRenderNodeOpPair(childZ, childOp));
Chris Craik8d1f2122015-11-24 16:40:09 -0800797 childOp->skipInOrderDraw = true;
John Reckd0a0b2a2014-03-20 16:28:56 -0700798 } else if (!child->properties().getProjectBackwards()) {
John Reck113e0822014-03-18 09:22:59 -0700799 // regular, in order drawing DisplayList
Chris Craik8d1f2122015-11-24 16:40:09 -0800800 childOp->skipInOrderDraw = false;
John Reck113e0822014-03-18 09:22:59 -0700801 }
802 }
803
Chris Craik8afd0f22014-08-21 17:41:57 -0700804 // Z sort any 3d children (stable-ness makes z compare fall back to standard drawing order)
John Reck113e0822014-03-18 09:22:59 -0700805 std::stable_sort(zTranslatedNodes.begin(), zTranslatedNodes.end());
Chris Craikb565df12015-10-05 13:00:52 -0700806#endif
John Reck113e0822014-03-18 09:22:59 -0700807}
808
Chris Craikb265e2c2014-03-27 15:50:09 -0700809template <class T>
810void RenderNode::issueDrawShadowOperation(const Matrix4& transformFromParent, T& handler) {
Chris Craik77b5cad2014-07-30 18:23:07 -0700811 if (properties().getAlpha() <= 0.0f
812 || properties().getOutline().getAlpha() <= 0.0f
Teng-Hui Zhu8d0ec382015-10-01 16:49:16 -0700813 || !properties().getOutline().getPath()
814 || properties().getScaleX() == 0
815 || properties().getScaleY() == 0) {
Chris Craik77b5cad2014-07-30 18:23:07 -0700816 // no shadow to draw
817 return;
818 }
Chris Craikb265e2c2014-03-27 15:50:09 -0700819
820 mat4 shadowMatrixXY(transformFromParent);
821 applyViewPropertyTransforms(shadowMatrixXY);
822
823 // Z matrix needs actual 3d transformation, so mapped z values will be correct
824 mat4 shadowMatrixZ(transformFromParent);
825 applyViewPropertyTransforms(shadowMatrixZ, true);
826
Chris Craik74669862014-08-07 17:27:30 -0700827 const SkPath* casterOutlinePath = properties().getOutline().getPath();
Chris Craikaf4d04c2014-07-29 12:50:14 -0700828 const SkPath* revealClipPath = properties().getRevealClip().getPath();
Chris Craik61317322014-05-21 13:03:52 -0700829 if (revealClipPath && revealClipPath->isEmpty()) return;
830
Chris Craik77b5cad2014-07-30 18:23:07 -0700831 float casterAlpha = properties().getAlpha() * properties().getOutline().getAlpha();
Chris Craik74669862014-08-07 17:27:30 -0700832
Chris Craik74669862014-08-07 17:27:30 -0700833
Chris Craikfaa79ff2014-12-01 13:44:21 -0800834 // holds temporary SkPath to store the result of intersections
Chris Craikd41c4d82015-01-05 15:51:13 -0800835 SkPath* frameAllocatedPath = nullptr;
Chris Craikfaa79ff2014-12-01 13:44:21 -0800836 const SkPath* outlinePath = casterOutlinePath;
837
838 // intersect the outline with the reveal clip, if present
839 if (revealClipPath) {
840 frameAllocatedPath = handler.allocPathForFrame();
841
Tom Hudson02a26302015-06-24 11:32:42 -0400842 Op(*outlinePath, *revealClipPath, kIntersect_SkPathOp, frameAllocatedPath);
Chris Craikfaa79ff2014-12-01 13:44:21 -0800843 outlinePath = frameAllocatedPath;
844 }
845
846 // intersect the outline with the clipBounds, if present
847 if (properties().getClippingFlags() & CLIP_TO_CLIP_BOUNDS) {
848 if (!frameAllocatedPath) {
849 frameAllocatedPath = handler.allocPathForFrame();
850 }
851
852 Rect clipBounds;
853 properties().getClippingRectForFlags(CLIP_TO_CLIP_BOUNDS, &clipBounds);
854 SkPath clipBoundsPath;
855 clipBoundsPath.addRect(clipBounds.left, clipBounds.top,
856 clipBounds.right, clipBounds.bottom);
857
Tom Hudson02a26302015-06-24 11:32:42 -0400858 Op(*outlinePath, clipBoundsPath, kIntersect_SkPathOp, frameAllocatedPath);
Chris Craik74669862014-08-07 17:27:30 -0700859 outlinePath = frameAllocatedPath;
860 }
861
Chris Craikb265e2c2014-03-27 15:50:09 -0700862 DisplayListOp* shadowOp = new (handler.allocator()) DrawShadowOp(
Chris Craik74669862014-08-07 17:27:30 -0700863 shadowMatrixXY, shadowMatrixZ, casterAlpha, outlinePath);
Chris Craikb265e2c2014-03-27 15:50:09 -0700864 handler(shadowOp, PROPERTY_SAVECOUNT, properties().getClipToBounds());
865}
866
John Reck113e0822014-03-18 09:22:59 -0700867#define SHADOW_DELTA 0.1f
868
869template <class T>
Chris Craikc3e75f92014-08-27 15:34:52 -0700870void RenderNode::issueOperationsOf3dChildren(ChildrenSelectMode mode,
John Reck272a6852015-07-29 16:48:58 -0700871 const Matrix4& initialTransform, const std::vector<ZDrawRenderNodeOpPair>& zTranslatedNodes,
Chris Craikc3e75f92014-08-27 15:34:52 -0700872 OpenGLRenderer& renderer, T& handler) {
John Reck113e0822014-03-18 09:22:59 -0700873 const int size = zTranslatedNodes.size();
874 if (size == 0
Chris Craikb9ce116d2015-08-20 15:14:06 -0700875 || (mode == ChildrenSelectMode::NegativeZChildren && zTranslatedNodes[0].key > 0.0f)
876 || (mode == ChildrenSelectMode::PositiveZChildren && zTranslatedNodes[size - 1].key < 0.0f)) {
John Reck113e0822014-03-18 09:22:59 -0700877 // no 3d children to draw
878 return;
879 }
880
Chris Craikc3e75f92014-08-27 15:34:52 -0700881 // Apply the base transform of the parent of the 3d children. This isolates
882 // 3d children of the current chunk from transformations made in previous chunks.
Florin Malitaeecff562015-12-21 10:43:01 -0500883 int rootRestoreTo = renderer.save(SaveFlags::Matrix);
Chris Craik6daa13c2015-08-19 13:32:12 -0700884 renderer.setGlobalMatrix(initialTransform);
Chris Craikc3e75f92014-08-27 15:34:52 -0700885
John Reck113e0822014-03-18 09:22:59 -0700886 /**
887 * Draw shadows and (potential) casters mostly in order, but allow the shadows of casters
888 * with very similar Z heights to draw together.
889 *
890 * This way, if Views A & B have the same Z height and are both casting shadows, the shadows are
891 * underneath both, and neither's shadow is drawn on top of the other.
892 */
893 const size_t nonNegativeIndex = findNonNegativeIndex(zTranslatedNodes);
894 size_t drawIndex, shadowIndex, endIndex;
Chris Craikb9ce116d2015-08-20 15:14:06 -0700895 if (mode == ChildrenSelectMode::NegativeZChildren) {
John Reck113e0822014-03-18 09:22:59 -0700896 drawIndex = 0;
897 endIndex = nonNegativeIndex;
898 shadowIndex = endIndex; // draw no shadows
899 } else {
900 drawIndex = nonNegativeIndex;
901 endIndex = size;
902 shadowIndex = drawIndex; // potentially draw shadow for each pos Z child
903 }
Chris Craik3f0854292014-04-15 16:18:08 -0700904
905 DISPLAY_LIST_LOGD("%*s%d %s 3d children:", (handler.level() + 1) * 2, "",
906 endIndex - drawIndex, mode == kNegativeZChildren ? "negative" : "positive");
907
John Reck113e0822014-03-18 09:22:59 -0700908 float lastCasterZ = 0.0f;
909 while (shadowIndex < endIndex || drawIndex < endIndex) {
910 if (shadowIndex < endIndex) {
Chris Craika7090e02014-06-20 16:01:00 -0700911 DrawRenderNodeOp* casterOp = zTranslatedNodes[shadowIndex].value;
Chris Craikb565df12015-10-05 13:00:52 -0700912 RenderNode* caster = casterOp->renderNode;
John Reck113e0822014-03-18 09:22:59 -0700913 const float casterZ = zTranslatedNodes[shadowIndex].key;
914 // attempt to render the shadow if the caster about to be drawn is its caster,
915 // OR if its caster's Z value is similar to the previous potential caster
916 if (shadowIndex == drawIndex || casterZ - lastCasterZ < SHADOW_DELTA) {
Chris Craik8d1f2122015-11-24 16:40:09 -0800917 caster->issueDrawShadowOperation(casterOp->localMatrix, handler);
John Reck113e0822014-03-18 09:22:59 -0700918
919 lastCasterZ = casterZ; // must do this even if current caster not casting a shadow
920 shadowIndex++;
921 continue;
922 }
923 }
924
925 // only the actual child DL draw needs to be in save/restore,
926 // since it modifies the renderer's matrix
Florin Malitaeecff562015-12-21 10:43:01 -0500927 int restoreTo = renderer.save(SaveFlags::Matrix);
John Reck113e0822014-03-18 09:22:59 -0700928
Chris Craika7090e02014-06-20 16:01:00 -0700929 DrawRenderNodeOp* childOp = zTranslatedNodes[drawIndex].value;
John Reck113e0822014-03-18 09:22:59 -0700930
Chris Craik8d1f2122015-11-24 16:40:09 -0800931 renderer.concatMatrix(childOp->localMatrix);
932 childOp->skipInOrderDraw = false; // this is horrible, I'm so sorry everyone
John Reckd0a0b2a2014-03-20 16:28:56 -0700933 handler(childOp, renderer.getSaveCount() - 1, properties().getClipToBounds());
Chris Craik8d1f2122015-11-24 16:40:09 -0800934 childOp->skipInOrderDraw = true;
John Reck113e0822014-03-18 09:22:59 -0700935
936 renderer.restoreToCount(restoreTo);
937 drawIndex++;
938 }
Chris Craikc3e75f92014-08-27 15:34:52 -0700939 renderer.restoreToCount(rootRestoreTo);
John Reck113e0822014-03-18 09:22:59 -0700940}
941
942template <class T>
Chris Craikb265e2c2014-03-27 15:50:09 -0700943void RenderNode::issueOperationsOfProjectedChildren(OpenGLRenderer& renderer, T& handler) {
Chris Craik3f0854292014-04-15 16:18:08 -0700944 DISPLAY_LIST_LOGD("%*s%d projected children:", (handler.level() + 1) * 2, "", mProjectedNodes.size());
945 const SkPath* projectionReceiverOutline = properties().getOutline().getPath();
Chris Craik3f0854292014-04-15 16:18:08 -0700946 int restoreTo = renderer.getSaveCount();
947
Chris Craikb3cca872014-08-08 18:42:51 -0700948 LinearAllocator& alloc = handler.allocator();
Florin Malitaeecff562015-12-21 10:43:01 -0500949 handler(new (alloc) SaveOp(SaveFlags::MatrixClip),
Chris Craikb3cca872014-08-08 18:42:51 -0700950 PROPERTY_SAVECOUNT, properties().getClipToBounds());
951
952 // Transform renderer to match background we're projecting onto
953 // (by offsetting canvas by translationX/Y of background rendernode, since only those are set)
954 const DisplayListOp* op =
Chris Craik10ed6922015-10-15 10:55:15 -0700955#if HWUI_NEW_OPS
956 nullptr;
957 LOG_ALWAYS_FATAL("unsupported");
958#else
Chris Craik003cc3d2015-10-16 10:24:55 -0700959 (mDisplayList->getOps()[mDisplayList->projectionReceiveIndex]);
Chris Craik10ed6922015-10-15 10:55:15 -0700960#endif
Chris Craikb3cca872014-08-08 18:42:51 -0700961 const DrawRenderNodeOp* backgroundOp = reinterpret_cast<const DrawRenderNodeOp*>(op);
Chris Craikb565df12015-10-05 13:00:52 -0700962 const RenderProperties& backgroundProps = backgroundOp->renderNode->properties();
Chris Craikb3cca872014-08-08 18:42:51 -0700963 renderer.translate(backgroundProps.getTranslationX(), backgroundProps.getTranslationY());
964
Chris Craik6fe991e52015-10-20 09:39:42 -0700965 // If the projection receiver has an outline, we mask projected content to it
Chris Craikfca52b752015-04-28 11:45:59 -0700966 // (which we know, apriori, are all tessellated paths)
967 renderer.setProjectionPathMask(alloc, projectionReceiverOutline);
Chris Craik3f0854292014-04-15 16:18:08 -0700968
969 // draw projected nodes
John Reck113e0822014-03-18 09:22:59 -0700970 for (size_t i = 0; i < mProjectedNodes.size(); i++) {
Chris Craik8d1f2122015-11-24 16:40:09 -0800971 renderNodeOp_t* childOp = mProjectedNodes[i];
John Reck113e0822014-03-18 09:22:59 -0700972
973 // matrix save, concat, and restore can be done safely without allocating operations
Florin Malitaeecff562015-12-21 10:43:01 -0500974 int restoreTo = renderer.save(SaveFlags::Matrix);
Chris Craik8d1f2122015-11-24 16:40:09 -0800975 renderer.concatMatrix(childOp->transformFromCompositingAncestor);
976 childOp->skipInOrderDraw = false; // this is horrible, I'm so sorry everyone
John Reckd0a0b2a2014-03-20 16:28:56 -0700977 handler(childOp, renderer.getSaveCount() - 1, properties().getClipToBounds());
Chris Craik8d1f2122015-11-24 16:40:09 -0800978 childOp->skipInOrderDraw = true;
John Reck113e0822014-03-18 09:22:59 -0700979 renderer.restoreToCount(restoreTo);
980 }
Chris Craik3f0854292014-04-15 16:18:08 -0700981
Chris Craikfca52b752015-04-28 11:45:59 -0700982 handler(new (alloc) RestoreToCountOp(restoreTo),
983 PROPERTY_SAVECOUNT, properties().getClipToBounds());
John Reck113e0822014-03-18 09:22:59 -0700984}
985
986/**
987 * This function serves both defer and replay modes, and will organize the displayList's component
988 * operations for a single frame:
989 *
990 * Every 'simple' state operation that affects just the matrix and alpha (or other factors of
991 * DeferredDisplayState) may be issued directly to the renderer, but complex operations (with custom
992 * defer logic) and operations in displayListOps are issued through the 'handler' which handles the
993 * defer vs replay logic, per operation
994 */
995template <class T>
Chris Craikb265e2c2014-03-27 15:50:09 -0700996void RenderNode::issueOperations(OpenGLRenderer& renderer, T& handler) {
Chris Craik003cc3d2015-10-16 10:24:55 -0700997 if (mDisplayList->isEmpty()) {
Chris Craikbf72eb82015-06-08 11:30:44 -0700998 DISPLAY_LIST_LOGD("%*sEmpty display list (%p, %s)", handler.level() * 2, "",
999 this, getName());
Chris Craik06451282014-07-21 10:25:54 -07001000 return;
1001 }
1002
Chris Craik0b7e8242015-10-28 16:50:44 -07001003#if HWUI_NEW_OPS
1004 const bool drawLayer = false;
1005#else
Chris Craik51d6a3d2014-12-22 17:16:56 -08001006 const bool drawLayer = (mLayer && (&renderer != mLayer->renderer.get()));
Chris Craik0b7e8242015-10-28 16:50:44 -07001007#endif
John Reck25fbb3f2014-06-12 13:46:45 -07001008 // If we are updating the contents of mLayer, we don't want to apply any of
1009 // the RenderNode's properties to this issueOperations pass. Those will all
1010 // be applied when the layer is drawn, aka when this is true.
1011 const bool useViewProperties = (!mLayer || drawLayer);
Chris Craik06451282014-07-21 10:25:54 -07001012 if (useViewProperties) {
1013 const Outline& outline = properties().getOutline();
Teng-Hui Zhu8d0ec382015-10-01 16:49:16 -07001014 if (properties().getAlpha() <= 0
1015 || (outline.getShouldClip() && outline.isEmpty())
1016 || properties().getScaleX() == 0
1017 || properties().getScaleY() == 0) {
Chris Craikbf72eb82015-06-08 11:30:44 -07001018 DISPLAY_LIST_LOGD("%*sRejected display list (%p, %s)", handler.level() * 2, "",
1019 this, getName());
Chris Craik06451282014-07-21 10:25:54 -07001020 return;
1021 }
John Reck113e0822014-03-18 09:22:59 -07001022 }
1023
Chris Craik3f0854292014-04-15 16:18:08 -07001024 handler.startMark(getName());
Chris Craikb265e2c2014-03-27 15:50:09 -07001025
John Reck113e0822014-03-18 09:22:59 -07001026#if DEBUG_DISPLAY_LIST
Chris Craik3f0854292014-04-15 16:18:08 -07001027 const Rect& clipRect = renderer.getLocalClipBounds();
1028 DISPLAY_LIST_LOGD("%*sStart display list (%p, %s), localClipBounds: %.0f, %.0f, %.0f, %.0f",
Chris Craik03188872015-02-02 18:39:33 -08001029 handler.level() * 2, "", this, getName(),
Chris Craik3f0854292014-04-15 16:18:08 -07001030 clipRect.left, clipRect.top, clipRect.right, clipRect.bottom);
John Reck113e0822014-03-18 09:22:59 -07001031#endif
1032
1033 LinearAllocator& alloc = handler.allocator();
1034 int restoreTo = renderer.getSaveCount();
Florin Malitaeecff562015-12-21 10:43:01 -05001035 handler(new (alloc) SaveOp(SaveFlags::MatrixClip),
John Reckd0a0b2a2014-03-20 16:28:56 -07001036 PROPERTY_SAVECOUNT, properties().getClipToBounds());
John Reck113e0822014-03-18 09:22:59 -07001037
Chris Craikbf72eb82015-06-08 11:30:44 -07001038 DISPLAY_LIST_LOGD("%*sSave %d %d", (handler.level() + 1) * 2, "",
Florin Malitaeecff562015-12-21 10:43:01 -05001039 SaveFlags::MatrixClip, restoreTo);
John Reck113e0822014-03-18 09:22:59 -07001040
John Reck25fbb3f2014-06-12 13:46:45 -07001041 if (useViewProperties) {
1042 setViewProperties<T>(renderer, handler);
1043 }
John Reck113e0822014-03-18 09:22:59 -07001044
Chris Craik10ed6922015-10-15 10:55:15 -07001045#if HWUI_NEW_OPS
1046 LOG_ALWAYS_FATAL("legacy op traversal not supported");
1047#else
Chris Craik8c271ca2014-03-25 10:33:01 -07001048 bool quickRejected = properties().getClipToBounds()
1049 && renderer.quickRejectConservative(0, 0, properties().getWidth(), properties().getHeight());
John Reck113e0822014-03-18 09:22:59 -07001050 if (!quickRejected) {
Chris Craikc3e75f92014-08-27 15:34:52 -07001051 Matrix4 initialTransform(*(renderer.currentTransform()));
Tom Hudsonac7b6d32015-06-30 11:26:13 -04001052 renderer.setBaseTransform(initialTransform);
Chris Craikc3e75f92014-08-27 15:34:52 -07001053
John Reck25fbb3f2014-06-12 13:46:45 -07001054 if (drawLayer) {
Chris Craik3aadd602015-08-20 12:41:40 -07001055 handler(new (alloc) DrawLayerOp(mLayer),
John Reck25fbb3f2014-06-12 13:46:45 -07001056 renderer.getSaveCount() - 1, properties().getClipToBounds());
1057 } else {
Chris Craikc166b6c2014-09-05 19:55:30 -07001058 const int saveCountOffset = renderer.getSaveCount() - 1;
Chris Craik003cc3d2015-10-16 10:24:55 -07001059 const int projectionReceiveIndex = mDisplayList->projectionReceiveIndex;
1060 for (size_t chunkIndex = 0; chunkIndex < mDisplayList->getChunks().size(); chunkIndex++) {
1061 const DisplayList::Chunk& chunk = mDisplayList->getChunks()[chunkIndex];
John Reck113e0822014-03-18 09:22:59 -07001062
John Reck272a6852015-07-29 16:48:58 -07001063 std::vector<ZDrawRenderNodeOpPair> zTranslatedNodes;
Chris Craik8afd0f22014-08-21 17:41:57 -07001064 buildZSortedChildList(chunk, zTranslatedNodes);
1065
Chris Craikb9ce116d2015-08-20 15:14:06 -07001066 issueOperationsOf3dChildren(ChildrenSelectMode::NegativeZChildren,
Chris Craikc3e75f92014-08-27 15:34:52 -07001067 initialTransform, zTranslatedNodes, renderer, handler);
1068
Andreas Gampeedaecc12014-11-10 20:54:07 -08001069 for (size_t opIndex = chunk.beginOpIndex; opIndex < chunk.endOpIndex; opIndex++) {
Chris Craik003cc3d2015-10-16 10:24:55 -07001070 DisplayListOp *op = mDisplayList->getOps()[opIndex];
Chris Craik80d49022014-06-20 15:03:43 -07001071#if DEBUG_DISPLAY_LIST
Chris Craik03188872015-02-02 18:39:33 -08001072 op->output(handler.level() + 1);
Chris Craik80d49022014-06-20 15:03:43 -07001073#endif
Chris Craik8afd0f22014-08-21 17:41:57 -07001074 handler(op, saveCountOffset, properties().getClipToBounds());
John Reck113e0822014-03-18 09:22:59 -07001075
John Reck272a6852015-07-29 16:48:58 -07001076 if (CC_UNLIKELY(!mProjectedNodes.empty() && projectionReceiveIndex >= 0 &&
Andreas Gampeedaecc12014-11-10 20:54:07 -08001077 opIndex == static_cast<size_t>(projectionReceiveIndex))) {
Chris Craik8afd0f22014-08-21 17:41:57 -07001078 issueOperationsOfProjectedChildren(renderer, handler);
1079 }
John Reck25fbb3f2014-06-12 13:46:45 -07001080 }
John Reck113e0822014-03-18 09:22:59 -07001081
Chris Craikb9ce116d2015-08-20 15:14:06 -07001082 issueOperationsOf3dChildren(ChildrenSelectMode::PositiveZChildren,
Chris Craikc3e75f92014-08-27 15:34:52 -07001083 initialTransform, zTranslatedNodes, renderer, handler);
Chris Craik8afd0f22014-08-21 17:41:57 -07001084 }
John Reck25fbb3f2014-06-12 13:46:45 -07001085 }
John Reck113e0822014-03-18 09:22:59 -07001086 }
Chris Craik10ed6922015-10-15 10:55:15 -07001087#endif
John Reck113e0822014-03-18 09:22:59 -07001088
Chris Craikbf72eb82015-06-08 11:30:44 -07001089 DISPLAY_LIST_LOGD("%*sRestoreToCount %d", (handler.level() + 1) * 2, "", restoreTo);
John Reck113e0822014-03-18 09:22:59 -07001090 handler(new (alloc) RestoreToCountOp(restoreTo),
John Reckd0a0b2a2014-03-20 16:28:56 -07001091 PROPERTY_SAVECOUNT, properties().getClipToBounds());
Chris Craikb265e2c2014-03-27 15:50:09 -07001092
Chris Craikbf72eb82015-06-08 11:30:44 -07001093 DISPLAY_LIST_LOGD("%*sDone (%p, %s)", handler.level() * 2, "", this, getName());
Chris Craikb265e2c2014-03-27 15:50:09 -07001094 handler.endMark();
John Reck113e0822014-03-18 09:22:59 -07001095}
1096
1097} /* namespace uirenderer */
1098} /* namespace android */