diff options
author | gman@google.com <gman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-12 02:07:09 +0000 |
---|---|---|
committer | gman@google.com <gman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-12 02:07:09 +0000 |
commit | d734f220da466c52f94423acc91bb347ef8811dd (patch) | |
tree | fa9422e17f016b5149888537be8f2ac0992a3918 /o3d | |
parent | 95853f348dddde2cae8eb9f8c3ca04cd1754c430 (diff) | |
download | chromium_src-d734f220da466c52f94423acc91bb347ef8811dd.zip chromium_src-d734f220da466c52f94423acc91bb347ef8811dd.tar.gz chromium_src-d734f220da466c52f94423acc91bb347ef8811dd.tar.bz2 |
A few more cleanup items for bitmap and
message_Commands
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23138 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d')
-rw-r--r-- | o3d/core/cross/bitmap.cc | 18 | ||||
-rw-r--r-- | o3d/core/cross/bitmap.h | 14 | ||||
-rw-r--r-- | o3d/core/cross/message_commands_test.cc | 85 | ||||
-rw-r--r-- | o3d/plugin/idl/bitmap.idl | 3 |
4 files changed, 107 insertions, 13 deletions
diff --git a/o3d/core/cross/bitmap.cc b/o3d/core/cross/bitmap.cc index c2709ae..8f82dc1 100644 --- a/o3d/core/cross/bitmap.cc +++ b/o3d/core/cross/bitmap.cc @@ -393,16 +393,22 @@ void Bitmap::GenerateMips(int source_level, int num_levels) { O3D_ERROR(service_locator()) << "source level out of range."; return; } - if (source_level + num_levels >= static_cast<int>(num_mipmaps()) || num_levels < 0) { + unsigned int max_mips = image::ComputeMipMapCount(width(), height()); + if (source_level + num_levels >= + static_cast<int>(max_mips) || num_levels < 0) { O3D_ERROR(service_locator()) << "num levels out of range."; return; } - GenerateMipmaps(image::ComputeMipDimension(source_level, width()), - image::ComputeMipDimension(source_level, height()), - format(), - num_levels, - GetMipData(source_level)); + if (GenerateMipmaps(image::ComputeMipDimension(source_level, width()), + image::ComputeMipDimension(source_level, height()), + format(), + num_levels, + GetMipData(source_level))) { + num_mipmaps_ = std::max( + num_mipmaps_, + static_cast<unsigned>(source_level + num_levels + 1)); + } } // NOTE: This only works for Bitmap since Bitmap knows the pitch. diff --git a/o3d/core/cross/bitmap.h b/o3d/core/cross/bitmap.h index a116ecb..2188fc9c 100644 --- a/o3d/core/cross/bitmap.h +++ b/o3d/core/cross/bitmap.h @@ -144,11 +144,6 @@ class Bitmap : public ParamObject { const void* src_data,
int src_pitch);
- // Gets the total size of the bitmap data, counting all faces and mip levels.
- size_t GetTotalSize() const {
- return GetMipChainSize(num_mipmaps_);
- }
-
// Gets the image data for a given mip-map level.
// Parameters:
// level: mip level to get.
@@ -296,7 +291,14 @@ class Bitmap : public ParamObject { unsigned int num_mipmaps,
uint8 *data);
+ // Gets the total size of the bitmap data, counting all faces and mip levels.
+ size_t GetTotalSize() const {
+ return GetMipChainSize(image::ComputeMipMapCount(width_, height_));
+ }
+
// pointer to the raw bitmap data
+ // NOTE: image_data_ is either NULL or it has space for the maximum number
+ // of mips for the current size bitmap, even if they are not used.
scoped_array<uint8> image_data_;
// format of the texture this is meant to represent.
Texture::Format format_;
@@ -304,7 +306,7 @@ class Bitmap : public ParamObject { int width_;
// height of the bitmap in pixels.
int height_;
- // number of mipmap levels in this texture.
+ // number of valid mipmap levels in this bitmap.
unsigned int num_mipmaps_;
// The purpose of the bitmap
Semantic semantic_;
diff --git a/o3d/core/cross/message_commands_test.cc b/o3d/core/cross/message_commands_test.cc index 93459a2..ca0c72b 100644 --- a/o3d/core/cross/message_commands_test.cc +++ b/o3d/core/cross/message_commands_test.cc @@ -29,6 +29,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include <stddef.h>
#include "core/cross/message_commands.h"
#include "tests/common/win/testing_common.h"
@@ -42,6 +43,90 @@ TEST_F(MessageCommandsTest, GetMessageDescription) { IMCMessage::ALLOCATE_SHARED_MEMORY), "ALLOCATE_SHARED_MEMORY");
};
+TEST_F(MessageCommandsTest, IMCMessage) {
+ IMCMessage msg(IMCMessage::INVALID_ID);
+ EXPECT_EQ(IMCMessage::INVALID_ID, msg.message_id);
+ EXPECT_EQ(4, sizeof(msg));
+ EXPECT_EQ(0, OFFSETOF(IMCMessage, message_id));
+}
+
+TEST_F(MessageCommandsTest, MessageInvalidId) {
+ MessageInvalidId msg();
+ EXPECT_EQ(IMCMessage::INVALID_ID, MessageInvalidId::kMessageId);
+ EXPECT_EQ(IMCMessage::INVALID_ID, msg.message_id);
+ EXPECT_EQ(4, sizeof(msg));
+ EXPECT_EQ(0, OFFSETOF(MessageInvalidId, message_id));
+}
+
+TEST_F(MessageHCommandsTest, MessageHello) {
+ MessageHello msg();
+ EXPECT_EQ(IMCMessage::HELLO, MessageHello::kMessageId);
+ EXPECT_EQ(IMCMessage::HELLO, msg.message_id);
+ EXPECT_EQ(4, sizeof(msg));
+ EXPECT_EQ(0, OFFSETOF(MessageHello, message_id));
+}
+
+TEST_F(MessageCommandsTest, MessageAllocateSharedMemory) {
+ MessageAllocateSharedMemory msg();
+ EXPECT_EQ(IMCMessage::ALLOCATE_SHARED_MEMORY,
+ MessageAllocateSharedMemory::kMessageId);
+ EXPECT_EQ(IMCMessage::ALLOCATE_SHARED_MEMORY, msg.message_id);
+ EXPECT_EQ(8, sizeof(msg));
+ EXPECT_EQ(0, OFFSETOF(MessageAllocateSharedMemory, message_id));
+ EXPECT_EQ(4, OFFSETOF(MessageAllocateSharedMemory, mem_size));
+}
+
+TEST_F(MessageCommandsTest, MessageRegisterSharedMemory) {
+ MessageRegisterSharedMemory msg();
+ EXPECT_EQ(IMCMessage::REGISTER_SHARED_MEMORY,
+ MessageRegisterSharedMemory::kMessageId);
+ EXPECT_EQ(IMCMessage::REGISTER_SHARED_MEMORY, msg.message_id);
+ EXPECT_EQ(8, sizeof(msg));
+ EXPECT_EQ(0, OFFSETOF(MessageRegisterSharedMemory, message_id));
+ EXPECT_EQ(4, OFFSETOF(MessageRegisterSharedMemory, mem_size));
+}
+
+TEST_F(MessageCommandsTest, MessageUnregisterSharedMemory) {
+ MessageUnregisterSharedMemory msg();
+ EXPECT_EQ(IMCMessage::UNREGISTER_SHARED_MEMORY,
+ MessageUnregisterSharedMemory::kMessageId);
+ EXPECT_EQ(IMCMessage::UNREGISTER_SHARED_MEMORY, msg.message_id);
+ EXPECT_EQ(8, sizeof(msg));
+ EXPECT_EQ(0, OFFSETOF(MessageUnregisterSharedMemory, message_id));
+ EXPECT_EQ(4, OFFSETOF(MessageUnregisterSharedMemory, buffer_id));
+}
+
+TEST_F(MessageCommandsTest, MessageUpdateTexture2D) {
+ MessageUpdateTexture2D msg();
+ EXPECT_EQ(IMCMessage::UPDATE_TEXTURE2D, MessageUpdateTexture2D::kMessageId);
+ EXPECT_EQ(IMCMessage::UPDATE_TEXTURE2D, msg.message_id);
+ EXPECT_EQ(24, sizeof(msg));
+ EXPECT_EQ(0, OFFSETOF(MessageUpdateTexture2D, message_id));
+ EXPECT_EQ(4, OFFSETOF(MessageUpdateTexture2D, texture_id));
+ EXPECT_EQ(8, OFFSETOF(MessageUpdateTexture2D, level));
+ EXPECT_EQ(12, OFFSETOF(MessageUpdateTexture2D, shared_memory_id));
+ EXPECT_EQ(16, OFFSETOF(MessageUpdateTexture2D, offset));
+ EXPECT_EQ(20, OFFSETOF(MessageUpdateTexture2D, number_of_bytes));
+}
+
+TEST_F(MessageCommandsTest, MessageUpdateTexture2DRect) {
+ MessageUpdateTexture2DRect msg();
+ EXPECT_EQ(IMCMessage::UPDATE_TEXTURE2D_RECT,
+ MessageUpdateTexture2DRect::kMessageId);
+ EXPECT_EQ(IMCMessage::UPDATE_TEXTURE2D_RECT, msg.message_id);
+ EXPECT_EQ(40, sizeof(msg));
+ EXPECT_EQ(0, OFFSETOF(MessageUpdateTexture2D, message_id));
+ EXPECT_EQ(4, OFFSETOF(MessageUpdateTexture2D, texture_id));
+ EXPECT_EQ(8, OFFSETOF(MessageUpdateTexture2D, level));
+ EXPECT_EQ(12, OFFSETOF(MessageUpdateTexture2D, x));
+ EXPECT_EQ(16, OFFSETOF(MessageUpdateTexture2D, y));
+ EXPECT_EQ(20, OFFSETOF(MessageUpdateTexture2D, width));
+ EXPECT_EQ(24, OFFSETOF(MessageUpdateTexture2D, height));
+ EXPECT_EQ(28, OFFSETOF(MessageUpdateTexture2D, shared_memory_id));
+ EXPECT_EQ(32, OFFSETOF(MessageUpdateTexture2D, offset));
+ EXPECT_EQ(36, OFFSETOF(MessageUpdateTexture2D, number_of_bytes));
+}
+
} // namespace o3d
diff --git a/o3d/plugin/idl/bitmap.idl b/o3d/plugin/idl/bitmap.idl index 76cca4c..b2fd6b6 100644 --- a/o3d/plugin/idl/bitmap.idl +++ b/o3d/plugin/idl/bitmap.idl @@ -75,7 +75,8 @@ class Bitmap : ParamObject { %[
Generates mip maps from the source level to lower levels.
- You can currently only use this on XRGB8 and ARGB8 textures.
+ You can not currently generate mips for DXT textures although you can load
+ them from dds files.
\param source_level The level to use as the source of the mips.
\param num_levels The number of levels to generate below the source level.
|