diff --git a/Assets/uDesktopDuplication/Plugins/x86/uDesktopDuplication.dll b/Assets/uDesktopDuplication/Plugins/x86/uDesktopDuplication.dll index 7800cdc..67efd53 100644 Binary files a/Assets/uDesktopDuplication/Plugins/x86/uDesktopDuplication.dll and b/Assets/uDesktopDuplication/Plugins/x86/uDesktopDuplication.dll differ diff --git a/Assets/uDesktopDuplication/Plugins/x86_64/uDesktopDuplication.dll b/Assets/uDesktopDuplication/Plugins/x86_64/uDesktopDuplication.dll index 1dc501a..96be68f 100644 Binary files a/Assets/uDesktopDuplication/Plugins/x86_64/uDesktopDuplication.dll and b/Assets/uDesktopDuplication/Plugins/x86_64/uDesktopDuplication.dll differ diff --git a/Plugins/uDesktopDuplication/uDesktopDuplication/Cursor.cpp b/Plugins/uDesktopDuplication/uDesktopDuplication/Cursor.cpp index d21fab9..d3f3820 100644 --- a/Plugins/uDesktopDuplication/uDesktopDuplication/Cursor.cpp +++ b/Plugins/uDesktopDuplication/uDesktopDuplication/Cursor.cpp @@ -62,16 +62,16 @@ void Cursor::UpdateBuffer(Duplicator* duplicator, const DXGI_OUTDUPL_FRAME_INFO& } -void Cursor::Draw( +void Cursor::UpdateTexture( Duplicator* duplicator, - const ComPtr& targetTexture) + const ComPtr& desktopTexture) { auto monitor = duplicator->GetMonitor(); // 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; } @@ -194,7 +194,7 @@ void Cursor::Draw( return; } - D3D11_BOX capturedImageArea + capturedImageArea_ = D3D11_BOX { static_cast(capturedImageLeft), static_cast(capturedImageTop), @@ -218,7 +218,7 @@ void Cursor::Draw( desc.Usage = D3D11_USAGE_STAGING; desc.BindFlags = 0; desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; - desc.MiscFlags = 0; + desc.MiscFlags = D3D11_RESOURCE_MISC_SHARED; if (FAILED(duplicator->GetDevice()->CreateTexture2D(&desc, nullptr, &texture))) { @@ -231,7 +231,7 @@ void Cursor::Draw( { ComPtr 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 @@ -359,12 +359,6 @@ void Cursor::Draw( } } - { - ComPtr context; - duplicator->GetDevice()->GetImmediateContext(&context); - context->UpdateSubresource(targetTexture.Get(), 0, &capturedImageArea, bgraBuffer_.Get(), capturedImageWidth * 4, 0); - } - if (FAILED(surface->Unmap())) { Debug::Error("Cursor::UpdateTexture() => surface->Unmap() failed."); @@ -373,6 +367,21 @@ void Cursor::Draw( } +void Cursor::Draw(const Microsoft::WRL::ComPtr& texture) +{ + if (texture == nullptr) + { + Debug::Error("Cursor::UpdateTexture() => Desktop texture is null."); + return; + } + + const auto capturedImageWidth = capturedImageArea_.right - capturedImageArea_.left; + ComPtr context; + GetDevice()->GetImmediateContext(&context); + context->UpdateSubresource(texture.Get(), 0, &capturedImageArea_, bgraBuffer_.Get(), capturedImageWidth * 4, 0); +} + + void Cursor::GetTexture(ID3D11Texture2D* texture) { if (!bgraBuffer_) diff --git a/Plugins/uDesktopDuplication/uDesktopDuplication/Cursor.h b/Plugins/uDesktopDuplication/uDesktopDuplication/Cursor.h index 584aca3..1640152 100644 --- a/Plugins/uDesktopDuplication/uDesktopDuplication/Cursor.h +++ b/Plugins/uDesktopDuplication/uDesktopDuplication/Cursor.h @@ -17,9 +17,10 @@ public: void UpdateBuffer( Duplicator* duplicator, const DXGI_OUTDUPL_FRAME_INFO& frameInfo); - void Draw( - Duplicator* duplicator, - const Microsoft::WRL::ComPtr& targetTexture); + void UpdateTexture( + Duplicator* duplicator, + const Microsoft::WRL::ComPtr& desktopTexture); + void Draw(const Microsoft::WRL::ComPtr& texture); void GetTexture(ID3D11Texture2D* texture); bool IsVisible() const; @@ -38,4 +39,5 @@ private: Buffer bgraBuffer_; DXGI_OUTDUPL_POINTER_SHAPE_INFO shapeInfo_; LARGE_INTEGER timestamp_; + D3D11_BOX capturedImageArea_; }; \ No newline at end of file diff --git a/Plugins/uDesktopDuplication/uDesktopDuplication/Debug.h b/Plugins/uDesktopDuplication/uDesktopDuplication/Debug.h index 01df84d..b42a7f3 100644 --- a/Plugins/uDesktopDuplication/uDesktopDuplication/Debug.h +++ b/Plugins/uDesktopDuplication/uDesktopDuplication/Debug.h @@ -148,7 +148,12 @@ private: #define UDD_FUNCTION_SCOPE_TIMER \ 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 #define UDD_FUNCTION_SCOPE_TIMER diff --git a/Plugins/uDesktopDuplication/uDesktopDuplication/Device.cpp b/Plugins/uDesktopDuplication/uDesktopDuplication/Device.cpp index 435300c..86babce 100644 --- a/Plugins/uDesktopDuplication/uDesktopDuplication/Device.cpp +++ b/Plugins/uDesktopDuplication/uDesktopDuplication/Device.cpp @@ -15,7 +15,7 @@ using namespace Microsoft::WRL; -Microsoft::WRL::ComPtr SharedTextureWrapper::Get() +const Microsoft::WRL::ComPtr& SharedTextureWrapper::Get() const { return pointer_; } diff --git a/Plugins/uDesktopDuplication/uDesktopDuplication/Device.h b/Plugins/uDesktopDuplication/uDesktopDuplication/Device.h index fbcfcd0..6b2cff4 100644 --- a/Plugins/uDesktopDuplication/uDesktopDuplication/Device.h +++ b/Plugins/uDesktopDuplication/uDesktopDuplication/Device.h @@ -12,7 +12,7 @@ class SharedTextureWrapper { friend class IsolatedD3D11Device; public: - Microsoft::WRL::ComPtr Get(); + const Microsoft::WRL::ComPtr& Get() const; Microsoft::WRL::ComPtr Lock(); void Unlock(); bool IsLocked() const; diff --git a/Plugins/uDesktopDuplication/uDesktopDuplication/Duplicator.cpp b/Plugins/uDesktopDuplication/uDesktopDuplication/Duplicator.cpp index 70510a4..df9a8af 100644 --- a/Plugins/uDesktopDuplication/uDesktopDuplication/Duplicator.cpp +++ b/Plugins/uDesktopDuplication/uDesktopDuplication/Duplicator.cpp @@ -327,9 +327,12 @@ void Duplicator::Duplicate(UINT timeout) if (!sharedTexture) return; ScopedReleaser sharedTextureReleaser([&] { sharedTextureWrapper->Unlock(); }); - ComPtr context; - device_->GetDevice()->GetImmediateContext(&context); - context->CopyResource(sharedTexture.Get(), texture.Get()); + { + UDD_SCOPE_TIMER(CopyResource); + ComPtr context; + device_->GetDevice()->GetImmediateContext(&context); + context->CopyResource(sharedTexture.Get(), texture.Get()); + } UpdateCursor(sharedTexture, frameInfo); UpdateMetadata(frameInfo.TotalMetadataBufferSize); @@ -362,7 +365,7 @@ void Duplicator::UpdateCursor( { auto cursor = manager->GetCursor(); cursor->UpdateBuffer(this, frameInfo); - cursor->Draw(this, texture); + cursor->UpdateTexture(this, texture); } } diff --git a/Plugins/uDesktopDuplication/uDesktopDuplication/Monitor.cpp b/Plugins/uDesktopDuplication/uDesktopDuplication/Monitor.cpp index 2d2db5c..9b148b6 100644 --- a/Plugins/uDesktopDuplication/uDesktopDuplication/Monitor.cpp +++ b/Plugins/uDesktopDuplication/uDesktopDuplication/Monitor.cpp @@ -98,6 +98,9 @@ void Monitor::Render() ComPtr context; GetDevice()->GetImmediateContext(&context); context->CopyResource(unityTexture_, sharedTexture.Get()); + + auto cursor = GetMonitorManager()->GetCursor(); + cursor->Draw(unityTexture_); } }