Re: xserver 1.20 RC1 tomorrow

2018-02-27 Thread Roman Gilg
On Tue, Feb 27, 2018 at 10:59 PM, Adam Jackson  wrote:
> 4) https://patchwork.freedesktop.org/series/37274/
> Per-window flips for Xwayland. No xfree86 changes.

Michel gave me feedback on my patches in the last weeks and I did
changes to some parts because of that. I planned on posting a new
patch series with these changes replacing the current one. I can do
this today.
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

Re: [PATCH v8 00/14] DRI3 multi-plane and modifier support

2018-02-27 Thread Daniel Stone
Hi,

On 28 February 2018 at 01:19, Daniel Stone  wrote:
> The major change is that the DRI3 protocol version has been bumped from
> 1.1 to 1.2, as there was previously a dri3proto-1.1 release, only
> carrying a 1.0 protocol version. We bump the version to avoid this,
> jumping straight from protocol version 1.0 to 1.2.

Wrong protocol.

Present needed to be bumped to 1.2, and DRI3 should stay at 1.1. I've
made the changes locally.

Cheers,
Daniel
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

[PATCH xorgproto v8 01/14] dri3: Add modifier/multi-plane requests, bump to v1.2

2018-02-27 Thread Daniel Stone
From: Louis-Francis Ratté-Boulianne 

DRI3 version 1.2 adds support for explicit format modifiers,
including multi-planar buffers.

Signed-off-by: Daniel Stone 
Signed-off-by: Louis-Francis Ratté-Boulianne 
---
 dri3proto.pc.in|   2 +-
 dri3proto.txt  | 319 +++--
 include/X11/extensions/dri3proto.h |  86 +-
 meson.build|   2 +-
 4 files changed, 396 insertions(+), 13 deletions(-)

diff --git a/dri3proto.pc.in b/dri3proto.pc.in
index 6d81d07..e42d60e 100644
--- a/dri3proto.pc.in
+++ b/dri3proto.pc.in
@@ -5,5 +5,5 @@ includedir=@includedir@
  
 Name: DRI3Proto
 Description: DRI3 extension headers
-Version: 1.0
+Version: 1.2
 Cflags: -I${includedir}
diff --git a/dri3proto.txt b/dri3proto.txt
index dac11d3..94322e7 100644
--- a/dri3proto.txt
+++ b/dri3proto.txt
@@ -1,16 +1,22 @@
  The DRI3 Extension
-Version 1.0
-  2013-6-4
-  
+Version 1.2
+ 2018-02-28
+
Keith Packard
  kei...@keithp.com
  Intel Corporation
 
+   Daniel Stone
+  dani...@collabora.com
+Collabora
+
+
 1. Introduction
 
 The DRI3 extension provides mechanisms to translate between direct
 rendered buffers and X pixmaps. When combined with the Present extension,
-a complete direct rendering solution for OpenGL is provided.
+a complete direct rendering solution for hardware-accelerated devices
+such as GPUs is provided.
 
 The direct rendered buffers are passed across the protocol via
 standard POSIX file descriptor passing mechanisms. On Linux, these
@@ -25,8 +31,9 @@ which can be used to serialize access to shared render 
buffers.
 Eric Anholt 
 Dave Airlie 
 Kristian Høgsberg 
-James Jones 
+James Jones 
 Arthur Huillet 
+Louis-Francis Ratté-Boulianne 
 
 ❄ ❄ ❄  ❄  ❄ ❄ ❄ 
 
@@ -117,9 +124,10 @@ The name of this extension is "DRI3"
Errors: Alloc, Drawable, IDChoice, Value, Match
 
Creates a pixmap for the direct rendering object associated
-   with 'buffer'. Changes to pixmap will be visible in that
-   direct rendered object and changes to the direct rendered
-   object will be visible in the pixmap.
+   with 'buffer' and the screen associated with 'drawable'.
+   Changes to pixmap will be visible in that direct rendered
+   object and changes to the direct rendered object will be
+   visible in the pixmap.
 
'size' specifies the total size of the buffer bytes. 'width',
'height' describe the geometry (in pixels) of the underlying
@@ -137,6 +145,9 @@ The name of this extension is "DRI3"
If depth or bpp are not supported by the screen, a Value error
is returned.
 
+   For information on synchronization of buffer access between
+   the client and the X server, please see section 12.
+
 ┌───
 DRI3BufferFromPixmap
pixmap: PIXMAP
@@ -167,6 +178,9 @@ The name of this extension is "DRI3"
If buffer cannot be used with the screen associated with
drawable, a Match error is returned.
 
+   For information on synchronization of buffer access between
+   the client and the X server, please see section 12.
+
 ┌───
 DRI3FenceFromFD
drawable: DRAWABLE
@@ -182,6 +196,9 @@ The name of this extension is "DRI3"
Details about the mechanism used with this file descriptor are
outside the scope of the DRI3 extension.
 
+   For information on synchronization of buffer access between
+   the client and the X server, please see section 12.
+
 ┌───
 DRI3FDFromFence
drawable: DRAWABLE
@@ -199,8 +216,163 @@ The name of this extension is "DRI3"
associated with a direct rendering device that 'fence' can
work with, otherwise a Match error results.
 
+   For information on synchronization of buffer access between
+   the client and the X server, please see section 12.
 
-❄ ❄ ❄  ❄  ❄ ❄ ❄ 
+┌───
+DRI3GetSupportedModifiers
+   window: WINDOW
+   depth: CARD8
+   bpp: CARD8
+  ▶
+   num_window_modifiers: CARD32
+   num_screen_modifiers: CARD32
+   window_modifiers: ListOfCARD64
+   screen_modifiers: ListOfCARD64
+└───
+   Errors: Window, Match
+
+   Return supported DRM FourCC modifiers for the specified
+   'window'.
+
+   The first list of 'window_modifiers' contains a set of
+   modifiers which the server considers optimal for the window's
+   current configuration. Using these modifiers to 

[PATCH xserver v8 08/14] modesetting: Get supported formats/modifiers for scanout

2018-02-27 Thread Daniel Stone
From: Louis-Francis Ratté-Boulianne 

Retrieve IN_FORMATS property from the plane. It gives the
allowed formats and modifiers for BO allocation.

Signed-off-by: Louis-Francis Ratté-Boulianne 
Reviewed-by: Daniel Stone 
---
 configure.ac |   4 +
 hw/xfree86/drivers/modesetting/drmmode_display.c | 114 ++-
 hw/xfree86/drivers/modesetting/drmmode_display.h |   9 ++
 include/dix-config.h.in  |   3 +
 include/meson.build  |   2 +
 5 files changed, 128 insertions(+), 4 deletions(-)

diff --git a/configure.ac b/configure.ac
index 46662867f..283d8e20c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2112,6 +2112,10 @@ if test "x$GLAMOR" = xyes; then
PKG_CHECK_EXISTS(libdrm >= 2.4.74,
 [AC_DEFINE(GLAMOR_HAS_DRM_NAME_FROM_FD_2, 1, [Have 
GLAMOR_HAS_DRM_NAME_FROM_FD_2])],
 [])
+
+   PKG_CHECK_EXISTS(libdrm >= 2.4.83,
+[AC_DEFINE(GLAMOR_HAS_DRM_MODIFIERS, 1, [Have 
GLAMOR_HAS_DRM_MODIFIERS])],
+[])
 fi
 AM_CONDITIONAL([GLAMOR_EGL], [test "x$GBM" = xyes])
 
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c 
b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 3e3613a98..7af805da2 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -56,6 +56,23 @@ static Bool drmmode_xf86crtc_resize(ScrnInfoPtr scrn, int 
width, int height);
 static PixmapPtr drmmode_create_pixmap_header(ScreenPtr pScreen, int width, 
int height,
   int depth, int bitsPerPixel, int 
devKind,
   void *pPixData);
+
+#ifdef GLAMOR_HAS_DRM_MODIFIERS
+
+static inline uint32_t *
+formats_ptr(struct drm_format_modifier_blob *blob)
+{
+return (uint32_t *)(((char *)blob) + blob->formats_offset);
+}
+
+static inline struct drm_format_modifier *
+modifiers_ptr(struct drm_format_modifier_blob *blob)
+{
+return (struct drm_format_modifier *)(((char *)blob) + 
blob->modifiers_offset);
+}
+
+#endif
+
 static Bool
 drmmode_zaphod_string_matches(ScrnInfoPtr scrn, const char *s, char 
*output_name)
 {
@@ -1532,15 +1549,76 @@ is_plane_assigned(ScrnInfoPtr scrn, int plane_id)
 return FALSE;
 }
 
+#ifdef GLAMOR_HAS_DRM_MODIFIERS
+/**
+ * Populates the formats array, and the modifiers of each format for a 
drm_plane.
+ */
+static Bool
+populate_format_modifiers(xf86CrtcPtr crtc, const drmModePlane *kplane,
+  uint32_t blob_id)
+{
+drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+drmmode_ptr drmmode = drmmode_crtc->drmmode;
+unsigned i, j;
+drmModePropertyBlobRes *blob;
+struct drm_format_modifier_blob *fmt_mod_blob;
+uint32_t *blob_formats;
+struct drm_format_modifier *blob_modifiers;
+
+blob = drmModeGetPropertyBlob(drmmode->fd, blob_id);
+if (!blob)
+return FALSE;
+
+fmt_mod_blob = blob->data;
+blob_formats = formats_ptr(fmt_mod_blob);
+blob_modifiers = modifiers_ptr(fmt_mod_blob);
+
+assert(drmmode_crtc->num_formats == fmt_mod_blob->count_formats);
+
+for (i = 0; i < fmt_mod_blob->count_formats; i++) {
+uint32_t num_modifiers = 0;
+uint64_t *modifiers = NULL;
+uint64_t *tmp;
+
+for (j = 0; j < fmt_mod_blob->count_modifiers; j++) {
+struct drm_format_modifier *mod = _modifiers[j];
+
+if ((i < mod->offset) || (i > mod->offset + 63))
+continue;
+if (!(mod->formats & (1 << (i - mod->offset
+continue;
+
+num_modifiers++;
+tmp = realloc(modifiers, num_modifiers * sizeof(modifiers[0]));
+if (!tmp) {
+free(modifiers);
+drmModeFreePropertyBlob(blob);
+return FALSE;
+}
+modifiers = tmp;
+modifiers[num_modifiers - 1] = mod->modifier;
+}
+
+drmmode_crtc->formats[i].format = blob_formats[i];
+drmmode_crtc->formats[i].modifiers = modifiers;
+drmmode_crtc->formats[i].num_modifiers = num_modifiers;
+}
+
+drmModeFreePropertyBlob(blob);
+
+return TRUE;
+}
+#endif
+
 static void
 drmmode_crtc_create_planes(xf86CrtcPtr crtc, int num)
 {
 drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
 drmmode_ptr drmmode = drmmode_crtc->drmmode;
 drmModePlaneRes *kplane_res;
-drmModePlane *kplane;
+drmModePlane *kplane, *best_kplane = NULL;
 drmModeObjectProperties *props;
-uint32_t i, type;
+uint32_t i, type, blob_id;
 int current_crtc, best_plane = 0;
 
 static drmmode_prop_enum_info_rec plane_type_enums[] = {
@@ -1562,6 +1640,7 @@ drmmode_crtc_create_planes(xf86CrtcPtr crtc, int num)
 },
 [DRMMODE_PLANE_FB_ID] = { 

[PATCH xserver v8 11/14] glamor: Implement PixmapFromBuffers and BuffersFromPixmap

2018-02-27 Thread Daniel Stone
From: Louis-Francis Ratté-Boulianne 

It relies on GBM >= 17.1.0 where we can import BO with multiple
planes and a format modifier (GBM_BO_IMPORT_FD_MODIFIER).

v2: Properly free fds in Xwayland

Signed-off-by: Louis-Francis Ratté-Boulianne 
Reviewed-by: Daniel Stone 
---
 configure.ac  |   4 +
 glamor/glamor.c   |  37 ---
 glamor/glamor.h   |  65 +++--
 glamor/glamor_egl.c   | 136 ++
 glamor/glamor_egl.h   |   1 +
 glamor/glamor_egl_ext.h   |  65 +
 glamor/glamor_egl_stubs.c |  16 ++-
 hw/xwayland/.gitignore|   2 +
 hw/xwayland/Makefile.am   |  10 +-
 hw/xwayland/meson.build   |   5 +-
 hw/xwayland/xwayland-glamor.c | 219 --
 hw/xwayland/xwayland.c|   6 +-
 hw/xwayland/xwayland.h|  10 +-
 include/dix-config.h.in   |   3 +
 include/meson.build   |   2 +
 15 files changed, 461 insertions(+), 120 deletions(-)
 create mode 100644 glamor/glamor_egl_ext.h

diff --git a/configure.ac b/configure.ac
index 283d8e20c..392511541 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2100,6 +2100,10 @@ if test "x$GLAMOR" = xyes; then
[AC_DEFINE(GLAMOR_HAS_GBM_LINEAR, 1, [Have 
GBM_BO_USE_LINEAR])], [],
[#include 
 #include ])
+   dnl 17.1.0 is required for gbm_bo_create_with_modifiers
+   PKG_CHECK_EXISTS(gbm >= 17.1.0,
+[AC_DEFINE(GBM_BO_WITH_MODIFIERS, 1, [Have 
gbm_bo_create_with_modifiers])],
+[])
else
if test "x$XORG" = xyes; then
AC_MSG_ERROR([Glamor for Xorg requires $LIBGBM])
diff --git a/glamor/glamor.c b/glamor/glamor.c
index d61e27563..c890d0ce0 100644
--- a/glamor/glamor.c
+++ b/glamor/glamor.c
@@ -32,6 +32,7 @@
  */
 
 #include 
+#include 
 
 #include "glamor_priv.h"
 #include "mipict.h"
@@ -793,8 +794,9 @@ glamor_supports_pixmap_import_export(ScreenPtr screen)
 }
 
 _X_EXPORT int
-glamor_fd_from_pixmap(ScreenPtr screen,
-  PixmapPtr pixmap, CARD16 *stride, CARD32 *size)
+glamor_fds_from_pixmap(ScreenPtr screen, PixmapPtr pixmap, int *fds,
+   uint32_t *strides, uint32_t *offsets,
+   uint64_t *modifier)
 {
 glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap);
 glamor_screen_private *glamor_priv =
@@ -808,10 +810,9 @@ glamor_fd_from_pixmap(ScreenPtr screen,
 if (!glamor_pixmap_ensure_fbo(pixmap, pixmap->drawable.depth == 30 ?
   GL_RGB10_A2 : GL_RGBA, 0))
 return -1;
-return glamor_egl_dri3_fd_name_from_tex(screen,
-pixmap,
-pixmap_priv->fbo->tex,
-FALSE, stride, size);
+return glamor_egl_fds_from_pixmap(screen, pixmap, fds,
+  strides, offsets,
+  modifier);
 default:
 break;
 }
@@ -824,6 +825,9 @@ glamor_shareable_fd_from_pixmap(ScreenPtr screen,
 {
 unsigned orig_usage_hint = pixmap->usage_hint;
 int ret;
+int fds[4];
+uint32_t strides[4], offsets[4];
+uint64_t modifier;
 
 /*
  * The actual difference between a sharable and non sharable buffer
@@ -832,7 +836,20 @@ glamor_shareable_fd_from_pixmap(ScreenPtr screen,
  * 2 of those calls are also exported API, so we cannot just add a flag.
  */
 pixmap->usage_hint = CREATE_PIXMAP_USAGE_SHARED;
-ret = glamor_fd_from_pixmap(screen, pixmap, stride, size);
+ret = glamor_fds_from_pixmap(screen, pixmap, fds, strides, offsets,
+ );
+
+/* Pixmaps with multi-planes/modifier are not shareable */
+if (ret > 1) {
+while (ret > 0)
+close(fds[--ret]);
+return -1;
+}
+
+ret = fds[0];
+*stride = strides[0];
+*size = pixmap->drawable.height * *stride;
+
 pixmap->usage_hint = orig_usage_hint;
 
 return ret;
@@ -849,10 +866,8 @@ glamor_name_from_pixmap(PixmapPtr pixmap, CARD16 *stride, 
CARD32 *size)
 if (!glamor_pixmap_ensure_fbo(pixmap, pixmap->drawable.depth == 30 ?
   GL_RGB10_A2 : GL_RGBA, 0))
 return -1;
-return glamor_egl_dri3_fd_name_from_tex(pixmap->drawable.pScreen,
-pixmap,
-pixmap_priv->fbo->tex,
-TRUE, stride, size);
+return glamor_egl_fd_name_from_pixmap(pixmap->drawable.pScreen,
+  pixmap, stride, size);
 default:
 

[PATCH xserver v8 10/14] modesetting: Check if buffer format is supported when flipping

2018-02-27 Thread Daniel Stone
From: Louis-Francis Ratté-Boulianne 

Add support for 'check_flip2' so that the present core can know
why it is impossible to flip in that scenario. The core can then
let know the client that the buffer format/modifier is suboptimal.

v2: No longer need to implement 'check_flip'

Signed-off-by: Louis-Francis Ratté-Boulianne 
Reviewed-by: Daniel Stone 
---
 hw/xfree86/drivers/modesetting/drmmode_display.c | 42 
 hw/xfree86/drivers/modesetting/drmmode_display.h |  2 ++
 hw/xfree86/drivers/modesetting/present.c | 30 ++---
 3 files changed, 70 insertions(+), 4 deletions(-)

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c 
b/hw/xfree86/drivers/modesetting/drmmode_display.c
index bfde3fabf..785849ef9 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -73,6 +73,48 @@ modifiers_ptr(struct drm_format_modifier_blob *blob)
 
 #endif
 
+Bool
+drmmode_is_format_supported(ScrnInfoPtr scrn, uint32_t format, uint64_t 
modifier)
+{
+xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+int c, i, j;
+
+for (c = 0; c < xf86_config->num_crtc; c++) {
+xf86CrtcPtr crtc = xf86_config->crtc[c];
+drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+Bool found = FALSE;
+
+if (!crtc->enabled)
+continue;
+
+for (i = 0; i < drmmode_crtc->num_formats; i++) {
+drmmode_format_ptr iter = _crtc->formats[i];
+
+if (iter->format != format)
+continue;
+
+if (modifier == 0) {
+found = TRUE;
+break;
+}
+
+for (j = 0; j < iter->num_modifiers; j++) {
+if (iter->modifiers[j] == modifier) {
+found = TRUE;
+break;
+}
+}
+
+break;
+}
+
+if (!found)
+return FALSE;
+}
+
+return TRUE;
+}
+
 #ifdef GBM_BO_WITH_MODIFIERS
 static uint32_t
 get_modifiers_set(ScrnInfoPtr scrn, uint32_t format, uint64_t **modifiers,
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h 
b/hw/xfree86/drivers/modesetting/drmmode_display.h
index 75e4b8499..607fe8179 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.h
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.h
@@ -241,6 +241,8 @@ extern DevPrivateKeyRec msPixmapPrivateKeyRec;
 
 #define msGetPixmapPriv(drmmode, p) 
((msPixmapPrivPtr)dixGetPrivateAddr(&(p)->devPrivates, 
&(drmmode)->pixmapPrivateKeyRec))
 
+Bool drmmode_is_format_supported(ScrnInfoPtr scrn, uint32_t format,
+ uint64_t modifier);
 int drmmode_bo_import(drmmode_ptr drmmode, drmmode_bo *bo,
   uint32_t *fb_id);
 int drmmode_bo_destroy(drmmode_ptr drmmode, drmmode_bo *bo);
diff --git a/hw/xfree86/drivers/modesetting/present.c 
b/hw/xfree86/drivers/modesetting/present.c
index 4a01d19ea..71ef2f7f1 100644
--- a/hw/xfree86/drivers/modesetting/present.c
+++ b/hw/xfree86/drivers/modesetting/present.c
@@ -214,7 +214,8 @@ static Bool
 ms_present_check_flip(RRCrtcPtr crtc,
   WindowPtr window,
   PixmapPtr pixmap,
-  Bool sync_flip)
+  Bool sync_flip,
+  PresentFlipReason *reason)
 {
 ScreenPtr screen = window->drawable.pScreen;
 ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
@@ -222,6 +223,9 @@ ms_present_check_flip(RRCrtcPtr crtc,
 xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn);
 int num_crtcs_on = 0;
 int i;
+#ifdef GLAMOR_HAS_DRM_MODIFIERS
+struct gbm_bo *gbm;
+#endif
 
 if (!ms->drmmode.pageflip)
 return FALSE;
@@ -252,6 +256,23 @@ ms_present_check_flip(RRCrtcPtr crtc,
 pixmap->devKind != drmmode_bo_get_pitch(>drmmode.front_bo))
 return FALSE;
 
+#ifdef GLAMOR_HAS_DRM_MODIFIERS
+/* Check if buffer format/modifier is supported by all active CRTCs */
+gbm = glamor_gbm_bo_from_pixmap(screen, pixmap);
+if (gbm) {
+uint32_t format;
+uint64_t modifier;
+
+format = gbm_bo_get_format(gbm);
+modifier = gbm_bo_get_modifier(gbm);
+if (!drmmode_is_format_supported(scrn, format, modifier)) {
+if (reason)
+*reason = PRESENT_FLIP_REASON_BUFFER_FORMAT;
+return FALSE;
+}
+}
+#endif
+
 /* Make sure there's a bo we can get to */
 /* XXX: actually do this.  also...is it sufficient?
  * if (!glamor_get_pixmap_private(pixmap))
@@ -280,7 +301,7 @@ ms_present_flip(RRCrtcPtr crtc,
 Bool ret;
 struct ms_present_vblank_event *event;
 
-if (!ms_present_check_flip(crtc, screen->root, pixmap, sync_flip))
+if (!ms_present_check_flip(crtc, screen->root, pixmap, sync_flip, NULL))
 return FALSE;
 
 event = calloc(1, 

[PATCH xserver v8 09/14] modesetting: Create scanout buffers using supported modifiers

2018-02-27 Thread Daniel Stone
From: Louis-Francis Ratté-Boulianne 

Use most optimal buffer format (e.g. tiled/compressed) available
for scanout.

v2: Don't use multi-plane modifier to create scanout buffer

v3: Add flag to retrieve modifiers set from enabled CRTCs only

v4: Fix uses when GBM/EGL driver doesn't support modifiers

Signed-off-by: Louis-Francis Ratté-Boulianne 
Reviewed-by: Daniel Stone 
---
 hw/xfree86/drivers/modesetting/drmmode_display.c | 90 +++-
 1 file changed, 87 insertions(+), 3 deletions(-)

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c 
b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 7af805da2..6fa22da56 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -73,6 +73,68 @@ modifiers_ptr(struct drm_format_modifier_blob *blob)
 
 #endif
 
+#ifdef GBM_BO_WITH_MODIFIERS
+static uint32_t
+get_modifiers_set(ScrnInfoPtr scrn, uint32_t format, uint64_t **modifiers,
+  Bool enabled_crtc_only, Bool exclude_multiplane)
+{
+xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+modesettingPtr ms = modesettingPTR(scrn);
+drmmode_ptr drmmode = >drmmode;
+int c, i, j, k, count_modifiers = 0;
+uint64_t *tmp, *ret = NULL;
+
+*modifiers = NULL;
+for (c = 0; c < xf86_config->num_crtc; c++) {
+xf86CrtcPtr crtc = xf86_config->crtc[c];
+drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+
+if (enabled_crtc_only && !crtc->enabled)
+continue;
+
+for (i = 0; i < drmmode_crtc->num_formats; i++) {
+drmmode_format_ptr iter = _crtc->formats[i];
+
+if (iter->format != format)
+continue;
+
+for (j = 0; j < iter->num_modifiers; j++) {
+Bool found = FALSE;
+
+   /* Don't choose multi-plane formats for our screen pixmap.
+* These will get used with frontbuffer rendering, which will
+* lead to worse-than-tearing with multi-plane formats, as the
+* primary and auxiliary planes go out of sync. */
+   if (exclude_multiplane &&
+gbm_device_get_format_modifier_plane_count(drmmode->gbm,
+   format,
+   
iter->modifiers[j]) > 1) {
+continue;
+}
+
+for (k = 0; k < count_modifiers; k++) {
+if (iter->modifiers[j] == ret[k])
+found = TRUE;
+}
+if (!found) {
+count_modifiers++;
+tmp = realloc(ret, count_modifiers * sizeof(uint64_t));
+if (!tmp) {
+free(ret);
+return 0;
+}
+ret = tmp;
+ret[count_modifiers - 1] = iter->modifiers[j];
+}
+}
+}
+}
+
+*modifiers = ret;
+return count_modifiers;
+}
+#endif
+
 static Bool
 drmmode_zaphod_string_matches(ScrnInfoPtr scrn, const char *s, char 
*output_name)
 {
@@ -593,14 +655,36 @@ static Bool
 drmmode_create_bo(drmmode_ptr drmmode, drmmode_bo *bo,
   unsigned width, unsigned height, unsigned bpp)
 {
+uint32_t format;
+
+if (drmmode->scrn->depth == 30)
+format = GBM_FORMAT_ARGB2101010;
+else
+format = GBM_FORMAT_ARGB;
+
 bo->width = width;
 bo->height = height;
 
 #ifdef GLAMOR_HAS_GBM
 if (drmmode->glamor) {
-bo->gbm = gbm_bo_create(drmmode->gbm, width, height,
-drmmode->scrn->depth == 30 ?
-GBM_FORMAT_ARGB2101010 : GBM_FORMAT_ARGB,
+#ifdef GBM_BO_WITH_MODIFIERS
+uint32_t num_modifiers;
+uint64_t *modifiers = NULL;
+
+num_modifiers = get_modifiers_set(drmmode->scrn, format, ,
+  FALSE, TRUE);
+if (num_modifiers > 0 &&
+!(num_modifiers == 1 && modifiers[0] == DRM_FORMAT_MOD_INVALID)) {
+bo->gbm = gbm_bo_create_with_modifiers(drmmode->gbm, width, height,
+   format, modifiers,
+   num_modifiers);
+free(modifiers);
+if (bo->gbm)
+return TRUE;
+}
+#endif
+
+bo->gbm = gbm_bo_create(drmmode->gbm, width, height, format,
 GBM_BO_USE_RENDERING | GBM_BO_USE_SCANOUT);
 return bo->gbm != NULL;
 }
-- 
2.14.3

___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

[PATCH xserver v8 14/14] dri3: Enable DRI3 version 1.2

2018-02-27 Thread Daniel Stone
From: Louis-Francis Ratté-Boulianne 

Enable DRI3 v1.2 now that all functions have been implemented and
that there is at least one backend implementing the driver hooks
(modesetting/glamor).

Signed-off-by: Louis-Francis Ratté-Boulianne 
Reviewed-by: Daniel Stone 
---
 include/protocol-versions.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/protocol-versions.h b/include/protocol-versions.h
index 39cd2e909..7cab7cd5b 100644
--- a/include/protocol-versions.h
+++ b/include/protocol-versions.h
@@ -48,7 +48,7 @@
 
 /* DRI3 */
 #define SERVER_DRI3_MAJOR_VERSION   1
-#define SERVER_DRI3_MINOR_VERSION   0
+#define SERVER_DRI3_MINOR_VERSION   2
 
 /* DMX */
 #define SERVER_DMX_MAJOR_VERSION   2
-- 
2.14.3

___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

[PATCH xserver v8 06/14] modesetting: Add support for multi-plane pixmaps when page-flipping

2018-02-27 Thread Daniel Stone
From: Louis-Francis Ratté-Boulianne 

This allows the uses of CCS compressed or tiled pixmaps as BOs when
page-flipping.

Signed-off-by: Louis-Francis Ratté-Boulianne 
Reviewed-by: Daniel Stone 
---
 hw/xfree86/drivers/modesetting/drmmode_display.c | 49 
 hw/xfree86/drivers/modesetting/drmmode_display.h |  4 ++
 hw/xfree86/drivers/modesetting/pageflip.c| 16 
 3 files changed, 62 insertions(+), 7 deletions(-)

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c 
b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 8674c2c16..ee9f4d724 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -39,6 +39,8 @@
 #include "micmap.h"
 #include "xf86cmap.h"
 #include "xf86DDC.h"
+#include 
+#include 
 
 #include 
 #include "xf86Crtc.h"
@@ -376,10 +378,57 @@ drmmode_bo_map(drmmode_ptr drmmode, drmmode_bo *bo)
 return bo->dumb->ptr;
 }
 
+int
+drmmode_bo_import(drmmode_ptr drmmode, drmmode_bo *bo,
+  uint32_t *fb_id)
+{
+#ifdef GBM_BO_WITH_MODIFIERS
+if (bo->gbm &&
+gbm_bo_get_modifier(bo->gbm) != DRM_FORMAT_MOD_INVALID) {
+int num_fds;
+
+num_fds = gbm_bo_get_plane_count(bo->gbm);
+if (num_fds > 0) {
+int i;
+uint32_t format;
+uint32_t handles[4];
+uint32_t strides[4];
+uint32_t offsets[4];
+uint64_t modifiers[4];
+
+memset(handles, 0, sizeof(handles));
+memset(strides, 0, sizeof(strides));
+memset(offsets, 0, sizeof(offsets));
+memset(modifiers, 0, sizeof(modifiers));
+
+format = gbm_bo_get_format(bo->gbm);
+for (i = 0; i < num_fds; i++) {
+handles[i] = gbm_bo_get_handle_for_plane(bo->gbm, i).u32;
+strides[i] = gbm_bo_get_stride_for_plane(bo->gbm, i);
+offsets[i] = gbm_bo_get_offset(bo->gbm, i);
+modifiers[i] = gbm_bo_get_modifier(bo->gbm);
+}
+
+return drmModeAddFB2WithModifiers(drmmode->fd, bo->width, 
bo->height,
+  format, handles, strides,
+  offsets, modifiers, fb_id,
+  DRM_MODE_FB_MODIFIERS);
+}
+}
+#endif
+return drmModeAddFB(drmmode->fd, bo->width, bo->height,
+drmmode->scrn->depth, drmmode->scrn->bitsPerPixel,
+drmmode_bo_get_pitch(bo),
+drmmode_bo_get_handle(bo), fb_id);
+}
+
 static Bool
 drmmode_create_bo(drmmode_ptr drmmode, drmmode_bo *bo,
   unsigned width, unsigned height, unsigned bpp)
 {
+bo->width = width;
+bo->height = height;
+
 #ifdef GLAMOR_HAS_GBM
 if (drmmode->glamor) {
 bo->gbm = gbm_bo_create(drmmode->gbm, width, height,
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h 
b/hw/xfree86/drivers/modesetting/drmmode_display.h
index 1f24c3a5b..177ccabd7 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.h
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.h
@@ -53,6 +53,8 @@ enum drmmode_plane_type {
 };
 
 typedef struct {
+uint32_t width;
+uint32_t height;
 struct dumb_bo *dumb;
 #ifdef GLAMOR_HAS_GBM
 struct gbm_bo *gbm;
@@ -202,6 +204,8 @@ extern DevPrivateKeyRec msPixmapPrivateKeyRec;
 
 #define msGetPixmapPriv(drmmode, p) 
((msPixmapPrivPtr)dixGetPrivateAddr(&(p)->devPrivates, 
&(drmmode)->pixmapPrivateKeyRec))
 
+int drmmode_bo_import(drmmode_ptr drmmode, drmmode_bo *bo,
+  uint32_t *fb_id);
 int drmmode_bo_destroy(drmmode_ptr drmmode, drmmode_bo *bo);
 uint32_t drmmode_bo_get_pitch(drmmode_bo *bo);
 uint32_t drmmode_bo_get_handle(drmmode_bo *bo);
diff --git a/hw/xfree86/drivers/modesetting/pageflip.c 
b/hw/xfree86/drivers/modesetting/pageflip.c
index dd296cd12..027ebfe42 100644
--- a/hw/xfree86/drivers/modesetting/pageflip.c
+++ b/hw/xfree86/drivers/modesetting/pageflip.c
@@ -258,6 +258,7 @@ ms_do_pageflip(ScreenPtr screen,
 
 new_front_bo.gbm = glamor_gbm_bo_from_pixmap(screen, new_front);
 new_front_bo.dumb = NULL;
+
 if (!new_front_bo.gbm) {
 xf86DrvMsg(scrn->scrnIndex, X_ERROR,
"Failed to get GBM bo for flip to new front.\n");
@@ -288,14 +289,12 @@ ms_do_pageflip(ScreenPtr screen,
 
 /* Create a new handle for the back buffer */
 flipdata->old_fb_id = ms->drmmode.fb_id;
-if (drmModeAddFB(ms->fd, scrn->virtualX, scrn->virtualY,
- scrn->depth, scrn->bitsPerPixel,
- drmmode_bo_get_pitch(_front_bo),
- drmmode_bo_get_handle(_front_bo), 
>drmmode.fb_id)) {
-goto error_out;
-}
 
-drmmode_bo_destroy(>drmmode, _front_bo);
+new_front_bo.width = new_front->drawable.width;
+

[PATCH xserver v8 12/14] glamor: Implement GetSupportedModifiers

2018-02-27 Thread Daniel Stone
From: Louis-Francis Ratté-Boulianne 

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 
Reviewed-by: Daniel Stone 
---
 configure.ac |   4 +
 glamor/glamor.c  |  25 +
 glamor/glamor.h  |  23 
 glamor/glamor_egl.c  |  92 +++
 glamor/glamor_priv.h |   1 +
 glamor/meson.build   |   4 +-
 hw/kdrive/ephyr/meson.build  |   1 +
 hw/xfree86/common/xf86Mode.c |   1 +
 hw/xfree86/drivers/modesetting/driver.c  |  12 +-
 hw/xfree86/drivers/modesetting/drmmode_display.c |  38 +++
 hw/xfree86/drivers/modesetting/drmmode_display.h |   1 +
 hw/xwayland/xwayland-glamor.c| 135 ---
 hw/xwayland/xwayland.h   |   9 +-
 include/dix-config.h.in  |   3 +
 include/meson.build  |   2 +
 meson.build  |   4 +-
 present/present.c|  38 +++
 present/present.h|   3 +
 18 files changed, 372 insertions(+), 24 deletions(-)

diff --git a/configure.ac b/configure.ac
index 392511541..8e247cdcf 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2092,6 +2092,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,
diff --git a/glamor/glamor.c b/glamor/glamor.c
index c890d0ce0..c7077dd84 100644
--- a/glamor/glamor.c
+++ b/glamor/glamor.c
@@ -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,
diff --git a/glamor/glamor.h b/glamor/glamor.h
index 8f8c31b45..5475aedbb 100644
--- a/glamor/glamor.h
+++ b/glamor/glamor.h
@@ -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 

[PATCH xserver v8 04/14] present: Send PresentCompleteModeSuboptimalCopy appropriately

2018-02-27 Thread Daniel Stone
From: Louis-Francis Ratté-Boulianne 

Add 'check_flip2' hook for driver to let know the core
about why flipping is not possible ('reason').
If it is because of unsupported buffer format/modifier,
a PresentCompleteNotify event is sent to the client with
the PresentCompleteModeSuboptimalCopy mode.

v2: Check for PresentOptionSuboptimal and check driver version
before using 'check_flip2'.

v3: Only require one of 'check_flip' or 'check_flip2' to be
implemented by the driver.
Refactor reasons list to enum

Signed-off-by: Louis-Francis Ratté-Boulianne 
Reviewed-by: Daniel Stone 
---
 configure.ac|  2 +-
 include/protocol-versions.h |  2 +-
 present/meson.build |  2 +-
 present/present.c   | 50 ++---
 present/present.h   | 12 ++-
 present/present_priv.h  |  2 ++
 6 files changed, 50 insertions(+), 20 deletions(-)

diff --git a/configure.ac b/configure.ac
index 47469d864..cef9503d7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -753,7 +753,7 @@ DAMAGEPROTO="damageproto >= 1.1"
 XCMISCPROTO="xcmiscproto >= 1.2.0"
 BIGREQSPROTO="bigreqsproto >= 1.1.0"
 XTRANS="xtrans >= 1.3.5"
-PRESENTPROTO="presentproto >= 1.0"
+PRESENTPROTO="presentproto >= 1.1"
 
 dnl List of libraries that require a specific version
 LIBAPPLEWM="applewm >= 1.4"
diff --git a/include/protocol-versions.h b/include/protocol-versions.h
index 938b9caa4..39cd2e909 100644
--- a/include/protocol-versions.h
+++ b/include/protocol-versions.h
@@ -69,7 +69,7 @@
 
 /* Present */
 #define SERVER_PRESENT_MAJOR_VERSION1
-#define SERVER_PRESENT_MINOR_VERSION0
+#define SERVER_PRESENT_MINOR_VERSION1
 
 /* RandR */
 #define SERVER_RANDR_MAJOR_VERSION 1
diff --git a/present/meson.build b/present/meson.build
index a4296ca7a..cf725302a 100644
--- a/present/meson.build
+++ b/present/meson.build
@@ -13,7 +13,7 @@ libxserver_present = static_library('libxserver_present',
 include_directories: inc,
 dependencies: [
 common_dep,
-dependency('presentproto', version: '>= 1.0')
+dependency('presentproto', version: '>= 1.1')
 ],
 c_args: '-DHAVE_XORG_CONFIG_H'
 )
diff --git a/present/present.c b/present/present.c
index 176e89c0b..42e5fb4fc 100644
--- a/present/present.c
+++ b/present/present.c
@@ -118,19 +118,23 @@ present_flip_pending_pixmap(ScreenPtr screen)
 }
 
 static Bool
-present_check_flip(RRCrtcPtrcrtc,
-   WindowPtrwindow,
-   PixmapPtrpixmap,
-   Bool sync_flip,
-   RegionPtrvalid,
-   int16_t  x_off,
-   int16_t  y_off)
+present_check_flip(RRCrtcPtrcrtc,
+   WindowPtrwindow,
+   PixmapPtrpixmap,
+   Bool sync_flip,
+   RegionPtrvalid,
+   int16_t  x_off,
+   int16_t  y_off,
+   PresentFlipReason   *reason)
 {
 ScreenPtr   screen = window->drawable.pScreen;
 PixmapPtr   window_pixmap;
 WindowPtr   root = screen->root;
 present_screen_priv_ptr screen_priv = present_screen_priv(screen);
 
+if (reason)
+*reason = PRESENT_FLIP_REASON_UNKNOWN;
+
 if (!screen_priv)
 return FALSE;
 
@@ -177,7 +181,12 @@ present_check_flip(RRCrtcPtrcrtc,
 }
 
 /* Ask the driver for permission */
-if (screen_priv->info->check_flip) {
+if (screen_priv->info->version >= 1 && screen_priv->info->check_flip2) {
+if (!(*screen_priv->info->check_flip2) (crtc, window, pixmap, 
sync_flip, reason)) {
+DebugPresent(("\td %08lx -> %08lx\n", window->drawable.id, pixmap 
? pixmap->drawable.id : 0));
+return FALSE;
+}
+} else if (screen_priv->info->check_flip) {
 if (!(*screen_priv->info->check_flip) (crtc, window, pixmap, 
sync_flip)) {
 DebugPresent(("\td %08lx -> %08lx\n", window->drawable.id, pixmap 
? pixmap->drawable.id : 0));
 return FALSE;
@@ -564,6 +573,7 @@ present_check_flip_window (WindowPtr window)
 present_window_priv_ptr window_priv = present_window_priv(window);
 present_vblank_ptr  flip_pending = screen_priv->flip_pending;
 present_vblank_ptr  vblank;
+PresentFlipReason   reason;
 
 /* If this window hasn't ever been used with Present, it can't be
  * flipping
@@ -580,7 +590,7 @@ present_check_flip_window (WindowPtr window)
  */
 if (flip_pending->window == window) {
 if (!present_check_flip(flip_pending->crtc, window, 
flip_pending->pixmap,
-flip_pending->sync_flip, NULL, 0, 0))
+

[PATCH xserver v8 07/14] modesetting: Use atomic modesetting to configure output/CRTCs

2018-02-27 Thread Daniel Stone
From: Louis-Francis Ratté-Boulianne 

To make sure we also use the same primary plane and to avoid
mixing uses of two APIs, it is better to always use the atomic
modesetting API when possible.

v2: Don't use mode_output->connector_id

Signed-off-by: Louis-Francis Ratté-Boulianne 
Reviewed-by: Daniel Stone 
---
 hw/xfree86/drivers/modesetting/drmmode_display.c | 262 +++
 hw/xfree86/drivers/modesetting/drmmode_display.h |  30 ++-
 hw/xfree86/drivers/modesetting/pageflip.c|   2 +-
 hw/xfree86/drivers/modesetting/present.c |   3 +-
 4 files changed, 252 insertions(+), 45 deletions(-)

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c 
b/hw/xfree86/drivers/modesetting/drmmode_display.c
index ee9f4d724..3e3613a98 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -267,16 +267,100 @@ plane_add_prop(drmModeAtomicReq *req, 
drmmode_crtc_private_ptr drmmode_crtc,
info->prop_id, val);
 return (ret <= 0) ? -1 : 0;
 }
+
+static int
+crtc_add_prop(drmModeAtomicReq *req, drmmode_crtc_private_ptr drmmode_crtc,
+  enum drmmode_crtc_property prop, uint64_t val)
+{
+drmmode_prop_info_ptr info = _crtc->props[prop];
+int ret;
+
+if (!info)
+return -1;
+
+ret = drmModeAtomicAddProperty(req, drmmode_crtc->mode_crtc->crtc_id,
+   info->prop_id, val);
+return (ret <= 0) ? -1 : 0;
+}
+
+static int
+connector_add_prop(drmModeAtomicReq *req, drmmode_output_private_ptr 
drmmode_output,
+   enum drmmode_connector_property prop, uint64_t val)
+{
+drmmode_prop_info_ptr info = _output->props_connector[prop];
+int ret;
+
+if (!info)
+return -1;
+
+ret = drmModeAtomicAddProperty(req, drmmode_output->output_id,
+   info->prop_id, val);
+return (ret <= 0) ? -1 : 0;
+}
+
+static int
+drmmode_CompareKModes(drmModeModeInfo * kmode, drmModeModeInfo * other)
+{
+return memcmp(kmode, other, sizeof(*kmode));
+}
+
+static int
+drm_mode_ensure_blob(xf86CrtcPtr crtc, drmModeModeInfo mode_info)
+{
+modesettingPtr ms = modesettingPTR(crtc->scrn);
+drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+drmmode_mode_ptr mode;
+int ret;
+
+if (drmmode_crtc->current_mode &&
+drmmode_CompareKModes(_crtc->current_mode->mode_info, 
_info) == 0)
+return 0;
+
+mode = calloc(sizeof(drmmode_mode_rec), 1);
+if (!mode)
+return -1;
+
+mode->mode_info = mode_info;
+ret = drmModeCreatePropertyBlob(ms->fd,
+>mode_info,
+sizeof(mode->mode_info),
+>blob_id);
+drmmode_crtc->current_mode = mode;
+xorg_list_add(>entry, _crtc->mode_list);
+
+return ret;
+}
+
+static void
+drm_mode_destroy(xf86CrtcPtr crtc, drmmode_mode_ptr mode)
+{
+modesettingPtr ms = modesettingPTR(crtc->scrn);
+if (mode->blob_id)
+drmModeDestroyPropertyBlob(ms->fd, mode->blob_id);
+xorg_list_del(>entry);
+free(mode);
+}
 #endif
 
+static void
+drmmode_ConvertToKMode(ScrnInfoPtr scrn,
+   drmModeModeInfo * kmode, DisplayModePtr mode);
+
 int
-drmmode_crtc_set_fb(xf86CrtcPtr crtc, uint32_t fb_id,
+drmmode_crtc_set_fb(xf86CrtcPtr crtc, DisplayModePtr mode, uint32_t fb_id,
 int x, int y, uint32_t flags, void *data)
 {
 modesettingPtr ms = modesettingPTR(crtc->scrn);
 xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
 drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
-int ret = 0;
+drmmode_ptr drmmode = drmmode_crtc->drmmode;
+int output_count = 0;
+uint32_t *output_ids = NULL;
+drmModeModeInfo kmode;
+int i, ret = 0;
+
+if (mode)
+drmmode_ConvertToKMode(crtc->scrn, , mode);
 
 #ifdef GLAMOR_HAS_DRM_ATOMIC
 if (ms->atomic_modeset) {
@@ -285,12 +369,56 @@ drmmode_crtc_set_fb(xf86CrtcPtr crtc, uint32_t fb_id,
 if (!req)
 return 1;
 
+if (mode) {
+ret = drm_mode_ensure_blob(crtc, kmode);
+
+for (i = 0; i < xf86_config->num_output; i++) {
+xf86OutputPtr output = xf86_config->output[i];
+drmmode_output_private_ptr drmmode_output;
+
+if (output->crtc != crtc)
+continue;
+
+drmmode_output = output->driver_private;
+if (drmmode_output->output_id == -1)
+continue;
+
+if (drmmode_output->dpms == DPMSModeOn) {
+ret |= crtc_add_prop(req, drmmode_crtc,
+ DRMMODE_CRTC_ACTIVE, 1);
+ret |= crtc_add_prop(req, drmmode_crtc,
+ 

[PATCH xserver v8 13/14] glamor: Use gbm_bo_create_with_modifiers for internal pixmap allocation

2018-02-27 Thread Daniel Stone
From: Louis-Francis Ratté-Boulianne 

Using modifier might allow the driver to use a more optimal format
(e.g. tiled/compressed). Let's try to use those if possible.

v2: Don't filter out multi-plane modifiers

Signed-off-by: Louis-Francis Ratté-Boulianne 
Reviewed-by: Daniel Stone 
---
 glamor/glamor_egl.c   | 32 ++--
 hw/xwayland/xwayland-glamor.c | 22 +++---
 2 files changed, 45 insertions(+), 9 deletions(-)

diff --git a/glamor/glamor_egl.c b/glamor/glamor_egl.c
index c00fb3c1b..ca368c15c 100644
--- a/glamor/glamor_egl.c
+++ b/glamor/glamor_egl.c
@@ -256,6 +256,7 @@ glamor_make_pixmap_exportable(PixmapPtr pixmap)
 glamor_get_pixmap_private(pixmap);
 unsigned width = pixmap->drawable.width;
 unsigned height = pixmap->drawable.height;
+uint32_t format;
 struct gbm_bo *bo;
 PixmapPtr exported;
 GCPtr scratch_gc;
@@ -270,14 +271,33 @@ glamor_make_pixmap_exportable(PixmapPtr pixmap)
 return FALSE;
 }
 
-bo = gbm_bo_create(glamor_egl->gbm, width, height,
-   (pixmap->drawable.depth == 30) ?
-   GBM_FORMAT_ARGB2101010 : GBM_FORMAT_ARGB,
+if (pixmap->drawable.depth == 30)
+   format = GBM_FORMAT_ARGB2101010;
+else
+format = GBM_FORMAT_ARGB;
+
+#ifdef GBM_BO_WITH_MODIFIERS
+if (glamor_egl->dmabuf_capable) {
+uint32_t num_modifiers;
+uint64_t *modifiers = NULL;
+
+glamor_get_modifiers(screen, format, _modifiers, );
+
+bo = gbm_bo_create_with_modifiers(glamor_egl->gbm, width, height,
+  format, modifiers, num_modifiers);
+free(modifiers);
+}
+else
+#endif
+{
+bo = gbm_bo_create(glamor_egl->gbm, width, height, format,
 #ifdef GLAMOR_HAS_GBM_LINEAR
-   (pixmap->usage_hint == CREATE_PIXMAP_USAGE_SHARED ?
-GBM_BO_USE_LINEAR : 0) |
+(pixmap->usage_hint == CREATE_PIXMAP_USAGE_SHARED ?
+ GBM_BO_USE_LINEAR : 0) |
 #endif
-   GBM_BO_USE_RENDERING | GBM_BO_USE_SCANOUT);
+GBM_BO_USE_RENDERING | GBM_BO_USE_SCANOUT);
+}
+
 if (!bo) {
 xf86DrvMsg(scrn->scrnIndex, X_ERROR,
"Failed to make %dx%dx%dbpp GBM bo\n",
diff --git a/hw/xwayland/xwayland-glamor.c b/hw/xwayland/xwayland-glamor.c
index 72e2625fb..b961695d7 100644
--- a/hw/xwayland/xwayland-glamor.c
+++ b/hw/xwayland/xwayland-glamor.c
@@ -227,14 +227,30 @@ xwl_glamor_create_pixmap(ScreenPtr screen,
 {
 struct xwl_screen *xwl_screen = xwl_screen_get(screen);
 struct gbm_bo *bo;
+uint32_t format;
 
 if (width > 0 && height > 0 && depth >= 15 &&
 (hint == 0 ||
  hint == CREATE_PIXMAP_USAGE_BACKING_PIXMAP ||
  hint == CREATE_PIXMAP_USAGE_SHARED)) {
-bo = gbm_bo_create(xwl_screen->gbm, width, height,
-   gbm_format_for_depth(depth),
-   GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING);
+format = gbm_format_for_depth(depth);
+
+#ifdef GBM_BO_WITH_MODIFIERS
+if (xwl_screen->dmabuf_capable) {
+uint32_t num_modifiers;
+uint64_t *modifiers = NULL;
+
+glamor_get_modifiers(screen, format, _modifiers, );
+bo = gbm_bo_create_with_modifiers(xwl_screen->gbm, width, height,
+  format, modifiers, 
num_modifiers);
+free(modifiers);
+}
+else
+#endif
+{
+bo = gbm_bo_create(xwl_screen->gbm, width, height, format,
+   GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING);
+}
 
 if (bo)
 return xwl_glamor_create_pixmap_for_bo(screen, bo, depth);
-- 
2.14.3

___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

[PATCH xserver v8 05/14] modesetting: Use atomic modesetting API for pageflip if available

2018-02-27 Thread Daniel Stone
From: Louis-Francis Ratté-Boulianne 

In order to flip between compressed and uncompressed buffers -
something drmModePageFlip explicitly bans us from doing - we need
to port use the atomic modesetting API. It's only 'fake' atomic
though given we still commit for each CRTC separately and
CRTC and connector properties are not set with the atomic API.

The helper functions to retrieve DRM properties have been borrowed
from Weston.

Signed-off-by: Louis-Francis Ratté-Boulianne 
Reviewed-by: Daniel Stone 
---
 configure.ac |   3 +
 hw/xfree86/drivers/modesetting/driver.c  |   6 +
 hw/xfree86/drivers/modesetting/driver.h  |   1 +
 hw/xfree86/drivers/modesetting/drmmode_display.c | 374 ++-
 hw/xfree86/drivers/modesetting/drmmode_display.h |  36 +++
 hw/xfree86/drivers/modesetting/pageflip.c|  22 +-
 include/dix-config.h.in  |   3 +
 include/meson.build  |   2 +
 8 files changed, 443 insertions(+), 4 deletions(-)

diff --git a/configure.ac b/configure.ac
index cef9503d7..46662867f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2106,6 +2106,9 @@ if test "x$GLAMOR" = xyes; then
fi
fi
 
+   PKG_CHECK_EXISTS(libdrm >= 2.4.62,
+[AC_DEFINE(GLAMOR_HAS_DRM_ATOMIC, 1, [libdrm supports 
atomic API])],
+[])
PKG_CHECK_EXISTS(libdrm >= 2.4.74,
 [AC_DEFINE(GLAMOR_HAS_DRM_NAME_FROM_FD_2, 1, [Have 
GLAMOR_HAS_DRM_NAME_FROM_FD_2])],
 [])
diff --git a/hw/xfree86/drivers/modesetting/driver.c 
b/hw/xfree86/drivers/modesetting/driver.c
index ec2aa9a27..88a42257c 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -1018,6 +1018,12 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 }
 #endif
 
+#ifdef GLAMOR_HAS_DRM_ATOMIC
+ret = drmSetClientCap(ms->fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1);
+ret |= drmSetClientCap(ms->fd, DRM_CLIENT_CAP_ATOMIC, 1);
+ms->atomic_modeset = (ret == 0);
+#endif
+
 if (drmmode_pre_init(pScrn, >drmmode, pScrn->bitsPerPixel / 8) == 
FALSE) {
 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "KMS setup failed\n");
 goto fail;
diff --git a/hw/xfree86/drivers/modesetting/driver.h 
b/hw/xfree86/drivers/modesetting/driver.h
index fe835918b..ed32239db 100644
--- a/hw/xfree86/drivers/modesetting/driver.h
+++ b/hw/xfree86/drivers/modesetting/driver.h
@@ -105,6 +105,7 @@ typedef struct _modesettingRec {
  * Page flipping stuff.
  *  @{
  */
+Bool atomic_modeset;
 /** @} */
 
 DamagePtr damage;
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c 
b/hw/xfree86/drivers/modesetting/drmmode_display.c
index bfc8c50db..8674c2c16 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -75,6 +75,233 @@ drmmode_zaphod_string_matches(ScrnInfoPtr scrn, const char 
*s, char *output_name
 return ret;
 }
 
+static uint64_t
+drmmode_prop_get_value(drmmode_prop_info_ptr info,
+   drmModeObjectPropertiesPtr props,
+   uint64_t def)
+{
+unsigned int i;
+
+if (info->prop_id == 0)
+return def;
+
+for (i = 0; i < props->count_props; i++) {
+unsigned int j;
+
+if (props->props[i] != info->prop_id)
+continue;
+
+/* Simple (non-enum) types can return the value directly */
+if (info->num_enum_values == 0)
+return props->prop_values[i];
+
+/* Map from raw value to enum value */
+for (j = 0; j < info->num_enum_values; j++) {
+if (!info->enum_values[j].valid)
+continue;
+if (info->enum_values[j].value != props->prop_values[i])
+continue;
+
+return j;
+}
+}
+
+return def;
+}
+
+static uint32_t
+drmmode_prop_info_update(drmmode_ptr drmmode,
+ drmmode_prop_info_ptr info,
+ unsigned int num_infos,
+ drmModeObjectProperties *props)
+{
+drmModePropertyRes *prop;
+uint32_t valid_mask = 0;
+unsigned i, j;
+
+assert(num_infos <= 32 && "update return type");
+
+for (i = 0; i < props->count_props; i++) {
+Bool props_incomplete = FALSE;
+unsigned int k;
+
+for (j = 0; j < num_infos; j++) {
+if (info[j].prop_id == props->props[i])
+break;
+if (!info[j].prop_id)
+props_incomplete = TRUE;
+}
+
+/* We've already discovered this property. */
+if (j != num_infos)
+continue;
+
+/* We haven't found this property ID, but as we've already
+ * found all known properties, we don't need to look any
+ * further. */
+if (!props_incomplete)

[PATCH xserver v8 03/14] dri3: Add multi-planar/modifier buffer requests

2018-02-27 Thread Daniel Stone
From: Louis-Francis Ratté-Boulianne 

Initial implementation for DRI3 v1.1. Only the DRI3 implementation
is there, backends need to implement the proper hooks.

Version is still set to 1.0 so clients shouldn't use the new
requests yet.

v2: Use depth/bpp instead of DRM formats in requests

v3: Remove DMA fence requests from v1.1
Add screen/drawable modifier sets

v4: Free array returned by 'get_drawable_modifiers()'

v5: Fix FD leak

Signed-off-by: Daniel Stone 
Signed-off-by: Louis-Francis Ratté-Boulianne 
---
 configure.ac  |   2 +-
 dri3/dri3.c   |  19 +++
 dri3/dri3.h   |  44 ++-
 dri3/dri3_priv.h  |  27 +++-
 dri3/dri3_request.c   | 294 --
 dri3/dri3_screen.c| 196 ++--
 hw/xwayland/xwayland-glamor.c |   4 +-
 meson.build   |   2 +-
 8 files changed, 559 insertions(+), 29 deletions(-)

diff --git a/configure.ac b/configure.ac
index 4d7c24fa9..47469d864 100644
--- a/configure.ac
+++ b/configure.ac
@@ -729,7 +729,7 @@ SCRNSAVERPROTO="scrnsaverproto >= 1.1"
 RESOURCEPROTO="resourceproto >= 1.2.0"
 DRIPROTO="xf86driproto >= 2.1.0"
 DRI2PROTO="dri2proto >= 2.8"
-DRI3PROTO="dri3proto >= 1.0"
+DRI3PROTO="dri3proto >= 1.2"
 XINERAMAPROTO="xineramaproto"
 BIGFONTPROTO="xf86bigfontproto >= 1.2.0"
 DGAPROTO="xf86dgaproto >= 2.0.99.1"
diff --git a/dri3/dri3.c b/dri3/dri3.c
index d042b8b7d..8ac0f3ae2 100644
--- a/dri3/dri3.c
+++ b/dri3/dri3.c
@@ -26,6 +26,8 @@
 
 #include "dri3_priv.h"
 
+#include 
+
 static int dri3_request;
 DevPrivateKeyRec dri3_screen_private_key;
 
@@ -99,3 +101,20 @@ dri3_extension_init(void)
 bail:
 FatalError("Cannot initialize DRI3 extension");
 }
+
+uint32_t
+drm_format_for_depth(uint32_t depth, uint32_t bpp)
+{
+switch (bpp) {
+case 16:
+return DRM_FORMAT_RGB565;
+case 24:
+return DRM_FORMAT_XRGB;
+case 30:
+return DRM_FORMAT_XRGB2101010;
+case 32:
+return DRM_FORMAT_ARGB;
+default:
+return 0;
+}
+}
diff --git a/dri3/dri3.h b/dri3/dri3.h
index 7562352ff..89ad13ad9 100644
--- a/dri3/dri3.h
+++ b/dri3/dri3.h
@@ -28,7 +28,7 @@
 #include 
 #include 
 
-#define DRI3_SCREEN_INFO_VERSION1
+#define DRI3_SCREEN_INFO_VERSION2
 
 typedef int (*dri3_open_proc)(ScreenPtr screen,
   RRProviderPtr provider,
@@ -47,11 +47,43 @@ typedef PixmapPtr (*dri3_pixmap_from_fd_proc) (ScreenPtr 
screen,
CARD8 depth,
CARD8 bpp);
 
+typedef PixmapPtr (*dri3_pixmap_from_fds_proc) (ScreenPtr screen,
+CARD8 num_fds,
+int *fds,
+CARD16 width,
+CARD16 height,
+CARD32 *strides,
+CARD32 *offsets,
+CARD8 depth,
+CARD8 bpp,
+CARD64 modifier);
+
 typedef int (*dri3_fd_from_pixmap_proc) (ScreenPtr screen,
  PixmapPtr pixmap,
  CARD16 *stride,
  CARD32 *size);
 
+typedef int (*dri3_fds_from_pixmap_proc) (ScreenPtr screen,
+  PixmapPtr pixmap,
+  int *fds,
+  CARD32 *strides,
+  CARD32 *offsets,
+  CARD64 *modifier);
+
+typedef int (*dri3_get_formats_proc) (ScreenPtr screen,
+  CARD32 *num_formats,
+  CARD32 **formats);
+
+typedef int (*dri3_get_modifiers_proc) (ScreenPtr screen,
+CARD32 format,
+CARD32 *num_modifiers,
+CARD64 **modifiers);
+
+typedef int (*dri3_get_drawable_modifiers_proc) (DrawablePtr draw,
+ CARD32 format,
+ CARD32 *num_modifiers,
+ CARD64 **modifiers);
+
 typedef struct dri3_screen_info {
 uint32_tversion;
 
@@ -62,6 +94,13 @@ typedef struct dri3_screen_info {
 /* Version 1 */
 dri3_open_client_proc   open_client;
 
+/* Version 2 */
+dri3_pixmap_from_fds_proc   pixmap_from_fds;
+dri3_fds_from_pixmap_proc   

[PATCH xorgproto v8 02/14] presentproto: PresentCompleteModeSuboptimalCopy flag

2018-02-27 Thread Daniel Stone
From: Louis-Francis Ratté-Boulianne 

If the Complete event has this mode, the client is not using
the more optimal format/modifier for the buffer allocation. The
client must explicitely inform the server that it understands
this mode by adding the PresentOptionSuboptimal flag when calling
PresentPixmap.

Its main usage as of now is to allow clients to re-fetch DRI3
format modifiers as some modifiers might allow direct scanout.

Bump presentproto version to 1.2.

Signed-off-by: Louis-Francis Ratté-Boulianne 
Reviewed-by: Daniel Stone 
---
 include/X11/extensions/presenttokens.h | 13 +++-
 meson.build|  2 +-
 presentproto.pc.in |  2 +-
 presentproto.txt   | 36 --
 4 files changed, 36 insertions(+), 17 deletions(-)

diff --git a/include/X11/extensions/presenttokens.h 
b/include/X11/extensions/presenttokens.h
index acb7576..9211207 100644
--- a/include/X11/extensions/presenttokens.h
+++ b/include/X11/extensions/presenttokens.h
@@ -25,7 +25,7 @@
 
 #define PRESENT_NAME   "Present"
 #define PRESENT_MAJOR  1
-#define PRESENT_MINOR  0
+#define PRESENT_MINOR  2
 
 #define PresentNumberErrors0
 #define PresentNumberEvents0
@@ -44,10 +44,12 @@
 #define PresentOptionAsync  (1 << 0)
 #define PresentOptionCopy   (1 << 1)
 #define PresentOptionUST(1 << 2)
+#define PresentOptionSuboptimal (1 << 3)
 
 #define PresentAllOptions   (PresentOptionAsync | \
  PresentOptionCopy | \
- PresentOptionUST)
+ PresentOptionUST | \
+ PresentOptionSuboptimal)
 
 /* Present capabilities */
 
@@ -94,8 +96,9 @@
 
 /* Complete Modes */
 
-#define PresentCompleteModeCopy 0
-#define PresentCompleteModeFlip 1
-#define PresentCompleteModeSkip 2
+#define PresentCompleteModeCopy   0
+#define PresentCompleteModeFlip   1
+#define PresentCompleteModeSkip   2
+#define PresentCompleteModeSuboptimalCopy 3
 
 #endif
diff --git a/meson.build b/meson.build
index cb92280..6fb1541 100644
--- a/meson.build
+++ b/meson.build
@@ -36,7 +36,7 @@ pcs = [
 ['glproto', '1.4.17'],
 ['inputproto',  '2.3.2'],
 ['kbproto', '1.0.7'],
-['presentproto','1.1'],
+['presentproto','1.2'],
 ['randrproto',  '1.6.0'],
 ['recordproto', '1.14.2'],
 ['renderproto', '0.11.1'],
diff --git a/presentproto.pc.in b/presentproto.pc.in
index 9a32fa8..6ec4b7d 100644
--- a/presentproto.pc.in
+++ b/presentproto.pc.in
@@ -5,5 +5,5 @@ includedir=@includedir@
  
 Name: PresentProto
 Description: Present extension headers
-Version: 1.1
+Version: 1.2
 Cflags: -I${includedir}
diff --git a/presentproto.txt b/presentproto.txt
index fdaf658..6ba55ae 100644
--- a/presentproto.txt
+++ b/presentproto.txt
@@ -1,6 +1,6 @@
The Present Extension
-Version 1.0
-  2013-6-6
+Version 1.2
+ 2018-02-26
   
Keith Packard
  kei...@keithp.com
@@ -24,6 +24,7 @@ change and is provided only as an aid to further Present 
development.
 Eric Anholt 
 Owen Taylor 
 James Jones 
+Louis-Francis Ratté-Boulianne 
 
 ❄ ❄ ❄  ❄  ❄ ❄ ❄ 
 
@@ -55,7 +56,8 @@ PRESENTEVENTMASK { PresentConfigureNotifyMask,
 
 PRESENTOPTION { PresentOptionAsync,
 PresentOptionCopy,
-   PresentOptionUST }
+   PresentOptionUST,
+   PresentOptionSuboptimal }
 
 PRESENTCAPABILITY { PresentCapabilityAsync,
PresentCapabilityFence,
@@ -66,7 +68,8 @@ PRESENTCOMPLETEKIND { PresentCompleteKindPixmap,
 
 PRESENTCOMPLETEMODE { PresentCompleteModeCopy,
  PresentCompleteModeFlip,
- PresentCompleteModeSkip }
+ PresentCompleteModeSkip,
+ PresentCompleteModeSuboptimalCopy }
 
 The Present extension also uses the Sync extension Fence data type to
 provide synchronization for pixmaps.
@@ -226,6 +229,10 @@ The name of this extension is "Present"
server will take the target UST time and convert it to a
suitable target MSC value.
 
+   If 'options' contains PresentOptionSuboptimal, then the
+   PresentCompleteNotify event can have mode
+   PresentCompleteModeSuboptimalCopy as the client supports it.
+
After the presentation occurs, a PresentCompleteNotify event
with kind 

[PATCH v8 00/14] DRI3 multi-plane and modifier support

2018-02-27 Thread Daniel Stone
Hi,
This is a respin of lfrb's previous v7 series, mostly with
non-functional changes to the spec text.

The major change is that the DRI3 protocol version has been bumped from
1.1 to 1.2, as there was previously a dri3proto-1.1 release, only
carrying a 1.0 protocol version. We bump the version to avoid this,
jumping straight from protocol version 1.0 to 1.2.

The text now more clearly differentiates between pixmap and window
usage, includes more explicit linkage to presentation, more clearly
defines what happens with invalid modifiers, and includes a lengthy
screed about implicit vs. explicit synchronization.

Cheers,
Daniel

___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

[PATCH xserver v8 05/14] modesetting: Use atomic modesetting API for pageflip if available

2018-02-27 Thread Daniel Stone
From: Louis-Francis Ratté-Boulianne 

In order to flip between compressed and uncompressed buffers -
something drmModePageFlip explicitly bans us from doing - we need
to port use the atomic modesetting API. It's only 'fake' atomic
though given we still commit for each CRTC separately and
CRTC and connector properties are not set with the atomic API.

The helper functions to retrieve DRM properties have been borrowed
from Weston.

Signed-off-by: Louis-Francis Ratté-Boulianne 
Reviewed-by: Daniel Stone 
---
 configure.ac |   3 +
 hw/xfree86/drivers/modesetting/driver.c  |   6 +
 hw/xfree86/drivers/modesetting/driver.h  |   1 +
 hw/xfree86/drivers/modesetting/drmmode_display.c | 374 ++-
 hw/xfree86/drivers/modesetting/drmmode_display.h |  36 +++
 hw/xfree86/drivers/modesetting/pageflip.c|  22 +-
 include/dix-config.h.in  |   3 +
 include/meson.build  |   2 +
 8 files changed, 443 insertions(+), 4 deletions(-)

diff --git a/configure.ac b/configure.ac
index cef9503d7..46662867f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2106,6 +2106,9 @@ if test "x$GLAMOR" = xyes; then
fi
fi
 
+   PKG_CHECK_EXISTS(libdrm >= 2.4.62,
+[AC_DEFINE(GLAMOR_HAS_DRM_ATOMIC, 1, [libdrm supports 
atomic API])],
+[])
PKG_CHECK_EXISTS(libdrm >= 2.4.74,
 [AC_DEFINE(GLAMOR_HAS_DRM_NAME_FROM_FD_2, 1, [Have 
GLAMOR_HAS_DRM_NAME_FROM_FD_2])],
 [])
diff --git a/hw/xfree86/drivers/modesetting/driver.c 
b/hw/xfree86/drivers/modesetting/driver.c
index ec2aa9a27..88a42257c 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -1018,6 +1018,12 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 }
 #endif
 
+#ifdef GLAMOR_HAS_DRM_ATOMIC
+ret = drmSetClientCap(ms->fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1);
+ret |= drmSetClientCap(ms->fd, DRM_CLIENT_CAP_ATOMIC, 1);
+ms->atomic_modeset = (ret == 0);
+#endif
+
 if (drmmode_pre_init(pScrn, >drmmode, pScrn->bitsPerPixel / 8) == 
FALSE) {
 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "KMS setup failed\n");
 goto fail;
diff --git a/hw/xfree86/drivers/modesetting/driver.h 
b/hw/xfree86/drivers/modesetting/driver.h
index fe835918b..ed32239db 100644
--- a/hw/xfree86/drivers/modesetting/driver.h
+++ b/hw/xfree86/drivers/modesetting/driver.h
@@ -105,6 +105,7 @@ typedef struct _modesettingRec {
  * Page flipping stuff.
  *  @{
  */
+Bool atomic_modeset;
 /** @} */
 
 DamagePtr damage;
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c 
b/hw/xfree86/drivers/modesetting/drmmode_display.c
index bfc8c50db..8674c2c16 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -75,6 +75,233 @@ drmmode_zaphod_string_matches(ScrnInfoPtr scrn, const char 
*s, char *output_name
 return ret;
 }
 
+static uint64_t
+drmmode_prop_get_value(drmmode_prop_info_ptr info,
+   drmModeObjectPropertiesPtr props,
+   uint64_t def)
+{
+unsigned int i;
+
+if (info->prop_id == 0)
+return def;
+
+for (i = 0; i < props->count_props; i++) {
+unsigned int j;
+
+if (props->props[i] != info->prop_id)
+continue;
+
+/* Simple (non-enum) types can return the value directly */
+if (info->num_enum_values == 0)
+return props->prop_values[i];
+
+/* Map from raw value to enum value */
+for (j = 0; j < info->num_enum_values; j++) {
+if (!info->enum_values[j].valid)
+continue;
+if (info->enum_values[j].value != props->prop_values[i])
+continue;
+
+return j;
+}
+}
+
+return def;
+}
+
+static uint32_t
+drmmode_prop_info_update(drmmode_ptr drmmode,
+ drmmode_prop_info_ptr info,
+ unsigned int num_infos,
+ drmModeObjectProperties *props)
+{
+drmModePropertyRes *prop;
+uint32_t valid_mask = 0;
+unsigned i, j;
+
+assert(num_infos <= 32 && "update return type");
+
+for (i = 0; i < props->count_props; i++) {
+Bool props_incomplete = FALSE;
+unsigned int k;
+
+for (j = 0; j < num_infos; j++) {
+if (info[j].prop_id == props->props[i])
+break;
+if (!info[j].prop_id)
+props_incomplete = TRUE;
+}
+
+/* We've already discovered this property. */
+if (j != num_infos)
+continue;
+
+/* We haven't found this property ID, but as we've already
+ * found all known properties, we don't need to look any
+ * further. */
+if (!props_incomplete)

[PATCH xserver v8 08/14] modesetting: Get supported formats/modifiers for scanout

2018-02-27 Thread Daniel Stone
From: Louis-Francis Ratté-Boulianne 

Retrieve IN_FORMATS property from the plane. It gives the
allowed formats and modifiers for BO allocation.

Signed-off-by: Louis-Francis Ratté-Boulianne 
Reviewed-by: Daniel Stone 
---
 configure.ac |   4 +
 hw/xfree86/drivers/modesetting/drmmode_display.c | 114 ++-
 hw/xfree86/drivers/modesetting/drmmode_display.h |   9 ++
 include/dix-config.h.in  |   3 +
 include/meson.build  |   2 +
 5 files changed, 128 insertions(+), 4 deletions(-)

diff --git a/configure.ac b/configure.ac
index 46662867f..283d8e20c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2112,6 +2112,10 @@ if test "x$GLAMOR" = xyes; then
PKG_CHECK_EXISTS(libdrm >= 2.4.74,
 [AC_DEFINE(GLAMOR_HAS_DRM_NAME_FROM_FD_2, 1, [Have 
GLAMOR_HAS_DRM_NAME_FROM_FD_2])],
 [])
+
+   PKG_CHECK_EXISTS(libdrm >= 2.4.83,
+[AC_DEFINE(GLAMOR_HAS_DRM_MODIFIERS, 1, [Have 
GLAMOR_HAS_DRM_MODIFIERS])],
+[])
 fi
 AM_CONDITIONAL([GLAMOR_EGL], [test "x$GBM" = xyes])
 
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c 
b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 3e3613a98..7af805da2 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -56,6 +56,23 @@ static Bool drmmode_xf86crtc_resize(ScrnInfoPtr scrn, int 
width, int height);
 static PixmapPtr drmmode_create_pixmap_header(ScreenPtr pScreen, int width, 
int height,
   int depth, int bitsPerPixel, int 
devKind,
   void *pPixData);
+
+#ifdef GLAMOR_HAS_DRM_MODIFIERS
+
+static inline uint32_t *
+formats_ptr(struct drm_format_modifier_blob *blob)
+{
+return (uint32_t *)(((char *)blob) + blob->formats_offset);
+}
+
+static inline struct drm_format_modifier *
+modifiers_ptr(struct drm_format_modifier_blob *blob)
+{
+return (struct drm_format_modifier *)(((char *)blob) + 
blob->modifiers_offset);
+}
+
+#endif
+
 static Bool
 drmmode_zaphod_string_matches(ScrnInfoPtr scrn, const char *s, char 
*output_name)
 {
@@ -1532,15 +1549,76 @@ is_plane_assigned(ScrnInfoPtr scrn, int plane_id)
 return FALSE;
 }
 
+#ifdef GLAMOR_HAS_DRM_MODIFIERS
+/**
+ * Populates the formats array, and the modifiers of each format for a 
drm_plane.
+ */
+static Bool
+populate_format_modifiers(xf86CrtcPtr crtc, const drmModePlane *kplane,
+  uint32_t blob_id)
+{
+drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+drmmode_ptr drmmode = drmmode_crtc->drmmode;
+unsigned i, j;
+drmModePropertyBlobRes *blob;
+struct drm_format_modifier_blob *fmt_mod_blob;
+uint32_t *blob_formats;
+struct drm_format_modifier *blob_modifiers;
+
+blob = drmModeGetPropertyBlob(drmmode->fd, blob_id);
+if (!blob)
+return FALSE;
+
+fmt_mod_blob = blob->data;
+blob_formats = formats_ptr(fmt_mod_blob);
+blob_modifiers = modifiers_ptr(fmt_mod_blob);
+
+assert(drmmode_crtc->num_formats == fmt_mod_blob->count_formats);
+
+for (i = 0; i < fmt_mod_blob->count_formats; i++) {
+uint32_t num_modifiers = 0;
+uint64_t *modifiers = NULL;
+uint64_t *tmp;
+
+for (j = 0; j < fmt_mod_blob->count_modifiers; j++) {
+struct drm_format_modifier *mod = _modifiers[j];
+
+if ((i < mod->offset) || (i > mod->offset + 63))
+continue;
+if (!(mod->formats & (1 << (i - mod->offset
+continue;
+
+num_modifiers++;
+tmp = realloc(modifiers, num_modifiers * sizeof(modifiers[0]));
+if (!tmp) {
+free(modifiers);
+drmModeFreePropertyBlob(blob);
+return FALSE;
+}
+modifiers = tmp;
+modifiers[num_modifiers - 1] = mod->modifier;
+}
+
+drmmode_crtc->formats[i].format = blob_formats[i];
+drmmode_crtc->formats[i].modifiers = modifiers;
+drmmode_crtc->formats[i].num_modifiers = num_modifiers;
+}
+
+drmModeFreePropertyBlob(blob);
+
+return TRUE;
+}
+#endif
+
 static void
 drmmode_crtc_create_planes(xf86CrtcPtr crtc, int num)
 {
 drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
 drmmode_ptr drmmode = drmmode_crtc->drmmode;
 drmModePlaneRes *kplane_res;
-drmModePlane *kplane;
+drmModePlane *kplane, *best_kplane = NULL;
 drmModeObjectProperties *props;
-uint32_t i, type;
+uint32_t i, type, blob_id;
 int current_crtc, best_plane = 0;
 
 static drmmode_prop_enum_info_rec plane_type_enums[] = {
@@ -1562,6 +1640,7 @@ drmmode_crtc_create_planes(xf86CrtcPtr crtc, int num)
 },
 [DRMMODE_PLANE_FB_ID] = { 

[PATCH xserver v8 09/14] modesetting: Create scanout buffers using supported modifiers

2018-02-27 Thread Daniel Stone
From: Louis-Francis Ratté-Boulianne 

Use most optimal buffer format (e.g. tiled/compressed) available
for scanout.

v2: Don't use multi-plane modifier to create scanout buffer

v3: Add flag to retrieve modifiers set from enabled CRTCs only

v4: Fix uses when GBM/EGL driver doesn't support modifiers

Signed-off-by: Louis-Francis Ratté-Boulianne 
Reviewed-by: Daniel Stone 
---
 hw/xfree86/drivers/modesetting/drmmode_display.c | 90 +++-
 1 file changed, 87 insertions(+), 3 deletions(-)

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c 
b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 7af805da2..6fa22da56 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -73,6 +73,68 @@ modifiers_ptr(struct drm_format_modifier_blob *blob)
 
 #endif
 
+#ifdef GBM_BO_WITH_MODIFIERS
+static uint32_t
+get_modifiers_set(ScrnInfoPtr scrn, uint32_t format, uint64_t **modifiers,
+  Bool enabled_crtc_only, Bool exclude_multiplane)
+{
+xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+modesettingPtr ms = modesettingPTR(scrn);
+drmmode_ptr drmmode = >drmmode;
+int c, i, j, k, count_modifiers = 0;
+uint64_t *tmp, *ret = NULL;
+
+*modifiers = NULL;
+for (c = 0; c < xf86_config->num_crtc; c++) {
+xf86CrtcPtr crtc = xf86_config->crtc[c];
+drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+
+if (enabled_crtc_only && !crtc->enabled)
+continue;
+
+for (i = 0; i < drmmode_crtc->num_formats; i++) {
+drmmode_format_ptr iter = _crtc->formats[i];
+
+if (iter->format != format)
+continue;
+
+for (j = 0; j < iter->num_modifiers; j++) {
+Bool found = FALSE;
+
+   /* Don't choose multi-plane formats for our screen pixmap.
+* These will get used with frontbuffer rendering, which will
+* lead to worse-than-tearing with multi-plane formats, as the
+* primary and auxiliary planes go out of sync. */
+   if (exclude_multiplane &&
+gbm_device_get_format_modifier_plane_count(drmmode->gbm,
+   format,
+   
iter->modifiers[j]) > 1) {
+continue;
+}
+
+for (k = 0; k < count_modifiers; k++) {
+if (iter->modifiers[j] == ret[k])
+found = TRUE;
+}
+if (!found) {
+count_modifiers++;
+tmp = realloc(ret, count_modifiers * sizeof(uint64_t));
+if (!tmp) {
+free(ret);
+return 0;
+}
+ret = tmp;
+ret[count_modifiers - 1] = iter->modifiers[j];
+}
+}
+}
+}
+
+*modifiers = ret;
+return count_modifiers;
+}
+#endif
+
 static Bool
 drmmode_zaphod_string_matches(ScrnInfoPtr scrn, const char *s, char 
*output_name)
 {
@@ -593,14 +655,36 @@ static Bool
 drmmode_create_bo(drmmode_ptr drmmode, drmmode_bo *bo,
   unsigned width, unsigned height, unsigned bpp)
 {
+uint32_t format;
+
+if (drmmode->scrn->depth == 30)
+format = GBM_FORMAT_ARGB2101010;
+else
+format = GBM_FORMAT_ARGB;
+
 bo->width = width;
 bo->height = height;
 
 #ifdef GLAMOR_HAS_GBM
 if (drmmode->glamor) {
-bo->gbm = gbm_bo_create(drmmode->gbm, width, height,
-drmmode->scrn->depth == 30 ?
-GBM_FORMAT_ARGB2101010 : GBM_FORMAT_ARGB,
+#ifdef GBM_BO_WITH_MODIFIERS
+uint32_t num_modifiers;
+uint64_t *modifiers = NULL;
+
+num_modifiers = get_modifiers_set(drmmode->scrn, format, ,
+  FALSE, TRUE);
+if (num_modifiers > 0 &&
+!(num_modifiers == 1 && modifiers[0] == DRM_FORMAT_MOD_INVALID)) {
+bo->gbm = gbm_bo_create_with_modifiers(drmmode->gbm, width, height,
+   format, modifiers,
+   num_modifiers);
+free(modifiers);
+if (bo->gbm)
+return TRUE;
+}
+#endif
+
+bo->gbm = gbm_bo_create(drmmode->gbm, width, height, format,
 GBM_BO_USE_RENDERING | GBM_BO_USE_SCANOUT);
 return bo->gbm != NULL;
 }
-- 
2.14.3

___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

[PATCH xserver v8 06/14] modesetting: Add support for multi-plane pixmaps when page-flipping

2018-02-27 Thread Daniel Stone
From: Louis-Francis Ratté-Boulianne 

This allows the uses of CCS compressed or tiled pixmaps as BOs when
page-flipping.

Signed-off-by: Louis-Francis Ratté-Boulianne 
Reviewed-by: Daniel Stone 
---
 hw/xfree86/drivers/modesetting/drmmode_display.c | 49 
 hw/xfree86/drivers/modesetting/drmmode_display.h |  4 ++
 hw/xfree86/drivers/modesetting/pageflip.c| 16 
 3 files changed, 62 insertions(+), 7 deletions(-)

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c 
b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 8674c2c16..ee9f4d724 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -39,6 +39,8 @@
 #include "micmap.h"
 #include "xf86cmap.h"
 #include "xf86DDC.h"
+#include 
+#include 
 
 #include 
 #include "xf86Crtc.h"
@@ -376,10 +378,57 @@ drmmode_bo_map(drmmode_ptr drmmode, drmmode_bo *bo)
 return bo->dumb->ptr;
 }
 
+int
+drmmode_bo_import(drmmode_ptr drmmode, drmmode_bo *bo,
+  uint32_t *fb_id)
+{
+#ifdef GBM_BO_WITH_MODIFIERS
+if (bo->gbm &&
+gbm_bo_get_modifier(bo->gbm) != DRM_FORMAT_MOD_INVALID) {
+int num_fds;
+
+num_fds = gbm_bo_get_plane_count(bo->gbm);
+if (num_fds > 0) {
+int i;
+uint32_t format;
+uint32_t handles[4];
+uint32_t strides[4];
+uint32_t offsets[4];
+uint64_t modifiers[4];
+
+memset(handles, 0, sizeof(handles));
+memset(strides, 0, sizeof(strides));
+memset(offsets, 0, sizeof(offsets));
+memset(modifiers, 0, sizeof(modifiers));
+
+format = gbm_bo_get_format(bo->gbm);
+for (i = 0; i < num_fds; i++) {
+handles[i] = gbm_bo_get_handle_for_plane(bo->gbm, i).u32;
+strides[i] = gbm_bo_get_stride_for_plane(bo->gbm, i);
+offsets[i] = gbm_bo_get_offset(bo->gbm, i);
+modifiers[i] = gbm_bo_get_modifier(bo->gbm);
+}
+
+return drmModeAddFB2WithModifiers(drmmode->fd, bo->width, 
bo->height,
+  format, handles, strides,
+  offsets, modifiers, fb_id,
+  DRM_MODE_FB_MODIFIERS);
+}
+}
+#endif
+return drmModeAddFB(drmmode->fd, bo->width, bo->height,
+drmmode->scrn->depth, drmmode->scrn->bitsPerPixel,
+drmmode_bo_get_pitch(bo),
+drmmode_bo_get_handle(bo), fb_id);
+}
+
 static Bool
 drmmode_create_bo(drmmode_ptr drmmode, drmmode_bo *bo,
   unsigned width, unsigned height, unsigned bpp)
 {
+bo->width = width;
+bo->height = height;
+
 #ifdef GLAMOR_HAS_GBM
 if (drmmode->glamor) {
 bo->gbm = gbm_bo_create(drmmode->gbm, width, height,
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h 
b/hw/xfree86/drivers/modesetting/drmmode_display.h
index 1f24c3a5b..177ccabd7 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.h
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.h
@@ -53,6 +53,8 @@ enum drmmode_plane_type {
 };
 
 typedef struct {
+uint32_t width;
+uint32_t height;
 struct dumb_bo *dumb;
 #ifdef GLAMOR_HAS_GBM
 struct gbm_bo *gbm;
@@ -202,6 +204,8 @@ extern DevPrivateKeyRec msPixmapPrivateKeyRec;
 
 #define msGetPixmapPriv(drmmode, p) 
((msPixmapPrivPtr)dixGetPrivateAddr(&(p)->devPrivates, 
&(drmmode)->pixmapPrivateKeyRec))
 
+int drmmode_bo_import(drmmode_ptr drmmode, drmmode_bo *bo,
+  uint32_t *fb_id);
 int drmmode_bo_destroy(drmmode_ptr drmmode, drmmode_bo *bo);
 uint32_t drmmode_bo_get_pitch(drmmode_bo *bo);
 uint32_t drmmode_bo_get_handle(drmmode_bo *bo);
diff --git a/hw/xfree86/drivers/modesetting/pageflip.c 
b/hw/xfree86/drivers/modesetting/pageflip.c
index dd296cd12..027ebfe42 100644
--- a/hw/xfree86/drivers/modesetting/pageflip.c
+++ b/hw/xfree86/drivers/modesetting/pageflip.c
@@ -258,6 +258,7 @@ ms_do_pageflip(ScreenPtr screen,
 
 new_front_bo.gbm = glamor_gbm_bo_from_pixmap(screen, new_front);
 new_front_bo.dumb = NULL;
+
 if (!new_front_bo.gbm) {
 xf86DrvMsg(scrn->scrnIndex, X_ERROR,
"Failed to get GBM bo for flip to new front.\n");
@@ -288,14 +289,12 @@ ms_do_pageflip(ScreenPtr screen,
 
 /* Create a new handle for the back buffer */
 flipdata->old_fb_id = ms->drmmode.fb_id;
-if (drmModeAddFB(ms->fd, scrn->virtualX, scrn->virtualY,
- scrn->depth, scrn->bitsPerPixel,
- drmmode_bo_get_pitch(_front_bo),
- drmmode_bo_get_handle(_front_bo), 
>drmmode.fb_id)) {
-goto error_out;
-}
 
-drmmode_bo_destroy(>drmmode, _front_bo);
+new_front_bo.width = new_front->drawable.width;
+

[PATCH xserver v8 03/14] dri3: Add multi-planar/modifier buffer requests

2018-02-27 Thread Daniel Stone
From: Louis-Francis Ratté-Boulianne 

Initial implementation for DRI3 v1.1. Only the DRI3 implementation
is there, backends need to implement the proper hooks.

Version is still set to 1.0 so clients shouldn't use the new
requests yet.

v2: Use depth/bpp instead of DRM formats in requests

v3: Remove DMA fence requests from v1.1
Add screen/drawable modifier sets

v4: Free array returned by 'get_drawable_modifiers()'

v5: Fix FD leak

Signed-off-by: Daniel Stone 
Signed-off-by: Louis-Francis Ratté-Boulianne 
---
 configure.ac  |   2 +-
 dri3/dri3.c   |  19 +++
 dri3/dri3.h   |  44 ++-
 dri3/dri3_priv.h  |  27 +++-
 dri3/dri3_request.c   | 294 --
 dri3/dri3_screen.c| 196 ++--
 hw/xwayland/xwayland-glamor.c |   4 +-
 meson.build   |   2 +-
 8 files changed, 559 insertions(+), 29 deletions(-)

diff --git a/configure.ac b/configure.ac
index 4d7c24fa9..47469d864 100644
--- a/configure.ac
+++ b/configure.ac
@@ -729,7 +729,7 @@ SCRNSAVERPROTO="scrnsaverproto >= 1.1"
 RESOURCEPROTO="resourceproto >= 1.2.0"
 DRIPROTO="xf86driproto >= 2.1.0"
 DRI2PROTO="dri2proto >= 2.8"
-DRI3PROTO="dri3proto >= 1.0"
+DRI3PROTO="dri3proto >= 1.2"
 XINERAMAPROTO="xineramaproto"
 BIGFONTPROTO="xf86bigfontproto >= 1.2.0"
 DGAPROTO="xf86dgaproto >= 2.0.99.1"
diff --git a/dri3/dri3.c b/dri3/dri3.c
index d042b8b7d..8ac0f3ae2 100644
--- a/dri3/dri3.c
+++ b/dri3/dri3.c
@@ -26,6 +26,8 @@
 
 #include "dri3_priv.h"
 
+#include 
+
 static int dri3_request;
 DevPrivateKeyRec dri3_screen_private_key;
 
@@ -99,3 +101,20 @@ dri3_extension_init(void)
 bail:
 FatalError("Cannot initialize DRI3 extension");
 }
+
+uint32_t
+drm_format_for_depth(uint32_t depth, uint32_t bpp)
+{
+switch (bpp) {
+case 16:
+return DRM_FORMAT_RGB565;
+case 24:
+return DRM_FORMAT_XRGB;
+case 30:
+return DRM_FORMAT_XRGB2101010;
+case 32:
+return DRM_FORMAT_ARGB;
+default:
+return 0;
+}
+}
diff --git a/dri3/dri3.h b/dri3/dri3.h
index 7562352ff..89ad13ad9 100644
--- a/dri3/dri3.h
+++ b/dri3/dri3.h
@@ -28,7 +28,7 @@
 #include 
 #include 
 
-#define DRI3_SCREEN_INFO_VERSION1
+#define DRI3_SCREEN_INFO_VERSION2
 
 typedef int (*dri3_open_proc)(ScreenPtr screen,
   RRProviderPtr provider,
@@ -47,11 +47,43 @@ typedef PixmapPtr (*dri3_pixmap_from_fd_proc) (ScreenPtr 
screen,
CARD8 depth,
CARD8 bpp);
 
+typedef PixmapPtr (*dri3_pixmap_from_fds_proc) (ScreenPtr screen,
+CARD8 num_fds,
+int *fds,
+CARD16 width,
+CARD16 height,
+CARD32 *strides,
+CARD32 *offsets,
+CARD8 depth,
+CARD8 bpp,
+CARD64 modifier);
+
 typedef int (*dri3_fd_from_pixmap_proc) (ScreenPtr screen,
  PixmapPtr pixmap,
  CARD16 *stride,
  CARD32 *size);
 
+typedef int (*dri3_fds_from_pixmap_proc) (ScreenPtr screen,
+  PixmapPtr pixmap,
+  int *fds,
+  CARD32 *strides,
+  CARD32 *offsets,
+  CARD64 *modifier);
+
+typedef int (*dri3_get_formats_proc) (ScreenPtr screen,
+  CARD32 *num_formats,
+  CARD32 **formats);
+
+typedef int (*dri3_get_modifiers_proc) (ScreenPtr screen,
+CARD32 format,
+CARD32 *num_modifiers,
+CARD64 **modifiers);
+
+typedef int (*dri3_get_drawable_modifiers_proc) (DrawablePtr draw,
+ CARD32 format,
+ CARD32 *num_modifiers,
+ CARD64 **modifiers);
+
 typedef struct dri3_screen_info {
 uint32_tversion;
 
@@ -62,6 +94,13 @@ typedef struct dri3_screen_info {
 /* Version 1 */
 dri3_open_client_proc   open_client;
 
+/* Version 2 */
+dri3_pixmap_from_fds_proc   pixmap_from_fds;
+dri3_fds_from_pixmap_proc   

[PATCH xserver v8 04/14] present: Send PresentCompleteModeSuboptimalCopy appropriately

2018-02-27 Thread Daniel Stone
From: Louis-Francis Ratté-Boulianne 

Add 'check_flip2' hook for driver to let know the core
about why flipping is not possible ('reason').
If it is because of unsupported buffer format/modifier,
a PresentCompleteNotify event is sent to the client with
the PresentCompleteModeSuboptimalCopy mode.

v2: Check for PresentOptionSuboptimal and check driver version
before using 'check_flip2'.

v3: Only require one of 'check_flip' or 'check_flip2' to be
implemented by the driver.
Refactor reasons list to enum

Signed-off-by: Louis-Francis Ratté-Boulianne 
Reviewed-by: Daniel Stone 
---
 configure.ac|  2 +-
 include/protocol-versions.h |  2 +-
 present/meson.build |  2 +-
 present/present.c   | 50 ++---
 present/present.h   | 12 ++-
 present/present_priv.h  |  2 ++
 6 files changed, 50 insertions(+), 20 deletions(-)

diff --git a/configure.ac b/configure.ac
index 47469d864..cef9503d7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -753,7 +753,7 @@ DAMAGEPROTO="damageproto >= 1.1"
 XCMISCPROTO="xcmiscproto >= 1.2.0"
 BIGREQSPROTO="bigreqsproto >= 1.1.0"
 XTRANS="xtrans >= 1.3.5"
-PRESENTPROTO="presentproto >= 1.0"
+PRESENTPROTO="presentproto >= 1.1"
 
 dnl List of libraries that require a specific version
 LIBAPPLEWM="applewm >= 1.4"
diff --git a/include/protocol-versions.h b/include/protocol-versions.h
index 938b9caa4..39cd2e909 100644
--- a/include/protocol-versions.h
+++ b/include/protocol-versions.h
@@ -69,7 +69,7 @@
 
 /* Present */
 #define SERVER_PRESENT_MAJOR_VERSION1
-#define SERVER_PRESENT_MINOR_VERSION0
+#define SERVER_PRESENT_MINOR_VERSION1
 
 /* RandR */
 #define SERVER_RANDR_MAJOR_VERSION 1
diff --git a/present/meson.build b/present/meson.build
index a4296ca7a..cf725302a 100644
--- a/present/meson.build
+++ b/present/meson.build
@@ -13,7 +13,7 @@ libxserver_present = static_library('libxserver_present',
 include_directories: inc,
 dependencies: [
 common_dep,
-dependency('presentproto', version: '>= 1.0')
+dependency('presentproto', version: '>= 1.1')
 ],
 c_args: '-DHAVE_XORG_CONFIG_H'
 )
diff --git a/present/present.c b/present/present.c
index 176e89c0b..42e5fb4fc 100644
--- a/present/present.c
+++ b/present/present.c
@@ -118,19 +118,23 @@ present_flip_pending_pixmap(ScreenPtr screen)
 }
 
 static Bool
-present_check_flip(RRCrtcPtrcrtc,
-   WindowPtrwindow,
-   PixmapPtrpixmap,
-   Bool sync_flip,
-   RegionPtrvalid,
-   int16_t  x_off,
-   int16_t  y_off)
+present_check_flip(RRCrtcPtrcrtc,
+   WindowPtrwindow,
+   PixmapPtrpixmap,
+   Bool sync_flip,
+   RegionPtrvalid,
+   int16_t  x_off,
+   int16_t  y_off,
+   PresentFlipReason   *reason)
 {
 ScreenPtr   screen = window->drawable.pScreen;
 PixmapPtr   window_pixmap;
 WindowPtr   root = screen->root;
 present_screen_priv_ptr screen_priv = present_screen_priv(screen);
 
+if (reason)
+*reason = PRESENT_FLIP_REASON_UNKNOWN;
+
 if (!screen_priv)
 return FALSE;
 
@@ -177,7 +181,12 @@ present_check_flip(RRCrtcPtrcrtc,
 }
 
 /* Ask the driver for permission */
-if (screen_priv->info->check_flip) {
+if (screen_priv->info->version >= 1 && screen_priv->info->check_flip2) {
+if (!(*screen_priv->info->check_flip2) (crtc, window, pixmap, 
sync_flip, reason)) {
+DebugPresent(("\td %08lx -> %08lx\n", window->drawable.id, pixmap 
? pixmap->drawable.id : 0));
+return FALSE;
+}
+} else if (screen_priv->info->check_flip) {
 if (!(*screen_priv->info->check_flip) (crtc, window, pixmap, 
sync_flip)) {
 DebugPresent(("\td %08lx -> %08lx\n", window->drawable.id, pixmap 
? pixmap->drawable.id : 0));
 return FALSE;
@@ -564,6 +573,7 @@ present_check_flip_window (WindowPtr window)
 present_window_priv_ptr window_priv = present_window_priv(window);
 present_vblank_ptr  flip_pending = screen_priv->flip_pending;
 present_vblank_ptr  vblank;
+PresentFlipReason   reason;
 
 /* If this window hasn't ever been used with Present, it can't be
  * flipping
@@ -580,7 +590,7 @@ present_check_flip_window (WindowPtr window)
  */
 if (flip_pending->window == window) {
 if (!present_check_flip(flip_pending->crtc, window, 
flip_pending->pixmap,
-flip_pending->sync_flip, NULL, 0, 0))
+

[PATCH xserver v8 07/14] modesetting: Use atomic modesetting to configure output/CRTCs

2018-02-27 Thread Daniel Stone
From: Louis-Francis Ratté-Boulianne 

To make sure we also use the same primary plane and to avoid
mixing uses of two APIs, it is better to always use the atomic
modesetting API when possible.

v2: Don't use mode_output->connector_id

Signed-off-by: Louis-Francis Ratté-Boulianne 
Reviewed-by: Daniel Stone 
---
 hw/xfree86/drivers/modesetting/drmmode_display.c | 262 +++
 hw/xfree86/drivers/modesetting/drmmode_display.h |  30 ++-
 hw/xfree86/drivers/modesetting/pageflip.c|   2 +-
 hw/xfree86/drivers/modesetting/present.c |   3 +-
 4 files changed, 252 insertions(+), 45 deletions(-)

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c 
b/hw/xfree86/drivers/modesetting/drmmode_display.c
index ee9f4d724..3e3613a98 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -267,16 +267,100 @@ plane_add_prop(drmModeAtomicReq *req, 
drmmode_crtc_private_ptr drmmode_crtc,
info->prop_id, val);
 return (ret <= 0) ? -1 : 0;
 }
+
+static int
+crtc_add_prop(drmModeAtomicReq *req, drmmode_crtc_private_ptr drmmode_crtc,
+  enum drmmode_crtc_property prop, uint64_t val)
+{
+drmmode_prop_info_ptr info = _crtc->props[prop];
+int ret;
+
+if (!info)
+return -1;
+
+ret = drmModeAtomicAddProperty(req, drmmode_crtc->mode_crtc->crtc_id,
+   info->prop_id, val);
+return (ret <= 0) ? -1 : 0;
+}
+
+static int
+connector_add_prop(drmModeAtomicReq *req, drmmode_output_private_ptr 
drmmode_output,
+   enum drmmode_connector_property prop, uint64_t val)
+{
+drmmode_prop_info_ptr info = _output->props_connector[prop];
+int ret;
+
+if (!info)
+return -1;
+
+ret = drmModeAtomicAddProperty(req, drmmode_output->output_id,
+   info->prop_id, val);
+return (ret <= 0) ? -1 : 0;
+}
+
+static int
+drmmode_CompareKModes(drmModeModeInfo * kmode, drmModeModeInfo * other)
+{
+return memcmp(kmode, other, sizeof(*kmode));
+}
+
+static int
+drm_mode_ensure_blob(xf86CrtcPtr crtc, drmModeModeInfo mode_info)
+{
+modesettingPtr ms = modesettingPTR(crtc->scrn);
+drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+drmmode_mode_ptr mode;
+int ret;
+
+if (drmmode_crtc->current_mode &&
+drmmode_CompareKModes(_crtc->current_mode->mode_info, 
_info) == 0)
+return 0;
+
+mode = calloc(sizeof(drmmode_mode_rec), 1);
+if (!mode)
+return -1;
+
+mode->mode_info = mode_info;
+ret = drmModeCreatePropertyBlob(ms->fd,
+>mode_info,
+sizeof(mode->mode_info),
+>blob_id);
+drmmode_crtc->current_mode = mode;
+xorg_list_add(>entry, _crtc->mode_list);
+
+return ret;
+}
+
+static void
+drm_mode_destroy(xf86CrtcPtr crtc, drmmode_mode_ptr mode)
+{
+modesettingPtr ms = modesettingPTR(crtc->scrn);
+if (mode->blob_id)
+drmModeDestroyPropertyBlob(ms->fd, mode->blob_id);
+xorg_list_del(>entry);
+free(mode);
+}
 #endif
 
+static void
+drmmode_ConvertToKMode(ScrnInfoPtr scrn,
+   drmModeModeInfo * kmode, DisplayModePtr mode);
+
 int
-drmmode_crtc_set_fb(xf86CrtcPtr crtc, uint32_t fb_id,
+drmmode_crtc_set_fb(xf86CrtcPtr crtc, DisplayModePtr mode, uint32_t fb_id,
 int x, int y, uint32_t flags, void *data)
 {
 modesettingPtr ms = modesettingPTR(crtc->scrn);
 xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
 drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
-int ret = 0;
+drmmode_ptr drmmode = drmmode_crtc->drmmode;
+int output_count = 0;
+uint32_t *output_ids = NULL;
+drmModeModeInfo kmode;
+int i, ret = 0;
+
+if (mode)
+drmmode_ConvertToKMode(crtc->scrn, , mode);
 
 #ifdef GLAMOR_HAS_DRM_ATOMIC
 if (ms->atomic_modeset) {
@@ -285,12 +369,56 @@ drmmode_crtc_set_fb(xf86CrtcPtr crtc, uint32_t fb_id,
 if (!req)
 return 1;
 
+if (mode) {
+ret = drm_mode_ensure_blob(crtc, kmode);
+
+for (i = 0; i < xf86_config->num_output; i++) {
+xf86OutputPtr output = xf86_config->output[i];
+drmmode_output_private_ptr drmmode_output;
+
+if (output->crtc != crtc)
+continue;
+
+drmmode_output = output->driver_private;
+if (drmmode_output->output_id == -1)
+continue;
+
+if (drmmode_output->dpms == DPMSModeOn) {
+ret |= crtc_add_prop(req, drmmode_crtc,
+ DRMMODE_CRTC_ACTIVE, 1);
+ret |= crtc_add_prop(req, drmmode_crtc,
+ 

Re: [RFC xorgproto v7 02/14] presentproto: PresentCompleteModeSuboptimalCopy flag

2018-02-27 Thread Daniel Stone
Hi,

On 27 February 2018 at 21:12, Keith Packard  wrote:
> Louis-Francis Ratté-Boulianne  writes:
>> +#define PresentCompleteModeFlip   1
>> +#define PresentCompleteModeSkip   2
>> +#define PresentCompleteModeSuboptimalCopy 3
>
> I realize that the goal is to get from Copy to Flip; I wonder if we
> might ever need a 'we managed to flip, but it's not great' mode and so
> want a PresentCompleteModeSuboptimalFlip case as well?

For the record, whilst this is true, we don't have any way of knowing
it in the open drivers at least. We know the SuboptimalCopy case
because we can tell that KMS just doesn't support the client buffer's
format+modifier. But there's no indication from KMS that a particular
FB is suboptimally-flippable. I suggested deferring the addition of a
SuboptimalFlip completion mode until we have a real user for it
(Xorg-on-HWC?).

Cheers,
Daniel
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

Re: xserver 1.20 RC1 tomorrow

2018-02-27 Thread Daniel Stone
Hi,

On 27 February 2018 at 21:59, Adam Jackson  wrote:
> 2) https://patchwork.freedesktop.org/series/27289/
> DRI3 v1.2. Has some ABI changes, but none that are essential, the old
> single-fd API can either be kept as is, or implemented in terms opf the
> new multiple-fd API.

Perhaps I'm being dense, but I can't see that this does have driver
ABI changes? The old single-plane hooks are still in place, and the
core has helpers to call them if possible (single-plane, no modifier,
driver doesn't have newer hook). We do change the helper to be
multi-FD rather than single FD, but that's just in dri3_priv.h, so
presumably not ABI?

> 3) https://patchwork.freedesktop.org/series/30946/
> DMA fences for DRI3. Does have at least one ABI change that looks
> essential, in misync.

I would certainly like to see this land, but there are some open
questions it'd be great to get more feedback: namely, should we use
the fences to schedule in-server (and not submit blits/flips until the
fence has passed), or should we pass the fences into the client APIs
(e.g. GPU command-stream wait on EGL-imported fences, KMS commit
wait). The former is more obvious, but also a behavioural change from
how we handled implicit fences previously.

> 4) https://patchwork.freedesktop.org/series/37274/
> Per-window flips for Xwayland. No xfree86 changes.

I'd quite like to give this another review pass, especially for
subsurfaces, but generally if Michel is happy than I am.

Cheers,
Daniel
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

xserver 1.20 RC1 tomorrow

2018-02-27 Thread Adam Jackson
I'd like to call the (xfree86) ABI frozen in RC1, and I think for the
remaining changes I'd like to see landed for 1.20 we can mostly land
them without ABI breaks. To enumerate:

1) https://patchwork.freedesktop.org/series/38022/ 
Xwayland streams support. No xfree86 changes.

2) https://patchwork.freedesktop.org/series/27289/
DRI3 v1.2. Has some ABI changes, but none that are essential, the old
single-fd API can either be kept as is, or implemented in terms opf the
new multiple-fd API.

3) https://patchwork.freedesktop.org/series/30946/
DMA fences for DRI3. Does have at least one ABI change that looks
essential, in misync. 

4) https://patchwork.freedesktop.org/series/37274/
Per-window flips for Xwayland. No xfree86 changes.

I'm not aware of any other major change series outstanding (that I
haven't myself written and failed to send). If you know of something
I've missed, please yell very loudly very soon.

Also, if you care about any of the above, patch review would be greatly
appreciated.

- ajax
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

Re: [RFC xorgproto v7 02/14] presentproto: PresentCompleteModeSuboptimalCopy flag

2018-02-27 Thread Keith Packard
Louis-Francis Ratté-Boulianne  writes:

> -#define PresentCompleteModeCopy 0
> -#define PresentCompleteModeFlip 1
> -#define PresentCompleteModeSkip 2
> +#define PresentCompleteModeCopy   0
> +#define PresentCompleteModeFlip   1
> +#define PresentCompleteModeSkip   2
> +#define PresentCompleteModeSuboptimalCopy 3

I realize that the goal is to get from Copy to Flip; I wonder if we
might ever need a 'we managed to flip, but it's not great' mode and so
want a PresentCompleteModeSuboptimalFlip case as well?

-- 
-keith


signature.asc
Description: PGP signature
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

Re: [RFC xserver v7 1/2] dri3: Add modifier/multi-plane requests, bump to v1.1

2018-02-27 Thread Keith Packard
Louis-Francis Ratté-Boulianne  writes:

> + The first list of 'drawable_modifiers' contains a set of
> + modifiers which the server considers optimal for the window's
> + current configuration. Using these modifiers to allocate, even
> + if locally suboptimal to the client driver, may result in a
> + more optimal display pipeline, e.g. by avoiding composition.

I think it would be good to explicitly mention the expected
PresentPixmap usage to describe why the window matters at
all. I didn't understand this when just reading the patch.

> + DRM_FORMAT_MOD_INVALID may be passed for 'modifier', in which
> + case the driver may make its own inference as to the exact
> + layout of the buffer(s).


I don't like using a name here which isn't consistent with the actual
semantic. I can easily imagine reading code using this extension and
having to go find the spec to figure out what DRM_FORMAT_MOD_INVALID
could mean in this context. Can we come up with a better name than this?
DRM_FORMAT_MOD_IMPLICIT or DRM_FORMAT_MOD_DRIVER_FIGURES_IT_OUT?

> + Synchronization of access to buffers shared between processes
> + is not defined by this protocol. Without the use of additional
> + extensions not defined by the DRI3 protocol as of version 1.1,
> + synchronization between multiple processes and contexts is
> + considered to follow the implicit model.
> +
> + In this model, the underlying driver is responsible for
> + enforcing a strict ordering such that any reads requested by
> + one process or context are fulfilled before any writes requested
> + by another process or context, as long as that read was
> + definitively submitted before the write (e.g. a through a
> + blocking read command such as glReadPixels or explicitly
> + flushing the command stream through glFlush). A similar
> + dependency exists for reads submitted after writes: the driver
> + must ensure that the write is fully visible and coherent to the
> + read request.

This is a great addition; i think it needs to be in a separate section
from the requests so that it can apply equally to all objects referenced
in the extension.

-- 
-keith


signature.asc
Description: PGP signature
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

Re: [RFC dri3proto v6 01/14] Add modifier/multi-plane requests, bump to v1.1

2018-02-27 Thread Keith Packard
Daniel Stone  writes:

> Oof. Originally we tried to match the rest of the stack by using
> formats rather than depth/bpp, but that rather breaks the current
> model where DRI3 is a transport for a bag of bits, and Present is the
> mechanism by which you make those bag of bits visible in a Window.

Yeah, thanks for the good discussion, I was just poking at the
boundaries here, and I now agree that depth+bpp is probably our best
option. Including bpp lets us go beyond the core protocol and use
formats which are different from image formats, and that seems like a
good idea.

> Hm, why would they? For DirectColour, presumably either your only
> difference from a hardware-accelerated TrueColor source is that you
> stick a huge LUT at the end of the frag shader, or you have a software
> pipeline.

Nah, DirectColor has a LUT in the scanout engine so you can do colormap
animation effects. As I said, it's not exactly popular these days for
very good reasons.

>>> of the right format before using DRI3PixmapFromBuffers.
>>
>> Like was mentionned by Daniel on #xorg-devel, we really need to have
>> the 'drawable' here and can't easily retrieve the drawable-specific
>> modifiers just from the 'depth'. (We check if the window is a possible
>> candidate for scanout to avoid useless client buffer reallocation).

Yup. I see you're mixing 'drawable' and 'window' freely here; I'd like
to be consistent. I think using 'window' would be best as then we
can explicitly document the expectation of using the resulting pixmap in
a PresentPixmap request for the specified window.


>>
>> We don't explicitely state that in the spec though to be as general as
>> possible. I guess it wouldn't hurt to add an example though if you
>> think it would make things clearer.
>
> Maybe something like:
>   Return supported DRM FourCC modifiers for the specified 'window'.
>
>   The first list of 'drawable_modifiers' contains a set of modifiers which
>   the server considers optimal for the window's current configuration.
>   Using these modifiers to allocate, even if locally suboptimal to the
>   client driver, may result in a more optimal display pipeline, e.g. by
>   avoiding composition.

I think this might mention the expected use of the resulting pixmap in a later
PresentPixmap request; that makes the connection between the 'window'
parameter and the created pixmap explicit.

>> Do you mean adding a new synchronization mechanism (between X rendering
>> and client rendering) that would only apply to this request (not
>> PixapFromBuffer)? Was it considered problematic with DRI3 v1.0?

No, I'd love to see a section describing the synchronization available
to all objects created through this extension.

> DRI3 v1.2 - sent to the list in August but with very little comment -
> adds support for dma-fence FDs. Michel questioned whether it would be
> best to insert a GPU command-stream stall, or use an asynchronous
> fence-completion mechanism to only later trigger presentation when the
> fence has passed, similar to if the client had specified that
> presentation should wait for a UST equivalent to when the fence was
> signalled. My intuition is that he's right, but it would be great to
> get more feedback on this.
>
> Louis-Francis hooked this up to the Vulkan WSI in Mesa, so you could
> use real semaphore objects in QueuePresent and AcquireNextImage.
>
> https://lists.freedesktop.org/archives/xorg-devel/2017-August/054439.html
> https://lists.freedesktop.org/archives/mesa-dev/2017-August/168201.html

Those look like reasonable patches on a first read-through; I was a bit
confused by the lack of any way for the server to wakeup when the DMA
fence became readable? Does it not need to be able to do that in case
the driver doesn't deal with it?

>>> > +   DRM_FORMAT_MOD_INVALID may be passed for 'modifier', in
>>> > which
>>> > +   case the driver may make its own inference as to the exact
>>> > +   layout of the buffer(s).
>>>
>>> Presumably using information acquired externally?
>>
>> Or internally; some drivers add metadata to the buffer to know about
>> tiling, etc.

I'm not terribly excited about this name; is there some way we could
make usage clearer in code?
DRM_FORMAT_MOD_FIGURE_IT_OUT_AUTOMATICALLY_SOMEHOW seems a bit long
though?

> Since that's just advisory
> text, we could explicitly make it 'undefined', or just leave it
> completely unstated, or ...

Well, I'd love to have this usage documented in the protocol spec so
that when people read the code there's someplace that says what it
means. And that would be more clear if we used a constant with a better
name than INVALID.

>   Synchronization of access to buffers shared between processes is not
>   defined by this protocol [ed: well, until DRI3 v1.2 adds explicit fencing].
>   Without the use of additional extensions not defined by the DRI3
>   protocol as of version 1.1, synchronization between multiple processes
>   and contexts is considered to follow the 

Re: [PATCH xrandr v5 0/6] xrandr: improve option parsing and documentation

2018-02-27 Thread Alex Deucher
On Tue, Feb 27, 2018 at 6:20 AM, Giuseppe Bilotta
 wrote:
> Miscellaneous patches to improve option parsing and documentation for
> xrandr.
>
> Allow single values to be given to --scale and --gamma, rejecting the
> option if valid values are followed by extra junk (e.g. 2x3a isn't
> accepted as a valid value for --scale), or if they are not positive.
>
> Minor improvements to the documentation are also introduced, the largest
> of which is the documentation of the xrandr monitor options.
>
> v2: rebased on current head.
> v3: fix code indentation, add grammar fix patch
> v4: single value accepted for --gamma too, monitor options documented
> v5: additional patch to check for positive values
>
> The patchset is also available from:
>
>   git://git.oblomov.eu/xorg/xrandr parse-doc-fixes
>
> up to c9755465412cbcf533d3c512397773949a26e55f.

For the series:
Reviewed-by: Alex Deucher 

>
>
> Giuseppe Bilotta (6):
>   xrandr: allow a single value for --scale
>   xrandr: stricter --scale argument parsing
>   xrandr.man: grammar tuning
>   xrandr: allow single value for --gamma
>   xrandr.man: document the monitor manipulation options
>   xrandr: gamma and scaling factors must be positive
>
>  man/xrandr.man | 46 +-
>  xrandr.c   | 31 ---
>  2 files changed, 61 insertions(+), 16 deletions(-)
>
> --
> 2.14.1.439.g647b9b4702
>
> ___
> xorg-devel@lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: https://lists.x.org/mailman/listinfo/xorg-devel
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

Re: [PATCH xserver 5/7] Add RandR leases with modesetting driver support [v6]

2018-02-27 Thread Keith Packard
Adam Jackson  writes:

> On Mon, 2018-02-12 at 13:51 -0800, Keith Packard wrote:
>
>> +static void
>> +drmmode_validate_leases(ScrnInfoPtr scrn)
>> +{
>> +ScreenPtr screen = scrn->pScreen;
>> +rrScrPrivPtr scr_priv = rrGetScrPriv(screen);
>> +modesettingPtr ms = modesettingPTR(scrn);
>> +drmmode_ptr drmmode = >drmmode;
>> +drmModeLesseeListPtr lessees;
>> +RRLeasePtr lease, next;
>> +int l;
>> +
>> +/* We can't talk to the kernel about leases when VT switched */
>> +if (!scrn->vtSema)
>> +return;
>> +
>> +lessees = drmModeListLessees(drmmode->fd);
>> +if (!lessees)
>> +return;
>
> This is new in libdrm 2.4.89, but we're still only requiring >= 2.3.1
> (lulz). I've bumped the requirement in configure.ac and meson.build.
>
> In 2/7, you begin using a #define from randrproto 1.6 without requiring
> it; I've fixed that too.
>
> With those changes, merged 1-5 of this series:
>
> remote: I: patch #204074 updated using rev 
> fabbaa8d6260da14fe5b7ca0f3f8748af16253a2.
> remote: E: failed to find patch for rev 
> b91c787c4cd2d20685db69426c539938c556128a.
> remote: I: patch #192311 updated using rev 
> 39573605050f6253d14a4786bb79ce2b48537039.
> remote: I: patch #204071 updated using rev 
> 023d4aba8d45e9e3630b944ecfb650c081799b96.
> remote: E: failed to find patch for rev 
> e4e3447603b5fd3a38a92c3f972396d1f81168ad.
> remote: I: 3 patch(es) updated to state Accepted.
> To ssh://git.freedesktop.org/git/xorg/xserver
>80d4f4b6c2..e4e3447603  master -> master
>
> I didn't merge 6/7 because libxcb has the following dumbness:
>
> desoxy:~% pkg-config --modversion xcb-randr
> 1.12

Yeah, I'll do a 1.13 release of libxcb with the necessary bits, then set the
required version in this patch to match.

> That is, of course, the libxcb version number, not a reflection of the
> randr protocol it supports. I don't have a good solution for that yet.
> At any rate it would break the build for people without git-fresh xcb
> bits, so it's left out for now.

Sounds good.

> Likewise I didn't merge 7/7 because you'd said you would change it to a
> command line option.

Yup, got lots of stuff to do today!

-- 
-keith


signature.asc
Description: PGP signature
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

Re: [PATCH xserver] protocol.txt: add GLX req. 35 - SetClientInfo2ARB

2018-02-27 Thread Adam Jackson
On Tue, 2018-02-27 at 17:05 +, Emil Velikov wrote:
> From: Emil Velikov 
> 
> Noticed while skimming for the typo'd version ;-)
> 
> Signed-off-by: Emil Velikov 

Nice catch. Merged, thanks:

remote: I: patch #207149 updated using rev 
85ff1cdbd3286838e512fe7c70af149a8743b6fe.
remote: I: 1 patch(es) updated to state Accepted.
To ssh://git.freedesktop.org/git/xorg/xserver
   e4e3447603..85ff1cdbd3  master -> master

- ajax
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

Re: [PATCH xserver 5/7] Add RandR leases with modesetting driver support [v6]

2018-02-27 Thread Adam Jackson
On Mon, 2018-02-12 at 13:51 -0800, Keith Packard wrote:

> +static void
> +drmmode_validate_leases(ScrnInfoPtr scrn)
> +{
> +ScreenPtr screen = scrn->pScreen;
> +rrScrPrivPtr scr_priv = rrGetScrPriv(screen);
> +modesettingPtr ms = modesettingPTR(scrn);
> +drmmode_ptr drmmode = >drmmode;
> +drmModeLesseeListPtr lessees;
> +RRLeasePtr lease, next;
> +int l;
> +
> +/* We can't talk to the kernel about leases when VT switched */
> +if (!scrn->vtSema)
> +return;
> +
> +lessees = drmModeListLessees(drmmode->fd);
> +if (!lessees)
> +return;

This is new in libdrm 2.4.89, but we're still only requiring >= 2.3.1
(lulz). I've bumped the requirement in configure.ac and meson.build.

In 2/7, you begin using a #define from randrproto 1.6 without requiring
it; I've fixed that too.

With those changes, merged 1-5 of this series:

remote: I: patch #204074 updated using rev 
fabbaa8d6260da14fe5b7ca0f3f8748af16253a2.
remote: E: failed to find patch for rev 
b91c787c4cd2d20685db69426c539938c556128a.
remote: I: patch #192311 updated using rev 
39573605050f6253d14a4786bb79ce2b48537039.
remote: I: patch #204071 updated using rev 
023d4aba8d45e9e3630b944ecfb650c081799b96.
remote: E: failed to find patch for rev 
e4e3447603b5fd3a38a92c3f972396d1f81168ad.
remote: I: 3 patch(es) updated to state Accepted.
To ssh://git.freedesktop.org/git/xorg/xserver
   80d4f4b6c2..e4e3447603  master -> master

I didn't merge 6/7 because libxcb has the following dumbness:

desoxy:~% pkg-config --modversion xcb-randr
1.12

That is, of course, the libxcb version number, not a reflection of the
randr protocol it supports. I don't have a good solution for that yet.
At any rate it would break the build for people without git-fresh xcb
bits, so it's left out for now.

Likewise I didn't merge 7/7 because you'd said you would change it to a
command line option.

- ajax
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

[PATCH xserver] protocol.txt: add GLX req. 35 - SetClientInfo2ARB

2018-02-27 Thread Emil Velikov
From: Emil Velikov 

Noticed while skimming for the typo'd version ;-)

Signed-off-by: Emil Velikov 
---
 dix/protocol.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/dix/protocol.txt b/dix/protocol.txt
index 244556a08..a1bf93652 100644
--- a/dix/protocol.txt
+++ b/dix/protocol.txt
@@ -149,6 +149,7 @@ R031 GLX:CreateWindow
 R032 GLX:DeleteWindow
 R033 GLX:SetClientInfoARB
 R034 GLX:CreateContextAttribsARB
+R035 GLX:SetClientInfo2ARB
 R101 GLX:NewList
 R102 GLX:EndList
 R103 GLX:DeleteLists
-- 
2.16.0

___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

[RFC xserver v7 11/14] glamor: Implement PixmapFromBuffers and BuffersFromPixmap

2018-02-27 Thread Louis-Francis Ratté-Boulianne
It relies on GBM >= 17.1.0 where we can import BO with multiple
planes and a format modifier (GBM_BO_IMPORT_FD_MODIFIER).

v2: Properly free fds in Xwayland

Signed-off-by: Louis-Francis Ratté-Boulianne 
Reviewed-by: Daniel Stone 
---
 configure.ac  |   4 +
 glamor/glamor.c   |  37 ---
 glamor/glamor.h   |  65 +++--
 glamor/glamor_egl.c   | 136 ++
 glamor/glamor_egl.h   |   1 +
 glamor/glamor_egl_ext.h   |  65 +
 glamor/glamor_egl_stubs.c |  16 ++-
 hw/xwayland/.gitignore|   2 +
 hw/xwayland/Makefile.am   |  10 +-
 hw/xwayland/meson.build   |   5 +-
 hw/xwayland/xwayland-glamor.c | 219 --
 hw/xwayland/xwayland.c|   6 +-
 hw/xwayland/xwayland.h|  10 +-
 include/dix-config.h.in   |   3 +
 include/meson.build   |   2 +
 15 files changed, 461 insertions(+), 120 deletions(-)
 create mode 100644 glamor/glamor_egl_ext.h

diff --git a/configure.ac b/configure.ac
index 7f54f780a..a4d729c94 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2100,6 +2100,10 @@ if test "x$GLAMOR" = xyes; then
[AC_DEFINE(GLAMOR_HAS_GBM_LINEAR, 1, [Have 
GBM_BO_USE_LINEAR])], [],
[#include 
 #include ])
+   dnl 17.1.0 is required for gbm_bo_create_with_modifiers
+   PKG_CHECK_EXISTS(gbm >= 17.1.0,
+[AC_DEFINE(GBM_BO_WITH_MODIFIERS, 1, [Have 
gbm_bo_create_with_modifiers])],
+[])
else
if test "x$XORG" = xyes; then
AC_MSG_ERROR([Glamor for Xorg requires $LIBGBM])
diff --git a/glamor/glamor.c b/glamor/glamor.c
index 4a41fe783..c4f6bcbf9 100644
--- a/glamor/glamor.c
+++ b/glamor/glamor.c
@@ -32,6 +32,7 @@
  */
 
 #include 
+#include 
 
 #include "glamor_priv.h"
 #include "mipict.h"
@@ -793,8 +794,9 @@ glamor_supports_pixmap_import_export(ScreenPtr screen)
 }
 
 _X_EXPORT int
-glamor_fd_from_pixmap(ScreenPtr screen,
-  PixmapPtr pixmap, CARD16 *stride, CARD32 *size)
+glamor_fds_from_pixmap(ScreenPtr screen, PixmapPtr pixmap, int *fds,
+   uint32_t *strides, uint32_t *offsets,
+   uint64_t *modifier)
 {
 glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap);
 glamor_screen_private *glamor_priv =
@@ -807,10 +809,9 @@ glamor_fd_from_pixmap(ScreenPtr screen,
 case GLAMOR_TEXTURE_ONLY:
 if (!glamor_pixmap_ensure_fbo(pixmap, GL_RGBA, 0))
 return -1;
-return glamor_egl_dri3_fd_name_from_tex(screen,
-pixmap,
-pixmap_priv->fbo->tex,
-FALSE, stride, size);
+return glamor_egl_fds_from_pixmap(screen, pixmap, fds,
+  strides, offsets,
+  modifier);
 default:
 break;
 }
@@ -823,6 +824,9 @@ glamor_shareable_fd_from_pixmap(ScreenPtr screen,
 {
 unsigned orig_usage_hint = pixmap->usage_hint;
 int ret;
+int fds[4];
+uint32_t strides[4], offsets[4];
+uint64_t modifier;
 
 /*
  * The actual difference between a sharable and non sharable buffer
@@ -831,7 +835,20 @@ glamor_shareable_fd_from_pixmap(ScreenPtr screen,
  * 2 of those calls are also exported API, so we cannot just add a flag.
  */
 pixmap->usage_hint = CREATE_PIXMAP_USAGE_SHARED;
-ret = glamor_fd_from_pixmap(screen, pixmap, stride, size);
+ret = glamor_fds_from_pixmap(screen, pixmap, fds, strides, offsets,
+ );
+
+/* Pixmaps with multi-planes/modifier are not shareable */
+if (ret > 1) {
+while (ret > 0)
+close(fds[--ret]);
+return -1;
+}
+
+ret = fds[0];
+*stride = strides[0];
+*size = pixmap->drawable.height * *stride;
+
 pixmap->usage_hint = orig_usage_hint;
 
 return ret;
@@ -847,10 +864,8 @@ glamor_name_from_pixmap(PixmapPtr pixmap, CARD16 *stride, 
CARD32 *size)
 case GLAMOR_TEXTURE_ONLY:
 if (!glamor_pixmap_ensure_fbo(pixmap, GL_RGBA, 0))
 return -1;
-return glamor_egl_dri3_fd_name_from_tex(pixmap->drawable.pScreen,
-pixmap,
-pixmap_priv->fbo->tex,
-TRUE, stride, size);
+return glamor_egl_fd_name_from_pixmap(pixmap->drawable.pScreen,
+  pixmap, stride, size);
 default:
 break;
 }
diff --git a/glamor/glamor.h b/glamor/glamor.h
index 5b15a46e5..8f8c31b45 100644
--- a/glamor/glamor.h
+++ b/glamor/glamor.h
@@ -138,15 +138,17 

[RFC xserver v7 09/14] modesetting: Create scanout buffers using supported modifiers

2018-02-27 Thread Louis-Francis Ratté-Boulianne
Use most optimal buffer format (e.g. tiled/compressed) available
for scanout.

v2: Don't use multi-plane modifier to create scanout buffer

v3: Add flag to retrieve modifiers set from enabled CRTCs only

v4: Fix uses when GBM/EGL driver doesn't support modifiers

Signed-off-by: Louis-Francis Ratté-Boulianne 
Reviewed-by: Daniel Stone 
---
 hw/xfree86/drivers/modesetting/drmmode_display.c | 79 
 1 file changed, 79 insertions(+)

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c 
b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 4a60f93b2..a0d32a094 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -73,6 +73,68 @@ modifiers_ptr(struct drm_format_modifier_blob *blob)
 
 #endif
 
+#ifdef GBM_BO_WITH_MODIFIERS
+static uint32_t
+get_modifiers_set(ScrnInfoPtr scrn, uint32_t format, uint64_t **modifiers,
+  Bool enabled_crtc_only, Bool exclude_multiplane)
+{
+xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+modesettingPtr ms = modesettingPTR(scrn);
+drmmode_ptr drmmode = >drmmode;
+int c, i, j, k, count_modifiers = 0;
+uint64_t *tmp, *ret = NULL;
+
+*modifiers = NULL;
+for (c = 0; c < xf86_config->num_crtc; c++) {
+xf86CrtcPtr crtc = xf86_config->crtc[c];
+drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+
+if (enabled_crtc_only && !crtc->enabled)
+continue;
+
+for (i = 0; i < drmmode_crtc->num_formats; i++) {
+drmmode_format_ptr iter = _crtc->formats[i];
+
+if (iter->format != format)
+continue;
+
+for (j = 0; j < iter->num_modifiers; j++) {
+Bool found = FALSE;
+
+   /* Don't choose multi-plane formats for our screen pixmap.
+* These will get used with frontbuffer rendering, which will
+* lead to worse-than-tearing with multi-plane formats, as the
+* primary and auxiliary planes go out of sync. */
+   if (exclude_multiplane &&
+gbm_device_get_format_modifier_plane_count(drmmode->gbm,
+   format,
+   
iter->modifiers[j]) > 1) {
+continue;
+}
+
+for (k = 0; k < count_modifiers; k++) {
+if (iter->modifiers[j] == ret[k])
+found = TRUE;
+}
+if (!found) {
+count_modifiers++;
+tmp = realloc(ret, count_modifiers * sizeof(uint64_t));
+if (!tmp) {
+free(ret);
+return 0;
+}
+ret = tmp;
+ret[count_modifiers - 1] = iter->modifiers[j];
+}
+}
+}
+}
+
+*modifiers = ret;
+return count_modifiers;
+}
+#endif
+
 static Bool
 drmmode_zaphod_string_matches(ScrnInfoPtr scrn, const char *s, char 
*output_name)
 {
@@ -598,6 +660,23 @@ drmmode_create_bo(drmmode_ptr drmmode, drmmode_bo *bo,
 
 #ifdef GLAMOR_HAS_GBM
 if (drmmode->glamor) {
+#ifdef GBM_BO_WITH_MODIFIERS
+uint32_t num_modifiers;
+uint64_t *modifiers = NULL;
+
+num_modifiers = get_modifiers_set(drmmode->scrn, DRM_FORMAT_ARGB,
+  , FALSE, TRUE);
+if (num_modifiers > 0 &&
+!(num_modifiers == 1 && modifiers[0] == DRM_FORMAT_MOD_INVALID)) {
+bo->gbm = gbm_bo_create_with_modifiers(drmmode->gbm, width, height,
+   GBM_FORMAT_ARGB,
+   modifiers, num_modifiers);
+free(modifiers);
+if (bo->gbm)
+return TRUE;
+}
+#endif
+
 bo->gbm = gbm_bo_create(drmmode->gbm, width, height,
 GBM_FORMAT_ARGB,
 GBM_BO_USE_RENDERING | GBM_BO_USE_SCANOUT);
-- 
2.14.3

___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

[RFC xserver v7 05/14] modesetting: Use atomic modesetting API for pageflip if available

2018-02-27 Thread Louis-Francis Ratté-Boulianne
In order to flip between compressed and uncompressed buffers -
something drmModePageFlip explicitly bans us from doing - we need
to port use the atomic modesetting API. It's only 'fake' atomic
though given we still commit for each CRTC separately and
CRTC and connector properties are not set with the atomic API.

The helper functions to retrieve DRM properties have been borrowed
from Weston.

Signed-off-by: Louis-Francis Ratté-Boulianne 
Reviewed-by: Daniel Stone 
---
 configure.ac |   3 +
 hw/xfree86/drivers/modesetting/driver.c  |   6 +
 hw/xfree86/drivers/modesetting/driver.h  |   1 +
 hw/xfree86/drivers/modesetting/drmmode_display.c | 374 ++-
 hw/xfree86/drivers/modesetting/drmmode_display.h |  36 +++
 hw/xfree86/drivers/modesetting/pageflip.c|  22 +-
 include/dix-config.h.in  |   3 +
 include/meson.build  |   2 +
 8 files changed, 443 insertions(+), 4 deletions(-)

diff --git a/configure.ac b/configure.ac
index e4fd4c375..8a2953197 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2106,6 +2106,9 @@ if test "x$GLAMOR" = xyes; then
fi
fi
 
+   PKG_CHECK_EXISTS(libdrm >= 2.4.62,
+[AC_DEFINE(GLAMOR_HAS_DRM_ATOMIC, 1, [libdrm supports 
atomic API])],
+[])
PKG_CHECK_EXISTS(libdrm >= 2.4.74,
 [AC_DEFINE(GLAMOR_HAS_DRM_NAME_FROM_FD_2, 1, [Have 
GLAMOR_HAS_DRM_NAME_FROM_FD_2])],
 [])
diff --git a/hw/xfree86/drivers/modesetting/driver.c 
b/hw/xfree86/drivers/modesetting/driver.c
index e057970a6..28cf03648 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -1017,6 +1017,12 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 }
 #endif
 
+#ifdef GLAMOR_HAS_DRM_ATOMIC
+ret = drmSetClientCap(ms->fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1);
+ret |= drmSetClientCap(ms->fd, DRM_CLIENT_CAP_ATOMIC, 1);
+ms->atomic_modeset = (ret == 0);
+#endif
+
 if (drmmode_pre_init(pScrn, >drmmode, pScrn->bitsPerPixel / 8) == 
FALSE) {
 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "KMS setup failed\n");
 goto fail;
diff --git a/hw/xfree86/drivers/modesetting/driver.h 
b/hw/xfree86/drivers/modesetting/driver.h
index fe835918b..ed32239db 100644
--- a/hw/xfree86/drivers/modesetting/driver.h
+++ b/hw/xfree86/drivers/modesetting/driver.h
@@ -105,6 +105,7 @@ typedef struct _modesettingRec {
  * Page flipping stuff.
  *  @{
  */
+Bool atomic_modeset;
 /** @} */
 
 DamagePtr damage;
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c 
b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 9c3856378..d82faa010 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -75,6 +75,233 @@ drmmode_zaphod_string_matches(ScrnInfoPtr scrn, const char 
*s, char *output_name
 return ret;
 }
 
+static uint64_t
+drmmode_prop_get_value(drmmode_prop_info_ptr info,
+   drmModeObjectPropertiesPtr props,
+   uint64_t def)
+{
+unsigned int i;
+
+if (info->prop_id == 0)
+return def;
+
+for (i = 0; i < props->count_props; i++) {
+unsigned int j;
+
+if (props->props[i] != info->prop_id)
+continue;
+
+/* Simple (non-enum) types can return the value directly */
+if (info->num_enum_values == 0)
+return props->prop_values[i];
+
+/* Map from raw value to enum value */
+for (j = 0; j < info->num_enum_values; j++) {
+if (!info->enum_values[j].valid)
+continue;
+if (info->enum_values[j].value != props->prop_values[i])
+continue;
+
+return j;
+}
+}
+
+return def;
+}
+
+static uint32_t
+drmmode_prop_info_update(drmmode_ptr drmmode,
+ drmmode_prop_info_ptr info,
+ unsigned int num_infos,
+ drmModeObjectProperties *props)
+{
+drmModePropertyRes *prop;
+uint32_t valid_mask = 0;
+unsigned i, j;
+
+assert(num_infos <= 32 && "update return type");
+
+for (i = 0; i < props->count_props; i++) {
+Bool props_incomplete = FALSE;
+unsigned int k;
+
+for (j = 0; j < num_infos; j++) {
+if (info[j].prop_id == props->props[i])
+break;
+if (!info[j].prop_id)
+props_incomplete = TRUE;
+}
+
+/* We've already discovered this property. */
+if (j != num_infos)
+continue;
+
+/* We haven't found this property ID, but as we've already
+ * found all known properties, we don't need to look any
+ * further. */
+if (!props_incomplete)
+break;
+
+prop = 

[RFC xserver v7 12/14] glamor: Implement GetSupportedModifiers

2018-02-27 Thread Louis-Francis Ratté-Boulianne
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 
Reviewed-by: Daniel Stone 
---
 configure.ac |   4 +
 glamor/glamor.c  |  25 +
 glamor/glamor.h  |  23 
 glamor/glamor_egl.c  |  92 +++
 glamor/glamor_priv.h |   1 +
 glamor/meson.build   |   4 +-
 hw/kdrive/ephyr/meson.build  |   1 +
 hw/xfree86/common/xf86Mode.c |   1 +
 hw/xfree86/drivers/modesetting/driver.c  |  12 +-
 hw/xfree86/drivers/modesetting/drmmode_display.c |  38 +++
 hw/xfree86/drivers/modesetting/drmmode_display.h |   1 +
 hw/xwayland/xwayland-glamor.c| 135 ---
 hw/xwayland/xwayland.h   |   9 +-
 include/dix-config.h.in  |   3 +
 include/meson.build  |   2 +
 meson.build  |   4 +-
 present/present.c|  38 +++
 present/present.h|   3 +
 18 files changed, 372 insertions(+), 24 deletions(-)

diff --git a/configure.ac b/configure.ac
index a4d729c94..a5413792c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2092,6 +2092,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,
diff --git a/glamor/glamor.c b/glamor/glamor.c
index c4f6bcbf9..1559310db 100644
--- a/glamor/glamor.c
+++ b/glamor/glamor.c
@@ -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,
diff --git a/glamor/glamor.h b/glamor/glamor.h
index 8f8c31b45..5475aedbb 100644
--- a/glamor/glamor.h
+++ b/glamor/glamor.h
@@ -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,
+

[RFC xserver v7 03/14] dri3: Add multi-planar/modifier buffer requests

2018-02-27 Thread Louis-Francis Ratté-Boulianne
Initial implementation for DRI3 v1.1. Only the DRI3 implementation
is there, backends need to implement the proper hooks.

Version is still set to 1.0 so clients shouldn't use the new
requests yet.

v2: Use depth/bpp instead of DRM formats in requests

v3: Remove DMA fence requests from v1.1
Add screen/drawable modifier sets

v4: Free array returned by 'get_drawable_modifiers()'

v5: Fix FD leak

Signed-off-by: Daniel Stone 
Signed-off-by: Louis-Francis Ratté-Boulianne 
---
 configure.ac  |   2 +-
 dri3/dri3.c   |  19 +++
 dri3/dri3.h   |  44 ++-
 dri3/dri3_priv.h  |  27 +++-
 dri3/dri3_request.c   | 293 --
 dri3/dri3_screen.c| 196 ++--
 hw/xwayland/xwayland-glamor.c |   4 +-
 meson.build   |   2 +-
 8 files changed, 558 insertions(+), 29 deletions(-)

diff --git a/configure.ac b/configure.ac
index c1f389c1e..2420266dd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -729,7 +729,7 @@ SCRNSAVERPROTO="scrnsaverproto >= 1.1"
 RESOURCEPROTO="resourceproto >= 1.2.0"
 DRIPROTO="xf86driproto >= 2.1.0"
 DRI2PROTO="dri2proto >= 2.8"
-DRI3PROTO="dri3proto >= 1.0"
+DRI3PROTO="dri3proto >= 1.1"
 XINERAMAPROTO="xineramaproto"
 BIGFONTPROTO="xf86bigfontproto >= 1.2.0"
 DGAPROTO="xf86dgaproto >= 2.0.99.1"
diff --git a/dri3/dri3.c b/dri3/dri3.c
index d042b8b7d..8ac0f3ae2 100644
--- a/dri3/dri3.c
+++ b/dri3/dri3.c
@@ -26,6 +26,8 @@
 
 #include "dri3_priv.h"
 
+#include 
+
 static int dri3_request;
 DevPrivateKeyRec dri3_screen_private_key;
 
@@ -99,3 +101,20 @@ dri3_extension_init(void)
 bail:
 FatalError("Cannot initialize DRI3 extension");
 }
+
+uint32_t
+drm_format_for_depth(uint32_t depth, uint32_t bpp)
+{
+switch (bpp) {
+case 16:
+return DRM_FORMAT_RGB565;
+case 24:
+return DRM_FORMAT_XRGB;
+case 30:
+return DRM_FORMAT_XRGB2101010;
+case 32:
+return DRM_FORMAT_ARGB;
+default:
+return 0;
+}
+}
diff --git a/dri3/dri3.h b/dri3/dri3.h
index 7562352ff..89ad13ad9 100644
--- a/dri3/dri3.h
+++ b/dri3/dri3.h
@@ -28,7 +28,7 @@
 #include 
 #include 
 
-#define DRI3_SCREEN_INFO_VERSION1
+#define DRI3_SCREEN_INFO_VERSION2
 
 typedef int (*dri3_open_proc)(ScreenPtr screen,
   RRProviderPtr provider,
@@ -47,11 +47,43 @@ typedef PixmapPtr (*dri3_pixmap_from_fd_proc) (ScreenPtr 
screen,
CARD8 depth,
CARD8 bpp);
 
+typedef PixmapPtr (*dri3_pixmap_from_fds_proc) (ScreenPtr screen,
+CARD8 num_fds,
+int *fds,
+CARD16 width,
+CARD16 height,
+CARD32 *strides,
+CARD32 *offsets,
+CARD8 depth,
+CARD8 bpp,
+CARD64 modifier);
+
 typedef int (*dri3_fd_from_pixmap_proc) (ScreenPtr screen,
  PixmapPtr pixmap,
  CARD16 *stride,
  CARD32 *size);
 
+typedef int (*dri3_fds_from_pixmap_proc) (ScreenPtr screen,
+  PixmapPtr pixmap,
+  int *fds,
+  CARD32 *strides,
+  CARD32 *offsets,
+  CARD64 *modifier);
+
+typedef int (*dri3_get_formats_proc) (ScreenPtr screen,
+  CARD32 *num_formats,
+  CARD32 **formats);
+
+typedef int (*dri3_get_modifiers_proc) (ScreenPtr screen,
+CARD32 format,
+CARD32 *num_modifiers,
+CARD64 **modifiers);
+
+typedef int (*dri3_get_drawable_modifiers_proc) (DrawablePtr draw,
+ CARD32 format,
+ CARD32 *num_modifiers,
+ CARD64 **modifiers);
+
 typedef struct dri3_screen_info {
 uint32_tversion;
 
@@ -62,6 +94,13 @@ typedef struct dri3_screen_info {
 /* Version 1 */
 dri3_open_client_proc   open_client;
 
+/* Version 2 */
+dri3_pixmap_from_fds_proc   pixmap_from_fds;
+dri3_fds_from_pixmap_proc   fds_from_pixmap;
+dri3_get_formats_proc   get_formats;

[RFC xserver v7 10/14] modesetting: Check if buffer format is supported when flipping

2018-02-27 Thread Louis-Francis Ratté-Boulianne
Add support for 'check_flip2' so that the present core can know
why it is impossible to flip in that scenario. The core can then
let know the client that the buffer format/modifier is suboptimal.

v2: No longer need to implement 'check_flip'

Signed-off-by: Louis-Francis Ratté-Boulianne 
Reviewed-by: Daniel Stone 
---
 hw/xfree86/drivers/modesetting/drmmode_display.c | 42 
 hw/xfree86/drivers/modesetting/drmmode_display.h |  2 ++
 hw/xfree86/drivers/modesetting/present.c | 30 ++---
 3 files changed, 70 insertions(+), 4 deletions(-)

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c 
b/hw/xfree86/drivers/modesetting/drmmode_display.c
index a0d32a094..3408084ab 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -73,6 +73,48 @@ modifiers_ptr(struct drm_format_modifier_blob *blob)
 
 #endif
 
+Bool
+drmmode_is_format_supported(ScrnInfoPtr scrn, uint32_t format, uint64_t 
modifier)
+{
+xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+int c, i, j;
+
+for (c = 0; c < xf86_config->num_crtc; c++) {
+xf86CrtcPtr crtc = xf86_config->crtc[c];
+drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+Bool found = FALSE;
+
+if (!crtc->enabled)
+continue;
+
+for (i = 0; i < drmmode_crtc->num_formats; i++) {
+drmmode_format_ptr iter = _crtc->formats[i];
+
+if (iter->format != format)
+continue;
+
+if (modifier == 0) {
+found = TRUE;
+break;
+}
+
+for (j = 0; j < iter->num_modifiers; j++) {
+if (iter->modifiers[j] == modifier) {
+found = TRUE;
+break;
+}
+}
+
+break;
+}
+
+if (!found)
+return FALSE;
+}
+
+return TRUE;
+}
+
 #ifdef GBM_BO_WITH_MODIFIERS
 static uint32_t
 get_modifiers_set(ScrnInfoPtr scrn, uint32_t format, uint64_t **modifiers,
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h 
b/hw/xfree86/drivers/modesetting/drmmode_display.h
index ce36e9092..52015c5df 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.h
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.h
@@ -234,6 +234,8 @@ extern DevPrivateKeyRec msPixmapPrivateKeyRec;
 
 #define msGetPixmapPriv(drmmode, p) 
((msPixmapPrivPtr)dixGetPrivateAddr(&(p)->devPrivates, 
&(drmmode)->pixmapPrivateKeyRec))
 
+Bool drmmode_is_format_supported(ScrnInfoPtr scrn, uint32_t format,
+ uint64_t modifier);
 int drmmode_bo_import(drmmode_ptr drmmode, drmmode_bo *bo,
   uint32_t *fb_id);
 int drmmode_bo_destroy(drmmode_ptr drmmode, drmmode_bo *bo);
diff --git a/hw/xfree86/drivers/modesetting/present.c 
b/hw/xfree86/drivers/modesetting/present.c
index 4a01d19ea..71ef2f7f1 100644
--- a/hw/xfree86/drivers/modesetting/present.c
+++ b/hw/xfree86/drivers/modesetting/present.c
@@ -214,7 +214,8 @@ static Bool
 ms_present_check_flip(RRCrtcPtr crtc,
   WindowPtr window,
   PixmapPtr pixmap,
-  Bool sync_flip)
+  Bool sync_flip,
+  PresentFlipReason *reason)
 {
 ScreenPtr screen = window->drawable.pScreen;
 ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
@@ -222,6 +223,9 @@ ms_present_check_flip(RRCrtcPtr crtc,
 xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn);
 int num_crtcs_on = 0;
 int i;
+#ifdef GLAMOR_HAS_DRM_MODIFIERS
+struct gbm_bo *gbm;
+#endif
 
 if (!ms->drmmode.pageflip)
 return FALSE;
@@ -252,6 +256,23 @@ ms_present_check_flip(RRCrtcPtr crtc,
 pixmap->devKind != drmmode_bo_get_pitch(>drmmode.front_bo))
 return FALSE;
 
+#ifdef GLAMOR_HAS_DRM_MODIFIERS
+/* Check if buffer format/modifier is supported by all active CRTCs */
+gbm = glamor_gbm_bo_from_pixmap(screen, pixmap);
+if (gbm) {
+uint32_t format;
+uint64_t modifier;
+
+format = gbm_bo_get_format(gbm);
+modifier = gbm_bo_get_modifier(gbm);
+if (!drmmode_is_format_supported(scrn, format, modifier)) {
+if (reason)
+*reason = PRESENT_FLIP_REASON_BUFFER_FORMAT;
+return FALSE;
+}
+}
+#endif
+
 /* Make sure there's a bo we can get to */
 /* XXX: actually do this.  also...is it sufficient?
  * if (!glamor_get_pixmap_private(pixmap))
@@ -280,7 +301,7 @@ ms_present_flip(RRCrtcPtr crtc,
 Bool ret;
 struct ms_present_vblank_event *event;
 
-if (!ms_present_check_flip(crtc, screen->root, pixmap, sync_flip))
+if (!ms_present_check_flip(crtc, screen->root, pixmap, sync_flip, NULL))
 return FALSE;
 
 event = calloc(1, sizeof(struct ms_present_vblank_event));
@@ -323,7 +344,7 @@ 

[RFC xserver v7 13/14] glamor: Use gbm_bo_create_with_modifiers for internal pixmap allocation

2018-02-27 Thread Louis-Francis Ratté-Boulianne
Using modifier might allow the driver to use a more optimal format
(e.g. tiled/compressed). Let's try to use those if possible.

v2: Don't filter out multi-plane modifiers

Signed-off-by: Louis-Francis Ratté-Boulianne 
Reviewed-by: Daniel Stone 
---
 glamor/glamor_egl.c   | 28 +++-
 hw/xwayland/xwayland-glamor.c | 22 +++---
 2 files changed, 42 insertions(+), 8 deletions(-)

diff --git a/glamor/glamor_egl.c b/glamor/glamor_egl.c
index e22bc1f6a..25abc0527 100644
--- a/glamor/glamor_egl.c
+++ b/glamor/glamor_egl.c
@@ -270,13 +270,31 @@ glamor_make_pixmap_exportable(PixmapPtr pixmap)
 return FALSE;
 }
 
-bo = gbm_bo_create(glamor_egl->gbm, width, height,
-   GBM_FORMAT_ARGB,
+#ifdef GBM_BO_WITH_MODIFIERS
+if (glamor_egl->dmabuf_capable) {
+uint32_t num_modifiers;
+uint64_t *modifiers = NULL;
+
+glamor_get_modifiers(screen, DRM_FORMAT_ARGB,
+ _modifiers, );
+
+bo = gbm_bo_create_with_modifiers(glamor_egl->gbm, width, height,
+  GBM_FORMAT_ARGB,
+  modifiers, num_modifiers);
+free(modifiers);
+}
+else
+#endif
+{
+bo = gbm_bo_create(glamor_egl->gbm, width, height,
+GBM_FORMAT_ARGB,
 #ifdef GLAMOR_HAS_GBM_LINEAR
-   (pixmap->usage_hint == CREATE_PIXMAP_USAGE_SHARED ?
-GBM_BO_USE_LINEAR : 0) |
+(pixmap->usage_hint == CREATE_PIXMAP_USAGE_SHARED ?
+ GBM_BO_USE_LINEAR : 0) |
 #endif
-   GBM_BO_USE_RENDERING | GBM_BO_USE_SCANOUT);
+GBM_BO_USE_RENDERING | GBM_BO_USE_SCANOUT);
+}
+
 if (!bo) {
 xf86DrvMsg(scrn->scrnIndex, X_ERROR,
"Failed to make %dx%dx%dbpp GBM bo\n",
diff --git a/hw/xwayland/xwayland-glamor.c b/hw/xwayland/xwayland-glamor.c
index 72e2625fb..b961695d7 100644
--- a/hw/xwayland/xwayland-glamor.c
+++ b/hw/xwayland/xwayland-glamor.c
@@ -227,14 +227,30 @@ xwl_glamor_create_pixmap(ScreenPtr screen,
 {
 struct xwl_screen *xwl_screen = xwl_screen_get(screen);
 struct gbm_bo *bo;
+uint32_t format;
 
 if (width > 0 && height > 0 && depth >= 15 &&
 (hint == 0 ||
  hint == CREATE_PIXMAP_USAGE_BACKING_PIXMAP ||
  hint == CREATE_PIXMAP_USAGE_SHARED)) {
-bo = gbm_bo_create(xwl_screen->gbm, width, height,
-   gbm_format_for_depth(depth),
-   GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING);
+format = gbm_format_for_depth(depth);
+
+#ifdef GBM_BO_WITH_MODIFIERS
+if (xwl_screen->dmabuf_capable) {
+uint32_t num_modifiers;
+uint64_t *modifiers = NULL;
+
+glamor_get_modifiers(screen, format, _modifiers, );
+bo = gbm_bo_create_with_modifiers(xwl_screen->gbm, width, height,
+  format, modifiers, 
num_modifiers);
+free(modifiers);
+}
+else
+#endif
+{
+bo = gbm_bo_create(xwl_screen->gbm, width, height, format,
+   GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING);
+}
 
 if (bo)
 return xwl_glamor_create_pixmap_for_bo(screen, bo, depth);
-- 
2.14.3

___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

[RFC xserver v7 14/14] dri3: Enable DRI3 version 1.1

2018-02-27 Thread Louis-Francis Ratté-Boulianne
Enable DRI3 v1.1 now that all functions have been implemented and
that there is at least one backend implementing the driver hooks
(modesetting/glamor).

Signed-off-by: Louis-Francis Ratté-Boulianne 
Reviewed-by: Daniel Stone 
---
 include/protocol-versions.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/protocol-versions.h b/include/protocol-versions.h
index fd8d8df88..3912ed5c7 100644
--- a/include/protocol-versions.h
+++ b/include/protocol-versions.h
@@ -48,7 +48,7 @@
 
 /* DRI3 */
 #define SERVER_DRI3_MAJOR_VERSION   1
-#define SERVER_DRI3_MINOR_VERSION   0
+#define SERVER_DRI3_MINOR_VERSION   1
 
 /* DMX */
 #define SERVER_DMX_MAJOR_VERSION   2
-- 
2.14.3

___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

[RFC xserver v7 06/14] modesetting: Add support for multi-plane pixmaps when page-flipping

2018-02-27 Thread Louis-Francis Ratté-Boulianne
This allows the uses of CCS compressed or tiled pixmaps as BOs when
page-flipping.

Signed-off-by: Louis-Francis Ratté-Boulianne 
Reviewed-by: Daniel Stone 
---
 hw/xfree86/drivers/modesetting/drmmode_display.c | 49 
 hw/xfree86/drivers/modesetting/drmmode_display.h |  4 ++
 hw/xfree86/drivers/modesetting/pageflip.c| 16 
 3 files changed, 62 insertions(+), 7 deletions(-)

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c 
b/hw/xfree86/drivers/modesetting/drmmode_display.c
index d82faa010..51851a9f9 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -39,6 +39,8 @@
 #include "micmap.h"
 #include "xf86cmap.h"
 #include "xf86DDC.h"
+#include 
+#include 
 
 #include 
 #include "xf86Crtc.h"
@@ -376,10 +378,57 @@ drmmode_bo_map(drmmode_ptr drmmode, drmmode_bo *bo)
 return bo->dumb->ptr;
 }
 
+int
+drmmode_bo_import(drmmode_ptr drmmode, drmmode_bo *bo,
+  uint32_t *fb_id)
+{
+#ifdef GBM_BO_WITH_MODIFIERS
+if (bo->gbm &&
+gbm_bo_get_modifier(bo->gbm) != DRM_FORMAT_MOD_INVALID) {
+int num_fds;
+
+num_fds = gbm_bo_get_plane_count(bo->gbm);
+if (num_fds > 0) {
+int i;
+uint32_t format;
+uint32_t handles[4];
+uint32_t strides[4];
+uint32_t offsets[4];
+uint64_t modifiers[4];
+
+memset(handles, 0, sizeof(handles));
+memset(strides, 0, sizeof(strides));
+memset(offsets, 0, sizeof(offsets));
+memset(modifiers, 0, sizeof(modifiers));
+
+format = gbm_bo_get_format(bo->gbm);
+for (i = 0; i < num_fds; i++) {
+handles[i] = gbm_bo_get_handle_for_plane(bo->gbm, i).u32;
+strides[i] = gbm_bo_get_stride_for_plane(bo->gbm, i);
+offsets[i] = gbm_bo_get_offset(bo->gbm, i);
+modifiers[i] = gbm_bo_get_modifier(bo->gbm);
+}
+
+return drmModeAddFB2WithModifiers(drmmode->fd, bo->width, 
bo->height,
+  format, handles, strides,
+  offsets, modifiers, fb_id,
+  DRM_MODE_FB_MODIFIERS);
+}
+}
+#endif
+return drmModeAddFB(drmmode->fd, bo->width, bo->height,
+drmmode->scrn->depth, drmmode->scrn->bitsPerPixel,
+drmmode_bo_get_pitch(bo),
+drmmode_bo_get_handle(bo), fb_id);
+}
+
 static Bool
 drmmode_create_bo(drmmode_ptr drmmode, drmmode_bo *bo,
   unsigned width, unsigned height, unsigned bpp)
 {
+bo->width = width;
+bo->height = height;
+
 #ifdef GLAMOR_HAS_GBM
 if (drmmode->glamor) {
 bo->gbm = gbm_bo_create(drmmode->gbm, width, height,
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h 
b/hw/xfree86/drivers/modesetting/drmmode_display.h
index 7e7ebb7f3..a76e9dc20 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.h
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.h
@@ -53,6 +53,8 @@ enum drmmode_plane_type {
 };
 
 typedef struct {
+uint32_t width;
+uint32_t height;
 struct dumb_bo *dumb;
 #ifdef GLAMOR_HAS_GBM
 struct gbm_bo *gbm;
@@ -195,6 +197,8 @@ extern DevPrivateKeyRec msPixmapPrivateKeyRec;
 
 #define msGetPixmapPriv(drmmode, p) 
((msPixmapPrivPtr)dixGetPrivateAddr(&(p)->devPrivates, 
&(drmmode)->pixmapPrivateKeyRec))
 
+int drmmode_bo_import(drmmode_ptr drmmode, drmmode_bo *bo,
+  uint32_t *fb_id);
 int drmmode_bo_destroy(drmmode_ptr drmmode, drmmode_bo *bo);
 uint32_t drmmode_bo_get_pitch(drmmode_bo *bo);
 uint32_t drmmode_bo_get_handle(drmmode_bo *bo);
diff --git a/hw/xfree86/drivers/modesetting/pageflip.c 
b/hw/xfree86/drivers/modesetting/pageflip.c
index dd296cd12..027ebfe42 100644
--- a/hw/xfree86/drivers/modesetting/pageflip.c
+++ b/hw/xfree86/drivers/modesetting/pageflip.c
@@ -258,6 +258,7 @@ ms_do_pageflip(ScreenPtr screen,
 
 new_front_bo.gbm = glamor_gbm_bo_from_pixmap(screen, new_front);
 new_front_bo.dumb = NULL;
+
 if (!new_front_bo.gbm) {
 xf86DrvMsg(scrn->scrnIndex, X_ERROR,
"Failed to get GBM bo for flip to new front.\n");
@@ -288,14 +289,12 @@ ms_do_pageflip(ScreenPtr screen,
 
 /* Create a new handle for the back buffer */
 flipdata->old_fb_id = ms->drmmode.fb_id;
-if (drmModeAddFB(ms->fd, scrn->virtualX, scrn->virtualY,
- scrn->depth, scrn->bitsPerPixel,
- drmmode_bo_get_pitch(_front_bo),
- drmmode_bo_get_handle(_front_bo), 
>drmmode.fb_id)) {
-goto error_out;
-}
 
-drmmode_bo_destroy(>drmmode, _front_bo);
+new_front_bo.width = new_front->drawable.width;
+new_front_bo.height = new_front->drawable.height;
+if 

[RFC xserver v7 08/14] modesetting: Get supported formats/modifiers for scanout

2018-02-27 Thread Louis-Francis Ratté-Boulianne
Retrieve IN_FORMATS property from the plane. It gives the
allowed formats and modifiers for BO allocation.

Signed-off-by: Louis-Francis Ratté-Boulianne 
Reviewed-by: Daniel Stone 
---
 configure.ac |   4 +
 hw/xfree86/drivers/modesetting/drmmode_display.c | 114 ++-
 hw/xfree86/drivers/modesetting/drmmode_display.h |   9 ++
 include/dix-config.h.in  |   3 +
 include/meson.build  |   2 +
 5 files changed, 128 insertions(+), 4 deletions(-)

diff --git a/configure.ac b/configure.ac
index 8a2953197..7f54f780a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2112,6 +2112,10 @@ if test "x$GLAMOR" = xyes; then
PKG_CHECK_EXISTS(libdrm >= 2.4.74,
 [AC_DEFINE(GLAMOR_HAS_DRM_NAME_FROM_FD_2, 1, [Have 
GLAMOR_HAS_DRM_NAME_FROM_FD_2])],
 [])
+
+   PKG_CHECK_EXISTS(libdrm >= 2.4.83,
+[AC_DEFINE(GLAMOR_HAS_DRM_MODIFIERS, 1, [Have 
GLAMOR_HAS_DRM_MODIFIERS])],
+[])
 fi
 AM_CONDITIONAL([GLAMOR_EGL], [test "x$GBM" = xyes])
 
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c 
b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 30e3b05db..4a60f93b2 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -56,6 +56,23 @@ static Bool drmmode_xf86crtc_resize(ScrnInfoPtr scrn, int 
width, int height);
 static PixmapPtr drmmode_create_pixmap_header(ScreenPtr pScreen, int width, 
int height,
   int depth, int bitsPerPixel, int 
devKind,
   void *pPixData);
+
+#ifdef GLAMOR_HAS_DRM_MODIFIERS
+
+static inline uint32_t *
+formats_ptr(struct drm_format_modifier_blob *blob)
+{
+return (uint32_t *)(((char *)blob) + blob->formats_offset);
+}
+
+static inline struct drm_format_modifier *
+modifiers_ptr(struct drm_format_modifier_blob *blob)
+{
+return (struct drm_format_modifier *)(((char *)blob) + 
blob->modifiers_offset);
+}
+
+#endif
+
 static Bool
 drmmode_zaphod_string_matches(ScrnInfoPtr scrn, const char *s, char 
*output_name)
 {
@@ -1531,15 +1548,76 @@ is_plane_assigned(ScrnInfoPtr scrn, int plane_id)
 return FALSE;
 }
 
+#ifdef GLAMOR_HAS_DRM_MODIFIERS
+/**
+ * Populates the formats array, and the modifiers of each format for a 
drm_plane.
+ */
+static Bool
+populate_format_modifiers(xf86CrtcPtr crtc, const drmModePlane *kplane,
+  uint32_t blob_id)
+{
+drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+drmmode_ptr drmmode = drmmode_crtc->drmmode;
+unsigned i, j;
+drmModePropertyBlobRes *blob;
+struct drm_format_modifier_blob *fmt_mod_blob;
+uint32_t *blob_formats;
+struct drm_format_modifier *blob_modifiers;
+
+blob = drmModeGetPropertyBlob(drmmode->fd, blob_id);
+if (!blob)
+return FALSE;
+
+fmt_mod_blob = blob->data;
+blob_formats = formats_ptr(fmt_mod_blob);
+blob_modifiers = modifiers_ptr(fmt_mod_blob);
+
+assert(drmmode_crtc->num_formats == fmt_mod_blob->count_formats);
+
+for (i = 0; i < fmt_mod_blob->count_formats; i++) {
+uint32_t num_modifiers = 0;
+uint64_t *modifiers = NULL;
+uint64_t *tmp;
+
+for (j = 0; j < fmt_mod_blob->count_modifiers; j++) {
+struct drm_format_modifier *mod = _modifiers[j];
+
+if ((i < mod->offset) || (i > mod->offset + 63))
+continue;
+if (!(mod->formats & (1 << (i - mod->offset
+continue;
+
+num_modifiers++;
+tmp = realloc(modifiers, num_modifiers * sizeof(modifiers[0]));
+if (!tmp) {
+free(modifiers);
+drmModeFreePropertyBlob(blob);
+return FALSE;
+}
+modifiers = tmp;
+modifiers[num_modifiers - 1] = mod->modifier;
+}
+
+drmmode_crtc->formats[i].format = blob_formats[i];
+drmmode_crtc->formats[i].modifiers = modifiers;
+drmmode_crtc->formats[i].num_modifiers = num_modifiers;
+}
+
+drmModeFreePropertyBlob(blob);
+
+return TRUE;
+}
+#endif
+
 static void
 drmmode_crtc_create_planes(xf86CrtcPtr crtc, int num)
 {
 drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
 drmmode_ptr drmmode = drmmode_crtc->drmmode;
 drmModePlaneRes *kplane_res;
-drmModePlane *kplane;
+drmModePlane *kplane, *best_kplane = NULL;
 drmModeObjectProperties *props;
-uint32_t i, type;
+uint32_t i, type, blob_id;
 int current_crtc, best_plane = 0;
 
 static drmmode_prop_enum_info_rec plane_type_enums[] = {
@@ -1561,6 +1639,7 @@ drmmode_crtc_create_planes(xf86CrtcPtr crtc, int num)
 },
 [DRMMODE_PLANE_FB_ID] = { .name = "FB_ID", },
 [DRMMODE_PLANE_CRTC_ID] = { .name 

[RFC xserver v7 1/2] dri3: Add modifier/multi-plane requests, bump to v1.1

2018-02-27 Thread Louis-Francis Ratté-Boulianne
DRI3 version 1.1 adds support for explicit format modifiers,
including multi-planar buffers.

Signed-off-by: Daniel Stone 
Signed-off-by: Louis-Francis Ratté-Boulianne 
---
 dri3proto.pc.in|   2 +-
 dri3proto.txt  | 243 -
 include/X11/extensions/dri3proto.h |  86 -
 meson.build|   2 +-
 4 files changed, 324 insertions(+), 9 deletions(-)

diff --git a/dri3proto.pc.in b/dri3proto.pc.in
index 6d81d07..c59aa1c 100644
--- a/dri3proto.pc.in
+++ b/dri3proto.pc.in
@@ -5,5 +5,5 @@ includedir=@includedir@
  
 Name: DRI3Proto
 Description: DRI3 extension headers
-Version: 1.0
+Version: 1.1
 Cflags: -I${includedir}
diff --git a/dri3proto.txt b/dri3proto.txt
index dac11d3..76cdbb8 100644
--- a/dri3proto.txt
+++ b/dri3proto.txt
@@ -1,11 +1,16 @@
  The DRI3 Extension
-Version 1.0
-  2013-6-4
+Version 1.1
+ 2018-02-26
   
Keith Packard
  kei...@keithp.com
  Intel Corporation
 
+Daniel Stone
+dani...@collabora.com
+  Collabora
+
+
 1. Introduction
 
 The DRI3 extension provides mechanisms to translate between direct
@@ -27,6 +32,7 @@ Dave Airlie 
 Kristian Høgsberg 
 James Jones 
 Arthur Huillet 
+Louis-Francis Ratté-Boulianne 
 
 ❄ ❄ ❄  ❄  ❄ ❄ ❄ 
 
@@ -117,9 +123,10 @@ The name of this extension is "DRI3"
Errors: Alloc, Drawable, IDChoice, Value, Match
 
Creates a pixmap for the direct rendering object associated
-   with 'buffer'. Changes to pixmap will be visible in that
-   direct rendered object and changes to the direct rendered
-   object will be visible in the pixmap.
+   with 'buffer' and the screen associated with 'drawable'.
+   Changes to pixmap will be visible in that direct rendered
+   object and changes to the direct rendered object will be
+   visible in the pixmap.
 
'size' specifies the total size of the buffer bytes. 'width',
'height' describe the geometry (in pixels) of the underlying
@@ -199,6 +206,156 @@ The name of this extension is "DRI3"
associated with a direct rendering device that 'fence' can
work with, otherwise a Match error results.
 
+┌───
+DRI3GetSupportedModifiers
+   window: WINDOW
+   depth: CARD8
+   bpp: CARD8
+  ▶
+   num_drawable_modifiers: CARD32
+   num_screen_modifiers: CARD32
+   drawable_modifiers: ListOfCARD64
+   screen_modifiers: ListOfCARD64
+└───
+   Errors: Window, Match
+
+   Return supported DRM FourCC modifiers for the specified
+   'window'.
+
+   The first list of 'drawable_modifiers' contains a set of
+   modifiers which the server considers optimal for the window's
+   current configuration. Using these modifiers to allocate, even
+   if locally suboptimal to the client driver, may result in a
+   more optimal display pipeline, e.g. by avoiding composition.
+
+   The second list of 'screen_modifiers', is the total set of
+   modifiers which are acceptable for use on the Screen associated
+   with 'window'. This set of modifiers will not change over the
+   lifetime of the client. Using this set of modifiers to allocate
+   may not result in a globally optimal pipeline, if separate
+   'drawable_modifiers' are available.
+
+   The meaning of any modifier is canonically defined in
+   drm_fourcc.h.
+
+┌───
+DRI3PixmapFromBuffers
+   pixmap: PIXMAP
+   drawable: DRAWABLE
+   num_buffers: CARD8
+   width, height: CARD16
+   stride0, offset0: CARD32
+   stride1, offset1: CARD32
+   stride2, offset2: CARD32
+   stride3, offset3: CARD32
+   depth, bpp: CARD8
+   modifier: CARD64
+   buffers: ListOfFD
+└───
+   Errors: Alloc, Drawable, IDChoice, Value, Match
+
+   Creates a pixmap for the direct rendering object associated
+   with 'buffers' and the screen associated with 'drawable'.
+   Changes to pixmap will be visible in that direct rendered
+   object and changes to the direct rendered object will be
+   visible in the pixmap.
+
+   In contrast to PixmapFromBuffer, multiple buffers may be
+   combined to specify a single logical source for pixel
+   sampling: 'num_buffers' may be set from 1 (single buffer,
+   akin to PixmapFromBuffer) to 4. This is the number of file
+   descriptors which will be sent with this request; one per
+   buffer.
+
+   Modifiers allow explicit specification of non-linear sources,
+   such as 

[RFC xserver v7 04/14] present: Send PresentCompleteModeSuboptimalCopy appropriately

2018-02-27 Thread Louis-Francis Ratté-Boulianne
Add 'check_flip2' hook for driver to let know the core
about why flipping is not possible ('reason').
If it is because of unsupported buffer format/modifier,
a PresentCompleteNotify event is sent to the client with
the PresentCompleteModeSuboptimalCopy mode.

v2: Check for PresentOptionSuboptimal and check driver version
before using 'check_flip2'.

v3: Only require one of 'check_flip' or 'check_flip2' to be
implemented by the driver.
Refactor reasons list to enum

Signed-off-by: Louis-Francis Ratté-Boulianne 
Reviewed-by: Daniel Stone 
---
 configure.ac|  2 +-
 include/protocol-versions.h |  2 +-
 present/meson.build |  2 +-
 present/present.c   | 50 ++---
 present/present.h   | 12 ++-
 present/present_priv.h  |  2 ++
 6 files changed, 50 insertions(+), 20 deletions(-)

diff --git a/configure.ac b/configure.ac
index 2420266dd..e4fd4c375 100644
--- a/configure.ac
+++ b/configure.ac
@@ -753,7 +753,7 @@ DAMAGEPROTO="damageproto >= 1.1"
 XCMISCPROTO="xcmiscproto >= 1.2.0"
 BIGREQSPROTO="bigreqsproto >= 1.1.0"
 XTRANS="xtrans >= 1.3.5"
-PRESENTPROTO="presentproto >= 1.0"
+PRESENTPROTO="presentproto >= 1.1"
 
 dnl List of libraries that require a specific version
 LIBAPPLEWM="applewm >= 1.4"
diff --git a/include/protocol-versions.h b/include/protocol-versions.h
index b4498927b..fd8d8df88 100644
--- a/include/protocol-versions.h
+++ b/include/protocol-versions.h
@@ -69,7 +69,7 @@
 
 /* Present */
 #define SERVER_PRESENT_MAJOR_VERSION1
-#define SERVER_PRESENT_MINOR_VERSION0
+#define SERVER_PRESENT_MINOR_VERSION1
 
 /* RandR */
 #define SERVER_RANDR_MAJOR_VERSION 1
diff --git a/present/meson.build b/present/meson.build
index a4296ca7a..cf725302a 100644
--- a/present/meson.build
+++ b/present/meson.build
@@ -13,7 +13,7 @@ libxserver_present = static_library('libxserver_present',
 include_directories: inc,
 dependencies: [
 common_dep,
-dependency('presentproto', version: '>= 1.0')
+dependency('presentproto', version: '>= 1.1')
 ],
 c_args: '-DHAVE_XORG_CONFIG_H'
 )
diff --git a/present/present.c b/present/present.c
index 176e89c0b..42e5fb4fc 100644
--- a/present/present.c
+++ b/present/present.c
@@ -118,19 +118,23 @@ present_flip_pending_pixmap(ScreenPtr screen)
 }
 
 static Bool
-present_check_flip(RRCrtcPtrcrtc,
-   WindowPtrwindow,
-   PixmapPtrpixmap,
-   Bool sync_flip,
-   RegionPtrvalid,
-   int16_t  x_off,
-   int16_t  y_off)
+present_check_flip(RRCrtcPtrcrtc,
+   WindowPtrwindow,
+   PixmapPtrpixmap,
+   Bool sync_flip,
+   RegionPtrvalid,
+   int16_t  x_off,
+   int16_t  y_off,
+   PresentFlipReason   *reason)
 {
 ScreenPtr   screen = window->drawable.pScreen;
 PixmapPtr   window_pixmap;
 WindowPtr   root = screen->root;
 present_screen_priv_ptr screen_priv = present_screen_priv(screen);
 
+if (reason)
+*reason = PRESENT_FLIP_REASON_UNKNOWN;
+
 if (!screen_priv)
 return FALSE;
 
@@ -177,7 +181,12 @@ present_check_flip(RRCrtcPtrcrtc,
 }
 
 /* Ask the driver for permission */
-if (screen_priv->info->check_flip) {
+if (screen_priv->info->version >= 1 && screen_priv->info->check_flip2) {
+if (!(*screen_priv->info->check_flip2) (crtc, window, pixmap, 
sync_flip, reason)) {
+DebugPresent(("\td %08lx -> %08lx\n", window->drawable.id, pixmap 
? pixmap->drawable.id : 0));
+return FALSE;
+}
+} else if (screen_priv->info->check_flip) {
 if (!(*screen_priv->info->check_flip) (crtc, window, pixmap, 
sync_flip)) {
 DebugPresent(("\td %08lx -> %08lx\n", window->drawable.id, pixmap 
? pixmap->drawable.id : 0));
 return FALSE;
@@ -564,6 +573,7 @@ present_check_flip_window (WindowPtr window)
 present_window_priv_ptr window_priv = present_window_priv(window);
 present_vblank_ptr  flip_pending = screen_priv->flip_pending;
 present_vblank_ptr  vblank;
+PresentFlipReason   reason;
 
 /* If this window hasn't ever been used with Present, it can't be
  * flipping
@@ -580,7 +590,7 @@ present_check_flip_window (WindowPtr window)
  */
 if (flip_pending->window == window) {
 if (!present_check_flip(flip_pending->crtc, window, 
flip_pending->pixmap,
-flip_pending->sync_flip, NULL, 0, 0))
+flip_pending->sync_flip, NULL, 0, 0, NULL))

[RFC xserver v7 07/14] modesetting: Use atomic modesetting to configure output/CRTCs

2018-02-27 Thread Louis-Francis Ratté-Boulianne
To make sure we also use the same primary plane and to avoid
mixing uses of two APIs, it is better to always use the atomic
modesetting API when possible.

v2: Don't use mode_output->connector_id

Signed-off-by: Louis-Francis Ratté-Boulianne 
Reviewed-by: Daniel Stone 
---
 hw/xfree86/drivers/modesetting/drmmode_display.c | 262 +++
 hw/xfree86/drivers/modesetting/drmmode_display.h |  30 ++-
 hw/xfree86/drivers/modesetting/pageflip.c|   2 +-
 hw/xfree86/drivers/modesetting/present.c |   3 +-
 4 files changed, 252 insertions(+), 45 deletions(-)

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c 
b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 51851a9f9..30e3b05db 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -267,16 +267,100 @@ plane_add_prop(drmModeAtomicReq *req, 
drmmode_crtc_private_ptr drmmode_crtc,
info->prop_id, val);
 return (ret <= 0) ? -1 : 0;
 }
+
+static int
+crtc_add_prop(drmModeAtomicReq *req, drmmode_crtc_private_ptr drmmode_crtc,
+  enum drmmode_crtc_property prop, uint64_t val)
+{
+drmmode_prop_info_ptr info = _crtc->props[prop];
+int ret;
+
+if (!info)
+return -1;
+
+ret = drmModeAtomicAddProperty(req, drmmode_crtc->mode_crtc->crtc_id,
+   info->prop_id, val);
+return (ret <= 0) ? -1 : 0;
+}
+
+static int
+connector_add_prop(drmModeAtomicReq *req, drmmode_output_private_ptr 
drmmode_output,
+   enum drmmode_connector_property prop, uint64_t val)
+{
+drmmode_prop_info_ptr info = _output->props_connector[prop];
+int ret;
+
+if (!info)
+return -1;
+
+ret = drmModeAtomicAddProperty(req, drmmode_output->output_id,
+   info->prop_id, val);
+return (ret <= 0) ? -1 : 0;
+}
+
+static int
+drmmode_CompareKModes(drmModeModeInfo * kmode, drmModeModeInfo * other)
+{
+return memcmp(kmode, other, sizeof(*kmode));
+}
+
+static int
+drm_mode_ensure_blob(xf86CrtcPtr crtc, drmModeModeInfo mode_info)
+{
+modesettingPtr ms = modesettingPTR(crtc->scrn);
+drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+drmmode_mode_ptr mode;
+int ret;
+
+if (drmmode_crtc->current_mode &&
+drmmode_CompareKModes(_crtc->current_mode->mode_info, 
_info) == 0)
+return 0;
+
+mode = calloc(sizeof(drmmode_mode_rec), 1);
+if (!mode)
+return -1;
+
+mode->mode_info = mode_info;
+ret = drmModeCreatePropertyBlob(ms->fd,
+>mode_info,
+sizeof(mode->mode_info),
+>blob_id);
+drmmode_crtc->current_mode = mode;
+xorg_list_add(>entry, _crtc->mode_list);
+
+return ret;
+}
+
+static void
+drm_mode_destroy(xf86CrtcPtr crtc, drmmode_mode_ptr mode)
+{
+modesettingPtr ms = modesettingPTR(crtc->scrn);
+if (mode->blob_id)
+drmModeDestroyPropertyBlob(ms->fd, mode->blob_id);
+xorg_list_del(>entry);
+free(mode);
+}
 #endif
 
+static void
+drmmode_ConvertToKMode(ScrnInfoPtr scrn,
+   drmModeModeInfo * kmode, DisplayModePtr mode);
+
 int
-drmmode_crtc_set_fb(xf86CrtcPtr crtc, uint32_t fb_id,
+drmmode_crtc_set_fb(xf86CrtcPtr crtc, DisplayModePtr mode, uint32_t fb_id,
 int x, int y, uint32_t flags, void *data)
 {
 modesettingPtr ms = modesettingPTR(crtc->scrn);
 xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
 drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
-int ret = 0;
+drmmode_ptr drmmode = drmmode_crtc->drmmode;
+int output_count = 0;
+uint32_t *output_ids = NULL;
+drmModeModeInfo kmode;
+int i, ret = 0;
+
+if (mode)
+drmmode_ConvertToKMode(crtc->scrn, , mode);
 
 #ifdef GLAMOR_HAS_DRM_ATOMIC
 if (ms->atomic_modeset) {
@@ -285,12 +369,56 @@ drmmode_crtc_set_fb(xf86CrtcPtr crtc, uint32_t fb_id,
 if (!req)
 return 1;
 
+if (mode) {
+ret = drm_mode_ensure_blob(crtc, kmode);
+
+for (i = 0; i < xf86_config->num_output; i++) {
+xf86OutputPtr output = xf86_config->output[i];
+drmmode_output_private_ptr drmmode_output;
+
+if (output->crtc != crtc)
+continue;
+
+drmmode_output = output->driver_private;
+if (drmmode_output->output_id == -1)
+continue;
+
+if (drmmode_output->dpms == DPMSModeOn) {
+ret |= crtc_add_prop(req, drmmode_crtc,
+ DRMMODE_CRTC_ACTIVE, 1);
+ret |= crtc_add_prop(req, drmmode_crtc,
+ DRMMODE_CRTC_MODE_ID,
+ 

[RFC xorgproto v7 02/14] presentproto: PresentCompleteModeSuboptimalCopy flag

2018-02-27 Thread Louis-Francis Ratté-Boulianne
If the Complete event has this mode, the client is not using
the more optimal format/modifier for the buffer allocation. The
client must explicitely inform the server that it understands
this mode by adding the PresentOptionSuboptimal flag when calling
PresentPixmap.

Its main usage as of now is to allow clients to re-fetch DRI3
format modifiers as some modifiers might allow direct scanout.

Bump presentproto version to 1.2.

Signed-off-by: Louis-Francis Ratté-Boulianne 
Reviewed-by: Daniel Stone 
---
 include/X11/extensions/presenttokens.h | 13 +++-
 meson.build|  2 +-
 presentproto.pc.in |  2 +-
 presentproto.txt   | 36 --
 4 files changed, 36 insertions(+), 17 deletions(-)

diff --git a/include/X11/extensions/presenttokens.h 
b/include/X11/extensions/presenttokens.h
index acb7576..9211207 100644
--- a/include/X11/extensions/presenttokens.h
+++ b/include/X11/extensions/presenttokens.h
@@ -25,7 +25,7 @@
 
 #define PRESENT_NAME   "Present"
 #define PRESENT_MAJOR  1
-#define PRESENT_MINOR  0
+#define PRESENT_MINOR  2
 
 #define PresentNumberErrors0
 #define PresentNumberEvents0
@@ -44,10 +44,12 @@
 #define PresentOptionAsync  (1 << 0)
 #define PresentOptionCopy   (1 << 1)
 #define PresentOptionUST(1 << 2)
+#define PresentOptionSuboptimal (1 << 3)
 
 #define PresentAllOptions   (PresentOptionAsync | \
  PresentOptionCopy | \
- PresentOptionUST)
+ PresentOptionUST | \
+ PresentOptionSuboptimal)
 
 /* Present capabilities */
 
@@ -94,8 +96,9 @@
 
 /* Complete Modes */
 
-#define PresentCompleteModeCopy 0
-#define PresentCompleteModeFlip 1
-#define PresentCompleteModeSkip 2
+#define PresentCompleteModeCopy   0
+#define PresentCompleteModeFlip   1
+#define PresentCompleteModeSkip   2
+#define PresentCompleteModeSuboptimalCopy 3
 
 #endif
diff --git a/meson.build b/meson.build
index 6507db2..fa576aa 100644
--- a/meson.build
+++ b/meson.build
@@ -36,7 +36,7 @@ pcs = [
 ['glproto', '1.4.17'],
 ['inputproto',  '2.3.2'],
 ['kbproto', '1.0.7'],
-['presentproto','1.1'],
+['presentproto','1.2'],
 ['randrproto',  '1.6.0'],
 ['recordproto', '1.14.2'],
 ['renderproto', '0.11.1'],
diff --git a/presentproto.pc.in b/presentproto.pc.in
index 9a32fa8..6ec4b7d 100644
--- a/presentproto.pc.in
+++ b/presentproto.pc.in
@@ -5,5 +5,5 @@ includedir=@includedir@
  
 Name: PresentProto
 Description: Present extension headers
-Version: 1.1
+Version: 1.2
 Cflags: -I${includedir}
diff --git a/presentproto.txt b/presentproto.txt
index fdaf658..6ba55ae 100644
--- a/presentproto.txt
+++ b/presentproto.txt
@@ -1,6 +1,6 @@
The Present Extension
-Version 1.0
-  2013-6-6
+Version 1.2
+ 2018-02-26
   
Keith Packard
  kei...@keithp.com
@@ -24,6 +24,7 @@ change and is provided only as an aid to further Present 
development.
 Eric Anholt 
 Owen Taylor 
 James Jones 
+Louis-Francis Ratté-Boulianne 
 
 ❄ ❄ ❄  ❄  ❄ ❄ ❄ 
 
@@ -55,7 +56,8 @@ PRESENTEVENTMASK { PresentConfigureNotifyMask,
 
 PRESENTOPTION { PresentOptionAsync,
 PresentOptionCopy,
-   PresentOptionUST }
+   PresentOptionUST,
+   PresentOptionSuboptimal }
 
 PRESENTCAPABILITY { PresentCapabilityAsync,
PresentCapabilityFence,
@@ -66,7 +68,8 @@ PRESENTCOMPLETEKIND { PresentCompleteKindPixmap,
 
 PRESENTCOMPLETEMODE { PresentCompleteModeCopy,
  PresentCompleteModeFlip,
- PresentCompleteModeSkip }
+ PresentCompleteModeSkip,
+ PresentCompleteModeSuboptimalCopy }
 
 The Present extension also uses the Sync extension Fence data type to
 provide synchronization for pixmaps.
@@ -226,6 +229,10 @@ The name of this extension is "Present"
server will take the target UST time and convert it to a
suitable target MSC value.
 
+   If 'options' contains PresentOptionSuboptimal, then the
+   PresentCompleteNotify event can have mode
+   PresentCompleteModeSuboptimalCopy as the client supports it.
+
After the presentation occurs, a PresentCompleteNotify event
with kind PresentCompleteKindPixmap will be generated, both to

[RFC xserver v7 00/14] DRI3 v1.1: modifiers and multi-plane

2018-02-27 Thread Louis-Francis Ratté-Boulianne
Hello,

This is the RFC v7 for DRI3 v1.1  (X11 modifiers and multi-plane).
For context, please check previous submissions:

https://lists.x.org/archives/xorg-devel/2017-June/053854.html
https://lists.x.org/archives/xorg-devel/2017-August/054436.html
https://lists.x.org/archives/xorg-devel/2017-September/054776.html
https://lists.x.org/archives/xorg-devel/2017-October/054899.html
https://lists.x.org/archives/xorg-devel/2017-November/055170.html
https://lists.x.org/archives/xorg-devel/2018-February/055932.html

The main changes in this iteration are:

 - Add some details in dri3proto.txt

 - Merge proto changes to xorgproto

 - Fix compilation issues in some commits

Thanks,

Louis-Francis
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

[RFC xorgproto v7 01/14] dri3proto: Add modifier/multi-plane requests, bump to v1.1

2018-02-27 Thread Louis-Francis Ratté-Boulianne
DRI3 version 1.1 adds support for explicit format modifiers,
including multi-planar buffers.

Signed-off-by: Daniel Stone 
Signed-off-by: Louis-Francis Ratté-Boulianne 
---
 dri3proto.pc.in|   2 +-
 dri3proto.txt  | 243 -
 include/X11/extensions/dri3proto.h |  86 -
 meson.build|   2 +-
 4 files changed, 324 insertions(+), 9 deletions(-)

diff --git a/dri3proto.pc.in b/dri3proto.pc.in
index 6d81d07..c59aa1c 100644
--- a/dri3proto.pc.in
+++ b/dri3proto.pc.in
@@ -5,5 +5,5 @@ includedir=@includedir@
  
 Name: DRI3Proto
 Description: DRI3 extension headers
-Version: 1.0
+Version: 1.1
 Cflags: -I${includedir}
diff --git a/dri3proto.txt b/dri3proto.txt
index dac11d3..76cdbb8 100644
--- a/dri3proto.txt
+++ b/dri3proto.txt
@@ -1,11 +1,16 @@
  The DRI3 Extension
-Version 1.0
-  2013-6-4
+Version 1.1
+ 2018-02-26
   
Keith Packard
  kei...@keithp.com
  Intel Corporation
 
+   Daniel Stone
+   dani...@collabora.com
+ Collabora
+
+
 1. Introduction
 
 The DRI3 extension provides mechanisms to translate between direct
@@ -27,6 +32,7 @@ Dave Airlie 
 Kristian Høgsberg 
 James Jones 
 Arthur Huillet 
+Louis-Francis Ratté-Boulianne 
 
 ❄ ❄ ❄  ❄  ❄ ❄ ❄ 
 
@@ -117,9 +123,10 @@ The name of this extension is "DRI3"
Errors: Alloc, Drawable, IDChoice, Value, Match
 
Creates a pixmap for the direct rendering object associated
-   with 'buffer'. Changes to pixmap will be visible in that
-   direct rendered object and changes to the direct rendered
-   object will be visible in the pixmap.
+   with 'buffer' and the screen associated with 'drawable'.
+   Changes to pixmap will be visible in that direct rendered
+   object and changes to the direct rendered object will be
+   visible in the pixmap.
 
'size' specifies the total size of the buffer bytes. 'width',
'height' describe the geometry (in pixels) of the underlying
@@ -199,6 +206,156 @@ The name of this extension is "DRI3"
associated with a direct rendering device that 'fence' can
work with, otherwise a Match error results.
 
+┌───
+DRI3GetSupportedModifiers
+   window: WINDOW
+   depth: CARD8
+   bpp: CARD8
+  ▶
+   num_drawable_modifiers: CARD32
+   num_screen_modifiers: CARD32
+   drawable_modifiers: ListOfCARD64
+   screen_modifiers: ListOfCARD64
+└───
+   Errors: Window, Match
+
+   Return supported DRM FourCC modifiers for the specified
+   'window'.
+
+   The first list of 'drawable_modifiers' contains a set of
+   modifiers which the server considers optimal for the window's
+   current configuration. Using these modifiers to allocate, even
+   if locally suboptimal to the client driver, may result in a
+   more optimal display pipeline, e.g. by avoiding composition.
+
+   The second list of 'screen_modifiers', is the total set of
+   modifiers which are acceptable for use on the Screen associated
+   with 'window'. This set of modifiers will not change over the
+   lifetime of the client. Using this set of modifiers to allocate
+   may not result in a globally optimal pipeline, if separate
+   'drawable_modifiers' are available.
+
+   The meaning of any modifier is canonically defined in
+   drm_fourcc.h.
+
+┌───
+DRI3PixmapFromBuffers
+   pixmap: PIXMAP
+   drawable: DRAWABLE
+   num_buffers: CARD8
+   width, height: CARD16
+   stride0, offset0: CARD32
+   stride1, offset1: CARD32
+   stride2, offset2: CARD32
+   stride3, offset3: CARD32
+   depth, bpp: CARD8
+   modifier: CARD64
+   buffers: ListOfFD
+└───
+   Errors: Alloc, Drawable, IDChoice, Value, Match
+
+   Creates a pixmap for the direct rendering object associated
+   with 'buffers' and the screen associated with 'drawable'.
+   Changes to pixmap will be visible in that direct rendered
+   object and changes to the direct rendered object will be
+   visible in the pixmap.
+
+   In contrast to PixmapFromBuffer, multiple buffers may be
+   combined to specify a single logical source for pixel
+   sampling: 'num_buffers' may be set from 1 (single buffer,
+   akin to PixmapFromBuffer) to 4. This is the number of file
+   descriptors which will be sent with this request; one per
+   buffer.
+
+   Modifiers allow explicit specification of non-linear sources,
+   such as tiled 

Re: [PATCH util/modular v2] release.sh: Add support for mesa-demos

2018-02-27 Thread Emil Velikov
On 23 February 2018 at 14:13, Andreas Boll  wrote:
> v2: Rebase on Mesa cleanup.
> Move demos into its own elif statement.
>
> Signed-off-by: Andreas Boll 
> ---
> Rebased on https://patchwork.freedesktop.org/patch/206466/
>
>  release.sh | 12 ++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
>
Thanks for the re-spin. Reviewed and pushed both patches to master.

-Emil
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

Re: Depth 30 enablement for modesetting-ddx and fixups for glamor. Rev 3

2018-02-27 Thread Adam Jackson
On Tue, 2018-02-27 at 03:05 +0100, Mario Kleiner wrote:
> Revision 3, with r-b's by Antoine Martin tacked on, thanks. Antoine, i
> left that one /* XXX handle 2 10 10 10 and 1555 formats; ... */ comment
> in place. As far as i understand it is meant to be a todo for depth 30 and
> depth 16 formats with alpha channel, and the current code only handles
> 10 bpc and 5 bpc formats without alpha channel, so that todo would
> still apply.
> 
> Also updated to address Ville's and Michel's comments.

Looks good to me, thanks for following up on this. Merged:

remote: I: patch #203383 updated using rev 
9ab5d91c6c228e8f5b34e4b30c5104aed6c41958.
remote: I: patch #203384 updated using rev 
c326c717c8dbf4a3f0c64a031fbe6030e73ff355.
remote: I: patch #205536 updated using rev 
7a687da24c9d3c9e40ffa426631bf355322d470e.
remote: I: patch #205535 updated using rev 
125201408ddd51ca8ea961a7338a6ad299e5816c.
remote: I: patch #206952 updated using rev 
b5f9fcd50a999a00128c0cc3f6e7d1f66182c9d5.
remote: I: patch #206953 updated using rev 
7bc86c7d2346eadb3aafe1550ec55e63f2a3b3e5.
remote: I: patch #203382 updated using rev 
80d4f4b6c20288aa3e0c9908d5d845fc0088a662.
remote: I: 7 patch(es) updated to state Accepted.
To ssh://git.freedesktop.org/git/xorg/xserver
   efe9e3e9ff..80d4f4b6c2  master -> master

- ajax
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

Re: [PATCH xserver] modesetting: Fix fallback for lack of new vblank kernel API.

2018-02-27 Thread Adam Jackson
On Mon, 2018-02-26 at 22:25 -0800, Keith Packard wrote:
> Mario Kleiner  writes:
> 
> > Turns out that the kernel DRM ioctl handling returns EINVAL
> > instead of ENOTTY if one tries to call the new drmCrtcGetSequence()
> 
> Thanks for fixing this. I must have missed testing this...
> 
> Reviewed-by: Keith Packard 

remote: I: patch #206976 updated using rev 
efe9e3e9ff96a06f50d94dc93ad2c19085fa3d09.
remote: I: 1 patch(es) updated to state Accepted.
To ssh://git.freedesktop.org/git/xorg/xserver
   8171d4c2d6..efe9e3e9ff  master -> master

- ajax
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

Re: EXT: Re: [PATCH xcb] Fix hanging issue in _XReply

2018-02-27 Thread Ray, Ian (GE Healthcare)

> On 19 Feb 2018, at 17.46, Arthur Huillet  wrote:
> 
> No opinion on the patch, but do you have a small reproducer app to expose the 
> problem?
> I've debugged something similar in the past, without much success (or 
> interest).
> 

Unfortunately not, I will try to put something together.


> Thanks,
> -- 
> A. Huillet

___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

[PATCH xrandr v5 6/6] xrandr: gamma and scaling factors must be positive

2018-02-27 Thread Giuseppe Bilotta
Signed-off-by: Giuseppe Bilotta 
---
 xrandr.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/xrandr.c b/xrandr.c
index f6c425f..7f1e867 100644
--- a/xrandr.c
+++ b/xrandr.c
@@ -2979,6 +2979,9 @@ main (int argc, char **argv)
argerr ("%s: invalid argument '%s'\n", argv[i-1], argv[i]);
config_output->gamma.green = config_output->gamma.blue = 
config_output->gamma.red;
}
+   if (config_output->gamma.red <= 0.0 || config_output->gamma.green 
<= 0.0 ||
+   config_output->gamma.blue <= 0.0)
+   argerr ("gamma correction factors must be positive\n");
config_output->changes |= changes_gamma;
setit_1_2 = True;
continue;
@@ -3030,6 +3033,8 @@ main (int argc, char **argv)
argerr ("failed to parse '%s' as a scaling factor\n", 
argv[i]);
sy = sx;
}
+   if (sx <= 0.0 || sy <= 0.0)
+   argerr ("scaling factors must be positive\n");
init_transform (_output->transform);
config_output->transform.transform.matrix[0][0] = XDoubleToFixed 
(sx);
config_output->transform.transform.matrix[1][1] = XDoubleToFixed 
(sy);
-- 
2.14.1.439.g647b9b4702

___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

[PATCH xrandr v5 2/6] xrandr: stricter --scale argument parsing

2018-02-27 Thread Giuseppe Bilotta
We used to accept something like --scale 2x3junk as a valid input
(scaling x by 2 and y by 3), even though this isn't really a valid
scaling factor.

Fix by making sure there is nothing after the parsed number(s).

Signed-off-by: Giuseppe Bilotta 
---
 xrandr.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/xrandr.c b/xrandr.c
index 1085a95..6a38cf2 100644
--- a/xrandr.c
+++ b/xrandr.c
@@ -3014,11 +3014,12 @@ main (int argc, char **argv)
if (!strcmp ("--scale", argv[i]))
{
double  sx, sy;
+   char junk;
if (!config_output) argerr ("%s must be used after --output\n", 
argv[i]);
if (++i >= argc) argerr ("%s requires an argument\n", argv[i-1]);
-   if (sscanf (argv[i], "%lfx%lf", , ) != 2)
+   if (sscanf (argv[i], "%lfx%lf%c", , , ) != 2)
{
-   if (sscanf (argv[i], "%lf", ) != 1)
+   if (sscanf (argv[i], "%lf%c", , ) != 1)
argerr ("failed to parse '%s' as a scaling factor\n", 
argv[i]);
sy = sx;
}
-- 
2.14.1.439.g647b9b4702

___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

[PATCH xrandr v5 3/6] xrandr.man: grammar tuning

2018-02-27 Thread Giuseppe Bilotta
Rephrase the --scale option paragraph to improve English and be more
consistent in choice of plurals and tense. Also ensure that each
sentence starts on a new line in the roff source.

Signed-off-by: Giuseppe Bilotta 
---
 man/xrandr.man | 11 ++-
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/man/xrandr.man b/man/xrandr.man
index e59abbe..cfbfb8f 100644
--- a/man/xrandr.man
+++ b/man/xrandr.man
@@ -208,11 +208,12 @@ Chooses the scaling filter method to be applied when the 
screen is scaled or
 transformed.
 Can be either 'bilinear' or 'nearest'.
 .IP "\-\-scale \fIx\fP[x\fIy\fP]"
-Changes the dimensions of the output picture. If the \fIy\fP value is omitted,
-the \fIx\fP value will be used for both dimensions. Values superior to 1 will 
lead to
-a compressed screen (screen dimension bigger than the dimension of the output
-mode), and values below 1 leads to a zoom in on the output. This option is
-actually a shortcut version of the \fI\-\-transform\fP option.
+Changes the dimensions of the output picture.
+If the \fIy\fP value is omitted, the \fIx\fP value will be used for both 
dimensions.
+Values larger than 1 lead to a compressed screen (screen dimension bigger
+than the dimension of the output mode), and values less than 1 lead to
+a zoom in on the output.
+This option is actually a shortcut version of the \fI\-\-transform\fP option.
 .IP "\-\-scale-from \fIw\fPx\fIh\fP"
 Specifies the size in pixels of the area of the framebuffer to be displayed on
 this output.
-- 
2.14.1.439.g647b9b4702

___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

[PATCH xrandr v5 4/6] xrandr: allow single value for --gamma

2018-02-27 Thread Giuseppe Bilotta
Similarly to --scale, accept a single value to be used for all three
components, and refuse values with extra junk after the acceptable
values.

Signed-off-by: Giuseppe Bilotta 
---
 man/xrandr.man |  9 ++---
 xrandr.c   | 15 +++
 2 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/man/xrandr.man b/man/xrandr.man
index cfbfb8f..9f976ad 100644
--- a/man/xrandr.man
+++ b/man/xrandr.man
@@ -63,7 +63,7 @@ xrandr \- primitive command line interface to RandR extension
 [\-\-set \fIproperty\fP \fIvalue\fP]
 [\-\-off]
 [\-\-crtc \fIcrtc\fP]
-[\-\-gamma \fIred\fP:\fIgreen\fP:\fIblue\fP]
+[\-\-gamma \fIred\fP[:\fIgreen\fP:\fIblue\fP]]
 [\-\-brightness \fIbrightness\fP]
 [\-o \fIorientation\fP]
 [\-s \fIsize\fP]
@@ -303,9 +303,12 @@ Uses the specified crtc (either as an index in the list of 
CRTCs or XID).
 In normal usage, this option is not required as xrandr tries to make
 sensible choices about which crtc to use with each output. When that fails
 for some reason, this option can override the normal selection.
-.IP "\-\-gamma \fIred\fP:\fIgreen\fP:\fIblue\fP"
+.IP "\-\-gamma \fIred\fP[:\fIgreen\fP:\fIblue\fP]"
 Set the specified floating point values as gamma correction on the crtc
-currently attached to this output. Note that you cannot get two different 
values
+currently attached to this output.
+If green and blue are not specified, the red value will be used
+for all three components.
+Note that you cannot get two different values
 for cloned outputs (i.e.: which share the same crtc) and that switching an 
output to another crtc doesn't change
 the crtc gamma corrections at all.
 .IP "\-\-brightness \fIbrightness\fP"
diff --git a/xrandr.c b/xrandr.c
index 6a38cf2..f6c425f 100644
--- a/xrandr.c
+++ b/xrandr.c
@@ -144,7 +144,7 @@ usage(void)
"  --off\n"
"  --crtc \n"
"  --panning 
x[++[/x++[]]]\n"
-   "  --gamma ::\n"
+   "  --gamma [::]\n"
"  --brightness \n"
"  --primary\n"
"  --noprimary\n"
@@ -2967,11 +2967,18 @@ main (int argc, char **argv)
continue;
}
if (!strcmp ("--gamma", argv[i])) {
+   char junk;
if (!config_output) argerr ("%s must be used after --output\n", 
argv[i]);
if (++i >= argc) argerr ("%s requires an argument\n", argv[i-1]);
-   if (sscanf(argv[i], "%f:%f:%f", _output->gamma.red,
-   _output->gamma.green, _output->gamma.blue) != 
3)
-   argerr ("%s: invalid argument '%s'\n", argv[i-1], argv[i]);
+   if (sscanf(argv[i], "%f:%f:%f%c", _output->gamma.red,
+   _output->gamma.green, _output->gamma.blue, 
) != 3)
+   {
+   /* check if it's a single floating-point value,
+* to be applied to all components */
+   if (sscanf(argv[i], "%f%c", _output->gamma.red, ) 
!= 1)
+   argerr ("%s: invalid argument '%s'\n", argv[i-1], argv[i]);
+   config_output->gamma.green = config_output->gamma.blue = 
config_output->gamma.red;
+   }
config_output->changes |= changes_gamma;
setit_1_2 = True;
continue;
-- 
2.14.1.439.g647b9b4702

___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

[PATCH xrandr v5 0/6] xrandr: improve option parsing and documentation

2018-02-27 Thread Giuseppe Bilotta
Miscellaneous patches to improve option parsing and documentation for
xrandr.

Allow single values to be given to --scale and --gamma, rejecting the
option if valid values are followed by extra junk (e.g. 2x3a isn't
accepted as a valid value for --scale), or if they are not positive.

Minor improvements to the documentation are also introduced, the largest
of which is the documentation of the xrandr monitor options.

v2: rebased on current head.
v3: fix code indentation, add grammar fix patch
v4: single value accepted for --gamma too, monitor options documented
v5: additional patch to check for positive values

The patchset is also available from:

  git://git.oblomov.eu/xorg/xrandr parse-doc-fixes

up to c9755465412cbcf533d3c512397773949a26e55f.


Giuseppe Bilotta (6):
  xrandr: allow a single value for --scale
  xrandr: stricter --scale argument parsing
  xrandr.man: grammar tuning
  xrandr: allow single value for --gamma
  xrandr.man: document the monitor manipulation options
  xrandr: gamma and scaling factors must be positive

 man/xrandr.man | 46 +-
 xrandr.c   | 31 ---
 2 files changed, 61 insertions(+), 16 deletions(-)

-- 
2.14.1.439.g647b9b4702

___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

[PATCH xrandr v5 5/6] xrandr.man: document the monitor manipulation options

2018-02-27 Thread Giuseppe Bilotta
Signed-off-by: Giuseppe Bilotta 
---
 man/xrandr.man | 23 +++
 1 file changed, 23 insertions(+)

diff --git a/man/xrandr.man b/man/xrandr.man
index 9f976ad..aa82724 100644
--- a/man/xrandr.man
+++ b/man/xrandr.man
@@ -72,6 +72,10 @@ xrandr \- primitive command line interface to RandR extension
 [\-\-listproviders]
 [\-\-setprovideroutputsource \fIprovider\fP \fIsource\fP]
 [\-\-setprovideroffloadsink \fIprovider\fP \fIsink\fP]
+[\-\-listmonitors]
+[\-\-listactivemonitors]
+[\-\-setmonitor \fIname\fP \fIgeometry\fP \fIoutputs\fP]
+[\-\-delmonitor \fIname\fP]
 .SH DESCRIPTION
 .I Xrandr
 is used to set the size, orientation and/or reflection of the outputs for a
@@ -118,6 +122,25 @@ is available.
 Forces the usage of the RandR version 1.2 protocol, even if the display does
 not report it as supported or a higher version is available.
 .PP
+.SH "RandR version 1.5 options"
+.PP
+Options for RandR 1.5 are used as a superset of the options for RandR 1.4.
+.PP
+.IP \-\-listmonitors
+Report information about all defined monitors.
+.IP \-\-listactivemonitors
+Report information about currently active monitors.
+.IP "\-\-setmonitor \fIname\fP \fIgeometry\fP \fIoutputs\fP"} 
{none|\fIoutput\fP,\fIoutput\fP,...}\n"
+Define a new monitor with the given geometry and associated to the given 
outputs.
+The output list is either the keyword \fBnone\fP or a comma-separated list of 
outputs.
+The geometry is either the keyword \fBauto\fP, in which case the monitor
+will automatically track the geometry of the associated outputs, or a manual 
specification
+in the form
+\fIw\fP/\fImmw\fPx\fIh\fP/\fImmh\fP+\fIx\fP+\fIy\fP
+where w, h, x, y are in pixels and mmw, mmh are the physical dimensions of the 
monitor.
+.IP "\-\-delmonitor \fIname\fP"
+Delete the given user-defined monitor.
+.PP
 .SH "RandR version 1.4 options"
 .PP
 Options for RandR 1.4 are used as a superset of the options for RandR 1.3.
-- 
2.14.1.439.g647b9b4702

___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

[PATCH xrandr v5 1/6] xrandr: allow a single value for --scale

2018-02-27 Thread Giuseppe Bilotta
This allows using e.g. --scale 0.5 as a shorthand for --scale 0.5x0.5

Signed-off-by: Giuseppe Bilotta 
---
 man/xrandr.man | 7 ---
 xrandr.c   | 8 ++--
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/man/xrandr.man b/man/xrandr.man
index 65ccc2a..e59abbe 100644
--- a/man/xrandr.man
+++ b/man/xrandr.man
@@ -34,7 +34,7 @@ xrandr \- primitive command line interface to RandR extension
 [\-\-current]
 [\-\-noprimary]
 [\-\-panning 
\fIwidth\fPx\fIheight\fP[+\fIx\fP+\fIy\fP[/\fItrack_width\fPx\fItrack_height\fP+\fItrack_x\fP+\fItrack_y\fP[/\fIborder_left\fP/\fIborder_top\fP/\fIborder_right\fP/\fIborder_bottom\fP
-[\-\-scale \fIx\fPx\fIy\fP]
+[\-\-scale \fIx\fP[x\fIy\fP]]
 [\-\-scale-from \fIw\fPx\fIh\fP]
 [\-\-transform 
\fIa\fP,\fIb\fP,\fIc\fP,\fId\fP,\fIe\fP,\fIf\fP,\fIg\fP,\fIh\fP,\fIi\fP]
 [\-\-primary]
@@ -207,8 +207,9 @@ values are used (a unit matrix without filter).
 Chooses the scaling filter method to be applied when the screen is scaled or
 transformed.
 Can be either 'bilinear' or 'nearest'.
-.IP "\-\-scale \fIx\fPx\fIy\fP"
-Changes the dimensions of the output picture. Values superior to 1 will lead to
+.IP "\-\-scale \fIx\fP[x\fIy\fP]"
+Changes the dimensions of the output picture. If the \fIy\fP value is omitted,
+the \fIx\fP value will be used for both dimensions. Values superior to 1 will 
lead to
 a compressed screen (screen dimension bigger than the dimension of the output
 mode), and values below 1 leads to a zoom in on the output. This option is
 actually a shortcut version of the \fI\-\-transform\fP option.
diff --git a/xrandr.c b/xrandr.c
index 2d4cb72..1085a95 100644
--- a/xrandr.c
+++ b/xrandr.c
@@ -137,7 +137,7 @@ usage(void)
"  --below \n"
"  --same-as \n"
"  --set  \n"
-   "  --scale x\n"
+   "  --scale [x]\n"
"  --scale-from x\n"
"  --transform \n"
"  --filter nearest,bilinear\n"
@@ -3017,7 +3017,11 @@ main (int argc, char **argv)
if (!config_output) argerr ("%s must be used after --output\n", 
argv[i]);
if (++i >= argc) argerr ("%s requires an argument\n", argv[i-1]);
if (sscanf (argv[i], "%lfx%lf", , ) != 2)
-   argerr ("failed to parse '%s' as a scaling factor\n", argv[i]);
+   {
+   if (sscanf (argv[i], "%lf", ) != 1)
+   argerr ("failed to parse '%s' as a scaling factor\n", 
argv[i]);
+   sy = sx;
+   }
init_transform (_output->transform);
config_output->transform.transform.matrix[0][0] = XDoubleToFixed 
(sx);
config_output->transform.transform.matrix[1][1] = XDoubleToFixed 
(sy);
-- 
2.14.1.439.g647b9b4702

___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

Re: [RFC xserver v6 00/14] DRI3 v1.1: modifiers and multi-plane

2018-02-27 Thread Daniel Stone
Hi,

On 16 February 2018 at 04:15, Louis-Francis Ratté-Boulianne
 wrote:
> This is the RFC v6 for DRI3 v1.1  (X11 modifiers and multi-plane).
> For context, please check previous submissions:
>
> https://lists.x.org/archives/xorg-devel/2017-June/053854.html
> https://lists.x.org/archives/xorg-devel/2017-August/054436.html
> https://lists.x.org/archives/xorg-devel/2017-September/054776.html
> https://lists.x.org/archives/xorg-devel/2017-October/054899.html
> https://lists.x.org/archives/xorg-devel/2017-November/055170.html
>
> The main changes in this iteration are:
>
>  - Re-enable multiplane modifiers (e.g. Intel CCS)
>
>  - Don't hardcode GBM surface format when using modifiers
>
>  - Don't conflict with new DRM properties helper

FWIW, the xserver series is:
Reviewed-by: Daniel Stone 

> The MESA-side of DRI3 v1.1 has been re-submitted today:
>
> https://lists.freedesktop.org/archives/mesa-dev/2018-February/185703.html

This is all reviewed and ready to go as well.

Cheers,
Daniel
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel