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())); | |
no sievers
2016/04/08 18:11:45
Unlike PepeprVideoEncoderHost, here the WeakPtr fa
danakj
2016/04/08 18:38:58
Sure, done.
| |
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 #if DCHECK_IS_ON() |
284 // If we're off-screen, no need to trigger and wait for compositing. | 285 // This should never occur more than once. |
285 // Just send the swap-buffers ACK to the plugin immediately. | 286 DCHECK(!lost_context_); |
286 commit_pending_ = false; | 287 lost_context_ = true; |
287 SwapBuffersACK(PP_OK); | 288 #endif |
288 } | |
289 } | |
290 | 289 |
291 void PPB_Graphics3D_Impl::OnContextLost() { | 290 // 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. | 291 // bound, we know our instance is valid. |
294 if (bound_to_instance_) { | 292 if (bound_to_instance_) { |
295 HostGlobals::Get()->GetInstance(pp_instance())->BindGraphics(pp_instance(), | 293 HostGlobals::Get()->GetInstance(pp_instance())->BindGraphics(pp_instance(), |
296 0); | 294 0); |
297 } | 295 } |
298 | 296 |
299 // Send context lost to plugin. This may have been caused by a PPAPI call, so | 297 // Send context lost to plugin. This may have been caused by a PPAPI call, so |
300 // avoid re-entering. | 298 // avoid re-entering. |
301 base::ThreadTaskRunnerHandle::Get()->PostTask( | 299 base::ThreadTaskRunnerHandle::Get()->PostTask( |
302 FROM_HERE, base::Bind(&PPB_Graphics3D_Impl::SendContextLost, | 300 FROM_HERE, base::Bind(&PPB_Graphics3D_Impl::SendContextLost, |
303 weak_ptr_factory_.GetWeakPtr())); | 301 weak_ptr_factory_.GetWeakPtr())); |
304 } | 302 } |
305 | 303 |
304 void PPB_Graphics3D_Impl::OnSwapBuffers() { | |
305 if (HasPendingSwap()) { | |
306 // If we're off-screen, no need to trigger and wait for compositing. | |
307 // Just send the swap-buffers ACK to the plugin immediately. | |
308 commit_pending_ = false; | |
309 SwapBuffersACK(PP_OK); | |
310 } | |
311 } | |
312 | |
306 void PPB_Graphics3D_Impl::SendContextLost() { | 313 void PPB_Graphics3D_Impl::SendContextLost() { |
307 // By the time we run this, the instance may have been deleted, or in the | 314 // 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 | 315 // process of being deleted. Even in the latter case, we don't want to send a |
309 // callback after DidDestroy. | 316 // callback after DidDestroy. |
310 PepperPluginInstanceImpl* instance = | 317 PepperPluginInstanceImpl* instance = |
311 HostGlobals::Get()->GetInstance(pp_instance()); | 318 HostGlobals::Get()->GetInstance(pp_instance()); |
312 if (!instance || !instance->container()) | 319 if (!instance || !instance->container()) |
313 return; | 320 return; |
314 | 321 |
315 // This PPB_Graphics3D_Impl could be deleted during the call to | 322 // This PPB_Graphics3D_Impl could be deleted during the call to |
316 // GetPluginInterface (which sends a sync message in some cases). We still | 323 // GetPluginInterface (which sends a sync message in some cases). We still |
317 // send the Graphics3DContextLost to the plugin; the instance may care about | 324 // send the Graphics3DContextLost to the plugin; the instance may care about |
318 // that event even though this context has been destroyed. | 325 // that event even though this context has been destroyed. |
319 PP_Instance this_pp_instance = pp_instance(); | 326 PP_Instance this_pp_instance = pp_instance(); |
320 const PPP_Graphics3D* ppp_graphics_3d = static_cast<const PPP_Graphics3D*>( | 327 const PPP_Graphics3D* ppp_graphics_3d = static_cast<const PPP_Graphics3D*>( |
321 instance->module()->GetPluginInterface(PPP_GRAPHICS_3D_INTERFACE)); | 328 instance->module()->GetPluginInterface(PPP_GRAPHICS_3D_INTERFACE)); |
322 // We have to check *again* that the instance exists, because it could have | 329 // We have to check *again* that the instance exists, because it could have |
323 // been deleted during GetPluginInterface(). Even the PluginModule could be | 330 // been deleted during GetPluginInterface(). Even the PluginModule could be |
324 // deleted, but in that case, the instance should also be gone, so the | 331 // deleted, but in that case, the instance should also be gone, so the |
325 // GetInstance check covers both cases. | 332 // GetInstance check covers both cases. |
326 if (ppp_graphics_3d && HostGlobals::Get()->GetInstance(this_pp_instance)) | 333 if (ppp_graphics_3d && HostGlobals::Get()->GetInstance(this_pp_instance)) |
327 ppp_graphics_3d->Graphics3DContextLost(this_pp_instance); | 334 ppp_graphics_3d->Graphics3DContextLost(this_pp_instance); |
328 } | 335 } |
329 | 336 |
330 } // namespace content | 337 } // namespace content |
OLD | NEW |