| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This file implements the GLContextWGL and PbufferGLContext classes. | 5 // This file implements the GLContextWGL and PbufferGLContext classes. |
| 6 | 6 |
| 7 #include "ui/gl/gl_context_wgl.h" | 7 #include "ui/gl/gl_context_wgl.h" |
| 8 | 8 |
| 9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "ui/gl/gl_bindings.h" | 11 #include "ui/gl/gl_bindings.h" |
| 12 #include "ui/gl/gl_implementation.h" | 12 #include "ui/gl/gl_implementation.h" |
| 13 #include "ui/gl/gl_surface_wgl.h" | 13 #include "ui/gl/gl_surface_wgl.h" |
| 14 | 14 |
| 15 namespace gfx { | 15 namespace gfx { |
| 16 | 16 |
| 17 GLContextWGL::GLContextWGL(GLShareGroup* share_group) | 17 GLContextWGL::GLContextWGL(GLShareGroup* share_group) |
| 18 : GLContext(share_group), | 18 : GLContextReal(share_group), |
| 19 context_(NULL) { | 19 context_(NULL) { |
| 20 } | 20 } |
| 21 | 21 |
| 22 GLContextWGL::~GLContextWGL() { | 22 GLContextWGL::~GLContextWGL() { |
| 23 Destroy(); | 23 Destroy(); |
| 24 } | 24 } |
| 25 | 25 |
| 26 std::string GLContextWGL::GetExtensions() { | 26 std::string GLContextWGL::GetExtensions() { |
| 27 const char* extensions = NULL; | 27 const char* extensions = NULL; |
| 28 if (g_driver_wgl.fn.wglGetExtensionsStringARBFn) | 28 if (g_driver_wgl.fn.wglGetExtensionsStringARBFn) |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 if (IsCurrent(surface)) | 74 if (IsCurrent(surface)) |
| 75 return true; | 75 return true; |
| 76 | 76 |
| 77 TRACE_EVENT0("gpu", "GLContextWGL::MakeCurrent"); | 77 TRACE_EVENT0("gpu", "GLContextWGL::MakeCurrent"); |
| 78 | 78 |
| 79 if (!wglMakeCurrent(static_cast<HDC>(surface->GetHandle()), context_)) { | 79 if (!wglMakeCurrent(static_cast<HDC>(surface->GetHandle()), context_)) { |
| 80 LOG(ERROR) << "Unable to make gl context current."; | 80 LOG(ERROR) << "Unable to make gl context current."; |
| 81 return false; | 81 return false; |
| 82 } | 82 } |
| 83 | 83 |
| 84 SetCurrent(this, surface); | 84 SetCurrent(surface); |
| 85 if (!InitializeExtensionBindings()) { | 85 if (!InitializeExtensionBindings()) { |
| 86 ReleaseCurrent(surface); | 86 ReleaseCurrent(surface); |
| 87 return false; | 87 return false; |
| 88 } | 88 } |
| 89 | 89 |
| 90 if (!surface->OnMakeCurrent(this)) { | 90 if (!surface->OnMakeCurrent(this)) { |
| 91 LOG(ERROR) << "Could not make current."; | 91 LOG(ERROR) << "Could not make current."; |
| 92 return false; | 92 return false; |
| 93 } | 93 } |
| 94 | 94 |
| 95 SetRealGLApi(); | 95 SetRealGLApi(); |
| 96 return true; | 96 return true; |
| 97 } | 97 } |
| 98 | 98 |
| 99 void GLContextWGL::ReleaseCurrent(GLSurface* surface) { | 99 void GLContextWGL::ReleaseCurrent(GLSurface* surface) { |
| 100 if (!IsCurrent(surface)) | 100 if (!IsCurrent(surface)) |
| 101 return; | 101 return; |
| 102 | 102 |
| 103 SetCurrent(NULL, NULL); | 103 SetCurrent(NULL); |
| 104 wglMakeCurrent(NULL, NULL); | 104 wglMakeCurrent(NULL, NULL); |
| 105 } | 105 } |
| 106 | 106 |
| 107 bool GLContextWGL::IsCurrent(GLSurface* surface) { | 107 bool GLContextWGL::IsCurrent(GLSurface* surface) { |
| 108 bool native_context_is_current = | 108 bool native_context_is_current = |
| 109 wglGetCurrentContext() == context_; | 109 wglGetCurrentContext() == context_; |
| 110 | 110 |
| 111 // If our context is current then our notion of which GLContext is | 111 // If our context is current then our notion of which GLContext is |
| 112 // current must be correct. On the other hand, third-party code | 112 // current must be correct. On the other hand, third-party code |
| 113 // using OpenGL might change the current context. | 113 // using OpenGL might change the current context. |
| 114 DCHECK(!native_context_is_current || (GetCurrent() == this)); | 114 DCHECK(!native_context_is_current || (GetRealCurrent() == this)); |
| 115 | 115 |
| 116 if (!native_context_is_current) | 116 if (!native_context_is_current) |
| 117 return false; | 117 return false; |
| 118 | 118 |
| 119 if (surface) { | 119 if (surface) { |
| 120 if (wglGetCurrentDC() != surface->GetHandle()) | 120 if (wglGetCurrentDC() != surface->GetHandle()) |
| 121 return false; | 121 return false; |
| 122 } | 122 } |
| 123 | 123 |
| 124 return true; | 124 return true; |
| 125 } | 125 } |
| 126 | 126 |
| 127 void* GLContextWGL::GetHandle() { | 127 void* GLContextWGL::GetHandle() { |
| 128 return context_; | 128 return context_; |
| 129 } | 129 } |
| 130 | 130 |
| 131 void GLContextWGL::SetSwapInterval(int interval) { | 131 void GLContextWGL::SetSwapInterval(int interval) { |
| 132 DCHECK(IsCurrent(NULL)); | 132 DCHECK(IsCurrent(NULL)); |
| 133 if (gfx::g_driver_wgl.ext.b_WGL_EXT_swap_control) { | 133 if (gfx::g_driver_wgl.ext.b_WGL_EXT_swap_control) { |
| 134 wglSwapIntervalEXT(interval); | 134 wglSwapIntervalEXT(interval); |
| 135 } else { | 135 } else { |
| 136 LOG(WARNING) << | 136 LOG(WARNING) << |
| 137 "Could not disable vsync: driver does not " | 137 "Could not disable vsync: driver does not " |
| 138 "support WGL_EXT_swap_control"; | 138 "support WGL_EXT_swap_control"; |
| 139 } | 139 } |
| 140 } | 140 } |
| 141 | 141 |
| 142 } // namespace gfx | 142 } // namespace gfx |
| OLD | NEW |