check ReleaseFrame result #10

This commit is contained in:
hecomi
2017-01-05 19:03:18 +09:00
parent 741e2c0bc1
commit d58855ff8a
3 changed files with 44 additions and 20 deletions
@@ -5,6 +5,7 @@
#include <wrl/client.h>
// Unity interface getter
struct IUnityInterfaces;
IUnityInterfaces* GetUnity();
@@ -21,6 +22,21 @@ const std::unique_ptr<MonitorManager>& GetMonitorManager();
LUID GetUnityAdapterLuid();
// Releaser
class ScopedReleaser
{
public:
using ReleaseFuncType = std::function<void()>;
ScopedReleaser(ReleaseFuncType&& func) : func_(func) {}
~ScopedReleaser() { func_(); }
private:
ReleaseFuncType func_;
};
// Message is pooled and fetch from Unity.
enum class Message
{
@@ -32,6 +48,7 @@ enum class Message
void SendMessageToUnity(Message message);
// Buffer
template <class T>
class Buffer
@@ -78,25 +78,6 @@ public:
};
// RAII helper
class ReleaseGuard
{
ComPtr<IDXGIOutputDuplication> m_dd;
ReleaseGuard(const ReleaseGuard &)=delete;
ReleaseGuard& operator=(const ReleaseGuard &)=delete;
public:
ReleaseGuard(const ComPtr<IDXGIOutputDuplication> &dd)
: m_dd(dd)
{}
~ReleaseGuard()
{
m_dd->ReleaseFrame();
}
};
struct QueueItem
{
ComPtr<ID3D11Texture2D> Texture;
@@ -357,7 +338,33 @@ void Monitor::DuplicateAndCopyLoop()
}
else
{
ReleaseGuard guard(deskDupl_);
ScopedReleaser releaser([this]
{
const auto hr = deskDupl_->ReleaseFrame();
if (FAILED(hr))
{
switch (hr)
{
case DXGI_ERROR_ACCESS_LOST:
{
Debug::Log("Monitor::Render() => DXGI_ERROR_ACCESS_LOST.");
state_ = State::AccessLost;
break;
}
case DXGI_ERROR_INVALID_CALL:
{
Debug::Error("Monitor::Render() => DXGI_ERROR_INVALID_CALL.");
break;
}
default:
{
state_ = State::Unknown;
Debug::Error("Monitor::Render() => Unknown Error.");
break;
}
}
}
});
ComPtr<ID3D11Texture2D> texture;
if (FAILED(resource.As(&texture))) {