add SkCanvas::clear(SkColor color) to call the new virtual clear on device.
git-svn-id: http://skia.googlecode.com/svn/trunk@1131 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h
index 39fd998..6b2ee10 100644
--- a/include/core/SkCanvas.h
+++ b/include/core/SkCanvas.h
@@ -391,10 +391,27 @@
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 16cfc4b..07c2748 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -1194,6 +1194,14 @@
// 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 2c0af5a..54a02fb 100644
--- a/src/core/SkPictureFlat.h
+++ b/src/core/SkPictureFlat.h
@@ -18,6 +18,7 @@
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 0232cc0..ed220ea 100644
--- a/src/core/SkPicturePlayback.cpp
+++ b/src/core/SkPicturePlayback.cpp
@@ -589,6 +589,9 @@
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 00e4b60..a48d0e4 100644
--- a/src/core/SkPictureRecord.cpp
+++ b/src/core/SkPictureRecord.cpp
@@ -166,6 +166,12 @@
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 f9c967d..14d1ffd 100644
--- a/src/core/SkPictureRecord.h
+++ b/src/core/SkPictureRecord.h
@@ -27,6 +27,7 @@
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&);