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

Side by Side Diff: ui/gl/gl_surface_wgl.cc

Issue 649863002: Don't create child window for WGL. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 unified diff | Download patch
« no previous file with comments | « ui/gl/gl_surface_wgl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "ui/gl/gl_bindings.h" 10 #include "ui/gl/gl_bindings.h"
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 initialized = true; 169 initialized = true;
170 return true; 170 return true;
171 } 171 }
172 172
173 HDC GLSurfaceWGL::GetDisplayDC() { 173 HDC GLSurfaceWGL::GetDisplayDC() {
174 return g_display->device_context(); 174 return g_display->device_context();
175 } 175 }
176 176
177 NativeViewGLSurfaceWGL::NativeViewGLSurfaceWGL(gfx::AcceleratedWidget window) 177 NativeViewGLSurfaceWGL::NativeViewGLSurfaceWGL(gfx::AcceleratedWidget window)
178 : window_(window), 178 : window_(window),
179 child_window_(NULL),
180 device_context_(NULL) { 179 device_context_(NULL) {
181 DCHECK(window); 180 DCHECK(window);
182 } 181 }
183 182
184 NativeViewGLSurfaceWGL::~NativeViewGLSurfaceWGL() { 183 NativeViewGLSurfaceWGL::~NativeViewGLSurfaceWGL() {
185 Destroy(); 184 Destroy();
186 } 185 }
187 186
188 bool NativeViewGLSurfaceWGL::Initialize() { 187 bool NativeViewGLSurfaceWGL::Initialize() {
189 DCHECK(!device_context_); 188 DCHECK(!device_context_);
190 189
191 RECT rect; 190 DWORD process_id;
192 if (!GetClientRect(window_, &rect)) { 191 GetWindowThreadProcessId(window_, &process_id);
193 LOG(ERROR) << "GetClientRect failed.\n"; 192 if (process_id != GetCurrentProcessId()) {
193 LOG(ERROR) << "Can't use window created in " << process_id
194 << " with wgl in " << GetCurrentProcessId();
194 Destroy(); 195 Destroy();
195 return false; 196 return false;
196 } 197 }
197 198
198 // Create a child window. WGL has problems using a window handle owned by 199 device_context_ = GetDC(window_);
199 // another process.
200 child_window_ = CreateWindow(
201 reinterpret_cast<wchar_t*>(g_display->window_class()),
202 L"",
203 WS_CHILDWINDOW | WS_DISABLED | WS_VISIBLE,
204 0, 0,
205 rect.right - rect.left,
206 rect.bottom - rect.top,
207 window_,
208 NULL,
209 NULL,
210 NULL);
211 if (!child_window_) {
212 LOG(ERROR) << "CreateWindow failed.\n";
213 Destroy();
214 return false;
215 }
216
217 // The GL context will render to this window.
218 device_context_ = GetDC(child_window_);
219 if (!device_context_) { 200 if (!device_context_) {
220 LOG(ERROR) << "Unable to get device context for window."; 201 LOG(ERROR) << "Unable to get device context for window.";
221 Destroy(); 202 Destroy();
222 return false; 203 return false;
223 } 204 }
224 205
225 if (!SetPixelFormat(device_context_, 206 if (!SetPixelFormat(device_context_,
226 g_display->pixel_format(), 207 g_display->pixel_format(),
227 &kPixelFormatDescriptor)) { 208 &kPixelFormatDescriptor)) {
228 LOG(ERROR) << "Unable to set the pixel format for GL context."; 209 LOG(ERROR) << "Unable to set the pixel format for GL context.";
229 Destroy(); 210 Destroy();
230 return false; 211 return false;
231 } 212 }
232 213
233 return true; 214 return true;
234 } 215 }
235 216
236 void NativeViewGLSurfaceWGL::Destroy() { 217 void NativeViewGLSurfaceWGL::Destroy() {
237 if (child_window_ && device_context_) 218 if (window_ && device_context_)
238 ReleaseDC(child_window_, device_context_); 219 ReleaseDC(window_, device_context_);
239 220
240 if (child_window_)
241 DestroyWindow(child_window_);
242
243 child_window_ = NULL;
244 device_context_ = NULL; 221 device_context_ = NULL;
245 } 222 }
246 223
247 bool NativeViewGLSurfaceWGL::IsOffscreen() { 224 bool NativeViewGLSurfaceWGL::IsOffscreen() {
248 return false; 225 return false;
249 } 226 }
250 227
251 bool NativeViewGLSurfaceWGL::SwapBuffers() { 228 bool NativeViewGLSurfaceWGL::SwapBuffers() {
252 TRACE_EVENT2("gpu", "NativeViewGLSurfaceWGL:RealSwapBuffers", 229 TRACE_EVENT2("gpu", "NativeViewGLSurfaceWGL:RealSwapBuffers",
253 "width", GetSize().width(), 230 "width", GetSize().width(),
254 "height", GetSize().height()); 231 "height", GetSize().height());
255 232
256 // Resize the child window to match the parent before swapping. Do not repaint
257 // it as it moves.
258 RECT rect;
259 if (!GetClientRect(window_, &rect))
260 return false;
261 if (!MoveWindow(child_window_,
262 0, 0,
263 rect.right - rect.left,
264 rect.bottom - rect.top,
265 FALSE)) {
266 return false;
267 }
268
269 DCHECK(device_context_); 233 DCHECK(device_context_);
270 return ::SwapBuffers(device_context_) == TRUE; 234 return ::SwapBuffers(device_context_) == TRUE;
271 } 235 }
272 236
273 gfx::Size NativeViewGLSurfaceWGL::GetSize() { 237 gfx::Size NativeViewGLSurfaceWGL::GetSize() {
274 RECT rect; 238 RECT rect;
275 BOOL result = GetClientRect(child_window_, &rect); 239 BOOL result = GetClientRect(window_, &rect);
276 DCHECK(result); 240 DCHECK(result);
277 return gfx::Size(rect.right - rect.left, rect.bottom - rect.top); 241 return gfx::Size(rect.right - rect.left, rect.bottom - rect.top);
278 } 242 }
279 243
280 void* NativeViewGLSurfaceWGL::GetHandle() { 244 void* NativeViewGLSurfaceWGL::GetHandle() {
281 return device_context_; 245 return device_context_;
282 } 246 }
283 247
284 PbufferGLSurfaceWGL::PbufferGLSurfaceWGL(const gfx::Size& size) 248 PbufferGLSurfaceWGL::PbufferGLSurfaceWGL(const gfx::Size& size)
285 : size_(size), 249 : size_(size),
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 313
350 gfx::Size PbufferGLSurfaceWGL::GetSize() { 314 gfx::Size PbufferGLSurfaceWGL::GetSize() {
351 return size_; 315 return size_;
352 } 316 }
353 317
354 void* PbufferGLSurfaceWGL::GetHandle() { 318 void* PbufferGLSurfaceWGL::GetHandle() {
355 return device_context_; 319 return device_context_;
356 } 320 }
357 321
358 } // namespace gfx 322 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gl/gl_surface_wgl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698