| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "gpu/command_buffer/client/gles2_implementation.h" | 7 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 8 #include "gpu/command_buffer/common/command_buffer.h" | 8 #include "gpu/command_buffer/common/command_buffer.h" |
| 9 #include "ppapi/c/dev/ppb_graphics_3d_dev.h" | 9 #include "ppapi/c/dev/ppb_graphics_3d_dev.h" |
| 10 #include "webkit/plugins/ppapi/common.h" | 10 #include "webkit/plugins/ppapi/common.h" |
| 11 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 11 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| 12 #include "webkit/plugins/ppapi/ppb_context_3d_impl.h" |
| 12 | 13 |
| 13 namespace webkit { | 14 namespace webkit { |
| 14 namespace ppapi { | 15 namespace ppapi { |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 PP_Resource Create(PP_Instance instance_id, | 19 PP_Resource Create(PP_Instance instance_id, |
| 19 PP_Config3D_Dev config, | 20 PP_Config3D_Dev config, |
| 20 const int32_t* attrib_list) { | 21 const int32_t* attrib_list) { |
| 21 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); | 22 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 const int32_t* attrib_list) { | 89 const int32_t* attrib_list) { |
| 89 return true; | 90 return true; |
| 90 } | 91 } |
| 91 | 92 |
| 92 bool PPB_Surface3D_Impl::BindToInstance(bool bind) { | 93 bool PPB_Surface3D_Impl::BindToInstance(bool bind) { |
| 93 bound_to_instance_ = bind; | 94 bound_to_instance_ = bind; |
| 94 return true; | 95 return true; |
| 95 } | 96 } |
| 96 | 97 |
| 97 bool PPB_Surface3D_Impl::BindToContext( | 98 bool PPB_Surface3D_Impl::BindToContext( |
| 98 PluginDelegate::PlatformContext3D* context) { | 99 PPB_Context3D_Impl* context) { |
| 99 if (context == context_) | 100 if (context == context_) |
| 100 return true; | 101 return true; |
| 101 | 102 |
| 102 // Unbind from the current context. | 103 // Unbind from the current context. |
| 103 if (context_) { | 104 if (context_) { |
| 104 context_->SetSwapBuffersCallback(NULL); | 105 context_->platform_context()->SetSwapBuffersCallback(NULL); |
| 105 } | 106 } |
| 106 if (context) { | 107 if (context) { |
| 107 // Resize the backing texture to the size of the instance when it is bound. | 108 // Resize the backing texture to the size of the instance when it is bound. |
| 108 // TODO(alokp): This should be the responsibility of plugins. | 109 // TODO(alokp): This should be the responsibility of plugins. |
| 109 const gfx::Size& size = instance()->position().size(); | 110 const gfx::Size& size = instance()->position().size(); |
| 110 context->GetGLES2Implementation()->ResizeCHROMIUM( | 111 context->gles2_impl()->ResizeCHROMIUM(size.width(), size.height()); |
| 111 size.width(), size.height()); | |
| 112 | 112 |
| 113 context->SetSwapBuffersCallback( | 113 context->platform_context()->SetSwapBuffersCallback( |
| 114 NewCallback(this, &PPB_Surface3D_Impl::OnSwapBuffers)); | 114 NewCallback(this, &PPB_Surface3D_Impl::OnSwapBuffers)); |
| 115 } | 115 } |
| 116 context_ = context; | 116 context_ = context; |
| 117 return true; | 117 return true; |
| 118 } | 118 } |
| 119 | 119 |
| 120 bool PPB_Surface3D_Impl::SwapBuffers(PP_CompletionCallback callback) { | 120 bool PPB_Surface3D_Impl::SwapBuffers(PP_CompletionCallback callback) { |
| 121 if (!context_) | 121 if (!context_) |
| 122 return false; | 122 return false; |
| 123 | 123 |
| 124 if (swap_callback_.func) { | 124 if (swap_callback_.func) { |
| 125 // Already a pending SwapBuffers that hasn't returned yet. | 125 // Already a pending SwapBuffers that hasn't returned yet. |
| 126 return false; | 126 return false; |
| 127 } | 127 } |
| 128 | 128 |
| 129 swap_callback_ = callback; | 129 swap_callback_ = callback; |
| 130 return context_->SwapBuffers(); | 130 context_->gles2_impl()->SwapBuffers(); |
| 131 return true; |
| 131 } | 132 } |
| 132 | 133 |
| 133 void PPB_Surface3D_Impl::ViewInitiatedPaint() { | 134 void PPB_Surface3D_Impl::ViewInitiatedPaint() { |
| 134 if (swap_callback_.func) { | 135 if (swap_callback_.func) { |
| 135 swap_initiated_ = true; | 136 swap_initiated_ = true; |
| 136 } | 137 } |
| 137 } | 138 } |
| 138 | 139 |
| 139 void PPB_Surface3D_Impl::ViewFlushedPaint() { | 140 void PPB_Surface3D_Impl::ViewFlushedPaint() { |
| 140 if (swap_initiated_ && swap_callback_.func) { | 141 if (swap_initiated_ && swap_callback_.func) { |
| 141 // We must clear swap_callback_ before issuing the callback. It will be | 142 // We must clear swap_callback_ before issuing the callback. It will be |
| 142 // common for the plugin to issue another SwapBuffers in response to the | 143 // common for the plugin to issue another SwapBuffers in response to the |
| 143 // callback, and we don't want to think that a callback is already pending. | 144 // callback, and we don't want to think that a callback is already pending. |
| 144 PP_CompletionCallback callback = PP_BlockUntilComplete(); | 145 PP_CompletionCallback callback = PP_BlockUntilComplete(); |
| 145 std::swap(callback, swap_callback_); | 146 std::swap(callback, swap_callback_); |
| 146 swap_initiated_ = false; | 147 swap_initiated_ = false; |
| 147 PP_RunCompletionCallback(&callback, PP_OK); | 148 PP_RunCompletionCallback(&callback, PP_OK); |
| 148 } | 149 } |
| 149 } | 150 } |
| 150 | 151 |
| 151 unsigned int PPB_Surface3D_Impl::GetBackingTextureId() { | 152 unsigned int PPB_Surface3D_Impl::GetBackingTextureId() { |
| 152 return context_ ? context_->GetBackingTextureId() : 0; | 153 return context_ ? context_->platform_context()->GetBackingTextureId() : 0; |
| 153 } | 154 } |
| 154 | 155 |
| 155 void PPB_Surface3D_Impl::OnSwapBuffers() { | 156 void PPB_Surface3D_Impl::OnSwapBuffers() { |
| 156 if (bound_to_instance_) | 157 if (bound_to_instance_) |
| 157 instance()->CommitBackingTexture(); | 158 instance()->CommitBackingTexture(); |
| 158 } | 159 } |
| 159 | 160 |
| 160 } // namespace ppapi | 161 } // namespace ppapi |
| 161 } // namespace webkit | 162 } // namespace webkit |
| 162 | 163 |
| OLD | NEW |