| 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_graphics_3d_impl.h" | 5 #include "webkit/plugins/ppapi/ppb_graphics_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 "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" | 
| 9 #include "base/thread_local.h" | 9 #include "base/thread_local.h" | 
| 10 #include "ppapi/c/dev/ppb_graphics_3d_dev.h" | 10 #include "ppapi/c/dev/ppb_graphics_3d_dev.h" | 
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 90         Resource::GetAs<PPB_Graphics3D_Impl>(graphics3d)); | 90         Resource::GetAs<PPB_Graphics3D_Impl>(graphics3d)); | 
| 91     return BoolToPPBool(context.get() && context->MakeCurrent()); | 91     return BoolToPPBool(context.get() && context->MakeCurrent()); | 
| 92   } | 92   } | 
| 93 } | 93 } | 
| 94 | 94 | 
| 95 PP_Resource GetCurrentContext() { | 95 PP_Resource GetCurrentContext() { | 
| 96   PPB_Graphics3D_Impl* current_context = PPB_Graphics3D_Impl::GetCurrent(); | 96   PPB_Graphics3D_Impl* current_context = PPB_Graphics3D_Impl::GetCurrent(); | 
| 97   return current_context ? current_context->GetReference() : 0; | 97   return current_context ? current_context->GetReference() : 0; | 
| 98 } | 98 } | 
| 99 | 99 | 
| 100 PP_Bool SwapBuffers(PP_Resource graphics3d, PP_CompletionCallback callback) { | 100 PP_Bool SwapBuffers(PP_Resource graphics3d) { | 
| 101   scoped_refptr<PPB_Graphics3D_Impl> context( | 101   scoped_refptr<PPB_Graphics3D_Impl> context( | 
| 102       Resource::GetAs<PPB_Graphics3D_Impl>(graphics3d)); | 102       Resource::GetAs<PPB_Graphics3D_Impl>(graphics3d)); | 
| 103   return BoolToPPBool(context && context->SwapBuffers(callback)); | 103   return BoolToPPBool(context && context->SwapBuffers()); | 
| 104 } | 104 } | 
| 105 | 105 | 
| 106 uint32_t GetError() { | 106 uint32_t GetError() { | 
| 107   // Technically, this should return the last error that occurred on the current | 107   // Technically, this should return the last error that occurred on the current | 
| 108   // thread, rather than an error associated with a particular context. | 108   // thread, rather than an error associated with a particular context. | 
| 109   // TODO(apatrick): Fix this. | 109   // TODO(apatrick): Fix this. | 
| 110   PPB_Graphics3D_Impl* current_context = PPB_Graphics3D_Impl::GetCurrent(); | 110   PPB_Graphics3D_Impl* current_context = PPB_Graphics3D_Impl::GetCurrent(); | 
| 111   if (!current_context) | 111   if (!current_context) | 
| 112     return 0; | 112     return 0; | 
| 113 | 113 | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
| 125   &MakeCurrent, | 125   &MakeCurrent, | 
| 126   &GetCurrentContext, | 126   &GetCurrentContext, | 
| 127   &SwapBuffers, | 127   &SwapBuffers, | 
| 128   &GetError | 128   &GetError | 
| 129 }; | 129 }; | 
| 130 | 130 | 
| 131 }  // namespace | 131 }  // namespace | 
| 132 | 132 | 
| 133 PPB_Graphics3D_Impl::PPB_Graphics3D_Impl(PluginModule* module) | 133 PPB_Graphics3D_Impl::PPB_Graphics3D_Impl(PluginModule* module) | 
| 134   : Resource(module), | 134   : Resource(module), | 
| 135     bound_instance_(NULL), | 135     bound_instance_(NULL) { | 
| 136     swap_initiated_(false), |  | 
| 137     swap_callback_(PP_BlockUntilComplete()) { |  | 
| 138 } | 136 } | 
| 139 | 137 | 
| 140 const PPB_Graphics3D_Dev* PPB_Graphics3D_Impl::GetInterface() { | 138 const PPB_Graphics3D_Dev* PPB_Graphics3D_Impl::GetInterface() { | 
| 141   return &ppb_graphics3d; | 139   return &ppb_graphics3d; | 
| 142 } | 140 } | 
| 143 | 141 | 
| 144 PPB_Graphics3D_Impl* PPB_Graphics3D_Impl::GetCurrent() { | 142 PPB_Graphics3D_Impl* PPB_Graphics3D_Impl::GetCurrent() { | 
| 145   return g_current_context_key.Get().Get(); | 143   return g_current_context_key.Get().Get(); | 
| 146 } | 144 } | 
| 147 | 145 | 
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 208 bool PPB_Graphics3D_Impl::MakeCurrent() { | 206 bool PPB_Graphics3D_Impl::MakeCurrent() { | 
| 209   if (!platform_context_.get()) | 207   if (!platform_context_.get()) | 
| 210     return false; | 208     return false; | 
| 211 | 209 | 
| 212   g_current_context_key.Get().Set(this); | 210   g_current_context_key.Get().Set(this); | 
| 213 | 211 | 
| 214   // TODO(apatrick): Return false on context lost. | 212   // TODO(apatrick): Return false on context lost. | 
| 215   return true; | 213   return true; | 
| 216 } | 214 } | 
| 217 | 215 | 
| 218 bool PPB_Graphics3D_Impl::SwapBuffers(PP_CompletionCallback callback) { | 216 bool PPB_Graphics3D_Impl::SwapBuffers() { | 
| 219   if (!platform_context_.get()) | 217   if (!platform_context_.get()) | 
| 220     return false; | 218     return false; | 
| 221 | 219 | 
| 222   if (swap_callback_.func) { |  | 
| 223     // Already a pending SwapBuffers that hasn't returned yet. |  | 
| 224     return false; |  | 
| 225   } |  | 
| 226 |  | 
| 227   swap_callback_ = callback; |  | 
| 228   return platform_context_->SwapBuffers(); | 220   return platform_context_->SwapBuffers(); | 
| 229 } | 221 } | 
| 230 | 222 | 
| 231 unsigned PPB_Graphics3D_Impl::GetError() { | 223 unsigned PPB_Graphics3D_Impl::GetError() { | 
| 232   if (!platform_context_.get()) | 224   if (!platform_context_.get()) | 
| 233     return 0; | 225     return 0; | 
| 234 | 226 | 
| 235   return platform_context_->GetError(); | 227   return platform_context_->GetError(); | 
| 236 } | 228 } | 
| 237 | 229 | 
| 238 void PPB_Graphics3D_Impl::ResizeBackingTexture(const gfx::Size& size) { | 230 void PPB_Graphics3D_Impl::ResizeBackingTexture(const gfx::Size& size) { | 
| 239   if (!platform_context_.get()) | 231   if (!platform_context_.get()) | 
| 240     return; | 232     return; | 
| 241 | 233 | 
| 242   platform_context_->ResizeBackingTexture(size); | 234   platform_context_->ResizeBackingTexture(size); | 
| 243 } | 235 } | 
| 244 | 236 | 
| 245 void PPB_Graphics3D_Impl::SetSwapBuffersCallback(Callback0::Type* callback) { | 237 void PPB_Graphics3D_Impl::SetSwapBuffersCallback(Callback0::Type* callback) { | 
| 246   if (!platform_context_.get()) | 238   if (!platform_context_.get()) | 
| 247     return; | 239     return; | 
| 248 | 240 | 
| 249   platform_context_->SetSwapBuffersCallback(callback); | 241   platform_context_->SetSwapBuffersCallback(callback); | 
| 250 } | 242 } | 
| 251 | 243 | 
| 252 void PPB_Graphics3D_Impl::ViewInitiatedPaint() { |  | 
| 253   if (swap_callback_.func) { |  | 
| 254     swap_initiated_ = true; |  | 
| 255   } |  | 
| 256 } |  | 
| 257 |  | 
| 258 void PPB_Graphics3D_Impl::ViewFlushedPaint() { |  | 
| 259   // Notify any "painted" callback. See |unpainted_flush_callback_| in the |  | 
| 260   // header for more. |  | 
| 261   if (swap_initiated_ && swap_callback_.func) { |  | 
| 262     // We must clear swap_callback_ before issuing the callback. It will be |  | 
| 263     // common for the plugin to issue another SwapBuffers in response to the |  | 
| 264     // callback, and we don't want to think that a callback is already pending. |  | 
| 265     PP_CompletionCallback callback = PP_BlockUntilComplete(); |  | 
| 266     std::swap(callback, swap_callback_); |  | 
| 267     swap_initiated_ = false; |  | 
| 268     PP_RunCompletionCallback(&callback, PP_OK); |  | 
| 269   } |  | 
| 270 } |  | 
| 271 |  | 
| 272 unsigned PPB_Graphics3D_Impl::GetBackingTextureId() { | 244 unsigned PPB_Graphics3D_Impl::GetBackingTextureId() { | 
| 273   if (!platform_context_.get()) | 245   if (!platform_context_.get()) | 
| 274     return 0; | 246     return 0; | 
| 275 | 247 | 
| 276   return platform_context_->GetBackingTextureId(); | 248   return platform_context_->GetBackingTextureId(); | 
| 277 } | 249 } | 
| 278 | 250 | 
| 279 void PPB_Graphics3D_Impl::Destroy() { | 251 void PPB_Graphics3D_Impl::Destroy() { | 
| 280   if (GetCurrent() == this) { | 252   if (GetCurrent() == this) { | 
| 281     ResetCurrent(); | 253     ResetCurrent(); | 
| 282   } | 254   } | 
| 283 | 255 | 
| 284   gles2_implementation_ = NULL; | 256   gles2_implementation_ = NULL; | 
| 285 | 257 | 
| 286   platform_context_.reset(); | 258   platform_context_.reset(); | 
| 287 } | 259 } | 
| 288 | 260 | 
| 289 }  // namespace ppapi | 261 }  // namespace ppapi | 
| 290 }  // namespace webkit | 262 }  // namespace webkit | 
| 291 | 263 | 
| OLD | NEW | 
|---|