Make GrGLInterface a per-GrContext refcounted object rather than a global
authorbsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Fri, 19 Aug 2011 13:28:54 +0000 (13:28 +0000)
committerbsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Fri, 19 Aug 2011 13:28:54 +0000 (13:28 +0000)
Review URL: http://codereview.appspot.com/4901046/

git-svn-id: http://skia.googlecode.com/svn/trunk@2140 2bbb7eff-a529-9590-31e7-b0007b416f81

31 files changed:
gpu/include/GrGLConfig.h
gpu/include/GrGLInterface.h
gpu/include/GrTypes.h
gpu/src/GrGLDefaultInterface_none.cpp
gpu/src/GrGLIRect.h
gpu/src/GrGLIndexBuffer.cpp
gpu/src/GrGLInterface.cpp
gpu/src/GrGLProgram.cpp
gpu/src/GrGLProgram.h
gpu/src/GrGLRenderTarget.cpp
gpu/src/GrGLStencilBuffer.cpp [new file with mode: 0644]
gpu/src/GrGLStencilBuffer.h
gpu/src/GrGLTexture.cpp
gpu/src/GrGLTexture.h
gpu/src/GrGLUtil.cpp
gpu/src/GrGLVertexBuffer.cpp
gpu/src/GrGpuFactory.cpp
gpu/src/GrGpuGL.cpp
gpu/src/GrGpuGL.h
gpu/src/GrGpuGLFixed.cpp
gpu/src/GrGpuGLFixed.h
gpu/src/GrGpuGLShaders.cpp
gpu/src/GrGpuGLShaders.h
gpu/src/android/GrGLDefaultInterface_android.cpp
gpu/src/ios/GrGLDefaultInterface_iOS.cpp
gpu/src/mac/GrGLDefaultInterface_mac.cpp
gpu/src/mesa/GrGLDefaultInterface_mesa.cpp
gpu/src/unix/GrGLDefaultInterface_unix.cpp
gpu/src/win/GrGLDefaultInterface_win.cpp
gyp/gpu.gyp
samplecode/SampleApp.cpp

index dc0c63398e1cf99a87d90f67adafa3f07cda06be..2f60a658e10ea65f3cff175349289634f1e96466 100644 (file)
 
 ////////////////////////////////////////////////////////////////////////////////
 
-extern void GrGLCheckErr(const char* location, const char* call);
+struct GrGLInterface;
 
-extern void GrGLClearErr();
+extern void GrGLCheckErr(const GrGLInterface* gl,
+                         const char* location,
+                         const char* call);
+
+extern void GrGLClearErr(const GrGLInterface* gl);
 
 #if GR_GL_CHECK_ERROR
     extern bool gCheckErrorGL;
-    #define GR_GL_CHECK_ERROR_IMPL(X) if (gCheckErrorGL) GrGLCheckErr(GR_FILE_AND_LINE_STR, #X)
+    #define GR_GL_CHECK_ERROR_IMPL(IFACE, X)                    \
+        if (gCheckErrorGL)                                      \
+            GrGLCheckErr(IFACE, GR_FILE_AND_LINE_STR, #X)
 #else
-    #define GR_GL_CHECK_ERROR_IMPL(X)
+    #define GR_GL_CHECK_ERROR_IMPL(IFACE, X)
 #endif
 
 #if GR_GL_LOG_CALLS
     extern bool gLogCallsGL;
-    #define GR_GL_LOG_CALLS_IMPL(X) if (gLogCallsGL) GrPrintf(GR_FILE_AND_LINE_STR "GL: " #X "\n")
+    #define GR_GL_LOG_CALLS_IMPL(X)
+        if (gLogCallsGL)                                        \
+            GrPrintf(GR_FILE_AND_LINE_STR "GL: " #X "\n")
 #else
     #define GR_GL_LOG_CALLS_IMPL(X)
 #endif
 
-#define GR_GL(X)                 GrGLGetGLInterface()->f##X;; GR_GL_LOG_CALLS_IMPL(X); GR_GL_CHECK_ERROR_IMPL(X);
-#define GR_GL_NO_ERR(X)          GrGLGetGLInterface()->f##X;; GR_GL_LOG_CALLS_IMPL(X);
+#define GR_GL_CALL(IFACE, X)                                    \
+    GR_GL_CALL_NOERRCHECK(IFACE, X)                             \
+    GR_GL_CHECK_ERROR_IMPL(IFACE, X)
+
+#define GR_GL_CALL_NOERRCHECK(IFACE, X)                         \
+    IFACE->f##X;                                                \
+    GR_GL_LOG_CALLS_IMPL(X);
 
-#define GR_GL_SUPPORT_DESKTOP   (kDesktop_GrGLBinding == GrGLGetGLInterface()->fBindingsExported)
-#define GR_GL_SUPPORT_ES1       (kES1_GrGLBinding == GrGLGetGLInterface()->fBindingsExported)
-#define GR_GL_SUPPORT_ES2       (kES2_GrGLBinding == GrGLGetGLInterface()->fBindingsExported)
-#define GR_GL_SUPPORT_ES        (GR_GL_SUPPORT_ES1 || GR_GL_SUPPORT_ES2)
+#define GR_GL_GET_ERROR(IFACE) (IFACE)->fGetError()
 
 ////////////////////////////////////////////////////////////////////////////////
 
 /**
- *  GrGLRestoreResetRowLength() will reset GL_UNPACK_ROW_LENGTH to 0. We write
+ *  GrGLResetRowLength() will reset GL_UNPACK_ROW_LENGTH to 0. We write
  *  this wrapper, since GL_UNPACK_ROW_LENGTH is not available on all GL versions
  */
-extern void GrGLRestoreResetRowLength();
+extern void GrGLResetRowLength(const GrGLInterface*);
 
 ////////////////////////////////////////////////////////////////////////////////
 
@@ -189,28 +199,28 @@ extern void GrGLRestoreResetRowLength();
  *  Some drivers want the var-int arg to be zero-initialized on input.
  */
 #define GR_GL_INIT_ZERO     0
-#define GR_GL_GetIntegerv(e, p)     \
+#define GR_GL_GetIntegerv(gl, e, p)     \
     do {                            \
         *(p) = GR_GL_INIT_ZERO;     \
-        GR_GL(GetIntegerv(e, p));   \
+        GR_GL_CALL(gl, GetIntegerv(e, p));   \
     } while (0)
 
-#define GR_GL_GetFramebufferAttachmentParameteriv(t, a, pname, p)   \
-    do {                                                            \
-        *(p) = GR_GL_INIT_ZERO;                                     \
-        GR_GL(GetFramebufferAttachmentParameteriv(t, a, pname, p)); \
+#define GR_GL_GetFramebufferAttachmentParameteriv(gl, t, a, pname, p)           \
+    do {                                                                        \
+        *(p) = GR_GL_INIT_ZERO;                                                 \
+        GR_GL_CALL(gl, GetFramebufferAttachmentParameteriv(t, a, pname, p));    \
     } while (0)
 
-#define GR_GL_GetRenderbufferParameteriv(t, pname, p)    \
-    do {                                                 \
-        *(p) = GR_GL_INIT_ZERO;                          \
-        GR_GL(GetRenderbufferParameteriv(t, pname, p));  \
+#define GR_GL_GetRenderbufferParameteriv(gl, t, pname, p)                       \
+    do {                                                                        \
+        *(p) = GR_GL_INIT_ZERO;                                                 \
+        GR_GL_CALL(gl, GetRenderbufferParameteriv(t, pname, p));                \
     } while (0)
 
-#define GR_GL_GetTexLevelParameteriv(t, l, pname, p)    \
-    do {                                                \
-        *(p) = GR_GL_INIT_ZERO;                         \
-        GR_GL(GetTexLevelParameteriv(t, l, pname, p));  \
+#define GR_GL_GetTexLevelParameteriv(gl, t, l, pname, p)                        \
+    do {                                                                        \
+        *(p) = GR_GL_INIT_ZERO;                                                 \
+        GR_GL_CALL(gl, GetTexLevelParameteriv(t, l, pname, p));                 \
     } while (0)
 
 ////////////////////////////////////////////////////////////////////////////////
index 0e0c5666b10c95fe8c5d29ed6ae73662ba8cb391..e6f0b57010ceaf9217c27162c656acc6eb0d741e 100644 (file)
@@ -12,7 +12,7 @@
 #define GrGLInterface_DEFINED
 
 #include "GrGLConfig.h"
-#include "GrTypes.h"
+#include "GrRefCnt.h"
 
 #if !defined(GR_GL_FUNCTION_TYPE)
     #define GR_GL_FUNCTION_TYPE
@@ -32,28 +32,38 @@ bool has_gl_extension_from_string(const char* ext,
                                   const char* extensionString);
 
 // these variants call glGetString()
-bool has_gl_extension(const char* ext);
-void gl_version(int* major, int* minor);
-float gl_version_as_float();
+bool has_gl_extension(const GrGLInterface*, const char* ext);
+void gl_version(const GrGLInterface*, int* major, int* minor);
+float gl_version_as_float(const GrGLInterface*);
 
 ////////////////////////////////////////////////////////////////////////////////
 
-/*
- * Routines managing the global interface used to invoke OpenGL calls.
+/**
+ * Rather than depend on platform-specific GL headers and libraries, we require
+ * the client to provide a struct of GL function pointers. This struct can be
+ * specified per-GrContext as a parameter to GrContext::Create. If NULL is
+ * passed to Create then the "default" GL interface is used. If the default is
+ * also NULL GrContext creation will fail.
+ *
+ * The default interface is specified by calling GrGLSetDefaultInterface. If
+ * this function hasn't been called or was last called with NULL then
+ * GrGLInitializeDefaultGLInterface will be called to attempt to initialize it.
+ * There are several implementations of this function provided. Each builds a
+ * GrGLInterface for a specific platform and sets it as the default. There is
+ * also an implementation that does nothing. You can link in any of the provided
+ * implementations or your own implementation that sets up the GL function 
+ * pointers for your specific platform.
  */
+
 struct GrGLInterface;
-GR_API GrGLInterface* GrGLGetGLInterface();
-GR_API void GrGLSetGLInterface(GrGLInterface* gl_interface);
 
-/*
- * This is called when GrGLSetGLInterface() hasn't been called before creating
- * a GrGpuGL object. It provides a default implementation. The actual
- * implementation depends on which GrGLDefaultInterface_*.cpp has been linked.
- * There are some platform-specific implementations provided as well as
- * GrGLDefaultInterface_none.cpp which does nothing (effectively requiring an
- * explicit GrGLSetGLInterface call by the host).
- */
-void GrGLSetDefaultGLInterface();
+GR_API const GrGLInterface* GrGLGetDefaultGLInterface();
+// returns param so that you can unref it
+GR_API const GrGLInterface* GrGLSetDefaultGLInterface(const GrGLInterface* gl_interface);
+
+// If this is implemented it must allocate a GrGLInterface on the heap because
+// GrGLInterface subclasses SkRefCnt.
+void GrGLInitializeDefaultGLInterface();
 
 typedef unsigned int GrGLenum;
 typedef unsigned char GrGLboolean;
@@ -220,8 +230,24 @@ enum GrGLCapability {
  * functions, and extensions.  The system assumes that the address of the
  * extension pointer will be valid across contexts.
  */
-struct GrGLInterface {
+struct GR_API GrGLInterface : public GrRefCnt {
+
+    GrGLInterface();
+
     bool validate(GrEngine engine) const;
+    bool supportsDesktop() const {
+        return 0 != (kDesktop_GrGLBinding & fBindingsExported);
+    }
+    bool supportsES1() const {
+        return 0 != (kES1_GrGLBinding & fBindingsExported);
+    }
+    bool supportsES2() const {
+        return 0 !=  (kES2_GrGLBinding & fBindingsExported);
+    }
+    bool supportsES() const {
+        return 0 != ((kES1_GrGLBinding | kES2_GrGLBinding) &
+                        fBindingsExported);
+    }
 
     // Indicator variable specifying the type of GL implementation
     // exported:  GLES{1|2} or Desktop.
@@ -362,11 +388,6 @@ struct GrGLInterface {
     // Dual Source Blending
     GrGLBindFragDataLocationIndexedProc fBindFragDataLocationIndexed;
 
-    // Code that initializes this struct using a static initializer should
-    // make this the last entry in the static initializer. It can help to guard
-    // against failing to initialize newly-added members of this struct.
-    enum { kStaticInitEndGuard } fStaticInitEndGuard;
-
 private:
     bool validateShaderFunctions() const;
     bool validateFixedFunctions() const;
index 96dece082e56d2e1255bf8247086084f29fcfb0e..e9fb3e6a166ac38637166038093010eed7ad8003 100644 (file)
@@ -173,13 +173,11 @@ static inline int16_t GrToS16(intptr_t x) {
 enum GrEngine {
     kOpenGL_Shaders_GrEngine,
     kOpenGL_Fixed_GrEngine,
-    kDirect3D9_GrEngine
 };
 
 /**
  * Engine-specific 3D context handle
- *      Unused for GL.
- *      IDirect3DDevice9* for D3D9
+ *      GrGLInterface* for OpenGL. If NULL will use the default GL interface.
  */
 typedef intptr_t GrPlatform3DContext;
 
index 9b8e3f0531e3094de3d3c8a2c37887fffe321fdb..93789075c2e56264f09b7c8862026f5e95655850 100644 (file)
@@ -7,5 +7,5 @@
  */
 
 
-void GrGLSetDefaultGLInterface() {
+void GrGLInitializeDefaultGLInterface() {
 }
index 5e3dfa6d535a0c1ddf619f65c0413a28505051f5..e94fa21a5a78b10f3d055a38a2cddf6e9369a02c 100644 (file)
@@ -23,17 +23,17 @@ struct GrGLIRect {
     GrGLsizei fWidth;
     GrGLsizei fHeight;
 
-    void pushToGLViewport() const {
-        GR_GL(Viewport(fLeft, fBottom, fWidth, fHeight));
+    void pushToGLViewport(const GrGLInterface* gl) const {
+        GR_GL_CALL(gl, Viewport(fLeft, fBottom, fWidth, fHeight));
     }
 
-    void pushToGLScissor() const {
-        GR_GL(Scissor(fLeft, fBottom, fWidth, fHeight));
+    void pushToGLScissor(const GrGLInterface* gl) const {
+        GR_GL_CALL(gl, Scissor(fLeft, fBottom, fWidth, fHeight));
     }
 
-    void setFromGLViewport() {
+    void setFromGLViewport(const GrGLInterface* gl) {
         GR_STATIC_ASSERT(sizeof(GrGLIRect) == 4*sizeof(GrGLint));
-        GR_GL_GetIntegerv(GR_GL_VIEWPORT, (GrGLint*) this);
+        GR_GL_GetIntegerv(gl, GR_GL_VIEWPORT, (GrGLint*) this);
     }
 
     // sometimes we have a GrIRect from the client that we
index 3b34d63eea5e77a387afd2a04bd521f27358d87e..54ee78bc272752bd279c35b1c5c99da60c03f369 100644 (file)
@@ -13,6 +13,8 @@
 
 #define GPUGL static_cast<GrGpuGL*>(getGpu())
 
+#define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X)
+
 GrGLIndexBuffer::GrGLIndexBuffer(GrGpuGL* gpu,
                                  GrGLuint id,
                                  size_t sizeInBytes,
@@ -27,7 +29,7 @@ void GrGLIndexBuffer::onRelease() {
     // make sure we've not been abandoned
     if (fBufferID) {
         GPUGL->notifyIndexBufferDelete(this);
-        GR_GL(DeleteBuffers(1, &fBufferID));
+        GL_CALL(DeleteBuffers(1, &fBufferID));
         fBufferID = 0;
     }
 }
@@ -38,7 +40,7 @@ void GrGLIndexBuffer::onAbandon() {
 }
 
 void GrGLIndexBuffer::bind() const {
-    GR_GL(BindBuffer(GR_GL_ELEMENT_ARRAY_BUFFER, fBufferID));
+    GL_CALL(BindBuffer(GR_GL_ELEMENT_ARRAY_BUFFER, fBufferID));
     GPUGL->notifyIndexBufferBind(this);
 }
 
@@ -52,9 +54,13 @@ void* GrGLIndexBuffer::lock() {
     if (GPUGL->supportsBufferLocking()) {
         this->bind();
         // Let driver know it can discard the old data
-        GR_GL(BufferData(GR_GL_ELEMENT_ARRAY_BUFFER, this->sizeInBytes(), NULL,
-                         this->dynamic() ? GR_GL_DYNAMIC_DRAW : GR_GL_STATIC_DRAW));
-        fLockPtr = GR_GL(MapBuffer(GR_GL_ELEMENT_ARRAY_BUFFER, GR_GL_WRITE_ONLY));
+        GL_CALL(BufferData(GR_GL_ELEMENT_ARRAY_BUFFER,
+                           this->sizeInBytes(),
+                           NULL,
+                           this->dynamic() ? GR_GL_DYNAMIC_DRAW :
+                                             GR_GL_STATIC_DRAW));
+        fLockPtr = GL_CALL(MapBuffer(GR_GL_ELEMENT_ARRAY_BUFFER,
+                                     GR_GL_WRITE_ONLY));
 
         return fLockPtr;
     }
@@ -71,7 +77,7 @@ void GrGLIndexBuffer::unlock() {
     GrAssert(GPUGL->supportsBufferLocking());
 
     this->bind();
-    GR_GL(UnmapBuffer(GR_GL_ELEMENT_ARRAY_BUFFER));
+    GL_CALL(UnmapBuffer(GR_GL_ELEMENT_ARRAY_BUFFER));
     fLockPtr = NULL;
 }
 
@@ -80,8 +86,8 @@ bool GrGLIndexBuffer::isLocked() const {
     if (this->isValid() && GPUGL->supportsBufferLocking()) {
         this->bind();
         GrGLint mapped;
-        GR_GL(GetBufferParameteriv(GR_GL_ELEMENT_ARRAY_BUFFER,
-                                   GR_GL_BUFFER_MAPPED, &mapped));
+        GL_CALL(GetBufferParameteriv(GR_GL_ELEMENT_ARRAY_BUFFER,
+                                     GR_GL_BUFFER_MAPPED, &mapped));
         GrAssert(!!mapped == !!fLockPtr);
     }
 #endif
@@ -97,12 +103,15 @@ bool GrGLIndexBuffer::updateData(const void* src, size_t srcSizeInBytes) {
     this->bind();
     GrGLenum usage = dynamic() ? GR_GL_DYNAMIC_DRAW : GR_GL_STATIC_DRAW;
     if (this->sizeInBytes() == srcSizeInBytes) {
-        GR_GL(BufferData(GR_GL_ELEMENT_ARRAY_BUFFER, srcSizeInBytes, src, usage));
+        GL_CALL(BufferData(GR_GL_ELEMENT_ARRAY_BUFFER,
+                            srcSizeInBytes, src, usage));
     } else {
 #if GR_GL_USE_BUFFER_DATA_NULL_HINT
-        GR_GL(BufferData(GR_GL_ELEMENT_ARRAY_BUFFER, this->sizeInBytes(), NULL, usage));
+        GL_CALL(BufferData(GR_GL_ELEMENT_ARRAY_BUFFER,
+                           this->sizeInBytes(), NULL, usage));
 #endif
-        GR_GL(BufferSubData(GR_GL_ELEMENT_ARRAY_BUFFER, 0, srcSizeInBytes, src));
+        GL_CALL(BufferSubData(GR_GL_ELEMENT_ARRAY_BUFFER,
+                              0, srcSizeInBytes, src));
     }
     return true;
 }
@@ -116,7 +125,8 @@ bool GrGLIndexBuffer::updateSubData(const void* src,
         return false;
     }
     this->bind();
-    GR_GL(BufferSubData(GR_GL_ELEMENT_ARRAY_BUFFER, offset, srcSizeInBytes, src));
+    GL_CALL(BufferSubData(GR_GL_ELEMENT_ARRAY_BUFFER,
+                          offset, srcSizeInBytes, src));
     return true;
 }
 
index 2a8ffaaeb482274114aaf3bdc07afdedae460211..ec00f16dc45ef20f3411cb152d125ae4a6230f8b 100644 (file)
@@ -7,14 +7,13 @@
  */
 
 
-
 #include "GrTypes.h"
 #include "GrGLInterface.h"
 #include "GrGLDefines.h"
 
 #include <stdio.h>
 
-GrGLInterface* gGLInterface = NULL;
+static SkAutoTUnref<const GrGLInterface> gDefaultGLInterface;
 
 void gl_version_from_string(int* major, int* minor,
                             const char* versionString) {
@@ -84,33 +83,160 @@ bool has_gl_extension_from_string(const char* ext,
     return false;
 }
 
-GR_API void GrGLSetGLInterface(GrGLInterface* gl_interface) {
-    gGLInterface = gl_interface;
+GR_API const GrGLInterface* GrGLSetDefaultGLInterface(const GrGLInterface* gl_interface) {
+    gl_interface->ref();
+    gDefaultGLInterface.reset(gl_interface);
+    return gl_interface;
 }
 
-GR_API GrGLInterface* GrGLGetGLInterface() {
-    return gGLInterface;
+GR_API const GrGLInterface* GrGLGetDefaultGLInterface() {
+    if (NULL == gDefaultGLInterface.get()) {
+        GrGLInitializeDefaultGLInterface();
+    }
+    return gDefaultGLInterface.get();
 }
 
-bool has_gl_extension(const char* ext) {
+bool has_gl_extension(const GrGLInterface* gl, const char* ext) {
     const char* glstr = reinterpret_cast<const char*>(
-                GrGLGetGLInterface()->fGetString(GR_GL_EXTENSIONS));
+                gl->fGetString(GR_GL_EXTENSIONS));
 
     return has_gl_extension_from_string(ext, glstr);
 }
 
-void gl_version(int* major, int* minor) {
+void gl_version(const GrGLInterface* gl, int* major, int* minor) {
     const char* v = reinterpret_cast<const char*>(
-                GrGLGetGLInterface()->fGetString(GR_GL_VERSION));
+                gl->fGetString(GR_GL_VERSION));
     gl_version_from_string(major, minor, v);
 }
 
-float gl_version_as_float() {
+float gl_version_as_float(const GrGLInterface* gl) {
     const char* v = reinterpret_cast<const char*>(
-                GrGLGetGLInterface()->fGetString(GR_GL_VERSION));
+                gl->fGetString(GR_GL_VERSION));
     return gl_version_as_float_from_string(v);
 }
 
+GrGLInterface::GrGLInterface() {
+    fBindingsExported = (GrGLBinding)0;
+    fNPOTRenderTargetSupport = kProbe_GrGLCapability;
+    fMinRenderTargetHeight = kProbe_GrGLCapability;
+    fMinRenderTargetWidth = kProbe_GrGLCapability;
+
+    fActiveTexture = NULL;
+    fAttachShader = NULL;
+    fBindAttribLocation = NULL;
+    fBindBuffer = NULL;
+    fBindTexture = NULL;
+    fBlendColor = NULL;
+    fBlendFunc = NULL;
+    fBufferData = NULL;
+    fBufferSubData = NULL;
+    fClear = NULL;
+    fClearColor = NULL;
+    fClearStencil = NULL;
+    fClientActiveTexture = NULL;
+    fColor4ub = NULL;
+    fColorMask = NULL;
+    fColorPointer = NULL;
+    fCompileShader = NULL;
+    fCompressedTexImage2D = NULL;
+    fCreateProgram = NULL;
+    fCreateShader = NULL;
+    fCullFace = NULL;
+    fDeleteBuffers = NULL;
+    fDeleteProgram = NULL;
+    fDeleteShader = NULL;
+    fDeleteTextures = NULL;
+    fDepthMask = NULL;
+    fDisable = NULL;
+    fDisableClientState = NULL;
+    fDisableVertexAttribArray = NULL;
+    fDrawArrays = NULL;
+    fDrawBuffer = NULL;
+    fDrawBuffers = NULL;
+    fDrawElements = NULL;
+    fEnable = NULL;
+    fEnableClientState = NULL;
+    fEnableVertexAttribArray = NULL;
+    fFrontFace = NULL;
+    fGenBuffers = NULL;
+    fGenTextures = NULL;
+    fGetBufferParameteriv = NULL;
+    fGetError = NULL;
+    fGetIntegerv = NULL;
+    fGetProgramInfoLog = NULL;
+    fGetProgramiv = NULL;
+    fGetShaderInfoLog = NULL;
+    fGetShaderiv = NULL;
+    fGetString = NULL;
+    fGetTexLevelParameteriv = NULL;
+    fGetUniformLocation = NULL;
+    fLineWidth = NULL;
+    fLinkProgram = NULL;
+    fLoadMatrixf = NULL;
+    fMatrixMode = NULL;
+    fPixelStorei = NULL;
+    fPointSize = NULL;
+    fReadBuffer = NULL;
+    fReadPixels = NULL;
+    fScissor = NULL;
+    fShadeModel = NULL;
+    fShaderSource = NULL;
+    fStencilFunc = NULL;
+    fStencilFuncSeparate = NULL;
+    fStencilMask = NULL;
+    fStencilMaskSeparate = NULL;
+    fStencilOp = NULL;
+    fStencilOpSeparate = NULL;
+    fTexCoordPointer = NULL;
+    fTexEnvi = NULL;
+    fTexImage2D = NULL;
+    fTexParameteri = NULL;
+    fTexSubImage2D = NULL;
+    fUniform1f = NULL;
+    fUniform1i = NULL;
+    fUniform1fv = NULL;
+    fUniform1iv = NULL;
+    fUniform2f = NULL;
+    fUniform2i = NULL;
+    fUniform2fv = NULL;
+    fUniform2iv = NULL;
+    fUniform3f = NULL;
+    fUniform3i = NULL;
+    fUniform3fv = NULL;
+    fUniform3iv = NULL;
+    fUniform4f = NULL;
+    fUniform4i = NULL;
+    fUniform4fv = NULL;
+    fUniform4iv = NULL;
+    fUniformMatrix2fv = NULL;
+    fUniformMatrix3fv = NULL;
+    fUniformMatrix4fv = NULL;
+    fUseProgram = NULL;
+    fVertexAttrib4fv = NULL;
+    fVertexAttribPointer = NULL;
+    fVertexPointer = NULL;
+    fViewport = NULL;
+    fBindFramebuffer = NULL;
+    fBindRenderbuffer = NULL;
+    fCheckFramebufferStatus = NULL;
+    fDeleteFramebuffers = NULL;
+    fDeleteRenderbuffers = NULL;
+    fFramebufferRenderbuffer = NULL;
+    fFramebufferTexture2D = NULL;
+    fGenFramebuffers = NULL;
+    fGenRenderbuffers = NULL;
+    fGetFramebufferAttachmentParameteriv = NULL;
+    fGetRenderbufferParameteriv = NULL;
+    fRenderbufferStorage = NULL;
+    fRenderbufferStorageMultisample = NULL;
+    fBlitFramebuffer = NULL;
+    fResolveMultisampleFramebuffer = NULL;
+    fMapBuffer = NULL;
+    fUnmapBuffer = NULL;
+    fBindFragDataLocationIndexed = NULL;
+}
+
+
 bool GrGLInterface::validateShaderFunctions() const {
     // required for GrGpuGLShaders
     if (NULL == fAttachShader ||
@@ -176,13 +302,12 @@ bool GrGLInterface::validateFixedFunctions() const {
 
 bool GrGLInterface::validate(GrEngine engine) const {
 
-    bool isDesktop = kDesktop_GrGLBinding == fBindingsExported;
+    bool isDesktop = this->supportsDesktop();
 
-    // ES1 and 2 can be supported in the same interface
-    bool isES = ((kES1_GrGLBinding | kES2_GrGLBinding) & fBindingsExported &&
-                 !(~(kES1_GrGLBinding | kES2_GrGLBinding) & fBindingsExported));
+    bool isES = this->supportsES();
     
-    if (!isDesktop && !isES) {
+    if (isDesktop == isES) {
+        // must have one, don't support both in same interface
         return false;
     }
 
@@ -261,7 +386,7 @@ bool GrGLInterface::validate(GrEngine engine) const {
     int major, minor;
     const char* ext;
 
-    gl_version(&major, &minor);
+    gl_version(this, &major, &minor);
     ext = (const char*)fGetString(GR_GL_EXTENSIONS);
 
     // Now check that baseline ES/Desktop fns not covered above are present
index 4cdbe7c969c2196d99ec4bd4feac3d5582887802..ed3cd120f6a63a5599bff1bc7ec8e36aec3efe65 100644 (file)
 
 namespace {
 
-const char* GrPrecision() {
-    if (GR_GL_SUPPORT_ES2) {
+const char* GrPrecision(const GrGLInterface* gl) {
+    if (gl->supportsES()) {
         return "mediump";
     } else {
         return " ";
     }
 }
 
-const char* GrShaderPrecision() {
-    if (GR_GL_SUPPORT_ES2) {
+const char* GrShaderPrecision(const GrGLInterface* gl) {
+    if (gl->supportsES()) {
         return "precision mediump float;\n";
     } else {
         return "";
@@ -320,7 +320,8 @@ static void addColorFilter(GrStringBuilder* fsCode, const char * outputVar,
     add_helper(outputVar, colorStr.c_str(), constStr.c_str(), fsCode);
 }
 
-bool GrGLProgram::genProgram(GrGLProgram::CachedData* programData) const {
+bool GrGLProgram::genProgram(const GrGLInterface* gl, 
+                             GrGLProgram::CachedData* programData) const {
 
     ShaderCodeSegments segments;
     const uint32_t& layout = fProgramDesc.fVertexLayout;
@@ -438,7 +439,7 @@ bool GrGLProgram::genProgram(GrGLProgram::CachedData* programData) const {
                     inCoords = texCoordAttrs[tcIdx].c_str();
                 }
 
-                genStageCode(s,
+                genStageCode(gl, s,
                              fProgramDesc.fStages[s],
                              inColor.size() ? inColor.c_str() : NULL,
                              outColor.c_str(),
@@ -561,7 +562,7 @@ bool GrGLProgram::genProgram(GrGLProgram::CachedData* programData) const {
                     inCoords = texCoordAttrs[tcIdx].c_str();
                 }
 
-                genStageCode(s,
+                genStageCode(gl, s,
                              fProgramDesc.fStages[s],
                              inCoverage.size() ? inCoverage.c_str() : NULL,
                              outCoverage.c_str(),
@@ -619,23 +620,24 @@ bool GrGLProgram::genProgram(GrGLProgram::CachedData* programData) const {
     ///////////////////////////////////////////////////////////////////////////
     // compile and setup attribs and unis
 
-    if (!CompileFSAndVS(segments, programData)) {
+    if (!CompileFSAndVS(gl, segments, programData)) {
         return false;
     }
 
-    if (!this->bindOutputsAttribsAndLinkProgram(texCoordAttrs,
+    if (!this->bindOutputsAttribsAndLinkProgram(gl, texCoordAttrs,
                                                 usingDeclaredOutputs,
                                                 dualSourceOutputWritten,
                                                 programData)) {
         return false;
     }
 
-    this->getUniformLocationsAndInitCache(programData);
+    this->getUniformLocationsAndInitCache(gl, programData);
 
     return true;
 }
 
-bool GrGLProgram::CompileFSAndVS(const ShaderCodeSegments& segments,
+bool GrGLProgram::CompileFSAndVS(const GrGLInterface* gl,
+                                 const ShaderCodeSegments& segments,
                                  CachedData* programData) {
 
     static const int MAX_STRINGS = 6;
@@ -678,10 +680,8 @@ bool GrGLProgram::CompileFSAndVS(const ShaderCodeSegments& segments,
     GrPrintf("\n");
 #endif
     GrAssert(stringCnt <= MAX_STRINGS);
-    programData->fVShaderID = CompileShader(GR_GL_VERTEX_SHADER,
-                                        stringCnt,
-                                        strings,
-                                        lengths);
+    programData->fVShaderID = CompileShader(gl, GR_GL_VERTEX_SHADER,
+                                            stringCnt, strings, lengths);
 
     if (!programData->fVShaderID) {
         return false;
@@ -694,9 +694,9 @@ bool GrGLProgram::CompileFSAndVS(const ShaderCodeSegments& segments,
         lengths[stringCnt] = segments.fHeader.size();
         ++stringCnt;
     }
-    if (strlen(GrShaderPrecision()) > 1) {
-        strings[stringCnt] = GrShaderPrecision();
-        lengths[stringCnt] = strlen(GrShaderPrecision());
+    if (strlen(GrShaderPrecision(gl)) > 1) {
+        strings[stringCnt] = GrShaderPrecision(gl);
+        lengths[stringCnt] = strlen(GrShaderPrecision(gl));
         ++stringCnt;
     }
     if (segments.fFSUnis.size()) {
@@ -727,7 +727,7 @@ bool GrGLProgram::CompileFSAndVS(const ShaderCodeSegments& segments,
 
 #if PRINT_SHADERS
     GrPrintf(segments.fHeader.c_str());
-    GrPrintf(GrShaderPrecision());
+    GrPrintf(GrShaderPrecision(gl));
     GrPrintf(segments.fFSUnis.c_str());
     GrPrintf(segments.fVaryings.c_str());
     GrPrintf(segments.fFSOutputs.c_str());
@@ -736,10 +736,8 @@ bool GrGLProgram::CompileFSAndVS(const ShaderCodeSegments& segments,
     GrPrintf("\n");
 #endif
     GrAssert(stringCnt <= MAX_STRINGS);
-    programData->fFShaderID = CompileShader(GR_GL_FRAGMENT_SHADER,
-                                            stringCnt,
-                                            strings,
-                                            lengths);
+    programData->fFShaderID = CompileShader(gl, GR_GL_FRAGMENT_SHADER,
+                                            stringCnt, strings, lengths);
 
     if (!programData->fFShaderID) {
         return false;
@@ -748,29 +746,31 @@ bool GrGLProgram::CompileFSAndVS(const ShaderCodeSegments& segments,
     return true;
 }
 
-GrGLuint GrGLProgram::CompileShader(GrGLenum type,
-                                      int stringCnt,
-                                      const char** strings,
-                                      int* stringLengths) {
+GrGLuint GrGLProgram::CompileShader(const GrGLInterface* gl,
+                                    GrGLenum type,
+                                    int stringCnt,
+                                    const char** strings,
+                                    int* stringLengths) {
     SK_TRACE_EVENT1("GrGLProgram::CompileShader",
                     "stringCount", SkStringPrintf("%i", stringCnt).c_str());
 
-    GrGLuint shader = GR_GL(CreateShader(type));
+    GrGLuint shader = GR_GL_CALL(gl, CreateShader(type));
     if (0 == shader) {
         return 0;
     }
 
     GrGLint compiled = GR_GL_INIT_ZERO;
-    GR_GL(ShaderSource(shader, stringCnt, strings, stringLengths));
-    GR_GL(CompileShader(shader));
-    GR_GL(GetShaderiv(shader, GR_GL_COMPILE_STATUS, &compiled));
+    GR_GL_CALL(gl, ShaderSource(shader, stringCnt, strings, stringLengths));
+    GR_GL_CALL(gl, CompileShader(shader));
+    GR_GL_CALL(gl, GetShaderiv(shader, GR_GL_COMPILE_STATUS, &compiled));
 
     if (!compiled) {
         GrGLint infoLen = GR_GL_INIT_ZERO;
-        GR_GL(GetShaderiv(shader, GR_GL_INFO_LOG_LENGTH, &infoLen));
+        GR_GL_CALL(gl, GetShaderiv(shader, GR_GL_INFO_LOG_LENGTH, &infoLen));
         SkAutoMalloc log(sizeof(char)*(infoLen+1)); // outside if for debugger
         if (infoLen > 0) {
-            GR_GL(GetShaderInfoLog(shader, infoLen+1, NULL, (char*)log.get()));
+            GR_GL_CALL(gl, GetShaderInfoLog(shader, infoLen+1, 
+                                            NULL, (char*)log.get()));
             for (int i = 0; i < stringCnt; ++i) {
                 if (NULL == stringLengths || stringLengths[i] < 0) {
                     GrPrintf(strings[i]);
@@ -781,49 +781,51 @@ GrGLuint GrGLProgram::CompileShader(GrGLenum type,
             GrPrintf("\n%s", log.get());
         }
         GrAssert(!"Shader compilation failed!");
-        GR_GL(DeleteShader(shader));
+        GR_GL_CALL(gl, DeleteShader(shader));
         return 0;
     }
     return shader;
 }
 
 bool GrGLProgram::bindOutputsAttribsAndLinkProgram(
+                                        const GrGLInterface* gl,
                                         GrStringBuilder texCoordAttrNames[],
                                         bool bindColorOut,
                                         bool bindDualSrcOut,
                                         CachedData* programData) const {
-    programData->fProgramID = GR_GL(CreateProgram());
+    programData->fProgramID = GR_GL_CALL(gl, CreateProgram());
     if (!programData->fProgramID) {
         return false;
     }
     const GrGLint& progID = programData->fProgramID;
 
-    GR_GL(AttachShader(progID, programData->fVShaderID));
-    GR_GL(AttachShader(progID, programData->fFShaderID));
+    GR_GL_CALL(gl, AttachShader(progID, programData->fVShaderID));
+    GR_GL_CALL(gl, AttachShader(progID, programData->fFShaderID));
 
     if (bindColorOut) {
-        GR_GL(BindFragDataLocationIndexed(programData->fProgramID,
+        GR_GL_CALL(gl, BindFragDataLocationIndexed(programData->fProgramID,
                                           0, 0, declared_color_output_name()));
     }
     if (bindDualSrcOut) {
-        GR_GL(BindFragDataLocationIndexed(programData->fProgramID,
+        GR_GL_CALL(gl, BindFragDataLocationIndexed(programData->fProgramID,
                                           0, 1, dual_source_output_name()));
     }
 
     // Bind the attrib locations to same values for all shaders
-    GR_GL(BindAttribLocation(progID, PositionAttributeIdx(), POS_ATTR_NAME));
+    GR_GL_CALL(gl, BindAttribLocation(progID, PositionAttributeIdx(),
+                                      POS_ATTR_NAME));
     for (int t = 0; t < GrDrawTarget::kMaxTexCoords; ++t) {
         if (texCoordAttrNames[t].size()) {
-            GR_GL(BindAttribLocation(progID,
-                                     TexCoordAttributeIdx(t),
-                                     texCoordAttrNames[t].c_str()));
+            GR_GL_CALL(gl, BindAttribLocation(progID,
+                                              TexCoordAttributeIdx(t),
+                                              texCoordAttrNames[t].c_str()));
         }
     }
 
     if (kSetAsAttribute == programData->fUniLocations.fViewMatrixUni) {
-        GR_GL(BindAttribLocation(progID,
-                             ViewMatrixAttributeIdx(),
-                             VIEW_MATRIX_NAME));
+        GR_GL_CALL(gl, BindAttribLocation(progID,
+                                          ViewMatrixAttributeIdx(),
+                                          VIEW_MATRIX_NAME));
     }
 
     for (int s = 0; s < GrDrawTarget::kNumStages; ++s) {
@@ -831,59 +833,59 @@ bool GrGLProgram::bindOutputsAttribsAndLinkProgram(
         if (kSetAsAttribute == unis.fTextureMatrixUni) {
             GrStringBuilder matName;
             tex_matrix_name(s, &matName);
-            GR_GL(BindAttribLocation(progID,
-                                     TextureMatrixAttributeIdx(s),
-                                     matName.c_str()));
+            GR_GL_CALL(gl, BindAttribLocation(progID,
+                                              TextureMatrixAttributeIdx(s),
+                                              matName.c_str()));
         }
     }
 
-    GR_GL(BindAttribLocation(progID, ColorAttributeIdx(), COL_ATTR_NAME));
+    GR_GL_CALL(gl, BindAttribLocation(progID, ColorAttributeIdx(), 
+                                      COL_ATTR_NAME));
 
-    GR_GL(LinkProgram(progID));
+    GR_GL_CALL(gl, LinkProgram(progID));
 
     GrGLint linked = GR_GL_INIT_ZERO;
-    GR_GL(GetProgramiv(progID, GR_GL_LINK_STATUS, &linked));
+    GR_GL_CALL(gl, GetProgramiv(progID, GR_GL_LINK_STATUS, &linked));
     if (!linked) {
         GrGLint infoLen = GR_GL_INIT_ZERO;
-        GR_GL(GetProgramiv(progID, GR_GL_INFO_LOG_LENGTH, &infoLen));
+        GR_GL_CALL(gl, GetProgramiv(progID, GR_GL_INFO_LOG_LENGTH, &infoLen));
         SkAutoMalloc log(sizeof(char)*(infoLen+1));  // outside if for debugger
         if (infoLen > 0) {
-            GR_GL(GetProgramInfoLog(progID,
-                                    infoLen+1,
-                                    NULL,
-                                    (char*)log.get()));
+            GR_GL_CALL(gl, GetProgramInfoLog(progID, infoLen+1,
+                                             NULL, (char*)log.get()));
             GrPrintf((char*)log.get());
         }
         GrAssert(!"Error linking program");
-        GR_GL(DeleteProgram(progID));
+        GR_GL_CALL(gl, DeleteProgram(progID));
         programData->fProgramID = 0;
         return false;
     }
     return true;
 }
 
-void GrGLProgram::getUniformLocationsAndInitCache(CachedData* programData) const {
+void GrGLProgram::getUniformLocationsAndInitCache(const GrGLInterface* gl, 
+                                                  CachedData* programData) const {
     const GrGLint& progID = programData->fProgramID;
 
     if (kUseUniform == programData->fUniLocations.fViewMatrixUni) {
         programData->fUniLocations.fViewMatrixUni =
-                        GR_GL(GetUniformLocation(progID, VIEW_MATRIX_NAME));
+                GR_GL_CALL(gl, GetUniformLocation(progID, VIEW_MATRIX_NAME));
         GrAssert(kUnusedUniform != programData->fUniLocations.fViewMatrixUni);
     }
     if (kUseUniform == programData->fUniLocations.fColorUni) {
         programData->fUniLocations.fColorUni =
-                                GR_GL(GetUniformLocation(progID, COL_UNI_NAME));
+                    GR_GL_CALL(gl, GetUniformLocation(progID, COL_UNI_NAME));
         GrAssert(kUnusedUniform != programData->fUniLocations.fColorUni);
     }
     if (kUseUniform == programData->fUniLocations.fColorFilterUni) {
         programData->fUniLocations.fColorFilterUni =
-                        GR_GL(GetUniformLocation(progID, COL_FILTER_UNI_NAME));
+                GR_GL_CALL(gl, GetUniformLocation(progID, COL_FILTER_UNI_NAME));
         GrAssert(kUnusedUniform != programData->fUniLocations.fColorFilterUni);
     }
 
     if (kUseUniform == programData->fUniLocations.fEdgesUni) {
         programData->fUniLocations.fEdgesUni =
-            GR_GL(GetUniformLocation(progID, EDGES_UNI_NAME));
+            GR_GL_CALL(gl, GetUniformLocation(progID, EDGES_UNI_NAME));
         GrAssert(kUnusedUniform != programData->fUniLocations.fEdgesUni);
     } else {
         programData->fUniLocations.fEdgesUni = kUnusedUniform;
@@ -895,18 +897,17 @@ void GrGLProgram::getUniformLocationsAndInitCache(CachedData* programData) const
             if (kUseUniform == locations.fTextureMatrixUni) {
                 GrStringBuilder texMName;
                 tex_matrix_name(s, &texMName);
-                locations.fTextureMatrixUni = GR_GL(GetUniformLocation(
-                                                progID,
-                                                texMName.c_str()));
+                locations.fTextureMatrixUni = 
+                   GR_GL_CALL(gl, GetUniformLocation(progID, texMName.c_str()));
                 GrAssert(kUnusedUniform != locations.fTextureMatrixUni);
             }
 
             if (kUseUniform == locations.fSamplerUni) {
                 GrStringBuilder samplerName;
                 sampler_name(s, &samplerName);
-                locations.fSamplerUni = GR_GL(GetUniformLocation(
-                                                     progID,
-                                                     samplerName.c_str()));
+                locations.fSamplerUni =
+                    GR_GL_CALL(gl, GetUniformLocation(progID,
+                                                      samplerName.c_str()));
                 GrAssert(kUnusedUniform != locations.fSamplerUni);
             }
 
@@ -914,51 +915,50 @@ void GrGLProgram::getUniformLocationsAndInitCache(CachedData* programData) const
                 GrStringBuilder texelSizeName;
                 normalized_texel_size_name(s, &texelSizeName);
                 locations.fNormalizedTexelSizeUni =
-                   GR_GL(GetUniformLocation(progID, texelSizeName.c_str()));
+                   GR_GL_CALL(gl, GetUniformLocation(progID, 
+                              texelSizeName.c_str()));
                 GrAssert(kUnusedUniform != locations.fNormalizedTexelSizeUni);
             }
 
             if (kUseUniform == locations.fRadial2Uni) {
                 GrStringBuilder radial2ParamName;
                 radial2_param_name(s, &radial2ParamName);
-                locations.fRadial2Uni = GR_GL(GetUniformLocation(
-                                             progID,
-                                             radial2ParamName.c_str()));
+                locations.fRadial2Uni =
+                    GR_GL_CALL(gl, GetUniformLocation(progID,
+                                   radial2ParamName.c_str()));
                 GrAssert(kUnusedUniform != locations.fRadial2Uni);
             }
 
             if (kUseUniform == locations.fTexDomUni) {
                 GrStringBuilder texDomName;
                 tex_domain_name(s, &texDomName);
-                locations.fTexDomUni = GR_GL(GetUniformLocation(
-                                             progID,
-                                             texDomName.c_str()));
+                locations.fTexDomUni =
+                    GR_GL_CALL(gl, GetUniformLocation(progID,
+                                                      texDomName.c_str()));
                 GrAssert(kUnusedUniform != locations.fTexDomUni);
             }
 
             GrStringBuilder kernelName, imageIncrementName;
             convolve_param_names(s, &kernelName, &imageIncrementName);
             if (kUseUniform == locations.fKernelUni) {
-                locations.fKernelUni = GR_GL(GetUniformLocation(
-                                             progID,
-                                             kernelName.c_str()));
+                locations.fKernelUni = GR_GL_CALL(gl, GetUniformLocation(
+                                                  progID, kernelName.c_str()));
                 GrAssert(kUnusedUniform != locations.fKernelUni);
             }
 
             if (kUseUniform == locations.fImageIncrementUni) {
-                locations.fImageIncrementUni = GR_GL(GetUniformLocation(
-                                                     progID,
-                                                     imageIncrementName.c_str()));
+                locations.fImageIncrementUni = GR_GL_CALL(gl, GetUniformLocation(progID,
+                                                         imageIncrementName.c_str()));
                 GrAssert(kUnusedUniform != locations.fImageIncrementUni);
             }
         }
     }
-    GR_GL(UseProgram(progID));
+    GR_GL_CALL(gl, UseProgram(progID));
 
     // init sampler unis and set bogus values for state tracking
     for (int s = 0; s < GrDrawTarget::kNumStages; ++s) {
         if (kUnusedUniform != programData->fUniLocations.fStages[s].fSamplerUni) {
-            GR_GL(Uniform1i(programData->fUniLocations.fStages[s].fSamplerUni, s));
+            GR_GL_CALL(gl, Uniform1i(programData->fUniLocations.fStages[s].fSamplerUni, s));
         }
         programData->fTextureMatrices[s] = GrMatrix::InvalidMatrix();
         programData->fRadial2CenterX1[s] = GR_ScalarMax;
@@ -975,7 +975,8 @@ void GrGLProgram::getUniformLocationsAndInitCache(CachedData* programData) const
 // Stage code generation
 //============================================================================
 
-void GrGLProgram::genStageCode(int stageNum,
+void GrGLProgram::genStageCode(const GrGLInterface* gl,
+                               int stageNum,
                                const GrGLProgram::StageDesc& desc,
                                const char* fsInColor, // NULL means no incoming color
                                const char* fsOutColor,
@@ -1051,7 +1052,7 @@ void GrGLProgram::genStageCode(int stageNum,
         StageDesc::kRadial2GradientDegenerate_CoordMapping == desc.fCoordMapping) {
 
         segments->fVSUnis.appendf("uniform %s float %s[6];\n",
-                                  GrPrecision(), radial2ParamsName.c_str());
+                                  GrPrecision(gl), radial2ParamsName.c_str());
         segments->fFSUnis.appendf("uniform float %s[6];\n",
                                   radial2ParamsName.c_str());
         locations->fRadial2Uni = kUseUniform;
@@ -1077,7 +1078,7 @@ void GrGLProgram::genStageCode(int stageNum,
         segments->fFSUnis.appendf("uniform vec2 %s;\n",
                                   imageIncrementName.c_str());
         segments->fVSUnis.appendf("uniform %s vec2 %s;\n",
-                                  GrPrecision(),
+                                  GrPrecision(gl),
                                   imageIncrementName.c_str());
         locations->fKernelUni = kUseUniform;
         locations->fImageIncrementUni = kUseUniform;
index ffe9f00347b0c6791677b72f422f914a55e541a9..b89653fb81f766456671ac3b6ba30a5e4f04071d 100644 (file)
@@ -51,7 +51,8 @@ public:
      *  The result of heavy init is not stored in datamembers of GrGLProgam,
      *  but in a separate cacheable container.
      */
-    bool genProgram(CachedData* programData) const;
+    bool genProgram(const GrGLInterface* gl,
+                    CachedData* programData) const;
 
      /**
       * The shader may modify the blend coeffecients. Params are in/out
@@ -273,7 +274,8 @@ private:
 
     // should set all fields in locations var to kUseUniform if the
     // corresponding uniform is required for the program.
-    void genStageCode(int stageNum,
+    void genStageCode(const GrGLInterface* gl,
+                      int stageNum,
                       const ProgramDesc::StageDesc& desc,
                       const char* fsInColor, // NULL means no incoming color
                       const char* fsOutColor,
@@ -281,18 +283,21 @@ private:
                       ShaderCodeSegments* segments,
                       StageUniLocations* locations) const;
 
-    static bool CompileFSAndVS(const ShaderCodeSegments& segments, 
+    static bool CompileFSAndVS(const GrGLInterface* gl,
+                               const ShaderCodeSegments& segments, 
                                CachedData* programData);
 
     // Compiles a GL shader, returns shader ID or 0 if failed
     // params have same meaning as glShaderSource
-    static GrGLuint CompileShader(GrGLenum type, int stringCnt,
+    static GrGLuint CompileShader(const GrGLInterface* gl,
+                                  GrGLenum type, int stringCnt,
                                   const char** strings,
                                   int* stringLengths);
 
     // Creates a GL program ID, binds shader attributes to GL vertex attrs, and
     // links the program
     bool bindOutputsAttribsAndLinkProgram(
+                const GrGLInterface* gl,
                 GrStringBuilder texCoordAttrNames[GrDrawTarget::kMaxTexCoords],
                 bool bindColorOut,
                 bool bindDualSrcOut,
@@ -300,7 +305,8 @@ private:
 
     // Gets locations for all uniforms set to kUseUniform and initializes cache
     // to invalid values.
-    void getUniformLocationsAndInitCache(CachedData* programData) const;
+    void getUniformLocationsAndInitCache(const GrGLInterface* gl,
+                                         CachedData* programData) const;
 
     friend class GrGpuGLShaders;
 };
index ccfc55aaa3460fd571bf7c2d249e69cbf9d7bd72..290ae2e47d8973d3ce5526be2ee421fd6e03b02a 100644 (file)
@@ -13,6 +13,8 @@
 
 #define GPUGL static_cast<GrGpuGL*>(getGpu())
 
+#define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X)
+
 void GrGLRenderTarget::init(const Desc& desc,
                             const GrGLIRect& viewport,
                             GrGLTexID* texID) {
@@ -64,13 +66,13 @@ void GrGLRenderTarget::onRelease() {
     GPUGL->notifyRenderTargetDelete(this);
     if (fOwnIDs) {
         if (fTexFBOID) {
-            GR_GL(DeleteFramebuffers(1, &fTexFBOID));
+            GL_CALL(DeleteFramebuffers(1, &fTexFBOID));
         }
         if (fRTFBOID && fRTFBOID != fTexFBOID) {
-            GR_GL(DeleteFramebuffers(1, &fRTFBOID));
+            GL_CALL(DeleteFramebuffers(1, &fRTFBOID));
         }
         if (fMSColorRenderbufferID) {
-            GR_GL(DeleteRenderbuffers(1, &fMSColorRenderbufferID));
+            GL_CALL(DeleteRenderbuffers(1, &fMSColorRenderbufferID));
         }
     }
     fRTFBOID                = 0;
diff --git a/gpu/src/GrGLStencilBuffer.cpp b/gpu/src/GrGLStencilBuffer.cpp
new file mode 100644 (file)
index 0000000..bc0bb36
--- /dev/null
@@ -0,0 +1,40 @@
+
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+
+#include "GrGLStencilBuffer.h"
+#include "GrGpuGL.h"
+
+GrGLStencilBuffer::~GrGLStencilBuffer() {
+    this->release();
+}
+
+size_t GrGLStencilBuffer::sizeInBytes() const {
+    uint64_t size = this->width();
+    size *= this->height();
+    size *= fFormat.fTotalBits;
+    size *= GrMax(1,this->numSamples());
+    return static_cast<size_t>(size / 8);
+}
+
+void GrGLStencilBuffer::onRelease() {
+    if (0 != fRenderbufferID) {
+        GrGpuGL* gpuGL = (GrGpuGL*) this->getGpu();
+        const GrGLInterface* gl = gpuGL->glInterface();
+        GR_GL_CALL(gl, DeleteRenderbuffers(1, &fRenderbufferID));
+        fRenderbufferID = 0;
+    }
+    INHERITED::onRelease();
+}
+
+void GrGLStencilBuffer::onAbandon() {
+    fRenderbufferID = 0;
+    INHERITED::onAbandon();
+}
+
+
index caaca479d2df9180e83d7e84c60fa0993b3ff2eb..eaf79421185bbf9070cb0fe080bc8466b3e39855 100644 (file)
@@ -32,39 +32,20 @@ public:
         , fRenderbufferID(rbid) {
     }
 
-    virtual ~GrGLStencilBuffer() {
-        this->release();
-    }
+    virtual ~GrGLStencilBuffer();
 
-    virtual size_t sizeInBytes() const {
-        uint64_t size = this->width();
-        size *= this->height();
-        size *= fFormat.fTotalBits;
-        size *= GrMax(1,this->numSamples());
-        return (size_t)(size / 8);
-    }
+    virtual size_t sizeInBytes() const;
 
     GrGLuint renderbufferID() const {
         return fRenderbufferID;
     }
 
-    const Format& format() const {
-        return fFormat;
-    }
+    const Format& format() const { return fFormat; }
 
 protected:
-    virtual void onRelease() {
-        if (0 != fRenderbufferID) {
-            GR_GL(DeleteRenderbuffers(1, &fRenderbufferID));
-            fRenderbufferID = 0;
-        }
-        INHERITED::onRelease();
-    }
+    virtual void onRelease();
 
-    virtual void onAbandon() {
-        fRenderbufferID = 0;
-        INHERITED::onAbandon();
-    }
+    virtual void onAbandon();
 
 private:
     Format fFormat;
index 1dc9c1cb38ad3793a1159cbcf3ac8cad997dc039..be7a0f1b9184af177ba29438b7ec44fd685f3da4 100644 (file)
@@ -13,7 +13,9 @@
 
 #define GPUGL static_cast<GrGpuGL*>(getGpu())
 
-const GrGLenum* GrGLTexture::WrapMode2GLWrap() {
+#define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X)
+
+const GrGLenum* GrGLTexture::WrapMode2GLWrap(GrGLBinding binding) {
     static const GrGLenum mirrorRepeatModes[] = {
         GR_GL_CLAMP_TO_EDGE,
         GR_GL_REPEAT,
@@ -26,7 +28,7 @@ const GrGLenum* GrGLTexture::WrapMode2GLWrap() {
         GR_GL_REPEAT
     };
 
-    if (GR_GL_SUPPORT_ES1 && !GR_GL_SUPPORT_ES2) {
+    if (kES1_GrGLBinding == binding) {
         return repeatModes;  // GL_MIRRORED_REPEAT not supported.
     } else {
         return mirrorRepeatModes;
@@ -41,7 +43,8 @@ void GrGLTexture::init(GrGpuGL* gpu,
     GrAssert(0 != textureDesc.fTextureID);
 
     fTexParams          = initialTexParams;
-    fTexIDObj           = new GrGLTexID(textureDesc.fTextureID,
+    fTexIDObj           = new GrGLTexID(GPUGL->glInterface(),
+                                        textureDesc.fTextureID,
                                         textureDesc.fOwnsID);
     fUploadFormat       = textureDesc.fUploadFormat;
     fUploadByteCount    = textureDesc.fUploadByteCount;
@@ -132,10 +135,10 @@ void GrGLTexture::uploadTextureData(int x,
      */
     bool restoreGLRowLength = false;
     bool flipY = kBottomUp_Orientation == fOrientation;
-    if (GR_GL_SUPPORT_DESKTOP && !flipY) {
+    if (kDesktop_GrGLBinding == GPUGL->glBinding() && !flipY) {
         // can't use this for flipping, only non-neg values allowed. :(
         if (srcData && rowBytes) {
-            GR_GL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH,
+            GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH,
                               rowBytes / fUploadByteCount));
             restoreGLRowLength = true;
         }
@@ -166,14 +169,14 @@ void GrGLTexture::uploadTextureData(int x,
     if (flipY) {
         y = this->height() - (y + height);
     }
-    GR_GL(BindTexture(GR_GL_TEXTURE_2D, fTexIDObj->id()));
-    GR_GL(PixelStorei(GR_GL_UNPACK_ALIGNMENT, fUploadByteCount));
-    GR_GL(TexSubImage2D(GR_GL_TEXTURE_2D, 0, x, y, width, height,
-                        fUploadFormat, fUploadType, srcData));
+    GL_CALL(BindTexture(GR_GL_TEXTURE_2D, fTexIDObj->id()));
+    GL_CALL(PixelStorei(GR_GL_UNPACK_ALIGNMENT, fUploadByteCount));
+    GL_CALL(TexSubImage2D(GR_GL_TEXTURE_2D, 0, x, y, width, height,
+                          fUploadFormat, fUploadType, srcData));
 
-    if (GR_GL_SUPPORT_DESKTOP) {
+    if (kDesktop_GrGLBinding == GPUGL->glBinding()) {
         if (restoreGLRowLength) {
-            GR_GL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0));
+            GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0));
         }
     }
 }
index 6020928c1fa236ec9b6b1d477d1c7b51954b6063..b0dc368adf81f1560729de54c571aaa2a4a9b9c0 100644 (file)
 class GrGLTexID : public GrRefCnt {
 
 public:
-    GrGLTexID(GrGLuint texID, bool ownsID) : fTexID(texID), fOwnsID(ownsID) {}
+    GrGLTexID(const GrGLInterface* gl, GrGLuint texID, bool ownsID)
+        : fGL(gl)
+        , fTexID(texID)
+        , fOwnsID(ownsID) {
+    }
 
     virtual ~GrGLTexID() {
         if (0 != fTexID && fOwnsID) {
-            GR_GL(DeleteTextures(1, &fTexID));
+            GR_GL_CALL(fGL, DeleteTextures(1, &fTexID));
         }
     }
 
@@ -32,8 +36,9 @@ public:
     GrGLuint id() const { return fTexID; }
 
 private:
-    GrGLuint      fTexID;
-    bool          fOwnsID;
+    const GrGLInterface* fGL;
+    GrGLuint             fTexID;
+    bool                 fOwnsID;
 };
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -119,7 +124,7 @@ public:
     // and it is up to the GrGpuGL derivative to handle y-mirroing.
     Orientation orientation() const { return fOrientation; }
 
-    static const GrGLenum* WrapMode2GLWrap();
+    static const GrGLenum* WrapMode2GLWrap(GrGLBinding binding);
 
 protected:
 
index 5a57ac49a755db081a30f432e6e14089b3279486..5637cf3627f0cd12d9f7339ff1498fa08ba0508e 100644 (file)
 #include "GrGLConfig.h"
 #include "GrGLInterface.h"
 
-void GrGLClearErr() {
-    while (GR_GL_NO_ERROR != GrGLGetGLInterface()->fGetError()) {}
+void GrGLClearErr(const GrGLInterface* gl) {
+    while (GR_GL_NO_ERROR != gl->fGetError()) {}
 }
 
-void GrGLCheckErr(const char* location, const char* call) {
-    uint32_t err =  GrGLGetGLInterface()->fGetError();
+void GrGLCheckErr(const GrGLInterface* gl,
+                  const char* location,
+                  const char* call) {
+    uint32_t err = GR_GL_GET_ERROR(gl);
     if (GR_GL_NO_ERROR != err) {
-        GrPrintf("---- glGetError %x", err);
+        GrPrintf("---- glGetError %x", GR_GL_GET_ERROR(gl));
         if (NULL != location) {
             GrPrintf(" at\n\t%s", location);
         }
@@ -28,9 +30,9 @@ void GrGLCheckErr(const char* location, const char* call) {
     }
 }
 
-void GrGLRestoreResetRowLength() {
-    if (GR_GL_SUPPORT_DESKTOP) {
-        GR_GL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0));
+void GrGLResetRowLength(const GrGLInterface* gl) {
+    if (gl->supportsDesktop()) {
+        GR_GL_CALL(gl, PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0));
     }
 }
 
index 516852b94f01011e1aa080a3c028c70939bf47b5..c4c623886a852935883cc8a701fd1e7e8dffb4dc 100644 (file)
@@ -13,6 +13,8 @@
 
 #define GPUGL static_cast<GrGpuGL*>(getGpu())
 
+#define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X)
+
 GrGLVertexBuffer::GrGLVertexBuffer(GrGpuGL* gpu,
                                    GrGLuint id,
                                    size_t sizeInBytes,
@@ -26,7 +28,7 @@ void GrGLVertexBuffer::onRelease() {
     // make sure we've not been abandoned
     if (fBufferID) {
         GPUGL->notifyVertexBufferDelete(this);
-        GR_GL(DeleteBuffers(1, &fBufferID));
+        GL_CALL(DeleteBuffers(1, &fBufferID));
         fBufferID = 0;
     }
 }
@@ -37,7 +39,7 @@ void GrGLVertexBuffer::onAbandon() {
 }
 
 void GrGLVertexBuffer::bind() const {
-    GR_GL(BindBuffer(GR_GL_ARRAY_BUFFER, fBufferID));
+    GL_CALL(BindBuffer(GR_GL_ARRAY_BUFFER, fBufferID));
     GPUGL->notifyVertexBufferBind(this);
 }
 
@@ -51,9 +53,10 @@ void* GrGLVertexBuffer::lock() {
     if (GPUGL->supportsBufferLocking()) {
         this->bind();
         // Let driver know it can discard the old data
-        GR_GL(BufferData(GR_GL_ARRAY_BUFFER, this->sizeInBytes(), NULL,
-                         this->dynamic() ? GR_GL_DYNAMIC_DRAW : GR_GL_STATIC_DRAW));
-        fLockPtr = GR_GL(MapBuffer(GR_GL_ARRAY_BUFFER, GR_GL_WRITE_ONLY));
+        GL_CALL(BufferData(GR_GL_ARRAY_BUFFER, this->sizeInBytes(), NULL,
+                           this->dynamic() ? GR_GL_DYNAMIC_DRAW :
+                                             GR_GL_STATIC_DRAW));
+        fLockPtr = GL_CALL(MapBuffer(GR_GL_ARRAY_BUFFER, GR_GL_WRITE_ONLY));
         return fLockPtr;
     }
     return NULL;
@@ -70,7 +73,7 @@ void GrGLVertexBuffer::unlock() {
     GrAssert(GPUGL->supportsBufferLocking());
 
     this->bind();
-    GR_GL(UnmapBuffer(GR_GL_ARRAY_BUFFER));
+    GL_CALL(UnmapBuffer(GR_GL_ARRAY_BUFFER));
     fLockPtr = NULL;
 }
 
@@ -80,7 +83,8 @@ bool GrGLVertexBuffer::isLocked() const {
     if (this->isValid() && GPUGL->supportsBufferLocking()) {
         GrGLint mapped;
         this->bind();
-        GR_GL(GetBufferParameteriv(GR_GL_ARRAY_BUFFER, GR_GL_BUFFER_MAPPED, &mapped));
+        GL_CALL(GetBufferParameteriv(GR_GL_ARRAY_BUFFER, 
+                                     GR_GL_BUFFER_MAPPED, &mapped));
         GrAssert(!!mapped == !!fLockPtr);
     }
 #endif
@@ -96,12 +100,13 @@ bool GrGLVertexBuffer::updateData(const void* src, size_t srcSizeInBytes) {
     this->bind();
     GrGLenum usage = dynamic() ? GR_GL_DYNAMIC_DRAW : GR_GL_STATIC_DRAW;
     if (this->sizeInBytes() == srcSizeInBytes) {
-        GR_GL(BufferData(GR_GL_ARRAY_BUFFER, srcSizeInBytes, src, usage));
+        GL_CALL(BufferData(GR_GL_ARRAY_BUFFER, srcSizeInBytes, src, usage));
     } else {
 #if GR_GL_USE_BUFFER_DATA_NULL_HINT
-        GR_GL(BufferData(GR_GL_ARRAY_BUFFER, this->sizeInBytes(), NULL, usage));
+        GL_CALL(BufferData(GR_GL_ARRAY_BUFFER, 
+                           this->sizeInBytes(), NULL, usage));
 #endif
-        GR_GL(BufferSubData(GR_GL_ARRAY_BUFFER, 0, srcSizeInBytes, src));
+        GL_CALL(BufferSubData(GR_GL_ARRAY_BUFFER, 0, srcSizeInBytes, src));
     }
     return true;
 }
@@ -115,7 +120,7 @@ bool GrGLVertexBuffer::updateSubData(const void* src,
         return false;
     }
     this->bind();
-    GR_GL(BufferSubData(GR_GL_ARRAY_BUFFER, offset, srcSizeInBytes, src));
+    GL_CALL(BufferSubData(GR_GL_ARRAY_BUFFER, offset, srcSizeInBytes, src));
     return true;
 }
 
index e1205cd74c305d437a7c7da1d8826491bb875713..c3b0242f32c58add42e48eecdab0e14f24583900 100644 (file)
 
 GrGpu* GrGpu::Create(GrEngine engine, GrPlatform3DContext context3D) {
 
+    const GrGLInterface* glInterface;
+
     if (kOpenGL_Shaders_GrEngine == engine ||
         kOpenGL_Fixed_GrEngine == engine) {
-        // If no GL bindings have been installed, fall-back to calling the
-        // GL functions that have been linked with the executable.
-        if (!GrGLGetGLInterface()) {
-            GrGLSetDefaultGLInterface();
-            // If there is no platform-default then just fail.
-            if (!GrGLGetGLInterface()) {
-                return NULL;
-            }
+        glInterface = reinterpret_cast<const GrGLInterface*>(context3D);
+        if (NULL == glInterface) {
+            glInterface = GrGLGetDefaultGLInterface();
+        }
+        if (NULL == glInterface) {
+#if GR_DEBUG
+            GrPrintf("No GL interface provided!");
+#endif
+            return NULL;
         }
-        if (!GrGLGetGLInterface()->validate(engine)) {
+        if (!glInterface->validate(engine)) {
 #if GR_DEBUG
             GrPrintf("Failed GL interface validation!");
 #endif
@@ -45,24 +48,12 @@ GrGpu* GrGpu::Create(GrEngine engine, GrPlatform3DContext context3D) {
 
     switch (engine) {
         case kOpenGL_Shaders_GrEngine:
-            GrAssert(NULL == (void*)context3D);
-            {
-#if 0 // old code path, will be removed soon
-                gpu = new GrGpuGLShaders2;
-#else
-                gpu = new GrGpuGLShaders;
-#endif
-            }
+            GrAssert(NULL != glInterface);
+            gpu = new GrGpuGLShaders(glInterface);
             break;
         case kOpenGL_Fixed_GrEngine:
-            GrAssert(NULL == (void*)context3D);
-            gpu = new GrGpuGLFixed;
-            break;
-        case kDirect3D9_GrEngine:
-            GrAssert(NULL != (void*)context3D);
-#if GR_WIN32_BUILD
-//            gpu = new GrGpuD3D9((IDirect3DDevice9*)context3D);
-#endif
+            GrAssert(NULL != glInterface);
+            gpu = new GrGpuGLFixed(glInterface);
             break;
         default:
             GrAssert(!"unknown engine");
index 692df0eef72eb50a8c90fc1fb8f163dd0106e91d..35e918b78c3ce6235d8f5eb6febb5bf0e5ac53aa 100644 (file)
@@ -15,6 +15,8 @@
 static const GrGLuint GR_MAX_GLUINT = ~0;
 static const GrGLint  GR_INVAL_GLINT = ~0;
 
+#define GL_CALL(X) GR_GL_CALL(this->glInterface(), X)
+
 // we use a spare texture unit to avoid
 // mucking with the state of any of the stages.
 static const int SPARE_TEX_UNIT = GrGpuGL::kNumStages;
@@ -150,40 +152,44 @@ bool GrGpuGL::TextureMatrixIsIdentity(const GrGLTexture* texture,
 
 static bool gPrintStartupSpew;
 
-static bool fbo_test(int w, int h) {
+static bool fbo_test(const GrGLInterface* gl, int w, int h) {
 
     GrGLint savedFBO;
     GrGLint savedTexUnit;
-    GR_GL_GetIntegerv(GR_GL_ACTIVE_TEXTURE, &savedTexUnit);
-    GR_GL_GetIntegerv(GR_GL_FRAMEBUFFER_BINDING, &savedFBO);
+    GR_GL_GetIntegerv(gl, GR_GL_ACTIVE_TEXTURE, &savedTexUnit);
+    GR_GL_GetIntegerv(gl, GR_GL_FRAMEBUFFER_BINDING, &savedFBO);
 
-    GR_GL(ActiveTexture(GR_GL_TEXTURE0 + SPARE_TEX_UNIT));
+    GR_GL_CALL(gl, ActiveTexture(GR_GL_TEXTURE0 + SPARE_TEX_UNIT));
 
     GrGLuint testFBO;
-    GR_GL(GenFramebuffers(1, &testFBO));
-    GR_GL(BindFramebuffer(GR_GL_FRAMEBUFFER, testFBO));
+    GR_GL_CALL(gl, GenFramebuffers(1, &testFBO));
+    GR_GL_CALL(gl, BindFramebuffer(GR_GL_FRAMEBUFFER, testFBO));
     GrGLuint testRTTex;
-    GR_GL(GenTextures(1, &testRTTex));
-    GR_GL(BindTexture(GR_GL_TEXTURE_2D, testRTTex));
+    GR_GL_CALL(gl, GenTextures(1, &testRTTex));
+    GR_GL_CALL(gl, BindTexture(GR_GL_TEXTURE_2D, testRTTex));
     // some implementations require texture to be mip-map complete before
     // FBO with level 0 bound as color attachment will be framebuffer complete.
-    GR_GL(TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_MIN_FILTER, GR_GL_NEAREST));
-    GR_GL(TexImage2D(GR_GL_TEXTURE_2D, 0, GR_GL_RGBA, w, h,
-                     0, GR_GL_RGBA, GR_GL_UNSIGNED_BYTE, NULL));
-    GR_GL(BindTexture(GR_GL_TEXTURE_2D, 0));
-    GR_GL(FramebufferTexture2D(GR_GL_FRAMEBUFFER, GR_GL_COLOR_ATTACHMENT0,
-                               GR_GL_TEXTURE_2D, testRTTex, 0));
-    GrGLenum status = GR_GL(CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
-    GR_GL(DeleteFramebuffers(1, &testFBO));
-    GR_GL(DeleteTextures(1, &testRTTex));
-
-    GR_GL(ActiveTexture(savedTexUnit));
-    GR_GL(BindFramebuffer(GR_GL_FRAMEBUFFER, savedFBO));
+    GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, 
+                                 GR_GL_TEXTURE_MIN_FILTER,
+                                 GR_GL_NEAREST));
+    GR_GL_CALL(gl, TexImage2D(GR_GL_TEXTURE_2D, 0, GR_GL_RGBA, w, h,
+                              0, GR_GL_RGBA, GR_GL_UNSIGNED_BYTE, NULL));
+    GR_GL_CALL(gl, BindTexture(GR_GL_TEXTURE_2D, 0));
+    GR_GL_CALL(gl, FramebufferTexture2D(GR_GL_FRAMEBUFFER,
+                                        GR_GL_COLOR_ATTACHMENT0,
+                                        GR_GL_TEXTURE_2D, testRTTex, 0));
+    GrGLenum status = GR_GL_CALL(gl, CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
+    GR_GL_CALL(gl, DeleteFramebuffers(1, &testFBO));
+    GR_GL_CALL(gl, DeleteTextures(1, &testRTTex));
+
+    GR_GL_CALL(gl, ActiveTexture(savedTexUnit));
+    GR_GL_CALL(gl, BindFramebuffer(GR_GL_FRAMEBUFFER, savedFBO));
 
     return status == GR_GL_FRAMEBUFFER_COMPLETE;
 }
 
-static bool probe_for_npot_render_target_support(bool hasNPOTTextureSupport) {
+static bool probe_for_npot_render_target_support(const GrGLInterface* gl,
+                                                 bool hasNPOTTextureSupport) {
 
     /* Experimentation has found that some GLs that support NPOT textures
        do not support FBOs with a NPOT texture. They report "unsupported" FBO
@@ -193,12 +199,13 @@ static bool probe_for_npot_render_target_support(bool hasNPOTTextureSupport) {
        internally to the next POT.
      */
     if (hasNPOTTextureSupport) {
-        return fbo_test(200, 200);
+        return fbo_test(gl, 200, 200);
     }
     return false;
 }
 
-static int probe_for_min_render_target_height(bool hasNPOTRenderTargetSupport,
+static int probe_for_min_render_target_height(const GrGLInterface* gl,
+                                              bool hasNPOTRenderTargetSupport,
                                               int maxRenderTargetSize) {
     /* The iPhone 4 has a restriction that for an FBO with texture color
        attachment with height <= 8 then the width must be <= height. Here
@@ -211,7 +218,7 @@ static int probe_for_min_render_target_height(bool hasNPOTRenderTargetSupport,
     for (GrGLuint i = 1; i <= 256; hasNPOTRenderTargetSupport ? ++i : i *= 2) {
         GrGLuint w = maxRenderTargetSize;
         GrGLuint h = i;
-        if (fbo_test(w, h)) {
+        if (fbo_test(gl, w, h)) {
             if (gPrintStartupSpew) {
                 GrPrintf("\t[%d, %d]: PASSED\n", w, h);
             }
@@ -228,8 +235,9 @@ static int probe_for_min_render_target_height(bool hasNPOTRenderTargetSupport,
     return minRenderTargetHeight;
 }
 
-static int probe_for_min_render_target_width(bool hasNPOTRenderTargetSupport,
-                                              int maxRenderTargetSize) {
+static int probe_for_min_render_target_width(const GrGLInterface* gl,
+                                             bool hasNPOTRenderTargetSupport,
+                                             int maxRenderTargetSize) {
 
     if (gPrintStartupSpew) {
         GrPrintf("Small width FBO texture experiments\n");
@@ -238,7 +246,7 @@ static int probe_for_min_render_target_width(bool hasNPOTRenderTargetSupport,
     for (GrGLuint i = 1; i <= 256; hasNPOTRenderTargetSupport ? i *= 2 : ++i) {
         GrGLuint w = i;
         GrGLuint h = maxRenderTargetSize;
-        if (fbo_test(w, h)) {
+        if (fbo_test(gl, w, h)) {
             if (gPrintStartupSpew) {
                 GrPrintf("\t[%d, %d]: PASSED\n", w, h);
             }
@@ -256,26 +264,43 @@ static int probe_for_min_render_target_width(bool hasNPOTRenderTargetSupport,
 }
 
 
-GrGpuGL::GrGpuGL() 
+GrGpuGL::GrGpuGL(const GrGLInterface* gl, GrGLBinding glBinding
     : fStencilFormats(8) {
 
-    GrGLClearErr();
+    gl->ref();
+    fGL = gl;
+    fGLBinding = glBinding;
+    switch (glBinding) {
+        case kDesktop_GrGLBinding:
+            GrAssert(gl->supportsDesktop());
+            break;
+        case kES1_GrGLBinding:
+            GrAssert(gl->supportsES1());
+            break;
+        case kES2_GrGLBinding:
+            GrAssert(gl->supportsES2());
+            break;
+        default:
+            GrCrash("Expect exactly one valid GL binding bit to be in use.");
+    }
+
+    GrGLClearErr(fGL);
 
     if (gPrintStartupSpew) {
+        const GrGLubyte* vendor = GL_CALL(GetString(GR_GL_VENDOR));
+        const GrGLubyte* renderer = GL_CALL(GetString(GR_GL_RENDERER));
+        const GrGLubyte* version = GL_CALL(GetString(GR_GL_VERSION));
+        const GrGLubyte* ext = GL_CALL(GetString(GR_GL_EXTENSIONS));
         GrPrintf("------------------------- create GrGpuGL %p --------------\n",
                  this);
-        GrPrintf("------ VENDOR %s\n",
-                 GrGLGetGLInterface()->fGetString(GR_GL_VENDOR));
-        GrPrintf("------ RENDERER %s\n",
-                 GrGLGetGLInterface()->fGetString(GR_GL_RENDERER));
-        GrPrintf("------ VERSION %s\n",
-                 GrGLGetGLInterface()->fGetString(GR_GL_VERSION));
-        GrPrintf("------ EXTENSIONS\n %s \n",
-                 GrGLGetGLInterface()->fGetString(GR_GL_EXTENSIONS));
+        GrPrintf("------ VENDOR %s\n", vendor);
+        GrPrintf("------ RENDERER %s\n", renderer);
+        GrPrintf("------ VERSION %s\n",  version);
+        GrPrintf("------ EXTENSIONS\n %s \n", ext);
     }
 
-    fGLVersion = gl_version_as_float();
-    fExtensionString = (const char*) GR_GL(GetString(GR_GL_EXTENSIONS));
+    fGLVersion = gl_version_as_float(gl);
+    fExtensionString = (const char*) GL_CALL(GetString(GR_GL_EXTENSIONS));
 
     this->resetDirtyFlags();
 
@@ -283,20 +308,20 @@ GrGpuGL::GrGpuGL()
     // check FS and fixed-function texture unit limits
     // we only use textures in the fragment stage currently.
     // checks are > to make sure we have a spare unit.
-    if (GR_GL_SUPPORT_DESKTOP || GR_GL_SUPPORT_ES2) {
-        GR_GL_GetIntegerv(GR_GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
+    if (kES1_GrGLBinding != this->glBinding()) {
+        GR_GL_GetIntegerv(gl, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
         GrAssert(maxTextureUnits > kNumStages);
     }
-    if (GR_GL_SUPPORT_DESKTOP || GR_GL_SUPPORT_ES1) {
-        GR_GL_GetIntegerv(GR_GL_MAX_TEXTURE_UNITS, &maxTextureUnits);
+    if (kES2_GrGLBinding != this->glBinding()) {
+        GR_GL_GetIntegerv(gl, GR_GL_MAX_TEXTURE_UNITS, &maxTextureUnits);
         GrAssert(maxTextureUnits > kNumStages);
     }
-    if (GR_GL_SUPPORT_ES2) {
-        GR_GL_GetIntegerv(GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
+    if (kES2_GrGLBinding == this->glBinding()) {
+        GR_GL_GetIntegerv(gl, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
                           &fMaxFragmentUniformVectors);
-    } else if (GR_GL_SUPPORT_DESKTOP) {
+    } else if (kDesktop_GrGLBinding != this->glBinding()) {
         GrGLint max;
-        GR_GL_GetIntegerv(GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
+        GR_GL_GetIntegerv(gl, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
         fMaxFragmentUniformVectors = max / 4;
     } else {
         fMaxFragmentUniformVectors = 16;
@@ -308,9 +333,9 @@ GrGpuGL::GrGpuGL()
     this->setupStencilFormats();
 
     GrGLint numFormats;
-    GR_GL_GetIntegerv(GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
+    GR_GL_GetIntegerv(gl, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
     SkAutoSTMalloc<10, GrGLint> formats(numFormats);
-    GR_GL_GetIntegerv(GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
+    GR_GL_GetIntegerv(gl, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
     for (int i = 0; i < numFormats; ++i) {
         if (formats[i] == GR_GL_PALETTE8_RGBA8) {
             f8bitPaletteSupport = true;
@@ -329,7 +354,7 @@ GrGpuGL::GrGpuGL()
 
     memset(fAASamples, 0, sizeof(fAASamples));
     fMSFBOType = kNone_MSFBO;
-    if (GR_GL_SUPPORT_ES) {
+    if (kDesktop_GrGLBinding != this->glBinding()) {
        if (this->hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
            // chrome's extension is equivalent to the EXT msaa
            // and fbo_blit extensions.
@@ -338,7 +363,6 @@ GrGpuGL::GrGpuGL()
             fMSFBOType = kAppleES_MSFBO;
         }
     } else {
-        GrAssert(GR_GL_SUPPORT_DESKTOP);
         if ((fGLVersion >= 3.f) || this->hasExtension("GL_ARB_framebuffer_object")) {
             fMSFBOType = kDesktopARB_MSFBO;
         } else if (this->hasExtension("GL_EXT_framebuffer_multisample") &&
@@ -365,7 +389,7 @@ GrGpuGL::GrGpuGL()
 
     if (kNone_MSFBO != fMSFBOType) {
         GrGLint maxSamples;
-        GR_GL_GetIntegerv(GR_GL_MAX_SAMPLES, &maxSamples);
+        GR_GL_GetIntegerv(gl, GR_GL_MAX_SAMPLES, &maxSamples);
         if (maxSamples > 1 ) {
             fAASamples[kNone_GrAALevel] = 0;
             fAASamples[kLow_GrAALevel] = GrMax(2,
@@ -382,7 +406,7 @@ GrGpuGL::GrGpuGL()
     }
     fFSAASupport = fAASamples[kHigh_GrAALevel] > 0;
 
-    if (GR_GL_SUPPORT_DESKTOP) {
+    if (kDesktop_GrGLBinding == this->glBinding()) {
         fHasStencilWrap = (fGLVersion >= 1.4f) ||
                           this->hasExtension("GL_EXT_stencil_wrap");
     } else {
@@ -392,7 +416,7 @@ GrGpuGL::GrGpuGL()
         GrPrintf("Stencil Wrap: %s\n", (fHasStencilWrap ? "YES" : "NO"));
     }
 
-    if (GR_GL_SUPPORT_DESKTOP) {
+    if (kDesktop_GrGLBinding == this->glBinding()) {
         // we could also look for GL_ATI_separate_stencil extension or
         // GL_EXT_stencil_two_side but they use different function signatures
         // than GL2.0+ (and than each other).
@@ -414,7 +438,7 @@ GrGpuGL::GrGpuGL()
                 (fStencilWrapOpsSupport ? "YES" : "NO"));
     }
 
-    if (GR_GL_SUPPORT_DESKTOP) {
+    if (kDesktop_GrGLBinding == this->glBinding()) {
         fRGBA8Renderbuffer = true;
     } else {
         fRGBA8Renderbuffer = this->hasExtension("GL_OES_rgb8_rgba8");
@@ -424,13 +448,13 @@ GrGpuGL::GrGpuGL()
     }
 
 
-    if (GR_GL_SUPPORT_ES) {
+    if (kDesktop_GrGLBinding != this->glBinding()) {
         if (GR_GL_32BPP_COLOR_FORMAT == GR_GL_BGRA) {
             GrAssert(this->hasExtension("GL_EXT_texture_format_BGRA8888"));
         }
     }
 
-    if (GR_GL_SUPPORT_DESKTOP) {
+    if (kDesktop_GrGLBinding == this->glBinding()) {
         fBufferLockSupport = true; // we require VBO support and the desktop VBO
                                    // extension includes glMapBuffer.
     } else {
@@ -441,7 +465,7 @@ GrGpuGL::GrGpuGL()
         GrPrintf("Map Buffer: %s\n", (fBufferLockSupport ? "YES" : "NO"));
     }
 
-    if (GR_GL_SUPPORT_DESKTOP) {
+    if (kDesktop_GrGLBinding == this->glBinding()) {
         if (fGLVersion >= 2.f || 
             this->hasExtension("GL_ARB_texture_non_power_of_two")) {
             fNPOTTextureTileSupport = true;
@@ -461,17 +485,17 @@ GrGpuGL::GrGpuGL()
         }
     }
 
-    fAALineSupport = GR_GL_SUPPORT_DESKTOP;
+    fAALineSupport = (kDesktop_GrGLBinding == this->glBinding());
 
     ////////////////////////////////////////////////////////////////////////////
     // Experiments to determine limitations that can't be queried.
     // TODO: Make these a preprocess that generate some compile time constants.
     // TODO: probe once at startup, rather than once per context creation.
 
-    int expectNPOTTargets = GrGLGetGLInterface()->fNPOTRenderTargetSupport;
+    int expectNPOTTargets = gl->fNPOTRenderTargetSupport;
     if (expectNPOTTargets == kProbe_GrGLCapability) {
         fNPOTRenderTargetSupport =
-            probe_for_npot_render_target_support(fNPOTTextureSupport);
+            probe_for_npot_render_target_support(gl, fNPOTTextureSupport);
     } else {
         GrAssert(expectNPOTTargets == 0 || expectNPOTTargets == 1);
         fNPOTRenderTargetSupport = static_cast<bool>(expectNPOTTargets);
@@ -495,23 +519,23 @@ GrGpuGL::GrGpuGL()
         }
     }
 
-    GR_GL_GetIntegerv(GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
-    GR_GL_GetIntegerv(GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
+    GR_GL_GetIntegerv(gl, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
+    GR_GL_GetIntegerv(gl, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
     // Our render targets are always created with textures as the color
     // attachment, hence this min:
     fMaxRenderTargetSize = GrMin(fMaxTextureSize, fMaxRenderTargetSize);
 
-    fMinRenderTargetHeight = GrGLGetGLInterface()->fMinRenderTargetHeight;
+    fMinRenderTargetHeight = gl->fMinRenderTargetHeight;
     if (fMinRenderTargetHeight == kProbe_GrGLCapability) {
         fMinRenderTargetHeight =
-            probe_for_min_render_target_height(fNPOTRenderTargetSupport,
+            probe_for_min_render_target_height(gl,fNPOTRenderTargetSupport,
                                                fMaxRenderTargetSize);
     }
 
-    fMinRenderTargetWidth = GrGLGetGLInterface()->fMinRenderTargetWidth;
+    fMinRenderTargetWidth = gl->fMinRenderTargetWidth;
     if (fMinRenderTargetWidth == kProbe_GrGLCapability) {
         fMinRenderTargetWidth =
-            probe_for_min_render_target_width(fNPOTRenderTargetSupport,
+            probe_for_min_render_target_width(gl, fNPOTRenderTargetSupport,
                                               fMaxRenderTargetSize);
     }
 
@@ -519,35 +543,36 @@ GrGpuGL::GrGpuGL()
 }
 
 GrGpuGL::~GrGpuGL() {
+    fGL->unref();
 }
 
 void GrGpuGL::resetContext() {
     // We detect cases when blending is effectively off
     fHWBlendDisabled = false;
-    GR_GL(Enable(GR_GL_BLEND));
+    GL_CALL(Enable(GR_GL_BLEND));
 
     // we don't use the zb at all
-    GR_GL(Disable(GR_GL_DEPTH_TEST));
-    GR_GL(DepthMask(GR_GL_FALSE));
+    GL_CALL(Disable(GR_GL_DEPTH_TEST));
+    GL_CALL(DepthMask(GR_GL_FALSE));
 
-    GR_GL(Disable(GR_GL_CULL_FACE));
-    GR_GL(FrontFace(GR_GL_CCW));
+    GL_CALL(Disable(GR_GL_CULL_FACE));
+    GL_CALL(FrontFace(GR_GL_CCW));
     fHWDrawState.fDrawFace = kBoth_DrawFace;
 
-    GR_GL(Disable(GR_GL_DITHER));
-    if (GR_GL_SUPPORT_DESKTOP) {
-        GR_GL(Disable(GR_GL_LINE_SMOOTH));
-        GR_GL(Disable(GR_GL_POINT_SMOOTH));
-        GR_GL(Disable(GR_GL_MULTISAMPLE));
+    GL_CALL(Disable(GR_GL_DITHER));
+    if (kDesktop_GrGLBinding == this->glBinding()) {
+        GL_CALL(Disable(GR_GL_LINE_SMOOTH));
+        GL_CALL(Disable(GR_GL_POINT_SMOOTH));
+        GL_CALL(Disable(GR_GL_MULTISAMPLE));
         fHWAAState.fMSAAEnabled = false;
         fHWAAState.fSmoothLineEnabled = false;
     }
 
-    GR_GL(ColorMask(GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE));
+    GL_CALL(ColorMask(GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE));
     fHWDrawState.fFlagBits = 0;
 
     // we only ever use lines in hairline mode
-    GR_GL(LineWidth(1));
+    GL_CALL(LineWidth(1));
 
     // invalid
     fActiveTextureUnitIdx = -1;
@@ -557,7 +582,7 @@ void GrGpuGL::resetContext() {
     fHWDrawState.fDstBlend = (GrBlendCoeff)-1;
 
     fHWDrawState.fBlendConstant = 0x00000000;
-    GR_GL(BlendColor(0,0,0,0));
+    GL_CALL(BlendColor(0,0,0,0));
 
     fHWDrawState.fColor = GrColor_ILLEGAL;
 
@@ -574,7 +599,7 @@ void GrGpuGL::resetContext() {
 
     fHWBounds.fScissorRect.invalidate();
     fHWBounds.fScissorEnabled = false;
-    GR_GL(Disable(GR_GL_SCISSOR_TEST));
+    GL_CALL(Disable(GR_GL_SCISSOR_TEST));
     fHWBounds.fViewportRect.invalidate();
 
     fHWDrawState.fStencilSettings.invalidate();
@@ -586,7 +611,7 @@ void GrGpuGL::resetContext() {
     
     fHWGeometryState.fArrayPtrsDirty = true;
 
-    GR_GL(ColorMask(GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE));
+    GL_CALL(ColorMask(GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE));
     fHWDrawState.fRenderTarget = NULL;
 }
 
@@ -689,9 +714,9 @@ namespace {
 
 static const GrGLenum kUnknownGLFormat = ~0;
 
-GrGLenum get_fbo_color_format() {
+GrGLenum get_fbo_color_format(const GrGLInterface* gl) {
     GrGLint cbType;
-    GR_GL_GetFramebufferAttachmentParameteriv(GR_GL_FRAMEBUFFER,
+    GR_GL_GetFramebufferAttachmentParameteriv(gl, GR_GL_FRAMEBUFFER,
                                     GR_GL_COLOR_ATTACHMENT0,
                                     GR_GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE,
                                     &cbType);
@@ -699,30 +724,30 @@ GrGLenum get_fbo_color_format() {
     GrGLint cbFormat;
     switch (cbType) {
         case GR_GL_RENDERBUFFER:
-            GR_GL_GetFramebufferAttachmentParameteriv(GR_GL_FRAMEBUFFER,
+            GR_GL_GetFramebufferAttachmentParameteriv(gl, GR_GL_FRAMEBUFFER,
                                     GR_GL_COLOR_ATTACHMENT0,
                                     GR_GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME,
                                     &cbID);
-            GR_GL(BindRenderbuffer(GR_GL_RENDERBUFFER, cbID));
-            GR_GL_GetRenderbufferParameteriv(GR_GL_RENDERBUFFER,
+            GR_GL_CALL(gl, BindRenderbuffer(GR_GL_RENDERBUFFER, cbID));
+            GR_GL_GetRenderbufferParameteriv(gl, GR_GL_RENDERBUFFER,
                                              GR_GL_RENDERBUFFER_INTERNAL_FORMAT,
                                              &cbFormat);
             return cbFormat;
             break;
         case GR_GL_TEXTURE:
             // ES doesn't have glGetTexLevelParameter
-            if (GR_GL_SUPPORT_DESKTOP) {
+            if (gl->supportsDesktop()) {
                 GrGLint cbLevel;
                 GrGLint cbFace;
-                GR_GL_GetFramebufferAttachmentParameteriv(GR_GL_FRAMEBUFFER,
+                GR_GL_GetFramebufferAttachmentParameteriv(gl, GR_GL_FRAMEBUFFER,
                                     GR_GL_COLOR_ATTACHMENT0,
                                     GR_GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME,
                                     &cbID);
-                GR_GL_GetFramebufferAttachmentParameteriv(GR_GL_FRAMEBUFFER,
+                GR_GL_GetFramebufferAttachmentParameteriv(gl, GR_GL_FRAMEBUFFER,
                                     GR_GL_COLOR_ATTACHMENT0,
                                     GR_GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL,
                                     &cbLevel);
-                GR_GL_GetFramebufferAttachmentParameteriv(GR_GL_FRAMEBUFFER,
+                GR_GL_GetFramebufferAttachmentParameteriv(gl, GR_GL_FRAMEBUFFER,
                             GR_GL_COLOR_ATTACHMENT0,
                             GR_GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE,
                             &cbFace);
@@ -735,8 +760,8 @@ GrGLenum get_fbo_color_format() {
                     bind = GR_GL_TEXTURE_2D;
                     target = GR_GL_TEXTURE_2D;
                 }
-                GR_GL(BindTexture(bind, cbID));
-                GR_GL_GetTexLevelParameteriv(target, cbLevel, 
+                GR_GL_CALL(gl, BindTexture(bind, cbID));
+                GR_GL_GetTexLevelParameteriv(gl, target, cbLevel, 
                                     GR_GL_TEXTURE_INTERNAL_FORMAT, &cbFormat);
                 return cbFormat;
             } else {
@@ -773,26 +798,27 @@ GrPixelConfig internal_color_format_to_config(GrGLenum iFormat) {
     }
 }
 
-GrPixelConfig get_implied_color_config(bool arbFBOExtension) {
+GrPixelConfig get_implied_color_config(const GrGLInterface* gl,
+                                       bool arbFBOExtension) {
     GrGLint rSize, bSize, gSize, aSize;
     if (arbFBOExtension) {
-        GR_GL_GetFramebufferAttachmentParameteriv(GR_GL_FRAMEBUFFER, 
+        GR_GL_GetFramebufferAttachmentParameteriv(gl, GR_GL_FRAMEBUFFER, 
                 GR_GL_COLOR_ATTACHMENT0,
                 GR_GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE, &rSize);
-        GR_GL_GetFramebufferAttachmentParameteriv(GR_GL_FRAMEBUFFER,
+        GR_GL_GetFramebufferAttachmentParameteriv(gl, GR_GL_FRAMEBUFFER,
                 GR_GL_COLOR_ATTACHMENT0,
                 GR_GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE, &gSize);
-        GR_GL_GetFramebufferAttachmentParameteriv(GR_GL_FRAMEBUFFER, 
+        GR_GL_GetFramebufferAttachmentParameteriv(gl, GR_GL_FRAMEBUFFER, 
                 GR_GL_COLOR_ATTACHMENT0,
                 GR_GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE, &bSize);
-        GR_GL_GetFramebufferAttachmentParameteriv(GR_GL_FRAMEBUFFER,
+        GR_GL_GetFramebufferAttachmentParameteriv(gl, GR_GL_FRAMEBUFFER,
                 GR_GL_COLOR_ATTACHMENT0, 
                 GR_GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE, &aSize);
     } else {
-        GR_GL_GetIntegerv(GR_GL_RED_BITS, &rSize);
-        GR_GL_GetIntegerv(GR_GL_GREEN_BITS, &gSize);
-        GR_GL_GetIntegerv(GR_GL_BLUE_BITS, &bSize);
-        GR_GL_GetIntegerv(GR_GL_ALPHA_BITS, &aSize);
+        GR_GL_GetIntegerv(gl, GR_GL_RED_BITS, &rSize);
+        GR_GL_GetIntegerv(gl, GR_GL_GREEN_BITS, &gSize);
+        GR_GL_GetIntegerv(gl, GR_GL_BLUE_BITS, &bSize);
+        GR_GL_GetIntegerv(gl, GR_GL_ALPHA_BITS, &aSize);
     }
 
     if(8 == rSize && 8 == gSize && 8 == bSize) {
@@ -809,15 +835,15 @@ GrPixelConfig get_implied_color_config(bool arbFBOExtension) {
     return kUnknown_GrPixelConfig;
 }
 
-int get_fbo_stencil_bits(bool arbFBOExtension) {
+int get_fbo_stencil_bits(const GrGLInterface* gl, bool arbFBOExtension) {
     GrGLint stencilBits;
     if (arbFBOExtension) {
-        GR_GL_GetFramebufferAttachmentParameteriv(GR_GL_FRAMEBUFFER,
+        GR_GL_GetFramebufferAttachmentParameteriv(gl, GR_GL_FRAMEBUFFER,
                                     GR_GL_STENCIL_ATTACHMENT,
                                     GR_GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE,
                                     &stencilBits);
     } else {
-        GR_GL_GetIntegerv(GR_GL_STENCIL_BITS, &stencilBits);
+        GR_GL_GetIntegerv(gl, GR_GL_STENCIL_BITS, &stencilBits);
     }
     return stencilBits;
 }
@@ -827,17 +853,18 @@ GrRenderTarget* GrGpuGL::onCreateRenderTargetFrom3DApiState() {
 
     GrGLRenderTarget::Desc rtDesc;
 
-    GR_GL_GetIntegerv(GR_GL_FRAMEBUFFER_BINDING, (GrGLint*)&rtDesc.fRTFBOID);
+    GR_GL_GetIntegerv(this->glInterface(), GR_GL_FRAMEBUFFER_BINDING, 
+                      (GrGLint*)&rtDesc.fRTFBOID);
     rtDesc.fTexFBOID = rtDesc.fRTFBOID;
     rtDesc.fMSColorRenderbufferID = 0;
 
-    bool arbFBO = (GR_GL_SUPPORT_DESKTOP && (fGLVersion > 3.0 ||
+    bool arbFBO = ((kDesktop_GrGLBinding == fGLBinding) && (fGLVersion > 3.0 ||
                    this->hasExtension("GL_ARB_framebuffer_object")));
 
     GrGLIRect viewport;
-    viewport.setFromGLViewport();
-    int stencilBits = get_fbo_stencil_bits(arbFBO);
-    GR_GL_GetIntegerv(GR_GL_SAMPLES, &rtDesc.fSampleCnt);
+    viewport.setFromGLViewport(this->glInterface());
+    int stencilBits = get_fbo_stencil_bits(this->glInterface(), arbFBO);
+    GR_GL_GetIntegerv(this->glInterface(), GR_GL_SAMPLES, &rtDesc.fSampleCnt);
 
     SkAutoTUnref<GrGLStencilBuffer> sb;
     if (stencilBits) {
@@ -852,9 +879,9 @@ GrRenderTarget* GrGpuGL::onCreateRenderTargetFrom3DApiState() {
                                        format));
     }
 
-    GrGLenum fmat = get_fbo_color_format();
+    GrGLenum fmat = get_fbo_color_format(this->glInterface());
     if (kUnknownGLFormat == fmat) {
-        rtDesc.fConfig = get_implied_color_config(arbFBO);
+        rtDesc.fConfig = get_implied_color_config(this->glInterface(), arbFBO);
     } else {
         rtDesc.fConfig = internal_color_format_to_config(fmat);
     }
@@ -888,7 +915,7 @@ void GrGpuGL::setupStencilFormats() {
         gS     = {GR_GL_STENCIL_INDEX,    kUnknownBitCount, kUnknownBitCount, false},
         gDS    = {GR_GL_DEPTH_STENCIL,    kUnknownBitCount, kUnknownBitCount, true };
 
-    if (GR_GL_SUPPORT_DESKTOP) {
+    if (kDesktop_GrGLBinding == this->glBinding()) {
         bool supportsPackedDS = fGLVersion >= 3.0f || 
                                 this->hasExtension("GL_EXT_packed_depth_stencil") ||
                                 this->hasExtension("GL_ARB_framebuffer_object");
@@ -949,10 +976,10 @@ void GrGpuGL::allocateAndUploadTexData(const GrGLTexture::Desc& desc,
      * GL_UNPACK_ROW_LENGTH.
      */
     bool flipY = GrGLTexture::kBottomUp_Orientation == desc.fOrientation;
-    if (GR_GL_SUPPORT_DESKTOP && !flipY) {
+    if (kDesktop_GrGLBinding == this->glBinding() && !flipY) {
         if (data && rowBytes != desc.fContentWidth * desc.fUploadByteCount) {
-            GR_GL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH,
-                              rowBytes / desc.fUploadByteCount));
+            GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH,
+                                rowBytes / desc.fUploadByteCount));
         }
     } else {
         size_t trimRowBytes = desc.fContentWidth * desc.fUploadByteCount;
@@ -979,7 +1006,7 @@ void GrGpuGL::allocateAndUploadTexData(const GrGLTexture::Desc& desc,
         }
     }
 
-    GR_GL(PixelStorei(GR_GL_UNPACK_ALIGNMENT, desc.fUploadByteCount));
+    GL_CALL(PixelStorei(GR_GL_UNPACK_ALIGNMENT, desc.fUploadByteCount));
     if (kIndex_8_GrPixelConfig == desc.fFormat &&
         supports8BitPalette()) {
         // ES only supports CompressedTexImage2D, not CompressedTexSubimage2D
@@ -987,20 +1014,20 @@ void GrGpuGL::allocateAndUploadTexData(const GrGLTexture::Desc& desc,
         GrAssert(desc.fContentHeight == desc.fAllocHeight);
         GrGLsizei imageSize = desc.fAllocWidth * desc.fAllocHeight +
                               kGrColorTableSize;
-        GR_GL(CompressedTexImage2D(GR_GL_TEXTURE_2D, 0, desc.fUploadFormat,
-                                   desc.fAllocWidth, desc.fAllocHeight,
-                                   0, imageSize, data));
-        GrGLRestoreResetRowLength();
+        GL_CALL(CompressedTexImage2D(GR_GL_TEXTURE_2D, 0, desc.fUploadFormat,
+                                     desc.fAllocWidth, desc.fAllocHeight,
+                                     0, imageSize, data));
+        GrGLResetRowLength(this->glInterface());
     } else {
         if (NULL != data && (desc.fAllocWidth != desc.fContentWidth ||
                                 desc.fAllocHeight != desc.fContentHeight)) {
-            GR_GL(TexImage2D(GR_GL_TEXTURE_2D, 0, internalFormat,
-                             desc.fAllocWidth, desc.fAllocHeight,
-                             0, desc.fUploadFormat, desc.fUploadType, NULL));
-            GR_GL(TexSubImage2D(GR_GL_TEXTURE_2D, 0, 0, 0, desc.fContentWidth,
-                                desc.fContentHeight, desc.fUploadFormat,
-                                desc.fUploadType, data));
-            GrGLRestoreResetRowLength();
+            GL_CALL(TexImage2D(GR_GL_TEXTURE_2D, 0, internalFormat,
+                               desc.fAllocWidth, desc.fAllocHeight,
+                               0, desc.fUploadFormat, desc.fUploadType, NULL));
+            GL_CALL(TexSubImage2D(GR_GL_TEXTURE_2D, 0, 0, 0, desc.fContentWidth,
+                                  desc.fContentHeight, desc.fUploadFormat,
+                                  desc.fUploadType, data));
+            GrGLResetRowLength(this->glInterface());
 
             int extraW = desc.fAllocWidth  - desc.fContentWidth;
             int extraH = desc.fAllocHeight - desc.fContentHeight;
@@ -1023,10 +1050,10 @@ void GrGpuGL::allocateAndUploadTexData(const GrGLTexture::Desc& desc,
                     memcpy(extraRowStart, lastRowStart, rowDataBytes);
                     extraRowStart += rowDataBytes;
                 }
-                GR_GL(TexSubImage2D(GR_GL_TEXTURE_2D, 0, 0, desc.fContentHeight,
-                                    desc.fContentWidth, extraH,
-                                    desc.fUploadFormat, desc.fUploadType,
-                                    texels.get()));
+                GL_CALL(TexSubImage2D(GR_GL_TEXTURE_2D, 0, 0,
+                                      desc.fContentHeight, desc.fContentWidth,
+                                      extraH, desc.fUploadFormat,
+                                      desc.fUploadType, texels.get()));
             }
             if (extraW) {
                 uint8_t* edgeTexel = (uint8_t*)data +
@@ -1039,10 +1066,10 @@ void GrGpuGL::allocateAndUploadTexData(const GrGLTexture::Desc& desc,
                     }
                     edgeTexel += rowBytes;
                 }
-                GR_GL(TexSubImage2D(GR_GL_TEXTURE_2D, 0, desc.fContentWidth, 0,
-                                    extraW, desc.fContentHeight,
-                                    desc.fUploadFormat, desc.fUploadType,
-                                    texels.get()));
+                GL_CALL(TexSubImage2D(GR_GL_TEXTURE_2D, 0, desc.fContentWidth,
+                                      0, extraW, desc.fContentHeight,
+                                      desc.fUploadFormat, desc.fUploadType,
+                                      texels.get()));
             }
             if (extraW && extraH) {
                 uint8_t* cornerTexel = (uint8_t*)data + 
@@ -1053,17 +1080,17 @@ void GrGpuGL::allocateAndUploadTexData(const GrGLTexture::Desc& desc,
                     memcpy(extraTexel, cornerTexel, desc.fUploadByteCount);
                     extraTexel += desc.fUploadByteCount;
                 }
-                GR_GL(TexSubImage2D(GR_GL_TEXTURE_2D, 0, desc.fContentWidth,
-                                    desc.fContentHeight, extraW, extraH, 
-                                    desc.fUploadFormat, desc.fUploadType,
-                                    texels.get()));
+                GL_CALL(TexSubImage2D(GR_GL_TEXTURE_2D, 0, desc.fContentWidth,
+                                      desc.fContentHeight, extraW, extraH, 
+                                      desc.fUploadFormat, desc.fUploadType,
+                                      texels.get()));
             }
 
         } else {
-            GR_GL(TexImage2D(GR_GL_TEXTURE_2D, 0, internalFormat,
-                             desc.fAllocWidth, desc.fAllocHeight, 0,
-                             desc.fUploadFormat, desc.fUploadType, data));
-            GrGLRestoreResetRowLength();
+            GL_CALL(TexImage2D(GR_GL_TEXTURE_2D, 0, internalFormat,
+                               desc.fAllocWidth, desc.fAllocHeight, 0,
+                               desc.fUploadFormat, desc.fUploadType, data));
+            GrGLResetRowLength(this->glInterface());
         }
     }
 }
@@ -1081,7 +1108,7 @@ bool GrGpuGL::createRenderTargetObjects(int width, int height,
 
     GrGLenum msColorFormat = 0; // suppress warning
 
-    GR_GL(GenFramebuffers(1, &desc->fTexFBOID));
+    GL_CALL(GenFramebuffers(1, &desc->fTexFBOID));
     if (!desc->fTexFBOID) {
         goto FAILED;
     }
@@ -1090,8 +1117,8 @@ bool GrGpuGL::createRenderTargetObjects(int width, int height,
     // If we are using multisampling we will create two FBOS. We render
     // to one and then resolve to the texture bound to the other.
     if (desc->fSampleCnt > 1 && kNone_MSFBO != fMSFBOType) {
-        GR_GL(GenFramebuffers(1, &desc->fRTFBOID));
-        GR_GL(GenRenderbuffers(1, &desc->fMSColorRenderbufferID));
+        GL_CALL(GenFramebuffers(1, &desc->fRTFBOID));
+        GL_CALL(GenRenderbuffers(1, &desc->fMSColorRenderbufferID));
         if (!desc->fRTFBOID ||
             !desc->fMSColorRenderbufferID || 
             !this->fboInternalFormat(desc->fConfig, &msColorFormat)) {
@@ -1103,33 +1130,34 @@ bool GrGpuGL::createRenderTargetObjects(int width, int height,
 
     if (desc->fRTFBOID != desc->fTexFBOID) {
         GrAssert(desc->fSampleCnt > 1);
-        GR_GL(BindRenderbuffer(GR_GL_RENDERBUFFER,
+        GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER,
                                desc->fMSColorRenderbufferID));
-        GR_GL_NO_ERR(RenderbufferStorageMultisample(GR_GL_RENDERBUFFER, 
-                                                    desc->fSampleCnt,
-                                                    msColorFormat,
-                                                    width, height));
-        err = GrGLGetGLInterface()->fGetError();
+        GR_GL_CALL_NOERRCHECK(this->glInterface(),
+                              RenderbufferStorageMultisample(GR_GL_RENDERBUFFER, 
+                                                             desc->fSampleCnt,
+                                                             msColorFormat,
+                                                             width, height));
+        err = GR_GL_GET_ERROR(this->glInterface());
         if (err != GR_GL_NO_ERROR) {
             goto FAILED;
         }
-        GR_GL(BindFramebuffer(GR_GL_FRAMEBUFFER, desc->fRTFBOID));
-        GR_GL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, 
+        GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, desc->fRTFBOID));
+        GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, 
                                       GR_GL_COLOR_ATTACHMENT0,
                                       GR_GL_RENDERBUFFER,
                                       desc->fMSColorRenderbufferID));
-        GrGLenum status = GR_GL(CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
+        GrGLenum status = GL_CALL(CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
         if (status != GR_GL_FRAMEBUFFER_COMPLETE) {
             goto FAILED;
         }
     }
-    GR_GL(BindFramebuffer(GR_GL_FRAMEBUFFER, desc->fTexFBOID));
+    GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, desc->fTexFBOID));
 
-    GR_GL(FramebufferTexture2D(GR_GL_FRAMEBUFFER,
-                               GR_GL_COLOR_ATTACHMENT0,
-                               GR_GL_TEXTURE_2D,
-                               texID, 0));
-    status = GR_GL(CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
+    GL_CALL(FramebufferTexture2D(GR_GL_FRAMEBUFFER,
+                                 GR_GL_COLOR_ATTACHMENT0,
+                                 GR_GL_TEXTURE_2D,
+                                 texID, 0));
+    status = GL_CALL(CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
     if (status != GR_GL_FRAMEBUFFER_COMPLETE) {
         goto FAILED;
     }
@@ -1138,13 +1166,13 @@ bool GrGpuGL::createRenderTargetObjects(int width, int height,
 
 FAILED:
     if (desc->fMSColorRenderbufferID) {
-        GR_GL(DeleteRenderbuffers(1, &desc->fMSColorRenderbufferID));
+        GL_CALL(DeleteRenderbuffers(1, &desc->fMSColorRenderbufferID));
     }
     if (desc->fRTFBOID != desc->fTexFBOID) {
-        GR_GL(DeleteFramebuffers(1, &desc->fRTFBOID));
+        GL_CALL(DeleteFramebuffers(1, &desc->fRTFBOID));
     }
     if (desc->fTexFBOID) {
-        GR_GL(DeleteFramebuffers(1, &desc->fTexFBOID));
+        GL_CALL(DeleteFramebuffers(1, &desc->fTexFBOID));
     }
     return false;
 }
@@ -1237,25 +1265,25 @@ GrTexture* GrGpuGL::onCreateTexture(const GrTextureDesc& desc,
         }
     }
 
-    GR_GL(GenTextures(1, &glTexDesc.fTextureID));
+    GL_CALL(GenTextures(1, &glTexDesc.fTextureID));
     if (!glTexDesc.fTextureID) {
         return return_null_texture();
     }
 
     this->setSpareTextureUnit();
-    GR_GL(BindTexture(GR_GL_TEXTURE_2D, glTexDesc.fTextureID));
-    GR_GL(TexParameteri(GR_GL_TEXTURE_2D,
-                        GR_GL_TEXTURE_MAG_FILTER,
-                        DEFAULT_PARAMS.fFilter));
-    GR_GL(TexParameteri(GR_GL_TEXTURE_2D,
-                        GR_GL_TEXTURE_MIN_FILTER,
-                        DEFAULT_PARAMS.fFilter));
-    GR_GL(TexParameteri(GR_GL_TEXTURE_2D,
-                        GR_GL_TEXTURE_WRAP_S,
-                        DEFAULT_PARAMS.fWrapS));
-    GR_GL(TexParameteri(GR_GL_TEXTURE_2D,
-                        GR_GL_TEXTURE_WRAP_T,
-                        DEFAULT_PARAMS.fWrapT));
+    GL_CALL(BindTexture(GR_GL_TEXTURE_2D, glTexDesc.fTextureID));
+    GL_CALL(TexParameteri(GR_GL_TEXTURE_2D,
+                          GR_GL_TEXTURE_MAG_FILTER,
+                          DEFAULT_PARAMS.fFilter));
+    GL_CALL(TexParameteri(GR_GL_TEXTURE_2D,
+                          GR_GL_TEXTURE_MIN_FILTER,
+                          DEFAULT_PARAMS.fFilter));
+    GL_CALL(TexParameteri(GR_GL_TEXTURE_2D,
+                          GR_GL_TEXTURE_WRAP_S,
+                          DEFAULT_PARAMS.fWrapS));
+    GL_CALL(TexParameteri(GR_GL_TEXTURE_2D,
+                          GR_GL_TEXTURE_WRAP_T,
+                          DEFAULT_PARAMS.fWrapT));
 
     this->allocateAndUploadTexData(glTexDesc, internalFormat,srcData, rowBytes);
 
@@ -1269,7 +1297,7 @@ GrTexture* GrGpuGL::onCreateTexture(const GrTextureDesc& desc,
                                              glTexDesc.fAllocHeight,
                                              glTexDesc.fTextureID,
                                              &glRTDesc)) {
-            GR_GL(DeleteTextures(1, &glTexDesc.fTextureID));
+            GL_CALL(DeleteTextures(1, &glTexDesc.fTextureID));
             return return_null_texture();
         }
         tex = new GrGLTexture(this, glTexDesc, glRTDesc, DEFAULT_PARAMS);
@@ -1284,16 +1312,18 @@ GrTexture* GrGpuGL::onCreateTexture(const GrTextureDesc& desc,
 }
 
 namespace {
-void inline get_stencil_rb_sizes(GrGLuint rb, GrGLStencilBuffer::Format* format) {
+void inline get_stencil_rb_sizes(const GrGLInterface* gl,
+                                 GrGLuint rb, 
+                                 GrGLStencilBuffer::Format* format) {
     // we shouldn't ever know one size and not the other
     GrAssert((kUnknownBitCount == format->fStencilBits) ==
              (kUnknownBitCount == format->fTotalBits));
     if (kUnknownBitCount == format->fStencilBits) {
-        GR_GL_GetRenderbufferParameteriv(GR_GL_RENDERBUFFER,
+        GR_GL_GetRenderbufferParameteriv(gl, GR_GL_RENDERBUFFER,
                                          GR_GL_RENDERBUFFER_STENCIL_SIZE,
                                          (GrGLint*)&format->fStencilBits);
         if (format->fPacked) {
-            GR_GL_GetRenderbufferParameteriv(GR_GL_RENDERBUFFER,
+            GR_GL_GetRenderbufferParameteriv(gl, GR_GL_RENDERBUFFER,
                                              GR_GL_RENDERBUFFER_DEPTH_SIZE,
                                              (GrGLint*)&format->fTotalBits);
             format->fTotalBits += format->fStencilBits;
@@ -1315,7 +1345,7 @@ bool GrGpuGL::createStencilBufferForRenderTarget(GrRenderTarget* rt,
 
     int samples = rt->numSamples();
     GrGLuint sbID;
-    GR_GL(GenRenderbuffers(1, &sbID));
+    GL_CALL(GenRenderbuffers(1, &sbID));
     if (!sbID) {
         return false;
     }
@@ -1324,7 +1354,7 @@ bool GrGpuGL::createStencilBufferForRenderTarget(GrRenderTarget* rt,
 
     int stencilFmtCnt = fStencilFormats.count();
     for (int i = 0; i < stencilFmtCnt; ++i) {
-        GR_GL(BindRenderbuffer(GR_GL_RENDERBUFFER, sbID));
+        GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, sbID));
         // we start with the last stencil format that succeeded in hopes
         // that we won't go through this loop more than once after the
         // first (painful) stencil creation.
@@ -1332,24 +1362,26 @@ bool GrGpuGL::createStencilBufferForRenderTarget(GrRenderTarget* rt,
         // we do this "if" so that we don't call the multisample
         // version on a GL that doesn't have an MSAA extension.
         if (samples > 1) {
-            GR_GL_NO_ERR(RenderbufferStorageMultisample(
+            GR_GL_CALL_NOERRCHECK(this->glInterface(),
+                                  RenderbufferStorageMultisample(
                                         GR_GL_RENDERBUFFER,
                                         samples,
                                         fStencilFormats[sIdx].fInternalFormat,
                                         width,
                                         height));
         } else {
-            GR_GL_NO_ERR(RenderbufferStorage(GR_GL_RENDERBUFFER,
+            GR_GL_CALL_NOERRCHECK(this->glInterface(),
+                                  RenderbufferStorage(GR_GL_RENDERBUFFER,
                                         fStencilFormats[sIdx].fInternalFormat,
                                         width, height));
         }
 
-        GrGLenum err = GrGLGetGLInterface()->fGetError();
+        GrGLenum err = GR_GL_GET_ERROR(this->glInterface());
         if (err == GR_GL_NO_ERROR) {
             // After sized formats we attempt an unsized format and take whatever
             // sizes GL gives us. In that case we query for the size.
             GrGLStencilBuffer::Format format = fStencilFormats[sIdx];
-            get_stencil_rb_sizes(sbID, &format);
+            get_stencil_rb_sizes(this->glInterface(), sbID, &format);
             sb = new GrGLStencilBuffer(this, sbID, width, height, 
                                        samples, format);
             if (this->attachStencilBufferToRenderTarget(sb, rt)) {
@@ -1362,7 +1394,7 @@ bool GrGpuGL::createStencilBufferForRenderTarget(GrRenderTarget* rt,
            sb->unref();
         }
     }
-    GR_GL(DeleteRenderbuffers(1, &sbID));
+    GL_CALL(DeleteRenderbuffers(1, &sbID));
     return false;
 }
 
@@ -1374,15 +1406,15 @@ bool GrGpuGL::attachStencilBufferToRenderTarget(GrStencilBuffer* sb,
 
     if (NULL == sb) {
         if (NULL != rt->getStencilBuffer()) {
-            GR_GL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
+            GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
                                           GR_GL_STENCIL_ATTACHMENT,
                                           GR_GL_RENDERBUFFER, 0));
-            GR_GL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
+            GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
                                           GR_GL_DEPTH_ATTACHMENT,
                                           GR_GL_RENDERBUFFER, 0));
 #if GR_DEBUG
             GrGLenum status = 
-                GR_GL(CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
+                GL_CALL(CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
             GrAssert(GR_GL_FRAMEBUFFER_COMPLETE == status);
 #endif
         }
@@ -1392,28 +1424,27 @@ bool GrGpuGL::attachStencilBufferToRenderTarget(GrStencilBuffer* sb,
         GrGLuint rb = glsb->renderbufferID();
 
         fHWDrawState.fRenderTarget = NULL;
-
-        GR_GL(BindFramebuffer(GR_GL_FRAMEBUFFER, fbo));
-        GR_GL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
+        GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, fbo));
+        GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
                                       GR_GL_STENCIL_ATTACHMENT,
                                       GR_GL_RENDERBUFFER, rb));
         if (glsb->format().fPacked) {
-            GR_GL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
+            GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
                                           GR_GL_DEPTH_ATTACHMENT,
                                           GR_GL_RENDERBUFFER, rb));
         } else {
-            GR_GL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
+            GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
                                           GR_GL_DEPTH_ATTACHMENT,
                                           GR_GL_RENDERBUFFER, 0));
         }
 
-        GrGLenum status = GR_GL(CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
+        GrGLenum status = GL_CALL(CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
         if (status != GR_GL_FRAMEBUFFER_COMPLETE) {
-            GR_GL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
+            GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
                                           GR_GL_STENCIL_ATTACHMENT,
                                           GR_GL_RENDERBUFFER, 0));
             if (glsb->format().fPacked) {
-                GR_GL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
+                GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
                                               GR_GL_DEPTH_ATTACHMENT,
                                               GR_GL_RENDERBUFFER, 0));
             }
@@ -1428,16 +1459,17 @@ bool GrGpuGL::attachStencilBufferToRenderTarget(GrStencilBuffer* sb,
 
 GrVertexBuffer* GrGpuGL::onCreateVertexBuffer(uint32_t size, bool dynamic) {
     GrGLuint id;
-    GR_GL(GenBuffers(1, &id));
+    GL_CALL(GenBuffers(1, &id));
     if (id) {
-        GR_GL(BindBuffer(GR_GL_ARRAY_BUFFER, id));
+        GL_CALL(BindBuffer(GR_GL_ARRAY_BUFFER, id));
         fHWGeometryState.fArrayPtrsDirty = true;
-        GrGLClearErr();
+        GrGLClearErr(this->glInterface());
         // make sure driver can allocate memory for this buffer
-        GR_GL_NO_ERR(BufferData(GR_GL_ARRAY_BUFFER, size, NULL,
-                                dynamic ? GR_GL_DYNAMIC_DRAW : GR_GL_STATIC_DRAW));
-        if (GrGLGetGLInterface()->fGetError() != GR_GL_NO_ERROR) {
-            GR_GL(DeleteBuffers(1, &id));
+        GR_GL_CALL_NOERRCHECK(this->glInterface(),
+                              BufferData(GR_GL_ARRAY_BUFFER, size, NULL, 
+                              dynamic ? GR_GL_DYNAMIC_DRAW : GR_GL_STATIC_DRAW));
+        if (this->glInterface()->fGetError() != GR_GL_NO_ERROR) {
+            GL_CALL(DeleteBuffers(1, &id));
             // deleting bound buffer does implicit bind to 0
             fHWGeometryState.fVertexBuffer = NULL;
             return NULL;
@@ -1452,15 +1484,16 @@ GrVertexBuffer* GrGpuGL::onCreateVertexBuffer(uint32_t size, bool dynamic) {
 
 GrIndexBuffer* GrGpuGL::onCreateIndexBuffer(uint32_t size, bool dynamic) {
     GrGLuint id;
-    GR_GL(GenBuffers(1, &id));
+    GL_CALL(GenBuffers(1, &id));
     if (id) {
-        GR_GL(BindBuffer(GR_GL_ELEMENT_ARRAY_BUFFER, id));
-        GrGLClearErr();
+        GL_CALL(BindBuffer(GR_GL_ELEMENT_ARRAY_BUFFER, id));
+        GrGLClearErr(this->glInterface());
         // make sure driver can allocate memory for this buffer
-        GR_GL_NO_ERR(BufferData(GR_GL_ELEMENT_ARRAY_BUFFER, size, NULL,
-                                dynamic ? GR_GL_DYNAMIC_DRAW : GR_GL_STATIC_DRAW));
-        if (GrGLGetGLInterface()->fGetError() != GR_GL_NO_ERROR) {
-            GR_GL(DeleteBuffers(1, &id));
+        GR_GL_CALL_NOERRCHECK(this->glInterface(),
+                              BufferData(GR_GL_ELEMENT_ARRAY_BUFFER, size, NULL,
+                              dynamic ? GR_GL_DYNAMIC_DRAW : GR_GL_STATIC_DRAW));
+        if (this->glInterface()->fGetError() != GR_GL_NO_ERROR) {
+            GL_CALL(DeleteBuffers(1, &id));
             // deleting bound buffer does implicit bind to 0
             fHWGeometryState.fIndexBuffer = NULL;
             return NULL;
@@ -1489,16 +1522,16 @@ void GrGpuGL::flushScissor(const GrIRect* rect) {
 
     if (NULL != rect) {
         if (fHWBounds.fScissorRect != scissor) {
-            scissor.pushToGLScissor();
+            scissor.pushToGLScissor(this->glInterface());
             fHWBounds.fScissorRect = scissor;
         }
         if (!fHWBounds.fScissorEnabled) {
-            GR_GL(Enable(GR_GL_SCISSOR_TEST));
+            GL_CALL(Enable(GR_GL_SCISSOR_TEST));
             fHWBounds.fScissorEnabled = true;
         }
     } else {
         if (fHWBounds.fScissorEnabled) {
-            GR_GL(Disable(GR_GL_SCISSOR_TEST));
+            GL_CALL(Disable(GR_GL_SCISSOR_TEST));
             fHWBounds.fScissorEnabled = false;
         }
     }
@@ -1522,13 +1555,13 @@ void GrGpuGL::onClear(const GrIRect* rect, GrColor color) {
     }
     this->flushRenderTarget(rect);
     this->flushScissor(rect);
-    GR_GL(ColorMask(GR_GL_TRUE,GR_GL_TRUE,GR_GL_TRUE,GR_GL_TRUE));
+    GL_CALL(ColorMask(GR_GL_TRUE,GR_GL_TRUE,GR_GL_TRUE,GR_GL_TRUE));
     fHWDrawState.fFlagBits &= ~kNoColorWrites_StateBit;
-    GR_GL(ClearColor(GrColorUnpackR(color)/255.f,
-                     GrColorUnpackG(color)/255.f,
-                     GrColorUnpackB(color)/255.f,
-                     GrColorUnpackA(color)/255.f));
-    GR_GL(Clear(GR_GL_COLOR_BUFFER_BIT));
+    GL_CALL(ClearColor(GrColorUnpackR(color)/255.f,
+                       GrColorUnpackG(color)/255.f,
+                       GrColorUnpackB(color)/255.f,
+                       GrColorUnpackA(color)/255.f));
+    GL_CALL(Clear(GR_GL_COLOR_BUFFER_BIT));
 }
 
 void GrGpuGL::clearStencil() {
@@ -1539,12 +1572,12 @@ void GrGpuGL::clearStencil() {
     this->flushRenderTarget(&GrIRect::EmptyIRect());
 
     if (fHWBounds.fScissorEnabled) {
-        GR_GL(Disable(GR_GL_SCISSOR_TEST));
+        GL_CALL(Disable(GR_GL_SCISSOR_TEST));
         fHWBounds.fScissorEnabled = false;
     }
-    GR_GL(StencilMask(0xffffffff));
-    GR_GL(ClearStencil(0));
-    GR_GL(Clear(GR_GL_STENCIL_BUFFER_BIT));
+    GL_CALL(StencilMask(0xffffffff));
+    GL_CALL(ClearStencil(0));
+    GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT));
     fHWDrawState.fStencilSettings.invalidate();
 }
 
@@ -1569,9 +1602,9 @@ void GrGpuGL::clearStencilClip(const GrIRect& rect) {
 #endif
     this->flushRenderTarget(&GrIRect::EmptyIRect());
     this->flushScissor(&rect);
-    GR_GL(StencilMask(clipStencilMask));
-    GR_GL(ClearStencil(0));
-    GR_GL(Clear(GR_GL_STENCIL_BUFFER_BIT));
+    GL_CALL(StencilMask(clipStencilMask));
+    GL_CALL(ClearStencil(0));
+    GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT));
     fHWDrawState.fStencilSettings.invalidate();
 }
 
@@ -1601,7 +1634,8 @@ bool GrGpuGL::onReadPixels(GrRenderTarget* target,
         case GrGLRenderTarget::kCanResolve_ResolveType:
             this->resolveRenderTarget(tgt);
             // we don't track the state of the READ FBO ID.
-            GR_GL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, tgt->textureFBOID()));
+            GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER,
+                                    tgt->textureFBOID()));
             break;
         default:
             GrCrash("Unknown resolve type");
@@ -1612,9 +1646,9 @@ bool GrGpuGL::onReadPixels(GrRenderTarget* target,
     // the read rect is viewport-relative
     GrGLIRect readRect;
     readRect.setRelativeTo(glvp, left, top, width, height);
-    GR_GL(ReadPixels(readRect.fLeft, readRect.fBottom,
-                     readRect.fWidth, readRect.fHeight,
-                     format, type, buffer));
+    GL_CALL(ReadPixels(readRect.fLeft, readRect.fBottom,
+                       readRect.fWidth, readRect.fHeight,
+                       format, type, buffer));
 
     // now reverse the order of the rows, since GL's are bottom-to-top, but our
     // API presents top-to-bottom
@@ -1643,12 +1677,12 @@ void GrGpuGL::flushRenderTarget(const GrIRect* bound) {
 
     GrGLRenderTarget* rt = (GrGLRenderTarget*)fCurrDrawState.fRenderTarget;
     if (fHWDrawState.fRenderTarget != fCurrDrawState.fRenderTarget) {
-        GR_GL(BindFramebuffer(GR_GL_FRAMEBUFFER, rt->renderFBOID()));
+        GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, rt->renderFBOID()));
     #if GR_COLLECT_STATS
         ++fStats.fRenderTargetChngCnt;
     #endif
     #if GR_DEBUG
-        GrGLenum status = GR_GL(CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
+        GrGLenum status = GL_CALL(CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
         if (status != GR_GL_FRAMEBUFFER_COMPLETE) {
             GrPrintf("GrGpuGL::flushRenderTarget glCheckFramebufferStatus %x\n", status);
         }
@@ -1657,7 +1691,7 @@ void GrGpuGL::flushRenderTarget(const GrIRect* bound) {
         fHWDrawState.fRenderTarget = fCurrDrawState.fRenderTarget;
         const GrGLIRect& vp = rt->getViewport();
         if (fHWBounds.fViewportRect != vp) {
-            vp.pushToGLViewport();
+            vp.pushToGLViewport(this->glInterface());
             fHWBounds.fViewportRect = vp;
         }
     }
@@ -1712,8 +1746,8 @@ void GrGpuGL::onGpuDrawIndexed(GrPrimitiveType type,
     // DrawElements always draws from the begining of the arrays for idx 0.
     GrAssert(0 == startVertex);
 
-    GR_GL(DrawElements(gPrimitiveType2GLMode[type], indexCount,
-                       GR_GL_UNSIGNED_SHORT, indices));
+    GL_CALL(DrawElements(gPrimitiveType2GLMode[type], indexCount,
+                         GR_GL_UNSIGNED_SHORT, indices));
 #if SWAP_PER_DRAW
     glFlush();
     #if GR_MAC_BUILD
@@ -1742,7 +1776,7 @@ void GrGpuGL::onGpuDrawNonIndexed(GrPrimitiveType type,
     // pass 0 for parameter first. We have to adjust gl*Pointer() to
     // account for startVertex in the DrawElements case. So we always
     // rely on setupGeometry to have accounted for startVertex.
-    GR_GL(DrawArrays(gPrimitiveType2GLMode[type], 0, vertexCount));
+    GL_CALL(DrawArrays(gPrimitiveType2GLMode[type], 0, vertexCount));
 #if SWAP_PER_DRAW
     glFlush();
     #if GR_MAC_BUILD
@@ -1762,10 +1796,10 @@ void GrGpuGL::resolveRenderTarget(GrGLRenderTarget* rt) {
     if (rt->needsResolve()) {
         GrAssert(kNone_MSFBO != fMSFBOType);
         GrAssert(rt->textureFBOID() != rt->renderFBOID());
-        GR_GL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER,
-                                        rt->renderFBOID()));
-        GR_GL(BindFramebuffer(GR_GL_DRAW_FRAMEBUFFER,
-                                        rt->textureFBOID()));
+        GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER,
+                                rt->renderFBOID()));
+        GL_CALL(BindFramebuffer(GR_GL_DRAW_FRAMEBUFFER,
+                                rt->textureFBOID()));
     #if GR_COLLECT_STATS
         ++fStats.fRenderTargetChngCnt;
     #endif
@@ -1780,10 +1814,10 @@ void GrGpuGL::resolveRenderTarget(GrGLRenderTarget* rt) {
 
         if (kAppleES_MSFBO == fMSFBOType) {
             // Apple's extension uses the scissor as the blit bounds.
-            GR_GL(Enable(GR_GL_SCISSOR_TEST));
-            GR_GL(Scissor(r.fLeft, r.fBottom,
-                          r.fWidth, r.fHeight));
-            GR_GL(ResolveMultisampleFramebuffer());
+            GL_CALL(Enable(GR_GL_SCISSOR_TEST));
+            GL_CALL(Scissor(r.fLeft, r.fBottom,
+                            r.fWidth, r.fHeight));
+            GL_CALL(ResolveMultisampleFramebuffer());
             fHWBounds.fScissorRect.invalidate();
             fHWBounds.fScissorEnabled = true;
         } else {
@@ -1794,9 +1828,9 @@ void GrGpuGL::resolveRenderTarget(GrGLRenderTarget* rt) {
             }
             int right = r.fLeft + r.fWidth;
             int top = r.fBottom + r.fHeight;
-            GR_GL(BlitFramebuffer(r.fLeft, r.fBottom, right, top,
-                                  r.fLeft, r.fBottom, right, top,
-                                  GR_GL_COLOR_BUFFER_BIT, GR_GL_NEAREST));
+            GL_CALL(BlitFramebuffer(r.fLeft, r.fBottom, right, top,
+                                    r.fLeft, r.fBottom, right, top,
+                                    GR_GL_COLOR_BUFFER_BIT, GR_GL_NEAREST));
         }
         rt->flagAsResolved();
     }
@@ -1866,9 +1900,9 @@ void GrGpuGL::flushStencil() {
         }
 
         if (settings->isDisabled()) {
-            GR_GL(Disable(GR_GL_STENCIL_TEST));
+            GL_CALL(Disable(GR_GL_STENCIL_TEST));
         } else {
-            GR_GL(Enable(GR_GL_STENCIL_TEST));
+            GL_CALL(Enable(GR_GL_STENCIL_TEST));
     #if GR_DEBUG
             if (!fStencilWrapOpsSupport) {
                 GrAssert(settings->fFrontPassOp != kIncWrap_StencilOp);
@@ -1944,21 +1978,25 @@ void GrGpuGL::flushStencil() {
                     backWriteMask &= userStencilMask;
                 }
 
-                GR_GL(StencilFuncSeparate(GR_GL_FRONT, frontFunc, frontRef, frontMask));
-                GR_GL(StencilMaskSeparate(GR_GL_FRONT, frontWriteMask));
-                GR_GL(StencilFuncSeparate(GR_GL_BACK, backFunc, backRef, backMask));
-                GR_GL(StencilMaskSeparate(GR_GL_BACK, backWriteMask));
-                GR_GL(StencilOpSeparate(GR_GL_FRONT, grToGLStencilOp[settings->fFrontFailOp],
-                                                  grToGLStencilOp[settings->fFrontPassOp],
-                                                  grToGLStencilOp[settings->fFrontPassOp]));
-
-                GR_GL(StencilOpSeparate(GR_GL_BACK,  grToGLStencilOp[settings->fBackFailOp],
-                                                  grToGLStencilOp[settings->fBackPassOp],
-                                                  grToGLStencilOp[settings->fBackPassOp]));
+                GL_CALL(StencilFuncSeparate(GR_GL_FRONT, frontFunc,
+                                            frontRef, frontMask));
+                GL_CALL(StencilMaskSeparate(GR_GL_FRONT, frontWriteMask));
+                GL_CALL(StencilFuncSeparate(GR_GL_BACK, backFunc,
+                                            backRef, backMask));
+                GL_CALL(StencilMaskSeparate(GR_GL_BACK, backWriteMask));
+                GL_CALL(StencilOpSeparate(GR_GL_FRONT,
+                                    grToGLStencilOp[settings->fFrontFailOp],
+                                    grToGLStencilOp[settings->fFrontPassOp],
+                                    grToGLStencilOp[settings->fFrontPassOp]));
+
+                GL_CALL(StencilOpSeparate(GR_GL_BACK,
+                                    grToGLStencilOp[settings->fBackFailOp],
+                                    grToGLStencilOp[settings->fBackPassOp],
+                                    grToGLStencilOp[settings->fBackPassOp]));
             } else {
-                GR_GL(StencilFunc(frontFunc, frontRef, frontMask));
-                GR_GL(StencilMask(frontWriteMask));
-                GR_GL(StencilOp(grToGLStencilOp[settings->fFrontFailOp],
+                GL_CALL(StencilFunc(frontFunc, frontRef, frontMask));
+                GL_CALL(StencilMask(frontWriteMask));
+                GL_CALL(StencilOp(grToGLStencilOp[settings->fFrontFailOp],
                                 grToGLStencilOp[settings->fFrontPassOp],
                                 grToGLStencilOp[settings->fFrontPassOp]));
             }
@@ -1981,7 +2019,7 @@ bool GrGpuGL::useSmoothLines() {
 }
 
 void GrGpuGL::flushAAState(GrPrimitiveType type) {
-    if (GR_GL_SUPPORT_DESKTOP) {
+    if (kDesktop_GrGLBinding == this->glBinding()) {
         // ES doesn't support toggling GL_MULTISAMPLE and doesn't have
         // smooth lines.
 
@@ -1990,25 +2028,25 @@ void GrGpuGL::flushAAState(GrPrimitiveType type) {
         if (GrIsPrimTypeLines(type)) {
             bool smooth = useSmoothLines();
             if (!fHWAAState.fSmoothLineEnabled && smooth) {
-                GR_GL(Enable(GR_GL_LINE_SMOOTH));
+                GL_CALL(Enable(GR_GL_LINE_SMOOTH));
                 fHWAAState.fSmoothLineEnabled = true;
             } else if (fHWAAState.fSmoothLineEnabled && !smooth) {
-                GR_GL(Disable(GR_GL_LINE_SMOOTH));
+                GL_CALL(Disable(GR_GL_LINE_SMOOTH));
                 fHWAAState.fSmoothLineEnabled = false;
             }
             if (fCurrDrawState.fRenderTarget->isMultisampled() && 
                 fHWAAState.fMSAAEnabled) {
-                GR_GL(Disable(GR_GL_MULTISAMPLE));
+                GL_CALL(Disable(GR_GL_MULTISAMPLE));
                 fHWAAState.fMSAAEnabled = false;
             }
         } else if (fCurrDrawState.fRenderTarget->isMultisampled() &&
                    !!(kAntialias_StateBit & fCurrDrawState.fFlagBits) !=
                    fHWAAState.fMSAAEnabled) {
             if (fHWAAState.fMSAAEnabled) {
-                GR_GL(Disable(GR_GL_MULTISAMPLE));
+                GL_CALL(Disable(GR_GL_MULTISAMPLE));
                 fHWAAState.fMSAAEnabled = false;
             } else {
-                GR_GL(Enable(GR_GL_MULTISAMPLE));
+                GL_CALL(Enable(GR_GL_MULTISAMPLE));
                 fHWAAState.fMSAAEnabled = true;
             }
         }
@@ -2020,13 +2058,13 @@ void GrGpuGL::flushBlend(GrPrimitiveType type,
                          GrBlendCoeff dstCoeff) {
     if (GrIsPrimTypeLines(type) && useSmoothLines()) {
         if (fHWBlendDisabled) {
-            GR_GL(Enable(GR_GL_BLEND));
+            GL_CALL(Enable(GR_GL_BLEND));
             fHWBlendDisabled = false;
         }
         if (kSA_BlendCoeff != fHWDrawState.fSrcBlend ||
             kISA_BlendCoeff != fHWDrawState.fDstBlend) {
-            GR_GL(BlendFunc(gXfermodeCoeff2Blend[kSA_BlendCoeff],
-                            gXfermodeCoeff2Blend[kISA_BlendCoeff]));
+            GL_CALL(BlendFunc(gXfermodeCoeff2Blend[kSA_BlendCoeff],
+                              gXfermodeCoeff2Blend[kISA_BlendCoeff]));
             fHWDrawState.fSrcBlend = kSA_BlendCoeff;
             fHWDrawState.fDstBlend = kISA_BlendCoeff;
         }
@@ -2034,17 +2072,17 @@ void GrGpuGL::flushBlend(GrPrimitiveType type,
         bool blendOff = canDisableBlend();
         if (fHWBlendDisabled != blendOff) {
             if (blendOff) {
-                GR_GL(Disable(GR_GL_BLEND));
+                GL_CALL(Disable(GR_GL_BLEND));
             } else {
-                GR_GL(Enable(GR_GL_BLEND));
+                GL_CALL(Enable(GR_GL_BLEND));
             }
             fHWBlendDisabled = blendOff;
         }
         if (!blendOff) {
             if (fHWDrawState.fSrcBlend != srcCoeff ||
                 fHWDrawState.fDstBlend != dstCoeff) {
-                GR_GL(BlendFunc(gXfermodeCoeff2Blend[srcCoeff],
-                                gXfermodeCoeff2Blend[dstCoeff]));
+                GL_CALL(BlendFunc(gXfermodeCoeff2Blend[srcCoeff],
+                                  gXfermodeCoeff2Blend[dstCoeff]));
                 fHWDrawState.fSrcBlend = srcCoeff;
                 fHWDrawState.fDstBlend = dstCoeff;
             }
@@ -2058,7 +2096,7 @@ void GrGpuGL::flushBlend(GrPrimitiveType type,
                     GrColorUnpackB(fCurrDrawState.fBlendConstant) / 255.f,
                     GrColorUnpackA(fCurrDrawState.fBlendConstant) / 255.f
                 };
-                GR_GL(BlendColor(c[0], c[1], c[2], c[3]));
+                GL_CALL(BlendColor(c[0], c[1], c[2], c[3]));
                 fHWDrawState.fBlendConstant = fCurrDrawState.fBlendConstant;
             }
         }
@@ -2104,7 +2142,7 @@ bool GrGpuGL::flushGLStateCommon(GrPrimitiveType type) {
 
             if (fHWDrawState.fTextures[s] != nextTexture) {
                 setTextureUnit(s);
-                GR_GL(BindTexture(GR_GL_TEXTURE_2D, nextTexture->textureID()));
+                GL_CALL(BindTexture(GR_GL_TEXTURE_2D, nextTexture->textureID()));
             #if GR_COLLECT_STATS
                 ++fStats.fTextureChngCnt;
             #endif
@@ -2122,31 +2160,31 @@ bool GrGpuGL::flushGLStateCommon(GrPrimitiveType type) {
 
             newTexParams.fFilter = grToGLFilter(sampler.getFilter());
 
-            newTexParams.fWrapS =
-                        GrGLTexture::WrapMode2GLWrap()[sampler.getWrapX()];
-            newTexParams.fWrapT =
-                        GrGLTexture::WrapMode2GLWrap()[sampler.getWrapY()];
+            const GrGLenum* wraps = 
+                                GrGLTexture::WrapMode2GLWrap(this->glBinding());
+            newTexParams.fWrapS = wraps[sampler.getWrapX()];
+            newTexParams.fWrapT = wraps[sampler.getWrapY()];
 
             if (newTexParams.fFilter != oldTexParams.fFilter) {
                 setTextureUnit(s);
-                GR_GL(TexParameteri(GR_GL_TEXTURE_2D,
-                                    GR_GL_TEXTURE_MAG_FILTER,
-                                    newTexParams.fFilter));
-                GR_GL(TexParameteri(GR_GL_TEXTURE_2D,
-                                    GR_GL_TEXTURE_MIN_FILTER,
-                                    newTexParams.fFilter));
+                GL_CALL(TexParameteri(GR_GL_TEXTURE_2D,
+                                      GR_GL_TEXTURE_MAG_FILTER,
+                                      newTexParams.fFilter));
+                GL_CALL(TexParameteri(GR_GL_TEXTURE_2D,
+                                      GR_GL_TEXTURE_MIN_FILTER,
+                                      newTexParams.fFilter));
             }
             if (newTexParams.fWrapS != oldTexParams.fWrapS) {
                 setTextureUnit(s);
-                GR_GL(TexParameteri(GR_GL_TEXTURE_2D,
-                                    GR_GL_TEXTURE_WRAP_S,
-                                    newTexParams.fWrapS));
+                GL_CALL(TexParameteri(GR_GL_TEXTURE_2D,
+                                      GR_GL_TEXTURE_WRAP_S,
+                                      newTexParams.fWrapS));
             }
             if (newTexParams.fWrapT != oldTexParams.fWrapT) {
                 setTextureUnit(s);
-                GR_GL(TexParameteri(GR_GL_TEXTURE_2D,
-                                    GR_GL_TEXTURE_WRAP_T,
-                                    newTexParams.fWrapT));
+                GL_CALL(TexParameteri(GR_GL_TEXTURE_2D,
+                                      GR_GL_TEXTURE_WRAP_T,
+                                      newTexParams.fWrapT));
             }
             nextTexture->setTexParams(newTexParams);
         }
@@ -2165,9 +2203,9 @@ bool GrGpuGL::flushGLStateCommon(GrPrimitiveType type) {
     if ((fCurrDrawState.fFlagBits & kDither_StateBit) !=
         (fHWDrawState.fFlagBits & kDither_StateBit)) {
         if (fCurrDrawState.fFlagBits & kDither_StateBit) {
-            GR_GL(Enable(GR_GL_DITHER));
+            GL_CALL(Enable(GR_GL_DITHER));
         } else {
-            GR_GL(Disable(GR_GL_DITHER));
+            GL_CALL(Disable(GR_GL_DITHER));
         }
     }
 
@@ -2179,21 +2217,21 @@ bool GrGpuGL::flushGLStateCommon(GrPrimitiveType type) {
         } else {
             mask = GR_GL_TRUE;
         }
-        GR_GL(ColorMask(mask, mask, mask, mask));
+        GL_CALL(ColorMask(mask, mask, mask, mask));
     }
 
     if (fHWDrawState.fDrawFace != fCurrDrawState.fDrawFace) {
         switch (fCurrDrawState.fDrawFace) {
             case kCCW_DrawFace:
-                GR_GL(Enable(GR_GL_CULL_FACE));
-                GR_GL(CullFace(GR_GL_BACK));
+                GL_CALL(Enable(GR_GL_CULL_FACE));
+                GL_CALL(CullFace(GR_GL_BACK));
                 break;
             case kCW_DrawFace:
-                GR_GL(Enable(GR_GL_CULL_FACE));
-                GR_GL(CullFace(GR_GL_FRONT));
+                GL_CALL(Enable(GR_GL_CULL_FACE));
+                GL_CALL(CullFace(GR_GL_FRONT));
                 break;
             case kBoth_DrawFace:
-                GR_GL(Disable(GR_GL_CULL_FACE));
+                GL_CALL(Disable(GR_GL_CULL_FACE));
                 break;
             default:
                 GrCrash("Unknown draw face.");
@@ -2275,7 +2313,7 @@ bool GrGpuGL::canBeTexture(GrPixelConfig config,
         case kRGBA_8888_GrPixelConfig:
         case kRGBX_8888_GrPixelConfig: // todo: can we tell it our X?
             *format = GR_GL_32BPP_COLOR_FORMAT;
-            if (GR_GL_SUPPORT_ES) {
+            if (kDesktop_GrGLBinding != this->glBinding()) {
                 // according to GL_EXT_texture_format_BGRA8888 the *internal*
                 // format for a BGRA is BGRA not RGBA (as on desktop)
                 *internalFormat = GR_GL_32BPP_COLOR_FORMAT;
@@ -2317,14 +2355,14 @@ bool GrGpuGL::canBeTexture(GrPixelConfig config,
 void GrGpuGL::setTextureUnit(int unit) {
     GrAssert(unit >= 0 && unit < kNumStages);
     if (fActiveTextureUnitIdx != unit) {
-        GR_GL(ActiveTexture(GR_GL_TEXTURE0 + unit));
+        GL_CALL(ActiveTexture(GR_GL_TEXTURE0 + unit));
         fActiveTextureUnitIdx = unit;
     }
 }
 
 void GrGpuGL::setSpareTextureUnit() {
     if (fActiveTextureUnitIdx != (GR_GL_TEXTURE0 + SPARE_TEX_UNIT)) {
-        GR_GL(ActiveTexture(GR_GL_TEXTURE0 + SPARE_TEX_UNIT));
+        GL_CALL(ActiveTexture(GR_GL_TEXTURE0 + SPARE_TEX_UNIT));
         fActiveTextureUnitIdx = SPARE_TEX_UNIT;
     }
 }
@@ -2346,9 +2384,10 @@ bool GrGpuGL::fboInternalFormat(GrPixelConfig config, GrGLenum* format) {
                 return false;
             }
         case kRGB_565_GrPixelConfig:
-            GrAssert(GR_GL_SUPPORT_ES);  // ES2 supports 565. ES1 supports it
-                                         // with FBO extension desktop GL has
-                                         // no such internal format
+            // ES2 supports 565. ES1 supports it
+            // with FBO extension desktop GL has
+            // no such internal format
+            GrAssert(kDesktop_GrGLBinding != this->glBinding());  
             *format = GR_GL_RGB565;
             return true;
         case kRGBA_4444_GrPixelConfig:
@@ -2391,7 +2430,7 @@ void GrGpuGL::setBuffers(bool indexed,
     GrAssert(NULL != vbuf);
     GrAssert(!vbuf->isLocked());
     if (fHWGeometryState.fVertexBuffer != vbuf) {
-        GR_GL(BindBuffer(GR_GL_ARRAY_BUFFER, vbuf->bufferID()));
+        GL_CALL(BindBuffer(GR_GL_ARRAY_BUFFER, vbuf->bufferID()));
         fHWGeometryState.fArrayPtrsDirty = true;
         fHWGeometryState.fVertexBuffer = vbuf;
     }
@@ -2419,7 +2458,7 @@ void GrGpuGL::setBuffers(bool indexed,
         GrAssert(NULL != ibuf);
         GrAssert(!ibuf->isLocked());
         if (fHWGeometryState.fIndexBuffer != ibuf) {
-            GR_GL(BindBuffer(GR_GL_ELEMENT_ARRAY_BUFFER, ibuf->bufferID()));
+            GL_CALL(BindBuffer(GR_GL_ELEMENT_ARRAY_BUFFER, ibuf->bufferID()));
             fHWGeometryState.fIndexBuffer = ibuf;
         }
     }
index 0f0181c4527b5ccefddfd2bb380beb801eb069d3..fc104c1c842283bae6055f768a3f1f24cd3ed2b9 100644 (file)
@@ -24,8 +24,11 @@ class GrGpuGL : public GrGpu {
 public:
     virtual ~GrGpuGL();
 
+    const GrGLInterface* glInterface() const { return fGL; }
+    GrGLBinding glBinding() const { return fGLBinding; }
+
 protected:
-    GrGpuGL();
+    GrGpuGL(const GrGLInterface* glInterface, GrGLBinding glBinding);
 
     struct {
         size_t                  fVertexOffset;
@@ -225,6 +228,9 @@ private:
     // from our loop that tries stencil formats and calls check fb status.
     int fLastSuccessfulStencilFmtIdx;
 
+    const GrGLInterface* fGL;
+    GrGLBinding fGLBinding;
+
     typedef GrGpu INHERITED;
 };
 
index b955eebbc730d32f70f5c946d838c12f8cd725f8..87b051bc9cfe905f36ccdee44fc6111786923b64 100644 (file)
@@ -46,9 +46,22 @@ static const GrGLenum gMatrixMode2Enum[] = {
     GR_GL_MODELVIEW, GR_GL_TEXTURE
 };
 
+#define GL_CALL(X) GR_GL_CALL(this->glInterface(), X)
 ///////////////////////////////////////////////////////////////////////////////
 
-GrGpuGLFixed::GrGpuGLFixed() {
+namespace {
+GrGLBinding get_binding_in_use(const GrGLInterface* gl) {
+    if (gl->supportsDesktop()) {
+        return kDesktop_GrGLBinding;
+    } else {
+        GrAssert(gl->supportsES1());
+        return kES1_GrGLBinding;
+    }
+}
+}
+
+GrGpuGLFixed::GrGpuGLFixed(const GrGLInterface* gl)
+    : GrGpuGL(gl, get_binding_in_use(gl)) {
     f4X4DownsampleFilterSupport = false;
     fDualSourceBlendingSupport = false;
 }
@@ -59,22 +72,42 @@ GrGpuGLFixed::~GrGpuGLFixed() {
 void GrGpuGLFixed::resetContext() {
     INHERITED::resetContext();
 
-    GR_GL(Disable(GR_GL_TEXTURE_2D));
+    GL_CALL(Disable(GR_GL_TEXTURE_2D));
 
     for (int s = 0; s < kNumStages; ++s) {
         setTextureUnit(s);
-        GR_GL(EnableClientState(GR_GL_VERTEX_ARRAY));
-        GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_TEXTURE_ENV_MODE, GR_GL_COMBINE));
-        GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_COMBINE_RGB,   GR_GL_MODULATE));
-        GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_SRC0_RGB,      GR_GL_TEXTURE0+s));
-        GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_SRC1_RGB,      GR_GL_PREVIOUS));
-        GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_OPERAND1_RGB,  GR_GL_SRC_COLOR));
-
-        GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_COMBINE_ALPHA, GR_GL_MODULATE));
-        GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_SRC0_ALPHA, GR_GL_TEXTURE0+s));
-        GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_OPERAND0_ALPHA, GR_GL_SRC_ALPHA));
-        GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_SRC1_ALPHA, GR_GL_PREVIOUS));
-        GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_OPERAND1_ALPHA, GR_GL_SRC_ALPHA));
+        GL_CALL(EnableClientState(GR_GL_VERTEX_ARRAY));
+        GL_CALL(TexEnvi(GR_GL_TEXTURE_ENV,
+                        GR_GL_TEXTURE_ENV_MODE,
+                        GR_GL_COMBINE));
+        GL_CALL(TexEnvi(GR_GL_TEXTURE_ENV,
+                        GR_GL_COMBINE_RGB,
+                        GR_GL_MODULATE));
+        GL_CALL(TexEnvi(GR_GL_TEXTURE_ENV,
+                        GR_GL_SRC0_RGB,
+                        GR_GL_TEXTURE0+s));
+        GL_CALL(TexEnvi(GR_GL_TEXTURE_ENV,
+                        GR_GL_SRC1_RGB,
+                        GR_GL_PREVIOUS));
+        GL_CALL(TexEnvi(GR_GL_TEXTURE_ENV,
+                        GR_GL_OPERAND1_RGB,
+                        GR_GL_SRC_COLOR));
+
+        GL_CALL(TexEnvi(GR_GL_TEXTURE_ENV,
+                        GR_GL_COMBINE_ALPHA,
+                        GR_GL_MODULATE));
+        GL_CALL(TexEnvi(GR_GL_TEXTURE_ENV,
+                        GR_GL_SRC0_ALPHA,
+                        GR_GL_TEXTURE0+s));
+        GL_CALL(TexEnvi(GR_GL_TEXTURE_ENV,
+                        GR_GL_OPERAND0_ALPHA,
+                        GR_GL_SRC_ALPHA));
+        GL_CALL(TexEnvi(GR_GL_TEXTURE_ENV,
+                        GR_GL_SRC1_ALPHA,
+                        GR_GL_PREVIOUS));
+        GL_CALL(TexEnvi(GR_GL_TEXTURE_ENV,
+                        GR_GL_OPERAND1_ALPHA,
+                        GR_GL_SRC_ALPHA));
 
         // color oprand0 changes between GL_SRC_COLR and GL_SRC_ALPHA depending
         // upon whether we have a (premultiplied) RGBA texture or just an ALPHA
@@ -85,14 +118,14 @@ void GrGpuGLFixed::resetContext() {
 
     fHWGeometryState.fVertexLayout = 0;
     fHWGeometryState.fVertexOffset  = ~0;
-    GR_GL(EnableClientState(GR_GL_VERTEX_ARRAY));
-    GR_GL(DisableClientState(GR_GL_TEXTURE_COORD_ARRAY));
-    GR_GL(ShadeModel(GR_GL_FLAT));
-    GR_GL(DisableClientState(GR_GL_COLOR_ARRAY));
+    GL_CALL(EnableClientState(GR_GL_VERTEX_ARRAY));
+    GL_CALL(DisableClientState(GR_GL_TEXTURE_COORD_ARRAY));
+    GL_CALL(ShadeModel(GR_GL_FLAT));
+    GL_CALL(DisableClientState(GR_GL_COLOR_ARRAY));
 
-    GR_GL(PointSize(1.f));
+    GL_CALL(PointSize(1.f));
 
-    GrGLClearErr();
+    GrGLClearErr(this->glInterface());
     fTextVerts = false;
 
     fBaseVertex = 0xffffffff;
@@ -113,8 +146,8 @@ void GrGpuGLFixed::flushProjectionMatrix() {
     mat[12] = -1.f;
     mat[13] = 1.f;
 
-    GR_GL(MatrixMode(GR_GL_PROJECTION));
-    GR_GL(LoadMatrixf(mat));
+    GL_CALL(MatrixMode(GR_GL_PROJECTION));
+    GL_CALL(LoadMatrixf(mat));
 }
 
 bool GrGpuGLFixed::flushGraphicsState(GrPrimitiveType type) {
@@ -129,7 +162,7 @@ bool GrGpuGLFixed::flushGraphicsState(GrPrimitiveType type) {
         }
     }
 
-    if (GR_GL_SUPPORT_ES1) {
+    if (kES1_GrGLBinding == this->glBinding()) {
         if (BlendCoeffReferencesConstant(fCurrDrawState.fSrcBlend) ||
             BlendCoeffReferencesConstant(fCurrDrawState.fDstBlend)) {
             unimpl("ES1 doesn't support blend constant");
@@ -152,9 +185,9 @@ bool GrGpuGLFixed::flushGraphicsState(GrPrimitiveType type) {
         if (usingTextures[s] != wasUsingTexture) {
             setTextureUnit(s);
             if (usingTextures[s]) {
-                GR_GL(Enable(GR_GL_TEXTURE_2D));
+                GL_CALL(Enable(GR_GL_TEXTURE_2D));
             } else {
-                GR_GL(Disable(GR_GL_TEXTURE_2D));
+                GL_CALL(Disable(GR_GL_TEXTURE_2D));
             }
         }
     }
@@ -165,17 +198,17 @@ bool GrGpuGLFixed::flushGraphicsState(GrPrimitiveType type) {
 
     if (vertColor != prevVertColor) {
         if (vertColor) {
-            GR_GL(ShadeModel(GR_GL_SMOOTH));
+            GL_CALL(ShadeModel(GR_GL_SMOOTH));
             // invalidate the immediate mode color
             fHWDrawState.fColor = GrColor_ILLEGAL;
         } else {
-            GR_GL(ShadeModel(GR_GL_FLAT));
+            GL_CALL(ShadeModel(GR_GL_FLAT));
         }
     }
 
 
     if (!vertColor && fHWDrawState.fColor != fCurrDrawState.fColor) {
-        GR_GL(Color4ub(GrColorUnpackR(fCurrDrawState.fColor),
+        GL_CALL(Color4ub(GrColorUnpackR(fCurrDrawState.fColor),
                        GrColorUnpackG(fCurrDrawState.fColor),
                        GrColorUnpackB(fCurrDrawState.fColor),
                        GrColorUnpackA(fCurrDrawState.fColor)));
@@ -193,7 +226,7 @@ bool GrGpuGLFixed::flushGraphicsState(GrPrimitiveType type) {
                         kColor_TextureEnvRGBOperand;
                 if (fHWRGBOperand0[s] != nextRGBOperand0) {
                     setTextureUnit(s);
-                    GR_GL(TexEnvi(GR_GL_TEXTURE_ENV,
+                    GL_CALL(TexEnvi(GR_GL_TEXTURE_ENV,
                                   GR_GL_OPERAND0_RGB,
                                   (nextRGBOperand0==kAlpha_TextureEnvRGBOperand) ?
                                     GR_GL_SRC_ALPHA :
@@ -212,8 +245,8 @@ bool GrGpuGLFixed::flushGraphicsState(GrPrimitiveType type) {
                     GrGpuMatrix glm;
                     glm.set(texMat);
                     setTextureUnit(s);
-                    GR_GL(MatrixMode(GR_GL_TEXTURE));
-                    GR_GL(LoadMatrixf(glm.fMat));
+                    GL_CALL(MatrixMode(GR_GL_TEXTURE));
+                    GL_CALL(LoadMatrixf(glm.fMat));
                     recordHWSamplerMatrix(s, getSamplerMatrix(s));
                 }
             } else {
@@ -226,8 +259,8 @@ bool GrGpuGLFixed::flushGraphicsState(GrPrimitiveType type) {
     if (fHWDrawState.fViewMatrix != fCurrDrawState.fViewMatrix) {
         GrGpuMatrix glm;
         glm.set(fCurrDrawState.fViewMatrix);
-        GR_GL(MatrixMode(GR_GL_MODELVIEW));
-        GR_GL(LoadMatrixf(glm.fMat));
+        GL_CALL(MatrixMode(GR_GL_MODELVIEW));
+        GL_CALL(LoadMatrixf(glm.fMat));
         fHWDrawState.fViewMatrix =
         fCurrDrawState.fViewMatrix;
     }
@@ -285,7 +318,8 @@ void GrGpuGLFixed::setupGeometry(int* startVertex,
                                    this->getGeomSrc().fVertexLayout)));
 
     if (posAndTexChange) {
-        GR_GL(VertexPointer(2, scalarType, newStride, (GrGLvoid*)vertexOffset));
+        GL_CALL(VertexPointer(2, scalarType,
+                              newStride, (GrGLvoid*)vertexOffset));
         fHWGeometryState.fVertexOffset = vertexOffset;
     }
 
@@ -293,32 +327,37 @@ void GrGpuGLFixed::setupGeometry(int* startVertex,
         // need to enable array if tex coord offset is 0
         // (using positions as coords)
         if (newTexCoordOffsets[s] >= 0) {
-            GrGLvoid* texCoordOffset = (GrGLvoid*)(vertexOffset + newTexCoordOffsets[s]);
+            GrGLvoid* texCoordOffset = (GrGLvoid*)(vertexOffset +
+                                                   newTexCoordOffsets[s]);
             if (oldTexCoordOffsets[s] < 0) {
-                GR_GL(ClientActiveTexture(GR_GL_TEXTURE0+s));
-                GR_GL(EnableClientState(GR_GL_TEXTURE_COORD_ARRAY));
-                GR_GL(TexCoordPointer(2, scalarType, newStride, texCoordOffset));
+                GL_CALL(ClientActiveTexture(GR_GL_TEXTURE0+s));
+                GL_CALL(EnableClientState(GR_GL_TEXTURE_COORD_ARRAY));
+                GL_CALL(TexCoordPointer(2, scalarType,
+                                        newStride, texCoordOffset));
             } else if (posAndTexChange ||
                        newTexCoordOffsets[s] != oldTexCoordOffsets[s]) {
-                GR_GL(ClientActiveTexture(GR_GL_TEXTURE0+s));
-                GR_GL(TexCoordPointer(2, scalarType, newStride, texCoordOffset));
+                GL_CALL(ClientActiveTexture(GR_GL_TEXTURE0+s));
+                GL_CALL(TexCoordPointer(2, scalarType,
+                                        newStride, texCoordOffset));
             }
         } else if (oldTexCoordOffsets[s] >= 0) {
-            GR_GL(ClientActiveTexture(GR_GL_TEXTURE0+s));
-            GR_GL(DisableClientState(GR_GL_TEXTURE_COORD_ARRAY));
+            GL_CALL(ClientActiveTexture(GR_GL_TEXTURE0+s));
+            GL_CALL(DisableClientState(GR_GL_TEXTURE_COORD_ARRAY));
         }
     }
 
     if (newColorOffset > 0) {
         GrGLvoid* colorOffset = (GrGLvoid*)(vertexOffset + newColorOffset);
         if (oldColorOffset <= 0) {
-            GR_GL(EnableClientState(GR_GL_COLOR_ARRAY));
-            GR_GL(ColorPointer(4, GR_GL_UNSIGNED_BYTE, newStride, colorOffset));
+            GL_CALL(EnableClientState(GR_GL_COLOR_ARRAY));
+            GL_CALL(ColorPointer(4, GR_GL_UNSIGNED_BYTE,
+                                newStride, colorOffset));
         } else if (allOffsetsChange || newColorOffset != oldColorOffset) {
-            GR_GL(ColorPointer(4, GR_GL_UNSIGNED_BYTE, newStride, colorOffset));
+            GL_CALL(ColorPointer(4, GR_GL_UNSIGNED_BYTE,
+                                 newStride, colorOffset));
         }
     } else if (oldColorOffset > 0) {
-        GR_GL(DisableClientState(GR_GL_COLOR_ARRAY));
+        GL_CALL(DisableClientState(GR_GL_COLOR_ARRAY));
     }
 
     fHWGeometryState.fVertexLayout = this->getGeomSrc().fVertexLayout;
index 7ac044d989adaa1e95a2874f52ff40242199935d..0e624b59dbc6e00847829333b96a37b2247b8992 100644 (file)
@@ -16,7 +16,7 @@
 // Fixed Pipeline OpenGL or OpenGL ES 1.x
 class GrGpuGLFixed : public GrGpuGL {
 public:
-             GrGpuGLFixed();
+             GrGpuGLFixed(const GrGLInterface* glInterface);
     virtual ~GrGpuGLFixed();
 
 protected:
index 96b03dab05559d78f7242f8aa0b9eb4aceb80201..748cf1ac47789b2abb1d4988c18c14ba71a05c3d 100644 (file)
@@ -51,19 +51,20 @@ private:
     enum {
         kMaxEntries = 32
     };
-    Entry        fEntries[kMaxEntries];
-    int          fCount;
-    unsigned int fCurrLRUStamp;
-
+    Entry                 fEntries[kMaxEntries];
+    int                   fCount;
+    unsigned int          fCurrLRUStamp;
+    const GrGLInterface*  fGL;
 public:
-    ProgramCache() 
+    ProgramCache(const GrGLInterface* gl
         : fCount(0)
-        , fCurrLRUStamp(0) {
+        , fCurrLRUStamp(0)
+        , fGL(gl) {
     }
 
     ~ProgramCache() {
         for (int i = 0; i < fCount; ++i) {
-            GrGpuGLShaders::DeleteProgram(&fEntries[i].fProgramData);
+            GrGpuGLShaders::DeleteProgram(fGL, &fEntries[i].fProgramData);
         }
     }
 
@@ -84,7 +85,7 @@ public:
         
         Entry* entry = fHashCache.find(newEntry.fKey);
         if (NULL == entry) {
-            if (!desc.genProgram(&newEntry.fProgramData)) {
+            if (!desc.genProgram(fGL, &newEntry.fProgramData)) {
                 return NULL;
             }
             if (fCount < kMaxEntries) {
@@ -99,7 +100,7 @@ public:
                     }
                 }
                 fHashCache.remove(entry->fKey, entry);
-                GrGpuGLShaders::DeleteProgram(&entry->fProgramData);
+                GrGpuGLShaders::DeleteProgram(fGL, &entry->fProgramData);
             }
             entry->copyAndTakeOwnership(newEntry);
             fHashCache.insert(entry->fKey, entry);
@@ -122,15 +123,18 @@ void GrGpuGLShaders::abandonResources(){
     fProgramCache->abandon();
 }
 
-void GrGpuGLShaders::DeleteProgram(CachedData* programData) {
-    GR_GL(DeleteShader(programData->fVShaderID));
-    GR_GL(DeleteShader(programData->fFShaderID));
-    GR_GL(DeleteProgram(programData->fProgramID));
+void GrGpuGLShaders::DeleteProgram(const GrGLInterface* gl,
+                                   CachedData* programData) {
+    GR_GL_CALL(gl, DeleteShader(programData->fVShaderID));
+    GR_GL_CALL(gl, DeleteShader(programData->fFShaderID));
+    GR_GL_CALL(gl, DeleteProgram(programData->fProgramID));
     GR_DEBUGCODE(memset(programData, 0, sizeof(*programData));)
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 
+#define GL_CALL(X) GR_GL_CALL(this->glInterface(), X)
+
 namespace {
     template <typename T>
     T random_val(GrRandom* r, T count) {
@@ -225,25 +229,37 @@ bool GrGpuGLShaders::programUnitTest() {
             stage.fKernelWidth = 4 * random.nextF() + 2;
         }
         CachedData cachedData;
-        if (!program.genProgram(&cachedData)) {
+        if (!program.genProgram(this->glInterface(), &cachedData)) {
             return false;
         }
-        DeleteProgram(&cachedData);
+        DeleteProgram(this->glInterface(), &cachedData);
         bool again = false;
         if (again) {
-            program.genProgram(&cachedData);
-            DeleteProgram(&cachedData);
+            program.genProgram(this->glInterface(), &cachedData);
+            DeleteProgram(this->glInterface(), &cachedData);
         }
     }
     return true;
 }
 
-GrGpuGLShaders::GrGpuGLShaders() {
+namespace {
+GrGLBinding get_binding_in_use(const GrGLInterface* gl) {
+    if (gl->supportsDesktop()) {
+        return kDesktop_GrGLBinding;
+    } else {
+        GrAssert(gl->supportsES2());
+        return kES2_GrGLBinding;
+    }
+}
+}
+
+GrGpuGLShaders::GrGpuGLShaders(const GrGLInterface* gl)
+    : GrGpuGL(gl, get_binding_in_use(gl)) {
 
     resetContext();
 
     f4X4DownsampleFilterSupport = true;
-    if (GR_GL_SUPPORT_DESKTOP) {
+    if (kDesktop_GrGLBinding == this->glBinding()) {
         fDualSourceBlendingSupport =
                             fGLVersion >= 3.3f ||
                             this->hasExtension("GL_ARB_blend_func_extended");
@@ -252,7 +268,7 @@ GrGpuGLShaders::GrGpuGLShaders() {
     }
 
     fProgramData = NULL;
-    fProgramCache = new ProgramCache();
+    fProgramCache = new ProgramCache(gl);
 
 #if 0
     this->programUnitTest();
@@ -289,11 +305,11 @@ void GrGpuGLShaders::resetContext() {
 
     fHWGeometryState.fVertexLayout = 0;
     fHWGeometryState.fVertexOffset = ~0;
-    GR_GL(DisableVertexAttribArray(GrGLProgram::ColorAttributeIdx()));
+    GL_CALL(DisableVertexAttribArray(GrGLProgram::ColorAttributeIdx()));
     for (int t = 0; t < kMaxTexCoords; ++t) {
-        GR_GL(DisableVertexAttribArray(GrGLProgram::TexCoordAttributeIdx(t)));
+        GL_CALL(DisableVertexAttribArray(GrGLProgram::TexCoordAttributeIdx(t)));
     }
-    GR_GL(EnableVertexAttribArray(GrGLProgram::PositionAttributeIdx()));
+    GL_CALL(EnableVertexAttribArray(GrGLProgram::PositionAttributeIdx()));
 
     fHWProgramID = 0;
 }
@@ -324,14 +340,14 @@ void GrGpuGLShaders::flushViewMatrix() {
     if (GrGLProgram::kSetAsAttribute ==  
         fProgramData->fUniLocations.fViewMatrixUni) {
         int baseIdx = GrGLProgram::ViewMatrixAttributeIdx();
-        GR_GL(VertexAttrib4fv(baseIdx + 0, mt+0));
-        GR_GL(VertexAttrib4fv(baseIdx + 1, mt+3));
-        GR_GL(VertexAttrib4fv(baseIdx + 2, mt+6));
+        GL_CALL(VertexAttrib4fv(baseIdx + 0, mt+0));
+        GL_CALL(VertexAttrib4fv(baseIdx + 1, mt+3));
+        GL_CALL(VertexAttrib4fv(baseIdx + 2, mt+6));
     } else {
         GrAssert(GrGLProgram::kUnusedUniform != 
                  fProgramData->fUniLocations.fViewMatrixUni);
-        GR_GL(UniformMatrix3fv(fProgramData->fUniLocations.fViewMatrixUni,
-                               1, false, mt));
+        GL_CALL(UniformMatrix3fv(fProgramData->fUniLocations.fViewMatrixUni,
+                                 1, false, mt));
     }
 }
 
@@ -370,7 +386,7 @@ void GrGpuGLShaders::flushTextureDomain(int s) {
             values[1] *= SkScalarToFloat(texture->contentScaleY());
             values[3] *= SkScalarToFloat(texture->contentScaleY());
 
-            GR_GL(Uniform4fv(uni, 1, values));
+            GL_CALL(Uniform4fv(uni, 1, values));
         }
     }
 }
@@ -409,11 +425,11 @@ void GrGpuGLShaders::flushTextureMatrix(int s) {
             if (GrGLProgram::kSetAsAttribute ==
                 fProgramData->fUniLocations.fStages[s].fTextureMatrixUni) {
                 int baseIdx = GrGLProgram::TextureMatrixAttributeIdx(s);
-                GR_GL(VertexAttrib4fv(baseIdx + 0, mt+0));
-                GR_GL(VertexAttrib4fv(baseIdx + 1, mt+3));
-                GR_GL(VertexAttrib4fv(baseIdx + 2, mt+6));
+                GL_CALL(VertexAttrib4fv(baseIdx + 0, mt+0));
+                GL_CALL(VertexAttrib4fv(baseIdx + 1, mt+3));
+                GL_CALL(VertexAttrib4fv(baseIdx + 2, mt+6));
             } else {
-                GR_GL(UniformMatrix3fv(uni, 1, false, mt));
+                GL_CALL(UniformMatrix3fv(uni, 1, false, mt));
             }
             recordHWSamplerMatrix(s, getSamplerMatrix(s));
         }
@@ -447,7 +463,7 @@ void GrGpuGLShaders::flushRadial2(int s) {
             GrScalarToFloat(GrMul(radius0, radius0)),
             sampler.isRadial2PosRoot() ? 1.f : -1.f
         };
-        GR_GL(Uniform1fv(uni, 6, values));
+        GL_CALL(Uniform1fv(uni, 6, values));
         fProgramData->fRadial2CenterX1[s] = sampler.getRadial2CenterX1();
         fProgramData->fRadial2Radius0[s]  = sampler.getRadial2Radius0();
         fProgramData->fRadial2PosRoot[s]  = sampler.isRadial2PosRoot();
@@ -458,11 +474,12 @@ void GrGpuGLShaders::flushConvolution(int s) {
     const GrSamplerState& sampler = fCurrDrawState.fSamplerStates[s];
     int kernelUni = fProgramData->fUniLocations.fStages[s].fKernelUni;
     if (GrGLProgram::kUnusedUniform != kernelUni) {
-        GR_GL(Uniform1fv(kernelUni, sampler.getKernelWidth(), sampler.getKernel()));
+        GL_CALL(Uniform1fv(kernelUni, sampler.getKernelWidth(),
+                           sampler.getKernel()));
     }
     int imageIncrementUni = fProgramData->fUniLocations.fStages[s].fImageIncrementUni;
     if (GrGLProgram::kUnusedUniform != imageIncrementUni) {
-        GR_GL(Uniform2fv(imageIncrementUni, 1, sampler.getImageIncrement()));
+        GL_CALL(Uniform2fv(imageIncrementUni, 1, sampler.getImageIncrement()));
     }
 }
 
@@ -475,7 +492,7 @@ void GrGpuGLShaders::flushTexelSize(int s) {
 
             float texelSize[] = {1.f / texture->allocatedWidth(),
                                  1.f / texture->allocatedHeight()};
-            GR_GL(Uniform2fv(uni, 1, texelSize));
+            GL_CALL(Uniform2fv(uni, 1, texelSize));
         }
     }
 }
@@ -493,7 +510,7 @@ void GrGpuGLShaders::flushEdgeAAData() {
             edges[i].fY = -b;
             edges[i].fZ += b * height;
         }
-        GR_GL(Uniform3fv(uni, count, &edges[0].fX));
+        GL_CALL(Uniform3fv(uni, count, &edges[0].fX));
     }
 }
 
@@ -518,7 +535,8 @@ void GrGpuGLShaders::flushColor() {
                 if (fHWDrawState.fColor != fCurrDrawState.fColor) {
                     // OpenGL ES only supports the float varities of glVertexAttrib
                     float c[] = GR_COLOR_TO_VEC4(fCurrDrawState.fColor);
-                    GR_GL(VertexAttrib4fv(GrGLProgram::ColorAttributeIdx(), c));
+                    GL_CALL(VertexAttrib4fv(GrGLProgram::ColorAttributeIdx(), 
+                                            c));
                     fHWDrawState.fColor = fCurrDrawState.fColor;
                 }
                 break;
@@ -528,7 +546,8 @@ void GrGpuGLShaders::flushColor() {
                     float c[] = GR_COLOR_TO_VEC4(fCurrDrawState.fColor);
                     GrAssert(GrGLProgram::kUnusedUniform != 
                              fProgramData->fUniLocations.fColorUni);
-                    GR_GL(Uniform4fv(fProgramData->fUniLocations.fColorUni, 1, c));
+                    GL_CALL(Uniform4fv(fProgramData->fUniLocations.fColorUni,
+                                        1, c));
                     fProgramData->fColor = fCurrDrawState.fColor;
                 }
                 break;
@@ -544,7 +563,7 @@ void GrGpuGLShaders::flushColor() {
             && fProgramData->fColorFilterColor
                 != fCurrDrawState.fColorFilterColor) {
         float c[] = GR_COLOR_TO_VEC4(fCurrDrawState.fColorFilterColor);
-        GR_GL(Uniform4fv(fProgramData->fUniLocations.fColorFilterUni, 1, c));
+        GL_CALL(Uniform4fv(fProgramData->fUniLocations.fColorFilterUni, 1, c));
         fProgramData->fColorFilterColor = fCurrDrawState.fColorFilterColor;
     }
 }
@@ -571,7 +590,7 @@ bool GrGpuGLShaders::flushGraphicsState(GrPrimitiveType type) {
     }
 
     if (fHWProgramID != fProgramData->fProgramID) {
-        GR_GL(UseProgram(fProgramData->fProgramID));
+        GL_CALL(UseProgram(fProgramData->fProgramID));
         fHWProgramID = fProgramData->fProgramID;
     }
     GrBlendCoeff srcCoeff = fCurrDrawState.fSrcBlend;
@@ -669,7 +688,7 @@ void GrGpuGLShaders::setupGeometry(int* startVertex,
 
     if (posAndTexChange) {
         int idx = GrGLProgram::PositionAttributeIdx();
-        GR_GL(VertexAttribPointer(idx, 2, scalarType, false, newStride, 
+        GL_CALL(VertexAttribPointer(idx, 2, scalarType, false, newStride, 
                                   (GrGLvoid*)vertexOffset));
         fHWGeometryState.fVertexOffset = vertexOffset;
     }
@@ -679,16 +698,16 @@ void GrGpuGLShaders::setupGeometry(int* startVertex,
             GrGLvoid* texCoordOffset = (GrGLvoid*)(vertexOffset + newTexCoordOffsets[t]);
             int idx = GrGLProgram::TexCoordAttributeIdx(t);
             if (oldTexCoordOffsets[t] <= 0) {
-                GR_GL(EnableVertexAttribArray(idx));
-                GR_GL(VertexAttribPointer(idx, 2, scalarType, texCoordNorm, 
+                GL_CALL(EnableVertexAttribArray(idx));
+                GL_CALL(VertexAttribPointer(idx, 2, scalarType, texCoordNorm, 
                                           newStride, texCoordOffset));
             } else if (posAndTexChange ||
                        newTexCoordOffsets[t] != oldTexCoordOffsets[t]) {
-                GR_GL(VertexAttribPointer(idx, 2, scalarType, texCoordNorm, 
+                GL_CALL(VertexAttribPointer(idx, 2, scalarType, texCoordNorm, 
                                           newStride, texCoordOffset));
             }
         } else if (oldTexCoordOffsets[t] > 0) {
-            GR_GL(DisableVertexAttribArray(GrGLProgram::TexCoordAttributeIdx(t)));
+            GL_CALL(DisableVertexAttribArray(GrGLProgram::TexCoordAttributeIdx(t)));
         }
     }
 
@@ -696,15 +715,15 @@ void GrGpuGLShaders::setupGeometry(int* startVertex,
         GrGLvoid* colorOffset = (int8_t*)(vertexOffset + newColorOffset);
         int idx = GrGLProgram::ColorAttributeIdx();
         if (oldColorOffset <= 0) {
-            GR_GL(EnableVertexAttribArray(idx));
-            GR_GL(VertexAttribPointer(idx, 4, GR_GL_UNSIGNED_BYTE,
+            GL_CALL(EnableVertexAttribArray(idx));
+            GL_CALL(VertexAttribPointer(idx, 4, GR_GL_UNSIGNED_BYTE,
                                       true, newStride, colorOffset));
         } else if (allOffsetsChange || newColorOffset != oldColorOffset) {
-            GR_GL(VertexAttribPointer(idx, 4, GR_GL_UNSIGNED_BYTE,
+            GL_CALL(VertexAttribPointer(idx, 4, GR_GL_UNSIGNED_BYTE,
                                       true, newStride, colorOffset));
         }
     } else if (oldColorOffset > 0) {
-        GR_GL(DisableVertexAttribArray(GrGLProgram::ColorAttributeIdx()));
+        GL_CALL(DisableVertexAttribArray(GrGLProgram::ColorAttributeIdx()));
     }
 
     fHWGeometryState.fVertexLayout = this->getGeomSrc().fVertexLayout;
index be6f64e06858d41c43909192a99a22d794a7d5a3..6d9cccd38b1954580822530b9c01dcaef8a7a541 100644 (file)
@@ -19,7 +19,7 @@ class GrGpuGLProgram;
 // Programmable OpenGL or OpenGL ES 2.0
 class GrGpuGLShaders : public GrGpuGL {
 public:
-             GrGpuGLShaders();
+             GrGpuGLShaders(const GrGLInterface* glInterface);
     virtual ~GrGpuGLShaders();
 
     virtual void resetContext();
@@ -74,7 +74,8 @@ private:
     // flushes the edges for edge AA
     void flushEdgeAAData();
 
-    static void DeleteProgram(CachedData* programData);
+    static void DeleteProgram(const GrGLInterface* gl,
+                              CachedData* programData);
 
     void buildProgram(GrPrimitiveType type);
 
index 033a93cd2e5f878723c8d0799b3050d3b11a4872..1976cdf3bc0ba2c89bc668ab1f562c6a524f11db 100644 (file)
 
 #include "gl2.h"
 #include "gl2ext.h"
-/*
-#include "gpu/GLES2/gl2.h"
-#include "gpu/GLES2/gl2ext.h"
-*/
-void GrGLSetDefaultGLInterface() {
-  static GrGLInterface cmd_buffer_interface = {
-    kES2_GrGLBinding,
-    kProbe_GrGLCapability,  // fNPOTRenderTargetSupport
-    kProbe_GrGLCapability,  // fMinRenderTargetHeight
-    kProbe_GrGLCapability,  // fMinRenderTargetWidth
-    glActiveTexture,
-    glAttachShader,
-    glBindAttribLocation,
-    glBindBuffer,
-    glBindTexture,
-    glBlendColor,
-    glBlendFunc,
-    glBufferData,
-    glBufferSubData,
-    glClear,
-    glClearColor,
-    glClearStencil,
-    NULL,  // glClientActiveTexture
-    NULL,  // glColor4ub
-    glColorMask,
-    NULL,  // glColorPointer
-    glCompileShader,
-    glCompressedTexImage2D,
-    glCreateProgram,
-    glCreateShader,
-    glCullFace,
-    glDeleteBuffers,
-    glDeleteProgram,
-    glDeleteShader,
-    glDeleteTextures,
-    glDepthMask,
-    glDisable,
-    NULL,  // glDisableClientState
-    glDisableVertexAttribArray,
-    glDrawArrays,
-    NULL, // glDrawBuffer
-    NULL, // glDrawBuffers
-    glDrawElements,
-    glEnable,
-    NULL,  // glEnableClientState
-    glEnableVertexAttribArray,
-    glFrontFace,
-    glGenBuffers,
-    glGenTextures,
-    glGetBufferParameteriv,
-    glGetError,
-    glGetIntegerv,
-    glGetProgramInfoLog,
-    glGetProgramiv,
-    glGetShaderInfoLog,
-    glGetShaderiv,
-    glGetString,
-    NULL, // glGetTexLevelParameteriv
-    glGetUniformLocation,
-    glLineWidth,
-    glLinkProgram,
-    NULL,  // glLoadMatrixf
-    NULL,  // glMatrixMode
-    glPixelStorei,
-    NULL,  // glPointSize
-    NULL, // glReadBuffer
-    glReadPixels,
-    glScissor,
-    NULL,  // glShadeModel
-    glShaderSource,
-    glStencilFunc,
-    glStencilFuncSeparate,
-    glStencilMask,
-    glStencilMaskSeparate,
-    glStencilOp,
-    glStencilOpSeparate,
-    NULL,  // glTexCoordPointer
-    NULL,  // glTexEnvi
-    glTexImage2D,
-    glTexParameteri,
-    glTexSubImage2D,
-    glUniform1f,
-    glUniform1i,
-    glUniform1fv,
-    glUniform1iv,
-    glUniform2f,
-    glUniform2i,
-    glUniform2fv,
-    glUniform2iv,
-    glUniform3f,
-    glUniform3i,
-    glUniform3fv,
-    glUniform3iv,
-    glUniform4f,
-    glUniform4i,
-    glUniform4fv,
-    glUniform4iv,
-    glUniformMatrix2fv,
-    glUniformMatrix3fv,
-    glUniformMatrix4fv,
-    glUseProgram,
-    glVertexAttrib4fv,
-    glVertexAttribPointer,
-    NULL,  // glVertexPointer
-    glViewport,
-    glBindFramebuffer,
-    glBindRenderbuffer,
-    glCheckFramebufferStatus,
-    glDeleteFramebuffers,
-    glDeleteRenderbuffers,
-    glFramebufferRenderbuffer,
-    glFramebufferTexture2D,
-    glGenFramebuffers,
-    glGenRenderbuffers,
-    glGetFramebufferAttachmentParameteriv,
-    glGetRenderbufferParameteriv,
-    glRenderbufferStorage,
-    NULL,  // glRenderbufferStorageMultisampleEXT,
-    NULL,  // glBlitFramebufferEXT,
-    NULL,  // glResolveMultisampleFramebuffer
-    glMapBufferOES,
-    glUnmapBufferOES,
-    NULL, // glBindFragDataLocationIndexed
-    GrGLInterface::kStaticInitEndGuard
-  };
-  static bool host_StubGL_initialized = false;
-  if (!host_StubGL_initialized) {
-    GrGLSetGLInterface(&cmd_buffer_interface);
-    host_StubGL_initialized = true;
-  }
+
+void GrGLInitializeDefaultGLInterface() {
+    GrGLSetGLInterface* glInterface = new GrGLInterface;
+
+    glInterface->fBindingsExported = kES2_GrGLBinding;
+    glInterface->fActiveTexture = glActiveTexture;
+    glInterface->fAttachShader = glAttachShader;
+    glInterface->fBindAttribLocation = glBindAttribLocation;
+    glInterface->fBindBuffer = glBindBuffer;
+    glInterface->fBindTexture = glBindTexture;
+    glInterface->fBlendColor = glBlendColor;
+    glInterface->fBlendFunc = glBlendFunc;
+    glInterface->fBufferData = glBufferData;
+    glInterface->fBufferSubData = glBufferSubData;
+    glInterface->fClear = glClear;
+    glInterface->fClearColor = glClearColor;
+    glInterface->fClearStencil = glClearStencil;
+    glInterface->fColorMask = glColorMask;
+    glInterface->fCompileShader = glCompileShader;
+    glInterface->fCompressedTexImage2D = glCompressedTexImage2D;
+    glInterface->fCreateProgram = glCreateProgram;
+    glInterface->fCreateShader = glCreateShader;
+    glInterface->fCullFace = glCullFace;
+    glInterface->fDeleteBuffers = glDeleteBuffers;
+    glInterface->fDeleteProgram = glDeleteProgram;
+    glInterface->fDeleteShader = glDeleteShader;
+    glInterface->fDeleteTextures = glDeleteTextures;
+    glInterface->fDepthMask = glDepthMask;
+    glInterface->fDisable = glDisable;
+    glInterface->fDisableVertexAttribArray = glDisableVertexAttribArray;
+    glInterface->fDrawArrays = glDrawArrays;
+    glInterface->fDrawElements = glDrawElements;
+    glInterface->fEnable = glEnable;
+    glInterface->fEnableVertexAttribArray = glEnableVertexAttribArray;
+    glInterface->fFrontFace = glFrontFace;
+    glInterface->fGenBuffers = glGenBuffers;
+    glInterface->fGenTextures = glGenTextures;
+    glInterface->fGetBufferParameteriv = glGetBufferParameteriv;
+    glInterface->fGetError = glGetError;
+    glInterface->fGetIntegerv = glGetIntegerv;
+    glInterface->fGetProgramInfoLog = glGetProgramInfoLog;
+    glInterface->fGetProgramiv = glGetProgramiv;
+    glInterface->fGetShaderInfoLog = glGetShaderInfoLog;
+    glInterface->fGetShaderiv = glGetShaderiv;
+    glInterface->fGetString = glGetString;
+    glInterface->fGetUniformLocation = glGetUniformLocation;
+    glInterface->fLineWidth = glLineWidth;
+    glInterface->fLinkProgram = glLinkProgram;
+    glInterface->fPixelStorei = glPixelStorei;
+    glInterface->fReadPixels = glReadPixels;
+    glInterface->fScissor = glScissor;
+    glInterface->fShaderSource = glShaderSource;
+    glInterface->fStencilFunc = glStencilFunc;
+    glInterface->fStencilFuncSeparate = glStencilFuncSeparate;
+    glInterface->fStencilMask = glStencilMask;
+    glInterface->fStencilMaskSeparate = glStencilMaskSeparate;
+    glInterface->fStencilOp = glStencilOp;
+    glInterface->fStencilOpSeparate = glStencilOpSeparate;
+    glInterface->fTexImage2D = glTexImage2D;
+    glInterface->fTexParameteri = glTexParameteri;
+    glInterface->fTexSubImage2D = glTexSubImage2D;
+    glInterface->fUniform1f = glUniform1f;
+    glInterface->fUniform1i = glUniform1i;
+    glInterface->fUniform1fv = glUniform1fv;
+    glInterface->fUniform1iv = glUniform1iv;
+    glInterface->fUniform2f = glUniform2f;
+    glInterface->fUniform2i = glUniform2i;
+    glInterface->fUniform2fv = glUniform2fv;
+    glInterface->fUniform2iv = glUniform2iv;
+    glInterface->fUniform3f = glUniform3f;
+    glInterface->fUniform3i = glUniform3i;
+    glInterface->fUniform3fv = glUniform3fv;
+    glInterface->fUniform3iv = glUniform3iv;
+    glInterface->fUniform4f = glUniform4f;
+    glInterface->fUniform4i = glUniform4i;
+    glInterface->fUniform4fv = glUniform4fv;
+    glInterface->fUniform4iv = glUniform4iv;
+    glInterface->fUniformMatrix2fv = glUniformMatrix2fv;
+    glInterface->fUniformMatrix3fv = glUniformMatrix3fv;
+    glInterface->fUniformMatrix4fv = glUniformMatrix4fv;
+    glInterface->fUseProgram = glUseProgram;
+    glInterface->fVertexAttrib4fv = glVertexAttrib4fv;
+    glInterface->fVertexAttribPointer = glVertexAttribPointer;
+    glInterface->fViewport = glViewport;
+    glInterface->fBindFramebuffer = glBindFramebuffer;
+    glInterface->fBindRenderbuffer = glBindRenderbuffer;
+    glInterface->fCheckFramebufferStatus = glCheckFramebufferStatus;
+    glInterface->fDeleteFramebuffers = glDeleteFramebuffers;
+    glInterface->fDeleteRenderbuffers = glDeleteRenderbuffers;
+    glInterface->fFramebufferRenderbuffer = glFramebufferRenderbuffer;
+    glInterface->fFramebufferTexture2D = glFramebufferTexture2D;
+    glInterface->fGenFramebuffers = glGenFramebuffers;
+    glInterface->fGenRenderbuffers = glGenRenderbuffers;
+    glInterface->fGetFramebufferAttachmentParameteriv = glGetFramebufferAttachmentParameteriv;
+    glInterface->fGetRenderbufferParameteriv = glGetRenderbufferParameteriv;
+    glInterface->fRenderbufferStorage = glRenderbufferStorage;
+    glInterface->fMapBufferOES = glMapBufferOES;
+    glInterface->fUnmapBufferOES = glUnmapBufferOES;
+
+    GrGLSetDefaultInterface(glInterface)->unref();
 }
index 7bdbcc70794be37aac9469aa04edcc54e0f8a305..6f5b28b463e9bfca7a3f6f0ff6bd86d1dc68c562 100644 (file)
 #import <OpenGLES/ES2/gl.h>
 #import <OpenGLES/ES2/glext.h>
 
-void GrGLSetDefaultGLInterface() {
-    static GrGLInterface gDefaultInterface;
-    static bool gDefaultInterfaceInit;
-    if (!gDefaultInterfaceInit) {
-        gDefaultInterface.fNPOTRenderTargetSupport = kProbe_GrGLCapability;
-        gDefaultInterface.fMinRenderTargetHeight = kProbe_GrGLCapability;
-        gDefaultInterface.fMinRenderTargetWidth = kProbe_GrGLCapability;
-        
-        gDefaultInterface.fActiveTexture = glActiveTexture;
-        gDefaultInterface.fAttachShader = glAttachShader;
-        gDefaultInterface.fBindAttribLocation = glBindAttribLocation;
-        gDefaultInterface.fBindBuffer = glBindBuffer;
-        gDefaultInterface.fBindTexture = glBindTexture;
-        gDefaultInterface.fBlendColor = glBlendColor;
-        gDefaultInterface.fBlendFunc = glBlendFunc;
-        gDefaultInterface.fBufferData = (GrGLBufferDataProc)glBufferData;
-        gDefaultInterface.fBufferSubData = (GrGLBufferSubDataProc)glBufferSubData;
-        gDefaultInterface.fClear = glClear;
-        gDefaultInterface.fClearColor = glClearColor;
-        gDefaultInterface.fClearStencil = glClearStencil;
-        gDefaultInterface.fClientActiveTexture = glClientActiveTexture;
-        gDefaultInterface.fColorMask = glColorMask;
-        gDefaultInterface.fColorPointer = glColorPointer;
-        gDefaultInterface.fColor4ub = glColor4ub;
-        gDefaultInterface.fCompileShader = glCompileShader;
-        gDefaultInterface.fCompressedTexImage2D = glCompressedTexImage2D;
-        gDefaultInterface.fCreateProgram = glCreateProgram;
-        gDefaultInterface.fCreateShader = glCreateShader;
-        gDefaultInterface.fCullFace = glCullFace;
-        gDefaultInterface.fDeleteBuffers = glDeleteBuffers;
-        gDefaultInterface.fDeleteProgram = glDeleteProgram;
-        gDefaultInterface.fDeleteShader = glDeleteShader;
-        gDefaultInterface.fDeleteTextures = glDeleteTextures;
-        gDefaultInterface.fDepthMask = glDepthMask;
-        gDefaultInterface.fDisable = glDisable;
-        gDefaultInterface.fDisableClientState = glDisableClientState;
-        gDefaultInterface.fDisableVertexAttribArray =
-        glDisableVertexAttribArray;
-        gDefaultInterface.fDrawArrays = glDrawArrays;
-        gDefaultInterface.fDrawElements = glDrawElements;
-        gDefaultInterface.fEnable = glEnable;
-        gDefaultInterface.fEnableClientState = glEnableClientState;
-        gDefaultInterface.fEnableVertexAttribArray = glEnableVertexAttribArray;
-        gDefaultInterface.fFrontFace = glFrontFace;
-        gDefaultInterface.fGenBuffers = glGenBuffers;
-        gDefaultInterface.fGetBufferParameteriv = glGetBufferParameteriv;
-        gDefaultInterface.fGetError = glGetError;
-        gDefaultInterface.fGetIntegerv = glGetIntegerv;
-        gDefaultInterface.fGetProgramInfoLog = glGetProgramInfoLog;
-        gDefaultInterface.fGetProgramiv = glGetProgramiv;
-        gDefaultInterface.fGetShaderInfoLog = glGetShaderInfoLog;
-        gDefaultInterface.fGetShaderiv = glGetShaderiv;
-        gDefaultInterface.fGetString = glGetString;
-        gDefaultInterface.fGenTextures = glGenTextures;
-        gDefaultInterface.fGetUniformLocation = glGetUniformLocation;
-        gDefaultInterface.fLineWidth = glLineWidth;
-        gDefaultInterface.fLinkProgram = glLinkProgram;
-        gDefaultInterface.fLoadMatrixf = glLoadMatrixf;
-        gDefaultInterface.fMatrixMode = glMatrixMode;
-        gDefaultInterface.fPointSize = glPointSize;
-        gDefaultInterface.fPixelStorei = glPixelStorei;
-        gDefaultInterface.fReadBuffer = NULL; 
-        gDefaultInterface.fReadPixels = glReadPixels;
-        gDefaultInterface.fScissor = glScissor;
-        gDefaultInterface.fShadeModel = glShadeModel;
-        gDefaultInterface.fShaderSource = glShaderSource;
-        gDefaultInterface.fStencilFunc = glStencilFunc;
-        gDefaultInterface.fStencilFuncSeparate = glStencilFuncSeparate;
-        gDefaultInterface.fStencilMask = glStencilMask;
-        gDefaultInterface.fStencilMaskSeparate = glStencilMaskSeparate;
-        gDefaultInterface.fStencilOp = glStencilOp;
-        gDefaultInterface.fStencilOpSeparate = glStencilOpSeparate;
-        gDefaultInterface.fTexCoordPointer = glTexCoordPointer;
-        gDefaultInterface.fTexEnvi = glTexEnvi;
-        // mac uses GLenum for internalFormat param (non-standard)
-        // amounts to int vs. uint.
-        gDefaultInterface.fTexImage2D = (GrGLTexImage2DProc)glTexImage2D;
-        gDefaultInterface.fTexParameteri = glTexParameteri;
-        gDefaultInterface.fTexSubImage2D = glTexSubImage2D;
-        gDefaultInterface.fUniform1f = glUniform1f;
-        gDefaultInterface.fUniform1i = glUniform1i;
-        gDefaultInterface.fUniform1fv = glUniform1fv;
-        gDefaultInterface.fUniform1iv = glUniform1iv;
-        gDefaultInterface.fUniform2f = glUniform2f;
-        gDefaultInterface.fUniform2i = glUniform2i;
-        gDefaultInterface.fUniform2fv = glUniform2fv;
-        gDefaultInterface.fUniform2iv = glUniform2iv;
-        gDefaultInterface.fUniform3f = glUniform3f;
-        gDefaultInterface.fUniform3i = glUniform3i;
-        gDefaultInterface.fUniform3fv = glUniform3fv;
-        gDefaultInterface.fUniform3iv = glUniform3iv;
-        gDefaultInterface.fUniform4f = glUniform4f;
-        gDefaultInterface.fUniform4i = glUniform4i;
-        gDefaultInterface.fUniform4fv = glUniform4fv;
-        gDefaultInterface.fUniform4iv = glUniform4iv;
-        gDefaultInterface.fUniform4fv = glUniform4fv;
-        gDefaultInterface.fUniformMatrix2fv = glUniformMatrix2fv;
-        gDefaultInterface.fUniformMatrix3fv = glUniformMatrix3fv;
-        gDefaultInterface.fUniformMatrix4fv = glUniformMatrix4fv;
-        gDefaultInterface.fUseProgram = glUseProgram;
-        gDefaultInterface.fVertexAttrib4fv = glVertexAttrib4fv;
-        gDefaultInterface.fVertexAttribPointer = glVertexAttribPointer;
-        gDefaultInterface.fVertexPointer = glVertexPointer;
-        gDefaultInterface.fViewport = glViewport;
-        
-        gDefaultInterface.fGenFramebuffers = glGenFramebuffers;
-        gDefaultInterface.fGetFramebufferAttachmentParameteriv = glGetFramebufferAttachmentParameteriv;
-        gDefaultInterface.fGetRenderbufferParameteriv = glGetRenderbufferParameteriv;
-        gDefaultInterface.fBindFramebuffer = glBindFramebuffer;
-        gDefaultInterface.fFramebufferTexture2D = glFramebufferTexture2D;
-        gDefaultInterface.fCheckFramebufferStatus = glCheckFramebufferStatus;
-        gDefaultInterface.fDeleteFramebuffers = glDeleteFramebuffers;
-        gDefaultInterface.fRenderbufferStorage = glRenderbufferStorage;
-        gDefaultInterface.fGenRenderbuffers = glGenRenderbuffers;
-        gDefaultInterface.fDeleteRenderbuffers = glDeleteRenderbuffers;
-        gDefaultInterface.fFramebufferRenderbuffer = glFramebufferRenderbuffer;
-        gDefaultInterface.fBindRenderbuffer = glBindRenderbuffer;
+void GrGLInitializeDefaultGLInterface() {
+    GrGLInterface* defaultInterface = new GrGLInterface();
+
+    defaultInterface->fNPOTRenderTargetSupport = kProbe_GrGLCapability;
+    defaultInterface->fMinRenderTargetHeight = kProbe_GrGLCapability;
+    defaultInterface->fMinRenderTargetWidth = kProbe_GrGLCapability;
+    defaultInterface->fActiveTexture = glActiveTexture;
+    defaultInterface->fAttachShader = glAttachShader;
+    defaultInterface->fBindAttribLocation = glBindAttribLocation;
+    defaultInterface->fBindBuffer = glBindBuffer;
+    defaultInterface->fBindTexture = glBindTexture;
+    defaultInterface->fBlendColor = glBlendColor;
+    defaultInterface->fBlendFunc = glBlendFunc;
+    defaultInterface->fBufferData = (GrGLBufferDataProc)glBufferData;
+    defaultInterface->fBufferSubData = (GrGLBufferSubDataProc)glBufferSubData;
+    defaultInterface->fClear = glClear;
+    defaultInterface->fClearColor = glClearColor;
+    defaultInterface->fClearStencil = glClearStencil;
+    defaultInterface->fClientActiveTexture = glClientActiveTexture;
+    defaultInterface->fColorMask = glColorMask;
+    defaultInterface->fColorPointer = glColorPointer;
+    defaultInterface->fColor4ub = glColor4ub;
+    defaultInterface->fCompileShader = glCompileShader;
+    defaultInterface->fCompressedTexImage2D = glCompressedTexImage2D;
+    defaultInterface->fCreateProgram = glCreateProgram;
+    defaultInterface->fCreateShader = glCreateShader;
+    defaultInterface->fCullFace = glCullFace;
+    defaultInterface->fDeleteBuffers = glDeleteBuffers;
+    defaultInterface->fDeleteProgram = glDeleteProgram;
+    defaultInterface->fDeleteShader = glDeleteShader;
+    defaultInterface->fDeleteTextures = glDeleteTextures;
+    defaultInterface->fDepthMask = glDepthMask;
+    defaultInterface->fDisable = glDisable;
+    defaultInterface->fDisableClientState = glDisableClientState;
+    defaultInterface->fDisableVertexAttribArray =
+    glDisableVertexAttribArray;
+    defaultInterface->fDrawArrays = glDrawArrays;
+    defaultInterface->fDrawBuffer = NULL;
+    defaultInterface->fDrawBuffers = NULL;
+    defaultInterface->fDrawElements = glDrawElements;
+    defaultInterface->fEnable = glEnable;
+    defaultInterface->fEnableClientState = glEnableClientState;
+    defaultInterface->fEnableVertexAttribArray = glEnableVertexAttribArray;
+    defaultInterface->fFrontFace = glFrontFace;
+    defaultInterface->fGenBuffers = glGenBuffers;
+    defaultInterface->fGetBufferParameteriv = glGetBufferParameteriv;
+    defaultInterface->fGetError = glGetError;
+    defaultInterface->fGetIntegerv = glGetIntegerv;
+    defaultInterface->fGetProgramInfoLog = glGetProgramInfoLog;
+    defaultInterface->fGetProgramiv = glGetProgramiv;
+    defaultInterface->fGetShaderInfoLog = glGetShaderInfoLog;
+    defaultInterface->fGetShaderiv = glGetShaderiv;
+    defaultInterface->fGetString = glGetString;
+    defaultInterface->fGenTextures = glGenTextures;
+    defaultInterface->fGetUniformLocation = glGetUniformLocation;
+    defaultInterface->fLineWidth = glLineWidth;
+    defaultInterface->fLinkProgram = glLinkProgram;
+    defaultInterface->fLoadMatrixf = glLoadMatrixf;
+    defaultInterface->fMatrixMode = glMatrixMode;
+    defaultInterface->fPointSize = glPointSize;
+    defaultInterface->fPixelStorei = glPixelStorei;
+    defaultInterface->fReadBuffer = NULL;
+    defaultInterface->fReadPixels = glReadPixels;
+    defaultInterface->fScissor = glScissor;
+    defaultInterface->fShadeModel = glShadeModel;
+    defaultInterface->fShaderSource = glShaderSource;
+    defaultInterface->fStencilFunc = glStencilFunc;
+    defaultInterface->fStencilFuncSeparate = glStencilFuncSeparate;
+    defaultInterface->fStencilMask = glStencilMask;
+    defaultInterface->fStencilMaskSeparate = glStencilMaskSeparate;
+    defaultInterface->fStencilOp = glStencilOp;
+    defaultInterface->fStencilOpSeparate = glStencilOpSeparate;
+    defaultInterface->fTexCoordPointer = glTexCoordPointer;
+    defaultInterface->fTexEnvi = glTexEnvi;
+    // mac uses GLenum for internalFormat param (non-standard)
+    // amounts to int vs. uint.
+    defaultInterface->fTexImage2D = (GrGLTexImage2DProc)glTexImage2D;
+    defaultInterface->fTexParameteri = glTexParameteri;
+    defaultInterface->fTexSubImage2D = glTexSubImage2D;
+    defaultInterface->fUniform1f = glUniform1f;
+    defaultInterface->fUniform1i = glUniform1i;
+    defaultInterface->fUniform1fv = glUniform1fv;
+    defaultInterface->fUniform1iv = glUniform1iv;
+    defaultInterface->fUniform2f = glUniform2f;
+    defaultInterface->fUniform2i = glUniform2i;
+    defaultInterface->fUniform2fv = glUniform2fv;
+    defaultInterface->fUniform2iv = glUniform2iv;
+    defaultInterface->fUniform3f = glUniform3f;
+    defaultInterface->fUniform3i = glUniform3i;
+    defaultInterface->fUniform3fv = glUniform3fv;
+    defaultInterface->fUniform3iv = glUniform3iv;
+    defaultInterface->fUniform4f = glUniform4f;
+    defaultInterface->fUniform4i = glUniform4i;
+    defaultInterface->fUniform4fv = glUniform4fv;
+    defaultInterface->fUniform4iv = glUniform4iv;
+    defaultInterface->fUniform4fv = glUniform4fv;
+    defaultInterface->fUniformMatrix2fv = glUniformMatrix2fv;
+    defaultInterface->fUniformMatrix3fv = glUniformMatrix3fv;
+    defaultInterface->fUniformMatrix4fv = glUniformMatrix4fv;
+    defaultInterface->fUseProgram = glUseProgram;
+    defaultInterface->fVertexAttrib4fv = glVertexAttrib4fv;
+    defaultInterface->fVertexAttribPointer = glVertexAttribPointer;
+    defaultInterface->fVertexPointer = glVertexPointer;
+    defaultInterface->fViewport = glViewport;
+    defaultInterface->fGenFramebuffers = glGenFramebuffers;
+    defaultInterface->fGetFramebufferAttachmentParameteriv = glGetFramebufferAttachmentParameteriv;
+    defaultInterface->fGetRenderbufferParameteriv = glGetRenderbufferParameteriv;
+    defaultInterface->fBindFramebuffer = glBindFramebuffer;
+    defaultInterface->fFramebufferTexture2D = glFramebufferTexture2D;
+    defaultInterface->fCheckFramebufferStatus = glCheckFramebufferStatus;
+    defaultInterface->fDeleteFramebuffers = glDeleteFramebuffers;
+    defaultInterface->fRenderbufferStorage = glRenderbufferStorage;
+    defaultInterface->fGenRenderbuffers = glGenRenderbuffers;
+    defaultInterface->fDeleteRenderbuffers = glDeleteRenderbuffers;
+    defaultInterface->fFramebufferRenderbuffer = glFramebufferRenderbuffer;
+    defaultInterface->fBindRenderbuffer = glBindRenderbuffer;
        
 #if GL_OES_mapbuffer
-        gDefaultInterface.fMapBuffer = glMapBufferOES;
-        gDefaultInterface.fUnmapBuffer = glUnmapBufferOES;
+    defaultInterface->fMapBuffer = glMapBufferOES;
+    defaultInterface->fUnmapBuffer = glUnmapBufferOES;
 #endif
         
 #if GL_APPLE_framebuffer_multisample
-        gDefaultInterface.fRenderbufferStorageMultisample = glRenderbufferStorageMultisampleAPPLE;
-        gDefaultInterface.fResolveMultisampleFramebuffer = glResolveMultisampleFramebufferAPPLE;
+    defaultInterface->fRenderbufferStorageMultisample = glRenderbufferStorageMultisampleAPPLE;
+    defaultInterface->fResolveMultisampleFramebuffer = glResolveMultisampleFramebufferAPPLE;
 #endif
-        gDefaultInterface.fBindFragDataLocationIndexed = NULL;
+    defaultInterface->fBindFragDataLocationIndexed = NULL;
         
-        gDefaultInterface.fBindingsExported = kES2_GrGLBinding;
-        
-        gDefaultInterfaceInit = true;
-    }
-    GrGLSetGLInterface(&gDefaultInterface);
+    defaultInterface->fBindingsExported = kES2_GrGLBinding | kES1_GrGLBinding;
+
+    GrGLSetDefaultGLInterface(&defaultInterface)->unref();
 }
\ No newline at end of file
index 293f14c114dcf805f118f1ff77b0593dbcde19b5..3901797be92c3824634403bd0f56f0cca571c4d3 100644 (file)
 #include <OpenGL/gl.h>
 #include <OpenGL/glext.h>
 
-void GrGLSetDefaultGLInterface() {
-    static GrGLInterface gDefaultInterface;
-    static bool gDefaultInterfaceInit;
-    if (!gDefaultInterfaceInit) {
-        gDefaultInterface.fNPOTRenderTargetSupport = kProbe_GrGLCapability;
-        gDefaultInterface.fMinRenderTargetHeight = kProbe_GrGLCapability;
-        gDefaultInterface.fMinRenderTargetWidth = kProbe_GrGLCapability;
-
-        gDefaultInterface.fActiveTexture = glActiveTexture;
-        gDefaultInterface.fAttachShader = glAttachShader;
-        gDefaultInterface.fBindAttribLocation = glBindAttribLocation;
-        gDefaultInterface.fBindBuffer = glBindBuffer;
-        gDefaultInterface.fBindTexture = glBindTexture;
-        gDefaultInterface.fBlendColor = glBlendColor;
-        gDefaultInterface.fBlendFunc = glBlendFunc;
-        gDefaultInterface.fBufferData = glBufferData;
-        gDefaultInterface.fBufferSubData = glBufferSubData;
-        gDefaultInterface.fClear = glClear;
-        gDefaultInterface.fClearColor = glClearColor;
-        gDefaultInterface.fClearStencil = glClearStencil;
-        gDefaultInterface.fClientActiveTexture = glClientActiveTexture;
-        gDefaultInterface.fColorMask = glColorMask;
-        gDefaultInterface.fColorPointer = glColorPointer;
-        gDefaultInterface.fColor4ub = glColor4ub;
-        gDefaultInterface.fCompileShader = glCompileShader;
-        gDefaultInterface.fCompressedTexImage2D = glCompressedTexImage2D;
-        gDefaultInterface.fCreateProgram = glCreateProgram;
-        gDefaultInterface.fCreateShader = glCreateShader;
-        gDefaultInterface.fCullFace = glCullFace;
-        gDefaultInterface.fDeleteBuffers = glDeleteBuffers;
-        gDefaultInterface.fDeleteProgram = glDeleteProgram;
-        gDefaultInterface.fDeleteShader = glDeleteShader;
-        gDefaultInterface.fDeleteTextures = glDeleteTextures;
-        gDefaultInterface.fDepthMask = glDepthMask;
-        gDefaultInterface.fDisable = glDisable;
-        gDefaultInterface.fDisableClientState = glDisableClientState;
-        gDefaultInterface.fDisableVertexAttribArray = 
-                                            glDisableVertexAttribArray;
-        gDefaultInterface.fDrawArrays = glDrawArrays;
-        gDefaultInterface.fDrawBuffer = glDrawBuffer;
-        gDefaultInterface.fDrawBuffers = glDrawBuffers;
-        gDefaultInterface.fDrawElements = glDrawElements;
-        gDefaultInterface.fEnable = glEnable;
-        gDefaultInterface.fEnableClientState = glEnableClientState;
-        gDefaultInterface.fEnableVertexAttribArray = glEnableVertexAttribArray;
-        gDefaultInterface.fFrontFace = glFrontFace;
-        gDefaultInterface.fGenBuffers = glGenBuffers;
-        gDefaultInterface.fGetBufferParameteriv = glGetBufferParameteriv;
-        gDefaultInterface.fGetError = glGetError;
-        gDefaultInterface.fGetIntegerv = glGetIntegerv;
-        gDefaultInterface.fGetProgramInfoLog = glGetProgramInfoLog;
-        gDefaultInterface.fGetProgramiv = glGetProgramiv;
-        gDefaultInterface.fGetShaderInfoLog = glGetShaderInfoLog;
-        gDefaultInterface.fGetShaderiv = glGetShaderiv;
-        gDefaultInterface.fGetString = glGetString;
-        gDefaultInterface.fGetTexLevelParameteriv = glGetTexLevelParameteriv;
-        gDefaultInterface.fGenTextures = glGenTextures;
-        gDefaultInterface.fGetUniformLocation = glGetUniformLocation;
-        gDefaultInterface.fLineWidth = glLineWidth;
-        gDefaultInterface.fLinkProgram = glLinkProgram;
-        gDefaultInterface.fLoadMatrixf = glLoadMatrixf;
-        gDefaultInterface.fMapBuffer = glMapBuffer;
-        gDefaultInterface.fMatrixMode = glMatrixMode;
-        gDefaultInterface.fPointSize = glPointSize;
-        gDefaultInterface.fPixelStorei = glPixelStorei;
-        gDefaultInterface.fReadBuffer = glReadBuffer;
-        gDefaultInterface.fReadPixels = glReadPixels;
-        gDefaultInterface.fScissor = glScissor;
-        gDefaultInterface.fShadeModel = glShadeModel;
-        gDefaultInterface.fShaderSource = glShaderSource;
-        gDefaultInterface.fStencilFunc = glStencilFunc;
-        gDefaultInterface.fStencilFuncSeparate = glStencilFuncSeparate;
-        gDefaultInterface.fStencilMask = glStencilMask;
-        gDefaultInterface.fStencilMaskSeparate = glStencilMaskSeparate;
-        gDefaultInterface.fStencilOp = glStencilOp;
-        gDefaultInterface.fStencilOpSeparate = glStencilOpSeparate;
-        gDefaultInterface.fTexCoordPointer = glTexCoordPointer;
-        gDefaultInterface.fTexEnvi = glTexEnvi;
-        // mac uses GLenum for internalFormat param (non-standard)
-        // amounts to int vs. uint.
-        gDefaultInterface.fTexImage2D = (GrGLTexImage2DProc)glTexImage2D;
-        gDefaultInterface.fTexParameteri = glTexParameteri;
-        gDefaultInterface.fTexSubImage2D = glTexSubImage2D;
-        gDefaultInterface.fUniform1f = glUniform1f;
-        gDefaultInterface.fUniform1i = glUniform1i;
-        gDefaultInterface.fUniform1fv = glUniform1fv;
-        gDefaultInterface.fUniform1iv = glUniform1iv;
-        gDefaultInterface.fUniform2f = glUniform2f;
-        gDefaultInterface.fUniform2i = glUniform2i;
-        gDefaultInterface.fUniform2fv = glUniform2fv;
-        gDefaultInterface.fUniform2iv = glUniform2iv;
-        gDefaultInterface.fUniform3f = glUniform3f;
-        gDefaultInterface.fUniform3i = glUniform3i;
-        gDefaultInterface.fUniform3fv = glUniform3fv;
-        gDefaultInterface.fUniform3iv = glUniform3iv;
-        gDefaultInterface.fUniform4f = glUniform4f;
-        gDefaultInterface.fUniform4i = glUniform4i;
-        gDefaultInterface.fUniform4fv = glUniform4fv;
-        gDefaultInterface.fUniform4iv = glUniform4iv;
-        gDefaultInterface.fUniform4fv = glUniform4fv;
-        gDefaultInterface.fUniformMatrix2fv = glUniformMatrix2fv;
-        gDefaultInterface.fUniformMatrix3fv = glUniformMatrix3fv;
-        gDefaultInterface.fUniformMatrix4fv = glUniformMatrix4fv;
-        gDefaultInterface.fUnmapBuffer = glUnmapBuffer;
-        gDefaultInterface.fUseProgram = glUseProgram;
-        gDefaultInterface.fVertexAttrib4fv = glVertexAttrib4fv;
-        gDefaultInterface.fVertexAttribPointer = glVertexAttribPointer;
-        gDefaultInterface.fVertexPointer = glVertexPointer;
-        gDefaultInterface.fViewport = glViewport;
+void GrGLInitializeDefaultGLInterface() {
+    GrGLInterface* defaultInterface = new GrGLInterface;
+    defaultInterface->fBindingsExported = kDesktop_GrGLBinding;
+    defaultInterface->fActiveTexture = glActiveTexture;
+    defaultInterface->fAttachShader = glAttachShader;
+    defaultInterface->fBindAttribLocation = glBindAttribLocation;
+    defaultInterface->fBindBuffer = glBindBuffer;
+    defaultInterface->fBindTexture = glBindTexture;
+    defaultInterface->fBlendColor = glBlendColor;
+    defaultInterface->fBlendFunc = glBlendFunc;
+    defaultInterface->fBufferData = glBufferData;
+    defaultInterface->fBufferSubData = glBufferSubData;
+    defaultInterface->fClear = glClear;
+    defaultInterface->fClearColor = glClearColor;
+    defaultInterface->fClearStencil = glClearStencil;
+    defaultInterface->fClientActiveTexture = glClientActiveTexture;
+    defaultInterface->fColorMask = glColorMask;
+    defaultInterface->fColorPointer = glColorPointer;
+    defaultInterface->fColor4ub = glColor4ub;
+    defaultInterface->fCompileShader = glCompileShader;
+    defaultInterface->fCompressedTexImage2D = glCompressedTexImage2D;
+    defaultInterface->fCreateProgram = glCreateProgram;
+    defaultInterface->fCreateShader = glCreateShader;
+    defaultInterface->fCullFace = glCullFace;
+    defaultInterface->fDeleteBuffers = glDeleteBuffers;
+    defaultInterface->fDeleteProgram = glDeleteProgram;
+    defaultInterface->fDeleteShader = glDeleteShader;
+    defaultInterface->fDeleteTextures = glDeleteTextures;
+    defaultInterface->fDepthMask = glDepthMask;
+    defaultInterface->fDisable = glDisable;
+    defaultInterface->fDisableClientState = glDisableClientState;
+    defaultInterface->fDisableVertexAttribArray = 
+                                        glDisableVertexAttribArray;
+    defaultInterface->fDrawArrays = glDrawArrays;
+    defaultInterface->fDrawBuffer = glDrawBuffer;
+    defaultInterface->fDrawBuffers = glDrawBuffers;
+    defaultInterface->fDrawElements = glDrawElements;
+    defaultInterface->fEnable = glEnable;
+    defaultInterface->fEnableClientState = glEnableClientState;
+    defaultInterface->fEnableVertexAttribArray = glEnableVertexAttribArray;
+    defaultInterface->fFrontFace = glFrontFace;
+    defaultInterface->fGenBuffers = glGenBuffers;
+    defaultInterface->fGetBufferParameteriv = glGetBufferParameteriv;
+    defaultInterface->fGetError = glGetError;
+    defaultInterface->fGetIntegerv = glGetIntegerv;
+    defaultInterface->fGetProgramInfoLog = glGetProgramInfoLog;
+    defaultInterface->fGetProgramiv = glGetProgramiv;
+    defaultInterface->fGetShaderInfoLog = glGetShaderInfoLog;
+    defaultInterface->fGetShaderiv = glGetShaderiv;
+    defaultInterface->fGetString = glGetString;
+    defaultInterface->fGetTexLevelParameteriv = glGetTexLevelParameteriv;
+    defaultInterface->fGenTextures = glGenTextures;
+    defaultInterface->fGetUniformLocation = glGetUniformLocation;
+    defaultInterface->fLineWidth = glLineWidth;
+    defaultInterface->fLinkProgram = glLinkProgram;
+    defaultInterface->fLoadMatrixf = glLoadMatrixf;
+    defaultInterface->fMapBuffer = glMapBuffer;
+    defaultInterface->fMatrixMode = glMatrixMode;
+    defaultInterface->fPointSize = glPointSize;
+    defaultInterface->fPixelStorei = glPixelStorei;
+    defaultInterface->fReadBuffer = glReadBuffer;
+    defaultInterface->fReadPixels = glReadPixels;
+    defaultInterface->fScissor = glScissor;
+    defaultInterface->fShadeModel = glShadeModel;
+    defaultInterface->fShaderSource = glShaderSource;
+    defaultInterface->fStencilFunc = glStencilFunc;
+    defaultInterface->fStencilFuncSeparate = glStencilFuncSeparate;
+    defaultInterface->fStencilMask = glStencilMask;
+    defaultInterface->fStencilMaskSeparate = glStencilMaskSeparate;
+    defaultInterface->fStencilOp = glStencilOp;
+    defaultInterface->fStencilOpSeparate = glStencilOpSeparate;
+    defaultInterface->fTexCoordPointer = glTexCoordPointer;
+    defaultInterface->fTexEnvi = glTexEnvi;
+    // mac uses GLenum for internalFormat param (non-standard)
+    // amounts to int vs. uint.
+    defaultInterface->fTexImage2D = (GrGLTexImage2DProc)glTexImage2D;
+    defaultInterface->fTexParameteri = glTexParameteri;
+    defaultInterface->fTexSubImage2D = glTexSubImage2D;
+    defaultInterface->fUniform1f = glUniform1f;
+    defaultInterface->fUniform1i = glUniform1i;
+    defaultInterface->fUniform1fv = glUniform1fv;
+    defaultInterface->fUniform1iv = glUniform1iv;
+    defaultInterface->fUniform2f = glUniform2f;
+    defaultInterface->fUniform2i = glUniform2i;
+    defaultInterface->fUniform2fv = glUniform2fv;
+    defaultInterface->fUniform2iv = glUniform2iv;
+    defaultInterface->fUniform3f = glUniform3f;
+    defaultInterface->fUniform3i = glUniform3i;
+    defaultInterface->fUniform3fv = glUniform3fv;
+    defaultInterface->fUniform3iv = glUniform3iv;
+    defaultInterface->fUniform4f = glUniform4f;
+    defaultInterface->fUniform4i = glUniform4i;
+    defaultInterface->fUniform4fv = glUniform4fv;
+    defaultInterface->fUniform4iv = glUniform4iv;
+    defaultInterface->fUniform4fv = glUniform4fv;
+    defaultInterface->fUniformMatrix2fv = glUniformMatrix2fv;
+    defaultInterface->fUniformMatrix3fv = glUniformMatrix3fv;
+    defaultInterface->fUniformMatrix4fv = glUniformMatrix4fv;
+    defaultInterface->fUnmapBuffer = glUnmapBuffer;
+    defaultInterface->fUseProgram = glUseProgram;
+    defaultInterface->fVertexAttrib4fv = glVertexAttrib4fv;
+    defaultInterface->fVertexAttribPointer = glVertexAttribPointer;
+    defaultInterface->fVertexPointer = glVertexPointer;
+    defaultInterface->fViewport = glViewport;
 
 #if GL_ARB_framebuffer_object
-        gDefaultInterface.fGenFramebuffers = glGenFramebuffers;
-        gDefaultInterface.fGetFramebufferAttachmentParameteriv = glGetFramebufferAttachmentParameteriv;
-        gDefaultInterface.fGetRenderbufferParameteriv = glGetRenderbufferParameteriv;
-        gDefaultInterface.fBindFramebuffer = glBindFramebuffer;
-        gDefaultInterface.fFramebufferTexture2D = glFramebufferTexture2D;
-        gDefaultInterface.fCheckFramebufferStatus = glCheckFramebufferStatus;
-        gDefaultInterface.fDeleteFramebuffers = glDeleteFramebuffers;
-        gDefaultInterface.fRenderbufferStorage = glRenderbufferStorage;
-        gDefaultInterface.fGenRenderbuffers = glGenRenderbuffers;
-        gDefaultInterface.fDeleteRenderbuffers = glDeleteRenderbuffers;
-        gDefaultInterface.fFramebufferRenderbuffer = glFramebufferRenderbuffer;
-        gDefaultInterface.fBindRenderbuffer = glBindRenderbuffer;
-        gDefaultInterface.fRenderbufferStorageMultisample = 
-                                        glRenderbufferStorageMultisample;
-        gDefaultInterface.fBlitFramebuffer = glBlitFramebuffer;
+    defaultInterface->fGenFramebuffers = glGenFramebuffers;
+    defaultInterface->fGetFramebufferAttachmentParameteriv = glGetFramebufferAttachmentParameteriv;
+    defaultInterface->fGetRenderbufferParameteriv = glGetRenderbufferParameteriv;
+    defaultInterface->fBindFramebuffer = glBindFramebuffer;
+    defaultInterface->fFramebufferTexture2D = glFramebufferTexture2D;
+    defaultInterface->fCheckFramebufferStatus = glCheckFramebufferStatus;
+    defaultInterface->fDeleteFramebuffers = glDeleteFramebuffers;
+    defaultInterface->fRenderbufferStorage = glRenderbufferStorage;
+    defaultInterface->fGenRenderbuffers = glGenRenderbuffers;
+    defaultInterface->fDeleteRenderbuffers = glDeleteRenderbuffers;
+    defaultInterface->fFramebufferRenderbuffer = glFramebufferRenderbuffer;
+    defaultInterface->fBindRenderbuffer = glBindRenderbuffer;
+    defaultInterface->fRenderbufferStorageMultisample = 
+                                    glRenderbufferStorageMultisample;
+    defaultInterface->fBlitFramebuffer = glBlitFramebuffer;
 #elif GL_EXT_framebuffer_object
-        gDefaultInterface.fGenFramebuffers = glGenFramebuffersEXT;
-        gDefaultInterface.fGetFramebufferAttachmentivParameter = glGetFramebufferAttachmentParameterivEXT;
-        gDefaultInterface.fGLGetRenderbufferParameteriv = glGetRenderbufferParameterivEXT;
-        gDefaultInterface.fBindFramebuffer = glBindFramebufferEXT;
-        gDefaultInterface.fFramebufferTexture2D = glFramebufferTexture2DEXT;
-        gDefaultInterface.fCheckFramebufferStatus = glCheckFramebufferStatusEXT;
-        gDefaultInterface.fDeleteFramebuffers = glDeleteFramebuffersEXT;
-        gDefaultInterface.fRenderbufferStorage = glRenderbufferStorageEXT;
-        gDefaultInterface.fGenRenderbuffers = glGenRenderbuffersEXT;
-        gDefaultInterface.fDeleteRenderbuffers = glDeleteRenderbuffers;
-        gDefaultInterface.fFramebufferRenderbuffer = 
-                                                glFramebufferRenderbufferEXT;
-        gDefaultInterface.fBindRenderbuffer = glBindRenderbufferEXT;
-    #if GL_EXT_framebuffer_multisample
-        gDefaultInterface.fRenderbufferStorageMultisample = 
-                                            glRenderbufferStorageMultisampleEXT;
-    #endif
-    #if GL_EXT_framebuffer_blit
-        gDefaultInterface.fBlitFramebuffer = glBlitFramebufferEXT;
-    #endif
+    defaultInterface->fGenFramebuffers = glGenFramebuffersEXT;
+    defaultInterface->fGetFramebufferAttachmentivParameter = glGetFramebufferAttachmentParameterivEXT;
+    defaultInterface->fGLGetRenderbufferParameteriv = glGetRenderbufferParameterivEXT;
+    defaultInterface->fBindFramebuffer = glBindFramebufferEXT;
+    defaultInterface->fFramebufferTexture2D = glFramebufferTexture2DEXT;
+    defaultInterface->fCheckFramebufferStatus = glCheckFramebufferStatusEXT;
+    defaultInterface->fDeleteFramebuffers = glDeleteFramebuffersEXT;
+    defaultInterface->fRenderbufferStorage = glRenderbufferStorageEXT;
+    defaultInterface->fGenRenderbuffers = glGenRenderbuffersEXT;
+    defaultInterface->fDeleteRenderbuffers = glDeleteRenderbuffers;
+    defaultInterface->fFramebufferRenderbuffer = 
+                                            glFramebufferRenderbufferEXT;
+    defaultInterface->fBindRenderbuffer = glBindRenderbufferEXT;
+#if GL_EXT_framebuffer_multisample
+    defaultInterface->fRenderbufferStorageMultisample = 
+                                        glRenderbufferStorageMultisampleEXT;
+#endif
+#if GL_EXT_framebuffer_blit
+    defaultInterface->fBlitFramebuffer = glBlitFramebufferEXT;
+#endif
 #endif
-        gDefaultInterface.fBindFragDataLocationIndexed = NULL;
+    defaultInterface->fBindFragDataLocationIndexed = NULL;
 
-        gDefaultInterface.fBindingsExported = kDesktop_GrGLBinding;
+    defaultInterface->fBindingsExported = kDesktop_GrGLBinding;
 
-        gDefaultInterfaceInit = true;
-    }
-    GrGLSetGLInterface(&gDefaultInterface);
+    GrGLSetDefaultGLInterface(defaultInterface)->unref();
 }
index c6be2dfe9bd49d61d3b79a7263e8889473220d0d..6d5661aa31cb15d96abc47f66c5996afc54e4226 100644 (file)
 #include <GL/glext.h>
 #include <GL/glu.h>
 
-#define GR_GL_GET_PROC(F) gDefaultInterface.f ## F = (GrGL ## F ## Proc) \
+#define GR_GL_GET_PROC(F) defaultInterface->f ## F = (GrGL ## F ## Proc) \
         OSMesaGetProcAddress("gl" #F);
-#define GR_GL_GET_PROC_SUFFIX(F, S) gDefaultInterface.f ## F = (GrGL ## F ## Proc) \
+#define GR_GL_GET_PROC_SUFFIX(F, S) defaultInterface->f ## F = (GrGL ## F ## Proc) \
         OSMesaGetProcAddress("gl" #F #S);
 
-void GrGLSetDefaultGLInterface() {
-    static GrGLInterface gDefaultInterface;
-    static bool gDefaultInterfaceInit;
-    if (!gDefaultInterfaceInit && NULL != OSMesaGetCurrentContext()) {
+void GrGLInitializeDefaultGLInterface() {
+    if (NULL != OSMesaGetCurrentContext()) {
+        GrGLInterface defaultInterface = new GrGLInterface();
         int major, minor;
         const char* versionString = (const char*) glGetString(GL_VERSION);
         const char* extString = (const char*) glGetString(GL_EXTENSIONS);
@@ -31,83 +30,83 @@ void GrGLSetDefaultGLInterface() {
             // We must have array and element_array buffer objects.
             return;
         }
-        gDefaultInterface.fNPOTRenderTargetSupport = kProbe_GrGLCapability;
-        gDefaultInterface.fMinRenderTargetHeight = kProbe_GrGLCapability;
-        gDefaultInterface.fMinRenderTargetWidth = kProbe_GrGLCapability;
+        defaultInterface->fNPOTRenderTargetSupport = kProbe_GrGLCapability;
+        defaultInterface->fMinRenderTargetHeight = kProbe_GrGLCapability;
+        defaultInterface->fMinRenderTargetWidth = kProbe_GrGLCapability;
 
-        gDefaultInterface.fActiveTexture = glActiveTexture;
+        defaultInterface->fActiveTexture = glActiveTexture;
         GR_GL_GET_PROC(AttachShader);
         GR_GL_GET_PROC(BindAttribLocation);
         GR_GL_GET_PROC(BindBuffer);
-        gDefaultInterface.fBindTexture = glBindTexture;
-        gDefaultInterface.fBlendColor = glBlendColor;
-        gDefaultInterface.fBlendFunc = glBlendFunc;
+        defaultInterface->fBindTexture = glBindTexture;
+        defaultInterface->fBlendColor = glBlendColor;
+        defaultInterface->fBlendFunc = glBlendFunc;
         GR_GL_GET_PROC(BufferData);
         GR_GL_GET_PROC(BufferSubData);
-        gDefaultInterface.fClear = glClear;
-        gDefaultInterface.fClearColor = glClearColor;
-        gDefaultInterface.fClearStencil = glClearStencil;
-        gDefaultInterface.fClientActiveTexture = glClientActiveTexture;
-        gDefaultInterface.fColorMask = glColorMask;
-        gDefaultInterface.fColorPointer = glColorPointer;
-        gDefaultInterface.fColor4ub = glColor4ub;
+        defaultInterface->fClear = glClear;
+        defaultInterface->fClearColor = glClearColor;
+        defaultInterface->fClearStencil = glClearStencil;
+        defaultInterface->fClientActiveTexture = glClientActiveTexture;
+        defaultInterface->fColorMask = glColorMask;
+        defaultInterface->fColorPointer = glColorPointer;
+        defaultInterface->fColor4ub = glColor4ub;
         GR_GL_GET_PROC(CompileShader);
-        gDefaultInterface.fCompressedTexImage2D = glCompressedTexImage2D;
+        defaultInterface->fCompressedTexImage2D = glCompressedTexImage2D;
         GR_GL_GET_PROC(CreateProgram);
         GR_GL_GET_PROC(CreateShader);
-        gDefaultInterface.fCullFace = glCullFace;
+        defaultInterface->fCullFace = glCullFace;
         GR_GL_GET_PROC(DeleteBuffers);
         GR_GL_GET_PROC(DeleteProgram);
         GR_GL_GET_PROC(DeleteShader);
-        gDefaultInterface.fDeleteTextures = glDeleteTextures;
-        gDefaultInterface.fDepthMask = glDepthMask;
-        gDefaultInterface.fDisable = glDisable;
-        gDefaultInterface.fDisableClientState = glDisableClientState;
+        defaultInterface->fDeleteTextures = glDeleteTextures;
+        defaultInterface->fDepthMask = glDepthMask;
+        defaultInterface->fDisable = glDisable;
+        defaultInterface->fDisableClientState = glDisableClientState;
         GR_GL_GET_PROC(DisableVertexAttribArray);
-        gDefaultInterface.fDrawArrays = glDrawArrays;
-        gDefaultInterface.fDrawBuffer = glDrawBuffer;
+        defaultInterface->fDrawArrays = glDrawArrays;
+        defaultInterface->fDrawBuffer = glDrawBuffer;
         GR_GL_GET_PROC(DrawBuffers);
-        gDefaultInterface.fDrawElements = glDrawElements;
-        gDefaultInterface.fEnable = glEnable;
-        gDefaultInterface.fEnableClientState = glEnableClientState;
+        defaultInterface->fDrawElements = glDrawElements;
+        defaultInterface->fEnable = glEnable;
+        defaultInterface->fEnableClientState = glEnableClientState;
         GR_GL_GET_PROC(EnableVertexAttribArray);
-        gDefaultInterface.fFrontFace = glFrontFace;
+        defaultInterface->fFrontFace = glFrontFace;
         GR_GL_GET_PROC(GenBuffers);
         GR_GL_GET_PROC(GetBufferParameteriv);
-        gDefaultInterface.fGetError = glGetError;
-        gDefaultInterface.fGetIntegerv = glGetIntegerv;
+        defaultInterface->fGetError = glGetError;
+        defaultInterface->fGetIntegerv = glGetIntegerv;
         GR_GL_GET_PROC(GetProgramInfoLog);
         GR_GL_GET_PROC(GetProgramiv);
         GR_GL_GET_PROC(GetShaderInfoLog);
         GR_GL_GET_PROC(GetShaderiv);
-        gDefaultInterface.fGetString = glGetString;
-        gDefaultInterface.fGetTexLevelParameteriv = glGetTexLevelParameteriv;
-        gDefaultInterface.fGenTextures = glGenTextures;
+        defaultInterface->fGetString = glGetString;
+        defaultInterface->fGetTexLevelParameteriv = glGetTexLevelParameteriv;
+        defaultInterface->fGenTextures = glGenTextures;
         GR_GL_GET_PROC(GetUniformLocation);
-        gDefaultInterface.fLineWidth = glLineWidth;
+        defaultInterface->fLineWidth = glLineWidth;
         GR_GL_GET_PROC(LinkProgram);
-        gDefaultInterface.fLoadMatrixf = glLoadMatrixf;
+        defaultInterface->fLoadMatrixf = glLoadMatrixf;
         GR_GL_GET_PROC(MapBuffer);
-        gDefaultInterface.fMatrixMode = glMatrixMode;
-        gDefaultInterface.fPointSize = glPointSize;
-        gDefaultInterface.fPixelStorei = glPixelStorei;
-        gDefaultInterface.fReadBuffer = glReadBuffer;
-        gDefaultInterface.fReadPixels = glReadPixels;
-        gDefaultInterface.fScissor = glScissor;
-        gDefaultInterface.fShadeModel = glShadeModel;
+        defaultInterface->fMatrixMode = glMatrixMode;
+        defaultInterface->fPointSize = glPointSize;
+        defaultInterface->fPixelStorei = glPixelStorei;
+        defaultInterface->fReadBuffer = glReadBuffer;
+        defaultInterface->fReadPixels = glReadPixels;
+        defaultInterface->fScissor = glScissor;
+        defaultInterface->fShadeModel = glShadeModel;
         GR_GL_GET_PROC(ShaderSource);
-        gDefaultInterface.fStencilFunc = glStencilFunc;
+        defaultInterface->fStencilFunc = glStencilFunc;
         GR_GL_GET_PROC(StencilFuncSeparate);
-        gDefaultInterface.fStencilMask = glStencilMask;
+        defaultInterface->fStencilMask = glStencilMask;
         GR_GL_GET_PROC(StencilMaskSeparate);
-        gDefaultInterface.fStencilOp = glStencilOp;
+        defaultInterface->fStencilOp = glStencilOp;
         GR_GL_GET_PROC(StencilOpSeparate);
-        gDefaultInterface.fTexCoordPointer = glTexCoordPointer;
-        gDefaultInterface.fTexEnvi = glTexEnvi;
+        defaultInterface->fTexCoordPointer = glTexCoordPointer;
+        defaultInterface->fTexEnvi = glTexEnvi;
         //OSMesa on Mac's glTexImage2D takes a GLenum for internalFormat rather than a GLint.
-        gDefaultInterface.fTexImage2D = reinterpret_cast<GrGLTexImage2DProc>(glTexImage2D);
-        gDefaultInterface.fTexParameteri = glTexParameteri;
-        gDefaultInterface.fTexSubImage2D = glTexSubImage2D;
+        defaultInterface->fTexImage2D = reinterpret_cast<GrGLTexImage2DProc>(glTexImage2D);
+        defaultInterface->fTexParameteri = glTexParameteri;
+        defaultInterface->fTexSubImage2D = glTexSubImage2D;
         GR_GL_GET_PROC(Uniform1f);
         GR_GL_GET_PROC(Uniform1i);
         GR_GL_GET_PROC(Uniform1fv);
@@ -131,8 +130,8 @@ void GrGLSetDefaultGLInterface() {
         GR_GL_GET_PROC(UseProgram);
         GR_GL_GET_PROC(VertexAttrib4fv);
         GR_GL_GET_PROC(VertexAttribPointer);
-        gDefaultInterface.fVertexPointer = glVertexPointer;
-        gDefaultInterface.fViewport = glViewport;
+        defaultInterface->fVertexPointer = glVertexPointer;
+        defaultInterface->fViewport = glViewport;
 
         // First look for GL3.0 FBO or GL_ARB_framebuffer_object (same since
         // GL_ARB_framebuffer_object doesn't use ARB suffix.)
@@ -179,10 +178,7 @@ void GrGLSetDefaultGLInterface() {
             return;
         }
         GR_GL_GET_PROC(BindFragDataLocationIndexed);
-        gDefaultInterface.fBindingsExported = kDesktop_GrGLBinding;
-
-        gDefaultInterfaceInit = true;
+        defaultInterface->fBindingsExported = kDesktop_GrGLBinding;
+        GrGLSetDefaultGLInterface(defaultInterface)->unref();
     }
-    if (gDefaultInterfaceInit)
-        GrGLSetGLInterface(&gDefaultInterface);
 }
index 01725b9db6225d244a7525e11e29608df647567e..3e12ca1b544a18b738424e1ede84759df85ad4fa 100644 (file)
 #include <GL/glext.h>
 #include <GL/glu.h>
 
-#define GR_GL_GET_PROC(F) gDefaultInterface.f ## F = (GrGL ## F ## Proc) \
+#define GR_GL_GET_PROC(F) defaultInterface->f ## F = (GrGL ## F ## Proc) \
         glXGetProcAddress(reinterpret_cast<const GLubyte*>("gl" #F));
-#define GR_GL_GET_PROC_SUFFIX(F, S) gDefaultInterface.f ## F = (GrGL ## F ## Proc) \
+#define GR_GL_GET_PROC_SUFFIX(F, S) defaultInterface->f ## F = (GrGL ## F ## Proc) \
         glXGetProcAddress(reinterpret_cast<const GLubyte*>("gl" #F #S));
 
-void GrGLSetDefaultGLInterface() {
-    static GrGLInterface gDefaultInterface;
-    static bool gDefaultInterfaceInit;
-    if (!gDefaultInterfaceInit && NULL != glXGetCurrentContext()) {
+void GrGLInitializeDefaultGLInterface() {
+    if (NULL != glXGetCurrentContext()) {
         int major, minor;
         const char* versionString = (const char*) glGetString(GL_VERSION);
         const char* extString = (const char*) glGetString(GL_EXTENSIONS);
@@ -33,82 +31,84 @@ void GrGLSetDefaultGLInterface() {
             return;
         }
 
-        gDefaultInterface.fNPOTRenderTargetSupport = kProbe_GrGLCapability;
-        gDefaultInterface.fMinRenderTargetHeight = kProbe_GrGLCapability;
-        gDefaultInterface.fMinRenderTargetWidth = kProbe_GrGLCapability;
+        GrGLInterface* defaultInterface = new GrGLInterface();
 
-        gDefaultInterface.fActiveTexture = glActiveTexture;
+        defaultInterface->fNPOTRenderTargetSupport = kProbe_GrGLCapability;
+        defaultInterface->fMinRenderTargetHeight = kProbe_GrGLCapability;
+        defaultInterface->fMinRenderTargetWidth = kProbe_GrGLCapability;
+
+        defaultInterface->fActiveTexture = glActiveTexture;
         GR_GL_GET_PROC(AttachShader);
         GR_GL_GET_PROC(BindAttribLocation);
         GR_GL_GET_PROC(BindBuffer);
-        gDefaultInterface.fBindTexture = glBindTexture;
-        gDefaultInterface.fBlendColor = glBlendColor;
-        gDefaultInterface.fBlendFunc = glBlendFunc;
+        defaultInterface->fBindTexture = glBindTexture;
+        defaultInterface->fBlendColor = glBlendColor;
+        defaultInterface->fBlendFunc = glBlendFunc;
         GR_GL_GET_PROC(BufferData);
         GR_GL_GET_PROC(BufferSubData);
-        gDefaultInterface.fClear = glClear;
-        gDefaultInterface.fClearColor = glClearColor;
-        gDefaultInterface.fClearStencil = glClearStencil;
-        gDefaultInterface.fClientActiveTexture = glClientActiveTexture;
-        gDefaultInterface.fColorMask = glColorMask;
-        gDefaultInterface.fColorPointer = glColorPointer;
-        gDefaultInterface.fColor4ub = glColor4ub;
+        defaultInterface->fClear = glClear;
+        defaultInterface->fClearColor = glClearColor;
+        defaultInterface->fClearStencil = glClearStencil;
+        defaultInterface->fClientActiveTexture = glClientActiveTexture;
+        defaultInterface->fColorMask = glColorMask;
+        defaultInterface->fColorPointer = glColorPointer;
+        defaultInterface->fColor4ub = glColor4ub;
         GR_GL_GET_PROC(CompileShader);
-        gDefaultInterface.fCompressedTexImage2D = glCompressedTexImage2D;
+        defaultInterface->fCompressedTexImage2D = glCompressedTexImage2D;
         GR_GL_GET_PROC(CreateProgram);
         GR_GL_GET_PROC(CreateShader);
-        gDefaultInterface.fCullFace = glCullFace;
+        defaultInterface->fCullFace = glCullFace;
         GR_GL_GET_PROC(DeleteBuffers);
         GR_GL_GET_PROC(DeleteProgram);
         GR_GL_GET_PROC(DeleteShader);
-        gDefaultInterface.fDeleteTextures = glDeleteTextures;
-        gDefaultInterface.fDepthMask = glDepthMask;
-        gDefaultInterface.fDisable = glDisable;
-        gDefaultInterface.fDisableClientState = glDisableClientState;
+        defaultInterface->fDeleteTextures = glDeleteTextures;
+        defaultInterface->fDepthMask = glDepthMask;
+        defaultInterface->fDisable = glDisable;
+        defaultInterface->fDisableClientState = glDisableClientState;
         GR_GL_GET_PROC(DisableVertexAttribArray);
-        gDefaultInterface.fDrawArrays = glDrawArrays;
-        gDefaultInterface.fDrawBuffer = glDrawBuffer;
+        defaultInterface->fDrawArrays = glDrawArrays;
+        defaultInterface->fDrawBuffer = glDrawBuffer;
         GR_GL_GET_PROC(DrawBuffers);
-        gDefaultInterface.fDrawElements = glDrawElements;
-        gDefaultInterface.fEnable = glEnable;
-        gDefaultInterface.fEnableClientState = glEnableClientState;
+        defaultInterface->fDrawElements = glDrawElements;
+        defaultInterface->fEnable = glEnable;
+        defaultInterface->fEnableClientState = glEnableClientState;
         GR_GL_GET_PROC(EnableVertexAttribArray);
-        gDefaultInterface.fFrontFace = glFrontFace;
+        defaultInterface->fFrontFace = glFrontFace;
         GR_GL_GET_PROC(GenBuffers);
         GR_GL_GET_PROC(GetBufferParameteriv);
-        gDefaultInterface.fGetError = glGetError;
-        gDefaultInterface.fGetIntegerv = glGetIntegerv;
+        defaultInterface->fGetError = glGetError;
+        defaultInterface->fGetIntegerv = glGetIntegerv;
         GR_GL_GET_PROC(GetProgramInfoLog);
         GR_GL_GET_PROC(GetProgramiv);
         GR_GL_GET_PROC(GetShaderInfoLog);
         GR_GL_GET_PROC(GetShaderiv);
-        gDefaultInterface.fGetString = glGetString;
-        gDefaultInterface.fGetTexLevelParameteriv = glGetTexLevelParameteriv;
-        gDefaultInterface.fGenTextures = glGenTextures;
+        defaultInterface->fGetString = glGetString;
+        defaultInterface->fGetTexLevelParameteriv = glGetTexLevelParameteriv;
+        defaultInterface->fGenTextures = glGenTextures;
         GR_GL_GET_PROC(GetUniformLocation);
-        gDefaultInterface.fLineWidth = glLineWidth;
+        defaultInterface->fLineWidth = glLineWidth;
         GR_GL_GET_PROC(LinkProgram);
-        gDefaultInterface.fLoadMatrixf = glLoadMatrixf;
+        defaultInterface->fLoadMatrixf = glLoadMatrixf;
         GR_GL_GET_PROC(MapBuffer);
-        gDefaultInterface.fMatrixMode = glMatrixMode;
-        gDefaultInterface.fPointSize = glPointSize;
-        gDefaultInterface.fPixelStorei = glPixelStorei;
-        gDefaultInterface.fReadBuffer = glReadBuffer;
-        gDefaultInterface.fReadPixels = glReadPixels;
-        gDefaultInterface.fScissor = glScissor;
-        gDefaultInterface.fShadeModel = glShadeModel;
+        defaultInterface->fMatrixMode = glMatrixMode;
+        defaultInterface->fPointSize = glPointSize;
+        defaultInterface->fPixelStorei = glPixelStorei;
+        defaultInterface->fReadBuffer = glReadBuffer;
+        defaultInterface->fReadPixels = glReadPixels;
+        defaultInterface->fScissor = glScissor;
+        defaultInterface->fShadeModel = glShadeModel;
         GR_GL_GET_PROC(ShaderSource);
-        gDefaultInterface.fStencilFunc = glStencilFunc;
+        defaultInterface->fStencilFunc = glStencilFunc;
         GR_GL_GET_PROC(StencilFuncSeparate);
-        gDefaultInterface.fStencilMask = glStencilMask;
+        defaultInterface->fStencilMask = glStencilMask;
         GR_GL_GET_PROC(StencilMaskSeparate);
-        gDefaultInterface.fStencilOp = glStencilOp;
+        defaultInterface->fStencilOp = glStencilOp;
         GR_GL_GET_PROC(StencilOpSeparate);
-        gDefaultInterface.fTexCoordPointer = glTexCoordPointer;
-        gDefaultInterface.fTexEnvi = glTexEnvi;
-        gDefaultInterface.fTexImage2D = glTexImage2D;
-        gDefaultInterface.fTexParameteri = glTexParameteri;
-        gDefaultInterface.fTexSubImage2D = glTexSubImage2D;
+        defaultInterface->fTexCoordPointer = glTexCoordPointer;
+        defaultInterface->fTexEnvi = glTexEnvi;
+        defaultInterface->fTexImage2D = glTexImage2D;
+        defaultInterface->fTexParameteri = glTexParameteri;
+        defaultInterface->fTexSubImage2D = glTexSubImage2D;
         GR_GL_GET_PROC(Uniform1f);
         GR_GL_GET_PROC(Uniform1i);
         GR_GL_GET_PROC(Uniform1fv);
@@ -132,8 +132,8 @@ void GrGLSetDefaultGLInterface() {
         GR_GL_GET_PROC(UseProgram);
         GR_GL_GET_PROC(VertexAttrib4fv);
         GR_GL_GET_PROC(VertexAttribPointer);
-        gDefaultInterface.fVertexPointer = glVertexPointer;
-        gDefaultInterface.fViewport = glViewport;
+        defaultInterface->fVertexPointer = glVertexPointer;
+        defaultInterface->fViewport = glViewport;
         GR_GL_GET_PROC(BindFragDataLocationIndexed);
 
         // First look for GL3.0 FBO or GL_ARB_framebuffer_object (same since
@@ -180,10 +180,8 @@ void GrGLSetDefaultGLInterface() {
             // we must have FBOs
             return;
         }
-        gDefaultInterface.fBindingsExported = kDesktop_GrGLBinding;
+        defaultInterface->fBindingsExported = kDesktop_GrGLBinding;
 
-        gDefaultInterfaceInit = true;
+        GrGLSetDefaultGLInterface(defaultInterface)->unref();
     }
-    if (gDefaultInterfaceInit)
-        GrGLSetGLInterface(&gDefaultInterface);
 }
index 1bf04578ce166aa8b81537adc5666198ed2e1aa8..e5c7369ccb5a0ba75e2ba8393f0b0bffd47a26f5 100644 (file)
  * Otherwise, a springboard would be needed that hides the calling convention.
  */
 
-#define GR_GL_GET_PROC(F) gDefaultInterface.f ## F = (GrGL ## F ## Proc) wglGetProcAddress("gl" #F);
-#define GR_GL_GET_PROC_SUFFIX(F, S) gDefaultInterface.f ## F = (GrGL ## F ## Proc) wglGetProcAddress("gl" #F #S);
+#define GR_GL_GET_PROC(F) defaultInterface->f ## F = (GrGL ## F ## Proc) wglGetProcAddress("gl" #F);
+#define GR_GL_GET_PROC_SUFFIX(F, S) defaultInterface->f ## F = (GrGL ## F ## Proc) wglGetProcAddress("gl" #F #S);
 
-void GrGLSetDefaultGLInterface() {
-    static GrGLInterface gDefaultInterface;
-    static bool gDefaultInterfaceInit;
-    if (!gDefaultInterfaceInit) {
+void GrGLInitializeDefaultGLInterface() {
 
-        // wglGetProcAddress requires a context.
-        if (NULL != wglGetCurrentContext()) {
-            int major, minor;
-            const char* versionString = (const char*) glGetString(GL_VERSION);
-            const char* extString = (const char*) glGetString(GL_EXTENSIONS);
-            gl_version_from_string(&major, &minor, versionString);
+    // wglGetProcAddress requires a context.
+    if (NULL != wglGetCurrentContext()) {
+        int major, minor;
+        const char* versionString = (const char*) glGetString(GL_VERSION);
+        const char* extString = (const char*) glGetString(GL_EXTENSIONS);
+        gl_version_from_string(&major, &minor, versionString);
 
-            if (major == 1 && minor < 5) {
-                // We must have array and element_array buffer objects.
-                return;
-            }
+        if (major == 1 && minor < 5) {
+            // We must have array and element_array buffer objects.
+            return;
+        }
+        GrGLInterface* defaultInterface = new GrGLInterface();
 
-            gDefaultInterface.fNPOTRenderTargetSupport = kProbe_GrGLCapability;
-            gDefaultInterface.fMinRenderTargetHeight = kProbe_GrGLCapability;
-            gDefaultInterface.fMinRenderTargetWidth = kProbe_GrGLCapability;
+        defaultInterface->fNPOTRenderTargetSupport = kProbe_GrGLCapability;
+        defaultInterface->fMinRenderTargetHeight = kProbe_GrGLCapability;
+        defaultInterface->fMinRenderTargetWidth = kProbe_GrGLCapability;
 
-            // Functions that are part of GL 1.1 will return NULL in
-            // wglGetProcAddress
-            gDefaultInterface.fBlendFunc = glBlendFunc;
-            gDefaultInterface.fClear = glClear;
-            gDefaultInterface.fClearColor = glClearColor;
-            gDefaultInterface.fClearStencil = glClearStencil;
-            gDefaultInterface.fColor4ub = glColor4ub;
-            gDefaultInterface.fColorMask = glColorMask;
-            gDefaultInterface.fColorPointer = glColorPointer;
-            gDefaultInterface.fCullFace = glCullFace;
-            gDefaultInterface.fDeleteTextures = glDeleteTextures;
-            gDefaultInterface.fDepthMask = glDepthMask;
-            gDefaultInterface.fDisable = glDisable;
-            gDefaultInterface.fDisableClientState = glDisableClientState;
-            gDefaultInterface.fDrawArrays = glDrawArrays;
-            gDefaultInterface.fDrawBuffer = glDrawBuffer;
-            gDefaultInterface.fDrawElements = glDrawElements;
-            gDefaultInterface.fEnable = glEnable;
-            gDefaultInterface.fEnableClientState = glEnableClientState;
-            gDefaultInterface.fFrontFace = glFrontFace;
-            gDefaultInterface.fGenTextures = glGenTextures;
-            gDefaultInterface.fGetError = glGetError;
-            gDefaultInterface.fGetIntegerv = glGetIntegerv;
-            gDefaultInterface.fGetString = glGetString;
-            gDefaultInterface.fGetTexLevelParameteriv = glGetTexLevelParameteriv;
-            gDefaultInterface.fLineWidth = glLineWidth;
-            gDefaultInterface.fLoadMatrixf = glLoadMatrixf;
-            gDefaultInterface.fMatrixMode = glMatrixMode;
-            gDefaultInterface.fPixelStorei = glPixelStorei;
-            gDefaultInterface.fPointSize = glPointSize;
-            gDefaultInterface.fReadBuffer = glReadBuffer;
-            gDefaultInterface.fReadPixels = glReadPixels;
-            gDefaultInterface.fScissor = glScissor;
-            gDefaultInterface.fShadeModel = glShadeModel;
-            gDefaultInterface.fStencilFunc = glStencilFunc;
-            gDefaultInterface.fStencilMask = glStencilMask;
-            gDefaultInterface.fStencilOp = glStencilOp;
-            gDefaultInterface.fTexImage2D = glTexImage2D;
-            gDefaultInterface.fTexParameteri = glTexParameteri;
-            gDefaultInterface.fTexCoordPointer = glTexCoordPointer;
-            gDefaultInterface.fTexEnvi = glTexEnvi;
-            gDefaultInterface.fTexSubImage2D = glTexSubImage2D;
-            gDefaultInterface.fViewport = glViewport;
-            gDefaultInterface.fVertexPointer = glVertexPointer;
+        // Functions that are part of GL 1.1 will return NULL in
+        // wglGetProcAddress
+        defaultInterface->fBlendFunc = glBlendFunc;
+        defaultInterface->fClear = glClear;
+        defaultInterface->fClearColor = glClearColor;
+        defaultInterface->fClearStencil = glClearStencil;
+        defaultInterface->fColor4ub = glColor4ub;
+        defaultInterface->fColorMask = glColorMask;
+        defaultInterface->fColorPointer = glColorPointer;
+        defaultInterface->fCullFace = glCullFace;
+        defaultInterface->fDeleteTextures = glDeleteTextures;
+        defaultInterface->fDepthMask = glDepthMask;
+        defaultInterface->fDisable = glDisable;
+        defaultInterface->fDisableClientState = glDisableClientState;
+        defaultInterface->fDrawArrays = glDrawArrays;
+        defaultInterface->fDrawElements = glDrawElements;
+        defaultInterface->fDrawBuffer = glDrawBuffer;
+        defaultInterface->fEnable = glEnable;
+        defaultInterface->fEnableClientState = glEnableClientState;
+        defaultInterface->fFrontFace = glFrontFace;
+        defaultInterface->fGenTextures = glGenTextures;
+        defaultInterface->fGetError = glGetError;
+        defaultInterface->fGetIntegerv = glGetIntegerv;
+        defaultInterface->fGetString = glGetString;
+        defaultInterface->fGetTexLevelParameteriv = glGetTexLevelParameteriv;
+        defaultInterface->fLineWidth = glLineWidth;
+        defaultInterface->fLoadMatrixf = glLoadMatrixf;
+        defaultInterface->fMatrixMode = glMatrixMode;
+        defaultInterface->fPixelStorei = glPixelStorei;
+        defaultInterface->fPointSize = glPointSize;
+        defaultInterface->fReadBuffer = glReadBuffer;
+        defaultInterface->fReadPixels = glReadPixels;
+        defaultInterface->fScissor = glScissor;
+        defaultInterface->fShadeModel = glShadeModel;
+        defaultInterface->fStencilFunc = glStencilFunc;
+        defaultInterface->fStencilMask = glStencilMask;
+        defaultInterface->fStencilOp = glStencilOp;
+        defaultInterface->fTexImage2D = glTexImage2D;
+        defaultInterface->fTexParameteri = glTexParameteri;
+        defaultInterface->fTexCoordPointer = glTexCoordPointer;
+        defaultInterface->fTexEnvi = glTexEnvi;
+        defaultInterface->fTexSubImage2D = glTexSubImage2D;
+        defaultInterface->fViewport = glViewport;
+        defaultInterface->fVertexPointer = glVertexPointer;
 
-            GR_GL_GET_PROC(ActiveTexture);
-            GR_GL_GET_PROC(AttachShader);
-            GR_GL_GET_PROC(BindAttribLocation);
-            GR_GL_GET_PROC(BindBuffer);
-            GR_GL_GET_PROC(BindTexture);
-            GR_GL_GET_PROC(BlendColor);
-            GR_GL_GET_PROC(BufferData);
-            GR_GL_GET_PROC(BufferSubData);
-            GR_GL_GET_PROC(ClientActiveTexture);
-            GR_GL_GET_PROC(CompileShader);
-            GR_GL_GET_PROC(CompressedTexImage2D);
-            GR_GL_GET_PROC(CreateProgram);
-            GR_GL_GET_PROC(CreateShader);
-            GR_GL_GET_PROC(DeleteBuffers);
-            GR_GL_GET_PROC(DeleteProgram);
-            GR_GL_GET_PROC(DeleteShader);
-            GR_GL_GET_PROC(DisableVertexAttribArray);
-            GR_GL_GET_PROC(DrawBuffers);
-            GR_GL_GET_PROC(EnableVertexAttribArray);
-            GR_GL_GET_PROC(GenBuffers);
-            GR_GL_GET_PROC(GetBufferParameteriv);
-            GR_GL_GET_PROC(GetProgramInfoLog);
-            GR_GL_GET_PROC(GetProgramiv);
-            GR_GL_GET_PROC(GetShaderInfoLog);
-            GR_GL_GET_PROC(GetShaderiv);
-            GR_GL_GET_PROC(GetUniformLocation);
-            GR_GL_GET_PROC(LinkProgram);
-            GR_GL_GET_PROC(ShaderSource);
-            GR_GL_GET_PROC(StencilFuncSeparate);
-            GR_GL_GET_PROC(StencilMaskSeparate);
-            GR_GL_GET_PROC(StencilOpSeparate);
-            GR_GL_GET_PROC(Uniform1f);
-            GR_GL_GET_PROC(Uniform1i);
-            GR_GL_GET_PROC(Uniform1fv);
-            GR_GL_GET_PROC(Uniform1iv);
-            GR_GL_GET_PROC(Uniform2f);
-            GR_GL_GET_PROC(Uniform2i);
-            GR_GL_GET_PROC(Uniform2fv);
-            GR_GL_GET_PROC(Uniform2iv);
-            GR_GL_GET_PROC(Uniform3f);
-            GR_GL_GET_PROC(Uniform3i);
-            GR_GL_GET_PROC(Uniform3fv);
-            GR_GL_GET_PROC(Uniform3iv);
-            GR_GL_GET_PROC(Uniform4f);
-            GR_GL_GET_PROC(Uniform4i);
-            GR_GL_GET_PROC(Uniform4fv);
-            GR_GL_GET_PROC(Uniform4iv);
-            GR_GL_GET_PROC(UniformMatrix2fv);
-            GR_GL_GET_PROC(UniformMatrix3fv);
-            GR_GL_GET_PROC(UniformMatrix4fv);
-            GR_GL_GET_PROC(UseProgram);
-            GR_GL_GET_PROC(VertexAttrib4fv);
-            GR_GL_GET_PROC(VertexAttribPointer);
-            GR_GL_GET_PROC(BindFragDataLocationIndexed);
+        GR_GL_GET_PROC(ActiveTexture);
+        GR_GL_GET_PROC(AttachShader);
+        GR_GL_GET_PROC(BindAttribLocation);
+        GR_GL_GET_PROC(BindBuffer);
+        GR_GL_GET_PROC(BindTexture);
+        GR_GL_GET_PROC(BlendColor);
+        GR_GL_GET_PROC(BufferData);
+        GR_GL_GET_PROC(BufferSubData);
+        GR_GL_GET_PROC(ClientActiveTexture);
+        GR_GL_GET_PROC(CompileShader);
+        GR_GL_GET_PROC(CompressedTexImage2D);
+        GR_GL_GET_PROC(CreateProgram);
+        GR_GL_GET_PROC(CreateShader);
+        GR_GL_GET_PROC(DeleteBuffers);
+        GR_GL_GET_PROC(DeleteProgram);
+        GR_GL_GET_PROC(DeleteShader);
+        GR_GL_GET_PROC(DisableVertexAttribArray);
+        GR_GL_GET_PROC(DrawBuffers);
+        GR_GL_GET_PROC(EnableVertexAttribArray);
+        GR_GL_GET_PROC(GenBuffers);
+        GR_GL_GET_PROC(GetBufferParameteriv);
+        GR_GL_GET_PROC(GetProgramInfoLog);
+        GR_GL_GET_PROC(GetProgramiv);
+        GR_GL_GET_PROC(GetShaderInfoLog);
+        GR_GL_GET_PROC(GetShaderiv);
+        GR_GL_GET_PROC(GetUniformLocation);
+        GR_GL_GET_PROC(LinkProgram);
+        GR_GL_GET_PROC(ShaderSource);
+        GR_GL_GET_PROC(StencilFuncSeparate);
+        GR_GL_GET_PROC(StencilMaskSeparate);
+        GR_GL_GET_PROC(StencilOpSeparate);
+        GR_GL_GET_PROC(Uniform1f);
+        GR_GL_GET_PROC(Uniform1i);
+        GR_GL_GET_PROC(Uniform1fv);
+        GR_GL_GET_PROC(Uniform1iv);
+        GR_GL_GET_PROC(Uniform2f);
+        GR_GL_GET_PROC(Uniform2i);
+        GR_GL_GET_PROC(Uniform2fv);
+        GR_GL_GET_PROC(Uniform2iv);
+        GR_GL_GET_PROC(Uniform3f);
+        GR_GL_GET_PROC(Uniform3i);
+        GR_GL_GET_PROC(Uniform3fv);
+        GR_GL_GET_PROC(Uniform3iv);
+        GR_GL_GET_PROC(Uniform4f);
+        GR_GL_GET_PROC(Uniform4i);
+        GR_GL_GET_PROC(Uniform4fv);
+        GR_GL_GET_PROC(Uniform4iv);
+        GR_GL_GET_PROC(UniformMatrix2fv);
+        GR_GL_GET_PROC(UniformMatrix3fv);
+        GR_GL_GET_PROC(UniformMatrix4fv);
+        GR_GL_GET_PROC(UseProgram);
+        GR_GL_GET_PROC(VertexAttrib4fv);
+        GR_GL_GET_PROC(VertexAttribPointer);
+        GR_GL_GET_PROC(BindFragDataLocationIndexed);
 
-            // First look for GL3.0 FBO or GL_ARB_framebuffer_object (same since
-            // GL_ARB_framebuffer_object doesn't use ARB suffix.)
-            if (major >= 3 || has_gl_extension_from_string("GL_ARB_framebuffer_object", extString)) {
-                GR_GL_GET_PROC(GenFramebuffers);
-                GR_GL_GET_PROC(GetFramebufferAttachmentParameteriv);
-                GR_GL_GET_PROC(GetRenderbufferParameteriv);
-                GR_GL_GET_PROC(BindFramebuffer);
-                GR_GL_GET_PROC(FramebufferTexture2D);
-                GR_GL_GET_PROC(CheckFramebufferStatus);
-                GR_GL_GET_PROC(DeleteFramebuffers);
-                GR_GL_GET_PROC(RenderbufferStorage);
-                GR_GL_GET_PROC(GenRenderbuffers);
-                GR_GL_GET_PROC(DeleteRenderbuffers);
-                GR_GL_GET_PROC(FramebufferRenderbuffer);
-                GR_GL_GET_PROC(BindRenderbuffer);
-                GR_GL_GET_PROC(RenderbufferStorageMultisample);
-                GR_GL_GET_PROC(BlitFramebuffer);
-            } else if (has_gl_extension_from_string("GL_EXT_framebuffer_object", extString)) {
-                GR_GL_GET_PROC_SUFFIX(GenFramebuffers, EXT);
-                GR_GL_GET_PROC_SUFFIX(GetFramebufferAttachmentParameteriv, EXT);
-                GR_GL_GET_PROC_SUFFIX(GetRenderbufferParameteriv, EXT);
-                GR_GL_GET_PROC_SUFFIX(BindFramebuffer, EXT);
-                GR_GL_GET_PROC_SUFFIX(FramebufferTexture2D, EXT);
-                GR_GL_GET_PROC_SUFFIX(CheckFramebufferStatus, EXT);
-                GR_GL_GET_PROC_SUFFIX(DeleteFramebuffers, EXT);
-                GR_GL_GET_PROC_SUFFIX(RenderbufferStorage, EXT);
-                GR_GL_GET_PROC_SUFFIX(GenRenderbuffers, EXT);
-                GR_GL_GET_PROC_SUFFIX(DeleteRenderbuffers, EXT);
-                GR_GL_GET_PROC_SUFFIX(FramebufferRenderbuffer, EXT);
-                GR_GL_GET_PROC_SUFFIX(BindRenderbuffer, EXT);
-                if (has_gl_extension_from_string("GL_EXT_framebuffer_multisample", extString)) {
-                    GR_GL_GET_PROC_SUFFIX(RenderbufferStorageMultisample, EXT);
-                }
-                if (has_gl_extension_from_string("GL_EXT_framebuffer_blit", extString)) {
-                    GR_GL_GET_PROC_SUFFIX(BlitFramebuffer, EXT);
-                }
-            } else {
-                // we must have FBOs
-                return;
+        // First look for GL3.0 FBO or GL_ARB_framebuffer_object (same since
+        // GL_ARB_framebuffer_object doesn't use ARB suffix.)
+        if (major >= 3 || has_gl_extension_from_string("GL_ARB_framebuffer_object", extString)) {
+            GR_GL_GET_PROC(GenFramebuffers);
+            GR_GL_GET_PROC(GetFramebufferAttachmentParameteriv);
+            GR_GL_GET_PROC(GetRenderbufferParameteriv);
+            GR_GL_GET_PROC(BindFramebuffer);
+            GR_GL_GET_PROC(FramebufferTexture2D);
+            GR_GL_GET_PROC(CheckFramebufferStatus);
+            GR_GL_GET_PROC(DeleteFramebuffers);
+            GR_GL_GET_PROC(RenderbufferStorage);
+            GR_GL_GET_PROC(GenRenderbuffers);
+            GR_GL_GET_PROC(DeleteRenderbuffers);
+            GR_GL_GET_PROC(FramebufferRenderbuffer);
+            GR_GL_GET_PROC(BindRenderbuffer);
+            GR_GL_GET_PROC(RenderbufferStorageMultisample);
+            GR_GL_GET_PROC(BlitFramebuffer);
+        } else if (has_gl_extension_from_string("GL_EXT_framebuffer_object", extString)) {
+            GR_GL_GET_PROC_SUFFIX(GenFramebuffers, EXT);
+            GR_GL_GET_PROC_SUFFIX(GetFramebufferAttachmentParameteriv, EXT);
+            GR_GL_GET_PROC_SUFFIX(GetRenderbufferParameteriv, EXT);
+            GR_GL_GET_PROC_SUFFIX(BindFramebuffer, EXT);
+            GR_GL_GET_PROC_SUFFIX(FramebufferTexture2D, EXT);
+            GR_GL_GET_PROC_SUFFIX(CheckFramebufferStatus, EXT);
+            GR_GL_GET_PROC_SUFFIX(DeleteFramebuffers, EXT);
+            GR_GL_GET_PROC_SUFFIX(RenderbufferStorage, EXT);
+            GR_GL_GET_PROC_SUFFIX(GenRenderbuffers, EXT);
+            GR_GL_GET_PROC_SUFFIX(DeleteRenderbuffers, EXT);
+            GR_GL_GET_PROC_SUFFIX(FramebufferRenderbuffer, EXT);
+            GR_GL_GET_PROC_SUFFIX(BindRenderbuffer, EXT);
+            if (has_gl_extension_from_string("GL_EXT_framebuffer_multisample", extString)) {
+                GR_GL_GET_PROC_SUFFIX(RenderbufferStorageMultisample, EXT);
+            }
+            if (has_gl_extension_from_string("GL_EXT_framebuffer_blit", extString)) {
+                GR_GL_GET_PROC_SUFFIX(BlitFramebuffer, EXT);
             }
-            GR_GL_GET_PROC(MapBuffer);
-            GR_GL_GET_PROC(UnmapBuffer);
+        } else {
+            // we must have FBOs
+            return;
+        }
+        GR_GL_GET_PROC(MapBuffer);
+        GR_GL_GET_PROC(UnmapBuffer);
 
-            gDefaultInterface.fBindingsExported = kDesktop_GrGLBinding;
+        defaultInterface->fBindingsExported = kDesktop_GrGLBinding;
 
-            gDefaultInterfaceInit = true;
-        }
-    }
-    if (gDefaultInterfaceInit) {
-        GrGLSetGLInterface(&gDefaultInterface);
+        GrGLSetDefaultGLInterface(defaultInterface)->unref();
     }
 }
index 11e39a75062601de6af1e372f0f7fc1e54725ea4..7330cf3cff3655fe698e83d24bc95a2c96b9010c 100644 (file)
         '../gpu/src/GrGLProgram.h',
         '../gpu/src/GrGLRenderTarget.cpp',
         '../gpu/src/GrGLRenderTarget.h',
+        '../gpu/src/GrGLStencilBuffer.cpp',
         '../gpu/src/GrGLStencilBuffer.h',
         '../gpu/src/GrGLTexture.cpp',
         '../gpu/src/GrGLTexture.h',
index c523ad8f988a60514c546c18c27264c28931e5cc..3805ca6607b30950455f0f2402758d65a896426c 100644 (file)
@@ -153,10 +153,12 @@ public:
             desc.fWidth = SkScalarRound(win->width());
             desc.fHeight = SkScalarRound(win->height());
             desc.fConfig = kRGBA_8888_GrPixelConfig;
-            GR_GL_GetIntegerv(GR_GL_STENCIL_BITS, &desc.fStencilBits);
-            GR_GL_GetIntegerv(GR_GL_SAMPLES, &desc.fSampleCnt);
+            const GrGLInterface* gl = GrGLGetDefaultGLInterface();
+            GrAssert(NULL != gl);
+            GR_GL_GetIntegerv(gl, GR_GL_STENCIL_BITS, &desc.fStencilBits);
+            GR_GL_GetIntegerv(gl, GR_GL_SAMPLES, &desc.fSampleCnt);
             GrGLint buffer;
-            GR_GL_GetIntegerv(GR_GL_FRAMEBUFFER_BINDING, &buffer);
+            GR_GL_GetIntegerv(gl, GR_GL_FRAMEBUFFER_BINDING, &buffer);
             desc.fPlatformRenderTarget = buffer;
 
             SkSafeUnref(fGrRenderTarget);