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

Unified Diff: ui/gfx/gl/gl_context_wgl.cc

Issue 7021014: GLContext no longer holds a pointer to a GLSurface. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 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/gl/gl_context_wgl.cc
===================================================================
--- ui/gfx/gl/gl_context_wgl.cc (revision 86168)
+++ ui/gfx/gl/gl_context_wgl.cc (working copy)
@@ -9,13 +9,12 @@
#include "base/logging.h"
#include "ui/gfx/gl/gl_bindings.h"
#include "ui/gfx/gl/gl_implementation.h"
+#include "ui/gfx/gl/gl_surface_wgl.h"
namespace gfx {
-GLContextWGL::GLContextWGL(GLSurfaceWGL* surface)
- : surface_(surface),
- context_(NULL) {
- DCHECK(surface);
+GLContextWGL::GLContextWGL()
+ : context_(NULL) {
}
GLContextWGL::~GLContextWGL() {
@@ -28,7 +27,7 @@
// able to use surface_ here. Either use a display device context or the
// surface that was passed to MakeCurrent.
const char* extensions = wglGetExtensionsStringARB(
- static_cast<HDC>(surface_->GetHandle()));
+ GLSurfaceWGL::GetDisplay());
if (extensions) {
return GLContext::GetExtensions() + " " + extensions;
}
@@ -37,12 +36,15 @@
return GLContext::GetExtensions();
}
-bool GLContextWGL::Initialize(GLContext* shared_context) {
+bool GLContextWGL::Initialize(GLContext* shared_context,
+ GLSurface* compatible_surface) {
+ GLSurfaceWGL* surface_wgl = static_cast<GLSurfaceWGL*>(compatible_surface);
+
// TODO(apatrick): When contexts and surfaces are separated, we won't be
// able to use surface_ here. Either use a display device context or a
// surface that the context is compatible with not necessarily limited to
// rendering to.
- context_ = wglCreateContext(static_cast<HDC>(surface_->GetHandle()));
+ context_ = wglCreateContext(static_cast<HDC>(surface_wgl->GetHandle()));
if (!context_) {
LOG(ERROR) << "Failed to create GL context.";
Destroy();
@@ -67,20 +69,14 @@
wglDeleteContext(context_);
context_ = NULL;
}
-
- if (surface_.get()) {
- surface_->Destroy();
- surface_.reset();
- }
}
-bool GLContextWGL::MakeCurrent() {
- if (IsCurrent()) {
+bool GLContextWGL::MakeCurrent(GLSurface* surface) {
+ DCHECK(context_);
+ if (IsCurrent(surface))
return true;
- }
- if (!wglMakeCurrent(static_cast<HDC>(surface_->GetHandle()),
- context_)) {
+ if (!wglMakeCurrent(static_cast<HDC>(surface->GetHandle()), context_)) {
LOG(ERROR) << "Unable to make gl context current.";
return false;
}
@@ -88,24 +84,23 @@
return true;
}
-bool GLContextWGL::IsCurrent() {
- return wglGetCurrentDC() == surface_->GetHandle() &&
- wglGetCurrentContext() == context_;
-}
+void GLContextWGL::ReleaseCurrent(GLSurface* surface) {
+ if (!IsCurrent(surface))
+ return;
-bool GLContextWGL::IsOffscreen() {
- // TODO(apatrick): remove this from GLContext interface.
- return surface_->IsOffscreen();
+ wglMakeCurrent(NULL, NULL);
}
-bool GLContextWGL::SwapBuffers() {
- // TODO(apatrick): remove this from GLContext interface.
- return surface_->SwapBuffers();
-}
+bool GLContextWGL::IsCurrent(GLSurface* surface) {
+ if (wglGetCurrentContext() != context_)
+ return false;
-gfx::Size GLContextWGL::GetSize() {
- // TODO(apatrick): remove this from GLContext interface.
- return surface_->GetSize();
+ if (surface) {
+ if (wglGetCurrentDC() != surface->GetHandle())
+ return false;
+ }
+
+ return true;
}
void* GLContextWGL::GetHandle() {
@@ -113,7 +108,7 @@
}
void GLContextWGL::SetSwapInterval(int interval) {
- DCHECK(IsCurrent());
+ DCHECK(IsCurrent(NULL));
if (HasExtension("WGL_EXT_swap_control") && wglSwapIntervalEXT) {
wglSwapIntervalEXT(interval);
}

Powered by Google App Engine
This is Rietveld 408576698