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