mirror of
https://github.com/gnif/LookingGlass.git
synced 2025-08-05 18:24:08 +00:00
[host] fixed support for high DPI desktops (4K+)
This commit is contained in:
@@ -211,19 +211,6 @@ void DXGI::DeInitialize()
|
||||
m_initialized = false;
|
||||
}
|
||||
|
||||
bool DXGI::ReInitialize()
|
||||
{
|
||||
DeInitialize();
|
||||
|
||||
/*
|
||||
DXGI needs some time when mode switches occur, failing to do so causes
|
||||
failure to start and exceptions internal to DXGI
|
||||
*/
|
||||
Sleep(200);
|
||||
|
||||
return Initialize(m_options);
|
||||
}
|
||||
|
||||
FrameType DXGI::GetFrameType()
|
||||
{
|
||||
if (!m_initialized)
|
||||
@@ -240,10 +227,10 @@ size_t DXGI::GetMaxFrameSize()
|
||||
return (m_width * m_height * 4);
|
||||
}
|
||||
|
||||
bool DXGI::GrabFrame(FrameInfo & frame)
|
||||
GrabStatus DXGI::GrabFrame(FrameInfo & frame)
|
||||
{
|
||||
if (!m_initialized)
|
||||
return false;
|
||||
return GRAB_STATUS_ERROR;
|
||||
|
||||
DXGI_OUTDUPL_FRAME_INFO frameInfo;
|
||||
CComPtr<IDXGIResource> res;
|
||||
@@ -258,6 +245,8 @@ bool DXGI::GrabFrame(FrameInfo & frame)
|
||||
switch (status)
|
||||
{
|
||||
case DXGI_ERROR_ACCESS_LOST: // desktop switch, mode change or switch DWM on or off
|
||||
return GRAB_STATUS_REINIT;
|
||||
|
||||
case WAIT_ABANDONED: // this can happen also during desktop switches, not documented by MS though
|
||||
{
|
||||
// see if we can open the desktop, if not the secure desktop
|
||||
@@ -275,7 +264,7 @@ bool DXGI::GrabFrame(FrameInfo & frame)
|
||||
if (!ReInitialize())
|
||||
{
|
||||
DEBUG_ERROR("Failed to ReInitialize after lost access to desktop");
|
||||
return false;
|
||||
return GRAB_STATUS_ERROR;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -283,7 +272,7 @@ bool DXGI::GrabFrame(FrameInfo & frame)
|
||||
default:
|
||||
// unknown failure
|
||||
DEBUG_INFO("AcquireNextFrame failed: %08x", status);
|
||||
return false;
|
||||
return GRAB_STATUS_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -292,7 +281,7 @@ bool DXGI::GrabFrame(FrameInfo & frame)
|
||||
{
|
||||
m_dup->ReleaseFrame();
|
||||
DEBUG_ERROR("Failed to acquire next frame");
|
||||
return false;
|
||||
return GRAB_STATUS_ERROR;
|
||||
}
|
||||
|
||||
CComQIPtr<ID3D11Texture2D> src = res;
|
||||
@@ -300,7 +289,7 @@ bool DXGI::GrabFrame(FrameInfo & frame)
|
||||
{
|
||||
m_dup->ReleaseFrame();
|
||||
DEBUG_ERROR("Failed to get src ID3D11Texture2D");
|
||||
return false;
|
||||
return GRAB_STATUS_ERROR;
|
||||
}
|
||||
|
||||
D3D11_TEXTURE2D_DESC desc;
|
||||
@@ -324,7 +313,7 @@ bool DXGI::GrabFrame(FrameInfo & frame)
|
||||
{
|
||||
m_dup->ReleaseFrame();
|
||||
DEBUG_ERROR("Failed to get the new pointer shape: %08x", status);
|
||||
return false;
|
||||
return GRAB_STATUS_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -336,7 +325,7 @@ bool DXGI::GrabFrame(FrameInfo & frame)
|
||||
if (!surface)
|
||||
{
|
||||
DEBUG_ERROR("Failed to get IDXGISurface1");
|
||||
return false;
|
||||
return GRAB_STATUS_ERROR;
|
||||
}
|
||||
|
||||
DXGI_MAPPED_RECT rect;
|
||||
@@ -344,7 +333,7 @@ bool DXGI::GrabFrame(FrameInfo & frame)
|
||||
if (FAILED(status))
|
||||
{
|
||||
DEBUG_ERROR("Failed to map surface: %08x", status);
|
||||
return false;
|
||||
return GRAB_STATUS_ERROR;
|
||||
}
|
||||
|
||||
m_width = desc.Width;
|
||||
@@ -381,7 +370,7 @@ bool DXGI::GrabFrame(FrameInfo & frame)
|
||||
case DXGI_OUTDUPL_POINTER_SHAPE_TYPE_MONOCHROME : type = CURSOR_TYPE_MONOCHROME ; break;
|
||||
default:
|
||||
DEBUG_ERROR("Invalid cursor type");
|
||||
return false;
|
||||
return GRAB_STATUS_ERROR;
|
||||
}
|
||||
|
||||
POINT cursorPos;
|
||||
@@ -404,8 +393,8 @@ bool DXGI::GrabFrame(FrameInfo & frame)
|
||||
if (FAILED(status))
|
||||
{
|
||||
DEBUG_ERROR("Failed to unmap surface: %08x", status);
|
||||
return false;
|
||||
return GRAB_STATUS_ERROR;
|
||||
}
|
||||
|
||||
return true;
|
||||
return GRAB_STATUS_OK;
|
||||
}
|
@@ -38,16 +38,25 @@ namespace Capture
|
||||
|
||||
bool Initialize(CaptureOptions * options);
|
||||
void DeInitialize();
|
||||
bool ReInitialize()
|
||||
{
|
||||
DeInitialize();
|
||||
/*
|
||||
DXGI needs some time when mode switches occur, failing to do so causes
|
||||
failure to start and exceptions internal to DXGI
|
||||
*/
|
||||
Sleep(200);
|
||||
return Initialize(m_options);
|
||||
}
|
||||
|
||||
enum FrameType GetFrameType();
|
||||
enum FrameComp GetFrameCompression();
|
||||
size_t GetMaxFrameSize();
|
||||
bool GrabFrame(struct FrameInfo & frame);
|
||||
enum GrabStatus GrabFrame(struct FrameInfo & frame);
|
||||
|
||||
private:
|
||||
CaptureOptions * m_options;
|
||||
|
||||
bool ReInitialize();
|
||||
|
||||
bool m_initialized;
|
||||
unsigned int m_width;
|
||||
unsigned int m_height;
|
||||
|
@@ -50,7 +50,7 @@ bool NvFBC::Initialize(CaptureOptions * options)
|
||||
if (m_initialized)
|
||||
DeInitialize();
|
||||
|
||||
m_options = options;
|
||||
m_options = options;
|
||||
m_optNoCrop = false;
|
||||
for (CaptureOptions::const_iterator it = options->cbegin(); it != options->cend(); ++it)
|
||||
{
|
||||
@@ -212,12 +212,14 @@ size_t NvFBC::GetMaxFrameSize()
|
||||
return m_maxCaptureWidth * m_maxCaptureHeight * 4;
|
||||
}
|
||||
|
||||
bool NvFBC::GrabFrame(struct FrameInfo & frame)
|
||||
enum GrabStatus NvFBC::GrabFrame(struct FrameInfo & frame)
|
||||
{
|
||||
if (!m_initialized)
|
||||
return false;
|
||||
return GRAB_STATUS_ERROR;
|
||||
|
||||
const HWND hDesktop = GetDesktopWindow();
|
||||
const unsigned int screenWidth = GetSystemMetrics(SM_CXSCREEN);
|
||||
const unsigned int screenHeight = GetSystemMetrics(SM_CYSCREEN);
|
||||
RECT desktop;
|
||||
GetWindowRect(hDesktop, &desktop);
|
||||
|
||||
@@ -249,22 +251,22 @@ bool NvFBC::GrabFrame(struct FrameInfo & frame)
|
||||
|
||||
if (m_optNoCrop)
|
||||
{
|
||||
dataWidth = m_grabInfo.dwWidth * 4;
|
||||
dataWidth = m_grabInfo.dwWidth * 4;
|
||||
dataOffset = 0;
|
||||
|
||||
frame.width = m_grabInfo.dwWidth;
|
||||
frame.width = m_grabInfo.dwWidth;
|
||||
frame.height = m_grabInfo.dwHeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
const unsigned int realHeight = min(m_grabInfo.dwHeight, (unsigned int)(desktop.bottom - desktop.top));
|
||||
const unsigned int realWidth = min(m_grabInfo.dwWidth , (unsigned int)(desktop.right - desktop.left));
|
||||
dataWidth = realWidth * 4;
|
||||
const unsigned int realHeight = min(m_grabInfo.dwHeight, screenHeight);
|
||||
const unsigned int realWidth = min(m_grabInfo.dwWidth, screenWidth);
|
||||
dataWidth = realWidth * 4;
|
||||
dataOffset =
|
||||
(((m_grabInfo.dwHeight - realHeight) >> 1) * m_grabInfo.dwBufferWidth +
|
||||
((m_grabInfo.dwWidth - realWidth ) >> 1)) * 4;
|
||||
((m_grabInfo.dwWidth - realWidth) >> 1)) * 4;
|
||||
|
||||
frame.width = realWidth;
|
||||
frame.width = realWidth;
|
||||
frame.height = realHeight;
|
||||
}
|
||||
|
||||
@@ -276,27 +278,22 @@ bool NvFBC::GrabFrame(struct FrameInfo & frame)
|
||||
for(unsigned int y = 0; y < frame.height; ++y, dst += dataWidth, src += m_grabInfo.dwBufferWidth * 4)
|
||||
memcpySSE(dst, src, dataWidth);
|
||||
|
||||
return true;
|
||||
return GRAB_STATUS_OK;
|
||||
}
|
||||
|
||||
if (status == NVFBC_ERROR_DYNAMIC_DISABLE)
|
||||
{
|
||||
DEBUG_ERROR("NvFBC was disabled by someone else");
|
||||
return false;
|
||||
return GRAB_STATUS_ERROR;
|
||||
}
|
||||
|
||||
if (status == NVFBC_ERROR_INVALIDATED_SESSION)
|
||||
{
|
||||
DEBUG_WARN("Session was invalidated, attempting to restart");
|
||||
DeInitialize();
|
||||
if (!Initialize(m_options))
|
||||
{
|
||||
DEBUG_ERROR("Failed to re-iniaialize");
|
||||
return false;
|
||||
}
|
||||
return GRAB_STATUS_REINIT;
|
||||
}
|
||||
}
|
||||
|
||||
DEBUG_ERROR("Failed to grab frame");
|
||||
return false;
|
||||
return GRAB_STATUS_ERROR;
|
||||
}
|
||||
|
@@ -37,10 +37,15 @@ namespace Capture
|
||||
|
||||
bool Initialize(CaptureOptions * options);
|
||||
void DeInitialize();
|
||||
bool ReInitialize()
|
||||
{
|
||||
DeInitialize();
|
||||
return Initialize(m_options);
|
||||
}
|
||||
enum FrameType GetFrameType();
|
||||
enum FrameComp GetFrameCompression();
|
||||
size_t GetMaxFrameSize();
|
||||
bool GrabFrame(struct FrameInfo & frame);
|
||||
enum GrabStatus GrabFrame(struct FrameInfo & frame);
|
||||
|
||||
private:
|
||||
CaptureOptions * m_options;
|
||||
|
Reference in New Issue
Block a user