summaryrefslogtreecommitdiffstats
path: root/o3d/core
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
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')
-rw-r--r--o3d/core/build.scons1
-rw-r--r--o3d/core/cross/buffer.cc30
-rw-r--r--o3d/core/cross/buffer.h2
-rw-r--r--o3d/core/cross/client.cc16
-rw-r--r--o3d/core/cross/client_info.cc58
-rw-r--r--o3d/core/cross/client_info.h118
-rw-r--r--o3d/core/cross/client_info_test.cc152
-rw-r--r--o3d/core/cross/object_manager.h7
-rw-r--r--o3d/core/cross/service_implementation.h4
-rw-r--r--o3d/core/cross/texture.cc31
-rw-r--r--o3d/core/win/d3d9/renderer_d3d9.cc11
11 files changed, 415 insertions, 15 deletions
diff --git a/o3d/core/build.scons b/o3d/core/build.scons
index 30ce2c4..088ebce 100644
--- a/o3d/core/build.scons
+++ b/o3d/core/build.scons
@@ -42,6 +42,7 @@ cross_inputs = [
'cross/class_manager.cc',
'cross/clear_buffer.cc',
'cross/client.cc',
+ 'cross/client_info.cc',
'cross/core_metrics.cc',
'cross/counter.cc',
'cross/counter_manager.cc',
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) {
diff --git a/o3d/core/cross/buffer.h b/o3d/core/cross/buffer.h
index fc9c1bc..c85b9da 100644
--- a/o3d/core/cross/buffer.h
+++ b/o3d/core/cross/buffer.h
@@ -212,6 +212,8 @@ class Buffer : public NamedObject {
// field_to_remove: address of field. If NULL no field is removed.
bool ReshuffleBuffer(unsigned int new_stride, Field* field_to_remove);
+ void AdjustBufferMemoryInfo(bool add);
+
Features* features_;
// Fields.
diff --git a/o3d/core/cross/client.cc b/o3d/core/cross/client.cc
index 54aca22..e494f5d 100644
--- a/o3d/core/cross/client.cc
+++ b/o3d/core/cross/client.cc
@@ -69,17 +69,17 @@ namespace o3d {
// Client constructor. Creates the default root node for the scenegraph
Client::Client(ServiceLocator* service_locator)
: service_locator_(service_locator),
- object_manager_(service_locator_),
+ object_manager_(service_locator),
profiler_(service_locator),
- error_status_(service_locator_),
- draw_list_manager_(service_locator_),
- counter_manager_(service_locator_),
- transformation_context_(service_locator_),
- semantic_manager_(service_locator_),
+ error_status_(service_locator),
+ draw_list_manager_(service_locator),
+ counter_manager_(service_locator),
+ transformation_context_(service_locator),
+ semantic_manager_(service_locator),
rendering_(false),
render_tree_called_(false),
- renderer_(service_locator_),
- evaluation_counter_(service_locator_),
+ renderer_(service_locator),
+ evaluation_counter_(service_locator),
event_manager_(),
root_(NULL),
render_mode_(RENDERMODE_CONTINUOUS),
diff --git a/o3d/core/cross/client_info.cc b/o3d/core/cross/client_info.cc
new file mode 100644
index 0000000..735e2e6
--- /dev/null
+++ b/o3d/core/cross/client_info.cc
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2009, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+// This file contains the ClientInfoManager implementation
+
+#include "core/cross/precompile.h"
+#include "core/cross/client_info.h"
+#include <vector>
+#include "base/string_util.h"
+#include "core/cross/types.h"
+#include "core/cross/service_dependency.h"
+#include "core/cross/object_manager.h"
+
+namespace o3d {
+
+const InterfaceId ClientInfoManager::kInterfaceId =
+ InterfaceTraits<ClientInfoManager>::kInterfaceId;
+
+ClientInfoManager::ClientInfoManager(ServiceLocator* service_locator)
+ : service_(service_locator, this) {
+}
+
+const ClientInfo& ClientInfoManager::client_info() {
+ ServiceDependency<ObjectManager> object_manager_(service_.service_locator());
+ client_info_.num_objects_ = object_manager_->GetNumObjects();
+ return client_info_;
+}
+
+} // namespace o3d
diff --git a/o3d/core/cross/client_info.h b/o3d/core/cross/client_info.h
new file mode 100644
index 0000000..2fd8869
--- /dev/null
+++ b/o3d/core/cross/client_info.h
@@ -0,0 +1,118 @@
+/*
+ * Copyright 2009, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+// This file defines the ClientInfo class.
+
+#ifndef O3D_CORE_CROSS_CLIENT_INFO_H_
+#define O3D_CORE_CROSS_CLIENT_INFO_H_
+
+#include "core/cross/types.h"
+#include "core/cross/service_locator.h"
+#include "core/cross/service_implementation.h"
+
+namespace o3d {
+
+// This class is used to report infomation about the client.
+class ClientInfo {
+ public:
+ ClientInfo()
+ : num_objects_(0),
+ texture_memory_used_(0),
+ buffer_memory_used_(0),
+ software_renderer_(false) {
+ }
+
+ // The number of objects the client is currently tracking.
+ int num_objects() const {
+ return num_objects_;
+ }
+
+ // The amount of texture memory used.
+ int texture_memory_used() const {
+ return texture_memory_used_;
+ };
+
+ // The amount of texture memory used.
+ int buffer_memory_used() const {
+ return buffer_memory_used_;
+ }
+
+ // Whether or not we are using the software renderer.
+ bool software_renderer() const {
+ return software_renderer_;
+ }
+
+ private:
+ friend class ClientInfoManager;
+
+ int num_objects_;
+ int texture_memory_used_;
+ int buffer_memory_used_;
+ bool software_renderer_;
+};
+
+// A class to manage the client info so other classes can easily look it up.
+class ClientInfoManager {
+ public:
+ static const InterfaceId kInterfaceId;
+
+ explicit ClientInfoManager(ServiceLocator* service_locator);
+
+ const ClientInfo& client_info();
+
+ // Adds or subtracts from the amount of texture memory used.
+ void AdjustTextureMemoryUsed(int amount) {
+ client_info_.texture_memory_used_ += amount;
+ DCHECK(client_info_.texture_memory_used_ >= 0);
+ }
+
+ // Adds or subtracts from the amount of texture memory used.
+ void AdjustBufferMemoryUsed(int amount) {
+ client_info_.buffer_memory_used_ += amount;
+ DCHECK(client_info_.buffer_memory_used_ >= 0);
+ }
+
+ void SetSoftwareRenderer(bool used) {
+ client_info_.software_renderer_ = used;
+ }
+
+private:
+ ServiceImplementation<ClientInfoManager> service_;
+
+ ClientInfo client_info_;
+
+ DISALLOW_COPY_AND_ASSIGN(ClientInfoManager);
+};
+
+} // namespace o3d
+
+#endif // O3D_CORE_CROSS_CLIENT_INFO_H_
diff --git a/o3d/core/cross/client_info_test.cc b/o3d/core/cross/client_info_test.cc
new file mode 100644
index 0000000..d83aa92
--- /dev/null
+++ b/o3d/core/cross/client_info_test.cc
@@ -0,0 +1,152 @@
+/*
+ * Copyright 2009, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+// This file implements unit tests for class ClientInfoManager.
+
+#include "core/cross/client.h"
+#include "tests/common/win/testing_common.h"
+#include "core/cross/client_info.h"
+
+namespace o3d {
+
+class ClientInfoManagerTest : public testing::Test {
+ public:
+ ServiceLocator* service_locator() {
+ return service_locator_;
+ }
+
+ ObjectManager* object_manager() {
+ return object_manager_;
+ }
+
+ protected:
+ ClientInfoManagerTest() { }
+
+ virtual void SetUp() {
+ // We need to create a new SerivceLocator because the global one
+ // already has a global ClientInfoManager object registered on it.
+ service_locator_ = new ServiceLocator;
+ object_manager_ = new ObjectManager(service_locator_);
+ }
+
+ virtual void TearDown() {
+ delete object_manager_;
+ delete service_locator_;
+ }
+
+ ServiceLocator* service_locator_;
+ ObjectManager* object_manager_;
+};
+
+TEST_F(ClientInfoManagerTest, Basic) {
+ ClientInfoManager* client_info_manager =
+ new ClientInfoManager(service_locator());
+ ASSERT_TRUE(client_info_manager != NULL);
+
+ // Check that the client_info_manager start off correctly.
+ EXPECT_EQ(0, client_info_manager->client_info().texture_memory_used());
+ EXPECT_EQ(0, client_info_manager->client_info().buffer_memory_used());
+ EXPECT_EQ(0, client_info_manager->client_info().num_objects());
+ EXPECT_FALSE(client_info_manager->client_info().software_renderer());
+
+ delete client_info_manager;
+}
+
+TEST_F(ClientInfoManagerTest, AdjustTextureMemoryUsed) {
+ ClientInfoManager* client_info_manager =
+ new ClientInfoManager(service_locator());
+ ASSERT_TRUE(client_info_manager != NULL);
+
+ client_info_manager->AdjustTextureMemoryUsed(10);
+ EXPECT_EQ(10, client_info_manager->client_info().texture_memory_used());
+ client_info_manager->AdjustTextureMemoryUsed(10);
+ EXPECT_EQ(20, client_info_manager->client_info().texture_memory_used());
+ client_info_manager->AdjustTextureMemoryUsed(-10);
+ EXPECT_EQ(10, client_info_manager->client_info().texture_memory_used());
+ client_info_manager->AdjustTextureMemoryUsed(-10);
+ EXPECT_EQ(0, client_info_manager->client_info().texture_memory_used());
+
+ delete client_info_manager;
+}
+
+TEST_F(ClientInfoManagerTest, AdjustBufferMemoryUsed) {
+ ClientInfoManager* client_info_manager =
+ new ClientInfoManager(service_locator());
+ ASSERT_TRUE(client_info_manager != NULL);
+
+ client_info_manager->AdjustBufferMemoryUsed(10);
+ EXPECT_EQ(10, client_info_manager->client_info().buffer_memory_used());
+ client_info_manager->AdjustBufferMemoryUsed(10);
+ EXPECT_EQ(20, client_info_manager->client_info().buffer_memory_used());
+ client_info_manager->AdjustBufferMemoryUsed(-10);
+ EXPECT_EQ(10, client_info_manager->client_info().buffer_memory_used());
+ client_info_manager->AdjustBufferMemoryUsed(-10);
+ EXPECT_EQ(0, client_info_manager->client_info().buffer_memory_used());
+
+ delete client_info_manager;
+}
+
+TEST_F(ClientInfoManagerTest, SetNumObjects) {
+ ClientInfoManager* client_info_manager =
+ new ClientInfoManager(service_locator());
+ ASSERT_TRUE(client_info_manager != NULL);
+
+ ObjectBase* object_1 = new ObjectBase(service_locator());
+ ASSERT_TRUE(object_1 != NULL);
+ EXPECT_EQ(1, client_info_manager->client_info().num_objects());
+
+ ObjectBase* object_2 = new ObjectBase(service_locator());
+ ASSERT_TRUE(object_2 != NULL);
+ EXPECT_EQ(2, client_info_manager->client_info().num_objects());
+
+ delete object_1;
+ EXPECT_EQ(1, client_info_manager->client_info().num_objects());
+ delete object_2;
+ EXPECT_EQ(0, client_info_manager->client_info().num_objects());
+
+ delete client_info_manager;
+}
+
+TEST_F(ClientInfoManagerTest, SetSoftwareRenderer) {
+ ClientInfoManager* client_info_manager =
+ new ClientInfoManager(service_locator());
+ ASSERT_TRUE(client_info_manager != NULL);
+
+ client_info_manager->SetSoftwareRenderer(true);
+ EXPECT_TRUE(client_info_manager->client_info().software_renderer());
+ client_info_manager->SetSoftwareRenderer(false);
+ EXPECT_FALSE(client_info_manager->client_info().software_renderer());
+
+ delete client_info_manager;
+}
+
+} // namespace o3d
diff --git a/o3d/core/cross/object_manager.h b/o3d/core/cross/object_manager.h
index 5294ac1..fea7d62 100644
--- a/o3d/core/cross/object_manager.h
+++ b/o3d/core/cross/object_manager.h
@@ -39,6 +39,7 @@
#include "core/cross/object_base.h"
#include "core/cross/named_object.h"
#include "core/cross/service_implementation.h"
+#include "core/cross/service_dependency.h"
#include "core/cross/types.h"
#include "core/cross/error.h"
@@ -50,7 +51,6 @@ class Pack;
// lists of objects can be found based on various criteria.
class ObjectManager {
public:
-
static const InterfaceId kInterfaceId;
explicit ObjectManager(ServiceLocator* service_locator);
@@ -183,8 +183,11 @@ class ObjectManager {
// Destroys all registered packs.
void DestroyAllPacks();
- private:
+ size_t GetNumObjects() const {
+ return object_map_.size();
+ }
+ private:
typedef std::vector<SmartPointer<Pack> > PackRefArray;
// Dictionary of Objects indexed by their unique ID
diff --git a/o3d/core/cross/service_implementation.h b/o3d/core/cross/service_implementation.h
index 3ffd74c..c4a5b8d 100644
--- a/o3d/core/cross/service_implementation.h
+++ b/o3d/core/cross/service_implementation.h
@@ -57,6 +57,10 @@ class ServiceImplementation {
service_locator_->RemoveService(Interface::kInterfaceId, service_);
}
+ ServiceLocator* service_locator() const {
+ return service_locator_;
+ }
+
private:
ServiceLocator* service_locator_;
Interface* service_;
diff --git a/o3d/core/cross/texture.cc b/o3d/core/cross/texture.cc
index 70a6b5a..058dbb4 100644
--- a/o3d/core/cross/texture.cc
+++ b/o3d/core/cross/texture.cc
@@ -34,7 +34,9 @@
#include "core/cross/precompile.h"
#include "core/cross/texture.h"
+#include "core/cross/bitmap.h"
#include "core/cross/renderer.h"
+#include "core/cross/client_info.h"
#include "core/cross/error.h"
namespace o3d {
@@ -64,6 +66,11 @@ Texture2D::Texture2D(ServiceLocator* service_locator,
RegisterReadOnlyParamRef(kHeightParamName, &height_param_);
width_param_->set_read_only_value(width);
height_param_->set_read_only_value(height);
+
+ ClientInfoManager* client_info_manager =
+ service_locator->GetService<ClientInfoManager>();
+ client_info_manager->AdjustTextureMemoryUsed(
+ static_cast<int>(Bitmap::GetMipChainSize(width, height, format, levels)));
}
Texture2D::~Texture2D() {
@@ -72,6 +79,14 @@ Texture2D::~Texture2D() {
<< "Texture2D \"" << name()
<< "\" was never unlocked before being destroyed.";
}
+
+ ClientInfoManager* client_info_manager =
+ service_locator()->GetService<ClientInfoManager>();
+ client_info_manager->AdjustTextureMemoryUsed(
+ -static_cast<int>(Bitmap::GetMipChainSize(width(),
+ height(),
+ format(),
+ levels())));
}
ObjectBase::Ref Texture2D::Create(ServiceLocator* service_locator) {
@@ -116,6 +131,14 @@ TextureCUBE::TextureCUBE(ServiceLocator* service_locator,
}
RegisterReadOnlyParamRef(kEdgeLengthParamName, &edge_length_param_);
edge_length_param_->set_read_only_value(edge_length);
+
+ ClientInfoManager* client_info_manager =
+ service_locator->GetService<ClientInfoManager>();
+ client_info_manager->AdjustTextureMemoryUsed(
+ static_cast<int>(Bitmap::GetMipChainSize(edge_length,
+ edge_length,
+ format,
+ levels)) * 6);
}
TextureCUBE::~TextureCUBE() {
@@ -127,6 +150,14 @@ TextureCUBE::~TextureCUBE() {
break; // No need to report it more than once.
}
}
+
+ ClientInfoManager* client_info_manager =
+ service_locator()->GetService<ClientInfoManager>();
+ client_info_manager->AdjustTextureMemoryUsed(
+ -static_cast<int>(Bitmap::GetMipChainSize(edge_length(),
+ edge_length(),
+ format(),
+ levels()) * 6));
}
ObjectBase::Ref TextureCUBE::Create(ServiceLocator* service_locator) {
diff --git a/o3d/core/win/d3d9/renderer_d3d9.cc b/o3d/core/win/d3d9/renderer_d3d9.cc
index de2ab2c..aaf920e 100644
--- a/o3d/core/win/d3d9/renderer_d3d9.cc
+++ b/o3d/core/win/d3d9/renderer_d3d9.cc
@@ -43,6 +43,7 @@
#include "core/cross/renderer_platform.h"
#include "core/cross/semantic_manager.h"
#include "core/cross/service_dependency.h"
+#include "core/cross/client_info.h"
#include "core/cross/shape.h"
#include "core/cross/features.h"
#include "core/cross/types.h"
@@ -366,7 +367,7 @@ bool IsForceSoftwareRendererEnabled() {
&key))) {
return false;
}
-
+
bool enabled = false;
DWORD type;
DWORD value;
@@ -398,6 +399,7 @@ Renderer::InitStatus InitializeD3D9Context(
D3DPRESENT_PARAMETERS* d3d_present_parameters,
bool fullscreen,
Features* features,
+ ServiceLocator* service_locator,
int* out_width,
int* out_height) {
@@ -411,7 +413,7 @@ Renderer::InitStatus InitializeD3D9Context(
// Create a hardware device.
status_hardware = CreateDirect3D(Direct3DCreate9, d3d, features);
}
-
+
if (status_hardware != Renderer::SUCCESS) {
Renderer::InitStatus status_software = CreateDirect3D(
Direct3DCreate9Software, d3d, features);
@@ -430,6 +432,10 @@ Renderer::InitStatus InitializeD3D9Context(
}
SetupSoftwareRenderer(*d3d);
+
+ ClientInfoManager* client_info_manager =
+ service_locator->GetService<ClientInfoManager>();
+ client_info_manager->SetSoftwareRenderer(true);
}
D3DDISPLAYMODE d3ddm;
@@ -978,6 +984,7 @@ Renderer::InitStatus RendererD3D9::InitPlatformSpecific(
&d3d_present_parameters_,
fullscreen_,
features(),
+ service_locator(),
&width,
&height);
if (init_status != SUCCESS) {