diff options
author | apatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-03 22:49:57 +0000 |
---|---|---|
committer | apatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-03 22:49:57 +0000 |
commit | 3b1ecc26f9030a105858477a2147a76fcfa6d628 (patch) | |
tree | 3ff5ef3f0ab6e7742500b3072a26de18bfde9340 /gpu | |
parent | 066957fe6d4b9be3d5921b37249af5ba45451c7a (diff) | |
download | chromium_src-3b1ecc26f9030a105858477a2147a76fcfa6d628.zip chromium_src-3b1ecc26f9030a105858477a2147a76fcfa6d628.tar.gz chromium_src-3b1ecc26f9030a105858477a2147a76fcfa6d628.tar.bz2 |
Implemented support for GL context share groups in the renderer process.I put all compositor and canvas contexts in the same share group so they can share IDs.
Review URL: http://codereview.chromium.org/7554015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@95345 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gpu')
-rw-r--r-- | gpu/command_buffer/common/gles2_cmd_format.h | 3 | ||||
-rw-r--r-- | gpu/command_buffer/common/id_allocator.cc | 33 | ||||
-rw-r--r-- | gpu/command_buffer/common/id_allocator.h | 56 | ||||
-rw-r--r-- | gpu/command_buffer/service/context_group.cc | 19 | ||||
-rw-r--r-- | gpu/command_buffer/service/context_group.h | 9 | ||||
-rw-r--r-- | gpu/command_buffer/service/gles2_cmd_decoder.cc | 18 | ||||
-rw-r--r-- | gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc | 2 | ||||
-rw-r--r-- | gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h | 2 |
8 files changed, 110 insertions, 32 deletions
diff --git a/gpu/command_buffer/common/gles2_cmd_format.h b/gpu/command_buffer/common/gles2_cmd_format.h index ec9ea33..484b266 100644 --- a/gpu/command_buffer/common/gles2_cmd_format.h +++ b/gpu/command_buffer/common/gles2_cmd_format.h @@ -52,7 +52,8 @@ enum IdNamespaces { kFramebuffers, kProgramsAndShaders, kRenderbuffers, - kTextures + kTextures, + kNumIdNamespaces }; // These numbers must not change diff --git a/gpu/command_buffer/common/id_allocator.cc b/gpu/command_buffer/common/id_allocator.cc index eb450f3..e3fbdd5 100644 --- a/gpu/command_buffer/common/id_allocator.cc +++ b/gpu/command_buffer/common/id_allocator.cc @@ -9,6 +9,9 @@ namespace gpu { +IdAllocatorInterface::~IdAllocatorInterface() { +} + IdAllocator::IdAllocator() {} IdAllocator::~IdAllocator() {} @@ -85,4 +88,34 @@ ResourceId IdAllocator::FindFirstUnusedId() const { return id; } +NonReusedIdAllocator::NonReusedIdAllocator() : last_id_(0) { +} + +NonReusedIdAllocator::~NonReusedIdAllocator() { +} + +ResourceId NonReusedIdAllocator::AllocateID() { + return ++last_id_; +} + +ResourceId NonReusedIdAllocator::AllocateIDAtOrAbove(ResourceId desired_id) { + if (desired_id > last_id_) + last_id_ = desired_id; + + return ++last_id_; +} + +bool NonReusedIdAllocator::MarkAsUsed(ResourceId id) { + GPU_NOTREACHED(); + return false; +} + +void NonReusedIdAllocator::FreeID(ResourceId id) { +} + +bool NonReusedIdAllocator::InUse(ResourceId id) const { + GPU_NOTREACHED(); + return false; +} + } // namespace gpu diff --git a/gpu/command_buffer/common/id_allocator.h b/gpu/command_buffer/common/id_allocator.h index 4e80290..23c93d2 100644 --- a/gpu/command_buffer/common/id_allocator.h +++ b/gpu/command_buffer/common/id_allocator.h @@ -11,6 +11,10 @@ #include <utility> #include "../common/types.h" +// TODO(apatrick): Having regular GL flush semantics on the client side, it +// probably isn't necessary to round trip to the service to allocate IDs. +// Retire this code. + namespace gpu { // A resource ID, key to the resource maps. @@ -18,27 +22,39 @@ typedef uint32 ResourceId; // Invalid resource ID. static const ResourceId kInvalidResource = 0u; -// A class to manage the allocation of resource IDs. -class IdAllocator { +class IdAllocatorInterface { public: - IdAllocator(); - ~IdAllocator(); + virtual ~IdAllocatorInterface(); // Allocates a new resource ID. - ResourceId AllocateID(); + virtual ResourceId AllocateID() = 0; // Allocates an Id starting at or above desired_id. // Note: may wrap if it starts near limit. - ResourceId AllocateIDAtOrAbove(ResourceId desired_id); + virtual ResourceId AllocateIDAtOrAbove(ResourceId desired_id) = 0; // Marks an id as used. Returns false if id was already used. - bool MarkAsUsed(ResourceId id); + virtual bool MarkAsUsed(ResourceId id) = 0; // Frees a resource ID. - void FreeID(ResourceId id); + virtual void FreeID(ResourceId id) = 0; // Checks whether or not a resource ID is in use. - bool InUse(ResourceId id) const; + virtual bool InUse(ResourceId id) const = 0; +}; + +// A class to manage the allocation of resource IDs. +class IdAllocator : public IdAllocatorInterface { + public: + IdAllocator(); + virtual ~IdAllocator(); + + // Implement IdAllocatorInterface. + virtual ResourceId AllocateID(); + virtual ResourceId AllocateIDAtOrAbove(ResourceId desired_id); + virtual bool MarkAsUsed(ResourceId id); + virtual void FreeID(ResourceId id); + virtual bool InUse(ResourceId id) const; private: // TODO(gman): This would work much better with ranges or a hash table. @@ -56,6 +72,28 @@ class IdAllocator { DISALLOW_COPY_AND_ASSIGN(IdAllocator); }; +// A class to manage the allocation of resource IDs that are never reused. This +// implementation does not track which IDs are currently used. It is useful for +// shared and programs which cannot be implicitly created by binding a +// previously unused ID. +class NonReusedIdAllocator : public IdAllocatorInterface { + public: + NonReusedIdAllocator(); + virtual ~NonReusedIdAllocator(); + + // Implement IdAllocatorInterface. + virtual ResourceId AllocateID(); + virtual ResourceId AllocateIDAtOrAbove(ResourceId desired_id); + virtual bool MarkAsUsed(ResourceId id); + virtual void FreeID(ResourceId id); + virtual bool InUse(ResourceId id) const; + + private: + ResourceId last_id_; + + DISALLOW_COPY_AND_ASSIGN(NonReusedIdAllocator); +}; + } // namespace gpu #endif // GPU_COMMAND_BUFFER_CLIENT_ID_ALLOCATOR_H_ diff --git a/gpu/command_buffer/service/context_group.cc b/gpu/command_buffer/service/context_group.cc index 7b474d3..f852835 100644 --- a/gpu/command_buffer/service/context_group.cc +++ b/gpu/command_buffer/service/context_group.cc @@ -27,6 +27,12 @@ ContextGroup::ContextGroup() max_fragment_uniform_vectors_(0u), max_varying_vectors_(0u), max_vertex_uniform_vectors_(0u) { + id_namespaces_[id_namespaces::kBuffers].reset(new IdAllocator); + id_namespaces_[id_namespaces::kFramebuffers].reset(new IdAllocator); + id_namespaces_[id_namespaces::kProgramsAndShaders].reset( + new NonReusedIdAllocator); + id_namespaces_[id_namespaces::kRenderbuffers].reset(new IdAllocator); + id_namespaces_[id_namespaces::kTextures].reset(new IdAllocator); } ContextGroup::~ContextGroup() { @@ -145,14 +151,11 @@ void ContextGroup::Destroy() { } } -IdAllocator* ContextGroup::GetIdAllocator(unsigned namespace_id) { - IdAllocatorMap::iterator it = id_namespaces_.find(namespace_id); - if (it != id_namespaces_.end()) { - return it->second.get(); - } - IdAllocator* id_allocator = new IdAllocator(); - id_namespaces_[namespace_id] = linked_ptr<IdAllocator>(id_allocator); - return id_allocator; +IdAllocatorInterface* ContextGroup::GetIdAllocator(unsigned namespace_id) { + if (namespace_id >= arraysize(id_namespaces_)) + return NULL; + + return id_namespaces_[namespace_id].get(); } } // namespace gles2 diff --git a/gpu/command_buffer/service/context_group.h b/gpu/command_buffer/service/context_group.h index 9bd3a58..a2e6382 100644 --- a/gpu/command_buffer/service/context_group.h +++ b/gpu/command_buffer/service/context_group.h @@ -11,12 +11,13 @@ #include "base/memory/linked_ptr.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" +#include "gpu/command_buffer/common/gles2_cmd_format.h" #include "gpu/command_buffer/service/gles2_cmd_validation.h" #include "gpu/command_buffer/service/feature_info.h" namespace gpu { -class IdAllocator; +class IdAllocatorInterface; namespace gles2 { @@ -103,7 +104,7 @@ class ContextGroup : public base::RefCounted<ContextGroup> { return shader_manager_.get(); } - IdAllocator* GetIdAllocator(unsigned namepsace_id); + IdAllocatorInterface* GetIdAllocator(unsigned namespace_id); private: // Destroys all the resources. @@ -133,8 +134,8 @@ class ContextGroup : public base::RefCounted<ContextGroup> { scoped_ptr<ShaderManager> shader_manager_; - typedef base::hash_map<uint32, linked_ptr<IdAllocator> > IdAllocatorMap; - IdAllocatorMap id_namespaces_; + linked_ptr<IdAllocatorInterface> + id_namespaces_[id_namespaces::kNumIdNamespaces]; FeatureInfo feature_info_; diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.cc b/gpu/command_buffer/service/gles2_cmd_decoder.cc index c982c9a..1dd1bfd 100644 --- a/gpu/command_buffer/service/gles2_cmd_decoder.cc +++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc @@ -1649,7 +1649,7 @@ GLES2DecoderImpl::GLES2DecoderImpl(SurfaceManager* surface_manager, ContextGroup* group) : GLES2Decoder(), surface_manager_(surface_manager), - group_(ContextGroup::Ref(group ? group : new ContextGroup())), + group_(group), error_bits_(0), pack_alignment_(4), unpack_alignment_(4), @@ -1695,6 +1695,8 @@ GLES2DecoderImpl::GLES2DecoderImpl(SurfaceManager* surface_manager, frame_number_(0), has_arb_robustness_(false), reset_status_(GL_NO_ERROR) { + DCHECK(group); + attrib_0_value_.v[0] = 0.0f; attrib_0_value_.v[1] = 0.0f; attrib_0_value_.v[2] = 0.0f; @@ -2727,7 +2729,7 @@ void GLES2DecoderImpl::DoBindBuffer(GLenum target, GLuint client_id) { glGenBuffersARB(1, &service_id); CreateBufferInfo(client_id, service_id); info = GetBufferInfo(client_id); - IdAllocator* id_allocator = + IdAllocatorInterface* id_allocator = group_->GetIdAllocator(id_namespaces::kBuffers); id_allocator->MarkAsUsed(client_id); } @@ -2806,7 +2808,7 @@ void GLES2DecoderImpl::DoBindFramebuffer(GLenum target, GLuint client_id) { glGenFramebuffersEXT(1, &service_id); CreateFramebufferInfo(client_id, service_id); info = GetFramebufferInfo(client_id); - IdAllocator* id_allocator = + IdAllocatorInterface* id_allocator = group_->GetIdAllocator(id_namespaces::kFramebuffers); id_allocator->MarkAsUsed(client_id); } else { @@ -2845,7 +2847,7 @@ void GLES2DecoderImpl::DoBindRenderbuffer(GLenum target, GLuint client_id) { glGenRenderbuffersEXT(1, &service_id); CreateRenderbufferInfo(client_id, service_id); info = GetRenderbufferInfo(client_id); - IdAllocator* id_allocator = + IdAllocatorInterface* id_allocator = group_->GetIdAllocator(id_namespaces::kRenderbuffers); id_allocator->MarkAsUsed(client_id); } else { @@ -2867,7 +2869,7 @@ void GLES2DecoderImpl::DoBindTexture(GLenum target, GLuint client_id) { glGenTextures(1, &service_id); CreateTextureInfo(client_id, service_id); info = GetTextureInfo(client_id); - IdAllocator* id_allocator = + IdAllocatorInterface* id_allocator = group_->GetIdAllocator(id_namespaces::kTextures); id_allocator->MarkAsUsed(client_id); } @@ -3360,7 +3362,7 @@ error::Error GLES2DecoderImpl::HandleDeleteProgram( void GLES2DecoderImpl::DoDeleteSharedIdsCHROMIUM( GLuint namespace_id, GLsizei n, const GLuint* ids) { - IdAllocator* id_allocator = group_->GetIdAllocator(namespace_id); + IdAllocatorInterface* id_allocator = group_->GetIdAllocator(namespace_id); for (GLsizei ii = 0; ii < n; ++ii) { id_allocator->FreeID(ids[ii]); } @@ -3389,7 +3391,7 @@ error::Error GLES2DecoderImpl::HandleDeleteSharedIdsCHROMIUM( void GLES2DecoderImpl::DoGenSharedIdsCHROMIUM( GLuint namespace_id, GLuint id_offset, GLsizei n, GLuint* ids) { - IdAllocator* id_allocator = group_->GetIdAllocator(namespace_id); + IdAllocatorInterface* id_allocator = group_->GetIdAllocator(namespace_id); if (id_offset == 0) { for (GLsizei ii = 0; ii < n; ++ii) { ids[ii] = id_allocator->AllocateID(); @@ -3426,7 +3428,7 @@ error::Error GLES2DecoderImpl::HandleGenSharedIdsCHROMIUM( void GLES2DecoderImpl::DoRegisterSharedIdsCHROMIUM( GLuint namespace_id, GLsizei n, const GLuint* ids) { - IdAllocator* id_allocator = group_->GetIdAllocator(namespace_id); + IdAllocatorInterface* id_allocator = group_->GetIdAllocator(namespace_id); for (GLsizei ii = 0; ii < n; ++ii) { if (!id_allocator->MarkAsUsed(ids[ii])) { for (GLsizei jj = 0; jj < ii; ++jj) { diff --git a/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc b/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc index 823cc1a..e145a79 100644 --- a/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc +++ b/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc @@ -2310,7 +2310,7 @@ TEST_F(GLES2DecoderTest, SharedIds) { GLuint* ids = GetSharedMemoryAs<GLuint*>(); gen_cmd.Init(kNamespaceId, 0, 2, kSharedMemoryId, kSharedMemoryOffset); EXPECT_EQ(error::kNoError, ExecuteCmd(gen_cmd)); - IdAllocator* id_allocator = GetIdAllocator(kNamespaceId); + IdAllocatorInterface* id_allocator = GetIdAllocator(kNamespaceId); ASSERT_TRUE(id_allocator != NULL); // This check is implementation dependant but it's kind of hard to check // otherwise. 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 3762952..b7379a4 100644 --- a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h +++ b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h @@ -128,7 +128,7 @@ class GLES2DecoderTestBase : public testing::Test { return reinterpret_cast<T>(ptr); } - IdAllocator* GetIdAllocator(GLuint namespace_id) { + IdAllocatorInterface* GetIdAllocator(GLuint namespace_id) { return group_->GetIdAllocator(namespace_id); } |