Commit d3b84ab5 by Geoff Lang

Don't subclass windows in SurfaceD3D.

The subclassing was not used by chromium and caused problems for users that wanted to use a window owned by another thread as an EGL surface. BUG=angleproject:961 Change-Id: I1d91323c758374de317179874320961385b10ae0 Reviewed-on: https://chromium-review.googlesource.com/266658Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarJohn Bauman <jbauman@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent b7f1a8b0
...@@ -43,7 +43,6 @@ SurfaceD3D::SurfaceD3D(RendererD3D *renderer, egl::Display *display, const egl:: ...@@ -43,7 +43,6 @@ SurfaceD3D::SurfaceD3D(RendererD3D *renderer, egl::Display *display, const egl::
mDepthStencilFormat(config->depthStencilFormat), mDepthStencilFormat(config->depthStencilFormat),
mSwapChain(nullptr), mSwapChain(nullptr),
mSwapIntervalDirty(true), mSwapIntervalDirty(true),
mWindowSubclassed(false),
mNativeWindow(window), mNativeWindow(window),
mWidth(width), mWidth(width),
mHeight(height), mHeight(height),
...@@ -51,12 +50,10 @@ SurfaceD3D::SurfaceD3D(RendererD3D *renderer, egl::Display *display, const egl:: ...@@ -51,12 +50,10 @@ SurfaceD3D::SurfaceD3D(RendererD3D *renderer, egl::Display *display, const egl::
mSwapInterval(1), mSwapInterval(1),
mShareHandle(reinterpret_cast<HANDLE*>(shareHandle)) mShareHandle(reinterpret_cast<HANDLE*>(shareHandle))
{ {
subclassWindow();
} }
SurfaceD3D::~SurfaceD3D() SurfaceD3D::~SurfaceD3D()
{ {
unsubclassWindow();
releaseSwapChain(); releaseSwapChain();
#if !defined(ANGLE_ENABLE_WINDOWS_STORE) #if !defined(ANGLE_ENABLE_WINDOWS_STORE)
...@@ -280,90 +277,6 @@ egl::Error SurfaceD3D::swapRect(EGLint x, EGLint y, EGLint width, EGLint height) ...@@ -280,90 +277,6 @@ egl::Error SurfaceD3D::swapRect(EGLint x, EGLint y, EGLint width, EGLint height)
return egl::Error(EGL_SUCCESS); return egl::Error(EGL_SUCCESS);
} }
#if !defined(ANGLE_ENABLE_WINDOWS_STORE)
#define kSurfaceProperty _TEXT("Egl::SurfaceOwner")
#define kParentWndProc _TEXT("Egl::SurfaceParentWndProc")
static LRESULT CALLBACK SurfaceWindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
{
if (message == WM_SIZE)
{
SurfaceD3D* surf = reinterpret_cast<SurfaceD3D*>(GetProp(hwnd, kSurfaceProperty));
if(surf)
{
surf->checkForOutOfDateSwapChain();
}
}
WNDPROC prevWndFunc = reinterpret_cast<WNDPROC >(GetProp(hwnd, kParentWndProc));
return CallWindowProc(prevWndFunc, hwnd, message, wparam, lparam);
}
#endif
void SurfaceD3D::subclassWindow()
{
#if !defined(ANGLE_ENABLE_WINDOWS_STORE)
HWND window = mNativeWindow.getNativeWindow();
if (!window)
{
return;
}
DWORD processId;
DWORD threadId = GetWindowThreadProcessId(window, &processId);
if (processId != GetCurrentProcessId() || threadId != GetCurrentThreadId())
{
return;
}
SetLastError(0);
LONG_PTR oldWndProc = SetWindowLongPtr(window, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(SurfaceWindowProc));
if(oldWndProc == 0 && GetLastError() != ERROR_SUCCESS)
{
mWindowSubclassed = false;
return;
}
SetProp(window, kSurfaceProperty, reinterpret_cast<HANDLE>(this));
SetProp(window, kParentWndProc, reinterpret_cast<HANDLE>(oldWndProc));
mWindowSubclassed = true;
#endif
}
void SurfaceD3D::unsubclassWindow()
{
if (!mWindowSubclassed)
{
return;
}
#if !defined(ANGLE_ENABLE_WINDOWS_STORE)
HWND window = mNativeWindow.getNativeWindow();
if (!window)
{
return;
}
// un-subclass
LONG_PTR parentWndFunc = reinterpret_cast<LONG_PTR>(GetProp(window, kParentWndProc));
// Check the windowproc is still SurfaceWindowProc.
// If this assert fails, then it is likely the application has subclassed the
// hwnd as well and did not unsubclass before destroying its EGL context. The
// application should be modified to either subclass before initializing the
// EGL context, or to unsubclass before destroying the EGL context.
if(parentWndFunc)
{
LONG_PTR prevWndFunc = SetWindowLongPtr(window, GWLP_WNDPROC, parentWndFunc);
UNUSED_ASSERTION_VARIABLE(prevWndFunc);
ASSERT(prevWndFunc == reinterpret_cast<LONG_PTR>(SurfaceWindowProc));
}
RemoveProp(window, kSurfaceProperty);
RemoveProp(window, kParentWndProc);
#endif
mWindowSubclassed = false;
}
bool SurfaceD3D::checkForOutOfDateSwapChain() bool SurfaceD3D::checkForOutOfDateSwapChain()
{ {
RECT client; RECT client;
......
...@@ -62,9 +62,6 @@ class SurfaceD3D : public SurfaceImpl ...@@ -62,9 +62,6 @@ class SurfaceD3D : public SurfaceImpl
egl::Error resetSwapChain(int backbufferWidth, int backbufferHeight); egl::Error resetSwapChain(int backbufferWidth, int backbufferHeight);
egl::Error resizeSwapChain(int backbufferWidth, int backbufferHeight); egl::Error resizeSwapChain(int backbufferWidth, int backbufferHeight);
void subclassWindow();
void unsubclassWindow();
RendererD3D *mRenderer; RendererD3D *mRenderer;
egl::Display *mDisplay; egl::Display *mDisplay;
...@@ -75,7 +72,6 @@ class SurfaceD3D : public SurfaceImpl ...@@ -75,7 +72,6 @@ class SurfaceD3D : public SurfaceImpl
SwapChainD3D *mSwapChain; SwapChainD3D *mSwapChain;
bool mSwapIntervalDirty; bool mSwapIntervalDirty;
bool mWindowSubclassed; // Indicates whether we successfully subclassed mWindow for WM_RESIZE hooking
NativeWindow mNativeWindow; // Handler for the Window that the surface is created for. NativeWindow mNativeWindow; // Handler for the Window that the surface is created for.
EGLint mWidth; EGLint mWidth;
......
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