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 GLES2 command buffers."""
13 from optparse
import OptionParser
14 from subprocess
import call
17 _SIZE_OF_COMMAND_HEADER
= 4
18 _FIRST_SPECIFIC_COMMAND_ID
= 256
20 _LICENSE
= """// Copyright 2014 The Chromium Authors. All rights reserved.
21 // Use of this source code is governed by a BSD-style license that can be
22 // found in the LICENSE file.
26 _DO_NOT_EDIT_WARNING
= """// This file is auto-generated from
27 // gpu/command_buffer/build_gles2_cmd_buffer.py
28 // It's formatted by clang-format using chromium coding style:
29 // clang-format -i -style=chromium filename
34 # This string is copied directly out of the gl2.h file from GLES2.0
38 # *) Any argument that is a resourceID has been changed to GLid<Type>.
39 # (not pointer arguments) and if it's allowed to be zero it's GLidZero<Type>
40 # If it's allowed to not exist it's GLidBind<Type>
42 # *) All GLenums have been changed to GLenumTypeOfEnum
45 'GLenum': 'unsigned int',
46 'GLboolean': 'unsigned char',
47 'GLbitfield': 'unsigned int',
48 'GLbyte': 'signed char',
52 'GLubyte': 'unsigned char',
53 'GLushort': 'unsigned short',
54 'GLuint': 'unsigned int',
63 'GLintptr': 'long int',
64 'GLsizeiptr': 'long int'
68 'GLintptr': 'long long int',
69 'GLsizeiptr': 'long long int'
72 # Capabilites selected with glEnable
75 {'name': 'cull_face'},
76 {'name': 'depth_test', 'state_flag': 'framebuffer_state_.clear_state_dirty'},
77 {'name': 'dither', 'default': True},
78 {'name': 'polygon_offset_fill'},
79 {'name': 'sample_alpha_to_coverage'},
80 {'name': 'sample_coverage'},
81 {'name': 'scissor_test'},
82 {'name': 'stencil_test',
83 'state_flag': 'framebuffer_state_.clear_state_dirty'},
90 'enum': 'GL_COLOR_CLEAR_VALUE',
92 {'name': 'color_clear_red', 'type': 'GLfloat', 'default': '0.0f'},
93 {'name': 'color_clear_green', 'type': 'GLfloat', 'default': '0.0f'},
94 {'name': 'color_clear_blue', 'type': 'GLfloat', 'default': '0.0f'},
95 {'name': 'color_clear_alpha', 'type': 'GLfloat', 'default': '0.0f'},
100 'func': 'ClearDepth',
101 'enum': 'GL_DEPTH_CLEAR_VALUE',
103 {'name': 'depth_clear', 'type': 'GLclampf', 'default': '1.0f'},
109 'enum': 'GL_COLOR_WRITEMASK',
112 'name': 'color_mask_red',
118 'name': 'color_mask_green',
124 'name': 'color_mask_blue',
130 'name': 'color_mask_alpha',
136 'state_flag': 'framebuffer_state_.clear_state_dirty',
140 'func': 'ClearStencil',
141 'enum': 'GL_STENCIL_CLEAR_VALUE',
143 {'name': 'stencil_clear', 'type': 'GLint', 'default': '0'},
148 'func': 'BlendColor',
149 'enum': 'GL_BLEND_COLOR',
151 {'name': 'blend_color_red', 'type': 'GLfloat', 'default': '0.0f'},
152 {'name': 'blend_color_green', 'type': 'GLfloat', 'default': '0.0f'},
153 {'name': 'blend_color_blue', 'type': 'GLfloat', 'default': '0.0f'},
154 {'name': 'blend_color_alpha', 'type': 'GLfloat', 'default': '0.0f'},
159 'func': 'BlendEquationSeparate',
162 'name': 'blend_equation_rgb',
164 'enum': 'GL_BLEND_EQUATION_RGB',
165 'default': 'GL_FUNC_ADD',
168 'name': 'blend_equation_alpha',
170 'enum': 'GL_BLEND_EQUATION_ALPHA',
171 'default': 'GL_FUNC_ADD',
177 'func': 'BlendFuncSeparate',
180 'name': 'blend_source_rgb',
182 'enum': 'GL_BLEND_SRC_RGB',
186 'name': 'blend_dest_rgb',
188 'enum': 'GL_BLEND_DST_RGB',
189 'default': 'GL_ZERO',
192 'name': 'blend_source_alpha',
194 'enum': 'GL_BLEND_SRC_ALPHA',
198 'name': 'blend_dest_alpha',
200 'enum': 'GL_BLEND_DST_ALPHA',
201 'default': 'GL_ZERO',
207 'func': 'PolygonOffset',
210 'name': 'polygon_offset_factor',
212 'enum': 'GL_POLYGON_OFFSET_FACTOR',
216 'name': 'polygon_offset_units',
218 'enum': 'GL_POLYGON_OFFSET_UNITS',
226 'enum': 'GL_CULL_FACE_MODE',
231 'default': 'GL_BACK',
238 'enum': 'GL_FRONT_FACE',
239 'states': [{'name': 'front_face', 'type': 'GLenum', 'default': 'GL_CCW'}],
244 'enum': 'GL_DEPTH_FUNC',
245 'states': [{'name': 'depth_func', 'type': 'GLenum', 'default': 'GL_LESS'}],
249 'func': 'DepthRange',
250 'enum': 'GL_DEPTH_RANGE',
252 {'name': 'z_near', 'type': 'GLclampf', 'default': '0.0f'},
253 {'name': 'z_far', 'type': 'GLclampf', 'default': '1.0f'},
258 'func': 'SampleCoverage',
261 'name': 'sample_coverage_value',
263 'enum': 'GL_SAMPLE_COVERAGE_VALUE',
267 'name': 'sample_coverage_invert',
269 'enum': 'GL_SAMPLE_COVERAGE_INVERT',
276 'func': 'StencilMaskSeparate',
277 'state_flag': 'framebuffer_state_.clear_state_dirty',
280 'name': 'stencil_front_writemask',
282 'enum': 'GL_STENCIL_WRITEMASK',
283 'default': '0xFFFFFFFFU',
287 'name': 'stencil_back_writemask',
289 'enum': 'GL_STENCIL_BACK_WRITEMASK',
290 'default': '0xFFFFFFFFU',
297 'func': 'StencilOpSeparate',
300 'name': 'stencil_front_fail_op',
302 'enum': 'GL_STENCIL_FAIL',
303 'default': 'GL_KEEP',
306 'name': 'stencil_front_z_fail_op',
308 'enum': 'GL_STENCIL_PASS_DEPTH_FAIL',
309 'default': 'GL_KEEP',
312 'name': 'stencil_front_z_pass_op',
314 'enum': 'GL_STENCIL_PASS_DEPTH_PASS',
315 'default': 'GL_KEEP',
318 'name': 'stencil_back_fail_op',
320 'enum': 'GL_STENCIL_BACK_FAIL',
321 'default': 'GL_KEEP',
324 'name': 'stencil_back_z_fail_op',
326 'enum': 'GL_STENCIL_BACK_PASS_DEPTH_FAIL',
327 'default': 'GL_KEEP',
330 'name': 'stencil_back_z_pass_op',
332 'enum': 'GL_STENCIL_BACK_PASS_DEPTH_PASS',
333 'default': 'GL_KEEP',
339 'func': 'StencilFuncSeparate',
342 'name': 'stencil_front_func',
344 'enum': 'GL_STENCIL_FUNC',
345 'default': 'GL_ALWAYS',
348 'name': 'stencil_front_ref',
350 'enum': 'GL_STENCIL_REF',
354 'name': 'stencil_front_mask',
356 'enum': 'GL_STENCIL_VALUE_MASK',
357 'default': '0xFFFFFFFFU',
360 'name': 'stencil_back_func',
362 'enum': 'GL_STENCIL_BACK_FUNC',
363 'default': 'GL_ALWAYS',
366 'name': 'stencil_back_ref',
368 'enum': 'GL_STENCIL_BACK_REF',
372 'name': 'stencil_back_mask',
374 'enum': 'GL_STENCIL_BACK_VALUE_MASK',
375 'default': '0xFFFFFFFFU',
380 'type': 'NamedParameter',
384 'name': 'hint_generate_mipmap',
386 'enum': 'GL_GENERATE_MIPMAP_HINT',
387 'default': 'GL_DONT_CARE'
390 'name': 'hint_fragment_shader_derivative',
392 'enum': 'GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES',
393 'default': 'GL_DONT_CARE',
394 'extension_flag': 'oes_standard_derivatives'
399 'type': 'NamedParameter',
400 'func': 'PixelStorei',
403 'name': 'pack_alignment',
405 'enum': 'GL_PACK_ALIGNMENT',
409 'name': 'unpack_alignment',
411 'enum': 'GL_UNPACK_ALIGNMENT',
416 # TODO: Consider implemenenting these states
421 'enum': 'GL_LINE_WIDTH',
424 'name': 'line_width',
427 'range_checks': [{'check': "<= 0.0f", 'test_value': "0.0f"}],
434 'enum': 'GL_DEPTH_WRITEMASK',
437 'name': 'depth_mask',
443 'state_flag': 'framebuffer_state_.clear_state_dirty',
448 'enum': 'GL_SCISSOR_BOX',
450 # NOTE: These defaults reset at GLES2DecoderImpl::Initialization.
455 'expected': 'kViewportX',
461 'expected': 'kViewportY',
464 'name': 'scissor_width',
467 'expected': 'kViewportWidth',
470 'name': 'scissor_height',
473 'expected': 'kViewportHeight',
480 'enum': 'GL_VIEWPORT',
482 # NOTE: These defaults reset at GLES2DecoderImpl::Initialization.
484 'name': 'viewport_x',
487 'expected': 'kViewportX',
490 'name': 'viewport_y',
493 'expected': 'kViewportY',
496 'name': 'viewport_width',
499 'expected': 'kViewportWidth',
502 'name': 'viewport_height',
505 'expected': 'kViewportHeight',
509 'MatrixValuesCHROMIUM': {
510 'type': 'NamedParameter',
511 'func': 'MatrixLoadfEXT',
513 { 'enum': 'GL_PATH_MODELVIEW_MATRIX_CHROMIUM',
514 'enum_set': 'GL_PATH_MODELVIEW_CHROMIUM',
515 'name': 'modelview_matrix',
518 '1.0f', '0.0f','0.0f','0.0f',
519 '0.0f', '1.0f','0.0f','0.0f',
520 '0.0f', '0.0f','1.0f','0.0f',
521 '0.0f', '0.0f','0.0f','1.0f',
523 'extension_flag': 'chromium_path_rendering',
525 { 'enum': 'GL_PATH_PROJECTION_MATRIX_CHROMIUM',
526 'enum_set': 'GL_PATH_PROJECTION_CHROMIUM',
527 'name': 'projection_matrix',
530 '1.0f', '0.0f','0.0f','0.0f',
531 '0.0f', '1.0f','0.0f','0.0f',
532 '0.0f', '0.0f','1.0f','0.0f',
533 '0.0f', '0.0f','0.0f','1.0f',
535 'extension_flag': 'chromium_path_rendering',
541 # Named type info object represents a named type that is used in OpenGL call
542 # arguments. Each named type defines a set of valid OpenGL call arguments. The
543 # named types are used in 'cmd_buffer_functions.txt'.
544 # type: The actual GL type of the named type.
545 # valid: The list of values that are valid for both the client and the service.
546 # invalid: Examples of invalid values for the type. At least these values
547 # should be tested to be invalid.
548 # is_complete: The list of valid values of type are final and will not be
549 # modified during runtime.
558 'GL_LINEAR_MIPMAP_LINEAR',
561 'FrameBufferTarget': {
567 'GL_DRAW_FRAMEBUFFER' ,
568 'GL_READ_FRAMEBUFFER' ,
571 'RenderBufferTarget': {
584 'GL_ELEMENT_ARRAY_BUFFER',
601 'CompressedTextureFormat': {
609 # NOTE: State an Capability entries added later.
611 'GL_ALIASED_LINE_WIDTH_RANGE',
612 'GL_ALIASED_POINT_SIZE_RANGE',
614 'GL_ARRAY_BUFFER_BINDING',
616 'GL_COMPRESSED_TEXTURE_FORMATS',
617 'GL_CURRENT_PROGRAM',
620 'GL_ELEMENT_ARRAY_BUFFER_BINDING',
621 'GL_FRAMEBUFFER_BINDING',
622 'GL_GENERATE_MIPMAP_HINT',
624 'GL_IMPLEMENTATION_COLOR_READ_FORMAT',
625 'GL_IMPLEMENTATION_COLOR_READ_TYPE',
626 'GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS',
627 'GL_MAX_CUBE_MAP_TEXTURE_SIZE',
628 'GL_MAX_FRAGMENT_UNIFORM_VECTORS',
629 'GL_MAX_RENDERBUFFER_SIZE',
630 'GL_MAX_TEXTURE_IMAGE_UNITS',
631 'GL_MAX_TEXTURE_SIZE',
632 'GL_MAX_VARYING_VECTORS',
633 'GL_MAX_VERTEX_ATTRIBS',
634 'GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS',
635 'GL_MAX_VERTEX_UNIFORM_VECTORS',
636 'GL_MAX_VIEWPORT_DIMS',
637 'GL_NUM_COMPRESSED_TEXTURE_FORMATS',
638 'GL_NUM_SHADER_BINARY_FORMATS',
641 'GL_RENDERBUFFER_BINDING',
643 'GL_SAMPLE_COVERAGE_INVERT',
644 'GL_SAMPLE_COVERAGE_VALUE',
647 'GL_SHADER_BINARY_FORMATS',
648 'GL_SHADER_COMPILER',
651 'GL_TEXTURE_BINDING_2D',
652 'GL_TEXTURE_BINDING_CUBE_MAP',
653 'GL_UNPACK_ALIGNMENT',
654 'GL_UNPACK_FLIP_Y_CHROMIUM',
655 'GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM',
656 'GL_UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM',
657 'GL_BIND_GENERATES_RESOURCE_CHROMIUM',
658 # we can add this because we emulate it if the driver does not support it.
659 'GL_VERTEX_ARRAY_BINDING_OES',
666 'GetTexParamTarget': {
670 'GL_TEXTURE_CUBE_MAP',
673 'GL_PROXY_TEXTURE_CUBE_MAP',
680 'GL_TEXTURE_CUBE_MAP_POSITIVE_X',
681 'GL_TEXTURE_CUBE_MAP_NEGATIVE_X',
682 'GL_TEXTURE_CUBE_MAP_POSITIVE_Y',
683 'GL_TEXTURE_CUBE_MAP_NEGATIVE_Y',
684 'GL_TEXTURE_CUBE_MAP_POSITIVE_Z',
685 'GL_TEXTURE_CUBE_MAP_NEGATIVE_Z',
688 'GL_PROXY_TEXTURE_CUBE_MAP',
691 'TextureBindTarget': {
695 'GL_TEXTURE_CUBE_MAP',
706 'GL_FRAGMENT_SHADER',
709 'GL_GEOMETRY_SHADER',
745 'GL_FUNC_REVERSE_SUBTRACT',
758 'GL_ONE_MINUS_SRC_COLOR',
760 'GL_ONE_MINUS_DST_COLOR',
762 'GL_ONE_MINUS_SRC_ALPHA',
764 'GL_ONE_MINUS_DST_ALPHA',
766 'GL_ONE_MINUS_CONSTANT_COLOR',
768 'GL_ONE_MINUS_CONSTANT_ALPHA',
769 'GL_SRC_ALPHA_SATURATE',
778 'GL_ONE_MINUS_SRC_COLOR',
780 'GL_ONE_MINUS_DST_COLOR',
782 'GL_ONE_MINUS_SRC_ALPHA',
784 'GL_ONE_MINUS_DST_ALPHA',
786 'GL_ONE_MINUS_CONSTANT_COLOR',
788 'GL_ONE_MINUS_CONSTANT_ALPHA',
793 'valid': ["GL_%s" % cap
['name'].upper() for cap
in _CAPABILITY_FLAGS
],
840 'GL_COLOR_ATTACHMENT0',
841 'GL_DEPTH_ATTACHMENT',
842 'GL_STENCIL_ATTACHMENT',
845 'BackbufferAttachment': {
860 'GL_PIXEL_PACK_BUFFER',
863 'FrameBufferParameter': {
866 'GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE',
867 'GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME',
868 'GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL',
869 'GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE',
875 'GL_PATH_PROJECTION_CHROMIUM',
876 'GL_PATH_MODELVIEW_CHROMIUM',
879 'ProgramParameter': {
884 'GL_VALIDATE_STATUS',
885 'GL_INFO_LOG_LENGTH',
886 'GL_ATTACHED_SHADERS',
887 'GL_ACTIVE_ATTRIBUTES',
888 'GL_ACTIVE_ATTRIBUTE_MAX_LENGTH',
889 'GL_ACTIVE_UNIFORMS',
890 'GL_ACTIVE_UNIFORM_MAX_LENGTH',
893 'QueryObjectParameter': {
896 'GL_QUERY_RESULT_EXT',
897 'GL_QUERY_RESULT_AVAILABLE_EXT',
903 'GL_CURRENT_QUERY_EXT',
909 'GL_ANY_SAMPLES_PASSED_EXT',
910 'GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT',
911 'GL_COMMANDS_ISSUED_CHROMIUM',
912 'GL_LATENCY_QUERY_CHROMIUM',
913 'GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM',
914 'GL_ASYNC_PIXEL_PACK_COMPLETED_CHROMIUM',
915 'GL_COMMANDS_COMPLETED_CHROMIUM',
918 'RenderBufferParameter': {
921 'GL_RENDERBUFFER_RED_SIZE',
922 'GL_RENDERBUFFER_GREEN_SIZE',
923 'GL_RENDERBUFFER_BLUE_SIZE',
924 'GL_RENDERBUFFER_ALPHA_SIZE',
925 'GL_RENDERBUFFER_DEPTH_SIZE',
926 'GL_RENDERBUFFER_STENCIL_SIZE',
927 'GL_RENDERBUFFER_WIDTH',
928 'GL_RENDERBUFFER_HEIGHT',
929 'GL_RENDERBUFFER_INTERNAL_FORMAT',
938 'GL_INFO_LOG_LENGTH',
939 'GL_SHADER_SOURCE_LENGTH',
940 'GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE',
960 'GL_SHADING_LANGUAGE_VERSION',
964 'TextureParameter': {
967 'GL_TEXTURE_MAG_FILTER',
968 'GL_TEXTURE_MIN_FILTER',
969 'GL_TEXTURE_POOL_CHROMIUM',
974 'GL_GENERATE_MIPMAP',
980 'GL_TEXTURE_POOL_MANAGED_CHROMIUM',
981 'GL_TEXTURE_POOL_UNMANAGED_CHROMIUM',
988 'GL_MIRRORED_REPEAT',
992 'TextureMinFilterMode': {
997 'GL_NEAREST_MIPMAP_NEAREST',
998 'GL_LINEAR_MIPMAP_NEAREST',
999 'GL_NEAREST_MIPMAP_LINEAR',
1000 'GL_LINEAR_MIPMAP_LINEAR',
1003 'TextureMagFilterMode': {
1014 'GL_FRAMEBUFFER_ATTACHMENT_ANGLE',
1017 'VertexAttribute': {
1020 # some enum that the decoder actually passes through to GL needs
1021 # to be the first listed here since it's used in unit tests.
1022 'GL_VERTEX_ATTRIB_ARRAY_NORMALIZED',
1023 'GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING',
1024 'GL_VERTEX_ATTRIB_ARRAY_ENABLED',
1025 'GL_VERTEX_ATTRIB_ARRAY_SIZE',
1026 'GL_VERTEX_ATTRIB_ARRAY_STRIDE',
1027 'GL_VERTEX_ATTRIB_ARRAY_TYPE',
1028 'GL_CURRENT_VERTEX_ATTRIB',
1034 'GL_VERTEX_ATTRIB_ARRAY_POINTER',
1040 'GL_GENERATE_MIPMAP_HINT',
1043 'GL_PERSPECTIVE_CORRECTION_HINT',
1057 'GL_PACK_ALIGNMENT',
1058 'GL_UNPACK_ALIGNMENT',
1059 'GL_UNPACK_FLIP_Y_CHROMIUM',
1060 'GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM',
1061 'GL_UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM',
1064 'GL_PACK_SWAP_BYTES',
1065 'GL_UNPACK_SWAP_BYTES',
1068 'PixelStoreAlignment': {
1081 'ReadPixelFormat': {
1093 'GL_UNSIGNED_SHORT_5_6_5',
1094 'GL_UNSIGNED_SHORT_4_4_4_4',
1095 'GL_UNSIGNED_SHORT_5_5_5_1',
1106 'GL_UNSIGNED_SHORT_5_6_5',
1107 'GL_UNSIGNED_SHORT_4_4_4_4',
1108 'GL_UNSIGNED_SHORT_5_5_5_1',
1115 'RenderBufferFormat': {
1121 'GL_DEPTH_COMPONENT16',
1122 'GL_STENCIL_INDEX8',
1125 'ShaderBinaryFormat': {
1148 'GL_LUMINANCE_ALPHA',
1157 'TextureInternalFormat': {
1162 'GL_LUMINANCE_ALPHA',
1171 'TextureInternalFormatStorage': {
1178 'GL_LUMINANCE8_EXT',
1179 'GL_LUMINANCE8_ALPHA8_EXT',
1184 'VertexAttribType': {
1190 'GL_UNSIGNED_SHORT',
1191 # 'GL_FIXED', // This is not available on Desktop GL.
1200 'is_complete': True,
1208 'VertexAttribSize': {
1223 'is_complete': True,
1232 'type': 'GLboolean',
1233 'is_complete': True,
1244 'GL_GUILTY_CONTEXT_RESET_ARB',
1245 'GL_INNOCENT_CONTEXT_RESET_ARB',
1246 'GL_UNKNOWN_CONTEXT_RESET_ARB',
1251 # This table specifies the different pepper interfaces that are supported for
1252 # GL commands. 'dev' is true if it's a dev interface.
1253 _PEPPER_INTERFACES
= [
1254 {'name': '', 'dev': False},
1255 {'name': 'InstancedArrays', 'dev': False},
1256 {'name': 'FramebufferBlit', 'dev': False},
1257 {'name': 'FramebufferMultisample', 'dev': False},
1258 {'name': 'ChromiumEnableFeature', 'dev': False},
1259 {'name': 'ChromiumMapSub', 'dev': False},
1260 {'name': 'Query', 'dev': False},
1261 {'name': 'VertexArrayObject', 'dev': False},
1262 {'name': 'DrawBuffers', 'dev': True},
1265 # A function info object specifies the type and other special data for the
1266 # command that will be generated. A base function info object is generated by
1267 # parsing the "cmd_buffer_functions.txt", one for each function in the
1268 # file. These function info objects can be augmented and their values can be
1269 # overridden by adding an object to the table below.
1271 # Must match function names specified in "cmd_buffer_functions.txt".
1273 # cmd_comment: A comment added to the cmd format.
1274 # type: defines which handler will be used to generate code.
1275 # decoder_func: defines which function to call in the decoder to execute the
1276 # corresponding GL command. If not specified the GL command will
1277 # be called directly.
1278 # gl_test_func: GL function that is expected to be called when testing.
1279 # cmd_args: The arguments to use for the command. This overrides generating
1280 # them based on the GL function arguments.
1281 # gen_cmd: Whether or not this function geneates a command. Default = True.
1282 # data_transfer_methods: Array of methods that are used for transfering the
1283 # pointer data. Possible values: 'immediate', 'shm', 'bucket'.
1284 # The default is 'immediate' if the command has one pointer
1285 # argument, otherwise 'shm'. One command is generated for each
1286 # transfer method. Affects only commands which are not of type
1287 # 'HandWritten', 'GETn' or 'GLcharN'.
1288 # Note: the command arguments that affect this are the final args,
1289 # taking cmd_args override into consideration.
1290 # impl_func: Whether or not to generate the GLES2Implementation part of this
1292 # impl_decl: Whether or not to generate the GLES2Implementation declaration
1294 # needs_size: If true a data_size field is added to the command.
1295 # count: The number of units per element. For PUTn or PUT types.
1296 # unit_test: If False no service side unit test will be generated.
1297 # client_test: If False no client side unit test will be generated.
1298 # expectation: If False the unit test will have no expected calls.
1299 # gen_func: Name of function that generates GL resource for corresponding
1301 # states: array of states that get set by this function corresponding to
1302 # the given arguments
1303 # state_flag: name of flag that is set to true when function is called.
1304 # no_gl: no GL function is called.
1305 # valid_args: A dictionary of argument indices to args to use in unit tests
1306 # when they can not be automatically determined.
1307 # pepper_interface: The pepper interface that is used for this extension
1308 # pepper_name: The name of the function as exposed to pepper.
1309 # pepper_args: A string representing the argument list (what would appear in
1310 # C/C++ between the parentheses for the function declaration)
1311 # that the Pepper API expects for this function. Use this only if
1312 # the stable Pepper API differs from the GLES2 argument list.
1313 # invalid_test: False if no invalid test needed.
1314 # shadowed: True = the value is shadowed so no glGetXXX call will be made.
1315 # first_element_only: For PUT types, True if only the first element of an
1316 # array is used and we end up calling the single value
1317 # corresponding function. eg. TexParameteriv -> TexParameteri
1318 # extension: Function is an extension to GL and should not be exposed to
1319 # pepper unless pepper_interface is defined.
1320 # extension_flag: Function is an extension and should be enabled only when
1321 # the corresponding feature info flag is enabled. Implies
1322 # 'extension': True.
1323 # not_shared: For GENn types, True if objects can't be shared between contexts
1327 'decoder_func': 'DoActiveTexture',
1330 'client_test': False,
1332 'AttachShader': {'decoder_func': 'DoAttachShader'},
1333 'BindAttribLocation': {
1335 'data_transfer_methods': ['bucket'],
1340 'decoder_func': 'DoBindBuffer',
1341 'gen_func': 'GenBuffersARB',
1343 'BindFramebuffer': {
1345 'decoder_func': 'DoBindFramebuffer',
1346 'gl_test_func': 'glBindFramebufferEXT',
1347 'gen_func': 'GenFramebuffersEXT',
1350 'BindRenderbuffer': {
1352 'decoder_func': 'DoBindRenderbuffer',
1353 'gl_test_func': 'glBindRenderbufferEXT',
1354 'gen_func': 'GenRenderbuffersEXT',
1358 'decoder_func': 'DoBindTexture',
1359 'gen_func': 'GenTextures',
1360 # TODO(gman): remove this once client side caching works.
1361 'client_test': False,
1364 'BlitFramebufferCHROMIUM': {
1365 'decoder_func': 'DoBlitFramebufferCHROMIUM',
1367 'extension_flag': 'chromium_framebuffer_multisample',
1368 'pepper_interface': 'FramebufferBlit',
1369 'pepper_name': 'BlitFramebufferEXT',
1370 'defer_reads': True,
1371 'defer_draws': True,
1376 'data_transfer_methods': ['shm'],
1377 'client_test': False,
1381 'client_test': False,
1382 'decoder_func': 'DoBufferSubData',
1383 'data_transfer_methods': ['shm'],
1385 'CheckFramebufferStatus': {
1387 'decoder_func': 'DoCheckFramebufferStatus',
1388 'gl_test_func': 'glCheckFramebufferStatusEXT',
1389 'error_value': 'GL_FRAMEBUFFER_UNSUPPORTED',
1390 'result': ['GLenum'],
1393 'decoder_func': 'DoClear',
1394 'defer_draws': True,
1399 'state': 'ClearColor',
1403 'state': 'ClearDepthf',
1404 'decoder_func': 'glClearDepth',
1405 'gl_test_func': 'glClearDepth',
1412 'state': 'ColorMask',
1414 'expectation': False,
1416 'ConsumeTextureCHROMIUM': {
1417 'decoder_func': 'DoConsumeTextureCHROMIUM',
1420 'count': 64, # GL_MAILBOX_SIZE_CHROMIUM
1422 'client_test': False,
1423 'extension': "CHROMIUM_texture_mailbox",
1427 'CreateAndConsumeTextureCHROMIUM': {
1428 'decoder_func': 'DoCreateAndConsumeTextureCHROMIUM',
1430 'type': 'HandWritten',
1431 'data_transfer_methods': ['immediate'],
1433 'client_test': False,
1434 'extension': "CHROMIUM_texture_mailbox",
1439 'state': 'ClearStencil',
1441 'EnableFeatureCHROMIUM': {
1443 'data_transfer_methods': ['shm'],
1444 'decoder_func': 'DoEnableFeatureCHROMIUM',
1445 'expectation': False,
1446 'cmd_args': 'GLuint bucket_id, GLint* result',
1447 'result': ['GLint'],
1450 'pepper_interface': 'ChromiumEnableFeature',
1452 'CompileShader': {'decoder_func': 'DoCompileShader', 'unit_test': False},
1453 'CompressedTexImage2D': {
1455 'data_transfer_methods': ['bucket', 'shm'],
1457 'CompressedTexSubImage2D': {
1459 'data_transfer_methods': ['bucket', 'shm'],
1460 'decoder_func': 'DoCompressedTexSubImage2D',
1463 'decoder_func': 'DoCopyTexImage2D',
1465 'defer_reads': True,
1467 'CopyTexSubImage2D': {
1468 'decoder_func': 'DoCopyTexSubImage2D',
1469 'defer_reads': True,
1471 'CreateImageCHROMIUM': {
1474 'GLsizei width, GLsizei height, GLenum internalformat, GLenum usage',
1475 'result': ['GLuint'],
1476 'client_test': False,
1478 'expectation': False,
1482 'DestroyImageCHROMIUM': {
1484 'client_test': False,
1489 'GetImageParameterivCHROMIUM': {
1491 'client_test': False,
1493 'expectation': False,
1499 'client_test': False,
1503 'client_test': False,
1507 'state': 'BlendColor',
1510 'type': 'StateSetRGBAlpha',
1511 'state': 'BlendEquation',
1513 '0': 'GL_FUNC_SUBTRACT'
1516 'BlendEquationSeparate': {
1518 'state': 'BlendEquation',
1520 '0': 'GL_FUNC_SUBTRACT'
1524 'type': 'StateSetRGBAlpha',
1525 'state': 'BlendFunc',
1527 'BlendFuncSeparate': {
1529 'state': 'BlendFunc',
1531 'SampleCoverage': {'decoder_func': 'DoSampleCoverage'},
1533 'type': 'StateSetFrontBack',
1534 'state': 'StencilFunc',
1536 'StencilFuncSeparate': {
1537 'type': 'StateSetFrontBackSeparate',
1538 'state': 'StencilFunc',
1541 'type': 'StateSetFrontBack',
1542 'state': 'StencilOp',
1547 'StencilOpSeparate': {
1548 'type': 'StateSetFrontBackSeparate',
1549 'state': 'StencilOp',
1555 'type': 'StateSetNamedParameter',
1558 'CullFace': {'type': 'StateSet', 'state': 'CullFace'},
1559 'FrontFace': {'type': 'StateSet', 'state': 'FrontFace'},
1560 'DepthFunc': {'type': 'StateSet', 'state': 'DepthFunc'},
1563 'state': 'LineWidth',
1570 'state': 'PolygonOffset',
1574 'gl_test_func': 'glDeleteBuffersARB',
1575 'resource_type': 'Buffer',
1576 'resource_types': 'Buffers',
1578 'DeleteFramebuffers': {
1580 'gl_test_func': 'glDeleteFramebuffersEXT',
1581 'resource_type': 'Framebuffer',
1582 'resource_types': 'Framebuffers',
1584 'DeleteProgram': {'type': 'Delete', 'decoder_func': 'DoDeleteProgram'},
1585 'DeleteRenderbuffers': {
1587 'gl_test_func': 'glDeleteRenderbuffersEXT',
1588 'resource_type': 'Renderbuffer',
1589 'resource_types': 'Renderbuffers',
1591 'DeleteShader': {'type': 'Delete', 'decoder_func': 'DoDeleteShader'},
1592 'DeleteSharedIdsCHROMIUM': {
1594 'decoder_func': 'DoDeleteSharedIdsCHROMIUM',
1596 'expectation': False,
1597 'data_transfer_methods': ['shm'],
1603 'resource_type': 'Texture',
1604 'resource_types': 'Textures',
1607 'decoder_func': 'DoDepthRangef',
1608 'gl_test_func': 'glDepthRange',
1612 'state': 'DepthMask',
1614 'expectation': False,
1616 'DetachShader': {'decoder_func': 'DoDetachShader'},
1618 'decoder_func': 'DoDisable',
1620 'client_test': False,
1622 'DisableVertexAttribArray': {
1623 'decoder_func': 'DoDisableVertexAttribArray',
1628 'cmd_args': 'GLenumDrawMode mode, GLint first, GLsizei count',
1629 'defer_draws': True,
1634 'cmd_args': 'GLenumDrawMode mode, GLsizei count, '
1635 'GLenumIndexType type, GLuint index_offset',
1636 'client_test': False,
1637 'defer_draws': True,
1641 'decoder_func': 'DoEnable',
1643 'client_test': False,
1645 'EnableVertexAttribArray': {
1646 'decoder_func': 'DoEnableVertexAttribArray',
1651 'client_test': False,
1652 'decoder_func': 'DoFinish',
1653 'defer_reads': True,
1657 'decoder_func': 'DoFlush',
1659 'FramebufferRenderbuffer': {
1660 'decoder_func': 'DoFramebufferRenderbuffer',
1661 'gl_test_func': 'glFramebufferRenderbufferEXT',
1663 'FramebufferTexture2D': {
1664 'decoder_func': 'DoFramebufferTexture2D',
1665 'gl_test_func': 'glFramebufferTexture2DEXT',
1668 'FramebufferTexture2DMultisampleEXT': {
1669 'decoder_func': 'DoFramebufferTexture2DMultisample',
1670 'gl_test_func': 'glFramebufferTexture2DMultisampleEXT',
1671 'expectation': False,
1673 'extension_flag': 'multisampled_render_to_texture',
1677 'decoder_func': 'DoGenerateMipmap',
1678 'gl_test_func': 'glGenerateMipmapEXT',
1682 'gl_test_func': 'glGenBuffersARB',
1683 'resource_type': 'Buffer',
1684 'resource_types': 'Buffers',
1686 'GenMailboxCHROMIUM': {
1687 'type': 'HandWritten',
1689 'extension': "CHROMIUM_texture_mailbox",
1692 'GenFramebuffers': {
1694 'gl_test_func': 'glGenFramebuffersEXT',
1695 'resource_type': 'Framebuffer',
1696 'resource_types': 'Framebuffers',
1698 'GenRenderbuffers': {
1699 'type': 'GENn', 'gl_test_func': 'glGenRenderbuffersEXT',
1700 'resource_type': 'Renderbuffer',
1701 'resource_types': 'Renderbuffers',
1705 'gl_test_func': 'glGenTextures',
1706 'resource_type': 'Texture',
1707 'resource_types': 'Textures',
1709 'GenSharedIdsCHROMIUM': {
1711 'decoder_func': 'DoGenSharedIdsCHROMIUM',
1713 'expectation': False,
1714 'data_transfer_methods': ['shm'],
1718 'GetActiveAttrib': {
1720 'data_transfer_methods': ['shm'],
1722 'GLidProgram program, GLuint index, uint32_t name_bucket_id, '
1730 'GetActiveUniform': {
1732 'data_transfer_methods': ['shm'],
1734 'GLidProgram program, GLuint index, uint32_t name_bucket_id, '
1742 'GetAttachedShaders': {
1744 'data_transfer_methods': ['shm'],
1745 'cmd_args': 'GLidProgram program, void* result, uint32_t result_size',
1746 'result': ['SizedResult<GLuint>'],
1748 'GetAttribLocation': {
1750 'data_transfer_methods': ['shm'],
1752 'GLidProgram program, uint32_t name_bucket_id, GLint* location',
1753 'result': ['GLint'],
1754 'error_return': -1, # http://www.opengl.org/sdk/docs/man/xhtml/glGetAttribLocation.xml
1758 'result': ['SizedResult<GLboolean>'],
1759 'decoder_func': 'DoGetBooleanv',
1760 'gl_test_func': 'glGetBooleanv',
1762 'GetBufferParameteriv': {
1764 'result': ['SizedResult<GLint>'],
1765 'decoder_func': 'DoGetBufferParameteriv',
1766 'expectation': False,
1771 'decoder_func': 'GetErrorState()->GetGLError',
1773 'result': ['GLenum'],
1774 'client_test': False,
1778 'result': ['SizedResult<GLfloat>'],
1779 'decoder_func': 'DoGetFloatv',
1780 'gl_test_func': 'glGetFloatv',
1782 'GetFramebufferAttachmentParameteriv': {
1784 'decoder_func': 'DoGetFramebufferAttachmentParameteriv',
1785 'gl_test_func': 'glGetFramebufferAttachmentParameterivEXT',
1786 'result': ['SizedResult<GLint>'],
1790 'result': ['SizedResult<GLint>'],
1791 'decoder_func': 'DoGetIntegerv',
1792 'client_test': False,
1794 'GetMaxValueInBufferCHROMIUM': {
1796 'decoder_func': 'DoGetMaxValueInBufferCHROMIUM',
1797 'result': ['GLuint'],
1799 'client_test': False,
1804 'GetMultipleIntegervCHROMIUM': {
1806 'data_transfer_methods': ['shm'],
1807 'expectation': False,
1810 'client_test': False,
1814 'decoder_func': 'DoGetProgramiv',
1815 'result': ['SizedResult<GLint>'],
1816 'expectation': False,
1818 'GetProgramInfoCHROMIUM': {
1820 'expectation': False,
1824 'client_test': False,
1825 'cmd_args': 'GLidProgram program, uint32_t bucket_id',
1827 'uint32_t link_status',
1828 'uint32_t num_attribs',
1829 'uint32_t num_uniforms',
1832 'GetProgramInfoLog': {
1834 'expectation': False,
1836 'GetRenderbufferParameteriv': {
1838 'decoder_func': 'DoGetRenderbufferParameteriv',
1839 'gl_test_func': 'glGetRenderbufferParameterivEXT',
1840 'result': ['SizedResult<GLint>'],
1844 'decoder_func': 'DoGetShaderiv',
1845 'result': ['SizedResult<GLint>'],
1847 'GetShaderInfoLog': {
1849 'get_len_func': 'glGetShaderiv',
1850 'get_len_enum': 'GL_INFO_LOG_LENGTH',
1853 'GetShaderPrecisionFormat': {
1855 'data_transfer_methods': ['shm'],
1857 'GLenumShaderType shadertype, GLenumShaderPrecision precisiontype, '
1861 'int32_t min_range',
1862 'int32_t max_range',
1863 'int32_t precision',
1866 'GetShaderSource': {
1868 'get_len_func': 'DoGetShaderiv',
1869 'get_len_enum': 'GL_SHADER_SOURCE_LENGTH',
1871 'client_test': False,
1875 'client_test': False,
1876 'cmd_args': 'GLenumStringType name, uint32_t bucket_id',
1878 'GetTexParameterfv': {
1880 'decoder_func': 'DoGetTexParameterfv',
1881 'result': ['SizedResult<GLfloat>']
1883 'GetTexParameteriv': {
1885 'decoder_func': 'DoGetTexParameteriv',
1886 'result': ['SizedResult<GLint>']
1888 'GetTranslatedShaderSourceANGLE': {
1890 'get_len_func': 'DoGetShaderiv',
1891 'get_len_enum': 'GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE',
1897 'data_transfer_methods': ['shm'],
1898 'result': ['SizedResult<GLfloat>'],
1902 'data_transfer_methods': ['shm'],
1903 'result': ['SizedResult<GLint>'],
1905 'GetUniformLocation': {
1907 'data_transfer_methods': ['shm'],
1909 'GLidProgram program, uint32_t name_bucket_id, GLint* location',
1910 'result': ['GLint'],
1911 'error_return': -1, # http://www.opengl.org/sdk/docs/man/xhtml/glGetUniformLocation.xml
1913 'GetVertexAttribfv': {
1915 'result': ['SizedResult<GLfloat>'],
1917 'decoder_func': 'DoGetVertexAttribfv',
1918 'expectation': False,
1919 'client_test': False,
1921 'GetVertexAttribiv': {
1923 'result': ['SizedResult<GLint>'],
1925 'decoder_func': 'DoGetVertexAttribiv',
1926 'expectation': False,
1927 'client_test': False,
1929 'GetVertexAttribPointerv': {
1931 'data_transfer_methods': ['shm'],
1932 'result': ['SizedResult<GLuint>'],
1933 'client_test': False,
1937 'decoder_func': 'DoIsBuffer',
1938 'expectation': False,
1942 'decoder_func': 'DoIsEnabled',
1944 'expectation': False,
1948 'decoder_func': 'DoIsFramebuffer',
1949 'expectation': False,
1953 'decoder_func': 'DoIsProgram',
1954 'expectation': False,
1958 'decoder_func': 'DoIsRenderbuffer',
1959 'expectation': False,
1963 'decoder_func': 'DoIsShader',
1964 'expectation': False,
1968 'decoder_func': 'DoIsTexture',
1969 'expectation': False,
1972 'decoder_func': 'DoLinkProgram',
1975 'MapBufferCHROMIUM': {
1979 'client_test': False,
1981 'MapBufferSubDataCHROMIUM': {
1985 'client_test': False,
1986 'pepper_interface': 'ChromiumMapSub',
1988 'MapImageCHROMIUM': {
1992 'client_test': False,
1994 'MapTexSubImage2DCHROMIUM': {
1998 'client_test': False,
1999 'pepper_interface': 'ChromiumMapSub',
2001 'PixelStorei': {'type': 'Manual'},
2002 'PostSubBufferCHROMIUM': {
2006 'client_test': False,
2010 'ProduceTextureCHROMIUM': {
2011 'decoder_func': 'DoProduceTextureCHROMIUM',
2014 'count': 64, # GL_MAILBOX_SIZE_CHROMIUM
2016 'client_test': False,
2017 'extension': "CHROMIUM_texture_mailbox",
2021 'ProduceTextureDirectCHROMIUM': {
2022 'decoder_func': 'DoProduceTextureDirectCHROMIUM',
2025 'count': 64, # GL_MAILBOX_SIZE_CHROMIUM
2027 'client_test': False,
2028 'extension': "CHROMIUM_texture_mailbox",
2032 'RenderbufferStorage': {
2033 'decoder_func': 'DoRenderbufferStorage',
2034 'gl_test_func': 'glRenderbufferStorageEXT',
2035 'expectation': False,
2037 'RenderbufferStorageMultisampleCHROMIUM': {
2039 '// GL_CHROMIUM_framebuffer_multisample\n',
2040 'decoder_func': 'DoRenderbufferStorageMultisampleCHROMIUM',
2041 'gl_test_func': 'glRenderbufferStorageMultisampleCHROMIUM',
2042 'expectation': False,
2044 'extension_flag': 'chromium_framebuffer_multisample',
2045 'pepper_interface': 'FramebufferMultisample',
2046 'pepper_name': 'RenderbufferStorageMultisampleEXT',
2048 'RenderbufferStorageMultisampleEXT': {
2050 '// GL_EXT_multisampled_render_to_texture\n',
2051 'decoder_func': 'DoRenderbufferStorageMultisampleEXT',
2052 'gl_test_func': 'glRenderbufferStorageMultisampleEXT',
2053 'expectation': False,
2055 'extension_flag': 'multisampled_render_to_texture',
2059 '// ReadPixels has the result separated from the pixel buffer so that\n'
2060 '// it is easier to specify the result going to some specific place\n'
2061 '// that exactly fits the rectangle of pixels.\n',
2063 'data_transfer_methods': ['shm'],
2065 'client_test': False,
2067 'GLint x, GLint y, GLsizei width, GLsizei height, '
2068 'GLenumReadPixelFormat format, GLenumReadPixelType type, '
2069 'uint32_t pixels_shm_id, uint32_t pixels_shm_offset, '
2070 'uint32_t result_shm_id, uint32_t result_shm_offset, '
2072 'result': ['uint32_t'],
2073 'defer_reads': True,
2075 'RegisterSharedIdsCHROMIUM': {
2077 'decoder_func': 'DoRegisterSharedIdsCHROMIUM',
2079 'expectation': False,
2080 'data_transfer_methods': ['shm'],
2084 'ReleaseShaderCompiler': {
2085 'decoder_func': 'DoReleaseShaderCompiler',
2090 'client_test': False,
2094 'data_transfer_methods': ['bucket'],
2096 'client_test': False,
2098 'GLuint shader, const char* data',
2100 'GLuint shader, GLsizei count, const char** str, const GLint* length',
2103 'type': 'StateSetFrontBack',
2104 'state': 'StencilMask',
2106 'expectation': False,
2108 'StencilMaskSeparate': {
2109 'type': 'StateSetFrontBackSeparate',
2110 'state': 'StencilMask',
2112 'expectation': False,
2116 'decoder_func': 'DoSwapBuffers',
2118 'client_test': False,
2124 'data_transfer_methods': ['shm'],
2125 'client_test': False,
2128 'decoder_func': 'DoTexParameterf',
2134 'decoder_func': 'DoTexParameteri',
2141 'data_value': 'GL_NEAREST',
2143 'decoder_func': 'DoTexParameterfv',
2144 'gl_test_func': 'glTexParameterf',
2145 'first_element_only': True,
2149 'data_value': 'GL_NEAREST',
2151 'decoder_func': 'DoTexParameteriv',
2152 'gl_test_func': 'glTexParameteri',
2153 'first_element_only': True,
2157 'data_transfer_methods': ['shm'],
2158 'client_test': False,
2159 'cmd_args': 'GLenumTextureTarget target, GLint level, '
2160 'GLint xoffset, GLint yoffset, '
2161 'GLsizei width, GLsizei height, '
2162 'GLenumTextureFormat format, GLenumPixelType type, '
2163 'const void* pixels, GLboolean internal'
2165 'Uniform1f': {'type': 'PUTXn', 'count': 1},
2169 'decoder_func': 'DoUniform1fv',
2171 'Uniform1i': {'decoder_func': 'DoUniform1i', 'unit_test': False},
2175 'decoder_func': 'DoUniform1iv',
2178 'Uniform2i': {'type': 'PUTXn', 'count': 2},
2179 'Uniform2f': {'type': 'PUTXn', 'count': 2},
2183 'decoder_func': 'DoUniform2fv',
2188 'decoder_func': 'DoUniform2iv',
2190 'Uniform3i': {'type': 'PUTXn', 'count': 3},
2191 'Uniform3f': {'type': 'PUTXn', 'count': 3},
2195 'decoder_func': 'DoUniform3fv',
2200 'decoder_func': 'DoUniform3iv',
2202 'Uniform4i': {'type': 'PUTXn', 'count': 4},
2203 'Uniform4f': {'type': 'PUTXn', 'count': 4},
2207 'decoder_func': 'DoUniform4fv',
2212 'decoder_func': 'DoUniform4iv',
2214 'UniformMatrix2fv': {
2217 'decoder_func': 'DoUniformMatrix2fv',
2219 'UniformMatrix3fv': {
2222 'decoder_func': 'DoUniformMatrix3fv',
2224 'UniformMatrix4fv': {
2227 'decoder_func': 'DoUniformMatrix4fv',
2229 'UnmapBufferCHROMIUM': {
2233 'client_test': False,
2235 'UnmapBufferSubDataCHROMIUM': {
2239 'client_test': False,
2240 'pepper_interface': 'ChromiumMapSub',
2242 'UnmapImageCHROMIUM': {
2246 'client_test': False,
2248 'UnmapTexSubImage2DCHROMIUM': {
2252 'client_test': False,
2253 'pepper_interface': 'ChromiumMapSub',
2257 'decoder_func': 'DoUseProgram',
2259 'ValidateProgram': {'decoder_func': 'DoValidateProgram'},
2260 'VertexAttrib1f': {'decoder_func': 'DoVertexAttrib1f'},
2261 'VertexAttrib1fv': {
2264 'decoder_func': 'DoVertexAttrib1fv',
2266 'VertexAttrib2f': {'decoder_func': 'DoVertexAttrib2f'},
2267 'VertexAttrib2fv': {
2270 'decoder_func': 'DoVertexAttrib2fv',
2272 'VertexAttrib3f': {'decoder_func': 'DoVertexAttrib3f'},
2273 'VertexAttrib3fv': {
2276 'decoder_func': 'DoVertexAttrib3fv',
2278 'VertexAttrib4f': {'decoder_func': 'DoVertexAttrib4f'},
2279 'VertexAttrib4fv': {
2282 'decoder_func': 'DoVertexAttrib4fv',
2284 'VertexAttribPointer': {
2286 'cmd_args': 'GLuint indx, GLintVertexAttribSize size, '
2287 'GLenumVertexAttribType type, GLboolean normalized, '
2288 'GLsizei stride, GLuint offset',
2289 'client_test': False,
2296 'decoder_func': 'DoViewport',
2305 'GetRequestableExtensionsCHROMIUM': {
2308 'cmd_args': 'uint32_t bucket_id',
2312 'RequestExtensionCHROMIUM': {
2315 'client_test': False,
2316 'cmd_args': 'uint32_t bucket_id',
2320 'RateLimitOffscreenContextCHROMIUM': {
2324 'client_test': False,
2326 'CreateStreamTextureCHROMIUM': {
2327 'type': 'HandWritten',
2333 'TexImageIOSurface2DCHROMIUM': {
2334 'decoder_func': 'DoTexImageIOSurface2DCHROMIUM',
2339 'CopyTextureCHROMIUM': {
2340 'decoder_func': 'DoCopyTextureCHROMIUM',
2345 'TexStorage2DEXT': {
2348 'decoder_func': 'DoTexStorage2DEXT',
2350 'DrawArraysInstancedANGLE': {
2352 'cmd_args': 'GLenumDrawMode mode, GLint first, GLsizei count, '
2353 'GLsizei primcount',
2356 'pepper_interface': 'InstancedArrays',
2357 'defer_draws': True,
2361 'decoder_func': 'DoDrawBuffersEXT',
2363 'client_test': False,
2365 # could use 'extension_flag': 'ext_draw_buffers' but currently expected to
2368 'pepper_interface': 'DrawBuffers',
2370 'DrawElementsInstancedANGLE': {
2372 'cmd_args': 'GLenumDrawMode mode, GLsizei count, '
2373 'GLenumIndexType type, GLuint index_offset, GLsizei primcount',
2376 'client_test': False,
2377 'pepper_interface': 'InstancedArrays',
2378 'defer_draws': True,
2380 'VertexAttribDivisorANGLE': {
2382 'cmd_args': 'GLuint index, GLuint divisor',
2385 'pepper_interface': 'InstancedArrays',
2389 'gl_test_func': 'glGenQueriesARB',
2390 'resource_type': 'Query',
2391 'resource_types': 'Queries',
2393 'pepper_interface': 'Query',
2394 'not_shared': 'True',
2396 'DeleteQueriesEXT': {
2398 'gl_test_func': 'glDeleteQueriesARB',
2399 'resource_type': 'Query',
2400 'resource_types': 'Queries',
2402 'pepper_interface': 'Query',
2406 'client_test': False,
2407 'pepper_interface': 'Query',
2411 'cmd_args': 'GLenumQueryTarget target, GLidQuery id, void* sync_data',
2412 'data_transfer_methods': ['shm'],
2413 'gl_test_func': 'glBeginQuery',
2414 'pepper_interface': 'Query',
2418 'cmd_args': 'GLenumQueryTarget target, GLuint submit_count',
2419 'gl_test_func': 'glEndnQuery',
2420 'client_test': False,
2421 'pepper_interface': 'Query',
2425 'client_test': False,
2426 'gl_test_func': 'glGetQueryiv',
2427 'pepper_interface': 'Query',
2429 'GetQueryObjectuivEXT': {
2431 'client_test': False,
2432 'gl_test_func': 'glGetQueryObjectuiv',
2433 'pepper_interface': 'Query',
2435 'BindUniformLocationCHROMIUM': {
2438 'data_transfer_methods': ['bucket'],
2440 'gl_test_func': 'DoBindUniformLocationCHROMIUM',
2442 'InsertEventMarkerEXT': {
2444 'decoder_func': 'DoInsertEventMarkerEXT',
2445 'expectation': False,
2448 'PushGroupMarkerEXT': {
2450 'decoder_func': 'DoPushGroupMarkerEXT',
2451 'expectation': False,
2454 'PopGroupMarkerEXT': {
2455 'decoder_func': 'DoPopGroupMarkerEXT',
2456 'expectation': False,
2461 'GenVertexArraysOES': {
2464 'gl_test_func': 'glGenVertexArraysOES',
2465 'resource_type': 'VertexArray',
2466 'resource_types': 'VertexArrays',
2468 'pepper_interface': 'VertexArrayObject',
2470 'BindVertexArrayOES': {
2473 'gl_test_func': 'glBindVertexArrayOES',
2474 'decoder_func': 'DoBindVertexArrayOES',
2475 'gen_func': 'GenVertexArraysOES',
2477 'client_test': False,
2478 'pepper_interface': 'VertexArrayObject',
2480 'DeleteVertexArraysOES': {
2483 'gl_test_func': 'glDeleteVertexArraysOES',
2484 'resource_type': 'VertexArray',
2485 'resource_types': 'VertexArrays',
2487 'pepper_interface': 'VertexArrayObject',
2489 'IsVertexArrayOES': {
2492 'gl_test_func': 'glIsVertexArrayOES',
2493 'decoder_func': 'DoIsVertexArrayOES',
2494 'expectation': False,
2496 'pepper_interface': 'VertexArrayObject',
2498 'BindTexImage2DCHROMIUM': {
2499 'decoder_func': 'DoBindTexImage2DCHROMIUM',
2504 'ReleaseTexImage2DCHROMIUM': {
2505 'decoder_func': 'DoReleaseTexImage2DCHROMIUM',
2510 'ShallowFinishCHROMIUM': {
2515 'client_test': False,
2517 'ShallowFlushCHROMIUM': {
2522 'client_test': False,
2524 'TraceBeginCHROMIUM': {
2527 'client_test': False,
2528 'cmd_args': 'GLuint bucket_id',
2532 'TraceEndCHROMIUM': {
2534 'client_test': False,
2535 'decoder_func': 'DoTraceEndCHROMIUM',
2540 'AsyncTexImage2DCHROMIUM': {
2542 'data_transfer_methods': ['shm'],
2543 'client_test': False,
2544 'cmd_args': 'GLenumTextureTarget target, GLint level, '
2545 'GLintTextureInternalFormat internalformat, '
2546 'GLsizei width, GLsizei height, '
2547 'GLintTextureBorder border, '
2548 'GLenumTextureFormat format, GLenumPixelType type, '
2549 'const void* pixels, '
2550 'uint32_t async_upload_token, '
2555 'AsyncTexSubImage2DCHROMIUM': {
2557 'data_transfer_methods': ['shm'],
2558 'client_test': False,
2559 'cmd_args': 'GLenumTextureTarget target, GLint level, '
2560 'GLint xoffset, GLint yoffset, '
2561 'GLsizei width, GLsizei height, '
2562 'GLenumTextureFormat format, GLenumPixelType type, '
2563 'const void* data, '
2564 'uint32_t async_upload_token, '
2569 'WaitAsyncTexImage2DCHROMIUM': {
2571 'client_test': False,
2575 'WaitAllAsyncTexImage2DCHROMIUM': {
2577 'client_test': False,
2581 'DiscardFramebufferEXT': {
2584 'cmd_args': 'GLenum target, GLsizei count, '
2585 'const GLenum* attachments',
2586 'decoder_func': 'DoDiscardFramebufferEXT',
2588 'client_test': False,
2589 'extension_flag': 'ext_discard_framebuffer',
2591 'LoseContextCHROMIUM': {
2592 'decoder_func': 'DoLoseContextCHROMIUM',
2597 'InsertSyncPointCHROMIUM': {
2598 'type': 'HandWritten',
2600 'extension': "CHROMIUM_sync_point",
2603 'WaitSyncPointCHROMIUM': {
2606 'extension': "CHROMIUM_sync_point",
2610 'DiscardBackbufferCHROMIUM': {
2616 'ScheduleOverlayPlaneCHROMIUM': {
2620 'client_test': False,
2624 'MatrixLoadfCHROMIUM': {
2627 'data_type': 'GLfloat',
2628 'decoder_func': 'DoMatrixLoadfCHROMIUM',
2629 'gl_test_func': 'glMatrixLoadfEXT',
2632 'extension_flag': 'chromium_path_rendering',
2634 'MatrixLoadIdentityCHROMIUM': {
2635 'decoder_func': 'DoMatrixLoadIdentityCHROMIUM',
2636 'gl_test_func': 'glMatrixLoadIdentityEXT',
2639 'extension_flag': 'chromium_path_rendering',
2644 def Grouper(n
, iterable
, fillvalue
=None):
2645 """Collect data into fixed-length chunks or blocks"""
2646 args
= [iter(iterable
)] * n
2647 return itertools
.izip_longest(fillvalue
=fillvalue
, *args
)
2650 def SplitWords(input_string
):
2651 """Transforms a input_string into a list of lower-case components.
2654 input_string: the input string.
2657 a list of lower-case words.
2659 if input_string
.find('_') > -1:
2660 # 'some_TEXT_' -> 'some text'
2661 return input_string
.replace('_', ' ').strip().lower().split()
2663 if re
.search('[A-Z]', input_string
) and re
.search('[a-z]', input_string
):
2665 # look for capitalization to cut input_strings
2666 # 'SomeText' -> 'Some Text'
2667 input_string
= re
.sub('([A-Z])', r
' \1', input_string
).strip()
2668 # 'Vector3' -> 'Vector 3'
2669 input_string
= re
.sub('([^0-9])([0-9])', r
'\1 \2', input_string
)
2670 return input_string
.lower().split()
2674 """Makes a lower-case identifier from words.
2677 words: a list of lower-case words.
2680 the lower-case identifier.
2682 return '_'.join(words
)
2685 def ToUnderscore(input_string
):
2686 """converts CamelCase to camel_case."""
2687 words
= SplitWords(input_string
)
2690 def CachedStateName(item
):
2691 if item
.get('cached', False):
2692 return 'cached_' + item
['name']
2695 def ToGLExtensionString(extension_flag
):
2696 """Returns GL-type extension string of a extension flag."""
2697 if extension_flag
== "oes_compressed_etc1_rgb8_texture":
2698 return "OES_compressed_ETC1_RGB8_texture" # Fixup inconsitency with rgb8,
2700 uppercase_words
= [ 'img', 'ext', 'arb', 'chromium', 'oes', 'amd', 'bgra8888',
2701 'egl', 'atc', 'etc1', 'angle']
2702 parts
= extension_flag
.split('_')
2704 [part
.upper() if part
in uppercase_words
else part
for part
in parts
])
2706 def ToCamelCase(input_string
):
2707 """converts ABC_underscore_case to ABCUnderscoreCase."""
2708 return ''.join(w
[0].upper() + w
[1:] for w
in input_string
.split('_'))
2710 def GetGLGetTypeConversion(result_type
, value_type
, value
):
2711 """Makes a gl compatible type conversion string for accessing state variables.
2713 Useful when accessing state variables through glGetXXX calls.
2714 glGet documetation (for example, the manual pages):
2715 [...] If glGetIntegerv is called, [...] most floating-point values are
2716 rounded to the nearest integer value. [...]
2719 result_type: the gl type to be obtained
2720 value_type: the GL type of the state variable
2721 value: the name of the state variable
2724 String that converts the state variable to desired GL type according to GL
2728 if result_type
== 'GLint':
2729 if value_type
== 'GLfloat':
2730 return 'static_cast<GLint>(round(%s))' % value
2731 return 'static_cast<%s>(%s)' % (result_type
, value
)
2733 class CWriter(object):
2734 """Writes to a file formatting it for Google's style guidelines."""
2736 def __init__(self
, filename
):
2737 self
.filename
= filename
2740 def Write(self
, string
):
2741 """Writes a string to a file spliting if it's > 80 characters."""
2742 lines
= string
.splitlines()
2743 num_lines
= len(lines
)
2744 for ii
in range(0, num_lines
):
2745 self
.content
.append(lines
[ii
])
2746 if ii
< (num_lines
- 1) or string
[-1] == '\n':
2747 self
.content
.append('\n')
2750 """Close the file."""
2751 content
= "".join(self
.content
)
2753 if os
.path
.exists(self
.filename
):
2754 old_file
= open(self
.filename
, "rb");
2755 old_content
= old_file
.read()
2757 if content
== old_content
:
2760 file = open(self
.filename
, "wb")
2765 class CHeaderWriter(CWriter
):
2766 """Writes a C Header file."""
2768 _non_alnum_re
= re
.compile(r
'[^a-zA-Z0-9]')
2770 def __init__(self
, filename
, file_comment
= None):
2771 CWriter
.__init
__(self
, filename
)
2773 base
= os
.path
.abspath(filename
)
2774 while os
.path
.basename(base
) != 'src':
2775 new_base
= os
.path
.dirname(base
)
2776 assert new_base
!= base
# Prevent infinite loop.
2779 hpath
= os
.path
.relpath(filename
, base
)
2780 self
.guard
= self
._non
_alnum
_re
.sub('_', hpath
).upper() + '_'
2782 self
.Write(_LICENSE
)
2783 self
.Write(_DO_NOT_EDIT_WARNING
)
2784 if not file_comment
== None:
2785 self
.Write(file_comment
)
2786 self
.Write("#ifndef %s\n" % self
.guard
)
2787 self
.Write("#define %s\n\n" % self
.guard
)
2790 self
.Write("#endif // %s\n\n" % self
.guard
)
2793 class TypeHandler(object):
2794 """This class emits code for a particular type of function."""
2796 _remove_expected_call_re
= re
.compile(r
' EXPECT_CALL.*?;\n', re
.S
)
2801 def InitFunction(self
, func
):
2802 """Add or adjust anything type specific for this function."""
2803 if func
.GetInfo('needs_size') and not func
.name
.endswith('Bucket'):
2804 func
.AddCmdArg(DataSizeArgument('data_size'))
2806 def NeedsDataTransferFunction(self
, func
):
2807 """Overriden from TypeHandler."""
2808 return func
.num_pointer_args
>= 1
2810 def WriteStruct(self
, func
, file):
2811 """Writes a structure that matches the arguments to a function."""
2812 comment
= func
.GetInfo('cmd_comment')
2813 if not comment
== None:
2815 file.Write("struct %s {\n" % func
.name
)
2816 file.Write(" typedef %s ValueType;\n" % func
.name
)
2817 file.Write(" static const CommandId kCmdId = k%s;\n" % func
.name
)
2818 func
.WriteCmdArgFlag(file)
2819 func
.WriteCmdFlag(file)
2821 result
= func
.GetInfo('result')
2822 if not result
== None:
2823 if len(result
) == 1:
2824 file.Write(" typedef %s Result;\n\n" % result
[0])
2826 file.Write(" struct Result {\n")
2828 file.Write(" %s;\n" % line
)
2829 file.Write(" };\n\n")
2831 func
.WriteCmdComputeSize(file)
2832 func
.WriteCmdSetHeader(file)
2833 func
.WriteCmdInit(file)
2834 func
.WriteCmdSet(file)
2836 file.Write(" gpu::CommandHeader header;\n")
2837 args
= func
.GetCmdArgs()
2839 file.Write(" %s %s;\n" % (arg
.cmd_type
, arg
.name
))
2841 consts
= func
.GetCmdConstants()
2842 for const
in consts
:
2843 file.Write(" static const %s %s = %s;\n" %
2844 (const
.cmd_type
, const
.name
, const
.GetConstantValue()))
2849 size
= len(args
) * _SIZE_OF_UINT32
+ _SIZE_OF_COMMAND_HEADER
2850 file.Write("COMPILE_ASSERT(sizeof(%s) == %d,\n" % (func
.name
, size
))
2851 file.Write(" Sizeof_%s_is_not_%d);\n" % (func
.name
, size
))
2852 file.Write("COMPILE_ASSERT(offsetof(%s, header) == 0,\n" % func
.name
)
2853 file.Write(" OffsetOf_%s_header_not_0);\n" % func
.name
)
2854 offset
= _SIZE_OF_COMMAND_HEADER
2856 file.Write("COMPILE_ASSERT(offsetof(%s, %s) == %d,\n" %
2857 (func
.name
, arg
.name
, offset
))
2858 file.Write(" OffsetOf_%s_%s_not_%d);\n" %
2859 (func
.name
, arg
.name
, offset
))
2860 offset
+= _SIZE_OF_UINT32
2861 if not result
== None and len(result
) > 1:
2864 parts
= line
.split()
2867 COMPILE_ASSERT(offsetof(%(cmd_name)s::Result, %(field_name)s) == %(offset)d,
2868 OffsetOf_%(cmd_name)s_Result_%(field_name)s_not_%(offset)d);
2870 file.Write((check
.strip() + "\n") % {
2871 'cmd_name': func
.name
,
2875 offset
+= _SIZE_OF_UINT32
2878 def WriteHandlerImplementation(self
, func
, file):
2879 """Writes the handler implementation for this command."""
2880 file.Write(" %s(%s);\n" %
2881 (func
.GetGLFunctionName(), func
.MakeOriginalArgString("")))
2883 def WriteCmdSizeTest(self
, func
, file):
2884 """Writes the size test for a command."""
2885 file.Write(" EXPECT_EQ(sizeof(cmd), cmd.header.size * 4u);\n")
2887 def WriteFormatTest(self
, func
, file):
2888 """Writes a format test for a command."""
2889 file.Write("TEST_F(GLES2FormatTest, %s) {\n" % func
.name
)
2890 file.Write(" cmds::%s& cmd = *GetBufferAs<cmds::%s>();\n" %
2891 (func
.name
, func
.name
))
2892 file.Write(" void* next_cmd = cmd.Set(\n")
2894 args
= func
.GetCmdArgs()
2895 for value
, arg
in enumerate(args
):
2896 file.Write(",\n static_cast<%s>(%d)" % (arg
.type, value
+ 11))
2898 file.Write(" EXPECT_EQ(static_cast<uint32_t>(cmds::%s::kCmdId),\n" %
2900 file.Write(" cmd.header.command);\n")
2901 func
.type_handler
.WriteCmdSizeTest(func
, file)
2902 for value
, arg
in enumerate(args
):
2903 file.Write(" EXPECT_EQ(static_cast<%s>(%d), cmd.%s);\n" %
2904 (arg
.type, value
+ 11, arg
.name
))
2905 file.Write(" CheckBytesWrittenMatchesExpectedSize(\n")
2906 file.Write(" next_cmd, sizeof(cmd));\n")
2910 def WriteImmediateFormatTest(self
, func
, file):
2911 """Writes a format test for an immediate version of a command."""
2914 def WriteBucketFormatTest(self
, func
, file):
2915 """Writes a format test for a bucket version of a command."""
2918 def WriteGetDataSizeCode(self
, func
, file):
2919 """Writes the code to set data_size used in validation"""
2922 def WriteImmediateCmdSizeTest(self
, func
, file):
2923 """Writes a size test for an immediate version of a command."""
2924 file.Write(" // TODO(gman): Compute correct size.\n")
2925 file.Write(" EXPECT_EQ(sizeof(cmd), cmd.header.size * 4u);\n")
2927 def WriteImmediateHandlerImplementation (self
, func
, file):
2928 """Writes the handler impl for the immediate version of a command."""
2929 file.Write(" %s(%s);\n" %
2930 (func
.GetGLFunctionName(), func
.MakeOriginalArgString("")))
2932 def WriteBucketHandlerImplementation (self
, func
, file):
2933 """Writes the handler impl for the bucket version of a command."""
2934 file.Write(" %s(%s);\n" %
2935 (func
.GetGLFunctionName(), func
.MakeOriginalArgString("")))
2937 def WriteServiceHandlerFunctionHeader(self
, func
, file):
2938 """Writes function header for service implementation handlers."""
2939 file.Write("""error::Error GLES2DecoderImpl::Handle%(name)s(
2940 uint32_t immediate_data_size, const void* cmd_data) {
2941 const gles2::cmds::%(name)s& c =
2942 *static_cast<const gles2::cmds::%(name)s*>(cmd_data);
2944 """ % {'name': func
.name
})
2946 def WriteServiceImplementation(self
, func
, file):
2947 """Writes the service implementation for a command."""
2948 self
.WriteServiceHandlerFunctionHeader(func
, file)
2949 self
.WriteHandlerExtensionCheck(func
, file)
2950 self
.WriteHandlerDeferReadWrite(func
, file);
2951 if len(func
.GetOriginalArgs()) > 0:
2952 last_arg
= func
.GetLastOriginalArg()
2953 all_but_last_arg
= func
.GetOriginalArgs()[:-1]
2954 for arg
in all_but_last_arg
:
2955 arg
.WriteGetCode(file)
2956 self
.WriteGetDataSizeCode(func
, file)
2957 last_arg
.WriteGetCode(file)
2958 func
.WriteHandlerValidation(file)
2959 func
.WriteHandlerImplementation(file)
2960 file.Write(" return error::kNoError;\n")
2964 def WriteImmediateServiceImplementation(self
, func
, file):
2965 """Writes the service implementation for an immediate version of command."""
2966 self
.WriteServiceHandlerFunctionHeader(func
, file)
2967 self
.WriteHandlerExtensionCheck(func
, file)
2968 self
.WriteHandlerDeferReadWrite(func
, file);
2969 last_arg
= func
.GetLastOriginalArg()
2970 all_but_last_arg
= func
.GetOriginalArgs()[:-1]
2971 for arg
in all_but_last_arg
:
2972 arg
.WriteGetCode(file)
2973 self
.WriteGetDataSizeCode(func
, file)
2974 last_arg
.WriteGetCode(file)
2975 func
.WriteHandlerValidation(file)
2976 func
.WriteHandlerImplementation(file)
2977 file.Write(" return error::kNoError;\n")
2981 def WriteBucketServiceImplementation(self
, func
, file):
2982 """Writes the service implementation for a bucket version of command."""
2983 self
.WriteServiceHandlerFunctionHeader(func
, file)
2984 self
.WriteHandlerExtensionCheck(func
, file)
2985 self
.WriteHandlerDeferReadWrite(func
, file);
2986 last_arg
= func
.GetLastOriginalArg()
2987 all_but_last_arg
= func
.GetOriginalArgs()[:-1]
2988 for arg
in all_but_last_arg
:
2989 arg
.WriteGetCode(file)
2990 self
.WriteGetDataSizeCode(func
, file)
2991 last_arg
.WriteGetCode(file)
2992 func
.WriteHandlerValidation(file)
2993 func
.WriteHandlerImplementation(file)
2994 file.Write(" return error::kNoError;\n")
2998 def WriteHandlerExtensionCheck(self
, func
, file):
2999 if func
.GetInfo('extension_flag'):
3000 file.Write(" if (!features().%s) {\n" % func
.GetInfo('extension_flag'))
3001 file.Write(" LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, \"gl%s\","
3002 " \"function not available\");\n" % func
.original_name
)
3003 file.Write(" return error::kNoError;")
3004 file.Write(" }\n\n")
3006 def WriteHandlerDeferReadWrite(self
, func
, file):
3007 """Writes the code to handle deferring reads or writes."""
3008 defer_draws
= func
.GetInfo('defer_draws')
3009 defer_reads
= func
.GetInfo('defer_reads')
3010 if defer_draws
or defer_reads
:
3011 file.Write(" error::Error error;\n")
3013 file.Write(" error = WillAccessBoundFramebufferForDraw();\n")
3014 file.Write(" if (error != error::kNoError)\n")
3015 file.Write(" return error;\n")
3017 file.Write(" error = WillAccessBoundFramebufferForRead();\n")
3018 file.Write(" if (error != error::kNoError)\n")
3019 file.Write(" return error;\n")
3021 def WriteValidUnitTest(self
, func
, file, test
, *extras
):
3022 """Writes a valid unit test for the service implementation."""
3023 if func
.GetInfo('expectation') == False:
3024 test
= self
._remove
_expected
_call
_re
.sub('', test
)
3027 arg
.GetValidArg(func
) \
3028 for arg
in func
.GetOriginalArgs() if not arg
.IsConstant()
3031 arg
.GetValidGLArg(func
) \
3032 for arg
in func
.GetOriginalArgs()
3034 gl_func_name
= func
.GetGLTestFunctionName()
3037 'gl_func_name': gl_func_name
,
3038 'args': ", ".join(arg_strings
),
3039 'gl_args': ", ".join(gl_arg_strings
),
3041 for extra
in extras
:
3044 while (old_test
!= test
):
3047 file.Write(test
% vars)
3049 def WriteInvalidUnitTest(self
, func
, file, test
, *extras
):
3050 """Writes an invalid unit test for the service implementation."""
3051 for invalid_arg_index
, invalid_arg
in enumerate(func
.GetOriginalArgs()):
3052 # Service implementation does not test constants, as they are not part of
3053 # the call in the service side.
3054 if invalid_arg
.IsConstant():
3057 num_invalid_values
= invalid_arg
.GetNumInvalidValues(func
)
3058 for value_index
in range(0, num_invalid_values
):
3060 parse_result
= "kNoError"
3062 for arg
in func
.GetOriginalArgs():
3063 if arg
.IsConstant():
3065 if invalid_arg
is arg
:
3066 (arg_string
, parse_result
, gl_error
) = arg
.GetInvalidArg(
3069 arg_string
= arg
.GetValidArg(func
)
3070 arg_strings
.append(arg_string
)
3072 for arg
in func
.GetOriginalArgs():
3073 gl_arg_strings
.append("_")
3074 gl_func_name
= func
.GetGLTestFunctionName()
3076 if not gl_error
== None:
3077 gl_error_test
= '\n EXPECT_EQ(%s, GetGLError());' % gl_error
3081 'arg_index': invalid_arg_index
,
3082 'value_index': value_index
,
3083 'gl_func_name': gl_func_name
,
3084 'args': ", ".join(arg_strings
),
3085 'all_but_last_args': ", ".join(arg_strings
[:-1]),
3086 'gl_args': ", ".join(gl_arg_strings
),
3087 'parse_result': parse_result
,
3088 'gl_error_test': gl_error_test
,
3090 for extra
in extras
:
3092 file.Write(test
% vars)
3094 def WriteServiceUnitTest(self
, func
, file, *extras
):
3095 """Writes the service unit test for a command."""
3097 if func
.name
== 'Enable':
3099 TEST_P(%(test_name)s, %(name)sValidArgs) {
3100 SetupExpectationsForEnableDisable(%(gl_args)s, true);
3101 SpecializedSetup<cmds::%(name)s, 0>(true);
3104 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
3105 EXPECT_EQ(GL_NO_ERROR, GetGLError());
3108 elif func
.name
== 'Disable':
3110 TEST_P(%(test_name)s, %(name)sValidArgs) {
3111 SetupExpectationsForEnableDisable(%(gl_args)s, false);
3112 SpecializedSetup<cmds::%(name)s, 0>(true);
3115 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
3116 EXPECT_EQ(GL_NO_ERROR, GetGLError());
3121 TEST_P(%(test_name)s, %(name)sValidArgs) {
3122 EXPECT_CALL(*gl_, %(gl_func_name)s(%(gl_args)s));
3123 SpecializedSetup<cmds::%(name)s, 0>(true);
3126 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
3127 EXPECT_EQ(GL_NO_ERROR, GetGLError());
3130 self
.WriteValidUnitTest(func
, file, valid_test
, *extras
)
3133 TEST_P(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) {
3134 EXPECT_CALL(*gl_, %(gl_func_name)s(%(gl_args)s)).Times(0);
3135 SpecializedSetup<cmds::%(name)s, 0>(false);
3138 EXPECT_EQ(error::%(parse_result)s, ExecuteCmd(cmd));%(gl_error_test)s
3141 self
.WriteInvalidUnitTest(func
, file, invalid_test
, *extras
)
3143 def WriteImmediateServiceUnitTest(self
, func
, file, *extras
):
3144 """Writes the service unit test for an immediate command."""
3145 file.Write("// TODO(gman): %s\n" % func
.name
)
3147 def WriteImmediateValidationCode(self
, func
, file):
3148 """Writes the validation code for an immediate version of a command."""
3151 def WriteBucketServiceUnitTest(self
, func
, file, *extras
):
3152 """Writes the service unit test for a bucket command."""
3153 file.Write("// TODO(gman): %s\n" % func
.name
)
3155 def WriteBucketValidationCode(self
, func
, file):
3156 """Writes the validation code for a bucket version of a command."""
3157 file.Write("// TODO(gman): %s\n" % func
.name
)
3159 def WriteGLES2ImplementationDeclaration(self
, func
, file):
3160 """Writes the GLES2 Implemention declaration."""
3161 impl_decl
= func
.GetInfo('impl_decl')
3162 if impl_decl
== None or impl_decl
== True:
3163 file.Write("virtual %s %s(%s) OVERRIDE;\n" %
3164 (func
.return_type
, func
.original_name
,
3165 func
.MakeTypedOriginalArgString("")))
3168 def WriteGLES2CLibImplementation(self
, func
, file):
3169 file.Write("%s GLES2%s(%s) {\n" %
3170 (func
.return_type
, func
.name
,
3171 func
.MakeTypedOriginalArgString("")))
3172 result_string
= "return "
3173 if func
.return_type
== "void":
3175 file.Write(" %sgles2::GetGLContext()->%s(%s);\n" %
3176 (result_string
, func
.original_name
,
3177 func
.MakeOriginalArgString("")))
3180 def WriteGLES2Header(self
, func
, file):
3181 """Writes a re-write macro for GLES"""
3182 file.Write("#define gl%s GLES2_GET_FUN(%s)\n" %(func
.name
, func
.name
))
3184 def WriteClientGLCallLog(self
, func
, file):
3185 """Writes a logging macro for the client side code."""
3187 if len(func
.GetOriginalArgs()):
3190 ' GPU_CLIENT_LOG("[" << GetLogPrefix() << "] gl%s("%s%s << ")");\n' %
3191 (func
.original_name
, comma
, func
.MakeLogArgString()))
3193 def WriteClientGLReturnLog(self
, func
, file):
3194 """Writes the return value logging code."""
3195 if func
.return_type
!= "void":
3196 file.Write(' GPU_CLIENT_LOG("return:" << result)\n')
3198 def WriteGLES2ImplementationHeader(self
, func
, file):
3199 """Writes the GLES2 Implemention."""
3200 self
.WriteGLES2ImplementationDeclaration(func
, file)
3202 def WriteGLES2TraceImplementationHeader(self
, func
, file):
3203 """Writes the GLES2 Trace Implemention header."""
3204 file.Write("virtual %s %s(%s) OVERRIDE;\n" %
3205 (func
.return_type
, func
.original_name
,
3206 func
.MakeTypedOriginalArgString("")))
3208 def WriteGLES2TraceImplementation(self
, func
, file):
3209 """Writes the GLES2 Trace Implemention."""
3210 file.Write("%s GLES2TraceImplementation::%s(%s) {\n" %
3211 (func
.return_type
, func
.original_name
,
3212 func
.MakeTypedOriginalArgString("")))
3213 result_string
= "return "
3214 if func
.return_type
== "void":
3216 file.Write(' TRACE_EVENT_BINARY_EFFICIENT0("gpu", "GLES2Trace::%s");\n' %
3218 file.Write(" %sgl_->%s(%s);\n" %
3219 (result_string
, func
.name
, func
.MakeOriginalArgString("")))
3223 def WriteGLES2Implementation(self
, func
, file):
3224 """Writes the GLES2 Implemention."""
3225 impl_func
= func
.GetInfo('impl_func')
3226 impl_decl
= func
.GetInfo('impl_decl')
3227 gen_cmd
= func
.GetInfo('gen_cmd')
3228 if (func
.can_auto_generate
and
3229 (impl_func
== None or impl_func
== True) and
3230 (impl_decl
== None or impl_decl
== True) and
3231 (gen_cmd
== None or gen_cmd
== True)):
3232 file.Write("%s GLES2Implementation::%s(%s) {\n" %
3233 (func
.return_type
, func
.original_name
,
3234 func
.MakeTypedOriginalArgString("")))
3235 file.Write(" GPU_CLIENT_SINGLE_THREAD_CHECK();\n")
3236 self
.WriteClientGLCallLog(func
, file)
3237 func
.WriteDestinationInitalizationValidation(file)
3238 for arg
in func
.GetOriginalArgs():
3239 arg
.WriteClientSideValidationCode(file, func
)
3240 file.Write(" helper_->%s(%s);\n" %
3241 (func
.name
, func
.MakeHelperArgString("")))
3242 file.Write(" CheckGLError();\n")
3243 self
.WriteClientGLReturnLog(func
, file)
3247 def WriteGLES2InterfaceHeader(self
, func
, file):
3248 """Writes the GLES2 Interface."""
3249 file.Write("virtual %s %s(%s) = 0;\n" %
3250 (func
.return_type
, func
.original_name
,
3251 func
.MakeTypedOriginalArgString("")))
3253 def WriteGLES2InterfaceStub(self
, func
, file):
3254 """Writes the GLES2 Interface stub declaration."""
3255 file.Write("virtual %s %s(%s) OVERRIDE;\n" %
3256 (func
.return_type
, func
.original_name
,
3257 func
.MakeTypedOriginalArgString("")))
3259 def WriteGLES2InterfaceStubImpl(self
, func
, file):
3260 """Writes the GLES2 Interface stub declaration."""
3261 args
= func
.GetOriginalArgs()
3262 arg_string
= ", ".join(
3263 ["%s /* %s */" % (arg
.type, arg
.name
) for arg
in args
])
3264 file.Write("%s GLES2InterfaceStub::%s(%s) {\n" %
3265 (func
.return_type
, func
.original_name
, arg_string
))
3266 if func
.return_type
!= "void":
3267 file.Write(" return 0;\n")
3270 def WriteGLES2ImplementationUnitTest(self
, func
, file):
3271 """Writes the GLES2 Implemention unit test."""
3272 client_test
= func
.GetInfo('client_test')
3273 if (func
.can_auto_generate
and
3274 (client_test
== None or client_test
== True)):
3276 TEST_F(GLES2ImplementationTest, %(name)s) {
3281 expected.cmd.Init(%(cmd_args)s);
3283 gl_->%(name)s(%(args)s);
3284 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected)));
3288 arg
.GetValidClientSideCmdArg(func
) for arg
in func
.GetCmdArgs()
3292 arg
.GetValidClientSideArg(func
) for arg
in func
.GetOriginalArgs()
3297 'args': ", ".join(gl_arg_strings
),
3298 'cmd_args': ", ".join(cmd_arg_strings
),
3301 # Test constants for invalid values, as they are not tested by the
3303 constants
= [arg
for arg
in func
.GetOriginalArgs() if arg
.IsConstant()]
3306 TEST_F(GLES2ImplementationTest, %(name)sInvalidConstantArg%(invalid_index)d) {
3307 gl_->%(name)s(%(args)s);
3308 EXPECT_TRUE(NoCommandsWritten());
3309 EXPECT_EQ(%(gl_error)s, CheckError());
3312 for invalid_arg
in constants
:
3314 invalid
= invalid_arg
.GetInvalidArg(func
)
3315 for arg
in func
.GetOriginalArgs():
3316 if arg
is invalid_arg
:
3317 gl_arg_strings
.append(invalid
[0])
3319 gl_arg_strings
.append(arg
.GetValidClientSideArg(func
))
3323 'invalid_index': func
.GetOriginalArgs().index(invalid_arg
),
3324 'args': ", ".join(gl_arg_strings
),
3325 'gl_error': invalid
[2],
3328 if client_test
!= False:
3329 file.Write("// TODO: Implement unit test for %s\n" % func
.name
)
3331 def WriteDestinationInitalizationValidation(self
, func
, file):
3332 """Writes the client side destintion initialization validation."""
3333 for arg
in func
.GetOriginalArgs():
3334 arg
.WriteDestinationInitalizationValidation(file, func
)
3336 def WriteTraceEvent(self
, func
, file):
3337 file.Write(' TRACE_EVENT0("gpu", "GLES2Implementation::%s");\n' %
3340 def WriteImmediateCmdComputeSize(self
, func
, file):
3341 """Writes the size computation code for the immediate version of a cmd."""
3342 file.Write(" static uint32_t ComputeSize(uint32_t size_in_bytes) {\n")
3343 file.Write(" return static_cast<uint32_t>(\n")
3344 file.Write(" sizeof(ValueType) + // NOLINT\n")
3345 file.Write(" RoundSizeToMultipleOfEntries(size_in_bytes));\n")
3349 def WriteImmediateCmdSetHeader(self
, func
, file):
3350 """Writes the SetHeader function for the immediate version of a cmd."""
3351 file.Write(" void SetHeader(uint32_t size_in_bytes) {\n")
3352 file.Write(" header.SetCmdByTotalSize<ValueType>(size_in_bytes);\n")
3356 def WriteImmediateCmdInit(self
, func
, file):
3357 """Writes the Init function for the immediate version of a command."""
3358 raise NotImplementedError(func
.name
)
3360 def WriteImmediateCmdSet(self
, func
, file):
3361 """Writes the Set function for the immediate version of a command."""
3362 raise NotImplementedError(func
.name
)
3364 def WriteCmdHelper(self
, func
, file):
3365 """Writes the cmd helper definition for a cmd."""
3366 code
= """ void %(name)s(%(typed_args)s) {
3367 gles2::cmds::%(name)s* c = GetCmdSpace<gles2::cmds::%(name)s>();
3376 "typed_args": func
.MakeTypedCmdArgString(""),
3377 "args": func
.MakeCmdArgString(""),
3380 def WriteImmediateCmdHelper(self
, func
, file):
3381 """Writes the cmd helper definition for the immediate version of a cmd."""
3382 code
= """ void %(name)s(%(typed_args)s) {
3383 const uint32_t s = 0; // TODO(gman): compute correct size
3384 gles2::cmds::%(name)s* c =
3385 GetImmediateCmdSpaceTotalSize<gles2::cmds::%(name)s>(s);
3394 "typed_args": func
.MakeTypedCmdArgString(""),
3395 "args": func
.MakeCmdArgString(""),
3399 class StateSetHandler(TypeHandler
):
3400 """Handler for commands that simply set state."""
3403 TypeHandler
.__init
__(self
)
3405 def WriteHandlerImplementation(self
, func
, file):
3406 """Overrriden from TypeHandler."""
3407 state_name
= func
.GetInfo('state')
3408 state
= _STATES
[state_name
]
3409 states
= state
['states']
3410 args
= func
.GetOriginalArgs()
3411 for ndx
,item
in enumerate(states
):
3413 if 'range_checks' in item
:
3414 for range_check
in item
['range_checks']:
3415 code
.append("%s %s" % (args
[ndx
].name
, range_check
['check']))
3416 if 'nan_check' in item
:
3417 # Drivers might generate an INVALID_VALUE error when a value is set
3418 # to NaN. This is allowed behavior under GLES 3.0 section 2.1.1 or
3419 # OpenGL 4.5 section 2.3.4.1 - providing NaN allows undefined results.
3420 # Make this behavior consistent within Chromium, and avoid leaking GL
3421 # errors by generating the error in the command buffer instead of
3422 # letting the GL driver generate it.
3423 code
.append("base::IsNaN(%s)" % args
[ndx
].name
)
3425 file.Write(" if (%s) {\n" % " ||\n ".join(code
))
3427 ' LOCAL_SET_GL_ERROR(GL_INVALID_VALUE,'
3428 ' "%s", "%s out of range");\n' %
3429 (func
.name
, args
[ndx
].name
))
3430 file.Write(" return error::kNoError;\n")
3433 for ndx
,item
in enumerate(states
):
3434 code
.append("state_.%s != %s" % (item
['name'], args
[ndx
].name
))
3435 file.Write(" if (%s) {\n" % " ||\n ".join(code
))
3436 for ndx
,item
in enumerate(states
):
3437 file.Write(" state_.%s = %s;\n" % (item
['name'], args
[ndx
].name
))
3438 if 'state_flag' in state
:
3439 file.Write(" %s = true;\n" % state
['state_flag'])
3440 if not func
.GetInfo("no_gl"):
3441 for ndx
,item
in enumerate(states
):
3442 if item
.get('cached', False):
3443 file.Write(" state_.%s = %s;\n" %
3444 (CachedStateName(item
), args
[ndx
].name
))
3445 file.Write(" %s(%s);\n" %
3446 (func
.GetGLFunctionName(), func
.MakeOriginalArgString("")))
3449 def WriteServiceUnitTest(self
, func
, file, *extras
):
3450 """Overrriden from TypeHandler."""
3451 TypeHandler
.WriteServiceUnitTest(self
, func
, file, *extras
)
3452 state_name
= func
.GetInfo('state')
3453 state
= _STATES
[state_name
]
3454 states
= state
['states']
3455 for ndx
,item
in enumerate(states
):
3456 if 'range_checks' in item
:
3457 for check_ndx
, range_check
in enumerate(item
['range_checks']):
3459 TEST_P(%(test_name)s, %(name)sInvalidValue%(ndx)d_%(check_ndx)d) {
3460 SpecializedSetup<cmds::%(name)s, 0>(false);
3463 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
3464 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
3469 arg
.GetValidArg(func
) \
3470 for arg
in func
.GetOriginalArgs() if not arg
.IsConstant()
3473 arg_strings
[ndx
] = range_check
['test_value']
3477 'check_ndx': check_ndx
,
3478 'args': ", ".join(arg_strings
),
3480 for extra
in extras
:
3482 file.Write(valid_test
% vars)
3483 if 'nan_check' in item
:
3485 TEST_P(%(test_name)s, %(name)sNaNValue%(ndx)d) {
3486 SpecializedSetup<cmds::%(name)s, 0>(false);
3489 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
3490 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
3495 arg
.GetValidArg(func
) \
3496 for arg
in func
.GetOriginalArgs() if not arg
.IsConstant()
3499 arg_strings
[ndx
] = 'nanf("")'
3503 'args': ", ".join(arg_strings
),
3505 for extra
in extras
:
3507 file.Write(valid_test
% vars)
3510 class StateSetRGBAlphaHandler(TypeHandler
):
3511 """Handler for commands that simply set state that have rgb/alpha."""
3514 TypeHandler
.__init
__(self
)
3516 def WriteHandlerImplementation(self
, func
, file):
3517 """Overrriden from TypeHandler."""
3518 state_name
= func
.GetInfo('state')
3519 state
= _STATES
[state_name
]
3520 states
= state
['states']
3521 args
= func
.GetOriginalArgs()
3522 num_args
= len(args
)
3524 for ndx
,item
in enumerate(states
):
3525 code
.append("state_.%s != %s" % (item
['name'], args
[ndx
% num_args
].name
))
3526 file.Write(" if (%s) {\n" % " ||\n ".join(code
))
3527 for ndx
, item
in enumerate(states
):
3528 file.Write(" state_.%s = %s;\n" %
3529 (item
['name'], args
[ndx
% num_args
].name
))
3530 if 'state_flag' in state
:
3531 file.Write(" %s = true;\n" % state
['state_flag'])
3532 if not func
.GetInfo("no_gl"):
3533 file.Write(" %s(%s);\n" %
3534 (func
.GetGLFunctionName(), func
.MakeOriginalArgString("")))
3538 class StateSetFrontBackSeparateHandler(TypeHandler
):
3539 """Handler for commands that simply set state that have front/back."""
3542 TypeHandler
.__init
__(self
)
3544 def WriteHandlerImplementation(self
, func
, file):
3545 """Overrriden from TypeHandler."""
3546 state_name
= func
.GetInfo('state')
3547 state
= _STATES
[state_name
]
3548 states
= state
['states']
3549 args
= func
.GetOriginalArgs()
3551 num_args
= len(args
)
3552 file.Write(" bool changed = false;\n")
3553 for group_ndx
, group
in enumerate(Grouper(num_args
- 1, states
)):
3554 file.Write(" if (%s == %s || %s == GL_FRONT_AND_BACK) {\n" %
3555 (face
, ('GL_FRONT', 'GL_BACK')[group_ndx
], face
))
3557 for ndx
, item
in enumerate(group
):
3558 code
.append("state_.%s != %s" % (item
['name'], args
[ndx
+ 1].name
))
3559 file.Write(" changed |= %s;\n" % " ||\n ".join(code
))
3561 file.Write(" if (changed) {\n")
3562 for group_ndx
, group
in enumerate(Grouper(num_args
- 1, states
)):
3563 file.Write(" if (%s == %s || %s == GL_FRONT_AND_BACK) {\n" %
3564 (face
, ('GL_FRONT', 'GL_BACK')[group_ndx
], face
))
3565 for ndx
, item
in enumerate(group
):
3566 file.Write(" state_.%s = %s;\n" %
3567 (item
['name'], args
[ndx
+ 1].name
))
3569 if 'state_flag' in state
:
3570 file.Write(" %s = true;\n" % state
['state_flag'])
3571 if not func
.GetInfo("no_gl"):
3572 file.Write(" %s(%s);\n" %
3573 (func
.GetGLFunctionName(), func
.MakeOriginalArgString("")))
3577 class StateSetFrontBackHandler(TypeHandler
):
3578 """Handler for commands that simply set state that set both front/back."""
3581 TypeHandler
.__init
__(self
)
3583 def WriteHandlerImplementation(self
, func
, file):
3584 """Overrriden from TypeHandler."""
3585 state_name
= func
.GetInfo('state')
3586 state
= _STATES
[state_name
]
3587 states
= state
['states']
3588 args
= func
.GetOriginalArgs()
3589 num_args
= len(args
)
3591 for group_ndx
, group
in enumerate(Grouper(num_args
, states
)):
3592 for ndx
, item
in enumerate(group
):
3593 code
.append("state_.%s != %s" % (item
['name'], args
[ndx
].name
))
3594 file.Write(" if (%s) {\n" % " ||\n ".join(code
))
3595 for group_ndx
, group
in enumerate(Grouper(num_args
, states
)):
3596 for ndx
, item
in enumerate(group
):
3597 file.Write(" state_.%s = %s;\n" % (item
['name'], args
[ndx
].name
))
3598 if 'state_flag' in state
:
3599 file.Write(" %s = true;\n" % state
['state_flag'])
3600 if not func
.GetInfo("no_gl"):
3601 file.Write(" %s(%s);\n" %
3602 (func
.GetGLFunctionName(), func
.MakeOriginalArgString("")))
3606 class StateSetNamedParameter(TypeHandler
):
3607 """Handler for commands that set a state chosen with an enum parameter."""
3610 TypeHandler
.__init
__(self
)
3612 def WriteHandlerImplementation(self
, func
, file):
3613 """Overridden from TypeHandler."""
3614 state_name
= func
.GetInfo('state')
3615 state
= _STATES
[state_name
]
3616 states
= state
['states']
3617 args
= func
.GetOriginalArgs()
3618 num_args
= len(args
)
3619 assert num_args
== 2
3620 file.Write(" switch (%s) {\n" % args
[0].name
)
3621 for state
in states
:
3622 file.Write(" case %s:\n" % state
['enum'])
3623 file.Write(" if (state_.%s != %s) {\n" %
3624 (state
['name'], args
[1].name
))
3625 file.Write(" state_.%s = %s;\n" % (state
['name'], args
[1].name
))
3626 if not func
.GetInfo("no_gl"):
3627 file.Write(" %s(%s);\n" %
3628 (func
.GetGLFunctionName(), func
.MakeOriginalArgString("")))
3630 file.Write(" break;\n")
3631 file.Write(" default:\n")
3632 file.Write(" NOTREACHED();\n")
3636 class CustomHandler(TypeHandler
):
3637 """Handler for commands that are auto-generated but require minor tweaks."""
3640 TypeHandler
.__init
__(self
)
3642 def WriteServiceImplementation(self
, func
, file):
3643 """Overrriden from TypeHandler."""
3646 def WriteImmediateServiceImplementation(self
, func
, file):
3647 """Overrriden from TypeHandler."""
3650 def WriteBucketServiceImplementation(self
, func
, file):
3651 """Overrriden from TypeHandler."""
3654 def WriteServiceUnitTest(self
, func
, file, *extras
):
3655 """Overrriden from TypeHandler."""
3656 file.Write("// TODO(gman): %s\n\n" % func
.name
)
3658 def WriteImmediateServiceUnitTest(self
, func
, file, *extras
):
3659 """Overrriden from TypeHandler."""
3660 file.Write("// TODO(gman): %s\n\n" % func
.name
)
3662 def WriteImmediateCmdGetTotalSize(self
, func
, file):
3663 """Overrriden from TypeHandler."""
3665 " uint32_t total_size = 0; // TODO(gman): get correct size.\n")
3667 def WriteImmediateCmdInit(self
, func
, file):
3668 """Overrriden from TypeHandler."""
3669 file.Write(" void Init(%s) {\n" % func
.MakeTypedCmdArgString("_"))
3670 self
.WriteImmediateCmdGetTotalSize(func
, file)
3671 file.Write(" SetHeader(total_size);\n")
3672 args
= func
.GetCmdArgs()
3674 file.Write(" %s = _%s;\n" % (arg
.name
, arg
.name
))
3678 def WriteImmediateCmdSet(self
, func
, file):
3679 """Overrriden from TypeHandler."""
3680 copy_args
= func
.MakeCmdArgString("_", False)
3681 file.Write(" void* Set(void* cmd%s) {\n" %
3682 func
.MakeTypedCmdArgString("_", True))
3683 self
.WriteImmediateCmdGetTotalSize(func
, file)
3684 file.Write(" static_cast<ValueType*>(cmd)->Init(%s);\n" % copy_args
)
3685 file.Write(" return NextImmediateCmdAddressTotalSize<ValueType>("
3686 "cmd, total_size);\n")
3691 class TodoHandler(CustomHandler
):
3692 """Handle for commands that are not yet implemented."""
3694 def NeedsDataTransferFunction(self
, func
):
3695 """Overriden from TypeHandler."""
3698 def WriteImmediateFormatTest(self
, func
, file):
3699 """Overrriden from TypeHandler."""
3702 def WriteGLES2ImplementationUnitTest(self
, func
, file):
3703 """Overrriden from TypeHandler."""
3706 def WriteGLES2Implementation(self
, func
, file):
3707 """Overrriden from TypeHandler."""
3708 file.Write("%s GLES2Implementation::%s(%s) {\n" %
3709 (func
.return_type
, func
.original_name
,
3710 func
.MakeTypedOriginalArgString("")))
3711 file.Write(" // TODO: for now this is a no-op\n")
3714 "GL_INVALID_OPERATION, \"gl%s\", \"not implemented\");\n" %
3716 if func
.return_type
!= "void":
3717 file.Write(" return 0;\n")
3721 def WriteServiceImplementation(self
, func
, file):
3722 """Overrriden from TypeHandler."""
3723 self
.WriteServiceHandlerFunctionHeader(func
, file)
3724 file.Write(" // TODO: for now this is a no-op\n")
3726 " LOCAL_SET_GL_ERROR("
3727 "GL_INVALID_OPERATION, \"gl%s\", \"not implemented\");\n" %
3729 file.Write(" return error::kNoError;\n")
3734 class HandWrittenHandler(CustomHandler
):
3735 """Handler for comands where everything must be written by hand."""
3737 def InitFunction(self
, func
):
3738 """Add or adjust anything type specific for this function."""
3739 CustomHandler
.InitFunction(self
, func
)
3740 func
.can_auto_generate
= False
3742 def NeedsDataTransferFunction(self
, func
):
3743 """Overriden from TypeHandler."""
3744 # If specified explicitly, force the data transfer method.
3745 if func
.GetInfo('data_transfer_methods'):
3749 def WriteStruct(self
, func
, file):
3750 """Overrriden from TypeHandler."""
3753 def WriteDocs(self
, func
, file):
3754 """Overrriden from TypeHandler."""
3757 def WriteServiceUnitTest(self
, func
, file, *extras
):
3758 """Overrriden from TypeHandler."""
3759 file.Write("// TODO(gman): %s\n\n" % func
.name
)
3761 def WriteImmediateServiceUnitTest(self
, func
, file, *extras
):
3762 """Overrriden from TypeHandler."""
3763 file.Write("// TODO(gman): %s\n\n" % func
.name
)
3765 def WriteBucketServiceUnitTest(self
, func
, file, *extras
):
3766 """Overrriden from TypeHandler."""
3767 file.Write("// TODO(gman): %s\n\n" % func
.name
)
3769 def WriteServiceImplementation(self
, func
, file):
3770 """Overrriden from TypeHandler."""
3773 def WriteImmediateServiceImplementation(self
, func
, file):
3774 """Overrriden from TypeHandler."""
3777 def WriteBucketServiceImplementation(self
, func
, file):
3778 """Overrriden from TypeHandler."""
3781 def WriteImmediateCmdHelper(self
, func
, file):
3782 """Overrriden from TypeHandler."""
3785 def WriteBucketCmdHelper(self
, func
, file):
3786 """Overrriden from TypeHandler."""
3789 def WriteCmdHelper(self
, func
, file):
3790 """Overrriden from TypeHandler."""
3793 def WriteFormatTest(self
, func
, file):
3794 """Overrriden from TypeHandler."""
3795 file.Write("// TODO(gman): Write test for %s\n" % func
.name
)
3797 def WriteImmediateFormatTest(self
, func
, file):
3798 """Overrriden from TypeHandler."""
3799 file.Write("// TODO(gman): Write test for %s\n" % func
.name
)
3801 def WriteBucketFormatTest(self
, func
, file):
3802 """Overrriden from TypeHandler."""
3803 file.Write("// TODO(gman): Write test for %s\n" % func
.name
)
3807 class ManualHandler(CustomHandler
):
3808 """Handler for commands who's handlers must be written by hand."""
3811 CustomHandler
.__init
__(self
)
3813 def InitFunction(self
, func
):
3814 """Overrriden from TypeHandler."""
3815 if (func
.name
== 'CompressedTexImage2DBucket'):
3816 func
.cmd_args
= func
.cmd_args
[:-1]
3817 func
.AddCmdArg(Argument('bucket_id', 'GLuint'))
3819 CustomHandler
.InitFunction(self
, func
)
3821 def WriteServiceImplementation(self
, func
, file):
3822 """Overrriden from TypeHandler."""
3825 def WriteBucketServiceImplementation(self
, func
, file):
3826 """Overrriden from TypeHandler."""
3829 def WriteServiceUnitTest(self
, func
, file, *extras
):
3830 """Overrriden from TypeHandler."""
3831 file.Write("// TODO(gman): %s\n\n" % func
.name
)
3833 def WriteImmediateServiceUnitTest(self
, func
, file, *extras
):
3834 """Overrriden from TypeHandler."""
3835 file.Write("// TODO(gman): %s\n\n" % func
.name
)
3837 def WriteImmediateServiceImplementation(self
, func
, file):
3838 """Overrriden from TypeHandler."""
3841 def WriteImmediateFormatTest(self
, func
, file):
3842 """Overrriden from TypeHandler."""
3843 file.Write("// TODO(gman): Implement test for %s\n" % func
.name
)
3845 def WriteGLES2Implementation(self
, func
, file):
3846 """Overrriden from TypeHandler."""
3847 if func
.GetInfo('impl_func'):
3848 super(ManualHandler
, self
).WriteGLES2Implementation(func
, file)
3850 def WriteGLES2ImplementationHeader(self
, func
, file):
3851 """Overrriden from TypeHandler."""
3852 file.Write("virtual %s %s(%s) OVERRIDE;\n" %
3853 (func
.return_type
, func
.original_name
,
3854 func
.MakeTypedOriginalArgString("")))
3857 def WriteImmediateCmdGetTotalSize(self
, func
, file):
3858 """Overrriden from TypeHandler."""
3859 # TODO(gman): Move this data to _FUNCTION_INFO?
3860 CustomHandler
.WriteImmediateCmdGetTotalSize(self
, func
, file)
3863 class DataHandler(TypeHandler
):
3864 """Handler for glBufferData, glBufferSubData, glTexImage2D, glTexSubImage2D,
3865 glCompressedTexImage2D, glCompressedTexImageSub2D."""
3867 TypeHandler
.__init
__(self
)
3869 def InitFunction(self
, func
):
3870 """Overrriden from TypeHandler."""
3871 if func
.name
== 'CompressedTexSubImage2DBucket':
3872 func
.cmd_args
= func
.cmd_args
[:-1]
3873 func
.AddCmdArg(Argument('bucket_id', 'GLuint'))
3875 def WriteGetDataSizeCode(self
, func
, file):
3876 """Overrriden from TypeHandler."""
3877 # TODO(gman): Move this data to _FUNCTION_INFO?
3879 if name
.endswith("Immediate"):
3881 if name
== 'BufferData' or name
== 'BufferSubData':
3882 file.Write(" uint32_t data_size = size;\n")
3883 elif (name
== 'CompressedTexImage2D' or
3884 name
== 'CompressedTexSubImage2D'):
3885 file.Write(" uint32_t data_size = imageSize;\n")
3886 elif (name
== 'CompressedTexSubImage2DBucket'):
3887 file.Write(" Bucket* bucket = GetBucket(c.bucket_id);\n")
3888 file.Write(" uint32_t data_size = bucket->size();\n")
3889 file.Write(" GLsizei imageSize = data_size;\n")
3890 elif name
== 'TexImage2D' or name
== 'TexSubImage2D':
3891 code
= """ uint32_t data_size;
3892 if (!GLES2Util::ComputeImageDataSize(
3893 width, height, format, type, unpack_alignment_, &data_size)) {
3894 return error::kOutOfBounds;
3900 "// uint32_t data_size = 0; // TODO(gman): get correct size!\n")
3902 def WriteImmediateCmdGetTotalSize(self
, func
, file):
3903 """Overrriden from TypeHandler."""
3906 def WriteImmediateCmdSizeTest(self
, func
, file):
3907 """Overrriden from TypeHandler."""
3908 file.Write(" EXPECT_EQ(sizeof(cmd), total_size);\n")
3910 def WriteImmediateCmdInit(self
, func
, file):
3911 """Overrriden from TypeHandler."""
3912 file.Write(" void Init(%s) {\n" % func
.MakeTypedCmdArgString("_"))
3913 self
.WriteImmediateCmdGetTotalSize(func
, file)
3914 file.Write(" SetHeader(total_size);\n")
3915 args
= func
.GetCmdArgs()
3917 file.Write(" %s = _%s;\n" % (arg
.name
, arg
.name
))
3921 def WriteImmediateCmdSet(self
, func
, file):
3922 """Overrriden from TypeHandler."""
3923 copy_args
= func
.MakeCmdArgString("_", False)
3924 file.Write(" void* Set(void* cmd%s) {\n" %
3925 func
.MakeTypedCmdArgString("_", True))
3926 self
.WriteImmediateCmdGetTotalSize(func
, file)
3927 file.Write(" static_cast<ValueType*>(cmd)->Init(%s);\n" % copy_args
)
3928 file.Write(" return NextImmediateCmdAddressTotalSize<ValueType>("
3929 "cmd, total_size);\n")
3933 def WriteImmediateFormatTest(self
, func
, file):
3934 """Overrriden from TypeHandler."""
3935 # TODO(gman): Remove this exception.
3936 file.Write("// TODO(gman): Implement test for %s\n" % func
.name
)
3939 def WriteServiceUnitTest(self
, func
, file, *extras
):
3940 """Overrriden from TypeHandler."""
3941 file.Write("// TODO(gman): %s\n\n" % func
.name
)
3943 def WriteImmediateServiceUnitTest(self
, func
, file, *extras
):
3944 """Overrriden from TypeHandler."""
3945 file.Write("// TODO(gman): %s\n\n" % func
.name
)
3947 def WriteBucketServiceImplementation(self
, func
, file):
3948 """Overrriden from TypeHandler."""
3949 if not func
.name
== 'CompressedTexSubImage2DBucket':
3950 TypeHandler
.WriteBucketServiceImplemenation(self
, func
, file)
3953 class BindHandler(TypeHandler
):
3954 """Handler for glBind___ type functions."""
3957 TypeHandler
.__init
__(self
)
3959 def WriteServiceUnitTest(self
, func
, file, *extras
):
3960 """Overrriden from TypeHandler."""
3962 if len(func
.GetOriginalArgs()) == 1:
3964 TEST_P(%(test_name)s, %(name)sValidArgs) {
3965 EXPECT_CALL(*gl_, %(gl_func_name)s(%(gl_args)s));
3966 SpecializedSetup<cmds::%(name)s, 0>(true);
3969 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
3970 EXPECT_EQ(GL_NO_ERROR, GetGLError());
3973 if func
.GetInfo("gen_func"):
3975 TEST_P(%(test_name)s, %(name)sValidArgsNewId) {
3976 EXPECT_CALL(*gl_, %(gl_func_name)s(kNewServiceId));
3977 EXPECT_CALL(*gl_, %(gl_gen_func_name)s(1, _))
3978 .WillOnce(SetArgumentPointee<1>(kNewServiceId));
3979 SpecializedSetup<cmds::%(name)s, 0>(true);
3981 cmd.Init(kNewClientId);
3982 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
3983 EXPECT_EQ(GL_NO_ERROR, GetGLError());
3984 EXPECT_TRUE(Get%(resource_type)s(kNewClientId) != NULL);
3987 self
.WriteValidUnitTest(func
, file, valid_test
, {
3988 'resource_type': func
.GetOriginalArgs()[0].resource_type
,
3989 'gl_gen_func_name': func
.GetInfo("gen_func"),
3993 TEST_P(%(test_name)s, %(name)sValidArgs) {
3994 EXPECT_CALL(*gl_, %(gl_func_name)s(%(gl_args)s));
3995 SpecializedSetup<cmds::%(name)s, 0>(true);
3998 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
3999 EXPECT_EQ(GL_NO_ERROR, GetGLError());
4002 if func
.GetInfo("gen_func"):
4004 TEST_P(%(test_name)s, %(name)sValidArgsNewId) {
4005 EXPECT_CALL(*gl_, %(gl_func_name)s(%(first_gl_arg)s, kNewServiceId));
4006 EXPECT_CALL(*gl_, %(gl_gen_func_name)s(1, _))
4007 .WillOnce(SetArgumentPointee<1>(kNewServiceId));
4008 SpecializedSetup<cmds::%(name)s, 0>(true);
4010 cmd.Init(%(first_arg)s, kNewClientId);
4011 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
4012 EXPECT_EQ(GL_NO_ERROR, GetGLError());
4013 EXPECT_TRUE(Get%(resource_type)s(kNewClientId) != NULL);
4016 self
.WriteValidUnitTest(func
, file, valid_test
, {
4017 'first_arg': func
.GetOriginalArgs()[0].GetValidArg(func
),
4018 'first_gl_arg': func
.GetOriginalArgs()[0].GetValidGLArg(func
),
4019 'resource_type': func
.GetOriginalArgs()[1].resource_type
,
4020 'gl_gen_func_name': func
.GetInfo("gen_func"),
4024 TEST_P(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) {
4025 EXPECT_CALL(*gl_, %(gl_func_name)s(%(gl_args)s)).Times(0);
4026 SpecializedSetup<cmds::%(name)s, 0>(false);
4029 EXPECT_EQ(error::%(parse_result)s, ExecuteCmd(cmd));%(gl_error_test)s
4032 self
.WriteInvalidUnitTest(func
, file, invalid_test
, *extras
)
4034 def WriteGLES2Implementation(self
, func
, file):
4035 """Writes the GLES2 Implemention."""
4037 impl_func
= func
.GetInfo('impl_func')
4038 impl_decl
= func
.GetInfo('impl_decl')
4040 if (func
.can_auto_generate
and
4041 (impl_func
== None or impl_func
== True) and
4042 (impl_decl
== None or impl_decl
== True)):
4044 file.Write("%s GLES2Implementation::%s(%s) {\n" %
4045 (func
.return_type
, func
.original_name
,
4046 func
.MakeTypedOriginalArgString("")))
4047 file.Write(" GPU_CLIENT_SINGLE_THREAD_CHECK();\n")
4048 func
.WriteDestinationInitalizationValidation(file)
4049 self
.WriteClientGLCallLog(func
, file)
4050 for arg
in func
.GetOriginalArgs():
4051 arg
.WriteClientSideValidationCode(file, func
)
4053 code
= """ if (Is%(type)sReservedId(%(id)s)) {
4054 SetGLError(GL_INVALID_OPERATION, "%(name)s\", \"%(id)s reserved id");
4057 if (%(name)sHelper(%(arg_string)s)) {
4058 helper_->%(name)s(%(arg_string)s);
4065 if len(func
.GetOriginalArgs()) == 1:
4066 # Bind functions that have no target (like BindVertexArrayOES)
4067 name_arg
= func
.GetOriginalArgs()[0]
4069 # Bind functions that have both a target and a name (like BindTexture)
4070 name_arg
= func
.GetOriginalArgs()[1]
4074 'arg_string': func
.MakeOriginalArgString(""),
4075 'id': name_arg
.name
,
4076 'type': name_arg
.resource_type
,
4077 'lc_type': name_arg
.resource_type
.lower(),
4080 def WriteGLES2ImplementationUnitTest(self
, func
, file):
4081 """Overrriden from TypeHandler."""
4082 client_test
= func
.GetInfo('client_test')
4083 if client_test
== False:
4086 TEST_F(GLES2ImplementationTest, %(name)s) {
4091 expected.cmd.Init(%(cmd_args)s);
4093 gl_->%(name)s(%(args)s);
4094 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected)));
4096 gl_->%(name)s(%(args)s);
4097 EXPECT_TRUE(NoCommandsWritten());
4101 arg
.GetValidClientSideCmdArg(func
) for arg
in func
.GetCmdArgs()
4104 arg
.GetValidClientSideArg(func
) for arg
in func
.GetOriginalArgs()
4109 'args': ", ".join(gl_arg_strings
),
4110 'cmd_args': ", ".join(cmd_arg_strings
),
4114 class GENnHandler(TypeHandler
):
4115 """Handler for glGen___ type functions."""
4118 TypeHandler
.__init
__(self
)
4120 def InitFunction(self
, func
):
4121 """Overrriden from TypeHandler."""
4124 def WriteGetDataSizeCode(self
, func
, file):
4125 """Overrriden from TypeHandler."""
4126 code
= """ uint32_t data_size;
4127 if (!SafeMultiplyUint32(n, sizeof(GLuint), &data_size)) {
4128 return error::kOutOfBounds;
4133 def WriteHandlerImplementation (self
, func
, file):
4134 """Overrriden from TypeHandler."""
4135 file.Write(" if (!%sHelper(n, %s)) {\n"
4136 " return error::kInvalidArguments;\n"
4138 (func
.name
, func
.GetLastOriginalArg().name
))
4140 def WriteImmediateHandlerImplementation(self
, func
, file):
4141 """Overrriden from TypeHandler."""
4142 file.Write(" if (!%sHelper(n, %s)) {\n"
4143 " return error::kInvalidArguments;\n"
4145 (func
.original_name
, func
.GetLastOriginalArg().name
))
4147 def WriteGLES2Implementation(self
, func
, file):
4148 """Overrriden from TypeHandler."""
4149 log_code
= (""" GPU_CLIENT_LOG_CODE_BLOCK({
4150 for (GLsizei i = 0; i < n; ++i) {
4151 GPU_CLIENT_LOG(" " << i << ": " << %s[i]);
4153 });""" % func
.GetOriginalArgs()[1].name
)
4155 'log_code': log_code
,
4156 'return_type': func
.return_type
,
4157 'name': func
.original_name
,
4158 'typed_args': func
.MakeTypedOriginalArgString(""),
4159 'args': func
.MakeOriginalArgString(""),
4160 'resource_types': func
.GetInfo('resource_types'),
4161 'count_name': func
.GetOriginalArgs()[0].name
,
4164 "%(return_type)s GLES2Implementation::%(name)s(%(typed_args)s) {\n" %
4166 func
.WriteDestinationInitalizationValidation(file)
4167 self
.WriteClientGLCallLog(func
, file)
4168 for arg
in func
.GetOriginalArgs():
4169 arg
.WriteClientSideValidationCode(file, func
)
4170 not_shared
= func
.GetInfo('not_shared')
4173 """ IdAllocatorInterface* id_allocator = GetIdAllocator(id_namespaces::k%s);
4174 for (GLsizei ii = 0; ii < n; ++ii)
4175 %s[ii] = id_allocator->AllocateID();""" %
4176 (func
.GetInfo('resource_types'), func
.GetOriginalArgs()[1].name
))
4178 alloc_code
= (""" GetIdHandler(id_namespaces::k%(resource_types)s)->
4179 MakeIds(this, 0, %(args)s);""" % args
)
4180 args
['alloc_code'] = alloc_code
4182 code
= """ GPU_CLIENT_SINGLE_THREAD_CHECK();
4184 %(name)sHelper(%(args)s);
4185 helper_->%(name)sImmediate(%(args)s);
4186 if (share_group_->bind_generates_resource())
4187 helper_->CommandBufferHelper::Flush();
4193 file.Write(code
% args
)
4195 def WriteGLES2ImplementationUnitTest(self
, func
, file):
4196 """Overrriden from TypeHandler."""
4198 TEST_F(GLES2ImplementationTest, %(name)s) {
4199 GLuint ids[2] = { 0, };
4201 cmds::%(name)sImmediate gen;
4205 expected.gen.Init(arraysize(ids), &ids[0]);
4206 expected.data[0] = k%(types)sStartId;
4207 expected.data[1] = k%(types)sStartId + 1;
4208 gl_->%(name)s(arraysize(ids), &ids[0]);
4209 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected)));
4210 EXPECT_EQ(k%(types)sStartId, ids[0]);
4211 EXPECT_EQ(k%(types)sStartId + 1, ids[1]);
4216 'types': func
.GetInfo('resource_types'),
4219 def WriteServiceUnitTest(self
, func
, file, *extras
):
4220 """Overrriden from TypeHandler."""
4222 TEST_P(%(test_name)s, %(name)sValidArgs) {
4223 EXPECT_CALL(*gl_, %(gl_func_name)s(1, _))
4224 .WillOnce(SetArgumentPointee<1>(kNewServiceId));
4225 GetSharedMemoryAs<GLuint*>()[0] = kNewClientId;
4226 SpecializedSetup<cmds::%(name)s, 0>(true);
4229 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
4230 EXPECT_EQ(GL_NO_ERROR, GetGLError());
4231 EXPECT_TRUE(Get%(resource_name)s(kNewClientId) != NULL);
4234 self
.WriteValidUnitTest(func
, file, valid_test
, {
4235 'resource_name': func
.GetInfo('resource_type'),
4238 TEST_P(%(test_name)s, %(name)sInvalidArgs) {
4239 EXPECT_CALL(*gl_, %(gl_func_name)s(_, _)).Times(0);
4240 GetSharedMemoryAs<GLuint*>()[0] = client_%(resource_name)s_id_;
4241 SpecializedSetup<cmds::%(name)s, 0>(false);
4244 EXPECT_EQ(error::kInvalidArguments, ExecuteCmd(cmd));
4247 self
.WriteValidUnitTest(func
, file, invalid_test
, {
4248 'resource_name': func
.GetInfo('resource_type').lower(),
4251 def WriteImmediateServiceUnitTest(self
, func
, file, *extras
):
4252 """Overrriden from TypeHandler."""
4254 TEST_P(%(test_name)s, %(name)sValidArgs) {
4255 EXPECT_CALL(*gl_, %(gl_func_name)s(1, _))
4256 .WillOnce(SetArgumentPointee<1>(kNewServiceId));
4257 cmds::%(name)s* cmd = GetImmediateAs<cmds::%(name)s>();
4258 GLuint temp = kNewClientId;
4259 SpecializedSetup<cmds::%(name)s, 0>(true);
4260 cmd->Init(1, &temp);
4261 EXPECT_EQ(error::kNoError,
4262 ExecuteImmediateCmd(*cmd, sizeof(temp)));
4263 EXPECT_EQ(GL_NO_ERROR, GetGLError());
4264 EXPECT_TRUE(Get%(resource_name)s(kNewClientId) != NULL);
4267 self
.WriteValidUnitTest(func
, file, valid_test
, {
4268 'resource_name': func
.GetInfo('resource_type'),
4271 TEST_P(%(test_name)s, %(name)sInvalidArgs) {
4272 EXPECT_CALL(*gl_, %(gl_func_name)s(_, _)).Times(0);
4273 cmds::%(name)s* cmd = GetImmediateAs<cmds::%(name)s>();
4274 SpecializedSetup<cmds::%(name)s, 0>(false);
4275 cmd->Init(1, &client_%(resource_name)s_id_);
4276 EXPECT_EQ(error::kInvalidArguments,
4277 ExecuteImmediateCmd(*cmd, sizeof(&client_%(resource_name)s_id_)));
4280 self
.WriteValidUnitTest(func
, file, invalid_test
, {
4281 'resource_name': func
.GetInfo('resource_type').lower(),
4284 def WriteImmediateCmdComputeSize(self
, func
, file):
4285 """Overrriden from TypeHandler."""
4286 file.Write(" static uint32_t ComputeDataSize(GLsizei n) {\n")
4288 " return static_cast<uint32_t>(sizeof(GLuint) * n); // NOLINT\n")
4291 file.Write(" static uint32_t ComputeSize(GLsizei n) {\n")
4292 file.Write(" return static_cast<uint32_t>(\n")
4293 file.Write(" sizeof(ValueType) + ComputeDataSize(n)); // NOLINT\n")
4297 def WriteImmediateCmdSetHeader(self
, func
, file):
4298 """Overrriden from TypeHandler."""
4299 file.Write(" void SetHeader(GLsizei n) {\n")
4300 file.Write(" header.SetCmdByTotalSize<ValueType>(ComputeSize(n));\n")
4304 def WriteImmediateCmdInit(self
, func
, file):
4305 """Overrriden from TypeHandler."""
4306 last_arg
= func
.GetLastOriginalArg()
4307 file.Write(" void Init(%s, %s _%s) {\n" %
4308 (func
.MakeTypedCmdArgString("_"),
4309 last_arg
.type, last_arg
.name
))
4310 file.Write(" SetHeader(_n);\n")
4311 args
= func
.GetCmdArgs()
4313 file.Write(" %s = _%s;\n" % (arg
.name
, arg
.name
))
4314 file.Write(" memcpy(ImmediateDataAddress(this),\n")
4315 file.Write(" _%s, ComputeDataSize(_n));\n" % last_arg
.name
)
4319 def WriteImmediateCmdSet(self
, func
, file):
4320 """Overrriden from TypeHandler."""
4321 last_arg
= func
.GetLastOriginalArg()
4322 copy_args
= func
.MakeCmdArgString("_", False)
4323 file.Write(" void* Set(void* cmd%s, %s _%s) {\n" %
4324 (func
.MakeTypedCmdArgString("_", True),
4325 last_arg
.type, last_arg
.name
))
4326 file.Write(" static_cast<ValueType*>(cmd)->Init(%s, _%s);\n" %
4327 (copy_args
, last_arg
.name
))
4328 file.Write(" const uint32_t size = ComputeSize(_n);\n")
4329 file.Write(" return NextImmediateCmdAddressTotalSize<ValueType>("
4334 def WriteImmediateCmdHelper(self
, func
, file):
4335 """Overrriden from TypeHandler."""
4336 code
= """ void %(name)s(%(typed_args)s) {
4337 const uint32_t size = gles2::cmds::%(name)s::ComputeSize(n);
4338 gles2::cmds::%(name)s* c =
4339 GetImmediateCmdSpaceTotalSize<gles2::cmds::%(name)s>(size);
4348 "typed_args": func
.MakeTypedOriginalArgString(""),
4349 "args": func
.MakeOriginalArgString(""),
4352 def WriteImmediateFormatTest(self
, func
, file):
4353 """Overrriden from TypeHandler."""
4354 file.Write("TEST_F(GLES2FormatTest, %s) {\n" % func
.name
)
4355 file.Write(" static GLuint ids[] = { 12, 23, 34, };\n")
4356 file.Write(" cmds::%s& cmd = *GetBufferAs<cmds::%s>();\n" %
4357 (func
.name
, func
.name
))
4358 file.Write(" void* next_cmd = cmd.Set(\n")
4359 file.Write(" &cmd, static_cast<GLsizei>(arraysize(ids)), ids);\n")
4360 file.Write(" EXPECT_EQ(static_cast<uint32_t>(cmds::%s::kCmdId),\n" %
4362 file.Write(" cmd.header.command);\n")
4363 file.Write(" EXPECT_EQ(sizeof(cmd) +\n")
4364 file.Write(" RoundSizeToMultipleOfEntries(cmd.n * 4u),\n")
4365 file.Write(" cmd.header.size * 4u);\n")
4366 file.Write(" EXPECT_EQ(static_cast<GLsizei>(arraysize(ids)), cmd.n);\n");
4367 file.Write(" CheckBytesWrittenMatchesExpectedSize(\n")
4368 file.Write(" next_cmd, sizeof(cmd) +\n")
4369 file.Write(" RoundSizeToMultipleOfEntries(arraysize(ids) * 4u));\n")
4370 file.Write(" // TODO(gman): Check that ids were inserted;\n")
4375 class CreateHandler(TypeHandler
):
4376 """Handler for glCreate___ type functions."""
4379 TypeHandler
.__init
__(self
)
4381 def InitFunction(self
, func
):
4382 """Overrriden from TypeHandler."""
4383 func
.AddCmdArg(Argument("client_id", 'uint32_t'))
4385 def WriteServiceUnitTest(self
, func
, file, *extras
):
4386 """Overrriden from TypeHandler."""
4388 TEST_P(%(test_name)s, %(name)sValidArgs) {
4389 EXPECT_CALL(*gl_, %(gl_func_name)s(%(gl_args)s))
4390 .WillOnce(Return(kNewServiceId));
4391 SpecializedSetup<cmds::%(name)s, 0>(true);
4393 cmd.Init(%(args)s%(comma)skNewClientId);
4394 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
4395 EXPECT_EQ(GL_NO_ERROR, GetGLError());
4396 EXPECT_TRUE(Get%(resource_type)s(kNewClientId) != NULL);
4400 if len(func
.GetOriginalArgs()):
4402 self
.WriteValidUnitTest(func
, file, valid_test
, {
4404 'resource_type': func
.name
[6:],
4407 TEST_P(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) {
4408 EXPECT_CALL(*gl_, %(gl_func_name)s(%(gl_args)s)).Times(0);
4409 SpecializedSetup<cmds::%(name)s, 0>(false);
4411 cmd.Init(%(args)s%(comma)skNewClientId);
4412 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));%(gl_error_test)s
4415 self
.WriteInvalidUnitTest(func
, file, invalid_test
, {
4419 def WriteHandlerImplementation (self
, func
, file):
4420 """Overrriden from TypeHandler."""
4421 file.Write(" uint32_t client_id = c.client_id;\n")
4422 file.Write(" if (!%sHelper(%s)) {\n" %
4423 (func
.name
, func
.MakeCmdArgString("")))
4424 file.Write(" return error::kInvalidArguments;\n")
4427 def WriteGLES2Implementation(self
, func
, file):
4428 """Overrriden from TypeHandler."""
4429 file.Write("%s GLES2Implementation::%s(%s) {\n" %
4430 (func
.return_type
, func
.original_name
,
4431 func
.MakeTypedOriginalArgString("")))
4432 file.Write(" GPU_CLIENT_SINGLE_THREAD_CHECK();\n")
4433 func
.WriteDestinationInitalizationValidation(file)
4434 self
.WriteClientGLCallLog(func
, file)
4435 for arg
in func
.GetOriginalArgs():
4436 arg
.WriteClientSideValidationCode(file, func
)
4437 file.Write(" GLuint client_id;\n")
4439 " GetIdHandler(id_namespaces::kProgramsAndShaders)->\n")
4440 file.Write(" MakeIds(this, 0, 1, &client_id);\n")
4441 file.Write(" helper_->%s(%s);\n" %
4442 (func
.name
, func
.MakeCmdArgString("")))
4443 file.Write(' GPU_CLIENT_LOG("returned " << client_id);\n')
4444 file.Write(" CheckGLError();\n")
4445 file.Write(" return client_id;\n")
4450 class DeleteHandler(TypeHandler
):
4451 """Handler for glDelete___ single resource type functions."""
4454 TypeHandler
.__init
__(self
)
4456 def WriteServiceImplementation(self
, func
, file):
4457 """Overrriden from TypeHandler."""
4460 def WriteGLES2Implementation(self
, func
, file):
4461 """Overrriden from TypeHandler."""
4462 file.Write("%s GLES2Implementation::%s(%s) {\n" %
4463 (func
.return_type
, func
.original_name
,
4464 func
.MakeTypedOriginalArgString("")))
4465 file.Write(" GPU_CLIENT_SINGLE_THREAD_CHECK();\n")
4466 func
.WriteDestinationInitalizationValidation(file)
4467 self
.WriteClientGLCallLog(func
, file)
4468 for arg
in func
.GetOriginalArgs():
4469 arg
.WriteClientSideValidationCode(file, func
)
4471 " GPU_CLIENT_DCHECK(%s != 0);\n" % func
.GetOriginalArgs()[-1].name
)
4472 file.Write(" %sHelper(%s);\n" %
4473 (func
.original_name
, func
.GetOriginalArgs()[-1].name
))
4474 file.Write(" CheckGLError();\n")
4479 class DELnHandler(TypeHandler
):
4480 """Handler for glDelete___ type functions."""
4483 TypeHandler
.__init
__(self
)
4485 def WriteGetDataSizeCode(self
, func
, file):
4486 """Overrriden from TypeHandler."""
4487 code
= """ uint32_t data_size;
4488 if (!SafeMultiplyUint32(n, sizeof(GLuint), &data_size)) {
4489 return error::kOutOfBounds;
4494 def WriteGLES2ImplementationUnitTest(self
, func
, file):
4495 """Overrriden from TypeHandler."""
4497 TEST_F(GLES2ImplementationTest, %(name)s) {
4498 GLuint ids[2] = { k%(types)sStartId, k%(types)sStartId + 1 };
4500 cmds::%(name)sImmediate del;
4504 expected.del.Init(arraysize(ids), &ids[0]);
4505 expected.data[0] = k%(types)sStartId;
4506 expected.data[1] = k%(types)sStartId + 1;
4507 gl_->%(name)s(arraysize(ids), &ids[0]);
4508 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected)));
4513 'types': func
.GetInfo('resource_types'),
4516 def WriteServiceUnitTest(self
, func
, file, *extras
):
4517 """Overrriden from TypeHandler."""
4519 TEST_P(%(test_name)s, %(name)sValidArgs) {
4522 %(gl_func_name)s(1, Pointee(kService%(upper_resource_name)sId)))
4524 GetSharedMemoryAs<GLuint*>()[0] = client_%(resource_name)s_id_;
4525 SpecializedSetup<cmds::%(name)s, 0>(true);
4528 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
4529 EXPECT_EQ(GL_NO_ERROR, GetGLError());
4531 Get%(upper_resource_name)s(client_%(resource_name)s_id_) == NULL);
4534 self
.WriteValidUnitTest(func
, file, valid_test
, {
4535 'resource_name': func
.GetInfo('resource_type').lower(),
4536 'upper_resource_name': func
.GetInfo('resource_type'),
4539 TEST_P(%(test_name)s, %(name)sInvalidArgs) {
4540 GetSharedMemoryAs<GLuint*>()[0] = kInvalidClientId;
4541 SpecializedSetup<cmds::%(name)s, 0>(false);
4544 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
4547 self
.WriteValidUnitTest(func
, file, invalid_test
, *extras
)
4549 def WriteImmediateServiceUnitTest(self
, func
, file, *extras
):
4550 """Overrriden from TypeHandler."""
4552 TEST_P(%(test_name)s, %(name)sValidArgs) {
4555 %(gl_func_name)s(1, Pointee(kService%(upper_resource_name)sId)))
4557 cmds::%(name)s& cmd = *GetImmediateAs<cmds::%(name)s>();
4558 SpecializedSetup<cmds::%(name)s, 0>(true);
4559 cmd.Init(1, &client_%(resource_name)s_id_);
4560 EXPECT_EQ(error::kNoError,
4561 ExecuteImmediateCmd(cmd, sizeof(client_%(resource_name)s_id_)));
4562 EXPECT_EQ(GL_NO_ERROR, GetGLError());
4564 Get%(upper_resource_name)s(client_%(resource_name)s_id_) == NULL);
4567 self
.WriteValidUnitTest(func
, file, valid_test
, {
4568 'resource_name': func
.GetInfo('resource_type').lower(),
4569 'upper_resource_name': func
.GetInfo('resource_type'),
4572 TEST_P(%(test_name)s, %(name)sInvalidArgs) {
4573 cmds::%(name)s& cmd = *GetImmediateAs<cmds::%(name)s>();
4574 SpecializedSetup<cmds::%(name)s, 0>(false);
4575 GLuint temp = kInvalidClientId;
4577 EXPECT_EQ(error::kNoError,
4578 ExecuteImmediateCmd(cmd, sizeof(temp)));
4581 self
.WriteValidUnitTest(func
, file, invalid_test
, *extras
)
4583 def WriteHandlerImplementation (self
, func
, file):
4584 """Overrriden from TypeHandler."""
4585 file.Write(" %sHelper(n, %s);\n" %
4586 (func
.name
, func
.GetLastOriginalArg().name
))
4588 def WriteImmediateHandlerImplementation (self
, func
, file):
4589 """Overrriden from TypeHandler."""
4590 file.Write(" %sHelper(n, %s);\n" %
4591 (func
.original_name
, func
.GetLastOriginalArg().name
))
4593 def WriteGLES2Implementation(self
, func
, file):
4594 """Overrriden from TypeHandler."""
4595 impl_decl
= func
.GetInfo('impl_decl')
4596 if impl_decl
== None or impl_decl
== True:
4598 'return_type': func
.return_type
,
4599 'name': func
.original_name
,
4600 'typed_args': func
.MakeTypedOriginalArgString(""),
4601 'args': func
.MakeOriginalArgString(""),
4602 'resource_type': func
.GetInfo('resource_type').lower(),
4603 'count_name': func
.GetOriginalArgs()[0].name
,
4606 "%(return_type)s GLES2Implementation::%(name)s(%(typed_args)s) {\n" %
4608 file.Write(" GPU_CLIENT_SINGLE_THREAD_CHECK();\n")
4609 func
.WriteDestinationInitalizationValidation(file)
4610 self
.WriteClientGLCallLog(func
, file)
4611 file.Write(""" GPU_CLIENT_LOG_CODE_BLOCK({
4612 for (GLsizei i = 0; i < n; ++i) {
4613 GPU_CLIENT_LOG(" " << i << ": " << %s[i]);
4616 """ % func
.GetOriginalArgs()[1].name
)
4617 file.Write(""" GPU_CLIENT_DCHECK_CODE_BLOCK({
4618 for (GLsizei i = 0; i < n; ++i) {
4622 """ % func
.GetOriginalArgs()[1].name
)
4623 for arg
in func
.GetOriginalArgs():
4624 arg
.WriteClientSideValidationCode(file, func
)
4625 code
= """ %(name)sHelper(%(args)s);
4630 file.Write(code
% args
)
4632 def WriteImmediateCmdComputeSize(self
, func
, file):
4633 """Overrriden from TypeHandler."""
4634 file.Write(" static uint32_t ComputeDataSize(GLsizei n) {\n")
4636 " return static_cast<uint32_t>(sizeof(GLuint) * n); // NOLINT\n")
4639 file.Write(" static uint32_t ComputeSize(GLsizei n) {\n")
4640 file.Write(" return static_cast<uint32_t>(\n")
4641 file.Write(" sizeof(ValueType) + ComputeDataSize(n)); // NOLINT\n")
4645 def WriteImmediateCmdSetHeader(self
, func
, file):
4646 """Overrriden from TypeHandler."""
4647 file.Write(" void SetHeader(GLsizei n) {\n")
4648 file.Write(" header.SetCmdByTotalSize<ValueType>(ComputeSize(n));\n")
4652 def WriteImmediateCmdInit(self
, func
, file):
4653 """Overrriden from TypeHandler."""
4654 last_arg
= func
.GetLastOriginalArg()
4655 file.Write(" void Init(%s, %s _%s) {\n" %
4656 (func
.MakeTypedCmdArgString("_"),
4657 last_arg
.type, last_arg
.name
))
4658 file.Write(" SetHeader(_n);\n")
4659 args
= func
.GetCmdArgs()
4661 file.Write(" %s = _%s;\n" % (arg
.name
, arg
.name
))
4662 file.Write(" memcpy(ImmediateDataAddress(this),\n")
4663 file.Write(" _%s, ComputeDataSize(_n));\n" % last_arg
.name
)
4667 def WriteImmediateCmdSet(self
, func
, file):
4668 """Overrriden from TypeHandler."""
4669 last_arg
= func
.GetLastOriginalArg()
4670 copy_args
= func
.MakeCmdArgString("_", False)
4671 file.Write(" void* Set(void* cmd%s, %s _%s) {\n" %
4672 (func
.MakeTypedCmdArgString("_", True),
4673 last_arg
.type, last_arg
.name
))
4674 file.Write(" static_cast<ValueType*>(cmd)->Init(%s, _%s);\n" %
4675 (copy_args
, last_arg
.name
))
4676 file.Write(" const uint32_t size = ComputeSize(_n);\n")
4677 file.Write(" return NextImmediateCmdAddressTotalSize<ValueType>("
4682 def WriteImmediateCmdHelper(self
, func
, file):
4683 """Overrriden from TypeHandler."""
4684 code
= """ void %(name)s(%(typed_args)s) {
4685 const uint32_t size = gles2::cmds::%(name)s::ComputeSize(n);
4686 gles2::cmds::%(name)s* c =
4687 GetImmediateCmdSpaceTotalSize<gles2::cmds::%(name)s>(size);
4696 "typed_args": func
.MakeTypedOriginalArgString(""),
4697 "args": func
.MakeOriginalArgString(""),
4700 def WriteImmediateFormatTest(self
, func
, file):
4701 """Overrriden from TypeHandler."""
4702 file.Write("TEST_F(GLES2FormatTest, %s) {\n" % func
.name
)
4703 file.Write(" static GLuint ids[] = { 12, 23, 34, };\n")
4704 file.Write(" cmds::%s& cmd = *GetBufferAs<cmds::%s>();\n" %
4705 (func
.name
, func
.name
))
4706 file.Write(" void* next_cmd = cmd.Set(\n")
4707 file.Write(" &cmd, static_cast<GLsizei>(arraysize(ids)), ids);\n")
4708 file.Write(" EXPECT_EQ(static_cast<uint32_t>(cmds::%s::kCmdId),\n" %
4710 file.Write(" cmd.header.command);\n")
4711 file.Write(" EXPECT_EQ(sizeof(cmd) +\n")
4712 file.Write(" RoundSizeToMultipleOfEntries(cmd.n * 4u),\n")
4713 file.Write(" cmd.header.size * 4u);\n")
4714 file.Write(" EXPECT_EQ(static_cast<GLsizei>(arraysize(ids)), cmd.n);\n");
4715 file.Write(" CheckBytesWrittenMatchesExpectedSize(\n")
4716 file.Write(" next_cmd, sizeof(cmd) +\n")
4717 file.Write(" RoundSizeToMultipleOfEntries(arraysize(ids) * 4u));\n")
4718 file.Write(" // TODO(gman): Check that ids were inserted;\n")
4723 class GETnHandler(TypeHandler
):
4724 """Handler for GETn for glGetBooleanv, glGetFloatv, ... type functions."""
4727 TypeHandler
.__init
__(self
)
4729 def NeedsDataTransferFunction(self
, func
):
4730 """Overriden from TypeHandler."""
4733 def WriteServiceImplementation(self
, func
, file):
4734 """Overrriden from TypeHandler."""
4735 self
.WriteServiceHandlerFunctionHeader(func
, file)
4736 last_arg
= func
.GetLastOriginalArg()
4738 all_but_last_args
= func
.GetOriginalArgs()[:-1]
4739 for arg
in all_but_last_args
:
4740 arg
.WriteGetCode(file)
4742 code
= """ typedef cmds::%(func_name)s::Result Result;
4743 GLsizei num_values = 0;
4744 GetNumValuesReturnedForGLGet(pname, &num_values);
4745 Result* result = GetSharedMemoryAs<Result*>(
4746 c.params_shm_id, c.params_shm_offset, Result::ComputeSize(num_values));
4747 %(last_arg_type)s params = result ? result->GetData() : NULL;
4750 'last_arg_type': last_arg
.type,
4751 'func_name': func
.name
,
4753 func
.WriteHandlerValidation(file)
4754 code
= """ // Check that the client initialized the result.
4755 if (result->size != 0) {
4756 return error::kInvalidArguments;
4759 shadowed
= func
.GetInfo('shadowed')
4761 file.Write(' LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("%s");\n' % func
.name
)
4763 func
.WriteHandlerImplementation(file)
4765 code
= """ result->SetNumResults(num_values);
4766 return error::kNoError;
4770 code
= """ GLenum error = glGetError();
4771 if (error == GL_NO_ERROR) {
4772 result->SetNumResults(num_values);
4774 LOCAL_SET_GL_ERROR(error, "%(func_name)s", "");
4776 return error::kNoError;
4780 file.Write(code
% {'func_name': func
.name
})
4782 def WriteGLES2Implementation(self
, func
, file):
4783 """Overrriden from TypeHandler."""
4784 impl_decl
= func
.GetInfo('impl_decl')
4785 if impl_decl
== None or impl_decl
== True:
4786 file.Write("%s GLES2Implementation::%s(%s) {\n" %
4787 (func
.return_type
, func
.original_name
,
4788 func
.MakeTypedOriginalArgString("")))
4789 file.Write(" GPU_CLIENT_SINGLE_THREAD_CHECK();\n")
4790 func
.WriteDestinationInitalizationValidation(file)
4791 self
.WriteClientGLCallLog(func
, file)
4792 for arg
in func
.GetOriginalArgs():
4793 arg
.WriteClientSideValidationCode(file, func
)
4794 all_but_last_args
= func
.GetOriginalArgs()[:-1]
4796 ", ".join(["%s" % arg
.name
for arg
in all_but_last_args
]))
4800 for arg
in func
.GetOriginalArgs() if not arg
.IsConstant()]))
4801 self
.WriteTraceEvent(func
, file)
4802 code
= """ if (%(func_name)sHelper(%(all_arg_string)s)) {
4805 typedef cmds::%(func_name)s::Result Result;
4806 Result* result = GetResultAs<Result*>();
4810 result->SetNumResults(0);
4811 helper_->%(func_name)s(%(arg_string)s,
4812 GetResultShmId(), GetResultShmOffset());
4814 result->CopyResult(params);
4815 GPU_CLIENT_LOG_CODE_BLOCK({
4816 for (int32_t i = 0; i < result->GetNumResults(); ++i) {
4817 GPU_CLIENT_LOG(" " << i << ": " << result->GetData()[i]);
4824 'func_name': func
.name
,
4825 'arg_string': arg_string
,
4826 'all_arg_string': all_arg_string
,
4829 def WriteGLES2ImplementationUnitTest(self
, func
, file):
4830 """Writes the GLES2 Implemention unit test."""
4832 TEST_F(GLES2ImplementationTest, %(name)s) {
4836 typedef cmds::%(name)s::Result Result;
4837 Result::Type result = 0;
4839 ExpectedMemoryInfo result1 = GetExpectedResultMemory(4);
4840 expected.cmd.Init(%(cmd_args)s, result1.id, result1.offset);
4841 EXPECT_CALL(*command_buffer(), OnFlush())
4842 .WillOnce(SetMemory(result1.ptr, SizedResultHelper<Result::Type>(1)))
4843 .RetiresOnSaturation();
4844 gl_->%(name)s(%(args)s, &result);
4845 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected)));
4846 EXPECT_EQ(static_cast<Result::Type>(1), result);
4849 first_cmd_arg
= func
.GetCmdArgs()[0].GetValidNonCachedClientSideCmdArg(func
)
4850 if not first_cmd_arg
:
4853 first_gl_arg
= func
.GetCmdArgs()[0].GetValidNonCachedClientSideArg(func
)
4854 cmd_arg_strings
= [first_cmd_arg
]
4855 for arg
in func
.GetCmdArgs()[1:-2]:
4856 cmd_arg_strings
.append(arg
.GetValidClientSideCmdArg(func
))
4857 gl_arg_strings
= [first_gl_arg
]
4858 for arg
in func
.GetOriginalArgs()[1:-1]:
4859 gl_arg_strings
.append(arg
.GetValidClientSideArg(func
))
4863 'args': ", ".join(gl_arg_strings
),
4864 'cmd_args': ", ".join(cmd_arg_strings
),
4867 def WriteServiceUnitTest(self
, func
, file, *extras
):
4868 """Overrriden from TypeHandler."""
4870 TEST_P(%(test_name)s, %(name)sValidArgs) {
4871 EXPECT_CALL(*gl_, GetError())
4872 .WillOnce(Return(GL_NO_ERROR))
4873 .WillOnce(Return(GL_NO_ERROR))
4874 .RetiresOnSaturation();
4875 SpecializedSetup<cmds::%(name)s, 0>(true);
4876 typedef cmds::%(name)s::Result Result;
4877 Result* result = static_cast<Result*>(shared_memory_address_);
4878 EXPECT_CALL(*gl_, %(gl_func_name)s(%(local_gl_args)s));
4882 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
4883 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(
4885 result->GetNumResults());
4886 EXPECT_EQ(GL_NO_ERROR, GetGLError());
4891 for arg
in func
.GetOriginalArgs()[:-1]:
4892 arg_value
= arg
.GetValidGLArg(func
)
4893 gl_arg_strings
.append(arg_value
)
4894 if arg
.name
== 'pname':
4895 valid_pname
= arg_value
4896 if func
.GetInfo('gl_test_func') == 'glGetIntegerv':
4897 gl_arg_strings
.append("_")
4899 gl_arg_strings
.append("result->GetData()")
4901 self
.WriteValidUnitTest(func
, file, valid_test
, {
4902 'local_gl_args': ", ".join(gl_arg_strings
),
4903 'valid_pname': valid_pname
,
4907 TEST_P(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) {
4908 EXPECT_CALL(*gl_, %(gl_func_name)s(%(gl_args)s)).Times(0);
4909 SpecializedSetup<cmds::%(name)s, 0>(false);
4910 cmds::%(name)s::Result* result =
4911 static_cast<cmds::%(name)s::Result*>(shared_memory_address_);
4915 EXPECT_EQ(error::%(parse_result)s, ExecuteCmd(cmd));
4916 EXPECT_EQ(0u, result->size);%(gl_error_test)s
4919 self
.WriteInvalidUnitTest(func
, file, invalid_test
, *extras
)
4921 class ArrayArgTypeHandler(TypeHandler
):
4922 """Base class for type handlers that handle args that are arrays"""
4925 TypeHandler
.__init
__(self
)
4927 def GetArrayType(self
, func
):
4928 """Returns the type of the element in the element array being PUT to."""
4929 for arg
in func
.GetOriginalArgs():
4931 element_type
= arg
.GetPointedType()
4934 # Special case: array type handler is used for a function that is forwarded
4935 # to the actual array type implementation
4936 element_type
= func
.GetOriginalArgs()[-1].type
4937 assert all(arg
.type == element_type \
4938 for arg
in func
.GetOriginalArgs()[-self
.GetArrayCount(func
):])
4941 def GetArrayCount(self
, func
):
4942 """Returns the count of the elements in the array being PUT to."""
4943 return func
.GetInfo('count')
4945 class PUTHandler(ArrayArgTypeHandler
):
4946 """Handler for glTexParameter_v, glVertexAttrib_v functions."""
4949 ArrayArgTypeHandler
.__init
__(self
)
4951 def WriteServiceUnitTest(self
, func
, file, *extras
):
4952 """Writes the service unit test for a command."""
4953 expected_call
= "EXPECT_CALL(*gl_, %(gl_func_name)s(%(gl_args)s));"
4954 if func
.GetInfo("first_element_only"):
4956 arg
.GetValidGLArg(func
) for arg
in func
.GetOriginalArgs()
4958 gl_arg_strings
[-1] = "*" + gl_arg_strings
[-1]
4959 expected_call
= ("EXPECT_CALL(*gl_, %%(gl_func_name)s(%s));" %
4960 ", ".join(gl_arg_strings
))
4962 TEST_P(%(test_name)s, %(name)sValidArgs) {
4963 SpecializedSetup<cmds::%(name)s, 0>(true);
4966 GetSharedMemoryAs<%(data_type)s*>()[0] = %(data_value)s;
4968 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
4969 EXPECT_EQ(GL_NO_ERROR, GetGLError());
4973 'data_type': self
.GetArrayType(func
),
4974 'data_value': func
.GetInfo('data_value') or '0',
4975 'expected_call': expected_call
,
4977 self
.WriteValidUnitTest(func
, file, valid_test
, extra
, *extras
)
4980 TEST_P(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) {
4981 EXPECT_CALL(*gl_, %(gl_func_name)s(%(gl_args)s)).Times(0);
4982 SpecializedSetup<cmds::%(name)s, 0>(false);
4985 GetSharedMemoryAs<%(data_type)s*>()[0] = %(data_value)s;
4986 EXPECT_EQ(error::%(parse_result)s, ExecuteCmd(cmd));%(gl_error_test)s
4989 self
.WriteInvalidUnitTest(func
, file, invalid_test
, extra
, *extras
)
4991 def WriteImmediateServiceUnitTest(self
, func
, file, *extras
):
4992 """Writes the service unit test for a command."""
4994 TEST_P(%(test_name)s, %(name)sValidArgs) {
4995 cmds::%(name)s& cmd = *GetImmediateAs<cmds::%(name)s>();
4996 SpecializedSetup<cmds::%(name)s, 0>(true);
4997 %(data_type)s temp[%(data_count)s] = { %(data_value)s, };
4998 cmd.Init(%(gl_args)s, &temp[0]);
5001 %(gl_func_name)s(%(gl_args)s, %(data_ref)sreinterpret_cast<
5002 %(data_type)s*>(ImmediateDataAddress(&cmd))));
5003 EXPECT_EQ(error::kNoError,
5004 ExecuteImmediateCmd(cmd, sizeof(temp)));
5005 EXPECT_EQ(GL_NO_ERROR, GetGLError());
5009 arg
.GetValidGLArg(func
) for arg
in func
.GetOriginalArgs()[0:-1]
5011 gl_any_strings
= ["_"] * len(gl_arg_strings
)
5014 'data_ref': ("*" if func
.GetInfo('first_element_only') else ""),
5015 'data_type': self
.GetArrayType(func
),
5016 'data_count': self
.GetArrayCount(func
),
5017 'data_value': func
.GetInfo('data_value') or '0',
5018 'gl_args': ", ".join(gl_arg_strings
),
5019 'gl_any_args': ", ".join(gl_any_strings
),
5021 self
.WriteValidUnitTest(func
, file, valid_test
, extra
, *extras
)
5024 TEST_P(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) {
5025 cmds::%(name)s& cmd = *GetImmediateAs<cmds::%(name)s>();
5026 EXPECT_CALL(*gl_, %(gl_func_name)s(%(gl_any_args)s, _)).Times(0);
5027 SpecializedSetup<cmds::%(name)s, 0>(false);
5028 %(data_type)s temp[%(data_count)s] = { %(data_value)s, };
5029 cmd.Init(%(all_but_last_args)s, &temp[0]);
5030 EXPECT_EQ(error::%(parse_result)s,
5031 ExecuteImmediateCmd(cmd, sizeof(temp)));%(gl_error_test)s
5034 self
.WriteInvalidUnitTest(func
, file, invalid_test
, extra
, *extras
)
5036 def WriteGetDataSizeCode(self
, func
, file):
5037 """Overrriden from TypeHandler."""
5038 code
= """ uint32_t data_size;
5039 if (!ComputeDataSize(1, sizeof(%s), %d, &data_size)) {
5040 return error::kOutOfBounds;
5043 file.Write(code
% (self
.GetArrayType(func
), self
.GetArrayCount(func
)))
5044 if func
.IsImmediate():
5045 file.Write(" if (data_size > immediate_data_size) {\n")
5046 file.Write(" return error::kOutOfBounds;\n")
5049 def WriteGLES2Implementation(self
, func
, file):
5050 """Overrriden from TypeHandler."""
5051 impl_func
= func
.GetInfo('impl_func')
5052 if (impl_func
!= None and impl_func
!= True):
5054 file.Write("%s GLES2Implementation::%s(%s) {\n" %
5055 (func
.return_type
, func
.original_name
,
5056 func
.MakeTypedOriginalArgString("")))
5057 file.Write(" GPU_CLIENT_SINGLE_THREAD_CHECK();\n")
5058 func
.WriteDestinationInitalizationValidation(file)
5059 self
.WriteClientGLCallLog(func
, file)
5060 last_arg_name
= func
.GetLastOriginalArg().name
5061 values_str
= ' << ", " << '.join(
5062 ["%s[%d]" % (last_arg_name
, ndx
) \
5063 for ndx
in range(0, self
.GetArrayCount(func
))])
5064 file.Write(' GPU_CLIENT_LOG("values: " << %s);\n' % values_str
)
5065 for arg
in func
.GetOriginalArgs():
5066 arg
.WriteClientSideValidationCode(file, func
)
5067 file.Write(" helper_->%sImmediate(%s);\n" %
5068 (func
.name
, func
.MakeOriginalArgString("")))
5069 file.Write(" CheckGLError();\n")
5073 def WriteGLES2ImplementationUnitTest(self
, func
, file):
5074 """Writes the GLES2 Implemention unit test."""
5075 client_test
= func
.GetInfo('client_test')
5076 if (client_test
!= None and client_test
!= True):
5079 TEST_F(GLES2ImplementationTest, %(name)s) {
5080 %(type)s data[%(count)d] = {0};
5082 cmds::%(name)sImmediate cmd;
5083 %(type)s data[%(count)d];
5086 for (int jj = 0; jj < %(count)d; ++jj) {
5087 data[jj] = static_cast<%(type)s>(jj);
5090 expected.cmd.Init(%(cmd_args)s, &data[0]);
5091 gl_->%(name)s(%(args)s, &data[0]);
5092 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected)));
5096 arg
.GetValidClientSideCmdArg(func
) for arg
in func
.GetCmdArgs()[0:-2]
5099 arg
.GetValidClientSideArg(func
) for arg
in func
.GetOriginalArgs()[0:-1]
5104 'type': self
.GetArrayType(func
),
5105 'count': self
.GetArrayCount(func
),
5106 'args': ", ".join(gl_arg_strings
),
5107 'cmd_args': ", ".join(cmd_arg_strings
),
5110 def WriteImmediateCmdComputeSize(self
, func
, file):
5111 """Overrriden from TypeHandler."""
5112 file.Write(" static uint32_t ComputeDataSize() {\n")
5113 file.Write(" return static_cast<uint32_t>(\n")
5114 file.Write(" sizeof(%s) * %d); // NOLINT\n" %
5115 (self
.GetArrayType(func
), self
.GetArrayCount(func
)))
5118 file.Write(" static uint32_t ComputeSize() {\n")
5119 file.Write(" return static_cast<uint32_t>(\n")
5121 " sizeof(ValueType) + ComputeDataSize()); // NOLINT\n")
5125 def WriteImmediateCmdSetHeader(self
, func
, file):
5126 """Overrriden from TypeHandler."""
5127 file.Write(" void SetHeader() {\n")
5129 " header.SetCmdByTotalSize<ValueType>(ComputeSize());\n")
5133 def WriteImmediateCmdInit(self
, func
, file):
5134 """Overrriden from TypeHandler."""
5135 last_arg
= func
.GetLastOriginalArg()
5136 file.Write(" void Init(%s, %s _%s) {\n" %
5137 (func
.MakeTypedCmdArgString("_"),
5138 last_arg
.type, last_arg
.name
))
5139 file.Write(" SetHeader();\n")
5140 args
= func
.GetCmdArgs()
5142 file.Write(" %s = _%s;\n" % (arg
.name
, arg
.name
))
5143 file.Write(" memcpy(ImmediateDataAddress(this),\n")
5144 file.Write(" _%s, ComputeDataSize());\n" % last_arg
.name
)
5148 def WriteImmediateCmdSet(self
, func
, file):
5149 """Overrriden from TypeHandler."""
5150 last_arg
= func
.GetLastOriginalArg()
5151 copy_args
= func
.MakeCmdArgString("_", False)
5152 file.Write(" void* Set(void* cmd%s, %s _%s) {\n" %
5153 (func
.MakeTypedCmdArgString("_", True),
5154 last_arg
.type, last_arg
.name
))
5155 file.Write(" static_cast<ValueType*>(cmd)->Init(%s, _%s);\n" %
5156 (copy_args
, last_arg
.name
))
5157 file.Write(" const uint32_t size = ComputeSize();\n")
5158 file.Write(" return NextImmediateCmdAddressTotalSize<ValueType>("
5163 def WriteImmediateCmdHelper(self
, func
, file):
5164 """Overrriden from TypeHandler."""
5165 code
= """ void %(name)s(%(typed_args)s) {
5166 const uint32_t size = gles2::cmds::%(name)s::ComputeSize();
5167 gles2::cmds::%(name)s* c =
5168 GetImmediateCmdSpaceTotalSize<gles2::cmds::%(name)s>(size);
5177 "typed_args": func
.MakeTypedOriginalArgString(""),
5178 "args": func
.MakeOriginalArgString(""),
5181 def WriteImmediateFormatTest(self
, func
, file):
5182 """Overrriden from TypeHandler."""
5183 file.Write("TEST_F(GLES2FormatTest, %s) {\n" % func
.name
)
5184 file.Write(" const int kSomeBaseValueToTestWith = 51;\n")
5185 file.Write(" static %s data[] = {\n" % self
.GetArrayType(func
))
5186 for v
in range(0, self
.GetArrayCount(func
)):
5187 file.Write(" static_cast<%s>(kSomeBaseValueToTestWith + %d),\n" %
5188 (self
.GetArrayType(func
), v
))
5190 file.Write(" cmds::%s& cmd = *GetBufferAs<cmds::%s>();\n" %
5191 (func
.name
, func
.name
))
5192 file.Write(" void* next_cmd = cmd.Set(\n")
5194 args
= func
.GetCmdArgs()
5195 for value
, arg
in enumerate(args
):
5196 file.Write(",\n static_cast<%s>(%d)" % (arg
.type, value
+ 11))
5197 file.Write(",\n data);\n")
5198 args
= func
.GetCmdArgs()
5199 file.Write(" EXPECT_EQ(static_cast<uint32_t>(cmds::%s::kCmdId),\n"
5201 file.Write(" cmd.header.command);\n")
5202 file.Write(" EXPECT_EQ(sizeof(cmd) +\n")
5203 file.Write(" RoundSizeToMultipleOfEntries(sizeof(data)),\n")
5204 file.Write(" cmd.header.size * 4u);\n")
5205 for value
, arg
in enumerate(args
):
5206 file.Write(" EXPECT_EQ(static_cast<%s>(%d), cmd.%s);\n" %
5207 (arg
.type, value
+ 11, arg
.name
))
5208 file.Write(" CheckBytesWrittenMatchesExpectedSize(\n")
5209 file.Write(" next_cmd, sizeof(cmd) +\n")
5210 file.Write(" RoundSizeToMultipleOfEntries(sizeof(data)));\n")
5211 file.Write(" // TODO(gman): Check that data was inserted;\n")
5216 class PUTnHandler(ArrayArgTypeHandler
):
5217 """Handler for PUTn 'glUniform__v' type functions."""
5220 ArrayArgTypeHandler
.__init
__(self
)
5222 def WriteServiceUnitTest(self
, func
, file, *extras
):
5223 """Overridden from TypeHandler."""
5224 ArrayArgTypeHandler
.WriteServiceUnitTest(self
, func
, file, *extras
)
5227 TEST_P(%(test_name)s, %(name)sValidArgsCountTooLarge) {
5228 EXPECT_CALL(*gl_, %(gl_func_name)s(%(gl_args)s));
5229 SpecializedSetup<cmds::%(name)s, 0>(true);
5232 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
5233 EXPECT_EQ(GL_NO_ERROR, GetGLError());
5238 for count
, arg
in enumerate(func
.GetOriginalArgs()):
5239 # hardcoded to match unit tests.
5241 # the location of the second element of the 2nd uniform.
5242 # defined in GLES2DecoderBase::SetupShaderForUniform
5243 gl_arg_strings
.append("3")
5244 arg_strings
.append("ProgramManager::MakeFakeLocation(1, 1)")
5246 # the number of elements that gl will be called with.
5247 gl_arg_strings
.append("3")
5248 # the number of elements requested in the command.
5249 arg_strings
.append("5")
5251 gl_arg_strings
.append(arg
.GetValidGLArg(func
))
5252 if not arg
.IsConstant():
5253 arg_strings
.append(arg
.GetValidArg(func
))
5255 'gl_args': ", ".join(gl_arg_strings
),
5256 'args': ", ".join(arg_strings
),
5258 self
.WriteValidUnitTest(func
, file, valid_test
, extra
, *extras
)
5260 def WriteImmediateServiceUnitTest(self
, func
, file, *extras
):
5261 """Overridden from TypeHandler."""
5263 TEST_P(%(test_name)s, %(name)sValidArgs) {
5264 cmds::%(name)s& cmd = *GetImmediateAs<cmds::%(name)s>();
5267 %(gl_func_name)s(%(gl_args)s,
5268 reinterpret_cast<%(data_type)s*>(ImmediateDataAddress(&cmd))));
5269 SpecializedSetup<cmds::%(name)s, 0>(true);
5270 %(data_type)s temp[%(data_count)s * 2] = { 0, };
5271 cmd.Init(%(args)s, &temp[0]);
5272 EXPECT_EQ(error::kNoError,
5273 ExecuteImmediateCmd(cmd, sizeof(temp)));
5274 EXPECT_EQ(GL_NO_ERROR, GetGLError());
5280 for arg
in func
.GetOriginalArgs()[0:-1]:
5281 gl_arg_strings
.append(arg
.GetValidGLArg(func
))
5282 gl_any_strings
.append("_")
5283 if not arg
.IsConstant():
5284 arg_strings
.append(arg
.GetValidArg(func
))
5286 'data_type': self
.GetArrayType(func
),
5287 'data_count': self
.GetArrayCount(func
),
5288 'args': ", ".join(arg_strings
),
5289 'gl_args': ", ".join(gl_arg_strings
),
5290 'gl_any_args': ", ".join(gl_any_strings
),
5292 self
.WriteValidUnitTest(func
, file, valid_test
, extra
, *extras
)
5295 TEST_P(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) {
5296 cmds::%(name)s& cmd = *GetImmediateAs<cmds::%(name)s>();
5297 EXPECT_CALL(*gl_, %(gl_func_name)s(%(gl_any_args)s, _)).Times(0);
5298 SpecializedSetup<cmds::%(name)s, 0>(false);
5299 %(data_type)s temp[%(data_count)s * 2] = { 0, };
5300 cmd.Init(%(all_but_last_args)s, &temp[0]);
5301 EXPECT_EQ(error::%(parse_result)s,
5302 ExecuteImmediateCmd(cmd, sizeof(temp)));%(gl_error_test)s
5305 self
.WriteInvalidUnitTest(func
, file, invalid_test
, extra
, *extras
)
5307 def WriteGetDataSizeCode(self
, func
, file):
5308 """Overrriden from TypeHandler."""
5309 code
= """ uint32_t data_size;
5310 if (!ComputeDataSize(count, sizeof(%s), %d, &data_size)) {
5311 return error::kOutOfBounds;
5314 file.Write(code
% (self
.GetArrayType(func
), self
.GetArrayCount(func
)))
5315 if func
.IsImmediate():
5316 file.Write(" if (data_size > immediate_data_size) {\n")
5317 file.Write(" return error::kOutOfBounds;\n")
5320 def WriteGLES2Implementation(self
, func
, file):
5321 """Overrriden from TypeHandler."""
5322 file.Write("%s GLES2Implementation::%s(%s) {\n" %
5323 (func
.return_type
, func
.original_name
,
5324 func
.MakeTypedOriginalArgString("")))
5325 file.Write(" GPU_CLIENT_SINGLE_THREAD_CHECK();\n")
5326 func
.WriteDestinationInitalizationValidation(file)
5327 self
.WriteClientGLCallLog(func
, file)
5328 last_arg_name
= func
.GetLastOriginalArg().name
5329 file.Write(""" GPU_CLIENT_LOG_CODE_BLOCK({
5330 for (GLsizei i = 0; i < count; ++i) {
5332 values_str
= ' << ", " << '.join(
5333 ["%s[%d + i * %d]" % (
5334 last_arg_name
, ndx
, self
.GetArrayCount(func
)) for ndx
in range(
5335 0, self
.GetArrayCount(func
))])
5336 file.Write(' GPU_CLIENT_LOG(" " << i << ": " << %s);\n' % values_str
)
5337 file.Write(" }\n });\n")
5338 for arg
in func
.GetOriginalArgs():
5339 arg
.WriteClientSideValidationCode(file, func
)
5340 file.Write(" helper_->%sImmediate(%s);\n" %
5341 (func
.name
, func
.MakeInitString("")))
5342 file.Write(" CheckGLError();\n")
5346 def WriteGLES2ImplementationUnitTest(self
, func
, file):
5347 """Writes the GLES2 Implemention unit test."""
5349 TEST_F(GLES2ImplementationTest, %(name)s) {
5350 %(type)s data[%(count_param)d][%(count)d] = {{0}};
5352 cmds::%(name)sImmediate cmd;
5353 %(type)s data[%(count_param)d][%(count)d];
5357 for (int ii = 0; ii < %(count_param)d; ++ii) {
5358 for (int jj = 0; jj < %(count)d; ++jj) {
5359 data[ii][jj] = static_cast<%(type)s>(ii * %(count)d + jj);
5362 expected.cmd.Init(%(cmd_args)s, &data[0][0]);
5363 gl_->%(name)s(%(args)s, &data[0][0]);
5364 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected)));
5368 arg
.GetValidClientSideCmdArg(func
) for arg
in func
.GetCmdArgs()[0:-2]
5372 for arg
in func
.GetOriginalArgs()[0:-1]:
5373 valid_value
= arg
.GetValidClientSideArg(func
)
5374 gl_arg_strings
.append(valid_value
)
5375 if arg
.name
== "count":
5376 count_param
= int(valid_value
)
5379 'type': self
.GetArrayType(func
),
5380 'count': self
.GetArrayCount(func
),
5381 'args': ", ".join(gl_arg_strings
),
5382 'cmd_args': ", ".join(cmd_arg_strings
),
5383 'count_param': count_param
,
5386 # Test constants for invalid values, as they are not tested by the
5389 arg
for arg
in func
.GetOriginalArgs()[0:-1] if arg
.IsConstant()
5395 TEST_F(GLES2ImplementationTest, %(name)sInvalidConstantArg%(invalid_index)d) {
5396 %(type)s data[%(count_param)d][%(count)d] = {{0}};
5397 for (int ii = 0; ii < %(count_param)d; ++ii) {
5398 for (int jj = 0; jj < %(count)d; ++jj) {
5399 data[ii][jj] = static_cast<%(type)s>(ii * %(count)d + jj);
5402 gl_->%(name)s(%(args)s, &data[0][0]);
5403 EXPECT_TRUE(NoCommandsWritten());
5404 EXPECT_EQ(%(gl_error)s, CheckError());
5407 for invalid_arg
in constants
:
5409 invalid
= invalid_arg
.GetInvalidArg(func
)
5410 for arg
in func
.GetOriginalArgs()[0:-1]:
5411 if arg
is invalid_arg
:
5412 gl_arg_strings
.append(invalid
[0])
5414 valid_value
= arg
.GetValidClientSideArg(func
)
5415 gl_arg_strings
.append(valid_value
)
5416 if arg
.name
== "count":
5417 count_param
= int(valid_value
)
5421 'invalid_index': func
.GetOriginalArgs().index(invalid_arg
),
5422 'type': self
.GetArrayType(func
),
5423 'count': self
.GetArrayCount(func
),
5424 'args': ", ".join(gl_arg_strings
),
5425 'gl_error': invalid
[2],
5426 'count_param': count_param
,
5430 def WriteImmediateCmdComputeSize(self
, func
, file):
5431 """Overrriden from TypeHandler."""
5432 file.Write(" static uint32_t ComputeDataSize(GLsizei count) {\n")
5433 file.Write(" return static_cast<uint32_t>(\n")
5434 file.Write(" sizeof(%s) * %d * count); // NOLINT\n" %
5435 (self
.GetArrayType(func
), self
.GetArrayCount(func
)))
5438 file.Write(" static uint32_t ComputeSize(GLsizei count) {\n")
5439 file.Write(" return static_cast<uint32_t>(\n")
5441 " sizeof(ValueType) + ComputeDataSize(count)); // NOLINT\n")
5445 def WriteImmediateCmdSetHeader(self
, func
, file):
5446 """Overrriden from TypeHandler."""
5447 file.Write(" void SetHeader(GLsizei count) {\n")
5449 " header.SetCmdByTotalSize<ValueType>(ComputeSize(count));\n")
5453 def WriteImmediateCmdInit(self
, func
, file):
5454 """Overrriden from TypeHandler."""
5455 last_arg
= func
.GetLastOriginalArg()
5456 file.Write(" void Init(%s, %s _%s) {\n" %
5457 (func
.MakeTypedCmdArgString("_"),
5458 last_arg
.type, last_arg
.name
))
5459 file.Write(" SetHeader(_count);\n")
5460 args
= func
.GetCmdArgs()
5462 file.Write(" %s = _%s;\n" % (arg
.name
, arg
.name
))
5463 file.Write(" memcpy(ImmediateDataAddress(this),\n")
5464 file.Write(" _%s, ComputeDataSize(_count));\n" % last_arg
.name
)
5468 def WriteImmediateCmdSet(self
, func
, file):
5469 """Overrriden from TypeHandler."""
5470 last_arg
= func
.GetLastOriginalArg()
5471 copy_args
= func
.MakeCmdArgString("_", False)
5472 file.Write(" void* Set(void* cmd%s, %s _%s) {\n" %
5473 (func
.MakeTypedCmdArgString("_", True),
5474 last_arg
.type, last_arg
.name
))
5475 file.Write(" static_cast<ValueType*>(cmd)->Init(%s, _%s);\n" %
5476 (copy_args
, last_arg
.name
))
5477 file.Write(" const uint32_t size = ComputeSize(_count);\n")
5478 file.Write(" return NextImmediateCmdAddressTotalSize<ValueType>("
5483 def WriteImmediateCmdHelper(self
, func
, file):
5484 """Overrriden from TypeHandler."""
5485 code
= """ void %(name)s(%(typed_args)s) {
5486 const uint32_t size = gles2::cmds::%(name)s::ComputeSize(count);
5487 gles2::cmds::%(name)s* c =
5488 GetImmediateCmdSpaceTotalSize<gles2::cmds::%(name)s>(size);
5497 "typed_args": func
.MakeTypedInitString(""),
5498 "args": func
.MakeInitString("")
5501 def WriteImmediateFormatTest(self
, func
, file):
5502 """Overrriden from TypeHandler."""
5503 args
= func
.GetCmdArgs()
5506 if arg
.name
== "count":
5507 count_param
= int(arg
.GetValidClientSideCmdArg(func
))
5508 file.Write("TEST_F(GLES2FormatTest, %s) {\n" % func
.name
)
5509 file.Write(" const int kSomeBaseValueToTestWith = 51;\n")
5510 file.Write(" static %s data[] = {\n" % self
.GetArrayType(func
))
5511 for v
in range(0, self
.GetArrayCount(func
) * count_param
):
5512 file.Write(" static_cast<%s>(kSomeBaseValueToTestWith + %d),\n" %
5513 (self
.GetArrayType(func
), v
))
5515 file.Write(" cmds::%s& cmd = *GetBufferAs<cmds::%s>();\n" %
5516 (func
.name
, func
.name
))
5517 file.Write(" const GLsizei kNumElements = %d;\n" % count_param
)
5518 file.Write(" const size_t kExpectedCmdSize =\n")
5519 file.Write(" sizeof(cmd) + kNumElements * sizeof(%s) * %d;\n" %
5520 (self
.GetArrayType(func
), self
.GetArrayCount(func
)))
5521 file.Write(" void* next_cmd = cmd.Set(\n")
5523 for value
, arg
in enumerate(args
):
5524 file.Write(",\n static_cast<%s>(%d)" % (arg
.type, value
+ 1))
5525 file.Write(",\n data);\n")
5526 file.Write(" EXPECT_EQ(static_cast<uint32_t>(cmds::%s::kCmdId),\n" %
5528 file.Write(" cmd.header.command);\n")
5529 file.Write(" EXPECT_EQ(kExpectedCmdSize, cmd.header.size * 4u);\n")
5530 for value
, arg
in enumerate(args
):
5531 file.Write(" EXPECT_EQ(static_cast<%s>(%d), cmd.%s);\n" %
5532 (arg
.type, value
+ 1, arg
.name
))
5533 file.Write(" CheckBytesWrittenMatchesExpectedSize(\n")
5534 file.Write(" next_cmd, sizeof(cmd) +\n")
5535 file.Write(" RoundSizeToMultipleOfEntries(sizeof(data)));\n")
5536 file.Write(" // TODO(gman): Check that data was inserted;\n")
5541 class PUTXnHandler(ArrayArgTypeHandler
):
5542 """Handler for glUniform?f functions."""
5544 ArrayArgTypeHandler
.__init
__(self
)
5546 def WriteHandlerImplementation(self
, func
, file):
5547 """Overrriden from TypeHandler."""
5548 code
= """ %(type)s temp[%(count)s] = { %(values)s};
5549 Do%(name)sv(%(location)s, 1, &temp[0]);
5552 args
= func
.GetOriginalArgs()
5553 count
= int(self
.GetArrayCount(func
))
5554 num_args
= len(args
)
5555 for ii
in range(count
):
5556 values
+= "%s, " % args
[len(args
) - count
+ ii
].name
5560 'count': self
.GetArrayCount(func
),
5561 'type': self
.GetArrayType(func
),
5562 'location': args
[0].name
,
5563 'args': func
.MakeOriginalArgString(""),
5567 def WriteServiceUnitTest(self
, func
, file, *extras
):
5568 """Overrriden from TypeHandler."""
5570 TEST_P(%(test_name)s, %(name)sValidArgs) {
5571 EXPECT_CALL(*gl_, %(name)sv(%(local_args)s));
5572 SpecializedSetup<cmds::%(name)s, 0>(true);
5575 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
5576 EXPECT_EQ(GL_NO_ERROR, GetGLError());
5579 args
= func
.GetOriginalArgs()
5580 local_args
= "%s, 1, _" % args
[0].GetValidGLArg(func
)
5581 self
.WriteValidUnitTest(func
, file, valid_test
, {
5583 'count': self
.GetArrayCount(func
),
5584 'local_args': local_args
,
5588 TEST_P(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) {
5589 EXPECT_CALL(*gl_, %(name)sv(_, _, _).Times(0);
5590 SpecializedSetup<cmds::%(name)s, 0>(false);
5593 EXPECT_EQ(error::%(parse_result)s, ExecuteCmd(cmd));%(gl_error_test)s
5596 self
.WriteInvalidUnitTest(func
, file, invalid_test
, {
5597 'name': func
.GetInfo('name'),
5598 'count': self
.GetArrayCount(func
),
5602 class GLcharHandler(CustomHandler
):
5603 """Handler for functions that pass a single string ."""
5606 CustomHandler
.__init
__(self
)
5608 def WriteImmediateCmdComputeSize(self
, func
, file):
5609 """Overrriden from TypeHandler."""
5610 file.Write(" static uint32_t ComputeSize(uint32_t data_size) {\n")
5611 file.Write(" return static_cast<uint32_t>(\n")
5612 file.Write(" sizeof(ValueType) + data_size); // NOLINT\n")
5615 def WriteImmediateCmdSetHeader(self
, func
, file):
5616 """Overrriden from TypeHandler."""
5618 void SetHeader(uint32_t data_size) {
5619 header.SetCmdBySize<ValueType>(data_size);
5624 def WriteImmediateCmdInit(self
, func
, file):
5625 """Overrriden from TypeHandler."""
5626 last_arg
= func
.GetLastOriginalArg()
5627 args
= func
.GetCmdArgs()
5630 set_code
.append(" %s = _%s;" % (arg
.name
, arg
.name
))
5632 void Init(%(typed_args)s, uint32_t _data_size) {
5633 SetHeader(_data_size);
5635 memcpy(ImmediateDataAddress(this), _%(last_arg)s, _data_size);
5640 "typed_args": func
.MakeTypedArgString("_"),
5641 "set_code": "\n".join(set_code
),
5642 "last_arg": last_arg
.name
5645 def WriteImmediateCmdSet(self
, func
, file):
5646 """Overrriden from TypeHandler."""
5647 last_arg
= func
.GetLastOriginalArg()
5648 file.Write(" void* Set(void* cmd%s, uint32_t _data_size) {\n" %
5649 func
.MakeTypedCmdArgString("_", True))
5650 file.Write(" static_cast<ValueType*>(cmd)->Init(%s, _data_size);\n" %
5651 func
.MakeCmdArgString("_"))
5652 file.Write(" return NextImmediateCmdAddress<ValueType>("
5653 "cmd, _data_size);\n")
5657 def WriteImmediateCmdHelper(self
, func
, file):
5658 """Overrriden from TypeHandler."""
5659 code
= """ void %(name)s(%(typed_args)s) {
5660 const uint32_t data_size = strlen(name);
5661 gles2::cmds::%(name)s* c =
5662 GetImmediateCmdSpace<gles2::cmds::%(name)s>(data_size);
5664 c->Init(%(args)s, data_size);
5671 "typed_args": func
.MakeTypedOriginalArgString(""),
5672 "args": func
.MakeOriginalArgString(""),
5676 def WriteImmediateFormatTest(self
, func
, file):
5677 """Overrriden from TypeHandler."""
5680 all_but_last_arg
= func
.GetCmdArgs()[:-1]
5681 for value
, arg
in enumerate(all_but_last_arg
):
5682 init_code
.append(" static_cast<%s>(%d)," % (arg
.type, value
+ 11))
5683 for value
, arg
in enumerate(all_but_last_arg
):
5684 check_code
.append(" EXPECT_EQ(static_cast<%s>(%d), cmd.%s);" %
5685 (arg
.type, value
+ 11, arg
.name
))
5687 TEST_F(GLES2FormatTest, %(func_name)s) {
5688 cmds::%(func_name)s& cmd = *GetBufferAs<cmds::%(func_name)s>();
5689 static const char* const test_str = \"test string\";
5690 void* next_cmd = cmd.Set(
5695 EXPECT_EQ(static_cast<uint32_t>(cmds::%(func_name)s::kCmdId),
5696 cmd.header.command);
5697 EXPECT_EQ(sizeof(cmd) +
5698 RoundSizeToMultipleOfEntries(strlen(test_str)),
5699 cmd.header.size * 4u);
5700 EXPECT_EQ(static_cast<char*>(next_cmd),
5701 reinterpret_cast<char*>(&cmd) + sizeof(cmd) +
5702 RoundSizeToMultipleOfEntries(strlen(test_str)));
5704 EXPECT_EQ(static_cast<uint32_t>(strlen(test_str)), cmd.data_size);
5705 EXPECT_EQ(0, memcmp(test_str, ImmediateDataAddress(&cmd), strlen(test_str)));
5708 sizeof(cmd) + RoundSizeToMultipleOfEntries(strlen(test_str)),
5709 sizeof(cmd) + strlen(test_str));
5714 'func_name': func
.name
,
5715 'init_code': "\n".join(init_code
),
5716 'check_code': "\n".join(check_code
),
5720 class GLcharNHandler(CustomHandler
):
5721 """Handler for functions that pass a single string with an optional len."""
5724 CustomHandler
.__init
__(self
)
5726 def InitFunction(self
, func
):
5727 """Overrriden from TypeHandler."""
5729 func
.AddCmdArg(Argument('bucket_id', 'GLuint'))
5731 def NeedsDataTransferFunction(self
, func
):
5732 """Overriden from TypeHandler."""
5735 def AddBucketFunction(self
, generator
, func
):
5736 """Overrriden from TypeHandler."""
5739 def WriteServiceImplementation(self
, func
, file):
5740 """Overrriden from TypeHandler."""
5741 self
.WriteServiceHandlerFunctionHeader(func
, file)
5743 GLuint bucket_id = static_cast<GLuint>(c.%(bucket_id)s);
5744 Bucket* bucket = GetBucket(bucket_id);
5745 if (!bucket || bucket->size() == 0) {
5746 return error::kInvalidArguments;
5749 if (!bucket->GetAsString(&str)) {
5750 return error::kInvalidArguments;
5752 %(gl_func_name)s(0, str.c_str());
5753 return error::kNoError;
5758 'gl_func_name': func
.GetGLFunctionName(),
5759 'bucket_id': func
.cmd_args
[0].name
,
5763 class IsHandler(TypeHandler
):
5764 """Handler for glIs____ type and glGetError functions."""
5767 TypeHandler
.__init
__(self
)
5769 def InitFunction(self
, func
):
5770 """Overrriden from TypeHandler."""
5771 func
.AddCmdArg(Argument("result_shm_id", 'uint32_t'))
5772 func
.AddCmdArg(Argument("result_shm_offset", 'uint32_t'))
5773 if func
.GetInfo('result') == None:
5774 func
.AddInfo('result', ['uint32_t'])
5776 def WriteServiceUnitTest(self
, func
, file, *extras
):
5777 """Overrriden from TypeHandler."""
5779 TEST_P(%(test_name)s, %(name)sValidArgs) {
5780 EXPECT_CALL(*gl_, %(gl_func_name)s(%(gl_args)s));
5781 SpecializedSetup<cmds::%(name)s, 0>(true);
5783 cmd.Init(%(args)s%(comma)sshared_memory_id_, shared_memory_offset_);
5784 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
5785 EXPECT_EQ(GL_NO_ERROR, GetGLError());
5789 if len(func
.GetOriginalArgs()):
5791 self
.WriteValidUnitTest(func
, file, valid_test
, {
5796 TEST_P(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) {
5797 EXPECT_CALL(*gl_, %(gl_func_name)s(%(gl_args)s)).Times(0);
5798 SpecializedSetup<cmds::%(name)s, 0>(false);
5800 cmd.Init(%(args)s%(comma)sshared_memory_id_, shared_memory_offset_);
5801 EXPECT_EQ(error::%(parse_result)s, ExecuteCmd(cmd));%(gl_error_test)s
5804 self
.WriteInvalidUnitTest(func
, file, invalid_test
, {
5809 TEST_P(%(test_name)s, %(name)sInvalidArgsBadSharedMemoryId) {
5810 EXPECT_CALL(*gl_, %(gl_func_name)s(%(gl_args)s)).Times(0);
5811 SpecializedSetup<cmds::%(name)s, 0>(false);
5813 cmd.Init(%(args)s%(comma)skInvalidSharedMemoryId, shared_memory_offset_);
5814 EXPECT_EQ(error::kOutOfBounds, ExecuteCmd(cmd));
5815 cmd.Init(%(args)s%(comma)sshared_memory_id_, kInvalidSharedMemoryOffset);
5816 EXPECT_EQ(error::kOutOfBounds, ExecuteCmd(cmd));
5819 self
.WriteValidUnitTest(func
, file, invalid_test
, {
5823 def WriteServiceImplementation(self
, func
, file):
5824 """Overrriden from TypeHandler."""
5825 self
.WriteServiceHandlerFunctionHeader(func
, file)
5826 args
= func
.GetOriginalArgs()
5828 arg
.WriteGetCode(file)
5830 code
= """ typedef cmds::%(func_name)s::Result Result;
5831 Result* result_dst = GetSharedMemoryAs<Result*>(
5832 c.result_shm_id, c.result_shm_offset, sizeof(*result_dst));
5834 return error::kOutOfBounds;
5837 file.Write(code
% {'func_name': func
.name
})
5838 func
.WriteHandlerValidation(file)
5839 file.Write(" *result_dst = %s(%s);\n" %
5840 (func
.GetGLFunctionName(), func
.MakeOriginalArgString("")))
5841 file.Write(" return error::kNoError;\n")
5845 def WriteGLES2Implementation(self
, func
, file):
5846 """Overrriden from TypeHandler."""
5847 impl_func
= func
.GetInfo('impl_func')
5848 if impl_func
== None or impl_func
== True:
5849 error_value
= func
.GetInfo("error_value") or "GL_FALSE"
5850 file.Write("%s GLES2Implementation::%s(%s) {\n" %
5851 (func
.return_type
, func
.original_name
,
5852 func
.MakeTypedOriginalArgString("")))
5853 file.Write(" GPU_CLIENT_SINGLE_THREAD_CHECK();\n")
5854 self
.WriteTraceEvent(func
, file)
5855 func
.WriteDestinationInitalizationValidation(file)
5856 self
.WriteClientGLCallLog(func
, file)
5857 file.Write(" typedef cmds::%s::Result Result;\n" % func
.name
)
5858 file.Write(" Result* result = GetResultAs<Result*>();\n")
5859 file.Write(" if (!result) {\n")
5860 file.Write(" return %s;\n" % error_value
)
5862 file.Write(" *result = 0;\n")
5863 arg_string
= func
.MakeOriginalArgString("")
5865 if len(arg_string
) > 0:
5868 " helper_->%s(%s%sGetResultShmId(), GetResultShmOffset());\n" %
5869 (func
.name
, arg_string
, comma
))
5870 file.Write(" WaitForCmd();\n")
5871 file.Write(" %s result_value = *result;\n" % func
.return_type
)
5872 file.Write(' GPU_CLIENT_LOG("returned " << result_value);\n')
5873 file.Write(" CheckGLError();\n")
5874 file.Write(" return result_value;\n")
5878 def WriteGLES2ImplementationUnitTest(self
, func
, file):
5879 """Overrriden from TypeHandler."""
5880 client_test
= func
.GetInfo('client_test')
5881 if client_test
== None or client_test
== True:
5883 TEST_F(GLES2ImplementationTest, %(name)s) {
5889 ExpectedMemoryInfo result1 =
5890 GetExpectedResultMemory(sizeof(cmds::%(name)s::Result));
5891 expected.cmd.Init(1, result1.id, result1.offset);
5893 EXPECT_CALL(*command_buffer(), OnFlush())
5894 .WillOnce(SetMemory(result1.ptr, uint32_t(1)))
5895 .RetiresOnSaturation();
5897 GLboolean result = gl_->%(name)s(1);
5898 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected)));
5899 EXPECT_TRUE(result);
5907 class STRnHandler(TypeHandler
):
5908 """Handler for GetProgramInfoLog, GetShaderInfoLog, GetShaderSource, and
5909 GetTranslatedShaderSourceANGLE."""
5912 TypeHandler
.__init
__(self
)
5914 def InitFunction(self
, func
):
5915 """Overrriden from TypeHandler."""
5916 # remove all but the first cmd args.
5917 cmd_args
= func
.GetCmdArgs()
5919 func
.AddCmdArg(cmd_args
[0])
5920 # add on a bucket id.
5921 func
.AddCmdArg(Argument('bucket_id', 'uint32_t'))
5923 def WriteGLES2Implementation(self
, func
, file):
5924 """Overrriden from TypeHandler."""
5925 code_1
= """%(return_type)s GLES2Implementation::%(func_name)s(%(args)s) {
5926 GPU_CLIENT_SINGLE_THREAD_CHECK();
5928 code_2
= """ GPU_CLIENT_LOG("[" << GetLogPrefix()
5929 << "] gl%(func_name)s" << "("
5932 << static_cast<void*>(%(arg2)s) << ", "
5933 << static_cast<void*>(%(arg3)s) << ")");
5934 helper_->SetBucketSize(kResultBucketId, 0);
5935 helper_->%(func_name)s(%(id_name)s, kResultBucketId);
5937 GLsizei max_size = 0;
5938 if (GetBucketAsString(kResultBucketId, &str)) {
5941 std::min(static_cast<size_t>(%(bufsize_name)s) - 1, str.size());
5942 memcpy(%(dest_name)s, str.c_str(), max_size);
5943 %(dest_name)s[max_size] = '\\0';
5944 GPU_CLIENT_LOG("------\\n" << %(dest_name)s << "\\n------");
5947 if (%(length_name)s != NULL) {
5948 *%(length_name)s = max_size;
5953 args
= func
.GetOriginalArgs()
5955 'return_type': func
.return_type
,
5956 'func_name': func
.original_name
,
5957 'args': func
.MakeTypedOriginalArgString(""),
5958 'id_name': args
[0].name
,
5959 'bufsize_name': args
[1].name
,
5960 'length_name': args
[2].name
,
5961 'dest_name': args
[3].name
,
5962 'arg0': args
[0].name
,
5963 'arg1': args
[1].name
,
5964 'arg2': args
[2].name
,
5965 'arg3': args
[3].name
,
5967 file.Write(code_1
% str_args
)
5968 func
.WriteDestinationInitalizationValidation(file)
5969 file.Write(code_2
% str_args
)
5971 def WriteServiceUnitTest(self
, func
, file, *extras
):
5972 """Overrriden from TypeHandler."""
5974 TEST_P(%(test_name)s, %(name)sValidArgs) {
5975 const char* kInfo = "hello";
5976 const uint32_t kBucketId = 123;
5977 SpecializedSetup<cmds::%(name)s, 0>(true);
5979 EXPECT_CALL(*gl_, %(gl_func_name)s(%(gl_args)s))
5980 .WillOnce(DoAll(SetArgumentPointee<2>(strlen(kInfo)),
5981 SetArrayArgument<3>(kInfo, kInfo + strlen(kInfo) + 1)));
5984 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
5985 CommonDecoder::Bucket* bucket = decoder_->GetBucket(kBucketId);
5986 ASSERT_TRUE(bucket != NULL);
5987 EXPECT_EQ(strlen(kInfo) + 1, bucket->size());
5988 EXPECT_EQ(0, memcmp(bucket->GetData(0, bucket->size()), kInfo,
5990 EXPECT_EQ(GL_NO_ERROR, GetGLError());
5993 args
= func
.GetOriginalArgs()
5994 id_name
= args
[0].GetValidGLArg(func
)
5995 get_len_func
= func
.GetInfo('get_len_func')
5996 get_len_enum
= func
.GetInfo('get_len_enum')
5999 'get_len_func': get_len_func
,
6000 'get_len_enum': get_len_enum
,
6001 'gl_args': '%s, strlen(kInfo) + 1, _, _' %
6002 args
[0].GetValidGLArg(func
),
6003 'args': '%s, kBucketId' % args
[0].GetValidArg(func
),
6004 'expect_len_code': '',
6006 if get_len_func
and get_len_func
[0:2] == 'gl':
6007 sub
['expect_len_code'] = (
6008 " EXPECT_CALL(*gl_, %s(%s, %s, _))\n"
6009 " .WillOnce(SetArgumentPointee<2>(strlen(kInfo) + 1));") % (
6010 get_len_func
[2:], id_name
, get_len_enum
)
6011 self
.WriteValidUnitTest(func
, file, valid_test
, sub
, *extras
)
6014 TEST_P(%(test_name)s, %(name)sInvalidArgs) {
6015 const uint32_t kBucketId = 123;
6016 EXPECT_CALL(*gl_, %(gl_func_name)s(_, _, _, _))
6019 cmd.Init(kInvalidClientId, kBucketId);
6020 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
6021 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
6024 self
.WriteValidUnitTest(func
, file, invalid_test
, *extras
)
6026 def WriteServiceImplementation(self
, func
, file):
6027 """Overrriden from TypeHandler."""
6030 class NamedType(object):
6031 """A class that represents a type of an argument in a client function.
6033 A type of an argument that is to be passed through in the command buffer
6034 command. Currently used only for the arguments that are specificly named in
6035 the 'cmd_buffer_functions.txt' file, mostly enums.
6038 def __init__(self
, info
):
6039 assert not 'is_complete' in info
or info
['is_complete'] == True
6041 self
.valid
= info
['valid']
6042 if 'invalid' in info
:
6043 self
.invalid
= info
['invalid']
6048 return self
.info
['type']
6050 def GetInvalidValues(self
):
6053 def GetValidValues(self
):
6056 def IsConstant(self
):
6057 if not 'is_complete' in self
.info
:
6060 return len(self
.GetValidValues()) == 1
6062 def GetConstantValue(self
):
6063 return self
.GetValidValues()[0]
6065 class Argument(object):
6066 """A class that represents a function argument."""
6069 'GLenum': 'uint32_t',
6071 'GLintptr': 'int32_t',
6072 'GLsizei': 'int32_t',
6073 'GLsizeiptr': 'int32_t',
6075 'GLclampf': 'float',
6077 need_validation_
= ['GLsizei*', 'GLboolean*', 'GLenum*', 'GLint*']
6079 def __init__(self
, name
, type):
6081 self
.optional
= type.endswith("Optional*")
6083 type = type[:-9] + "*"
6086 if type in self
.cmd_type_map_
:
6087 self
.cmd_type
= self
.cmd_type_map_
[type]
6089 self
.cmd_type
= 'uint32_t'
6091 def IsPointer(self
):
6092 """Returns true if argument is a pointer."""
6095 def IsConstant(self
):
6096 """Returns true if the argument has only one valid value."""
6099 def AddCmdArgs(self
, args
):
6100 """Adds command arguments for this argument to the given list."""
6101 if not self
.IsConstant():
6102 return args
.append(self
)
6104 def AddInitArgs(self
, args
):
6105 """Adds init arguments for this argument to the given list."""
6106 if not self
.IsConstant():
6107 return args
.append(self
)
6109 def GetValidArg(self
, func
):
6110 """Gets a valid value for this argument."""
6111 valid_arg
= func
.GetValidArg(self
)
6112 if valid_arg
!= None:
6115 index
= func
.GetOriginalArgs().index(self
)
6116 return str(index
+ 1)
6118 def GetValidClientSideArg(self
, func
):
6119 """Gets a valid value for this argument."""
6120 valid_arg
= func
.GetValidArg(self
)
6121 if valid_arg
!= None:
6124 index
= func
.GetOriginalArgs().index(self
)
6125 return str(index
+ 1)
6127 def GetValidClientSideCmdArg(self
, func
):
6128 """Gets a valid value for this argument."""
6129 valid_arg
= func
.GetValidArg(self
)
6130 if valid_arg
!= None:
6133 index
= func
.GetOriginalArgs().index(self
)
6134 return str(index
+ 1)
6137 index
= func
.GetCmdArgs().index(self
)
6138 return str(index
+ 1)
6140 def GetValidGLArg(self
, func
):
6141 """Gets a valid GL value for this argument."""
6142 return self
.GetValidArg(func
)
6144 def GetValidNonCachedClientSideArg(self
, func
):
6145 """Returns a valid value for this argument in a GL call.
6146 Using the value will produce a command buffer service invocation.
6147 Returns None if there is no such value."""
6150 def GetValidNonCachedClientSideCmdArg(self
, func
):
6151 """Returns a valid value for this argument in a command buffer command.
6152 Calling the GL function with the value returned by
6153 GetValidNonCachedClientSideArg will result in a command buffer command
6154 that contains the value returned by this function. """
6157 def GetNumInvalidValues(self
, func
):
6158 """returns the number of invalid values to be tested."""
6161 def GetInvalidArg(self
, index
):
6162 """returns an invalid value and expected parse result by index."""
6163 return ("---ERROR0---", "---ERROR2---", None)
6165 def GetLogArg(self
):
6166 """Get argument appropriate for LOG macro."""
6167 if self
.type == 'GLboolean':
6168 return 'GLES2Util::GetStringBool(%s)' % self
.name
6169 if self
.type == 'GLenum':
6170 return 'GLES2Util::GetStringEnum(%s)' % self
.name
6173 def WriteGetCode(self
, file):
6174 """Writes the code to get an argument from a command structure."""
6175 file.Write(" %s %s = static_cast<%s>(c.%s);\n" %
6176 (self
.type, self
.name
, self
.type, self
.name
))
6178 def WriteValidationCode(self
, file, func
):
6179 """Writes the validation code for an argument."""
6182 def WriteClientSideValidationCode(self
, file, func
):
6183 """Writes the validation code for an argument."""
6186 def WriteDestinationInitalizationValidation(self
, file, func
):
6187 """Writes the client side destintion initialization validation."""
6190 def WriteDestinationInitalizationValidatationIfNeeded(self
, file, func
):
6191 """Writes the client side destintion initialization validation if needed."""
6192 parts
= self
.type.split(" ")
6195 if parts
[0] in self
.need_validation_
:
6197 " GPU_CLIENT_VALIDATE_DESTINATION_%sINITALIZATION(%s, %s);\n" %
6198 ("OPTIONAL_" if self
.optional
else "", self
.type[:-1], self
.name
))
6201 def WriteGetAddress(self
, file):
6202 """Writes the code to get the address this argument refers to."""
6205 def GetImmediateVersion(self
):
6206 """Gets the immediate version of this argument."""
6209 def GetBucketVersion(self
):
6210 """Gets the bucket version of this argument."""
6214 class BoolArgument(Argument
):
6215 """class for GLboolean"""
6217 def __init__(self
, name
, type):
6218 Argument
.__init
__(self
, name
, 'GLboolean')
6220 def GetValidArg(self
, func
):
6221 """Gets a valid value for this argument."""
6224 def GetValidClientSideArg(self
, func
):
6225 """Gets a valid value for this argument."""
6228 def GetValidClientSideCmdArg(self
, func
):
6229 """Gets a valid value for this argument."""
6232 def GetValidGLArg(self
, func
):
6233 """Gets a valid GL value for this argument."""
6237 class UniformLocationArgument(Argument
):
6238 """class for uniform locations."""
6240 def __init__(self
, name
):
6241 Argument
.__init
__(self
, name
, "GLint")
6243 def WriteGetCode(self
, file):
6244 """Writes the code to get an argument from a command structure."""
6245 code
= """ %s %s = static_cast<%s>(c.%s);
6247 file.Write(code
% (self
.type, self
.name
, self
.type, self
.name
))
6249 class DataSizeArgument(Argument
):
6250 """class for data_size which Bucket commands do not need."""
6252 def __init__(self
, name
):
6253 Argument
.__init
__(self
, name
, "uint32_t")
6255 def GetBucketVersion(self
):
6259 class SizeArgument(Argument
):
6260 """class for GLsizei and GLsizeiptr."""
6262 def __init__(self
, name
, type):
6263 Argument
.__init
__(self
, name
, type)
6265 def GetNumInvalidValues(self
, func
):
6266 """overridden from Argument."""
6267 if func
.IsImmediate():
6271 def GetInvalidArg(self
, index
):
6272 """overridden from Argument."""
6273 return ("-1", "kNoError", "GL_INVALID_VALUE")
6275 def WriteValidationCode(self
, file, func
):
6276 """overridden from Argument."""
6277 file.Write(" if (%s < 0) {\n" % self
.name
)
6279 " LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, \"gl%s\", \"%s < 0\");\n" %
6280 (func
.original_name
, self
.name
))
6281 file.Write(" return error::kNoError;\n")
6284 def WriteClientSideValidationCode(self
, file, func
):
6285 """overridden from Argument."""
6286 file.Write(" if (%s < 0) {\n" % self
.name
)
6288 " SetGLError(GL_INVALID_VALUE, \"gl%s\", \"%s < 0\");\n" %
6289 (func
.original_name
, self
.name
))
6290 file.Write(" return;\n")
6294 class SizeNotNegativeArgument(SizeArgument
):
6295 """class for GLsizeiNotNegative. It's NEVER allowed to be negative"""
6297 def __init__(self
, name
, type, gl_type
):
6298 SizeArgument
.__init
__(self
, name
, gl_type
)
6300 def GetInvalidArg(self
, index
):
6301 """overridden from SizeArgument."""
6302 return ("-1", "kOutOfBounds", "GL_NO_ERROR")
6304 def WriteValidationCode(self
, file, func
):
6305 """overridden from SizeArgument."""
6309 class EnumBaseArgument(Argument
):
6310 """Base class for EnumArgument, IntArgument and ValidatedBoolArgument"""
6312 def __init__(self
, name
, gl_type
, type, gl_error
):
6313 Argument
.__init
__(self
, name
, gl_type
)
6315 self
.local_type
= type
6316 self
.gl_error
= gl_error
6317 name
= type[len(gl_type
):]
6318 self
.type_name
= name
6319 self
.named_type
= NamedType(_NAMED_TYPE_INFO
[name
])
6321 def IsConstant(self
):
6322 return self
.named_type
.IsConstant()
6324 def GetConstantValue(self
):
6325 return self
.named_type
.GetConstantValue()
6327 def WriteValidationCode(self
, file, func
):
6328 if self
.named_type
.IsConstant():
6330 file.Write(" if (!validators_->%s.IsValid(%s)) {\n" %
6331 (ToUnderscore(self
.type_name
), self
.name
))
6332 if self
.gl_error
== "GL_INVALID_ENUM":
6334 " LOCAL_SET_GL_ERROR_INVALID_ENUM(\"gl%s\", %s, \"%s\");\n" %
6335 (func
.original_name
, self
.name
, self
.name
))
6338 " LOCAL_SET_GL_ERROR(%s, \"gl%s\", \"%s %s\");\n" %
6339 (self
.gl_error
, func
.original_name
, self
.name
, self
.gl_error
))
6340 file.Write(" return error::kNoError;\n")
6343 def WriteClientSideValidationCode(self
, file, func
):
6344 if not self
.named_type
.IsConstant():
6346 file.Write(" if (%s != %s) {" % (self
.name
,
6347 self
.GetConstantValue()))
6349 " SetGLError(%s, \"gl%s\", \"%s %s\");\n" %
6350 (self
.gl_error
, func
.original_name
, self
.name
, self
.gl_error
))
6351 if func
.return_type
== "void":
6352 file.Write(" return;\n")
6354 file.Write(" return %s;\n" % func
.GetErrorReturnString())
6357 def GetValidArg(self
, func
):
6358 valid_arg
= func
.GetValidArg(self
)
6359 if valid_arg
!= None:
6361 valid
= self
.named_type
.GetValidValues()
6363 num_valid
= len(valid
)
6366 index
= func
.GetOriginalArgs().index(self
)
6367 return str(index
+ 1)
6369 def GetValidClientSideArg(self
, func
):
6370 """Gets a valid value for this argument."""
6371 return self
.GetValidArg(func
)
6373 def GetValidClientSideCmdArg(self
, func
):
6374 """Gets a valid value for this argument."""
6375 valid_arg
= func
.GetValidArg(self
)
6376 if valid_arg
!= None:
6379 valid
= self
.named_type
.GetValidValues()
6381 num_valid
= len(valid
)
6385 index
= func
.GetOriginalArgs().index(self
)
6386 return str(index
+ 1)
6389 index
= func
.GetCmdArgs().index(self
)
6390 return str(index
+ 1)
6392 def GetValidGLArg(self
, func
):
6393 """Gets a valid value for this argument."""
6394 return self
.GetValidArg(func
)
6396 def GetNumInvalidValues(self
, func
):
6397 """returns the number of invalid values to be tested."""
6398 return len(self
.named_type
.GetInvalidValues())
6400 def GetInvalidArg(self
, index
):
6401 """returns an invalid value by index."""
6402 invalid
= self
.named_type
.GetInvalidValues()
6404 num_invalid
= len(invalid
)
6405 if index
>= num_invalid
:
6406 index
= num_invalid
- 1
6407 return (invalid
[index
], "kNoError", self
.gl_error
)
6408 return ("---ERROR1---", "kNoError", self
.gl_error
)
6411 class EnumArgument(EnumBaseArgument
):
6412 """A class that represents a GLenum argument"""
6414 def __init__(self
, name
, type):
6415 EnumBaseArgument
.__init
__(self
, name
, "GLenum", type, "GL_INVALID_ENUM")
6417 def GetLogArg(self
):
6418 """Overridden from Argument."""
6419 return ("GLES2Util::GetString%s(%s)" %
6420 (self
.type_name
, self
.name
))
6423 class IntArgument(EnumBaseArgument
):
6424 """A class for a GLint argument that can only except specific values.
6426 For example glTexImage2D takes a GLint for its internalformat
6427 argument instead of a GLenum.
6430 def __init__(self
, name
, type):
6431 EnumBaseArgument
.__init
__(self
, name
, "GLint", type, "GL_INVALID_VALUE")
6434 class ValidatedBoolArgument(EnumBaseArgument
):
6435 """A class for a GLboolean argument that can only except specific values.
6437 For example glUniformMatrix takes a GLboolean for it's transpose but it
6441 def __init__(self
, name
, type):
6442 EnumBaseArgument
.__init
__(self
, name
, "GLboolean", type, "GL_INVALID_VALUE")
6444 def GetLogArg(self
):
6445 """Overridden from Argument."""
6446 return 'GLES2Util::GetStringBool(%s)' % self
.name
6449 class ImmediatePointerArgument(Argument
):
6450 """A class that represents an immediate argument to a function.
6452 An immediate argument is one where the data follows the command.
6455 def __init__(self
, name
, type):
6456 Argument
.__init
__(self
, name
, type)
6458 def IsPointer(self
):
6461 def GetPointedType(self
):
6462 match
= re
.match('(const\s+)?(?P<element_type>[\w]+)\s*\*', self
.type)
6464 return match
.groupdict()['element_type']
6466 def AddCmdArgs(self
, args
):
6467 """Overridden from Argument."""
6470 def WriteGetCode(self
, file):
6471 """Overridden from Argument."""
6473 " %s %s = GetImmediateDataAs<%s>(\n" %
6474 (self
.type, self
.name
, self
.type))
6475 file.Write(" c, data_size, immediate_data_size);\n")
6477 def WriteValidationCode(self
, file, func
):
6478 """Overridden from Argument."""
6479 file.Write(" if (%s == NULL) {\n" % self
.name
)
6480 file.Write(" return error::kOutOfBounds;\n")
6483 def GetImmediateVersion(self
):
6484 """Overridden from Argument."""
6487 def WriteDestinationInitalizationValidation(self
, file, func
):
6488 """Overridden from Argument."""
6489 self
.WriteDestinationInitalizationValidatationIfNeeded(file, func
)
6491 def GetLogArg(self
):
6492 """Overridden from Argument."""
6493 return "static_cast<const void*>(%s)" % self
.name
6496 class BucketPointerArgument(Argument
):
6497 """A class that represents an bucket argument to a function."""
6499 def __init__(self
, name
, type):
6500 Argument
.__init
__(self
, name
, type)
6502 def AddCmdArgs(self
, args
):
6503 """Overridden from Argument."""
6506 def WriteGetCode(self
, file):
6507 """Overridden from Argument."""
6509 " %s %s = bucket->GetData(0, data_size);\n" %
6510 (self
.type, self
.name
))
6512 def WriteValidationCode(self
, file, func
):
6513 """Overridden from Argument."""
6516 def GetImmediateVersion(self
):
6517 """Overridden from Argument."""
6520 def WriteDestinationInitalizationValidation(self
, file, func
):
6521 """Overridden from Argument."""
6522 self
.WriteDestinationInitalizationValidatationIfNeeded(file, func
)
6524 def GetLogArg(self
):
6525 """Overridden from Argument."""
6526 return "static_cast<const void*>(%s)" % self
.name
6529 class PointerArgument(Argument
):
6530 """A class that represents a pointer argument to a function."""
6532 def __init__(self
, name
, type):
6533 Argument
.__init
__(self
, name
, type)
6535 def IsPointer(self
):
6536 """Returns true if argument is a pointer."""
6539 def GetPointedType(self
):
6540 match
= re
.match('(const\s+)?(?P<element_type>[\w]+)\s*\*', self
.type)
6542 return match
.groupdict()['element_type']
6544 def GetValidArg(self
, func
):
6545 """Overridden from Argument."""
6546 return "shared_memory_id_, shared_memory_offset_"
6548 def GetValidGLArg(self
, func
):
6549 """Overridden from Argument."""
6550 return "reinterpret_cast<%s>(shared_memory_address_)" % self
.type
6552 def GetNumInvalidValues(self
, func
):
6553 """Overridden from Argument."""
6556 def GetInvalidArg(self
, index
):
6557 """Overridden from Argument."""
6559 return ("kInvalidSharedMemoryId, 0", "kOutOfBounds", None)
6561 return ("shared_memory_id_, kInvalidSharedMemoryOffset",
6562 "kOutOfBounds", None)
6564 def GetLogArg(self
):
6565 """Overridden from Argument."""
6566 return "static_cast<const void*>(%s)" % self
.name
6568 def AddCmdArgs(self
, args
):
6569 """Overridden from Argument."""
6570 args
.append(Argument("%s_shm_id" % self
.name
, 'uint32_t'))
6571 args
.append(Argument("%s_shm_offset" % self
.name
, 'uint32_t'))
6573 def WriteGetCode(self
, file):
6574 """Overridden from Argument."""
6576 " %s %s = GetSharedMemoryAs<%s>(\n" %
6577 (self
.type, self
.name
, self
.type))
6579 " c.%s_shm_id, c.%s_shm_offset, data_size);\n" %
6580 (self
.name
, self
.name
))
6582 def WriteGetAddress(self
, file):
6583 """Overridden from Argument."""
6585 " %s %s = GetSharedMemoryAs<%s>(\n" %
6586 (self
.type, self
.name
, self
.type))
6588 " %s_shm_id, %s_shm_offset, %s_size);\n" %
6589 (self
.name
, self
.name
, self
.name
))
6591 def WriteValidationCode(self
, file, func
):
6592 """Overridden from Argument."""
6593 file.Write(" if (%s == NULL) {\n" % self
.name
)
6594 file.Write(" return error::kOutOfBounds;\n")
6597 def GetImmediateVersion(self
):
6598 """Overridden from Argument."""
6599 return ImmediatePointerArgument(self
.name
, self
.type)
6601 def GetBucketVersion(self
):
6602 """Overridden from Argument."""
6603 if self
.type == "const char*":
6604 return InputStringBucketArgument(self
.name
, self
.type)
6605 return BucketPointerArgument(self
.name
, self
.type)
6607 def WriteDestinationInitalizationValidation(self
, file, func
):
6608 """Overridden from Argument."""
6609 self
.WriteDestinationInitalizationValidatationIfNeeded(file, func
)
6612 class InputStringBucketArgument(Argument
):
6613 """An string input argument where the string is passed in a bucket."""
6615 def __init__(self
, name
, type):
6616 Argument
.__init
__(self
, name
+ "_bucket_id", "uint32_t")
6618 def WriteGetCode(self
, file):
6619 """Overridden from Argument."""
6621 Bucket* %(name)s_bucket = GetBucket(c.%(name)s);
6622 if (!%(name)s_bucket) {
6623 return error::kInvalidArguments;
6625 std::string %(name)s_str;
6626 if (!%(name)s_bucket->GetAsString(&%(name)s_str)) {
6627 return error::kInvalidArguments;
6629 const char* %(name)s = %(name)s_str.c_str();
6635 def GetValidArg(self
, func
):
6636 return "kNameBucketId"
6638 def GetValidGLArg(self
, func
):
6642 class ResourceIdArgument(Argument
):
6643 """A class that represents a resource id argument to a function."""
6645 def __init__(self
, name
, type):
6646 match
= re
.match("(GLid\w+)", type)
6647 self
.resource_type
= match
.group(1)[4:]
6648 type = type.replace(match
.group(1), "GLuint")
6649 Argument
.__init
__(self
, name
, type)
6651 def WriteGetCode(self
, file):
6652 """Overridden from Argument."""
6653 file.Write(" %s %s = c.%s;\n" % (self
.type, self
.name
, self
.name
))
6655 def GetValidArg(self
, func
):
6656 return "client_%s_id_" % self
.resource_type
.lower()
6658 def GetValidGLArg(self
, func
):
6659 return "kService%sId" % self
.resource_type
6662 class ResourceIdBindArgument(Argument
):
6663 """Represents a resource id argument to a bind function."""
6665 def __init__(self
, name
, type):
6666 match
= re
.match("(GLidBind\w+)", type)
6667 self
.resource_type
= match
.group(1)[8:]
6668 type = type.replace(match
.group(1), "GLuint")
6669 Argument
.__init
__(self
, name
, type)
6671 def WriteGetCode(self
, file):
6672 """Overridden from Argument."""
6673 code
= """ %(type)s %(name)s = c.%(name)s;
6675 file.Write(code
% {'type': self
.type, 'name': self
.name
})
6677 def GetValidArg(self
, func
):
6678 return "client_%s_id_" % self
.resource_type
.lower()
6680 def GetValidGLArg(self
, func
):
6681 return "kService%sId" % self
.resource_type
6684 class ResourceIdZeroArgument(Argument
):
6685 """Represents a resource id argument to a function that can be zero."""
6687 def __init__(self
, name
, type):
6688 match
= re
.match("(GLidZero\w+)", type)
6689 self
.resource_type
= match
.group(1)[8:]
6690 type = type.replace(match
.group(1), "GLuint")
6691 Argument
.__init
__(self
, name
, type)
6693 def WriteGetCode(self
, file):
6694 """Overridden from Argument."""
6695 file.Write(" %s %s = c.%s;\n" % (self
.type, self
.name
, self
.name
))
6697 def GetValidArg(self
, func
):
6698 return "client_%s_id_" % self
.resource_type
.lower()
6700 def GetValidGLArg(self
, func
):
6701 return "kService%sId" % self
.resource_type
6703 def GetNumInvalidValues(self
, func
):
6704 """returns the number of invalid values to be tested."""
6707 def GetInvalidArg(self
, index
):
6708 """returns an invalid value by index."""
6709 return ("kInvalidClientId", "kNoError", "GL_INVALID_VALUE")
6712 class Function(object):
6713 """A class that represents a function."""
6717 'Bind': BindHandler(),
6718 'Create': CreateHandler(),
6719 'Custom': CustomHandler(),
6720 'Data': DataHandler(),
6721 'Delete': DeleteHandler(),
6722 'DELn': DELnHandler(),
6723 'GENn': GENnHandler(),
6724 'GETn': GETnHandler(),
6725 'GLchar': GLcharHandler(),
6726 'GLcharN': GLcharNHandler(),
6727 'HandWritten': HandWrittenHandler(),
6729 'Manual': ManualHandler(),
6730 'PUT': PUTHandler(),
6731 'PUTn': PUTnHandler(),
6732 'PUTXn': PUTXnHandler(),
6733 'StateSet': StateSetHandler(),
6734 'StateSetRGBAlpha': StateSetRGBAlphaHandler(),
6735 'StateSetFrontBack': StateSetFrontBackHandler(),
6736 'StateSetFrontBackSeparate': StateSetFrontBackSeparateHandler(),
6737 'StateSetNamedParameter': StateSetNamedParameter(),
6738 'STRn': STRnHandler(),
6739 'Todo': TodoHandler(),
6742 def __init__(self
, name
, info
):
6744 self
.original_name
= info
['original_name']
6746 self
.original_args
= self
.ParseArgs(info
['original_args'])
6748 if 'cmd_args' in info
:
6749 self
.args_for_cmds
= self
.ParseArgs(info
['cmd_args'])
6751 self
.args_for_cmds
= self
.original_args
[:]
6753 self
.return_type
= info
['return_type']
6754 if self
.return_type
!= 'void':
6755 self
.return_arg
= CreateArg(info
['return_type'] + " result")
6757 self
.return_arg
= None
6759 self
.num_pointer_args
= sum(
6760 [1 for arg
in self
.args_for_cmds
if arg
.IsPointer()])
6762 self
.type_handler
= self
.type_handlers
[info
['type']]
6763 self
.can_auto_generate
= (self
.num_pointer_args
== 0 and
6764 info
['return_type'] == "void")
6767 def ParseArgs(self
, arg_string
):
6768 """Parses a function arg string."""
6770 parts
= arg_string
.split(',')
6771 for arg_string
in parts
:
6772 arg
= CreateArg(arg_string
)
6777 def IsType(self
, type_name
):
6778 """Returns true if function is a certain type."""
6779 return self
.info
['type'] == type_name
6781 def InitFunction(self
):
6782 """Creates command args and calls the init function for the type handler.
6784 Creates argument lists for command buffer commands, eg. self.cmd_args and
6786 Calls the type function initialization.
6787 Override to create different kind of command buffer command argument lists.
6790 for arg
in self
.args_for_cmds
:
6791 arg
.AddCmdArgs(self
.cmd_args
)
6794 for arg
in self
.args_for_cmds
:
6795 arg
.AddInitArgs(self
.init_args
)
6798 self
.init_args
.append(self
.return_arg
)
6800 self
.type_handler
.InitFunction(self
)
6802 def IsImmediate(self
):
6803 """Returns whether the function is immediate data function or not."""
6806 def GetInfo(self
, name
, default
= None):
6807 """Returns a value from the function info for this function."""
6808 if name
in self
.info
:
6809 return self
.info
[name
]
6812 def GetValidArg(self
, arg
):
6813 """Gets a valid argument value for the parameter arg from the function info
6816 index
= self
.GetOriginalArgs().index(arg
)
6820 valid_args
= self
.GetInfo('valid_args')
6821 if valid_args
and str(index
) in valid_args
:
6822 return valid_args
[str(index
)]
6825 def AddInfo(self
, name
, value
):
6827 self
.info
[name
] = value
6829 def IsExtension(self
):
6830 return self
.GetInfo('extension') or self
.GetInfo('extension_flag')
6832 def IsCoreGLFunction(self
):
6833 return (not self
.IsExtension() and
6834 not self
.GetInfo('pepper_interface'))
6836 def InPepperInterface(self
, interface
):
6837 ext
= self
.GetInfo('pepper_interface')
6838 if not interface
.GetName():
6839 return self
.IsCoreGLFunction()
6840 return ext
== interface
.GetName()
6842 def InAnyPepperExtension(self
):
6843 return self
.IsCoreGLFunction() or self
.GetInfo('pepper_interface')
6845 def GetErrorReturnString(self
):
6846 if self
.GetInfo("error_return"):
6847 return self
.GetInfo("error_return")
6848 elif self
.return_type
== "GLboolean":
6850 elif "*" in self
.return_type
:
6854 def GetGLFunctionName(self
):
6855 """Gets the function to call to execute GL for this command."""
6856 if self
.GetInfo('decoder_func'):
6857 return self
.GetInfo('decoder_func')
6858 return "gl%s" % self
.original_name
6860 def GetGLTestFunctionName(self
):
6861 gl_func_name
= self
.GetInfo('gl_test_func')
6862 if gl_func_name
== None:
6863 gl_func_name
= self
.GetGLFunctionName()
6864 if gl_func_name
.startswith("gl"):
6865 gl_func_name
= gl_func_name
[2:]
6867 gl_func_name
= self
.original_name
6870 def GetDataTransferMethods(self
):
6871 return self
.GetInfo('data_transfer_methods',
6872 ['immediate' if self
.num_pointer_args
== 1 else 'shm'])
6874 def AddCmdArg(self
, arg
):
6875 """Adds a cmd argument to this function."""
6876 self
.cmd_args
.append(arg
)
6878 def GetCmdArgs(self
):
6879 """Gets the command args for this function."""
6880 return self
.cmd_args
6882 def ClearCmdArgs(self
):
6883 """Clears the command args for this function."""
6886 def GetCmdConstants(self
):
6887 """Gets the constants for this function."""
6888 return [arg
for arg
in self
.args_for_cmds
if arg
.IsConstant()]
6890 def GetInitArgs(self
):
6891 """Gets the init args for this function."""
6892 return self
.init_args
6894 def GetOriginalArgs(self
):
6895 """Gets the original arguments to this function."""
6896 return self
.original_args
6898 def GetLastOriginalArg(self
):
6899 """Gets the last original argument to this function."""
6900 return self
.original_args
[len(self
.original_args
) - 1]
6902 def __MaybePrependComma(self
, arg_string
, add_comma
):
6903 """Adds a comma if arg_string is not empty and add_comma is true."""
6905 if add_comma
and len(arg_string
):
6907 return "%s%s" % (comma
, arg_string
)
6909 def MakeTypedOriginalArgString(self
, prefix
, add_comma
= False):
6910 """Gets a list of arguments as they are in GL."""
6911 args
= self
.GetOriginalArgs()
6912 arg_string
= ", ".join(
6913 ["%s %s%s" % (arg
.type, prefix
, arg
.name
) for arg
in args
])
6914 return self
.__MaybePrependComma
(arg_string
, add_comma
)
6916 def MakeOriginalArgString(self
, prefix
, add_comma
= False, separator
= ", "):
6917 """Gets the list of arguments as they are in GL."""
6918 args
= self
.GetOriginalArgs()
6919 arg_string
= separator
.join(
6920 ["%s%s" % (prefix
, arg
.name
) for arg
in args
])
6921 return self
.__MaybePrependComma
(arg_string
, add_comma
)
6923 def MakeTypedHelperArgString(self
, prefix
, add_comma
= False):
6924 """Gets a list of typed GL arguments after removing unneeded arguments."""
6925 args
= self
.GetOriginalArgs()
6926 arg_string
= ", ".join(
6931 ) for arg
in args
if not arg
.IsConstant()])
6932 return self
.__MaybePrependComma
(arg_string
, add_comma
)
6934 def MakeHelperArgString(self
, prefix
, add_comma
= False, separator
= ", "):
6935 """Gets a list of GL arguments after removing unneeded arguments."""
6936 args
= self
.GetOriginalArgs()
6937 arg_string
= separator
.join(
6938 ["%s%s" % (prefix
, arg
.name
)
6939 for arg
in args
if not arg
.IsConstant()])
6940 return self
.__MaybePrependComma
(arg_string
, add_comma
)
6942 def MakeTypedPepperArgString(self
, prefix
):
6943 """Gets a list of arguments as they need to be for Pepper."""
6944 if self
.GetInfo("pepper_args"):
6945 return self
.GetInfo("pepper_args")
6947 return self
.MakeTypedOriginalArgString(prefix
, False)
6949 def MapCTypeToPepperIdlType(self
, ctype
, is_for_return_type
=False):
6950 """Converts a C type name to the corresponding Pepper IDL type."""
6952 'char*': '[out] str_t',
6953 'const GLchar* const*': '[out] cstr_t',
6954 'const char*': 'cstr_t',
6955 'const void*': 'mem_t',
6956 'void*': '[out] mem_t',
6957 'void**': '[out] mem_ptr_t',
6959 # We use "GLxxx_ptr_t" for "GLxxx*".
6960 matched
= re
.match(r
'(const )?(GL\w+)\*$', ctype
)
6962 idltype
= matched
.group(2) + '_ptr_t'
6963 if not matched
.group(1):
6964 idltype
= '[out] ' + idltype
6965 # If an in/out specifier is not specified yet, prepend [in].
6966 if idltype
[0] != '[':
6967 idltype
= '[in] ' + idltype
6968 # Strip the in/out specifier for a return type.
6969 if is_for_return_type
:
6970 idltype
= re
.sub(r
'\[\w+\] ', '', idltype
)
6973 def MakeTypedPepperIdlArgStrings(self
):
6974 """Gets a list of arguments as they need to be for Pepper IDL."""
6975 args
= self
.GetOriginalArgs()
6976 return ["%s %s" % (self
.MapCTypeToPepperIdlType(arg
.type), arg
.name
)
6979 def GetPepperName(self
):
6980 if self
.GetInfo("pepper_name"):
6981 return self
.GetInfo("pepper_name")
6984 def MakeTypedCmdArgString(self
, prefix
, add_comma
= False):
6985 """Gets a typed list of arguments as they need to be for command buffers."""
6986 args
= self
.GetCmdArgs()
6987 arg_string
= ", ".join(
6988 ["%s %s%s" % (arg
.type, prefix
, arg
.name
) for arg
in args
])
6989 return self
.__MaybePrependComma
(arg_string
, add_comma
)
6991 def MakeCmdArgString(self
, prefix
, add_comma
= False):
6992 """Gets the list of arguments as they need to be for command buffers."""
6993 args
= self
.GetCmdArgs()
6994 arg_string
= ", ".join(
6995 ["%s%s" % (prefix
, arg
.name
) for arg
in args
])
6996 return self
.__MaybePrependComma
(arg_string
, add_comma
)
6998 def MakeTypedInitString(self
, prefix
, add_comma
= False):
6999 """Gets a typed list of arguments as they need to be for cmd Init/Set."""
7000 args
= self
.GetInitArgs()
7001 arg_string
= ", ".join(
7002 ["%s %s%s" % (arg
.type, prefix
, arg
.name
) for arg
in args
])
7003 return self
.__MaybePrependComma
(arg_string
, add_comma
)
7005 def MakeInitString(self
, prefix
, add_comma
= False):
7006 """Gets the list of arguments as they need to be for cmd Init/Set."""
7007 args
= self
.GetInitArgs()
7008 arg_string
= ", ".join(
7009 ["%s%s" % (prefix
, arg
.name
) for arg
in args
])
7010 return self
.__MaybePrependComma
(arg_string
, add_comma
)
7012 def MakeLogArgString(self
):
7013 """Makes a string of the arguments for the LOG macros"""
7014 args
= self
.GetOriginalArgs()
7015 return ' << ", " << '.join([arg
.GetLogArg() for arg
in args
])
7017 def WriteCommandDescription(self
, file):
7018 """Writes a description of the command."""
7019 file.Write("//! Command that corresponds to gl%s.\n" % self
.original_name
)
7021 def WriteHandlerValidation(self
, file):
7022 """Writes validation code for the function."""
7023 for arg
in self
.GetOriginalArgs():
7024 arg
.WriteValidationCode(file, self
)
7025 self
.WriteValidationCode(file)
7027 def WriteHandlerImplementation(self
, file):
7028 """Writes the handler implementation for this command."""
7029 self
.type_handler
.WriteHandlerImplementation(self
, file)
7031 def WriteValidationCode(self
, file):
7032 """Writes the validation code for a command."""
7035 def WriteCmdFlag(self
, file):
7036 """Writes the cmd cmd_flags constant."""
7038 # By default trace only at the highest level 3.
7039 trace_level
= int(self
.GetInfo('trace_level', default
= 3))
7040 if trace_level
not in xrange(0, 4):
7041 raise KeyError("Unhandled trace_level: %d" % trace_level
)
7043 flags
.append('CMD_FLAG_SET_TRACE_LEVEL(%d)' % trace_level
)
7046 cmd_flags
= ' | '.join(flags
)
7050 file.Write(" static const uint8 cmd_flags = %s;\n" % cmd_flags
)
7053 def WriteCmdArgFlag(self
, file):
7054 """Writes the cmd kArgFlags constant."""
7055 file.Write(" static const cmd::ArgFlags kArgFlags = cmd::kFixed;\n")
7057 def WriteCmdComputeSize(self
, file):
7058 """Writes the ComputeSize function for the command."""
7059 file.Write(" static uint32_t ComputeSize() {\n")
7061 " return static_cast<uint32_t>(sizeof(ValueType)); // NOLINT\n")
7065 def WriteCmdSetHeader(self
, file):
7066 """Writes the cmd's SetHeader function."""
7067 file.Write(" void SetHeader() {\n")
7068 file.Write(" header.SetCmd<ValueType>();\n")
7072 def WriteCmdInit(self
, file):
7073 """Writes the cmd's Init function."""
7074 file.Write(" void Init(%s) {\n" % self
.MakeTypedCmdArgString("_"))
7075 file.Write(" SetHeader();\n")
7076 args
= self
.GetCmdArgs()
7078 file.Write(" %s = _%s;\n" % (arg
.name
, arg
.name
))
7082 def WriteCmdSet(self
, file):
7083 """Writes the cmd's Set function."""
7084 copy_args
= self
.MakeCmdArgString("_", False)
7085 file.Write(" void* Set(void* cmd%s) {\n" %
7086 self
.MakeTypedCmdArgString("_", True))
7087 file.Write(" static_cast<ValueType*>(cmd)->Init(%s);\n" % copy_args
)
7088 file.Write(" return NextCmdAddress<ValueType>(cmd);\n")
7092 def WriteStruct(self
, file):
7093 self
.type_handler
.WriteStruct(self
, file)
7095 def WriteDocs(self
, file):
7096 self
.type_handler
.WriteDocs(self
, file)
7098 def WriteCmdHelper(self
, file):
7099 """Writes the cmd's helper."""
7100 self
.type_handler
.WriteCmdHelper(self
, file)
7102 def WriteServiceImplementation(self
, file):
7103 """Writes the service implementation for a command."""
7104 self
.type_handler
.WriteServiceImplementation(self
, file)
7106 def WriteServiceUnitTest(self
, file, *extras
):
7107 """Writes the service implementation for a command."""
7108 self
.type_handler
.WriteServiceUnitTest(self
, file, *extras
)
7110 def WriteGLES2CLibImplementation(self
, file):
7111 """Writes the GLES2 C Lib Implemention."""
7112 self
.type_handler
.WriteGLES2CLibImplementation(self
, file)
7114 def WriteGLES2InterfaceHeader(self
, file):
7115 """Writes the GLES2 Interface declaration."""
7116 self
.type_handler
.WriteGLES2InterfaceHeader(self
, file)
7118 def WriteGLES2InterfaceStub(self
, file):
7119 """Writes the GLES2 Interface Stub declaration."""
7120 self
.type_handler
.WriteGLES2InterfaceStub(self
, file)
7122 def WriteGLES2InterfaceStubImpl(self
, file):
7123 """Writes the GLES2 Interface Stub declaration."""
7124 self
.type_handler
.WriteGLES2InterfaceStubImpl(self
, file)
7126 def WriteGLES2ImplementationHeader(self
, file):
7127 """Writes the GLES2 Implemention declaration."""
7128 self
.type_handler
.WriteGLES2ImplementationHeader(self
, file)
7130 def WriteGLES2Implementation(self
, file):
7131 """Writes the GLES2 Implemention definition."""
7132 self
.type_handler
.WriteGLES2Implementation(self
, file)
7134 def WriteGLES2TraceImplementationHeader(self
, file):
7135 """Writes the GLES2 Trace Implemention declaration."""
7136 self
.type_handler
.WriteGLES2TraceImplementationHeader(self
, file)
7138 def WriteGLES2TraceImplementation(self
, file):
7139 """Writes the GLES2 Trace Implemention definition."""
7140 self
.type_handler
.WriteGLES2TraceImplementation(self
, file)
7142 def WriteGLES2Header(self
, file):
7143 """Writes the GLES2 Implemention unit test."""
7144 self
.type_handler
.WriteGLES2Header(self
, file)
7146 def WriteGLES2ImplementationUnitTest(self
, file):
7147 """Writes the GLES2 Implemention unit test."""
7148 self
.type_handler
.WriteGLES2ImplementationUnitTest(self
, file)
7150 def WriteDestinationInitalizationValidation(self
, file):
7151 """Writes the client side destintion initialization validation."""
7152 self
.type_handler
.WriteDestinationInitalizationValidation(self
, file)
7154 def WriteFormatTest(self
, file):
7155 """Writes the cmd's format test."""
7156 self
.type_handler
.WriteFormatTest(self
, file)
7159 class PepperInterface(object):
7160 """A class that represents a function."""
7162 def __init__(self
, info
):
7163 self
.name
= info
["name"]
7164 self
.dev
= info
["dev"]
7169 def GetInterfaceName(self
):
7173 upperint
= "_" + self
.name
.upper()
7176 return "PPB_OPENGLES2%s%s_INTERFACE" % (upperint
, dev
)
7178 def GetInterfaceString(self
):
7182 return "PPB_OpenGLES2%s%s" % (self
.name
, dev
)
7184 def GetStructName(self
):
7188 return "PPB_OpenGLES2%s%s" % (self
.name
, dev
)
7191 class ImmediateFunction(Function
):
7192 """A class that represnets an immediate function command."""
7194 def __init__(self
, func
):
7197 "%sImmediate" % func
.name
,
7200 def InitFunction(self
):
7201 # Override args in original_args and args_for_cmds with immediate versions
7204 new_original_args
= []
7205 for arg
in self
.original_args
:
7206 new_arg
= arg
.GetImmediateVersion()
7208 new_original_args
.append(new_arg
)
7209 self
.original_args
= new_original_args
7211 new_args_for_cmds
= []
7212 for arg
in self
.args_for_cmds
:
7213 new_arg
= arg
.GetImmediateVersion()
7215 new_args_for_cmds
.append(new_arg
)
7217 self
.args_for_cmds
= new_args_for_cmds
7219 Function
.InitFunction(self
)
7221 def IsImmediate(self
):
7224 def WriteCommandDescription(self
, file):
7225 """Overridden from Function"""
7226 file.Write("//! Immediate version of command that corresponds to gl%s.\n" %
7229 def WriteServiceImplementation(self
, file):
7230 """Overridden from Function"""
7231 self
.type_handler
.WriteImmediateServiceImplementation(self
, file)
7233 def WriteHandlerImplementation(self
, file):
7234 """Overridden from Function"""
7235 self
.type_handler
.WriteImmediateHandlerImplementation(self
, file)
7237 def WriteServiceUnitTest(self
, file, *extras
):
7238 """Writes the service implementation for a command."""
7239 self
.type_handler
.WriteImmediateServiceUnitTest(self
, file, *extras
)
7241 def WriteValidationCode(self
, file):
7242 """Overridden from Function"""
7243 self
.type_handler
.WriteImmediateValidationCode(self
, file)
7245 def WriteCmdArgFlag(self
, file):
7246 """Overridden from Function"""
7247 file.Write(" static const cmd::ArgFlags kArgFlags = cmd::kAtLeastN;\n")
7249 def WriteCmdComputeSize(self
, file):
7250 """Overridden from Function"""
7251 self
.type_handler
.WriteImmediateCmdComputeSize(self
, file)
7253 def WriteCmdSetHeader(self
, file):
7254 """Overridden from Function"""
7255 self
.type_handler
.WriteImmediateCmdSetHeader(self
, file)
7257 def WriteCmdInit(self
, file):
7258 """Overridden from Function"""
7259 self
.type_handler
.WriteImmediateCmdInit(self
, file)
7261 def WriteCmdSet(self
, file):
7262 """Overridden from Function"""
7263 self
.type_handler
.WriteImmediateCmdSet(self
, file)
7265 def WriteCmdHelper(self
, file):
7266 """Overridden from Function"""
7267 self
.type_handler
.WriteImmediateCmdHelper(self
, file)
7269 def WriteFormatTest(self
, file):
7270 """Overridden from Function"""
7271 self
.type_handler
.WriteImmediateFormatTest(self
, file)
7274 class BucketFunction(Function
):
7275 """A class that represnets a bucket version of a function command."""
7277 def __init__(self
, func
):
7280 "%sBucket" % func
.name
,
7283 def InitFunction(self
):
7284 # Override args in original_args and args_for_cmds with bucket versions
7287 new_original_args
= []
7288 for arg
in self
.original_args
:
7289 new_arg
= arg
.GetBucketVersion()
7291 new_original_args
.append(new_arg
)
7292 self
.original_args
= new_original_args
7294 new_args_for_cmds
= []
7295 for arg
in self
.args_for_cmds
:
7296 new_arg
= arg
.GetBucketVersion()
7298 new_args_for_cmds
.append(new_arg
)
7300 self
.args_for_cmds
= new_args_for_cmds
7302 Function
.InitFunction(self
)
7304 def WriteCommandDescription(self
, file):
7305 """Overridden from Function"""
7306 file.Write("//! Bucket version of command that corresponds to gl%s.\n" %
7309 def WriteServiceImplementation(self
, file):
7310 """Overridden from Function"""
7311 self
.type_handler
.WriteBucketServiceImplementation(self
, file)
7313 def WriteHandlerImplementation(self
, file):
7314 """Overridden from Function"""
7315 self
.type_handler
.WriteBucketHandlerImplementation(self
, file)
7317 def WriteServiceUnitTest(self
, file, *extras
):
7318 """Writes the service implementation for a command."""
7319 self
.type_handler
.WriteBucketServiceUnitTest(self
, file, *extras
)
7322 def CreateArg(arg_string
):
7323 """Creates an Argument."""
7324 arg_parts
= arg_string
.split()
7325 if len(arg_parts
) == 1 and arg_parts
[0] == 'void':
7327 # Is this a pointer argument?
7328 elif arg_string
.find('*') >= 0:
7329 return PointerArgument(
7331 " ".join(arg_parts
[0:-1]))
7332 # Is this a resource argument? Must come after pointer check.
7333 elif arg_parts
[0].startswith('GLidBind'):
7334 return ResourceIdBindArgument(arg_parts
[-1], " ".join(arg_parts
[0:-1]))
7335 elif arg_parts
[0].startswith('GLidZero'):
7336 return ResourceIdZeroArgument(arg_parts
[-1], " ".join(arg_parts
[0:-1]))
7337 elif arg_parts
[0].startswith('GLid'):
7338 return ResourceIdArgument(arg_parts
[-1], " ".join(arg_parts
[0:-1]))
7339 elif arg_parts
[0].startswith('GLenum') and len(arg_parts
[0]) > 6:
7340 return EnumArgument(arg_parts
[-1], " ".join(arg_parts
[0:-1]))
7341 elif arg_parts
[0].startswith('GLboolean') and len(arg_parts
[0]) > 9:
7342 return ValidatedBoolArgument(arg_parts
[-1], " ".join(arg_parts
[0:-1]))
7343 elif arg_parts
[0].startswith('GLboolean'):
7344 return BoolArgument(arg_parts
[-1], " ".join(arg_parts
[0:-1]))
7345 elif arg_parts
[0].startswith('GLintUniformLocation'):
7346 return UniformLocationArgument(arg_parts
[-1])
7347 elif (arg_parts
[0].startswith('GLint') and len(arg_parts
[0]) > 5 and
7348 not arg_parts
[0].startswith('GLintptr')):
7349 return IntArgument(arg_parts
[-1], " ".join(arg_parts
[0:-1]))
7350 elif (arg_parts
[0].startswith('GLsizeiNotNegative') or
7351 arg_parts
[0].startswith('GLintptrNotNegative')):
7352 return SizeNotNegativeArgument(arg_parts
[-1],
7353 " ".join(arg_parts
[0:-1]),
7354 arg_parts
[0][0:-11])
7355 elif arg_parts
[0].startswith('GLsize'):
7356 return SizeArgument(arg_parts
[-1], " ".join(arg_parts
[0:-1]))
7358 return Argument(arg_parts
[-1], " ".join(arg_parts
[0:-1]))
7361 class GLGenerator(object):
7362 """A class to generate GL command buffers."""
7364 _function_re
= re
.compile(r
'GL_APICALL(.*?)GL_APIENTRY (.*?) \((.*?)\);')
7366 def __init__(self
, verbose
):
7367 self
.original_functions
= []
7369 self
.verbose
= verbose
7371 self
.pepper_interfaces
= []
7372 self
.interface_info
= {}
7374 for interface
in _PEPPER_INTERFACES
:
7375 interface
= PepperInterface(interface
)
7376 self
.pepper_interfaces
.append(interface
)
7377 self
.interface_info
[interface
.GetName()] = interface
7379 def AddFunction(self
, func
):
7380 """Adds a function."""
7381 self
.functions
.append(func
)
7383 def GetFunctionInfo(self
, name
):
7384 """Gets a type info for the given function name."""
7385 if name
in _FUNCTION_INFO
:
7386 func_info
= _FUNCTION_INFO
[name
].copy()
7390 if not 'type' in func_info
:
7391 func_info
['type'] = ''
7396 """Prints something if verbose is true."""
7400 def Error(self
, msg
):
7401 """Prints an error."""
7402 print "Error: %s" % msg
7405 def WriteLicense(self
, file):
7406 """Writes the license."""
7407 file.Write(_LICENSE
)
7409 def WriteNamespaceOpen(self
, file):
7410 """Writes the code for the namespace."""
7411 file.Write("namespace gpu {\n")
7412 file.Write("namespace gles2 {\n")
7415 def WriteNamespaceClose(self
, file):
7416 """Writes the code to close the namespace."""
7417 file.Write("} // namespace gles2\n")
7418 file.Write("} // namespace gpu\n")
7421 def ParseGLH(self
, filename
):
7422 """Parses the cmd_buffer_functions.txt file and extracts the functions"""
7423 f
= open(filename
, "r")
7424 functions
= f
.read()
7426 for line
in functions
.splitlines():
7427 match
= self
._function
_re
.match(line
)
7429 func_name
= match
.group(2)[2:]
7430 func_info
= self
.GetFunctionInfo(func_name
)
7431 if func_info
['type'] == 'Noop':
7434 parsed_func_info
= {
7435 'original_name': func_name
,
7436 'original_args': match
.group(3),
7437 'return_type': match
.group(1).strip(),
7440 for k
in parsed_func_info
.keys():
7441 if not k
in func_info
:
7442 func_info
[k
] = parsed_func_info
[k
]
7444 f
= Function(func_name
, func_info
)
7445 self
.original_functions
.append(f
)
7447 #for arg in f.GetOriginalArgs():
7448 # if not isinstance(arg, EnumArgument) and arg.type == 'GLenum':
7449 # self.Log("%s uses bare GLenum %s." % (func_name, arg.name))
7451 gen_cmd
= f
.GetInfo('gen_cmd')
7452 if gen_cmd
== True or gen_cmd
== None:
7453 if f
.type_handler
.NeedsDataTransferFunction(f
):
7454 methods
= f
.GetDataTransferMethods()
7455 if 'immediate' in methods
:
7456 self
.AddFunction(ImmediateFunction(f
))
7457 if 'bucket' in methods
:
7458 self
.AddFunction(BucketFunction(f
))
7459 if 'shm' in methods
:
7464 self
.Log("Auto Generated Functions : %d" %
7465 len([f
for f
in self
.functions
if f
.can_auto_generate
or
7466 (not f
.IsType('') and not f
.IsType('Custom') and
7467 not f
.IsType('Todo'))]))
7469 funcs
= [f
for f
in self
.functions
if not f
.can_auto_generate
and
7470 (f
.IsType('') or f
.IsType('Custom') or f
.IsType('Todo'))]
7471 self
.Log("Non Auto Generated Functions: %d" % len(funcs
))
7474 self
.Log(" %-10s %-20s gl%s" % (f
.info
['type'], f
.return_type
, f
.name
))
7476 def WriteCommandIds(self
, filename
):
7477 """Writes the command buffer format"""
7478 file = CHeaderWriter(filename
)
7479 file.Write("#define GLES2_COMMAND_LIST(OP) \\\n")
7481 for func
in self
.functions
:
7482 file.Write(" %-60s /* %d */ \\\n" %
7483 ("OP(%s)" % func
.name
, id))
7487 file.Write("enum CommandId {\n")
7488 file.Write(" kStartPoint = cmd::kLastCommonId, "
7489 "// All GLES2 commands start after this.\n")
7490 file.Write("#define GLES2_CMD_OP(name) k ## name,\n")
7491 file.Write(" GLES2_COMMAND_LIST(GLES2_CMD_OP)\n")
7492 file.Write("#undef GLES2_CMD_OP\n")
7493 file.Write(" kNumCommands\n")
7498 def WriteFormat(self
, filename
):
7499 """Writes the command buffer format"""
7500 file = CHeaderWriter(filename
)
7501 for func
in self
.functions
:
7503 #gen_cmd = func.GetInfo('gen_cmd')
7504 #if gen_cmd == True or gen_cmd == None:
7505 func
.WriteStruct(file)
7509 def WriteDocs(self
, filename
):
7510 """Writes the command buffer doc version of the commands"""
7511 file = CWriter(filename
)
7512 for func
in self
.functions
:
7514 #gen_cmd = func.GetInfo('gen_cmd')
7515 #if gen_cmd == True or gen_cmd == None:
7516 func
.WriteDocs(file)
7520 def WriteFormatTest(self
, filename
):
7521 """Writes the command buffer format test."""
7522 file = CHeaderWriter(
7524 "// This file contains unit tests for gles2 commmands\n"
7525 "// It is included by gles2_cmd_format_test.cc\n"
7528 for func
in self
.functions
:
7530 #gen_cmd = func.GetInfo('gen_cmd')
7531 #if gen_cmd == True or gen_cmd == None:
7532 func
.WriteFormatTest(file)
7536 def WriteCmdHelperHeader(self
, filename
):
7537 """Writes the gles2 command helper."""
7538 file = CHeaderWriter(filename
)
7540 for func
in self
.functions
:
7542 #gen_cmd = func.GetInfo('gen_cmd')
7543 #if gen_cmd == True or gen_cmd == None:
7544 func
.WriteCmdHelper(file)
7548 def WriteServiceContextStateHeader(self
, filename
):
7549 """Writes the service context state header."""
7550 file = CHeaderWriter(
7552 "// It is included by context_state.h\n")
7553 file.Write("struct EnableFlags {\n")
7554 file.Write(" EnableFlags();\n")
7555 for capability
in _CAPABILITY_FLAGS
:
7556 file.Write(" bool %s;\n" % capability
['name'])
7557 file.Write(" bool cached_%s;\n" % capability
['name'])
7558 file.Write("};\n\n")
7560 for state_name
in sorted(_STATES
.keys()):
7561 state
= _STATES
[state_name
]
7562 for item
in state
['states']:
7563 if isinstance(item
['default'], list):
7564 file.Write("%s %s[%d];\n" % (item
['type'], item
['name'],
7565 len(item
['default'])))
7567 file.Write("%s %s;\n" % (item
['type'], item
['name']))
7569 if item
.get('cached', False):
7570 if isinstance(item
['default'], list):
7571 file.Write("%s cached_%s[%d];\n" % (item
['type'], item
['name'],
7572 len(item
['default'])))
7574 file.Write("%s cached_%s;\n" % (item
['type'], item
['name']))
7579 inline void SetDeviceCapabilityState(GLenum cap, bool enable) {
7582 for capability
in _CAPABILITY_FLAGS
:
7585 """ % capability
['name'].upper())
7587 if (enable_flags.cached_%(name)s == enable &&
7588 !ignore_cached_state)
7590 enable_flags.cached_%(name)s = enable;
7608 def WriteClientContextStateHeader(self
, filename
):
7609 """Writes the client context state header."""
7610 file = CHeaderWriter(
7612 "// It is included by client_context_state.h\n")
7613 file.Write("struct EnableFlags {\n")
7614 file.Write(" EnableFlags();\n")
7615 for capability
in _CAPABILITY_FLAGS
:
7616 file.Write(" bool %s;\n" % capability
['name'])
7617 file.Write("};\n\n")
7621 def WriteContextStateGetters(self
, file, class_name
):
7622 """Writes the state getters."""
7623 for gl_type
in ["GLint", "GLfloat"]:
7625 bool %s::GetStateAs%s(
7626 GLenum pname, %s* params, GLsizei* num_written) const {
7628 """ % (class_name
, gl_type
, gl_type
))
7629 for state_name
in sorted(_STATES
.keys()):
7630 state
= _STATES
[state_name
]
7632 file.Write(" case %s:\n" % state
['enum'])
7633 file.Write(" *num_written = %d;\n" % len(state
['states']))
7634 file.Write(" if (params) {\n")
7635 for ndx
,item
in enumerate(state
['states']):
7636 file.Write(" params[%d] = static_cast<%s>(%s);\n" %
7637 (ndx
, gl_type
, item
['name']))
7639 file.Write(" return true;\n")
7641 for item
in state
['states']:
7642 file.Write(" case %s:\n" % item
['enum'])
7643 if isinstance(item
['default'], list):
7644 item_len
= len(item
['default'])
7645 file.Write(" *num_written = %d;\n" % item_len
)
7646 file.Write(" if (params) {\n")
7647 if item
['type'] == gl_type
:
7648 file.Write(" memcpy(params, %s, sizeof(%s) * %d);\n" %
7649 (item
['name'], item
['type'], item_len
))
7651 file.Write(" for (size_t i = 0; i < %s; ++i) {\n" %
7653 file.Write(" params[i] = %s;\n" %
7654 (GetGLGetTypeConversion(gl_type
, item
['type'],
7655 "%s[i]" % item
['name'])))
7658 file.Write(" *num_written = 1;\n")
7659 file.Write(" if (params) {\n")
7660 file.Write(" params[0] = %s;\n" %
7661 (GetGLGetTypeConversion(gl_type
, item
['type'],
7664 file.Write(" return true;\n")
7665 for capability
in _CAPABILITY_FLAGS
:
7666 file.Write(" case GL_%s:\n" % capability
['name'].upper())
7667 file.Write(" *num_written = 1;\n")
7668 file.Write(" if (params) {\n")
7670 " params[0] = static_cast<%s>(enable_flags.%s);\n" %
7671 (gl_type
, capability
['name']))
7673 file.Write(" return true;\n")
7674 file.Write(""" default:
7680 def WriteServiceContextStateImpl(self
, filename
):
7681 """Writes the context state service implementation."""
7682 file = CHeaderWriter(
7684 "// It is included by context_state.cc\n")
7686 for capability
in _CAPABILITY_FLAGS
:
7687 code
.append("%s(%s)" %
7688 (capability
['name'],
7689 ('false', 'true')['default' in capability
]))
7690 code
.append("cached_%s(%s)" %
7691 (capability
['name'],
7692 ('false', 'true')['default' in capability
]))
7693 file.Write("ContextState::EnableFlags::EnableFlags()\n : %s {\n}\n" %
7697 file.Write("void ContextState::Initialize() {\n")
7698 for state_name
in sorted(_STATES
.keys()):
7699 state
= _STATES
[state_name
]
7700 for item
in state
['states']:
7701 if isinstance(item
['default'], list):
7702 for ndx
, value
in enumerate(item
['default']):
7703 file.Write(" %s[%d] = %s;\n" % (item
['name'], ndx
, value
))
7705 file.Write(" %s = %s;\n" % (item
['name'], item
['default']))
7706 if item
.get('cached', False):
7707 if isinstance(item
['default'], list):
7708 for ndx
, value
in enumerate(item
['default']):
7709 file.Write(" cached_%s[%d] = %s;\n" % (item
['name'], ndx
, value
))
7711 file.Write(" cached_%s = %s;\n" % (item
['name'], item
['default']))
7715 void ContextState::InitCapabilities(const ContextState* prev_state) const {
7717 def WriteCapabilities(test_prev
):
7718 for capability
in _CAPABILITY_FLAGS
:
7719 capability_name
= capability
['name']
7721 file.Write(""" if (prev_state->enable_flags.cached_%s !=
7722 enable_flags.cached_%s)\n""" %
7723 (capability_name
, capability_name
))
7724 file.Write(" EnableDisable(GL_%s, enable_flags.cached_%s);\n" %
7725 (capability_name
.upper(), capability_name
))
7727 file.Write(" if (prev_state) {")
7728 WriteCapabilities(True)
7729 file.Write(" } else {")
7730 WriteCapabilities(False)
7735 void ContextState::InitState(const ContextState *prev_state) const {
7738 def WriteStates(test_prev
):
7739 # We need to sort the keys so the expectations match
7740 for state_name
in sorted(_STATES
.keys()):
7741 state
= _STATES
[state_name
]
7742 if state
['type'] == 'FrontBack':
7743 num_states
= len(state
['states'])
7744 for ndx
, group
in enumerate(Grouper(num_states
/ 2, state
['states'])):
7748 for place
, item
in enumerate(group
):
7749 item_name
= CachedStateName(item
)
7750 args
.append('%s' % item_name
)
7754 file.Write("(%s != prev_state->%s)" % (item_name
, item_name
))
7758 " gl%s(%s, %s);\n" %
7759 (state
['func'], ('GL_FRONT', 'GL_BACK')[ndx
], ", ".join(args
)))
7760 elif state
['type'] == 'NamedParameter':
7761 for item
in state
['states']:
7762 item_name
= CachedStateName(item
)
7764 if 'extension_flag' in item
:
7765 file.Write(" if (feature_info_->feature_flags().%s) {\n " %
7766 item
['extension_flag'])
7768 if isinstance(item
['default'], list):
7769 file.Write(" if (memcmp(prev_state->%s, %s, "
7770 "sizeof(%s) * %d)) {\n" %
7771 (item_name
, item_name
, item
['type'],
7772 len(item
['default'])))
7774 file.Write(" if (prev_state->%s != %s) {\n " %
7775 (item_name
, item_name
))
7776 file.Write(" gl%s(%s, %s);\n" %
7779 if 'enum_set' in item
else item
['enum']),
7782 if 'extension_flag' in item
:
7785 if 'extension_flag' in item
:
7788 if 'extension_flag' in state
:
7789 file.Write(" if (feature_info_->feature_flags().%s)\n " %
7790 state
['extension_flag'])
7794 for place
, item
in enumerate(state
['states']):
7795 item_name
= CachedStateName(item
)
7796 args
.append('%s' % item_name
)
7800 file.Write("(%s != prev_state->%s)" %
7801 (item_name
, item_name
))
7804 file.Write(" gl%s(%s);\n" % (state
['func'], ", ".join(args
)))
7806 file.Write(" if (prev_state) {")
7808 file.Write(" } else {")
7813 file.Write("""bool ContextState::GetEnabled(GLenum cap) const {
7816 for capability
in _CAPABILITY_FLAGS
:
7817 file.Write(" case GL_%s:\n" % capability
['name'].upper())
7818 file.Write(" return enable_flags.%s;\n" % capability
['name'])
7819 file.Write(""" default:
7826 self
.WriteContextStateGetters(file, "ContextState")
7829 def WriteClientContextStateImpl(self
, filename
):
7830 """Writes the context state client side implementation."""
7831 file = CHeaderWriter(
7833 "// It is included by client_context_state.cc\n")
7835 for capability
in _CAPABILITY_FLAGS
:
7836 code
.append("%s(%s)" %
7837 (capability
['name'],
7838 ('false', 'true')['default' in capability
]))
7840 "ClientContextState::EnableFlags::EnableFlags()\n : %s {\n}\n" %
7845 bool ClientContextState::SetCapabilityState(
7846 GLenum cap, bool enabled, bool* changed) {
7850 for capability
in _CAPABILITY_FLAGS
:
7851 file.Write(" case GL_%s:\n" % capability
['name'].upper())
7852 file.Write(""" if (enable_flags.%(name)s != enabled) {
7854 enable_flags.%(name)s = enabled;
7858 file.Write(""" default:
7863 file.Write("""bool ClientContextState::GetEnabled(
7864 GLenum cap, bool* enabled) const {
7867 for capability
in _CAPABILITY_FLAGS
:
7868 file.Write(" case GL_%s:\n" % capability
['name'].upper())
7869 file.Write(" *enabled = enable_flags.%s;\n" % capability
['name'])
7870 file.Write(" return true;\n")
7871 file.Write(""" default:
7878 def WriteServiceImplementation(self
, filename
):
7879 """Writes the service decorder implementation."""
7880 file = CHeaderWriter(
7882 "// It is included by gles2_cmd_decoder.cc\n")
7884 for func
in self
.functions
:
7886 #gen_cmd = func.GetInfo('gen_cmd')
7887 #if gen_cmd == True or gen_cmd == None:
7888 func
.WriteServiceImplementation(file)
7891 bool GLES2DecoderImpl::SetCapabilityState(GLenum cap, bool enabled) {
7894 for capability
in _CAPABILITY_FLAGS
:
7895 file.Write(" case GL_%s:\n" % capability
['name'].upper())
7896 if 'state_flag' in capability
:
7899 state_.enable_flags.%(name)s = enabled;
7900 if (state_.enable_flags.cached_%(name)s != enabled
7901 || state_.ignore_cached_state) {
7902 %(state_flag)s = true;
7908 state_.enable_flags.%(name)s = enabled;
7909 if (state_.enable_flags.cached_%(name)s != enabled
7910 || state_.ignore_cached_state) {
7911 state_.enable_flags.cached_%(name)s = enabled;
7916 file.Write(""" default:
7924 def WriteServiceUnitTests(self
, filename
):
7925 """Writes the service decorder unit tests."""
7926 num_tests
= len(self
.functions
)
7927 FUNCTIONS_PER_FILE
= 98 # hard code this so it doesn't change.
7929 for test_num
in range(0, num_tests
, FUNCTIONS_PER_FILE
):
7931 name
= filename
% count
7932 file = CHeaderWriter(
7934 "// It is included by gles2_cmd_decoder_unittest_%d.cc\n" % count
)
7935 test_name
= 'GLES2DecoderTest%d' % count
7936 end
= test_num
+ FUNCTIONS_PER_FILE
7939 for idx
in range(test_num
, end
):
7940 func
= self
.functions
[idx
]
7942 # Do any filtering of the functions here, so that the functions
7943 # will not move between the numbered files if filtering properties
7945 if func
.GetInfo('extension_flag'):
7949 #gen_cmd = func.GetInfo('gen_cmd')
7950 #if gen_cmd == True or gen_cmd == None:
7951 if func
.GetInfo('unit_test') == False:
7952 file.Write("// TODO(gman): %s\n" % func
.name
)
7954 func
.WriteServiceUnitTest(file, {
7955 'test_name': test_name
7959 file = CHeaderWriter(
7961 "// It is included by gles2_cmd_decoder_unittest_base.cc\n")
7963 """void GLES2DecoderTestBase::SetupInitCapabilitiesExpectations() {
7965 for capability
in _CAPABILITY_FLAGS
:
7966 file.Write(" ExpectEnableDisable(GL_%s, %s);\n" %
7967 (capability
['name'].upper(),
7968 ('false', 'true')['default' in capability
]))
7971 void GLES2DecoderTestBase::SetupInitStateExpectations() {
7974 # We need to sort the keys so the expectations match
7975 for state_name
in sorted(_STATES
.keys()):
7976 state
= _STATES
[state_name
]
7977 if state
['type'] == 'FrontBack':
7978 num_states
= len(state
['states'])
7979 for ndx
, group
in enumerate(Grouper(num_states
/ 2, state
['states'])):
7982 if 'expected' in item
:
7983 args
.append(item
['expected'])
7985 args
.append(item
['default'])
7987 " EXPECT_CALL(*gl_, %s(%s, %s))\n" %
7988 (state
['func'], ('GL_FRONT', 'GL_BACK')[ndx
], ", ".join(args
)))
7989 file.Write(" .Times(1)\n")
7990 file.Write(" .RetiresOnSaturation();\n")
7991 elif state
['type'] == 'NamedParameter':
7992 for item
in state
['states']:
7993 if 'extension_flag' in item
:
7994 file.Write(" if (group_->feature_info()->feature_flags().%s) {\n" %
7995 item
['extension_flag'])
7997 expect_value
= item
['default']
7998 if isinstance(expect_value
, list):
7999 # TODO: Currently we do not check array values.
8003 " EXPECT_CALL(*gl_, %s(%s, %s))\n" %
8006 if 'enum_set' in item
else item
['enum']),
8008 file.Write(" .Times(1)\n")
8009 file.Write(" .RetiresOnSaturation();\n")
8010 if 'extension_flag' in item
:
8013 if 'extension_flag' in state
:
8014 file.Write(" if (group_->feature_info()->feature_flags().%s) {\n" %
8015 state
['extension_flag'])
8018 for item
in state
['states']:
8019 if 'expected' in item
:
8020 args
.append(item
['expected'])
8022 args
.append(item
['default'])
8023 # TODO: Currently we do not check array values.
8024 args
= ["_" if isinstance(arg
, list) else arg
for arg
in args
]
8025 file.Write(" EXPECT_CALL(*gl_, %s(%s))\n" %
8026 (state
['func'], ", ".join(args
)))
8027 file.Write(" .Times(1)\n")
8028 file.Write(" .RetiresOnSaturation();\n")
8029 if 'extension_flag' in state
:
8035 def WriteServiceUnitTestsForExtensions(self
, filename
):
8036 """Writes the service decorder unit tests for functions with extension_flag.
8038 The functions are special in that they need a specific unit test
8039 baseclass to turn on the extension.
8041 functions
= [f
for f
in self
.functions
if f
.GetInfo('extension_flag')]
8042 file = CHeaderWriter(
8044 "// It is included by gles2_cmd_decoder_unittest_extensions.cc\n")
8045 for func
in functions
:
8047 if func
.GetInfo('unit_test') == False:
8048 file.Write("// TODO(gman): %s\n" % func
.name
)
8050 extension
= ToCamelCase(
8051 ToGLExtensionString(func
.GetInfo('extension_flag')))
8052 func
.WriteServiceUnitTest(file, {
8053 'test_name': 'GLES2DecoderTestWith%s' % extension
8058 def WriteGLES2Header(self
, filename
):
8059 """Writes the GLES2 header."""
8060 file = CHeaderWriter(
8062 "// This file contains Chromium-specific GLES2 declarations.\n\n")
8064 for func
in self
.original_functions
:
8065 func
.WriteGLES2Header(file)
8070 def WriteGLES2CLibImplementation(self
, filename
):
8071 """Writes the GLES2 c lib implementation."""
8072 file = CHeaderWriter(
8074 "// These functions emulate GLES2 over command buffers.\n")
8076 for func
in self
.original_functions
:
8077 func
.WriteGLES2CLibImplementation(file)
8082 extern const NameToFunc g_gles2_function_table[] = {
8084 for func
in self
.original_functions
:
8086 ' { "gl%s", reinterpret_cast<GLES2FunctionPointer>(gl%s), },\n' %
8087 (func
.name
, func
.name
))
8088 file.Write(""" { NULL, NULL, },
8091 } // namespace gles2
8095 def WriteGLES2InterfaceHeader(self
, filename
):
8096 """Writes the GLES2 interface header."""
8097 file = CHeaderWriter(
8099 "// This file is included by gles2_interface.h to declare the\n"
8100 "// GL api functions.\n")
8101 for func
in self
.original_functions
:
8102 func
.WriteGLES2InterfaceHeader(file)
8105 def WriteGLES2InterfaceStub(self
, filename
):
8106 """Writes the GLES2 interface stub header."""
8107 file = CHeaderWriter(
8109 "// This file is included by gles2_interface_stub.h.\n")
8110 for func
in self
.original_functions
:
8111 func
.WriteGLES2InterfaceStub(file)
8114 def WriteGLES2InterfaceStubImpl(self
, filename
):
8115 """Writes the GLES2 interface header."""
8116 file = CHeaderWriter(
8118 "// This file is included by gles2_interface_stub.cc.\n")
8119 for func
in self
.original_functions
:
8120 func
.WriteGLES2InterfaceStubImpl(file)
8123 def WriteGLES2ImplementationHeader(self
, filename
):
8124 """Writes the GLES2 Implementation header."""
8125 file = CHeaderWriter(
8127 "// This file is included by gles2_implementation.h to declare the\n"
8128 "// GL api functions.\n")
8129 for func
in self
.original_functions
:
8130 func
.WriteGLES2ImplementationHeader(file)
8133 def WriteGLES2Implementation(self
, filename
):
8134 """Writes the GLES2 Implementation."""
8135 file = CHeaderWriter(
8137 "// This file is included by gles2_implementation.cc to define the\n"
8138 "// GL api functions.\n")
8139 for func
in self
.original_functions
:
8140 func
.WriteGLES2Implementation(file)
8143 def WriteGLES2TraceImplementationHeader(self
, filename
):
8144 """Writes the GLES2 Trace Implementation header."""
8145 file = CHeaderWriter(
8147 "// This file is included by gles2_trace_implementation.h\n")
8148 for func
in self
.original_functions
:
8149 func
.WriteGLES2TraceImplementationHeader(file)
8152 def WriteGLES2TraceImplementation(self
, filename
):
8153 """Writes the GLES2 Trace Implementation."""
8154 file = CHeaderWriter(
8156 "// This file is included by gles2_trace_implementation.cc\n")
8157 for func
in self
.original_functions
:
8158 func
.WriteGLES2TraceImplementation(file)
8161 def WriteGLES2ImplementationUnitTests(self
, filename
):
8162 """Writes the GLES2 helper header."""
8163 file = CHeaderWriter(
8165 "// This file is included by gles2_implementation.h to declare the\n"
8166 "// GL api functions.\n")
8167 for func
in self
.original_functions
:
8168 func
.WriteGLES2ImplementationUnitTest(file)
8171 def WriteServiceUtilsHeader(self
, filename
):
8172 """Writes the gles2 auto generated utility header."""
8173 file = CHeaderWriter(filename
)
8174 for name
in sorted(_NAMED_TYPE_INFO
.keys()):
8175 named_type
= NamedType(_NAMED_TYPE_INFO
[name
])
8176 if named_type
.IsConstant():
8178 file.Write("ValueValidator<%s> %s;\n" %
8179 (named_type
.GetType(), ToUnderscore(name
)))
8183 def WriteServiceUtilsImplementation(self
, filename
):
8184 """Writes the gles2 auto generated utility implementation."""
8185 file = CHeaderWriter(filename
)
8186 names
= sorted(_NAMED_TYPE_INFO
.keys())
8188 named_type
= NamedType(_NAMED_TYPE_INFO
[name
])
8189 if named_type
.IsConstant():
8191 if named_type
.GetValidValues():
8192 file.Write("static const %s valid_%s_table[] = {\n" %
8193 (named_type
.GetType(), ToUnderscore(name
)))
8194 for value
in named_type
.GetValidValues():
8195 file.Write(" %s,\n" % value
)
8198 file.Write("Validators::Validators()")
8200 for count
, name
in enumerate(names
):
8201 named_type
= NamedType(_NAMED_TYPE_INFO
[name
])
8202 if named_type
.IsConstant():
8204 if named_type
.GetValidValues():
8205 code
= """%(pre)s%(name)s(
8206 valid_%(name)s_table, arraysize(valid_%(name)s_table))"""
8208 code
= "%(pre)s%(name)s()"
8210 'name': ToUnderscore(name
),
8215 file.Write("}\n\n");
8218 def WriteCommonUtilsHeader(self
, filename
):
8219 """Writes the gles2 common utility header."""
8220 file = CHeaderWriter(filename
)
8221 type_infos
= sorted(_NAMED_TYPE_INFO
.keys())
8222 for type_info
in type_infos
:
8223 if _NAMED_TYPE_INFO
[type_info
]['type'] == 'GLenum':
8224 file.Write("static std::string GetString%s(uint32_t value);\n" %
8229 def WriteCommonUtilsImpl(self
, filename
):
8230 """Writes the gles2 common utility header."""
8231 enum_re
= re
.compile(r
'\#define\s+(GL_[a-zA-Z0-9_]+)\s+([0-9A-Fa-fx]+)')
8233 for fname
in ['../../third_party/khronos/GLES2/gl2.h',
8234 '../../third_party/khronos/GLES2/gl2ext.h',
8235 '../../gpu/GLES2/gl2chromium.h',
8236 '../../gpu/GLES2/gl2extchromium.h']:
8237 lines
= open(fname
).readlines()
8239 m
= enum_re
.match(line
)
8243 if len(value
) <= 10 and not value
in dict:
8246 file = CHeaderWriter(filename
)
8247 file.Write("static const GLES2Util::EnumToString "
8248 "enum_to_string_table[] = {\n")
8250 file.Write(' { %s, "%s", },\n' % (value
, dict[value
]))
8253 const GLES2Util::EnumToString* const GLES2Util::enum_to_string_table_ =
8254 enum_to_string_table;
8255 const size_t GLES2Util::enum_to_string_table_len_ =
8256 sizeof(enum_to_string_table) / sizeof(enum_to_string_table[0]);
8260 enums
= sorted(_NAMED_TYPE_INFO
.keys())
8262 if _NAMED_TYPE_INFO
[enum
]['type'] == 'GLenum':
8263 file.Write("std::string GLES2Util::GetString%s(uint32_t value) {\n" %
8265 if len(_NAMED_TYPE_INFO
[enum
]['valid']) > 0:
8266 file.Write(" static const EnumToString string_table[] = {\n")
8267 for value
in _NAMED_TYPE_INFO
[enum
]['valid']:
8268 file.Write(' { %s, "%s" },\n' % (value
, value
))
8270 return GLES2Util::GetQualifiedEnumString(
8271 string_table, arraysize(string_table), value);
8276 file.Write(""" return GLES2Util::GetQualifiedEnumString(
8283 def WritePepperGLES2Interface(self
, filename
, dev
):
8284 """Writes the Pepper OpenGLES interface definition."""
8285 file = CWriter(filename
)
8286 file.Write(_LICENSE
)
8287 file.Write(_DO_NOT_EDIT_WARNING
)
8289 file.Write("label Chrome {\n")
8290 file.Write(" M39 = 1.0\n")
8291 file.Write("};\n\n")
8295 file.Write("[version=1.0]\n")
8296 file.Write("describe {\n")
8297 for gltype
in ['GLbitfield', 'GLboolean', 'GLbyte', 'GLclampf',
8298 'GLclampx', 'GLenum', 'GLfixed', 'GLfloat', 'GLint',
8299 'GLintptr', 'GLshort', 'GLsizei', 'GLsizeiptr',
8300 'GLubyte', 'GLuint', 'GLushort']:
8301 file.Write(" %s;\n" % gltype
)
8302 file.Write(" %s_ptr_t;\n" % gltype
)
8303 file.Write("};\n\n")
8306 file.Write("#inline c\n")
8307 file.Write("#include \"ppapi/c/pp_resource.h\"\n")
8309 file.Write("#include \"ppapi/c/ppb_opengles2.h\"\n\n")
8311 file.Write("\n#ifndef __gl2_h_\n")
8312 for (k
, v
) in _GL_TYPES
.iteritems():
8313 file.Write("typedef %s %s;\n" % (v
, k
))
8314 file.Write("#ifdef _WIN64\n")
8315 for (k
, v
) in _GL_TYPES_64
.iteritems():
8316 file.Write("typedef %s %s;\n" % (v
, k
))
8317 file.Write("#else\n")
8318 for (k
, v
) in _GL_TYPES_32
.iteritems():
8319 file.Write("typedef %s %s;\n" % (v
, k
))
8320 file.Write("#endif // _WIN64\n")
8321 file.Write("#endif // __gl2_h_\n\n")
8322 file.Write("#endinl\n")
8324 for interface
in self
.pepper_interfaces
:
8325 if interface
.dev
!= dev
:
8327 # Historically, we provide OpenGLES2 interfaces with struct
8328 # namespace. Not to break code which uses the interface as
8329 # "struct OpenGLES2", we put it in struct namespace.
8330 file.Write('\n[macro="%s", force_struct_namespace]\n' %
8331 interface
.GetInterfaceName())
8332 file.Write("interface %s {\n" % interface
.GetStructName())
8333 for func
in self
.original_functions
:
8334 if not func
.InPepperInterface(interface
):
8337 ret_type
= func
.MapCTypeToPepperIdlType(func
.return_type
,
8338 is_for_return_type
=True)
8339 func_prefix
= " %s %s(" % (ret_type
, func
.GetPepperName())
8340 file.Write(func_prefix
)
8341 file.Write("[in] PP_Resource context")
8342 for arg
in func
.MakeTypedPepperIdlArgStrings():
8343 file.Write(",\n" + " " * len(func_prefix
) + arg
)
8345 file.Write("};\n\n")
8350 def WritePepperGLES2Implementation(self
, filename
):
8351 """Writes the Pepper OpenGLES interface implementation."""
8353 file = CWriter(filename
)
8354 file.Write(_LICENSE
)
8355 file.Write(_DO_NOT_EDIT_WARNING
)
8357 file.Write("#include \"ppapi/shared_impl/ppb_opengles2_shared.h\"\n\n")
8358 file.Write("#include \"base/logging.h\"\n")
8359 file.Write("#include \"gpu/command_buffer/client/gles2_implementation.h\"\n")
8360 file.Write("#include \"ppapi/shared_impl/ppb_graphics_3d_shared.h\"\n")
8361 file.Write("#include \"ppapi/thunk/enter.h\"\n\n")
8363 file.Write("namespace ppapi {\n\n")
8364 file.Write("namespace {\n\n")
8366 file.Write("typedef thunk::EnterResource<thunk::PPB_Graphics3D_API>"
8369 file.Write("gpu::gles2::GLES2Implementation* ToGles2Impl(Enter3D*"
8371 file.Write(" DCHECK(enter);\n")
8372 file.Write(" DCHECK(enter->succeeded());\n")
8373 file.Write(" return static_cast<PPB_Graphics3D_Shared*>(enter->object())->"
8375 file.Write("}\n\n");
8377 for func
in self
.original_functions
:
8378 if not func
.InAnyPepperExtension():
8381 original_arg
= func
.MakeTypedPepperArgString("")
8382 context_arg
= "PP_Resource context_id"
8383 if len(original_arg
):
8384 arg
= context_arg
+ ", " + original_arg
8387 file.Write("%s %s(%s) {\n" %
8388 (func
.return_type
, func
.GetPepperName(), arg
))
8389 file.Write(" Enter3D enter(context_id, true);\n")
8390 file.Write(" if (enter.succeeded()) {\n")
8392 return_str
= "" if func
.return_type
== "void" else "return "
8393 file.Write(" %sToGles2Impl(&enter)->%s(%s);\n" %
8394 (return_str
, func
.original_name
,
8395 func
.MakeOriginalArgString("")))
8397 if func
.return_type
== "void":
8400 file.Write(" else {\n")
8401 file.Write(" return %s;\n" % func
.GetErrorReturnString())
8405 file.Write("} // namespace\n")
8407 for interface
in self
.pepper_interfaces
:
8408 file.Write("const %s* PPB_OpenGLES2_Shared::Get%sInterface() {\n" %
8409 (interface
.GetStructName(), interface
.GetName()))
8410 file.Write(" static const struct %s "
8411 "ppb_opengles2 = {\n" % interface
.GetStructName())
8413 file.Write(",\n &".join(
8414 f
.GetPepperName() for f
in self
.original_functions
8415 if f
.InPepperInterface(interface
)))
8419 file.Write(" return &ppb_opengles2;\n")
8422 file.Write("} // namespace ppapi\n")
8425 def WriteGLES2ToPPAPIBridge(self
, filename
):
8426 """Connects GLES2 helper library to PPB_OpenGLES2 interface"""
8428 file = CWriter(filename
)
8429 file.Write(_LICENSE
)
8430 file.Write(_DO_NOT_EDIT_WARNING
)
8432 file.Write("#ifndef GL_GLEXT_PROTOTYPES\n")
8433 file.Write("#define GL_GLEXT_PROTOTYPES\n")
8434 file.Write("#endif\n")
8435 file.Write("#include <GLES2/gl2.h>\n")
8436 file.Write("#include <GLES2/gl2ext.h>\n")
8437 file.Write("#include \"ppapi/lib/gl/gles2/gl2ext_ppapi.h\"\n\n")
8439 for func
in self
.original_functions
:
8440 if not func
.InAnyPepperExtension():
8443 interface
= self
.interface_info
[func
.GetInfo('pepper_interface') or '']
8445 file.Write("%s GL_APIENTRY gl%s(%s) {\n" %
8446 (func
.return_type
, func
.GetPepperName(),
8447 func
.MakeTypedPepperArgString("")))
8448 return_str
= "" if func
.return_type
== "void" else "return "
8449 interface_str
= "glGet%sInterfacePPAPI()" % interface
.GetName()
8450 original_arg
= func
.MakeOriginalArgString("")
8451 context_arg
= "glGetCurrentContextPPAPI()"
8452 if len(original_arg
):
8453 arg
= context_arg
+ ", " + original_arg
8456 if interface
.GetName():
8457 file.Write(" const struct %s* ext = %s;\n" %
8458 (interface
.GetStructName(), interface_str
))
8459 file.Write(" if (ext)\n")
8460 file.Write(" %sext->%s(%s);\n" %
8461 (return_str
, func
.GetPepperName(), arg
))
8463 file.Write(" %s0;\n" % return_str
)
8465 file.Write(" %s%s->%s(%s);\n" %
8466 (return_str
, interface_str
, func
.GetPepperName(), arg
))
8470 def WriteMojoGLCallVisitor(self
, filename
):
8471 """Provides the GL implementation for mojo"""
8472 file = CWriter(filename
)
8473 file.Write(_LICENSE
)
8474 file.Write(_DO_NOT_EDIT_WARNING
)
8476 for func
in self
.original_functions
:
8477 if not func
.IsCoreGLFunction():
8479 file.Write("VISIT_GL_CALL(%s, %s, (%s), (%s))\n" %
8480 (func
.name
, func
.return_type
,
8481 func
.MakeTypedOriginalArgString(""),
8482 func
.MakeOriginalArgString("")))
8486 def WriteMojoGLCallVisitorForExtension(self
, filename
, extension
):
8487 """Provides the GL implementation for mojo for a particular extension"""
8488 file = CWriter(filename
)
8489 file.Write(_LICENSE
)
8490 file.Write(_DO_NOT_EDIT_WARNING
)
8492 for func
in self
.original_functions
:
8493 if func
.GetInfo("extension") != extension
:
8495 file.Write("VISIT_GL_CALL(%s, %s, (%s), (%s))\n" %
8496 (func
.name
, func
.return_type
,
8497 func
.MakeTypedOriginalArgString(""),
8498 func
.MakeOriginalArgString("")))
8502 def Format(generated_files
):
8503 for filename
in generated_files
:
8504 call(["clang-format", "-i", "-style=chromium", filename
])
8507 """This is the main function."""
8508 parser
= OptionParser()
8511 help="base directory for resulting files, under chrome/src. default is "
8512 "empty. Use this if you want the result stored under gen.")
8514 "-v", "--verbose", action
="store_true",
8515 help="prints more output.")
8517 (options
, args
) = parser
.parse_args(args
=argv
)
8519 # Add in states and capabilites to GLState
8520 gl_state_valid
= _NAMED_TYPE_INFO
['GLState']['valid']
8521 for state_name
in sorted(_STATES
.keys()):
8522 state
= _STATES
[state_name
]
8523 if 'extension_flag' in state
:
8526 if not state
['enum'] in gl_state_valid
:
8527 gl_state_valid
.append(state
['enum'])
8529 for item
in state
['states']:
8530 if 'extension_flag' in item
:
8532 if not item
['enum'] in gl_state_valid
:
8533 gl_state_valid
.append(item
['enum'])
8534 for capability
in _CAPABILITY_FLAGS
:
8535 valid_value
= "GL_%s" % capability
['name'].upper()
8536 if not valid_value
in gl_state_valid
:
8537 gl_state_valid
.append(valid_value
)
8539 # This script lives under gpu/command_buffer, cd to base directory.
8540 os
.chdir(os
.path
.dirname(__file__
) + "/../..")
8542 gen
= GLGenerator(options
.verbose
)
8543 gen
.ParseGLH("gpu/command_buffer/cmd_buffer_functions.txt")
8545 # Support generating files under gen/
8546 if options
.output_dir
!= None:
8547 os
.chdir(options
.output_dir
)
8549 gen
.WritePepperGLES2Interface("ppapi/api/ppb_opengles2.idl", False)
8550 gen
.WritePepperGLES2Interface("ppapi/api/dev/ppb_opengles2ext_dev.idl", True)
8551 gen
.WriteGLES2ToPPAPIBridge("ppapi/lib/gl/gles2/gles2.c")
8552 gen
.WritePepperGLES2Implementation(
8553 "ppapi/shared_impl/ppb_opengles2_shared.cc")
8554 os
.chdir("gpu/command_buffer")
8555 gen
.WriteCommandIds("common/gles2_cmd_ids_autogen.h")
8556 gen
.WriteFormat("common/gles2_cmd_format_autogen.h")
8557 gen
.WriteFormatTest("common/gles2_cmd_format_test_autogen.h")
8558 gen
.WriteGLES2InterfaceHeader("client/gles2_interface_autogen.h")
8559 gen
.WriteGLES2InterfaceStub("client/gles2_interface_stub_autogen.h")
8560 gen
.WriteGLES2InterfaceStubImpl(
8561 "client/gles2_interface_stub_impl_autogen.h")
8562 gen
.WriteGLES2ImplementationHeader("client/gles2_implementation_autogen.h")
8563 gen
.WriteGLES2Implementation("client/gles2_implementation_impl_autogen.h")
8564 gen
.WriteGLES2ImplementationUnitTests(
8565 "client/gles2_implementation_unittest_autogen.h")
8566 gen
.WriteGLES2TraceImplementationHeader(
8567 "client/gles2_trace_implementation_autogen.h")
8568 gen
.WriteGLES2TraceImplementation(
8569 "client/gles2_trace_implementation_impl_autogen.h")
8570 gen
.WriteGLES2CLibImplementation("client/gles2_c_lib_autogen.h")
8571 gen
.WriteCmdHelperHeader("client/gles2_cmd_helper_autogen.h")
8572 gen
.WriteServiceImplementation("service/gles2_cmd_decoder_autogen.h")
8573 gen
.WriteServiceContextStateHeader("service/context_state_autogen.h")
8574 gen
.WriteServiceContextStateImpl("service/context_state_impl_autogen.h")
8575 gen
.WriteClientContextStateHeader("client/client_context_state_autogen.h")
8576 gen
.WriteClientContextStateImpl(
8577 "client/client_context_state_impl_autogen.h")
8578 gen
.WriteServiceUnitTests("service/gles2_cmd_decoder_unittest_%d_autogen.h")
8579 gen
.WriteServiceUnitTestsForExtensions(
8580 "service/gles2_cmd_decoder_unittest_extensions_autogen.h")
8581 gen
.WriteServiceUtilsHeader("service/gles2_cmd_validation_autogen.h")
8582 gen
.WriteServiceUtilsImplementation(
8583 "service/gles2_cmd_validation_implementation_autogen.h")
8584 gen
.WriteCommonUtilsHeader("common/gles2_cmd_utils_autogen.h")
8585 gen
.WriteCommonUtilsImpl("common/gles2_cmd_utils_implementation_autogen.h")
8586 gen
.WriteGLES2Header("../GLES2/gl2chromium_autogen.h")
8587 mojo_gles2_prefix
= "../../mojo/public/c/gles2/gles2_call_visitor"
8588 gen
.WriteMojoGLCallVisitor(mojo_gles2_prefix
+ "_autogen.h")
8589 gen
.WriteMojoGLCallVisitorForExtension(
8590 mojo_gles2_prefix
+ "_chromium_texture_mailbox_autogen.h",
8591 "CHROMIUM_texture_mailbox")
8592 gen
.WriteMojoGLCallVisitorForExtension(
8593 mojo_gles2_prefix
+ "_chromium_sync_point_autogen.h",
8594 "CHROMIUM_sync_point")
8597 "common/gles2_cmd_format_autogen.h",
8598 "common/gles2_cmd_format_test_autogen.h",
8599 "common/gles2_cmd_ids_autogen.h",
8600 "common/gles2_cmd_utils_autogen.h",
8601 "common/gles2_cmd_utils_implementation_autogen.h",
8602 "client/client_context_state_autogen.h",
8603 "client/client_context_state_impl_autogen.h",
8604 "client/gles2_cmd_helper_autogen.h",
8605 "client/gles2_c_lib_autogen.h",
8606 "client/gles2_implementation_autogen.h",
8607 "client/gles2_implementation_impl_autogen.h",
8608 "client/gles2_implementation_unittest_autogen.h",
8609 "client/gles2_interface_autogen.h",
8610 "client/gles2_interface_stub_autogen.h",
8611 "client/gles2_interface_stub_impl_autogen.h",
8612 "client/gles2_trace_implementation_autogen.h",
8613 "client/gles2_trace_implementation_impl_autogen.h",
8614 "service/context_state_autogen.h",
8615 "service/context_state_impl_autogen.h",
8616 "service/gles2_cmd_decoder_autogen.h",
8617 "service/gles2_cmd_decoder_unittest_0_autogen.h",
8618 "service/gles2_cmd_decoder_unittest_1_autogen.h",
8619 "service/gles2_cmd_decoder_unittest_2_autogen.h",
8620 "service/gles2_cmd_decoder_unittest_3_autogen.h",
8621 "service/gles2_cmd_validation_autogen.h",
8622 "service/gles2_cmd_validation_implementation_autogen.h"])
8624 mojo_gles2_prefix
= "mojo/public/c/gles2/gles2_call_visitor"
8626 "gpu/GLES2/gl2chromium_autogen.h",
8627 mojo_gles2_prefix
+ "_autogen.h",
8628 mojo_gles2_prefix
+ "_chromium_texture_mailbox_autogen.h",
8629 mojo_gles2_prefix
+ "_chromium_sync_point_autogen.h",
8630 "ppapi/lib/gl/gles2/gles2.c",
8631 "ppapi/shared_impl/ppb_opengles2_shared.cc"])
8634 print "%d errors" % gen
.errors
8639 if __name__
== '__main__':
8640 sys
.exit(main(sys
.argv
[1:]))