RecordingCanvas.cpp revision 766431aa57c16ece8842287a92b2e7208e3b8ac3
1/*
2 * Copyright (C) 2015 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#include "RecordingCanvas.h"
18
19#include "DeferredLayerUpdater.h"
20#include "RecordedOp.h"
21#include "RenderNode.h"
22#include "VectorDrawable.h"
23
24namespace android {
25namespace uirenderer {
26
27RecordingCanvas::RecordingCanvas(size_t width, size_t height)
28        : mState(*this)
29        , mResourceCache(ResourceCache::getInstance()) {
30    resetRecording(width, height);
31}
32
33RecordingCanvas::~RecordingCanvas() {
34    LOG_ALWAYS_FATAL_IF(mDisplayList,
35            "Destroyed a RecordingCanvas during a record!");
36}
37
38void RecordingCanvas::resetRecording(int width, int height) {
39    LOG_ALWAYS_FATAL_IF(mDisplayList,
40            "prepareDirty called a second time during a recording!");
41    mDisplayList = new DisplayList();
42
43    mState.initializeRecordingSaveStack(width, height);
44
45    mDeferredBarrierType = DeferredBarrierType::InOrder;
46    mState.setDirtyClip(false);
47}
48
49DisplayList* RecordingCanvas::finishRecording() {
50    restoreToCount(1);
51    mPaintMap.clear();
52    mRegionMap.clear();
53    mPathMap.clear();
54    DisplayList* displayList = mDisplayList;
55    mDisplayList = nullptr;
56    mSkiaCanvasProxy.reset(nullptr);
57    return displayList;
58}
59
60SkCanvas* RecordingCanvas::asSkCanvas() {
61    LOG_ALWAYS_FATAL_IF(!mDisplayList,
62            "attempting to get an SkCanvas when we are not recording!");
63    if (!mSkiaCanvasProxy) {
64        mSkiaCanvasProxy.reset(new SkiaCanvasProxy(this));
65    }
66
67    // SkCanvas instances default to identity transform, but should inherit
68    // the state of this Canvas; if this code was in the SkiaCanvasProxy
69    // constructor, we couldn't cache mSkiaCanvasProxy.
70    SkMatrix parentTransform;
71    getMatrix(&parentTransform);
72    mSkiaCanvasProxy.get()->setMatrix(parentTransform);
73
74    return mSkiaCanvasProxy.get();
75}
76
77// ----------------------------------------------------------------------------
78// CanvasStateClient implementation
79// ----------------------------------------------------------------------------
80
81void RecordingCanvas::onViewportInitialized() {
82}
83
84void RecordingCanvas::onSnapshotRestored(const Snapshot& removed, const Snapshot& restored) {
85    if (removed.flags & Snapshot::kFlagIsFboLayer) {
86        addOp(new (alloc()) EndLayerOp());
87    } else if (removed.flags & Snapshot::kFlagIsLayer) {
88        addOp(new (alloc()) EndUnclippedLayerOp());
89    }
90}
91
92// ----------------------------------------------------------------------------
93// android/graphics/Canvas state operations
94// ----------------------------------------------------------------------------
95// Save (layer)
96int RecordingCanvas::save(SaveFlags::Flags flags) {
97    return mState.save((int) flags);
98}
99
100void RecordingCanvas::RecordingCanvas::restore() {
101    mState.restore();
102}
103
104void RecordingCanvas::restoreToCount(int saveCount) {
105    mState.restoreToCount(saveCount);
106}
107
108int RecordingCanvas::saveLayer(float left, float top, float right, float bottom,
109        const SkPaint* paint, SaveFlags::Flags flags) {
110    // force matrix/clip isolation for layer
111    flags |= SaveFlags::MatrixClip;
112    bool clippedLayer = flags & SaveFlags::ClipToLayer;
113
114    const Snapshot& previous = *mState.currentSnapshot();
115
116    // initialize the snapshot as though it almost represents an FBO layer so deferred draw
117    // operations will be able to store and restore the current clip and transform info, and
118    // quick rejection will be correct (for display lists)
119
120    const Rect unmappedBounds(left, top, right, bottom);
121
122    // determine clipped bounds relative to previous viewport.
123    Rect visibleBounds = unmappedBounds;
124    previous.transform->mapRect(visibleBounds);
125
126    if (CC_UNLIKELY(!clippedLayer
127            && previous.transform->rectToRect()
128            && visibleBounds.contains(previous.getRenderTargetClip()))) {
129        // unlikely case where an unclipped savelayer is recorded with a clip it can use,
130        // as none of its unaffected/unclipped area is visible
131        clippedLayer = true;
132        flags |= SaveFlags::ClipToLayer;
133    }
134
135    visibleBounds.doIntersect(previous.getRenderTargetClip());
136    visibleBounds.snapToPixelBoundaries();
137    visibleBounds.doIntersect(Rect(previous.getViewportWidth(), previous.getViewportHeight()));
138
139    // Map visible bounds back to layer space, and intersect with parameter bounds
140    Rect layerBounds = visibleBounds;
141    Matrix4 inverse;
142    inverse.loadInverse(*previous.transform);
143    inverse.mapRect(layerBounds);
144    layerBounds.doIntersect(unmappedBounds);
145
146    int saveValue = mState.save((int) flags);
147    Snapshot& snapshot = *mState.writableSnapshot();
148
149    // layerBounds is in original bounds space, but clipped by current recording clip
150    if (layerBounds.isEmpty() || unmappedBounds.isEmpty()) {
151        // Don't bother recording layer, since it's been rejected
152        if (CC_LIKELY(clippedLayer)) {
153            snapshot.resetClip(0, 0, 0, 0);
154        }
155        return saveValue;
156    }
157
158    if (CC_LIKELY(clippedLayer)) {
159        auto previousClip = getRecordedClip(); // note: done before new snapshot's clip has changed
160
161        snapshot.flags |= Snapshot::kFlagIsLayer | Snapshot::kFlagIsFboLayer;
162        snapshot.initializeViewport(unmappedBounds.getWidth(), unmappedBounds.getHeight());
163        snapshot.transform->loadTranslate(-unmappedBounds.left, -unmappedBounds.top, 0.0f);
164
165        Rect clip = layerBounds;
166        clip.translate(-unmappedBounds.left, -unmappedBounds.top);
167        snapshot.resetClip(clip.left, clip.top, clip.right, clip.bottom);
168        snapshot.roundRectClipState = nullptr;
169
170        addOp(new (alloc()) BeginLayerOp(
171                unmappedBounds,
172                *previous.transform, // transform to *draw* with
173                previousClip, // clip to *draw* with
174                refPaint(paint)));
175    } else {
176        snapshot.flags |= Snapshot::kFlagIsLayer;
177
178        addOp(new (alloc()) BeginUnclippedLayerOp(
179                unmappedBounds,
180                *mState.currentSnapshot()->transform,
181                getRecordedClip(),
182                refPaint(paint)));
183    }
184
185    return saveValue;
186}
187
188// Matrix
189void RecordingCanvas::rotate(float degrees) {
190    if (degrees == 0) return;
191
192    mState.rotate(degrees);
193}
194
195void RecordingCanvas::scale(float sx, float sy) {
196    if (sx == 1 && sy == 1) return;
197
198    mState.scale(sx, sy);
199}
200
201void RecordingCanvas::skew(float sx, float sy) {
202    mState.skew(sx, sy);
203}
204
205void RecordingCanvas::translate(float dx, float dy) {
206    if (dx == 0 && dy == 0) return;
207
208    mState.translate(dx, dy, 0);
209}
210
211// Clip
212bool RecordingCanvas::getClipBounds(SkRect* outRect) const {
213    *outRect = mState.getLocalClipBounds().toSkRect();
214    return !(outRect->isEmpty());
215}
216bool RecordingCanvas::quickRejectRect(float left, float top, float right, float bottom) const {
217    return mState.quickRejectConservative(left, top, right, bottom);
218}
219bool RecordingCanvas::quickRejectPath(const SkPath& path) const {
220    SkRect bounds = path.getBounds();
221    return mState.quickRejectConservative(bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom);
222}
223bool RecordingCanvas::clipRect(float left, float top, float right, float bottom, SkRegion::Op op) {
224    return mState.clipRect(left, top, right, bottom, op);
225}
226bool RecordingCanvas::clipPath(const SkPath* path, SkRegion::Op op) {
227    return mState.clipPath(path, op);
228}
229bool RecordingCanvas::clipRegion(const SkRegion* region, SkRegion::Op op) {
230    return mState.clipRegion(region, op);
231}
232
233// ----------------------------------------------------------------------------
234// android/graphics/Canvas draw operations
235// ----------------------------------------------------------------------------
236void RecordingCanvas::drawColor(int color, SkXfermode::Mode mode) {
237    SkPaint paint;
238    paint.setColor(color);
239    paint.setXfermodeMode(mode);
240    drawPaint(paint);
241}
242
243void RecordingCanvas::drawPaint(const SkPaint& paint) {
244    addOp(new (alloc()) RectOp(
245            mState.getRenderTargetClipBounds(), // OK, since we've not passed transform
246            Matrix4::identity(),
247            getRecordedClip(),
248            refPaint(&paint)));
249}
250
251static Rect calcBoundsOfPoints(const float* points, int floatCount) {
252    Rect unmappedBounds(points[0], points[1], points[0], points[1]);
253    for (int i = 2; i < floatCount; i += 2) {
254        unmappedBounds.expandToCover(points[i], points[i + 1]);
255    }
256    return unmappedBounds;
257}
258
259// Geometry
260void RecordingCanvas::drawPoints(const float* points, int floatCount, const SkPaint& paint) {
261    if (floatCount < 2) return;
262    floatCount &= ~0x1; // round down to nearest two
263
264    addOp(new (alloc()) PointsOp(
265            calcBoundsOfPoints(points, floatCount),
266            *mState.currentSnapshot()->transform,
267            getRecordedClip(),
268            refPaint(&paint), refBuffer<float>(points, floatCount), floatCount));
269}
270
271void RecordingCanvas::drawLines(const float* points, int floatCount, const SkPaint& paint) {
272    if (floatCount < 4) return;
273    floatCount &= ~0x3; // round down to nearest four
274
275    addOp(new (alloc()) LinesOp(
276            calcBoundsOfPoints(points, floatCount),
277            *mState.currentSnapshot()->transform,
278            getRecordedClip(),
279            refPaint(&paint), refBuffer<float>(points, floatCount), floatCount));
280}
281
282void RecordingCanvas::drawRect(float left, float top, float right, float bottom, const SkPaint& paint) {
283    addOp(new (alloc()) RectOp(
284            Rect(left, top, right, bottom),
285            *(mState.currentSnapshot()->transform),
286            getRecordedClip(),
287            refPaint(&paint)));
288}
289
290void RecordingCanvas::drawSimpleRects(const float* rects, int vertexCount, const SkPaint* paint) {
291    if (rects == nullptr) return;
292
293    Vertex* rectData = (Vertex*) mDisplayList->allocator.alloc(vertexCount * sizeof(Vertex));
294    Vertex* vertex = rectData;
295
296    float left = FLT_MAX;
297    float top = FLT_MAX;
298    float right = FLT_MIN;
299    float bottom = FLT_MIN;
300    for (int index = 0; index < vertexCount; index += 4) {
301        float l = rects[index + 0];
302        float t = rects[index + 1];
303        float r = rects[index + 2];
304        float b = rects[index + 3];
305
306        Vertex::set(vertex++, l, t);
307        Vertex::set(vertex++, r, t);
308        Vertex::set(vertex++, l, b);
309        Vertex::set(vertex++, r, b);
310
311        left = std::min(left, l);
312        top = std::min(top, t);
313        right = std::max(right, r);
314        bottom = std::max(bottom, b);
315    }
316    addOp(new (alloc()) SimpleRectsOp(
317            Rect(left, top, right, bottom),
318            *(mState.currentSnapshot()->transform),
319            getRecordedClip(),
320            refPaint(paint), rectData, vertexCount));
321}
322
323void RecordingCanvas::drawRegion(const SkRegion& region, const SkPaint& paint) {
324    if (paint.getStyle() == SkPaint::kFill_Style
325            && (!paint.isAntiAlias() || mState.currentTransform()->isSimple())) {
326        int count = 0;
327        Vector<float> rects;
328        SkRegion::Iterator it(region);
329        while (!it.done()) {
330            const SkIRect& r = it.rect();
331            rects.push(r.fLeft);
332            rects.push(r.fTop);
333            rects.push(r.fRight);
334            rects.push(r.fBottom);
335            count += 4;
336            it.next();
337        }
338        drawSimpleRects(rects.array(), count, &paint);
339    } else {
340        SkRegion::Iterator it(region);
341        while (!it.done()) {
342            const SkIRect& r = it.rect();
343            drawRect(r.fLeft, r.fTop, r.fRight, r.fBottom, paint);
344            it.next();
345        }
346    }
347}
348void RecordingCanvas::drawRoundRect(float left, float top, float right, float bottom,
349            float rx, float ry, const SkPaint& paint) {
350    addOp(new (alloc()) RoundRectOp(
351            Rect(left, top, right, bottom),
352            *(mState.currentSnapshot()->transform),
353            getRecordedClip(),
354            refPaint(&paint), rx, ry));
355}
356
357void RecordingCanvas::drawRoundRect(
358        CanvasPropertyPrimitive* left, CanvasPropertyPrimitive* top,
359        CanvasPropertyPrimitive* right, CanvasPropertyPrimitive* bottom,
360        CanvasPropertyPrimitive* rx, CanvasPropertyPrimitive* ry,
361        CanvasPropertyPaint* paint) {
362    mDisplayList->ref(left);
363    mDisplayList->ref(top);
364    mDisplayList->ref(right);
365    mDisplayList->ref(bottom);
366    mDisplayList->ref(rx);
367    mDisplayList->ref(ry);
368    mDisplayList->ref(paint);
369    refBitmapsInShader(paint->value.getShader());
370    addOp(new (alloc()) RoundRectPropsOp(
371            *(mState.currentSnapshot()->transform),
372            getRecordedClip(),
373            &paint->value,
374            &left->value, &top->value, &right->value, &bottom->value,
375            &rx->value, &ry->value));
376}
377
378void RecordingCanvas::drawCircle(float x, float y, float radius, const SkPaint& paint) {
379    // TODO: move to Canvas.h
380    if (radius <= 0) return;
381    drawOval(x - radius, y - radius, x + radius, y + radius, paint);
382}
383
384void RecordingCanvas::drawCircle(
385        CanvasPropertyPrimitive* x, CanvasPropertyPrimitive* y,
386        CanvasPropertyPrimitive* radius, CanvasPropertyPaint* paint) {
387    mDisplayList->ref(x);
388    mDisplayList->ref(y);
389    mDisplayList->ref(radius);
390    mDisplayList->ref(paint);
391    refBitmapsInShader(paint->value.getShader());
392    addOp(new (alloc()) CirclePropsOp(
393            *(mState.currentSnapshot()->transform),
394            getRecordedClip(),
395            &paint->value,
396            &x->value, &y->value, &radius->value));
397}
398
399void RecordingCanvas::drawOval(float left, float top, float right, float bottom, const SkPaint& paint) {
400    addOp(new (alloc()) OvalOp(
401            Rect(left, top, right, bottom),
402            *(mState.currentSnapshot()->transform),
403            getRecordedClip(),
404            refPaint(&paint)));
405}
406
407void RecordingCanvas::drawArc(float left, float top, float right, float bottom,
408        float startAngle, float sweepAngle, bool useCenter, const SkPaint& paint) {
409    addOp(new (alloc()) ArcOp(
410            Rect(left, top, right, bottom),
411            *(mState.currentSnapshot()->transform),
412            getRecordedClip(),
413            refPaint(&paint),
414            startAngle, sweepAngle, useCenter));
415}
416
417void RecordingCanvas::drawPath(const SkPath& path, const SkPaint& paint) {
418    addOp(new (alloc()) PathOp(
419            Rect(path.getBounds()),
420            *(mState.currentSnapshot()->transform),
421            getRecordedClip(),
422            refPaint(&paint), refPath(&path)));
423}
424
425void RecordingCanvas::drawVectorDrawable(VectorDrawableRoot* tree) {
426    mDisplayList->ref(tree);
427    addOp(new (alloc()) VectorDrawableOp(
428            tree,
429            Rect(tree->getBounds()),
430            *(mState.currentSnapshot()->transform),
431            getRecordedClip()));
432}
433
434// Bitmap-based
435void RecordingCanvas::drawBitmap(const SkBitmap& bitmap, float left, float top, const SkPaint* paint) {
436    save(SaveFlags::Matrix);
437    translate(left, top);
438    drawBitmap(&bitmap, paint);
439    restore();
440}
441
442void RecordingCanvas::drawBitmap(const SkBitmap& bitmap, const SkMatrix& matrix,
443                            const SkPaint* paint) {
444    if (matrix.isIdentity()) {
445        drawBitmap(&bitmap, paint);
446    } else if (!(matrix.getType() & ~(SkMatrix::kScale_Mask | SkMatrix::kTranslate_Mask))
447            && MathUtils::isPositive(matrix.getScaleX())
448            && MathUtils::isPositive(matrix.getScaleY())) {
449        // SkMatrix::isScaleTranslate() not available in L
450        SkRect src;
451        SkRect dst;
452        bitmap.getBounds(&src);
453        matrix.mapRect(&dst, src);
454        drawBitmap(bitmap, src.fLeft, src.fTop, src.fRight, src.fBottom,
455                   dst.fLeft, dst.fTop, dst.fRight, dst.fBottom, paint);
456    } else {
457        save(SaveFlags::Matrix);
458        concat(matrix);
459        drawBitmap(&bitmap, paint);
460        restore();
461    }
462}
463
464void RecordingCanvas::drawBitmap(const SkBitmap& bitmap, float srcLeft, float srcTop,
465            float srcRight, float srcBottom, float dstLeft, float dstTop,
466            float dstRight, float dstBottom, const SkPaint* paint) {
467    if (srcLeft == 0 && srcTop == 0
468            && srcRight == bitmap.width()
469            && srcBottom == bitmap.height()
470            && (srcBottom - srcTop == dstBottom - dstTop)
471            && (srcRight - srcLeft == dstRight - dstLeft)) {
472        // transform simple rect to rect drawing case into position bitmap ops, since they merge
473        save(SaveFlags::Matrix);
474        translate(dstLeft, dstTop);
475        drawBitmap(&bitmap, paint);
476        restore();
477    } else {
478        addOp(new (alloc()) BitmapRectOp(
479                Rect(dstLeft, dstTop, dstRight, dstBottom),
480                *(mState.currentSnapshot()->transform),
481                getRecordedClip(),
482                refPaint(paint), refBitmap(bitmap),
483                Rect(srcLeft, srcTop, srcRight, srcBottom)));
484    }
485}
486
487void RecordingCanvas::drawBitmapMesh(const SkBitmap& bitmap, int meshWidth, int meshHeight,
488            const float* vertices, const int* colors, const SkPaint* paint) {
489    int vertexCount = (meshWidth + 1) * (meshHeight + 1);
490    addOp(new (alloc()) BitmapMeshOp(
491            calcBoundsOfPoints(vertices, vertexCount * 2),
492            *(mState.currentSnapshot()->transform),
493            getRecordedClip(),
494            refPaint(paint), refBitmap(bitmap), meshWidth, meshHeight,
495            refBuffer<float>(vertices, vertexCount * 2), // 2 floats per vertex
496            refBuffer<int>(colors, vertexCount))); // 1 color per vertex
497}
498
499void RecordingCanvas::drawNinePatch(const SkBitmap& bitmap, const android::Res_png_9patch& patch,
500            float dstLeft, float dstTop, float dstRight, float dstBottom,
501            const SkPaint* paint) {
502    addOp(new (alloc()) PatchOp(
503            Rect(dstLeft, dstTop, dstRight, dstBottom),
504            *(mState.currentSnapshot()->transform),
505            getRecordedClip(),
506            refPaint(paint), refBitmap(bitmap), refPatch(&patch)));
507}
508
509// Text
510void RecordingCanvas::drawText(const uint16_t* glyphs, const float* positions, int glyphCount,
511            const SkPaint& paint, float x, float y, float boundsLeft, float boundsTop,
512            float boundsRight, float boundsBottom, float totalAdvance) {
513    if (!glyphs || !positions || glyphCount <= 0 || PaintUtils::paintWillNotDrawText(paint)) return;
514    glyphs = refBuffer<glyph_t>(glyphs, glyphCount);
515    positions = refBuffer<float>(positions, glyphCount * 2);
516
517    // TODO: either must account for text shadow in bounds, or record separate ops for text shadows
518    addOp(new (alloc()) TextOp(
519            Rect(boundsLeft, boundsTop, boundsRight, boundsBottom),
520            *(mState.currentSnapshot()->transform),
521            getRecordedClip(),
522            refPaint(&paint), glyphs, positions, glyphCount, x, y));
523    drawTextDecorations(x, y, totalAdvance, paint);
524}
525
526void RecordingCanvas::drawTextOnPath(const uint16_t* glyphs, int glyphCount, const SkPath& path,
527            float hOffset, float vOffset, const SkPaint& paint) {
528    if (!glyphs || glyphCount <= 0 || PaintUtils::paintWillNotDrawText(paint)) return;
529    glyphs = refBuffer<glyph_t>(glyphs, glyphCount);
530    addOp(new (alloc()) TextOnPathOp(
531            mState.getLocalClipBounds(), // TODO: explicitly define bounds
532            *(mState.currentSnapshot()->transform),
533            getRecordedClip(),
534            refPaint(&paint), glyphs, glyphCount, refPath(&path), hOffset, vOffset));
535}
536
537void RecordingCanvas::drawBitmap(const SkBitmap* bitmap, const SkPaint* paint) {
538    addOp(new (alloc()) BitmapOp(
539            Rect(bitmap->width(), bitmap->height()),
540            *(mState.currentSnapshot()->transform),
541            getRecordedClip(),
542            refPaint(paint), refBitmap(*bitmap)));
543}
544
545void RecordingCanvas::drawRenderNode(RenderNode* renderNode) {
546    auto&& stagingProps = renderNode->stagingProperties();
547    RenderNodeOp* op = new (alloc()) RenderNodeOp(
548            Rect(stagingProps.getWidth(), stagingProps.getHeight()),
549            *(mState.currentSnapshot()->transform),
550            getRecordedClip(),
551            renderNode);
552    int opIndex = addOp(op);
553    int childIndex = mDisplayList->addChild(op);
554
555    // update the chunk's child indices
556    DisplayList::Chunk& chunk = mDisplayList->chunks.back();
557    chunk.endChildIndex = childIndex + 1;
558
559    if (renderNode->stagingProperties().isProjectionReceiver()) {
560        // use staging property, since recording on UI thread
561        mDisplayList->projectionReceiveIndex = opIndex;
562    }
563}
564
565void RecordingCanvas::drawLayer(DeferredLayerUpdater* layerHandle) {
566    // We ref the DeferredLayerUpdater due to its thread-safe ref-counting semantics.
567    mDisplayList->ref(layerHandle);
568
569    Layer* layer = layerHandle->backingLayer();
570    Matrix4 totalTransform(*(mState.currentSnapshot()->transform));
571    totalTransform.multiply(layer->getTransform());
572
573    addOp(new (alloc()) TextureLayerOp(
574            Rect(layer->getWidth(), layer->getHeight()),
575            totalTransform,
576            getRecordedClip(),
577            layer));
578}
579
580void RecordingCanvas::callDrawGLFunction(Functor* functor) {
581    mDisplayList->functors.push_back(functor);
582    addOp(new (alloc()) FunctorOp(
583            mState.getLocalClipBounds(), // TODO: explicitly define bounds
584            *(mState.currentSnapshot()->transform),
585            getRecordedClip(),
586            functor));
587}
588
589size_t RecordingCanvas::addOp(RecordedOp* op) {
590    // TODO: validate if "addDrawOp" quickrejection logic is useful before adding
591    int insertIndex = mDisplayList->ops.size();
592    mDisplayList->ops.push_back(op);
593    if (mDeferredBarrierType != DeferredBarrierType::None) {
594        // op is first in new chunk
595        mDisplayList->chunks.emplace_back();
596        DisplayList::Chunk& newChunk = mDisplayList->chunks.back();
597        newChunk.beginOpIndex = insertIndex;
598        newChunk.endOpIndex = insertIndex + 1;
599        newChunk.reorderChildren = (mDeferredBarrierType == DeferredBarrierType::OutOfOrder);
600
601        int nextChildIndex = mDisplayList->children.size();
602        newChunk.beginChildIndex = newChunk.endChildIndex = nextChildIndex;
603        mDeferredBarrierType = DeferredBarrierType::None;
604    } else {
605        // standard case - append to existing chunk
606        mDisplayList->chunks.back().endOpIndex = insertIndex + 1;
607    }
608    return insertIndex;
609}
610
611void RecordingCanvas::refBitmapsInShader(const SkShader* shader) {
612    if (!shader) return;
613
614    // If this paint has an SkShader that has an SkBitmap add
615    // it to the bitmap pile
616    SkBitmap bitmap;
617    SkShader::TileMode xy[2];
618    if (shader->isABitmap(&bitmap, nullptr, xy)) {
619        refBitmap(bitmap);
620        return;
621    }
622    SkShader::ComposeRec rec;
623    if (shader->asACompose(&rec)) {
624        refBitmapsInShader(rec.fShaderA);
625        refBitmapsInShader(rec.fShaderB);
626        return;
627    }
628}
629
630}; // namespace uirenderer
631}; // namespace android
632