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" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 share_api = enter.object(); | 74 share_api = enter.object(); |
75 } | 75 } |
76 scoped_refptr<PPB_Graphics3D_Impl> graphics_3d( | 76 scoped_refptr<PPB_Graphics3D_Impl> graphics_3d( |
77 new PPB_Graphics3D_Impl(instance)); | 77 new PPB_Graphics3D_Impl(instance)); |
78 if (!graphics_3d->Init(share_api, attrib_list)) | 78 if (!graphics_3d->Init(share_api, attrib_list)) |
79 return 0; | 79 return 0; |
80 return graphics_3d->GetReference(); | 80 return graphics_3d->GetReference(); |
81 } | 81 } |
82 | 82 |
83 // static | 83 // static |
84 PP_Resource PPB_Graphics3D_Impl::CreateRaw(PP_Instance instance, | 84 PP_Resource PPB_Graphics3D_Impl::CreateRaw( |
85 PP_Resource share_context, | 85 PP_Instance instance, |
86 const int32_t* attrib_list) { | 86 PP_Resource share_context, |
| 87 const int32_t* attrib_list, |
| 88 base::SharedMemoryHandle* shared_state_handle) { |
87 PPB_Graphics3D_API* share_api = NULL; | 89 PPB_Graphics3D_API* share_api = NULL; |
88 if (share_context) { | 90 if (share_context) { |
89 EnterResourceNoLock<PPB_Graphics3D_API> enter(share_context, true); | 91 EnterResourceNoLock<PPB_Graphics3D_API> enter(share_context, true); |
90 if (enter.failed()) | 92 if (enter.failed()) |
91 return 0; | 93 return 0; |
92 share_api = enter.object(); | 94 share_api = enter.object(); |
93 } | 95 } |
94 scoped_refptr<PPB_Graphics3D_Impl> graphics_3d( | 96 scoped_refptr<PPB_Graphics3D_Impl> graphics_3d( |
95 new PPB_Graphics3D_Impl(instance)); | 97 new PPB_Graphics3D_Impl(instance)); |
96 if (!graphics_3d->InitRaw(share_api, attrib_list)) | 98 if (!graphics_3d->InitRaw(share_api, attrib_list, shared_state_handle)) |
97 return 0; | 99 return 0; |
98 return graphics_3d->GetReference(); | 100 return graphics_3d->GetReference(); |
99 } | 101 } |
100 | 102 |
101 PP_Bool PPB_Graphics3D_Impl::SetGetBuffer(int32_t transfer_buffer_id) { | 103 PP_Bool PPB_Graphics3D_Impl::SetGetBuffer(int32_t transfer_buffer_id) { |
102 GetCommandBuffer()->SetGetBuffer(transfer_buffer_id); | 104 GetCommandBuffer()->SetGetBuffer(transfer_buffer_id); |
103 return PP_TRUE; | 105 return PP_TRUE; |
104 } | 106 } |
105 | 107 |
106 scoped_refptr<gpu::Buffer> PPB_Graphics3D_Impl::CreateTransferBuffer( | 108 scoped_refptr<gpu::Buffer> PPB_Graphics3D_Impl::CreateTransferBuffer( |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 // Wait for the command to complete on the GPU to allow for throttling. | 202 // Wait for the command to complete on the GPU to allow for throttling. |
201 command_buffer_->Echo(base::Bind(&PPB_Graphics3D_Impl::OnSwapBuffers, | 203 command_buffer_->Echo(base::Bind(&PPB_Graphics3D_Impl::OnSwapBuffers, |
202 weak_ptr_factory_.GetWeakPtr())); | 204 weak_ptr_factory_.GetWeakPtr())); |
203 } | 205 } |
204 | 206 |
205 return PP_OK_COMPLETIONPENDING; | 207 return PP_OK_COMPLETIONPENDING; |
206 } | 208 } |
207 | 209 |
208 bool PPB_Graphics3D_Impl::Init(PPB_Graphics3D_API* share_context, | 210 bool PPB_Graphics3D_Impl::Init(PPB_Graphics3D_API* share_context, |
209 const int32_t* attrib_list) { | 211 const int32_t* attrib_list) { |
210 if (!InitRaw(share_context, attrib_list)) | 212 if (!InitRaw(share_context, attrib_list, NULL)) |
211 return false; | 213 return false; |
212 | 214 |
213 gpu::gles2::GLES2Implementation* share_gles2 = NULL; | 215 gpu::gles2::GLES2Implementation* share_gles2 = NULL; |
214 if (share_context) { | 216 if (share_context) { |
215 share_gles2 = | 217 share_gles2 = |
216 static_cast<PPB_Graphics3D_Shared*>(share_context)->gles2_impl(); | 218 static_cast<PPB_Graphics3D_Shared*>(share_context)->gles2_impl(); |
217 } | 219 } |
218 | 220 |
219 return CreateGLES2Impl(kCommandBufferSize, kTransferBufferSize, share_gles2); | 221 return CreateGLES2Impl(kCommandBufferSize, kTransferBufferSize, share_gles2); |
220 } | 222 } |
221 | 223 |
222 bool PPB_Graphics3D_Impl::InitRaw(PPB_Graphics3D_API* share_context, | 224 bool PPB_Graphics3D_Impl::InitRaw( |
223 const int32_t* attrib_list) { | 225 PPB_Graphics3D_API* share_context, |
| 226 const int32_t* attrib_list, |
| 227 base::SharedMemoryHandle* shared_state_handle) { |
224 PepperPluginInstanceImpl* plugin_instance = | 228 PepperPluginInstanceImpl* plugin_instance = |
225 HostGlobals::Get()->GetInstance(pp_instance()); | 229 HostGlobals::Get()->GetInstance(pp_instance()); |
226 if (!plugin_instance) | 230 if (!plugin_instance) |
227 return false; | 231 return false; |
228 | 232 |
229 const WebPreferences& prefs = | 233 const WebPreferences& prefs = |
230 static_cast<RenderViewImpl*>(plugin_instance->GetRenderView()) | 234 static_cast<RenderViewImpl*>(plugin_instance->GetRenderView()) |
231 ->webkit_preferences(); | 235 ->webkit_preferences(); |
232 // 3D access might be disabled or blacklisted. | 236 // 3D access might be disabled or blacklisted. |
233 if (!prefs.pepper_3d_enabled) | 237 if (!prefs.pepper_3d_enabled) |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 static_cast<PPB_Graphics3D_Impl*>(share_context); | 286 static_cast<PPB_Graphics3D_Impl*>(share_context); |
283 share_buffer = share_graphics->command_buffer_; | 287 share_buffer = share_graphics->command_buffer_; |
284 } | 288 } |
285 | 289 |
286 command_buffer_ = channel_->CreateOffscreenCommandBuffer( | 290 command_buffer_ = channel_->CreateOffscreenCommandBuffer( |
287 surface_size, share_buffer, attribs, GURL::EmptyGURL(), gpu_preference); | 291 surface_size, share_buffer, attribs, GURL::EmptyGURL(), gpu_preference); |
288 if (!command_buffer_) | 292 if (!command_buffer_) |
289 return false; | 293 return false; |
290 if (!command_buffer_->Initialize()) | 294 if (!command_buffer_->Initialize()) |
291 return false; | 295 return false; |
| 296 if (shared_state_handle) |
| 297 *shared_state_handle = command_buffer_->GetSharedStateHandle(); |
292 mailbox_ = gpu::Mailbox::Generate(); | 298 mailbox_ = gpu::Mailbox::Generate(); |
293 if (!command_buffer_->ProduceFrontBuffer(mailbox_)) | 299 if (!command_buffer_->ProduceFrontBuffer(mailbox_)) |
294 return false; | 300 return false; |
295 sync_point_ = command_buffer_->InsertSyncPoint(); | 301 sync_point_ = command_buffer_->InsertSyncPoint(); |
296 | 302 |
297 command_buffer_->SetChannelErrorCallback(base::Bind( | 303 command_buffer_->SetChannelErrorCallback(base::Bind( |
298 &PPB_Graphics3D_Impl::OnContextLost, weak_ptr_factory_.GetWeakPtr())); | 304 &PPB_Graphics3D_Impl::OnContextLost, weak_ptr_factory_.GetWeakPtr())); |
299 | 305 |
300 command_buffer_->SetOnConsoleMessageCallback(base::Bind( | 306 command_buffer_->SetOnConsoleMessageCallback(base::Bind( |
301 &PPB_Graphics3D_Impl::OnConsoleMessage, weak_ptr_factory_.GetWeakPtr())); | 307 &PPB_Graphics3D_Impl::OnConsoleMessage, weak_ptr_factory_.GetWeakPtr())); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 instance->module()->GetPluginInterface(PPP_GRAPHICS_3D_INTERFACE)); | 366 instance->module()->GetPluginInterface(PPP_GRAPHICS_3D_INTERFACE)); |
361 // We have to check *again* that the instance exists, because it could have | 367 // We have to check *again* that the instance exists, because it could have |
362 // been deleted during GetPluginInterface(). Even the PluginModule could be | 368 // been deleted during GetPluginInterface(). Even the PluginModule could be |
363 // deleted, but in that case, the instance should also be gone, so the | 369 // deleted, but in that case, the instance should also be gone, so the |
364 // GetInstance check covers both cases. | 370 // GetInstance check covers both cases. |
365 if (ppp_graphics_3d && HostGlobals::Get()->GetInstance(this_pp_instance)) | 371 if (ppp_graphics_3d && HostGlobals::Get()->GetInstance(this_pp_instance)) |
366 ppp_graphics_3d->Graphics3DContextLost(this_pp_instance); | 372 ppp_graphics_3d->Graphics3DContextLost(this_pp_instance); |
367 } | 373 } |
368 | 374 |
369 } // namespace content | 375 } // namespace content |
OLD | NEW |