summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomeu Vizoso <tomeu.vizoso@collabora.com>2016-04-22 11:08:45 +0200
committerTomeu Vizoso <tomeu.vizoso@collabora.com>2016-05-31 15:31:48 +0200
commit7be235c1247a8cf51f55938ef05cb41708924b8f (patch)
tree345df874c292fb5cfcb00c53d95520b0e9f60142
parent303b380d728bc870c399ba46525854d323f894e7 (diff)
lib: Actually use provided size when creating BO
When reworking igt_create_fb_with_bo_size to use igt_create_bo_with_dimensions, we mistakenly stopped acknowledging non-zero size parameters. To fix this, we move the core of the code to create_bo_for_fb and teach it to use the GEM APIs when a size is passed. igt_create_bo_with_dimensions ends up calling just create_bo_for_fb with a zero size because now the later is more generic than the former. Also, create_bo_for_fb now returns the handle of the BO that was created, as there's no point anymore in having it be a parameter passed by reference. Signed-off-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
-rw-r--r--lib/igt_fb.c107
1 files changed, 50 insertions, 57 deletions
diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index 3e53d3b8c..61205f345 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -180,39 +180,24 @@ void igt_calc_fb_size(int fd, int width, int height, int bpp, uint64_t tiling,
*size_ret = size;
}
-/**
- * igt_create_bo_with_dimensions:
- * @fd: open drm file descriptor
- * @width: width of the buffer object in pixels
- * @height: height of the buffer object in pixels
- * @format: drm fourcc pixel format code
- * @modifier: modifier corresponding to the tiling layout of the buffer object
- * @stride: stride of the buffer object in bytes (0 for automatic stride)
- * @size_ret: size of the buffer object as created by the kernel
- * @stride_ret: stride of the buffer object as created by the kernel
- * @is_dumb: whether the created buffer object is a dumb buffer or not
- *
- * This function allocates a gem buffer object matching the requested
- * properties.
- *
- * Returns:
- * The kms id of the created buffer object.
- */
-int igt_create_bo_with_dimensions(int fd, int width, int height,
- uint32_t format, uint64_t modifier,
- unsigned stride, unsigned *size_ret,
- unsigned *stride_ret, bool *is_dumb)
+/* helpers to create nice-looking framebuffers */
+static int create_bo_for_fb(int fd, int width, int height, uint32_t format,
+ uint64_t tiling, unsigned size, unsigned stride,
+ unsigned *size_ret, unsigned *stride_ret,
+ bool *is_dumb)
{
int bpp = igt_drm_format_to_bpp(format);
int bo;
- if (modifier || stride) {
- unsigned size, calculated_stride;
+ if (tiling || size || stride) {
+ unsigned calculated_size, calculated_stride;
- igt_calc_fb_size(fd, width, height, bpp, modifier, &size,
- &calculated_stride);
+ igt_calc_fb_size(fd, width, height, bpp, tiling,
+ &calculated_size, &calculated_stride);
if (stride == 0)
stride = calculated_stride;
+ if (size == 0)
+ size = calculated_size;
if (is_dumb)
*is_dumb = false;
@@ -220,7 +205,7 @@ int igt_create_bo_with_dimensions(int fd, int width, int height,
if (is_i915_device(fd)) {
bo = gem_create(fd, size);
- gem_set_tiling(fd, bo, modifier, stride);
+ gem_set_tiling(fd, bo, tiling, stride);
if (size_ret)
*size_ret = size;
@@ -230,9 +215,9 @@ int igt_create_bo_with_dimensions(int fd, int width, int height,
return bo;
} else {
- bool driver_has_tiling_support = false;
+ bool driver_has_gem_api = false;
- igt_require(driver_has_tiling_support);
+ igt_require(driver_has_gem_api);
return -EINVAL;
}
} else {
@@ -244,23 +229,31 @@ int igt_create_bo_with_dimensions(int fd, int width, int height,
}
}
-/* helpers to create nice-looking framebuffers */
-static int create_bo_for_fb(int fd, int width, int height, uint32_t format,
- uint64_t tiling, unsigned bo_size,
- unsigned bo_stride, uint32_t *gem_handle_ret,
- unsigned *size_ret, unsigned *stride_ret,
- bool *is_dumb)
+/**
+ * igt_create_bo_with_dimensions:
+ * @fd: open drm file descriptor
+ * @width: width of the buffer object in pixels
+ * @height: height of the buffer object in pixels
+ * @format: drm fourcc pixel format code
+ * @modifier: modifier corresponding to the tiling layout of the buffer object
+ * @stride: stride of the buffer object in bytes (0 for automatic stride)
+ * @size_ret: size of the buffer object as created by the kernel
+ * @stride_ret: stride of the buffer object as created by the kernel
+ * @is_dumb: whether the created buffer object is a dumb buffer or not
+ *
+ * This function allocates a gem buffer object matching the requested
+ * properties.
+ *
+ * Returns:
+ * The kms id of the created buffer object.
+ */
+int igt_create_bo_with_dimensions(int fd, int width, int height,
+ uint32_t format, uint64_t modifier,
+ unsigned stride, unsigned *size_ret,
+ unsigned *stride_ret, bool *is_dumb)
{
- uint32_t gem_handle;
- int ret = 0;
-
- gem_handle = igt_create_bo_with_dimensions(fd, width, height, format,
- tiling, bo_stride, size_ret,
- stride_ret, is_dumb);
-
- *gem_handle_ret = gem_handle;
-
- return ret;
+ return create_bo_for_fb(fd, width, height, format, modifier, 0, stride,
+ size_ret, stride_ret, is_dumb);
}
/**
@@ -600,9 +593,10 @@ igt_create_fb_with_bo_size(int fd, int width, int height,
igt_debug("%s(width=%d, height=%d, format=0x%x, tiling=0x%"PRIx64", size=%d)\n",
__func__, width, height, format, tiling, bo_size);
- do_or_die(create_bo_for_fb(fd, width, height, format, tiling, bo_size,
- bo_stride, &fb->gem_handle, &fb->size,
- &fb->stride, &fb->is_dumb));
+ fb->gem_handle = create_bo_for_fb(fd, width, height, format, tiling,
+ bo_size, bo_stride, &fb->size,
+ &fb->stride, &fb->is_dumb);
+ igt_assert(fb->gem_handle > 0);
igt_debug("%s(handle=%d, pitch=%d)\n",
__func__, fb->gem_handle, fb->stride);
@@ -1006,7 +1000,6 @@ static void create_cairo_surface__blit(int fd, struct igt_fb *fb)
struct fb_blit_upload *blit;
cairo_format_t cairo_format;
unsigned int obj_tiling = fb_mod_to_obj_tiling(fb->tiling);
- int ret;
blit = malloc(sizeof(*blit));
igt_assert(blit);
@@ -1016,14 +1009,14 @@ static void create_cairo_surface__blit(int fd, struct igt_fb *fb)
* cairo). This linear bo will be then blitted to its final
* destination, tiling it at the same time.
*/
- ret = create_bo_for_fb(fd, fb->width, fb->height, fb->drm_format,
- LOCAL_DRM_FORMAT_MOD_NONE, 0, 0,
- &blit->linear.handle,
- &blit->linear.size,
- &blit->linear.stride,
- &blit->linear.is_dumb);
-
- igt_assert(ret == 0);
+ blit->linear.handle = create_bo_for_fb(fd, fb->width, fb->height,
+ fb->drm_format,
+ LOCAL_DRM_FORMAT_MOD_NONE, 0,
+ 0, &blit->linear.size,
+ &blit->linear.stride,
+ &blit->linear.is_dumb);
+
+ igt_assert(blit->linear.handle > 0);
blit->fd = fd;
blit->fb = fb;