mirror of
https://github.com/raysan5/raylib.git
synced 2026-02-01 03:39:18 -05:00
FindNearestConnectorMode: prefer mode with smallest number of unused pixels (#5158)
Co-authored-by: Philipp Maierhoefer <particle@maierhoefer.net>
This commit is contained in:
@ -53,6 +53,7 @@
|
|||||||
#include <termios.h> // POSIX terminal control definitions - tcgetattr(), tcsetattr()
|
#include <termios.h> // POSIX terminal control definitions - tcgetattr(), tcsetattr()
|
||||||
#include <pthread.h> // POSIX threads management (inputs reading)
|
#include <pthread.h> // POSIX threads management (inputs reading)
|
||||||
#include <dirent.h> // POSIX directory browsing
|
#include <dirent.h> // POSIX directory browsing
|
||||||
|
#include <limits.h> // INT_MAX
|
||||||
|
|
||||||
#include <sys/ioctl.h> // Required for: ioctl() - UNIX System call for device-specific input/output operations
|
#include <sys/ioctl.h> // Required for: ioctl() - UNIX System call for device-specific input/output operations
|
||||||
#include <linux/kd.h> // Linux: KDSKBMODE, K_MEDIUMRAM constants definition
|
#include <linux/kd.h> // Linux: KDSKBMODE, K_MEDIUMRAM constants definition
|
||||||
@ -2150,6 +2151,8 @@ static int FindNearestConnectorMode(const drmModeConnector *connector, uint widt
|
|||||||
if (NULL == connector) return -1;
|
if (NULL == connector) return -1;
|
||||||
|
|
||||||
int nearestIndex = -1;
|
int nearestIndex = -1;
|
||||||
|
int minUnusedPixels = INT_MAX;
|
||||||
|
int minFpsDiff = INT_MAX;
|
||||||
for (int i = 0; i < platform.connector->count_modes; i++)
|
for (int i = 0; i < platform.connector->count_modes; i++)
|
||||||
{
|
{
|
||||||
const drmModeModeInfo *const mode = &platform.connector->modes[i];
|
const drmModeModeInfo *const mode = &platform.connector->modes[i];
|
||||||
@ -2169,21 +2172,17 @@ static int FindNearestConnectorMode(const drmModeConnector *connector, uint widt
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nearestIndex < 0)
|
const int unusedPixels = (mode->hdisplay - width) * (mode->vdisplay - height);
|
||||||
|
const int fpsDiff = mode->vrefresh - fps;
|
||||||
|
|
||||||
|
if ((unusedPixels < minUnusedPixels) ||
|
||||||
|
((unusedPixels == minUnusedPixels) && (abs(fpsDiff) < abs(minFpsDiff))) ||
|
||||||
|
((unusedPixels == minUnusedPixels) && (abs(fpsDiff) == abs(minFpsDiff)) && (fpsDiff > 0)))
|
||||||
{
|
{
|
||||||
nearestIndex = i;
|
nearestIndex = i;
|
||||||
continue;
|
minUnusedPixels = unusedPixels;
|
||||||
|
minFpsDiff = fpsDiff;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int widthDiff = abs(mode->hdisplay - width);
|
|
||||||
const int heightDiff = abs(mode->vdisplay - height);
|
|
||||||
const int fpsDiff = abs(mode->vrefresh - fps);
|
|
||||||
|
|
||||||
const int nearestWidthDiff = abs(platform.connector->modes[nearestIndex].hdisplay - width);
|
|
||||||
const int nearestHeightDiff = abs(platform.connector->modes[nearestIndex].vdisplay - height);
|
|
||||||
const int nearestFpsDiff = abs(platform.connector->modes[nearestIndex].vrefresh - fps);
|
|
||||||
|
|
||||||
if ((widthDiff < nearestWidthDiff) || (heightDiff < nearestHeightDiff) || (fpsDiff < nearestFpsDiff)) nearestIndex = i;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nearestIndex;
|
return nearestIndex;
|
||||||
|
|||||||
Reference in New Issue
Block a user