summaryrefslogtreecommitdiffstats
path: root/ui/gl
diff options
context:
space:
mode:
Diffstat (limited to 'ui/gl')
-rw-r--r--ui/gl/gl_context.cc6
-rw-r--r--ui/gl/gl_context.h10
-rw-r--r--ui/gl/gl_state_restorer.h2
-rw-r--r--ui/gl/scoped_binders.cc61
-rw-r--r--ui/gl/scoped_binders.h21
5 files changed, 76 insertions, 24 deletions
diff --git a/ui/gl/gl_context.cc b/ui/gl/gl_context.cc
index 610ce44..e26f759 100644
--- a/ui/gl/gl_context.cc
+++ b/ui/gl/gl_context.cc
@@ -96,7 +96,11 @@ void GLContext::SetCurrent(GLContext* context, GLSurface* surface) {
}
GLStateRestorer* GLContext::GetGLStateRestorer() {
- return NULL;
+ return state_restorer_.get();
+}
+
+void GLContext::SetGLStateRestorer(GLStateRestorer* state_restorer) {
+ state_restorer_ = make_scoped_ptr(state_restorer);
}
bool GLContext::WasAllocatedUsingRobustnessExtension() {
diff --git a/ui/gl/gl_context.h b/ui/gl/gl_context.h
index 8f9aa23..fe8ada2 100644
--- a/ui/gl/gl_context.h
+++ b/ui/gl/gl_context.h
@@ -11,13 +11,13 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "ui/gl/gl_share_group.h"
+#include "ui/gl/gl_state_restorer.h"
#include "ui/gl/gpu_preference.h"
namespace gfx {
class GLSurface;
class VirtualGLApi;
-class GLStateRestorer;
// Encapsulates an OpenGL context, hiding platform specific management.
class GL_EXPORT GLContext : public base::RefCounted<GLContext> {
@@ -47,8 +47,11 @@ class GL_EXPORT GLContext : public base::RefCounted<GLContext> {
// Get the underlying platform specific GL context "handle".
virtual void* GetHandle() = 0;
- // Gets the GLStateRestore for the context.
- virtual GLStateRestorer* GetGLStateRestorer();
+ // Gets the GLStateRestorer for the context.
+ GLStateRestorer* GetGLStateRestorer();
+
+ // Sets the GLStateRestorer for the context (takes ownership).
+ void SetGLStateRestorer(GLStateRestorer* state_restorer);
// Set swap interval. This context must be current.
virtual void SetSwapInterval(int interval) = 0;
@@ -116,6 +119,7 @@ class GL_EXPORT GLContext : public base::RefCounted<GLContext> {
scoped_refptr<GLShareGroup> share_group_;
scoped_ptr<VirtualGLApi> virtual_gl_api_;
+ scoped_ptr<GLStateRestorer> state_restorer_;
DISALLOW_COPY_AND_ASSIGN(GLContext);
};
diff --git a/ui/gl/gl_state_restorer.h b/ui/gl/gl_state_restorer.h
index 8366a7a..3ada2fe 100644
--- a/ui/gl/gl_state_restorer.h
+++ b/ui/gl/gl_state_restorer.h
@@ -18,6 +18,8 @@ class GL_EXPORT GLStateRestorer {
virtual ~GLStateRestorer();
virtual void RestoreState() = 0;
+ virtual void RestoreAllTextureUnitBindings() = 0;
+ virtual void RestoreFramebufferBindings() = 0;
DISALLOW_COPY_AND_ASSIGN(GLStateRestorer);
};
diff --git a/ui/gl/scoped_binders.cc b/ui/gl/scoped_binders.cc
index 4fce78f..696acf6 100644
--- a/ui/gl/scoped_binders.cc
+++ b/ui/gl/scoped_binders.cc
@@ -4,37 +4,62 @@
#include "ui/gl/scoped_binders.h"
#include "ui/gl/gl_bindings.h"
+#include "ui/gl/gl_context.h"
+#include "ui/gl/gl_state_restorer.h"
-namespace ui {
+namespace gfx {
-ScopedFrameBufferBinder::ScopedFrameBufferBinder(unsigned int fbo) {
- glGetIntegerv(GL_FRAMEBUFFER_BINDING, &old_fbo_);
+ScopedFrameBufferBinder::ScopedFrameBufferBinder(unsigned int fbo)
+ : state_restorer_(!GLContext::GetCurrent()
+ ? NULL
+ : GLContext::GetCurrent()->GetGLStateRestorer()),
+ old_fbo_(-1) {
+ if (!state_restorer_)
+ glGetIntegerv(GL_FRAMEBUFFER_BINDING, &old_fbo_);
glBindFramebufferEXT(GL_FRAMEBUFFER, fbo);
}
ScopedFrameBufferBinder::~ScopedFrameBufferBinder() {
- glBindFramebufferEXT(GL_FRAMEBUFFER, old_fbo_);
+ if (state_restorer_) {
+ DCHECK(!!GLContext::GetCurrent());
+ DCHECK_EQ(state_restorer_, GLContext::GetCurrent()->GetGLStateRestorer());
+ state_restorer_->RestoreAllTextureUnitBindings();
+ } else {
+ glBindFramebufferEXT(GL_FRAMEBUFFER, old_fbo_);
+ }
}
ScopedTextureBinder::ScopedTextureBinder(unsigned int target, unsigned int id)
- : target_(target) {
- GLenum target_getter = 0;
- switch (target) {
- case GL_TEXTURE_2D:
- target_getter = GL_TEXTURE_BINDING_2D;
- break;
- case GL_TEXTURE_CUBE_MAP:
- target_getter = GL_TEXTURE_BINDING_CUBE_MAP;
- break;
- default:
- NOTIMPLEMENTED() << "Target not part of OpenGL ES 2.0 spec.";
+ : state_restorer_(!GLContext::GetCurrent()
+ ? NULL
+ : GLContext::GetCurrent()->GetGLStateRestorer()),
+ target_(target),
+ old_id_(-1) {
+ if (!state_restorer_) {
+ GLenum target_getter = 0;
+ switch (target) {
+ case GL_TEXTURE_2D:
+ target_getter = GL_TEXTURE_BINDING_2D;
+ break;
+ case GL_TEXTURE_CUBE_MAP:
+ target_getter = GL_TEXTURE_BINDING_CUBE_MAP;
+ break;
+ default:
+ NOTIMPLEMENTED() << "Target not part of OpenGL ES 2.0 spec.";
+ }
+ glGetIntegerv(target_getter, &old_id_);
}
- glGetIntegerv(target_getter, &old_id_);
glBindTexture(target_, id);
}
ScopedTextureBinder::~ScopedTextureBinder() {
- glBindTexture(target_, old_id_);
+ if (state_restorer_) {
+ DCHECK(!!GLContext::GetCurrent());
+ DCHECK_EQ(state_restorer_, GLContext::GetCurrent()->GetGLStateRestorer());
+ state_restorer_->RestoreAllTextureUnitBindings();
+ } else {
+ glBindTexture(target_, old_id_);
+ }
}
-} // namespace ui
+} // namespace gfx
diff --git a/ui/gl/scoped_binders.h b/ui/gl/scoped_binders.h
index c133673..dab7b31 100644
--- a/ui/gl/scoped_binders.h
+++ b/ui/gl/scoped_binders.h
@@ -5,9 +5,11 @@
#ifndef UI_GL_SCOPED_BINDERS_H_
#define UI_GL_SCOPED_BINDERS_H_
+#include "base/basictypes.h"
#include "ui/gl/gl_export.h"
-namespace ui {
+namespace gfx {
+class GLStateRestorer;
class GL_EXPORT ScopedFrameBufferBinder {
public:
@@ -15,19 +17,34 @@ class GL_EXPORT ScopedFrameBufferBinder {
~ScopedFrameBufferBinder();
private:
+ // Whenever possible we prefer to use the current GLContext's
+ // GLStateRestorer to maximize driver compabitility.
+ GLStateRestorer* state_restorer_;
+
+ // Failing that we use GL calls to save and restore state.
int old_fbo_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScopedFrameBufferBinder);
};
+
class GL_EXPORT ScopedTextureBinder {
public:
ScopedTextureBinder(unsigned int target, unsigned int id);
~ScopedTextureBinder();
private:
+ // Whenever possible we prefer to use the current GLContext's
+ // GLStateRestorer to maximize driver compabitility.
+ GLStateRestorer* state_restorer_;
+
+ // Failing that we use GL calls to save and restore state.
int target_;
int old_id_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScopedTextureBinder);
};
-} // namespace ui
+} // namespace gfx
#endif // UI_GL_SCOPED_BINDERS_H_