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 return CreateGLES2Impl(kCommandBufferSize, kTransferBufferSize); |
piman
2012/05/17 00:05:58
Actually, I'm just realizing, this will also need
(scshunt)
2012/05/17 16:55:45
Currently I believe we only use the Raw codepath.
| |
212 } | 213 } |
213 | 214 |
214 bool PPB_Graphics3D_Impl::InitRaw(PP_Resource share_context, | 215 bool PPB_Graphics3D_Impl::InitRaw(PPB_Graphics3D_API* share_context, |
215 const int32_t* attrib_list) { | 216 const int32_t* attrib_list) { |
216 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); | 217 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); |
217 if (!plugin_instance) | 218 if (!plugin_instance) |
218 return false; | 219 return false; |
219 | 220 |
220 // TODO(alokp): Support shared context. | 221 PluginDelegate::PlatformContext3D* share_platform_context = 0; |
piman
2012/05/16 23:38:45
nit: s/0/NULL/
(scshunt)
2012/05/17 16:55:45
picked.
| |
221 DCHECK_EQ(0, share_context); | 222 if (share_context) { |
222 if (share_context != 0) | 223 PPB_Graphics3D_Impl* share_graphics = |
223 return false; | 224 static_cast<PPB_Graphics3D_Impl*>(share_context); |
piman
2012/05/16 23:38:45
nit: indent +4
(scshunt)
2012/05/17 16:55:45
Also picked.
| |
225 share_platform_context = share_graphics->platform_context(); | |
226 } | |
224 | 227 |
225 platform_context_.reset(plugin_instance->CreateContext3D()); | 228 platform_context_.reset(plugin_instance->CreateContext3D()); |
226 if (!platform_context_.get()) | 229 if (!platform_context_.get()) |
227 return false; | 230 return false; |
228 | 231 |
229 if (!platform_context_->Init(attrib_list)) | 232 if (!platform_context_->Init(attrib_list, share_platform_context)) |
230 return false; | 233 return false; |
231 | 234 |
232 platform_context_->SetContextLostCallback( | 235 platform_context_->SetContextLostCallback( |
233 base::Bind(&PPB_Graphics3D_Impl::OnContextLost, | 236 base::Bind(&PPB_Graphics3D_Impl::OnContextLost, |
234 weak_ptr_factory_.GetWeakPtr())); | 237 weak_ptr_factory_.GetWeakPtr())); |
235 | 238 |
236 platform_context_->SetOnConsoleMessageCallback( | 239 platform_context_->SetOnConsoleMessageCallback( |
237 base::Bind(&PPB_Graphics3D_Impl::OnConsoleMessage, | 240 base::Bind(&PPB_Graphics3D_Impl::OnConsoleMessage, |
238 weak_ptr_factory_.GetWeakPtr())); | 241 weak_ptr_factory_.GetWeakPtr())); |
239 return true; | 242 return true; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
287 const PPP_Graphics3D* ppp_graphics_3d = | 290 const PPP_Graphics3D* ppp_graphics_3d = |
288 static_cast<const PPP_Graphics3D*>( | 291 static_cast<const PPP_Graphics3D*>( |
289 instance->module()->GetPluginInterface( | 292 instance->module()->GetPluginInterface( |
290 PPP_GRAPHICS_3D_INTERFACE)); | 293 PPP_GRAPHICS_3D_INTERFACE)); |
291 if (ppp_graphics_3d) | 294 if (ppp_graphics_3d) |
292 ppp_graphics_3d->Graphics3DContextLost(pp_instance()); | 295 ppp_graphics_3d->Graphics3DContextLost(pp_instance()); |
293 } | 296 } |
294 | 297 |
295 } // namespace ppapi | 298 } // namespace ppapi |
296 } // namespace webkit | 299 } // namespace webkit |
OLD | NEW |