OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/renderer/pepper/ppb_graphics_3d_impl.h" | 5 #include "content/renderer/pepper/ppb_graphics_3d_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "content/renderer/pepper/host_globals.h" |
11 #include "content/renderer/pepper/pepper_platform_context_3d.h" | 12 #include "content/renderer/pepper/pepper_platform_context_3d.h" |
12 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" | 13 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
13 #include "content/renderer/pepper/plugin_module.h" | 14 #include "content/renderer/pepper/plugin_module.h" |
14 #include "content/renderer/pepper/resource_helper.h" | |
15 #include "content/renderer/render_view_impl.h" | 15 #include "content/renderer/render_view_impl.h" |
16 #include "gpu/command_buffer/client/gles2_implementation.h" | 16 #include "gpu/command_buffer/client/gles2_implementation.h" |
17 #include "ppapi/c/ppp_graphics_3d.h" | 17 #include "ppapi/c/ppp_graphics_3d.h" |
18 #include "ppapi/thunk/enter.h" | 18 #include "ppapi/thunk/enter.h" |
19 #include "third_party/WebKit/public/platform/WebString.h" | 19 #include "third_party/WebKit/public/platform/WebString.h" |
20 #include "third_party/WebKit/public/web/WebConsoleMessage.h" | 20 #include "third_party/WebKit/public/web/WebConsoleMessage.h" |
21 #include "third_party/WebKit/public/web/WebDocument.h" | 21 #include "third_party/WebKit/public/web/WebDocument.h" |
22 #include "third_party/WebKit/public/web/WebElement.h" | 22 #include "third_party/WebKit/public/web/WebElement.h" |
23 #include "third_party/WebKit/public/web/WebFrame.h" | 23 #include "third_party/WebKit/public/web/WebFrame.h" |
24 #include "third_party/WebKit/public/web/WebPluginContainer.h" | 24 #include "third_party/WebKit/public/web/WebPluginContainer.h" |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 gles2_impl()->SwapBuffers(); | 198 gles2_impl()->SwapBuffers(); |
199 | 199 |
200 if (bound_to_instance_) { | 200 if (bound_to_instance_) { |
201 // If we are bound to the instance, we need to ask the compositor | 201 // If we are bound to the instance, we need to ask the compositor |
202 // to commit our backing texture so that the graphics appears on the page. | 202 // to commit our backing texture so that the graphics appears on the page. |
203 // When the backing texture will be committed we get notified via | 203 // When the backing texture will be committed we get notified via |
204 // ViewFlushedPaint(). | 204 // ViewFlushedPaint(). |
205 // | 205 // |
206 // Don't need to check for NULL from GetPluginInstance since when we're | 206 // Don't need to check for NULL from GetPluginInstance since when we're |
207 // bound, we know our instance is valid. | 207 // bound, we know our instance is valid. |
208 ResourceHelper::GetPluginInstance(this)->CommitBackingTexture(); | 208 HostGlobals::Get()->GetInstance(pp_instance())->CommitBackingTexture(); |
209 commit_pending_ = true; | 209 commit_pending_ = true; |
210 } else { | 210 } else { |
211 // Wait for the command to complete on the GPU to allow for throttling. | 211 // Wait for the command to complete on the GPU to allow for throttling. |
212 platform_context_->Echo(base::Bind(&PPB_Graphics3D_Impl::OnSwapBuffers, | 212 platform_context_->Echo(base::Bind(&PPB_Graphics3D_Impl::OnSwapBuffers, |
213 weak_ptr_factory_.GetWeakPtr())); | 213 weak_ptr_factory_.GetWeakPtr())); |
214 } | 214 } |
215 | 215 |
216 | 216 |
217 return PP_OK_COMPLETIONPENDING; | 217 return PP_OK_COMPLETIONPENDING; |
218 } | 218 } |
(...skipping 13 matching lines...) Expand all Loading... |
232 static_cast<PPB_Graphics3D_Shared*>(share_context)->gles2_impl(); | 232 static_cast<PPB_Graphics3D_Shared*>(share_context)->gles2_impl(); |
233 } | 233 } |
234 | 234 |
235 return CreateGLES2Impl(kCommandBufferSize, kTransferBufferSize, | 235 return CreateGLES2Impl(kCommandBufferSize, kTransferBufferSize, |
236 share_gles2); | 236 share_gles2); |
237 } | 237 } |
238 | 238 |
239 bool PPB_Graphics3D_Impl::InitRaw(PPB_Graphics3D_API* share_context, | 239 bool PPB_Graphics3D_Impl::InitRaw(PPB_Graphics3D_API* share_context, |
240 const int32_t* attrib_list) { | 240 const int32_t* attrib_list) { |
241 PepperPluginInstanceImpl* plugin_instance = | 241 PepperPluginInstanceImpl* plugin_instance = |
242 ResourceHelper::GetPluginInstance(this); | 242 HostGlobals::Get()->GetInstance(pp_instance()); |
243 if (!plugin_instance) | 243 if (!plugin_instance) |
244 return false; | 244 return false; |
245 | 245 |
246 PlatformContext3D* share_platform_context = NULL; | 246 PlatformContext3D* share_platform_context = NULL; |
247 if (share_context) { | 247 if (share_context) { |
248 PPB_Graphics3D_Impl* share_graphics = | 248 PPB_Graphics3D_Impl* share_graphics = |
249 static_cast<PPB_Graphics3D_Impl*>(share_context); | 249 static_cast<PPB_Graphics3D_Impl*>(share_context); |
250 share_platform_context = share_graphics->platform_context(); | 250 share_platform_context = share_graphics->platform_context(); |
251 } | 251 } |
252 | 252 |
(...skipping 20 matching lines...) Expand all Loading... |
273 base::Bind(&PPB_Graphics3D_Impl::OnConsoleMessage, | 273 base::Bind(&PPB_Graphics3D_Impl::OnConsoleMessage, |
274 weak_ptr_factory_.GetWeakPtr())); | 274 weak_ptr_factory_.GetWeakPtr())); |
275 return true; | 275 return true; |
276 } | 276 } |
277 | 277 |
278 void PPB_Graphics3D_Impl::OnConsoleMessage(const std::string& message, | 278 void PPB_Graphics3D_Impl::OnConsoleMessage(const std::string& message, |
279 int id) { | 279 int id) { |
280 if (!bound_to_instance_) | 280 if (!bound_to_instance_) |
281 return; | 281 return; |
282 WebPluginContainer* container = | 282 WebPluginContainer* container = |
283 ResourceHelper::GetPluginInstance(this)->container(); | 283 HostGlobals::Get()->GetInstance(pp_instance())->container(); |
284 if (!container) | 284 if (!container) |
285 return; | 285 return; |
286 WebFrame* frame = container->element().document().frame(); | 286 WebFrame* frame = container->element().document().frame(); |
287 if (!frame) | 287 if (!frame) |
288 return; | 288 return; |
289 WebConsoleMessage console_message = WebConsoleMessage( | 289 WebConsoleMessage console_message = WebConsoleMessage( |
290 WebConsoleMessage::LevelError, WebString(UTF8ToUTF16(message))); | 290 WebConsoleMessage::LevelError, WebString(UTF8ToUTF16(message))); |
291 frame->addMessageToConsole(console_message); | 291 frame->addMessageToConsole(console_message); |
292 } | 292 } |
293 | 293 |
294 void PPB_Graphics3D_Impl::OnSwapBuffers() { | 294 void PPB_Graphics3D_Impl::OnSwapBuffers() { |
295 if (HasPendingSwap()) { | 295 if (HasPendingSwap()) { |
296 // If we're off-screen, no need to trigger and wait for compositing. | 296 // If we're off-screen, no need to trigger and wait for compositing. |
297 // Just send the swap-buffers ACK to the plugin immediately. | 297 // Just send the swap-buffers ACK to the plugin immediately. |
298 commit_pending_ = false; | 298 commit_pending_ = false; |
299 SwapBuffersACK(PP_OK); | 299 SwapBuffersACK(PP_OK); |
300 } | 300 } |
301 } | 301 } |
302 | 302 |
303 void PPB_Graphics3D_Impl::OnContextLost() { | 303 void PPB_Graphics3D_Impl::OnContextLost() { |
304 // Don't need to check for NULL from GetPluginInstance since when we're | 304 // Don't need to check for NULL from GetPluginInstance since when we're |
305 // bound, we know our instance is valid. | 305 // bound, we know our instance is valid. |
306 if (bound_to_instance_) | 306 if (bound_to_instance_) { |
307 ResourceHelper::GetPluginInstance(this)->BindGraphics(pp_instance(), 0); | 307 HostGlobals::Get()->GetInstance(pp_instance())->BindGraphics( |
| 308 pp_instance(), 0); |
| 309 } |
308 | 310 |
309 // Send context lost to plugin. This may have been caused by a PPAPI call, so | 311 // Send context lost to plugin. This may have been caused by a PPAPI call, so |
310 // avoid re-entering. | 312 // avoid re-entering. |
311 base::MessageLoop::current()->PostTask( | 313 base::MessageLoop::current()->PostTask( |
312 FROM_HERE, | 314 FROM_HERE, |
313 base::Bind(&PPB_Graphics3D_Impl::SendContextLost, | 315 base::Bind(&PPB_Graphics3D_Impl::SendContextLost, |
314 weak_ptr_factory_.GetWeakPtr())); | 316 weak_ptr_factory_.GetWeakPtr())); |
315 } | 317 } |
316 | 318 |
317 void PPB_Graphics3D_Impl::SendContextLost() { | 319 void PPB_Graphics3D_Impl::SendContextLost() { |
318 // By the time we run this, the instance may have been deleted, or in the | 320 // By the time we run this, the instance may have been deleted, or in the |
319 // process of being deleted. Even in the latter case, we don't want to send a | 321 // process of being deleted. Even in the latter case, we don't want to send a |
320 // callback after DidDestroy. | 322 // callback after DidDestroy. |
321 PepperPluginInstanceImpl* instance = ResourceHelper::GetPluginInstance(this); | 323 PepperPluginInstanceImpl* instance = |
| 324 HostGlobals::Get()->GetInstance(pp_instance()); |
322 if (!instance || !instance->container()) | 325 if (!instance || !instance->container()) |
323 return; | 326 return; |
324 | 327 |
325 // This PPB_Graphics3D_Impl could be deleted during the call to | 328 // This PPB_Graphics3D_Impl could be deleted during the call to |
326 // GetPluginInterface (which sends a sync message in some cases). We still | 329 // GetPluginInterface (which sends a sync message in some cases). We still |
327 // send the Graphics3DContextLost to the plugin; the instance may care about | 330 // send the Graphics3DContextLost to the plugin; the instance may care about |
328 // that event even though this context has been destroyed. | 331 // that event even though this context has been destroyed. |
329 PP_Instance this_pp_instance = pp_instance(); | 332 PP_Instance this_pp_instance = pp_instance(); |
330 const PPP_Graphics3D* ppp_graphics_3d = | 333 const PPP_Graphics3D* ppp_graphics_3d = |
331 static_cast<const PPP_Graphics3D*>( | 334 static_cast<const PPP_Graphics3D*>( |
332 instance->module()->GetPluginInterface( | 335 instance->module()->GetPluginInterface( |
333 PPP_GRAPHICS_3D_INTERFACE)); | 336 PPP_GRAPHICS_3D_INTERFACE)); |
334 if (ppp_graphics_3d) | 337 if (ppp_graphics_3d) |
335 ppp_graphics_3d->Graphics3DContextLost(this_pp_instance); | 338 ppp_graphics_3d->Graphics3DContextLost(this_pp_instance); |
336 } | 339 } |
337 | 340 |
338 } // namespace content | 341 } // namespace content |
OLD | NEW |