blob: 3cf625fc08eb9b65e54ba5396cd216f2741fe413 [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
John Reckec0c9252014-07-07 16:30:41 -0700214 LOG_ALWAYS_FATAL_IF(mStagingDisplayListData || (mDisplayListData && !mNeedsDisplayListDataSync),
215 "View.destroyHardwareResources wasn't called!");
John Reckf47a5942014-06-30 16:20:04 -0700216 break;
John Recke45b1fd2014-04-15 09:50:16 -0700217 }
John Reck25fbb3f2014-06-12 13:46:45 -0700218
219 prepareLayer(info);
John Reckf47a5942014-06-30 16:20:04 -0700220 if (info.mode == TreeInfo::MODE_FULL || info.mode == TreeInfo::MODE_DESTROY_RESOURCES) {
John Reck25fbb3f2014-06-12 13:46:45 -0700221 pushStagingDisplayListChanges(info);
222 }
John Reckf4198b72014-04-09 17:00:04 -0700223 prepareSubTree(info, mDisplayListData);
John Reck25fbb3f2014-06-12 13:46:45 -0700224 pushLayerUpdate(info);
225
John Recka447d292014-06-11 18:39:44 -0700226 info.damageAccumulator->popTransform();
John Reckf4198b72014-04-09 17:00:04 -0700227}
228
John Reck25fbb3f2014-06-12 13:46:45 -0700229void RenderNode::pushStagingPropertiesChanges(TreeInfo& info) {
John Reckff941dc2014-05-14 16:34:14 -0700230 // Push the animators first so that setupStartValueIfNecessary() is called
231 // before properties() is trampled by stagingProperties(), as they are
232 // required by some animators.
John Reck68bfe0a2014-06-24 15:34:58 -0700233 mAnimatorManager.pushStaging(info);
John Reckff941dc2014-05-14 16:34:14 -0700234 if (mDirtyPropertyFields) {
235 mDirtyPropertyFields = 0;
John Recke4267ea2014-06-03 15:53:15 -0700236 damageSelf(info);
John Recka447d292014-06-11 18:39:44 -0700237 info.damageAccumulator->popTransform();
John Reckff941dc2014-05-14 16:34:14 -0700238 mProperties = mStagingProperties;
John Reck25fbb3f2014-06-12 13:46:45 -0700239 applyLayerPropertiesToLayer(info);
John Recke4267ea2014-06-03 15:53:15 -0700240 // We could try to be clever and only re-damage if the matrix changed.
241 // However, we don't need to worry about that. The cost of over-damaging
242 // here is only going to be a single additional map rect of this node
243 // plus a rect join(). The parent's transform (and up) will only be
244 // performed once.
John Recka447d292014-06-11 18:39:44 -0700245 info.damageAccumulator->pushTransform(this);
John Recke4267ea2014-06-03 15:53:15 -0700246 damageSelf(info);
John Reckff941dc2014-05-14 16:34:14 -0700247 }
John Reck25fbb3f2014-06-12 13:46:45 -0700248}
249
250void RenderNode::applyLayerPropertiesToLayer(TreeInfo& info) {
251 if (CC_LIKELY(!mLayer)) return;
252
253 const LayerProperties& props = properties().layerProperties();
254 mLayer->setAlpha(props.alpha(), props.xferMode());
255 mLayer->setColorFilter(props.colorFilter());
256 mLayer->setBlend(props.needsBlending());
257}
258
259void RenderNode::pushStagingDisplayListChanges(TreeInfo& info) {
John Reck8de65a82014-04-09 15:23:38 -0700260 if (mNeedsDisplayListDataSync) {
261 mNeedsDisplayListDataSync = false;
262 // Do a push pass on the old tree to handle freeing DisplayListData
263 // that are no longer used
John Reckec0c9252014-07-07 16:30:41 -0700264 TreeInfo::TraversalMode mode = TreeInfo::MODE_MAYBE_DETACHING;
265 if (CC_UNLIKELY(info.mode == TreeInfo::MODE_DESTROY_RESOURCES)) {
266 mode = TreeInfo::MODE_DESTROY_RESOURCES;
267 }
268 TreeInfo oldTreeInfo(mode, info);
John Reckf4198b72014-04-09 17:00:04 -0700269 prepareSubTree(oldTreeInfo, mDisplayListData);
John Reck8de65a82014-04-09 15:23:38 -0700270 delete mDisplayListData;
271 mDisplayListData = mStagingDisplayListData;
272 mStagingDisplayListData = 0;
John Recke4267ea2014-06-03 15:53:15 -0700273 damageSelf(info);
John Reck8de65a82014-04-09 15:23:38 -0700274 }
John Reck8de65a82014-04-09 15:23:38 -0700275}
276
John Reckf4198b72014-04-09 17:00:04 -0700277void RenderNode::prepareSubTree(TreeInfo& info, DisplayListData* subtree) {
John Reck8de65a82014-04-09 15:23:38 -0700278 if (subtree) {
John Reck860d1552014-04-11 19:15:05 -0700279 TextureCache& cache = Caches::getInstance().textureCache;
John Reckf9be7792014-05-02 18:21:16 -0700280 info.out.hasFunctors |= subtree->functorCount;
John Reck860d1552014-04-11 19:15:05 -0700281 // TODO: Fix ownedBitmapResources to not require disabling prepareTextures
282 // and thus falling out of async drawing path.
283 if (subtree->ownedBitmapResources.size()) {
284 info.prepareTextures = false;
285 }
286 for (size_t i = 0; info.prepareTextures && i < subtree->bitmapResources.size(); i++) {
287 info.prepareTextures = cache.prefetchAndMarkInUse(subtree->bitmapResources[i]);
John Reckf4198b72014-04-09 17:00:04 -0700288 }
John Reck8de65a82014-04-09 15:23:38 -0700289 for (size_t i = 0; i < subtree->children().size(); i++) {
Chris Craika7090e02014-06-20 16:01:00 -0700290 DrawRenderNodeOp* op = subtree->children()[i];
291 RenderNode* childNode = op->mRenderNode;
John Recka447d292014-06-11 18:39:44 -0700292 info.damageAccumulator->pushTransform(&op->mTransformFromParent);
John Reckf4198b72014-04-09 17:00:04 -0700293 childNode->prepareTreeImpl(info);
John Recka447d292014-06-11 18:39:44 -0700294 info.damageAccumulator->popTransform();
John Reck5bf11bb2014-03-25 10:22:09 -0700295 }
John Reck113e0822014-03-18 09:22:59 -0700296 }
297}
298
299/*
300 * For property operations, we pass a savecount of 0, since the operations aren't part of the
301 * displaylist, and thus don't have to compensate for the record-time/playback-time discrepancy in
John Reckd0a0b2a2014-03-20 16:28:56 -0700302 * base saveCount (i.e., how RestoreToCount uses saveCount + properties().getCount())
John Reck113e0822014-03-18 09:22:59 -0700303 */
304#define PROPERTY_SAVECOUNT 0
305
306template <class T>
Chris Craikb265e2c2014-03-27 15:50:09 -0700307void RenderNode::setViewProperties(OpenGLRenderer& renderer, T& handler) {
John Reck113e0822014-03-18 09:22:59 -0700308#if DEBUG_DISPLAY_LIST
Chris Craikb265e2c2014-03-27 15:50:09 -0700309 properties().debugOutputProperties(handler.level() + 1);
John Reck113e0822014-03-18 09:22:59 -0700310#endif
John Reckd0a0b2a2014-03-20 16:28:56 -0700311 if (properties().getLeft() != 0 || properties().getTop() != 0) {
312 renderer.translate(properties().getLeft(), properties().getTop());
John Reck113e0822014-03-18 09:22:59 -0700313 }
John Reckd0a0b2a2014-03-20 16:28:56 -0700314 if (properties().getStaticMatrix()) {
Derek Sollenberger13908822013-12-10 12:28:58 -0500315 renderer.concatMatrix(*properties().getStaticMatrix());
John Reckd0a0b2a2014-03-20 16:28:56 -0700316 } else if (properties().getAnimationMatrix()) {
Derek Sollenberger13908822013-12-10 12:28:58 -0500317 renderer.concatMatrix(*properties().getAnimationMatrix());
John Reck113e0822014-03-18 09:22:59 -0700318 }
John Reckf7483e32014-04-11 08:54:47 -0700319 if (properties().hasTransformMatrix()) {
320 if (properties().isTransformTranslateOnly()) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700321 renderer.translate(properties().getTranslationX(), properties().getTranslationY());
John Reck113e0822014-03-18 09:22:59 -0700322 } else {
John Reckd0a0b2a2014-03-20 16:28:56 -0700323 renderer.concatMatrix(*properties().getTransformMatrix());
John Reck113e0822014-03-18 09:22:59 -0700324 }
325 }
John Reck25fbb3f2014-06-12 13:46:45 -0700326 const bool isLayer = properties().layerProperties().type() != kLayerTypeNone;
327 bool clipToBoundsNeeded = isLayer ? false : properties().getClipToBounds();
John Reckd0a0b2a2014-03-20 16:28:56 -0700328 if (properties().getAlpha() < 1) {
John Reck25fbb3f2014-06-12 13:46:45 -0700329 if (isLayer) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700330 renderer.setOverrideLayerAlpha(properties().getAlpha());
331 } else if (!properties().getHasOverlappingRendering()) {
332 renderer.scaleAlpha(properties().getAlpha());
John Reck113e0822014-03-18 09:22:59 -0700333 } else {
334 // TODO: should be able to store the size of a DL at record time and not
335 // have to pass it into this call. In fact, this information might be in the
336 // location/size info that we store with the new native transform data.
337 int saveFlags = SkCanvas::kHasAlphaLayer_SaveFlag;
338 if (clipToBoundsNeeded) {
339 saveFlags |= SkCanvas::kClipToLayer_SaveFlag;
340 clipToBoundsNeeded = false; // clipping done by saveLayer
341 }
342
343 SaveLayerOp* op = new (handler.allocator()) SaveLayerOp(
Chris Craik8c271ca2014-03-25 10:33:01 -0700344 0, 0, properties().getWidth(), properties().getHeight(),
345 properties().getAlpha() * 255, saveFlags);
John Reckd0a0b2a2014-03-20 16:28:56 -0700346 handler(op, PROPERTY_SAVECOUNT, properties().getClipToBounds());
John Reck113e0822014-03-18 09:22:59 -0700347 }
348 }
349 if (clipToBoundsNeeded) {
Chris Craik8c271ca2014-03-25 10:33:01 -0700350 ClipRectOp* op = new (handler.allocator()) ClipRectOp(
351 0, 0, properties().getWidth(), properties().getHeight(), SkRegion::kIntersect_Op);
John Reckd0a0b2a2014-03-20 16:28:56 -0700352 handler(op, PROPERTY_SAVECOUNT, properties().getClipToBounds());
John Reck113e0822014-03-18 09:22:59 -0700353 }
Chris Craik8c271ca2014-03-25 10:33:01 -0700354
355 if (CC_UNLIKELY(properties().hasClippingPath())) {
Chris Craik2bcad172014-05-14 18:11:23 -0700356 ClipPathOp* op = new (handler.allocator()) ClipPathOp(
357 properties().getClippingPath(), properties().getClippingPathOp());
John Reckd0a0b2a2014-03-20 16:28:56 -0700358 handler(op, PROPERTY_SAVECOUNT, properties().getClipToBounds());
John Reck113e0822014-03-18 09:22:59 -0700359 }
360}
361
362/**
363 * Apply property-based transformations to input matrix
364 *
365 * If true3dTransform is set to true, the transform applied to the input matrix will use true 4x4
366 * matrix computation instead of the Skia 3x3 matrix + camera hackery.
367 */
368void RenderNode::applyViewPropertyTransforms(mat4& matrix, bool true3dTransform) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700369 if (properties().getLeft() != 0 || properties().getTop() != 0) {
370 matrix.translate(properties().getLeft(), properties().getTop());
John Reck113e0822014-03-18 09:22:59 -0700371 }
John Reckd0a0b2a2014-03-20 16:28:56 -0700372 if (properties().getStaticMatrix()) {
373 mat4 stat(*properties().getStaticMatrix());
John Reck113e0822014-03-18 09:22:59 -0700374 matrix.multiply(stat);
John Reckd0a0b2a2014-03-20 16:28:56 -0700375 } else if (properties().getAnimationMatrix()) {
376 mat4 anim(*properties().getAnimationMatrix());
John Reck113e0822014-03-18 09:22:59 -0700377 matrix.multiply(anim);
378 }
Chris Craike0bb87d2014-04-22 17:55:41 -0700379
Chris Craikcc39e162014-04-25 18:34:11 -0700380 bool applyTranslationZ = true3dTransform && !MathUtils::isZero(properties().getZ());
Chris Craike0bb87d2014-04-22 17:55:41 -0700381 if (properties().hasTransformMatrix() || applyTranslationZ) {
John Reckf7483e32014-04-11 08:54:47 -0700382 if (properties().isTransformTranslateOnly()) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700383 matrix.translate(properties().getTranslationX(), properties().getTranslationY(),
Chris Craikcc39e162014-04-25 18:34:11 -0700384 true3dTransform ? properties().getZ() : 0.0f);
John Reck113e0822014-03-18 09:22:59 -0700385 } else {
386 if (!true3dTransform) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700387 matrix.multiply(*properties().getTransformMatrix());
John Reck113e0822014-03-18 09:22:59 -0700388 } else {
389 mat4 true3dMat;
390 true3dMat.loadTranslate(
John Reckd0a0b2a2014-03-20 16:28:56 -0700391 properties().getPivotX() + properties().getTranslationX(),
392 properties().getPivotY() + properties().getTranslationY(),
Chris Craikcc39e162014-04-25 18:34:11 -0700393 properties().getZ());
John Reckd0a0b2a2014-03-20 16:28:56 -0700394 true3dMat.rotate(properties().getRotationX(), 1, 0, 0);
395 true3dMat.rotate(properties().getRotationY(), 0, 1, 0);
396 true3dMat.rotate(properties().getRotation(), 0, 0, 1);
397 true3dMat.scale(properties().getScaleX(), properties().getScaleY(), 1);
398 true3dMat.translate(-properties().getPivotX(), -properties().getPivotY());
John Reck113e0822014-03-18 09:22:59 -0700399
400 matrix.multiply(true3dMat);
401 }
402 }
403 }
404}
405
406/**
407 * Organizes the DisplayList hierarchy to prepare for background projection reordering.
408 *
409 * This should be called before a call to defer() or drawDisplayList()
410 *
411 * Each DisplayList that serves as a 3d root builds its list of composited children,
412 * which are flagged to not draw in the standard draw loop.
413 */
414void RenderNode::computeOrdering() {
415 ATRACE_CALL();
416 mProjectedNodes.clear();
417
418 // TODO: create temporary DDLOp and call computeOrderingImpl on top DisplayList so that
419 // transform properties are applied correctly to top level children
420 if (mDisplayListData == NULL) return;
John Reck087bc0c2014-04-04 16:20:08 -0700421 for (unsigned int i = 0; i < mDisplayListData->children().size(); i++) {
Chris Craika7090e02014-06-20 16:01:00 -0700422 DrawRenderNodeOp* childOp = mDisplayListData->children()[i];
423 childOp->mRenderNode->computeOrderingImpl(childOp,
Chris Craik3f0854292014-04-15 16:18:08 -0700424 properties().getOutline().getPath(), &mProjectedNodes, &mat4::identity());
John Reck113e0822014-03-18 09:22:59 -0700425 }
426}
427
428void RenderNode::computeOrderingImpl(
Chris Craika7090e02014-06-20 16:01:00 -0700429 DrawRenderNodeOp* opState,
Chris Craik3f0854292014-04-15 16:18:08 -0700430 const SkPath* outlineOfProjectionSurface,
Chris Craika7090e02014-06-20 16:01:00 -0700431 Vector<DrawRenderNodeOp*>* compositedChildrenOfProjectionSurface,
John Reck113e0822014-03-18 09:22:59 -0700432 const mat4* transformFromProjectionSurface) {
433 mProjectedNodes.clear();
434 if (mDisplayListData == NULL || mDisplayListData->isEmpty()) return;
435
436 // TODO: should avoid this calculation in most cases
437 // TODO: just calculate single matrix, down to all leaf composited elements
438 Matrix4 localTransformFromProjectionSurface(*transformFromProjectionSurface);
439 localTransformFromProjectionSurface.multiply(opState->mTransformFromParent);
440
John Reckd0a0b2a2014-03-20 16:28:56 -0700441 if (properties().getProjectBackwards()) {
John Reck113e0822014-03-18 09:22:59 -0700442 // composited projectee, flag for out of order draw, save matrix, and store in proj surface
443 opState->mSkipInOrderDraw = true;
444 opState->mTransformFromCompositingAncestor.load(localTransformFromProjectionSurface);
445 compositedChildrenOfProjectionSurface->add(opState);
446 } else {
447 // standard in order draw
448 opState->mSkipInOrderDraw = false;
449 }
450
John Reck087bc0c2014-04-04 16:20:08 -0700451 if (mDisplayListData->children().size() > 0) {
John Reck113e0822014-03-18 09:22:59 -0700452 const bool isProjectionReceiver = mDisplayListData->projectionReceiveIndex >= 0;
453 bool haveAppliedPropertiesToProjection = false;
John Reck087bc0c2014-04-04 16:20:08 -0700454 for (unsigned int i = 0; i < mDisplayListData->children().size(); i++) {
Chris Craika7090e02014-06-20 16:01:00 -0700455 DrawRenderNodeOp* childOp = mDisplayListData->children()[i];
456 RenderNode* child = childOp->mRenderNode;
John Reck113e0822014-03-18 09:22:59 -0700457
Chris Craik3f0854292014-04-15 16:18:08 -0700458 const SkPath* projectionOutline = NULL;
Chris Craika7090e02014-06-20 16:01:00 -0700459 Vector<DrawRenderNodeOp*>* projectionChildren = NULL;
John Reck113e0822014-03-18 09:22:59 -0700460 const mat4* projectionTransform = NULL;
John Reckd0a0b2a2014-03-20 16:28:56 -0700461 if (isProjectionReceiver && !child->properties().getProjectBackwards()) {
John Reck113e0822014-03-18 09:22:59 -0700462 // if receiving projections, collect projecting descendent
463
464 // Note that if a direct descendent is projecting backwards, we pass it's
465 // grandparent projection collection, since it shouldn't project onto it's
466 // parent, where it will already be drawing.
Chris Craik3f0854292014-04-15 16:18:08 -0700467 projectionOutline = properties().getOutline().getPath();
John Reck113e0822014-03-18 09:22:59 -0700468 projectionChildren = &mProjectedNodes;
469 projectionTransform = &mat4::identity();
470 } else {
471 if (!haveAppliedPropertiesToProjection) {
472 applyViewPropertyTransforms(localTransformFromProjectionSurface);
473 haveAppliedPropertiesToProjection = true;
474 }
Chris Craik3f0854292014-04-15 16:18:08 -0700475 projectionOutline = outlineOfProjectionSurface;
John Reck113e0822014-03-18 09:22:59 -0700476 projectionChildren = compositedChildrenOfProjectionSurface;
477 projectionTransform = &localTransformFromProjectionSurface;
478 }
Chris Craik3f0854292014-04-15 16:18:08 -0700479 child->computeOrderingImpl(childOp,
480 projectionOutline, projectionChildren, projectionTransform);
John Reck113e0822014-03-18 09:22:59 -0700481 }
482 }
John Reck113e0822014-03-18 09:22:59 -0700483}
484
485class DeferOperationHandler {
486public:
487 DeferOperationHandler(DeferStateStruct& deferStruct, int level)
488 : mDeferStruct(deferStruct), mLevel(level) {}
489 inline void operator()(DisplayListOp* operation, int saveCount, bool clipToBounds) {
490 operation->defer(mDeferStruct, saveCount, mLevel, clipToBounds);
491 }
492 inline LinearAllocator& allocator() { return *(mDeferStruct.mAllocator); }
Chris Craikb265e2c2014-03-27 15:50:09 -0700493 inline void startMark(const char* name) {} // do nothing
494 inline void endMark() {}
495 inline int level() { return mLevel; }
496 inline int replayFlags() { return mDeferStruct.mReplayFlags; }
John Reck113e0822014-03-18 09:22:59 -0700497
498private:
499 DeferStateStruct& mDeferStruct;
500 const int mLevel;
501};
502
Chris Craik80d49022014-06-20 15:03:43 -0700503void RenderNode::defer(DeferStateStruct& deferStruct, const int level) {
John Reck113e0822014-03-18 09:22:59 -0700504 DeferOperationHandler handler(deferStruct, level);
Chris Craikb265e2c2014-03-27 15:50:09 -0700505 issueOperations<DeferOperationHandler>(deferStruct.mRenderer, handler);
John Reck113e0822014-03-18 09:22:59 -0700506}
507
508class ReplayOperationHandler {
509public:
510 ReplayOperationHandler(ReplayStateStruct& replayStruct, int level)
511 : mReplayStruct(replayStruct), mLevel(level) {}
512 inline void operator()(DisplayListOp* operation, int saveCount, bool clipToBounds) {
513#if DEBUG_DISPLAY_LIST_OPS_AS_EVENTS
Chris Craik3f0854292014-04-15 16:18:08 -0700514 mReplayStruct.mRenderer.eventMark(operation->name());
John Reck113e0822014-03-18 09:22:59 -0700515#endif
516 operation->replay(mReplayStruct, saveCount, mLevel, clipToBounds);
517 }
518 inline LinearAllocator& allocator() { return *(mReplayStruct.mAllocator); }
Chris Craikb265e2c2014-03-27 15:50:09 -0700519 inline void startMark(const char* name) {
520 mReplayStruct.mRenderer.startMark(name);
521 }
522 inline void endMark() {
523 mReplayStruct.mRenderer.endMark();
Chris Craikb265e2c2014-03-27 15:50:09 -0700524 }
525 inline int level() { return mLevel; }
526 inline int replayFlags() { return mReplayStruct.mReplayFlags; }
John Reck113e0822014-03-18 09:22:59 -0700527
528private:
529 ReplayStateStruct& mReplayStruct;
530 const int mLevel;
531};
532
Chris Craik80d49022014-06-20 15:03:43 -0700533void RenderNode::replay(ReplayStateStruct& replayStruct, const int level) {
John Reck113e0822014-03-18 09:22:59 -0700534 ReplayOperationHandler handler(replayStruct, level);
Chris Craikb265e2c2014-03-27 15:50:09 -0700535 issueOperations<ReplayOperationHandler>(replayStruct.mRenderer, handler);
John Reck113e0822014-03-18 09:22:59 -0700536}
537
Chris Craika7090e02014-06-20 16:01:00 -0700538void RenderNode::buildZSortedChildList(Vector<ZDrawRenderNodeOpPair>& zTranslatedNodes) {
John Reck087bc0c2014-04-04 16:20:08 -0700539 if (mDisplayListData == NULL || mDisplayListData->children().size() == 0) return;
John Reck113e0822014-03-18 09:22:59 -0700540
John Reck087bc0c2014-04-04 16:20:08 -0700541 for (unsigned int i = 0; i < mDisplayListData->children().size(); i++) {
Chris Craika7090e02014-06-20 16:01:00 -0700542 DrawRenderNodeOp* childOp = mDisplayListData->children()[i];
543 RenderNode* child = childOp->mRenderNode;
Chris Craikcc39e162014-04-25 18:34:11 -0700544 float childZ = child->properties().getZ();
John Reck113e0822014-03-18 09:22:59 -0700545
Chris Craike0bb87d2014-04-22 17:55:41 -0700546 if (!MathUtils::isZero(childZ)) {
Chris Craika7090e02014-06-20 16:01:00 -0700547 zTranslatedNodes.add(ZDrawRenderNodeOpPair(childZ, childOp));
John Reck113e0822014-03-18 09:22:59 -0700548 childOp->mSkipInOrderDraw = true;
John Reckd0a0b2a2014-03-20 16:28:56 -0700549 } else if (!child->properties().getProjectBackwards()) {
John Reck113e0822014-03-18 09:22:59 -0700550 // regular, in order drawing DisplayList
551 childOp->mSkipInOrderDraw = false;
552 }
553 }
554
555 // Z sort 3d children (stable-ness makes z compare fall back to standard drawing order)
556 std::stable_sort(zTranslatedNodes.begin(), zTranslatedNodes.end());
557}
558
Chris Craikb265e2c2014-03-27 15:50:09 -0700559template <class T>
560void RenderNode::issueDrawShadowOperation(const Matrix4& transformFromParent, T& handler) {
Chris Craik61317322014-05-21 13:03:52 -0700561 if (properties().getAlpha() <= 0.0f || properties().getOutline().isEmpty()) return;
Chris Craikb265e2c2014-03-27 15:50:09 -0700562
563 mat4 shadowMatrixXY(transformFromParent);
564 applyViewPropertyTransforms(shadowMatrixXY);
565
566 // Z matrix needs actual 3d transformation, so mapped z values will be correct
567 mat4 shadowMatrixZ(transformFromParent);
568 applyViewPropertyTransforms(shadowMatrixZ, true);
569
570 const SkPath* outlinePath = properties().getOutline().getPath();
571 const RevealClip& revealClip = properties().getRevealClip();
572 const SkPath* revealClipPath = revealClip.hasConvexClip()
573 ? revealClip.getPath() : NULL; // only pass the reveal clip's path if it's convex
574
Chris Craik61317322014-05-21 13:03:52 -0700575 if (revealClipPath && revealClipPath->isEmpty()) return;
576
Chris Craikb265e2c2014-03-27 15:50:09 -0700577 /**
578 * The drawing area of the caster is always the same as the its perimeter (which
579 * the shadow system uses) *except* in the inverse clip case. Inform the shadow
580 * system that the caster's drawing area (as opposed to its perimeter) has been
581 * clipped, so that it knows the caster can't be opaque.
582 */
583 bool casterUnclipped = !revealClip.willClip() || revealClip.hasConvexClip();
584
585 DisplayListOp* shadowOp = new (handler.allocator()) DrawShadowOp(
586 shadowMatrixXY, shadowMatrixZ,
587 properties().getAlpha(), casterUnclipped,
Chris Craikb265e2c2014-03-27 15:50:09 -0700588 outlinePath, revealClipPath);
589 handler(shadowOp, PROPERTY_SAVECOUNT, properties().getClipToBounds());
590}
591
Chris Craik80d49022014-06-20 15:03:43 -0700592template <class T>
593int RenderNode::issueOperationsOfNegZChildren(
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 -1;
597
598 // create a save around the body of the ViewGroup's draw method, so that
599 // matrix/clip methods don't affect composited children
600 int shadowSaveCount = renderer.getSaveCount();
601 handler(new (handler.allocator()) SaveOp(SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag),
602 PROPERTY_SAVECOUNT, properties().getClipToBounds());
603
604 issueOperationsOf3dChildren(zTranslatedNodes, kNegativeZChildren, renderer, handler);
605 return shadowSaveCount;
606}
607
608template <class T>
609void RenderNode::issueOperationsOfPosZChildren(int shadowRestoreTo,
Chris Craika7090e02014-06-20 16:01:00 -0700610 const Vector<ZDrawRenderNodeOpPair>& zTranslatedNodes,
Chris Craik80d49022014-06-20 15:03:43 -0700611 OpenGLRenderer& renderer, T& handler) {
612 if (zTranslatedNodes.isEmpty()) return;
613
614 LOG_ALWAYS_FATAL_IF(shadowRestoreTo < 0, "invalid save to restore to");
615 handler(new (handler.allocator()) RestoreToCountOp(shadowRestoreTo),
616 PROPERTY_SAVECOUNT, properties().getClipToBounds());
617 renderer.setOverrideLayerAlpha(1.0f);
618
619 issueOperationsOf3dChildren(zTranslatedNodes, kPositiveZChildren, renderer, handler);
620}
621
John Reck113e0822014-03-18 09:22:59 -0700622#define SHADOW_DELTA 0.1f
623
624template <class T>
Chris Craika7090e02014-06-20 16:01:00 -0700625void RenderNode::issueOperationsOf3dChildren(const Vector<ZDrawRenderNodeOpPair>& zTranslatedNodes,
John Reck113e0822014-03-18 09:22:59 -0700626 ChildrenSelectMode mode, OpenGLRenderer& renderer, T& handler) {
627 const int size = zTranslatedNodes.size();
628 if (size == 0
629 || (mode == kNegativeZChildren && zTranslatedNodes[0].key > 0.0f)
630 || (mode == kPositiveZChildren && zTranslatedNodes[size - 1].key < 0.0f)) {
631 // no 3d children to draw
632 return;
633 }
634
John Reck113e0822014-03-18 09:22:59 -0700635 /**
636 * Draw shadows and (potential) casters mostly in order, but allow the shadows of casters
637 * with very similar Z heights to draw together.
638 *
639 * This way, if Views A & B have the same Z height and are both casting shadows, the shadows are
640 * underneath both, and neither's shadow is drawn on top of the other.
641 */
642 const size_t nonNegativeIndex = findNonNegativeIndex(zTranslatedNodes);
643 size_t drawIndex, shadowIndex, endIndex;
644 if (mode == kNegativeZChildren) {
645 drawIndex = 0;
646 endIndex = nonNegativeIndex;
647 shadowIndex = endIndex; // draw no shadows
648 } else {
649 drawIndex = nonNegativeIndex;
650 endIndex = size;
651 shadowIndex = drawIndex; // potentially draw shadow for each pos Z child
652 }
Chris Craik3f0854292014-04-15 16:18:08 -0700653
654 DISPLAY_LIST_LOGD("%*s%d %s 3d children:", (handler.level() + 1) * 2, "",
655 endIndex - drawIndex, mode == kNegativeZChildren ? "negative" : "positive");
656
John Reck113e0822014-03-18 09:22:59 -0700657 float lastCasterZ = 0.0f;
658 while (shadowIndex < endIndex || drawIndex < endIndex) {
659 if (shadowIndex < endIndex) {
Chris Craika7090e02014-06-20 16:01:00 -0700660 DrawRenderNodeOp* casterOp = zTranslatedNodes[shadowIndex].value;
661 RenderNode* caster = casterOp->mRenderNode;
John Reck113e0822014-03-18 09:22:59 -0700662 const float casterZ = zTranslatedNodes[shadowIndex].key;
663 // attempt to render the shadow if the caster about to be drawn is its caster,
664 // OR if its caster's Z value is similar to the previous potential caster
665 if (shadowIndex == drawIndex || casterZ - lastCasterZ < SHADOW_DELTA) {
Chris Craikb265e2c2014-03-27 15:50:09 -0700666 caster->issueDrawShadowOperation(casterOp->mTransformFromParent, handler);
John Reck113e0822014-03-18 09:22:59 -0700667
668 lastCasterZ = casterZ; // must do this even if current caster not casting a shadow
669 shadowIndex++;
670 continue;
671 }
672 }
673
674 // only the actual child DL draw needs to be in save/restore,
675 // since it modifies the renderer's matrix
676 int restoreTo = renderer.save(SkCanvas::kMatrix_SaveFlag);
677
Chris Craika7090e02014-06-20 16:01:00 -0700678 DrawRenderNodeOp* childOp = zTranslatedNodes[drawIndex].value;
679 RenderNode* child = childOp->mRenderNode;
John Reck113e0822014-03-18 09:22:59 -0700680
681 renderer.concatMatrix(childOp->mTransformFromParent);
682 childOp->mSkipInOrderDraw = false; // this is horrible, I'm so sorry everyone
John Reckd0a0b2a2014-03-20 16:28:56 -0700683 handler(childOp, renderer.getSaveCount() - 1, properties().getClipToBounds());
John Reck113e0822014-03-18 09:22:59 -0700684 childOp->mSkipInOrderDraw = true;
685
686 renderer.restoreToCount(restoreTo);
687 drawIndex++;
688 }
John Reck113e0822014-03-18 09:22:59 -0700689}
690
691template <class T>
Chris Craikb265e2c2014-03-27 15:50:09 -0700692void RenderNode::issueOperationsOfProjectedChildren(OpenGLRenderer& renderer, T& handler) {
Chris Craik3f0854292014-04-15 16:18:08 -0700693 DISPLAY_LIST_LOGD("%*s%d projected children:", (handler.level() + 1) * 2, "", mProjectedNodes.size());
694 const SkPath* projectionReceiverOutline = properties().getOutline().getPath();
Chris Craik3f0854292014-04-15 16:18:08 -0700695 int restoreTo = renderer.getSaveCount();
696
697 // If the projection reciever has an outline, we mask each of the projected rendernodes to it
698 // Either with clipRect, or special saveLayer masking
699 LinearAllocator& alloc = handler.allocator();
700 if (projectionReceiverOutline != NULL) {
701 const SkRect& outlineBounds = projectionReceiverOutline->getBounds();
702 if (projectionReceiverOutline->isRect(NULL)) {
703 // mask to the rect outline simply with clipRect
704 handler(new (alloc) SaveOp(SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag),
705 PROPERTY_SAVECOUNT, properties().getClipToBounds());
706 ClipRectOp* clipOp = new (alloc) ClipRectOp(
707 outlineBounds.left(), outlineBounds.top(),
708 outlineBounds.right(), outlineBounds.bottom(), SkRegion::kIntersect_Op);
709 handler(clipOp, PROPERTY_SAVECOUNT, properties().getClipToBounds());
710 } else {
711 // wrap the projected RenderNodes with a SaveLayer that will mask to the outline
712 SaveLayerOp* op = new (alloc) SaveLayerOp(
713 outlineBounds.left(), outlineBounds.top(),
714 outlineBounds.right(), outlineBounds.bottom(),
Chris Craik80d49022014-06-20 15:03:43 -0700715 255, SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag | SkCanvas::kARGB_ClipLayer_SaveFlag);
Chris Craik3f0854292014-04-15 16:18:08 -0700716 op->setMask(projectionReceiverOutline);
717 handler(op, PROPERTY_SAVECOUNT, properties().getClipToBounds());
718
719 /* TODO: add optimizations here to take advantage of placement/size of projected
720 * children (which may shrink saveLayer area significantly). This is dependent on
721 * passing actual drawing/dirtying bounds of projected content down to native.
722 */
723 }
724 }
725
726 // draw projected nodes
John Reck113e0822014-03-18 09:22:59 -0700727 for (size_t i = 0; i < mProjectedNodes.size(); i++) {
Chris Craika7090e02014-06-20 16:01:00 -0700728 DrawRenderNodeOp* childOp = mProjectedNodes[i];
John Reck113e0822014-03-18 09:22:59 -0700729
730 // matrix save, concat, and restore can be done safely without allocating operations
731 int restoreTo = renderer.save(SkCanvas::kMatrix_SaveFlag);
732 renderer.concatMatrix(childOp->mTransformFromCompositingAncestor);
733 childOp->mSkipInOrderDraw = false; // this is horrible, I'm so sorry everyone
John Reckd0a0b2a2014-03-20 16:28:56 -0700734 handler(childOp, renderer.getSaveCount() - 1, properties().getClipToBounds());
John Reck113e0822014-03-18 09:22:59 -0700735 childOp->mSkipInOrderDraw = true;
736 renderer.restoreToCount(restoreTo);
737 }
Chris Craik3f0854292014-04-15 16:18:08 -0700738
739 if (projectionReceiverOutline != NULL) {
740 handler(new (alloc) RestoreToCountOp(restoreTo),
741 PROPERTY_SAVECOUNT, properties().getClipToBounds());
742 }
John Reck113e0822014-03-18 09:22:59 -0700743}
744
745/**
746 * This function serves both defer and replay modes, and will organize the displayList's component
747 * operations for a single frame:
748 *
749 * Every 'simple' state operation that affects just the matrix and alpha (or other factors of
750 * DeferredDisplayState) may be issued directly to the renderer, but complex operations (with custom
751 * defer logic) and operations in displayListOps are issued through the 'handler' which handles the
752 * defer vs replay logic, per operation
753 */
754template <class T>
Chris Craikb265e2c2014-03-27 15:50:09 -0700755void RenderNode::issueOperations(OpenGLRenderer& renderer, T& handler) {
John Reck25fbb3f2014-06-12 13:46:45 -0700756 const bool drawLayer = (mLayer && (&renderer != mLayer->renderer));
757 // If we are updating the contents of mLayer, we don't want to apply any of
758 // the RenderNode's properties to this issueOperations pass. Those will all
759 // be applied when the layer is drawn, aka when this is true.
760 const bool useViewProperties = (!mLayer || drawLayer);
761
Chris Craikb265e2c2014-03-27 15:50:09 -0700762 const int level = handler.level();
John Reck25fbb3f2014-06-12 13:46:45 -0700763 if (mDisplayListData->isEmpty() || (useViewProperties && properties().getAlpha() <= 0)) {
Chris Craik3f0854292014-04-15 16:18:08 -0700764 DISPLAY_LIST_LOGD("%*sEmpty display list (%p, %s)", level * 2, "", this, getName());
John Reck113e0822014-03-18 09:22:59 -0700765 return;
766 }
767
Chris Craik3f0854292014-04-15 16:18:08 -0700768 handler.startMark(getName());
Chris Craikb265e2c2014-03-27 15:50:09 -0700769
John Reck113e0822014-03-18 09:22:59 -0700770#if DEBUG_DISPLAY_LIST
Chris Craik3f0854292014-04-15 16:18:08 -0700771 const Rect& clipRect = renderer.getLocalClipBounds();
772 DISPLAY_LIST_LOGD("%*sStart display list (%p, %s), localClipBounds: %.0f, %.0f, %.0f, %.0f",
773 level * 2, "", this, getName(),
774 clipRect.left, clipRect.top, clipRect.right, clipRect.bottom);
John Reck113e0822014-03-18 09:22:59 -0700775#endif
776
777 LinearAllocator& alloc = handler.allocator();
778 int restoreTo = renderer.getSaveCount();
779 handler(new (alloc) SaveOp(SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag),
John Reckd0a0b2a2014-03-20 16:28:56 -0700780 PROPERTY_SAVECOUNT, properties().getClipToBounds());
John Reck113e0822014-03-18 09:22:59 -0700781
782 DISPLAY_LIST_LOGD("%*sSave %d %d", (level + 1) * 2, "",
783 SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag, restoreTo);
784
John Reck25fbb3f2014-06-12 13:46:45 -0700785 if (useViewProperties) {
786 setViewProperties<T>(renderer, handler);
787 }
John Reck113e0822014-03-18 09:22:59 -0700788
Chris Craik8c271ca2014-03-25 10:33:01 -0700789 bool quickRejected = properties().getClipToBounds()
790 && renderer.quickRejectConservative(0, 0, properties().getWidth(), properties().getHeight());
John Reck113e0822014-03-18 09:22:59 -0700791 if (!quickRejected) {
Chris Craikdeeda3d2014-05-05 19:09:33 -0700792 if (mProperties.getOutline().willClip()) {
793 renderer.setClippingOutline(alloc, &(mProperties.getOutline()));
794 }
795
John Reck25fbb3f2014-06-12 13:46:45 -0700796 if (drawLayer) {
797 handler(new (alloc) DrawLayerOp(mLayer, 0, 0),
798 renderer.getSaveCount() - 1, properties().getClipToBounds());
799 } else {
Chris Craika7090e02014-06-20 16:01:00 -0700800 Vector<ZDrawRenderNodeOpPair> zTranslatedNodes;
John Reck25fbb3f2014-06-12 13:46:45 -0700801 buildZSortedChildList(zTranslatedNodes);
John Reck113e0822014-03-18 09:22:59 -0700802
John Reck25fbb3f2014-06-12 13:46:45 -0700803 // for 3d root, draw children with negative z values
Chris Craik80d49022014-06-20 15:03:43 -0700804 int shadowRestoreTo = issueOperationsOfNegZChildren(zTranslatedNodes, renderer, handler);
John Reck113e0822014-03-18 09:22:59 -0700805
John Reck25fbb3f2014-06-12 13:46:45 -0700806 DisplayListLogBuffer& logBuffer = DisplayListLogBuffer::getInstance();
807 const int saveCountOffset = renderer.getSaveCount() - 1;
808 const int projectionReceiveIndex = mDisplayListData->projectionReceiveIndex;
809 for (unsigned int i = 0; i < mDisplayListData->displayListOps.size(); i++) {
810 DisplayListOp *op = mDisplayListData->displayListOps[i];
John Reck113e0822014-03-18 09:22:59 -0700811
Chris Craik80d49022014-06-20 15:03:43 -0700812#if DEBUG_DISPLAY_LIST
John Reck25fbb3f2014-06-12 13:46:45 -0700813 op->output(level + 1);
Chris Craik80d49022014-06-20 15:03:43 -0700814#endif
John Reck25fbb3f2014-06-12 13:46:45 -0700815 logBuffer.writeCommand(level, op->name());
816 handler(op, saveCountOffset, properties().getClipToBounds());
John Reck113e0822014-03-18 09:22:59 -0700817
John Reck25fbb3f2014-06-12 13:46:45 -0700818 if (CC_UNLIKELY(i == projectionReceiveIndex && mProjectedNodes.size() > 0)) {
819 issueOperationsOfProjectedChildren(renderer, handler);
820 }
John Reck113e0822014-03-18 09:22:59 -0700821 }
John Reck113e0822014-03-18 09:22:59 -0700822
John Reck25fbb3f2014-06-12 13:46:45 -0700823 // for 3d root, draw children with positive z values
Chris Craik80d49022014-06-20 15:03:43 -0700824 issueOperationsOfPosZChildren(shadowRestoreTo, zTranslatedNodes, renderer, handler);
John Reck25fbb3f2014-06-12 13:46:45 -0700825 }
John Reck113e0822014-03-18 09:22:59 -0700826 }
827
828 DISPLAY_LIST_LOGD("%*sRestoreToCount %d", (level + 1) * 2, "", restoreTo);
829 handler(new (alloc) RestoreToCountOp(restoreTo),
John Reckd0a0b2a2014-03-20 16:28:56 -0700830 PROPERTY_SAVECOUNT, properties().getClipToBounds());
John Reck113e0822014-03-18 09:22:59 -0700831 renderer.setOverrideLayerAlpha(1.0f);
Chris Craikb265e2c2014-03-27 15:50:09 -0700832
Chris Craik3f0854292014-04-15 16:18:08 -0700833 DISPLAY_LIST_LOGD("%*sDone (%p, %s)", level * 2, "", this, getName());
Chris Craikb265e2c2014-03-27 15:50:09 -0700834 handler.endMark();
John Reck113e0822014-03-18 09:22:59 -0700835}
836
837} /* namespace uirenderer */
838} /* namespace android */