call ReleaseFrame() just before AcquireNextFrame() #18.

This commit is contained in:
hecomi
2018-05-20 01:11:03 +09:00
parent 0d2c0e02f0
commit b5fd483d6a
4 changed files with 40 additions and 28 deletions
@@ -46,7 +46,8 @@ void Duplicator::InitializeDevice()
void Duplicator::InitializeDuplication()
{
ComPtr<IDXGIOutput1> output1;
if (FAILED(monitor_->GetOutput().As(&output1))) {
if (FAILED(monitor_->GetOutput().As(&output1)))
{
return;
}
@@ -243,6 +244,8 @@ void Duplicator::Duplicate(UINT timeout)
if (!dupl_ || !device_) return;
Release();
ComPtr<IDXGIResource> resource;
DXGI_OUTDUPL_FRAME_INFO frameInfo;
const auto hr = dupl_->AcquireNextFrame(timeout, &frameInfo, &resource);
@@ -285,33 +288,7 @@ void Duplicator::Duplicate(UINT timeout)
return;
}
ScopedReleaser releaser([this]
{
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_ = true;
ComPtr<ID3D11Texture2D> 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(
const ComPtr<ID3D11Texture2D>& texture,
const DXGI_OUTDUPL_FRAME_INFO& frameInfo)
@@ -68,6 +68,7 @@ private:
void CheckUnityAdapter();
void Duplicate(UINT timeout);
void Release();
void UpdateCursor(
const Microsoft::WRL::ComPtr<ID3D11Texture2D>& texture,
@@ -83,6 +84,7 @@ private:
Microsoft::WRL::ComPtr<IDXGIOutputDuplication> dupl_;
Frame lastFrame_;
UINT lastFrameId_ = 0;
bool isFrameAquired_ = false;
volatile bool shouldRun_ = false;
std::thread thread_;