[skottie] Avoid reshaping text unnecessarily

Only call into SkShaper when the text value changes.

Change-Id: I4c44a20fd48be932f9ffe23af5ebcc12b67956ee
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/241077
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Florin Malita <fmalita@chromium.org>
diff --git a/modules/skottie/src/text/TextAdapter.cpp b/modules/skottie/src/text/TextAdapter.cpp
index c0bc464..a7b5ecf 100644
--- a/modules/skottie/src/text/TextAdapter.cpp
+++ b/modules/skottie/src/text/TextAdapter.cpp
@@ -78,7 +78,7 @@
 
     abuilder->bindProperty<TextValue>(*jd,
         [raw_adapter] (const TextValue& txt) {
-            raw_adapter->fText = txt;
+            raw_adapter->setText(txt);
         });
 
     abuilder->dispatchTextProperty(adapter);
@@ -186,11 +186,14 @@
     }
 }
 
-void TextAdapter::onSync() {
-    if (!fText.fHasFill && !fText.fHasStroke) {
-        return;
+void TextAdapter::setText(const TextValue& txt) {
+    if (txt != fText) {
+        fText = txt;
+        fTextDirty = true;
     }
+}
 
+void TextAdapter::reshape() {
     const Shaper::TextDesc text_desc = {
         fText.fTypeface,
         fText.fTextSize,
@@ -245,6 +248,17 @@
     fRoot->addChild(sksg::Draw::Make(sksg::Rect::Make(shape_result.computeBounds()),
                                      std::move(bounds_color)));
 #endif
+}
+
+void TextAdapter::onSync() {
+    if (!fText.fHasFill && !fText.fHasStroke) {
+        return;
+    }
+
+    if (fTextDirty) {
+        this->reshape();
+        fTextDirty = false;
+    }
 
     if (fFragments.empty()) {
         return;
diff --git a/modules/skottie/src/text/TextAdapter.h b/modules/skottie/src/text/TextAdapter.h
index fef240b..9e72b17 100644
--- a/modules/skottie/src/text/TextAdapter.h
+++ b/modules/skottie/src/text/TextAdapter.h
@@ -30,7 +30,7 @@
     const sk_sp<sksg::Group>& renderNode() const { return fRoot; }
 
     const TextValue& getText() const { return fText; }
-    void setText(const TextValue& t) { fText = t; }
+    void setText(const TextValue&);
 
 protected:
     void onSync() override;
@@ -46,6 +46,7 @@
                                       fStrokeColorNode;
     };
 
+    void reshape();
     void addFragment(const Shaper::Fragment&);
     void buildDomainMaps(const Shaper::Result&);
 
@@ -64,6 +65,7 @@
     TextAnimator::DomainMaps fMaps;
 
     TextValue                fText;
+    bool                     fTextDirty = true;
 };
 
 } // namespace internal