| 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/common/command_buffer.h" | 7 #include "gpu/command_buffer/common/command_buffer.h" |
| 8 #include "ppapi/c/dev/ppb_graphics_3d_dev.h" | 8 #include "ppapi/c/dev/ppb_graphics_3d_dev.h" |
| 9 #include "webkit/plugins/ppapi/common.h" | 9 #include "webkit/plugins/ppapi/common.h" |
| 10 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 10 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 int32_t attribute, | 44 int32_t attribute, |
| 45 int32_t* value) { | 45 int32_t* value) { |
| 46 // TODO(alokp): Implement me. | 46 // TODO(alokp): Implement me. |
| 47 return 0; | 47 return 0; |
| 48 } | 48 } |
| 49 | 49 |
| 50 int32_t SwapBuffers(PP_Resource surface_id, | 50 int32_t SwapBuffers(PP_Resource surface_id, |
| 51 PP_CompletionCallback callback) { | 51 PP_CompletionCallback callback) { |
| 52 scoped_refptr<PPB_Surface3D_Impl> surface( | 52 scoped_refptr<PPB_Surface3D_Impl> surface( |
| 53 Resource::GetAs<PPB_Surface3D_Impl>(surface_id)); | 53 Resource::GetAs<PPB_Surface3D_Impl>(surface_id)); |
| 54 return surface->SwapBuffers(); | 54 return surface->SwapBuffers(callback); |
| 55 } | 55 } |
| 56 | 56 |
| 57 const PPB_Surface3D_Dev ppb_surface3d = { | 57 const PPB_Surface3D_Dev ppb_surface3d = { |
| 58 &Create, | 58 &Create, |
| 59 &IsSurface3D, | 59 &IsSurface3D, |
| 60 &SetAttrib, | 60 &SetAttrib, |
| 61 &GetAttrib, | 61 &GetAttrib, |
| 62 &SwapBuffers | 62 &SwapBuffers |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 } // namespace | 65 } // namespace |
| 66 | 66 |
| 67 PPB_Surface3D_Impl::PPB_Surface3D_Impl(PluginInstance* instance) | 67 PPB_Surface3D_Impl::PPB_Surface3D_Impl(PluginInstance* instance) |
| 68 : Resource(instance->module()), | 68 : Resource(instance->module()), |
| 69 instance_(instance), | 69 instance_(instance), |
| 70 bound_to_instance_(false), | 70 bound_to_instance_(false), |
| 71 swap_initiated_(false), |
| 72 swap_callback_(PP_BlockUntilComplete()), |
| 71 context_(NULL) { | 73 context_(NULL) { |
| 72 } | 74 } |
| 73 | 75 |
| 74 PPB_Surface3D_Impl::~PPB_Surface3D_Impl() { | 76 PPB_Surface3D_Impl::~PPB_Surface3D_Impl() { |
| 75 } | 77 } |
| 76 | 78 |
| 77 const PPB_Surface3D_Dev* PPB_Surface3D_Impl::GetInterface() { | 79 const PPB_Surface3D_Dev* PPB_Surface3D_Impl::GetInterface() { |
| 78 return &ppb_surface3d; | 80 return &ppb_surface3d; |
| 79 } | 81 } |
| 80 | 82 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 // TODO(apatrick): Figure out the semantics of binding and resizing. | 116 // TODO(apatrick): Figure out the semantics of binding and resizing. |
| 115 context->SwapBuffers(); | 117 context->SwapBuffers(); |
| 116 | 118 |
| 117 context->SetSwapBuffersCallback( | 119 context->SetSwapBuffersCallback( |
| 118 NewCallback(this, &PPB_Surface3D_Impl::OnSwapBuffers)); | 120 NewCallback(this, &PPB_Surface3D_Impl::OnSwapBuffers)); |
| 119 } | 121 } |
| 120 context_ = context; | 122 context_ = context; |
| 121 return true; | 123 return true; |
| 122 } | 124 } |
| 123 | 125 |
| 124 bool PPB_Surface3D_Impl::SwapBuffers() { | 126 bool PPB_Surface3D_Impl::SwapBuffers(PP_CompletionCallback callback) { |
| 125 return context_ && context_->SwapBuffers(); | 127 if (!context_) |
| 128 return false; |
| 129 |
| 130 if (swap_callback_.func) { |
| 131 // Already a pending SwapBuffers that hasn't returned yet. |
| 132 return false; |
| 133 } |
| 134 |
| 135 swap_callback_ = callback; |
| 136 return context_->SwapBuffers(); |
| 137 } |
| 138 |
| 139 void PPB_Surface3D_Impl::ViewInitiatedPaint() { |
| 140 if (swap_callback_.func) { |
| 141 swap_initiated_ = true; |
| 142 } |
| 143 } |
| 144 |
| 145 void PPB_Surface3D_Impl::ViewFlushedPaint() { |
| 146 if (swap_initiated_ && swap_callback_.func) { |
| 147 // We must clear swap_callback_ before issuing the callback. It will be |
| 148 // common for the plugin to issue another SwapBuffers in response to the |
| 149 // callback, and we don't want to think that a callback is already pending. |
| 150 PP_CompletionCallback callback = PP_BlockUntilComplete(); |
| 151 std::swap(callback, swap_callback_); |
| 152 swap_initiated_ = false; |
| 153 PP_RunCompletionCallback(&callback, PP_OK); |
| 154 } |
| 126 } | 155 } |
| 127 | 156 |
| 128 unsigned int PPB_Surface3D_Impl::GetBackingTextureId() { | 157 unsigned int PPB_Surface3D_Impl::GetBackingTextureId() { |
| 129 return context_ ? context_->GetBackingTextureId() : 0; | 158 return context_ ? context_->GetBackingTextureId() : 0; |
| 130 } | 159 } |
| 131 | 160 |
| 132 void PPB_Surface3D_Impl::OnSwapBuffers() { | 161 void PPB_Surface3D_Impl::OnSwapBuffers() { |
| 133 if (bound_to_instance_) | 162 if (bound_to_instance_) |
| 134 instance()->CommitBackingTexture(); | 163 instance()->CommitBackingTexture(); |
| 135 } | 164 } |
| 136 | 165 |
| 137 } // namespace ppapi | 166 } // namespace ppapi |
| 138 } // namespace webkit | 167 } // namespace webkit |
| 139 | 168 |
| OLD | NEW |