summaryrefslogtreecommitdiffstats
path: root/gpu
diff options
context:
space:
mode:
authorgman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-23 01:06:45 +0000
committergman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-23 01:06:45 +0000
commitfad1feecaab4671dba200b07dce7000508188a4a (patch)
tree6d90428bf56c6522c016383fd4cdc30c26cafcd5 /gpu
parent8c38cc0eb3e89e20acd2eccbe0d6adc7ddbaf000 (diff)
downloadchromium_src-fad1feecaab4671dba200b07dce7000508188a4a.zip
chromium_src-fad1feecaab4671dba200b07dce7000508188a4a.tar.gz
chromium_src-fad1feecaab4671dba200b07dce7000508188a4a.tar.bz2
Add renderbuffer memory tracing
TEST=none BUG=79762 R=apatrick@chromium.org Review URL: http://codereview.chromium.org/9022015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@115657 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gpu')
-rw-r--r--gpu/command_buffer/service/renderbuffer_manager.cc43
-rw-r--r--gpu/command_buffer/service/renderbuffer_manager.h6
-rw-r--r--gpu/command_buffer/service/renderbuffer_manager_unittest.cc4
3 files changed, 50 insertions, 3 deletions
diff --git a/gpu/command_buffer/service/renderbuffer_manager.cc b/gpu/command_buffer/service/renderbuffer_manager.cc
index 5c9ca30..38b3c76 100644
--- a/gpu/command_buffer/service/renderbuffer_manager.cc
+++ b/gpu/command_buffer/service/renderbuffer_manager.cc
@@ -4,27 +4,59 @@
#include "gpu/command_buffer/service/renderbuffer_manager.h"
#include "base/logging.h"
+#include "base/debug/trace_event.h"
#include "gpu/command_buffer/common/gles2_cmd_utils.h"
#include "gpu/command_buffer/service/gles2_cmd_decoder.h"
namespace gpu {
namespace gles2 {
+static uint32 BytesPerPixel(GLenum format) {
+ switch (format) {
+ case GL_STENCIL_INDEX8:
+ return 1;
+ case GL_RGBA4:
+ case GL_RGB565:
+ case GL_RGB5_A1:
+ case GL_DEPTH_COMPONENT16:
+ return 2;
+ case GL_DEPTH24_STENCIL8:
+ case GL_RGB8_OES:
+ case GL_RGBA8_OES:
+ case GL_DEPTH_COMPONENT24:
+ return 4;
+ default:
+ return 0;
+ }
+}
+
RenderbufferManager::RenderbufferManager(
GLint max_renderbuffer_size, GLint max_samples)
: max_renderbuffer_size_(max_renderbuffer_size),
max_samples_(max_samples),
- num_uncleared_renderbuffers_(0) {
+ num_uncleared_renderbuffers_(0),
+ mem_represented_(0) {
+ UpdateMemRepresented();
}
RenderbufferManager::~RenderbufferManager() {
DCHECK(renderbuffer_infos_.empty());
}
+uint32 RenderbufferManager::RenderbufferInfo::EstimatedSize() {
+ return width_ * height_ * samples_ * BytesPerPixel(internal_format_);
+}
+
+void RenderbufferManager::UpdateMemRepresented() {
+ TRACE_COUNTER_ID1(
+ "RenderbufferManager", "RenderbufferMemory", this, mem_represented_);
+}
+
void RenderbufferManager::Destroy(bool have_context) {
while (!renderbuffer_infos_.empty()) {
+ RenderbufferInfo* info = renderbuffer_infos_.begin()->second;
+ mem_represented_ -= info->EstimatedSize();
if (have_context) {
- RenderbufferInfo* info = renderbuffer_infos_.begin()->second;
if (!info->IsDeleted()) {
GLuint service_id = info->service_id();
glDeleteRenderbuffersEXT(1, &service_id);
@@ -33,6 +65,8 @@ void RenderbufferManager::Destroy(bool have_context) {
}
renderbuffer_infos_.erase(renderbuffer_infos_.begin());
}
+ DCHECK_EQ(0u, mem_represented_);
+ UpdateMemRepresented();
}
void RenderbufferManager::SetInfo(
@@ -42,7 +76,10 @@ void RenderbufferManager::SetInfo(
if (!renderbuffer->cleared()) {
--num_uncleared_renderbuffers_;
}
+ mem_represented_ -= renderbuffer->EstimatedSize();
renderbuffer->SetInfo(samples, internalformat, width, height);
+ mem_represented_ += renderbuffer->EstimatedSize();
+ UpdateMemRepresented();
if (!renderbuffer->cleared()) {
++num_uncleared_renderbuffers_;
}
@@ -83,6 +120,8 @@ void RenderbufferManager::RemoveRenderbufferInfo(GLuint client_id) {
if (!info->cleared()) {
--num_uncleared_renderbuffers_;
}
+ mem_represented_ -= info->EstimatedSize();
+ UpdateMemRepresented();
info->MarkAsDeleted();
renderbuffer_infos_.erase(it);
}
diff --git a/gpu/command_buffer/service/renderbuffer_manager.h b/gpu/command_buffer/service/renderbuffer_manager.h
index 5cd7e50..a61d435 100644
--- a/gpu/command_buffer/service/renderbuffer_manager.h
+++ b/gpu/command_buffer/service/renderbuffer_manager.h
@@ -69,6 +69,8 @@ class RenderbufferManager {
return has_been_bound_ && !IsDeleted();
}
+ uint32 EstimatedSize();
+
private:
friend class RenderbufferManager;
friend class base::RefCounted<RenderbufferInfo>;
@@ -149,11 +151,15 @@ class RenderbufferManager {
bool GetClientId(GLuint service_id, GLuint* client_id) const;
private:
+ void UpdateMemRepresented();
+
GLint max_renderbuffer_size_;
GLint max_samples_;
int num_uncleared_renderbuffers_;
+ uint32 mem_represented_;
+
// Info for each renderbuffer in the system.
typedef base::hash_map<GLuint, RenderbufferInfo::Ref> RenderbufferInfoMap;
RenderbufferInfoMap renderbuffer_infos_;
diff --git a/gpu/command_buffer/service/renderbuffer_manager_unittest.cc b/gpu/command_buffer/service/renderbuffer_manager_unittest.cc
index 63719d7..0384785 100644
--- a/gpu/command_buffer/service/renderbuffer_manager_unittest.cc
+++ b/gpu/command_buffer/service/renderbuffer_manager_unittest.cc
@@ -103,10 +103,11 @@ TEST_F(RenderbufferManagerTest, RenderbufferInfo) {
EXPECT_EQ(0, info1->width());
EXPECT_EQ(0, info1->height());
EXPECT_TRUE(info1->cleared());
+ EXPECT_EQ(0u, info1->EstimatedSize());
// Check if we set the info it gets marked as not cleared.
const GLsizei kSamples = 4;
- const GLenum kFormat = GL_RGBA;
+ const GLenum kFormat = GL_RGBA4;
const GLsizei kWidth = 128;
const GLsizei kHeight = 64;
manager_.SetInfo(info1, kSamples, kFormat, kWidth, kHeight);
@@ -117,6 +118,7 @@ TEST_F(RenderbufferManagerTest, RenderbufferInfo) {
EXPECT_FALSE(info1->cleared());
EXPECT_FALSE(info1->IsDeleted());
EXPECT_TRUE(manager_.HaveUnclearedRenderbuffers());
+ EXPECT_EQ(kWidth * kHeight * 4u * 2u, info1->EstimatedSize());
manager_.SetCleared(info1);
EXPECT_TRUE(info1->cleared());