| 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..88bae2fe0ec76dc9e9ec481a8dc6f9eee50d47fc 100644
|
| --- a/content/browser/renderer_host/image_transport_factory.cc
|
| +++ b/content/browser/renderer_host/image_transport_factory.cc
|
| @@ -21,6 +21,7 @@
|
| #include "content/browser/gpu/gpu_surface_tracker.h"
|
| #include "content/common/gpu/client/gl_helper.h"
|
| #include "content/common/gpu/client/gpu_channel_host.h"
|
| +#include "content/common/gpu/client/offscreen_context_command_buffer.h"
|
| #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
|
| #include "content/common/gpu/gpu_messages.h"
|
| #include "content/common/gpu/gpu_process_launch_causes.h"
|
| @@ -224,11 +225,12 @@ class CompositorSwapClient
|
| // instead.
|
| // TODO(piman): Fix the underlying issues.
|
| MessageLoop::current()->PostTask(FROM_HERE,
|
| - base::Bind(&CompositorSwapClient::OnLostContext, this->AsWeakPtr()));
|
| + base::Bind(&CompositorSwapClient::OnLostSwapContext,
|
| + this->AsWeakPtr()));
|
| }
|
|
|
| private:
|
| - void OnLostContext();
|
| + void OnLostSwapContext();
|
| ui::Compositor* compositor_;
|
| GpuProcessTransportFactory* factory_;
|
|
|
| @@ -368,11 +370,13 @@ void BrowserCompositorOutputSurfaceProxy::OnUpdateVSyncParameters(
|
|
|
| class GpuProcessTransportFactory
|
| : public ui::ContextFactory,
|
| - public ImageTransportFactory,
|
| - public WebKit::WebGraphicsContext3D::WebGraphicsContextLostCallback {
|
| + public OffscreenContextCommandBufferClient,
|
| + public ImageTransportFactory {
|
| public:
|
| GpuProcessTransportFactory()
|
| - : ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)) {
|
| + : shared_context_main_thread_(this),
|
| + shared_context_compositor_thread_(this),
|
| + ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)) {
|
| output_surface_proxy_ = new BrowserCompositorOutputSurfaceProxy();
|
| }
|
|
|
| @@ -400,6 +404,24 @@ class GpuProcessTransportFactory
|
| output_surface_proxy_);
|
| }
|
|
|
| + virtual WebKit::WebGraphicsContext3D* OffscreenContextForMainThread()
|
| + OVERRIDE {
|
| + return shared_context_main_thread_.Context3d();
|
| + }
|
| +
|
| + virtual WebKit::WebGraphicsContext3D*
|
| + OffscreenContextForCompositorThread() OVERRIDE {
|
| + return shared_context_compositor_thread_.Context3d();
|
| + }
|
| +
|
| + virtual GrContext* OffscreenGrContextForMainThread() OVERRIDE {
|
| + return shared_context_main_thread_.GrContext();
|
| + }
|
| +
|
| + virtual GrContext* OffscreenGrContextForCompositorThread() OVERRIDE {
|
| + return shared_context_compositor_thread_.GrContext();
|
| + }
|
| +
|
| virtual void RemoveCompositor(ui::Compositor* compositor) OVERRIDE {
|
| PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor);
|
| if (it == per_compositor_data_.end())
|
| @@ -420,12 +442,12 @@ class GpuProcessTransportFactory
|
| }
|
|
|
| virtual gfx::GLSurfaceHandle CreateSharedSurfaceHandle() OVERRIDE {
|
| - 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_.Context3d()->GetGPUProcessID();
|
| + handle.parent_client_id =
|
| + shared_context_main_thread_.Context3d()->GetChannelID();
|
| return handle;
|
| }
|
|
|
| @@ -435,11 +457,12 @@ class GpuProcessTransportFactory
|
|
|
| virtual scoped_refptr<ui::Texture> CreateTransportClient(
|
| float device_scale_factor) {
|
| - if (!shared_context_.get())
|
| + if (!shared_context_main_thread_.Context3d())
|
| return NULL;
|
| scoped_refptr<ImageTransportClientTexture> image(
|
| - new ImageTransportClientTexture(shared_context_.get(),
|
| - device_scale_factor));
|
| + new ImageTransportClientTexture(
|
| + shared_context_main_thread_.Context3d(),
|
| + device_scale_factor));
|
| return image;
|
| }
|
|
|
| @@ -447,31 +470,37 @@ class GpuProcessTransportFactory
|
| const gfx::Size& size,
|
| float device_scale_factor,
|
| unsigned int texture_id) OVERRIDE {
|
| - if (!shared_context_.get())
|
| - return NULL;
|
| - scoped_refptr<OwnedTexture> image(
|
| - new OwnedTexture(shared_context_.get(), size, device_scale_factor,
|
| - texture_id));
|
| + if (!shared_context_main_thread_.Context3d())
|
| + return NULL;
|
| + scoped_refptr<OwnedTexture> image(new OwnedTexture(
|
| + shared_context_main_thread_.Context3d(),
|
| + size,
|
| + device_scale_factor,
|
| + texture_id));
|
| return image;
|
| }
|
|
|
| virtual GLHelper* GetGLHelper() {
|
| if (!gl_helper_.get()) {
|
| - CreateSharedContextLazy();
|
| - WebKit::WebGraphicsContext3D* context_for_thread =
|
| + WebGraphicsContext3DCommandBufferImpl* main_thread_context =
|
| + shared_context_main_thread_.Context3d();
|
| + if (!main_thread_context)
|
| + return NULL;
|
| + WebGraphicsContext3DCommandBufferImpl* helper_thread_context =
|
| CreateOffscreenContext();
|
| - if (!context_for_thread)
|
| + if (!helper_thread_context)
|
| return NULL;
|
| - gl_helper_.reset(new GLHelper(shared_context_.get(),
|
| - context_for_thread));
|
| + gl_helper_.reset(new GLHelper(main_thread_context,
|
| + helper_thread_context));
|
| }
|
| return gl_helper_.get();
|
| }
|
|
|
| virtual uint32 InsertSyncPoint() OVERRIDE {
|
| - if (!shared_context_.get())
|
| + if (!shared_context_main_thread_.Context3d())
|
| return 0;
|
| - return shared_context_->insertSyncPoint();
|
| + return shared_context_main_thread_.Context3d()->
|
| + insertSyncPoint();
|
| }
|
|
|
| virtual void AddObserver(ImageTransportFactoryObserver* observer) {
|
| @@ -482,16 +511,32 @@ class GpuProcessTransportFactory
|
| observer_list_.RemoveObserver(observer);
|
| }
|
|
|
| - // WebGraphicsContextLostCallback implementation, called for the shared
|
| - // context.
|
| - virtual void onContextLost() {
|
| - MessageLoop::current()->PostTask(
|
| - FROM_HERE,
|
| - base::Bind(&GpuProcessTransportFactory::OnLostSharedContext,
|
| - callback_factory_.GetWeakPtr()));
|
| + // OffscreenContextCommandBufferClient implementation.
|
| + virtual void DidCreateContext(
|
| + OffscreenContextCommandBuffer* offscreen_context,
|
| + bool success) OVERRIDE {
|
| + if (success)
|
| + return;
|
| + if (offscreen_context == &shared_context_main_thread_) {
|
| + // 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 main thread context.";
|
| + }
|
| + }
|
| +
|
| + // OffscreenContextCommandBufferClient implementation.
|
| + virtual void DidLoseContext(OffscreenContextCommandBuffer* offscreen_context)
|
| + OVERRIDE {
|
| + if (offscreen_context == &shared_context_main_thread_) {
|
| + MessageLoop::current()->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(&GpuProcessTransportFactory::OnLostMainThreadSharedContext,
|
| + callback_factory_.GetWeakPtr(),
|
| + base::Unretained(offscreen_context)));
|
| + }
|
| }
|
|
|
| - void OnLostContext(ui::Compositor* compositor) {
|
| + void OnLostSwapContext(ui::Compositor* compositor) {
|
| LOG(ERROR) << "Lost UI compositor context.";
|
| PerCompositorData* data = per_compositor_data_[compositor];
|
| DCHECK(data);
|
| @@ -514,8 +559,6 @@ class GpuProcessTransportFactory
|
| PerCompositorData* CreatePerCompositorData(ui::Compositor* compositor) {
|
| DCHECK(!per_compositor_data_[compositor]);
|
|
|
| - CreateSharedContextLazy();
|
| -
|
| gfx::AcceleratedWidget widget = compositor->widget();
|
| GpuSurfaceTracker* tracker = GpuSurfaceTracker::Get();
|
|
|
| @@ -560,31 +603,8 @@ class GpuProcessTransportFactory
|
| return context.release();
|
| }
|
|
|
| - void CreateSharedContextLazy() {
|
| - if (shared_context_.get())
|
| - return;
|
| -
|
| - shared_context_.reset(CreateOffscreenContext());
|
| - if (!shared_context_.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 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);
|
| - }
|
| -
|
| - void OnLostSharedContext() {
|
| - // 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<GLHelper> old_helper(gl_helper_.release());
|
| -
|
| + void OnLostMainThreadSharedContext(
|
| + OffscreenContextCommandBuffer* offscreen_contxt) {
|
| FOR_EACH_OBSERVER(ImageTransportFactoryObserver,
|
| observer_list_,
|
| OnLostResources());
|
| @@ -592,7 +612,8 @@ class GpuProcessTransportFactory
|
|
|
| typedef std::map<ui::Compositor*, PerCompositorData*> PerCompositorDataMap;
|
| PerCompositorDataMap per_compositor_data_;
|
| - scoped_ptr<WebGraphicsContext3DCommandBufferImpl> shared_context_;
|
| + OffscreenContextCommandBuffer shared_context_main_thread_;
|
| + OffscreenContextCommandBuffer shared_context_compositor_thread_;
|
| scoped_ptr<GLHelper> gl_helper_;
|
| ObserverList<ImageTransportFactoryObserver> observer_list_;
|
| base::WeakPtrFactory<GpuProcessTransportFactory> callback_factory_;
|
| @@ -601,8 +622,8 @@ class GpuProcessTransportFactory
|
| DISALLOW_COPY_AND_ASSIGN(GpuProcessTransportFactory);
|
| };
|
|
|
| -void CompositorSwapClient::OnLostContext() {
|
| - factory_->OnLostContext(compositor_);
|
| +void CompositorSwapClient::OnLostSwapContext() {
|
| + factory_->OnLostSwapContext(compositor_);
|
| // Note: previous line destroyed this. Don't access members from now on.
|
| }
|
|
|
|
|