Chromium Code Reviews| Index: content/browser/android/in_process/synchronous_compositor_impl.cc |
| diff --git a/content/browser/android/in_process/synchronous_compositor_impl.cc b/content/browser/android/in_process/synchronous_compositor_impl.cc |
| index 678f622875b9ceef5056a7b72a5057db68e7a795..1c571c7cc3471606cb7cabf4571338e0c8722ab9 100644 |
| --- a/content/browser/android/in_process/synchronous_compositor_impl.cc |
| +++ b/content/browser/android/in_process/synchronous_compositor_impl.cc |
| @@ -16,13 +16,20 @@ |
| #include "content/public/browser/render_process_host.h" |
| #include "content/public/browser/render_view_host.h" |
| #include "content/renderer/android/synchronous_compositor_factory.h" |
| +#include "content/renderer/media/android/stream_texture_factory_android_synchronous_impl.h" |
| +#include "gpu/command_buffer/client/gl_in_process_context.h" |
| +#include "gpu/command_buffer/service/stream_texture_manager_in_process_android.h" |
| +#include "ui/gl/android/surface_texture_bridge.h" |
| #include "ui/gl/gl_surface.h" |
| #include "webkit/common/gpu/context_provider_in_process.h" |
| +#include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" |
| namespace content { |
| namespace { |
| +using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl; |
| + |
| int GetInProcessRendererId() { |
| content::RenderProcessHost::iterator it = |
| content::RenderProcessHost::AllHostsIterator(); |
| @@ -38,9 +45,35 @@ int GetInProcessRendererId() { |
| return id; |
| } |
| +class VideoContextProvider |
| + : public StreamTextureFactorySynchronousImpl::ContextProvider { |
| + public: |
| + VideoContextProvider( |
| + const scoped_refptr<cc::ContextProvider>& context_provider, |
| + gpu::GLInProcessContext* gl_in_process_context) |
| + : context_provider_(context_provider), |
| + gl_in_process_context_(gl_in_process_context) {} |
| + |
| + virtual scoped_refptr<gfx::SurfaceTextureBridge> GetSurfaceTexture( |
| + uint32 stream_id) OVERRIDE { |
| + return gl_in_process_context_->GetSurfaceTexture(stream_id); |
| + } |
| + |
| + virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE { |
| + return context_provider_->Context3d(); |
| + } |
| + |
| + private: |
| + scoped_refptr<cc::ContextProvider> context_provider_; |
| + gpu::GLInProcessContext* gl_in_process_context_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(VideoContextProvider); |
| +}; |
| + |
| class SynchronousCompositorFactoryImpl : public SynchronousCompositorFactory { |
| public: |
| - SynchronousCompositorFactoryImpl() { |
| + SynchronousCompositorFactoryImpl() |
| + : offscreen_context_as_gl_in_process_context_(NULL) { |
| SynchronousCompositorFactory::SetInstance(this); |
| } |
| @@ -65,15 +98,53 @@ class SynchronousCompositorFactoryImpl : public SynchronousCompositorFactory { |
| return &synchronous_input_event_filter_; |
| } |
| + scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> |
| + CreateOffscreenContext() { |
| + if (!gfx::GLSurface::InitializeOneOff()) |
| + return scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>(); |
| + |
| + const char* allowed_extensions = "*"; |
|
boliu
2013/08/20 21:33:49
Leave a comment about deduping this code.
no sievers
2013/08/20 21:59:58
Well, ideally we wouldn't have one thing (GLInProc
|
| + const gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; |
| + |
| + WebKit::WebGraphicsContext3D::Attributes attributes; |
| + attributes.antialias = false; |
| + attributes.shareResources = true; |
| + attributes.noAutomaticFlushes = true; |
| + |
| + gpu::GLInProcessContextAttribs in_process_attribs; |
| + WebGraphicsContext3DInProcessCommandBufferImpl::ConvertAttributes( |
| + attributes, &in_process_attribs); |
| + scoped_ptr<gpu::GLInProcessContext> context( |
| + gpu::GLInProcessContext::CreateContext(true, |
| + NULL, |
| + gfx::Size(1, 1), |
| + attributes.shareResources, |
| + allowed_extensions, |
| + in_process_attribs, |
| + gpu_preference)); |
| + |
| + offscreen_context_as_gl_in_process_context_ = context.get(); |
| + if (!context.get()) |
| + return scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>(); |
| + |
| + return scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>( |
| + WebGraphicsContext3DInProcessCommandBufferImpl::WrapContext( |
| + context.Pass(), attributes)); |
| + } |
| + |
| virtual scoped_refptr<cc::ContextProvider> |
| GetOffscreenContextProviderForMainThread() OVERRIDE { |
| if (!offscreen_context_for_main_thread_.get() || |
| offscreen_context_for_main_thread_->DestroyedOnMainThread()) { |
| offscreen_context_for_main_thread_ = |
| - webkit::gpu::ContextProviderInProcess::CreateOffscreen(); |
| + webkit::gpu::ContextProviderInProcess::Create(base::Bind( |
| + &SynchronousCompositorFactoryImpl::CreateOffscreenContext, |
| + base::Unretained(this))); |
| if (offscreen_context_for_main_thread_.get() && |
| - !offscreen_context_for_main_thread_->BindToCurrentThread()) |
| + !offscreen_context_for_main_thread_->BindToCurrentThread()) { |
| offscreen_context_for_main_thread_ = NULL; |
| + offscreen_context_as_gl_in_process_context_ = NULL; |
| + } |
| } |
| return offscreen_context_for_main_thread_; |
| } |
| @@ -95,6 +166,16 @@ class SynchronousCompositorFactoryImpl : public SynchronousCompositorFactory { |
| return offscreen_context_for_compositor_thread_; |
| } |
| + virtual scoped_ptr<StreamTextureFactory> CreateStreamTextureFactory( |
| + int view_id) OVERRIDE { |
| + scoped_refptr<VideoContextProvider> context_provider = |
| + new VideoContextProvider(offscreen_context_for_main_thread_, |
| + offscreen_context_as_gl_in_process_context_); |
| + return make_scoped_ptr(new StreamTextureFactorySynchronousImpl( |
| + context_provider.get(), view_id)) |
| + .PassAs<StreamTextureFactory>(); |
| + } |
| + |
| private: |
| SynchronousInputEventFilter synchronous_input_event_filter_; |
| @@ -102,6 +183,7 @@ class SynchronousCompositorFactoryImpl : public SynchronousCompositorFactory { |
| // not usage. |
| base::Lock offscreen_context_for_compositor_thread_creation_lock_; |
| scoped_refptr<cc::ContextProvider> offscreen_context_for_main_thread_; |
| + gpu::GLInProcessContext* offscreen_context_as_gl_in_process_context_; |
|
boliu
2013/08/20 21:33:49
Indicate with var name or a comment that this is a
no sievers
2013/08/20 21:59:58
Done.
|
| scoped_refptr<cc::ContextProvider> offscreen_context_for_compositor_thread_; |
| }; |