add drawData() to canvas, to record data blobs
authorreed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Fri, 4 Dec 2009 21:32:27 +0000 (21:32 +0000)
committerreed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Fri, 4 Dec 2009 21:32:27 +0000 (21:32 +0000)
git-svn-id: http://skia.googlecode.com/svn/trunk@452 2bbb7eff-a529-9590-31e7-b0007b416f81

include/core/SkCanvas.h
include/utils/SkDumpCanvas.h
include/utils/SkProxyCanvas.h
samplecode/SamplePicture.cpp
src/core/SkCanvas.cpp
src/core/SkPictureFlat.h
src/core/SkPicturePlayback.cpp
src/core/SkPictureRecord.cpp
src/core/SkPictureRecord.h
src/utils/SkDumpCanvas.cpp
src/utils/SkProxyCanvas.cpp

index 8fba6cf49dfed9a7503b2508d8d1990c3c44422e..40b5c56171b43e1912a3383ed00c48efd86f0025 100644 (file)
@@ -626,6 +626,14 @@ public:
                               const uint16_t indices[], int indexCount,
                               const SkPaint& paint);
 
+    /** Send a blob of data to the canvas.
+        For canvases that draw, this call is effectively a no-op, as the data
+        is not parsed, but just ignored. However, this call exists for
+        subclasses like SkPicture's recording canvas, that can store the data
+        and then play it back later (via another call to drawData).
+     */
+    virtual void drawData(const void* data, size_t length);
+
     //////////////////////////////////////////////////////////////////////////
     
     /** Get the current bounder object.
index 6f16c92faf7401f8f67ff8f7e82d88c741630fb5..3731bef822a0b20984bb5b8236792696d3fd3461 100644 (file)
@@ -34,7 +34,8 @@ public:
         kDrawText_Verb,
         kDrawPicture_Verb,
         kDrawShape_Verb,
-        kDrawVertices_Verb
+        kDrawVertices_Verb,
+        kDrawData_Verb
     };
     
     /** Subclasses of this are installed on the DumpCanvas, and then called for
@@ -102,6 +103,7 @@ public:
                               const SkColor colors[], SkXfermode* xmode,
                               const uint16_t indices[], int indexCount,
                               const SkPaint& paint);
+    virtual void drawData(const void*, size_t);
 
 private:
     Dumper* fDumper;
index f2e57abf848dcbcb8eac6f72bbc7bbcb371b2ad0..082e0fdee880a9e6cccf74a428de9433893cfda1 100644 (file)
@@ -75,7 +75,8 @@ public:
                               const SkColor colors[], SkXfermode* xmode,
                               const uint16_t indices[], int indexCount,
                               const SkPaint& paint);
-    
+    virtual void drawData(const void* data, size_t length);
+
     virtual SkBounder* setBounder(SkBounder* bounder);
     virtual SkDrawFilter* setDrawFilter(SkDrawFilter* filter);
 
index e1b05ad66b23cd6aa588ac0d7a2247d2db6419eb..e232a5040999c4afe412bb759faa28eb3444e64f 100644 (file)
@@ -1,11 +1,11 @@
 #include "SampleCode.h"
+#include "SkDumpCanvas.h"
 #include "SkView.h"
 #include "SkCanvas.h"
 #include "Sk64.h"
 #include "SkGradientShader.h"
 #include "SkGraphics.h"
 #include "SkImageDecoder.h"
-#include "SkKernel33MaskFilter.h"
 #include "SkPath.h"
 #include "SkPicture.h"
 #include "SkRandom.h"
@@ -103,15 +103,21 @@ protected:
         canvas->drawBitmap(fBitmap, 0, 0, NULL);
         canvas->restore();
 
+        const char beforeStr[] = "before circle";
+        const char afterStr[] = "after circle";
+
         paint.setAntiAlias(true);
     
         paint.setColor(SK_ColorRED);
+        canvas->drawData(beforeStr, sizeof(beforeStr));
         canvas->drawCircle(SkIntToScalar(50), SkIntToScalar(50),
                            SkIntToScalar(40), paint);
+        canvas->drawData(afterStr, sizeof(afterStr));
         paint.setColor(SK_ColorBLACK);
         paint.setTextSize(SkIntToScalar(40));
         canvas->drawText("Picture", 7, SkIntToScalar(50), SkIntToScalar(62),
                          paint);
+        
     }
 
     virtual void onDraw(SkCanvas* canvas) {
@@ -145,6 +151,12 @@ protected:
         canvas->translate(-SkIntToScalar(100), 0);
         canvas->drawPicture(*pict);
         canvas->restore();
+
+        if (false) {
+            SkDebugfDumper dumper;
+            SkDumpCanvas dumpCanvas(&dumper);
+            dumpCanvas.drawPicture(*pict);
+        }
         
         // test that we can re-record a subpicture, and see the results
         
index 0bf0614264f83327a235d38fdd1b5f96c4602db0..a5529af6330fb371f061231310cd075be7f1767c 100644 (file)
@@ -1239,6 +1239,10 @@ void SkCanvas::drawVertices(VertexMode vmode, int vertexCount,
     ITER_END
 }
 
+void SkCanvas::drawData(const void* data, size_t length) {
+    // do nothing. Subclasses may do something with the data
+}
+
 //////////////////////////////////////////////////////////////////////////////
 // These methods are NOT virtual, and therefore must call back into virtual
 // methods, rather than actually drawing themselves.
index 86a161d144d57ddd288eddf565ffe7a432d5eed3..2c0af5a2ecd787ad23e356c665281bd8d1607736 100644 (file)
@@ -18,6 +18,7 @@ enum DrawType {
     DRAW_BITMAP,
     DRAW_BITMAP_MATRIX,
     DRAW_BITMAP_RECT,
+    DRAW_DATA,
     DRAW_PAINT,
     DRAW_PATH,
     DRAW_PICTURE,
index 03cdc1681cefde0a88e43417290f9a869a69f9d0..f488565b41c9372eb385b11345fc600552bc7d6d 100644 (file)
@@ -589,6 +589,11 @@ void SkPicturePlayback::draw(SkCanvas& canvas) {
                 const SkMatrix* matrix = getMatrix();
                 canvas.drawBitmapMatrix(bitmap, *matrix, paint);
             } break;
+            case DRAW_DATA: {
+                size_t length = getInt();
+                canvas.drawData(fReader.skip(length), length);
+                // skip handles padding the read out to a multiple of 4
+            } break;
             case DRAW_PAINT:
                 canvas.drawPaint(*getPaint());
                 break;
index b565fc11a8f8e5f6f9b84c481d44efa4b6f9f2d5..9844a480cd95b7e67c28fd985c3a505183b6143f 100644 (file)
@@ -410,6 +410,12 @@ void SkPictureRecord::drawVertices(VertexMode vmode, int vertexCount,
     }
 }
 
+void SkPictureRecord::drawData(const void* data, size_t length) {
+    addDraw(DRAW_DATA);
+    addInt(length);
+    fWriter.writePad(data, length);
+}
+
 ///////////////////////////////////////////////////////////////////////////////
     
 void SkPictureRecord::reset() {
index 05761afd0b8199eeade510a2b6ef49f2a197e658..f9c967d32f26fe5a52856aa4e73da2de46fc510b 100644 (file)
@@ -56,6 +56,7 @@ public:
                           const SkColor colors[], SkXfermode*,
                           const uint16_t indices[], int indexCount,
                               const SkPaint&);
+    virtual void drawData(const void*, size_t);
 
     void addFontMetricsTopBottom(const SkPaint& paint, SkScalar baselineY);
     
index 215113300c42ebcd394aa18b1113ee32c5844f2a..4ff7a50fc8dc73545a7957ed37fc3939e2e0ecd0 100644 (file)
@@ -379,6 +379,12 @@ void SkDumpCanvas::drawVertices(VertexMode vmode, int vertexCount,
                SkScalarToFloat(vertices[0].fY));
 }
 
+void SkDumpCanvas::drawData(const void* data, size_t length) {
+//    this->dump(kDrawData_Verb, NULL, "drawData(%d)", length);
+    this->dump(kDrawData_Verb, NULL, "drawData(%d) %.*s", length,
+               SkMin32(length, 64), data);
+}
+
 ///////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////////
 
index cb0d44a88a0b5ae3360ec467b006fc3a43c2a0f2..c643c8277ef9f01c6b4fa5d1adddaeaa8303d75a 100644 (file)
@@ -151,6 +151,10 @@ void SkProxyCanvas::drawVertices(VertexMode vmode, int vertexCount,
                                      xmode, indices, indexCount, paint);
 }
 
+void SkProxyCanvas::drawData(const void* data, size_t length) {
+    fProxy->drawData(data, length);
+}
+
 SkBounder* SkProxyCanvas::setBounder(SkBounder* bounder) {
     return fProxy->setBounder(bounder);
 }