Index: content/browser/renderer_host/image_transport_factory.cc |
diff --git a/content/browser/renderer_host/image_transport_factory.cc b/content/browser/renderer_host/image_transport_factory.cc |
index ba45309f8d990cfe0539c320d0291f8b06491df1..2db28ba792cd0fb94e68e314b3909bcad1f72136 100644 |
--- a/content/browser/renderer_host/image_transport_factory.cc |
+++ b/content/browser/renderer_host/image_transport_factory.cc |
@@ -372,7 +372,8 @@ class GpuProcessTransportFactory |
public WebKit::WebGraphicsContext3D::WebGraphicsContextLostCallback { |
public: |
GpuProcessTransportFactory() |
- : ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)) { |
+ : lost_context_callbacks_(0), |
+ ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)) { |
output_surface_proxy_ = new BrowserCompositorOutputSurfaceProxy(); |
} |
@@ -423,8 +424,9 @@ class GpuProcessTransportFactory |
CreateSharedContextLazy(); |
gfx::GLSurfaceHandle handle = gfx::GLSurfaceHandle( |
gfx::kNullPluginWindow, true); |
- handle.parent_gpu_process_id = shared_context_->GetGPUProcessID(); |
- handle.parent_client_id = shared_context_->GetChannelID(); |
+ handle.parent_gpu_process_id = |
+ shared_context_main_thread_->GetGPUProcessID(); |
+ handle.parent_client_id = shared_context_main_thread_->GetChannelID(); |
return handle; |
} |
@@ -435,10 +437,10 @@ class GpuProcessTransportFactory |
virtual scoped_refptr<ui::Texture> CreateTransportClient( |
float device_scale_factor) { |
- if (!shared_context_.get()) |
+ if (!shared_context_main_thread_.get()) |
return NULL; |
scoped_refptr<ImageTransportClientTexture> image( |
- new ImageTransportClientTexture(shared_context_.get(), |
+ new ImageTransportClientTexture(shared_context_main_thread_.get(), |
device_scale_factor)); |
return image; |
} |
@@ -447,11 +449,13 @@ class GpuProcessTransportFactory |
const gfx::Size& size, |
float device_scale_factor, |
unsigned int texture_id) OVERRIDE { |
- if (!shared_context_.get()) |
+ if (!shared_context_main_thread_.get()) |
return NULL; |
- scoped_refptr<OwnedTexture> image( |
- new OwnedTexture(shared_context_.get(), size, device_scale_factor, |
- texture_id)); |
+ scoped_refptr<OwnedTexture> image(new OwnedTexture( |
+ shared_context_main_thread_.get(), |
+ size, |
+ device_scale_factor, |
+ texture_id)); |
return image; |
} |
@@ -462,16 +466,16 @@ class GpuProcessTransportFactory |
CreateOffscreenContext(); |
if (!context_for_thread) |
return NULL; |
- gl_helper_.reset(new GLHelper(shared_context_.get(), |
+ gl_helper_.reset(new GLHelper(shared_context_main_thread_.get(), |
context_for_thread)); |
} |
return gl_helper_.get(); |
} |
virtual uint32 InsertSyncPoint() OVERRIDE { |
- if (!shared_context_.get()) |
+ if (!shared_context_main_thread_.get()) |
return 0; |
- return shared_context_->insertSyncPoint(); |
+ return shared_context_main_thread_->insertSyncPoint(); |
} |
virtual void AddObserver(ImageTransportFactoryObserver* observer) { |
@@ -485,9 +489,17 @@ class GpuProcessTransportFactory |
// WebGraphicsContextLostCallback implementation, called for the shared |
// context. |
virtual void onContextLost() { |
+ // Wait until we get the callback for each of our shared contexts. |
+ ++lost_context_callbacks_; |
+ int expected_callbacks = (shared_context_main_thread_ ? 1 : 0) + |
+ (shared_context_compositor_thread_ ? 1 : 0); |
+ DCHECK(expected_callbacks); |
+ if (lost_context_callbacks_ < expected_callbacks) |
+ return; |
+ |
MessageLoop::current()->PostTask( |
FROM_HERE, |
- base::Bind(&GpuProcessTransportFactory::OnLostSharedContext, |
+ base::Bind(&GpuProcessTransportFactory::OnLostSharedContexts, |
callback_factory_.GetWeakPtr())); |
} |
@@ -560,31 +572,57 @@ class GpuProcessTransportFactory |
return context.release(); |
} |
+ virtual WebKit::WebGraphicsContext3D* OffscreenContextForMainThread() |
+ OVERRIDE { |
+ CreateSharedContextLazy(); |
+ return shared_context_main_thread_.get(); |
+ } |
+ |
+ virtual WebKit::WebGraphicsContext3D* OffscreenContextForCompositorThread() |
+ OVERRIDE { |
+ if (shared_context_compositor_thread_) |
+ return shared_context_compositor_thread_.get(); |
+ |
+ shared_context_compositor_thread_.reset(CreateOffscreenContext()); |
+ if (!shared_context_compositor_thread_->makeContextCurrent()) |
+ shared_context_compositor_thread_.reset(); |
+ if (!shared_context_compositor_thread_) |
+ return NULL; |
+ |
+ shared_context_compositor_thread_->setContextLostCallback(this); |
+ return shared_context_compositor_thread_.get(); |
+ } |
+ |
void CreateSharedContextLazy() { |
- if (shared_context_.get()) |
+ if (shared_context_main_thread_.get()) |
return; |
- shared_context_.reset(CreateOffscreenContext()); |
- if (!shared_context_.get()) { |
+ shared_context_main_thread_.reset(CreateOffscreenContext()); |
+ if (!shared_context_main_thread_.get()) { |
// If we can't recreate contexts, we won't be able to show the UI. Better |
// crash at this point. |
LOG(FATAL) << "Failed to initialize UI shared context."; |
} |
- if (!shared_context_->makeContextCurrent()) { |
+ if (!shared_context_main_thread_->makeContextCurrent()) { |
// If we can't recreate contexts, we won't be able to show the UI. Better |
// crash at this point. |
LOG(FATAL) << "Failed to make UI shared context current."; |
} |
- shared_context_->setContextLostCallback(this); |
+ shared_context_main_thread_->setContextLostCallback(this); |
} |
- void OnLostSharedContext() { |
+ void OnLostSharedContexts() { |
// Keep old resources around while we call the observers, but ensure that |
// new resources are created if needed. |
- scoped_ptr<WebGraphicsContext3DCommandBufferImpl> old_shared_context( |
- shared_context_.release()); |
+ scoped_ptr<WebGraphicsContext3DCommandBufferImpl> |
+ old_shared_context_main_thread(shared_context_main_thread_.release()); |
+ scoped_ptr<WebGraphicsContext3DCommandBufferImpl> |
+ old_shared_context_compositor_thread( |
+ shared_context_compositor_thread_.release()); |
scoped_ptr<GLHelper> old_helper(gl_helper_.release()); |
+ lost_context_callbacks_ = 0; |
+ |
FOR_EACH_OBSERVER(ImageTransportFactoryObserver, |
observer_list_, |
OnLostResources()); |
@@ -592,7 +630,10 @@ class GpuProcessTransportFactory |
typedef std::map<ui::Compositor*, PerCompositorData*> PerCompositorDataMap; |
PerCompositorDataMap per_compositor_data_; |
- scoped_ptr<WebGraphicsContext3DCommandBufferImpl> shared_context_; |
+ scoped_ptr<WebGraphicsContext3DCommandBufferImpl> shared_context_main_thread_; |
+ scoped_ptr<WebGraphicsContext3DCommandBufferImpl> |
+ shared_context_compositor_thread_; |
+ int lost_context_callbacks_; |
scoped_ptr<GLHelper> gl_helper_; |
ObserverList<ImageTransportFactoryObserver> observer_list_; |
base::WeakPtrFactory<GpuProcessTransportFactory> callback_factory_; |