Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: mojo/examples/pepper_container_app/pepper_container_app.cc

Issue 607233002: Nukes NativeViewportClient::OnCreated (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix build Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/examples/compositor_app/compositor_app.cc ('k') | mojo/examples/sample_app/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/memory/weak_ptr.h"
8 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
9 #include "build/build_config.h" 10 #include "build/build_config.h"
10 #include "mojo/application/application_runner_chromium.h" 11 #include "mojo/application/application_runner_chromium.h"
11 #include "mojo/examples/pepper_container_app/mojo_ppapi_globals.h" 12 #include "mojo/examples/pepper_container_app/mojo_ppapi_globals.h"
12 #include "mojo/examples/pepper_container_app/plugin_instance.h" 13 #include "mojo/examples/pepper_container_app/plugin_instance.h"
13 #include "mojo/examples/pepper_container_app/plugin_module.h" 14 #include "mojo/examples/pepper_container_app/plugin_module.h"
14 #include "mojo/examples/pepper_container_app/type_converters.h" 15 #include "mojo/examples/pepper_container_app/type_converters.h"
15 #include "mojo/public/c/system/main.h" 16 #include "mojo/public/c/system/main.h"
16 #include "mojo/public/cpp/application/application_delegate.h" 17 #include "mojo/public/cpp/application/application_delegate.h"
17 #include "mojo/public/cpp/application/application_impl.h" 18 #include "mojo/public/cpp/application/application_impl.h"
18 #include "mojo/public/cpp/system/core.h" 19 #include "mojo/public/cpp/system/core.h"
19 #include "mojo/services/public/interfaces/geometry/geometry.mojom.h" 20 #include "mojo/services/public/interfaces/geometry/geometry.mojom.h"
20 #include "mojo/services/public/interfaces/gpu/gpu.mojom.h" 21 #include "mojo/services/public/interfaces/gpu/gpu.mojom.h"
21 #include "mojo/services/public/interfaces/native_viewport/native_viewport.mojom. h" 22 #include "mojo/services/public/interfaces/native_viewport/native_viewport.mojom. h"
22 #include "ppapi/c/pp_rect.h" 23 #include "ppapi/c/pp_rect.h"
23 #include "ppapi/shared_impl/proxy_lock.h" 24 #include "ppapi/shared_impl/proxy_lock.h"
24 25
25 namespace mojo { 26 namespace mojo {
26 namespace examples { 27 namespace examples {
27 28
28 class PepperContainerApp: public ApplicationDelegate, 29 class PepperContainerApp: public ApplicationDelegate,
29 public NativeViewportClient, 30 public NativeViewportClient,
30 public MojoPpapiGlobals::Delegate { 31 public MojoPpapiGlobals::Delegate {
31 public: 32 public:
32 explicit PepperContainerApp() 33 PepperContainerApp()
33 : ppapi_globals_(this), 34 : ppapi_globals_(this),
34 plugin_module_(new PluginModule) {} 35 plugin_module_(new PluginModule),
36 weak_factory_(this) {}
35 37
36 virtual ~PepperContainerApp() {} 38 virtual ~PepperContainerApp() {}
37 39
38 virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE { 40 virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE {
39 app->ConnectToService("mojo:mojo_native_viewport_service", &viewport_); 41 app->ConnectToService("mojo:mojo_native_viewport_service", &viewport_);
40 viewport_.set_client(this); 42 viewport_.set_client(this);
41 43
42 // TODO(jamesr): Should be mojo:mojo_gpu_service 44 // TODO(jamesr): Should be mojo:mojo_gpu_service
43 app->ConnectToService("mojo:mojo_native_viewport_service", &gpu_service_); 45 app->ConnectToService("mojo:mojo_native_viewport_service", &gpu_service_);
44 46
45 SizePtr size(Size::New()); 47 SizePtr size(Size::New());
46 size->width = 800; 48 size->width = 800;
47 size->height = 600; 49 size->height = 600;
48 viewport_->Create(size.Pass()); 50 viewport_->Create(size.Pass(),
51 base::Bind(&PepperContainerApp::OnCreatedNativeViewport,
52 weak_factory_.GetWeakPtr()));
49 viewport_->Show(); 53 viewport_->Show();
50 } 54 }
51 55
52 // NativeViewportClient implementation. 56 // NativeViewportClient implementation.
53 virtual void OnCreated(uint64_t native_viewport_id) OVERRIDE {
54 native_viewport_id_ = native_viewport_id;
55 ppapi::ProxyAutoLock lock;
56
57 plugin_instance_ = plugin_module_->CreateInstance().Pass();
58 if (!plugin_instance_->DidCreate())
59 plugin_instance_.reset();
60 }
61
62 virtual void OnDestroyed() OVERRIDE { 57 virtual void OnDestroyed() OVERRIDE {
63 ppapi::ProxyAutoLock lock; 58 ppapi::ProxyAutoLock lock;
64 59
65 if (plugin_instance_) { 60 if (plugin_instance_) {
66 plugin_instance_->DidDestroy(); 61 plugin_instance_->DidDestroy();
67 plugin_instance_.reset(); 62 plugin_instance_.reset();
68 } 63 }
69 64
70 base::MessageLoop::current()->Quit(); 65 base::MessageLoop::current()->Quit();
71 } 66 }
72 67
73 virtual void OnBoundsChanged(SizePtr bounds) OVERRIDE { 68 virtual void OnSizeChanged(SizePtr size) OVERRIDE {
74 ppapi::ProxyAutoLock lock; 69 ppapi::ProxyAutoLock lock;
75 70
76 if (plugin_instance_) 71 if (plugin_instance_) {
77 plugin_instance_->DidChangeView(bounds.To<PP_Rect>()); 72 PP_Rect pp_rect = {{0, 0}, {size->width, size->height}};
73 plugin_instance_->DidChangeView(pp_rect);
74 }
78 } 75 }
79 76
80 virtual void OnEvent(EventPtr event, 77 virtual void OnEvent(EventPtr event,
81 const mojo::Callback<void()>& callback) OVERRIDE { 78 const mojo::Callback<void()>& callback) OVERRIDE {
82 if (!event->location_data.is_null()) { 79 if (!event->location_data.is_null()) {
83 ppapi::ProxyAutoLock lock; 80 ppapi::ProxyAutoLock lock;
84 81
85 // TODO(yzshen): Handle events. 82 // TODO(yzshen): Handle events.
86 } 83 }
87 callback.Run(); 84 callback.Run();
88 } 85 }
89 86
90 // MojoPpapiGlobals::Delegate implementation. 87 // MojoPpapiGlobals::Delegate implementation.
91 virtual ScopedMessagePipeHandle CreateGLES2Context() OVERRIDE { 88 virtual ScopedMessagePipeHandle CreateGLES2Context() OVERRIDE {
92 CommandBufferPtr command_buffer; 89 CommandBufferPtr command_buffer;
93 SizePtr size = Size::New(); 90 SizePtr size = Size::New();
94 size->width = 800; 91 size->width = 800;
95 size->width = 600; 92 size->width = 600;
96 // TODO(jamesr): Output a surface to the native viewport instead. 93 // TODO(jamesr): Output a surface to the native viewport instead.
97 gpu_service_->CreateOnscreenGLES2Context( 94 gpu_service_->CreateOnscreenGLES2Context(
98 native_viewport_id_, size.Pass(), Get(&command_buffer)); 95 native_viewport_id_, size.Pass(), Get(&command_buffer));
99 return command_buffer.PassMessagePipe(); 96 return command_buffer.PassMessagePipe();
100 } 97 }
101 98
102 private: 99 private:
100 void OnCreatedNativeViewport(uint64_t native_viewport_id) {
101 native_viewport_id_ = native_viewport_id;
102 ppapi::ProxyAutoLock lock;
103
104 plugin_instance_ = plugin_module_->CreateInstance().Pass();
105 if (!plugin_instance_->DidCreate())
106 plugin_instance_.reset();
107 }
108
103 MojoPpapiGlobals ppapi_globals_; 109 MojoPpapiGlobals ppapi_globals_;
104 110
105 uint64_t native_viewport_id_; 111 uint64_t native_viewport_id_;
106 NativeViewportPtr viewport_; 112 NativeViewportPtr viewport_;
107 GpuPtr gpu_service_; 113 GpuPtr gpu_service_;
108 scoped_refptr<PluginModule> plugin_module_; 114 scoped_refptr<PluginModule> plugin_module_;
109 scoped_ptr<PluginInstance> plugin_instance_; 115 scoped_ptr<PluginInstance> plugin_instance_;
110 116
117 base::WeakPtrFactory<PepperContainerApp> weak_factory_;
118
111 DISALLOW_COPY_AND_ASSIGN(PepperContainerApp); 119 DISALLOW_COPY_AND_ASSIGN(PepperContainerApp);
112 }; 120 };
113 121
114 } // namespace examples 122 } // namespace examples
115 } // namespace mojo 123 } // namespace mojo
116 124
117 MojoResult MojoMain(MojoHandle shell_handle) { 125 MojoResult MojoMain(MojoHandle shell_handle) {
118 mojo::ApplicationRunnerChromium runner( 126 mojo::ApplicationRunnerChromium runner(
119 new mojo::examples::PepperContainerApp); 127 new mojo::examples::PepperContainerApp);
120 return runner.Run(shell_handle); 128 return runner.Run(shell_handle);
121 } 129 }
122 130
OLDNEW
« no previous file with comments | « mojo/examples/compositor_app/compositor_app.cc ('k') | mojo/examples/sample_app/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698