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

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

Issue 451753003: Mojo multiple command buffer support and sample (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: better casts Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « mojo/examples/compositor_app/compositor_app.cc ('k') | mojo/examples/sample_app/sample_app.cc » ('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/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/application/application_delegate.h" 14 #include "mojo/public/cpp/application/application_delegate.h"
15 #include "mojo/public/cpp/application/application_impl.h" 15 #include "mojo/public/cpp/application/application_impl.h"
16 #include "mojo/public/cpp/system/core.h" 16 #include "mojo/public/cpp/system/core.h"
17 #include "mojo/services/public/interfaces/gpu/gpu.mojom.h"
17 #include "mojo/services/public/interfaces/native_viewport/native_viewport.mojom. h" 18 #include "mojo/services/public/interfaces/native_viewport/native_viewport.mojom. h"
18 #include "ppapi/c/pp_rect.h" 19 #include "ppapi/c/pp_rect.h"
19 #include "ppapi/shared_impl/proxy_lock.h" 20 #include "ppapi/shared_impl/proxy_lock.h"
20 21
21 namespace mojo { 22 namespace mojo {
22 namespace examples { 23 namespace examples {
23 24
24 class PepperContainerApp: public ApplicationDelegate, 25 class PepperContainerApp: public ApplicationDelegate,
25 public NativeViewportClient, 26 public NativeViewportClient,
26 public MojoPpapiGlobals::Delegate { 27 public MojoPpapiGlobals::Delegate {
27 public: 28 public:
28 explicit PepperContainerApp() 29 explicit PepperContainerApp()
29 : ppapi_globals_(this), 30 : ppapi_globals_(this),
30 plugin_module_(new PluginModule) {} 31 plugin_module_(new PluginModule) {}
31 32
32 virtual ~PepperContainerApp() {} 33 virtual ~PepperContainerApp() {}
33 34
34 virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE { 35 virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE {
35 app->ConnectToService("mojo:mojo_native_viewport_service", &viewport_); 36 app->ConnectToService("mojo:mojo_native_viewport_service", &viewport_);
36 viewport_.set_client(this); 37 viewport_.set_client(this);
37 38
39 // TODO(jamesr): Should be mojo:mojo_gpu_service
40 app->ConnectToService("mojo:mojo_native_viewport_service", &gpu_service_);
41
38 RectPtr rect(Rect::New()); 42 RectPtr rect(Rect::New());
39 rect->x = 10; 43 rect->x = 10;
40 rect->y = 10; 44 rect->y = 10;
41 rect->width = 800; 45 rect->width = 800;
42 rect->height = 600; 46 rect->height = 600;
43 viewport_->Create(rect.Pass()); 47 viewport_->Create(rect.Pass());
44 viewport_->Show(); 48 viewport_->Show();
45 } 49 }
46 50
47 // NativeViewportClient implementation. 51 // NativeViewportClient implementation.
48 virtual void OnCreated() OVERRIDE { 52 virtual void OnCreated(uint64_t native_viewport_id) OVERRIDE {
53 native_viewport_id_ = native_viewport_id;
49 ppapi::ProxyAutoLock lock; 54 ppapi::ProxyAutoLock lock;
50 55
51 plugin_instance_ = plugin_module_->CreateInstance().Pass(); 56 plugin_instance_ = plugin_module_->CreateInstance().Pass();
52 if (!plugin_instance_->DidCreate()) 57 if (!plugin_instance_->DidCreate())
53 plugin_instance_.reset(); 58 plugin_instance_.reset();
54 } 59 }
55 60
56 virtual void OnDestroyed(const mojo::Callback<void()>& callback) OVERRIDE { 61 virtual void OnDestroyed() OVERRIDE {
57 ppapi::ProxyAutoLock lock; 62 ppapi::ProxyAutoLock lock;
58 63
59 if (plugin_instance_) { 64 if (plugin_instance_) {
60 plugin_instance_->DidDestroy(); 65 plugin_instance_->DidDestroy();
61 plugin_instance_.reset(); 66 plugin_instance_.reset();
62 } 67 }
63 68
64 base::MessageLoop::current()->Quit(); 69 base::MessageLoop::current()->Quit();
65 callback.Run();
66 } 70 }
67 71
68 virtual void OnBoundsChanged(RectPtr bounds) OVERRIDE { 72 virtual void OnBoundsChanged(RectPtr bounds) OVERRIDE {
69 ppapi::ProxyAutoLock lock; 73 ppapi::ProxyAutoLock lock;
70 74
71 if (plugin_instance_) 75 if (plugin_instance_)
72 plugin_instance_->DidChangeView(bounds.To<PP_Rect>()); 76 plugin_instance_->DidChangeView(bounds.To<PP_Rect>());
73 } 77 }
74 78
75 virtual void OnEvent(EventPtr event, 79 virtual void OnEvent(EventPtr event,
76 const mojo::Callback<void()>& callback) OVERRIDE { 80 const mojo::Callback<void()>& callback) OVERRIDE {
77 if (!event->location_data.is_null()) { 81 if (!event->location_data.is_null()) {
78 ppapi::ProxyAutoLock lock; 82 ppapi::ProxyAutoLock lock;
79 83
80 // TODO(yzshen): Handle events. 84 // TODO(yzshen): Handle events.
81 } 85 }
82 callback.Run(); 86 callback.Run();
83 } 87 }
84 88
85 // MojoPpapiGlobals::Delegate implementation. 89 // MojoPpapiGlobals::Delegate implementation.
86 virtual ScopedMessagePipeHandle CreateGLES2Context() OVERRIDE { 90 virtual ScopedMessagePipeHandle CreateGLES2Context() OVERRIDE {
87 CommandBufferPtr command_buffer; 91 CommandBufferPtr command_buffer;
88 viewport_->CreateGLES2Context(Get(&command_buffer)); 92 SizePtr size = Size::New();
93 size->width = 800;
94 size->width = 600;
95 gpu_service_->CreateOnscreenGLES2Context(
96 native_viewport_id_, size.Pass(), Get(&command_buffer));
89 return command_buffer.PassMessagePipe(); 97 return command_buffer.PassMessagePipe();
90 } 98 }
91 99
92 private: 100 private:
93 MojoPpapiGlobals ppapi_globals_; 101 MojoPpapiGlobals ppapi_globals_;
94 102
103 uint64_t native_viewport_id_;
95 NativeViewportPtr viewport_; 104 NativeViewportPtr viewport_;
105 GpuPtr gpu_service_;
96 scoped_refptr<PluginModule> plugin_module_; 106 scoped_refptr<PluginModule> plugin_module_;
97 scoped_ptr<PluginInstance> plugin_instance_; 107 scoped_ptr<PluginInstance> plugin_instance_;
98 108
99 DISALLOW_COPY_AND_ASSIGN(PepperContainerApp); 109 DISALLOW_COPY_AND_ASSIGN(PepperContainerApp);
100 }; 110 };
101 111
102 } // namespace examples 112 } // namespace examples
103 113
104 // static 114 // static
105 ApplicationDelegate* ApplicationDelegate::Create() { 115 ApplicationDelegate* ApplicationDelegate::Create() {
106 return new examples::PepperContainerApp(); 116 return new examples::PepperContainerApp();
107 } 117 }
108 118
109 } // namespace mojo 119 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/examples/compositor_app/compositor_app.cc ('k') | mojo/examples/sample_app/sample_app.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698