| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 // Unset the client before the command_buffer_ is destroyed, similar to how | 59 // Unset the client before the command_buffer_ is destroyed, similar to how |
| 60 // WeakPtrFactory invalidates before it. | 60 // WeakPtrFactory invalidates before it. |
| 61 if (command_buffer_) | 61 if (command_buffer_) |
| 62 command_buffer_->SetGpuControlClient(nullptr); | 62 command_buffer_->SetGpuControlClient(nullptr); |
| 63 } | 63 } |
| 64 | 64 |
| 65 // static | 65 // static |
| 66 PP_Resource PPB_Graphics3D_Impl::CreateRaw( | 66 PP_Resource PPB_Graphics3D_Impl::CreateRaw( |
| 67 PP_Instance instance, | 67 PP_Instance instance, |
| 68 PP_Resource share_context, | 68 PP_Resource share_context, |
| 69 const int32_t* attrib_list, | 69 const gpu::gles2::ContextCreationAttribHelper& attrib_helper, |
| 70 gpu::Capabilities* capabilities, | 70 gpu::Capabilities* capabilities, |
| 71 base::SharedMemoryHandle* shared_state_handle, | 71 base::SharedMemoryHandle* shared_state_handle, |
| 72 gpu::CommandBufferId* command_buffer_id) { | 72 gpu::CommandBufferId* command_buffer_id) { |
| 73 PPB_Graphics3D_API* share_api = NULL; | 73 PPB_Graphics3D_API* share_api = NULL; |
| 74 if (share_context) { | 74 if (share_context) { |
| 75 EnterResourceNoLock<PPB_Graphics3D_API> enter(share_context, true); | 75 EnterResourceNoLock<PPB_Graphics3D_API> enter(share_context, true); |
| 76 if (enter.failed()) | 76 if (enter.failed()) |
| 77 return 0; | 77 return 0; |
| 78 share_api = enter.object(); | 78 share_api = enter.object(); |
| 79 } | 79 } |
| 80 scoped_refptr<PPB_Graphics3D_Impl> graphics_3d( | 80 scoped_refptr<PPB_Graphics3D_Impl> graphics_3d( |
| 81 new PPB_Graphics3D_Impl(instance)); | 81 new PPB_Graphics3D_Impl(instance)); |
| 82 if (!graphics_3d->InitRaw(share_api, attrib_list, capabilities, | 82 if (!graphics_3d->InitRaw(share_api, attrib_helper, capabilities, |
| 83 shared_state_handle, command_buffer_id)) | 83 shared_state_handle, command_buffer_id)) |
| 84 return 0; | 84 return 0; |
| 85 return graphics_3d->GetReference(); | 85 return graphics_3d->GetReference(); |
| 86 } | 86 } |
| 87 | 87 |
| 88 PP_Bool PPB_Graphics3D_Impl::SetGetBuffer(int32_t transfer_buffer_id) { | 88 PP_Bool PPB_Graphics3D_Impl::SetGetBuffer(int32_t transfer_buffer_id) { |
| 89 GetCommandBuffer()->SetGetBuffer(transfer_buffer_id); | 89 GetCommandBuffer()->SetGetBuffer(transfer_buffer_id); |
| 90 return PP_TRUE; | 90 return PP_TRUE; |
| 91 } | 91 } |
| 92 | 92 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 } else { | 202 } else { |
| 203 // Wait for the command to complete on the GPU to allow for throttling. | 203 // Wait for the command to complete on the GPU to allow for throttling. |
| 204 command_buffer_->SignalSyncToken( | 204 command_buffer_->SignalSyncToken( |
| 205 sync_token, base::Bind(&PPB_Graphics3D_Impl::OnSwapBuffers, | 205 sync_token, base::Bind(&PPB_Graphics3D_Impl::OnSwapBuffers, |
| 206 weak_ptr_factory_.GetWeakPtr())); | 206 weak_ptr_factory_.GetWeakPtr())); |
| 207 } | 207 } |
| 208 | 208 |
| 209 return PP_OK_COMPLETIONPENDING; | 209 return PP_OK_COMPLETIONPENDING; |
| 210 } | 210 } |
| 211 | 211 |
| 212 bool PPB_Graphics3D_Impl::InitRaw(PPB_Graphics3D_API* share_context, | 212 bool PPB_Graphics3D_Impl::InitRaw( |
| 213 const int32_t* attrib_list, | 213 PPB_Graphics3D_API* share_context, |
| 214 gpu::Capabilities* capabilities, | 214 const gpu::gles2::ContextCreationAttribHelper& requested_attribs, |
| 215 base::SharedMemoryHandle* shared_state_handle, | 215 gpu::Capabilities* capabilities, |
| 216 gpu::CommandBufferId* command_buffer_id) { | 216 base::SharedMemoryHandle* shared_state_handle, |
| 217 gpu::CommandBufferId* command_buffer_id) { |
| 217 PepperPluginInstanceImpl* plugin_instance = | 218 PepperPluginInstanceImpl* plugin_instance = |
| 218 HostGlobals::Get()->GetInstance(pp_instance()); | 219 HostGlobals::Get()->GetInstance(pp_instance()); |
| 219 if (!plugin_instance) | 220 if (!plugin_instance) |
| 220 return false; | 221 return false; |
| 221 | 222 |
| 222 RenderView* render_view = plugin_instance->GetRenderView(); | 223 RenderView* render_view = plugin_instance->GetRenderView(); |
| 223 if (!render_view) | 224 if (!render_view) |
| 224 return false; | 225 return false; |
| 225 | 226 |
| 226 const WebPreferences& prefs = render_view->GetWebkitPreferences(); | 227 const WebPreferences& prefs = render_view->GetWebkitPreferences(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 237 RenderThreadImpl* render_thread = RenderThreadImpl::current(); | 238 RenderThreadImpl* render_thread = RenderThreadImpl::current(); |
| 238 if (!render_thread) | 239 if (!render_thread) |
| 239 return false; | 240 return false; |
| 240 | 241 |
| 241 scoped_refptr<gpu::GpuChannelHost> channel = | 242 scoped_refptr<gpu::GpuChannelHost> channel = |
| 242 render_thread->EstablishGpuChannelSync( | 243 render_thread->EstablishGpuChannelSync( |
| 243 CAUSE_FOR_GPU_LAUNCH_PEPPERPLATFORMCONTEXT3DIMPL_INITIALIZE); | 244 CAUSE_FOR_GPU_LAUNCH_PEPPERPLATFORMCONTEXT3DIMPL_INITIALIZE); |
| 244 if (!channel) | 245 if (!channel) |
| 245 return false; | 246 return false; |
| 246 | 247 |
| 247 gpu::gles2::ContextCreationAttribHelper attrib_helper; | 248 has_alpha_ = requested_attribs.alpha_size > 0; |
| 248 std::vector<int32_t> attribs; | 249 |
| 249 attrib_helper.gpu_preference = gl::PreferDiscreteGpu; | 250 gpu::gles2::ContextCreationAttribHelper attrib_helper = requested_attribs; |
| 250 // TODO(alokp): Change CommandBufferProxyImpl::Create() | |
| 251 // interface to accept width and height in the attrib_list so that | |
| 252 // we do not need to filter for width and height here. | |
| 253 if (attrib_list) { | |
| 254 for (const int32_t* attr = attrib_list; attr[0] != PP_GRAPHICS3DATTRIB_NONE; | |
| 255 attr += 2) { | |
| 256 switch (attr[0]) { | |
| 257 case PP_GRAPHICS3DATTRIB_WIDTH: | |
| 258 attrib_helper.offscreen_framebuffer_size.set_width(attr[1]); | |
| 259 break; | |
| 260 case PP_GRAPHICS3DATTRIB_HEIGHT: | |
| 261 attrib_helper.offscreen_framebuffer_size.set_height(attr[1]); | |
| 262 break; | |
| 263 case PP_GRAPHICS3DATTRIB_GPU_PREFERENCE: | |
| 264 attrib_helper.gpu_preference = | |
| 265 (attr[1] == PP_GRAPHICS3DATTRIB_GPU_PREFERENCE_LOW_POWER) | |
| 266 ? gl::PreferIntegratedGpu | |
| 267 : gl::PreferDiscreteGpu; | |
| 268 break; | |
| 269 case PP_GRAPHICS3DATTRIB_ALPHA_SIZE: | |
| 270 has_alpha_ = attr[1] > 0; | |
| 271 // fall-through | |
| 272 default: | |
| 273 attribs.push_back(attr[0]); | |
| 274 attribs.push_back(attr[1]); | |
| 275 break; | |
| 276 } | |
| 277 } | |
| 278 attribs.push_back(PP_GRAPHICS3DATTRIB_NONE); | |
| 279 } | |
| 280 if (!attrib_helper.Parse(attribs)) | |
| 281 return false; | |
| 282 attrib_helper.should_use_native_gmb_for_backbuffer = use_image_chromium_; | 251 attrib_helper.should_use_native_gmb_for_backbuffer = use_image_chromium_; |
| 283 | 252 |
| 284 gpu::CommandBufferProxyImpl* share_buffer = NULL; | 253 gpu::CommandBufferProxyImpl* share_buffer = NULL; |
| 285 if (share_context) { | 254 if (share_context) { |
| 286 PPB_Graphics3D_Impl* share_graphics = | 255 PPB_Graphics3D_Impl* share_graphics = |
| 287 static_cast<PPB_Graphics3D_Impl*>(share_context); | 256 static_cast<PPB_Graphics3D_Impl*>(share_context); |
| 288 share_buffer = share_graphics->GetCommandBufferProxy(); | 257 share_buffer = share_graphics->GetCommandBufferProxy(); |
| 289 } | 258 } |
| 290 | 259 |
| 291 command_buffer_ = gpu::CommandBufferProxyImpl::Create( | 260 command_buffer_ = gpu::CommandBufferProxyImpl::Create( |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 if (!mailboxes_to_reuse_.empty()) { | 356 if (!mailboxes_to_reuse_.empty()) { |
| 388 gpu::Mailbox mailbox = mailboxes_to_reuse_.back(); | 357 gpu::Mailbox mailbox = mailboxes_to_reuse_.back(); |
| 389 mailboxes_to_reuse_.pop_back(); | 358 mailboxes_to_reuse_.pop_back(); |
| 390 return mailbox; | 359 return mailbox; |
| 391 } | 360 } |
| 392 | 361 |
| 393 return gpu::Mailbox::Generate(); | 362 return gpu::Mailbox::Generate(); |
| 394 } | 363 } |
| 395 | 364 |
| 396 } // namespace content | 365 } // namespace content |
| OLD | NEW |