Use GrContextFactories that produce a single GrContext in unit tests.

This is to alleviate problems due to the command buffer getting bent out of shape when the current
OpenGL context is switched out from under it (because we ran a test with a native GL context). This,
however is not a full solution. More changes will be required to ensure that after running each
command buffer or native test we bind the null context. This does allow us to take a step in that
direction without breaking anything too badly. Moreover, there is no real benefit to reusing a
GrContextFactory.

Modifies DEF_GPUTEST to take GrContextOptions rather than a factory to use. Tests were already using
their own factories anyway.

In tests that use GrContextFactory the factory instance is moved to the inner loop.

Modifies gpucts and skia_test to not use persistent GrContextFactories.

Change-Id: Ie7a36793545c775f2f30653ead6fec93a3d22717
Reviewed-on: https://skia-review.googlesource.com/71861
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
diff --git a/tests/skia_test.cpp b/tests/skia_test.cpp
index 6b7df71..8e4cbae 100644
--- a/tests/skia_test.cpp
+++ b/tests/skia_test.cpp
@@ -22,6 +22,8 @@
 #if SK_SUPPORT_GPU
 #include "GrContext.h"
 #include "GrContextFactory.h"
+#else
+struct GrContextOptions {};
 #endif
 
 using namespace skiatest;
@@ -82,38 +84,32 @@
 
 class SkTestRunnable {
 public:
-    SkTestRunnable(const Test& test,
-                   Status* status,
-                   GrContextFactory* grContextFactory = nullptr)
-        : fTest(test), fStatus(status), fGrContextFactory(grContextFactory) {}
+    SkTestRunnable(const Test& test, Status* status) : fTest(test), fStatus(status) {}
 
-  void operator()() {
-      struct TestReporter : public skiatest::Reporter {
-      public:
-          TestReporter() : fStats(nullptr), fError(false), fTestCount(0) {}
-          void bumpTestCount() override { ++fTestCount; }
-          bool allowExtendedTest() const override {
-              return FLAGS_extendedTest;
-          }
-          bool verbose() const override { return FLAGS_veryVerbose; }
-          void reportFailed(const skiatest::Failure& failure) override {
-              SkDebugf("\nFAILED: %s", failure.toString().c_str());
-              fError = true;
-          }
-          void* stats() const override { return fStats; }
-          void* fStats;
-          bool fError;
-          int fTestCount;
-      } reporter;
+    void operator()() {
+        struct TestReporter : public skiatest::Reporter {
+        public:
+            TestReporter() : fStats(nullptr), fError(false), fTestCount(0) {}
+            void bumpTestCount() override { ++fTestCount; }
+            bool allowExtendedTest() const override { return FLAGS_extendedTest; }
+            bool verbose() const override { return FLAGS_veryVerbose; }
+            void reportFailed(const skiatest::Failure& failure) override {
+                SkDebugf("\nFAILED: %s", failure.toString().c_str());
+                fError = true;
+            }
+            void* stats() const override { return fStats; }
+            void* fStats;
+            bool fError;
+            int fTestCount;
+        } reporter;
 
-      const Timer timer;
-      fTest.proc(&reporter, fGrContextFactory);
-      SkMSec elapsed = timer.elapsedMsInt();
-      if (reporter.fError) {
-          fStatus->reportFailure();
-      }
-      fStatus->endTest(fTest.name, !reporter.fError, elapsed,
-                       reporter.fTestCount);
+        const Timer timer;
+        fTest.proc(&reporter, GrContextOptions());
+        SkMSec elapsed = timer.elapsedMsInt();
+        if (reporter.fError) {
+            fStatus->reportFailure();
+        }
+        fStatus->endTest(fTest.name, !reporter.fError, elapsed, reporter.fTestCount);
   }
 
 private:
@@ -233,17 +229,9 @@
         }
     }
 
-    GrContextFactory* grContextFactoryPtr = nullptr;
-#if SK_SUPPORT_GPU
-    // Give GPU tests a context factory if that makes sense on this machine.
-    GrContextFactory grContextFactory;
-    grContextFactoryPtr = &grContextFactory;
-
-#endif
-
     // Run GPU tests on this thread.
     for (int i = 0; i < gpuTests.count(); i++) {
-        SkTestRunnable(*gpuTests[i], &status, grContextFactoryPtr)();
+        SkTestRunnable(*gpuTests[i], &status)();
     }
 
     // Block until threaded tests finish.