Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stdio.h> | 5 #include <stdio.h> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "mojo/common/bindings_support_impl.h" | 9 #include "mojo/common/bindings_support_impl.h" |
| 10 #include "mojo/examples/sample_app/native_viewport_client_impl.h" | 10 #include "mojo/examples/sample_app/gles2_client_impl.h" |
| 11 #include "mojo/public/bindings/lib/bindings_support.h" | 11 #include "mojo/public/bindings/lib/bindings_support.h" |
| 12 #include "mojo/public/bindings/lib/remote_ptr.h" | |
| 12 #include "mojo/public/gles2/gles2.h" | 13 #include "mojo/public/gles2/gles2.h" |
| 13 #include "mojo/public/system/core.h" | 14 #include "mojo/public/system/core.h" |
| 14 #include "mojo/public/system/macros.h" | 15 #include "mojo/public/system/macros.h" |
| 16 #include "mojom/native_viewport.h" | |
| 17 #include "mojom/shell.h" | |
| 15 | 18 |
| 16 #if defined(WIN32) | 19 #if defined(WIN32) |
| 17 #if !defined(CDECL) | 20 #if !defined(CDECL) |
| 18 #define CDECL __cdecl | 21 #define CDECL __cdecl |
| 19 #endif | 22 #endif |
| 20 #define SAMPLE_APP_EXPORT __declspec(dllexport) | 23 #define SAMPLE_APP_EXPORT __declspec(dllexport) |
| 21 #else | 24 #else |
| 22 #define CDECL | 25 #define CDECL |
| 23 #define SAMPLE_APP_EXPORT __attribute__((visibility("default"))) | 26 #define SAMPLE_APP_EXPORT __attribute__((visibility("default"))) |
| 24 #endif | 27 #endif |
| 25 | 28 |
| 26 namespace mojo { | 29 namespace mojo { |
| 27 namespace examples { | 30 namespace examples { |
| 28 | 31 |
| 29 void Start(ScopedMessagePipeHandle pipe) { | 32 class SampleApp : public shell::ShellClientStub { |
| 30 printf("Starting sample app.\n"); | 33 public: |
| 31 NativeViewportClientImpl client(pipe.Pass()); | 34 explicit SampleApp(ScopedMessagePipeHandle shell_pipe) |
| 32 client.Open(); | 35 : shell_(shell_pipe.Pass()) { |
| 33 base::MessageLoop::current()->Run(); | 36 shell_.SetPeer(this); |
| 34 } | 37 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.
| |
| 38 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
| |
| 39 CreateMessagePipe(&client_handle, &app_handle); | |
| 40 native_viewport_client_.reset( | |
| 41 new NativeViewportClientImpl(client_handle.Pass())); | |
| 42 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
| |
| 43 } | |
| 44 | |
| 45 virtual void Connect(ScopedMessagePipeHandle handle) MOJO_OVERRIDE { | |
| 46 } | |
| 47 | |
| 48 private: | |
| 49 class NativeViewportClientImpl : public mojo::NativeViewportClientStub { | |
| 50 public: | |
| 51 explicit NativeViewportClientImpl(ScopedMessagePipeHandle client_handle) | |
| 52 : viewport_(client_handle.Pass()) { | |
| 53 viewport_.SetPeer(this); | |
| 54 viewport_->Open();; | |
|
darin (slow to review)
2013/12/10 06:12:36
nit: extra ";"
DaveMoore
2013/12/11 18:56:44
Done.
| |
| 55 ScopedMessagePipeHandle gles2; | |
| 56 ScopedMessagePipeHandle gles2_client; | |
| 57 CreateMessagePipe(&gles2, &gles2_client); | |
| 58 | |
| 59 gles2_client_.reset(new GLES2ClientImpl(gles2.Pass())); | |
| 60 viewport_->CreateGLES2Context(gles2_client.Pass()); | |
| 61 } | |
| 62 | |
| 63 virtual ~NativeViewportClientImpl() {} | |
| 64 | |
| 65 virtual void OnCreated() MOJO_OVERRIDE { | |
| 66 } | |
| 67 | |
| 68 virtual void OnDestroyed() MOJO_OVERRIDE { | |
| 69 base::MessageLoop::current()->Quit(); | |
| 70 } | |
| 71 | |
| 72 virtual void OnEvent(const Event& event) MOJO_OVERRIDE { | |
| 73 if (!event.location().is_null()) { | |
| 74 LOG(INFO) << "Located Event @" | |
| 75 << event.location().x() << "," << event.location().y(); | |
| 76 } | |
| 77 } | |
| 78 | |
| 79 private: | |
| 80 scoped_ptr<GLES2ClientImpl> gles2_client_; | |
| 81 RemotePtr<NativeViewport> viewport_; | |
| 82 }; | |
| 83 mojo::RemotePtr<shell::Shell> shell_; | |
| 84 scoped_ptr<NativeViewportClientImpl> native_viewport_client_; | |
| 85 }; | |
| 35 | 86 |
| 36 } // namespace examples | 87 } // namespace examples |
| 37 } // namespace mojo | 88 } // namespace mojo |
| 38 | 89 |
| 39 extern "C" SAMPLE_APP_EXPORT MojoResult CDECL MojoMain(MojoHandle pipe) { | 90 extern "C" SAMPLE_APP_EXPORT MojoResult CDECL MojoMain( |
| 91 MojoHandle shell_handle) { | |
| 40 base::MessageLoop loop; | 92 base::MessageLoop loop; |
| 41 mojo::common::BindingsSupportImpl bindings_support; | 93 mojo::common::BindingsSupportImpl bindings_support_impl; |
| 42 mojo::BindingsSupport::Set(&bindings_support); | 94 mojo::BindingsSupport::Set(&bindings_support_impl); |
| 43 MojoGLES2Initialize(); | 95 MojoGLES2Initialize(); |
| 44 | 96 |
| 45 mojo::ScopedMessagePipeHandle scoped_handle; | 97 mojo::examples::SampleApp app( |
| 46 scoped_handle.reset(mojo::MessagePipeHandle(pipe)); | 98 mojo::MakeScopedHandle(mojo::MessagePipeHandle(shell_handle)).Pass()); |
| 47 mojo::examples::Start(scoped_handle.Pass()); | 99 base::MessageLoop::current()->Run(); |
| 48 | 100 |
| 49 MojoGLES2Terminate(); | 101 MojoGLES2Terminate(); |
| 50 mojo::BindingsSupport::Set(NULL); | 102 mojo::BindingsSupport::Set(NULL); |
| 51 return MOJO_RESULT_OK; | 103 return MOJO_RESULT_OK; |
| 52 } | 104 } |
| OLD | NEW |