diff --git a/.gitmodules b/.gitmodules index b63750f8..e6f85da7 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "vendor/kvm-guest-drivers-windows"] path = vendor/kvm-guest-drivers-windows url = https://github.com/virtio-win/kvm-guest-drivers-windows.git +[submodule "vendor/DXGICaptureSample"] + path = vendor/DXGICaptureSample + url = https://github.com/pgurenko/DXGICaptureSample.git diff --git a/host/Capture/DXGI.cpp b/host/Capture/DXGI.cpp index 1b6c5c47..3b1b3b2a 100644 --- a/host/Capture/DXGI.cpp +++ b/host/Capture/DXGI.cpp @@ -19,10 +19,12 @@ Place, Suite 330, Boston, MA 02111-1307 USA #include "DXGI.h" using namespace Capture; -DXGI::DXGI() : - m_initialized(false) -{ +#include "common\debug.h" +DXGI::DXGI() : + m_initialized(false), + m_manager(NULL) +{ } DXGI::~DXGI() @@ -35,12 +37,32 @@ bool DXGI::Initialize() if (m_initialized) DeInitialize(); + if (FAILED(CoInitializeEx(NULL, COINIT_MULTITHREADED))) + { + DEBUG_ERROR("CoInitializeEx failed"); + return false; + } + + m_manager = new DXGIManager(); + m_manager->SetCaptureSource(CSDesktop); + + RECT rect; + m_manager->GetOutputRect(rect); + m_width = rect.right - rect.left; + m_height = rect.bottom - rect.top; + m_initialized = true; return true; } void DXGI::DeInitialize() { + if (m_manager) + { + delete m_manager; + m_manager = NULL; + } + m_initialized = false; } @@ -49,7 +71,7 @@ FrameType DXGI::GetFrameType() if (!m_initialized) return FRAME_TYPE_INVALID; - return FrameType(); + return FRAME_TYPE_ARGB; } FrameComp DXGI::GetFrameCompression() @@ -57,15 +79,39 @@ FrameComp DXGI::GetFrameCompression() if (!m_initialized) return FRAME_COMP_NONE; - return FrameComp(); + return FRAME_COMP_NONE; } size_t DXGI::GetMaxFrameSize() { - return size_t(); + if (!m_initialized); + return 0; + + return m_width * m_height * 4; } bool DXGI::GrabFrame(FrameInfo & frame) { - return false; + RECT rect; + m_manager->GetOutputRect(rect); + m_width = rect.right - rect.left; + m_height = rect.bottom - rect.top; + + HRESULT result; + for(int i = 0; i < 2; ++i) + { + result = m_manager->GetOutputBits((BYTE*)frame.buffer, rect); + if (SUCCEEDED(result)) + break; + } + + if (FAILED(result)) + return false; + + + frame.width = m_width; + frame.height = m_height; + frame.stride = m_width; + frame.outSize = m_width * m_height * 4; + return true; } \ No newline at end of file diff --git a/host/Capture/DXGI.h b/host/Capture/DXGI.h index f90b293c..1b8a4437 100644 --- a/host/Capture/DXGI.h +++ b/host/Capture/DXGI.h @@ -19,6 +19,10 @@ Place, Suite 330, Boston, MA 02111-1307 USA #pragma once #include "ICapture.h" +#include + +#define W32_LEAN_AND_MEAN +#include namespace Capture { @@ -35,6 +39,9 @@ namespace Capture bool GrabFrame(struct FrameInfo & frame); private: - bool m_initialized; + bool m_initialized; + DXGIManager * m_manager; + unsigned int m_width; + unsigned int m_height; }; }; \ No newline at end of file diff --git a/host/kvm-ivshmem-host.vcxproj b/host/kvm-ivshmem-host.vcxproj index 51b6c650..30f12e94 100644 --- a/host/kvm-ivshmem-host.vcxproj +++ b/host/kvm-ivshmem-host.vcxproj @@ -96,7 +96,7 @@ Windows true - kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;setupapi.lib;%(AdditionalDependencies) + kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;setupapi.lib;d3d11.lib;dxgi.lib;gdiplus.lib;%(AdditionalDependencies) %(AdditionalLibraryDirectories) @@ -113,7 +113,7 @@ Windows true - kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;setupapi.lib;%(AdditionalDependencies) + kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;setupapi.lib;d3d11.lib;dxgi.lib;gdiplus.lib;%(AdditionalDependencies) %(AdditionalLibraryDirectories) @@ -134,7 +134,7 @@ true true true - kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;setupapi.lib;%(AdditionalDependencies) + kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;setupapi.lib;d3d11.lib;dxgi.lib;gdiplus.lib;%(AdditionalDependencies) %(AdditionalLibraryDirectories) @@ -155,11 +155,12 @@ true true true - kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;setupapi.lib;%(AdditionalDependencies) + kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;setupapi.lib;d3d11.lib;dxgi.lib;gdiplus.lib;%(AdditionalDependencies) %(AdditionalLibraryDirectories) + @@ -168,6 +169,7 @@ + diff --git a/host/kvm-ivshmem-host.vcxproj.filters b/host/kvm-ivshmem-host.vcxproj.filters index 7574fa53..4cf57003 100644 --- a/host/kvm-ivshmem-host.vcxproj.filters +++ b/host/kvm-ivshmem-host.vcxproj.filters @@ -39,6 +39,9 @@ Source Files\Capture + + Source Files\Capture + @@ -65,5 +68,8 @@ Header Files\Capture + + Header Files\Capture + \ No newline at end of file diff --git a/vendor/DXGICaptureSample b/vendor/DXGICaptureSample new file mode 160000 index 00000000..9e304f24 --- /dev/null +++ b/vendor/DXGICaptureSample @@ -0,0 +1 @@ +Subproject commit 9e304f24b5b11bbd1c61a9c1c528693cd2843c5d