Commit 836bd217 by Geoff Lang

Detect cross-process HWNDs and verify DXGI 1.2 exists in D3D11.

DXGI 1.2 is required to create a swap chain for a HWND owned by another process. This fix will allow us to fall back to creating a Renderer9 if DXGI 1.2 is not available instead of failing to create the swap chain later. BUG=angle:562 Change-Id: Iad1b37967e38452cae201a6d6fa621ad66ce5f3c Reviewed-on: https://chromium-review.googlesource.com/186977Tested-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarShannon Woods <shannonwoods@chromium.org>
parent aacedfcf
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include <d3d9.h> #include <d3d9.h>
#include <d3d11.h> #include <d3d11.h>
#include <dxgi.h> #include <dxgi.h>
#include <dxgi1_2.h>
#include <d3dcompiler.h> #include <d3dcompiler.h>
#ifdef _MSC_VER #ifdef _MSC_VER
......
...@@ -40,6 +40,12 @@ ...@@ -40,6 +40,12 @@
#include "libEGL/Display.h" #include "libEGL/Display.h"
// Enable ANGLE_SKIP_DXGI_1_2_CHECK if there is not a possibility of using cross-process
// HWNDs or the Windows 7 Platform Update (KB2670838) is expected to be installed.
#ifndef ANGLE_SKIP_DXGI_1_2_CHECK
#define ANGLE_SKIP_DXGI_1_2_CHECK 0
#endif
#ifdef _DEBUG #ifdef _DEBUG
// this flag enables suppressing some spurious warnings that pop up in certain WebGL samples // this flag enables suppressing some spurious warnings that pop up in certain WebGL samples
// and conformance tests. to enable all warnings, remove this define. // and conformance tests. to enable all warnings, remove this define.
...@@ -203,6 +209,36 @@ EGLint Renderer11::initialize() ...@@ -203,6 +209,36 @@ EGLint Renderer11::initialize()
} }
} }
#if !ANGLE_SKIP_DXGI_1_2_CHECK
// In order to create a swap chain for an HWND owned by another process, DXGI 1.2 is required.
// The easiest way to check is to query for a IDXGIDevice2.
bool requireDXGI1_2 = false;
HWND hwnd = WindowFromDC(mDc);
if (hwnd)
{
DWORD currentProcessId = GetCurrentProcessId();
DWORD wndProcessId;
GetWindowThreadProcessId(hwnd, &wndProcessId);
requireDXGI1_2 = (currentProcessId != wndProcessId);
}
else
{
requireDXGI1_2 = true;
}
if (requireDXGI1_2)
{
IDXGIDevice2 *dxgiDevice2 = NULL;
result = mDevice->QueryInterface(__uuidof(IDXGIDevice2), (void**)&dxgiDevice2);
if (FAILED(result))
{
ERR("DXGI 1.2 required to present to HWNDs owned by another process.\n");
return EGL_NOT_INITIALIZED;
}
SafeRelease(dxgiDevice2);
}
#endif
IDXGIDevice *dxgiDevice = NULL; IDXGIDevice *dxgiDevice = NULL;
result = mDevice->QueryInterface(__uuidof(IDXGIDevice), (void**)&dxgiDevice); result = mDevice->QueryInterface(__uuidof(IDXGIDevice), (void**)&dxgiDevice);
......
...@@ -392,21 +392,7 @@ EGLint SwapChain11::reset(int backbufferWidth, int backbufferHeight, EGLint swap ...@@ -392,21 +392,7 @@ EGLint SwapChain11::reset(int backbufferWidth, int backbufferHeight, EGLint swap
} }
else else
{ {
// We cannot create a swap chain for an HWND that is owned by a different process on some versions of return EGL_BAD_ALLOC;
// windows
DWORD currentProcessId = GetCurrentProcessId();
DWORD wndProcessId;
GetWindowThreadProcessId(mWindow, &wndProcessId);
if (currentProcessId != wndProcessId)
{
ERR("Could not create swap chain, window owned by different process");
return EGL_BAD_NATIVE_WINDOW;
}
else
{
return EGL_BAD_ALLOC;
}
} }
} }
......
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