-
Notifications
You must be signed in to change notification settings - Fork 883
/
kodi-999.97-fix_frametime_for_active_vsync.patch
113 lines (103 loc) · 3.82 KB
/
kodi-999.97-fix_frametime_for_active_vsync.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
From d695fce46de7f59b043a6a5feeb2997936159799 Mon Sep 17 00:00:00 2001
From: Rainer Hochecker <fernetmenta@online.de>
Date: Fri, 20 Mar 2015 10:25:48 +0100
Subject: [PATCH] fix frametime for active vsync
---
xbmc/Application.cpp | 11 ++++++++++-
xbmc/utils/TimeUtils.cpp | 23 +++++++++++++++++++----
xbmc/utils/TimeUtils.h | 2 +-
3 files changed, 30 insertions(+), 6 deletions(-)
diff --git a/xbmc/Application.cpp b/xbmc/Application.cpp
index a79c7dd..eef7f02 100644
--- a/xbmc/Application.cpp
+++ b/xbmc/Application.cpp
@@ -2216,6 +2216,7 @@ void CApplication::Render()
bool hasRendered = false;
bool limitFrames = false;
unsigned int singleFrameTime = 10; // default limit 100 fps
+ bool vsync = true;
// Whether externalplayer is playing and we're unfocused
bool extPlayerActive = m_pPlayer->GetCurrentPlayer() == EPC_EXTPLAYER && m_pPlayer->IsPlaying() && !m_AppFocused;
@@ -2228,6 +2229,8 @@ void CApplication::Render()
if (!extPlayerActive && g_graphicsContext.IsFullScreenVideo() && !m_pPlayer->IsPausedPlayback())
{
m_bPresentFrame = g_renderManager.HasFrame();
+ if (vsync_mode == VSYNC_DISABLED)
+ vsync = false;
}
else
{
@@ -2236,9 +2239,15 @@ void CApplication::Render()
// DXMERGE - we checked for g_videoConfig.GetVSyncMode() before this
// perhaps allowing it to be set differently than the UI option??
if (vsync_mode == VSYNC_DISABLED || vsync_mode == VSYNC_VIDEO)
+ {
limitFrames = true; // not using vsync.
+ vsync = false;
+ }
else if ((g_infoManager.GetFPS() > g_graphicsContext.GetFPS() + 10) && g_infoManager.GetFPS() > 1000 / singleFrameTime)
+ {
limitFrames = true; // using vsync, but it isn't working.
+ vsync = false;
+ }
if (limitFrames)
{
@@ -2334,7 +2343,7 @@ void CApplication::Render()
}
m_lastFrameTime = XbmcThreads::SystemClockMillis();
- CTimeUtils::UpdateFrameTime(flip);
+ CTimeUtils::UpdateFrameTime(flip, vsync);
g_renderManager.UpdateResolution();
g_renderManager.ManageCaptures();
diff --git a/xbmc/utils/TimeUtils.cpp b/xbmc/utils/TimeUtils.cpp
index 9f2e135..57e5e90 100644
--- a/xbmc/utils/TimeUtils.cpp
+++ b/xbmc/utils/TimeUtils.cpp
@@ -21,6 +21,7 @@
#include "TimeUtils.h"
#include "XBDateTime.h"
#include "threads/SystemClock.h"
+#include "guilib/GraphicContext.h"
#if (defined HAVE_CONFIG_H) && (!defined TARGET_WINDOWS)
#include "config.h"
@@ -72,12 +73,26 @@ int64_t CurrentHostFrequency(void)
CTimeSmoother CTimeUtils::frameTimer;
unsigned int CTimeUtils::frameTime = 0;
-void CTimeUtils::UpdateFrameTime(bool flip)
+void CTimeUtils::UpdateFrameTime(bool flip, bool vsync)
{
unsigned int currentTime = XbmcThreads::SystemClockMillis();
- if (flip)
- frameTimer.AddTimeStamp(currentTime);
- frameTime = frameTimer.GetNextFrameTime(currentTime);
+ if (vsync)
+ {
+ unsigned int last = frameTime;
+ while (frameTime < currentTime)
+ {
+ frameTime += (unsigned int)(1000 / g_graphicsContext.GetFPS());
+ // observe wrap around
+ if (frameTime < last)
+ break;
+ }
+ }
+ else
+ {
+ if (flip)
+ frameTimer.AddTimeStamp(currentTime);
+ frameTime = frameTimer.GetNextFrameTime(currentTime);
+ }
}
unsigned int CTimeUtils::GetFrameTime()
diff --git a/xbmc/utils/TimeUtils.h b/xbmc/utils/TimeUtils.h
index f8796d5..e07540f 100644
--- a/xbmc/utils/TimeUtils.h
+++ b/xbmc/utils/TimeUtils.h
@@ -32,7 +32,7 @@ int64_t CurrentHostFrequency(void);
class CTimeUtils
{
public:
- static void UpdateFrameTime(bool flip); ///< update the frame time. Not threadsafe
+ static void UpdateFrameTime(bool flip, bool vsync); ///< update the frame time. Not threadsafe
static unsigned int GetFrameTime(); ///< returns the frame time in MS. Not threadsafe
static CDateTime GetLocalTime(time_t time);