summaryrefslogtreecommitdiffstats
path: root/o3d
diff options
context:
space:
mode:
authortschmelcher@chromium.org <tschmelcher@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-06 21:20:47 +0000
committertschmelcher@chromium.org <tschmelcher@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-06 21:20:47 +0000
commit88e6577f7fd716a7f0d9f0590d030af6372c6333 (patch)
treebca566c86d617151b4044f620bb6d19be0e10957 /o3d
parent7968428a96099f945dcd1381aefb60b0a2faa484 (diff)
downloadchromium_src-88e6577f7fd716a7f0d9f0590d030af6372c6333.zip
chromium_src-88e6577f7fd716a7f0d9f0590d030af6372c6333.tar.gz
chromium_src-88e6577f7fd716a7f0d9f0590d030af6372c6333.tar.bz2
Add an API to allow JavaScript to determine the framerate of individual dynamic textures.
TEST=loaded O3D on a test page on Linux and used the new API to display the framerate BUG=none Review URL: http://codereview.chromium.org/5591006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68379 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d')
-rw-r--r--o3d/core/cross/cairo/texture_cairo.cc4
-rw-r--r--o3d/core/cross/gl/texture_gl.cc6
-rw-r--r--o3d/core/cross/gles2/texture_gles2.cc6
-rw-r--r--o3d/core/cross/texture_base.cc28
-rw-r--r--o3d/core/cross/texture_base.h22
-rw-r--r--o3d/core/win/d3d9/texture_d3d9.cc64
-rw-r--r--o3d/plugin/idl/texture.idl10
7 files changed, 111 insertions, 29 deletions
diff --git a/o3d/core/cross/cairo/texture_cairo.cc b/o3d/core/cross/cairo/texture_cairo.cc
index 31ab81f..87943f83 100644
--- a/o3d/core/cross/cairo/texture_cairo.cc
+++ b/o3d/core/cross/cairo/texture_cairo.cc
@@ -174,6 +174,10 @@ void TextureCairo::SetRect(int level,
// Discard our reference to the source surface.
cairo_surface_destroy(source_image_surface);
+
+ if (level == 0) {
+ TextureUpdated();
+ }
}
// Locks the given mipmap level of this texture for loading from main memory,
diff --git a/o3d/core/cross/gl/texture_gl.cc b/o3d/core/cross/gl/texture_gl.cc
index 814e7b3..7626e8e 100644
--- a/o3d/core/cross/gl/texture_gl.cc
+++ b/o3d/core/cross/gl/texture_gl.cc
@@ -451,6 +451,9 @@ void Texture2DGL::SetRect(int level,
src_data);
}
}
+ if (level == 0) {
+ TextureUpdated();
+ }
}
// Locks the given mipmap level of this texture for loading from main memory,
@@ -789,6 +792,9 @@ void TextureCUBEGL::SetRect(TextureCUBE::CubeFace face,
src_data);
}
}
+ if (level == 0) {
+ TextureUpdated();
+ }
}
// Locks the given face and mipmap level of this texture for loading from
diff --git a/o3d/core/cross/gles2/texture_gles2.cc b/o3d/core/cross/gles2/texture_gles2.cc
index 7c84cad..09dc269 100644
--- a/o3d/core/cross/gles2/texture_gles2.cc
+++ b/o3d/core/cross/gles2/texture_gles2.cc
@@ -493,6 +493,9 @@ void Texture2DGLES2::SetRect(int level,
src_data);
}
}
+ if (level == 0) {
+ TextureUpdated();
+ }
}
// Locks the given mipmap level of this texture for loading from main memory,
@@ -843,6 +846,9 @@ void TextureCUBEGLES2::SetRect(TextureCUBE::CubeFace face,
src_data);
}
}
+ if (level == 0) {
+ TextureUpdated();
+ }
}
// Locks the given face and mipmap level of this texture for loading from
diff --git a/o3d/core/cross/texture_base.cc b/o3d/core/cross/texture_base.cc
index a101425..3c633a8 100644
--- a/o3d/core/cross/texture_base.cc
+++ b/o3d/core/cross/texture_base.cc
@@ -33,8 +33,10 @@
// This file contains the definition of the Texture class.
#include "core/cross/texture_base.h"
-#include "core/cross/pack.h"
+
#include "core/cross/bitmap.h"
+#include "core/cross/pack.h"
+#include "core/cross/renderer.h"
namespace o3d {
@@ -49,14 +51,36 @@ Texture::Texture(ServiceLocator* service_locator,
int levels,
bool enable_render_surfaces)
: ParamObject(service_locator),
+ renderer_(service_locator->GetService<Renderer>()),
alpha_is_one_(false),
format_(format),
weak_pointer_manager_(this),
- render_surfaces_enabled_(enable_render_surfaces) {
+ render_surfaces_enabled_(enable_render_surfaces),
+ has_unrendered_update_(false),
+ last_render_frame_count_(0),
+ update_count_(0),
+ render_count_(0) {
RegisterReadOnlyParamRef(kLevelsParamName, &levels_param_);
levels_param_->set_read_only_value(levels);
}
+void Texture::TextureUpdated() {
+ CheckLastTextureUpdateRendered();
+ last_render_frame_count_ = renderer_->render_frame_count();
+ update_count_++;
+ has_unrendered_update_ = true;
+}
+
+void Texture::CheckLastTextureUpdateRendered() {
+ if (has_unrendered_update_ &&
+ renderer_->render_frame_count() != last_render_frame_count_) {
+ // Then a new frame has been rendered to the screen since we last
+ // updated this texture, so that update has been rendered to the screen.
+ render_count_++;
+ has_unrendered_update_ = false;
+ }
+}
+
ObjectBase::Ref ParamTexture::Create(ServiceLocator* service_locator) {
return ObjectBase::Ref(new ParamTexture(service_locator, false, false));
}
diff --git a/o3d/core/cross/texture_base.h b/o3d/core/cross/texture_base.h
index e6d0fce..8adf8e1 100644
--- a/o3d/core/cross/texture_base.h
+++ b/o3d/core/cross/texture_base.h
@@ -117,6 +117,15 @@ class Texture : public ParamObject {
return format_;
}
+ int update_count() {
+ return update_count_;
+ }
+
+ int render_count() {
+ CheckLastTextureUpdateRendered();
+ return render_count_;
+ }
+
bool render_surfaces_enabled() const {
return render_surfaces_enabled_;
}
@@ -142,7 +151,13 @@ class Texture : public ParamObject {
format_ = format;
}
+ void TextureUpdated();
+
+ Renderer* renderer_;
+
private:
+ void CheckLastTextureUpdateRendered();
+
// The number of mipmap levels contained in this texture.
ParamInteger::Ref levels_param_;
@@ -157,6 +172,13 @@ class Texture : public ParamObject {
bool render_surfaces_enabled_;
+ // Counting of frames, to allow the page to determine the framerate of dynamic
+ // textures.
+ bool has_unrendered_update_;
+ int last_render_frame_count_;
+ int update_count_;
+ int render_count_;
+
O3D_DECL_CLASS(Texture, ParamObject);
DISALLOW_COPY_AND_ASSIGN(Texture);
};
diff --git a/o3d/core/win/d3d9/texture_d3d9.cc b/o3d/core/win/d3d9/texture_d3d9.cc
index 8cb411c..c90d3f1 100644
--- a/o3d/core/win/d3d9/texture_d3d9.cc
+++ b/o3d/core/win/d3d9/texture_d3d9.cc
@@ -260,7 +260,7 @@ void SetTextureRectCompressed(Texture::Format format,
}
}
-void SetTextureRect(
+bool SetTextureRect(
ServiceLocator* service_locator,
IDirect3DTexture9* d3d_texture,
Texture::Format format,
@@ -280,7 +280,7 @@ void SetTextureRect(
if (!HR(d3d_texture->LockRect(
level, &out_rect, compressed ? NULL : &rect, 0))) {
O3D_ERROR(service_locator) << "Failed to Lock Texture2D (D3D9)";
- return;
+ return false;
}
const uint8* src = static_cast<const uint8*>(src_data);
@@ -294,11 +294,12 @@ void SetTextureRect(
}
if (!HR(d3d_texture->UnlockRect(level))) {
O3D_ERROR(service_locator) << "Failed to Unlock Texture2D (D3D9)";
- return;
+ return false;
}
+ return true;
}
-void SetTextureFaceRect(
+bool SetTextureFaceRect(
ServiceLocator* service_locator,
IDirect3DCubeTexture9* d3d_texture,
Texture::Format format,
@@ -321,7 +322,7 @@ void SetTextureFaceRect(
if (!HR(d3d_texture->LockRect(
d3d_face, level, &out_rect, compressed ? NULL : &rect, 0))) {
O3D_ERROR(service_locator) << "Failed to Lock TextureCUBE (D3D9)";
- return;
+ return false;
}
const uint8* src = static_cast<const uint8*>(src_data);
@@ -335,8 +336,9 @@ void SetTextureFaceRect(
}
if (!HR(d3d_texture->UnlockRect(d3d_face, level))) {
O3D_ERROR(service_locator) << "Failed to Unlock TextureCUBE (D3D9)";
- return;
+ return false;
}
+ return true;
}
} // unnamed namespace
@@ -550,6 +552,7 @@ void Texture2DD3D9::SetRect(int level,
return;
}
+ bool success = true;
if (resize_to_pot_) {
DCHECK(backing_bitmap_->image_data());
DCHECK(!compressed);
@@ -559,16 +562,19 @@ void Texture2DD3D9::SetRect(int level,
level, dst_left, dst_top, src_width, src_height, src_data, src_pitch);
UpdateBackedMipLevel(level);
} else {
- SetTextureRect(service_locator(),
- d3d_texture_,
- format(),
- level,
- dst_left,
- dst_top,
- src_width,
- src_height,
- src_data,
- src_pitch);
+ success = SetTextureRect(service_locator(),
+ d3d_texture_,
+ format(),
+ level,
+ dst_left,
+ dst_top,
+ src_width,
+ src_height,
+ src_data,
+ src_pitch);
+ }
+ if (success && level == 0) {
+ TextureUpdated();
}
}
@@ -877,6 +883,7 @@ void TextureCUBED3D9::SetRect(TextureCUBE::CubeFace face,
return;
}
+ bool success = true;
if (resize_to_pot_) {
Bitmap* backing_bitmap = backing_bitmaps_[face].Get();
DCHECK(backing_bitmap->image_data());
@@ -887,17 +894,20 @@ void TextureCUBED3D9::SetRect(TextureCUBE::CubeFace face,
level, dst_left, dst_top, src_width, src_height, src_data, src_pitch);
UpdateBackedMipLevel(face, level);
} else {
- SetTextureFaceRect(service_locator(),
- d3d_cube_texture_,
- format(),
- face,
- level,
- dst_left,
- dst_top,
- src_width,
- src_height,
- src_data,
- src_pitch);
+ success = SetTextureFaceRect(service_locator(),
+ d3d_cube_texture_,
+ format(),
+ face,
+ level,
+ dst_left,
+ dst_top,
+ src_width,
+ src_height,
+ src_data,
+ src_pitch);
+ }
+ if (success && level == 0) {
+ TextureUpdated();
}
}
diff --git a/o3d/plugin/idl/texture.idl b/o3d/plugin/idl/texture.idl
index e503ab8..2c11f16 100644
--- a/o3d/plugin/idl/texture.idl
+++ b/o3d/plugin/idl/texture.idl
@@ -109,6 +109,16 @@ namespace o3d {
[getter, getter, setter] bool alpha_is_one;
%[
+ The count of total updates made to this texture.
+ %]
+ [getter] int update_count;
+
+ %[
+ The count of updates made to this texture that were rendered to the screen.
+ %]
+ [getter] int render_count;
+
+ %[
Generates Mips.
\param source_level the mip to use as the source.
\param num_levels the number of mips from the source to generate.