add frame rate setter and calc more accurate sleep duration.
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -172,6 +172,8 @@ public static class Lib
|
||||
public static extern bool HasBeenUpdated(int id);
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern bool UseGetPixels(int id, bool use);
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern void SetFrameRate(uint frameRate);
|
||||
|
||||
public static string GetName(int id)
|
||||
{
|
||||
|
||||
@@ -148,17 +148,20 @@ void Duplicator::Start()
|
||||
shouldRun_ = true;
|
||||
while (shouldRun_)
|
||||
{
|
||||
const UINT timeout = 16 /* milliseconds */;
|
||||
const auto frameRate = GetMonitorManager()->GetFrameRate();
|
||||
const UINT frameMicroSeconds = 1000000 / frameRate;
|
||||
const UINT frameMilliSeconds = 1000 / frameRate;
|
||||
|
||||
ScopedTimer timer([timeout] (microseconds us)
|
||||
ScopedTimer timer([frameMicroSeconds] (microseconds us)
|
||||
{
|
||||
const auto waitTime = milliseconds(timeout) - us;
|
||||
const auto waitTime = microseconds(frameMicroSeconds) - us;
|
||||
if (waitTime > microseconds::zero())
|
||||
{
|
||||
std::this_thread::sleep_for(waitTime);
|
||||
}
|
||||
});
|
||||
|
||||
const auto timeout = static_cast<UINT>(frameMilliSeconds);
|
||||
if (!Duplicate(timeout)) break;
|
||||
}
|
||||
|
||||
|
||||
@@ -168,3 +168,15 @@ int MonitorManager::GetTotalHeight() const
|
||||
const auto maxBottom = *std::max_element(bottoms.begin(), bottoms.end());
|
||||
return maxBottom - minTop;
|
||||
}
|
||||
|
||||
|
||||
void MonitorManager::SetFrameRate(UINT frameRate)
|
||||
{
|
||||
frameRate_ = frameRate;
|
||||
}
|
||||
|
||||
|
||||
UINT MonitorManager::GetFrameRate() const
|
||||
{
|
||||
return frameRate_;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@ public:
|
||||
int GetCursorMonitorId() const { return cursorMonitorId_; }
|
||||
std::shared_ptr<Monitor> GetMonitor(int id) const;
|
||||
std::shared_ptr<Cursor> GetCursor() const;
|
||||
void SetFrameRate(UINT frameRate);
|
||||
UINT GetFrameRate() const;
|
||||
|
||||
public:
|
||||
int GetMonitorCount() const;
|
||||
@@ -33,7 +35,7 @@ public:
|
||||
|
||||
private:
|
||||
LUID unityAdapterLuid_;
|
||||
|
||||
UINT frameRate_ = 60;
|
||||
bool enableTextureCopyFromGpuToCpu_ = false;
|
||||
std::vector<std::shared_ptr<Monitor>> monitors_;
|
||||
std::shared_ptr<Cursor> cursor_ = std::make_shared<Cursor>();
|
||||
|
||||
@@ -439,4 +439,10 @@ extern "C"
|
||||
return monitor->UseGetPixels(use);
|
||||
}
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API SetFrameRate(UINT frameRate)
|
||||
{
|
||||
if (!g_manager) return;
|
||||
g_manager->SetFrameRate(frameRate);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user