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

Unified Diff: ui/gfx/compositor/compositor_gl.h

Issue 7552039: Vend common GL context (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge with ToT Created 9 years, 4 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: ui/gfx/compositor/compositor_gl.h
diff --git a/ui/gfx/compositor/compositor_gl.h b/ui/gfx/compositor/compositor_gl.h
index 0872d1ece0dda8042b6236c71244b570f823a0c0..f1b9bb53b7c70ab75c3fb290cbc50bfdce0bd010 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,
@@ -33,24 +74,26 @@ class COMPOSITOR_EXPORT TextureGL : public Texture {
// Draws the texture.
// TODO(pkotwicz) merge these two methods into one, this method currently
// doesn't make sense in the context of windows
- virtual void Draw(const ui::TextureDrawParams& params) OVERRIDE;
+ virtual void Draw(const ui::TextureDrawParams& params,
+ const gfx::Size& surface_size) OVERRIDE;
virtual void Draw(const ui::TextureDrawParams& params,
- const gfx::Rect& clip_bounds_in_texture) OVERRIDE;
+ const gfx::Rect& clip_bounds_in_texture,
+ const gfx::Size& surface_size) OVERRIDE;
protected:
- TextureGL(CompositorGL* compositor, const gfx::Size& size);
+ explicit TextureGL(const gfx::Size& size);
virtual ~TextureGL();
// Actually draws the texture.
// Only the region defined by draw_bounds will be drawn.
void DrawInternal(const TextureProgramGL& program,
const ui::TextureDrawParams& params,
- const gfx::Rect& clip_bounds_in_texture);
+ const gfx::Rect& clip_bounds_in_texture,
+ const gfx::Size& surface_size);
unsigned int texture_id_;
gfx::Size size_;
- CompositorGL* compositor_;
private:
DISALLOW_COPY_AND_ASSIGN(TextureGL);
@@ -64,9 +107,6 @@ class COMPOSITOR_EXPORT CompositorGL : public Compositor {
void MakeCurrent();
gfx::Size GetSize();
- TextureProgramGL* program_no_swizzle();
- TextureProgramGL* program_swizzle();
-
private:
// Overridden from Compositor.
virtual Texture* CreateTexture() OVERRIDE;
@@ -80,8 +120,6 @@ class COMPOSITOR_EXPORT CompositorGL : public Compositor {
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_;

Powered by Google App Engine
This is Rietveld 408576698