mirror of
https://github.com/gnif/LookingGlass.git
synced 2025-08-05 18:24:08 +00:00
[c-host] restructure project to use cmake
This commit is contained in:
23
c-host/platform/Windows/CMakeLists.txt
Normal file
23
c-host/platform/Windows/CMakeLists.txt
Normal file
@@ -0,0 +1,23 @@
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
project(platform_Windows LANGUAGES C)
|
||||
|
||||
include_directories(
|
||||
${PROJECT_SOURCE_DIR}/include
|
||||
)
|
||||
|
||||
add_library(platform_Windows STATIC
|
||||
src/platform.c
|
||||
src/windebug.c
|
||||
)
|
||||
|
||||
add_subdirectory("capture")
|
||||
|
||||
target_link_libraries(platform_Windows
|
||||
capture
|
||||
setupapi
|
||||
)
|
||||
|
||||
target_include_directories(platform_Windows
|
||||
PRIVATE
|
||||
src
|
||||
)
|
11
c-host/platform/Windows/capture/CMakeLists.txt
Normal file
11
c-host/platform/Windows/capture/CMakeLists.txt
Normal file
@@ -0,0 +1,11 @@
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
project(capture LANGUAGES C)
|
||||
|
||||
include("PreCapture")
|
||||
|
||||
add_capture("DXGI")
|
||||
|
||||
include("PostCapture")
|
||||
|
||||
add_library(capture STATIC ${CAPTURE_C})
|
||||
target_link_libraries(capture ${CAPTURE_LINK})
|
25
c-host/platform/Windows/capture/DXGI/CMakeLists.txt
Normal file
25
c-host/platform/Windows/capture/DXGI/CMakeLists.txt
Normal file
@@ -0,0 +1,25 @@
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
project(capture_DXGI LANGUAGES C)
|
||||
|
||||
add_library(capture_DXGI STATIC
|
||||
src/dxgi.c
|
||||
)
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DCOBJMACROS -DINITGUID")
|
||||
|
||||
FIND_PROGRAM(DLLTOOL_EXECUTABLE NAMES "dlltool.exe" DOC "dlltool executable")
|
||||
ADD_CUSTOM_COMMAND(TARGET capture_DXGI POST_BUILD
|
||||
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/dll"
|
||||
COMMAND ${DLLTOOL_EXECUTABLE} --def libd3d11.def --output-lib "${PROJECT_BINARY_DIR}/libd3d11.dll"
|
||||
VERBATIM
|
||||
)
|
||||
|
||||
target_link_libraries(capture_DXGI
|
||||
${PROJECT_BINARY_DIR}/libd3d11.dll
|
||||
dxgi
|
||||
)
|
||||
|
||||
target_include_directories(capture_DXGI
|
||||
PRIVATE
|
||||
src
|
||||
)
|
44
c-host/platform/Windows/capture/DXGI/dll/libd3d11.def
Normal file
44
c-host/platform/Windows/capture/DXGI/dll/libd3d11.def
Normal file
@@ -0,0 +1,44 @@
|
||||
LIBRARY "d3d11.dll"
|
||||
EXPORTS
|
||||
D3DKMTCloseAdapter
|
||||
D3DKMTDestroyAllocation
|
||||
D3DKMTDestroyContext
|
||||
D3DKMTDestroyDevice
|
||||
D3DKMTDestroySynchronizationObject
|
||||
D3DKMTQueryAdapterInfo
|
||||
D3DKMTSetDisplayPrivateDriverFormat
|
||||
D3DKMTSignalSynchronizationObject
|
||||
D3DKMTUnlock
|
||||
D3DKMTWaitForSynchronizationObject
|
||||
OpenAdapter10
|
||||
OpenAdapter10_2
|
||||
D3D11CoreCreateDevice
|
||||
D3D11CoreCreateLayeredDevice
|
||||
D3D11CoreGetLayeredDeviceSize
|
||||
D3D11CoreRegisterLayers
|
||||
D3D11CreateDevice
|
||||
D3D11CreateDeviceAndSwapChain
|
||||
D3DKMTCreateAllocation
|
||||
D3DKMTCreateContext
|
||||
D3DKMTCreateDevice
|
||||
D3DKMTCreateSynchronizationObject
|
||||
D3DKMTEscape
|
||||
D3DKMTGetContextSchedulingPriority
|
||||
D3DKMTGetDeviceState
|
||||
D3DKMTGetDisplayModeList
|
||||
D3DKMTGetMultisampleMethodList
|
||||
D3DKMTGetRuntimeData
|
||||
D3DKMTGetSharedPrimaryHandle
|
||||
D3DKMTLock
|
||||
D3DKMTOpenAdapterFromHdc
|
||||
D3DKMTOpenResource
|
||||
D3DKMTPresent
|
||||
D3DKMTQueryAllocationResidency
|
||||
D3DKMTQueryResourceInfo
|
||||
D3DKMTRender
|
||||
D3DKMTSetAllocationPriority
|
||||
D3DKMTSetContextSchedulingPriority
|
||||
D3DKMTSetDisplayMode
|
||||
D3DKMTSetGammaRamp
|
||||
D3DKMTSetVidPnSourceOwner
|
||||
D3DKMTWaitForVerticalBlankEvent
|
770
c-host/platform/Windows/capture/DXGI/src/dxgi.c
Normal file
770
c-host/platform/Windows/capture/DXGI/src/dxgi.c
Normal file
@@ -0,0 +1,770 @@
|
||||
/*
|
||||
Looking Glass - KVM FrameRelay (KVMFR) Client
|
||||
Copyright (C) 2017-2019 Geoffrey McRae <geoff@hostfission.com>
|
||||
https://looking-glass.hostfission.com
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any later
|
||||
version.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with
|
||||
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||
Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "interface/capture.h"
|
||||
#include "interface/platform.h"
|
||||
#include "debug.h"
|
||||
#include "windows/windebug.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <dxgi.h>
|
||||
#include <d3d11.h>
|
||||
#include <d3dcommon.h>
|
||||
|
||||
#include "dxgi_extra.h"
|
||||
|
||||
#define MAX_TEXTURES 2
|
||||
|
||||
typedef struct Texture
|
||||
{
|
||||
ID3D11Texture2D * tex;
|
||||
D3D11_MAPPED_SUBRESOURCE map;
|
||||
osEventHandle * evt;
|
||||
}
|
||||
Texture;
|
||||
|
||||
typedef struct Pointer
|
||||
{
|
||||
unsigned int version;
|
||||
|
||||
unsigned int x, y;
|
||||
unsigned int w, h;
|
||||
bool visible;
|
||||
unsigned int pitch;
|
||||
CaptureFormat format;
|
||||
}
|
||||
Pointer;
|
||||
|
||||
// locals
|
||||
struct iface
|
||||
{
|
||||
bool initialized;
|
||||
bool reinit;
|
||||
IDXGIFactory1 * factory;
|
||||
IDXGIAdapter1 * adapter;
|
||||
IDXGIOutput * output;
|
||||
ID3D11Device * device;
|
||||
ID3D11DeviceContext * deviceContext;
|
||||
D3D_FEATURE_LEVEL featureLevel;
|
||||
IDXGIOutputDuplication * dup;
|
||||
Texture texture[MAX_TEXTURES];
|
||||
int texRIndex;
|
||||
int texWIndex;
|
||||
bool needsRelease;
|
||||
osEventHandle * frameEvent;
|
||||
osEventHandle * pointerEvent;
|
||||
|
||||
unsigned int width;
|
||||
unsigned int height;
|
||||
unsigned int pitch;
|
||||
unsigned int stride;
|
||||
CaptureFormat format;
|
||||
|
||||
// pointer state
|
||||
Pointer lastPointer;
|
||||
Pointer pointer;
|
||||
|
||||
// pointer shape
|
||||
void * pointerShape;
|
||||
unsigned int pointerSize;
|
||||
unsigned int pointerUsed;
|
||||
};
|
||||
|
||||
static bool dpiDone = false;
|
||||
static struct iface * this = NULL;
|
||||
|
||||
// forwards
|
||||
|
||||
static bool dxgi_deinit();
|
||||
static CaptureResult dxgi_releaseFrame();
|
||||
|
||||
// implementation
|
||||
|
||||
static const char * dxgi_getName()
|
||||
{
|
||||
return "DXGI";
|
||||
}
|
||||
|
||||
static bool dxgi_create()
|
||||
{
|
||||
assert(!this);
|
||||
this = calloc(sizeof(struct iface), 1);
|
||||
if (!this)
|
||||
{
|
||||
DEBUG_ERROR("failed to allocate iface struct");
|
||||
return false;
|
||||
}
|
||||
|
||||
this->frameEvent = os_createEvent(true);
|
||||
if (!this->frameEvent)
|
||||
{
|
||||
DEBUG_ERROR("failed to create the frame event");
|
||||
free(this);
|
||||
return false;
|
||||
}
|
||||
|
||||
this->pointerEvent = os_createEvent(true);
|
||||
if (!this->pointerEvent)
|
||||
{
|
||||
DEBUG_ERROR("failed to create the pointer event");
|
||||
os_freeEvent(this->frameEvent);
|
||||
free(this);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool dxgi_init(void * pointerShape, const unsigned int pointerSize)
|
||||
{
|
||||
assert(this);
|
||||
|
||||
// this is required for DXGI 1.5 support to function
|
||||
if (!dpiDone)
|
||||
{
|
||||
DECLARE_HANDLE(DPI_AWARENESS_CONTEXT);
|
||||
#define DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 ((DPI_AWARENESS_CONTEXT)-4)
|
||||
typedef BOOL (*User32_SetProcessDpiAwarenessContext)(DPI_AWARENESS_CONTEXT value);
|
||||
|
||||
HMODULE user32 = LoadLibraryA("user32.dll");
|
||||
User32_SetProcessDpiAwarenessContext fn;
|
||||
fn = (User32_SetProcessDpiAwarenessContext)GetProcAddress(user32, "SetProcessDpiAwarenessContext");
|
||||
if (fn)
|
||||
fn(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
|
||||
FreeLibrary(user32);
|
||||
dpiDone = true;
|
||||
}
|
||||
|
||||
HRESULT status;
|
||||
DXGI_OUTPUT_DESC outputDesc;
|
||||
|
||||
this->pointerShape = pointerShape;
|
||||
this->pointerSize = pointerSize;
|
||||
this->pointerUsed = 0;
|
||||
|
||||
this->reinit = false;
|
||||
this->texRIndex = 0;
|
||||
this->texWIndex = 0;
|
||||
os_resetEvent(this->frameEvent);
|
||||
|
||||
status = CreateDXGIFactory1(&IID_IDXGIFactory1, (void **)&this->factory);
|
||||
if (FAILED(status))
|
||||
{
|
||||
DEBUG_WINERROR("Failed to create DXGIFactory1", status);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
for(int i = 0; IDXGIFactory1_EnumAdapters1(this->factory, i, &this->adapter) != DXGI_ERROR_NOT_FOUND; ++i)
|
||||
{
|
||||
for(int n = 0; IDXGIAdapter1_EnumOutputs(this->adapter, n, &this->output) != DXGI_ERROR_NOT_FOUND; ++n)
|
||||
{
|
||||
IDXGIOutput_GetDesc(this->output, &outputDesc);
|
||||
if (outputDesc.AttachedToDesktop)
|
||||
break;
|
||||
|
||||
IDXGIOutput_Release(this->output);
|
||||
this->output = NULL;
|
||||
}
|
||||
|
||||
if (this->output)
|
||||
break;
|
||||
|
||||
IDXGIAdapter1_Release(this->adapter);
|
||||
this->adapter = NULL;
|
||||
}
|
||||
|
||||
if (!this->output)
|
||||
{
|
||||
DEBUG_ERROR("Failed to locate a valid output device");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
static const D3D_FEATURE_LEVEL featureLevels[] =
|
||||
{
|
||||
D3D_FEATURE_LEVEL_12_1,
|
||||
D3D_FEATURE_LEVEL_12_0,
|
||||
D3D_FEATURE_LEVEL_11_1,
|
||||
D3D_FEATURE_LEVEL_11_0,
|
||||
D3D_FEATURE_LEVEL_10_1,
|
||||
D3D_FEATURE_LEVEL_10_0,
|
||||
D3D_FEATURE_LEVEL_9_3,
|
||||
D3D_FEATURE_LEVEL_9_2,
|
||||
D3D_FEATURE_LEVEL_9_1
|
||||
};
|
||||
|
||||
IDXGIAdapter * tmp;
|
||||
status = IDXGIAdapter1_QueryInterface(this->adapter, &IID_IDXGIAdapter, (void **)&tmp);
|
||||
if (FAILED(status))
|
||||
{
|
||||
DEBUG_ERROR("Failed to query IDXGIAdapter interface");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
status = D3D11CreateDevice(
|
||||
tmp,
|
||||
D3D_DRIVER_TYPE_UNKNOWN,
|
||||
NULL,
|
||||
D3D11_CREATE_DEVICE_VIDEO_SUPPORT,
|
||||
featureLevels, sizeof(featureLevels) / sizeof(D3D_FEATURE_LEVEL),
|
||||
D3D11_SDK_VERSION,
|
||||
&this->device,
|
||||
&this->featureLevel,
|
||||
&this->deviceContext);
|
||||
|
||||
IDXGIAdapter_Release(tmp);
|
||||
|
||||
if (FAILED(status))
|
||||
{
|
||||
DEBUG_WINERROR("Failed to create D3D11 device", status);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
DXGI_ADAPTER_DESC1 adapterDesc;
|
||||
IDXGIAdapter1_GetDesc1(this->adapter, &adapterDesc);
|
||||
this->width = outputDesc.DesktopCoordinates.right - outputDesc.DesktopCoordinates.left;
|
||||
this->height = outputDesc.DesktopCoordinates.bottom - outputDesc.DesktopCoordinates.top;
|
||||
|
||||
DEBUG_INFO("Device Descripion: %ls" , adapterDesc.Description);
|
||||
DEBUG_INFO("Device Vendor ID : 0x%x" , adapterDesc.VendorId);
|
||||
DEBUG_INFO("Device Device ID : 0x%x" , adapterDesc.DeviceId);
|
||||
DEBUG_INFO("Device Video Mem : %u MiB" , (unsigned)(adapterDesc.DedicatedVideoMemory / 1048576));
|
||||
DEBUG_INFO("Device Sys Mem : %u MiB" , (unsigned)(adapterDesc.DedicatedSystemMemory / 1048576));
|
||||
DEBUG_INFO("Shared Sys Mem : %u MiB" , (unsigned)(adapterDesc.SharedSystemMemory / 1048576));
|
||||
DEBUG_INFO("Feature Level : 0x%x" , this->featureLevel);
|
||||
DEBUG_INFO("Capture Size : %u x %u", this->width, this->height);
|
||||
|
||||
// bump up our priority
|
||||
{
|
||||
IDXGIDevice * dxgi;
|
||||
status = ID3D11Device_QueryInterface(this->device, &IID_IDXGIDevice, (void **)&dxgi);
|
||||
if (FAILED(status))
|
||||
{
|
||||
DEBUG_WINERROR("failed to query DXGI interface from device", status);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
IDXGIDevice_SetGPUThreadPriority(dxgi, 7);
|
||||
IDXGIDevice_Release(dxgi);
|
||||
}
|
||||
|
||||
IDXGIOutput5 * output5 = NULL;
|
||||
status = IDXGIOutput_QueryInterface(this->output, &IID_IDXGIOutput5, (void **)&output5);
|
||||
if (FAILED(status))
|
||||
{
|
||||
DEBUG_WARN("IDXGIOutput5 is not available, please update windows for improved performance!");
|
||||
DEBUG_WARN("Falling back to IDXIGOutput1");
|
||||
|
||||
IDXGIOutput1 * output1 = NULL;
|
||||
status = IDXGIOutput_QueryInterface(this->output, &IID_IDXGIOutput1, (void **)&output1);
|
||||
if (FAILED(status))
|
||||
{
|
||||
DEBUG_ERROR("Failed to query IDXGIOutput1 from the output");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
// we try this twice in case we still get an error on re-initialization
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
status = IDXGIOutput1_DuplicateOutput(output1, (IUnknown *)this->device, &this->dup);
|
||||
if (SUCCEEDED(status))
|
||||
break;
|
||||
Sleep(200);
|
||||
}
|
||||
|
||||
if (FAILED(status))
|
||||
{
|
||||
DEBUG_WINERROR("DuplicateOutput Failed", status);
|
||||
IDXGIOutput1_Release(output1);
|
||||
goto fail;
|
||||
}
|
||||
IDXGIOutput1_Release(output1);
|
||||
}
|
||||
else
|
||||
{
|
||||
const DXGI_FORMAT supportedFormats[] =
|
||||
{
|
||||
DXGI_FORMAT_B8G8R8A8_UNORM,
|
||||
DXGI_FORMAT_R8G8B8A8_UNORM,
|
||||
DXGI_FORMAT_R10G10B10A2_UNORM
|
||||
};
|
||||
|
||||
// we try this twice in case we still get an error on re-initialization
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
status = IDXGIOutput5_DuplicateOutput1(
|
||||
output5,
|
||||
(IUnknown *)this->device,
|
||||
0,
|
||||
sizeof(supportedFormats) / sizeof(DXGI_FORMAT),
|
||||
supportedFormats,
|
||||
&this->dup);
|
||||
|
||||
if (SUCCEEDED(status))
|
||||
break;
|
||||
|
||||
// if access is denied we just keep trying until it isn't
|
||||
if (status == E_ACCESSDENIED)
|
||||
--i;
|
||||
|
||||
Sleep(200);
|
||||
}
|
||||
|
||||
if (FAILED(status))
|
||||
{
|
||||
DEBUG_WINERROR("DuplicateOutput1 Failed", status);
|
||||
IDXGIOutput5_Release(output5);
|
||||
goto fail;
|
||||
}
|
||||
IDXGIOutput5_Release(output5);
|
||||
}
|
||||
|
||||
DXGI_OUTDUPL_DESC dupDesc;
|
||||
IDXGIOutputDuplication_GetDesc(this->dup, &dupDesc);
|
||||
DEBUG_INFO("Source Format : %s", GetDXGIFormatStr(dupDesc.ModeDesc.Format));
|
||||
|
||||
switch(dupDesc.ModeDesc.Format)
|
||||
{
|
||||
case DXGI_FORMAT_B8G8R8A8_UNORM : this->format = CAPTURE_FMT_BGRA ; break;
|
||||
case DXGI_FORMAT_R8G8B8A8_UNORM : this->format = CAPTURE_FMT_RGBA ; break;
|
||||
case DXGI_FORMAT_R10G10B10A2_UNORM: this->format = CAPTURE_FMT_RGBA10; break;
|
||||
default:
|
||||
DEBUG_ERROR("Unsupported source format");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
D3D11_TEXTURE2D_DESC texDesc;
|
||||
memset(&texDesc, 0, sizeof(texDesc));
|
||||
texDesc.Width = this->width;
|
||||
texDesc.Height = this->height;
|
||||
texDesc.MipLevels = 1;
|
||||
texDesc.ArraySize = 1;
|
||||
texDesc.SampleDesc.Count = 1;
|
||||
texDesc.SampleDesc.Quality = 0;
|
||||
texDesc.Usage = D3D11_USAGE_STAGING;
|
||||
texDesc.Format = dupDesc.ModeDesc.Format;
|
||||
texDesc.BindFlags = 0;
|
||||
texDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
|
||||
texDesc.MiscFlags = 0;
|
||||
|
||||
for(int i = 0; i < MAX_TEXTURES; ++i)
|
||||
{
|
||||
status = ID3D11Device_CreateTexture2D(this->device, &texDesc, NULL, &this->texture[i].tex);
|
||||
if (FAILED(status))
|
||||
{
|
||||
DEBUG_WINERROR("Failed to create texture", status);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
this->texture[i].evt = os_createEvent(true);
|
||||
if (!this->texture[i].evt)
|
||||
{
|
||||
DEBUG_ERROR("Failed to create the texture event");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
// pre-signal the events to flag as unused
|
||||
os_signalEvent(this->texture[i].evt);
|
||||
}
|
||||
|
||||
// map the texture simply to get the pitch and stride
|
||||
D3D11_MAPPED_SUBRESOURCE mapping;
|
||||
status = ID3D11DeviceContext_Map(this->deviceContext, (ID3D11Resource *)this->texture[0].tex, 0, D3D11_MAP_READ, 0, &mapping);
|
||||
if (FAILED(status))
|
||||
{
|
||||
DEBUG_WINERROR("Failed to map the texture", status);
|
||||
goto fail;
|
||||
}
|
||||
this->pitch = mapping.RowPitch;
|
||||
this->stride = mapping.RowPitch / 4;
|
||||
ID3D11DeviceContext_Unmap(this->deviceContext, (ID3D11Resource *)this->texture[0].tex, 0);
|
||||
|
||||
this->initialized = true;
|
||||
return true;
|
||||
|
||||
fail:
|
||||
dxgi_deinit();
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool dxgi_deinit()
|
||||
{
|
||||
assert(this);
|
||||
|
||||
for(int i = 0; i < MAX_TEXTURES; ++i)
|
||||
{
|
||||
if (this->texture[i].map.pData)
|
||||
{
|
||||
ID3D11DeviceContext_Unmap(this->deviceContext, (ID3D11Resource*)this->texture[i].tex, 0);
|
||||
this->texture[i].map.pData = NULL;
|
||||
}
|
||||
|
||||
if (this->texture[i].tex)
|
||||
{
|
||||
ID3D11Texture2D_Release(this->texture[i].tex);
|
||||
this->texture[i].tex = NULL;
|
||||
}
|
||||
|
||||
if (this->texture[i].evt)
|
||||
{
|
||||
os_signalEvent(this->texture[i].evt);
|
||||
os_freeEvent(this->texture[i].evt);
|
||||
this->texture[i].evt = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (this->dup)
|
||||
{
|
||||
dxgi_releaseFrame();
|
||||
IDXGIOutputDuplication_Release(this->dup);
|
||||
this->dup = NULL;
|
||||
}
|
||||
|
||||
if (this->deviceContext)
|
||||
{
|
||||
ID3D11DeviceContext_Release(this->deviceContext);
|
||||
this->deviceContext = NULL;
|
||||
}
|
||||
|
||||
if (this->output)
|
||||
{
|
||||
IDXGIOutput_Release(this->output);
|
||||
this->output = NULL;
|
||||
}
|
||||
|
||||
if (this->device)
|
||||
{
|
||||
ID3D11Device_Release(this->device);
|
||||
this->device = NULL;
|
||||
}
|
||||
|
||||
if (this->adapter)
|
||||
{
|
||||
IDXGIAdapter1_Release(this->adapter);
|
||||
this->adapter = NULL;
|
||||
}
|
||||
|
||||
if (this->factory)
|
||||
{
|
||||
// if this doesn't free we have a memory leak
|
||||
DWORD count = IDXGIFactory1_Release(this->factory);
|
||||
this->factory = NULL;
|
||||
if (count != 0)
|
||||
{
|
||||
DEBUG_ERROR("Factory release is %lu, there is a memory leak!", count);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
this->initialized = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void dxgi_free()
|
||||
{
|
||||
assert(this);
|
||||
|
||||
if (this->initialized)
|
||||
dxgi_deinit();
|
||||
|
||||
os_freeEvent(this->frameEvent );
|
||||
os_freeEvent(this->pointerEvent);
|
||||
|
||||
free(this);
|
||||
this = NULL;
|
||||
}
|
||||
|
||||
static unsigned int dxgi_getMaxFrameSize()
|
||||
{
|
||||
assert(this);
|
||||
assert(this->initialized);
|
||||
|
||||
return this->height * this->pitch;
|
||||
}
|
||||
|
||||
inline static CaptureResult dxgi_capture_int()
|
||||
{
|
||||
assert(this);
|
||||
assert(this->initialized);
|
||||
|
||||
CaptureResult result;
|
||||
HRESULT status;
|
||||
DXGI_OUTDUPL_FRAME_INFO frameInfo;
|
||||
IDXGIResource * res;
|
||||
|
||||
result = dxgi_releaseFrame();
|
||||
if (result != CAPTURE_RESULT_OK)
|
||||
return result;
|
||||
|
||||
status = IDXGIOutputDuplication_AcquireNextFrame(this->dup, 1000, &frameInfo, &res);
|
||||
switch(status)
|
||||
{
|
||||
case S_OK:
|
||||
this->needsRelease = true;
|
||||
break;
|
||||
|
||||
case DXGI_ERROR_WAIT_TIMEOUT:
|
||||
return CAPTURE_RESULT_TIMEOUT;
|
||||
|
||||
case WAIT_ABANDONED:
|
||||
case DXGI_ERROR_ACCESS_LOST:
|
||||
return CAPTURE_RESULT_REINIT;
|
||||
|
||||
default:
|
||||
DEBUG_WINERROR("AcquireNextFrame failed", status);
|
||||
return CAPTURE_RESULT_ERROR;
|
||||
}
|
||||
|
||||
if (frameInfo.LastPresentTime.QuadPart != 0)
|
||||
{
|
||||
Texture * tex = &this->texture[this->texWIndex];
|
||||
|
||||
// check if the texture is free, if not skip the frame to keep up
|
||||
if (!os_waitEvent(tex->evt, 0))
|
||||
{
|
||||
DEBUG_WARN("Frame skipped");
|
||||
}
|
||||
else
|
||||
{
|
||||
ID3D11Texture2D * src;
|
||||
status = IDXGIResource_QueryInterface(res, &IID_ID3D11Texture2D, (void **)&src);
|
||||
if (FAILED(status))
|
||||
{
|
||||
DEBUG_WINERROR("Failed to get the texture from the dxgi resource", status);
|
||||
IDXGIResource_Release(res);
|
||||
return CAPTURE_RESULT_ERROR;
|
||||
}
|
||||
|
||||
// if the texture was mapped, unmap it
|
||||
if (tex->map.pData)
|
||||
{
|
||||
ID3D11DeviceContext_Unmap(this->deviceContext, (ID3D11Resource*)tex->tex, 0);
|
||||
tex->map.pData = NULL;
|
||||
}
|
||||
|
||||
// issue the copy from GPU to CPU RAM
|
||||
ID3D11DeviceContext_CopyResource(this->deviceContext,
|
||||
(ID3D11Resource *)tex->tex, (ID3D11Resource *)src);
|
||||
|
||||
// map the resource (this must be done here as ID3D11DeviceContext is not thread safe)
|
||||
status = ID3D11DeviceContext_Map(this->deviceContext, (ID3D11Resource*)tex->tex, 0, D3D11_MAP_READ, 0, &tex->map);
|
||||
if (FAILED(status))
|
||||
{
|
||||
DEBUG_WINERROR("Failed to map the texture", status);
|
||||
IDXGIResource_Release(res);
|
||||
return CAPTURE_RESULT_ERROR;
|
||||
}
|
||||
|
||||
// signal that a frame is available
|
||||
os_signalEvent(this->frameEvent);
|
||||
|
||||
// advance our write pointer
|
||||
if (++this->texWIndex == MAX_TEXTURES)
|
||||
this->texWIndex = 0;
|
||||
|
||||
ID3D11Texture2D_Release(src);
|
||||
}
|
||||
}
|
||||
|
||||
IDXGIResource_Release(res);
|
||||
|
||||
// if the pointer has moved or changed state
|
||||
bool signalPointer = false;
|
||||
if (frameInfo.LastMouseUpdateTime.QuadPart)
|
||||
{
|
||||
if (
|
||||
frameInfo.PointerPosition.Position.x != this->lastPointer.x ||
|
||||
frameInfo.PointerPosition.Position.y != this->lastPointer.y ||
|
||||
frameInfo.PointerPosition.Visible != this->lastPointer.visible
|
||||
)
|
||||
{
|
||||
this->pointer.x = frameInfo.PointerPosition.Position.x;
|
||||
this->pointer.y = frameInfo.PointerPosition.Position.y;
|
||||
this->pointer.visible = frameInfo.PointerPosition.Visible;
|
||||
signalPointer = true;
|
||||
}
|
||||
}
|
||||
|
||||
// if the pointer shape has changed
|
||||
if (frameInfo.PointerShapeBufferSize > 0)
|
||||
{
|
||||
// update the buffer
|
||||
if (frameInfo.PointerShapeBufferSize > this->pointerSize)
|
||||
DEBUG_WARN("The pointer shape is too large to fit in the buffer, ignoring the shape");
|
||||
else
|
||||
{
|
||||
DXGI_OUTDUPL_POINTER_SHAPE_INFO shapeInfo;
|
||||
status = IDXGIOutputDuplication_GetFramePointerShape(this->dup, this->pointerSize, this->pointerShape, &this->pointerUsed, &shapeInfo);
|
||||
if (FAILED(status))
|
||||
{
|
||||
DEBUG_WINERROR("Failed to get the new pointer shape", status);
|
||||
return CAPTURE_RESULT_ERROR;
|
||||
}
|
||||
|
||||
switch(shapeInfo.Type)
|
||||
{
|
||||
case DXGI_OUTDUPL_POINTER_SHAPE_TYPE_COLOR : this->pointer.format = CAPTURE_FMT_COLOR ; break;
|
||||
case DXGI_OUTDUPL_POINTER_SHAPE_TYPE_MASKED_COLOR: this->pointer.format = CAPTURE_FMT_MASKED; break;
|
||||
case DXGI_OUTDUPL_POINTER_SHAPE_TYPE_MONOCHROME : this->pointer.format = CAPTURE_FMT_MONO ; break;
|
||||
default:
|
||||
DEBUG_ERROR("Unsupported cursor format");
|
||||
return CAPTURE_RESULT_ERROR;
|
||||
}
|
||||
|
||||
this->pointer.w = shapeInfo.Width;
|
||||
this->pointer.h = shapeInfo.Height;
|
||||
this->pointer.pitch = shapeInfo.Pitch;
|
||||
++this->pointer.version;
|
||||
signalPointer = true;
|
||||
}
|
||||
}
|
||||
|
||||
// signal about the pointer update
|
||||
if (signalPointer)
|
||||
os_signalEvent(this->pointerEvent);
|
||||
|
||||
return CAPTURE_RESULT_OK;
|
||||
}
|
||||
|
||||
static CaptureResult dxgi_capture(bool * hasFrameUpdate, bool * hasPointerUpdate)
|
||||
{
|
||||
CaptureResult result = dxgi_capture_int(hasFrameUpdate, hasPointerUpdate);
|
||||
|
||||
// signal pending events if the result was any form of failure or reinit
|
||||
if (result != CAPTURE_RESULT_OK && result != CAPTURE_RESULT_TIMEOUT)
|
||||
{
|
||||
this->reinit = true;
|
||||
os_signalEvent(this->frameEvent );
|
||||
os_signalEvent(this->pointerEvent);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static CaptureResult dxgi_getFrame(CaptureFrame * frame)
|
||||
{
|
||||
assert(this);
|
||||
assert(this->initialized);
|
||||
|
||||
if (this->reinit)
|
||||
return CAPTURE_RESULT_REINIT;
|
||||
|
||||
if (!os_waitEvent(this->frameEvent, TIMEOUT_INFINITE))
|
||||
{
|
||||
DEBUG_ERROR("Failed to wait on the frame event");
|
||||
return CAPTURE_RESULT_ERROR;
|
||||
}
|
||||
|
||||
if (this->reinit)
|
||||
return CAPTURE_RESULT_REINIT;
|
||||
|
||||
Texture * tex = &this->texture[this->texRIndex];
|
||||
|
||||
frame->width = this->width;
|
||||
frame->height = this->height;
|
||||
frame->pitch = this->pitch;
|
||||
frame->stride = this->stride;
|
||||
frame->format = this->format;
|
||||
|
||||
memcpy(frame->data, tex->map.pData, this->pitch * this->height);
|
||||
os_signalEvent(tex->evt);
|
||||
|
||||
if (++this->texRIndex == MAX_TEXTURES)
|
||||
this->texRIndex = 0;
|
||||
|
||||
return CAPTURE_RESULT_OK;
|
||||
}
|
||||
|
||||
static CaptureResult dxgi_getPointer(CapturePointer * pointer)
|
||||
{
|
||||
assert(this);
|
||||
assert(this->initialized);
|
||||
|
||||
if (this->reinit)
|
||||
return CAPTURE_RESULT_REINIT;
|
||||
|
||||
if (!os_waitEvent(this->pointerEvent, TIMEOUT_INFINITE))
|
||||
{
|
||||
DEBUG_ERROR("Failed to wait on the pointer event");
|
||||
return CAPTURE_RESULT_ERROR;
|
||||
}
|
||||
|
||||
if (this->reinit)
|
||||
return CAPTURE_RESULT_REINIT;
|
||||
|
||||
Pointer p;
|
||||
memcpy(&p, &this->pointer, sizeof(Pointer));
|
||||
|
||||
pointer->x = p.x;
|
||||
pointer->y = p.y;
|
||||
pointer->width = p.w;
|
||||
pointer->height = p.h;
|
||||
pointer->pitch = p.pitch;
|
||||
pointer->visible = p.visible;
|
||||
pointer->format = p.format;
|
||||
pointer->shapeUpdate = p.version > this->lastPointer.version;
|
||||
|
||||
memcpy(&this->lastPointer, &p, sizeof(Pointer));
|
||||
|
||||
return CAPTURE_RESULT_OK;
|
||||
}
|
||||
|
||||
static CaptureResult dxgi_releaseFrame()
|
||||
{
|
||||
assert(this);
|
||||
if (!this->needsRelease)
|
||||
return CAPTURE_RESULT_OK;
|
||||
|
||||
HRESULT status = IDXGIOutputDuplication_ReleaseFrame(this->dup);
|
||||
switch(status)
|
||||
{
|
||||
case S_OK:
|
||||
break;
|
||||
|
||||
case DXGI_ERROR_INVALID_CALL:
|
||||
DEBUG_WINERROR("Frame was already released", status);
|
||||
return CAPTURE_RESULT_ERROR;
|
||||
|
||||
case WAIT_ABANDONED:
|
||||
case DXGI_ERROR_ACCESS_LOST:
|
||||
{
|
||||
this->needsRelease = false;
|
||||
return CAPTURE_RESULT_REINIT;
|
||||
}
|
||||
|
||||
default:
|
||||
DEBUG_WINERROR("ReleaseFrame failed", status);
|
||||
return CAPTURE_RESULT_ERROR;
|
||||
}
|
||||
|
||||
this->needsRelease = false;
|
||||
return CAPTURE_RESULT_OK;
|
||||
}
|
||||
|
||||
struct CaptureInterface Capture_DXGI =
|
||||
{
|
||||
.getName = dxgi_getName,
|
||||
.create = dxgi_create,
|
||||
.init = dxgi_init,
|
||||
.deinit = dxgi_deinit,
|
||||
.free = dxgi_free,
|
||||
.getMaxFrameSize = dxgi_getMaxFrameSize,
|
||||
.capture = dxgi_capture,
|
||||
.getFrame = dxgi_getFrame,
|
||||
.getPointer = dxgi_getPointer
|
||||
};
|
641
c-host/platform/Windows/capture/DXGI/src/dxgi_extra.h
Normal file
641
c-host/platform/Windows/capture/DXGI/src/dxgi_extra.h
Normal file
@@ -0,0 +1,641 @@
|
||||
/*
|
||||
Looking Glass - KVM FrameRelay (KVMFR) Client
|
||||
Copyright (C) 2017-2019 Geoffrey McRae <geoff@hostfission.com>
|
||||
https://looking-glass.hostfission.com
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any later
|
||||
version.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with
|
||||
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||
Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include <dxgi.h>
|
||||
#include <d3d11.h>
|
||||
#include <d3dcommon.h>
|
||||
|
||||
// missing declarations in dxgi.h
|
||||
HRESULT __stdcall CreateDXGIFactory1(REFIID riid, void **factory);
|
||||
#define D3D_FEATURE_LEVEL_12_0 0xc000
|
||||
#define D3D_FEATURE_LEVEL_12_1 0xc100
|
||||
|
||||
#define DXGI_ERROR_ACCESS_LOST _HRESULT_TYPEDEF_(0x887A0026L)
|
||||
#define DXGI_ERROR_WAIT_TIMEOUT _HRESULT_TYPEDEF_(0x887A0027L)
|
||||
|
||||
enum DXGI_OUTDUPL_POINTER_SHAPE_TYPE {
|
||||
DXGI_OUTDUPL_POINTER_SHAPE_TYPE_MONOCHROME = 1,
|
||||
DXGI_OUTDUPL_POINTER_SHAPE_TYPE_COLOR,
|
||||
DXGI_OUTDUPL_POINTER_SHAPE_TYPE_MASKED_COLOR
|
||||
};
|
||||
|
||||
typedef struct DXGI_OUTDUPL_DESC {
|
||||
DXGI_MODE_DESC ModeDesc;
|
||||
DXGI_MODE_ROTATION Rotation;
|
||||
BOOL DesktopImageInSystemMemory;
|
||||
}
|
||||
DXGI_OUTDUPL_DESC;
|
||||
|
||||
typedef struct DXGI_OUTDUPL_POINTER_POSITION {
|
||||
POINT Position;
|
||||
BOOL Visible;
|
||||
}
|
||||
DXGI_OUTDUPL_POINTER_POSITION;
|
||||
|
||||
typedef struct DXGI_OUTDUPL_FRAME_INFO {
|
||||
LARGE_INTEGER LastPresentTime;
|
||||
LARGE_INTEGER LastMouseUpdateTime;
|
||||
UINT AccumulatedFrames;
|
||||
BOOL RectsCoalesced;
|
||||
BOOL ProtectedContentMaskedOut;
|
||||
DXGI_OUTDUPL_POINTER_POSITION PointerPosition;
|
||||
UINT TotalMetadataBufferSize;
|
||||
UINT PointerShapeBufferSize;
|
||||
}
|
||||
DXGI_OUTDUPL_FRAME_INFO;
|
||||
|
||||
typedef struct DXGI_OUTDUPL_MOVE_RECT {
|
||||
POINT SourcePoint;
|
||||
RECT DestinationRect;
|
||||
}
|
||||
DXGI_OUTDUPL_MOVE_RECT;
|
||||
|
||||
typedef struct DXGI_OUTDUPL_POINTER_SHAPE_INFO {
|
||||
UINT Type;
|
||||
UINT Width;
|
||||
UINT Height;
|
||||
UINT Pitch;
|
||||
POINT HotSpot;
|
||||
}
|
||||
DXGI_OUTDUPL_POINTER_SHAPE_INFO;
|
||||
|
||||
DEFINE_GUID(IID_IDXGIOutputDuplication, 0x191cfac3, 0xa341, 0x470d, 0xb2,0x6e,0xa8,0x64,0xf4,0x28,0x31,0x9c);
|
||||
|
||||
typedef interface IDXGIOutputDuplication IDXGIOutputDuplication;
|
||||
|
||||
typedef struct IDXGIOutputDuplicationVtbl {
|
||||
BEGIN_INTERFACE
|
||||
|
||||
/*** IUnknown methods ***/
|
||||
HRESULT (STDMETHODCALLTYPE *QueryInterface)(
|
||||
IDXGIOutputDuplication* This,
|
||||
REFIID riid,
|
||||
void **ppvObject);
|
||||
|
||||
ULONG (STDMETHODCALLTYPE *AddRef)(
|
||||
IDXGIOutputDuplication* This);
|
||||
|
||||
ULONG (STDMETHODCALLTYPE *Release)(
|
||||
IDXGIOutputDuplication* This);
|
||||
|
||||
/*** IDXGIObject methods ***/
|
||||
HRESULT (STDMETHODCALLTYPE *SetPrivateData)(
|
||||
IDXGIOutputDuplication* This,
|
||||
REFGUID guid,
|
||||
UINT data_size,
|
||||
const void *data);
|
||||
|
||||
HRESULT (STDMETHODCALLTYPE *SetPrivateDataInterface)(
|
||||
IDXGIOutputDuplication* This,
|
||||
REFGUID guid,
|
||||
const IUnknown *object);
|
||||
|
||||
HRESULT (STDMETHODCALLTYPE *GetPrivateData)(
|
||||
IDXGIOutputDuplication* This,
|
||||
REFGUID guid,
|
||||
UINT *data_size,
|
||||
void *data);
|
||||
|
||||
HRESULT (STDMETHODCALLTYPE *GetParent)(
|
||||
IDXGIOutputDuplication* This,
|
||||
REFIID riid,
|
||||
void **parent);
|
||||
|
||||
/*** IDXGIOutputDuplication methods ***/
|
||||
|
||||
void (STDMETHODCALLTYPE *GetDesc)(
|
||||
IDXGIOutputDuplication* This,
|
||||
DXGI_OUTDUPL_DESC *pDesc);
|
||||
|
||||
HRESULT (STDMETHODCALLTYPE *AcquireNextFrame)(
|
||||
IDXGIOutputDuplication* This,
|
||||
UINT TimeoutInMilliseconds,
|
||||
DXGI_OUTDUPL_FRAME_INFO *pFrameInfo,
|
||||
IDXGIResource **ppDesktopResource);
|
||||
|
||||
HRESULT (STDMETHODCALLTYPE *GetFrameDirtyRects)(
|
||||
IDXGIOutputDuplication* This,
|
||||
UINT DirtyRectsBufferSize,
|
||||
RECT *pDirtyRectsBuffer,
|
||||
UINT *pDirtyRectsBufferSizeRequired);
|
||||
|
||||
HRESULT (STDMETHODCALLTYPE *GetFrameMoveRects)(
|
||||
IDXGIOutputDuplication* This,
|
||||
UINT MoveRectsBufferSize,
|
||||
DXGI_OUTDUPL_MOVE_RECT *pMoveRectBuffer,
|
||||
UINT *pMoveRectsBufferSizeRequired);
|
||||
|
||||
HRESULT (STDMETHODCALLTYPE *GetFramePointerShape)(
|
||||
IDXGIOutputDuplication* This,
|
||||
UINT PointerShapeBufferSize,
|
||||
void *pPointerShapeBuffer,
|
||||
UINT *pPointerShapeBufferSizeRequired,
|
||||
DXGI_OUTDUPL_POINTER_SHAPE_INFO *pPointerShapeInfo);
|
||||
|
||||
HRESULT (STDMETHODCALLTYPE *MapDesktopSurface)(
|
||||
IDXGIOutputDuplication* This,
|
||||
DXGI_MAPPED_RECT *pLockedRect);
|
||||
|
||||
HRESULT (STDMETHODCALLTYPE *UnMapDesktopSurface)(
|
||||
IDXGIOutputDuplication* This);
|
||||
|
||||
HRESULT (STDMETHODCALLTYPE *ReleaseFrame)(
|
||||
IDXGIOutputDuplication* This);
|
||||
|
||||
END_INTERFACE
|
||||
}
|
||||
IDXGIOutputDuplicationVtbl;
|
||||
|
||||
interface IDXGIOutputDuplication {
|
||||
CONST_VTBL IDXGIOutputDuplicationVtbl* lpVtbl;
|
||||
};
|
||||
|
||||
#define IDXGIOutputDuplication_Release(This) (This)->lpVtbl->Release(This)
|
||||
#define IDXGIOutputDuplication_GetDesc(This, pDesc) (This)->lpVtbl->GetDesc(This, pDesc)
|
||||
#define IDXGIOutputDuplication_AcquireNextFrame(This, TimeoutInMilliseconds, pFrameInfo, ppDesktopResource) (This)->lpVtbl->AcquireNextFrame(This, TimeoutInMilliseconds, pFrameInfo, ppDesktopResource)
|
||||
#define IDXGIOutputDuplication_GetFrameDirtyRects(This, DirtyRectsBufferSize, pDirectyRectsBuffer, pDirtyRectsBufferSizeRequired) (This)->lpVtbl->GetFrameDirtyRects(This, DirtyRectsBufferSize, pDirectyRectsBuffer, pDirtyRectsBufferSizeRequired)
|
||||
#define IDXGIOutputDuplication_GetFrameMoveRects(This, MoveRectsBufferSize, pDirtyRectsBuffer, pDirtyRectsBufferSizeRequired) (This)->lpVtbl->GetFrameMoveRects(This, MoveRectsBufferSize, pDirtyRectsBuffer, pDirtyRectsBufferSizeRequired)
|
||||
#define IDXGIOutputDuplication_GetFramePointerShape(This, PointerShapeBufferSize, pPointerShapeBuffer, pPointerShapeBufferSizeRequired, pPointerShapeInfo) (This)->lpVtbl->GetFramePointerShape(This, PointerShapeBufferSize, pPointerShapeBuffer, pPointerShapeBufferSizeRequired, pPointerShapeInfo)
|
||||
#define IDXGIOutputDuplication_MapDesktopSurface(This, pLockedRect) (This)->lpVtbl->MapDesktopSurface(This, pLockedRect)
|
||||
#define IDXGIOutputDuplication_UnMapDesktopSurface(This) (This)->lpVtbl->UnMapDesktopSurface(This)
|
||||
#define IDXGIOutputDuplication_ReleaseFrame(This) (This)->lpVtbl->ReleaseFrame(This)
|
||||
|
||||
typedef struct DXGI_MODE_DESC1
|
||||
{
|
||||
UINT Width;
|
||||
UINT Height;
|
||||
DXGI_RATIONAL RefreshRate;
|
||||
DXGI_FORMAT Format;
|
||||
DXGI_MODE_SCANLINE_ORDER ScanlineOrdering;
|
||||
DXGI_MODE_SCALING Scaling;
|
||||
BOOL Stereo;
|
||||
}
|
||||
DXGI_MODE_DESC1;
|
||||
|
||||
typedef enum DXGI_COLOR_SPACE_TYPE {
|
||||
DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709 = 0,
|
||||
DXGI_COLOR_SPACE_RGB_FULL_G10_NONE_P709 = 1,
|
||||
DXGI_COLOR_SPACE_RGB_STUDIO_G22_NONE_P709 = 2,
|
||||
DXGI_COLOR_SPACE_RGB_STUDIO_G22_NONE_P2020 = 3,
|
||||
DXGI_COLOR_SPACE_RESERVED = 4,
|
||||
DXGI_COLOR_SPACE_YCBCR_FULL_G22_NONE_P709_X601 = 5,
|
||||
DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P601 = 6,
|
||||
DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P601 = 7,
|
||||
DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P709 = 8,
|
||||
DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P709 = 9,
|
||||
DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P2020 = 10,
|
||||
DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P2020 = 11,
|
||||
DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020 = 12,
|
||||
DXGI_COLOR_SPACE_YCBCR_STUDIO_G2084_LEFT_P2020 = 13,
|
||||
DXGI_COLOR_SPACE_RGB_STUDIO_G2084_NONE_P2020 = 14,
|
||||
DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_TOPLEFT_P2020 = 15,
|
||||
DXGI_COLOR_SPACE_YCBCR_STUDIO_G2084_TOPLEFT_P2020 = 16,
|
||||
DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P2020 = 17,
|
||||
DXGI_COLOR_SPACE_YCBCR_STUDIO_GHLG_TOPLEFT_P2020 = 18,
|
||||
DXGI_COLOR_SPACE_YCBCR_FULL_GHLG_TOPLEFT_P2020 = 19,
|
||||
DXGI_COLOR_SPACE_RGB_STUDIO_G24_NONE_P709 = 20,
|
||||
DXGI_COLOR_SPACE_RGB_STUDIO_G24_NONE_P2020 = 21,
|
||||
DXGI_COLOR_SPACE_YCBCR_STUDIO_G24_LEFT_P709 = 22,
|
||||
DXGI_COLOR_SPACE_YCBCR_STUDIO_G24_LEFT_P2020 = 23,
|
||||
DXGI_COLOR_SPACE_YCBCR_STUDIO_G24_TOPLEFT_P2020 = 24,
|
||||
DXGI_COLOR_SPACE_CUSTOM = 0xFFFFFFFF
|
||||
} DXGI_COLOR_SPACE_TYPE;
|
||||
|
||||
DEFINE_GUID(IID_IDXGIOutput1, 0x00cddea8, 0x939b, 0x4b83, 0xa3,0x40,0xa6,0x85,0x22,0x66,0x66,0xcc);
|
||||
|
||||
typedef struct IDXGIOutput1 IDXGIOutput1;
|
||||
|
||||
typedef struct IDXGIOutput1Vtbl {
|
||||
BEGIN_INTERFACE
|
||||
|
||||
/*** IUnknown methods ***/
|
||||
HRESULT (STDMETHODCALLTYPE *QueryInterface)(
|
||||
IDXGIOutput1* This,
|
||||
REFIID riid,
|
||||
void **ppvObject);
|
||||
|
||||
ULONG (STDMETHODCALLTYPE *AddRef)(
|
||||
IDXGIOutput1* This);
|
||||
|
||||
ULONG (STDMETHODCALLTYPE *Release)(
|
||||
IDXGIOutput1* This);
|
||||
|
||||
/*** IDXGIObject methods ***/
|
||||
HRESULT (STDMETHODCALLTYPE *SetPrivateData)(
|
||||
IDXGIOutput1* This,
|
||||
REFGUID guid,
|
||||
UINT data_size,
|
||||
const void *data);
|
||||
|
||||
HRESULT (STDMETHODCALLTYPE *SetPrivateDataInterface)(
|
||||
IDXGIOutput1* This,
|
||||
REFGUID guid,
|
||||
const IUnknown *object);
|
||||
|
||||
HRESULT (STDMETHODCALLTYPE *GetPrivateData)(
|
||||
IDXGIOutput1* This,
|
||||
REFGUID guid,
|
||||
UINT *data_size,
|
||||
void *data);
|
||||
|
||||
HRESULT (STDMETHODCALLTYPE *GetParent)(
|
||||
IDXGIOutput1* This,
|
||||
REFIID riid,
|
||||
void **parent);
|
||||
|
||||
/*** IDXGIOutput methods ***/
|
||||
HRESULT (STDMETHODCALLTYPE *GetDesc)(
|
||||
IDXGIOutput1* This,
|
||||
DXGI_OUTPUT_DESC *desc);
|
||||
|
||||
HRESULT (STDMETHODCALLTYPE *GetDisplayModeList)(
|
||||
IDXGIOutput1* This,
|
||||
DXGI_FORMAT format,
|
||||
UINT flags,
|
||||
UINT *mode_count,
|
||||
DXGI_MODE_DESC *desc);
|
||||
|
||||
HRESULT (STDMETHODCALLTYPE *FindClosestMatchingMode)(
|
||||
IDXGIOutput1* This,
|
||||
const DXGI_MODE_DESC *mode,
|
||||
DXGI_MODE_DESC *closest_match,
|
||||
IUnknown *device);
|
||||
|
||||
HRESULT (STDMETHODCALLTYPE *WaitForVBlank)(
|
||||
IDXGIOutput1* This);
|
||||
|
||||
HRESULT (STDMETHODCALLTYPE *TakeOwnership)(
|
||||
IDXGIOutput1* This,
|
||||
IUnknown *device,
|
||||
WINBOOL exclusive);
|
||||
|
||||
void (STDMETHODCALLTYPE *ReleaseOwnership)(
|
||||
IDXGIOutput1* This);
|
||||
|
||||
HRESULT (STDMETHODCALLTYPE *GetGammaControlCapabilities)(
|
||||
IDXGIOutput1* This,
|
||||
DXGI_GAMMA_CONTROL_CAPABILITIES *gamma_caps);
|
||||
|
||||
HRESULT (STDMETHODCALLTYPE *SetGammaControl)(
|
||||
IDXGIOutput1* This,
|
||||
const DXGI_GAMMA_CONTROL *gamma_control);
|
||||
|
||||
HRESULT (STDMETHODCALLTYPE *GetGammaControl)(
|
||||
IDXGIOutput1* This,
|
||||
DXGI_GAMMA_CONTROL *gamma_control);
|
||||
|
||||
HRESULT (STDMETHODCALLTYPE *SetDisplaySurface)(
|
||||
IDXGIOutput1* This,
|
||||
IDXGISurface *surface);
|
||||
|
||||
HRESULT (STDMETHODCALLTYPE *GetDisplaySurfaceData)(
|
||||
IDXGIOutput1* This,
|
||||
IDXGISurface *surface);
|
||||
|
||||
HRESULT (STDMETHODCALLTYPE *GetFrameStatistics)(
|
||||
IDXGIOutput1* This,
|
||||
DXGI_FRAME_STATISTICS *stats);
|
||||
|
||||
/*** IDXGIOutput1 methods ***/
|
||||
|
||||
HRESULT (STDMETHODCALLTYPE *GetDisplayModeList1)(
|
||||
IDXGIOutput1* This,
|
||||
DXGI_FORMAT EnumFormat,
|
||||
UINT Flags,
|
||||
UINT *pNumModes,
|
||||
DXGI_MODE_DESC1 *pDesc);
|
||||
|
||||
HRESULT (STDMETHODCALLTYPE *FindClosestMatchingMode1)(
|
||||
IDXGIOutput1* This,
|
||||
const DXGI_MODE_DESC1 *pModeToMatch,
|
||||
DXGI_MODE_DESC1 *pClosestMatch,
|
||||
IUnknown *pConcernedDevice);
|
||||
|
||||
HRESULT (STDMETHODCALLTYPE *GetDisplaySurfaceData1)(
|
||||
IDXGIOutput1* This,
|
||||
IDXGIResource *pDestination);
|
||||
|
||||
HRESULT (STDMETHODCALLTYPE *DuplicateOutput)(
|
||||
IDXGIOutput1* This,
|
||||
IUnknown *pDevice,
|
||||
IDXGIOutputDuplication **ppOutputDuplication);
|
||||
|
||||
END_INTERFACE
|
||||
}
|
||||
IDXGIOutput1Vtbl;
|
||||
interface IDXGIOutput1 {
|
||||
CONST_VTBL IDXGIOutput1Vtbl* lpVtbl;
|
||||
};
|
||||
|
||||
#define IDXGIOutput1_DuplicateOutput(This,pDevice,ppOutputDuplication) (This)->lpVtbl->DuplicateOutput(This,pDevice,ppOutputDuplication)
|
||||
#define IDXGIOutput1_Release(This) (This)->lpVtbl->Release(This);
|
||||
|
||||
DEFINE_GUID(IID_IDXGIOutput5, 0x80a07424, 0xab52, 0x42eb, 0x83,0x3c,0x0c,0x42,0xfd,0x28,0x2d,0x98);
|
||||
|
||||
typedef struct IDXGIOutput5 IDXGIOutput5;
|
||||
|
||||
typedef struct IDXGIOutput5Vtbl {
|
||||
BEGIN_INTERFACE
|
||||
|
||||
/*** IUnknown methods ***/
|
||||
HRESULT (STDMETHODCALLTYPE *QueryInterface)(
|
||||
IDXGIOutput5* This,
|
||||
REFIID riid,
|
||||
void **ppvObject);
|
||||
|
||||
ULONG (STDMETHODCALLTYPE *AddRef)(
|
||||
IDXGIOutput5* This);
|
||||
|
||||
ULONG (STDMETHODCALLTYPE *Release)(
|
||||
IDXGIOutput5* This);
|
||||
|
||||
/*** IDXGIObject methods ***/
|
||||
HRESULT (STDMETHODCALLTYPE *SetPrivateData)(
|
||||
IDXGIOutput5* This,
|
||||
REFGUID guid,
|
||||
UINT data_size,
|
||||
const void *data);
|
||||
|
||||
HRESULT (STDMETHODCALLTYPE *SetPrivateDataInterface)(
|
||||
IDXGIOutput5* This,
|
||||
REFGUID guid,
|
||||
const IUnknown *object);
|
||||
|
||||
HRESULT (STDMETHODCALLTYPE *GetPrivateData)(
|
||||
IDXGIOutput5* This,
|
||||
REFGUID guid,
|
||||
UINT *data_size,
|
||||
void *data);
|
||||
|
||||
HRESULT (STDMETHODCALLTYPE *GetParent)(
|
||||
IDXGIOutput5* This,
|
||||
REFIID riid,
|
||||
void **parent);
|
||||
|
||||
/*** IDXGIOutput methods ***/
|
||||
HRESULT (STDMETHODCALLTYPE *GetDesc)(
|
||||
IDXGIOutput5* This,
|
||||
DXGI_OUTPUT_DESC *desc);
|
||||
|
||||
HRESULT (STDMETHODCALLTYPE *GetDisplayModeList)(
|
||||
IDXGIOutput5* This,
|
||||
DXGI_FORMAT format,
|
||||
UINT flags,
|
||||
UINT *mode_count,
|
||||
DXGI_MODE_DESC *desc);
|
||||
|
||||
HRESULT (STDMETHODCALLTYPE *FindClosestMatchingMode)(
|
||||
IDXGIOutput5* This,
|
||||
const DXGI_MODE_DESC *mode,
|
||||
DXGI_MODE_DESC *closest_match,
|
||||
IUnknown *device);
|
||||
|
||||
HRESULT (STDMETHODCALLTYPE *WaitForVBlank)(
|
||||
IDXGIOutput5* This);
|
||||
|
||||
HRESULT (STDMETHODCALLTYPE *TakeOwnership)(
|
||||
IDXGIOutput5* This,
|
||||
IUnknown *device,
|
||||
WINBOOL exclusive);
|
||||
|
||||
void (STDMETHODCALLTYPE *ReleaseOwnership)(
|
||||
IDXGIOutput5* This);
|
||||
|
||||
HRESULT (STDMETHODCALLTYPE *GetGammaControlCapabilities)(
|
||||
IDXGIOutput5* This,
|
||||
DXGI_GAMMA_CONTROL_CAPABILITIES *gamma_caps);
|
||||
|
||||
HRESULT (STDMETHODCALLTYPE *SetGammaControl)(
|
||||
IDXGIOutput5* This,
|
||||
const DXGI_GAMMA_CONTROL *gamma_control);
|
||||
|
||||
HRESULT (STDMETHODCALLTYPE *GetGammaControl)(
|
||||
IDXGIOutput5* This,
|
||||
DXGI_GAMMA_CONTROL *gamma_control);
|
||||
|
||||
HRESULT (STDMETHODCALLTYPE *SetDisplaySurface)(
|
||||
IDXGIOutput5* This,
|
||||
IDXGISurface *surface);
|
||||
|
||||
HRESULT (STDMETHODCALLTYPE *GetDisplaySurfaceData)(
|
||||
IDXGIOutput5* This,
|
||||
IDXGISurface *surface);
|
||||
|
||||
HRESULT (STDMETHODCALLTYPE *GetFrameStatistics)(
|
||||
IDXGIOutput5* This,
|
||||
DXGI_FRAME_STATISTICS *stats);
|
||||
|
||||
/*** IDXGIOutput1 methods ***/
|
||||
|
||||
HRESULT (STDMETHODCALLTYPE *GetDisplayModeList1)(
|
||||
IDXGIOutput5* This,
|
||||
DXGI_FORMAT EnumFormat,
|
||||
UINT Flags,
|
||||
UINT *pNumModes,
|
||||
DXGI_MODE_DESC1 *pDesc);
|
||||
|
||||
HRESULT (STDMETHODCALLTYPE *FindClosestMatchingMode1)(
|
||||
IDXGIOutput5* This,
|
||||
const DXGI_MODE_DESC1 *pModeToMatch,
|
||||
DXGI_MODE_DESC1 *pClosestMatch,
|
||||
IUnknown *pConcernedDevice);
|
||||
|
||||
HRESULT (STDMETHODCALLTYPE *GetDisplaySurfaceData1)(
|
||||
IDXGIOutput5* This,
|
||||
IDXGIResource *pDestination);
|
||||
|
||||
HRESULT (STDMETHODCALLTYPE *DuplicateOutput)(
|
||||
IDXGIOutput5* This,
|
||||
IUnknown *pDevice,
|
||||
IDXGIOutputDuplication **ppOutputDuplication);
|
||||
|
||||
/*** IDXGIOutput2 methods ***/
|
||||
|
||||
BOOL (STDMETHODCALLTYPE *SupportsOverlays)(
|
||||
IDXGIOutput5* This);
|
||||
|
||||
/*** IDXGIOutput3 methods ***/
|
||||
|
||||
HRESULT (STDMETHODCALLTYPE *CheckOverlaySupport)(
|
||||
IDXGIOutput5* This,
|
||||
DXGI_FORMAT EnumFormat,
|
||||
IUnknown *pConcernedDevice,
|
||||
UINT *pFlags);
|
||||
|
||||
/*** IDXGIOutput4 methods ***/
|
||||
|
||||
HRESULT (STDMETHODCALLTYPE *CheckOverlayColorSpaceSupport)(
|
||||
IDXGIOutput5* This,
|
||||
DXGI_FORMAT Format,
|
||||
DXGI_COLOR_SPACE_TYPE ColorSpace,
|
||||
IUnknown *pConcernedDevice,
|
||||
UINT *pFlags);
|
||||
|
||||
/*** IDXGIOutput5 methods ***/
|
||||
|
||||
HRESULT (STDMETHODCALLTYPE *DuplicateOutput1)(
|
||||
IDXGIOutput5* This,
|
||||
IUnknown *pDevice,
|
||||
UINT Flags,
|
||||
UINT SupportedFormatsCount,
|
||||
const DXGI_FORMAT *pSupportedFormats,
|
||||
IDXGIOutputDuplication **ppOutputDuplication);
|
||||
|
||||
END_INTERFACE
|
||||
}
|
||||
IDXGIOutput5Vtbl;
|
||||
interface IDXGIOutput5 {
|
||||
CONST_VTBL IDXGIOutput5Vtbl* lpVtbl;
|
||||
};
|
||||
|
||||
#define IDXGIOutput5_DuplicateOutput1(This,pDevice,Flags,SupportedForamtsCount,pSupportedFormats,ppOutputDuplication) (This)->lpVtbl->DuplicateOutput1(This,pDevice,Flags,SupportedForamtsCount,pSupportedFormats,ppOutputDuplication)
|
||||
#define IDXGIOutput5_Release(This) (This)->lpVtbl->Release(This);
|
||||
|
||||
|
||||
static const char * DXGI_FORMAT_STR[] = {
|
||||
"DXGI_FORMAT_UNKNOWN",
|
||||
"DXGI_FORMAT_R32G32B32A32_TYPELESS",
|
||||
"DXGI_FORMAT_R32G32B32A32_FLOAT",
|
||||
"DXGI_FORMAT_R32G32B32A32_UINT",
|
||||
"DXGI_FORMAT_R32G32B32A32_SINT",
|
||||
"DXGI_FORMAT_R32G32B32_TYPELESS",
|
||||
"DXGI_FORMAT_R32G32B32_FLOAT",
|
||||
"DXGI_FORMAT_R32G32B32_UINT",
|
||||
"DXGI_FORMAT_R32G32B32_SINT",
|
||||
"DXGI_FORMAT_R16G16B16A16_TYPELESS",
|
||||
"DXGI_FORMAT_R16G16B16A16_FLOAT",
|
||||
"DXGI_FORMAT_R16G16B16A16_UNORM",
|
||||
"DXGI_FORMAT_R16G16B16A16_UINT",
|
||||
"DXGI_FORMAT_R16G16B16A16_SNORM",
|
||||
"DXGI_FORMAT_R16G16B16A16_SINT",
|
||||
"DXGI_FORMAT_R32G32_TYPELESS",
|
||||
"DXGI_FORMAT_R32G32_FLOAT",
|
||||
"DXGI_FORMAT_R32G32_UINT",
|
||||
"DXGI_FORMAT_R32G32_SINT",
|
||||
"DXGI_FORMAT_R32G8X24_TYPELESS",
|
||||
"DXGI_FORMAT_D32_FLOAT_S8X24_UINT",
|
||||
"DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS",
|
||||
"DXGI_FORMAT_X32_TYPELESS_G8X24_UINT",
|
||||
"DXGI_FORMAT_R10G10B10A2_TYPELESS",
|
||||
"DXGI_FORMAT_R10G10B10A2_UNORM",
|
||||
"DXGI_FORMAT_R10G10B10A2_UINT",
|
||||
"DXGI_FORMAT_R11G11B10_FLOAT",
|
||||
"DXGI_FORMAT_R8G8B8A8_TYPELESS",
|
||||
"DXGI_FORMAT_R8G8B8A8_UNORM",
|
||||
"DXGI_FORMAT_R8G8B8A8_UNORM_SRGB",
|
||||
"DXGI_FORMAT_R8G8B8A8_UINT",
|
||||
"DXGI_FORMAT_R8G8B8A8_SNORM",
|
||||
"DXGI_FORMAT_R8G8B8A8_SINT",
|
||||
"DXGI_FORMAT_R16G16_TYPELESS",
|
||||
"DXGI_FORMAT_R16G16_FLOAT",
|
||||
"DXGI_FORMAT_R16G16_UNORM",
|
||||
"DXGI_FORMAT_R16G16_UINT",
|
||||
"DXGI_FORMAT_R16G16_SNORM",
|
||||
"DXGI_FORMAT_R16G16_SINT",
|
||||
"DXGI_FORMAT_R32_TYPELESS",
|
||||
"DXGI_FORMAT_D32_FLOAT",
|
||||
"DXGI_FORMAT_R32_FLOAT",
|
||||
"DXGI_FORMAT_R32_UINT",
|
||||
"DXGI_FORMAT_R32_SINT",
|
||||
"DXGI_FORMAT_R24G8_TYPELESS",
|
||||
"DXGI_FORMAT_D24_UNORM_S8_UINT",
|
||||
"DXGI_FORMAT_R24_UNORM_X8_TYPELESS",
|
||||
"DXGI_FORMAT_X24_TYPELESS_G8_UINT",
|
||||
"DXGI_FORMAT_R8G8_TYPELESS",
|
||||
"DXGI_FORMAT_R8G8_UNORM",
|
||||
"DXGI_FORMAT_R8G8_UINT",
|
||||
"DXGI_FORMAT_R8G8_SNORM",
|
||||
"DXGI_FORMAT_R8G8_SINT",
|
||||
"DXGI_FORMAT_R16_TYPELESS",
|
||||
"DXGI_FORMAT_R16_FLOAT",
|
||||
"DXGI_FORMAT_D16_UNORM",
|
||||
"DXGI_FORMAT_R16_UNORM",
|
||||
"DXGI_FORMAT_R16_UINT",
|
||||
"DXGI_FORMAT_R16_SNORM",
|
||||
"DXGI_FORMAT_R16_SINT",
|
||||
"DXGI_FORMAT_R8_TYPELESS",
|
||||
"DXGI_FORMAT_R8_UNORM",
|
||||
"DXGI_FORMAT_R8_UINT",
|
||||
"DXGI_FORMAT_R8_SNORM",
|
||||
"DXGI_FORMAT_R8_SINT",
|
||||
"DXGI_FORMAT_A8_UNORM",
|
||||
"DXGI_FORMAT_R1_UNORM",
|
||||
"DXGI_FORMAT_R9G9B9E5_SHAREDEXP",
|
||||
"DXGI_FORMAT_R8G8_B8G8_UNORM",
|
||||
"DXGI_FORMAT_G8R8_G8B8_UNORM",
|
||||
"DXGI_FORMAT_BC1_TYPELESS",
|
||||
"DXGI_FORMAT_BC1_UNORM",
|
||||
"DXGI_FORMAT_BC1_UNORM_SRGB",
|
||||
"DXGI_FORMAT_BC2_TYPELESS",
|
||||
"DXGI_FORMAT_BC2_UNORM",
|
||||
"DXGI_FORMAT_BC2_UNORM_SRGB",
|
||||
"DXGI_FORMAT_BC3_TYPELESS",
|
||||
"DXGI_FORMAT_BC3_UNORM",
|
||||
"DXGI_FORMAT_BC3_UNORM_SRGB",
|
||||
"DXGI_FORMAT_BC4_TYPELESS",
|
||||
"DXGI_FORMAT_BC4_UNORM",
|
||||
"DXGI_FORMAT_BC4_SNORM",
|
||||
"DXGI_FORMAT_BC5_TYPELESS",
|
||||
"DXGI_FORMAT_BC5_UNORM",
|
||||
"DXGI_FORMAT_BC5_SNORM",
|
||||
"DXGI_FORMAT_B5G6R5_UNORM",
|
||||
"DXGI_FORMAT_B5G5R5A1_UNORM",
|
||||
"DXGI_FORMAT_B8G8R8A8_UNORM",
|
||||
"DXGI_FORMAT_B8G8R8X8_UNORM",
|
||||
"DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM",
|
||||
"DXGI_FORMAT_B8G8R8A8_TYPELESS",
|
||||
"DXGI_FORMAT_B8G8R8A8_UNORM_SRGB",
|
||||
"DXGI_FORMAT_B8G8R8X8_TYPELESS",
|
||||
"DXGI_FORMAT_B8G8R8X8_UNORM_SRGB",
|
||||
"DXGI_FORMAT_BC6H_TYPELESS",
|
||||
"DXGI_FORMAT_BC6H_UF16",
|
||||
"DXGI_FORMAT_BC6H_SF16",
|
||||
"DXGI_FORMAT_BC7_TYPELESS",
|
||||
"DXGI_FORMAT_BC7_UNORM",
|
||||
"DXGI_FORMAT_BC7_UNORM_SRGB",
|
||||
"DXGI_FORMAT_AYUV",
|
||||
"DXGI_FORMAT_Y410",
|
||||
"DXGI_FORMAT_Y416",
|
||||
"DXGI_FORMAT_NV12",
|
||||
"DXGI_FORMAT_P010",
|
||||
"DXGI_FORMAT_P016",
|
||||
"DXGI_FORMAT_420_OPAQUE",
|
||||
"DXGI_FORMAT_YUY2",
|
||||
"DXGI_FORMAT_Y210",
|
||||
"DXGI_FORMAT_Y216",
|
||||
"DXGI_FORMAT_NV11",
|
||||
"DXGI_FORMAT_AI44",
|
||||
"DXGI_FORMAT_IA44",
|
||||
"DXGI_FORMAT_P8",
|
||||
"DXGI_FORMAT_A8P8",
|
||||
"DXGI_FORMAT_B4G4R4A4_UNORM",
|
||||
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
|
||||
|
||||
"DXGI_FORMAT_P208",
|
||||
"DXGI_FORMAT_V208",
|
||||
"DXGI_FORMAT_V408"
|
||||
};
|
||||
|
||||
static const char * GetDXGIFormatStr(DXGI_FORMAT format)
|
||||
{
|
||||
if (format > sizeof(DXGI_FORMAT_STR) / sizeof(const char *))
|
||||
return DXGI_FORMAT_STR[0];
|
||||
return DXGI_FORMAT_STR[format];
|
||||
}
|
27
c-host/platform/Windows/include/windows/windebug.h
Normal file
27
c-host/platform/Windows/include/windows/windebug.h
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
Looking Glass - KVM FrameRelay (KVMFR) Client
|
||||
Copyright (C) 2017-2019 Geoffrey McRae <geoff@hostfission.com>
|
||||
https://looking-glass.hostfission.com
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any later
|
||||
version.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with
|
||||
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||
Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "debug.h"
|
||||
#include <windows.h>
|
||||
|
||||
void DebugWinError(const char * file, const unsigned int line, const char * function, const char * desc, HRESULT status);
|
||||
|
||||
#define DEBUG_WINERROR(x, y) DebugWinError(STRIPPATH(__FILE__), __LINE__, __FUNCTION__, x, y)
|
357
c-host/platform/Windows/src/platform.c
Normal file
357
c-host/platform/Windows/src/platform.c
Normal file
@@ -0,0 +1,357 @@
|
||||
/*
|
||||
Looking Glass - KVM FrameRelay (KVMFR) Client
|
||||
Copyright (C) 2017-2019 Geoffrey McRae <geoff@hostfission.com>
|
||||
https://looking-glass.hostfission.com
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any later
|
||||
version.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with
|
||||
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||
Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include <windows.h>
|
||||
#include <setupapi.h>
|
||||
|
||||
#include "interface/platform.h"
|
||||
#include "debug.h"
|
||||
#include "windows/windebug.h"
|
||||
#include "ivshmem/Public.h"
|
||||
|
||||
static HANDLE shmemHandle = INVALID_HANDLE_VALUE;
|
||||
static bool shmemOwned = false;
|
||||
static IVSHMEM_MMAP shmemMap = {0};
|
||||
static HWND messageWnd;
|
||||
|
||||
struct osThreadHandle
|
||||
{
|
||||
const char * name;
|
||||
osThreadFunction function;
|
||||
void * opaque;
|
||||
HANDLE handle;
|
||||
DWORD threadID;
|
||||
int resultCode;
|
||||
};
|
||||
|
||||
LRESULT CALLBACK DummyWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case WM_CLOSE:
|
||||
DestroyWindow(hwnd);
|
||||
break;
|
||||
|
||||
case WM_DESTROY:
|
||||
PostQuitMessage(0);
|
||||
break;
|
||||
|
||||
default:
|
||||
return DefWindowProc(hwnd, msg, wParam, lParam);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int appThread(void * opaque)
|
||||
{
|
||||
int result = app_main();
|
||||
SendMessage(messageWnd, WM_CLOSE, 0, 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
|
||||
{
|
||||
int result = 0;
|
||||
HDEVINFO deviceInfoSet;
|
||||
PSP_DEVICE_INTERFACE_DETAIL_DATA infData = NULL;
|
||||
SP_DEVICE_INTERFACE_DATA deviceInterfaceData;
|
||||
|
||||
#if 0
|
||||
// redirect stderr to a file
|
||||
{
|
||||
char tempPath[MAX_PATH+1];
|
||||
GetTempPathA(sizeof(tempPath), tempPath);
|
||||
int len = snprintf(NULL, 0, "%slooking-glass-host.txt", tempPath);
|
||||
char * path = malloc(len + 1);
|
||||
sprintf(path, "%slooking-glass-host.txt", tempPath);
|
||||
freopen(path, "a", stderr);
|
||||
free(path);
|
||||
}
|
||||
#endif
|
||||
|
||||
// always flush stderr
|
||||
setbuf(stderr, NULL);
|
||||
|
||||
deviceInfoSet = SetupDiGetClassDevs(NULL, NULL, NULL, DIGCF_PRESENT | DIGCF_ALLCLASSES | DIGCF_DEVICEINTERFACE);
|
||||
memset(&deviceInterfaceData, 0, sizeof(SP_DEVICE_INTERFACE_DATA));
|
||||
deviceInterfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
|
||||
|
||||
if (SetupDiEnumDeviceInterfaces(deviceInfoSet, NULL, &GUID_DEVINTERFACE_IVSHMEM, 0, &deviceInterfaceData) == FALSE)
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
if (error == ERROR_NO_MORE_ITEMS)
|
||||
{
|
||||
DEBUG_WINERROR("Unable to enumerate the device, is it attached?", error);
|
||||
result = -1;
|
||||
goto finish;
|
||||
}
|
||||
|
||||
DEBUG_WINERROR("SetupDiEnumDeviceInterfaces failed", error);
|
||||
result = -1;
|
||||
goto finish;
|
||||
}
|
||||
|
||||
DWORD reqSize = 0;
|
||||
SetupDiGetDeviceInterfaceDetail(deviceInfoSet, &deviceInterfaceData, NULL, 0, &reqSize, NULL);
|
||||
if (!reqSize)
|
||||
{
|
||||
DEBUG_WINERROR("SetupDiGetDeviceInterfaceDetail", GetLastError());
|
||||
result = -1;
|
||||
goto finish;
|
||||
}
|
||||
|
||||
infData = (PSP_DEVICE_INTERFACE_DETAIL_DATA)calloc(reqSize, 1);
|
||||
infData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
|
||||
if (!SetupDiGetDeviceInterfaceDetail(deviceInfoSet, &deviceInterfaceData, infData, reqSize, NULL, NULL))
|
||||
{
|
||||
free(infData);
|
||||
DEBUG_WINERROR("SetupDiGetDeviceInterfaceDetail", GetLastError());
|
||||
result = -1;
|
||||
goto finish;
|
||||
}
|
||||
|
||||
shmemHandle = CreateFile(infData->DevicePath, 0, 0, NULL, OPEN_EXISTING, 0, 0);
|
||||
if (shmemHandle == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
SetupDiDestroyDeviceInfoList(deviceInfoSet);
|
||||
free(infData);
|
||||
DEBUG_WINERROR("CreateFile returned INVALID_HANDLE_VALUE", GetLastError());
|
||||
result = -1;
|
||||
goto finish;
|
||||
}
|
||||
|
||||
free(infData);
|
||||
SetupDiDestroyDeviceInfoList(deviceInfoSet);
|
||||
|
||||
// create a message window so that our message pump works
|
||||
WNDCLASSEX wx = {};
|
||||
wx.cbSize = sizeof(WNDCLASSEX);
|
||||
wx.lpfnWndProc = DummyWndProc;
|
||||
wx.hInstance = hInstance;
|
||||
wx.lpszClassName = "DUMMY_CLASS";
|
||||
if (!RegisterClassEx(&wx))
|
||||
{
|
||||
DEBUG_ERROR("Failed to register message window class");
|
||||
result = -1;
|
||||
goto finish_shmem;
|
||||
}
|
||||
messageWnd = CreateWindowEx(0, "DUMMY_CLASS", "DUMMY_NAME", 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, NULL, NULL);
|
||||
|
||||
osThreadHandle * thread;
|
||||
if (!os_createThread("appThread", appThread, NULL, &thread))
|
||||
{
|
||||
DEBUG_ERROR("Failed to create the main application thread");
|
||||
result = -1;
|
||||
goto finish_shmem;
|
||||
}
|
||||
|
||||
while(true)
|
||||
{
|
||||
MSG msg;
|
||||
BOOL bRet = GetMessage(&msg, NULL, 0, 0);
|
||||
if (bRet > 0)
|
||||
{
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
else if (bRet < 0)
|
||||
{
|
||||
DEBUG_ERROR("Unknown error from GetMessage");
|
||||
result = -1;
|
||||
goto shutdown;
|
||||
}
|
||||
|
||||
DEBUG_INFO("Platform shutdown");
|
||||
break;
|
||||
}
|
||||
|
||||
shutdown:
|
||||
app_quit();
|
||||
if (!os_joinThread(thread, &result))
|
||||
{
|
||||
DEBUG_ERROR("Failed to join the main application thread");
|
||||
result = -1;
|
||||
}
|
||||
finish_shmem:
|
||||
os_shmemUnmap();
|
||||
CloseHandle(shmemHandle);
|
||||
finish:
|
||||
return result;
|
||||
}
|
||||
|
||||
unsigned int os_shmemSize()
|
||||
{
|
||||
IVSHMEM_SIZE size;
|
||||
if (!DeviceIoControl(shmemHandle, IOCTL_IVSHMEM_REQUEST_SIZE, NULL, 0, &size, sizeof(IVSHMEM_SIZE), NULL, NULL))
|
||||
{
|
||||
DEBUG_WINERROR("DeviceIoControl Failed", GetLastError());
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (unsigned int)size;
|
||||
}
|
||||
|
||||
bool os_shmemMmap(void **ptr)
|
||||
{
|
||||
if (shmemOwned)
|
||||
{
|
||||
*ptr = shmemMap.ptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
memset(&shmemMap, 0, sizeof(IVSHMEM_MMAP));
|
||||
if (!DeviceIoControl(
|
||||
shmemHandle,
|
||||
IOCTL_IVSHMEM_REQUEST_MMAP,
|
||||
NULL, 0,
|
||||
&shmemMap, sizeof(IVSHMEM_MMAP),
|
||||
NULL, NULL))
|
||||
{
|
||||
DEBUG_WINERROR("DeviceIoControl Failed", GetLastError());
|
||||
return false;
|
||||
}
|
||||
|
||||
*ptr = shmemMap.ptr;
|
||||
shmemOwned = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void os_shmemUnmap()
|
||||
{
|
||||
if (!shmemOwned)
|
||||
return;
|
||||
|
||||
if (!DeviceIoControl(shmemHandle, IOCTL_IVSHMEM_RELEASE_MMAP, NULL, 0, NULL, 0, NULL, NULL))
|
||||
DEBUG_WINERROR("DeviceIoControl failed", GetLastError());
|
||||
else
|
||||
shmemOwned = false;
|
||||
}
|
||||
|
||||
static DWORD WINAPI threadWrapper(LPVOID lpParameter)
|
||||
{
|
||||
osThreadHandle * handle = (osThreadHandle *)lpParameter;
|
||||
handle->resultCode = handle->function(handle->opaque);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool os_createThread(const char * name, osThreadFunction function, void * opaque, osThreadHandle ** handle)
|
||||
{
|
||||
*handle = (osThreadHandle *)malloc(sizeof(osThreadHandle));
|
||||
(*handle)->name = name;
|
||||
(*handle)->function = function;
|
||||
(*handle)->opaque = opaque;
|
||||
(*handle)->handle = CreateThread(NULL, 0, threadWrapper, *handle, 0, &(*handle)->threadID);
|
||||
|
||||
if (!(*handle)->handle)
|
||||
{
|
||||
free(*handle);
|
||||
*handle = NULL;
|
||||
DEBUG_WINERROR("CreateThread failed", GetLastError());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool os_joinThread(osThreadHandle * handle, int * resultCode)
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
switch(WaitForSingleObject(handle->handle, INFINITE))
|
||||
{
|
||||
case WAIT_OBJECT_0:
|
||||
if (resultCode)
|
||||
*resultCode = handle->resultCode;
|
||||
CloseHandle(handle->handle);
|
||||
free(handle);
|
||||
return true;
|
||||
|
||||
case WAIT_ABANDONED:
|
||||
case WAIT_TIMEOUT:
|
||||
continue;
|
||||
|
||||
case WAIT_FAILED:
|
||||
DEBUG_WINERROR("Wait for thread failed", GetLastError());
|
||||
CloseHandle(handle->handle);
|
||||
free(handle);
|
||||
return false;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
DEBUG_WINERROR("Unknown failure waiting for thread", GetLastError());
|
||||
return false;
|
||||
}
|
||||
|
||||
osEventHandle * os_createEvent(bool autoReset)
|
||||
{
|
||||
HANDLE event = CreateEvent(NULL, autoReset ? FALSE : TRUE, FALSE, NULL);
|
||||
if (!event)
|
||||
{
|
||||
DEBUG_WINERROR("Failed to create the event", GetLastError());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (osEventHandle*)event;
|
||||
}
|
||||
|
||||
void os_freeEvent(osEventHandle * handle)
|
||||
{
|
||||
CloseHandle((HANDLE)handle);
|
||||
}
|
||||
|
||||
bool os_waitEvent(osEventHandle * handle, unsigned int timeout)
|
||||
{
|
||||
const DWORD to = (timeout == TIMEOUT_INFINITE) ? INFINITE : (DWORD)timeout;
|
||||
while(true)
|
||||
{
|
||||
switch(WaitForSingleObject((HANDLE)handle, to))
|
||||
{
|
||||
case WAIT_OBJECT_0:
|
||||
return true;
|
||||
|
||||
case WAIT_ABANDONED:
|
||||
continue;
|
||||
|
||||
case WAIT_TIMEOUT:
|
||||
if (timeout == TIMEOUT_INFINITE)
|
||||
continue;
|
||||
|
||||
return false;
|
||||
|
||||
case WAIT_FAILED:
|
||||
DEBUG_WINERROR("Wait for event failed", GetLastError());
|
||||
return false;
|
||||
}
|
||||
|
||||
DEBUG_ERROR("Unknown wait event return code");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool os_signalEvent(osEventHandle * handle)
|
||||
{
|
||||
return SetEvent((HANDLE)handle);
|
||||
}
|
||||
|
||||
bool os_resetEvent(osEventHandle * handle)
|
||||
{
|
||||
return ResetEvent((HANDLE)handle);
|
||||
}
|
42
c-host/platform/Windows/src/windebug.c
Normal file
42
c-host/platform/Windows/src/windebug.c
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
Looking Glass - KVM FrameRelay (KVMFR) Client
|
||||
Copyright (C) 2017-2019 Geoffrey McRae <geoff@hostfission.com>
|
||||
https://looking-glass.hostfission.com
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any later
|
||||
version.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with
|
||||
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||
Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "windows/windebug.h"
|
||||
#include <stdio.h>
|
||||
|
||||
void DebugWinError(const char * file, const unsigned int line, const char * function, const char * desc, HRESULT status)
|
||||
{
|
||||
char *buffer;
|
||||
FormatMessageA(
|
||||
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER,
|
||||
NULL,
|
||||
status,
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
(char*)&buffer,
|
||||
1024,
|
||||
NULL
|
||||
);
|
||||
|
||||
for(size_t i = strlen(buffer) - 1; i > 0; --i)
|
||||
if (buffer[i] == '\n' || buffer[i] == '\r')
|
||||
buffer[i] = 0;
|
||||
|
||||
fprintf(stderr, "[E] %20s:%-4u | %-30s | %s: 0x%08x (%s)\n", file, line, function, desc, (int)status, buffer);
|
||||
LocalFree(buffer);
|
||||
}
|
Reference in New Issue
Block a user