| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 // Unset the client before the command_buffer_ is destroyed, similar to how | 50 // Unset the client before the command_buffer_ is destroyed, similar to how |
| 51 // WeakPtrFactory invalidates before it. | 51 // WeakPtrFactory invalidates before it. |
| 52 if (command_buffer_) | 52 if (command_buffer_) |
| 53 command_buffer_->SetGpuControlClient(nullptr); | 53 command_buffer_->SetGpuControlClient(nullptr); |
| 54 } | 54 } |
| 55 | 55 |
| 56 // static | 56 // static |
| 57 PP_Resource PPB_Graphics3D_Impl::CreateRaw( | 57 PP_Resource PPB_Graphics3D_Impl::CreateRaw( |
| 58 PP_Instance instance, | 58 PP_Instance instance, |
| 59 PP_Resource share_context, | 59 PP_Resource share_context, |
| 60 const int32_t* attrib_list, | 60 const gpu::gles2::ContextCreationAttribHelper& attrib_helper, |
| 61 gpu::Capabilities* capabilities, | 61 gpu::Capabilities* capabilities, |
| 62 base::SharedMemoryHandle* shared_state_handle, | 62 base::SharedMemoryHandle* shared_state_handle, |
| 63 gpu::CommandBufferId* command_buffer_id) { | 63 gpu::CommandBufferId* command_buffer_id) { |
| 64 PPB_Graphics3D_API* share_api = NULL; | 64 PPB_Graphics3D_API* share_api = NULL; |
| 65 if (share_context) { | 65 if (share_context) { |
| 66 EnterResourceNoLock<PPB_Graphics3D_API> enter(share_context, true); | 66 EnterResourceNoLock<PPB_Graphics3D_API> enter(share_context, true); |
| 67 if (enter.failed()) | 67 if (enter.failed()) |
| 68 return 0; | 68 return 0; |
| 69 share_api = enter.object(); | 69 share_api = enter.object(); |
| 70 } | 70 } |
| 71 scoped_refptr<PPB_Graphics3D_Impl> graphics_3d( | 71 scoped_refptr<PPB_Graphics3D_Impl> graphics_3d( |
| 72 new PPB_Graphics3D_Impl(instance)); | 72 new PPB_Graphics3D_Impl(instance)); |
| 73 if (!graphics_3d->InitRaw(share_api, attrib_list, capabilities, | 73 if (!graphics_3d->InitRaw(share_api, attrib_helper, capabilities, |
| 74 shared_state_handle, command_buffer_id)) | 74 shared_state_handle, command_buffer_id)) |
| 75 return 0; | 75 return 0; |
| 76 return graphics_3d->GetReference(); | 76 return graphics_3d->GetReference(); |
| 77 } | 77 } |
| 78 | 78 |
| 79 PP_Bool PPB_Graphics3D_Impl::SetGetBuffer(int32_t transfer_buffer_id) { | 79 PP_Bool PPB_Graphics3D_Impl::SetGetBuffer(int32_t transfer_buffer_id) { |
| 80 GetCommandBuffer()->SetGetBuffer(transfer_buffer_id); | 80 GetCommandBuffer()->SetGetBuffer(transfer_buffer_id); |
| 81 return PP_TRUE; | 81 return PP_TRUE; |
| 82 } | 82 } |
| 83 | 83 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 } else { | 183 } else { |
| 184 // Wait for the command to complete on the GPU to allow for throttling. | 184 // Wait for the command to complete on the GPU to allow for throttling. |
| 185 command_buffer_->SignalSyncToken( | 185 command_buffer_->SignalSyncToken( |
| 186 sync_token, base::Bind(&PPB_Graphics3D_Impl::OnSwapBuffers, | 186 sync_token, base::Bind(&PPB_Graphics3D_Impl::OnSwapBuffers, |
| 187 weak_ptr_factory_.GetWeakPtr())); | 187 weak_ptr_factory_.GetWeakPtr())); |
| 188 } | 188 } |
| 189 | 189 |
| 190 return PP_OK_COMPLETIONPENDING; | 190 return PP_OK_COMPLETIONPENDING; |
| 191 } | 191 } |
| 192 | 192 |
| 193 bool PPB_Graphics3D_Impl::InitRaw(PPB_Graphics3D_API* share_context, | 193 bool PPB_Graphics3D_Impl::InitRaw( |
| 194 const int32_t* attrib_list, | 194 PPB_Graphics3D_API* share_context, |
| 195 gpu::Capabilities* capabilities, | 195 const gpu::gles2::ContextCreationAttribHelper& attrib_helper, |
| 196 base::SharedMemoryHandle* shared_state_handle, | 196 gpu::Capabilities* capabilities, |
| 197 gpu::CommandBufferId* command_buffer_id) { | 197 base::SharedMemoryHandle* shared_state_handle, |
| 198 gpu::CommandBufferId* command_buffer_id) { |
| 198 PepperPluginInstanceImpl* plugin_instance = | 199 PepperPluginInstanceImpl* plugin_instance = |
| 199 HostGlobals::Get()->GetInstance(pp_instance()); | 200 HostGlobals::Get()->GetInstance(pp_instance()); |
| 200 if (!plugin_instance) | 201 if (!plugin_instance) |
| 201 return false; | 202 return false; |
| 202 | 203 |
| 203 RenderView* render_view = plugin_instance->GetRenderView(); | 204 RenderView* render_view = plugin_instance->GetRenderView(); |
| 204 if (!render_view) | 205 if (!render_view) |
| 205 return false; | 206 return false; |
| 206 | 207 |
| 207 const WebPreferences& prefs = render_view->GetWebkitPreferences(); | 208 const WebPreferences& prefs = render_view->GetWebkitPreferences(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 218 RenderThreadImpl* render_thread = RenderThreadImpl::current(); | 219 RenderThreadImpl* render_thread = RenderThreadImpl::current(); |
| 219 if (!render_thread) | 220 if (!render_thread) |
| 220 return false; | 221 return false; |
| 221 | 222 |
| 222 scoped_refptr<gpu::GpuChannelHost> channel = | 223 scoped_refptr<gpu::GpuChannelHost> channel = |
| 223 render_thread->EstablishGpuChannelSync( | 224 render_thread->EstablishGpuChannelSync( |
| 224 CAUSE_FOR_GPU_LAUNCH_PEPPERPLATFORMCONTEXT3DIMPL_INITIALIZE); | 225 CAUSE_FOR_GPU_LAUNCH_PEPPERPLATFORMCONTEXT3DIMPL_INITIALIZE); |
| 225 if (!channel) | 226 if (!channel) |
| 226 return false; | 227 return false; |
| 227 | 228 |
| 228 gpu::gles2::ContextCreationAttribHelper attrib_helper; | 229 has_alpha_ = attrib_helper.alpha_size > 0; |
| 229 std::vector<int32_t> attribs; | |
| 230 attrib_helper.gpu_preference = gl::PreferDiscreteGpu; | |
| 231 // TODO(alokp): Change CommandBufferProxyImpl::Create() | |
| 232 // interface to accept width and height in the attrib_list so that | |
| 233 // we do not need to filter for width and height here. | |
| 234 if (attrib_list) { | |
| 235 for (const int32_t* attr = attrib_list; attr[0] != PP_GRAPHICS3DATTRIB_NONE; | |
| 236 attr += 2) { | |
| 237 switch (attr[0]) { | |
| 238 case PP_GRAPHICS3DATTRIB_WIDTH: | |
| 239 attrib_helper.offscreen_framebuffer_size.set_width(attr[1]); | |
| 240 break; | |
| 241 case PP_GRAPHICS3DATTRIB_HEIGHT: | |
| 242 attrib_helper.offscreen_framebuffer_size.set_height(attr[1]); | |
| 243 break; | |
| 244 case PP_GRAPHICS3DATTRIB_GPU_PREFERENCE: | |
| 245 attrib_helper.gpu_preference = | |
| 246 (attr[1] == PP_GRAPHICS3DATTRIB_GPU_PREFERENCE_LOW_POWER) | |
| 247 ? gl::PreferIntegratedGpu | |
| 248 : gl::PreferDiscreteGpu; | |
| 249 break; | |
| 250 case PP_GRAPHICS3DATTRIB_ALPHA_SIZE: | |
| 251 has_alpha_ = attr[1] > 0; | |
| 252 // fall-through | |
| 253 default: | |
| 254 attribs.push_back(attr[0]); | |
| 255 attribs.push_back(attr[1]); | |
| 256 break; | |
| 257 } | |
| 258 } | |
| 259 attribs.push_back(PP_GRAPHICS3DATTRIB_NONE); | |
| 260 } | |
| 261 if (!attrib_helper.Parse(attribs)) | |
| 262 return false; | |
| 263 | 230 |
| 264 gpu::CommandBufferProxyImpl* share_buffer = NULL; | 231 gpu::CommandBufferProxyImpl* share_buffer = NULL; |
| 265 if (share_context) { | 232 if (share_context) { |
| 266 PPB_Graphics3D_Impl* share_graphics = | 233 PPB_Graphics3D_Impl* share_graphics = |
| 267 static_cast<PPB_Graphics3D_Impl*>(share_context); | 234 static_cast<PPB_Graphics3D_Impl*>(share_context); |
| 268 share_buffer = share_graphics->GetCommandBufferProxy(); | 235 share_buffer = share_graphics->GetCommandBufferProxy(); |
| 269 } | 236 } |
| 270 | 237 |
| 271 command_buffer_ = gpu::CommandBufferProxyImpl::Create( | 238 command_buffer_ = gpu::CommandBufferProxyImpl::Create( |
| 272 std::move(channel), gpu::kNullSurfaceHandle, share_buffer, | 239 std::move(channel), gpu::kNullSurfaceHandle, share_buffer, |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 if (!mailboxes_to_reuse_.empty()) { | 332 if (!mailboxes_to_reuse_.empty()) { |
| 366 gpu::Mailbox mailbox = mailboxes_to_reuse_.back(); | 333 gpu::Mailbox mailbox = mailboxes_to_reuse_.back(); |
| 367 mailboxes_to_reuse_.pop_back(); | 334 mailboxes_to_reuse_.pop_back(); |
| 368 return mailbox; | 335 return mailbox; |
| 369 } | 336 } |
| 370 | 337 |
| 371 return gpu::Mailbox::Generate(); | 338 return gpu::Mailbox::Generate(); |
| 372 } | 339 } |
| 373 | 340 |
| 374 } // namespace content | 341 } // namespace content |
| OLD | NEW |