OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 | |
6 #include "app/gfx/gl/gl_bindings_skia.h" | |
7 | |
8 #include "app/gfx/gl/gl_bindings.h" | |
9 #include "app/gfx/gl/gl_implementation.h" | |
10 #include "base/logging.h" | |
11 | |
12 // Skia is built against the headers in gpu\GLES. These functions | |
13 // are exported without any call-type modifiers. | |
14 #define GR_GL_FUNCTION_TYPE | |
15 | |
16 // The GrGLInterface header pulls in the default GL headers. Disable pulling | |
17 // in the default platform headers to prevent conflicts with the GL api points | |
18 // included via gl_bindings.h | |
19 #define GR_GL_NO_PLATFORM_INCLUDES 1 | |
20 #include "third_party/skia/gpu/include/GrGLInterface.h" | |
21 #undef GR_GL_NO_PLATFORM_INCLUDES | |
22 | |
23 namespace { | |
24 | |
25 extern "C" { | |
26 | |
27 // The following stub functions are required because the glXXX routines exported | |
28 // via gl_bindings.h use call-type GL_BINDING_CALL, which on Windows is stdcall. | |
29 // Skia has been built against the GLES headers, so the interfaces in | |
30 // GrGLInterface are __cdecl. | |
31 | |
32 GLvoid StubGLActiveTexture(GLenum texture) { | |
33 glActiveTexture(texture); | |
34 } | |
35 | |
36 GLvoid StubGLAttachShader(GLuint program, GLuint shader) { | |
37 glAttachShader(program, shader); | |
38 } | |
39 | |
40 GLvoid StubGLBindAttribLocation(GLuint program, GLuint index, | |
41 const char* name) { | |
42 glBindAttribLocation(program, index, name); | |
43 } | |
44 | |
45 GLvoid StubGLBindBuffer(GLenum target, GLuint buffer) { | |
46 glBindBuffer(target, buffer); | |
47 } | |
48 | |
49 GLvoid StubGLBindFramebuffer(GLenum target, GLuint framebuffer) { | |
50 glBindFramebufferEXT(target, framebuffer); | |
51 } | |
52 | |
53 GLvoid StubGLBindRenderbuffer(GLenum target, GLuint renderbuffer) { | |
54 glBindRenderbufferEXT(target, renderbuffer); | |
55 } | |
56 | |
57 GLvoid StubGLBindTexture(GLenum target, GLuint texture) { | |
58 glBindTexture(target, texture); | |
59 } | |
60 | |
61 GLvoid StubGLBlendColor(GLclampf red, GLclampf green, GLclampf blue, | |
62 GLclampf alpha) { | |
63 glBlendColor(red, green, blue, alpha); | |
64 } | |
65 | |
66 GLvoid StubGLBlendFunc(GLenum sfactor, GLenum dfactor) { | |
67 glBlendFunc(sfactor, dfactor); | |
68 } | |
69 | |
70 GLvoid StubGLBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, | |
71 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, | |
72 GLbitfield mask, GLenum filter) { | |
73 glBlitFramebufferEXT(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, | |
74 mask, filter); | |
75 } | |
76 | |
77 GLvoid StubGLBufferData(GLenum target, GLsizei size, const void* data, | |
78 GLenum usage) { | |
79 glBufferData(target, size, data, usage); | |
80 } | |
81 | |
82 GLvoid StubGLBufferSubData(GLenum target, GLint offset, GLsizei size, | |
83 const void* data) { | |
84 glBufferSubData(target, offset, size, data); | |
85 } | |
86 | |
87 GLenum StubGLCheckFramebufferStatus(GLenum target) { | |
88 return glCheckFramebufferStatusEXT(target); | |
89 } | |
90 | |
91 GLvoid StubGLClear(GLbitfield mask) { | |
92 glClear(mask); | |
93 } | |
94 | |
95 GLvoid StubGLClearColor(GLclampf red, GLclampf green, GLclampf blue, | |
96 GLclampf alpha) { | |
97 glClearColor(red, green, blue, alpha); | |
98 } | |
99 | |
100 GLvoid StubGLClearStencil(GLint s) { | |
101 glClearStencil(s); | |
102 } | |
103 | |
104 GLvoid StubGLColorMask(GLboolean red, GLboolean green, GLboolean blue, | |
105 GLboolean alpha) { | |
106 glColorMask(red, green, blue, alpha); | |
107 } | |
108 | |
109 GLvoid StubGLCompileShader(GLuint shader) { | |
110 glCompileShader(shader); | |
111 } | |
112 | |
113 GLvoid StubGLCompressedTexImage2D(GLenum target, GLint level, | |
114 GLenum internalformat, GLsizei width, | |
115 GLsizei height, GLint border, | |
116 GLsizei imageSize, const void* data) { | |
117 glCompressedTexImage2D(target, level, internalformat, width, height, border, | |
118 imageSize, data); | |
119 } | |
120 | |
121 GLuint StubGLCreateProgram(void) { | |
122 return glCreateProgram(); | |
123 } | |
124 | |
125 GLuint StubGLCreateShader(GLenum type) { | |
126 return glCreateShader(type); | |
127 } | |
128 | |
129 GLvoid StubGLCullFace(GLenum mode) { | |
130 glCullFace(mode); | |
131 } | |
132 | |
133 GLvoid StubGLDeleteBuffers(GLsizei n, const GLuint* buffers) { | |
134 glDeleteBuffersARB(n, buffers); | |
135 } | |
136 | |
137 GLvoid StubGLDeleteFramebuffers(GLsizei n, const GLuint* framebuffers) { | |
138 glDeleteFramebuffersEXT(n, framebuffers); | |
139 } | |
140 | |
141 GLvoid StubGLDeleteProgram(GLuint program) { | |
142 glDeleteProgram(program); | |
143 } | |
144 | |
145 GLvoid StubGLDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers) { | |
146 glDeleteRenderbuffersEXT(n, renderbuffers); | |
147 } | |
148 | |
149 GLvoid StubGLDeleteShader(GLuint shader) { | |
150 glDeleteShader(shader); | |
151 } | |
152 | |
153 GLvoid StubGLDeleteTextures(GLsizei n, const GLuint* textures) { | |
154 glDeleteTextures(n, textures); | |
155 } | |
156 | |
157 GLvoid StubGLDepthMask(GLboolean flag) { | |
158 glDepthMask(flag); | |
159 } | |
160 | |
161 GLvoid StubGLDisable(GLenum cap) { | |
162 glDisable(cap); | |
163 } | |
164 | |
165 GLvoid StubGLDisableVertexAttribArray(GLuint index) { | |
166 glDisableVertexAttribArray(index); | |
167 } | |
168 | |
169 GLvoid StubGLDrawArrays(GLenum mode, GLint first, GLsizei count) { | |
170 glDrawArrays(mode, first, count); | |
171 } | |
172 | |
173 GLvoid StubGLDrawElements(GLenum mode, GLsizei count, GLenum type, | |
174 const void* indices) { | |
175 glDrawElements(mode, count, type, indices); | |
176 } | |
177 | |
178 GLvoid StubGLEnable(GLenum cap) { | |
179 glEnable(cap); | |
180 } | |
181 | |
182 GLvoid StubGLEnableVertexAttribArray(GLuint index) { | |
183 glEnableVertexAttribArray(index); | |
184 } | |
185 | |
186 GLvoid StubGLFramebufferRenderbuffer(GLenum target, GLenum attachment, | |
187 GLenum renderbuffertarget, | |
188 GLuint renderbuffer) { | |
189 glFramebufferRenderbufferEXT(target, attachment, renderbuffertarget, | |
190 renderbuffer); | |
191 } | |
192 | |
193 GLvoid StubGLFramebufferTexture2D(GLenum target, GLenum attachment, | |
194 GLenum textarget, GLuint texture, | |
195 GLint level) { | |
196 glFramebufferTexture2DEXT(target, attachment, textarget, texture, level); | |
197 } | |
198 | |
199 GLvoid StubGLFrontFace(GLenum mode) { | |
200 glFrontFace(mode); | |
201 } | |
202 | |
203 GLvoid StubGLGenBuffers(GLsizei n, GLuint* buffers) { | |
204 glGenBuffersARB(n, buffers); | |
205 } | |
206 | |
207 GLvoid StubGLGenFramebuffers(GLsizei n, GLuint* framebuffers) { | |
208 glGenFramebuffersEXT(n, framebuffers); | |
209 } | |
210 | |
211 GLvoid StubGLGenRenderbuffers(GLsizei n, GLuint* renderbuffers) { | |
212 glGenRenderbuffersEXT(n, renderbuffers); | |
213 } | |
214 | |
215 GLvoid StubGLGenTextures(GLsizei n, GLuint* textures) { | |
216 glGenTextures(n, textures); | |
217 } | |
218 | |
219 GLvoid StubGLGetBufferParameteriv(GLenum target, GLenum pname, GLint* params) { | |
220 glGetBufferParameteriv(target, pname, params); | |
221 } | |
222 | |
223 GLenum StubGLGetError() { | |
224 return glGetError(); | |
225 } | |
226 | |
227 GLvoid StubGLGetIntegerv(GLenum pname, GLint* params) { | |
228 glGetIntegerv(pname, params); | |
229 } | |
230 | |
231 GLvoid StubGLGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, | |
232 char* infolog) { | |
233 glGetProgramInfoLog(program, bufsize, length, infolog); | |
234 } | |
235 | |
236 GLvoid StubGLGetProgramiv(GLuint program, GLenum pname, GLint* params) { | |
237 glGetProgramiv(program, pname, params); | |
238 } | |
239 | |
240 GLvoid StubGLGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, | |
241 char* infolog) { | |
242 glGetShaderInfoLog(shader, bufsize, length, infolog); | |
243 } | |
244 | |
245 GLvoid StubGLGetShaderiv(GLuint shader, GLenum pname, GLint* params) { | |
246 glGetShaderiv(shader, pname, params); | |
247 } | |
248 | |
249 const GLubyte* StubGLGetString(GLenum name) { | |
250 return glGetString(name); | |
251 } | |
252 | |
253 GLint StubGLGetUniformLocation(GLuint program, const char* name) { | |
254 return glGetUniformLocation(program, name); | |
255 } | |
256 | |
257 GLvoid StubGLLineWidth(GLfloat width) { | |
258 glLineWidth(width); | |
259 } | |
260 | |
261 GLvoid StubGLLinkProgram(GLuint program) { | |
262 glLinkProgram(program); | |
263 } | |
264 | |
265 void* StubGLMapBuffer(GLenum target, GLenum access) { | |
266 return glMapBuffer(target, access); | |
267 } | |
268 | |
269 GLvoid StubGLPixelStorei(GLenum pname, GLint param) { | |
270 glPixelStorei(pname, param); | |
271 } | |
272 | |
273 GLvoid StubGLReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, | |
274 GLenum format, GLenum type, void* pixels) { | |
275 glReadPixels(x, y, width, height, format, type, pixels); | |
276 } | |
277 | |
278 GLvoid StubGLRenderBufferStorage(GLenum target, GLenum internalformat, | |
279 GLsizei width, GLsizei height) { | |
280 glRenderbufferStorageEXT(target, internalformat, width, height); | |
281 } | |
282 | |
283 GLvoid StubGLRenderbufferStorageMultisample(GLenum target, GLsizei samples, | |
284 GLenum internalformat, | |
285 GLsizei width, GLsizei height) { | |
286 glRenderbufferStorageMultisampleEXT(target, samples, internalformat, width, | |
287 height); | |
288 } | |
289 | |
290 GLvoid StubGLScissor(GLint x, GLint y, GLsizei width, GLsizei height) { | |
291 glScissor(x, y, width, height); | |
292 } | |
293 | |
294 GLvoid StubGLShaderSource(GLuint shader, GLsizei count, const char** str, | |
295 const GLint* length) { | |
296 glShaderSource(shader, count, str, length); | |
297 } | |
298 | |
299 GLvoid StubGLStencilFunc(GLenum func, GLint ref, GLuint mask) { | |
300 glStencilFunc(func, ref, mask); | |
301 } | |
302 | |
303 GLvoid StubGLStencilFuncSeparate(GLenum face, GLenum func, GLint ref, | |
304 GLuint mask) { | |
305 glStencilFuncSeparate(face, func, ref, mask); | |
306 } | |
307 | |
308 GLvoid StubGLStencilMask(GLuint mask) { | |
309 glStencilMask(mask); | |
310 } | |
311 | |
312 GLvoid StubGLStencilMaskSeparate(GLenum face, GLuint mask) { | |
313 glStencilMaskSeparate(face, mask); | |
314 } | |
315 | |
316 GLvoid StubGLStencilOp(GLenum fail, GLenum zfail, GLenum zpass) { | |
317 glStencilOp(fail, zfail, zpass); | |
318 } | |
319 | |
320 GLvoid StubGLStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, | |
321 GLenum zpass) { | |
322 glStencilOpSeparate(face, fail, zfail, zpass); | |
323 } | |
324 | |
325 GLvoid StubGLTexImage2D(GLenum target, GLint level, GLint internalformat, | |
326 GLsizei width, GLsizei height, GLint border, | |
327 GLenum format, GLenum type, const void* pixels) { | |
328 glTexImage2D(target, level, internalformat, width, height, border, format, | |
329 type, pixels); | |
330 } | |
331 | |
332 GLvoid StubGLTexParameteri(GLenum target, GLenum pname, GLint param) { | |
333 glTexParameteri(target, pname, param); | |
334 } | |
335 | |
336 GLvoid StubGLTexSubImage2D(GLenum target, GLint level, GLint xoffset, | |
337 GLint yoffset, GLsizei width, GLsizei height, | |
338 GLenum format, GLenum type, const void* pixels) { | |
339 glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, | |
340 pixels); | |
341 } | |
342 | |
343 GLvoid StubGLUniform1fv(GLint location, GLsizei count, const GLfloat* v) { | |
344 glUniform1fv(location, count, v); | |
345 } | |
346 | |
347 GLvoid StubGLUniform1i(GLint location, GLint x) { | |
348 glUniform1i(location, x); | |
349 } | |
350 | |
351 GLvoid StubGLUniform4fv(GLint location, GLsizei count, const GLfloat* v) { | |
352 glUniform4fv(location, count, v); | |
353 } | |
354 | |
355 GLvoid StubGLUniformMatrix3fv(GLint location, GLsizei count, | |
356 GLboolean transpose, const GLfloat* value) { | |
357 glUniformMatrix3fv(location, count, transpose, value); | |
358 } | |
359 | |
360 GLboolean StubGLUnmapBuffer(GLenum target) { | |
361 return glUnmapBuffer(target); | |
362 } | |
363 | |
364 GLvoid StubGLUseProgram(GLuint program) { | |
365 glUseProgram(program); | |
366 } | |
367 | |
368 GLvoid StubGLVertexAttrib4fv(GLuint indx, const GLfloat* values) { | |
369 glVertexAttrib4fv(indx, values); | |
370 } | |
371 | |
372 GLvoid StubGLVertexAttribPointer(GLuint indx, GLint size, GLenum type, | |
373 GLboolean normalized, GLsizei stride, | |
374 const void* ptr) { | |
375 glVertexAttribPointer(indx, size, type, normalized, stride, ptr); | |
376 } | |
377 | |
378 GLvoid StubGLViewport(GLint x, GLint y, GLsizei width, GLsizei height) { | |
379 glViewport(x, y, width, height); | |
380 } | |
381 | |
382 } // extern "C" | |
383 | |
384 // Populate |gl_interface| with pointers to the GL implementation used by | |
385 // Chrome. | |
386 void InitializeGrGLInterface(GrGLInterface* gl_interface) { | |
387 | |
388 // Propagate the type of GL bindings exported back to skia. | |
389 switch (gfx::GetGLImplementation()) { | |
390 case gfx::kGLImplementationNone: | |
391 NOTREACHED(); | |
392 break; | |
393 case gfx::kGLImplementationDesktopGL: | |
394 gl_interface->fBindingsExported = kDesktop_GrGLBinding; | |
395 break; | |
396 case gfx::kGLImplementationOSMesaGL: | |
397 gl_interface->fBindingsExported = kDesktop_GrGLBinding; | |
398 break; | |
399 case gfx::kGLImplementationEGLGLES2: | |
400 gl_interface->fBindingsExported = kES2_GrGLBinding; | |
401 break; | |
402 case gfx::kGLImplementationMockGL: | |
403 NOTREACHED(); | |
404 break; | |
405 } | |
406 | |
407 gl_interface->fClientActiveTexture = NULL; | |
408 gl_interface->fColor4ub = NULL; | |
409 gl_interface->fColorPointer = NULL; | |
410 gl_interface->fDisableClientState = NULL; | |
411 gl_interface->fEnableClientState = NULL; | |
412 gl_interface->fLoadMatrixf = NULL; | |
413 gl_interface->fMatrixMode = NULL; | |
414 gl_interface->fPointSize = NULL; | |
415 gl_interface->fShadeModel = NULL; | |
416 gl_interface->fTexCoordPointer = NULL; | |
417 gl_interface->fTexEnvi = NULL; | |
418 gl_interface->fVertexPointer = NULL; | |
419 | |
420 gl_interface->fFramebufferTexture2DMultisample = NULL; | |
421 gl_interface->fResolveMultisampleFramebuffer = NULL; | |
422 gl_interface->fActiveTexture = StubGLActiveTexture; | |
423 gl_interface->fAttachShader = StubGLAttachShader; | |
424 gl_interface->fBindAttribLocation = StubGLBindAttribLocation; | |
425 gl_interface->fBindBuffer = StubGLBindBuffer; | |
426 gl_interface->fBindTexture = StubGLBindTexture; | |
427 gl_interface->fBlendColor = StubGLBlendColor; | |
428 gl_interface->fBlendFunc = StubGLBlendFunc; | |
429 gl_interface->fBufferData = StubGLBufferData; | |
430 gl_interface->fBufferSubData = StubGLBufferSubData; | |
431 gl_interface->fClear = StubGLClear; | |
432 gl_interface->fClearColor = StubGLClearColor; | |
433 gl_interface->fClearStencil = StubGLClearStencil; | |
434 gl_interface->fColorMask = StubGLColorMask; | |
435 gl_interface->fCompileShader = StubGLCompileShader; | |
436 gl_interface->fCompressedTexImage2D = StubGLCompressedTexImage2D; | |
437 gl_interface->fCreateProgram = StubGLCreateProgram; | |
438 gl_interface->fCreateShader = StubGLCreateShader; | |
439 gl_interface->fCullFace = StubGLCullFace; | |
440 gl_interface->fDeleteBuffers = StubGLDeleteBuffers; | |
441 gl_interface->fDeleteProgram = StubGLDeleteProgram; | |
442 gl_interface->fDeleteShader = StubGLDeleteShader; | |
443 gl_interface->fDeleteTextures = StubGLDeleteTextures; | |
444 gl_interface->fDepthMask = StubGLDepthMask; | |
445 gl_interface->fDisable = StubGLDisable; | |
446 gl_interface->fDisableVertexAttribArray = StubGLDisableVertexAttribArray; | |
447 gl_interface->fDrawArrays = StubGLDrawArrays; | |
448 gl_interface->fDrawElements = StubGLDrawElements; | |
449 gl_interface->fEnable = StubGLEnable; | |
450 gl_interface->fEnableVertexAttribArray = StubGLEnableVertexAttribArray; | |
451 gl_interface->fFrontFace = StubGLFrontFace; | |
452 gl_interface->fGenBuffers = StubGLGenBuffers; | |
453 gl_interface->fGenTextures = StubGLGenTextures; | |
454 gl_interface->fGetBufferParameteriv = StubGLGetBufferParameteriv; | |
455 gl_interface->fGetError = StubGLGetError; | |
456 gl_interface->fGetIntegerv = StubGLGetIntegerv; | |
457 gl_interface->fGetProgramInfoLog = StubGLGetProgramInfoLog; | |
458 gl_interface->fGetProgramiv = StubGLGetProgramiv; | |
459 gl_interface->fGetShaderInfoLog = StubGLGetShaderInfoLog; | |
460 gl_interface->fGetShaderiv = StubGLGetShaderiv; | |
461 gl_interface->fGetString = StubGLGetString; | |
462 gl_interface->fGetUniformLocation = StubGLGetUniformLocation; | |
463 gl_interface->fLineWidth = StubGLLineWidth; | |
464 gl_interface->fLinkProgram = StubGLLinkProgram; | |
465 gl_interface->fPixelStorei = StubGLPixelStorei; | |
466 gl_interface->fReadPixels = StubGLReadPixels; | |
467 gl_interface->fScissor = StubGLScissor; | |
468 gl_interface->fShaderSource = StubGLShaderSource; | |
469 gl_interface->fStencilFunc = StubGLStencilFunc; | |
470 gl_interface->fStencilFuncSeparate = StubGLStencilFuncSeparate; | |
471 gl_interface->fStencilMask = StubGLStencilMask; | |
472 gl_interface->fStencilMaskSeparate = StubGLStencilMaskSeparate; | |
473 gl_interface->fStencilOp = StubGLStencilOp; | |
474 gl_interface->fStencilOpSeparate = StubGLStencilOpSeparate; | |
475 gl_interface->fTexImage2D = StubGLTexImage2D; | |
476 gl_interface->fTexParameteri = StubGLTexParameteri; | |
477 gl_interface->fTexSubImage2D = StubGLTexSubImage2D; | |
478 gl_interface->fUniform1fv = StubGLUniform1fv; | |
479 gl_interface->fUniform1i = StubGLUniform1i; | |
480 gl_interface->fUniform4fv = StubGLUniform4fv; | |
481 gl_interface->fUniformMatrix3fv = StubGLUniformMatrix3fv; | |
482 gl_interface->fUseProgram = StubGLUseProgram; | |
483 gl_interface->fVertexAttrib4fv = StubGLVertexAttrib4fv; | |
484 gl_interface->fVertexAttribPointer = StubGLVertexAttribPointer; | |
485 gl_interface->fViewport = StubGLViewport; | |
486 gl_interface->fBindFramebuffer = StubGLBindFramebuffer; | |
487 gl_interface->fBindRenderbuffer = StubGLBindRenderbuffer; | |
488 gl_interface->fCheckFramebufferStatus = StubGLCheckFramebufferStatus; | |
489 gl_interface->fDeleteFramebuffers = StubGLDeleteFramebuffers; | |
490 gl_interface->fDeleteRenderbuffers = StubGLDeleteRenderbuffers; | |
491 gl_interface->fFramebufferRenderbuffer = StubGLFramebufferRenderbuffer; | |
492 gl_interface->fFramebufferTexture2D = StubGLFramebufferTexture2D; | |
493 gl_interface->fGenFramebuffers = StubGLGenFramebuffers; | |
494 gl_interface->fGenRenderbuffers = StubGLGenRenderbuffers; | |
495 gl_interface->fRenderbufferStorage = StubGLRenderBufferStorage; | |
496 gl_interface->fRenderbufferStorageMultisample = | |
497 StubGLRenderbufferStorageMultisample; | |
498 gl_interface->fBlitFramebuffer = StubGLBlitFramebuffer; | |
499 gl_interface->fMapBuffer = StubGLMapBuffer; | |
500 gl_interface->fUnmapBuffer = StubGLUnmapBuffer; | |
501 } | |
502 | |
503 } // namespace | |
504 | |
505 namespace gfx { | |
506 | |
507 void BindSkiaToHostGL() { | |
508 static GrGLInterface host_gl_interface; | |
509 static bool host_StubGL_initialized = false; | |
510 if (!host_StubGL_initialized) { | |
511 InitializeGrGLInterface(&host_gl_interface); | |
512 GrGLSetGLInterface(&host_gl_interface); | |
513 host_StubGL_initialized = true; | |
514 } | |
515 } | |
516 | |
517 } // namespace gfx | |
OLD | NEW |