mirror of
https://github.com/SFML/SFML.git
synced 2024-11-24 20:31:05 +08:00
[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
40
extlibs/headers/drm/drm-common.c
vendored
40
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");
|
||||
}
|
||||
|
||||
/* 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: */
|
||||
for (i = 0; i < resources->count_encoders; i++)
|
||||
{
|
||||
@ -373,7 +345,17 @@ 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
|
||||
drm->original_crtc = drmModeGetCrtc(drm->fd, drm->crtc_id);
|
||||
|
||||
if(getenv("SFML_DRM_DEBUG"))
|
||||
/* 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"))
|
||||
{
|
||||
printf("DRM Mode used: %s@%d\n", drm->mode->name, drm->mode->vrefresh);
|
||||
}
|
||||
|
@ -94,14 +94,18 @@ namespace
|
||||
if (!initialized)
|
||||
return;
|
||||
|
||||
drmModeSetCrtc(drmNode.fd,
|
||||
drmNode.original_crtc->crtc_id,
|
||||
drmNode.original_crtc->buffer_id,
|
||||
drmNode.original_crtc->x,
|
||||
drmNode.original_crtc->y,
|
||||
&drmNode.connector_id,
|
||||
1,
|
||||
&drmNode.original_crtc->mode);
|
||||
/* Avoid a modeswitch if possible */
|
||||
if (drmNode.mode != &drmNode.original_crtc->mode)
|
||||
drmModeSetCrtc(drmNode.fd,
|
||||
drmNode.original_crtc->crtc_id,
|
||||
drmNode.original_crtc->buffer_id,
|
||||
drmNode.original_crtc->x,
|
||||
drmNode.original_crtc->y,
|
||||
&drmNode.connector_id,
|
||||
1,
|
||||
&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);
|
||||
drmModeFreeEncoder(drmNode.saved_encoder);
|
||||
|
Loading…
Reference in New Issue
Block a user