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/cpp/bindings/allocation_scope.h" | |
15 #include "mojo/public/cpp/environment/environment.h" | 14 #include "mojo/public/cpp/environment/environment.h" |
16 #include "mojo/public/cpp/gles2/gles2.h" | 15 #include "mojo/public/cpp/gles2/gles2.h" |
17 #include "mojo/public/cpp/shell/application.h" | 16 #include "mojo/public/cpp/shell/application.h" |
18 #include "mojo/public/cpp/system/core.h" | 17 #include "mojo/public/cpp/system/core.h" |
19 #include "mojo/public/interfaces/shell/shell.mojom.h" | 18 #include "mojo/public/interfaces/shell/shell.mojom.h" |
20 #include "mojo/services/native_viewport/native_viewport.mojom.h" | 19 #include "mojo/services/native_viewport/native_viewport.mojom.h" |
21 #include "ppapi/c/pp_rect.h" | 20 #include "ppapi/c/pp_rect.h" |
22 #include "ppapi/shared_impl/proxy_lock.h" | 21 #include "ppapi/shared_impl/proxy_lock.h" |
23 | 22 |
24 #if defined(OS_WIN) | 23 #if defined(OS_WIN) |
(...skipping 10 matching lines...) Expand all Loading... |
35 namespace examples { | 34 namespace examples { |
36 | 35 |
37 class PepperContainerApp: public Application, | 36 class PepperContainerApp: public Application, |
38 public NativeViewportClient, | 37 public NativeViewportClient, |
39 public MojoPpapiGlobals::Delegate { | 38 public MojoPpapiGlobals::Delegate { |
40 public: | 39 public: |
41 explicit PepperContainerApp(MojoHandle shell_handle) | 40 explicit PepperContainerApp(MojoHandle shell_handle) |
42 : Application(shell_handle), | 41 : Application(shell_handle), |
43 ppapi_globals_(this), | 42 ppapi_globals_(this), |
44 plugin_module_(new PluginModule) { | 43 plugin_module_(new PluginModule) { |
45 mojo::AllocationScope scope; | |
46 | |
47 ConnectTo("mojo:mojo_native_viewport_service", &viewport_); | 44 ConnectTo("mojo:mojo_native_viewport_service", &viewport_); |
48 viewport_->SetClient(this); | 45 viewport_->SetClient(this); |
49 | 46 |
50 Rect::Builder rect; | 47 RectPtr rect(Rect::New()); |
51 Point::Builder point; | 48 rect->position = Point::New(); |
52 point.set_x(10); | 49 rect->position->x = 10; |
53 point.set_y(10); | 50 rect->position->y = 10; |
54 rect.set_position(point.Finish()); | 51 rect->size = Size::New(); |
55 Size::Builder size; | 52 rect->size->width = 800; |
56 size.set_width(800); | 53 rect->size->height = 600; |
57 size.set_height(600); | 54 viewport_->Create(rect.Pass()); |
58 rect.set_size(size.Finish()); | |
59 viewport_->Create(rect.Finish()); | |
60 viewport_->Show(); | 55 viewport_->Show(); |
61 } | 56 } |
62 | 57 |
63 virtual ~PepperContainerApp() {} | 58 virtual ~PepperContainerApp() {} |
64 | 59 |
65 // NativeViewportClient implementation. | 60 // NativeViewportClient implementation. |
66 virtual void OnCreated() OVERRIDE { | 61 virtual void OnCreated() OVERRIDE { |
67 ppapi::ProxyAutoLock lock; | 62 ppapi::ProxyAutoLock lock; |
68 | 63 |
69 plugin_instance_ = plugin_module_->CreateInstance().Pass(); | 64 plugin_instance_ = plugin_module_->CreateInstance().Pass(); |
70 if (!plugin_instance_->DidCreate()) | 65 if (!plugin_instance_->DidCreate()) |
71 plugin_instance_.reset(); | 66 plugin_instance_.reset(); |
72 } | 67 } |
73 | 68 |
74 virtual void OnDestroyed() OVERRIDE { | 69 virtual void OnDestroyed() OVERRIDE { |
75 ppapi::ProxyAutoLock lock; | 70 ppapi::ProxyAutoLock lock; |
76 | 71 |
77 if (plugin_instance_) { | 72 if (plugin_instance_) { |
78 plugin_instance_->DidDestroy(); | 73 plugin_instance_->DidDestroy(); |
79 plugin_instance_.reset(); | 74 plugin_instance_.reset(); |
80 } | 75 } |
81 | 76 |
82 base::MessageLoop::current()->Quit(); | 77 base::MessageLoop::current()->Quit(); |
83 } | 78 } |
84 | 79 |
85 virtual void OnBoundsChanged(const Rect& bounds) OVERRIDE { | 80 virtual void OnBoundsChanged(RectPtr bounds) OVERRIDE { |
86 ppapi::ProxyAutoLock lock; | 81 ppapi::ProxyAutoLock lock; |
87 | 82 |
88 if (plugin_instance_) | 83 if (plugin_instance_) |
89 plugin_instance_->DidChangeView(bounds); | 84 plugin_instance_->DidChangeView(bounds.To<PP_Rect>()); |
90 } | 85 } |
91 | 86 |
92 virtual void OnEvent(const Event& event, | 87 virtual void OnEvent(EventPtr event, |
93 const mojo::Callback<void()>& callback) OVERRIDE { | 88 const mojo::Callback<void()>& callback) OVERRIDE { |
94 if (!event.location().is_null()) { | 89 if (!event->location.is_null()) { |
95 ppapi::ProxyAutoLock lock; | 90 ppapi::ProxyAutoLock lock; |
96 | 91 |
97 // TODO(yzshen): Handle events. | 92 // TODO(yzshen): Handle events. |
98 } | 93 } |
99 callback.Run(); | 94 callback.Run(); |
100 } | 95 } |
101 | 96 |
102 // MojoPpapiGlobals::Delegate implementation. | 97 // MojoPpapiGlobals::Delegate implementation. |
103 virtual ScopedMessagePipeHandle CreateGLES2Context() OVERRIDE { | 98 virtual ScopedMessagePipeHandle CreateGLES2Context() OVERRIDE { |
104 MessagePipe gles2_pipe; | 99 MessagePipe gles2_pipe; |
(...skipping 17 matching lines...) Expand all Loading... |
122 extern "C" PEPPER_CONTAINER_APP_EXPORT MojoResult CDECL MojoMain( | 117 extern "C" PEPPER_CONTAINER_APP_EXPORT MojoResult CDECL MojoMain( |
123 MojoHandle shell_handle) { | 118 MojoHandle shell_handle) { |
124 mojo::Environment env; | 119 mojo::Environment env; |
125 mojo::GLES2Initializer gles2; | 120 mojo::GLES2Initializer gles2; |
126 base::MessageLoop run_loop; | 121 base::MessageLoop run_loop; |
127 mojo::examples::PepperContainerApp app(shell_handle); | 122 mojo::examples::PepperContainerApp app(shell_handle); |
128 | 123 |
129 run_loop.Run(); | 124 run_loop.Run(); |
130 return MOJO_RESULT_OK; | 125 return MOJO_RESULT_OK; |
131 } | 126 } |
OLD | NEW |