Rewrite restore_scissor_on_fbo_change

Old workaround was never used by chrome and was insufficient for
SkiaRenderer bug on Adreno 3xx.

Use same name used by Chrome.

Always set the scissor state before every draw/clear when using FBO 0.

Bug: chromium:1152831
Change-Id: Ibf0453d949fa3d5cb964411da3bcc1ec62a3d3a4
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/342076
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index 9a6b33f..f679806 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -2206,6 +2206,21 @@
         fHWBoundRenderTargetUniqueID = rtID;
         this->flushViewport(target->width(), target->height());
     }
+    if (this->caps()->workarounds().force_update_scissor_state_when_binding_fbo0 &&
+        fBoundDrawFramebuffer == 0) {
+        // The driver forgets the correct scissor state when using FBO 0.
+        if (!fHWScissorSettings.fRect.isInvalid()) {
+            const GrNativeRect& r = fHWScissorSettings.fRect;
+            GL_CALL(Scissor(r.fX, r.fY, r.fWidth, r.fHeight));
+        }
+        if (fHWScissorSettings.fEnabled == kYes_TriState) {
+            GL_CALL(Disable(GR_GL_SCISSOR_TEST));
+            GL_CALL(Enable(GR_GL_SCISSOR_TEST));
+        } else if (fHWScissorSettings.fEnabled == kNo_TriState) {
+            GL_CALL(Enable(GR_GL_SCISSOR_TEST));
+            GL_CALL(Disable(GR_GL_SCISSOR_TEST));
+        }
+    }
 
     if (this->glCaps().srgbWriteControl()) {
         this->flushFramebufferSRGB(this->caps()->isFormatSRGB(target->backendFormat()));
@@ -2882,8 +2897,7 @@
 }
 
 void GrGLGpu::onFBOChanged() {
-    if (this->caps()->workarounds().flush_on_framebuffer_change ||
-        this->caps()->workarounds().restore_scissor_on_fbo_change) {
+    if (this->caps()->workarounds().flush_on_framebuffer_change) {
         this->flush(FlushType::kForce);
     }
 #ifdef SK_DEBUG
@@ -2900,15 +2914,6 @@
     if (target == GR_GL_FRAMEBUFFER || target == GR_GL_DRAW_FRAMEBUFFER) {
         fBoundDrawFramebuffer = fboid;
     }
-
-    if (this->caps()->workarounds().restore_scissor_on_fbo_change) {
-        // The driver forgets the correct scissor when modifying the FBO binding.
-        if (!fHWScissorSettings.fRect.isInvalid()) {
-            const GrNativeRect& r = fHWScissorSettings.fRect;
-            GL_CALL(Scissor(r.fX, r.fY, r.fWidth, r.fHeight));
-        }
-    }
-
     this->onFBOChanged();
 }
 
diff --git a/src/gpu/gpu_workaround_list.txt b/src/gpu/gpu_workaround_list.txt
index 3f30fd1..5d96845 100644
--- a/src/gpu/gpu_workaround_list.txt
+++ b/src/gpu/gpu_workaround_list.txt
@@ -5,13 +5,13 @@
 disallow_large_instanced_draw
 emulate_abs_int_function
 flush_on_framebuffer_change
+force_update_scissor_state_when_binding_fbo0
 gl_clear_broken
 max_fragment_uniform_vectors_32
 max_msaa_sample_count_4
 max_texture_size_limit_4096
 pack_parameters_workaround_with_pack_buffer
 remove_pow_with_constant_exponent
-restore_scissor_on_fbo_change
 rewrite_do_while_loops
 unbind_attachments_on_bound_render_fbo_delete
 unfold_short_circuit_as_ternary_operation