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" |
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" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
69 commit_pending_(false), | 70 commit_pending_(false), |
70 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 71 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
71 } | 72 } |
72 | 73 |
73 PPB_Graphics3D_Impl::~PPB_Graphics3D_Impl() { | 74 PPB_Graphics3D_Impl::~PPB_Graphics3D_Impl() { |
74 DestroyGLES2Impl(); | 75 DestroyGLES2Impl(); |
75 } | 76 } |
76 | 77 |
77 // static | 78 // static |
78 PP_Resource PPB_Graphics3D_Impl::Create(PP_Instance instance, | 79 PP_Resource PPB_Graphics3D_Impl::Create(PP_Instance instance, |
79 PP_Resource share_context, | 80 PPB_Graphics3D_API* share_context, |
80 const int32_t* attrib_list) { | 81 const int32_t* attrib_list) { |
81 scoped_refptr<PPB_Graphics3D_Impl> graphics_3d( | 82 scoped_refptr<PPB_Graphics3D_Impl> graphics_3d( |
82 new PPB_Graphics3D_Impl(instance)); | 83 new PPB_Graphics3D_Impl(instance)); |
83 if (!graphics_3d->Init(share_context, attrib_list)) | 84 if (!graphics_3d->Init(share_context, attrib_list)) |
84 return 0; | 85 return 0; |
85 return graphics_3d->GetReference(); | 86 return graphics_3d->GetReference(); |
86 } | 87 } |
87 | 88 |
88 PP_Resource PPB_Graphics3D_Impl::CreateRaw(PP_Instance instance, | 89 PP_Resource PPB_Graphics3D_Impl::CreateRaw(PP_Instance instance, |
89 PP_Resource share_context, | 90 PPB_Graphics3D_API* share_context, |
90 const int32_t* attrib_list) { | 91 const int32_t* attrib_list) { |
91 scoped_refptr<PPB_Graphics3D_Impl> graphics_3d( | 92 scoped_refptr<PPB_Graphics3D_Impl> graphics_3d( |
92 new PPB_Graphics3D_Impl(instance)); | 93 new PPB_Graphics3D_Impl(instance)); |
93 if (!graphics_3d->InitRaw(share_context, attrib_list)) | 94 if (!graphics_3d->InitRaw(share_context, attrib_list)) |
94 return 0; | 95 return 0; |
95 return graphics_3d->GetReference(); | 96 return graphics_3d->GetReference(); |
96 } | 97 } |
97 | 98 |
98 PP_Bool PPB_Graphics3D_Impl::InitCommandBuffer() { | 99 PP_Bool PPB_Graphics3D_Impl::InitCommandBuffer() { |
99 return PP_FromBool(GetCommandBuffer()->Initialize()); | 100 return PP_FromBool(GetCommandBuffer()->Initialize()); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 } else { | 193 } else { |
193 // Wait for the command to complete on the GPU to allow for throttling. | 194 // Wait for the command to complete on the GPU to allow for throttling. |
194 platform_context_->Echo(base::Bind(&PPB_Graphics3D_Impl::OnSwapBuffers, | 195 platform_context_->Echo(base::Bind(&PPB_Graphics3D_Impl::OnSwapBuffers, |
195 weak_ptr_factory_.GetWeakPtr())); | 196 weak_ptr_factory_.GetWeakPtr())); |
196 } | 197 } |
197 | 198 |
198 | 199 |
199 return PP_OK_COMPLETIONPENDING; | 200 return PP_OK_COMPLETIONPENDING; |
200 } | 201 } |
201 | 202 |
202 bool PPB_Graphics3D_Impl::Init(PP_Resource share_context, | 203 bool PPB_Graphics3D_Impl::Init(PPB_Graphics3D_API* share_context, |
203 const int32_t* attrib_list) { | 204 const int32_t* attrib_list) { |
204 if (!InitRaw(share_context, attrib_list)) | 205 if (!InitRaw(share_context, attrib_list)) |
205 return false; | 206 return false; |
206 | 207 |
207 gpu::CommandBuffer* command_buffer = GetCommandBuffer(); | 208 gpu::CommandBuffer* command_buffer = GetCommandBuffer(); |
208 if (!command_buffer->Initialize()) | 209 if (!command_buffer->Initialize()) |
209 return false; | 210 return false; |
210 | 211 |
211 return CreateGLES2Impl(kCommandBufferSize, kTransferBufferSize); | 212 gpu::gles2::GLES2Implementation* share_gles2 = NULL; |
213 if (share_context) { | |
214 share_gles2 | |
215 = static_cast<PPB_Graphics3D_Shared*>(share_context)->gles2_impl(); | |
piman
2012/05/25 22:41:00
nit: for wrapping, the = should go on the previous
| |
216 } | |
217 | |
218 return CreateGLES2Impl(kCommandBufferSize, kTransferBufferSize, | |
219 share_gles2); | |
212 } | 220 } |
213 | 221 |
214 bool PPB_Graphics3D_Impl::InitRaw(PP_Resource share_context, | 222 bool PPB_Graphics3D_Impl::InitRaw(PPB_Graphics3D_API* share_context, |
215 const int32_t* attrib_list) { | 223 const int32_t* attrib_list) { |
216 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); | 224 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); |
217 if (!plugin_instance) | 225 if (!plugin_instance) |
218 return false; | 226 return false; |
219 | 227 |
220 // TODO(alokp): Support shared context. | 228 PluginDelegate::PlatformContext3D* share_platform_context = NULL; |
221 DCHECK_EQ(0, share_context); | 229 if (share_context) { |
222 if (share_context != 0) | 230 PPB_Graphics3D_Impl* share_graphics = |
223 return false; | 231 static_cast<PPB_Graphics3D_Impl*>(share_context); |
232 share_platform_context = share_graphics->platform_context(); | |
233 } | |
224 | 234 |
225 platform_context_.reset(plugin_instance->CreateContext3D()); | 235 platform_context_.reset(plugin_instance->CreateContext3D()); |
226 if (!platform_context_.get()) | 236 if (!platform_context_.get()) |
227 return false; | 237 return false; |
228 | 238 |
229 if (!platform_context_->Init(attrib_list)) | 239 if (!platform_context_->Init(attrib_list, share_platform_context)) |
230 return false; | 240 return false; |
231 | 241 |
232 platform_context_->SetContextLostCallback( | 242 platform_context_->SetContextLostCallback( |
233 base::Bind(&PPB_Graphics3D_Impl::OnContextLost, | 243 base::Bind(&PPB_Graphics3D_Impl::OnContextLost, |
234 weak_ptr_factory_.GetWeakPtr())); | 244 weak_ptr_factory_.GetWeakPtr())); |
235 | 245 |
236 platform_context_->SetOnConsoleMessageCallback( | 246 platform_context_->SetOnConsoleMessageCallback( |
237 base::Bind(&PPB_Graphics3D_Impl::OnConsoleMessage, | 247 base::Bind(&PPB_Graphics3D_Impl::OnConsoleMessage, |
238 weak_ptr_factory_.GetWeakPtr())); | 248 weak_ptr_factory_.GetWeakPtr())); |
239 return true; | 249 return true; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
287 const PPP_Graphics3D* ppp_graphics_3d = | 297 const PPP_Graphics3D* ppp_graphics_3d = |
288 static_cast<const PPP_Graphics3D*>( | 298 static_cast<const PPP_Graphics3D*>( |
289 instance->module()->GetPluginInterface( | 299 instance->module()->GetPluginInterface( |
290 PPP_GRAPHICS_3D_INTERFACE)); | 300 PPP_GRAPHICS_3D_INTERFACE)); |
291 if (ppp_graphics_3d) | 301 if (ppp_graphics_3d) |
292 ppp_graphics_3d->Graphics3DContextLost(pp_instance()); | 302 ppp_graphics_3d->Graphics3DContextLost(pp_instance()); |
293 } | 303 } |
294 | 304 |
295 } // namespace ppapi | 305 } // namespace ppapi |
296 } // namespace webkit | 306 } // namespace webkit |
OLD | NEW |