add annotations to debugger
authorreed <reed@google.com>
Wed, 29 Jun 2016 01:54:19 +0000 (18:54 -0700)
committerCommit bot <commit-bot@chromium.org>
Wed, 29 Jun 2016 01:54:19 +0000 (18:54 -0700)
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2105113002

Review-Url: https://codereview.chromium.org/2105113002

tools/debugger/SkDebugCanvas.cpp
tools/debugger/SkDebugCanvas.h
tools/debugger/SkDrawCommand.cpp
tools/debugger/SkDrawCommand.h

index 5ee22eba3fe9e83f00d038371af018067b8960be..ceea78219314015752baaf578168ac1a319fed41 100644 (file)
@@ -552,6 +552,10 @@ void SkDebugCanvas::didConcat(const SkMatrix& matrix) {
     this->INHERITED::didConcat(matrix);
 }
 
+void SkDebugCanvas::onDrawAnnotation(const SkRect& rect, const char key[], SkData* value) {
+    this->addDrawCommand(new SkDrawAnnotationCommand(rect, key, sk_ref_sp(value)));
+}
+
 void SkDebugCanvas::onDrawBitmap(const SkBitmap& bitmap, SkScalar left,
                                  SkScalar top, const SkPaint* paint) {
     this->addDrawCommand(new SkDrawBitmapCommand(bitmap, left, top, paint));
index 47aaf755721bae8054713584fa064d1f83a477b5..d0cdf82a369833ea90e912c30cbefd996dbe69fb 100644 (file)
@@ -194,6 +194,7 @@ protected:
     void didConcat(const SkMatrix&) override;
     void didSetMatrix(const SkMatrix&) override;
 
+    void onDrawAnnotation(const SkRect&, const char[], SkData*) override;
     void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override;
     void onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
                     const SkPaint&) override;
index b95a9b89d1753c785db85a0296535669e1501301..1ef5e0b86c03047a230128c16afe172189289de0 100644 (file)
@@ -177,6 +177,7 @@ const char* SkDrawCommand::GetCommandString(OpType type) {
         case kClipRect_OpType: return "ClipRect";
         case kClipRRect_OpType: return "ClipRRect";
         case kConcat_OpType: return "Concat";
+        case kDrawAnnotation_OpType: return "drawAnnotation";
         case kDrawBitmap_OpType: return "DrawBitmap";
         case kDrawBitmapNine_OpType: return "DrawBitmapNine";
         case kDrawBitmapRect_OpType: return "DrawBitmapRect";
@@ -235,6 +236,7 @@ SkDrawCommand* SkDrawCommand::fromJSON(Json::Value& command, UrlDataManager& url
         INSTALL_FACTORY(ClipRect);
         INSTALL_FACTORY(ClipRRect);
         INSTALL_FACTORY(Concat);
+        INSTALL_FACTORY(DrawAnnotation);
         INSTALL_FACTORY(DrawBitmap);
         INSTALL_FACTORY(DrawBitmapRect);
         INSTALL_FACTORY(DrawBitmapNine);
@@ -1712,6 +1714,41 @@ SkConcatCommand* SkConcatCommand::fromJSON(Json::Value& command, UrlDataManager&
     return new SkConcatCommand(matrix);
 }
 
+////
+
+SkDrawAnnotationCommand::SkDrawAnnotationCommand(const SkRect& rect, const char key[],
+                                                 sk_sp<SkData> value)
+    : INHERITED(kDrawAnnotation_OpType)
+    , fRect(rect)
+    , fKey(key)
+    , fValue(std::move(value))
+{}
+
+void SkDrawAnnotationCommand::execute(SkCanvas* canvas) const {
+    canvas->drawAnnotation(fRect, fKey.c_str(), fValue);
+}
+
+Json::Value SkDrawAnnotationCommand::toJSON(UrlDataManager& urlDataManager) const {
+    Json::Value result = INHERITED::toJSON(urlDataManager);
+
+    result[SKDEBUGCANVAS_ATTRIBUTE_COORDS] = MakeJsonRect(fRect);
+    result["key"] = Json::Value(fKey.c_str());
+    if (fValue.get()) {
+        // TODO: dump out the "value"
+    }
+    return result;
+}
+
+SkDrawAnnotationCommand* SkDrawAnnotationCommand::fromJSON(Json::Value& command,
+                                                           UrlDataManager& urlDataManager) {
+    SkRect rect;
+    extract_json_rect(command[SKDEBUGCANVAS_ATTRIBUTE_COORDS], &rect);
+    sk_sp<SkData> data(nullptr); // TODO: extract "value" from the Json
+    return new SkDrawAnnotationCommand(rect, command["key"].asCString(), data);
+}
+
+////
+
 SkDrawBitmapCommand::SkDrawBitmapCommand(const SkBitmap& bitmap, SkScalar left, SkScalar top,
                                          const SkPaint* paint)
     : INHERITED(kDrawBitmap_OpType) {
index 9b81adad3fa6be4eda1e0d7b8130364fcaa9bc76..0d1ece0055043c2ab3344b7ac5d4996275d74250 100644 (file)
@@ -28,6 +28,7 @@ public:
         kClipRect_OpType,
         kClipRRect_OpType,
         kConcat_OpType,
+        kDrawAnnotation_OpType,
         kDrawBitmap_OpType,
         kDrawBitmapNine_OpType,
         kDrawBitmapRect_OpType,
@@ -247,6 +248,21 @@ private:
     typedef SkDrawCommand INHERITED;
 };
 
+class SkDrawAnnotationCommand : public SkDrawCommand {
+public:
+    SkDrawAnnotationCommand(const SkRect&, const char key[], sk_sp<SkData> value);
+    void execute(SkCanvas* canvas) const override;
+    Json::Value toJSON(UrlDataManager& urlDataManager) const override;
+    static SkDrawAnnotationCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
+
+private:
+    SkRect          fRect;
+    SkString        fKey;
+    sk_sp<SkData>   fValue;
+
+    typedef SkDrawCommand INHERITED;
+};
+
 class SkDrawBitmapCommand : public SkDrawCommand {
 public:
     SkDrawBitmapCommand(const SkBitmap& bitmap, SkScalar left, SkScalar top,