draw cursor texture to unity texture instead of cached texture.
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -62,16 +62,16 @@ void Cursor::UpdateBuffer(Duplicator* duplicator, const DXGI_OUTDUPL_FRAME_INFO&
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Cursor::Draw(
|
void Cursor::UpdateTexture(
|
||||||
Duplicator* duplicator,
|
Duplicator* duplicator,
|
||||||
const ComPtr<ID3D11Texture2D>& targetTexture)
|
const ComPtr<ID3D11Texture2D>& desktopTexture)
|
||||||
{
|
{
|
||||||
auto monitor = duplicator->GetMonitor();
|
auto monitor = duplicator->GetMonitor();
|
||||||
|
|
||||||
// Check desktop texure
|
// Check desktop texure
|
||||||
if (targetTexture == nullptr)
|
if (desktopTexture == nullptr)
|
||||||
{
|
{
|
||||||
Debug::Error("Cursor::UpdateTexture() => target texture is null.");
|
Debug::Error("Cursor::UpdateTexture() => Desktop texture is null.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,7 +194,7 @@ void Cursor::Draw(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
D3D11_BOX capturedImageArea
|
capturedImageArea_ = D3D11_BOX
|
||||||
{
|
{
|
||||||
static_cast<UINT>(capturedImageLeft),
|
static_cast<UINT>(capturedImageLeft),
|
||||||
static_cast<UINT>(capturedImageTop),
|
static_cast<UINT>(capturedImageTop),
|
||||||
@@ -218,7 +218,7 @@ void Cursor::Draw(
|
|||||||
desc.Usage = D3D11_USAGE_STAGING;
|
desc.Usage = D3D11_USAGE_STAGING;
|
||||||
desc.BindFlags = 0;
|
desc.BindFlags = 0;
|
||||||
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
|
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
|
||||||
desc.MiscFlags = 0;
|
desc.MiscFlags = D3D11_RESOURCE_MISC_SHARED;
|
||||||
|
|
||||||
if (FAILED(duplicator->GetDevice()->CreateTexture2D(&desc, nullptr, &texture)))
|
if (FAILED(duplicator->GetDevice()->CreateTexture2D(&desc, nullptr, &texture)))
|
||||||
{
|
{
|
||||||
@@ -231,7 +231,7 @@ void Cursor::Draw(
|
|||||||
{
|
{
|
||||||
ComPtr<ID3D11DeviceContext> context;
|
ComPtr<ID3D11DeviceContext> context;
|
||||||
duplicator->GetDevice()->GetImmediateContext(&context);
|
duplicator->GetDevice()->GetImmediateContext(&context);
|
||||||
context->CopySubresourceRegion(texture.Get(), 0, 0, 0, 0, targetTexture.Get(), 0, &capturedImageArea);
|
context->CopySubresourceRegion(texture.Get(), 0, 0, 0, 0, desktopTexture.Get(), 0, &capturedImageArea_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get mapped surface to access pixels in CPU
|
// Get mapped surface to access pixels in CPU
|
||||||
@@ -359,12 +359,6 @@ void Cursor::Draw(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
|
||||||
ComPtr<ID3D11DeviceContext> context;
|
|
||||||
duplicator->GetDevice()->GetImmediateContext(&context);
|
|
||||||
context->UpdateSubresource(targetTexture.Get(), 0, &capturedImageArea, bgraBuffer_.Get(), capturedImageWidth * 4, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (FAILED(surface->Unmap()))
|
if (FAILED(surface->Unmap()))
|
||||||
{
|
{
|
||||||
Debug::Error("Cursor::UpdateTexture() => surface->Unmap() failed.");
|
Debug::Error("Cursor::UpdateTexture() => surface->Unmap() failed.");
|
||||||
@@ -373,6 +367,21 @@ void Cursor::Draw(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Cursor::Draw(const Microsoft::WRL::ComPtr<ID3D11Texture2D>& texture)
|
||||||
|
{
|
||||||
|
if (texture == nullptr)
|
||||||
|
{
|
||||||
|
Debug::Error("Cursor::UpdateTexture() => Desktop texture is null.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto capturedImageWidth = capturedImageArea_.right - capturedImageArea_.left;
|
||||||
|
ComPtr<ID3D11DeviceContext> context;
|
||||||
|
GetDevice()->GetImmediateContext(&context);
|
||||||
|
context->UpdateSubresource(texture.Get(), 0, &capturedImageArea_, bgraBuffer_.Get(), capturedImageWidth * 4, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Cursor::GetTexture(ID3D11Texture2D* texture)
|
void Cursor::GetTexture(ID3D11Texture2D* texture)
|
||||||
{
|
{
|
||||||
if (!bgraBuffer_)
|
if (!bgraBuffer_)
|
||||||
|
|||||||
@@ -17,9 +17,10 @@ public:
|
|||||||
void UpdateBuffer(
|
void UpdateBuffer(
|
||||||
Duplicator* duplicator,
|
Duplicator* duplicator,
|
||||||
const DXGI_OUTDUPL_FRAME_INFO& frameInfo);
|
const DXGI_OUTDUPL_FRAME_INFO& frameInfo);
|
||||||
void Draw(
|
void UpdateTexture(
|
||||||
Duplicator* duplicator,
|
Duplicator* duplicator,
|
||||||
const Microsoft::WRL::ComPtr<ID3D11Texture2D>& targetTexture);
|
const Microsoft::WRL::ComPtr<ID3D11Texture2D>& desktopTexture);
|
||||||
|
void Draw(const Microsoft::WRL::ComPtr<ID3D11Texture2D>& texture);
|
||||||
void GetTexture(ID3D11Texture2D* texture);
|
void GetTexture(ID3D11Texture2D* texture);
|
||||||
|
|
||||||
bool IsVisible() const;
|
bool IsVisible() const;
|
||||||
@@ -38,4 +39,5 @@ private:
|
|||||||
Buffer<BYTE> bgraBuffer_;
|
Buffer<BYTE> bgraBuffer_;
|
||||||
DXGI_OUTDUPL_POINTER_SHAPE_INFO shapeInfo_;
|
DXGI_OUTDUPL_POINTER_SHAPE_INFO shapeInfo_;
|
||||||
LARGE_INTEGER timestamp_;
|
LARGE_INTEGER timestamp_;
|
||||||
|
D3D11_BOX capturedImageArea_;
|
||||||
};
|
};
|
||||||
@@ -148,7 +148,12 @@ private:
|
|||||||
#define UDD_FUNCTION_SCOPE_TIMER \
|
#define UDD_FUNCTION_SCOPE_TIMER \
|
||||||
ScopedTimer _timer_##__COUNTER__([](std::chrono::microseconds us) \
|
ScopedTimer _timer_##__COUNTER__([](std::chrono::microseconds us) \
|
||||||
{ \
|
{ \
|
||||||
Debug::Log(__FUNCTION__, "@", __FILE__, ":", __LINE__, " => ", us.count(), " (us)"); \
|
Debug::Log(__FUNCTION__, "@", __FILE__, ":", __LINE__, " => ", us.count(), " [us]"); \
|
||||||
|
});
|
||||||
|
#define UDD_SCOPE_TIMER(Name) \
|
||||||
|
ScopedTimer _timer_##__COUNTER__([](std::chrono::microseconds us) \
|
||||||
|
{ \
|
||||||
|
Debug::Log(#Name, " => ", us.count(), " [us]"); \
|
||||||
});
|
});
|
||||||
#else
|
#else
|
||||||
#define UDD_FUNCTION_SCOPE_TIMER
|
#define UDD_FUNCTION_SCOPE_TIMER
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ using namespace Microsoft::WRL;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
Microsoft::WRL::ComPtr<ID3D11Texture2D> SharedTextureWrapper::Get()
|
const Microsoft::WRL::ComPtr<ID3D11Texture2D>& SharedTextureWrapper::Get() const
|
||||||
{
|
{
|
||||||
return pointer_;
|
return pointer_;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class SharedTextureWrapper
|
|||||||
{
|
{
|
||||||
friend class IsolatedD3D11Device;
|
friend class IsolatedD3D11Device;
|
||||||
public:
|
public:
|
||||||
Microsoft::WRL::ComPtr<ID3D11Texture2D> Get();
|
const Microsoft::WRL::ComPtr<ID3D11Texture2D>& Get() const;
|
||||||
Microsoft::WRL::ComPtr<ID3D11Texture2D> Lock();
|
Microsoft::WRL::ComPtr<ID3D11Texture2D> Lock();
|
||||||
void Unlock();
|
void Unlock();
|
||||||
bool IsLocked() const;
|
bool IsLocked() const;
|
||||||
|
|||||||
@@ -327,9 +327,12 @@ void Duplicator::Duplicate(UINT timeout)
|
|||||||
if (!sharedTexture) return;
|
if (!sharedTexture) return;
|
||||||
ScopedReleaser sharedTextureReleaser([&] { sharedTextureWrapper->Unlock(); });
|
ScopedReleaser sharedTextureReleaser([&] { sharedTextureWrapper->Unlock(); });
|
||||||
|
|
||||||
ComPtr<ID3D11DeviceContext> context;
|
{
|
||||||
device_->GetDevice()->GetImmediateContext(&context);
|
UDD_SCOPE_TIMER(CopyResource);
|
||||||
context->CopyResource(sharedTexture.Get(), texture.Get());
|
ComPtr<ID3D11DeviceContext> context;
|
||||||
|
device_->GetDevice()->GetImmediateContext(&context);
|
||||||
|
context->CopyResource(sharedTexture.Get(), texture.Get());
|
||||||
|
}
|
||||||
|
|
||||||
UpdateCursor(sharedTexture, frameInfo);
|
UpdateCursor(sharedTexture, frameInfo);
|
||||||
UpdateMetadata(frameInfo.TotalMetadataBufferSize);
|
UpdateMetadata(frameInfo.TotalMetadataBufferSize);
|
||||||
@@ -362,7 +365,7 @@ void Duplicator::UpdateCursor(
|
|||||||
{
|
{
|
||||||
auto cursor = manager->GetCursor();
|
auto cursor = manager->GetCursor();
|
||||||
cursor->UpdateBuffer(this, frameInfo);
|
cursor->UpdateBuffer(this, frameInfo);
|
||||||
cursor->Draw(this, texture);
|
cursor->UpdateTexture(this, texture);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -98,6 +98,9 @@ void Monitor::Render()
|
|||||||
ComPtr<ID3D11DeviceContext> context;
|
ComPtr<ID3D11DeviceContext> context;
|
||||||
GetDevice()->GetImmediateContext(&context);
|
GetDevice()->GetImmediateContext(&context);
|
||||||
context->CopyResource(unityTexture_, sharedTexture.Get());
|
context->CopyResource(unityTexture_, sharedTexture.Get());
|
||||||
|
|
||||||
|
auto cursor = GetMonitorManager()->GetCursor();
|
||||||
|
cursor->Draw(unityTexture_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user