add SkCanvas::clear(SkColor color) to call the new virtual clear on device.
authorreed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Thu, 14 Apr 2011 18:59:28 +0000 (18:59 +0000)
committerreed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Thu, 14 Apr 2011 18:59:28 +0000 (18:59 +0000)
git-svn-id: http://skia.googlecode.com/svn/trunk@1131 2bbb7eff-a529-9590-31e7-b0007b416f81

include/core/SkCanvas.h
src/core/SkCanvas.cpp
src/core/SkPictureFlat.h
src/core/SkPicturePlayback.cpp
src/core/SkPictureRecord.cpp
src/core/SkPictureRecord.h

index 39fd998..6b2ee10 100644 (file)
@@ -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 {
index 16cfc4b..07c2748 100644 (file)
@@ -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)
 
index 2c0af5a..54a02fb 100644 (file)
@@ -18,6 +18,7 @@ enum DrawType {
     DRAW_BITMAP,
     DRAW_BITMAP_MATRIX,
     DRAW_BITMAP_RECT,
+    DRAW_CLEAR,
     DRAW_DATA,
     DRAW_PAINT,
     DRAW_PATH,
index 0232cc0..ed220ea 100644 (file)
@@ -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);
index 00e4b60..a48d0e4 100644 (file)
@@ -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);
index f9c967d..14d1ffd 100644 (file)
@@ -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&);