<div dir="ltr">Right, the DRI2 case need to get name or get handle of a pixmap, for traditional xserver,<div>as it always share the same fd and in the same process, get handle should be good</div><div>enough. I'm not familiar with xwayland. Is it also enough for the Xwayland to get a pixmap's</div>
<div>handle for the DRI2 case?</div><div><br></div><div>I just checked the intel video driver, and it seems the DRI3 support is not merged to the upstream.</div><div>I found that Keith already implemented the DRI3 for UXA driver on his personal repository's dri3</div>
<div>branch. I understand that your focus is xwayland currently, but if you can verify these new APIs on</div><div>traditional xserver platform, it will be very convenient to test and verify.  That will need some extra</div>
<div>effort to add glamor support to the dri3 branch's intel_dri3.c.</div><div><br></div><div>Thanks,</div><div>Zhigang Gong.</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Nov 23, 2013 at 9:19 PM,  <span dir="ltr"><<a href="mailto:davyaxel@free.fr" target="_blank">davyaxel@free.fr</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 23/11/2013, zhigang gong wrote :<br>
<div class="im">> At the time I developed glamor, the extension of creating egl image from gl texture was<br>
> not implemented in mesa. Now mesa already supported it,  and we can provide these new<br>
> APIs to DDR driver. Just as you said, we may need a new API in libglamor.so to query a<br>
> pixmap's type and texture unit id, then we don't need to access the pixmap's private data<br>
> structure.<br>
> The new API you implemented will give DDR a chance to support DRI more efficiently.<br>
> Currently, when the client want to create a dri2 buffer on a textured only pixmap, it will<br>
> trigger a glamor_fixup function to create a new textured_drm pixmap and then copy the<br>
> old buffer to this new buffer. Now we can avoid this extra copy with this new API at that<br>
> case.<br>
> Thanks,<br>
> Zhigang Gong.<br>
<br>
</div>The other dri3 helper could look like that:<br>
<br>
PixmapPtr  glamor_egl_get_pixmap_from_fd (ScreenPtr screen,<br>
                                          int fd,<br>
                                          int width,<br>
                                          int height,<br>
                                          int stride,<br>
                                          int depth,<br>
                                          int bpp)<br>
{<br>
  PixmapPtr pixmap;<br>
<div class="im">  struct glamor_egl_screen_private *glamor_egl;<br>
  EGLImageKHR image;<br>
</div><div class="im">  struct gbm_bo* bo;<br>
  EGLint attribs[] = {<br>
</div>        EGL_WIDTH, 0,<br>
        EGL_HEIGHT, 0,<br>
        EGL_LINUX_DRM_FOURCC_EXT, 0,<br>
        EGL_DMA_BUF_PLANE0_FD_EXT, 0,<br>
        EGL_DMA_BUF_PLANE0_OFFSET_EXT, 0,<br>
        EGL_DMA_BUF_PLANE0_PITCH_EXT, 0,<br>
        EGL_NONE<br>
    };<br>
   ScrnInfoPtr scrn = xf86ScreenToScrn(screen);<br>
   glamor_egl = glamor_egl_get_screen_private(scrn);<br>
<br>
/* we have no way to choose between RGB or others. Favor RGB */<br>
<br>
  switch(bpp){<br>
    case 16:<br>
      if (depth == 16)<br>
          attribs[5] = DRM_FORMAT_RGB565;<br>
      break;<br>
    case 24:<br>
      if (depth == 24)<br>
        attribs[5] = DRM_FORMAT_RGB888;<br>
      break;<br>
    case 32:<br>
      if (depth == 24)<br>
        attribs [5] = DRM_FORMAT_XRGB8888;<br>
      else if (depth == 32)<br>
        attribs [5] = DRM_FORMAT_ARGB8888;<br>
  }<br>
  if (attribs[5] == 0 || width==0 || height == 0)<br>
    goto failure;<br>
<br>
  pixmap = fbCreatePixmap(screen, 0, 0, depth, 0);<br>
  attribs[1] = width;<br>
  attribs[3] = height;<br>
  attribs[7] = fd;<br>
  attribs[11] = stride;<br>
  screen->ModifyPixmapHeader (pixmap, width, height, 0, 0,<br>
                  stride, NULL);<br>
<div class="im"><br>
  image = glamor_egl->egl_create_image_khr(glamor_egl->display,<br>
</div>                                                                       EGL_NO_CONTEXT,<br>
                                                                       EGL_LINUX_DMA_BUF_EXT,<br>
                                                                       NULL, attribs);<br>
  if (image == EGL_NO_IMAGE_KHR)<br>
    goto destroy_pixmap;<br>
  /* images imported with EGL_LINUX_DMA_BUF_EXT have<br>
      restrictions about their use, since they can potentially<br>
      be of YUV format. Convert to gbm_bo, which accepts<br>
      only non YUV formats, and then do not share the same<br>
      limitations */<br>
<div class="im">  bo = gbm_bo_import(glamor_egl->gbm,GBM_BO_IMPORT_EGL_IMAGE,image,0);<br>
  glamor_egl->egl_destroy_image_khr(glamor_egl->display, image);<br>
</div>  if(!bo)<br>
    goto destroy_pixmap;<br>
  if(!glamor_egl_create_textured_pixmap_from_gbm_bo(pixmap, bo))<br>
    goto destroy_bo;<br>
  gbm_bo_destroy(bo);<br>
  return pixmap;<br>
<br>
destroy_bo:<br>
  gbm_bo_destroy(bo);<br>
destroy_pixmap:<br>
  fbDestroyPixmap(pixmap);<br>
failure:<br>
  return NULL;<br>
}<br>
<br>
For the dri2 use case you mention,<br>
It'll probably need a glamor_egl_get_name_from_pixmap.<br>
<br>
<br>
Axel Davy<br>
<div class="HOEnZb"><div class="h5"><br>
> On Fri, Nov 22, 2013 at 6:45 AM, <<a href="mailto:davyaxel@free.fr">davyaxel@free.fr</a>> wrote:<br>
><br>
>     Hi,<br>
><br>
>     I've got pixmap->fd working with this experimental function (on intel):<br>
><br>
>     Bool glamor_egl_get_fd_from_pixmap(PixmapPtr pixmap, int* fd)<br>
>     {<br>
>       struct glamor_pixmap_private * priv = glamor_get_pixmap_private(pixmap);<br>
>       ScreenPtr screen = pixmap->drawable.pScreen;<br>
>       ScrnInfoPtr scrn = xf86ScreenToScrn(screen);<br>
>       struct glamor_egl_screen_private *glamor_egl;<br>
>       EGLImageKHR image;<br>
>       GLuint texture;<br>
>       Bool ret = FALSE;<br>
>       struct gbm_bo* bo;<br>
>       EGLint attribs[] = {<br>
>             EGL_IMAGE_PRESERVED_KHR, EGL_TRUE,<br>
>             EGL_GL_TEXTURE_LEVEL_KHR, 0,<br>
>             EGL_NONE<br>
>       };<br>
><br>
>       glamor_egl = glamor_egl_get_screen_private(scrn);<br>
>       switch (priv->type)<br>
>       {<br>
>         case GLAMOR_TEXTURE_DRM:<br>
>         case GLAMOR_TEXTURE_ONLY:<br>
>            glamor_egl_make_current(screen);<br>
>            image = glamor_egl->egl_create_image_khr(glamor_egl->display,<br>
>                              glamor_egl->context,<br>
>                              EGL_GL_TEXTURE_2D_KHR,<br>
>                              priv->base.fbo->tex, attribs);<br>
>            if (image == EGL_NO_IMAGE_KHR)<br>
>             goto leave;<br>
>            bo = gbm_bo_import(glamor_egl->gbm,GBM_BO_IMPORT_EGL_IMAGE,image,0);<br>
>            glamor_egl->egl_destroy_image_khr(glamor_egl->display, image);<br>
>            ret = glamor_get_fd_from_bo(glamor_egl->fd,bo,fd);<br>
>            if(ret)<br>
>            {<br>
>               glamor_set_pixmap_type(pixmap, GLAMOR_TEXTURE_DRM);<br>
>               pixmap->devKind = gbm_bo_get_stride(bo);<br>
>            }<br>
>            gbm_bo_destroy(bo);<br>
>            break;<br>
>         default: return 0;<br>
>       }<br>
>       leave:<br>
>       glamor_egl_restore_context(screen);<br>
>             return ret;<br>
>     }<br>
><br>
>     int<br>
>     glamor_get_fd_from_bo (int gbm_fd, struct gbm_bo *bo, int *fd)<br>
>     {<br>
>       union gbm_bo_handle handle;<br>
>       struct drm_prime_handle args;<br>
><br>
>       handle = gbm_bo_get_handle(bo);<br>
>       args.handle = handle.u32;<br>
>       args.flags = DRM_CLOEXEC;<br>
>       if (ioctl (gbm_fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &args))<br>
>         return FALSE;<br>
>       *fd = args.fd;<br>
>       return TRUE;<br>
>     }<br>
><br>
><br>
>     Of course there are some missing checks, etc.<br>
>     And it needs glamor_egl.c has access to the glamor_pixmap_private to get the texture.<br>
>     I think it would be better to have a function glamor_get_pixmap_texture_number that glamor_egl would have access to.<br>
><br>
>     Feel free to add comments<br>
><br>
>     Axel Davy<br>
>     _______________________________________________<br>
>     Glamor mailing list<br>
>     <a href="mailto:Glamor@lists.freedesktop.org">Glamor@lists.freedesktop.org</a><br>
>     <a href="http://lists.freedesktop.org/mailman/listinfo/glamor" target="_blank">http://lists.freedesktop.org/mailman/listinfo/glamor</a><br>
><br>
</div></div></blockquote></div><br></div>