diff mbox series

[i-g-t,4/5] lib/igt_fb: Check for stride before creating cairo surface

Message ID 20180906000350.2478-5-drawat@vmware.com (mailing list archive)
State New, archived
Headers show
Series vmwgfx as a new driver for igt-gpu-tools | expand

Commit Message

Deepak Singh Rawat Sept. 6, 2018, 12:03 a.m. UTC
Cairo surface creation will fail if stride of provided buffer is not
same as expected by cairo. This fails for vmwgfx odd length framebuffer
as in vmwgfx stride is always width * bpp.

Signed-off-by: Deepak Rawat <drawat@vmware.com>
---
 lib/igt_fb.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Chris Wilson Sept. 6, 2018, 8:58 a.m. UTC | #1
Quoting Deepak Rawat (2018-09-06 01:03:49)
> Cairo surface creation will fail if stride of provided buffer is not
> same as expected by cairo. This fails for vmwgfx odd length framebuffer
> as in vmwgfx stride is always width * bpp.
> 
> Signed-off-by: Deepak Rawat <drawat@vmware.com>
> ---
>  lib/igt_fb.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/lib/igt_fb.c b/lib/igt_fb.c
> index ba995a1a..2724e323 100644
> --- a/lib/igt_fb.c
> +++ b/lib/igt_fb.c
> @@ -1349,6 +1349,9 @@ static void create_cairo_surface__gtt(int fd, struct igt_fb *fb)
>                 ptr = gem_mmap__gtt(fd, fb->gem_handle, fb->size,
>                                     PROT_READ | PROT_WRITE);
>  
> +       igt_require(fb->stride == cairo_format_stride_for_width(
> +               drm_format_to_cairo(fb->drm_format), fb->width));
> +
>         fb->cairo_surface =
>                 cairo_image_surface_create_for_data(ptr,
>                                                     drm_format_to_cairo(fb->drm_format),

Is there not a 
igt_require_f/igt_assert_f(cairo_surface_status(fb->cairo_surface) == CAIRO_STATUS_SUCCESS,
"Unable to create a cairo surface: %s", cairo_status_to_string(cairo_surface_status(fb->cairo_surface)));
here?
-Chris
Deepak Singh Rawat Sept. 6, 2018, 10:24 p.m. UTC | #2
> Quoting Deepak Rawat (2018-09-06 01:03:49)
> > Cairo surface creation will fail if stride of provided buffer is not
> > same as expected by cairo. This fails for vmwgfx odd length framebuffer
> > as in vmwgfx stride is always width * bpp.
> >
> > Signed-off-by: Deepak Rawat <drawat@vmware.com>
> > ---
> >  lib/igt_fb.c | 3 +++
> >  1 file changed, 3 insertions(+)
> >
> > diff --git a/lib/igt_fb.c b/lib/igt_fb.c
> > index ba995a1a..2724e323 100644
> > --- a/lib/igt_fb.c
> > +++ b/lib/igt_fb.c
> > @@ -1349,6 +1349,9 @@ static void create_cairo_surface__gtt(int fd,
> struct igt_fb *fb)
> >                 ptr = gem_mmap__gtt(fd, fb->gem_handle, fb->size,
> >                                     PROT_READ | PROT_WRITE);
> >
> > +       igt_require(fb->stride == cairo_format_stride_for_width(
> > +               drm_format_to_cairo(fb->drm_format), fb->width));
> > +
> >         fb->cairo_surface =
> >                 cairo_image_surface_create_for_data(ptr,
> >                                                     drm_format_to_cairo(fb->drm_format),
> 
> Is there not a
> igt_require_f/igt_assert_f(cairo_surface_status(fb->cairo_surface) ==
> CAIRO_STATUS_SUCCESS,
> "Unable to create a cairo surface: %s",
> cairo_status_to_string(cairo_surface_status(fb->cairo_surface)));
> here?
> -Chris

Thanks Chris for the review.

No there wasn't a check like that but I guess I can add that instead of
checking for stride.
diff mbox series

Patch

diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index ba995a1a..2724e323 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -1349,6 +1349,9 @@  static void create_cairo_surface__gtt(int fd, struct igt_fb *fb)
 		ptr = gem_mmap__gtt(fd, fb->gem_handle, fb->size,
 				    PROT_READ | PROT_WRITE);
 
+	igt_require(fb->stride == cairo_format_stride_for_width(
+		drm_format_to_cairo(fb->drm_format), fb->width));
+
 	fb->cairo_surface =
 		cairo_image_surface_create_for_data(ptr,
 						    drm_format_to_cairo(fb->drm_format),