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

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

Issue 653883004: Create child window using WS_EX_NOPARENTNOTIFY 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 intermediate_class.hCursor = LoadCursor(NULL, IDC_ARROW); 92 intermediate_class.hCursor = LoadCursor(NULL, IDC_ARROW);
93 intermediate_class.hbrBackground = NULL; 93 intermediate_class.hbrBackground = NULL;
94 intermediate_class.lpszMenuName = NULL; 94 intermediate_class.lpszMenuName = NULL;
95 intermediate_class.lpszClassName = L"Intermediate GL Window"; 95 intermediate_class.lpszClassName = L"Intermediate GL Window";
96 window_class_ = RegisterClass(&intermediate_class); 96 window_class_ = RegisterClass(&intermediate_class);
97 if (!window_class_) { 97 if (!window_class_) {
98 LOG(ERROR) << "RegisterClass failed."; 98 LOG(ERROR) << "RegisterClass failed.";
99 return false; 99 return false;
100 } 100 }
101 101
102 window_handle_ = CreateWindow( 102 window_handle_ = CreateWindowEx(WS_EX_NOPARENTNOTIFY,
Ken Russell (switch to Gerrit) 2014/10/16 00:58:47 Is WS_EX_NOPARENTNOTIFY strictly needed for this w
103 reinterpret_cast<wchar_t*>(window_class_), 103 reinterpret_cast<wchar_t*>(window_class_),
104 L"", 104 L"",
105 WS_OVERLAPPEDWINDOW, 105 WS_OVERLAPPEDWINDOW,
106 0, 0, 106 0,
107 100, 100, 107 0,
108 NULL, 108 100,
109 NULL, 109 100,
110 NULL, 110 NULL,
111 NULL); 111 NULL,
112 NULL,
113 NULL);
112 if (!window_handle_) { 114 if (!window_handle_) {
113 LOG(ERROR) << "CreateWindow failed."; 115 LOG(ERROR) << "CreateWindow failed.";
114 return false; 116 return false;
115 } 117 }
116 118
117 device_context_ = GetDC(window_handle_); 119 device_context_ = GetDC(window_handle_);
118 pixel_format_ = ChoosePixelFormat(device_context_, 120 pixel_format_ = ChoosePixelFormat(device_context_,
119 &kPixelFormatDescriptor); 121 &kPixelFormatDescriptor);
120 if (pixel_format_ == 0) { 122 if (pixel_format_ == 0) {
121 LOG(ERROR) << "Unable to get the pixel format for GL context."; 123 LOG(ERROR) << "Unable to get the pixel format for GL context.";
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 g_display = wgl_display.release(); 170 g_display = wgl_display.release();
169 initialized = true; 171 initialized = true;
170 return true; 172 return true;
171 } 173 }
172 174
173 HDC GLSurfaceWGL::GetDisplayDC() { 175 HDC GLSurfaceWGL::GetDisplayDC() {
174 return g_display->device_context(); 176 return g_display->device_context();
175 } 177 }
176 178
177 NativeViewGLSurfaceWGL::NativeViewGLSurfaceWGL(gfx::AcceleratedWidget window) 179 NativeViewGLSurfaceWGL::NativeViewGLSurfaceWGL(gfx::AcceleratedWidget window)
178 : window_(window), 180 : window_(window), child_window_(NULL), device_context_(NULL) {
179 device_context_(NULL) {
180 DCHECK(window); 181 DCHECK(window);
181 } 182 }
182 183
183 NativeViewGLSurfaceWGL::~NativeViewGLSurfaceWGL() { 184 NativeViewGLSurfaceWGL::~NativeViewGLSurfaceWGL() {
184 Destroy(); 185 Destroy();
185 } 186 }
186 187
187 bool NativeViewGLSurfaceWGL::Initialize() { 188 bool NativeViewGLSurfaceWGL::Initialize() {
188 DCHECK(!device_context_); 189 DCHECK(!device_context_);
189 190
190 DWORD process_id; 191 RECT rect;
191 GetWindowThreadProcessId(window_, &process_id); 192 if (!GetClientRect(window_, &rect)) {
192 if (process_id != GetCurrentProcessId()) { 193 LOG(ERROR) << "GetClientRect failed.\n";
193 LOG(ERROR) << "Can't use window created in " << process_id
194 << " with wgl in " << GetCurrentProcessId();
195 Destroy(); 194 Destroy();
196 return false; 195 return false;
197 } 196 }
198 197
199 device_context_ = GetDC(window_); 198 // Create a child window. WGL has problems using a window handle owned by
199 // another process.
200 child_window_ =
201 CreateWindowEx(WS_EX_NOPARENTNOTIFY,
202 reinterpret_cast<wchar_t*>(g_display->window_class()),
203 L"",
204 WS_CHILDWINDOW | WS_DISABLED | WS_VISIBLE,
205 0,
206 0,
207 rect.right - rect.left,
208 rect.bottom - rect.top,
209 window_,
210 NULL,
211 NULL,
212 NULL);
213 if (!child_window_) {
214 LOG(ERROR) << "CreateWindow failed.\n";
215 Destroy();
216 return false;
217 }
218
219 // The GL context will render to this window.
220 device_context_ = GetDC(child_window_);
200 if (!device_context_) { 221 if (!device_context_) {
201 LOG(ERROR) << "Unable to get device context for window."; 222 LOG(ERROR) << "Unable to get device context for window.";
202 Destroy(); 223 Destroy();
203 return false; 224 return false;
204 } 225 }
205 226
206 if (!SetPixelFormat(device_context_, 227 if (!SetPixelFormat(device_context_,
207 g_display->pixel_format(), 228 g_display->pixel_format(),
208 &kPixelFormatDescriptor)) { 229 &kPixelFormatDescriptor)) {
209 LOG(ERROR) << "Unable to set the pixel format for GL context."; 230 LOG(ERROR) << "Unable to set the pixel format for GL context.";
210 Destroy(); 231 Destroy();
211 return false; 232 return false;
212 } 233 }
213 234
214 return true; 235 return true;
215 } 236 }
216 237
217 void NativeViewGLSurfaceWGL::Destroy() { 238 void NativeViewGLSurfaceWGL::Destroy() {
218 if (window_ && device_context_) 239 if (child_window_ && device_context_)
219 ReleaseDC(window_, device_context_); 240 ReleaseDC(child_window_, device_context_);
220 241
242 if (child_window_)
243 DestroyWindow(child_window_);
244
245 child_window_ = NULL;
221 device_context_ = NULL; 246 device_context_ = NULL;
222 } 247 }
223 248
224 bool NativeViewGLSurfaceWGL::IsOffscreen() { 249 bool NativeViewGLSurfaceWGL::IsOffscreen() {
225 return false; 250 return false;
226 } 251 }
227 252
228 bool NativeViewGLSurfaceWGL::SwapBuffers() { 253 bool NativeViewGLSurfaceWGL::SwapBuffers() {
229 TRACE_EVENT2("gpu", "NativeViewGLSurfaceWGL:RealSwapBuffers", 254 TRACE_EVENT2("gpu", "NativeViewGLSurfaceWGL:RealSwapBuffers",
230 "width", GetSize().width(), 255 "width", GetSize().width(),
231 "height", GetSize().height()); 256 "height", GetSize().height());
232 257
258 // Resize the child window to match the parent before swapping. Do not repaint
259 // it as it moves.
260 RECT rect;
261 if (!GetClientRect(window_, &rect))
262 return false;
263 if (!MoveWindow(child_window_,
264 0,
265 0,
266 rect.right - rect.left,
267 rect.bottom - rect.top,
268 FALSE)) {
269 return false;
270 }
271
233 DCHECK(device_context_); 272 DCHECK(device_context_);
234 return ::SwapBuffers(device_context_) == TRUE; 273 return ::SwapBuffers(device_context_) == TRUE;
235 } 274 }
236 275
237 gfx::Size NativeViewGLSurfaceWGL::GetSize() { 276 gfx::Size NativeViewGLSurfaceWGL::GetSize() {
238 RECT rect; 277 RECT rect;
239 BOOL result = GetClientRect(window_, &rect); 278 BOOL result = GetClientRect(child_window_, &rect);
240 DCHECK(result); 279 DCHECK(result);
241 return gfx::Size(rect.right - rect.left, rect.bottom - rect.top); 280 return gfx::Size(rect.right - rect.left, rect.bottom - rect.top);
242 } 281 }
243 282
244 void* NativeViewGLSurfaceWGL::GetHandle() { 283 void* NativeViewGLSurfaceWGL::GetHandle() {
245 return device_context_; 284 return device_context_;
246 } 285 }
247 286
248 PbufferGLSurfaceWGL::PbufferGLSurfaceWGL(const gfx::Size& size) 287 PbufferGLSurfaceWGL::PbufferGLSurfaceWGL(const gfx::Size& size)
249 : size_(size), 288 : size_(size),
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 352
314 gfx::Size PbufferGLSurfaceWGL::GetSize() { 353 gfx::Size PbufferGLSurfaceWGL::GetSize() {
315 return size_; 354 return size_;
316 } 355 }
317 356
318 void* PbufferGLSurfaceWGL::GetHandle() { 357 void* PbufferGLSurfaceWGL::GetHandle() {
319 return device_context_; 358 return device_context_;
320 } 359 }
321 360
322 } // namespace gfx 361 } // 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