blob: 89105ea19fbdfa4d101f178ab72fc5c6a49cd40e [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
Chris Craik80d49022014-06-20 15:03:43 -070018#define LOG_TAG "OpenGLRenderer"
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 Reck68bfe0a2014-06-24 15:34:58 -070065 , mAnimatorManager(*this)
John Reck25fbb3f2014-06-12 13:46:45 -070066 , 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 Reck68bfe0a2014-06-24 15:34:58 -0700120void RenderNode::addAnimator(const sp<BaseRenderNodeAnimator>& animator) {
121 mAnimatorManager.addAnimator(animator);
122}
123
John Recke4267ea2014-06-03 15:53:15 -0700124void RenderNode::damageSelf(TreeInfo& info) {
John Reckce9f3082014-06-17 16:18:09 -0700125 if (isRenderable()) {
John Reck293e8682014-06-17 10:34:02 -0700126 if (properties().getClipDamageToBounds()) {
John Recka447d292014-06-11 18:39:44 -0700127 info.damageAccumulator->dirty(0, 0, properties().getWidth(), properties().getHeight());
128 } else {
129 // Hope this is big enough?
130 // TODO: Get this from the display list ops or something
131 info.damageAccumulator->dirty(INT_MIN, INT_MIN, INT_MAX, INT_MAX);
132 }
John Recke4267ea2014-06-03 15:53:15 -0700133 }
134}
135
John Reck25fbb3f2014-06-12 13:46:45 -0700136void RenderNode::prepareLayer(TreeInfo& info) {
137 LayerType layerType = properties().layerProperties().type();
138 if (CC_UNLIKELY(layerType == kLayerTypeRenderLayer)) {
139 // We push a null transform here as we don't care what the existing dirty
140 // area is, only what our display list dirty is as well as our children's
141 // dirty area
142 info.damageAccumulator->pushNullTransform();
143 }
144}
145
146void RenderNode::pushLayerUpdate(TreeInfo& info) {
147 LayerType layerType = properties().layerProperties().type();
148 // If we are not a layer OR we cannot be rendered (eg, view was detached)
149 // we need to destroy any Layers we may have had previously
150 if (CC_LIKELY(layerType != kLayerTypeRenderLayer) || CC_UNLIKELY(!isRenderable())) {
151 if (layerType == kLayerTypeRenderLayer) {
152 info.damageAccumulator->popTransform();
153 }
154 if (CC_UNLIKELY(mLayer)) {
155 LayerRenderer::destroyLayer(mLayer);
156 mLayer = NULL;
157 }
158 return;
159 }
160
161 if (!mLayer) {
John Reck3b202512014-06-23 13:13:08 -0700162 mLayer = LayerRenderer::createRenderLayer(info.renderState, getWidth(), getHeight());
John Reck25fbb3f2014-06-12 13:46:45 -0700163 applyLayerPropertiesToLayer(info);
164 damageSelf(info);
165 } else if (mLayer->layer.getWidth() != getWidth() || mLayer->layer.getHeight() != getHeight()) {
John Reckc25e5062014-06-18 14:21:29 -0700166 if (!LayerRenderer::resizeLayer(mLayer, getWidth(), getHeight())) {
167 LayerRenderer::destroyLayer(mLayer);
168 mLayer = 0;
169 }
John Reck25fbb3f2014-06-12 13:46:45 -0700170 damageSelf(info);
171 }
172
173 SkRect dirty;
174 info.damageAccumulator->peekAtDirty(&dirty);
175 info.damageAccumulator->popTransform();
176
John Reckc25e5062014-06-18 14:21:29 -0700177 if (!mLayer) {
178 if (info.errorHandler) {
179 std::string msg = "Unable to create layer for ";
180 msg += getName();
181 info.errorHandler->onError(msg);
182 }
183 return;
184 }
185
John Reck25fbb3f2014-06-12 13:46:45 -0700186 if (!dirty.isEmpty()) {
187 mLayer->updateDeferred(this, dirty.fLeft, dirty.fTop, dirty.fRight, dirty.fBottom);
188 }
189 // This is not inside the above if because we may have called
190 // updateDeferred on a previous prepare pass that didn't have a renderer
191 if (info.renderer && mLayer->deferredUpdateScheduled) {
192 info.renderer->pushLayerUpdate(mLayer);
193 }
194}
195
John Recke4267ea2014-06-03 15:53:15 -0700196void RenderNode::prepareTreeImpl(TreeInfo& info) {
John Recka447d292014-06-11 18:39:44 -0700197 info.damageAccumulator->pushTransform(this);
John Reckf47a5942014-06-30 16:20:04 -0700198
199 switch (info.mode) {
200 case TreeInfo::MODE_FULL:
John Reck25fbb3f2014-06-12 13:46:45 -0700201 pushStagingPropertiesChanges(info);
John Reck68bfe0a2014-06-24 15:34:58 -0700202 mAnimatorManager.animate(info);
John Reckf47a5942014-06-30 16:20:04 -0700203 break;
204 case TreeInfo::MODE_MAYBE_DETACHING:
John Reck25fbb3f2014-06-12 13:46:45 -0700205 pushStagingPropertiesChanges(info);
John Reckf47a5942014-06-30 16:20:04 -0700206 break;
207 case TreeInfo::MODE_RT_ONLY:
John Reck68bfe0a2014-06-24 15:34:58 -0700208 mAnimatorManager.animate(info);
John Reckf47a5942014-06-30 16:20:04 -0700209 break;
210 case TreeInfo::MODE_DESTROY_RESOURCES:
211 // This will also release the hardware layer if we have one as
212 // isRenderable() will return false, thus causing pushLayerUpdate
213 // to recycle the hardware layer
214 setStagingDisplayList(NULL);
215 break;
John Recke45b1fd2014-04-15 09:50:16 -0700216 }
John Reck25fbb3f2014-06-12 13:46:45 -0700217
218 prepareLayer(info);
John Reckf47a5942014-06-30 16:20:04 -0700219 if (info.mode == TreeInfo::MODE_FULL || info.mode == TreeInfo::MODE_DESTROY_RESOURCES) {
John Reck25fbb3f2014-06-12 13:46:45 -0700220 pushStagingDisplayListChanges(info);
221 }
John Reckf4198b72014-04-09 17:00:04 -0700222 prepareSubTree(info, mDisplayListData);
John Reck25fbb3f2014-06-12 13:46:45 -0700223 pushLayerUpdate(info);
224
John Recka447d292014-06-11 18:39:44 -0700225 info.damageAccumulator->popTransform();
John Reckf4198b72014-04-09 17:00:04 -0700226}
227
John Reck25fbb3f2014-06-12 13:46:45 -0700228void RenderNode::pushStagingPropertiesChanges(TreeInfo& info) {
John Reckff941dc2014-05-14 16:34:14 -0700229 // Push the animators first so that setupStartValueIfNecessary() is called
230 // before properties() is trampled by stagingProperties(), as they are
231 // required by some animators.
John Reck68bfe0a2014-06-24 15:34:58 -0700232 mAnimatorManager.pushStaging(info);
John Reckff941dc2014-05-14 16:34:14 -0700233 if (mDirtyPropertyFields) {
234 mDirtyPropertyFields = 0;
John Recke4267ea2014-06-03 15:53:15 -0700235 damageSelf(info);
John Recka447d292014-06-11 18:39:44 -0700236 info.damageAccumulator->popTransform();
John Reckff941dc2014-05-14 16:34:14 -0700237 mProperties = mStagingProperties;
John Reck25fbb3f2014-06-12 13:46:45 -0700238 applyLayerPropertiesToLayer(info);
John Recke4267ea2014-06-03 15:53:15 -0700239 // We could try to be clever and only re-damage if the matrix changed.
240 // However, we don't need to worry about that. The cost of over-damaging
241 // here is only going to be a single additional map rect of this node
242 // plus a rect join(). The parent's transform (and up) will only be
243 // performed once.
John Recka447d292014-06-11 18:39:44 -0700244 info.damageAccumulator->pushTransform(this);
John Recke4267ea2014-06-03 15:53:15 -0700245 damageSelf(info);
John Reckff941dc2014-05-14 16:34:14 -0700246 }
John Reck25fbb3f2014-06-12 13:46:45 -0700247}
248
249void RenderNode::applyLayerPropertiesToLayer(TreeInfo& info) {
250 if (CC_LIKELY(!mLayer)) return;
251
252 const LayerProperties& props = properties().layerProperties();
253 mLayer->setAlpha(props.alpha(), props.xferMode());
254 mLayer->setColorFilter(props.colorFilter());
255 mLayer->setBlend(props.needsBlending());
256}
257
258void RenderNode::pushStagingDisplayListChanges(TreeInfo& info) {
John Reck8de65a82014-04-09 15:23:38 -0700259 if (mNeedsDisplayListDataSync) {
260 mNeedsDisplayListDataSync = false;
261 // Do a push pass on the old tree to handle freeing DisplayListData
262 // that are no longer used
John Reck68bfe0a2014-06-24 15:34:58 -0700263 TreeInfo oldTreeInfo(TreeInfo::MODE_MAYBE_DETACHING, info);
John Reckf4198b72014-04-09 17:00:04 -0700264 prepareSubTree(oldTreeInfo, mDisplayListData);
John Reck8de65a82014-04-09 15:23:38 -0700265 delete mDisplayListData;
266 mDisplayListData = mStagingDisplayListData;
267 mStagingDisplayListData = 0;
John Recke4267ea2014-06-03 15:53:15 -0700268 damageSelf(info);
John Reck8de65a82014-04-09 15:23:38 -0700269 }
John Reck8de65a82014-04-09 15:23:38 -0700270}
271
John Reckf4198b72014-04-09 17:00:04 -0700272void RenderNode::prepareSubTree(TreeInfo& info, DisplayListData* subtree) {
John Reck8de65a82014-04-09 15:23:38 -0700273 if (subtree) {
John Reck860d1552014-04-11 19:15:05 -0700274 TextureCache& cache = Caches::getInstance().textureCache;
John Reckf9be7792014-05-02 18:21:16 -0700275 info.out.hasFunctors |= subtree->functorCount;
John Reck860d1552014-04-11 19:15:05 -0700276 // TODO: Fix ownedBitmapResources to not require disabling prepareTextures
277 // and thus falling out of async drawing path.
278 if (subtree->ownedBitmapResources.size()) {
279 info.prepareTextures = false;
280 }
281 for (size_t i = 0; info.prepareTextures && i < subtree->bitmapResources.size(); i++) {
282 info.prepareTextures = cache.prefetchAndMarkInUse(subtree->bitmapResources[i]);
John Reckf4198b72014-04-09 17:00:04 -0700283 }
John Reck8de65a82014-04-09 15:23:38 -0700284 for (size_t i = 0; i < subtree->children().size(); i++) {
Chris Craika7090e02014-06-20 16:01:00 -0700285 DrawRenderNodeOp* op = subtree->children()[i];
286 RenderNode* childNode = op->mRenderNode;
John Recka447d292014-06-11 18:39:44 -0700287 info.damageAccumulator->pushTransform(&op->mTransformFromParent);
John Reckf4198b72014-04-09 17:00:04 -0700288 childNode->prepareTreeImpl(info);
John Recka447d292014-06-11 18:39:44 -0700289 info.damageAccumulator->popTransform();
John Reck5bf11bb2014-03-25 10:22:09 -0700290 }
John Reck113e0822014-03-18 09:22:59 -0700291 }
292}
293
294/*
295 * For property operations, we pass a savecount of 0, since the operations aren't part of the
296 * displaylist, and thus don't have to compensate for the record-time/playback-time discrepancy in
John Reckd0a0b2a2014-03-20 16:28:56 -0700297 * base saveCount (i.e., how RestoreToCount uses saveCount + properties().getCount())
John Reck113e0822014-03-18 09:22:59 -0700298 */
299#define PROPERTY_SAVECOUNT 0
300
301template <class T>
Chris Craikb265e2c2014-03-27 15:50:09 -0700302void RenderNode::setViewProperties(OpenGLRenderer& renderer, T& handler) {
John Reck113e0822014-03-18 09:22:59 -0700303#if DEBUG_DISPLAY_LIST
Chris Craikb265e2c2014-03-27 15:50:09 -0700304 properties().debugOutputProperties(handler.level() + 1);
John Reck113e0822014-03-18 09:22:59 -0700305#endif
John Reckd0a0b2a2014-03-20 16:28:56 -0700306 if (properties().getLeft() != 0 || properties().getTop() != 0) {
307 renderer.translate(properties().getLeft(), properties().getTop());
John Reck113e0822014-03-18 09:22:59 -0700308 }
John Reckd0a0b2a2014-03-20 16:28:56 -0700309 if (properties().getStaticMatrix()) {
Derek Sollenberger13908822013-12-10 12:28:58 -0500310 renderer.concatMatrix(*properties().getStaticMatrix());
John Reckd0a0b2a2014-03-20 16:28:56 -0700311 } else if (properties().getAnimationMatrix()) {
Derek Sollenberger13908822013-12-10 12:28:58 -0500312 renderer.concatMatrix(*properties().getAnimationMatrix());
John Reck113e0822014-03-18 09:22:59 -0700313 }
John Reckf7483e32014-04-11 08:54:47 -0700314 if (properties().hasTransformMatrix()) {
315 if (properties().isTransformTranslateOnly()) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700316 renderer.translate(properties().getTranslationX(), properties().getTranslationY());
John Reck113e0822014-03-18 09:22:59 -0700317 } else {
John Reckd0a0b2a2014-03-20 16:28:56 -0700318 renderer.concatMatrix(*properties().getTransformMatrix());
John Reck113e0822014-03-18 09:22:59 -0700319 }
320 }
John Reck25fbb3f2014-06-12 13:46:45 -0700321 const bool isLayer = properties().layerProperties().type() != kLayerTypeNone;
322 bool clipToBoundsNeeded = isLayer ? false : properties().getClipToBounds();
John Reckd0a0b2a2014-03-20 16:28:56 -0700323 if (properties().getAlpha() < 1) {
John Reck25fbb3f2014-06-12 13:46:45 -0700324 if (isLayer) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700325 renderer.setOverrideLayerAlpha(properties().getAlpha());
326 } else if (!properties().getHasOverlappingRendering()) {
327 renderer.scaleAlpha(properties().getAlpha());
John Reck113e0822014-03-18 09:22:59 -0700328 } else {
329 // TODO: should be able to store the size of a DL at record time and not
330 // have to pass it into this call. In fact, this information might be in the
331 // location/size info that we store with the new native transform data.
332 int saveFlags = SkCanvas::kHasAlphaLayer_SaveFlag;
333 if (clipToBoundsNeeded) {
334 saveFlags |= SkCanvas::kClipToLayer_SaveFlag;
335 clipToBoundsNeeded = false; // clipping done by saveLayer
336 }
337
338 SaveLayerOp* op = new (handler.allocator()) SaveLayerOp(
Chris Craik8c271ca2014-03-25 10:33:01 -0700339 0, 0, properties().getWidth(), properties().getHeight(),
340 properties().getAlpha() * 255, saveFlags);
John Reckd0a0b2a2014-03-20 16:28:56 -0700341 handler(op, PROPERTY_SAVECOUNT, properties().getClipToBounds());
John Reck113e0822014-03-18 09:22:59 -0700342 }
343 }
344 if (clipToBoundsNeeded) {
Chris Craik8c271ca2014-03-25 10:33:01 -0700345 ClipRectOp* op = new (handler.allocator()) ClipRectOp(
346 0, 0, properties().getWidth(), properties().getHeight(), SkRegion::kIntersect_Op);
John Reckd0a0b2a2014-03-20 16:28:56 -0700347 handler(op, PROPERTY_SAVECOUNT, properties().getClipToBounds());
John Reck113e0822014-03-18 09:22:59 -0700348 }
Chris Craik8c271ca2014-03-25 10:33:01 -0700349
350 if (CC_UNLIKELY(properties().hasClippingPath())) {
Chris Craik2bcad172014-05-14 18:11:23 -0700351 ClipPathOp* op = new (handler.allocator()) ClipPathOp(
352 properties().getClippingPath(), properties().getClippingPathOp());
John Reckd0a0b2a2014-03-20 16:28:56 -0700353 handler(op, PROPERTY_SAVECOUNT, properties().getClipToBounds());
John Reck113e0822014-03-18 09:22:59 -0700354 }
355}
356
357/**
358 * Apply property-based transformations to input matrix
359 *
360 * If true3dTransform is set to true, the transform applied to the input matrix will use true 4x4
361 * matrix computation instead of the Skia 3x3 matrix + camera hackery.
362 */
363void RenderNode::applyViewPropertyTransforms(mat4& matrix, bool true3dTransform) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700364 if (properties().getLeft() != 0 || properties().getTop() != 0) {
365 matrix.translate(properties().getLeft(), properties().getTop());
John Reck113e0822014-03-18 09:22:59 -0700366 }
John Reckd0a0b2a2014-03-20 16:28:56 -0700367 if (properties().getStaticMatrix()) {
368 mat4 stat(*properties().getStaticMatrix());
John Reck113e0822014-03-18 09:22:59 -0700369 matrix.multiply(stat);
John Reckd0a0b2a2014-03-20 16:28:56 -0700370 } else if (properties().getAnimationMatrix()) {
371 mat4 anim(*properties().getAnimationMatrix());
John Reck113e0822014-03-18 09:22:59 -0700372 matrix.multiply(anim);
373 }
Chris Craike0bb87d2014-04-22 17:55:41 -0700374
Chris Craikcc39e162014-04-25 18:34:11 -0700375 bool applyTranslationZ = true3dTransform && !MathUtils::isZero(properties().getZ());
Chris Craike0bb87d2014-04-22 17:55:41 -0700376 if (properties().hasTransformMatrix() || applyTranslationZ) {
John Reckf7483e32014-04-11 08:54:47 -0700377 if (properties().isTransformTranslateOnly()) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700378 matrix.translate(properties().getTranslationX(), properties().getTranslationY(),
Chris Craikcc39e162014-04-25 18:34:11 -0700379 true3dTransform ? properties().getZ() : 0.0f);
John Reck113e0822014-03-18 09:22:59 -0700380 } else {
381 if (!true3dTransform) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700382 matrix.multiply(*properties().getTransformMatrix());
John Reck113e0822014-03-18 09:22:59 -0700383 } else {
384 mat4 true3dMat;
385 true3dMat.loadTranslate(
John Reckd0a0b2a2014-03-20 16:28:56 -0700386 properties().getPivotX() + properties().getTranslationX(),
387 properties().getPivotY() + properties().getTranslationY(),
Chris Craikcc39e162014-04-25 18:34:11 -0700388 properties().getZ());
John Reckd0a0b2a2014-03-20 16:28:56 -0700389 true3dMat.rotate(properties().getRotationX(), 1, 0, 0);
390 true3dMat.rotate(properties().getRotationY(), 0, 1, 0);
391 true3dMat.rotate(properties().getRotation(), 0, 0, 1);
392 true3dMat.scale(properties().getScaleX(), properties().getScaleY(), 1);
393 true3dMat.translate(-properties().getPivotX(), -properties().getPivotY());
John Reck113e0822014-03-18 09:22:59 -0700394
395 matrix.multiply(true3dMat);
396 }
397 }
398 }
399}
400
401/**
402 * Organizes the DisplayList hierarchy to prepare for background projection reordering.
403 *
404 * This should be called before a call to defer() or drawDisplayList()
405 *
406 * Each DisplayList that serves as a 3d root builds its list of composited children,
407 * which are flagged to not draw in the standard draw loop.
408 */
409void RenderNode::computeOrdering() {
410 ATRACE_CALL();
411 mProjectedNodes.clear();
412
413 // TODO: create temporary DDLOp and call computeOrderingImpl on top DisplayList so that
414 // transform properties are applied correctly to top level children
415 if (mDisplayListData == NULL) return;
John Reck087bc0c2014-04-04 16:20:08 -0700416 for (unsigned int i = 0; i < mDisplayListData->children().size(); i++) {
Chris Craika7090e02014-06-20 16:01:00 -0700417 DrawRenderNodeOp* childOp = mDisplayListData->children()[i];
418 childOp->mRenderNode->computeOrderingImpl(childOp,
Chris Craik3f0854292014-04-15 16:18:08 -0700419 properties().getOutline().getPath(), &mProjectedNodes, &mat4::identity());
John Reck113e0822014-03-18 09:22:59 -0700420 }
421}
422
423void RenderNode::computeOrderingImpl(
Chris Craika7090e02014-06-20 16:01:00 -0700424 DrawRenderNodeOp* opState,
Chris Craik3f0854292014-04-15 16:18:08 -0700425 const SkPath* outlineOfProjectionSurface,
Chris Craika7090e02014-06-20 16:01:00 -0700426 Vector<DrawRenderNodeOp*>* compositedChildrenOfProjectionSurface,
John Reck113e0822014-03-18 09:22:59 -0700427 const mat4* transformFromProjectionSurface) {
428 mProjectedNodes.clear();
429 if (mDisplayListData == NULL || mDisplayListData->isEmpty()) return;
430
431 // TODO: should avoid this calculation in most cases
432 // TODO: just calculate single matrix, down to all leaf composited elements
433 Matrix4 localTransformFromProjectionSurface(*transformFromProjectionSurface);
434 localTransformFromProjectionSurface.multiply(opState->mTransformFromParent);
435
John Reckd0a0b2a2014-03-20 16:28:56 -0700436 if (properties().getProjectBackwards()) {
John Reck113e0822014-03-18 09:22:59 -0700437 // composited projectee, flag for out of order draw, save matrix, and store in proj surface
438 opState->mSkipInOrderDraw = true;
439 opState->mTransformFromCompositingAncestor.load(localTransformFromProjectionSurface);
440 compositedChildrenOfProjectionSurface->add(opState);
441 } else {
442 // standard in order draw
443 opState->mSkipInOrderDraw = false;
444 }
445
John Reck087bc0c2014-04-04 16:20:08 -0700446 if (mDisplayListData->children().size() > 0) {
John Reck113e0822014-03-18 09:22:59 -0700447 const bool isProjectionReceiver = mDisplayListData->projectionReceiveIndex >= 0;
448 bool haveAppliedPropertiesToProjection = false;
John Reck087bc0c2014-04-04 16:20:08 -0700449 for (unsigned int i = 0; i < mDisplayListData->children().size(); i++) {
Chris Craika7090e02014-06-20 16:01:00 -0700450 DrawRenderNodeOp* childOp = mDisplayListData->children()[i];
451 RenderNode* child = childOp->mRenderNode;
John Reck113e0822014-03-18 09:22:59 -0700452
Chris Craik3f0854292014-04-15 16:18:08 -0700453 const SkPath* projectionOutline = NULL;
Chris Craika7090e02014-06-20 16:01:00 -0700454 Vector<DrawRenderNodeOp*>* projectionChildren = NULL;
John Reck113e0822014-03-18 09:22:59 -0700455 const mat4* projectionTransform = NULL;
John Reckd0a0b2a2014-03-20 16:28:56 -0700456 if (isProjectionReceiver && !child->properties().getProjectBackwards()) {
John Reck113e0822014-03-18 09:22:59 -0700457 // if receiving projections, collect projecting descendent
458
459 // Note that if a direct descendent is projecting backwards, we pass it's
460 // grandparent projection collection, since it shouldn't project onto it's
461 // parent, where it will already be drawing.
Chris Craik3f0854292014-04-15 16:18:08 -0700462 projectionOutline = properties().getOutline().getPath();
John Reck113e0822014-03-18 09:22:59 -0700463 projectionChildren = &mProjectedNodes;
464 projectionTransform = &mat4::identity();
465 } else {
466 if (!haveAppliedPropertiesToProjection) {
467 applyViewPropertyTransforms(localTransformFromProjectionSurface);
468 haveAppliedPropertiesToProjection = true;
469 }
Chris Craik3f0854292014-04-15 16:18:08 -0700470 projectionOutline = outlineOfProjectionSurface;
John Reck113e0822014-03-18 09:22:59 -0700471 projectionChildren = compositedChildrenOfProjectionSurface;
472 projectionTransform = &localTransformFromProjectionSurface;
473 }
Chris Craik3f0854292014-04-15 16:18:08 -0700474 child->computeOrderingImpl(childOp,
475 projectionOutline, projectionChildren, projectionTransform);
John Reck113e0822014-03-18 09:22:59 -0700476 }
477 }
John Reck113e0822014-03-18 09:22:59 -0700478}
479
480class DeferOperationHandler {
481public:
482 DeferOperationHandler(DeferStateStruct& deferStruct, int level)
483 : mDeferStruct(deferStruct), mLevel(level) {}
484 inline void operator()(DisplayListOp* operation, int saveCount, bool clipToBounds) {
485 operation->defer(mDeferStruct, saveCount, mLevel, clipToBounds);
486 }
487 inline LinearAllocator& allocator() { return *(mDeferStruct.mAllocator); }
Chris Craikb265e2c2014-03-27 15:50:09 -0700488 inline void startMark(const char* name) {} // do nothing
489 inline void endMark() {}
490 inline int level() { return mLevel; }
491 inline int replayFlags() { return mDeferStruct.mReplayFlags; }
John Reck113e0822014-03-18 09:22:59 -0700492
493private:
494 DeferStateStruct& mDeferStruct;
495 const int mLevel;
496};
497
Chris Craik80d49022014-06-20 15:03:43 -0700498void RenderNode::defer(DeferStateStruct& deferStruct, const int level) {
John Reck113e0822014-03-18 09:22:59 -0700499 DeferOperationHandler handler(deferStruct, level);
Chris Craikb265e2c2014-03-27 15:50:09 -0700500 issueOperations<DeferOperationHandler>(deferStruct.mRenderer, handler);
John Reck113e0822014-03-18 09:22:59 -0700501}
502
503class ReplayOperationHandler {
504public:
505 ReplayOperationHandler(ReplayStateStruct& replayStruct, int level)
506 : mReplayStruct(replayStruct), mLevel(level) {}
507 inline void operator()(DisplayListOp* operation, int saveCount, bool clipToBounds) {
508#if DEBUG_DISPLAY_LIST_OPS_AS_EVENTS
Chris Craik3f0854292014-04-15 16:18:08 -0700509 mReplayStruct.mRenderer.eventMark(operation->name());
John Reck113e0822014-03-18 09:22:59 -0700510#endif
511 operation->replay(mReplayStruct, saveCount, mLevel, clipToBounds);
512 }
513 inline LinearAllocator& allocator() { return *(mReplayStruct.mAllocator); }
Chris Craikb265e2c2014-03-27 15:50:09 -0700514 inline void startMark(const char* name) {
515 mReplayStruct.mRenderer.startMark(name);
516 }
517 inline void endMark() {
518 mReplayStruct.mRenderer.endMark();
Chris Craikb265e2c2014-03-27 15:50:09 -0700519 }
520 inline int level() { return mLevel; }
521 inline int replayFlags() { return mReplayStruct.mReplayFlags; }
John Reck113e0822014-03-18 09:22:59 -0700522
523private:
524 ReplayStateStruct& mReplayStruct;
525 const int mLevel;
526};
527
Chris Craik80d49022014-06-20 15:03:43 -0700528void RenderNode::replay(ReplayStateStruct& replayStruct, const int level) {
John Reck113e0822014-03-18 09:22:59 -0700529 ReplayOperationHandler handler(replayStruct, level);
Chris Craikb265e2c2014-03-27 15:50:09 -0700530 issueOperations<ReplayOperationHandler>(replayStruct.mRenderer, handler);
John Reck113e0822014-03-18 09:22:59 -0700531}
532
Chris Craika7090e02014-06-20 16:01:00 -0700533void RenderNode::buildZSortedChildList(Vector<ZDrawRenderNodeOpPair>& zTranslatedNodes) {
John Reck087bc0c2014-04-04 16:20:08 -0700534 if (mDisplayListData == NULL || mDisplayListData->children().size() == 0) return;
John Reck113e0822014-03-18 09:22:59 -0700535
John Reck087bc0c2014-04-04 16:20:08 -0700536 for (unsigned int i = 0; i < mDisplayListData->children().size(); i++) {
Chris Craika7090e02014-06-20 16:01:00 -0700537 DrawRenderNodeOp* childOp = mDisplayListData->children()[i];
538 RenderNode* child = childOp->mRenderNode;
Chris Craikcc39e162014-04-25 18:34:11 -0700539 float childZ = child->properties().getZ();
John Reck113e0822014-03-18 09:22:59 -0700540
Chris Craike0bb87d2014-04-22 17:55:41 -0700541 if (!MathUtils::isZero(childZ)) {
Chris Craika7090e02014-06-20 16:01:00 -0700542 zTranslatedNodes.add(ZDrawRenderNodeOpPair(childZ, childOp));
John Reck113e0822014-03-18 09:22:59 -0700543 childOp->mSkipInOrderDraw = true;
John Reckd0a0b2a2014-03-20 16:28:56 -0700544 } else if (!child->properties().getProjectBackwards()) {
John Reck113e0822014-03-18 09:22:59 -0700545 // regular, in order drawing DisplayList
546 childOp->mSkipInOrderDraw = false;
547 }
548 }
549
550 // Z sort 3d children (stable-ness makes z compare fall back to standard drawing order)
551 std::stable_sort(zTranslatedNodes.begin(), zTranslatedNodes.end());
552}
553
Chris Craikb265e2c2014-03-27 15:50:09 -0700554template <class T>
555void RenderNode::issueDrawShadowOperation(const Matrix4& transformFromParent, T& handler) {
Chris Craik61317322014-05-21 13:03:52 -0700556 if (properties().getAlpha() <= 0.0f || properties().getOutline().isEmpty()) return;
Chris Craikb265e2c2014-03-27 15:50:09 -0700557
558 mat4 shadowMatrixXY(transformFromParent);
559 applyViewPropertyTransforms(shadowMatrixXY);
560
561 // Z matrix needs actual 3d transformation, so mapped z values will be correct
562 mat4 shadowMatrixZ(transformFromParent);
563 applyViewPropertyTransforms(shadowMatrixZ, true);
564
565 const SkPath* outlinePath = properties().getOutline().getPath();
566 const RevealClip& revealClip = properties().getRevealClip();
567 const SkPath* revealClipPath = revealClip.hasConvexClip()
568 ? revealClip.getPath() : NULL; // only pass the reveal clip's path if it's convex
569
Chris Craik61317322014-05-21 13:03:52 -0700570 if (revealClipPath && revealClipPath->isEmpty()) return;
571
Chris Craikb265e2c2014-03-27 15:50:09 -0700572 /**
573 * The drawing area of the caster is always the same as the its perimeter (which
574 * the shadow system uses) *except* in the inverse clip case. Inform the shadow
575 * system that the caster's drawing area (as opposed to its perimeter) has been
576 * clipped, so that it knows the caster can't be opaque.
577 */
578 bool casterUnclipped = !revealClip.willClip() || revealClip.hasConvexClip();
579
580 DisplayListOp* shadowOp = new (handler.allocator()) DrawShadowOp(
581 shadowMatrixXY, shadowMatrixZ,
582 properties().getAlpha(), casterUnclipped,
Chris Craikb265e2c2014-03-27 15:50:09 -0700583 outlinePath, revealClipPath);
584 handler(shadowOp, PROPERTY_SAVECOUNT, properties().getClipToBounds());
585}
586
Chris Craik80d49022014-06-20 15:03:43 -0700587template <class T>
588int RenderNode::issueOperationsOfNegZChildren(
Chris Craika7090e02014-06-20 16:01:00 -0700589 const Vector<ZDrawRenderNodeOpPair>& zTranslatedNodes,
Chris Craik80d49022014-06-20 15:03:43 -0700590 OpenGLRenderer& renderer, T& handler) {
591 if (zTranslatedNodes.isEmpty()) return -1;
592
593 // create a save around the body of the ViewGroup's draw method, so that
594 // matrix/clip methods don't affect composited children
595 int shadowSaveCount = renderer.getSaveCount();
596 handler(new (handler.allocator()) SaveOp(SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag),
597 PROPERTY_SAVECOUNT, properties().getClipToBounds());
598
599 issueOperationsOf3dChildren(zTranslatedNodes, kNegativeZChildren, renderer, handler);
600 return shadowSaveCount;
601}
602
603template <class T>
604void RenderNode::issueOperationsOfPosZChildren(int shadowRestoreTo,
Chris Craika7090e02014-06-20 16:01:00 -0700605 const Vector<ZDrawRenderNodeOpPair>& zTranslatedNodes,
Chris Craik80d49022014-06-20 15:03:43 -0700606 OpenGLRenderer& renderer, T& handler) {
607 if (zTranslatedNodes.isEmpty()) return;
608
609 LOG_ALWAYS_FATAL_IF(shadowRestoreTo < 0, "invalid save to restore to");
610 handler(new (handler.allocator()) RestoreToCountOp(shadowRestoreTo),
611 PROPERTY_SAVECOUNT, properties().getClipToBounds());
612 renderer.setOverrideLayerAlpha(1.0f);
613
614 issueOperationsOf3dChildren(zTranslatedNodes, kPositiveZChildren, renderer, handler);
615}
616
John Reck113e0822014-03-18 09:22:59 -0700617#define SHADOW_DELTA 0.1f
618
619template <class T>
Chris Craika7090e02014-06-20 16:01:00 -0700620void RenderNode::issueOperationsOf3dChildren(const Vector<ZDrawRenderNodeOpPair>& zTranslatedNodes,
John Reck113e0822014-03-18 09:22:59 -0700621 ChildrenSelectMode mode, OpenGLRenderer& renderer, T& handler) {
622 const int size = zTranslatedNodes.size();
623 if (size == 0
624 || (mode == kNegativeZChildren && zTranslatedNodes[0].key > 0.0f)
625 || (mode == kPositiveZChildren && zTranslatedNodes[size - 1].key < 0.0f)) {
626 // no 3d children to draw
627 return;
628 }
629
John Reck113e0822014-03-18 09:22:59 -0700630 /**
631 * Draw shadows and (potential) casters mostly in order, but allow the shadows of casters
632 * with very similar Z heights to draw together.
633 *
634 * This way, if Views A & B have the same Z height and are both casting shadows, the shadows are
635 * underneath both, and neither's shadow is drawn on top of the other.
636 */
637 const size_t nonNegativeIndex = findNonNegativeIndex(zTranslatedNodes);
638 size_t drawIndex, shadowIndex, endIndex;
639 if (mode == kNegativeZChildren) {
640 drawIndex = 0;
641 endIndex = nonNegativeIndex;
642 shadowIndex = endIndex; // draw no shadows
643 } else {
644 drawIndex = nonNegativeIndex;
645 endIndex = size;
646 shadowIndex = drawIndex; // potentially draw shadow for each pos Z child
647 }
Chris Craik3f0854292014-04-15 16:18:08 -0700648
649 DISPLAY_LIST_LOGD("%*s%d %s 3d children:", (handler.level() + 1) * 2, "",
650 endIndex - drawIndex, mode == kNegativeZChildren ? "negative" : "positive");
651
John Reck113e0822014-03-18 09:22:59 -0700652 float lastCasterZ = 0.0f;
653 while (shadowIndex < endIndex || drawIndex < endIndex) {
654 if (shadowIndex < endIndex) {
Chris Craika7090e02014-06-20 16:01:00 -0700655 DrawRenderNodeOp* casterOp = zTranslatedNodes[shadowIndex].value;
656 RenderNode* caster = casterOp->mRenderNode;
John Reck113e0822014-03-18 09:22:59 -0700657 const float casterZ = zTranslatedNodes[shadowIndex].key;
658 // attempt to render the shadow if the caster about to be drawn is its caster,
659 // OR if its caster's Z value is similar to the previous potential caster
660 if (shadowIndex == drawIndex || casterZ - lastCasterZ < SHADOW_DELTA) {
Chris Craikb265e2c2014-03-27 15:50:09 -0700661 caster->issueDrawShadowOperation(casterOp->mTransformFromParent, handler);
John Reck113e0822014-03-18 09:22:59 -0700662
663 lastCasterZ = casterZ; // must do this even if current caster not casting a shadow
664 shadowIndex++;
665 continue;
666 }
667 }
668
669 // only the actual child DL draw needs to be in save/restore,
670 // since it modifies the renderer's matrix
671 int restoreTo = renderer.save(SkCanvas::kMatrix_SaveFlag);
672
Chris Craika7090e02014-06-20 16:01:00 -0700673 DrawRenderNodeOp* childOp = zTranslatedNodes[drawIndex].value;
674 RenderNode* child = childOp->mRenderNode;
John Reck113e0822014-03-18 09:22:59 -0700675
676 renderer.concatMatrix(childOp->mTransformFromParent);
677 childOp->mSkipInOrderDraw = false; // this is horrible, I'm so sorry everyone
John Reckd0a0b2a2014-03-20 16:28:56 -0700678 handler(childOp, renderer.getSaveCount() - 1, properties().getClipToBounds());
John Reck113e0822014-03-18 09:22:59 -0700679 childOp->mSkipInOrderDraw = true;
680
681 renderer.restoreToCount(restoreTo);
682 drawIndex++;
683 }
John Reck113e0822014-03-18 09:22:59 -0700684}
685
686template <class T>
Chris Craikb265e2c2014-03-27 15:50:09 -0700687void RenderNode::issueOperationsOfProjectedChildren(OpenGLRenderer& renderer, T& handler) {
Chris Craik3f0854292014-04-15 16:18:08 -0700688 DISPLAY_LIST_LOGD("%*s%d projected children:", (handler.level() + 1) * 2, "", mProjectedNodes.size());
689 const SkPath* projectionReceiverOutline = properties().getOutline().getPath();
Chris Craik3f0854292014-04-15 16:18:08 -0700690 int restoreTo = renderer.getSaveCount();
691
692 // If the projection reciever has an outline, we mask each of the projected rendernodes to it
693 // Either with clipRect, or special saveLayer masking
694 LinearAllocator& alloc = handler.allocator();
695 if (projectionReceiverOutline != NULL) {
696 const SkRect& outlineBounds = projectionReceiverOutline->getBounds();
697 if (projectionReceiverOutline->isRect(NULL)) {
698 // mask to the rect outline simply with clipRect
699 handler(new (alloc) SaveOp(SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag),
700 PROPERTY_SAVECOUNT, properties().getClipToBounds());
701 ClipRectOp* clipOp = new (alloc) ClipRectOp(
702 outlineBounds.left(), outlineBounds.top(),
703 outlineBounds.right(), outlineBounds.bottom(), SkRegion::kIntersect_Op);
704 handler(clipOp, PROPERTY_SAVECOUNT, properties().getClipToBounds());
705 } else {
706 // wrap the projected RenderNodes with a SaveLayer that will mask to the outline
707 SaveLayerOp* op = new (alloc) SaveLayerOp(
708 outlineBounds.left(), outlineBounds.top(),
709 outlineBounds.right(), outlineBounds.bottom(),
Chris Craik80d49022014-06-20 15:03:43 -0700710 255, SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag | SkCanvas::kARGB_ClipLayer_SaveFlag);
Chris Craik3f0854292014-04-15 16:18:08 -0700711 op->setMask(projectionReceiverOutline);
712 handler(op, PROPERTY_SAVECOUNT, properties().getClipToBounds());
713
714 /* TODO: add optimizations here to take advantage of placement/size of projected
715 * children (which may shrink saveLayer area significantly). This is dependent on
716 * passing actual drawing/dirtying bounds of projected content down to native.
717 */
718 }
719 }
720
721 // draw projected nodes
John Reck113e0822014-03-18 09:22:59 -0700722 for (size_t i = 0; i < mProjectedNodes.size(); i++) {
Chris Craika7090e02014-06-20 16:01:00 -0700723 DrawRenderNodeOp* childOp = mProjectedNodes[i];
John Reck113e0822014-03-18 09:22:59 -0700724
725 // matrix save, concat, and restore can be done safely without allocating operations
726 int restoreTo = renderer.save(SkCanvas::kMatrix_SaveFlag);
727 renderer.concatMatrix(childOp->mTransformFromCompositingAncestor);
728 childOp->mSkipInOrderDraw = false; // this is horrible, I'm so sorry everyone
John Reckd0a0b2a2014-03-20 16:28:56 -0700729 handler(childOp, renderer.getSaveCount() - 1, properties().getClipToBounds());
John Reck113e0822014-03-18 09:22:59 -0700730 childOp->mSkipInOrderDraw = true;
731 renderer.restoreToCount(restoreTo);
732 }
Chris Craik3f0854292014-04-15 16:18:08 -0700733
734 if (projectionReceiverOutline != NULL) {
735 handler(new (alloc) RestoreToCountOp(restoreTo),
736 PROPERTY_SAVECOUNT, properties().getClipToBounds());
737 }
John Reck113e0822014-03-18 09:22:59 -0700738}
739
740/**
741 * This function serves both defer and replay modes, and will organize the displayList's component
742 * operations for a single frame:
743 *
744 * Every 'simple' state operation that affects just the matrix and alpha (or other factors of
745 * DeferredDisplayState) may be issued directly to the renderer, but complex operations (with custom
746 * defer logic) and operations in displayListOps are issued through the 'handler' which handles the
747 * defer vs replay logic, per operation
748 */
749template <class T>
Chris Craikb265e2c2014-03-27 15:50:09 -0700750void RenderNode::issueOperations(OpenGLRenderer& renderer, T& handler) {
John Reck25fbb3f2014-06-12 13:46:45 -0700751 const bool drawLayer = (mLayer && (&renderer != mLayer->renderer));
752 // If we are updating the contents of mLayer, we don't want to apply any of
753 // the RenderNode's properties to this issueOperations pass. Those will all
754 // be applied when the layer is drawn, aka when this is true.
755 const bool useViewProperties = (!mLayer || drawLayer);
756
Chris Craikb265e2c2014-03-27 15:50:09 -0700757 const int level = handler.level();
John Reck25fbb3f2014-06-12 13:46:45 -0700758 if (mDisplayListData->isEmpty() || (useViewProperties && properties().getAlpha() <= 0)) {
Chris Craik3f0854292014-04-15 16:18:08 -0700759 DISPLAY_LIST_LOGD("%*sEmpty display list (%p, %s)", level * 2, "", this, getName());
John Reck113e0822014-03-18 09:22:59 -0700760 return;
761 }
762
Chris Craik3f0854292014-04-15 16:18:08 -0700763 handler.startMark(getName());
Chris Craikb265e2c2014-03-27 15:50:09 -0700764
John Reck113e0822014-03-18 09:22:59 -0700765#if DEBUG_DISPLAY_LIST
Chris Craik3f0854292014-04-15 16:18:08 -0700766 const Rect& clipRect = renderer.getLocalClipBounds();
767 DISPLAY_LIST_LOGD("%*sStart display list (%p, %s), localClipBounds: %.0f, %.0f, %.0f, %.0f",
768 level * 2, "", this, getName(),
769 clipRect.left, clipRect.top, clipRect.right, clipRect.bottom);
John Reck113e0822014-03-18 09:22:59 -0700770#endif
771
772 LinearAllocator& alloc = handler.allocator();
773 int restoreTo = renderer.getSaveCount();
774 handler(new (alloc) SaveOp(SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag),
John Reckd0a0b2a2014-03-20 16:28:56 -0700775 PROPERTY_SAVECOUNT, properties().getClipToBounds());
John Reck113e0822014-03-18 09:22:59 -0700776
777 DISPLAY_LIST_LOGD("%*sSave %d %d", (level + 1) * 2, "",
778 SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag, restoreTo);
779
John Reck25fbb3f2014-06-12 13:46:45 -0700780 if (useViewProperties) {
781 setViewProperties<T>(renderer, handler);
782 }
John Reck113e0822014-03-18 09:22:59 -0700783
Chris Craik8c271ca2014-03-25 10:33:01 -0700784 bool quickRejected = properties().getClipToBounds()
785 && renderer.quickRejectConservative(0, 0, properties().getWidth(), properties().getHeight());
John Reck113e0822014-03-18 09:22:59 -0700786 if (!quickRejected) {
Chris Craikdeeda3d2014-05-05 19:09:33 -0700787 if (mProperties.getOutline().willClip()) {
788 renderer.setClippingOutline(alloc, &(mProperties.getOutline()));
789 }
790
John Reck25fbb3f2014-06-12 13:46:45 -0700791 if (drawLayer) {
792 handler(new (alloc) DrawLayerOp(mLayer, 0, 0),
793 renderer.getSaveCount() - 1, properties().getClipToBounds());
794 } else {
Chris Craika7090e02014-06-20 16:01:00 -0700795 Vector<ZDrawRenderNodeOpPair> zTranslatedNodes;
John Reck25fbb3f2014-06-12 13:46:45 -0700796 buildZSortedChildList(zTranslatedNodes);
John Reck113e0822014-03-18 09:22:59 -0700797
John Reck25fbb3f2014-06-12 13:46:45 -0700798 // for 3d root, draw children with negative z values
Chris Craik80d49022014-06-20 15:03:43 -0700799 int shadowRestoreTo = issueOperationsOfNegZChildren(zTranslatedNodes, renderer, handler);
John Reck113e0822014-03-18 09:22:59 -0700800
John Reck25fbb3f2014-06-12 13:46:45 -0700801 DisplayListLogBuffer& logBuffer = DisplayListLogBuffer::getInstance();
802 const int saveCountOffset = renderer.getSaveCount() - 1;
803 const int projectionReceiveIndex = mDisplayListData->projectionReceiveIndex;
804 for (unsigned int i = 0; i < mDisplayListData->displayListOps.size(); i++) {
805 DisplayListOp *op = mDisplayListData->displayListOps[i];
John Reck113e0822014-03-18 09:22:59 -0700806
Chris Craik80d49022014-06-20 15:03:43 -0700807#if DEBUG_DISPLAY_LIST
John Reck25fbb3f2014-06-12 13:46:45 -0700808 op->output(level + 1);
Chris Craik80d49022014-06-20 15:03:43 -0700809#endif
John Reck25fbb3f2014-06-12 13:46:45 -0700810 logBuffer.writeCommand(level, op->name());
811 handler(op, saveCountOffset, properties().getClipToBounds());
John Reck113e0822014-03-18 09:22:59 -0700812
John Reck25fbb3f2014-06-12 13:46:45 -0700813 if (CC_UNLIKELY(i == projectionReceiveIndex && mProjectedNodes.size() > 0)) {
814 issueOperationsOfProjectedChildren(renderer, handler);
815 }
John Reck113e0822014-03-18 09:22:59 -0700816 }
John Reck113e0822014-03-18 09:22:59 -0700817
John Reck25fbb3f2014-06-12 13:46:45 -0700818 // for 3d root, draw children with positive z values
Chris Craik80d49022014-06-20 15:03:43 -0700819 issueOperationsOfPosZChildren(shadowRestoreTo, zTranslatedNodes, renderer, handler);
John Reck25fbb3f2014-06-12 13:46:45 -0700820 }
John Reck113e0822014-03-18 09:22:59 -0700821 }
822
823 DISPLAY_LIST_LOGD("%*sRestoreToCount %d", (level + 1) * 2, "", restoreTo);
824 handler(new (alloc) RestoreToCountOp(restoreTo),
John Reckd0a0b2a2014-03-20 16:28:56 -0700825 PROPERTY_SAVECOUNT, properties().getClipToBounds());
John Reck113e0822014-03-18 09:22:59 -0700826 renderer.setOverrideLayerAlpha(1.0f);
Chris Craikb265e2c2014-03-27 15:50:09 -0700827
Chris Craik3f0854292014-04-15 16:18:08 -0700828 DISPLAY_LIST_LOGD("%*sDone (%p, %s)", level * 2, "", this, getName());
Chris Craikb265e2c2014-03-27 15:50:09 -0700829 handler.endMark();
John Reck113e0822014-03-18 09:22:59 -0700830}
831
832} /* namespace uirenderer */
833} /* namespace android */