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