If the caller is going to specify a custom size, it's likely that he
will also specify a custom stride. The automatic stride picked by
create_bo_for_fb() is too huge for tiled buffers, so if the caller
wants smaller buffers, then he'll need a smaller stride too, otherwise
the Kernel will reject the addfb IOCTL due to stride * height being
bigger than the size.

I want to make tests/kms_frontbuffer_tracking use
igt_create_fb_with_bo_size() so I can provide smaller buffers that
will fit into the CFB. I'm also planning to make all frontbuffers with
the same width/height/format have the same stride and size regardless
of tiling method so I can exercise specific code paths.

Signed-off-by: Paulo Zanoni <paulo.r.zan...@intel.com>
---
 lib/igt_fb.c     | 25 ++++++++++++++++---------
 lib/igt_fb.h     |  3 ++-
 tests/kms_flip.c |  2 +-
 3 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index 2818c9f..3ea9915 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -76,9 +76,8 @@ static struct format_desc_struct {
 /* helpers to create nice-looking framebuffers */
 static int create_bo_for_fb(int fd, int width, int height, int bpp,
                            uint64_t tiling, unsigned bo_size,
-                           uint32_t *gem_handle_ret,
-                           unsigned *size_ret,
-                           unsigned *stride_ret)
+                           unsigned bo_stride, uint32_t *gem_handle_ret,
+                           unsigned *size_ret, unsigned *stride_ret)
 {
        uint32_t gem_handle;
        int size, ret = 0;
@@ -110,12 +109,16 @@ static int create_bo_for_fb(int fd, int width, int 
height, int bpp,
 
        if (bo_size == 0)
                bo_size = size;
+       if (bo_stride == 0)
+               bo_stride = stride;
+
        gem_handle = gem_create(fd, bo_size);
 
        if (tiling == LOCAL_I915_FORMAT_MOD_X_TILED)
-               ret = __gem_set_tiling(fd, gem_handle, I915_TILING_X, stride);
+               ret = __gem_set_tiling(fd, gem_handle, I915_TILING_X,
+                                      bo_stride);
 
-       *stride_ret = stride;
+       *stride_ret = bo_stride;
        *size_ret = bo_size;
        *gem_handle_ret = gem_handle;
 
@@ -401,6 +404,7 @@ void igt_paint_image(cairo_t *cr, const char *filename,
  * @tiling: tiling layout of the framebuffer (as framebuffer modifier)
  * @fb: pointer to an #igt_fb structure
  * @bo_size: size of the backing bo (0 for automatic size)
+ * @bo_stride: stride of the backing bo (0 for automatic stride)
  *
  * This function allocates a gem buffer object suitable to back a framebuffer
  * with the requested properties and then wraps it up in a drm framebuffer
@@ -415,7 +419,8 @@ void igt_paint_image(cairo_t *cr, const char *filename,
 unsigned int
 igt_create_fb_with_bo_size(int fd, int width, int height,
                           uint32_t format, uint64_t tiling,
-                          struct igt_fb *fb, unsigned bo_size)
+                          struct igt_fb *fb, unsigned bo_size,
+                          unsigned bo_stride)
 {
        uint32_t fb_id;
        int bpp;
@@ -427,7 +432,8 @@ igt_create_fb_with_bo_size(int fd, int width, int height,
        igt_debug("%s(width=%d, height=%d, format=0x%x [bpp=%d], 
tiling=0x%"PRIx64", size=%d)\n",
                  __func__, width, height, format, bpp, tiling, bo_size);
        do_or_die(create_bo_for_fb(fd, width, height, bpp, tiling, bo_size,
-                                  &fb->gem_handle, &fb->size, &fb->stride));
+                                  bo_stride, &fb->gem_handle, &fb->size,
+                                  &fb->stride));
 
        igt_debug("%s(handle=%d, pitch=%d)\n",
                  __func__, fb->gem_handle, fb->stride);
@@ -485,7 +491,8 @@ igt_create_fb_with_bo_size(int fd, int width, int height,
 unsigned int igt_create_fb(int fd, int width, int height, uint32_t format,
                           uint64_t tiling, struct igt_fb *fb)
 {
-       return igt_create_fb_with_bo_size(fd, width, height, format, tiling, 
fb, 0);
+       return igt_create_fb_with_bo_size(fd, width, height, format, tiling, fb,
+                                         0, 0);
 }
 
 /**
@@ -714,7 +721,7 @@ static void create_cairo_surface__blit(int fd, struct 
igt_fb *fb)
         */
        bpp = igt_drm_format_to_bpp(fb->drm_format);
        ret = create_bo_for_fb(fd, fb->width, fb->height, bpp,
-                               LOCAL_DRM_FORMAT_MOD_NONE, 0,
+                               LOCAL_DRM_FORMAT_MOD_NONE, 0, 0,
                                &blit->linear.handle,
                                &blit->linear.size,
                                &blit->linear.stride);
diff --git a/lib/igt_fb.h b/lib/igt_fb.h
index a07acd2..37892b5 100644
--- a/lib/igt_fb.h
+++ b/lib/igt_fb.h
@@ -72,7 +72,8 @@ enum igt_text_align {
 unsigned int
 igt_create_fb_with_bo_size(int fd, int width, int height,
                           uint32_t format, uint64_t tiling,
-                          struct igt_fb *fb, unsigned bo_size);
+                          struct igt_fb *fb, unsigned bo_size,
+                          unsigned bo_stride);
 unsigned int igt_create_fb(int fd, int width, int height, uint32_t format,
                           uint64_t tiling, struct igt_fb *fb);
 unsigned int igt_create_color_fb(int fd, int width, int height,
diff --git a/tests/kms_flip.c b/tests/kms_flip.c
index e1b5856..e65fef2 100644
--- a/tests/kms_flip.c
+++ b/tests/kms_flip.c
@@ -1390,7 +1390,7 @@ static void run_test_on_crtc_set(struct test_output *o, 
int *crtc_idxs,
                                         tiling, &o->fb_info[0]);
        o->fb_ids[1] = igt_create_fb_with_bo_size(drm_fd, o->fb_width, 
o->fb_height,
                                         igt_bpp_depth_to_drm_format(o->bpp, 
o->depth),
-                                        tiling, &o->fb_info[1], bo_size);
+                                        tiling, &o->fb_info[1], bo_size, 0);
        o->fb_ids[2] = igt_create_fb(drm_fd, o->fb_width, o->fb_height,
                                         igt_bpp_depth_to_drm_format(o->bpp, 
o->depth),
                                         LOCAL_I915_FORMAT_MOD_X_TILED, 
&o->fb_info[2]);
-- 
2.6.2

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

Reply via email to