OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/renderer/pepper_plugin_delegate_impl.h" | 5 #include "chrome/renderer/pepper_plugin_delegate_impl.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
10 #include "app/surface/transport_dib.h" | 10 #include "app/surface/transport_dib.h" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/scoped_ptr.h" | 14 #include "base/scoped_ptr.h" |
15 #include "base/string_split.h" | 15 #include "base/string_split.h" |
16 #include "base/task.h" | 16 #include "base/task.h" |
17 #include "base/time.h" | 17 #include "base/time.h" |
18 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
19 #include "chrome/common/child_thread.h" | 19 #include "chrome/common/child_thread.h" |
20 #include "chrome/common/file_system/file_system_dispatcher.h" | 20 #include "chrome/common/file_system/file_system_dispatcher.h" |
21 #include "chrome/common/pepper_file_messages.h" | 21 #include "chrome/common/pepper_file_messages.h" |
22 #include "chrome/common/pepper_plugin_registry.h" | 22 #include "chrome/common/pepper_plugin_registry.h" |
23 #include "chrome/common/render_messages.h" | 23 #include "chrome/common/render_messages.h" |
24 #include "chrome/common/render_messages_params.h" | 24 #include "chrome/common/render_messages_params.h" |
25 #include "chrome/renderer/audio_message_filter.h" | 25 #include "chrome/renderer/audio_message_filter.h" |
26 #include "chrome/renderer/command_buffer_proxy.h" | 26 #include "chrome/renderer/command_buffer_proxy.h" |
27 #include "chrome/renderer/ggl/ggl.h" | 27 #include "chrome/renderer/ggl/ggl.h" |
28 #include "chrome/renderer/gpu_channel_host.h" | 28 #include "chrome/renderer/gpu_channel_host.h" |
| 29 #include "chrome/renderer/pepper_platform_context_3d_impl.h" |
29 #include "chrome/renderer/render_thread.h" | 30 #include "chrome/renderer/render_thread.h" |
30 #include "chrome/renderer/render_view.h" | 31 #include "chrome/renderer/render_view.h" |
31 #include "chrome/renderer/webgraphicscontext3d_command_buffer_impl.h" | 32 #include "chrome/renderer/webgraphicscontext3d_command_buffer_impl.h" |
32 #include "chrome/renderer/webplugin_delegate_proxy.h" | 33 #include "chrome/renderer/webplugin_delegate_proxy.h" |
33 #include "gfx/size.h" | 34 #include "gfx/size.h" |
34 #include "grit/locale_settings.h" | 35 #include "grit/locale_settings.h" |
35 #include "ipc/ipc_channel_handle.h" | 36 #include "ipc/ipc_channel_handle.h" |
36 #include "ppapi/c/dev/pp_video_dev.h" | 37 #include "ppapi/c/dev/pp_video_dev.h" |
37 #include "ppapi/proxy/host_dispatcher.h" | 38 #include "ppapi/proxy/host_dispatcher.h" |
38 #include "third_party/WebKit/WebKit/chromium/public/WebFileChooserCompletion.h" | 39 #include "third_party/WebKit/WebKit/chromium/public/WebFileChooserCompletion.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 } | 91 } |
91 | 92 |
92 private: | 93 private: |
93 int width_; | 94 int width_; |
94 int height_; | 95 int height_; |
95 scoped_ptr<TransportDIB> dib_; | 96 scoped_ptr<TransportDIB> dib_; |
96 | 97 |
97 DISALLOW_COPY_AND_ASSIGN(PlatformImage2DImpl); | 98 DISALLOW_COPY_AND_ASSIGN(PlatformImage2DImpl); |
98 }; | 99 }; |
99 | 100 |
100 #ifdef ENABLE_GPU | |
101 | |
102 class PlatformContext3DImpl : public pepper::PluginDelegate::PlatformContext3D { | |
103 public: | |
104 explicit PlatformContext3DImpl(WebKit::WebView* web_view) | |
105 : web_view_(web_view), | |
106 context_(NULL) { | |
107 } | |
108 | |
109 virtual ~PlatformContext3DImpl() { | |
110 if (context_) { | |
111 ggl::DestroyContext(context_); | |
112 context_ = NULL; | |
113 } | |
114 } | |
115 | |
116 virtual bool Init(); | |
117 virtual bool SwapBuffers(); | |
118 virtual unsigned GetError(); | |
119 virtual void SetSwapBuffersCallback(Callback0::Type* callback); | |
120 void ResizeBackingTexture(const gfx::Size& size); | |
121 virtual unsigned GetBackingTextureId(); | |
122 virtual gpu::gles2::GLES2Implementation* GetGLES2Implementation(); | |
123 | |
124 private: | |
125 WebKit::WebView* web_view_; | |
126 ggl::Context* context_; | |
127 }; | |
128 | |
129 #endif // ENABLE_GPU | |
130 | 101 |
131 class PlatformAudioImpl | 102 class PlatformAudioImpl |
132 : public pepper::PluginDelegate::PlatformAudio, | 103 : public pepper::PluginDelegate::PlatformAudio, |
133 public AudioMessageFilter::Delegate, | 104 public AudioMessageFilter::Delegate, |
134 public base::RefCountedThreadSafe<PlatformAudioImpl> { | 105 public base::RefCountedThreadSafe<PlatformAudioImpl> { |
135 public: | 106 public: |
136 explicit PlatformAudioImpl(scoped_refptr<AudioMessageFilter> filter) | 107 explicit PlatformAudioImpl(scoped_refptr<AudioMessageFilter> filter) |
137 : client_(NULL), filter_(filter), stream_id_(0), | 108 : client_(NULL), filter_(filter), stream_id_(0), |
138 main_message_loop_(MessageLoop::current()) { | 109 main_message_loop_(MessageLoop::current()) { |
139 DCHECK(filter_); | 110 DCHECK(filter_); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 // MessageFilter used to send/receive IPC. | 155 // MessageFilter used to send/receive IPC. |
185 scoped_refptr<AudioMessageFilter> filter_; | 156 scoped_refptr<AudioMessageFilter> filter_; |
186 // Our ID on the MessageFilter. | 157 // Our ID on the MessageFilter. |
187 int32 stream_id_; | 158 int32 stream_id_; |
188 | 159 |
189 MessageLoop* main_message_loop_; | 160 MessageLoop* main_message_loop_; |
190 | 161 |
191 DISALLOW_COPY_AND_ASSIGN(PlatformAudioImpl); | 162 DISALLOW_COPY_AND_ASSIGN(PlatformAudioImpl); |
192 }; | 163 }; |
193 | 164 |
194 #ifdef ENABLE_GPU | |
195 | |
196 bool PlatformContext3DImpl::Init() { | |
197 // Ignore initializing more than once. | |
198 if (context_) | |
199 return true; | |
200 | |
201 WebGraphicsContext3DCommandBufferImpl* context = | |
202 static_cast<WebGraphicsContext3DCommandBufferImpl*>( | |
203 web_view_->graphicsContext3D()); | |
204 if (!context) | |
205 return false; | |
206 | |
207 ggl::Context* parent_context = context->context(); | |
208 if (!parent_context) | |
209 return false; | |
210 | |
211 RenderThread* render_thread = RenderThread::current(); | |
212 if (!render_thread) | |
213 return false; | |
214 | |
215 GpuChannelHost* host = render_thread->GetGpuChannel(); | |
216 if (!host) | |
217 return false; | |
218 | |
219 DCHECK(host->state() == GpuChannelHost::kConnected); | |
220 | |
221 // TODO(apatrick): Let Pepper plugins configure their back buffer surface. | |
222 static const int32 attribs[] = { | |
223 ggl::GGL_ALPHA_SIZE, 8, | |
224 ggl::GGL_DEPTH_SIZE, 24, | |
225 ggl::GGL_STENCIL_SIZE, 8, | |
226 ggl::GGL_SAMPLES, 0, | |
227 ggl::GGL_SAMPLE_BUFFERS, 0, | |
228 ggl::GGL_NONE, | |
229 }; | |
230 | |
231 // TODO(apatrick): Decide which extensions to expose to Pepper plugins. | |
232 // Currently they get only core GLES2. | |
233 context_ = ggl::CreateOffscreenContext(host, | |
234 parent_context, | |
235 gfx::Size(1, 1), | |
236 "", | |
237 attribs); | |
238 if (!context_) | |
239 return false; | |
240 | |
241 return true; | |
242 } | |
243 | |
244 bool PlatformContext3DImpl::SwapBuffers() { | |
245 DCHECK(context_); | |
246 return ggl::SwapBuffers(context_); | |
247 } | |
248 | |
249 unsigned PlatformContext3DImpl::GetError() { | |
250 DCHECK(context_); | |
251 return ggl::GetError(context_); | |
252 } | |
253 | |
254 void PlatformContext3DImpl::ResizeBackingTexture(const gfx::Size& size) { | |
255 DCHECK(context_); | |
256 ggl::ResizeOffscreenContext(context_, size); | |
257 } | |
258 | |
259 void PlatformContext3DImpl::SetSwapBuffersCallback(Callback0::Type* callback) { | |
260 DCHECK(context_); | |
261 ggl::SetSwapBuffersCallback(context_, callback); | |
262 } | |
263 | |
264 unsigned PlatformContext3DImpl::GetBackingTextureId() { | |
265 DCHECK(context_); | |
266 return ggl::GetParentTextureId(context_); | |
267 } | |
268 | |
269 gpu::gles2::GLES2Implementation* | |
270 PlatformContext3DImpl::GetGLES2Implementation() { | |
271 DCHECK(context_); | |
272 return ggl::GetImplementation(context_); | |
273 } | |
274 | |
275 #endif // ENABLE_GPU | |
276 | |
277 bool PlatformAudioImpl::Initialize( | 165 bool PlatformAudioImpl::Initialize( |
278 uint32_t sample_rate, uint32_t sample_count, | 166 uint32_t sample_rate, uint32_t sample_count, |
279 pepper::PluginDelegate::PlatformAudio::Client* client) { | 167 pepper::PluginDelegate::PlatformAudio::Client* client) { |
280 | 168 |
281 DCHECK(client); | 169 DCHECK(client); |
282 // Make sure we don't call init more than once. | 170 // Make sure we don't call init more than once. |
283 DCHECK_EQ(0, stream_id_); | 171 DCHECK_EQ(0, stream_id_); |
284 | 172 |
285 client_ = client; | 173 client_ = client; |
286 | 174 |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 if (!dib) | 492 if (!dib) |
605 return NULL; | 493 return NULL; |
606 #endif | 494 #endif |
607 | 495 |
608 return new PlatformImage2DImpl(width, height, dib); | 496 return new PlatformImage2DImpl(width, height, dib); |
609 } | 497 } |
610 | 498 |
611 pepper::PluginDelegate::PlatformContext3D* | 499 pepper::PluginDelegate::PlatformContext3D* |
612 PepperPluginDelegateImpl::CreateContext3D() { | 500 PepperPluginDelegateImpl::CreateContext3D() { |
613 #ifdef ENABLE_GPU | 501 #ifdef ENABLE_GPU |
614 return new PlatformContext3DImpl(render_view_->webview()); | 502 WebGraphicsContext3DCommandBufferImpl* context = |
| 503 static_cast<WebGraphicsContext3DCommandBufferImpl*>( |
| 504 render_view_->webview()->graphicsContext3D()); |
| 505 if (!context) |
| 506 return NULL; |
| 507 |
| 508 ggl::Context* parent_context = context->context(); |
| 509 if (!parent_context) |
| 510 return NULL; |
| 511 |
| 512 return new PlatformContext3DImpl(parent_context); |
615 #else | 513 #else |
616 return NULL; | 514 return NULL; |
617 #endif | 515 #endif |
618 } | 516 } |
619 | 517 |
620 pepper::PluginDelegate::PlatformVideoDecoder* | 518 pepper::PluginDelegate::PlatformVideoDecoder* |
621 PepperPluginDelegateImpl::CreateVideoDecoder( | 519 PepperPluginDelegateImpl::CreateVideoDecoder( |
622 const PP_VideoDecoderConfig_Dev& decoder_config) { | 520 const PP_VideoDecoderConfig_Dev& decoder_config) { |
623 scoped_ptr<PlatformVideoDecoderImpl> decoder(new PlatformVideoDecoderImpl()); | 521 scoped_ptr<PlatformVideoDecoderImpl> decoder(new PlatformVideoDecoderImpl()); |
624 | 522 |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
909 } | 807 } |
910 | 808 |
911 void PepperPluginDelegateImpl::DidStopLoading() { | 809 void PepperPluginDelegateImpl::DidStopLoading() { |
912 render_view_->DidStopLoadingForPlugin(); | 810 render_view_->DidStopLoadingForPlugin(); |
913 } | 811 } |
914 | 812 |
915 void PepperPluginDelegateImpl::SetContentRestriction(int restrictions) { | 813 void PepperPluginDelegateImpl::SetContentRestriction(int restrictions) { |
916 render_view_->Send(new ViewHostMsg_UpdateContentRestrictions( | 814 render_view_->Send(new ViewHostMsg_UpdateContentRestrictions( |
917 render_view_->routing_id(), restrictions)); | 815 render_view_->routing_id(), restrictions)); |
918 } | 816 } |
OLD | NEW |