Don't use GL_FRAMEBUFFER_SRGB unless available.

Don't try to enable or disable GL_FRAMEBUFFER_SRGB unless
extensions.sRGBWriteControl is true.  For example if you
try it with Mesa GLES2 you get a GL error.

BUG=angleproject:1896

Change-Id: I5f5b4e8ea4f5a7c6913f27761a6e2dc88aacc78c
Reviewed-on: https://chromium-review.googlesource.com/443824
Commit-Queue: Frank Henigman <fjhenigman@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/libANGLE/renderer/gl/FramebufferGL.cpp b/src/libANGLE/renderer/gl/FramebufferGL.cpp
index 8cf144f..a4b4ccd 100644
--- a/src/libANGLE/renderer/gl/FramebufferGL.cpp
+++ b/src/libANGLE/renderer/gl/FramebufferGL.cpp
@@ -167,7 +167,7 @@
 
 Error FramebufferGL::clear(ContextImpl *context, GLbitfield mask)
 {
-    syncClearState(mask);
+    syncClearState(context, mask);
     mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID);
     mFunctions->clear(mask);
 
@@ -179,7 +179,7 @@
                                    GLint drawbuffer,
                                    const GLfloat *values)
 {
-    syncClearBufferState(buffer, drawbuffer);
+    syncClearBufferState(context, buffer, drawbuffer);
     mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID);
     mFunctions->clearBufferfv(buffer, drawbuffer, values);
 
@@ -191,7 +191,7 @@
                                     GLint drawbuffer,
                                     const GLuint *values)
 {
-    syncClearBufferState(buffer, drawbuffer);
+    syncClearBufferState(context, buffer, drawbuffer);
     mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID);
     mFunctions->clearBufferuiv(buffer, drawbuffer, values);
 
@@ -203,7 +203,7 @@
                                    GLint drawbuffer,
                                    const GLint *values)
 {
-    syncClearBufferState(buffer, drawbuffer);
+    syncClearBufferState(context, buffer, drawbuffer);
     mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID);
     mFunctions->clearBufferiv(buffer, drawbuffer, values);
 
@@ -216,7 +216,7 @@
                                    GLfloat depth,
                                    GLint stencil)
 {
-    syncClearBufferState(buffer, drawbuffer);
+    syncClearBufferState(context, buffer, drawbuffer);
     mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID);
     mFunctions->clearBufferfi(buffer, drawbuffer, depth, stencil);
 
@@ -343,7 +343,7 @@
     }
 
     // Enable FRAMEBUFFER_SRGB if needed
-    mStateManager->setFramebufferSRGBEnabledForFramebuffer(true, this);
+    mStateManager->setFramebufferSRGBEnabledForFramebuffer(context->getContextState(), true, this);
 
     GLenum blitMask = mask;
     if (needManualColorBlit && (mask & GL_COLOR_BUFFER_BIT) && readAttachmentSamples <= 1)
@@ -461,7 +461,7 @@
     return mIsDefault;
 }
 
-void FramebufferGL::syncClearState(GLbitfield mask)
+void FramebufferGL::syncClearState(ContextImpl *context, GLbitfield mask)
 {
     if (mFunctions->standard == STANDARD_GL_DESKTOP)
     {
@@ -478,16 +478,16 @@
                 }
             }
 
-            mStateManager->setFramebufferSRGBEnabled(hasSRGBAttachment);
+            mStateManager->setFramebufferSRGBEnabled(context->getContextState(), hasSRGBAttachment);
         }
         else
         {
-            mStateManager->setFramebufferSRGBEnabled(!mIsDefault);
+            mStateManager->setFramebufferSRGBEnabled(context->getContextState(), !mIsDefault);
         }
     }
 }
 
-void FramebufferGL::syncClearBufferState(GLenum buffer, GLint drawBuffer)
+void FramebufferGL::syncClearBufferState(ContextImpl *context, GLenum buffer, GLint drawBuffer)
 {
     if (mFunctions->standard == STANDARD_GL_DESKTOP)
     {
@@ -510,12 +510,13 @@
 
             if (attachment != nullptr)
             {
-                mStateManager->setFramebufferSRGBEnabled(attachment->getColorEncoding() == GL_SRGB);
+                mStateManager->setFramebufferSRGBEnabled(context->getContextState(),
+                                                         attachment->getColorEncoding() == GL_SRGB);
             }
         }
         else
         {
-            mStateManager->setFramebufferSRGBEnabled(!mIsDefault);
+            mStateManager->setFramebufferSRGBEnabled(context->getContextState(), !mIsDefault);
         }
     }
 }