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/location.h" | 9 #include "base/location.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 share_buffer = share_graphics->GetCommandBufferProxy(); | 237 share_buffer = share_graphics->GetCommandBufferProxy(); |
238 } | 238 } |
239 | 239 |
240 command_buffer_ = channel_->CreateCommandBuffer( | 240 command_buffer_ = channel_->CreateCommandBuffer( |
241 gpu::kNullSurfaceHandle, surface_size, share_buffer, | 241 gpu::kNullSurfaceHandle, surface_size, share_buffer, |
242 gpu::GpuChannelHost::kDefaultStreamId, | 242 gpu::GpuChannelHost::kDefaultStreamId, |
243 gpu::GpuChannelHost::kDefaultStreamPriority, attribs, GURL::EmptyGURL(), | 243 gpu::GpuChannelHost::kDefaultStreamPriority, attribs, GURL::EmptyGURL(), |
244 gpu_preference); | 244 gpu_preference); |
245 if (!command_buffer_) | 245 if (!command_buffer_) |
246 return false; | 246 return false; |
| 247 |
| 248 command_buffer_->SetGpuControlClient(this); |
| 249 |
247 if (!command_buffer_->Initialize()) | 250 if (!command_buffer_->Initialize()) |
248 return false; | 251 return false; |
| 252 |
249 if (shared_state_handle) | 253 if (shared_state_handle) |
250 *shared_state_handle = command_buffer_->GetSharedStateHandle(); | 254 *shared_state_handle = command_buffer_->GetSharedStateHandle(); |
251 if (capabilities) | 255 if (capabilities) |
252 *capabilities = command_buffer_->GetCapabilities(); | 256 *capabilities = command_buffer_->GetCapabilities(); |
253 if (command_buffer_id) | 257 if (command_buffer_id) |
254 *command_buffer_id = command_buffer_->GetCommandBufferID(); | 258 *command_buffer_id = command_buffer_->GetCommandBufferID(); |
| 259 |
255 mailbox_ = gpu::Mailbox::Generate(); | 260 mailbox_ = gpu::Mailbox::Generate(); |
256 if (!command_buffer_->ProduceFrontBuffer(mailbox_)) | 261 if (!command_buffer_->ProduceFrontBuffer(mailbox_)) |
257 return false; | 262 return false; |
258 | 263 |
259 command_buffer_->SetContextLostCallback(base::Bind( | |
260 &PPB_Graphics3D_Impl::OnContextLost, weak_ptr_factory_.GetWeakPtr())); | |
261 | |
262 command_buffer_->SetOnConsoleMessageCallback(base::Bind( | |
263 &PPB_Graphics3D_Impl::OnConsoleMessage, weak_ptr_factory_.GetWeakPtr())); | |
264 return true; | 264 return true; |
265 } | 265 } |
266 | 266 |
267 void PPB_Graphics3D_Impl::OnConsoleMessage(const std::string& message, int id) { | 267 void PPB_Graphics3D_Impl::OnGpuControlErrorMessage(const char* message, |
| 268 int32_t id) { |
268 if (!bound_to_instance_) | 269 if (!bound_to_instance_) |
269 return; | 270 return; |
270 WebPluginContainer* container = | 271 WebPluginContainer* container = |
271 HostGlobals::Get()->GetInstance(pp_instance())->container(); | 272 HostGlobals::Get()->GetInstance(pp_instance())->container(); |
272 if (!container) | 273 if (!container) |
273 return; | 274 return; |
274 WebLocalFrame* frame = container->element().document().frame(); | 275 WebLocalFrame* frame = container->element().document().frame(); |
275 if (!frame) | 276 if (!frame) |
276 return; | 277 return; |
277 WebConsoleMessage console_message = WebConsoleMessage( | 278 WebConsoleMessage console_message = WebConsoleMessage( |
278 WebConsoleMessage::LevelError, WebString(base::UTF8ToUTF16(message))); | 279 WebConsoleMessage::LevelError, WebString(base::UTF8ToUTF16(message))); |
279 frame->addMessageToConsole(console_message); | 280 frame->addMessageToConsole(console_message); |
280 } | 281 } |
281 | 282 |
282 void PPB_Graphics3D_Impl::OnSwapBuffers() { | 283 void PPB_Graphics3D_Impl::OnGpuControlLostContext() { |
283 if (HasPendingSwap()) { | 284 // Don't need to check for null from GetPluginInstance since when we're |
284 // If we're off-screen, no need to trigger and wait for compositing. | |
285 // Just send the swap-buffers ACK to the plugin immediately. | |
286 commit_pending_ = false; | |
287 SwapBuffersACK(PP_OK); | |
288 } | |
289 } | |
290 | |
291 void PPB_Graphics3D_Impl::OnContextLost() { | |
292 // Don't need to check for NULL from GetPluginInstance since when we're | |
293 // bound, we know our instance is valid. | 285 // bound, we know our instance is valid. |
294 if (bound_to_instance_) { | 286 if (bound_to_instance_) { |
295 HostGlobals::Get()->GetInstance(pp_instance())->BindGraphics(pp_instance(), | 287 HostGlobals::Get()->GetInstance(pp_instance())->BindGraphics(pp_instance(), |
296 0); | 288 0); |
297 } | 289 } |
298 | 290 |
299 // Send context lost to plugin. This may have been caused by a PPAPI call, so | 291 // Send context lost to plugin. This may have been caused by a PPAPI call, so |
300 // avoid re-entering. | 292 // avoid re-entering. |
301 base::ThreadTaskRunnerHandle::Get()->PostTask( | 293 base::ThreadTaskRunnerHandle::Get()->PostTask( |
302 FROM_HERE, base::Bind(&PPB_Graphics3D_Impl::SendContextLost, | 294 FROM_HERE, base::Bind(&PPB_Graphics3D_Impl::SendContextLost, |
303 weak_ptr_factory_.GetWeakPtr())); | 295 weak_ptr_factory_.GetWeakPtr())); |
304 } | 296 } |
305 | 297 |
| 298 void PPB_Graphics3D_Impl::OnSwapBuffers() { |
| 299 if (HasPendingSwap()) { |
| 300 // If we're off-screen, no need to trigger and wait for compositing. |
| 301 // Just send the swap-buffers ACK to the plugin immediately. |
| 302 commit_pending_ = false; |
| 303 SwapBuffersACK(PP_OK); |
| 304 } |
| 305 } |
| 306 |
306 void PPB_Graphics3D_Impl::SendContextLost() { | 307 void PPB_Graphics3D_Impl::SendContextLost() { |
307 // By the time we run this, the instance may have been deleted, or in the | 308 // By the time we run this, the instance may have been deleted, or in the |
308 // process of being deleted. Even in the latter case, we don't want to send a | 309 // process of being deleted. Even in the latter case, we don't want to send a |
309 // callback after DidDestroy. | 310 // callback after DidDestroy. |
310 PepperPluginInstanceImpl* instance = | 311 PepperPluginInstanceImpl* instance = |
311 HostGlobals::Get()->GetInstance(pp_instance()); | 312 HostGlobals::Get()->GetInstance(pp_instance()); |
312 if (!instance || !instance->container()) | 313 if (!instance || !instance->container()) |
313 return; | 314 return; |
314 | 315 |
315 // This PPB_Graphics3D_Impl could be deleted during the call to | 316 // This PPB_Graphics3D_Impl could be deleted during the call to |
316 // GetPluginInterface (which sends a sync message in some cases). We still | 317 // GetPluginInterface (which sends a sync message in some cases). We still |
317 // send the Graphics3DContextLost to the plugin; the instance may care about | 318 // send the Graphics3DContextLost to the plugin; the instance may care about |
318 // that event even though this context has been destroyed. | 319 // that event even though this context has been destroyed. |
319 PP_Instance this_pp_instance = pp_instance(); | 320 PP_Instance this_pp_instance = pp_instance(); |
320 const PPP_Graphics3D* ppp_graphics_3d = static_cast<const PPP_Graphics3D*>( | 321 const PPP_Graphics3D* ppp_graphics_3d = static_cast<const PPP_Graphics3D*>( |
321 instance->module()->GetPluginInterface(PPP_GRAPHICS_3D_INTERFACE)); | 322 instance->module()->GetPluginInterface(PPP_GRAPHICS_3D_INTERFACE)); |
322 // We have to check *again* that the instance exists, because it could have | 323 // We have to check *again* that the instance exists, because it could have |
323 // been deleted during GetPluginInterface(). Even the PluginModule could be | 324 // been deleted during GetPluginInterface(). Even the PluginModule could be |
324 // deleted, but in that case, the instance should also be gone, so the | 325 // deleted, but in that case, the instance should also be gone, so the |
325 // GetInstance check covers both cases. | 326 // GetInstance check covers both cases. |
326 if (ppp_graphics_3d && HostGlobals::Get()->GetInstance(this_pp_instance)) | 327 if (ppp_graphics_3d && HostGlobals::Get()->GetInstance(this_pp_instance)) |
327 ppp_graphics_3d->Graphics3DContextLost(this_pp_instance); | 328 ppp_graphics_3d->Graphics3DContextLost(this_pp_instance); |
328 } | 329 } |
329 | 330 |
330 } // namespace content | 331 } // namespace content |
OLD | NEW |