| 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" | |
| 9 #include "mojo/common/bindings_support_impl.h" | |
| 10 #include "mojo/examples/sample_app/gles2_client_impl.h" | 8 #include "mojo/examples/sample_app/gles2_client_impl.h" |
| 11 #include "mojo/public/bindings/lib/bindings_support.h" | 9 #include "mojo/public/bindings/lib/bindings_support.h" |
| 12 #include "mojo/public/bindings/lib/remote_ptr.h" | 10 #include "mojo/public/bindings/lib/remote_ptr.h" |
| 13 #include "mojo/public/gles2/gles2.h" | 11 #include "mojo/public/gles2/gles2.h" |
| 14 #include "mojo/public/system/core.h" | 12 #include "mojo/public/system/core.h" |
| 15 #include "mojo/public/system/macros.h" | 13 #include "mojo/public/system/macros.h" |
| 14 #include "mojo/public/utility/environment.h" |
| 15 #include "mojo/public/utility/run_loop.h" |
| 16 #include "mojom/native_viewport.h" | 16 #include "mojom/native_viewport.h" |
| 17 #include "mojom/shell.h" | 17 #include "mojom/shell.h" |
| 18 | 18 |
| 19 #if defined(WIN32) | 19 #if defined(WIN32) |
| 20 #if !defined(CDECL) | 20 #if !defined(CDECL) |
| 21 #define CDECL __cdecl | 21 #define CDECL __cdecl |
| 22 #endif | 22 #endif |
| 23 #define SAMPLE_APP_EXPORT __declspec(dllexport) | 23 #define SAMPLE_APP_EXPORT __declspec(dllexport) |
| 24 #else | 24 #else |
| 25 #define CDECL | 25 #define CDECL |
| 26 #define SAMPLE_APP_EXPORT __attribute__((visibility("default"))) | 26 #define SAMPLE_APP_EXPORT __attribute__((visibility("default"))) |
| 27 #endif | 27 #endif |
| 28 | 28 |
| 29 namespace mojo { | 29 namespace mojo { |
| 30 namespace examples { | 30 namespace examples { |
| 31 | 31 |
| 32 class SampleApp : public ShellClient { | 32 class SampleApp : public ShellClient { |
| 33 public: | 33 public: |
| 34 explicit SampleApp(ScopedMessagePipeHandle shell_handle) | 34 explicit SampleApp(ScopedMessagePipeHandle shell_handle) |
| 35 : shell_(shell_handle.Pass(), this) { | 35 : shell_(shell_handle.Pass(), this) { |
| 36 | 36 |
| 37 MessagePipe pipe; | 37 MessagePipe pipe; |
| 38 native_viewport_client_.reset( | 38 native_viewport_client_.reset( |
| 39 new NativeViewportClientImpl(pipe.handle0.Pass())); | 39 new NativeViewportClientImpl(pipe.handle0.Pass())); |
| 40 mojo::AllocationScope scope; | 40 mojo::AllocationScope scope; |
| 41 shell_->Connect("mojo:mojo_native_viewport_service", pipe.handle1.Pass()); | 41 shell_->Connect("mojo:mojo_native_viewport_service", pipe.handle1.Pass()); |
| 42 } | 42 } |
| 43 | 43 |
| 44 virtual void AcceptConnection(ScopedMessagePipeHandle handle) MOJO_OVERRIDE { | 44 virtual void AcceptConnection(ScopedMessagePipeHandle handle) MOJO_OVERRIDE { |
| 45 NOTREACHED() << "SampleApp can't be connected to."; | |
| 46 } | 45 } |
| 47 | 46 |
| 48 private: | 47 private: |
| 49 class NativeViewportClientImpl : public mojo::NativeViewportClient { | 48 class NativeViewportClientImpl : public mojo::NativeViewportClient { |
| 50 public: | 49 public: |
| 51 explicit NativeViewportClientImpl(ScopedMessagePipeHandle viewport_handle) | 50 explicit NativeViewportClientImpl(ScopedMessagePipeHandle viewport_handle) |
| 52 : viewport_(viewport_handle.Pass(), this) { | 51 : viewport_(viewport_handle.Pass(), this) { |
| 53 viewport_->Open(); | 52 viewport_->Open(); |
| 54 | 53 |
| 55 MessagePipe pipe; | 54 MessagePipe pipe; |
| 56 gles2_client_.reset(new GLES2ClientImpl(pipe.handle0.Pass())); | 55 gles2_client_.reset(new GLES2ClientImpl(pipe.handle0.Pass())); |
| 57 viewport_->CreateGLES2Context(pipe.handle1.Pass()); | 56 viewport_->CreateGLES2Context(pipe.handle1.Pass()); |
| 58 } | 57 } |
| 59 | 58 |
| 60 virtual ~NativeViewportClientImpl() {} | 59 virtual ~NativeViewportClientImpl() {} |
| 61 | 60 |
| 62 virtual void OnCreated() MOJO_OVERRIDE { | 61 virtual void OnCreated() MOJO_OVERRIDE { |
| 63 } | 62 } |
| 64 | 63 |
| 65 virtual void OnDestroyed() MOJO_OVERRIDE { | 64 virtual void OnDestroyed() MOJO_OVERRIDE { |
| 66 base::MessageLoop::current()->Quit(); | 65 utility::RunLoop::current()->Quit(); |
| 67 } | 66 } |
| 68 | 67 |
| 69 virtual void OnEvent(const Event& event) MOJO_OVERRIDE { | 68 virtual void OnEvent(const Event& event) MOJO_OVERRIDE { |
| 70 if (!event.location().is_null()) { | 69 if (!event.location().is_null()) { |
| 71 gles2_client_->HandleInputEvent(event); | 70 gles2_client_->HandleInputEvent(event); |
| 72 viewport_->AckEvent(event); | 71 viewport_->AckEvent(event); |
| 73 } | 72 } |
| 74 } | 73 } |
| 75 | 74 |
| 76 private: | 75 private: |
| 77 scoped_ptr<GLES2ClientImpl> gles2_client_; | 76 scoped_ptr<GLES2ClientImpl> gles2_client_; |
| 78 RemotePtr<NativeViewport> viewport_; | 77 RemotePtr<NativeViewport> viewport_; |
| 79 }; | 78 }; |
| 80 mojo::RemotePtr<Shell> shell_; | 79 mojo::RemotePtr<Shell> shell_; |
| 81 scoped_ptr<NativeViewportClientImpl> native_viewport_client_; | 80 scoped_ptr<NativeViewportClientImpl> native_viewport_client_; |
| 82 }; | 81 }; |
| 83 | 82 |
| 84 } // namespace examples | 83 } // namespace examples |
| 85 } // namespace mojo | 84 } // namespace mojo |
| 86 | 85 |
| 87 extern "C" SAMPLE_APP_EXPORT MojoResult CDECL MojoMain( | 86 extern "C" SAMPLE_APP_EXPORT MojoResult CDECL MojoMain( |
| 88 MojoHandle shell_handle) { | 87 MojoHandle shell_handle) { |
| 89 base::MessageLoop loop; | 88 mojo::utility::Environment env; |
| 90 mojo::common::BindingsSupportImpl bindings_support_impl; | 89 mojo::utility::RunLoop loop; |
| 91 mojo::BindingsSupport::Set(&bindings_support_impl); | |
| 92 MojoGLES2Initialize(); | 90 MojoGLES2Initialize(); |
| 93 | 91 |
| 94 mojo::examples::SampleApp app( | 92 mojo::examples::SampleApp app( |
| 95 mojo::MakeScopedHandle(mojo::MessagePipeHandle(shell_handle)).Pass()); | 93 mojo::MakeScopedHandle(mojo::MessagePipeHandle(shell_handle)).Pass()); |
| 96 loop.Run(); | 94 loop.Run(); |
| 97 | 95 |
| 98 MojoGLES2Terminate(); | 96 MojoGLES2Terminate(); |
| 99 mojo::BindingsSupport::Set(NULL); | 97 mojo::BindingsSupport::Set(NULL); |
| 100 return MOJO_RESULT_OK; | 98 return MOJO_RESULT_OK; |
| 101 } | 99 } |
| OLD | NEW |