Commit 7dfcda1c authored by boliu@chromium.org's avatar boliu@chromium.org

Clean up SyncCompositorFactory context creation

Separate out context creation that does not need surface or service
into separate CreateOffscreenContext call.

Do not create GLSurfaceStubs on client side, and pass in NULL window
so the context creates GLSurfaceStubs on service side.

Clean up share context code since compositor does not need an offscreen
context anymore.

BUG=370566

Review URL: https://codereview.chromium.org/271763002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@269618 0039d316-1c4b-4281-b951-d872f2087c98
parent 188d11b3
...@@ -32,23 +32,25 @@ blink::WebGraphicsContext3D::Attributes GetDefaultAttribs() { ...@@ -32,23 +32,25 @@ blink::WebGraphicsContext3D::Attributes GetDefaultAttribs() {
using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl; using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl;
scoped_ptr<gpu::GLInProcessContext> CreateContextWithAttributes( scoped_ptr<gpu::GLInProcessContext> CreateOffscreenContext(
scoped_refptr<gfx::GLSurface> surface,
scoped_refptr<gpu::InProcessCommandBuffer::Service> service,
gpu::GLInProcessContext* share_context,
const blink::WebGraphicsContext3D::Attributes& attributes) { const blink::WebGraphicsContext3D::Attributes& attributes) {
const gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; const gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu;
if (!surface)
surface = gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size(1, 1));
gpu::GLInProcessContextAttribs in_process_attribs; gpu::GLInProcessContextAttribs in_process_attribs;
WebGraphicsContext3DInProcessCommandBufferImpl::ConvertAttributes( WebGraphicsContext3DInProcessCommandBufferImpl::ConvertAttributes(
attributes, &in_process_attribs); attributes, &in_process_attribs);
in_process_attribs.lose_context_when_out_of_memory = 1; in_process_attribs.lose_context_when_out_of_memory = 1;
scoped_ptr<gpu::GLInProcessContext> context( scoped_ptr<gpu::GLInProcessContext> context(
gpu::GLInProcessContext::CreateWithSurface( gpu::GLInProcessContext::Create(NULL /* service */,
surface, service, share_context, in_process_attribs, gpu_preference)); 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(); return context.Pass();
} }
...@@ -56,8 +58,31 @@ scoped_ptr<gpu::GLInProcessContext> CreateContext( ...@@ -56,8 +58,31 @@ scoped_ptr<gpu::GLInProcessContext> CreateContext(
scoped_refptr<gfx::GLSurface> surface, scoped_refptr<gfx::GLSurface> surface,
scoped_refptr<gpu::InProcessCommandBuffer::Service> service, scoped_refptr<gpu::InProcessCommandBuffer::Service> service,
gpu::GLInProcessContext* share_context) { gpu::GLInProcessContext* share_context) {
return CreateContextWithAttributes( const gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu;
surface, service, share_context, GetDefaultAttribs()); 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( scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> WrapContext(
...@@ -107,8 +132,7 @@ class VideoContextProvider ...@@ -107,8 +132,7 @@ class VideoContextProvider
using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl; using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl;
SynchronousCompositorFactoryImpl::SynchronousCompositorFactoryImpl() SynchronousCompositorFactoryImpl::SynchronousCompositorFactoryImpl()
: wrapped_gl_context_for_compositor_thread_(NULL), : num_hardware_compositors_(0) {
num_hardware_compositors_(0) {
SynchronousCompositorFactory::SetInstance(this); SynchronousCompositorFactory::SetInstance(this);
} }
...@@ -137,7 +161,7 @@ scoped_refptr<ContextProviderWebContext> SynchronousCompositorFactoryImpl:: ...@@ -137,7 +161,7 @@ scoped_refptr<ContextProviderWebContext> SynchronousCompositorFactoryImpl::
if ((!offscreen_context_for_main_thread_.get() || if ((!offscreen_context_for_main_thread_.get() ||
offscreen_context_for_main_thread_->DestroyedOnMainThread())) { offscreen_context_for_main_thread_->DestroyedOnMainThread())) {
scoped_ptr<gpu::GLInProcessContext> context = scoped_ptr<gpu::GLInProcessContext> context =
CreateContext(NULL, NULL, NULL); CreateOffscreenContext(GetDefaultAttribs());
offscreen_context_for_main_thread_ = offscreen_context_for_main_thread_ =
webkit::gpu::ContextProviderInProcess::Create( webkit::gpu::ContextProviderInProcess::Create(
WrapContext(context.Pass()), WrapContext(context.Pass()),
...@@ -152,42 +176,16 @@ scoped_refptr<ContextProviderWebContext> SynchronousCompositorFactoryImpl:: ...@@ -152,42 +176,16 @@ scoped_refptr<ContextProviderWebContext> SynchronousCompositorFactoryImpl::
return offscreen_context_for_main_thread_; 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:: scoped_refptr<cc::ContextProvider> SynchronousCompositorFactoryImpl::
CreateOnscreenContextProviderForCompositorThread( CreateOnscreenContextProviderForCompositorThread(
scoped_refptr<gfx::GLSurface> surface) { scoped_refptr<gfx::GLSurface> surface) {
DCHECK(surface); DCHECK(surface);
DCHECK(service_); DCHECK(service_);
DCHECK(wrapped_gl_context_for_compositor_thread_);
if (!share_context_.get())
share_context_ = CreateContext(NULL, service_, NULL);
return webkit::gpu::ContextProviderInProcess::Create( return webkit::gpu::ContextProviderInProcess::Create(
WrapContext(CreateContext( WrapContext(CreateContext(surface, service_, share_context_.get())),
surface, service_, wrapped_gl_context_for_compositor_thread_)),
"Compositor-Onscreen"); "Compositor-Onscreen");
} }
...@@ -205,8 +203,7 @@ SynchronousCompositorFactoryImpl::CreateStreamTextureFactory(int view_id) { ...@@ -205,8 +203,7 @@ SynchronousCompositorFactoryImpl::CreateStreamTextureFactory(int view_id) {
blink::WebGraphicsContext3D* blink::WebGraphicsContext3D*
SynchronousCompositorFactoryImpl::CreateOffscreenGraphicsContext3D( SynchronousCompositorFactoryImpl::CreateOffscreenGraphicsContext3D(
const blink::WebGraphicsContext3D::Attributes& attributes) { const blink::WebGraphicsContext3D::Attributes& attributes) {
return WrapContext(CreateContextWithAttributes(NULL, NULL, NULL, attributes)) return WrapContext(CreateOffscreenContext(attributes)).release();
.release();
} }
void SynchronousCompositorFactoryImpl::CompositorInitializedHardwareDraw() { void SynchronousCompositorFactoryImpl::CompositorInitializedHardwareDraw() {
...@@ -235,12 +232,10 @@ SynchronousCompositorFactoryImpl::TryCreateStreamTextureFactory() { ...@@ -235,12 +232,10 @@ SynchronousCompositorFactoryImpl::TryCreateStreamTextureFactory() {
// will fail creation when all compositors release hardware draw. // will fail creation when all compositors release hardware draw.
if (CanCreateMainThreadContext() && !video_context_provider_) { if (CanCreateMainThreadContext() && !video_context_provider_) {
DCHECK(service_); DCHECK(service_);
DCHECK(wrapped_gl_context_for_compositor_thread_); DCHECK(share_context_.get());
video_context_provider_ = new VideoContextProvider( video_context_provider_ = new VideoContextProvider(
CreateContext(new gfx::GLSurfaceStub, CreateContext(NULL, service_, share_context_.get()));
service_,
wrapped_gl_context_for_compositor_thread_));
} }
return video_context_provider_; return video_context_provider_;
} }
......
...@@ -46,11 +46,6 @@ class SynchronousCompositorFactoryImpl : public SynchronousCompositorFactory { ...@@ -46,11 +46,6 @@ class SynchronousCompositorFactoryImpl : public SynchronousCompositorFactory {
virtual blink::WebGraphicsContext3D* CreateOffscreenGraphicsContext3D( virtual blink::WebGraphicsContext3D* CreateOffscreenGraphicsContext3D(
const blink::WebGraphicsContext3D::Attributes& attributes) OVERRIDE; const blink::WebGraphicsContext3D::Attributes& attributes) OVERRIDE;
// 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>
GetOffscreenContextProviderForCompositorThread();
SynchronousInputEventFilter* synchronous_input_event_filter() { SynchronousInputEventFilter* synchronous_input_event_filter() {
return &synchronous_input_event_filter_; return &synchronous_input_event_filter_;
...@@ -74,12 +69,9 @@ class SynchronousCompositorFactoryImpl : public SynchronousCompositorFactory { ...@@ -74,12 +69,9 @@ class SynchronousCompositorFactoryImpl : public SynchronousCompositorFactory {
scoped_refptr<webkit::gpu::ContextProviderWebContext> scoped_refptr<webkit::gpu::ContextProviderWebContext>
offscreen_context_for_main_thread_; offscreen_context_for_main_thread_;
// This is a pointer to the context owned by
// |offscreen_context_for_main_thread_|.
gpu::GLInProcessContext* wrapped_gl_context_for_compositor_thread_;
scoped_refptr<cc::ContextProvider> offscreen_context_for_compositor_thread_;
scoped_refptr<gpu::InProcessCommandBuffer::Service> service_; scoped_refptr<gpu::InProcessCommandBuffer::Service> service_;
scoped_ptr<gpu::GLInProcessContext> share_context_;
scoped_refptr<StreamTextureFactorySynchronousImpl::ContextProvider> scoped_refptr<StreamTextureFactorySynchronousImpl::ContextProvider>
video_context_provider_; video_context_provider_;
......
...@@ -93,12 +93,8 @@ bool SynchronousCompositorImpl::InitializeHwDraw( ...@@ -93,12 +93,8 @@ bool SynchronousCompositorImpl::InitializeHwDraw(
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
DCHECK(output_surface_); DCHECK(output_surface_);
// Create contexts in this order so that the share group gets passed
// along correctly.
scoped_refptr<cc::ContextProvider> offscreen_context =
g_factory.Get().GetOffscreenContextProviderForCompositorThread();
scoped_refptr<cc::ContextProvider> onscreen_context = scoped_refptr<cc::ContextProvider> onscreen_context =
g_factory.Get().CreateOnscreenContextProviderForCompositorThread(surface); g_factory.Get().CreateOnscreenContextProviderForCompositorThread(surface);
bool success = output_surface_->InitializeHwDraw(onscreen_context); bool success = output_surface_->InitializeHwDraw(onscreen_context);
......
...@@ -337,25 +337,33 @@ GLInProcessContext* GLInProcessContext::CreateContext( ...@@ -337,25 +337,33 @@ GLInProcessContext* GLInProcessContext::CreateContext(
return context.release(); return context.release();
} }
// static GLInProcessContext* GLInProcessContext::Create(
GLInProcessContext* GLInProcessContext::CreateWithSurface(
scoped_refptr<gfx::GLSurface> surface,
scoped_refptr<gpu::InProcessCommandBuffer::Service> service, scoped_refptr<gpu::InProcessCommandBuffer::Service> service,
scoped_refptr<gfx::GLSurface> surface,
bool is_offscreen,
gfx::AcceleratedWidget window,
const gfx::Size& size,
GLInProcessContext* share_context, GLInProcessContext* share_context,
bool use_global_share_group,
const GLInProcessContextAttribs& attribs, const GLInProcessContextAttribs& attribs,
gfx::GpuPreference gpu_preference) { gfx::GpuPreference gpu_preference) {
scoped_ptr<GLInProcessContextImpl> context( DCHECK(!use_global_share_group || !share_context);
new GLInProcessContextImpl()); if (surface.get()) {
if (!context->Initialize( DCHECK_EQ(surface->IsOffscreen(), is_offscreen);
surface, DCHECK(surface->GetSize() == size);
surface->IsOffscreen(), DCHECK_EQ(gfx::kNullAcceleratedWidget, window);
false, }
share_context,
gfx::kNullAcceleratedWidget, scoped_ptr<GLInProcessContextImpl> context(new GLInProcessContextImpl());
surface->GetSize(), if (!context->Initialize(surface,
attribs, is_offscreen,
gpu_preference, use_global_share_group,
service)) share_context,
gfx::kNullAcceleratedWidget,
size,
attribs,
gpu_preference,
service))
return NULL; return NULL;
return context.release(); return context.release();
......
...@@ -52,6 +52,7 @@ class GL_IN_PROCESS_CONTEXT_EXPORT GLInProcessContext { ...@@ -52,6 +52,7 @@ class GL_IN_PROCESS_CONTEXT_EXPORT GLInProcessContext {
// Create a GLInProcessContext, if |is_offscreen| is true, renders to an // Create a GLInProcessContext, if |is_offscreen| is true, renders to an
// offscreen context. |attrib_list| must be NULL or a NONE-terminated list // offscreen context. |attrib_list| must be NULL or a NONE-terminated list
// of attribute/value pairs. // of attribute/value pairs.
// TODO(boliu): Fix all callsites to use Create and remove this.
static GLInProcessContext* CreateContext( static GLInProcessContext* CreateContext(
bool is_offscreen, bool is_offscreen,
gfx::AcceleratedWidget window, gfx::AcceleratedWidget window,
...@@ -60,14 +61,21 @@ class GL_IN_PROCESS_CONTEXT_EXPORT GLInProcessContext { ...@@ -60,14 +61,21 @@ class GL_IN_PROCESS_CONTEXT_EXPORT GLInProcessContext {
const GLInProcessContextAttribs& attribs, const GLInProcessContextAttribs& attribs,
gfx::GpuPreference gpu_preference); gfx::GpuPreference gpu_preference);
// Create context with the provided GLSurface. All other arguments match // If |surface| is not NULL, then it must match |is_offscreen| and |size|,
// CreateContext factory above. Can only be called if the command buffer // |window| must be gfx::kNullAcceleratedWidget, and the command buffer
// service runs on the same thread as this client because GLSurface is not // service must run on the same thread as this client because GLSurface is
// thread safe. // not thread safe. If |surface| is NULL, then the other parameters are used
static GLInProcessContext* CreateWithSurface( // to correctly create a surface.
scoped_refptr<gfx::GLSurface> surface, // Only one of |share_context| and |use_global_share_group| can be used at
// the same time.
static GLInProcessContext* Create(
scoped_refptr<gpu::InProcessCommandBuffer::Service> service, scoped_refptr<gpu::InProcessCommandBuffer::Service> service,
scoped_refptr<gfx::GLSurface> surface,
bool is_offscreen,
gfx::AcceleratedWidget window,
const gfx::Size& size,
GLInProcessContext* share_context, GLInProcessContext* share_context,
bool use_global_share_group,
const GLInProcessContextAttribs& attribs, const GLInProcessContextAttribs& attribs,
gfx::GpuPreference gpu_preference); gfx::GpuPreference gpu_preference);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment