Make GrAtlasTextBlob::run own effects it points to.

BUG=chromium:608566

Currently the run has bare pointers and the effects can be destroyed while a run is pointing at them.

GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1993213003

Review-Url: https://codereview.chromium.org/1993213003
diff --git a/src/gpu/text/GrAtlasTextBlob.cpp b/src/gpu/text/GrAtlasTextBlob.cpp
index 54af7af..13c96b5 100644
--- a/src/gpu/text/GrAtlasTextBlob.cpp
+++ b/src/gpu/text/GrAtlasTextBlob.cpp
@@ -58,9 +58,13 @@
     // if we have an override descriptor for the run, then we should use that
     SkAutoDescriptor* desc = run->fOverrideDescriptor.get() ? run->fOverrideDescriptor.get() :
                                                               &run->fDescriptor;
-    skPaint.getScalerContextDescriptor(&run->fEffects, desc, props, scalerContextFlags, viewMatrix);
+    SkScalerContextEffects effects;
+    skPaint.getScalerContextDescriptor(&effects, desc, props, scalerContextFlags, viewMatrix);
     run->fTypeface.reset(SkSafeRef(skPaint.getTypeface()));
-    return SkGlyphCache::DetachCache(run->fTypeface, run->fEffects, desc->getDesc());
+    run->fPathEffect = sk_ref_sp(effects.fPathEffect);
+    run->fRasterizer = sk_ref_sp(effects.fRasterizer);
+    run->fMaskFilter = sk_ref_sp(effects.fMaskFilter);
+    return SkGlyphCache::DetachCache(run->fTypeface, effects, desc->getDesc());
 }
 
 void GrAtlasTextBlob::appendGlyph(int runIndex,
diff --git a/src/gpu/text/GrAtlasTextBlob.h b/src/gpu/text/GrAtlasTextBlob.h
index d9083b2..63c8033 100644
--- a/src/gpu/text/GrAtlasTextBlob.h
+++ b/src/gpu/text/GrAtlasTextBlob.h
@@ -14,6 +14,8 @@
 #include "GrMemoryPool.h"
 #include "SkDescriptor.h"
 #include "SkMaskFilter.h"
+#include "SkPathEffect.h"
+#include "SkRasterizer.h"
 #include "SkSurfaceProps.h"
 #include "SkTInternalLList.h"
 
@@ -477,7 +479,11 @@
         SkAutoTUnref<SkTypeface> fTypeface;
         SkSTArray<kMinSubRuns, SubRunInfo> fSubRunInfo;
         SkAutoDescriptor fDescriptor;
-        SkScalerContextEffects fEffects;
+
+        // Effects from the paint that are used to build a SkScalerContext.
+        sk_sp<SkPathEffect> fPathEffect;
+        sk_sp<SkRasterizer> fRasterizer;
+        sk_sp<SkMaskFilter> fMaskFilter;
 
         // Distance field text cannot draw coloremoji, and so has to fall back.  However,
         // though the distance field text and the coloremoji may share the same run, they
diff --git a/src/gpu/text/GrAtlasTextBlob_regenInBatch.cpp b/src/gpu/text/GrAtlasTextBlob_regenInBatch.cpp
index 28d3219..59df1fa 100644
--- a/src/gpu/text/GrAtlasTextBlob_regenInBatch.cpp
+++ b/src/gpu/text/GrAtlasTextBlob_regenInBatch.cpp
@@ -158,7 +158,11 @@
                                       : run->fDescriptor.getDesc();
 
         if (!*lazyCache || (*lazyCache)->getDescriptor() != *desc) {
-            lazyCache->reset(SkGlyphCache::DetachCache(run->fTypeface, run->fEffects, desc));
+            SkScalerContextEffects effects;
+            effects.fPathEffect = run->fPathEffect.get();
+            effects.fRasterizer = run->fRasterizer.get();
+            effects.fMaskFilter = run->fMaskFilter.get();
+            lazyCache->reset(SkGlyphCache::DetachCache(run->fTypeface, effects, desc));
         }
 
         if (regenGlyphs) {