[DRM] Use the current resolution
In order to prevent an unnecessary modeswitch and use the current TTY resolution, don't use the preferred mode reported by DRM. This is useful for people who set a custom resolution at boot and are forced into the monitor's preferred resolution when a SFML DRM app starts
This commit is contained in:
parent
1d12c56332
commit
65ef0619c8
38
extlibs/headers/drm/drm-common.c
vendored
38
extlibs/headers/drm/drm-common.c
vendored
@ -309,34 +309,6 @@ int init_drm(struct drm *drm, const char *device, const char *mode_str,
|
|||||||
printf("requested mode not found, using default mode!\n");
|
printf("requested mode not found, using default mode!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* find preferred mode or the highest resolution mode: */
|
|
||||||
if (!drm->mode)
|
|
||||||
{
|
|
||||||
for (i = 0, area = 0; i < connector->count_modes; i++)
|
|
||||||
{
|
|
||||||
drmModeModeInfo *current_mode = &connector->modes[i];
|
|
||||||
|
|
||||||
if (current_mode->type & DRM_MODE_TYPE_PREFERRED)
|
|
||||||
{
|
|
||||||
drm->mode = current_mode;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
int current_area = current_mode->hdisplay * current_mode->vdisplay;
|
|
||||||
if (current_area > area)
|
|
||||||
{
|
|
||||||
drm->mode = current_mode;
|
|
||||||
area = current_area;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!drm->mode)
|
|
||||||
{
|
|
||||||
printf("could not find mode!\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* find encoder: */
|
/* find encoder: */
|
||||||
for (i = 0; i < resources->count_encoders; i++)
|
for (i = 0; i < resources->count_encoders; i++)
|
||||||
{
|
{
|
||||||
@ -373,6 +345,16 @@ int init_drm(struct drm *drm, const char *device, const char *mode_str,
|
|||||||
// get original display mode so we can restore display mode after program exits
|
// get original display mode so we can restore display mode after program exits
|
||||||
drm->original_crtc = drmModeGetCrtc(drm->fd, drm->crtc_id);
|
drm->original_crtc = drmModeGetCrtc(drm->fd, drm->crtc_id);
|
||||||
|
|
||||||
|
/* Let's use the current mode rather than the preferred one if the user didn't
|
||||||
|
* specify a mode with env vars
|
||||||
|
*/
|
||||||
|
if (!drm->mode)
|
||||||
|
{
|
||||||
|
if(getenv("SFML_DRM_DEBUG"))
|
||||||
|
printf("DRM using the current mode\n");
|
||||||
|
drm->mode = &(drm->original_crtc->mode);
|
||||||
|
}
|
||||||
|
|
||||||
if (getenv("SFML_DRM_DEBUG"))
|
if (getenv("SFML_DRM_DEBUG"))
|
||||||
{
|
{
|
||||||
printf("DRM Mode used: %s@%d\n", drm->mode->name, drm->mode->vrefresh);
|
printf("DRM Mode used: %s@%d\n", drm->mode->name, drm->mode->vrefresh);
|
||||||
|
@ -94,6 +94,8 @@ namespace
|
|||||||
if (!initialized)
|
if (!initialized)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
/* Avoid a modeswitch if possible */
|
||||||
|
if (drmNode.mode != &drmNode.original_crtc->mode)
|
||||||
drmModeSetCrtc(drmNode.fd,
|
drmModeSetCrtc(drmNode.fd,
|
||||||
drmNode.original_crtc->crtc_id,
|
drmNode.original_crtc->crtc_id,
|
||||||
drmNode.original_crtc->buffer_id,
|
drmNode.original_crtc->buffer_id,
|
||||||
@ -102,6 +104,8 @@ namespace
|
|||||||
&drmNode.connector_id,
|
&drmNode.connector_id,
|
||||||
1,
|
1,
|
||||||
&drmNode.original_crtc->mode);
|
&drmNode.original_crtc->mode);
|
||||||
|
else if (getenv("SFML_DRM_DEBUG"))
|
||||||
|
printf("DRM keeping the same mode since using the original one\n");
|
||||||
|
|
||||||
drmModeFreeConnector(drmNode.saved_connector);
|
drmModeFreeConnector(drmNode.saved_connector);
|
||||||
drmModeFreeEncoder(drmNode.saved_encoder);
|
drmModeFreeEncoder(drmNode.saved_encoder);
|
||||||
|
Loading…
Reference in New Issue
Block a user