First pass at Comment API

https://codereview.chromium.org/13957009/



git-svn-id: http://skia.googlecode.com/svn/trunk@9310 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index df2a0f9..e26007f 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -2010,10 +2010,6 @@
     LOOPER_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.
diff --git a/src/core/SkPictureFlat.h b/src/core/SkPictureFlat.h
index b513271..0a147de 100644
--- a/src/core/SkPictureFlat.h
+++ b/src/core/SkPictureFlat.h
@@ -62,8 +62,11 @@
     SKEW,
     TRANSLATE,
     NOOP,
+    BEGIN_COMMENT_GROUP,
+    COMMENT,
+    END_COMMENT_GROUP,
 
-    LAST_DRAWTYPE_ENUM = NOOP
+    LAST_DRAWTYPE_ENUM = END_COMMENT_GROUP
 };
 
 // In the 'match' method, this constant will match any flavor of DRAW_BITMAP*
diff --git a/src/core/SkPicturePlayback.cpp b/src/core/SkPicturePlayback.cpp
index e4f041f..898d379 100644
--- a/src/core/SkPicturePlayback.cpp
+++ b/src/core/SkPicturePlayback.cpp
@@ -858,6 +858,18 @@
                 canvas.drawData(reader.skip(length), length);
                 // skip handles padding the read out to a multiple of 4
             } break;
+            case BEGIN_COMMENT_GROUP: {
+                const char* desc = reader.readString();
+                canvas.beginCommentGroup(desc);
+            } break;
+            case COMMENT: {
+                const char* kywd = reader.readString();
+                const char* value = reader.readString();
+                canvas.addComment(kywd, value);
+            } break;
+            case END_COMMENT_GROUP: {
+                canvas.endCommentGroup();
+            } break;
             case DRAW_OVAL: {
                 const SkPaint& paint = *getPaint(reader);
                 canvas.drawOval(reader.skipT<SkRect>(), paint);
diff --git a/src/core/SkPictureRecord.cpp b/src/core/SkPictureRecord.cpp
index f405c3a..fc85028 100644
--- a/src/core/SkPictureRecord.cpp
+++ b/src/core/SkPictureRecord.cpp
@@ -106,6 +106,9 @@
         0,  // SKEW - no paint
         0,  // TRANSLATE - no paint
         0,  // NOOP - no paint
+        0,  // BEGIN_GROUP - no paint
+        0,  // COMMENT - no paint
+        0,  // END_GROUP - no paint
     };
 
     SkASSERT(sizeof(gPaintOffsets) == LAST_DRAWTYPE_ENUM + 1);
@@ -1276,6 +1279,33 @@
     validate(initialOffset, size);
 }
 
+void SkPictureRecord::beginCommentGroup(const char* description) {
+    // op/size + length of string + \0 terminated chars
+    int length = strlen(description);
+    uint32_t size = 2 * kUInt32Size + SkAlign4(length + 1);
+    uint32_t initialOffset = this->addDraw(BEGIN_COMMENT_GROUP, &size);
+    fWriter.writeString(description, length);
+    validate(initialOffset, size);
+}
+
+void SkPictureRecord::addComment(const char* kywd, const char* value) {
+    // op/size + 2x length of string + 2x \0 terminated chars
+    int kywdLen = strlen(kywd);
+    int valueLen = strlen(value);
+    uint32_t size = 3 * kUInt32Size + SkAlign4(kywdLen + 1) + SkAlign4(valueLen + 1);
+    uint32_t initialOffset = this->addDraw(COMMENT, &size);
+    fWriter.writeString(kywd, kywdLen);
+    fWriter.writeString(value, valueLen);
+    validate(initialOffset, size);
+}
+
+void SkPictureRecord::endCommentGroup() {
+    // op/size
+    uint32_t size = 1 * kUInt32Size;
+    uint32_t initialOffset = this->addDraw(END_COMMENT_GROUP, &size);
+    validate(initialOffset, size);
+}
+
 ///////////////////////////////////////////////////////////////////////////////
 
 void SkPictureRecord::addBitmap(const SkBitmap& bitmap) {
diff --git a/src/core/SkPictureRecord.h b/src/core/SkPictureRecord.h
index 6245b78..95ce5d2 100644
--- a/src/core/SkPictureRecord.h
+++ b/src/core/SkPictureRecord.h
@@ -82,6 +82,9 @@
                           const uint16_t indices[], int indexCount,
                               const SkPaint&) SK_OVERRIDE;
     virtual void drawData(const void*, size_t) SK_OVERRIDE;
+    virtual void beginCommentGroup(const char* description) SK_OVERRIDE;
+    virtual void addComment(const char* kywd, const char* value) SK_OVERRIDE;
+    virtual void endCommentGroup() SK_OVERRIDE;
     virtual bool isDrawingToLayer() const SK_OVERRIDE;
 
     void addFontMetricsTopBottom(const SkPaint& paint, const SkFlatData&,
diff --git a/src/pipe/SkGPipeWrite.cpp b/src/pipe/SkGPipeWrite.cpp
index 32786fd..3b22a5e 100644
--- a/src/pipe/SkGPipeWrite.cpp
+++ b/src/pipe/SkGPipeWrite.cpp
@@ -255,6 +255,9 @@
                           const uint16_t indices[], int indexCount,
                               const SkPaint&) SK_OVERRIDE;
     virtual void drawData(const void*, size_t) SK_OVERRIDE;
+    virtual void beginCommentGroup(const char* description) SK_OVERRIDE;
+    virtual void addComment(const char* kywd, const char* value) SK_OVERRIDE;
+    virtual void endCommentGroup() SK_OVERRIDE;
 
     /**
      * Flatten an SkBitmap to send to the reader, where it will be referenced
@@ -970,6 +973,18 @@
     }
 }
 
+void SkGPipeCanvas::beginCommentGroup(const char* description) {
+    // ignore for now
+}
+
+void SkGPipeCanvas::addComment(const char* kywd, const char* value) {
+    // ignore for now
+}
+
+void SkGPipeCanvas::endCommentGroup() {
+    // ignore for now
+}
+
 void SkGPipeCanvas::flushRecording(bool detachCurrentBlock) {
     doNotify();
     if (detachCurrentBlock) {
diff --git a/src/utils/SkDumpCanvas.cpp b/src/utils/SkDumpCanvas.cpp
index 46c4141..87ddd31 100644
--- a/src/utils/SkDumpCanvas.cpp
+++ b/src/utils/SkDumpCanvas.cpp
@@ -442,6 +442,18 @@
                SkMin32(length, 64), data);
 }
 
+void SkDumpCanvas::beginCommentGroup(const char* description) {
+    this->dump(kBeginCommentGroup_Verb, NULL, "beginCommentGroup(%s)", description);
+}
+
+void SkDumpCanvas::addComment(const char* kywd, const char* value) {
+    this->dump(kAddComment_Verb, NULL, "addComment(%s, %s)", kywd, value);
+}
+
+void SkDumpCanvas::endCommentGroup() {
+    this->dump(kEndCommentGroup_Verb, NULL, "endCommentGroup()");
+}
+
 ///////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////////
 
diff --git a/src/utils/SkProxyCanvas.cpp b/src/utils/SkProxyCanvas.cpp
index 057f1df..053a757 100644
--- a/src/utils/SkProxyCanvas.cpp
+++ b/src/utils/SkProxyCanvas.cpp
@@ -158,6 +158,18 @@
     fProxy->drawData(data, length);
 }
 
+void SkProxyCanvas::beginCommentGroup(const char* description) {
+    fProxy->beginCommentGroup(description);
+}
+
+void SkProxyCanvas::addComment(const char* kywd, const char* value) {
+    fProxy->addComment(kywd, value);
+}
+
+void SkProxyCanvas::endCommentGroup() {
+    fProxy->endCommentGroup();
+}
+
 SkBounder* SkProxyCanvas::setBounder(SkBounder* bounder) {
     return fProxy->setBounder(bounder);
 }