| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "gpu/command_buffer/client/gles2_implementation.h" | 8 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 9 #include "webkit/plugins/ppapi/plugin_module.h" | 9 #include "webkit/plugins/ppapi/plugin_module.h" |
| 10 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 10 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| 11 #include "webkit/plugins/ppapi/resource_helper.h" |
| 11 | 12 |
| 12 using ppapi::thunk::PPB_Graphics3D_API; | 13 using ppapi::thunk::PPB_Graphics3D_API; |
| 13 | 14 |
| 14 namespace webkit { | 15 namespace webkit { |
| 15 namespace ppapi { | 16 namespace ppapi { |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 const int32 kCommandBufferSize = 1024 * 1024; | 19 const int32 kCommandBufferSize = 1024 * 1024; |
| 19 const int32 kTransferBufferSize = 1024 * 1024; | 20 const int32 kTransferBufferSize = 1024 * 1024; |
| 20 | 21 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 42 s.get_offset, | 43 s.get_offset, |
| 43 s.put_offset, | 44 s.put_offset, |
| 44 s.token, | 45 s.token, |
| 45 static_cast<PPB_Graphics3DTrustedError>(s.error), | 46 static_cast<PPB_Graphics3DTrustedError>(s.error), |
| 46 s.generation | 47 s.generation |
| 47 }; | 48 }; |
| 48 return state; | 49 return state; |
| 49 } | 50 } |
| 50 } // namespace. | 51 } // namespace. |
| 51 | 52 |
| 52 PPB_Graphics3D_Impl::PPB_Graphics3D_Impl(PluginInstance* instance) | 53 PPB_Graphics3D_Impl::PPB_Graphics3D_Impl(PP_Instance instance) |
| 53 : Resource(instance), | 54 : Resource(instance), |
| 54 bound_to_instance_(false), | 55 bound_to_instance_(false), |
| 55 commit_pending_(false), | 56 commit_pending_(false), |
| 56 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 57 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 57 } | 58 } |
| 58 | 59 |
| 59 PPB_Graphics3D_Impl::~PPB_Graphics3D_Impl() { | 60 PPB_Graphics3D_Impl::~PPB_Graphics3D_Impl() { |
| 60 DestroyGLES2Impl(); | 61 DestroyGLES2Impl(); |
| 61 } | 62 } |
| 62 | 63 |
| 63 // static | 64 // static |
| 64 PP_Resource PPB_Graphics3D_Impl::Create(PluginInstance* instance, | 65 PP_Resource PPB_Graphics3D_Impl::Create(PP_Instance instance, |
| 65 PP_Resource share_context, | 66 PP_Resource share_context, |
| 66 const int32_t* attrib_list) { | 67 const int32_t* attrib_list) { |
| 67 scoped_refptr<PPB_Graphics3D_Impl> graphics_3d( | 68 scoped_refptr<PPB_Graphics3D_Impl> graphics_3d( |
| 68 new PPB_Graphics3D_Impl(instance)); | 69 new PPB_Graphics3D_Impl(instance)); |
| 69 if (!graphics_3d->Init(share_context, attrib_list)) | 70 if (!graphics_3d->Init(share_context, attrib_list)) |
| 70 return 0; | 71 return 0; |
| 71 return graphics_3d->GetReference(); | 72 return graphics_3d->GetReference(); |
| 72 } | 73 } |
| 73 | 74 |
| 74 PP_Resource PPB_Graphics3D_Impl::CreateRaw(PluginInstance* instance, | 75 PP_Resource PPB_Graphics3D_Impl::CreateRaw(PP_Instance instance, |
| 75 PP_Resource share_context, | 76 PP_Resource share_context, |
| 76 const int32_t* attrib_list) { | 77 const int32_t* attrib_list) { |
| 77 scoped_refptr<PPB_Graphics3D_Impl> graphics_3d( | 78 scoped_refptr<PPB_Graphics3D_Impl> graphics_3d( |
| 78 new PPB_Graphics3D_Impl(instance)); | 79 new PPB_Graphics3D_Impl(instance)); |
| 79 if (!graphics_3d->InitRaw(share_context, attrib_list)) | 80 if (!graphics_3d->InitRaw(share_context, attrib_list)) |
| 80 return 0; | 81 return 0; |
| 81 return graphics_3d->GetReference(); | 82 return graphics_3d->GetReference(); |
| 82 } | 83 } |
| 83 | 84 |
| 84 PPB_Graphics3D_API* PPB_Graphics3D_Impl::AsPPB_Graphics3D_API() { | 85 PPB_Graphics3D_API* PPB_Graphics3D_Impl::AsPPB_Graphics3D_API() { |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 return CreateGLES2Impl(kCommandBufferSize, kTransferBufferSize); | 179 return CreateGLES2Impl(kCommandBufferSize, kTransferBufferSize); |
| 179 } | 180 } |
| 180 | 181 |
| 181 bool PPB_Graphics3D_Impl::InitRaw(PP_Resource share_context, | 182 bool PPB_Graphics3D_Impl::InitRaw(PP_Resource share_context, |
| 182 const int32_t* attrib_list) { | 183 const int32_t* attrib_list) { |
| 183 // TODO(alokp): Support shared context. | 184 // TODO(alokp): Support shared context. |
| 184 DCHECK_EQ(0, share_context); | 185 DCHECK_EQ(0, share_context); |
| 185 if (share_context != 0) | 186 if (share_context != 0) |
| 186 return 0; | 187 return 0; |
| 187 | 188 |
| 188 platform_context_.reset(instance()->CreateContext3D()); | 189 platform_context_.reset( |
| 190 ResourceHelper::GetPluginInstance(this)->CreateContext3D()); |
| 189 if (!platform_context_.get()) | 191 if (!platform_context_.get()) |
| 190 return false; | 192 return false; |
| 191 | 193 |
| 192 if (!platform_context_->Init(attrib_list)) | 194 if (!platform_context_->Init(attrib_list)) |
| 193 return false; | 195 return false; |
| 194 | 196 |
| 195 platform_context_->SetContextLostCallback( | 197 platform_context_->SetContextLostCallback( |
| 196 callback_factory_.NewCallback(&PPB_Graphics3D_Impl::OnContextLost)); | 198 callback_factory_.NewCallback(&PPB_Graphics3D_Impl::OnContextLost)); |
| 197 platform_context_->SetSwapBuffersCallback( | 199 platform_context_->SetSwapBuffersCallback( |
| 198 callback_factory_.NewCallback(&PPB_Graphics3D_Impl::OnSwapBuffers)); | 200 callback_factory_.NewCallback(&PPB_Graphics3D_Impl::OnSwapBuffers)); |
| 199 return true; | 201 return true; |
| 200 } | 202 } |
| 201 | 203 |
| 202 void PPB_Graphics3D_Impl::OnSwapBuffers() { | 204 void PPB_Graphics3D_Impl::OnSwapBuffers() { |
| 203 if (bound_to_instance_) { | 205 if (bound_to_instance_) { |
| 204 // If we are bound to the instance, we need to ask the compositor | 206 // If we are bound to the instance, we need to ask the compositor |
| 205 // to commit our backing texture so that the graphics appears on the page. | 207 // to commit our backing texture so that the graphics appears on the page. |
| 206 // When the backing texture will be committed we get notified via | 208 // When the backing texture will be committed we get notified via |
| 207 // ViewFlushedPaint(). | 209 // ViewFlushedPaint(). |
| 208 instance()->CommitBackingTexture(); | 210 ResourceHelper::GetPluginInstance(this)->CommitBackingTexture(); |
| 209 commit_pending_ = true; | 211 commit_pending_ = true; |
| 210 } else if (HasPendingSwap()) { | 212 } else if (HasPendingSwap()) { |
| 211 // If we're off-screen, no need to trigger and wait for compositing. | 213 // If we're off-screen, no need to trigger and wait for compositing. |
| 212 // Just send the swap-buffers ACK to the plugin immediately. | 214 // Just send the swap-buffers ACK to the plugin immediately. |
| 213 commit_pending_ = false; | 215 commit_pending_ = false; |
| 214 SwapBuffersACK(PP_OK); | 216 SwapBuffersACK(PP_OK); |
| 215 } | 217 } |
| 216 } | 218 } |
| 217 | 219 |
| 218 void PPB_Graphics3D_Impl::OnContextLost() { | 220 void PPB_Graphics3D_Impl::OnContextLost() { |
| 219 if (bound_to_instance_) | 221 if (bound_to_instance_) |
| 220 instance()->BindGraphics(instance()->pp_instance(), 0); | 222 ResourceHelper::GetPluginInstance(this)->BindGraphics(pp_instance(), 0); |
| 221 | 223 |
| 222 // Send context lost to plugin. This may have been caused by a PPAPI call, so | 224 // Send context lost to plugin. This may have been caused by a PPAPI call, so |
| 223 // avoid re-entering. | 225 // avoid re-entering. |
| 224 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( | 226 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( |
| 225 this, &PPB_Graphics3D_Impl::SendContextLost)); | 227 this, &PPB_Graphics3D_Impl::SendContextLost)); |
| 226 } | 228 } |
| 227 | 229 |
| 228 void PPB_Graphics3D_Impl::SendContextLost() { | 230 void PPB_Graphics3D_Impl::SendContextLost() { |
| 229 // By the time we run this, the instance may have been deleted, or in the | 231 // By the time we run this, the instance may have been deleted, or in the |
| 230 // process of being deleted. Even in the latter case, we don't want to send a | 232 // process of being deleted. Even in the latter case, we don't want to send a |
| 231 // callback after DidDestroy. | 233 // callback after DidDestroy. |
| 232 if (!instance() || !instance()->container()) | 234 PluginInstance* instance = ResourceHelper::GetPluginInstance(this); |
| 235 if (!instance || !instance->container()) |
| 233 return; | 236 return; |
| 234 | 237 |
| 235 const PPP_Graphics3D_Dev* ppp_graphics_3d = | 238 const PPP_Graphics3D_Dev* ppp_graphics_3d = |
| 236 static_cast<const PPP_Graphics3D_Dev*>( | 239 static_cast<const PPP_Graphics3D_Dev*>( |
| 237 instance()->module()->GetPluginInterface( | 240 instance->module()->GetPluginInterface( |
| 238 PPP_GRAPHICS_3D_DEV_INTERFACE)); | 241 PPP_GRAPHICS_3D_DEV_INTERFACE)); |
| 239 if (ppp_graphics_3d) | 242 if (ppp_graphics_3d) |
| 240 ppp_graphics_3d->Graphics3DContextLost(instance()->pp_instance()); | 243 ppp_graphics_3d->Graphics3DContextLost(pp_instance()); |
| 241 } | 244 } |
| 242 | 245 |
| 243 } // namespace ppapi | 246 } // namespace ppapi |
| 244 } // namespace webkit | 247 } // namespace webkit |
| OLD | NEW |