summaryrefslogtreecommitdiffstats
path: root/o3d
diff options
context:
space:
mode:
authorgman@google.com <gman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-14 00:50:44 +0000
committergman@google.com <gman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-14 00:50:44 +0000
commit920894548dc271c46113b4960915f0d5bee5ceea (patch)
tree0c1f6bbce6db960605300da08859dcce7301fbe7 /o3d
parent106f1ea08504f309d6796b232681dfd08689eb08 (diff)
downloadchromium_src-920894548dc271c46113b4960915f0d5bee5ceea.zip
chromium_src-920894548dc271c46113b4960915f0d5bee5ceea.tar.gz
chromium_src-920894548dc271c46113b4960915f0d5bee5ceea.tar.bz2
Change to O3D IMC code so UPDATE_TEXTURE2D_RECT has
a pitch which allows you to send a sub rect of a source rectangle. Also fixed a bug in UPDATE_TEXTRE2D so it works as it used to. They used to send 1280x199+200 bytes to update the first 320x200 area of a 1280x720 texture. I broke that in a previous build. Finally I changed the declarations in message_command.h to be C++ compatible. The offsetof macro does not work if a class has a constructor. Review URL: http://codereview.chromium.org/165503 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23402 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d')
-rw-r--r--o3d/core/cross/message_commands.cc8
-rw-r--r--o3d/core/cross/message_commands.h312
-rw-r--r--o3d/core/cross/message_commands_test.cc156
-rw-r--r--o3d/core/cross/message_queue.cc131
-rw-r--r--o3d/core/cross/message_queue.h6
-rw-r--r--o3d/core/cross/message_queue_test.cc28
6 files changed, 341 insertions, 300 deletions
diff --git a/o3d/core/cross/message_commands.cc b/o3d/core/cross/message_commands.cc
index 631f518..30a5be5 100644
--- a/o3d/core/cross/message_commands.cc
+++ b/o3d/core/cross/message_commands.cc
@@ -35,16 +35,16 @@
#include "core/cross/message_commands.h"
namespace o3d {
-
-const char* IMCMessage::GetMessageDescription(IMCMessage::MessageId id) {
- const char* const message_descriptions[] = {
+namespace imc {
+const char* GetMessageDescription(MessageId id) {
+ static const char* const message_descriptions[] = {
#define O3D_IMC_MESSAGE_OP(id, class_name) #id,
O3D_IMC_MESSAGE_LIST(O3D_IMC_MESSAGE_OP)
#undef O3D_IMC_MESSAGE_OP
};
return message_descriptions[id];
}
-
+} // namespace imc
} // namespace o3d
diff --git a/o3d/core/cross/message_commands.h b/o3d/core/cross/message_commands.h
index bb14f9b..216c837 100644
--- a/o3d/core/cross/message_commands.h
+++ b/o3d/core/cross/message_commands.h
@@ -62,107 +62,111 @@ O3D_PUSH_STRUCTURE_PACKING_1;
OP(UPDATE_TEXTURE2D_RECT, MessageUpdateTexture2DRect) \
-// The base of all IMCMessages
-struct IMCMessage {
- enum MessageId {
- #define O3D_IMC_MESSAGE_OP(id, class_name) id,
- O3D_IMC_MESSAGE_LIST(O3D_IMC_MESSAGE_OP)
- #undef O3D_IMC_MESSAGE_OP
+namespace imc {
+enum MessageId {
+ #define O3D_IMC_MESSAGE_OP(id, class_name) id,
+ O3D_IMC_MESSAGE_LIST(O3D_IMC_MESSAGE_OP)
+ #undef O3D_IMC_MESSAGE_OP
- MAX_NUM_IDS,
+ MAX_NUM_IDS,
- ID_FORCE_DWORD = 0x7fffffff // Forces a 32-bit size enum
- };
-
- explicit IMCMessage(MessageId id) : message_id(id) {
- }
-
- // Returns a string by message ID.
- static const char* GetMessageDescription(MessageId id);
+ ID_FORCE_DWORD = 0x7fffffff // Forces a 32-bit size enum
+};
- int32 message_id;
+// Returns a string by message ID.
+const char* GetMessageDescription(MessageId id);
};
// An invalid message. This is mostly a place holder for id 0.
-struct MessageInvalidId : public IMCMessage {
- static const IMCMessage::MessageId kMessageId = INVALID_ID;
+struct MessageInvalidId {
+ // Message Content.
+ struct Msg {
+ static const imc::MessageId kMessageId = imc::INVALID_ID;
- MessageInvalidId()
- : IMCMessage(kMessageId) {
+ imc::MessageId message_id;
+ };
+
+ MessageInvalidId() {
+ msg.message_id = Msg::kMessageId;
}
+
+ Msg msg;
};
// The first message you send.
-struct MessageHello : public IMCMessage {
- static const IMCMessage::MessageId kMessageId = HELLO;
+struct MessageHello {
+ // Message Content.
+ struct Msg {
+ static const imc::MessageId kMessageId = imc::HELLO;
+
+ imc::MessageId message_id;
+ };
- MessageHello()
- : IMCMessage(kMessageId) {
+ MessageHello() {
+ msg.message_id = Msg::kMessageId;
}
+
+ Msg msg;
};
// A message to allocate shared memory
-struct MessageAllocateSharedMemory : public IMCMessage {
- static const MessageId kMessageId = ALLOCATE_SHARED_MEMORY;
- static const int32 kMaxSharedMemSize = 1024 * 1024 * 128; // 128MB
+struct MessageAllocateSharedMemory {
+ // Message Content.
+ struct Msg {
+ static const imc::MessageId kMessageId = imc::ALLOCATE_SHARED_MEMORY;
+ static const int32 kMaxSharedMemSize = 1024 * 1024 * 128; // 128MB
+
+ imc::MessageId message_id;
+
+ // The amount of memory to allocate.
+ int32 mem_size;
+ };
- MessageAllocateSharedMemory()
- : IMCMessage(kMessageId) {
+ MessageAllocateSharedMemory() {
+ msg.message_id = Msg::kMessageId;
}
// Parameters:
// in_mem_size: The number of bytes to allocate.
- explicit MessageAllocateSharedMemory(int32 in_mem_size)
- : IMCMessage(kMessageId),
- mem_size(in_mem_size) {
+ explicit MessageAllocateSharedMemory(int32 in_mem_size) {
+ msg.message_id = Msg::kMessageId;
+ msg.mem_size = in_mem_size;
}
- // The amount of memory to allocate.
- int32 mem_size;
+ Msg msg;
};
-// A message to register shared memory.
-struct MessageRegisterSharedMemory : public IMCMessage {
- static const MessageId kMessageId = REGISTER_SHARED_MEMORY;
- static const int32 kMaxSharedMemSize = 1024 * 1024 * 128; // 128MB
-
- MessageRegisterSharedMemory()
- : IMCMessage(kMessageId) {
- }
- explicit MessageRegisterSharedMemory(int32 in_mem_size)
- : IMCMessage(kMessageId),
- mem_size(in_mem_size) {
- }
+// A message to update the entire contents of a 2D texture. The number
+// of bytes MUST equal the size of the entire texture to be updated including
+// all mips.
+struct MessageUpdateTexture2D {
+ // Message Content.
+ struct Msg {
+ static const imc::MessageId kMessageId = imc::UPDATE_TEXTURE2D;
- int32 mem_size;
-};
+ imc::MessageId message_id;
-// A message to unregister shared memory.
-struct MessageUnregisterSharedMemory : public IMCMessage {
- static const MessageId kMessageId = UNREGISTER_SHARED_MEMORY;
+ // The id of the texture to set.
+ Id texture_id;
- MessageUnregisterSharedMemory()
- : IMCMessage(kMessageId) {
- }
+ // The mip level of the texture to set.
+ int32 level;
- // Parameters:
- // in_buffer_id: The id of the buffer to unregister.
- explicit MessageUnregisterSharedMemory(int32 in_buffer_id)
- : IMCMessage(kMessageId),
- buffer_id(in_buffer_id) {
- }
+ // The id of the shared memory the contains the data to use to set the
+ // texture.
+ int32 shared_memory_id;
- int32 buffer_id;
-};
+ // The offset inside the shared memory where the texture data starts.
+ int32 offset;
-// A message to update the entire contents of a 2D texture. The number
-// of bytes MUST equal the size of the entire texture to be updated including
-// all mips.
-struct MessageUpdateTexture2D : public IMCMessage {
- static const MessageId kMessageId = UPDATE_TEXTURE2D;
+ // The number of bytes to get out of shared memory.
+ // NOTE: this number MUST match the size of the texture. For example for an
+ // ARGB texture it must be mip_width * mip_height * 4 * sizeof(uint8)
+ int32 number_of_bytes;
+ };
- MessageUpdateTexture2D()
- : IMCMessage(kMessageId) {
+ MessageUpdateTexture2D() {
+ msg.message_id = Msg::kMessageId;
}
// Parameters:
@@ -179,41 +183,105 @@ struct MessageUpdateTexture2D : public IMCMessage {
int32 in_level,
int32 in_shared_memory_id,
int32 in_offset,
- int32 in_number_of_bytes)
- : IMCMessage(kMessageId),
- texture_id(in_texture_id),
- level(in_level),
- shared_memory_id(in_shared_memory_id),
- offset(in_offset),
- number_of_bytes(in_number_of_bytes) {
+ int32 in_number_of_bytes) {
+ msg.message_id = Msg::kMessageId;
+ msg.texture_id = in_texture_id;
+ msg.level = in_level;
+ msg.shared_memory_id = in_shared_memory_id;
+ msg.offset = in_offset;
+ msg.number_of_bytes = in_number_of_bytes;
}
- // The id of the texture to set.
- Id texture_id;
+ Msg msg;
+};
- // The mip level of the texture to set.
- int32 level;
+// A message to register shared memory.
+struct MessageRegisterSharedMemory {
+ // Message Content.
+ struct Msg {
+ static const imc::MessageId kMessageId = imc::REGISTER_SHARED_MEMORY;
+ static const int32 kMaxSharedMemSize = 1024 * 1024 * 128; // 128MB
+
+ imc::MessageId message_id;
+ int32 mem_size;
+ };
- // The id of the shared memory the contains the data to use to set the
- // texture.
- int32 shared_memory_id;
+ MessageRegisterSharedMemory() {
+ msg.message_id = Msg::kMessageId;
+ }
- // The offset inside the shared memory where the texture data starts.
- int32 offset;
+ explicit MessageRegisterSharedMemory(int32 in_mem_size) {
+ msg.message_id = Msg::kMessageId;
+ msg.mem_size = in_mem_size;
+ }
- // The number of bytes to get out of shared memory.
- // NOTE: this number MUST match the size of the texture. For example for an
- // ARGB texture it must be mip_width * mip_height * 4 * sizeof(uint8)
- int32 number_of_bytes;
+ Msg msg;
+};
+
+// A message to unregister shared memory.
+struct MessageUnregisterSharedMemory {
+ // Message Content.
+ struct Msg {
+ static const imc::MessageId kMessageId = imc::UNREGISTER_SHARED_MEMORY;
+
+ imc::MessageId message_id;
+ int32 buffer_id;
+ };
+
+ MessageUnregisterSharedMemory() {
+ msg.message_id = Msg::kMessageId;
+ }
+
+ // Parameters:
+ // in_buffer_id: The id of the buffer to unregister.
+ explicit MessageUnregisterSharedMemory(int32 in_buffer_id) {
+ msg.message_id = Msg::kMessageId;
+ msg.buffer_id = in_buffer_id;
+ }
+
+ Msg msg;
};
// A message to update a portion of a 2D texture. The number of bytes MUST equal
// the size of the portion of the texture to be updated.
-struct MessageUpdateTexture2DRect : public IMCMessage {
- static const MessageId kMessageId = UPDATE_TEXTURE2D_RECT;
+struct MessageUpdateTexture2DRect {
+ // Message Content.
+ struct Msg {
+ static const imc::MessageId kMessageId = imc::UPDATE_TEXTURE2D_RECT;
+
+ imc::MessageId message_id;
+
+ // The id of the texture to set.
+ Id texture_id;
+
+ // The mip level of the texture to set.
+ int32 level;
- MessageUpdateTexture2DRect()
- : IMCMessage(kMessageId) {
+ // The left edge of the rectangle to update in the texture.
+ int32 x;
+
+ // The top edge of the rectangle to update in the texture.
+ int32 y;
+
+ // The width of the rectangle to update in the texture.
+ int32 width;
+
+ // The height of the rectangle to update in the texture.
+ int32 height;
+
+ // The id of the shared memory the contains the data to use to set the
+ // texture.
+ int32 shared_memory_id;
+
+ // The offset inside the shared memory where the texture data starts.
+ int32 offset;
+
+ // The number of bytes bytes across 1 row in the source data.
+ int32 pitch;
+ };
+
+ MessageUpdateTexture2DRect() {
+ msg.message_id = Msg::kMessageId;
}
// Parameters:
@@ -227,10 +295,7 @@ struct MessageUpdateTexture2DRect : public IMCMessage {
// use to set the texture.
// in_offset: The offset inside the shared memory where the texture data
// starts.
- // in_number_of_bytes: The number of bytes to get out of shared memory.
- // NOTE: this number MUST match the size of the area in the texture to
- // be updated. For example for an ARGB texture it must be
- // width * height 4 * sizeof(uint8)
+ // in_pitch: The number of bytes bytes across 1 row in the source data.
MessageUpdateTexture2DRect(Id in_texture_id,
int32 in_level,
int32 in_x,
@@ -239,49 +304,20 @@ struct MessageUpdateTexture2DRect : public IMCMessage {
int32 in_height,
int32 in_shared_memory_id,
int32 in_offset,
- int32 in_number_of_bytes)
- : IMCMessage(kMessageId),
- texture_id(in_texture_id),
- level(in_level),
- x(in_x),
- y(in_y),
- width(in_width),
- height(in_height),
- shared_memory_id(in_shared_memory_id),
- offset(in_offset),
- number_of_bytes(in_number_of_bytes) {
+ int32 in_pitch) {
+ msg.message_id = Msg::kMessageId;
+ msg.texture_id = in_texture_id;
+ msg.level = in_level;
+ msg.x = in_x;
+ msg.y = in_y;
+ msg.width = in_width;
+ msg.height = in_height;
+ msg.shared_memory_id = in_shared_memory_id;
+ msg.offset = in_offset;
+ msg.pitch = in_pitch;
}
- // The id of the texture to set.
- Id texture_id;
-
- // The mip level of the texture to set.
- int32 level;
-
- // The left edge of the rectangle to update in the texture.
- int32 x;
-
- // The top edge of the rectangle to update in the texture.
- int32 y;
-
- // The width of the rectangle to update in the texture.
- int32 width;
-
- // The height of the rectangle to update in the texture.
- int32 height;
-
- // The id of the shared memory the contains the data to use to set the
- // texture.
- int32 shared_memory_id;
-
- // The offset inside the shared memory where the texture data starts.
- int32 offset;
-
- // The number of bytes to get out of shared memory.
- // NOTE: this number MUST match the size of the area in the texture to be
- // updated. For example for an ARGB texture it must be
- // width * height 4 * sizeof(uint8)
- int32 number_of_bytes;
+ Msg msg;
};
O3D_POP_STRUCTURE_PACKING;
diff --git a/o3d/core/cross/message_commands_test.cc b/o3d/core/cross/message_commands_test.cc
index b56735f..c4303dc 100644
--- a/o3d/core/cross/message_commands_test.cc
+++ b/o3d/core/cross/message_commands_test.cc
@@ -35,108 +35,124 @@
namespace o3d {
-#define O3D_OFFSETOF(type, field) \
- static_cast<size_t>( \
- reinterpret_cast<char*>(&(reinterpret_cast<type*>(1))->field) - \
- reinterpret_cast<char *>(1))
-
class MessageCommandsTest : public testing::Test {
};
TEST_F(MessageCommandsTest, GetMessageDescription) {
- EXPECT_STREQ(IMCMessage::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(4u, sizeof msg);
- EXPECT_EQ(0u, O3D_OFFSETOF(IMCMessage, message_id));
+ EXPECT_STREQ(imc::GetMessageDescription(
+ imc::ALLOCATE_SHARED_MEMORY), "ALLOCATE_SHARED_MEMORY");
}
TEST_F(MessageCommandsTest, MessageInvalidIdTest) {
+ EXPECT_EQ(static_cast<int>(imc::INVALID_ID), 0);
+ //EXPECT_EQ(imc::INVALID_ID, MessageInvalidId::Msg::KMessageId);
+ EXPECT_EQ(0u, offsetof(MessageInvalidId::Msg, message_id));
MessageInvalidId msg;
- EXPECT_EQ(static_cast<int>(IMCMessage::INVALID_ID), 0);
- //EXPECT_EQ(IMCMessage::INVALID_ID, MessageInvalidId::kMessageId);
- EXPECT_EQ(IMCMessage::INVALID_ID, msg.message_id);
- EXPECT_EQ(4u, sizeof(msg));
- EXPECT_EQ(0u, O3D_OFFSETOF(MessageInvalidId, message_id));
+ EXPECT_EQ(imc::INVALID_ID, msg.msg.message_id);
+ EXPECT_EQ(4u, sizeof msg.msg);
}
TEST_F(MessageCommandsTest, MessageHelloTest) {
+ EXPECT_EQ(static_cast<int>(imc::HELLO), 1);
+ //EXPECT_EQ(imc::HELLO, MessageHello::Msg::KMessageId);
+ EXPECT_EQ(0u, offsetof(MessageHello::Msg, message_id));
MessageHello msg;
- EXPECT_EQ(static_cast<int>(IMCMessage::HELLO), 1);
- //EXPECT_EQ(IMCMessage::HELLO, MessageHello::kMessageId);
- EXPECT_EQ(msg.message_id, IMCMessage::HELLO);
- EXPECT_EQ(4u, sizeof msg);
- EXPECT_EQ(0u, O3D_OFFSETOF(MessageHello, message_id));
+ EXPECT_EQ(imc::HELLO, msg.msg.message_id);
+ EXPECT_EQ(4u, sizeof msg.msg);
}
TEST_F(MessageCommandsTest, MessageAllocateSharedMemoryTest) {
+ EXPECT_EQ(static_cast<int>(imc::ALLOCATE_SHARED_MEMORY), 2);
+ //EXPECT_EQ(imc::ALLOCATE_SHARED_MEMORY,
+ // MessageAllocateSharedMemory::Msg::KMessageId);
+ EXPECT_EQ(0u, offsetof(MessageAllocateSharedMemory::Msg, message_id));
+ EXPECT_EQ(4u, offsetof(MessageAllocateSharedMemory::Msg, mem_size));
MessageAllocateSharedMemory msg;
- EXPECT_EQ(static_cast<int>(IMCMessage::ALLOCATE_SHARED_MEMORY), 2);
- //EXPECT_EQ(IMCMessage::ALLOCATE_SHARED_MEMORY,
- // MessageAllocateSharedMemory::kMessageId);
- EXPECT_EQ(IMCMessage::ALLOCATE_SHARED_MEMORY, msg.message_id);
- EXPECT_EQ(8u, sizeof msg);
- EXPECT_EQ(0u, O3D_OFFSETOF(MessageAllocateSharedMemory, message_id));
- EXPECT_EQ(4u, O3D_OFFSETOF(MessageAllocateSharedMemory, mem_size));
+ EXPECT_EQ(imc::ALLOCATE_SHARED_MEMORY, msg.msg.message_id);
+ EXPECT_EQ(8u, sizeof msg.msg);
+ MessageAllocateSharedMemory msg2(3);
+ EXPECT_EQ(imc::ALLOCATE_SHARED_MEMORY, msg2.msg.message_id);
+ EXPECT_EQ(3, msg2.msg.mem_size);
}
TEST_F(MessageCommandsTest, MessageUpdateTexture2D) {
+ EXPECT_EQ(static_cast<int>(imc::UPDATE_TEXTURE2D), 3);
+ //EXPECT_EQ(imc::UPDATE_TEXTURE2D,
+ // MessageUpdateTexture2D::Msg::KMessageId);
+ EXPECT_EQ(0u, offsetof(MessageUpdateTexture2D::Msg, message_id));
+ EXPECT_EQ(4u, offsetof(MessageUpdateTexture2D::Msg, texture_id));
+ EXPECT_EQ(8u, offsetof(MessageUpdateTexture2D::Msg, level));
+ EXPECT_EQ(12u, offsetof(MessageUpdateTexture2D::Msg, shared_memory_id));
+ EXPECT_EQ(16u, offsetof(MessageUpdateTexture2D::Msg, offset));
+ EXPECT_EQ(20u, offsetof(MessageUpdateTexture2D::Msg, number_of_bytes));
MessageUpdateTexture2D msg;
- EXPECT_EQ(static_cast<int>(IMCMessage::UPDATE_TEXTURE2D), 3);
- //EXPECT_EQ(IMCMessage::UPDATE_TEXTURE2D, MessageUpdateTexture2D::kMessageId);
- EXPECT_EQ(IMCMessage::UPDATE_TEXTURE2D, msg.message_id);
- EXPECT_EQ(24u, sizeof msg);
- EXPECT_EQ(0u, O3D_OFFSETOF(MessageUpdateTexture2D, message_id));
- EXPECT_EQ(4u, O3D_OFFSETOF(MessageUpdateTexture2D, texture_id));
- EXPECT_EQ(8u, O3D_OFFSETOF(MessageUpdateTexture2D, level));
- EXPECT_EQ(12u, O3D_OFFSETOF(MessageUpdateTexture2D, shared_memory_id));
- EXPECT_EQ(16u, O3D_OFFSETOF(MessageUpdateTexture2D, offset));
- EXPECT_EQ(20u, O3D_OFFSETOF(MessageUpdateTexture2D, number_of_bytes));
+ EXPECT_EQ(imc::UPDATE_TEXTURE2D, msg.msg.message_id);
+ EXPECT_EQ(24u, sizeof msg.msg);
+ MessageUpdateTexture2D msg2(2, 3, 4, 5, 6);
+ EXPECT_EQ(imc::UPDATE_TEXTURE2D, msg2.msg.message_id);
+ EXPECT_EQ(2, msg2.msg.texture_id);
+ EXPECT_EQ(3, msg2.msg.level);
+ EXPECT_EQ(4, msg2.msg.shared_memory_id);
+ EXPECT_EQ(5, msg2.msg.offset);
+ EXPECT_EQ(6, msg2.msg.number_of_bytes);
}
TEST_F(MessageCommandsTest, MessageRegisterSharedMemory) {
+ EXPECT_EQ(static_cast<int>(imc::REGISTER_SHARED_MEMORY), 4);
+ //EXPECT_EQ(imc::REGISTER_SHARED_MEMORY,
+ // MessageRegisterSharedMemory::Msg::KMessageId);
+ EXPECT_EQ(0u, offsetof(MessageRegisterSharedMemory::Msg, message_id));
+ EXPECT_EQ(4u, offsetof(MessageRegisterSharedMemory::Msg, mem_size));
MessageRegisterSharedMemory msg;
- EXPECT_EQ(static_cast<int>(IMCMessage::REGISTER_SHARED_MEMORY), 4);
- //EXPECT_EQ(IMCMessage::REGISTER_SHARED_MEMORY,
- // MessageRegisterSharedMemory::kMessageId);
- EXPECT_EQ(IMCMessage::REGISTER_SHARED_MEMORY, msg.message_id);
- EXPECT_EQ(8u, sizeof msg);
- EXPECT_EQ(0u, O3D_OFFSETOF(MessageRegisterSharedMemory, message_id));
- EXPECT_EQ(4u, O3D_OFFSETOF(MessageRegisterSharedMemory, mem_size));
+ EXPECT_EQ(imc::REGISTER_SHARED_MEMORY, msg.msg.message_id);
+ EXPECT_EQ(8u, sizeof msg.msg);
+ MessageRegisterSharedMemory msg2(123);
+ EXPECT_EQ(imc::REGISTER_SHARED_MEMORY, msg2.msg.message_id);
+ EXPECT_EQ(123, msg2.msg.mem_size);
}
TEST_F(MessageCommandsTest, MessageUnregisterSharedMemory) {
+ EXPECT_EQ(static_cast<int>(imc::UNREGISTER_SHARED_MEMORY), 5);
+ //EXPECT_EQ(imc::UNREGISTER_SHARED_MEMORY,
+ // MessageUnregisterSharedMemory::Msg::KMessageId);
+ EXPECT_EQ(0u, offsetof(MessageUnregisterSharedMemory::Msg, message_id));
+ EXPECT_EQ(4u, offsetof(MessageUnregisterSharedMemory::Msg, buffer_id));
MessageUnregisterSharedMemory msg;
- EXPECT_EQ(static_cast<int>(IMCMessage::UNREGISTER_SHARED_MEMORY), 5);
- //EXPECT_EQ(IMCMessage::UNREGISTER_SHARED_MEMORY,
- // MessageUnregisterSharedMemory::kMessageId);
- EXPECT_EQ(IMCMessage::UNREGISTER_SHARED_MEMORY, msg.message_id);
- EXPECT_EQ(8u, sizeof msg);
- EXPECT_EQ(0u, O3D_OFFSETOF(MessageUnregisterSharedMemory, message_id));
- EXPECT_EQ(4u, O3D_OFFSETOF(MessageUnregisterSharedMemory, buffer_id));
+ EXPECT_EQ(imc::UNREGISTER_SHARED_MEMORY, msg.msg.message_id);
+ EXPECT_EQ(8u, sizeof msg.msg);
+ MessageUnregisterSharedMemory msg2(2);
+ EXPECT_EQ(imc::UNREGISTER_SHARED_MEMORY, msg2.msg.message_id);
+ EXPECT_EQ(2, msg2.msg.buffer_id);
}
TEST_F(MessageCommandsTest, MessageUpdateTexture2DRect) {
+ EXPECT_EQ(static_cast<int>(imc::UPDATE_TEXTURE2D_RECT), 6);
+ //EXPECT_EQ(imc::UPDATE_TEXTURE2D_RECT,
+ // MessageUpdateTexture2DRect::Msg::KMessageId);
+ EXPECT_EQ(0u, offsetof(MessageUpdateTexture2DRect::Msg, message_id));
+ EXPECT_EQ(4u, offsetof(MessageUpdateTexture2DRect::Msg, texture_id));
+ EXPECT_EQ(8u, offsetof(MessageUpdateTexture2DRect::Msg, level));
+ EXPECT_EQ(12u, offsetof(MessageUpdateTexture2DRect::Msg, x));
+ EXPECT_EQ(16u, offsetof(MessageUpdateTexture2DRect::Msg, y));
+ EXPECT_EQ(20u, offsetof(MessageUpdateTexture2DRect::Msg, width));
+ EXPECT_EQ(24u, offsetof(MessageUpdateTexture2DRect::Msg, height));
+ EXPECT_EQ(28u, offsetof(MessageUpdateTexture2DRect::Msg, shared_memory_id));
+ EXPECT_EQ(32u, offsetof(MessageUpdateTexture2DRect::Msg, offset));
+ EXPECT_EQ(36u, offsetof(MessageUpdateTexture2DRect::Msg, pitch));
MessageUpdateTexture2DRect msg;
- EXPECT_EQ(static_cast<int>(IMCMessage::UPDATE_TEXTURE2D_RECT), 6);
- //EXPECT_EQ(IMCMessage::UPDATE_TEXTURE2D_RECT,
- // MessageUpdateTexture2DRect::kMessageId);
- EXPECT_EQ(IMCMessage::UPDATE_TEXTURE2D_RECT, msg.message_id);
- EXPECT_EQ(40u, sizeof msg);
- EXPECT_EQ(0u, O3D_OFFSETOF(MessageUpdateTexture2DRect, message_id));
- EXPECT_EQ(4u, O3D_OFFSETOF(MessageUpdateTexture2DRect, texture_id));
- EXPECT_EQ(8u, O3D_OFFSETOF(MessageUpdateTexture2DRect, level));
- EXPECT_EQ(12u, O3D_OFFSETOF(MessageUpdateTexture2DRect, x));
- EXPECT_EQ(16u, O3D_OFFSETOF(MessageUpdateTexture2DRect, y));
- EXPECT_EQ(20u, O3D_OFFSETOF(MessageUpdateTexture2DRect, width));
- EXPECT_EQ(24u, O3D_OFFSETOF(MessageUpdateTexture2DRect, height));
- EXPECT_EQ(28u, O3D_OFFSETOF(MessageUpdateTexture2DRect, shared_memory_id));
- EXPECT_EQ(32u, O3D_OFFSETOF(MessageUpdateTexture2DRect, offset));
- EXPECT_EQ(36u, O3D_OFFSETOF(MessageUpdateTexture2DRect, number_of_bytes));
+ EXPECT_EQ(imc::UPDATE_TEXTURE2D_RECT, msg.msg.message_id);
+ EXPECT_EQ(40u, sizeof msg.msg);
+ MessageUpdateTexture2DRect msg2(2, 3, 4, 5, 6, 7, 8, 9, 10);
+ EXPECT_EQ(imc::UPDATE_TEXTURE2D_RECT, msg2.msg.message_id);
+ EXPECT_EQ(2, msg2.msg.texture_id);
+ EXPECT_EQ(3, msg2.msg.level);
+ EXPECT_EQ(4, msg2.msg.x);
+ EXPECT_EQ(5, msg2.msg.y);
+ EXPECT_EQ(6, msg2.msg.width);
+ EXPECT_EQ(7, msg2.msg.height);
+ EXPECT_EQ(8, msg2.msg.shared_memory_id);
+ EXPECT_EQ(9, msg2.msg.offset);
+ EXPECT_EQ(10, msg2.msg.pitch);
}
} // namespace o3d
diff --git a/o3d/core/cross/message_queue.cc b/o3d/core/cross/message_queue.cc
index 61b63d0..eaed533 100644
--- a/o3d/core/cross/message_queue.cc
+++ b/o3d/core/cross/message_queue.cc
@@ -221,13 +221,13 @@ bool MessageQueue::CheckForNewMessages() {
// ReceiveMessageFromSocket also returns true if there are no
// messages in the queue in which case message_length will be equal
// to -1.
- IMCMessage::MessageId message_id;
+ imc::MessageId message_id;
int message_length = 0;
if (ReceiveMessageFromSocket(server_socket_handle_,
&header,
&message_id,
&message_length)) {
- if (message_id == IMCMessage::HELLO) {
+ if (message_id == imc::HELLO) {
ProcessHelloMessage(&header, handles);
#ifdef OS_WIN
metric_imc_hello_msg.Set(true);
@@ -277,9 +277,9 @@ bool MessageQueue::CheckForNewMessages() {
// return the ID in message_id.
bool MessageQueue::ReceiveMessageFromSocket(nacl::Handle socket,
nacl::MessageHeader* header,
- IMCMessage::MessageId* message_id,
+ imc::MessageId* message_id,
int* length) {
- *message_id = IMCMessage::INVALID_ID;
+ *message_id = imc::INVALID_ID;
// Check if there's a new message but don't block waiting for it.
int message_length = nacl::ReceiveDatagram(socket,
@@ -324,10 +324,10 @@ bool MessageQueue::ReceiveMessageFromSocket(nacl::Handle socket,
}
// Extract the ID of the message just received.
- IMCMessage::MessageId id_found =
- *(reinterpret_cast<IMCMessage::MessageId*>(header->iov[0].base));
- if (id_found <= IMCMessage::INVALID_ID ||
- id_found >= IMCMessage::MAX_NUM_IDS) {
+ imc::MessageId id_found =
+ *(reinterpret_cast<imc::MessageId*>(header->iov[0].base));
+ if (id_found <= imc::INVALID_ID ||
+ id_found >= imc::MAX_NUM_IDS) {
LOG(ERROR) << "Unknown ID found in message :" << id_found;
}
*message_id = id_found;
@@ -342,16 +342,16 @@ bool MessageQueue::ReceiveMessageFromSocket(nacl::Handle socket,
bool MessageQueue::ProcessClientRequest(ConnectedClient* client,
int message_length,
- IMCMessage::MessageId message_id,
+ imc::MessageId message_id,
nacl::MessageHeader* header,
nacl::Handle* handles) {
static int expected_message_lengths[] = {
- #define O3D_IMC_MESSAGE_OP(id, class_name) sizeof(class_name),
+ #define O3D_IMC_MESSAGE_OP(id, class_name) sizeof(class_name::Msg),
O3D_IMC_MESSAGE_LIST(O3D_IMC_MESSAGE_OP)
#undef O3D_IMC_MESSAGE_OP
};
- if (message_id == IMCMessage::INVALID_ID ||
+ if (message_id == imc::INVALID_ID ||
static_cast<unsigned>(message_id) >=
arraysize(expected_message_lengths)) {
LOG(ERROR) << "Unrecognized message id " << message_id;
@@ -360,15 +360,15 @@ bool MessageQueue::ProcessClientRequest(ConnectedClient* client,
if (message_length != expected_message_lengths[message_id]) {
LOG(ERROR) << "Bad message length for "
- << IMCMessage::GetMessageDescription(message_id);
+ << imc::GetMessageDescription(message_id);
return false;
}
switch (message_id) {
#define O3D_IMC_MESSAGE_OP(id, class_name) \
- case IMCMessage::id: return Process ## class_name( \
+ case imc::id: return Process ## class_name( \
client, message_length, header, handles, \
- *static_cast<const class_name*>(header->iov[0].base));
+ *static_cast<const class_name::Msg*>(header->iov[0].base));
O3D_IMC_MESSAGE_LIST(O3D_IMC_MESSAGE_OP)
#undef O3D_IMC_MESSAGE_OP
default:
@@ -443,7 +443,7 @@ bool MessageQueue::ProcessMessageInvalidId(
int message_length,
nacl::MessageHeader* header,
nacl::Handle* handles,
- const MessageInvalidId& message) {
+ const MessageInvalidId::Msg& message) {
return false;
}
@@ -452,7 +452,7 @@ bool MessageQueue::ProcessMessageHello(
int message_length,
nacl::MessageHeader* header,
nacl::Handle* handles,
- const MessageHello& message) {
+ const MessageHello::Msg& message) {
// Hello is handled special.
return false;
}
@@ -467,7 +467,7 @@ bool MessageQueue::ProcessMessageAllocateSharedMemory(
int message_length,
nacl::MessageHeader* header,
nacl::Handle* handles,
- const MessageAllocateSharedMemory& message) {
+ const MessageAllocateSharedMemory::Msg& message) {
if (header->iov_length != 1 ||
header->handle_count != 0) {
@@ -477,10 +477,10 @@ bool MessageQueue::ProcessMessageAllocateSharedMemory(
int32 mem_size = message.mem_size;
if (mem_size <= 0 ||
- mem_size > MessageAllocateSharedMemory::kMaxSharedMemSize) {
+ mem_size > MessageAllocateSharedMemory::Msg::kMaxSharedMemSize) {
LOG(ERROR) << "Invalid mem size requested: " << mem_size
<< "(max size = "
- << MessageAllocateSharedMemory::kMaxSharedMemSize << ")";
+ << MessageAllocateSharedMemory::Msg::kMaxSharedMemSize << ")";
return false;
}
@@ -547,12 +547,12 @@ bool MessageQueue::ProcessMessageUpdateTexture2D(
int message_length,
nacl::MessageHeader* header,
nacl::Handle* handles,
- const MessageUpdateTexture2D& message) {
+ const MessageUpdateTexture2D::Msg& message) {
// Check the length of the message to make sure it contains the size of
// the requested buffer.
if (header->iov_length != 1 ||
header->handle_count != 0) {
- LOG(ERROR) << "Malformed message for UPDATE_TEXTURE";
+ LOG(ERROR) << "Malformed message for UPDATE_TEXTURE2D";
SendBooleanResponse(client->client_handle(), false);
return false;
}
@@ -581,40 +581,36 @@ bool MessageQueue::ProcessMessageUpdateTexture2D(
// Check that we will not be reading past the end of the allocated shared
// memory.
- // TODO(gman): Comment this back in.
- //if (message.offset + message.number_of_bytes > info->size) {
- // O3D_ERROR(service_locator_)
- // << "Offset + texture size exceed allocated shared memory size ("
- // << message.offset << " + " << message.number_of_bytes << " > "
- // << info->size;
- // SendBooleanResponse(client->client_handle(), false);
- // return false;
- //}
+ if (message.offset + message.number_of_bytes > info->size) {
+ O3D_ERROR(service_locator_)
+ << "Offset + texture size exceeds allocated shared memory size ("
+ << message.offset << " + " << message.number_of_bytes << " > "
+ << info->size;
+ SendBooleanResponse(client->client_handle(), false);
+ return false;
+ }
unsigned int mip_width =
image::ComputeMipDimension(message.level, texture_object->width());
unsigned int mip_height =
image::ComputeMipDimension(message.level, texture_object->height());
- if (static_cast<unsigned>(message.number_of_bytes) !=
- image::ComputeMipChainSize(mip_width, mip_height,
- texture_object->format(), 1)) {
- // TODO(gman): comment this back in and return false.
- //O3D_ERROR(service_locator_)
- // << "texture_size does not match size of texture level ("
- // << message.offset << " + " << message.number_of_bytes << " > "
- // << info->size;
- //SendBooleanResponse(client->client_handle(), false);
- //return false;
- SendBooleanResponse(client->client_handle(), true);
- return true;
- }
-
void *target_address =
- static_cast<char*>(info->mapped_address) + message.offset;
+ PointerFromVoidPointer<void*>(info->mapped_address, message.offset);
+
+ int pitch = image::ComputePitch(texture_object->format(), mip_width);
+ int rows = message.number_of_bytes / pitch;
+
texture_object->SetRect(
- message.level, 0, 0, mip_width, mip_height, target_address,
- image::ComputePitch(texture_object->format(), mip_width));
+ message.level, 0, 0, mip_width, rows, target_address, pitch);
+
+ int remain = message.number_of_bytes % pitch;
+ if (remain) {
+ int width = remain / image::ComputePitch(texture_object->format(), 1);
+ texture_object->SetRect(
+ message.level, rows, 0, width, 1,
+ AddPointerOffset<void*>(target_address, rows * pitch), pitch);
+ }
SendBooleanResponse(client->client_handle(), true);
return true;
@@ -625,12 +621,12 @@ bool MessageQueue::ProcessMessageUpdateTexture2DRect(
int message_length,
nacl::MessageHeader* header,
nacl::Handle* handles,
- const MessageUpdateTexture2DRect& message) {
+ const MessageUpdateTexture2DRect::Msg& message) {
// Check the length of the message to make sure it contains the size of
// the requested buffer.
if (header->iov_length != 1 ||
header->handle_count != 0) {
- LOG(ERROR) << "Malformed message for UPDATE_TEXTURE_RECT";
+ LOG(ERROR) << "Malformed message for UPDATE_TEXTURE2D_RECT";
SendBooleanResponse(client->client_handle(), false);
return false;
}
@@ -659,10 +655,14 @@ bool MessageQueue::ProcessMessageUpdateTexture2DRect(
// Check that we will not be reading past the end of the allocated shared
// memory.
- if (message.offset + message.number_of_bytes > info->size) {
+ int32 number_of_bytes =
+ (message.height - 1) * message.pitch +
+ image::ComputePitch(texture_object->format(), message.width);
+ if (message.offset + number_of_bytes > info->size) {
O3D_ERROR(service_locator_)
- << "Offset + texture size exceed allocated shared memory size ("
- << message.offset << " + " << message.number_of_bytes << " > "
+ << "Offset + size as computed by width, height and pitch"
+ << " exceeds allocated shared memory size ("
+ << message.offset << " + " << number_of_bytes << " > "
<< info->size;
SendBooleanResponse(client->client_handle(), false);
return false;
@@ -685,24 +685,13 @@ bool MessageQueue::ProcessMessageUpdateTexture2DRect(
return false;
}
- if (static_cast<unsigned>(message.number_of_bytes) !=
- image::ComputeMipChainSize(message.width, message.height,
- texture_object->format(),
- 1)) {
- O3D_ERROR(service_locator_)
- << "number of bytes does not match size of texture rect ("
- << message.offset << " + " << message.number_of_bytes << " > "
- << info->size;
- SendBooleanResponse(client->client_handle(), false);
- return false;
- }
-
void *target_address =
- static_cast<char*>(info->mapped_address) + message.offset;
+ PointerFromVoidPointer<void*>(info->mapped_address, message.offset);
texture_object->SetRect(
- message.level, message.x, message.y, message.width, message.height,
+ message.level, message.x, message.y,
+ message.width, message.height,
target_address,
- image::ComputePitch(texture_object->format(), mip_width));
+ message.pitch);
SendBooleanResponse(client->client_handle(), true);
return true;
@@ -719,7 +708,7 @@ bool MessageQueue::ProcessMessageRegisterSharedMemory(
int message_length,
nacl::MessageHeader* header,
nacl::Handle* handles,
- const MessageRegisterSharedMemory& message) {
+ const MessageRegisterSharedMemory::Msg& message) {
if (header->iov_length != 1 ||
header->handle_count != 1) {
LOG(ERROR) << "Malformed message for REGISTER_SHARED_MEMORY";
@@ -728,10 +717,10 @@ bool MessageQueue::ProcessMessageRegisterSharedMemory(
int32 mem_size = message.mem_size;
if (mem_size <= 0 ||
- mem_size > MessageRegisterSharedMemory::kMaxSharedMemSize) {
+ mem_size > MessageRegisterSharedMemory::Msg::kMaxSharedMemSize) {
LOG(ERROR) << "Invalid mem size sent: " << mem_size
<< "(max size = "
- << MessageRegisterSharedMemory::kMaxSharedMemSize << ")";
+ << MessageRegisterSharedMemory::Msg::kMaxSharedMemSize << ")";
return false;
}
@@ -793,7 +782,7 @@ bool MessageQueue::ProcessMessageUnregisterSharedMemory(
int message_length,
nacl::MessageHeader* header,
nacl::Handle* handles,
- const MessageUnregisterSharedMemory& message) {
+ const MessageUnregisterSharedMemory::Msg& message) {
if (header->iov_length != 1 ||
header->handle_count != 0) {
LOG(ERROR) << "Malformed message for UNREGISTER_SHARED_MEMORY";
diff --git a/o3d/core/cross/message_queue.h b/o3d/core/cross/message_queue.h
index 7226064..55643ac 100644
--- a/o3d/core/cross/message_queue.h
+++ b/o3d/core/cross/message_queue.h
@@ -144,7 +144,7 @@ class MessageQueue {
// Client.
bool ProcessClientRequest(ConnectedClient* client,
int message_length,
- IMCMessage::MessageId message_id,
+ imc::MessageId message_id,
nacl::MessageHeader* header,
nacl::Handle* handles);
@@ -166,7 +166,7 @@ class MessageQueue {
int message_length, \
nacl::MessageHeader* header, \
nacl::Handle* handles, \
- const class_name& message);
+ const class_name::Msg& message);
O3D_IMC_MESSAGE_LIST(O3D_IMC_MESSAGE_OP)
#undef O3D_IMC_MESSAGE_OP
@@ -190,7 +190,7 @@ class MessageQueue {
// false in every other case.
bool ReceiveMessageFromSocket(nacl::Handle socket,
nacl::MessageHeader* header,
- IMCMessage::MessageId* message_id,
+ imc::MessageId* message_id,
int* message_length);
ServiceLocator* service_locator_;
diff --git a/o3d/core/cross/message_queue_test.cc b/o3d/core/cross/message_queue_test.cc
index ac34ad8..e9df153 100644
--- a/o3d/core/cross/message_queue_test.cc
+++ b/o3d/core/cross/message_queue_test.cc
@@ -295,8 +295,8 @@ bool TextureUpdateHelper::ConnectToO3D(const char* o3d_address,
MessageHello msg;
nacl::MessageHeader header;
nacl::IOVec vec;
- vec.base = &msg;
- vec.length = sizeof(msg);
+ vec.base = &msg.msg;
+ vec.length = sizeof(msg.msg);
nacl::SocketAddress socket_address;
::base::snprintf(socket_address.path,
@@ -312,8 +312,8 @@ bool TextureUpdateHelper::ConnectToO3D(const char* o3d_address,
0,
&socket_address);
- EXPECT_EQ(sizeof(msg), static_cast<size_t>(result));
- if (static_cast<size_t>(result) != sizeof(msg)) {
+ EXPECT_EQ(sizeof(msg.msg), static_cast<size_t>(result));
+ if (static_cast<size_t>(result) != sizeof(msg.msg)) {
return false;
}
@@ -346,8 +346,8 @@ bool TextureUpdateHelper::RequestSharedMemory(size_t requested_size,
nacl::MessageHeader header;
nacl::IOVec vec;
- vec.base = &msg;
- vec.length = sizeof(msg);
+ vec.base = &msg.msg;
+ vec.length = sizeof(msg.msg);
header.iov = &vec;
header.iov_length = 1;
@@ -421,8 +421,8 @@ bool TextureUpdateHelper::RequestTextureUpdate(unsigned int texture_id,
nacl::MessageHeader header;
nacl::IOVec vec;
- vec.base = &msg;
- vec.length = sizeof(msg);
+ vec.base = &msg.msg;
+ vec.length = sizeof(msg.msg);
header.iov = &vec;
header.iov_length = 1;
@@ -465,8 +465,8 @@ bool TextureUpdateHelper::RequestTextureRectUpdate(unsigned int texture_id,
nacl::MessageHeader header;
nacl::IOVec vec;
- vec.base = &msg;
- vec.length = sizeof(msg);
+ vec.base = &msg.msg;
+ vec.length = sizeof(msg.msg);
header.iov = &vec;
header.iov_length = 1;
@@ -505,8 +505,8 @@ int TextureUpdateHelper::RegisterSharedMemory(nacl::Handle shared_memory,
nacl::MessageHeader header;
nacl::IOVec vec;
- vec.base = &msg;
- vec.length = sizeof(msg);
+ vec.base = &msg.msg;
+ vec.length = sizeof(msg.msg);
header.iov = &vec;
header.iov_length = 1;
@@ -548,8 +548,8 @@ bool TextureUpdateHelper::UnregisterSharedMemory(int shared_memory_id) {
nacl::MessageHeader header;
nacl::IOVec vec;
- vec.base = &msg;
- vec.length = sizeof(msg);
+ vec.base = &msg.msg;
+ vec.length = sizeof(msg.msg);
header.iov = &vec;
header.iov_length = 1;
header.handles = NULL;