[canvaskit] Return damage rect from ManagedAnimation::seek()

This is useful to avoid redrawing unnecessarily when the animation
doesn't progress.

Bug: skia:9267
Change-Id: Id4184ae8308b8abd959fbfd1768e3e22d1efe0a4
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/229006
Reviewed-by: Ravi Mistry <rmistry@google.com>
Commit-Queue: Florin Malita <fmalita@chromium.org>
diff --git a/modules/canvaskit/canvaskit/extra.html b/modules/canvaskit/canvaskit/extra.html
index 53b4788..99a458a 100644
--- a/modules/canvaskit/canvaskit/extra.html
+++ b/modules/canvaskit/canvaskit/extra.html
@@ -155,9 +155,12 @@
 
     function drawFrame(canvas) {
       let seek = ((Date.now() - firstFrame) / duration) % 1.0;
-      animation.seek(seek);
-      canvas.clear(CanvasKit.WHITE);
-      animation.render(canvas, bounds);
+      let damage = animation.seek(seek);
+      // TODO: SkRect.isEmpty()?
+      if (damage.fRight > damage.fLeft && damage.fBottom > damage.fTop) {
+        canvas.clear(CanvasKit.WHITE);
+        animation.render(canvas, bounds);
+      }
       surface.requestAnimationFrame(drawFrame);
     }
     surface.requestAnimationFrame(drawFrame);
diff --git a/modules/canvaskit/skottie_bindings.cpp b/modules/canvaskit/skottie_bindings.cpp
index 6d4898c..88213b9 100644
--- a/modules/canvaskit/skottie_bindings.cpp
+++ b/modules/canvaskit/skottie_bindings.cpp
@@ -10,6 +10,7 @@
 #include "include/core/SkString.h"
 #include "include/core/SkTypes.h"
 #include "modules/skottie/include/Skottie.h"
+#include "modules/sksg/include/SkSGInvalidationController.h"
 #include "src/core/SkMakeUnique.h"
 
 #include <string>
@@ -100,7 +101,12 @@
     // skottie::Animation API
     void render(SkCanvas* canvas) const { fAnimation->render(canvas, nullptr); }
     void render(SkCanvas* canvas, const SkRect& dst) const { fAnimation->render(canvas, &dst); }
-    void seek(SkScalar t) { fAnimation->seek(t); }
+    // Returns a damage rect.
+    SkRect seek(SkScalar t) {
+        sksg::InvalidationController ic;
+        fAnimation->seek(t, &ic);
+        return ic.bounds();
+    }
     SkScalar duration() const { return fAnimation->duration(); }
     const SkSize&      size() const { return fAnimation->size(); }
     std::string version() const { return std::string(fAnimation->version().c_str()); }