update cursor in each thread #10
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
#include <d3d11.h>
|
||||
#include <wrl/client.h>
|
||||
|
||||
#include "Cursor.h"
|
||||
#include "Debug.h"
|
||||
#include "MonitorManager.h"
|
||||
#include "Monitor.h"
|
||||
#include "Cursor.h"
|
||||
#include "Duplicator.h"
|
||||
|
||||
using namespace Microsoft::WRL;
|
||||
|
||||
@@ -19,8 +21,11 @@ Cursor::~Cursor()
|
||||
}
|
||||
|
||||
|
||||
void Cursor::UpdateBuffer(Monitor* monitor, const DXGI_OUTDUPL_FRAME_INFO& frameInfo)
|
||||
void Cursor::UpdateBuffer(Duplicator* duplicator)
|
||||
{
|
||||
auto monitor = duplicator->GetMonitor();
|
||||
const auto& frameInfo = duplicator->GetFrame().info;
|
||||
|
||||
if (frameInfo.LastMouseUpdateTime.QuadPart == 0)
|
||||
{
|
||||
return;
|
||||
@@ -50,7 +55,7 @@ void Cursor::UpdateBuffer(Monitor* monitor, const DXGI_OUTDUPL_FRAME_INFO& frame
|
||||
// Get mouse pointer information
|
||||
UINT bufferSize;
|
||||
DXGI_OUTDUPL_POINTER_SHAPE_INFO shapeInfo;
|
||||
const auto hr = monitor->GetDeskDupl()->GetFramePointerShape(
|
||||
const auto hr = duplicator->GetDuplication()->GetFramePointerShape(
|
||||
buffer_.Size(),
|
||||
buffer_.Get(),
|
||||
&bufferSize,
|
||||
@@ -67,12 +72,15 @@ void Cursor::UpdateBuffer(Monitor* monitor, const DXGI_OUTDUPL_FRAME_INFO& frame
|
||||
}
|
||||
|
||||
|
||||
void Cursor::Draw(Monitor* monitor)
|
||||
void Cursor::Draw(Duplicator* duplicator)
|
||||
{
|
||||
auto monitor = duplicator->GetMonitor();
|
||||
const auto& frame = duplicator->GetFrame();
|
||||
|
||||
// Check desktop texure
|
||||
if (monitor->GetUnityTexture() == nullptr)
|
||||
if (frame.texture == nullptr)
|
||||
{
|
||||
Debug::Error("Cursor::UpdateTexture() => Monitor::GetUnityTexture() is null.");
|
||||
Debug::Error("Cursor::UpdateTexture() => texture is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -220,7 +228,7 @@ void Cursor::Draw(Monitor* monitor)
|
||||
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
|
||||
desc.MiscFlags = 0;
|
||||
|
||||
if (FAILED(GetDevice()->CreateTexture2D(&desc, nullptr, &texture)))
|
||||
if (FAILED(duplicator->GetDevice()->CreateTexture2D(&desc, nullptr, &texture)))
|
||||
{
|
||||
Debug::Error("Cursor::UpdateTexture() => GetDevice()->CreateTexture2D() failed.");
|
||||
return;
|
||||
@@ -230,8 +238,8 @@ void Cursor::Draw(Monitor* monitor)
|
||||
// Copy desktop image to the texture
|
||||
{
|
||||
ComPtr<ID3D11DeviceContext> context;
|
||||
GetDevice()->GetImmediateContext(&context);
|
||||
context->CopySubresourceRegion(texture.Get(), 0, 0, 0, 0, monitor->GetUnityTexture(), 0, &capturedImageArea);
|
||||
duplicator->GetDevice()->GetImmediateContext(&context);
|
||||
context->CopySubresourceRegion(texture.Get(), 0, 0, 0, 0, frame.texture.Get(), 0, &capturedImageArea);
|
||||
}
|
||||
|
||||
// Get mapped surface to access pixels in CPU
|
||||
@@ -361,8 +369,8 @@ void Cursor::Draw(Monitor* monitor)
|
||||
|
||||
{
|
||||
ComPtr<ID3D11DeviceContext> context;
|
||||
GetDevice()->GetImmediateContext(&context);
|
||||
context->UpdateSubresource(monitor->GetUnityTexture(), 0, &capturedImageArea, bgraBuffer_.Get(), capturedImageWidth * 4, 0);
|
||||
duplicator->GetDevice()->GetImmediateContext(&context);
|
||||
context->UpdateSubresource(frame.texture.Get(), 0, &capturedImageArea, bgraBuffer_.Get(), capturedImageWidth * 4, 0);
|
||||
}
|
||||
|
||||
if (FAILED(surface->Unmap()))
|
||||
|
||||
@@ -5,15 +5,15 @@
|
||||
#include <memory>
|
||||
#include "Common.h"
|
||||
|
||||
class Monitor;
|
||||
class Duplicator;
|
||||
|
||||
class Cursor
|
||||
{
|
||||
public:
|
||||
explicit Cursor();
|
||||
~Cursor();
|
||||
void UpdateBuffer(Monitor* monitor, const DXGI_OUTDUPL_FRAME_INFO& frameInfo);
|
||||
void Draw(Monitor* monitor);
|
||||
void UpdateBuffer(Duplicator* duplicator);
|
||||
void Draw(Duplicator* duplicator);
|
||||
void GetTexture(ID3D11Texture2D* texture);
|
||||
|
||||
bool IsVisible() const;
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
#include "Duplicator.h"
|
||||
#include "Monitor.h"
|
||||
#include "MonitorManager.h"
|
||||
#include "Cursor.h"
|
||||
#include "Device.h"
|
||||
#include "Debug.h"
|
||||
|
||||
@@ -183,6 +185,18 @@ Duplicator::State Duplicator::GetState() const
|
||||
}
|
||||
|
||||
|
||||
Monitor* Duplicator::GetMonitor() const
|
||||
{
|
||||
return monitor_;
|
||||
}
|
||||
|
||||
|
||||
Microsoft::WRL::ComPtr<ID3D11Device> Duplicator::GetDevice()
|
||||
{
|
||||
return device_->GetDevice();
|
||||
}
|
||||
|
||||
|
||||
ComPtr<IDXGIOutputDuplication> Duplicator::GetDuplication()
|
||||
{
|
||||
return dupl_;
|
||||
@@ -294,10 +308,28 @@ bool Duplicator::Duplicate()
|
||||
|
||||
UpdateMetadata();
|
||||
|
||||
if (frameInfo.PointerPosition.Visible)
|
||||
{
|
||||
GetMonitorManager()->SetCursorMonitorId(monitor_->GetId());
|
||||
}
|
||||
|
||||
if (GetMonitorManager()->GetCursorMonitorId() == monitor_->GetId())
|
||||
{
|
||||
UpdateCursor();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void Duplicator::UpdateCursor()
|
||||
{
|
||||
auto cursor = GetMonitorManager()->GetCursor();
|
||||
cursor->UpdateBuffer(this);
|
||||
cursor->Draw(this);
|
||||
}
|
||||
|
||||
|
||||
void Duplicator::UpdateMetadata()
|
||||
{
|
||||
metaData_.buffer.ExpandIfNeeded(lastFrame_.info.TotalMetadataBufferSize);
|
||||
|
||||
@@ -55,6 +55,8 @@ public:
|
||||
bool IsRunning() const;
|
||||
bool IsError() const;
|
||||
State GetState() const;
|
||||
Monitor* GetMonitor() const;
|
||||
Microsoft::WRL::ComPtr<ID3D11Device> GetDevice();
|
||||
Microsoft::WRL::ComPtr<IDXGIOutputDuplication> GetDuplication();
|
||||
const Frame& GetFrame() const;
|
||||
|
||||
@@ -64,6 +66,8 @@ private:
|
||||
void CheckUnityAdapter();
|
||||
|
||||
bool Duplicate();
|
||||
|
||||
void UpdateCursor();
|
||||
void UpdateMetadata();
|
||||
void UpdateMoveRects();
|
||||
void UpdateDirtyRects();
|
||||
|
||||
@@ -100,33 +100,15 @@ void Monitor::Render()
|
||||
}
|
||||
}
|
||||
|
||||
if (frameInfo.PointerPosition.Visible)
|
||||
{
|
||||
GetMonitorManager()->SetCursorMonitorId(id_);
|
||||
}
|
||||
|
||||
if (GetMonitorManager()->GetCursorMonitorId() == id_)
|
||||
{
|
||||
UpdateCursor(frameInfo);
|
||||
}
|
||||
|
||||
if (UseGetPixels())
|
||||
{
|
||||
CopyTextureFromGpuToCpu(texture.Get());
|
||||
CopyTextureFromGpuToCpu(unityTexture_);
|
||||
}
|
||||
|
||||
hasBeenUpdated_ = true;
|
||||
}
|
||||
|
||||
|
||||
void Monitor::UpdateCursor(const DXGI_OUTDUPL_FRAME_INFO& frameInfo)
|
||||
{
|
||||
auto cursor_ = GetMonitorManager()->GetCursor();
|
||||
cursor_->UpdateBuffer(this, frameInfo);
|
||||
cursor_->Draw(this);
|
||||
}
|
||||
|
||||
|
||||
int Monitor::GetId() const
|
||||
{
|
||||
return id_;
|
||||
|
||||
@@ -53,7 +53,6 @@ public:
|
||||
bool GetPixels(BYTE* output, int x, int y, int width, int height);
|
||||
|
||||
private:
|
||||
void UpdateCursor(const DXGI_OUTDUPL_FRAME_INFO& frameInfo);
|
||||
void CopyTextureFromGpuToCpu(ID3D11Texture2D* texture);
|
||||
|
||||
int id_ = -1;
|
||||
|
||||
Reference in New Issue
Block a user