Skip to content

Commit fba27e7

Browse files
committed
Significantly Cleaned up the DX screen capturing code
1 parent 2737244 commit fba27e7

13 files changed

+248
-1019
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.2)
1+
cmake_minimum_required(VERSION 3.0)
22
project(Screen_Capture)
33

44
option(BUILD_EXAMPLE "Build example" On)

include/windows/DXCommon.h

+6-25
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,7 @@
1515
#include <windows.h>
1616
#include <d3d11.h>
1717
#include <dxgi1_2.h>
18-
#include <DirectXMath.h>
1918
#include <wrl.h>
20-
#include <DirectXMath.h>
21-
22-
#include <d3dcompiler.h>
23-
#include "PixelShader.h"
24-
#include "VertexShader.h"
2519

2620
#pragma comment(lib,"dxgi.lib")
2721
#pragma comment(lib,"d3d11.lib")
@@ -34,32 +28,17 @@ namespace SL {
3428
extern HRESULT FrameInfoExpectedErrors[];
3529
extern HRESULT EnumOutputsExpectedErrors[];
3630

37-
struct FRAME_DATA
38-
{
39-
Microsoft::WRL::ComPtr<ID3D11Texture2D> Frame;
40-
DXGI_OUTDUPL_FRAME_INFO FrameInfo = { 0 };
41-
std::shared_ptr<BYTE> MetaData;
42-
UINT DirtyCount = 0;
43-
UINT MoveCount = 0;
44-
UINT SrcreenIndex = 0;
45-
};
4631
struct DX_RESOURCES
4732
{
4833
Microsoft::WRL::ComPtr<ID3D11Device> Device;
4934
Microsoft::WRL::ComPtr<ID3D11DeviceContext> DeviceContext;
50-
Microsoft::WRL::ComPtr<ID3D11VertexShader> VertexShader;
51-
Microsoft::WRL::ComPtr<ID3D11PixelShader> PixelShader;
52-
Microsoft::WRL::ComPtr<ID3D11InputLayout> InputLayout;
53-
Microsoft::WRL::ComPtr<ID3D11SamplerState> SamplerLinear;
5435
} ;
55-
56-
57-
struct VERTEX
36+
struct DUPLE_RESOURCES
5837
{
59-
DirectX::XMFLOAT3 Pos;
60-
DirectX::XMFLOAT2 TexCoord;
38+
Microsoft::WRL::ComPtr<IDXGIOutputDuplication> OutputDuplication;
39+
DXGI_OUTPUT_DESC OutputDesc;
40+
UINT Output;
6141
};
62-
6342
enum DUPL_RETURN
6443
{
6544
DUPL_RETURN_SUCCESS = 0,
@@ -70,6 +49,8 @@ namespace SL {
7049
DUPL_RETURN ProcessFailure(ID3D11Device* Device, LPCWSTR Str, LPCWSTR Title, HRESULT hr, HRESULT* ExpectedErrors = nullptr);
7150
DUPL_RETURN DesktopDuplicationSupported();
7251
DUPL_RETURN Initialize(DX_RESOURCES& r);
52+
DUPL_RETURN Initialize(DUPLE_RESOURCES& r, ID3D11Device* device, const UINT output);
53+
RECT ConvertRect(RECT Dirty, const DXGI_OUTPUT_DESC& DeskDesc);
7354

7455
}
7556
}

include/windows/DXDuplicationManager.h

-34
This file was deleted.

include/windows/DXFrameProcessor.h

+11-21
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,26 @@
55

66
namespace SL {
77
namespace Screen_Capture {
8-
98
class DXFrameProcessor {
109
public:
11-
DXFrameProcessor(DX_RESOURCES& Data, ImageCallback& cb);
10+
DXFrameProcessor();
1211
~DXFrameProcessor();
13-
14-
DUPL_RETURN ProcessFrame(FRAME_DATA* Data, DXGI_OUTPUT_DESC* DeskDesc);
12+
DUPL_RETURN Init(ImageCallback& cb, UINT output);
13+
DUPL_RETURN ProcessFrame(bool* timedout);
1514

1615
private:
17-
// methods
18-
DUPL_RETURN CopyDirty(ID3D11Texture2D* SrcSurface, RECT* DirtyBuffer, UINT DirtyCount, DXGI_OUTPUT_DESC* DeskDesc);
19-
DUPL_RETURN CopyMove(ID3D11Texture2D* SrcSurface, DXGI_OUTDUPL_MOVE_RECT* MoveBuffer, UINT MoveCount, DXGI_OUTPUT_DESC* DeskDesc);
20-
void SetDirtyVert(VERTEX* Vertices, RECT* Dirty, DXGI_OUTPUT_DESC* DeskDesc, D3D11_TEXTURE2D_DESC* ThisDesc);
21-
void SetMoveRect(RECT* SrcRect, RECT* DestRect, DXGI_OUTPUT_DESC* DeskDesc, DXGI_OUTDUPL_MOVE_RECT* MoveRect, INT TexWidth, INT TexHeight);
2216

23-
Microsoft::WRL::ComPtr<ID3D11Device> m_Device;
24-
Microsoft::WRL::ComPtr<ID3D11DeviceContext> m_DeviceContext;
25-
Microsoft::WRL::ComPtr<ID3D11Texture2D> m_MoveSurf;
26-
Microsoft::WRL::ComPtr<ID3D11Texture2D> m_CopySurf;
27-
Microsoft::WRL::ComPtr<ID3D11Texture2D> m_StagingSurf;
28-
Microsoft::WRL::ComPtr<ID3D11VertexShader> m_VertexShader;
29-
Microsoft::WRL::ComPtr<ID3D11PixelShader> m_PixelShader;
30-
Microsoft::WRL::ComPtr<ID3D11InputLayout> m_InputLayout;
31-
Microsoft::WRL::ComPtr<ID3D11RenderTargetView> m_RTV;
32-
Microsoft::WRL::ComPtr<ID3D11SamplerState> m_SamplerLinear;
17+
Microsoft::WRL::ComPtr<ID3D11Device> Device;
18+
Microsoft::WRL::ComPtr<ID3D11DeviceContext> DeviceContext;
19+
Microsoft::WRL::ComPtr<ID3D11Texture2D> StagingSurf;
20+
21+
Microsoft::WRL::ComPtr<IDXGIOutputDuplication> OutputDuplication;
22+
DXGI_OUTPUT_DESC OutputDesc;
23+
UINT Output;
24+
std::vector<BYTE> MetaDataBuffer;
3325

3426
ImageCallback CallBack;
3527

36-
std::unique_ptr<BYTE[]> m_DirtyVertexBufferAlloc;
37-
UINT m_DirtyVertexBufferAllocSize;
3828
};
3929
}
4030
}

lib/CMakeLists.txt

-8
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ project(Screen_Capturelib)
33
if(WIN32)
44
set(SCREEN_CAPTURE_PLATFORM_SRC
55
${Screen_Capture_SOURCE_DIR}/src/windows/GetMonitors.cpp
6-
${Screen_Capture_SOURCE_DIR}/include/windows/DXDuplicationManager.h
7-
${Screen_Capture_SOURCE_DIR}/src/windows/DXDuplicationManager.cpp
86
${Screen_Capture_SOURCE_DIR}/include/windows/DXFrameProcessor.h
97
${Screen_Capture_SOURCE_DIR}/src/windows/DXFrameProcessor.cpp
108
${Screen_Capture_SOURCE_DIR}/include/windows/DXThread.h
@@ -14,14 +12,8 @@ if(WIN32)
1412
${Screen_Capture_SOURCE_DIR}/include/windows/DXCommon.h
1513
${Screen_Capture_SOURCE_DIR}/src/windows/DXCommon.cpp
1614
${Screen_Capture_SOURCE_DIR}/src/windows/ThreadRunner.cpp
17-
${Screen_Capture_SOURCE_DIR}/src/windows/PixelShader.hlsl
18-
${Screen_Capture_SOURCE_DIR}/src/windows/VertexShader.hlsl
1915
)
2016

21-
set_source_files_properties(${Screen_Capture_SOURCE_DIR}/src/windows/PixelShader.hlsl PROPERTIES VS_SHADER_TYPE Pixel VS_SHADER_MODEL 4.0 VS_SHADER_ENTRYPOINT PS VS_SHADER_FLAGS "/DFLAGS_ADDED /Fh \"../../src/windows/%(Filename).h\"")
22-
set_source_files_properties(${Screen_Capture_SOURCE_DIR}/src/windows/VertexShader.hlsl PROPERTIES VS_SHADER_TYPE Vertex VS_SHADER_MODEL 4.0 VS_SHADER_ENTRYPOINT VS VS_SHADER_FLAGS "/DFLAGS_ADDED /Fh \"../../src/windows/%(Filename).h\"")
23-
24-
2517
set(SCREEN_CAPTURE_PLATFORM_INC
2618
${Screen_Capture_SOURCE_DIR}/include/windows
2719
${Screen_Capture_SOURCE_DIR}/src/windows

src/ThreadManager.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ void SL::Screen_Capture::ThreadManager::Init(std::shared_ptr<std::atomic_bool>&
1717
m_ThreadHandles.resize(monitors.size());
1818
m_ThreadData.resize(monitors.size());
1919

20-
for (int i = 0; i < monitors.size(); ++i)
20+
for (size_t i = 0; i < monitors.size(); ++i)
2121
{
2222
m_ThreadData[i] = std::make_shared<THREAD_DATA>();
2323
m_ThreadData[i]->UnexpectedErrorEvent = unexpected;

0 commit comments

Comments
 (0)