Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1019)

Side by Side Diff: gpu/command_buffer/build_gles2_cmd_buffer.py

Issue 272953002: Make command buffer generator infer GL array element type from the GL prototype (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address review comments. Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | ppapi/shared_impl/ppb_opengles2_shared.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """code generator for GLES2 command buffers.""" 6 """code generator for GLES2 command buffers."""
7 7
8 import itertools 8 import itertools
9 import os 9 import os
10 import os.path 10 import os.path
(...skipping 1220 matching lines...) Expand 10 before | Expand all | Expand 10 after
1231 # gen_cmd: Whether or not this function geneates a command. Default = True. 1231 # gen_cmd: Whether or not this function geneates a command. Default = True.
1232 # immediate: Whether or not to generate an immediate command for the GL 1232 # immediate: Whether or not to generate an immediate command for the GL
1233 # function. The default is if there is exactly 1 pointer argument 1233 # function. The default is if there is exactly 1 pointer argument
1234 # in the GL function an immediate command is generated. 1234 # in the GL function an immediate command is generated.
1235 # bucket: True to generate a bucket version of the command. 1235 # bucket: True to generate a bucket version of the command.
1236 # impl_func: Whether or not to generate the GLES2Implementation part of this 1236 # impl_func: Whether or not to generate the GLES2Implementation part of this
1237 # command. 1237 # command.
1238 # impl_decl: Whether or not to generate the GLES2Implementation declaration 1238 # impl_decl: Whether or not to generate the GLES2Implementation declaration
1239 # for this command. 1239 # for this command.
1240 # needs_size: If true a data_size field is added to the command. 1240 # needs_size: If true a data_size field is added to the command.
1241 # data_type: The type of data the command uses. For PUTn or PUT types.
1242 # count: The number of units per element. For PUTn or PUT types. 1241 # count: The number of units per element. For PUTn or PUT types.
1243 # unit_test: If False no service side unit test will be generated. 1242 # unit_test: If False no service side unit test will be generated.
1244 # client_test: If False no client side unit test will be generated. 1243 # client_test: If False no client side unit test will be generated.
1245 # expectation: If False the unit test will have no expected calls. 1244 # expectation: If False the unit test will have no expected calls.
1246 # gen_func: Name of function that generates GL resource for corresponding 1245 # gen_func: Name of function that generates GL resource for corresponding
1247 # bind function. 1246 # bind function.
1248 # states: array of states that get set by this function corresponding to 1247 # states: array of states that get set by this function corresponding to
1249 # the given arguments 1248 # the given arguments
1250 # state_flag: name of flag that is set to true when function is called. 1249 # state_flag: name of flag that is set to true when function is called.
1251 # no_gl: no GL function is called. 1250 # no_gl: no GL function is called.
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1352 'ColorMask': { 1351 'ColorMask': {
1353 'type': 'StateSet', 1352 'type': 'StateSet',
1354 'state': 'ColorMask', 1353 'state': 'ColorMask',
1355 'no_gl': True, 1354 'no_gl': True,
1356 'expectation': False, 1355 'expectation': False,
1357 }, 1356 },
1358 'ConsumeTextureCHROMIUM': { 1357 'ConsumeTextureCHROMIUM': {
1359 'decoder_func': 'DoConsumeTextureCHROMIUM', 1358 'decoder_func': 'DoConsumeTextureCHROMIUM',
1360 'impl_func': False, 1359 'impl_func': False,
1361 'type': 'PUT', 1360 'type': 'PUT',
1362 'data_type': 'GLbyte',
1363 'count': 64, # GL_MAILBOX_SIZE_CHROMIUM 1361 'count': 64, # GL_MAILBOX_SIZE_CHROMIUM
1364 'unit_test': False, 1362 'unit_test': False,
1365 'client_test': False, 1363 'client_test': False,
1366 'extension': True, 1364 'extension': True,
1367 'chromium': True, 1365 'chromium': True,
1368 'trace_level': 1, 1366 'trace_level': 1,
1369 }, 1367 },
1370 'ClearStencil': { 1368 'ClearStencil': {
1371 'type': 'StateSet', 1369 'type': 'StateSet',
1372 'state': 'ClearStencil', 1370 'state': 'ClearStencil',
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
1946 'impl_func': False, 1944 'impl_func': False,
1947 'unit_test': False, 1945 'unit_test': False,
1948 'client_test': False, 1946 'client_test': False,
1949 'extension': True, 1947 'extension': True,
1950 'chromium': True, 1948 'chromium': True,
1951 }, 1949 },
1952 'ProduceTextureCHROMIUM': { 1950 'ProduceTextureCHROMIUM': {
1953 'decoder_func': 'DoProduceTextureCHROMIUM', 1951 'decoder_func': 'DoProduceTextureCHROMIUM',
1954 'impl_func': False, 1952 'impl_func': False,
1955 'type': 'PUT', 1953 'type': 'PUT',
1956 'data_type': 'GLbyte',
1957 'count': 64, # GL_MAILBOX_SIZE_CHROMIUM 1954 'count': 64, # GL_MAILBOX_SIZE_CHROMIUM
1958 'unit_test': False, 1955 'unit_test': False,
1959 'client_test': False, 1956 'client_test': False,
1960 'extension': True, 1957 'extension': True,
1961 'chromium': True, 1958 'chromium': True,
1962 'trace_level': 1, 1959 'trace_level': 1,
1963 }, 1960 },
1964 'RenderbufferStorage': { 1961 'RenderbufferStorage': {
1965 'decoder_func': 'DoRenderbufferStorage', 1962 'decoder_func': 'DoRenderbufferStorage',
1966 'gl_test_func': 'glRenderbufferStorageEXT', 1963 'gl_test_func': 'glRenderbufferStorageEXT',
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
2064 }, 2061 },
2065 }, 2062 },
2066 'TexParameteri': { 2063 'TexParameteri': {
2067 'decoder_func': 'DoTexParameteri', 2064 'decoder_func': 'DoTexParameteri',
2068 'valid_args': { 2065 'valid_args': {
2069 '2': 'GL_NEAREST' 2066 '2': 'GL_NEAREST'
2070 }, 2067 },
2071 }, 2068 },
2072 'TexParameterfv': { 2069 'TexParameterfv': {
2073 'type': 'PUT', 2070 'type': 'PUT',
2074 'data_type': 'GLfloat',
2075 'data_value': 'GL_NEAREST', 2071 'data_value': 'GL_NEAREST',
2076 'count': 1, 2072 'count': 1,
2077 'decoder_func': 'DoTexParameterfv', 2073 'decoder_func': 'DoTexParameterfv',
2078 'gl_test_func': 'glTexParameterf', 2074 'gl_test_func': 'glTexParameterf',
2079 'first_element_only': True, 2075 'first_element_only': True,
2080 }, 2076 },
2081 'TexParameteriv': { 2077 'TexParameteriv': {
2082 'type': 'PUT', 2078 'type': 'PUT',
2083 'data_type': 'GLint',
2084 'data_value': 'GL_NEAREST', 2079 'data_value': 'GL_NEAREST',
2085 'count': 1, 2080 'count': 1,
2086 'decoder_func': 'DoTexParameteriv', 2081 'decoder_func': 'DoTexParameteriv',
2087 'gl_test_func': 'glTexParameteri', 2082 'gl_test_func': 'glTexParameteri',
2088 'first_element_only': True, 2083 'first_element_only': True,
2089 }, 2084 },
2090 'TexSubImage2D': { 2085 'TexSubImage2D': {
2091 'type': 'Manual', 2086 'type': 'Manual',
2092 'immediate': False, 2087 'immediate': False,
2093 'client_test': False, 2088 'client_test': False,
2094 'cmd_args': 'GLenumTextureTarget target, GLint level, ' 2089 'cmd_args': 'GLenumTextureTarget target, GLint level, '
2095 'GLint xoffset, GLint yoffset, ' 2090 'GLint xoffset, GLint yoffset, '
2096 'GLsizei width, GLsizei height, ' 2091 'GLsizei width, GLsizei height, '
2097 'GLenumTextureFormat format, GLenumPixelType type, ' 2092 'GLenumTextureFormat format, GLenumPixelType type, '
2098 'const void* pixels, GLboolean internal' 2093 'const void* pixels, GLboolean internal'
2099 }, 2094 },
2100 'Uniform1f': {'type': 'PUTXn', 'data_type': 'GLfloat', 'count': 1}, 2095 'Uniform1f': {'type': 'PUTXn', 'count': 1},
2101 'Uniform1fv': { 2096 'Uniform1fv': {
2102 'type': 'PUTn', 2097 'type': 'PUTn',
2103 'data_type': 'GLfloat',
2104 'count': 1, 2098 'count': 1,
2105 'decoder_func': 'DoUniform1fv', 2099 'decoder_func': 'DoUniform1fv',
2106 }, 2100 },
2107 'Uniform1i': {'decoder_func': 'DoUniform1i', 'unit_test': False}, 2101 'Uniform1i': {'decoder_func': 'DoUniform1i', 'unit_test': False},
2108 'Uniform1iv': { 2102 'Uniform1iv': {
2109 'type': 'PUTn', 2103 'type': 'PUTn',
2110 'data_type': 'GLint',
2111 'count': 1, 2104 'count': 1,
2112 'decoder_func': 'DoUniform1iv', 2105 'decoder_func': 'DoUniform1iv',
2113 'unit_test': False, 2106 'unit_test': False,
2114 }, 2107 },
2115 'Uniform2i': {'type': 'PUTXn', 'data_type': 'GLint', 'count': 2}, 2108 'Uniform2i': {'type': 'PUTXn', 'count': 2},
2116 'Uniform2f': {'type': 'PUTXn', 'data_type': 'GLfloat', 'count': 2}, 2109 'Uniform2f': {'type': 'PUTXn', 'count': 2},
2117 'Uniform2fv': { 2110 'Uniform2fv': {
2118 'type': 'PUTn', 2111 'type': 'PUTn',
2119 'data_type': 'GLfloat',
2120 'count': 2, 2112 'count': 2,
2121 'decoder_func': 'DoUniform2fv', 2113 'decoder_func': 'DoUniform2fv',
2122 }, 2114 },
2123 'Uniform2iv': { 2115 'Uniform2iv': {
2124 'type': 'PUTn', 2116 'type': 'PUTn',
2125 'data_type': 'GLint',
2126 'count': 2, 2117 'count': 2,
2127 'decoder_func': 'DoUniform2iv', 2118 'decoder_func': 'DoUniform2iv',
2128 }, 2119 },
2129 'Uniform3i': {'type': 'PUTXn', 'data_type': 'GLint', 'count': 3}, 2120 'Uniform3i': {'type': 'PUTXn', 'count': 3},
2130 'Uniform3f': {'type': 'PUTXn', 'data_type': 'GLfloat', 'count': 3}, 2121 'Uniform3f': {'type': 'PUTXn', 'count': 3},
2131 'Uniform3fv': { 2122 'Uniform3fv': {
2132 'type': 'PUTn', 2123 'type': 'PUTn',
2133 'data_type': 'GLfloat',
2134 'count': 3, 2124 'count': 3,
2135 'decoder_func': 'DoUniform3fv', 2125 'decoder_func': 'DoUniform3fv',
2136 }, 2126 },
2137 'Uniform3iv': { 2127 'Uniform3iv': {
2138 'type': 'PUTn', 2128 'type': 'PUTn',
2139 'data_type': 'GLint',
2140 'count': 3, 2129 'count': 3,
2141 'decoder_func': 'DoUniform3iv', 2130 'decoder_func': 'DoUniform3iv',
2142 }, 2131 },
2143 'Uniform4i': {'type': 'PUTXn', 'data_type': 'GLint', 'count': 4}, 2132 'Uniform4i': {'type': 'PUTXn', 'count': 4},
2144 'Uniform4f': {'type': 'PUTXn', 'data_type': 'GLfloat', 'count': 4}, 2133 'Uniform4f': {'type': 'PUTXn', 'count': 4},
2145 'Uniform4fv': { 2134 'Uniform4fv': {
2146 'type': 'PUTn', 2135 'type': 'PUTn',
2147 'data_type': 'GLfloat',
2148 'count': 4, 2136 'count': 4,
2149 'decoder_func': 'DoUniform4fv', 2137 'decoder_func': 'DoUniform4fv',
2150 }, 2138 },
2151 'Uniform4iv': { 2139 'Uniform4iv': {
2152 'type': 'PUTn', 2140 'type': 'PUTn',
2153 'data_type': 'GLint',
2154 'count': 4, 2141 'count': 4,
2155 'decoder_func': 'DoUniform4iv', 2142 'decoder_func': 'DoUniform4iv',
2156 }, 2143 },
2157 'UniformMatrix2fv': { 2144 'UniformMatrix2fv': {
2158 'type': 'PUTn', 2145 'type': 'PUTn',
2159 'data_type': 'GLfloat',
2160 'count': 4, 2146 'count': 4,
2161 'decoder_func': 'DoUniformMatrix2fv', 2147 'decoder_func': 'DoUniformMatrix2fv',
2162 }, 2148 },
2163 'UniformMatrix3fv': { 2149 'UniformMatrix3fv': {
2164 'type': 'PUTn', 2150 'type': 'PUTn',
2165 'data_type': 'GLfloat',
2166 'count': 9, 2151 'count': 9,
2167 'decoder_func': 'DoUniformMatrix3fv', 2152 'decoder_func': 'DoUniformMatrix3fv',
2168 }, 2153 },
2169 'UniformMatrix4fv': { 2154 'UniformMatrix4fv': {
2170 'type': 'PUTn', 2155 'type': 'PUTn',
2171 'data_type': 'GLfloat',
2172 'count': 16, 2156 'count': 16,
2173 'decoder_func': 'DoUniformMatrix4fv', 2157 'decoder_func': 'DoUniformMatrix4fv',
2174 }, 2158 },
2175 'UnmapBufferCHROMIUM': { 2159 'UnmapBufferCHROMIUM': {
2176 'gen_cmd': False, 2160 'gen_cmd': False,
2177 'extension': True, 2161 'extension': True,
2178 'chromium': True, 2162 'chromium': True,
2179 'client_test': False, 2163 'client_test': False,
2180 }, 2164 },
2181 'UnmapBufferSubDataCHROMIUM': { 2165 'UnmapBufferSubDataCHROMIUM': {
(...skipping 17 matching lines...) Expand all
2199 'pepper_interface': 'ChromiumMapSub', 2183 'pepper_interface': 'ChromiumMapSub',
2200 }, 2184 },
2201 'UseProgram': { 2185 'UseProgram': {
2202 'type': 'Bind', 2186 'type': 'Bind',
2203 'decoder_func': 'DoUseProgram', 2187 'decoder_func': 'DoUseProgram',
2204 }, 2188 },
2205 'ValidateProgram': {'decoder_func': 'DoValidateProgram'}, 2189 'ValidateProgram': {'decoder_func': 'DoValidateProgram'},
2206 'VertexAttrib1f': {'decoder_func': 'DoVertexAttrib1f'}, 2190 'VertexAttrib1f': {'decoder_func': 'DoVertexAttrib1f'},
2207 'VertexAttrib1fv': { 2191 'VertexAttrib1fv': {
2208 'type': 'PUT', 2192 'type': 'PUT',
2209 'data_type': 'GLfloat',
2210 'count': 1, 2193 'count': 1,
2211 'decoder_func': 'DoVertexAttrib1fv', 2194 'decoder_func': 'DoVertexAttrib1fv',
2212 }, 2195 },
2213 'VertexAttrib2f': {'decoder_func': 'DoVertexAttrib2f'}, 2196 'VertexAttrib2f': {'decoder_func': 'DoVertexAttrib2f'},
2214 'VertexAttrib2fv': { 2197 'VertexAttrib2fv': {
2215 'type': 'PUT', 2198 'type': 'PUT',
2216 'data_type': 'GLfloat',
2217 'count': 2, 2199 'count': 2,
2218 'decoder_func': 'DoVertexAttrib2fv', 2200 'decoder_func': 'DoVertexAttrib2fv',
2219 }, 2201 },
2220 'VertexAttrib3f': {'decoder_func': 'DoVertexAttrib3f'}, 2202 'VertexAttrib3f': {'decoder_func': 'DoVertexAttrib3f'},
2221 'VertexAttrib3fv': { 2203 'VertexAttrib3fv': {
2222 'type': 'PUT', 2204 'type': 'PUT',
2223 'data_type': 'GLfloat',
2224 'count': 3, 2205 'count': 3,
2225 'decoder_func': 'DoVertexAttrib3fv', 2206 'decoder_func': 'DoVertexAttrib3fv',
2226 }, 2207 },
2227 'VertexAttrib4f': {'decoder_func': 'DoVertexAttrib4f'}, 2208 'VertexAttrib4f': {'decoder_func': 'DoVertexAttrib4f'},
2228 'VertexAttrib4fv': { 2209 'VertexAttrib4fv': {
2229 'type': 'PUT', 2210 'type': 'PUT',
2230 'data_type': 'GLfloat',
2231 'count': 4, 2211 'count': 4,
2232 'decoder_func': 'DoVertexAttrib4fv', 2212 'decoder_func': 'DoVertexAttrib4fv',
2233 }, 2213 },
2234 'VertexAttribPointer': { 2214 'VertexAttribPointer': {
2235 'type': 'Manual', 2215 'type': 'Manual',
2236 'cmd_args': 'GLuint indx, GLintVertexAttribSize size, ' 2216 'cmd_args': 'GLuint indx, GLintVertexAttribSize size, '
2237 'GLenumVertexAttribType type, GLboolean normalized, ' 2217 'GLenumVertexAttribType type, GLboolean normalized, '
2238 'GLsizei stride, GLuint offset', 2218 'GLsizei stride, GLuint offset',
2239 'client_test': False, 2219 'client_test': False,
2240 }, 2220 },
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
2305 'cmd_args': 'GLenumDrawMode mode, GLint first, GLsizei count, ' 2285 'cmd_args': 'GLenumDrawMode mode, GLint first, GLsizei count, '
2306 'GLsizei primcount', 2286 'GLsizei primcount',
2307 'extension': True, 2287 'extension': True,
2308 'unit_test': False, 2288 'unit_test': False,
2309 'pepper_interface': 'InstancedArrays', 2289 'pepper_interface': 'InstancedArrays',
2310 'defer_draws': True, 2290 'defer_draws': True,
2311 }, 2291 },
2312 'DrawBuffersEXT': { 2292 'DrawBuffersEXT': {
2313 'type': 'PUTn', 2293 'type': 'PUTn',
2314 'decoder_func': 'DoDrawBuffersEXT', 2294 'decoder_func': 'DoDrawBuffersEXT',
2315 'data_type': 'GLenum',
2316 'count': 1, 2295 'count': 1,
2317 'client_test': False, 2296 'client_test': False,
2318 'unit_test': False, 2297 'unit_test': False,
2319 'extension': True, 2298 'extension': True,
2320 'pepper_interface': 'DrawBuffers', 2299 'pepper_interface': 'DrawBuffers',
2321 }, 2300 },
2322 'DrawElementsInstancedANGLE': { 2301 'DrawElementsInstancedANGLE': {
2323 'type': 'Manual', 2302 'type': 'Manual',
2324 'cmd_args': 'GLenumDrawMode mode, GLsizei count, ' 2303 'cmd_args': 'GLenumDrawMode mode, GLsizei count, '
2325 'GLenumIndexType type, GLuint index_offset, GLsizei primcount', 2304 'GLenumIndexType type, GLuint index_offset, GLsizei primcount',
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
2526 'WaitAllAsyncTexImage2DCHROMIUM': { 2505 'WaitAllAsyncTexImage2DCHROMIUM': {
2527 'type': 'Manual', 2506 'type': 'Manual',
2528 'immediate': False, 2507 'immediate': False,
2529 'client_test': False, 2508 'client_test': False,
2530 'extension': True, 2509 'extension': True,
2531 'chromium': True, 2510 'chromium': True,
2532 }, 2511 },
2533 'DiscardFramebufferEXT': { 2512 'DiscardFramebufferEXT': {
2534 'type': 'PUTn', 2513 'type': 'PUTn',
2535 'count': 1, 2514 'count': 1,
2536 'data_type': 'GLenum',
2537 'cmd_args': 'GLenum target, GLsizei count, ' 2515 'cmd_args': 'GLenum target, GLsizei count, '
2538 'const GLenum* attachments', 2516 'const GLenum* attachments',
2539 'decoder_func': 'DoDiscardFramebufferEXT', 2517 'decoder_func': 'DoDiscardFramebufferEXT',
2540 'unit_test': False, 2518 'unit_test': False,
2541 'client_test': False, 2519 'client_test': False,
2542 'extension': True, 2520 'extension': True,
2543 }, 2521 },
2544 'LoseContextCHROMIUM': { 2522 'LoseContextCHROMIUM': {
2545 'type': 'Manual', 2523 'type': 'Manual',
2546 'impl_func': True, 2524 'impl_func': True,
(...skipping 2176 matching lines...) Expand 10 before | Expand all | Expand 10 after
4723 static_cast<cmds::%(name)s::Result*>(shared_memory_address_); 4701 static_cast<cmds::%(name)s::Result*>(shared_memory_address_);
4724 result->size = 0; 4702 result->size = 0;
4725 cmds::%(name)s cmd; 4703 cmds::%(name)s cmd;
4726 cmd.Init(%(args)s); 4704 cmd.Init(%(args)s);
4727 EXPECT_EQ(error::%(parse_result)s, ExecuteCmd(cmd)); 4705 EXPECT_EQ(error::%(parse_result)s, ExecuteCmd(cmd));
4728 EXPECT_EQ(0u, result->size);%(gl_error_test)s 4706 EXPECT_EQ(0u, result->size);%(gl_error_test)s
4729 } 4707 }
4730 """ 4708 """
4731 self.WriteInvalidUnitTest(func, file, invalid_test) 4709 self.WriteInvalidUnitTest(func, file, invalid_test)
4732 4710
4733 4711 class ArrayArgTypeHandler(TypeHandler):
4734 class PUTHandler(TypeHandler): 4712 """Base class for type handlers that handle args that are arrays"""
4735 """Handler for glTexParameter_v, glVertexAttrib_v functions."""
4736 4713
4737 def __init__(self): 4714 def __init__(self):
4738 TypeHandler.__init__(self) 4715 TypeHandler.__init__(self)
4739 4716
4717 def GetArrayType(self, func):
4718 """Returns the type of the element in the element array being PUT to."""
4719 for arg in func.GetOriginalArgs():
4720 if arg.IsPointer():
4721 element_type = arg.GetPointedType()
4722 return element_type
4723
4724 # Special case: array type handler is used for a function that is forwarded
4725 # to the actual array type implementation
4726 element_type = func.GetOriginalArgs()[-1].type
4727 assert all(arg.type == element_type \
4728 for arg in func.GetOriginalArgs()[-self.GetArrayCount(func):])
4729 return element_type
4730
4731 def GetArrayCount(self, func):
4732 """Returns the count of the elements in the array being PUT to."""
4733 return func.GetInfo('count')
4734
4735 class PUTHandler(ArrayArgTypeHandler):
4736 """Handler for glTexParameter_v, glVertexAttrib_v functions."""
4737
4738 def __init__(self):
4739 ArrayArgTypeHandler.__init__(self)
4740
4740 def WriteServiceUnitTest(self, func, file): 4741 def WriteServiceUnitTest(self, func, file):
4741 """Writes the service unit test for a command.""" 4742 """Writes the service unit test for a command."""
4742 expected_call = "EXPECT_CALL(*gl_, %(gl_func_name)s(%(gl_args)s));" 4743 expected_call = "EXPECT_CALL(*gl_, %(gl_func_name)s(%(gl_args)s));"
4743 if func.GetInfo("first_element_only"): 4744 if func.GetInfo("first_element_only"):
4744 gl_arg_strings = [] 4745 gl_arg_strings = []
4745 for count, arg in enumerate(func.GetOriginalArgs()): 4746 for count, arg in enumerate(func.GetOriginalArgs()):
4746 gl_arg_strings.append(arg.GetValidGLArg(func, count, 0)) 4747 gl_arg_strings.append(arg.GetValidGLArg(func, count, 0))
4747 gl_arg_strings[-1] = "*" + gl_arg_strings[-1] 4748 gl_arg_strings[-1] = "*" + gl_arg_strings[-1]
4748 expected_call = ("EXPECT_CALL(*gl_, %%(gl_func_name)s(%s));" % 4749 expected_call = ("EXPECT_CALL(*gl_, %%(gl_func_name)s(%s));" %
4749 ", ".join(gl_arg_strings)) 4750 ", ".join(gl_arg_strings))
4750 valid_test = """ 4751 valid_test = """
4751 TEST_P(%(test_name)s, %(name)sValidArgs) { 4752 TEST_P(%(test_name)s, %(name)sValidArgs) {
4752 SpecializedSetup<cmds::%(name)s, 0>(true); 4753 SpecializedSetup<cmds::%(name)s, 0>(true);
4753 cmds::%(name)s cmd; 4754 cmds::%(name)s cmd;
4754 cmd.Init(%(args)s); 4755 cmd.Init(%(args)s);
4755 GetSharedMemoryAs<%(data_type)s*>()[0] = %(data_value)s; 4756 GetSharedMemoryAs<%(data_type)s*>()[0] = %(data_value)s;
4756 %(expected_call)s 4757 %(expected_call)s
4757 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 4758 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
4758 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 4759 EXPECT_EQ(GL_NO_ERROR, GetGLError());
4759 } 4760 }
4760 """ 4761 """
4761 extra = { 4762 extra = {
4762 'data_type': func.GetInfo('data_type'), 4763 'data_type': self.GetArrayType(func),
4763 'data_value': func.GetInfo('data_value') or '0', 4764 'data_value': func.GetInfo('data_value') or '0',
4764 'expected_call': expected_call, 4765 'expected_call': expected_call,
4765 } 4766 }
4766 self.WriteValidUnitTest(func, file, valid_test, extra) 4767 self.WriteValidUnitTest(func, file, valid_test, extra)
4767 4768
4768 invalid_test = """ 4769 invalid_test = """
4769 TEST_P(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) { 4770 TEST_P(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) {
4770 EXPECT_CALL(*gl_, %(gl_func_name)s(%(gl_args)s)).Times(0); 4771 EXPECT_CALL(*gl_, %(gl_func_name)s(%(gl_args)s)).Times(0);
4771 SpecializedSetup<cmds::%(name)s, 0>(false); 4772 SpecializedSetup<cmds::%(name)s, 0>(false);
4772 cmds::%(name)s cmd; 4773 cmds::%(name)s cmd;
(...skipping 21 matching lines...) Expand all
4794 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 4795 EXPECT_EQ(GL_NO_ERROR, GetGLError());
4795 } 4796 }
4796 """ 4797 """
4797 gl_arg_strings = [] 4798 gl_arg_strings = []
4798 gl_any_strings = [] 4799 gl_any_strings = []
4799 for count, arg in enumerate(func.GetOriginalArgs()[0:-1]): 4800 for count, arg in enumerate(func.GetOriginalArgs()[0:-1]):
4800 gl_arg_strings.append(arg.GetValidGLArg(func, count, 0)) 4801 gl_arg_strings.append(arg.GetValidGLArg(func, count, 0))
4801 gl_any_strings.append("_") 4802 gl_any_strings.append("_")
4802 extra = { 4803 extra = {
4803 'data_ref': ("*" if func.GetInfo('first_element_only') else ""), 4804 'data_ref': ("*" if func.GetInfo('first_element_only') else ""),
4804 'data_type': func.GetInfo('data_type'), 4805 'data_type': self.GetArrayType(func),
4805 'data_count': func.GetInfo('count'), 4806 'data_count': self.GetArrayCount(func),
4806 'data_value': func.GetInfo('data_value') or '0', 4807 'data_value': func.GetInfo('data_value') or '0',
4807 'gl_args': ", ".join(gl_arg_strings), 4808 'gl_args': ", ".join(gl_arg_strings),
4808 'gl_any_args': ", ".join(gl_any_strings), 4809 'gl_any_args': ", ".join(gl_any_strings),
4809 } 4810 }
4810 self.WriteValidUnitTest(func, file, valid_test, extra) 4811 self.WriteValidUnitTest(func, file, valid_test, extra)
4811 4812
4812 invalid_test = """ 4813 invalid_test = """
4813 TEST_P(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) { 4814 TEST_P(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) {
4814 cmds::%(name)s& cmd = *GetImmediateAs<cmds::%(name)s>(); 4815 cmds::%(name)s& cmd = *GetImmediateAs<cmds::%(name)s>();
4815 EXPECT_CALL(*gl_, %(gl_func_name)s(%(gl_any_args)s, _)).Times(0); 4816 EXPECT_CALL(*gl_, %(gl_func_name)s(%(gl_any_args)s, _)).Times(0);
4816 SpecializedSetup<cmds::%(name)s, 0>(false); 4817 SpecializedSetup<cmds::%(name)s, 0>(false);
4817 %(data_type)s temp[%(data_count)s] = { %(data_value)s, }; 4818 %(data_type)s temp[%(data_count)s] = { %(data_value)s, };
4818 cmd.Init(%(all_but_last_args)s, &temp[0]); 4819 cmd.Init(%(all_but_last_args)s, &temp[0]);
4819 EXPECT_EQ(error::%(parse_result)s, 4820 EXPECT_EQ(error::%(parse_result)s,
4820 ExecuteImmediateCmd(cmd, sizeof(temp)));%(gl_error_test)s 4821 ExecuteImmediateCmd(cmd, sizeof(temp)));%(gl_error_test)s
4821 } 4822 }
4822 """ 4823 """
4823 self.WriteInvalidUnitTest(func, file, invalid_test, extra) 4824 self.WriteInvalidUnitTest(func, file, invalid_test, extra)
4824 4825
4825 def WriteGetDataSizeCode(self, func, file): 4826 def WriteGetDataSizeCode(self, func, file):
4826 """Overrriden from TypeHandler.""" 4827 """Overrriden from TypeHandler."""
4827 code = """ uint32_t data_size; 4828 code = """ uint32_t data_size;
4828 if (!ComputeDataSize(1, sizeof(%s), %d, &data_size)) { 4829 if (!ComputeDataSize(1, sizeof(%s), %d, &data_size)) {
4829 return error::kOutOfBounds; 4830 return error::kOutOfBounds;
4830 } 4831 }
4831 """ 4832 """
4832 file.Write(code % (func.info.data_type, func.info.count)) 4833 file.Write(code % (self.GetArrayType(func), self.GetArrayCount(func)))
4833 if func.is_immediate: 4834 if func.is_immediate:
4834 file.Write(" if (data_size > immediate_data_size) {\n") 4835 file.Write(" if (data_size > immediate_data_size) {\n")
4835 file.Write(" return error::kOutOfBounds;\n") 4836 file.Write(" return error::kOutOfBounds;\n")
4836 file.Write(" }\n") 4837 file.Write(" }\n")
4837 4838
4838 def WriteGLES2Implementation(self, func, file): 4839 def WriteGLES2Implementation(self, func, file):
4839 """Overrriden from TypeHandler.""" 4840 """Overrriden from TypeHandler."""
4840 impl_func = func.GetInfo('impl_func') 4841 impl_func = func.GetInfo('impl_func')
4841 if (impl_func != None and impl_func != True): 4842 if (impl_func != None and impl_func != True):
4842 return; 4843 return;
4843 file.Write("%s GLES2Implementation::%s(%s) {\n" % 4844 file.Write("%s GLES2Implementation::%s(%s) {\n" %
4844 (func.return_type, func.original_name, 4845 (func.return_type, func.original_name,
4845 func.MakeTypedOriginalArgString(""))) 4846 func.MakeTypedOriginalArgString("")))
4846 file.Write(" GPU_CLIENT_SINGLE_THREAD_CHECK();\n") 4847 file.Write(" GPU_CLIENT_SINGLE_THREAD_CHECK();\n")
4847 func.WriteDestinationInitalizationValidation(file) 4848 func.WriteDestinationInitalizationValidation(file)
4848 self.WriteClientGLCallLog(func, file) 4849 self.WriteClientGLCallLog(func, file)
4849 last_arg_name = func.GetLastOriginalArg().name 4850 last_arg_name = func.GetLastOriginalArg().name
4850 values_str = ' << ", " << '.join( 4851 values_str = ' << ", " << '.join(
4851 ["%s[%d]" % (last_arg_name, ndx) for ndx in range(0, func.info.count)]) 4852 ["%s[%d]" % (last_arg_name, ndx) \
4853 for ndx in range(0, self.GetArrayCount(func))])
4852 file.Write(' GPU_CLIENT_LOG("values: " << %s);\n' % values_str) 4854 file.Write(' GPU_CLIENT_LOG("values: " << %s);\n' % values_str)
4853 for arg in func.GetOriginalArgs(): 4855 for arg in func.GetOriginalArgs():
4854 arg.WriteClientSideValidationCode(file, func) 4856 arg.WriteClientSideValidationCode(file, func)
4855 file.Write(" helper_->%sImmediate(%s);\n" % 4857 file.Write(" helper_->%sImmediate(%s);\n" %
4856 (func.name, func.MakeOriginalArgString(""))) 4858 (func.name, func.MakeOriginalArgString("")))
4857 file.Write(" CheckGLError();\n") 4859 file.Write(" CheckGLError();\n")
4858 file.Write("}\n") 4860 file.Write("}\n")
4859 file.Write("\n") 4861 file.Write("\n")
4860 4862
4861 def WriteGLES2ImplementationUnitTest(self, func, file): 4863 def WriteGLES2ImplementationUnitTest(self, func, file):
(...skipping 19 matching lines...) Expand all
4881 } 4883 }
4882 """ 4884 """
4883 cmd_arg_strings = [] 4885 cmd_arg_strings = []
4884 for count, arg in enumerate(func.GetCmdArgs()[0:-2]): 4886 for count, arg in enumerate(func.GetCmdArgs()[0:-2]):
4885 cmd_arg_strings.append(arg.GetValidClientSideCmdArg(func, count, 0)) 4887 cmd_arg_strings.append(arg.GetValidClientSideCmdArg(func, count, 0))
4886 gl_arg_strings = [] 4888 gl_arg_strings = []
4887 for count, arg in enumerate(func.GetOriginalArgs()[0:-1]): 4889 for count, arg in enumerate(func.GetOriginalArgs()[0:-1]):
4888 gl_arg_strings.append(arg.GetValidClientSideArg(func, count, 0)) 4890 gl_arg_strings.append(arg.GetValidClientSideArg(func, count, 0))
4889 file.Write(code % { 4891 file.Write(code % {
4890 'name': func.name, 4892 'name': func.name,
4891 'type': func.GetInfo('data_type'), 4893 'type': self.GetArrayType(func),
4892 'count': func.GetInfo('count'), 4894 'count': self.GetArrayCount(func),
4893 'args': ", ".join(gl_arg_strings), 4895 'args': ", ".join(gl_arg_strings),
4894 'cmd_args': ", ".join(cmd_arg_strings), 4896 'cmd_args': ", ".join(cmd_arg_strings),
4895 }) 4897 })
4896 4898
4897 def WriteImmediateCmdComputeSize(self, func, file): 4899 def WriteImmediateCmdComputeSize(self, func, file):
4898 """Overrriden from TypeHandler.""" 4900 """Overrriden from TypeHandler."""
4899 file.Write(" static uint32_t ComputeDataSize() {\n") 4901 file.Write(" static uint32_t ComputeDataSize() {\n")
4900 file.Write(" return static_cast<uint32_t>(\n") 4902 file.Write(" return static_cast<uint32_t>(\n")
4901 file.Write(" sizeof(%s) * %d); // NOLINT\n" % 4903 file.Write(" sizeof(%s) * %d); // NOLINT\n" %
4902 (func.info.data_type, func.info.count)) 4904 (self.GetArrayType(func), self.GetArrayCount(func)))
4903 file.Write(" }\n") 4905 file.Write(" }\n")
4904 file.Write("\n") 4906 file.Write("\n")
4905 file.Write(" static uint32_t ComputeSize() {\n") 4907 file.Write(" static uint32_t ComputeSize() {\n")
4906 file.Write(" return static_cast<uint32_t>(\n") 4908 file.Write(" return static_cast<uint32_t>(\n")
4907 file.Write( 4909 file.Write(
4908 " sizeof(ValueType) + ComputeDataSize()); // NOLINT\n") 4910 " sizeof(ValueType) + ComputeDataSize()); // NOLINT\n")
4909 file.Write(" }\n") 4911 file.Write(" }\n")
4910 file.Write("\n") 4912 file.Write("\n")
4911 4913
4912 def WriteImmediateCmdSetHeader(self, func, file): 4914 def WriteImmediateCmdSetHeader(self, func, file):
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
4962 file.Write(code % { 4964 file.Write(code % {
4963 "name": func.name, 4965 "name": func.name,
4964 "typed_args": func.MakeTypedOriginalArgString(""), 4966 "typed_args": func.MakeTypedOriginalArgString(""),
4965 "args": func.MakeOriginalArgString(""), 4967 "args": func.MakeOriginalArgString(""),
4966 }) 4968 })
4967 4969
4968 def WriteImmediateFormatTest(self, func, file): 4970 def WriteImmediateFormatTest(self, func, file):
4969 """Overrriden from TypeHandler.""" 4971 """Overrriden from TypeHandler."""
4970 file.Write("TEST_F(GLES2FormatTest, %s) {\n" % func.name) 4972 file.Write("TEST_F(GLES2FormatTest, %s) {\n" % func.name)
4971 file.Write(" const int kSomeBaseValueToTestWith = 51;\n") 4973 file.Write(" const int kSomeBaseValueToTestWith = 51;\n")
4972 file.Write(" static %s data[] = {\n" % func.info.data_type) 4974 file.Write(" static %s data[] = {\n" % self.GetArrayType(func))
4973 for v in range(0, func.info.count): 4975 for v in range(0, self.GetArrayCount(func)):
4974 file.Write(" static_cast<%s>(kSomeBaseValueToTestWith + %d),\n" % 4976 file.Write(" static_cast<%s>(kSomeBaseValueToTestWith + %d),\n" %
4975 (func.info.data_type, v)) 4977 (self.GetArrayType(func), v))
4976 file.Write(" };\n") 4978 file.Write(" };\n")
4977 file.Write(" cmds::%s& cmd = *GetBufferAs<cmds::%s>();\n" % 4979 file.Write(" cmds::%s& cmd = *GetBufferAs<cmds::%s>();\n" %
4978 (func.name, func.name)) 4980 (func.name, func.name))
4979 file.Write(" void* next_cmd = cmd.Set(\n") 4981 file.Write(" void* next_cmd = cmd.Set(\n")
4980 file.Write(" &cmd") 4982 file.Write(" &cmd")
4981 args = func.GetCmdArgs() 4983 args = func.GetCmdArgs()
4982 for value, arg in enumerate(args): 4984 for value, arg in enumerate(args):
4983 file.Write(",\n static_cast<%s>(%d)" % (arg.type, value + 11)) 4985 file.Write(",\n static_cast<%s>(%d)" % (arg.type, value + 11))
4984 file.Write(",\n data);\n") 4986 file.Write(",\n data);\n")
4985 args = func.GetCmdArgs() 4987 args = func.GetCmdArgs()
4986 file.Write(" EXPECT_EQ(static_cast<uint32_t>(cmds::%s::kCmdId),\n" 4988 file.Write(" EXPECT_EQ(static_cast<uint32_t>(cmds::%s::kCmdId),\n"
4987 % func.name) 4989 % func.name)
4988 file.Write(" cmd.header.command);\n") 4990 file.Write(" cmd.header.command);\n")
4989 file.Write(" EXPECT_EQ(sizeof(cmd) +\n") 4991 file.Write(" EXPECT_EQ(sizeof(cmd) +\n")
4990 file.Write(" RoundSizeToMultipleOfEntries(sizeof(data)),\n") 4992 file.Write(" RoundSizeToMultipleOfEntries(sizeof(data)),\n")
4991 file.Write(" cmd.header.size * 4u);\n") 4993 file.Write(" cmd.header.size * 4u);\n")
4992 for value, arg in enumerate(args): 4994 for value, arg in enumerate(args):
4993 file.Write(" EXPECT_EQ(static_cast<%s>(%d), cmd.%s);\n" % 4995 file.Write(" EXPECT_EQ(static_cast<%s>(%d), cmd.%s);\n" %
4994 (arg.type, value + 11, arg.name)) 4996 (arg.type, value + 11, arg.name))
4995 file.Write(" CheckBytesWrittenMatchesExpectedSize(\n") 4997 file.Write(" CheckBytesWrittenMatchesExpectedSize(\n")
4996 file.Write(" next_cmd, sizeof(cmd) +\n") 4998 file.Write(" next_cmd, sizeof(cmd) +\n")
4997 file.Write(" RoundSizeToMultipleOfEntries(sizeof(data)));\n") 4999 file.Write(" RoundSizeToMultipleOfEntries(sizeof(data)));\n")
4998 file.Write(" // TODO(gman): Check that data was inserted;\n") 5000 file.Write(" // TODO(gman): Check that data was inserted;\n")
4999 file.Write("}\n") 5001 file.Write("}\n")
5000 file.Write("\n") 5002 file.Write("\n")
5001 5003
5002 5004
5003 class PUTnHandler(TypeHandler): 5005 class PUTnHandler(ArrayArgTypeHandler):
5004 """Handler for PUTn 'glUniform__v' type functions.""" 5006 """Handler for PUTn 'glUniform__v' type functions."""
5005 5007
5006 def __init__(self): 5008 def __init__(self):
5007 TypeHandler.__init__(self) 5009 ArrayArgTypeHandler.__init__(self)
5008 5010
5009 def WriteServiceUnitTest(self, func, file): 5011 def WriteServiceUnitTest(self, func, file):
5010 """Overridden from TypeHandler.""" 5012 """Overridden from TypeHandler."""
5011 TypeHandler.WriteServiceUnitTest(self, func, file) 5013 ArrayArgTypeHandler.WriteServiceUnitTest(self, func, file)
5012 5014
5013 valid_test = """ 5015 valid_test = """
5014 TEST_P(%(test_name)s, %(name)sValidArgsCountTooLarge) { 5016 TEST_P(%(test_name)s, %(name)sValidArgsCountTooLarge) {
5015 EXPECT_CALL(*gl_, %(gl_func_name)s(%(gl_args)s)); 5017 EXPECT_CALL(*gl_, %(gl_func_name)s(%(gl_args)s));
5016 SpecializedSetup<cmds::%(name)s, 0>(true); 5018 SpecializedSetup<cmds::%(name)s, 0>(true);
5017 cmds::%(name)s cmd; 5019 cmds::%(name)s cmd;
5018 cmd.Init(%(args)s); 5020 cmd.Init(%(args)s);
5019 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 5021 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
5020 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 5022 EXPECT_EQ(GL_NO_ERROR, GetGLError());
5021 } 5023 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
5061 } 5063 }
5062 """ 5064 """
5063 gl_arg_strings = [] 5065 gl_arg_strings = []
5064 gl_any_strings = [] 5066 gl_any_strings = []
5065 arg_strings = [] 5067 arg_strings = []
5066 for count, arg in enumerate(func.GetOriginalArgs()[0:-1]): 5068 for count, arg in enumerate(func.GetOriginalArgs()[0:-1]):
5067 gl_arg_strings.append(arg.GetValidGLArg(func, count, 0)) 5069 gl_arg_strings.append(arg.GetValidGLArg(func, count, 0))
5068 gl_any_strings.append("_") 5070 gl_any_strings.append("_")
5069 arg_strings.append(arg.GetValidArg(func, count, 0)) 5071 arg_strings.append(arg.GetValidArg(func, count, 0))
5070 extra = { 5072 extra = {
5071 'data_type': func.GetInfo('data_type'), 5073 'data_type': self.GetArrayType(func),
5072 'data_count': func.GetInfo('count'), 5074 'data_count': self.GetArrayCount(func),
5073 'args': ", ".join(arg_strings), 5075 'args': ", ".join(arg_strings),
5074 'gl_args': ", ".join(gl_arg_strings), 5076 'gl_args': ", ".join(gl_arg_strings),
5075 'gl_any_args': ", ".join(gl_any_strings), 5077 'gl_any_args': ", ".join(gl_any_strings),
5076 } 5078 }
5077 self.WriteValidUnitTest(func, file, valid_test, extra) 5079 self.WriteValidUnitTest(func, file, valid_test, extra)
5078 5080
5079 invalid_test = """ 5081 invalid_test = """
5080 TEST_P(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) { 5082 TEST_P(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) {
5081 cmds::%(name)s& cmd = *GetImmediateAs<cmds::%(name)s>(); 5083 cmds::%(name)s& cmd = *GetImmediateAs<cmds::%(name)s>();
5082 EXPECT_CALL(*gl_, %(gl_func_name)s(%(gl_any_args)s, _)).Times(0); 5084 EXPECT_CALL(*gl_, %(gl_func_name)s(%(gl_any_args)s, _)).Times(0);
5083 SpecializedSetup<cmds::%(name)s, 0>(false); 5085 SpecializedSetup<cmds::%(name)s, 0>(false);
5084 %(data_type)s temp[%(data_count)s * 2] = { 0, }; 5086 %(data_type)s temp[%(data_count)s * 2] = { 0, };
5085 cmd.Init(%(all_but_last_args)s, &temp[0]); 5087 cmd.Init(%(all_but_last_args)s, &temp[0]);
5086 EXPECT_EQ(error::%(parse_result)s, 5088 EXPECT_EQ(error::%(parse_result)s,
5087 ExecuteImmediateCmd(cmd, sizeof(temp)));%(gl_error_test)s 5089 ExecuteImmediateCmd(cmd, sizeof(temp)));%(gl_error_test)s
5088 } 5090 }
5089 """ 5091 """
5090 self.WriteInvalidUnitTest(func, file, invalid_test, extra) 5092 self.WriteInvalidUnitTest(func, file, invalid_test, extra)
5091 5093
5092 def WriteGetDataSizeCode(self, func, file): 5094 def WriteGetDataSizeCode(self, func, file):
5093 """Overrriden from TypeHandler.""" 5095 """Overrriden from TypeHandler."""
5094 code = """ uint32_t data_size; 5096 code = """ uint32_t data_size;
5095 if (!ComputeDataSize(count, sizeof(%s), %d, &data_size)) { 5097 if (!ComputeDataSize(count, sizeof(%s), %d, &data_size)) {
5096 return error::kOutOfBounds; 5098 return error::kOutOfBounds;
5097 } 5099 }
5098 """ 5100 """
5099 file.Write(code % (func.info.data_type, func.info.count)) 5101 file.Write(code % (self.GetArrayType(func), self.GetArrayCount(func)))
5100 if func.is_immediate: 5102 if func.is_immediate:
5101 file.Write(" if (data_size > immediate_data_size) {\n") 5103 file.Write(" if (data_size > immediate_data_size) {\n")
5102 file.Write(" return error::kOutOfBounds;\n") 5104 file.Write(" return error::kOutOfBounds;\n")
5103 file.Write(" }\n") 5105 file.Write(" }\n")
5104 5106
5105 def WriteGLES2Implementation(self, func, file): 5107 def WriteGLES2Implementation(self, func, file):
5106 """Overrriden from TypeHandler.""" 5108 """Overrriden from TypeHandler."""
5107 file.Write("%s GLES2Implementation::%s(%s) {\n" % 5109 file.Write("%s GLES2Implementation::%s(%s) {\n" %
5108 (func.return_type, func.original_name, 5110 (func.return_type, func.original_name,
5109 func.MakeTypedOriginalArgString(""))) 5111 func.MakeTypedOriginalArgString("")))
5110 file.Write(" GPU_CLIENT_SINGLE_THREAD_CHECK();\n") 5112 file.Write(" GPU_CLIENT_SINGLE_THREAD_CHECK();\n")
5111 func.WriteDestinationInitalizationValidation(file) 5113 func.WriteDestinationInitalizationValidation(file)
5112 self.WriteClientGLCallLog(func, file) 5114 self.WriteClientGLCallLog(func, file)
5113 last_arg_name = func.GetLastOriginalArg().name 5115 last_arg_name = func.GetLastOriginalArg().name
5114 file.Write(""" GPU_CLIENT_LOG_CODE_BLOCK({ 5116 file.Write(""" GPU_CLIENT_LOG_CODE_BLOCK({
5115 for (GLsizei i = 0; i < count; ++i) { 5117 for (GLsizei i = 0; i < count; ++i) {
5116 """) 5118 """)
5117 values_str = ' << ", " << '.join( 5119 values_str = ' << ", " << '.join(
5118 ["%s[%d + i * %d]" % ( 5120 ["%s[%d + i * %d]" % (
5119 last_arg_name, ndx, func.info.count) for ndx in range( 5121 last_arg_name, ndx, self.GetArrayCount(func)) for ndx in range(
5120 0, func.info.count)]) 5122 0, self.GetArrayCount(func))])
5121 file.Write(' GPU_CLIENT_LOG(" " << i << ": " << %s);\n' % values_str) 5123 file.Write(' GPU_CLIENT_LOG(" " << i << ": " << %s);\n' % values_str)
5122 file.Write(" }\n });\n") 5124 file.Write(" }\n });\n")
5123 for arg in func.GetOriginalArgs(): 5125 for arg in func.GetOriginalArgs():
5124 arg.WriteClientSideValidationCode(file, func) 5126 arg.WriteClientSideValidationCode(file, func)
5125 file.Write(" helper_->%sImmediate(%s);\n" % 5127 file.Write(" helper_->%sImmediate(%s);\n" %
5126 (func.name, func.MakeOriginalArgString(""))) 5128 (func.name, func.MakeOriginalArgString("")))
5127 file.Write(" CheckGLError();\n") 5129 file.Write(" CheckGLError();\n")
5128 file.Write("}\n") 5130 file.Write("}\n")
5129 file.Write("\n") 5131 file.Write("\n")
5130 5132
(...skipping 22 matching lines...) Expand all
5153 for count, arg in enumerate(func.GetCmdArgs()[0:-2]): 5155 for count, arg in enumerate(func.GetCmdArgs()[0:-2]):
5154 cmd_arg_strings.append(arg.GetValidClientSideCmdArg(func, count, 0)) 5156 cmd_arg_strings.append(arg.GetValidClientSideCmdArg(func, count, 0))
5155 gl_arg_strings = [] 5157 gl_arg_strings = []
5156 count_param = 0 5158 count_param = 0
5157 for count, arg in enumerate(func.GetOriginalArgs()[0:-1]): 5159 for count, arg in enumerate(func.GetOriginalArgs()[0:-1]):
5158 gl_arg_strings.append(arg.GetValidClientSideArg(func, count, 0)) 5160 gl_arg_strings.append(arg.GetValidClientSideArg(func, count, 0))
5159 if arg.name == "count": 5161 if arg.name == "count":
5160 count_param = int(arg.GetValidClientSideArg(func, count, 0)) 5162 count_param = int(arg.GetValidClientSideArg(func, count, 0))
5161 file.Write(code % { 5163 file.Write(code % {
5162 'name': func.name, 5164 'name': func.name,
5163 'type': func.GetInfo('data_type'), 5165 'type': self.GetArrayType(func),
5164 'count': func.GetInfo('count'), 5166 'count': self.GetArrayCount(func),
5165 'args': ", ".join(gl_arg_strings), 5167 'args': ", ".join(gl_arg_strings),
5166 'cmd_args': ", ".join(cmd_arg_strings), 5168 'cmd_args': ", ".join(cmd_arg_strings),
5167 'count_param': count_param, 5169 'count_param': count_param,
5168 }) 5170 })
5169 5171
5170 def WriteImmediateCmdComputeSize(self, func, file): 5172 def WriteImmediateCmdComputeSize(self, func, file):
5171 """Overrriden from TypeHandler.""" 5173 """Overrriden from TypeHandler."""
5172 file.Write(" static uint32_t ComputeDataSize(GLsizei count) {\n") 5174 file.Write(" static uint32_t ComputeDataSize(GLsizei count) {\n")
5173 file.Write(" return static_cast<uint32_t>(\n") 5175 file.Write(" return static_cast<uint32_t>(\n")
5174 file.Write(" sizeof(%s) * %d * count); // NOLINT\n" % 5176 file.Write(" sizeof(%s) * %d * count); // NOLINT\n" %
5175 (func.info.data_type, func.info.count)) 5177 (self.GetArrayType(func), self.GetArrayCount(func)))
5176 file.Write(" }\n") 5178 file.Write(" }\n")
5177 file.Write("\n") 5179 file.Write("\n")
5178 file.Write(" static uint32_t ComputeSize(GLsizei count) {\n") 5180 file.Write(" static uint32_t ComputeSize(GLsizei count) {\n")
5179 file.Write(" return static_cast<uint32_t>(\n") 5181 file.Write(" return static_cast<uint32_t>(\n")
5180 file.Write( 5182 file.Write(
5181 " sizeof(ValueType) + ComputeDataSize(count)); // NOLINT\n") 5183 " sizeof(ValueType) + ComputeDataSize(count)); // NOLINT\n")
5182 file.Write(" }\n") 5184 file.Write(" }\n")
5183 file.Write("\n") 5185 file.Write("\n")
5184 5186
5185 def WriteImmediateCmdSetHeader(self, func, file): 5187 def WriteImmediateCmdSetHeader(self, func, file):
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
5240 5242
5241 def WriteImmediateFormatTest(self, func, file): 5243 def WriteImmediateFormatTest(self, func, file):
5242 """Overrriden from TypeHandler.""" 5244 """Overrriden from TypeHandler."""
5243 args = func.GetCmdArgs() 5245 args = func.GetCmdArgs()
5244 count_param = 0 5246 count_param = 0
5245 for value, arg in enumerate(args): 5247 for value, arg in enumerate(args):
5246 if arg.name == "count": 5248 if arg.name == "count":
5247 count_param = int(arg.GetValidClientSideArg(func, value, 0)) 5249 count_param = int(arg.GetValidClientSideArg(func, value, 0))
5248 file.Write("TEST_F(GLES2FormatTest, %s) {\n" % func.name) 5250 file.Write("TEST_F(GLES2FormatTest, %s) {\n" % func.name)
5249 file.Write(" const int kSomeBaseValueToTestWith = 51;\n") 5251 file.Write(" const int kSomeBaseValueToTestWith = 51;\n")
5250 file.Write(" static %s data[] = {\n" % func.info.data_type) 5252 file.Write(" static %s data[] = {\n" % self.GetArrayType(func))
5251 for v in range(0, func.info.count * count_param): 5253 for v in range(0, self.GetArrayCount(func) * count_param):
5252 file.Write(" static_cast<%s>(kSomeBaseValueToTestWith + %d),\n" % 5254 file.Write(" static_cast<%s>(kSomeBaseValueToTestWith + %d),\n" %
5253 (func.info.data_type, v)) 5255 (self.GetArrayType(func), v))
5254 file.Write(" };\n") 5256 file.Write(" };\n")
5255 file.Write(" cmds::%s& cmd = *GetBufferAs<cmds::%s>();\n" % 5257 file.Write(" cmds::%s& cmd = *GetBufferAs<cmds::%s>();\n" %
5256 (func.name, func.name)) 5258 (func.name, func.name))
5257 file.Write(" const GLsizei kNumElements = %d;\n" % count_param) 5259 file.Write(" const GLsizei kNumElements = %d;\n" % count_param)
5258 file.Write(" const size_t kExpectedCmdSize =\n") 5260 file.Write(" const size_t kExpectedCmdSize =\n")
5259 file.Write(" sizeof(cmd) + kNumElements * sizeof(%s) * %d;\n" % 5261 file.Write(" sizeof(cmd) + kNumElements * sizeof(%s) * %d;\n" %
5260 (func.info.data_type, func.info.count)) 5262 (self.GetArrayType(func), self.GetArrayCount(func)))
5261 file.Write(" void* next_cmd = cmd.Set(\n") 5263 file.Write(" void* next_cmd = cmd.Set(\n")
5262 file.Write(" &cmd") 5264 file.Write(" &cmd")
5263 for value, arg in enumerate(args): 5265 for value, arg in enumerate(args):
5264 file.Write(",\n static_cast<%s>(%d)" % (arg.type, value + 1)) 5266 file.Write(",\n static_cast<%s>(%d)" % (arg.type, value + 1))
5265 file.Write(",\n data);\n") 5267 file.Write(",\n data);\n")
5266 file.Write(" EXPECT_EQ(static_cast<uint32_t>(cmds::%s::kCmdId),\n" % 5268 file.Write(" EXPECT_EQ(static_cast<uint32_t>(cmds::%s::kCmdId),\n" %
5267 func.name) 5269 func.name)
5268 file.Write(" cmd.header.command);\n") 5270 file.Write(" cmd.header.command);\n")
5269 file.Write(" EXPECT_EQ(kExpectedCmdSize, cmd.header.size * 4u);\n") 5271 file.Write(" EXPECT_EQ(kExpectedCmdSize, cmd.header.size * 4u);\n")
5270 for value, arg in enumerate(args): 5272 for value, arg in enumerate(args):
5271 file.Write(" EXPECT_EQ(static_cast<%s>(%d), cmd.%s);\n" % 5273 file.Write(" EXPECT_EQ(static_cast<%s>(%d), cmd.%s);\n" %
5272 (arg.type, value + 1, arg.name)) 5274 (arg.type, value + 1, arg.name))
5273 file.Write(" CheckBytesWrittenMatchesExpectedSize(\n") 5275 file.Write(" CheckBytesWrittenMatchesExpectedSize(\n")
5274 file.Write(" next_cmd, sizeof(cmd) +\n") 5276 file.Write(" next_cmd, sizeof(cmd) +\n")
5275 file.Write(" RoundSizeToMultipleOfEntries(sizeof(data)));\n") 5277 file.Write(" RoundSizeToMultipleOfEntries(sizeof(data)));\n")
5276 file.Write(" // TODO(gman): Check that data was inserted;\n") 5278 file.Write(" // TODO(gman): Check that data was inserted;\n")
5277 file.Write("}\n") 5279 file.Write("}\n")
5278 file.Write("\n") 5280 file.Write("\n")
5279 5281
5280 5282
5281 class PUTXnHandler(TypeHandler): 5283 class PUTXnHandler(ArrayArgTypeHandler):
5282 """Handler for glUniform?f functions.""" 5284 """Handler for glUniform?f functions."""
5283 def __init__(self): 5285 def __init__(self):
5284 TypeHandler.__init__(self) 5286 ArrayArgTypeHandler.__init__(self)
5285 5287
5286 def WriteHandlerImplementation(self, func, file): 5288 def WriteHandlerImplementation(self, func, file):
5287 """Overrriden from TypeHandler.""" 5289 """Overrriden from TypeHandler."""
5288 code = """ %(type)s temp[%(count)s] = { %(values)s}; 5290 code = """ %(type)s temp[%(count)s] = { %(values)s};
5289 Do%(name)sv(%(location)s, 1, &temp[0]); 5291 Do%(name)sv(%(location)s, 1, &temp[0]);
5290 """ 5292 """
5291 values = "" 5293 values = ""
5292 args = func.GetOriginalArgs() 5294 args = func.GetOriginalArgs()
5293 count = int(func.GetInfo('count')) 5295 count = int(self.GetArrayCount(func))
5294 num_args = len(args) 5296 num_args = len(args)
5295 for ii in range(count): 5297 for ii in range(count):
5296 values += "%s, " % args[len(args) - count + ii].name 5298 values += "%s, " % args[len(args) - count + ii].name
5297 5299
5298 file.Write(code % { 5300 file.Write(code % {
5299 'name': func.name, 5301 'name': func.name,
5300 'count': func.GetInfo('count'), 5302 'count': self.GetArrayCount(func),
5301 'type': func.GetInfo('data_type'), 5303 'type': self.GetArrayType(func),
5302 'location': args[0].name, 5304 'location': args[0].name,
5303 'args': func.MakeOriginalArgString(""), 5305 'args': func.MakeOriginalArgString(""),
5304 'values': values, 5306 'values': values,
5305 }) 5307 })
5306 5308
5307 def WriteServiceUnitTest(self, func, file): 5309 def WriteServiceUnitTest(self, func, file):
5308 """Overrriden from TypeHandler.""" 5310 """Overrriden from TypeHandler."""
5309 valid_test = """ 5311 valid_test = """
5310 TEST_P(%(test_name)s, %(name)sValidArgs) { 5312 TEST_P(%(test_name)s, %(name)sValidArgs) {
5311 EXPECT_CALL(*gl_, %(name)sv(%(local_args)s)); 5313 EXPECT_CALL(*gl_, %(name)sv(%(local_args)s));
5312 SpecializedSetup<cmds::%(name)s, 0>(true); 5314 SpecializedSetup<cmds::%(name)s, 0>(true);
5313 cmds::%(name)s cmd; 5315 cmds::%(name)s cmd;
5314 cmd.Init(%(args)s); 5316 cmd.Init(%(args)s);
5315 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 5317 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
5316 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 5318 EXPECT_EQ(GL_NO_ERROR, GetGLError());
5317 } 5319 }
5318 """ 5320 """
5319 args = func.GetOriginalArgs() 5321 args = func.GetOriginalArgs()
5320 local_args = "%s, 1, _" % args[0].GetValidGLArg(func, 0, 0) 5322 local_args = "%s, 1, _" % args[0].GetValidGLArg(func, 0, 0)
5321 self.WriteValidUnitTest(func, file, valid_test, { 5323 self.WriteValidUnitTest(func, file, valid_test, {
5322 'name': func.name, 5324 'name': func.name,
5323 'count': func.GetInfo('count'), 5325 'count': self.GetArrayCount(func),
5324 'local_args': local_args, 5326 'local_args': local_args,
5325 }) 5327 })
5326 5328
5327 invalid_test = """ 5329 invalid_test = """
5328 TEST_P(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) { 5330 TEST_P(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) {
5329 EXPECT_CALL(*gl_, %(name)sv(_, _, _).Times(0); 5331 EXPECT_CALL(*gl_, %(name)sv(_, _, _).Times(0);
5330 SpecializedSetup<cmds::%(name)s, 0>(false); 5332 SpecializedSetup<cmds::%(name)s, 0>(false);
5331 cmds::%(name)s cmd; 5333 cmds::%(name)s cmd;
5332 cmd.Init(%(args)s); 5334 cmd.Init(%(args)s);
5333 EXPECT_EQ(error::%(parse_result)s, ExecuteCmd(cmd));%(gl_error_test)s 5335 EXPECT_EQ(error::%(parse_result)s, ExecuteCmd(cmd));%(gl_error_test)s
5334 } 5336 }
5335 """ 5337 """
5336 self.WriteInvalidUnitTest(func, file, invalid_test, { 5338 self.WriteInvalidUnitTest(func, file, invalid_test, {
5337 'name': func.GetInfo('name'), 5339 'name': func.GetInfo('name'),
5338 'count': func.GetInfo('count'), 5340 'count': self.GetArrayCount(func),
5339 }) 5341 })
5340 5342
5341 5343
5342 class GLcharHandler(CustomHandler): 5344 class GLcharHandler(CustomHandler):
5343 """Handler for functions that pass a single string .""" 5345 """Handler for functions that pass a single string ."""
5344 5346
5345 def __init__(self): 5347 def __init__(self):
5346 CustomHandler.__init__(self) 5348 CustomHandler.__init__(self)
5347 5349
5348 def WriteImmediateCmdComputeSize(self, func, file): 5350 def WriteImmediateCmdComputeSize(self, func, file):
(...skipping 759 matching lines...) Expand 10 before | Expand all | Expand 10 after
6108 6110
6109 class ImmediatePointerArgument(Argument): 6111 class ImmediatePointerArgument(Argument):
6110 """A class that represents an immediate argument to a function. 6112 """A class that represents an immediate argument to a function.
6111 6113
6112 An immediate argument is one where the data follows the command. 6114 An immediate argument is one where the data follows the command.
6113 """ 6115 """
6114 6116
6115 def __init__(self, name, type): 6117 def __init__(self, name, type):
6116 Argument.__init__(self, name, type) 6118 Argument.__init__(self, name, type)
6117 6119
6120 def IsPointer(self):
6121 return True
6122
6123 def GetPointedType(self):
6124 match = re.match('(const\s+)?(?P<element_type>[\w]+)\s*\*', self.type)
6125 assert match
6126 return match.groupdict()['element_type']
6127
6118 def AddCmdArgs(self, args): 6128 def AddCmdArgs(self, args):
6119 """Overridden from Argument.""" 6129 """Overridden from Argument."""
6120 pass 6130 pass
6121 6131
6122 def WriteGetCode(self, file): 6132 def WriteGetCode(self, file):
6123 """Overridden from Argument.""" 6133 """Overridden from Argument."""
6124 file.Write( 6134 file.Write(
6125 " %s %s = GetImmediateDataAs<%s>(\n" % 6135 " %s %s = GetImmediateDataAs<%s>(\n" %
6126 (self.type, self.name, self.type)) 6136 (self.type, self.name, self.type))
6127 file.Write(" c, data_size, immediate_data_size);\n") 6137 file.Write(" c, data_size, immediate_data_size);\n")
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
6181 class PointerArgument(Argument): 6191 class PointerArgument(Argument):
6182 """A class that represents a pointer argument to a function.""" 6192 """A class that represents a pointer argument to a function."""
6183 6193
6184 def __init__(self, name, type): 6194 def __init__(self, name, type):
6185 Argument.__init__(self, name, type) 6195 Argument.__init__(self, name, type)
6186 6196
6187 def IsPointer(self): 6197 def IsPointer(self):
6188 """Returns true if argument is a pointer.""" 6198 """Returns true if argument is a pointer."""
6189 return True 6199 return True
6190 6200
6201 def GetPointedType(self):
6202 match = re.match('(const\s+)?(?P<element_type>[\w]+)\s*\*', self.type)
6203 assert match
6204 return match.groupdict()['element_type']
6205
6191 def GetValidArg(self, func, offset, index): 6206 def GetValidArg(self, func, offset, index):
6192 """Overridden from Argument.""" 6207 """Overridden from Argument."""
6193 return "shared_memory_id_, shared_memory_offset_" 6208 return "shared_memory_id_, shared_memory_offset_"
6194 6209
6195 def GetValidGLArg(self, func, offset, index): 6210 def GetValidGLArg(self, func, offset, index):
6196 """Overridden from Argument.""" 6211 """Overridden from Argument."""
6197 return "reinterpret_cast<%s>(shared_memory_address_)" % self.type 6212 return "reinterpret_cast<%s>(shared_memory_address_)" % self.type
6198 6213
6199 def GetNumInvalidValues(self, func): 6214 def GetNumInvalidValues(self, func):
6200 """Overridden from Argument.""" 6215 """Overridden from Argument."""
(...skipping 1865 matching lines...) Expand 10 before | Expand all | Expand 10 after
8066 "ppapi/shared_impl/ppb_opengles2_shared.cc"]) 8081 "ppapi/shared_impl/ppb_opengles2_shared.cc"])
8067 8082
8068 if gen.errors > 0: 8083 if gen.errors > 0:
8069 print "%d errors" % gen.errors 8084 print "%d errors" % gen.errors
8070 return 1 8085 return 1
8071 return 0 8086 return 0
8072 8087
8073 8088
8074 if __name__ == '__main__': 8089 if __name__ == '__main__':
8075 sys.exit(main(sys.argv[1:])) 8090 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « no previous file | ppapi/shared_impl/ppb_opengles2_shared.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698