Remove the compile-time selection of the GL implementation based on the
authortwiz@google.com <twiz@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Fri, 18 Mar 2011 20:41:44 +0000 (20:41 +0000)
committertwiz@google.com <twiz@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Fri, 18 Mar 2011 20:41:44 +0000 (20:41 +0000)
GR_SUPPORT_GLDESKTOP family of macros.

Support for the platform is configured dynamically, by querying the
fBindingsExported member of active GrGLInterface instance.

Review: http://codereview.appspot.com/4298048/

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

gpu/include/GrGLConfig.h
gpu/include/GrGLInterface.h
gpu/include/GrGLPlatformIncludes.h
gpu/include/GrGLTexture.h
gpu/src/GrGLInterface.cpp
gpu/src/GrGLTexture.cpp
gpu/src/GrGpuFactory.cpp
gpu/src/GrGpuGL.cpp
gpu/src/GrGpuGLFixed.cpp
gpu/src/GrGpuGLShaders2.cpp

index 3c1c597..8599b63 100644 (file)
 #include "GrGLDefines.h"
 
 /**
+ * The following macros are used to staticlly configure the default
+ * GrGLInterface, but should not be used outside of the GrGLInterface
+ * scaffolding.  Undefine here to prevent accidental use.
+ */
+#undef GR_SUPPORT_GLDESKTOP
+#undef GR_SUPPORT_GLES1
+#undef GR_SUPPORT_GLES2
+#undef GR_SUPPORT_GLES
+
+/**
  * The following are optional defines that can be enabled at the compiler
  * command line, in a IDE project, in a GrUserConfig.h file, or in a GL custom
  * file (if one is in use). They don't require GR_GL_CUSTOM_SETUP or
@@ -158,19 +168,22 @@ static inline void GrGLClearErr() {
 #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); GR_GL_CHECK_ERROR_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)
+
 ////////////////////////////////////////////////////////////////////////////////
 
 /**
  *  GrGL_RestoreResetRowLength() will reset GL_UNPACK_ROW_LENGTH to 0. We write
  *  this wrapper, since GL_UNPACK_ROW_LENGTH is not available on all GL versions
  */
-#if GR_SUPPORT_GLDESKTOP
-    static inline void GrGL_RestoreResetRowLength() {
+static inline void GrGL_RestoreResetRowLength() {
+    if (GR_GL_SUPPORT_DESKTOP) {
         GR_GL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0));
     }
-#else
-    #define GrGL_RestoreResetRowLength()
-#endif
+}
 
 ////////////////////////////////////////////////////////////////////////////////
 
index 7bee111..7a44f4f 100644 (file)
@@ -63,6 +63,12 @@ typedef double GrGLdouble;
 typedef double GrGLclampd;
 typedef void GrGLvoid;
 
+enum GrGLBinding {
+    kDesktop_GrGLBinding = 0x01,
+    kES1_GrGLBinding = 0x02,
+    kES2_GrGLBinding = 0x04
+};
+
 extern "C" {
 /*
  * The following interface exports the OpenGL entry points used by the system.
@@ -178,6 +184,10 @@ struct GrGLInterface {
     typedef GrGLvoid* (GR_GL_FUNCTION_TYPE *GrGLMapBufferProc)(GrGLenum target, GrGLenum access);
     typedef GrGLboolean (GR_GL_FUNCTION_TYPE *GrGLUnmapBufferProc)(GrGLenum target);
 
+    // Indicator variable specifying the type of GL implementation
+    // exported:  GLES{1|2} or Desktop.
+    GrGLBinding fBindingsExported;
+
     GrGLActiveTextureProc fActiveTexture;
     GrGLAttachShaderProc fAttachShader;
     GrGLBindAttribLocationProc fBindAttribLocation;
index 54ae6bf..65e5281 100644 (file)
  * Alternatively, define GR_GL_CUSTOM_SETUP_HEADER (and not GR_GL_CUSTOM_SETUP)
  * to a header that can be included. This file should:
  *      1. Define the approprate GR_SUPPORT_GL* macro(s) to 1
- *      2. Includes all necessary GL headers.
+ *      2. Specify all of the necessary GL include headers in the following
+ *         macros:
+ *              GR_GL_PLATFORM_HEADER_SUPPORT:  Header required before GL
+ *                                              includes.
+ *              GR_GL_PLATFORM_HEADER:  GL header location.
+ *              GR_GL_PLATFORM_HEADER_EXT:  (Optional)  Header for extension
+ *                                          definitions.
  *      3. Optionally define GR_GL_FUNCTION_TYPE.
  *      4. Define GR_GL_PROC_ADDRESS.
  *      5. Optionally define GR_GL_PROC_ADDRESS_HEADER
 #if GR_GL_CUSTOM_SETUP
 
     #ifdef GR_SUPPORT_GLES1
-        #include GR_INCLUDE_GLES1
+        #define GR_GL_PLATFORM_HEADER GR_INCLUDE_GLES1
         #if defined(GR_INCLUDE_GLES1ext)
-            #include GR_INCLUDE_GLES1ext
+            #define GR_GL_PLATFORM_HEADER_EXT GR_INCLUDE_GLES1ext
         #endif
     #endif
 
     #ifdef GR_SUPPORT_GLES2
-        #include GR_INCLUDE_GLES2
+        #define GR_GL_PLATFORM_HEADER GR_INCLUDE_GLES2
         #if defined(GR_INCLUDE_GLES2ext)
-            #include GR_INCLUDE_GLES2ext
+            #define GR_GL_PLATFORM_HEADER_EXT GR_INCLUDE_GLES2ext
         #endif
     #endif
 
     #ifdef GR_SUPPORT_GLDESKTOP
-        #include GR_INCLUDE_GLDESKTOP
+        #define GR_GL_PLATFORM_HEADER GR_INCLUDE_GLDESKTOP
         #if defined(GR_INCLUDE_GLDESKTOPext)
-            #include GR_INCLUDE_GLDESKTOPext
+            #define GR_GL_PLATFORM_HEADER_EXT GR_INCLUDE_GLDESKTOPext
         #endif
     #endif
 
index 0a1c107..1747b6d 100644 (file)
@@ -210,7 +210,7 @@ private:
     GrGLRenderTarget*   fRenderTarget;
     GrGpuGL*            fGpuGL;
 
-    static const GrGLenum gWrapMode2GLWrap[];
+    static const GrGLenum* WrapMode2GLWrap();
 
     friend class GrGpuGL;
 
index 4d72604..0bddd98 100644 (file)
@@ -244,6 +244,20 @@ void InitializeGLInterfaceExtensions(GrGLInterface* glBindings) {
 void GrGLInitializeGLInterface(GrGLInterface* glBindings) {
     Gr_bzero(glBindings, sizeof(GrGLInterface));
 
+    // Indicate the type of the exported GL functions based on macros
+    // pulled in from the platform includes.
+#if GR_SUPPORT_GLDESKTOP
+    glBindings->fBindingsExported = kDesktop_GrGLBinding;
+#endif
+
+#if GR_SUPPORT_GLES1 && !GR_SUPPORT_GLES2
+    glBindings->fBindingsExported = kES1_GrGLBinding;
+#endif
+
+#if GR_SUPPORT_GLES2
+    glBindings->fBindingsExported = kES2_GrGLBinding;
+#endif
+
 #if GR_SUPPORT_GLDESKTOP || GR_SUPPORT_GLES1
     // These entry points only exist on desktop GL implementations.
     GR_GL_GET_PROC_SYMBOL(Color4ub);
index a57871b..3970e85 100644 (file)
@@ -71,14 +71,24 @@ void GrGLRenderTarget::abandon() {
 
 ////////////////////////////////////////////////////////////////////////////////
 
-const GrGLenum GrGLTexture::gWrapMode2GLWrap[] = {
-    GR_GL_CLAMP_TO_EDGE,
-    GR_GL_REPEAT,
-#if GR_SUPPORT_GLES1 && !GR_SUPPORT_GLES2
-    GR_GL_REPEAT            // GL_MIRRORED_REPEAT not supported :(
-#else 
-    GR_GL_MIRRORED_REPEAT
-#endif
+const GrGLenum* GrGLTexture::WrapMode2GLWrap() {
+    static const GrGLenum mirrorRepeatModes[] = {
+        GR_GL_CLAMP_TO_EDGE,
+        GR_GL_REPEAT,
+        GR_GL_MIRRORED_REPEAT
+    };
+
+    static const GrGLenum repeatModes[] = {
+        GR_GL_CLAMP_TO_EDGE,
+        GR_GL_REPEAT,
+        GR_GL_REPEAT
+    };
+
+    if (GR_GL_SUPPORT_ES1 && !GR_GL_SUPPORT_ES2) {
+        return repeatModes;  // GL_MIRRORED_REPEAT not supported.
+    } else {
+        return mirrorRepeatModes;
+    }
 };
 
 
index 7c2db2b..0030656 100644 (file)
 
 #include "GrGLConfig.h"
 
-
-#if GR_SUPPORT_GLES1 || GR_SUPPORT_GLDESKTOP
-    #include "GrGpuGLFixed.h"
-#endif
-
-#if GR_SUPPORT_GLES2 || GR_SUPPORT_GLDESKTOP
-    #include "GrGpuGLShaders2.h"
-#endif
+#include "GrGpuGLFixed.h"
+#include "GrGpuGLShaders2.h"
 
 #include "GrGpu.h"
 
@@ -46,15 +40,11 @@ GrGpu* GrGpu::Create(Engine engine, Platform3DContext context3D) {
     switch (engine) {
         case kOpenGL_Shaders_Engine:
             GrAssert(NULL == context3D);
-#if GR_SUPPORT_GLES2 || GR_SUPPORT_GLDESKTOP
             gpu = new GrGpuGLShaders2;
-#endif
             break;
         case kOpenGL_Fixed_Engine:
             GrAssert(NULL == context3D);
-#if GR_SUPPORT_GLES1 || GR_SUPPORT_GLDESKTOP
             gpu = new GrGpuGLFixed;
-#endif
             break;
         case kDirect3D9_Engine:
             GrAssert(NULL != context3D);
@@ -69,6 +59,3 @@ GrGpu* GrGpu::Create(Engine engine, Platform3DContext context3D) {
 
     return gpu;
 }
-
-
-
index b7552d9..9604650 100644 (file)
 
 #include "GrGpuGL.h"
 #include "GrMemory.h"
-#if GR_WIN32_BUILD
-    // need to get wglGetProcAddress
-    #undef WIN32_LEAN_AND_MEAN
-    #define WIN32_LEAN_AND_MEAN 1
-    #include <windows.h>
-    #undef WIN32_LEAN_AND_MEAN
-#endif
-
 
 static const GrGLuint GR_MAX_GLUINT = ~0;
 static const GrGLint  GR_INVAL_GLINT = ~0;
@@ -201,14 +193,14 @@ 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_SUPPORT_GLDESKTOP || GR_SUPPORT_GLES2
-    GR_GL_GetIntegerv(GR_GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
-    GrAssert(maxTextureUnits > kNumStages);
-#endif
-#if GR_SUPPORT_GLDESKTOP || GR_SUPPORT_GLES1
-    GR_GL_GetIntegerv(GR_GL_MAX_TEXTURE_UNITS, &maxTextureUnits);
-    GrAssert(maxTextureUnits > kNumStages);
-#endif
+    if (GR_GL_SUPPORT_DESKTOP || GR_GL_SUPPORT_ES2) {
+        GR_GL_GetIntegerv(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);
+        GrAssert(maxTextureUnits > kNumStages);
+    }
 
     ////////////////////////////////////////////////////////////////////////////
     // Check for supported features.
@@ -250,17 +242,16 @@ GrGpuGL::GrGpuGL() {
             GrPrintf("MSAA Support: APPLE ES EXT.\n");
         }
     }
-#if GR_SUPPORT_GLDESKTOP
-    else if ((major >= 3) ||
+    else if (GR_GL_SUPPORT_DESKTOP && (
+             (major >= 3) ||
              has_gl_extension("GL_ARB_framebuffer_object") ||
              (has_gl_extension("GL_EXT_framebuffer_multisample") &&
-              has_gl_extension("GL_EXT_framebuffer_blit"))) {
+              has_gl_extension("GL_EXT_framebuffer_blit")))) {
         fMSFBOType = kDesktop_MSFBO;
          if (gPrintStartupSpew) {
              GrPrintf("MSAA Support: DESKTOP\n");
          }
     }
-#endif
     else {
         if (gPrintStartupSpew) {
             GrPrintf("MSAA Support: NONE\n");
@@ -288,83 +279,84 @@ GrGpuGL::GrGpuGL() {
         }
     }
 
-#if GR_SUPPORT_GLDESKTOP
-    fHasStencilWrap = (major >= 2 || (major == 1 && minor >= 4)) ||
-                      has_gl_extension("GL_EXT_stencil_wrap");
-#else
-    fHasStencilWrap = (major >= 2) || has_gl_extension("GL_OES_stencil_wrap");
-#endif
+    if (GR_GL_SUPPORT_DESKTOP) {
+        fHasStencilWrap = (major >= 2 || (major == 1 && minor >= 4)) ||
+                          has_gl_extension("GL_EXT_stencil_wrap");
+    } else {
+        fHasStencilWrap = (major >= 2) || has_gl_extension("GL_OES_stencil_wrap");
+    }
     if (gPrintStartupSpew) {
         GrPrintf("Stencil Wrap: %s\n", (fHasStencilWrap ? "YES" : "NO"));
     }
 
-#if GR_SUPPORT_GLDESKTOP
-    // 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).
-    fTwoSidedStencilSupport = (major >= 2);
-    // supported on GL 1.4 and higher or by extension
-    fStencilWrapOpsSupport = (major > 1) ||
-                             ((1 == major) && (minor >= 4)) ||
-                              has_gl_extension("GL_EXT_stencil_wrap");
-#else
-    // ES 2 has two sided stencil but 1.1 doesn't. There doesn't seem to be
-    // an ES1 extension.
-    fTwoSidedStencilSupport = (major >= 2);
-    // stencil wrap support is in ES2, ES1 requires extension.
-    fStencilWrapOpsSupport = (major > 1) ||
-                              has_gl_extension("GL_OES_stencil_wrap");
-
-#endif
+    if (GR_GL_SUPPORT_DESKTOP) {
+        // 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).
+        fTwoSidedStencilSupport = (major >= 2);
+        // supported on GL 1.4 and higher or by extension
+        fStencilWrapOpsSupport = (major > 1) ||
+                                 ((1 == major) && (minor >= 4)) ||
+                                  has_gl_extension("GL_EXT_stencil_wrap");
+    } else {
+        // ES 2 has two sided stencil but 1.1 doesn't. There doesn't seem to be
+        // an ES1 extension.
+        fTwoSidedStencilSupport = (major >= 2);
+        // stencil wrap support is in ES2, ES1 requires extension.
+        fStencilWrapOpsSupport = (major > 1) ||
+                                  has_gl_extension("GL_OES_stencil_wrap");
+    }
     if (gPrintStartupSpew) {
         GrPrintf("Stencil Caps: TwoSide: %s, Wrap: %s\n",
                 (fTwoSidedStencilSupport ? "YES" : "NO"),
                 (fStencilWrapOpsSupport ? "YES" : "NO"));
     }
 
-#if GR_SUPPORT_GLDESKTOP
-    fRGBA8Renderbuffer = true;
-#else
-    fRGBA8Renderbuffer = has_gl_extension("GL_OES_rgb8_rgba8");
-#endif
+    if (GR_GL_SUPPORT_DESKTOP) {
+        fRGBA8Renderbuffer = true;
+    } else {
+        fRGBA8Renderbuffer = has_gl_extension("GL_OES_rgb8_rgba8");
+    }
     if (gPrintStartupSpew) {
         GrPrintf("RGBA Renderbuffer: %s\n", (fRGBA8Renderbuffer ? "YES" : "NO"));
     }
 
-#if GR_SUPPORT_GLES
-    if (GR_GL_32BPP_COLOR_FORMAT == GR_BGRA) {
-        GrAssert(has_gl_extension("GL_EXT_texture_format_BGRA8888"));
+
+    if (GR_GL_SUPPORT_ES) {
+        if (GR_GL_32BPP_COLOR_FORMAT == GR_BGRA) {
+            GrAssert(has_gl_extension("GL_EXT_texture_format_BGRA8888"));
+        }
     }
-#endif
 
-#if GR_SUPPORT_GLDESKTOP
-    fBufferLockSupport = true; // we require VBO support and the desktop VBO
-                               // extension includes glMapBuffer.
-#else
-    fBufferLockSupport = has_gl_extension("GL_OES_mapbuffer");
-#endif
+    if (GR_GL_SUPPORT_DESKTOP) {
+        fBufferLockSupport = true; // we require VBO support and the desktop VBO
+                                   // extension includes glMapBuffer.
+    } else {
+        fBufferLockSupport = has_gl_extension("GL_OES_mapbuffer");
+    }
 
     if (gPrintStartupSpew) {
         GrPrintf("Map Buffer: %s\n", (fBufferLockSupport ? "YES" : "NO"));
     }
 
-#if GR_SUPPORT_GLDESKTOP
-    if (major >= 2 || has_gl_extension("GL_ARB_texture_non_power_of_two")) {
-        fNPOTTextureTileSupport = true;
-        fNPOTTextureSupport = true;
-    } else {
-        fNPOTTextureTileSupport = false;
-        fNPOTTextureSupport = false;
-    }
-#else
-    if (major >= 2) {
-        fNPOTTextureSupport = true;
-        fNPOTTextureTileSupport = has_gl_extension("GL_OES_texture_npot");
+    if (GR_GL_SUPPORT_DESKTOP) {
+        if (major >= 2 || has_gl_extension("GL_ARB_texture_non_power_of_two")) {
+            fNPOTTextureTileSupport = true;
+            fNPOTTextureSupport = true;
+        } else {
+            fNPOTTextureTileSupport = false;
+            fNPOTTextureSupport = false;
+        }
     } else {
-        fNPOTTextureSupport = has_gl_extension("GL_APPLE_texture_2D_limited_npot");
-        fNPOTTextureTileSupport = false;
+        if (major >= 2) {
+            fNPOTTextureSupport = true;
+            fNPOTTextureTileSupport = has_gl_extension("GL_OES_texture_npot");
+        } else {
+            fNPOTTextureSupport =
+                        has_gl_extension("GL_APPLE_texture_2D_limited_npot");
+            fNPOTTextureTileSupport = false;
+        }
     }
-#endif
 
     ////////////////////////////////////////////////////////////////////////////
     // Experiments to determine limitations that can't be queried. TODO: Make
@@ -482,11 +474,11 @@ void GrGpuGL::resetContext() {
     fHWDrawState.fDrawFace = kBoth_DrawFace;
 
     GR_GL(Disable(GR_GL_DITHER));
-#if GR_SUPPORT_GLDESKTOP
-    GR_GL(Disable(GR_GL_LINE_SMOOTH));
-    GR_GL(Disable(GR_GL_POINT_SMOOTH));
-    GR_GL(Disable(GR_GL_MULTISAMPLE));
-#endif
+    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));
+    }
 
     GR_GL(ColorMask(GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE));
     fHWDrawState.fFlagBits = 0;
@@ -583,25 +575,36 @@ GrRenderTarget* GrGpuGL::createRenderTargetFrom3DApiStateHelper() {
 
 static const GrGLuint UNKNOWN_BITS = ~0;
 
-// defines stencil formats from more to less preferred
-static const struct {
+struct StencilFormat {
     GrGLenum  fEnum;
     GrGLuint  fBits;
-} gStencilFormats[] = {
-    {GR_STENCIL_INDEX8,     8},
+};
 
-#if GR_SUPPORT_GLDESKTOP
-    {GR_STENCIL_INDEX16,    16},
-#endif
+const StencilFormat* GrGLStencilFormats() {
+    // defines stencil formats from more to less preferred
+    static const StencilFormat desktopStencilFormats[] = {
+        {GR_STENCIL_INDEX8,     8},
+        {GR_STENCIL_INDEX16,    16},
+        {GR_DEPTH24_STENCIL8,   8},
+        {GR_STENCIL_INDEX4,     4},
+        {GR_GL_STENCIL_INDEX,      UNKNOWN_BITS},
+        {GR_DEPTH_STENCIL,      UNKNOWN_BITS},
+        {0, 0}
+    };
 
-    {GR_DEPTH24_STENCIL8,   8},
-    {GR_STENCIL_INDEX4,     4},
+    static const StencilFormat esStencilFormats[] = {
+        {GR_STENCIL_INDEX8,     8},
+        {GR_DEPTH24_STENCIL8,   8},
+        {GR_STENCIL_INDEX4,     4},
+        {0, 0}
+    };
 
-#if GR_SUPPORT_GLDESKTOP
-    {GR_GL_STENCIL_INDEX,      UNKNOWN_BITS},
-    {GR_DEPTH_STENCIL,      UNKNOWN_BITS}
-#endif
-};
+    if (GR_GL_SUPPORT_DESKTOP) {
+        return desktopStencilFormats;
+    } else {
+        return esStencilFormats;
+    }
+}
 
 // good to set a break-point here to know when createTexture fails
 static GrTexture* return_null_texture() {
@@ -667,29 +670,29 @@ GrTexture* GrGpuGL::createTextureHelper(const TextureDesc& desc,
      *  to trim those off here, since GL doesn't let us pass the rowBytes as
      *  a parameter to glTexImage2D
      */
-#if GR_SUPPORT_GLDESKTOP
-    if (srcData) {
-        GR_GL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH,
-                          rowBytes / glDesc.fUploadByteCount));
-    }
-#else
-    GrAutoSMalloc<128 * 128> trimStorage;
-    size_t trimRowBytes = desc.fWidth * glDesc.fUploadByteCount;
-    if (srcData && (trimRowBytes < rowBytes)) {
-        size_t trimSize = desc.fHeight * trimRowBytes;
-        trimStorage.realloc(trimSize);
-        // now copy the data into our new storage, skipping the trailing bytes
-        const char* src = (const char*)srcData;
-        char* dst = (char*)trimStorage.get();
-        for (uint32_t y = 0; y < desc.fHeight; y++) {
-            memcpy(dst, src, trimRowBytes);
-            src += rowBytes;
-            dst += trimRowBytes;
+    if (GR_GL_SUPPORT_DESKTOP) {
+        if (srcData) {
+            GR_GL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH,
+                              rowBytes / glDesc.fUploadByteCount));
+        }
+    } else {
+        GrAutoSMalloc<128 * 128> trimStorage;
+        size_t trimRowBytes = desc.fWidth * glDesc.fUploadByteCount;
+        if (srcData && (trimRowBytes < rowBytes)) {
+            size_t trimSize = desc.fHeight * trimRowBytes;
+            trimStorage.realloc(trimSize);
+            // now copy the data into our new storage, skipping the trailing bytes
+            const char* src = (const char*)srcData;
+            char* dst = (char*)trimStorage.get();
+            for (uint32_t y = 0; y < desc.fHeight; y++) {
+                memcpy(dst, src, trimRowBytes);
+                src += rowBytes;
+                dst += trimRowBytes;
+            }
+            // now point srcData to our trimmed version
+            srcData = trimStorage.get();
         }
-        // now point srcData to our trimmed version
-        srcData = trimStorage.get();
     }
-#endif
 
     if (renderTarget) {
         if (!this->npotRenderTargetSupport()) {
@@ -846,11 +849,9 @@ GrTexture* GrGpuGL::createTextureHelper(const TextureDesc& desc,
         } else {
             rtIDs.fRTFBOID = rtIDs.fTexFBOID;
         }
-        int attempts = 1;
         if (!(kNoPathRendering_TextureFlag & desc.fFlags)) {
             GR_GL(GenRenderbuffers(1, &rtIDs.fStencilRenderbufferID));
             GrAssert(0 != rtIDs.fStencilRenderbufferID);
-            attempts = GR_ARRAY_COUNT(gStencilFormats);
         }
 
         // someone suggested that some systems might require
@@ -859,7 +860,9 @@ GrTexture* GrGpuGL::createTextureHelper(const TextureDesc& desc,
         GR_GL(BindTexture(GR_GL_TEXTURE_2D, 0));
 
         err = ~GR_GL_NO_ERROR;
-        for (int i = 0; i < attempts; ++i) {
+
+        const StencilFormat* stencilFormats = GrGLStencilFormats();
+        for (int i = 0; 0 != stencilFormats[i].fEnum; ++i) {
             if (rtIDs.fStencilRenderbufferID) {
                 GR_GL(BindRenderbuffer(GR_RENDERBUFFER,
                                        rtIDs.fStencilRenderbufferID));
@@ -867,12 +870,12 @@ GrTexture* GrGpuGL::createTextureHelper(const TextureDesc& desc,
                     GR_GL_NO_ERR(RenderbufferStorageMultisample(
                                                 GR_RENDERBUFFER,
                                                 samples,
-                                                gStencilFormats[i].fEnum,
+                                                stencilFormats[i].fEnum,
                                                 glDesc.fAllocWidth,
                                                 glDesc.fAllocHeight));
                 } else {
                     GR_GL_NO_ERR(RenderbufferStorage(GR_RENDERBUFFER,
-                                                     gStencilFormats[i].fEnum,
+                                                     stencilFormats[i].fEnum,
                                                      glDesc.fAllocWidth,
                                                      glDesc.fAllocHeight));
                 }
@@ -941,43 +944,43 @@ GrTexture* GrGpuGL::createTextureHelper(const TextureDesc& desc,
             }
             status = GR_GL(CheckFramebufferStatus(GR_FRAMEBUFFER));
 
-#if GR_SUPPORT_GLDESKTOP
-            // On some implementations you have to be bound as DEPTH_STENCIL.
-            // (Even binding to DEPTH and STENCIL separately with the same
-            // buffer doesn't work.)
-            if (rtIDs.fStencilRenderbufferID &&
-                status != GR_FRAMEBUFFER_COMPLETE) {
-                GR_GL(FramebufferRenderbuffer(GR_FRAMEBUFFER,
-                                              GR_STENCIL_ATTACHMENT,
-                                              GR_RENDERBUFFER,
-                                              0));
-                GR_GL(FramebufferRenderbuffer(GR_FRAMEBUFFER,
-                                              GR_DEPTH_STENCIL_ATTACHMENT,
-                                              GR_RENDERBUFFER,
-                                              rtIDs.fStencilRenderbufferID));
-                status = GR_GL(CheckFramebufferStatus(GR_FRAMEBUFFER));
+            if (GR_GL_SUPPORT_DESKTOP) {
+                // On some implementations you have to be bound as DEPTH_STENCIL.
+                // (Even binding to DEPTH and STENCIL separately with the same
+                // buffer doesn't work.)
+                if (rtIDs.fStencilRenderbufferID &&
+                    status != GR_FRAMEBUFFER_COMPLETE) {
+                    GR_GL(FramebufferRenderbuffer(GR_FRAMEBUFFER,
+                                                  GR_STENCIL_ATTACHMENT,
+                                                  GR_RENDERBUFFER,
+                                                  0));
+                    GR_GL(FramebufferRenderbuffer(GR_FRAMEBUFFER,
+                                                  GR_DEPTH_STENCIL_ATTACHMENT,
+                                                  GR_RENDERBUFFER,
+                                                  rtIDs.fStencilRenderbufferID));
+                    status = GR_GL(CheckFramebufferStatus(GR_FRAMEBUFFER));
+                }
             }
-#endif
             if (status != GR_FRAMEBUFFER_COMPLETE) {
                 GrPrintf("-- glCheckFramebufferStatus %x %d %d\n",
                          status, desc.fWidth, desc.fHeight);
-#if GR_SUPPORT_GLDESKTOP
-                if (rtIDs.fStencilRenderbufferID) {
-                    GR_GL(FramebufferRenderbuffer(GR_FRAMEBUFFER,
-                                                  GR_DEPTH_STENCIL_ATTACHMENT,
-                                                  GR_RENDERBUFFER,
-                                                  0));
+                if (GR_GL_SUPPORT_DESKTOP) {
+                    if (rtIDs.fStencilRenderbufferID) {
+                        GR_GL(FramebufferRenderbuffer(GR_FRAMEBUFFER,
+                                                      GR_DEPTH_STENCIL_ATTACHMENT,
+                                                      GR_RENDERBUFFER,
+                                                      0));
+                    }
                 }
-#endif
                 continue;
             }
             // we're successful!
             failed = false;
             if (rtIDs.fStencilRenderbufferID) {
-                if (UNKNOWN_BITS == gStencilFormats[i].fBits) {
+                if (UNKNOWN_BITS == stencilFormats[i].fBits) {
                     GR_GL_GetIntegerv(GR_GL_STENCIL_BITS, (GrGLint*)&glDesc.fStencilBits);
                 } else {
-                    glDesc.fStencilBits = gStencilFormats[i].fBits;
+                    glDesc.fStencilBits = stencilFormats[i].fBits;
                 }
             }
             break;
@@ -1556,9 +1559,9 @@ bool GrGpuGL::flushGLStateCommon(GrPrimitiveType type) {
                 newTexParams.fFilter = sampler.isFilter() ? GR_GL_LINEAR :
                                                             GR_GL_NEAREST;
                 newTexParams.fWrapS =
-                            GrGLTexture::gWrapMode2GLWrap[sampler.getWrapX()];
+                            GrGLTexture::WrapMode2GLWrap()[sampler.getWrapX()];
                 newTexParams.fWrapT =
-                            GrGLTexture::gWrapMode2GLWrap[sampler.getWrapY()];
+                            GrGLTexture::WrapMode2GLWrap()[sampler.getWrapY()];
 
                 if (newTexParams.fFilter != oldTexParams.fFilter) {
                     setTextureUnit(s);
@@ -1615,33 +1618,33 @@ bool GrGpuGL::flushGLStateCommon(GrPrimitiveType type) {
         GR_GL(ColorMask(mask, mask, mask, mask));
     }
 
-#if GR_SUPPORT_GLDESKTOP
-    // ES doesn't support toggling GL_MULTISAMPLE and doesn't have
-    // smooth lines.
-    if (fDirtyFlags.fRenderTargetChanged ||
-        (fCurrDrawState.fFlagBits & kAntialias_StateBit) !=
-        (fHWDrawState.fFlagBits & kAntialias_StateBit)) {
-        GrGLint msaa = 0;
-        // only perform query if we know MSAA is supported.
-        // calling on non-MSAA target caused a crash in one environment,
-        // though I don't think it should.
-        if (fAASamples[kHigh_AALevel]) {
-            GR_GL_GetIntegerv(GR_GL_SAMPLE_BUFFERS, &msaa);
-        }
-        if (fCurrDrawState.fFlagBits & kAntialias_StateBit) {
-            if (msaa) {
-                GR_GL(Enable(GR_GL_MULTISAMPLE));
-            } else {
-                GR_GL(Enable(GR_GL_LINE_SMOOTH));
+    if (GR_GL_SUPPORT_DESKTOP) {
+        // ES doesn't support toggling GL_MULTISAMPLE and doesn't have
+        // smooth lines.
+        if (fDirtyFlags.fRenderTargetChanged ||
+            (fCurrDrawState.fFlagBits & kAntialias_StateBit) !=
+            (fHWDrawState.fFlagBits & kAntialias_StateBit)) {
+            GrGLint msaa = 0;
+            // only perform query if we know MSAA is supported.
+            // calling on non-MSAA target caused a crash in one environment,
+            // though I don't think it should.
+            if (fAASamples[kHigh_AALevel]) {
+                GR_GL_GetIntegerv(GR_GL_SAMPLE_BUFFERS, &msaa);
             }
-        } else {
-            if (msaa) {
-                GR_GL(Disable(GR_GL_MULTISAMPLE));
+            if (fCurrDrawState.fFlagBits & kAntialias_StateBit) {
+                if (msaa) {
+                    GR_GL(Enable(GR_GL_MULTISAMPLE));
+                } else {
+                    GR_GL(Enable(GR_GL_LINE_SMOOTH));
+                }
+            } else {
+                if (msaa) {
+                    GR_GL(Disable(GR_GL_MULTISAMPLE));
+                }
+                GR_GL(Disable(GR_GL_LINE_SMOOTH));
             }
-            GR_GL(Disable(GR_GL_LINE_SMOOTH));
         }
     }
-#endif
 
     bool blendOff = canDisableBlend();
     if (fHWBlendDisabled != blendOff) {
@@ -1775,13 +1778,13 @@ bool GrGpuGL::canBeTexture(GrTexture::PixelConfig config,
         case GrTexture::kRGBA_8888_PixelConfig:
         case GrTexture::kRGBX_8888_PixelConfig: // todo: can we tell it our X?
             *format = GR_GL_32BPP_COLOR_FORMAT;
-#if GR_SUPPORT_GLES
-            // 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;
-#else
-            *internalFormat = GR_GL_RGBA;
-#endif
+            if (GR_GL_SUPPORT_ES) {
+                // 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;
+            } else {
+                *internalFormat = GR_GL_RGBA;
+            }
             *type = GR_GL_UNSIGNED_BYTE;
             break;
         case GrTexture::kRGB_565_PixelConfig:
@@ -1845,12 +1848,12 @@ bool GrGpuGL::fboInternalFormat(GrTexture::PixelConfig config, GrGLenum* format)
             } else {
                 return false;
             }
-#if GR_SUPPORT_GLES // ES2 supports 565. ES1 supports it with FBO extension
-                    // desktop GL has no such internal format
         case GrTexture::kRGB_565_PixelConfig:
+            GrAssert(GR_GL_SUPPORT_ES);  // ES2 supports 565. ES1 supports it
+                                         // with FBO extension desktop GL has
+                                         // no such internal format
             *format = GR_RGB565;
             return true;
-#endif
         case GrTexture::kRGBA_4444_PixelConfig:
             *format = GR_GL_RGBA4;
             return true;
index 5a053a0..3e6d909 100644 (file)
@@ -17,8 +17,6 @@
 
 #include "GrGLConfig.h"
 
-#if GR_SUPPORT_GLES1 || GR_SUPPORT_GLDESKTOP
-
 #include "GrGpuGLFixed.h"
 #include "GrGpuVertex.h"
 
@@ -137,13 +135,13 @@ bool GrGpuGLFixed::flushGraphicsState(GrPrimitiveType type) {
         }
     }
 
-#if GR_SUPPORT_GLES1
-    if (BlendCoefReferencesConstant(fCurrDrawState.fSrcBlend) ||
-        BlendCoefReferencesConstant(fCurrDrawState.fDstBlend)) {
-        uimpl("ES1 doesn't support blend constant");
-        return false;
+    if (GR_GL_SUPPORT_ES1) {
+        if (BlendCoefReferencesConstant(fCurrDrawState.fSrcBlend) ||
+            BlendCoefReferencesConstant(fCurrDrawState.fDstBlend)) {
+            unimpl("ES1 doesn't support blend constant");
+            return false;
+        }
     }
-#endif
 
     if (!flushGLStateCommon(type)) {
         return false;
@@ -330,6 +328,3 @@ void GrGpuGLFixed::setupGeometry(int* startVertex,
     fHWGeometryState.fVertexLayout = fGeometrySrc.fVertexLayout;
     fHWGeometryState.fArrayPtrsDirty = false;
 }
-
-#endif
-
index 972d8a3..a56e511 100644 (file)
@@ -17,8 +17,6 @@
 
 #include "GrGLConfig.h"
 
-#if GR_SUPPORT_GLES2 || GR_SUPPORT_GLDESKTOP
-
 #include "GrGpuGLShaders2.h"
 #include "GrGpuVertex.h"
 #include "GrMemory.h"
 
 #define SKIP_CACHE_CHECK    true
 
-#if GR_SUPPORT_GLES2
-    #define GR_PRECISION                "mediump"
-    const char GR_SHADER_PRECISION[] =  "precision mediump float;\n";
-#else
-    #define GR_PRECISION                ""
-    const char GR_SHADER_PRECISION[] =  "";
-#endif
-
-
 #define POS_ATTR_LOCATION 0
 #define TEX_ATTR_LOCATION(X) (1 + X)
 #define COL_ATTR_LOCATION (2 + GrDrawTarget::kMaxTexCoords)
 
 #define GR_UINT32_MAX   static_cast<uint32_t>(-1)
 
+namespace {
+
+const char* GrPrecision() {
+    if (GR_GL_SUPPORT_ES2) {
+        return "mediump";
+    } else {
+        return "";
+    }
+}
+
+const char* GrShaderPrecision() {
+    if (GR_GL_SUPPORT_ES2) {
+        return "precision mediump float;\n";
+    } else {
+        return "";
+    }
+}
+
+}  // namespace
+
 struct GrGpuGLShaders2::StageUniLocations {
     GrGLint fTextureMatrixUni;
     GrGLint fSamplerUni;
@@ -501,11 +510,15 @@ void GrGpuGLShaders2::GenStageCode(int stageNum,
 
     if (StageDesc::kRadial2Gradient_CoordMapping == desc.fCoordMapping) {
 
-        segments->fVSUnis += "uniform " GR_PRECISION " float ";
+        segments->fVSUnis += "uniform ";
+        segments->fVSUnis += GrPrecision();
+        segments->fVSUnis += " float ";
         segments->fVSUnis += radial2ParamsName;
         segments->fVSUnis += "[6];\n";
 
-        segments->fFSUnis += "uniform " GR_PRECISION " float ";
+        segments->fFSUnis += "uniform ";
+        segments->fFSUnis += GrPrecision();
+        segments->fFSUnis += " float ";
         segments->fFSUnis += radial2ParamsName;
         segments->fFSUnis += "[6];\n";
         locations->fRadial2Uni = 1;
@@ -821,9 +834,9 @@ void GrGpuGLShaders2::GenProgram(const ProgramDesc& desc,
 
     stringCnt = 0;
 
-    if (GR_ARRAY_COUNT(GR_SHADER_PRECISION) > 1) {
-        strings[stringCnt] = GR_SHADER_PRECISION;
-        lengths[stringCnt] = GR_ARRAY_COUNT(GR_SHADER_PRECISION) - 1;
+    if (strlen(GrShaderPrecision()) > 1) {
+        strings[stringCnt] = GrShaderPrecision();
+        lengths[stringCnt] = strlen(GrShaderPrecision());
         ++stringCnt;
     }
     if (segments.fFSUnis.length()) {
@@ -844,7 +857,7 @@ void GrGpuGLShaders2::GenProgram(const ProgramDesc& desc,
 
 #if PRINT_SHADERS
     GrPrintf("%s%s%s%s\n",
-             GR_SHADER_PRECISION,
+             GrShaderPrecision(),
              segments.fFSUnis.cstr(),
              segments.fVaryings.cstr(),
              segments.fFSCode.cstr());
@@ -1401,6 +1414,3 @@ void GrGpuGLShaders2::setupGeometry(int* startVertex,
     fHWGeometryState.fVertexLayout = fGeometrySrc.fVertexLayout;
     fHWGeometryState.fArrayPtrsDirty = false;
 }
-#endif
-
-