summaryrefslogtreecommitdiffstats
path: root/gpu
diff options
context:
space:
mode:
authorgman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-23 13:12:14 +0000
committergman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-23 13:12:14 +0000
commit1078f91209cf0ba2ecc315547a0bc562431c319a (patch)
tree1f9bcbf4ce4b15e8477810b32fae961cee0fc9e9 /gpu
parent2626dad41524638b99f64fa58012195341becb9e (diff)
downloadchromium_src-1078f91209cf0ba2ecc315547a0bc562431c319a.zip
chromium_src-1078f91209cf0ba2ecc315547a0bc562431c319a.tar.gz
chromium_src-1078f91209cf0ba2ecc315547a0bc562431c319a.tar.bz2
Add tracking of backbuffer memory to command buffer
TEST=none BUG=79762 R=apatrick@chromium.org Review URL: http://codereview.chromium.org/8958027 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@115715 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gpu')
-rw-r--r--gpu/command_buffer/common/gles2_cmd_utils.cc21
-rw-r--r--gpu/command_buffer/common/gles2_cmd_utils.h2
-rw-r--r--gpu/command_buffer/common/gles2_cmd_utils_unittest.cc17
-rw-r--r--gpu/command_buffer/service/gles2_cmd_decoder.cc82
4 files changed, 116 insertions, 6 deletions
diff --git a/gpu/command_buffer/common/gles2_cmd_utils.cc b/gpu/command_buffer/common/gles2_cmd_utils.cc
index b2be64b..23e0ac43 100644
--- a/gpu/command_buffer/common/gles2_cmd_utils.cc
+++ b/gpu/command_buffer/common/gles2_cmd_utils.cc
@@ -405,6 +405,27 @@ bool GLES2Util::ComputeImageDataSize(
return true;
}
+size_t GLES2Util::RenderbufferBytesPerPixel(int 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_RGB:
+ case GL_RGBA:
+ case GL_DEPTH24_STENCIL8_OES:
+ case GL_RGB8_OES:
+ case GL_RGBA8_OES:
+ case GL_DEPTH_COMPONENT24_OES:
+ return 4;
+ default:
+ return 0;
+ }
+}
+
uint32 GLES2Util::GetGLDataTypeSizeForUniforms(int type) {
switch (type) {
case GL_FLOAT:
diff --git a/gpu/command_buffer/common/gles2_cmd_utils.h b/gpu/command_buffer/common/gles2_cmd_utils.h
index 85a4ee3..7d62c6e 100644
--- a/gpu/command_buffer/common/gles2_cmd_utils.h
+++ b/gpu/command_buffer/common/gles2_cmd_utils.h
@@ -92,6 +92,8 @@ class GLES2Util {
int width, int height, int format, int type, int unpack_alignment,
uint32* size);
+ static size_t RenderbufferBytesPerPixel(int format);
+
static uint32 GetGLDataTypeSizeForUniforms(int type);
static size_t GetGLTypeSizeForTexturesAndBuffers(uint32 type);
diff --git a/gpu/command_buffer/common/gles2_cmd_utils_unittest.cc b/gpu/command_buffer/common/gles2_cmd_utils_unittest.cc
index 567e9a6..cf5a0ee 100644
--- a/gpu/command_buffer/common/gles2_cmd_utils_unittest.cc
+++ b/gpu/command_buffer/common/gles2_cmd_utils_unittest.cc
@@ -107,6 +107,23 @@ TEST_F(GLES2UtilTest, ComputeImageDataSizeUnpackAlignment) {
kWidth * 3, size);
}
+TEST_F(GLES2UtilTest, RenderbufferBytesPerPixel) {
+ EXPECT_EQ(1u, GLES2Util::RenderbufferBytesPerPixel(GL_STENCIL_INDEX8));
+ EXPECT_EQ(2u, GLES2Util::RenderbufferBytesPerPixel(GL_RGBA4));
+ EXPECT_EQ(2u, GLES2Util::RenderbufferBytesPerPixel(GL_RGB565));
+ EXPECT_EQ(2u, GLES2Util::RenderbufferBytesPerPixel(GL_RGB5_A1));
+ EXPECT_EQ(2u, GLES2Util::RenderbufferBytesPerPixel(GL_DEPTH_COMPONENT16));
+ EXPECT_EQ(4u, GLES2Util::RenderbufferBytesPerPixel(GL_RGB));
+ EXPECT_EQ(4u, GLES2Util::RenderbufferBytesPerPixel(GL_RGBA));
+ EXPECT_EQ(
+ 4u, GLES2Util::RenderbufferBytesPerPixel(GL_DEPTH24_STENCIL8_OES));
+ EXPECT_EQ(4u, GLES2Util::RenderbufferBytesPerPixel(GL_RGB8_OES));
+ EXPECT_EQ(4u, GLES2Util::RenderbufferBytesPerPixel(GL_RGBA8_OES));
+ EXPECT_EQ(
+ 4u, GLES2Util::RenderbufferBytesPerPixel(GL_DEPTH_COMPONENT24_OES));
+ EXPECT_EQ(0u, GLES2Util::RenderbufferBytesPerPixel(-1));
+}
+
} // 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 9b038f8..10c1c5d0 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder.cc
+++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc
@@ -15,6 +15,7 @@
#include "base/atomicops.h"
#include "base/at_exit.h"
#include "base/bind.h"
+#include "base/debug/trace_event.h"
#if defined(OS_MACOSX)
#include "base/mac/scoped_cftyperef.h"
#endif
@@ -25,7 +26,6 @@
#include "gpu/command_buffer/common/gles2_cmd_format.h"
#include "gpu/command_buffer/common/gles2_cmd_utils.h"
#include "gpu/command_buffer/common/id_allocator.h"
-#include "gpu/command_buffer/common/trace_event.h"
#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"
@@ -306,10 +306,15 @@ class Texture {
return size_;
}
+ size_t estimated_size() const {
+ return estimated_size_;
+ }
+
private:
GLES2DecoderImpl* decoder_;
GLuint id_;
gfx::Size size_;
+ size_t estimated_size_;
DISALLOW_COPY_AND_ASSIGN(Texture);
};
@@ -337,9 +342,14 @@ class RenderBuffer {
return id_;
}
+ size_t estimated_size() const {
+ return estimated_size_;
+ }
+
private:
GLES2DecoderImpl* decoder_;
GLuint id_;
+ size_t estimated_size_;
DISALLOW_COPY_AND_ASSIGN(RenderBuffer);
};
@@ -546,6 +556,7 @@ class GLES2DecoderImpl : public base::SupportsWeakPtr<GLES2DecoderImpl>,
private:
friend class ScopedGLErrorSuppressor;
friend class ScopedResolvedFrameBufferBinder;
+ friend class Texture;
friend class RenderBuffer;
friend class FrameBuffer;
@@ -1289,6 +1300,10 @@ class GLES2DecoderImpl : public base::SupportsWeakPtr<GLES2DecoderImpl>,
error::Error* error, GLuint* service_id, void** result,
GLenum* result_type);
+ // Computes the estimated memory used for the backbuffer and passes it to
+ // the tracing system.
+ void UpdateBackbufferMemoryAccounting();
+
// Returns true if the context was just lost due to e.g. GL_ARB_robustness.
bool WasContextLost();
@@ -1556,7 +1571,6 @@ ScopedResolvedFrameBufferBinder::ScopedResolvedFrameBufferBinder(
DCHECK(decoder_->offscreen_saved_color_format_);
decoder_->offscreen_resolved_color_texture_->AllocateStorage(
decoder_->offscreen_size_, decoder_->offscreen_saved_color_format_);
-
decoder_->offscreen_resolved_frame_buffer_->AttachRenderTexture(
decoder_->offscreen_resolved_color_texture_.get());
if (decoder_->offscreen_resolved_frame_buffer_->CheckStatus() !=
@@ -1597,7 +1611,8 @@ ScopedResolvedFrameBufferBinder::~ScopedResolvedFrameBufferBinder() {
Texture::Texture(GLES2DecoderImpl* decoder)
: decoder_(decoder),
- id_(0) {
+ id_(0),
+ estimated_size_(0) {
}
Texture::~Texture() {
@@ -1625,6 +1640,8 @@ void Texture::Create() {
// crash.
glTexImage2D(
GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+ estimated_size_ = 16u * 16u * 4u;
+ decoder_->UpdateBackbufferMemoryAccounting();
}
bool Texture::AllocateStorage(const gfx::Size& size, GLenum format) {
@@ -1644,7 +1661,15 @@ bool Texture::AllocateStorage(const gfx::Size& size, GLenum format) {
size_ = size;
- return glGetError() == GL_NO_ERROR;
+ bool success = glGetError() == GL_NO_ERROR;
+ if (success) {
+ uint32 image_size = 0;
+ GLES2Util::ComputeImageDataSize(
+ size.width(), size.height(), format, GL_UNSIGNED_BYTE, 4, &image_size);
+ estimated_size_ = image_size;
+ decoder_->UpdateBackbufferMemoryAccounting();
+ }
+ return success;
}
void Texture::Copy(const gfx::Size& size, GLenum format) {
@@ -1665,6 +1690,8 @@ void Texture::Destroy() {
ScopedGLErrorSuppressor suppressor(decoder_);
glDeleteTextures(1, &id_);
id_ = 0;
+ estimated_size_ = 0;
+ decoder_->UpdateBackbufferMemoryAccounting();
}
}
@@ -1674,7 +1701,8 @@ void Texture::Invalidate() {
RenderBuffer::RenderBuffer(GLES2DecoderImpl* decoder)
: decoder_(decoder),
- id_(0) {
+ id_(0),
+ estimated_size_(0) {
}
RenderBuffer::~RenderBuffer() {
@@ -1714,7 +1742,13 @@ bool RenderBuffer::AllocateStorage(const gfx::Size& size, GLenum format,
size.height());
}
}
- return glGetError() == GL_NO_ERROR;
+ bool success = glGetError() == GL_NO_ERROR;
+ if (success) {
+ estimated_size_ = size.width() * size.height() * samples *
+ GLES2Util::RenderbufferBytesPerPixel(format);
+ decoder_->UpdateBackbufferMemoryAccounting();
+ }
+ return success;
}
void RenderBuffer::Destroy() {
@@ -1722,6 +1756,8 @@ void RenderBuffer::Destroy() {
ScopedGLErrorSuppressor suppressor(decoder_);
glDeleteRenderbuffersEXT(1, &id_);
id_ = 0;
+ estimated_size_ = 0;
+ decoder_->UpdateBackbufferMemoryAccounting();
}
}
@@ -2763,6 +2799,36 @@ bool GLES2DecoderImpl::SetParent(GLES2Decoder* new_parent,
return true;
}
+void GLES2DecoderImpl::UpdateBackbufferMemoryAccounting() {
+ size_t total = 0;
+ if (offscreen_target_frame_buffer_.get()) {
+ if (offscreen_target_color_texture_.get()) {
+ total += offscreen_target_color_texture_->estimated_size();
+ }
+ if (offscreen_target_color_render_buffer_.get()) {
+ total += offscreen_target_color_render_buffer_->estimated_size();
+ }
+ if (offscreen_target_depth_render_buffer_.get()) {
+ total += offscreen_target_depth_render_buffer_->estimated_size();
+ }
+ if (offscreen_target_stencil_render_buffer_.get()) {
+ total += offscreen_target_stencil_render_buffer_->estimated_size();
+ }
+ if (offscreen_saved_color_texture_.get()) {
+ total += offscreen_saved_color_texture_->estimated_size();
+ }
+ if (offscreen_resolved_color_texture_.get()) {
+ total += offscreen_resolved_color_texture_->estimated_size();
+ }
+ } else {
+ gfx::Size size = surface_->GetSize();
+ total += size.width() * size.height() *
+ GLES2Util::RenderbufferBytesPerPixel(back_buffer_color_format_);
+ }
+ TRACE_COUNTER_ID1(
+ "GLES2DecoderImpl", "BackbufferMemory", this, total);
+}
+
bool GLES2DecoderImpl::ResizeOffscreenFrameBuffer(const gfx::Size& size) {
bool is_offscreen = !!offscreen_target_frame_buffer_.get();
if (!is_offscreen) {
@@ -2817,6 +2883,7 @@ bool GLES2DecoderImpl::ResizeOffscreenFrameBuffer(const gfx::Size& size) {
<< "to allocate storage for offscreen target stencil buffer.";
return false;
}
+ UpdateBackbufferMemoryAccounting();
// Attach the offscreen target buffers to the target frame buffer.
if (IsOffscreenBufferMultisampled()) {
@@ -2901,6 +2968,8 @@ error::Error GLES2DecoderImpl::HandleResizeCHROMIUM(
return error::kLostContext;
}
+ UpdateBackbufferMemoryAccounting();
+
return error::kNoError;
}
@@ -7290,6 +7359,7 @@ error::Error GLES2DecoderImpl::HandleSwapBuffers(
DCHECK(offscreen_saved_color_format_);
offscreen_saved_color_texture_->AllocateStorage(
offscreen_size_, offscreen_saved_color_format_);
+ UpdateBackbufferMemoryAccounting();
offscreen_saved_frame_buffer_->AttachRenderTexture(
offscreen_saved_color_texture_.get());