Make GrGLInterface be context-specific on all platforms

BUG=skia:2042
R=robertphillips@google.com

Author: bsalomon@google.com

Review URL: https://codereview.chromium.org/137753005

git-svn-id: http://skia.googlecode.com/svn/trunk@13097 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
commit-bot@chromium.org 2014-01-15 19:32:03 +00:00
parent 5fdaffdbcb
commit a3b15ed037
7 changed files with 425 additions and 450 deletions

View File

@ -37,17 +37,12 @@ static const GrGLBinding kES2_GrGLBinding = kES_GrGLBinding;
* 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
* passed to Create then a "default" GL interface is created. If the default is
* also NULL GrContext creation will fail.
*
* The default interface is returned by GrGLDefaultInterface. This function's
* implementation is platform-specific. Several have been provided, along with
* an implementation that simply returns NULL. It is implementation-specific
* whether the same GrGLInterface is returned or whether a new one is created
* at each call. Some platforms may not be able to use a single GrGLInterface
* because extension function ptrs vary across contexts. Note that GrGLInterface
* is ref-counted. So if the same object is returned by multiple calls to
* GrGLDefaultInterface, each should bump the ref count.
* an implementation that simply returns NULL.
*
* By defining GR_GL_PER_GL_CALL_IFACE_CALLBACK to 1 the client can specify a
* callback function that will be called prior to each GL function call. See
@ -60,9 +55,8 @@ const GrGLInterface* GrGLDefaultInterface();
/**
* Creates a GrGLInterface for a "native" GL context (e.g. WGL on windows,
* GLX on linux, AGL on Mac). On platforms that have context-specific function
* pointers for GL extensions (e.g. windows) the returned interface is only
* valid for the context that was current at creation.
* GLX on linux, AGL on Mac). The interface is only valid for the GL context
* that is current when the interface is created.
*/
const GrGLInterface* GrGLCreateNativeInterface();

View File

@ -22,7 +22,6 @@
const GrGLInterface* GrGLCreateANGLEInterface() {
static SkAutoTUnref<GrGLInterface> glInterface;
static HMODULE ghANGLELib = NULL;
if (NULL == ghANGLELib) {
@ -34,126 +33,122 @@ const GrGLInterface* GrGLCreateANGLEInterface() {
return NULL;
}
if (!glInterface.get()) {
GrGLInterface* interface = new GrGLInterface;
glInterface.reset(interface);
interface->fBindingsExported = kES_GrGLBinding;
GrGLInterface* interface = SkNEW(GrGLInterface);
interface->fBindingsExported = kES_GrGLBinding;
GET_PROC(ActiveTexture);
GET_PROC(AttachShader);
GET_PROC(BindAttribLocation);
GET_PROC(BindBuffer);
GET_PROC(BindTexture);
interface->fBindVertexArray =
(GrGLBindVertexArrayProc) eglGetProcAddress("glBindVertexArrayOES");
GET_PROC(BlendColor);
GET_PROC(BlendFunc);
GET_PROC(BufferData);
GET_PROC(BufferSubData);
GET_PROC(Clear);
GET_PROC(ClearColor);
GET_PROC(ClearStencil);
GET_PROC(ColorMask);
GET_PROC(CompileShader);
GET_PROC(CompressedTexImage2D);
GET_PROC(CopyTexSubImage2D);
GET_PROC(CreateProgram);
GET_PROC(CreateShader);
GET_PROC(CullFace);
GET_PROC(DeleteBuffers);
GET_PROC(DeleteProgram);
GET_PROC(DeleteShader);
GET_PROC(DeleteTextures);
interface->fDeleteVertexArrays =
(GrGLDeleteVertexArraysProc) eglGetProcAddress("glDeleteVertexArraysOES");
GET_PROC(DepthMask);
GET_PROC(Disable);
GET_PROC(DisableVertexAttribArray);
GET_PROC(DrawArrays);
GET_PROC(DrawElements);
GET_PROC(Enable);
GET_PROC(EnableVertexAttribArray);
GET_PROC(Finish);
GET_PROC(Flush);
GET_PROC(FrontFace);
GET_PROC(GenBuffers);
GET_PROC(GenerateMipmap);
GET_PROC(GenTextures);
interface->fGenVertexArrays =
(GrGLGenVertexArraysProc) eglGetProcAddress("glGenVertexArraysOES");
GET_PROC(GetBufferParameteriv);
GET_PROC(GetError);
GET_PROC(GetIntegerv);
GET_PROC(GetProgramInfoLog);
GET_PROC(GetProgramiv);
GET_PROC(GetShaderInfoLog);
GET_PROC(GetShaderiv);
GET_PROC(GetString);
GET_PROC(GetUniformLocation);
GET_PROC(LineWidth);
GET_PROC(LinkProgram);
GET_PROC(PixelStorei);
GET_PROC(ReadPixels);
GET_PROC(Scissor);
GET_PROC(ShaderSource);
GET_PROC(StencilFunc);
GET_PROC(StencilFuncSeparate);
GET_PROC(StencilMask);
GET_PROC(StencilMaskSeparate);
GET_PROC(StencilOp);
GET_PROC(StencilOpSeparate);
GET_PROC(TexImage2D);
GET_PROC(TexParameteri);
GET_PROC(TexParameteriv);
GET_PROC(TexSubImage2D);
GET_PROC(ActiveTexture);
GET_PROC(AttachShader);
GET_PROC(BindAttribLocation);
GET_PROC(BindBuffer);
GET_PROC(BindTexture);
interface->fBindVertexArray =
(GrGLBindVertexArrayProc) eglGetProcAddress("glBindVertexArrayOES");
GET_PROC(BlendColor);
GET_PROC(BlendFunc);
GET_PROC(BufferData);
GET_PROC(BufferSubData);
GET_PROC(Clear);
GET_PROC(ClearColor);
GET_PROC(ClearStencil);
GET_PROC(ColorMask);
GET_PROC(CompileShader);
GET_PROC(CompressedTexImage2D);
GET_PROC(CopyTexSubImage2D);
GET_PROC(CreateProgram);
GET_PROC(CreateShader);
GET_PROC(CullFace);
GET_PROC(DeleteBuffers);
GET_PROC(DeleteProgram);
GET_PROC(DeleteShader);
GET_PROC(DeleteTextures);
interface->fDeleteVertexArrays =
(GrGLDeleteVertexArraysProc) eglGetProcAddress("glDeleteVertexArraysOES");
GET_PROC(DepthMask);
GET_PROC(Disable);
GET_PROC(DisableVertexAttribArray);
GET_PROC(DrawArrays);
GET_PROC(DrawElements);
GET_PROC(Enable);
GET_PROC(EnableVertexAttribArray);
GET_PROC(Finish);
GET_PROC(Flush);
GET_PROC(FrontFace);
GET_PROC(GenBuffers);
GET_PROC(GenerateMipmap);
GET_PROC(GenTextures);
interface->fGenVertexArrays =
(GrGLGenVertexArraysProc) eglGetProcAddress("glGenVertexArraysOES");
GET_PROC(GetBufferParameteriv);
GET_PROC(GetError);
GET_PROC(GetIntegerv);
GET_PROC(GetProgramInfoLog);
GET_PROC(GetProgramiv);
GET_PROC(GetShaderInfoLog);
GET_PROC(GetShaderiv);
GET_PROC(GetString);
GET_PROC(GetUniformLocation);
GET_PROC(LineWidth);
GET_PROC(LinkProgram);
GET_PROC(PixelStorei);
GET_PROC(ReadPixels);
GET_PROC(Scissor);
GET_PROC(ShaderSource);
GET_PROC(StencilFunc);
GET_PROC(StencilFuncSeparate);
GET_PROC(StencilMask);
GET_PROC(StencilMaskSeparate);
GET_PROC(StencilOp);
GET_PROC(StencilOpSeparate);
GET_PROC(TexImage2D);
GET_PROC(TexParameteri);
GET_PROC(TexParameteriv);
GET_PROC(TexSubImage2D);
#if GL_ARB_texture_storage
GET_PROC(TexStorage2D);
GET_PROC(TexStorage2D);
#elif GL_EXT_texture_storage
interface->fTexStorage2D = (GrGLTexStorage2DProc) eglGetProcAddress("glTexStorage2DEXT");
interface->fTexStorage2D = (GrGLTexStorage2DProc) eglGetProcAddress("glTexStorage2DEXT");
#endif
GET_PROC(Uniform1f);
GET_PROC(Uniform1i);
GET_PROC(Uniform1fv);
GET_PROC(Uniform1iv);
GET_PROC(Uniform1f);
GET_PROC(Uniform1i);
GET_PROC(Uniform1fv);
GET_PROC(Uniform1iv);
GET_PROC(Uniform2f);
GET_PROC(Uniform2i);
GET_PROC(Uniform2fv);
GET_PROC(Uniform2iv);
GET_PROC(Uniform2f);
GET_PROC(Uniform2i);
GET_PROC(Uniform2fv);
GET_PROC(Uniform2iv);
GET_PROC(Uniform3f);
GET_PROC(Uniform3i);
GET_PROC(Uniform3fv);
GET_PROC(Uniform3iv);
GET_PROC(Uniform3f);
GET_PROC(Uniform3i);
GET_PROC(Uniform3fv);
GET_PROC(Uniform3iv);
GET_PROC(Uniform4f);
GET_PROC(Uniform4i);
GET_PROC(Uniform4fv);
GET_PROC(Uniform4iv);
GET_PROC(Uniform4f);
GET_PROC(Uniform4i);
GET_PROC(Uniform4fv);
GET_PROC(Uniform4iv);
GET_PROC(UniformMatrix2fv);
GET_PROC(UniformMatrix3fv);
GET_PROC(UniformMatrix4fv);
GET_PROC(UseProgram);
GET_PROC(VertexAttrib4fv);
GET_PROC(VertexAttribPointer);
GET_PROC(Viewport);
GET_PROC(BindFramebuffer);
GET_PROC(BindRenderbuffer);
GET_PROC(CheckFramebufferStatus);
GET_PROC(DeleteFramebuffers);
GET_PROC(DeleteRenderbuffers);
GET_PROC(FramebufferRenderbuffer);
GET_PROC(FramebufferTexture2D);
GET_PROC(GenFramebuffers);
GET_PROC(GenRenderbuffers);
GET_PROC(GetFramebufferAttachmentParameteriv);
GET_PROC(GetRenderbufferParameteriv);
GET_PROC(RenderbufferStorage);
GET_PROC(UniformMatrix2fv);
GET_PROC(UniformMatrix3fv);
GET_PROC(UniformMatrix4fv);
GET_PROC(UseProgram);
GET_PROC(VertexAttrib4fv);
GET_PROC(VertexAttribPointer);
GET_PROC(Viewport);
GET_PROC(BindFramebuffer);
GET_PROC(BindRenderbuffer);
GET_PROC(CheckFramebufferStatus);
GET_PROC(DeleteFramebuffers);
GET_PROC(DeleteRenderbuffers);
GET_PROC(FramebufferRenderbuffer);
GET_PROC(FramebufferTexture2D);
GET_PROC(GenFramebuffers);
GET_PROC(GenRenderbuffers);
GET_PROC(GetFramebufferAttachmentParameteriv);
GET_PROC(GetRenderbufferParameteriv);
GET_PROC(RenderbufferStorage);
interface->fMapBuffer = (GrGLMapBufferProc) eglGetProcAddress("glMapBufferOES");
interface->fUnmapBuffer = (GrGLUnmapBufferProc) eglGetProcAddress("glUnmapBufferOES");
}
glInterface.get()->ref();
return glInterface.get();
interface->fMapBuffer = (GrGLMapBufferProc) eglGetProcAddress("glMapBufferOES");
interface->fUnmapBuffer = (GrGLUnmapBufferProc) eglGetProcAddress("glUnmapBufferOES");
return interface;
}

View File

@ -13,140 +13,136 @@
#import <OpenGLES/ES2/glext.h>
const GrGLInterface* GrGLCreateNativeInterface() {
static SkAutoTUnref<GrGLInterface> glInterface;
if (!glInterface.get()) {
GrGLInterface* interface = SkNEW(GrGLInterface);
glInterface.reset(interface);
GrGLInterface* interface = SkNEW(GrGLInterface);
interface->fActiveTexture = glActiveTexture;
interface->fAttachShader = glAttachShader;
interface->fBindAttribLocation = glBindAttribLocation;
interface->fBindBuffer = glBindBuffer;
interface->fBindTexture = glBindTexture;
interface->fBlendColor = glBlendColor;
interface->fBlendFunc = glBlendFunc;
interface->fBufferData = (GrGLBufferDataProc)glBufferData;
interface->fBufferSubData = (GrGLBufferSubDataProc)glBufferSubData;
interface->fClear = glClear;
interface->fClearColor = glClearColor;
interface->fClearStencil = glClearStencil;
interface->fColorMask = glColorMask;
interface->fCompileShader = glCompileShader;
interface->fCompressedTexImage2D = glCompressedTexImage2D;
interface->fCopyTexSubImage2D = glCopyTexSubImage2D;
interface->fCreateProgram = glCreateProgram;
interface->fCreateShader = glCreateShader;
interface->fCullFace = glCullFace;
interface->fDeleteBuffers = glDeleteBuffers;
interface->fDeleteProgram = glDeleteProgram;
interface->fDeleteShader = glDeleteShader;
interface->fDeleteTextures = glDeleteTextures;
interface->fDepthMask = glDepthMask;
interface->fDisable = glDisable;
interface->fDisableVertexAttribArray = glDisableVertexAttribArray;
interface->fDrawArrays = glDrawArrays;
interface->fDrawBuffer = NULL;
interface->fDrawBuffers = NULL;
interface->fDrawElements = glDrawElements;
interface->fEnable = glEnable;
interface->fEnableVertexAttribArray = glEnableVertexAttribArray;
interface->fFinish = glFinish;
interface->fFlush = glFlush;
interface->fFrontFace = glFrontFace;
interface->fGenBuffers = glGenBuffers;
interface->fGenerateMipmap = glGenerateMipmap;
interface->fGetBufferParameteriv = glGetBufferParameteriv;
interface->fGetError = glGetError;
interface->fGetIntegerv = glGetIntegerv;
interface->fGetProgramInfoLog = glGetProgramInfoLog;
interface->fGetProgramiv = glGetProgramiv;
interface->fGetShaderInfoLog = glGetShaderInfoLog;
interface->fGetShaderiv = glGetShaderiv;
interface->fGetString = glGetString;
interface->fGenTextures = glGenTextures;
interface->fGetUniformLocation = glGetUniformLocation;
interface->fLineWidth = glLineWidth;
interface->fLinkProgram = glLinkProgram;
interface->fPixelStorei = glPixelStorei;
interface->fReadBuffer = NULL;
interface->fReadPixels = glReadPixels;
interface->fScissor = glScissor;
interface->fShaderSource = glShaderSource;
interface->fStencilFunc = glStencilFunc;
interface->fStencilFuncSeparate = glStencilFuncSeparate;
interface->fStencilMask = glStencilMask;
interface->fStencilMaskSeparate = glStencilMaskSeparate;
interface->fStencilOp = glStencilOp;
interface->fStencilOpSeparate = glStencilOpSeparate;
// mac uses GLenum for internalFormat param (non-standard)
// amounts to int vs. uint.
interface->fTexImage2D = (GrGLTexImage2DProc)glTexImage2D;
interface->fActiveTexture = glActiveTexture;
interface->fAttachShader = glAttachShader;
interface->fBindAttribLocation = glBindAttribLocation;
interface->fBindBuffer = glBindBuffer;
interface->fBindTexture = glBindTexture;
interface->fBlendColor = glBlendColor;
interface->fBlendFunc = glBlendFunc;
interface->fBufferData = (GrGLBufferDataProc)glBufferData;
interface->fBufferSubData = (GrGLBufferSubDataProc)glBufferSubData;
interface->fClear = glClear;
interface->fClearColor = glClearColor;
interface->fClearStencil = glClearStencil;
interface->fColorMask = glColorMask;
interface->fCompileShader = glCompileShader;
interface->fCompressedTexImage2D = glCompressedTexImage2D;
interface->fCopyTexSubImage2D = glCopyTexSubImage2D;
interface->fCreateProgram = glCreateProgram;
interface->fCreateShader = glCreateShader;
interface->fCullFace = glCullFace;
interface->fDeleteBuffers = glDeleteBuffers;
interface->fDeleteProgram = glDeleteProgram;
interface->fDeleteShader = glDeleteShader;
interface->fDeleteTextures = glDeleteTextures;
interface->fDepthMask = glDepthMask;
interface->fDisable = glDisable;
interface->fDisableVertexAttribArray = glDisableVertexAttribArray;
interface->fDrawArrays = glDrawArrays;
interface->fDrawBuffer = NULL;
interface->fDrawBuffers = NULL;
interface->fDrawElements = glDrawElements;
interface->fEnable = glEnable;
interface->fEnableVertexAttribArray = glEnableVertexAttribArray;
interface->fFinish = glFinish;
interface->fFlush = glFlush;
interface->fFrontFace = glFrontFace;
interface->fGenBuffers = glGenBuffers;
interface->fGenerateMipmap = glGenerateMipmap;
interface->fGetBufferParameteriv = glGetBufferParameteriv;
interface->fGetError = glGetError;
interface->fGetIntegerv = glGetIntegerv;
interface->fGetProgramInfoLog = glGetProgramInfoLog;
interface->fGetProgramiv = glGetProgramiv;
interface->fGetShaderInfoLog = glGetShaderInfoLog;
interface->fGetShaderiv = glGetShaderiv;
interface->fGetString = glGetString;
interface->fGenTextures = glGenTextures;
interface->fGetUniformLocation = glGetUniformLocation;
interface->fLineWidth = glLineWidth;
interface->fLinkProgram = glLinkProgram;
interface->fPixelStorei = glPixelStorei;
interface->fReadBuffer = NULL;
interface->fReadPixels = glReadPixels;
interface->fScissor = glScissor;
interface->fShaderSource = glShaderSource;
interface->fStencilFunc = glStencilFunc;
interface->fStencilFuncSeparate = glStencilFuncSeparate;
interface->fStencilMask = glStencilMask;
interface->fStencilMaskSeparate = glStencilMaskSeparate;
interface->fStencilOp = glStencilOp;
interface->fStencilOpSeparate = glStencilOpSeparate;
// mac uses GLenum for internalFormat param (non-standard)
// amounts to int vs. uint.
interface->fTexImage2D = (GrGLTexImage2DProc)glTexImage2D;
#if GL_ARB_texture_storage
interface->fTexStorage2D = glTexStorage2D;
interface->fTexStorage2D = glTexStorage2D;
#elif GL_EXT_texture_storage
interface->fTexStorage2D = glTexStorage2DEXT;
interface->fTexStorage2D = glTexStorage2DEXT;
#endif
#if GL_EXT_discard_framebuffer
interface->fDiscardFramebuffer = glDiscardFramebufferEXT;
interface->fDiscardFramebuffer = glDiscardFramebufferEXT;
#endif
interface->fTexParameteri = glTexParameteri;
interface->fTexParameteriv = glTexParameteriv;
interface->fTexSubImage2D = glTexSubImage2D;
interface->fUniform1f = glUniform1f;
interface->fUniform1i = glUniform1i;
interface->fUniform1fv = glUniform1fv;
interface->fUniform1iv = glUniform1iv;
interface->fUniform2f = glUniform2f;
interface->fUniform2i = glUniform2i;
interface->fUniform2fv = glUniform2fv;
interface->fUniform2iv = glUniform2iv;
interface->fUniform3f = glUniform3f;
interface->fUniform3i = glUniform3i;
interface->fUniform3fv = glUniform3fv;
interface->fUniform3iv = glUniform3iv;
interface->fUniform4f = glUniform4f;
interface->fUniform4i = glUniform4i;
interface->fUniform4fv = glUniform4fv;
interface->fUniform4iv = glUniform4iv;
interface->fUniform4fv = glUniform4fv;
interface->fUniformMatrix2fv = glUniformMatrix2fv;
interface->fUniformMatrix3fv = glUniformMatrix3fv;
interface->fUniformMatrix4fv = glUniformMatrix4fv;
interface->fUseProgram = glUseProgram;
interface->fVertexAttrib4fv = glVertexAttrib4fv;
interface->fVertexAttribPointer = glVertexAttribPointer;
interface->fViewport = glViewport;
interface->fGenFramebuffers = glGenFramebuffers;
interface->fGetFramebufferAttachmentParameteriv = glGetFramebufferAttachmentParameteriv;
interface->fGetRenderbufferParameteriv = glGetRenderbufferParameteriv;
interface->fBindFramebuffer = glBindFramebuffer;
interface->fFramebufferTexture2D = glFramebufferTexture2D;
interface->fCheckFramebufferStatus = glCheckFramebufferStatus;
interface->fDeleteFramebuffers = glDeleteFramebuffers;
interface->fRenderbufferStorage = glRenderbufferStorage;
interface->fGenRenderbuffers = glGenRenderbuffers;
interface->fDeleteRenderbuffers = glDeleteRenderbuffers;
interface->fFramebufferRenderbuffer = glFramebufferRenderbuffer;
interface->fBindRenderbuffer = glBindRenderbuffer;
interface->fTexParameteri = glTexParameteri;
interface->fTexParameteriv = glTexParameteriv;
interface->fTexSubImage2D = glTexSubImage2D;
interface->fUniform1f = glUniform1f;
interface->fUniform1i = glUniform1i;
interface->fUniform1fv = glUniform1fv;
interface->fUniform1iv = glUniform1iv;
interface->fUniform2f = glUniform2f;
interface->fUniform2i = glUniform2i;
interface->fUniform2fv = glUniform2fv;
interface->fUniform2iv = glUniform2iv;
interface->fUniform3f = glUniform3f;
interface->fUniform3i = glUniform3i;
interface->fUniform3fv = glUniform3fv;
interface->fUniform3iv = glUniform3iv;
interface->fUniform4f = glUniform4f;
interface->fUniform4i = glUniform4i;
interface->fUniform4fv = glUniform4fv;
interface->fUniform4iv = glUniform4iv;
interface->fUniform4fv = glUniform4fv;
interface->fUniformMatrix2fv = glUniformMatrix2fv;
interface->fUniformMatrix3fv = glUniformMatrix3fv;
interface->fUniformMatrix4fv = glUniformMatrix4fv;
interface->fUseProgram = glUseProgram;
interface->fVertexAttrib4fv = glVertexAttrib4fv;
interface->fVertexAttribPointer = glVertexAttribPointer;
interface->fViewport = glViewport;
interface->fGenFramebuffers = glGenFramebuffers;
interface->fGetFramebufferAttachmentParameteriv = glGetFramebufferAttachmentParameteriv;
interface->fGetRenderbufferParameteriv = glGetRenderbufferParameteriv;
interface->fBindFramebuffer = glBindFramebuffer;
interface->fFramebufferTexture2D = glFramebufferTexture2D;
interface->fCheckFramebufferStatus = glCheckFramebufferStatus;
interface->fDeleteFramebuffers = glDeleteFramebuffers;
interface->fRenderbufferStorage = glRenderbufferStorage;
interface->fGenRenderbuffers = glGenRenderbuffers;
interface->fDeleteRenderbuffers = glDeleteRenderbuffers;
interface->fFramebufferRenderbuffer = glFramebufferRenderbuffer;
interface->fBindRenderbuffer = glBindRenderbuffer;
#if GL_OES_mapbuffer
interface->fMapBuffer = glMapBufferOES;
interface->fUnmapBuffer = glUnmapBufferOES;
interface->fMapBuffer = glMapBufferOES;
interface->fUnmapBuffer = glUnmapBufferOES;
#endif
#if GL_APPLE_framebuffer_multisample
interface->fRenderbufferStorageMultisample = glRenderbufferStorageMultisampleAPPLE;
interface->fResolveMultisampleFramebuffer = glResolveMultisampleFramebufferAPPLE;
interface->fRenderbufferStorageMultisample = glRenderbufferStorageMultisampleAPPLE;
interface->fResolveMultisampleFramebuffer = glResolveMultisampleFramebufferAPPLE;
#endif
#if GL_OES_vertex_array_object
interface->fBindVertexArray = glBindVertexArrayOES;
interface->fDeleteVertexArrays = glDeleteVertexArraysOES;
interface->fGenVertexArrays = glGenVertexArraysOES;
interface->fBindVertexArray = glBindVertexArrayOES;
interface->fDeleteVertexArrays = glDeleteVertexArraysOES;
interface->fGenVertexArrays = glGenVertexArraysOES;
#endif
interface->fBindingsExported = kES_GrGLBinding;
}
glInterface.get()->ref();
return glInterface.get();
interface->fBindingsExported = kES_GrGLBinding;
return interface;
}

View File

@ -43,209 +43,203 @@ static void* GetProcAddress(const char* name) {
#define GET_PROC_SUFFIX(name, suffix) (interface->f ## name = ((GrGL ## name ## Proc) GetProcAddress("gl" #name #suffix)))
const GrGLInterface* GrGLCreateNativeInterface() {
// The gl functions are not context-specific so we create one global interface
static SkAutoTUnref<GrGLInterface> glInterface;
if (!glInterface.get()) {
GrGLInterface* interface = new GrGLInterface;
GrGLGetStringProc glGetString = (GrGLGetStringProc) GetProcAddress("glGetString");
GrGLGetStringiProc glGetStringi = (GrGLGetStringiProc) GetProcAddress("glGetStringi");
GrGLGetIntegervProc glGetIntegerv = (GrGLGetIntegervProc) GetProcAddress("glGetIntegerv");
GrGLGetStringProc glGetString = (GrGLGetStringProc) GetProcAddress("glGetString");
GrGLGetStringiProc glGetStringi = (GrGLGetStringiProc) GetProcAddress("glGetStringi");
GrGLGetIntegervProc glGetIntegerv = (GrGLGetIntegervProc) GetProcAddress("glGetIntegerv");
glInterface.reset(interface);
const char* verStr = (const char*) glGetString(GR_GL_VERSION);
GrGLVersion ver = GrGLGetVersionFromString(verStr);
GrGLExtensions extensions;
if (!extensions.init(kDesktop_GrGLBinding, glGetString, glGetStringi, glGetIntegerv)) {
glInterface.reset(NULL);
return NULL;
const char* verStr = (const char*) glGetString(GR_GL_VERSION);
GrGLVersion ver = GrGLGetVersionFromString(verStr);
GrGLExtensions extensions;
if (!extensions.init(kDesktop_GrGLBinding, glGetString, glGetStringi, glGetIntegerv)) {
return NULL;
}
GrGLInterface* interface = SkNEW(GrGLInterface);
interface->fBindingsExported = kDesktop_GrGLBinding;
GET_PROC(ActiveTexture);
GET_PROC(AttachShader);
GET_PROC(BeginQuery);
GET_PROC(BindAttribLocation);
GET_PROC(BindBuffer);
if (ver >= GR_GL_VER(3,0)) {
GET_PROC(BindFragDataLocation);
}
GET_PROC(BindTexture);
GET_PROC(BlendFunc);
if (ver >= GR_GL_VER(1,4) ||
extensions.has("GL_ARB_imaging") ||
extensions.has("GL_EXT_blend_color")) {
GET_PROC(BlendColor);
}
GET_PROC(BufferData);
GET_PROC(BufferSubData);
GET_PROC(Clear);
GET_PROC(ClearColor);
GET_PROC(ClearStencil);
GET_PROC(ClientActiveTexture);
GET_PROC(ColorMask);
GET_PROC(CompileShader);
GET_PROC(CompressedTexImage2D);
GET_PROC(CopyTexSubImage2D);
GET_PROC(CreateProgram);
GET_PROC(CreateShader);
GET_PROC(CullFace);
GET_PROC(DeleteBuffers);
GET_PROC(DeleteProgram);
GET_PROC(DeleteQueries);
GET_PROC(DeleteShader);
GET_PROC(DeleteTextures);
GET_PROC(DepthMask);
GET_PROC(Disable);
GET_PROC(DisableClientState);
GET_PROC(DisableVertexAttribArray);
GET_PROC(DrawArrays);
GET_PROC(DrawBuffer);
GET_PROC(DrawBuffers);
GET_PROC(DrawElements);
GET_PROC(Enable);
GET_PROC(EnableClientState);
GET_PROC(EnableVertexAttribArray);
GET_PROC(EndQuery);
GET_PROC(Finish);
GET_PROC(Flush);
GET_PROC(FrontFace);
GET_PROC(GenBuffers);
GET_PROC(GenerateMipmap);
GET_PROC(GenQueries);
GET_PROC(GetBufferParameteriv);
GET_PROC(GetError);
GET_PROC(GetIntegerv);
GET_PROC(GetProgramInfoLog);
GET_PROC(GetProgramiv);
GET_PROC(GetQueryiv);
GET_PROC(GetQueryObjectiv);
GET_PROC(GetQueryObjectuiv);
GET_PROC(GetShaderInfoLog);
GET_PROC(GetShaderiv);
GET_PROC(GetString);
GET_PROC(GetStringi);
GET_PROC(GetTexLevelParameteriv);
GET_PROC(GenTextures);
GET_PROC(GetUniformLocation);
GET_PROC(LineWidth);
GET_PROC(LinkProgram);
GET_PROC(LoadIdentity);
GET_PROC(LoadMatrixf);
GET_PROC(MapBuffer);
GET_PROC(MatrixMode);
GET_PROC(PixelStorei);
GET_PROC(ReadBuffer);
GET_PROC(ReadPixels);
GET_PROC(Scissor);
GET_PROC(ShaderSource);
GET_PROC(StencilFunc);
GET_PROC(StencilFuncSeparate);
GET_PROC(StencilMask);
GET_PROC(StencilMaskSeparate);
GET_PROC(StencilOp);
GET_PROC(StencilOpSeparate);
GET_PROC(TexGenf);
GET_PROC(TexGenfv);
GET_PROC(TexGeni);
GET_PROC(TexImage2D);
GET_PROC(TexParameteri);
GET_PROC(TexParameteriv);
if (ver >= GR_GL_VER(4,2) || extensions.has("GL_ARB_texture_storage")) {
GET_PROC(TexStorage2D);
} else if (extensions.has("GL_EXT_texture_storage")) {
GET_PROC_SUFFIX(TexStorage2D, EXT);
}
GET_PROC(TexSubImage2D);
GET_PROC(Uniform1f);
GET_PROC(Uniform1i);
GET_PROC(Uniform1fv);
GET_PROC(Uniform1iv);
GET_PROC(Uniform2f);
GET_PROC(Uniform2i);
GET_PROC(Uniform2fv);
GET_PROC(Uniform2iv);
GET_PROC(Uniform3f);
GET_PROC(Uniform3i);
GET_PROC(Uniform3fv);
GET_PROC(Uniform3iv);
GET_PROC(Uniform4f);
GET_PROC(Uniform4i);
GET_PROC(Uniform4fv);
GET_PROC(Uniform4iv);
GET_PROC(Uniform4fv);
GET_PROC(UniformMatrix2fv);
GET_PROC(UniformMatrix3fv);
GET_PROC(UniformMatrix4fv);
GET_PROC(UnmapBuffer);
GET_PROC(UseProgram);
GET_PROC(VertexAttrib4fv);
GET_PROC(VertexAttribPointer);
GET_PROC(VertexPointer);
GET_PROC(Viewport);
if (ver >= GR_GL_VER(3,0) || extensions.has("GL_ARB_vertex_array_object")) {
// no ARB suffix for GL_ARB_vertex_array_object
GET_PROC(BindVertexArray);
GET_PROC(DeleteVertexArrays);
GET_PROC(GenVertexArrays);
}
if (ver >= GR_GL_VER(3,3) || extensions.has("GL_ARB_timer_query")) {
// ARB extension doesn't use the ARB suffix on the function name
GET_PROC(QueryCounter);
GET_PROC(GetQueryObjecti64v);
GET_PROC(GetQueryObjectui64v);
} else if (extensions.has("GL_EXT_timer_query")) {
GET_PROC_SUFFIX(GetQueryObjecti64v, EXT);
GET_PROC_SUFFIX(GetQueryObjectui64v, EXT);
}
if (ver >= GR_GL_VER(3,0) || extensions.has("GL_ARB_framebuffer_object")) {
// ARB extension doesn't use the ARB suffix on the function names
GET_PROC(GenFramebuffers);
GET_PROC(GetFramebufferAttachmentParameteriv);
GET_PROC(GetRenderbufferParameteriv);
GET_PROC(BindFramebuffer);
GET_PROC(FramebufferTexture2D);
GET_PROC(CheckFramebufferStatus);
GET_PROC(DeleteFramebuffers);
GET_PROC(RenderbufferStorage);
GET_PROC(GenRenderbuffers);
GET_PROC(DeleteRenderbuffers);
GET_PROC(FramebufferRenderbuffer);
GET_PROC(BindRenderbuffer);
GET_PROC(RenderbufferStorageMultisample);
GET_PROC(BlitFramebuffer);
} else {
if (extensions.has("GL_EXT_framebuffer_object")) {
GET_PROC_SUFFIX(GenFramebuffers, EXT);
GET_PROC_SUFFIX(GetFramebufferAttachmentParameteriv, EXT);
GET_PROC_SUFFIX(GetRenderbufferParameteriv, EXT);
GET_PROC_SUFFIX(BindFramebuffer, EXT);
GET_PROC_SUFFIX(FramebufferTexture2D, EXT);
GET_PROC_SUFFIX(CheckFramebufferStatus, EXT);
GET_PROC_SUFFIX(DeleteFramebuffers, EXT);
GET_PROC_SUFFIX(RenderbufferStorage, EXT);
GET_PROC_SUFFIX(GenRenderbuffers, EXT);
GET_PROC_SUFFIX(DeleteRenderbuffers, EXT);
GET_PROC_SUFFIX(FramebufferRenderbuffer, EXT);
GET_PROC_SUFFIX(BindRenderbuffer, EXT);
}
interface->fBindingsExported = kDesktop_GrGLBinding;
GET_PROC(ActiveTexture);
GET_PROC(AttachShader);
GET_PROC(BeginQuery);
GET_PROC(BindAttribLocation);
GET_PROC(BindBuffer);
if (ver >= GR_GL_VER(3,0)) {
GET_PROC(BindFragDataLocation);
if (extensions.has("GL_EXT_framebuffer_multisample")) {
GET_PROC_SUFFIX(RenderbufferStorageMultisample, EXT);
}
GET_PROC(BindTexture);
GET_PROC(BlendFunc);
if (ver >= GR_GL_VER(1,4) ||
extensions.has("GL_ARB_imaging") ||
extensions.has("GL_EXT_blend_color")) {
GET_PROC(BlendColor);
}
GET_PROC(BufferData);
GET_PROC(BufferSubData);
GET_PROC(Clear);
GET_PROC(ClearColor);
GET_PROC(ClearStencil);
GET_PROC(ClientActiveTexture);
GET_PROC(ColorMask);
GET_PROC(CompileShader);
GET_PROC(CompressedTexImage2D);
GET_PROC(CopyTexSubImage2D);
GET_PROC(CreateProgram);
GET_PROC(CreateShader);
GET_PROC(CullFace);
GET_PROC(DeleteBuffers);
GET_PROC(DeleteProgram);
GET_PROC(DeleteQueries);
GET_PROC(DeleteShader);
GET_PROC(DeleteTextures);
GET_PROC(DepthMask);
GET_PROC(Disable);
GET_PROC(DisableClientState);
GET_PROC(DisableVertexAttribArray);
GET_PROC(DrawArrays);
GET_PROC(DrawBuffer);
GET_PROC(DrawBuffers);
GET_PROC(DrawElements);
GET_PROC(Enable);
GET_PROC(EnableClientState);
GET_PROC(EnableVertexAttribArray);
GET_PROC(EndQuery);
GET_PROC(Finish);
GET_PROC(Flush);
GET_PROC(FrontFace);
GET_PROC(GenBuffers);
GET_PROC(GenerateMipmap);
GET_PROC(GenQueries);
GET_PROC(GetBufferParameteriv);
GET_PROC(GetError);
GET_PROC(GetIntegerv);
GET_PROC(GetProgramInfoLog);
GET_PROC(GetProgramiv);
GET_PROC(GetQueryiv);
GET_PROC(GetQueryObjectiv);
GET_PROC(GetQueryObjectuiv);
GET_PROC(GetShaderInfoLog);
GET_PROC(GetShaderiv);
GET_PROC(GetString);
GET_PROC(GetStringi);
GET_PROC(GetTexLevelParameteriv);
GET_PROC(GenTextures);
GET_PROC(GetUniformLocation);
GET_PROC(LineWidth);
GET_PROC(LinkProgram);
GET_PROC(LoadIdentity);
GET_PROC(LoadMatrixf);
GET_PROC(MapBuffer);
GET_PROC(MatrixMode);
GET_PROC(PixelStorei);
GET_PROC(ReadBuffer);
GET_PROC(ReadPixels);
GET_PROC(Scissor);
GET_PROC(ShaderSource);
GET_PROC(StencilFunc);
GET_PROC(StencilFuncSeparate);
GET_PROC(StencilMask);
GET_PROC(StencilMaskSeparate);
GET_PROC(StencilOp);
GET_PROC(StencilOpSeparate);
GET_PROC(TexGenf);
GET_PROC(TexGenfv);
GET_PROC(TexGeni);
GET_PROC(TexImage2D);
GET_PROC(TexParameteri);
GET_PROC(TexParameteriv);
if (ver >= GR_GL_VER(4,2) || extensions.has("GL_ARB_texture_storage")) {
GET_PROC(TexStorage2D);
} else if (extensions.has("GL_EXT_texture_storage")) {
GET_PROC_SUFFIX(TexStorage2D, EXT);
}
GET_PROC(TexSubImage2D);
GET_PROC(Uniform1f);
GET_PROC(Uniform1i);
GET_PROC(Uniform1fv);
GET_PROC(Uniform1iv);
GET_PROC(Uniform2f);
GET_PROC(Uniform2i);
GET_PROC(Uniform2fv);
GET_PROC(Uniform2iv);
GET_PROC(Uniform3f);
GET_PROC(Uniform3i);
GET_PROC(Uniform3fv);
GET_PROC(Uniform3iv);
GET_PROC(Uniform4f);
GET_PROC(Uniform4i);
GET_PROC(Uniform4fv);
GET_PROC(Uniform4iv);
GET_PROC(Uniform4fv);
GET_PROC(UniformMatrix2fv);
GET_PROC(UniformMatrix3fv);
GET_PROC(UniformMatrix4fv);
GET_PROC(UnmapBuffer);
GET_PROC(UseProgram);
GET_PROC(VertexAttrib4fv);
GET_PROC(VertexAttribPointer);
GET_PROC(VertexPointer);
GET_PROC(Viewport);
if (ver >= GR_GL_VER(3,0) || extensions.has("GL_ARB_vertex_array_object")) {
// no ARB suffix for GL_ARB_vertex_array_object
GET_PROC(BindVertexArray);
GET_PROC(DeleteVertexArrays);
GET_PROC(GenVertexArrays);
}
if (ver >= GR_GL_VER(3,3) || extensions.has("GL_ARB_timer_query")) {
// ARB extension doesn't use the ARB suffix on the function name
GET_PROC(QueryCounter);
GET_PROC(GetQueryObjecti64v);
GET_PROC(GetQueryObjectui64v);
} else if (extensions.has("GL_EXT_timer_query")) {
GET_PROC_SUFFIX(GetQueryObjecti64v, EXT);
GET_PROC_SUFFIX(GetQueryObjectui64v, EXT);
}
if (ver >= GR_GL_VER(3,0) || extensions.has("GL_ARB_framebuffer_object")) {
// ARB extension doesn't use the ARB suffix on the function names
GET_PROC(GenFramebuffers);
GET_PROC(GetFramebufferAttachmentParameteriv);
GET_PROC(GetRenderbufferParameteriv);
GET_PROC(BindFramebuffer);
GET_PROC(FramebufferTexture2D);
GET_PROC(CheckFramebufferStatus);
GET_PROC(DeleteFramebuffers);
GET_PROC(RenderbufferStorage);
GET_PROC(GenRenderbuffers);
GET_PROC(DeleteRenderbuffers);
GET_PROC(FramebufferRenderbuffer);
GET_PROC(BindRenderbuffer);
GET_PROC(RenderbufferStorageMultisample);
GET_PROC(BlitFramebuffer);
} else {
if (extensions.has("GL_EXT_framebuffer_object")) {
GET_PROC_SUFFIX(GenFramebuffers, EXT);
GET_PROC_SUFFIX(GetFramebufferAttachmentParameteriv, EXT);
GET_PROC_SUFFIX(GetRenderbufferParameteriv, EXT);
GET_PROC_SUFFIX(BindFramebuffer, EXT);
GET_PROC_SUFFIX(FramebufferTexture2D, EXT);
GET_PROC_SUFFIX(CheckFramebufferStatus, EXT);
GET_PROC_SUFFIX(DeleteFramebuffers, EXT);
GET_PROC_SUFFIX(RenderbufferStorage, EXT);
GET_PROC_SUFFIX(GenRenderbuffers, EXT);
GET_PROC_SUFFIX(DeleteRenderbuffers, EXT);
GET_PROC_SUFFIX(FramebufferRenderbuffer, EXT);
GET_PROC_SUFFIX(BindRenderbuffer, EXT);
}
if (extensions.has("GL_EXT_framebuffer_multisample")) {
GET_PROC_SUFFIX(RenderbufferStorageMultisample, EXT);
}
if (extensions.has("GL_EXT_framebuffer_blit")) {
GET_PROC_SUFFIX(BlitFramebuffer, EXT);
}
}
if (ver >= GR_GL_VER(3,3) || extensions.has("GL_ARB_blend_func_extended")) {
// ARB extension doesn't use the ARB suffix on the function name
GET_PROC(BindFragDataLocationIndexed);
if (extensions.has("GL_EXT_framebuffer_blit")) {
GET_PROC_SUFFIX(BlitFramebuffer, EXT);
}
}
glInterface.get()->ref();
return glInterface.get();
if (ver >= GR_GL_VER(3,3) || extensions.has("GL_ARB_blend_func_extended")) {
// ARB extension doesn't use the ARB suffix on the function name
GET_PROC(BindFragDataLocationIndexed);
}
return interface;
}

View File

@ -41,7 +41,7 @@ const GrGLInterface* GrGLCreateMesaInterface() {
// We must have array and element_array buffer objects.
return NULL;
}
GrGLInterface* interface = new GrGLInterface();
GrGLInterface* interface = SkNEW(GrGLInterface());
GR_GL_GET_PROC(ActiveTexture);
GR_GL_GET_PROC(BeginQuery);

View File

@ -41,7 +41,7 @@ const GrGLInterface* GrGLCreateNativeInterface() {
return NULL;
}
GrGLInterface* interface = new GrGLInterface();
GrGLInterface* interface = SkNEW(GrGLInterface());
interface->fActiveTexture = glActiveTexture;
GR_GL_GET_PROC(AttachShader);

View File

@ -41,10 +41,6 @@ private:
};
const GrGLInterface* GrGLCreateNativeInterface() {
// wglGetProcAddress requires a context.
// GL Function pointers retrieved in one context may not be valid in another
// context. For that reason we create a new GrGLInterface each time we're
// called.
AutoLibraryUnload alu("opengl32.dll");
if (NULL == alu.get()) {
return NULL;
@ -75,7 +71,7 @@ const GrGLInterface* GrGLCreateNativeInterface() {
// We must have array and element_array buffer objects.
return NULL;
}
GrGLInterface* interface = new GrGLInterface();
GrGLInterface* interface = SkNEW(GrGLInterface);
// Functions that are part of GL 1.1 will return NULL in
// wglGetProcAddress