Chromium Code Reviews| 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..01f77aecd06baeafad544757f07cfd0b655aa00c 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,74 @@ |
| 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 shell::ShellClientStub { |
| + public: |
| + explicit SampleApp(ScopedMessagePipeHandle shell_pipe) |
| + : shell_(shell_pipe.Pass()) { |
| + shell_.SetPeer(this); |
| + mojo::AllocationScope scope; |
|
darin (slow to review)
2013/12/10 06:12:36
nit: you might consider moving |scope| closer to w
DaveMoore
2013/12/11 18:56:44
Done.
|
| + mojo::ScopedMessagePipeHandle app_handle, client_handle; |
|
darin (slow to review)
2013/12/10 06:12:36
nit: app_handle -> service_handle ?
client_handle
DaveMoore
2013/12/11 18:56:44
I think I've made it consistent now. The handle is
|
| + CreateMessagePipe(&client_handle, &app_handle); |
| + native_viewport_client_.reset( |
| + new NativeViewportClientImpl(client_handle.Pass())); |
| + shell_->Connect("mojo:mojo_native_viewport_service", app_handle.Pass()); |
|
Ben Goodger (Google)
2013/12/10 16:35:03
not a direct comment on this CL but an observation
DaveMoore
2013/12/11 18:56:44
Agreed. The goal is to have something in mojom tha
|
| + } |
| + |
| + virtual void Connect(ScopedMessagePipeHandle handle) MOJO_OVERRIDE { |
| + } |
| + |
| + private: |
| + class NativeViewportClientImpl : public mojo::NativeViewportClientStub { |
| + public: |
| + explicit NativeViewportClientImpl(ScopedMessagePipeHandle client_handle) |
| + : viewport_(client_handle.Pass()) { |
| + viewport_.SetPeer(this); |
| + viewport_->Open();; |
|
darin (slow to review)
2013/12/10 06:12:36
nit: extra ";"
DaveMoore
2013/12/11 18:56:44
Done.
|
| + ScopedMessagePipeHandle gles2; |
| + ScopedMessagePipeHandle gles2_client; |
| + CreateMessagePipe(&gles2, &gles2_client); |
| + |
| + gles2_client_.reset(new GLES2ClientImpl(gles2.Pass())); |
| + viewport_->CreateGLES2Context(gles2_client.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()) { |
| + LOG(INFO) << "Located Event @" |
| + << event.location().x() << "," << event.location().y(); |
| + } |
| + } |
| + |
| + private: |
| + scoped_ptr<GLES2ClientImpl> gles2_client_; |
| + RemotePtr<NativeViewport> viewport_; |
| + }; |
| + mojo::RemotePtr<shell::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()); |
| + base::MessageLoop::current()->Run(); |
| MojoGLES2Terminate(); |
| mojo::BindingsSupport::Set(NULL); |