<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sun, Feb 5, 2017 at 8:16 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"><span class="">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>
</span>v3: Fix DRIimage leak (using Jason's recommended change)<br>
Make plane 0 return planar stride. This might break legacy behavior (Jason)<br>
<br>
Cc: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br>
<span class="">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>
</span>make plane 0 with multi plane be normal (Jason)<br>
---<br>
src/gbm/backends/dri/gbm_dri.c | 45 ++++++++++++++++++++++++++++++<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, 57 insertions(+), 7 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 3d9c540d95..ecba3ead5a 100644<br>
--- a/src/gbm/backends/dri/gbm_<wbr>dri.c<br>
+++ b/src/gbm/backends/dri/gbm_<wbr>dri.c<br>
@@ -648,20 +648,53 @@ gbm_dri_bo_get_handle_for_<wbr>plane(struct gbm_bo *_bo, int plane)<br>
}<br>
<br>
__DRIimage *image = dri->image->fromPlanar(bo-><wbr>image, plane, NULL);<br>
- if (!image) {<br>
- /* Use the parent's handle */<br>
- image = bo->image;<br>
+ if (image) {<br>
+ dri->image->queryImage(image, __DRI_IMAGE_ATTRIB_HANDLE, &ret.s32);<br>
+ dri->image->destroyImage(<wbr>image);<br>
+ } else {<br>
+ dri->image->queryImage(bo-><wbr>image, __DRI_IMAGE_ATTRIB_HANDLE, &ret.s32);<br>
}<br>
<br>
- dri->image->queryImage(image, __DRI_IMAGE_ATTRIB_HANDLE, &ret.s32);<br>
-<br></blockquote><div><br></div><div>Wrong patch?<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
return ret;<br>
<span class=""> }<br>
<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>
</span><div><div class="h5">+ if (!dri->image || dri->image->base.version < 11 || !dri->image->fromPlanar) {<br>
+ /* Preserve legacy behavior if plane is 0 */<br>
+ if (plane == 0)<br>
+ return _bo->stride;<br>
+<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>
--<br>
</div></div>2.11.1<br>
<br>
</blockquote></div><br></div></div>