backends/native: Add meta_calculate_drm_mode_vblank_duration_us()

Computes the vblank duration from mode timings.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1762>
This commit is contained in:
Ivan Molodetskikh
2021-01-06 11:36:04 +03:00
committed by Marge Bot
parent 63b9ac2724
commit e40ff9d8b7
3 changed files with 129 additions and 4 deletions

View File

@ -47,6 +47,27 @@ meta_calculate_drm_mode_refresh_rate (const drmModeModeInfo *drm_mode)
return numerator / denominator;
}
int64_t
meta_calculate_drm_mode_vblank_duration_us (const drmModeModeInfo *drm_mode)
{
int64_t value;
if (drm_mode->htotal <= 0 || drm_mode->vtotal <= 0)
return 0;
/* Convert to int64_t early. */
value = drm_mode->vtotal - drm_mode->vdisplay;
value *= drm_mode->htotal;
if (drm_mode->flags & DRM_MODE_FLAG_DBLSCAN)
value *= 2;
/* Round the duration up as it is used for buffer swap deadline computation. */
value = (value * 1000 + drm_mode->clock - 1) / drm_mode->clock;
return value;
}
/**
* meta_drm_format_to_string:
* @tmp: temporary buffer

View File

@ -34,6 +34,9 @@ typedef struct _MetaDrmFormatBuf
META_EXPORT_TEST
float meta_calculate_drm_mode_refresh_rate (const drmModeModeInfo *drm_mode);
META_EXPORT_TEST
int64_t meta_calculate_drm_mode_vblank_duration_us (const drmModeModeInfo *drm_mode);
const char * meta_drm_format_to_string (MetaDrmFormatBuf *tmp,
uint32_t drm_format);