summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorbacker@chromium.org <backer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-08 15:10:13 +0000
committerbacker@chromium.org <backer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-08 15:10:13 +0000
commitcda29aaf8f48ceb7fcdcbf8b02691e8c393600fc (patch)
tree4b9d3f918da8895c18a64a8a730e6893cdb099e3 /ui
parent327ff6e613b71a630cb5a96ce8203202fd58064a (diff)
downloadchromium_src-cda29aaf8f48ceb7fcdcbf8b02691e8c393600fc.zip
chromium_src-cda29aaf8f48ceb7fcdcbf8b02691e8c393600fc.tar.gz
chromium_src-cda29aaf8f48ceb7fcdcbf8b02691e8c393600fc.tar.bz2
Share shaders between browser compositors.
Each compositor has it's own context. We should share shaders between them because compiling shaders is expensive. To do this, I pin the very first context created with a ref count. Then I use context sharing to share the shaders. BUG=none TEST=by hand with intel, nv, nouveau, and tegra drivers on a TOUCH_UI build Review URL: http://codereview.chromium.org/7327001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@91853 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/gfx/compositor/compositor_gl.cc43
-rw-r--r--ui/gfx/compositor/compositor_gl.h6
2 files changed, 31 insertions, 18 deletions
diff --git a/ui/gfx/compositor/compositor_gl.cc b/ui/gfx/compositor/compositor_gl.cc
index 707402d..f8d9efb 100644
--- a/ui/gfx/compositor/compositor_gl.cc
+++ b/ui/gfx/compositor/compositor_gl.cc
@@ -21,6 +21,10 @@
namespace {
+// We pin the first context that the Compositor class creates with ref counting.
+// This hosts the shaders that are shared between all Compositor contexts.
+scoped_refptr<gfx::GLContext> g_share_context;
+
GLuint CompileShader(GLenum type, const GLchar* source) {
GLuint shader = glCreateShader(type);
if (!shader)
@@ -50,6 +54,9 @@ GLuint CompileShader(GLenum type, const GLchar* source) {
namespace ui {
+TextureProgramGL* CompositorGL::program_swizzle_ = NULL;
+TextureProgramGL* CompositorGL::program_no_swizzle_ = NULL;
+
// Wraps a simple GL program for drawing textures to the screen.
class TextureProgramGL {
public:
@@ -92,7 +99,6 @@ class TextureProgramGL {
GLuint a_tex_loc_;
GLuint u_tex_loc_;
GLuint u_mat_loc_;
-
};
class TextureProgramNoSwizzleGL : public TextureProgramGL {
@@ -320,7 +326,14 @@ CompositorGL::CompositorGL(gfx::AcceleratedWidget widget,
: started_(false),
size_(size) {
gl_surface_ = gfx::GLSurface::CreateViewGLSurface(widget);
- gl_context_ = gfx::GLContext::CreateGLContext(NULL, gl_surface_.get());
+ if (g_share_context.get()) {
+ gl_context_ = gfx::GLContext::CreateGLContext(
+ g_share_context->share_group(), gl_surface_.get());
+ } else {
+ gl_context_ = gfx::GLContext::CreateGLContext(
+ NULL, gl_surface_.get());
+ g_share_context = gl_context_;
+ }
gl_context_->MakeCurrent(gl_surface_.get());
if (!InitShaders())
LOG(ERROR) << "Unable to initialize shaders (context = "
@@ -342,11 +355,11 @@ gfx::Size CompositorGL::GetSize() {
}
TextureProgramGL* CompositorGL::program_no_swizzle() {
- return program_no_swizzle_.get();
+ return program_no_swizzle_;
}
TextureProgramGL* CompositorGL::program_swizzle() {
- return program_swizzle_.get();
+ return program_swizzle_;
}
Texture* CompositorGL::CreateTexture() {
@@ -392,17 +405,19 @@ void CompositorGL::OnWidgetSizeChanged(const gfx::Size& size) {
}
bool CompositorGL::InitShaders() {
- scoped_ptr<TextureProgramGL> temp_program(new TextureProgramNoSwizzleGL());
- if (!temp_program->Initialize())
- return false;
- else
- program_no_swizzle_.reset(temp_program.release());
+ if (!program_no_swizzle_) {
+ scoped_ptr<TextureProgramGL> temp_program(new TextureProgramNoSwizzleGL());
+ if (!temp_program->Initialize())
+ return false;
+ program_no_swizzle_ = temp_program.release();
+ }
- temp_program.reset(new TextureProgramSwizzleGL());
- if (!temp_program->Initialize())
- return false;
- else
- program_swizzle_.reset(temp_program.release());
+ if (!program_swizzle_) {
+ scoped_ptr<TextureProgramGL> temp_program(new TextureProgramSwizzleGL());
+ if (!temp_program->Initialize())
+ return false;
+ program_swizzle_ = temp_program.release();
+ }
return true;
}
diff --git a/ui/gfx/compositor/compositor_gl.h b/ui/gfx/compositor/compositor_gl.h
index 7ea0b12..697e830 100644
--- a/ui/gfx/compositor/compositor_gl.h
+++ b/ui/gfx/compositor/compositor_gl.h
@@ -75,10 +75,8 @@ class CompositorGL : public Compositor {
scoped_refptr<gfx::GLSurface> gl_surface_;
scoped_refptr<gfx::GLContext> gl_context_;
- // TODO(wjmaclean): Make these static so they ca be shared in a single
- // context.
- scoped_ptr<TextureProgramGL> program_swizzle_;
- scoped_ptr<TextureProgramGL> program_no_swizzle_;
+ static TextureProgramGL* program_swizzle_;
+ static TextureProgramGL* program_no_swizzle_;
gfx::Size size_;