OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/macros.h" | 5 #include "base/macros.h" |
6 #include "base/memory/ref_counted.h" | 6 #include "base/memory/ref_counted.h" |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
10 #include "mojo/examples/pepper_container_app/mojo_ppapi_globals.h" | 10 #include "mojo/examples/pepper_container_app/mojo_ppapi_globals.h" |
11 #include "mojo/examples/pepper_container_app/plugin_instance.h" | 11 #include "mojo/examples/pepper_container_app/plugin_instance.h" |
12 #include "mojo/examples/pepper_container_app/plugin_module.h" | 12 #include "mojo/examples/pepper_container_app/plugin_module.h" |
13 #include "mojo/examples/pepper_container_app/type_converters.h" | 13 #include "mojo/examples/pepper_container_app/type_converters.h" |
14 #include "mojo/public/c/system/main.h" | 14 #include "mojo/public/c/system/main.h" |
15 #include "mojo/public/cpp/application/application_delegate.h" | 15 #include "mojo/public/cpp/application/application_delegate.h" |
16 #include "mojo/public/cpp/application/application_impl.h" | 16 #include "mojo/public/cpp/application/application_impl.h" |
17 #include "mojo/public/cpp/application/application_runner_chromium.h" | 17 #include "mojo/public/cpp/application/application_runner_chromium.h" |
18 #include "mojo/public/cpp/system/core.h" | 18 #include "mojo/public/cpp/system/core.h" |
| 19 #include "mojo/services/public/interfaces/geometry/geometry.mojom.h" |
19 #include "mojo/services/public/interfaces/gpu/gpu.mojom.h" | 20 #include "mojo/services/public/interfaces/gpu/gpu.mojom.h" |
20 #include "mojo/services/public/interfaces/native_viewport/native_viewport.mojom.
h" | 21 #include "mojo/services/public/interfaces/native_viewport/native_viewport.mojom.
h" |
21 #include "ppapi/c/pp_rect.h" | 22 #include "ppapi/c/pp_rect.h" |
22 #include "ppapi/shared_impl/proxy_lock.h" | 23 #include "ppapi/shared_impl/proxy_lock.h" |
23 | 24 |
24 namespace mojo { | 25 namespace mojo { |
25 namespace examples { | 26 namespace examples { |
26 | 27 |
27 class PepperContainerApp: public ApplicationDelegate, | 28 class PepperContainerApp: public ApplicationDelegate, |
28 public NativeViewportClient, | 29 public NativeViewportClient, |
29 public MojoPpapiGlobals::Delegate { | 30 public MojoPpapiGlobals::Delegate { |
30 public: | 31 public: |
31 explicit PepperContainerApp() | 32 explicit PepperContainerApp() |
32 : ppapi_globals_(this), | 33 : ppapi_globals_(this), |
33 plugin_module_(new PluginModule) {} | 34 plugin_module_(new PluginModule) {} |
34 | 35 |
35 virtual ~PepperContainerApp() {} | 36 virtual ~PepperContainerApp() {} |
36 | 37 |
37 virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE { | 38 virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE { |
38 app->ConnectToService("mojo:mojo_native_viewport_service", &viewport_); | 39 app->ConnectToService("mojo:mojo_native_viewport_service", &viewport_); |
39 viewport_.set_client(this); | 40 viewport_.set_client(this); |
40 | 41 |
41 // TODO(jamesr): Should be mojo:mojo_gpu_service | 42 // TODO(jamesr): Should be mojo:mojo_gpu_service |
42 app->ConnectToService("mojo:mojo_native_viewport_service", &gpu_service_); | 43 app->ConnectToService("mojo:mojo_native_viewport_service", &gpu_service_); |
43 | 44 |
44 RectPtr rect(Rect::New()); | 45 SizePtr size(Size::New()); |
45 rect->x = 10; | 46 size->width = 800; |
46 rect->y = 10; | 47 size->height = 600; |
47 rect->width = 800; | 48 viewport_->Create(size.Pass()); |
48 rect->height = 600; | |
49 viewport_->Create(rect.Pass()); | |
50 viewport_->Show(); | 49 viewport_->Show(); |
51 } | 50 } |
52 | 51 |
53 // NativeViewportClient implementation. | 52 // NativeViewportClient implementation. |
54 virtual void OnCreated(uint64_t native_viewport_id) OVERRIDE { | 53 virtual void OnCreated(uint64_t native_viewport_id) OVERRIDE { |
55 native_viewport_id_ = native_viewport_id; | 54 native_viewport_id_ = native_viewport_id; |
56 ppapi::ProxyAutoLock lock; | 55 ppapi::ProxyAutoLock lock; |
57 | 56 |
58 plugin_instance_ = plugin_module_->CreateInstance().Pass(); | 57 plugin_instance_ = plugin_module_->CreateInstance().Pass(); |
59 if (!plugin_instance_->DidCreate()) | 58 if (!plugin_instance_->DidCreate()) |
60 plugin_instance_.reset(); | 59 plugin_instance_.reset(); |
61 } | 60 } |
62 | 61 |
63 virtual void OnDestroyed() OVERRIDE { | 62 virtual void OnDestroyed() OVERRIDE { |
64 ppapi::ProxyAutoLock lock; | 63 ppapi::ProxyAutoLock lock; |
65 | 64 |
66 if (plugin_instance_) { | 65 if (plugin_instance_) { |
67 plugin_instance_->DidDestroy(); | 66 plugin_instance_->DidDestroy(); |
68 plugin_instance_.reset(); | 67 plugin_instance_.reset(); |
69 } | 68 } |
70 | 69 |
71 base::MessageLoop::current()->Quit(); | 70 base::MessageLoop::current()->Quit(); |
72 } | 71 } |
73 | 72 |
74 virtual void OnBoundsChanged(RectPtr bounds) OVERRIDE { | 73 virtual void OnBoundsChanged(SizePtr bounds) OVERRIDE { |
75 ppapi::ProxyAutoLock lock; | 74 ppapi::ProxyAutoLock lock; |
76 | 75 |
77 if (plugin_instance_) | 76 if (plugin_instance_) |
78 plugin_instance_->DidChangeView(bounds.To<PP_Rect>()); | 77 plugin_instance_->DidChangeView(bounds.To<PP_Rect>()); |
79 } | 78 } |
80 | 79 |
81 virtual void OnEvent(EventPtr event, | 80 virtual void OnEvent(EventPtr event, |
82 const mojo::Callback<void()>& callback) OVERRIDE { | 81 const mojo::Callback<void()>& callback) OVERRIDE { |
83 if (!event->location_data.is_null()) { | 82 if (!event->location_data.is_null()) { |
84 ppapi::ProxyAutoLock lock; | 83 ppapi::ProxyAutoLock lock; |
(...skipping 29 matching lines...) Expand all Loading... |
114 | 113 |
115 } // namespace examples | 114 } // namespace examples |
116 } // namespace mojo | 115 } // namespace mojo |
117 | 116 |
118 MojoResult MojoMain(MojoHandle shell_handle) { | 117 MojoResult MojoMain(MojoHandle shell_handle) { |
119 mojo::ApplicationRunnerChromium runner( | 118 mojo::ApplicationRunnerChromium runner( |
120 new mojo::examples::PepperContainerApp); | 119 new mojo::examples::PepperContainerApp); |
121 return runner.Run(shell_handle); | 120 return runner.Run(shell_handle); |
122 } | 121 } |
123 | 122 |
OLD | NEW |