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_graphics_3d_impl.h" | 5 #include "webkit/plugins/ppapi/ppb_graphics_3d_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "gpu/command_buffer/client/gles2_implementation.h" | 9 #include "gpu/command_buffer/client/gles2_implementation.h" |
10 #include "webkit/plugins/ppapi/plugin_module.h" | 10 #include "webkit/plugins/ppapi/plugin_module.h" |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
158 return platform_context_->GetCommandBuffer(); | 158 return platform_context_->GetCommandBuffer(); |
159 } | 159 } |
160 | 160 |
161 int32 PPB_Graphics3D_Impl::DoSwapBuffers() { | 161 int32 PPB_Graphics3D_Impl::DoSwapBuffers() { |
162 // We do not have a GLES2 implementation when using an OOP proxy. | 162 // We do not have a GLES2 implementation when using an OOP proxy. |
163 // The plugin-side proxy is responsible for adding the SwapBuffers command | 163 // The plugin-side proxy is responsible for adding the SwapBuffers command |
164 // to the command buffer in that case. | 164 // to the command buffer in that case. |
165 if (gles2_impl()) | 165 if (gles2_impl()) |
166 gles2_impl()->SwapBuffers(); | 166 gles2_impl()->SwapBuffers(); |
167 | 167 |
168 platform_context_->Echo(base::Bind(&PPB_Graphics3D_Impl::OnSwapBuffers, | 168 if (bound_to_instance_) { |
169 weak_ptr_factory_.GetWeakPtr())); | 169 // If we are bound to the instance, we need to ask the compositor |
170 // to commit our backing texture so that the graphics appears on the page. | |
171 // When the backing texture will be committed we get notified via | |
172 // ViewFlushedPaint(). | |
173 // | |
174 // Don't need to check for NULL from GetPluginInstance since when we're | |
175 // bound, we know our instance is valid. | |
176 ResourceHelper::GetPluginInstance(this)->CommitBackingTexture(); | |
piman
2011/11/23 06:41:49
This part is good, but you'll want to fix ppapi::p
| |
177 commit_pending_ = true; | |
178 } else { | |
179 // Wait for the command to complete on the GPU to allow for throttling. | |
180 platform_context_->Echo(base::Bind(&PPB_Graphics3D_Impl::OnSwapBuffers, | |
181 weak_ptr_factory_.GetWeakPtr())); | |
182 } | |
183 | |
170 | 184 |
171 return PP_OK_COMPLETIONPENDING; | 185 return PP_OK_COMPLETIONPENDING; |
172 } | 186 } |
173 | 187 |
174 bool PPB_Graphics3D_Impl::Init(PP_Resource share_context, | 188 bool PPB_Graphics3D_Impl::Init(PP_Resource share_context, |
175 const int32_t* attrib_list) { | 189 const int32_t* attrib_list) { |
176 if (!InitRaw(share_context, attrib_list)) | 190 if (!InitRaw(share_context, attrib_list)) |
177 return false; | 191 return false; |
178 | 192 |
179 gpu::CommandBuffer* command_buffer = GetCommandBuffer(); | 193 gpu::CommandBuffer* command_buffer = GetCommandBuffer(); |
(...skipping 21 matching lines...) Expand all Loading... | |
201 if (!platform_context_->Init(attrib_list)) | 215 if (!platform_context_->Init(attrib_list)) |
202 return false; | 216 return false; |
203 | 217 |
204 platform_context_->SetContextLostCallback( | 218 platform_context_->SetContextLostCallback( |
205 base::Bind(&PPB_Graphics3D_Impl::OnContextLost, | 219 base::Bind(&PPB_Graphics3D_Impl::OnContextLost, |
206 weak_ptr_factory_.GetWeakPtr())); | 220 weak_ptr_factory_.GetWeakPtr())); |
207 return true; | 221 return true; |
208 } | 222 } |
209 | 223 |
210 void PPB_Graphics3D_Impl::OnSwapBuffers() { | 224 void PPB_Graphics3D_Impl::OnSwapBuffers() { |
211 if (bound_to_instance_) { | 225 if (HasPendingSwap()) { |
212 // If we are bound to the instance, we need to ask the compositor | |
213 // to commit our backing texture so that the graphics appears on the page. | |
214 // When the backing texture will be committed we get notified via | |
215 // ViewFlushedPaint(). | |
216 // | |
217 // Don't need to check for NULL from GetPluginInstance since when we're | |
218 // bound, we know our instance is valid. | |
219 ResourceHelper::GetPluginInstance(this)->CommitBackingTexture(); | |
220 commit_pending_ = true; | |
221 } else if (HasPendingSwap()) { | |
222 // If we're off-screen, no need to trigger and wait for compositing. | 226 // If we're off-screen, no need to trigger and wait for compositing. |
223 // Just send the swap-buffers ACK to the plugin immediately. | 227 // Just send the swap-buffers ACK to the plugin immediately. |
224 commit_pending_ = false; | 228 commit_pending_ = false; |
225 SwapBuffersACK(PP_OK); | 229 SwapBuffersACK(PP_OK); |
226 } | 230 } |
227 } | 231 } |
228 | 232 |
229 void PPB_Graphics3D_Impl::OnContextLost() { | 233 void PPB_Graphics3D_Impl::OnContextLost() { |
230 // Don't need to check for NULL from GetPluginInstance since when we're | 234 // Don't need to check for NULL from GetPluginInstance since when we're |
231 // bound, we know our instance is valid. | 235 // bound, we know our instance is valid. |
(...skipping 17 matching lines...) Expand all Loading... | |
249 const PPP_Graphics3D* ppp_graphics_3d = | 253 const PPP_Graphics3D* ppp_graphics_3d = |
250 static_cast<const PPP_Graphics3D*>( | 254 static_cast<const PPP_Graphics3D*>( |
251 instance->module()->GetPluginInterface( | 255 instance->module()->GetPluginInterface( |
252 PPP_GRAPHICS_3D_INTERFACE)); | 256 PPP_GRAPHICS_3D_INTERFACE)); |
253 if (ppp_graphics_3d) | 257 if (ppp_graphics_3d) |
254 ppp_graphics_3d->Graphics3DContextLost(pp_instance()); | 258 ppp_graphics_3d->Graphics3DContextLost(pp_instance()); |
255 } | 259 } |
256 | 260 |
257 } // namespace ppapi | 261 } // namespace ppapi |
258 } // namespace webkit | 262 } // namespace webkit |
OLD | NEW |