<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Jan 23, 2017 at 10:19 PM, Ben Widawsky <span dir="ltr"><<a href="mailto:ben@bwidawsk.net" target="_blank">ben@bwidawsk.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">v2: Preserve legacy behavior when plane is 0 (Jason Ekstrand)<br>
EINVAL when input plane is greater than total planes (Jason Ekstrand)<br>
Don't leak the image after fromPlanar (Daniel)<br>
Move bo->image check below plane count preventing bad index succeeding (Daniel)<br>
<br>
Signed-off-by: Ben Widawsky <<a href="mailto:ben@bwidawsk.net">ben@bwidawsk.net</a>><br>
Reviewed-by: Eric Engestrom <<a href="mailto:eric.engestrom@imgtec.com">eric.engestrom@imgtec.com</a>> (v1)<br>
Acked-by: Daniel Stone <<a href="mailto:daniels@collabora.com">daniels@collabora.com</a>><br>
---<br>
src/gbm/backends/dri/gbm_dri.c | 35 ++++++++++++++++++++++++++++++<wbr>++++-<br>
src/gbm/gbm-symbols-check | 1 +<br>
src/gbm/main/gbm.c | 15 ++++++++++++++-<br>
src/gbm/main/gbm.h | 3 +++<br>
4 files changed, 52 insertions(+), 2 deletions(-)<br>
<br>
diff --git a/src/gbm/backends/dri/gbm_<wbr>dri.c b/src/gbm/backends/dri/gbm_<wbr>dri.c<br>
index f055a665db..395f78e851 100644<br>
--- a/src/gbm/backends/dri/gbm_<wbr>dri.c<br>
+++ b/src/gbm/backends/dri/gbm_<wbr>dri.c<br>
@@ -661,7 +661,40 @@ gbm_dri_bo_get_handle_for_<wbr>plane(struct gbm_bo *_bo, int plane)<br>
static uint32_t<br>
gbm_dri_bo_get_stride(struct gbm_bo *_bo, int plane)<br>
{<br>
- return _bo->stride;<br>
+ struct gbm_dri_device *dri = gbm_dri_device(_bo->gbm);<br>
+ struct gbm_dri_bo *bo = gbm_dri_bo(_bo);<br>
+ __DRIimage *image;<br>
+ int stride = 0;<br>
+<br>
+ /* Preserve legacy behavior if plane is 0 */<br>
+ if (plane == 0)<br>
+ return _bo->stride;<br></blockquote><div><br></div><div>This implies that, for multi-planar images, you have to have the BO stride be the same as the image stride. Do we want this or do we only want to return bo->stride if we don't have enough DRI stuff (in the if below) to use the image? I think it's probably ok either way.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
+ if (!dri->image || dri->image->base.version < 11 || !dri->image->fromPlanar) {<br>
+ errno = ENOSYS;<br>
+ return 0;<br>
+ }<br>
+<br>
+ if (plane >= get_number_planes(dri, bo->image)) {<br>
+ errno = EINVAL;<br>
+ return 0;<br>
+ }<br>
+<br>
+ if (bo->image == NULL)<br>
+ return _bo->stride;<br>
+<br>
+ image = dri->image->fromPlanar(bo-><wbr>image, plane, NULL);<br>
+ if (!image) {<br>
+ /* Use the parent stride */<br>
+ image = bo->image;<br>
+ }<br>
+<br>
+ dri->image->queryImage(image, __DRI_IMAGE_ATTRIB_STRIDE, &stride);<br>
+<br>
+ if (image != bo->image)<br>
+ dri->image->destroyImage(<wbr>image);<br>
+<br>
+ return (uint32_t)stride;<br>
}<br>
<br>
static void<br>
diff --git a/src/gbm/gbm-symbols-check b/src/gbm/gbm-symbols-check<br>
index 1e6dd4d3ec..459006a63f 100755<br>
--- a/src/gbm/gbm-symbols-check<br>
+++ b/src/gbm/gbm-symbols-check<br>
@@ -14,6 +14,7 @@ gbm_bo_unmap<br>
gbm_bo_get_width<br>
gbm_bo_get_height<br>
gbm_bo_get_stride<br>
+gbm_bo_get_stride_for_plane<br>
gbm_bo_get_format<br>
gbm_bo_get_device<br>
gbm_bo_get_handle<br>
diff --git a/src/gbm/main/gbm.c b/src/gbm/main/gbm.c<br>
index 7462e90c4c..0a9f0bef7e 100644<br>
--- a/src/gbm/main/gbm.c<br>
+++ b/src/gbm/main/gbm.c<br>
@@ -165,7 +165,20 @@ gbm_bo_get_height(struct gbm_bo *bo)<br>
GBM_EXPORT uint32_t<br>
gbm_bo_get_stride(struct gbm_bo *bo)<br>
{<br>
- return bo->gbm->bo_get_stride(bo, 0);<br>
+ return gbm_bo_get_stride_for_plane(<wbr>bo, 0);<br>
+}<br>
+<br>
+/** Get the stride for the given plane<br>
+ *<br>
+ * \param bo The buffer object<br>
+ * \param plane for which you want the stride<br>
+ *<br>
+ * \sa gbm_bo_get_stride()<br>
+ */<br>
+GBM_EXPORT uint32_t<br>
+gbm_bo_get_stride_for_plane(<wbr>struct gbm_bo *bo, int plane)<br>
+{<br>
+ return bo->gbm->bo_get_stride(bo, plane);<br>
}<br>
<br>
/** Get the format of the buffer object<br>
diff --git a/src/gbm/main/gbm.h b/src/gbm/main/gbm.h<br>
index 67548206c4..1719c5312a 100644<br>
--- a/src/gbm/main/gbm.h<br>
+++ b/src/gbm/main/gbm.h<br>
@@ -304,6 +304,9 @@ uint32_t<br>
gbm_bo_get_stride(struct gbm_bo *bo);<br>
<br>
uint32_t<br>
+gbm_bo_get_stride_for_plane(<wbr>struct gbm_bo *bo, int plane);<br>
+<br>
+uint32_t<br>
gbm_bo_get_format(struct gbm_bo *bo);<br>
<br>
struct gbm_device *<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.11.0<br>
<br>
______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div>