diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h index 39fd998c3c..6b2ee10e75 100644 --- a/include/core/SkCanvas.h +++ b/include/core/SkCanvas.h @@ -391,10 +391,27 @@ public: void drawColor(SkColor color, SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode); - /** Fill the entire canvas' bitmap (restricted to the current clip) with the - specified paint. - @param paint The paint used to fill the canvas - */ + /** + * This erases the entire drawing surface to the specified color, + * irrespective of the clip. It does not blend with the previous pixels, + * but always overwrites them. + * + * It is roughly equivalent to the following: + * canvas.save(); + * canvas.clipRect(hugeRect, kReplace_Op); + * paint.setColor(color); + * paint.setXfermodeMode(kSrc_Mode); + * canvas.drawPaint(paint); + * canvas.restore(); + * though it is almost always much more efficient. + */ + virtual void clear(SkColor); + + /** + * Fill the entire canvas' bitmap (restricted to the current clip) with the + * specified paint. + * @param paint The paint used to fill the canvas + */ virtual void drawPaint(const SkPaint& paint); enum PointMode { diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp index 16cfc4bcb6..07c2748a7a 100644 --- a/src/core/SkCanvas.cpp +++ b/src/core/SkCanvas.cpp @@ -1194,6 +1194,14 @@ SkDevice* SkCanvas::createDevice(SkBitmap::Config config, int width, int height, // These are the virtual drawing methods ////////////////////////////////////////////////////////////////////////////// +void SkCanvas::clear(SkColor color) { + SkDrawIter iter(this); + + while (iter.next()) { + iter.fDevice->clear(color); + } +} + void SkCanvas::drawPaint(const SkPaint& paint) { LOOPER_BEGIN(paint, SkDrawFilter::kPaint_Type) diff --git a/src/core/SkPictureFlat.h b/src/core/SkPictureFlat.h index 2c0af5a2ec..54a02fbb27 100644 --- a/src/core/SkPictureFlat.h +++ b/src/core/SkPictureFlat.h @@ -18,6 +18,7 @@ enum DrawType { DRAW_BITMAP, DRAW_BITMAP_MATRIX, DRAW_BITMAP_RECT, + DRAW_CLEAR, DRAW_DATA, DRAW_PAINT, DRAW_PATH, diff --git a/src/core/SkPicturePlayback.cpp b/src/core/SkPicturePlayback.cpp index 0232cc0a88..ed220ea0ca 100644 --- a/src/core/SkPicturePlayback.cpp +++ b/src/core/SkPicturePlayback.cpp @@ -589,6 +589,9 @@ void SkPicturePlayback::draw(SkCanvas& canvas) { const SkMatrix* matrix = getMatrix(); canvas.drawBitmapMatrix(bitmap, *matrix, paint); } break; + case DRAW_CLEAR: + canvas.clear(getInt()); + break; case DRAW_DATA: { size_t length = getInt(); canvas.drawData(fReader.skip(length), length); diff --git a/src/core/SkPictureRecord.cpp b/src/core/SkPictureRecord.cpp index 00e4b600ef..a48d0e4deb 100644 --- a/src/core/SkPictureRecord.cpp +++ b/src/core/SkPictureRecord.cpp @@ -166,6 +166,12 @@ bool SkPictureRecord::clipRegion(const SkRegion& region, SkRegion::Op op) { return this->INHERITED::clipRegion(region, op); } +void SkPictureRecord::clear(SkColor color) { + addDraw(DRAW_CLEAR); + addInt(color); + validate(); +} + void SkPictureRecord::drawPaint(const SkPaint& paint) { addDraw(DRAW_PAINT); addPaint(paint); diff --git a/src/core/SkPictureRecord.h b/src/core/SkPictureRecord.h index f9c967d32f..14d1ffd196 100644 --- a/src/core/SkPictureRecord.h +++ b/src/core/SkPictureRecord.h @@ -27,6 +27,7 @@ public: virtual bool clipRect(const SkRect& rect, SkRegion::Op op); virtual bool clipPath(const SkPath& path, SkRegion::Op op); virtual bool clipRegion(const SkRegion& region, SkRegion::Op op); + virtual void clear(SkColor); virtual void drawPaint(const SkPaint& paint); virtual void drawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&);