Move clear-as-draw workaround to GrGLGpu and expose via GrContextOptions.


Bug: skia:7154
Change-Id: I23ffc11dab4a377fbd6b7e4e33722b3fa0793d58
Reviewed-on: https://skia-review.googlesource.com/60681
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
diff --git a/tests/ClearTest.cpp b/tests/ClearTest.cpp
index bcd0899..c1c39dc 100644
--- a/tests/ClearTest.cpp
+++ b/tests/ClearTest.cpp
@@ -43,8 +43,7 @@
                                                     kRGBA_8888_GrPixelConfig, nullptr);
 }
 
-DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ClearOp, reporter, ctxInfo) {
-    GrContext* context = ctxInfo.grContext();
+static void clear_op_test(skiatest::Reporter* reporter, GrContext* context) {
     static const int kW = 10;
     static const int kH = 10;
 
@@ -202,4 +201,84 @@
                failX, failY);
     }
 }
+
+DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ClearOp, reporter, ctxInfo) {
+    clear_op_test(reporter, ctxInfo.grContext());
+    if (ctxInfo.backend() == kOpenGL_GrBackend) {
+        GrContextOptions options(ctxInfo.options());
+        options.fUseDrawInsteadOfGLClear = GrContextOptions::Enable::kYes;
+        sk_gpu_test::GrContextFactory workaroundFactory(options);
+        clear_op_test(reporter, workaroundFactory.get(ctxInfo.type()));
+    }
+}
+
+#if 0
+
+void fullscreen_clear_with_layer_test(skiatest::Reporter* reporter, GrContext* context) {
+    const SkImageInfo ii = SkImageInfo::Make(400, 77, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
+
+    sk_sp<SkSurface> surf = SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, ii);
+    SkCanvas* canvas = surf->getCanvas();
+
+    SkPaint paints[2];
+    paints[0].setColor(SK_ColorGREEN);
+    paints[1].setColor(SK_ColorGRAY);
+
+    static const int kLeftX = 158;
+    static const int kMidX = 258;
+    static const int kRightX = 383;
+    static const int kTopY = 26;
+    static const int kBotY = 51;
+
+    const SkRect rects[2] = {
+        { kLeftX, kTopY, kMidX, kBotY },
+        { kMidX, kTopY, kRightX, kBotY },
+    };
+
+    for (int i = 0; i < 2; ++i) {
+        // the bounds parameter is required to cause a full screen clear
+        canvas->saveLayer(&rects[i], nullptr);
+            canvas->drawRect(rects[i], paints[i]);
+        canvas->restore();
+    }
+
+    SkBitmap bm;
+    bm.allocPixels(ii, 0);
+
+    SkAssertResult(surf->readPixels(bm, 0, 0));
+
+    bool isCorrect = true;
+    for (int y = kTopY; isCorrect && y < kBotY; ++y) {
+        const uint32_t* sl = bm.getAddr32(0, y);
+
+        for (int x = kLeftX; x < kMidX; ++x) {
+            if (SK_ColorGREEN != sl[x]) {
+                isCorrect = false;
+                break;
+            }
+        }
+
+        for (int x = kMidX; x < kRightX; ++x) {
+            if (SK_ColorGRAY != sl[x]) {
+                isCorrect = false;
+                break;
+            }
+        }
+    }
+
+    REPORTER_ASSERT(reporter, isCorrect);
+}
+// From crbug.com/768134
+DEF_GPUTEST_FOR_RENDERING_CONTEXTS(FullScreenClearWithLayers, reporter, ctxInfo) {
+    fullscreen_clear_with_layer_test(reporter, ctxInfo.grContext());
+    if (ctxInfo.backend() == kOpenGL_GrBackend) {
+        GrContextOptions options(ctxInfo.options());
+        options.fUseDrawInsteadOfGLClear = GrContextOptions::Enable::kYes;
+        sk_gpu_test::GrContextFactory workaroundFactory(options);
+        fullscreen_clear_with_layer_test(reporter, workaroundFactory.get(ctxInfo.type()));
+    }
+}
+
+#endif
+
 #endif