glx: Unify dri2/dri3 vblank_mode logic.
We need it from kopper, as well. Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz@gmail.com> Reviewed-by: Adam Jackson <ajax@redhat.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17470>
This commit is contained in:
parent
f9ecf99ca9
commit
ff18be0872
|
@ -49,12 +49,7 @@
|
||||||
#include "dri_common.h"
|
#include "dri_common.h"
|
||||||
#include "dri2_priv.h"
|
#include "dri2_priv.h"
|
||||||
#include "loader.h"
|
#include "loader.h"
|
||||||
|
#include "loader_dri_helper.h"
|
||||||
/* From driconf.h, user exposed so should be stable */
|
|
||||||
#define DRI_CONF_VBLANK_NEVER 0
|
|
||||||
#define DRI_CONF_VBLANK_DEF_INTERVAL_0 1
|
|
||||||
#define DRI_CONF_VBLANK_DEF_INTERVAL_1 2
|
|
||||||
#define DRI_CONF_VBLANK_ALWAYS_SYNC 3
|
|
||||||
|
|
||||||
#undef DRI2_MINOR
|
#undef DRI2_MINOR
|
||||||
#define DRI2_MINOR 1
|
#define DRI2_MINOR 1
|
||||||
|
@ -302,7 +297,6 @@ dri2CreateDrawable(struct glx_screen *base, XID xDrawable,
|
||||||
__GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) config_base;
|
__GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) config_base;
|
||||||
struct glx_display *dpyPriv;
|
struct glx_display *dpyPriv;
|
||||||
struct dri2_display *pdp;
|
struct dri2_display *pdp;
|
||||||
GLint vblank_mode = DRI_CONF_VBLANK_DEF_INTERVAL_1;
|
|
||||||
|
|
||||||
dpyPriv = __glXInitialize(psc->base.dpy);
|
dpyPriv = __glXInitialize(psc->base.dpy);
|
||||||
if (dpyPriv == NULL)
|
if (dpyPriv == NULL)
|
||||||
|
@ -317,25 +311,9 @@ dri2CreateDrawable(struct glx_screen *base, XID xDrawable,
|
||||||
pdraw->base.drawable = drawable;
|
pdraw->base.drawable = drawable;
|
||||||
pdraw->base.psc = &psc->base;
|
pdraw->base.psc = &psc->base;
|
||||||
pdraw->bufferCount = 0;
|
pdraw->bufferCount = 0;
|
||||||
pdraw->swap_interval = 1; /* default may be overridden below */
|
pdraw->swap_interval = dri_get_initial_swap_interval(psc->driScreen, psc->config);
|
||||||
pdraw->have_back = 0;
|
pdraw->have_back = 0;
|
||||||
|
|
||||||
if (psc->config)
|
|
||||||
psc->config->configQueryi(psc->driScreen,
|
|
||||||
"vblank_mode", &vblank_mode);
|
|
||||||
|
|
||||||
switch (vblank_mode) {
|
|
||||||
case DRI_CONF_VBLANK_NEVER:
|
|
||||||
case DRI_CONF_VBLANK_DEF_INTERVAL_0:
|
|
||||||
pdraw->swap_interval = 0;
|
|
||||||
break;
|
|
||||||
case DRI_CONF_VBLANK_DEF_INTERVAL_1:
|
|
||||||
case DRI_CONF_VBLANK_ALWAYS_SYNC:
|
|
||||||
default:
|
|
||||||
pdraw->swap_interval = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
DRI2CreateDrawable(psc->base.dpy, xDrawable);
|
DRI2CreateDrawable(psc->base.dpy, xDrawable);
|
||||||
pdp = (struct dri2_display *)dpyPriv->dri2Display;
|
pdp = (struct dri2_display *)dpyPriv->dri2Display;
|
||||||
/* Create a new drawable */
|
/* Create a new drawable */
|
||||||
|
@ -832,25 +810,10 @@ dri2SetSwapInterval(__GLXDRIdrawable *pdraw, int interval)
|
||||||
{
|
{
|
||||||
xcb_connection_t *c = XGetXCBConnection(pdraw->psc->dpy);
|
xcb_connection_t *c = XGetXCBConnection(pdraw->psc->dpy);
|
||||||
struct dri2_drawable *priv = (struct dri2_drawable *) pdraw;
|
struct dri2_drawable *priv = (struct dri2_drawable *) pdraw;
|
||||||
GLint vblank_mode = DRI_CONF_VBLANK_DEF_INTERVAL_1;
|
|
||||||
struct dri2_screen *psc = (struct dri2_screen *) priv->base.psc;
|
struct dri2_screen *psc = (struct dri2_screen *) priv->base.psc;
|
||||||
|
|
||||||
if (psc->config)
|
if (!dri_valid_swap_interval(psc->driScreen, psc->config, interval))
|
||||||
psc->config->configQueryi(psc->driScreen,
|
return GLX_BAD_VALUE;
|
||||||
"vblank_mode", &vblank_mode);
|
|
||||||
|
|
||||||
switch (vblank_mode) {
|
|
||||||
case DRI_CONF_VBLANK_NEVER:
|
|
||||||
if (interval != 0)
|
|
||||||
return GLX_BAD_VALUE;
|
|
||||||
break;
|
|
||||||
case DRI_CONF_VBLANK_ALWAYS_SYNC:
|
|
||||||
if (interval <= 0)
|
|
||||||
return GLX_BAD_VALUE;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
xcb_dri2_swap_interval(c, priv->base.xDrawable, interval);
|
xcb_dri2_swap_interval(c, priv->base.xDrawable, interval);
|
||||||
priv->swap_interval = interval;
|
priv->swap_interval = interval;
|
||||||
|
|
|
@ -76,6 +76,7 @@
|
||||||
#include "dri_common.h"
|
#include "dri_common.h"
|
||||||
#include "dri3_priv.h"
|
#include "dri3_priv.h"
|
||||||
#include "loader.h"
|
#include "loader.h"
|
||||||
|
#include "loader_dri_helper.h"
|
||||||
#include "dri2.h"
|
#include "dri2.h"
|
||||||
|
|
||||||
static struct dri3_drawable *
|
static struct dri3_drawable *
|
||||||
|
@ -646,25 +647,10 @@ dri3_set_swap_interval(__GLXDRIdrawable *pdraw, int interval)
|
||||||
assert(pdraw != NULL);
|
assert(pdraw != NULL);
|
||||||
|
|
||||||
struct dri3_drawable *priv = (struct dri3_drawable *) pdraw;
|
struct dri3_drawable *priv = (struct dri3_drawable *) pdraw;
|
||||||
GLint vblank_mode = DRI_CONF_VBLANK_DEF_INTERVAL_1;
|
|
||||||
struct dri3_screen *psc = (struct dri3_screen *) priv->base.psc;
|
struct dri3_screen *psc = (struct dri3_screen *) priv->base.psc;
|
||||||
|
|
||||||
if (psc->config)
|
if (!dri_valid_swap_interval(psc->driScreen, psc->config, interval))
|
||||||
psc->config->configQueryi(psc->driScreen,
|
return GLX_BAD_VALUE;
|
||||||
"vblank_mode", &vblank_mode);
|
|
||||||
|
|
||||||
switch (vblank_mode) {
|
|
||||||
case DRI_CONF_VBLANK_NEVER:
|
|
||||||
if (interval != 0)
|
|
||||||
return GLX_BAD_VALUE;
|
|
||||||
break;
|
|
||||||
case DRI_CONF_VBLANK_ALWAYS_SYNC:
|
|
||||||
if (interval <= 0)
|
|
||||||
return GLX_BAD_VALUE;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
loader_dri3_set_swap_interval(&priv->loader_drawable, interval);
|
loader_dri3_set_swap_interval(&priv->loader_drawable, interval);
|
||||||
|
|
||||||
|
|
|
@ -61,12 +61,6 @@
|
||||||
|
|
||||||
#include "loader_dri3_helper.h"
|
#include "loader_dri3_helper.h"
|
||||||
|
|
||||||
/* From driconf.h, user exposed so should be stable */
|
|
||||||
#define DRI_CONF_VBLANK_NEVER 0
|
|
||||||
#define DRI_CONF_VBLANK_DEF_INTERVAL_0 1
|
|
||||||
#define DRI_CONF_VBLANK_DEF_INTERVAL_1 2
|
|
||||||
#define DRI_CONF_VBLANK_ALWAYS_SYNC 3
|
|
||||||
|
|
||||||
struct dri3_display
|
struct dri3_display
|
||||||
{
|
{
|
||||||
__GLXDRIdisplay base;
|
__GLXDRIdisplay base;
|
||||||
|
|
|
@ -39,12 +39,6 @@
|
||||||
#include "util/macros.h"
|
#include "util/macros.h"
|
||||||
#include "drm-uapi/drm_fourcc.h"
|
#include "drm-uapi/drm_fourcc.h"
|
||||||
|
|
||||||
/* From driconf.h, user exposed so should be stable */
|
|
||||||
#define DRI_CONF_VBLANK_NEVER 0
|
|
||||||
#define DRI_CONF_VBLANK_DEF_INTERVAL_0 1
|
|
||||||
#define DRI_CONF_VBLANK_DEF_INTERVAL_1 2
|
|
||||||
#define DRI_CONF_VBLANK_ALWAYS_SYNC 3
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A cached blit context.
|
* A cached blit context.
|
||||||
*/
|
*/
|
||||||
|
@ -397,8 +391,6 @@ loader_dri3_drawable_init(xcb_connection_t *conn,
|
||||||
xcb_get_geometry_cookie_t cookie;
|
xcb_get_geometry_cookie_t cookie;
|
||||||
xcb_get_geometry_reply_t *reply;
|
xcb_get_geometry_reply_t *reply;
|
||||||
xcb_generic_error_t *error;
|
xcb_generic_error_t *error;
|
||||||
GLint vblank_mode = DRI_CONF_VBLANK_DEF_INTERVAL_1;
|
|
||||||
int swap_interval;
|
|
||||||
|
|
||||||
draw->conn = conn;
|
draw->conn = conn;
|
||||||
draw->ext = ext;
|
draw->ext = ext;
|
||||||
|
@ -425,9 +417,6 @@ loader_dri3_drawable_init(xcb_connection_t *conn,
|
||||||
if (draw->ext->config) {
|
if (draw->ext->config) {
|
||||||
unsigned char adaptive_sync = 0;
|
unsigned char adaptive_sync = 0;
|
||||||
|
|
||||||
draw->ext->config->configQueryi(draw->dri_screen,
|
|
||||||
"vblank_mode", &vblank_mode);
|
|
||||||
|
|
||||||
draw->ext->config->configQueryb(draw->dri_screen,
|
draw->ext->config->configQueryb(draw->dri_screen,
|
||||||
"adaptive_sync",
|
"adaptive_sync",
|
||||||
&adaptive_sync);
|
&adaptive_sync);
|
||||||
|
@ -438,18 +427,8 @@ loader_dri3_drawable_init(xcb_connection_t *conn,
|
||||||
if (!draw->adaptive_sync)
|
if (!draw->adaptive_sync)
|
||||||
set_adaptive_sync_property(conn, draw->drawable, false);
|
set_adaptive_sync_property(conn, draw->drawable, false);
|
||||||
|
|
||||||
switch (vblank_mode) {
|
draw->swap_interval = dri_get_initial_swap_interval(draw->dri_screen,
|
||||||
case DRI_CONF_VBLANK_NEVER:
|
draw->ext->config);
|
||||||
case DRI_CONF_VBLANK_DEF_INTERVAL_0:
|
|
||||||
swap_interval = 0;
|
|
||||||
break;
|
|
||||||
case DRI_CONF_VBLANK_DEF_INTERVAL_1:
|
|
||||||
case DRI_CONF_VBLANK_ALWAYS_SYNC:
|
|
||||||
default:
|
|
||||||
swap_interval = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
draw->swap_interval = swap_interval;
|
|
||||||
|
|
||||||
dri3_update_max_num_back(draw);
|
dri3_update_max_num_back(draw);
|
||||||
|
|
||||||
|
@ -487,7 +466,7 @@ loader_dri3_drawable_init(xcb_connection_t *conn,
|
||||||
* Make sure server has the same swap interval we do for the new
|
* Make sure server has the same swap interval we do for the new
|
||||||
* drawable.
|
* drawable.
|
||||||
*/
|
*/
|
||||||
loader_dri3_set_swap_interval(draw, swap_interval);
|
loader_dri3_set_swap_interval(draw, draw->swap_interval);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,3 +72,56 @@ __DRIimage *loader_dri_create_image(__DRIscreen *screen,
|
||||||
return image->createImage(screen, width, height, dri_format, dri_usage,
|
return image->createImage(screen, width, height, dri_format, dri_usage,
|
||||||
loaderPrivate);
|
loaderPrivate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* From driconf.h, user exposed so should be stable */
|
||||||
|
#define DRI_CONF_VBLANK_NEVER 0
|
||||||
|
#define DRI_CONF_VBLANK_DEF_INTERVAL_0 1
|
||||||
|
#define DRI_CONF_VBLANK_DEF_INTERVAL_1 2
|
||||||
|
#define DRI_CONF_VBLANK_ALWAYS_SYNC 3
|
||||||
|
|
||||||
|
static int dri_vblank_mode(__DRIscreen *driScreen, const __DRI2configQueryExtension *config)
|
||||||
|
{
|
||||||
|
GLint vblank_mode = DRI_CONF_VBLANK_DEF_INTERVAL_1;
|
||||||
|
|
||||||
|
if (config)
|
||||||
|
config->configQueryi(driScreen, "vblank_mode", &vblank_mode);
|
||||||
|
|
||||||
|
return vblank_mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
int dri_get_initial_swap_interval(__DRIscreen *driScreen,
|
||||||
|
const __DRI2configQueryExtension *config)
|
||||||
|
{
|
||||||
|
int vblank_mode = dri_vblank_mode(driScreen, config);
|
||||||
|
|
||||||
|
switch (vblank_mode) {
|
||||||
|
case DRI_CONF_VBLANK_NEVER:
|
||||||
|
case DRI_CONF_VBLANK_DEF_INTERVAL_0:
|
||||||
|
return 0;
|
||||||
|
case DRI_CONF_VBLANK_DEF_INTERVAL_1:
|
||||||
|
case DRI_CONF_VBLANK_ALWAYS_SYNC:
|
||||||
|
default:
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dri_valid_swap_interval(__DRIscreen *driScreen,
|
||||||
|
const __DRI2configQueryExtension *config, int interval)
|
||||||
|
{
|
||||||
|
int vblank_mode = dri_vblank_mode(driScreen, config);
|
||||||
|
|
||||||
|
switch (vblank_mode) {
|
||||||
|
case DRI_CONF_VBLANK_NEVER:
|
||||||
|
if (interval != 0)
|
||||||
|
return false;
|
||||||
|
break;
|
||||||
|
case DRI_CONF_VBLANK_ALWAYS_SYNC:
|
||||||
|
if (interval <= 0)
|
||||||
|
return false;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
|
@ -31,3 +31,9 @@ __DRIimage *loader_dri_create_image(__DRIscreen *screen,
|
||||||
const uint64_t *modifiers,
|
const uint64_t *modifiers,
|
||||||
unsigned int modifiers_count,
|
unsigned int modifiers_count,
|
||||||
void *loaderPrivate);
|
void *loaderPrivate);
|
||||||
|
|
||||||
|
int dri_get_initial_swap_interval(__DRIscreen *driScreen,
|
||||||
|
const __DRI2configQueryExtension *config);
|
||||||
|
|
||||||
|
bool dri_valid_swap_interval(__DRIscreen *driScreen,
|
||||||
|
const __DRI2configQueryExtension *config, int interval);
|
||||||
|
|
Loading…
Reference in New Issue