Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(808)

Unified Diff: content/browser/renderer_host/image_transport_factory.cc

Issue 12212007: cc: Route offscreen context creation for compositor to the browser. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Put OffscreenContext class in content/common/gpu/client for renderer Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..1d12b6d6642fbed10aba35f84b7edc8e80c4f098 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"
@@ -31,6 +32,8 @@
#include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3D.h"
#include "third_party/khronos/GLES2/gl2.h"
#include "third_party/khronos/GLES2/gl2ext.h"
+#include "third_party/skia/include/gpu/GrContext.h"
+#include "third_party/skia/include/gpu/gl/GrGLInterface.h"
#include "ui/compositor/compositor.h"
#include "ui/compositor/compositor_setup.h"
#include "ui/compositor/test_web_graphics_context_3d.h"
@@ -224,11 +227,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 +372,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 +406,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 +444,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 +459,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 +472,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 +513,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 +561,6 @@ class GpuProcessTransportFactory
PerCompositorData* CreatePerCompositorData(ui::Compositor* compositor) {
DCHECK(!per_compositor_data_[compositor]);
- CreateSharedContextLazy();
-
gfx::AcceleratedWidget widget = compositor->widget();
GpuSurfaceTracker* tracker = GpuSurfaceTracker::Get();
@@ -560,39 +605,17 @@ 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());
+ observer_list_,
+ OnLostResources());
}
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 +624,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.
}

Powered by Google App Engine
This is Rietveld 408576698