blob: 3d93383e2c492c199e4cbf47804994ef4fabc320 [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
17#define ATRACE_TAG ATRACE_TAG_VIEW
John Recka447d292014-06-11 18:39:44 -070018#define LOG_TAG "RenderNode"
John Reck113e0822014-03-18 09:22:59 -070019
20#include "RenderNode.h"
21
John Recke45b1fd2014-04-15 09:50:16 -070022#include <algorithm>
John Reckc25e5062014-06-18 14:21:29 -070023#include <string>
John Recke45b1fd2014-04-15 09:50:16 -070024
John Reck113e0822014-03-18 09:22:59 -070025#include <SkCanvas.h>
26#include <algorithm>
27
28#include <utils/Trace.h>
29
John Recke4267ea2014-06-03 15:53:15 -070030#include "DamageAccumulator.h"
John Reck113e0822014-03-18 09:22:59 -070031#include "Debug.h"
32#include "DisplayListOp.h"
33#include "DisplayListLogBuffer.h"
John Reck25fbb3f2014-06-12 13:46:45 -070034#include "LayerRenderer.h"
35#include "OpenGLRenderer.h"
Chris Craike0bb87d2014-04-22 17:55:41 -070036#include "utils/MathUtils.h"
John Reck113e0822014-03-18 09:22:59 -070037
38namespace android {
39namespace uirenderer {
40
41void RenderNode::outputLogBuffer(int fd) {
42 DisplayListLogBuffer& logBuffer = DisplayListLogBuffer::getInstance();
43 if (logBuffer.isEmpty()) {
44 return;
45 }
46
47 FILE *file = fdopen(fd, "a");
48
49 fprintf(file, "\nRecent DisplayList operations\n");
50 logBuffer.outputCommands(file);
51
52 String8 cachesLog;
53 Caches::getInstance().dumpMemoryUsage(cachesLog);
54 fprintf(file, "\nCaches:\n%s", cachesLog.string());
55 fprintf(file, "\n");
56
57 fflush(file);
58}
59
John Reck8de65a82014-04-09 15:23:38 -070060RenderNode::RenderNode()
John Reckff941dc2014-05-14 16:34:14 -070061 : mDirtyPropertyFields(0)
John Reck8de65a82014-04-09 15:23:38 -070062 , mNeedsDisplayListDataSync(false)
63 , mDisplayListData(0)
John Recke45b1fd2014-04-15 09:50:16 -070064 , mStagingDisplayListData(0)
John Reck25fbb3f2014-06-12 13:46:45 -070065 , mNeedsAnimatorsSync(false)
66 , mLayer(0) {
John Reck113e0822014-03-18 09:22:59 -070067}
68
69RenderNode::~RenderNode() {
John Reck113e0822014-03-18 09:22:59 -070070 delete mDisplayListData;
John Reck8de65a82014-04-09 15:23:38 -070071 delete mStagingDisplayListData;
John Reck25fbb3f2014-06-12 13:46:45 -070072 LayerRenderer::destroyLayerDeferred(mLayer);
John Reck113e0822014-03-18 09:22:59 -070073}
74
John Reck8de65a82014-04-09 15:23:38 -070075void RenderNode::setStagingDisplayList(DisplayListData* data) {
76 mNeedsDisplayListDataSync = true;
77 delete mStagingDisplayListData;
78 mStagingDisplayListData = data;
79 if (mStagingDisplayListData) {
80 Caches::getInstance().registerFunctors(mStagingDisplayListData->functorCount);
John Reck113e0822014-03-18 09:22:59 -070081 }
82}
83
84/**
85 * This function is a simplified version of replay(), where we simply retrieve and log the
86 * display list. This function should remain in sync with the replay() function.
87 */
88void RenderNode::output(uint32_t level) {
89 ALOGD("%*sStart display list (%p, %s, render=%d)", (level - 1) * 2, "", this,
Chris Craik3f0854292014-04-15 16:18:08 -070090 getName(), isRenderable());
John Reck113e0822014-03-18 09:22:59 -070091 ALOGD("%*s%s %d", level * 2, "", "Save",
92 SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag);
93
John Reckd0a0b2a2014-03-20 16:28:56 -070094 properties().debugOutputProperties(level);
John Reck113e0822014-03-18 09:22:59 -070095 int flags = DisplayListOp::kOpLogFlag_Recurse;
96 for (unsigned int i = 0; i < mDisplayListData->displayListOps.size(); i++) {
97 mDisplayListData->displayListOps[i]->output(level, flags);
98 }
99
Chris Craik3f0854292014-04-15 16:18:08 -0700100 ALOGD("%*sDone (%p, %s)", (level - 1) * 2, "", this, getName());
John Reck113e0822014-03-18 09:22:59 -0700101}
102
John Reckfe5e7b72014-05-23 17:42:28 -0700103int RenderNode::getDebugSize() {
104 int size = sizeof(RenderNode);
105 if (mStagingDisplayListData) {
106 size += mStagingDisplayListData->allocator.usedSize();
107 }
108 if (mDisplayListData && mDisplayListData != mStagingDisplayListData) {
109 size += mDisplayListData->allocator.usedSize();
110 }
111 return size;
112}
113
John Reckf4198b72014-04-09 17:00:04 -0700114void RenderNode::prepareTree(TreeInfo& info) {
115 ATRACE_CALL();
116
117 prepareTreeImpl(info);
118}
119
John Recke4267ea2014-06-03 15:53:15 -0700120void RenderNode::damageSelf(TreeInfo& info) {
John Reckce9f3082014-06-17 16:18:09 -0700121 if (isRenderable()) {
John Reck293e8682014-06-17 10:34:02 -0700122 if (properties().getClipDamageToBounds()) {
John Recka447d292014-06-11 18:39:44 -0700123 info.damageAccumulator->dirty(0, 0, properties().getWidth(), properties().getHeight());
124 } else {
125 // Hope this is big enough?
126 // TODO: Get this from the display list ops or something
127 info.damageAccumulator->dirty(INT_MIN, INT_MIN, INT_MAX, INT_MAX);
128 }
John Recke4267ea2014-06-03 15:53:15 -0700129 }
130}
131
John Reck25fbb3f2014-06-12 13:46:45 -0700132void RenderNode::prepareLayer(TreeInfo& info) {
133 LayerType layerType = properties().layerProperties().type();
134 if (CC_UNLIKELY(layerType == kLayerTypeRenderLayer)) {
135 // We push a null transform here as we don't care what the existing dirty
136 // area is, only what our display list dirty is as well as our children's
137 // dirty area
138 info.damageAccumulator->pushNullTransform();
139 }
140}
141
142void RenderNode::pushLayerUpdate(TreeInfo& info) {
143 LayerType layerType = properties().layerProperties().type();
144 // If we are not a layer OR we cannot be rendered (eg, view was detached)
145 // we need to destroy any Layers we may have had previously
146 if (CC_LIKELY(layerType != kLayerTypeRenderLayer) || CC_UNLIKELY(!isRenderable())) {
147 if (layerType == kLayerTypeRenderLayer) {
148 info.damageAccumulator->popTransform();
149 }
150 if (CC_UNLIKELY(mLayer)) {
151 LayerRenderer::destroyLayer(mLayer);
152 mLayer = NULL;
153 }
154 return;
155 }
156
157 if (!mLayer) {
158 mLayer = LayerRenderer::createRenderLayer(getWidth(), getHeight());
159 applyLayerPropertiesToLayer(info);
160 damageSelf(info);
161 } else if (mLayer->layer.getWidth() != getWidth() || mLayer->layer.getHeight() != getHeight()) {
John Reckc25e5062014-06-18 14:21:29 -0700162 if (!LayerRenderer::resizeLayer(mLayer, getWidth(), getHeight())) {
163 LayerRenderer::destroyLayer(mLayer);
164 mLayer = 0;
165 }
John Reck25fbb3f2014-06-12 13:46:45 -0700166 damageSelf(info);
167 }
168
169 SkRect dirty;
170 info.damageAccumulator->peekAtDirty(&dirty);
171 info.damageAccumulator->popTransform();
172
John Reckc25e5062014-06-18 14:21:29 -0700173 if (!mLayer) {
174 if (info.errorHandler) {
175 std::string msg = "Unable to create layer for ";
176 msg += getName();
177 info.errorHandler->onError(msg);
178 }
179 return;
180 }
181
John Reck25fbb3f2014-06-12 13:46:45 -0700182 if (!dirty.isEmpty()) {
183 mLayer->updateDeferred(this, dirty.fLeft, dirty.fTop, dirty.fRight, dirty.fBottom);
184 }
185 // This is not inside the above if because we may have called
186 // updateDeferred on a previous prepare pass that didn't have a renderer
187 if (info.renderer && mLayer->deferredUpdateScheduled) {
188 info.renderer->pushLayerUpdate(mLayer);
189 }
190}
191
John Recke4267ea2014-06-03 15:53:15 -0700192void RenderNode::prepareTreeImpl(TreeInfo& info) {
John Recka447d292014-06-11 18:39:44 -0700193 info.damageAccumulator->pushTransform(this);
John Recke4267ea2014-06-03 15:53:15 -0700194 if (info.mode == TreeInfo::MODE_FULL) {
John Reck25fbb3f2014-06-12 13:46:45 -0700195 pushStagingPropertiesChanges(info);
John Recke4267ea2014-06-03 15:53:15 -0700196 evaluateAnimations(info);
197 } else if (info.mode == TreeInfo::MODE_MAYBE_DETACHING) {
John Reck25fbb3f2014-06-12 13:46:45 -0700198 pushStagingPropertiesChanges(info);
John Recke4267ea2014-06-03 15:53:15 -0700199 } else if (info.mode == TreeInfo::MODE_RT_ONLY) {
John Recke45b1fd2014-04-15 09:50:16 -0700200 evaluateAnimations(info);
201 }
John Reck25fbb3f2014-06-12 13:46:45 -0700202
203 prepareLayer(info);
204 if (info.mode == TreeInfo::MODE_FULL) {
205 pushStagingDisplayListChanges(info);
206 }
John Reckf4198b72014-04-09 17:00:04 -0700207 prepareSubTree(info, mDisplayListData);
John Reck25fbb3f2014-06-12 13:46:45 -0700208 pushLayerUpdate(info);
209
John Recka447d292014-06-11 18:39:44 -0700210 info.damageAccumulator->popTransform();
John Reckf4198b72014-04-09 17:00:04 -0700211}
212
John Reckff941dc2014-05-14 16:34:14 -0700213class PushAnimatorsFunctor {
214public:
215 PushAnimatorsFunctor(RenderNode* target, TreeInfo& info)
216 : mTarget(target), mInfo(info) {}
217
218 bool operator() (const sp<BaseRenderNodeAnimator>& animator) {
219 animator->setupStartValueIfNecessary(mTarget, mInfo);
220 return animator->isFinished();
221 }
222private:
223 RenderNode* mTarget;
224 TreeInfo& mInfo;
225};
John Recke45b1fd2014-04-15 09:50:16 -0700226
John Reck25fbb3f2014-06-12 13:46:45 -0700227void RenderNode::pushStagingPropertiesChanges(TreeInfo& info) {
John Reckff941dc2014-05-14 16:34:14 -0700228 // Push the animators first so that setupStartValueIfNecessary() is called
229 // before properties() is trampled by stagingProperties(), as they are
230 // required by some animators.
John Recke45b1fd2014-04-15 09:50:16 -0700231 if (mNeedsAnimatorsSync) {
John Reck52622662014-04-30 14:19:56 -0700232 mAnimators.resize(mStagingAnimators.size());
John Reck52244ff2014-05-01 21:27:37 -0700233 std::vector< sp<BaseRenderNodeAnimator> >::iterator it;
John Reckff941dc2014-05-14 16:34:14 -0700234 PushAnimatorsFunctor functor(this, info);
John Recke45b1fd2014-04-15 09:50:16 -0700235 // hint: this means copy_if_not()
236 it = std::remove_copy_if(mStagingAnimators.begin(), mStagingAnimators.end(),
John Reckff941dc2014-05-14 16:34:14 -0700237 mAnimators.begin(), functor);
John Recke45b1fd2014-04-15 09:50:16 -0700238 mAnimators.resize(std::distance(mAnimators.begin(), it));
239 }
John Reckff941dc2014-05-14 16:34:14 -0700240 if (mDirtyPropertyFields) {
241 mDirtyPropertyFields = 0;
John Recke4267ea2014-06-03 15:53:15 -0700242 damageSelf(info);
John Recka447d292014-06-11 18:39:44 -0700243 info.damageAccumulator->popTransform();
John Reckff941dc2014-05-14 16:34:14 -0700244 mProperties = mStagingProperties;
John Reck25fbb3f2014-06-12 13:46:45 -0700245 applyLayerPropertiesToLayer(info);
John Recke4267ea2014-06-03 15:53:15 -0700246 // We could try to be clever and only re-damage if the matrix changed.
247 // However, we don't need to worry about that. The cost of over-damaging
248 // here is only going to be a single additional map rect of this node
249 // plus a rect join(). The parent's transform (and up) will only be
250 // performed once.
John Recka447d292014-06-11 18:39:44 -0700251 info.damageAccumulator->pushTransform(this);
John Recke4267ea2014-06-03 15:53:15 -0700252 damageSelf(info);
John Reckff941dc2014-05-14 16:34:14 -0700253 }
John Reck25fbb3f2014-06-12 13:46:45 -0700254}
255
256void RenderNode::applyLayerPropertiesToLayer(TreeInfo& info) {
257 if (CC_LIKELY(!mLayer)) return;
258
259 const LayerProperties& props = properties().layerProperties();
260 mLayer->setAlpha(props.alpha(), props.xferMode());
261 mLayer->setColorFilter(props.colorFilter());
262 mLayer->setBlend(props.needsBlending());
263}
264
265void RenderNode::pushStagingDisplayListChanges(TreeInfo& info) {
John Reck8de65a82014-04-09 15:23:38 -0700266 if (mNeedsDisplayListDataSync) {
267 mNeedsDisplayListDataSync = false;
268 // Do a push pass on the old tree to handle freeing DisplayListData
269 // that are no longer used
John Recke4267ea2014-06-03 15:53:15 -0700270 TreeInfo oldTreeInfo(TreeInfo::MODE_MAYBE_DETACHING);
271 oldTreeInfo.damageAccumulator = info.damageAccumulator;
John Reckf4198b72014-04-09 17:00:04 -0700272 prepareSubTree(oldTreeInfo, mDisplayListData);
John Reck8de65a82014-04-09 15:23:38 -0700273 delete mDisplayListData;
274 mDisplayListData = mStagingDisplayListData;
275 mStagingDisplayListData = 0;
John Recke4267ea2014-06-03 15:53:15 -0700276 damageSelf(info);
John Reck8de65a82014-04-09 15:23:38 -0700277 }
John Reck8de65a82014-04-09 15:23:38 -0700278}
279
John Recke45b1fd2014-04-15 09:50:16 -0700280class AnimateFunctor {
281public:
John Reck52244ff2014-05-01 21:27:37 -0700282 AnimateFunctor(RenderNode* target, TreeInfo& info)
John Recke45b1fd2014-04-15 09:50:16 -0700283 : mTarget(target), mInfo(info) {}
284
John Reckff941dc2014-05-14 16:34:14 -0700285 bool operator() (const sp<BaseRenderNodeAnimator>& animator) {
John Reck52244ff2014-05-01 21:27:37 -0700286 return animator->animate(mTarget, mInfo);
John Recke45b1fd2014-04-15 09:50:16 -0700287 }
288private:
John Reck52244ff2014-05-01 21:27:37 -0700289 RenderNode* mTarget;
John Recke45b1fd2014-04-15 09:50:16 -0700290 TreeInfo& mInfo;
291};
292
293void RenderNode::evaluateAnimations(TreeInfo& info) {
294 if (!mAnimators.size()) return;
295
John Recke4267ea2014-06-03 15:53:15 -0700296 // TODO: Can we target this better? For now treat it like any other staging
297 // property push and just damage self before and after animators are run
298
299 damageSelf(info);
John Recka447d292014-06-11 18:39:44 -0700300 info.damageAccumulator->popTransform();
John Recke4267ea2014-06-03 15:53:15 -0700301
John Reck52244ff2014-05-01 21:27:37 -0700302 AnimateFunctor functor(this, info);
303 std::vector< sp<BaseRenderNodeAnimator> >::iterator newEnd;
John Recke45b1fd2014-04-15 09:50:16 -0700304 newEnd = std::remove_if(mAnimators.begin(), mAnimators.end(), functor);
305 mAnimators.erase(newEnd, mAnimators.end());
306 mProperties.updateMatrix();
John Reckf9be7792014-05-02 18:21:16 -0700307 info.out.hasAnimations |= mAnimators.size();
John Recke4267ea2014-06-03 15:53:15 -0700308
John Recka447d292014-06-11 18:39:44 -0700309 info.damageAccumulator->pushTransform(this);
John Recke4267ea2014-06-03 15:53:15 -0700310 damageSelf(info);
John Recke45b1fd2014-04-15 09:50:16 -0700311}
312
John Reckf4198b72014-04-09 17:00:04 -0700313void RenderNode::prepareSubTree(TreeInfo& info, DisplayListData* subtree) {
John Reck8de65a82014-04-09 15:23:38 -0700314 if (subtree) {
John Reck860d1552014-04-11 19:15:05 -0700315 TextureCache& cache = Caches::getInstance().textureCache;
John Reckf9be7792014-05-02 18:21:16 -0700316 info.out.hasFunctors |= subtree->functorCount;
John Reck860d1552014-04-11 19:15:05 -0700317 // TODO: Fix ownedBitmapResources to not require disabling prepareTextures
318 // and thus falling out of async drawing path.
319 if (subtree->ownedBitmapResources.size()) {
320 info.prepareTextures = false;
321 }
322 for (size_t i = 0; info.prepareTextures && i < subtree->bitmapResources.size(); i++) {
323 info.prepareTextures = cache.prefetchAndMarkInUse(subtree->bitmapResources[i]);
John Reckf4198b72014-04-09 17:00:04 -0700324 }
John Reck8de65a82014-04-09 15:23:38 -0700325 for (size_t i = 0; i < subtree->children().size(); i++) {
John Recka447d292014-06-11 18:39:44 -0700326 DrawDisplayListOp* op = subtree->children()[i];
327 RenderNode* childNode = op->mDisplayList;
328 info.damageAccumulator->pushTransform(&op->mTransformFromParent);
John Reckf4198b72014-04-09 17:00:04 -0700329 childNode->prepareTreeImpl(info);
John Recka447d292014-06-11 18:39:44 -0700330 info.damageAccumulator->popTransform();
John Reck5bf11bb2014-03-25 10:22:09 -0700331 }
John Reck113e0822014-03-18 09:22:59 -0700332 }
333}
334
335/*
336 * For property operations, we pass a savecount of 0, since the operations aren't part of the
337 * displaylist, and thus don't have to compensate for the record-time/playback-time discrepancy in
John Reckd0a0b2a2014-03-20 16:28:56 -0700338 * base saveCount (i.e., how RestoreToCount uses saveCount + properties().getCount())
John Reck113e0822014-03-18 09:22:59 -0700339 */
340#define PROPERTY_SAVECOUNT 0
341
342template <class T>
Chris Craikb265e2c2014-03-27 15:50:09 -0700343void RenderNode::setViewProperties(OpenGLRenderer& renderer, T& handler) {
John Reck113e0822014-03-18 09:22:59 -0700344#if DEBUG_DISPLAY_LIST
Chris Craikb265e2c2014-03-27 15:50:09 -0700345 properties().debugOutputProperties(handler.level() + 1);
John Reck113e0822014-03-18 09:22:59 -0700346#endif
John Reckd0a0b2a2014-03-20 16:28:56 -0700347 if (properties().getLeft() != 0 || properties().getTop() != 0) {
348 renderer.translate(properties().getLeft(), properties().getTop());
John Reck113e0822014-03-18 09:22:59 -0700349 }
John Reckd0a0b2a2014-03-20 16:28:56 -0700350 if (properties().getStaticMatrix()) {
Derek Sollenberger13908822013-12-10 12:28:58 -0500351 renderer.concatMatrix(*properties().getStaticMatrix());
John Reckd0a0b2a2014-03-20 16:28:56 -0700352 } else if (properties().getAnimationMatrix()) {
Derek Sollenberger13908822013-12-10 12:28:58 -0500353 renderer.concatMatrix(*properties().getAnimationMatrix());
John Reck113e0822014-03-18 09:22:59 -0700354 }
John Reckf7483e32014-04-11 08:54:47 -0700355 if (properties().hasTransformMatrix()) {
356 if (properties().isTransformTranslateOnly()) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700357 renderer.translate(properties().getTranslationX(), properties().getTranslationY());
John Reck113e0822014-03-18 09:22:59 -0700358 } else {
John Reckd0a0b2a2014-03-20 16:28:56 -0700359 renderer.concatMatrix(*properties().getTransformMatrix());
John Reck113e0822014-03-18 09:22:59 -0700360 }
361 }
John Reck25fbb3f2014-06-12 13:46:45 -0700362 const bool isLayer = properties().layerProperties().type() != kLayerTypeNone;
363 bool clipToBoundsNeeded = isLayer ? false : properties().getClipToBounds();
John Reckd0a0b2a2014-03-20 16:28:56 -0700364 if (properties().getAlpha() < 1) {
John Reck25fbb3f2014-06-12 13:46:45 -0700365 if (isLayer) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700366 renderer.setOverrideLayerAlpha(properties().getAlpha());
367 } else if (!properties().getHasOverlappingRendering()) {
368 renderer.scaleAlpha(properties().getAlpha());
John Reck113e0822014-03-18 09:22:59 -0700369 } else {
370 // TODO: should be able to store the size of a DL at record time and not
371 // have to pass it into this call. In fact, this information might be in the
372 // location/size info that we store with the new native transform data.
373 int saveFlags = SkCanvas::kHasAlphaLayer_SaveFlag;
374 if (clipToBoundsNeeded) {
375 saveFlags |= SkCanvas::kClipToLayer_SaveFlag;
376 clipToBoundsNeeded = false; // clipping done by saveLayer
377 }
378
379 SaveLayerOp* op = new (handler.allocator()) SaveLayerOp(
Chris Craik8c271ca2014-03-25 10:33:01 -0700380 0, 0, properties().getWidth(), properties().getHeight(),
381 properties().getAlpha() * 255, saveFlags);
John Reckd0a0b2a2014-03-20 16:28:56 -0700382 handler(op, PROPERTY_SAVECOUNT, properties().getClipToBounds());
John Reck113e0822014-03-18 09:22:59 -0700383 }
384 }
385 if (clipToBoundsNeeded) {
Chris Craik8c271ca2014-03-25 10:33:01 -0700386 ClipRectOp* op = new (handler.allocator()) ClipRectOp(
387 0, 0, properties().getWidth(), properties().getHeight(), SkRegion::kIntersect_Op);
John Reckd0a0b2a2014-03-20 16:28:56 -0700388 handler(op, PROPERTY_SAVECOUNT, properties().getClipToBounds());
John Reck113e0822014-03-18 09:22:59 -0700389 }
Chris Craik8c271ca2014-03-25 10:33:01 -0700390
391 if (CC_UNLIKELY(properties().hasClippingPath())) {
Chris Craik2bcad172014-05-14 18:11:23 -0700392 ClipPathOp* op = new (handler.allocator()) ClipPathOp(
393 properties().getClippingPath(), properties().getClippingPathOp());
John Reckd0a0b2a2014-03-20 16:28:56 -0700394 handler(op, PROPERTY_SAVECOUNT, properties().getClipToBounds());
John Reck113e0822014-03-18 09:22:59 -0700395 }
396}
397
398/**
399 * Apply property-based transformations to input matrix
400 *
401 * If true3dTransform is set to true, the transform applied to the input matrix will use true 4x4
402 * matrix computation instead of the Skia 3x3 matrix + camera hackery.
403 */
404void RenderNode::applyViewPropertyTransforms(mat4& matrix, bool true3dTransform) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700405 if (properties().getLeft() != 0 || properties().getTop() != 0) {
406 matrix.translate(properties().getLeft(), properties().getTop());
John Reck113e0822014-03-18 09:22:59 -0700407 }
John Reckd0a0b2a2014-03-20 16:28:56 -0700408 if (properties().getStaticMatrix()) {
409 mat4 stat(*properties().getStaticMatrix());
John Reck113e0822014-03-18 09:22:59 -0700410 matrix.multiply(stat);
John Reckd0a0b2a2014-03-20 16:28:56 -0700411 } else if (properties().getAnimationMatrix()) {
412 mat4 anim(*properties().getAnimationMatrix());
John Reck113e0822014-03-18 09:22:59 -0700413 matrix.multiply(anim);
414 }
Chris Craike0bb87d2014-04-22 17:55:41 -0700415
Chris Craikcc39e162014-04-25 18:34:11 -0700416 bool applyTranslationZ = true3dTransform && !MathUtils::isZero(properties().getZ());
Chris Craike0bb87d2014-04-22 17:55:41 -0700417 if (properties().hasTransformMatrix() || applyTranslationZ) {
John Reckf7483e32014-04-11 08:54:47 -0700418 if (properties().isTransformTranslateOnly()) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700419 matrix.translate(properties().getTranslationX(), properties().getTranslationY(),
Chris Craikcc39e162014-04-25 18:34:11 -0700420 true3dTransform ? properties().getZ() : 0.0f);
John Reck113e0822014-03-18 09:22:59 -0700421 } else {
422 if (!true3dTransform) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700423 matrix.multiply(*properties().getTransformMatrix());
John Reck113e0822014-03-18 09:22:59 -0700424 } else {
425 mat4 true3dMat;
426 true3dMat.loadTranslate(
John Reckd0a0b2a2014-03-20 16:28:56 -0700427 properties().getPivotX() + properties().getTranslationX(),
428 properties().getPivotY() + properties().getTranslationY(),
Chris Craikcc39e162014-04-25 18:34:11 -0700429 properties().getZ());
John Reckd0a0b2a2014-03-20 16:28:56 -0700430 true3dMat.rotate(properties().getRotationX(), 1, 0, 0);
431 true3dMat.rotate(properties().getRotationY(), 0, 1, 0);
432 true3dMat.rotate(properties().getRotation(), 0, 0, 1);
433 true3dMat.scale(properties().getScaleX(), properties().getScaleY(), 1);
434 true3dMat.translate(-properties().getPivotX(), -properties().getPivotY());
John Reck113e0822014-03-18 09:22:59 -0700435
436 matrix.multiply(true3dMat);
437 }
438 }
439 }
440}
441
442/**
443 * Organizes the DisplayList hierarchy to prepare for background projection reordering.
444 *
445 * This should be called before a call to defer() or drawDisplayList()
446 *
447 * Each DisplayList that serves as a 3d root builds its list of composited children,
448 * which are flagged to not draw in the standard draw loop.
449 */
450void RenderNode::computeOrdering() {
451 ATRACE_CALL();
452 mProjectedNodes.clear();
453
454 // TODO: create temporary DDLOp and call computeOrderingImpl on top DisplayList so that
455 // transform properties are applied correctly to top level children
456 if (mDisplayListData == NULL) return;
John Reck087bc0c2014-04-04 16:20:08 -0700457 for (unsigned int i = 0; i < mDisplayListData->children().size(); i++) {
458 DrawDisplayListOp* childOp = mDisplayListData->children()[i];
John Reck113e0822014-03-18 09:22:59 -0700459 childOp->mDisplayList->computeOrderingImpl(childOp,
Chris Craik3f0854292014-04-15 16:18:08 -0700460 properties().getOutline().getPath(), &mProjectedNodes, &mat4::identity());
John Reck113e0822014-03-18 09:22:59 -0700461 }
462}
463
464void RenderNode::computeOrderingImpl(
465 DrawDisplayListOp* opState,
Chris Craik3f0854292014-04-15 16:18:08 -0700466 const SkPath* outlineOfProjectionSurface,
John Reck113e0822014-03-18 09:22:59 -0700467 Vector<DrawDisplayListOp*>* compositedChildrenOfProjectionSurface,
468 const mat4* transformFromProjectionSurface) {
469 mProjectedNodes.clear();
470 if (mDisplayListData == NULL || mDisplayListData->isEmpty()) return;
471
472 // TODO: should avoid this calculation in most cases
473 // TODO: just calculate single matrix, down to all leaf composited elements
474 Matrix4 localTransformFromProjectionSurface(*transformFromProjectionSurface);
475 localTransformFromProjectionSurface.multiply(opState->mTransformFromParent);
476
John Reckd0a0b2a2014-03-20 16:28:56 -0700477 if (properties().getProjectBackwards()) {
John Reck113e0822014-03-18 09:22:59 -0700478 // composited projectee, flag for out of order draw, save matrix, and store in proj surface
479 opState->mSkipInOrderDraw = true;
480 opState->mTransformFromCompositingAncestor.load(localTransformFromProjectionSurface);
481 compositedChildrenOfProjectionSurface->add(opState);
482 } else {
483 // standard in order draw
484 opState->mSkipInOrderDraw = false;
485 }
486
John Reck087bc0c2014-04-04 16:20:08 -0700487 if (mDisplayListData->children().size() > 0) {
John Reck113e0822014-03-18 09:22:59 -0700488 const bool isProjectionReceiver = mDisplayListData->projectionReceiveIndex >= 0;
489 bool haveAppliedPropertiesToProjection = false;
John Reck087bc0c2014-04-04 16:20:08 -0700490 for (unsigned int i = 0; i < mDisplayListData->children().size(); i++) {
491 DrawDisplayListOp* childOp = mDisplayListData->children()[i];
John Reck113e0822014-03-18 09:22:59 -0700492 RenderNode* child = childOp->mDisplayList;
493
Chris Craik3f0854292014-04-15 16:18:08 -0700494 const SkPath* projectionOutline = NULL;
John Reck113e0822014-03-18 09:22:59 -0700495 Vector<DrawDisplayListOp*>* projectionChildren = NULL;
496 const mat4* projectionTransform = NULL;
John Reckd0a0b2a2014-03-20 16:28:56 -0700497 if (isProjectionReceiver && !child->properties().getProjectBackwards()) {
John Reck113e0822014-03-18 09:22:59 -0700498 // if receiving projections, collect projecting descendent
499
500 // Note that if a direct descendent is projecting backwards, we pass it's
501 // grandparent projection collection, since it shouldn't project onto it's
502 // parent, where it will already be drawing.
Chris Craik3f0854292014-04-15 16:18:08 -0700503 projectionOutline = properties().getOutline().getPath();
John Reck113e0822014-03-18 09:22:59 -0700504 projectionChildren = &mProjectedNodes;
505 projectionTransform = &mat4::identity();
506 } else {
507 if (!haveAppliedPropertiesToProjection) {
508 applyViewPropertyTransforms(localTransformFromProjectionSurface);
509 haveAppliedPropertiesToProjection = true;
510 }
Chris Craik3f0854292014-04-15 16:18:08 -0700511 projectionOutline = outlineOfProjectionSurface;
John Reck113e0822014-03-18 09:22:59 -0700512 projectionChildren = compositedChildrenOfProjectionSurface;
513 projectionTransform = &localTransformFromProjectionSurface;
514 }
Chris Craik3f0854292014-04-15 16:18:08 -0700515 child->computeOrderingImpl(childOp,
516 projectionOutline, projectionChildren, projectionTransform);
John Reck113e0822014-03-18 09:22:59 -0700517 }
518 }
John Reck113e0822014-03-18 09:22:59 -0700519}
520
521class DeferOperationHandler {
522public:
523 DeferOperationHandler(DeferStateStruct& deferStruct, int level)
524 : mDeferStruct(deferStruct), mLevel(level) {}
525 inline void operator()(DisplayListOp* operation, int saveCount, bool clipToBounds) {
526 operation->defer(mDeferStruct, saveCount, mLevel, clipToBounds);
527 }
528 inline LinearAllocator& allocator() { return *(mDeferStruct.mAllocator); }
Chris Craikb265e2c2014-03-27 15:50:09 -0700529 inline void startMark(const char* name) {} // do nothing
530 inline void endMark() {}
531 inline int level() { return mLevel; }
532 inline int replayFlags() { return mDeferStruct.mReplayFlags; }
John Reck113e0822014-03-18 09:22:59 -0700533
534private:
535 DeferStateStruct& mDeferStruct;
536 const int mLevel;
537};
538
Chris Craikb265e2c2014-03-27 15:50:09 -0700539void RenderNode::deferNodeTree(DeferStateStruct& deferStruct) {
540 DeferOperationHandler handler(deferStruct, 0);
Chris Craikcc39e162014-04-25 18:34:11 -0700541 if (MathUtils::isPositive(properties().getZ())) {
542 issueDrawShadowOperation(Matrix4::identity(), handler);
543 }
Chris Craikb265e2c2014-03-27 15:50:09 -0700544 issueOperations<DeferOperationHandler>(deferStruct.mRenderer, handler);
545}
546
547void RenderNode::deferNodeInParent(DeferStateStruct& deferStruct, const int level) {
John Reck113e0822014-03-18 09:22:59 -0700548 DeferOperationHandler handler(deferStruct, level);
Chris Craikb265e2c2014-03-27 15:50:09 -0700549 issueOperations<DeferOperationHandler>(deferStruct.mRenderer, handler);
John Reck113e0822014-03-18 09:22:59 -0700550}
551
552class ReplayOperationHandler {
553public:
554 ReplayOperationHandler(ReplayStateStruct& replayStruct, int level)
555 : mReplayStruct(replayStruct), mLevel(level) {}
556 inline void operator()(DisplayListOp* operation, int saveCount, bool clipToBounds) {
557#if DEBUG_DISPLAY_LIST_OPS_AS_EVENTS
Chris Craik3f0854292014-04-15 16:18:08 -0700558 mReplayStruct.mRenderer.eventMark(operation->name());
John Reck113e0822014-03-18 09:22:59 -0700559#endif
560 operation->replay(mReplayStruct, saveCount, mLevel, clipToBounds);
561 }
562 inline LinearAllocator& allocator() { return *(mReplayStruct.mAllocator); }
Chris Craikb265e2c2014-03-27 15:50:09 -0700563 inline void startMark(const char* name) {
564 mReplayStruct.mRenderer.startMark(name);
565 }
566 inline void endMark() {
567 mReplayStruct.mRenderer.endMark();
Chris Craikb265e2c2014-03-27 15:50:09 -0700568 }
569 inline int level() { return mLevel; }
570 inline int replayFlags() { return mReplayStruct.mReplayFlags; }
John Reck113e0822014-03-18 09:22:59 -0700571
572private:
573 ReplayStateStruct& mReplayStruct;
574 const int mLevel;
575};
576
Chris Craikb265e2c2014-03-27 15:50:09 -0700577void RenderNode::replayNodeTree(ReplayStateStruct& replayStruct) {
578 ReplayOperationHandler handler(replayStruct, 0);
Chris Craikcc39e162014-04-25 18:34:11 -0700579 if (MathUtils::isPositive(properties().getZ())) {
580 issueDrawShadowOperation(Matrix4::identity(), handler);
581 }
Chris Craikb265e2c2014-03-27 15:50:09 -0700582 issueOperations<ReplayOperationHandler>(replayStruct.mRenderer, handler);
583}
584
585void RenderNode::replayNodeInParent(ReplayStateStruct& replayStruct, const int level) {
John Reck113e0822014-03-18 09:22:59 -0700586 ReplayOperationHandler handler(replayStruct, level);
Chris Craikb265e2c2014-03-27 15:50:09 -0700587 issueOperations<ReplayOperationHandler>(replayStruct.mRenderer, handler);
John Reck113e0822014-03-18 09:22:59 -0700588}
589
590void RenderNode::buildZSortedChildList(Vector<ZDrawDisplayListOpPair>& zTranslatedNodes) {
John Reck087bc0c2014-04-04 16:20:08 -0700591 if (mDisplayListData == NULL || mDisplayListData->children().size() == 0) return;
John Reck113e0822014-03-18 09:22:59 -0700592
John Reck087bc0c2014-04-04 16:20:08 -0700593 for (unsigned int i = 0; i < mDisplayListData->children().size(); i++) {
594 DrawDisplayListOp* childOp = mDisplayListData->children()[i];
John Reck113e0822014-03-18 09:22:59 -0700595 RenderNode* child = childOp->mDisplayList;
Chris Craikcc39e162014-04-25 18:34:11 -0700596 float childZ = child->properties().getZ();
John Reck113e0822014-03-18 09:22:59 -0700597
Chris Craike0bb87d2014-04-22 17:55:41 -0700598 if (!MathUtils::isZero(childZ)) {
John Reck113e0822014-03-18 09:22:59 -0700599 zTranslatedNodes.add(ZDrawDisplayListOpPair(childZ, childOp));
600 childOp->mSkipInOrderDraw = true;
John Reckd0a0b2a2014-03-20 16:28:56 -0700601 } else if (!child->properties().getProjectBackwards()) {
John Reck113e0822014-03-18 09:22:59 -0700602 // regular, in order drawing DisplayList
603 childOp->mSkipInOrderDraw = false;
604 }
605 }
606
607 // Z sort 3d children (stable-ness makes z compare fall back to standard drawing order)
608 std::stable_sort(zTranslatedNodes.begin(), zTranslatedNodes.end());
609}
610
Chris Craikb265e2c2014-03-27 15:50:09 -0700611template <class T>
612void RenderNode::issueDrawShadowOperation(const Matrix4& transformFromParent, T& handler) {
Chris Craik61317322014-05-21 13:03:52 -0700613 if (properties().getAlpha() <= 0.0f || properties().getOutline().isEmpty()) return;
Chris Craikb265e2c2014-03-27 15:50:09 -0700614
615 mat4 shadowMatrixXY(transformFromParent);
616 applyViewPropertyTransforms(shadowMatrixXY);
617
618 // Z matrix needs actual 3d transformation, so mapped z values will be correct
619 mat4 shadowMatrixZ(transformFromParent);
620 applyViewPropertyTransforms(shadowMatrixZ, true);
621
622 const SkPath* outlinePath = properties().getOutline().getPath();
623 const RevealClip& revealClip = properties().getRevealClip();
624 const SkPath* revealClipPath = revealClip.hasConvexClip()
625 ? revealClip.getPath() : NULL; // only pass the reveal clip's path if it's convex
626
Chris Craik61317322014-05-21 13:03:52 -0700627 if (revealClipPath && revealClipPath->isEmpty()) return;
628
Chris Craikb265e2c2014-03-27 15:50:09 -0700629 /**
630 * The drawing area of the caster is always the same as the its perimeter (which
631 * the shadow system uses) *except* in the inverse clip case. Inform the shadow
632 * system that the caster's drawing area (as opposed to its perimeter) has been
633 * clipped, so that it knows the caster can't be opaque.
634 */
635 bool casterUnclipped = !revealClip.willClip() || revealClip.hasConvexClip();
636
637 DisplayListOp* shadowOp = new (handler.allocator()) DrawShadowOp(
638 shadowMatrixXY, shadowMatrixZ,
639 properties().getAlpha(), casterUnclipped,
Chris Craikb265e2c2014-03-27 15:50:09 -0700640 outlinePath, revealClipPath);
641 handler(shadowOp, PROPERTY_SAVECOUNT, properties().getClipToBounds());
642}
643
John Reck113e0822014-03-18 09:22:59 -0700644#define SHADOW_DELTA 0.1f
645
646template <class T>
Chris Craikb265e2c2014-03-27 15:50:09 -0700647void RenderNode::issueOperationsOf3dChildren(const Vector<ZDrawDisplayListOpPair>& zTranslatedNodes,
John Reck113e0822014-03-18 09:22:59 -0700648 ChildrenSelectMode mode, OpenGLRenderer& renderer, T& handler) {
649 const int size = zTranslatedNodes.size();
650 if (size == 0
651 || (mode == kNegativeZChildren && zTranslatedNodes[0].key > 0.0f)
652 || (mode == kPositiveZChildren && zTranslatedNodes[size - 1].key < 0.0f)) {
653 // no 3d children to draw
654 return;
655 }
656
John Reck113e0822014-03-18 09:22:59 -0700657 /**
658 * Draw shadows and (potential) casters mostly in order, but allow the shadows of casters
659 * with very similar Z heights to draw together.
660 *
661 * This way, if Views A & B have the same Z height and are both casting shadows, the shadows are
662 * underneath both, and neither's shadow is drawn on top of the other.
663 */
664 const size_t nonNegativeIndex = findNonNegativeIndex(zTranslatedNodes);
665 size_t drawIndex, shadowIndex, endIndex;
666 if (mode == kNegativeZChildren) {
667 drawIndex = 0;
668 endIndex = nonNegativeIndex;
669 shadowIndex = endIndex; // draw no shadows
670 } else {
671 drawIndex = nonNegativeIndex;
672 endIndex = size;
673 shadowIndex = drawIndex; // potentially draw shadow for each pos Z child
674 }
Chris Craik3f0854292014-04-15 16:18:08 -0700675
676 DISPLAY_LIST_LOGD("%*s%d %s 3d children:", (handler.level() + 1) * 2, "",
677 endIndex - drawIndex, mode == kNegativeZChildren ? "negative" : "positive");
678
John Reck113e0822014-03-18 09:22:59 -0700679 float lastCasterZ = 0.0f;
680 while (shadowIndex < endIndex || drawIndex < endIndex) {
681 if (shadowIndex < endIndex) {
682 DrawDisplayListOp* casterOp = zTranslatedNodes[shadowIndex].value;
683 RenderNode* caster = casterOp->mDisplayList;
684 const float casterZ = zTranslatedNodes[shadowIndex].key;
685 // attempt to render the shadow if the caster about to be drawn is its caster,
686 // OR if its caster's Z value is similar to the previous potential caster
687 if (shadowIndex == drawIndex || casterZ - lastCasterZ < SHADOW_DELTA) {
Chris Craikb265e2c2014-03-27 15:50:09 -0700688 caster->issueDrawShadowOperation(casterOp->mTransformFromParent, handler);
John Reck113e0822014-03-18 09:22:59 -0700689
690 lastCasterZ = casterZ; // must do this even if current caster not casting a shadow
691 shadowIndex++;
692 continue;
693 }
694 }
695
696 // only the actual child DL draw needs to be in save/restore,
697 // since it modifies the renderer's matrix
698 int restoreTo = renderer.save(SkCanvas::kMatrix_SaveFlag);
699
700 DrawDisplayListOp* childOp = zTranslatedNodes[drawIndex].value;
701 RenderNode* child = childOp->mDisplayList;
702
703 renderer.concatMatrix(childOp->mTransformFromParent);
704 childOp->mSkipInOrderDraw = false; // this is horrible, I'm so sorry everyone
John Reckd0a0b2a2014-03-20 16:28:56 -0700705 handler(childOp, renderer.getSaveCount() - 1, properties().getClipToBounds());
John Reck113e0822014-03-18 09:22:59 -0700706 childOp->mSkipInOrderDraw = true;
707
708 renderer.restoreToCount(restoreTo);
709 drawIndex++;
710 }
John Reck113e0822014-03-18 09:22:59 -0700711}
712
713template <class T>
Chris Craikb265e2c2014-03-27 15:50:09 -0700714void RenderNode::issueOperationsOfProjectedChildren(OpenGLRenderer& renderer, T& handler) {
Chris Craik3f0854292014-04-15 16:18:08 -0700715 DISPLAY_LIST_LOGD("%*s%d projected children:", (handler.level() + 1) * 2, "", mProjectedNodes.size());
716 const SkPath* projectionReceiverOutline = properties().getOutline().getPath();
717 bool maskProjecteesWithPath = projectionReceiverOutline != NULL
718 && !projectionReceiverOutline->isRect(NULL);
719 int restoreTo = renderer.getSaveCount();
720
721 // If the projection reciever has an outline, we mask each of the projected rendernodes to it
722 // Either with clipRect, or special saveLayer masking
723 LinearAllocator& alloc = handler.allocator();
724 if (projectionReceiverOutline != NULL) {
725 const SkRect& outlineBounds = projectionReceiverOutline->getBounds();
726 if (projectionReceiverOutline->isRect(NULL)) {
727 // mask to the rect outline simply with clipRect
728 handler(new (alloc) SaveOp(SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag),
729 PROPERTY_SAVECOUNT, properties().getClipToBounds());
730 ClipRectOp* clipOp = new (alloc) ClipRectOp(
731 outlineBounds.left(), outlineBounds.top(),
732 outlineBounds.right(), outlineBounds.bottom(), SkRegion::kIntersect_Op);
733 handler(clipOp, PROPERTY_SAVECOUNT, properties().getClipToBounds());
734 } else {
735 // wrap the projected RenderNodes with a SaveLayer that will mask to the outline
736 SaveLayerOp* op = new (alloc) SaveLayerOp(
737 outlineBounds.left(), outlineBounds.top(),
738 outlineBounds.right(), outlineBounds.bottom(),
739 255, SkCanvas::kARGB_ClipLayer_SaveFlag);
740 op->setMask(projectionReceiverOutline);
741 handler(op, PROPERTY_SAVECOUNT, properties().getClipToBounds());
742
743 /* TODO: add optimizations here to take advantage of placement/size of projected
744 * children (which may shrink saveLayer area significantly). This is dependent on
745 * passing actual drawing/dirtying bounds of projected content down to native.
746 */
747 }
748 }
749
750 // draw projected nodes
John Reck113e0822014-03-18 09:22:59 -0700751 for (size_t i = 0; i < mProjectedNodes.size(); i++) {
752 DrawDisplayListOp* childOp = mProjectedNodes[i];
753
754 // matrix save, concat, and restore can be done safely without allocating operations
755 int restoreTo = renderer.save(SkCanvas::kMatrix_SaveFlag);
756 renderer.concatMatrix(childOp->mTransformFromCompositingAncestor);
757 childOp->mSkipInOrderDraw = false; // this is horrible, I'm so sorry everyone
John Reckd0a0b2a2014-03-20 16:28:56 -0700758 handler(childOp, renderer.getSaveCount() - 1, properties().getClipToBounds());
John Reck113e0822014-03-18 09:22:59 -0700759 childOp->mSkipInOrderDraw = true;
760 renderer.restoreToCount(restoreTo);
761 }
Chris Craik3f0854292014-04-15 16:18:08 -0700762
763 if (projectionReceiverOutline != NULL) {
764 handler(new (alloc) RestoreToCountOp(restoreTo),
765 PROPERTY_SAVECOUNT, properties().getClipToBounds());
766 }
John Reck113e0822014-03-18 09:22:59 -0700767}
768
769/**
770 * This function serves both defer and replay modes, and will organize the displayList's component
771 * operations for a single frame:
772 *
773 * Every 'simple' state operation that affects just the matrix and alpha (or other factors of
774 * DeferredDisplayState) may be issued directly to the renderer, but complex operations (with custom
775 * defer logic) and operations in displayListOps are issued through the 'handler' which handles the
776 * defer vs replay logic, per operation
777 */
778template <class T>
Chris Craikb265e2c2014-03-27 15:50:09 -0700779void RenderNode::issueOperations(OpenGLRenderer& renderer, T& handler) {
John Reck25fbb3f2014-06-12 13:46:45 -0700780 const bool drawLayer = (mLayer && (&renderer != mLayer->renderer));
781 // If we are updating the contents of mLayer, we don't want to apply any of
782 // the RenderNode's properties to this issueOperations pass. Those will all
783 // be applied when the layer is drawn, aka when this is true.
784 const bool useViewProperties = (!mLayer || drawLayer);
785
Chris Craikb265e2c2014-03-27 15:50:09 -0700786 const int level = handler.level();
John Reck25fbb3f2014-06-12 13:46:45 -0700787 if (mDisplayListData->isEmpty() || (useViewProperties && properties().getAlpha() <= 0)) {
Chris Craik3f0854292014-04-15 16:18:08 -0700788 DISPLAY_LIST_LOGD("%*sEmpty display list (%p, %s)", level * 2, "", this, getName());
John Reck113e0822014-03-18 09:22:59 -0700789 return;
790 }
791
Chris Craik3f0854292014-04-15 16:18:08 -0700792 handler.startMark(getName());
Chris Craikb265e2c2014-03-27 15:50:09 -0700793
John Reck113e0822014-03-18 09:22:59 -0700794#if DEBUG_DISPLAY_LIST
Chris Craik3f0854292014-04-15 16:18:08 -0700795 const Rect& clipRect = renderer.getLocalClipBounds();
796 DISPLAY_LIST_LOGD("%*sStart display list (%p, %s), localClipBounds: %.0f, %.0f, %.0f, %.0f",
797 level * 2, "", this, getName(),
798 clipRect.left, clipRect.top, clipRect.right, clipRect.bottom);
John Reck113e0822014-03-18 09:22:59 -0700799#endif
800
801 LinearAllocator& alloc = handler.allocator();
802 int restoreTo = renderer.getSaveCount();
803 handler(new (alloc) SaveOp(SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag),
John Reckd0a0b2a2014-03-20 16:28:56 -0700804 PROPERTY_SAVECOUNT, properties().getClipToBounds());
John Reck113e0822014-03-18 09:22:59 -0700805
806 DISPLAY_LIST_LOGD("%*sSave %d %d", (level + 1) * 2, "",
807 SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag, restoreTo);
808
John Reck25fbb3f2014-06-12 13:46:45 -0700809 if (useViewProperties) {
810 setViewProperties<T>(renderer, handler);
811 }
John Reck113e0822014-03-18 09:22:59 -0700812
Chris Craik8c271ca2014-03-25 10:33:01 -0700813 bool quickRejected = properties().getClipToBounds()
814 && renderer.quickRejectConservative(0, 0, properties().getWidth(), properties().getHeight());
John Reck113e0822014-03-18 09:22:59 -0700815 if (!quickRejected) {
Chris Craikdeeda3d2014-05-05 19:09:33 -0700816 if (mProperties.getOutline().willClip()) {
817 renderer.setClippingOutline(alloc, &(mProperties.getOutline()));
818 }
819
John Reck25fbb3f2014-06-12 13:46:45 -0700820 if (drawLayer) {
821 handler(new (alloc) DrawLayerOp(mLayer, 0, 0),
822 renderer.getSaveCount() - 1, properties().getClipToBounds());
823 } else {
824 Vector<ZDrawDisplayListOpPair> zTranslatedNodes;
825 buildZSortedChildList(zTranslatedNodes);
John Reck113e0822014-03-18 09:22:59 -0700826
John Reck25fbb3f2014-06-12 13:46:45 -0700827 // for 3d root, draw children with negative z values
828 issueOperationsOf3dChildren(zTranslatedNodes, kNegativeZChildren, renderer, handler);
John Reck113e0822014-03-18 09:22:59 -0700829
John Reck25fbb3f2014-06-12 13:46:45 -0700830 DisplayListLogBuffer& logBuffer = DisplayListLogBuffer::getInstance();
831 const int saveCountOffset = renderer.getSaveCount() - 1;
832 const int projectionReceiveIndex = mDisplayListData->projectionReceiveIndex;
833 for (unsigned int i = 0; i < mDisplayListData->displayListOps.size(); i++) {
834 DisplayListOp *op = mDisplayListData->displayListOps[i];
John Reck113e0822014-03-18 09:22:59 -0700835
John Reck25fbb3f2014-06-12 13:46:45 -0700836 #if DEBUG_DISPLAY_LIST
837 op->output(level + 1);
838 #endif
839 logBuffer.writeCommand(level, op->name());
840 handler(op, saveCountOffset, properties().getClipToBounds());
John Reck113e0822014-03-18 09:22:59 -0700841
John Reck25fbb3f2014-06-12 13:46:45 -0700842 if (CC_UNLIKELY(i == projectionReceiveIndex && mProjectedNodes.size() > 0)) {
843 issueOperationsOfProjectedChildren(renderer, handler);
844 }
John Reck113e0822014-03-18 09:22:59 -0700845 }
John Reck113e0822014-03-18 09:22:59 -0700846
John Reck25fbb3f2014-06-12 13:46:45 -0700847 // for 3d root, draw children with positive z values
848 issueOperationsOf3dChildren(zTranslatedNodes, kPositiveZChildren, renderer, handler);
849 }
John Reck113e0822014-03-18 09:22:59 -0700850 }
851
852 DISPLAY_LIST_LOGD("%*sRestoreToCount %d", (level + 1) * 2, "", restoreTo);
853 handler(new (alloc) RestoreToCountOp(restoreTo),
John Reckd0a0b2a2014-03-20 16:28:56 -0700854 PROPERTY_SAVECOUNT, properties().getClipToBounds());
John Reck113e0822014-03-18 09:22:59 -0700855 renderer.setOverrideLayerAlpha(1.0f);
Chris Craikb265e2c2014-03-27 15:50:09 -0700856
Chris Craik3f0854292014-04-15 16:18:08 -0700857 DISPLAY_LIST_LOGD("%*sDone (%p, %s)", level * 2, "", this, getName());
Chris Craikb265e2c2014-03-27 15:50:09 -0700858 handler.endMark();
John Reck113e0822014-03-18 09:22:59 -0700859}
860
861} /* namespace uirenderer */
862} /* namespace android */