RenderNode.cpp revision b49f446c98096c4790a11d9b5bc83a4e585278c9
1/*
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
18
19#include "RenderNode.h"
20
21#include <SkCanvas.h>
22#include <algorithm>
23
24#include <utils/Trace.h>
25
26#include "Debug.h"
27#include "DisplayListOp.h"
28#include "DisplayListLogBuffer.h"
29
30namespace android {
31namespace uirenderer {
32
33void RenderNode::outputLogBuffer(int fd) {
34    DisplayListLogBuffer& logBuffer = DisplayListLogBuffer::getInstance();
35    if (logBuffer.isEmpty()) {
36        return;
37    }
38
39    FILE *file = fdopen(fd, "a");
40
41    fprintf(file, "\nRecent DisplayList operations\n");
42    logBuffer.outputCommands(file);
43
44    String8 cachesLog;
45    Caches::getInstance().dumpMemoryUsage(cachesLog);
46    fprintf(file, "\nCaches:\n%s", cachesLog.string());
47    fprintf(file, "\n");
48
49    fflush(file);
50}
51
52RenderNode::RenderNode() : mDestroyed(false), mDisplayListData(0) {
53}
54
55RenderNode::~RenderNode() {
56    LOG_ALWAYS_FATAL_IF(mDestroyed, "Double destroyed DisplayList %p", this);
57
58    mDestroyed = true;
59    delete mDisplayListData;
60}
61
62void RenderNode::destroyDisplayListDeferred(RenderNode* displayList) {
63    if (displayList) {
64        DISPLAY_LIST_LOGD("Deferring display list destruction");
65        Caches::getInstance().deleteDisplayListDeferred(displayList);
66    }
67}
68
69void RenderNode::setData(DisplayListData* data) {
70    delete mDisplayListData;
71    mDisplayListData = data;
72    if (mDisplayListData) {
73        Caches::getInstance().registerFunctors(mDisplayListData->functorCount);
74    }
75}
76
77/**
78 * This function is a simplified version of replay(), where we simply retrieve and log the
79 * display list. This function should remain in sync with the replay() function.
80 */
81void RenderNode::output(uint32_t level) {
82    ALOGD("%*sStart display list (%p, %s, render=%d)", (level - 1) * 2, "", this,
83            mName.string(), isRenderable());
84    ALOGD("%*s%s %d", level * 2, "", "Save",
85            SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag);
86
87    outputViewProperties(level);
88    int flags = DisplayListOp::kOpLogFlag_Recurse;
89    for (unsigned int i = 0; i < mDisplayListData->displayListOps.size(); i++) {
90        mDisplayListData->displayListOps[i]->output(level, flags);
91    }
92
93    ALOGD("%*sDone (%p, %s)", (level - 1) * 2, "", this, mName.string());
94}
95
96void RenderNode::outputViewProperties(const int level) {
97    properties().updateMatrix();
98    if (properties().mLeft != 0 || properties().mTop != 0) {
99        ALOGD("%*sTranslate (left, top) %d, %d", level * 2, "", properties().mLeft, properties().mTop);
100    }
101    if (properties().mStaticMatrix) {
102        ALOGD("%*sConcatMatrix (static) %p: " SK_MATRIX_STRING,
103                level * 2, "", properties().mStaticMatrix, SK_MATRIX_ARGS(properties().mStaticMatrix));
104    }
105    if (properties().mAnimationMatrix) {
106        ALOGD("%*sConcatMatrix (animation) %p: " SK_MATRIX_STRING,
107                level * 2, "", properties().mAnimationMatrix, SK_MATRIX_ARGS(properties().mAnimationMatrix));
108    }
109    if (properties().mMatrixFlags != 0) {
110        if (properties().mMatrixFlags == TRANSLATION) {
111            ALOGD("%*sTranslate %.2f, %.2f, %.2f",
112                    level * 2, "", properties().mTranslationX, properties().mTranslationY, properties().mTranslationZ);
113        } else {
114            ALOGD("%*sConcatMatrix %p: " MATRIX_4_STRING,
115                    level * 2, "", properties().mTransformMatrix, MATRIX_4_ARGS(properties().mTransformMatrix));
116        }
117    }
118
119    bool clipToBoundsNeeded = properties().mCaching ? false : properties().mClipToBounds;
120    if (properties().mAlpha < 1) {
121        if (properties().mCaching) {
122            ALOGD("%*sSetOverrideLayerAlpha %.2f", level * 2, "", properties().mAlpha);
123        } else if (!properties().mHasOverlappingRendering) {
124            ALOGD("%*sScaleAlpha %.2f", level * 2, "", properties().mAlpha);
125        } else {
126            int flags = SkCanvas::kHasAlphaLayer_SaveFlag;
127            if (clipToBoundsNeeded) {
128                flags |= SkCanvas::kClipToLayer_SaveFlag;
129                clipToBoundsNeeded = false; // clipping done by save layer
130            }
131            ALOGD("%*sSaveLayerAlpha %d, %d, %d, %d, %d, 0x%x", level * 2, "",
132                    0, 0, properties().mWidth, properties().mHeight,
133                    (int)(properties().mAlpha * 255), flags);
134        }
135    }
136    if (clipToBoundsNeeded) {
137        ALOGD("%*sClipRect %d, %d, %d, %d", level * 2, "",
138                0, 0, properties().mWidth, properties().mHeight);
139    }
140}
141
142/*
143 * For property operations, we pass a savecount of 0, since the operations aren't part of the
144 * displaylist, and thus don't have to compensate for the record-time/playback-time discrepancy in
145 * base saveCount (i.e., how RestoreToCount uses saveCount + properties().mCount)
146 */
147#define PROPERTY_SAVECOUNT 0
148
149template <class T>
150void RenderNode::setViewProperties(OpenGLRenderer& renderer, T& handler,
151        const int level) {
152#if DEBUG_DISPLAY_LIST
153    outputViewProperties(level);
154#endif
155    properties().updateMatrix();
156    if (properties().mLeft != 0 || properties().mTop != 0) {
157        renderer.translate(properties().mLeft, properties().mTop);
158    }
159    if (properties().mStaticMatrix) {
160        renderer.concatMatrix(properties().mStaticMatrix);
161    } else if (properties().mAnimationMatrix) {
162        renderer.concatMatrix(properties().mAnimationMatrix);
163    }
164    if (properties().mMatrixFlags != 0) {
165        if (properties().mMatrixFlags == TRANSLATION) {
166            renderer.translate(properties().mTranslationX, properties().mTranslationY);
167        } else {
168            renderer.concatMatrix(*properties().mTransformMatrix);
169        }
170    }
171    bool clipToBoundsNeeded = properties().mCaching ? false : properties().mClipToBounds;
172    if (properties().mAlpha < 1) {
173        if (properties().mCaching) {
174            renderer.setOverrideLayerAlpha(properties().mAlpha);
175        } else if (!properties().mHasOverlappingRendering) {
176            renderer.scaleAlpha(properties().mAlpha);
177        } else {
178            // TODO: should be able to store the size of a DL at record time and not
179            // have to pass it into this call. In fact, this information might be in the
180            // location/size info that we store with the new native transform data.
181            int saveFlags = SkCanvas::kHasAlphaLayer_SaveFlag;
182            if (clipToBoundsNeeded) {
183                saveFlags |= SkCanvas::kClipToLayer_SaveFlag;
184                clipToBoundsNeeded = false; // clipping done by saveLayer
185            }
186
187            SaveLayerOp* op = new (handler.allocator()) SaveLayerOp(
188                    0, 0, properties().mWidth, properties().mHeight,
189                    properties().mAlpha * 255, saveFlags);
190            handler(op, PROPERTY_SAVECOUNT, properties().mClipToBounds);
191        }
192    }
193    if (clipToBoundsNeeded) {
194        ClipRectOp* op = new (handler.allocator()) ClipRectOp(
195                0, 0, properties().mWidth, properties().mHeight, SkRegion::kIntersect_Op);
196        handler(op, PROPERTY_SAVECOUNT, properties().mClipToBounds);
197    }
198    if (CC_UNLIKELY(properties().mOutline.willClip())) {
199        // TODO: optimize RR case
200        ClipPathOp* op = new (handler.allocator()) ClipPathOp(properties().mOutline.getPath(),
201                SkRegion::kIntersect_Op);
202        handler(op, PROPERTY_SAVECOUNT, properties().mClipToBounds);
203    }
204}
205
206/**
207 * Apply property-based transformations to input matrix
208 *
209 * If true3dTransform is set to true, the transform applied to the input matrix will use true 4x4
210 * matrix computation instead of the Skia 3x3 matrix + camera hackery.
211 */
212void RenderNode::applyViewPropertyTransforms(mat4& matrix, bool true3dTransform) {
213    if (properties().mLeft != 0 || properties().mTop != 0) {
214        matrix.translate(properties().mLeft, properties().mTop);
215    }
216    if (properties().mStaticMatrix) {
217        mat4 stat(*properties().mStaticMatrix);
218        matrix.multiply(stat);
219    } else if (properties().mAnimationMatrix) {
220        mat4 anim(*properties().mAnimationMatrix);
221        matrix.multiply(anim);
222    }
223    if (properties().mMatrixFlags != 0) {
224        properties().updateMatrix();
225        if (properties().mMatrixFlags == TRANSLATION) {
226            matrix.translate(properties().mTranslationX, properties().mTranslationY,
227                    true3dTransform ? properties().mTranslationZ : 0.0f);
228        } else {
229            if (!true3dTransform) {
230                matrix.multiply(*properties().mTransformMatrix);
231            } else {
232                mat4 true3dMat;
233                true3dMat.loadTranslate(
234                        properties().mPivotX + properties().mTranslationX,
235                        properties().mPivotY + properties().mTranslationY,
236                        properties().mTranslationZ);
237                true3dMat.rotate(properties().mRotationX, 1, 0, 0);
238                true3dMat.rotate(properties().mRotationY, 0, 1, 0);
239                true3dMat.rotate(properties().mRotation, 0, 0, 1);
240                true3dMat.scale(properties().mScaleX, properties().mScaleY, 1);
241                true3dMat.translate(-properties().mPivotX, -properties().mPivotY);
242
243                matrix.multiply(true3dMat);
244            }
245        }
246    }
247}
248
249/**
250 * Organizes the DisplayList hierarchy to prepare for background projection reordering.
251 *
252 * This should be called before a call to defer() or drawDisplayList()
253 *
254 * Each DisplayList that serves as a 3d root builds its list of composited children,
255 * which are flagged to not draw in the standard draw loop.
256 */
257void RenderNode::computeOrdering() {
258    ATRACE_CALL();
259    mProjectedNodes.clear();
260
261    // TODO: create temporary DDLOp and call computeOrderingImpl on top DisplayList so that
262    // transform properties are applied correctly to top level children
263    if (mDisplayListData == NULL) return;
264    for (unsigned int i = 0; i < mDisplayListData->children.size(); i++) {
265        DrawDisplayListOp* childOp = mDisplayListData->children[i];
266        childOp->mDisplayList->computeOrderingImpl(childOp,
267                &mProjectedNodes, &mat4::identity());
268    }
269}
270
271void RenderNode::computeOrderingImpl(
272        DrawDisplayListOp* opState,
273        Vector<DrawDisplayListOp*>* compositedChildrenOfProjectionSurface,
274        const mat4* transformFromProjectionSurface) {
275    mProjectedNodes.clear();
276    if (mDisplayListData == NULL || mDisplayListData->isEmpty()) return;
277
278    // TODO: should avoid this calculation in most cases
279    // TODO: just calculate single matrix, down to all leaf composited elements
280    Matrix4 localTransformFromProjectionSurface(*transformFromProjectionSurface);
281    localTransformFromProjectionSurface.multiply(opState->mTransformFromParent);
282
283    if (properties().mProjectBackwards) {
284        // composited projectee, flag for out of order draw, save matrix, and store in proj surface
285        opState->mSkipInOrderDraw = true;
286        opState->mTransformFromCompositingAncestor.load(localTransformFromProjectionSurface);
287        compositedChildrenOfProjectionSurface->add(opState);
288    } else {
289        // standard in order draw
290        opState->mSkipInOrderDraw = false;
291    }
292
293    if (mDisplayListData->children.size() > 0) {
294        const bool isProjectionReceiver = mDisplayListData->projectionReceiveIndex >= 0;
295        bool haveAppliedPropertiesToProjection = false;
296        for (unsigned int i = 0; i < mDisplayListData->children.size(); i++) {
297            DrawDisplayListOp* childOp = mDisplayListData->children[i];
298            RenderNode* child = childOp->mDisplayList;
299
300            Vector<DrawDisplayListOp*>* projectionChildren = NULL;
301            const mat4* projectionTransform = NULL;
302            if (isProjectionReceiver && !child->properties().mProjectBackwards) {
303                // if receiving projections, collect projecting descendent
304
305                // Note that if a direct descendent is projecting backwards, we pass it's
306                // grandparent projection collection, since it shouldn't project onto it's
307                // parent, where it will already be drawing.
308                projectionChildren = &mProjectedNodes;
309                projectionTransform = &mat4::identity();
310            } else {
311                if (!haveAppliedPropertiesToProjection) {
312                    applyViewPropertyTransforms(localTransformFromProjectionSurface);
313                    haveAppliedPropertiesToProjection = true;
314                }
315                projectionChildren = compositedChildrenOfProjectionSurface;
316                projectionTransform = &localTransformFromProjectionSurface;
317            }
318            child->computeOrderingImpl(childOp, projectionChildren, projectionTransform);
319        }
320    }
321
322}
323
324class DeferOperationHandler {
325public:
326    DeferOperationHandler(DeferStateStruct& deferStruct, int level)
327        : mDeferStruct(deferStruct), mLevel(level) {}
328    inline void operator()(DisplayListOp* operation, int saveCount, bool clipToBounds) {
329        operation->defer(mDeferStruct, saveCount, mLevel, clipToBounds);
330    }
331    inline LinearAllocator& allocator() { return *(mDeferStruct.mAllocator); }
332
333private:
334    DeferStateStruct& mDeferStruct;
335    const int mLevel;
336};
337
338void RenderNode::defer(DeferStateStruct& deferStruct, const int level) {
339    DeferOperationHandler handler(deferStruct, level);
340    iterate<DeferOperationHandler>(deferStruct.mRenderer, handler, level);
341}
342
343class ReplayOperationHandler {
344public:
345    ReplayOperationHandler(ReplayStateStruct& replayStruct, int level)
346        : mReplayStruct(replayStruct), mLevel(level) {}
347    inline void operator()(DisplayListOp* operation, int saveCount, bool clipToBounds) {
348#if DEBUG_DISPLAY_LIST_OPS_AS_EVENTS
349        properties().mReplayStruct.mRenderer.eventMark(operation->name());
350#endif
351        operation->replay(mReplayStruct, saveCount, mLevel, clipToBounds);
352    }
353    inline LinearAllocator& allocator() { return *(mReplayStruct.mAllocator); }
354
355private:
356    ReplayStateStruct& mReplayStruct;
357    const int mLevel;
358};
359
360void RenderNode::replay(ReplayStateStruct& replayStruct, const int level) {
361    ReplayOperationHandler handler(replayStruct, level);
362
363    replayStruct.mRenderer.startMark(mName.string());
364    iterate<ReplayOperationHandler>(replayStruct.mRenderer, handler, level);
365    replayStruct.mRenderer.endMark();
366
367    DISPLAY_LIST_LOGD("%*sDone (%p, %s), returning %d", level * 2, "", this, mName.string(),
368            replayStruct.mDrawGlStatus);
369}
370
371void RenderNode::buildZSortedChildList(Vector<ZDrawDisplayListOpPair>& zTranslatedNodes) {
372    if (mDisplayListData == NULL || mDisplayListData->children.size() == 0) return;
373
374    for (unsigned int i = 0; i < mDisplayListData->children.size(); i++) {
375        DrawDisplayListOp* childOp = mDisplayListData->children[i];
376        RenderNode* child = childOp->mDisplayList;
377        float childZ = child->properties().mTranslationZ;
378
379        if (childZ != 0.0f) {
380            zTranslatedNodes.add(ZDrawDisplayListOpPair(childZ, childOp));
381            childOp->mSkipInOrderDraw = true;
382        } else if (!child->properties().mProjectBackwards) {
383            // regular, in order drawing DisplayList
384            childOp->mSkipInOrderDraw = false;
385        }
386    }
387
388    // Z sort 3d children (stable-ness makes z compare fall back to standard drawing order)
389    std::stable_sort(zTranslatedNodes.begin(), zTranslatedNodes.end());
390}
391
392#define SHADOW_DELTA 0.1f
393
394template <class T>
395void RenderNode::iterate3dChildren(const Vector<ZDrawDisplayListOpPair>& zTranslatedNodes,
396        ChildrenSelectMode mode, OpenGLRenderer& renderer, T& handler) {
397    const int size = zTranslatedNodes.size();
398    if (size == 0
399            || (mode == kNegativeZChildren && zTranslatedNodes[0].key > 0.0f)
400            || (mode == kPositiveZChildren && zTranslatedNodes[size - 1].key < 0.0f)) {
401        // no 3d children to draw
402        return;
403    }
404
405    int rootRestoreTo = renderer.save(SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag);
406    LinearAllocator& alloc = handler.allocator();
407    ClipRectOp* clipOp = new (alloc) ClipRectOp(0, 0, properties().mWidth, properties().mHeight,
408            SkRegion::kIntersect_Op); // clip to 3d root bounds
409    handler(clipOp, PROPERTY_SAVECOUNT, properties().mClipToBounds);
410
411    /**
412     * Draw shadows and (potential) casters mostly in order, but allow the shadows of casters
413     * with very similar Z heights to draw together.
414     *
415     * This way, if Views A & B have the same Z height and are both casting shadows, the shadows are
416     * underneath both, and neither's shadow is drawn on top of the other.
417     */
418    const size_t nonNegativeIndex = findNonNegativeIndex(zTranslatedNodes);
419    size_t drawIndex, shadowIndex, endIndex;
420    if (mode == kNegativeZChildren) {
421        drawIndex = 0;
422        endIndex = nonNegativeIndex;
423        shadowIndex = endIndex; // draw no shadows
424    } else {
425        drawIndex = nonNegativeIndex;
426        endIndex = size;
427        shadowIndex = drawIndex; // potentially draw shadow for each pos Z child
428    }
429    float lastCasterZ = 0.0f;
430    while (shadowIndex < endIndex || drawIndex < endIndex) {
431        if (shadowIndex < endIndex) {
432            DrawDisplayListOp* casterOp = zTranslatedNodes[shadowIndex].value;
433            RenderNode* caster = casterOp->mDisplayList;
434            const float casterZ = zTranslatedNodes[shadowIndex].key;
435            // attempt to render the shadow if the caster about to be drawn is its caster,
436            // OR if its caster's Z value is similar to the previous potential caster
437            if (shadowIndex == drawIndex || casterZ - lastCasterZ < SHADOW_DELTA) {
438
439                if (caster->properties().mAlpha > 0.0f) {
440                    mat4 shadowMatrixXY(casterOp->mTransformFromParent);
441                    caster->applyViewPropertyTransforms(shadowMatrixXY);
442
443                    // Z matrix needs actual 3d transformation, so mapped z values will be correct
444                    mat4 shadowMatrixZ(casterOp->mTransformFromParent);
445                    caster->applyViewPropertyTransforms(shadowMatrixZ, true);
446
447                    DisplayListOp* shadowOp  = new (alloc) DrawShadowOp(
448                            shadowMatrixXY, shadowMatrixZ,
449                            caster->properties().mAlpha, caster->properties().mOutline.getPath(),
450                            caster->properties().mWidth, caster->properties().mHeight);
451                    handler(shadowOp, PROPERTY_SAVECOUNT, properties().mClipToBounds);
452                }
453
454                lastCasterZ = casterZ; // must do this even if current caster not casting a shadow
455                shadowIndex++;
456                continue;
457            }
458        }
459
460        // only the actual child DL draw needs to be in save/restore,
461        // since it modifies the renderer's matrix
462        int restoreTo = renderer.save(SkCanvas::kMatrix_SaveFlag);
463
464        DrawDisplayListOp* childOp = zTranslatedNodes[drawIndex].value;
465        RenderNode* child = childOp->mDisplayList;
466
467        renderer.concatMatrix(childOp->mTransformFromParent);
468        childOp->mSkipInOrderDraw = false; // this is horrible, I'm so sorry everyone
469        handler(childOp, renderer.getSaveCount() - 1, properties().mClipToBounds);
470        childOp->mSkipInOrderDraw = true;
471
472        renderer.restoreToCount(restoreTo);
473        drawIndex++;
474    }
475    handler(new (alloc) RestoreToCountOp(rootRestoreTo), PROPERTY_SAVECOUNT, properties().mClipToBounds);
476}
477
478template <class T>
479void RenderNode::iterateProjectedChildren(OpenGLRenderer& renderer, T& handler, const int level) {
480    int rootRestoreTo = renderer.save(SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag);
481    LinearAllocator& alloc = handler.allocator();
482    ClipRectOp* clipOp = new (alloc) ClipRectOp(0, 0, properties().mWidth, properties().mHeight,
483            SkRegion::kReplace_Op); // clip to projection surface root bounds
484    handler(clipOp, PROPERTY_SAVECOUNT, properties().mClipToBounds);
485
486    for (size_t i = 0; i < mProjectedNodes.size(); i++) {
487        DrawDisplayListOp* childOp = mProjectedNodes[i];
488
489        // matrix save, concat, and restore can be done safely without allocating operations
490        int restoreTo = renderer.save(SkCanvas::kMatrix_SaveFlag);
491        renderer.concatMatrix(childOp->mTransformFromCompositingAncestor);
492        childOp->mSkipInOrderDraw = false; // this is horrible, I'm so sorry everyone
493        handler(childOp, renderer.getSaveCount() - 1, properties().mClipToBounds);
494        childOp->mSkipInOrderDraw = true;
495        renderer.restoreToCount(restoreTo);
496    }
497    handler(new (alloc) RestoreToCountOp(rootRestoreTo), PROPERTY_SAVECOUNT, properties().mClipToBounds);
498}
499
500/**
501 * This function serves both defer and replay modes, and will organize the displayList's component
502 * operations for a single frame:
503 *
504 * Every 'simple' state operation that affects just the matrix and alpha (or other factors of
505 * DeferredDisplayState) may be issued directly to the renderer, but complex operations (with custom
506 * defer logic) and operations in displayListOps are issued through the 'handler' which handles the
507 * defer vs replay logic, per operation
508 */
509template <class T>
510void RenderNode::iterate(OpenGLRenderer& renderer, T& handler, const int level) {
511    if (CC_UNLIKELY(mDestroyed)) { // temporary debug logging
512        ALOGW("Error: %s is drawing after destruction", mName.string());
513        CRASH();
514    }
515    if (mDisplayListData->isEmpty() || properties().mAlpha <= 0) {
516        DISPLAY_LIST_LOGD("%*sEmpty display list (%p, %s)", level * 2, "", this, mName.string());
517        return;
518    }
519
520#if DEBUG_DISPLAY_LIST
521    Rect* clipRect = renderer.getClipRect();
522    DISPLAY_LIST_LOGD("%*sStart display list (%p, %s), clipRect: %.0f, %.0f, %.0f, %.0f",
523            level * 2, "", this, mName.string(), clipRect->left, clipRect->top,
524            clipRect->right, clipRect->bottom);
525#endif
526
527    LinearAllocator& alloc = handler.allocator();
528    int restoreTo = renderer.getSaveCount();
529    handler(new (alloc) SaveOp(SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag),
530            PROPERTY_SAVECOUNT, properties().mClipToBounds);
531
532    DISPLAY_LIST_LOGD("%*sSave %d %d", (level + 1) * 2, "",
533            SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag, restoreTo);
534
535    setViewProperties<T>(renderer, handler, level + 1);
536
537    bool quickRejected = properties().mClipToBounds && renderer.quickRejectConservative(0, 0, properties().mWidth, properties().mHeight);
538    if (!quickRejected) {
539        Vector<ZDrawDisplayListOpPair> zTranslatedNodes;
540        buildZSortedChildList(zTranslatedNodes);
541
542        // for 3d root, draw children with negative z values
543        iterate3dChildren(zTranslatedNodes, kNegativeZChildren, renderer, handler);
544
545        DisplayListLogBuffer& logBuffer = DisplayListLogBuffer::getInstance();
546        const int saveCountOffset = renderer.getSaveCount() - 1;
547        const int projectionReceiveIndex = mDisplayListData->projectionReceiveIndex;
548        for (unsigned int i = 0; i < mDisplayListData->displayListOps.size(); i++) {
549            DisplayListOp *op = mDisplayListData->displayListOps[i];
550
551#if DEBUG_DISPLAY_LIST
552            op->output(level + 1);
553#endif
554
555            logBuffer.writeCommand(level, op->name());
556            handler(op, saveCountOffset, properties().mClipToBounds);
557
558            if (CC_UNLIKELY(i == projectionReceiveIndex && mProjectedNodes.size() > 0)) {
559                iterateProjectedChildren(renderer, handler, level);
560            }
561        }
562
563        // for 3d root, draw children with positive z values
564        iterate3dChildren(zTranslatedNodes, kPositiveZChildren, renderer, handler);
565    }
566
567    DISPLAY_LIST_LOGD("%*sRestoreToCount %d", (level + 1) * 2, "", restoreTo);
568    handler(new (alloc) RestoreToCountOp(restoreTo),
569            PROPERTY_SAVECOUNT, properties().mClipToBounds);
570    renderer.setOverrideLayerAlpha(1.0f);
571}
572
573} /* namespace uirenderer */
574} /* namespace android */
575