Add GCMChannelStatusSyncer to schedule requests and enable/disable GCM
[chromium-blink-merge.git] / ui / gl / generate_bindings.py
blob16fd009597424ec102054fe03f90ea53992c9ca5
1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 """code generator for GL/GLES extension wrangler."""
8 import optparse
9 import os
10 import collections
11 import re
12 import sys
14 """In case there are multiple versions of the same function, one that's listed
15 first takes priority if its conditions are met. If the function is an extension
16 function, finding the extension from the extension string is a condition for
17 binding it. The last version of the function is treated as a fallback option in
18 case no other versions were bound, so a non-null function pointer in the
19 bindings does not guarantee that the function is supported.
21 Function binding conditions can be specified manually by supplying a versions
22 array instead of the names array. Each version has the following keys:
23 name: Mandatory. Name of the function. Multiple versions can have the same
24 name but different conditions.
25 gl_versions: List of GL versions where the function is found.
26 extensions: Extensions where the function is found. If not specified, the
27 extensions are determined based on GL header files.
28 If the function exists in an extension header, you may specify
29 an empty array to prevent making that a condition for binding.
31 By default, the function gets its name from the first name in its names or
32 versions array. This can be overridden by supplying a 'known_as' key.
33 """
34 GL_FUNCTIONS = [
35 { 'return_type': 'void',
36 'names': ['glActiveTexture'],
37 'arguments': 'GLenum texture', },
38 { 'return_type': 'void',
39 'names': ['glAttachShader'],
40 'arguments': 'GLuint program, GLuint shader', },
41 { 'return_type': 'void',
42 'names': ['glBeginQuery'],
43 'arguments': 'GLenum target, GLuint id', },
44 { 'return_type': 'void',
45 'names': ['glBeginQueryARB', 'glBeginQueryEXT'],
46 'arguments': 'GLenum target, GLuint id', },
47 { 'return_type': 'void',
48 'names': ['glBindAttribLocation'],
49 'arguments': 'GLuint program, GLuint index, const char* name', },
50 { 'return_type': 'void',
51 'names': ['glBindBuffer'],
52 'arguments': 'GLenum target, GLuint buffer', },
53 { 'return_type': 'void',
54 'names': ['glBindFragDataLocation'],
55 'arguments': 'GLuint program, GLuint colorNumber, const char* name', },
56 { 'return_type': 'void',
57 'names': ['glBindFragDataLocationIndexed'],
58 'arguments':
59 'GLuint program, GLuint colorNumber, GLuint index, const char* name', },
60 { 'return_type': 'void',
61 'names': ['glBindFramebufferEXT', 'glBindFramebuffer'],
62 'arguments': 'GLenum target, GLuint framebuffer', },
63 { 'return_type': 'void',
64 'names': ['glBindRenderbufferEXT', 'glBindRenderbuffer'],
65 'arguments': 'GLenum target, GLuint renderbuffer', },
66 { 'return_type': 'void',
67 'names': ['glBindTexture'],
68 'arguments': 'GLenum target, GLuint texture', },
69 { 'return_type': 'void',
70 'names': ['glBlendColor'],
71 'arguments': 'GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha', },
72 { 'return_type': 'void',
73 'names': ['glBlendEquation'],
74 'arguments': ' GLenum mode ', },
75 { 'return_type': 'void',
76 'names': ['glBlendEquationSeparate'],
77 'arguments': 'GLenum modeRGB, GLenum modeAlpha', },
78 { 'return_type': 'void',
79 'names': ['glBlendFunc'],
80 'arguments': 'GLenum sfactor, GLenum dfactor', },
81 { 'return_type': 'void',
82 'names': ['glBlendFuncSeparate'],
83 'arguments':
84 'GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha', },
85 { 'return_type': 'void',
86 'names': ['glBlitFramebuffer'],
87 'arguments': 'GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, '
88 'GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, '
89 'GLbitfield mask, GLenum filter', },
90 { 'return_type': 'void',
91 'names': ['glBlitFramebufferEXT', 'glBlitFramebuffer'],
92 'arguments': 'GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, '
93 'GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, '
94 'GLbitfield mask, GLenum filter', },
95 { 'return_type': 'void',
96 'names': ['glBlitFramebufferANGLE', 'glBlitFramebuffer'],
97 'arguments': 'GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, '
98 'GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, '
99 'GLbitfield mask, GLenum filter', },
100 { 'return_type': 'void',
101 'names': ['glBufferData'],
102 'arguments':
103 'GLenum target, GLsizeiptr size, const void* data, GLenum usage', },
104 { 'return_type': 'void',
105 'names': ['glBufferSubData'],
106 'arguments':
107 'GLenum target, GLintptr offset, GLsizeiptr size, const void* data', },
108 { 'return_type': 'GLenum',
109 'names': ['glCheckFramebufferStatusEXT',
110 'glCheckFramebufferStatus'],
111 'arguments': 'GLenum target',
112 'logging_code': """
113 GL_SERVICE_LOG("GL_RESULT: " << GLES2Util::GetStringEnum(result));
114 """, },
115 { 'return_type': 'void',
116 'names': ['glClear'],
117 'arguments': 'GLbitfield mask', },
118 { 'return_type': 'void',
119 'names': ['glClearColor'],
120 'arguments': 'GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha', },
121 { 'return_type': 'void',
122 'names': ['glClearDepth'],
123 'arguments': 'GLclampd depth', },
124 { 'return_type': 'void',
125 'names': ['glClearDepthf'],
126 'arguments': 'GLclampf depth', },
127 { 'return_type': 'void',
128 'names': ['glClearStencil'],
129 'arguments': 'GLint s', },
130 { 'return_type': 'void',
131 'names': ['glColorMask'],
132 'arguments':
133 'GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha', },
134 { 'return_type': 'void',
135 'names': ['glCompileShader'],
136 'arguments': 'GLuint shader', },
137 { 'return_type': 'void',
138 'names': ['glCompressedTexImage2D'],
139 'arguments':
140 'GLenum target, GLint level, GLenum internalformat, GLsizei width, '
141 'GLsizei height, GLint border, GLsizei imageSize, const void* data', },
142 { 'return_type': 'void',
143 'names': ['glCompressedTexSubImage2D'],
144 'arguments':
145 'GLenum target, GLint level, GLint xoffset, GLint yoffset, '
146 'GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, '
147 'const void* data', },
148 { 'return_type': 'void',
149 'names': ['glCopyTexImage2D'],
150 'arguments':
151 'GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, '
152 'GLsizei width, GLsizei height, GLint border', },
153 { 'return_type': 'void',
154 'names': ['glCopyTexSubImage2D'],
155 'arguments':
156 'GLenum target, GLint level, GLint xoffset, '
157 'GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height', },
158 { 'return_type': 'GLuint',
159 'names': ['glCreateProgram'],
160 'arguments': 'void', },
161 { 'return_type': 'GLuint',
162 'names': ['glCreateShader'],
163 'arguments': 'GLenum type', },
164 { 'return_type': 'void',
165 'names': ['glCullFace'],
166 'arguments': 'GLenum mode', },
167 { 'return_type': 'void',
168 'names': ['glDeleteBuffersARB', 'glDeleteBuffers'],
169 'arguments': 'GLsizei n, const GLuint* buffers', },
170 { 'return_type': 'void',
171 'names': ['glDeleteFramebuffersEXT', 'glDeleteFramebuffers'],
172 'arguments': 'GLsizei n, const GLuint* framebuffers', },
173 { 'return_type': 'void',
174 'names': ['glDeleteProgram'],
175 'arguments': 'GLuint program', },
176 { 'return_type': 'void',
177 'names': ['glDeleteQueries'],
178 'arguments': 'GLsizei n, const GLuint* ids', },
179 { 'return_type': 'void',
180 'names': ['glDeleteQueriesARB', 'glDeleteQueriesEXT'],
181 'arguments': 'GLsizei n, const GLuint* ids', },
182 { 'return_type': 'void',
183 'names': ['glDeleteRenderbuffersEXT', 'glDeleteRenderbuffers'],
184 'arguments': 'GLsizei n, const GLuint* renderbuffers', },
185 { 'return_type': 'void',
186 'names': ['glDeleteShader'],
187 'arguments': 'GLuint shader', },
188 { 'return_type': 'void',
189 'names': ['glDeleteTextures'],
190 'arguments': 'GLsizei n, const GLuint* textures', },
191 { 'return_type': 'void',
192 'names': ['glDepthFunc'],
193 'arguments': 'GLenum func', },
194 { 'return_type': 'void',
195 'names': ['glDepthMask'],
196 'arguments': 'GLboolean flag', },
197 { 'return_type': 'void',
198 'names': ['glDepthRange'],
199 'arguments': 'GLclampd zNear, GLclampd zFar', },
200 { 'return_type': 'void',
201 'names': ['glDepthRangef'],
202 'arguments': 'GLclampf zNear, GLclampf zFar', },
203 { 'return_type': 'void',
204 'names': ['glDetachShader'],
205 'arguments': 'GLuint program, GLuint shader', },
206 { 'return_type': 'void',
207 'names': ['glDisable'],
208 'arguments': 'GLenum cap', },
209 { 'return_type': 'void',
210 'names': ['glDisableVertexAttribArray'],
211 'arguments': 'GLuint index', },
212 { 'return_type': 'void',
213 'names': ['glDrawArrays'],
214 'arguments': 'GLenum mode, GLint first, GLsizei count', },
215 { 'return_type': 'void',
216 'names': ['glDrawBuffer'],
217 'arguments': 'GLenum mode', },
218 { 'return_type': 'void',
219 'names': ['glDrawBuffersARB', 'glDrawBuffersEXT'],
220 'arguments': 'GLsizei n, const GLenum* bufs', },
221 { 'return_type': 'void',
222 'names': ['glDrawElements'],
223 'arguments':
224 'GLenum mode, GLsizei count, GLenum type, const void* indices', },
225 { 'return_type': 'void',
226 'names': ['glEGLImageTargetTexture2DOES'],
227 'arguments': 'GLenum target, GLeglImageOES image', },
228 { 'return_type': 'void',
229 'names': ['glEGLImageTargetRenderbufferStorageOES'],
230 'arguments': 'GLenum target, GLeglImageOES image', },
231 { 'return_type': 'void',
232 'names': ['glEnable'],
233 'arguments': 'GLenum cap', },
234 { 'return_type': 'void',
235 'names': ['glEnableVertexAttribArray'],
236 'arguments': 'GLuint index', },
237 { 'return_type': 'void',
238 'names': ['glEndQuery'],
239 'arguments': 'GLenum target', },
240 { 'return_type': 'void',
241 'names': ['glEndQueryARB', 'glEndQueryEXT'],
242 'arguments': 'GLenum target', },
243 { 'return_type': 'void',
244 'names': ['glFinish'],
245 'arguments': 'void', },
246 { 'return_type': 'void',
247 'names': ['glFlush'],
248 'arguments': 'void', },
249 { 'return_type': 'void',
250 'names': ['glFramebufferRenderbufferEXT', 'glFramebufferRenderbuffer'],
251 'arguments': \
252 'GLenum target, GLenum attachment, GLenum renderbuffertarget, '
253 'GLuint renderbuffer', },
254 { 'return_type': 'void',
255 'names': ['glFramebufferTexture2DEXT', 'glFramebufferTexture2D'],
256 'arguments':
257 'GLenum target, GLenum attachment, GLenum textarget, GLuint texture, '
258 'GLint level', },
259 { 'return_type': 'void',
260 'names': ['glFramebufferTexture2DMultisampleEXT'],
261 'arguments':
262 'GLenum target, GLenum attachment, GLenum textarget, GLuint texture, '
263 'GLint level, GLsizei samples', },
264 { 'return_type': 'void',
265 'names': ['glFramebufferTexture2DMultisampleIMG'],
266 'arguments':
267 'GLenum target, GLenum attachment, GLenum textarget, GLuint texture, '
268 'GLint level, GLsizei samples', },
269 { 'return_type': 'void',
270 'names': ['glFrontFace'],
271 'arguments': 'GLenum mode', },
272 { 'return_type': 'void',
273 'names': ['glGenBuffersARB', 'glGenBuffers'],
274 'arguments': 'GLsizei n, GLuint* buffers', },
275 { 'return_type': 'void',
276 'names': ['glGenQueries'],
277 'arguments': 'GLsizei n, GLuint* ids', },
278 { 'return_type': 'void',
279 'names': ['glGenQueriesARB', 'glGenQueriesEXT'],
280 'arguments': 'GLsizei n, GLuint* ids', },
281 { 'return_type': 'void',
282 'names': ['glGenerateMipmapEXT', 'glGenerateMipmap'],
283 'arguments': 'GLenum target', },
284 { 'return_type': 'void',
285 'names': ['glGenFramebuffersEXT', 'glGenFramebuffers'],
286 'arguments': 'GLsizei n, GLuint* framebuffers', },
287 { 'return_type': 'void',
288 'names': ['glGenRenderbuffersEXT', 'glGenRenderbuffers'],
289 'arguments': 'GLsizei n, GLuint* renderbuffers', },
290 { 'return_type': 'void',
291 'names': ['glGenTextures'],
292 'arguments': 'GLsizei n, GLuint* textures', },
293 { 'return_type': 'void',
294 'names': ['glGetActiveAttrib'],
295 'arguments':
296 'GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, '
297 'GLint* size, GLenum* type, char* name', },
298 { 'return_type': 'void',
299 'names': ['glGetActiveUniform'],
300 'arguments':
301 'GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, '
302 'GLint* size, GLenum* type, char* name', },
303 { 'return_type': 'void',
304 'names': ['glGetAttachedShaders'],
305 'arguments':
306 'GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders', },
307 { 'return_type': 'GLint',
308 'names': ['glGetAttribLocation'],
309 'arguments': 'GLuint program, const char* name', },
310 { 'return_type': 'void',
311 'names': ['glGetBooleanv'],
312 'arguments': 'GLenum pname, GLboolean* params', },
313 { 'return_type': 'void',
314 'names': ['glGetBufferParameteriv'],
315 'arguments': 'GLenum target, GLenum pname, GLint* params', },
316 { 'return_type': 'GLenum',
317 'names': ['glGetError'],
318 'arguments': 'void',
319 'logging_code': """
320 GL_SERVICE_LOG("GL_RESULT: " << GLES2Util::GetStringError(result));
321 """, },
322 { 'return_type': 'void',
323 'names': ['glGetFloatv'],
324 'arguments': 'GLenum pname, GLfloat* params', },
325 { 'return_type': 'void',
326 'names': ['glGetFramebufferAttachmentParameterivEXT',
327 'glGetFramebufferAttachmentParameteriv'],
328 'arguments': 'GLenum target, '
329 'GLenum attachment, GLenum pname, GLint* params', },
330 { 'return_type': 'GLenum',
331 'names': ['glGetGraphicsResetStatusARB',
332 'glGetGraphicsResetStatusEXT'],
333 'arguments': 'void', },
334 { 'return_type': 'void',
335 'names': ['glGetIntegerv'],
336 'arguments': 'GLenum pname, GLint* params', },
337 { 'return_type': 'void',
338 'known_as': 'glGetProgramBinary',
339 'versions': [{ 'name': 'glGetProgramBinaryOES' },
340 { 'name': 'glGetProgramBinary',
341 'extensions': ['GL_ARB_get_program_binary'] },
342 { 'name': 'glGetProgramBinary' }],
343 'arguments': 'GLuint program, GLsizei bufSize, GLsizei* length, '
344 'GLenum* binaryFormat, GLvoid* binary' },
345 { 'return_type': 'void',
346 'names': ['glGetProgramiv'],
347 'arguments': 'GLuint program, GLenum pname, GLint* params', },
348 { 'return_type': 'void',
349 'names': ['glGetProgramInfoLog'],
350 'arguments':
351 'GLuint program, GLsizei bufsize, GLsizei* length, char* infolog', },
352 { 'return_type': 'void',
353 'names': ['glGetQueryiv'],
354 'arguments': 'GLenum target, GLenum pname, GLint* params', },
355 { 'return_type': 'void',
356 'names': ['glGetQueryivARB', 'glGetQueryivEXT'],
357 'arguments': 'GLenum target, GLenum pname, GLint* params', },
358 { 'return_type': 'void',
359 'names': ['glGetQueryObjecti64v'],
360 'arguments': 'GLuint id, GLenum pname, GLint64* params', },
361 { 'return_type': 'void',
362 'names': ['glGetQueryObjectui64v', 'glGetQueryObjectui64vEXT'],
363 'arguments': 'GLuint id, GLenum pname, GLuint64* params', },
364 { 'return_type': 'void',
365 'names': ['glGetQueryObjectuiv'],
366 'arguments': 'GLuint id, GLenum pname, GLuint* params', },
367 { 'return_type': 'void',
368 'names': ['glGetQueryObjectuivARB', 'glGetQueryObjectuivEXT'],
369 'arguments': 'GLuint id, GLenum pname, GLuint* params', },
370 { 'return_type': 'void',
371 'names': ['glGetQueryObjectiv', 'glGetQueryObjectivARB',
372 'glGetQueryObjectivEXT'],
373 'arguments': 'GLuint id, GLenum pname, GLint* params', },
374 { 'return_type': 'void',
375 'names': ['glGetRenderbufferParameterivEXT', 'glGetRenderbufferParameteriv'],
376 'arguments': 'GLenum target, GLenum pname, GLint* params', },
377 { 'return_type': 'void',
378 'names': ['glGetShaderiv'],
379 'arguments': 'GLuint shader, GLenum pname, GLint* params', },
380 { 'return_type': 'void',
381 'names': ['glGetShaderInfoLog'],
382 'arguments':
383 'GLuint shader, GLsizei bufsize, GLsizei* length, char* infolog', },
384 { 'return_type': 'void',
385 'names': ['glGetShaderPrecisionFormat'],
386 'arguments': 'GLenum shadertype, GLenum precisiontype, '
387 'GLint* range, GLint* precision', },
388 { 'return_type': 'void',
389 'names': ['glGetShaderSource'],
390 'arguments':
391 'GLuint shader, GLsizei bufsize, GLsizei* length, char* source', },
392 { 'return_type': 'const GLubyte*',
393 'names': ['glGetString'],
394 'arguments': 'GLenum name', },
395 { 'return_type': 'void',
396 'names': ['glGetTexLevelParameterfv'],
397 'arguments': 'GLenum target, GLint level, GLenum pname, GLfloat* params', },
398 { 'return_type': 'void',
399 'names': ['glGetTexLevelParameteriv'],
400 'arguments': 'GLenum target, GLint level, GLenum pname, GLint* params', },
401 { 'return_type': 'void',
402 'names': ['glGetTexParameterfv'],
403 'arguments': 'GLenum target, GLenum pname, GLfloat* params', },
404 { 'return_type': 'void',
405 'names': ['glGetTexParameteriv'],
406 'arguments': 'GLenum target, GLenum pname, GLint* params', },
407 { 'return_type': 'void',
408 'names': ['glGetTranslatedShaderSourceANGLE'],
409 'arguments':
410 'GLuint shader, GLsizei bufsize, GLsizei* length, char* source', },
411 { 'return_type': 'void',
412 'names': ['glGetUniformfv'],
413 'arguments': 'GLuint program, GLint location, GLfloat* params', },
414 { 'return_type': 'void',
415 'names': ['glGetUniformiv'],
416 'arguments': 'GLuint program, GLint location, GLint* params', },
417 { 'return_type': 'GLint',
418 'names': ['glGetUniformLocation'],
419 'arguments': 'GLuint program, const char* name', },
420 { 'return_type': 'void',
421 'names': ['glGetVertexAttribfv'],
422 'arguments': 'GLuint index, GLenum pname, GLfloat* params', },
423 { 'return_type': 'void',
424 'names': ['glGetVertexAttribiv'],
425 'arguments': 'GLuint index, GLenum pname, GLint* params', },
426 { 'return_type': 'void',
427 'names': ['glGetVertexAttribPointerv'],
428 'arguments': 'GLuint index, GLenum pname, void** pointer', },
429 { 'return_type': 'void',
430 'names': ['glHint'],
431 'arguments': 'GLenum target, GLenum mode', },
432 { 'return_type': 'void',
433 'names': ['glInsertEventMarkerEXT'],
434 'arguments': 'GLsizei length, const char* marker', },
435 { 'return_type': 'GLboolean',
436 'names': ['glIsBuffer'],
437 'arguments': 'GLuint buffer', },
438 { 'return_type': 'GLboolean',
439 'names': ['glIsEnabled'],
440 'arguments': 'GLenum cap', },
441 { 'return_type': 'GLboolean',
442 'names': ['glIsFramebufferEXT', 'glIsFramebuffer'],
443 'arguments': 'GLuint framebuffer', },
444 { 'return_type': 'GLboolean',
445 'names': ['glIsProgram'],
446 'arguments': 'GLuint program', },
447 { 'return_type': 'GLboolean',
448 'names': ['glIsQueryARB', 'glIsQueryEXT'],
449 'arguments': 'GLuint query', },
450 { 'return_type': 'GLboolean',
451 'names': ['glIsRenderbufferEXT', 'glIsRenderbuffer'],
452 'arguments': 'GLuint renderbuffer', },
453 { 'return_type': 'GLboolean',
454 'names': ['glIsShader'],
455 'arguments': 'GLuint shader', },
456 { 'return_type': 'GLboolean',
457 'names': ['glIsTexture'],
458 'arguments': 'GLuint texture', },
459 { 'return_type': 'void',
460 'names': ['glLineWidth'],
461 'arguments': 'GLfloat width', },
462 { 'return_type': 'void',
463 'names': ['glLinkProgram'],
464 'arguments': 'GLuint program', },
465 { 'return_type': 'void*',
466 'known_as': 'glMapBuffer',
467 'names': ['glMapBufferOES', 'glMapBuffer'],
468 'arguments': 'GLenum target, GLenum access', },
469 { 'return_type': 'void*',
470 'names': ['glMapBufferRange'],
471 'arguments':
472 'GLenum target, GLintptr offset, GLsizeiptr length, GLenum access', },
473 { 'return_type': 'void',
474 'names': ['glFlushMappedBufferRange'],
475 'arguments': 'GLenum target, GLintptr offset, GLsizeiptr length', },
476 { 'return_type': 'void',
477 'names': ['glPixelStorei'],
478 'arguments': 'GLenum pname, GLint param', },
479 { 'return_type': 'void',
480 'names': ['glPointParameteri'],
481 'arguments': 'GLenum pname, GLint param', },
482 { 'return_type': 'void',
483 'names': ['glPolygonOffset'],
484 'arguments': 'GLfloat factor, GLfloat units', },
485 { 'return_type': 'void',
486 'names': ['glPopGroupMarkerEXT'],
487 'arguments': 'void', },
488 { 'return_type': 'void',
489 'known_as': 'glProgramBinary',
490 'versions': [{ 'name': 'glProgramBinaryOES' },
491 { 'name': 'glProgramBinary',
492 'extensions': ['GL_ARB_get_program_binary'] },
493 { 'name': 'glProgramBinary' }],
494 'arguments': 'GLuint program, GLenum binaryFormat, '
495 'const GLvoid* binary, GLsizei length' },
496 { 'return_type': 'void',
497 'versions': [{ 'name': 'glProgramParameteri',
498 'extensions': ['GL_ARB_get_program_binary'] },
499 { 'name': 'glProgramParameteri' }],
500 'arguments': 'GLuint program, GLenum pname, GLint value' },
501 { 'return_type': 'void',
502 'names': ['glPushGroupMarkerEXT'],
503 'arguments': 'GLsizei length, const char* marker', },
504 { 'return_type': 'void',
505 'names': ['glQueryCounter', 'glQueryCounterEXT'],
506 'arguments': 'GLuint id, GLenum target', },
507 { 'return_type': 'void',
508 'names': ['glReadBuffer'],
509 'arguments': 'GLenum src', },
510 { 'return_type': 'void',
511 'names': ['glReadPixels'],
512 'arguments':
513 'GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, '
514 'GLenum type, void* pixels', },
515 { 'return_type': 'void',
516 'names': ['glReleaseShaderCompiler'],
517 'arguments': 'void', },
518 # Multisampling API is different in different GL versions, some require an
519 # explicit resolve step for renderbuffers and/or FBO texture attachments and
520 # some do not. Multiple alternatives might be present in a single
521 # implementation, which require different use of the API and may have
522 # different performance (explicit resolve performing worse, for example).
523 # So even though the function signature is the same across versions, we split
524 # their definitions so that the function to use can be chosen correctly at a
525 # higher level.
526 # TODO(oetuaho@nvidia.com): Some of these might still be possible to combine.
527 # This could also fix weirdness in the mock bindings that's caused by the same
528 # function name appearing multiple times.
529 # This is the ES3 function, which requires explicit resolve:
530 { 'return_type': 'void',
531 'names': ['glRenderbufferStorageMultisample'],
532 'arguments': 'GLenum target, GLsizei samples, GLenum internalformat, '
533 'GLsizei width, GLsizei height', },
534 # In desktop GL, EXT and core versions both have an explicit resolve step,
535 # though desktop core GL implicitly resolves when drawing to a window.
536 # TODO(oetuaho@nvidia.com): Right now this function also doubles as ES2 EXT
537 # function, which has implicit resolve, and for which the fallback is wrong.
538 # Fix this.
539 { 'return_type': 'void',
540 'names': ['glRenderbufferStorageMultisampleEXT',
541 'glRenderbufferStorageMultisample'],
542 'arguments': 'GLenum target, GLsizei samples, GLenum internalformat, '
543 'GLsizei width, GLsizei height', },
544 { 'return_type': 'void',
545 'names': ['glRenderbufferStorageMultisampleANGLE',
546 'glRenderbufferStorageMultisample'],
547 'arguments': 'GLenum target, GLsizei samples, GLenum internalformat, '
548 'GLsizei width, GLsizei height', },
549 { 'return_type': 'void',
550 'names': ['glRenderbufferStorageMultisampleIMG'],
551 'arguments': 'GLenum target, GLsizei samples, GLenum internalformat, '
552 'GLsizei width, GLsizei height', },
553 { 'return_type': 'void',
554 'names': ['glRenderbufferStorageEXT', 'glRenderbufferStorage'],
555 'arguments':
556 'GLenum target, GLenum internalformat, GLsizei width, GLsizei height', },
557 { 'return_type': 'void',
558 'names': ['glSampleCoverage'],
559 'arguments': 'GLclampf value, GLboolean invert', },
560 { 'return_type': 'void',
561 'names': ['glScissor'],
562 'arguments': 'GLint x, GLint y, GLsizei width, GLsizei height', },
563 { 'return_type': 'void',
564 'names': ['glShaderBinary'],
565 'arguments': 'GLsizei n, const GLuint* shaders, GLenum binaryformat, '
566 'const void* binary, GLsizei length', },
567 { 'return_type': 'void',
568 'names': ['glShaderSource'],
569 'arguments': 'GLuint shader, GLsizei count, const char* const* str, '
570 'const GLint* length',
571 'logging_code': """
572 GL_SERVICE_LOG_CODE_BLOCK({
573 for (GLsizei ii = 0; ii < count; ++ii) {
574 if (str[ii]) {
575 if (length && length[ii] >= 0) {
576 std::string source(str[ii], length[ii]);
577 GL_SERVICE_LOG(" " << ii << ": ---\\n" << source << "\\n---");
578 } else {
579 GL_SERVICE_LOG(" " << ii << ": ---\\n" << str[ii] << "\\n---");
581 } else {
582 GL_SERVICE_LOG(" " << ii << ": NULL");
586 """, },
587 { 'return_type': 'void',
588 'names': ['glStencilFunc'],
589 'arguments': 'GLenum func, GLint ref, GLuint mask', },
590 { 'return_type': 'void',
591 'names': ['glStencilFuncSeparate'],
592 'arguments': 'GLenum face, GLenum func, GLint ref, GLuint mask', },
593 { 'return_type': 'void',
594 'names': ['glStencilMask'],
595 'arguments': 'GLuint mask', },
596 { 'return_type': 'void',
597 'names': ['glStencilMaskSeparate'],
598 'arguments': 'GLenum face, GLuint mask', },
599 { 'return_type': 'void',
600 'names': ['glStencilOp'],
601 'arguments': 'GLenum fail, GLenum zfail, GLenum zpass', },
602 { 'return_type': 'void',
603 'names': ['glStencilOpSeparate'],
604 'arguments': 'GLenum face, GLenum fail, GLenum zfail, GLenum zpass', },
605 { 'return_type': 'void',
606 'names': ['glTexImage2D'],
607 'arguments':
608 'GLenum target, GLint level, GLint internalformat, GLsizei width, '
609 'GLsizei height, GLint border, GLenum format, GLenum type, '
610 'const void* pixels', },
611 { 'return_type': 'void',
612 'names': ['glTexParameterf'],
613 'arguments': 'GLenum target, GLenum pname, GLfloat param', },
614 { 'return_type': 'void',
615 'names': ['glTexParameterfv'],
616 'arguments': 'GLenum target, GLenum pname, const GLfloat* params', },
617 { 'return_type': 'void',
618 'names': ['glTexParameteri'],
619 'arguments': 'GLenum target, GLenum pname, GLint param', },
620 { 'return_type': 'void',
621 'names': ['glTexParameteriv'],
622 'arguments': 'GLenum target, GLenum pname, const GLint* params', },
623 { 'return_type': 'void',
624 'known_as': 'glTexStorage2DEXT',
625 'versions': [{ 'name': 'glTexStorage2D',
626 'gl_versions': ['es3'] },
627 { 'name': 'glTexStorage2D',
628 'extensions': ['GL_ARB_texture_storage'] },
629 { 'name': 'glTexStorage2DEXT',
630 'extensions': ['GL_EXT_texture_storage'] }],
631 'arguments': 'GLenum target, GLsizei levels, GLenum internalformat, '
632 'GLsizei width, GLsizei height', },
633 { 'return_type': 'void',
634 'names': ['glTexSubImage2D'],
635 'arguments':
636 'GLenum target, GLint level, GLint xoffset, GLint yoffset, '
637 'GLsizei width, GLsizei height, GLenum format, GLenum type, '
638 'const void* pixels', },
639 { 'return_type': 'void',
640 'names': ['glUniform1f'],
641 'arguments': 'GLint location, GLfloat x', },
642 { 'return_type': 'void',
643 'names': ['glUniform1fv'],
644 'arguments': 'GLint location, GLsizei count, const GLfloat* v', },
645 { 'return_type': 'void',
646 'names': ['glUniform1i'],
647 'arguments': 'GLint location, GLint x', },
648 { 'return_type': 'void',
649 'names': ['glUniform1iv'],
650 'arguments': 'GLint location, GLsizei count, const GLint* v', },
651 { 'return_type': 'void',
652 'names': ['glUniform2f'],
653 'arguments': 'GLint location, GLfloat x, GLfloat y', },
654 { 'return_type': 'void',
655 'names': ['glUniform2fv'],
656 'arguments': 'GLint location, GLsizei count, const GLfloat* v', },
657 { 'return_type': 'void',
658 'names': ['glUniform2i'],
659 'arguments': 'GLint location, GLint x, GLint y', },
660 { 'return_type': 'void',
661 'names': ['glUniform2iv'],
662 'arguments': 'GLint location, GLsizei count, const GLint* v', },
663 { 'return_type': 'void',
664 'names': ['glUniform3f'],
665 'arguments': 'GLint location, GLfloat x, GLfloat y, GLfloat z', },
666 { 'return_type': 'void',
667 'names': ['glUniform3fv'],
668 'arguments': 'GLint location, GLsizei count, const GLfloat* v', },
669 { 'return_type': 'void',
670 'names': ['glUniform3i'],
671 'arguments': 'GLint location, GLint x, GLint y, GLint z', },
672 { 'return_type': 'void',
673 'names': ['glUniform3iv'],
674 'arguments': 'GLint location, GLsizei count, const GLint* v', },
675 { 'return_type': 'void',
676 'names': ['glUniform4f'],
677 'arguments': 'GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w', },
678 { 'return_type': 'void',
679 'names': ['glUniform4fv'],
680 'arguments': 'GLint location, GLsizei count, const GLfloat* v', },
681 { 'return_type': 'void',
682 'names': ['glUniform4i'],
683 'arguments': 'GLint location, GLint x, GLint y, GLint z, GLint w', },
684 { 'return_type': 'void',
685 'names': ['glUniform4iv'],
686 'arguments': 'GLint location, GLsizei count, const GLint* v', },
687 { 'return_type': 'void',
688 'names': ['glUniformMatrix2fv'],
689 'arguments': 'GLint location, GLsizei count, '
690 'GLboolean transpose, const GLfloat* value', },
691 { 'return_type': 'void',
692 'names': ['glUniformMatrix3fv'],
693 'arguments': 'GLint location, GLsizei count, '
694 'GLboolean transpose, const GLfloat* value', },
695 { 'return_type': 'void',
696 'names': ['glUniformMatrix4fv'],
697 'arguments': 'GLint location, GLsizei count, '
698 'GLboolean transpose, const GLfloat* value', },
699 { 'return_type': 'GLboolean',
700 'known_as': 'glUnmapBuffer',
701 'names': ['glUnmapBufferOES', 'glUnmapBuffer'],
702 'arguments': 'GLenum target', },
703 { 'return_type': 'void',
704 'names': ['glUseProgram'],
705 'arguments': 'GLuint program', },
706 { 'return_type': 'void',
707 'names': ['glValidateProgram'],
708 'arguments': 'GLuint program', },
709 { 'return_type': 'void',
710 'names': ['glVertexAttrib1f'],
711 'arguments': 'GLuint indx, GLfloat x', },
712 { 'return_type': 'void',
713 'names': ['glVertexAttrib1fv'],
714 'arguments': 'GLuint indx, const GLfloat* values', },
715 { 'return_type': 'void',
716 'names': ['glVertexAttrib2f'],
717 'arguments': 'GLuint indx, GLfloat x, GLfloat y', },
718 { 'return_type': 'void',
719 'names': ['glVertexAttrib2fv'],
720 'arguments': 'GLuint indx, const GLfloat* values', },
721 { 'return_type': 'void',
722 'names': ['glVertexAttrib3f'],
723 'arguments': 'GLuint indx, GLfloat x, GLfloat y, GLfloat z', },
724 { 'return_type': 'void',
725 'names': ['glVertexAttrib3fv'],
726 'arguments': 'GLuint indx, const GLfloat* values', },
727 { 'return_type': 'void',
728 'names': ['glVertexAttrib4f'],
729 'arguments': 'GLuint indx, GLfloat x, GLfloat y, GLfloat z, GLfloat w', },
730 { 'return_type': 'void',
731 'names': ['glVertexAttrib4fv'],
732 'arguments': 'GLuint indx, const GLfloat* values', },
733 { 'return_type': 'void',
734 'names': ['glVertexAttribPointer'],
735 'arguments': 'GLuint indx, GLint size, GLenum type, GLboolean normalized, '
736 'GLsizei stride, const void* ptr', },
737 { 'return_type': 'void',
738 'names': ['glViewport'],
739 'arguments': 'GLint x, GLint y, GLsizei width, GLsizei height', },
740 { 'return_type': 'void',
741 'names': ['glGenFencesNV'],
742 'arguments': 'GLsizei n, GLuint* fences', },
743 { 'return_type': 'void',
744 'names': ['glDeleteFencesNV'],
745 'arguments': 'GLsizei n, const GLuint* fences', },
746 { 'return_type': 'void',
747 'names': ['glSetFenceNV'],
748 'arguments': 'GLuint fence, GLenum condition', },
749 { 'return_type': 'GLboolean',
750 'names': ['glTestFenceNV'],
751 'arguments': 'GLuint fence', },
752 { 'return_type': 'void',
753 'names': ['glFinishFenceNV'],
754 'arguments': 'GLuint fence', },
755 { 'return_type': 'GLboolean',
756 'names': ['glIsFenceNV'],
757 'arguments': 'GLuint fence', },
758 { 'return_type': 'void',
759 'names': ['glGetFenceivNV'],
760 'arguments': 'GLuint fence, GLenum pname, GLint* params', },
761 { 'return_type': 'GLsync',
762 'names': ['glFenceSync'],
763 'arguments': 'GLenum condition, GLbitfield flags', },
764 { 'return_type': 'GLboolean',
765 'names': ['glIsSync'],
766 'arguments': 'GLsync sync', },
767 { 'return_type': 'void',
768 'names': ['glDeleteSync'],
769 'arguments': 'GLsync sync', },
770 { 'return_type': 'void',
771 'names': ['glGetSynciv'],
772 'arguments':
773 'GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length,'
774 'GLint* values', },
775 { 'return_type': 'GLenum',
776 'names': ['glClientWaitSync'],
777 'arguments':
778 'GLsync sync, GLbitfield flags, GLuint64 timeout', },
779 { 'return_type': 'GLenum',
780 'names': ['glWaitSync'],
781 'arguments':
782 'GLsync sync, GLbitfield flags, GLuint64 timeout', },
783 { 'return_type': 'void',
784 'known_as': 'glDrawArraysInstancedANGLE',
785 'names': ['glDrawArraysInstancedARB', 'glDrawArraysInstancedANGLE',
786 'glDrawArraysInstanced'],
787 'arguments': 'GLenum mode, GLint first, GLsizei count, GLsizei primcount', },
788 { 'return_type': 'void',
789 'known_as': 'glDrawElementsInstancedANGLE',
790 'names': ['glDrawElementsInstancedARB', 'glDrawElementsInstancedANGLE',
791 'glDrawElementsInstanced'],
792 'arguments':
793 'GLenum mode, GLsizei count, GLenum type, const void* indices, '
794 'GLsizei primcount', },
795 { 'return_type': 'void',
796 'known_as': 'glVertexAttribDivisorANGLE',
797 'names': ['glVertexAttribDivisorARB', 'glVertexAttribDivisorANGLE',
798 'glVertexAttribDivisor'],
799 'arguments':
800 'GLuint index, GLuint divisor', },
801 { 'return_type': 'void',
802 'known_as': 'glGenVertexArraysOES',
803 'versions': [{ 'name': 'glGenVertexArrays',
804 'gl_versions': ['gl3', 'gl4', 'es3'] },
805 { 'name': 'glGenVertexArrays',
806 'extensions': ['GL_ARB_vertex_array_object'] },
807 { 'name': 'glGenVertexArraysOES' },
808 { 'name': 'glGenVertexArraysAPPLE',
809 'extensions': ['GL_APPLE_vertex_array_object'] }],
810 'arguments': 'GLsizei n, GLuint* arrays', },
811 { 'return_type': 'void',
812 'known_as': 'glDeleteVertexArraysOES',
813 'versions': [{ 'name': 'glDeleteVertexArrays',
814 'gl_versions': ['gl3', 'gl4', 'es3'] },
815 { 'name': 'glDeleteVertexArrays',
816 'extensions': ['GL_ARB_vertex_array_object'] },
817 { 'name': 'glDeleteVertexArraysOES' },
818 { 'name': 'glDeleteVertexArraysAPPLE',
819 'extensions': ['GL_APPLE_vertex_array_object'] }],
820 'arguments': 'GLsizei n, const GLuint* arrays' },
821 { 'return_type': 'void',
822 'known_as': 'glBindVertexArrayOES',
823 'versions': [{ 'name': 'glBindVertexArray',
824 'gl_versions': ['gl3', 'gl4', 'es3'] },
825 { 'name': 'glBindVertexArray',
826 'extensions': ['GL_ARB_vertex_array_object'] },
827 { 'name': 'glBindVertexArrayOES' },
828 { 'name': 'glBindVertexArrayAPPLE',
829 'extensions': ['GL_APPLE_vertex_array_object'] }],
830 'arguments': 'GLuint array' },
831 { 'return_type': 'GLboolean',
832 'known_as': 'glIsVertexArrayOES',
833 'versions': [{ 'name': 'glIsVertexArray',
834 'gl_versions': ['gl3', 'gl4'] },
835 { 'name': 'glIsVertexArray',
836 'extensions': ['GL_ARB_vertex_array_object'] },
837 { 'name': 'glIsVertexArrayOES' },
838 { 'name': 'glIsVertexArrayAPPLE',
839 'extensions': ['GL_APPLE_vertex_array_object'] }],
840 'arguments': 'GLuint array' },
841 { 'return_type': 'void',
842 'known_as': 'glDiscardFramebufferEXT',
843 'versions': [{ 'name': 'glInvalidateFramebuffer',
844 'gl_versions': ['es3'],
845 'extensions': [] },
846 { 'name': 'glDiscardFramebufferEXT',
847 'gl_versions': ['es1', 'es2'] }],
848 'arguments': 'GLenum target, GLsizei numAttachments, '
849 'const GLenum* attachments' },
850 { 'return_type': 'void',
851 'known_as': 'glMatrixLoadfEXT',
852 'versions': [{ 'name': 'glMatrixLoadfEXT',
853 'gl_versions': ['gl4'],
854 'extensions': ['GL_EXT_direct_state_access'] },
855 { 'name': 'glMatrixLoadfEXT',
856 'gl_versions': ['es3'],
857 'extensions': ['GL_NV_path_rendering'] }],
858 'arguments': 'GLenum matrixMode, const GLfloat* m' },
859 { 'return_type': 'void',
860 'known_as': 'glMatrixLoadIdentityEXT',
861 'versions': [{ 'name': 'glMatrixLoadIdentityEXT',
862 'gl_versions': ['gl4'],
863 'extensions': ['GL_EXT_direct_state_access'] },
864 { 'name': 'glMatrixLoadIdentityEXT',
865 'gl_versions': ['es3'],
866 'extensions': ['GL_NV_path_rendering'] }],
867 'arguments': 'GLenum matrixMode' },
870 OSMESA_FUNCTIONS = [
871 { 'return_type': 'OSMesaContext',
872 'names': ['OSMesaCreateContext'],
873 'arguments': 'GLenum format, OSMesaContext sharelist', },
874 { 'return_type': 'OSMesaContext',
875 'names': ['OSMesaCreateContextExt'],
876 'arguments':
877 'GLenum format, GLint depthBits, GLint stencilBits, GLint accumBits, '
878 'OSMesaContext sharelist', },
879 { 'return_type': 'void',
880 'names': ['OSMesaDestroyContext'],
881 'arguments': 'OSMesaContext ctx', },
882 { 'return_type': 'GLboolean',
883 'names': ['OSMesaMakeCurrent'],
884 'arguments': 'OSMesaContext ctx, void* buffer, GLenum type, GLsizei width, '
885 'GLsizei height', },
886 { 'return_type': 'OSMesaContext',
887 'names': ['OSMesaGetCurrentContext'],
888 'arguments': 'void', },
889 { 'return_type': 'void',
890 'names': ['OSMesaPixelStore'],
891 'arguments': 'GLint pname, GLint value', },
892 { 'return_type': 'void',
893 'names': ['OSMesaGetIntegerv'],
894 'arguments': 'GLint pname, GLint* value', },
895 { 'return_type': 'GLboolean',
896 'names': ['OSMesaGetDepthBuffer'],
897 'arguments':
898 'OSMesaContext c, GLint* width, GLint* height, GLint* bytesPerValue, '
899 'void** buffer', },
900 { 'return_type': 'GLboolean',
901 'names': ['OSMesaGetColorBuffer'],
902 'arguments': 'OSMesaContext c, GLint* width, GLint* height, GLint* format, '
903 'void** buffer', },
904 { 'return_type': 'OSMESAproc',
905 'names': ['OSMesaGetProcAddress'],
906 'arguments': 'const char* funcName', },
907 { 'return_type': 'void',
908 'names': ['OSMesaColorClamp'],
909 'arguments': 'GLboolean enable', },
912 EGL_FUNCTIONS = [
913 { 'return_type': 'EGLint',
914 'names': ['eglGetError'],
915 'arguments': 'void', },
916 { 'return_type': 'EGLDisplay',
917 'names': ['eglGetDisplay'],
918 'arguments': 'EGLNativeDisplayType display_id', },
919 { 'return_type': 'EGLDisplay',
920 'known_as': 'eglGetPlatformDisplayEXT',
921 'versions': [{ 'name': 'eglGetPlatformDisplayEXT',
922 'extensions': ['EGL_ANGLE_platform_angle'] }],
923 'arguments': 'EGLenum platform, void* native_display, '
924 'const EGLint* attrib_list', },
925 { 'return_type': 'EGLBoolean',
926 'names': ['eglInitialize'],
927 'arguments': 'EGLDisplay dpy, EGLint* major, EGLint* minor', },
928 { 'return_type': 'EGLBoolean',
929 'names': ['eglTerminate'],
930 'arguments': 'EGLDisplay dpy', },
931 { 'return_type': 'const char*',
932 'names': ['eglQueryString'],
933 'arguments': 'EGLDisplay dpy, EGLint name', },
934 { 'return_type': 'EGLBoolean',
935 'names': ['eglGetConfigs'],
936 'arguments': 'EGLDisplay dpy, EGLConfig* configs, EGLint config_size, '
937 'EGLint* num_config', },
938 { 'return_type': 'EGLBoolean',
939 'names': ['eglChooseConfig'],
940 'arguments': 'EGLDisplay dpy, const EGLint* attrib_list, EGLConfig* configs, '
941 'EGLint config_size, EGLint* num_config', },
942 { 'return_type': 'EGLBoolean',
943 'names': ['eglGetConfigAttrib'],
944 'arguments':
945 'EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint* value', },
946 { 'return_type': 'EGLImageKHR',
947 'versions': [{ 'name': 'eglCreateImageKHR',
948 'extensions':
949 ['EGL_KHR_image_base', 'EGL_KHR_gl_texture_2D_image'] }],
950 'arguments':
951 'EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, '
952 'const EGLint* attrib_list' },
953 { 'return_type': 'EGLBoolean',
954 'versions': [{ 'name' : 'eglDestroyImageKHR',
955 'extensions': ['EGL_KHR_image_base'] }],
956 'arguments': 'EGLDisplay dpy, EGLImageKHR image' },
957 { 'return_type': 'EGLSurface',
958 'names': ['eglCreateWindowSurface'],
959 'arguments': 'EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, '
960 'const EGLint* attrib_list', },
961 { 'return_type': 'EGLSurface',
962 'names': ['eglCreatePbufferSurface'],
963 'arguments': 'EGLDisplay dpy, EGLConfig config, const EGLint* attrib_list', },
964 { 'return_type': 'EGLSurface',
965 'names': ['eglCreatePixmapSurface'],
966 'arguments': 'EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, '
967 'const EGLint* attrib_list', },
968 { 'return_type': 'EGLBoolean',
969 'names': ['eglDestroySurface'],
970 'arguments': 'EGLDisplay dpy, EGLSurface surface', },
971 { 'return_type': 'EGLBoolean',
972 'names': ['eglQuerySurface'],
973 'arguments':
974 'EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint* value', },
975 { 'return_type': 'EGLBoolean',
976 'names': ['eglBindAPI'],
977 'arguments': 'EGLenum api', },
978 { 'return_type': 'EGLenum',
979 'names': ['eglQueryAPI'],
980 'arguments': 'void', },
981 { 'return_type': 'EGLBoolean',
982 'names': ['eglWaitClient'],
983 'arguments': 'void', },
984 { 'return_type': 'EGLBoolean',
985 'names': ['eglReleaseThread'],
986 'arguments': 'void', },
987 { 'return_type': 'EGLSurface',
988 'names': ['eglCreatePbufferFromClientBuffer'],
989 'arguments':
990 'EGLDisplay dpy, EGLenum buftype, void* buffer, EGLConfig config, '
991 'const EGLint* attrib_list', },
992 { 'return_type': 'EGLBoolean',
993 'names': ['eglSurfaceAttrib'],
994 'arguments':
995 'EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value', },
996 { 'return_type': 'EGLBoolean',
997 'names': ['eglBindTexImage'],
998 'arguments': 'EGLDisplay dpy, EGLSurface surface, EGLint buffer', },
999 { 'return_type': 'EGLBoolean',
1000 'names': ['eglReleaseTexImage'],
1001 'arguments': 'EGLDisplay dpy, EGLSurface surface, EGLint buffer', },
1002 { 'return_type': 'EGLBoolean',
1003 'names': ['eglSwapInterval'],
1004 'arguments': 'EGLDisplay dpy, EGLint interval', },
1005 { 'return_type': 'EGLContext',
1006 'names': ['eglCreateContext'],
1007 'arguments': 'EGLDisplay dpy, EGLConfig config, EGLContext share_context, '
1008 'const EGLint* attrib_list', },
1009 { 'return_type': 'EGLBoolean',
1010 'names': ['eglDestroyContext'],
1011 'arguments': 'EGLDisplay dpy, EGLContext ctx', },
1012 { 'return_type': 'EGLBoolean',
1013 'names': ['eglMakeCurrent'],
1014 'arguments':
1015 'EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx', },
1016 { 'return_type': 'EGLContext',
1017 'names': ['eglGetCurrentContext'],
1018 'arguments': 'void', },
1019 { 'return_type': 'EGLSurface',
1020 'names': ['eglGetCurrentSurface'],
1021 'arguments': 'EGLint readdraw', },
1022 { 'return_type': 'EGLDisplay',
1023 'names': ['eglGetCurrentDisplay'],
1024 'arguments': 'void', },
1025 { 'return_type': 'EGLBoolean',
1026 'names': ['eglQueryContext'],
1027 'arguments':
1028 'EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint* value', },
1029 { 'return_type': 'EGLBoolean',
1030 'names': ['eglWaitGL'],
1031 'arguments': 'void', },
1032 { 'return_type': 'EGLBoolean',
1033 'names': ['eglWaitNative'],
1034 'arguments': 'EGLint engine', },
1035 { 'return_type': 'EGLBoolean',
1036 'names': ['eglSwapBuffers'],
1037 'arguments': 'EGLDisplay dpy, EGLSurface surface', },
1038 { 'return_type': 'EGLBoolean',
1039 'names': ['eglCopyBuffers'],
1040 'arguments':
1041 'EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target', },
1042 { 'return_type': '__eglMustCastToProperFunctionPointerType',
1043 'names': ['eglGetProcAddress'],
1044 'arguments': 'const char* procname', },
1045 { 'return_type': 'EGLBoolean',
1046 'names': ['eglPostSubBufferNV'],
1047 'arguments': 'EGLDisplay dpy, EGLSurface surface, '
1048 'EGLint x, EGLint y, EGLint width, EGLint height', },
1049 { 'return_type': 'EGLBoolean',
1050 'names': ['eglQuerySurfacePointerANGLE'],
1051 'arguments':
1052 'EGLDisplay dpy, EGLSurface surface, EGLint attribute, void** value', },
1053 { 'return_type': 'EGLSyncKHR',
1054 'versions': [{ 'name': 'eglCreateSyncKHR',
1055 'extensions': ['EGL_KHR_fence_sync'] }],
1056 'arguments': 'EGLDisplay dpy, EGLenum type, const EGLint* attrib_list' },
1057 { 'return_type': 'EGLint',
1058 'versions': [{ 'name': 'eglClientWaitSyncKHR',
1059 'extensions': ['EGL_KHR_fence_sync'] }],
1060 'arguments': 'EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, '
1061 'EGLTimeKHR timeout' },
1062 { 'return_type': 'EGLBoolean',
1063 'versions': [{ 'name': 'eglGetSyncAttribKHR',
1064 'extensions': ['EGL_KHR_fence_sync'] }],
1065 'arguments': 'EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, '
1066 'EGLint* value' },
1067 { 'return_type': 'EGLBoolean',
1068 'versions': [{ 'name': 'eglDestroySyncKHR',
1069 'extensions': ['EGL_KHR_fence_sync'] }],
1070 'arguments': 'EGLDisplay dpy, EGLSyncKHR sync' },
1071 { 'return_type': 'EGLBoolean',
1072 'names': ['eglGetSyncValuesCHROMIUM'],
1073 'arguments':
1074 'EGLDisplay dpy, EGLSurface surface, '
1075 'EGLuint64CHROMIUM* ust, EGLuint64CHROMIUM* msc, '
1076 'EGLuint64CHROMIUM* sbc', },
1077 { 'return_type': 'EGLint',
1078 'versions': [{ 'name': 'eglWaitSyncKHR',
1079 'extensions': ['EGL_KHR_fence_sync'] }],
1080 'arguments': 'EGLDisplay dpy, EGLSyncKHR sync, EGLint flags' }
1083 WGL_FUNCTIONS = [
1084 { 'return_type': 'HGLRC',
1085 'names': ['wglCreateContext'],
1086 'arguments': 'HDC hdc', },
1087 { 'return_type': 'HGLRC',
1088 'names': ['wglCreateLayerContext'],
1089 'arguments': 'HDC hdc, int iLayerPlane', },
1090 { 'return_type': 'BOOL',
1091 'names': ['wglCopyContext'],
1092 'arguments': 'HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask', },
1093 { 'return_type': 'BOOL',
1094 'names': ['wglDeleteContext'],
1095 'arguments': 'HGLRC hglrc', },
1096 { 'return_type': 'HGLRC',
1097 'names': ['wglGetCurrentContext'],
1098 'arguments': '', },
1099 { 'return_type': 'HDC',
1100 'names': ['wglGetCurrentDC'],
1101 'arguments': '', },
1102 { 'return_type': 'BOOL',
1103 'names': ['wglMakeCurrent'],
1104 'arguments': 'HDC hdc, HGLRC hglrc', },
1105 { 'return_type': 'BOOL',
1106 'names': ['wglShareLists'],
1107 'arguments': 'HGLRC hglrc1, HGLRC hglrc2', },
1108 { 'return_type': 'BOOL',
1109 'names': ['wglSwapIntervalEXT'],
1110 'arguments': 'int interval', },
1111 { 'return_type': 'BOOL',
1112 'names': ['wglSwapLayerBuffers'],
1113 'arguments': 'HDC hdc, UINT fuPlanes', },
1114 { 'return_type': 'const char*',
1115 'names': ['wglGetExtensionsStringARB'],
1116 'arguments': 'HDC hDC', },
1117 { 'return_type': 'const char*',
1118 'names': ['wglGetExtensionsStringEXT'],
1119 'arguments': '', },
1120 { 'return_type': 'BOOL',
1121 'names': ['wglChoosePixelFormatARB'],
1122 'arguments':
1123 'HDC dc, const int* int_attrib_list, const float* float_attrib_list, '
1124 'UINT max_formats, int* formats, UINT* num_formats', },
1125 { 'return_type': 'HPBUFFERARB',
1126 'names': ['wglCreatePbufferARB'],
1127 'arguments': 'HDC hDC, int iPixelFormat, int iWidth, int iHeight, '
1128 'const int* piAttribList', },
1129 { 'return_type': 'HDC',
1130 'names': ['wglGetPbufferDCARB'],
1131 'arguments': 'HPBUFFERARB hPbuffer', },
1132 { 'return_type': 'int',
1133 'names': ['wglReleasePbufferDCARB'],
1134 'arguments': 'HPBUFFERARB hPbuffer, HDC hDC', },
1135 { 'return_type': 'BOOL',
1136 'names': ['wglDestroyPbufferARB'],
1137 'arguments': 'HPBUFFERARB hPbuffer', },
1138 { 'return_type': 'BOOL',
1139 'names': ['wglQueryPbufferARB'],
1140 'arguments': 'HPBUFFERARB hPbuffer, int iAttribute, int* piValue', },
1143 GLX_FUNCTIONS = [
1144 { 'return_type': 'int',
1145 'names': ['glXWaitVideoSyncSGI'],
1146 'arguments': 'int divisor, int remainder, unsigned int* count', },
1147 { 'return_type': 'XVisualInfo*',
1148 'names': ['glXChooseVisual'],
1149 'arguments': 'Display* dpy, int screen, int* attribList', },
1150 { 'return_type': 'void',
1151 'names': ['glXCopySubBufferMESA'],
1152 'arguments': 'Display* dpy, GLXDrawable drawable, '
1153 'int x, int y, int width, int height', },
1154 { 'return_type': 'GLXContext',
1155 'names': ['glXCreateContext'],
1156 'arguments':
1157 'Display* dpy, XVisualInfo* vis, GLXContext shareList, int direct', },
1158 { 'return_type': 'void',
1159 'names': ['glXBindTexImageEXT'],
1160 'arguments':
1161 'Display* dpy, GLXDrawable drawable, int buffer, int* attribList', },
1162 { 'return_type': 'void',
1163 'names': ['glXReleaseTexImageEXT'],
1164 'arguments': 'Display* dpy, GLXDrawable drawable, int buffer', },
1165 { 'return_type': 'void',
1166 'names': ['glXDestroyContext'],
1167 'arguments': 'Display* dpy, GLXContext ctx', },
1168 { 'return_type': 'int',
1169 'names': ['glXMakeCurrent'],
1170 'arguments': 'Display* dpy, GLXDrawable drawable, GLXContext ctx', },
1171 { 'return_type': 'void',
1172 'names': ['glXCopyContext'],
1173 'arguments':
1174 'Display* dpy, GLXContext src, GLXContext dst, unsigned long mask', },
1175 { 'return_type': 'void',
1176 'names': ['glXSwapBuffers'],
1177 'arguments': 'Display* dpy, GLXDrawable drawable', },
1178 { 'return_type': 'GLXPixmap',
1179 'names': ['glXCreateGLXPixmap'],
1180 'arguments': 'Display* dpy, XVisualInfo* visual, Pixmap pixmap', },
1181 { 'return_type': 'void',
1182 'names': ['glXDestroyGLXPixmap'],
1183 'arguments': 'Display* dpy, GLXPixmap pixmap', },
1184 { 'return_type': 'int',
1185 'names': ['glXQueryExtension'],
1186 'arguments': 'Display* dpy, int* errorb, int* event', },
1187 { 'return_type': 'int',
1188 'names': ['glXQueryVersion'],
1189 'arguments': 'Display* dpy, int* maj, int* min', },
1190 { 'return_type': 'int',
1191 'names': ['glXIsDirect'],
1192 'arguments': 'Display* dpy, GLXContext ctx', },
1193 { 'return_type': 'int',
1194 'names': ['glXGetConfig'],
1195 'arguments': 'Display* dpy, XVisualInfo* visual, int attrib, int* value', },
1196 { 'return_type': 'GLXContext',
1197 'names': ['glXGetCurrentContext'],
1198 'arguments': 'void', },
1199 { 'return_type': 'GLXDrawable',
1200 'names': ['glXGetCurrentDrawable'],
1201 'arguments': 'void', },
1202 { 'return_type': 'void',
1203 'names': ['glXWaitGL'],
1204 'arguments': 'void', },
1205 { 'return_type': 'void',
1206 'names': ['glXWaitX'],
1207 'arguments': 'void', },
1208 { 'return_type': 'void',
1209 'names': ['glXUseXFont'],
1210 'arguments': 'Font font, int first, int count, int list', },
1211 { 'return_type': 'const char*',
1212 'names': ['glXQueryExtensionsString'],
1213 'arguments': 'Display* dpy, int screen', },
1214 { 'return_type': 'const char*',
1215 'names': ['glXQueryServerString'],
1216 'arguments': 'Display* dpy, int screen, int name', },
1217 { 'return_type': 'const char*',
1218 'names': ['glXGetClientString'],
1219 'arguments': 'Display* dpy, int name', },
1220 { 'return_type': 'Display*',
1221 'names': ['glXGetCurrentDisplay'],
1222 'arguments': 'void', },
1223 { 'return_type': 'GLXFBConfig*',
1224 'names': ['glXChooseFBConfig'],
1225 'arguments':
1226 'Display* dpy, int screen, const int* attribList, int* nitems', },
1227 { 'return_type': 'int',
1228 'names': ['glXGetFBConfigAttrib'],
1229 'arguments': 'Display* dpy, GLXFBConfig config, int attribute, int* value', },
1230 { 'return_type': 'GLXFBConfig*',
1231 'names': ['glXGetFBConfigs'],
1232 'arguments': 'Display* dpy, int screen, int* nelements', },
1233 { 'return_type': 'XVisualInfo*',
1234 'names': ['glXGetVisualFromFBConfig'],
1235 'arguments': 'Display* dpy, GLXFBConfig config', },
1236 { 'return_type': 'GLXWindow',
1237 'names': ['glXCreateWindow'],
1238 'arguments':
1239 'Display* dpy, GLXFBConfig config, Window win, const int* attribList', },
1240 { 'return_type': 'void',
1241 'names': ['glXDestroyWindow'],
1242 'arguments': 'Display* dpy, GLXWindow window', },
1243 { 'return_type': 'GLXPixmap',
1244 'names': ['glXCreatePixmap'],
1245 'arguments': 'Display* dpy, GLXFBConfig config, '
1246 'Pixmap pixmap, const int* attribList', },
1247 { 'return_type': 'void',
1248 'names': ['glXDestroyPixmap'],
1249 'arguments': 'Display* dpy, GLXPixmap pixmap', },
1250 { 'return_type': 'GLXPbuffer',
1251 'names': ['glXCreatePbuffer'],
1252 'arguments': 'Display* dpy, GLXFBConfig config, const int* attribList', },
1253 { 'return_type': 'void',
1254 'names': ['glXDestroyPbuffer'],
1255 'arguments': 'Display* dpy, GLXPbuffer pbuf', },
1256 { 'return_type': 'void',
1257 'names': ['glXQueryDrawable'],
1258 'arguments':
1259 'Display* dpy, GLXDrawable draw, int attribute, unsigned int* value', },
1260 { 'return_type': 'GLXContext',
1261 'names': ['glXCreateNewContext'],
1262 'arguments': 'Display* dpy, GLXFBConfig config, int renderType, '
1263 'GLXContext shareList, int direct', },
1264 { 'return_type': 'int',
1265 'names': ['glXMakeContextCurrent'],
1266 'arguments':
1267 'Display* dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx', },
1268 { 'return_type': 'GLXDrawable',
1269 'names': ['glXGetCurrentReadDrawable'],
1270 'arguments': 'void', },
1271 { 'return_type': 'int',
1272 'names': ['glXQueryContext'],
1273 'arguments': 'Display* dpy, GLXContext ctx, int attribute, int* value', },
1274 { 'return_type': 'void',
1275 'names': ['glXSelectEvent'],
1276 'arguments': 'Display* dpy, GLXDrawable drawable, unsigned long mask', },
1277 { 'return_type': 'void',
1278 'names': ['glXGetSelectedEvent'],
1279 'arguments': 'Display* dpy, GLXDrawable drawable, unsigned long* mask', },
1280 { 'return_type': 'void',
1281 'names': ['glXSwapIntervalMESA'],
1282 'arguments': 'unsigned int interval', },
1283 { 'return_type': 'void',
1284 'names': ['glXSwapIntervalEXT'],
1285 'arguments': 'Display* dpy, GLXDrawable drawable, int interval', },
1286 { 'return_type': 'GLXFBConfig',
1287 'names': ['glXGetFBConfigFromVisualSGIX'],
1288 'arguments': 'Display* dpy, XVisualInfo* visualInfo', },
1289 { 'return_type': 'GLXContext',
1290 'names': ['glXCreateContextAttribsARB'],
1291 'arguments':
1292 'Display* dpy, GLXFBConfig config, GLXContext share_context, int direct, '
1293 'const int* attrib_list', },
1294 { 'return_type': 'bool',
1295 'names': ['glXGetSyncValuesOML'],
1296 'arguments':
1297 'Display* dpy, GLXDrawable drawable, int64* ust, int64* msc, '
1298 'int64* sbc' },
1299 { 'return_type': 'bool',
1300 'names': ['glXGetMscRateOML'],
1301 'arguments':
1302 'Display* dpy, GLXDrawable drawable, int32* numerator, '
1303 'int32* denominator' },
1306 FUNCTION_SETS = [
1307 [GL_FUNCTIONS, 'gl', [
1308 'GL/glext.h',
1309 'GLES2/gl2ext.h',
1310 # Files below are Chromium-specific and shipped with Chromium sources.
1311 'GL/glextchromium.h',
1312 'GLES2/gl2chromium.h',
1313 'GLES2/gl2extchromium.h'
1314 ], []],
1315 [OSMESA_FUNCTIONS, 'osmesa', [], []],
1316 [EGL_FUNCTIONS, 'egl', [
1317 'EGL/eglext.h',
1318 # Files below are Chromium-specific and shipped with Chromium sources.
1319 'EGL/eglextchromium.h',
1322 'EGL_ANGLE_d3d_share_handle_client_buffer',
1323 'EGL_ANGLE_surface_d3d_texture_2d_share_handle',
1326 [WGL_FUNCTIONS, 'wgl', ['GL/wglext.h'], []],
1327 [GLX_FUNCTIONS, 'glx', ['GL/glx.h', 'GL/glxext.h'], []],
1330 def GenerateHeader(file, functions, set_name, used_extensions):
1331 """Generates gl_bindings_autogen_x.h"""
1333 # Write file header.
1334 file.write(
1335 """// Copyright (c) 2012 The Chromium Authors. All rights reserved.
1336 // Use of this source code is governed by a BSD-style license that can be
1337 // found in the LICENSE file.
1339 // This file is automatically generated.
1341 #ifndef UI_GFX_GL_GL_BINDINGS_AUTOGEN_%(name)s_H_
1342 #define UI_GFX_GL_GL_BINDINGS_AUTOGEN_%(name)s_H_
1344 namespace gfx {
1346 class GLContext;
1348 """ % {'name': set_name.upper()})
1350 # Write typedefs for function pointer types. Always use the GL name for the
1351 # typedef.
1352 file.write('\n')
1353 for func in functions:
1354 file.write('typedef %s (GL_BINDING_CALL *%sProc)(%s);\n' %
1355 (func['return_type'], func['known_as'], func['arguments']))
1357 # Write declarations for booleans indicating which extensions are available.
1358 file.write('\n')
1359 file.write("struct Extensions%s {\n" % set_name.upper())
1360 for extension in sorted(used_extensions):
1361 file.write(' bool b_%s;\n' % extension)
1362 file.write('};\n')
1363 file.write('\n')
1365 # Write Procs struct.
1366 file.write("struct Procs%s {\n" % set_name.upper())
1367 for func in functions:
1368 file.write(' %sProc %sFn;\n' % (func['known_as'], func['known_as']))
1369 file.write('};\n')
1370 file.write('\n')
1372 # Write Api class.
1373 file.write(
1374 """class GL_EXPORT %(name)sApi {
1375 public:
1376 %(name)sApi();
1377 virtual ~%(name)sApi();
1379 """ % {'name': set_name.upper()})
1380 for func in functions:
1381 file.write(' virtual %s %sFn(%s) = 0;\n' %
1382 (func['return_type'], func['known_as'], func['arguments']))
1383 file.write('};\n')
1384 file.write('\n')
1386 file.write( '} // namespace gfx\n')
1388 # Write macros to invoke function pointers. Always use the GL name for the
1389 # macro.
1390 file.write('\n')
1391 for func in functions:
1392 file.write('#define %s ::gfx::g_current_%s_context->%sFn\n' %
1393 (func['known_as'], set_name.lower(), func['known_as']))
1395 file.write('\n')
1396 file.write('#endif // UI_GFX_GL_GL_BINDINGS_AUTOGEN_%s_H_\n' %
1397 set_name.upper())
1400 def GenerateAPIHeader(file, functions, set_name):
1401 """Generates gl_bindings_api_autogen_x.h"""
1403 # Write file header.
1404 file.write(
1405 """// Copyright (c) 2012 The Chromium Authors. All rights reserved.
1406 // Use of this source code is governed by a BSD-style license that can be
1407 // found in the LICENSE file.
1409 // This file is automatically generated.
1411 """ % {'name': set_name.upper()})
1413 # Write API declaration.
1414 for func in functions:
1415 file.write(' virtual %s %sFn(%s) OVERRIDE;\n' %
1416 (func['return_type'], func['known_as'], func['arguments']))
1418 file.write('\n')
1421 def GenerateMockHeader(file, functions, set_name):
1422 """Generates gl_mock_autogen_x.h"""
1424 # Write file header.
1425 file.write(
1426 """// Copyright (c) 2012 The Chromium Authors. All rights reserved.
1427 // Use of this source code is governed by a BSD-style license that can be
1428 // found in the LICENSE file.
1430 // This file is automatically generated.
1432 """ % {'name': set_name.upper()})
1434 # Write API declaration.
1435 for func in functions:
1436 args = func['arguments']
1437 if args == 'void':
1438 args = ''
1439 arg_count = 0
1440 if len(args):
1441 arg_count = func['arguments'].count(',') + 1
1442 file.write(' MOCK_METHOD%d(%s, %s(%s));\n' %
1443 (arg_count, func['known_as'][2:], func['return_type'], args))
1445 file.write('\n')
1448 def GenerateSource(file, functions, set_name, used_extensions):
1449 """Generates gl_bindings_autogen_x.cc"""
1451 # Write file header.
1452 file.write(
1453 """// Copyright (c) 2011 The Chromium Authors. All rights reserved.
1454 // Use of this source code is governed by a BSD-style license that can be
1455 // found in the LICENSE file.
1457 // This file is automatically generated.
1459 #include <string>
1460 #include "base/debug/trace_event.h"
1461 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
1462 #include "ui/gl/gl_bindings.h"
1463 #include "ui/gl/gl_context.h"
1464 #include "ui/gl/gl_implementation.h"
1465 #include "ui/gl/gl_version_info.h"
1466 #include "ui/gl/gl_%s_api_implementation.h"
1468 using gpu::gles2::GLES2Util;
1470 namespace gfx {
1471 """ % set_name.lower())
1473 file.write('\n')
1474 file.write('static bool g_debugBindingsInitialized;\n')
1475 file.write('Driver%s g_driver_%s;\n' % (set_name.upper(), set_name.lower()))
1476 file.write('\n')
1478 # Write stub functions that take the place of some functions before a context
1479 # is initialized. This is done to provide clear asserts on debug build and to
1480 # avoid crashing in case of a bug on release build.
1481 file.write('\n')
1482 for func in functions:
1483 unique_names = set([version['name'] for version in func['versions']])
1484 if len(unique_names) > 1:
1485 file.write('%s %sNotBound(%s) {\n' %
1486 (func['return_type'], func['known_as'], func['arguments']))
1487 file.write(' NOTREACHED();\n')
1488 return_type = func['return_type'].lower()
1489 # Returning 0 works for booleans, integers and pointers.
1490 if return_type != 'void':
1491 file.write(' return 0;\n')
1492 file.write('}\n')
1494 # Write function to initialize the function pointers that are always the same
1495 # and to initialize bindings where choice of the function depends on the
1496 # extension string or the GL version to point to stub functions.
1497 file.write('\n')
1498 file.write('void Driver%s::InitializeStaticBindings() {\n' %
1499 set_name.upper())
1501 def WriteFuncBinding(file, known_as, version_name):
1502 file.write(
1503 ' fn.%sFn = reinterpret_cast<%sProc>(GetGLProcAddress("%s"));\n' %
1504 (known_as, known_as, version_name))
1506 for func in functions:
1507 unique_names = set([version['name'] for version in func['versions']])
1508 if len(unique_names) == 1:
1509 WriteFuncBinding(file, func['known_as'], func['known_as'])
1510 else:
1511 file.write(' fn.%sFn = reinterpret_cast<%sProc>(%sNotBound);\n' %
1512 (func['known_as'], func['known_as'], func['known_as']))
1514 file.write('}\n')
1515 file.write('\n')
1517 # Write function to initialize bindings where choice of the function depends
1518 # on the extension string or the GL version.
1519 file.write("""void Driver%s::InitializeDynamicBindings(GLContext* context) {
1520 DCHECK(context && context->IsCurrent(NULL));
1521 const GLVersionInfo* ver ALLOW_UNUSED = context->GetVersionInfo();
1522 std::string extensions ALLOW_UNUSED = context->GetExtensions();
1523 extensions += " ";
1525 """ % set_name.upper())
1526 for extension in sorted(used_extensions):
1527 # Extra space at the end of the extension name is intentional, it is used
1528 # as a separator
1529 file.write(' ext.b_%s = extensions.find("%s ") != std::string::npos;\n' %
1530 (extension, extension))
1532 def WrapOr(cond):
1533 if ' || ' in cond:
1534 return '(%s)' % cond
1535 return cond
1537 def WrapAnd(cond):
1538 if ' && ' in cond:
1539 return '(%s)' % cond
1540 return cond
1542 def VersionCondition(version):
1543 conditions = []
1544 if 'gl_versions' in version:
1545 gl_versions = version['gl_versions']
1546 version_cond = ' || '.join(['ver->is_%s' % gl for gl in gl_versions])
1547 conditions.append(WrapOr(version_cond))
1548 if 'extensions' in version and version['extensions']:
1549 ext_cond = ' || '.join(['ext.b_%s' % e for e in version['extensions']])
1550 conditions.append(WrapOr(ext_cond))
1551 return ' && '.join(conditions)
1553 def WriteConditionalFuncBinding(file, func):
1554 # Functions with only one version are always bound unconditionally
1555 assert len(func['versions']) > 1
1556 known_as = func['known_as']
1557 i = 0
1558 first_version = True
1559 while i < len(func['versions']):
1560 version = func['versions'][i]
1561 cond = VersionCondition(version)
1562 combined_conditions = [WrapAnd(cond)]
1563 last_version = i + 1 == len(func['versions'])
1564 while not last_version and \
1565 func['versions'][i + 1]['name'] == version['name']:
1566 i += 1
1567 combinable_cond = VersionCondition(func['versions'][i])
1568 combined_conditions.append(WrapAnd(combinable_cond))
1569 last_version = i + 1 == len(func['versions'])
1570 if len(combined_conditions) > 1:
1571 if [1 for cond in combined_conditions if cond == '']:
1572 cond = ''
1573 else:
1574 cond = ' || '.join(combined_conditions)
1575 # Don't make the last possible binding conditional on anything else but
1576 # that the function isn't already bound to avoid verbose specification
1577 # of functions which have both ARB and core versions with the same name,
1578 # and to be able to bind to mock extension functions in unit tests which
1579 # call InitializeDynamicGLBindings with a stub context that doesn't have
1580 # extensions in its extension string.
1581 # TODO(oetuaho@nvidia.com): Get rid of the fallback.
1582 # http://crbug.com/325668
1583 if cond != '' and not last_version:
1584 if not first_version:
1585 file.write(' if (!fn.%sFn && (%s))\n ' % (known_as, cond))
1586 else:
1587 file.write(' if (%s)\n ' % cond)
1588 elif not first_version:
1589 file.write(' if (!fn.%sFn)\n ' % known_as)
1590 WriteFuncBinding(file, known_as, version['name'])
1591 i += 1
1592 first_version = False
1594 for func in functions:
1595 unique_names = set([version['name'] for version in func['versions']])
1596 if len(unique_names) > 1:
1597 file.write('\n')
1598 file.write(' fn.%sFn = 0;\n' % func['known_as'])
1599 file.write(' debug_fn.%sFn = 0;\n' % func['known_as'])
1600 WriteConditionalFuncBinding(file, func)
1602 # Some new function pointers have been added, so update them in debug bindings
1603 file.write('\n')
1604 file.write(' if (g_debugBindingsInitialized)\n')
1605 file.write(' InitializeDebugBindings();\n')
1606 file.write('}\n')
1607 file.write('\n')
1609 # Write logging wrappers for each function.
1610 file.write('extern "C" {\n')
1611 for func in functions:
1612 return_type = func['return_type']
1613 arguments = func['arguments']
1614 file.write('\n')
1615 file.write('static %s GL_BINDING_CALL Debug_%s(%s) {\n' %
1616 (return_type, func['known_as'], arguments))
1617 argument_names = re.sub(
1618 r'(const )?[a-zA-Z0-9_]+\** ([a-zA-Z0-9_]+)', r'\2', arguments)
1619 argument_names = re.sub(
1620 r'(const )?[a-zA-Z0-9_]+\** ([a-zA-Z0-9_]+)', r'\2', argument_names)
1621 log_argument_names = re.sub(
1622 r'const char\* ([a-zA-Z0-9_]+)', r'CONSTCHAR_\1', arguments)
1623 log_argument_names = re.sub(
1624 r'(const )?[a-zA-Z0-9_]+\* ([a-zA-Z0-9_]+)',
1625 r'CONSTVOID_\2', log_argument_names)
1626 log_argument_names = re.sub(
1627 r'(?<!E)GLenum ([a-zA-Z0-9_]+)', r'GLenum_\1', log_argument_names)
1628 log_argument_names = re.sub(
1629 r'(?<!E)GLboolean ([a-zA-Z0-9_]+)', r'GLboolean_\1', log_argument_names)
1630 log_argument_names = re.sub(
1631 r'(const )?[a-zA-Z0-9_]+\** ([a-zA-Z0-9_]+)', r'\2',
1632 log_argument_names)
1633 log_argument_names = re.sub(
1634 r'(const )?[a-zA-Z0-9_]+\** ([a-zA-Z0-9_]+)', r'\2',
1635 log_argument_names)
1636 log_argument_names = re.sub(
1637 r'CONSTVOID_([a-zA-Z0-9_]+)',
1638 r'static_cast<const void*>(\1)', log_argument_names)
1639 log_argument_names = re.sub(
1640 r'CONSTCHAR_([a-zA-Z0-9_]+)', r'\1', log_argument_names)
1641 log_argument_names = re.sub(
1642 r'GLenum_([a-zA-Z0-9_]+)', r'GLES2Util::GetStringEnum(\1)',
1643 log_argument_names)
1644 log_argument_names = re.sub(
1645 r'GLboolean_([a-zA-Z0-9_]+)', r'GLES2Util::GetStringBool(\1)',
1646 log_argument_names)
1647 log_argument_names = log_argument_names.replace(',', ' << ", " <<')
1648 if argument_names == 'void' or argument_names == '':
1649 argument_names = ''
1650 log_argument_names = ''
1651 else:
1652 log_argument_names = " << " + log_argument_names
1653 function_name = func['known_as']
1654 if return_type == 'void':
1655 file.write(' GL_SERVICE_LOG("%s" << "(" %s << ")");\n' %
1656 (function_name, log_argument_names))
1657 file.write(' g_driver_%s.debug_fn.%sFn(%s);\n' %
1658 (set_name.lower(), function_name, argument_names))
1659 if 'logging_code' in func:
1660 file.write("%s\n" % func['logging_code'])
1661 else:
1662 file.write(' GL_SERVICE_LOG("%s" << "(" %s << ")");\n' %
1663 (function_name, log_argument_names))
1664 file.write(' %s result = g_driver_%s.debug_fn.%sFn(%s);\n' %
1665 (return_type, set_name.lower(), function_name, argument_names))
1666 if 'logging_code' in func:
1667 file.write("%s\n" % func['logging_code'])
1668 else:
1669 file.write(' GL_SERVICE_LOG("GL_RESULT: " << result);\n')
1670 file.write(' return result;\n')
1671 file.write('}\n')
1672 file.write('} // extern "C"\n')
1674 # Write function to initialize the debug function pointers.
1675 file.write('\n')
1676 file.write('void Driver%s::InitializeDebugBindings() {\n' %
1677 set_name.upper())
1678 for func in functions:
1679 first_name = func['known_as']
1680 file.write(' if (!debug_fn.%sFn) {\n' % first_name)
1681 file.write(' debug_fn.%sFn = fn.%sFn;\n' % (first_name, first_name))
1682 file.write(' fn.%sFn = Debug_%s;\n' % (first_name, first_name))
1683 file.write(' }\n')
1684 file.write(' g_debugBindingsInitialized = true;\n')
1685 file.write('}\n')
1687 # Write function to clear all function pointers.
1688 file.write('\n')
1689 file.write("""void Driver%s::ClearBindings() {
1690 memset(this, 0, sizeof(*this));
1692 """ % set_name.upper())
1694 def MakeArgNames(arguments):
1695 argument_names = re.sub(
1696 r'(const )?[a-zA-Z0-9_]+\** ([a-zA-Z0-9_]+)', r'\2', arguments)
1697 argument_names = re.sub(
1698 r'(const )?[a-zA-Z0-9_]+\** ([a-zA-Z0-9_]+)', r'\2', argument_names)
1699 if argument_names == 'void' or argument_names == '':
1700 argument_names = ''
1701 return argument_names
1703 # Write GLApiBase functions
1704 for func in functions:
1705 function_name = func['known_as']
1706 return_type = func['return_type']
1707 arguments = func['arguments']
1708 file.write('\n')
1709 file.write('%s %sApiBase::%sFn(%s) {\n' %
1710 (return_type, set_name.upper(), function_name, arguments))
1711 argument_names = MakeArgNames(arguments)
1712 if return_type == 'void':
1713 file.write(' driver_->fn.%sFn(%s);\n' %
1714 (function_name, argument_names))
1715 else:
1716 file.write(' return driver_->fn.%sFn(%s);\n' %
1717 (function_name, argument_names))
1718 file.write('}\n')
1720 # Write TraceGLApi functions
1721 for func in functions:
1722 function_name = func['known_as']
1723 return_type = func['return_type']
1724 arguments = func['arguments']
1725 file.write('\n')
1726 file.write('%s Trace%sApi::%sFn(%s) {\n' %
1727 (return_type, set_name.upper(), function_name, arguments))
1728 argument_names = MakeArgNames(arguments)
1729 file.write(' TRACE_EVENT_BINARY_EFFICIENT0("gpu", "TraceGLAPI::%s")\n' %
1730 function_name)
1731 if return_type == 'void':
1732 file.write(' %s_api_->%sFn(%s);\n' %
1733 (set_name.lower(), function_name, argument_names))
1734 else:
1735 file.write(' return %s_api_->%sFn(%s);\n' %
1736 (set_name.lower(), function_name, argument_names))
1737 file.write('}\n')
1739 # Write NoContextGLApi functions
1740 if set_name.upper() == "GL":
1741 for func in functions:
1742 function_name = func['known_as']
1743 return_type = func['return_type']
1744 arguments = func['arguments']
1745 file.write('\n')
1746 file.write('%s NoContextGLApi::%sFn(%s) {\n' %
1747 (return_type, function_name, arguments))
1748 argument_names = MakeArgNames(arguments)
1749 no_context_error = "Trying to call %s() without current GL context" % function_name
1750 file.write(' NOTREACHED() << "%s";\n' % no_context_error)
1751 file.write(' LOG(ERROR) << "%s";\n' % no_context_error)
1752 default_value = { 'GLenum': 'static_cast<GLenum>(0)',
1753 'GLuint': '0U',
1754 'GLint': '0',
1755 'GLboolean': 'GL_FALSE',
1756 'GLbyte': '0',
1757 'GLubyte': '0',
1758 'GLbutfield': '0',
1759 'GLushort': '0',
1760 'GLsizei': '0',
1761 'GLfloat': '0.0f',
1762 'GLdouble': '0.0',
1763 'GLsync': 'NULL'}
1764 if return_type.endswith('*'):
1765 file.write(' return NULL;\n')
1766 elif return_type != 'void':
1767 file.write(' return %s;\n' % default_value[return_type])
1768 file.write('}\n')
1770 file.write('\n')
1771 file.write('} // namespace gfx\n')
1774 def GetUniquelyNamedFunctions(functions):
1775 uniquely_named_functions = {}
1777 for func in functions:
1778 for version in func['versions']:
1779 uniquely_named_functions[version['name']] = ({
1780 'name': version['name'],
1781 'return_type': func['return_type'],
1782 'arguments': func['arguments'],
1783 'known_as': func['known_as']
1785 return uniquely_named_functions
1788 def GenerateMockBindingsHeader(file, functions):
1789 """Headers for functions that invoke MockGLInterface members"""
1791 file.write(
1792 """// Copyright (c) 2014 The Chromium Authors. All rights reserved.
1793 // Use of this source code is governed by a BSD-style license that can be
1794 // found in the LICENSE file.
1796 // This file is automatically generated.
1798 """)
1799 uniquely_named_functions = GetUniquelyNamedFunctions(functions)
1801 for key in sorted(uniquely_named_functions.iterkeys()):
1802 func = uniquely_named_functions[key]
1803 file.write('static %s GL_BINDING_CALL Mock_%s(%s);\n' %
1804 (func['return_type'], func['name'], func['arguments']))
1807 def GenerateMockBindingsSource(file, functions):
1808 """Generates functions that invoke MockGLInterface members and a
1809 GetGLProcAddress function that returns addresses to those functions."""
1811 file.write(
1812 """// Copyright (c) 2011 The Chromium Authors. All rights reserved.
1813 // Use of this source code is governed by a BSD-style license that can be
1814 // found in the LICENSE file.
1816 // This file is automatically generated.
1818 #include <string.h>
1820 #include "ui/gl/gl_mock.h"
1822 namespace gfx {
1824 // This is called mainly to prevent the compiler combining the code of mock
1825 // functions with identical contents, so that their function pointers will be
1826 // different.
1827 void MakeFunctionUnique(const char *func_name) {
1828 VLOG(2) << "Calling mock " << func_name;
1831 """)
1832 # Write functions that trampoline into the set MockGLInterface instance.
1833 uniquely_named_functions = GetUniquelyNamedFunctions(functions)
1834 sorted_function_names = sorted(uniquely_named_functions.iterkeys())
1836 for key in sorted_function_names:
1837 func = uniquely_named_functions[key]
1838 file.write('\n')
1839 file.write('%s GL_BINDING_CALL MockGLInterface::Mock_%s(%s) {\n' %
1840 (func['return_type'], func['name'], func['arguments']))
1841 file.write(' MakeFunctionUnique("%s");\n' % func['name'])
1842 arg_re = r'(const )?[a-zA-Z0-9]+((\s*const\s*)?\*)* ([a-zA-Z0-9]+)'
1843 argument_names = re.sub(arg_re, r'\4', func['arguments'])
1844 if argument_names == 'void':
1845 argument_names = ''
1846 function_name = func['known_as'][2:]
1847 if func['return_type'] == 'void':
1848 file.write(' interface_->%s(%s);\n' %
1849 (function_name, argument_names))
1850 else:
1851 file.write(' return interface_->%s(%s);\n' %
1852 (function_name, argument_names))
1853 file.write('}\n')
1855 # Write an 'invalid' function to catch code calling through uninitialized
1856 # function pointers or trying to interpret the return value of
1857 # GLProcAddress().
1858 file.write('\n')
1859 file.write('static void MockInvalidFunction() {\n')
1860 file.write(' NOTREACHED();\n')
1861 file.write('}\n')
1863 # Write a function to lookup a mock GL function based on its name.
1864 file.write('\n')
1865 file.write('void* GL_BINDING_CALL ' +
1866 'MockGLInterface::GetGLProcAddress(const char* name) {\n')
1867 for key in sorted_function_names:
1868 name = uniquely_named_functions[key]['name']
1869 file.write(' if (strcmp(name, "%s") == 0)\n' % name)
1870 file.write(' return reinterpret_cast<void*>(Mock_%s);\n' % name)
1871 # Always return a non-NULL pointer like some EGL implementations do.
1872 file.write(' return reinterpret_cast<void*>(&MockInvalidFunction);\n')
1873 file.write('}\n')
1875 file.write('\n')
1876 file.write('} // namespace gfx\n')
1879 def ParseExtensionFunctionsFromHeader(header_file):
1880 """Parse a C extension header file and return a map from extension names to
1881 a list of functions.
1883 Args:
1884 header_file: Line-iterable C header file.
1885 Returns:
1886 Map of extension name => functions.
1888 extension_start = re.compile(
1889 r'#ifndef ((?:GL|EGL|WGL|GLX)_[A-Z]+_[a-zA-Z]\w+)')
1890 extension_function = re.compile(r'.+\s+([a-z]+\w+)\s*\(')
1891 typedef = re.compile(r'typedef .*')
1892 macro_start = re.compile(r'^#(if|ifdef|ifndef).*')
1893 macro_end = re.compile(r'^#endif.*')
1894 macro_depth = 0
1895 current_extension = None
1896 current_extension_depth = 0
1897 extensions = collections.defaultdict(lambda: [])
1898 for line in header_file:
1899 if macro_start.match(line):
1900 macro_depth += 1
1901 elif macro_end.match(line):
1902 macro_depth -= 1
1903 if macro_depth < current_extension_depth:
1904 current_extension = None
1905 match = extension_start.match(line)
1906 if match:
1907 current_extension = match.group(1)
1908 current_extension_depth = macro_depth
1909 assert current_extension not in extensions, \
1910 "Duplicate extension: " + current_extension
1911 match = extension_function.match(line)
1912 if match and current_extension and not typedef.match(line):
1913 extensions[current_extension].append(match.group(1))
1914 return extensions
1917 def GetExtensionFunctions(extension_headers):
1918 """Parse extension functions from a list of header files.
1920 Args:
1921 extension_headers: List of header file names.
1922 Returns:
1923 Map of extension name => list of functions.
1925 extensions = {}
1926 for header in extension_headers:
1927 extensions.update(ParseExtensionFunctionsFromHeader(open(header)))
1928 return extensions
1931 def GetFunctionToExtensionMap(extensions):
1932 """Construct map from a function names to extensions which define the
1933 function.
1935 Args:
1936 extensions: Map of extension name => functions.
1937 Returns:
1938 Map of function name => extension name.
1940 function_to_extensions = {}
1941 for extension, functions in extensions.items():
1942 for function in functions:
1943 if not function in function_to_extensions:
1944 function_to_extensions[function] = []
1945 function_to_extensions[function].append(extension)
1946 return function_to_extensions
1949 def LooksLikeExtensionFunction(function):
1950 """Heuristic to see if a function name is consistent with extension function
1951 naming."""
1952 vendor = re.match(r'\w+?([A-Z][A-Z]+)$', function)
1953 return vendor is not None and not vendor.group(1) in ['GL', 'API', 'DC']
1956 def FillExtensionsFromHeaders(functions, extension_headers, extra_extensions):
1957 """Determine which functions belong to extensions based on extension headers,
1958 and fill in this information to the functions table for functions that don't
1959 already have the information.
1961 Args:
1962 functions: List of (return type, function versions, arguments).
1963 extension_headers: List of header file names.
1964 extra_extensions: Extensions to add to the list.
1965 Returns:
1966 Set of used extensions.
1968 # Parse known extensions.
1969 extensions = GetExtensionFunctions(extension_headers)
1970 functions_to_extensions = GetFunctionToExtensionMap(extensions)
1972 # Fill in the extension information.
1973 used_extensions = set()
1974 for func in functions:
1975 for version in func['versions']:
1976 name = version['name']
1977 # Make sure we know about all extensions and extension functions.
1978 if 'extensions' in version:
1979 used_extensions.update(version['extensions'])
1980 elif name in functions_to_extensions:
1981 # If there are multiple versions with the same name, assume that they
1982 # already have all the correct conditions, we can't just blindly add
1983 # the same extension conditions to all of them
1984 if len([v for v in func['versions'] if v['name'] == name]) == 1:
1985 version['extensions'] = functions_to_extensions[name]
1986 used_extensions.update(version['extensions'])
1987 elif LooksLikeExtensionFunction(name):
1988 raise RuntimeError('%s looks like an extension function but does not '
1989 'belong to any of the known extensions.' % name)
1991 # Add extensions that do not have any functions.
1992 used_extensions.update(extra_extensions)
1994 return used_extensions
1997 def ResolveHeader(header, header_paths):
1998 paths = header_paths.split(':')
2000 for path in paths:
2001 result = os.path.join(path, header)
2002 if not os.path.isabs(path):
2003 result = os.path.relpath(os.path.join(os.getcwd(), result), os.getcwd())
2004 if os.path.exists(result):
2005 # Always use forward slashes as path separators. Otherwise backslashes
2006 # may be incorrectly interpreted as escape characters.
2007 return result.replace(os.path.sep, '/')
2009 raise Exception('Header %s not found.' % header)
2012 def main(argv):
2013 """This is the main function."""
2015 parser = optparse.OptionParser()
2016 parser.add_option('--inputs', action='store_true')
2017 parser.add_option('--header-paths')
2019 options, args = parser.parse_args(argv)
2021 if options.inputs:
2022 for [_, _, headers, _] in FUNCTION_SETS:
2023 for header in headers:
2024 print ResolveHeader(header, options.header_paths)
2025 return 0
2027 directory = '.'
2028 if len(args) >= 1:
2029 directory = args[0]
2031 for [functions, set_name, extension_headers, extensions] in FUNCTION_SETS:
2032 # Function names can be specified in two ways (list of unique names or list
2033 # of versions with different binding conditions). Fill in the data to the
2034 # versions list in case it is missing, so that can be used from here on:
2035 for func in functions:
2036 assert 'versions' in func or 'names' in func, 'Function with no names'
2037 if 'versions' not in func:
2038 func['versions'] = [{'name': n} for n in func['names']]
2039 # Use the first version's name unless otherwise specified
2040 if 'known_as' not in func:
2041 func['known_as'] = func['versions'][0]['name']
2042 # Make sure that 'names' is not accidentally used instead of 'versions'
2043 if 'names' in func:
2044 del func['names']
2046 extension_headers = [ResolveHeader(h, options.header_paths)
2047 for h in extension_headers]
2048 used_extensions = FillExtensionsFromHeaders(
2049 functions, extension_headers, extensions)
2051 header_file = open(
2052 os.path.join(directory, 'gl_bindings_autogen_%s.h' % set_name), 'wb')
2053 GenerateHeader(header_file, functions, set_name, used_extensions)
2054 header_file.close()
2056 header_file = open(
2057 os.path.join(directory, 'gl_bindings_api_autogen_%s.h' % set_name),
2058 'wb')
2059 GenerateAPIHeader(header_file, functions, set_name)
2060 header_file.close()
2062 source_file = open(
2063 os.path.join(directory, 'gl_bindings_autogen_%s.cc' % set_name), 'wb')
2064 GenerateSource(source_file, functions, set_name, used_extensions)
2065 source_file.close()
2067 header_file = open(
2068 os.path.join(directory, 'gl_mock_autogen_gl.h'), 'wb')
2069 GenerateMockHeader(header_file, GL_FUNCTIONS, 'gl')
2070 header_file.close()
2072 header_file = open(os.path.join(directory, 'gl_bindings_autogen_mock.h'),
2073 'wb')
2074 GenerateMockBindingsHeader(header_file, GL_FUNCTIONS)
2075 header_file.close()
2077 source_file = open(os.path.join(directory, 'gl_bindings_autogen_mock.cc'),
2078 'wb')
2079 GenerateMockBindingsSource(source_file, GL_FUNCTIONS)
2080 source_file.close()
2081 return 0
2084 if __name__ == '__main__':
2085 sys.exit(main(sys.argv[1:]))