summaryrefslogtreecommitdiffstats
path: root/o3d/core
diff options
context:
space:
mode:
Diffstat (limited to 'o3d/core')
-rw-r--r--o3d/core/cross/message_commands.h19
-rw-r--r--o3d/core/cross/message_commands_test.cc9
-rw-r--r--o3d/core/cross/message_queue.cc20
-rw-r--r--o3d/core/cross/message_queue_test.cc93
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