From 759e89065f87fd138bdaee001a467632dc8c04e0 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sun, 13 Sep 2009 19:53:47 +0100 Subject: Fix glamoCreateBuffer(s) (for DRI2) --- src/glamo-dri2.c | 167 +++++++++++++++++++++++++++++++++++++++++----------- src/glamo-kms-exa.c | 5 -- src/glamo-kms-exa.h | 4 ++ 3 files changed, 135 insertions(+), 41 deletions(-) diff --git a/src/glamo-dri2.c b/src/glamo-dri2.c index 286094a..70b9d93 100644 --- a/src/glamo-dri2.c +++ b/src/glamo-dri2.c @@ -32,6 +32,36 @@ * * Author: Alan Hourihane * + * + * Also based partially on xf86-video-ati, to which the following + * notice applies: + * + * Copyright 2008 Kristian Høgsberg + * Copyright 2008 Jérôme Glisse + * + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation on the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NON-INFRINGEMENT. IN NO EVENT SHALL ATI, VA LINUX SYSTEMS AND/OR + * THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * */ @@ -46,37 +76,92 @@ #include #include #include +#include #include "glamo.h" #include "glamo-dri2.h" #include "glamo-kms-exa.h" -typedef struct { - PixmapPtr pPixmap; -} GlamoDRI2BufferPrivateRec, *GlamoDRI2BufferPrivatePtr; +struct glamo_dri2_buffer_priv { + PixmapPtr pixmap; + unsigned int attachment; +}; #if DRI2INFOREC_VERSION >= 3 -static DRI2BufferPtr glamoCreateBuffer(DrawablePtr pDraw, +static DRI2BufferPtr glamoCreateBuffer(DrawablePtr drawable, unsigned int attachment, unsigned int format) { + ScreenPtr pScreen = drawable->pScreen; DRI2BufferPtr buffer; + struct glamo_dri2_buffer_priv *private; + PixmapPtr pixmap; + struct glamo_exa_pixmap_priv *driver_priv; + int r; + + buffer = xcalloc(1, sizeof(*buffer)); + if (buffer == NULL) { + return NULL; + } + private = xcalloc(1, sizeof(*private)); + if (private == NULL) { + xfree(buffer); + return NULL; + } + + if ( attachment == DRI2BufferFrontLeft ) { + if ( drawable->type == DRAWABLE_PIXMAP ) { + pixmap = (PixmapPtr)drawable; + } else { + pixmap = pScreen->GetWindowPixmap((WindowPtr)drawable); + } + pixmap->refcnt++; + } else { + pixmap = pScreen->CreatePixmap(pScreen, + drawable->width, + drawable->height, + (format != 0)?format:drawable->depth, + 0); + } + exaMoveInPixmap(pixmap); + driver_priv = exaGetPixmapDriverPrivate(pixmap); + if ( !driver_priv ) { + xfree(buffer); + xfree(private); + return NULL; + } + r = glamo_gem_name_buffer(driver_priv->bo, &buffer->name); + if (r) { + fprintf(stderr, "Couldn't name buffer: %d %s\n", + r, strerror(r)); + xfree(buffer); + xfree(private); + return NULL; + } + buffer->attachment = attachment; + buffer->pitch = pixmap->devKind; + buffer->cpp = pixmap->drawable.bitsPerPixel / 8; + buffer->driverPrivate = private; + buffer->format = format; + buffer->flags = 0; + private->pixmap = pixmap; + private->attachment = attachment; + return buffer; } #else -static DRI2BufferPtr glamoCreateBuffers(DrawablePtr pDraw, +static DRI2BufferPtr glamoCreateBuffers(DrawablePtr drawable, unsigned int *attachments, int count) { - ScreenPtr pScreen = pDraw->pScreen; - DRI2BufferPtr buffers; + ScreenPtr pScreen = drawable->pScreen; int i; - GlamoDRI2BufferPrivatePtr privates; - PixmapPtr pPixmap, pDepthPixmap; + DRI2BufferPtr buffers; + struct glamo_dri2_buffer_priv *privates; buffers = xcalloc(count, sizeof *buffers); if ( buffers == NULL ) return NULL; @@ -86,41 +171,51 @@ static DRI2BufferPtr glamoCreateBuffers(DrawablePtr pDraw, return NULL; } - pDepthPixmap = NULL; /* For each attachment */ for ( i=0; itype == DRAWABLE_PIXMAP ) { - pPixmap = (PixmapPtr)pDraw; + if ( attachments[i] == DRI2BufferFrontLeft ) { + if ( drawable->type == DRAWABLE_PIXMAP ) { + pixmap = (PixmapPtr)drawable; } else { - pPixmap = (*pScreen->GetWindowPixmap)( - (WindowPtr)pDraw); + pixmap = pScreen->GetWindowPixmap( + (WindowPtr)drawable); } - pPixmap->refcnt++; - + pixmap->refcnt++; } else { - - /* Anything else - create a new pixmap */ - pPixmap = (*pScreen->CreatePixmap)(pScreen, - pDraw->width, - pDraw->height, - pDraw->depth, - 0); - + pixmap = pScreen->CreatePixmap(pScreen, + drawable->width, + drawable->height, + drawable->depth, + 0); + } + exaMoveInPixmap(pixmap); + driver_priv = exaGetPixmapDriverPrivate(pixmap); + if ( !driver_priv ) { + xfree(buffers); + xfree(privates); + return NULL; + } + r = glamo_gem_name_buffer(driver_priv->bo, &buffers[i].name); + if (r) { + fprintf(stderr, "Couldn't name buffer: %d %s\n", + r, strerror(r)); + xfree(buffers); + xfree(privates); + return NULL; } - - if ( attachments[i] == DRI2BufferDepth ) pDepthPixmap = pPixmap; - - /* Set up the return data structure */ buffers[i].attachment = attachments[i]; - buffers[i].pitch = pPixmap->devKind; - buffers[i].cpp = pPixmap->drawable.bitsPerPixel / 8; + buffers[i].pitch = pixmap->devKind; + buffers[i].cpp = pixmap->drawable.bitsPerPixel / 8; buffers[i].driverPrivate = &privates[i]; + buffers[i].format = drawable->depth; buffers[i].flags = 0; - privates[i].pPixmap = pPixmap; + privates[i].pixmap = pixmap; + privates[i].attachment = attachments[i]; } @@ -135,10 +230,10 @@ static void glamoDestroyBuffer(DrawablePtr pDraw, DRI2BufferPtr buffer) { ScreenPtr pScreen = pDraw->pScreen; - GlamoDRI2BufferPrivatePtr private; + struct glamo_dri2_buffer_priv *private; private = buffer->driverPrivate; - (*pScreen->DestroyPixmap)(private->pPixmap); + pScreen->DestroyPixmap(private->pixmap); if ( buffer ) { xfree(buffer->driverPrivate); @@ -156,7 +251,7 @@ static void glamoDestroyBuffers(DrawablePtr pDraw, for ( i=0; iDestroyPixmap)(private->pPixmap); + pScreen->DestroyPixmap(private->pixmap); } if ( buffers ) { diff --git a/src/glamo-kms-exa.c b/src/glamo-kms-exa.c index 87839c7..557ba60 100644 --- a/src/glamo-kms-exa.c +++ b/src/glamo-kms-exa.c @@ -74,11 +74,6 @@ #endif -struct glamo_exa_pixmap_priv { - struct glamo_bo *bo; -}; - - static const CARD8 GLAMOSolidRop[16] = { /* GXclear */ 0x00, /* 0 */ /* GXand */ 0xa0, /* src AND dst */ diff --git a/src/glamo-kms-exa.h b/src/glamo-kms-exa.h index b39878a..0473b3b 100644 --- a/src/glamo-kms-exa.h +++ b/src/glamo-kms-exa.h @@ -22,6 +22,10 @@ #include "xf86.h" +struct glamo_exa_pixmap_priv { + struct glamo_bo *bo; +}; + extern void GlamoKMSExaInit(ScrnInfoPtr pScrn); extern void GlamoKMSExaClose(ScrnInfoPtr pScrn); extern unsigned int driGetPixmapHandle(PixmapPtr pPixmap, unsigned int *flags); -- cgit v1.2.3