| 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/application/application_connection.h" | 9 #include "mojo/public/cpp/application/application_connection.h" |
| 10 #include "mojo/public/cpp/application/application_delegate.h" | 10 #include "mojo/public/cpp/application/application_delegate.h" |
| 11 #include "mojo/public/cpp/application/application_impl.h" | 11 #include "mojo/public/cpp/application/application_impl.h" |
| 12 #include "mojo/public/cpp/system/core.h" | 12 #include "mojo/public/cpp/system/core.h" |
| 13 #include "mojo/public/cpp/system/macros.h" | 13 #include "mojo/public/cpp/system/macros.h" |
| 14 #include "mojo/public/cpp/utility/run_loop.h" | 14 #include "mojo/public/cpp/utility/run_loop.h" |
| 15 #include "mojo/services/public/interfaces/gpu/gpu.mojom.h" |
| 15 #include "mojo/services/public/interfaces/native_viewport/native_viewport.mojom.
h" | 16 #include "mojo/services/public/interfaces/native_viewport/native_viewport.mojom.
h" |
| 16 | 17 |
| 17 namespace examples { | 18 namespace examples { |
| 18 | 19 |
| 19 class SampleApp : public mojo::ApplicationDelegate, | 20 class SampleApp : public mojo::ApplicationDelegate, |
| 20 public mojo::NativeViewportClient { | 21 public mojo::NativeViewportClient { |
| 21 public: | 22 public: |
| 22 SampleApp() {} | 23 SampleApp() {} |
| 23 | 24 |
| 24 virtual ~SampleApp() { | 25 virtual ~SampleApp() { |
| 25 // TODO(darin): Fix shutdown so we don't need to leak this. | 26 // TODO(darin): Fix shutdown so we don't need to leak this. |
| 26 MOJO_ALLOW_UNUSED GLES2ClientImpl* leaked = gles2_client_.release(); | 27 MOJO_ALLOW_UNUSED GLES2ClientImpl* leaked = gles2_client_.release(); |
| 27 } | 28 } |
| 28 | 29 |
| 29 virtual void Initialize(mojo::ApplicationImpl* app) MOJO_OVERRIDE { | 30 virtual void Initialize(mojo::ApplicationImpl* app) MOJO_OVERRIDE { |
| 30 app->ConnectToService("mojo:mojo_native_viewport_service", &viewport_); | 31 app->ConnectToService("mojo:mojo_native_viewport_service", &viewport_); |
| 31 viewport_.set_client(this); | 32 viewport_.set_client(this); |
| 32 | 33 |
| 34 // TODO(jamesr): Should be mojo:mojo_gpu_service |
| 35 app->ConnectToService("mojo:mojo_native_viewport_service", &gpu_service_); |
| 36 |
| 33 mojo::RectPtr rect(mojo::Rect::New()); | 37 mojo::RectPtr rect(mojo::Rect::New()); |
| 34 rect->x = 10; | 38 rect->x = 10; |
| 35 rect->y = 10; | 39 rect->y = 10; |
| 36 rect->width = 800; | 40 rect->width = 800; |
| 37 rect->height = 600; | 41 rect->height = 600; |
| 38 viewport_->Create(rect.Pass()); | 42 viewport_->Create(rect.Pass()); |
| 39 viewport_->Show(); | 43 viewport_->Show(); |
| 44 } |
| 40 | 45 |
| 46 virtual void OnCreated(uint64_t native_viewport_id) MOJO_OVERRIDE { |
| 47 mojo::SizePtr size = mojo::Size::New(); |
| 48 size->width = 800; |
| 49 size->height = 600; |
| 41 mojo::CommandBufferPtr command_buffer; | 50 mojo::CommandBufferPtr command_buffer; |
| 42 viewport_->CreateGLES2Context(Get(&command_buffer)); | 51 gpu_service_->CreateOnscreenGLES2Context( |
| 52 native_viewport_id, size.Pass(), Get(&command_buffer)); |
| 43 gles2_client_.reset(new GLES2ClientImpl(command_buffer.Pass())); | 53 gles2_client_.reset(new GLES2ClientImpl(command_buffer.Pass())); |
| 44 } | 54 } |
| 45 | 55 |
| 46 virtual void OnCreated() MOJO_OVERRIDE { | 56 virtual void OnDestroyed() MOJO_OVERRIDE { mojo::RunLoop::current()->Quit(); } |
| 47 } | |
| 48 | |
| 49 virtual void OnDestroyed( | |
| 50 const mojo::Callback<void()>& callback) MOJO_OVERRIDE { | |
| 51 mojo::RunLoop::current()->Quit(); | |
| 52 callback.Run(); | |
| 53 } | |
| 54 | 57 |
| 55 virtual void OnBoundsChanged(mojo::RectPtr bounds) MOJO_OVERRIDE { | 58 virtual void OnBoundsChanged(mojo::RectPtr bounds) MOJO_OVERRIDE { |
| 56 assert(bounds); | 59 assert(bounds); |
| 57 mojo::SizePtr size(mojo::Size::New()); | 60 mojo::SizePtr size(mojo::Size::New()); |
| 58 size->width = bounds->width; | 61 size->width = bounds->width; |
| 59 size->height = bounds->height; | 62 size->height = bounds->height; |
| 60 gles2_client_->SetSize(*size); | 63 if (gles2_client_) |
| 64 gles2_client_->SetSize(*size); |
| 61 } | 65 } |
| 62 | 66 |
| 63 virtual void OnEvent(mojo::EventPtr event, | 67 virtual void OnEvent(mojo::EventPtr event, |
| 64 const mojo::Callback<void()>& callback) MOJO_OVERRIDE { | 68 const mojo::Callback<void()>& callback) MOJO_OVERRIDE { |
| 65 assert(event); | 69 assert(event); |
| 66 if (event->location_data && event->location_data->in_view_location) | 70 if (event->location_data && event->location_data->in_view_location) |
| 67 gles2_client_->HandleInputEvent(*event); | 71 gles2_client_->HandleInputEvent(*event); |
| 68 callback.Run(); | 72 callback.Run(); |
| 69 } | 73 } |
| 70 | 74 |
| 71 private: | 75 private: |
| 72 scoped_ptr<GLES2ClientImpl> gles2_client_; | 76 scoped_ptr<GLES2ClientImpl> gles2_client_; |
| 73 mojo::NativeViewportPtr viewport_; | 77 mojo::NativeViewportPtr viewport_; |
| 78 mojo::GpuPtr gpu_service_; |
| 74 | 79 |
| 75 DISALLOW_COPY_AND_ASSIGN(SampleApp); | 80 DISALLOW_COPY_AND_ASSIGN(SampleApp); |
| 76 }; | 81 }; |
| 77 | 82 |
| 78 } // namespace examples | 83 } // namespace examples |
| 79 | 84 |
| 80 namespace mojo { | 85 namespace mojo { |
| 81 | 86 |
| 82 // static | 87 // static |
| 83 ApplicationDelegate* ApplicationDelegate::Create() { | 88 ApplicationDelegate* ApplicationDelegate::Create() { |
| 84 return new examples::SampleApp(); | 89 return new examples::SampleApp(); |
| 85 } | 90 } |
| 86 | 91 |
| 87 } // namespace mojo | 92 } // namespace mojo |
| OLD | NEW |