Index: ui/gfx/compositor/compositor_gl.h |
diff --git a/ui/gfx/compositor/compositor_gl.h b/ui/gfx/compositor/compositor_gl.h |
index 0872d1ece0dda8042b6236c71244b570f823a0c0..cfa4756738bff30773e9a3082595b8b6de694442 100644 |
--- a/ui/gfx/compositor/compositor_gl.h |
+++ b/ui/gfx/compositor/compositor_gl.h |
@@ -8,6 +8,8 @@ |
#include "base/compiler_specific.h" |
#include "base/memory/scoped_ptr.h" |
+#include "base/memory/singleton.h" |
+#include "base/memory/ref_counted.h" |
#include "ui/gfx/compositor/compositor.h" |
#include "ui/gfx/size.h" |
@@ -22,9 +24,48 @@ namespace ui { |
class CompositorGL; |
class TextureProgramGL; |
+// We share resources (such as shaders) between different Compositors via |
+// GLContext sharing so that we only have to create/destroy them once. |
+class COMPOSITOR_EXPORT SharedResources { |
+ public: |
+ static SharedResources* GetInstance(); |
+ |
+ bool MakeSharedContextCurrent(); |
+ |
+ // Creates a context that shares the resources hosted by this singleton. |
+ scoped_refptr<gfx::GLContext> CreateContext(gfx::GLSurface* surface); |
+ |
+ ui::TextureProgramGL* program_no_swizzle() { |
+ return program_no_swizzle_.get(); |
+ } |
+ |
+ ui::TextureProgramGL* program_swizzle() { |
+ return program_swizzle_.get(); |
+ } |
+ |
+ private: |
+ friend struct DefaultSingletonTraits<SharedResources>; |
+ |
+ SharedResources(); |
+ virtual ~SharedResources(); |
+ |
+ bool Initialize(); |
+ void Destroy(); |
+ |
+ bool initialized_; |
+ |
+ scoped_refptr<gfx::GLContext> context_; |
+ scoped_refptr<gfx::GLSurface> surface_; |
+ |
+ scoped_ptr<ui::TextureProgramGL> program_swizzle_; |
+ scoped_ptr<ui::TextureProgramGL> program_no_swizzle_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(SharedResources); |
+}; |
+ |
class COMPOSITOR_EXPORT TextureGL : public Texture { |
public: |
- explicit TextureGL(CompositorGL* compositor); |
+ TextureGL(); |
virtual void SetCanvas(const SkCanvas& canvas, |
const gfx::Point& origin, |
@@ -39,7 +80,7 @@ class COMPOSITOR_EXPORT TextureGL : public Texture { |
const gfx::Rect& clip_bounds_in_texture) OVERRIDE; |
protected: |
- TextureGL(CompositorGL* compositor, const gfx::Size& size); |
+ explicit TextureGL(const gfx::Size& size); |
virtual ~TextureGL(); |
// Actually draws the texture. |
@@ -50,7 +91,6 @@ class COMPOSITOR_EXPORT TextureGL : public Texture { |
unsigned int texture_id_; |
gfx::Size size_; |
- CompositorGL* compositor_; |
private: |
DISALLOW_COPY_AND_ASSIGN(TextureGL); |
@@ -64,8 +104,8 @@ class COMPOSITOR_EXPORT CompositorGL : public Compositor { |
void MakeCurrent(); |
gfx::Size GetSize(); |
- TextureProgramGL* program_no_swizzle(); |
- TextureProgramGL* program_swizzle(); |
+ protected: |
+ virtual void OnWidgetSizeChanged() OVERRIDE; |
private: |
// Overridden from Compositor. |
@@ -74,14 +114,11 @@ class COMPOSITOR_EXPORT CompositorGL : public Compositor { |
virtual void NotifyEnd() OVERRIDE; |
virtual void Blur(const gfx::Rect& bounds) OVERRIDE; |
virtual void SchedulePaint() OVERRIDE; |
- virtual void OnWidgetSizeChanged(const gfx::Size& size) OVERRIDE; |
// The GL context used for compositing. |
scoped_refptr<gfx::GLSurface> gl_surface_; |
scoped_refptr<gfx::GLContext> gl_context_; |
- gfx::Size size_; |
- |
// Keep track of whether compositing has started or not. |
bool started_; |