Add missing onDrawDrawable() overrides to utility canvases

Change-Id: Ia5a7c523263e2c4744e0f3a743c6a4433760a4be
Reviewed-on: https://skia-review.googlesource.com/49770
Reviewed-by: Stan Iliev <stani@google.com>
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Florin Malita <fmalita@chromium.org>
diff --git a/include/utils/SkDumpCanvas.h b/include/utils/SkDumpCanvas.h
index e7f941c..2988aaa 100644
--- a/include/utils/SkDumpCanvas.h
+++ b/include/utils/SkDumpCanvas.h
@@ -45,6 +45,7 @@
         kDrawBitmap_Verb,
         kDrawText_Verb,
         kDrawPicture_Verb,
+        kDrawDrawable_Verb,
         kDrawVertices_Verb,
         kDrawPatch_Verb,
         kDrawData_Verb, // obsolete
@@ -120,6 +121,7 @@
     void onClipRegion(const SkRegion&, SkClipOp) override;
 
     void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override;
+    void onDrawDrawable(SkDrawable*, const SkMatrix*) override;
     void onDrawAnnotation(const SkRect&, const char key[], SkData* value) override;
 
     static const char* EdgeStyleToAAString(ClipEdgeStyle edgeStyle);
diff --git a/include/utils/SkLuaCanvas.h b/include/utils/SkLuaCanvas.h
index 7653b45..2fef2c0 100644
--- a/include/utils/SkLuaCanvas.h
+++ b/include/utils/SkLuaCanvas.h
@@ -66,6 +66,7 @@
     void onClipRegion(const SkRegion&, SkClipOp) override;
 
     void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override;
+    void onDrawDrawable(SkDrawable*, const SkMatrix*) override;
 
 private:
     lua_State*  fL;
diff --git a/include/utils/SkNWayCanvas.h b/include/utils/SkNWayCanvas.h
index 7701d50..6641395 100644
--- a/include/utils/SkNWayCanvas.h
+++ b/include/utils/SkNWayCanvas.h
@@ -79,6 +79,7 @@
     void onClipRegion(const SkRegion&, SkClipOp) override;
 
     void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override;
+    void onDrawDrawable(SkDrawable*, const SkMatrix*) override;
     void onDrawAnnotation(const SkRect&, const char[], SkData*) override;
 
     class Iter;
diff --git a/include/utils/SkPaintFilterCanvas.h b/include/utils/SkPaintFilterCanvas.h
index 31b3663..d89c80a 100644
--- a/include/utils/SkPaintFilterCanvas.h
+++ b/include/utils/SkPaintFilterCanvas.h
@@ -34,6 +34,7 @@
         kOval_Type,
         kPath_Type,
         kPicture_Type,
+        kDrawable_Type,
         kText_Type,
         kTextBlob_Type,
         kVertices_Type,
@@ -79,6 +80,7 @@
                              const SkPoint texCoords[4], SkBlendMode,
                              const SkPaint& paint) override;
     void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override;
+    void onDrawDrawable(SkDrawable*, const SkMatrix*) override;
 
     void onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
                     const SkPaint&) override;
diff --git a/src/utils/SkDumpCanvas.cpp b/src/utils/SkDumpCanvas.cpp
index 05cabad..c547fa2 100644
--- a/src/utils/SkDumpCanvas.cpp
+++ b/src/utils/SkDumpCanvas.cpp
@@ -6,6 +6,7 @@
  */
 
 #include "SkData.h"
+#include "SkDrawable.h"
 #include "SkDumpCanvas.h"
 #include "SkImage.h"
 #include "SkPatchUtils.h"
@@ -461,11 +462,22 @@
     fNestLevel += 1;
     this->INHERITED::onDrawPicture(picture, matrix, paint);
     fNestLevel -= 1;
-    this->dump(kDrawPicture_Verb, nullptr, "endPicture(%p) %f:%f:%f:%f", &picture,
+    this->dump(kDrawPicture_Verb, nullptr, "endPicture(%p) %f:%f:%f:%f", picture,
                picture->cullRect().fLeft, picture->cullRect().fTop,
                picture->cullRect().fRight, picture->cullRect().fBottom);
 }
 
+void SkDumpCanvas::onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) {
+    const auto bounds = drawable->getBounds();
+    this->dump(kDrawPicture_Verb, nullptr, "drawDrawable(%p) %f:%f:%f:%f", drawable,
+               bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom);
+    fNestLevel += 1;
+    this->INHERITED::onDrawDrawable(drawable, matrix);
+    fNestLevel -= 1;
+    this->dump(kDrawPicture_Verb, nullptr, "endDrawable(%p) %f:%f:%f:%f", drawable,
+               bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom);
+}
+
 void SkDumpCanvas::onDrawVerticesObject(const SkVertices* vertices, SkBlendMode,
                                         const SkPaint& paint) {
     this->dump(kDrawVertices_Verb, &paint, "drawVertices(%s [%d] ...)",
diff --git a/src/utils/SkLuaCanvas.cpp b/src/utils/SkLuaCanvas.cpp
index ddf5187..9d2e8c9 100644
--- a/src/utils/SkLuaCanvas.cpp
+++ b/src/utils/SkLuaCanvas.cpp
@@ -307,6 +307,12 @@
     this->INHERITED::onDrawPicture(picture, matrix, paint);
 }
 
+void SkLuaCanvas::onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) {
+    AUTO_LUA("drawDrawable");
+    // call through so we can see the nested ops
+    this->INHERITED::onDrawDrawable(drawable, matrix);
+}
+
 void SkLuaCanvas::onDrawVerticesObject(const SkVertices*, SkBlendMode, const SkPaint& paint) {
     AUTO_LUA("drawVertices");
     lua.pushPaint(paint, "paint");
diff --git a/src/utils/SkNWayCanvas.cpp b/src/utils/SkNWayCanvas.cpp
index 208f3b4..b1e92fb 100644
--- a/src/utils/SkNWayCanvas.cpp
+++ b/src/utils/SkNWayCanvas.cpp
@@ -282,6 +282,13 @@
     }
 }
 
+void SkNWayCanvas::onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) {
+    Iter iter(fList);
+    while (iter.next()) {
+        iter->drawDrawable(drawable, matrix);
+    }
+}
+
 void SkNWayCanvas::onDrawVerticesObject(const SkVertices* vertices, SkBlendMode bmode,
                                         const SkPaint& paint) {
     Iter iter(fList);
diff --git a/src/utils/SkPaintFilterCanvas.cpp b/src/utils/SkPaintFilterCanvas.cpp
index e504c72..6092058 100644
--- a/src/utils/SkPaintFilterCanvas.cpp
+++ b/src/utils/SkPaintFilterCanvas.cpp
@@ -172,6 +172,16 @@
     }
 }
 
+void SkPaintFilterCanvas::onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) {
+    // There is no paint to filter in this case, but we can still filter on type.
+    // Subclasses need to unroll the drawable explicity (by overriding this method) in
+    // order to actually filter nested content.
+    AutoPaintFilter apf(this, kDrawable_Type, nullptr);
+    if (apf.shouldDraw()) {
+        this->INHERITED::onDrawDrawable(drawable, matrix);
+    }
+}
+
 void SkPaintFilterCanvas::onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
                                      const SkPaint& paint) {
     AutoPaintFilter apf(this, kText_Type, paint);