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

Side by Side Diff: chrome/renderer/pepper_plugin_delegate_impl.cc

Issue 3531008: Integrated Pepper3D v2 with the accelerated compositor.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 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 | Annotate | Revision Log
OLDNEW
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 <cmath> 5 #include <cmath>
6 6
7 #include "chrome/renderer/pepper_plugin_delegate_impl.h" 7 #include "chrome/renderer/pepper_plugin_delegate_impl.h"
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/file_path.h" 12 #include "base/file_path.h"
12 #include "base/logging.h" 13 #include "base/logging.h"
13 #include "base/scoped_ptr.h" 14 #include "base/scoped_ptr.h"
14 #include "base/string_split.h" 15 #include "base/string_split.h"
15 #include "base/task.h" 16 #include "base/task.h"
16 #include "base/time.h" 17 #include "base/time.h"
17 #include "base/utf_string_conversions.h" 18 #include "base/utf_string_conversions.h"
18 #include "chrome/common/child_thread.h" 19 #include "chrome/common/child_thread.h"
19 #include "chrome/common/file_system/file_system_dispatcher.h" 20 #include "chrome/common/file_system/file_system_dispatcher.h"
20 #include "chrome/common/render_messages.h" 21 #include "chrome/common/render_messages.h"
21 #include "chrome/common/render_messages_params.h" 22 #include "chrome/common/render_messages_params.h"
22 #include "chrome/renderer/audio_message_filter.h" 23 #include "chrome/renderer/audio_message_filter.h"
23 #include "chrome/renderer/command_buffer_proxy.h" 24 #include "chrome/renderer/command_buffer_proxy.h"
25 #include "chrome/renderer/ggl/ggl.h"
26 #include "chrome/renderer/gpu_channel_host.h"
24 #include "chrome/renderer/render_thread.h" 27 #include "chrome/renderer/render_thread.h"
25 #include "chrome/renderer/render_view.h" 28 #include "chrome/renderer/render_view.h"
29 #include "chrome/renderer/webgraphicscontext3d_command_buffer_impl.h"
26 #include "chrome/renderer/webplugin_delegate_proxy.h" 30 #include "chrome/renderer/webplugin_delegate_proxy.h"
31 #include "gfx/size.h"
27 #include "grit/locale_settings.h" 32 #include "grit/locale_settings.h"
28 #include "ppapi/c/dev/pp_video_dev.h" 33 #include "ppapi/c/dev/pp_video_dev.h"
29 #include "third_party/WebKit/WebKit/chromium/public/WebFileChooserCompletion.h" 34 #include "third_party/WebKit/WebKit/chromium/public/WebFileChooserCompletion.h"
30 #include "third_party/WebKit/WebKit/chromium/public/WebFileChooserParams.h" 35 #include "third_party/WebKit/WebKit/chromium/public/WebFileChooserParams.h"
31 #include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h" 36 #include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h"
32 #include "third_party/WebKit/WebKit/chromium/public/WebView.h" 37 #include "third_party/WebKit/WebKit/chromium/public/WebView.h"
33 #include "webkit/fileapi/file_system_callback_dispatcher.h" 38 #include "webkit/fileapi/file_system_callback_dispatcher.h"
34 #include "webkit/glue/plugins/pepper_file_io.h" 39 #include "webkit/glue/plugins/pepper_file_io.h"
35 #include "webkit/glue/plugins/pepper_plugin_instance.h" 40 #include "webkit/glue/plugins/pepper_plugin_instance.h"
36 #include "webkit/glue/plugins/webplugin.h" 41 #include "webkit/glue/plugins/webplugin.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 int height_; 78 int height_;
74 scoped_ptr<TransportDIB> dib_; 79 scoped_ptr<TransportDIB> dib_;
75 80
76 DISALLOW_COPY_AND_ASSIGN(PlatformImage2DImpl); 81 DISALLOW_COPY_AND_ASSIGN(PlatformImage2DImpl);
77 }; 82 };
78 83
79 #ifdef ENABLE_GPU 84 #ifdef ENABLE_GPU
80 85
81 class PlatformContext3DImpl : public pepper::PluginDelegate::PlatformContext3D { 86 class PlatformContext3DImpl : public pepper::PluginDelegate::PlatformContext3D {
82 public: 87 public:
83 explicit PlatformContext3DImpl(RenderView* render_view) 88 explicit PlatformContext3DImpl(WebKit::WebView* web_view)
84 : render_view_(render_view), 89 : web_view_(web_view),
85 nested_delegate_(NULL), 90 context_(NULL) {
86 command_buffer_(NULL), 91 }
87 renderview_to_webplugin_adapter_(render_view) {}
88 92
89 virtual ~PlatformContext3DImpl() { 93 virtual ~PlatformContext3DImpl() {
90 if (nested_delegate_) { 94 if (context_) {
91 nested_delegate_->DestroyCommandBuffer(command_buffer_); 95 ggl::DestroyContext(context_);
92 nested_delegate_->PluginDestroyed(); 96 context_ = NULL;
93 } 97 }
94 } 98 }
95 99
96 virtual bool Init(const gfx::Rect& position, const gfx::Rect& clip); 100 virtual bool Init();
97 101 virtual bool SwapBuffers();
98 virtual gpu::CommandBuffer* GetCommandBuffer() { 102 virtual unsigned GetError();
99 return command_buffer_; 103 virtual void SetSwapBuffersCallback(Callback0::Type* callback);
100 } 104 void ResizeBackingTexture(const gfx::Size& size);
101 105 virtual unsigned GetBackingTextureId();
102 virtual void SetNotifyRepaintTask(Task* task) { 106 virtual gpu::gles2::GLES2Implementation* GetGLES2Implementation();
103 command_buffer_->SetNotifyRepaintTask(task);
104 }
105 107
106 private: 108 private:
107 109 WebKit::WebView* web_view_;
108 class WebPluginAdapter : public webkit_glue::WebPlugin { 110 ggl::Context* context_;
109 public:
110 explicit WebPluginAdapter(RenderView* render_view)
111 : render_view_(render_view) {}
112
113 virtual void SetWindow(gfx::PluginWindowHandle window) {
114 render_view_->CreatedPluginWindow(window);
115 }
116
117 virtual void WillDestroyWindow(gfx::PluginWindowHandle window) {
118 render_view_->WillDestroyPluginWindow(window);
119 }
120
121 virtual void SetAcceptsInputEvents(bool accepts) {
122 NOTREACHED();
123 }
124
125 #if defined(OS_WIN)
126 virtual void SetWindowlessPumpEvent(HANDLE pump_messages_event) {
127 NOTREACHED();
128 }
129 #endif
130
131 virtual void CancelResource(unsigned long id) {
132 NOTREACHED();
133 }
134
135 virtual void Invalidate() {
136 NOTREACHED();
137 }
138
139 virtual void InvalidateRect(const gfx::Rect& rect) {
140 NOTREACHED();
141 }
142
143 virtual NPObject* GetWindowScriptNPObject() {
144 NOTREACHED();
145 return NULL;
146 }
147
148 virtual NPObject* GetPluginElement() {
149 NOTREACHED();
150 return NULL;
151 }
152
153 virtual void SetCookie(const GURL& url,
154 const GURL& first_party_for_cookies,
155 const std::string& cookie) {
156 NOTREACHED();
157 }
158
159 virtual std::string GetCookies(const GURL& url,
160 const GURL& first_party_for_cookies) {
161 NOTREACHED();
162 return std::string();
163 }
164
165 virtual void ShowModalHTMLDialog(const GURL& url, int width, int height,
166 const std::string& json_arguments,
167 std::string* json_retval) {
168 NOTREACHED();
169 }
170
171 virtual void OnMissingPluginStatus(int status) {
172 NOTREACHED();
173 }
174
175 virtual void HandleURLRequest(const char* url,
176 const char* method,
177 const char* target,
178 const char* buf,
179 unsigned int len,
180 int notify_id,
181 bool popups_allowed) {
182 NOTREACHED();
183 }
184
185 virtual void CancelDocumentLoad() {
186 NOTREACHED();
187 }
188
189 virtual void InitiateHTTPRangeRequest(const char* url,
190 const char* range_info,
191 int range_request_id) {
192 NOTREACHED();
193 }
194
195 virtual bool IsOffTheRecord() {
196 NOTREACHED();
197 return false;
198 }
199
200 virtual void SetDeferResourceLoading(unsigned long resource_id,
201 bool defer) {
202 NOTREACHED();
203 }
204
205 private:
206 RenderView* render_view_;
207 };
208
209 void SendNestedDelegateGeometryToBrowser(const gfx::Rect& window_rect,
210 const gfx::Rect& clip_rect);
211
212 RenderView* render_view_;
213 WebPluginDelegateProxy* nested_delegate_;
214 CommandBufferProxy* command_buffer_;
215 WebPluginAdapter renderview_to_webplugin_adapter_;
216 }; 111 };
217 112
218 #endif // ENABLE_GPU 113 #endif // ENABLE_GPU
219 114
220 class PlatformAudioImpl 115 class PlatformAudioImpl
221 : public pepper::PluginDelegate::PlatformAudio, 116 : public pepper::PluginDelegate::PlatformAudio,
222 public AudioMessageFilter::Delegate { 117 public AudioMessageFilter::Delegate {
223 public: 118 public:
224 explicit PlatformAudioImpl(scoped_refptr<AudioMessageFilter> filter) 119 explicit PlatformAudioImpl(scoped_refptr<AudioMessageFilter> filter)
225 : client_(NULL), filter_(filter), stream_id_(0) { 120 : client_(NULL), filter_(filter), stream_id_(0) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 // MessageFilter used to send/receive IPC. 166 // MessageFilter used to send/receive IPC.
272 scoped_refptr<AudioMessageFilter> filter_; 167 scoped_refptr<AudioMessageFilter> filter_;
273 // Our ID on the MessageFilter. 168 // Our ID on the MessageFilter.
274 int32 stream_id_; 169 int32 stream_id_;
275 170
276 DISALLOW_COPY_AND_ASSIGN(PlatformAudioImpl); 171 DISALLOW_COPY_AND_ASSIGN(PlatformAudioImpl);
277 }; 172 };
278 173
279 #ifdef ENABLE_GPU 174 #ifdef ENABLE_GPU
280 175
281 bool PlatformContext3DImpl::Init(const gfx::Rect& position, 176 bool PlatformContext3DImpl::Init() {
282 const gfx::Rect& clip) {
283 #if defined(ENABLE_GPU)
284 // Ignore initializing more than once. 177 // Ignore initializing more than once.
285 if (nested_delegate_) 178 if (context_)
286 return true; 179 return true;
287 180
288 // Create an instance of the GPU plugin that is responsible for 3D 181 WebGraphicsContext3DCommandBufferImpl* context =
289 // rendering. 182 static_cast<WebGraphicsContext3DCommandBufferImpl*>(
290 nested_delegate_ = new WebPluginDelegateProxy( 183 web_view_->graphicsContext3D());
291 std::string("application/vnd.google.chrome.gpu-plugin"), 184 if (!context)
292 render_view_->AsWeakPtr()); 185 return false;
293 186
294 if (nested_delegate_->Initialize(GURL(), std::vector<std::string>(), 187 ggl::Context* parent_context = context->context();
295 std::vector<std::string>(), 188 if (!parent_context)
296 &renderview_to_webplugin_adapter_, 189 return false;
297 false)) {
298 // Ensure the window has the correct size before initializing the
299 // command buffer.
300 nested_delegate_->UpdateGeometry(position, clip);
301 190
302 // Ask the GPU plugin to create a command buffer and return a proxy. 191 RenderThread* render_thread = RenderThread::current();
303 command_buffer_ = nested_delegate_->CreateCommandBuffer(); 192 if (!render_thread)
304 if (command_buffer_) { 193 return false;
305 // Initialize the proxy command buffer.
306 if (command_buffer_->Initialize(kDefaultCommandBufferSize)) {
307 #if defined(OS_MACOSX)
308 command_buffer_->SetWindowSize(position.size());
309 #endif // OS_MACOSX
310 194
311 // Make sure the nested delegate shows up in the right place 195 GpuChannelHost* host = render_thread->GetGpuChannel();
312 // on the page. 196 if (!host)
313 SendNestedDelegateGeometryToBrowser(position, clip); 197 return false;
314 198
315 return true; 199 DCHECK(host->state() == GpuChannelHost::CONNECTED);
316 }
317 }
318 200
319 nested_delegate_->DestroyCommandBuffer(command_buffer_); 201 // TODO(apatrick): Let Pepper plugins configure their back buffer surface.
320 command_buffer_ = NULL; 202 static const int32 attribs[] = {
321 } 203 ggl::GGL_ALPHA_SIZE, 8,
204 ggl::GGL_DEPTH_SIZE, 24,
205 ggl::GGL_STENCIL_SIZE, 8,
206 ggl::GGL_SAMPLES, 0,
207 ggl::GGL_SAMPLE_BUFFERS, 0,
208 ggl::GGL_NONE,
209 };
322 210
323 nested_delegate_->PluginDestroyed(); 211 // TODO(apatrick): Decide which extensions to expose to Pepper plugins.
324 nested_delegate_ = NULL; 212 // Currently they get only core GLES2.
325 #endif // ENABLE_GPU 213 context_ = ggl::CreateOffscreenContext(host,
326 return false; 214 parent_context,
215 gfx::Size(1, 1),
216 "",
217 attribs);
218 if (!context_)
219 return false;
220
221 return true;
327 } 222 }
328 223
329 void PlatformContext3DImpl::SendNestedDelegateGeometryToBrowser( 224 bool PlatformContext3DImpl::SwapBuffers() {
330 const gfx::Rect& window_rect, 225 DCHECK(context_);
331 const gfx::Rect& clip_rect) { 226 return ggl::SwapBuffers(context_);
332 // Inform the browser about the location of the plugin on the page. 227 }
333 // It appears that initially the plugin does not get laid out correctly --
334 // possibly due to lazy creation of the nested delegate.
335 if (!nested_delegate_ ||
336 !nested_delegate_->GetPluginWindowHandle() ||
337 !render_view_) {
338 return;
339 }
340 228
341 webkit_glue::WebPluginGeometry geom; 229 unsigned PlatformContext3DImpl::GetError() {
342 geom.window = nested_delegate_->GetPluginWindowHandle(); 230 DCHECK(context_);
343 geom.window_rect = window_rect; 231 return ggl::GetError(context_);
344 geom.clip_rect = clip_rect; 232 }
345 // Rects_valid must be true for this to work in the Gtk port; 233
346 // hopefully not having the cutout rects will not cause incorrect 234 void PlatformContext3DImpl::ResizeBackingTexture(const gfx::Size& size) {
347 // clipping. 235 DCHECK(context_);
348 geom.rects_valid = true; 236 ggl::ResizeOffscreenContext(context_, size);
349 geom.visible = true; 237 }
350 render_view_->DidMovePlugin(geom); 238
239 void PlatformContext3DImpl::SetSwapBuffersCallback(Callback0::Type* callback) {
240 DCHECK(context_);
241 ggl::SetSwapBuffersCallback(context_, callback);
242 }
243
244 unsigned PlatformContext3DImpl::GetBackingTextureId() {
245 DCHECK(context_);
246 return ggl::GetParentTextureId(context_);
247 }
248
249 gpu::gles2::GLES2Implementation*
250 PlatformContext3DImpl::GetGLES2Implementation() {
251 DCHECK(context_);
252 return ggl::GetImplementation(context_);
351 } 253 }
352 254
353 #endif // ENABLE_GPU 255 #endif // ENABLE_GPU
354 256
355 bool PlatformAudioImpl::Initialize( 257 bool PlatformAudioImpl::Initialize(
356 uint32_t sample_rate, uint32_t sample_count, 258 uint32_t sample_rate, uint32_t sample_count,
357 pepper::PluginDelegate::PlatformAudio::Client* client) { 259 pepper::PluginDelegate::PlatformAudio::Client* client) {
358 260
359 DCHECK(client); 261 DCHECK(client);
360 // Make sure we don't call init more than once. 262 // Make sure we don't call init more than once.
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 if (!dib) 499 if (!dib)
598 return NULL; 500 return NULL;
599 #endif 501 #endif
600 502
601 return new PlatformImage2DImpl(width, height, dib); 503 return new PlatformImage2DImpl(width, height, dib);
602 } 504 }
603 505
604 pepper::PluginDelegate::PlatformContext3D* 506 pepper::PluginDelegate::PlatformContext3D*
605 PepperPluginDelegateImpl::CreateContext3D() { 507 PepperPluginDelegateImpl::CreateContext3D() {
606 #ifdef ENABLE_GPU 508 #ifdef ENABLE_GPU
607 return new PlatformContext3DImpl(render_view_); 509 return new PlatformContext3DImpl(render_view_->webview());
608 #else 510 #else
609 return NULL; 511 return NULL;
610 #endif 512 #endif
611 } 513 }
612 514
613 pepper::PluginDelegate::PlatformVideoDecoder* 515 pepper::PluginDelegate::PlatformVideoDecoder*
614 PepperPluginDelegateImpl::CreateVideoDecoder( 516 PepperPluginDelegateImpl::CreateVideoDecoder(
615 const PP_VideoDecoderConfig_Dev& decoder_config) { 517 const PP_VideoDecoderConfig_Dev& decoder_config) {
616 scoped_ptr<PlatformVideoDecoderImpl> decoder(new PlatformVideoDecoderImpl()); 518 scoped_ptr<PlatformVideoDecoderImpl> decoder(new PlatformVideoDecoderImpl());
617 519
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
900 } 802 }
901 803
902 void PepperPluginDelegateImpl::DidStopLoading() { 804 void PepperPluginDelegateImpl::DidStopLoading() {
903 render_view_->DidStopLoadingForPlugin(); 805 render_view_->DidStopLoadingForPlugin();
904 } 806 }
905 807
906 void PepperPluginDelegateImpl::SetContentRestriction(int restrictions) { 808 void PepperPluginDelegateImpl::SetContentRestriction(int restrictions) {
907 render_view_->Send(new ViewHostMsg_UpdateContentRestrictions( 809 render_view_->Send(new ViewHostMsg_UpdateContentRestrictions(
908 render_view_->routing_id(), restrictions)); 810 render_view_->routing_id(), restrictions));
909 } 811 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698