Commit cda29aaf authored by backer@chromium.org's avatar backer@chromium.org

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
parent 327ff6e6
...@@ -21,6 +21,10 @@ ...@@ -21,6 +21,10 @@
namespace { 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 CompileShader(GLenum type, const GLchar* source) {
GLuint shader = glCreateShader(type); GLuint shader = glCreateShader(type);
if (!shader) if (!shader)
...@@ -50,6 +54,9 @@ GLuint CompileShader(GLenum type, const GLchar* source) { ...@@ -50,6 +54,9 @@ GLuint CompileShader(GLenum type, const GLchar* source) {
namespace ui { namespace ui {
TextureProgramGL* CompositorGL::program_swizzle_ = NULL;
TextureProgramGL* CompositorGL::program_no_swizzle_ = NULL;
// Wraps a simple GL program for drawing textures to the screen. // Wraps a simple GL program for drawing textures to the screen.
class TextureProgramGL { class TextureProgramGL {
public: public:
...@@ -92,7 +99,6 @@ class TextureProgramGL { ...@@ -92,7 +99,6 @@ class TextureProgramGL {
GLuint a_tex_loc_; GLuint a_tex_loc_;
GLuint u_tex_loc_; GLuint u_tex_loc_;
GLuint u_mat_loc_; GLuint u_mat_loc_;
}; };
class TextureProgramNoSwizzleGL : public TextureProgramGL { class TextureProgramNoSwizzleGL : public TextureProgramGL {
...@@ -320,7 +326,14 @@ CompositorGL::CompositorGL(gfx::AcceleratedWidget widget, ...@@ -320,7 +326,14 @@ CompositorGL::CompositorGL(gfx::AcceleratedWidget widget,
: started_(false), : started_(false),
size_(size) { size_(size) {
gl_surface_ = gfx::GLSurface::CreateViewGLSurface(widget); 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()); gl_context_->MakeCurrent(gl_surface_.get());
if (!InitShaders()) if (!InitShaders())
LOG(ERROR) << "Unable to initialize shaders (context = " LOG(ERROR) << "Unable to initialize shaders (context = "
...@@ -342,11 +355,11 @@ gfx::Size CompositorGL::GetSize() { ...@@ -342,11 +355,11 @@ gfx::Size CompositorGL::GetSize() {
} }
TextureProgramGL* CompositorGL::program_no_swizzle() { TextureProgramGL* CompositorGL::program_no_swizzle() {
return program_no_swizzle_.get(); return program_no_swizzle_;
} }
TextureProgramGL* CompositorGL::program_swizzle() { TextureProgramGL* CompositorGL::program_swizzle() {
return program_swizzle_.get(); return program_swizzle_;
} }
Texture* CompositorGL::CreateTexture() { Texture* CompositorGL::CreateTexture() {
...@@ -392,17 +405,19 @@ void CompositorGL::OnWidgetSizeChanged(const gfx::Size& size) { ...@@ -392,17 +405,19 @@ void CompositorGL::OnWidgetSizeChanged(const gfx::Size& size) {
} }
bool CompositorGL::InitShaders() { bool CompositorGL::InitShaders() {
scoped_ptr<TextureProgramGL> temp_program(new TextureProgramNoSwizzleGL()); if (!program_no_swizzle_) {
if (!temp_program->Initialize()) scoped_ptr<TextureProgramGL> temp_program(new TextureProgramNoSwizzleGL());
return false; if (!temp_program->Initialize())
else return false;
program_no_swizzle_.reset(temp_program.release()); program_no_swizzle_ = temp_program.release();
}
temp_program.reset(new TextureProgramSwizzleGL()); if (!program_swizzle_) {
if (!temp_program->Initialize()) scoped_ptr<TextureProgramGL> temp_program(new TextureProgramSwizzleGL());
return false; if (!temp_program->Initialize())
else return false;
program_swizzle_.reset(temp_program.release()); program_swizzle_ = temp_program.release();
}
return true; return true;
} }
......
...@@ -75,10 +75,8 @@ class CompositorGL : public Compositor { ...@@ -75,10 +75,8 @@ class CompositorGL : public Compositor {
scoped_refptr<gfx::GLSurface> gl_surface_; scoped_refptr<gfx::GLSurface> gl_surface_;
scoped_refptr<gfx::GLContext> gl_context_; scoped_refptr<gfx::GLContext> gl_context_;
// TODO(wjmaclean): Make these static so they ca be shared in a single static TextureProgramGL* program_swizzle_;
// context. static TextureProgramGL* program_no_swizzle_;
scoped_ptr<TextureProgramGL> program_swizzle_;
scoped_ptr<TextureProgramGL> program_no_swizzle_;
gfx::Size size_; gfx::Size size_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment