Index: ui/compositor/compositor.cc |
diff --git a/ui/compositor/compositor.cc b/ui/compositor/compositor.cc |
index 372a03910313456f9e57e6ca6348674909ddb4ee..b7625983f43d9780d090aa40e05eb8c2c5df3a16 100644 |
--- a/ui/compositor/compositor.cc |
+++ b/ui/compositor/compositor.cc |
@@ -24,10 +24,12 @@ |
#include "ui/compositor/dip_util.h" |
#include "ui/compositor/layer.h" |
#include "ui/compositor/test_web_graphics_context_3d.h" |
+#include "ui/gl/context_provider.h" |
#include "ui/gl/gl_context.h" |
#include "ui/gl/gl_implementation.h" |
#include "ui/gl/gl_surface.h" |
#include "ui/gl/gl_switches.h" |
+#include "webkit/gpu/grcontext_for_webgraphicscontext3d.h" |
#include "webkit/gpu/webgraphicscontext3d_in_process_impl.h" |
#if defined(OS_CHROMEOS) |
@@ -70,6 +72,22 @@ class PendingSwap { |
DISALLOW_COPY_AND_ASSIGN(PendingSwap); |
}; |
+class NullContextProvider : public ui::ContextProvider { |
+ public: |
+ virtual bool InitializeOnMainThread() OVERRIDE { return true; } |
+ virtual bool BindToCurrentThread() OVERRIDE { return false; } |
+ virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE { return NULL; } |
+ virtual class GrContext* GrContext() OVERRIDE { return NULL; } |
+ virtual void VerifyContexts() OVERRIDE {} |
+ protected: |
piman
2013/02/21 22:49:48
nit: blank line before 'protected:'
danakj
2013/02/22 01:56:31
Done.
|
+ virtual ~NullContextProvider() {} |
+}; |
+ |
+static scoped_refptr<NullContextProvider> |
piman
2013/02/21 22:49:48
You can't have non-POD as globals.
Use Singletons?
danakj
2013/02/22 01:56:31
Oh right, POD only.. I used a Singleton class that
|
+ g_test_offscreen_contexts_main_thread; |
+static scoped_refptr<NullContextProvider> |
+ g_test_offscreen_contexts_compositor_thread; |
+ |
} // namespace |
namespace ui { |
@@ -122,6 +140,67 @@ WebKit::WebGraphicsContext3D* DefaultContextFactory::CreateOffscreenContext() { |
return CreateContextCommon(NULL, true); |
} |
+class DefaultContextFactory::DefaultContextProvider |
+ : public ui::ContextProvider { |
+ public: |
+ DefaultContextProvider(ContextFactory* factory) |
+ : factory_(factory), |
+ destroyed_(false) {} |
+ |
+ virtual bool InitializeOnMainThread() OVERRIDE { |
+ context3d_.reset(factory_->CreateOffscreenContext()); |
+ return !!context3d_; |
+ } |
+ |
+ virtual bool BindToCurrentThread() { |
+ return context3d_->makeContextCurrent(); |
+ } |
+ |
+ virtual WebKit::WebGraphicsContext3D* Context3d() { return context3d_.get(); } |
+ |
+ virtual class GrContext* GrContext() { |
+ if (!gr_context_) { |
+ gr_context_.reset( |
+ new webkit::gpu::GrContextForWebGraphicsContext3D(context3d_.get())); |
+ } |
+ return gr_context_->get(); |
+ } |
+ |
+ virtual void VerifyContexts() OVERRIDE { |
+ if (!context3d_ || context3d_->isContextLost()) |
+ destroyed_ = true; |
piman
2013/02/21 22:49:48
same here wrt thread safety
danakj
2013/02/22 01:56:31
Done.
|
+ } |
+ |
+ bool destroyed() const { return destroyed_; } |
+ |
+ protected: |
+ virtual ~DefaultContextProvider() {} |
+ |
+ private: |
+ ContextFactory* factory_; |
+ bool destroyed_; |
+ scoped_ptr<WebKit::WebGraphicsContext3D> context3d_; |
+ scoped_ptr<webkit::gpu::GrContextForWebGraphicsContext3D> gr_context_; |
+}; |
+ |
+scoped_refptr<ui::ContextProvider> |
+DefaultContextFactory::OffscreenContextProviderForMainThread() { |
+ if (!offscreen_contexts_main_thread_ || |
+ !offscreen_contexts_main_thread_->destroyed()) { |
+ offscreen_contexts_main_thread_ = new DefaultContextProvider(this); |
+ } |
+ return offscreen_contexts_main_thread_; |
+} |
+ |
+scoped_refptr<ui::ContextProvider> |
+DefaultContextFactory::OffscreenContextProviderForCompositorThread() { |
+ if (!offscreen_contexts_compositor_thread_ || |
+ !offscreen_contexts_compositor_thread_->destroyed()) { |
+ offscreen_contexts_compositor_thread_ = new DefaultContextProvider(this); |
+ } |
+ return offscreen_contexts_compositor_thread_; |
+} |
+ |
void DefaultContextFactory::RemoveCompositor(Compositor* compositor) { |
} |
@@ -518,6 +597,27 @@ void Compositor::scheduleComposite() { |
ScheduleDraw(); |
} |
+scoped_refptr<ui::ContextProvider> |
+Compositor::OffscreenContextProviderForMainThread() { |
+ if (g_test_compositor_enabled) { |
+ if (!g_test_offscreen_contexts_main_thread) |
+ g_test_offscreen_contexts_main_thread = new NullContextProvider; |
+ return g_test_offscreen_contexts_main_thread; |
+ } |
+ return ContextFactory::GetInstance()->OffscreenContextProviderForMainThread(); |
+} |
+ |
+scoped_refptr<ui::ContextProvider> |
+Compositor::OffscreenContextProviderForCompositorThread() { |
+ if (g_test_compositor_enabled) { |
+ if (!g_test_offscreen_contexts_compositor_thread) |
+ g_test_offscreen_contexts_compositor_thread = new NullContextProvider; |
+ return g_test_offscreen_contexts_compositor_thread; |
+ } |
+ return ContextFactory::GetInstance()-> |
+ OffscreenContextProviderForCompositorThread(); |
+} |
+ |
scoped_refptr<CompositorLock> Compositor::GetCompositorLock() { |
if (!compositor_lock_) { |
compositor_lock_ = new CompositorLock(this); |