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

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

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