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/c/system/main.h" | 9 #include "mojo/public/c/system/main.h" |
10 #include "mojo/public/cpp/application/application_connection.h" | 10 #include "mojo/public/cpp/application/application_connection.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 MOJO_ALLOW_UNUSED GLES2ClientImpl* leaked = gles2_client_.release(); | 29 MOJO_ALLOW_UNUSED GLES2ClientImpl* leaked = gles2_client_.release(); |
30 } | 30 } |
31 | 31 |
32 virtual void Initialize(mojo::ApplicationImpl* app) MOJO_OVERRIDE { | 32 virtual void Initialize(mojo::ApplicationImpl* app) MOJO_OVERRIDE { |
33 app->ConnectToService("mojo:mojo_native_viewport_service", &viewport_); | 33 app->ConnectToService("mojo:mojo_native_viewport_service", &viewport_); |
34 viewport_.set_client(this); | 34 viewport_.set_client(this); |
35 | 35 |
36 // TODO(jamesr): Should be mojo:mojo_gpu_service | 36 // TODO(jamesr): Should be mojo:mojo_gpu_service |
37 app->ConnectToService("mojo:mojo_native_viewport_service", &gpu_service_); | 37 app->ConnectToService("mojo:mojo_native_viewport_service", &gpu_service_); |
38 | 38 |
39 mojo::RectPtr rect(mojo::Rect::New()); | 39 mojo::SizePtr size(mojo::Size::New()); |
40 rect->x = 10; | 40 size->width = 800; |
41 rect->y = 10; | 41 size->height = 600; |
42 rect->width = 800; | 42 viewport_->Create(size.Pass()); |
43 rect->height = 600; | |
44 viewport_->Create(rect.Pass()); | |
45 viewport_->Show(); | 43 viewport_->Show(); |
46 } | 44 } |
47 | 45 |
48 virtual void OnCreated(uint64_t native_viewport_id) MOJO_OVERRIDE { | 46 virtual void OnCreated(uint64_t native_viewport_id) MOJO_OVERRIDE { |
49 mojo::SizePtr size = mojo::Size::New(); | 47 mojo::SizePtr size = mojo::Size::New(); |
50 size->width = 800; | 48 size->width = 800; |
51 size->height = 600; | 49 size->height = 600; |
52 mojo::CommandBufferPtr command_buffer; | 50 mojo::CommandBufferPtr command_buffer; |
53 // TODO(jamesr): Output to a surface instead. | 51 // TODO(jamesr): Output to a surface instead. |
54 gpu_service_->CreateOnscreenGLES2Context( | 52 gpu_service_->CreateOnscreenGLES2Context( |
55 native_viewport_id, size.Pass(), Get(&command_buffer)); | 53 native_viewport_id, size.Pass(), Get(&command_buffer)); |
56 gles2_client_.reset(new GLES2ClientImpl(command_buffer.Pass())); | 54 gles2_client_.reset(new GLES2ClientImpl(command_buffer.Pass())); |
57 } | 55 } |
58 | 56 |
59 virtual void OnDestroyed() MOJO_OVERRIDE { mojo::RunLoop::current()->Quit(); } | 57 virtual void OnDestroyed() MOJO_OVERRIDE { mojo::RunLoop::current()->Quit(); } |
60 | 58 |
61 virtual void OnBoundsChanged(mojo::RectPtr bounds) MOJO_OVERRIDE { | 59 virtual void OnBoundsChanged(mojo::SizePtr bounds) MOJO_OVERRIDE { |
62 assert(bounds); | 60 assert(bounds); |
63 mojo::SizePtr size(mojo::Size::New()); | |
64 size->width = bounds->width; | |
65 size->height = bounds->height; | |
66 if (gles2_client_) | 61 if (gles2_client_) |
67 gles2_client_->SetSize(*size); | 62 gles2_client_->SetSize(*bounds); |
68 } | 63 } |
69 | 64 |
70 virtual void OnEvent(mojo::EventPtr event, | 65 virtual void OnEvent(mojo::EventPtr event, |
71 const mojo::Callback<void()>& callback) MOJO_OVERRIDE { | 66 const mojo::Callback<void()>& callback) MOJO_OVERRIDE { |
72 assert(event); | 67 assert(event); |
73 if (event->location_data && event->location_data->in_view_location) | 68 if (event->location_data && event->location_data->in_view_location) |
74 gles2_client_->HandleInputEvent(*event); | 69 gles2_client_->HandleInputEvent(*event); |
75 callback.Run(); | 70 callback.Run(); |
76 } | 71 } |
77 | 72 |
78 private: | 73 private: |
79 scoped_ptr<GLES2ClientImpl> gles2_client_; | 74 scoped_ptr<GLES2ClientImpl> gles2_client_; |
80 mojo::NativeViewportPtr viewport_; | 75 mojo::NativeViewportPtr viewport_; |
81 mojo::GpuPtr gpu_service_; | 76 mojo::GpuPtr gpu_service_; |
82 | 77 |
83 DISALLOW_COPY_AND_ASSIGN(SampleApp); | 78 DISALLOW_COPY_AND_ASSIGN(SampleApp); |
84 }; | 79 }; |
85 | 80 |
86 } // namespace examples | 81 } // namespace examples |
87 | 82 |
88 MojoResult MojoMain(MojoHandle shell_handle) { | 83 MojoResult MojoMain(MojoHandle shell_handle) { |
89 mojo::ApplicationRunner runner(new examples::SampleApp); | 84 mojo::ApplicationRunner runner(new examples::SampleApp); |
90 return runner.Run(shell_handle); | 85 return runner.Run(shell_handle); |
91 } | 86 } |
OLD | NEW |