Add return value on GrRecordReplaceDraw

This assists debugging layer hoisting errors (e.g., when a layer is hoisted but not actually used in subsequent rendering).

Review URL: https://codereview.chromium.org/694533004
This commit is contained in:
robertphillips 2014-10-30 11:54:31 -07:00 committed by Commit bot
parent 189fc98e08
commit 0882fdcc15
2 changed files with 27 additions and 18 deletions

View File

@ -66,16 +66,19 @@ public:
, fReplacements(replacements) , fReplacements(replacements)
, fInitialMatrix(initialMatrix) , fInitialMatrix(initialMatrix)
, fCallback(callback) , fCallback(callback)
, fIndex(0) { , fIndex(0)
, fNumReplaced(0) {
} }
void draw() { int draw() {
const SkBBoxHierarchy* bbh = fPicture->fBBH.get(); const SkBBoxHierarchy* bbh = fPicture->fBBH.get();
const SkRecord* record = fPicture->fRecord.get(); const SkRecord* record = fPicture->fRecord.get();
if (NULL == record) { if (NULL == record) {
return; return 0;
} }
fNumReplaced = 0;
fOps.rewind(); fOps.rewind();
if (bbh) { if (bbh) {
@ -91,7 +94,7 @@ public:
for (fIndex = 0; fIndex < fOps.count(); ++fIndex) { for (fIndex = 0; fIndex < fOps.count(); ++fIndex) {
if (fCallback && fCallback->abortDrawing()) { if (fCallback && fCallback->abortDrawing()) {
return; return fNumReplaced;
} }
record->visit<void>(fOps[fIndex], *this); record->visit<void>(fOps[fIndex], *this);
@ -100,12 +103,14 @@ public:
} else { } else {
for (fIndex = 0; fIndex < (int) record->count(); ++fIndex) { for (fIndex = 0; fIndex < (int) record->count(); ++fIndex) {
if (fCallback && fCallback->abortDrawing()) { if (fCallback && fCallback->abortDrawing()) {
return; return fNumReplaced;
} }
record->visit<void>(fIndex, *this); record->visit<void>(fIndex, *this);
} }
} }
return fNumReplaced;
} }
// Same as Draw for all ops except DrawPicture and SaveLayer. // Same as Draw for all ops except DrawPicture and SaveLayer.
@ -118,7 +123,7 @@ public:
// Draw sub-pictures with the same replacement list but a different picture // Draw sub-pictures with the same replacement list but a different picture
ReplaceDraw draw(fCanvas, dp.picture, fReplacements, fInitialMatrix, fCallback); ReplaceDraw draw(fCanvas, dp.picture, fReplacements, fInitialMatrix, fCallback);
draw.draw(); fNumReplaced += draw.draw();
} }
void operator()(const SkRecords::SaveLayer& sl) { void operator()(const SkRecords::SaveLayer& sl) {
@ -131,12 +136,14 @@ public:
startOffset = fIndex; startOffset = fIndex;
} }
const SkMatrix& ctm = fCanvas->getTotalMatrix();
const GrReplacements::ReplacementInfo* ri = fReplacements->lookupByStart( const GrReplacements::ReplacementInfo* ri = fReplacements->lookupByStart(
fPicture->uniqueID(), fPicture->uniqueID(),
startOffset, startOffset,
fCanvas->getTotalMatrix()); ctm);
if (ri) { if (ri) {
fNumReplaced++;
draw_replacement_bitmap(ri, fCanvas, fInitialMatrix); draw_replacement_bitmap(ri, fCanvas, fInitialMatrix);
if (fPicture->fBBH.get()) { if (fPicture->fBBH.get()) {
@ -163,18 +170,19 @@ private:
SkTDArray<unsigned> fOps; SkTDArray<unsigned> fOps;
int fIndex; int fIndex;
int fNumReplaced;
typedef Draw INHERITED; typedef Draw INHERITED;
}; };
void GrRecordReplaceDraw(const SkPicture* picture, int GrRecordReplaceDraw(const SkPicture* picture,
SkCanvas* canvas, SkCanvas* canvas,
const GrReplacements* replacements, const GrReplacements* replacements,
const SkMatrix& initialMatrix, const SkMatrix& initialMatrix,
SkDrawPictureCallback* callback) { SkDrawPictureCallback* callback) {
SkAutoCanvasRestore saveRestore(canvas, true /*save now, restore at exit*/); SkAutoCanvasRestore saveRestore(canvas, true /*save now, restore at exit*/);
ReplaceDraw draw(canvas, picture, replacements, initialMatrix, callback); ReplaceDraw draw(canvas, picture, replacements, initialMatrix, callback);
draw.draw(); return draw.draw();
} }

View File

@ -101,10 +101,11 @@ private:
// Draw an SkPicture into an SkCanvas replacing saveLayer/restore blocks with // Draw an SkPicture into an SkCanvas replacing saveLayer/restore blocks with
// drawBitmap calls. A convenience wrapper around SkRecords::Draw. // drawBitmap calls. A convenience wrapper around SkRecords::Draw.
void GrRecordReplaceDraw(const SkPicture*, // It returns the number of saveLayer/restore blocks replaced with drawBitmap calls.
SkCanvas*, int GrRecordReplaceDraw(const SkPicture*,
const GrReplacements*, SkCanvas*,
const SkMatrix& initialMatrix, const GrReplacements*,
SkDrawPictureCallback*); const SkMatrix& initialMatrix,
SkDrawPictureCallback*);
#endif // GrRecordReplaceDraw_DEFINED #endif // GrRecordReplaceDraw_DEFINED