Plumbed in discard_framebuffer extension

https://codereview.chromium.org/14461006/



git-svn-id: http://skia.googlecode.com/svn/trunk@8906 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp
index 461b3d6..b868d6a 100644
--- a/src/gpu/gl/GrGLCaps.cpp
+++ b/src/gpu/gl/GrGLCaps.cpp
@@ -43,6 +43,7 @@
     fVertexArrayObjectSupport = false;
     fUseNonVBOVertexAndIndexDynamicData = false;
     fIsCoreProfile = false;
+    fDiscardFBSupport = false;
 }
 
 GrGLCaps::GrGLCaps(const GrGLCaps& caps) : GrDrawTargetCaps() {
@@ -76,6 +77,7 @@
     fVertexArrayObjectSupport = caps.fVertexArrayObjectSupport;
     fUseNonVBOVertexAndIndexDynamicData = caps.fUseNonVBOVertexAndIndexDynamicData;
     fIsCoreProfile = caps.fIsCoreProfile;
+    fDiscardFBSupport = caps.fDiscardFBSupport;
 
     return *this;
 }
@@ -194,6 +196,8 @@
         fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
     }
 
+    fDiscardFBSupport = ctxInfo.hasExtension("GL_EXT_discard_framebuffer");
+
     if (kDesktop_GrGLBinding == binding) {
         fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
                                     ctxInfo.hasExtension("GL_ARB_vertex_array_object");
@@ -548,4 +552,5 @@
     GrPrintf("Use non-VBO for dynamic data: %s\n",
              (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
     GrPrintf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
+    GrPrintf("Discard FrameBuffer support: %s\n", (fDiscardFBSupport ? "YES" : "NO"));
 }
diff --git a/src/gpu/gl/GrGLCaps.h b/src/gpu/gl/GrGLCaps.h
index 4599e57..4aff025 100644
--- a/src/gpu/gl/GrGLCaps.h
+++ b/src/gpu/gl/GrGLCaps.h
@@ -236,6 +236,9 @@
 
     bool isCoreProfile() const { return fIsCoreProfile; }
 
+    /// Is there support for discarding the frame buffer
+    bool discardFBSupport() const { return fDiscardFBSupport; }
+
 private:
     /**
      * Maintains a bit per GrPixelConfig. It is used to avoid redundantly
@@ -311,6 +314,7 @@
     bool fVertexArrayObjectSupport : 1;
     bool fUseNonVBOVertexAndIndexDynamicData : 1;
     bool fIsCoreProfile : 1;
+    bool fDiscardFBSupport : 1;
 
     typedef GrDrawTargetCaps INHERITED;
 };
diff --git a/src/gpu/gl/GrGLCreateNullInterface.cpp b/src/gpu/gl/GrGLCreateNullInterface.cpp
index 5a5ec6b..1c2e1cd 100644
--- a/src/gpu/gl/GrGLCreateNullInterface.cpp
+++ b/src/gpu/gl/GrGLCreateNullInterface.cpp
@@ -241,6 +241,7 @@
         interface->fTexParameteriv = noOpGLTexParameteriv;
         interface->fTexSubImage2D = noOpGLTexSubImage2D;
         interface->fTexStorage2D = noOpGLTexStorage2D;
+        interface->fDiscardFramebuffer = noOpGLDiscardFramebuffer;
         interface->fUniform1f = noOpGLUniform1f;
         interface->fUniform1i = noOpGLUniform1i;
         interface->fUniform1fv = noOpGLUniform1fv;
diff --git a/src/gpu/gl/GrGLInterface.cpp b/src/gpu/gl/GrGLInterface.cpp
index 89912a0..b70841c 100644
--- a/src/gpu/gl/GrGLInterface.cpp
+++ b/src/gpu/gl/GrGLInterface.cpp
@@ -295,6 +295,15 @@
         }
     }
 
+    if (extensions.has("GL_EXT_discard_framebuffer")) {
+// FIXME: Remove this once Chromium is updated to provide this function
+#if 0
+        if (NULL == fDiscardFramebuffer) {
+            return false;
+        }
+#endif
+    }
+
     // FBO MSAA
     if (kDesktop_GrGLBinding == binding) {
         // GL 3.0 and the ARB extension have multisample + blit
diff --git a/src/gpu/gl/GrGLNoOpInterface.cpp b/src/gpu/gl/GrGLNoOpInterface.cpp
index 82e7a1b..f61fa55 100644
--- a/src/gpu/gl/GrGLNoOpInterface.cpp
+++ b/src/gpu/gl/GrGLNoOpInterface.cpp
@@ -238,6 +238,11 @@
                                                 GrGLsizei height) {
 }
 
+GrGLvoid GR_GL_FUNCTION_TYPE noOpGLDiscardFramebuffer(GrGLenum target, 
+                                                      GrGLsizei numAttachments, 
+                                                      const GrGLenum* attachments) {
+}
+
 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLTexSubImage2D(GrGLenum target,
                                                  GrGLint level,
                                                  GrGLint xoffset,
diff --git a/src/gpu/gl/GrGLNoOpInterface.h b/src/gpu/gl/GrGLNoOpInterface.h
index b04cdca..3002c07 100644
--- a/src/gpu/gl/GrGLNoOpInterface.h
+++ b/src/gpu/gl/GrGLNoOpInterface.h
@@ -159,6 +159,10 @@
                                                 GrGLsizei width,
                                                 GrGLsizei height);
 
+GrGLvoid GR_GL_FUNCTION_TYPE noOpGLDiscardFramebuffer(GrGLenum target, 
+                                                      GrGLsizei numAttachments, 
+                                                      const GrGLenum* attachments);
+
 GrGLvoid GR_GL_FUNCTION_TYPE noOpGLTexSubImage2D(GrGLenum target,
                                                  GrGLint level,
                                                  GrGLint xoffset,
diff --git a/src/gpu/gl/GrGpuGL.cpp b/src/gpu/gl/GrGpuGL.cpp
index 0f3d534..de7746f 100644
--- a/src/gpu/gl/GrGpuGL.cpp
+++ b/src/gpu/gl/GrGpuGL.cpp
@@ -1519,13 +1519,13 @@
 
     if (fHWBoundRenderTarget != rt) {
         GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, rt->renderFBOID()));
-    #if GR_DEBUG
+#if GR_DEBUG
         GrGLenum status;
         GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
         if (status != GR_GL_FRAMEBUFFER_COMPLETE) {
             GrPrintf("GrGpuGL::flushRenderTarget glCheckFramebufferStatus %x\n", status);
         }
-    #endif
+#endif
         fHWBoundRenderTarget = rt;
         const GrGLIRect& vp = rt->getViewport();
         if (fHWViewport != vp) {
diff --git a/src/gpu/gl/android/GrGLCreateNativeInterface_android.cpp b/src/gpu/gl/android/GrGLCreateNativeInterface_android.cpp
index 081fa05..842741c 100644
--- a/src/gpu/gl/android/GrGLCreateNativeInterface_android.cpp
+++ b/src/gpu/gl/android/GrGLCreateNativeInterface_android.cpp
@@ -95,6 +95,9 @@
 #else
         interface->fTexStorage2D = (GrGLTexStorage2DProc) eglGetProcAddress("glTexStorage2DEXT");
 #endif
+#if GL_EXT_discard_framebuffer
+        interface->fDiscardFramebuffer = glDiscardFramebufferEXT;
+#endif
         interface->fUniform1f = glUniform1f;
         interface->fUniform1i = glUniform1i;
         interface->fUniform1fv = glUniform1fv;
diff --git a/src/gpu/gl/debug/GrGLCreateDebugInterface.cpp b/src/gpu/gl/debug/GrGLCreateDebugInterface.cpp
index 2d7b044..4162331 100644
--- a/src/gpu/gl/debug/GrGLCreateDebugInterface.cpp
+++ b/src/gpu/gl/debug/GrGLCreateDebugInterface.cpp
@@ -861,6 +861,7 @@
     interface->fTexParameteriv = noOpGLTexParameteriv;
     interface->fTexSubImage2D = noOpGLTexSubImage2D;
     interface->fTexStorage2D = noOpGLTexStorage2D;
+    interface->fDiscardFramebuffer = noOpGLDiscardFramebuffer;
     interface->fUniform1f = noOpGLUniform1f;
     interface->fUniform1i = noOpGLUniform1i;
     interface->fUniform1fv = noOpGLUniform1fv;
diff --git a/src/gpu/gl/iOS/GrGLCreateNativeInterface_iOS.cpp b/src/gpu/gl/iOS/GrGLCreateNativeInterface_iOS.cpp
index 0ab0dbb..e83ccdd 100644
--- a/src/gpu/gl/iOS/GrGLCreateNativeInterface_iOS.cpp
+++ b/src/gpu/gl/iOS/GrGLCreateNativeInterface_iOS.cpp
@@ -85,6 +85,9 @@
 #elif GL_EXT_texture_storage
         interface->fTexStorage2D = glTexStorage2DEXT;
 #endif
+#if GL_EXT_discard_framebuffer
+        interface->fDiscardFramebuffer = glDiscardFramebufferEXT;
+#endif
         interface->fTexParameteri = glTexParameteri;
         interface->fTexParameteriv = glTexParameteriv;
         interface->fTexSubImage2D = glTexSubImage2D;