DRI2: If the SDK supports it, use the DRI2GetBuffersWithFormat interfaces

If DRI2INFOREC_VERSION is defined in the server's dri2.h and has a
value greater than 1, compile to use the CreateBuffer and
DestroyBuffer interfaces.  The format parameter parameter to
CreateBuffer is assumed to be the bits-per-pixel of the buffer.

Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Kristian Høgsberg <krh@redhat.com>
This commit is contained in:
Ian Romanick 2009-04-24 12:28:13 -07:00
parent 106e4b44c5
commit 5d6f4f6eb7
1 changed files with 133 additions and 1 deletions

View File

@ -93,6 +93,12 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifdef DRI2
#include "dri2.h"
#if DRI2INFOREC_VERSION >= 1
#define USE_DRI2_1_1_0
#endif
extern XF86ModuleData dri2ModuleData;
#endif
static Bool I830InitVisualConfigs(ScreenPtr pScreen);
@ -1532,6 +1538,7 @@ typedef struct {
unsigned int attachment;
} I830DRI2BufferPrivateRec, *I830DRI2BufferPrivatePtr;
#ifndef USE_DRI2_1_1_0
static DRI2BufferPtr
I830DRI2CreateBuffers(DrawablePtr pDraw, unsigned int *attachments, int count)
{
@ -1615,6 +1622,88 @@ I830DRI2CreateBuffers(DrawablePtr pDraw, unsigned int *attachments, int count)
return buffers;
}
#else
static DRI2BufferPtr
I830DRI2CreateBuffer(DrawablePtr pDraw, unsigned int attachment,
unsigned int format)
{
ScreenPtr pScreen = pDraw->pScreen;
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
I830Ptr pI830 = I830PTR(pScrn);
DRI2BufferPtr buffers;
dri_bo *bo;
I830DRI2BufferPrivatePtr privates;
PixmapPtr pPixmap;
buffers = xcalloc(1, sizeof *buffers);
if (buffers == NULL)
return NULL;
privates = xcalloc(1, sizeof *privates);
if (privates == NULL) {
xfree(buffers);
return NULL;
}
if (attachment == DRI2BufferFrontLeft) {
if (pDraw->type == DRAWABLE_PIXMAP)
pPixmap = (PixmapPtr) pDraw;
else
pPixmap = (*pScreen->GetWindowPixmap)((WindowPtr) pDraw);
pPixmap->refcnt++;
} else {
unsigned int hint = 0;
switch (attachment) {
case DRI2BufferDepth:
case DRI2BufferDepthStencil:
if (SUPPORTS_YTILING(pI830))
hint = INTEL_CREATE_PIXMAP_TILING_Y;
else
hint = INTEL_CREATE_PIXMAP_TILING_X;
break;
case DRI2BufferFakeFrontLeft:
case DRI2BufferFakeFrontRight:
case DRI2BufferBackLeft:
case DRI2BufferBackRight:
hint = INTEL_CREATE_PIXMAP_TILING_X;
break;
}
if (!pI830->tiling ||
(!IS_I965G(pI830) && !pI830->kernel_exec_fencing))
hint = 0;
pPixmap = (*pScreen->CreatePixmap)(pScreen,
pDraw->width,
pDraw->height,
format,
hint);
}
buffers->attachment = attachment;
buffers->pitch = pPixmap->devKind;
buffers->cpp = pPixmap->drawable.bitsPerPixel / 8;
buffers->driverPrivate = privates;
buffers->format = format;
buffers->flags = 0; /* not tiled */
privates->pPixmap = pPixmap;
privates->attachment = attachment;
bo = i830_get_pixmap_bo (pPixmap);
if (dri_bo_flink(bo, &buffers->name) != 0) {
/* failed to name buffer */
}
return buffers;
}
#endif
#ifndef USE_DRI2_1_1_0
static void
I830DRI2DestroyBuffers(DrawablePtr pDraw, DRI2BufferPtr buffers, int count)
{
@ -1635,6 +1724,24 @@ I830DRI2DestroyBuffers(DrawablePtr pDraw, DRI2BufferPtr buffers, int count)
}
}
#else
static void
I830DRI2DestroyBuffer(DrawablePtr pDraw, DRI2BufferPtr buffer)
{
if (buffer) {
I830DRI2BufferPrivatePtr private = buffer->driverPrivate;
ScreenPtr pScreen = pDraw->pScreen;
(*pScreen->DestroyPixmap)(private->pPixmap);
xfree(private);
xfree(buffer);
}
}
#endif
static void
I830DRI2CopyRegion(DrawablePtr pDraw, RegionPtr pRegion,
DRI2BufferPtr pDstBuffer, DRI2BufferPtr pSrcBuffer)
@ -1686,12 +1793,28 @@ Bool I830DRI2ScreenInit(ScreenPtr pScreen)
int i;
struct stat sbuf;
dev_t d;
#ifdef USE_DRI2_1_1_0
int dri2_major = 1;
int dri2_minor = 0;
#endif
if (pI830->accel != ACCEL_UXA) {
xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "DRI2 requires UXA\n");
return FALSE;
}
#ifdef USE_DRI2_1_1_0
if (xf86LoaderCheckSymbol("DRI2Version")) {
DRI2Version(& dri2_major, & dri2_minor);
}
if (dri2_minor < 1) {
xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
"DRI2 requires DRI2 module version 1.1.0 or later\n");
return FALSE;
}
#endif
sprintf(buf, "pci:%04x:%02x:%02x.%d",
pI830->PciInfo->domain,
pI830->PciInfo->bus,
@ -1736,10 +1859,19 @@ Bool I830DRI2ScreenInit(ScreenPtr pScreen)
info.driverName = IS_I965G(pI830) ? "i965" : "i915";
info.deviceName = p;
info.version = 1;
#ifdef USE_DRI2_1_1_0
info.version = 2;
info.CreateBuffers = NULL;
info.DestroyBuffers = NULL;
info.CreateBuffer = I830DRI2CreateBuffer;
info.DestroyBuffer = I830DRI2DestroyBuffer;
#else
info.version = 1;
info.CreateBuffers = I830DRI2CreateBuffers;
info.DestroyBuffers = I830DRI2DestroyBuffers;
#endif
info.CopyRegion = I830DRI2CopyRegion;
pI830->drmSubFD = info.fd;