summaryrefslogtreecommitdiffstats
path: root/o3d/core/cross/buffer.cc
diff options
context:
space:
mode:
authorgman@google.com <gman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-09 22:59:37 +0000
committergman@google.com <gman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-09 22:59:37 +0000
commitc1bf07dd1da400c45c8b0af7aa3f24dfdbbfc615 (patch)
treed7df97e6184d7be23e1710be728332f1d0077f68 /o3d/core/cross/buffer.cc
parent013a4d61cc1d89a24690dfead3e6b22377d5993a (diff)
downloadchromium_src-c1bf07dd1da400c45c8b0af7aa3f24dfdbbfc615.zip
chromium_src-c1bf07dd1da400c45c8b0af7aa3f24dfdbbfc615.tar.gz
chromium_src-c1bf07dd1da400c45c8b0af7aa3f24dfdbbfc615.tar.bz2
Add ClientInfo
This allows an app to ask a few things from the client. 1) How many objects the client is tracking. This is useful for a quick way to check that you're freeing resources. While the developer could use client.objects.length or client.packs[ii].objects.length that wouldend up creating hundreds of thousands of NPObjects. 2) Check if the software renderer is being used 3) Check the approximate amount of memory used by textures. Again, they could compute this with client.getObjectsByClassName('o3d.Texture') but it seemed like it might be useful. I say approximate because I would have to dig down into the indivdual renderers to get better info since a NPOT card will use more memory but it didn't seem worth it. 4) check the approximate amount of memory used by hardware buffers. Review URL: http://codereview.chromium.org/155276 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20334 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d/core/cross/buffer.cc')
-rw-r--r--o3d/core/cross/buffer.cc30
1 files changed, 27 insertions, 3 deletions
diff --git a/o3d/core/cross/buffer.cc b/o3d/core/cross/buffer.cc
index cd1f8d6..7d4ced1 100644
--- a/o3d/core/cross/buffer.cc
+++ b/o3d/core/cross/buffer.cc
@@ -34,6 +34,7 @@
#include "core/cross/precompile.h"
#include "core/cross/buffer.h"
+#include "core/cross/client_info.h"
#include "core/cross/renderer.h"
#include "core/cross/features.h"
#include "core/cross/error.h"
@@ -108,6 +109,7 @@ Buffer::Buffer(ServiceLocator* service_locator)
}
Buffer::~Buffer() {
+ AdjustBufferMemoryInfo(false);
for (unsigned ii = 0; ii < fields_.size(); ++ii) {
if (!fields_[ii].IsNull()) {
fields_[ii]->ClearBuffer();
@@ -115,6 +117,18 @@ Buffer::~Buffer() {
}
}
+void Buffer::AdjustBufferMemoryInfo(bool add) {
+ // Only count VRAM/hardware buffers.
+ if (IsA(VertexBuffer::GetApparentClass()) ||
+ IsA(IndexBuffer::GetApparentClass())) {
+ size_t size_in_bytes = num_elements_ * stride_;
+ ClientInfoManager* client_info_manager =
+ service_locator()->GetService<ClientInfoManager>();
+ client_info_manager->AdjustBufferMemoryUsed(
+ static_cast<int>(size_in_bytes) * (add ? 1 : -1));
+ }
+}
+
bool Buffer::AllocateElements(unsigned num_elements) {
if (access_mode_ != NONE) {
O3D_ERROR(service_locator()) << "Attempt to allocate locked Buffer '"
@@ -152,25 +166,33 @@ bool Buffer::AllocateElements(unsigned num_elements) {
return false;
}
+ bool success = true;
if (!ConcreteAllocate(size_in_bytes)) {
- num_elements_ = 0;
- return false;
+ num_elements = 0;
+ size_in_bytes = 0;
+ success = false;
}
num_elements_ = num_elements;
- return true;
+
+ AdjustBufferMemoryInfo(true);
+
+ return success;
}
void Buffer::Free() {
if (num_elements_ > 0) {
ConcreteFree();
+ AdjustBufferMemoryInfo(false);
num_elements_ = 0;
}
}
bool Buffer::ReshuffleBuffer(unsigned int new_stride, Field* field_to_remove) {
if (new_stride == 0) {
+ AdjustBufferMemoryInfo(false);
ConcreteFree();
+ stride_ = 0;
return true;
}
if (num_elements_) {
@@ -202,6 +224,7 @@ bool Buffer::ReshuffleBuffer(unsigned int new_stride, Field* field_to_remove) {
// Copy the reorganized data into a new buffer.
{
ConcreteFree();
+ AdjustBufferMemoryInfo(false);
if (!ConcreteAllocate(size_in_bytes)) {
num_elements_ = 0;
O3D_ERROR(service_locator())
@@ -214,6 +237,7 @@ bool Buffer::ReshuffleBuffer(unsigned int new_stride, Field* field_to_remove) {
// is completed (see CreateField, RemoveField) for when we create a new
// buffer with no fields yet.
stride_ = new_stride;
+ AdjustBufferMemoryInfo(true);
BufferLockHelper helper(this);
void* destination = helper.GetData(Buffer::WRITE_ONLY);
if (!destination) {