Chromium Code Reviews| Index: content/renderer/android/synchronous_compositor_output_surface.cc |
| diff --git a/content/renderer/android/synchronous_compositor_output_surface.cc b/content/renderer/android/synchronous_compositor_output_surface.cc |
| index 87792ea0de59ec588c417e9f71563f15177dcc70..ed269d41bc48eb640b1e5ed842ed30aa4f233b04 100644 |
| --- a/content/renderer/android/synchronous_compositor_output_surface.cc |
| +++ b/content/renderer/android/synchronous_compositor_output_surface.cc |
| @@ -5,23 +5,39 @@ |
| #include "content/renderer/android/synchronous_compositor_output_surface.h" |
| #include "base/logging.h" |
| +#include "base/time.h" |
| #include "cc/output/output_surface_client.h" |
| -#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
| #include "content/public/renderer/android/synchronous_compositor_client.h" |
| #include "content/public/renderer/content_renderer_client.h" |
| #include "skia/ext/refptr.h" |
| #include "third_party/skia/include/core/SkCanvas.h" |
| #include "third_party/skia/include/core/SkPicture.h" |
| +#include "webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" |
| + |
| +using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl; |
| namespace content { |
| +namespace { |
| + |
| +// TODO(boliu): RenderWidgetImpl should create in process contexts as well. |
|
jamesr
2013/05/03 19:46:51
What's RenderWidgetImpl?
|
| +scoped_ptr<WebKit::WebGraphicsContext3D> CreateWebGraphicsContext3D() { |
| + WebKit::WebGraphicsContext3D::Attributes attributes; |
| + attributes.antialias = false; |
| + attributes.shareResources = true; |
| + attributes.noAutomaticFlushes = true; |
| + |
| + return scoped_ptr<WebKit::WebGraphicsContext3D>( |
| + WebGraphicsContext3DInProcessCommandBufferImpl |
| + ::CreateViewContext(attributes, NULL)); |
| +} |
| +} // namespace |
| SynchronousCompositorOutputSurface::SynchronousCompositorOutputSurface( |
| - int32 routing_id, |
| - WebGraphicsContext3DCommandBufferImpl* context) |
| - : cc::OutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D>(context)), |
| + int32 routing_id) |
| + : cc::OutputSurface(CreateWebGraphicsContext3D()), |
| compositor_client_(NULL), |
| - routing_id_(routing_id) { |
| - // WARNING: may be called on any thread. |
| + routing_id_(routing_id), |
| + did_swap_buffer_(false) { |
| } |
| SynchronousCompositorOutputSurface::~SynchronousCompositorOutputSurface() { |
| @@ -40,15 +56,33 @@ bool SynchronousCompositorOutputSurface::BindToClient( |
| return true; |
| } |
| +void SynchronousCompositorOutputSurface::Reshape(gfx::Size size) { |
| + // Intentional no-op. |
| +} |
| + |
| void SynchronousCompositorOutputSurface::SendFrameToParentCompositor( |
| cc::CompositorFrame* frame) { |
| // Intentional no-op: see http://crbug.com/237006 |
| } |
| +void SynchronousCompositorOutputSurface::EnableVSyncNotification( |
| + bool enable_vsync) { |
| + DCHECK(CalledOnValidThread()); |
| + vsync_enabled_ = enable_vsync; |
| + UpdateCompositorClientSettings(); |
| +} |
| + |
| +void SynchronousCompositorOutputSurface::SwapBuffers( |
| + const cc::LatencyInfo& info) { |
| + context3d()->finish(); |
| + did_swap_buffer_ = true; |
| +} |
| + |
| void SynchronousCompositorOutputSurface::SetClient( |
| SynchronousCompositorClient* compositor_client) { |
| DCHECK(CalledOnValidThread()); |
| compositor_client_ = compositor_client; |
| + UpdateCompositorClientSettings(); |
| } |
| bool SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { |
| @@ -57,6 +91,30 @@ bool SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { |
| return false; |
| } |
| +bool SynchronousCompositorOutputSurface::DemandDrawHw(gfx::Rect damage_rect) { |
| + DCHECK(CalledOnValidThread()); |
| + DCHECK(client_); |
| + |
| + did_swap_buffer_ = false; |
| + client_->SetNeedsRedrawRect(damage_rect); |
| + if (vsync_enabled_) |
| + client_->DidVSync(base::TimeTicks::Now()); |
| + |
| + // This is used to make sure that the GLContextVirtual used by the compositor |
| + // restores its state. |
| + static scoped_ptr<WebKit::WebGraphicsContext3D> background_context = |
| + CreateWebGraphicsContext3D(); |
| + background_context->makeContextCurrent(); |
| + |
| + return did_swap_buffer_; |
| +} |
| + |
| +void SynchronousCompositorOutputSurface::UpdateCompositorClientSettings() { |
| + if (compositor_client_) { |
| + compositor_client_->SetContinuousInvalidate(vsync_enabled_); |
| + } |
| +} |
| + |
| // Not using base::NonThreadSafe as we want to enforce a more exacting threading |
| // requirement: SynchronousCompositorOutputSurface() must only be used by |
| // embedders that supply their own compositor loop via |