glamor: Implement GetSupportedModifiers

Implement function added in DRI3 v1.1.

A newest version of libepoxy (>= 1.4.4) is required as earlier
versions use a problematic version of Khronos
EXT_image_dma_buf_import_modifiers spec.

v4: Only send scanout-supported modifiers if flipping is possible
v5: Fix memory corruption in XWayland (uninitialized pointer)

Signed-off-by: Louis-Francis Ratté-Boulianne <lfrb@collabora.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
Acked-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
This commit is contained in:
Louis-Francis Ratté-Boulianne 2018-02-28 01:19:44 +00:00 committed by Adam Jackson
parent c8c276c956
commit cef12efc15
18 changed files with 372 additions and 24 deletions

View File

@ -2087,6 +2087,10 @@ if test "x$GLAMOR" = xyes; then
AC_DEFINE(GLAMOR, 1, [Build glamor])
PKG_CHECK_MODULES([GLAMOR], [epoxy])
PKG_CHECK_EXISTS(epoxy >= 1.4.4,
[AC_DEFINE(GLAMOR_HAS_EGL_QUERY_DMABUF, 1, [Have GLAMOR_HAS_EGL_QUERY_DMABUF])],
[])
PKG_CHECK_MODULES(GBM, "$LIBGBM", [GBM=yes], [GBM=no])
if test "x$GBM" = xyes; then
AC_DEFINE(GLAMOR_HAS_GBM, 1,

View File

@ -793,6 +793,31 @@ glamor_supports_pixmap_import_export(ScreenPtr screen)
return glamor_priv->dri3_enabled;
}
_X_EXPORT void
glamor_set_drawable_modifiers_func(ScreenPtr screen,
GetDrawableModifiersFuncPtr func)
{
glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
glamor_priv->get_drawable_modifiers = func;
}
_X_EXPORT Bool
glamor_get_drawable_modifiers(DrawablePtr draw, CARD32 format,
CARD32 *num_modifiers, uint64_t **modifiers)
{
struct glamor_screen_private *glamor_priv =
glamor_get_screen_private(draw->pScreen);
if (glamor_priv->get_drawable_modifiers) {
return glamor_priv->get_drawable_modifiers(draw, format,
num_modifiers, modifiers);
}
*num_modifiers = 0;
*modifiers = NULL;
return TRUE;
}
_X_EXPORT int
glamor_fds_from_pixmap(ScreenPtr screen, PixmapPtr pixmap, int *fds,
uint32_t *strides, uint32_t *offsets,

View File

@ -60,6 +60,11 @@ typedef enum glamor_pixmap_type {
GLAMOR_TEXTURE_ONLY,
} glamor_pixmap_type_t;
typedef Bool (*GetDrawableModifiersFuncPtr) (DrawablePtr draw,
CARD32 format,
CARD32 *num_modifiers,
uint64_t **modifiers);
#define GLAMOR_EGL_EXTERNAL_BUFFER 3
#define GLAMOR_USE_EGL_SCREEN (1 << 0)
#define GLAMOR_NO_DRI3 (1 << 1)
@ -272,6 +277,24 @@ extern _X_EXPORT Bool glamor_back_pixmap_from_fd(PixmapPtr pixmap,
CARD16 stride,
CARD8 depth,
CARD8 bpp);
extern _X_EXPORT Bool glamor_get_formats(ScreenPtr screen,
CARD32 *num_formats,
CARD32 **formats);
extern _X_EXPORT Bool glamor_get_modifiers(ScreenPtr screen,
CARD32 format,
CARD32 *num_modifiers,
uint64_t **modifiers);
extern _X_EXPORT Bool glamor_get_drawable_modifiers(DrawablePtr draw,
CARD32 format,
CARD32 *num_modifiers,
uint64_t **modifiers);
extern _X_EXPORT void glamor_set_drawable_modifiers_func(ScreenPtr screen,
GetDrawableModifiersFuncPtr func);
#ifdef GLAMOR_FOR_XORG
#define GLAMOR_EGL_MODULE_NAME "glamoregl"

View File

@ -505,6 +505,95 @@ glamor_pixmap_from_fds(ScreenPtr screen,
return pixmap;
}
_X_EXPORT Bool
glamor_get_formats(ScreenPtr screen,
CARD32 *num_formats, CARD32 **formats)
{
#ifdef GLAMOR_HAS_EGL_QUERY_DMABUF
struct glamor_egl_screen_private *glamor_egl;
EGLint num;
glamor_egl = glamor_egl_get_screen_private(xf86ScreenToScrn(screen));
if (!glamor_egl->dmabuf_capable)
return FALSE;
if (!eglQueryDmaBufFormatsEXT(glamor_egl->display, 0, NULL, &num)) {
*num_formats = 0;
return FALSE;
}
if (num == 0) {
*num_formats = 0;
return TRUE;
}
*formats = calloc(num, sizeof(CARD32));
if (*formats == NULL) {
*num_formats = 0;
return FALSE;
}
if (!eglQueryDmaBufFormatsEXT(glamor_egl->display, num,
(EGLint *) *formats, &num)) {
*num_formats = 0;
free(*formats);
return FALSE;
}
*num_formats = num;
return TRUE;
#else
*num_formats = 0;
return TRUE;
#endif
}
_X_EXPORT Bool
glamor_get_modifiers(ScreenPtr screen, CARD32 format,
CARD32 *num_modifiers, uint64_t **modifiers)
{
#ifdef GLAMOR_HAS_EGL_QUERY_DMABUF
struct glamor_egl_screen_private *glamor_egl;
EGLint num;
glamor_egl = glamor_egl_get_screen_private(xf86ScreenToScrn(screen));
if (!glamor_egl->dmabuf_capable)
return FALSE;
if (!eglQueryDmaBufModifiersEXT(glamor_egl->display, format, 0, NULL,
NULL, &num)) {
*num_modifiers = 0;
return FALSE;
}
if (num == 0) {
*num_modifiers = 0;
return TRUE;
}
*modifiers = calloc(num, sizeof(uint64_t));
if (*modifiers == NULL) {
*num_modifiers = 0;
return FALSE;
}
if (!eglQueryDmaBufModifiersEXT(glamor_egl->display, format, num,
(EGLuint64KHR *) *modifiers, NULL, &num)) {
*num_modifiers = 0;
free(*modifiers);
return FALSE;
}
*num_modifiers = num;
return TRUE;
#else
*num_modifiers = 0;
return TRUE;
#endif
}
static Bool
glamor_egl_destroy_pixmap(PixmapPtr pixmap)
{
@ -626,6 +715,9 @@ static dri3_screen_info_rec glamor_dri3_info = {
.open_client = glamor_dri3_open_client,
.pixmap_from_fds = glamor_pixmap_from_fds,
.fds_from_pixmap = glamor_egl_fds_from_pixmap,
.get_formats = glamor_get_formats,
.get_modifiers = glamor_get_modifiers,
.get_drawable_modifiers = glamor_get_drawable_modifiers,
};
#endif /* DRI3 */

View File

@ -281,6 +281,7 @@ typedef struct glamor_screen_private {
int radial_max_nstops;
struct glamor_saved_procs saved_procs;
GetDrawableModifiersFuncPtr get_drawable_modifiers;
int flags;
ScreenPtr screen;
int dri3_enabled;

View File

@ -38,12 +38,14 @@ if build_xv
srcs_glamor += 'glamor_xv.c'
endif
epoxy_dep = dependency('epoxy')
glamor = static_library('glamor',
srcs_glamor,
include_directories: inc,
dependencies: [
common_dep,
dependency('epoxy'),
epoxy_dep,
],
)

View File

@ -30,6 +30,7 @@ if build_glamor
xephyr_glamor += glamor
xephyr_glamor += glamor_egl_stubs
xephyr_dep += dependency('x11-xcb')
xephyr_dep += epoxy_dep
endif
if build_xv

View File

@ -86,6 +86,7 @@
#include <X11/X.h>
#include "xf86Modes.h"
#include "xf86Crtc.h"
#include "os.h"
#include "servermd.h"
#include "globals.h"

View File

@ -1601,15 +1601,11 @@ ScreenInit(ScreenPtr pScreen, int argc, char **argv)
fbPictureInit(pScreen, NULL, 0);
#ifdef GLAMOR_HAS_GBM
if (ms->drmmode.glamor) {
if (!glamor_init(pScreen, GLAMOR_USE_EGL_SCREEN)) {
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
"Failed to initialize glamor at ScreenInit() time.\n");
return FALSE;
}
if (drmmode_init(pScrn, &ms->drmmode) == FALSE) {
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
"Failed to initialize glamor at ScreenInit() time.\n");
return FALSE;
}
#endif
if (ms->drmmode.shadow_enable && !msShadowInit(pScreen)) {
xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "shadow fb init failed\n");

View File

@ -45,6 +45,7 @@
#include <xf86drm.h>
#include "xf86Crtc.h"
#include "drmmode_display.h"
#include "present.h"
#include <cursorstr.h>
@ -175,6 +176,24 @@ get_modifiers_set(ScrnInfoPtr scrn, uint32_t format, uint64_t **modifiers,
*modifiers = ret;
return count_modifiers;
}
static Bool
get_drawable_modifiers(DrawablePtr draw, uint32_t format,
uint32_t *num_modifiers, uint64_t **modifiers)
{
ScrnInfoPtr scrn = xf86ScreenToScrn(draw->pScreen);
modesettingPtr ms = modesettingPTR(scrn);
if (!present_can_window_flip((WindowPtr) draw) ||
!ms->drmmode.pageflip || ms->drmmode.dri2_flipping || !scrn->vtSema) {
*num_modifiers = 0;
*modifiers = NULL;
return TRUE;
}
*num_modifiers = get_modifiers_set(scrn, format, modifiers, TRUE, FALSE);
return TRUE;
}
#endif
static Bool
@ -3121,6 +3140,25 @@ drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp)
return TRUE;
}
Bool
drmmode_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode)
{
#ifdef GLAMOR_HAS_GBM
ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
if (drmmode->glamor) {
if (!glamor_init(pScreen, GLAMOR_USE_EGL_SCREEN)) {
return FALSE;
}
#ifdef GBM_BO_WITH_MODIFIERS
glamor_set_drawable_modifiers_func(pScreen, get_drawable_modifiers);
#endif
}
#endif
return TRUE;
}
void
drmmode_adjust_frame(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int x, int y)
{

View File

@ -263,6 +263,7 @@ Bool drmmode_SharedPixmapFlip(PixmapPtr frontTarget, xf86CrtcPtr crtc,
void drmmode_DisableSharedPixmapFlipping(xf86CrtcPtr crtc, drmmode_ptr drmmode);
extern Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp);
extern Bool drmmode_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode);
void drmmode_adjust_frame(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int x, int y);
extern Bool drmmode_set_desired_modes(ScrnInfoPtr pScrn, drmmode_ptr drmmode, Bool set_hw);
extern Bool drmmode_setup_colormap(ScreenPtr pScreen, ScrnInfoPtr pScrn);

View File

@ -407,19 +407,6 @@ xwl_drm_handle_device(void *data, struct wl_drm *drm, const char *device)
static void
xwl_drm_handle_format(void *data, struct wl_drm *drm, uint32_t format)
{
struct xwl_screen *xwl_screen = data;
switch (format) {
case WL_DRM_FORMAT_ARGB8888:
xwl_screen->formats |= XWL_FORMAT_ARGB8888;
break;
case WL_DRM_FORMAT_XRGB8888:
xwl_screen->formats |= XWL_FORMAT_XRGB8888;
break;
case WL_DRM_FORMAT_RGB565:
xwl_screen->formats |= XWL_FORMAT_RGB565;
break;
}
}
static void
@ -446,6 +433,54 @@ static const struct wl_drm_listener xwl_drm_listener = {
xwl_drm_handle_capabilities
};
static void
xwl_dmabuf_handle_format(void *data, struct zwp_linux_dmabuf_v1 *dmabuf,
uint32_t format)
{
}
static void
xwl_dmabuf_handle_modifier(void *data, struct zwp_linux_dmabuf_v1 *dmabuf,
uint32_t format, uint32_t modifier_hi,
uint32_t modifier_lo)
{
struct xwl_screen *xwl_screen = data;
struct xwl_format *xwl_format = NULL;
int i;
for (i = 0; i < xwl_screen->num_formats; i++) {
if (xwl_screen->formats[i].format == format) {
xwl_format = &xwl_screen->formats[i];
break;
}
}
if (xwl_format == NULL) {
xwl_screen->num_formats++;
xwl_screen->formats = realloc(xwl_screen->formats,
xwl_screen->num_formats * sizeof(*xwl_format));
if (!xwl_screen->formats)
return;
xwl_format = &xwl_screen->formats[xwl_screen->num_formats - 1];
xwl_format->format = format;
xwl_format->num_modifiers = 0;
xwl_format->modifiers = NULL;
}
xwl_format->num_modifiers++;
xwl_format->modifiers = realloc(xwl_format->modifiers,
xwl_format->num_modifiers * sizeof(uint64_t));
if (!xwl_format->modifiers)
return;
xwl_format->modifiers[xwl_format->num_modifiers - 1] = (uint64_t) modifier_lo;
xwl_format->modifiers[xwl_format->num_modifiers - 1] |= (uint64_t) modifier_hi << 32;
}
static const struct zwp_linux_dmabuf_v1_listener xwl_dmabuf_listener = {
.format = xwl_dmabuf_handle_format,
.modifier = xwl_dmabuf_handle_modifier
};
Bool
xwl_screen_set_drm_interface(struct xwl_screen *xwl_screen,
uint32_t id, uint32_t version)
@ -470,6 +505,7 @@ xwl_screen_set_dmabuf_interface(struct xwl_screen *xwl_screen,
xwl_screen->dmabuf =
wl_registry_bind(xwl_screen->registry, id, &zwp_linux_dmabuf_v1_interface, 3);
zwp_linux_dmabuf_v1_add_listener(xwl_screen->dmabuf, &xwl_dmabuf_listener, xwl_screen);
return TRUE;
}
@ -678,12 +714,85 @@ glamor_egl_fds_from_pixmap(ScreenPtr screen, PixmapPtr pixmap, int *fds,
#endif
}
_X_EXPORT Bool
glamor_get_formats(ScreenPtr screen,
CARD32 *num_formats, CARD32 **formats)
{
struct xwl_screen *xwl_screen = xwl_screen_get(screen);
int i;
if (!xwl_screen->dmabuf_capable || !xwl_screen->dmabuf)
return FALSE;
if (xwl_screen->num_formats == 0) {
*num_formats = 0;
return TRUE;
}
*formats = calloc(xwl_screen->num_formats, sizeof(CARD32));
if (*formats == NULL) {
*num_formats = 0;
return FALSE;
}
for (i = 0; i < xwl_screen->num_formats; i++)
(*formats)[i] = xwl_screen->formats[i].format;
*num_formats = xwl_screen->num_formats;
return TRUE;
}
_X_EXPORT Bool
glamor_get_modifiers(ScreenPtr screen, CARD32 format,
CARD32 *num_modifiers, uint64_t **modifiers)
{
struct xwl_screen *xwl_screen = xwl_screen_get(screen);
struct xwl_format *xwl_format = NULL;
int i;
if (!xwl_screen->dmabuf_capable || !xwl_screen->dmabuf)
return FALSE;
if (xwl_screen->num_formats == 0) {
*num_modifiers = 0;
return TRUE;
}
for (i = 0; i < xwl_screen->num_formats; i++) {
if (xwl_screen->formats[i].format == format) {
xwl_format = &xwl_screen->formats[i];
break;
}
}
if (!xwl_format) {
*num_modifiers = 0;
return FALSE;
}
*modifiers = calloc(xwl_format->num_modifiers, sizeof(uint64_t));
if (*modifiers == NULL) {
*num_modifiers = 0;
return FALSE;
}
for (i = 0; i < xwl_format->num_modifiers; i++)
(*modifiers)[i] = xwl_format->modifiers[i];
*num_modifiers = xwl_format->num_modifiers;
return TRUE;
}
static dri3_screen_info_rec xwl_dri3_info = {
.version = 2,
.open = NULL,
.pixmap_from_fds = glamor_pixmap_from_fds,
.fds_from_pixmap = glamor_fds_from_pixmap,
.open_client = xwl_dri3_open_client,
.get_formats = glamor_get_formats,
.get_modifiers = glamor_get_modifiers,
.get_drawable_modifiers = glamor_get_drawable_modifiers,
};
Bool

View File

@ -49,6 +49,12 @@
#include "xdg-output-unstable-v1-client-protocol.h"
#include "linux-dmabuf-unstable-v1-client-protocol.h"
struct xwl_format {
uint32_t format;
int num_modifiers;
uint64_t *modifiers;
};
struct xwl_screen {
int width;
int height;
@ -100,7 +106,8 @@ struct xwl_screen {
int drm_authenticated;
struct wl_drm *drm;
struct zwp_linux_dmabuf_v1 *dmabuf;
uint32_t formats;
uint32_t num_formats;
struct xwl_format *formats;
uint32_t capabilities;
void *egl_display, *egl_context;
struct gbm_device *gbm;

View File

@ -500,6 +500,9 @@
/* Glamor can retrieve supported DRM formats/modifiers */
#undef GLAMOR_HAS_DRM_MODIFIERS
/* Glamor can use eglQueryDmaBuf* functions */
#undef GLAMOR_HAS_EGL_QUERY_DMABUF
/* byte order */
#undef X_BYTE_ORDER

View File

@ -79,6 +79,8 @@ conf_data.set('GLAMOR_HAS_DRM_NAME_FROM_FD_2',
libdrm_dep.found() and libdrm_dep.version().version_compare('>= 2.4.74'))
conf_data.set('GLAMOR_HAS_DRM_MODIFIERS',
libdrm_dep.found() and libdrm_dep.version().version_compare('>= 2.4.83'))
conf_data.set('GLAMOR_HAS_EGL_QUERY_DMABUF',
epoxy_dep.found() and epoxy_dep.version().version_compare('>= 1.4.4'))
conf_data.set('GLXEXT', build_glx)
conf_data.set('GLAMOR', build_glamor)
conf_data.set('GLAMOR_HAS_GBM', gbm_dep.found())

View File

@ -262,9 +262,11 @@ else
build_glamor = get_option('glamor') == 'true'
endif
gbm_dep = dependency('', required:false)
gbm_dep = dependency('', required: false)
epoxy_dep = dependency('', required: false)
if build_glamor
gbm_dep = dependency('gbm', version: '>= 10.2', required: false)
epoxy_dep = dependency('epoxy', required: false)
endif
# XXX: Add more sha1 options, because Linux is about choice

View File

@ -614,6 +614,44 @@ present_check_flip_window (WindowPtr window)
}
}
Bool
present_can_window_flip(WindowPtr window)
{
ScreenPtr screen = window->drawable.pScreen;
PixmapPtr window_pixmap;
WindowPtr root = screen->root;
present_screen_priv_ptr screen_priv = present_screen_priv(screen);
if (!screen_priv)
return FALSE;
if (!screen_priv->info)
return FALSE;
/* Check to see if the driver supports flips at all */
if (!screen_priv->info->flip)
return FALSE;
/* Make sure the window hasn't been redirected with Composite */
window_pixmap = screen->GetWindowPixmap(window);
if (window_pixmap != screen->GetScreenPixmap(screen) &&
window_pixmap != screen_priv->flip_pixmap &&
window_pixmap != present_flip_pending_pixmap(screen))
return FALSE;
/* Check for full-screen window */
if (!RegionEqual(&window->clipList, &root->winSize)) {
return FALSE;
}
/* Does the window match the pixmap exactly? */
if (window->drawable.x != 0 || window->drawable.y != 0) {
return FALSE;
}
return TRUE;
}
/*
* Called when the wait fence is triggered; just gets the current msc/ust and
* calls present_execute again. That will re-check the fence and pend the

View File

@ -135,4 +135,7 @@ typedef void (*present_complete_notify_proc)(WindowPtr window,
extern _X_EXPORT void
present_register_complete_notify(present_complete_notify_proc proc);
extern _X_EXPORT Bool
present_can_window_flip(WindowPtr window);
#endif /* _PRESENT_H_ */