diff options
author | piman@google.com <piman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-05 01:18:59 +0000 |
---|---|---|
committer | piman@google.com <piman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-05 01:18:59 +0000 |
commit | cad37d275799e1d4761c5f192b134249c34a1c77 (patch) | |
tree | 9d441b1d79ea503563f8607f03d0692da566860a /gpu | |
parent | 783ffc7355af267f7dd6881f9f2436fbcd95b2a1 (diff) | |
download | chromium_src-cad37d275799e1d4761c5f192b134249c34a1c77.zip chromium_src-cad37d275799e1d4761c5f192b134249c34a1c77.tar.gz chromium_src-cad37d275799e1d4761c5f192b134249c34a1c77.tar.bz2 |
Make Graphics3D::SwapBuffers take a completion callback
BUG=none
TEST=with demo_simple_vertex_shader, rate control works
Review URL: http://codereview.chromium.org/5944001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@70474 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gpu')
-rw-r--r-- | gpu/demos/framework/pepper.cc | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/gpu/demos/framework/pepper.cc b/gpu/demos/framework/pepper.cc index ce698d5..c6f6e1f 100644 --- a/gpu/demos/framework/pepper.cc +++ b/gpu/demos/framework/pepper.cc @@ -24,7 +24,9 @@ class PluginInstance : public pp::Instance { PluginInstance(PP_Instance instance, pp::Module* module) : pp::Instance(instance), module_(module), - demo_(CreateDemo()) { + demo_(CreateDemo()), + swap_pending_(false), + paint_needed_(false) { // Set the callback object outside of the initializer list to avoid a // compiler warning about using "this" in an initializer list. callback_factory_.Initialize(this); @@ -63,24 +65,30 @@ class PluginInstance : public pp::Instance { context_.BindSurfaces(surface_, surface_); pp::Instance::BindGraphics(surface_); - if (demo_->IsAnimated()) - Animate(0); - else - Paint(); + Paint(); } void Paint() { + if (swap_pending_) { + // A swap is pending. Delay paint until swap finishes. + paint_needed_ = true; + return; + } glSetCurrentContextPPAPI(context_.pp_resource()); demo_->Draw(); - surface_.SwapBuffers(); + swap_pending_ = true; + surface_.SwapBuffers( + callback_factory_.NewCallback(&PluginInstance::OnSwap)); glSetCurrentContextPPAPI(0); } private: - void Animate(int delay) { - Paint(); - module_->core()->CallOnMainThread(delay, - callback_factory_.NewCallback(&PluginInstance::Animate), delay); + void OnSwap(int32_t) { + swap_pending_ = false; + if (paint_needed_ || demo_->IsAnimated()) { + paint_needed_ = false; + Paint(); + } } pp::Module* module_; @@ -88,6 +96,8 @@ class PluginInstance : public pp::Instance { pp::Context3D_Dev context_; pp::Surface3D_Dev surface_; pp::Size size_; + bool swap_pending_; + bool paint_needed_; pp::CompletionCallbackFactory<PluginInstance> callback_factory_; }; |