diff options
author | apatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-23 20:34:15 +0000 |
---|---|---|
committer | apatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-23 20:34:15 +0000 |
commit | f62a5abd6205c7a84a19f8b00b45b0792b767f57 (patch) | |
tree | 100e751f4e0302bbb4ecde919fb1cea272aeb7cf /ui/gfx/gl/gl_context_cgl.cc | |
parent | 97807cbf58afe1e25b2bd014ce758e88e483d08b (diff) | |
download | chromium_src-f62a5abd6205c7a84a19f8b00b45b0792b767f57.zip chromium_src-f62a5abd6205c7a84a19f8b00b45b0792b767f57.tar.gz chromium_src-f62a5abd6205c7a84a19f8b00b45b0792b767f57.tar.bz2 |
GLContext no longer holds a pointer to a GLSurface.
This is part of an ongoing effort to treat GL contexts and GL surfaces as independent entities.
TEST=run WebGL on mac, windows and linux, trybots
BUG=none
Review URL: http://codereview.chromium.org/7021014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86332 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx/gl/gl_context_cgl.cc')
-rw-r--r-- | ui/gfx/gl/gl_context_cgl.cc | 55 |
1 files changed, 34 insertions, 21 deletions
diff --git a/ui/gfx/gl/gl_context_cgl.cc b/ui/gfx/gl/gl_context_cgl.cc index bee8ac2..cb2853b 100644 --- a/ui/gfx/gl/gl_context_cgl.cc +++ b/ui/gfx/gl/gl_context_cgl.cc @@ -10,16 +10,18 @@ namespace gfx { -GLContextCGL::GLContextCGL(GLSurfaceCGL* surface) - : surface_(surface), - context_(NULL) { +GLContextCGL::GLContextCGL() + : context_(NULL) { } GLContextCGL::~GLContextCGL() { Destroy(); } -bool GLContextCGL::Initialize(GLContext* shared_context) { +bool GLContextCGL::Initialize(GLContext* shared_context, + GLSurface* compatible_surface) { + DCHECK(compatible_surface); + CGLError res = CGLCreateContext( static_cast<CGLPixelFormatObj>(GLSurfaceCGL::GetPixelFormat()), shared_context ? @@ -41,12 +43,13 @@ void GLContextCGL::Destroy() { } } -bool GLContextCGL::MakeCurrent() { - if (IsCurrent()) +bool GLContextCGL::MakeCurrent(GLSurface* surface) { + DCHECK(context_); + if (IsCurrent(surface)) return true; if (CGLSetPBuffer(static_cast<CGLContextObj>(context_), - static_cast<CGLPBufferObj>(surface_->GetHandle()), + static_cast<CGLPBufferObj>(surface->GetHandle()), 0, 0, 0) != kCGLNoError) { @@ -64,23 +67,33 @@ bool GLContextCGL::MakeCurrent() { return true; } -bool GLContextCGL::IsCurrent() { - return CGLGetCurrentContext() == context_; -} +void GLContextCGL::ReleaseCurrent(GLSurface* surface) { + if (!IsCurrent(surface)) + return; -bool GLContextCGL::IsOffscreen() { - // TODO(apatrick): remove this from GLContext interface. - return surface_->IsOffscreen(); + CGLSetCurrentContext(NULL); + CGLSetPBuffer(static_cast<CGLContextObj>(context_), NULL, 0, 0, 0); } -bool GLContextCGL::SwapBuffers() { - // TODO(apatrick): remove this from GLContext interface. - return surface_->SwapBuffers(); -} +bool GLContextCGL::IsCurrent(GLSurface* surface) { + if (CGLGetCurrentContext() != context_) + return false; -gfx::Size GLContextCGL::GetSize() { - // TODO(apatrick): remove this from GLContext interface. - return surface_->GetSize(); + if (surface) { + CGLPBufferObj current_surface = NULL; + GLenum face; + GLint level; + GLint screen; + CGLGetPBuffer(static_cast<CGLContextObj>(context_), + ¤t_surface, + &face, + &level, + &screen); + if (current_surface != surface->GetHandle()) + return false; + } + + return true; } void* GLContextCGL::GetHandle() { @@ -88,7 +101,7 @@ void* GLContextCGL::GetHandle() { } void GLContextCGL::SetSwapInterval(int interval) { - DCHECK(IsCurrent()); + DCHECK(IsCurrent(NULL)); NOTREACHED() << "Attempt to call SetSwapInterval on a GLContextCGL."; } |