Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(509)

Unified Diff: content/browser/android/in_process/synchronous_compositor_factory_impl.cc

Issue 271763002: Clean up SyncCompositorFactory context creation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: inline Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/android/in_process/synchronous_compositor_factory_impl.cc
diff --git a/content/browser/android/in_process/synchronous_compositor_factory_impl.cc b/content/browser/android/in_process/synchronous_compositor_factory_impl.cc
index 3e5df8b7d6cf21cdfe635ab4ca44c6826ac24a63..62aa33e256462bc2c671714f1c9649b053edfb55 100644
--- a/content/browser/android/in_process/synchronous_compositor_factory_impl.cc
+++ b/content/browser/android/in_process/synchronous_compositor_factory_impl.cc
@@ -32,23 +32,25 @@ blink::WebGraphicsContext3D::Attributes GetDefaultAttribs() {
using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl;
-scoped_ptr<gpu::GLInProcessContext> CreateContextWithAttributes(
- scoped_refptr<gfx::GLSurface> surface,
- scoped_refptr<gpu::InProcessCommandBuffer::Service> service,
- gpu::GLInProcessContext* share_context,
+scoped_ptr<gpu::GLInProcessContext> CreateOffscreenContext(
const blink::WebGraphicsContext3D::Attributes& attributes) {
const gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu;
- if (!surface)
- surface = gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size(1, 1));
-
gpu::GLInProcessContextAttribs in_process_attribs;
WebGraphicsContext3DInProcessCommandBufferImpl::ConvertAttributes(
attributes, &in_process_attribs);
in_process_attribs.lose_context_when_out_of_memory = 1;
+
scoped_ptr<gpu::GLInProcessContext> context(
- gpu::GLInProcessContext::CreateWithSurface(
- surface, service, share_context, in_process_attribs, gpu_preference));
+ gpu::GLInProcessContext::Create(NULL /* service */,
+ NULL /* surface */,
+ true /* is_offscreen */,
+ gfx::kNullAcceleratedWidget,
+ gfx::Size(1, 1),
+ NULL /* share_context */,
+ false /* share_resources */,
+ in_process_attribs,
+ gpu_preference));
return context.Pass();
}
@@ -56,8 +58,31 @@ scoped_ptr<gpu::GLInProcessContext> CreateContext(
scoped_refptr<gfx::GLSurface> surface,
scoped_refptr<gpu::InProcessCommandBuffer::Service> service,
gpu::GLInProcessContext* share_context) {
- return CreateContextWithAttributes(
- surface, service, share_context, GetDefaultAttribs());
+ const gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu;
+ gpu::GLInProcessContextAttribs in_process_attribs;
+ WebGraphicsContext3DInProcessCommandBufferImpl::ConvertAttributes(
+ GetDefaultAttribs(), &in_process_attribs);
+ in_process_attribs.lose_context_when_out_of_memory = 1;
+
+
+ bool is_offscreen = false;
+ gfx::Size size(1, 1);
+ if (surface) {
+ is_offscreen = surface->IsOffscreen();
+ size = surface->GetSize();
+ }
+
+ scoped_ptr<gpu::GLInProcessContext> context(
+ gpu::GLInProcessContext::Create(service,
+ surface,
+ is_offscreen,
+ gfx::kNullAcceleratedWidget,
+ size,
+ share_context,
+ false /* share_resources */,
+ in_process_attribs,
+ gpu_preference));
+ return context.Pass();
}
scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> WrapContext(
@@ -107,8 +132,7 @@ class VideoContextProvider
using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl;
SynchronousCompositorFactoryImpl::SynchronousCompositorFactoryImpl()
- : wrapped_gl_context_for_compositor_thread_(NULL),
- num_hardware_compositors_(0) {
+ : num_hardware_compositors_(0) {
SynchronousCompositorFactory::SetInstance(this);
}
@@ -137,7 +161,7 @@ scoped_refptr<ContextProviderWebContext> SynchronousCompositorFactoryImpl::
if ((!offscreen_context_for_main_thread_.get() ||
offscreen_context_for_main_thread_->DestroyedOnMainThread())) {
scoped_ptr<gpu::GLInProcessContext> context =
- CreateContext(NULL, NULL, NULL);
+ CreateOffscreenContext(GetDefaultAttribs());
offscreen_context_for_main_thread_ =
webkit::gpu::ContextProviderInProcess::Create(
WrapContext(context.Pass()),
@@ -152,42 +176,16 @@ scoped_refptr<ContextProviderWebContext> SynchronousCompositorFactoryImpl::
return offscreen_context_for_main_thread_;
}
-// This is called on the renderer compositor impl thread (InitializeHwDraw) in
-// order to support Android WebView synchronously enable and disable hardware
-// mode multiple times in the same task.
-scoped_refptr<cc::ContextProvider> SynchronousCompositorFactoryImpl::
- GetOffscreenContextProviderForCompositorThread() {
- DCHECK(service_);
- bool failed = false;
- if (!offscreen_context_for_compositor_thread_.get() ||
- offscreen_context_for_compositor_thread_->DestroyedOnMainThread()) {
- scoped_ptr<gpu::GLInProcessContext> context =
- CreateContext(new gfx::GLSurfaceStub, service_, NULL);
- wrapped_gl_context_for_compositor_thread_ = context.get();
- offscreen_context_for_compositor_thread_ =
- webkit::gpu::ContextProviderInProcess::Create(
- WrapContext(context.Pass()),
- "Compositor-Offscreen-compositor-thread");
- failed = !offscreen_context_for_compositor_thread_.get() ||
- !offscreen_context_for_compositor_thread_->BindToCurrentThread();
- }
- if (failed) {
- offscreen_context_for_compositor_thread_ = NULL;
- wrapped_gl_context_for_compositor_thread_ = NULL;
- }
- return offscreen_context_for_compositor_thread_;
-}
-
scoped_refptr<cc::ContextProvider> SynchronousCompositorFactoryImpl::
CreateOnscreenContextProviderForCompositorThread(
scoped_refptr<gfx::GLSurface> surface) {
DCHECK(surface);
DCHECK(service_);
- DCHECK(wrapped_gl_context_for_compositor_thread_);
+ if (!share_context_.get())
+ share_context_ = CreateContext(NULL, service_, NULL);
return webkit::gpu::ContextProviderInProcess::Create(
- WrapContext(CreateContext(
- surface, service_, wrapped_gl_context_for_compositor_thread_)),
+ WrapContext(CreateContext(surface, service_, share_context_.get())),
"Compositor-Onscreen");
}
@@ -205,8 +203,7 @@ SynchronousCompositorFactoryImpl::CreateStreamTextureFactory(int view_id) {
blink::WebGraphicsContext3D*
SynchronousCompositorFactoryImpl::CreateOffscreenGraphicsContext3D(
const blink::WebGraphicsContext3D::Attributes& attributes) {
- return WrapContext(CreateContextWithAttributes(NULL, NULL, NULL, attributes))
- .release();
+ return WrapContext(CreateOffscreenContext(attributes)).release();
}
void SynchronousCompositorFactoryImpl::CompositorInitializedHardwareDraw() {
@@ -235,12 +232,10 @@ SynchronousCompositorFactoryImpl::TryCreateStreamTextureFactory() {
// will fail creation when all compositors release hardware draw.
if (CanCreateMainThreadContext() && !video_context_provider_) {
DCHECK(service_);
- DCHECK(wrapped_gl_context_for_compositor_thread_);
+ DCHECK(share_context_.get());
video_context_provider_ = new VideoContextProvider(
- CreateContext(new gfx::GLSurfaceStub,
- service_,
- wrapped_gl_context_for_compositor_thread_));
+ CreateContext(NULL, service_, share_context_.get()));
}
return video_context_provider_;
}

Powered by Google App Engine
This is Rietveld 408576698