• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2014 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #include "include/core/SkImage.h"
9 #include "src/core/SkCanvasPriv.h"
10 #include "src/core/SkRecordDraw.h"
11 #include "src/utils/SkPatchUtils.h"
12 
SkRecordDraw(const SkRecord & record,SkCanvas * canvas,SkPicture const * const drawablePicts[],SkDrawable * const drawables[],int drawableCount,const SkBBoxHierarchy * bbh,SkPicture::AbortCallback * callback)13 void SkRecordDraw(const SkRecord& record,
14                   SkCanvas* canvas,
15                   SkPicture const* const drawablePicts[],
16                   SkDrawable* const drawables[],
17                   int drawableCount,
18                   const SkBBoxHierarchy* bbh,
19                   SkPicture::AbortCallback* callback) {
20     SkAutoCanvasRestore saveRestore(canvas, true /*save now, restore at exit*/);
21 
22     if (bbh) {
23         // Draw only ops that affect pixels in the canvas's current clip.
24         // The SkRecord and BBH were recorded in identity space.  This canvas
25         // is not necessarily in that same space.  getLocalClipBounds() returns us
26         // this canvas' clip bounds transformed back into identity space, which
27         // lets us query the BBH.
28         SkRect query = canvas->getLocalClipBounds();
29 
30         SkTDArray<int> ops;
31         bbh->search(query, &ops);
32 
33         SkRecords::Draw draw(canvas, drawablePicts, drawables, drawableCount);
34         for (int i = 0; i < ops.count(); i++) {
35             if (callback && callback->abort()) {
36                 return;
37             }
38             // This visit call uses the SkRecords::Draw::operator() to call
39             // methods on the |canvas|, wrapped by methods defined with the
40             // DRAW() macro.
41             record.visit(ops[i], draw);
42         }
43     } else {
44         // Draw all ops.
45         SkRecords::Draw draw(canvas, drawablePicts, drawables, drawableCount);
46         for (int i = 0; i < record.count(); i++) {
47             if (callback && callback->abort()) {
48                 return;
49             }
50             // This visit call uses the SkRecords::Draw::operator() to call
51             // methods on the |canvas|, wrapped by methods defined with the
52             // DRAW() macro.
53             record.visit(i, draw);
54         }
55     }
56 }
57 
SkRecordPartialDraw(const SkRecord & record,SkCanvas * canvas,SkPicture const * const drawablePicts[],int drawableCount,int start,int stop,const SkMatrix & initialCTM)58 void SkRecordPartialDraw(const SkRecord& record, SkCanvas* canvas,
59                          SkPicture const* const drawablePicts[], int drawableCount,
60                          int start, int stop,
61                          const SkMatrix& initialCTM) {
62     SkAutoCanvasRestore saveRestore(canvas, true /*save now, restore at exit*/);
63 
64     stop = SkTMin(stop, record.count());
65     SkRecords::Draw draw(canvas, drawablePicts, nullptr, drawableCount, &initialCTM);
66     for (int i = start; i < stop; i++) {
67         record.visit(i, draw);
68     }
69 }
70 
71 namespace SkRecords {
72 
73 // NoOps draw nothing.
draw(const NoOp &)74 template <> void Draw::draw(const NoOp&) {}
75 
76 #define DRAW(T, call) template <> void Draw::draw(const T& r) { fCanvas->call; }
77 DRAW(Flush, flush());
78 DRAW(Restore, restore());
79 DRAW(Save, save());
80 DRAW(SaveLayer, saveLayer(SkCanvas::SaveLayerRec(r.bounds,
81                                                  r.paint,
82                                                  r.backdrop.get(),
83                                                  r.clipMask.get(),
84                                                  r.clipMatrix,
85                                                  r.saveLayerFlags)));
86 
draw(const SaveBehind & r)87 template <> void Draw::draw(const SaveBehind& r) {
88     SkCanvasPriv::SaveBehind(fCanvas, r.subset);
89 }
90 
draw(const DrawBehind & r)91 template <> void Draw::draw(const DrawBehind& r) {
92     SkCanvasPriv::DrawBehind(fCanvas, r.paint);
93 }
94 
95 DRAW(SetMatrix, setMatrix(SkMatrix::Concat(fInitialCTM, r.matrix)));
96 DRAW(Concat, concat(r.matrix));
97 DRAW(Translate, translate(r.dx, r.dy));
98 
99 DRAW(ClipPath, clipPath(r.path, r.opAA.op(), r.opAA.aa()));
100 DRAW(ClipRRect, clipRRect(r.rrect, r.opAA.op(), r.opAA.aa()));
101 DRAW(ClipRect, clipRect(r.rect, r.opAA.op(), r.opAA.aa()));
102 DRAW(ClipRegion, clipRegion(r.region, r.op));
103 
104 DRAW(DrawArc, drawArc(r.oval, r.startAngle, r.sweepAngle, r.useCenter, r.paint));
105 DRAW(DrawDRRect, drawDRRect(r.outer, r.inner, r.paint));
106 DRAW(DrawImage, drawImage(r.image.get(), r.left, r.top, r.paint));
107 
draw(const DrawImageLattice & r)108 template <> void Draw::draw(const DrawImageLattice& r) {
109     SkCanvas::Lattice lattice;
110     lattice.fXCount = r.xCount;
111     lattice.fXDivs = r.xDivs;
112     lattice.fYCount = r.yCount;
113     lattice.fYDivs = r.yDivs;
114     lattice.fRectTypes = (0 == r.flagCount) ? nullptr : r.flags;
115     lattice.fColors = (0 == r.flagCount) ? nullptr : r.colors;
116     lattice.fBounds = &r.src;
117     fCanvas->drawImageLattice(r.image.get(), lattice, r.dst, r.paint);
118 }
119 
120 DRAW(DrawImageRect, legacy_drawImageRect(r.image.get(), r.src, r.dst, r.paint, r.constraint));
121 DRAW(DrawImageNine, drawImageNine(r.image.get(), r.center, r.dst, r.paint));
122 DRAW(DrawOval, drawOval(r.oval, r.paint));
123 DRAW(DrawPaint, drawPaint(r.paint));
124 DRAW(DrawPath, drawPath(r.path, r.paint));
125 DRAW(DrawPatch, drawPatch(r.cubics, r.colors, r.texCoords, r.bmode, r.paint));
126 DRAW(DrawPicture, drawPicture(r.picture.get(), &r.matrix, r.paint));
127 DRAW(DrawPoints, drawPoints(r.mode, r.count, r.pts, r.paint));
128 DRAW(DrawRRect, drawRRect(r.rrect, r.paint));
129 DRAW(DrawRect, drawRect(r.rect, r.paint));
130 DRAW(DrawRegion, drawRegion(r.region, r.paint));
131 DRAW(DrawTextBlob, drawTextBlob(r.blob.get(), r.x, r.y, r.paint));
132 DRAW(DrawAtlas, drawAtlas(r.atlas.get(),
133                           r.xforms, r.texs, r.colors, r.count, r.mode, r.cull, r.paint));
134 DRAW(DrawVertices, drawVertices(r.vertices, r.bones, r.boneCount, r.bmode, r.paint));
135 DRAW(DrawShadowRec, private_draw_shadow_rec(r.path, r.rec));
136 DRAW(DrawAnnotation, drawAnnotation(r.rect, r.key.c_str(), r.value.get()));
137 
138 DRAW(DrawEdgeAAQuad, experimental_DrawEdgeAAQuad(
139         r.rect, r.clip, r.aa, r.color, r.mode));
140 DRAW(DrawEdgeAAImageSet, experimental_DrawEdgeAAImageSet(
141         r.set.get(), r.count, r.dstClips, r.preViewMatrices, r.paint, r.constraint));
142 
143 #undef DRAW
144 
draw(const DrawDrawable & r)145 template <> void Draw::draw(const DrawDrawable& r) {
146     SkASSERT(r.index >= 0);
147     SkASSERT(r.index < fDrawableCount);
148     if (fDrawables) {
149         SkASSERT(nullptr == fDrawablePicts);
150         fCanvas->drawDrawable(fDrawables[r.index], r.matrix);
151     } else {
152         fCanvas->drawPicture(fDrawablePicts[r.index], r.matrix, nullptr);
153     }
154 }
155 
156 // This is an SkRecord visitor that fills an SkBBoxHierarchy.
157 //
158 // The interesting part here is how to calculate bounds for ops which don't
159 // have intrinsic bounds.  What is the bounds of a Save or a Translate?
160 //
161 // We answer this by thinking about a particular definition of bounds: if I
162 // don't execute this op, pixels in this rectangle might draw incorrectly.  So
163 // the bounds of a Save, a Translate, a Restore, etc. are the union of the
164 // bounds of Draw* ops that they might have an effect on.  For any given
165 // Save/Restore block, the bounds of the Save, the Restore, and any other
166 // non-drawing ("control") ops inside are exactly the union of the bounds of
167 // the drawing ops inside that block.
168 //
169 // To implement this, we keep a stack of active Save blocks.  As we consume ops
170 // inside the Save/Restore block, drawing ops are unioned with the bounds of
171 // the block, and control ops are stashed away for later.  When we finish the
172 // block with a Restore, our bounds are complete, and we go back and fill them
173 // in for all the control ops we stashed away.
174 class FillBounds : SkNoncopyable {
175 public:
FillBounds(const SkRect & cullRect,const SkRecord & record,SkRect bounds[])176     FillBounds(const SkRect& cullRect, const SkRecord& record, SkRect bounds[])
177         : fNumRecords(record.count())
178         , fCullRect(cullRect)
179         , fBounds(bounds) {
180         fCTM = SkMatrix::I();
181 
182         // We push an extra save block to track the bounds of any top-level control operations.
183         fSaveStack.push_back({ 0, Bounds::MakeEmpty(), nullptr, fCTM });
184     }
185 
cleanUp()186     void cleanUp() {
187         // If we have any lingering unpaired Saves, simulate restores to make
188         // sure all ops in those Save blocks have their bounds calculated.
189         while (!fSaveStack.isEmpty()) {
190             this->popSaveBlock();
191         }
192 
193         // Any control ops not part of any Save/Restore block draw everywhere.
194         while (!fControlIndices.isEmpty()) {
195             this->popControl(fCullRect);
196         }
197     }
198 
setCurrentOp(int currentOp)199     void setCurrentOp(int currentOp) { fCurrentOp = currentOp; }
200 
201 
operator ()(const T & op)202     template <typename T> void operator()(const T& op) {
203         this->updateCTM(op);
204         this->trackBounds(op);
205     }
206 
207     // In this file, SkRect are in local coordinates, Bounds are translated back to identity space.
208     typedef SkRect Bounds;
209 
currentOp() const210     int currentOp() const { return fCurrentOp; }
ctm() const211     const SkMatrix& ctm() const { return fCTM; }
getBounds(int index) const212     const Bounds& getBounds(int index) const { return fBounds[index]; }
213 
214     // Adjust rect for all paints that may affect its geometry, then map it to identity space.
adjustAndMap(SkRect rect,const SkPaint * paint) const215     Bounds adjustAndMap(SkRect rect, const SkPaint* paint) const {
216         // Inverted rectangles really confuse our BBHs.
217         rect.sort();
218 
219         // Adjust the rect for its own paint.
220         if (!AdjustForPaint(paint, &rect)) {
221             // The paint could do anything to our bounds.  The only safe answer is the cull.
222             return fCullRect;
223         }
224 
225         // Adjust rect for all the paints from the SaveLayers we're inside.
226         if (!this->adjustForSaveLayerPaints(&rect)) {
227             // Same deal as above.
228             return fCullRect;
229         }
230 
231         // Map the rect back to identity space.
232         fCTM.mapRect(&rect);
233 
234         // Nothing can draw outside the cull rect.
235         if (!rect.intersect(fCullRect)) {
236             return Bounds::MakeEmpty();
237         }
238 
239         return rect;
240     }
241 
242 private:
243     struct SaveBounds {
244         int controlOps;        // Number of control ops in this Save block, including the Save.
245         Bounds bounds;         // Bounds of everything in the block.
246         const SkPaint* paint;  // Unowned.  If set, adjusts the bounds of all ops in this block.
247         SkMatrix ctm;
248     };
249 
250     // Only Restore, SetMatrix, Concat, and Translate change the CTM.
updateCTM(const T &)251     template <typename T> void updateCTM(const T&) {}
updateCTM(const Restore & op)252     void updateCTM(const Restore& op)   { fCTM = op.matrix; }
updateCTM(const SetMatrix & op)253     void updateCTM(const SetMatrix& op) { fCTM = op.matrix; }
updateCTM(const Concat & op)254     void updateCTM(const Concat& op)    { fCTM.preConcat(op.matrix); }
updateCTM(const Translate & op)255     void updateCTM(const Translate& op) { fCTM.preTranslate(op.dx, op.dy); }
256 
257     // The bounds of these ops must be calculated when we hit the Restore
258     // from the bounds of the ops in the same Save block.
trackBounds(const Save &)259     void trackBounds(const Save&)          { this->pushSaveBlock(nullptr); }
trackBounds(const SaveLayer & op)260     void trackBounds(const SaveLayer& op)  { this->pushSaveBlock(op.paint); }
trackBounds(const SaveBehind &)261     void trackBounds(const SaveBehind&)    { this->pushSaveBlock(nullptr); }
trackBounds(const Restore &)262     void trackBounds(const Restore&) { fBounds[fCurrentOp] = this->popSaveBlock(); }
263 
trackBounds(const SetMatrix &)264     void trackBounds(const SetMatrix&)         { this->pushControl(); }
trackBounds(const Concat &)265     void trackBounds(const Concat&)            { this->pushControl(); }
trackBounds(const Translate &)266     void trackBounds(const Translate&)         { this->pushControl(); }
trackBounds(const ClipRect &)267     void trackBounds(const ClipRect&)          { this->pushControl(); }
trackBounds(const ClipRRect &)268     void trackBounds(const ClipRRect&)         { this->pushControl(); }
trackBounds(const ClipPath &)269     void trackBounds(const ClipPath&)          { this->pushControl(); }
trackBounds(const ClipRegion &)270     void trackBounds(const ClipRegion&)        { this->pushControl(); }
271 
272 
273     // For all other ops, we can calculate and store the bounds directly now.
trackBounds(const T & op)274     template <typename T> void trackBounds(const T& op) {
275         fBounds[fCurrentOp] = this->bounds(op);
276         this->updateSaveBounds(fBounds[fCurrentOp]);
277     }
278 
pushSaveBlock(const SkPaint * paint)279     void pushSaveBlock(const SkPaint* paint) {
280         // Starting a new Save block.  Push a new entry to represent that.
281         SaveBounds sb;
282         sb.controlOps = 0;
283         // If the paint affects transparent black,
284         // the bound shouldn't be smaller than the cull.
285         sb.bounds =
286             PaintMayAffectTransparentBlack(paint) ? fCullRect : Bounds::MakeEmpty();
287         sb.paint = paint;
288         sb.ctm = this->fCTM;
289 
290         fSaveStack.push_back(sb);
291         this->pushControl();
292     }
293 
PaintMayAffectTransparentBlack(const SkPaint * paint)294     static bool PaintMayAffectTransparentBlack(const SkPaint* paint) {
295         if (paint) {
296             // FIXME: this is very conservative
297             if (paint->getImageFilter() || paint->getColorFilter()) {
298                 return true;
299             }
300 
301             // Unusual blendmodes require us to process a saved layer
302             // even with operations outisde the clip.
303             // For example, DstIn is used by masking layers.
304             // https://code.google.com/p/skia/issues/detail?id=1291
305             // https://crbug.com/401593
306             switch (paint->getBlendMode()) {
307                 // For each of the following transfer modes, if the source
308                 // alpha is zero (our transparent black), the resulting
309                 // blended alpha is not necessarily equal to the original
310                 // destination alpha.
311                 case SkBlendMode::kClear:
312                 case SkBlendMode::kSrc:
313                 case SkBlendMode::kSrcIn:
314                 case SkBlendMode::kDstIn:
315                 case SkBlendMode::kSrcOut:
316                 case SkBlendMode::kDstATop:
317                 case SkBlendMode::kModulate:
318                     return true;
319                     break;
320                 default:
321                     break;
322             }
323         }
324         return false;
325     }
326 
popSaveBlock()327     Bounds popSaveBlock() {
328         // We're done the Save block.  Apply the block's bounds to all control ops inside it.
329         SaveBounds sb;
330         fSaveStack.pop(&sb);
331 
332         while (sb.controlOps --> 0) {
333             this->popControl(sb.bounds);
334         }
335 
336         // This whole Save block may be part another Save block.
337         this->updateSaveBounds(sb.bounds);
338 
339         // If called from a real Restore (not a phony one for balance), it'll need the bounds.
340         return sb.bounds;
341     }
342 
pushControl()343     void pushControl() {
344         fControlIndices.push_back(fCurrentOp);
345         if (!fSaveStack.isEmpty()) {
346             fSaveStack.top().controlOps++;
347         }
348     }
349 
popControl(const Bounds & bounds)350     void popControl(const Bounds& bounds) {
351         fBounds[fControlIndices.top()] = bounds;
352         fControlIndices.pop();
353     }
354 
updateSaveBounds(const Bounds & bounds)355     void updateSaveBounds(const Bounds& bounds) {
356         // If we're in a Save block, expand its bounds to cover these bounds too.
357         if (!fSaveStack.isEmpty()) {
358             fSaveStack.top().bounds.join(bounds);
359         }
360     }
361 
bounds(const Flush &) const362     Bounds bounds(const Flush&) const { return fCullRect; }
363 
bounds(const DrawPaint &) const364     Bounds bounds(const DrawPaint&) const { return fCullRect; }
bounds(const DrawBehind &) const365     Bounds bounds(const DrawBehind&) const { return fCullRect; }
bounds(const NoOp &) const366     Bounds bounds(const NoOp&)  const { return Bounds::MakeEmpty(); }    // NoOps don't draw.
367 
bounds(const DrawRect & op) const368     Bounds bounds(const DrawRect& op) const { return this->adjustAndMap(op.rect, &op.paint); }
bounds(const DrawRegion & op) const369     Bounds bounds(const DrawRegion& op) const {
370         SkRect rect = SkRect::Make(op.region.getBounds());
371         return this->adjustAndMap(rect, &op.paint);
372     }
bounds(const DrawOval & op) const373     Bounds bounds(const DrawOval& op) const { return this->adjustAndMap(op.oval, &op.paint); }
374     // Tighter arc bounds?
bounds(const DrawArc & op) const375     Bounds bounds(const DrawArc& op) const { return this->adjustAndMap(op.oval, &op.paint); }
bounds(const DrawRRect & op) const376     Bounds bounds(const DrawRRect& op) const {
377         return this->adjustAndMap(op.rrect.rect(), &op.paint);
378     }
bounds(const DrawDRRect & op) const379     Bounds bounds(const DrawDRRect& op) const {
380         return this->adjustAndMap(op.outer.rect(), &op.paint);
381     }
bounds(const DrawImage & op) const382     Bounds bounds(const DrawImage& op) const {
383         const SkImage* image = op.image.get();
384         SkRect rect = SkRect::MakeXYWH(op.left, op.top, image->width(), image->height());
385 
386         return this->adjustAndMap(rect, op.paint);
387     }
bounds(const DrawImageLattice & op) const388     Bounds bounds(const DrawImageLattice& op) const {
389         return this->adjustAndMap(op.dst, op.paint);
390     }
bounds(const DrawImageRect & op) const391     Bounds bounds(const DrawImageRect& op) const {
392         return this->adjustAndMap(op.dst, op.paint);
393     }
bounds(const DrawImageNine & op) const394     Bounds bounds(const DrawImageNine& op) const {
395         return this->adjustAndMap(op.dst, op.paint);
396     }
bounds(const DrawPath & op) const397     Bounds bounds(const DrawPath& op) const {
398         return op.path.isInverseFillType() ? fCullRect
399                                            : this->adjustAndMap(op.path.getBounds(), &op.paint);
400     }
bounds(const DrawPoints & op) const401     Bounds bounds(const DrawPoints& op) const {
402         SkRect dst;
403         dst.set(op.pts, op.count);
404 
405         // Pad the bounding box a little to make sure hairline points' bounds aren't empty.
406         SkScalar stroke = SkMaxScalar(op.paint.getStrokeWidth(), 0.01f);
407         dst.outset(stroke/2, stroke/2);
408 
409         return this->adjustAndMap(dst, &op.paint);
410     }
bounds(const DrawPatch & op) const411     Bounds bounds(const DrawPatch& op) const {
412         SkRect dst;
413         dst.set(op.cubics, SkPatchUtils::kNumCtrlPts);
414         return this->adjustAndMap(dst, &op.paint);
415     }
bounds(const DrawVertices & op) const416     Bounds bounds(const DrawVertices& op) const {
417         return this->adjustAndMap(op.vertices->bounds(), &op.paint);
418     }
419 
bounds(const DrawAtlas & op) const420     Bounds bounds(const DrawAtlas& op) const {
421         if (op.cull) {
422             // TODO: <reed> can we pass nullptr for the paint? Isn't cull already "correct"
423             // for the paint (by the caller)?
424             return this->adjustAndMap(*op.cull, op.paint);
425         } else {
426             return fCullRect;
427         }
428     }
429 
bounds(const DrawShadowRec & op) const430     Bounds bounds(const DrawShadowRec& op) const {
431         SkRect bounds;
432         SkDrawShadowMetrics::GetLocalBounds(op.path, op.rec, fCTM, &bounds);
433         return this->adjustAndMap(bounds, nullptr);
434     }
435 
bounds(const DrawPicture & op) const436     Bounds bounds(const DrawPicture& op) const {
437         SkRect dst = op.picture->cullRect();
438         op.matrix.mapRect(&dst);
439         return this->adjustAndMap(dst, op.paint);
440     }
441 
bounds(const DrawTextBlob & op) const442     Bounds bounds(const DrawTextBlob& op) const {
443         SkRect dst = op.blob->bounds();
444         dst.offset(op.x, op.y);
445         return this->adjustAndMap(dst, &op.paint);
446     }
447 
bounds(const DrawDrawable & op) const448     Bounds bounds(const DrawDrawable& op) const {
449         return this->adjustAndMap(op.worstCaseBounds, nullptr);
450     }
451 
bounds(const DrawAnnotation & op) const452     Bounds bounds(const DrawAnnotation& op) const {
453         return this->adjustAndMap(op.rect, nullptr);
454     }
bounds(const DrawEdgeAAQuad & op) const455     Bounds bounds(const DrawEdgeAAQuad& op) const {
456         SkRect bounds = op.rect;
457         if (op.clip) {
458             bounds.setBounds(op.clip, 4);
459         }
460         return this->adjustAndMap(bounds, nullptr);
461     }
bounds(const DrawEdgeAAImageSet & op) const462     Bounds bounds(const DrawEdgeAAImageSet& op) const {
463         SkRect rect = SkRect::MakeEmpty();
464         int clipIndex = 0;
465         for (int i = 0; i < op.count; ++i) {
466             SkRect entryBounds = op.set[i].fDstRect;
467             if (op.set[i].fHasClip) {
468                 entryBounds.setBounds(op.dstClips + clipIndex, 4);
469                 clipIndex += 4;
470             }
471             if (op.set[i].fMatrixIndex >= 0) {
472                 op.preViewMatrices[op.set[i].fMatrixIndex].mapRect(&entryBounds);
473             }
474             rect.join(this->adjustAndMap(entryBounds, nullptr));
475         }
476         return rect;
477     }
478 
479     // Returns true if rect was meaningfully adjusted for the effects of paint,
480     // false if the paint could affect the rect in unknown ways.
AdjustForPaint(const SkPaint * paint,SkRect * rect)481     static bool AdjustForPaint(const SkPaint* paint, SkRect* rect) {
482         if (paint) {
483             if (paint->canComputeFastBounds()) {
484                 *rect = paint->computeFastBounds(*rect, rect);
485                 return true;
486             }
487             return false;
488         }
489         return true;
490     }
491 
adjustForSaveLayerPaints(SkRect * rect,int savesToIgnore=0) const492     bool adjustForSaveLayerPaints(SkRect* rect, int savesToIgnore = 0) const {
493         for (int i = fSaveStack.count() - 1 - savesToIgnore; i >= 0; i--) {
494             SkMatrix inverse;
495             if (!fSaveStack[i].ctm.invert(&inverse)) {
496                 return false;
497             }
498             inverse.mapRect(rect);
499             if (!AdjustForPaint(fSaveStack[i].paint, rect)) {
500                 return false;
501             }
502             fSaveStack[i].ctm.mapRect(rect);
503         }
504         return true;
505     }
506 
507     const int fNumRecords;
508 
509     // We do not guarantee anything for operations outside of the cull rect
510     const SkRect fCullRect;
511 
512     // Conservative identity-space bounds for each op in the SkRecord.
513     Bounds* fBounds;
514 
515     // We walk fCurrentOp through the SkRecord,
516     // as we go using updateCTM() to maintain the exact CTM (fCTM).
517     int fCurrentOp;
518     SkMatrix fCTM;
519 
520     // Used to track the bounds of Save/Restore blocks and the control ops inside them.
521     SkTDArray<SaveBounds> fSaveStack;
522     SkTDArray<int>   fControlIndices;
523 };
524 
525 }  // namespace SkRecords
526 
SkRecordFillBounds(const SkRect & cullRect,const SkRecord & record,SkRect bounds[])527 void SkRecordFillBounds(const SkRect& cullRect, const SkRecord& record, SkRect bounds[]) {
528     SkRecords::FillBounds visitor(cullRect, record, bounds);
529     for (int curOp = 0; curOp < record.count(); curOp++) {
530         visitor.setCurrentOp(curOp);
531         record.visit(curOp, visitor);
532     }
533     visitor.cleanUp();
534 }
535 
536