Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1566)

Unified Diff: mojo/examples/sample_app/sample_app.cc

Issue 93793009: Implement ServiceManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Allow Android to be built Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/examples/sample_app/native_viewport_client_impl.cc ('k') | mojo/mojo.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/examples/sample_app/sample_app.cc
diff --git a/mojo/examples/sample_app/sample_app.cc b/mojo/examples/sample_app/sample_app.cc
index 02d4ce20c3e5b2c687ed5cafe8f16dc69ec9b7b1..094ff88b9898cc531d0f363b5f447288607780b2 100644
--- a/mojo/examples/sample_app/sample_app.cc
+++ b/mojo/examples/sample_app/sample_app.cc
@@ -7,11 +7,14 @@
#include "base/message_loop/message_loop.h"
#include "mojo/common/bindings_support_impl.h"
-#include "mojo/examples/sample_app/native_viewport_client_impl.h"
+#include "mojo/examples/sample_app/gles2_client_impl.h"
#include "mojo/public/bindings/lib/bindings_support.h"
+#include "mojo/public/bindings/lib/remote_ptr.h"
#include "mojo/public/gles2/gles2.h"
#include "mojo/public/system/core.h"
#include "mojo/public/system/macros.h"
+#include "mojom/native_viewport.h"
+#include "mojom/shell.h"
#if defined(WIN32)
#if !defined(CDECL)
@@ -26,25 +29,75 @@
namespace mojo {
namespace examples {
-void Start(ScopedMessagePipeHandle pipe) {
- printf("Starting sample app.\n");
- NativeViewportClientImpl client(pipe.Pass());
- client.Open();
- base::MessageLoop::current()->Run();
-}
+class SampleApp : public ShellClientStub {
+ public:
+ explicit SampleApp(ScopedMessagePipeHandle shell_handle)
+ : shell_(shell_handle.Pass()) {
+ shell_.SetPeer(this);
+ mojo::ScopedMessagePipeHandle client_handle, native_viewport_handle;
+ CreateMessagePipe(&client_handle, &native_viewport_handle);
+ native_viewport_client_.reset(
+ new NativeViewportClientImpl(native_viewport_handle.Pass()));
+ mojo::AllocationScope scope;
+ shell_->Connect("mojo:mojo_native_viewport_service", client_handle.Pass());
+ }
+
+ virtual void AcceptConnection(ScopedMessagePipeHandle handle) MOJO_OVERRIDE {
+ NOTREACHED() << "SampleApp can't be connected to.";
+ }
+
+ private:
+ class NativeViewportClientImpl : public mojo::NativeViewportClientStub {
+ public:
+ explicit NativeViewportClientImpl(ScopedMessagePipeHandle viewport_handle)
+ : viewport_(viewport_handle.Pass()) {
+ viewport_.SetPeer(this);
+ viewport_->Open();
+ ScopedMessagePipeHandle gles2_handle;
+ ScopedMessagePipeHandle gles2_client_handle;
+ CreateMessagePipe(&gles2_handle, &gles2_client_handle);
+
+ gles2_client_.reset(new GLES2ClientImpl(gles2_handle.Pass()));
+ viewport_->CreateGLES2Context(gles2_client_handle.Pass());
+ }
+
+ virtual ~NativeViewportClientImpl() {}
+
+ virtual void OnCreated() MOJO_OVERRIDE {
+ }
+
+ virtual void OnDestroyed() MOJO_OVERRIDE {
+ base::MessageLoop::current()->Quit();
+ }
+
+ virtual void OnEvent(const Event& event) MOJO_OVERRIDE {
+ if (!event.location().is_null()) {
+ gles2_client_->HandleInputEvent(event);
+ viewport_->AckEvent(event);
+ }
+ }
+
+ private:
+ scoped_ptr<GLES2ClientImpl> gles2_client_;
+ RemotePtr<NativeViewport> viewport_;
+ };
+ mojo::RemotePtr<Shell> shell_;
+ scoped_ptr<NativeViewportClientImpl> native_viewport_client_;
+};
} // namespace examples
} // namespace mojo
-extern "C" SAMPLE_APP_EXPORT MojoResult CDECL MojoMain(MojoHandle pipe) {
+extern "C" SAMPLE_APP_EXPORT MojoResult CDECL MojoMain(
+ MojoHandle shell_handle) {
base::MessageLoop loop;
- mojo::common::BindingsSupportImpl bindings_support;
- mojo::BindingsSupport::Set(&bindings_support);
+ mojo::common::BindingsSupportImpl bindings_support_impl;
+ mojo::BindingsSupport::Set(&bindings_support_impl);
MojoGLES2Initialize();
- mojo::ScopedMessagePipeHandle scoped_handle;
- scoped_handle.reset(mojo::MessagePipeHandle(pipe));
- mojo::examples::Start(scoped_handle.Pass());
+ mojo::examples::SampleApp app(
+ mojo::MakeScopedHandle(mojo::MessagePipeHandle(shell_handle)).Pass());
+ loop.Run();
MojoGLES2Terminate();
mojo::BindingsSupport::Set(NULL);
« no previous file with comments | « mojo/examples/sample_app/native_viewport_client_impl.cc ('k') | mojo/mojo.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698