diff options
author | gman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-07 16:41:28 +0000 |
---|---|---|
committer | gman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-07 16:41:28 +0000 |
commit | 4c9abdb7f2f33059a575abd55548b457bcad9fd8 (patch) | |
tree | 18941f301d5c3c4db329916b35f2567b45017efa /gpu | |
parent | 39b9f7eeb2c14ba1188051d3203d18a4664c3e36 (diff) | |
download | chromium_src-4c9abdb7f2f33059a575abd55548b457bcad9fd8.zip chromium_src-4c9abdb7f2f33059a575abd55548b457bcad9fd8.tar.gz chromium_src-4c9abdb7f2f33059a575abd55548b457bcad9fd8.tar.bz2 |
Initialize destinations variables before calling GL functions
because if the context is lost those variables will
be uninitialized.
TEST=ran chrome, conformance tests, unit tests and hand edited gles2_demo to test
BUG=none
Review URL: http://codereview.chromium.org/5254006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68480 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gpu')
-rwxr-xr-x | gpu/command_buffer/build_gles2_cmd_buffer.py | 37 | ||||
-rw-r--r-- | gpu/command_buffer/client/gles2_c_lib.cc | 28 | ||||
-rw-r--r-- | gpu/command_buffer/client/gles2_c_lib_autogen.h | 22 | ||||
-rw-r--r-- | gpu/command_buffer/client/gles2_demo_cc.cc | 8 |
4 files changed, 93 insertions, 2 deletions
diff --git a/gpu/command_buffer/build_gles2_cmd_buffer.py b/gpu/command_buffer/build_gles2_cmd_buffer.py index 01a321f..d6e4661 100755 --- a/gpu/command_buffer/build_gles2_cmd_buffer.py +++ b/gpu/command_buffer/build_gles2_cmd_buffer.py @@ -2145,6 +2145,11 @@ TEST_F(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) { else: self.WriteGLES2ImplementationDeclaration(func, file) + def WriteDestinationInitalizationValidation(self, func, file): + """Writes the client side destintion initialization validation.""" + for arg in func.GetOriginalArgs(): + arg.WriteDestinationInitalizationValidation(file, func) + def WriteImmediateCmdComputeSize(self, func, file): """Writes the size computation code for the immediate version of a cmd.""" file.Write(" static uint32 ComputeSize(uint32 size_in_bytes) {\n") @@ -4000,6 +4005,7 @@ class Argument(object): 'GLfloat': 'float', 'GLclampf': 'float', } + need_validation_ = ['GLsizei*', 'GLboolean*', 'GLenum*', 'GLint*'] def __init__(self, name, type): self.name = name @@ -4049,6 +4055,20 @@ class Argument(object): """Writes the validation code for an argument.""" pass + def WriteDestinationInitalizationValidation(self, file, func): + """Writes the client side destintion initialization validation.""" + pass + + def WriteDestinationInitalizationValidatationIfNeeded(self, file, func): + """Writes the client side destintion initialization validation if needed.""" + parts = self.type.split(" ") + if len(parts) > 1: + return + if parts[0] in self.need_validation_: + file.Write(" GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(%s, %s);\n" % + (self.type[:-1], self.name)) + + def WriteGetAddress(self, file): """Writes the code to get the address this argument refers to.""" pass @@ -4233,6 +4253,10 @@ class ImmediatePointerArgument(Argument): """Overridden from Argument.""" return None + def WriteDestinationInitalizationValidation(self, file, func): + """Overridden from Argument.""" + self.WriteDestinationInitalizationValidatationIfNeeded(file, func) + class BucketPointerArgument(Argument): """A class that represents an bucket argument to a function.""" @@ -4258,6 +4282,10 @@ class BucketPointerArgument(Argument): """Overridden from Argument.""" return None + def WriteDestinationInitalizationValidation(self, file, func): + """Overridden from Argument.""" + self.WriteDestinationInitalizationValidatationIfNeeded(file, func) + class PointerArgument(Argument): """A class that represents a pointer argument to a function.""" @@ -4328,6 +4356,10 @@ class PointerArgument(Argument): return InputStringBucketArgument(self.name, self.type) return BucketPointerArgument(self.name, self.type) + def WriteDestinationInitalizationValidation(self, file, func): + """Overridden from Argument.""" + self.WriteDestinationInitalizationValidatationIfNeeded(file, func) + class InputStringBucketArgument(Argument): """An string input argument where the string is passed in a bucket.""" @@ -4649,6 +4681,10 @@ class Function(object): """Writes the GLES2 Implemention declaration.""" self.type_handler.WriteGLES2ImplementationHeader(self, file) + def WriteDestinationInitalizationValidation(self, file): + """Writes the client side destintion initialization validation.""" + self.type_handler.WriteDestinationInitalizationValidation(self, file) + def WriteFormatTest(self, file): """Writes the cmd's format test.""" self.type_handler.WriteFormatTest(self, file) @@ -5136,6 +5172,7 @@ class GLGenerator(object): file.Write("%s GLES2%s(%s) {\n" % (func.return_type, func.name, func.MakeTypedOriginalArgString(""))) + func.WriteDestinationInitalizationValidation(file) comma = "" if len(func.GetOriginalArgs()): comma = " << " diff --git a/gpu/command_buffer/client/gles2_c_lib.cc b/gpu/command_buffer/client/gles2_c_lib.cc index 74cc431..f53067e 100644 --- a/gpu/command_buffer/client/gles2_c_lib.cc +++ b/gpu/command_buffer/client/gles2_c_lib.cc @@ -4,8 +4,36 @@ // These functions emluate GLES2 over command buffers for C. +#include <assert.h> #include "../client/gles2_lib.h" +// Check that destination pointers point to initialized memory. +// When the context is lost, calling GL function has no effect so if destination +// pointers point to initialized memory it can often lead to crash bugs. eg. +// +// GLsizei len; +// glGetShaderSource(shader, max_size, &len, buffer); +// std::string src(buffer, buffer + len); // len can be uninitialized here!!! +// +// Because this check is not official GL this check happens only on Chrome code, +// not Pepper. +// +// If it was up to us we'd just always write to the destination but the OpenGL +// spec defines the behavior of OpenGL function, not us. :-( +#if defined(__native_client__) + #define GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION_ASSERT(v) +#elif defined(GPU_DCHECK) + #define GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION_ASSERT(v) GPU_DCHECK(v) +#elif defined(DCHECK) + #define GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION_ASSERT(v) DCHECK(v) +#else + #define GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION_ASSERT(v) ASSERT(v) +#endif + +#define GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(type, ptr) \ + GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION_ASSERT(ptr && \ + (ptr[0] == static_cast<type>(0) || ptr[0] == static_cast<type>(-1))); + extern "C" { // 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 diff --git a/gpu/command_buffer/client/gles2_c_lib_autogen.h b/gpu/command_buffer/client/gles2_c_lib_autogen.h index 01cb485..13cf792 100644 --- a/gpu/command_buffer/client/gles2_c_lib_autogen.h +++ b/gpu/command_buffer/client/gles2_c_lib_autogen.h @@ -279,6 +279,9 @@ void GLES2GenTextures(GLsizei n, GLuint* textures) { void GLES2GetActiveAttrib( GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, char* name) { + GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLsizei, length); + GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLint, size); + GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLenum, type); GPU_CLIENT_LOG( "GetActiveAttrib" << "(" << program << ", " << index << ", " << bufsize << ", " << length << ", " << size << ", " << type << ", " << name << ")"); // NOLINT gles2::GetGLContext()->GetActiveAttrib( @@ -287,6 +290,9 @@ void GLES2GetActiveAttrib( void GLES2GetActiveUniform( GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, char* name) { + GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLsizei, length); + GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLint, size); + GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLenum, type); GPU_CLIENT_LOG( "GetActiveUniform" << "(" << program << ", " << index << ", " << bufsize << ", " << length << ", " << size << ", " << type << ", " << name << ")"); // NOLINT gles2::GetGLContext()->GetActiveUniform( @@ -294,6 +300,7 @@ void GLES2GetActiveUniform( } void GLES2GetAttachedShaders( GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders) { + GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLsizei, count); GPU_CLIENT_LOG( "GetAttachedShaders" << "(" << program << ", " << maxcount << ", " << count << ", " << shaders << ")"); // NOLINT gles2::GetGLContext()->GetAttachedShaders(program, maxcount, count, shaders); @@ -305,10 +312,12 @@ GLint GLES2GetAttribLocation(GLuint program, const char* name) { return result; } void GLES2GetBooleanv(GLenum pname, GLboolean* params) { + GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLboolean, params); GPU_CLIENT_LOG("GetBooleanv" << "(" << pname << ", " << params << ")"); gles2::GetGLContext()->GetBooleanv(pname, params); } void GLES2GetBufferParameteriv(GLenum target, GLenum pname, GLint* params) { + GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLint, params); GPU_CLIENT_LOG( "GetBufferParameteriv" << "(" << target << ", " << pname << ", " << params << ")"); // NOLINT gles2::GetGLContext()->GetBufferParameteriv(target, pname, params); @@ -325,45 +334,54 @@ void GLES2GetFloatv(GLenum pname, GLfloat* params) { } void GLES2GetFramebufferAttachmentParameteriv( GLenum target, GLenum attachment, GLenum pname, GLint* params) { + GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLint, params); GPU_CLIENT_LOG( "GetFramebufferAttachmentParameteriv" << "(" << target << ", " << attachment << ", " << pname << ", " << params << ")"); // NOLINT gles2::GetGLContext()->GetFramebufferAttachmentParameteriv( target, attachment, pname, params); } void GLES2GetIntegerv(GLenum pname, GLint* params) { + GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLint, params); GPU_CLIENT_LOG("GetIntegerv" << "(" << pname << ", " << params << ")"); gles2::GetGLContext()->GetIntegerv(pname, params); } void GLES2GetProgramiv(GLuint program, GLenum pname, GLint* params) { + GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLint, params); GPU_CLIENT_LOG( "GetProgramiv" << "(" << program << ", " << pname << ", " << params << ")"); // NOLINT gles2::GetGLContext()->GetProgramiv(program, pname, params); } void GLES2GetProgramInfoLog( GLuint program, GLsizei bufsize, GLsizei* length, char* infolog) { + GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLsizei, length); GPU_CLIENT_LOG( "GetProgramInfoLog" << "(" << program << ", " << bufsize << ", " << length << ", " << infolog << ")"); // NOLINT gles2::GetGLContext()->GetProgramInfoLog(program, bufsize, length, infolog); } void GLES2GetRenderbufferParameteriv( GLenum target, GLenum pname, GLint* params) { + GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLint, params); GPU_CLIENT_LOG( "GetRenderbufferParameteriv" << "(" << target << ", " << pname << ", " << params << ")"); // NOLINT gles2::GetGLContext()->GetRenderbufferParameteriv(target, pname, params); } void GLES2GetShaderiv(GLuint shader, GLenum pname, GLint* params) { + GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLint, params); GPU_CLIENT_LOG( "GetShaderiv" << "(" << shader << ", " << pname << ", " << params << ")"); gles2::GetGLContext()->GetShaderiv(shader, pname, params); } void GLES2GetShaderInfoLog( GLuint shader, GLsizei bufsize, GLsizei* length, char* infolog) { + GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLsizei, length); GPU_CLIENT_LOG( "GetShaderInfoLog" << "(" << shader << ", " << bufsize << ", " << length << ", " << infolog << ")"); // NOLINT gles2::GetGLContext()->GetShaderInfoLog(shader, bufsize, length, infolog); } void GLES2GetShaderPrecisionFormat( GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision) { + GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLint, range); + GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLint, precision); GPU_CLIENT_LOG( "GetShaderPrecisionFormat" << "(" << shadertype << ", " << precisiontype << ", " << range << ", " << precision << ")"); // NOLINT gles2::GetGLContext()->GetShaderPrecisionFormat( @@ -371,6 +389,7 @@ void GLES2GetShaderPrecisionFormat( } void GLES2GetShaderSource( GLuint shader, GLsizei bufsize, GLsizei* length, char* source) { + GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLsizei, length); GPU_CLIENT_LOG( "GetShaderSource" << "(" << shader << ", " << bufsize << ", " << length << ", " << source << ")"); // NOLINT gles2::GetGLContext()->GetShaderSource(shader, bufsize, length, source); @@ -387,6 +406,7 @@ void GLES2GetTexParameterfv(GLenum target, GLenum pname, GLfloat* params) { gles2::GetGLContext()->GetTexParameterfv(target, pname, params); } void GLES2GetTexParameteriv(GLenum target, GLenum pname, GLint* params) { + GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLint, params); GPU_CLIENT_LOG( "GetTexParameteriv" << "(" << target << ", " << pname << ", " << params << ")"); // NOLINT gles2::GetGLContext()->GetTexParameteriv(target, pname, params); @@ -397,6 +417,7 @@ void GLES2GetUniformfv(GLuint program, GLint location, GLfloat* params) { gles2::GetGLContext()->GetUniformfv(program, location, params); } void GLES2GetUniformiv(GLuint program, GLint location, GLint* params) { + GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLint, params); GPU_CLIENT_LOG( "GetUniformiv" << "(" << program << ", " << location << ", " << params << ")"); // NOLINT gles2::GetGLContext()->GetUniformiv(program, location, params); @@ -414,6 +435,7 @@ void GLES2GetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params) { gles2::GetGLContext()->GetVertexAttribfv(index, pname, params); } void GLES2GetVertexAttribiv(GLuint index, GLenum pname, GLint* params) { + GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLint, params); GPU_CLIENT_LOG( "GetVertexAttribiv" << "(" << index << ", " << pname << ", " << params << ")"); // NOLINT gles2::GetGLContext()->GetVertexAttribiv(index, pname, params); diff --git a/gpu/command_buffer/client/gles2_demo_cc.cc b/gpu/command_buffer/client/gles2_demo_cc.cc index cb33f8c..e271a0f 100644 --- a/gpu/command_buffer/client/gles2_demo_cc.cc +++ b/gpu/command_buffer/client/gles2_demo_cc.cc @@ -47,7 +47,7 @@ GLuint LoadShader(GLenum type, const char* shaderSrc) { // Compile the shader glCompileShader(shader); // Check the compile status - GLint value; + GLint value = 0; glGetShaderiv(shader, GL_COMPILE_STATUS, &value); if (value == 0) { char buffer[1024]; @@ -100,7 +100,7 @@ void InitShaders() { // Link the program glLinkProgram(programObject); // Check the link status - GLint linked; + GLint linked = 0; glGetProgramiv(programObject, GL_LINK_STATUS, &linked); if (linked == 0) { char buffer[1024]; @@ -173,6 +173,10 @@ void GLFromCPPInit() { g_texture = CreateCheckerboardTexture(); InitShaders(); CheckGLError("GLFromCPPInit", __LINE__); + + char buf[128]; + glReadPixels(0, 0, 1, 1, 0, 0, buf); + CheckGLError("GLFromCPPInit:ReadPixels", __LINE__); } void GLFromCPPDraw() { |