| 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 "webkit/plugins/ppapi/ppb_graphics_3d_impl.h" | 5 #include "webkit/plugins/ppapi/ppb_graphics_3d_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "gpu/command_buffer/client/gles2_implementation.h" | 10 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 11 #include "ppapi/c/ppp_graphics_3d.h" | 11 #include "ppapi/c/ppp_graphics_3d.h" |
| 12 #include "ppapi/thunk/enter.h" |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
| 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebConsoleMessage.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebConsoleMessage.h" |
| 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
| 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" |
| 18 #include "webkit/plugins/ppapi/plugin_module.h" | 19 #include "webkit/plugins/ppapi/plugin_module.h" |
| 19 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 20 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| 20 #include "webkit/plugins/ppapi/resource_helper.h" | 21 #include "webkit/plugins/ppapi/resource_helper.h" |
| 21 | 22 |
| 23 using ppapi::thunk::EnterResourceNoLock; |
| 22 using ppapi::thunk::PPB_Graphics3D_API; | 24 using ppapi::thunk::PPB_Graphics3D_API; |
| 23 using WebKit::WebConsoleMessage; | 25 using WebKit::WebConsoleMessage; |
| 24 using WebKit::WebFrame; | 26 using WebKit::WebFrame; |
| 25 using WebKit::WebPluginContainer; | 27 using WebKit::WebPluginContainer; |
| 26 using WebKit::WebString; | 28 using WebKit::WebString; |
| 27 | 29 |
| 28 namespace webkit { | 30 namespace webkit { |
| 29 namespace ppapi { | 31 namespace ppapi { |
| 30 | 32 |
| 31 namespace { | 33 namespace { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 } | 73 } |
| 72 | 74 |
| 73 PPB_Graphics3D_Impl::~PPB_Graphics3D_Impl() { | 75 PPB_Graphics3D_Impl::~PPB_Graphics3D_Impl() { |
| 74 DestroyGLES2Impl(); | 76 DestroyGLES2Impl(); |
| 75 } | 77 } |
| 76 | 78 |
| 77 // static | 79 // static |
| 78 PP_Resource PPB_Graphics3D_Impl::Create(PP_Instance instance, | 80 PP_Resource PPB_Graphics3D_Impl::Create(PP_Instance instance, |
| 79 PP_Resource share_context, | 81 PP_Resource share_context, |
| 80 const int32_t* attrib_list) { | 82 const int32_t* attrib_list) { |
| 83 PPB_Graphics3D_API* share_api = NULL; |
| 84 if (share_context) { |
| 85 EnterResourceNoLock<PPB_Graphics3D_API> enter(share_context, true); |
| 86 if (enter.failed()) |
| 87 return 0; |
| 88 share_api = enter.object(); |
| 89 } |
| 90 |
| 81 scoped_refptr<PPB_Graphics3D_Impl> graphics_3d( | 91 scoped_refptr<PPB_Graphics3D_Impl> graphics_3d( |
| 82 new PPB_Graphics3D_Impl(instance)); | 92 new PPB_Graphics3D_Impl(instance)); |
| 83 if (!graphics_3d->Init(share_context, attrib_list)) | 93 |
| 94 if (!graphics_3d->Init(share_api, attrib_list)) |
| 84 return 0; | 95 return 0; |
| 85 return graphics_3d->GetReference(); | 96 return graphics_3d->GetReference(); |
| 86 } | 97 } |
| 87 | 98 |
| 88 PP_Resource PPB_Graphics3D_Impl::CreateRaw(PP_Instance instance, | 99 PP_Resource PPB_Graphics3D_Impl::CreateRaw(PP_Instance instance, |
| 89 PP_Resource share_context, | 100 PP_Resource share_context, |
| 90 const int32_t* attrib_list) { | 101 const int32_t* attrib_list) { |
| 102 PPB_Graphics3D_API* share_api = NULL; |
| 103 if (share_context) { |
| 104 EnterResourceNoLock<PPB_Graphics3D_API> enter(share_context, true); |
| 105 if (enter.failed()) |
| 106 return 0; |
| 107 share_api = enter.object(); |
| 108 } |
| 91 scoped_refptr<PPB_Graphics3D_Impl> graphics_3d( | 109 scoped_refptr<PPB_Graphics3D_Impl> graphics_3d( |
| 92 new PPB_Graphics3D_Impl(instance)); | 110 new PPB_Graphics3D_Impl(instance)); |
| 93 if (!graphics_3d->InitRaw(share_context, attrib_list)) | 111 if (!graphics_3d->InitRaw(share_api, attrib_list)) |
| 94 return 0; | 112 return 0; |
| 95 return graphics_3d->GetReference(); | 113 return graphics_3d->GetReference(); |
| 96 } | 114 } |
| 97 | 115 |
| 98 PP_Bool PPB_Graphics3D_Impl::InitCommandBuffer() { | 116 PP_Bool PPB_Graphics3D_Impl::InitCommandBuffer() { |
| 99 return PP_FromBool(GetCommandBuffer()->Initialize()); | 117 return PP_FromBool(GetCommandBuffer()->Initialize()); |
| 100 } | 118 } |
| 101 | 119 |
| 102 PP_Bool PPB_Graphics3D_Impl::SetGetBuffer(int32_t transfer_buffer_id) { | 120 PP_Bool PPB_Graphics3D_Impl::SetGetBuffer(int32_t transfer_buffer_id) { |
| 103 GetCommandBuffer()->SetGetBuffer(transfer_buffer_id); | 121 GetCommandBuffer()->SetGetBuffer(transfer_buffer_id); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 } else { | 210 } else { |
| 193 // Wait for the command to complete on the GPU to allow for throttling. | 211 // Wait for the command to complete on the GPU to allow for throttling. |
| 194 platform_context_->Echo(base::Bind(&PPB_Graphics3D_Impl::OnSwapBuffers, | 212 platform_context_->Echo(base::Bind(&PPB_Graphics3D_Impl::OnSwapBuffers, |
| 195 weak_ptr_factory_.GetWeakPtr())); | 213 weak_ptr_factory_.GetWeakPtr())); |
| 196 } | 214 } |
| 197 | 215 |
| 198 | 216 |
| 199 return PP_OK_COMPLETIONPENDING; | 217 return PP_OK_COMPLETIONPENDING; |
| 200 } | 218 } |
| 201 | 219 |
| 202 bool PPB_Graphics3D_Impl::Init(PP_Resource share_context, | 220 bool PPB_Graphics3D_Impl::Init(PPB_Graphics3D_API* share_context, |
| 203 const int32_t* attrib_list) { | 221 const int32_t* attrib_list) { |
| 204 if (!InitRaw(share_context, attrib_list)) | 222 if (!InitRaw(share_context, attrib_list)) |
| 205 return false; | 223 return false; |
| 206 | 224 |
| 207 gpu::CommandBuffer* command_buffer = GetCommandBuffer(); | 225 gpu::CommandBuffer* command_buffer = GetCommandBuffer(); |
| 208 if (!command_buffer->Initialize()) | 226 if (!command_buffer->Initialize()) |
| 209 return false; | 227 return false; |
| 210 | 228 |
| 211 return CreateGLES2Impl(kCommandBufferSize, kTransferBufferSize); | 229 gpu::gles2::GLES2Implementation* share_gles2 = NULL; |
| 230 if (share_context) { |
| 231 share_gles2 = |
| 232 static_cast<PPB_Graphics3D_Shared*>(share_context)->gles2_impl(); |
| 233 } |
| 234 |
| 235 return CreateGLES2Impl(kCommandBufferSize, kTransferBufferSize, |
| 236 share_gles2); |
| 212 } | 237 } |
| 213 | 238 |
| 214 bool PPB_Graphics3D_Impl::InitRaw(PP_Resource share_context, | 239 bool PPB_Graphics3D_Impl::InitRaw(PPB_Graphics3D_API* share_context, |
| 215 const int32_t* attrib_list) { | 240 const int32_t* attrib_list) { |
| 216 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); | 241 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); |
| 217 if (!plugin_instance) | 242 if (!plugin_instance) |
| 218 return false; | 243 return false; |
| 219 | 244 |
| 220 // TODO(alokp): Support shared context. | 245 PluginDelegate::PlatformContext3D* share_platform_context = NULL; |
| 221 DCHECK_EQ(0, share_context); | 246 if (share_context) { |
| 222 if (share_context != 0) | 247 PPB_Graphics3D_Impl* share_graphics = |
| 223 return false; | 248 static_cast<PPB_Graphics3D_Impl*>(share_context); |
| 249 share_platform_context = share_graphics->platform_context(); |
| 250 } |
| 224 | 251 |
| 225 platform_context_.reset(plugin_instance->CreateContext3D()); | 252 platform_context_.reset(plugin_instance->CreateContext3D()); |
| 226 if (!platform_context_.get()) | 253 if (!platform_context_.get()) |
| 227 return false; | 254 return false; |
| 228 | 255 |
| 229 if (!platform_context_->Init(attrib_list)) | 256 if (!platform_context_->Init(attrib_list, share_platform_context)) |
| 230 return false; | 257 return false; |
| 231 | 258 |
| 232 platform_context_->SetContextLostCallback( | 259 platform_context_->SetContextLostCallback( |
| 233 base::Bind(&PPB_Graphics3D_Impl::OnContextLost, | 260 base::Bind(&PPB_Graphics3D_Impl::OnContextLost, |
| 234 weak_ptr_factory_.GetWeakPtr())); | 261 weak_ptr_factory_.GetWeakPtr())); |
| 235 | 262 |
| 236 platform_context_->SetOnConsoleMessageCallback( | 263 platform_context_->SetOnConsoleMessageCallback( |
| 237 base::Bind(&PPB_Graphics3D_Impl::OnConsoleMessage, | 264 base::Bind(&PPB_Graphics3D_Impl::OnConsoleMessage, |
| 238 weak_ptr_factory_.GetWeakPtr())); | 265 weak_ptr_factory_.GetWeakPtr())); |
| 239 return true; | 266 return true; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 const PPP_Graphics3D* ppp_graphics_3d = | 314 const PPP_Graphics3D* ppp_graphics_3d = |
| 288 static_cast<const PPP_Graphics3D*>( | 315 static_cast<const PPP_Graphics3D*>( |
| 289 instance->module()->GetPluginInterface( | 316 instance->module()->GetPluginInterface( |
| 290 PPP_GRAPHICS_3D_INTERFACE)); | 317 PPP_GRAPHICS_3D_INTERFACE)); |
| 291 if (ppp_graphics_3d) | 318 if (ppp_graphics_3d) |
| 292 ppp_graphics_3d->Graphics3DContextLost(pp_instance()); | 319 ppp_graphics_3d->Graphics3DContextLost(pp_instance()); |
| 293 } | 320 } |
| 294 | 321 |
| 295 } // namespace ppapi | 322 } // namespace ppapi |
| 296 } // namespace webkit | 323 } // namespace webkit |
| OLD | NEW |