Move function decls and macros out of public headers that are meant for internal use.

git-svn-id: http://skia.googlecode.com/svn/trunk@3849 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
bsalomon@google.com 2012-05-07 17:09:37 +00:00
parent aa99c9e85f
commit 9c1f1ac5d3
16 changed files with 227 additions and 194 deletions

View File

@ -7,6 +7,7 @@
*/
#include "BenchGpuTimer_gl.h"
#include "gl/SkGLContext.h"
#include "gl/GrGLUtil.h"
BenchGpuTimer::BenchGpuTimer(const SkGLContext* glctx) {
fContext = glctx;

View File

@ -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',

View File

@ -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',

View File

@ -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

View File

@ -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<int>(major) << 16) | \
static_cast<int>(minor))
#define GR_GLSL_VER(major, minor) ((static_cast<int>(major) << 16) | \
static_cast<int>(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 <typename FNPTR_TYPE> class GLPtr {
public:
GLPtr() : fPtr(NULL) {}

View File

@ -23,6 +23,7 @@
#include "SkTypeface.h"
#include "gl/GrGLInterface.h"
#include "gl/GrGLUtil.h"
#include "GrRenderTarget.h"
#include "SkPDFDevice.h"

View File

@ -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"

View File

@ -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

View File

@ -7,9 +7,8 @@
*/
#include "GrTypes.h"
#include "gl/GrGLInterface.h"
#include "gl/GrGLDefines.h"
#include "GrGLUtil.h"
#include <stdio.h>
@ -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;

View File

@ -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);
}

81
src/gpu/gl/GrGLUtil.h Normal file
View File

@ -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<int>(major) << 16) | \
static_cast<int>(minor))
#define GR_GLSL_VER(major, minor) ((static_cast<int>(major) << 16) | \
static_cast<int>(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

View File

@ -6,6 +6,7 @@
* found in the LICENSE file.
*/
#include "gl/SkGLContext.h"
#include "gl/GrGLUtil.h"
SkGLContext::SkGLContext()
: fFBO(0)

View File

@ -8,6 +8,7 @@
#include "gl/GrGLInterface.h"
#include "../GrGLUtil.h"
#include <OpenGL/gl.h>
#include <OpenGL/glext.h>

View File

@ -8,6 +8,7 @@
#include "gl/GrGLInterface.h"
#include "../GrGLUtil.h"
#define GL_GLEXT_PROTOTYPES
#include <GL/osmesa.h>

View File

@ -8,6 +8,7 @@
#include "gl/GrGLInterface.h"
#include "../GrGLUtil.h"
#include <GL/glx.h>
#include <GL/gl.h>

View File

@ -8,6 +8,7 @@
#include "gl/GrGLInterface.h"
#include "../GrGLUtil.h"
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <GL/GL.h>