Skip to content

Commit

Permalink
Fixed enabling/disabling of mouse cursor recording for recording sour…
Browse files Browse the repository at this point in the history
…ces.
  • Loading branch information
sskodje committed Jun 26, 2022
1 parent 9125f7b commit 49260fa
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 27 deletions.
9 changes: 6 additions & 3 deletions ScreenRecorderLibNative/CommonTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ struct RECORDING_SOURCE_BASE abstract {
/// Determines if the source is capturing video. If false, it will be blacked out.
/// </summary>
std::optional<bool> IsVideoCaptureEnabled;
/// <summary>
/// Determines if the source is capturing mouse cursors. If false, it will be hidden.
/// </summary>
std::optional<bool> IsCursorCaptureEnabled;

RECORDING_SOURCE_BASE() :
Type(RecordingSourceType::Display),
Expand All @@ -213,7 +217,8 @@ struct RECORDING_SOURCE_BASE abstract {
ID(L""),
Stretch(TextureStretchMode::Uniform),
Anchor(ContentAnchor::TopLeft),
IsVideoCaptureEnabled(std::nullopt)
IsVideoCaptureEnabled(std::nullopt),
IsCursorCaptureEnabled(std::nullopt)
{

}
Expand Down Expand Up @@ -254,7 +259,6 @@ struct RECORDING_OVERLAY_DATA
struct RECORDING_SOURCE : RECORDING_SOURCE_BASE
{
std::optional<RecordingSourceApi> SourceApi;
std::optional<bool> IsCursorCaptureEnabled;
/// <summary>
/// An optional custom area of the source to record. Must be equal or smaller than the source area. A smaller area will crop the source.
/// </summary>
Expand All @@ -266,7 +270,6 @@ struct RECORDING_SOURCE : RECORDING_SOURCE_BASE

RECORDING_SOURCE() :
RECORDING_SOURCE_BASE(),
IsCursorCaptureEnabled(std::nullopt),
SourceRect{ std::nullopt },
Position{ std::nullopt },
SourceApi(std::nullopt)
Expand Down
6 changes: 0 additions & 6 deletions ScreenRecorderLibNative/DesktopDuplicationCapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ using namespace DirectX;
DesktopDuplicationCapture::DesktopDuplicationCapture() :
CaptureBase(),
m_IsInitialized(false),
m_IsCursorCaptureEnabled(false),
m_DeskDupl(nullptr),
m_MetaDataBuffer(nullptr),
m_MetaDataSize(0),
Expand Down Expand Up @@ -39,11 +38,6 @@ DesktopDuplicationCapture::DesktopDuplicationCapture() :
RtlZeroMemory(&m_OutputDesc, sizeof(m_OutputDesc));
}

DesktopDuplicationCapture::DesktopDuplicationCapture(_In_ bool isCursorCaptureEnabled) :DesktopDuplicationCapture()
{
m_IsCursorCaptureEnabled = isCursorCaptureEnabled;
}

DesktopDuplicationCapture::~DesktopDuplicationCapture()
{
SafeRelease(&m_DeskDupl);
Expand Down
2 changes: 0 additions & 2 deletions ScreenRecorderLibNative/DesktopDuplicationCapture.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class DesktopDuplicationCapture : public CaptureBase
{
public:
DesktopDuplicationCapture();
DesktopDuplicationCapture(_In_ bool isCursorCaptureEnabled);
virtual ~DesktopDuplicationCapture();
virtual HRESULT Initialize(_In_ ID3D11DeviceContext *pDeviceContext, _In_ ID3D11Device *pDevice) override;
virtual HRESULT AcquireNextFrame(_In_ DWORD timeoutMillis, _Outptr_opt_ ID3D11Texture2D **ppFrame) override;
Expand Down Expand Up @@ -40,7 +39,6 @@ class DesktopDuplicationCapture : public CaptureBase
float m_CursorScaleX;
float m_CursorScaleY;

bool m_IsCursorCaptureEnabled;
bool m_IsInitialized;
LARGE_INTEGER m_LastGrabTimeStamp;
LARGE_INTEGER m_LastSampleUpdatedTimeStamp;
Expand Down
10 changes: 4 additions & 6 deletions ScreenRecorderLibNative/ScreenCaptureManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -590,10 +590,10 @@ DWORD WINAPI CaptureThreadProc(_In_ void *Param)
}
case RecordingSourceType::Display: {
if (pSource->SourceApi == RecordingSourceApi::DesktopDuplication) {
pRecordingSourceCapture = make_unique<DesktopDuplicationCapture>(pSource->IsCursorCaptureEnabled.value_or(false));
pRecordingSourceCapture = make_unique<DesktopDuplicationCapture>();
}
else if (pSource->SourceApi == RecordingSourceApi::WindowsGraphicsCapture) {
pRecordingSourceCapture = make_unique<WindowsGraphicsCapture>(pSource->IsCursorCaptureEnabled.value_or(false));
pRecordingSourceCapture = make_unique<WindowsGraphicsCapture>();
}
break;
}
Expand Down Expand Up @@ -649,7 +649,7 @@ DWORD WINAPI CaptureThreadProc(_In_ void *Param)
hr = pRecordingSourceCapture->Initialize(pSourceData->DxRes.Context, pSourceData->DxRes.Device);
if (FAILED(hr))
{
LOG_ERROR(L"Failed to initialize recording source %ls",pRecordingSourceCapture->Name().c_str());
LOG_ERROR(L"Failed to initialize recording source %ls", pRecordingSourceCapture->Name().c_str());
goto Exit;
}
hr = pRecordingSourceCapture->StartCapture(*pSource);
Expand Down Expand Up @@ -733,7 +733,7 @@ DWORD WINAPI CaptureThreadProc(_In_ void *Param)
LONGLONG waitTimeMillis = duration_cast<milliseconds>(chrono::steady_clock::now() - WaitForFrameBegin).count();
LOG_TRACE(L"CaptureThreadProc waited for busy shared surface for %lld ms", waitTimeMillis);
}
if (pSource->IsCursorCaptureEnabled.value_or(false)) {
if (pSource->IsCursorCaptureEnabled.value_or(true)) {
// Get mouse info
hr = pRecordingSourceCapture->GetMouse(pData->PtrInfo, pSourceData->FrameCoordinates, pSourceData->OffsetX, pSourceData->OffsetY);
if (FAILED(hr)) {
Expand All @@ -744,7 +744,6 @@ DWORD WINAPI CaptureThreadProc(_In_ void *Param)
pData->PtrInfo->Visible = false;
}


if (pSource->IsVideoCaptureEnabled.value_or(true)) {
if (IsSharedSurfaceDirty) {
//The screen has been blacked out, so we restore a full frame to the shared surface before starting to apply updates.
Expand All @@ -762,7 +761,6 @@ DWORD WINAPI CaptureThreadProc(_In_ void *Param)
IsCapturingVideo = false;
}
}

}
if (hr == DXGI_ERROR_WAIT_TIMEOUT) {
continue;
Expand Down
14 changes: 6 additions & 8 deletions ScreenRecorderLibNative/WindowsGraphicsCapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ WindowsGraphicsCapture::WindowsGraphicsCapture() :
m_TextureManager(nullptr),
m_HaveDeliveredFirstFrame(false),
m_IsInitialized(false),
m_IsCursorCaptureEnabled(false),
m_MouseManager(nullptr),
m_QPCFrequency{ 0 },
m_LastSampleReceivedTimeStamp{ 0 },
Expand All @@ -49,11 +48,7 @@ WindowsGraphicsCapture::WindowsGraphicsCapture() :
RtlZeroMemory(&m_CurrentData, sizeof(m_CurrentData));
m_NewFrameEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
QueryPerformanceFrequency(&m_QPCFrequency);
}

WindowsGraphicsCapture::WindowsGraphicsCapture(_In_ bool isCursorCaptureEnabled) :WindowsGraphicsCapture()
{
m_IsCursorCaptureEnabled = isCursorCaptureEnabled;
m_IsCursorCapturePropertyAvailable = IsGraphicsCaptureCursorCapturePropertyAvailable();
}

WindowsGraphicsCapture::~WindowsGraphicsCapture()
Expand Down Expand Up @@ -234,8 +229,8 @@ HRESULT WindowsGraphicsCapture::StartCapture(_In_ RECORDING_SOURCE_BASE &recordi
m_framePool.FrameArrived({ this, &WindowsGraphicsCapture::OnFrameArrived });

WINRT_ASSERT(m_session != nullptr);
if (IsGraphicsCaptureCursorCapturePropertyAvailable()) {
m_session.IsCursorCaptureEnabled(m_IsCursorCaptureEnabled);
if (m_IsCursorCapturePropertyAvailable) {
m_session.IsCursorCaptureEnabled(m_RecordingSource->IsCursorCaptureEnabled.value_or(true));
}
m_session.StartCapture();
m_closed.store(false);
Expand Down Expand Up @@ -493,6 +488,9 @@ void WindowsGraphicsCapture::OnFrameArrived(winrt::Direct3D11CaptureFramePool co
{
QueryPerformanceCounter(&m_LastSampleReceivedTimeStamp);
SetEvent(m_NewFrameEvent);
if (m_session.IsCursorCaptureEnabled() != m_RecordingSource->IsCursorCaptureEnabled.value_or(true)) {
m_session.IsCursorCaptureEnabled(m_RecordingSource->IsCursorCaptureEnabled.value_or(true));
}
}

HRESULT WindowsGraphicsCapture::GetNextFrame(_In_ DWORD timeoutMillis, _Inout_ GRAPHICS_FRAME_DATA *pData)
Expand Down
3 changes: 1 addition & 2 deletions ScreenRecorderLibNative/WindowsGraphicsCapture.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class WindowsGraphicsCapture : public CaptureBase
{
public:
WindowsGraphicsCapture();
WindowsGraphicsCapture(_In_ bool isCursorCaptureEnabled);
virtual ~WindowsGraphicsCapture();
virtual HRESULT Initialize(_In_ ID3D11DeviceContext *pDeviceContext, _In_ ID3D11Device *pDevice) override;
virtual HRESULT AcquireNextFrame(_In_ DWORD timeoutMillis, _Outptr_opt_ ID3D11Texture2D **ppFrame) override;
Expand Down Expand Up @@ -40,7 +39,7 @@ class WindowsGraphicsCapture : public CaptureBase
int m_CursorOffsetY;
float m_CursorScaleX;
float m_CursorScaleY;
bool m_IsCursorCaptureEnabled;
bool m_IsCursorCapturePropertyAvailable;
bool m_IsInitialized;
HANDLE m_NewFrameEvent;
bool m_HaveDeliveredFirstFrame;
Expand Down

0 comments on commit 49260fa

Please sign in to comment.