diff options
author | gman@google.com <gman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-26 21:23:38 +0000 |
---|---|---|
committer | gman@google.com <gman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-26 21:23:38 +0000 |
commit | 8b0d2570138bdc5041396befe90e5c55de1dffe5 (patch) | |
tree | 988d2f791deb47db87c5f0b1d3c59ec34522f9be /o3d/core | |
parent | 058254a8c1f684aecce93ed3d6ba6ca8864611b1 (diff) | |
download | chromium_src-8b0d2570138bdc5041396befe90e5c55de1dffe5.zip chromium_src-8b0d2570138bdc5041396befe90e5c55de1dffe5.tar.gz chromium_src-8b0d2570138bdc5041396befe90e5c55de1dffe5.tar.bz2 |
Adds a RENDER message to the O3D IMC.
Normally O3D renders as fast as it can but you can
put O3D in a render-on-demand mode
in which case it will only render when it has to,
like when part of the window is uncovered, or when
you explicit tell it.
Asking it to render does not render immediately, it
just marks the plugin in a state of "need to render".
The plugin will render at the next available chance.
Review URL: http://codereview.chromium.org/174465
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@24531 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d/core')
-rw-r--r-- | o3d/core/cross/message_commands.h | 19 | ||||
-rw-r--r-- | o3d/core/cross/message_commands_test.cc | 9 | ||||
-rw-r--r-- | o3d/core/cross/message_queue.cc | 20 | ||||
-rw-r--r-- | o3d/core/cross/message_queue_test.cc | 93 |
4 files changed, 141 insertions, 0 deletions
diff --git a/o3d/core/cross/message_commands.h b/o3d/core/cross/message_commands.h index 216c837..ce92d59 100644 --- a/o3d/core/cross/message_commands.h +++ b/o3d/core/cross/message_commands.h @@ -60,6 +60,7 @@ O3D_PUSH_STRUCTURE_PACKING_1; OP(REGISTER_SHARED_MEMORY, MessageRegisterSharedMemory) \
OP(UNREGISTER_SHARED_MEMORY, MessageUnregisterSharedMemory) \
OP(UPDATE_TEXTURE2D_RECT, MessageUpdateTexture2DRect) \
+ OP(RENDER, MessageRender) \
namespace imc {
@@ -320,6 +321,24 @@ struct MessageUpdateTexture2DRect { Msg msg;
};
+// Tell O3D to render. This is generally used when O3D is in Render on demand
+// mode.
+struct MessageRender {
+ // Message Content.
+ struct Msg {
+ static const imc::MessageId kMessageId = imc::RENDER;
+
+ imc::MessageId message_id;
+ };
+
+ MessageRender() {
+ msg.message_id = Msg::kMessageId;
+ }
+
+ Msg msg;
+};
+
+
O3D_POP_STRUCTURE_PACKING;
} // namespace o3d
diff --git a/o3d/core/cross/message_commands_test.cc b/o3d/core/cross/message_commands_test.cc index 93c0b72..3e089aa 100644 --- a/o3d/core/cross/message_commands_test.cc +++ b/o3d/core/cross/message_commands_test.cc @@ -143,6 +143,15 @@ TEST_F(MessageCommandsTest, MessageUpdateTexture2DRect) { EXPECT_EQ(10, msg2.msg.pitch); } +TEST_F(MessageCommandsTest, MessageRenderTest) { + EXPECT_EQ(static_cast<int>(imc::RENDER), 7); + EXPECT_EQ(0u, offsetof(MessageRender::Msg, message_id)); + MessageRender msg; + EXPECT_EQ(imc::RENDER, msg.msg.message_id); + EXPECT_EQ(4u, sizeof msg.msg); +} + + } // namespace o3d diff --git a/o3d/core/cross/message_queue.cc b/o3d/core/cross/message_queue.cc index ae601cf..23fa55e 100644 --- a/o3d/core/cross/message_queue.cc +++ b/o3d/core/cross/message_queue.cc @@ -44,6 +44,7 @@ #include "core/cross/texture.h" #include "core/cross/error.h" #include "core/cross/pointer_utils.h" +#include "core/cross/renderer.h" #ifdef OS_WIN #include "core/cross/core_metrics.h" @@ -791,5 +792,24 @@ bool MessageQueue::ProcessMessageUnregisterSharedMemory( return res; } +// Processes a request to Render. +bool MessageQueue::ProcessMessageRender( + ConnectedClient* client, + int message_length, + nacl::MessageHeader* header, + nacl::Handle* handles, + const MessageRender::Msg& message) { + if (header->iov_length != 1 || + header->handle_count != 0) { + LOG(ERROR) << "Malformed message for RENDER"; + return false; + } + + Renderer* renderer(service_locator_->GetService<Renderer>()); + if (renderer) { + renderer->set_need_to_render(true); + } + return true; +} } // namespace o3d diff --git a/o3d/core/cross/message_queue_test.cc b/o3d/core/cross/message_queue_test.cc index 3bc3941..1e2cf60 100644 --- a/o3d/core/cross/message_queue_test.cc +++ b/o3d/core/cross/message_queue_test.cc @@ -39,6 +39,7 @@ #include "core/cross/service_dependency.h" #include "core/cross/texture.h" #include "core/cross/types.h" +#include "core/cross/renderer.h" #include "tests/common/win/testing_common.h" #include "base/condition_variable.h" #include "base/lock.h" @@ -251,6 +252,9 @@ class TextureUpdateHelper { // memory segment. bool UnregisterSharedMemory(int shared_memory_id); + // Tells the renderer to render. + bool Render(); + private: // Handle of the socket that's connected to o3d. nacl::Handle o3d_handle_; @@ -564,7 +568,25 @@ bool TextureUpdateHelper::UnregisterSharedMemory(int shared_memory_id) { return reply; } +// Tells the renderer to render.. +bool TextureUpdateHelper::Render() { + MessageRender msg; + nacl::MessageHeader header; + nacl::IOVec vec; + + vec.base = &msg.msg; + vec.length = sizeof(msg.msg); + header.iov = &vec; + header.iov_length = 1; + header.handles = NULL; + header.handle_count = 0; + // Send message. + int result = nacl::SendDatagram(o3d_handle_, &header, 0); + EXPECT_EQ(static_cast<int>(vec.length), result); + // Read back the boolean reply from the O3D plugin + return true; +} //---------------------------------------------------------------------- // This is the main class containing all of the other ones. It knows @@ -1121,4 +1143,75 @@ TEST_F(MessageQueueTest, ConcurrentSharedMemoryOperations) { EXPECT_FALSE(CheckErrorExists()); } +namespace { + +// This helper class for Render test. +class RenderTest : public PerThreadConnectedTest { + private: + int num_iterations_; + + public: + explicit RenderTest(int num_iterations) { + num_iterations_ = num_iterations; + } + + void Run(MessageQueue* queue, + nacl::Handle socket_handle) { + String socket_addr = queue->GetSocketAddress(); + TextureUpdateHelper helper; + if (!helper.ConnectToO3D(socket_addr.c_str(), + socket_handle)) { + FAIL_TEST("Failed to connect to O3D"); + } + + // Allocate a shared memory segment + size_t mem_size = nacl::kMapPageSize; + nacl::Handle shared_memory = nacl::CreateMemoryObject(mem_size); + if (shared_memory == nacl::kInvalidHandle) { + FAIL_TEST("Failed to allocate shared memory object"); + } + + for (int i = 0; i < num_iterations_; i++) { + bool result = helper.Render(); + if (!result) { + FAIL_TEST("Failed to request a render"); + } + // Because Render has no result we run a few more messages the do + // to make sure Render was processed. + int shared_mem_id = + helper.RegisterSharedMemory(shared_memory, mem_size); + if (shared_mem_id < 0) { + FAIL_TEST("Failed to register shared memory with server"); + } + result = helper.UnregisterSharedMemory(shared_mem_id); + if (!result) { + FAIL_TEST("Failed to unregister shared memory from server"); + } + } + + Pass(); + } +}; + +} // anonymous namespace. + +// Tests requesting a render. +TEST_F(MessageQueueTest, Render) { + class Provider : public TestProvider { + public: + virtual PerThreadConnectedTest* CreateTest() { + return new RenderTest(1); + } + }; + + Renderer* renderer(g_service_locator->GetService<Renderer>()); + ASSERT_TRUE(renderer != NULL); + renderer->set_need_to_render(false); + + Provider provider; + RunTests(1, TimeDelta::FromSeconds(1), &provider); + EXPECT_FALSE(CheckErrorExists()); + EXPECT_TRUE(renderer->need_to_render()); +} + } // namespace o3d |