| 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 "mojo/examples/sample_app/gles2_client_impl.h" | 8 #include "mojo/examples/sample_app/gles2_client_impl.h" |
| 9 #include "mojo/public/cpp/bindings/allocation_scope.h" | |
| 10 #include "mojo/public/cpp/environment/environment.h" | 9 #include "mojo/public/cpp/environment/environment.h" |
| 11 #include "mojo/public/cpp/gles2/gles2.h" | 10 #include "mojo/public/cpp/gles2/gles2.h" |
| 12 #include "mojo/public/cpp/shell/application.h" | 11 #include "mojo/public/cpp/shell/application.h" |
| 13 #include "mojo/public/cpp/system/core.h" | 12 #include "mojo/public/cpp/system/core.h" |
| 14 #include "mojo/public/cpp/system/macros.h" | 13 #include "mojo/public/cpp/system/macros.h" |
| 15 #include "mojo/public/cpp/utility/run_loop.h" | 14 #include "mojo/public/cpp/utility/run_loop.h" |
| 16 #include "mojo/public/interfaces/shell/shell.mojom.h" | 15 #include "mojo/public/interfaces/shell/shell.mojom.h" |
| 17 #include "mojo/services/native_viewport/native_viewport.mojom.h" | 16 #include "mojo/services/native_viewport/native_viewport.mojom.h" |
| 18 | 17 |
| 19 #if defined(WIN32) | 18 #if defined(WIN32) |
| 20 #if !defined(CDECL) | 19 #if !defined(CDECL) |
| 21 #define CDECL __cdecl | 20 #define CDECL __cdecl |
| 22 #endif | 21 #endif |
| 23 #define SAMPLE_APP_EXPORT __declspec(dllexport) | 22 #define SAMPLE_APP_EXPORT __declspec(dllexport) |
| 24 #else | 23 #else |
| 25 #define CDECL | 24 #define CDECL |
| 26 #define SAMPLE_APP_EXPORT __attribute__((visibility("default"))) | 25 #define SAMPLE_APP_EXPORT __attribute__((visibility("default"))) |
| 27 #endif | 26 #endif |
| 28 | 27 |
| 29 namespace mojo { | 28 namespace mojo { |
| 30 namespace examples { | 29 namespace examples { |
| 31 | 30 |
| 32 class SampleApp : public Application, public NativeViewportClient { | 31 class SampleApp : public Application, public NativeViewportClient { |
| 33 public: | 32 public: |
| 34 explicit SampleApp(MojoHandle shell_handle) : Application(shell_handle) { | 33 explicit SampleApp(MojoHandle shell_handle) : Application(shell_handle) { |
| 35 ConnectTo("mojo:mojo_native_viewport_service", &viewport_); | 34 ConnectTo("mojo:mojo_native_viewport_service", &viewport_); |
| 36 viewport_.set_client(this); | 35 viewport_.set_client(this); |
| 37 | 36 |
| 38 AllocationScope scope; | 37 RectPtr rect(Rect::New()); |
| 39 | 38 rect->position = Point::New(); |
| 40 Rect::Builder rect; | 39 rect->position->x = 10; |
| 41 Point::Builder point; | 40 rect->position->y = 10; |
| 42 point.set_x(10); | 41 rect->size = Size::New(); |
| 43 point.set_y(10); | 42 rect->size->width = 800; |
| 44 rect.set_position(point.Finish()); | 43 rect->size->height = 600; |
| 45 Size::Builder size; | 44 viewport_->Create(rect.Pass()); |
| 46 size.set_width(800); | |
| 47 size.set_height(600); | |
| 48 rect.set_size(size.Finish()); | |
| 49 viewport_->Create(rect.Finish()); | |
| 50 viewport_->Show(); | 45 viewport_->Show(); |
| 51 | 46 |
| 52 MessagePipe gles2_pipe; | 47 MessagePipe gles2_pipe; |
| 53 viewport_->CreateGLES2Context(gles2_pipe.handle0.Pass()); | 48 viewport_->CreateGLES2Context(gles2_pipe.handle0.Pass()); |
| 54 gles2_client_.reset(new GLES2ClientImpl(gles2_pipe.handle1.Pass())); | 49 gles2_client_.reset(new GLES2ClientImpl(gles2_pipe.handle1.Pass())); |
| 55 } | 50 } |
| 56 | 51 |
| 57 virtual ~SampleApp() { | 52 virtual ~SampleApp() { |
| 58 // TODO(darin): Fix shutdown so we don't need to leak this. | 53 // TODO(darin): Fix shutdown so we don't need to leak this. |
| 59 MOJO_ALLOW_UNUSED GLES2ClientImpl* leaked = gles2_client_.release(); | 54 MOJO_ALLOW_UNUSED GLES2ClientImpl* leaked = gles2_client_.release(); |
| 60 } | 55 } |
| 61 | 56 |
| 62 virtual void OnCreated() MOJO_OVERRIDE { | 57 virtual void OnCreated() MOJO_OVERRIDE { |
| 63 } | 58 } |
| 64 | 59 |
| 65 virtual void OnDestroyed() MOJO_OVERRIDE { | 60 virtual void OnDestroyed() MOJO_OVERRIDE { |
| 66 RunLoop::current()->Quit(); | 61 RunLoop::current()->Quit(); |
| 67 } | 62 } |
| 68 | 63 |
| 69 virtual void OnBoundsChanged(const Rect& bounds) MOJO_OVERRIDE { | 64 virtual void OnBoundsChanged(RectPtr bounds) MOJO_OVERRIDE { |
| 70 gles2_client_->SetSize(bounds.size()); | 65 assert(bounds); |
| 66 assert(bounds->size); |
| 67 gles2_client_->SetSize(*bounds->size); |
| 71 } | 68 } |
| 72 | 69 |
| 73 virtual void OnEvent(const Event& event, | 70 virtual void OnEvent(EventPtr event, |
| 74 const Callback<void()>& callback) MOJO_OVERRIDE { | 71 const Callback<void()>& callback) MOJO_OVERRIDE { |
| 75 if (!event.location().is_null()) | 72 assert(event); |
| 76 gles2_client_->HandleInputEvent(event); | 73 if (event->location) |
| 74 gles2_client_->HandleInputEvent(*event); |
| 77 callback.Run(); | 75 callback.Run(); |
| 78 } | 76 } |
| 79 | 77 |
| 80 private: | 78 private: |
| 81 scoped_ptr<GLES2ClientImpl> gles2_client_; | 79 scoped_ptr<GLES2ClientImpl> gles2_client_; |
| 82 NativeViewportPtr viewport_; | 80 NativeViewportPtr viewport_; |
| 83 }; | 81 }; |
| 84 | 82 |
| 85 } // namespace examples | 83 } // namespace examples |
| 86 } // namespace mojo | 84 } // namespace mojo |
| 87 | 85 |
| 88 extern "C" SAMPLE_APP_EXPORT MojoResult CDECL MojoMain( | 86 extern "C" SAMPLE_APP_EXPORT MojoResult CDECL MojoMain( |
| 89 MojoHandle shell_handle) { | 87 MojoHandle shell_handle) { |
| 90 mojo::Environment env; | 88 mojo::Environment env; |
| 91 mojo::RunLoop loop; | 89 mojo::RunLoop loop; |
| 92 mojo::GLES2Initializer gles2; | 90 mojo::GLES2Initializer gles2; |
| 93 | 91 |
| 94 mojo::examples::SampleApp app(shell_handle); | 92 mojo::examples::SampleApp app(shell_handle); |
| 95 loop.Run(); | 93 loop.Run(); |
| 96 return MOJO_RESULT_OK; | 94 return MOJO_RESULT_OK; |
| 97 } | 95 } |
| OLD | NEW |