Merge David Reveman's gradient optimization patch from pixman
This commit is contained in:
parent
d0e55774e0
commit
0a9239ec25
1393
fb/fbcompose.c
1393
fb/fbcompose.c
File diff suppressed because it is too large
Load Diff
106
render/picture.c
106
render/picture.c
|
@ -890,54 +890,22 @@ static unsigned int INTERPOLATE_PIXEL_256(unsigned int x, unsigned int a,
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void initGradientColorTable(SourcePictPtr pGradient, int *error)
|
CARD32
|
||||||
|
PictureGradientColor (PictGradientStopPtr stop1,
|
||||||
|
PictGradientStopPtr stop2,
|
||||||
|
CARD32 x)
|
||||||
{
|
{
|
||||||
int begin_pos, end_pos;
|
CARD32 current_color, next_color;
|
||||||
xFixed incr, dpos;
|
int dist, idist;
|
||||||
int pos, current_stop;
|
|
||||||
PictGradientStopPtr stops = pGradient->linear.stops;
|
|
||||||
int nstops = pGradient->linear.nstops;
|
|
||||||
|
|
||||||
/* The position where the gradient begins and ends */
|
current_color = xRenderColorToCard32 (stop1->color);
|
||||||
begin_pos = (stops[0].x * PICT_GRADIENT_STOPTABLE_SIZE) >> 16;
|
next_color = xRenderColorToCard32 (stop2->color);
|
||||||
end_pos = (stops[nstops - 1].x * PICT_GRADIENT_STOPTABLE_SIZE) >> 16;
|
|
||||||
|
|
||||||
pos = 0; /* The position in the color table. */
|
dist = (int) (256 * (x - stop1->x) / (stop2->x - stop1->x));
|
||||||
|
idist = 256 - dist;
|
||||||
|
|
||||||
/* Up to first point */
|
return premultiply (INTERPOLATE_PIXEL_256 (current_color, idist,
|
||||||
while (pos <= begin_pos) {
|
next_color, dist));
|
||||||
pGradient->linear.colorTable[pos] = xRenderColorToCard32(stops[0].color);
|
|
||||||
++pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
incr = (1<<16)/ PICT_GRADIENT_STOPTABLE_SIZE; /* the double increment. */
|
|
||||||
dpos = incr * pos; /* The position in terms of 0-1. */
|
|
||||||
|
|
||||||
current_stop = 0; /* We always interpolate between current and current + 1. */
|
|
||||||
|
|
||||||
/* Gradient area */
|
|
||||||
while (pos < end_pos) {
|
|
||||||
unsigned int current_color = xRenderColorToCard32(stops[current_stop].color);
|
|
||||||
unsigned int next_color = xRenderColorToCard32(stops[current_stop + 1].color);
|
|
||||||
|
|
||||||
int dist = (int)(256*(dpos - stops[current_stop].x)
|
|
||||||
/ (stops[current_stop+1].x - stops[current_stop].x));
|
|
||||||
int idist = 256 - dist;
|
|
||||||
|
|
||||||
pGradient->linear.colorTable[pos] = premultiply(INTERPOLATE_PIXEL_256(current_color, idist, next_color, dist));
|
|
||||||
|
|
||||||
++pos;
|
|
||||||
dpos += incr;
|
|
||||||
|
|
||||||
if (dpos > stops[current_stop + 1].x)
|
|
||||||
++current_stop;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* After last point */
|
|
||||||
while (pos < PICT_GRADIENT_STOPTABLE_SIZE) {
|
|
||||||
pGradient->linear.colorTable[pos] = xRenderColorToCard32(stops[nstops - 1].color);
|
|
||||||
++pos;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void initGradient(SourcePictPtr pGradient, int stopCount,
|
static void initGradient(SourcePictPtr pGradient, int stopCount,
|
||||||
|
@ -953,26 +921,30 @@ static void initGradient(SourcePictPtr pGradient, int stopCount,
|
||||||
|
|
||||||
dpos = -1;
|
dpos = -1;
|
||||||
for (i = 0; i < stopCount; ++i) {
|
for (i = 0; i < stopCount; ++i) {
|
||||||
if (stopPoints[i] <= dpos || stopPoints[i] > (1<<16)) {
|
if (stopPoints[i] < dpos || stopPoints[i] > (1<<16)) {
|
||||||
*error = BadValue;
|
*error = BadValue;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
dpos = stopPoints[i];
|
dpos = stopPoints[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
pGradient->linear.stops = xalloc(stopCount*sizeof(PictGradientStop));
|
pGradient->gradient.stops = xalloc(stopCount*sizeof(PictGradientStop));
|
||||||
if (!pGradient->linear.stops) {
|
if (!pGradient->gradient.stops) {
|
||||||
*error = BadAlloc;
|
*error = BadAlloc;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pGradient->linear.nstops = stopCount;
|
pGradient->gradient.nstops = stopCount;
|
||||||
|
|
||||||
for (i = 0; i < stopCount; ++i) {
|
for (i = 0; i < stopCount; ++i) {
|
||||||
pGradient->linear.stops[i].x = stopPoints[i];
|
pGradient->gradient.stops[i].x = stopPoints[i];
|
||||||
pGradient->linear.stops[i].color = stopColors[i];
|
pGradient->gradient.stops[i].color = stopColors[i];
|
||||||
}
|
}
|
||||||
initGradientColorTable(pGradient, error);
|
|
||||||
|
pGradient->gradient.class = SourcePictClassUnknown;
|
||||||
|
pGradient->gradient.stopRange = 0xffff;
|
||||||
|
pGradient->gradient.colorTable = NULL;
|
||||||
|
pGradient->gradient.colorTableSize = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PicturePtr createSourcePicture(void)
|
static PicturePtr createSourcePicture(void)
|
||||||
|
@ -980,9 +952,9 @@ static PicturePtr createSourcePicture(void)
|
||||||
PicturePtr pPicture;
|
PicturePtr pPicture;
|
||||||
pPicture = (PicturePtr) xalloc(sizeof(PictureRec));
|
pPicture = (PicturePtr) xalloc(sizeof(PictureRec));
|
||||||
pPicture->pDrawable = 0;
|
pPicture->pDrawable = 0;
|
||||||
pPicture->format = PICT_a8r8g8b8;
|
|
||||||
pPicture->pFormat = 0;
|
pPicture->pFormat = 0;
|
||||||
pPicture->pNext = 0;
|
pPicture->pNext = 0;
|
||||||
|
pPicture->format = PICT_a8r8g8b8;
|
||||||
pPicture->devPrivates = 0;
|
pPicture->devPrivates = 0;
|
||||||
|
|
||||||
SetPictureToDefaults(pPicture);
|
SetPictureToDefaults(pPicture);
|
||||||
|
@ -1027,10 +999,6 @@ CreateLinearGradientPicture (Picture pid, xPointFixed *p1, xPointFixed *p2,
|
||||||
*error = BadAlloc;
|
*error = BadAlloc;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (p1->x == p2->x && p1->y == p2->y) {
|
|
||||||
*error = BadValue;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
pPicture->id = pid;
|
pPicture->id = pid;
|
||||||
pPicture->pSourcePict = (SourcePictPtr) xalloc(sizeof(PictLinearGradient));
|
pPicture->pSourcePict = (SourcePictPtr) xalloc(sizeof(PictLinearGradient));
|
||||||
|
@ -1072,14 +1040,6 @@ CreateRadialGradientPicture (Picture pid, xPointFixed *inner, xPointFixed *outer
|
||||||
*error = BadAlloc;
|
*error = BadAlloc;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
{
|
|
||||||
double dx = (double)(inner->x - outer->x);
|
|
||||||
double dy = (double)(inner->y - outer->y);
|
|
||||||
if (sqrt(dx*dx + dy*dy) + (double)(innerRadius) > (double)(outerRadius)) {
|
|
||||||
*error = BadValue;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pPicture->id = pid;
|
pPicture->id = pid;
|
||||||
pPicture->pSourcePict = (SourcePictPtr) xalloc(sizeof(PictRadialGradient));
|
pPicture->pSourcePict = (SourcePictPtr) xalloc(sizeof(PictRadialGradient));
|
||||||
|
@ -1627,13 +1587,17 @@ FreePicture (pointer value,
|
||||||
{
|
{
|
||||||
if (pPicture->transform)
|
if (pPicture->transform)
|
||||||
xfree (pPicture->transform);
|
xfree (pPicture->transform);
|
||||||
if (!pPicture->pDrawable) {
|
|
||||||
if (pPicture->pSourcePict) {
|
if (pPicture->pSourcePict)
|
||||||
if (pPicture->pSourcePict->type != SourcePictTypeSolidFill)
|
{
|
||||||
xfree(pPicture->pSourcePict->linear.stops);
|
if (pPicture->pSourcePict->type != SourcePictTypeSolidFill)
|
||||||
xfree(pPicture->pSourcePict);
|
xfree(pPicture->pSourcePict->linear.stops);
|
||||||
}
|
|
||||||
} else {
|
xfree(pPicture->pSourcePict);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pPicture->pDrawable)
|
||||||
|
{
|
||||||
ScreenPtr pScreen = pPicture->pDrawable->pScreen;
|
ScreenPtr pScreen = pPicture->pDrawable->pScreen;
|
||||||
PictureScreenPtr ps = GetPictureScreen(pScreen);
|
PictureScreenPtr ps = GetPictureScreen(pScreen);
|
||||||
|
|
||||||
|
|
|
@ -68,8 +68,13 @@ typedef struct _PictTransform {
|
||||||
#define SourcePictTypeRadial 2
|
#define SourcePictTypeRadial 2
|
||||||
#define SourcePictTypeConical 3
|
#define SourcePictTypeConical 3
|
||||||
|
|
||||||
|
#define SourcePictClassUnknown 0
|
||||||
|
#define SourcePictClassHorizontal 1
|
||||||
|
#define SourcePictClassVertical 2
|
||||||
|
|
||||||
typedef struct _PictSolidFill {
|
typedef struct _PictSolidFill {
|
||||||
unsigned int type;
|
unsigned int type;
|
||||||
|
unsigned int class;
|
||||||
CARD32 color;
|
CARD32 color;
|
||||||
} PictSolidFill, *PictSolidFillPtr;
|
} PictSolidFill, *PictSolidFillPtr;
|
||||||
|
|
||||||
|
@ -80,16 +85,22 @@ typedef struct _PictGradientStop {
|
||||||
|
|
||||||
typedef struct _PictGradient {
|
typedef struct _PictGradient {
|
||||||
unsigned int type;
|
unsigned int type;
|
||||||
|
unsigned int class;
|
||||||
int nstops;
|
int nstops;
|
||||||
PictGradientStopPtr stops;
|
PictGradientStopPtr stops;
|
||||||
CARD32 colorTable[PICT_GRADIENT_STOPTABLE_SIZE];
|
int stopRange;
|
||||||
|
CARD32 *colorTable;
|
||||||
|
int colorTableSize;
|
||||||
} PictGradient, *PictGradientPtr;
|
} PictGradient, *PictGradientPtr;
|
||||||
|
|
||||||
typedef struct _PictLinearGradient {
|
typedef struct _PictLinearGradient {
|
||||||
unsigned int type;
|
unsigned int type;
|
||||||
|
unsigned int class;
|
||||||
int nstops;
|
int nstops;
|
||||||
PictGradientStopPtr stops;
|
PictGradientStopPtr stops;
|
||||||
CARD32 colorTable[PICT_GRADIENT_STOPTABLE_SIZE];
|
int stopRange;
|
||||||
|
CARD32 *colorTable;
|
||||||
|
int colorTableSize;
|
||||||
xPointFixed p1;
|
xPointFixed p1;
|
||||||
xPointFixed p2;
|
xPointFixed p2;
|
||||||
} PictLinearGradient, *PictLinearGradientPtr;
|
} PictLinearGradient, *PictLinearGradientPtr;
|
||||||
|
@ -98,7 +109,6 @@ typedef struct _PictRadialGradient {
|
||||||
unsigned int type;
|
unsigned int type;
|
||||||
int nstops;
|
int nstops;
|
||||||
PictGradientStopPtr stops;
|
PictGradientStopPtr stops;
|
||||||
CARD32 colorTable[PICT_GRADIENT_STOPTABLE_SIZE];
|
|
||||||
double fx;
|
double fx;
|
||||||
double fy;
|
double fy;
|
||||||
double dx;
|
double dx;
|
||||||
|
@ -110,9 +120,12 @@ typedef struct _PictRadialGradient {
|
||||||
|
|
||||||
typedef struct _PictConicalGradient {
|
typedef struct _PictConicalGradient {
|
||||||
unsigned int type;
|
unsigned int type;
|
||||||
|
unsigned int class;
|
||||||
int nstops;
|
int nstops;
|
||||||
PictGradientStopPtr stops;
|
PictGradientStopPtr stops;
|
||||||
CARD32 colorTable[PICT_GRADIENT_STOPTABLE_SIZE];
|
int stopRange;
|
||||||
|
CARD32 *colorTable;
|
||||||
|
int colorTableSize;
|
||||||
xPointFixed center;
|
xPointFixed center;
|
||||||
xFixed angle;
|
xFixed angle;
|
||||||
} PictConicalGradient, *PictConicalGradientPtr;
|
} PictConicalGradient, *PictConicalGradientPtr;
|
||||||
|
@ -624,6 +637,11 @@ Bool
|
||||||
PictureTransformPoint3d (PictTransformPtr transform,
|
PictureTransformPoint3d (PictTransformPtr transform,
|
||||||
PictVectorPtr vector);
|
PictVectorPtr vector);
|
||||||
|
|
||||||
|
CARD32
|
||||||
|
PictureGradientColor (PictGradientStopPtr stop1,
|
||||||
|
PictGradientStopPtr stop2,
|
||||||
|
CARD32 x);
|
||||||
|
|
||||||
void RenderExtensionInit (void);
|
void RenderExtensionInit (void);
|
||||||
|
|
||||||
Bool
|
Bool
|
||||||
|
|
Loading…
Reference in New Issue
Block a user