| 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 #include "ui/gl/gl_surface_wgl.h" | 5 #include "ui/gl/gl_surface_wgl.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "ui/gl/gl_bindings.h" | 9 #include "ui/gl/gl_bindings.h" |
| 10 #include "ui/gl/gl_gl_api_implementation.h" | 10 #include "ui/gl/gl_gl_api_implementation.h" |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 bool GLSurfaceWGL::InitializeOneOff() { | 157 bool GLSurfaceWGL::InitializeOneOff() { |
| 158 static bool initialized = false; | 158 static bool initialized = false; |
| 159 if (initialized) | 159 if (initialized) |
| 160 return true; | 160 return true; |
| 161 | 161 |
| 162 DCHECK(g_display == NULL); | 162 DCHECK(g_display == NULL); |
| 163 scoped_ptr<DisplayWGL> wgl_display(new DisplayWGL); | 163 scoped_ptr<DisplayWGL> wgl_display(new DisplayWGL); |
| 164 if (!wgl_display->Init()) | 164 if (!wgl_display->Init()) |
| 165 return false; | 165 return false; |
| 166 | 166 |
| 167 // Create a temporary GL context to bind to extension entry points. | 167 // Create a temporary GL context to bind to entry points. wglGetProcAddress |
| 168 // is specified to return NULL for all queries if a context is not current in |
| 169 // MSDN documentation, and the static bindings may contain functions that |
| 170 // need to be queried with wglGetProcAddress. |
| 168 HGLRC gl_context = wglCreateContext(wgl_display->device_context()); | 171 HGLRC gl_context = wglCreateContext(wgl_display->device_context()); |
| 169 if (!gl_context) { | 172 if (!gl_context) { |
| 170 LOG(ERROR) << "Failed to create temporary context."; | 173 LOG(ERROR) << "Failed to create temporary context."; |
| 171 return false; | 174 return false; |
| 172 } | 175 } |
| 173 if (!wglMakeCurrent(wgl_display->device_context(), gl_context)) { | 176 if (!wglMakeCurrent(wgl_display->device_context(), gl_context)) { |
| 174 LOG(ERROR) << "Failed to make temporary GL context current."; | 177 LOG(ERROR) << "Failed to make temporary GL context current."; |
| 175 wglDeleteContext(gl_context); | 178 wglDeleteContext(gl_context); |
| 176 return false; | 179 return false; |
| 177 } | 180 } |
| 178 // Get bindings to extension functions that cannot be acquired without a | 181 InitializeStaticGLBindingsGL(); |
| 179 // current context. | 182 InitializeStaticGLBindingsWGL(); |
| 180 InitializeGLBindingsGL(); | |
| 181 InitializeGLBindingsWGL(); | |
| 182 | 183 |
| 183 wglMakeCurrent(NULL, NULL); | 184 wglMakeCurrent(NULL, NULL); |
| 184 wglDeleteContext(gl_context); | 185 wglDeleteContext(gl_context); |
| 185 | 186 |
| 186 g_display = wgl_display.release(); | 187 g_display = wgl_display.release(); |
| 187 initialized = true; | 188 initialized = true; |
| 188 return true; | 189 return true; |
| 189 } | 190 } |
| 190 | 191 |
| 191 HDC GLSurfaceWGL::GetDisplayDC() { | 192 HDC GLSurfaceWGL::GetDisplayDC() { |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 | 360 |
| 360 gfx::Size PbufferGLSurfaceWGL::GetSize() { | 361 gfx::Size PbufferGLSurfaceWGL::GetSize() { |
| 361 return size_; | 362 return size_; |
| 362 } | 363 } |
| 363 | 364 |
| 364 void* PbufferGLSurfaceWGL::GetHandle() { | 365 void* PbufferGLSurfaceWGL::GetHandle() { |
| 365 return device_context_; | 366 return device_context_; |
| 366 } | 367 } |
| 367 | 368 |
| 368 } // namespace gfx | 369 } // namespace gfx |
| OLD | NEW |