[PATCH xinput] property: plug a memory leak

2018-09-11 Thread Peter Hutterer
Not that it matters since we'll exit after this call anyway, but coverity is
unhappy and that makes us all unhappy, doesn't it?

Signed-off-by: Peter Hutterer 
---
 src/property.c | 27 +++
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/src/property.c b/src/property.c
index e4a46f8..071f80f 100644
--- a/src/property.c
+++ b/src/property.c
@@ -610,19 +610,20 @@ do_set_prop_xi2(Display *dpy, Atom type, int format, int 
argc, char **argv, char
 unsigned char *c;
 int16_t *s;
 int32_t *l;
-} data;
+} data = { NULL };
+int rc = EXIT_FAILURE;
 
 if (argc < 3)
 {
 fprintf(stderr, "Usage: xinput %s %s\n", n, desc);
-return EXIT_FAILURE;
+goto out;
 }
 
 info = xi2_find_device_info(dpy, argv[0]);
 if (!info)
 {
 fprintf(stderr, "unable to find device %s\n", argv[0]);
-return EXIT_FAILURE;
+goto out;
 }
 
 name = argv[1];
@@ -631,7 +632,7 @@ do_set_prop_xi2(Display *dpy, Atom type, int format, int 
argc, char **argv, char
 
 if (prop == None) {
 fprintf(stderr, "invalid property '%s'\n", name);
-return EXIT_FAILURE;
+goto out;
 }
 
 float_atom = XInternAtom(dpy, "FLOAT", False);
@@ -643,7 +644,7 @@ do_set_prop_xi2(Display *dpy, Atom type, int format, int 
argc, char **argv, char
   _after, ) != Success) {
 fprintf(stderr, "failed to get property type and format for 
'%s'\n",
 name);
-return EXIT_FAILURE;
+goto out;
 } else {
 if (type == None)
 type = old_type;
@@ -657,7 +658,7 @@ do_set_prop_xi2(Display *dpy, Atom type, int format, int 
argc, char **argv, char
 if (type == None) {
 fprintf(stderr, "property '%s' doesn't exist, you need to specify "
 "its type and format\n", name);
-return EXIT_FAILURE;
+goto out;
 }
 
 data.c = calloc(nelements, sizeof(int32_t));
@@ -678,36 +679,38 @@ do_set_prop_xi2(Display *dpy, Atom type, int format, int 
argc, char **argv, char
 break;
 default:
 fprintf(stderr, "unexpected size for property %s", name);
-return EXIT_FAILURE;
+goto out;
 }
 } else if (type == float_atom) {
 if (format != 32) {
 fprintf(stderr, "unexpected format %d for property '%s'\n",
 format, name);
-return EXIT_FAILURE;
+goto out;
 }
 *(float *)(data.l + i) = strtod(argv[2 + i], );
 if (endptr == argv[2 + i]) {
 fprintf(stderr, "argument %s could not be parsed\n", argv[2 + 
i]);
-return EXIT_FAILURE;
+goto out;
 }
 } else if (type == XA_ATOM) {
 if (format != 32) {
 fprintf(stderr, "unexpected format %d for property '%s'\n",
 format, name);
-return EXIT_FAILURE;
+goto out;
 }
 data.l[i] = parse_atom(dpy, argv[2 + i]);
 } else {
 fprintf(stderr, "unexpected type for property '%s'\n", name);
-return EXIT_FAILURE;
+goto out;
 }
 }
 
 XIChangeProperty(dpy, info->deviceid, prop, type, format, PropModeReplace,
   data.c, nelements);
+rc = EXIT_SUCCESS;
+out:
 free(data.c);
-return EXIT_SUCCESS;
+return rc;
 }
 #endif
 
-- 
2.17.1

___
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 app/sessreg] Replace strncpy calls with a sane version that always terminates

2018-09-11 Thread Peter Hutterer
Fixes coverity complaints about potentially unterminated strings

Signed-off-by: Peter Hutterer 
---
 sessreg.c | 26 +-
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/sessreg.c b/sessreg.c
index 0a8fdb2..53b30b0 100644
--- a/sessreg.c
+++ b/sessreg.c
@@ -192,6 +192,14 @@ sysnerr (int x, const char *s)
return x;
 }
 
+static void
+safe_strncpy(char *dest, const char *src, size_t n)
+{
+(void)strncpy(dest, src, n);
+if (n > 0)
+dest[n - 1] = '\0';
+}
+
 int
 main (int argc, char **argv)
 {
@@ -406,9 +414,9 @@ main (int argc, char **argv)
memset(, 0, sizeof(ll));
ll.ll_time = current_time;
if (line)
-(void) strncpy (ll.ll_line, line, sizeof (ll.ll_line));
+safe_strncpy (ll.ll_line, line, sizeof (ll.ll_line));
if (host_name)
-(void) strncpy (ll.ll_host, host_name, sizeof 
(ll.ll_host));
+safe_strncpy (ll.ll_host, host_name, sizeof 
(ll.ll_host));
 
sysnerr (write (llog, (char *) , sizeof (ll))
== sizeof (ll), "write lastlog entry");
@@ -429,11 +437,11 @@ set_utmp (struct utmp *u, char *line, char *user, char 
*host, time_t date, int a
 {
memset (u, 0, sizeof (*u));
if (line)
-   (void) strncpy (u->ut_line, line, sizeof (u->ut_line));
+   safe_strncpy (u->ut_line, line, sizeof (u->ut_line));
else
memset (u->ut_line, 0, sizeof (u->ut_line));
if (addp && user)
-   (void) strncpy (u->ut_name, user, sizeof (u->ut_name));
+   safe_strncpy (u->ut_name, user, sizeof (u->ut_name));
else
memset (u->ut_name, 0, sizeof (u->ut_name));
 #ifdef HAVE_STRUCT_UTMP_UT_ID
@@ -451,7 +459,7 @@ set_utmp (struct utmp *u, char *line, char *user, char 
*host, time_t date, int a
i -= sizeof (u->ut_id);
else
i = 0;
-   (void) strncpy (u->ut_id, line + i, sizeof (u->ut_id));
+   safe_strncpy (u->ut_id, line + i, sizeof (u->ut_id));
} else
memset (u->ut_id, 0, sizeof (u->ut_id));
 #endif
@@ -469,7 +477,7 @@ set_utmp (struct utmp *u, char *line, char *user, char 
*host, time_t date, int a
 #endif
 #ifdef HAVE_STRUCT_UTMP_UT_HOST
if (addp && host)
-   (void) strncpy (u->ut_host, host, sizeof (u->ut_host));
+   safe_strncpy (u->ut_host, host, sizeof (u->ut_host));
else
memset (u->ut_host, 0, sizeof (u->ut_host));
 #endif
@@ -513,7 +521,7 @@ set_utmpx (struct utmpx *u, const char *line, const char 
*user,
if(strcmp(line, ":0") == 0)
(void) strcpy(u->ut_line, "console");
else
-   (void) strncpy (u->ut_line, line, sizeof (u->ut_line));
+   safe_strncpy (u->ut_line, line, sizeof (u->ut_line));
 
strncpy(u->ut_host, line, sizeof(u->ut_host));
 #ifdef HAVE_STRUCT_UTMPX_UT_SYSLEN
@@ -523,7 +531,7 @@ set_utmpx (struct utmpx *u, const char *line, const char 
*user,
else
memset (u->ut_line, 0, sizeof (u->ut_line));
if (addp && user)
-   (void) strncpy (u->ut_user, user, sizeof (u->ut_user));
+   safe_strncpy (u->ut_user, user, sizeof (u->ut_user));
else
memset (u->ut_user, 0, sizeof (u->ut_user));
 
@@ -541,7 +549,7 @@ set_utmpx (struct utmpx *u, const char *line, const char 
*user,
i -= sizeof (u->ut_id);
else
i = 0;
-   (void) strncpy (u->ut_id, line + i, sizeof (u->ut_id));
+   safe_strncpy (u->ut_id, line + i, sizeof (u->ut_id));
 
/* make sure there is no entry using identical ut_id */
if (!UtmpxIdOpen(u->ut_id) && addp) {
-- 
2.17.1

___
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] devices: break after finding and removing device from lists

2018-09-11 Thread Peter Hutterer
On Wed, Sep 12, 2018 at 11:40:56AM +1000, Dave Airlie wrote:
> From: Dave Airlie 
> 
> Coverity complains about a use after free in here after the
> freeing, I can't follow the linked list so well, but whot
> says the device can only be on one list once, so break should
> fix it.
> 
> Signed-off-by: Dave Airlie 

Reviewed-by: Peter Hutterer 

Cheers,
   Peter

> ---
>  dix/devices.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/dix/devices.c b/dix/devices.c
> index 4a628afb0..1b18b168e 100644
> --- a/dix/devices.c
> +++ b/dix/devices.c
> @@ -1177,6 +1177,7 @@ RemoveDevice(DeviceIntPtr dev, BOOL sendevent)
>  flags[tmp->id] = IsMaster(tmp) ? XIMasterRemoved : 
> XISlaveRemoved;
>  CloseDevice(tmp);
>  ret = Success;
> +break;
>  }
>  }
>  
> @@ -1193,6 +1194,7 @@ RemoveDevice(DeviceIntPtr dev, BOOL sendevent)
>  prev->next = next;
>  
>  ret = Success;
> +break;
>  }
>  }
>  
> -- 
> 2.17.1
> 
> ___
> 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

[PATCH] devices: break after finding and removing device from lists

2018-09-11 Thread Dave Airlie
From: Dave Airlie 

Coverity complains about a use after free in here after the
freeing, I can't follow the linked list so well, but whot
says the device can only be on one list once, so break should
fix it.

Signed-off-by: Dave Airlie 
---
 dix/devices.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/dix/devices.c b/dix/devices.c
index 4a628afb0..1b18b168e 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -1177,6 +1177,7 @@ RemoveDevice(DeviceIntPtr dev, BOOL sendevent)
 flags[tmp->id] = IsMaster(tmp) ? XIMasterRemoved : XISlaveRemoved;
 CloseDevice(tmp);
 ret = Success;
+break;
 }
 }
 
@@ -1193,6 +1194,7 @@ RemoveDevice(DeviceIntPtr dev, BOOL sendevent)
 prev->next = next;
 
 ret = Success;
+break;
 }
 }
 
-- 
2.17.1

___
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 v8 05/14] modesetting: Use atomic modesetting API for pageflip if available

2018-09-11 Thread Dave Airlie
On Wed, 28 Feb 2018 at 11:21, Daniel Stone  wrote:
>
> 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 

Re: [PATCH xserver v2] glamor: add support for NV12 in Xv

2018-09-11 Thread Adam Jackson
On Tue, 2018-09-11 at 15:41 -0400, Alex Deucher wrote:
> On Tue, Sep 11, 2018 at 1:30 PM Julien Isorce  wrote:
> > 
> > Useful when video decoders only output NV12. Currently
> > glamor Xv only supports I420 and YV12.
> > 
> > Note that Intel's sna supports I420, YV12, YUY2, UYVY, NV12.
> > 
> > Test: xvinfo | grep NV12
> > Test: gst-launch-1.0 videotestsrc ! video/x-raw, format=NV12 ! xvimagesink
> > 
> > v2: Combine the two texture2Ds on u_sampler.
> > 
> > Signed-off-by: Julien Isorce 
> 
> Reviewed-by: Alex Deucher 

Merged the series, thanks.

- 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 v2] glamor: add support for NV12 in Xv

2018-09-11 Thread Alex Deucher
On Tue, Sep 11, 2018 at 1:30 PM Julien Isorce  wrote:
>
> Useful when video decoders only output NV12. Currently
> glamor Xv only supports I420 and YV12.
>
> Note that Intel's sna supports I420, YV12, YUY2, UYVY, NV12.
>
> Test: xvinfo | grep NV12
> Test: gst-launch-1.0 videotestsrc ! video/x-raw, format=NV12 ! xvimagesink
>
> v2: Combine the two texture2Ds on u_sampler.
>
> Signed-off-by: Julien Isorce 

Reviewed-by: Alex Deucher 

> ---
>  glamor/glamor_xv.c | 180 
> +
>  1 file changed, 155 insertions(+), 25 deletions(-)
>
> diff --git a/glamor/glamor_xv.c b/glamor/glamor_xv.c
> index 62fc4ff..6fef6ed 100644
> --- a/glamor/glamor_xv.c
> +++ b/glamor/glamor_xv.c
> @@ -59,8 +59,40 @@ typedef struct tagREF_TRANSFORM {
>  #define RTFContrast(a)   (1.0 + ((a)*1.0)/1000.0)
>  #define RTFHue(a)   (((a)*3.1416)/1000.0)
>
> -static const glamor_facet glamor_facet_xv_planar = {
> -.name = "xv_planar",
> +static const glamor_facet glamor_facet_xv_planar_2 = {
> +.name = "xv_planar_2",
> +
> +.version = 120,
> +
> +.source_name = "v_texcoord0",
> +.vs_vars = ("attribute vec2 position;\n"
> +"attribute vec2 v_texcoord0;\n"
> +"varying vec2 tcs;\n"),
> +.vs_exec = (GLAMOR_POS(gl_Position, position)
> +"tcs = v_texcoord0;\n"),
> +
> +.fs_vars = ("uniform sampler2D y_sampler;\n"
> +"uniform sampler2D u_sampler;\n"
> +"uniform vec4 offsetyco;\n"
> +"uniform vec4 ucogamma;\n"
> +"uniform vec4 vco;\n"
> +"varying vec2 tcs;\n"),
> +.fs_exec = (
> +"float sample;\n"
> +"vec2 sample_uv;\n"
> +"vec4 temp1;\n"
> +"sample = texture2D(y_sampler, tcs).w;\n"
> +"temp1.xyz = offsetyco.www * vec3(sample) + 
> offsetyco.xyz;\n"
> +"sample_uv = texture2D(u_sampler, tcs).xy;\n"
> +"temp1.xyz = ucogamma.xyz * vec3(sample_uv.x) + 
> temp1.xyz;\n"
> +"temp1.xyz = clamp(vco.xyz * vec3(sample_uv.y) + 
> temp1.xyz, 0.0, 1.0);\n"
> +"temp1.w = 1.0;\n"
> +"gl_FragColor = temp1;\n"
> +),
> +};
> +
> +static const glamor_facet glamor_facet_xv_planar_3 = {
> +.name = "xv_planar_3",
>
>  .version = 120,
>
> @@ -110,26 +142,50 @@ Atom glamorBrightness, glamorContrast, 
> glamorSaturation, glamorHue,
>  XvImageRec glamor_xv_images[] = {
>  XVIMAGE_YV12,
>  XVIMAGE_I420,
> +XVIMAGE_NV12
>  };
>  int glamor_xv_num_images = ARRAY_SIZE(glamor_xv_images);
>
>  static void
> -glamor_init_xv_shader(ScreenPtr screen)
> +glamor_init_xv_shader(ScreenPtr screen, int id)
>  {
>  glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
>  GLint sampler_loc;
> +const glamor_facet *glamor_facet_xv_planar = NULL;
> +
> +switch (id) {
> +case FOURCC_YV12:
> +case FOURCC_I420:
> +glamor_facet_xv_planar = _facet_xv_planar_3;
> +break;
> +case FOURCC_NV12:
> +glamor_facet_xv_planar = _facet_xv_planar_2;
> +break;
> +default:
> +break;
> +}
>
>  glamor_build_program(screen,
>   _priv->xv_prog,
> - _facet_xv_planar, NULL, NULL, NULL);
> + glamor_facet_xv_planar, NULL, NULL, NULL);
>
>  glUseProgram(glamor_priv->xv_prog.prog);
>  sampler_loc = glGetUniformLocation(glamor_priv->xv_prog.prog, 
> "y_sampler");
>  glUniform1i(sampler_loc, 0);
>  sampler_loc = glGetUniformLocation(glamor_priv->xv_prog.prog, 
> "u_sampler");
>  glUniform1i(sampler_loc, 1);
> -sampler_loc = glGetUniformLocation(glamor_priv->xv_prog.prog, 
> "v_sampler");
> -glUniform1i(sampler_loc, 2);
> +
> +switch (id) {
> +case FOURCC_YV12:
> +case FOURCC_I420:
> +sampler_loc = glGetUniformLocation(glamor_priv->xv_prog.prog, 
> "v_sampler");
> +glUniform1i(sampler_loc, 2);
> +break;
> +case FOURCC_NV12:
> +break;
> +default:
> +break;
> +}
>
>  }
>
> @@ -227,6 +283,21 @@ glamor_xv_query_image_attributes(int id,
>  offsets[2] = size;
>  size += tmp;
>  break;
> +case FOURCC_NV12:
> +*w = ALIGN(*w, 2);
> +*h = ALIGN(*h, 2);
> +size = ALIGN(*w, 4);
> +if (pitches)
> +pitches[0] = size;
> +size *= *h;
> +if (offsets)
> +offsets[1] = offsets[2] = size;
> +tmp = ALIGN(*w, 4);
> +if (pitches)
> +pitches[1] = pitches[2] = tmp;
> +tmp *= (*h >> 1);
> +size += tmp;
> +break;
>  }
>  return size;
>  }
> @@ -240,7 +311,7 @@ static REF_TRANSFORM trans[2] = {
>  };
>
>  void
> -glamor_xv_render(glamor_port_private 

Re: [PATCH xserver v2] glamor: add support for NV12 in Xv

2018-09-11 Thread Matt Turner
On Tue, Sep 11, 2018 at 10:28 AM Julien Isorce  wrote:
>
> Useful when video decoders only output NV12. Currently
> glamor Xv only supports I420 and YV12.
>
> Note that Intel's sna supports I420, YV12, YUY2, UYVY, NV12.
>
> Test: xvinfo | grep NV12
> Test: gst-launch-1.0 videotestsrc ! video/x-raw, format=NV12 ! xvimagesink
>
> v2: Combine the two texture2Ds on u_sampler.
>
> Signed-off-by: Julien Isorce 

I don't know the code well enough to give a R-b, but you fixed the one
thing I pointed out. Looks good to me.
___
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 0/3] Xv: add NV12 support in glamor

2018-09-11 Thread Julien Isorce
Thx!

On Tue, Sep 11, 2018 at 12:29 AM Olivier Fourdan  wrote:

> Hi Julien,
>
> On Fri, 7 Sep 2018 at 00:40, Julien Isorce 
> wrote:
> >
> > Some video decoders can only output NV12 and currently glamor Xv only
> > supports I420 and YV12.
> >
> > Tested with xf86-video-ati, xf86-video-amdgpu and xf86-video-modesetting
> > on AMD graphics but should work on any setup that can use glamor.
> >
> > Test: gst-launch-1.0 videotestsrc ! video/x-raw, format=NV12 !
> xvimagesink
> >
> > Julien Isorce (3):
> >   xfree86: define FOURCC_NV12 and XVIMAGE_NV12
> >   glamor: add support for GL_RG
> >   glamor: add support for NV12 in Xv
> >
> >  glamor/glamor.c|   2 +
> >  glamor/glamor.h|   1 +
> >  glamor/glamor_priv.h   |   4 +-
> >  glamor/glamor_transfer.c   |  10 ++-
> >  glamor/glamor_utils.h  |   4 +
> >  glamor/glamor_xv.c | 180
> ++---
> >  hw/xfree86/common/fourcc.h |  20 +
> >  7 files changed, 193 insertions(+), 28 deletions(-)
> >
> > --
> > 2.7.4
> >
>
> Nice! Tested with Xwayland using gstreamer, so:
>
> Tested-by: Olivier Fourdan 
>
> Cheers,
> Olivier
>
___
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 v2] glamor: add support for NV12 in Xv

2018-09-11 Thread Julien Isorce
Useful when video decoders only output NV12. Currently
glamor Xv only supports I420 and YV12.

Note that Intel's sna supports I420, YV12, YUY2, UYVY, NV12.

Test: xvinfo | grep NV12
Test: gst-launch-1.0 videotestsrc ! video/x-raw, format=NV12 ! xvimagesink

v2: Combine the two texture2Ds on u_sampler.

Signed-off-by: Julien Isorce 
---
 glamor/glamor_xv.c | 180 +
 1 file changed, 155 insertions(+), 25 deletions(-)

diff --git a/glamor/glamor_xv.c b/glamor/glamor_xv.c
index 62fc4ff..6fef6ed 100644
--- a/glamor/glamor_xv.c
+++ b/glamor/glamor_xv.c
@@ -59,8 +59,40 @@ typedef struct tagREF_TRANSFORM {
 #define RTFContrast(a)   (1.0 + ((a)*1.0)/1000.0)
 #define RTFHue(a)   (((a)*3.1416)/1000.0)
 
-static const glamor_facet glamor_facet_xv_planar = {
-.name = "xv_planar",
+static const glamor_facet glamor_facet_xv_planar_2 = {
+.name = "xv_planar_2",
+
+.version = 120,
+
+.source_name = "v_texcoord0",
+.vs_vars = ("attribute vec2 position;\n"
+"attribute vec2 v_texcoord0;\n"
+"varying vec2 tcs;\n"),
+.vs_exec = (GLAMOR_POS(gl_Position, position)
+"tcs = v_texcoord0;\n"),
+
+.fs_vars = ("uniform sampler2D y_sampler;\n"
+"uniform sampler2D u_sampler;\n"
+"uniform vec4 offsetyco;\n"
+"uniform vec4 ucogamma;\n"
+"uniform vec4 vco;\n"
+"varying vec2 tcs;\n"),
+.fs_exec = (
+"float sample;\n"
+"vec2 sample_uv;\n"
+"vec4 temp1;\n"
+"sample = texture2D(y_sampler, tcs).w;\n"
+"temp1.xyz = offsetyco.www * vec3(sample) + 
offsetyco.xyz;\n"
+"sample_uv = texture2D(u_sampler, tcs).xy;\n"
+"temp1.xyz = ucogamma.xyz * vec3(sample_uv.x) + 
temp1.xyz;\n"
+"temp1.xyz = clamp(vco.xyz * vec3(sample_uv.y) + 
temp1.xyz, 0.0, 1.0);\n"
+"temp1.w = 1.0;\n"
+"gl_FragColor = temp1;\n"
+),
+};
+
+static const glamor_facet glamor_facet_xv_planar_3 = {
+.name = "xv_planar_3",
 
 .version = 120,
 
@@ -110,26 +142,50 @@ Atom glamorBrightness, glamorContrast, glamorSaturation, 
glamorHue,
 XvImageRec glamor_xv_images[] = {
 XVIMAGE_YV12,
 XVIMAGE_I420,
+XVIMAGE_NV12
 };
 int glamor_xv_num_images = ARRAY_SIZE(glamor_xv_images);
 
 static void
-glamor_init_xv_shader(ScreenPtr screen)
+glamor_init_xv_shader(ScreenPtr screen, int id)
 {
 glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
 GLint sampler_loc;
+const glamor_facet *glamor_facet_xv_planar = NULL;
+
+switch (id) {
+case FOURCC_YV12:
+case FOURCC_I420:
+glamor_facet_xv_planar = _facet_xv_planar_3;
+break;
+case FOURCC_NV12:
+glamor_facet_xv_planar = _facet_xv_planar_2;
+break;
+default:
+break;
+}
 
 glamor_build_program(screen,
  _priv->xv_prog,
- _facet_xv_planar, NULL, NULL, NULL);
+ glamor_facet_xv_planar, NULL, NULL, NULL);
 
 glUseProgram(glamor_priv->xv_prog.prog);
 sampler_loc = glGetUniformLocation(glamor_priv->xv_prog.prog, "y_sampler");
 glUniform1i(sampler_loc, 0);
 sampler_loc = glGetUniformLocation(glamor_priv->xv_prog.prog, "u_sampler");
 glUniform1i(sampler_loc, 1);
-sampler_loc = glGetUniformLocation(glamor_priv->xv_prog.prog, "v_sampler");
-glUniform1i(sampler_loc, 2);
+
+switch (id) {
+case FOURCC_YV12:
+case FOURCC_I420:
+sampler_loc = glGetUniformLocation(glamor_priv->xv_prog.prog, 
"v_sampler");
+glUniform1i(sampler_loc, 2);
+break;
+case FOURCC_NV12:
+break;
+default:
+break;
+}
 
 }
 
@@ -227,6 +283,21 @@ glamor_xv_query_image_attributes(int id,
 offsets[2] = size;
 size += tmp;
 break;
+case FOURCC_NV12:
+*w = ALIGN(*w, 2);
+*h = ALIGN(*h, 2);
+size = ALIGN(*w, 4);
+if (pitches)
+pitches[0] = size;
+size *= *h;
+if (offsets)
+offsets[1] = offsets[2] = size;
+tmp = ALIGN(*w, 4);
+if (pitches)
+pitches[1] = pitches[2] = tmp;
+tmp *= (*h >> 1);
+size += tmp;
+break;
 }
 return size;
 }
@@ -240,7 +311,7 @@ static REF_TRANSFORM trans[2] = {
 };
 
 void
-glamor_xv_render(glamor_port_private *port_priv)
+glamor_xv_render(glamor_port_private *port_priv, int id)
 {
 ScreenPtr screen = port_priv->pPixmap->drawable.pScreen;
 glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
@@ -264,7 +335,7 @@ glamor_xv_render(glamor_port_private *port_priv)
 int dst_box_index;
 
 if (!glamor_priv->xv_prog.prog)
-

Re: [PATCH xserver 3/3] glamor: add support for NV12 in Xv

2018-09-11 Thread Matt Turner
On Thu, Sep 6, 2018 at 3:40 PM Julien Isorce  wrote:
>
> Useful when video decoders only support NV12. Currently
> glamor Xv only supports I420 and YV12.
>
> Note that Intel's sna supports I420, YV12, YUY2, UYVY, NV12.
>
> Test: xvinfo | grep NV12
> Test: gst-launch-1.0 videotestsrc ! video/x-raw, format=NV12 ! xvimagesink
>
> Signed-off-by: Julien Isorce 
> ---
>  glamor/glamor_xv.c | 180 
> +
>  1 file changed, 155 insertions(+), 25 deletions(-)
>
> diff --git a/glamor/glamor_xv.c b/glamor/glamor_xv.c
> index 62fc4ff..5631293 100644
> --- a/glamor/glamor_xv.c
> +++ b/glamor/glamor_xv.c
> @@ -59,8 +59,40 @@ typedef struct tagREF_TRANSFORM {
>  #define RTFContrast(a)   (1.0 + ((a)*1.0)/1000.0)
>  #define RTFHue(a)   (((a)*3.1416)/1000.0)
>
> -static const glamor_facet glamor_facet_xv_planar = {
> -.name = "xv_planar",
> +static const glamor_facet glamor_facet_xv_planar_2 = {
> +.name = "xv_planar_2",
> +
> +.version = 120,
> +
> +.source_name = "v_texcoord0",
> +.vs_vars = ("attribute vec2 position;\n"
> +"attribute vec2 v_texcoord0;\n"
> +"varying vec2 tcs;\n"),
> +.vs_exec = (GLAMOR_POS(gl_Position, position)
> +"tcs = v_texcoord0;\n"),
> +
> +.fs_vars = ("uniform sampler2D y_sampler;\n"
> +"uniform sampler2D u_sampler;\n"
> +"uniform vec4 offsetyco;\n"
> +"uniform vec4 ucogamma;\n"
> +"uniform vec4 vco;\n"
> +"varying vec2 tcs;\n"),
> +.fs_exec = (
> +"float sample;\n"
> +"vec4 temp1;\n"
> +"sample = texture2D(y_sampler, tcs).w;\n"
> +"temp1.xyz = offsetyco.www * vec3(sample) + 
> offsetyco.xyz;\n"
> +"sample = texture2D(u_sampler, tcs).x;\n"
> +"temp1.xyz = ucogamma.xyz * vec3(sample) + 
> temp1.xyz;\n"
> +"sample = texture2D(u_sampler, tcs).y;\n"

Might as well combine the two texture2Ds on u_sampler. I expect most
GLSL compilers will be able to combine them into one operation, but
there's no point in leaving it to chance.
___
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 0/3] Xv: add NV12 support in glamor

2018-09-11 Thread Alex Deucher
On Thu, Sep 6, 2018 at 6:40 PM Julien Isorce  wrote:
>
> Some video decoders can only output NV12 and currently glamor Xv only
> supports I420 and YV12.
>
> Tested with xf86-video-ati, xf86-video-amdgpu and xf86-video-modesetting
> on AMD graphics but should work on any setup that can use glamor.
>
> Test: gst-launch-1.0 videotestsrc ! video/x-raw, format=NV12 ! xvimagesink
>
> Julien Isorce (3):
>   xfree86: define FOURCC_NV12 and XVIMAGE_NV12
>   glamor: add support for GL_RG
>   glamor: add support for NV12 in Xv

Series is:
Reviewed-by: Alex Deucher 

>
>  glamor/glamor.c|   2 +
>  glamor/glamor.h|   1 +
>  glamor/glamor_priv.h   |   4 +-
>  glamor/glamor_transfer.c   |  10 ++-
>  glamor/glamor_utils.h  |   4 +
>  glamor/glamor_xv.c | 180 
> ++---
>  hw/xfree86/common/fourcc.h |  20 +
>  7 files changed, 193 insertions(+), 28 deletions(-)
>
> --
> 2.7.4
>
> ___
> 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 0/3] Xv: add NV12 support in glamor

2018-09-11 Thread Olivier Fourdan
Hi Julien,

On Fri, 7 Sep 2018 at 00:40, Julien Isorce  wrote:
>
> Some video decoders can only output NV12 and currently glamor Xv only
> supports I420 and YV12.
>
> Tested with xf86-video-ati, xf86-video-amdgpu and xf86-video-modesetting
> on AMD graphics but should work on any setup that can use glamor.
>
> Test: gst-launch-1.0 videotestsrc ! video/x-raw, format=NV12 ! xvimagesink
>
> Julien Isorce (3):
>   xfree86: define FOURCC_NV12 and XVIMAGE_NV12
>   glamor: add support for GL_RG
>   glamor: add support for NV12 in Xv
>
>  glamor/glamor.c|   2 +
>  glamor/glamor.h|   1 +
>  glamor/glamor_priv.h   |   4 +-
>  glamor/glamor_transfer.c   |  10 ++-
>  glamor/glamor_utils.h  |   4 +
>  glamor/glamor_xv.c | 180 
> ++---
>  hw/xfree86/common/fourcc.h |  20 +
>  7 files changed, 193 insertions(+), 28 deletions(-)
>
> --
> 2.7.4
>

Nice! Tested with Xwayland using gstreamer, so:

Tested-by: Olivier Fourdan 

Cheers,
Olivier
___
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: [Pixman] [BUG] SIGSEGV in sse2_fill

2018-09-11 Thread Frédéric Fauberteau

Le 2018-09-10 12:34, Michel Dänzer a écrit :

On 2018-09-10 12:01 p.m., Frédéric Fauberteau wrote:

Le 2018-09-10 09:26, Michel Dänzer a écrit :

On 2018-09-10 8:22 a.m., Frédéric Fauberteau wrote:

Le 2018-09-01 15:16, Michel Dänzer a écrit :

On 2018-09-01 9:22 a.m., Frédéric Fauberteau wrote:


[  5770.134] (EE) RADEON(0): Failed to make prime FD for handle: 
22

[  5770.134] (EE) RADEON(0): Failed to create textured screen.


This is the problem. Please try current xf86-video-ati Git master,
specifically
https://gitlab.freedesktop.org/xorg/driver/xf86-video-ati/commit/db28d35ce9fd07a2a4703f3df0633d4c8291ff9b


could help for this.


I just tested this commit and xorg server now starts without
segfaulting.

I am from a remote host and I don't know if the display is correct. 
But

the log file shows an error:

[688070.735] (II) Initializing extension DRI2
[688070.737] (II) RADEON(0): Setting screen physical size to 783 x 
277

[688070.923] failed to add FB for modeset
[688070.923] (WW) RADEON(0): Failed to set mode on CRTC 0
[688070.954] failed to add FB for modeset
[688070.954] (WW) RADEON(0): Failed to set mode on CRTC 1
[688070.955] (EE) RADEON(0): Failed to enable any CRTC


Please try the Git master branch, which will soon become the 18.1
release. If there's still a problem with that, please provide the
corresponding full Xorg log file.


Please find the Xorg.0.log produced after upgrading the driver to
de88ea2755611bdcb18d91d8234d2ab5be8ff2e9:


Thanks, the rest of the log file looks fine.

The above warning and error messages indicate that drmModeAddFB fails.
Since you got the "Failed to make prime FD for handle" error message
from glamor with the 18.0.1 driver, there might still be an issue
related to the GEM handle of the front buffer.

I've never seen this before, so I suspect it could be an issue specific
to NetBSD's KMS support. Can you poke around a bit to see why
drmModeAddFB fails? E.g., what are the parameters passed to it by
radeon_fb_create, and what error does it return?


My wm runs but I have a blank screen.

The problem seems come from drmModeAddFB () from 
/usr/pkg/lib/libdrm.so.2 but I have no debugging symbol.


Thanks for your feedback. I'll try to follow your trail.
___
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