Index: webkit/compositor_bindings/web_layer_tree_view_impl.cc |
diff --git a/webkit/compositor_bindings/web_layer_tree_view_impl.cc b/webkit/compositor_bindings/web_layer_tree_view_impl.cc |
index dba117c88ac00bc2e40cca90f63d154ffc1856a6..848254958d2d3f279ef211750d8ff6fc4b7b7d21 100644 |
--- a/webkit/compositor_bindings/web_layer_tree_view_impl.cc |
+++ b/webkit/compositor_bindings/web_layer_tree_view_impl.cc |
@@ -6,6 +6,8 @@ |
#include "base/command_line.h" |
#include "base/string_number_conversions.h" |
+#include "base/synchronization/lock.h" |
+#include "cc/context_provider.h" |
#include "cc/input_handler.h" |
#include "cc/layer.h" |
#include "cc/layer_tree_host.h" |
@@ -16,6 +18,7 @@ |
#include "third_party/WebKit/Source/Platform/chromium/public/WebLayerTreeViewClient.h" |
#include "third_party/WebKit/Source/Platform/chromium/public/WebLayerTreeView.h" |
#include "third_party/WebKit/Source/Platform/chromium/public/WebRenderingStats.h" |
+#include "third_party/WebKit/Source/Platform/chromium/public/WebSharedGraphicsContext3D.h" |
#include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" |
#include "web_layer_impl.h" |
#include "web_to_ccinput_handler_adapter.h" |
@@ -283,4 +286,74 @@ void WebLayerTreeViewImpl::scheduleComposite() |
m_client->scheduleComposite(); |
} |
+class WebLayerTreeViewImpl::MainThreadContextProvider : public cc::ContextProvider { |
+ public: |
+ virtual bool InitializeOnMainThread() OVERRIDE { return true; } |
+ virtual bool BindToCurrentThread() OVERRIDE { return true; } |
+ |
+ virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE { |
+ return WebSharedGraphicsContext3D::mainThreadContext(); |
+ } |
+ virtual class GrContext* GrContext() OVERRIDE { |
+ return WebSharedGraphicsContext3D::mainThreadGrContext(); |
+ } |
+ |
+ virtual void VerifyContexts() OVERRIDE {} |
+ |
+ protected: |
+ virtual ~MainThreadContextProvider() {} |
+}; |
+ |
+scoped_refptr<cc::ContextProvider> WebLayerTreeViewImpl::OffscreenContextProviderForMainThread() { |
+ if (!m_contextsMainThread) |
+ m_contextsMainThread = new MainThreadContextProvider; |
+ return m_contextsMainThread; |
+} |
+ |
+class WebLayerTreeViewImpl::CompositorThreadContextProvider |
+ : public cc::ContextProvider { |
+ public: |
+ CompositorThreadContextProvider() : destroyed_(false) {} |
+ |
+ virtual bool InitializeOnMainThread() OVERRIDE { |
+ return WebSharedGraphicsContext3D::createCompositorThreadContext(); |
+ } |
+ virtual bool BindToCurrentThread() OVERRIDE { |
+ return Context3d()->makeContextCurrent(); |
+ } |
+ |
+ virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE { |
+ return WebSharedGraphicsContext3D::compositorThreadContext(); |
+ } |
+ virtual class GrContext* GrContext() OVERRIDE { |
+ return WebSharedGraphicsContext3D::compositorThreadGrContext(); |
+ } |
+ |
+ virtual void VerifyContexts() OVERRIDE { |
+ if (Context3d() && !Context3d()->isContextLost()) |
+ return; |
+ base::AutoLock lock(destroyed_lock_); |
+ destroyed_ = true; |
+ } |
+ bool DestroyedOnMainThread() { |
+ base::AutoLock lock(destroyed_lock_); |
+ return destroyed_; |
+ } |
+ |
+ protected: |
+ virtual ~CompositorThreadContextProvider() {} |
+ |
+ private: |
+ base::Lock destroyed_lock_; |
+ bool destroyed_; |
+}; |
+ |
+scoped_refptr<cc::ContextProvider> WebLayerTreeViewImpl::OffscreenContextProviderForCompositorThread() { |
+ if (!m_contextsCompositorThread || |
+ m_contextsCompositorThread->DestroyedOnMainThread()) { |
+ m_contextsCompositorThread = new CompositorThreadContextProvider; |
+ } |
+ return m_contextsCompositorThread; |
+} |
+ |
} // namespace WebKit |