fixed DRM connector mode selection

This commit is contained in:
kernelkinetic 2020-09-20 11:01:51 +02:00
parent ff5d1cc028
commit b6873ab9f2

View File

@ -3153,8 +3153,13 @@ static bool InitGraphicsDevice(int width, int height)
return false; return false;
} }
int findExactly = 1; bool findExactly = true;
bool avoidProgressive = CORE.Window.flags & FLAG_INTERLACED_HINT;
#define IS_INTERLACED(mode) (mode.flags & DRM_MODE_FLAG_INTERLACE)
#define IS_PROGRESSIVE(mode) (!IS_INTERLACED(mode))
find_connector_mode: find_connector_mode:
TRACELOG(LOG_TRACE, "searching connector mode, should find exactly matching: %s, should avoid progressive mode: %s",
findExactly ? "yes" : "no", avoidProgressive ? "yes" : "no");
// If InitWindow should use the current mode find it in the connector's mode list // If InitWindow should use the current mode find it in the connector's mode list
if ((CORE.Window.screen.width <= 0) || (CORE.Window.screen.height <= 0)) if ((CORE.Window.screen.width <= 0) || (CORE.Window.screen.height <= 0))
{ {
@ -3162,19 +3167,20 @@ find_connector_mode:
TRACELOG(LOG_TRACE, "selecting for (res 0x0)"); TRACELOG(LOG_TRACE, "selecting for (res 0x0)");
for (int i = CORE.Window.connector->count_modes - 1; i >= 0; i--) for (int i = CORE.Window.connector->count_modes - 1; i >= 0; i--)
{ {
TRACELOG(LOG_TRACE, "mode %i h=%i v=%i", i, CORE.Window.connector->modes[i].hdisplay, CORE.Window.connector->modes[i].vdisplay); TRACELOG(LOG_TRACE, "mode %i h=%i v=%i %s", i, CORE.Window.connector->modes[i].hdisplay, CORE.Window.connector->modes[i].vdisplay,
if (CORE.Window.connector->modes[i].flags & DRM_MODE_FLAG_INTERLACE) IS_INTERLACED(CORE.Window.connector->modes[i]) ? "interlaced" : "progressive");
if (IS_PROGRESSIVE(CORE.Window.connector->modes[i]))
{ {
TRACELOG(LOG_TRACE, "interlaced mode"); TRACELOG(LOG_TRACE, "progressive mode");
if (!(CORE.Window.flags & FLAG_INTERLACED_HINT)) if (avoidProgressive)
{ {
TRACELOG(LOG_TRACE, "but shouldn't choose an interlaced mode"); TRACELOG(LOG_TRACE, "but shouldn't choose an progressive mode");
continue; continue;
} }
} }
else else
{ {
TRACELOG(LOG_TRACE, "progressive mode"); TRACELOG(LOG_TRACE, "interlaced mode");
} }
if (0 == BINCMP(&CORE.Window.crtc->mode, &CORE.Window.connector->modes[i])) if (0 == BINCMP(&CORE.Window.crtc->mode, &CORE.Window.connector->modes[i]))
@ -3197,30 +3203,31 @@ find_connector_mode:
// Get closest video mode to desired CORE.Window.screen.width/CORE.Window.screen.height // Get closest video mode to desired CORE.Window.screen.width/CORE.Window.screen.height
for (int i = CORE.Window.connector->count_modes - 1; i >= 0; i--) for (int i = CORE.Window.connector->count_modes - 1; i >= 0; i--)
{ {
TRACELOG(LOG_TRACE, "mode %i h=%i v=%i", i, CORE.Window.connector->modes[i].hdisplay, CORE.Window.connector->modes[i].vdisplay); TRACELOG(LOG_TRACE, "mode %i h=%i v=%i %s", i, CORE.Window.connector->modes[i].hdisplay, CORE.Window.connector->modes[i].vdisplay,
if (CORE.Window.connector->modes[i].flags & DRM_MODE_FLAG_INTERLACE) IS_INTERLACED(CORE.Window.connector->modes[i]) ? "interlaced" : "progressive");
if (IS_PROGRESSIVE(CORE.Window.connector->modes[i]))
{ {
TRACELOG(LOG_TRACE, "interlaced mode"); TRACELOG(LOG_TRACE, "progressive mode");
if (!(CORE.Window.flags & FLAG_INTERLACED_HINT)) if (avoidProgressive)
{ {
TRACELOG(LOG_TRACE, "but shouldn't choose an interlaced mode"); TRACELOG(LOG_TRACE, "but shouldn't choose an progressive mode");
continue; continue;
} }
} }
else else
{ {
TRACELOG(LOG_TRACE, "progressive mode"); TRACELOG(LOG_TRACE, "interlaced mode");
} }
int found = 0; bool found = false;
if (findExactly) { if (findExactly) {
found = (CORE.Window.connector->modes[i].hdisplay == CORE.Window.screen.width) && found = (CORE.Window.connector->modes[i].hdisplay == CORE.Window.screen.width) &&
(CORE.Window.connector->modes[i].vdisplay == CORE.Window.screen.height); (CORE.Window.connector->modes[i].vdisplay == CORE.Window.screen.height);
} }
else else
{ {
found = (CORE.Window.connector->modes[i].hdisplay >= CORE.Window.screen.width) && found = (CORE.Window.connector->modes[i].hdisplay >= CORE.Window.screen.width) &&
(CORE.Window.connector->modes[i].vdisplay >= CORE.Window.screen.height); (CORE.Window.connector->modes[i].vdisplay >= CORE.Window.screen.height);
} }
if (found) if (found)
{ {
@ -3232,19 +3239,21 @@ find_connector_mode:
} }
} }
} }
#undef IS_PROGRESSIVE
#undef IS_INTERLACED
if (CORE.Window.modeIndex < 0) if (CORE.Window.modeIndex < 0)
{ {
if (findExactly) if (findExactly)
{ {
findExactly = 0; findExactly = false;
goto find_connector_mode; goto find_connector_mode;
} }
else else
{ {
if (CORE.Window.flags & FLAG_INTERLACED_HINT) if (avoidProgressive)
{ {
CORE.Window.flags &= ~FLAG_INTERLACED_HINT; avoidProgressive = false;
findExactly = 1; findExactly = true;
goto find_connector_mode; goto find_connector_mode;
} }
} }