Skip to content

Commit

Permalink
Significantly Cleaned up the DX screen capturing code
Browse files Browse the repository at this point in the history
  • Loading branch information
smasherprog committed Dec 31, 2016
1 parent 2737244 commit fba27e7
Show file tree
Hide file tree
Showing 13 changed files with 248 additions and 1,019 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.2)
cmake_minimum_required(VERSION 3.0)
project(Screen_Capture)

option(BUILD_EXAMPLE "Build example" On)
Expand Down
31 changes: 6 additions & 25 deletions include/windows/DXCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,7 @@
#include <windows.h>
#include <d3d11.h>
#include <dxgi1_2.h>
#include <DirectXMath.h>
#include <wrl.h>
#include <DirectXMath.h>

#include <d3dcompiler.h>
#include "PixelShader.h"
#include "VertexShader.h"

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

struct FRAME_DATA
{
Microsoft::WRL::ComPtr<ID3D11Texture2D> Frame;
DXGI_OUTDUPL_FRAME_INFO FrameInfo = { 0 };
std::shared_ptr<BYTE> MetaData;
UINT DirtyCount = 0;
UINT MoveCount = 0;
UINT SrcreenIndex = 0;
};
struct DX_RESOURCES
{
Microsoft::WRL::ComPtr<ID3D11Device> Device;
Microsoft::WRL::ComPtr<ID3D11DeviceContext> DeviceContext;
Microsoft::WRL::ComPtr<ID3D11VertexShader> VertexShader;
Microsoft::WRL::ComPtr<ID3D11PixelShader> PixelShader;
Microsoft::WRL::ComPtr<ID3D11InputLayout> InputLayout;
Microsoft::WRL::ComPtr<ID3D11SamplerState> SamplerLinear;
} ;


struct VERTEX
struct DUPLE_RESOURCES
{
DirectX::XMFLOAT3 Pos;
DirectX::XMFLOAT2 TexCoord;
Microsoft::WRL::ComPtr<IDXGIOutputDuplication> OutputDuplication;
DXGI_OUTPUT_DESC OutputDesc;
UINT Output;
};

enum DUPL_RETURN
{
DUPL_RETURN_SUCCESS = 0,
Expand All @@ -70,6 +49,8 @@ namespace SL {
DUPL_RETURN ProcessFailure(ID3D11Device* Device, LPCWSTR Str, LPCWSTR Title, HRESULT hr, HRESULT* ExpectedErrors = nullptr);
DUPL_RETURN DesktopDuplicationSupported();
DUPL_RETURN Initialize(DX_RESOURCES& r);
DUPL_RETURN Initialize(DUPLE_RESOURCES& r, ID3D11Device* device, const UINT output);
RECT ConvertRect(RECT Dirty, const DXGI_OUTPUT_DESC& DeskDesc);

}
}
34 changes: 0 additions & 34 deletions include/windows/DXDuplicationManager.h

This file was deleted.

32 changes: 11 additions & 21 deletions include/windows/DXFrameProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,26 @@

namespace SL {
namespace Screen_Capture {

class DXFrameProcessor {
public:
DXFrameProcessor(DX_RESOURCES& Data, ImageCallback& cb);
DXFrameProcessor();
~DXFrameProcessor();

DUPL_RETURN ProcessFrame(FRAME_DATA* Data, DXGI_OUTPUT_DESC* DeskDesc);
DUPL_RETURN Init(ImageCallback& cb, UINT output);
DUPL_RETURN ProcessFrame(bool* timedout);

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

Microsoft::WRL::ComPtr<ID3D11Device> m_Device;
Microsoft::WRL::ComPtr<ID3D11DeviceContext> m_DeviceContext;
Microsoft::WRL::ComPtr<ID3D11Texture2D> m_MoveSurf;
Microsoft::WRL::ComPtr<ID3D11Texture2D> m_CopySurf;
Microsoft::WRL::ComPtr<ID3D11Texture2D> m_StagingSurf;
Microsoft::WRL::ComPtr<ID3D11VertexShader> m_VertexShader;
Microsoft::WRL::ComPtr<ID3D11PixelShader> m_PixelShader;
Microsoft::WRL::ComPtr<ID3D11InputLayout> m_InputLayout;
Microsoft::WRL::ComPtr<ID3D11RenderTargetView> m_RTV;
Microsoft::WRL::ComPtr<ID3D11SamplerState> m_SamplerLinear;
Microsoft::WRL::ComPtr<ID3D11Device> Device;
Microsoft::WRL::ComPtr<ID3D11DeviceContext> DeviceContext;
Microsoft::WRL::ComPtr<ID3D11Texture2D> StagingSurf;

Microsoft::WRL::ComPtr<IDXGIOutputDuplication> OutputDuplication;
DXGI_OUTPUT_DESC OutputDesc;
UINT Output;
std::vector<BYTE> MetaDataBuffer;

ImageCallback CallBack;

std::unique_ptr<BYTE[]> m_DirtyVertexBufferAlloc;
UINT m_DirtyVertexBufferAllocSize;
};
}
}
8 changes: 0 additions & 8 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ project(Screen_Capturelib)
if(WIN32)
set(SCREEN_CAPTURE_PLATFORM_SRC
${Screen_Capture_SOURCE_DIR}/src/windows/GetMonitors.cpp
${Screen_Capture_SOURCE_DIR}/include/windows/DXDuplicationManager.h
${Screen_Capture_SOURCE_DIR}/src/windows/DXDuplicationManager.cpp
${Screen_Capture_SOURCE_DIR}/include/windows/DXFrameProcessor.h
${Screen_Capture_SOURCE_DIR}/src/windows/DXFrameProcessor.cpp
${Screen_Capture_SOURCE_DIR}/include/windows/DXThread.h
Expand All @@ -14,14 +12,8 @@ if(WIN32)
${Screen_Capture_SOURCE_DIR}/include/windows/DXCommon.h
${Screen_Capture_SOURCE_DIR}/src/windows/DXCommon.cpp
${Screen_Capture_SOURCE_DIR}/src/windows/ThreadRunner.cpp
${Screen_Capture_SOURCE_DIR}/src/windows/PixelShader.hlsl
${Screen_Capture_SOURCE_DIR}/src/windows/VertexShader.hlsl
)

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\"")
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\"")


set(SCREEN_CAPTURE_PLATFORM_INC
${Screen_Capture_SOURCE_DIR}/include/windows
${Screen_Capture_SOURCE_DIR}/src/windows
Expand Down
2 changes: 1 addition & 1 deletion src/ThreadManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void SL::Screen_Capture::ThreadManager::Init(std::shared_ptr<std::atomic_bool>&
m_ThreadHandles.resize(monitors.size());
m_ThreadData.resize(monitors.size());

for (int i = 0; i < monitors.size(); ++i)
for (size_t i = 0; i < monitors.size(); ++i)
{
m_ThreadData[i] = std::make_shared<THREAD_DATA>();
m_ThreadData[i]->UnexpectedErrorEvent = unexpected;
Expand Down
Loading

0 comments on commit fba27e7

Please sign in to comment.