blob: e803ec3dc510135f65130553282bd0be357cf0cf [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 Recke4267ea2014-06-03 15:53:15 -0700198 if (info.mode == TreeInfo::MODE_FULL) {
John Reck25fbb3f2014-06-12 13:46:45 -0700199 pushStagingPropertiesChanges(info);
John Reck68bfe0a2014-06-24 15:34:58 -0700200 mAnimatorManager.animate(info);
John Recke4267ea2014-06-03 15:53:15 -0700201 } else if (info.mode == TreeInfo::MODE_MAYBE_DETACHING) {
John Reck25fbb3f2014-06-12 13:46:45 -0700202 pushStagingPropertiesChanges(info);
John Recke4267ea2014-06-03 15:53:15 -0700203 } else if (info.mode == TreeInfo::MODE_RT_ONLY) {
John Reck68bfe0a2014-06-24 15:34:58 -0700204 mAnimatorManager.animate(info);
John Recke45b1fd2014-04-15 09:50:16 -0700205 }
John Reck25fbb3f2014-06-12 13:46:45 -0700206
207 prepareLayer(info);
208 if (info.mode == TreeInfo::MODE_FULL) {
209 pushStagingDisplayListChanges(info);
210 }
John Reckf4198b72014-04-09 17:00:04 -0700211 prepareSubTree(info, mDisplayListData);
John Reck25fbb3f2014-06-12 13:46:45 -0700212 pushLayerUpdate(info);
213
John Recka447d292014-06-11 18:39:44 -0700214 info.damageAccumulator->popTransform();
John Reckf4198b72014-04-09 17:00:04 -0700215}
216
John Reck25fbb3f2014-06-12 13:46:45 -0700217void RenderNode::pushStagingPropertiesChanges(TreeInfo& info) {
John Reckff941dc2014-05-14 16:34:14 -0700218 // Push the animators first so that setupStartValueIfNecessary() is called
219 // before properties() is trampled by stagingProperties(), as they are
220 // required by some animators.
John Reck68bfe0a2014-06-24 15:34:58 -0700221 mAnimatorManager.pushStaging(info);
John Reckff941dc2014-05-14 16:34:14 -0700222 if (mDirtyPropertyFields) {
223 mDirtyPropertyFields = 0;
John Recke4267ea2014-06-03 15:53:15 -0700224 damageSelf(info);
John Recka447d292014-06-11 18:39:44 -0700225 info.damageAccumulator->popTransform();
John Reckff941dc2014-05-14 16:34:14 -0700226 mProperties = mStagingProperties;
John Reck25fbb3f2014-06-12 13:46:45 -0700227 applyLayerPropertiesToLayer(info);
John Recke4267ea2014-06-03 15:53:15 -0700228 // We could try to be clever and only re-damage if the matrix changed.
229 // However, we don't need to worry about that. The cost of over-damaging
230 // here is only going to be a single additional map rect of this node
231 // plus a rect join(). The parent's transform (and up) will only be
232 // performed once.
John Recka447d292014-06-11 18:39:44 -0700233 info.damageAccumulator->pushTransform(this);
John Recke4267ea2014-06-03 15:53:15 -0700234 damageSelf(info);
John Reckff941dc2014-05-14 16:34:14 -0700235 }
John Reck25fbb3f2014-06-12 13:46:45 -0700236}
237
238void RenderNode::applyLayerPropertiesToLayer(TreeInfo& info) {
239 if (CC_LIKELY(!mLayer)) return;
240
241 const LayerProperties& props = properties().layerProperties();
242 mLayer->setAlpha(props.alpha(), props.xferMode());
243 mLayer->setColorFilter(props.colorFilter());
244 mLayer->setBlend(props.needsBlending());
245}
246
247void RenderNode::pushStagingDisplayListChanges(TreeInfo& info) {
John Reck8de65a82014-04-09 15:23:38 -0700248 if (mNeedsDisplayListDataSync) {
249 mNeedsDisplayListDataSync = false;
250 // Do a push pass on the old tree to handle freeing DisplayListData
251 // that are no longer used
John Reck68bfe0a2014-06-24 15:34:58 -0700252 TreeInfo oldTreeInfo(TreeInfo::MODE_MAYBE_DETACHING, info);
John Reckf4198b72014-04-09 17:00:04 -0700253 prepareSubTree(oldTreeInfo, mDisplayListData);
John Reck8de65a82014-04-09 15:23:38 -0700254 delete mDisplayListData;
255 mDisplayListData = mStagingDisplayListData;
256 mStagingDisplayListData = 0;
John Recke4267ea2014-06-03 15:53:15 -0700257 damageSelf(info);
John Reck8de65a82014-04-09 15:23:38 -0700258 }
John Reck8de65a82014-04-09 15:23:38 -0700259}
260
John Reckf4198b72014-04-09 17:00:04 -0700261void RenderNode::prepareSubTree(TreeInfo& info, DisplayListData* subtree) {
John Reck8de65a82014-04-09 15:23:38 -0700262 if (subtree) {
John Reck860d1552014-04-11 19:15:05 -0700263 TextureCache& cache = Caches::getInstance().textureCache;
John Reckf9be7792014-05-02 18:21:16 -0700264 info.out.hasFunctors |= subtree->functorCount;
John Reck860d1552014-04-11 19:15:05 -0700265 // TODO: Fix ownedBitmapResources to not require disabling prepareTextures
266 // and thus falling out of async drawing path.
267 if (subtree->ownedBitmapResources.size()) {
268 info.prepareTextures = false;
269 }
270 for (size_t i = 0; info.prepareTextures && i < subtree->bitmapResources.size(); i++) {
271 info.prepareTextures = cache.prefetchAndMarkInUse(subtree->bitmapResources[i]);
John Reckf4198b72014-04-09 17:00:04 -0700272 }
John Reck8de65a82014-04-09 15:23:38 -0700273 for (size_t i = 0; i < subtree->children().size(); i++) {
Chris Craika7090e02014-06-20 16:01:00 -0700274 DrawRenderNodeOp* op = subtree->children()[i];
275 RenderNode* childNode = op->mRenderNode;
John Recka447d292014-06-11 18:39:44 -0700276 info.damageAccumulator->pushTransform(&op->mTransformFromParent);
John Reckf4198b72014-04-09 17:00:04 -0700277 childNode->prepareTreeImpl(info);
John Recka447d292014-06-11 18:39:44 -0700278 info.damageAccumulator->popTransform();
John Reck5bf11bb2014-03-25 10:22:09 -0700279 }
John Reck113e0822014-03-18 09:22:59 -0700280 }
281}
282
283/*
284 * For property operations, we pass a savecount of 0, since the operations aren't part of the
285 * displaylist, and thus don't have to compensate for the record-time/playback-time discrepancy in
John Reckd0a0b2a2014-03-20 16:28:56 -0700286 * base saveCount (i.e., how RestoreToCount uses saveCount + properties().getCount())
John Reck113e0822014-03-18 09:22:59 -0700287 */
288#define PROPERTY_SAVECOUNT 0
289
290template <class T>
Chris Craikb265e2c2014-03-27 15:50:09 -0700291void RenderNode::setViewProperties(OpenGLRenderer& renderer, T& handler) {
John Reck113e0822014-03-18 09:22:59 -0700292#if DEBUG_DISPLAY_LIST
Chris Craikb265e2c2014-03-27 15:50:09 -0700293 properties().debugOutputProperties(handler.level() + 1);
John Reck113e0822014-03-18 09:22:59 -0700294#endif
John Reckd0a0b2a2014-03-20 16:28:56 -0700295 if (properties().getLeft() != 0 || properties().getTop() != 0) {
296 renderer.translate(properties().getLeft(), properties().getTop());
John Reck113e0822014-03-18 09:22:59 -0700297 }
John Reckd0a0b2a2014-03-20 16:28:56 -0700298 if (properties().getStaticMatrix()) {
Derek Sollenberger13908822013-12-10 12:28:58 -0500299 renderer.concatMatrix(*properties().getStaticMatrix());
John Reckd0a0b2a2014-03-20 16:28:56 -0700300 } else if (properties().getAnimationMatrix()) {
Derek Sollenberger13908822013-12-10 12:28:58 -0500301 renderer.concatMatrix(*properties().getAnimationMatrix());
John Reck113e0822014-03-18 09:22:59 -0700302 }
John Reckf7483e32014-04-11 08:54:47 -0700303 if (properties().hasTransformMatrix()) {
304 if (properties().isTransformTranslateOnly()) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700305 renderer.translate(properties().getTranslationX(), properties().getTranslationY());
John Reck113e0822014-03-18 09:22:59 -0700306 } else {
John Reckd0a0b2a2014-03-20 16:28:56 -0700307 renderer.concatMatrix(*properties().getTransformMatrix());
John Reck113e0822014-03-18 09:22:59 -0700308 }
309 }
John Reck25fbb3f2014-06-12 13:46:45 -0700310 const bool isLayer = properties().layerProperties().type() != kLayerTypeNone;
311 bool clipToBoundsNeeded = isLayer ? false : properties().getClipToBounds();
John Reckd0a0b2a2014-03-20 16:28:56 -0700312 if (properties().getAlpha() < 1) {
John Reck25fbb3f2014-06-12 13:46:45 -0700313 if (isLayer) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700314 renderer.setOverrideLayerAlpha(properties().getAlpha());
315 } else if (!properties().getHasOverlappingRendering()) {
316 renderer.scaleAlpha(properties().getAlpha());
John Reck113e0822014-03-18 09:22:59 -0700317 } else {
318 // TODO: should be able to store the size of a DL at record time and not
319 // have to pass it into this call. In fact, this information might be in the
320 // location/size info that we store with the new native transform data.
321 int saveFlags = SkCanvas::kHasAlphaLayer_SaveFlag;
322 if (clipToBoundsNeeded) {
323 saveFlags |= SkCanvas::kClipToLayer_SaveFlag;
324 clipToBoundsNeeded = false; // clipping done by saveLayer
325 }
326
327 SaveLayerOp* op = new (handler.allocator()) SaveLayerOp(
Chris Craik8c271ca2014-03-25 10:33:01 -0700328 0, 0, properties().getWidth(), properties().getHeight(),
329 properties().getAlpha() * 255, saveFlags);
John Reckd0a0b2a2014-03-20 16:28:56 -0700330 handler(op, PROPERTY_SAVECOUNT, properties().getClipToBounds());
John Reck113e0822014-03-18 09:22:59 -0700331 }
332 }
333 if (clipToBoundsNeeded) {
Chris Craik8c271ca2014-03-25 10:33:01 -0700334 ClipRectOp* op = new (handler.allocator()) ClipRectOp(
335 0, 0, properties().getWidth(), properties().getHeight(), SkRegion::kIntersect_Op);
John Reckd0a0b2a2014-03-20 16:28:56 -0700336 handler(op, PROPERTY_SAVECOUNT, properties().getClipToBounds());
John Reck113e0822014-03-18 09:22:59 -0700337 }
Chris Craik8c271ca2014-03-25 10:33:01 -0700338
339 if (CC_UNLIKELY(properties().hasClippingPath())) {
Chris Craik2bcad172014-05-14 18:11:23 -0700340 ClipPathOp* op = new (handler.allocator()) ClipPathOp(
341 properties().getClippingPath(), properties().getClippingPathOp());
John Reckd0a0b2a2014-03-20 16:28:56 -0700342 handler(op, PROPERTY_SAVECOUNT, properties().getClipToBounds());
John Reck113e0822014-03-18 09:22:59 -0700343 }
344}
345
346/**
347 * Apply property-based transformations to input matrix
348 *
349 * If true3dTransform is set to true, the transform applied to the input matrix will use true 4x4
350 * matrix computation instead of the Skia 3x3 matrix + camera hackery.
351 */
352void RenderNode::applyViewPropertyTransforms(mat4& matrix, bool true3dTransform) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700353 if (properties().getLeft() != 0 || properties().getTop() != 0) {
354 matrix.translate(properties().getLeft(), properties().getTop());
John Reck113e0822014-03-18 09:22:59 -0700355 }
John Reckd0a0b2a2014-03-20 16:28:56 -0700356 if (properties().getStaticMatrix()) {
357 mat4 stat(*properties().getStaticMatrix());
John Reck113e0822014-03-18 09:22:59 -0700358 matrix.multiply(stat);
John Reckd0a0b2a2014-03-20 16:28:56 -0700359 } else if (properties().getAnimationMatrix()) {
360 mat4 anim(*properties().getAnimationMatrix());
John Reck113e0822014-03-18 09:22:59 -0700361 matrix.multiply(anim);
362 }
Chris Craike0bb87d2014-04-22 17:55:41 -0700363
Chris Craikcc39e162014-04-25 18:34:11 -0700364 bool applyTranslationZ = true3dTransform && !MathUtils::isZero(properties().getZ());
Chris Craike0bb87d2014-04-22 17:55:41 -0700365 if (properties().hasTransformMatrix() || applyTranslationZ) {
John Reckf7483e32014-04-11 08:54:47 -0700366 if (properties().isTransformTranslateOnly()) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700367 matrix.translate(properties().getTranslationX(), properties().getTranslationY(),
Chris Craikcc39e162014-04-25 18:34:11 -0700368 true3dTransform ? properties().getZ() : 0.0f);
John Reck113e0822014-03-18 09:22:59 -0700369 } else {
370 if (!true3dTransform) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700371 matrix.multiply(*properties().getTransformMatrix());
John Reck113e0822014-03-18 09:22:59 -0700372 } else {
373 mat4 true3dMat;
374 true3dMat.loadTranslate(
John Reckd0a0b2a2014-03-20 16:28:56 -0700375 properties().getPivotX() + properties().getTranslationX(),
376 properties().getPivotY() + properties().getTranslationY(),
Chris Craikcc39e162014-04-25 18:34:11 -0700377 properties().getZ());
John Reckd0a0b2a2014-03-20 16:28:56 -0700378 true3dMat.rotate(properties().getRotationX(), 1, 0, 0);
379 true3dMat.rotate(properties().getRotationY(), 0, 1, 0);
380 true3dMat.rotate(properties().getRotation(), 0, 0, 1);
381 true3dMat.scale(properties().getScaleX(), properties().getScaleY(), 1);
382 true3dMat.translate(-properties().getPivotX(), -properties().getPivotY());
John Reck113e0822014-03-18 09:22:59 -0700383
384 matrix.multiply(true3dMat);
385 }
386 }
387 }
388}
389
390/**
391 * Organizes the DisplayList hierarchy to prepare for background projection reordering.
392 *
393 * This should be called before a call to defer() or drawDisplayList()
394 *
395 * Each DisplayList that serves as a 3d root builds its list of composited children,
396 * which are flagged to not draw in the standard draw loop.
397 */
398void RenderNode::computeOrdering() {
399 ATRACE_CALL();
400 mProjectedNodes.clear();
401
402 // TODO: create temporary DDLOp and call computeOrderingImpl on top DisplayList so that
403 // transform properties are applied correctly to top level children
404 if (mDisplayListData == NULL) return;
John Reck087bc0c2014-04-04 16:20:08 -0700405 for (unsigned int i = 0; i < mDisplayListData->children().size(); i++) {
Chris Craika7090e02014-06-20 16:01:00 -0700406 DrawRenderNodeOp* childOp = mDisplayListData->children()[i];
407 childOp->mRenderNode->computeOrderingImpl(childOp,
Chris Craik3f0854292014-04-15 16:18:08 -0700408 properties().getOutline().getPath(), &mProjectedNodes, &mat4::identity());
John Reck113e0822014-03-18 09:22:59 -0700409 }
410}
411
412void RenderNode::computeOrderingImpl(
Chris Craika7090e02014-06-20 16:01:00 -0700413 DrawRenderNodeOp* opState,
Chris Craik3f0854292014-04-15 16:18:08 -0700414 const SkPath* outlineOfProjectionSurface,
Chris Craika7090e02014-06-20 16:01:00 -0700415 Vector<DrawRenderNodeOp*>* compositedChildrenOfProjectionSurface,
John Reck113e0822014-03-18 09:22:59 -0700416 const mat4* transformFromProjectionSurface) {
417 mProjectedNodes.clear();
418 if (mDisplayListData == NULL || mDisplayListData->isEmpty()) return;
419
420 // TODO: should avoid this calculation in most cases
421 // TODO: just calculate single matrix, down to all leaf composited elements
422 Matrix4 localTransformFromProjectionSurface(*transformFromProjectionSurface);
423 localTransformFromProjectionSurface.multiply(opState->mTransformFromParent);
424
John Reckd0a0b2a2014-03-20 16:28:56 -0700425 if (properties().getProjectBackwards()) {
John Reck113e0822014-03-18 09:22:59 -0700426 // composited projectee, flag for out of order draw, save matrix, and store in proj surface
427 opState->mSkipInOrderDraw = true;
428 opState->mTransformFromCompositingAncestor.load(localTransformFromProjectionSurface);
429 compositedChildrenOfProjectionSurface->add(opState);
430 } else {
431 // standard in order draw
432 opState->mSkipInOrderDraw = false;
433 }
434
John Reck087bc0c2014-04-04 16:20:08 -0700435 if (mDisplayListData->children().size() > 0) {
John Reck113e0822014-03-18 09:22:59 -0700436 const bool isProjectionReceiver = mDisplayListData->projectionReceiveIndex >= 0;
437 bool haveAppliedPropertiesToProjection = false;
John Reck087bc0c2014-04-04 16:20:08 -0700438 for (unsigned int i = 0; i < mDisplayListData->children().size(); i++) {
Chris Craika7090e02014-06-20 16:01:00 -0700439 DrawRenderNodeOp* childOp = mDisplayListData->children()[i];
440 RenderNode* child = childOp->mRenderNode;
John Reck113e0822014-03-18 09:22:59 -0700441
Chris Craik3f0854292014-04-15 16:18:08 -0700442 const SkPath* projectionOutline = NULL;
Chris Craika7090e02014-06-20 16:01:00 -0700443 Vector<DrawRenderNodeOp*>* projectionChildren = NULL;
John Reck113e0822014-03-18 09:22:59 -0700444 const mat4* projectionTransform = NULL;
John Reckd0a0b2a2014-03-20 16:28:56 -0700445 if (isProjectionReceiver && !child->properties().getProjectBackwards()) {
John Reck113e0822014-03-18 09:22:59 -0700446 // if receiving projections, collect projecting descendent
447
448 // Note that if a direct descendent is projecting backwards, we pass it's
449 // grandparent projection collection, since it shouldn't project onto it's
450 // parent, where it will already be drawing.
Chris Craik3f0854292014-04-15 16:18:08 -0700451 projectionOutline = properties().getOutline().getPath();
John Reck113e0822014-03-18 09:22:59 -0700452 projectionChildren = &mProjectedNodes;
453 projectionTransform = &mat4::identity();
454 } else {
455 if (!haveAppliedPropertiesToProjection) {
456 applyViewPropertyTransforms(localTransformFromProjectionSurface);
457 haveAppliedPropertiesToProjection = true;
458 }
Chris Craik3f0854292014-04-15 16:18:08 -0700459 projectionOutline = outlineOfProjectionSurface;
John Reck113e0822014-03-18 09:22:59 -0700460 projectionChildren = compositedChildrenOfProjectionSurface;
461 projectionTransform = &localTransformFromProjectionSurface;
462 }
Chris Craik3f0854292014-04-15 16:18:08 -0700463 child->computeOrderingImpl(childOp,
464 projectionOutline, projectionChildren, projectionTransform);
John Reck113e0822014-03-18 09:22:59 -0700465 }
466 }
John Reck113e0822014-03-18 09:22:59 -0700467}
468
469class DeferOperationHandler {
470public:
471 DeferOperationHandler(DeferStateStruct& deferStruct, int level)
472 : mDeferStruct(deferStruct), mLevel(level) {}
473 inline void operator()(DisplayListOp* operation, int saveCount, bool clipToBounds) {
474 operation->defer(mDeferStruct, saveCount, mLevel, clipToBounds);
475 }
476 inline LinearAllocator& allocator() { return *(mDeferStruct.mAllocator); }
Chris Craikb265e2c2014-03-27 15:50:09 -0700477 inline void startMark(const char* name) {} // do nothing
478 inline void endMark() {}
479 inline int level() { return mLevel; }
480 inline int replayFlags() { return mDeferStruct.mReplayFlags; }
John Reck113e0822014-03-18 09:22:59 -0700481
482private:
483 DeferStateStruct& mDeferStruct;
484 const int mLevel;
485};
486
Chris Craik80d49022014-06-20 15:03:43 -0700487void RenderNode::defer(DeferStateStruct& deferStruct, const int level) {
John Reck113e0822014-03-18 09:22:59 -0700488 DeferOperationHandler handler(deferStruct, level);
Chris Craikb265e2c2014-03-27 15:50:09 -0700489 issueOperations<DeferOperationHandler>(deferStruct.mRenderer, handler);
John Reck113e0822014-03-18 09:22:59 -0700490}
491
492class ReplayOperationHandler {
493public:
494 ReplayOperationHandler(ReplayStateStruct& replayStruct, int level)
495 : mReplayStruct(replayStruct), mLevel(level) {}
496 inline void operator()(DisplayListOp* operation, int saveCount, bool clipToBounds) {
497#if DEBUG_DISPLAY_LIST_OPS_AS_EVENTS
Chris Craik3f0854292014-04-15 16:18:08 -0700498 mReplayStruct.mRenderer.eventMark(operation->name());
John Reck113e0822014-03-18 09:22:59 -0700499#endif
500 operation->replay(mReplayStruct, saveCount, mLevel, clipToBounds);
501 }
502 inline LinearAllocator& allocator() { return *(mReplayStruct.mAllocator); }
Chris Craikb265e2c2014-03-27 15:50:09 -0700503 inline void startMark(const char* name) {
504 mReplayStruct.mRenderer.startMark(name);
505 }
506 inline void endMark() {
507 mReplayStruct.mRenderer.endMark();
Chris Craikb265e2c2014-03-27 15:50:09 -0700508 }
509 inline int level() { return mLevel; }
510 inline int replayFlags() { return mReplayStruct.mReplayFlags; }
John Reck113e0822014-03-18 09:22:59 -0700511
512private:
513 ReplayStateStruct& mReplayStruct;
514 const int mLevel;
515};
516
Chris Craik80d49022014-06-20 15:03:43 -0700517void RenderNode::replay(ReplayStateStruct& replayStruct, const int level) {
John Reck113e0822014-03-18 09:22:59 -0700518 ReplayOperationHandler handler(replayStruct, level);
Chris Craikb265e2c2014-03-27 15:50:09 -0700519 issueOperations<ReplayOperationHandler>(replayStruct.mRenderer, handler);
John Reck113e0822014-03-18 09:22:59 -0700520}
521
Chris Craika7090e02014-06-20 16:01:00 -0700522void RenderNode::buildZSortedChildList(Vector<ZDrawRenderNodeOpPair>& zTranslatedNodes) {
John Reck087bc0c2014-04-04 16:20:08 -0700523 if (mDisplayListData == NULL || mDisplayListData->children().size() == 0) return;
John Reck113e0822014-03-18 09:22:59 -0700524
John Reck087bc0c2014-04-04 16:20:08 -0700525 for (unsigned int i = 0; i < mDisplayListData->children().size(); i++) {
Chris Craika7090e02014-06-20 16:01:00 -0700526 DrawRenderNodeOp* childOp = mDisplayListData->children()[i];
527 RenderNode* child = childOp->mRenderNode;
Chris Craikcc39e162014-04-25 18:34:11 -0700528 float childZ = child->properties().getZ();
John Reck113e0822014-03-18 09:22:59 -0700529
Chris Craike0bb87d2014-04-22 17:55:41 -0700530 if (!MathUtils::isZero(childZ)) {
Chris Craika7090e02014-06-20 16:01:00 -0700531 zTranslatedNodes.add(ZDrawRenderNodeOpPair(childZ, childOp));
John Reck113e0822014-03-18 09:22:59 -0700532 childOp->mSkipInOrderDraw = true;
John Reckd0a0b2a2014-03-20 16:28:56 -0700533 } else if (!child->properties().getProjectBackwards()) {
John Reck113e0822014-03-18 09:22:59 -0700534 // regular, in order drawing DisplayList
535 childOp->mSkipInOrderDraw = false;
536 }
537 }
538
539 // Z sort 3d children (stable-ness makes z compare fall back to standard drawing order)
540 std::stable_sort(zTranslatedNodes.begin(), zTranslatedNodes.end());
541}
542
Chris Craikb265e2c2014-03-27 15:50:09 -0700543template <class T>
544void RenderNode::issueDrawShadowOperation(const Matrix4& transformFromParent, T& handler) {
Chris Craik61317322014-05-21 13:03:52 -0700545 if (properties().getAlpha() <= 0.0f || properties().getOutline().isEmpty()) return;
Chris Craikb265e2c2014-03-27 15:50:09 -0700546
547 mat4 shadowMatrixXY(transformFromParent);
548 applyViewPropertyTransforms(shadowMatrixXY);
549
550 // Z matrix needs actual 3d transformation, so mapped z values will be correct
551 mat4 shadowMatrixZ(transformFromParent);
552 applyViewPropertyTransforms(shadowMatrixZ, true);
553
554 const SkPath* outlinePath = properties().getOutline().getPath();
555 const RevealClip& revealClip = properties().getRevealClip();
556 const SkPath* revealClipPath = revealClip.hasConvexClip()
557 ? revealClip.getPath() : NULL; // only pass the reveal clip's path if it's convex
558
Chris Craik61317322014-05-21 13:03:52 -0700559 if (revealClipPath && revealClipPath->isEmpty()) return;
560
Chris Craikb265e2c2014-03-27 15:50:09 -0700561 /**
562 * The drawing area of the caster is always the same as the its perimeter (which
563 * the shadow system uses) *except* in the inverse clip case. Inform the shadow
564 * system that the caster's drawing area (as opposed to its perimeter) has been
565 * clipped, so that it knows the caster can't be opaque.
566 */
567 bool casterUnclipped = !revealClip.willClip() || revealClip.hasConvexClip();
568
569 DisplayListOp* shadowOp = new (handler.allocator()) DrawShadowOp(
570 shadowMatrixXY, shadowMatrixZ,
571 properties().getAlpha(), casterUnclipped,
Chris Craikb265e2c2014-03-27 15:50:09 -0700572 outlinePath, revealClipPath);
573 handler(shadowOp, PROPERTY_SAVECOUNT, properties().getClipToBounds());
574}
575
Chris Craik80d49022014-06-20 15:03:43 -0700576template <class T>
577int RenderNode::issueOperationsOfNegZChildren(
Chris Craika7090e02014-06-20 16:01:00 -0700578 const Vector<ZDrawRenderNodeOpPair>& zTranslatedNodes,
Chris Craik80d49022014-06-20 15:03:43 -0700579 OpenGLRenderer& renderer, T& handler) {
580 if (zTranslatedNodes.isEmpty()) return -1;
581
582 // create a save around the body of the ViewGroup's draw method, so that
583 // matrix/clip methods don't affect composited children
584 int shadowSaveCount = renderer.getSaveCount();
585 handler(new (handler.allocator()) SaveOp(SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag),
586 PROPERTY_SAVECOUNT, properties().getClipToBounds());
587
588 issueOperationsOf3dChildren(zTranslatedNodes, kNegativeZChildren, renderer, handler);
589 return shadowSaveCount;
590}
591
592template <class T>
593void RenderNode::issueOperationsOfPosZChildren(int shadowRestoreTo,
Chris Craika7090e02014-06-20 16:01:00 -0700594 const Vector<ZDrawRenderNodeOpPair>& zTranslatedNodes,
Chris Craik80d49022014-06-20 15:03:43 -0700595 OpenGLRenderer& renderer, T& handler) {
596 if (zTranslatedNodes.isEmpty()) return;
597
598 LOG_ALWAYS_FATAL_IF(shadowRestoreTo < 0, "invalid save to restore to");
599 handler(new (handler.allocator()) RestoreToCountOp(shadowRestoreTo),
600 PROPERTY_SAVECOUNT, properties().getClipToBounds());
601 renderer.setOverrideLayerAlpha(1.0f);
602
603 issueOperationsOf3dChildren(zTranslatedNodes, kPositiveZChildren, renderer, handler);
604}
605
John Reck113e0822014-03-18 09:22:59 -0700606#define SHADOW_DELTA 0.1f
607
608template <class T>
Chris Craika7090e02014-06-20 16:01:00 -0700609void RenderNode::issueOperationsOf3dChildren(const Vector<ZDrawRenderNodeOpPair>& zTranslatedNodes,
John Reck113e0822014-03-18 09:22:59 -0700610 ChildrenSelectMode mode, OpenGLRenderer& renderer, T& handler) {
611 const int size = zTranslatedNodes.size();
612 if (size == 0
613 || (mode == kNegativeZChildren && zTranslatedNodes[0].key > 0.0f)
614 || (mode == kPositiveZChildren && zTranslatedNodes[size - 1].key < 0.0f)) {
615 // no 3d children to draw
616 return;
617 }
618
John Reck113e0822014-03-18 09:22:59 -0700619 /**
620 * Draw shadows and (potential) casters mostly in order, but allow the shadows of casters
621 * with very similar Z heights to draw together.
622 *
623 * This way, if Views A & B have the same Z height and are both casting shadows, the shadows are
624 * underneath both, and neither's shadow is drawn on top of the other.
625 */
626 const size_t nonNegativeIndex = findNonNegativeIndex(zTranslatedNodes);
627 size_t drawIndex, shadowIndex, endIndex;
628 if (mode == kNegativeZChildren) {
629 drawIndex = 0;
630 endIndex = nonNegativeIndex;
631 shadowIndex = endIndex; // draw no shadows
632 } else {
633 drawIndex = nonNegativeIndex;
634 endIndex = size;
635 shadowIndex = drawIndex; // potentially draw shadow for each pos Z child
636 }
Chris Craik3f0854292014-04-15 16:18:08 -0700637
638 DISPLAY_LIST_LOGD("%*s%d %s 3d children:", (handler.level() + 1) * 2, "",
639 endIndex - drawIndex, mode == kNegativeZChildren ? "negative" : "positive");
640
John Reck113e0822014-03-18 09:22:59 -0700641 float lastCasterZ = 0.0f;
642 while (shadowIndex < endIndex || drawIndex < endIndex) {
643 if (shadowIndex < endIndex) {
Chris Craika7090e02014-06-20 16:01:00 -0700644 DrawRenderNodeOp* casterOp = zTranslatedNodes[shadowIndex].value;
645 RenderNode* caster = casterOp->mRenderNode;
John Reck113e0822014-03-18 09:22:59 -0700646 const float casterZ = zTranslatedNodes[shadowIndex].key;
647 // attempt to render the shadow if the caster about to be drawn is its caster,
648 // OR if its caster's Z value is similar to the previous potential caster
649 if (shadowIndex == drawIndex || casterZ - lastCasterZ < SHADOW_DELTA) {
Chris Craikb265e2c2014-03-27 15:50:09 -0700650 caster->issueDrawShadowOperation(casterOp->mTransformFromParent, handler);
John Reck113e0822014-03-18 09:22:59 -0700651
652 lastCasterZ = casterZ; // must do this even if current caster not casting a shadow
653 shadowIndex++;
654 continue;
655 }
656 }
657
658 // only the actual child DL draw needs to be in save/restore,
659 // since it modifies the renderer's matrix
660 int restoreTo = renderer.save(SkCanvas::kMatrix_SaveFlag);
661
Chris Craika7090e02014-06-20 16:01:00 -0700662 DrawRenderNodeOp* childOp = zTranslatedNodes[drawIndex].value;
663 RenderNode* child = childOp->mRenderNode;
John Reck113e0822014-03-18 09:22:59 -0700664
665 renderer.concatMatrix(childOp->mTransformFromParent);
666 childOp->mSkipInOrderDraw = false; // this is horrible, I'm so sorry everyone
John Reckd0a0b2a2014-03-20 16:28:56 -0700667 handler(childOp, renderer.getSaveCount() - 1, properties().getClipToBounds());
John Reck113e0822014-03-18 09:22:59 -0700668 childOp->mSkipInOrderDraw = true;
669
670 renderer.restoreToCount(restoreTo);
671 drawIndex++;
672 }
John Reck113e0822014-03-18 09:22:59 -0700673}
674
675template <class T>
Chris Craikb265e2c2014-03-27 15:50:09 -0700676void RenderNode::issueOperationsOfProjectedChildren(OpenGLRenderer& renderer, T& handler) {
Chris Craik3f0854292014-04-15 16:18:08 -0700677 DISPLAY_LIST_LOGD("%*s%d projected children:", (handler.level() + 1) * 2, "", mProjectedNodes.size());
678 const SkPath* projectionReceiverOutline = properties().getOutline().getPath();
Chris Craik3f0854292014-04-15 16:18:08 -0700679 int restoreTo = renderer.getSaveCount();
680
681 // If the projection reciever has an outline, we mask each of the projected rendernodes to it
682 // Either with clipRect, or special saveLayer masking
683 LinearAllocator& alloc = handler.allocator();
684 if (projectionReceiverOutline != NULL) {
685 const SkRect& outlineBounds = projectionReceiverOutline->getBounds();
686 if (projectionReceiverOutline->isRect(NULL)) {
687 // mask to the rect outline simply with clipRect
688 handler(new (alloc) SaveOp(SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag),
689 PROPERTY_SAVECOUNT, properties().getClipToBounds());
690 ClipRectOp* clipOp = new (alloc) ClipRectOp(
691 outlineBounds.left(), outlineBounds.top(),
692 outlineBounds.right(), outlineBounds.bottom(), SkRegion::kIntersect_Op);
693 handler(clipOp, PROPERTY_SAVECOUNT, properties().getClipToBounds());
694 } else {
695 // wrap the projected RenderNodes with a SaveLayer that will mask to the outline
696 SaveLayerOp* op = new (alloc) SaveLayerOp(
697 outlineBounds.left(), outlineBounds.top(),
698 outlineBounds.right(), outlineBounds.bottom(),
Chris Craik80d49022014-06-20 15:03:43 -0700699 255, SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag | SkCanvas::kARGB_ClipLayer_SaveFlag);
Chris Craik3f0854292014-04-15 16:18:08 -0700700 op->setMask(projectionReceiverOutline);
701 handler(op, PROPERTY_SAVECOUNT, properties().getClipToBounds());
702
703 /* TODO: add optimizations here to take advantage of placement/size of projected
704 * children (which may shrink saveLayer area significantly). This is dependent on
705 * passing actual drawing/dirtying bounds of projected content down to native.
706 */
707 }
708 }
709
710 // draw projected nodes
John Reck113e0822014-03-18 09:22:59 -0700711 for (size_t i = 0; i < mProjectedNodes.size(); i++) {
Chris Craika7090e02014-06-20 16:01:00 -0700712 DrawRenderNodeOp* childOp = mProjectedNodes[i];
John Reck113e0822014-03-18 09:22:59 -0700713
714 // matrix save, concat, and restore can be done safely without allocating operations
715 int restoreTo = renderer.save(SkCanvas::kMatrix_SaveFlag);
716 renderer.concatMatrix(childOp->mTransformFromCompositingAncestor);
717 childOp->mSkipInOrderDraw = false; // this is horrible, I'm so sorry everyone
John Reckd0a0b2a2014-03-20 16:28:56 -0700718 handler(childOp, renderer.getSaveCount() - 1, properties().getClipToBounds());
John Reck113e0822014-03-18 09:22:59 -0700719 childOp->mSkipInOrderDraw = true;
720 renderer.restoreToCount(restoreTo);
721 }
Chris Craik3f0854292014-04-15 16:18:08 -0700722
723 if (projectionReceiverOutline != NULL) {
724 handler(new (alloc) RestoreToCountOp(restoreTo),
725 PROPERTY_SAVECOUNT, properties().getClipToBounds());
726 }
John Reck113e0822014-03-18 09:22:59 -0700727}
728
729/**
730 * This function serves both defer and replay modes, and will organize the displayList's component
731 * operations for a single frame:
732 *
733 * Every 'simple' state operation that affects just the matrix and alpha (or other factors of
734 * DeferredDisplayState) may be issued directly to the renderer, but complex operations (with custom
735 * defer logic) and operations in displayListOps are issued through the 'handler' which handles the
736 * defer vs replay logic, per operation
737 */
738template <class T>
Chris Craikb265e2c2014-03-27 15:50:09 -0700739void RenderNode::issueOperations(OpenGLRenderer& renderer, T& handler) {
John Reck25fbb3f2014-06-12 13:46:45 -0700740 const bool drawLayer = (mLayer && (&renderer != mLayer->renderer));
741 // If we are updating the contents of mLayer, we don't want to apply any of
742 // the RenderNode's properties to this issueOperations pass. Those will all
743 // be applied when the layer is drawn, aka when this is true.
744 const bool useViewProperties = (!mLayer || drawLayer);
745
Chris Craikb265e2c2014-03-27 15:50:09 -0700746 const int level = handler.level();
John Reck25fbb3f2014-06-12 13:46:45 -0700747 if (mDisplayListData->isEmpty() || (useViewProperties && properties().getAlpha() <= 0)) {
Chris Craik3f0854292014-04-15 16:18:08 -0700748 DISPLAY_LIST_LOGD("%*sEmpty display list (%p, %s)", level * 2, "", this, getName());
John Reck113e0822014-03-18 09:22:59 -0700749 return;
750 }
751
Chris Craik3f0854292014-04-15 16:18:08 -0700752 handler.startMark(getName());
Chris Craikb265e2c2014-03-27 15:50:09 -0700753
John Reck113e0822014-03-18 09:22:59 -0700754#if DEBUG_DISPLAY_LIST
Chris Craik3f0854292014-04-15 16:18:08 -0700755 const Rect& clipRect = renderer.getLocalClipBounds();
756 DISPLAY_LIST_LOGD("%*sStart display list (%p, %s), localClipBounds: %.0f, %.0f, %.0f, %.0f",
757 level * 2, "", this, getName(),
758 clipRect.left, clipRect.top, clipRect.right, clipRect.bottom);
John Reck113e0822014-03-18 09:22:59 -0700759#endif
760
761 LinearAllocator& alloc = handler.allocator();
762 int restoreTo = renderer.getSaveCount();
763 handler(new (alloc) SaveOp(SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag),
John Reckd0a0b2a2014-03-20 16:28:56 -0700764 PROPERTY_SAVECOUNT, properties().getClipToBounds());
John Reck113e0822014-03-18 09:22:59 -0700765
766 DISPLAY_LIST_LOGD("%*sSave %d %d", (level + 1) * 2, "",
767 SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag, restoreTo);
768
John Reck25fbb3f2014-06-12 13:46:45 -0700769 if (useViewProperties) {
770 setViewProperties<T>(renderer, handler);
771 }
John Reck113e0822014-03-18 09:22:59 -0700772
Chris Craik8c271ca2014-03-25 10:33:01 -0700773 bool quickRejected = properties().getClipToBounds()
774 && renderer.quickRejectConservative(0, 0, properties().getWidth(), properties().getHeight());
John Reck113e0822014-03-18 09:22:59 -0700775 if (!quickRejected) {
Chris Craikdeeda3d2014-05-05 19:09:33 -0700776 if (mProperties.getOutline().willClip()) {
777 renderer.setClippingOutline(alloc, &(mProperties.getOutline()));
778 }
779
John Reck25fbb3f2014-06-12 13:46:45 -0700780 if (drawLayer) {
781 handler(new (alloc) DrawLayerOp(mLayer, 0, 0),
782 renderer.getSaveCount() - 1, properties().getClipToBounds());
783 } else {
Chris Craika7090e02014-06-20 16:01:00 -0700784 Vector<ZDrawRenderNodeOpPair> zTranslatedNodes;
John Reck25fbb3f2014-06-12 13:46:45 -0700785 buildZSortedChildList(zTranslatedNodes);
John Reck113e0822014-03-18 09:22:59 -0700786
John Reck25fbb3f2014-06-12 13:46:45 -0700787 // for 3d root, draw children with negative z values
Chris Craik80d49022014-06-20 15:03:43 -0700788 int shadowRestoreTo = issueOperationsOfNegZChildren(zTranslatedNodes, renderer, handler);
John Reck113e0822014-03-18 09:22:59 -0700789
John Reck25fbb3f2014-06-12 13:46:45 -0700790 DisplayListLogBuffer& logBuffer = DisplayListLogBuffer::getInstance();
791 const int saveCountOffset = renderer.getSaveCount() - 1;
792 const int projectionReceiveIndex = mDisplayListData->projectionReceiveIndex;
793 for (unsigned int i = 0; i < mDisplayListData->displayListOps.size(); i++) {
794 DisplayListOp *op = mDisplayListData->displayListOps[i];
John Reck113e0822014-03-18 09:22:59 -0700795
Chris Craik80d49022014-06-20 15:03:43 -0700796#if DEBUG_DISPLAY_LIST
John Reck25fbb3f2014-06-12 13:46:45 -0700797 op->output(level + 1);
Chris Craik80d49022014-06-20 15:03:43 -0700798#endif
John Reck25fbb3f2014-06-12 13:46:45 -0700799 logBuffer.writeCommand(level, op->name());
800 handler(op, saveCountOffset, properties().getClipToBounds());
John Reck113e0822014-03-18 09:22:59 -0700801
John Reck25fbb3f2014-06-12 13:46:45 -0700802 if (CC_UNLIKELY(i == projectionReceiveIndex && mProjectedNodes.size() > 0)) {
803 issueOperationsOfProjectedChildren(renderer, handler);
804 }
John Reck113e0822014-03-18 09:22:59 -0700805 }
John Reck113e0822014-03-18 09:22:59 -0700806
John Reck25fbb3f2014-06-12 13:46:45 -0700807 // for 3d root, draw children with positive z values
Chris Craik80d49022014-06-20 15:03:43 -0700808 issueOperationsOfPosZChildren(shadowRestoreTo, zTranslatedNodes, renderer, handler);
John Reck25fbb3f2014-06-12 13:46:45 -0700809 }
John Reck113e0822014-03-18 09:22:59 -0700810 }
811
812 DISPLAY_LIST_LOGD("%*sRestoreToCount %d", (level + 1) * 2, "", restoreTo);
813 handler(new (alloc) RestoreToCountOp(restoreTo),
John Reckd0a0b2a2014-03-20 16:28:56 -0700814 PROPERTY_SAVECOUNT, properties().getClipToBounds());
John Reck113e0822014-03-18 09:22:59 -0700815 renderer.setOverrideLayerAlpha(1.0f);
Chris Craikb265e2c2014-03-27 15:50:09 -0700816
Chris Craik3f0854292014-04-15 16:18:08 -0700817 DISPLAY_LIST_LOGD("%*sDone (%p, %s)", level * 2, "", this, getName());
Chris Craikb265e2c2014-03-27 15:50:09 -0700818 handler.endMark();
John Reck113e0822014-03-18 09:22:59 -0700819}
820
821} /* namespace uirenderer */
822} /* namespace android */