| 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 | 174 |
| 174 gpu::CommandBuffer* command_buffer = GetCommandBuffer(); | 175 gpu::CommandBuffer* command_buffer = GetCommandBuffer(); |
| 175 if (!command_buffer->Initialize(kCommandBufferSize)) | 176 if (!command_buffer->Initialize(kCommandBufferSize)) |
| 176 return false; | 177 return false; |
| 177 | 178 |
| 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) { |
| 184 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); |
| 185 if (!plugin_instance) |
| 186 return false; |
| 187 |
| 183 // TODO(alokp): Support shared context. | 188 // TODO(alokp): Support shared context. |
| 184 DCHECK_EQ(0, share_context); | 189 DCHECK_EQ(0, share_context); |
| 185 if (share_context != 0) | 190 if (share_context != 0) |
| 186 return 0; | 191 return false; |
| 187 | 192 |
| 188 platform_context_.reset(instance()->CreateContext3D()); | 193 platform_context_.reset(plugin_instance->CreateContext3D()); |
| 189 if (!platform_context_.get()) | 194 if (!platform_context_.get()) |
| 190 return false; | 195 return false; |
| 191 | 196 |
| 192 if (!platform_context_->Init(attrib_list)) | 197 if (!platform_context_->Init(attrib_list)) |
| 193 return false; | 198 return false; |
| 194 | 199 |
| 195 platform_context_->SetContextLostCallback( | 200 platform_context_->SetContextLostCallback( |
| 196 callback_factory_.NewCallback(&PPB_Graphics3D_Impl::OnContextLost)); | 201 callback_factory_.NewCallback(&PPB_Graphics3D_Impl::OnContextLost)); |
| 197 platform_context_->SetSwapBuffersCallback( | 202 platform_context_->SetSwapBuffersCallback( |
| 198 callback_factory_.NewCallback(&PPB_Graphics3D_Impl::OnSwapBuffers)); | 203 callback_factory_.NewCallback(&PPB_Graphics3D_Impl::OnSwapBuffers)); |
| 199 return true; | 204 return true; |
| 200 } | 205 } |
| 201 | 206 |
| 202 void PPB_Graphics3D_Impl::OnSwapBuffers() { | 207 void PPB_Graphics3D_Impl::OnSwapBuffers() { |
| 203 if (bound_to_instance_) { | 208 if (bound_to_instance_) { |
| 204 // If we are bound to the instance, we need to ask the compositor | 209 // 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. | 210 // 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 | 211 // When the backing texture will be committed we get notified via |
| 207 // ViewFlushedPaint(). | 212 // ViewFlushedPaint(). |
| 208 instance()->CommitBackingTexture(); | 213 // |
| 214 // Don't need to check for NULL from GetPluginInstance since when we're |
| 215 // bound, we know our instance is valid. |
| 216 ResourceHelper::GetPluginInstance(this)->CommitBackingTexture(); |
| 209 commit_pending_ = true; | 217 commit_pending_ = true; |
| 210 } else if (HasPendingSwap()) { | 218 } else if (HasPendingSwap()) { |
| 211 // If we're off-screen, no need to trigger and wait for compositing. | 219 // If we're off-screen, no need to trigger and wait for compositing. |
| 212 // Just send the swap-buffers ACK to the plugin immediately. | 220 // Just send the swap-buffers ACK to the plugin immediately. |
| 213 commit_pending_ = false; | 221 commit_pending_ = false; |
| 214 SwapBuffersACK(PP_OK); | 222 SwapBuffersACK(PP_OK); |
| 215 } | 223 } |
| 216 } | 224 } |
| 217 | 225 |
| 218 void PPB_Graphics3D_Impl::OnContextLost() { | 226 void PPB_Graphics3D_Impl::OnContextLost() { |
| 227 // Don't need to check for NULL from GetPluginInstance since when we're |
| 228 // bound, we know our instance is valid. |
| 219 if (bound_to_instance_) | 229 if (bound_to_instance_) |
| 220 instance()->BindGraphics(instance()->pp_instance(), 0); | 230 ResourceHelper::GetPluginInstance(this)->BindGraphics(pp_instance(), 0); |
| 221 | 231 |
| 222 // Send context lost to plugin. This may have been caused by a PPAPI call, so | 232 // Send context lost to plugin. This may have been caused by a PPAPI call, so |
| 223 // avoid re-entering. | 233 // avoid re-entering. |
| 224 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( | 234 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( |
| 225 this, &PPB_Graphics3D_Impl::SendContextLost)); | 235 this, &PPB_Graphics3D_Impl::SendContextLost)); |
| 226 } | 236 } |
| 227 | 237 |
| 228 void PPB_Graphics3D_Impl::SendContextLost() { | 238 void PPB_Graphics3D_Impl::SendContextLost() { |
| 229 // By the time we run this, the instance may have been deleted, or in the | 239 // 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 | 240 // process of being deleted. Even in the latter case, we don't want to send a |
| 231 // callback after DidDestroy. | 241 // callback after DidDestroy. |
| 232 if (!instance() || !instance()->container()) | 242 PluginInstance* instance = ResourceHelper::GetPluginInstance(this); |
| 243 if (!instance || !instance->container()) |
| 233 return; | 244 return; |
| 234 | 245 |
| 235 const PPP_Graphics3D_Dev* ppp_graphics_3d = | 246 const PPP_Graphics3D_Dev* ppp_graphics_3d = |
| 236 static_cast<const PPP_Graphics3D_Dev*>( | 247 static_cast<const PPP_Graphics3D_Dev*>( |
| 237 instance()->module()->GetPluginInterface( | 248 instance->module()->GetPluginInterface( |
| 238 PPP_GRAPHICS_3D_DEV_INTERFACE)); | 249 PPP_GRAPHICS_3D_DEV_INTERFACE)); |
| 239 if (ppp_graphics_3d) | 250 if (ppp_graphics_3d) |
| 240 ppp_graphics_3d->Graphics3DContextLost(instance()->pp_instance()); | 251 ppp_graphics_3d->Graphics3DContextLost(pp_instance()); |
| 241 } | 252 } |
| 242 | 253 |
| 243 } // namespace ppapi | 254 } // namespace ppapi |
| 244 } // namespace webkit | 255 } // namespace webkit |
| OLD | NEW |