summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorapatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-12 21:01:40 +0000
committerapatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-12 21:01:40 +0000
commit02dbea79131f7f54212eb02ee91bf2953924bec1 (patch)
treef56c1f2477aaff07499b728c157de39116762603 /ui
parent6cfabd8daaf8cea08ba46b005571d2cc05d350bb (diff)
downloadchromium_src-02dbea79131f7f54212eb02ee91bf2953924bec1.zip
chromium_src-02dbea79131f7f54212eb02ee91bf2953924bec1.tar.gz
chromium_src-02dbea79131f7f54212eb02ee91bf2953924bec1.tar.bz2
Partially fix WGL backend on windows.
It should render on all windows boxes with working GL. The GPU process creates a child window to render to again, but only if desktop GL has been enabled. The child window is not created by default so there should not be issues with deadlocks. Resizing flickers for some reason. TEST=WebGL works, trybots. BUG=none Review URL: http://codereview.chromium.org/6991002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85181 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/gfx/gl/gl_surface_wgl.cc88
-rw-r--r--ui/gfx/gl/gl_surface_wgl.h1
2 files changed, 72 insertions, 17 deletions
diff --git a/ui/gfx/gl/gl_surface_wgl.cc b/ui/gfx/gl/gl_surface_wgl.cc
index 0218266..73ff12e 100644
--- a/ui/gfx/gl/gl_surface_wgl.cc
+++ b/ui/gfx/gl/gl_surface_wgl.cc
@@ -10,6 +10,7 @@
namespace gfx {
+static ATOM g_class_registration;
static HWND g_window;
static int g_pixel_format = 0;
@@ -37,7 +38,19 @@ static LRESULT CALLBACK IntermediateWindowProc(HWND window,
UINT message,
WPARAM w_param,
LPARAM l_param) {
- return ::DefWindowProc(window, message, w_param, l_param);
+ switch (message) {
+ case WM_ERASEBKGND:
+ // Prevent windows from erasing the background.
+ return 1;
+ case WM_PAINT:
+ // Do not paint anything.
+ PAINTSTRUCT paint;
+ if (BeginPaint(window, &paint))
+ EndPaint(window, &paint);
+ return 0;
+ default:
+ return DefWindowProc(window, message, w_param, l_param);
+ }
}
GLSurfaceWGL::GLSurfaceWGL() {
@@ -63,7 +76,7 @@ bool GLSurfaceWGL::InitializeOneOff() {
}
WNDCLASS intermediate_class;
- intermediate_class.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
+ intermediate_class.style = CS_OWNDC;
intermediate_class.lpfnWndProc = IntermediateWindowProc;
intermediate_class.cbClsExtra = 0;
intermediate_class.cbWndExtra = 0;
@@ -74,14 +87,14 @@ bool GLSurfaceWGL::InitializeOneOff() {
intermediate_class.lpszMenuName = NULL;
intermediate_class.lpszClassName = L"Intermediate GL Window";
- ATOM class_registration = ::RegisterClass(&intermediate_class);
- if (!class_registration) {
+ g_class_registration = ::RegisterClass(&intermediate_class);
+ if (!g_class_registration) {
LOG(ERROR) << "RegisterClass failed.";
return false;
}
g_window = CreateWindow(
- reinterpret_cast<wchar_t*>(class_registration),
+ reinterpret_cast<wchar_t*>(g_class_registration),
L"",
WS_OVERLAPPEDWINDOW,
0, 0,
@@ -92,7 +105,7 @@ bool GLSurfaceWGL::InitializeOneOff() {
NULL);
if (!g_window) {
- UnregisterClass(reinterpret_cast<wchar_t*>(class_registration),
+ UnregisterClass(reinterpret_cast<wchar_t*>(g_class_registration),
module_handle);
LOG(ERROR) << "CreateWindow failed.";
return false;
@@ -106,7 +119,7 @@ bool GLSurfaceWGL::InitializeOneOff() {
if (g_pixel_format == 0) {
LOG(ERROR) << "Unable to get the pixel format for GL context.";
ReleaseDC(g_window, temporary_dc);
- UnregisterClass(reinterpret_cast<wchar_t*>(class_registration),
+ UnregisterClass(reinterpret_cast<wchar_t*>(g_class_registration),
module_handle);
return false;
}
@@ -116,7 +129,7 @@ bool GLSurfaceWGL::InitializeOneOff() {
&kPixelFormatDescriptor)) {
LOG(ERROR) << "Unable to set the pixel format for temporary GL context.";
ReleaseDC(g_window, temporary_dc);
- UnregisterClass(reinterpret_cast<wchar_t*>(class_registration),
+ UnregisterClass(reinterpret_cast<wchar_t*>(g_class_registration),
module_handle);
return false;
}
@@ -126,7 +139,7 @@ bool GLSurfaceWGL::InitializeOneOff() {
if (!gl_context) {
LOG(ERROR) << "Failed to create temporary context.";
ReleaseDC(g_window, temporary_dc);
- UnregisterClass(reinterpret_cast<wchar_t*>(class_registration),
+ UnregisterClass(reinterpret_cast<wchar_t*>(g_class_registration),
module_handle);
return false;
}
@@ -135,7 +148,7 @@ bool GLSurfaceWGL::InitializeOneOff() {
LOG(ERROR) << "Failed to make temporary GL context current.";
wglDeleteContext(gl_context);
ReleaseDC(g_window, temporary_dc);
- UnregisterClass(reinterpret_cast<wchar_t*>(class_registration),
+ UnregisterClass(reinterpret_cast<wchar_t*>(g_class_registration),
module_handle);
return false;
}
@@ -148,8 +161,6 @@ bool GLSurfaceWGL::InitializeOneOff() {
wglMakeCurrent(NULL, NULL);
wglDeleteContext(gl_context);
ReleaseDC(g_window, temporary_dc);
- UnregisterClass(reinterpret_cast<wchar_t*>(class_registration),
- module_handle);
initialized = true;
return true;
@@ -157,6 +168,7 @@ bool GLSurfaceWGL::InitializeOneOff() {
NativeViewGLSurfaceWGL::NativeViewGLSurfaceWGL(gfx::PluginWindowHandle window)
: window_(window),
+ child_window_(NULL),
device_context_(NULL) {
DCHECK(window);
}
@@ -168,8 +180,34 @@ NativeViewGLSurfaceWGL::~NativeViewGLSurfaceWGL() {
bool NativeViewGLSurfaceWGL::Initialize() {
DCHECK(!device_context_);
+ 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_ = CreateWindow(
+ reinterpret_cast<wchar_t*>(g_class_registration),
+ 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;
+ }
+
// The GL context will render to this window.
- device_context_ = GetDC(window_);
+ device_context_ = GetDC(child_window_);
if (!device_context_) {
LOG(ERROR) << "Unable to get device context for window.";
Destroy();
@@ -188,10 +226,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_);
- window_ = NULL;
+ child_window_ = NULL;
device_context_ = NULL;
}
@@ -200,13 +241,26 @@ bool NativeViewGLSurfaceWGL::IsOffscreen() {
}
bool NativeViewGLSurfaceWGL::SwapBuffers() {
+ // 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;
- DCHECK(GetClientRect(window_, &rect));
+ DCHECK(GetClientRect(child_window_, &rect));
return gfx::Size(rect.right - rect.left, rect.bottom - rect.top);
}
diff --git a/ui/gfx/gl/gl_surface_wgl.h b/ui/gfx/gl/gl_surface_wgl.h
index b768655..1684fdb 100644
--- a/ui/gfx/gl/gl_surface_wgl.h
+++ b/ui/gfx/gl/gl_surface_wgl.h
@@ -37,6 +37,7 @@ class NativeViewGLSurfaceWGL : public GLSurfaceWGL {
private:
gfx::PluginWindowHandle window_;
+ gfx::PluginWindowHandle child_window_;
HDC device_context_;
DISALLOW_COPY_AND_ASSIGN(NativeViewGLSurfaceWGL);