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