gfx/gl/SkiaGLGlue.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/gl/SkiaGLGlue.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,937 @@
     1.4 +/* -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40; -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "skia/GrContext.h"
    1.10 +#include "skia/GrGLInterface.h"
    1.11 +#include "mozilla/gfx/2D.h"
    1.12 +#include "mozilla/ThreadLocal.h"
    1.13 +#include "mozilla/DebugOnly.h"
    1.14 +
    1.15 +/* SkPostConfig.h includes windows.h, which includes windef.h
    1.16 + * which redefines min/max. We don't want that. */
    1.17 +#ifdef _WIN32
    1.18 +#undef min
    1.19 +#undef max
    1.20 +#endif
    1.21 +
    1.22 +#include "GLContext.h"
    1.23 +#include "SkiaGLGlue.h"
    1.24 +
    1.25 +using mozilla::gl::GLContext;
    1.26 +using mozilla::gl::GLFeature;
    1.27 +using mozilla::gl::SkiaGLGlue;
    1.28 +using mozilla::gfx::DrawTarget;
    1.29 +
    1.30 +static mozilla::ThreadLocal<GLContext*> sGLContext;
    1.31 +
    1.32 +extern "C" {
    1.33 +
    1.34 +static void SetStaticGLContext(GLContext* context)
    1.35 +{
    1.36 +    if (!sGLContext.initialized()) {
    1.37 +      mozilla::DebugOnly<bool> success = sGLContext.init();
    1.38 +      MOZ_ASSERT(success);
    1.39 +    }
    1.40 +
    1.41 +    sGLContext.set(context);
    1.42 +}
    1.43 +
    1.44 +void EnsureGLContext(const GrGLInterface* i)
    1.45 +{
    1.46 +    const SkiaGLGlue* contextSkia = reinterpret_cast<const SkiaGLGlue*>(i->fCallbackData);
    1.47 +    MOZ_ASSERT(contextSkia);
    1.48 +    GLContext* gl = contextSkia->GetGLContext();
    1.49 +    gl->MakeCurrent();
    1.50 +    SetStaticGLContext(gl);
    1.51 +}
    1.52 +
    1.53 +// Core GL functions required by Ganesh
    1.54 +
    1.55 +GrGLvoid glActiveTexture_mozilla(GrGLenum texture)
    1.56 +{
    1.57 +    return sGLContext.get()->fActiveTexture(texture);
    1.58 +}
    1.59 +
    1.60 +GrGLvoid glAttachShader_mozilla(GrGLuint program, GrGLuint shader)
    1.61 +{
    1.62 +    return sGLContext.get()->fAttachShader(program, shader);
    1.63 +}
    1.64 +
    1.65 +GrGLvoid glBindAttribLocation_mozilla(GrGLuint program, GrGLuint index, const GLchar* name)
    1.66 +{
    1.67 +    return sGLContext.get()->fBindAttribLocation(program, index, name);
    1.68 +}
    1.69 +
    1.70 +GrGLvoid glBindBuffer_mozilla(GrGLenum target, GrGLuint buffer)
    1.71 +{
    1.72 +    return sGLContext.get()->fBindBuffer(target, buffer);
    1.73 +}
    1.74 +
    1.75 +GrGLvoid glBindFramebuffer_mozilla(GrGLenum target, GrGLuint framebuffer)
    1.76 +{
    1.77 +    return sGLContext.get()->fBindFramebuffer(target, framebuffer);
    1.78 +}
    1.79 +
    1.80 +GrGLvoid glBindRenderbuffer_mozilla(GrGLenum target, GrGLuint renderbuffer)
    1.81 +{
    1.82 +    return sGLContext.get()->fBindRenderbuffer(target, renderbuffer);
    1.83 +}
    1.84 +
    1.85 +GrGLvoid glBindTexture_mozilla(GrGLenum target, GrGLuint texture)
    1.86 +{
    1.87 +    return sGLContext.get()->fBindTexture(target, texture);
    1.88 +}
    1.89 +
    1.90 +GrGLvoid glBlendColor_mozilla(GrGLclampf red, GrGLclampf green, GrGLclampf blue, GrGLclampf alpha)
    1.91 +{
    1.92 +    return sGLContext.get()->fBlendColor(red, green, blue, alpha);
    1.93 +}
    1.94 +
    1.95 +GrGLvoid glBlendFunc_mozilla(GrGLenum sfactor, GrGLenum dfactor)
    1.96 +{
    1.97 +    return sGLContext.get()->fBlendFunc(sfactor, dfactor);
    1.98 +}
    1.99 +
   1.100 +GrGLvoid glBufferData_mozilla(GrGLenum target, GrGLsizeiptr size, const void* data, GrGLenum usage)
   1.101 +{
   1.102 +    return sGLContext.get()->fBufferData(target, size, data, usage);
   1.103 +}
   1.104 +
   1.105 +GrGLvoid glBufferSubData_mozilla(GrGLenum target, GrGLintptr offset, GrGLsizeiptr size, const void* data)
   1.106 +{
   1.107 +    return sGLContext.get()->fBufferSubData(target, offset, size, data);
   1.108 +}
   1.109 +
   1.110 +GrGLenum glCheckFramebufferStatus_mozilla(GrGLenum target)
   1.111 +{
   1.112 +    return sGLContext.get()->fCheckFramebufferStatus(target);
   1.113 +}
   1.114 +
   1.115 +GrGLvoid glClear_mozilla(GrGLbitfield mask)
   1.116 +{
   1.117 +    return sGLContext.get()->fClear(mask);
   1.118 +}
   1.119 +
   1.120 +GrGLvoid glClearColor_mozilla(GrGLclampf red, GrGLclampf green, GrGLclampf blue, GrGLclampf alpha)
   1.121 +{
   1.122 +    return sGLContext.get()->fClearColor(red, green, blue, alpha);
   1.123 +}
   1.124 +
   1.125 +GrGLvoid glClearStencil_mozilla(GrGLint s)
   1.126 +{
   1.127 +    return sGLContext.get()->fClearStencil(s);
   1.128 +}
   1.129 +
   1.130 +GrGLvoid glColorMask_mozilla(GrGLboolean red, GrGLboolean green, GrGLboolean blue, GrGLboolean alpha)
   1.131 +{
   1.132 +    return sGLContext.get()->fColorMask(red, green, blue, alpha);
   1.133 +}
   1.134 +
   1.135 +GrGLvoid glCompileShader_mozilla(GrGLuint shader)
   1.136 +{
   1.137 +    return sGLContext.get()->fCompileShader(shader);
   1.138 +}
   1.139 +
   1.140 +GrGLvoid glCopyTexSubImage2D_mozilla(GrGLenum target, GrGLint level, GrGLint xoffset, GrGLint yoffset,
   1.141 +                                     GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height)
   1.142 +{
   1.143 +    return sGLContext.get()->fCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
   1.144 +}
   1.145 +
   1.146 +GrGLuint glCreateProgram_mozilla(void)
   1.147 +{
   1.148 +    return sGLContext.get()->fCreateProgram();
   1.149 +}
   1.150 +
   1.151 +GrGLuint glCreateShader_mozilla(GrGLenum type)
   1.152 +{
   1.153 +    return sGLContext.get()->fCreateShader(type);
   1.154 +}
   1.155 +
   1.156 +GrGLvoid glCullFace_mozilla(GrGLenum mode)
   1.157 +{
   1.158 +    return sGLContext.get()->fCullFace(mode);
   1.159 +}
   1.160 +
   1.161 +GrGLvoid glDeleteBuffers_mozilla(GrGLsizei n, const GrGLuint* buffers)
   1.162 +{
   1.163 +    return sGLContext.get()->fDeleteBuffers(n, buffers);
   1.164 +}
   1.165 +
   1.166 +GrGLvoid glDeleteFramebuffers_mozilla(GrGLsizei n, const GrGLuint* framebuffers)
   1.167 +{
   1.168 +    return sGLContext.get()->fDeleteFramebuffers(n, framebuffers);
   1.169 +}
   1.170 +
   1.171 +GrGLvoid glDeleteProgram_mozilla(GrGLuint program)
   1.172 +{
   1.173 +    return sGLContext.get()->fDeleteProgram(program);
   1.174 +}
   1.175 +
   1.176 +GrGLvoid glDeleteRenderbuffers_mozilla(GrGLsizei n, const GrGLuint* renderbuffers)
   1.177 +{
   1.178 +    return sGLContext.get()->fDeleteRenderbuffers(n, renderbuffers);
   1.179 +}
   1.180 +
   1.181 +GrGLvoid glDeleteShader_mozilla(GrGLuint shader)
   1.182 +{
   1.183 +    return sGLContext.get()->fDeleteShader(shader);
   1.184 +}
   1.185 +
   1.186 +GrGLvoid glDeleteTextures_mozilla(GrGLsizei n, const GrGLuint* textures)
   1.187 +{
   1.188 +    return sGLContext.get()->fDeleteTextures(n, textures);
   1.189 +}
   1.190 +
   1.191 +GrGLvoid glDepthMask_mozilla(GrGLboolean flag)
   1.192 +{
   1.193 +    return sGLContext.get()->fDepthMask(flag);
   1.194 +}
   1.195 +
   1.196 +GrGLvoid glDisable_mozilla(GrGLenum cap)
   1.197 +{
   1.198 +    return sGLContext.get()->fDisable(cap);
   1.199 +}
   1.200 +
   1.201 +GrGLvoid glDisableVertexAttribArray_mozilla(GrGLuint index)
   1.202 +{
   1.203 +    return sGLContext.get()->fDisableVertexAttribArray(index);
   1.204 +}
   1.205 +
   1.206 +GrGLvoid glDrawArrays_mozilla(GrGLenum mode, GrGLint first, GrGLsizei count)
   1.207 +{
   1.208 +    return sGLContext.get()->fDrawArrays(mode, first, count);
   1.209 +}
   1.210 +
   1.211 +GrGLvoid glDrawElements_mozilla(GrGLenum mode, GrGLsizei count, GrGLenum type, const void* indices)
   1.212 +{
   1.213 +    return sGLContext.get()->fDrawElements(mode, count, type, indices);
   1.214 +}
   1.215 +
   1.216 +GrGLvoid glEnable_mozilla(GrGLenum cap)
   1.217 +{
   1.218 +    return sGLContext.get()->fEnable(cap);
   1.219 +}
   1.220 +
   1.221 +GrGLvoid glEnableVertexAttribArray_mozilla(GrGLuint index)
   1.222 +{
   1.223 +    return sGLContext.get()->fEnableVertexAttribArray(index);
   1.224 +}
   1.225 +
   1.226 +GrGLvoid glFinish_mozilla()
   1.227 +{
   1.228 +    return sGLContext.get()->fFinish();
   1.229 +}
   1.230 +
   1.231 +GrGLvoid glFlush_mozilla()
   1.232 +{
   1.233 +    return sGLContext.get()->fFlush();
   1.234 +}
   1.235 +
   1.236 +GrGLvoid glFramebufferRenderbuffer_mozilla(GrGLenum target, GrGLenum attachment, GrGLenum renderbuffertarget, GrGLuint renderbuffer)
   1.237 +{
   1.238 +    return sGLContext.get()->fFramebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer);
   1.239 +}
   1.240 +
   1.241 +GrGLvoid glFramebufferTexture2D_mozilla(GrGLenum target, GrGLenum attachment, GrGLenum textarget, GrGLuint texture, GrGLint level)
   1.242 +{
   1.243 +    return sGLContext.get()->fFramebufferTexture2D(target, attachment, textarget, texture, level);
   1.244 +}
   1.245 +
   1.246 +GrGLvoid glFrontFace_mozilla(GrGLenum mode)
   1.247 +{
   1.248 +    return sGLContext.get()->fFrontFace(mode);
   1.249 +}
   1.250 +
   1.251 +GrGLvoid glGenBuffers_mozilla(GrGLsizei n, GrGLuint* buffers)
   1.252 +{
   1.253 +    return sGLContext.get()->fGenBuffers(n, buffers);
   1.254 +}
   1.255 +
   1.256 +GrGLvoid glGenFramebuffers_mozilla(GrGLsizei n, GrGLuint* framebuffers)
   1.257 +{
   1.258 +    return sGLContext.get()->fGenFramebuffers(n, framebuffers);
   1.259 +}
   1.260 +
   1.261 +GrGLvoid glGenRenderbuffers_mozilla(GrGLsizei n, GrGLuint* renderbuffers)
   1.262 +{
   1.263 +    return sGLContext.get()->fGenRenderbuffers(n, renderbuffers);
   1.264 +}
   1.265 +
   1.266 +GrGLvoid glGenTextures_mozilla(GrGLsizei n, GrGLuint* textures)
   1.267 +{
   1.268 +    return sGLContext.get()->fGenTextures(n, textures);
   1.269 +}
   1.270 +
   1.271 +GrGLvoid glGenerateMipmap_mozilla(GrGLenum target)
   1.272 +{
   1.273 +    return sGLContext.get()->fGenerateMipmap(target);
   1.274 +}
   1.275 +
   1.276 +GrGLvoid glGetBufferParameteriv_mozilla(GrGLenum target, GrGLenum pname, GrGLint* params)
   1.277 +{
   1.278 +    return sGLContext.get()->fGetBufferParameteriv(target, pname, params);
   1.279 +}
   1.280 +
   1.281 +GrGLvoid glGetFramebufferAttachmentParameteriv_mozilla(GrGLenum target, GrGLenum attachment, GrGLenum pname, GrGLint* params)
   1.282 +{
   1.283 +    return sGLContext.get()->fGetFramebufferAttachmentParameteriv(target, attachment, pname, params);
   1.284 +}
   1.285 +
   1.286 +GrGLenum glGetError_mozilla()
   1.287 +{
   1.288 +    return sGLContext.get()->fGetError();
   1.289 +}
   1.290 +
   1.291 +GrGLvoid glGetIntegerv_mozilla(GrGLenum pname, GrGLint* params)
   1.292 +{
   1.293 +    return sGLContext.get()->fGetIntegerv(pname, params);
   1.294 +}
   1.295 +
   1.296 +GrGLvoid glGetProgramInfoLog_mozilla(GrGLuint program, GrGLsizei bufsize, GrGLsizei* length, char* infolog)
   1.297 +{
   1.298 +    return sGLContext.get()->fGetProgramInfoLog(program, bufsize, length, infolog);
   1.299 +}
   1.300 +
   1.301 +GrGLvoid glGetProgramiv_mozilla(GrGLuint program, GrGLenum pname, GrGLint* params)
   1.302 +{
   1.303 +    return sGLContext.get()->fGetProgramiv(program, pname, params);
   1.304 +}
   1.305 +
   1.306 +GrGLvoid glGetRenderbufferParameteriv_mozilla(GrGLenum target, GrGLenum pname, GrGLint* params)
   1.307 +{
   1.308 +    return sGLContext.get()->fGetRenderbufferParameteriv(target, pname, params);
   1.309 +}
   1.310 +
   1.311 +GrGLvoid glGetShaderInfoLog_mozilla(GrGLuint shader, GrGLsizei bufsize, GrGLsizei* length, char* infolog)
   1.312 +{
   1.313 +    return sGLContext.get()->fGetShaderInfoLog(shader, bufsize, length, infolog);
   1.314 +}
   1.315 +
   1.316 +GrGLvoid glGetShaderiv_mozilla(GrGLuint shader, GrGLenum pname, GrGLint* params)
   1.317 +{
   1.318 +    return sGLContext.get()->fGetShaderiv(shader, pname, params);
   1.319 +}
   1.320 +
   1.321 +const GLubyte* glGetString_mozilla(GrGLenum name)
   1.322 +{
   1.323 +    // GLContext only exposes a OpenGL 2.0 style API, so we have to intercept a bunch
   1.324 +    // of checks that Ganesh makes to determine which capabilities are present
   1.325 +    // on the GL implementation and change them to match what GLContext actually exposes.
   1.326 +
   1.327 +    if (name == LOCAL_GL_VERSION) {
   1.328 +        if (sGLContext.get()->IsGLES()) {
   1.329 +            return reinterpret_cast<const GLubyte*>("OpenGL ES 2.0");
   1.330 +        } else {
   1.331 +            return reinterpret_cast<const GLubyte*>("2.0");
   1.332 +        }
   1.333 +    } else if (name == LOCAL_GL_EXTENSIONS) {
   1.334 +        // Only expose the bare minimum extensions we want to support to ensure a functional Ganesh
   1.335 +        // as GLContext only exposes certain extensions
   1.336 +        static bool extensionsStringBuilt = false;
   1.337 +        static char extensionsString[1024];
   1.338 +
   1.339 +        if (!extensionsStringBuilt) {
   1.340 +            extensionsString[0] = '\0';
   1.341 +
   1.342 +            if (sGLContext.get()->IsGLES()) {
   1.343 +                // OES is only applicable to GLES2
   1.344 +                if (sGLContext.get()->IsExtensionSupported(GLContext::OES_packed_depth_stencil)) {
   1.345 +                    strcat(extensionsString, "GL_OES_packed_depth_stencil ");
   1.346 +                }
   1.347 +
   1.348 +                if (sGLContext.get()->IsExtensionSupported(GLContext::OES_rgb8_rgba8)) {
   1.349 +                    strcat(extensionsString, "GL_OES_rgb8_rgba8 ");
   1.350 +                }
   1.351 +
   1.352 +                if (sGLContext.get()->IsExtensionSupported(GLContext::OES_texture_npot)) {
   1.353 +                    strcat(extensionsString, "GL_OES_texture_npot ");
   1.354 +                }
   1.355 +
   1.356 +                if (sGLContext.get()->IsExtensionSupported(GLContext::OES_vertex_array_object)) {
   1.357 +                    strcat(extensionsString, "GL_OES_vertex_array_object ");
   1.358 +                }
   1.359 +
   1.360 +                if (sGLContext.get()->IsSupported(GLFeature::standard_derivatives)) {
   1.361 +                    strcat(extensionsString, "GL_OES_standard_derivatives ");
   1.362 +                }
   1.363 +            }
   1.364 +
   1.365 +            if (sGLContext.get()->IsExtensionSupported(GLContext::EXT_texture_format_BGRA8888)) {
   1.366 +                strcat(extensionsString, "GL_EXT_texture_format_BGRA8888 ");
   1.367 +            }
   1.368 +
   1.369 +            if (sGLContext.get()->IsExtensionSupported(GLContext::EXT_packed_depth_stencil)) {
   1.370 +                strcat(extensionsString, "GL_EXT_packed_depth_stencil ");
   1.371 +            }
   1.372 +
   1.373 +            if (sGLContext.get()->IsExtensionSupported(GLContext::EXT_bgra)) {
   1.374 +                strcat(extensionsString, "GL_EXT_bgra ");
   1.375 +            }
   1.376 +
   1.377 +            if (sGLContext.get()->IsExtensionSupported(GLContext::EXT_read_format_bgra)) {
   1.378 +                strcat(extensionsString, "GL_EXT_read_format_bgra ");
   1.379 +            }
   1.380 +
   1.381 +            extensionsStringBuilt = true;
   1.382 +#ifdef DEBUG
   1.383 +            printf_stderr("Exported SkiaGL extensions: %s\n", extensionsString);
   1.384 +#endif
   1.385 +        }
   1.386 +
   1.387 +        return reinterpret_cast<const GLubyte*>(extensionsString);
   1.388 +
   1.389 +    } else if (name == LOCAL_GL_SHADING_LANGUAGE_VERSION) {
   1.390 +        if (sGLContext.get()->IsGLES()) {
   1.391 +            return reinterpret_cast<const GLubyte*>("OpenGL ES GLSL ES 1.0");
   1.392 +        } else {
   1.393 +            return reinterpret_cast<const GLubyte*>("1.10");
   1.394 +        }
   1.395 +    }
   1.396 +
   1.397 +    return sGLContext.get()->fGetString(name);
   1.398 +}
   1.399 +
   1.400 +GrGLint glGetUniformLocation_mozilla(GrGLuint program, const char* name)
   1.401 +{
   1.402 +    return sGLContext.get()->fGetUniformLocation(program, name);
   1.403 +}
   1.404 +
   1.405 +GrGLvoid glLineWidth_mozilla(GrGLfloat width)
   1.406 +{
   1.407 +    return sGLContext.get()->fLineWidth(width);
   1.408 +}
   1.409 +
   1.410 +GrGLvoid glLinkProgram_mozilla(GrGLuint program)
   1.411 +{
   1.412 +    return sGLContext.get()->fLinkProgram(program);
   1.413 +}
   1.414 +
   1.415 +GrGLvoid glPixelStorei_mozilla(GrGLenum pname, GrGLint param)
   1.416 +{
   1.417 +    return sGLContext.get()->fPixelStorei(pname, param);
   1.418 +}
   1.419 +
   1.420 +GrGLvoid glReadPixels_mozilla(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height,
   1.421 +                              GrGLenum format, GrGLenum type, void* pixels)
   1.422 +{
   1.423 +    return sGLContext.get()->fReadPixels(x, y, width, height,
   1.424 +                                   format, type, pixels);
   1.425 +}
   1.426 +
   1.427 +GrGLvoid glRenderbufferStorage_mozilla(GrGLenum target, GrGLenum internalformat, GrGLsizei width, GrGLsizei height)
   1.428 +{
   1.429 +    return sGLContext.get()->fRenderbufferStorage(target, internalformat, width, height);
   1.430 +}
   1.431 +
   1.432 +GrGLvoid glScissor_mozilla(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height)
   1.433 +{
   1.434 +    return sGLContext.get()->fScissor(x, y, width, height);
   1.435 +}
   1.436 +
   1.437 +GrGLvoid glShaderSource_mozilla(GrGLuint shader, GrGLsizei count, const char** str, const GrGLint* length)
   1.438 +{
   1.439 +    return sGLContext.get()->fShaderSource(shader, count, str, length);
   1.440 +}
   1.441 +
   1.442 +GrGLvoid glStencilFunc_mozilla(GrGLenum func, GrGLint ref, GrGLuint mask)
   1.443 +{
   1.444 +    return sGLContext.get()->fStencilFunc(func, ref, mask);
   1.445 +}
   1.446 +
   1.447 +GrGLvoid glStencilMask_mozilla(GrGLuint mask)
   1.448 +{
   1.449 +    return sGLContext.get()->fStencilMask(mask);
   1.450 +}
   1.451 +
   1.452 +GrGLvoid glStencilOp_mozilla(GrGLenum fail, GrGLenum zfail, GrGLenum zpass)
   1.453 +{
   1.454 +    return sGLContext.get()->fStencilOp(fail, zfail, zpass);
   1.455 +}
   1.456 +
   1.457 +GrGLvoid glTexImage2D_mozilla(GrGLenum target, GrGLint level, GrGLint internalformat,
   1.458 +                              GrGLsizei width, GrGLsizei height, GrGLint border,
   1.459 +                              GrGLenum format, GrGLenum type, const void* pixels)
   1.460 +{
   1.461 +    return sGLContext.get()->fTexImage2D(target, level, internalformat,
   1.462 +                                   width, height, border,
   1.463 +                                   format, type, pixels);
   1.464 +}
   1.465 +
   1.466 +GrGLvoid glTexParameteri_mozilla(GrGLenum target, GrGLenum pname, GrGLint param)
   1.467 +{
   1.468 +    return sGLContext.get()->fTexParameteri(target, pname, param);
   1.469 +}
   1.470 +
   1.471 +GrGLvoid glTexParameteriv_mozilla(GrGLenum target, GrGLenum pname, const GrGLint* params)
   1.472 +{
   1.473 +    return sGLContext.get()->fTexParameteriv(target, pname, params);
   1.474 +}
   1.475 +
   1.476 +GrGLvoid glTexSubImage2D_mozilla(GrGLenum target, GrGLint level,
   1.477 +                                 GrGLint xoffset, GrGLint yoffset,
   1.478 +                                 GrGLsizei width, GrGLsizei height,
   1.479 +                                 GrGLenum format, GrGLenum type, const void* pixels)
   1.480 +{
   1.481 +    return sGLContext.get()->fTexSubImage2D(target, level,
   1.482 +                                      xoffset, yoffset,
   1.483 +                                      width, height,
   1.484 +                                      format, type, pixels);
   1.485 +}
   1.486 +
   1.487 +GrGLvoid glUniform1f_mozilla(GrGLint location, GrGLfloat v)
   1.488 +{
   1.489 +    return sGLContext.get()->fUniform1f(location, v);
   1.490 +}
   1.491 +
   1.492 +GrGLvoid glUniform1i_mozilla(GrGLint location, GrGLint v)
   1.493 +{
   1.494 +    return sGLContext.get()->fUniform1i(location, v);
   1.495 +}
   1.496 +
   1.497 +GrGLvoid glUniform1fv_mozilla(GrGLint location, GrGLsizei count, const GrGLfloat* v)
   1.498 +{
   1.499 +    return sGLContext.get()->fUniform1fv(location, count, v);
   1.500 +}
   1.501 +
   1.502 +GrGLvoid glUniform1iv_mozilla(GrGLint location, GrGLsizei count, const GrGLint* v)
   1.503 +{
   1.504 +    return sGLContext.get()->fUniform1iv(location, count, v);
   1.505 +}
   1.506 +
   1.507 +GrGLvoid glUniform2f_mozilla(GrGLint location, GrGLfloat v0, GrGLfloat v1)
   1.508 +{
   1.509 +    return sGLContext.get()->fUniform2f(location, v0, v1);
   1.510 +}
   1.511 +
   1.512 +GrGLvoid glUniform2i_mozilla(GrGLint location, GrGLint v0, GrGLint v1)
   1.513 +{
   1.514 +    return sGLContext.get()->fUniform2i(location, v0, v1);
   1.515 +}
   1.516 +
   1.517 +GrGLvoid glUniform2fv_mozilla(GrGLint location, GrGLsizei count, const GrGLfloat* v)
   1.518 +{
   1.519 +    return sGLContext.get()->fUniform2fv(location, count, v);
   1.520 +}
   1.521 +
   1.522 +GrGLvoid glUniform2iv_mozilla(GrGLint location, GrGLsizei count, const GrGLint* v)
   1.523 +{
   1.524 +    return sGLContext.get()->fUniform2iv(location, count, v);
   1.525 +}
   1.526 +
   1.527 +GrGLvoid glUniform3f_mozilla(GrGLint location, GrGLfloat v0, GrGLfloat v1, GrGLfloat v2)
   1.528 +{
   1.529 +    return sGLContext.get()->fUniform3f(location, v0, v1, v2);
   1.530 +}
   1.531 +
   1.532 +GrGLvoid glUniform3i_mozilla(GrGLint location, GrGLint v0, GrGLint v1, GrGLint v2)
   1.533 +{
   1.534 +    return sGLContext.get()->fUniform3i(location, v0, v1, v2);
   1.535 +}
   1.536 +
   1.537 +GrGLvoid glUniform3fv_mozilla(GrGLint location, GrGLsizei count, const GrGLfloat* v)
   1.538 +{
   1.539 +    return sGLContext.get()->fUniform3fv(location, count, v);
   1.540 +}
   1.541 +
   1.542 +GrGLvoid glUniform3iv_mozilla(GrGLint location, GrGLsizei count, const GrGLint* v)
   1.543 +{
   1.544 +    return sGLContext.get()->fUniform3iv(location, count, v);
   1.545 +}
   1.546 +
   1.547 +GrGLvoid glUniform4f_mozilla(GrGLint location, GrGLfloat v0, GrGLfloat v1, GrGLfloat v2, GrGLfloat v3)
   1.548 +{
   1.549 +    return sGLContext.get()->fUniform4f(location, v0, v1, v2, v3);
   1.550 +}
   1.551 +
   1.552 +GrGLvoid glUniform4i_mozilla(GrGLint location, GrGLint v0, GrGLint v1, GrGLint v2, GrGLint v3)
   1.553 +{
   1.554 +    return sGLContext.get()->fUniform4i(location, v0, v1, v2, v3);
   1.555 +}
   1.556 +
   1.557 +GrGLvoid glUniform4fv_mozilla(GrGLint location, GrGLsizei count, const GrGLfloat* v)
   1.558 +{
   1.559 +    return sGLContext.get()->fUniform4fv(location, count, v);
   1.560 +}
   1.561 +
   1.562 +GrGLvoid glUniform4iv_mozilla(GrGLint location, GrGLsizei count, const GrGLint* v)
   1.563 +{
   1.564 +    return sGLContext.get()->fUniform4iv(location, count, v);
   1.565 +}
   1.566 +
   1.567 +GrGLvoid glUniformMatrix2fv_mozilla(GrGLint location, GrGLsizei count, GrGLboolean transpose, const GrGLfloat* value)
   1.568 +{
   1.569 +    return sGLContext.get()->fUniformMatrix2fv(location, count, transpose, value);
   1.570 +}
   1.571 +
   1.572 +GrGLvoid glUniformMatrix3fv_mozilla(GrGLint location, GrGLsizei count, GrGLboolean transpose, const GrGLfloat* value)
   1.573 +{
   1.574 +    return sGLContext.get()->fUniformMatrix3fv(location, count, transpose, value);
   1.575 +}
   1.576 +
   1.577 +GrGLvoid glUniformMatrix4fv_mozilla(GrGLint location, GrGLsizei count, GrGLboolean transpose, const GrGLfloat* value)
   1.578 +{
   1.579 +    return sGLContext.get()->fUniformMatrix4fv(location, count, transpose, value);
   1.580 +}
   1.581 +
   1.582 +GrGLvoid glUseProgram_mozilla(GrGLuint program)
   1.583 +{
   1.584 +    return sGLContext.get()->fUseProgram(program);
   1.585 +}
   1.586 +
   1.587 +GrGLvoid glVertexAttrib4fv_mozilla(GrGLuint index, const GrGLfloat* values)
   1.588 +{
   1.589 +    return sGLContext.get()->fVertexAttrib4fv(index, values);
   1.590 +}
   1.591 +
   1.592 +GrGLvoid glVertexAttribPointer_mozilla(GrGLuint index, GrGLint size, GrGLenum type, GrGLboolean normalized, GrGLsizei stride, const void* ptr)
   1.593 +{
   1.594 +    return sGLContext.get()->fVertexAttribPointer(index, size, type, normalized, stride, ptr);
   1.595 +}
   1.596 +
   1.597 +GrGLvoid glViewport_mozilla(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height)
   1.598 +{
   1.599 +    return sGLContext.get()->fViewport(x, y, width, height);
   1.600 +}
   1.601 +
   1.602 +// Required if the bindings are GLES2 or desktop OpenGL 2.0
   1.603 +
   1.604 +GrGLvoid glStencilFuncSeparate_mozilla(GrGLenum frontfunc, GrGLenum backfunc, GrGLint ref, GrGLuint mask)
   1.605 +{
   1.606 +    return sGLContext.get()->fStencilFuncSeparate(frontfunc, backfunc, ref, mask);
   1.607 +}
   1.608 +
   1.609 +GrGLvoid glStencilMaskSeparate_mozilla(GrGLenum face, GrGLuint mask)
   1.610 +{
   1.611 +    return sGLContext.get()->fStencilMaskSeparate(face, mask);
   1.612 +}
   1.613 +
   1.614 +GrGLvoid glStencilOpSeparate_mozilla(GrGLenum face, GrGLenum sfail, GrGLenum dpfail, GrGLenum dppass)
   1.615 +{
   1.616 +    return sGLContext.get()->fStencilOpSeparate(face, sfail, dpfail, dppass);
   1.617 +}
   1.618 +
   1.619 +// Not in GLES2
   1.620 +
   1.621 +GrGLvoid glGetTexLevelParameteriv_mozilla(GrGLenum target, GrGLint level, GrGLenum pname, GrGLint *params)
   1.622 +{
   1.623 +    return sGLContext.get()->fGetTexLevelParameteriv(target, level, pname, params);
   1.624 +}
   1.625 +
   1.626 +GrGLvoid glDrawBuffer_mozilla(GrGLenum mode)
   1.627 +{
   1.628 +    return sGLContext.get()->fDrawBuffer(mode);
   1.629 +}
   1.630 +
   1.631 +GrGLvoid glReadBuffer_mozilla(GrGLenum mode)
   1.632 +{
   1.633 +    return sGLContext.get()->fReadBuffer(mode);
   1.634 +}
   1.635 +
   1.636 +// Desktop OpenGL version >= 1.5
   1.637 +
   1.638 +GrGLvoid glGenQueries_mozilla(GrGLsizei n, GrGLuint* ids)
   1.639 +{
   1.640 +    return sGLContext.get()->fGenQueries(n, ids);
   1.641 +}
   1.642 +
   1.643 +GrGLvoid glDeleteQueries_mozilla(GrGLsizei n, const GrGLuint* ids)
   1.644 +{
   1.645 +    return sGLContext.get()->fDeleteQueries(n, ids);
   1.646 +}
   1.647 +
   1.648 +GrGLvoid glBeginQuery_mozilla(GrGLenum target, GrGLuint id)
   1.649 +{
   1.650 +    return sGLContext.get()->fBeginQuery(target, id);
   1.651 +}
   1.652 +
   1.653 +GrGLvoid glEndQuery_mozilla(GrGLenum target)
   1.654 +{
   1.655 +    return sGLContext.get()->fEndQuery(target);
   1.656 +}
   1.657 +
   1.658 +GrGLvoid glGetQueryiv_mozilla(GrGLenum target, GrGLenum pname, GrGLint* params)
   1.659 +{
   1.660 +    return sGLContext.get()->fGetQueryiv(target, pname, params);
   1.661 +}
   1.662 +
   1.663 +GrGLvoid glGetQueryObjectiv_mozilla(GrGLuint id, GrGLenum pname, GrGLint* params)
   1.664 +{
   1.665 +    return sGLContext.get()->fGetQueryObjectiv(id, pname, params);
   1.666 +}
   1.667 +
   1.668 +GrGLvoid glGetQueryObjectuiv_mozilla(GrGLuint id, GrGLenum pname, GrGLuint* params)
   1.669 +{
   1.670 +    return sGLContext.get()->fGetQueryObjectuiv(id, pname, params);
   1.671 +}
   1.672 +
   1.673 +// Desktop OpenGL version >= 2.0
   1.674 +
   1.675 +GrGLvoid glDrawBuffers_mozilla(GrGLsizei n, const GrGLenum* bufs)
   1.676 +{
   1.677 +    return sGLContext.get()->fDrawBuffers(n, bufs);
   1.678 +}
   1.679 +
   1.680 +// GLContext supports glMapBuffer on everything (GL_OES_mapbuffer)
   1.681 +
   1.682 +GrGLvoid* glMapBuffer_mozilla(GrGLenum target, GrGLenum access)
   1.683 +{
   1.684 +    return sGLContext.get()->fMapBuffer(target, access);
   1.685 +}
   1.686 +
   1.687 +GrGLboolean glUnmapBuffer_mozilla(GrGLenum target)
   1.688 +{
   1.689 +    return sGLContext.get()->fUnmapBuffer(target);
   1.690 +}
   1.691 +
   1.692 +// GLContext supports glCompressedTexImage2D (GL_ARB_texture_compression)
   1.693 +
   1.694 +GrGLvoid glCompressedTexImage2D_mozilla(GrGLenum target, GrGLint level, GrGLenum internalformat,
   1.695 +                                        GrGLsizei width, GrGLsizei height, GrGLint border,
   1.696 +                                        GrGLsizei imageSize, const GrGLvoid* pixels)
   1.697 +{
   1.698 +    return sGLContext.get()->fCompressedTexImage2D(target, level, internalformat,
   1.699 +                                             width, height, border,
   1.700 +                                             imageSize, pixels);
   1.701 +}
   1.702 +
   1.703 +// GLContext supports glBlitFramebuffer/glRenderbufferStorageMultisample (GL_ARB_framebuffer_object)
   1.704 +
   1.705 +GrGLvoid glRenderbufferStorageMultisample_mozilla(GrGLenum target, GrGLsizei samples, GrGLenum internalformat,
   1.706 +                                                  GrGLsizei width, GrGLsizei height)
   1.707 +{
   1.708 +    return sGLContext.get()->fRenderbufferStorageMultisample(target, samples, internalformat,
   1.709 +                                                       width, height);
   1.710 +}
   1.711 +
   1.712 +GrGLvoid glBlitFramebuffer_mozilla(GrGLint srcX0, GrGLint srcY0,
   1.713 +                                   GrGLint srcX1, GrGLint srcY1,
   1.714 +                                   GrGLint dstX0, GrGLint dstY0,
   1.715 +                                   GrGLint dstX1, GrGLint dstY1,
   1.716 +                                   GrGLbitfield mask, GrGLenum filter) {
   1.717 +    return sGLContext.get()->fBlitFramebuffer(srcX0, srcY0,
   1.718 +                                        srcX1, srcY1,
   1.719 +                                        dstX0, dstY0,
   1.720 +                                        dstX1, dstY1,
   1.721 +                                        mask, filter);
   1.722 +}
   1.723 +
   1.724 +GrGLvoid glBindVertexArray_mozilla(GrGLuint array) {
   1.725 +    return sGLContext.get()->fBindVertexArray(array);
   1.726 +}
   1.727 +
   1.728 +GrGLvoid glDeleteVertexArrays_mozilla(GrGLsizei n, const GrGLuint *arrays) {
   1.729 +    return sGLContext.get()->fDeleteVertexArrays(n, arrays);
   1.730 +}
   1.731 +
   1.732 +GrGLvoid glGenVertexArrays_mozilla(GrGLsizei n, GrGLuint *arrays) {
   1.733 +    return sGLContext.get()->fGenVertexArrays(n, arrays);
   1.734 +}
   1.735 +
   1.736 +// Additional functions required for desktop GL < version 3.2
   1.737 +
   1.738 +GrGLvoid glLoadMatrixf_mozilla(const GLfloat* matrix)
   1.739 +{
   1.740 +    return sGLContext.get()->fLoadMatrixf(matrix);
   1.741 +}
   1.742 +
   1.743 +GrGLvoid glLoadIdentity_mozilla()
   1.744 +{
   1.745 +    return sGLContext.get()->fLoadIdentity();
   1.746 +}
   1.747 +
   1.748 +GrGLvoid glMatrixMode_mozilla(GrGLenum mode)
   1.749 +{
   1.750 +    return sGLContext.get()->fMatrixMode(mode);
   1.751 +}
   1.752 +
   1.753 +GrGLvoid glTexGeni_mozilla(GrGLenum coord, GrGLenum pname, GrGLint param)
   1.754 +{
   1.755 +    return sGLContext.get()->fTexGeni(coord, pname, param);
   1.756 +}
   1.757 +
   1.758 +GrGLvoid glTexGenfv_mozilla(GrGLenum coord, GrGLenum pname, const GrGLfloat* param)
   1.759 +{
   1.760 +    return sGLContext.get()->fTexGenfv(coord, pname, param);
   1.761 +}
   1.762 +
   1.763 +} // extern "C"
   1.764 +
   1.765 +static GrGLInterface* CreateGrGLInterfaceFromGLContext(GLContext* context)
   1.766 +{
   1.767 +    SetStaticGLContext(context);
   1.768 +
   1.769 +    GrGLInterface* i = new GrGLInterface();
   1.770 +    i->fCallback = EnsureGLContext;
   1.771 +    i->fCallbackData = 0; // must be later initialized to be a valid DrawTargetSkia* pointer
   1.772 +
   1.773 +    context->MakeCurrent();
   1.774 +
   1.775 +    // We support both desktop GL and GLES2
   1.776 +    if (context->IsGLES()) {
   1.777 +        i->fStandard = kGLES_GrGLStandard;
   1.778 +    } else {
   1.779 +        i->fStandard = kGL_GrGLStandard;
   1.780 +    }
   1.781 +
   1.782 +    GrGLExtensions extensions;
   1.783 +    if (!extensions.init(i->fStandard, glGetString_mozilla, NULL, glGetIntegerv_mozilla)) {
   1.784 +        return nullptr;
   1.785 +    }
   1.786 +
   1.787 +    i->fExtensions.swap(&extensions);
   1.788 +
   1.789 +    // Core GL functions required by Ganesh
   1.790 +    i->fFunctions.fActiveTexture = glActiveTexture_mozilla;
   1.791 +    i->fFunctions.fAttachShader = glAttachShader_mozilla;
   1.792 +    i->fFunctions.fBindAttribLocation = glBindAttribLocation_mozilla;
   1.793 +    i->fFunctions.fBindBuffer = glBindBuffer_mozilla;
   1.794 +    i->fFunctions.fBindFramebuffer = glBindFramebuffer_mozilla;
   1.795 +    i->fFunctions.fBindRenderbuffer = glBindRenderbuffer_mozilla;
   1.796 +    i->fFunctions.fBindTexture = glBindTexture_mozilla;
   1.797 +    i->fFunctions.fBlendFunc = glBlendFunc_mozilla;
   1.798 +    i->fFunctions.fBlendColor = glBlendColor_mozilla;
   1.799 +    i->fFunctions.fBufferData = glBufferData_mozilla;
   1.800 +    i->fFunctions.fBufferSubData = glBufferSubData_mozilla;
   1.801 +    i->fFunctions.fCheckFramebufferStatus = glCheckFramebufferStatus_mozilla;
   1.802 +    i->fFunctions.fClear = glClear_mozilla;
   1.803 +    i->fFunctions.fClearColor = glClearColor_mozilla;
   1.804 +    i->fFunctions.fClearStencil = glClearStencil_mozilla;
   1.805 +    i->fFunctions.fColorMask = glColorMask_mozilla;
   1.806 +    i->fFunctions.fCompileShader = glCompileShader_mozilla;
   1.807 +    i->fFunctions.fCopyTexSubImage2D = glCopyTexSubImage2D_mozilla;
   1.808 +    i->fFunctions.fCreateProgram = glCreateProgram_mozilla;
   1.809 +    i->fFunctions.fCreateShader = glCreateShader_mozilla;
   1.810 +    i->fFunctions.fCullFace = glCullFace_mozilla;
   1.811 +    i->fFunctions.fDeleteBuffers = glDeleteBuffers_mozilla;
   1.812 +    i->fFunctions.fDeleteFramebuffers = glDeleteFramebuffers_mozilla;
   1.813 +    i->fFunctions.fDeleteProgram = glDeleteProgram_mozilla;
   1.814 +    i->fFunctions.fDeleteRenderbuffers = glDeleteRenderbuffers_mozilla;
   1.815 +    i->fFunctions.fDeleteShader = glDeleteShader_mozilla;
   1.816 +    i->fFunctions.fDeleteTextures = glDeleteTextures_mozilla;
   1.817 +    i->fFunctions.fDepthMask = glDepthMask_mozilla;
   1.818 +    i->fFunctions.fDisable = glDisable_mozilla;
   1.819 +    i->fFunctions.fDisableVertexAttribArray = glDisableVertexAttribArray_mozilla;
   1.820 +    i->fFunctions.fDrawArrays = glDrawArrays_mozilla;
   1.821 +    i->fFunctions.fDrawElements = glDrawElements_mozilla;
   1.822 +    i->fFunctions.fEnable = glEnable_mozilla;
   1.823 +    i->fFunctions.fEnableVertexAttribArray = glEnableVertexAttribArray_mozilla;
   1.824 +    i->fFunctions.fFinish = glFinish_mozilla;
   1.825 +    i->fFunctions.fFlush = glFlush_mozilla;
   1.826 +    i->fFunctions.fFramebufferRenderbuffer = glFramebufferRenderbuffer_mozilla;
   1.827 +    i->fFunctions.fFramebufferTexture2D = glFramebufferTexture2D_mozilla;
   1.828 +    i->fFunctions.fFrontFace = glFrontFace_mozilla;
   1.829 +    i->fFunctions.fGenBuffers = glGenBuffers_mozilla;
   1.830 +    i->fFunctions.fGenFramebuffers = glGenFramebuffers_mozilla;
   1.831 +    i->fFunctions.fGenRenderbuffers = glGenRenderbuffers_mozilla;
   1.832 +    i->fFunctions.fGetFramebufferAttachmentParameteriv = glGetFramebufferAttachmentParameteriv_mozilla;
   1.833 +    i->fFunctions.fGenTextures = glGenTextures_mozilla;
   1.834 +    i->fFunctions.fGenerateMipmap = glGenerateMipmap_mozilla;
   1.835 +    i->fFunctions.fGetBufferParameteriv = glGetBufferParameteriv_mozilla;
   1.836 +    i->fFunctions.fGetError = glGetError_mozilla;
   1.837 +    i->fFunctions.fGetIntegerv = glGetIntegerv_mozilla;
   1.838 +    i->fFunctions.fGetProgramInfoLog = glGetProgramInfoLog_mozilla;
   1.839 +    i->fFunctions.fGetProgramiv = glGetProgramiv_mozilla;
   1.840 +    i->fFunctions.fGetRenderbufferParameteriv = glGetRenderbufferParameteriv_mozilla;
   1.841 +    i->fFunctions.fGetShaderInfoLog = glGetShaderInfoLog_mozilla;
   1.842 +    i->fFunctions.fGetShaderiv = glGetShaderiv_mozilla;
   1.843 +    i->fFunctions.fGetString = glGetString_mozilla;
   1.844 +    i->fFunctions.fGetUniformLocation = glGetUniformLocation_mozilla;
   1.845 +    i->fFunctions.fLineWidth = glLineWidth_mozilla;
   1.846 +    i->fFunctions.fLinkProgram = glLinkProgram_mozilla;
   1.847 +    i->fFunctions.fPixelStorei = glPixelStorei_mozilla;
   1.848 +    i->fFunctions.fReadPixels = glReadPixels_mozilla;
   1.849 +    i->fFunctions.fRenderbufferStorage = glRenderbufferStorage_mozilla;
   1.850 +    i->fFunctions.fScissor = glScissor_mozilla;
   1.851 +    i->fFunctions.fShaderSource = glShaderSource_mozilla;
   1.852 +    i->fFunctions.fStencilFunc = glStencilFunc_mozilla;
   1.853 +    i->fFunctions.fStencilMask = glStencilMask_mozilla;
   1.854 +    i->fFunctions.fStencilOp = glStencilOp_mozilla;
   1.855 +    i->fFunctions.fTexImage2D = glTexImage2D_mozilla;
   1.856 +    i->fFunctions.fTexParameteri = glTexParameteri_mozilla;
   1.857 +    i->fFunctions.fTexParameteriv = glTexParameteriv_mozilla;
   1.858 +    i->fFunctions.fTexSubImage2D = glTexSubImage2D_mozilla;
   1.859 +    i->fFunctions.fUniform1f = glUniform1f_mozilla;
   1.860 +    i->fFunctions.fUniform1i = glUniform1i_mozilla;
   1.861 +    i->fFunctions.fUniform1fv = glUniform1fv_mozilla;
   1.862 +    i->fFunctions.fUniform1iv = glUniform1iv_mozilla;
   1.863 +    i->fFunctions.fUniform2f = glUniform2f_mozilla;
   1.864 +    i->fFunctions.fUniform2i = glUniform2i_mozilla;
   1.865 +    i->fFunctions.fUniform2fv = glUniform2fv_mozilla;
   1.866 +    i->fFunctions.fUniform2iv = glUniform2iv_mozilla;
   1.867 +    i->fFunctions.fUniform3f = glUniform3f_mozilla;
   1.868 +    i->fFunctions.fUniform3i = glUniform3i_mozilla;
   1.869 +    i->fFunctions.fUniform3fv = glUniform3fv_mozilla;
   1.870 +    i->fFunctions.fUniform3iv = glUniform3iv_mozilla;
   1.871 +    i->fFunctions.fUniform4f = glUniform4f_mozilla;
   1.872 +    i->fFunctions.fUniform4i = glUniform4i_mozilla;
   1.873 +    i->fFunctions.fUniform4fv = glUniform4fv_mozilla;
   1.874 +    i->fFunctions.fUniform4iv = glUniform4iv_mozilla;
   1.875 +    i->fFunctions.fUniformMatrix2fv = glUniformMatrix2fv_mozilla;
   1.876 +    i->fFunctions.fUniformMatrix3fv = glUniformMatrix3fv_mozilla;
   1.877 +    i->fFunctions.fUniformMatrix4fv = glUniformMatrix4fv_mozilla;
   1.878 +    i->fFunctions.fUseProgram = glUseProgram_mozilla;
   1.879 +    i->fFunctions.fVertexAttrib4fv = glVertexAttrib4fv_mozilla;
   1.880 +    i->fFunctions.fVertexAttribPointer = glVertexAttribPointer_mozilla;
   1.881 +    i->fFunctions.fViewport = glViewport_mozilla;
   1.882 +
   1.883 +    // Required for either desktop OpenGL 2.0 or OpenGL ES 2.0
   1.884 +    i->fFunctions.fStencilFuncSeparate = glStencilFuncSeparate_mozilla;
   1.885 +    i->fFunctions.fStencilMaskSeparate = glStencilMaskSeparate_mozilla;
   1.886 +    i->fFunctions.fStencilOpSeparate = glStencilOpSeparate_mozilla;
   1.887 +
   1.888 +    // GLContext supports glMapBuffer
   1.889 +    i->fFunctions.fMapBuffer = glMapBuffer_mozilla;
   1.890 +    i->fFunctions.fUnmapBuffer = glUnmapBuffer_mozilla;
   1.891 +
   1.892 +    // GLContext supports glRenderbufferStorageMultisample/glBlitFramebuffer
   1.893 +    i->fFunctions.fRenderbufferStorageMultisample = glRenderbufferStorageMultisample_mozilla;
   1.894 +    i->fFunctions.fBlitFramebuffer = glBlitFramebuffer_mozilla;
   1.895 +
   1.896 +    // GLContext supports glCompressedTexImage2D
   1.897 +    i->fFunctions.fCompressedTexImage2D = glCompressedTexImage2D_mozilla;
   1.898 +
   1.899 +    // GL_OES_vertex_array_object
   1.900 +    i->fFunctions.fBindVertexArray = glBindVertexArray_mozilla;
   1.901 +    i->fFunctions.fDeleteVertexArrays = glDeleteVertexArrays_mozilla;
   1.902 +    i->fFunctions.fGenVertexArrays = glGenVertexArrays_mozilla;
   1.903 +
   1.904 +    // Desktop GL 
   1.905 +    i->fFunctions.fGetTexLevelParameteriv = glGetTexLevelParameteriv_mozilla;
   1.906 +    i->fFunctions.fDrawBuffer = glDrawBuffer_mozilla;
   1.907 +    i->fFunctions.fReadBuffer = glReadBuffer_mozilla;
   1.908 +
   1.909 +    // Desktop OpenGL > 1.5
   1.910 +    i->fFunctions.fGenQueries = glGenQueries_mozilla;
   1.911 +    i->fFunctions.fDeleteQueries = glDeleteQueries_mozilla;
   1.912 +    i->fFunctions.fBeginQuery = glBeginQuery_mozilla;
   1.913 +    i->fFunctions.fEndQuery = glEndQuery_mozilla;
   1.914 +    i->fFunctions.fGetQueryiv = glGetQueryiv_mozilla;
   1.915 +    i->fFunctions.fGetQueryObjectiv = glGetQueryObjectiv_mozilla;
   1.916 +    i->fFunctions.fGetQueryObjectuiv = glGetQueryObjectuiv_mozilla;
   1.917 +
   1.918 +    // Desktop OpenGL > 2.0
   1.919 +    i->fFunctions.fDrawBuffers = glDrawBuffers_mozilla;
   1.920 +
   1.921 +    // Desktop OpenGL < 3.2 (which we pretend to be)
   1.922 +    i->fFunctions.fLoadIdentity = glLoadIdentity_mozilla;
   1.923 +    i->fFunctions.fLoadMatrixf = glLoadMatrixf_mozilla;
   1.924 +    i->fFunctions.fMatrixMode = glMatrixMode_mozilla;
   1.925 +    i->fFunctions.fTexGenfv = glTexGenfv_mozilla;
   1.926 +    i->fFunctions.fTexGeni = glTexGeni_mozilla;
   1.927 +
   1.928 +    return i;
   1.929 +}
   1.930 +
   1.931 +SkiaGLGlue::SkiaGLGlue(GLContext* context)
   1.932 +    : mGLContext(context)
   1.933 +{
   1.934 +    SkAutoTUnref<GrGLInterface> i(CreateGrGLInterfaceFromGLContext(mGLContext));
   1.935 +    i->fCallbackData = reinterpret_cast<GrGLInterfaceCallbackData>(this);
   1.936 +    mGrGLInterface = i;
   1.937 +    SkAutoTUnref<GrContext> gr(GrContext::Create(kOpenGL_GrBackend, (GrBackendContext)mGrGLInterface.get()));
   1.938 +
   1.939 +    mGrContext = gr;
   1.940 +}

mercurial