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