summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/renderer/render_view.h3
-rw-r--r--chrome/renderer/webgraphicscontext3d_command_buffer_impl.cc5
-rw-r--r--gpu/demos/framework/pepper.cc30
-rw-r--r--ppapi/cpp/dev/surface_3d_dev.cc4
-rw-r--r--ppapi/cpp/dev/surface_3d_dev.h4
-rw-r--r--webkit/plugins/ppapi/ppapi_plugin_instance.cc4
-rw-r--r--webkit/plugins/ppapi/ppb_surface_3d_impl.cc35
-rw-r--r--webkit/plugins/ppapi/ppb_surface_3d_impl.h9
8 files changed, 75 insertions, 19 deletions
diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h
index 7760d26..4e8d0aa 100644
--- a/chrome/renderer/render_view.h
+++ b/chrome/renderer/render_view.h
@@ -670,13 +670,14 @@ class RenderView : public RenderWidget,
// appropriate section, add it there. If not, there are some random functions
// nearer to the top you can add it to.
+ virtual void DidFlushPaint();
+
protected:
// RenderWidget overrides:
virtual void Close();
virtual void OnResize(const gfx::Size& new_size,
const gfx::Rect& resizer_rect);
virtual void DidInitiatePaint();
- virtual void DidFlushPaint();
virtual webkit::ppapi::PluginInstance* GetBitmapForOptimizedPluginPaint(
const gfx::Rect& paint_bounds,
TransportDIB** dib,
diff --git a/chrome/renderer/webgraphicscontext3d_command_buffer_impl.cc b/chrome/renderer/webgraphicscontext3d_command_buffer_impl.cc
index 659c8be..1be5461 100644
--- a/chrome/renderer/webgraphicscontext3d_command_buffer_impl.cc
+++ b/chrome/renderer/webgraphicscontext3d_command_buffer_impl.cc
@@ -116,6 +116,11 @@ bool WebGraphicsContext3DCommandBufferImpl::initialize(
renderview->routing_id(),
kWebGraphicsContext3DPerferredGLExtensions,
attribs);
+ if (context_) {
+ ggl::SetSwapBuffersCallback(
+ context_,
+ NewCallback(renderview, &RenderView::DidFlushPaint));
+ }
} else {
bool compositing_enabled = !CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableAcceleratedCompositing);
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_;
};
diff --git a/ppapi/cpp/dev/surface_3d_dev.cc b/ppapi/cpp/dev/surface_3d_dev.cc
index a222683..eab8149 100644
--- a/ppapi/cpp/dev/surface_3d_dev.cc
+++ b/ppapi/cpp/dev/surface_3d_dev.cc
@@ -38,13 +38,13 @@ Surface3D_Dev::Surface3D_Dev(const Instance& instance,
}
}
-int32_t Surface3D_Dev::SwapBuffers() const {
+int32_t Surface3D_Dev::SwapBuffers(const CompletionCallback& cc) const {
if (!has_interface<PPB_Surface3D_Dev>())
return PP_ERROR_NOINTERFACE;
return get_interface<PPB_Surface3D_Dev>()->SwapBuffers(
pp_resource(),
- PP_BlockUntilComplete());
+ cc.pp_completion_callback());
}
} // namespace pp
diff --git a/ppapi/cpp/dev/surface_3d_dev.h b/ppapi/cpp/dev/surface_3d_dev.h
index ff7c809..450ce41 100644
--- a/ppapi/cpp/dev/surface_3d_dev.h
+++ b/ppapi/cpp/dev/surface_3d_dev.h
@@ -7,6 +7,7 @@
#include "ppapi/c/dev/ppb_surface_3d_dev.h"
+#include "ppapi/cpp/completion_callback.h"
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/resource.h"
@@ -23,8 +24,7 @@ class Surface3D_Dev : public Resource {
PP_Config3D_Dev config,
const int32_t* attrib_list);
- // TODO(alokp): Add completion callback.
- int32_t SwapBuffers() const;
+ int32_t SwapBuffers(const CompletionCallback& cc) const;
protected:
explicit Surface3D_Dev(PP_Resource resource_id) : Resource(resource_id) {}
diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.cc b/webkit/plugins/ppapi/ppapi_plugin_instance.cc
index 33e05fa..5147b32 100644
--- a/webkit/plugins/ppapi/ppapi_plugin_instance.cc
+++ b/webkit/plugins/ppapi/ppapi_plugin_instance.cc
@@ -631,11 +631,15 @@ void PluginInstance::SetContentAreaFocus(bool has_focus) {
void PluginInstance::ViewInitiatedPaint() {
if (bound_graphics_2d())
bound_graphics_2d()->ViewInitiatedPaint();
+ if (bound_graphics_3d())
+ bound_graphics_3d()->ViewInitiatedPaint();
}
void PluginInstance::ViewFlushedPaint() {
if (bound_graphics_2d())
bound_graphics_2d()->ViewFlushedPaint();
+ if (bound_graphics_3d())
+ bound_graphics_3d()->ViewFlushedPaint();
}
bool PluginInstance::GetBitmapForOptimizedPluginPaint(
diff --git a/webkit/plugins/ppapi/ppb_surface_3d_impl.cc b/webkit/plugins/ppapi/ppb_surface_3d_impl.cc
index 0283d3b..5b42cf9 100644
--- a/webkit/plugins/ppapi/ppb_surface_3d_impl.cc
+++ b/webkit/plugins/ppapi/ppb_surface_3d_impl.cc
@@ -51,7 +51,7 @@ int32_t SwapBuffers(PP_Resource surface_id,
PP_CompletionCallback callback) {
scoped_refptr<PPB_Surface3D_Impl> surface(
Resource::GetAs<PPB_Surface3D_Impl>(surface_id));
- return surface->SwapBuffers();
+ return surface->SwapBuffers(callback);
}
const PPB_Surface3D_Dev ppb_surface3d = {
@@ -68,6 +68,8 @@ PPB_Surface3D_Impl::PPB_Surface3D_Impl(PluginInstance* instance)
: Resource(instance->module()),
instance_(instance),
bound_to_instance_(false),
+ swap_initiated_(false),
+ swap_callback_(PP_BlockUntilComplete()),
context_(NULL) {
}
@@ -121,8 +123,35 @@ bool PPB_Surface3D_Impl::BindToContext(
return true;
}
-bool PPB_Surface3D_Impl::SwapBuffers() {
- return context_ && context_->SwapBuffers();
+bool PPB_Surface3D_Impl::SwapBuffers(PP_CompletionCallback callback) {
+ if (!context_)
+ return false;
+
+ if (swap_callback_.func) {
+ // Already a pending SwapBuffers that hasn't returned yet.
+ return false;
+ }
+
+ swap_callback_ = callback;
+ return context_->SwapBuffers();
+}
+
+void PPB_Surface3D_Impl::ViewInitiatedPaint() {
+ if (swap_callback_.func) {
+ swap_initiated_ = true;
+ }
+}
+
+void PPB_Surface3D_Impl::ViewFlushedPaint() {
+ if (swap_initiated_ && swap_callback_.func) {
+ // We must clear swap_callback_ before issuing the callback. It will be
+ // common for the plugin to issue another SwapBuffers in response to the
+ // callback, and we don't want to think that a callback is already pending.
+ PP_CompletionCallback callback = PP_BlockUntilComplete();
+ std::swap(callback, swap_callback_);
+ swap_initiated_ = false;
+ PP_RunCompletionCallback(&callback, PP_OK);
+ }
}
unsigned int PPB_Surface3D_Impl::GetBackingTextureId() {
diff --git a/webkit/plugins/ppapi/ppb_surface_3d_impl.h b/webkit/plugins/ppapi/ppb_surface_3d_impl.h
index d09689e..0cd0643 100644
--- a/webkit/plugins/ppapi/ppb_surface_3d_impl.h
+++ b/webkit/plugins/ppapi/ppb_surface_3d_impl.h
@@ -49,7 +49,10 @@ class PPB_Surface3D_Impl : public Resource {
unsigned int GetBackingTextureId();
- bool SwapBuffers();
+ bool SwapBuffers(PP_CompletionCallback callback);
+
+ void ViewInitiatedPaint();
+ void ViewFlushedPaint();
private:
// Called when SwapBuffers is complete.
@@ -59,6 +62,10 @@ class PPB_Surface3D_Impl : public Resource {
PluginInstance* instance_;
bool bound_to_instance_;
+ // True when the page's SwapBuffers has been issued but not returned yet.
+ bool swap_initiated_;
+ PP_CompletionCallback swap_callback_;
+
// The context this surface is currently bound to.
PluginDelegate::PlatformContext3D* context_;