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

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

Issue 11363191: Cache more GL state both service and client side. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 1 month 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 | gpu/command_buffer/client/client_context_state.h » ('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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 60
61 # Capabilites selected with glEnable 61 # Capabilites selected with glEnable
62 _CAPABILITY_FLAGS = [ 62 _CAPABILITY_FLAGS = [
63 {'name': 'blend'}, 63 {'name': 'blend'},
64 {'name': 'cull_face'}, 64 {'name': 'cull_face'},
65 {'name': 'depth_test', 'state_flag': 'clear_state_dirty_'}, 65 {'name': 'depth_test', 'state_flag': 'clear_state_dirty_'},
66 {'name': 'dither', 'default': True}, 66 {'name': 'dither', 'default': True},
67 {'name': 'polygon_offset_fill'}, 67 {'name': 'polygon_offset_fill'},
68 {'name': 'sample_alpha_to_coverage'}, 68 {'name': 'sample_alpha_to_coverage'},
69 {'name': 'sample_coverage'}, 69 {'name': 'sample_coverage'},
70 {'name': 'scissor_test'}, 70 {'name': 'scissor_test', 'state_flag': 'clear_state_dirty_'},
71 {'name': 'stencil_test', 'state_flag': 'clear_state_dirty_'}, 71 {'name': 'stencil_test', 'state_flag': 'clear_state_dirty_'},
72 ] 72 ]
73 73
74 _STATES = { 74 _STATES = {
75 'ClearColor': { 75 'ClearColor': {
76 'type': 'Normal', 76 'type': 'Normal',
77 'func': 'ClearColor', 77 'func': 'ClearColor',
78 'enum': 'GL_COLOR_CLEAR_VALUE', 78 'enum': 'GL_COLOR_CLEAR_VALUE',
79 'states': [ 79 'states': [
80 {'name': 'color_clear_red', 'type': 'GLfloat', 'default': '0.0f'}, 80 {'name': 'color_clear_red', 'type': 'GLfloat', 'default': '0.0f'},
(...skipping 1123 matching lines...) Expand 10 before | Expand all | Expand 10 after
1204 }, 1204 },
1205 'ClearColor': { 1205 'ClearColor': {
1206 'type': 'StateSet', 1206 'type': 'StateSet',
1207 'state': 'ClearColor', 1207 'state': 'ClearColor',
1208 }, 1208 },
1209 'ClearDepthf': { 1209 'ClearDepthf': {
1210 'type': 'StateSet', 1210 'type': 'StateSet',
1211 'state': 'ClearDepthf', 1211 'state': 'ClearDepthf',
1212 'decoder_func': 'glClearDepth', 1212 'decoder_func': 'glClearDepth',
1213 'gl_test_func': 'glClearDepth', 1213 'gl_test_func': 'glClearDepth',
1214 'valid_args': {
1215 '0': '0.5f'
1216 },
1214 }, 1217 },
1215 'ColorMask': { 1218 'ColorMask': {
1216 'type': 'StateSet', 1219 'type': 'StateSet',
1217 'state': 'ColorMask', 1220 'state': 'ColorMask',
1218 'no_gl': True, 1221 'no_gl': True,
1219 'expectation': False, 1222 'expectation': False,
1220 }, 1223 },
1221 'ConsumeTextureCHROMIUM': { 1224 'ConsumeTextureCHROMIUM': {
1222 'decoder_func': 'DoConsumeTextureCHROMIUM', 1225 'decoder_func': 'DoConsumeTextureCHROMIUM',
1223 'type': 'PUT', 1226 'type': 'PUT',
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1268 'type': 'Create', 1271 'type': 'Create',
1269 'client_test': False, 1272 'client_test': False,
1270 }, 1273 },
1271 'BlendColor': { 1274 'BlendColor': {
1272 'type': 'StateSet', 1275 'type': 'StateSet',
1273 'state': 'BlendColor', 1276 'state': 'BlendColor',
1274 }, 1277 },
1275 'BlendEquation': { 1278 'BlendEquation': {
1276 'type': 'StateSetRGBAlpha', 1279 'type': 'StateSetRGBAlpha',
1277 'state': 'BlendEquation', 1280 'state': 'BlendEquation',
1281 'valid_args': {
1282 '0': 'GL_FUNC_SUBTRACT'
1283 },
1278 }, 1284 },
1279 'BlendEquationSeparate': { 1285 'BlendEquationSeparate': {
1280 'type': 'StateSet', 1286 'type': 'StateSet',
1281 'state': 'BlendEquation', 1287 'state': 'BlendEquation',
1288 'valid_args': {
1289 '0': 'GL_FUNC_SUBTRACT'
1290 },
1282 }, 1291 },
1283 'BlendFunc': { 1292 'BlendFunc': {
1284 'type': 'StateSetRGBAlpha', 1293 'type': 'StateSetRGBAlpha',
1285 'state': 'BlendFunc', 1294 'state': 'BlendFunc',
1286 }, 1295 },
1287 'BlendFuncSeparate': { 1296 'BlendFuncSeparate': {
1288 'type': 'StateSet', 1297 'type': 'StateSet',
1289 'state': 'BlendFunc', 1298 'state': 'BlendFunc',
1290 }, 1299 },
1291 'SampleCoverage': {'decoder_func': 'DoSampleCoverage'}, 1300 'SampleCoverage': {'decoder_func': 'DoSampleCoverage'},
1292 'StencilFunc': { 1301 'StencilFunc': {
1293 'type': 'StencilFrontBack', 1302 'type': 'StateSetFrontBack',
1294 'state': 'StencilFunc', 1303 'state': 'StencilFunc',
1295 }, 1304 },
1296 'StencilFuncSeparate': { 1305 'StencilFuncSeparate': {
1297 'type': 'StencilFrontBack', 1306 'type': 'StateSetFrontBackSeparate',
1298 'state': 'StencilFunc', 1307 'state': 'StencilFunc',
1299 }, 1308 },
1300 'StencilOp': { 1309 'StencilOp': {
1301 'type': 'StateSetFrontBack', 1310 'type': 'StateSetFrontBack',
1302 'state': 'StencilOp', 1311 'state': 'StencilOp',
1312 'valid_args': {
1313 '1': 'GL_INCR'
1314 },
1303 }, 1315 },
1304 'StencilOpSeparate': { 1316 'StencilOpSeparate': {
1305 'type': 'StateSetFrontBackSeparate', 1317 'type': 'StateSetFrontBackSeparate',
1306 'state': 'StencilOp', 1318 'state': 'StencilOp',
1319 'valid_args': {
1320 '1': 'GL_INCR'
1321 },
1307 }, 1322 },
1308 'Hint': {'decoder_func': 'DoHint'}, 1323 'Hint': {'decoder_func': 'DoHint'},
1309 'CullFace': {'type': 'StateSet', 'state': 'CullFace'}, 1324 'CullFace': {'type': 'StateSet', 'state': 'CullFace'},
1310 'FrontFace': {'type': 'StateSet', 'state': 'FrontFace'}, 1325 'FrontFace': {'type': 'StateSet', 'state': 'FrontFace'},
1311 'DepthFunc': {'type': 'StateSet', 'state': 'DepthFunc'}, 1326 'DepthFunc': {'type': 'StateSet', 'state': 'DepthFunc'},
1312 'LineWidth': {'type': 'StateSet', 'state': 'LineWidth'}, 1327 'LineWidth': {
1328 'type': 'StateSet',
1329 'state': 'LineWidth',
1330 'valid_args': {
1331 '0': '0.5f'
1332 },
1333 },
1313 'PolygonOffset': { 1334 'PolygonOffset': {
1314 'type': 'StateSet', 1335 'type': 'StateSet',
1315 'state': 'PolygonOffset', 1336 'state': 'PolygonOffset',
1316 }, 1337 },
1317 'DeleteBuffers': { 1338 'DeleteBuffers': {
1318 'type': 'DELn', 1339 'type': 'DELn',
1319 'gl_test_func': 'glDeleteBuffersARB', 1340 'gl_test_func': 'glDeleteBuffersARB',
1320 'resource_type': 'Buffer', 1341 'resource_type': 'Buffer',
1321 'resource_types': 'Buffers', 1342 'resource_types': 'Buffers',
1322 }, 1343 },
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1355 'DepthMask': { 1376 'DepthMask': {
1356 'type': 'StateSet', 1377 'type': 'StateSet',
1357 'state': 'DepthMask', 1378 'state': 'DepthMask',
1358 'no_gl': True, 1379 'no_gl': True,
1359 'expectation': False, 1380 'expectation': False,
1360 }, 1381 },
1361 'DetachShader': {'decoder_func': 'DoDetachShader'}, 1382 'DetachShader': {'decoder_func': 'DoDetachShader'},
1362 'Disable': { 1383 'Disable': {
1363 'decoder_func': 'DoDisable', 1384 'decoder_func': 'DoDisable',
1364 'impl_func': False, 1385 'impl_func': False,
1386 'client_test': False,
1365 }, 1387 },
1366 'DisableVertexAttribArray': { 1388 'DisableVertexAttribArray': {
1367 'decoder_func': 'DoDisableVertexAttribArray', 1389 'decoder_func': 'DoDisableVertexAttribArray',
1368 'impl_decl': False, 1390 'impl_decl': False,
1369 }, 1391 },
1370 'DrawArrays': { 1392 'DrawArrays': {
1371 'type': 'Manual', 1393 'type': 'Manual',
1372 'cmd_args': 'GLenumDrawMode mode, GLint first, GLsizei count', 1394 'cmd_args': 'GLenumDrawMode mode, GLint first, GLsizei count',
1373 }, 1395 },
1374 'DrawElements': { 1396 'DrawElements': {
1375 'type': 'Manual', 1397 'type': 'Manual',
1376 'cmd_args': 'GLenumDrawMode mode, GLsizei count, ' 1398 'cmd_args': 'GLenumDrawMode mode, GLsizei count, '
1377 'GLenumIndexType type, GLuint index_offset', 1399 'GLenumIndexType type, GLuint index_offset',
1378 'client_test': False 1400 'client_test': False
1379 }, 1401 },
1380 'Enable': { 1402 'Enable': {
1381 'decoder_func': 'DoEnable', 1403 'decoder_func': 'DoEnable',
1382 'impl_func': False, 1404 'impl_func': False,
1405 'client_test': False,
1383 }, 1406 },
1384 'EnableVertexAttribArray': { 1407 'EnableVertexAttribArray': {
1385 'decoder_func': 'DoEnableVertexAttribArray', 1408 'decoder_func': 'DoEnableVertexAttribArray',
1386 'impl_decl': False, 1409 'impl_decl': False,
1387 }, 1410 },
1388 'Finish': { 1411 'Finish': {
1389 'impl_func': False, 1412 'impl_func': False,
1390 'client_test': False, 1413 'client_test': False,
1391 'decoder_func': 'DoFinish', 1414 'decoder_func': 'DoFinish',
1392 }, 1415 },
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after
1929 'client_test': False, 1952 'client_test': False,
1930 'pepper_interface': 'ChromiumMapSub', 1953 'pepper_interface': 'ChromiumMapSub',
1931 }, 1954 },
1932 'UnmapTexSubImage2DCHROMIUM': { 1955 'UnmapTexSubImage2DCHROMIUM': {
1933 'gen_cmd': False, 1956 'gen_cmd': False,
1934 'extension': True, 1957 'extension': True,
1935 'chromium': True, 1958 'chromium': True,
1936 'client_test': False, 1959 'client_test': False,
1937 'pepper_interface': 'ChromiumMapSub', 1960 'pepper_interface': 'ChromiumMapSub',
1938 }, 1961 },
1939 'UseProgram': {'decoder_func': 'DoUseProgram', 'unit_test': False}, 1962 'UseProgram': {
1963 'decoder_func': 'DoUseProgram',
1964 'impl_func': False,
1965 'unit_test': False,
1966 },
1940 'ValidateProgram': {'decoder_func': 'DoValidateProgram'}, 1967 'ValidateProgram': {'decoder_func': 'DoValidateProgram'},
1941 'VertexAttrib1f': {'decoder_func': 'DoVertexAttrib1f'}, 1968 'VertexAttrib1f': {'decoder_func': 'DoVertexAttrib1f'},
1942 'VertexAttrib1fv': { 1969 'VertexAttrib1fv': {
1943 'type': 'PUT', 1970 'type': 'PUT',
1944 'data_type': 'GLfloat', 1971 'data_type': 'GLfloat',
1945 'count': 1, 1972 'count': 1,
1946 'decoder_func': 'DoVertexAttrib1fv', 1973 'decoder_func': 'DoVertexAttrib1fv',
1947 }, 1974 },
1948 'VertexAttrib2f': {'decoder_func': 'DoVertexAttrib2f'}, 1975 'VertexAttrib2f': {'decoder_func': 'DoVertexAttrib2f'},
1949 'VertexAttrib2fv': { 1976 'VertexAttrib2fv': {
(...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after
2843 2870
2844 def __init__(self): 2871 def __init__(self):
2845 TypeHandler.__init__(self) 2872 TypeHandler.__init__(self)
2846 2873
2847 def WriteHandlerImplementation(self, func, file): 2874 def WriteHandlerImplementation(self, func, file):
2848 """Overrriden from TypeHandler.""" 2875 """Overrriden from TypeHandler."""
2849 state_name = func.GetInfo('state') 2876 state_name = func.GetInfo('state')
2850 state = _STATES[state_name] 2877 state = _STATES[state_name]
2851 states = state['states'] 2878 states = state['states']
2852 args = func.GetOriginalArgs() 2879 args = func.GetOriginalArgs()
2880 code = []
2853 for ndx,item in enumerate(states): 2881 for ndx,item in enumerate(states):
2854 file.Write(" state_.%s = %s;\n" % (item['name'], args[ndx].name)) 2882 code.append("state_.%s != %s" % (item['name'], args[ndx].name))
2883 file.Write(" if (%s) {\n" % " ||\n ".join(code))
2884 for ndx,item in enumerate(states):
2885 file.Write(" state_.%s = %s;\n" % (item['name'], args[ndx].name))
2855 if 'state_flag' in state: 2886 if 'state_flag' in state:
2856 file.Write(" %s = true;\n" % state['state_flag']) 2887 file.Write(" %s = true;\n" % state['state_flag'])
2857 if not func.GetInfo("no_gl"): 2888 if not func.GetInfo("no_gl"):
2858 file.Write(" %s(%s);\n" % 2889 file.Write(" %s(%s);\n" %
2859 (func.GetGLFunctionName(), func.MakeOriginalArgString(""))) 2890 (func.GetGLFunctionName(), func.MakeOriginalArgString("")))
2891 file.Write(" }\n")
2860 2892
2861 2893
2862 class StateSetRGBAlphaHandler(TypeHandler): 2894 class StateSetRGBAlphaHandler(TypeHandler):
2863 """Handler for commands that simply set state that have rgb/alpha.""" 2895 """Handler for commands that simply set state that have rgb/alpha."""
2864 2896
2865 def __init__(self): 2897 def __init__(self):
2866 TypeHandler.__init__(self) 2898 TypeHandler.__init__(self)
2867 2899
2868 def WriteHandlerImplementation(self, func, file): 2900 def WriteHandlerImplementation(self, func, file):
2869 """Overrriden from TypeHandler.""" 2901 """Overrriden from TypeHandler."""
2870 state_name = func.GetInfo('state') 2902 state_name = func.GetInfo('state')
2871 state = _STATES[state_name] 2903 state = _STATES[state_name]
2872 states = state['states'] 2904 states = state['states']
2873 args = func.GetOriginalArgs() 2905 args = func.GetOriginalArgs()
2874 num_args = len(args) 2906 num_args = len(args)
2875 for ndx, item in enumerate(states): 2907 code = []
2876 file.Write(" state_.%s = %s;\n" % 2908 for ndx,item in enumerate(states):
2909 code.append("state_.%s != %s" % (item['name'], args[ndx % num_args].name))
2910 file.Write(" if (%s) {\n" % " ||\n ".join(code))
2911 for ndx,item in enumerate(states):
2912 file.Write(" state_.%s = %s;\n" %
2877 (item['name'], args[ndx % num_args].name)) 2913 (item['name'], args[ndx % num_args].name))
2878 if 'state_flag' in state: 2914 if 'state_flag' in state:
2879 file.Write(" %s = true;\n" % state['state_flag']) 2915 file.Write(" %s = true;\n" % state['state_flag'])
2880 if not func.GetInfo("no_gl"): 2916 if not func.GetInfo("no_gl"):
2881 file.Write(" %s(%s);\n" % 2917 file.Write(" %s(%s);\n" %
2882 (func.GetGLFunctionName(), func.MakeOriginalArgString(""))) 2918 (func.GetGLFunctionName(), func.MakeOriginalArgString("")))
2919 file.Write(" }\n")
2883 2920
2884 2921
2885 class StateSetFrontBackSeparateHandler(TypeHandler): 2922 class StateSetFrontBackSeparateHandler(TypeHandler):
2886 """Handler for commands that simply set state that have front/back.""" 2923 """Handler for commands that simply set state that have front/back."""
2887 2924
2888 def __init__(self): 2925 def __init__(self):
2889 TypeHandler.__init__(self) 2926 TypeHandler.__init__(self)
2890 2927
2891 def WriteHandlerImplementation(self, func, file): 2928 def WriteHandlerImplementation(self, func, file):
2892 """Overrriden from TypeHandler.""" 2929 """Overrriden from TypeHandler."""
2893 state_name = func.GetInfo('state') 2930 state_name = func.GetInfo('state')
2894 state = _STATES[state_name] 2931 state = _STATES[state_name]
2895 states = state['states'] 2932 states = state['states']
2896 args = func.GetOriginalArgs() 2933 args = func.GetOriginalArgs()
2897 face = args[0].name 2934 face = args[0].name
2898 num_args = len(args) 2935 num_args = len(args)
2936 file.Write(" bool changed = false;\n")
2899 for group_ndx, group in enumerate(Grouper(num_args - 1, states)): 2937 for group_ndx, group in enumerate(Grouper(num_args - 1, states)):
2900 file.Write(" if (%s == %s || %s == GL_FRONT_AND_BACK) {\n" % 2938 file.Write(" if (%s == %s || %s == GL_FRONT_AND_BACK) {\n" %
2901 (face, ('GL_FRONT', 'GL_BACK')[group_ndx], face)) 2939 (face, ('GL_FRONT', 'GL_BACK')[group_ndx], face))
2940 code = []
2902 for ndx, item in enumerate(group): 2941 for ndx, item in enumerate(group):
2903 file.Write(" state_.%s = %s;\n" % (item['name'], args[ndx + 1].name)) 2942 code.append("state_.%s != %s" % (item['name'], args[ndx + 1].name))
2943 file.Write(" changed |= %s;\n" % " ||\n ".join(code))
2904 file.Write(" }\n") 2944 file.Write(" }\n")
2945 file.Write(" if (changed) {\n")
2946 for group_ndx, group in enumerate(Grouper(num_args - 1, states)):
2947 file.Write(" if (%s == %s || %s == GL_FRONT_AND_BACK) {\n" %
2948 (face, ('GL_FRONT', 'GL_BACK')[group_ndx], face))
2949 for ndx, item in enumerate(group):
2950 file.Write(" state_.%s = %s;\n" %
2951 (item['name'], args[ndx + 1].name))
2952 file.Write(" }\n")
2905 if 'state_flag' in state: 2953 if 'state_flag' in state:
2906 file.Write(" %s = true;\n" % state['state_flag']) 2954 file.Write(" %s = true;\n" % state['state_flag'])
2907 if not func.GetInfo("no_gl"): 2955 if not func.GetInfo("no_gl"):
2908 file.Write(" %s(%s);\n" % 2956 file.Write(" %s(%s);\n" %
2909 (func.GetGLFunctionName(), func.MakeOriginalArgString(""))) 2957 (func.GetGLFunctionName(), func.MakeOriginalArgString("")))
2958 file.Write(" }\n")
2910 2959
2911 2960
2912 class StateSetFrontBackHandler(TypeHandler): 2961 class StateSetFrontBackHandler(TypeHandler):
2913 """Handler for commands that simply set state that set both front/back.""" 2962 """Handler for commands that simply set state that set both front/back."""
2914 2963
2915 def __init__(self): 2964 def __init__(self):
2916 TypeHandler.__init__(self) 2965 TypeHandler.__init__(self)
2917 2966
2918 def WriteHandlerImplementation(self, func, file): 2967 def WriteHandlerImplementation(self, func, file):
2919 """Overrriden from TypeHandler.""" 2968 """Overrriden from TypeHandler."""
2920 state_name = func.GetInfo('state') 2969 state_name = func.GetInfo('state')
2921 state = _STATES[state_name] 2970 state = _STATES[state_name]
2922 states = state['states'] 2971 states = state['states']
2923 args = func.GetOriginalArgs() 2972 args = func.GetOriginalArgs()
2924 face = args[0].name
2925 num_args = len(args) 2973 num_args = len(args)
2974 code = []
2926 for group_ndx, group in enumerate(Grouper(num_args, states)): 2975 for group_ndx, group in enumerate(Grouper(num_args, states)):
2927 for ndx, item in enumerate(group): 2976 for ndx, item in enumerate(group):
2928 file.Write(" state_.%s = %s;\n" % (item['name'], args[ndx].name)) 2977 code.append("state_.%s != %s" % (item['name'], args[ndx].name))
2978 file.Write(" if (%s) {\n" % " ||\n ".join(code))
2979 for group_ndx, group in enumerate(Grouper(num_args, states)):
2980 for ndx, item in enumerate(group):
2981 file.Write(" state_.%s = %s;\n" % (item['name'], args[ndx].name))
2929 if 'state_flag' in state: 2982 if 'state_flag' in state:
2930 file.Write(" %s = true;\n" % state['state_flag']) 2983 file.Write(" %s = true;\n" % state['state_flag'])
2931 if not func.GetInfo("no_gl"): 2984 if not func.GetInfo("no_gl"):
2932 file.Write(" %s(%s);\n" % 2985 file.Write(" %s(%s);\n" %
2933 (func.GetGLFunctionName(), func.MakeOriginalArgString(""))) 2986 (func.GetGLFunctionName(), func.MakeOriginalArgString("")))
2987 file.Write(" }\n")
2988
2934 2989
2935 class CustomHandler(TypeHandler): 2990 class CustomHandler(TypeHandler):
2936 """Handler for commands that are auto-generated but require minor tweaks.""" 2991 """Handler for commands that are auto-generated but require minor tweaks."""
2937 2992
2938 def __init__(self): 2993 def __init__(self):
2939 TypeHandler.__init__(self) 2994 TypeHandler.__init__(self)
2940 2995
2941 def WriteServiceImplementation(self, func, file): 2996 def WriteServiceImplementation(self, func, file):
2942 """Overrriden from TypeHandler.""" 2997 """Overrriden from TypeHandler."""
2943 pass 2998 pass
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
3369 file.Write(" GPU_CLIENT_SINGLE_THREAD_CHECK();\n") 3424 file.Write(" GPU_CLIENT_SINGLE_THREAD_CHECK();\n")
3370 func.WriteDestinationInitalizationValidation(file) 3425 func.WriteDestinationInitalizationValidation(file)
3371 self.WriteClientGLCallLog(func, file) 3426 self.WriteClientGLCallLog(func, file)
3372 for arg in func.GetOriginalArgs(): 3427 for arg in func.GetOriginalArgs():
3373 arg.WriteClientSideValidationCode(file, func) 3428 arg.WriteClientSideValidationCode(file, func)
3374 3429
3375 code = """ if (Is%(type)sReservedId(%(id)s)) { 3430 code = """ if (Is%(type)sReservedId(%(id)s)) {
3376 SetGLError(GL_INVALID_OPERATION, "%(name)s\", \"%(id)s reserved id"); 3431 SetGLError(GL_INVALID_OPERATION, "%(name)s\", \"%(id)s reserved id");
3377 return; 3432 return;
3378 } 3433 }
3379 Bind%(type)sHelper(%(arg_string)s); 3434 if (Bind%(type)sHelper(%(arg_string)s)) {
3380 helper_->%(name)s(%(arg_string)s); 3435 helper_->%(name)s(%(arg_string)s);
3436 }
3381 } 3437 }
3382 3438
3383 """ 3439 """
3384 name_arg = None 3440 name_arg = None
3385 if len(func.GetOriginalArgs()) == 1: 3441 if len(func.GetOriginalArgs()) == 1:
3386 # Bind functions that have no target (like BindVertexArrayOES) 3442 # Bind functions that have no target (like BindVertexArrayOES)
3387 name_arg = func.GetOriginalArgs()[0] 3443 name_arg = func.GetOriginalArgs()[0]
3388 else: 3444 else:
3389 # Bind functions that have both a target and a name (like BindTexture) 3445 # Bind functions that have both a target and a name (like BindTexture)
3390 name_arg = func.GetOriginalArgs()[1] 3446 name_arg = func.GetOriginalArgs()[1]
3391 3447
3392 file.Write(code % { 3448 file.Write(code % {
3393 'name': func.name, 3449 'name': func.name,
3394 'arg_string': func.MakeOriginalArgString(""), 3450 'arg_string': func.MakeOriginalArgString(""),
3395 'id': name_arg.name, 3451 'id': name_arg.name,
3396 'type': name_arg.resource_type, 3452 'type': name_arg.resource_type,
3397 'lc_type': name_arg.resource_type.lower(), 3453 'lc_type': name_arg.resource_type.lower(),
3398 }) 3454 })
3399 3455
3456 def WriteGLES2ImplementationUnitTest(self, func, file):
3457 """Overrriden from TypeHandler."""
3458 code = """
3459 TEST_F(GLES2ImplementationTest, %(name)s) {
3460 struct Cmds {
3461 %(name)s cmd;
3462 };
3463 Cmds expected;
3464 expected.cmd.Init(%(cmd_args)s);
3465
3466 gl_->%(name)s(%(args)s);
3467 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected)));
3468 ClearCommands();
3469 gl_->%(name)s(%(args)s);
3470 EXPECT_TRUE(NoCommandsWritten());
3471 }
3472 """
3473 cmd_arg_strings = []
3474 for count, arg in enumerate(func.GetCmdArgs()):
3475 cmd_arg_strings.append(arg.GetValidClientSideCmdArg(func, count, 0))
3476 count += 1
3477 gl_arg_strings = []
3478 for count, arg in enumerate(func.GetOriginalArgs()):
3479 gl_arg_strings.append(arg.GetValidClientSideArg(func, count, 0))
3480 file.Write(code % {
3481 'name': func.name,
3482 'args': ", ".join(gl_arg_strings),
3483 'cmd_args': ", ".join(cmd_arg_strings),
3484 })
3485
3400 3486
3401 class GENnHandler(TypeHandler): 3487 class GENnHandler(TypeHandler):
3402 """Handler for glGen___ type functions.""" 3488 """Handler for glGen___ type functions."""
3403 3489
3404 def __init__(self): 3490 def __init__(self):
3405 TypeHandler.__init__(self) 3491 TypeHandler.__init__(self)
3406 3492
3407 def InitFunction(self, func): 3493 def InitFunction(self, func):
3408 """Overrriden from TypeHandler.""" 3494 """Overrriden from TypeHandler."""
3409 pass 3495 pass
(...skipping 2896 matching lines...) Expand 10 before | Expand all | Expand 10 after
6306 interface = PepperInterface(interface) 6392 interface = PepperInterface(interface)
6307 self.pepper_interfaces.append(interface) 6393 self.pepper_interfaces.append(interface)
6308 self.interface_info[interface.GetName()] = interface 6394 self.interface_info[interface.GetName()] = interface
6309 6395
6310 def AddFunction(self, func): 6396 def AddFunction(self, func):
6311 """Adds a function.""" 6397 """Adds a function."""
6312 self.functions.append(func) 6398 self.functions.append(func)
6313 6399
6314 def GetTypeHandler(self, name): 6400 def GetTypeHandler(self, name):
6315 """Gets a type info for the given type.""" 6401 """Gets a type info for the given type."""
6316 if name in self._type_handlers: 6402 if len(name):
6317 return self._type_handlers[name] 6403 if name in self._type_handlers:
6404 return self._type_handlers[name]
6405 else:
6406 raise KeyError("no such type handler: %s" % name)
6318 return self._empty_type_handler 6407 return self._empty_type_handler
6319 6408
6320 def GetFunctionInfo(self, name): 6409 def GetFunctionInfo(self, name):
6321 """Gets a type info for the given function name.""" 6410 """Gets a type info for the given function name."""
6322 if name in self._function_info: 6411 if name in self._function_info:
6323 return self._function_info[name] 6412 return self._function_info[name]
6324 return self._empty_function_info 6413 return self._empty_function_info
6325 6414
6326 def Log(self, msg): 6415 def Log(self, msg):
6327 """Prints something if verbose is true.""" 6416 """Prints something if verbose is true."""
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
6481 file = CHeaderWriter(filename) 6570 file = CHeaderWriter(filename)
6482 6571
6483 for func in self.functions: 6572 for func in self.functions:
6484 if True: 6573 if True:
6485 #gen_cmd = func.GetInfo('gen_cmd') 6574 #gen_cmd = func.GetInfo('gen_cmd')
6486 #if gen_cmd == True or gen_cmd == None: 6575 #if gen_cmd == True or gen_cmd == None:
6487 func.WriteCmdHelper(file) 6576 func.WriteCmdHelper(file)
6488 6577
6489 file.Close() 6578 file.Close()
6490 6579
6491 def WriteContextStateHeader(self, filename): 6580 def WriteServiceContextStateHeader(self, filename):
6492 """Writes the context state header.""" 6581 """Writes the service context state header."""
6493 file = CHeaderWriter( 6582 file = CHeaderWriter(
6494 filename, 6583 filename,
6495 "// It is included by context_state.h\n") 6584 "// It is included by context_state.h\n")
6496 file.Write("struct EnableFlags {\n") 6585 file.Write("struct EnableFlags {\n")
6497 file.Write(" EnableFlags();\n") 6586 file.Write(" EnableFlags();\n")
6498 for capability in _CAPABILITY_FLAGS: 6587 for capability in _CAPABILITY_FLAGS:
6499 file.Write(" bool %s;\n" % capability['name']) 6588 file.Write(" bool %s;\n" % capability['name'])
6500 file.Write("};\n\n") 6589 file.Write("};\n\n")
6501 6590
6502 for state_name in sorted(_STATES.keys()): 6591 for state_name in sorted(_STATES.keys()):
6503 state = _STATES[state_name] 6592 state = _STATES[state_name]
6504 for item in state['states']: 6593 for item in state['states']:
6505 file.Write("%s %s;\n" % (item['type'], item['name'])) 6594 file.Write("%s %s;\n" % (item['type'], item['name']))
6506 file.Write("\n") 6595 file.Write("\n")
6507 6596
6508 file.Close() 6597 file.Close()
6509 6598
6510 def WriteContextStateImpl(self, filename): 6599 def WriteClientContextStateHeader(self, filename):
6511 """Writes the context state implementation.""" 6600 """Writes the client context state header."""
6601 file = CHeaderWriter(
6602 filename,
6603 "// It is included by client_context_state.h\n")
6604 file.Write("struct EnableFlags {\n")
6605 file.Write(" EnableFlags();\n")
6606 for capability in _CAPABILITY_FLAGS:
6607 file.Write(" bool %s;\n" % capability['name'])
6608 file.Write("};\n\n")
6609
6610 file.Close()
6611
6612 def WriteContextStateGetters(self, file, class_name):
6613 """Writes the state getters."""
6614 for gl_type in ["GLint", "GLfloat"]:
6615 file.Write("""
6616 bool %s::GetStateAs%s(
6617 GLenum pname, %s* params, GLsizei* num_written) const {
6618 switch (pname) {
6619 """ % (class_name, gl_type, gl_type))
6620 for state_name in _STATES.keys():
6621 state = _STATES[state_name]
6622 if 'enum' in state:
6623 file.Write(" case %s:\n" % state['enum'])
6624 file.Write(" *num_written = %d;\n" % len(state['states']))
6625 file.Write(" if (params) {\n")
6626 for ndx,item in enumerate(state['states']):
6627 file.Write(" params[%d] = static_cast<%s>(%s);\n" %
6628 (ndx, gl_type, item['name']))
6629 file.Write(" }\n")
6630 file.Write(" return true;\n")
6631 else:
6632 for item in state['states']:
6633 file.Write(" case %s:\n" % item['enum'])
6634 file.Write(" *num_written = 1;\n")
6635 file.Write(" if (params) {\n")
6636 file.Write(" params[0] = static_cast<%s>(%s);\n" %
6637 (gl_type, item['name']))
6638 file.Write(" }\n")
6639 file.Write(" return true;\n")
6640 for capability in _CAPABILITY_FLAGS:
6641 file.Write(" case GL_%s:\n" % capability['name'].upper())
6642 file.Write(" *num_written = 1;\n")
6643 file.Write(" if (params) {\n")
6644 file.Write(
6645 " params[0] = static_cast<%s>(enable_flags.%s);\n" %
6646 (gl_type, capability['name']))
6647 file.Write(" }\n")
6648 file.Write(" return true;\n")
6649 file.Write(""" default:
6650 return false;
6651 }
6652 }
6653 """)
6654
6655 def WriteServiceContextStateImpl(self, filename):
6656 """Writes the context state service implementation."""
6512 file = CHeaderWriter( 6657 file = CHeaderWriter(
6513 filename, 6658 filename,
6514 "// It is included by context_state.cc\n") 6659 "// It is included by context_state.cc\n")
6515 code = [] 6660 code = []
6516 for capability in _CAPABILITY_FLAGS: 6661 for capability in _CAPABILITY_FLAGS:
6517 code.append("%s(%s)" % 6662 code.append("%s(%s)" %
6518 (capability['name'], 6663 (capability['name'],
6519 ('false', 'true')['default' in capability])) 6664 ('false', 'true')['default' in capability]))
6520 file.Write("ContextState::EnableFlags::EnableFlags()\n : %s {\n}\n" % 6665 file.Write("ContextState::EnableFlags::EnableFlags()\n : %s {\n}\n" %
6521 ",\n ".join(code)) 6666 ",\n ".join(code))
(...skipping 29 matching lines...) Expand all
6551 file.Write( 6696 file.Write(
6552 " gl%s(%s, %s);\n" % 6697 " gl%s(%s, %s);\n" %
6553 (state['func'], ('GL_FRONT', 'GL_BACK')[ndx], ", ".join(args))) 6698 (state['func'], ('GL_FRONT', 'GL_BACK')[ndx], ", ".join(args)))
6554 else: 6699 else:
6555 args = [] 6700 args = []
6556 for item in state['states']: 6701 for item in state['states']:
6557 args.append('%s' % item['name']) 6702 args.append('%s' % item['name'])
6558 file.Write(" gl%s(%s);\n" % (state['func'], ", ".join(args))) 6703 file.Write(" gl%s(%s);\n" % (state['func'], ", ".join(args)))
6559 file.Write("}\n") 6704 file.Write("}\n")
6560 6705
6706 file.Write("""bool ContextState::GetEnabled(GLenum cap) const {
6707 switch (cap) {
6708 """)
6709 for capability in _CAPABILITY_FLAGS:
6710 file.Write(" case GL_%s:\n" % capability['name'].upper())
6711 file.Write(" return enable_flags.%s;\n" % capability['name'])
6712 file.Write(""" default:
6713 GPU_NOTREACHED();
6714 return false;
6715 }
6716 }
6717 """)
6718
6719 self.WriteContextStateGetters(file, "ContextState")
6720 file.Close()
6721
6722 def WriteClientContextStateImpl(self, filename):
6723 """Writes the context state client side implementation."""
6724 file = CHeaderWriter(
6725 filename,
6726 "// It is included by client_context_state.cc\n")
6727 code = []
6728 for capability in _CAPABILITY_FLAGS:
6729 code.append("%s(%s)" %
6730 (capability['name'],
6731 ('false', 'true')['default' in capability]))
6732 file.Write(
6733 "ClientContextState::EnableFlags::EnableFlags()\n : %s {\n}\n" %
6734 ",\n ".join(code))
6735 file.Write("\n")
6736
6737 file.Write("""
6738 bool ClientContextState::SetCapabilityState(
6739 GLenum cap, bool enabled, bool* changed) {
6740 *changed = false;
6741 switch (cap) {
6742 """)
6743 for capability in _CAPABILITY_FLAGS:
6744 file.Write(" case GL_%s:\n" % capability['name'].upper())
6745 file.Write(""" if (enable_flags.%(name)s != enabled) {
6746 *changed = true;
6747 enable_flags.%(name)s = enabled;
6748 }
6749 return true;
6750 """ % capability)
6751 file.Write(""" default:
6752 return false;
6753 }
6754 }
6755 """)
6756 file.Write("""bool ClientContextState::GetEnabled(
6757 GLenum cap, bool* enabled) const {
6758 switch (cap) {
6759 """)
6760 for capability in _CAPABILITY_FLAGS:
6761 file.Write(" case GL_%s:\n" % capability['name'].upper())
6762 file.Write(" *enabled = enable_flags.%s;\n" % capability['name'])
6763 file.Write(" return true;\n")
6764 file.Write(""" default:
6765 return false;
6766 }
6767 }
6768 """)
6561 file.Close() 6769 file.Close()
6562 6770
6563 def WriteServiceImplementation(self, filename): 6771 def WriteServiceImplementation(self, filename):
6564 """Writes the service decorder implementation.""" 6772 """Writes the service decorder implementation."""
6565 file = CHeaderWriter( 6773 file = CHeaderWriter(
6566 filename, 6774 filename,
6567 "// It is included by gles2_cmd_decoder.cc\n") 6775 "// It is included by gles2_cmd_decoder.cc\n")
6568 6776
6569 for func in self.functions: 6777 for func in self.functions:
6570 if True: 6778 if True:
(...skipping 16 matching lines...) Expand all
6587 """ % capability) 6795 """ % capability)
6588 else: 6796 else:
6589 file.Write(""" state_.enable_flags.%(name)s = enabled; 6797 file.Write(""" state_.enable_flags.%(name)s = enabled;
6590 return true; 6798 return true;
6591 """ % capability) 6799 """ % capability)
6592 file.Write(""" default: 6800 file.Write(""" default:
6593 NOTREACHED(); 6801 NOTREACHED();
6594 return false; 6802 return false;
6595 } 6803 }
6596 } 6804 }
6597
6598 bool GLES2DecoderImpl::DoIsEnabled(GLenum cap) {
6599 switch (cap) {
6600 """)
6601 for capability in _CAPABILITY_FLAGS:
6602 file.Write(" case GL_%s:\n" % capability['name'].upper())
6603 file.Write(" return state_.enable_flags.%s;\n" %
6604 capability['name'])
6605 file.Write(""" default:
6606 NOTREACHED();
6607 return false;
6608 }
6609 }
6610 """)
6611 for gl_type in ["GLint", "GLfloat"]:
6612 file.Write("""
6613 bool GLES2DecoderImpl::GetStateAs%s(
6614 GLenum pname, %s* params, GLsizei* num_written) {
6615 switch (pname) {
6616 """ % (gl_type, gl_type))
6617 for state_name in _STATES.keys():
6618 state = _STATES[state_name]
6619 if 'enum' in state:
6620 file.Write(" case %s:\n" % state['enum'])
6621 file.Write(" *num_written = %d;\n" % len(state['states']))
6622 file.Write(" if (params) {\n")
6623 for ndx,item in enumerate(state['states']):
6624 file.Write(" params[%d] = static_cast<%s>(state_.%s);\n" %
6625 (ndx, gl_type, item['name']))
6626 file.Write(" }\n")
6627 file.Write(" return true;\n")
6628 else:
6629 for item in state['states']:
6630 file.Write(" case %s:\n" % item['enum'])
6631 file.Write(" *num_written = 1;\n")
6632 file.Write(" if (params) {\n")
6633 file.Write(" params[0] = static_cast<%s>(state_.%s);\n" %
6634 (gl_type, item['name']))
6635 file.Write(" }\n")
6636 file.Write(" return true;\n")
6637 for capability in _CAPABILITY_FLAGS:
6638 file.Write(" case GL_%s:\n" % capability['name'].upper())
6639 file.Write(" *num_written = 1;\n")
6640 file.Write(" if (params) {\n")
6641 file.Write(" params[0] = static_cast<%s>("
6642 "state_.enable_flags.%s);\n" %
6643 (gl_type, capability['name']))
6644 file.Write(" }\n")
6645 file.Write(" return true;\n")
6646 file.Write(""" default:
6647 return false;
6648 }
6649 }
6650 """) 6805 """)
6651 file.Close() 6806 file.Close()
6652 6807
6653 def WriteServiceUnitTests(self, filename): 6808 def WriteServiceUnitTests(self, filename):
6654 """Writes the service decorder unit tests.""" 6809 """Writes the service decorder unit tests."""
6655 num_tests = len(self.functions) 6810 num_tests = len(self.functions)
6656 FUNCTIONS_PER_FILE = 98 # hard code this so it doesn't change. 6811 FUNCTIONS_PER_FILE = 98 # hard code this so it doesn't change.
6657 count = 0 6812 count = 0
6658 for test_num in range(0, num_tests, FUNCTIONS_PER_FILE): 6813 for test_num in range(0, num_tests, FUNCTIONS_PER_FILE):
6659 count += 1 6814 count += 1
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
7171 gen.WriteGLES2InterfaceStub("client/gles2_interface_stub_autogen.h") 7326 gen.WriteGLES2InterfaceStub("client/gles2_interface_stub_autogen.h")
7172 gen.WriteGLES2InterfaceStubImpl( 7327 gen.WriteGLES2InterfaceStubImpl(
7173 "client/gles2_interface_stub_impl_autogen.h") 7328 "client/gles2_interface_stub_impl_autogen.h")
7174 gen.WriteGLES2ImplementationHeader("client/gles2_implementation_autogen.h") 7329 gen.WriteGLES2ImplementationHeader("client/gles2_implementation_autogen.h")
7175 gen.WriteGLES2Implementation("client/gles2_implementation_impl_autogen.h") 7330 gen.WriteGLES2Implementation("client/gles2_implementation_impl_autogen.h")
7176 gen.WriteGLES2ImplementationUnitTests( 7331 gen.WriteGLES2ImplementationUnitTests(
7177 "client/gles2_implementation_unittest_autogen.h") 7332 "client/gles2_implementation_unittest_autogen.h")
7178 gen.WriteGLES2CLibImplementation("client/gles2_c_lib_autogen.h") 7333 gen.WriteGLES2CLibImplementation("client/gles2_c_lib_autogen.h")
7179 gen.WriteCmdHelperHeader("client/gles2_cmd_helper_autogen.h") 7334 gen.WriteCmdHelperHeader("client/gles2_cmd_helper_autogen.h")
7180 gen.WriteServiceImplementation("service/gles2_cmd_decoder_autogen.h") 7335 gen.WriteServiceImplementation("service/gles2_cmd_decoder_autogen.h")
7181 gen.WriteContextStateHeader("service/context_state_autogen.h") 7336 gen.WriteServiceContextStateHeader("service/context_state_autogen.h")
7182 gen.WriteContextStateImpl("service/context_state_impl_autogen.h") 7337 gen.WriteServiceContextStateImpl("service/context_state_impl_autogen.h")
7338 gen.WriteClientContextStateHeader("client/client_context_state_autogen.h")
7339 gen.WriteClientContextStateImpl(
7340 "client/client_context_state_impl_autogen.h")
7183 gen.WriteServiceUnitTests("service/gles2_cmd_decoder_unittest_%d_autogen.h") 7341 gen.WriteServiceUnitTests("service/gles2_cmd_decoder_unittest_%d_autogen.h")
7184 gen.WriteServiceUtilsHeader("service/gles2_cmd_validation_autogen.h") 7342 gen.WriteServiceUtilsHeader("service/gles2_cmd_validation_autogen.h")
7185 gen.WriteServiceUtilsImplementation( 7343 gen.WriteServiceUtilsImplementation(
7186 "service/gles2_cmd_validation_implementation_autogen.h") 7344 "service/gles2_cmd_validation_implementation_autogen.h")
7187 gen.WriteCommonUtilsHeader("common/gles2_cmd_utils_autogen.h") 7345 gen.WriteCommonUtilsHeader("common/gles2_cmd_utils_autogen.h")
7188 gen.WriteCommonUtilsImpl("common/gles2_cmd_utils_implementation_autogen.h") 7346 gen.WriteCommonUtilsImpl("common/gles2_cmd_utils_implementation_autogen.h")
7189 7347
7190 if gen.errors > 0: 7348 if gen.errors > 0:
7191 print "%d errors" % gen.errors 7349 print "%d errors" % gen.errors
7192 return 1 7350 return 1
7193 return 0 7351 return 0
7194 7352
7195 7353
7196 if __name__ == '__main__': 7354 if __name__ == '__main__':
7197 sys.exit(main(sys.argv[1:])) 7355 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « no previous file | gpu/command_buffer/client/client_context_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698