michael@0: /* -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40; -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "skia/GrContext.h" michael@0: #include "skia/GrGLInterface.h" michael@0: #include "mozilla/gfx/2D.h" michael@0: #include "mozilla/ThreadLocal.h" michael@0: #include "mozilla/DebugOnly.h" michael@0: michael@0: /* SkPostConfig.h includes windows.h, which includes windef.h michael@0: * which redefines min/max. We don't want that. */ michael@0: #ifdef _WIN32 michael@0: #undef min michael@0: #undef max michael@0: #endif michael@0: michael@0: #include "GLContext.h" michael@0: #include "SkiaGLGlue.h" michael@0: michael@0: using mozilla::gl::GLContext; michael@0: using mozilla::gl::GLFeature; michael@0: using mozilla::gl::SkiaGLGlue; michael@0: using mozilla::gfx::DrawTarget; michael@0: michael@0: static mozilla::ThreadLocal sGLContext; michael@0: michael@0: extern "C" { michael@0: michael@0: static void SetStaticGLContext(GLContext* context) michael@0: { michael@0: if (!sGLContext.initialized()) { michael@0: mozilla::DebugOnly success = sGLContext.init(); michael@0: MOZ_ASSERT(success); michael@0: } michael@0: michael@0: sGLContext.set(context); michael@0: } michael@0: michael@0: void EnsureGLContext(const GrGLInterface* i) michael@0: { michael@0: const SkiaGLGlue* contextSkia = reinterpret_cast(i->fCallbackData); michael@0: MOZ_ASSERT(contextSkia); michael@0: GLContext* gl = contextSkia->GetGLContext(); michael@0: gl->MakeCurrent(); michael@0: SetStaticGLContext(gl); michael@0: } michael@0: michael@0: // Core GL functions required by Ganesh michael@0: michael@0: GrGLvoid glActiveTexture_mozilla(GrGLenum texture) michael@0: { michael@0: return sGLContext.get()->fActiveTexture(texture); michael@0: } michael@0: michael@0: GrGLvoid glAttachShader_mozilla(GrGLuint program, GrGLuint shader) michael@0: { michael@0: return sGLContext.get()->fAttachShader(program, shader); michael@0: } michael@0: michael@0: GrGLvoid glBindAttribLocation_mozilla(GrGLuint program, GrGLuint index, const GLchar* name) michael@0: { michael@0: return sGLContext.get()->fBindAttribLocation(program, index, name); michael@0: } michael@0: michael@0: GrGLvoid glBindBuffer_mozilla(GrGLenum target, GrGLuint buffer) michael@0: { michael@0: return sGLContext.get()->fBindBuffer(target, buffer); michael@0: } michael@0: michael@0: GrGLvoid glBindFramebuffer_mozilla(GrGLenum target, GrGLuint framebuffer) michael@0: { michael@0: return sGLContext.get()->fBindFramebuffer(target, framebuffer); michael@0: } michael@0: michael@0: GrGLvoid glBindRenderbuffer_mozilla(GrGLenum target, GrGLuint renderbuffer) michael@0: { michael@0: return sGLContext.get()->fBindRenderbuffer(target, renderbuffer); michael@0: } michael@0: michael@0: GrGLvoid glBindTexture_mozilla(GrGLenum target, GrGLuint texture) michael@0: { michael@0: return sGLContext.get()->fBindTexture(target, texture); michael@0: } michael@0: michael@0: GrGLvoid glBlendColor_mozilla(GrGLclampf red, GrGLclampf green, GrGLclampf blue, GrGLclampf alpha) michael@0: { michael@0: return sGLContext.get()->fBlendColor(red, green, blue, alpha); michael@0: } michael@0: michael@0: GrGLvoid glBlendFunc_mozilla(GrGLenum sfactor, GrGLenum dfactor) michael@0: { michael@0: return sGLContext.get()->fBlendFunc(sfactor, dfactor); michael@0: } michael@0: michael@0: GrGLvoid glBufferData_mozilla(GrGLenum target, GrGLsizeiptr size, const void* data, GrGLenum usage) michael@0: { michael@0: return sGLContext.get()->fBufferData(target, size, data, usage); michael@0: } michael@0: michael@0: GrGLvoid glBufferSubData_mozilla(GrGLenum target, GrGLintptr offset, GrGLsizeiptr size, const void* data) michael@0: { michael@0: return sGLContext.get()->fBufferSubData(target, offset, size, data); michael@0: } michael@0: michael@0: GrGLenum glCheckFramebufferStatus_mozilla(GrGLenum target) michael@0: { michael@0: return sGLContext.get()->fCheckFramebufferStatus(target); michael@0: } michael@0: michael@0: GrGLvoid glClear_mozilla(GrGLbitfield mask) michael@0: { michael@0: return sGLContext.get()->fClear(mask); michael@0: } michael@0: michael@0: GrGLvoid glClearColor_mozilla(GrGLclampf red, GrGLclampf green, GrGLclampf blue, GrGLclampf alpha) michael@0: { michael@0: return sGLContext.get()->fClearColor(red, green, blue, alpha); michael@0: } michael@0: michael@0: GrGLvoid glClearStencil_mozilla(GrGLint s) michael@0: { michael@0: return sGLContext.get()->fClearStencil(s); michael@0: } michael@0: michael@0: GrGLvoid glColorMask_mozilla(GrGLboolean red, GrGLboolean green, GrGLboolean blue, GrGLboolean alpha) michael@0: { michael@0: return sGLContext.get()->fColorMask(red, green, blue, alpha); michael@0: } michael@0: michael@0: GrGLvoid glCompileShader_mozilla(GrGLuint shader) michael@0: { michael@0: return sGLContext.get()->fCompileShader(shader); michael@0: } michael@0: michael@0: GrGLvoid glCopyTexSubImage2D_mozilla(GrGLenum target, GrGLint level, GrGLint xoffset, GrGLint yoffset, michael@0: GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height) michael@0: { michael@0: return sGLContext.get()->fCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height); michael@0: } michael@0: michael@0: GrGLuint glCreateProgram_mozilla(void) michael@0: { michael@0: return sGLContext.get()->fCreateProgram(); michael@0: } michael@0: michael@0: GrGLuint glCreateShader_mozilla(GrGLenum type) michael@0: { michael@0: return sGLContext.get()->fCreateShader(type); michael@0: } michael@0: michael@0: GrGLvoid glCullFace_mozilla(GrGLenum mode) michael@0: { michael@0: return sGLContext.get()->fCullFace(mode); michael@0: } michael@0: michael@0: GrGLvoid glDeleteBuffers_mozilla(GrGLsizei n, const GrGLuint* buffers) michael@0: { michael@0: return sGLContext.get()->fDeleteBuffers(n, buffers); michael@0: } michael@0: michael@0: GrGLvoid glDeleteFramebuffers_mozilla(GrGLsizei n, const GrGLuint* framebuffers) michael@0: { michael@0: return sGLContext.get()->fDeleteFramebuffers(n, framebuffers); michael@0: } michael@0: michael@0: GrGLvoid glDeleteProgram_mozilla(GrGLuint program) michael@0: { michael@0: return sGLContext.get()->fDeleteProgram(program); michael@0: } michael@0: michael@0: GrGLvoid glDeleteRenderbuffers_mozilla(GrGLsizei n, const GrGLuint* renderbuffers) michael@0: { michael@0: return sGLContext.get()->fDeleteRenderbuffers(n, renderbuffers); michael@0: } michael@0: michael@0: GrGLvoid glDeleteShader_mozilla(GrGLuint shader) michael@0: { michael@0: return sGLContext.get()->fDeleteShader(shader); michael@0: } michael@0: michael@0: GrGLvoid glDeleteTextures_mozilla(GrGLsizei n, const GrGLuint* textures) michael@0: { michael@0: return sGLContext.get()->fDeleteTextures(n, textures); michael@0: } michael@0: michael@0: GrGLvoid glDepthMask_mozilla(GrGLboolean flag) michael@0: { michael@0: return sGLContext.get()->fDepthMask(flag); michael@0: } michael@0: michael@0: GrGLvoid glDisable_mozilla(GrGLenum cap) michael@0: { michael@0: return sGLContext.get()->fDisable(cap); michael@0: } michael@0: michael@0: GrGLvoid glDisableVertexAttribArray_mozilla(GrGLuint index) michael@0: { michael@0: return sGLContext.get()->fDisableVertexAttribArray(index); michael@0: } michael@0: michael@0: GrGLvoid glDrawArrays_mozilla(GrGLenum mode, GrGLint first, GrGLsizei count) michael@0: { michael@0: return sGLContext.get()->fDrawArrays(mode, first, count); michael@0: } michael@0: michael@0: GrGLvoid glDrawElements_mozilla(GrGLenum mode, GrGLsizei count, GrGLenum type, const void* indices) michael@0: { michael@0: return sGLContext.get()->fDrawElements(mode, count, type, indices); michael@0: } michael@0: michael@0: GrGLvoid glEnable_mozilla(GrGLenum cap) michael@0: { michael@0: return sGLContext.get()->fEnable(cap); michael@0: } michael@0: michael@0: GrGLvoid glEnableVertexAttribArray_mozilla(GrGLuint index) michael@0: { michael@0: return sGLContext.get()->fEnableVertexAttribArray(index); michael@0: } michael@0: michael@0: GrGLvoid glFinish_mozilla() michael@0: { michael@0: return sGLContext.get()->fFinish(); michael@0: } michael@0: michael@0: GrGLvoid glFlush_mozilla() michael@0: { michael@0: return sGLContext.get()->fFlush(); michael@0: } michael@0: michael@0: GrGLvoid glFramebufferRenderbuffer_mozilla(GrGLenum target, GrGLenum attachment, GrGLenum renderbuffertarget, GrGLuint renderbuffer) michael@0: { michael@0: return sGLContext.get()->fFramebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer); michael@0: } michael@0: michael@0: GrGLvoid glFramebufferTexture2D_mozilla(GrGLenum target, GrGLenum attachment, GrGLenum textarget, GrGLuint texture, GrGLint level) michael@0: { michael@0: return sGLContext.get()->fFramebufferTexture2D(target, attachment, textarget, texture, level); michael@0: } michael@0: michael@0: GrGLvoid glFrontFace_mozilla(GrGLenum mode) michael@0: { michael@0: return sGLContext.get()->fFrontFace(mode); michael@0: } michael@0: michael@0: GrGLvoid glGenBuffers_mozilla(GrGLsizei n, GrGLuint* buffers) michael@0: { michael@0: return sGLContext.get()->fGenBuffers(n, buffers); michael@0: } michael@0: michael@0: GrGLvoid glGenFramebuffers_mozilla(GrGLsizei n, GrGLuint* framebuffers) michael@0: { michael@0: return sGLContext.get()->fGenFramebuffers(n, framebuffers); michael@0: } michael@0: michael@0: GrGLvoid glGenRenderbuffers_mozilla(GrGLsizei n, GrGLuint* renderbuffers) michael@0: { michael@0: return sGLContext.get()->fGenRenderbuffers(n, renderbuffers); michael@0: } michael@0: michael@0: GrGLvoid glGenTextures_mozilla(GrGLsizei n, GrGLuint* textures) michael@0: { michael@0: return sGLContext.get()->fGenTextures(n, textures); michael@0: } michael@0: michael@0: GrGLvoid glGenerateMipmap_mozilla(GrGLenum target) michael@0: { michael@0: return sGLContext.get()->fGenerateMipmap(target); michael@0: } michael@0: michael@0: GrGLvoid glGetBufferParameteriv_mozilla(GrGLenum target, GrGLenum pname, GrGLint* params) michael@0: { michael@0: return sGLContext.get()->fGetBufferParameteriv(target, pname, params); michael@0: } michael@0: michael@0: GrGLvoid glGetFramebufferAttachmentParameteriv_mozilla(GrGLenum target, GrGLenum attachment, GrGLenum pname, GrGLint* params) michael@0: { michael@0: return sGLContext.get()->fGetFramebufferAttachmentParameteriv(target, attachment, pname, params); michael@0: } michael@0: michael@0: GrGLenum glGetError_mozilla() michael@0: { michael@0: return sGLContext.get()->fGetError(); michael@0: } michael@0: michael@0: GrGLvoid glGetIntegerv_mozilla(GrGLenum pname, GrGLint* params) michael@0: { michael@0: return sGLContext.get()->fGetIntegerv(pname, params); michael@0: } michael@0: michael@0: GrGLvoid glGetProgramInfoLog_mozilla(GrGLuint program, GrGLsizei bufsize, GrGLsizei* length, char* infolog) michael@0: { michael@0: return sGLContext.get()->fGetProgramInfoLog(program, bufsize, length, infolog); michael@0: } michael@0: michael@0: GrGLvoid glGetProgramiv_mozilla(GrGLuint program, GrGLenum pname, GrGLint* params) michael@0: { michael@0: return sGLContext.get()->fGetProgramiv(program, pname, params); michael@0: } michael@0: michael@0: GrGLvoid glGetRenderbufferParameteriv_mozilla(GrGLenum target, GrGLenum pname, GrGLint* params) michael@0: { michael@0: return sGLContext.get()->fGetRenderbufferParameteriv(target, pname, params); michael@0: } michael@0: michael@0: GrGLvoid glGetShaderInfoLog_mozilla(GrGLuint shader, GrGLsizei bufsize, GrGLsizei* length, char* infolog) michael@0: { michael@0: return sGLContext.get()->fGetShaderInfoLog(shader, bufsize, length, infolog); michael@0: } michael@0: michael@0: GrGLvoid glGetShaderiv_mozilla(GrGLuint shader, GrGLenum pname, GrGLint* params) michael@0: { michael@0: return sGLContext.get()->fGetShaderiv(shader, pname, params); michael@0: } michael@0: michael@0: const GLubyte* glGetString_mozilla(GrGLenum name) michael@0: { michael@0: // GLContext only exposes a OpenGL 2.0 style API, so we have to intercept a bunch michael@0: // of checks that Ganesh makes to determine which capabilities are present michael@0: // on the GL implementation and change them to match what GLContext actually exposes. michael@0: michael@0: if (name == LOCAL_GL_VERSION) { michael@0: if (sGLContext.get()->IsGLES()) { michael@0: return reinterpret_cast("OpenGL ES 2.0"); michael@0: } else { michael@0: return reinterpret_cast("2.0"); michael@0: } michael@0: } else if (name == LOCAL_GL_EXTENSIONS) { michael@0: // Only expose the bare minimum extensions we want to support to ensure a functional Ganesh michael@0: // as GLContext only exposes certain extensions michael@0: static bool extensionsStringBuilt = false; michael@0: static char extensionsString[1024]; michael@0: michael@0: if (!extensionsStringBuilt) { michael@0: extensionsString[0] = '\0'; michael@0: michael@0: if (sGLContext.get()->IsGLES()) { michael@0: // OES is only applicable to GLES2 michael@0: if (sGLContext.get()->IsExtensionSupported(GLContext::OES_packed_depth_stencil)) { michael@0: strcat(extensionsString, "GL_OES_packed_depth_stencil "); michael@0: } michael@0: michael@0: if (sGLContext.get()->IsExtensionSupported(GLContext::OES_rgb8_rgba8)) { michael@0: strcat(extensionsString, "GL_OES_rgb8_rgba8 "); michael@0: } michael@0: michael@0: if (sGLContext.get()->IsExtensionSupported(GLContext::OES_texture_npot)) { michael@0: strcat(extensionsString, "GL_OES_texture_npot "); michael@0: } michael@0: michael@0: if (sGLContext.get()->IsExtensionSupported(GLContext::OES_vertex_array_object)) { michael@0: strcat(extensionsString, "GL_OES_vertex_array_object "); michael@0: } michael@0: michael@0: if (sGLContext.get()->IsSupported(GLFeature::standard_derivatives)) { michael@0: strcat(extensionsString, "GL_OES_standard_derivatives "); michael@0: } michael@0: } michael@0: michael@0: if (sGLContext.get()->IsExtensionSupported(GLContext::EXT_texture_format_BGRA8888)) { michael@0: strcat(extensionsString, "GL_EXT_texture_format_BGRA8888 "); michael@0: } michael@0: michael@0: if (sGLContext.get()->IsExtensionSupported(GLContext::EXT_packed_depth_stencil)) { michael@0: strcat(extensionsString, "GL_EXT_packed_depth_stencil "); michael@0: } michael@0: michael@0: if (sGLContext.get()->IsExtensionSupported(GLContext::EXT_bgra)) { michael@0: strcat(extensionsString, "GL_EXT_bgra "); michael@0: } michael@0: michael@0: if (sGLContext.get()->IsExtensionSupported(GLContext::EXT_read_format_bgra)) { michael@0: strcat(extensionsString, "GL_EXT_read_format_bgra "); michael@0: } michael@0: michael@0: extensionsStringBuilt = true; michael@0: #ifdef DEBUG michael@0: printf_stderr("Exported SkiaGL extensions: %s\n", extensionsString); michael@0: #endif michael@0: } michael@0: michael@0: return reinterpret_cast(extensionsString); michael@0: michael@0: } else if (name == LOCAL_GL_SHADING_LANGUAGE_VERSION) { michael@0: if (sGLContext.get()->IsGLES()) { michael@0: return reinterpret_cast("OpenGL ES GLSL ES 1.0"); michael@0: } else { michael@0: return reinterpret_cast("1.10"); michael@0: } michael@0: } michael@0: michael@0: return sGLContext.get()->fGetString(name); michael@0: } michael@0: michael@0: GrGLint glGetUniformLocation_mozilla(GrGLuint program, const char* name) michael@0: { michael@0: return sGLContext.get()->fGetUniformLocation(program, name); michael@0: } michael@0: michael@0: GrGLvoid glLineWidth_mozilla(GrGLfloat width) michael@0: { michael@0: return sGLContext.get()->fLineWidth(width); michael@0: } michael@0: michael@0: GrGLvoid glLinkProgram_mozilla(GrGLuint program) michael@0: { michael@0: return sGLContext.get()->fLinkProgram(program); michael@0: } michael@0: michael@0: GrGLvoid glPixelStorei_mozilla(GrGLenum pname, GrGLint param) michael@0: { michael@0: return sGLContext.get()->fPixelStorei(pname, param); michael@0: } michael@0: michael@0: GrGLvoid glReadPixels_mozilla(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height, michael@0: GrGLenum format, GrGLenum type, void* pixels) michael@0: { michael@0: return sGLContext.get()->fReadPixels(x, y, width, height, michael@0: format, type, pixels); michael@0: } michael@0: michael@0: GrGLvoid glRenderbufferStorage_mozilla(GrGLenum target, GrGLenum internalformat, GrGLsizei width, GrGLsizei height) michael@0: { michael@0: return sGLContext.get()->fRenderbufferStorage(target, internalformat, width, height); michael@0: } michael@0: michael@0: GrGLvoid glScissor_mozilla(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height) michael@0: { michael@0: return sGLContext.get()->fScissor(x, y, width, height); michael@0: } michael@0: michael@0: GrGLvoid glShaderSource_mozilla(GrGLuint shader, GrGLsizei count, const char** str, const GrGLint* length) michael@0: { michael@0: return sGLContext.get()->fShaderSource(shader, count, str, length); michael@0: } michael@0: michael@0: GrGLvoid glStencilFunc_mozilla(GrGLenum func, GrGLint ref, GrGLuint mask) michael@0: { michael@0: return sGLContext.get()->fStencilFunc(func, ref, mask); michael@0: } michael@0: michael@0: GrGLvoid glStencilMask_mozilla(GrGLuint mask) michael@0: { michael@0: return sGLContext.get()->fStencilMask(mask); michael@0: } michael@0: michael@0: GrGLvoid glStencilOp_mozilla(GrGLenum fail, GrGLenum zfail, GrGLenum zpass) michael@0: { michael@0: return sGLContext.get()->fStencilOp(fail, zfail, zpass); michael@0: } michael@0: michael@0: GrGLvoid glTexImage2D_mozilla(GrGLenum target, GrGLint level, GrGLint internalformat, michael@0: GrGLsizei width, GrGLsizei height, GrGLint border, michael@0: GrGLenum format, GrGLenum type, const void* pixels) michael@0: { michael@0: return sGLContext.get()->fTexImage2D(target, level, internalformat, michael@0: width, height, border, michael@0: format, type, pixels); michael@0: } michael@0: michael@0: GrGLvoid glTexParameteri_mozilla(GrGLenum target, GrGLenum pname, GrGLint param) michael@0: { michael@0: return sGLContext.get()->fTexParameteri(target, pname, param); michael@0: } michael@0: michael@0: GrGLvoid glTexParameteriv_mozilla(GrGLenum target, GrGLenum pname, const GrGLint* params) michael@0: { michael@0: return sGLContext.get()->fTexParameteriv(target, pname, params); michael@0: } michael@0: michael@0: GrGLvoid glTexSubImage2D_mozilla(GrGLenum target, GrGLint level, michael@0: GrGLint xoffset, GrGLint yoffset, michael@0: GrGLsizei width, GrGLsizei height, michael@0: GrGLenum format, GrGLenum type, const void* pixels) michael@0: { michael@0: return sGLContext.get()->fTexSubImage2D(target, level, michael@0: xoffset, yoffset, michael@0: width, height, michael@0: format, type, pixels); michael@0: } michael@0: michael@0: GrGLvoid glUniform1f_mozilla(GrGLint location, GrGLfloat v) michael@0: { michael@0: return sGLContext.get()->fUniform1f(location, v); michael@0: } michael@0: michael@0: GrGLvoid glUniform1i_mozilla(GrGLint location, GrGLint v) michael@0: { michael@0: return sGLContext.get()->fUniform1i(location, v); michael@0: } michael@0: michael@0: GrGLvoid glUniform1fv_mozilla(GrGLint location, GrGLsizei count, const GrGLfloat* v) michael@0: { michael@0: return sGLContext.get()->fUniform1fv(location, count, v); michael@0: } michael@0: michael@0: GrGLvoid glUniform1iv_mozilla(GrGLint location, GrGLsizei count, const GrGLint* v) michael@0: { michael@0: return sGLContext.get()->fUniform1iv(location, count, v); michael@0: } michael@0: michael@0: GrGLvoid glUniform2f_mozilla(GrGLint location, GrGLfloat v0, GrGLfloat v1) michael@0: { michael@0: return sGLContext.get()->fUniform2f(location, v0, v1); michael@0: } michael@0: michael@0: GrGLvoid glUniform2i_mozilla(GrGLint location, GrGLint v0, GrGLint v1) michael@0: { michael@0: return sGLContext.get()->fUniform2i(location, v0, v1); michael@0: } michael@0: michael@0: GrGLvoid glUniform2fv_mozilla(GrGLint location, GrGLsizei count, const GrGLfloat* v) michael@0: { michael@0: return sGLContext.get()->fUniform2fv(location, count, v); michael@0: } michael@0: michael@0: GrGLvoid glUniform2iv_mozilla(GrGLint location, GrGLsizei count, const GrGLint* v) michael@0: { michael@0: return sGLContext.get()->fUniform2iv(location, count, v); michael@0: } michael@0: michael@0: GrGLvoid glUniform3f_mozilla(GrGLint location, GrGLfloat v0, GrGLfloat v1, GrGLfloat v2) michael@0: { michael@0: return sGLContext.get()->fUniform3f(location, v0, v1, v2); michael@0: } michael@0: michael@0: GrGLvoid glUniform3i_mozilla(GrGLint location, GrGLint v0, GrGLint v1, GrGLint v2) michael@0: { michael@0: return sGLContext.get()->fUniform3i(location, v0, v1, v2); michael@0: } michael@0: michael@0: GrGLvoid glUniform3fv_mozilla(GrGLint location, GrGLsizei count, const GrGLfloat* v) michael@0: { michael@0: return sGLContext.get()->fUniform3fv(location, count, v); michael@0: } michael@0: michael@0: GrGLvoid glUniform3iv_mozilla(GrGLint location, GrGLsizei count, const GrGLint* v) michael@0: { michael@0: return sGLContext.get()->fUniform3iv(location, count, v); michael@0: } michael@0: michael@0: GrGLvoid glUniform4f_mozilla(GrGLint location, GrGLfloat v0, GrGLfloat v1, GrGLfloat v2, GrGLfloat v3) michael@0: { michael@0: return sGLContext.get()->fUniform4f(location, v0, v1, v2, v3); michael@0: } michael@0: michael@0: GrGLvoid glUniform4i_mozilla(GrGLint location, GrGLint v0, GrGLint v1, GrGLint v2, GrGLint v3) michael@0: { michael@0: return sGLContext.get()->fUniform4i(location, v0, v1, v2, v3); michael@0: } michael@0: michael@0: GrGLvoid glUniform4fv_mozilla(GrGLint location, GrGLsizei count, const GrGLfloat* v) michael@0: { michael@0: return sGLContext.get()->fUniform4fv(location, count, v); michael@0: } michael@0: michael@0: GrGLvoid glUniform4iv_mozilla(GrGLint location, GrGLsizei count, const GrGLint* v) michael@0: { michael@0: return sGLContext.get()->fUniform4iv(location, count, v); michael@0: } michael@0: michael@0: GrGLvoid glUniformMatrix2fv_mozilla(GrGLint location, GrGLsizei count, GrGLboolean transpose, const GrGLfloat* value) michael@0: { michael@0: return sGLContext.get()->fUniformMatrix2fv(location, count, transpose, value); michael@0: } michael@0: michael@0: GrGLvoid glUniformMatrix3fv_mozilla(GrGLint location, GrGLsizei count, GrGLboolean transpose, const GrGLfloat* value) michael@0: { michael@0: return sGLContext.get()->fUniformMatrix3fv(location, count, transpose, value); michael@0: } michael@0: michael@0: GrGLvoid glUniformMatrix4fv_mozilla(GrGLint location, GrGLsizei count, GrGLboolean transpose, const GrGLfloat* value) michael@0: { michael@0: return sGLContext.get()->fUniformMatrix4fv(location, count, transpose, value); michael@0: } michael@0: michael@0: GrGLvoid glUseProgram_mozilla(GrGLuint program) michael@0: { michael@0: return sGLContext.get()->fUseProgram(program); michael@0: } michael@0: michael@0: GrGLvoid glVertexAttrib4fv_mozilla(GrGLuint index, const GrGLfloat* values) michael@0: { michael@0: return sGLContext.get()->fVertexAttrib4fv(index, values); michael@0: } michael@0: michael@0: GrGLvoid glVertexAttribPointer_mozilla(GrGLuint index, GrGLint size, GrGLenum type, GrGLboolean normalized, GrGLsizei stride, const void* ptr) michael@0: { michael@0: return sGLContext.get()->fVertexAttribPointer(index, size, type, normalized, stride, ptr); michael@0: } michael@0: michael@0: GrGLvoid glViewport_mozilla(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height) michael@0: { michael@0: return sGLContext.get()->fViewport(x, y, width, height); michael@0: } michael@0: michael@0: // Required if the bindings are GLES2 or desktop OpenGL 2.0 michael@0: michael@0: GrGLvoid glStencilFuncSeparate_mozilla(GrGLenum frontfunc, GrGLenum backfunc, GrGLint ref, GrGLuint mask) michael@0: { michael@0: return sGLContext.get()->fStencilFuncSeparate(frontfunc, backfunc, ref, mask); michael@0: } michael@0: michael@0: GrGLvoid glStencilMaskSeparate_mozilla(GrGLenum face, GrGLuint mask) michael@0: { michael@0: return sGLContext.get()->fStencilMaskSeparate(face, mask); michael@0: } michael@0: michael@0: GrGLvoid glStencilOpSeparate_mozilla(GrGLenum face, GrGLenum sfail, GrGLenum dpfail, GrGLenum dppass) michael@0: { michael@0: return sGLContext.get()->fStencilOpSeparate(face, sfail, dpfail, dppass); michael@0: } michael@0: michael@0: // Not in GLES2 michael@0: michael@0: GrGLvoid glGetTexLevelParameteriv_mozilla(GrGLenum target, GrGLint level, GrGLenum pname, GrGLint *params) michael@0: { michael@0: return sGLContext.get()->fGetTexLevelParameteriv(target, level, pname, params); michael@0: } michael@0: michael@0: GrGLvoid glDrawBuffer_mozilla(GrGLenum mode) michael@0: { michael@0: return sGLContext.get()->fDrawBuffer(mode); michael@0: } michael@0: michael@0: GrGLvoid glReadBuffer_mozilla(GrGLenum mode) michael@0: { michael@0: return sGLContext.get()->fReadBuffer(mode); michael@0: } michael@0: michael@0: // Desktop OpenGL version >= 1.5 michael@0: michael@0: GrGLvoid glGenQueries_mozilla(GrGLsizei n, GrGLuint* ids) michael@0: { michael@0: return sGLContext.get()->fGenQueries(n, ids); michael@0: } michael@0: michael@0: GrGLvoid glDeleteQueries_mozilla(GrGLsizei n, const GrGLuint* ids) michael@0: { michael@0: return sGLContext.get()->fDeleteQueries(n, ids); michael@0: } michael@0: michael@0: GrGLvoid glBeginQuery_mozilla(GrGLenum target, GrGLuint id) michael@0: { michael@0: return sGLContext.get()->fBeginQuery(target, id); michael@0: } michael@0: michael@0: GrGLvoid glEndQuery_mozilla(GrGLenum target) michael@0: { michael@0: return sGLContext.get()->fEndQuery(target); michael@0: } michael@0: michael@0: GrGLvoid glGetQueryiv_mozilla(GrGLenum target, GrGLenum pname, GrGLint* params) michael@0: { michael@0: return sGLContext.get()->fGetQueryiv(target, pname, params); michael@0: } michael@0: michael@0: GrGLvoid glGetQueryObjectiv_mozilla(GrGLuint id, GrGLenum pname, GrGLint* params) michael@0: { michael@0: return sGLContext.get()->fGetQueryObjectiv(id, pname, params); michael@0: } michael@0: michael@0: GrGLvoid glGetQueryObjectuiv_mozilla(GrGLuint id, GrGLenum pname, GrGLuint* params) michael@0: { michael@0: return sGLContext.get()->fGetQueryObjectuiv(id, pname, params); michael@0: } michael@0: michael@0: // Desktop OpenGL version >= 2.0 michael@0: michael@0: GrGLvoid glDrawBuffers_mozilla(GrGLsizei n, const GrGLenum* bufs) michael@0: { michael@0: return sGLContext.get()->fDrawBuffers(n, bufs); michael@0: } michael@0: michael@0: // GLContext supports glMapBuffer on everything (GL_OES_mapbuffer) michael@0: michael@0: GrGLvoid* glMapBuffer_mozilla(GrGLenum target, GrGLenum access) michael@0: { michael@0: return sGLContext.get()->fMapBuffer(target, access); michael@0: } michael@0: michael@0: GrGLboolean glUnmapBuffer_mozilla(GrGLenum target) michael@0: { michael@0: return sGLContext.get()->fUnmapBuffer(target); michael@0: } michael@0: michael@0: // GLContext supports glCompressedTexImage2D (GL_ARB_texture_compression) michael@0: michael@0: GrGLvoid glCompressedTexImage2D_mozilla(GrGLenum target, GrGLint level, GrGLenum internalformat, michael@0: GrGLsizei width, GrGLsizei height, GrGLint border, michael@0: GrGLsizei imageSize, const GrGLvoid* pixels) michael@0: { michael@0: return sGLContext.get()->fCompressedTexImage2D(target, level, internalformat, michael@0: width, height, border, michael@0: imageSize, pixels); michael@0: } michael@0: michael@0: // GLContext supports glBlitFramebuffer/glRenderbufferStorageMultisample (GL_ARB_framebuffer_object) michael@0: michael@0: GrGLvoid glRenderbufferStorageMultisample_mozilla(GrGLenum target, GrGLsizei samples, GrGLenum internalformat, michael@0: GrGLsizei width, GrGLsizei height) michael@0: { michael@0: return sGLContext.get()->fRenderbufferStorageMultisample(target, samples, internalformat, michael@0: width, height); michael@0: } michael@0: michael@0: GrGLvoid glBlitFramebuffer_mozilla(GrGLint srcX0, GrGLint srcY0, michael@0: GrGLint srcX1, GrGLint srcY1, michael@0: GrGLint dstX0, GrGLint dstY0, michael@0: GrGLint dstX1, GrGLint dstY1, michael@0: GrGLbitfield mask, GrGLenum filter) { michael@0: return sGLContext.get()->fBlitFramebuffer(srcX0, srcY0, michael@0: srcX1, srcY1, michael@0: dstX0, dstY0, michael@0: dstX1, dstY1, michael@0: mask, filter); michael@0: } michael@0: michael@0: GrGLvoid glBindVertexArray_mozilla(GrGLuint array) { michael@0: return sGLContext.get()->fBindVertexArray(array); michael@0: } michael@0: michael@0: GrGLvoid glDeleteVertexArrays_mozilla(GrGLsizei n, const GrGLuint *arrays) { michael@0: return sGLContext.get()->fDeleteVertexArrays(n, arrays); michael@0: } michael@0: michael@0: GrGLvoid glGenVertexArrays_mozilla(GrGLsizei n, GrGLuint *arrays) { michael@0: return sGLContext.get()->fGenVertexArrays(n, arrays); michael@0: } michael@0: michael@0: // Additional functions required for desktop GL < version 3.2 michael@0: michael@0: GrGLvoid glLoadMatrixf_mozilla(const GLfloat* matrix) michael@0: { michael@0: return sGLContext.get()->fLoadMatrixf(matrix); michael@0: } michael@0: michael@0: GrGLvoid glLoadIdentity_mozilla() michael@0: { michael@0: return sGLContext.get()->fLoadIdentity(); michael@0: } michael@0: michael@0: GrGLvoid glMatrixMode_mozilla(GrGLenum mode) michael@0: { michael@0: return sGLContext.get()->fMatrixMode(mode); michael@0: } michael@0: michael@0: GrGLvoid glTexGeni_mozilla(GrGLenum coord, GrGLenum pname, GrGLint param) michael@0: { michael@0: return sGLContext.get()->fTexGeni(coord, pname, param); michael@0: } michael@0: michael@0: GrGLvoid glTexGenfv_mozilla(GrGLenum coord, GrGLenum pname, const GrGLfloat* param) michael@0: { michael@0: return sGLContext.get()->fTexGenfv(coord, pname, param); michael@0: } michael@0: michael@0: } // extern "C" michael@0: michael@0: static GrGLInterface* CreateGrGLInterfaceFromGLContext(GLContext* context) michael@0: { michael@0: SetStaticGLContext(context); michael@0: michael@0: GrGLInterface* i = new GrGLInterface(); michael@0: i->fCallback = EnsureGLContext; michael@0: i->fCallbackData = 0; // must be later initialized to be a valid DrawTargetSkia* pointer michael@0: michael@0: context->MakeCurrent(); michael@0: michael@0: // We support both desktop GL and GLES2 michael@0: if (context->IsGLES()) { michael@0: i->fStandard = kGLES_GrGLStandard; michael@0: } else { michael@0: i->fStandard = kGL_GrGLStandard; michael@0: } michael@0: michael@0: GrGLExtensions extensions; michael@0: if (!extensions.init(i->fStandard, glGetString_mozilla, NULL, glGetIntegerv_mozilla)) { michael@0: return nullptr; michael@0: } michael@0: michael@0: i->fExtensions.swap(&extensions); michael@0: michael@0: // Core GL functions required by Ganesh michael@0: i->fFunctions.fActiveTexture = glActiveTexture_mozilla; michael@0: i->fFunctions.fAttachShader = glAttachShader_mozilla; michael@0: i->fFunctions.fBindAttribLocation = glBindAttribLocation_mozilla; michael@0: i->fFunctions.fBindBuffer = glBindBuffer_mozilla; michael@0: i->fFunctions.fBindFramebuffer = glBindFramebuffer_mozilla; michael@0: i->fFunctions.fBindRenderbuffer = glBindRenderbuffer_mozilla; michael@0: i->fFunctions.fBindTexture = glBindTexture_mozilla; michael@0: i->fFunctions.fBlendFunc = glBlendFunc_mozilla; michael@0: i->fFunctions.fBlendColor = glBlendColor_mozilla; michael@0: i->fFunctions.fBufferData = glBufferData_mozilla; michael@0: i->fFunctions.fBufferSubData = glBufferSubData_mozilla; michael@0: i->fFunctions.fCheckFramebufferStatus = glCheckFramebufferStatus_mozilla; michael@0: i->fFunctions.fClear = glClear_mozilla; michael@0: i->fFunctions.fClearColor = glClearColor_mozilla; michael@0: i->fFunctions.fClearStencil = glClearStencil_mozilla; michael@0: i->fFunctions.fColorMask = glColorMask_mozilla; michael@0: i->fFunctions.fCompileShader = glCompileShader_mozilla; michael@0: i->fFunctions.fCopyTexSubImage2D = glCopyTexSubImage2D_mozilla; michael@0: i->fFunctions.fCreateProgram = glCreateProgram_mozilla; michael@0: i->fFunctions.fCreateShader = glCreateShader_mozilla; michael@0: i->fFunctions.fCullFace = glCullFace_mozilla; michael@0: i->fFunctions.fDeleteBuffers = glDeleteBuffers_mozilla; michael@0: i->fFunctions.fDeleteFramebuffers = glDeleteFramebuffers_mozilla; michael@0: i->fFunctions.fDeleteProgram = glDeleteProgram_mozilla; michael@0: i->fFunctions.fDeleteRenderbuffers = glDeleteRenderbuffers_mozilla; michael@0: i->fFunctions.fDeleteShader = glDeleteShader_mozilla; michael@0: i->fFunctions.fDeleteTextures = glDeleteTextures_mozilla; michael@0: i->fFunctions.fDepthMask = glDepthMask_mozilla; michael@0: i->fFunctions.fDisable = glDisable_mozilla; michael@0: i->fFunctions.fDisableVertexAttribArray = glDisableVertexAttribArray_mozilla; michael@0: i->fFunctions.fDrawArrays = glDrawArrays_mozilla; michael@0: i->fFunctions.fDrawElements = glDrawElements_mozilla; michael@0: i->fFunctions.fEnable = glEnable_mozilla; michael@0: i->fFunctions.fEnableVertexAttribArray = glEnableVertexAttribArray_mozilla; michael@0: i->fFunctions.fFinish = glFinish_mozilla; michael@0: i->fFunctions.fFlush = glFlush_mozilla; michael@0: i->fFunctions.fFramebufferRenderbuffer = glFramebufferRenderbuffer_mozilla; michael@0: i->fFunctions.fFramebufferTexture2D = glFramebufferTexture2D_mozilla; michael@0: i->fFunctions.fFrontFace = glFrontFace_mozilla; michael@0: i->fFunctions.fGenBuffers = glGenBuffers_mozilla; michael@0: i->fFunctions.fGenFramebuffers = glGenFramebuffers_mozilla; michael@0: i->fFunctions.fGenRenderbuffers = glGenRenderbuffers_mozilla; michael@0: i->fFunctions.fGetFramebufferAttachmentParameteriv = glGetFramebufferAttachmentParameteriv_mozilla; michael@0: i->fFunctions.fGenTextures = glGenTextures_mozilla; michael@0: i->fFunctions.fGenerateMipmap = glGenerateMipmap_mozilla; michael@0: i->fFunctions.fGetBufferParameteriv = glGetBufferParameteriv_mozilla; michael@0: i->fFunctions.fGetError = glGetError_mozilla; michael@0: i->fFunctions.fGetIntegerv = glGetIntegerv_mozilla; michael@0: i->fFunctions.fGetProgramInfoLog = glGetProgramInfoLog_mozilla; michael@0: i->fFunctions.fGetProgramiv = glGetProgramiv_mozilla; michael@0: i->fFunctions.fGetRenderbufferParameteriv = glGetRenderbufferParameteriv_mozilla; michael@0: i->fFunctions.fGetShaderInfoLog = glGetShaderInfoLog_mozilla; michael@0: i->fFunctions.fGetShaderiv = glGetShaderiv_mozilla; michael@0: i->fFunctions.fGetString = glGetString_mozilla; michael@0: i->fFunctions.fGetUniformLocation = glGetUniformLocation_mozilla; michael@0: i->fFunctions.fLineWidth = glLineWidth_mozilla; michael@0: i->fFunctions.fLinkProgram = glLinkProgram_mozilla; michael@0: i->fFunctions.fPixelStorei = glPixelStorei_mozilla; michael@0: i->fFunctions.fReadPixels = glReadPixels_mozilla; michael@0: i->fFunctions.fRenderbufferStorage = glRenderbufferStorage_mozilla; michael@0: i->fFunctions.fScissor = glScissor_mozilla; michael@0: i->fFunctions.fShaderSource = glShaderSource_mozilla; michael@0: i->fFunctions.fStencilFunc = glStencilFunc_mozilla; michael@0: i->fFunctions.fStencilMask = glStencilMask_mozilla; michael@0: i->fFunctions.fStencilOp = glStencilOp_mozilla; michael@0: i->fFunctions.fTexImage2D = glTexImage2D_mozilla; michael@0: i->fFunctions.fTexParameteri = glTexParameteri_mozilla; michael@0: i->fFunctions.fTexParameteriv = glTexParameteriv_mozilla; michael@0: i->fFunctions.fTexSubImage2D = glTexSubImage2D_mozilla; michael@0: i->fFunctions.fUniform1f = glUniform1f_mozilla; michael@0: i->fFunctions.fUniform1i = glUniform1i_mozilla; michael@0: i->fFunctions.fUniform1fv = glUniform1fv_mozilla; michael@0: i->fFunctions.fUniform1iv = glUniform1iv_mozilla; michael@0: i->fFunctions.fUniform2f = glUniform2f_mozilla; michael@0: i->fFunctions.fUniform2i = glUniform2i_mozilla; michael@0: i->fFunctions.fUniform2fv = glUniform2fv_mozilla; michael@0: i->fFunctions.fUniform2iv = glUniform2iv_mozilla; michael@0: i->fFunctions.fUniform3f = glUniform3f_mozilla; michael@0: i->fFunctions.fUniform3i = glUniform3i_mozilla; michael@0: i->fFunctions.fUniform3fv = glUniform3fv_mozilla; michael@0: i->fFunctions.fUniform3iv = glUniform3iv_mozilla; michael@0: i->fFunctions.fUniform4f = glUniform4f_mozilla; michael@0: i->fFunctions.fUniform4i = glUniform4i_mozilla; michael@0: i->fFunctions.fUniform4fv = glUniform4fv_mozilla; michael@0: i->fFunctions.fUniform4iv = glUniform4iv_mozilla; michael@0: i->fFunctions.fUniformMatrix2fv = glUniformMatrix2fv_mozilla; michael@0: i->fFunctions.fUniformMatrix3fv = glUniformMatrix3fv_mozilla; michael@0: i->fFunctions.fUniformMatrix4fv = glUniformMatrix4fv_mozilla; michael@0: i->fFunctions.fUseProgram = glUseProgram_mozilla; michael@0: i->fFunctions.fVertexAttrib4fv = glVertexAttrib4fv_mozilla; michael@0: i->fFunctions.fVertexAttribPointer = glVertexAttribPointer_mozilla; michael@0: i->fFunctions.fViewport = glViewport_mozilla; michael@0: michael@0: // Required for either desktop OpenGL 2.0 or OpenGL ES 2.0 michael@0: i->fFunctions.fStencilFuncSeparate = glStencilFuncSeparate_mozilla; michael@0: i->fFunctions.fStencilMaskSeparate = glStencilMaskSeparate_mozilla; michael@0: i->fFunctions.fStencilOpSeparate = glStencilOpSeparate_mozilla; michael@0: michael@0: // GLContext supports glMapBuffer michael@0: i->fFunctions.fMapBuffer = glMapBuffer_mozilla; michael@0: i->fFunctions.fUnmapBuffer = glUnmapBuffer_mozilla; michael@0: michael@0: // GLContext supports glRenderbufferStorageMultisample/glBlitFramebuffer michael@0: i->fFunctions.fRenderbufferStorageMultisample = glRenderbufferStorageMultisample_mozilla; michael@0: i->fFunctions.fBlitFramebuffer = glBlitFramebuffer_mozilla; michael@0: michael@0: // GLContext supports glCompressedTexImage2D michael@0: i->fFunctions.fCompressedTexImage2D = glCompressedTexImage2D_mozilla; michael@0: michael@0: // GL_OES_vertex_array_object michael@0: i->fFunctions.fBindVertexArray = glBindVertexArray_mozilla; michael@0: i->fFunctions.fDeleteVertexArrays = glDeleteVertexArrays_mozilla; michael@0: i->fFunctions.fGenVertexArrays = glGenVertexArrays_mozilla; michael@0: michael@0: // Desktop GL michael@0: i->fFunctions.fGetTexLevelParameteriv = glGetTexLevelParameteriv_mozilla; michael@0: i->fFunctions.fDrawBuffer = glDrawBuffer_mozilla; michael@0: i->fFunctions.fReadBuffer = glReadBuffer_mozilla; michael@0: michael@0: // Desktop OpenGL > 1.5 michael@0: i->fFunctions.fGenQueries = glGenQueries_mozilla; michael@0: i->fFunctions.fDeleteQueries = glDeleteQueries_mozilla; michael@0: i->fFunctions.fBeginQuery = glBeginQuery_mozilla; michael@0: i->fFunctions.fEndQuery = glEndQuery_mozilla; michael@0: i->fFunctions.fGetQueryiv = glGetQueryiv_mozilla; michael@0: i->fFunctions.fGetQueryObjectiv = glGetQueryObjectiv_mozilla; michael@0: i->fFunctions.fGetQueryObjectuiv = glGetQueryObjectuiv_mozilla; michael@0: michael@0: // Desktop OpenGL > 2.0 michael@0: i->fFunctions.fDrawBuffers = glDrawBuffers_mozilla; michael@0: michael@0: // Desktop OpenGL < 3.2 (which we pretend to be) michael@0: i->fFunctions.fLoadIdentity = glLoadIdentity_mozilla; michael@0: i->fFunctions.fLoadMatrixf = glLoadMatrixf_mozilla; michael@0: i->fFunctions.fMatrixMode = glMatrixMode_mozilla; michael@0: i->fFunctions.fTexGenfv = glTexGenfv_mozilla; michael@0: i->fFunctions.fTexGeni = glTexGeni_mozilla; michael@0: michael@0: return i; michael@0: } michael@0: michael@0: SkiaGLGlue::SkiaGLGlue(GLContext* context) michael@0: : mGLContext(context) michael@0: { michael@0: SkAutoTUnref i(CreateGrGLInterfaceFromGLContext(mGLContext)); michael@0: i->fCallbackData = reinterpret_cast(this); michael@0: mGrGLInterface = i; michael@0: SkAutoTUnref gr(GrContext::Create(kOpenGL_GrBackend, (GrBackendContext)mGrGLInterface.get())); michael@0: michael@0: mGrContext = gr; michael@0: }