, fReplacements(replacements)
, fInitialMatrix(initialMatrix)
, fCallback(callback)
- , fIndex(0) {
+ , fIndex(0)
+ , fNumReplaced(0) {
}
- void draw() {
+ int draw() {
const SkBBoxHierarchy* bbh = fPicture->fBBH.get();
const SkRecord* record = fPicture->fRecord.get();
if (NULL == record) {
- return;
+ return 0;
}
+ fNumReplaced = 0;
+
fOps.rewind();
if (bbh) {
for (fIndex = 0; fIndex < fOps.count(); ++fIndex) {
if (fCallback && fCallback->abortDrawing()) {
- return;
+ return fNumReplaced;
}
record->visit<void>(fOps[fIndex], *this);
} else {
for (fIndex = 0; fIndex < (int) record->count(); ++fIndex) {
if (fCallback && fCallback->abortDrawing()) {
- return;
+ return fNumReplaced;
}
record->visit<void>(fIndex, *this);
}
}
+
+ return fNumReplaced;
}
// Same as Draw for all ops except DrawPicture and SaveLayer.
// Draw sub-pictures with the same replacement list but a different picture
ReplaceDraw draw(fCanvas, dp.picture, fReplacements, fInitialMatrix, fCallback);
- draw.draw();
+ fNumReplaced += draw.draw();
}
void operator()(const SkRecords::SaveLayer& sl) {
startOffset = fIndex;
}
+ const SkMatrix& ctm = fCanvas->getTotalMatrix();
const GrReplacements::ReplacementInfo* ri = fReplacements->lookupByStart(
fPicture->uniqueID(),
startOffset,
- fCanvas->getTotalMatrix());
+ ctm);
if (ri) {
+ fNumReplaced++;
draw_replacement_bitmap(ri, fCanvas, fInitialMatrix);
if (fPicture->fBBH.get()) {
SkTDArray<unsigned> fOps;
int fIndex;
+ int fNumReplaced;
typedef Draw INHERITED;
};
-void GrRecordReplaceDraw(const SkPicture* picture,
- SkCanvas* canvas,
- const GrReplacements* replacements,
- const SkMatrix& initialMatrix,
- SkDrawPictureCallback* callback) {
+int GrRecordReplaceDraw(const SkPicture* picture,
+ SkCanvas* canvas,
+ const GrReplacements* replacements,
+ const SkMatrix& initialMatrix,
+ SkDrawPictureCallback* callback) {
SkAutoCanvasRestore saveRestore(canvas, true /*save now, restore at exit*/);
ReplaceDraw draw(canvas, picture, replacements, initialMatrix, callback);
- draw.draw();
+ return draw.draw();
}
// Draw an SkPicture into an SkCanvas replacing saveLayer/restore blocks with
// drawBitmap calls. A convenience wrapper around SkRecords::Draw.
-void GrRecordReplaceDraw(const SkPicture*,
- SkCanvas*,
- const GrReplacements*,
- const SkMatrix& initialMatrix,
- SkDrawPictureCallback*);
+// It returns the number of saveLayer/restore blocks replaced with drawBitmap calls.
+int GrRecordReplaceDraw(const SkPicture*,
+ SkCanvas*,
+ const GrReplacements*,
+ const SkMatrix& initialMatrix,
+ SkDrawPictureCallback*);
#endif // GrRecordReplaceDraw_DEFINED