call ReleaseFrame() just before AcquireNextFrame() #18.
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -46,7 +46,8 @@ void Duplicator::InitializeDevice()
|
|||||||
void Duplicator::InitializeDuplication()
|
void Duplicator::InitializeDuplication()
|
||||||
{
|
{
|
||||||
ComPtr<IDXGIOutput1> output1;
|
ComPtr<IDXGIOutput1> output1;
|
||||||
if (FAILED(monitor_->GetOutput().As(&output1))) {
|
if (FAILED(monitor_->GetOutput().As(&output1)))
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -243,6 +244,8 @@ void Duplicator::Duplicate(UINT timeout)
|
|||||||
|
|
||||||
if (!dupl_ || !device_) return;
|
if (!dupl_ || !device_) return;
|
||||||
|
|
||||||
|
Release();
|
||||||
|
|
||||||
ComPtr<IDXGIResource> resource;
|
ComPtr<IDXGIResource> resource;
|
||||||
DXGI_OUTDUPL_FRAME_INFO frameInfo;
|
DXGI_OUTDUPL_FRAME_INFO frameInfo;
|
||||||
const auto hr = dupl_->AcquireNextFrame(timeout, &frameInfo, &resource);
|
const auto hr = dupl_->AcquireNextFrame(timeout, &frameInfo, &resource);
|
||||||
@@ -285,33 +288,7 @@ void Duplicator::Duplicate(UINT timeout)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScopedReleaser releaser([this]
|
isFrameAcquired_ = true;
|
||||||
{
|
|
||||||
const auto hr = dupl_->ReleaseFrame();
|
|
||||||
if (FAILED(hr))
|
|
||||||
{
|
|
||||||
switch (hr)
|
|
||||||
{
|
|
||||||
case DXGI_ERROR_ACCESS_LOST:
|
|
||||||
{
|
|
||||||
Debug::Log("Duplicator::Duplicate() => DXGI_ERROR_ACCESS_LOST.");
|
|
||||||
state_ = State::AccessLost;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case DXGI_ERROR_INVALID_CALL:
|
|
||||||
{
|
|
||||||
Debug::Error("Duplicator::Duplicate() => DXGI_ERROR_INVALID_CALL.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
state_ = State::Unknown;
|
|
||||||
Debug::Error("Duplicator::Duplicate() => Unknown Error.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
ComPtr<ID3D11Texture2D> texture;
|
ComPtr<ID3D11Texture2D> texture;
|
||||||
if (FAILED(resource.As(&texture)))
|
if (FAILED(resource.As(&texture)))
|
||||||
@@ -349,6 +326,39 @@ void Duplicator::Duplicate(UINT timeout)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Duplicator::Release()
|
||||||
|
{
|
||||||
|
if (!isFrameAcquired_) return;
|
||||||
|
|
||||||
|
const auto hr = dupl_->ReleaseFrame();
|
||||||
|
if (FAILED(hr))
|
||||||
|
{
|
||||||
|
switch (hr)
|
||||||
|
{
|
||||||
|
case DXGI_ERROR_ACCESS_LOST:
|
||||||
|
{
|
||||||
|
Debug::Log("Duplicator::Duplicate() => DXGI_ERROR_ACCESS_LOST.");
|
||||||
|
state_ = State::AccessLost;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DXGI_ERROR_INVALID_CALL:
|
||||||
|
{
|
||||||
|
Debug::Error("Duplicator::Duplicate() => DXGI_ERROR_INVALID_CALL.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
state_ = State::Unknown;
|
||||||
|
Debug::Error("Duplicator::Duplicate() => Unknown Error.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
isFrameAcquired_ = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Duplicator::UpdateCursor(
|
void Duplicator::UpdateCursor(
|
||||||
const ComPtr<ID3D11Texture2D>& texture,
|
const ComPtr<ID3D11Texture2D>& texture,
|
||||||
const DXGI_OUTDUPL_FRAME_INFO& frameInfo)
|
const DXGI_OUTDUPL_FRAME_INFO& frameInfo)
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ private:
|
|||||||
void CheckUnityAdapter();
|
void CheckUnityAdapter();
|
||||||
|
|
||||||
void Duplicate(UINT timeout);
|
void Duplicate(UINT timeout);
|
||||||
|
void Release();
|
||||||
|
|
||||||
void UpdateCursor(
|
void UpdateCursor(
|
||||||
const Microsoft::WRL::ComPtr<ID3D11Texture2D>& texture,
|
const Microsoft::WRL::ComPtr<ID3D11Texture2D>& texture,
|
||||||
@@ -83,6 +84,7 @@ private:
|
|||||||
Microsoft::WRL::ComPtr<IDXGIOutputDuplication> dupl_;
|
Microsoft::WRL::ComPtr<IDXGIOutputDuplication> dupl_;
|
||||||
Frame lastFrame_;
|
Frame lastFrame_;
|
||||||
UINT lastFrameId_ = 0;
|
UINT lastFrameId_ = 0;
|
||||||
|
bool isFrameAquired_ = false;
|
||||||
|
|
||||||
volatile bool shouldRun_ = false;
|
volatile bool shouldRun_ = false;
|
||||||
std::thread thread_;
|
std::thread thread_;
|
||||||
|
|||||||
Reference in New Issue
Block a user