Don't draw strikes that are too small

This may fix a fuzzer bug that trips an
assert for empty rectangles. I could not reproduce
the fuzzer problem.

Bug: chromium:1029831
Change-Id: I88befb7c27d9ddc357e0a9e494e68125f8252f43
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/257676
Reviewed-by: Ben Wagner <bungeman@google.com>
Commit-Queue: Herb Derby <herb@google.com>
diff --git a/src/core/SkGlyphRunPainter.cpp b/src/core/SkGlyphRunPainter.cpp
index 20228fd..3c04f83 100644
--- a/src/core/SkGlyphRunPainter.cpp
+++ b/src/core/SkGlyphRunPainter.cpp
@@ -209,17 +209,19 @@
             std::tie(strikeSpec, minScale, maxScale) =
                     SkStrikeSpec::MakeSDFT(runFont, runPaint, fDeviceProps, viewMatrix, options);
 
-            SkScopedStrikeForGPU strike = strikeSpec.findOrCreateScopedStrike(fStrikeCache);
+            if (!strikeSpec.isEmpty()) {
+                SkScopedStrikeForGPU strike = strikeSpec.findOrCreateScopedStrike(fStrikeCache);
 
-            fDrawable.startSource(fRejects.source(), origin);
-            strike->prepareForSDFTDrawing(&fDrawable, &fRejects);
-            fRejects.flipRejectsToSource();
+                fDrawable.startSource(fRejects.source(), origin);
+                strike->prepareForSDFTDrawing(&fDrawable, &fRejects);
+                fRejects.flipRejectsToSource();
 
-            if (process) {
-                // processSourceSDFT must be called even if there are no glyphs to make sure runs
-                // are set correctly.
-                process->processSourceSDFT(
-                        fDrawable.drawable(), strikeSpec, runFont, minScale, maxScale);
+                if (process) {
+                    // processSourceSDFT must be called even if there are no glyphs to make sure
+                    // runs are set correctly.
+                    process->processSourceSDFT(
+                            fDrawable.drawable(), strikeSpec, runFont, minScale, maxScale);
+                }
             }
         }
 
@@ -232,18 +234,20 @@
             SkStrikeSpec strikeSpec = SkStrikeSpec::MakePath(
                     runFont, runPaint, fDeviceProps, fScalerContextFlags);
 
-            SkScopedStrikeForGPU strike = strikeSpec.findOrCreateScopedStrike(fStrikeCache);
+            if (!strikeSpec.isEmpty()) {
+                SkScopedStrikeForGPU strike = strikeSpec.findOrCreateScopedStrike(fStrikeCache);
 
-            fDrawable.startSource(fRejects.source(), origin);
-            strike->prepareForPathDrawing(&fDrawable, &fRejects);
-            fRejects.flipRejectsToSource();
-            maxDimensionInSourceSpace =
-                    fRejects.rejectedMaxDimension() * strikeSpec.strikeToSourceRatio();
+                fDrawable.startSource(fRejects.source(), origin);
+                strike->prepareForPathDrawing(&fDrawable, &fRejects);
+                fRejects.flipRejectsToSource();
+                maxDimensionInSourceSpace =
+                        fRejects.rejectedMaxDimension() * strikeSpec.strikeToSourceRatio();
 
-            if (process) {
-                // processSourcePaths must be called even if there are no glyphs to make sure runs
-                // are set correctly.
-                process->processSourcePaths(fDrawable.drawable(), runFont, strikeSpec);
+                if (process) {
+                    // processSourcePaths must be called even if there are no glyphs to make sure
+                    // runs are set correctly.
+                    process->processSourcePaths(fDrawable.drawable(), runFont, strikeSpec);
+                }
             }
         }
 
@@ -315,15 +319,17 @@
                         runFont, runPaint, fDeviceProps,
                         fScalerContextFlags, maxDimensionInSourceSpace);
 
-                SkScopedStrikeForGPU strike = strikeSpec.findOrCreateScopedStrike(fStrikeCache);
+                if (!strikeSpec.isEmpty()) {
+                    SkScopedStrikeForGPU strike = strikeSpec.findOrCreateScopedStrike(fStrikeCache);
 
-                fDrawable.startSource(fRejects.source(), origin);
-                strike->prepareForMaskDrawing(&fDrawable, &fRejects);
-                fRejects.flipRejectsToSource();
-                SkASSERT(fRejects.source().empty());
+                    fDrawable.startSource(fRejects.source(), origin);
+                    strike->prepareForMaskDrawing(&fDrawable, &fRejects);
+                    fRejects.flipRejectsToSource();
+                    SkASSERT(fRejects.source().empty());
 
-                if (process) {
-                    process->processSourceMasks(fDrawable.drawable(), strikeSpec);
+                    if (process) {
+                        process->processSourceMasks(fDrawable.drawable(), strikeSpec);
+                    }
                 }
             }
         }
diff --git a/src/core/SkStrikeSpec.h b/src/core/SkStrikeSpec.h
index f40032a..c22a9c3 100644
--- a/src/core/SkStrikeSpec.h
+++ b/src/core/SkStrikeSpec.h
@@ -78,6 +78,7 @@
             SkStrikeCache* cache = SkStrikeCache::GlobalStrikeCache()) const;
 
     SkScalar strikeToSourceRatio() const { return fStrikeToSourceRatio; }
+    bool isEmpty() const { return SkScalarNearlyZero(fStrikeToSourceRatio); }
     const SkDescriptor& descriptor() const { return *fAutoDescriptor.getDesc(); }
     static bool ShouldDrawAsPath(const SkPaint& paint, const SkFont& font, const SkMatrix& matrix);