Use negative stride and PBOs in Xgl

This commit is contained in:
David Reveman 2005-03-11 00:58:49 +00:00
parent 8653db5d57
commit 4de5aa4285
10 changed files with 149 additions and 78 deletions

View File

@ -67,7 +67,9 @@ ScreenPtr currentScreen = NULL;
xglScreenInfoRec xglScreenInfo = { xglScreenInfoRec xglScreenInfo = {
NULL, 0, 0, 0, 0, FALSE, NULL, 0, 0, 0, 0, FALSE,
DEFAULT_GEOMETRY_DATA_TYPE, DEFAULT_GEOMETRY_DATA_TYPE,
DEFAULT_GEOMETRY_USAGE DEFAULT_GEOMETRY_USAGE,
FALSE,
XGL_DEFAULT_PBO_MASK
}; };
static Bool static Bool

View File

@ -54,6 +54,8 @@ typedef struct _GCFuncs *GCFuncsPtr;
extern WindowPtr *WindowTable; extern WindowPtr *WindowTable;
#define XGL_DEFAULT_PBO_MASK 0 /* don't use PBO as default */
typedef struct _xglScreenInfo { typedef struct _xglScreenInfo {
glitz_drawable_t *drawable; glitz_drawable_t *drawable;
unsigned int width; unsigned int width;
@ -63,6 +65,8 @@ typedef struct _xglScreenInfo {
Bool fullscreen; Bool fullscreen;
int geometryDataType; int geometryDataType;
int geometryUsage; int geometryUsage;
Bool yInverted;
int pboMask;
} xglScreenInfoRec, *xglScreenInfoPtr; } xglScreenInfoRec, *xglScreenInfoPtr;
typedef struct _xglPixelFormat { typedef struct _xglPixelFormat {
@ -217,6 +221,8 @@ typedef struct _xglScreen {
int nOffscreen; int nOffscreen;
int geometryUsage; int geometryUsage;
int geometryDataType; int geometryDataType;
Bool yInverted;
int pboMask;
xglGeometryRec scratchGeometry; xglGeometryRec scratchGeometry;
#ifdef RENDER #ifdef RENDER
@ -830,12 +836,27 @@ xglSetGeometry (xglGeometryPtr pGeometry,
/* xglpixmap.c */ /* xglpixmap.c */
#define XGL_PIXMAP_USAGE_HINT_STREAM_DRAW 1
#define XGL_PIXMAP_USAGE_HINT_STREAM_READ 2
#define XGL_PIXMAP_USAGE_HINT_STREAM_COPY 3
#define XGL_PIXMAP_USAGE_HINT_STATIC_DRAW 4
#define XGL_PIXMAP_USAGE_HINT_STATIC_READ 5
#define XGL_PIXMAP_USAGE_HINT_STATIC_COPY 6
#define XGL_PIXMAP_USAGE_HINT_DYNAMIC_DRAW 7
#define XGL_PIXMAP_USAGE_HINT_DYNAMIC_READ 8
#define XGL_PIXMAP_USAGE_HINT_DYNAMIC_COPY 9
#define XGL_PIXMAP_USAGE_HINT_DEFAULT XGL_PIXMAP_USAGE_HINT_STREAM_DRAW
PixmapPtr PixmapPtr
xglCreatePixmap (ScreenPtr pScreen, xglCreatePixmap (ScreenPtr pScreen,
int width, int width,
int height, int height,
int depth); int depth);
void
xglFiniPixmap (PixmapPtr pPixmap);
Bool Bool
xglDestroyPixmap (PixmapPtr pPixmap); xglDestroyPixmap (PixmapPtr pPixmap);
@ -860,7 +881,7 @@ Bool
xglCreatePixmapSurface (PixmapPtr pPixmap); xglCreatePixmapSurface (PixmapPtr pPixmap);
Bool Bool
xglAllocatePixmapBits (PixmapPtr pPixmap); xglAllocatePixmapBits (PixmapPtr pPixmap, int hint);
Bool Bool
xglMapPixmapBits (PixmapPtr pPixmap); xglMapPixmapBits (PixmapPtr pPixmap);

View File

@ -157,8 +157,8 @@ xglSetVisualTypesAndMasks (ScreenInfo *pScreenInfo,
if (xglPbufferVisuals) if (xglPbufferVisuals)
{ {
xglPbufferVisuals[nxglPbufferVisuals].format = format; xglPbufferVisuals[nxglPbufferVisuals].format = format;
xglPbufferVisuals[nxglPbufferVisuals].pPixel = pPixelFormat; xglPbufferVisuals[nxglPbufferVisuals].pPixel = NULL;
xglPbufferVisuals[nxglPbufferVisuals].visuals = visuals; xglPbufferVisuals[nxglPbufferVisuals].visuals = 0;
nxglPbufferVisuals++; nxglPbufferVisuals++;
} }
} }
@ -217,23 +217,6 @@ xglInitVisuals (ScreenInfo *pScreenInfo)
rm, gm, bm); rm, gm, bm);
} }
} }
#if 1
{
for (j = 0; j < nxglVisuals; j++)
{
ErrorF ("Visual: 0x%x (%c) - r/g/b/a: %d/%d/%d/%d db: %d\n",
(int) xglVisuals[j].format->id,
xglVisuals[j].format->types.pbuffer? 'y' : 'n',
xglVisuals[j].format->color.red_size,
xglVisuals[j].format->color.green_size,
xglVisuals[j].format->color.blue_size,
xglVisuals[j].format->color.alpha_size,
xglVisuals[j].format->doublebuffer);
}
}
#endif
} }
void void

View File

@ -158,12 +158,6 @@ xglCopyProc (DrawablePtr pSrc,
pBox++; pBox++;
} }
if (pPixmapPriv->target == xglPixmapTargetIn)
{
if (!xglSyncSurface (pDst))
FatalError (XGL_SW_FAILURE_STRING);
}
} else } else
xglAddCurrentBitDamage (pDst); xglAddCurrentBitDamage (pDst);
} }

View File

@ -105,6 +105,9 @@ xglUseMsg (void)
ErrorF ("-vertextype [short|float] set vertex data type\n"); ErrorF ("-vertextype [short|float] set vertex data type\n");
ErrorF ("-vbostream " ErrorF ("-vbostream "
"use vertex buffer objects for streaming of vertex data\n"); "use vertex buffer objects for streaming of vertex data\n");
ErrorF ("-yinverted Y is upside-down\n");
ErrorF ("-pbomask [1|4|8|16|32] "
"set bpp's to use with pixel buffer objects\n");
} }
int int
@ -148,6 +151,22 @@ xglProcessArgument (xglScreenInfoPtr pScreenInfo,
pScreenInfo->geometryUsage = GEOMETRY_USAGE_STREAM; pScreenInfo->geometryUsage = GEOMETRY_USAGE_STREAM;
return 1; return 1;
} }
else if (!strcmp (argv[i], "-yinverted"))
{
pScreenInfo->yInverted = TRUE;
return 1;
}
else if (!strcmp (argv[i], "-pbomask"))
{
if ((i + 1) < argc)
{
pScreenInfo->pboMask = atoi (argv[i + 1]);
}
else
return 1;
return 2;
}
return 0; return 0;
} }

View File

@ -26,6 +26,24 @@
#include "xgl.h" #include "xgl.h"
#include "fb.h" #include "fb.h"
static glitz_buffer_hint_t xglPixmapUsageHints[] = {
(glitz_buffer_hint_t) 0, /* reserved for system memory */
GLITZ_BUFFER_HINT_STREAM_DRAW,
GLITZ_BUFFER_HINT_STREAM_READ,
GLITZ_BUFFER_HINT_STREAM_COPY,
GLITZ_BUFFER_HINT_STATIC_DRAW,
GLITZ_BUFFER_HINT_STATIC_READ,
GLITZ_BUFFER_HINT_STATIC_COPY,
GLITZ_BUFFER_HINT_DYNAMIC_DRAW,
GLITZ_BUFFER_HINT_DYNAMIC_READ,
GLITZ_BUFFER_HINT_DYNAMIC_COPY
};
#define NUM_XGL_PIXMAP_USAGE_HINTS \
(sizeof (xglPixmapUsageHints) / sizeof (xglPixmapUsageHints[0]))
#define XGL_PIXMAP_USAGE_HINT(hint) (xglPixmapUsageHints[hint])
static void static void
xglPixmapDamageReport (DamagePtr pDamage, xglPixmapDamageReport (DamagePtr pDamage,
RegionPtr pRegion, RegionPtr pRegion,
@ -187,14 +205,11 @@ xglCreatePixmap (ScreenPtr pScreen,
return pPixmap; return pPixmap;
} }
Bool void
xglDestroyPixmap (PixmapPtr pPixmap) xglFiniPixmap (PixmapPtr pPixmap)
{ {
XGL_PIXMAP_PRIV (pPixmap); XGL_PIXMAP_PRIV (pPixmap);
if (--pPixmap->refcnt)
return TRUE;
if (pPixmapPriv->pArea) if (pPixmapPriv->pArea)
xglWithdrawArea (pPixmapPriv->pArea); xglWithdrawArea (pPixmapPriv->pArea);
@ -215,6 +230,15 @@ xglDestroyPixmap (PixmapPtr pPixmap)
if (pPixmapPriv->surface) if (pPixmapPriv->surface)
glitz_surface_destroy (pPixmapPriv->surface); glitz_surface_destroy (pPixmapPriv->surface);
}
Bool
xglDestroyPixmap (PixmapPtr pPixmap)
{
if (--pPixmap->refcnt)
return TRUE;
xglFiniPixmap (pPixmap);
xfree (pPixmap); xfree (pPixmap);
@ -362,7 +386,6 @@ xglModifyPixmapHeader (PixmapPtr pPixmap,
glitz_surface_reference (pScreenPriv->surface); glitz_surface_reference (pScreenPriv->surface);
pPixmapPriv->surface = pScreenPriv->surface; pPixmapPriv->surface = pScreenPriv->surface;
pPixmapPriv->pPixel = pScreenPriv->pVisual[0].pPixel;
pPixmapPriv->target = xglPixmapTargetIn; pPixmapPriv->target = xglPixmapTargetIn;
pScreenPriv->pScreenPixmap = pPixmap; pScreenPriv->pScreenPixmap = pPixmap;
@ -405,7 +428,8 @@ xglPixmapToGeometry (PixmapPtr pPixmap,
if (!pPixmapPriv->buffer) if (!pPixmapPriv->buffer)
{ {
if (!xglAllocatePixmapBits (pPixmap)) if (!xglAllocatePixmapBits (pPixmap,
XGL_PIXMAP_USAGE_HINT_DEFAULT))
return NULL; return NULL;
} }
@ -476,11 +500,12 @@ xglCreatePixmapSurface (PixmapPtr pPixmap)
} }
Bool Bool
xglAllocatePixmapBits (PixmapPtr pPixmap) xglAllocatePixmapBits (PixmapPtr pPixmap, int hint)
{ {
int width, height, bpp, stride; int width, height, bpp, stride;
XGL_PIXMAP_PRIV (pPixmap); XGL_PIXMAP_PRIV (pPixmap);
XGL_SCREEN_PRIV (pPixmap->drawable.pScreen);
width = pPixmap->drawable.width; width = pPixmap->drawable.width;
height = pPixmap->drawable.height; height = pPixmap->drawable.height;
@ -490,22 +515,37 @@ xglAllocatePixmapBits (PixmapPtr pPixmap)
if (stride) if (stride)
{ {
pPixmapPriv->bits = xalloc (height * stride); glitz_buffer_t *buffer;
if (!pPixmapPriv->bits)
return FALSE; if ((pScreenPriv->pboMask & bpp) && hint)
pPixmapPriv->buffer =
glitz_buffer_create_for_data (pPixmapPriv->bits);
if (!pPixmapPriv->buffer)
{ {
xfree (pPixmapPriv->bits); buffer = glitz_pixel_buffer_create (pScreenPriv->drawable,
NULL, height * stride,
XGL_PIXMAP_USAGE_HINT (hint));
}
else
{
pPixmapPriv->bits = xalloc (height * stride);
if (!pPixmapPriv->bits)
return FALSE;
buffer = glitz_buffer_create_for_data (pPixmapPriv->bits);
}
if (!buffer)
{
if (pPixmapPriv->bits)
xfree (pPixmapPriv->bits);
pPixmapPriv->bits = NULL; pPixmapPriv->bits = NULL;
return FALSE; return FALSE;
} }
pPixmapPriv->buffer = buffer;
} }
/* XXX: pPixmapPriv->stride = -stride */ if (pScreenPriv->yInverted)
pPixmapPriv->stride = stride; pPixmapPriv->stride = stride;
else
pPixmapPriv->stride = -stride;
return TRUE; return TRUE;
} }
@ -520,7 +560,8 @@ xglMapPixmapBits (PixmapPtr pPixmap)
XGL_PIXMAP_PRIV (pPixmap); XGL_PIXMAP_PRIV (pPixmap);
if (!pPixmapPriv->buffer) if (!pPixmapPriv->buffer)
if (!xglAllocatePixmapBits (pPixmap)) if (!xglAllocatePixmapBits (pPixmap,
XGL_PIXMAP_USAGE_HINT_DEFAULT))
return FALSE; return FALSE;
bits = glitz_buffer_map (pPixmapPriv->buffer, bits = glitz_buffer_map (pPixmapPriv->buffer,

View File

@ -135,6 +135,7 @@ xglScreenInit (ScreenPtr pScreen,
xglScreenInfoPtr pScreenInfo) xglScreenInfoPtr pScreenInfo)
{ {
xglScreenPtr pScreenPriv; xglScreenPtr pScreenPriv;
int depth;
#ifdef RENDER #ifdef RENDER
PictureScreenPtr pPictureScreen; PictureScreenPtr pPictureScreen;
@ -152,15 +153,19 @@ xglScreenInit (ScreenPtr pScreen,
pScreenPriv->features = pScreenPriv->features =
glitz_drawable_get_features (pScreenInfo->drawable); glitz_drawable_get_features (pScreenInfo->drawable);
depth = pScreenPriv->pVisual->pPixel->depth;
if (!xglInitOffscreen (pScreen, pScreenInfo)) if (!xglInitOffscreen (pScreen, pScreenInfo))
return FALSE; return FALSE;
xglInitPixmapFormats (pScreen); xglInitPixmapFormats (pScreen);
if (!pScreenPriv->pixmapFormats[32].format) if (!pScreenPriv->pixmapFormats[depth].format)
return FALSE; return FALSE;
pScreenPriv->geometryDataType = pScreenInfo->geometryDataType; pScreenPriv->geometryDataType = pScreenInfo->geometryDataType;
pScreenPriv->geometryUsage = pScreenInfo->geometryUsage; pScreenPriv->geometryUsage = pScreenInfo->geometryUsage;
pScreenPriv->yInverted = pScreenInfo->yInverted;
pScreenPriv->pboMask = pScreenInfo->pboMask;
GEOMETRY_INIT (pScreen, &pScreenPriv->scratchGeometry, GEOMETRY_INIT (pScreen, &pScreenPriv->scratchGeometry,
GLITZ_GEOMETRY_TYPE_VERTEX, GLITZ_GEOMETRY_TYPE_VERTEX,
@ -168,7 +173,7 @@ xglScreenInit (ScreenPtr pScreen,
pScreenPriv->surface = pScreenPriv->surface =
glitz_surface_create (pScreenPriv->drawable, glitz_surface_create (pScreenPriv->drawable,
pScreenPriv->pixmapFormats[32].format, pScreenPriv->pixmapFormats[depth].format,
pScreenInfo->width, pScreenInfo->height, pScreenInfo->width, pScreenInfo->height,
0, NULL); 0, NULL);
if (!pScreenPriv->surface) if (!pScreenPriv->surface)
@ -283,7 +288,9 @@ xglFinishScreenInit (ScreenPtr pScreen)
XGL_SCREEN_PRIV (pScreen); XGL_SCREEN_PRIV (pScreen);
miInitializeBackingStore (pScreen); /* Do we want to use BackingStore?
miInitializeBackingStore (pScreen);
*/
if (!fbCreateDefColormap (pScreen)) if (!fbCreateDefColormap (pScreen))
return FALSE; return FALSE;
@ -348,7 +355,8 @@ xglCloseScreen (int index,
ScreenPtr pScreen) ScreenPtr pScreen)
{ {
XGL_SCREEN_PRIV (pScreen); XGL_SCREEN_PRIV (pScreen);
XGL_PIXMAP_PRIV (pScreenPriv->pScreenPixmap);
#ifdef RENDER #ifdef RENDER
int i; int i;
@ -362,6 +370,10 @@ xglCloseScreen (int index,
glitz_surface_destroy (pScreenPriv->trapInfo.mask); glitz_surface_destroy (pScreenPriv->trapInfo.mask);
#endif #endif
xglFiniPixmap (pScreenPriv->pScreenPixmap);
if (pPixmapPriv->pDamage)
DamageDestroy (pPixmapPriv->pDamage);
if (pScreenPriv->solid) if (pScreenPriv->solid)
glitz_surface_destroy (pScreenPriv->solid); glitz_surface_destroy (pScreenPriv->solid);

View File

@ -64,7 +64,8 @@ xglShmPutImage (DrawablePtr pDrawable,
XGL_PIXMAP_PRIV (pPixmap); XGL_PIXMAP_PRIV (pPixmap);
if (!xglAllocatePixmapBits (pPixmap)) if (!xglAllocatePixmapBits (pPixmap,
XGL_PIXMAP_USAGE_HINT_DEFAULT))
{ {
(*pScreen->DestroyPixmap) (pPixmap); (*pScreen->DestroyPixmap) (pPixmap);
return; return;

View File

@ -80,7 +80,7 @@ xglSyncBits (DrawablePtr pDrawable,
pBitBox = &pPixmapPriv->bitBox; pBitBox = &pPixmapPriv->bitBox;
if (pExtents) if (pPixmapPriv->target == xglPixmapTargetIn && pExtents)
{ {
box.x1 = MAX (0, pExtents->x1); box.x1 = MAX (0, pExtents->x1);
box.y1 = MAX (0, pExtents->y1); box.y1 = MAX (0, pExtents->y1);
@ -150,7 +150,7 @@ xglSyncBits (DrawablePtr pDrawable,
} }
if (!pPixmapPriv->buffer) if (!pPixmapPriv->buffer)
if (!xglAllocatePixmapBits (pPixmap)) if (!xglAllocatePixmapBits (pPixmap, XGL_PIXMAP_USAGE_HINT_DEFAULT))
return FALSE; return FALSE;
if (pPixmapPriv->pDamage) if (pPixmapPriv->pDamage)
@ -176,23 +176,24 @@ xglSyncBits (DrawablePtr pDrawable,
nBox = REGION_NUM_RECTS (&region); nBox = REGION_NUM_RECTS (&region);
format.masks = pPixmapPriv->pPixel->masks; format.masks = pPixmapPriv->pPixel->masks;
if (pPixmapPriv->stride < 0)
{
format.bytes_per_line = -pPixmapPriv->stride;
format.scanline_order = GLITZ_PIXEL_SCANLINE_ORDER_BOTTOM_UP;
}
else
{
format.bytes_per_line = pPixmapPriv->stride;
format.scanline_order = GLITZ_PIXEL_SCANLINE_ORDER_TOP_DOWN;
}
while (nBox--) while (nBox--)
{ {
format.xoffset = pBox->x1; format.xoffset = pBox->x1;
format.skip_lines = pBox->y1;
if (pPixmapPriv->stride < 0)
{
format.skip_lines = pPixmap->drawable.height - pBox->y2;
format.bytes_per_line = -pPixmapPriv->stride;
format.scanline_order = GLITZ_PIXEL_SCANLINE_ORDER_BOTTOM_UP;
}
else
{
format.skip_lines = pBox->y1;
format.bytes_per_line = pPixmapPriv->stride;
format.scanline_order = GLITZ_PIXEL_SCANLINE_ORDER_TOP_DOWN;
}
glitz_get_pixels (pPixmapPriv->surface, glitz_get_pixels (pPixmapPriv->surface,
pBox->x1, pBox->x1,
pBox->y1, pBox->y1,
@ -254,17 +255,18 @@ xglSyncSurface (DrawablePtr pDrawable)
pBox = REGION_RECTS (pRegion); pBox = REGION_RECTS (pRegion);
pExt = REGION_EXTENTS (pDrawable->pScreen, pRegion); pExt = REGION_EXTENTS (pDrawable->pScreen, pRegion);
format.masks = pPixmapPriv->pPixel->masks; format.masks = pPixmapPriv->pPixel->masks;
format.xoffset = pExt->x1; format.xoffset = pExt->x1;
format.skip_lines = pExt->y1;
if (pPixmapPriv->stride < 0) if (pPixmapPriv->stride < 0)
{ {
format.skip_lines = pPixmap->drawable.height - pExt->y2;
format.bytes_per_line = -pPixmapPriv->stride; format.bytes_per_line = -pPixmapPriv->stride;
format.scanline_order = GLITZ_PIXEL_SCANLINE_ORDER_BOTTOM_UP; format.scanline_order = GLITZ_PIXEL_SCANLINE_ORDER_BOTTOM_UP;
} }
else else
{ {
format.skip_lines = pExt->y1;
format.bytes_per_line = pPixmapPriv->stride; format.bytes_per_line = pPixmapPriv->stride;
format.scanline_order = GLITZ_PIXEL_SCANLINE_ORDER_TOP_DOWN; format.scanline_order = GLITZ_PIXEL_SCANLINE_ORDER_TOP_DOWN;
} }

View File

@ -66,17 +66,13 @@ xglCreateMaskPicture (ScreenPtr pScreen,
{ {
XGL_PIXMAP_PRIV (pPixmap); XGL_PIXMAP_PRIV (pPixmap);
if (!xglAllocatePixmapBits (pPixmap)) if (!xglAllocatePixmapBits (pPixmap, XGL_PIXMAP_USAGE_HINT_DEFAULT))
{ {
(*pScreen->DestroyPixmap) (pPixmap); (*pScreen->DestroyPixmap) (pPixmap);
return 0; return 0;
} }
pPixmapPriv->target = xglPixmapTargetNo; pPixmapPriv->target = xglPixmapTargetNo;
/* force negative stride */
if (pPixmapPriv->stride > 0)
pPixmapPriv->stride = -pPixmapPriv->stride;
} }
pGC = GetScratchGC (pPixmap->drawable.depth, pScreen); pGC = GetScratchGC (pPixmap->drawable.depth, pScreen);