Commit 7cc1237a authored by danakj@chromium.org's avatar danakj@chromium.org

Leak contexts that are owned by another thread.

This avoids destroying contexts on the main thread that are bound to
the compositor thread as this causes DCHECKs to fire and is a bad thing.

The renderer already does this, as it has been threaded much longer on
more platforms so we noticed it. Recently noticed this in browser tests
in the UI compositor too.

This also updates the Mojo DemoContextFactory to match the behaviour of
GpuProcessTransportFactory wrt the offscreen compositor context creation
and destruction.

R=jamesr, piman
BUG=344016

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@252124 0039d316-1c4b-4281-b951-d872f2087c98
parent f360d8b7
......@@ -139,7 +139,7 @@ class ImageTransportClientTexture : public OwnedTexture {
};
GpuProcessTransportFactory::GpuProcessTransportFactory()
: callback_factory_(this) {
: callback_factory_(this), offscreen_content_bound_to_other_thread_(false) {
output_surface_proxy_ = new BrowserCompositorOutputSurfaceProxy(
&output_surface_map_);
}
......@@ -149,6 +149,13 @@ GpuProcessTransportFactory::~GpuProcessTransportFactory() {
// Make sure the lost context callback doesn't try to run during destruction.
callback_factory_.InvalidateWeakPtrs();
if (offscreen_compositor_contexts_.get() &&
offscreen_content_bound_to_other_thread_) {
// Leak shared contexts on other threads, as we can not get to the correct
// thread to destroy them.
offscreen_compositor_contexts_->set_leak_on_destroy();
}
}
scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
......@@ -362,6 +369,8 @@ GpuProcessTransportFactory::OffscreenCompositorContextProvider() {
offscreen_compositor_contexts_ = ContextProviderCommandBuffer::Create(
GpuProcessTransportFactory::CreateOffscreenCommandBufferContext(),
"Compositor-Offscreen");
offscreen_content_bound_to_other_thread_ =
ui::Compositor::WasInitializedWithThread();
return offscreen_compositor_contexts_;
}
......
......@@ -80,6 +80,7 @@ class GpuProcessTransportFactory
scoped_ptr<GLHelper> gl_helper_;
ObserverList<ImageTransportFactoryObserver> observer_list_;
base::WeakPtrFactory<GpuProcessTransportFactory> callback_factory_;
bool offscreen_content_bound_to_other_thread_;
// The contents of this map and its methods may only be used on the compositor
// thread.
......
......@@ -51,7 +51,11 @@ void DemoContextFactory::RemoveReflector(
scoped_refptr<cc::ContextProvider>
DemoContextFactory::OffscreenCompositorContextProvider() {
if (!offscreen_compositor_contexts_.get() ||
!offscreen_compositor_contexts_->DestroyedOnMainThread()) {
offscreen_compositor_contexts_->DestroyedOnMainThread()) {
// If the compositor was initialized with its own thread then we would need
// to leak the context provider when we shutdown to avoid destroying the
// contexts on the wrong thread.
DCHECK(!ui::Compositor::WasInitializedWithThread());
offscreen_compositor_contexts_ =
webkit::gpu::ContextProviderInProcess::CreateOffscreen();
}
......@@ -60,22 +64,14 @@ DemoContextFactory::OffscreenCompositorContextProvider() {
scoped_refptr<cc::ContextProvider>
DemoContextFactory::SharedMainThreadContextProvider() {
if (shared_main_thread_contexts_ &&
!shared_main_thread_contexts_->DestroyedOnMainThread())
return shared_main_thread_contexts_;
if (ui::Compositor::WasInitializedWithThread()) {
if (!shared_main_thread_contexts_ ||
shared_main_thread_contexts_->DestroyedOnMainThread()) {
shared_main_thread_contexts_ =
webkit::gpu::ContextProviderInProcess::CreateOffscreen();
} else {
shared_main_thread_contexts_ =
static_cast<webkit::gpu::ContextProviderInProcess*>(
OffscreenCompositorContextProvider().get());
if (shared_main_thread_contexts_ &&
!shared_main_thread_contexts_->BindToCurrentThread())
shared_main_thread_contexts_ = NULL;
}
if (shared_main_thread_contexts_ &&
!shared_main_thread_contexts_->BindToCurrentThread())
shared_main_thread_contexts_ = NULL;
return shared_main_thread_contexts_;
}
......
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