소스 검색

DisplayManager: better check for rate-multiples

Instead of just somehow naively rounding, explicitly check how much the
rate-multiple deviates from the ideal rate.

The new code fixes behavior of the reported video rate is e.g. 24.999.
On the other hand, it should be much stricter for detecting actual
multiples. It might need some readjustment, depending on what kind of
video/display FPS combinations we have to deal with.
Vincent Lang 8 년 전
부모
커밋
2707ad201b
1개의 변경된 파일12개의 추가작업 그리고 6개의 파일을 삭제
  1. 12 6
      src/display/DisplayManager.cpp

+ 12 - 6
src/display/DisplayManager.cpp

@@ -74,17 +74,23 @@ bool DisplayManager::isValidDisplayMode(int display, int mode)
 }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
+// refresh: video FPS
+// multiple: display FPS
 bool DisplayManager::isRateMultipleOf(float refresh, float multiple, bool exact)
 {
-  if (((int)refresh == 0) || ((int)multiple == 0))
+  int roundedRefresh = lrint(refresh);
+  int roundedMultiple = lrint(multiple);
+
+  if (roundedRefresh == 0)
       return false;
 
-  if (((int)multiple % (int)refresh) == 0)
-    return true;
+  float newRate = roundedMultiple / roundedRefresh * refresh;
+  if (newRate < 1)
+    return false;
+
+  float tolerance = exact ? 0.1 : 1;
 
-  int roundedRefresh = (int)round(refresh);
-  int roundedMultiple = (int)round(multiple);
-  return ((roundedMultiple % roundedRefresh) == 0) && (!exact);
+  return fabs(newRate - multiple) < tolerance;
 }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////