dri2: change DRI2Buffer to enable multiplanar yuv
authorRicardo Salveti de Araujo <ricardo.salveti@linaro.org>
Thu, 23 Aug 2012 18:14:39 +0000 (15:14 -0300)
committerRob Clark <rob.clark@linaro.org>
Thu, 23 Aug 2012 18:24:01 +0000 (13:24 -0500)
Change DRI2Buffer to make names/pitches into an array to deal with
multiplanar yuv.

Based on the dri2video support patch by Rob Clark <rob@ti.com>

Signed-off-by: Ricardo Salveti de Araujo <ricardo.salveti@linaro.org>
include/X11/extensions/dri2.h
src/dri2.c
test/dri2-nouveau.c
test/dri2-omap.c
test/dri2test.c

index e42cdb675d2f04219434857c89277e2cabc7bed6..71c73341635435f18d0a959d8c7fe71a2fd590a7 100644 (file)
@@ -43,8 +43,8 @@
 typedef struct
 {
    unsigned int attachment;
-   unsigned int name;
-   unsigned int pitch;
+   unsigned int names[3];    /* unused entries set to zero.. non-planar formats only use names[0] */
+   unsigned int pitch[3];    /* unused entries set to zero.. non-planar formats only use pitch[0] */
    unsigned int cpp;
    unsigned int flags;
 } DRI2Buffer;
index 1154a9efecd2702a457d65686a96e2f788b016aa..f94736c9f99c845405b3e16681c8c598239fa173 100644 (file)
@@ -363,10 +363,9 @@ DRI2DestroyDrawable(Display * dpy, XID drawable)
    SyncHandle();
 }
 
-DRI2Buffer *
-DRI2GetBuffers(Display * dpy, XID drawable,
-               int *width, int *height,
-               unsigned int *attachments, int count, int *outCount)
+static DRI2Buffer *
+getbuffers(Display *dpy, XID drawable, int *width, int *height,
+               unsigned int *attachments, int count, int *outCount, int dri2ReqType)
 {
    XExtDisplayInfo *info = DRI2FindDisplay(dpy);
    xDRI2GetBuffersReply rep;
@@ -374,18 +373,27 @@ DRI2GetBuffers(Display * dpy, XID drawable,
    DRI2Buffer *buffers;
    xDRI2Buffer repBuffer;
    CARD32 *p;
-   int i;
+   int i, nattachments;
+
+   /* DRI2GetBuffersWithFormat has interleaved attachment+format in
+    * attachments[] array, so length of array is 2x as long..
+    */
+   if (dri2ReqType == X_DRI2GetBuffersWithFormat) {
+          nattachments = 2 * count;
+   } else {
+          nattachments = count;
+   }
 
    XextCheckExtension(dpy, info, dri2ExtensionName, False);
 
    LockDisplay(dpy);
-   GetReqExtra(DRI2GetBuffers, count * 4, req);
+   GetReqExtra(DRI2GetBuffers, nattachments * 4, req);
    req->reqType = info->codes->major_opcode;
-   req->dri2ReqType = X_DRI2GetBuffers;
+   req->dri2ReqType = dri2ReqType;
    req->drawable = drawable;
    req->count = count;
    p = (CARD32 *) & req[1];
-   for (i = 0; i < count; i++)
+   for (i = 0; i < nattachments; i++)
       p[i] = attachments[i];
 
    if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
@@ -398,21 +406,16 @@ DRI2GetBuffers(Display * dpy, XID drawable,
    *height = rep.height;
    *outCount = rep.count;
 
-   buffers = Xmalloc(rep.count * sizeof buffers[0]);
-   if (buffers == NULL) {
-      _XEatData(dpy, rep.count * sizeof repBuffer);
-      UnlockDisplay(dpy);
-      SyncHandle();
-      return NULL;
-   }
-
+   buffers = calloc(rep.count, sizeof buffers[0]);
    for (i = 0; i < rep.count; i++) {
       _XReadPad(dpy, (char *) &repBuffer, sizeof repBuffer);
-      buffers[i].attachment = repBuffer.attachment;
-      buffers[i].name = repBuffer.name;
-      buffers[i].pitch = repBuffer.pitch;
-      buffers[i].cpp = repBuffer.cpp;
-      buffers[i].flags = repBuffer.flags;
+      if (buffers) {
+         buffers[i].attachment = repBuffer.attachment;
+         buffers[i].names[0] = repBuffer.name;
+         buffers[i].pitch[0] = repBuffer.pitch;
+         buffers[i].cpp = repBuffer.cpp;
+         buffers[i].flags = repBuffer.flags;
+      }
    }
 
    UnlockDisplay(dpy);
@@ -421,63 +424,22 @@ DRI2GetBuffers(Display * dpy, XID drawable,
    return buffers;
 }
 
+DRI2Buffer *
+DRI2GetBuffers(Display * dpy, XID drawable,
+               int *width, int *height,
+               unsigned int *attachments, int count, int *outCount)
+{
+       return getbuffers(dpy, drawable, width, height, attachments,
+                       count, outCount, X_DRI2GetBuffers);
+}
 
 DRI2Buffer *
 DRI2GetBuffersWithFormat(Display * dpy, XID drawable,
                          int *width, int *height,
                          unsigned int *attachments, int count, int *outCount)
 {
-   XExtDisplayInfo *info = DRI2FindDisplay(dpy);
-   xDRI2GetBuffersReply rep;
-   xDRI2GetBuffersReq *req;
-   DRI2Buffer *buffers;
-   xDRI2Buffer repBuffer;
-   CARD32 *p;
-   int i;
-
-   XextCheckExtension(dpy, info, dri2ExtensionName, False);
-
-   LockDisplay(dpy);
-   GetReqExtra(DRI2GetBuffers, count * (4 * 2), req);
-   req->reqType = info->codes->major_opcode;
-   req->dri2ReqType = X_DRI2GetBuffersWithFormat;
-   req->drawable = drawable;
-   req->count = count;
-   p = (CARD32 *) & req[1];
-   for (i = 0; i < (count * 2); i++)
-      p[i] = attachments[i];
-
-   if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
-      UnlockDisplay(dpy);
-      SyncHandle();
-      return NULL;
-   }
-
-   *width = rep.width;
-   *height = rep.height;
-   *outCount = rep.count;
-
-   buffers = Xmalloc(rep.count * sizeof buffers[0]);
-   if (buffers == NULL) {
-      _XEatData(dpy, rep.count * sizeof repBuffer);
-      UnlockDisplay(dpy);
-      SyncHandle();
-      return NULL;
-   }
-
-   for (i = 0; i < rep.count; i++) {
-      _XReadPad(dpy, (char *) &repBuffer, sizeof repBuffer);
-      buffers[i].attachment = repBuffer.attachment;
-      buffers[i].name = repBuffer.name;
-      buffers[i].pitch = repBuffer.pitch;
-      buffers[i].cpp = repBuffer.cpp;
-      buffers[i].flags = repBuffer.flags;
-   }
-
-   UnlockDisplay(dpy);
-   SyncHandle();
-
-   return buffers;
+       return getbuffers(dpy, drawable, width, height, attachments,
+                       count, outCount, X_DRI2GetBuffersWithFormat);
 }
 
 
index f91cc4877e86ed59f5e6454764cc97cf68052f1a..52de35e9d5d2a6c71956a0b44e98093ae6847ee7 100644 (file)
@@ -52,7 +52,7 @@ static void setup(int fd)
 static void * init(DRI2Buffer *dri2buf)
 {
        struct nouveau_bo *bo = NULL;
-       int ret = nouveau_bo_handle_ref(dev, dri2buf->name, &bo);
+       int ret = nouveau_bo_handle_ref(dev, dri2buf->names[0], &bo);
        if (ret) {
                ERROR_MSG("nouveau_bo_handle_ref failed: %d", ret);
                return NULL;
index 181599dd3a783212d6d408ebed74bcae335bef32..2bcff283b48e12a7d03157ca88e0f7aefda2ebbd 100644 (file)
@@ -48,7 +48,7 @@ static void setup(int fd)
 
 static void * init(DRI2Buffer *dri2buf)
 {
-       return omap_bo_from_name(dev, dri2buf->name);
+       return omap_bo_from_name(dev, dri2buf->names[0]);
 }
 
 static char * prep(void *hdl)
index 1aa101d23d597ad4c50bc3c8adfba57b7fda38af..ec74e813b8c8b4483a761bdf448da6e837fa69c9 100644 (file)
@@ -48,7 +48,7 @@ static void fill(char *virtual, int n, int width, int height, int stride)
     for (j = 0; j < height; j++) {
             uint32_t *fb_ptr = (uint32_t*)((char*)virtual + j * stride);
             for (i = 0; i < width; i++) {
-                    div_t d = div(n+i, width);
+                    div_t d = div(n+i+j, width);
                     fb_ptr[i] =
                             0x00130502 * (d.quot >> 6) +
                             0x000a1120 * (d.rem >> 6);
@@ -109,7 +109,7 @@ int main(int argc, char **argv)
                CARD64 count;
 
                char *buf = backend->prep(bufs[i % nbufs].hdl);
-               fill(buf, i, w, h, bufs[i % nbufs].dri2buf->pitch);
+               fill(buf, i, w, h, bufs[i % nbufs].dri2buf->pitch[0]);
                backend->fini(bufs[i % nbufs].hdl);
                DRI2SwapBuffers(dpy, win, 0, 0, 0, &count);
                MSG("DRI2SwapBuffers: count=%lu", count);