diff options
author | gman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-25 02:57:58 +0000 |
---|---|---|
committer | gman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-25 02:57:58 +0000 |
commit | a25fa87a6cf2d10414454d8b8ad75ffeb13fb2cd (patch) | |
tree | ec191648b64ae8d31baee4f5f437535d3e0e0615 /gpu | |
parent | 319cedc65c0a9ffe5c3515b066b65f07d1fd7258 (diff) | |
download | chromium_src-a25fa87a6cf2d10414454d8b8ad75ffeb13fb2cd.zip chromium_src-a25fa87a6cf2d10414454d8b8ad75ffeb13fb2cd.tar.gz chromium_src-a25fa87a6cf2d10414454d8b8ad75ffeb13fb2cd.tar.bz2 |
Adds renderbuffer and framebuffer tracking so we can
clear the buffers.
Note: I did not actually write the clearing code
or the binding code. Will do in another CL after
Al checks in his code.
TEST=unit tests
BUG=none
Review URL: http://codereview.chromium.org/1243002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42577 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gpu')
-rw-r--r-- | gpu/command_buffer/service/context_group.cc | 4 | ||||
-rw-r--r-- | gpu/command_buffer/service/context_group.h | 14 | ||||
-rw-r--r-- | gpu/command_buffer/service/context_group_unittest.cc | 2 | ||||
-rw-r--r-- | gpu/command_buffer/service/framebuffer_manager.cc | 51 | ||||
-rw-r--r-- | gpu/command_buffer/service/framebuffer_manager.h | 90 | ||||
-rw-r--r-- | gpu/command_buffer/service/framebuffer_manager_unittest.cc | 52 | ||||
-rw-r--r-- | gpu/command_buffer/service/gles2_cmd_decoder.cc | 78 | ||||
-rw-r--r-- | gpu/command_buffer/service/renderbuffer_manager.cc | 39 | ||||
-rw-r--r-- | gpu/command_buffer/service/renderbuffer_manager.h | 90 | ||||
-rw-r--r-- | gpu/command_buffer/service/renderbuffer_manager_unittest.cc | 53 | ||||
-rw-r--r-- | gpu/command_buffer/service/resource_test.cc | 99 | ||||
-rw-r--r-- | gpu/gpu.gyp | 6 |
12 files changed, 475 insertions, 103 deletions
diff --git a/gpu/command_buffer/service/context_group.cc b/gpu/command_buffer/service/context_group.cc index 5bc0ae41..d20ee4c9 100644 --- a/gpu/command_buffer/service/context_group.cc +++ b/gpu/command_buffer/service/context_group.cc @@ -4,8 +4,10 @@ #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" #include "gpu/command_buffer/service/texture_manager.h" @@ -28,6 +30,8 @@ bool ContextGroup::Initialize() { id_manager_.reset(new IdManager()); buffer_manager_.reset(new BufferManager()); + framebuffer_manager_.reset(new FramebufferManager()); + renderbuffer_manager_.reset(new RenderbufferManager()); shader_manager_.reset(new ShaderManager()); program_manager_.reset(new ProgramManager()); diff --git a/gpu/command_buffer/service/context_group.h b/gpu/command_buffer/service/context_group.h index 362be16..fd6e1c3 100644 --- a/gpu/command_buffer/service/context_group.h +++ b/gpu/command_buffer/service/context_group.h @@ -14,6 +14,8 @@ namespace gles2 { class GLES2Decoder; class BufferManager; +class FramebufferManager; +class RenderbufferManager; class IdManager; class ProgramManager; class ShaderManager; @@ -46,6 +48,14 @@ class ContextGroup { return buffer_manager_.get(); } + FramebufferManager* framebuffer_manager() const { + return framebuffer_manager_.get(); + } + + RenderbufferManager* renderbuffer_manager() const { + return renderbuffer_manager_.get(); + } + TextureManager* texture_manager() const { return texture_manager_.get(); } @@ -71,6 +81,10 @@ class ContextGroup { scoped_ptr<BufferManager> buffer_manager_; + scoped_ptr<FramebufferManager> framebuffer_manager_; + + scoped_ptr<RenderbufferManager> renderbuffer_manager_; + scoped_ptr<TextureManager> texture_manager_; scoped_ptr<ProgramManager> program_manager_; diff --git a/gpu/command_buffer/service/context_group_unittest.cc b/gpu/command_buffer/service/context_group_unittest.cc index a61077b..ef6c5ed 100644 --- a/gpu/command_buffer/service/context_group_unittest.cc +++ b/gpu/command_buffer/service/context_group_unittest.cc @@ -29,6 +29,8 @@ TEST_F(ContextGroupTest, Basic) { 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); EXPECT_TRUE(group_.texture_manager() == NULL); EXPECT_TRUE(group_.program_manager() == NULL); EXPECT_TRUE(group_.shader_manager() == NULL); diff --git a/gpu/command_buffer/service/framebuffer_manager.cc b/gpu/command_buffer/service/framebuffer_manager.cc new file mode 100644 index 0000000..5b55e76 --- /dev/null +++ b/gpu/command_buffer/service/framebuffer_manager.cc @@ -0,0 +1,51 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "gpu/command_buffer/service/framebuffer_manager.h" +#include "base/logging.h" +#include "gpu/command_buffer/common/gles2_cmd_utils.h" + +namespace gpu { +namespace gles2 { + +void FramebufferManager::CreateFramebufferInfo(GLuint framebuffer_id) { + std::pair<FramebufferInfoMap::iterator, bool> result = + framebuffer_infos_.insert( + std::make_pair( + framebuffer_id, + FramebufferInfo::Ref(new FramebufferInfo(framebuffer_id)))); + DCHECK(result.second); +} + +FramebufferManager::FramebufferInfo* FramebufferManager::GetFramebufferInfo( + GLuint framebuffer_id) { + FramebufferInfoMap::iterator it = framebuffer_infos_.find(framebuffer_id); + return it != framebuffer_infos_.end() ? it->second : NULL; +} + +void FramebufferManager::RemoveFramebufferInfo(GLuint framebuffer_id) { + FramebufferInfoMap::iterator it = framebuffer_infos_.find(framebuffer_id); + if (it != framebuffer_infos_.end()) { + it->second->MarkAsDeleted(); + framebuffer_infos_.erase(framebuffer_id); + } +} + +void FramebufferManager::FramebufferInfo::AttachRenderbuffer( + GLenum attachment, RenderbufferManager::RenderbufferInfo* renderbuffer) { + DCHECK(attachment == GL_COLOR_ATTACHMENT0 || + attachment == GL_DEPTH_ATTACHMENT || + attachment == GL_STENCIL_ATTACHMENT); + if (renderbuffer) { + renderbuffers_[attachment] = + RenderbufferManager::RenderbufferInfo::Ref(renderbuffer); + } else { + renderbuffers_.erase(attachment); + } +} + +} // namespace gles2 +} // namespace gpu + + diff --git a/gpu/command_buffer/service/framebuffer_manager.h b/gpu/command_buffer/service/framebuffer_manager.h new file mode 100644 index 0000000..f923f9f --- /dev/null +++ b/gpu/command_buffer/service/framebuffer_manager.h @@ -0,0 +1,90 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef GPU_COMMAND_BUFFER_SERVICE_FRAMEBUFFER_MANAGER_H_ +#define GPU_COMMAND_BUFFER_SERVICE_FRAMEBUFFER_MANAGER_H_ + +#include <map> +#include "base/basictypes.h" +#include "base/logging.h" +#include "base/ref_counted.h" +#include "base/scoped_ptr.h" +#include "gpu/command_buffer/service/gl_utils.h" +#include "gpu/command_buffer/service/renderbuffer_manager.h" + +namespace gpu { +namespace gles2 { + +// This class keeps track of the frambebuffers and their attached renderbuffers +// so we can correctly clear them. +class FramebufferManager { + public: + // Info about Framebuffers currently in the system. + class FramebufferInfo : public base::RefCounted<FramebufferInfo> { + public: + typedef scoped_refptr<FramebufferInfo> Ref; + + explicit FramebufferInfo(GLuint framebuffer_id) + : framebuffer_id_(framebuffer_id) { + } + + GLuint framebuffer_id() const { + return framebuffer_id_; + } + + // Attaches a renderbuffer to a particlar attachment. + // Pass null to detach. + void AttachRenderbuffer( + GLenum attachment, RenderbufferManager::RenderbufferInfo* renderbuffer); + + bool IsDeleted() { + return framebuffer_id_ == 0; + } + + private: + friend class FramebufferManager; + friend class base::RefCounted<FramebufferInfo>; + + ~FramebufferInfo() { } + + void MarkAsDeleted() { + framebuffer_id_ = 0; + renderbuffers_.clear(); + } + + // Service side framebuffer id. + GLuint framebuffer_id_; + + // A map of attachments to renderbuffers. + typedef std::map<GLenum, RenderbufferManager::RenderbufferInfo::Ref> + AttachmentToRenderbufferMap; + AttachmentToRenderbufferMap renderbuffers_; + }; + + FramebufferManager() { } + + // Creates a FramebufferInfo for the given framebuffer. + void CreateFramebufferInfo(GLuint framebuffer_id); + + // Gets the framebuffer info for the given framebuffer. + FramebufferInfo* GetFramebufferInfo(GLuint framebuffer_id); + + // Removes a framebuffer info for the given framebuffer. + void RemoveFramebufferInfo(GLuint framebuffer_id); + + private: + // Info for each framebuffer in the system. + // TODO(gman): Choose a faster container. + typedef std::map<GLuint, FramebufferInfo::Ref> FramebufferInfoMap; + FramebufferInfoMap framebuffer_infos_; + + DISALLOW_COPY_AND_ASSIGN(FramebufferManager); +}; + +} // namespace gles2 +} // namespace gpu + +#endif // GPU_COMMAND_BUFFER_SERVICE_FRAMEBUFFER_MANAGER_H_ + + diff --git a/gpu/command_buffer/service/framebuffer_manager_unittest.cc b/gpu/command_buffer/service/framebuffer_manager_unittest.cc new file mode 100644 index 0000000..29cc31c --- /dev/null +++ b/gpu/command_buffer/service/framebuffer_manager_unittest.cc @@ -0,0 +1,52 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "gpu/command_buffer/service/framebuffer_manager.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace gpu { +namespace gles2 { + +class FramebufferManagerTest : public testing::Test { + public: + FramebufferManagerTest() { + } + + protected: + virtual void SetUp() { + } + + virtual void TearDown() { + } + + FramebufferManager manager_; +}; + +TEST_F(FramebufferManagerTest, Basic) { + const GLuint kFramebuffer1Id = 1; + const GLsizeiptr kFramebuffer1Size = 123; + const GLuint kFramebuffer2Id = 2; + // Check we can create framebuffer. + manager_.CreateFramebufferInfo(kFramebuffer1Id); + // Check framebuffer got created. + FramebufferManager::FramebufferInfo* info1 = + manager_.GetFramebufferInfo(kFramebuffer1Id); + ASSERT_TRUE(info1 != NULL); + EXPECT_FALSE(info1->IsDeleted()); + EXPECT_EQ(kFramebuffer1Id, info1->framebuffer_id()); + // Check we get nothing for a non-existent framebuffer. + EXPECT_TRUE(manager_.GetFramebufferInfo(kFramebuffer2Id) == NULL); + // Check trying to a remove non-existent framebuffers does not crash. + manager_.RemoveFramebufferInfo(kFramebuffer2Id); + // Check we can't get the framebuffer after we remove it. + manager_.RemoveFramebufferInfo(kFramebuffer1Id); + EXPECT_TRUE(manager_.GetFramebufferInfo(kFramebuffer1Id) == NULL); +} + +// TODO(gman): Write test for AttachRenderbuffer + +} // namespace gles2 +} // namespace gpu + + diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.cc b/gpu/command_buffer/service/gles2_cmd_decoder.cc index 4c99bff..512a819 100644 --- a/gpu/command_buffer/service/gles2_cmd_decoder.cc +++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc @@ -20,10 +20,12 @@ #include "gpu/command_buffer/service/buffer_manager.h" #include "gpu/command_buffer/service/cmd_buffer_engine.h" #include "gpu/command_buffer/service/context_group.h" +#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" #include "gpu/command_buffer/service/texture_manager.h" #if defined(UNIT_TEST) @@ -260,6 +262,14 @@ class GLES2DecoderImpl : public GLES2Decoder { 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); // TODO(gman): Cache these pointers? IdManager* id_manager() { @@ -270,6 +280,14 @@ class GLES2DecoderImpl : public GLES2Decoder { return group_->buffer_manager(); } + RenderbufferManager* renderbuffer_manager() { + return group_->renderbuffer_manager(); + } + + FramebufferManager* framebuffer_manager() { + return group_->framebuffer_manager(); + } + ProgramManager* program_manager() { return group_->program_manager(); } @@ -416,6 +434,42 @@ class GLES2DecoderImpl : public GLES2Decoder { // with deleted buffers. void RemoveBufferInfo(GLuint buffer_id); + // Creates a framebuffer info for the given framebuffer. + void CreateFramebufferInfo(GLuint framebuffer) { + return framebuffer_manager()->CreateFramebufferInfo(framebuffer); + } + + // Gets the framebuffer info for the given framebuffer. + FramebufferManager::FramebufferInfo* GetFramebufferInfo( + GLuint framebuffer) { + FramebufferManager::FramebufferInfo* info = + framebuffer_manager()->GetFramebufferInfo(framebuffer); + return (info && !info->IsDeleted()) ? info : NULL; + } + + // Removes the framebuffer info for the given framebuffer. + void RemoveFramebufferInfo(GLuint framebuffer_id) { + framebuffer_manager()->RemoveFramebufferInfo(framebuffer_id); + } + + // Creates a renderbuffer info for the given renderbuffer. + void CreateRenderbufferInfo(GLuint renderbuffer) { + return renderbuffer_manager()->CreateRenderbufferInfo(renderbuffer); + } + + // Gets the renderbuffer info for the given renderbuffer. + RenderbufferManager::RenderbufferInfo* GetRenderbufferInfo( + GLuint renderbuffer) { + RenderbufferManager::RenderbufferInfo* info = + renderbuffer_manager()->GetRenderbufferInfo(renderbuffer); + return (info && !info->IsDeleted()) ? info : NULL; + } + + // Removes the renderbuffer info for the given renderbuffer. + void RemoveRenderbufferInfo(GLuint renderbuffer_id) { + renderbuffer_manager()->RemoveRenderbufferInfo(renderbuffer_id); + } + error::Error GetAttribLocationHelper( GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset, const std::string& name_str); @@ -936,13 +990,21 @@ void GLGenBuffersHelper( } void GLGenFramebuffersHelper( - GLES2DecoderImpl*, GLsizei n, GLuint* ids) { + GLES2DecoderImpl* decoder, GLsizei n, GLuint* ids) { glGenFramebuffersEXT(n, ids); + // TODO(gman): handle error + for (GLsizei ii = 0; ii < n; ++ii) { + decoder->CreateFramebufferInfo(ids[ii]); + } } void GLGenRenderbuffersHelper( - GLES2DecoderImpl*, GLsizei n, GLuint* ids) { + GLES2DecoderImpl* decoder, GLsizei n, GLuint* ids) { glGenRenderbuffersEXT(n, ids); + // TODO(gman): handle error + for (GLsizei ii = 0; ii < n; ++ii) { + decoder->CreateRenderbufferInfo(ids[ii]); + } } void GLGenTexturesHelper( @@ -964,13 +1026,21 @@ void GLDeleteBuffersHelper( } void GLDeleteFramebuffersHelper( - GLES2DecoderImpl*, GLsizei n, GLuint* ids) { + GLES2DecoderImpl* decoder, GLsizei n, GLuint* ids) { glDeleteFramebuffersEXT(n, ids); + // TODO(gman): handle error + for (GLsizei ii = 0; ii < n; ++ii) { + decoder->RemoveFramebufferInfo(ids[ii]); + } } void GLDeleteRenderbuffersHelper( - GLES2DecoderImpl*, GLsizei n, GLuint* ids) { + GLES2DecoderImpl* decoder, GLsizei n, GLuint* ids) { glDeleteRenderbuffersEXT(n, ids); + // TODO(gman): handle error + for (GLsizei ii = 0; ii < n; ++ii) { + decoder->RemoveRenderbufferInfo(ids[ii]); + } } void GLDeleteTexturesHelper( diff --git a/gpu/command_buffer/service/renderbuffer_manager.cc b/gpu/command_buffer/service/renderbuffer_manager.cc new file mode 100644 index 0000000..0b5441d --- /dev/null +++ b/gpu/command_buffer/service/renderbuffer_manager.cc @@ -0,0 +1,39 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "gpu/command_buffer/service/renderbuffer_manager.h" +#include "base/logging.h" +#include "gpu/command_buffer/common/gles2_cmd_utils.h" +#include "gpu/command_buffer/service/gles2_cmd_decoder.h" + +namespace gpu { +namespace gles2 { + +void RenderbufferManager::CreateRenderbufferInfo(GLuint renderbuffer_id) { + std::pair<RenderbufferInfoMap::iterator, bool> result = + renderbuffer_infos_.insert( + std::make_pair( + renderbuffer_id, + RenderbufferInfo::Ref(new RenderbufferInfo(renderbuffer_id)))); + DCHECK(result.second); +} + +RenderbufferManager::RenderbufferInfo* RenderbufferManager::GetRenderbufferInfo( + GLuint renderbuffer_id) { + RenderbufferInfoMap::iterator it = renderbuffer_infos_.find(renderbuffer_id); + return it != renderbuffer_infos_.end() ? it->second : NULL; +} + +void RenderbufferManager::RemoveRenderbufferInfo(GLuint renderbuffer_id) { + RenderbufferInfoMap::iterator it = renderbuffer_infos_.find(renderbuffer_id); + if (it != renderbuffer_infos_.end()) { + it->second->MarkAsDeleted(); + renderbuffer_infos_.erase(renderbuffer_id); + } +} + +} // namespace gles2 +} // namespace gpu + + diff --git a/gpu/command_buffer/service/renderbuffer_manager.h b/gpu/command_buffer/service/renderbuffer_manager.h new file mode 100644 index 0000000..47c5282 --- /dev/null +++ b/gpu/command_buffer/service/renderbuffer_manager.h @@ -0,0 +1,90 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef GPU_COMMAND_BUFFER_SERVICE_RENDERBUFFER_MANAGER_H_ +#define GPU_COMMAND_BUFFER_SERVICE_RENDERBUFFER_MANAGER_H_ + +#include <map> +#include "base/basictypes.h" +#include "base/logging.h" +#include "base/ref_counted.h" +#include "base/scoped_ptr.h" +#include "gpu/command_buffer/service/gl_utils.h" + +namespace gpu { +namespace gles2 { + +// This class keeps track of the renderbuffers and whether or not they have +// been cleared. +class RenderbufferManager { + public: + // Info about Renderbuffers currently in the system. + class RenderbufferInfo : public base::RefCounted<RenderbufferInfo> { + public: + typedef scoped_refptr<RenderbufferInfo> Ref; + + explicit RenderbufferInfo(GLuint renderbuffer_id) + : renderbuffer_id_(renderbuffer_id), + cleared_(false) { + } + + GLuint renderbuffer_id() const { + return renderbuffer_id_; + } + + bool cleared() const { + return cleared_; + } + + void set_cleared() { + cleared_ = true; + } + + bool IsDeleted() { + return renderbuffer_id_ == 0; + } + + private: + friend class RenderbufferManager; + friend class base::RefCounted<RenderbufferInfo>; + + ~RenderbufferInfo() { } + + void MarkAsDeleted() { + renderbuffer_id_ = 0; + } + + // Service side renderbuffer id. + GLuint renderbuffer_id_; + + // Whether this renderbuffer has been cleared + bool cleared_; + }; + + RenderbufferManager() { } + + // Creates a RenderbufferInfo for the given renderbuffer. + void CreateRenderbufferInfo(GLuint renderbuffer_id); + + // Gets the renderbuffer info for the given renderbuffer. + RenderbufferInfo* GetRenderbufferInfo(GLuint renderbuffer_id); + + // Removes a renderbuffer info for the given renderbuffer. + void RemoveRenderbufferInfo(GLuint renderbuffer_id); + + private: + // Info for each renderbuffer in the system. + // TODO(gman): Choose a faster container. + typedef std::map<GLuint, RenderbufferInfo::Ref> RenderbufferInfoMap; + RenderbufferInfoMap renderbuffer_infos_; + + DISALLOW_COPY_AND_ASSIGN(RenderbufferManager); +}; + +} // namespace gles2 +} // namespace gpu + +#endif // GPU_COMMAND_BUFFER_SERVICE_RENDERBUFFER_MANAGER_H_ + + diff --git a/gpu/command_buffer/service/renderbuffer_manager_unittest.cc b/gpu/command_buffer/service/renderbuffer_manager_unittest.cc new file mode 100644 index 0000000..3582924 --- /dev/null +++ b/gpu/command_buffer/service/renderbuffer_manager_unittest.cc @@ -0,0 +1,53 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "gpu/command_buffer/service/renderbuffer_manager.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace gpu { +namespace gles2 { + +class RenderbufferManagerTest : public testing::Test { + public: + RenderbufferManagerTest() { + } + + protected: + virtual void SetUp() { + } + + virtual void TearDown() { + } + + RenderbufferManager manager_; +}; + +TEST_F(RenderbufferManagerTest, Basic) { + const GLuint kRenderbuffer1Id = 1; + const GLsizeiptr kRenderbuffer1Size = 123; + const GLuint kRenderbuffer2Id = 2; + // Check we can create renderbuffer. + manager_.CreateRenderbufferInfo(kRenderbuffer1Id); + // Check renderbuffer got created. + RenderbufferManager::RenderbufferInfo* info1 = + manager_.GetRenderbufferInfo(kRenderbuffer1Id); + 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()); + // Check we get nothing for a non-existent renderbuffer. + EXPECT_TRUE(manager_.GetRenderbufferInfo(kRenderbuffer2Id) == NULL); + // Check trying to a remove non-existent renderbuffers does not crash. + manager_.RemoveRenderbufferInfo(kRenderbuffer2Id); + // Check we can't get the renderbuffer after we remove it. + manager_.RemoveRenderbufferInfo(kRenderbuffer1Id); + EXPECT_TRUE(manager_.GetRenderbufferInfo(kRenderbuffer1Id) == NULL); +} + +} // namespace gles2 +} // namespace gpu + + diff --git a/gpu/command_buffer/service/resource_test.cc b/gpu/command_buffer/service/resource_test.cc deleted file mode 100644 index e86f679..0000000 --- a/gpu/command_buffer/service/resource_test.cc +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Tests for the ResourceMap. - -#include "gpu/command_buffer/service/precompile.h" -#include "gpu/command_buffer/service/resource.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace gpu { - -// Mock resource implementation that checks for leaks. -class ResourceMock : public Resource { - public: - ResourceMock() : Resource() { - ++instance_count_; - } - virtual ~ResourceMock() { - --instance_count_; - } - - // Returns the instance count. The instance count is increased in the - // constructor and decreased in the destructor, to track leaks. The reason is - // that we can't mock the destructor, though we want to make sure the mock is - // destroyed. - static int instance_count() { return instance_count_; } - private: - static int instance_count_; - DISALLOW_COPY_AND_ASSIGN(ResourceMock); -}; -int ResourceMock::instance_count_ = 0; - -// Test fixture for ResourceMap test. Creates a ResourceMap using a mock -// Resource, and checks for ResourceMock leaks. -class ResourceMapTest : public testing::Test { - protected: - typedef ResourceMap<ResourceMock> Map; - virtual void SetUp() { - instance_count_ = ResourceMock::instance_count(); - map_.reset(new Map()); - } - virtual void TearDown() { - CheckLeaks(); - } - - // Makes sure we didn't leak any ResourceMock object. - void CheckLeaks() { - EXPECT_EQ(instance_count_, ResourceMock::instance_count()); - } - - Map *map() const { return map_.get(); } - private: - int instance_count_; - scoped_ptr<Map> map_; -}; - -TEST_F(ResourceMapTest, TestMap) { - // check that initial mapping is empty. - EXPECT_EQ(NULL, map()->Get(0)); - EXPECT_EQ(NULL, map()->Get(1)); - EXPECT_EQ(NULL, map()->Get(392)); - - // create a new resource, assign it to an ID. - ResourceMock *resource = new ResourceMock(); - map()->Assign(123, resource); - EXPECT_EQ(resource, map()->Get(123)); - - // Destroy the resource, making sure the object is deleted. - EXPECT_EQ(true, map()->Destroy(123)); - EXPECT_EQ(false, map()->Destroy(123)); // destroying again should fail. - resource = NULL; - CheckLeaks(); - - // create a new resource, add it to the map, and make sure it gets deleted - // when we assign a new resource to that ID. - resource = new ResourceMock(); - map()->Assign(1, resource); - resource = new ResourceMock(); - map()->Assign(1, resource); - EXPECT_EQ(resource, map()->Get(1)); // check that we have the new resource. - EXPECT_EQ(true, map()->Destroy(1)); - CheckLeaks(); - - // Adds 3 resources, then call DestroyAllResources(). - resource = new ResourceMock(); - map()->Assign(1, resource); - resource = new ResourceMock(); - map()->Assign(2, resource); - resource = new ResourceMock(); - map()->Assign(3, resource); - map()->DestroyAllResources(); - EXPECT_EQ(NULL, map()->Get(1)); - EXPECT_EQ(NULL, map()->Get(2)); - EXPECT_EQ(NULL, map()->Get(3)); - CheckLeaks(); -} - -} // namespace gpu diff --git a/gpu/gpu.gyp b/gpu/gpu.gyp index 22cb17c..4e3106f 100644 --- a/gpu/gpu.gyp +++ b/gpu/gpu.gyp @@ -11,6 +11,8 @@ 'gpu_source_files': [ 'command_buffer/service/buffer_manager.h', 'command_buffer/service/buffer_manager.cc', + 'command_buffer/service/framebuffer_manager.h', + 'command_buffer/service/framebuffer_manager.cc', 'command_buffer/service/context_group.h', 'command_buffer/service/context_group.cc', 'command_buffer/service/gles2_cmd_decoder.h', @@ -25,6 +27,8 @@ 'command_buffer/service/id_manager.cc', 'command_buffer/service/program_manager.h', 'command_buffer/service/program_manager.cc', + 'command_buffer/service/renderbuffer_manager.h', + 'command_buffer/service/renderbuffer_manager.cc', 'command_buffer/service/shader_manager.h', 'command_buffer/service/shader_manager.cc', 'command_buffer/service/texture_manager.h', @@ -322,6 +326,7 @@ 'command_buffer/service/cmd_parser_test.cc', 'command_buffer/service/cmd_parser_test.cc', 'command_buffer/service/common_decoder_unittest.cc', + 'command_buffer/service/framebuffer_manager_unittest.cc', 'command_buffer/service/gpu_processor_unittest.cc', 'command_buffer/service/gl_interface.h', 'command_buffer/service/gl_interface.cc', @@ -336,6 +341,7 @@ 'command_buffer/service/gles2_cmd_decoder_unittest_2_autogen.h', 'command_buffer/service/id_manager_unittest.cc', 'command_buffer/service/program_manager_unittest.cc', + 'command_buffer/service/renderbuffer_manager_unittest.cc', 'command_buffer/service/shader_manager_unittest.cc', 'command_buffer/service/texture_manager_unittest.cc', ], |