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

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

Issue 681203002: Remove mojo/examples/pepper_container_app (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/macros.h"
6 #include "base/memory/ref_counted.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "base/memory/weak_ptr.h"
9 #include "base/message_loop/message_loop.h"
10 #include "build/build_config.h"
11 #include "mojo/application/application_runner_chromium.h"
12 #include "mojo/examples/pepper_container_app/mojo_ppapi_globals.h"
13 #include "mojo/examples/pepper_container_app/plugin_instance.h"
14 #include "mojo/examples/pepper_container_app/plugin_module.h"
15 #include "mojo/examples/pepper_container_app/type_converters.h"
16 #include "mojo/public/c/system/main.h"
17 #include "mojo/public/cpp/application/application_delegate.h"
18 #include "mojo/public/cpp/application/application_impl.h"
19 #include "mojo/public/cpp/system/core.h"
20 #include "mojo/services/public/interfaces/geometry/geometry.mojom.h"
21 #include "mojo/services/public/interfaces/gpu/gpu.mojom.h"
22 #include "mojo/services/public/interfaces/native_viewport/native_viewport.mojom. h"
23 #include "ppapi/c/pp_rect.h"
24 #include "ppapi/shared_impl/proxy_lock.h"
25
26 namespace mojo {
27 namespace examples {
28
29 class PepperContainerApp: public ApplicationDelegate,
30 public NativeViewportClient,
31 public MojoPpapiGlobals::Delegate {
32 public:
33 PepperContainerApp()
34 : ppapi_globals_(this),
35 plugin_module_(new PluginModule),
36 weak_factory_(this) {}
37
38 virtual ~PepperContainerApp() {}
39
40 virtual void Initialize(ApplicationImpl* app) override {
41 app->ConnectToService("mojo:native_viewport_service", &viewport_);
42 viewport_.set_client(this);
43
44 // TODO(jamesr): Should be mojo:gpu_service
45 app->ConnectToService("mojo:native_viewport_service", &gpu_service_);
46
47 SizePtr size(Size::New());
48 size->width = 800;
49 size->height = 600;
50 viewport_->Create(size.Pass(),
51 base::Bind(&PepperContainerApp::OnCreatedNativeViewport,
52 weak_factory_.GetWeakPtr()));
53 viewport_->Show();
54 }
55
56 // NativeViewportClient implementation.
57 virtual void OnDestroyed() override {
58 ppapi::ProxyAutoLock lock;
59
60 if (plugin_instance_) {
61 plugin_instance_->DidDestroy();
62 plugin_instance_.reset();
63 }
64
65 base::MessageLoop::current()->Quit();
66 }
67
68 virtual void OnSizeChanged(SizePtr size) override {
69 ppapi::ProxyAutoLock lock;
70
71 if (plugin_instance_) {
72 PP_Rect pp_rect = {{0, 0}, {size->width, size->height}};
73 plugin_instance_->DidChangeView(pp_rect);
74 }
75 }
76
77 virtual void OnEvent(EventPtr event,
78 const mojo::Callback<void()>& callback) override {
79 if (!event->location_data.is_null()) {
80 ppapi::ProxyAutoLock lock;
81
82 // TODO(yzshen): Handle events.
83 }
84 callback.Run();
85 }
86
87 // MojoPpapiGlobals::Delegate implementation.
88 virtual ScopedMessagePipeHandle CreateGLES2Context() override {
89 CommandBufferPtr command_buffer;
90 SizePtr size = Size::New();
91 size->width = 800;
92 size->width = 600;
93 // TODO(jamesr): Output a surface to the native viewport instead.
94 gpu_service_->CreateOnscreenGLES2Context(
95 native_viewport_id_, size.Pass(), GetProxy(&command_buffer));
96 return command_buffer.PassMessagePipe();
97 }
98
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
109 MojoPpapiGlobals ppapi_globals_;
110
111 uint64_t native_viewport_id_;
112 NativeViewportPtr viewport_;
113 GpuPtr gpu_service_;
114 scoped_refptr<PluginModule> plugin_module_;
115 scoped_ptr<PluginInstance> plugin_instance_;
116
117 base::WeakPtrFactory<PepperContainerApp> weak_factory_;
118
119 DISALLOW_COPY_AND_ASSIGN(PepperContainerApp);
120 };
121
122 } // namespace examples
123 } // namespace mojo
124
125 MojoResult MojoMain(MojoHandle shell_handle) {
126 mojo::ApplicationRunnerChromium runner(
127 new mojo::examples::PepperContainerApp);
128 return runner.Run(shell_handle);
129 }
130
OLDNEW
« no previous file with comments | « mojo/examples/pepper_container_app/mojo_ppapi_globals.cc ('k') | mojo/examples/pepper_container_app/plugin_instance.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698