<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Mar 7, 2017 at 2:31 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"><div class="HOEnZb"><div class="h5">On 17-03-07 08:28:09, Jason Ekstrand wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Mon, Mar 6, 2017 at 6:37 PM, Ben Widawsky <<a href="mailto:ben@bwidawsk.net" target="_blank">ben@bwidawsk.net</a>> wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
v2: Make the error return be -1 instead of 0 because I think 0 is<br>
actually valid.<br>
<br>
v3: Set errno to EINVAL when the specified plane is above the total<br>
planes. (Jason Ekstrand)<br>
Return the bo's handle if there is no image ie. for dumb images like<br>
cursor (Daniel)<br>
<br>
Signed-off-by: Ben Widawsky <<a href="mailto:ben@bwidawsk.net" target="_blank">ben@bwidawsk.net</a>><br>
Acked-by: Daniel Stone <<a href="mailto:daniels@collabora.com" target="_blank">daniels@collabora.com</a>><br>
---<br>
 src/gbm/backends/dri/gbm_dri.<wbr>c | 35 ++++++++++++++++++++++++++++++<wbr>+++++<br>
 src/gbm/gbm-symbols-check      |  1 +<br>
 src/gbm/main/gbm.c             | 18 ++++++++++++++++++<br>
 src/gbm/main/gbm.h             |  3 +++<br>
 src/gbm/main/gbmint.h          |  1 +<br>
 5 files changed, 58 insertions(+)<br>
<br>
diff --git a/src/gbm/backends/dri/gbm_dri<wbr>.c b/src/gbm/backends/dri/gbm_<br>
dri.c<br>
index 0b75e411df..c3704e505b 100644<br>
--- a/src/gbm/backends/dri/gbm_dri<wbr>.c<br>
+++ b/src/gbm/backends/dri/gbm_dri<wbr>.c<br>
@@ -624,6 +624,40 @@ gbm_dri_bo_get_planes(struct gbm_bo *_bo)<br>
    return get_number_planes(dri, bo->image);<br>
 }<br>
<br>
+static union gbm_bo_handle<br>
+gbm_dri_bo_get_handle_for_pla<wbr>ne(struct gbm_bo *_bo, int plane)<br>
+{<br>
+   struct gbm_dri_device *dri = gbm_dri_device(_bo->gbm);<br>
+   struct gbm_dri_bo *bo = gbm_dri_bo(_bo);<br>
+   union gbm_bo_handle ret;<br>
+   ret.s32 = -1;<br>
+<br>
+   if (!dri->image || dri->image->base.version < 13 ||<br>
!dri->image->fromPlanar) {<br>
+      errno = ENOSYS;<br>
+      return ret;<br>
+   }<br>
+<br>
+   if (plane >= get_number_planes(dri, bo->image)) {<br>
+      errno = EINVAL;<br>
+      return ret;<br>
+   }<br>
+<br>
+   if (!bo->image) {<br>
+      ret.s32 = bo->handle;<br>
+      return ret;<br>
+   }<br>
+<br>
+   __DRIimage *image = dri->image->fromPlanar(bo->ima<wbr>ge, plane, NULL);<br>
+   if (!image) {<br>
+      /* Use the parent's handle */<br>
+      image = bo->image;<br>
<br>
</blockquote>
<br>
Assuming get_number_of_planes does the right thing, I think this is<br>
correct.  Would it make sense to add an assert(plane == 0) to this error<br>
case and the one above?<br>
<br>
<br>
</blockquote>
<br></div></div>
Let me claim ignorance...<br>
<br>
For "the one above": I thought it might be possible to have a planar dumb bo, in<br>
which case, the assertion wouldn't always hold. However, I have other code here<br>
which prevents that, so I think I'll modify the commit message, add some<br>
comments, and most importantly make a patch before this which prevents dumb BOs<br>
from being planar formats.<br>
<br>
For the !image case: this assertion should also hold, but since fromPlanar can<br>
be implemented however by the DRI implementation, I don't know if it's the right<br>
thing to add assertions in that path. I'm fine with adding it, I just claim some<br>
level of ignorance.<br></blockquote><div><br></div><div>Yes, the top one is definitely assert-worthy.  The bottom one maybe not?  For the bottom one, I guess I could see someone making fromPlanar as just return ref(bo->image) in which case maybe that's not safe?  Then again, if the implemented it that way, all of the planes would have to have the same offset/stride so the next two entrypoints would be toast.  It seems somewhat reasonable to assert for the second one too but I also must claim ignorance at this point. :-)<br></div></div></div></div>