| 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_surface_3d_impl.h" | 5 #include "webkit/plugins/ppapi/ppb_surface_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 "gpu/command_buffer/common/command_buffer.h" | 9 #include "gpu/command_buffer/common/command_buffer.h" |
| 10 #include "ppapi/c/dev/ppb_graphics_3d_dev.h" | 10 #include "ppapi/c/dev/ppb_graphics_3d_dev.h" |
| 11 #include "ppapi/c/dev/ppp_graphics_3d_dev.h" | 11 #include "ppapi/c/dev/ppp_graphics_3d_dev.h" |
| 12 #include "webkit/plugins/ppapi/common.h" | 12 #include "webkit/plugins/ppapi/common.h" |
| 13 #include "webkit/plugins/ppapi/plugin_module.h" | 13 #include "webkit/plugins/ppapi/plugin_module.h" |
| 14 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 14 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| 15 #include "webkit/plugins/ppapi/ppb_context_3d_impl.h" | 15 #include "webkit/plugins/ppapi/ppb_context_3d_impl.h" |
| 16 #include "webkit/plugins/ppapi/resource_helper.h" |
| 16 | 17 |
| 17 using ppapi::thunk::PPB_Surface3D_API; | 18 using ppapi::thunk::PPB_Surface3D_API; |
| 18 | 19 |
| 19 namespace webkit { | 20 namespace webkit { |
| 20 namespace ppapi { | 21 namespace ppapi { |
| 21 | 22 |
| 22 PPB_Surface3D_Impl::PPB_Surface3D_Impl(PluginInstance* instance) | 23 PPB_Surface3D_Impl::PPB_Surface3D_Impl(PP_Instance instance) |
| 23 : Resource(instance), | 24 : Resource(instance), |
| 24 bound_to_instance_(false), | 25 bound_to_instance_(false), |
| 25 swap_initiated_(false), | 26 swap_initiated_(false), |
| 26 context_(NULL) { | 27 context_(NULL) { |
| 27 } | 28 } |
| 28 | 29 |
| 29 PPB_Surface3D_Impl::~PPB_Surface3D_Impl() { | 30 PPB_Surface3D_Impl::~PPB_Surface3D_Impl() { |
| 30 if (context_) | 31 if (context_) |
| 31 context_->BindSurfacesImpl(NULL, NULL); | 32 context_->BindSurfacesImpl(NULL, NULL); |
| 32 } | 33 } |
| 33 | 34 |
| 34 // static | 35 // static |
| 35 PP_Resource PPB_Surface3D_Impl::Create(PluginInstance* instance, | 36 PP_Resource PPB_Surface3D_Impl::Create(PP_Instance instance, |
| 36 PP_Config3D_Dev config, | 37 PP_Config3D_Dev config, |
| 37 const int32_t* attrib_list) { | 38 const int32_t* attrib_list) { |
| 38 scoped_refptr<PPB_Surface3D_Impl> surface( | 39 scoped_refptr<PPB_Surface3D_Impl> surface( |
| 39 new PPB_Surface3D_Impl(instance)); | 40 new PPB_Surface3D_Impl(instance)); |
| 40 if (!surface->Init(config, attrib_list)) | 41 if (!surface->Init(config, attrib_list)) |
| 41 return 0; | 42 return 0; |
| 42 return surface->GetReference(); | 43 return surface->GetReference(); |
| 43 } | 44 } |
| 44 | 45 |
| 45 PPB_Surface3D_API* PPB_Surface3D_Impl::AsPPB_Surface3D_API() { | 46 PPB_Surface3D_API* PPB_Surface3D_Impl::AsPPB_Surface3D_API() { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 64 } | 65 } |
| 65 | 66 |
| 66 if (swap_callback_.get() && !swap_callback_->completed()) { | 67 if (swap_callback_.get() && !swap_callback_->completed()) { |
| 67 // Already a pending SwapBuffers that hasn't returned yet. | 68 // Already a pending SwapBuffers that hasn't returned yet. |
| 68 return PP_ERROR_INPROGRESS; | 69 return PP_ERROR_INPROGRESS; |
| 69 } | 70 } |
| 70 | 71 |
| 71 if (!context_) | 72 if (!context_) |
| 72 return PP_ERROR_FAILED; | 73 return PP_ERROR_FAILED; |
| 73 | 74 |
| 74 swap_callback_ = new TrackedCompletionCallback( | 75 PluginModule* module = ResourceHelper::GetPluginModule(this); |
| 75 instance()->module()->GetCallbackTracker(), pp_resource(), callback); | 76 |
| 77 swap_callback_ = new TrackedCompletionCallback(module->GetCallbackTracker(), |
| 78 pp_resource(), callback); |
| 76 gpu::gles2::GLES2Implementation* impl = context_->gles2_impl(); | 79 gpu::gles2::GLES2Implementation* impl = context_->gles2_impl(); |
| 77 if (impl) | 80 if (impl) |
| 78 context_->gles2_impl()->SwapBuffers(); | 81 context_->gles2_impl()->SwapBuffers(); |
| 79 // |SwapBuffers()| should not call us back synchronously, but double-check. | 82 // |SwapBuffers()| should not call us back synchronously, but double-check. |
| 80 DCHECK(!swap_callback_->completed()); | 83 DCHECK(!swap_callback_->completed()); |
| 81 return PP_OK_COMPLETIONPENDING; | 84 return PP_OK_COMPLETIONPENDING; |
| 82 } | 85 } |
| 83 | 86 |
| 84 bool PPB_Surface3D_Impl::Init(PP_Config3D_Dev config, | 87 bool PPB_Surface3D_Impl::Init(PP_Config3D_Dev config, |
| 85 const int32_t* attrib_list) { | 88 const int32_t* attrib_list) { |
| 86 return true; | 89 return true; |
| 87 } | 90 } |
| 88 | 91 |
| 89 bool PPB_Surface3D_Impl::BindToInstance(bool bind) { | 92 bool PPB_Surface3D_Impl::BindToInstance(bool bind) { |
| 90 bound_to_instance_ = bind; | 93 bound_to_instance_ = bind; |
| 91 return true; | 94 return true; |
| 92 } | 95 } |
| 93 | 96 |
| 94 bool PPB_Surface3D_Impl::BindToContext(PPB_Context3D_Impl* context) { | 97 bool PPB_Surface3D_Impl::BindToContext(PPB_Context3D_Impl* context) { |
| 95 if (context == context_) | 98 if (context == context_) |
| 96 return true; | 99 return true; |
| 97 | 100 |
| 101 PluginInstance* instance = ResourceHelper::GetPluginInstance(this); |
| 102 |
| 98 if (!context && bound_to_instance_) | 103 if (!context && bound_to_instance_) |
| 99 instance()->BindGraphics(instance()->pp_instance(), 0); | 104 instance->BindGraphics(pp_instance(), 0); |
| 100 | 105 |
| 101 // Unbind from the current context. | 106 // Unbind from the current context. |
| 102 if (context_ && context_->platform_context()) | 107 if (context_ && context_->platform_context()) |
| 103 context_->platform_context()->SetSwapBuffersCallback(NULL); | 108 context_->platform_context()->SetSwapBuffersCallback(NULL); |
| 104 if (context && context->platform_context()) { | 109 if (context && context->platform_context()) { |
| 105 // Resize the backing texture to the size of the instance when it is bound. | 110 // Resize the backing texture to the size of the instance when it is bound. |
| 106 // TODO(alokp): This should be the responsibility of plugins. | 111 // TODO(alokp): This should be the responsibility of plugins. |
| 107 gpu::gles2::GLES2Implementation* impl = context->gles2_impl(); | 112 gpu::gles2::GLES2Implementation* impl = context->gles2_impl(); |
| 108 if (impl) { | 113 if (impl) { |
| 109 const gfx::Size& size = instance()->position().size(); | 114 const gfx::Size& size = instance->position().size(); |
| 110 impl->ResizeCHROMIUM(size.width(), size.height()); | 115 impl->ResizeCHROMIUM(size.width(), size.height()); |
| 111 } | 116 } |
| 112 | 117 |
| 113 context->platform_context()->SetSwapBuffersCallback( | 118 context->platform_context()->SetSwapBuffersCallback( |
| 114 NewCallback(this, &PPB_Surface3D_Impl::OnSwapBuffers)); | 119 NewCallback(this, &PPB_Surface3D_Impl::OnSwapBuffers)); |
| 115 } | 120 } |
| 116 context_ = context; | 121 context_ = context; |
| 117 return true; | 122 return true; |
| 118 } | 123 } |
| 119 | 124 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 131 callback->Run(PP_OK); // Will complete abortively if necessary. | 136 callback->Run(PP_OK); // Will complete abortively if necessary. |
| 132 } | 137 } |
| 133 } | 138 } |
| 134 | 139 |
| 135 unsigned int PPB_Surface3D_Impl::GetBackingTextureId() { | 140 unsigned int PPB_Surface3D_Impl::GetBackingTextureId() { |
| 136 return context_ ? context_->platform_context()->GetBackingTextureId() : 0; | 141 return context_ ? context_->platform_context()->GetBackingTextureId() : 0; |
| 137 } | 142 } |
| 138 | 143 |
| 139 void PPB_Surface3D_Impl::OnSwapBuffers() { | 144 void PPB_Surface3D_Impl::OnSwapBuffers() { |
| 140 if (bound_to_instance_) { | 145 if (bound_to_instance_) { |
| 141 instance()->CommitBackingTexture(); | 146 PluginInstance* instance = ResourceHelper::GetPluginInstance(this); |
| 147 instance->CommitBackingTexture(); |
| 142 swap_initiated_ = true; | 148 swap_initiated_ = true; |
| 143 } else if (swap_callback_.get() && !swap_callback_->completed()) { | 149 } else if (swap_callback_.get() && !swap_callback_->completed()) { |
| 144 // If we're off-screen, no need to trigger compositing so run the callback | 150 // If we're off-screen, no need to trigger compositing so run the callback |
| 145 // immediately. | 151 // immediately. |
| 146 swap_initiated_ = false; | 152 swap_initiated_ = false; |
| 147 scoped_refptr<TrackedCompletionCallback> callback; | 153 scoped_refptr<TrackedCompletionCallback> callback; |
| 148 callback.swap(swap_callback_); | 154 callback.swap(swap_callback_); |
| 149 callback->Run(PP_OK); // Will complete abortively if necessary. | 155 callback->Run(PP_OK); // Will complete abortively if necessary. |
| 150 } | 156 } |
| 151 } | 157 } |
| 152 | 158 |
| 153 void PPB_Surface3D_Impl::OnContextLost() { | 159 void PPB_Surface3D_Impl::OnContextLost() { |
| 154 if (bound_to_instance_) | 160 if (bound_to_instance_) |
| 155 instance()->BindGraphics(instance()->pp_instance(), 0); | 161 ResourceHelper::GetPluginInstance(this)->BindGraphics(pp_instance(), 0); |
| 156 | 162 |
| 157 // Send context lost to plugin. This may have been caused by a PPAPI call, so | 163 // Send context lost to plugin. This may have been caused by a PPAPI call, so |
| 158 // avoid re-entering. | 164 // avoid re-entering. |
| 159 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( | 165 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( |
| 160 this, &PPB_Surface3D_Impl::SendContextLost)); | 166 this, &PPB_Surface3D_Impl::SendContextLost)); |
| 161 } | 167 } |
| 162 | 168 |
| 163 void PPB_Surface3D_Impl::SendContextLost() { | 169 void PPB_Surface3D_Impl::SendContextLost() { |
| 170 PluginInstance* instance = ResourceHelper::GetPluginInstance(this); |
| 171 |
| 164 // By the time we run this, the instance may have been deleted, or in the | 172 // By the time we run this, the instance may have been deleted, or in the |
| 165 // process of being deleted. Even in the latter case, we don't want to send a | 173 // process of being deleted. Even in the latter case, we don't want to send a |
| 166 // callback after DidDestroy. | 174 // callback after DidDestroy. |
| 167 if (!instance() || !instance()->container()) | 175 if (!instance || !instance->container()) |
| 168 return; | 176 return; |
| 169 const PPP_Graphics3D_Dev* ppp_graphics_3d = | 177 const PPP_Graphics3D_Dev* ppp_graphics_3d = |
| 170 static_cast<const PPP_Graphics3D_Dev*>( | 178 static_cast<const PPP_Graphics3D_Dev*>( |
| 171 instance()->module()->GetPluginInterface( | 179 instance->module()->GetPluginInterface( |
| 172 PPP_GRAPHICS_3D_DEV_INTERFACE)); | 180 PPP_GRAPHICS_3D_DEV_INTERFACE)); |
| 173 if (ppp_graphics_3d) | 181 if (ppp_graphics_3d) |
| 174 ppp_graphics_3d->Graphics3DContextLost(instance()->pp_instance()); | 182 ppp_graphics_3d->Graphics3DContextLost(pp_instance()); |
| 175 } | 183 } |
| 176 | 184 |
| 177 } // namespace ppapi | 185 } // namespace ppapi |
| 178 } // namespace webkit | 186 } // namespace webkit |
| OLD | NEW |