diff options
author | gman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-27 00:48:03 +0000 |
---|---|---|
committer | gman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-27 00:48:03 +0000 |
commit | ae51d195b0e1bfaba2243f005a1aba675395595f (patch) | |
tree | d6990cd30404b49ad0b01db2126f971b601a94d6 /gpu/command_buffer | |
parent | 4b3540935a9769fb1634483027b70ee763ee431e (diff) | |
download | chromium_src-ae51d195b0e1bfaba2243f005a1aba675395595f.zip chromium_src-ae51d195b0e1bfaba2243f005a1aba675395595f.tar.gz chromium_src-ae51d195b0e1bfaba2243f005a1aba675395595f.tar.bz2 |
Changes the code to use separate ids namspaces
for buffers, textures, programs, etc.. This is
needed to pass GLES2 conformance tests.
TEST=old unit tests
BUG=none
Review URL: http://codereview.chromium.org/1747013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@45654 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gpu/command_buffer')
33 files changed, 903 insertions, 1013 deletions
diff --git a/gpu/command_buffer/build_gles2_cmd_buffer.py b/gpu/command_buffer/build_gles2_cmd_buffer.py index 67f683a..64e9539 100755 --- a/gpu/command_buffer/build_gles2_cmd_buffer.py +++ b/gpu/command_buffer/build_gles2_cmd_buffer.py @@ -116,11 +116,11 @@ GL_APICALL void GL_APIENTRY glGetVertexAttribPointerv (GLuint index, GLe GL_APICALL void GL_APIENTRY glHint (GLenumHintTarget target, GLenumHintMode mode); GL_APICALL GLboolean GL_APIENTRY glIsBuffer (GLidBuffer buffer); GL_APICALL GLboolean GL_APIENTRY glIsEnabled (GLenumCapability cap); -GL_APICALL GLboolean GL_APIENTRY glIsFramebuffer (GLuint framebuffer); -GL_APICALL GLboolean GL_APIENTRY glIsProgram (GLuint program); -GL_APICALL GLboolean GL_APIENTRY glIsRenderbuffer (GLuint renderbuffer); -GL_APICALL GLboolean GL_APIENTRY glIsShader (GLuint shader); -GL_APICALL GLboolean GL_APIENTRY glIsTexture (GLuint texture); +GL_APICALL GLboolean GL_APIENTRY glIsFramebuffer (GLidFramebuffer framebuffer); +GL_APICALL GLboolean GL_APIENTRY glIsProgram (GLidProgram program); +GL_APICALL GLboolean GL_APIENTRY glIsRenderbuffer (GLidRenderbuffer renderbuffer); +GL_APICALL GLboolean GL_APIENTRY glIsShader (GLidShader shader); +GL_APICALL GLboolean GL_APIENTRY glIsTexture (GLidTexture texture); GL_APICALL void GL_APIENTRY glLineWidth (GLfloat width); GL_APICALL void GL_APIENTRY glLinkProgram (GLidProgram program); GL_APICALL void GL_APIENTRY glPixelStorei (GLenumPixelStore pname, GLintPixelStoreAlignment param); @@ -958,6 +958,7 @@ _ENUM_LISTS = { _FUNCTION_INFO = { 'ActiveTexture': {'decoder_func': 'DoActiveTexture', 'unit_test': False}, + 'AttachShader': {'decoder_func': 'DoAttachShader'}, 'BindAttribLocation': {'type': 'GLchar', 'bucket': True, 'needs_size': True}, 'BindBuffer': { 'type': 'Bind', @@ -1013,6 +1014,7 @@ _FUNCTION_INFO = { 'DeleteShader': {'type': 'Custom', 'decoder_func': 'DoDeleteShader'}, 'DeleteTextures': {'type': 'DELn'}, 'DepthRangef': {'decoder_func': 'glDepthRange'}, + 'DetachShader': {'decoder_func': 'DoDetachShader'}, 'DisableVertexAttribArray': { 'decoder_func': 'DoDisableVertexAttribArray', 'impl_decl': False, @@ -1130,7 +1132,7 @@ _FUNCTION_INFO = { 'type': 'STRn', 'get_len_func': 'glGetProgramiv', 'get_len_enum': 'GL_INFO_LOG_LENGTH', - }, + }, 'GetRenderbufferParameteriv': { 'type': 'GETn', 'decoder_func': 'DoGetRenderbufferParameteriv', @@ -1162,7 +1164,6 @@ _FUNCTION_INFO = { }, 'GetShaderSource': { 'type': 'STRn', - 'decoder_func': 'DoGetShaderSource', 'get_len_func': 'DoGetShaderiv', 'get_len_enum': 'GL_SHADER_SOURCE_LENGTH', 'unit_test': False, @@ -1311,6 +1312,7 @@ _FUNCTION_INFO = { 'UniformMatrix3fv': {'type': 'PUTn', 'data_type': 'GLfloat', 'count': 9}, 'UniformMatrix4fv': {'type': 'PUTn', 'data_type': 'GLfloat', 'count': 16}, 'UseProgram': {'decoder_func': 'DoUseProgram', 'unit_test': False}, + 'ValidateProgram': {'decoder_func': 'DoValidateProgram'}, 'VertexAttrib1fv': {'type': 'PUT', 'data_type': 'GLfloat', 'count': 1}, 'VertexAttrib2fv': {'type': 'PUT', 'data_type': 'GLfloat', 'count': 2}, 'VertexAttrib3fv': {'type': 'PUT', 'data_type': 'GLfloat', 'count': 3}, @@ -2161,8 +2163,7 @@ TEST_F(%(test_name)s, %(name)sValidArgsNewId) { cmd.Init(%(first_arg)s, kNewClientId); EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); EXPECT_EQ(GL_NO_ERROR, GetGLError()); - EXPECT_EQ(GetServiceId(kNewClientId), kNewServiceId); - EXPECT_TRUE(Get%(resource_type)sInfo(kNewServiceId) != NULL); + EXPECT_TRUE(Get%(resource_type)sInfo(kNewClientId) != NULL); } """ gen_func_names = { @@ -2197,12 +2198,12 @@ TEST_F(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) { func.MakeTypedOriginalArgString(""))) for arg in func.GetOriginalArgs(): arg.WriteClientSideValidationCode(file) - code = """ if (IsReservedId(%(id)s)) { + code = """ if (Is%(type)sReservedId(%(id)s)) { SetGLError(GL_INVALID_OPERATION); return; } if (%(id)s != 0) { - id_allocator_.MarkAsUsed(%(id)s); + %(lc_type)s_id_allocator_.MarkAsUsed(%(id)s); } helper_->%(name)s(%(arg_string)s); } @@ -2212,6 +2213,8 @@ TEST_F(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) { 'name': func.name, 'arg_string': func.MakeOriginalArgString(""), 'id': func.GetOriginalArgs()[1].name, + 'type': func.GetOriginalArgs()[1].resource_type, + 'lc_type': func.GetOriginalArgs()[1].resource_type.lower(), }) else: self.WriteGLES2ImplementationDeclaration(func, file) @@ -2238,28 +2241,33 @@ class GENnHandler(TypeHandler): def WriteHandlerImplementation (self, func, file): """Overrriden from TypeHandler.""" - file.Write(" if (!GenGLObjects<GL%sHelper>(n, %s)) {\n" + file.Write(" if (!%sHelper(n, %s)) {\n" " return error::kInvalidArguments;\n" " }\n" % (func.name, func.GetLastOriginalArg().name)) def WriteImmediateHandlerImplementation(self, func, file): """Overrriden from TypeHandler.""" - file.Write(" if (!GenGLObjects<GL%sHelper>(n, %s)) {\n" + file.Write(" if (!%sHelper(n, %s)) {\n" " return error::kInvalidArguments;\n" " }\n" % (func.original_name, func.GetLastOriginalArg().name)) def WriteGLES2ImplementationHeader(self, func, file): """Overrriden from TypeHandler.""" - file.Write("%s %s(%s) {\n" % - (func.return_type, func.original_name, - func.MakeTypedOriginalArgString(""))) - file.Write(" MakeIds(%s);\n" % func.MakeOriginalArgString("")) - file.Write(" helper_->%sImmediate(%s);\n" % - (func.name, func.MakeOriginalArgString(""))) - file.Write("}\n") - file.Write("\n") + code = """%(return_type)s %(name)s(%(typed_args)s) { + MakeIds(&%(resource_type)s_id_allocator_, %(args)s); + helper_->%(name)sImmediate(%(args)s); +} + +""" + file.Write(code % { + 'return_type': func.return_type, + 'name': func.original_name, + 'typed_args': func.MakeTypedOriginalArgString(""), + 'args': func.MakeOriginalArgString(""), + 'resource_type': func.name[3:-1].lower() + }) def WriteServiceUnitTest(self, func, file): """Overrriden from TypeHandler.""" @@ -2273,10 +2281,12 @@ TEST_F(%(test_name)s, %(name)sValidArgs) { cmd.Init(%(args)s); EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); EXPECT_EQ(GL_NO_ERROR, GetGLError()); - EXPECT_EQ(GetServiceId(kNewClientId), kNewServiceId); + EXPECT_TRUE(Get%(resource_name)sInfo(kNewClientId) != NULL); } """ - self.WriteValidUnitTest(func, file, valid_test) + self.WriteValidUnitTest(func, file, valid_test, { + 'resource_name': func.name[3:-1], + }) invalid_test = """ TEST_F(%(test_name)s, %(name)sInvalidArgs) { EXPECT_CALL(*gl_, %(gl_func_name)s(_, _)).Times(0); @@ -2304,10 +2314,12 @@ TEST_F(%(test_name)s, %(name)sValidArgs) { EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, sizeof(temp))); EXPECT_EQ(GL_NO_ERROR, GetGLError()); - EXPECT_EQ(GetServiceId(kNewClientId), kNewServiceId); + EXPECT_TRUE(Get%(resource_name)sInfo(kNewClientId) != NULL); } """ - self.WriteValidUnitTest(func, file, valid_test) + self.WriteValidUnitTest(func, file, valid_test, { + 'resource_name': func.original_name[3:-1], + }) invalid_test = """ TEST_F(%(test_name)s, %(name)sInvalidArgs) { EXPECT_CALL(*gl_, %(gl_func_name)s(_, _)).Times(0); @@ -2440,7 +2452,7 @@ TEST_F(%(test_name)s, %(name)sValidArgs) { cmd.Init(%(args)s%(comma)skNewClientId); EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); EXPECT_EQ(GL_NO_ERROR, GetGLError()); - EXPECT_EQ(GetServiceId(kNewClientId), kNewServiceId); + EXPECT_TRUE(Get%(resource_type)sInfo(kNewClientId) != NULL); } """ comma = "" @@ -2448,6 +2460,7 @@ TEST_F(%(test_name)s, %(name)sValidArgs) { comma =", " self.WriteValidUnitTest(func, file, valid_test, { 'comma': comma, + 'resource_type': func.name[6:], }) invalid_test = """ TEST_F(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) { @@ -2465,8 +2478,10 @@ TEST_F(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) { def WriteHandlerImplementation (self, func, file): """Overrriden from TypeHandler.""" file.Write(" uint32 client_id = c.client_id;\n") - file.Write(" %sHelper(%s);\n" % + file.Write(" if (!%sHelper(%s)) {\n" % (func.name, func.MakeCmdArgString(""))) + file.Write(" return error::kInvalidArguments;\n") + file.Write(" }\n") def WriteGLES2ImplementationHeader(self, func, file): """Overrriden from TypeHandler.""" @@ -2474,7 +2489,7 @@ TEST_F(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) { (func.return_type, func.original_name, func.MakeTypedOriginalArgString(""))) file.Write(" GLuint client_id;\n") - file.Write(" MakeIds(1, &client_id);\n") + file.Write(" MakeIds(&program_and_shader_id_allocator_, 1, &client_id);\n") file.Write(" helper_->%s(%s);\n" % (func.name, func.MakeCmdArgString(""))) file.Write(" return client_id;\n") @@ -2511,7 +2526,8 @@ TEST_F(%(test_name)s, %(name)sValidArgs) { cmd.Init(%(args)s); EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); EXPECT_EQ(GL_NO_ERROR, GetGLError()); - EXPECT_EQ(GetServiceId(kNewClientId), 0u); + EXPECT_TRUE( + Get%(upper_resource_name)sInfo(client_%(resource_name)s_id_) == NULL); } """ self.WriteValidUnitTest(func, file, valid_test, { @@ -2521,8 +2537,6 @@ TEST_F(%(test_name)s, %(name)sValidArgs) { }) invalid_test = """ TEST_F(%(test_name)s, %(name)sInvalidArgs) { - EXPECT_CALL(*gl_, %(gl_func_name)s(1, Pointee(0))) - .Times(1); GetSharedMemoryAs<GLuint*>()[0] = kInvalidClientId; SpecializedSetup<%(name)s, 0>(); %(name)s cmd; @@ -2546,7 +2560,8 @@ TEST_F(%(test_name)s, %(name)sValidArgs) { EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, sizeof(client_%(resource_name)s_id_))); EXPECT_EQ(GL_NO_ERROR, GetGLError()); - EXPECT_EQ(GetServiceId(kNewClientId), 0u); + EXPECT_TRUE( + Get%(upper_resource_name)sInfo(client_%(resource_name)s_id_) == NULL); } """ self.WriteValidUnitTest(func, file, valid_test, { @@ -2556,8 +2571,6 @@ TEST_F(%(test_name)s, %(name)sValidArgs) { }) invalid_test = """ TEST_F(%(test_name)s, %(name)sInvalidArgs) { - EXPECT_CALL(*gl_, %(gl_func_name)s(1, Pointee(0))) - .Times(1); %(name)s& cmd = *GetImmediateAs<%(name)s>(); SpecializedSetup<%(name)s, 0>(); GLuint temp = kInvalidClientId; @@ -2570,12 +2583,12 @@ TEST_F(%(test_name)s, %(name)sInvalidArgs) { def WriteHandlerImplementation (self, func, file): """Overrriden from TypeHandler.""" - file.Write(" DeleteGLObjects<GL%sHelper>(n, %s);\n" % + file.Write(" %sHelper(n, %s);\n" % (func.name, func.GetLastOriginalArg().name)) def WriteImmediateHandlerImplementation (self, func, file): """Overrriden from TypeHandler.""" - file.Write(" DeleteGLObjects<GL%sHelper>(n, %s);\n" % + file.Write(" %sHelper(n, %s);\n" % (func.original_name, func.GetLastOriginalArg().name)) def WriteGLES2ImplementationHeader(self, func, file): @@ -2585,7 +2598,8 @@ TEST_F(%(test_name)s, %(name)sInvalidArgs) { file.Write("%s %s(%s) {\n" % (func.return_type, func.original_name, func.MakeTypedOriginalArgString(""))) - file.Write(" FreeIds(%s);\n" % func.MakeOriginalArgString("")) + file.Write(" FreeIds(&%s_id_allocator_, %s);\n" % + (func.name[6:-1].lower(), func.MakeOriginalArgString(""))) file.Write(" helper_->%sImmediate(%s);\n" % (func.name, func.MakeOriginalArgString(""))) file.Write("}\n") @@ -3504,28 +3518,7 @@ TEST_F(%(test_name)s, %(name)sInvalidArgs) { def WriteServiceImplementation(self, func, file): """Overrriden from TypeHandler.""" - file.Write( - "error::Error GLES2DecoderImpl::Handle%s(\n" % func.name) - file.Write( - " uint32 immediate_data_size, const gles2::%s& c) {\n" % func.name) - args = func.GetCmdArgs() - id_arg = args[0] - bucket_arg = args[1] - id_arg.WriteGetCode(file) - bucket_arg.WriteGetCode(file) - id_arg.WriteValidationCode(file) - file.Write(" GLint len = 0;\n") - file.Write(" %s(%s, %s, &len);\n" % ( - func.GetInfo('get_len_func'), id_arg.name, - func.GetInfo('get_len_enum'))) - file.Write(" Bucket* bucket = CreateBucket(%s);\n" % bucket_arg.name) - file.Write(" bucket->SetSize(len + 1);\n"); - file.Write( - " %s(%s, len + 1, &len, bucket->GetDataAs<GLchar*>(0, len + 1));\n" % - (func.GetGLFunctionName(), id_arg.name)) - file.Write(" return error::kNoError;\n") - file.Write("}\n") - file.Write("\n") + pass class FunctionInfo(object): @@ -3885,12 +3878,7 @@ class ResourceIdArgument(Argument): def WriteGetCode(self, file): """Overridden from Argument.""" - file.Write(" %s %s;\n" % (self.type, self.name)) - file.Write(" if (!id_manager()->GetServiceId(c.%s, &%s)) {\n" % - (self.name, self.name)) - file.Write(" SetGLError(GL_INVALID_VALUE);\n") - file.Write(" return error::kNoError;\n") - file.Write(" }\n") + file.Write(" %s %s = c.%s;\n" % (self.type, self.name, self.name)) def GetValidArg(self, offset, index): return "client_%s_id_" % self.resource_type.lower() @@ -3920,16 +3908,6 @@ class ResourceIdBindArgument(Argument): def GetValidGLArg(self, offset, index): return "kService%sId" % self.resource_type - def GetNumInvalidValues(self, func): - """returns the number of invalid values to be tested.""" - return 1 - - def GetInvalidArg(self, offset, index): - """returns an invalid value by index.""" - if self.resource_type == "Texture": - return ("client_buffer_id_", "kNoError", "GL_INVALID_OPERATION") - return ("client_texture_id_", "kNoError", "GL_INVALID_OPERATION") - class ResourceIdZeroArgument(Argument): """Represents a resource id argument to a function that can be zero.""" @@ -3943,11 +3921,6 @@ class ResourceIdZeroArgument(Argument): def WriteGetCode(self, file): """Overridden from Argument.""" file.Write(" %s %s = c.%s;\n" % (self.type, self.name, self.name)) - file.Write(" if (%s != 0 && !id_manager()->GetServiceId(%s, &%s)) {\n" % - (self.name, self.name, self.name)) - file.Write(" SetGLError(GL_INVALID_VALUE);\n") - file.Write(" return error::kNoError;\n") - file.Write(" }\n") def GetValidArg(self, offset, index): return "client_%s_id_" % self.resource_type.lower() @@ -3961,9 +3934,7 @@ class ResourceIdZeroArgument(Argument): def GetInvalidArg(self, offset, index): """returns an invalid value by index.""" - if self.resource_type == "Texture": - return ("client_buffer_id_", "kNoError", "GL_INVALID_OPERATION") - return ("client_texture_id_", "kNoError", "GL_INVALID_OPERATION") + return ("kInvalidClientId", "kNoError", "GL_INVALID_VALUE") class Function(object): diff --git a/gpu/command_buffer/client/gles2_implementation.cc b/gpu/command_buffer/client/gles2_implementation.cc index 583b0d5..724de0b 100644 --- a/gpu/command_buffer/client/gles2_implementation.cc +++ b/gpu/command_buffer/client/gles2_implementation.cc @@ -350,8 +350,8 @@ GLES2Implementation::GLES2Implementation( #if defined(GLES2_SUPPORT_CLIENT_SIDE_BUFFERS) GLint max_vertex_attribs; GetIntegerv(GL_MAX_VERTEX_ATTRIBS, &max_vertex_attribs); - id_allocator_.MarkAsUsed(kClientSideArrayId); - id_allocator_.MarkAsUsed(kClientSideElementArrayId); + buffer_id_allocator_.MarkAsUsed(kClientSideArrayId); + buffer_id_allocator_.MarkAsUsed(kClientSideElementArrayId); reserved_ids_[0] = kClientSideArrayId; reserved_ids_[1] = kClientSideElementArrayId; @@ -369,15 +369,17 @@ GLES2Implementation::~GLES2Implementation() { transfer_buffer_.Free(result_buffer_); } -void GLES2Implementation::MakeIds(GLsizei n, GLuint* ids) { +void GLES2Implementation::MakeIds( + IdAllocator* id_allocator, GLsizei n, GLuint* ids) { for (GLsizei ii = 0; ii < n; ++ii) { - ids[ii] = id_allocator_.AllocateID(); + ids[ii] = id_allocator->AllocateID(); } } -void GLES2Implementation::FreeIds(GLsizei n, const GLuint* ids) { +void GLES2Implementation::FreeIds( + IdAllocator* id_allocator, GLsizei n, const GLuint* ids) { for (GLsizei ii = 0; ii < n; ++ii) { - id_allocator_.FreeID(ids[ii]); + id_allocator->FreeID(ids[ii]); } } @@ -1180,7 +1182,7 @@ void GLES2Implementation::ReadPixels( } #if defined(GLES2_SUPPORT_CLIENT_SIDE_BUFFERS) -bool GLES2Implementation::IsReservedId(GLuint id) { +bool GLES2Implementation::IsBufferReservedId(GLuint id) { for (size_t ii = 0; ii < arraysize(reserved_ids_); ++ii) { if (id == reserved_ids_[ii]) { return true; @@ -1189,7 +1191,7 @@ bool GLES2Implementation::IsReservedId(GLuint id) { return false; } #else -bool GLES2Implementation::IsReservedId(GLuint) { // NOLINT +bool GLES2Implementation::IsBufferReservedId(GLuint) { // NOLINT return false; } #endif @@ -1197,12 +1199,12 @@ bool GLES2Implementation::IsReservedId(GLuint) { // NOLINT #if defined(GLES2_SUPPORT_CLIENT_SIDE_BUFFERS) void GLES2Implementation::BindBuffer(GLenum target, GLuint buffer) { - if (IsReservedId(buffer)) { + if (IsBufferReservedId(buffer)) { SetGLError(GL_INVALID_OPERATION); return; } if (buffer != 0) { - id_allocator_.MarkAsUsed(buffer); + buffer_id_allocator_.MarkAsUsed(buffer); } switch (target) { case GL_ARRAY_BUFFER: @@ -1218,7 +1220,7 @@ void GLES2Implementation::BindBuffer(GLenum target, GLuint buffer) { } void GLES2Implementation::DeleteBuffers(GLsizei n, const GLuint* buffers) { - FreeIds(n, buffers); + FreeIds(&buffer_id_allocator_, n, buffers); for (GLsizei ii = 0; ii < n; ++ii) { if (buffers[ii] == bound_array_buffer_id_) { bound_array_buffer_id_ = 0; diff --git a/gpu/command_buffer/client/gles2_implementation.h b/gpu/command_buffer/client/gles2_implementation.h index 4200458..2c37cba 100644 --- a/gpu/command_buffer/client/gles2_implementation.h +++ b/gpu/command_buffer/client/gles2_implementation.h @@ -126,11 +126,17 @@ class GLES2Implementation { } #endif - // Makes a set of Ids for glGen___ functions. - void MakeIds(GLsizei n, GLuint* ids); + void MakeIds(IdAllocator* id_allocator, GLsizei n, GLuint* ids); - // Frees a set of Ids for glDelete___ functions. - void FreeIds(GLsizei n, const GLuint* ids); + void FreeIds(IdAllocator* id_allocator, GLsizei n, const GLuint* ids); + + GLuint MakeTextureId() { + return texture_id_allocator_.AllocateID(); + } + + void FreeTextureId(GLuint id) { + texture_id_allocator_.FreeID(id); + } private: // Wraps FencedAllocatorWrapper to provide aligned allocations. @@ -203,7 +209,10 @@ class GLES2Implementation { void SetBucketAsString(uint32 bucket_id, const std::string& str); // Returns true if id is reserved. - bool IsReservedId(GLuint id); + bool IsBufferReservedId(GLuint id); + bool IsFramebufferReservedId(GLuint id) { return false; } + bool IsRenderbufferReservedId(GLuint id) { return false; } + bool IsTextureReservedId(GLuint id) { return false; } #if defined(GLES2_SUPPORT_CLIENT_SIDE_BUFFERS) // Helper for GetVertexAttrib @@ -216,7 +225,11 @@ class GLES2Implementation { GLES2Util util_; GLES2CmdHelper* helper_; - IdAllocator id_allocator_; + IdAllocator buffer_id_allocator_; + IdAllocator framebuffer_id_allocator_; + IdAllocator renderbuffer_id_allocator_; + IdAllocator program_and_shader_id_allocator_; + IdAllocator texture_id_allocator_; AlignedFencedAllocator transfer_buffer_; int transfer_buffer_id_; void* result_buffer_; diff --git a/gpu/command_buffer/client/gles2_implementation_autogen.h b/gpu/command_buffer/client/gles2_implementation_autogen.h index 9938cb8..c755807 100644 --- a/gpu/command_buffer/client/gles2_implementation_autogen.h +++ b/gpu/command_buffer/client/gles2_implementation_autogen.h @@ -20,34 +20,34 @@ void AttachShader(GLuint program, GLuint shader) { void BindAttribLocation(GLuint program, GLuint index, const char* name); void BindFramebuffer(GLenum target, GLuint framebuffer) { - if (IsReservedId(framebuffer)) { + if (IsFramebufferReservedId(framebuffer)) { SetGLError(GL_INVALID_OPERATION); return; } if (framebuffer != 0) { - id_allocator_.MarkAsUsed(framebuffer); + framebuffer_id_allocator_.MarkAsUsed(framebuffer); } helper_->BindFramebuffer(target, framebuffer); } void BindRenderbuffer(GLenum target, GLuint renderbuffer) { - if (IsReservedId(renderbuffer)) { + if (IsRenderbufferReservedId(renderbuffer)) { SetGLError(GL_INVALID_OPERATION); return; } if (renderbuffer != 0) { - id_allocator_.MarkAsUsed(renderbuffer); + renderbuffer_id_allocator_.MarkAsUsed(renderbuffer); } helper_->BindRenderbuffer(target, renderbuffer); } void BindTexture(GLenum target, GLuint texture) { - if (IsReservedId(texture)) { + if (IsTextureReservedId(texture)) { SetGLError(GL_INVALID_OPERATION); return; } if (texture != 0) { - id_allocator_.MarkAsUsed(texture); + texture_id_allocator_.MarkAsUsed(texture); } helper_->BindTexture(target, texture); } @@ -154,14 +154,14 @@ void CopyTexSubImage2D( GLuint CreateProgram() { GLuint client_id; - MakeIds(1, &client_id); + MakeIds(&program_and_shader_id_allocator_, 1, &client_id); helper_->CreateProgram(client_id); return client_id; } GLuint CreateShader(GLenum type) { GLuint client_id; - MakeIds(1, &client_id); + MakeIds(&program_and_shader_id_allocator_, 1, &client_id); helper_->CreateShader(type, client_id); return client_id; } @@ -171,7 +171,7 @@ void CullFace(GLenum mode) { } void DeleteFramebuffers(GLsizei n, const GLuint* framebuffers) { - FreeIds(n, framebuffers); + FreeIds(&framebuffer_id_allocator_, n, framebuffers); helper_->DeleteFramebuffersImmediate(n, framebuffers); } @@ -180,7 +180,7 @@ void DeleteProgram(GLuint program) { } void DeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers) { - FreeIds(n, renderbuffers); + FreeIds(&renderbuffer_id_allocator_, n, renderbuffers); helper_->DeleteRenderbuffersImmediate(n, renderbuffers); } @@ -189,7 +189,7 @@ void DeleteShader(GLuint shader) { } void DeleteTextures(GLsizei n, const GLuint* textures) { - FreeIds(n, textures); + FreeIds(&texture_id_allocator_, n, textures); helper_->DeleteTexturesImmediate(n, textures); } @@ -242,7 +242,7 @@ void FrontFace(GLenum mode) { } void GenBuffers(GLsizei n, GLuint* buffers) { - MakeIds(n, buffers); + MakeIds(&buffer_id_allocator_, n, buffers); helper_->GenBuffersImmediate(n, buffers); } @@ -251,17 +251,17 @@ void GenerateMipmap(GLenum target) { } void GenFramebuffers(GLsizei n, GLuint* framebuffers) { - MakeIds(n, framebuffers); + MakeIds(&framebuffer_id_allocator_, n, framebuffers); helper_->GenFramebuffersImmediate(n, framebuffers); } void GenRenderbuffers(GLsizei n, GLuint* renderbuffers) { - MakeIds(n, renderbuffers); + MakeIds(&renderbuffer_id_allocator_, n, renderbuffers); helper_->GenRenderbuffersImmediate(n, renderbuffers); } void GenTextures(GLsizei n, GLuint* textures) { - MakeIds(n, textures); + MakeIds(&texture_id_allocator_, n, textures); helper_->GenTexturesImmediate(n, textures); } diff --git a/gpu/command_buffer/client/gles2_implementation_unittest.cc b/gpu/command_buffer/client/gles2_implementation_unittest.cc index 79cf95e..93710fc 100644 --- a/gpu/command_buffer/client/gles2_implementation_unittest.cc +++ b/gpu/command_buffer/client/gles2_implementation_unittest.cc @@ -645,24 +645,6 @@ TEST_F(GLES2ImplementationTest, ReservedIds) { gl_->BindBuffer( GL_ARRAY_BUFFER, GLES2Implementation::kClientSideElementArrayId); - gl_->BindFramebuffer( - GL_FRAMEBUFFER, - GLES2Implementation::kClientSideArrayId); - gl_->BindFramebuffer( - GL_FRAMEBUFFER, - GLES2Implementation::kClientSideElementArrayId); - gl_->BindRenderbuffer( - GL_RENDERBUFFER, - GLES2Implementation::kClientSideArrayId); - gl_->BindRenderbuffer( - GL_RENDERBUFFER, - GLES2Implementation::kClientSideElementArrayId); - gl_->BindTexture( - GL_TEXTURE_2D, - GLES2Implementation::kClientSideArrayId); - gl_->BindTexture( - GL_TEXTURE_2D, - GLES2Implementation::kClientSideElementArrayId); GLenum err = gl_->GetError(); EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), err); EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); diff --git a/gpu/command_buffer/service/buffer_manager.cc b/gpu/command_buffer/service/buffer_manager.cc index 9b58e42..dbc382c 100644 --- a/gpu/command_buffer/service/buffer_manager.cc +++ b/gpu/command_buffer/service/buffer_manager.cc @@ -10,25 +10,25 @@ namespace gpu { namespace gles2 { -void BufferManager::CreateBufferInfo(GLuint buffer_id) { +void BufferManager::CreateBufferInfo(GLuint client_id, GLuint service_id) { std::pair<BufferInfoMap::iterator, bool> result = buffer_infos_.insert( - std::make_pair(buffer_id, - BufferInfo::Ref(new BufferInfo(buffer_id)))); + std::make_pair(client_id, + BufferInfo::Ref(new BufferInfo(service_id)))); DCHECK(result.second); } BufferManager::BufferInfo* BufferManager::GetBufferInfo( - GLuint buffer_id) { - BufferInfoMap::iterator it = buffer_infos_.find(buffer_id); + GLuint client_id) { + BufferInfoMap::iterator it = buffer_infos_.find(client_id); return it != buffer_infos_.end() ? it->second : NULL; } -void BufferManager::RemoveBufferInfo(GLuint buffer_id) { - BufferInfoMap::iterator it = buffer_infos_.find(buffer_id); +void BufferManager::RemoveBufferInfo(GLuint client_id) { + BufferInfoMap::iterator it = buffer_infos_.find(client_id); if (it != buffer_infos_.end()) { it->second->MarkAsDeleted(); - buffer_infos_.erase(buffer_id); + buffer_infos_.erase(it); } } diff --git a/gpu/command_buffer/service/buffer_manager.h b/gpu/command_buffer/service/buffer_manager.h index c77b5df..7eefd52 100644 --- a/gpu/command_buffer/service/buffer_manager.h +++ b/gpu/command_buffer/service/buffer_manager.h @@ -27,14 +27,14 @@ class BufferManager { public: typedef scoped_refptr<BufferInfo> Ref; - explicit BufferInfo(GLuint buffer_id) - : buffer_id_(buffer_id), + explicit BufferInfo(GLuint service_id) + : service_id_(service_id), target_(0), size_(0) { } - GLuint buffer_id() const { - return buffer_id_; + GLuint service_id() const { + return service_id_; } GLenum target() const { @@ -65,7 +65,7 @@ class BufferManager { GLuint* max_value); bool IsDeleted() { - return buffer_id_ == 0; + return service_id_ == 0; } private: @@ -103,7 +103,7 @@ class BufferManager { ~BufferInfo() { } void MarkAsDeleted() { - buffer_id_ = 0; + service_id_ = 0; shadow_.reset(); ClearCache(); } @@ -112,7 +112,7 @@ class BufferManager { void ClearCache(); // Service side buffer id. - GLuint buffer_id_; + GLuint service_id_; // The type of buffer. 0 = unset, GL_BUFFER_ARRAY = vertex data, // GL_ELEMENT_BUFFER_ARRAY = index data. @@ -134,13 +134,13 @@ class BufferManager { BufferManager() { } // Creates a BufferInfo for the given buffer. - void CreateBufferInfo(GLuint buffer_id); + void CreateBufferInfo(GLuint client_id, GLuint service_id); // Gets the buffer info for the given buffer. - BufferInfo* GetBufferInfo(GLuint buffer_id); + BufferInfo* GetBufferInfo(GLuint client_id); // Removes a buffer info for the given buffer. - void RemoveBufferInfo(GLuint buffer_id); + void RemoveBufferInfo(GLuint client_id); private: // Info for each buffer in the system. diff --git a/gpu/command_buffer/service/buffer_manager_unittest.cc b/gpu/command_buffer/service/buffer_manager_unittest.cc index 0f4dc52..2346f7c 100644 --- a/gpu/command_buffer/service/buffer_manager_unittest.cc +++ b/gpu/command_buffer/service/buffer_manager_unittest.cc @@ -24,37 +24,39 @@ class BufferManagerTest : public testing::Test { }; TEST_F(BufferManagerTest, Basic) { - const GLuint kBuffer1Id = 1; + const GLuint kClientBuffer1Id = 1; + const GLuint kServiceBuffer1Id = 11; const GLsizeiptr kBuffer1Size = 123; - const GLuint kBuffer2Id = 2; + const GLuint kClientBuffer2Id = 2; // Check we can create buffer. - manager_.CreateBufferInfo(kBuffer1Id); + manager_.CreateBufferInfo(kClientBuffer1Id, kServiceBuffer1Id); // Check buffer got created. - BufferManager::BufferInfo* info1 = manager_.GetBufferInfo(kBuffer1Id); + BufferManager::BufferInfo* info1 = manager_.GetBufferInfo(kClientBuffer1Id); ASSERT_TRUE(info1 != NULL); EXPECT_EQ(0u, info1->target()); EXPECT_EQ(0, info1->size()); EXPECT_FALSE(info1->IsDeleted()); - EXPECT_EQ(kBuffer1Id, info1->buffer_id()); + EXPECT_EQ(kServiceBuffer1Id, info1->service_id()); info1->set_target(GL_ELEMENT_ARRAY_BUFFER); EXPECT_EQ(static_cast<GLenum>(GL_ELEMENT_ARRAY_BUFFER), info1->target()); // Check we and set its size. info1->SetSize(kBuffer1Size); EXPECT_EQ(kBuffer1Size, info1->size()); // Check we get nothing for a non-existent buffer. - EXPECT_TRUE(manager_.GetBufferInfo(kBuffer2Id) == NULL); + EXPECT_TRUE(manager_.GetBufferInfo(kClientBuffer2Id) == NULL); // Check trying to a remove non-existent buffers does not crash. - manager_.RemoveBufferInfo(kBuffer2Id); + manager_.RemoveBufferInfo(kClientBuffer2Id); // Check we can't get the buffer after we remove it. - manager_.RemoveBufferInfo(kBuffer1Id); - EXPECT_TRUE(manager_.GetBufferInfo(kBuffer1Id) == NULL); + manager_.RemoveBufferInfo(kClientBuffer1Id); + EXPECT_TRUE(manager_.GetBufferInfo(kClientBuffer1Id) == NULL); } TEST_F(BufferManagerTest, SetRange) { - const GLuint kBufferId = 1; + const GLuint kClientBufferId = 1; + const GLuint kServiceBufferId = 11; const uint8 data[] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; - manager_.CreateBufferInfo(kBufferId); - BufferManager::BufferInfo* info = manager_.GetBufferInfo(kBufferId); + manager_.CreateBufferInfo(kClientBufferId, kServiceBufferId); + BufferManager::BufferInfo* info = manager_.GetBufferInfo(kClientBufferId); ASSERT_TRUE(info != NULL); info->set_target(GL_ELEMENT_ARRAY_BUFFER); info->SetSize(sizeof(data)); @@ -65,11 +67,12 @@ TEST_F(BufferManagerTest, SetRange) { } TEST_F(BufferManagerTest, GetMaxValueForRangeUint8) { - const GLuint kBufferId = 1; + const GLuint kClientBufferId = 1; + const GLuint kServiceBufferId = 11; const uint8 data[] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; const uint8 new_data[] = {100, 120, 110}; - manager_.CreateBufferInfo(kBufferId); - BufferManager::BufferInfo* info = manager_.GetBufferInfo(kBufferId); + manager_.CreateBufferInfo(kClientBufferId, kServiceBufferId); + BufferManager::BufferInfo* info = manager_.GetBufferInfo(kClientBufferId); ASSERT_TRUE(info != NULL); info->set_target(GL_ELEMENT_ARRAY_BUFFER); info->SetSize(sizeof(data)); @@ -94,11 +97,12 @@ TEST_F(BufferManagerTest, GetMaxValueForRangeUint8) { } TEST_F(BufferManagerTest, GetMaxValueForRangeUint16) { - const GLuint kBufferId = 1; + const GLuint kClientBufferId = 1; + const GLuint kServiceBufferId = 11; const uint16 data[] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; const uint16 new_data[] = {100, 120, 110}; - manager_.CreateBufferInfo(kBufferId); - BufferManager::BufferInfo* info = manager_.GetBufferInfo(kBufferId); + manager_.CreateBufferInfo(kClientBufferId, kServiceBufferId); + BufferManager::BufferInfo* info = manager_.GetBufferInfo(kClientBufferId); ASSERT_TRUE(info != NULL); info->set_target(GL_ELEMENT_ARRAY_BUFFER); info->SetSize(sizeof(data)); diff --git a/gpu/command_buffer/service/context_group.cc b/gpu/command_buffer/service/context_group.cc index d20ee4c9..6e85e30 100644 --- a/gpu/command_buffer/service/context_group.cc +++ b/gpu/command_buffer/service/context_group.cc @@ -5,7 +5,6 @@ #include "gpu/command_buffer/service/context_group.h" #include "gpu/command_buffer/service/buffer_manager.h" #include "gpu/command_buffer/service/framebuffer_manager.h" -#include "gpu/command_buffer/service/id_manager.h" #include "gpu/command_buffer/service/program_manager.h" #include "gpu/command_buffer/service/renderbuffer_manager.h" #include "gpu/command_buffer/service/shader_manager.h" @@ -28,7 +27,6 @@ bool ContextGroup::Initialize() { return true; } - id_manager_.reset(new IdManager()); buffer_manager_.reset(new BufferManager()); framebuffer_manager_.reset(new FramebufferManager()); renderbuffer_manager_.reset(new RenderbufferManager()); diff --git a/gpu/command_buffer/service/context_group.h b/gpu/command_buffer/service/context_group.h index fd6e1c3..8ccbb62 100644 --- a/gpu/command_buffer/service/context_group.h +++ b/gpu/command_buffer/service/context_group.h @@ -16,7 +16,6 @@ class GLES2Decoder; class BufferManager; class FramebufferManager; class RenderbufferManager; -class IdManager; class ProgramManager; class ShaderManager; class TextureManager; @@ -39,11 +38,6 @@ class ContextGroup { return max_texture_units_; } - // Map of client ids to GL ids. - IdManager* id_manager() const { - return id_manager_.get(); - } - BufferManager* buffer_manager() const { return buffer_manager_.get(); } @@ -76,9 +70,6 @@ class ContextGroup { uint32 max_texture_units_; - // Map of client ids to GL ids. - scoped_ptr<IdManager> id_manager_; - scoped_ptr<BufferManager> buffer_manager_; scoped_ptr<FramebufferManager> framebuffer_manager_; diff --git a/gpu/command_buffer/service/context_group_unittest.cc b/gpu/command_buffer/service/context_group_unittest.cc index ef6c5ed..d46bec6 100644 --- a/gpu/command_buffer/service/context_group_unittest.cc +++ b/gpu/command_buffer/service/context_group_unittest.cc @@ -27,7 +27,6 @@ TEST_F(ContextGroupTest, Basic) { // Test it starts off uninitialized. EXPECT_EQ(0u, group_.max_vertex_attribs()); EXPECT_EQ(0u, group_.max_texture_units()); - EXPECT_TRUE(group_.id_manager() == NULL); EXPECT_TRUE(group_.buffer_manager() == NULL); EXPECT_TRUE(group_.framebuffer_manager() == NULL); EXPECT_TRUE(group_.renderbuffer_manager() == NULL); diff --git a/gpu/command_buffer/service/framebuffer_manager.cc b/gpu/command_buffer/service/framebuffer_manager.cc index 5b55e76..fb1014a 100644 --- a/gpu/command_buffer/service/framebuffer_manager.cc +++ b/gpu/command_buffer/service/framebuffer_manager.cc @@ -9,26 +9,27 @@ namespace gpu { namespace gles2 { -void FramebufferManager::CreateFramebufferInfo(GLuint framebuffer_id) { +void FramebufferManager::CreateFramebufferInfo( + GLuint client_id, GLuint service_id) { std::pair<FramebufferInfoMap::iterator, bool> result = framebuffer_infos_.insert( std::make_pair( - framebuffer_id, - FramebufferInfo::Ref(new FramebufferInfo(framebuffer_id)))); + client_id, + FramebufferInfo::Ref(new FramebufferInfo(service_id)))); DCHECK(result.second); } FramebufferManager::FramebufferInfo* FramebufferManager::GetFramebufferInfo( - GLuint framebuffer_id) { - FramebufferInfoMap::iterator it = framebuffer_infos_.find(framebuffer_id); + GLuint client_id) { + FramebufferInfoMap::iterator it = framebuffer_infos_.find(client_id); return it != framebuffer_infos_.end() ? it->second : NULL; } -void FramebufferManager::RemoveFramebufferInfo(GLuint framebuffer_id) { - FramebufferInfoMap::iterator it = framebuffer_infos_.find(framebuffer_id); +void FramebufferManager::RemoveFramebufferInfo(GLuint client_id) { + FramebufferInfoMap::iterator it = framebuffer_infos_.find(client_id); if (it != framebuffer_infos_.end()) { it->second->MarkAsDeleted(); - framebuffer_infos_.erase(framebuffer_id); + framebuffer_infos_.erase(it); } } diff --git a/gpu/command_buffer/service/framebuffer_manager.h b/gpu/command_buffer/service/framebuffer_manager.h index f923f9f..db05c5b 100644 --- a/gpu/command_buffer/service/framebuffer_manager.h +++ b/gpu/command_buffer/service/framebuffer_manager.h @@ -25,12 +25,12 @@ class FramebufferManager { public: typedef scoped_refptr<FramebufferInfo> Ref; - explicit FramebufferInfo(GLuint framebuffer_id) - : framebuffer_id_(framebuffer_id) { + explicit FramebufferInfo(GLuint service_id) + : service_id_(service_id) { } - GLuint framebuffer_id() const { - return framebuffer_id_; + GLuint service_id() const { + return service_id_; } // Attaches a renderbuffer to a particlar attachment. @@ -39,7 +39,7 @@ class FramebufferManager { GLenum attachment, RenderbufferManager::RenderbufferInfo* renderbuffer); bool IsDeleted() { - return framebuffer_id_ == 0; + return service_id_ == 0; } private: @@ -49,12 +49,12 @@ class FramebufferManager { ~FramebufferInfo() { } void MarkAsDeleted() { - framebuffer_id_ = 0; + service_id_ = 0; renderbuffers_.clear(); } // Service side framebuffer id. - GLuint framebuffer_id_; + GLuint service_id_; // A map of attachments to renderbuffers. typedef std::map<GLenum, RenderbufferManager::RenderbufferInfo::Ref> @@ -65,13 +65,13 @@ class FramebufferManager { FramebufferManager() { } // Creates a FramebufferInfo for the given framebuffer. - void CreateFramebufferInfo(GLuint framebuffer_id); + void CreateFramebufferInfo(GLuint client_id, GLuint service_id); // Gets the framebuffer info for the given framebuffer. - FramebufferInfo* GetFramebufferInfo(GLuint framebuffer_id); + FramebufferInfo* GetFramebufferInfo(GLuint client_id); // Removes a framebuffer info for the given framebuffer. - void RemoveFramebufferInfo(GLuint framebuffer_id); + void RemoveFramebufferInfo(GLuint client_id); private: // Info for each framebuffer in the system. diff --git a/gpu/command_buffer/service/framebuffer_manager_unittest.cc b/gpu/command_buffer/service/framebuffer_manager_unittest.cc index 36bbbe9..1c57c85 100644 --- a/gpu/command_buffer/service/framebuffer_manager_unittest.cc +++ b/gpu/command_buffer/service/framebuffer_manager_unittest.cc @@ -24,23 +24,24 @@ class FramebufferManagerTest : public testing::Test { }; TEST_F(FramebufferManagerTest, Basic) { - const GLuint kFramebuffer1Id = 1; - const GLuint kFramebuffer2Id = 2; + const GLuint kClient1Id = 1; + const GLuint kService1Id = 11; + const GLuint kClient2Id = 2; // Check we can create framebuffer. - manager_.CreateFramebufferInfo(kFramebuffer1Id); + manager_.CreateFramebufferInfo(kClient1Id, kService1Id); // Check framebuffer got created. FramebufferManager::FramebufferInfo* info1 = - manager_.GetFramebufferInfo(kFramebuffer1Id); + manager_.GetFramebufferInfo(kClient1Id); ASSERT_TRUE(info1 != NULL); EXPECT_FALSE(info1->IsDeleted()); - EXPECT_EQ(kFramebuffer1Id, info1->framebuffer_id()); + EXPECT_EQ(kService1Id, info1->service_id()); // Check we get nothing for a non-existent framebuffer. - EXPECT_TRUE(manager_.GetFramebufferInfo(kFramebuffer2Id) == NULL); + EXPECT_TRUE(manager_.GetFramebufferInfo(kClient2Id) == NULL); // Check trying to a remove non-existent framebuffers does not crash. - manager_.RemoveFramebufferInfo(kFramebuffer2Id); + manager_.RemoveFramebufferInfo(kClient2Id); // Check we can't get the framebuffer after we remove it. - manager_.RemoveFramebufferInfo(kFramebuffer1Id); - EXPECT_TRUE(manager_.GetFramebufferInfo(kFramebuffer1Id) == NULL); + manager_.RemoveFramebufferInfo(kClient1Id); + EXPECT_TRUE(manager_.GetFramebufferInfo(kClient1Id) == NULL); } // TODO(gman): Write test for AttachRenderbuffer diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.cc b/gpu/command_buffer/service/gles2_cmd_decoder.cc index b005e512..d85310e 100644 --- a/gpu/command_buffer/service/gles2_cmd_decoder.cc +++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc @@ -26,7 +26,6 @@ #include "gpu/command_buffer/service/framebuffer_manager.h" #include "gpu/command_buffer/service/gl_utils.h" #include "gpu/command_buffer/service/gles2_cmd_validation.h" -#include "gpu/command_buffer/service/id_manager.h" #include "gpu/command_buffer/service/program_manager.h" #include "gpu/command_buffer/service/renderbuffer_manager.h" #include "gpu/command_buffer/service/shader_manager.h" @@ -383,7 +382,6 @@ class GLES2DecoderImpl : public base::SupportsWeakPtr<GLES2DecoderImpl>, virtual void Destroy(); virtual void ResizeOffscreenFrameBuffer(const gfx::Size& size); virtual bool MakeCurrent(); - virtual uint32 GetServiceIdForTesting(uint32 client_id); virtual GLES2Util* GetGLES2Util() { return &util_; } virtual gfx::GLContext* GetGLContext() { return context_; } @@ -413,28 +411,17 @@ class GLES2DecoderImpl : public base::SupportsWeakPtr<GLES2DecoderImpl>, TextureManager::TextureInfo::Ref bound_texture_cube_map; }; - friend void GLGenTexturesHelper( - GLES2DecoderImpl* decoder, GLsizei n, GLuint* ids); - friend void GLDeleteTexturesHelper( - GLES2DecoderImpl* decoder, GLsizei n, GLuint* ids); - friend void GLGenBuffersHelper( - GLES2DecoderImpl* decoder, GLsizei n, GLuint* ids); - friend void GLDeleteBuffersHelper( - GLES2DecoderImpl* decoder, GLsizei n, GLuint* ids); - friend void GLGenFramebuffersHelper( - GLES2DecoderImpl* decoder, GLsizei n, GLuint* ids); - friend void GLDeleteFramebuffersHelper( - GLES2DecoderImpl* decoder, GLsizei n, GLuint* ids); - friend void GLGenRenderbuffersHelper( - GLES2DecoderImpl* decoder, GLsizei n, GLuint* ids); - friend void GLDeleteRenderbuffersHelper( - GLES2DecoderImpl* decoder, GLsizei n, GLuint* ids); + // Helpers for the glGen and glDelete functions. + bool GenTexturesHelper(GLsizei n, const GLuint* client_ids); + void DeleteTexturesHelper(GLsizei n, const GLuint* client_ids); + bool GenBuffersHelper(GLsizei n, const GLuint* client_ids); + void DeleteBuffersHelper(GLsizei n, const GLuint* client_ids); + bool GenFramebuffersHelper(GLsizei n, const GLuint* client_ids); + void DeleteFramebuffersHelper(GLsizei n, const GLuint* client_ids); + bool GenRenderbuffersHelper(GLsizei n, const GLuint* client_ids); + void DeleteRenderbuffersHelper(GLsizei n, const GLuint* client_ids); // TODO(gman): Cache these pointers? - IdManager* id_manager() { - return group_->id_manager(); - } - BufferManager* buffer_manager() { return group_->buffer_manager(); } @@ -461,54 +448,22 @@ class GLES2DecoderImpl : public base::SupportsWeakPtr<GLES2DecoderImpl>, bool UpdateOffscreenFrameBufferSize(); - // Template to help call glGenXXX functions. - template <void gl_gen_function(GLES2DecoderImpl*, GLsizei, GLuint*)> - bool GenGLObjects(GLsizei n, const GLuint* client_ids) { - DCHECK_GE(n, 0); - if (!ValidateIdsAreUnused(n, client_ids)) { - return false; - } - scoped_array<GLuint>temp(new GLuint[n]); - gl_gen_function(this, n, temp.get()); - return RegisterObjects(n, client_ids, temp.get()); - } - - // Template to help call glDeleteXXX functions. - template <void gl_delete_function(GLES2DecoderImpl*, GLsizei, GLuint*)> - bool DeleteGLObjects(GLsizei n, const GLuint* client_ids) { - DCHECK_GE(n, 0); - scoped_array<GLuint>temp(new GLuint[n]); - UnregisterObjects(n, client_ids, temp.get()); - gl_delete_function(this, n, temp.get()); - return true; - } - - // Check that the given ids are not used. - bool ValidateIdsAreUnused(GLsizei n, const GLuint* client_ids); - - // Register client ids with generated service ids. - bool RegisterObjects( - GLsizei n, const GLuint* client_ids, const GLuint* service_ids); - - // Unregisters client ids with service ids. - void UnregisterObjects( - GLsizei n, const GLuint* client_ids, GLuint* service_ids); - // Creates a TextureInfo for the given texture. - TextureManager::TextureInfo* CreateTextureInfo(GLuint texture) { - return texture_manager()->CreateTextureInfo(texture); + TextureManager::TextureInfo* CreateTextureInfo( + GLuint client_id, GLuint service_id) { + return texture_manager()->CreateTextureInfo(client_id, service_id); } // Gets the texture info for the given texture. Returns NULL if none exists. - TextureManager::TextureInfo* GetTextureInfo(GLuint texture) { + TextureManager::TextureInfo* GetTextureInfo(GLuint client_id) { TextureManager::TextureInfo* info = - texture_manager()->GetTextureInfo(texture); + texture_manager()->GetTextureInfo(client_id); return (info && !info->IsDeleted()) ? info : NULL; } // Deletes the texture info for the given texture. - void RemoveTextureInfo(GLuint texture) { - texture_manager()->RemoveTextureInfo(texture); + void RemoveTextureInfo(GLuint client_id) { + texture_manager()->RemoveTextureInfo(client_id); } // Get the size (in pixels) of the currently bound frame buffer (either FBO @@ -540,90 +495,91 @@ class GLES2DecoderImpl : public base::SupportsWeakPtr<GLES2DecoderImpl>, uint32 pixels_size); // Creates a ProgramInfo for the given program. - void CreateProgramInfo(GLuint program) { - program_manager()->CreateProgramInfo(program); + void CreateProgramInfo(GLuint client_id, GLuint service_id) { + program_manager()->CreateProgramInfo(client_id, service_id); } // Gets the program info for the given program. Returns NULL if none exists. - // Programs that have no had glLinkProgram succesfully called on them will - // not exist. - ProgramManager::ProgramInfo* GetProgramInfo(GLuint program) { + ProgramManager::ProgramInfo* GetProgramInfo(GLuint client_id) { ProgramManager::ProgramInfo* info = - program_manager()->GetProgramInfo(program); + program_manager()->GetProgramInfo(client_id); return (info && !info->IsDeleted()) ? info : NULL; } // Deletes the program info for the given program. - void RemoveProgramInfo(GLuint program) { - program_manager()->RemoveProgramInfo(program); + void RemoveProgramInfo(GLuint client_id) { + program_manager()->RemoveProgramInfo(client_id); } // Creates a ShaderInfo for the given shader. - void CreateShaderInfo(GLuint shader) { - shader_manager()->CreateShaderInfo(shader); + void CreateShaderInfo(GLuint client_id, GLuint service_id) { + shader_manager()->CreateShaderInfo(client_id, service_id); } // Gets the shader info for the given shader. Returns NULL if none exists. - ShaderManager::ShaderInfo* GetShaderInfo(GLuint shader) { - ShaderManager::ShaderInfo* info = shader_manager()->GetShaderInfo(shader); + ShaderManager::ShaderInfo* GetShaderInfo(GLuint client_id) { + ShaderManager::ShaderInfo* info = + shader_manager()->GetShaderInfo(client_id); return (info && !info->IsDeleted()) ? info : NULL; } // Deletes the shader info for the given shader. - void RemoveShaderInfo(GLuint shader) { - shader_manager()->RemoveShaderInfo(shader); + void RemoveShaderInfo(GLuint client_id) { + shader_manager()->RemoveShaderInfo(client_id); } // Creates a buffer info for the given buffer. - void CreateBufferInfo(GLuint buffer) { - return buffer_manager()->CreateBufferInfo(buffer); + void CreateBufferInfo(GLuint client_id, GLuint service_id) { + return buffer_manager()->CreateBufferInfo(client_id, service_id); } // Gets the buffer info for the given buffer. - BufferManager::BufferInfo* GetBufferInfo(GLuint buffer) { - BufferManager::BufferInfo* info = buffer_manager()->GetBufferInfo(buffer); + BufferManager::BufferInfo* GetBufferInfo(GLuint client_id) { + BufferManager::BufferInfo* info = + buffer_manager()->GetBufferInfo(client_id); return (info && !info->IsDeleted()) ? info : NULL; } // Removes any buffers in the VertexAtrribInfos and BufferInfos. This is used // on glDeleteBuffers so we can make sure the user does not try to render // with deleted buffers. - void RemoveBufferInfo(GLuint buffer_id); + void RemoveBufferInfo(GLuint client_id); // Creates a framebuffer info for the given framebuffer. - void CreateFramebufferInfo(GLuint framebuffer) { - return framebuffer_manager()->CreateFramebufferInfo(framebuffer); + void CreateFramebufferInfo(GLuint client_id, GLuint service_id) { + return framebuffer_manager()->CreateFramebufferInfo(client_id, service_id); } // Gets the framebuffer info for the given framebuffer. FramebufferManager::FramebufferInfo* GetFramebufferInfo( - GLuint framebuffer) { + GLuint client_id) { FramebufferManager::FramebufferInfo* info = - framebuffer_manager()->GetFramebufferInfo(framebuffer); + framebuffer_manager()->GetFramebufferInfo(client_id); return (info && !info->IsDeleted()) ? info : NULL; } // Removes the framebuffer info for the given framebuffer. - void RemoveFramebufferInfo(GLuint framebuffer_id) { - framebuffer_manager()->RemoveFramebufferInfo(framebuffer_id); + void RemoveFramebufferInfo(GLuint client_id) { + framebuffer_manager()->RemoveFramebufferInfo(client_id); } // Creates a renderbuffer info for the given renderbuffer. - void CreateRenderbufferInfo(GLuint renderbuffer) { - return renderbuffer_manager()->CreateRenderbufferInfo(renderbuffer); + void CreateRenderbufferInfo(GLuint client_id, GLuint service_id) { + return renderbuffer_manager()->CreateRenderbufferInfo( + client_id, service_id); } // Gets the renderbuffer info for the given renderbuffer. RenderbufferManager::RenderbufferInfo* GetRenderbufferInfo( - GLuint renderbuffer) { + GLuint client_id) { RenderbufferManager::RenderbufferInfo* info = - renderbuffer_manager()->GetRenderbufferInfo(renderbuffer); + renderbuffer_manager()->GetRenderbufferInfo(client_id); return (info && !info->IsDeleted()) ? info : NULL; } // Removes the renderbuffer info for the given renderbuffer. - void RemoveRenderbufferInfo(GLuint renderbuffer_id) { - renderbuffer_manager()->RemoveRenderbufferInfo(renderbuffer_id); + void RemoveRenderbufferInfo(GLuint client_id) { + renderbuffer_manager()->RemoveRenderbufferInfo(client_id); } error::Error GetAttribLocationHelper( @@ -636,20 +592,23 @@ class GLES2DecoderImpl : public base::SupportsWeakPtr<GLES2DecoderImpl>, // Helper for glShaderSource. error::Error ShaderSourceHelper( - GLuint shader, const char* data, uint32 data_size); + GLuint client_id, const char* data, uint32 data_size); // Helper for glGetBooleanv, glGetFloatv and glGetIntegerv bool GetHelper(GLenum pname, GLint* params, GLsizei* num_written); // Wrapper for glCreateProgram - void CreateProgramHelper(GLuint client_id); + bool CreateProgramHelper(GLuint client_id); // Wrapper for glCreateShader - void CreateShaderHelper(GLenum type, GLuint client_id); + bool CreateShaderHelper(GLenum type, GLuint client_id); // Wrapper for glActiveTexture void DoActiveTexture(GLenum texture_unit); + // Wrapper for glAttachShader + void DoAttachShader(GLuint client_program_id, GLint client_shader_id); + // Wrapper for glBindBuffer since we need to track the current targets. void DoBindBuffer(GLenum target, GLuint buffer); @@ -676,6 +635,9 @@ class GLES2DecoderImpl : public base::SupportsWeakPtr<GLES2DecoderImpl>, // Wrapper for glCompileShader. void DoCompileShader(GLuint shader); + // Wrapper for glDetachShader + void DoDetachShader(GLuint client_program_id, GLint client_shader_id); + // Wrapper for glDrawArrays. void DoDrawArrays(GLenum mode, GLint first, GLsizei count); @@ -726,10 +688,6 @@ class GLES2DecoderImpl : public base::SupportsWeakPtr<GLES2DecoderImpl>, // Wrapper for glGetShaderiv void DoGetShaderiv(GLuint shader, GLenum pname, GLint* params); - // Wrapper for glGetShaderSource. - void DoGetShaderSource( - GLuint shader, GLsizei bufsize, GLsizei* length, char* dst); - // Wrappers for glIsXXX functions. bool DoIsBuffer(GLuint client_id); bool DoIsFramebuffer(GLuint client_id); @@ -743,7 +701,7 @@ class GLES2DecoderImpl : public base::SupportsWeakPtr<GLES2DecoderImpl>, // Wrapper for glRenderbufferStorage. void DoRenderbufferStorage( - GLenum target, GLenum internalformat, GLsizei width, GLsizei height); + GLenum target, GLenum internalformat, GLsizei width, GLsizei height); // Wrapper for glReleaseShaderCompiler. void DoReleaseShaderCompiler() { } @@ -762,6 +720,9 @@ class GLES2DecoderImpl : public base::SupportsWeakPtr<GLES2DecoderImpl>, // Wrapper for glUseProgram void DoUseProgram(GLuint program); + // Wrapper for glValidateProgram. + void DoValidateProgram(GLuint program_client_id); + // Gets the GLError through our wrapper. GLenum GetGLError(); @@ -947,7 +908,7 @@ ScopedTexture2DBinder::~ScopedTexture2DBinder() { GLES2DecoderImpl::TextureUnit& info = decoder_->texture_units_[0]; GLuint last_id; if (info.bound_texture_2d) - last_id = info.bound_texture_2d->texture_id(); + last_id = info.bound_texture_2d->service_id(); else last_id = 0; @@ -967,7 +928,7 @@ ScopedRenderBufferBinder::~ScopedRenderBufferBinder() { glBindRenderbufferEXT( GL_RENDERBUFFER, decoder_->bound_renderbuffer_ ? - decoder_->bound_renderbuffer_->renderbuffer_id() : 0); + decoder_->bound_renderbuffer_->service_id() : 0); } ScopedFrameBufferBinder::ScopedFrameBufferBinder(GLES2DecoderImpl* decoder, @@ -981,7 +942,7 @@ ScopedFrameBufferBinder::~ScopedFrameBufferBinder() { ScopedGLErrorSuppressor suppressor(decoder_); FramebufferManager::FramebufferInfo* info = decoder_->bound_framebuffer_.get(); - GLuint framebuffer_id = info ? info->framebuffer_id() : 0; + GLuint framebuffer_id = info ? info->service_id() : 0; if (framebuffer_id == 0 && decoder_->offscreen_target_frame_buffer_.get()) { glBindFramebufferEXT(GL_FRAMEBUFFER, @@ -1267,10 +1228,8 @@ bool GLES2DecoderImpl::Initialize(gfx::GLContext* context, // it can reference it. if (parent_) { GLuint service_id = offscreen_saved_color_texture_->id(); - parent_->id_manager()->AddMapping(parent_client_texture_id, - service_id); TextureManager::TextureInfo* info = - parent_->CreateTextureInfo(service_id); + parent_->CreateTextureInfo(parent_client_texture_id, service_id); parent_->texture_manager()->SetInfoTarget(info, GL_TEXTURE_2D); } @@ -1309,133 +1268,124 @@ bool GLES2DecoderImpl::Initialize(gfx::GLContext* context, return true; } -// These commands convert from c calls to local os calls. -void GLGenBuffersHelper( - GLES2DecoderImpl* decoder, GLsizei n, GLuint* ids) { - glGenBuffersARB(n, ids); - // TODO(gman): handle error +bool GLES2DecoderImpl::GenBuffersHelper(GLsizei n, const GLuint* client_ids) { for (GLsizei ii = 0; ii < n; ++ii) { - decoder->CreateBufferInfo(ids[ii]); + if (GetBufferInfo(client_ids[ii])) { + return false; + } } -} - -void GLGenFramebuffersHelper( - GLES2DecoderImpl* decoder, GLsizei n, GLuint* ids) { - glGenFramebuffersEXT(n, ids); - // TODO(gman): handle error + scoped_array<GLuint> service_ids(new GLuint[n]); + glGenBuffersARB(n, service_ids.get()); for (GLsizei ii = 0; ii < n; ++ii) { - decoder->CreateFramebufferInfo(ids[ii]); + CreateBufferInfo(client_ids[ii], service_ids[ii]); } + return true; } -void GLGenRenderbuffersHelper( - GLES2DecoderImpl* decoder, GLsizei n, GLuint* ids) { - glGenRenderbuffersEXT(n, ids); - // TODO(gman): handle error +bool GLES2DecoderImpl::GenFramebuffersHelper( + GLsizei n, const GLuint* client_ids) { for (GLsizei ii = 0; ii < n; ++ii) { - decoder->CreateRenderbufferInfo(ids[ii]); + if (GetFramebufferInfo(client_ids[ii])) { + return false; + } } -} - -void GLGenTexturesHelper( - GLES2DecoderImpl* decoder, GLsizei n, GLuint* ids) { - glGenTextures(n, ids); - // TODO(gman): handle error + scoped_array<GLuint> service_ids(new GLuint[n]); + glGenFramebuffersEXT(n, service_ids.get()); for (GLsizei ii = 0; ii < n; ++ii) { - decoder->CreateTextureInfo(ids[ii]); + CreateFramebufferInfo(client_ids[ii], service_ids[ii]); } + return true; } -void GLDeleteBuffersHelper( - GLES2DecoderImpl* decoder, GLsizei n, GLuint* ids) { - glDeleteBuffersARB(n, ids); - // TODO(gman): handle error +bool GLES2DecoderImpl::GenRenderbuffersHelper( + GLsizei n, const GLuint* client_ids) { for (GLsizei ii = 0; ii < n; ++ii) { - decoder->RemoveBufferInfo(ids[ii]); + if (GetRenderbufferInfo(client_ids[ii])) { + return false; + } } -} - -void GLDeleteFramebuffersHelper( - GLES2DecoderImpl* decoder, GLsizei n, GLuint* ids) { - glDeleteFramebuffersEXT(n, ids); - // TODO(gman): handle error + scoped_array<GLuint> service_ids(new GLuint[n]); + glGenRenderbuffersEXT(n, service_ids.get()); for (GLsizei ii = 0; ii < n; ++ii) { - decoder->RemoveFramebufferInfo(ids[ii]); + CreateRenderbufferInfo(client_ids[ii], service_ids[ii]); } + return true; } -void GLDeleteRenderbuffersHelper( - GLES2DecoderImpl* decoder, GLsizei n, GLuint* ids) { - glDeleteRenderbuffersEXT(n, ids); - // TODO(gman): handle error +bool GLES2DecoderImpl::GenTexturesHelper(GLsizei n, const GLuint* client_ids) { for (GLsizei ii = 0; ii < n; ++ii) { - decoder->RemoveRenderbufferInfo(ids[ii]); + if (GetTextureInfo(client_ids[ii])) { + return false; + } } -} - -void GLDeleteTexturesHelper( - GLES2DecoderImpl* decoder, GLsizei n, GLuint* ids) { - glDeleteTextures(n, ids); - // TODO(gman): handle error + scoped_array<GLuint> service_ids(new GLuint[n]); + glGenTextures(n, service_ids.get()); for (GLsizei ii = 0; ii < n; ++ii) { - decoder->RemoveTextureInfo(ids[ii]); + CreateTextureInfo(client_ids[ii], service_ids[ii]); } -} - -// } // anonymous namespace - -bool GLES2DecoderImpl::MakeCurrent() { -#if defined(UNIT_TEST) return true; -#else - return context_->MakeCurrent(); -#endif } -uint32 GLES2DecoderImpl::GetServiceIdForTesting(uint32 client_id) { -#if defined(UNIT_TEST) - GLuint service_id; - bool result = id_manager()->GetServiceId(client_id, &service_id); - return result ? service_id : 0u; -#else - DCHECK(false); - return 0u; -#endif +void GLES2DecoderImpl::DeleteBuffersHelper( + GLsizei n, const GLuint* client_ids) { + for (GLsizei ii = 0; ii < n; ++ii) { + BufferManager::BufferInfo* info = GetBufferInfo(client_ids[ii]); + if (info) { + GLuint service_id = info->service_id(); + glDeleteBuffersARB(1, &service_id); + RemoveBufferInfo(client_ids[ii]); + } + } } -bool GLES2DecoderImpl::ValidateIdsAreUnused( +void GLES2DecoderImpl::DeleteFramebuffersHelper( GLsizei n, const GLuint* client_ids) { for (GLsizei ii = 0; ii < n; ++ii) { - GLuint service_id; - if (id_manager()->GetServiceId(client_ids[ii], &service_id)) { - return false; + FramebufferManager::FramebufferInfo* info = + GetFramebufferInfo(client_ids[ii]); + if (info) { + GLuint service_id = info->service_id(); + glDeleteFramebuffersEXT(1, &service_id); + RemoveFramebufferInfo(client_ids[ii]); } } - return true; } -bool GLES2DecoderImpl::RegisterObjects( - GLsizei n, const GLuint* client_ids, const GLuint* service_ids) { +void GLES2DecoderImpl::DeleteRenderbuffersHelper( + GLsizei n, const GLuint* client_ids) { for (GLsizei ii = 0; ii < n; ++ii) { - if (!id_manager()->AddMapping(client_ids[ii], service_ids[ii])) { - NOTREACHED(); - return false; + RenderbufferManager::RenderbufferInfo* info = + GetRenderbufferInfo(client_ids[ii]); + if (info) { + GLuint service_id = info->service_id(); + glDeleteRenderbuffersEXT(1, &service_id); + RemoveRenderbufferInfo(client_ids[ii]); } } - return true; } -void GLES2DecoderImpl::UnregisterObjects( - GLsizei n, const GLuint* client_ids, GLuint* service_ids) { +void GLES2DecoderImpl::DeleteTexturesHelper( + GLsizei n, const GLuint* client_ids) { for (GLsizei ii = 0; ii < n; ++ii) { - if (id_manager()->GetServiceId(client_ids[ii], &service_ids[ii])) { - id_manager()->RemoveMapping(client_ids[ii], service_ids[ii]); - } else { - service_ids[ii] = 0; + TextureManager::TextureInfo* info = GetTextureInfo(client_ids[ii]); + if (info) { + GLuint service_id = info->service_id(); + glDeleteTextures(1, &service_id); + RemoveTextureInfo(client_ids[ii]); } } } +// } // anonymous namespace + +bool GLES2DecoderImpl::MakeCurrent() { +#if defined(UNIT_TEST) + return true; +#else + return context_->MakeCurrent(); +#endif +} + gfx::Size GLES2DecoderImpl::GetBoundFrameBufferSize() { if (bound_framebuffer_ != 0) { int width = 0; @@ -1479,23 +1429,26 @@ gfx::Size GLES2DecoderImpl::GetBoundFrameBufferSize() { GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, &texture_id); if (texture_id != 0) { - TextureManager::TextureInfo* texture_info = - GetTextureInfo(texture_id); - if (texture_info) { - GLint level = 0; - GLint face = 0; - glGetFramebufferAttachmentParameterivEXT( - GL_FRAMEBUFFER, - GL_COLOR_ATTACHMENT0, - GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL, - &level); - glGetFramebufferAttachmentParameterivEXT( - GL_FRAMEBUFFER, - GL_COLOR_ATTACHMENT0, - GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE, - &face); - texture_info->GetLevelSize( - face ? face : GL_TEXTURE_2D, level, &width, &height); + GLuint client_id = 0; + if (texture_manager()->GetClientId(texture_id, &client_id)) { + TextureManager::TextureInfo* texture_info = + GetTextureInfo(client_id); + if (texture_info) { + GLint level = 0; + GLint face = 0; + glGetFramebufferAttachmentParameterivEXT( + GL_FRAMEBUFFER, + GL_COLOR_ATTACHMENT0, + GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL, + &level); + glGetFramebufferAttachmentParameterivEXT( + GL_FRAMEBUFFER, + GL_COLOR_ATTACHMENT0, + GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE, + &face); + texture_info->GetLevelSize( + face ? face : GL_TEXTURE_2D, level, &width, &height); + } } } break; @@ -1628,10 +1581,9 @@ void GLES2DecoderImpl::Destroy() { // First check the texture has been mapped into the parent. This might not // be the case if initialization failed midway through. GLuint service_id = offscreen_saved_color_texture_->id(); - GLuint client_id; - if (parent_->id_manager()->GetClientId(service_id, &client_id)) { - parent_->texture_manager()->RemoveTextureInfo(service_id); - parent_->id_manager()->RemoveMapping(client_id, service_id); + GLuint client_id = 0; + if (parent_->texture_manager()->GetClientId(service_id, &client_id)) { + parent_->texture_manager()->RemoveTextureInfo(client_id); } } @@ -1732,43 +1684,30 @@ error::Error GLES2DecoderImpl::DoCommand( return result; } -void GLES2DecoderImpl::RemoveBufferInfo(GLuint buffer_id) { - buffer_manager()->RemoveBufferInfo(buffer_id); - // TODO(gman): See if we can remove the rest of this function as - // buffers are now reference counted and have a "IsDeleted" function. - if (bound_array_buffer_ && bound_array_buffer_->buffer_id() == buffer_id) { - bound_array_buffer_ = NULL; - } - if (bound_element_array_buffer_ && - bound_element_array_buffer_->buffer_id() == buffer_id) { - bound_element_array_buffer_ = NULL; - } - - // go through VertexAttribInfo and update any info that references the buffer. - for (GLuint ii = 0; ii < group_->max_vertex_attribs(); ++ii) { - VertexAttribInfo& info = vertex_attrib_infos_[ii]; - if (info.buffer() && info.buffer()->buffer_id() == buffer_id) { - info.ClearBuffer(); - } - } +void GLES2DecoderImpl::RemoveBufferInfo(GLuint client_id) { + buffer_manager()->RemoveBufferInfo(client_id); } -void GLES2DecoderImpl::CreateProgramHelper(GLuint client_id) { - // TODO(gman): verify client_id is unused. +bool GLES2DecoderImpl::CreateProgramHelper(GLuint client_id) { + if (GetProgramInfo(client_id)) { + return false; + } GLuint service_id = glCreateProgram(); - if (service_id) { - id_manager()->AddMapping(client_id, service_id); - CreateProgramInfo(service_id); + if (service_id != 0) { + CreateProgramInfo(client_id, service_id); } + return true; } -void GLES2DecoderImpl::CreateShaderHelper(GLenum type, GLuint client_id) { - // TODO(gman): verify client_id is unused. +bool GLES2DecoderImpl::CreateShaderHelper(GLenum type, GLuint client_id) { + if (GetShaderInfo(client_id)) { + return false; + } GLuint service_id = glCreateShader(type); - if (service_id) { - id_manager()->AddMapping(client_id, service_id); - CreateShaderInfo(service_id); + if (service_id != 0) { + CreateShaderInfo(client_id, service_id); } + return true; } bool GLES2DecoderImpl::ValidateGLenumCompressedTextureInternalFormat(GLenum) { @@ -1789,23 +1728,26 @@ void GLES2DecoderImpl::DoActiveTexture(GLenum texture_unit) { void GLES2DecoderImpl::DoBindBuffer(GLenum target, GLuint client_id) { BufferManager::BufferInfo* info = NULL; GLuint service_id = 0; - if (client_id != 0 && !id_manager()->GetServiceId(client_id, &service_id)) { - // It's a new id so make a buffer info for it. - glGenBuffersARB(1, &service_id); - RegisterObjects(1, &client_id, &service_id); - CreateBufferInfo(service_id); - } - if (service_id) { - info = GetBufferInfo(service_id); + if (client_id != 0) { + info = GetBufferInfo(client_id); + if (!info) { + // It's a new id so make a buffer info for it. + glGenBuffersARB(1, &service_id); + CreateBufferInfo(client_id, service_id); + info = GetBufferInfo(client_id); + } + } + if (info) { // Check the buffer exists // Check that we are not trying to bind it to a different target. - if (!info || (info->target() != 0 && info->target() != target)) { + if ((info->target() != 0 && info->target() != target)) { SetGLError(GL_INVALID_OPERATION); return; } if (info->target() == 0) { info->set_target(target); } + service_id = info->service_id(); } switch (target) { case GL_ARRAY_BUFFER: @@ -1824,18 +1766,15 @@ void GLES2DecoderImpl::DoBindBuffer(GLenum target, GLuint client_id) { void GLES2DecoderImpl::DoBindFramebuffer(GLenum target, GLuint client_id) { FramebufferManager::FramebufferInfo* info = NULL; GLuint service_id = 0; - if (client_id != 0 && !id_manager()->GetServiceId(client_id, &service_id)) { - // It's a new id so make a framebuffer info for it. - glGenFramebuffersEXT(1, &service_id); - RegisterObjects(1, &client_id, &service_id); - CreateFramebufferInfo(service_id); - } - if (service_id) { - info = GetFramebufferInfo(service_id); - // Check the framebuffer exists + if (client_id != 0) { + info = GetFramebufferInfo(client_id); if (!info) { - SetGLError(GL_INVALID_OPERATION); - return; + // It's a new id so make a framebuffer info for it. + glGenFramebuffersEXT(1, &service_id); + CreateFramebufferInfo(client_id, service_id); + info = GetFramebufferInfo(client_id); + } else { + service_id = info->service_id(); } } bound_framebuffer_ = info; @@ -1851,18 +1790,14 @@ void GLES2DecoderImpl::DoBindFramebuffer(GLenum target, GLuint client_id) { void GLES2DecoderImpl::DoBindRenderbuffer(GLenum target, GLuint client_id) { RenderbufferManager::RenderbufferInfo* info = NULL; GLuint service_id = 0; - if (client_id != 0 && !id_manager()->GetServiceId(client_id, &service_id)) { - // It's a new id so make a renderbuffer info for it. - glGenRenderbuffersEXT(1, &service_id); - RegisterObjects(1, &client_id, &service_id); - CreateRenderbufferInfo(service_id); - } - if (service_id) { - info = GetRenderbufferInfo(service_id); - // Check the renderbuffer exists + if (client_id != 0) { + info = GetRenderbufferInfo(client_id); if (!info) { - SetGLError(GL_INVALID_OPERATION); - return; + // It's a new id so make a renderbuffer info for it. + glGenRenderbuffersEXT(1, &service_id); + CreateRenderbufferInfo(client_id, service_id); + } else { + service_id = info->service_id(); } } bound_renderbuffer_ = info; @@ -1870,26 +1805,30 @@ void GLES2DecoderImpl::DoBindRenderbuffer(GLenum target, GLuint client_id) { } void GLES2DecoderImpl::DoBindTexture(GLenum target, GLuint client_id) { + TextureManager::TextureInfo* info = NULL; GLuint service_id = 0; - if (client_id != 0 && !id_manager()->GetServiceId(client_id, &service_id)) { - // It's a new id so make a texture info for it. - glGenTextures(1, &service_id); - RegisterObjects(1, &client_id, &service_id); - CreateTextureInfo(service_id); - } - TextureManager::TextureInfo* info = - service_id ? GetTextureInfo(service_id) : - texture_manager()->GetDefaultTextureInfo(target); + if (client_id != 0) { + info = GetTextureInfo(client_id); + if (!info) { + // It's a new id so make a texture info for it. + glGenTextures(1, &service_id); + CreateTextureInfo(client_id, service_id); + info = GetTextureInfo(client_id); + } + } else { + info = texture_manager()->GetDefaultTextureInfo(target); + } + // Check the texture exists // Check that we are not trying to bind it to a different target. - if (!info || (info->target() != 0 && info->target() != target)) { + if (info->target() != 0 && info->target() != target) { SetGLError(GL_INVALID_OPERATION); return; } if (info->target() == 0) { texture_manager()->SetInfoTarget(info, target); } - glBindTexture(target, service_id); + glBindTexture(target, info->service_id()); TextureUnit& unit = texture_units_[active_texture_unit_]; unit.bind_target = target; switch (target) { @@ -2030,8 +1969,8 @@ void GLES2DecoderImpl::DoGetProgramiv( error::Error GLES2DecoderImpl::HandleBindAttribLocation( uint32 immediate_data_size, const gles2::BindAttribLocation& c) { - GLuint program; - if (!id_manager()->GetServiceId(c.program, &program)) { + ProgramManager::ProgramInfo* info = GetProgramInfo(c.program); + if (!info) { SetGLError(GL_INVALID_VALUE); return error::kNoError; } @@ -2043,14 +1982,14 @@ error::Error GLES2DecoderImpl::HandleBindAttribLocation( return error::kOutOfBounds; } String name_str(name, name_size); - glBindAttribLocation(program, index, name_str.c_str()); + glBindAttribLocation(info->service_id(), index, name_str.c_str()); return error::kNoError; } error::Error GLES2DecoderImpl::HandleBindAttribLocationImmediate( uint32 immediate_data_size, const gles2::BindAttribLocationImmediate& c) { - GLuint program; - if (!id_manager()->GetServiceId(c.program, &program)) { + ProgramManager::ProgramInfo* info = GetProgramInfo(c.program); + if (!info) { SetGLError(GL_INVALID_VALUE); return error::kNoError; } @@ -2062,14 +2001,14 @@ error::Error GLES2DecoderImpl::HandleBindAttribLocationImmediate( return error::kOutOfBounds; } String name_str(name, name_size); - glBindAttribLocation(program, index, name_str.c_str()); + glBindAttribLocation(info->service_id(), index, name_str.c_str()); return error::kNoError; } error::Error GLES2DecoderImpl::HandleBindAttribLocationBucket( uint32 immediate_data_size, const gles2::BindAttribLocationBucket& c) { - GLuint program; - if (!id_manager()->GetServiceId(c.program, &program)) { + ProgramManager::ProgramInfo* info = GetProgramInfo(c.program); + if (!info) { SetGLError(GL_INVALID_VALUE); return error::kNoError; } @@ -2080,35 +2019,37 @@ error::Error GLES2DecoderImpl::HandleBindAttribLocationBucket( } std::string name_str; bucket->GetAsString(&name_str); - glBindAttribLocation(program, index, name_str.c_str()); + glBindAttribLocation(info->service_id(), index, name_str.c_str()); return error::kNoError; } error::Error GLES2DecoderImpl::HandleDeleteShader( uint32 immediate_data_size, const gles2::DeleteShader& c) { - GLuint shader = c.shader; - GLuint service_id; - if (!id_manager()->GetServiceId(shader, &service_id)) { - SetGLError(GL_INVALID_VALUE); - return error::kNoError; + GLuint client_id = c.shader; + if (client_id) { + ShaderManager::ShaderInfo* info = GetShaderInfo(client_id); + if (info) { + glDeleteShader(info->service_id()); + RemoveShaderInfo(client_id); + } else { + SetGLError(GL_INVALID_VALUE); + } } - RemoveShaderInfo(service_id); - glDeleteShader(service_id); - id_manager()->RemoveMapping(shader, service_id); return error::kNoError; } error::Error GLES2DecoderImpl::HandleDeleteProgram( uint32 immediate_data_size, const gles2::DeleteProgram& c) { - GLuint program = c.program; - GLuint service_id; - if (!id_manager()->GetServiceId(program, &service_id)) { - SetGLError(GL_INVALID_VALUE); - return error::kNoError; + GLuint client_id = c.program; + if (client_id) { + ProgramManager::ProgramInfo* info = GetProgramInfo(client_id); + if (info) { + glDeleteProgram(info->service_id()); + RemoveProgramInfo(client_id); + } else { + SetGLError(GL_INVALID_VALUE); + } } - RemoveProgramInfo(service_id); - glDeleteProgram(service_id); - id_manager()->RemoveMapping(program, service_id); return error::kNoError; } @@ -2126,13 +2067,23 @@ void GLES2DecoderImpl::DoDrawArrays( void GLES2DecoderImpl::DoFramebufferRenderbuffer( GLenum target, GLenum attachment, GLenum renderbuffertarget, - GLuint renderbuffer) { + GLuint client_renderbuffer_id) { if (!bound_framebuffer_) { SetGLError(GL_INVALID_OPERATION); return; } - glFramebufferRenderbufferEXT(target, attachment, renderbuffertarget, - renderbuffer); + GLuint service_id = 0; + if (client_renderbuffer_id) { + RenderbufferManager::RenderbufferInfo* info = + GetRenderbufferInfo(client_renderbuffer_id); + if (!info) { + SetGLError(GL_INVALID_OPERATION); + return; + } + service_id = info->service_id(); + } + glFramebufferRenderbufferEXT( + target, attachment, renderbuffertarget, service_id); } GLenum GLES2DecoderImpl::DoCheckFramebufferStatus(GLenum target) { @@ -2143,13 +2094,22 @@ GLenum GLES2DecoderImpl::DoCheckFramebufferStatus(GLenum target) { } void GLES2DecoderImpl::DoFramebufferTexture2D( - GLenum target, GLenum attachment, GLenum textarget, GLuint texture, - GLint level) { + GLenum target, GLenum attachment, GLenum textarget, + GLuint client_texture_id, GLint level) { if (!bound_framebuffer_) { SetGLError(GL_INVALID_OPERATION); return; } - glFramebufferTexture2DEXT(target, attachment, textarget, texture, level); + GLuint service_id = 0; + if (client_texture_id) { + TextureManager::TextureInfo* info = GetTextureInfo(client_texture_id); + if (!info) { + SetGLError(GL_INVALID_OPERATION); + return; + } + service_id = info->service_id(); + } + glFramebufferTexture2DEXT(target, attachment, textarget, service_id, level); } void GLES2DecoderImpl::DoGetFramebufferAttachmentParameteriv( @@ -2186,10 +2146,10 @@ void GLES2DecoderImpl::DoLinkProgram(GLuint program) { return; } CopyRealGLErrorsToWrapper(); - glLinkProgram(program); + glLinkProgram(info->service_id()); GLenum error = glGetError(); if (error != GL_NO_ERROR) { - RemoveProgramInfo(program); + info->Reset(); SetGLError(error); } else { info->Update(); @@ -2262,17 +2222,23 @@ void GLES2DecoderImpl::DoUniform1iv( } void GLES2DecoderImpl::DoUseProgram(GLuint program) { + GLuint service_id = 0; ProgramManager::ProgramInfo* info = NULL; if (program) { info = GetProgramInfo(program); if (!info) { + SetGLError(GL_INVALID_VALUE); + return; + } + if (!info->IsValid()) { // Program was not linked successfully. (ie, glLinkProgram) SetGLError(GL_INVALID_OPERATION); return; } + service_id = info->service_id(); } current_program_ = info; - glUseProgram(program); + glUseProgram(service_id); } GLenum GLES2DecoderImpl::GetGLError() { @@ -2393,7 +2359,7 @@ void GLES2DecoderImpl::RestoreStateForNonRenderableTextures() { texture_unit.bound_texture_2d : texture_unit.bound_texture_cube_map; glBindTexture(texture_unit.bind_target, - texture_info ? texture_info->texture_id() : 0); + texture_info ? texture_info->service_id() : 0); } } } @@ -2466,10 +2432,12 @@ GLuint GLES2DecoderImpl::DoGetMaxValueInBuffer( GLuint buffer_id, GLsizei count, GLenum type, GLuint offset) { GLuint max_vertex_accessed = 0; BufferManager::BufferInfo* info = GetBufferInfo(buffer_id); - if (info->target() != GL_ELEMENT_ARRAY_BUFFER) { + if (!info || info->target() != GL_ELEMENT_ARRAY_BUFFER) { + // TODO(gman): Should this be a GL error or a command buffer error? SetGLError(GL_INVALID_OPERATION); } else { if (!info->GetMaxValueForRange(offset, count, type, &max_vertex_accessed)) { + // TODO(gman): Should this be a GL error or a command buffer error? SetGLError(GL_INVALID_OPERATION); } } @@ -2481,10 +2449,10 @@ GLuint GLES2DecoderImpl::DoGetMaxValueInBuffer( // of whatever context it came from (shared memory, immediate memory, bucket // memory.) error::Error GLES2DecoderImpl::ShaderSourceHelper( - GLuint shader, const char* data, uint32 data_size) { - ShaderManager::ShaderInfo* info = GetShaderInfo(shader); + GLuint client_id, const char* data, uint32 data_size) { + ShaderManager::ShaderInfo* info = GetShaderInfo(client_id); if (!info) { - SetGLError(GL_INVALID_OPERATION); + SetGLError(GL_INVALID_VALUE); return error::kNoError; } // Note: We don't actually call glShaderSource here. We wait until @@ -2495,59 +2463,43 @@ error::Error GLES2DecoderImpl::ShaderSourceHelper( error::Error GLES2DecoderImpl::HandleShaderSource( uint32 immediate_data_size, const gles2::ShaderSource& c) { - GLuint shader; - if (!id_manager()->GetServiceId(c.shader, &shader)) { - SetGLError(GL_INVALID_VALUE); - return error::kNoError; - } uint32 data_size = c.data_size; const char* data = GetSharedMemoryAs<const char*>( c.data_shm_id, c.data_shm_offset, data_size); if (!data) { return error::kOutOfBounds; } - return ShaderSourceHelper(shader, data, data_size); + return ShaderSourceHelper(c.shader, data, data_size); } error::Error GLES2DecoderImpl::HandleShaderSourceImmediate( uint32 immediate_data_size, const gles2::ShaderSourceImmediate& c) { - GLuint shader; - if (!id_manager()->GetServiceId(c.shader, &shader)) { - SetGLError(GL_INVALID_VALUE); - return error::kNoError; - } uint32 data_size = c.data_size; const char* data = GetImmediateDataAs<const char*>( c, data_size, immediate_data_size); if (!data) { return error::kOutOfBounds; } - return ShaderSourceHelper(shader, data, data_size); + return ShaderSourceHelper(c.shader, data, data_size); } error::Error GLES2DecoderImpl::HandleShaderSourceBucket( uint32 immediate_data_size, const gles2::ShaderSourceBucket& c) { - GLuint shader; - if (!id_manager()->GetServiceId(c.shader, &shader)) { - SetGLError(GL_INVALID_VALUE); - return error::kNoError; - } Bucket* bucket = GetBucket(c.data_bucket_id); if (!bucket || bucket->size() == 0) { return error::kInvalidArguments; } return ShaderSourceHelper( - shader, bucket->GetDataAs<const char*>(0, bucket->size() - 1), + c.shader, bucket->GetDataAs<const char*>(0, bucket->size() - 1), bucket->size() - 1); } -void GLES2DecoderImpl::DoCompileShader(GLuint shader) { - ShaderManager::ShaderInfo* info = GetShaderInfo(shader); +void GLES2DecoderImpl::DoCompileShader(GLuint client_id) { + ShaderManager::ShaderInfo* info = GetShaderInfo(client_id); if (!info) { - SetGLError(GL_INVALID_OPERATION); + SetGLError(GL_INVALID_VALUE); return; } - // Translate GL ES 2.0 shader to Desktop GL shader and pass that to // glShaderSource and then glCompileShader. const char* shader_src = info->source().c_str(); @@ -2578,8 +2530,8 @@ void GLES2DecoderImpl::DoCompileShader(GLuint shader) { #endif // GLES2_GPU_SERVICE_TRANSLATE_SHADER #endif // GLES2_GPU_SERVICE_BACKEND_NATIVE_GLES2 - glShaderSource(shader, 1, &shader_src, NULL); - glCompileShader(shader); + glShaderSource(info->service_id(), 1, &shader_src, NULL); + glCompileShader(info->service_id()); #if !defined(GLES2_GPU_SERVICE_BACKEND_NATIVE_GLES2) #ifdef GLES2_GPU_SERVICE_TRANSLATE_SHADER @@ -2598,74 +2550,123 @@ void GLES2DecoderImpl::DoGetShaderiv( if (pname == GL_SHADER_SOURCE_LENGTH) { *params = info->source().size(); } else { - glGetShaderiv(shader, pname, params); + glGetShaderiv(info->service_id(), pname, params); } } -void GLES2DecoderImpl::DoGetShaderSource( - GLuint shader, GLsizei bufsize, GLsizei* length, char* dst) { +error::Error GLES2DecoderImpl::HandleGetShaderSource( + uint32 immediate_data_size, const gles2::GetShaderSource& c) { + GLuint shader = c.shader; ShaderManager::ShaderInfo* info = GetShaderInfo(shader); if (!info) { - SetGLError(GL_INVALID_OPERATION); - return; + SetGLError(GL_INVALID_VALUE); + return error::kNoError; + } + uint32 bucket_id = static_cast<uint32>(c.bucket_id); + Bucket* bucket = CreateBucket(bucket_id); + bucket->SetFromString(info->source()); + return error::kNoError; +} + +error::Error GLES2DecoderImpl::HandleGetProgramInfoLog( + uint32 immediate_data_size, const gles2::GetProgramInfoLog& c) { + GLuint program = c.program; + ProgramManager::ProgramInfo* info = GetProgramInfo(program); + if (!info) { + SetGLError(GL_INVALID_VALUE); + return error::kNoError; } - // bufsize is set by the service side code and should always be positive. - DCHECK_GT(bufsize, 0); - const std::string& source = info->source(); - GLsizei size = std::min(bufsize - 1, static_cast<GLsizei>(source.size())); - if (length) { - *length = size; + uint32 bucket_id = static_cast<uint32>(c.bucket_id); + GLint len = 0; + glGetProgramiv(info->service_id(), GL_INFO_LOG_LENGTH, &len); + Bucket* bucket = CreateBucket(bucket_id); + bucket->SetSize(len + 1); + glGetProgramInfoLog( + info->service_id(), + len + 1, &len, bucket->GetDataAs<GLchar*>(0, len + 1)); + return error::kNoError; +} + +error::Error GLES2DecoderImpl::HandleGetShaderInfoLog( + uint32 immediate_data_size, const gles2::GetShaderInfoLog& c) { + GLuint shader = c.shader; + ShaderManager::ShaderInfo* info = GetShaderInfo(shader); + if (!info) { + SetGLError(GL_INVALID_VALUE); + return error::kNoError; } - memcpy(dst, source.c_str(), size); - dst[size] = '\0'; + uint32 bucket_id = static_cast<uint32>(c.bucket_id); + GLint len = 0; + glGetShaderiv(info->service_id(), GL_INFO_LOG_LENGTH, &len); + Bucket* bucket = CreateBucket(bucket_id); + bucket->SetSize(len + 1); + glGetShaderInfoLog( + info->service_id(), + len + 1, &len, bucket->GetDataAs<GLchar*>(0, len + 1)); + return error::kNoError; } bool GLES2DecoderImpl::DoIsBuffer(GLuint client_id) { - GLuint service_id = 0; - if (!id_manager()->GetServiceId(client_id, &service_id)) { - return false; - } - return GetBufferInfo(service_id) != NULL; + return GetBufferInfo(client_id) != NULL; } bool GLES2DecoderImpl::DoIsFramebuffer(GLuint client_id) { - GLuint service_id = 0; - if (!id_manager()->GetServiceId(client_id, &service_id)) { - return false; - } - return GetFramebufferInfo(service_id) != NULL; + return GetFramebufferInfo(client_id) != NULL; } bool GLES2DecoderImpl::DoIsProgram(GLuint client_id) { - GLuint service_id = 0; - if (!id_manager()->GetServiceId(client_id, &service_id)) { - return false; - } - return GetProgramInfo(service_id) != NULL; + return GetProgramInfo(client_id) != NULL; } bool GLES2DecoderImpl::DoIsRenderbuffer(GLuint client_id) { - GLuint service_id = 0; - if (!id_manager()->GetServiceId(client_id, &service_id)) { - return false; - } - return GetRenderbufferInfo(service_id) != NULL; + return GetRenderbufferInfo(client_id) != NULL; } bool GLES2DecoderImpl::DoIsShader(GLuint client_id) { - GLuint service_id = 0; - if (!id_manager()->GetServiceId(client_id, &service_id)) { - return false; - } - return GetShaderInfo(service_id) != NULL; + return GetShaderInfo(client_id) != NULL; } bool GLES2DecoderImpl::DoIsTexture(GLuint client_id) { - GLuint service_id = 0; - if (!id_manager()->GetServiceId(client_id, &service_id)) { - return false; + return GetTextureInfo(client_id) != NULL; +} + +void GLES2DecoderImpl::DoAttachShader( + GLuint program_client_id, GLint shader_client_id) { + ProgramManager::ProgramInfo* program_info = GetProgramInfo(program_client_id); + if (!program_info) { + SetGLError(GL_INVALID_VALUE); + return; + } + ShaderManager::ShaderInfo* shader_info = GetShaderInfo(shader_client_id); + if (!shader_info) { + SetGLError(GL_INVALID_VALUE); + return; } - return GetTextureInfo(service_id) != NULL; + glAttachShader(program_info->service_id(), shader_info->service_id()); +} + +void GLES2DecoderImpl::DoDetachShader( + GLuint program_client_id, GLint shader_client_id) { + ProgramManager::ProgramInfo* program_info = GetProgramInfo(program_client_id); + if (!program_info) { + SetGLError(GL_INVALID_VALUE); + return; + } + ShaderManager::ShaderInfo* shader_info = GetShaderInfo(shader_client_id); + if (!shader_info) { + SetGLError(GL_INVALID_VALUE); + return; + } + glDetachShader(program_info->service_id(), shader_info->service_id()); +} + +void GLES2DecoderImpl::DoValidateProgram(GLuint program_client_id) { + ProgramManager::ProgramInfo* info = GetProgramInfo(program_client_id); + if (!info) { + SetGLError(GL_INVALID_VALUE); + return; + } + glValidateProgram(info->service_id()); } error::Error GLES2DecoderImpl::HandleVertexAttribPointer( @@ -2846,14 +2847,12 @@ error::Error GLES2DecoderImpl::HandlePixelStorei( error::Error GLES2DecoderImpl::GetAttribLocationHelper( GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset, const std::string& name_str) { - GLuint program; - if (!id_manager()->GetServiceId(client_id, &program)) { + ProgramManager::ProgramInfo* info = GetProgramInfo(client_id); + if (!info) { SetGLError(GL_INVALID_VALUE); return error::kNoError; } - ProgramManager::ProgramInfo* info = GetProgramInfo(program); - if (!info) { - // Program was not linked successfully. (ie, glLinkProgram) + if (!info->IsValid()) { SetGLError(GL_INVALID_OPERATION); return error::kNoError; } @@ -2912,14 +2911,12 @@ error::Error GLES2DecoderImpl::HandleGetAttribLocationBucket( error::Error GLES2DecoderImpl::GetUniformLocationHelper( GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset, const std::string& name_str) { - GLuint program; - if (!id_manager()->GetServiceId(client_id, &program)) { + ProgramManager::ProgramInfo* info = GetProgramInfo(client_id); + if (!info) { SetGLError(GL_INVALID_VALUE); return error::kNoError; } - ProgramManager::ProgramInfo* info = GetProgramInfo(program); - if (!info) { - // Program was not linked successfully. (ie, glLinkProgram) + if (!info->IsValid()) { SetGLError(GL_INVALID_OPERATION); return error::kNoError; } @@ -3303,16 +3300,17 @@ bool GLES2DecoderImpl::GetUniformSetup( *result_pointer = result; // Set the result size to 0 so the client does not have to check for success. result->SetNumResults(0); - if (!id_manager()->GetServiceId(program, service_id)) { + ProgramManager::ProgramInfo* info = GetProgramInfo(program); + if (!info) { SetGLError(GL_INVALID_VALUE); - return error::kNoError; + return false; } - ProgramManager::ProgramInfo* info = GetProgramInfo(*service_id); - if (!info) { + if (!info->IsValid()) { // Program was not linked successfully. (ie, glLinkProgram) SetGLError(GL_INVALID_OPERATION); return false; } + *service_id = info->service_id(); GLenum type; if (!info->GetUniformTypeByLocation(location, &type)) { // No such location. @@ -3413,9 +3411,9 @@ error::Error GLES2DecoderImpl::HandleGetShaderPrecisionFormat( error::Error GLES2DecoderImpl::HandleGetAttachedShaders( uint32 immediate_data_size, const gles2::GetAttachedShaders& c) { - GLuint service_id; uint32 result_size = c.result_size; - if (!id_manager()->GetServiceId(c.program, &service_id)) { + ProgramManager::ProgramInfo* info = GetProgramInfo(c.program); + if (!info) { SetGLError(GL_INVALID_VALUE); return error::kNoError; } @@ -3431,10 +3429,11 @@ error::Error GLES2DecoderImpl::HandleGetAttachedShaders( return error::kInvalidArguments; } GLsizei count = 0; - glGetAttachedShaders(service_id, max_count, &count, result->GetData()); + glGetAttachedShaders( + info->service_id(), max_count, &count, result->GetData()); for (GLsizei ii = 0; ii < count; ++ii) { - if (!id_manager()->GetClientId(result->GetData()[ii], - &result->GetData()[ii])) { + if (!shader_manager()->GetClientId(result->GetData()[ii], + &result->GetData()[ii])) { NOTREACHED(); return error::kGenericError; } @@ -3448,7 +3447,6 @@ error::Error GLES2DecoderImpl::HandleGetActiveUniform( GLuint program = c.program; GLuint index = c.index; uint32 name_bucket_id = c.name_bucket_id; - GLuint service_id; typedef gles2::GetActiveUniform::Result Result; Result* result = GetSharedMemoryAs<Result*>( c.result_shm_id, c.result_shm_offset, sizeof(*result)); @@ -3459,14 +3457,14 @@ error::Error GLES2DecoderImpl::HandleGetActiveUniform( if (result->success != 0) { return error::kInvalidArguments; } - if (!id_manager()->GetServiceId(program, &service_id)) { + ProgramManager::ProgramInfo* info = GetProgramInfo(program); + if (!info) { SetGLError(GL_INVALID_VALUE); return error::kNoError; } - ProgramManager::ProgramInfo* info = GetProgramInfo(service_id); - if (!info) { + if (!info->IsValid()) { // Program was not linked successfully. (ie, glLinkProgram) - SetGLError(GL_INVALID_OPERATION); + SetGLError(GL_INVALID_VALUE); return error::kNoError; } const ProgramManager::ProgramInfo::UniformInfo* uniform_info = @@ -3488,7 +3486,6 @@ error::Error GLES2DecoderImpl::HandleGetActiveAttrib( GLuint program = c.program; GLuint index = c.index; uint32 name_bucket_id = c.name_bucket_id; - GLuint service_id; typedef gles2::GetActiveAttrib::Result Result; Result* result = GetSharedMemoryAs<Result*>( c.result_shm_id, c.result_shm_offset, sizeof(*result)); @@ -3499,12 +3496,12 @@ error::Error GLES2DecoderImpl::HandleGetActiveAttrib( if (result->success != 0) { return error::kInvalidArguments; } - if (!id_manager()->GetServiceId(program, &service_id)) { + ProgramManager::ProgramInfo* info = GetProgramInfo(program); + if (!info) { SetGLError(GL_INVALID_VALUE); return error::kNoError; } - ProgramManager::ProgramInfo* info = GetProgramInfo(service_id); - if (!info) { + if (!info->IsValid()) { // Program was not linked successfully. (ie, glLinkProgram) SetGLError(GL_INVALID_OPERATION); return error::kNoError; @@ -3553,11 +3550,12 @@ error::Error GLES2DecoderImpl::HandleShaderBinary( } scoped_array<GLuint> service_ids(new GLuint[n]); for (GLsizei ii = 0; ii < n; ++ii) { - if (!id_manager()->GetServiceId(shaders[ii], &service_ids[ii])) { + ShaderManager::ShaderInfo* info = GetShaderInfo(shaders[ii]); + if (!info) { SetGLError(GL_INVALID_VALUE); return error::kNoError; } - // TODO(gman): Check that each shader exists. + service_ids[ii] = info->service_id(); } // TODO(gman): call glShaderBinary return error::kNoError; diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.h b/gpu/command_buffer/service/gles2_cmd_decoder.h index 4acd379..e0829cf 100644 --- a/gpu/command_buffer/service/gles2_cmd_decoder.h +++ b/gpu/command_buffer/service/gles2_cmd_decoder.h @@ -67,9 +67,6 @@ class GLES2Decoder : public CommonDecoder { // Make this decoder's GL context current. virtual bool MakeCurrent() = 0; - // Gets a service id by client id. - virtual uint32 GetServiceIdForTesting(uint32 client_id) = 0; - // Gets the GLES2 Util which holds info. virtual GLES2Util* GetGLES2Util() = 0; diff --git a/gpu/command_buffer/service/gles2_cmd_decoder_autogen.h b/gpu/command_buffer/service/gles2_cmd_decoder_autogen.h index 0412a1d..45c2515 100644 --- a/gpu/command_buffer/service/gles2_cmd_decoder_autogen.h +++ b/gpu/command_buffer/service/gles2_cmd_decoder_autogen.h @@ -17,17 +17,9 @@ error::Error GLES2DecoderImpl::HandleActiveTexture( error::Error GLES2DecoderImpl::HandleAttachShader( uint32 immediate_data_size, const gles2::AttachShader& c) { - GLuint program; - if (!id_manager()->GetServiceId(c.program, &program)) { - SetGLError(GL_INVALID_VALUE); - return error::kNoError; - } - GLuint shader; - if (!id_manager()->GetServiceId(c.shader, &shader)) { - SetGLError(GL_INVALID_VALUE); - return error::kNoError; - } - glAttachShader(program, shader); + GLuint program = c.program; + GLuint shader = c.shader; + DoAttachShader(program, shader); return error::kNoError; } @@ -264,11 +256,7 @@ error::Error GLES2DecoderImpl::HandleColorMask( error::Error GLES2DecoderImpl::HandleCompileShader( uint32 immediate_data_size, const gles2::CompileShader& c) { - GLuint shader; - if (!id_manager()->GetServiceId(c.shader, &shader)) { - SetGLError(GL_INVALID_VALUE); - return error::kNoError; - } + GLuint shader = c.shader; DoCompileShader(shader); return error::kNoError; } @@ -403,7 +391,9 @@ error::Error GLES2DecoderImpl::HandleCopyTexSubImage2D( error::Error GLES2DecoderImpl::HandleCreateProgram( uint32 immediate_data_size, const gles2::CreateProgram& c) { uint32 client_id = c.client_id; - CreateProgramHelper(client_id); + if (!CreateProgramHelper(client_id)) { + return error::kInvalidArguments; + } return error::kNoError; } @@ -415,7 +405,9 @@ error::Error GLES2DecoderImpl::HandleCreateShader( return error::kNoError; } uint32 client_id = c.client_id; - CreateShaderHelper(type, client_id); + if (!CreateShaderHelper(type, client_id)) { + return error::kInvalidArguments; + } return error::kNoError; } @@ -446,7 +438,7 @@ error::Error GLES2DecoderImpl::HandleDeleteBuffers( if (buffers == NULL) { return error::kOutOfBounds; } - DeleteGLObjects<GLDeleteBuffersHelper>(n, buffers); + DeleteBuffersHelper(n, buffers); return error::kNoError; } @@ -466,7 +458,7 @@ error::Error GLES2DecoderImpl::HandleDeleteBuffersImmediate( if (buffers == NULL) { return error::kOutOfBounds; } - DeleteGLObjects<GLDeleteBuffersHelper>(n, buffers); + DeleteBuffersHelper(n, buffers); return error::kNoError; } @@ -486,7 +478,7 @@ error::Error GLES2DecoderImpl::HandleDeleteFramebuffers( if (framebuffers == NULL) { return error::kOutOfBounds; } - DeleteGLObjects<GLDeleteFramebuffersHelper>(n, framebuffers); + DeleteFramebuffersHelper(n, framebuffers); return error::kNoError; } @@ -506,7 +498,7 @@ error::Error GLES2DecoderImpl::HandleDeleteFramebuffersImmediate( if (framebuffers == NULL) { return error::kOutOfBounds; } - DeleteGLObjects<GLDeleteFramebuffersHelper>(n, framebuffers); + DeleteFramebuffersHelper(n, framebuffers); return error::kNoError; } @@ -526,7 +518,7 @@ error::Error GLES2DecoderImpl::HandleDeleteRenderbuffers( if (renderbuffers == NULL) { return error::kOutOfBounds; } - DeleteGLObjects<GLDeleteRenderbuffersHelper>(n, renderbuffers); + DeleteRenderbuffersHelper(n, renderbuffers); return error::kNoError; } @@ -546,7 +538,7 @@ error::Error GLES2DecoderImpl::HandleDeleteRenderbuffersImmediate( if (renderbuffers == NULL) { return error::kOutOfBounds; } - DeleteGLObjects<GLDeleteRenderbuffersHelper>(n, renderbuffers); + DeleteRenderbuffersHelper(n, renderbuffers); return error::kNoError; } @@ -566,7 +558,7 @@ error::Error GLES2DecoderImpl::HandleDeleteTextures( if (textures == NULL) { return error::kOutOfBounds; } - DeleteGLObjects<GLDeleteTexturesHelper>(n, textures); + DeleteTexturesHelper(n, textures); return error::kNoError; } @@ -586,7 +578,7 @@ error::Error GLES2DecoderImpl::HandleDeleteTexturesImmediate( if (textures == NULL) { return error::kOutOfBounds; } - DeleteGLObjects<GLDeleteTexturesHelper>(n, textures); + DeleteTexturesHelper(n, textures); return error::kNoError; } @@ -618,17 +610,9 @@ error::Error GLES2DecoderImpl::HandleDepthRangef( error::Error GLES2DecoderImpl::HandleDetachShader( uint32 immediate_data_size, const gles2::DetachShader& c) { - GLuint program; - if (!id_manager()->GetServiceId(c.program, &program)) { - SetGLError(GL_INVALID_VALUE); - return error::kNoError; - } - GLuint shader; - if (!id_manager()->GetServiceId(c.shader, &shader)) { - SetGLError(GL_INVALID_VALUE); - return error::kNoError; - } - glDetachShader(program, shader); + GLuint program = c.program; + GLuint shader = c.shader; + DoDetachShader(program, shader); return error::kNoError; } @@ -702,11 +686,7 @@ error::Error GLES2DecoderImpl::HandleFramebufferRenderbuffer( GLenum target = static_cast<GLenum>(c.target); GLenum attachment = static_cast<GLenum>(c.attachment); GLenum renderbuffertarget = static_cast<GLenum>(c.renderbuffertarget); - GLuint renderbuffer; - if (!id_manager()->GetServiceId(c.renderbuffer, &renderbuffer)) { - SetGLError(GL_INVALID_VALUE); - return error::kNoError; - } + GLuint renderbuffer = c.renderbuffer; if (!ValidateGLenumFrameBufferTarget(target)) { SetGLError(GL_INVALID_ENUM); return error::kNoError; @@ -729,11 +709,7 @@ error::Error GLES2DecoderImpl::HandleFramebufferTexture2D( GLenum target = static_cast<GLenum>(c.target); GLenum attachment = static_cast<GLenum>(c.attachment); GLenum textarget = static_cast<GLenum>(c.textarget); - GLuint texture; - if (!id_manager()->GetServiceId(c.texture, &texture)) { - SetGLError(GL_INVALID_VALUE); - return error::kNoError; - } + GLuint texture = c.texture; GLint level = static_cast<GLint>(c.level); if (!ValidateGLenumFrameBufferTarget(target)) { SetGLError(GL_INVALID_ENUM); @@ -778,7 +754,7 @@ error::Error GLES2DecoderImpl::HandleGenBuffers( if (buffers == NULL) { return error::kOutOfBounds; } - if (!GenGLObjects<GLGenBuffersHelper>(n, buffers)) { + if (!GenBuffersHelper(n, buffers)) { return error::kInvalidArguments; } return error::kNoError; @@ -800,7 +776,7 @@ error::Error GLES2DecoderImpl::HandleGenBuffersImmediate( if (buffers == NULL) { return error::kOutOfBounds; } - if (!GenGLObjects<GLGenBuffersHelper>(n, buffers)) { + if (!GenBuffersHelper(n, buffers)) { return error::kInvalidArguments; } return error::kNoError; @@ -833,7 +809,7 @@ error::Error GLES2DecoderImpl::HandleGenFramebuffers( if (framebuffers == NULL) { return error::kOutOfBounds; } - if (!GenGLObjects<GLGenFramebuffersHelper>(n, framebuffers)) { + if (!GenFramebuffersHelper(n, framebuffers)) { return error::kInvalidArguments; } return error::kNoError; @@ -855,7 +831,7 @@ error::Error GLES2DecoderImpl::HandleGenFramebuffersImmediate( if (framebuffers == NULL) { return error::kOutOfBounds; } - if (!GenGLObjects<GLGenFramebuffersHelper>(n, framebuffers)) { + if (!GenFramebuffersHelper(n, framebuffers)) { return error::kInvalidArguments; } return error::kNoError; @@ -877,7 +853,7 @@ error::Error GLES2DecoderImpl::HandleGenRenderbuffers( if (renderbuffers == NULL) { return error::kOutOfBounds; } - if (!GenGLObjects<GLGenRenderbuffersHelper>(n, renderbuffers)) { + if (!GenRenderbuffersHelper(n, renderbuffers)) { return error::kInvalidArguments; } return error::kNoError; @@ -899,7 +875,7 @@ error::Error GLES2DecoderImpl::HandleGenRenderbuffersImmediate( if (renderbuffers == NULL) { return error::kOutOfBounds; } - if (!GenGLObjects<GLGenRenderbuffersHelper>(n, renderbuffers)) { + if (!GenRenderbuffersHelper(n, renderbuffers)) { return error::kInvalidArguments; } return error::kNoError; @@ -921,7 +897,7 @@ error::Error GLES2DecoderImpl::HandleGenTextures( if (textures == NULL) { return error::kOutOfBounds; } - if (!GenGLObjects<GLGenTexturesHelper>(n, textures)) { + if (!GenTexturesHelper(n, textures)) { return error::kInvalidArguments; } return error::kNoError; @@ -943,7 +919,7 @@ error::Error GLES2DecoderImpl::HandleGenTexturesImmediate( if (textures == NULL) { return error::kOutOfBounds; } - if (!GenGLObjects<GLGenTexturesHelper>(n, textures)) { + if (!GenTexturesHelper(n, textures)) { return error::kInvalidArguments; } return error::kNoError; @@ -1149,11 +1125,7 @@ error::Error GLES2DecoderImpl::HandleGetIntegerv( error::Error GLES2DecoderImpl::HandleGetProgramiv( uint32 immediate_data_size, const gles2::GetProgramiv& c) { - GLuint program; - if (!id_manager()->GetServiceId(c.program, &program)) { - SetGLError(GL_INVALID_VALUE); - return error::kNoError; - } + GLuint program = c.program; GLenum pname = static_cast<GLenum>(c.pname); typedef GetProgramiv::Result Result; GLsizei num_values = util_.GLGetNumValuesReturned(pname); @@ -1186,23 +1158,6 @@ error::Error GLES2DecoderImpl::HandleGetProgramiv( return error::kNoError; } -error::Error GLES2DecoderImpl::HandleGetProgramInfoLog( - uint32 immediate_data_size, const gles2::GetProgramInfoLog& c) { - GLuint program; - if (!id_manager()->GetServiceId(c.program, &program)) { - SetGLError(GL_INVALID_VALUE); - return error::kNoError; - } - uint32 bucket_id = static_cast<uint32>(c.bucket_id); - GLint len = 0; - glGetProgramiv(program, GL_INFO_LOG_LENGTH, &len); - Bucket* bucket = CreateBucket(bucket_id); - bucket->SetSize(len + 1); - glGetProgramInfoLog( - program, len + 1, &len, bucket->GetDataAs<GLchar*>(0, len + 1)); - return error::kNoError; -} - error::Error GLES2DecoderImpl::HandleGetRenderbufferParameteriv( uint32 immediate_data_size, const gles2::GetRenderbufferParameteriv& c) { GLenum target = static_cast<GLenum>(c.target); @@ -1244,11 +1199,7 @@ error::Error GLES2DecoderImpl::HandleGetRenderbufferParameteriv( error::Error GLES2DecoderImpl::HandleGetShaderiv( uint32 immediate_data_size, const gles2::GetShaderiv& c) { - GLuint shader; - if (!id_manager()->GetServiceId(c.shader, &shader)) { - SetGLError(GL_INVALID_VALUE); - return error::kNoError; - } + GLuint shader = c.shader; GLenum pname = static_cast<GLenum>(c.pname); typedef GetShaderiv::Result Result; GLsizei num_values = util_.GLGetNumValuesReturned(pname); @@ -1281,40 +1232,6 @@ error::Error GLES2DecoderImpl::HandleGetShaderiv( return error::kNoError; } -error::Error GLES2DecoderImpl::HandleGetShaderInfoLog( - uint32 immediate_data_size, const gles2::GetShaderInfoLog& c) { - GLuint shader; - if (!id_manager()->GetServiceId(c.shader, &shader)) { - SetGLError(GL_INVALID_VALUE); - return error::kNoError; - } - uint32 bucket_id = static_cast<uint32>(c.bucket_id); - GLint len = 0; - glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &len); - Bucket* bucket = CreateBucket(bucket_id); - bucket->SetSize(len + 1); - glGetShaderInfoLog( - shader, len + 1, &len, bucket->GetDataAs<GLchar*>(0, len + 1)); - return error::kNoError; -} - -error::Error GLES2DecoderImpl::HandleGetShaderSource( - uint32 immediate_data_size, const gles2::GetShaderSource& c) { - GLuint shader; - if (!id_manager()->GetServiceId(c.shader, &shader)) { - SetGLError(GL_INVALID_VALUE); - return error::kNoError; - } - uint32 bucket_id = static_cast<uint32>(c.bucket_id); - GLint len = 0; - DoGetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &len); - Bucket* bucket = CreateBucket(bucket_id); - bucket->SetSize(len + 1); - DoGetShaderSource( - shader, len + 1, &len, bucket->GetDataAs<GLchar*>(0, len + 1)); - return error::kNoError; -} - error::Error GLES2DecoderImpl::HandleGetTexParameterfv( uint32 immediate_data_size, const gles2::GetTexParameterfv& c) { GLenum target = static_cast<GLenum>(c.target); @@ -1481,11 +1398,7 @@ error::Error GLES2DecoderImpl::HandleHint( error::Error GLES2DecoderImpl::HandleIsBuffer( uint32 immediate_data_size, const gles2::IsBuffer& c) { - GLuint buffer; - if (!id_manager()->GetServiceId(c.buffer, &buffer)) { - SetGLError(GL_INVALID_VALUE); - return error::kNoError; - } + GLuint buffer = c.buffer; typedef IsBuffer::Result Result; Result* result_dst = GetSharedMemoryAs<Result*>( c.result_shm_id, c.result_shm_offset, sizeof(*result_dst)); @@ -1515,7 +1428,7 @@ error::Error GLES2DecoderImpl::HandleIsEnabled( error::Error GLES2DecoderImpl::HandleIsFramebuffer( uint32 immediate_data_size, const gles2::IsFramebuffer& c) { - GLuint framebuffer = static_cast<GLuint>(c.framebuffer); + GLuint framebuffer = c.framebuffer; typedef IsFramebuffer::Result Result; Result* result_dst = GetSharedMemoryAs<Result*>( c.result_shm_id, c.result_shm_offset, sizeof(*result_dst)); @@ -1528,7 +1441,7 @@ error::Error GLES2DecoderImpl::HandleIsFramebuffer( error::Error GLES2DecoderImpl::HandleIsProgram( uint32 immediate_data_size, const gles2::IsProgram& c) { - GLuint program = static_cast<GLuint>(c.program); + GLuint program = c.program; typedef IsProgram::Result Result; Result* result_dst = GetSharedMemoryAs<Result*>( c.result_shm_id, c.result_shm_offset, sizeof(*result_dst)); @@ -1541,7 +1454,7 @@ error::Error GLES2DecoderImpl::HandleIsProgram( error::Error GLES2DecoderImpl::HandleIsRenderbuffer( uint32 immediate_data_size, const gles2::IsRenderbuffer& c) { - GLuint renderbuffer = static_cast<GLuint>(c.renderbuffer); + GLuint renderbuffer = c.renderbuffer; typedef IsRenderbuffer::Result Result; Result* result_dst = GetSharedMemoryAs<Result*>( c.result_shm_id, c.result_shm_offset, sizeof(*result_dst)); @@ -1554,7 +1467,7 @@ error::Error GLES2DecoderImpl::HandleIsRenderbuffer( error::Error GLES2DecoderImpl::HandleIsShader( uint32 immediate_data_size, const gles2::IsShader& c) { - GLuint shader = static_cast<GLuint>(c.shader); + GLuint shader = c.shader; typedef IsShader::Result Result; Result* result_dst = GetSharedMemoryAs<Result*>( c.result_shm_id, c.result_shm_offset, sizeof(*result_dst)); @@ -1567,7 +1480,7 @@ error::Error GLES2DecoderImpl::HandleIsShader( error::Error GLES2DecoderImpl::HandleIsTexture( uint32 immediate_data_size, const gles2::IsTexture& c) { - GLuint texture = static_cast<GLuint>(c.texture); + GLuint texture = c.texture; typedef IsTexture::Result Result; Result* result_dst = GetSharedMemoryAs<Result*>( c.result_shm_id, c.result_shm_offset, sizeof(*result_dst)); @@ -1587,11 +1500,7 @@ error::Error GLES2DecoderImpl::HandleLineWidth( error::Error GLES2DecoderImpl::HandleLinkProgram( uint32 immediate_data_size, const gles2::LinkProgram& c) { - GLuint program; - if (!id_manager()->GetServiceId(c.program, &program)) { - SetGLError(GL_INVALID_VALUE); - return error::kNoError; - } + GLuint program = c.program; DoLinkProgram(program); return error::kNoError; } @@ -2593,22 +2502,14 @@ error::Error GLES2DecoderImpl::HandleUniformMatrix4fvImmediate( error::Error GLES2DecoderImpl::HandleUseProgram( uint32 immediate_data_size, const gles2::UseProgram& c) { GLuint program = c.program; - if (program != 0 && !id_manager()->GetServiceId(program, &program)) { - SetGLError(GL_INVALID_VALUE); - return error::kNoError; - } DoUseProgram(program); return error::kNoError; } error::Error GLES2DecoderImpl::HandleValidateProgram( uint32 immediate_data_size, const gles2::ValidateProgram& c) { - GLuint program; - if (!id_manager()->GetServiceId(c.program, &program)) { - SetGLError(GL_INVALID_VALUE); - return error::kNoError; - } - glValidateProgram(program); + GLuint program = c.program; + DoValidateProgram(program); return error::kNoError; } @@ -2810,11 +2711,7 @@ error::Error GLES2DecoderImpl::HandleViewport( error::Error GLES2DecoderImpl::HandleGetMaxValueInBuffer( uint32 immediate_data_size, const gles2::GetMaxValueInBuffer& c) { - GLuint buffer_id; - if (!id_manager()->GetServiceId(c.buffer_id, &buffer_id)) { - SetGLError(GL_INVALID_VALUE); - return error::kNoError; - } + GLuint buffer_id = c.buffer_id; GLsizei count = static_cast<GLsizei>(c.count); GLenum type = static_cast<GLenum>(c.type); GLuint offset = static_cast<GLuint>(c.offset); diff --git a/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc b/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc index 1f64b79..771e977 100644 --- a/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc +++ b/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc @@ -443,12 +443,14 @@ TEST_F(GLES2DecoderWithShaderTest, GetUniformivBadProgramFails) { EXPECT_EQ(GL_INVALID_VALUE, GetGLError()); // Valid id that is not a program. The GL spec requires a different error for // this case. +#if GLES2_TEST_SHADER_VS_PROGRAM_IDS result->size = kInitialResult; - cmd.Init(client_texture_id_, kUniform2Location, + cmd.Init(client_shader_id_, kUniform2Location, kSharedMemoryId, kSharedMemoryOffset); EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); EXPECT_EQ(0U, result->size); EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); +#endif // GLES2_TEST_SHADER_VS_PROGRAM_IDS // Unlinked program EXPECT_CALL(*gl_, CreateProgram()) .Times(1) @@ -536,12 +538,14 @@ TEST_F(GLES2DecoderWithShaderTest, GetUniformfvBadProgramFails) { EXPECT_EQ(GL_INVALID_VALUE, GetGLError()); // Valid id that is not a program. The GL spec requires a different error for // this case. +#if GLES2_TEST_SHADER_VS_PROGRAM_IDS result->size = kInitialResult; - cmd.Init(client_texture_id_, kUniform2Location, + cmd.Init(client_shader_id_, kUniform2Location, kSharedMemoryId, kSharedMemoryOffset); EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); EXPECT_EQ(0U, result->size); EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); +#endif // GLES2_TEST_SHADER_VS_PROGRAM_IDS // Unlinked program EXPECT_CALL(*gl_, CreateProgram()) .Times(1) @@ -740,12 +744,14 @@ TEST_F(GLES2DecoderWithShaderTest, GetActiveUniformBadProgramFails) { EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); EXPECT_EQ(0, result->success); EXPECT_EQ(GL_INVALID_VALUE, GetGLError()); +#if GLES2_TEST_SHADER_VS_PROGRAM_IDS result->success = 0; - cmd.Init(client_texture_id_, kUniformIndex, kBucketId, + cmd.Init(client_shader_id_, kUniformIndex, kBucketId, shared_memory_id_, shared_memory_offset_); EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); EXPECT_EQ(0, result->success); EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); +#endif // GLES2_TEST_SHADER_VS_PROGRAM_IDS } TEST_F(GLES2DecoderWithShaderTest, GetActiveUniformBadIndexFails) { @@ -818,12 +824,14 @@ TEST_F(GLES2DecoderWithShaderTest, GetActiveAttribBadProgramFails) { EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); EXPECT_EQ(0, result->success); EXPECT_EQ(GL_INVALID_VALUE, GetGLError()); +#if GLES2_TEST_SHADER_VS_PROGRAM_IDS result->success = 0; - cmd.Init(client_texture_id_, kAttribIndex, kBucketId, + cmd.Init(client_shader_id_, kAttribIndex, kBucketId, shared_memory_id_, shared_memory_offset_); EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); EXPECT_EQ(0, result->success); EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); +#endif // GLES2_TEST_SHADER_VS_PROGRAM_IDS } TEST_F(GLES2DecoderWithShaderTest, GetActiveAttribBadIndexFails) { @@ -865,9 +873,11 @@ TEST_F(GLES2DecoderTest, CompileShaderInvalidArgs) { cmd.Init(kInvalidClientId); EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); EXPECT_EQ(GL_INVALID_VALUE, GetGLError()); - cmd.Init(client_texture_id_); +#if GLES2_TEST_SHADER_VS_PROGRAM_IDS + cmd.Init(client_program_id_); EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); +#endif // GLES2_TEST_SHADER_VS_PROGRAM_IDS } TEST_F(GLES2DecoderTest, ShaderSourceAndGetShaderSourceValidArgs) { @@ -899,10 +909,12 @@ TEST_F(GLES2DecoderTest, ShaderSourceInvalidArgs) { kSharedMemoryId, kSharedMemoryOffset, kSourceSize); EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); EXPECT_EQ(GL_INVALID_VALUE, GetGLError()); - cmd.Init(client_texture_id_, +#if GLES2_TEST_SHADER_VS_PROGRAM_IDS + cmd.Init(client_program_id_, kSharedMemoryId, kSharedMemoryOffset, kSourceSize); EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); +#endif // GLES2_TEST_SHADER_VS_PROGRAM_IDS cmd.Init(client_shader_id_, kInvalidSharedMemoryId, kSharedMemoryOffset, kSourceSize); EXPECT_NE(error::kNoError, ExecuteCmd(cmd)); @@ -942,9 +954,11 @@ TEST_F(GLES2DecoderTest, ShaderSourceImmediateInvalidArgs) { memcpy(GetImmediateDataAs<void*>(&cmd), kSource, kSourceSize); EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, kSourceSize)); EXPECT_EQ(GL_INVALID_VALUE, GetGLError()); - cmd.Init(client_texture_id_, kSourceSize); +#if GLES2_TEST_SHADER_VS_PROGRAM_IDS + cmd.Init(client_program_id_, kSourceSize); EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, kSourceSize)); EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); +#endif // GLES2_TEST_SHADER_VS_PROGRAM_IDS } TEST_F(GLES2DecoderTest, ShaderSourceBucketAndGetShaderSourceValidArgs) { @@ -1908,7 +1922,7 @@ TEST_F(GLES2DecoderWithShaderTest, GetMaxValueInBuffer) { GL_UNSIGNED_SHORT, kValidIndexRangeStart * 2, kSharedMemoryId, kSharedMemoryOffset); EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); - EXPECT_EQ(GL_INVALID_VALUE, GetGLError()); + EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); cmd.Init(client_element_buffer_id_, kOutOfRangeIndexRangeEnd, GL_UNSIGNED_SHORT, kValidIndexRangeStart * 2, kSharedMemoryId, kSharedMemoryOffset); 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 c91acde..fcec43f 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 @@ -42,8 +42,7 @@ TEST_F(GLES2DecoderTest1, BindBufferValidArgsNewId) { cmd.Init(GL_ARRAY_BUFFER, kNewClientId); EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); EXPECT_EQ(GL_NO_ERROR, GetGLError()); - EXPECT_EQ(GetServiceId(kNewClientId), kNewServiceId); - EXPECT_TRUE(GetBufferInfo(kNewServiceId) != NULL); + EXPECT_TRUE(GetBufferInfo(kNewClientId) != NULL); } TEST_F(GLES2DecoderTest1, BindBufferInvalidArgs0_0) { @@ -55,15 +54,6 @@ TEST_F(GLES2DecoderTest1, BindBufferInvalidArgs0_0) { EXPECT_EQ(GL_INVALID_ENUM, GetGLError()); } -TEST_F(GLES2DecoderTest1, BindBufferInvalidArgs1_0) { - EXPECT_CALL(*gl_, BindBuffer(_, _)).Times(0); - SpecializedSetup<BindBuffer, 0>(); - BindBuffer cmd; - cmd.Init(GL_ARRAY_BUFFER, client_texture_id_); - EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); - EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); -} - TEST_F(GLES2DecoderTest1, BindFramebufferValidArgs) { EXPECT_CALL(*gl_, BindFramebufferEXT(GL_FRAMEBUFFER, kServiceFramebufferId)); SpecializedSetup<BindFramebuffer, 0>(); @@ -82,8 +72,7 @@ TEST_F(GLES2DecoderTest1, BindFramebufferValidArgsNewId) { cmd.Init(GL_FRAMEBUFFER, kNewClientId); EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); EXPECT_EQ(GL_NO_ERROR, GetGLError()); - EXPECT_EQ(GetServiceId(kNewClientId), kNewServiceId); - EXPECT_TRUE(GetFramebufferInfo(kNewServiceId) != NULL); + EXPECT_TRUE(GetFramebufferInfo(kNewClientId) != NULL); } TEST_F(GLES2DecoderTest1, BindFramebufferInvalidArgs0_0) { @@ -95,15 +84,6 @@ TEST_F(GLES2DecoderTest1, BindFramebufferInvalidArgs0_0) { EXPECT_EQ(GL_INVALID_ENUM, GetGLError()); } -TEST_F(GLES2DecoderTest1, BindFramebufferInvalidArgs1_0) { - EXPECT_CALL(*gl_, BindFramebufferEXT(_, _)).Times(0); - SpecializedSetup<BindFramebuffer, 0>(); - BindFramebuffer cmd; - cmd.Init(GL_FRAMEBUFFER, client_texture_id_); - EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); - EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); -} - TEST_F(GLES2DecoderTest1, BindRenderbufferValidArgs) { EXPECT_CALL( *gl_, BindRenderbufferEXT(GL_RENDERBUFFER, kServiceRenderbufferId)); @@ -123,8 +103,7 @@ TEST_F(GLES2DecoderTest1, BindRenderbufferValidArgsNewId) { cmd.Init(GL_RENDERBUFFER, kNewClientId); EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); EXPECT_EQ(GL_NO_ERROR, GetGLError()); - EXPECT_EQ(GetServiceId(kNewClientId), kNewServiceId); - EXPECT_TRUE(GetRenderbufferInfo(kNewServiceId) != NULL); + EXPECT_TRUE(GetRenderbufferInfo(kNewClientId) != NULL); } TEST_F(GLES2DecoderTest1, BindRenderbufferInvalidArgs0_0) { @@ -136,15 +115,6 @@ TEST_F(GLES2DecoderTest1, BindRenderbufferInvalidArgs0_0) { EXPECT_EQ(GL_INVALID_ENUM, GetGLError()); } -TEST_F(GLES2DecoderTest1, BindRenderbufferInvalidArgs1_0) { - EXPECT_CALL(*gl_, BindRenderbufferEXT(_, _)).Times(0); - SpecializedSetup<BindRenderbuffer, 0>(); - BindRenderbuffer cmd; - cmd.Init(GL_RENDERBUFFER, client_texture_id_); - EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); - EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); -} - TEST_F(GLES2DecoderTest1, BindTextureValidArgs) { EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kServiceTextureId)); SpecializedSetup<BindTexture, 0>(); @@ -163,8 +133,7 @@ TEST_F(GLES2DecoderTest1, BindTextureValidArgsNewId) { cmd.Init(GL_TEXTURE_2D, kNewClientId); EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); EXPECT_EQ(GL_NO_ERROR, GetGLError()); - EXPECT_EQ(GetServiceId(kNewClientId), kNewServiceId); - EXPECT_TRUE(GetTextureInfo(kNewServiceId) != NULL); + EXPECT_TRUE(GetTextureInfo(kNewClientId) != NULL); } TEST_F(GLES2DecoderTest1, BindTextureInvalidArgs0_0) { @@ -185,15 +154,6 @@ TEST_F(GLES2DecoderTest1, BindTextureInvalidArgs0_1) { EXPECT_EQ(GL_INVALID_ENUM, GetGLError()); } -TEST_F(GLES2DecoderTest1, BindTextureInvalidArgs1_0) { - EXPECT_CALL(*gl_, BindTexture(_, _)).Times(0); - SpecializedSetup<BindTexture, 0>(); - BindTexture cmd; - cmd.Init(GL_TEXTURE_2D, client_buffer_id_); - EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); - EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); -} - TEST_F(GLES2DecoderTest1, BlendColorValidArgs) { EXPECT_CALL(*gl_, BlendColor(1, 2, 3, 4)); SpecializedSetup<BlendColor, 0>(); @@ -463,7 +423,7 @@ TEST_F(GLES2DecoderTest1, CreateProgramValidArgs) { cmd.Init(kNewClientId); EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); EXPECT_EQ(GL_NO_ERROR, GetGLError()); - EXPECT_EQ(GetServiceId(kNewClientId), kNewServiceId); + EXPECT_TRUE(GetProgramInfo(kNewClientId) != NULL); } TEST_F(GLES2DecoderTest1, CreateShaderValidArgs) { @@ -474,7 +434,7 @@ TEST_F(GLES2DecoderTest1, CreateShaderValidArgs) { cmd.Init(GL_VERTEX_SHADER, kNewClientId); EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); EXPECT_EQ(GL_NO_ERROR, GetGLError()); - EXPECT_EQ(GetServiceId(kNewClientId), kNewServiceId); + EXPECT_TRUE(GetShaderInfo(kNewClientId) != NULL); } TEST_F(GLES2DecoderTest1, CreateShaderInvalidArgs0_0) { @@ -506,12 +466,11 @@ TEST_F(GLES2DecoderTest1, DeleteBuffersValidArgs) { cmd.Init(1, shared_memory_id_, shared_memory_offset_); EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); EXPECT_EQ(GL_NO_ERROR, GetGLError()); - EXPECT_EQ(GetServiceId(kNewClientId), 0u); + EXPECT_TRUE( + GetBufferInfo(client_buffer_id_) == NULL); } TEST_F(GLES2DecoderTest1, DeleteBuffersInvalidArgs) { - EXPECT_CALL(*gl_, DeleteBuffersARB(1, Pointee(0))) - .Times(1); GetSharedMemoryAs<GLuint*>()[0] = kInvalidClientId; SpecializedSetup<DeleteBuffers, 0>(); DeleteBuffers cmd; @@ -530,12 +489,11 @@ TEST_F(GLES2DecoderTest1, DeleteBuffersImmediateValidArgs) { EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, sizeof(client_buffer_id_))); EXPECT_EQ(GL_NO_ERROR, GetGLError()); - EXPECT_EQ(GetServiceId(kNewClientId), 0u); + EXPECT_TRUE( + GetBufferInfo(client_buffer_id_) == NULL); } TEST_F(GLES2DecoderTest1, DeleteBuffersImmediateInvalidArgs) { - EXPECT_CALL(*gl_, DeleteBuffersARB(1, Pointee(0))) - .Times(1); DeleteBuffersImmediate& cmd = *GetImmediateAs<DeleteBuffersImmediate>(); SpecializedSetup<DeleteBuffersImmediate, 0>(); GLuint temp = kInvalidClientId; @@ -555,12 +513,11 @@ TEST_F(GLES2DecoderTest1, DeleteFramebuffersValidArgs) { cmd.Init(1, shared_memory_id_, shared_memory_offset_); EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); EXPECT_EQ(GL_NO_ERROR, GetGLError()); - EXPECT_EQ(GetServiceId(kNewClientId), 0u); + EXPECT_TRUE( + GetFramebufferInfo(client_framebuffer_id_) == NULL); } TEST_F(GLES2DecoderTest1, DeleteFramebuffersInvalidArgs) { - EXPECT_CALL(*gl_, DeleteFramebuffersEXT(1, Pointee(0))) - .Times(1); GetSharedMemoryAs<GLuint*>()[0] = kInvalidClientId; SpecializedSetup<DeleteFramebuffers, 0>(); DeleteFramebuffers cmd; @@ -580,12 +537,11 @@ TEST_F(GLES2DecoderTest1, DeleteFramebuffersImmediateValidArgs) { EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, sizeof(client_framebuffer_id_))); EXPECT_EQ(GL_NO_ERROR, GetGLError()); - EXPECT_EQ(GetServiceId(kNewClientId), 0u); + EXPECT_TRUE( + GetFramebufferInfo(client_framebuffer_id_) == NULL); } TEST_F(GLES2DecoderTest1, DeleteFramebuffersImmediateInvalidArgs) { - EXPECT_CALL(*gl_, DeleteFramebuffersEXT(1, Pointee(0))) - .Times(1); DeleteFramebuffersImmediate& cmd = *GetImmediateAs<DeleteFramebuffersImmediate>(); SpecializedSetup<DeleteFramebuffersImmediate, 0>(); @@ -608,12 +564,11 @@ TEST_F(GLES2DecoderTest1, DeleteRenderbuffersValidArgs) { cmd.Init(1, shared_memory_id_, shared_memory_offset_); EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); EXPECT_EQ(GL_NO_ERROR, GetGLError()); - EXPECT_EQ(GetServiceId(kNewClientId), 0u); + EXPECT_TRUE( + GetRenderbufferInfo(client_renderbuffer_id_) == NULL); } TEST_F(GLES2DecoderTest1, DeleteRenderbuffersInvalidArgs) { - EXPECT_CALL(*gl_, DeleteRenderbuffersEXT(1, Pointee(0))) - .Times(1); GetSharedMemoryAs<GLuint*>()[0] = kInvalidClientId; SpecializedSetup<DeleteRenderbuffers, 0>(); DeleteRenderbuffers cmd; @@ -633,12 +588,11 @@ TEST_F(GLES2DecoderTest1, DeleteRenderbuffersImmediateValidArgs) { EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, sizeof(client_renderbuffer_id_))); EXPECT_EQ(GL_NO_ERROR, GetGLError()); - EXPECT_EQ(GetServiceId(kNewClientId), 0u); + EXPECT_TRUE( + GetRenderbufferInfo(client_renderbuffer_id_) == NULL); } TEST_F(GLES2DecoderTest1, DeleteRenderbuffersImmediateInvalidArgs) { - EXPECT_CALL(*gl_, DeleteRenderbuffersEXT(1, Pointee(0))) - .Times(1); DeleteRenderbuffersImmediate& cmd = *GetImmediateAs<DeleteRenderbuffersImmediate>(); SpecializedSetup<DeleteRenderbuffersImmediate, 0>(); @@ -661,12 +615,11 @@ TEST_F(GLES2DecoderTest1, DeleteTexturesValidArgs) { cmd.Init(1, shared_memory_id_, shared_memory_offset_); EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); EXPECT_EQ(GL_NO_ERROR, GetGLError()); - EXPECT_EQ(GetServiceId(kNewClientId), 0u); + EXPECT_TRUE( + GetTextureInfo(client_texture_id_) == NULL); } TEST_F(GLES2DecoderTest1, DeleteTexturesInvalidArgs) { - EXPECT_CALL(*gl_, DeleteTextures(1, Pointee(0))) - .Times(1); GetSharedMemoryAs<GLuint*>()[0] = kInvalidClientId; SpecializedSetup<DeleteTextures, 0>(); DeleteTextures cmd; @@ -685,12 +638,11 @@ TEST_F(GLES2DecoderTest1, DeleteTexturesImmediateValidArgs) { EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, sizeof(client_texture_id_))); EXPECT_EQ(GL_NO_ERROR, GetGLError()); - EXPECT_EQ(GetServiceId(kNewClientId), 0u); + EXPECT_TRUE( + GetTextureInfo(client_texture_id_) == NULL); } TEST_F(GLES2DecoderTest1, DeleteTexturesImmediateInvalidArgs) { - EXPECT_CALL(*gl_, DeleteTextures(1, Pointee(0))) - .Times(1); DeleteTexturesImmediate& cmd = *GetImmediateAs<DeleteTexturesImmediate>(); SpecializedSetup<DeleteTexturesImmediate, 0>(); GLuint temp = kInvalidClientId; @@ -918,7 +870,7 @@ TEST_F(GLES2DecoderTest1, GenBuffersValidArgs) { cmd.Init(1, shared_memory_id_, shared_memory_offset_); EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); EXPECT_EQ(GL_NO_ERROR, GetGLError()); - EXPECT_EQ(GetServiceId(kNewClientId), kNewServiceId); + EXPECT_TRUE(GetBufferInfo(kNewClientId) != NULL); } TEST_F(GLES2DecoderTest1, GenBuffersInvalidArgs) { @@ -940,7 +892,7 @@ TEST_F(GLES2DecoderTest1, GenBuffersImmediateValidArgs) { EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, sizeof(temp))); EXPECT_EQ(GL_NO_ERROR, GetGLError()); - EXPECT_EQ(GetServiceId(kNewClientId), kNewServiceId); + EXPECT_TRUE(GetBufferInfo(kNewClientId) != NULL); } TEST_F(GLES2DecoderTest1, GenBuffersImmediateInvalidArgs) { @@ -988,7 +940,7 @@ TEST_F(GLES2DecoderTest1, GenFramebuffersValidArgs) { cmd.Init(1, shared_memory_id_, shared_memory_offset_); EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); EXPECT_EQ(GL_NO_ERROR, GetGLError()); - EXPECT_EQ(GetServiceId(kNewClientId), kNewServiceId); + EXPECT_TRUE(GetFramebufferInfo(kNewClientId) != NULL); } TEST_F(GLES2DecoderTest1, GenFramebuffersInvalidArgs) { @@ -1010,7 +962,7 @@ TEST_F(GLES2DecoderTest1, GenFramebuffersImmediateValidArgs) { EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, sizeof(temp))); EXPECT_EQ(GL_NO_ERROR, GetGLError()); - EXPECT_EQ(GetServiceId(kNewClientId), kNewServiceId); + EXPECT_TRUE(GetFramebufferInfo(kNewClientId) != NULL); } TEST_F(GLES2DecoderTest1, GenFramebuffersImmediateInvalidArgs) { @@ -1031,7 +983,7 @@ TEST_F(GLES2DecoderTest1, GenRenderbuffersValidArgs) { cmd.Init(1, shared_memory_id_, shared_memory_offset_); EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); EXPECT_EQ(GL_NO_ERROR, GetGLError()); - EXPECT_EQ(GetServiceId(kNewClientId), kNewServiceId); + EXPECT_TRUE(GetRenderbufferInfo(kNewClientId) != NULL); } TEST_F(GLES2DecoderTest1, GenRenderbuffersInvalidArgs) { @@ -1054,7 +1006,7 @@ TEST_F(GLES2DecoderTest1, GenRenderbuffersImmediateValidArgs) { EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, sizeof(temp))); EXPECT_EQ(GL_NO_ERROR, GetGLError()); - EXPECT_EQ(GetServiceId(kNewClientId), kNewServiceId); + EXPECT_TRUE(GetRenderbufferInfo(kNewClientId) != NULL); } TEST_F(GLES2DecoderTest1, GenRenderbuffersImmediateInvalidArgs) { @@ -1076,7 +1028,7 @@ TEST_F(GLES2DecoderTest1, GenTexturesValidArgs) { cmd.Init(1, shared_memory_id_, shared_memory_offset_); EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); EXPECT_EQ(GL_NO_ERROR, GetGLError()); - EXPECT_EQ(GetServiceId(kNewClientId), kNewServiceId); + EXPECT_TRUE(GetTextureInfo(kNewClientId) != NULL); } TEST_F(GLES2DecoderTest1, GenTexturesInvalidArgs) { @@ -1098,7 +1050,7 @@ TEST_F(GLES2DecoderTest1, GenTexturesImmediateValidArgs) { EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, sizeof(temp))); EXPECT_EQ(GL_NO_ERROR, GetGLError()); - EXPECT_EQ(GetServiceId(kNewClientId), kNewServiceId); + EXPECT_TRUE(GetTextureInfo(kNewClientId) != NULL); } TEST_F(GLES2DecoderTest1, GenTexturesImmediateInvalidArgs) { 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 56a56ac..ae27310 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 @@ -192,7 +192,7 @@ TEST_F(GLES2DecoderTest2, IsEnabledInvalidArgsBadSharedMemoryId) { TEST_F(GLES2DecoderTest2, IsFramebufferValidArgs) { SpecializedSetup<IsFramebuffer, 0>(); IsFramebuffer cmd; - cmd.Init(1, shared_memory_id_, shared_memory_offset_); + cmd.Init(client_framebuffer_id_, shared_memory_id_, shared_memory_offset_); EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); EXPECT_EQ(GL_NO_ERROR, GetGLError()); } @@ -200,16 +200,18 @@ TEST_F(GLES2DecoderTest2, IsFramebufferValidArgs) { TEST_F(GLES2DecoderTest2, IsFramebufferInvalidArgsBadSharedMemoryId) { SpecializedSetup<IsFramebuffer, 0>(); IsFramebuffer cmd; - cmd.Init(1, kInvalidSharedMemoryId, shared_memory_offset_); + cmd.Init( + client_framebuffer_id_, kInvalidSharedMemoryId, shared_memory_offset_); EXPECT_EQ(error::kOutOfBounds, ExecuteCmd(cmd)); - cmd.Init(1, shared_memory_id_, kInvalidSharedMemoryOffset); + cmd.Init( + client_framebuffer_id_, shared_memory_id_, kInvalidSharedMemoryOffset); EXPECT_EQ(error::kOutOfBounds, ExecuteCmd(cmd)); } TEST_F(GLES2DecoderTest2, IsProgramValidArgs) { SpecializedSetup<IsProgram, 0>(); IsProgram cmd; - cmd.Init(1, shared_memory_id_, shared_memory_offset_); + cmd.Init(client_program_id_, shared_memory_id_, shared_memory_offset_); EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); EXPECT_EQ(GL_NO_ERROR, GetGLError()); } @@ -217,16 +219,16 @@ TEST_F(GLES2DecoderTest2, IsProgramValidArgs) { TEST_F(GLES2DecoderTest2, IsProgramInvalidArgsBadSharedMemoryId) { SpecializedSetup<IsProgram, 0>(); IsProgram cmd; - cmd.Init(1, kInvalidSharedMemoryId, shared_memory_offset_); + cmd.Init(client_program_id_, kInvalidSharedMemoryId, shared_memory_offset_); EXPECT_EQ(error::kOutOfBounds, ExecuteCmd(cmd)); - cmd.Init(1, shared_memory_id_, kInvalidSharedMemoryOffset); + cmd.Init(client_program_id_, shared_memory_id_, kInvalidSharedMemoryOffset); EXPECT_EQ(error::kOutOfBounds, ExecuteCmd(cmd)); } TEST_F(GLES2DecoderTest2, IsRenderbufferValidArgs) { SpecializedSetup<IsRenderbuffer, 0>(); IsRenderbuffer cmd; - cmd.Init(1, shared_memory_id_, shared_memory_offset_); + cmd.Init(client_renderbuffer_id_, shared_memory_id_, shared_memory_offset_); EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); EXPECT_EQ(GL_NO_ERROR, GetGLError()); } @@ -234,16 +236,18 @@ TEST_F(GLES2DecoderTest2, IsRenderbufferValidArgs) { TEST_F(GLES2DecoderTest2, IsRenderbufferInvalidArgsBadSharedMemoryId) { SpecializedSetup<IsRenderbuffer, 0>(); IsRenderbuffer cmd; - cmd.Init(1, kInvalidSharedMemoryId, shared_memory_offset_); + cmd.Init( + client_renderbuffer_id_, kInvalidSharedMemoryId, shared_memory_offset_); EXPECT_EQ(error::kOutOfBounds, ExecuteCmd(cmd)); - cmd.Init(1, shared_memory_id_, kInvalidSharedMemoryOffset); + cmd.Init( + client_renderbuffer_id_, shared_memory_id_, kInvalidSharedMemoryOffset); EXPECT_EQ(error::kOutOfBounds, ExecuteCmd(cmd)); } TEST_F(GLES2DecoderTest2, IsShaderValidArgs) { SpecializedSetup<IsShader, 0>(); IsShader cmd; - cmd.Init(1, shared_memory_id_, shared_memory_offset_); + cmd.Init(client_shader_id_, shared_memory_id_, shared_memory_offset_); EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); EXPECT_EQ(GL_NO_ERROR, GetGLError()); } @@ -251,16 +255,16 @@ TEST_F(GLES2DecoderTest2, IsShaderValidArgs) { TEST_F(GLES2DecoderTest2, IsShaderInvalidArgsBadSharedMemoryId) { SpecializedSetup<IsShader, 0>(); IsShader cmd; - cmd.Init(1, kInvalidSharedMemoryId, shared_memory_offset_); + cmd.Init(client_shader_id_, kInvalidSharedMemoryId, shared_memory_offset_); EXPECT_EQ(error::kOutOfBounds, ExecuteCmd(cmd)); - cmd.Init(1, shared_memory_id_, kInvalidSharedMemoryOffset); + cmd.Init(client_shader_id_, shared_memory_id_, kInvalidSharedMemoryOffset); EXPECT_EQ(error::kOutOfBounds, ExecuteCmd(cmd)); } TEST_F(GLES2DecoderTest2, IsTextureValidArgs) { SpecializedSetup<IsTexture, 0>(); IsTexture cmd; - cmd.Init(1, shared_memory_id_, shared_memory_offset_); + cmd.Init(client_texture_id_, shared_memory_id_, shared_memory_offset_); EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); EXPECT_EQ(GL_NO_ERROR, GetGLError()); } @@ -268,9 +272,9 @@ TEST_F(GLES2DecoderTest2, IsTextureValidArgs) { TEST_F(GLES2DecoderTest2, IsTextureInvalidArgsBadSharedMemoryId) { SpecializedSetup<IsTexture, 0>(); IsTexture cmd; - cmd.Init(1, kInvalidSharedMemoryId, shared_memory_offset_); + cmd.Init(client_texture_id_, kInvalidSharedMemoryId, shared_memory_offset_); EXPECT_EQ(error::kOutOfBounds, ExecuteCmd(cmd)); - cmd.Init(1, shared_memory_id_, kInvalidSharedMemoryOffset); + cmd.Init(client_texture_id_, shared_memory_id_, kInvalidSharedMemoryOffset); EXPECT_EQ(error::kOutOfBounds, ExecuteCmd(cmd)); } 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 41e20b4..bff12c1 100644 --- a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h +++ b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h @@ -125,10 +125,6 @@ class GLES2DecoderTestBase : public testing::Test { return reinterpret_cast<T>(ptr); } - uint32 GetServiceId(uint32 client_id) { - return decoder_->GetServiceIdForTesting(client_id); - } - BufferManager::BufferInfo* GetBufferInfo(GLuint service_id) { return group_.buffer_manager()->GetBufferInfo(service_id); } diff --git a/gpu/command_buffer/service/program_manager.cc b/gpu/command_buffer/service/program_manager.cc index 43b0148..581a185 100644 --- a/gpu/command_buffer/service/program_manager.cc +++ b/gpu/command_buffer/service/program_manager.cc @@ -18,25 +18,33 @@ bool ProgramManager::IsInvalidPrefix(const char* name, size_t length) { memcmp(name, kInvalidPrefix, sizeof(kInvalidPrefix)) == 0); } +void ProgramManager::ProgramInfo::Reset() { + valid_ = false; + max_uniform_name_length_ = 0; + max_attrib_name_length_ = 0; + attrib_infos_.clear(); + uniform_infos_.clear(); + sampler_indices_.clear(); + location_to_index_map_.clear(); +} + void ProgramManager::ProgramInfo::Update() { + Reset(); GLint num_attribs = 0; GLint max_len = 0; - max_uniform_name_length_ = 0; - max_attrib_name_length_ = 0; - glGetProgramiv(program_id_, GL_ACTIVE_ATTRIBUTES, &num_attribs); - glGetProgramiv(program_id_, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &max_len); + glGetProgramiv(service_id_, GL_ACTIVE_ATTRIBUTES, &num_attribs); + glGetProgramiv(service_id_, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &max_len); // TODO(gman): Should we check for error? scoped_array<char> name_buffer(new char[max_len]); - attrib_infos_.clear(); for (GLint ii = 0; ii < num_attribs; ++ii) { GLsizei length; GLsizei size; GLenum type; glGetActiveAttrib( - program_id_, ii, max_len, &length, &size, &type, name_buffer.get()); + service_id_, ii, max_len, &length, &size, &type, name_buffer.get()); if (!IsInvalidPrefix(name_buffer.get(), length)) { // TODO(gman): Should we check for error? - GLint location = glGetAttribLocation(program_id_, name_buffer.get()); + GLint location = glGetAttribLocation(service_id_, name_buffer.get()); attrib_infos_.push_back( VertexAttribInfo(size, type, name_buffer.get(), location)); max_attrib_name_length_ = std::max(max_attrib_name_length_, length); @@ -44,10 +52,8 @@ void ProgramManager::ProgramInfo::Update() { } GLint num_uniforms; - glGetProgramiv(program_id_, GL_ACTIVE_UNIFORMS, &num_uniforms); - uniform_infos_.clear(); - sampler_indices_.clear(); - glGetProgramiv(program_id_, GL_ACTIVE_UNIFORM_MAX_LENGTH, &max_len); + glGetProgramiv(service_id_, GL_ACTIVE_UNIFORMS, &num_uniforms); + glGetProgramiv(service_id_, GL_ACTIVE_UNIFORM_MAX_LENGTH, &max_len); name_buffer.reset(new char[max_len]); GLint max_location = -1; int index = 0; // this index tracks valid uniforms. @@ -56,10 +62,10 @@ void ProgramManager::ProgramInfo::Update() { GLsizei size; GLenum type; glGetActiveUniform( - program_id_, ii, max_len, &length, &size, &type, name_buffer.get()); + service_id_, ii, max_len, &length, &size, &type, name_buffer.get()); // TODO(gman): Should we check for error? if (!IsInvalidPrefix(name_buffer.get(), length)) { - GLint location = glGetUniformLocation(program_id_, name_buffer.get()); + GLint location = glGetUniformLocation(service_id_, name_buffer.get()); const UniformInfo* info = AddUniformInfo(size, type, location, name_buffer.get()); for (size_t jj = 0; jj < info->element_locations.size(); ++jj) { @@ -87,6 +93,7 @@ void ProgramManager::ProgramInfo::Update() { location_to_index_map_[info.element_locations[jj]] = ii; } } + valid_ = true; } GLint ProgramManager::ProgramInfo::GetUniformLocation( @@ -165,7 +172,7 @@ const ProgramManager::ProgramInfo::UniformInfo* for (GLsizei ii = 1; ii < info.size; ++ii) { std::string element_name(name + "[" + IntToString(ii) + "]"); info.element_locations[ii] = - glGetUniformLocation(program_id_, element_name.c_str()); + glGetUniformLocation(service_id_, element_name.c_str()); } // Sadly there is no way to tell if this is an array except if the name // has an array string or the size > 1. That means an array of size 1 can @@ -222,26 +229,26 @@ void ProgramManager::ProgramInfo::GetProgramiv(GLenum pname, GLint* params) { *params = max_uniform_name_length_; break; default: - glGetProgramiv(program_id_, pname, params); + glGetProgramiv(service_id_, pname, params); break; } } -void ProgramManager::CreateProgramInfo(GLuint program_id) { +void ProgramManager::CreateProgramInfo(GLuint client_id, GLuint service_id) { std::pair<ProgramInfoMap::iterator, bool> result = program_infos_.insert( - std::make_pair(program_id, - ProgramInfo::Ref(new ProgramInfo(program_id)))); + std::make_pair(client_id, + ProgramInfo::Ref(new ProgramInfo(service_id)))); DCHECK(result.second); } -ProgramManager::ProgramInfo* ProgramManager::GetProgramInfo(GLuint program_id) { - ProgramInfoMap::iterator it = program_infos_.find(program_id); +ProgramManager::ProgramInfo* ProgramManager::GetProgramInfo(GLuint client_id) { + ProgramInfoMap::iterator it = program_infos_.find(client_id); return it != program_infos_.end() ? it->second : NULL; } -void ProgramManager::RemoveProgramInfo(GLuint program_id) { - ProgramInfoMap::iterator it = program_infos_.find(program_id); +void ProgramManager::RemoveProgramInfo(GLuint client_id) { + ProgramInfoMap::iterator it = program_infos_.find(client_id); if (it != program_infos_.end()) { it->second->MarkAsDeleted(); program_infos_.erase(it); diff --git a/gpu/command_buffer/service/program_manager.h b/gpu/command_buffer/service/program_manager.h index 48c5440..078f8a5 100644 --- a/gpu/command_buffer/service/program_manager.h +++ b/gpu/command_buffer/service/program_manager.h @@ -64,16 +64,25 @@ class ProgramManager { typedef std::vector<VertexAttribInfo> AttribInfoVector; typedef std::vector<int> SamplerIndices; - explicit ProgramInfo(GLuint program_id) + explicit ProgramInfo(GLuint service_id) : max_attrib_name_length_(0), max_uniform_name_length_(0), - program_id_(program_id) { + service_id_(service_id), + valid_(false) { + } + + GLuint service_id() const { + return service_id_; } const SamplerIndices& sampler_indices() { return sampler_indices_; } + // Resets the program after an unsuccessful link. + void Reset(); + + // Updates the program info after a successful link. void Update(); const AttribInfoVector& GetAttribInfos() const { @@ -104,11 +113,15 @@ class ProgramManager { bool SetSamplers(GLint location, GLsizei count, const GLint* value); bool IsDeleted() const { - return program_id_ == 0; + return service_id_ == 0; } void GetProgramiv(GLenum pname, GLint* params); + bool IsValid() const { + return valid_; + } + private: friend class base::RefCounted<ProgramInfo>; friend class ProgramManager; @@ -116,7 +129,7 @@ class ProgramManager { ~ProgramInfo() { } void MarkAsDeleted() { - program_id_ = 0; + service_id_ = 0; } const UniformInfo* AddUniformInfo( @@ -138,19 +151,22 @@ class ProgramManager { SamplerIndices sampler_indices_; // The program this ProgramInfo is tracking. - GLuint program_id_; + GLuint service_id_; + + // This is true if glLinkProgram was successful. + bool valid_; }; ProgramManager() { } // Creates a new program info. - void CreateProgramInfo(GLuint program_id); + void CreateProgramInfo(GLuint client_id, GLuint service_id); // Gets a program info - ProgramInfo* GetProgramInfo(GLuint program_id); + ProgramInfo* GetProgramInfo(GLuint client_id); // Deletes the program info for the given program. - void RemoveProgramInfo(GLuint program_id); + void RemoveProgramInfo(GLuint client_id); // Returns true if prefix is invalid for gl. static bool IsInvalidPrefix(const char* name, size_t length); diff --git a/gpu/command_buffer/service/program_manager_unittest.cc b/gpu/command_buffer/service/program_manager_unittest.cc index c0f1409..48fd50b 100644 --- a/gpu/command_buffer/service/program_manager_unittest.cc +++ b/gpu/command_buffer/service/program_manager_unittest.cc @@ -38,20 +38,22 @@ class ProgramManagerTest : public testing::Test { }; TEST_F(ProgramManagerTest, Basic) { - const GLuint kProgram1Id = 1; - const GLuint kProgram2Id = 2; + const GLuint kClient1Id = 1; + const GLuint kService1Id = 11; + const GLuint kClient2Id = 2; // Check we can create program. - manager_.CreateProgramInfo(kProgram1Id); + manager_.CreateProgramInfo(kClient1Id, kService1Id); // Check program got created. - ProgramManager::ProgramInfo* info1 = manager_.GetProgramInfo(kProgram1Id); + ProgramManager::ProgramInfo* info1 = manager_.GetProgramInfo(kClient1Id); ASSERT_TRUE(info1 != NULL); + EXPECT_EQ(kService1Id, info1->service_id()); // Check we get nothing for a non-existent program. - EXPECT_TRUE(manager_.GetProgramInfo(kProgram2Id) == NULL); + EXPECT_TRUE(manager_.GetProgramInfo(kClient2Id) == NULL); // Check trying to a remove non-existent programs does not crash. - manager_.RemoveProgramInfo(kProgram2Id); + manager_.RemoveProgramInfo(kClient2Id); // Check we can't get the program after we remove it. - manager_.RemoveProgramInfo(kProgram1Id); - EXPECT_TRUE(manager_.GetProgramInfo(kProgram1Id) == NULL); + manager_.RemoveProgramInfo(kClient1Id); + EXPECT_TRUE(manager_.GetProgramInfo(kClient1Id) == NULL); } class ProgramManagerWithShaderTest : public testing::Test { @@ -62,7 +64,8 @@ class ProgramManagerWithShaderTest : public testing::Test { static const GLint kNumVertexAttribs = 16; - static const GLuint kProgramId = 123; + static const GLuint kClientProgramId = 123; + static const GLuint kServiceProgramId = 456; static const char* kAttrib1Name; static const char* kAttrib2Name; @@ -118,8 +121,8 @@ class ProgramManagerWithShaderTest : public testing::Test { SetupDefaultShaderExpectations(); - manager_.CreateProgramInfo(kProgramId); - program_info_ = manager_.GetProgramInfo(kProgramId); + manager_.CreateProgramInfo(kClientProgramId, kServiceProgramId); + program_info_ = manager_.GetProgramInfo(kClientProgramId); program_info_->Update(); } @@ -206,7 +209,7 @@ class ProgramManagerWithShaderTest : public testing::Test { void SetupDefaultShaderExpectations() { SetupShader(kAttribs, kNumAttribs, kUniforms, kNumUniforms, - kProgramId); + kServiceProgramId); } virtual void TearDown() { @@ -232,7 +235,8 @@ ProgramManagerWithShaderTest::AttribInfo // GCC requires these declarations, but MSVC requires they not be present #ifndef COMPILER_MSVC const GLint ProgramManagerWithShaderTest::kNumVertexAttribs; -const GLuint ProgramManagerWithShaderTest::kProgramId; +const GLuint ProgramManagerWithShaderTest::kClientProgramId; +const GLuint ProgramManagerWithShaderTest::kServiceProgramId; const GLint ProgramManagerWithShaderTest::kAttrib1Size; const GLint ProgramManagerWithShaderTest::kAttrib2Size; const GLint ProgramManagerWithShaderTest::kAttrib3Size; @@ -281,7 +285,7 @@ const char* ProgramManagerWithShaderTest::kUniform3Name = "uniform3"; TEST_F(ProgramManagerWithShaderTest, GetAttribInfos) { const ProgramManager::ProgramInfo* program_info = - manager_.GetProgramInfo(kProgramId); + manager_.GetProgramInfo(kClientProgramId); ASSERT_TRUE(program_info != NULL); const ProgramManager::ProgramInfo::AttribInfoVector& infos = program_info->GetAttribInfos(); @@ -299,7 +303,7 @@ TEST_F(ProgramManagerWithShaderTest, GetAttribInfo) { const GLint kValidIndex = 1; const GLint kInvalidIndex = 1000; const ProgramManager::ProgramInfo* program_info = - manager_.GetProgramInfo(kProgramId); + manager_.GetProgramInfo(kClientProgramId); ASSERT_TRUE(program_info != NULL); const ProgramManager::ProgramInfo::VertexAttribInfo* info = program_info->GetAttribInfo(kValidIndex); @@ -314,7 +318,7 @@ TEST_F(ProgramManagerWithShaderTest, GetAttribInfo) { TEST_F(ProgramManagerWithShaderTest, GetAttribLocation) { const char* kInvalidName = "foo"; const ProgramManager::ProgramInfo* program_info = - manager_.GetProgramInfo(kProgramId); + manager_.GetProgramInfo(kClientProgramId); ASSERT_TRUE(program_info != NULL); EXPECT_EQ(kAttrib2Location, program_info->GetAttribLocation(kAttrib2Name)); EXPECT_EQ(-1, program_info->GetAttribLocation(kInvalidName)); @@ -323,7 +327,7 @@ TEST_F(ProgramManagerWithShaderTest, GetAttribLocation) { TEST_F(ProgramManagerWithShaderTest, GetUniformInfo) { const GLint kInvalidIndex = 1000; const ProgramManager::ProgramInfo* program_info = - manager_.GetProgramInfo(kProgramId); + manager_.GetProgramInfo(kClientProgramId); ASSERT_TRUE(program_info != NULL); const ProgramManager::ProgramInfo::UniformInfo* info = program_info->GetUniformInfo(0); @@ -352,7 +356,7 @@ TEST_F(ProgramManagerWithShaderTest, GetUniformInfo) { TEST_F(ProgramManagerWithShaderTest, GetUniformLocation) { const ProgramManager::ProgramInfo* program_info = - manager_.GetProgramInfo(kProgramId); + manager_.GetProgramInfo(kClientProgramId); ASSERT_TRUE(program_info != NULL); EXPECT_EQ(kUniform1Location, program_info->GetUniformLocation(kUniform1Name)); EXPECT_EQ(kUniform2Location, program_info->GetUniformLocation(kUniform2Name)); @@ -380,7 +384,7 @@ TEST_F(ProgramManagerWithShaderTest, GetUniformTypeByLocation) { const GLint kInvalidLocation = 1234; GLenum type = 0u; const ProgramManager::ProgramInfo* program_info = - manager_.GetProgramInfo(kProgramId); + manager_.GetProgramInfo(kClientProgramId); ASSERT_TRUE(program_info != NULL); EXPECT_TRUE(program_info->GetUniformTypeByLocation(kUniform2Location, &type)); EXPECT_EQ(kUniform2Type, type); @@ -401,11 +405,13 @@ TEST_F(ProgramManagerWithShaderTest, GLDriverReturnsGLUnderscoreUniform) { { kUniform3Name, kUniform3Size, kUniform3Type, kUniform3Location, }, }; const size_t kNumUniforms = arraysize(kUniforms); - static const GLuint kProgramId = 1234; - SetupShader(kAttribs, kNumAttribs, kUniforms, kNumUniforms, kProgramId); - manager_.CreateProgramInfo(kProgramId); + static const GLuint kClientProgramId = 1234; + static const GLuint kServiceProgramId = 5679; + SetupShader(kAttribs, kNumAttribs, kUniforms, kNumUniforms, + kServiceProgramId); + manager_.CreateProgramInfo(kClientProgramId, kServiceProgramId); ProgramManager::ProgramInfo* program_info = - manager_.GetProgramInfo(kProgramId); + manager_.GetProgramInfo(kClientProgramId); ASSERT_TRUE(program_info != NULL); program_info->Update(); GLint value = 0; diff --git a/gpu/command_buffer/service/renderbuffer_manager.cc b/gpu/command_buffer/service/renderbuffer_manager.cc index 0b5441d..fe07d01 100644 --- a/gpu/command_buffer/service/renderbuffer_manager.cc +++ b/gpu/command_buffer/service/renderbuffer_manager.cc @@ -10,26 +10,27 @@ namespace gpu { namespace gles2 { -void RenderbufferManager::CreateRenderbufferInfo(GLuint renderbuffer_id) { +void RenderbufferManager::CreateRenderbufferInfo( + GLuint client_id, GLuint service_id) { std::pair<RenderbufferInfoMap::iterator, bool> result = renderbuffer_infos_.insert( std::make_pair( - renderbuffer_id, - RenderbufferInfo::Ref(new RenderbufferInfo(renderbuffer_id)))); + client_id, + RenderbufferInfo::Ref(new RenderbufferInfo(service_id)))); DCHECK(result.second); } RenderbufferManager::RenderbufferInfo* RenderbufferManager::GetRenderbufferInfo( - GLuint renderbuffer_id) { - RenderbufferInfoMap::iterator it = renderbuffer_infos_.find(renderbuffer_id); + GLuint client_id) { + RenderbufferInfoMap::iterator it = renderbuffer_infos_.find(client_id); return it != renderbuffer_infos_.end() ? it->second : NULL; } -void RenderbufferManager::RemoveRenderbufferInfo(GLuint renderbuffer_id) { - RenderbufferInfoMap::iterator it = renderbuffer_infos_.find(renderbuffer_id); +void RenderbufferManager::RemoveRenderbufferInfo(GLuint client_id) { + RenderbufferInfoMap::iterator it = renderbuffer_infos_.find(client_id); if (it != renderbuffer_infos_.end()) { it->second->MarkAsDeleted(); - renderbuffer_infos_.erase(renderbuffer_id); + renderbuffer_infos_.erase(it); } } diff --git a/gpu/command_buffer/service/renderbuffer_manager.h b/gpu/command_buffer/service/renderbuffer_manager.h index 47c5282..8e2f70b 100644 --- a/gpu/command_buffer/service/renderbuffer_manager.h +++ b/gpu/command_buffer/service/renderbuffer_manager.h @@ -24,13 +24,13 @@ class RenderbufferManager { public: typedef scoped_refptr<RenderbufferInfo> Ref; - explicit RenderbufferInfo(GLuint renderbuffer_id) - : renderbuffer_id_(renderbuffer_id), + explicit RenderbufferInfo(GLuint service_id) + : service_id_(service_id), cleared_(false) { } - GLuint renderbuffer_id() const { - return renderbuffer_id_; + GLuint service_id() const { + return service_id_; } bool cleared() const { @@ -42,7 +42,7 @@ class RenderbufferManager { } bool IsDeleted() { - return renderbuffer_id_ == 0; + return service_id_ == 0; } private: @@ -52,11 +52,11 @@ class RenderbufferManager { ~RenderbufferInfo() { } void MarkAsDeleted() { - renderbuffer_id_ = 0; + service_id_ = 0; } // Service side renderbuffer id. - GLuint renderbuffer_id_; + GLuint service_id_; // Whether this renderbuffer has been cleared bool cleared_; @@ -65,13 +65,13 @@ class RenderbufferManager { RenderbufferManager() { } // Creates a RenderbufferInfo for the given renderbuffer. - void CreateRenderbufferInfo(GLuint renderbuffer_id); + void CreateRenderbufferInfo(GLuint client_id, GLuint service_id); // Gets the renderbuffer info for the given renderbuffer. - RenderbufferInfo* GetRenderbufferInfo(GLuint renderbuffer_id); + RenderbufferInfo* GetRenderbufferInfo(GLuint client_id); // Removes a renderbuffer info for the given renderbuffer. - void RemoveRenderbufferInfo(GLuint renderbuffer_id); + void RemoveRenderbufferInfo(GLuint client_id); private: // Info for each renderbuffer in the system. diff --git a/gpu/command_buffer/service/renderbuffer_manager_unittest.cc b/gpu/command_buffer/service/renderbuffer_manager_unittest.cc index 7f9d064..bebd8fc 100644 --- a/gpu/command_buffer/service/renderbuffer_manager_unittest.cc +++ b/gpu/command_buffer/service/renderbuffer_manager_unittest.cc @@ -24,26 +24,27 @@ class RenderbufferManagerTest : public testing::Test { }; TEST_F(RenderbufferManagerTest, Basic) { - const GLuint kRenderbuffer1Id = 1; - const GLuint kRenderbuffer2Id = 2; + const GLuint kClient1Id = 1; + const GLuint kService1Id = 11; + const GLuint kClient2Id = 2; // Check we can create renderbuffer. - manager_.CreateRenderbufferInfo(kRenderbuffer1Id); + manager_.CreateRenderbufferInfo(kClient1Id, kService1Id); // Check renderbuffer got created. RenderbufferManager::RenderbufferInfo* info1 = - manager_.GetRenderbufferInfo(kRenderbuffer1Id); + manager_.GetRenderbufferInfo(kClient1Id); ASSERT_TRUE(info1 != NULL); EXPECT_FALSE(info1->cleared()); info1->set_cleared(); EXPECT_TRUE(info1->cleared()); EXPECT_FALSE(info1->IsDeleted()); - EXPECT_EQ(kRenderbuffer1Id, info1->renderbuffer_id()); + EXPECT_EQ(kService1Id, info1->service_id()); // Check we get nothing for a non-existent renderbuffer. - EXPECT_TRUE(manager_.GetRenderbufferInfo(kRenderbuffer2Id) == NULL); + EXPECT_TRUE(manager_.GetRenderbufferInfo(kClient2Id) == NULL); // Check trying to a remove non-existent renderbuffers does not crash. - manager_.RemoveRenderbufferInfo(kRenderbuffer2Id); + manager_.RemoveRenderbufferInfo(kClient2Id); // Check we can't get the renderbuffer after we remove it. - manager_.RemoveRenderbufferInfo(kRenderbuffer1Id); - EXPECT_TRUE(manager_.GetRenderbufferInfo(kRenderbuffer1Id) == NULL); + manager_.RemoveRenderbufferInfo(kClient1Id); + EXPECT_TRUE(manager_.GetRenderbufferInfo(kClient1Id) == NULL); } } // namespace gles2 diff --git a/gpu/command_buffer/service/shader_manager.cc b/gpu/command_buffer/service/shader_manager.cc index 0daa0dc..53cb689 100644 --- a/gpu/command_buffer/service/shader_manager.cc +++ b/gpu/command_buffer/service/shader_manager.cc @@ -8,26 +8,38 @@ namespace gpu { namespace gles2 { -void ShaderManager::CreateShaderInfo(GLuint shader_id) { +void ShaderManager::CreateShaderInfo(GLuint client_id, GLuint service_id) { std::pair<ShaderInfoMap::iterator, bool> result = shader_infos_.insert(std::make_pair( - shader_id, ShaderInfo::Ref(new ShaderInfo(shader_id)))); + client_id, ShaderInfo::Ref(new ShaderInfo(service_id)))); DCHECK(result.second); } -ShaderManager::ShaderInfo* ShaderManager::GetShaderInfo(GLuint shader_id) { - ShaderInfoMap::iterator it = shader_infos_.find(shader_id); +ShaderManager::ShaderInfo* ShaderManager::GetShaderInfo(GLuint client_id) { + ShaderInfoMap::iterator it = shader_infos_.find(client_id); return it != shader_infos_.end() ? it->second : NULL; } -void ShaderManager::RemoveShaderInfo(GLuint shader_id) { - ShaderInfoMap::iterator it = shader_infos_.find(shader_id); +void ShaderManager::RemoveShaderInfo(GLuint client_id) { + ShaderInfoMap::iterator it = shader_infos_.find(client_id); if (it != shader_infos_.end()) { it->second->MarkAsDeleted(); shader_infos_.erase(it); } } +bool ShaderManager::GetClientId(GLuint service_id, GLuint* client_id) const { + // This doesn't need to be fast. It's only used during slow queries. + for (ShaderInfoMap::const_iterator it = shader_infos_.begin(); + it != shader_infos_.end(); ++it) { + if (it->second->service_id() == service_id) { + *client_id = it->first; + return true; + } + } + return false; +} + } // namespace gles2 } // namespace gpu diff --git a/gpu/command_buffer/service/shader_manager.h b/gpu/command_buffer/service/shader_manager.h index f9529e9..d911044 100644 --- a/gpu/command_buffer/service/shader_manager.h +++ b/gpu/command_buffer/service/shader_manager.h @@ -28,20 +28,24 @@ class ShaderManager { public: typedef scoped_refptr<ShaderInfo> Ref; - explicit ShaderInfo(GLuint shader_id) - : shader_id_(shader_id) { + explicit ShaderInfo(GLuint service_id) + : service_id_(service_id) { } void Update(const std::string& source) { source_ = source; } + GLuint service_id() const { + return service_id_; + } + const std::string& source() { return source_; } bool IsDeleted() { - return shader_id_ == 0; + return service_id_ == 0; } private: @@ -50,11 +54,11 @@ class ShaderManager { ~ShaderInfo() { } void MarkAsDeleted() { - shader_id_ = 0; + service_id_ = 0; } // The shader this ShaderInfo is tracking. - GLuint shader_id_; + GLuint service_id_; // The shader source as passed to glShaderSource. std::string source_; @@ -64,14 +68,17 @@ class ShaderManager { } // Creates a shader info for the given shader ID. - void CreateShaderInfo(GLuint shader_id); + void CreateShaderInfo(GLuint client_id, GLuint service_id); // Gets an existing shader info for the given shader ID. Returns NULL if none // exists. - ShaderInfo* GetShaderInfo(GLuint shader_id); + ShaderInfo* GetShaderInfo(GLuint client_id); // Deletes the shader info for the given shader. - void RemoveShaderInfo(GLuint shader_id); + void RemoveShaderInfo(GLuint client_id); + + // Gets a client id for a given service id. + bool GetClientId(GLuint service_id, GLuint* client_id) const; private: // Info for each shader by service side shader Id. diff --git a/gpu/command_buffer/service/shader_manager_unittest.cc b/gpu/command_buffer/service/shader_manager_unittest.cc index 20bad1b..c30d4c6 100644 --- a/gpu/command_buffer/service/shader_manager_unittest.cc +++ b/gpu/command_buffer/service/shader_manager_unittest.cc @@ -24,24 +24,26 @@ class ShaderManagerTest : public testing::Test { }; TEST_F(ShaderManagerTest, Basic) { - const GLuint kShader1Id = 1; - const std::string kShader1Source("hello world"); - const GLuint kShader2Id = 2; + const GLuint kClient1Id = 1; + const GLuint kService1Id = 11; + const std::string kClient1Source("hello world"); + const GLuint kClient2Id = 2; // Check we can create shader. - manager_.CreateShaderInfo(kShader1Id); + manager_.CreateShaderInfo(kClient1Id, kService1Id); // Check shader got created. - ShaderManager::ShaderInfo* info1 = manager_.GetShaderInfo(kShader1Id); + ShaderManager::ShaderInfo* info1 = manager_.GetShaderInfo(kClient1Id); ASSERT_TRUE(info1 != NULL); + EXPECT_EQ(kService1Id, info1->service_id()); // Check we and set its source. - info1->Update(kShader1Source); - EXPECT_STREQ(kShader1Source.c_str(), info1->source().c_str()); + info1->Update(kClient1Source); + EXPECT_STREQ(kClient1Source.c_str(), info1->source().c_str()); // Check we get nothing for a non-existent shader. - EXPECT_TRUE(manager_.GetShaderInfo(kShader2Id) == NULL); + EXPECT_TRUE(manager_.GetShaderInfo(kClient2Id) == NULL); // Check trying to a remove non-existent shaders does not crash. - manager_.RemoveShaderInfo(kShader2Id); + manager_.RemoveShaderInfo(kClient2Id); // Check we can't get the shader after we remove it. - manager_.RemoveShaderInfo(kShader1Id); - EXPECT_TRUE(manager_.GetShaderInfo(kShader1Id) == NULL); + manager_.RemoveShaderInfo(kClient1Id); + EXPECT_TRUE(manager_.GetShaderInfo(kClient1Id) == NULL); } } // namespace gles2 diff --git a/gpu/command_buffer/service/texture_manager.cc b/gpu/command_buffer/service/texture_manager.cc index a895e27..326d2b3 100644 --- a/gpu/command_buffer/service/texture_manager.cc +++ b/gpu/command_buffer/service/texture_manager.cc @@ -278,28 +278,40 @@ TextureManager::TextureManager( } TextureManager::TextureInfo* TextureManager::CreateTextureInfo( - GLuint texture_id) { - TextureInfo::Ref info(new TextureInfo(texture_id)); + GLuint client_id, GLuint service_id) { + TextureInfo::Ref info(new TextureInfo(service_id)); std::pair<TextureInfoMap::iterator, bool> result = - texture_infos_.insert(std::make_pair(texture_id, info)); + texture_infos_.insert(std::make_pair(client_id, info)); DCHECK(result.second); return info.get(); } TextureManager::TextureInfo* TextureManager::GetTextureInfo( - GLuint texture_id) { - TextureInfoMap::iterator it = texture_infos_.find(texture_id); + GLuint client_id) { + TextureInfoMap::iterator it = texture_infos_.find(client_id); return it != texture_infos_.end() ? it->second : NULL; } -void TextureManager::RemoveTextureInfo(GLuint texture_id) { - TextureInfoMap::iterator it = texture_infos_.find(texture_id); +void TextureManager::RemoveTextureInfo(GLuint client_id) { + TextureInfoMap::iterator it = texture_infos_.find(client_id); if (it != texture_infos_.end()) { it->second->MarkAsDeleted(); - texture_infos_.erase(texture_id); + texture_infos_.erase(it); } } +bool TextureManager::GetClientId(GLuint service_id, GLuint* client_id) const { + // This doesn't need to be fast. It's only used during slow queries. + for (TextureInfoMap::const_iterator it = texture_infos_.begin(); + it != texture_infos_.end(); ++it) { + if (it->second->service_id() == service_id) { + *client_id = it->first; + return true; + } + } + return false; +} + } // namespace gles2 } // namespace gpu diff --git a/gpu/command_buffer/service/texture_manager.h b/gpu/command_buffer/service/texture_manager.h index a2db386..14da6c2 100644 --- a/gpu/command_buffer/service/texture_manager.h +++ b/gpu/command_buffer/service/texture_manager.h @@ -27,8 +27,8 @@ class TextureManager { public: typedef scoped_refptr<TextureInfo> Ref; - explicit TextureInfo(GLuint texture_id) - : texture_id_(texture_id), + explicit TextureInfo(GLuint service_id) + : service_id_(service_id), deleted_(false), target_(0), min_filter_(GL_NEAREST_MIPMAP_LINEAR), @@ -46,8 +46,8 @@ class TextureManager { bool CanRender() const; // The service side OpenGL id of the texture. - GLuint texture_id() const { - return texture_id_; + GLuint service_id() const { + return service_id_; } // Returns the target this texure was first bound to or 0 if it has not @@ -135,7 +135,7 @@ class TextureManager { }; void MarkAsDeleted() { - texture_id_ = 0; + service_id_ = 0; deleted_ = true; } @@ -164,7 +164,7 @@ class TextureManager { std::vector<std::vector<LevelInfo> > level_infos_; // The id of the texure - GLuint texture_id_; + GLuint service_id_; // Whether this texture has been deleted. bool deleted_; @@ -234,13 +234,16 @@ class TextureManager { } // Creates a new texture info. - TextureInfo* CreateTextureInfo(GLuint texture_id); + TextureInfo* CreateTextureInfo(GLuint client_id, GLuint service_id); // Gets the texture info for the given texture. - TextureInfo* GetTextureInfo(GLuint texture_id); + TextureInfo* GetTextureInfo(GLuint client_id); // Removes a texture info. - void RemoveTextureInfo(GLuint texture_id); + void RemoveTextureInfo(GLuint client_id); + + // Gets a client id for a given service id. + bool GetClientId(GLuint service_id, GLuint* client_id) const; TextureInfo* GetDefaultTextureInfo(GLenum target) { return target == GL_TEXTURE_2D ? default_texture_2d_ : diff --git a/gpu/command_buffer/service/texture_manager_unittest.cc b/gpu/command_buffer/service/texture_manager_unittest.cc index 0383864a..50af31a 100644 --- a/gpu/command_buffer/service/texture_manager_unittest.cc +++ b/gpu/command_buffer/service/texture_manager_unittest.cc @@ -38,20 +38,22 @@ const GLint TextureManagerTest::kMaxCubeMapLevels; #endif TEST_F(TextureManagerTest, Basic) { - const GLuint kTexture1Id = 1; - const GLuint kTexture2Id = 2; + const GLuint kClient1Id = 1; + const GLuint kService1Id = 11; + const GLuint kClient2Id = 2; // Check we can create texture. - manager_.CreateTextureInfo(kTexture1Id); + manager_.CreateTextureInfo(kClient1Id, kService1Id); // Check texture got created. - TextureManager::TextureInfo* info1 = manager_.GetTextureInfo(kTexture1Id); + TextureManager::TextureInfo* info1 = manager_.GetTextureInfo(kClient1Id); ASSERT_TRUE(info1 != NULL); + EXPECT_EQ(kService1Id, info1->service_id()); // Check we get nothing for a non-existent texture. - EXPECT_TRUE(manager_.GetTextureInfo(kTexture2Id) == NULL); + EXPECT_TRUE(manager_.GetTextureInfo(kClient2Id) == NULL); // Check trying to a remove non-existent textures does not crash. - manager_.RemoveTextureInfo(kTexture2Id); + manager_.RemoveTextureInfo(kClient2Id); // Check we can't get the texture after we remove it. - manager_.RemoveTextureInfo(kTexture1Id); - EXPECT_TRUE(manager_.GetTextureInfo(kTexture1Id) == NULL); + manager_.RemoveTextureInfo(kClient1Id); + EXPECT_TRUE(manager_.GetTextureInfo(kClient1Id) == NULL); } TEST_F(TextureManagerTest, MaxValues) { @@ -114,7 +116,8 @@ class TextureInfoTest : public testing::Test { static const GLint kMaxCubeMapTextureSize = 8; static const GLint kMax2dLevels = 5; static const GLint kMaxCubeMapLevels = 4; - static const GLuint kTexture1Id = 1; + static const GLuint kClient1Id = 1; + static const GLuint kService1Id = 11; TextureInfoTest() : manager_(kMaxTextureSize, kMaxCubeMapTextureSize) { @@ -122,8 +125,8 @@ class TextureInfoTest : public testing::Test { protected: virtual void SetUp() { - manager_.CreateTextureInfo(kTexture1Id); - info_ = manager_.GetTextureInfo(kTexture1Id); + manager_.CreateTextureInfo(kClient1Id, kService1Id); + info_ = manager_.GetTextureInfo(kClient1Id); ASSERT_TRUE(info_ != NULL); } @@ -295,7 +298,7 @@ TEST_F(TextureInfoTest, GetLevelSize) { EXPECT_TRUE(info_->GetLevelSize(GL_TEXTURE_2D, 1, &width, &height)); EXPECT_EQ(4, width); EXPECT_EQ(5, height); - manager_.RemoveTextureInfo(info_->texture_id()); + manager_.RemoveTextureInfo(kClient1Id); EXPECT_FALSE(info_->GetLevelSize(GL_TEXTURE_2D, 1, &width, &height)); } |