Remove SK_ALLOW_STATIC_GLOBAL_INITIALIZERS from tests.

The tests themselves should run fine if no factories were actually
registered. This isolates the last uses of this flag to the gpu code
which is actually depending on it.

Change-Id: Ief9c01abfc37c4e071d946d70ef85f13f94ae0f6
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/213301
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
diff --git a/src/gpu/GrProcessor.cpp b/src/gpu/GrProcessor.cpp
index 34370de..2a58b54 100644
--- a/src/gpu/GrProcessor.cpp
+++ b/src/gpu/GrProcessor.cpp
@@ -27,7 +27,6 @@
 
 const GrCaps* GrProcessorTestData::caps() { return fContext->priv().caps(); }
 
-#if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
 class GrFragmentProcessor;
 class GrGeometryProcessor;
 
@@ -57,9 +56,15 @@
  * we verify the count is as expected.  If a new factory is added, then these numbers must be
  * manually adjusted.
  */
+#if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
 static const int kFPFactoryCount = 36;
 static const int kGPFactoryCount = 14;
 static const int kXPFactoryCount = 4;
+#else
+static const int kFPFactoryCount = 0;
+static const int kGPFactoryCount = 0;
+static const int kXPFactoryCount = 0;
+#endif
 
 template <>
 void GrFragmentProcessorTestFactory::VerifyFactoryCount() {
@@ -88,7 +93,6 @@
 }
 
 #endif
-#endif
 
 
 // We use a global pool protected by a mutex(spinlock). Chrome may use the same GrContext on
diff --git a/src/gpu/GrProcessorUnitTest.h b/src/gpu/GrProcessorUnitTest.h
index 2a763b7..8ed5297 100644
--- a/src/gpu/GrProcessorUnitTest.h
+++ b/src/gpu/GrProcessorUnitTest.h
@@ -73,8 +73,6 @@
     sk_sp<GrTextureProxy> fProxies[2];
 };
 
-#if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
-
 class GrProcessor;
 class GrTexture;
 
@@ -92,7 +90,9 @@
     /** Pick a random factory function and create a processor.  */
     static ProcessorSmartPtr Make(GrProcessorTestData* data) {
         VerifyFactoryCount();
-        SkASSERT(GetFactories()->count());
+        if (GetFactories()->count() == 0) {
+            return nullptr;
+        }
         uint32_t idx = data->fRandom->nextRangeU(0, GetFactories()->count() - 1);
         return MakeIdx(idx, data);
     }
@@ -102,6 +102,7 @@
 
     /** Use factory function at Index idx to create a processor. */
     static ProcessorSmartPtr MakeIdx(int idx, GrProcessorTestData* data) {
+        SkASSERT(idx < GetFactories()->count());
         GrProcessorTestFactory<ProcessorSmartPtr>* factory = (*GetFactories())[idx];
         ProcessorSmartPtr processor = factory->fMakeProc(data);
         SkASSERT(processor);
@@ -130,7 +131,9 @@
 
     static const GrXPFactory* Get(GrProcessorTestData* data) {
         VerifyFactoryCount();
-        SkASSERT(GetFactories()->count());
+        if (GetFactories()->count() == 0) {
+            return nullptr;
+        }
         uint32_t idx = data->fRandom->nextRangeU(0, GetFactories()->count() - 1);
         const GrXPFactory* xpf = (*GetFactories())[idx]->fGetProc(data);
         SkASSERT(xpf);
@@ -144,6 +147,8 @@
     static SkTArray<GrXPFactoryTestFactory*, true>* GetFactories();
 };
 
+#if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
+
 /** GrProcessor subclasses should insert this macro in their declaration to be included in the
  *  program generation unit test.
  */
diff --git a/tests/GLProgramsTest.cpp b/tests/GLProgramsTest.cpp
index 9d6d623..850f426 100644
--- a/tests/GLProgramsTest.cpp
+++ b/tests/GLProgramsTest.cpp
@@ -5,12 +5,10 @@
  * found in the LICENSE file.
  */
 
-// This is a GPU-backend specific test. It relies on static intializers to work
+// This is a GPU-backend specific test.
 
 #include "include/core/SkTypes.h"
 
-#if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
-
 #include "include/private/SkChecksum.h"
 #include "include/utils/SkRandom.h"
 #include "src/gpu/GrAutoLocaleSetter.h"
@@ -189,7 +187,9 @@
             std::unique_ptr<GrFragmentProcessor> fp;
             while (true) {
                 fp = GrFragmentProcessorTestFactory::Make(d);
-                SkASSERT(fp);
+                if (!fp) {
+                    return nullptr;
+                }
                 if (0 == fp->numChildProcessors()) {
                     break;
                 }
@@ -205,6 +205,9 @@
     }
     auto minLevelsChild = create_random_proc_tree(d, minLevels, maxLevels - 1);
     std::unique_ptr<GrFragmentProcessor> otherChild(create_random_proc_tree(d, 1, maxLevels - 1));
+    if (!minLevelsChild || !otherChild) {
+        return nullptr;
+    }
     SkBlendMode mode = static_cast<SkBlendMode>(d->fRandom->nextRangeU(0,
                                                                (int)SkBlendMode::kLastMode));
     std::unique_ptr<GrFragmentProcessor> fp;
@@ -235,17 +238,17 @@
         int numProcs = d->fRandom->nextULessThan(maxStages + 1);
         int numColorProcs = d->fRandom->nextULessThan(numProcs + 1);
 
-        for (int s = 0; s < numProcs;) {
+        for (int s = 0; s < numProcs; ++s) {
             std::unique_ptr<GrFragmentProcessor> fp(GrFragmentProcessorTestFactory::Make(d));
-            SkASSERT(fp);
-
+            if (!fp) {
+                continue;
+            }
             // finally add the stage to the correct pipeline in the drawstate
             if (s < numColorProcs) {
                 paint->addColorFragmentProcessor(std::move(fp));
             } else {
                 paint->addCoverageFragmentProcessor(std::move(fp));
             }
-            ++s;
         }
     }
 }
@@ -426,4 +429,3 @@
                                      opts);
 }
 
-#endif
diff --git a/tests/ProcessorTest.cpp b/tests/ProcessorTest.cpp
index 8c50799..fc88688 100644
--- a/tests/ProcessorTest.cpp
+++ b/tests/ProcessorTest.cpp
@@ -227,9 +227,6 @@
     }
 }
 
-// This test uses the random GrFragmentProcessor test factory, which relies on static initializers.
-#if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
-
 #include "tools/flags/CommandLineFlags.h"
 static DEFINE_bool(randomProcessorTest, false,
                    "Use non-deterministic seed for random processor tests?");
@@ -758,4 +755,3 @@
 }
 
 #endif  // GR_TEST_UTILS
-#endif  // SK_ALLOW_STATIC_GLOBAL_INITIALIZERS