OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/gfx/gl/gl_context_wgl.h" | 5 #include "ui/gfx/gl/gl_surface_wgl.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "ui/gfx/gl/gl_bindings.h" | 8 #include "ui/gfx/gl/gl_bindings.h" |
9 #include "ui/gfx/gl/gl_implementation.h" | 9 #include "ui/gfx/gl/gl_implementation.h" |
10 | 10 |
11 namespace gfx { | 11 namespace gfx { |
12 | 12 |
13 static ATOM g_class_registration; | 13 static ATOM g_class_registration; |
14 static HWND g_window; | 14 static HWND g_window; |
| 15 HDC g_display_dc; |
15 static int g_pixel_format = 0; | 16 static int g_pixel_format = 0; |
16 | 17 |
17 const PIXELFORMATDESCRIPTOR kPixelFormatDescriptor = { | 18 const PIXELFORMATDESCRIPTOR kPixelFormatDescriptor = { |
18 sizeof(kPixelFormatDescriptor), // Size of structure. | 19 sizeof(kPixelFormatDescriptor), // Size of structure. |
19 1, // Default version. | 20 1, // Default version. |
20 PFD_DRAW_TO_WINDOW | // Window drawing support. | 21 PFD_DRAW_TO_WINDOW | // Window drawing support. |
21 PFD_SUPPORT_OPENGL | // OpenGL support. | 22 PFD_SUPPORT_OPENGL | // OpenGL support. |
22 PFD_DOUBLEBUFFER, // Double buffering support (not stereo). | 23 PFD_DOUBLEBUFFER, // Double buffering support (not stereo). |
23 PFD_TYPE_RGBA, // RGBA color mode (not indexed). | 24 PFD_TYPE_RGBA, // RGBA color mode (not indexed). |
24 24, // 24 bit color mode. | 25 24, // 24 bit color mode. |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 NULL, | 105 NULL, |
105 NULL); | 106 NULL); |
106 | 107 |
107 if (!g_window) { | 108 if (!g_window) { |
108 UnregisterClass(reinterpret_cast<wchar_t*>(g_class_registration), | 109 UnregisterClass(reinterpret_cast<wchar_t*>(g_class_registration), |
109 module_handle); | 110 module_handle); |
110 LOG(ERROR) << "CreateWindow failed."; | 111 LOG(ERROR) << "CreateWindow failed."; |
111 return false; | 112 return false; |
112 } | 113 } |
113 | 114 |
114 HDC temporary_dc = GetDC(g_window); | 115 g_display_dc = GetDC(g_window); |
115 | 116 |
116 g_pixel_format = ChoosePixelFormat(temporary_dc, | 117 g_pixel_format = ChoosePixelFormat(g_display_dc, |
117 &kPixelFormatDescriptor); | 118 &kPixelFormatDescriptor); |
118 | 119 |
119 if (g_pixel_format == 0) { | 120 if (g_pixel_format == 0) { |
120 LOG(ERROR) << "Unable to get the pixel format for GL context."; | 121 LOG(ERROR) << "Unable to get the pixel format for GL context."; |
121 ReleaseDC(g_window, temporary_dc); | |
122 UnregisterClass(reinterpret_cast<wchar_t*>(g_class_registration), | 122 UnregisterClass(reinterpret_cast<wchar_t*>(g_class_registration), |
123 module_handle); | 123 module_handle); |
124 return false; | 124 return false; |
125 } | 125 } |
126 | 126 |
127 if (!SetPixelFormat(temporary_dc, | 127 if (!SetPixelFormat(g_display_dc, |
128 g_pixel_format, | 128 g_pixel_format, |
129 &kPixelFormatDescriptor)) { | 129 &kPixelFormatDescriptor)) { |
130 LOG(ERROR) << "Unable to set the pixel format for temporary GL context."; | 130 LOG(ERROR) << "Unable to set the pixel format for temporary GL context."; |
131 ReleaseDC(g_window, temporary_dc); | |
132 UnregisterClass(reinterpret_cast<wchar_t*>(g_class_registration), | 131 UnregisterClass(reinterpret_cast<wchar_t*>(g_class_registration), |
133 module_handle); | 132 module_handle); |
134 return false; | 133 return false; |
135 } | 134 } |
136 | 135 |
137 // Create a temporary GL context to bind to extension entry points. | 136 // Create a temporary GL context to bind to extension entry points. |
138 HGLRC gl_context = wglCreateContext(temporary_dc); | 137 HGLRC gl_context = wglCreateContext(g_display_dc); |
139 if (!gl_context) { | 138 if (!gl_context) { |
140 LOG(ERROR) << "Failed to create temporary context."; | 139 LOG(ERROR) << "Failed to create temporary context."; |
141 ReleaseDC(g_window, temporary_dc); | |
142 UnregisterClass(reinterpret_cast<wchar_t*>(g_class_registration), | 140 UnregisterClass(reinterpret_cast<wchar_t*>(g_class_registration), |
143 module_handle); | 141 module_handle); |
144 return false; | 142 return false; |
145 } | 143 } |
146 | 144 |
147 if (!wglMakeCurrent(temporary_dc, gl_context)) { | 145 if (!wglMakeCurrent(g_display_dc, gl_context)) { |
148 LOG(ERROR) << "Failed to make temporary GL context current."; | 146 LOG(ERROR) << "Failed to make temporary GL context current."; |
149 wglDeleteContext(gl_context); | 147 wglDeleteContext(gl_context); |
150 ReleaseDC(g_window, temporary_dc); | |
151 UnregisterClass(reinterpret_cast<wchar_t*>(g_class_registration), | 148 UnregisterClass(reinterpret_cast<wchar_t*>(g_class_registration), |
152 module_handle); | 149 module_handle); |
153 return false; | 150 return false; |
154 } | 151 } |
155 | 152 |
156 // Get bindings to extension functions that cannot be acquired without a | 153 // Get bindings to extension functions that cannot be acquired without a |
157 // current context. | 154 // current context. |
158 InitializeGLBindingsGL(); | 155 InitializeGLBindingsGL(); |
159 InitializeGLBindingsWGL(); | 156 InitializeGLBindingsWGL(); |
160 | 157 |
161 wglMakeCurrent(NULL, NULL); | 158 wglMakeCurrent(NULL, NULL); |
162 wglDeleteContext(gl_context); | 159 wglDeleteContext(gl_context); |
163 ReleaseDC(g_window, temporary_dc); | |
164 | 160 |
165 initialized = true; | 161 initialized = true; |
166 return true; | 162 return true; |
167 } | 163 } |
168 | 164 |
| 165 HDC GLSurfaceWGL::GetDisplay() { |
| 166 return g_display_dc; |
| 167 } |
| 168 |
169 NativeViewGLSurfaceWGL::NativeViewGLSurfaceWGL(gfx::PluginWindowHandle window) | 169 NativeViewGLSurfaceWGL::NativeViewGLSurfaceWGL(gfx::PluginWindowHandle window) |
170 : window_(window), | 170 : window_(window), |
171 child_window_(NULL), | 171 child_window_(NULL), |
172 device_context_(NULL) { | 172 device_context_(NULL) { |
173 DCHECK(window); | 173 DCHECK(window); |
174 } | 174 } |
175 | 175 |
176 NativeViewGLSurfaceWGL::~NativeViewGLSurfaceWGL() { | 176 NativeViewGLSurfaceWGL::~NativeViewGLSurfaceWGL() { |
177 Destroy(); | 177 Destroy(); |
178 } | 178 } |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 | 280 |
281 bool PbufferGLSurfaceWGL::Initialize() { | 281 bool PbufferGLSurfaceWGL::Initialize() { |
282 DCHECK(!device_context_); | 282 DCHECK(!device_context_); |
283 | 283 |
284 if (!wglCreatePbufferARB) { | 284 if (!wglCreatePbufferARB) { |
285 LOG(ERROR) << "wglCreatePbufferARB not available."; | 285 LOG(ERROR) << "wglCreatePbufferARB not available."; |
286 Destroy(); | 286 Destroy(); |
287 return false; | 287 return false; |
288 } | 288 } |
289 | 289 |
290 // Create a temporary device context for the display. The pbuffer will be | |
291 // compatible with it. | |
292 HDC temporary_dc = GetDC(g_window); | |
293 if (!temporary_dc) { | |
294 LOG(ERROR) << "Unable to get device context."; | |
295 return false; | |
296 } | |
297 | |
298 const int kNoAttributes[] = { 0 }; | 290 const int kNoAttributes[] = { 0 }; |
299 pbuffer_ = wglCreatePbufferARB(temporary_dc, | 291 pbuffer_ = wglCreatePbufferARB(g_display_dc, |
300 g_pixel_format, | 292 g_pixel_format, |
301 size_.width(), size_.height(), | 293 size_.width(), size_.height(), |
302 kNoAttributes); | 294 kNoAttributes); |
303 | 295 |
304 ReleaseDC(g_window, temporary_dc); | |
305 | |
306 if (!pbuffer_) { | 296 if (!pbuffer_) { |
307 LOG(ERROR) << "Unable to create pbuffer."; | 297 LOG(ERROR) << "Unable to create pbuffer."; |
308 Destroy(); | 298 Destroy(); |
309 return false; | 299 return false; |
310 } | 300 } |
311 | 301 |
312 device_context_ = wglGetPbufferDCARB(static_cast<HPBUFFERARB>(pbuffer_)); | 302 device_context_ = wglGetPbufferDCARB(static_cast<HPBUFFERARB>(pbuffer_)); |
313 if (!device_context_) { | 303 if (!device_context_) { |
314 LOG(ERROR) << "Unable to get pbuffer device context."; | 304 LOG(ERROR) << "Unable to get pbuffer device context."; |
315 Destroy(); | 305 Destroy(); |
(...skipping 26 matching lines...) Expand all Loading... |
342 | 332 |
343 gfx::Size PbufferGLSurfaceWGL::GetSize() { | 333 gfx::Size PbufferGLSurfaceWGL::GetSize() { |
344 return size_; | 334 return size_; |
345 } | 335 } |
346 | 336 |
347 void* PbufferGLSurfaceWGL::GetHandle() { | 337 void* PbufferGLSurfaceWGL::GetHandle() { |
348 return device_context_; | 338 return device_context_; |
349 } | 339 } |
350 | 340 |
351 } // namespace gfx | 341 } // namespace gfx |
OLD | NEW |