Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40; -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "skia/GrContext.h"
7 #include "skia/GrGLInterface.h"
8 #include "mozilla/gfx/2D.h"
9 #include "mozilla/ThreadLocal.h"
10 #include "mozilla/DebugOnly.h"
12 /* SkPostConfig.h includes windows.h, which includes windef.h
13 * which redefines min/max. We don't want that. */
14 #ifdef _WIN32
15 #undef min
16 #undef max
17 #endif
19 #include "GLContext.h"
20 #include "SkiaGLGlue.h"
22 using mozilla::gl::GLContext;
23 using mozilla::gl::GLFeature;
24 using mozilla::gl::SkiaGLGlue;
25 using mozilla::gfx::DrawTarget;
27 static mozilla::ThreadLocal<GLContext*> sGLContext;
29 extern "C" {
31 static void SetStaticGLContext(GLContext* context)
32 {
33 if (!sGLContext.initialized()) {
34 mozilla::DebugOnly<bool> success = sGLContext.init();
35 MOZ_ASSERT(success);
36 }
38 sGLContext.set(context);
39 }
41 void EnsureGLContext(const GrGLInterface* i)
42 {
43 const SkiaGLGlue* contextSkia = reinterpret_cast<const SkiaGLGlue*>(i->fCallbackData);
44 MOZ_ASSERT(contextSkia);
45 GLContext* gl = contextSkia->GetGLContext();
46 gl->MakeCurrent();
47 SetStaticGLContext(gl);
48 }
50 // Core GL functions required by Ganesh
52 GrGLvoid glActiveTexture_mozilla(GrGLenum texture)
53 {
54 return sGLContext.get()->fActiveTexture(texture);
55 }
57 GrGLvoid glAttachShader_mozilla(GrGLuint program, GrGLuint shader)
58 {
59 return sGLContext.get()->fAttachShader(program, shader);
60 }
62 GrGLvoid glBindAttribLocation_mozilla(GrGLuint program, GrGLuint index, const GLchar* name)
63 {
64 return sGLContext.get()->fBindAttribLocation(program, index, name);
65 }
67 GrGLvoid glBindBuffer_mozilla(GrGLenum target, GrGLuint buffer)
68 {
69 return sGLContext.get()->fBindBuffer(target, buffer);
70 }
72 GrGLvoid glBindFramebuffer_mozilla(GrGLenum target, GrGLuint framebuffer)
73 {
74 return sGLContext.get()->fBindFramebuffer(target, framebuffer);
75 }
77 GrGLvoid glBindRenderbuffer_mozilla(GrGLenum target, GrGLuint renderbuffer)
78 {
79 return sGLContext.get()->fBindRenderbuffer(target, renderbuffer);
80 }
82 GrGLvoid glBindTexture_mozilla(GrGLenum target, GrGLuint texture)
83 {
84 return sGLContext.get()->fBindTexture(target, texture);
85 }
87 GrGLvoid glBlendColor_mozilla(GrGLclampf red, GrGLclampf green, GrGLclampf blue, GrGLclampf alpha)
88 {
89 return sGLContext.get()->fBlendColor(red, green, blue, alpha);
90 }
92 GrGLvoid glBlendFunc_mozilla(GrGLenum sfactor, GrGLenum dfactor)
93 {
94 return sGLContext.get()->fBlendFunc(sfactor, dfactor);
95 }
97 GrGLvoid glBufferData_mozilla(GrGLenum target, GrGLsizeiptr size, const void* data, GrGLenum usage)
98 {
99 return sGLContext.get()->fBufferData(target, size, data, usage);
100 }
102 GrGLvoid glBufferSubData_mozilla(GrGLenum target, GrGLintptr offset, GrGLsizeiptr size, const void* data)
103 {
104 return sGLContext.get()->fBufferSubData(target, offset, size, data);
105 }
107 GrGLenum glCheckFramebufferStatus_mozilla(GrGLenum target)
108 {
109 return sGLContext.get()->fCheckFramebufferStatus(target);
110 }
112 GrGLvoid glClear_mozilla(GrGLbitfield mask)
113 {
114 return sGLContext.get()->fClear(mask);
115 }
117 GrGLvoid glClearColor_mozilla(GrGLclampf red, GrGLclampf green, GrGLclampf blue, GrGLclampf alpha)
118 {
119 return sGLContext.get()->fClearColor(red, green, blue, alpha);
120 }
122 GrGLvoid glClearStencil_mozilla(GrGLint s)
123 {
124 return sGLContext.get()->fClearStencil(s);
125 }
127 GrGLvoid glColorMask_mozilla(GrGLboolean red, GrGLboolean green, GrGLboolean blue, GrGLboolean alpha)
128 {
129 return sGLContext.get()->fColorMask(red, green, blue, alpha);
130 }
132 GrGLvoid glCompileShader_mozilla(GrGLuint shader)
133 {
134 return sGLContext.get()->fCompileShader(shader);
135 }
137 GrGLvoid glCopyTexSubImage2D_mozilla(GrGLenum target, GrGLint level, GrGLint xoffset, GrGLint yoffset,
138 GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height)
139 {
140 return sGLContext.get()->fCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
141 }
143 GrGLuint glCreateProgram_mozilla(void)
144 {
145 return sGLContext.get()->fCreateProgram();
146 }
148 GrGLuint glCreateShader_mozilla(GrGLenum type)
149 {
150 return sGLContext.get()->fCreateShader(type);
151 }
153 GrGLvoid glCullFace_mozilla(GrGLenum mode)
154 {
155 return sGLContext.get()->fCullFace(mode);
156 }
158 GrGLvoid glDeleteBuffers_mozilla(GrGLsizei n, const GrGLuint* buffers)
159 {
160 return sGLContext.get()->fDeleteBuffers(n, buffers);
161 }
163 GrGLvoid glDeleteFramebuffers_mozilla(GrGLsizei n, const GrGLuint* framebuffers)
164 {
165 return sGLContext.get()->fDeleteFramebuffers(n, framebuffers);
166 }
168 GrGLvoid glDeleteProgram_mozilla(GrGLuint program)
169 {
170 return sGLContext.get()->fDeleteProgram(program);
171 }
173 GrGLvoid glDeleteRenderbuffers_mozilla(GrGLsizei n, const GrGLuint* renderbuffers)
174 {
175 return sGLContext.get()->fDeleteRenderbuffers(n, renderbuffers);
176 }
178 GrGLvoid glDeleteShader_mozilla(GrGLuint shader)
179 {
180 return sGLContext.get()->fDeleteShader(shader);
181 }
183 GrGLvoid glDeleteTextures_mozilla(GrGLsizei n, const GrGLuint* textures)
184 {
185 return sGLContext.get()->fDeleteTextures(n, textures);
186 }
188 GrGLvoid glDepthMask_mozilla(GrGLboolean flag)
189 {
190 return sGLContext.get()->fDepthMask(flag);
191 }
193 GrGLvoid glDisable_mozilla(GrGLenum cap)
194 {
195 return sGLContext.get()->fDisable(cap);
196 }
198 GrGLvoid glDisableVertexAttribArray_mozilla(GrGLuint index)
199 {
200 return sGLContext.get()->fDisableVertexAttribArray(index);
201 }
203 GrGLvoid glDrawArrays_mozilla(GrGLenum mode, GrGLint first, GrGLsizei count)
204 {
205 return sGLContext.get()->fDrawArrays(mode, first, count);
206 }
208 GrGLvoid glDrawElements_mozilla(GrGLenum mode, GrGLsizei count, GrGLenum type, const void* indices)
209 {
210 return sGLContext.get()->fDrawElements(mode, count, type, indices);
211 }
213 GrGLvoid glEnable_mozilla(GrGLenum cap)
214 {
215 return sGLContext.get()->fEnable(cap);
216 }
218 GrGLvoid glEnableVertexAttribArray_mozilla(GrGLuint index)
219 {
220 return sGLContext.get()->fEnableVertexAttribArray(index);
221 }
223 GrGLvoid glFinish_mozilla()
224 {
225 return sGLContext.get()->fFinish();
226 }
228 GrGLvoid glFlush_mozilla()
229 {
230 return sGLContext.get()->fFlush();
231 }
233 GrGLvoid glFramebufferRenderbuffer_mozilla(GrGLenum target, GrGLenum attachment, GrGLenum renderbuffertarget, GrGLuint renderbuffer)
234 {
235 return sGLContext.get()->fFramebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer);
236 }
238 GrGLvoid glFramebufferTexture2D_mozilla(GrGLenum target, GrGLenum attachment, GrGLenum textarget, GrGLuint texture, GrGLint level)
239 {
240 return sGLContext.get()->fFramebufferTexture2D(target, attachment, textarget, texture, level);
241 }
243 GrGLvoid glFrontFace_mozilla(GrGLenum mode)
244 {
245 return sGLContext.get()->fFrontFace(mode);
246 }
248 GrGLvoid glGenBuffers_mozilla(GrGLsizei n, GrGLuint* buffers)
249 {
250 return sGLContext.get()->fGenBuffers(n, buffers);
251 }
253 GrGLvoid glGenFramebuffers_mozilla(GrGLsizei n, GrGLuint* framebuffers)
254 {
255 return sGLContext.get()->fGenFramebuffers(n, framebuffers);
256 }
258 GrGLvoid glGenRenderbuffers_mozilla(GrGLsizei n, GrGLuint* renderbuffers)
259 {
260 return sGLContext.get()->fGenRenderbuffers(n, renderbuffers);
261 }
263 GrGLvoid glGenTextures_mozilla(GrGLsizei n, GrGLuint* textures)
264 {
265 return sGLContext.get()->fGenTextures(n, textures);
266 }
268 GrGLvoid glGenerateMipmap_mozilla(GrGLenum target)
269 {
270 return sGLContext.get()->fGenerateMipmap(target);
271 }
273 GrGLvoid glGetBufferParameteriv_mozilla(GrGLenum target, GrGLenum pname, GrGLint* params)
274 {
275 return sGLContext.get()->fGetBufferParameteriv(target, pname, params);
276 }
278 GrGLvoid glGetFramebufferAttachmentParameteriv_mozilla(GrGLenum target, GrGLenum attachment, GrGLenum pname, GrGLint* params)
279 {
280 return sGLContext.get()->fGetFramebufferAttachmentParameteriv(target, attachment, pname, params);
281 }
283 GrGLenum glGetError_mozilla()
284 {
285 return sGLContext.get()->fGetError();
286 }
288 GrGLvoid glGetIntegerv_mozilla(GrGLenum pname, GrGLint* params)
289 {
290 return sGLContext.get()->fGetIntegerv(pname, params);
291 }
293 GrGLvoid glGetProgramInfoLog_mozilla(GrGLuint program, GrGLsizei bufsize, GrGLsizei* length, char* infolog)
294 {
295 return sGLContext.get()->fGetProgramInfoLog(program, bufsize, length, infolog);
296 }
298 GrGLvoid glGetProgramiv_mozilla(GrGLuint program, GrGLenum pname, GrGLint* params)
299 {
300 return sGLContext.get()->fGetProgramiv(program, pname, params);
301 }
303 GrGLvoid glGetRenderbufferParameteriv_mozilla(GrGLenum target, GrGLenum pname, GrGLint* params)
304 {
305 return sGLContext.get()->fGetRenderbufferParameteriv(target, pname, params);
306 }
308 GrGLvoid glGetShaderInfoLog_mozilla(GrGLuint shader, GrGLsizei bufsize, GrGLsizei* length, char* infolog)
309 {
310 return sGLContext.get()->fGetShaderInfoLog(shader, bufsize, length, infolog);
311 }
313 GrGLvoid glGetShaderiv_mozilla(GrGLuint shader, GrGLenum pname, GrGLint* params)
314 {
315 return sGLContext.get()->fGetShaderiv(shader, pname, params);
316 }
318 const GLubyte* glGetString_mozilla(GrGLenum name)
319 {
320 // GLContext only exposes a OpenGL 2.0 style API, so we have to intercept a bunch
321 // of checks that Ganesh makes to determine which capabilities are present
322 // on the GL implementation and change them to match what GLContext actually exposes.
324 if (name == LOCAL_GL_VERSION) {
325 if (sGLContext.get()->IsGLES()) {
326 return reinterpret_cast<const GLubyte*>("OpenGL ES 2.0");
327 } else {
328 return reinterpret_cast<const GLubyte*>("2.0");
329 }
330 } else if (name == LOCAL_GL_EXTENSIONS) {
331 // Only expose the bare minimum extensions we want to support to ensure a functional Ganesh
332 // as GLContext only exposes certain extensions
333 static bool extensionsStringBuilt = false;
334 static char extensionsString[1024];
336 if (!extensionsStringBuilt) {
337 extensionsString[0] = '\0';
339 if (sGLContext.get()->IsGLES()) {
340 // OES is only applicable to GLES2
341 if (sGLContext.get()->IsExtensionSupported(GLContext::OES_packed_depth_stencil)) {
342 strcat(extensionsString, "GL_OES_packed_depth_stencil ");
343 }
345 if (sGLContext.get()->IsExtensionSupported(GLContext::OES_rgb8_rgba8)) {
346 strcat(extensionsString, "GL_OES_rgb8_rgba8 ");
347 }
349 if (sGLContext.get()->IsExtensionSupported(GLContext::OES_texture_npot)) {
350 strcat(extensionsString, "GL_OES_texture_npot ");
351 }
353 if (sGLContext.get()->IsExtensionSupported(GLContext::OES_vertex_array_object)) {
354 strcat(extensionsString, "GL_OES_vertex_array_object ");
355 }
357 if (sGLContext.get()->IsSupported(GLFeature::standard_derivatives)) {
358 strcat(extensionsString, "GL_OES_standard_derivatives ");
359 }
360 }
362 if (sGLContext.get()->IsExtensionSupported(GLContext::EXT_texture_format_BGRA8888)) {
363 strcat(extensionsString, "GL_EXT_texture_format_BGRA8888 ");
364 }
366 if (sGLContext.get()->IsExtensionSupported(GLContext::EXT_packed_depth_stencil)) {
367 strcat(extensionsString, "GL_EXT_packed_depth_stencil ");
368 }
370 if (sGLContext.get()->IsExtensionSupported(GLContext::EXT_bgra)) {
371 strcat(extensionsString, "GL_EXT_bgra ");
372 }
374 if (sGLContext.get()->IsExtensionSupported(GLContext::EXT_read_format_bgra)) {
375 strcat(extensionsString, "GL_EXT_read_format_bgra ");
376 }
378 extensionsStringBuilt = true;
379 #ifdef DEBUG
380 printf_stderr("Exported SkiaGL extensions: %s\n", extensionsString);
381 #endif
382 }
384 return reinterpret_cast<const GLubyte*>(extensionsString);
386 } else if (name == LOCAL_GL_SHADING_LANGUAGE_VERSION) {
387 if (sGLContext.get()->IsGLES()) {
388 return reinterpret_cast<const GLubyte*>("OpenGL ES GLSL ES 1.0");
389 } else {
390 return reinterpret_cast<const GLubyte*>("1.10");
391 }
392 }
394 return sGLContext.get()->fGetString(name);
395 }
397 GrGLint glGetUniformLocation_mozilla(GrGLuint program, const char* name)
398 {
399 return sGLContext.get()->fGetUniformLocation(program, name);
400 }
402 GrGLvoid glLineWidth_mozilla(GrGLfloat width)
403 {
404 return sGLContext.get()->fLineWidth(width);
405 }
407 GrGLvoid glLinkProgram_mozilla(GrGLuint program)
408 {
409 return sGLContext.get()->fLinkProgram(program);
410 }
412 GrGLvoid glPixelStorei_mozilla(GrGLenum pname, GrGLint param)
413 {
414 return sGLContext.get()->fPixelStorei(pname, param);
415 }
417 GrGLvoid glReadPixels_mozilla(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height,
418 GrGLenum format, GrGLenum type, void* pixels)
419 {
420 return sGLContext.get()->fReadPixels(x, y, width, height,
421 format, type, pixels);
422 }
424 GrGLvoid glRenderbufferStorage_mozilla(GrGLenum target, GrGLenum internalformat, GrGLsizei width, GrGLsizei height)
425 {
426 return sGLContext.get()->fRenderbufferStorage(target, internalformat, width, height);
427 }
429 GrGLvoid glScissor_mozilla(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height)
430 {
431 return sGLContext.get()->fScissor(x, y, width, height);
432 }
434 GrGLvoid glShaderSource_mozilla(GrGLuint shader, GrGLsizei count, const char** str, const GrGLint* length)
435 {
436 return sGLContext.get()->fShaderSource(shader, count, str, length);
437 }
439 GrGLvoid glStencilFunc_mozilla(GrGLenum func, GrGLint ref, GrGLuint mask)
440 {
441 return sGLContext.get()->fStencilFunc(func, ref, mask);
442 }
444 GrGLvoid glStencilMask_mozilla(GrGLuint mask)
445 {
446 return sGLContext.get()->fStencilMask(mask);
447 }
449 GrGLvoid glStencilOp_mozilla(GrGLenum fail, GrGLenum zfail, GrGLenum zpass)
450 {
451 return sGLContext.get()->fStencilOp(fail, zfail, zpass);
452 }
454 GrGLvoid glTexImage2D_mozilla(GrGLenum target, GrGLint level, GrGLint internalformat,
455 GrGLsizei width, GrGLsizei height, GrGLint border,
456 GrGLenum format, GrGLenum type, const void* pixels)
457 {
458 return sGLContext.get()->fTexImage2D(target, level, internalformat,
459 width, height, border,
460 format, type, pixels);
461 }
463 GrGLvoid glTexParameteri_mozilla(GrGLenum target, GrGLenum pname, GrGLint param)
464 {
465 return sGLContext.get()->fTexParameteri(target, pname, param);
466 }
468 GrGLvoid glTexParameteriv_mozilla(GrGLenum target, GrGLenum pname, const GrGLint* params)
469 {
470 return sGLContext.get()->fTexParameteriv(target, pname, params);
471 }
473 GrGLvoid glTexSubImage2D_mozilla(GrGLenum target, GrGLint level,
474 GrGLint xoffset, GrGLint yoffset,
475 GrGLsizei width, GrGLsizei height,
476 GrGLenum format, GrGLenum type, const void* pixels)
477 {
478 return sGLContext.get()->fTexSubImage2D(target, level,
479 xoffset, yoffset,
480 width, height,
481 format, type, pixels);
482 }
484 GrGLvoid glUniform1f_mozilla(GrGLint location, GrGLfloat v)
485 {
486 return sGLContext.get()->fUniform1f(location, v);
487 }
489 GrGLvoid glUniform1i_mozilla(GrGLint location, GrGLint v)
490 {
491 return sGLContext.get()->fUniform1i(location, v);
492 }
494 GrGLvoid glUniform1fv_mozilla(GrGLint location, GrGLsizei count, const GrGLfloat* v)
495 {
496 return sGLContext.get()->fUniform1fv(location, count, v);
497 }
499 GrGLvoid glUniform1iv_mozilla(GrGLint location, GrGLsizei count, const GrGLint* v)
500 {
501 return sGLContext.get()->fUniform1iv(location, count, v);
502 }
504 GrGLvoid glUniform2f_mozilla(GrGLint location, GrGLfloat v0, GrGLfloat v1)
505 {
506 return sGLContext.get()->fUniform2f(location, v0, v1);
507 }
509 GrGLvoid glUniform2i_mozilla(GrGLint location, GrGLint v0, GrGLint v1)
510 {
511 return sGLContext.get()->fUniform2i(location, v0, v1);
512 }
514 GrGLvoid glUniform2fv_mozilla(GrGLint location, GrGLsizei count, const GrGLfloat* v)
515 {
516 return sGLContext.get()->fUniform2fv(location, count, v);
517 }
519 GrGLvoid glUniform2iv_mozilla(GrGLint location, GrGLsizei count, const GrGLint* v)
520 {
521 return sGLContext.get()->fUniform2iv(location, count, v);
522 }
524 GrGLvoid glUniform3f_mozilla(GrGLint location, GrGLfloat v0, GrGLfloat v1, GrGLfloat v2)
525 {
526 return sGLContext.get()->fUniform3f(location, v0, v1, v2);
527 }
529 GrGLvoid glUniform3i_mozilla(GrGLint location, GrGLint v0, GrGLint v1, GrGLint v2)
530 {
531 return sGLContext.get()->fUniform3i(location, v0, v1, v2);
532 }
534 GrGLvoid glUniform3fv_mozilla(GrGLint location, GrGLsizei count, const GrGLfloat* v)
535 {
536 return sGLContext.get()->fUniform3fv(location, count, v);
537 }
539 GrGLvoid glUniform3iv_mozilla(GrGLint location, GrGLsizei count, const GrGLint* v)
540 {
541 return sGLContext.get()->fUniform3iv(location, count, v);
542 }
544 GrGLvoid glUniform4f_mozilla(GrGLint location, GrGLfloat v0, GrGLfloat v1, GrGLfloat v2, GrGLfloat v3)
545 {
546 return sGLContext.get()->fUniform4f(location, v0, v1, v2, v3);
547 }
549 GrGLvoid glUniform4i_mozilla(GrGLint location, GrGLint v0, GrGLint v1, GrGLint v2, GrGLint v3)
550 {
551 return sGLContext.get()->fUniform4i(location, v0, v1, v2, v3);
552 }
554 GrGLvoid glUniform4fv_mozilla(GrGLint location, GrGLsizei count, const GrGLfloat* v)
555 {
556 return sGLContext.get()->fUniform4fv(location, count, v);
557 }
559 GrGLvoid glUniform4iv_mozilla(GrGLint location, GrGLsizei count, const GrGLint* v)
560 {
561 return sGLContext.get()->fUniform4iv(location, count, v);
562 }
564 GrGLvoid glUniformMatrix2fv_mozilla(GrGLint location, GrGLsizei count, GrGLboolean transpose, const GrGLfloat* value)
565 {
566 return sGLContext.get()->fUniformMatrix2fv(location, count, transpose, value);
567 }
569 GrGLvoid glUniformMatrix3fv_mozilla(GrGLint location, GrGLsizei count, GrGLboolean transpose, const GrGLfloat* value)
570 {
571 return sGLContext.get()->fUniformMatrix3fv(location, count, transpose, value);
572 }
574 GrGLvoid glUniformMatrix4fv_mozilla(GrGLint location, GrGLsizei count, GrGLboolean transpose, const GrGLfloat* value)
575 {
576 return sGLContext.get()->fUniformMatrix4fv(location, count, transpose, value);
577 }
579 GrGLvoid glUseProgram_mozilla(GrGLuint program)
580 {
581 return sGLContext.get()->fUseProgram(program);
582 }
584 GrGLvoid glVertexAttrib4fv_mozilla(GrGLuint index, const GrGLfloat* values)
585 {
586 return sGLContext.get()->fVertexAttrib4fv(index, values);
587 }
589 GrGLvoid glVertexAttribPointer_mozilla(GrGLuint index, GrGLint size, GrGLenum type, GrGLboolean normalized, GrGLsizei stride, const void* ptr)
590 {
591 return sGLContext.get()->fVertexAttribPointer(index, size, type, normalized, stride, ptr);
592 }
594 GrGLvoid glViewport_mozilla(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height)
595 {
596 return sGLContext.get()->fViewport(x, y, width, height);
597 }
599 // Required if the bindings are GLES2 or desktop OpenGL 2.0
601 GrGLvoid glStencilFuncSeparate_mozilla(GrGLenum frontfunc, GrGLenum backfunc, GrGLint ref, GrGLuint mask)
602 {
603 return sGLContext.get()->fStencilFuncSeparate(frontfunc, backfunc, ref, mask);
604 }
606 GrGLvoid glStencilMaskSeparate_mozilla(GrGLenum face, GrGLuint mask)
607 {
608 return sGLContext.get()->fStencilMaskSeparate(face, mask);
609 }
611 GrGLvoid glStencilOpSeparate_mozilla(GrGLenum face, GrGLenum sfail, GrGLenum dpfail, GrGLenum dppass)
612 {
613 return sGLContext.get()->fStencilOpSeparate(face, sfail, dpfail, dppass);
614 }
616 // Not in GLES2
618 GrGLvoid glGetTexLevelParameteriv_mozilla(GrGLenum target, GrGLint level, GrGLenum pname, GrGLint *params)
619 {
620 return sGLContext.get()->fGetTexLevelParameteriv(target, level, pname, params);
621 }
623 GrGLvoid glDrawBuffer_mozilla(GrGLenum mode)
624 {
625 return sGLContext.get()->fDrawBuffer(mode);
626 }
628 GrGLvoid glReadBuffer_mozilla(GrGLenum mode)
629 {
630 return sGLContext.get()->fReadBuffer(mode);
631 }
633 // Desktop OpenGL version >= 1.5
635 GrGLvoid glGenQueries_mozilla(GrGLsizei n, GrGLuint* ids)
636 {
637 return sGLContext.get()->fGenQueries(n, ids);
638 }
640 GrGLvoid glDeleteQueries_mozilla(GrGLsizei n, const GrGLuint* ids)
641 {
642 return sGLContext.get()->fDeleteQueries(n, ids);
643 }
645 GrGLvoid glBeginQuery_mozilla(GrGLenum target, GrGLuint id)
646 {
647 return sGLContext.get()->fBeginQuery(target, id);
648 }
650 GrGLvoid glEndQuery_mozilla(GrGLenum target)
651 {
652 return sGLContext.get()->fEndQuery(target);
653 }
655 GrGLvoid glGetQueryiv_mozilla(GrGLenum target, GrGLenum pname, GrGLint* params)
656 {
657 return sGLContext.get()->fGetQueryiv(target, pname, params);
658 }
660 GrGLvoid glGetQueryObjectiv_mozilla(GrGLuint id, GrGLenum pname, GrGLint* params)
661 {
662 return sGLContext.get()->fGetQueryObjectiv(id, pname, params);
663 }
665 GrGLvoid glGetQueryObjectuiv_mozilla(GrGLuint id, GrGLenum pname, GrGLuint* params)
666 {
667 return sGLContext.get()->fGetQueryObjectuiv(id, pname, params);
668 }
670 // Desktop OpenGL version >= 2.0
672 GrGLvoid glDrawBuffers_mozilla(GrGLsizei n, const GrGLenum* bufs)
673 {
674 return sGLContext.get()->fDrawBuffers(n, bufs);
675 }
677 // GLContext supports glMapBuffer on everything (GL_OES_mapbuffer)
679 GrGLvoid* glMapBuffer_mozilla(GrGLenum target, GrGLenum access)
680 {
681 return sGLContext.get()->fMapBuffer(target, access);
682 }
684 GrGLboolean glUnmapBuffer_mozilla(GrGLenum target)
685 {
686 return sGLContext.get()->fUnmapBuffer(target);
687 }
689 // GLContext supports glCompressedTexImage2D (GL_ARB_texture_compression)
691 GrGLvoid glCompressedTexImage2D_mozilla(GrGLenum target, GrGLint level, GrGLenum internalformat,
692 GrGLsizei width, GrGLsizei height, GrGLint border,
693 GrGLsizei imageSize, const GrGLvoid* pixels)
694 {
695 return sGLContext.get()->fCompressedTexImage2D(target, level, internalformat,
696 width, height, border,
697 imageSize, pixels);
698 }
700 // GLContext supports glBlitFramebuffer/glRenderbufferStorageMultisample (GL_ARB_framebuffer_object)
702 GrGLvoid glRenderbufferStorageMultisample_mozilla(GrGLenum target, GrGLsizei samples, GrGLenum internalformat,
703 GrGLsizei width, GrGLsizei height)
704 {
705 return sGLContext.get()->fRenderbufferStorageMultisample(target, samples, internalformat,
706 width, height);
707 }
709 GrGLvoid glBlitFramebuffer_mozilla(GrGLint srcX0, GrGLint srcY0,
710 GrGLint srcX1, GrGLint srcY1,
711 GrGLint dstX0, GrGLint dstY0,
712 GrGLint dstX1, GrGLint dstY1,
713 GrGLbitfield mask, GrGLenum filter) {
714 return sGLContext.get()->fBlitFramebuffer(srcX0, srcY0,
715 srcX1, srcY1,
716 dstX0, dstY0,
717 dstX1, dstY1,
718 mask, filter);
719 }
721 GrGLvoid glBindVertexArray_mozilla(GrGLuint array) {
722 return sGLContext.get()->fBindVertexArray(array);
723 }
725 GrGLvoid glDeleteVertexArrays_mozilla(GrGLsizei n, const GrGLuint *arrays) {
726 return sGLContext.get()->fDeleteVertexArrays(n, arrays);
727 }
729 GrGLvoid glGenVertexArrays_mozilla(GrGLsizei n, GrGLuint *arrays) {
730 return sGLContext.get()->fGenVertexArrays(n, arrays);
731 }
733 // Additional functions required for desktop GL < version 3.2
735 GrGLvoid glLoadMatrixf_mozilla(const GLfloat* matrix)
736 {
737 return sGLContext.get()->fLoadMatrixf(matrix);
738 }
740 GrGLvoid glLoadIdentity_mozilla()
741 {
742 return sGLContext.get()->fLoadIdentity();
743 }
745 GrGLvoid glMatrixMode_mozilla(GrGLenum mode)
746 {
747 return sGLContext.get()->fMatrixMode(mode);
748 }
750 GrGLvoid glTexGeni_mozilla(GrGLenum coord, GrGLenum pname, GrGLint param)
751 {
752 return sGLContext.get()->fTexGeni(coord, pname, param);
753 }
755 GrGLvoid glTexGenfv_mozilla(GrGLenum coord, GrGLenum pname, const GrGLfloat* param)
756 {
757 return sGLContext.get()->fTexGenfv(coord, pname, param);
758 }
760 } // extern "C"
762 static GrGLInterface* CreateGrGLInterfaceFromGLContext(GLContext* context)
763 {
764 SetStaticGLContext(context);
766 GrGLInterface* i = new GrGLInterface();
767 i->fCallback = EnsureGLContext;
768 i->fCallbackData = 0; // must be later initialized to be a valid DrawTargetSkia* pointer
770 context->MakeCurrent();
772 // We support both desktop GL and GLES2
773 if (context->IsGLES()) {
774 i->fStandard = kGLES_GrGLStandard;
775 } else {
776 i->fStandard = kGL_GrGLStandard;
777 }
779 GrGLExtensions extensions;
780 if (!extensions.init(i->fStandard, glGetString_mozilla, NULL, glGetIntegerv_mozilla)) {
781 return nullptr;
782 }
784 i->fExtensions.swap(&extensions);
786 // Core GL functions required by Ganesh
787 i->fFunctions.fActiveTexture = glActiveTexture_mozilla;
788 i->fFunctions.fAttachShader = glAttachShader_mozilla;
789 i->fFunctions.fBindAttribLocation = glBindAttribLocation_mozilla;
790 i->fFunctions.fBindBuffer = glBindBuffer_mozilla;
791 i->fFunctions.fBindFramebuffer = glBindFramebuffer_mozilla;
792 i->fFunctions.fBindRenderbuffer = glBindRenderbuffer_mozilla;
793 i->fFunctions.fBindTexture = glBindTexture_mozilla;
794 i->fFunctions.fBlendFunc = glBlendFunc_mozilla;
795 i->fFunctions.fBlendColor = glBlendColor_mozilla;
796 i->fFunctions.fBufferData = glBufferData_mozilla;
797 i->fFunctions.fBufferSubData = glBufferSubData_mozilla;
798 i->fFunctions.fCheckFramebufferStatus = glCheckFramebufferStatus_mozilla;
799 i->fFunctions.fClear = glClear_mozilla;
800 i->fFunctions.fClearColor = glClearColor_mozilla;
801 i->fFunctions.fClearStencil = glClearStencil_mozilla;
802 i->fFunctions.fColorMask = glColorMask_mozilla;
803 i->fFunctions.fCompileShader = glCompileShader_mozilla;
804 i->fFunctions.fCopyTexSubImage2D = glCopyTexSubImage2D_mozilla;
805 i->fFunctions.fCreateProgram = glCreateProgram_mozilla;
806 i->fFunctions.fCreateShader = glCreateShader_mozilla;
807 i->fFunctions.fCullFace = glCullFace_mozilla;
808 i->fFunctions.fDeleteBuffers = glDeleteBuffers_mozilla;
809 i->fFunctions.fDeleteFramebuffers = glDeleteFramebuffers_mozilla;
810 i->fFunctions.fDeleteProgram = glDeleteProgram_mozilla;
811 i->fFunctions.fDeleteRenderbuffers = glDeleteRenderbuffers_mozilla;
812 i->fFunctions.fDeleteShader = glDeleteShader_mozilla;
813 i->fFunctions.fDeleteTextures = glDeleteTextures_mozilla;
814 i->fFunctions.fDepthMask = glDepthMask_mozilla;
815 i->fFunctions.fDisable = glDisable_mozilla;
816 i->fFunctions.fDisableVertexAttribArray = glDisableVertexAttribArray_mozilla;
817 i->fFunctions.fDrawArrays = glDrawArrays_mozilla;
818 i->fFunctions.fDrawElements = glDrawElements_mozilla;
819 i->fFunctions.fEnable = glEnable_mozilla;
820 i->fFunctions.fEnableVertexAttribArray = glEnableVertexAttribArray_mozilla;
821 i->fFunctions.fFinish = glFinish_mozilla;
822 i->fFunctions.fFlush = glFlush_mozilla;
823 i->fFunctions.fFramebufferRenderbuffer = glFramebufferRenderbuffer_mozilla;
824 i->fFunctions.fFramebufferTexture2D = glFramebufferTexture2D_mozilla;
825 i->fFunctions.fFrontFace = glFrontFace_mozilla;
826 i->fFunctions.fGenBuffers = glGenBuffers_mozilla;
827 i->fFunctions.fGenFramebuffers = glGenFramebuffers_mozilla;
828 i->fFunctions.fGenRenderbuffers = glGenRenderbuffers_mozilla;
829 i->fFunctions.fGetFramebufferAttachmentParameteriv = glGetFramebufferAttachmentParameteriv_mozilla;
830 i->fFunctions.fGenTextures = glGenTextures_mozilla;
831 i->fFunctions.fGenerateMipmap = glGenerateMipmap_mozilla;
832 i->fFunctions.fGetBufferParameteriv = glGetBufferParameteriv_mozilla;
833 i->fFunctions.fGetError = glGetError_mozilla;
834 i->fFunctions.fGetIntegerv = glGetIntegerv_mozilla;
835 i->fFunctions.fGetProgramInfoLog = glGetProgramInfoLog_mozilla;
836 i->fFunctions.fGetProgramiv = glGetProgramiv_mozilla;
837 i->fFunctions.fGetRenderbufferParameteriv = glGetRenderbufferParameteriv_mozilla;
838 i->fFunctions.fGetShaderInfoLog = glGetShaderInfoLog_mozilla;
839 i->fFunctions.fGetShaderiv = glGetShaderiv_mozilla;
840 i->fFunctions.fGetString = glGetString_mozilla;
841 i->fFunctions.fGetUniformLocation = glGetUniformLocation_mozilla;
842 i->fFunctions.fLineWidth = glLineWidth_mozilla;
843 i->fFunctions.fLinkProgram = glLinkProgram_mozilla;
844 i->fFunctions.fPixelStorei = glPixelStorei_mozilla;
845 i->fFunctions.fReadPixels = glReadPixels_mozilla;
846 i->fFunctions.fRenderbufferStorage = glRenderbufferStorage_mozilla;
847 i->fFunctions.fScissor = glScissor_mozilla;
848 i->fFunctions.fShaderSource = glShaderSource_mozilla;
849 i->fFunctions.fStencilFunc = glStencilFunc_mozilla;
850 i->fFunctions.fStencilMask = glStencilMask_mozilla;
851 i->fFunctions.fStencilOp = glStencilOp_mozilla;
852 i->fFunctions.fTexImage2D = glTexImage2D_mozilla;
853 i->fFunctions.fTexParameteri = glTexParameteri_mozilla;
854 i->fFunctions.fTexParameteriv = glTexParameteriv_mozilla;
855 i->fFunctions.fTexSubImage2D = glTexSubImage2D_mozilla;
856 i->fFunctions.fUniform1f = glUniform1f_mozilla;
857 i->fFunctions.fUniform1i = glUniform1i_mozilla;
858 i->fFunctions.fUniform1fv = glUniform1fv_mozilla;
859 i->fFunctions.fUniform1iv = glUniform1iv_mozilla;
860 i->fFunctions.fUniform2f = glUniform2f_mozilla;
861 i->fFunctions.fUniform2i = glUniform2i_mozilla;
862 i->fFunctions.fUniform2fv = glUniform2fv_mozilla;
863 i->fFunctions.fUniform2iv = glUniform2iv_mozilla;
864 i->fFunctions.fUniform3f = glUniform3f_mozilla;
865 i->fFunctions.fUniform3i = glUniform3i_mozilla;
866 i->fFunctions.fUniform3fv = glUniform3fv_mozilla;
867 i->fFunctions.fUniform3iv = glUniform3iv_mozilla;
868 i->fFunctions.fUniform4f = glUniform4f_mozilla;
869 i->fFunctions.fUniform4i = glUniform4i_mozilla;
870 i->fFunctions.fUniform4fv = glUniform4fv_mozilla;
871 i->fFunctions.fUniform4iv = glUniform4iv_mozilla;
872 i->fFunctions.fUniformMatrix2fv = glUniformMatrix2fv_mozilla;
873 i->fFunctions.fUniformMatrix3fv = glUniformMatrix3fv_mozilla;
874 i->fFunctions.fUniformMatrix4fv = glUniformMatrix4fv_mozilla;
875 i->fFunctions.fUseProgram = glUseProgram_mozilla;
876 i->fFunctions.fVertexAttrib4fv = glVertexAttrib4fv_mozilla;
877 i->fFunctions.fVertexAttribPointer = glVertexAttribPointer_mozilla;
878 i->fFunctions.fViewport = glViewport_mozilla;
880 // Required for either desktop OpenGL 2.0 or OpenGL ES 2.0
881 i->fFunctions.fStencilFuncSeparate = glStencilFuncSeparate_mozilla;
882 i->fFunctions.fStencilMaskSeparate = glStencilMaskSeparate_mozilla;
883 i->fFunctions.fStencilOpSeparate = glStencilOpSeparate_mozilla;
885 // GLContext supports glMapBuffer
886 i->fFunctions.fMapBuffer = glMapBuffer_mozilla;
887 i->fFunctions.fUnmapBuffer = glUnmapBuffer_mozilla;
889 // GLContext supports glRenderbufferStorageMultisample/glBlitFramebuffer
890 i->fFunctions.fRenderbufferStorageMultisample = glRenderbufferStorageMultisample_mozilla;
891 i->fFunctions.fBlitFramebuffer = glBlitFramebuffer_mozilla;
893 // GLContext supports glCompressedTexImage2D
894 i->fFunctions.fCompressedTexImage2D = glCompressedTexImage2D_mozilla;
896 // GL_OES_vertex_array_object
897 i->fFunctions.fBindVertexArray = glBindVertexArray_mozilla;
898 i->fFunctions.fDeleteVertexArrays = glDeleteVertexArrays_mozilla;
899 i->fFunctions.fGenVertexArrays = glGenVertexArrays_mozilla;
901 // Desktop GL
902 i->fFunctions.fGetTexLevelParameteriv = glGetTexLevelParameteriv_mozilla;
903 i->fFunctions.fDrawBuffer = glDrawBuffer_mozilla;
904 i->fFunctions.fReadBuffer = glReadBuffer_mozilla;
906 // Desktop OpenGL > 1.5
907 i->fFunctions.fGenQueries = glGenQueries_mozilla;
908 i->fFunctions.fDeleteQueries = glDeleteQueries_mozilla;
909 i->fFunctions.fBeginQuery = glBeginQuery_mozilla;
910 i->fFunctions.fEndQuery = glEndQuery_mozilla;
911 i->fFunctions.fGetQueryiv = glGetQueryiv_mozilla;
912 i->fFunctions.fGetQueryObjectiv = glGetQueryObjectiv_mozilla;
913 i->fFunctions.fGetQueryObjectuiv = glGetQueryObjectuiv_mozilla;
915 // Desktop OpenGL > 2.0
916 i->fFunctions.fDrawBuffers = glDrawBuffers_mozilla;
918 // Desktop OpenGL < 3.2 (which we pretend to be)
919 i->fFunctions.fLoadIdentity = glLoadIdentity_mozilla;
920 i->fFunctions.fLoadMatrixf = glLoadMatrixf_mozilla;
921 i->fFunctions.fMatrixMode = glMatrixMode_mozilla;
922 i->fFunctions.fTexGenfv = glTexGenfv_mozilla;
923 i->fFunctions.fTexGeni = glTexGeni_mozilla;
925 return i;
926 }
928 SkiaGLGlue::SkiaGLGlue(GLContext* context)
929 : mGLContext(context)
930 {
931 SkAutoTUnref<GrGLInterface> i(CreateGrGLInterfaceFromGLContext(mGLContext));
932 i->fCallbackData = reinterpret_cast<GrGLInterfaceCallbackData>(this);
933 mGrGLInterface = i;
934 SkAutoTUnref<GrContext> gr(GrContext::Create(kOpenGL_GrBackend, (GrBackendContext)mGrGLInterface.get()));
936 mGrContext = gr;
937 }