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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gl/gl_surface_wgl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gl/gl_surface_wgl.cc
diff --git a/ui/gl/gl_surface_wgl.cc b/ui/gl/gl_surface_wgl.cc
index 690f4f42f18fecb4706460df32388c66edf55bba..66cef266fcf09895c051a5ed2013b8f2db6a796c 100644
--- a/ui/gl/gl_surface_wgl.cc
+++ b/ui/gl/gl_surface_wgl.cc
@@ -99,16 +99,18 @@ class DisplayWGL {
return false;
}
- window_handle_ = CreateWindow(
- reinterpret_cast<wchar_t*>(window_class_),
- L"",
- WS_OVERLAPPEDWINDOW,
- 0, 0,
- 100, 100,
- NULL,
- NULL,
- NULL,
- NULL);
+ 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
+ reinterpret_cast<wchar_t*>(window_class_),
+ L"",
+ WS_OVERLAPPEDWINDOW,
+ 0,
+ 0,
+ 100,
+ 100,
+ NULL,
+ NULL,
+ NULL,
+ NULL);
if (!window_handle_) {
LOG(ERROR) << "CreateWindow failed.";
return false;
@@ -175,8 +177,7 @@ HDC GLSurfaceWGL::GetDisplayDC() {
}
NativeViewGLSurfaceWGL::NativeViewGLSurfaceWGL(gfx::AcceleratedWidget window)
- : window_(window),
- device_context_(NULL) {
+ : window_(window), child_window_(NULL), device_context_(NULL) {
DCHECK(window);
}
@@ -187,16 +188,36 @@ NativeViewGLSurfaceWGL::~NativeViewGLSurfaceWGL() {
bool NativeViewGLSurfaceWGL::Initialize() {
DCHECK(!device_context_);
- DWORD process_id;
- GetWindowThreadProcessId(window_, &process_id);
- if (process_id != GetCurrentProcessId()) {
- LOG(ERROR) << "Can't use window created in " << process_id
- << " with wgl in " << GetCurrentProcessId();
+ RECT rect;
+ if (!GetClientRect(window_, &rect)) {
+ LOG(ERROR) << "GetClientRect failed.\n";
+ Destroy();
+ return false;
+ }
+
+ // Create a child window. WGL has problems using a window handle owned by
+ // another process.
+ child_window_ =
+ CreateWindowEx(WS_EX_NOPARENTNOTIFY,
+ reinterpret_cast<wchar_t*>(g_display->window_class()),
+ L"",
+ WS_CHILDWINDOW | WS_DISABLED | WS_VISIBLE,
+ 0,
+ 0,
+ rect.right - rect.left,
+ rect.bottom - rect.top,
+ window_,
+ NULL,
+ NULL,
+ NULL);
+ if (!child_window_) {
+ LOG(ERROR) << "CreateWindow failed.\n";
Destroy();
return false;
}
- device_context_ = GetDC(window_);
+ // The GL context will render to this window.
+ device_context_ = GetDC(child_window_);
if (!device_context_) {
LOG(ERROR) << "Unable to get device context for window.";
Destroy();
@@ -215,9 +236,13 @@ bool NativeViewGLSurfaceWGL::Initialize() {
}
void NativeViewGLSurfaceWGL::Destroy() {
- if (window_ && device_context_)
- ReleaseDC(window_, device_context_);
+ if (child_window_ && device_context_)
+ ReleaseDC(child_window_, device_context_);
+
+ if (child_window_)
+ DestroyWindow(child_window_);
+ child_window_ = NULL;
device_context_ = NULL;
}
@@ -230,13 +255,27 @@ bool NativeViewGLSurfaceWGL::SwapBuffers() {
"width", GetSize().width(),
"height", GetSize().height());
+ // Resize the child window to match the parent before swapping. Do not repaint
+ // it as it moves.
+ RECT rect;
+ if (!GetClientRect(window_, &rect))
+ return false;
+ if (!MoveWindow(child_window_,
+ 0,
+ 0,
+ rect.right - rect.left,
+ rect.bottom - rect.top,
+ FALSE)) {
+ return false;
+ }
+
DCHECK(device_context_);
return ::SwapBuffers(device_context_) == TRUE;
}
gfx::Size NativeViewGLSurfaceWGL::GetSize() {
RECT rect;
- BOOL result = GetClientRect(window_, &rect);
+ BOOL result = GetClientRect(child_window_, &rect);
DCHECK(result);
return gfx::Size(rect.right - rect.left, rect.bottom - rect.top);
}
« 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