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 908a091d18e89de81e1b8a401534e2590c7b65f1..a9d4b43cc157dde386e27fc11f7df1fafb86e2cb 100644 |
--- a/content/browser/renderer_host/image_transport_factory.cc |
+++ b/content/browser/renderer_host/image_transport_factory.cc |
@@ -36,6 +36,7 @@ |
#include "ui/compositor/test_web_graphics_context_3d.h" |
#include "ui/gfx/native_widget_types.h" |
#include "ui/gfx/size.h" |
+#include "webkit/gpu/grcontext_for_webgraphicscontext3d.h" |
#if defined(OS_WIN) |
#include "ui/surface/accelerated_surface_win.h" |
@@ -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) OVERRIDE { |
- 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) OVERRIDE { |
@@ -483,12 +487,12 @@ class GpuProcessTransportFactory |
observer_list_.RemoveObserver(observer); |
} |
- // WebGraphicsContextLostCallback implementation, called for the shared |
- // context. |
+ // WebGraphicsContextLostCallback implementation, called for the main thread |
+ // shared context. |
virtual void onContextLost() { |
MessageLoop::current()->PostTask( |
FROM_HERE, |
- base::Bind(&GpuProcessTransportFactory::OnLostSharedContext, |
+ base::Bind(&GpuProcessTransportFactory::OnLostMainThreadSharedContext, |
callback_factory_.GetWeakPtr())); |
} |
@@ -561,29 +565,105 @@ 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(); |
+ |
+ // This context is for another thread. Do not MakeCurrent on this thread, |
+ // and any callbacks will not be run on this thread. |
+ shared_context_compositor_thread_.reset(CreateOffscreenContext()); |
+ return shared_context_compositor_thread_.get(); |
+ } |
+ |
+ class MemoryCallbackProxy : |
+ public WebKit::WebGraphicsContext3D:: |
+ WebGraphicsMemoryAllocationChangedCallbackCHROMIUM { |
+ public: |
+ MemoryCallbackProxy( |
+ WebKit::WebGraphicsContext3D* context3d, |
+ webkit::gpu::GrContextForWebGraphicsContext3D* gr_context) |
+ : context3d_(context3d), |
+ gr_context_(gr_context) { |
+ context3d_->setMemoryAllocationChangedCallbackCHROMIUM(this); |
+ } |
+ virtual ~MemoryCallbackProxy() { |
+ context3d_->setMemoryAllocationChangedCallbackCHROMIUM(NULL); |
+ } |
+ |
+ private: |
+ // WebGraphicsMemoryAllocationChangedCallbackCHROMIUM implementation. |
+ virtual void onMemoryAllocationChanged( |
+ WebKit::WebGraphicsMemoryAllocation allocation) { |
+ gr_context_->SetMemoryLimit(!!allocation.gpuResourceSizeInBytes); |
+ } |
+ |
+ WebKit::WebGraphicsContext3D* context3d_; |
+ webkit::gpu::GrContextForWebGraphicsContext3D* gr_context_; |
+ }; |
+ |
+ virtual GrContext* OffscreenGrContextForMainThread() OVERRIDE { |
+ if (!grcontext_main_thread_ && shared_context_main_thread_) { |
+ grcontext_main_thread_.reset( |
+ new webkit::gpu::GrContextForWebGraphicsContext3D( |
+ shared_context_main_thread_.get())); |
+ memory_callback_proxy_main_thread_.reset(new MemoryCallbackProxy( |
+ shared_context_main_thread_.get(), grcontext_main_thread_.get())); |
+ } |
+ return grcontext_main_thread_->gr_context(); |
+ } |
+ |
+ virtual GrContext* OffscreenGrContextForCompositorThread() |
+ OVERRIDE { |
+ if (!grcontext_compositor_thread_ && shared_context_compositor_thread_) { |
+ grcontext_compositor_thread_.reset( |
+ new webkit::gpu::GrContextForWebGraphicsContext3D( |
+ shared_context_compositor_thread_.get())); |
+ memory_callback_proxy_compositor_thread_.reset(new MemoryCallbackProxy( |
piman
2013/02/13 19:13:31
So, this is called on the main thread, but the Mem
|
+ shared_context_compositor_thread_.get(), |
+ grcontext_compositor_thread_.get())); |
+ } |
+ return grcontext_compositor_thread_->gr_context(); |
+ } |
+ |
+ virtual void DestroyOffscreenContext3dForCompositorThread() OVERRIDE { |
+ memory_callback_proxy_compositor_thread_.reset(); |
+ grcontext_compositor_thread_.reset(); |
+ shared_context_compositor_thread_.reset(); |
+ } |
+ |
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 OnLostMainThreadSharedContext() { |
+ memory_callback_proxy_main_thread_.reset(); |
+ grcontext_main_thread_.reset(); |
+ |
// 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<GLHelper> old_helper(gl_helper_.release()); |
FOR_EACH_OBSERVER(ImageTransportFactoryObserver, |
@@ -593,7 +673,15 @@ 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_; |
+ scoped_ptr<webkit::gpu::GrContextForWebGraphicsContext3D> |
+ grcontext_main_thread_; |
+ scoped_ptr<webkit::gpu::GrContextForWebGraphicsContext3D> |
+ grcontext_compositor_thread_; |
+ scoped_ptr<MemoryCallbackProxy> memory_callback_proxy_main_thread_; |
+ scoped_ptr<MemoryCallbackProxy> memory_callback_proxy_compositor_thread_; |
scoped_ptr<GLHelper> gl_helper_; |
ObserverList<ImageTransportFactoryObserver> observer_list_; |
base::WeakPtrFactory<GpuProcessTransportFactory> callback_factory_; |