summaryrefslogtreecommitdiffstats
path: root/mojo/public
diff options
context:
space:
mode:
authorpiman@chromium.org <piman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-04 23:06:38 +0000
committerpiman@chromium.org <piman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-04 23:06:38 +0000
commit84e4d4fa159d9a92b42f7f2f4d612748d217e4b7 (patch)
tree87eb04b28704300bf2a59b89e49d7df61bb9bded /mojo/public
parentf368038ed50461fa08162b09a6152454d25e6f68 (diff)
downloadchromium_src-84e4d4fa159d9a92b42f7f2f4d612748d217e4b7.zip
chromium_src-84e4d4fa159d9a92b42f7f2f4d612748d217e4b7.tar.gz
chromium_src-84e4d4fa159d9a92b42f7f2f4d612748d217e4b7.tar.bz2
Create GLES2 context synchronously.
This introduces the infrastructure for "synchronous IPCs", and uses it for context creation. Though not strictly necessary for the current hack, it will be needed for the command buffer implementation, as well as for implementing an EGL layer. BUG=333157 R=darin@chromium.org Review URL: https://codereview.chromium.org/147083005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@248804 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo/public')
-rw-r--r--mojo/public/bindings/lib/sync_dispatcher.cc50
-rw-r--r--mojo/public/bindings/sync_dispatcher.h37
-rw-r--r--mojo/public/gles2/gles2.h1
-rw-r--r--mojo/public/gles2/gles2_private.cc2
-rw-r--r--mojo/public/gles2/gles2_private.h1
-rw-r--r--mojo/public/gles2/gles2_types.h2
6 files changed, 87 insertions, 6 deletions
diff --git a/mojo/public/bindings/lib/sync_dispatcher.cc b/mojo/public/bindings/lib/sync_dispatcher.cc
new file mode 100644
index 0000000..bbc521c
--- /dev/null
+++ b/mojo/public/bindings/lib/sync_dispatcher.cc
@@ -0,0 +1,50 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/public/bindings/sync_dispatcher.h"
+
+#include <stdlib.h>
+
+#include "mojo/public/bindings/lib/message.h"
+
+namespace mojo {
+
+bool WaitForMessageAndDispatch(MessagePipeHandle handle,
+ mojo::MessageReceiver* receiver) {
+ uint32_t num_bytes = 0, num_handles = 0;
+ while (true) {
+ MojoResult rv = ReadMessageRaw(handle,
+ NULL,
+ &num_bytes,
+ NULL,
+ &num_handles,
+ MOJO_READ_MESSAGE_FLAG_NONE);
+ if (rv == MOJO_RESULT_RESOURCE_EXHAUSTED)
+ break;
+ if (rv != MOJO_RESULT_SHOULD_WAIT)
+ return false;
+ rv = Wait(handle, MOJO_WAIT_FLAG_READABLE, MOJO_DEADLINE_INDEFINITE);
+ if (rv != MOJO_RESULT_OK)
+ return false;
+ }
+
+ Message message;
+ message.data = static_cast<MessageData*>(malloc(num_bytes));
+ message.handles.resize(num_handles);
+
+ MojoResult rv =
+ ReadMessageRaw(handle,
+ message.data,
+ &num_bytes,
+ message.handles.empty()
+ ? NULL
+ : reinterpret_cast<MojoHandle*>(&message.handles[0]),
+ &num_handles,
+ MOJO_READ_MESSAGE_FLAG_NONE);
+ if (rv != MOJO_RESULT_OK)
+ return false;
+ return receiver->Accept(&message);
+}
+
+} // namespace mojo
diff --git a/mojo/public/bindings/sync_dispatcher.h b/mojo/public/bindings/sync_dispatcher.h
new file mode 100644
index 0000000..096ffbd
--- /dev/null
+++ b/mojo/public/bindings/sync_dispatcher.h
@@ -0,0 +1,37 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MOJO_PUBLIC_BINDINGS_SYNC_DISPATCHER_H_
+#define MOJO_PUBLIC_BINDINGS_SYNC_DISPATCHER_H_
+
+#include "mojo/public/system/core_cpp.h"
+
+namespace mojo {
+
+class MessageReceiver;
+
+// Waits for one message to arrive on the message pipe, and dispatch it to the
+// receiver. Returns true on success, false on failure.
+bool WaitForMessageAndDispatch(MessagePipeHandle handle,
+ mojo::MessageReceiver* receiver);
+
+template<typename S> class SyncDispatcher {
+ public:
+ SyncDispatcher(ScopedMessagePipeHandle message_pipe, S* sink)
+ : message_pipe_(message_pipe.Pass()),
+ stub_(sink) {
+ }
+
+ bool WaitAndDispatchOneMessage() {
+ return WaitForMessageAndDispatch(message_pipe_.get(), &stub_);
+ }
+
+ private:
+ ScopedMessagePipeHandle message_pipe_;
+ typename S::_Stub stub_;
+};
+
+} // namespace mojo
+
+#endif // MOJO_PUBLIC_BINDINGS_SYNC_DISPATCHER_H_
diff --git a/mojo/public/gles2/gles2.h b/mojo/public/gles2/gles2.h
index fbf9fa2..8effd31 100644
--- a/mojo/public/gles2/gles2.h
+++ b/mojo/public/gles2/gles2.h
@@ -23,7 +23,6 @@ MOJO_GLES2_EXPORT void MojoGLES2Initialize(MojoAsyncWaiter* async_waiter);
MOJO_GLES2_EXPORT void MojoGLES2Terminate();
MOJO_GLES2_EXPORT MojoGLES2Context MojoGLES2CreateContext(
MojoHandle handle,
- MojoGLES2ContextCreated created_callback,
MojoGLES2ContextLost lost_callback,
MojoGLES2DrawAnimationFrame animation_callback,
void* closure);
diff --git a/mojo/public/gles2/gles2_private.cc b/mojo/public/gles2/gles2_private.cc
index 536e0fc..1752828 100644
--- a/mojo/public/gles2/gles2_private.cc
+++ b/mojo/public/gles2/gles2_private.cc
@@ -27,12 +27,10 @@ void MojoGLES2Terminate() {
MojoGLES2Context MojoGLES2CreateContext(
MojoHandle handle,
- MojoGLES2ContextCreated created_callback,
MojoGLES2ContextLost lost_callback,
MojoGLES2DrawAnimationFrame animation_callback,
void* closure) {
return g_gles2_support->CreateContext(mojo::MessagePipeHandle(handle),
- created_callback,
lost_callback,
animation_callback,
closure);
diff --git a/mojo/public/gles2/gles2_private.h b/mojo/public/gles2/gles2_private.h
index 87ea4b9..8465cae 100644
--- a/mojo/public/gles2/gles2_private.h
+++ b/mojo/public/gles2/gles2_private.h
@@ -28,7 +28,6 @@ class MOJO_GLES2_EXPORT GLES2Support {
virtual void Terminate() = 0;
virtual MojoGLES2Context CreateContext(
MessagePipeHandle handle,
- MojoGLES2ContextCreated created_callback,
MojoGLES2ContextLost lost_callback,
MojoGLES2DrawAnimationFrame animation_callback,
void* closure) = 0;
diff --git a/mojo/public/gles2/gles2_types.h b/mojo/public/gles2/gles2_types.h
index b6a9838..c7d2216 100644
--- a/mojo/public/gles2/gles2_types.h
+++ b/mojo/public/gles2/gles2_types.h
@@ -16,8 +16,6 @@ extern "C" {
#endif
typedef struct MojoGLES2ContextPrivate *MojoGLES2Context;
-// TODO(piman): create context synchronously
-typedef void (*MojoGLES2ContextCreated)(void* closure);
typedef void (*MojoGLES2ContextLost)(void* closure);
typedef void (*MojoGLES2DrawAnimationFrame)(void* closure);