Commit 9e16d40d by Jamie Madill

Fix Win32Window::resize breaking angle_tests.

We were messing up the client rect on resize, which caused the ReadPixels checks to mess up around the window edges. Disabling the window styles on the test windows masked this bug. Fix this by using a style-less child window inside the parent window. This gives us access to window styles for the samples project, along with the ability to use tiny 1x1 windows for testing. BUG=angle:730 Change-Id: Ic6dd931df7b4e32fbbcacbb004d3bbc49917f658 Reviewed-on: https://chromium-review.googlesource.com/217024Tested-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent dd8488d3
...@@ -22,6 +22,8 @@ void ANGLETest::SetUp() ...@@ -22,6 +22,8 @@ void ANGLETest::SetUp()
void ANGLETest::TearDown() void ANGLETest::TearDown()
{ {
swapBuffers(); swapBuffers();
mOSWindow->messageLoop();
if (!destroyEGLContext()) if (!destroyEGLContext())
{ {
FAIL() << "egl context destruction failed."; FAIL() << "egl context destruction failed.";
......
...@@ -31,7 +31,7 @@ class OSWindow ...@@ -31,7 +31,7 @@ class OSWindow
virtual void messageLoop() = 0; virtual void messageLoop() = 0;
bool popEvent(Event *event); bool popEvent(Event *event);
void pushEvent(Event event); virtual void pushEvent(Event event);
virtual void setMousePosition(int x, int y) = 0; virtual void setMousePosition(int x, int y) = 0;
virtual bool resize(int width, int height) = 0; virtual bool resize(int width, int height) = 0;
......
...@@ -362,8 +362,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) ...@@ -362,8 +362,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
} }
Win32Window::Win32Window() Win32Window::Win32Window()
: mClassName(), : mNativeWindow(0),
mNativeWindow(0), mParentWindow(0),
mNativeDisplay(0) mNativeDisplay(0)
{ {
} }
...@@ -377,36 +377,55 @@ bool Win32Window::initialize(const std::string &name, size_t width, size_t heigh ...@@ -377,36 +377,55 @@ bool Win32Window::initialize(const std::string &name, size_t width, size_t heigh
{ {
destroy(); destroy();
mClassName = name; mParentClassName = name;
mChildClassName = name + "Child";
WNDCLASSEXA windowClass = { 0 };
windowClass.cbSize = sizeof(WNDCLASSEXA); WNDCLASSEXA parentWindowClass = { 0 };
windowClass.style = CS_OWNDC; parentWindowClass.cbSize = sizeof(WNDCLASSEXA);
windowClass.lpfnWndProc = WndProc; parentWindowClass.style = 0;
windowClass.cbClsExtra = 0; parentWindowClass.lpfnWndProc = WndProc;
windowClass.cbWndExtra = 0; parentWindowClass.cbClsExtra = 0;
windowClass.hInstance = GetModuleHandle(NULL); parentWindowClass.cbWndExtra = 0;
windowClass.hIcon = NULL; parentWindowClass.hInstance = GetModuleHandle(NULL);
windowClass.hCursor = LoadCursorA(NULL, IDC_ARROW); parentWindowClass.hIcon = NULL;
windowClass.hbrBackground = 0; parentWindowClass.hCursor = LoadCursorA(NULL, IDC_ARROW);
windowClass.lpszMenuName = NULL; parentWindowClass.hbrBackground = 0;
windowClass.lpszClassName = mClassName.c_str(); parentWindowClass.lpszMenuName = NULL;
if (!RegisterClassExA(&windowClass)) parentWindowClass.lpszClassName = mParentClassName.c_str();
if (!RegisterClassExA(&parentWindowClass))
{ {
return false; return false;
} }
DWORD style = WS_VISIBLE | WS_CAPTION | WS_MINIMIZEBOX | WS_THICKFRAME | WS_MAXIMIZEBOX | WS_SYSMENU; WNDCLASSEXA childWindowClass = { 0 };
DWORD extendedStyle = WS_EX_APPWINDOW; childWindowClass.cbSize = sizeof(WNDCLASSEXA);
childWindowClass.style = CS_OWNDC;
childWindowClass.lpfnWndProc = WndProc;
childWindowClass.cbClsExtra = 0;
childWindowClass.cbWndExtra = 0;
childWindowClass.hInstance = GetModuleHandle(NULL);
childWindowClass.hIcon = NULL;
childWindowClass.hCursor = LoadCursorA(NULL, IDC_ARROW);
childWindowClass.hbrBackground = 0;
childWindowClass.lpszMenuName = NULL;
childWindowClass.lpszClassName = mChildClassName.c_str();
if (!RegisterClassExA(&childWindowClass))
{
return false;
}
DWORD parentStyle = WS_VISIBLE | WS_CAPTION | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SYSMENU;
DWORD parentExtendedStyle = WS_EX_APPWINDOW;
RECT sizeRect = { 0, 0, width, height }; RECT sizeRect = { 0, 0, width, height };
AdjustWindowRectEx(&sizeRect, style, false, extendedStyle); AdjustWindowRectEx(&sizeRect, parentStyle, FALSE, parentExtendedStyle);
mNativeWindow = CreateWindowExA(extendedStyle, mClassName.c_str(), name.c_str(), style, CW_USEDEFAULT, CW_USEDEFAULT, mParentWindow = CreateWindowExA(parentExtendedStyle, mParentClassName.c_str(), name.c_str(), parentStyle, CW_USEDEFAULT, CW_USEDEFAULT,
sizeRect.right - sizeRect.left, sizeRect.bottom - sizeRect.top, NULL, NULL, sizeRect.right - sizeRect.left, sizeRect.bottom - sizeRect.top, NULL, NULL,
GetModuleHandle(NULL), this); GetModuleHandle(NULL), this);
ShowWindow(mNativeWindow, SW_SHOW); mNativeWindow = CreateWindowExA(0, mChildClassName.c_str(), name.c_str(), WS_VISIBLE | WS_CHILD, 0, 0, width, height,
mParentWindow, NULL, GetModuleHandle(NULL), this);
mNativeDisplay = GetDC(mNativeWindow); mNativeDisplay = GetDC(mNativeWindow);
if (!mNativeDisplay) if (!mNativeDisplay)
...@@ -432,7 +451,14 @@ void Win32Window::destroy() ...@@ -432,7 +451,14 @@ void Win32Window::destroy()
mNativeWindow = 0; mNativeWindow = 0;
} }
UnregisterClassA(mClassName.c_str(), NULL); if (mParentWindow)
{
DestroyWindow(mParentWindow);
mParentWindow = 0;
}
UnregisterClassA(mParentClassName.c_str(), NULL);
UnregisterClassA(mChildClassName.c_str(), NULL);
} }
EGLNativeWindowType Win32Window::getNativeWindow() const EGLNativeWindowType Win32Window::getNativeWindow() const
...@@ -475,24 +501,54 @@ OSWindow *CreateOSWindow() ...@@ -475,24 +501,54 @@ OSWindow *CreateOSWindow()
bool Win32Window::resize(int width, int height) bool Win32Window::resize(int width, int height)
{ {
if (width == mWidth && height == mHeight)
{
return true;
}
RECT windowRect; RECT windowRect;
if (!GetWindowRect(mNativeWindow, &windowRect)) if (!GetWindowRect(mParentWindow, &windowRect))
{
return false;
}
RECT clientRect;
if (!GetClientRect(mParentWindow, &clientRect))
{ {
return false; return false;
} }
if (!MoveWindow(mNativeWindow, windowRect.left, windowRect.top, width, height, FALSE)) LONG diffX = (windowRect.right - windowRect.left) - clientRect.right;
LONG diffY = (windowRect.bottom - windowRect.top) - clientRect.bottom;
if (!MoveWindow(mParentWindow, windowRect.left, windowRect.top, width + diffX, height + diffY, FALSE))
{ {
return false; return false;
} }
mWidth = width; if (!MoveWindow(mNativeWindow, 0, 0, width, height, FALSE))
mHeight = height; {
return false;
}
return true; return true;
} }
bool Win32Window::setVisible(bool isVisible) bool Win32Window::setVisible(bool isVisible)
{ {
return (ShowWindow(mNativeWindow, isVisible ? SW_SHOW : SW_HIDE) == TRUE); int flag = (isVisible ? SW_SHOW : SW_HIDE);
return (ShowWindow(mNativeWindow, flag) == TRUE) &&
(ShowWindow(mParentWindow, flag) == TRUE);
}
void Win32Window::pushEvent(Event event)
{
OSWindow::pushEvent(event);
switch (event.Type)
{
case Event::EVENT_RESIZED:
MoveWindow(mNativeWindow, 0, 0, mWidth, mHeight, FALSE);
break;
}
} }
...@@ -25,17 +25,18 @@ class Win32Window : public OSWindow ...@@ -25,17 +25,18 @@ class Win32Window : public OSWindow
void messageLoop(); void messageLoop();
bool popEvent(Event *event); virtual void pushEvent(Event event);
void pushEvent(Event event);
void setMousePosition(int x, int y); void setMousePosition(int x, int y);
bool resize(int width, int height); bool resize(int width, int height);
bool setVisible(bool isVisible); bool setVisible(bool isVisible);
private: private:
std::string mClassName; std::string mParentClassName;
std::string mChildClassName;
EGLNativeWindowType mNativeWindow; EGLNativeWindowType mNativeWindow;
EGLNativeWindowType mParentWindow;
EGLNativeDisplayType mNativeDisplay; EGLNativeDisplayType mNativeDisplay;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment