diff --git a/bench/BenchGpuTimer_gl.cpp b/bench/BenchGpuTimer_gl.cpp index b7bd88b639..32909832f3 100644 --- a/bench/BenchGpuTimer_gl.cpp +++ b/bench/BenchGpuTimer_gl.cpp @@ -7,6 +7,7 @@ */ #include "BenchGpuTimer_gl.h" #include "gl/SkGLContext.h" +#include "gl/GrGLUtil.h" BenchGpuTimer::BenchGpuTimer(const SkGLContext* glctx) { fContext = glctx; diff --git a/gyp/SampleApp.gyp b/gyp/SampleApp.gyp index 9e74982c26..a9af72a235 100644 --- a/gyp/SampleApp.gyp +++ b/gyp/SampleApp.gyp @@ -10,6 +10,7 @@ '../gm', # needed to pull gm.h '../include/pipe', # To pull in SkGPipe.h for pipe reader/writer '../samplecode', # To pull SampleApp.h and SampleCode.h + '../src/gpu', # To pull gl/GrGLUtil.h ], 'includes': [ 'gmslides.gypi', diff --git a/gyp/gpu.gyp b/gyp/gpu.gyp index 31662abb9a..6f304d1cb0 100644 --- a/gyp/gpu.gyp +++ b/gyp/gpu.gyp @@ -91,6 +91,7 @@ '../include/core', '../src/core', '../include/gpu', + '../src/gpu', ], 'dependencies': [ 'libtess.gyp:libtess', @@ -301,6 +302,7 @@ '../src/gpu/gl/GrGLTexture.cpp', '../src/gpu/gl/GrGLTexture.h', '../src/gpu/gl/GrGLUtil.cpp', + '../src/gpu/gl/GrGLUtil.h', '../src/gpu/gl/GrGLVertexBuffer.cpp', '../src/gpu/gl/GrGLVertexBuffer.h', '../src/gpu/gl/GrGpuGL.cpp', diff --git a/include/gpu/gl/GrGLConfig.h b/include/gpu/gl/GrGLConfig.h index 806f05574e..32fa6d0383 100644 --- a/include/gpu/gl/GrGLConfig.h +++ b/include/gpu/gl/GrGLConfig.h @@ -267,36 +267,4 @@ extern void GrGLClearErr(const GrGLInterface* gl); #define GR_GL_GET_ERROR(IFACE) (IFACE)->fGetError() -//////////////////////////////////////////////////////////////////////////////// - -/** - * Some drivers want the var-int arg to be zero-initialized on input. - */ -#define GR_GL_INIT_ZERO 0 -#define GR_GL_GetIntegerv(gl, e, p) \ - do { \ - *(p) = GR_GL_INIT_ZERO; \ - GR_GL_CALL(gl, GetIntegerv(e, p)); \ - } while (0) - -#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(gl, t, pname, p) \ - do { \ - *(p) = GR_GL_INIT_ZERO; \ - GR_GL_CALL(gl, GetRenderbufferParameteriv(t, pname, p)); \ - } while (0) - -#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) - -//////////////////////////////////////////////////////////////////////////////// - #endif diff --git a/include/gpu/gl/GrGLInterface.h b/include/gpu/gl/GrGLInterface.h index 4b76defa5b..05c7c4f31d 100644 --- a/include/gpu/gl/GrGLInterface.h +++ b/include/gpu/gl/GrGLInterface.h @@ -7,7 +7,6 @@ */ - #ifndef GrGLInterface_DEFINED #define GrGLInterface_DEFINED @@ -37,32 +36,6 @@ enum GrGLBinding { //////////////////////////////////////////////////////////////////////////////// -/** - * Helpers for glGetString() - */ - -typedef uint32_t GrGLVersion; -typedef uint32_t GrGLSLVersion; - -#define GR_GL_VER(major, minor) ((static_cast(major) << 16) | \ - static_cast(minor)) -#define GR_GLSL_VER(major, minor) ((static_cast(major) << 16) | \ - static_cast(minor)) - -// these variants assume caller already has a string from glGetString() -GrGLVersion GrGLGetVersionFromString(const char* versionString); -GrGLBinding GrGLGetBindingInUseFromString(const char* versionString); -GrGLSLVersion GrGLGetGLSLVersionFromString(const char* versionString); -bool GrGLHasExtensionFromString(const char* ext, const char* extensionString); - -// these variants call glGetString() -bool GrGLHasExtension(const GrGLInterface*, const char* ext); -GrGLBinding GrGLGetBindingInUse(const GrGLInterface*); -GrGLVersion GrGLGetVersion(const GrGLInterface*); -GrGLSLVersion GrGLGetGLSLVersion(const GrGLInterface*); - -//////////////////////////////////////////////////////////////////////////////// - /** * 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 @@ -285,7 +258,7 @@ enum GrGLCapability { */ struct GR_API GrGLInterface : public GrRefCnt { private: - // simple wrapper class that exists only to initialize a pointers to NULL + // simple wrapper class that exists only to initialize a pointer to NULL template class GLPtr { public: GLPtr() : fPtr(NULL) {} diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp index 05f9c82031..6bfa897128 100644 --- a/samplecode/SampleApp.cpp +++ b/samplecode/SampleApp.cpp @@ -23,6 +23,7 @@ #include "SkTypeface.h" #include "gl/GrGLInterface.h" +#include "gl/GrGLUtil.h" #include "GrRenderTarget.h" #include "SkPDFDevice.h" diff --git a/src/gpu/gl/GrGLContextInfo.h b/src/gpu/gl/GrGLContextInfo.h index c37b11d92a..44fc98555f 100644 --- a/src/gpu/gl/GrGLContextInfo.h +++ b/src/gpu/gl/GrGLContextInfo.h @@ -9,9 +9,10 @@ #ifndef GrGLContextInfo_DEFINED #define GrGLContextInfo_DEFINED -#include "GrGLCaps.h" #include "gl/GrGLInterface.h" +#include "GrGLCaps.h" #include "GrGLSL.h" +#include "GrGLUtil.h" #include "SkString.h" diff --git a/src/gpu/gl/GrGLIRect.h b/src/gpu/gl/GrGLIRect.h index aee5fb4cca..05bba117fc 100644 --- a/src/gpu/gl/GrGLIRect.h +++ b/src/gpu/gl/GrGLIRect.h @@ -12,6 +12,7 @@ #define GrGLIRect_DEFINED #include "gl/GrGLInterface.h" +#include "GrGLUtil.h" /** * Helper struct for dealing with the fact that Ganesh and GL use different diff --git a/src/gpu/gl/GrGLInterface.cpp b/src/gpu/gl/GrGLInterface.cpp index 57de3e03fc..bbcf9233b8 100644 --- a/src/gpu/gl/GrGLInterface.cpp +++ b/src/gpu/gl/GrGLInterface.cpp @@ -7,9 +7,8 @@ */ -#include "GrTypes.h" #include "gl/GrGLInterface.h" -#include "gl/GrGLDefines.h" +#include "GrGLUtil.h" #include @@ -19,135 +18,6 @@ void GrGLDefaultInterfaceCallback(const GrGLInterface*) {} } #endif -GrGLBinding GrGLGetBindingInUseFromString(const char* versionString) { - if (NULL == versionString) { - GrAssert(!"NULL GL version string."); - return kNone_GrGLBinding; - } - - int major, minor; - - // check for desktop - int n = sscanf(versionString, "%d.%d", &major, &minor); - if (2 == n) { - return kDesktop_GrGLBinding; - } - - // check for ES 1 - char profile[2]; - n = sscanf(versionString, "OpenGL ES-%c%c %d.%d", profile, profile+1, - &major, &minor); - if (4 == n) { - // we no longer support ES1. - return kNone_GrGLBinding; - } - - // check for ES2 - n = sscanf(versionString, "OpenGL ES %d.%d", &major, &minor); - if (2 == n) { - return kES2_GrGLBinding; - } - return kNone_GrGLBinding; -} - -GrGLVersion GrGLGetVersionFromString(const char* versionString) { - if (NULL == versionString) { - GrAssert(!"NULL GL version string."); - return 0; - } - - int major, minor; - - int n = sscanf(versionString, "%d.%d", &major, &minor); - if (2 == n) { - return GR_GL_VER(major, minor); - } - - char profile[2]; - n = sscanf(versionString, "OpenGL ES-%c%c %d.%d", profile, profile+1, - &major, &minor); - if (4 == n) { - return GR_GL_VER(major, minor); - } - - n = sscanf(versionString, "OpenGL ES %d.%d", &major, &minor); - if (2 == n) { - return GR_GL_VER(major, minor); - } - - return 0; -} - -GrGLSLVersion GrGLGetGLSLVersionFromString(const char* versionString) { - if (NULL == versionString) { - GrAssert(!"NULL GLSL version string."); - return 0; - } - - int major, minor; - - int n = sscanf(versionString, "%d.%d", &major, &minor); - if (2 == n) { - return GR_GLSL_VER(major, minor); - } - - n = sscanf(versionString, "OpenGL ES GLSL ES %d.%d", &major, &minor); - if (2 == n) { - return GR_GLSL_VER(major, minor); - } - -#ifdef SK_BUILD_FOR_ANDROID - // android hack until the gpu vender updates their drivers - n = sscanf(versionString, "OpenGL ES GLSL %d.%d", &major, &minor); - if (2 == n) { - return GR_GLSL_VER(major, minor); - } -#endif - - return 0; -} - -bool GrGLHasExtensionFromString(const char* ext, const char* extensionString) { - int extLength = strlen(ext); - - while (true) { - int n = strcspn(extensionString, " "); - if (n == extLength && 0 == strncmp(ext, extensionString, n)) { - return true; - } - if (0 == extensionString[n]) { - return false; - } - extensionString += n+1; - } - - return false; -} - -bool GrGLHasExtension(const GrGLInterface* gl, const char* ext) { - const GrGLubyte* glstr; - GR_GL_CALL_RET(gl, glstr, GetString(GR_GL_EXTENSIONS)); - return GrGLHasExtensionFromString(ext, (const char*) glstr); -} - -GrGLBinding GrGLGetBindingInUse(const GrGLInterface* gl) { - const GrGLubyte* v; - GR_GL_CALL_RET(gl, v, GetString(GR_GL_VERSION)); - return GrGLGetBindingInUseFromString((const char*) v); -} - -GrGLVersion GrGLGetVersion(const GrGLInterface* gl) { - const GrGLubyte* v; - GR_GL_CALL_RET(gl, v, GetString(GR_GL_VERSION)); - return GrGLGetVersionFromString((const char*) v); -} - -GrGLSLVersion GrGLGetGLSLVersion(const GrGLInterface* gl) { - const GrGLubyte* v; - GR_GL_CALL_RET(gl, v, GetString(GR_GL_SHADING_LANGUAGE_VERSION)); - return GrGLGetGLSLVersionFromString((const char*) v); -} - GrGLInterface::GrGLInterface() { fBindingsExported = kNone_GrGLBinding; diff --git a/src/gpu/gl/GrGLUtil.cpp b/src/gpu/gl/GrGLUtil.cpp index 23ed5b4c08..c11c8c08f7 100644 --- a/src/gpu/gl/GrGLUtil.cpp +++ b/src/gpu/gl/GrGLUtil.cpp @@ -7,8 +7,7 @@ */ -#include "gl/GrGLConfig.h" -#include "gl/GrGLInterface.h" +#include "GrGLUtil.h" void GrGLClearErr(const GrGLInterface* gl) { while (GR_GL_NO_ERROR != gl->fGetError()) {} @@ -40,3 +39,133 @@ void GrGLCheckErr(const GrGLInterface* gl, bool gCheckErrorGL = !!(GR_GL_CHECK_ERROR_START); #endif +/////////////////////////////////////////////////////////////////////////////// + +GrGLBinding GrGLGetBindingInUseFromString(const char* versionString) { + if (NULL == versionString) { + GrAssert(!"NULL GL version string."); + return kNone_GrGLBinding; + } + + int major, minor; + + // check for desktop + int n = sscanf(versionString, "%d.%d", &major, &minor); + if (2 == n) { + return kDesktop_GrGLBinding; + } + + // check for ES 1 + char profile[2]; + n = sscanf(versionString, "OpenGL ES-%c%c %d.%d", profile, profile+1, + &major, &minor); + if (4 == n) { + // we no longer support ES1. + return kNone_GrGLBinding; + } + + // check for ES2 + n = sscanf(versionString, "OpenGL ES %d.%d", &major, &minor); + if (2 == n) { + return kES2_GrGLBinding; + } + return kNone_GrGLBinding; +} + +GrGLVersion GrGLGetVersionFromString(const char* versionString) { + if (NULL == versionString) { + GrAssert(!"NULL GL version string."); + return 0; + } + + int major, minor; + + int n = sscanf(versionString, "%d.%d", &major, &minor); + if (2 == n) { + return GR_GL_VER(major, minor); + } + + char profile[2]; + n = sscanf(versionString, "OpenGL ES-%c%c %d.%d", profile, profile+1, + &major, &minor); + if (4 == n) { + return GR_GL_VER(major, minor); + } + + n = sscanf(versionString, "OpenGL ES %d.%d", &major, &minor); + if (2 == n) { + return GR_GL_VER(major, minor); + } + + return 0; +} + +GrGLSLVersion GrGLGetGLSLVersionFromString(const char* versionString) { + if (NULL == versionString) { + GrAssert(!"NULL GLSL version string."); + return 0; + } + + int major, minor; + + int n = sscanf(versionString, "%d.%d", &major, &minor); + if (2 == n) { + return GR_GLSL_VER(major, minor); + } + + n = sscanf(versionString, "OpenGL ES GLSL ES %d.%d", &major, &minor); + if (2 == n) { + return GR_GLSL_VER(major, minor); + } + +#ifdef SK_BUILD_FOR_ANDROID + // android hack until the gpu vender updates their drivers + n = sscanf(versionString, "OpenGL ES GLSL %d.%d", &major, &minor); + if (2 == n) { + return GR_GLSL_VER(major, minor); + } +#endif + + return 0; +} + +bool GrGLHasExtensionFromString(const char* ext, const char* extensionString) { + int extLength = strlen(ext); + + while (true) { + int n = strcspn(extensionString, " "); + if (n == extLength && 0 == strncmp(ext, extensionString, n)) { + return true; + } + if (0 == extensionString[n]) { + return false; + } + extensionString += n+1; + } + + return false; +} + +bool GrGLHasExtension(const GrGLInterface* gl, const char* ext) { + const GrGLubyte* glstr; + GR_GL_CALL_RET(gl, glstr, GetString(GR_GL_EXTENSIONS)); + return GrGLHasExtensionFromString(ext, (const char*) glstr); +} + +GrGLBinding GrGLGetBindingInUse(const GrGLInterface* gl) { + const GrGLubyte* v; + GR_GL_CALL_RET(gl, v, GetString(GR_GL_VERSION)); + return GrGLGetBindingInUseFromString((const char*) v); +} + +GrGLVersion GrGLGetVersion(const GrGLInterface* gl) { + const GrGLubyte* v; + GR_GL_CALL_RET(gl, v, GetString(GR_GL_VERSION)); + return GrGLGetVersionFromString((const char*) v); +} + +GrGLSLVersion GrGLGetGLSLVersion(const GrGLInterface* gl) { + const GrGLubyte* v; + GR_GL_CALL_RET(gl, v, GetString(GR_GL_SHADING_LANGUAGE_VERSION)); + return GrGLGetGLSLVersionFromString((const char*) v); +} diff --git a/src/gpu/gl/GrGLUtil.h b/src/gpu/gl/GrGLUtil.h new file mode 100644 index 0000000000..4b89301005 --- /dev/null +++ b/src/gpu/gl/GrGLUtil.h @@ -0,0 +1,81 @@ +/* + * Copyright 2012 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef GrGLUtil_DEFINED +#define GrGLUtil_DEFINED + +#include "gl/GrGLInterface.h" +#include "GrGLDefines.h" + +//////////////////////////////////////////////////////////////////////////////// + +typedef uint32_t GrGLVersion; +typedef uint32_t GrGLSLVersion; + +#define GR_GL_VER(major, minor) ((static_cast(major) << 16) | \ + static_cast(minor)) +#define GR_GLSL_VER(major, minor) ((static_cast(major) << 16) | \ + static_cast(minor)) + +//////////////////////////////////////////////////////////////////////////////// + +/** + * Some drivers want the var-int arg to be zero-initialized on input. + */ +#define GR_GL_INIT_ZERO 0 +#define GR_GL_GetIntegerv(gl, e, p) \ + do { \ + *(p) = GR_GL_INIT_ZERO; \ + GR_GL_CALL(gl, GetIntegerv(e, p)); \ + } while (0) + +#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(gl, t, pname, p) \ + do { \ + *(p) = GR_GL_INIT_ZERO; \ + GR_GL_CALL(gl, GetRenderbufferParameteriv(t, pname, p)); \ + } while (0) +#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) + +//////////////////////////////////////////////////////////////////////////////// + +/** + * Helpers for glGetString() + */ + +// these variants assume caller already has a string from glGetString() +GrGLVersion GrGLGetVersionFromString(const char* versionString); +GrGLBinding GrGLGetBindingInUseFromString(const char* versionString); +GrGLSLVersion GrGLGetGLSLVersionFromString(const char* versionString); +bool GrGLHasExtensionFromString(const char* ext, const char* extensionString); + +// these variants call glGetString() +bool GrGLHasExtension(const GrGLInterface*, const char* ext); +GrGLBinding GrGLGetBindingInUse(const GrGLInterface*); +GrGLVersion GrGLGetVersion(const GrGLInterface*); +GrGLSLVersion GrGLGetGLSLVersion(const GrGLInterface*); + +/** + * Helpers for glGetError() + */ + +extern void GrGLCheckErr(const GrGLInterface* gl, + const char* location, + const char* call); + +extern void GrGLClearErr(const GrGLInterface* gl); + +#endif diff --git a/src/gpu/gl/SkGLContext.cpp b/src/gpu/gl/SkGLContext.cpp index 2d9cd6ac86..3252b566a6 100644 --- a/src/gpu/gl/SkGLContext.cpp +++ b/src/gpu/gl/SkGLContext.cpp @@ -6,6 +6,7 @@ * found in the LICENSE file. */ #include "gl/SkGLContext.h" +#include "gl/GrGLUtil.h" SkGLContext::SkGLContext() : fFBO(0) diff --git a/src/gpu/gl/mac/GrGLCreateNativeInterface_mac.cpp b/src/gpu/gl/mac/GrGLCreateNativeInterface_mac.cpp index 6a56eb5b9a..ecf620026c 100644 --- a/src/gpu/gl/mac/GrGLCreateNativeInterface_mac.cpp +++ b/src/gpu/gl/mac/GrGLCreateNativeInterface_mac.cpp @@ -8,6 +8,7 @@ #include "gl/GrGLInterface.h" +#include "../GrGLUtil.h" #include #include diff --git a/src/gpu/gl/mesa/GrGLCreateMesaInterface.cpp b/src/gpu/gl/mesa/GrGLCreateMesaInterface.cpp index 7fb58958ef..3745bf2155 100644 --- a/src/gpu/gl/mesa/GrGLCreateMesaInterface.cpp +++ b/src/gpu/gl/mesa/GrGLCreateMesaInterface.cpp @@ -8,6 +8,7 @@ #include "gl/GrGLInterface.h" +#include "../GrGLUtil.h" #define GL_GLEXT_PROTOTYPES #include diff --git a/src/gpu/gl/unix/GrGLCreateNativeInterface_unix.cpp b/src/gpu/gl/unix/GrGLCreateNativeInterface_unix.cpp index 0da63b57f7..ddac1593be 100644 --- a/src/gpu/gl/unix/GrGLCreateNativeInterface_unix.cpp +++ b/src/gpu/gl/unix/GrGLCreateNativeInterface_unix.cpp @@ -8,6 +8,7 @@ #include "gl/GrGLInterface.h" +#include "../GrGLUtil.h" #include #include diff --git a/src/gpu/gl/win/GrGLCreateNativeInterface_win.cpp b/src/gpu/gl/win/GrGLCreateNativeInterface_win.cpp index 5b2d10b99d..d16cb1dc6a 100644 --- a/src/gpu/gl/win/GrGLCreateNativeInterface_win.cpp +++ b/src/gpu/gl/win/GrGLCreateNativeInterface_win.cpp @@ -8,6 +8,7 @@ #include "gl/GrGLInterface.h" +#include "../GrGLUtil.h" #define WIN32_LEAN_AND_MEAN #include #include