summaryrefslogtreecommitdiffstats
path: root/gpu
diff options
context:
space:
mode:
authorgman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-30 00:35:22 +0000
committergman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-30 00:35:22 +0000
commitf731b9460b41625dca0baa3ececaf5caa3adb364 (patch)
treea44a58aacf9155738d36b4dd9769fa78c10bf843 /gpu
parent56b347ad82aa19dddb6180171717d67326fb4ba0 (diff)
downloadchromium_src-f731b9460b41625dca0baa3ececaf5caa3adb364.zip
chromium_src-f731b9460b41625dca0baa3ececaf5caa3adb364.tar.gz
chromium_src-f731b9460b41625dca0baa3ececaf5caa3adb364.tar.bz2
automate more GL state handling
BUG=155557 Review URL: https://chromiumcodereview.appspot.com/11301006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@164798 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gpu')
-rwxr-xr-xgpu/command_buffer/build_gles2_cmd_buffer.py942
-rw-r--r--gpu/command_buffer/client/gles2_implementation_unittest_autogen.h8
-rw-r--r--gpu/command_buffer/common/gles2_cmd_utils_implementation_autogen.h89
-rw-r--r--gpu/command_buffer/service/context_state.cc82
-rw-r--r--gpu/command_buffer/service/context_state.h81
-rw-r--r--gpu/command_buffer/service/context_state_autogen.h81
-rw-r--r--gpu/command_buffer/service/context_state_impl_autogen.h130
-rw-r--r--gpu/command_buffer/service/gles2_cmd_decoder.cc285
-rw-r--r--gpu/command_buffer/service/gles2_cmd_decoder_autogen.h415
-rw-r--r--gpu/command_buffer/service/gles2_cmd_decoder_unittest_0_autogen.h99
-rw-r--r--gpu/command_buffer/service/gles2_cmd_decoder_unittest_1_autogen.h8
-rw-r--r--gpu/command_buffer/service/gles2_cmd_decoder_unittest_2_autogen.h6
-rw-r--r--gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc123
-rw-r--r--gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h4
-rw-r--r--gpu/command_buffer/service/gles2_cmd_validation_implementation_autogen.h89
-rw-r--r--gpu/command_buffer_service.gypi2
-rw-r--r--gpu/gpu.gyp1
17 files changed, 1638 insertions, 807 deletions
diff --git a/gpu/command_buffer/build_gles2_cmd_buffer.py b/gpu/command_buffer/build_gles2_cmd_buffer.py
index 302e0ab..450dea4 100755
--- a/gpu/command_buffer/build_gles2_cmd_buffer.py
+++ b/gpu/command_buffer/build_gles2_cmd_buffer.py
@@ -5,6 +5,7 @@
"""code generator for GLES2 command buffers."""
+import itertools
import os
import os.path
import sys
@@ -57,6 +58,376 @@ _GL_TYPES = {
'GLsizeiptr': 'long int',
}
+# Capabilites selected with glEnable
+_CAPABILITY_FLAGS = [
+ {'name': 'blend'},
+ {'name': 'cull_face'},
+ {'name': 'depth_test', 'state_flag': 'clear_state_dirty_'},
+ {'name': 'dither', 'default': True},
+ {'name': 'polygon_offset_fill'},
+ {'name': 'sample_alpha_to_coverage'},
+ {'name': 'sample_coverage'},
+ {'name': 'scissor_test'},
+ {'name': 'stencil_test', 'state_flag': 'clear_state_dirty_'},
+]
+
+_STATES = {
+ 'ClearColor': {
+ 'type': 'Normal',
+ 'func': 'ClearColor',
+ 'enum': 'GL_COLOR_CLEAR_VALUE',
+ 'states': [
+ {'name': 'color_clear_red', 'type': 'GLfloat', 'default': '0.0f'},
+ {'name': 'color_clear_green', 'type': 'GLfloat', 'default': '0.0f'},
+ {'name': 'color_clear_blue', 'type': 'GLfloat', 'default': '0.0f'},
+ {'name': 'color_clear_alpha', 'type': 'GLfloat', 'default': '0.0f'},
+ ],
+ },
+ 'ClearDepthf': {
+ 'type': 'Normal',
+ 'func': 'ClearDepth',
+ 'enum': 'GL_DEPTH_CLEAR_VALUE',
+ 'states': [
+ {'name': 'depth_clear', 'type': 'GLclampf', 'default': '1.0f'},
+ ],
+ },
+ 'ColorMask': {
+ 'type': 'Normal',
+ 'func': 'ColorMask',
+ 'enum': 'GL_COLOR_WRITEMASK',
+ 'states': [
+ {'name': 'color_mask_red', 'type': 'GLboolean', 'default': 'true'},
+ {'name': 'color_mask_green', 'type': 'GLboolean', 'default': 'true'},
+ {'name': 'color_mask_blue', 'type': 'GLboolean', 'default': 'true'},
+ {'name': 'color_mask_alpha', 'type': 'GLboolean', 'default': 'true'},
+ ],
+ 'state_flag': 'clear_state_dirty_',
+ },
+ 'ClearStencil': {
+ 'type': 'Normal',
+ 'func': 'ClearStencil',
+ 'enum': 'GL_STENCIL_CLEAR_VALUE',
+ 'states': [
+ {'name': 'stencil_clear', 'type': 'GLint', 'default': '0'},
+ ],
+ },
+ 'BlendColor': {
+ 'type': 'Normal',
+ 'func': 'BlendColor',
+ 'enum': 'GL_BLEND_COLOR',
+ 'states': [
+ {'name': 'blend_color_red', 'type': 'GLfloat', 'default': '0.0f'},
+ {'name': 'blend_color_green', 'type': 'GLfloat', 'default': '0.0f'},
+ {'name': 'blend_color_blue', 'type': 'GLfloat', 'default': '0.0f'},
+ {'name': 'blend_color_alpha', 'type': 'GLfloat', 'default': '0.0f'},
+ ],
+ },
+ 'BlendEquation': {
+ 'type': 'SrcDst',
+ 'func': 'BlendEquationSeparate',
+ 'states': [
+ {
+ 'name': 'blend_equation_rgb',
+ 'type': 'GLenum',
+ 'enum': 'GL_BLEND_EQUATION_RGB',
+ 'default': 'GL_FUNC_ADD',
+ },
+ {
+ 'name': 'blend_equation_alpha',
+ 'type': 'GLenum',
+ 'enum': 'GL_BLEND_EQUATION_ALPHA',
+ 'default': 'GL_FUNC_ADD',
+ },
+ ],
+ },
+ 'BlendFunc': {
+ 'type': 'SrcDst',
+ 'func': 'BlendFuncSeparate',
+ 'states': [
+ {
+ 'name': 'blend_source_rgb',
+ 'type': 'GLenum',
+ 'enum': 'GL_BLEND_SRC_RGB',
+ 'default': 'GL_ONE',
+ },
+ {
+ 'name': 'blend_dest_rgb',
+ 'type': 'GLenum',
+ 'enum': 'GL_BLEND_DST_RGB',
+ 'default': 'GL_ZERO',
+ },
+ {
+ 'name': 'blend_source_alpha',
+ 'type': 'GLenum',
+ 'enum': 'GL_BLEND_SRC_ALPHA',
+ 'default': 'GL_ONE',
+ },
+ {
+ 'name': 'blend_dest_alpha',
+ 'type': 'GLenum',
+ 'enum': 'GL_BLEND_DST_ALPHA',
+ 'default': 'GL_ZERO',
+ },
+ ],
+ },
+ 'PolygonOffset': {
+ 'type': 'Normal',
+ 'func': 'PolygonOffset',
+ 'states': [
+ {
+ 'name': 'polygon_offset_factor',
+ 'type': 'GLfloat',
+ 'enum': 'GL_POLYGON_OFFSET_FACTOR',
+ 'default': '0.0f',
+ },
+ {
+ 'name': 'polygon_offset_units',
+ 'type': 'GLfloat',
+ 'enum': 'GL_POLYGON_OFFSET_UNITS',
+ 'default': '0.0f',
+ },
+ ],
+ },
+ 'CullFace': {
+ 'type': 'Normal',
+ 'func': 'CullFace',
+ 'enum': 'GL_CULL_FACE_MODE',
+ 'states': [
+ {
+ 'name': 'cull_mode',
+ 'type': 'GLenum',
+ 'default': 'GL_BACK',
+ },
+ ],
+ },
+ 'FrontFace': {
+ 'type': 'Normal',
+ 'func': 'FrontFace',
+ 'enum': 'GL_FRONT_FACE',
+ 'states': [{'name': 'front_face', 'type': 'GLenum', 'default': 'GL_CCW'}],
+ },
+ 'DepthFunc': {
+ 'type': 'Normal',
+ 'func': 'DepthFunc',
+ 'enum': 'GL_DEPTH_FUNC',
+ 'states': [{'name': 'depth_func', 'type': 'GLenum', 'default': 'GL_LESS'}],
+ },
+ 'DepthRange': {
+ 'type': 'Normal',
+ 'func': 'DepthRange',
+ 'enum': 'GL_DEPTH_RANGE',
+ 'states': [
+ {'name': 'z_near', 'type': 'GLclampf', 'default': '0.0f'},
+ {'name': 'z_far', 'type': 'GLclampf', 'default': '1.0f'},
+ ],
+ },
+ 'SampleCoverage': {
+ 'type': 'Normal',
+ 'func': 'SampleCoverage',
+ 'states': [
+ {
+ 'name': 'sample_coverage_value',
+ 'type': 'GLclampf',
+ 'enum': 'GL_SAMPLE_COVERAGE_VALUE',
+ 'default': '0.0f',
+ },
+ {
+ 'name': 'sample_coverage_invert',
+ 'type': 'GLboolean',
+ 'enum': 'GL_SAMPLE_COVERAGE_INVERT',
+ 'default': 'false',
+ },
+ ],
+ },
+ 'StencilMask': {
+ 'type': 'FrontBack',
+ 'func': 'StencilMaskSeparate',
+ 'state_flag': 'clear_state_dirty_',
+ 'states': [
+ {
+ 'name': 'stencil_front_writemask',
+ 'type': 'GLuint',
+ 'enum': 'GL_STENCIL_WRITEMASK',
+ 'default': '0xFFFFFFFFU',
+ },
+ {
+ 'name': 'stencil_back_writemask',
+ 'type': 'GLuint',
+ 'enum': 'GL_STENCIL_BACK_WRITEMASK',
+ 'default': '0xFFFFFFFFU',
+ },
+ ],
+ },
+ 'StencilOp': {
+ 'type': 'FrontBack',
+ 'func': 'StencilOpSeparate',
+ 'states': [
+ {
+ 'name': 'stencil_front_fail_op',
+ 'type': 'GLenum',
+ 'enum': 'GL_STENCIL_FAIL',
+ 'default': 'GL_KEEP',
+ },
+ {
+ 'name': 'stencil_front_z_fail_op',
+ 'type': 'GLenum',
+ 'enum': 'GL_STENCIL_PASS_DEPTH_FAIL',
+ 'default': 'GL_KEEP',
+ },
+ {
+ 'name': 'stencil_front_z_pass_op',
+ 'type': 'GLenum',
+ 'enum': 'GL_STENCIL_PASS_DEPTH_PASS',
+ 'default': 'GL_KEEP',
+ },
+ {
+ 'name': 'stencil_back_fail_op',
+ 'type': 'GLenum',
+ 'enum': 'GL_STENCIL_BACK_FAIL',
+ 'default': 'GL_KEEP',
+ },
+ {
+ 'name': 'stencil_back_z_fail_op',
+ 'type': 'GLenum',
+ 'enum': 'GL_STENCIL_BACK_PASS_DEPTH_FAIL',
+ 'default': 'GL_KEEP',
+ },
+ {
+ 'name': 'stencil_back_z_pass_op',
+ 'type': 'GLenum',
+ 'enum': 'GL_STENCIL_BACK_PASS_DEPTH_PASS',
+ 'default': 'GL_KEEP',
+ },
+ ],
+ },
+ 'StencilFunc': {
+ 'type': 'FrontBack',
+ 'func': 'StencilFuncSeparate',
+ 'states': [
+ {
+ 'name': 'stencil_front_func',
+ 'type': 'GLenum',
+ 'enum': 'GL_STENCIL_FUNC',
+ 'default': 'GL_ALWAYS',
+ },
+ {
+ 'name': 'stencil_front_ref',
+ 'type': 'GLint',
+ 'enum': 'GL_STENCIL_REF',
+ 'default': '0',
+ },
+ {
+ 'name': 'stencil_front_mask',
+ 'type': 'GLuint',
+ 'enum': 'GL_STENCIL_VALUE_MASK',
+ 'default': '0xFFFFFFFFU',
+ },
+ {
+ 'name': 'stencil_back_func',
+ 'type': 'GLenum',
+ 'enum': 'GL_STENCIL_BACK_FUNC',
+ 'default': 'GL_ALWAYS',
+ },
+ {
+ 'name': 'stencil_back_ref',
+ 'type': 'GLint',
+ 'enum': 'GL_STENCIL_BACK_REF',
+ 'default': '0',
+ },
+ {
+ 'name': 'stencil_back_mask',
+ 'type': 'GLuint',
+ 'enum': 'GL_STENCIL_BACK_VALUE_MASK',
+ 'default': '0xFFFFFFFFU',
+ },
+ ],
+ },
+ # TODO: Consider implemenenting these states
+ # GL_GENERATE_MIPMAP_HINT
+ # GL_ACTIVE_TEXTURE,
+ # GL_PACK_ALIGNMENT,
+ # GL_UNPACK_ALIGNMENT
+ 'LineWidth': {
+ 'type': 'Normal',
+ 'func': 'LineWidth',
+ 'enum': 'GL_LINE_WIDTH',
+ 'states': [{'name': 'line_width', 'type': 'GLfloat', 'default': '1.0f'}],
+ },
+ 'DepthMask': {
+ 'type': 'Normal',
+ 'func': 'DepthMask',
+ 'enum': 'GL_DEPTH_WRITEMASK',
+ 'states': [
+ {'name': 'depth_mask', 'type': 'GLboolean', 'default': 'true'},
+ ],
+ 'state_flag': 'clear_state_dirty_',
+ },
+ 'Scissor': {
+ 'type': 'Normal',
+ 'func': 'Scissor',
+ 'enum': 'GL_SCISSOR_BOX',
+ 'states': [
+ # NOTE: These defaults reset at GLES2DecoderImpl::Initialization.
+ {
+ 'name': 'scissor_x',
+ 'type': 'GLfloat',
+ 'default': '0.0f',
+ 'expected': 'kViewportX',
+ },
+ {
+ 'name': 'scissor_y',
+ 'type': 'GLfloat',
+ 'default': '0.0f',
+ 'expected': 'kViewportY',
+ },
+ {
+ 'name': 'scissor_width',
+ 'type': 'GLfloat',
+ 'default': '1.0f',
+ 'expected': 'kViewportWidth',
+ },
+ {
+ 'name': 'scissor_height',
+ 'type': 'GLfloat',
+ 'default': '1.0f',
+ 'expected': 'kViewportHeight',
+ },
+ ],
+ },
+ 'Viewport': {
+ 'type': 'Normal',
+ 'func': 'Viewport',
+ 'enum': 'GL_VIEWPORT',
+ 'states': [
+ # NOTE: These defaults reset at GLES2DecoderImpl::Initialization.
+ {
+ 'name': 'viewport_x',
+ 'type': 'GLfloat',
+ 'default': '0.0f',
+ 'expected': 'kViewportX',
+ },
+ {
+ 'name': 'viewport_y',
+ 'type': 'GLfloat',
+ 'default': '0.0f',
+ 'expected': 'kViewportY',
+ },
+ {
+ 'name': 'viewport_width',
+ 'type': 'GLfloat',
+ 'default': '1.0f',
+ 'expected': 'kViewportWidth',
+ },
+ {
+ 'name': 'viewport_height',
+ 'type': 'GLfloat',
+ 'default': '1.0f',
+ 'expected': 'kViewportHeight',
+ },
+ ],
+ },
+}
+
# This is a list of enum names and their valid values. It is used to map
# GLenum arguments to a specific set of valid values.
_ENUM_LISTS = {
@@ -118,41 +489,23 @@ _ENUM_LISTS = {
'GLState': {
'type': 'GLenum',
'valid': [
+ # NOTE: State an Capability entries added later.
'GL_ACTIVE_TEXTURE',
'GL_ALIASED_LINE_WIDTH_RANGE',
'GL_ALIASED_POINT_SIZE_RANGE',
'GL_ALPHA_BITS',
'GL_ARRAY_BUFFER_BINDING',
- 'GL_BLEND',
- 'GL_BLEND_COLOR',
- 'GL_BLEND_DST_ALPHA',
- 'GL_BLEND_DST_RGB',
- 'GL_BLEND_EQUATION_ALPHA',
- 'GL_BLEND_EQUATION_RGB',
- 'GL_BLEND_SRC_ALPHA',
- 'GL_BLEND_SRC_RGB',
'GL_BLUE_BITS',
- 'GL_COLOR_CLEAR_VALUE',
- 'GL_COLOR_WRITEMASK',
'GL_COMPRESSED_TEXTURE_FORMATS',
- 'GL_CULL_FACE',
- 'GL_CULL_FACE_MODE',
'GL_CURRENT_PROGRAM',
'GL_DEPTH_BITS',
- 'GL_DEPTH_CLEAR_VALUE',
- 'GL_DEPTH_FUNC',
'GL_DEPTH_RANGE',
- 'GL_DEPTH_TEST',
- 'GL_DEPTH_WRITEMASK',
- 'GL_DITHER',
'GL_ELEMENT_ARRAY_BUFFER_BINDING',
'GL_FRAMEBUFFER_BINDING',
- 'GL_FRONT_FACE',
'GL_GENERATE_MIPMAP_HINT',
'GL_GREEN_BITS',
'GL_IMPLEMENTATION_COLOR_READ_FORMAT',
'GL_IMPLEMENTATION_COLOR_READ_TYPE',
- 'GL_LINE_WIDTH',
'GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS',
'GL_MAX_CUBE_MAP_TEXTURE_SIZE',
'GL_MAX_FRAGMENT_UNIFORM_VECTORS',
@@ -167,9 +520,6 @@ _ENUM_LISTS = {
'GL_NUM_COMPRESSED_TEXTURE_FORMATS',
'GL_NUM_SHADER_BINARY_FORMATS',
'GL_PACK_ALIGNMENT',
- 'GL_POLYGON_OFFSET_FACTOR',
- 'GL_POLYGON_OFFSET_FILL',
- 'GL_POLYGON_OFFSET_UNITS',
'GL_RED_BITS',
'GL_RENDERBUFFER_BINDING',
'GL_SAMPLE_BUFFERS',
@@ -177,27 +527,10 @@ _ENUM_LISTS = {
'GL_SAMPLE_COVERAGE_VALUE',
'GL_SAMPLES',
'GL_SCISSOR_BOX',
- 'GL_SCISSOR_TEST',
'GL_SHADER_BINARY_FORMATS',
'GL_SHADER_COMPILER',
- 'GL_STENCIL_BACK_FAIL',
- 'GL_STENCIL_BACK_FUNC',
- 'GL_STENCIL_BACK_PASS_DEPTH_FAIL',
- 'GL_STENCIL_BACK_PASS_DEPTH_PASS',
- 'GL_STENCIL_BACK_REF',
- 'GL_STENCIL_BACK_VALUE_MASK',
- 'GL_STENCIL_BACK_WRITEMASK',
- 'GL_STENCIL_BITS',
- 'GL_STENCIL_CLEAR_VALUE',
- 'GL_STENCIL_FAIL',
- 'GL_STENCIL_FUNC',
- 'GL_STENCIL_PASS_DEPTH_FAIL',
- 'GL_STENCIL_PASS_DEPTH_PASS',
- 'GL_STENCIL_REF',
- 'GL_STENCIL_TEST',
- 'GL_STENCIL_VALUE_MASK',
- 'GL_STENCIL_WRITEMASK',
'GL_SUBPIXEL_BITS',
+ 'GL_STENCIL_BITS',
'GL_TEXTURE_BINDING_2D',
'GL_TEXTURE_BINDING_CUBE_MAP',
'GL_UNPACK_ALIGNMENT',
@@ -337,17 +670,7 @@ _ENUM_LISTS = {
},
'Capability': {
'type': 'GLenum',
- 'valid': [
- 'GL_DITHER', # 1st one is a non-cached value so autogen unit tests work.
- 'GL_BLEND',
- 'GL_CULL_FACE',
- 'GL_DEPTH_TEST',
- 'GL_POLYGON_OFFSET_FILL',
- 'GL_SAMPLE_ALPHA_TO_COVERAGE',
- 'GL_SAMPLE_COVERAGE',
- 'GL_SCISSOR_TEST',
- 'GL_STENCIL_TEST',
- ],
+ 'valid': ["GL_%s" % cap['name'].upper() for cap in _CAPABILITY_FLAGS],
'invalid': [
'GL_CLIP_PLANE0',
'GL_POINT_SPRITE',
@@ -881,30 +1204,17 @@ _FUNCTION_INFO = {
},
'ClearColor': {
'type': 'StateSet',
- 'states': [
- {'name': 'color_clear_red'},
- {'name': 'color_clear_green'},
- {'name': 'color_clear_blue'},
- {'name': 'color_clear_alpha'},
- ],
+ 'state': 'ClearColor',
},
'ClearDepthf': {
'type': 'StateSet',
- 'states': [
- {'name': 'depth_clear'},
- ],
+ 'state': 'ClearDepthf',
'decoder_func': 'glClearDepth',
'gl_test_func': 'glClearDepth',
},
'ColorMask': {
'type': 'StateSet',
- 'states': [
- {'name': 'color_mask_red'},
- {'name': 'color_mask_green'},
- {'name': 'color_mask_blue'},
- {'name': 'color_mask_alpha'},
- ],
- 'state_flag': 'clear_state_dirty_',
+ 'state': 'ColorMask',
'no_gl': True,
'expectation': False,
},
@@ -919,9 +1229,7 @@ _FUNCTION_INFO = {
},
'ClearStencil': {
'type': 'StateSet',
- 'states': [
- {'name': 'stencil_clear'},
- ],
+ 'state': 'ClearStencil',
},
'EnableFeatureCHROMIUM': {
'type': 'Custom',
@@ -962,47 +1270,49 @@ _FUNCTION_INFO = {
},
'BlendColor': {
'type': 'StateSet',
- 'states': [
- {'name': 'blend_color_red'},
- {'name': 'blend_color_green'},
- {'name': 'blend_color_blue'},
- {'name': 'blend_color_alpha'},
- ],
+ 'state': 'BlendColor',
+ },
+ 'BlendEquation': {
+ 'type': 'StateSetRGBAlpha',
+ 'state': 'BlendEquation',
},
- 'BlendEquation': {'decoder_func': 'DoBlendEquation'},
'BlendEquationSeparate': {
'type': 'StateSet',
- 'states': [
- {'name': 'blend_equation_rgb'},
- {'name': 'blend_equation_alpha'},
- ],
+ 'state': 'BlendEquation',
+ },
+ 'BlendFunc': {
+ 'type': 'StateSetRGBAlpha',
+ 'state': 'BlendFunc',
},
- 'BlendFunc': {'decoder_func': 'DoBlendFunc'},
'BlendFuncSeparate': {
'type': 'StateSet',
- 'states': [
- {'name': 'blend_source_rgb'},
- {'name': 'blend_dest_rgb'},
- {'name': 'blend_source_alpha'},
- {'name': 'blend_dest_alpha'},
- ],
+ 'state': 'BlendFunc',
},
'SampleCoverage': {'decoder_func': 'DoSampleCoverage'},
- 'StencilFunc': {'decoder_func': 'DoStencilFunc'},
- 'StencilFuncSeparate': {'decoder_func': 'DoStencilFuncSeparate'},
- 'StencilOp': {'decoder_func': 'DoStencilOp'},
- 'StencilOpSeparate': {'decoder_func': 'DoStencilOpSeparate'},
+ 'StencilFunc': {
+ 'type': 'StencilFrontBack',
+ 'state': 'StencilFunc',
+ },
+ 'StencilFuncSeparate': {
+ 'type': 'StencilFrontBack',
+ 'state': 'StencilFunc',
+ },
+ 'StencilOp': {
+ 'type': 'StateSetFrontBack',
+ 'state': 'StencilOp',
+ },
+ 'StencilOpSeparate': {
+ 'type': 'StateSetFrontBackSeparate',
+ 'state': 'StencilOp',
+ },
'Hint': {'decoder_func': 'DoHint'},
- 'CullFace': {'type': 'StateSet', 'states': [{'name': 'cull_mode'}]},
- 'FrontFace': {'type': 'StateSet', 'states': [{'name': 'front_face'}]},
- 'DepthFunc': {'type': 'StateSet', 'states': [{'name': 'depth_func'}]},
- 'LineWidth': {'type': 'StateSet', 'states': [{'name': 'line_width'}]},
+ 'CullFace': {'type': 'StateSet', 'state': 'CullFace'},
+ 'FrontFace': {'type': 'StateSet', 'state': 'FrontFace'},
+ 'DepthFunc': {'type': 'StateSet', 'state': 'DepthFunc'},
+ 'LineWidth': {'type': 'StateSet', 'state': 'LineWidth'},
'PolygonOffset': {
'type': 'StateSet',
- 'states': [
- {'name': 'polygon_offset_factor'},
- {'name': 'polygon_offset_units'},
- ],
+ 'state': 'PolygonOffset',
},
'DeleteBuffers': {
'type': 'DELn',
@@ -1044,10 +1354,7 @@ _FUNCTION_INFO = {
},
'DepthMask': {
'type': 'StateSet',
- 'states': [
- {'name': 'depth_mask'},
- ],
- 'state_flag': 'clear_state_dirty_',
+ 'state': 'DepthMask',
'no_gl': True,
'expectation': False,
},
@@ -1480,9 +1787,16 @@ _FUNCTION_INFO = {
'cmd_args':
'GLuint shader, const char* data',
},
- 'StencilMask': {'decoder_func': 'DoStencilMask', 'expectation': False},
+ 'StencilMask': {
+ 'type': 'StateSetFrontBack',
+ 'state': 'StencilMask',
+ 'no_gl': True,
+ 'expectation': False,
+ },
'StencilMaskSeparate': {
- 'decoder_func': 'DoStencilMaskSeparate',
+ 'type': 'StateSetFrontBackSeparate',
+ 'state': 'StencilMask',
+ 'no_gl': True,
'expectation': False,
},
'SwapBuffers': {
@@ -1863,6 +2177,12 @@ _FUNCTION_INFO = {
}
+def Grouper(n, iterable, fillvalue=None):
+ """Collect data into fixed-length chunks or blocks"""
+ args = [iter(iterable)] * n
+ return itertools.izip_longest(fillvalue=fillvalue, *args)
+
+
def SplitWords(input_string):
"""Transforms a input_string into a list of lower-case components.
@@ -2135,19 +2455,15 @@ COMPILE_ASSERT(offsetof(%(cmd_name)s::Result, %(field_name)s) == %(offset)d,
file.Write(" void* next_cmd = cmd.Set(\n")
file.Write(" &cmd")
args = func.GetCmdArgs()
- value = 11
- for arg in args:
- file.Write(",\n static_cast<%s>(%d)" % (arg.type, value))
- value += 1
+ for value, arg in enumerate(args):
+ file.Write(",\n static_cast<%s>(%d)" % (arg.type, value + 11))
file.Write(");\n")
- value = 11
file.Write(" EXPECT_EQ(static_cast<uint32>(%s::kCmdId),\n" % func.name)
file.Write(" cmd.header.command);\n")
func.type_handler.WriteCmdSizeTest(func, file)
- for arg in args:
+ for value, arg in enumerate(args):
file.Write(" EXPECT_EQ(static_cast<%s>(%d), cmd.%s);\n" %
- (arg.type, value, arg.name))
- value += 1
+ (arg.type, value + 11, arg.name))
file.Write(" CheckBytesWrittenMatchesExpectedSize(\n")
file.Write(" next_cmd, sizeof(cmd));\n")
file.Write("}\n")
@@ -2241,15 +2557,11 @@ COMPILE_ASSERT(offsetof(%(cmd_name)s::Result, %(field_name)s) == %(offset)d,
test = self._remove_expected_call_re.sub('', test)
name = func.name
arg_strings = []
- count = 0
- for arg in func.GetOriginalArgs():
+ for count, arg in enumerate(func.GetOriginalArgs()):
arg_strings.append(arg.GetValidArg(func, count, 0))
- count += 1
gl_arg_strings = []
- count = 0
- for arg in func.GetOriginalArgs():
+ for count, arg in enumerate(func.GetOriginalArgs()):
gl_arg_strings.append(arg.GetValidGLArg(func, count, 0))
- count += 1
gl_func_name = func.GetGLTestFunctionName()
vars = {
'test_name': 'GLES2DecoderTest%d' % file.file_num,
@@ -2263,27 +2575,22 @@ COMPILE_ASSERT(offsetof(%(cmd_name)s::Result, %(field_name)s) == %(offset)d,
def WriteInvalidUnitTest(self, func, file, test, extra = {}):
"""Writes a invalid unit test."""
- arg_index = 0
- for arg in func.GetOriginalArgs():
+ for arg_index, arg in enumerate(func.GetOriginalArgs()):
num_invalid_values = arg.GetNumInvalidValues(func)
for value_index in range(0, num_invalid_values):
arg_strings = []
parse_result = "kNoError"
gl_error = None
- count = 0
- for arg in func.GetOriginalArgs():
+ for count, arg in enumerate(func.GetOriginalArgs()):
if count == arg_index:
(arg_string, parse_result, gl_error) = arg.GetInvalidArg(
count, value_index)
else:
arg_string = arg.GetValidArg(func, count, 0)
arg_strings.append(arg_string)
- count += 1
gl_arg_strings = []
- count = 0
for arg in func.GetOriginalArgs():
gl_arg_strings.append("_")
- count += 1
gl_func_name = func.GetGLTestFunctionName()
gl_error_test = ''
if not gl_error == None:
@@ -2303,7 +2610,6 @@ COMPILE_ASSERT(offsetof(%(cmd_name)s::Result, %(field_name)s) == %(offset)d,
}
vars.update(extra)
file.Write(test % vars)
- arg_index += 1
def WriteServiceUnitTest(self, func, file):
"""Writes the service unit test for a command."""
@@ -2449,15 +2755,12 @@ TEST_F(GLES2ImplementationTest, %(name)s) {
}
"""
cmd_arg_strings = []
- count = 0
- for arg in func.GetCmdArgs():
+ for count, arg in enumerate(func.GetCmdArgs()):
cmd_arg_strings.append(arg.GetValidClientSideCmdArg(func, count, 0))
count += 1
gl_arg_strings = []
- count = 0
- for arg in func.GetOriginalArgs():
+ for count, arg in enumerate(func.GetOriginalArgs()):
gl_arg_strings.append(arg.GetValidClientSideArg(func, count, 0))
- count += 1
file.Write(code % {
'name': func.name,
'args': ", ".join(gl_arg_strings),
@@ -2539,20 +2842,92 @@ class StateSetHandler(TypeHandler):
def WriteHandlerImplementation(self, func, file):
"""Overrriden from TypeHandler."""
- states = func.GetInfo('states')
+ state_name = func.GetInfo('state')
+ state = _STATES[state_name]
+ states = state['states']
args = func.GetOriginalArgs()
- ndx = 0
- for state in states:
+ for ndx,state in enumerate(states):
file.Write(" state_.%s = %s;\n" % (state['name'], args[ndx].name))
- ndx += 1
- state_flag = func.GetInfo('state_flag')
- if state_flag:
- file.Write(" %s = true;\n" % state_flag)
+ if 'state_flag' in state:
+ file.Write(" %s = true;\n" % state['state_flag'])
if not func.GetInfo("no_gl"):
file.Write(" %s(%s);\n" %
(func.GetGLFunctionName(), func.MakeOriginalArgString("")))
+class StateSetRGBAlphaHandler(TypeHandler):
+ """Handler for commands that simply set state that have rgb/alpha."""
+
+ def __init__(self):
+ TypeHandler.__init__(self)
+
+ def WriteHandlerImplementation(self, func, file):
+ """Overrriden from TypeHandler."""
+ state_name = func.GetInfo('state')
+ state = _STATES[state_name]
+ states = state['states']
+ args = func.GetOriginalArgs()
+ num_args = len(args)
+ for ndx, item in enumerate(states):
+ file.Write(" state_.%s = %s;\n" %
+ (item['name'], args[ndx % num_args].name))
+ if 'state_flag' in state:
+ file.Write(" %s = true;\n" % state['state_flag'])
+ if not func.GetInfo("no_gl"):
+ file.Write(" %s(%s);\n" %
+ (func.GetGLFunctionName(), func.MakeOriginalArgString("")))
+
+
+class StateSetFrontBackSeparateHandler(TypeHandler):
+ """Handler for commands that simply set state that have front/back."""
+
+ def __init__(self):
+ TypeHandler.__init__(self)
+
+ def WriteHandlerImplementation(self, func, file):
+ """Overrriden from TypeHandler."""
+ state_name = func.GetInfo('state')
+ state = _STATES[state_name]
+ states = state['states']
+ args = func.GetOriginalArgs()
+ face = args[0].name
+ num_args = len(args)
+ for group_ndx, group in enumerate(Grouper(num_args - 1, states)):
+ file.Write(" if (%s == %s || %s == GL_FRONT_AND_BACK) {\n" %
+ (face, ('GL_FRONT', 'GL_BACK')[group_ndx], face))
+ for ndx, item in enumerate(group):
+ file.Write(" state_.%s = %s;\n" % (item['name'], args[ndx + 1].name))
+ file.Write(" }\n")
+ if 'state_flag' in state:
+ file.Write(" %s = true;\n" % state['state_flag'])
+ if not func.GetInfo("no_gl"):
+ file.Write(" %s(%s);\n" %
+ (func.GetGLFunctionName(), func.MakeOriginalArgString("")))
+
+
+class StateSetFrontBackHandler(TypeHandler):
+ """Handler for commands that simply set state that set both front/back."""
+
+ def __init__(self):
+ TypeHandler.__init__(self)
+
+ def WriteHandlerImplementation(self, func, file):
+ """Overrriden from TypeHandler."""
+ state_name = func.GetInfo('state')
+ state = _STATES[state_name]
+ states = state['states']
+ args = func.GetOriginalArgs()
+ face = args[0].name
+ num_args = len(args)
+ for group_ndx, group in enumerate(Grouper(num_args, states)):
+ for ndx, item in enumerate(group):
+ file.Write(" state_.%s = %s;\n" % (item['name'], args[ndx].name))
+ if 'state_flag' in state:
+ file.Write(" %s = true;\n" % state['state_flag'])
+ if not func.GetInfo("no_gl"):
+ file.Write(" %s(%s);\n" %
+ (func.GetGLFunctionName(), func.MakeOriginalArgString("")))
+
class CustomHandler(TypeHandler):
"""Handler for commands that are auto-generated but require minor tweaks."""
@@ -3725,16 +4100,12 @@ TEST_F(GLES2ImplementationTest, %(name)s) {
}
"""
cmd_arg_strings = []
- count = 0
- for arg in func.GetCmdArgs()[0:-2]:
+ for count, arg in enumerate(func.GetCmdArgs()[0:-2]):
cmd_arg_strings.append(arg.GetValidClientSideCmdArg(func, count, 0))
- count += 1
cmd_arg_strings[0] = '123'
gl_arg_strings = []
- count = 0
- for arg in func.GetOriginalArgs()[0:-1]:
+ for count, arg in enumerate(func.GetOriginalArgs()[0:-1]):
gl_arg_strings.append(arg.GetValidClientSideArg(func, count, 0))
- count += 1
gl_arg_strings[0] = '123'
file.Write(code % {
'name': func.name,
@@ -3766,13 +4137,11 @@ TEST_F(%(test_name)s, %(name)sValidArgs) {
"""
gl_arg_strings = []
valid_pname = ''
- count = 0
- for arg in func.GetOriginalArgs()[:-1]:
+ for count, arg in enumerate(func.GetOriginalArgs()[:-1]):
arg_value = arg.GetValidGLArg(func, count, 0)
gl_arg_strings.append(arg_value)
if arg.name == 'pname':
valid_pname = arg_value
- count += 1
if func.GetInfo('gl_test_func') == 'glGetIntegerv':
gl_arg_strings.append("_")
else:
@@ -3855,11 +4224,9 @@ TEST_F(%(test_name)s, %(name)sValidArgs) {
"""
gl_arg_strings = []
gl_any_strings = []
- count = 0
- for arg in func.GetOriginalArgs()[0:-1]:
+ for count, arg in enumerate(func.GetOriginalArgs()[0:-1]):
gl_arg_strings.append(arg.GetValidGLArg(func, count, 0))
gl_any_strings.append("_")
- count += 1
extra = {
'data_type': func.GetInfo('data_type'),
'data_count': func.GetInfo('count'),
@@ -3933,15 +4300,11 @@ TEST_F(GLES2ImplementationTest, %(name)s) {
}
"""
cmd_arg_strings = []
- count = 0
- for arg in func.GetCmdArgs()[0:-2]:
+ for count, arg in enumerate(func.GetCmdArgs()[0:-2]):
cmd_arg_strings.append(arg.GetValidClientSideCmdArg(func, count, 0))
- count += 1
gl_arg_strings = []
- count = 0
- for arg in func.GetOriginalArgs()[0:-1]:
+ for count, arg in enumerate(func.GetOriginalArgs()[0:-1]):
gl_arg_strings.append(arg.GetValidClientSideArg(func, count, 0))
- count += 1
file.Write(code % {
'name': func.name,
'type': func.GetInfo('data_type'),
@@ -4034,22 +4397,18 @@ TEST_F(GLES2ImplementationTest, %(name)s) {
file.Write(" void* next_cmd = cmd.Set(\n")
file.Write(" &cmd")
args = func.GetCmdArgs()
- value = 11
- for arg in args:
- file.Write(",\n static_cast<%s>(%d)" % (arg.type, value))
- value += 1
+ for value, arg in enumerate(args):
+ file.Write(",\n static_cast<%s>(%d)" % (arg.type, value + 11))
file.Write(",\n data);\n")
args = func.GetCmdArgs()
- value = 11
file.Write(" EXPECT_EQ(static_cast<uint32>(%s::kCmdId),\n" % func.name)
file.Write(" cmd.header.command);\n")
file.Write(" EXPECT_EQ(sizeof(cmd) +\n")
file.Write(" RoundSizeToMultipleOfEntries(sizeof(data)),\n")
file.Write(" cmd.header.size * 4u);\n")
- for arg in args:
+ for value, arg in enumerate(args):
file.Write(" EXPECT_EQ(static_cast<%s>(%d), cmd.%s);\n" %
- (arg.type, value, arg.name))
- value += 1
+ (arg.type, value + 11, arg.name))
file.Write(" CheckBytesWrittenMatchesExpectedSize(\n")
file.Write(" next_cmd, sizeof(cmd) +\n")
file.Write(" RoundSizeToMultipleOfEntries(sizeof(data)));\n")
@@ -4080,8 +4439,7 @@ TEST_F(%(test_name)s, %(name)sValidArgsCountTooLarge) {
"""
gl_arg_strings = []
arg_strings = []
- count = 0
- for arg in func.GetOriginalArgs():
+ for count, arg in enumerate(func.GetOriginalArgs()):
# hardcoded to match unit tests.
if count == 0:
# the location of the second element of the 2nd uniform.
@@ -4096,7 +4454,6 @@ TEST_F(%(test_name)s, %(name)sValidArgsCountTooLarge) {
else:
gl_arg_strings.append(arg.GetValidGLArg(func, count, 0))
arg_strings.append(arg.GetValidArg(func, count, 0))
- count += 1
extra = {
'gl_args': ", ".join(gl_arg_strings),
'args': ", ".join(arg_strings),
@@ -4123,12 +4480,10 @@ TEST_F(%(test_name)s, %(name)sValidArgs) {
gl_arg_strings = []
gl_any_strings = []
arg_strings = []
- count = 0
- for arg in func.GetOriginalArgs()[0:-1]:
+ for count, arg in enumerate(func.GetOriginalArgs()[0:-1]):
gl_arg_strings.append(arg.GetValidGLArg(func, count, 0))
gl_any_strings.append("_")
arg_strings.append(arg.GetValidArg(func, count, 0))
- count += 1
extra = {
'data_type': func.GetInfo('data_type'),
'data_count': func.GetInfo('count'),
@@ -4210,15 +4565,11 @@ TEST_F(GLES2ImplementationTest, %(name)s) {
}
"""
cmd_arg_strings = []
- count = 0
- for arg in func.GetCmdArgs()[0:-2]:
+ for count, arg in enumerate(func.GetCmdArgs()[0:-2]):
cmd_arg_strings.append(arg.GetValidClientSideCmdArg(func, count, 0))
- count += 1
gl_arg_strings = []
- count = 0
- for arg in func.GetOriginalArgs()[0:-1]:
+ for count, arg in enumerate(func.GetOriginalArgs()[0:-1]):
gl_arg_strings.append(arg.GetValidClientSideArg(func, count, 0))
- count += 1
file.Write(code % {
'name': func.name,
'type': func.GetInfo('data_type'),
@@ -4315,20 +4666,16 @@ TEST_F(GLES2ImplementationTest, %(name)s) {
file.Write(" void* next_cmd = cmd.Set(\n")
file.Write(" &cmd")
args = func.GetCmdArgs()
- value = 1
- for arg in args:
- file.Write(",\n static_cast<%s>(%d)" % (arg.type, value))
- value += 1
+ for value, arg in enumerate(args):
+ file.Write(",\n static_cast<%s>(%d)" % (arg.type, value + 1))
file.Write(",\n data);\n")
args = func.GetCmdArgs()
- value = 1
file.Write(" EXPECT_EQ(static_cast<uint32>(%s::kCmdId),\n" % func.name)
file.Write(" cmd.header.command);\n")
file.Write(" EXPECT_EQ(kExpectedCmdSize, cmd.header.size * 4u);\n")
- for arg in args:
+ for value, arg in enumerate(args):
file.Write(" EXPECT_EQ(static_cast<%s>(%d), cmd.%s);\n" %
- (arg.type, value, arg.name))
- value += 1
+ (arg.type, value + 1, arg.name))
file.Write(" CheckBytesWrittenMatchesExpectedSize(\n")
file.Write(" next_cmd, sizeof(cmd) +\n")
file.Write(" RoundSizeToMultipleOfEntries(sizeof(data)));\n")
@@ -4476,15 +4823,11 @@ class GLcharHandler(CustomHandler):
init_code = []
check_code = []
all_but_last_arg = func.GetCmdArgs()[:-1]
- value = 11
- for arg in all_but_last_arg:
- init_code.append(" static_cast<%s>(%d)," % (arg.type, value))
- value += 1
- value = 11
- for arg in all_but_last_arg:
+ for value, arg in enumerate(all_but_last_arg):
+ init_code.append(" static_cast<%s>(%d)," % (arg.type, value + 11))
+ for value, arg in enumerate(all_but_last_arg):
check_code.append(" EXPECT_EQ(static_cast<%s>(%d), cmd.%s);" %
- (arg.type, value, arg.name))
- value += 1
+ (arg.type, value + 11, arg.name))
code = """
TEST_F(GLES2FormatTest, %(func_name)s) {
%(func_name)s& cmd = *GetBufferAs<%(func_name)s>();
@@ -5941,6 +6284,9 @@ class GLGenerator(object):
'PUTn': PUTnHandler(),
'PUTXn': PUTXnHandler(),
'StateSet': StateSetHandler(),
+ 'StateSetRGBAlpha': StateSetRGBAlphaHandler(),
+ 'StateSetFrontBack': StateSetFrontBackHandler(),
+ 'StateSetFrontBackSeparate': StateSetFrontBackSeparateHandler(),
'STRn': STRnHandler(),
'Todo': TodoHandler(),
}
@@ -6138,6 +6484,78 @@ class GLGenerator(object):
file.Close()
+ def WriteContextStateHeader(self, filename):
+ """Writes the context state header."""
+ file = CHeaderWriter(
+ filename,
+ "// It is included by context_state.h\n")
+ file.Write("struct EnableFlags {\n")
+ file.Write(" EnableFlags();\n")
+ for capability in _CAPABILITY_FLAGS:
+ file.Write(" bool %s;\n" % capability['name'])
+ file.Write("};\n\n")
+
+ for state_name in sorted(_STATES.keys()):
+ state = _STATES[state_name]
+ for item in state['states']:
+ file.Write("%s %s;\n" % (item['type'], item['name']))
+ file.Write("\n")
+
+ file.Close()
+
+ def WriteContextStateImpl(self, filename):
+ """Writes the context state implementation."""
+ file = CHeaderWriter(
+ filename,
+ "// It is included by context_state.cc\n")
+ code = []
+ for capability in _CAPABILITY_FLAGS:
+ code.append("%s(%s)" %
+ (capability['name'],
+ ('false', 'true')['default' in capability]))
+ file.Write("ContextState::EnableFlags::EnableFlags()\n : %s {\n}\n" %
+ ",\n ".join(code))
+ file.Write("\n")
+
+ file.Write("void ContextState::Initialize() {\n")
+ for state_name in sorted(_STATES.keys()):
+ state = _STATES[state_name]
+ for item in state['states']:
+ file.Write(" %s = %s;\n" % (item['name'], item['default']))
+ file.Write("}\n")
+
+ file.Write("""
+void ContextState::InitCapabilities() {
+""")
+ for capability in _CAPABILITY_FLAGS:
+ file.Write(" EnableDisable(GL_%s, enable_flags.%s);\n" %
+ (capability['name'].upper(), capability['name']))
+ file.Write("""}
+
+void ContextState::InitState() {
+""")
+
+ # We need to sort the keys so the expectations match
+ for state_name in sorted(_STATES.keys()):
+ state = _STATES[state_name]
+ if state['type'] == 'FrontBack':
+ num_states = len(state['states'])
+ for ndx, group in enumerate(Grouper(num_states / 2, state['states'])):
+ args = []
+ for item in group:
+ args.append('%s' % item['name'])
+ file.Write(
+ " gl%s(%s, %s);\n" %
+ (state['func'], ('GL_FRONT', 'GL_BACK')[ndx], ", ".join(args)))
+ else:
+ args = []
+ for item in state['states']:
+ args.append('%s' % item['name'])
+ file.Write(" gl%s(%s);\n" % (state['func'], ", ".join(args)))
+ file.Write("}\n")
+
+ file.Close()
+
def WriteServiceImplementation(self, filename):
"""Writes the service decorder implementation."""
file = CHeaderWriter(
@@ -6150,6 +6568,77 @@ class GLGenerator(object):
#if gen_cmd == True or gen_cmd == None:
func.WriteServiceImplementation(file)
+ file.Write("""
+bool GLES2DecoderImpl::SetCapabilityState(GLenum cap, bool enabled) {
+ switch (cap) {
+""")
+ for capability in _CAPABILITY_FLAGS:
+ file.Write(" case GL_%s:\n" % capability['name'].upper())
+ if 'state_flag' in capability:
+ file.Write(""" if (state_.enable_flags.%(name)s != enabled) {
+ state_.enable_flags.%(name)s = enabled;
+ %(state_flag)s = true;
+ }
+ return false;
+""" % capability)
+ else:
+ file.Write(""" state_.enable_flags.%(name)s = enabled;
+ return true;
+""" % capability)
+ file.Write(""" default:
+ NOTREACHED();
+ return false;
+ }
+}
+
+bool GLES2DecoderImpl::DoIsEnabled(GLenum cap) {
+ switch (cap) {
+""")
+ for capability in _CAPABILITY_FLAGS:
+ file.Write(" case GL_%s:\n" % capability['name'].upper())
+ file.Write(" return state_.enable_flags.%s;\n" %
+ capability['name'])
+ file.Write(""" default:
+ NOTREACHED();
+ return false;
+ }
+}
+
+bool GLES2DecoderImpl::GetState(
+ GLenum pname, GLint* params, GLsizei* num_written) {
+ switch (pname) {
+""")
+ for state_name in _STATES.keys():
+ state = _STATES[state_name]
+ if 'enum' in state:
+ file.Write(" case %s:\n" % state['enum'])
+ file.Write(" *num_written = %d;\n" % len(state['states']))
+ file.Write(" if (params) {\n")
+ for ndx,item in enumerate(state['states']):
+ file.Write(" params[%d] = state_.%s;\n" % (ndx, item['name']))
+ file.Write(" }\n")
+ file.Write(" return true;\n")
+ else:
+ for item in state['states']:
+ file.Write(" case %s:\n" % item['enum'])
+ file.Write(" *num_written = 1;\n")
+ file.Write(" if (params) {\n")
+ file.Write(" params[0] = state_.%s;\n" % item['name'])
+ file.Write(" }\n")
+ file.Write(" return true;\n")
+ for capability in _CAPABILITY_FLAGS:
+ file.Write(" case GL_%s:\n" % capability['name'].upper())
+ file.Write(" *num_written = 1;\n")
+ file.Write(" if (params) {\n")
+ file.Write(" params[0] = state_.enable_flags.%s;\n" %
+ capability['name'])
+ file.Write(" }\n")
+ file.Write(" return true;\n")
+ file.Write(""" default:
+ return false;
+ }
+}
+""")
file.Close()
def WriteServiceUnitTests(self, filename):
@@ -6178,6 +6667,52 @@ class GLGenerator(object):
func.WriteServiceUnitTest(file)
file.Close()
+ file = CHeaderWriter(
+ filename % 0,
+ "// It is included by gles2_cmd_decoder_unittest_base.cc\n")
+ file.Write(
+"""void GLES2DecoderTestBase::SetupInitCapabilitiesExpectations() {
+""")
+ for capability in _CAPABILITY_FLAGS:
+ file.Write(" ExpectEnableDisable(GL_%s, %s);\n" %
+ (capability['name'].upper(),
+ ('false', 'true')['default' in capability]))
+ file.Write("""}
+
+void GLES2DecoderTestBase::SetupInitStateExpectations() {
+""")
+
+ # We need to sort the keys so the expectations match
+ for state_name in sorted(_STATES.keys()):
+ state = _STATES[state_name]
+ if state['type'] == 'FrontBack':
+ num_states = len(state['states'])
+ for ndx, group in enumerate(Grouper(num_states / 2, state['states'])):
+ args = []
+ for item in group:
+ if 'expected' in item:
+ args.append(item['expected'])
+ else:
+ args.append(item['default'])
+ file.Write(
+ " EXPECT_CALL(*gl_, %s(%s, %s))\n" %
+ (state['func'], ('GL_FRONT', 'GL_BACK')[ndx], ", ".join(args)))
+ file.Write(" .Times(1)\n")
+ file.Write(" .RetiresOnSaturation();\n")
+ else:
+ args = []
+ for item in state['states']:
+ if 'expected' in item:
+ args.append(item['expected'])
+ else:
+ args.append(item['default'])
+ file.Write(" EXPECT_CALL(*gl_, %s(%s))\n" %
+ (state['func'], ", ".join(args)))
+ file.Write(" .Times(1)\n")
+ file.Write(" .RetiresOnSaturation();\n")
+ file.Write("""}
+""")
+ file.Close()
def WriteGLES2CLibImplementation(self, filename):
@@ -6274,10 +6809,8 @@ class GLGenerator(object):
file.Write("Validators::Validators()\n")
pre = ': '
post = ','
- count = 0
- for enum in enums:
- count += 1
- if count == len(enums):
+ for count, enum in enumerate(enums):
+ if count + 1 == len(enums):
post = ' {'
if len(_ENUM_LISTS[enum]['valid']) > 0:
code = """ %(pre)s%(name)s(
@@ -6582,6 +7115,17 @@ def main(argv):
(options, args) = parser.parse_args(args=argv)
+ # Add in states and capabilites to GLState
+ for state_name in sorted(_STATES.keys()):
+ state = _STATES[state_name]
+ if 'enum' in state:
+ _ENUM_LISTS['GLState']['valid'].append(state['enum'])
+ else:
+ for item in state['states']:
+ _ENUM_LISTS['GLState']['valid'].append(item['enum'])
+ for capability in _CAPABILITY_FLAGS:
+ _ENUM_LISTS['GLState']['valid'].append("GL_%s" % capability['name'].upper())
+
# This script lives under gpu/command_buffer, cd to base directory.
os.chdir(os.path.dirname(__file__) + "/../..")
@@ -6625,6 +7169,8 @@ def main(argv):
gen.WriteGLES2CLibImplementation("client/gles2_c_lib_autogen.h")
gen.WriteCmdHelperHeader("client/gles2_cmd_helper_autogen.h")
gen.WriteServiceImplementation("service/gles2_cmd_decoder_autogen.h")
+ gen.WriteContextStateHeader("service/context_state_autogen.h")
+ gen.WriteContextStateImpl("service/context_state_impl_autogen.h")
gen.WriteServiceUnitTests("service/gles2_cmd_decoder_unittest_%d_autogen.h")
gen.WriteServiceUtilsHeader("service/gles2_cmd_validation_autogen.h")
gen.WriteServiceUtilsImplementation(
diff --git a/gpu/command_buffer/client/gles2_implementation_unittest_autogen.h b/gpu/command_buffer/client/gles2_implementation_unittest_autogen.h
index 0692887..890df13 100644
--- a/gpu/command_buffer/client/gles2_implementation_unittest_autogen.h
+++ b/gpu/command_buffer/client/gles2_implementation_unittest_autogen.h
@@ -371,9 +371,9 @@ TEST_F(GLES2ImplementationTest, Disable) {
Disable cmd;
};
Cmds expected;
- expected.cmd.Init(GL_DITHER);
+ expected.cmd.Init(GL_BLEND);
- gl_->Disable(GL_DITHER);
+ gl_->Disable(GL_BLEND);
EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected)));
}
@@ -404,9 +404,9 @@ TEST_F(GLES2ImplementationTest, Enable) {
Enable cmd;
};
Cmds expected;
- expected.cmd.Init(GL_DITHER);
+ expected.cmd.Init(GL_BLEND);
- gl_->Enable(GL_DITHER);
+ gl_->Enable(GL_BLEND);
EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected)));
}
diff --git a/gpu/command_buffer/common/gles2_cmd_utils_implementation_autogen.h b/gpu/command_buffer/common/gles2_cmd_utils_implementation_autogen.h
index d15efd1..6a4bee0 100644
--- a/gpu/command_buffer/common/gles2_cmd_utils_implementation_autogen.h
+++ b/gpu/command_buffer/common/gles2_cmd_utils_implementation_autogen.h
@@ -627,10 +627,10 @@ std::string GLES2Util::GetStringBufferUsage(uint32 value) {
std::string GLES2Util::GetStringCapability(uint32 value) {
static EnumToString string_table[] = {
- { GL_DITHER, "GL_DITHER" },
{ GL_BLEND, "GL_BLEND" },
{ GL_CULL_FACE, "GL_CULL_FACE" },
{ GL_DEPTH_TEST, "GL_DEPTH_TEST" },
+ { GL_DITHER, "GL_DITHER" },
{ GL_POLYGON_OFFSET_FILL, "GL_POLYGON_OFFSET_FILL" },
{ GL_SAMPLE_ALPHA_TO_COVERAGE, "GL_SAMPLE_ALPHA_TO_COVERAGE" },
{ GL_SAMPLE_COVERAGE, "GL_SAMPLE_COVERAGE" },
@@ -755,37 +755,18 @@ std::string GLES2Util::GetStringGLState(uint32 value) {
{ GL_ALIASED_POINT_SIZE_RANGE, "GL_ALIASED_POINT_SIZE_RANGE" },
{ GL_ALPHA_BITS, "GL_ALPHA_BITS" },
{ GL_ARRAY_BUFFER_BINDING, "GL_ARRAY_BUFFER_BINDING" },
- { GL_BLEND, "GL_BLEND" },
- { GL_BLEND_COLOR, "GL_BLEND_COLOR" },
- { GL_BLEND_DST_ALPHA, "GL_BLEND_DST_ALPHA" },
- { GL_BLEND_DST_RGB, "GL_BLEND_DST_RGB" },
- { GL_BLEND_EQUATION_ALPHA, "GL_BLEND_EQUATION_ALPHA" },
- { GL_BLEND_EQUATION_RGB, "GL_BLEND_EQUATION_RGB" },
- { GL_BLEND_SRC_ALPHA, "GL_BLEND_SRC_ALPHA" },
- { GL_BLEND_SRC_RGB, "GL_BLEND_SRC_RGB" },
{ GL_BLUE_BITS, "GL_BLUE_BITS" },
- { GL_COLOR_CLEAR_VALUE, "GL_COLOR_CLEAR_VALUE" },
- { GL_COLOR_WRITEMASK, "GL_COLOR_WRITEMASK" },
{ GL_COMPRESSED_TEXTURE_FORMATS, "GL_COMPRESSED_TEXTURE_FORMATS" },
- { GL_CULL_FACE, "GL_CULL_FACE" },
- { GL_CULL_FACE_MODE, "GL_CULL_FACE_MODE" },
{ GL_CURRENT_PROGRAM, "GL_CURRENT_PROGRAM" },
{ GL_DEPTH_BITS, "GL_DEPTH_BITS" },
- { GL_DEPTH_CLEAR_VALUE, "GL_DEPTH_CLEAR_VALUE" },
- { GL_DEPTH_FUNC, "GL_DEPTH_FUNC" },
{ GL_DEPTH_RANGE, "GL_DEPTH_RANGE" },
- { GL_DEPTH_TEST, "GL_DEPTH_TEST" },
- { GL_DEPTH_WRITEMASK, "GL_DEPTH_WRITEMASK" },
- { GL_DITHER, "GL_DITHER" },
{ GL_ELEMENT_ARRAY_BUFFER_BINDING, "GL_ELEMENT_ARRAY_BUFFER_BINDING" },
{ GL_FRAMEBUFFER_BINDING, "GL_FRAMEBUFFER_BINDING" },
- { GL_FRONT_FACE, "GL_FRONT_FACE" },
{ GL_GENERATE_MIPMAP_HINT, "GL_GENERATE_MIPMAP_HINT" },
{ GL_GREEN_BITS, "GL_GREEN_BITS" },
{ GL_IMPLEMENTATION_COLOR_READ_FORMAT,
"GL_IMPLEMENTATION_COLOR_READ_FORMAT" },
{ GL_IMPLEMENTATION_COLOR_READ_TYPE, "GL_IMPLEMENTATION_COLOR_READ_TYPE" },
- { GL_LINE_WIDTH, "GL_LINE_WIDTH" },
{ GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS,
"GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS" },
{ GL_MAX_CUBE_MAP_TEXTURE_SIZE, "GL_MAX_CUBE_MAP_TEXTURE_SIZE" },
@@ -801,9 +782,6 @@ std::string GLES2Util::GetStringGLState(uint32 value) {
{ GL_NUM_COMPRESSED_TEXTURE_FORMATS, "GL_NUM_COMPRESSED_TEXTURE_FORMATS" },
{ GL_NUM_SHADER_BINARY_FORMATS, "GL_NUM_SHADER_BINARY_FORMATS" },
{ GL_PACK_ALIGNMENT, "GL_PACK_ALIGNMENT" },
- { GL_POLYGON_OFFSET_FACTOR, "GL_POLYGON_OFFSET_FACTOR" },
- { GL_POLYGON_OFFSET_FILL, "GL_POLYGON_OFFSET_FILL" },
- { GL_POLYGON_OFFSET_UNITS, "GL_POLYGON_OFFSET_UNITS" },
{ GL_RED_BITS, "GL_RED_BITS" },
{ GL_RENDERBUFFER_BINDING, "GL_RENDERBUFFER_BINDING" },
{ GL_SAMPLE_BUFFERS, "GL_SAMPLE_BUFFERS" },
@@ -811,27 +789,10 @@ std::string GLES2Util::GetStringGLState(uint32 value) {
{ GL_SAMPLE_COVERAGE_VALUE, "GL_SAMPLE_COVERAGE_VALUE" },
{ GL_SAMPLES, "GL_SAMPLES" },
{ GL_SCISSOR_BOX, "GL_SCISSOR_BOX" },
- { GL_SCISSOR_TEST, "GL_SCISSOR_TEST" },
{ GL_SHADER_BINARY_FORMATS, "GL_SHADER_BINARY_FORMATS" },
{ GL_SHADER_COMPILER, "GL_SHADER_COMPILER" },
- { GL_STENCIL_BACK_FAIL, "GL_STENCIL_BACK_FAIL" },
- { GL_STENCIL_BACK_FUNC, "GL_STENCIL_BACK_FUNC" },
- { GL_STENCIL_BACK_PASS_DEPTH_FAIL, "GL_STENCIL_BACK_PASS_DEPTH_FAIL" },
- { GL_STENCIL_BACK_PASS_DEPTH_PASS, "GL_STENCIL_BACK_PASS_DEPTH_PASS" },
- { GL_STENCIL_BACK_REF, "GL_STENCIL_BACK_REF" },
- { GL_STENCIL_BACK_VALUE_MASK, "GL_STENCIL_BACK_VALUE_MASK" },
- { GL_STENCIL_BACK_WRITEMASK, "GL_STENCIL_BACK_WRITEMASK" },
- { GL_STENCIL_BITS, "GL_STENCIL_BITS" },
- { GL_STENCIL_CLEAR_VALUE, "GL_STENCIL_CLEAR_VALUE" },
- { GL_STENCIL_FAIL, "GL_STENCIL_FAIL" },
- { GL_STENCIL_FUNC, "GL_STENCIL_FUNC" },
- { GL_STENCIL_PASS_DEPTH_FAIL, "GL_STENCIL_PASS_DEPTH_FAIL" },
- { GL_STENCIL_PASS_DEPTH_PASS, "GL_STENCIL_PASS_DEPTH_PASS" },
- { GL_STENCIL_REF, "GL_STENCIL_REF" },
- { GL_STENCIL_TEST, "GL_STENCIL_TEST" },
- { GL_STENCIL_VALUE_MASK, "GL_STENCIL_VALUE_MASK" },
- { GL_STENCIL_WRITEMASK, "GL_STENCIL_WRITEMASK" },
{ GL_SUBPIXEL_BITS, "GL_SUBPIXEL_BITS" },
+ { GL_STENCIL_BITS, "GL_STENCIL_BITS" },
{ GL_TEXTURE_BINDING_2D, "GL_TEXTURE_BINDING_2D" },
{ GL_TEXTURE_BINDING_CUBE_MAP, "GL_TEXTURE_BINDING_CUBE_MAP" },
{ GL_UNPACK_ALIGNMENT, "GL_UNPACK_ALIGNMENT" },
@@ -841,6 +802,52 @@ std::string GLES2Util::GetStringGLState(uint32 value) {
{ GL_UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM,
"GL_UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM" },
{ GL_VIEWPORT, "GL_VIEWPORT" },
+ { GL_BLEND_COLOR, "GL_BLEND_COLOR" },
+ { GL_BLEND_EQUATION_RGB, "GL_BLEND_EQUATION_RGB" },
+ { GL_BLEND_EQUATION_ALPHA, "GL_BLEND_EQUATION_ALPHA" },
+ { GL_BLEND_SRC_RGB, "GL_BLEND_SRC_RGB" },
+ { GL_BLEND_DST_RGB, "GL_BLEND_DST_RGB" },
+ { GL_BLEND_SRC_ALPHA, "GL_BLEND_SRC_ALPHA" },
+ { GL_BLEND_DST_ALPHA, "GL_BLEND_DST_ALPHA" },
+ { GL_COLOR_CLEAR_VALUE, "GL_COLOR_CLEAR_VALUE" },
+ { GL_DEPTH_CLEAR_VALUE, "GL_DEPTH_CLEAR_VALUE" },
+ { GL_STENCIL_CLEAR_VALUE, "GL_STENCIL_CLEAR_VALUE" },
+ { GL_COLOR_WRITEMASK, "GL_COLOR_WRITEMASK" },
+ { GL_CULL_FACE_MODE, "GL_CULL_FACE_MODE" },
+ { GL_DEPTH_FUNC, "GL_DEPTH_FUNC" },
+ { GL_DEPTH_WRITEMASK, "GL_DEPTH_WRITEMASK" },
+ { GL_DEPTH_RANGE, "GL_DEPTH_RANGE" },
+ { GL_FRONT_FACE, "GL_FRONT_FACE" },
+ { GL_LINE_WIDTH, "GL_LINE_WIDTH" },
+ { GL_POLYGON_OFFSET_FACTOR, "GL_POLYGON_OFFSET_FACTOR" },
+ { GL_POLYGON_OFFSET_UNITS, "GL_POLYGON_OFFSET_UNITS" },
+ { GL_SAMPLE_COVERAGE_VALUE, "GL_SAMPLE_COVERAGE_VALUE" },
+ { GL_SAMPLE_COVERAGE_INVERT, "GL_SAMPLE_COVERAGE_INVERT" },
+ { GL_SCISSOR_BOX, "GL_SCISSOR_BOX" },
+ { GL_STENCIL_FUNC, "GL_STENCIL_FUNC" },
+ { GL_STENCIL_REF, "GL_STENCIL_REF" },
+ { GL_STENCIL_VALUE_MASK, "GL_STENCIL_VALUE_MASK" },
+ { GL_STENCIL_BACK_FUNC, "GL_STENCIL_BACK_FUNC" },
+ { GL_STENCIL_BACK_REF, "GL_STENCIL_BACK_REF" },
+ { GL_STENCIL_BACK_VALUE_MASK, "GL_STENCIL_BACK_VALUE_MASK" },
+ { GL_STENCIL_WRITEMASK, "GL_STENCIL_WRITEMASK" },
+ { GL_STENCIL_BACK_WRITEMASK, "GL_STENCIL_BACK_WRITEMASK" },
+ { GL_STENCIL_FAIL, "GL_STENCIL_FAIL" },
+ { GL_STENCIL_PASS_DEPTH_FAIL, "GL_STENCIL_PASS_DEPTH_FAIL" },
+ { GL_STENCIL_PASS_DEPTH_PASS, "GL_STENCIL_PASS_DEPTH_PASS" },
+ { GL_STENCIL_BACK_FAIL, "GL_STENCIL_BACK_FAIL" },
+ { GL_STENCIL_BACK_PASS_DEPTH_FAIL, "GL_STENCIL_BACK_PASS_DEPTH_FAIL" },
+ { GL_STENCIL_BACK_PASS_DEPTH_PASS, "GL_STENCIL_BACK_PASS_DEPTH_PASS" },
+ { GL_VIEWPORT, "GL_VIEWPORT" },
+ { GL_BLEND, "GL_BLEND" },
+ { GL_CULL_FACE, "GL_CULL_FACE" },
+ { GL_DEPTH_TEST, "GL_DEPTH_TEST" },
+ { GL_DITHER, "GL_DITHER" },
+ { GL_POLYGON_OFFSET_FILL, "GL_POLYGON_OFFSET_FILL" },
+ { GL_SAMPLE_ALPHA_TO_COVERAGE, "GL_SAMPLE_ALPHA_TO_COVERAGE" },
+ { GL_SAMPLE_COVERAGE, "GL_SAMPLE_COVERAGE" },
+ { GL_SCISSOR_TEST, "GL_SCISSOR_TEST" },
+ { GL_STENCIL_TEST, "GL_STENCIL_TEST" },
};
return GLES2Util::GetQualifiedEnumString(
string_table, arraysize(string_table), value);
diff --git a/gpu/command_buffer/service/context_state.cc b/gpu/command_buffer/service/context_state.cc
index 866abf4..f0524ab 100644
--- a/gpu/command_buffer/service/context_state.cc
+++ b/gpu/command_buffer/service/context_state.cc
@@ -4,9 +4,23 @@
#include "gpu/command_buffer/service/context_state.h"
+#include "gpu/command_buffer/common/gles2_cmd_utils.h"
+
namespace gpu {
namespace gles2 {
+namespace {
+
+void EnableDisable(GLenum pname, bool enable) {
+ if (enable) {
+ glEnable(pname);
+ } else {
+ glDisable(pname);
+ }
+}
+
+} // anonymous namespace.
+
TextureUnit::TextureUnit()
: bind_target(GL_TEXTURE_2D) {
}
@@ -18,78 +32,22 @@ ContextState::ContextState()
: pack_alignment(4),
unpack_alignment(4),
active_texture_unit(0),
- color_clear_red(0),
- color_clear_green(0),
- color_clear_blue(0),
- color_clear_alpha(0),
- color_mask_red(true),
- color_mask_green(true),
- color_mask_blue(true),
- color_mask_alpha(true),
- depth_clear(1.0f),
- depth_mask(true),
- depth_func(GL_LESS),
- z_near(0.0f),
- z_far(1.0f),
- enable_blend(false),
- enable_cull_face(false),
- enable_scissor_test(false),
- enable_depth_test(false),
- enable_stencil_test(false),
- enable_polygon_offset_fill(false),
- enable_dither(true),
- enable_sample_alpha_to_coverage(false),
- enable_sample_coverage(false),
- viewport_x(0),
- viewport_y(0),
- viewport_width(0),
- viewport_height(0),
viewport_max_width(0),
viewport_max_height(0),
- scissor_x(0),
- scissor_y(0),
- scissor_width(0),
- scissor_height(0),
- cull_mode(GL_BACK),
- front_face(GL_CCW),
- blend_source_rgb(GL_ONE),
- blend_dest_rgb(GL_ZERO),
- blend_source_alpha(GL_ONE),
- blend_dest_alpha(GL_ZERO),
- blend_equation_rgb(GL_FUNC_ADD),
- blend_equation_alpha(GL_FUNC_ADD),
- blend_color_red(0),
- blend_color_green(0),
- blend_color_blue(0),
- blend_color_alpha(0),
- stencil_clear(0),
- stencil_front_writemask(0xFFFFFFFFU),
- stencil_front_func(GL_ALWAYS),
- stencil_front_ref(0),
- stencil_front_mask(0xFFFFFFFFU),
- stencil_front_fail_op(GL_KEEP),
- stencil_front_z_fail_op(GL_KEEP),
- stencil_front_z_pass_op(GL_KEEP),
- stencil_back_writemask(0xFFFFFFFFU),
- stencil_back_func(GL_ALWAYS),
- stencil_back_ref(0),
- stencil_back_mask(0xFFFFFFFFU),
- stencil_back_fail_op(GL_KEEP),
- stencil_back_z_fail_op(GL_KEEP),
- stencil_back_z_pass_op(GL_KEEP),
- polygon_offset_factor(0.0f),
- polygon_offset_units(0.0f),
- sample_coverage_value(1.0f),
- sample_coverage_invert(false),
- line_width(1.0),
hint_generate_mipmap(GL_DONT_CARE),
hint_fragment_shader_derivative(GL_DONT_CARE),
pack_reverse_row_order(false) {
+ Initialize();
}
ContextState::~ContextState() {
}
+// Include the auto-generated part of this file. We split this because it means
+// we can easily edit the non-auto generated parts right here in this file
+// instead of having to edit some template or the code generator.
+#include "gpu/command_buffer/service/context_state_impl_autogen.h"
+
} // namespace gles2
} // namespace gpu
diff --git a/gpu/command_buffer/service/context_state.h b/gpu/command_buffer/service/context_state.h
index 7cabc0a..6997d60 100644
--- a/gpu/command_buffer/service/context_state.h
+++ b/gpu/command_buffer/service/context_state.h
@@ -81,6 +81,15 @@ struct GPU_EXPORT ContextState {
ContextState();
~ContextState();
+ void Initialize();
+
+ void InitCapabilities();
+ void InitState();
+
+ #include "gpu/command_buffer/service/context_state_autogen.h"
+
+ EnableFlags enable_flags;
+
// pack alignment as last set by glPixelStorei
GLint pack_alignment;
@@ -92,44 +101,10 @@ struct GPU_EXPORT ContextState {
// be 2.
GLuint active_texture_unit;
- GLfloat color_clear_red;
- GLfloat color_clear_green;
- GLfloat color_clear_blue;
- GLfloat color_clear_alpha;
- GLboolean color_mask_red;
- GLboolean color_mask_green;
- GLboolean color_mask_blue;
- GLboolean color_mask_alpha;
-
- GLclampf depth_clear;
- GLboolean depth_mask;
- GLenum depth_func;
- float z_near;
- float z_far;
-
- bool enable_blend;
- bool enable_cull_face;
- bool enable_scissor_test;
- bool enable_depth_test;
- bool enable_stencil_test;
- bool enable_polygon_offset_fill;
- bool enable_dither;
- bool enable_sample_alpha_to_coverage;
- bool enable_sample_coverage;
-
// Cached values of the currently assigned viewport dimensions.
- GLint viewport_x;
- GLint viewport_y;
- GLsizei viewport_width;
- GLsizei viewport_height;
GLsizei viewport_max_width;
GLsizei viewport_max_height;
- GLint scissor_x;
- GLint scissor_y;
- GLsizei scissor_width;
- GLsizei scissor_height;
-
// The currently bound array buffer. If this is 0 it is illegal to call
// glVertexAttribPointer.
BufferManager::BufferInfo::Ref bound_array_buffer;
@@ -152,44 +127,6 @@ struct GPU_EXPORT ContextState {
QueryManager::Query::Ref current_query;
- GLenum cull_mode;
- GLenum front_face;
-
- GLenum blend_source_rgb;
- GLenum blend_dest_rgb;
- GLenum blend_source_alpha;
- GLenum blend_dest_alpha;
- GLenum blend_equation_rgb;
- GLenum blend_equation_alpha;
- GLfloat blend_color_red;
- GLfloat blend_color_green;
- GLfloat blend_color_blue;
- GLfloat blend_color_alpha;
-
- GLint stencil_clear;
- GLuint stencil_front_writemask;
- GLenum stencil_front_func;
- GLint stencil_front_ref;
- GLuint stencil_front_mask;
- GLenum stencil_front_fail_op;
- GLenum stencil_front_z_fail_op;
- GLenum stencil_front_z_pass_op;
- GLuint stencil_back_writemask;
- GLenum stencil_back_func;
- GLint stencil_back_ref;
- GLuint stencil_back_mask;
- GLenum stencil_back_fail_op;
- GLenum stencil_back_z_fail_op;
- GLenum stencil_back_z_pass_op;
-
- GLfloat polygon_offset_factor;
- GLfloat polygon_offset_units;
-
- GLclampf sample_coverage_value;
- bool sample_coverage_invert;
-
- GLfloat line_width;
-
GLenum hint_generate_mipmap;
GLenum hint_fragment_shader_derivative;
diff --git a/gpu/command_buffer/service/context_state_autogen.h b/gpu/command_buffer/service/context_state_autogen.h
new file mode 100644
index 0000000..85835b1
--- /dev/null
+++ b/gpu/command_buffer/service/context_state_autogen.h
@@ -0,0 +1,81 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// This file is auto-generated from
+// gpu/command_buffer/build_gles2_cmd_buffer.py
+// DO NOT EDIT!
+
+// It is included by context_state.h
+#ifndef GPU_COMMAND_BUFFER_SERVICE_CONTEXT_STATE_AUTOGEN_H_
+#define GPU_COMMAND_BUFFER_SERVICE_CONTEXT_STATE_AUTOGEN_H_
+
+struct EnableFlags {
+ EnableFlags();
+ bool blend;
+ bool cull_face;
+ bool depth_test;
+ bool dither;
+ bool polygon_offset_fill;
+ bool sample_alpha_to_coverage;
+ bool sample_coverage;
+ bool scissor_test;
+ bool stencil_test;
+};
+
+GLfloat blend_color_red;
+GLfloat blend_color_green;
+GLfloat blend_color_blue;
+GLfloat blend_color_alpha;
+GLenum blend_equation_rgb;
+GLenum blend_equation_alpha;
+GLenum blend_source_rgb;
+GLenum blend_dest_rgb;
+GLenum blend_source_alpha;
+GLenum blend_dest_alpha;
+GLfloat color_clear_red;
+GLfloat color_clear_green;
+GLfloat color_clear_blue;
+GLfloat color_clear_alpha;
+GLclampf depth_clear;
+GLint stencil_clear;
+GLboolean color_mask_red;
+GLboolean color_mask_green;
+GLboolean color_mask_blue;
+GLboolean color_mask_alpha;
+GLenum cull_mode;
+GLenum depth_func;
+GLboolean depth_mask;
+GLclampf z_near;
+GLclampf z_far;
+GLenum front_face;
+GLfloat line_width;
+GLfloat polygon_offset_factor;
+GLfloat polygon_offset_units;
+GLclampf sample_coverage_value;
+GLboolean sample_coverage_invert;
+GLfloat scissor_x;
+GLfloat scissor_y;
+GLfloat scissor_width;
+GLfloat scissor_height;
+GLenum stencil_front_func;
+GLint stencil_front_ref;
+GLuint stencil_front_mask;
+GLenum stencil_back_func;
+GLint stencil_back_ref;
+GLuint stencil_back_mask;
+GLuint stencil_front_writemask;
+GLuint stencil_back_writemask;
+GLenum stencil_front_fail_op;
+GLenum stencil_front_z_fail_op;
+GLenum stencil_front_z_pass_op;
+GLenum stencil_back_fail_op;
+GLenum stencil_back_z_fail_op;
+GLenum stencil_back_z_pass_op;
+GLfloat viewport_x;
+GLfloat viewport_y;
+GLfloat viewport_width;
+GLfloat viewport_height;
+
+#endif // GPU_COMMAND_BUFFER_SERVICE_CONTEXT_STATE_AUTOGEN_H_
+
diff --git a/gpu/command_buffer/service/context_state_impl_autogen.h b/gpu/command_buffer/service/context_state_impl_autogen.h
new file mode 100644
index 0000000..0c207c7
--- /dev/null
+++ b/gpu/command_buffer/service/context_state_impl_autogen.h
@@ -0,0 +1,130 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// This file is auto-generated from
+// gpu/command_buffer/build_gles2_cmd_buffer.py
+// DO NOT EDIT!
+
+// It is included by context_state.cc
+#ifndef GPU_COMMAND_BUFFER_SERVICE_CONTEXT_STATE_IMPL_AUTOGEN_H_
+#define GPU_COMMAND_BUFFER_SERVICE_CONTEXT_STATE_IMPL_AUTOGEN_H_
+
+ContextState::EnableFlags::EnableFlags()
+ : blend(false),
+ cull_face(false),
+ depth_test(false),
+ dither(true),
+ polygon_offset_fill(false),
+ sample_alpha_to_coverage(false),
+ sample_coverage(false),
+ scissor_test(false),
+ stencil_test(false) {
+}
+
+void ContextState::Initialize() {
+ blend_color_red = 0.0f;
+ blend_color_green = 0.0f;
+ blend_color_blue = 0.0f;
+ blend_color_alpha = 0.0f;
+ blend_equation_rgb = GL_FUNC_ADD;
+ blend_equation_alpha = GL_FUNC_ADD;
+ blend_source_rgb = GL_ONE;
+ blend_dest_rgb = GL_ZERO;
+ blend_source_alpha = GL_ONE;
+ blend_dest_alpha = GL_ZERO;
+ color_clear_red = 0.0f;
+ color_clear_green = 0.0f;
+ color_clear_blue = 0.0f;
+ color_clear_alpha = 0.0f;
+ depth_clear = 1.0f;
+ stencil_clear = 0;
+ color_mask_red = true;
+ color_mask_green = true;
+ color_mask_blue = true;
+ color_mask_alpha = true;
+ cull_mode = GL_BACK;
+ depth_func = GL_LESS;
+ depth_mask = true;
+ z_near = 0.0f;
+ z_far = 1.0f;
+ front_face = GL_CCW;
+ line_width = 1.0f;
+ polygon_offset_factor = 0.0f;
+ polygon_offset_units = 0.0f;
+ sample_coverage_value = 0.0f;
+ sample_coverage_invert = false;
+ scissor_x = 0.0f;
+ scissor_y = 0.0f;
+ scissor_width = 1.0f;
+ scissor_height = 1.0f;
+ stencil_front_func = GL_ALWAYS;
+ stencil_front_ref = 0;
+ stencil_front_mask = 0xFFFFFFFFU;
+ stencil_back_func = GL_ALWAYS;
+ stencil_back_ref = 0;
+ stencil_back_mask = 0xFFFFFFFFU;
+ stencil_front_writemask = 0xFFFFFFFFU;
+ stencil_back_writemask = 0xFFFFFFFFU;
+ stencil_front_fail_op = GL_KEEP;
+ stencil_front_z_fail_op = GL_KEEP;
+ stencil_front_z_pass_op = GL_KEEP;
+ stencil_back_fail_op = GL_KEEP;
+ stencil_back_z_fail_op = GL_KEEP;
+ stencil_back_z_pass_op = GL_KEEP;
+ viewport_x = 0.0f;
+ viewport_y = 0.0f;
+ viewport_width = 1.0f;
+ viewport_height = 1.0f;
+}
+
+void ContextState::InitCapabilities() {
+ EnableDisable(GL_BLEND, enable_flags.blend);
+ EnableDisable(GL_CULL_FACE, enable_flags.cull_face);
+ EnableDisable(GL_DEPTH_TEST, enable_flags.depth_test);
+ EnableDisable(GL_DITHER, enable_flags.dither);
+ EnableDisable(GL_POLYGON_OFFSET_FILL, enable_flags.polygon_offset_fill);
+ EnableDisable(
+ GL_SAMPLE_ALPHA_TO_COVERAGE, enable_flags.sample_alpha_to_coverage);
+ EnableDisable(GL_SAMPLE_COVERAGE, enable_flags.sample_coverage);
+ EnableDisable(GL_SCISSOR_TEST, enable_flags.scissor_test);
+ EnableDisable(GL_STENCIL_TEST, enable_flags.stencil_test);
+}
+
+void ContextState::InitState() {
+ glBlendColor(
+ blend_color_red, blend_color_green, blend_color_blue, blend_color_alpha);
+ glBlendEquationSeparate(blend_equation_rgb, blend_equation_alpha);
+ glBlendFuncSeparate(
+ blend_source_rgb, blend_dest_rgb, blend_source_alpha, blend_dest_alpha);
+ glClearColor(
+ color_clear_red, color_clear_green, color_clear_blue, color_clear_alpha);
+ glClearDepth(depth_clear);
+ glClearStencil(stencil_clear);
+ glColorMask(
+ color_mask_red, color_mask_green, color_mask_blue, color_mask_alpha);
+ glCullFace(cull_mode);
+ glDepthFunc(depth_func);
+ glDepthMask(depth_mask);
+ glDepthRange(z_near, z_far);
+ glFrontFace(front_face);
+ glLineWidth(line_width);
+ glPolygonOffset(polygon_offset_factor, polygon_offset_units);
+ glSampleCoverage(sample_coverage_value, sample_coverage_invert);
+ glScissor(scissor_x, scissor_y, scissor_width, scissor_height);
+ glStencilFuncSeparate(
+ GL_FRONT, stencil_front_func, stencil_front_ref, stencil_front_mask);
+ glStencilFuncSeparate(
+ GL_BACK, stencil_back_func, stencil_back_ref, stencil_back_mask);
+ glStencilMaskSeparate(GL_FRONT, stencil_front_writemask);
+ glStencilMaskSeparate(GL_BACK, stencil_back_writemask);
+ glStencilOpSeparate(
+ GL_FRONT, stencil_front_fail_op, stencil_front_z_fail_op,
+ stencil_front_z_pass_op);
+ glStencilOpSeparate(
+ GL_BACK, stencil_back_fail_op, stencil_back_z_fail_op,
+ stencil_back_z_pass_op);
+ glViewport(viewport_x, viewport_y, viewport_width, viewport_height);
+}
+#endif // GPU_COMMAND_BUFFER_SERVICE_CONTEXT_STATE_IMPL_AUTOGEN_H_
+
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.cc b/gpu/command_buffer/service/gles2_cmd_decoder.cc
index 6b38210..ca0b4e9 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder.cc
+++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc
@@ -971,6 +971,8 @@ class GLES2DecoderImpl : public base::SupportsWeakPtr<GLES2DecoderImpl>,
// Helper for glGetBooleanv, glGetFloatv and glGetIntegerv
bool GetHelper(GLenum pname, GLint* params, GLsizei* num_written);
+ // Same as GetHelper except for auto-generated state.
+ bool GetState(GLenum pname, GLint* params, GLsizei* num_written);
// Wrapper for glCreateProgram
bool CreateProgramHelper(GLuint client_id);
@@ -1020,18 +1022,7 @@ class GLES2DecoderImpl : public base::SupportsWeakPtr<GLES2DecoderImpl>,
// Wrapper for glClear
error::Error DoClear(GLbitfield mask);
- // Wrappers for clear and mask settings functions.
- void DoStencilMask(GLuint mask);
- void DoStencilMaskSeparate(GLenum face, GLuint mask);
- void DoStencilFunc(GLenum func, GLint ref, GLuint mask);
- void DoStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask);
- void DoStencilOp(GLenum fail, GLenum zfail, GLenum zpass);
- void DoStencilOpSeparate(
- GLenum face, GLenum fail, GLenum zfail, GLenum zpass);
-
// Wrappers for various state.
- void DoBlendEquation(GLenum mode);
- void DoBlendFunc(GLenum sfactor, GLenum dfactor);
void DoDepthRangef(GLclampf znear, GLclampf zfar);
void DoHint(GLenum target, GLenum mode);
void DoSampleCoverage (GLclampf value, GLboolean invert);
@@ -1680,7 +1671,7 @@ ScopedResolvedFrameBufferBinder::~ScopedResolvedFrameBufferBinder() {
ScopedGLErrorSuppressor suppressor(decoder_);
decoder_->RestoreCurrentFramebufferBindings();
- if (decoder_->state_.enable_scissor_test) {
+ if (decoder_->state_.enable_flags.scissor_test) {
glEnable(GL_SCISSOR_TEST);
}
}
@@ -2240,9 +2231,6 @@ bool GLES2DecoderImpl::Initialize(
state_.viewport_width = size.width();
state_.viewport_height = size.height();
- glViewport(
- state_.viewport_x, state_.viewport_y,
- state_.viewport_width, state_.viewport_height);
GLint viewport_params[4] = { 0 };
glGetIntegerv(GL_MAX_VIEWPORT_DIMS, viewport_params);
@@ -2253,76 +2241,11 @@ bool GLES2DecoderImpl::Initialize(
state_.scissor_height = state_.viewport_height;
// Set all the default state because some GL drivers get it wrong.
+ state_.InitCapabilities();
+ state_.InitState();
glActiveTexture(GL_TEXTURE0 + state_.active_texture_unit);
- EnableDisable(GL_BLEND, state_.enable_blend);
- glBlendColor(
- state_.blend_color_red,
- state_.blend_color_green,
- state_.blend_color_blue,
- state_.blend_color_alpha);
- glBlendFunc(
- state_.blend_source_rgb,
- state_.blend_dest_rgb);
- glBlendFuncSeparate(
- state_.blend_source_rgb,
- state_.blend_dest_rgb,
- state_.blend_source_alpha,
- state_.blend_dest_alpha);
- glBlendEquation(
- state_.blend_equation_rgb);
- glBlendEquationSeparate(
- state_.blend_equation_rgb, state_.blend_equation_alpha);
- glClearColor(
- state_.color_clear_red, state_.color_clear_green, state_.color_clear_blue,
- state_.color_clear_alpha);
- glColorMask(
- state_.color_mask_red, state_.color_mask_green, state_.color_mask_blue,
- state_.color_mask_alpha);
- EnableDisable(GL_CULL_FACE, state_.enable_cull_face);
- glCullFace(state_.cull_mode);
- glClearDepth(state_.depth_clear);
- glDepthFunc(state_.depth_func);
- glDepthRange(state_.z_near, state_.z_far);
- EnableDisable(GL_DEPTH_TEST, state_.enable_depth_test);
- EnableDisable(GL_DITHER, state_.enable_dither);
- glFrontFace(state_.front_face);
glHint(GL_GENERATE_MIPMAP_HINT, state_.hint_generate_mipmap);
- glLineWidth(state_.line_width);
glPixelStorei(GL_PACK_ALIGNMENT, state_.pack_alignment);
- glPolygonOffset(state_.polygon_offset_factor, state_.polygon_offset_units);
- EnableDisable(GL_POLYGON_OFFSET_FILL, state_.enable_polygon_offset_fill);
- EnableDisable(
- GL_SAMPLE_ALPHA_TO_COVERAGE, state_.enable_sample_alpha_to_coverage);
- EnableDisable(GL_SAMPLE_COVERAGE, state_.enable_sample_coverage);
- glSampleCoverage(state_.sample_coverage_value, state_.sample_coverage_invert);
- glScissor(
- state_.scissor_x, state_.scissor_y,
- state_.scissor_width, state_.scissor_height);
- EnableDisable(GL_SCISSOR_TEST, state_.enable_scissor_test);
- EnableDisable(GL_STENCIL_TEST, state_.enable_stencil_test);
- glClearStencil(state_.stencil_clear);
- glStencilFuncSeparate(
- GL_FRONT,
- state_.stencil_front_func,
- state_.stencil_front_ref,
- state_.stencil_front_mask);
- glStencilFuncSeparate(
- GL_BACK,
- state_.stencil_back_func,
- state_.stencil_back_ref,
- state_.stencil_back_mask);
- glStencilOpSeparate(
- GL_FRONT,
- state_.stencil_front_fail_op,
- state_.stencil_front_z_fail_op,
- state_.stencil_front_z_pass_op);
- glStencilOpSeparate(
- GL_BACK,
- state_.stencil_back_fail_op,
- state_.stencil_back_z_fail_op,
- state_.stencil_back_z_pass_op);
- glStencilMaskSeparate(GL_FRONT, state_.stencil_front_writemask);
- glStencilMaskSeparate(GL_BACK, state_.stencil_back_writemask);
glPixelStorei(GL_UNPACK_ALIGNMENT, state_.unpack_alignment);
DoBindBuffer(GL_ARRAY_BUFFER, 0);
@@ -3400,16 +3323,17 @@ void GLES2DecoderImpl::ApplyDirtyState() {
BoundFramebufferHasColorAttachmentWithAlpha());
bool have_depth = BoundFramebufferHasDepthAttachment();
glDepthMask(state_.depth_mask && have_depth);
- EnableDisable(GL_DEPTH_TEST, state_.enable_depth_test && have_depth);
+ EnableDisable(GL_DEPTH_TEST, state_.enable_flags.depth_test && have_depth);
bool have_stencil = BoundFramebufferHasStencilAttachment();
glStencilMaskSeparate(
GL_FRONT, have_stencil ? state_.stencil_front_writemask : 0);
glStencilMaskSeparate(
GL_BACK, have_stencil ? state_.stencil_back_writemask : 0);
- EnableDisable(GL_STENCIL_TEST, state_.enable_stencil_test && have_stencil);
- EnableDisable(GL_CULL_FACE, state_.enable_cull_face);
- EnableDisable(GL_SCISSOR_TEST, state_.enable_scissor_test);
- EnableDisable(GL_BLEND, state_.enable_blend);
+ EnableDisable(
+ GL_STENCIL_TEST, state_.enable_flags.stencil_test && have_stencil);
+ EnableDisable(GL_CULL_FACE, state_.enable_flags.cull_face);
+ EnableDisable(GL_SCISSOR_TEST, state_.enable_flags.scissor_test);
+ EnableDisable(GL_BLEND, state_.enable_flags.blend);
clear_state_dirty_ = false;
}
}
@@ -3663,6 +3587,9 @@ bool GLES2DecoderImpl::GetHelper(
return true;
}
}
+ if (GetState(pname, params, num_written)) {
+ return true;
+ }
switch (pname) {
case GL_MAX_VIEWPORT_DIMS:
if (offscreen_target_frame_buffer_.get()) {
@@ -3698,45 +3625,6 @@ bool GLES2DecoderImpl::GetHelper(
params[0] = texture_manager()->MaxSizeForTarget(GL_TEXTURE_CUBE_MAP);
}
return true;
- case GL_COLOR_WRITEMASK:
- *num_written = 4;
- if (params) {
- params[0] = state_.color_mask_red;
- params[1] = state_.color_mask_green;
- params[2] = state_.color_mask_blue;
- params[3] = state_.color_mask_alpha;
- }
- return true;
- case GL_DEPTH_WRITEMASK:
- *num_written = 1;
- if (params) {
- params[0] = state_.depth_mask;
- }
- return true;
- case GL_STENCIL_BACK_WRITEMASK:
- *num_written = 1;
- if (params) {
- params[0] = state_.stencil_back_writemask;
- }
- return true;
- case GL_STENCIL_WRITEMASK:
- *num_written = 1;
- if (params) {
- params[0] = state_.stencil_front_writemask;
- }
- return true;
- case GL_DEPTH_TEST:
- *num_written = 1;
- if (params) {
- params[0] = state_.enable_depth_test;
- }
- return true;
- case GL_STENCIL_TEST:
- *num_written = 1;
- if (params) {
- params[0] = state_.enable_stencil_test;
- }
- return true;
case GL_ALPHA_BITS:
*num_written = 1;
if (params) {
@@ -4348,43 +4236,6 @@ void GLES2DecoderImpl::DoFramebufferRenderbuffer(
}
}
-bool GLES2DecoderImpl::SetCapabilityState(GLenum cap, bool enabled) {
- switch (cap) {
- case GL_BLEND:
- state_.enable_blend = enabled;
- return true;
- case GL_CULL_FACE:
- state_.enable_cull_face = enabled;
- return true;
- case GL_SCISSOR_TEST:
- state_.enable_scissor_test = enabled;
- return true;
- case GL_DEPTH_TEST: {
- if (state_.enable_depth_test != enabled) {
- state_.enable_depth_test = enabled;
- clear_state_dirty_ = true;
- }
- return false;
- }
- case GL_STENCIL_TEST:
- if (state_.enable_stencil_test != enabled) {
- state_.enable_stencil_test = enabled;
- clear_state_dirty_ = true;
- }
- return false;
- case GL_POLYGON_OFFSET_FILL:
- state_.enable_polygon_offset_fill = enabled;
- case GL_DITHER:
- state_.enable_dither = enabled;
- case GL_SAMPLE_ALPHA_TO_COVERAGE:
- state_.enable_sample_alpha_to_coverage = enabled;
- case GL_SAMPLE_COVERAGE:
- state_.enable_sample_coverage = enabled;
- default:
- return true;
- }
-}
-
void GLES2DecoderImpl::DoDisable(GLenum cap) {
if (SetCapabilityState(cap, false)) {
glDisable(cap);
@@ -4397,118 +4248,12 @@ void GLES2DecoderImpl::DoEnable(GLenum cap) {
}
}
-bool GLES2DecoderImpl::DoIsEnabled(GLenum cap) {
- switch (cap) {
- case GL_BLEND:
- return state_.enable_blend;
- case GL_CULL_FACE:
- return state_.enable_cull_face;
- case GL_SCISSOR_TEST:
- return state_.enable_scissor_test;
- case GL_DEPTH_TEST:
- return state_.enable_depth_test;
- case GL_STENCIL_TEST:
- return state_.enable_stencil_test;
- case GL_POLYGON_OFFSET_FILL:
- return state_.enable_polygon_offset_fill;
- case GL_DITHER:
- return state_.enable_dither;
- case GL_SAMPLE_ALPHA_TO_COVERAGE:
- return state_.enable_sample_alpha_to_coverage;
- case GL_SAMPLE_COVERAGE:
- return state_.enable_sample_coverage;
- default:
- return glIsEnabled(cap) != 0;
- }
-}
-
void GLES2DecoderImpl::DoDepthRangef(GLclampf znear, GLclampf zfar) {
state_.z_near = std::min(1.0f, std::max(0.0f, znear));
state_.z_far = std::min(1.0f, std::max(0.0f, zfar));
glDepthRange(znear, zfar);
}
-void GLES2DecoderImpl::DoStencilMask(GLuint mask) {
- state_.stencil_front_writemask = mask;
- state_.stencil_back_writemask = mask;
- clear_state_dirty_ = true;
-}
-
-void GLES2DecoderImpl::DoStencilMaskSeparate(GLenum face, GLuint mask) {
- if (face == GL_FRONT || face == GL_FRONT_AND_BACK) {
- state_.stencil_front_writemask = mask;
- }
- if (face == GL_BACK || face == GL_FRONT_AND_BACK) {
- state_.stencil_back_writemask = mask;
- }
- clear_state_dirty_ = true;
-}
-
-void GLES2DecoderImpl::DoStencilFunc(GLenum func, GLint ref, GLuint mask) {
- state_.stencil_front_func = func;
- state_.stencil_front_ref = ref;
- state_.stencil_front_mask = mask;
- state_.stencil_back_func = func;
- state_.stencil_back_ref = ref;
- state_.stencil_back_mask = mask;
- glStencilFunc(func, ref, mask);
-}
-
-void GLES2DecoderImpl::DoStencilFuncSeparate(
- GLenum face, GLenum func, GLint ref, GLuint mask) {
- if (face == GL_FRONT || face == GL_FRONT_AND_BACK) {
- state_.stencil_front_func = func;
- state_.stencil_front_ref = ref;
- state_.stencil_front_mask = mask;
- }
- if (face == GL_BACK || face == GL_FRONT_AND_BACK) {
- state_.stencil_back_func = func;
- state_.stencil_back_ref = ref;
- state_.stencil_back_mask = mask;
- }
- glStencilFuncSeparate(face, func, ref, mask);
-}
-
-void GLES2DecoderImpl::DoStencilOp(
- GLenum fail, GLenum zfail, GLenum zpass) {
- state_.stencil_front_fail_op = fail;
- state_.stencil_front_z_fail_op = zfail;
- state_.stencil_front_z_pass_op = zpass;
- state_.stencil_back_fail_op = fail;
- state_.stencil_back_z_fail_op = zfail;
- state_.stencil_back_z_pass_op = zpass;
- glStencilOp(fail, zfail, zpass);
-}
-
-void GLES2DecoderImpl::DoStencilOpSeparate(
- GLenum face, GLenum fail, GLenum zfail, GLenum zpass) {
- if (face == GL_FRONT || face == GL_FRONT_AND_BACK) {
- state_.stencil_front_fail_op = fail;
- state_.stencil_front_z_fail_op = zfail;
- state_.stencil_front_z_pass_op = zpass;
- }
- if (face == GL_BACK || face == GL_FRONT_AND_BACK) {
- state_.stencil_back_fail_op = fail;
- state_.stencil_back_z_fail_op = zfail;
- state_.stencil_back_z_pass_op = zpass;
- }
- glStencilOpSeparate(face, fail, zfail, zpass);
-}
-
-void GLES2DecoderImpl::DoBlendEquation(GLenum mode) {
- state_.blend_equation_rgb = mode;
- state_.blend_equation_alpha = mode;
- glBlendEquation(mode);
-}
-
-void GLES2DecoderImpl::DoBlendFunc(GLenum sfactor, GLenum dfactor) {
- state_.blend_source_rgb = sfactor;
- state_.blend_dest_rgb = dfactor;
- state_.blend_source_alpha = sfactor;
- state_.blend_dest_alpha = dfactor;
- glBlendFunc(sfactor, dfactor);
-}
-
void GLES2DecoderImpl::DoHint(GLenum target, GLenum mode) {
switch (target) {
case GL_GENERATE_MIPMAP_HINT:
@@ -4589,7 +4334,7 @@ void GLES2DecoderImpl::RestoreClearState() {
state_.color_clear_alpha);
glClearStencil(state_.stencil_clear);
glClearDepth(state_.depth_clear);
- if (state_.enable_scissor_test) {
+ if (state_.enable_flags.scissor_test) {
glEnable(GL_SCISSOR_TEST);
}
}
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder_autogen.h b/gpu/command_buffer/service/gles2_cmd_decoder_autogen.h
index 6a1251a..9d406c7 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder_autogen.h
+++ b/gpu/command_buffer/service/gles2_cmd_decoder_autogen.h
@@ -94,7 +94,9 @@ error::Error GLES2DecoderImpl::HandleBlendEquation(
SetGLErrorInvalidEnum("glBlendEquation", mode, "mode");
return error::kNoError;
}
- DoBlendEquation(mode);
+ state_.blend_equation_rgb = mode;
+ state_.blend_equation_alpha = mode;
+ glBlendEquation(mode);
return error::kNoError;
}
@@ -128,7 +130,11 @@ error::Error GLES2DecoderImpl::HandleBlendFunc(
SetGLErrorInvalidEnum("glBlendFunc", dfactor, "dfactor");
return error::kNoError;
}
- DoBlendFunc(sfactor, dfactor);
+ state_.blend_source_rgb = sfactor;
+ state_.blend_dest_rgb = dfactor;
+ state_.blend_source_alpha = sfactor;
+ state_.blend_dest_alpha = dfactor;
+ glBlendFunc(sfactor, dfactor);
return error::kNoError;
}
@@ -265,7 +271,6 @@ error::Error GLES2DecoderImpl::HandleColorMask(
state_.color_mask_green = green;
state_.color_mask_blue = blue;
state_.color_mask_alpha = alpha;
- clear_state_dirty_ = true;
return error::kNoError;
}
@@ -600,7 +605,6 @@ error::Error GLES2DecoderImpl::HandleDepthMask(
uint32 immediate_data_size, const gles2::DepthMask& c) {
GLboolean flag = static_cast<GLboolean>(c.flag);
state_.depth_mask = flag;
- clear_state_dirty_ = true;
return error::kNoError;
}
@@ -1514,7 +1518,7 @@ error::Error GLES2DecoderImpl::HandleStencilFunc(
SetGLErrorInvalidEnum("glStencilFunc", func, "func");
return error::kNoError;
}
- DoStencilFunc(func, ref, mask);
+ glStencilFunc(func, ref, mask);
return error::kNoError;
}
@@ -1532,14 +1536,16 @@ error::Error GLES2DecoderImpl::HandleStencilFuncSeparate(
SetGLErrorInvalidEnum("glStencilFuncSeparate", func, "func");
return error::kNoError;
}
- DoStencilFuncSeparate(face, func, ref, mask);
+ glStencilFuncSeparate(face, func, ref, mask);
return error::kNoError;
}
error::Error GLES2DecoderImpl::HandleStencilMask(
uint32 immediate_data_size, const gles2::StencilMask& c) {
GLuint mask = static_cast<GLuint>(c.mask);
- DoStencilMask(mask);
+ state_.stencil_front_writemask = mask;
+ state_.stencil_back_writemask = mask;
+ clear_state_dirty_ = true;
return error::kNoError;
}
@@ -1551,7 +1557,13 @@ error::Error GLES2DecoderImpl::HandleStencilMaskSeparate(
SetGLErrorInvalidEnum("glStencilMaskSeparate", face, "face");
return error::kNoError;
}
- DoStencilMaskSeparate(face, mask);
+ if (face == GL_FRONT || face == GL_FRONT_AND_BACK) {
+ state_.stencil_front_writemask = mask;
+ }
+ if (face == GL_BACK || face == GL_FRONT_AND_BACK) {
+ state_.stencil_back_writemask = mask;
+ }
+ clear_state_dirty_ = true;
return error::kNoError;
}
@@ -1572,7 +1584,13 @@ error::Error GLES2DecoderImpl::HandleStencilOp(
SetGLErrorInvalidEnum("glStencilOp", zpass, "zpass");
return error::kNoError;
}
- DoStencilOp(fail, zfail, zpass);
+ state_.stencil_front_fail_op = fail;
+ state_.stencil_front_z_fail_op = zfail;
+ state_.stencil_front_z_pass_op = zpass;
+ state_.stencil_back_fail_op = fail;
+ state_.stencil_back_z_fail_op = zfail;
+ state_.stencil_back_z_pass_op = zpass;
+ glStencilOp(fail, zfail, zpass);
return error::kNoError;
}
@@ -1598,7 +1616,17 @@ error::Error GLES2DecoderImpl::HandleStencilOpSeparate(
SetGLErrorInvalidEnum("glStencilOpSeparate", zpass, "zpass");
return error::kNoError;
}
- DoStencilOpSeparate(face, fail, zfail, zpass);
+ if (face == GL_FRONT || face == GL_FRONT_AND_BACK) {
+ state_.stencil_front_fail_op = fail;
+ state_.stencil_front_z_fail_op = zfail;
+ state_.stencil_front_z_pass_op = zpass;
+ }
+ if (face == GL_BACK || face == GL_FRONT_AND_BACK) {
+ state_.stencil_back_fail_op = fail;
+ state_.stencil_back_z_fail_op = zfail;
+ state_.stencil_back_z_pass_op = zpass;
+ }
+ glStencilOpSeparate(face, fail, zfail, zpass);
return error::kNoError;
}
@@ -2938,5 +2966,372 @@ error::Error GLES2DecoderImpl::HandleReleaseTexImage2DCHROMIUM(
return error::kNoError;
}
+
+bool GLES2DecoderImpl::SetCapabilityState(GLenum cap, bool enabled) {
+ switch (cap) {
+ case GL_BLEND:
+ state_.enable_flags.blend = enabled;
+ return true;
+ case GL_CULL_FACE:
+ state_.enable_flags.cull_face = enabled;
+ return true;
+ case GL_DEPTH_TEST:
+ if (state_.enable_flags.depth_test != enabled) {
+ state_.enable_flags.depth_test = enabled;
+ clear_state_dirty_ = true;
+ }
+ return false;
+ case GL_DITHER:
+ state_.enable_flags.dither = enabled;
+ return true;
+ case GL_POLYGON_OFFSET_FILL:
+ state_.enable_flags.polygon_offset_fill = enabled;
+ return true;
+ case GL_SAMPLE_ALPHA_TO_COVERAGE:
+ state_.enable_flags.sample_alpha_to_coverage = enabled;
+ return true;
+ case GL_SAMPLE_COVERAGE:
+ state_.enable_flags.sample_coverage = enabled;
+ return true;
+ case GL_SCISSOR_TEST:
+ state_.enable_flags.scissor_test = enabled;
+ return true;
+ case GL_STENCIL_TEST:
+ if (state_.enable_flags.stencil_test != enabled) {
+ state_.enable_flags.stencil_test = enabled;
+ clear_state_dirty_ = true;
+ }
+ return false;
+ default:
+ NOTREACHED();
+ return false;
+ }
+}
+
+bool GLES2DecoderImpl::DoIsEnabled(GLenum cap) {
+ switch (cap) {
+ case GL_BLEND:
+ return state_.enable_flags.blend;
+ case GL_CULL_FACE:
+ return state_.enable_flags.cull_face;
+ case GL_DEPTH_TEST:
+ return state_.enable_flags.depth_test;
+ case GL_DITHER:
+ return state_.enable_flags.dither;
+ case GL_POLYGON_OFFSET_FILL:
+ return state_.enable_flags.polygon_offset_fill;
+ case GL_SAMPLE_ALPHA_TO_COVERAGE:
+ return state_.enable_flags.sample_alpha_to_coverage;
+ case GL_SAMPLE_COVERAGE:
+ return state_.enable_flags.sample_coverage;
+ case GL_SCISSOR_TEST:
+ return state_.enable_flags.scissor_test;
+ case GL_STENCIL_TEST:
+ return state_.enable_flags.stencil_test;
+ default:
+ NOTREACHED();
+ return false;
+ }
+}
+
+bool GLES2DecoderImpl::GetState(
+ GLenum pname, GLint* params, GLsizei* num_written) {
+ switch (pname) {
+ case GL_VIEWPORT:
+ *num_written = 4;
+ if (params) {
+ params[0] = state_.viewport_x;
+ params[1] = state_.viewport_y;
+ params[2] = state_.viewport_width;
+ params[3] = state_.viewport_height;
+ }
+ return true;
+ case GL_BLEND_SRC_RGB:
+ *num_written = 1;
+ if (params) {
+ params[0] = state_.blend_source_rgb;
+ }
+ return true;
+ case GL_BLEND_DST_RGB:
+ *num_written = 1;
+ if (params) {
+ params[0] = state_.blend_dest_rgb;
+ }
+ return true;
+ case GL_BLEND_SRC_ALPHA:
+ *num_written = 1;
+ if (params) {
+ params[0] = state_.blend_source_alpha;
+ }
+ return true;
+ case GL_BLEND_DST_ALPHA:
+ *num_written = 1;
+ if (params) {
+ params[0] = state_.blend_dest_alpha;
+ }
+ return true;
+ case GL_LINE_WIDTH:
+ *num_written = 1;
+ if (params) {
+ params[0] = state_.line_width;
+ }
+ return true;
+ case GL_BLEND_COLOR:
+ *num_written = 4;
+ if (params) {
+ params[0] = state_.blend_color_red;
+ params[1] = state_.blend_color_green;
+ params[2] = state_.blend_color_blue;
+ params[3] = state_.blend_color_alpha;
+ }
+ return true;
+ case GL_STENCIL_CLEAR_VALUE:
+ *num_written = 1;
+ if (params) {
+ params[0] = state_.stencil_clear;
+ }
+ return true;
+ case GL_COLOR_WRITEMASK:
+ *num_written = 4;
+ if (params) {
+ params[0] = state_.color_mask_red;
+ params[1] = state_.color_mask_green;
+ params[2] = state_.color_mask_blue;
+ params[3] = state_.color_mask_alpha;
+ }
+ return true;
+ case GL_COLOR_CLEAR_VALUE:
+ *num_written = 4;
+ if (params) {
+ params[0] = state_.color_clear_red;
+ params[1] = state_.color_clear_green;
+ params[2] = state_.color_clear_blue;
+ params[3] = state_.color_clear_alpha;
+ }
+ return true;
+ case GL_DEPTH_RANGE:
+ *num_written = 2;
+ if (params) {
+ params[0] = state_.z_near;
+ params[1] = state_.z_far;
+ }
+ return true;
+ case GL_DEPTH_CLEAR_VALUE:
+ *num_written = 1;
+ if (params) {
+ params[0] = state_.depth_clear;
+ }
+ return true;
+ case GL_STENCIL_FAIL:
+ *num_written = 1;
+ if (params) {
+ params[0] = state_.stencil_front_fail_op;
+ }
+ return true;
+ case GL_STENCIL_PASS_DEPTH_FAIL:
+ *num_written = 1;
+ if (params) {
+ params[0] = state_.stencil_front_z_fail_op;
+ }
+ return true;
+ case GL_STENCIL_PASS_DEPTH_PASS:
+ *num_written = 1;
+ if (params) {
+ params[0] = state_.stencil_front_z_pass_op;
+ }
+ return true;
+ case GL_STENCIL_BACK_FAIL:
+ *num_written = 1;
+ if (params) {
+ params[0] = state_.stencil_back_fail_op;
+ }
+ return true;
+ case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
+ *num_written = 1;
+ if (params) {
+ params[0] = state_.stencil_back_z_fail_op;
+ }
+ return true;
+ case GL_STENCIL_BACK_PASS_DEPTH_PASS:
+ *num_written = 1;
+ if (params) {
+ params[0] = state_.stencil_back_z_pass_op;
+ }
+ return true;
+ case GL_SCISSOR_BOX:
+ *num_written = 4;
+ if (params) {
+ params[0] = state_.scissor_x;
+ params[1] = state_.scissor_y;
+ params[2] = state_.scissor_width;
+ params[3] = state_.scissor_height;
+ }
+ return true;
+ case GL_FRONT_FACE:
+ *num_written = 1;
+ if (params) {
+ params[0] = state_.front_face;
+ }
+ return true;
+ case GL_SAMPLE_COVERAGE_VALUE:
+ *num_written = 1;
+ if (params) {
+ params[0] = state_.sample_coverage_value;
+ }
+ return true;
+ case GL_SAMPLE_COVERAGE_INVERT:
+ *num_written = 1;
+ if (params) {
+ params[0] = state_.sample_coverage_invert;
+ }
+ return true;
+ case GL_POLYGON_OFFSET_FACTOR:
+ *num_written = 1;
+ if (params) {
+ params[0] = state_.polygon_offset_factor;
+ }
+ return true;
+ case GL_POLYGON_OFFSET_UNITS:
+ *num_written = 1;
+ if (params) {
+ params[0] = state_.polygon_offset_units;
+ }
+ return true;
+ case GL_CULL_FACE_MODE:
+ *num_written = 1;
+ if (params) {
+ params[0] = state_.cull_mode;
+ }
+ return true;
+ case GL_DEPTH_FUNC:
+ *num_written = 1;
+ if (params) {
+ params[0] = state_.depth_func;
+ }
+ return true;
+ case GL_STENCIL_FUNC:
+ *num_written = 1;
+ if (params) {
+ params[0] = state_.stencil_front_func;
+ }
+ return true;
+ case GL_STENCIL_REF:
+ *num_written = 1;
+ if (params) {
+ params[0] = state_.stencil_front_ref;
+ }
+ return true;
+ case GL_STENCIL_VALUE_MASK:
+ *num_written = 1;
+ if (params) {
+ params[0] = state_.stencil_front_mask;
+ }
+ return true;
+ case GL_STENCIL_BACK_FUNC:
+ *num_written = 1;
+ if (params) {
+ params[0] = state_.stencil_back_func;
+ }
+ return true;
+ case GL_STENCIL_BACK_REF:
+ *num_written = 1;
+ if (params) {
+ params[0] = state_.stencil_back_ref;
+ }
+ return true;
+ case GL_STENCIL_BACK_VALUE_MASK:
+ *num_written = 1;
+ if (params) {
+ params[0] = state_.stencil_back_mask;
+ }
+ return true;
+ case GL_DEPTH_WRITEMASK:
+ *num_written = 1;
+ if (params) {
+ params[0] = state_.depth_mask;
+ }
+ return true;
+ case GL_BLEND_EQUATION_RGB:
+ *num_written = 1;
+ if (params) {
+ params[0] = state_.blend_equation_rgb;
+ }
+ return true;
+ case GL_BLEND_EQUATION_ALPHA:
+ *num_written = 1;
+ if (params) {
+ params[0] = state_.blend_equation_alpha;
+ }
+ return true;
+ case GL_STENCIL_WRITEMASK:
+ *num_written = 1;
+ if (params) {
+ params[0] = state_.stencil_front_writemask;
+ }
+ return true;
+ case GL_STENCIL_BACK_WRITEMASK:
+ *num_written = 1;
+ if (params) {
+ params[0] = state_.stencil_back_writemask;
+ }
+ return true;
+ case GL_BLEND:
+ *num_written = 1;
+ if (params) {
+ params[0] = state_.enable_flags.blend;
+ }
+ return true;
+ case GL_CULL_FACE:
+ *num_written = 1;
+ if (params) {
+ params[0] = state_.enable_flags.cull_face;
+ }
+ return true;
+ case GL_DEPTH_TEST:
+ *num_written = 1;
+ if (params) {
+ params[0] = state_.enable_flags.depth_test;
+ }
+ return true;
+ case GL_DITHER:
+ *num_written = 1;
+ if (params) {
+ params[0] = state_.enable_flags.dither;
+ }
+ return true;
+ case GL_POLYGON_OFFSET_FILL:
+ *num_written = 1;
+ if (params) {
+ params[0] = state_.enable_flags.polygon_offset_fill;
+ }
+ return true;
+ case GL_SAMPLE_ALPHA_TO_COVERAGE:
+ *num_written = 1;
+ if (params) {
+ params[0] = state_.enable_flags.sample_alpha_to_coverage;
+ }
+ return true;
+ case GL_SAMPLE_COVERAGE:
+ *num_written = 1;
+ if (params) {
+ params[0] = state_.enable_flags.sample_coverage;
+ }
+ return true;
+ case GL_SCISSOR_TEST:
+ *num_written = 1;
+ if (params) {
+ params[0] = state_.enable_flags.scissor_test;
+ }
+ return true;
+ case GL_STENCIL_TEST:
+ *num_written = 1;
+ if (params) {
+ params[0] = state_.enable_flags.stencil_test;
+ }
+ return true;
+ default:
+ return false;
+ }
+}
#endif // GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_DECODER_AUTOGEN_H_
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_0_autogen.h b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_0_autogen.h
new file mode 100644
index 0000000..54eb68b
--- /dev/null
+++ b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_0_autogen.h
@@ -0,0 +1,99 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// This file is auto-generated from
+// gpu/command_buffer/build_gles2_cmd_buffer.py
+// DO NOT EDIT!
+
+// It is included by gles2_cmd_decoder_unittest_base.cc
+#ifndef GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_DECODER_UNITTEST_0_AUTOGEN_H_
+#define GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_DECODER_UNITTEST_0_AUTOGEN_H_
+
+void GLES2DecoderTestBase::SetupInitCapabilitiesExpectations() {
+ ExpectEnableDisable(GL_BLEND, false);
+ ExpectEnableDisable(GL_CULL_FACE, false);
+ ExpectEnableDisable(GL_DEPTH_TEST, false);
+ ExpectEnableDisable(GL_DITHER, true);
+ ExpectEnableDisable(GL_POLYGON_OFFSET_FILL, false);
+ ExpectEnableDisable(GL_SAMPLE_ALPHA_TO_COVERAGE, false);
+ ExpectEnableDisable(GL_SAMPLE_COVERAGE, false);
+ ExpectEnableDisable(GL_SCISSOR_TEST, false);
+ ExpectEnableDisable(GL_STENCIL_TEST, false);
+}
+
+void GLES2DecoderTestBase::SetupInitStateExpectations() {
+ EXPECT_CALL(*gl_, BlendColor(0.0f, 0.0f, 0.0f, 0.0f))
+ .Times(1)
+ .RetiresOnSaturation();
+ EXPECT_CALL(*gl_, BlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD))
+ .Times(1)
+ .RetiresOnSaturation();
+ EXPECT_CALL(*gl_, BlendFuncSeparate(GL_ONE, GL_ZERO, GL_ONE, GL_ZERO))
+ .Times(1)
+ .RetiresOnSaturation();
+ EXPECT_CALL(*gl_, ClearColor(0.0f, 0.0f, 0.0f, 0.0f))
+ .Times(1)
+ .RetiresOnSaturation();
+ EXPECT_CALL(*gl_, ClearDepth(1.0f))
+ .Times(1)
+ .RetiresOnSaturation();
+ EXPECT_CALL(*gl_, ClearStencil(0))
+ .Times(1)
+ .RetiresOnSaturation();
+ EXPECT_CALL(*gl_, ColorMask(true, true, true, true))
+ .Times(1)
+ .RetiresOnSaturation();
+ EXPECT_CALL(*gl_, CullFace(GL_BACK))
+ .Times(1)
+ .RetiresOnSaturation();
+ EXPECT_CALL(*gl_, DepthFunc(GL_LESS))
+ .Times(1)
+ .RetiresOnSaturation();
+ EXPECT_CALL(*gl_, DepthMask(true))
+ .Times(1)
+ .RetiresOnSaturation();
+ EXPECT_CALL(*gl_, DepthRange(0.0f, 1.0f))
+ .Times(1)
+ .RetiresOnSaturation();
+ EXPECT_CALL(*gl_, FrontFace(GL_CCW))
+ .Times(1)
+ .RetiresOnSaturation();
+ EXPECT_CALL(*gl_, LineWidth(1.0f))
+ .Times(1)
+ .RetiresOnSaturation();
+ EXPECT_CALL(*gl_, PolygonOffset(0.0f, 0.0f))
+ .Times(1)
+ .RetiresOnSaturation();
+ EXPECT_CALL(*gl_, SampleCoverage(0.0f, false))
+ .Times(1)
+ .RetiresOnSaturation();
+ EXPECT_CALL(
+ *gl_, Scissor(kViewportX, kViewportY, kViewportWidth, kViewportHeight))
+ .Times(1)
+ .RetiresOnSaturation();
+ EXPECT_CALL(*gl_, StencilFuncSeparate(GL_FRONT, GL_ALWAYS, 0, 0xFFFFFFFFU))
+ .Times(1)
+ .RetiresOnSaturation();
+ EXPECT_CALL(*gl_, StencilFuncSeparate(GL_BACK, GL_ALWAYS, 0, 0xFFFFFFFFU))
+ .Times(1)
+ .RetiresOnSaturation();
+ EXPECT_CALL(*gl_, StencilMaskSeparate(GL_FRONT, 0xFFFFFFFFU))
+ .Times(1)
+ .RetiresOnSaturation();
+ EXPECT_CALL(*gl_, StencilMaskSeparate(GL_BACK, 0xFFFFFFFFU))
+ .Times(1)
+ .RetiresOnSaturation();
+ EXPECT_CALL(*gl_, StencilOpSeparate(GL_FRONT, GL_KEEP, GL_KEEP, GL_KEEP))
+ .Times(1)
+ .RetiresOnSaturation();
+ EXPECT_CALL(*gl_, StencilOpSeparate(GL_BACK, GL_KEEP, GL_KEEP, GL_KEEP))
+ .Times(1)
+ .RetiresOnSaturation();
+ EXPECT_CALL(
+ *gl_, Viewport(kViewportX, kViewportY, kViewportWidth, kViewportHeight))
+ .Times(1)
+ .RetiresOnSaturation();
+}
+#endif // GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_DECODER_UNITTEST_0_AUTOGEN_H_
+
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_1_autogen.h b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_1_autogen.h
index 0d5539b..8e2a919 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_1_autogen.h
+++ b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_1_autogen.h
@@ -680,10 +680,10 @@ TEST_F(GLES2DecoderTest1, DetachShaderValidArgs) {
}
TEST_F(GLES2DecoderTest1, DisableValidArgs) {
- EXPECT_CALL(*gl_, Disable(GL_DITHER));
+ EXPECT_CALL(*gl_, Disable(GL_BLEND));
SpecializedSetup<Disable, 0>(true);
Disable cmd;
- cmd.Init(GL_DITHER);
+ cmd.Init(GL_BLEND);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
}
@@ -720,10 +720,10 @@ TEST_F(GLES2DecoderTest1, DisableVertexAttribArrayValidArgs) {
TEST_F(GLES2DecoderTest1, EnableValidArgs) {
- EXPECT_CALL(*gl_, Enable(GL_DITHER));
+ EXPECT_CALL(*gl_, Enable(GL_BLEND));
SpecializedSetup<Enable, 0>(true);
Enable cmd;
- cmd.Init(GL_DITHER);
+ cmd.Init(GL_BLEND);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
}
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_2_autogen.h b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_2_autogen.h
index 939ef93..173f515 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_2_autogen.h
+++ b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_2_autogen.h
@@ -93,7 +93,7 @@ TEST_F(GLES2DecoderTest2, IsBufferInvalidArgsBadSharedMemoryId) {
TEST_F(GLES2DecoderTest2, IsEnabledValidArgs) {
SpecializedSetup<IsEnabled, 0>(true);
IsEnabled cmd;
- cmd.Init(GL_DITHER, shared_memory_id_, shared_memory_offset_);
+ cmd.Init(GL_BLEND, shared_memory_id_, shared_memory_offset_);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
}
@@ -119,9 +119,9 @@ TEST_F(GLES2DecoderTest2, IsEnabledInvalidArgs0_1) {
TEST_F(GLES2DecoderTest2, IsEnabledInvalidArgsBadSharedMemoryId) {
SpecializedSetup<IsEnabled, 0>(false);
IsEnabled cmd;
- cmd.Init(GL_DITHER, kInvalidSharedMemoryId, shared_memory_offset_);
+ cmd.Init(GL_BLEND, kInvalidSharedMemoryId, shared_memory_offset_);
EXPECT_EQ(error::kOutOfBounds, ExecuteCmd(cmd));
- cmd.Init(GL_DITHER, shared_memory_id_, kInvalidSharedMemoryOffset);
+ cmd.Init(GL_BLEND, shared_memory_id_, kInvalidSharedMemoryOffset);
EXPECT_EQ(error::kOutOfBounds, ExecuteCmd(cmd));
}
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc
index 108d2ae..83c7e44 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc
+++ b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc
@@ -184,11 +184,6 @@ void GLES2DecoderTestBase::InitDecoder(
.Times(1)
.RetiresOnSaturation();
- EXPECT_CALL(*gl_, Viewport(
- kViewportX, kViewportY, kViewportWidth, kViewportHeight))
- .Times(1)
- .RetiresOnSaturation();
-
static GLint max_viewport_dims[] = {
kMaxViewportWidth,
kMaxViewportHeight
@@ -198,112 +193,18 @@ void GLES2DecoderTestBase::InitDecoder(
max_viewport_dims, max_viewport_dims + arraysize(max_viewport_dims)))
.RetiresOnSaturation();
+ SetupInitCapabilitiesExpectations();
+ SetupInitStateExpectations();
+
EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0))
.Times(1)
.RetiresOnSaturation();
- EXPECT_CALL(*gl_, Disable(GL_BLEND))
- .Times(1)
- .RetiresOnSaturation();
- EXPECT_CALL(*gl_, BlendColor(0.0f, 0.0, 0.0f, 0.0f))
- .Times(1)
- .RetiresOnSaturation();
- EXPECT_CALL(*gl_, BlendFunc(GL_ONE, GL_ZERO))
- .Times(1)
- .RetiresOnSaturation();
- EXPECT_CALL(*gl_, BlendFuncSeparate(GL_ONE, GL_ZERO, GL_ONE, GL_ZERO))
- .Times(1)
- .RetiresOnSaturation();
- EXPECT_CALL(*gl_, BlendEquation(GL_FUNC_ADD))
- .Times(1)
- .RetiresOnSaturation();
- EXPECT_CALL(*gl_, BlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD))
- .Times(1)
- .RetiresOnSaturation();
- EXPECT_CALL(*gl_, ClearColor(0.0f, 0.0, 0.0f, 0.0f))
- .Times(1)
- .RetiresOnSaturation();
- EXPECT_CALL(*gl_, ColorMask(true, true, true, true))
- .Times(1)
- .RetiresOnSaturation();
- EXPECT_CALL(*gl_, Disable(GL_CULL_FACE))
- .Times(1)
- .RetiresOnSaturation();
- EXPECT_CALL(*gl_, CullFace(GL_BACK))
- .Times(1)
- .RetiresOnSaturation();
- EXPECT_CALL(*gl_, ClearDepth(1.0f))
- .Times(1)
- .RetiresOnSaturation();
- EXPECT_CALL(*gl_, DepthFunc(GL_LESS))
- .Times(1)
- .RetiresOnSaturation();
- EXPECT_CALL(*gl_, DepthRange(0.0f, 1.0f))
- .Times(1)
- .RetiresOnSaturation();
- EXPECT_CALL(*gl_, Disable(GL_DEPTH_TEST))
- .Times(1)
- .RetiresOnSaturation();
- EXPECT_CALL(*gl_, Enable(GL_DITHER))
- .Times(1)
- .RetiresOnSaturation();
- EXPECT_CALL(*gl_, FrontFace(GL_CCW))
- .Times(1)
- .RetiresOnSaturation();
EXPECT_CALL(*gl_, Hint(GL_GENERATE_MIPMAP_HINT, GL_DONT_CARE))
.Times(1)
.RetiresOnSaturation();
- EXPECT_CALL(*gl_, LineWidth(1.0f))
- .Times(1)
- .RetiresOnSaturation();
EXPECT_CALL(*gl_, PixelStorei(GL_PACK_ALIGNMENT, 4))
.Times(1)
.RetiresOnSaturation();
- EXPECT_CALL(*gl_, PolygonOffset(0.0f, 0.0f))
- .Times(1)
- .RetiresOnSaturation();
- EXPECT_CALL(*gl_, Disable(GL_POLYGON_OFFSET_FILL))
- .Times(1)
- .RetiresOnSaturation();
- EXPECT_CALL(*gl_, Disable(GL_SAMPLE_ALPHA_TO_COVERAGE))
- .Times(1)
- .RetiresOnSaturation();
- EXPECT_CALL(*gl_, Disable(GL_SAMPLE_COVERAGE))
- .Times(1)
- .RetiresOnSaturation();
- EXPECT_CALL(*gl_, SampleCoverage(1.0, false))
- .Times(1)
- .RetiresOnSaturation();
- EXPECT_CALL(*gl_, Scissor(
- kViewportX, kViewportY, kViewportWidth, kViewportHeight))
- .Times(1)
- .RetiresOnSaturation();
- EXPECT_CALL(*gl_, Disable(GL_SCISSOR_TEST))
- .Times(1)
- .RetiresOnSaturation();
- EXPECT_CALL(*gl_, Disable(GL_STENCIL_TEST))
- .Times(1)
- .RetiresOnSaturation();
- EXPECT_CALL(*gl_, ClearStencil(0))
- .Times(1)
- .RetiresOnSaturation();
- EXPECT_CALL(*gl_, StencilFuncSeparate(GL_FRONT, GL_ALWAYS, 0, 0xFFFFFFFFU))
- .Times(1)
- .RetiresOnSaturation();
- EXPECT_CALL(*gl_, StencilFuncSeparate(GL_BACK, GL_ALWAYS, 0, 0xFFFFFFFFU))
- .Times(1)
- .RetiresOnSaturation();
- EXPECT_CALL(*gl_, StencilOpSeparate(GL_FRONT, GL_KEEP, GL_KEEP, GL_KEEP))
- .Times(1)
- .RetiresOnSaturation();
- EXPECT_CALL(*gl_, StencilOpSeparate(GL_BACK, GL_KEEP, GL_KEEP, GL_KEEP))
- .Times(1)
- .RetiresOnSaturation();
- EXPECT_CALL(*gl_, StencilMaskSeparate(GL_FRONT, 0xFFFFFFFFU))
- .Times(1)
- .RetiresOnSaturation();
- EXPECT_CALL(*gl_, StencilMaskSeparate(GL_BACK, 0xFFFFFFFFU))
- .Times(1)
- .RetiresOnSaturation();
EXPECT_CALL(*gl_, PixelStorei(GL_UNPACK_ALIGNMENT, 4))
.Times(1)
.RetiresOnSaturation();
@@ -399,6 +300,19 @@ void GLES2DecoderTestBase::TearDown() {
gl_.reset();
}
+void GLES2DecoderTestBase::ExpectEnableDisable(GLenum cap, bool enable) {
+ if (enable) {
+ EXPECT_CALL(*gl_, Enable(cap))
+ .Times(1)
+ .RetiresOnSaturation();
+ } else {
+ EXPECT_CALL(*gl_, Disable(cap))
+ .Times(1)
+ .RetiresOnSaturation();
+ }
+}
+
+
GLint GLES2DecoderTestBase::GetGLError() {
EXPECT_CALL(*gl_, GetError())
.WillOnce(Return(GL_NO_ERROR))
@@ -1459,5 +1373,10 @@ void GLES2DecoderWithShaderTestBase::SetUp() {
SetupDefaultProgram();
}
+// Include the auto-generated part of this file. We split this because it means
+// we can easily edit the non-auto generated parts right here in this file
+// instead of having to edit some template or the code generator.
+#include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_0_autogen.h"
+
} // namespace gles2
} // namespace gpu
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h
index f2fd38b..351d081 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h
+++ b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h
@@ -178,6 +178,10 @@ class GLES2DecoderTestBase : public testing::Test {
gl_.get(), uniforms, num_uniforms);
}
+ void SetupInitCapabilitiesExpectations();
+ void SetupInitStateExpectations();
+ void ExpectEnableDisable(GLenum cap, bool enable);
+
// Setups up a shader for testing glUniform.
void SetupShaderForUniform();
void SetupDefaultProgram();
diff --git a/gpu/command_buffer/service/gles2_cmd_validation_implementation_autogen.h b/gpu/command_buffer/service/gles2_cmd_validation_implementation_autogen.h
index 48eb54e..9f1dece 100644
--- a/gpu/command_buffer/service/gles2_cmd_validation_implementation_autogen.h
+++ b/gpu/command_buffer/service/gles2_cmd_validation_implementation_autogen.h
@@ -37,10 +37,10 @@ static GLenum valid_buffer_usage_table[] = {
};
static GLenum valid_capability_table[] = {
- GL_DITHER,
GL_BLEND,
GL_CULL_FACE,
GL_DEPTH_TEST,
+ GL_DITHER,
GL_POLYGON_OFFSET_FILL,
GL_SAMPLE_ALPHA_TO_COVERAGE,
GL_SAMPLE_COVERAGE,
@@ -124,36 +124,17 @@ static GLenum valid_g_l_state_table[] = {
GL_ALIASED_POINT_SIZE_RANGE,
GL_ALPHA_BITS,
GL_ARRAY_BUFFER_BINDING,
- GL_BLEND,
- GL_BLEND_COLOR,
- GL_BLEND_DST_ALPHA,
- GL_BLEND_DST_RGB,
- GL_BLEND_EQUATION_ALPHA,
- GL_BLEND_EQUATION_RGB,
- GL_BLEND_SRC_ALPHA,
- GL_BLEND_SRC_RGB,
GL_BLUE_BITS,
- GL_COLOR_CLEAR_VALUE,
- GL_COLOR_WRITEMASK,
GL_COMPRESSED_TEXTURE_FORMATS,
- GL_CULL_FACE,
- GL_CULL_FACE_MODE,
GL_CURRENT_PROGRAM,
GL_DEPTH_BITS,
- GL_DEPTH_CLEAR_VALUE,
- GL_DEPTH_FUNC,
GL_DEPTH_RANGE,
- GL_DEPTH_TEST,
- GL_DEPTH_WRITEMASK,
- GL_DITHER,
GL_ELEMENT_ARRAY_BUFFER_BINDING,
GL_FRAMEBUFFER_BINDING,
- GL_FRONT_FACE,
GL_GENERATE_MIPMAP_HINT,
GL_GREEN_BITS,
GL_IMPLEMENTATION_COLOR_READ_FORMAT,
GL_IMPLEMENTATION_COLOR_READ_TYPE,
- GL_LINE_WIDTH,
GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS,
GL_MAX_CUBE_MAP_TEXTURE_SIZE,
GL_MAX_FRAGMENT_UNIFORM_VECTORS,
@@ -168,9 +149,6 @@ static GLenum valid_g_l_state_table[] = {
GL_NUM_COMPRESSED_TEXTURE_FORMATS,
GL_NUM_SHADER_BINARY_FORMATS,
GL_PACK_ALIGNMENT,
- GL_POLYGON_OFFSET_FACTOR,
- GL_POLYGON_OFFSET_FILL,
- GL_POLYGON_OFFSET_UNITS,
GL_RED_BITS,
GL_RENDERBUFFER_BINDING,
GL_SAMPLE_BUFFERS,
@@ -178,27 +156,10 @@ static GLenum valid_g_l_state_table[] = {
GL_SAMPLE_COVERAGE_VALUE,
GL_SAMPLES,
GL_SCISSOR_BOX,
- GL_SCISSOR_TEST,
GL_SHADER_BINARY_FORMATS,
GL_SHADER_COMPILER,
- GL_STENCIL_BACK_FAIL,
- GL_STENCIL_BACK_FUNC,
- GL_STENCIL_BACK_PASS_DEPTH_FAIL,
- GL_STENCIL_BACK_PASS_DEPTH_PASS,
- GL_STENCIL_BACK_REF,
- GL_STENCIL_BACK_VALUE_MASK,
- GL_STENCIL_BACK_WRITEMASK,
- GL_STENCIL_BITS,
- GL_STENCIL_CLEAR_VALUE,
- GL_STENCIL_FAIL,
- GL_STENCIL_FUNC,
- GL_STENCIL_PASS_DEPTH_FAIL,
- GL_STENCIL_PASS_DEPTH_PASS,
- GL_STENCIL_REF,
- GL_STENCIL_TEST,
- GL_STENCIL_VALUE_MASK,
- GL_STENCIL_WRITEMASK,
GL_SUBPIXEL_BITS,
+ GL_STENCIL_BITS,
GL_TEXTURE_BINDING_2D,
GL_TEXTURE_BINDING_CUBE_MAP,
GL_UNPACK_ALIGNMENT,
@@ -206,6 +167,52 @@ static GLenum valid_g_l_state_table[] = {
GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM,
GL_UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM,
GL_VIEWPORT,
+ GL_BLEND_COLOR,
+ GL_BLEND_EQUATION_RGB,
+ GL_BLEND_EQUATION_ALPHA,
+ GL_BLEND_SRC_RGB,
+ GL_BLEND_DST_RGB,
+ GL_BLEND_SRC_ALPHA,
+ GL_BLEND_DST_ALPHA,
+ GL_COLOR_CLEAR_VALUE,
+ GL_DEPTH_CLEAR_VALUE,
+ GL_STENCIL_CLEAR_VALUE,
+ GL_COLOR_WRITEMASK,
+ GL_CULL_FACE_MODE,
+ GL_DEPTH_FUNC,
+ GL_DEPTH_WRITEMASK,
+ GL_DEPTH_RANGE,
+ GL_FRONT_FACE,
+ GL_LINE_WIDTH,
+ GL_POLYGON_OFFSET_FACTOR,
+ GL_POLYGON_OFFSET_UNITS,
+ GL_SAMPLE_COVERAGE_VALUE,
+ GL_SAMPLE_COVERAGE_INVERT,
+ GL_SCISSOR_BOX,
+ GL_STENCIL_FUNC,
+ GL_STENCIL_REF,
+ GL_STENCIL_VALUE_MASK,
+ GL_STENCIL_BACK_FUNC,
+ GL_STENCIL_BACK_REF,
+ GL_STENCIL_BACK_VALUE_MASK,
+ GL_STENCIL_WRITEMASK,
+ GL_STENCIL_BACK_WRITEMASK,
+ GL_STENCIL_FAIL,
+ GL_STENCIL_PASS_DEPTH_FAIL,
+ GL_STENCIL_PASS_DEPTH_PASS,
+ GL_STENCIL_BACK_FAIL,
+ GL_STENCIL_BACK_PASS_DEPTH_FAIL,
+ GL_STENCIL_BACK_PASS_DEPTH_PASS,
+ GL_VIEWPORT,
+ GL_BLEND,
+ GL_CULL_FACE,
+ GL_DEPTH_TEST,
+ GL_DITHER,
+ GL_POLYGON_OFFSET_FILL,
+ GL_SAMPLE_ALPHA_TO_COVERAGE,
+ GL_SAMPLE_COVERAGE,
+ GL_SCISSOR_TEST,
+ GL_STENCIL_TEST,
};
static GLenum valid_get_max_index_type_table[] = {
diff --git a/gpu/command_buffer_service.gypi b/gpu/command_buffer_service.gypi
index 78f4078..89f99a6 100644
--- a/gpu/command_buffer_service.gypi
+++ b/gpu/command_buffer_service.gypi
@@ -35,6 +35,8 @@
'command_buffer/service/context_group.h',
'command_buffer/service/context_group.cc',
'command_buffer/service/context_state.h',
+ 'command_buffer/service/context_state_autogen.h',
+ 'command_buffer/service/context_state_impl_autogen.h',
'command_buffer/service/context_state.cc',
'command_buffer/service/feature_info.h',
'command_buffer/service/feature_info.cc',
diff --git a/gpu/gpu.gyp b/gpu/gpu.gyp
index 86baa0f..6fc592d 100644
--- a/gpu/gpu.gyp
+++ b/gpu/gpu.gyp
@@ -176,6 +176,7 @@
'command_buffer/service/feature_info_unittest.cc',
'command_buffer/service/framebuffer_manager_unittest.cc',
'command_buffer/service/gles2_cmd_decoder_unittest.cc',
+ 'command_buffer/service/gles2_cmd_decoder_unittest_0_autogen.h',
'command_buffer/service/gles2_cmd_decoder_unittest_1.cc',
'command_buffer/service/gles2_cmd_decoder_unittest_1_autogen.h',
'command_buffer/service/gles2_cmd_decoder_unittest_2.cc',