| Index: content/browser/android/in_process/synchronous_compositor_output_surface.cc
|
| diff --git a/content/browser/android/in_process/synchronous_compositor_output_surface.cc b/content/browser/android/in_process/synchronous_compositor_output_surface.cc
|
| index fafd06fda22c7268b4f5d38024cee0196389259e..1992c8dc81f319dc38fc7341d75fc0c02773d03f 100644
|
| --- a/content/browser/android/in_process/synchronous_compositor_output_surface.cc
|
| +++ b/content/browser/android/in_process/synchronous_compositor_output_surface.cc
|
| @@ -15,6 +15,7 @@
|
| #include "content/browser/android/in_process/synchronous_compositor_impl.h"
|
| #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
|
| #include "content/public/browser/browser_thread.h"
|
| +#include "gpu/command_buffer/client/gl_in_process_context.h"
|
| #include "third_party/skia/include/core/SkCanvas.h"
|
| #include "third_party/skia/include/core/SkDevice.h"
|
| #include "ui/gfx/rect_conversions.h"
|
| @@ -23,22 +24,58 @@
|
| #include "ui/gl/gl_context.h"
|
| #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h"
|
|
|
| -using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl;
|
|
|
| namespace content {
|
|
|
| namespace {
|
|
|
| -// TODO(boliu): RenderThreadImpl should create in process contexts as well.
|
| -scoped_ptr<WebKit::WebGraphicsContext3D> CreateWebGraphicsContext3D() {
|
| +scoped_ptr<WebKit::WebGraphicsContext3D> CreateWebGraphicsContext3D(
|
| + scoped_refptr<gfx::GLSurface> surface) {
|
| + using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl;
|
| + if (!gfx::GLSurface::InitializeOneOff())
|
| + scoped_ptr<WebKit::WebGraphicsContext3D>();
|
| +
|
| + // TODO(boliu): Much of this code is copied or adapted from
|
| + // WebGraphicsContext3DInProcessCommandBufferImpl. Refactor and reduce
|
| + // code duplication.
|
| + const bool offscreen = false;
|
| + const gfx::Size size(1, 1);
|
| + const char* allowed_extensions = "*";
|
| + const gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu;
|
| +
|
| WebKit::WebGraphicsContext3D::Attributes attributes;
|
| attributes.antialias = false;
|
| attributes.shareResources = true;
|
| attributes.noAutomaticFlushes = true;
|
| + const int alpha_size = attributes.alpha ? 8 : 0;
|
| + const int depth_size = attributes.depth ? 24 : 0;
|
| + const int stencil_size = attributes.stencil ? 8 : 0;
|
| + const int samples = attributes.antialias ? 4 : 0;
|
| + const int sample_buffers = attributes.antialias ? 1 : 0;
|
| + const int32 attribs[] = {
|
| + gpu::GLInProcessContext::ALPHA_SIZE, alpha_size,
|
| + gpu::GLInProcessContext::DEPTH_SIZE, depth_size,
|
| + gpu::GLInProcessContext::STENCIL_SIZE, stencil_size,
|
| + gpu::GLInProcessContext::SAMPLES, samples,
|
| + gpu::GLInProcessContext::SAMPLE_BUFFERS, sample_buffers,
|
| + gpu::GLInProcessContext::NONE,
|
| + };
|
| +
|
| + scoped_ptr<gpu::GLInProcessContext> context(
|
| + gpu::GLInProcessContext::CreateWithSurface(surface,
|
| + offscreen,
|
| + size,
|
| + attributes.shareResources,
|
| + allowed_extensions,
|
| + attribs,
|
| + gpu_preference));
|
| +
|
| + if (!context.get())
|
| + scoped_ptr<WebKit::WebGraphicsContext3D>();
|
|
|
| return scoped_ptr<WebKit::WebGraphicsContext3D>(
|
| - WebGraphicsContext3DInProcessCommandBufferImpl
|
| - ::CreateViewContext(attributes, NULL));
|
| + WebGraphicsContext3DInProcessCommandBufferImpl::WrapContext(
|
| + context.Pass(), attributes));
|
| }
|
|
|
| void DidActivatePendingTree(int routing_id) {
|
| @@ -180,13 +217,21 @@ bool SynchronousCompositorOutputSurface::InitializeHwDraw(
|
| DCHECK(CalledOnValidThread());
|
| DCHECK(HasClient());
|
| DCHECK(!context3d_);
|
| + DCHECK(!surface_);
|
| +
|
| + surface_ = new gfx::GLSurfaceStub;
|
| + bool success = InitializeAndSetContext3D(
|
| + CreateWebGraphicsContext3D(surface_).Pass(), offscreen_context);
|
| + if (!success)
|
| + surface_ = NULL;
|
|
|
| - return InitializeAndSetContext3D(CreateWebGraphicsContext3D().Pass(),
|
| - offscreen_context);
|
| + return success;
|
| }
|
|
|
| void SynchronousCompositorOutputSurface::ReleaseHwDraw() {
|
| + DCHECK(surface_);
|
| cc::OutputSurface::ReleaseGL();
|
| + surface_ = NULL;
|
| }
|
|
|
| bool SynchronousCompositorOutputSurface::DemandDrawHw(
|
| @@ -197,6 +242,9 @@ bool SynchronousCompositorOutputSurface::DemandDrawHw(
|
| DCHECK(CalledOnValidThread());
|
| DCHECK(HasClient());
|
| DCHECK(context3d());
|
| + DCHECK(surface_);
|
| +
|
| + surface_->SaveCurrentFBO();
|
|
|
| gfx::Transform adjusted_transform = transform;
|
| AdjustTransformForClip(&adjusted_transform, clip);
|
| @@ -205,8 +253,6 @@ bool SynchronousCompositorOutputSurface::DemandDrawHw(
|
| SetExternalStencilTest(stencil_enabled);
|
| InvokeComposite(clip.size());
|
|
|
| - // TODO(boliu): Check if context is lost here.
|
| -
|
| return did_swap_buffer_;
|
| }
|
|
|
|
|