- Make image_from_pict() non-static

- Delete fbedge.c and fbedgeimp.h
- Use pixman_rasterize_edges() in fbtrap.c
This commit is contained in:
Soren Sandmann Pedersen 2007-05-23 15:50:25 -04:00
parent 2a960c442b
commit 9d87ef4e0d
7 changed files with 201 additions and 588 deletions

View File

@ -69,9 +69,7 @@ libfb_la_SOURCES = \
fbutil.c \
fbwindow.c \
fbpseudocolor.c \
fbpseudocolor.h \
fbedge.c \
fbedgeimp.h
fbpseudocolor.h
libwfb_la_SOURCES = $(libfb_la_SOURCES)

View File

@ -2146,4 +2146,8 @@ void
fbPaintWindow(WindowPtr pWin, RegionPtr pRegion, int what);
pixman_image_t *image_from_pict (PicturePtr pict,
Bool has_clip);
#endif /* _FB_H_ */

View File

@ -1,314 +0,0 @@
/*
* $Id$
*
* Copyright © 2004 Keith Packard
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation, and that the name of Keith Packard not be used in
* advertising or publicity pertaining to distribution of the software without
* specific, written prior permission. Keith Packard makes no
* representations about the suitability of this software for any purpose. It
* is provided "as is" without express or implied warranty.
*
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
#include <string.h>
#ifdef HAVE_DIX_CONFIG_H
#include <dix-config.h>
#endif
#include "fb.h"
#ifdef RENDER
#include "picturestr.h"
#include "mipict.h"
#include "renderedge.h"
#include "fbpict.h"
/*
* 4 bit alpha
*/
#define N_BITS 4
#define rasterizeEdges fbRasterizeEdges4
#if BITMAP_BIT_ORDER == LSBFirst
#define Shift4(o) ((o) << 2)
#else
#define Shift4(o) ((1-(o)) << 2)
#endif
#define Get4(x,o) (((x) >> Shift4(o)) & 0xf)
#define Put4(x,o,v) (((x) & ~(0xf << Shift4(o))) | (((v) & 0xf) << Shift4(o)))
#define DefineAlpha(line,x) \
CARD8 *__ap = (CARD8 *) line + ((x) >> 1); \
int __ao = (x) & 1
#define StepAlpha ((__ap += __ao), (__ao ^= 1))
#define AddAlpha(a) { \
CARD8 __o = READ(__ap); \
CARD8 __a = (a) + Get4(__o, __ao); \
WRITE(__ap, Put4 (__o, __ao, __a | (0 - ((__a) >> 4)))); \
}
#include "fbedgeimp.h"
#undef AddAlpha
#undef StepAlpha
#undef DefineAlpha
#undef rasterizeEdges
#undef N_BITS
/*
* 1 bit alpha
*/
#define N_BITS 1
#define rasterizeEdges fbRasterizeEdges1
#include "fbedgeimp.h"
#undef rasterizeEdges
#undef N_BITS
/*
* 8 bit alpha
*/
static INLINE CARD8
clip255 (int x)
{
if (x > 255) return 255;
return x;
}
static INLINE void
add_saturate_8 (CARD8 *buf, int value, int length)
{
while (length--)
{
WRITE(buf, clip255 (READ(buf) + value));
buf++;
}
}
/*
* We want to detect the case where we add the same value to a long
* span of pixels. The triangles on the end are filled in while we
* count how many sub-pixel scanlines contribute to the middle section.
*
* +--------------------------+
* fill_height =| \ /
* +------------------+
* |================|
* fill_start fill_end
*/
static void
fbRasterizeEdges8 (FbBits *buf,
int width,
int stride,
RenderEdge *l,
RenderEdge *r,
xFixed t,
xFixed b)
{
xFixed y = t;
FbBits *line;
int fill_start = -1, fill_end = -1;
int fill_size = 0;
line = buf + xFixedToInt (y) * stride;
for (;;)
{
CARD8 *ap = (CARD8 *) line;
xFixed lx, rx;
int lxi, rxi;
/* clip X */
lx = l->x;
if (lx < 0)
lx = 0;
rx = r->x;
if (xFixedToInt (rx) >= width)
rx = IntToxFixed (width);
/* Skip empty (or backwards) sections */
if (rx > lx)
{
int lxs, rxs;
/* Find pixel bounds for span. */
lxi = xFixedToInt (lx);
rxi = xFixedToInt (rx);
/* Sample coverage for edge pixels */
lxs = RenderSamplesX (lx, 8);
rxs = RenderSamplesX (rx, 8);
/* Add coverage across row */
if (lxi == rxi)
{
WRITE(ap +lxi, clip255 (READ(ap + lxi) + rxs - lxs));
}
else
{
WRITE(ap + lxi, clip255 (READ(ap + lxi) + N_X_FRAC(8) - lxs));
/* Move forward so that lxi/rxi is the pixel span */
lxi++;
/* Don't bother trying to optimize the fill unless
* the span is longer than 4 pixels. */
if (rxi - lxi > 4)
{
if (fill_start < 0)
{
fill_start = lxi;
fill_end = rxi;
fill_size++;
}
else
{
if (lxi >= fill_end || rxi < fill_start)
{
/* We're beyond what we saved, just fill it */
add_saturate_8 (ap + fill_start,
fill_size * N_X_FRAC(8),
fill_end - fill_start);
fill_start = lxi;
fill_end = rxi;
fill_size = 1;
}
else
{
/* Update fill_start */
if (lxi > fill_start)
{
add_saturate_8 (ap + fill_start,
fill_size * N_X_FRAC(8),
lxi - fill_start);
fill_start = lxi;
}
else if (lxi < fill_start)
{
add_saturate_8 (ap + lxi, N_X_FRAC(8),
fill_start - lxi);
}
/* Update fill_end */
if (rxi < fill_end)
{
add_saturate_8 (ap + rxi,
fill_size * N_X_FRAC(8),
fill_end - rxi);
fill_end = rxi;
}
else if (fill_end < rxi)
{
add_saturate_8 (ap + fill_end,
N_X_FRAC(8),
rxi - fill_end);
}
fill_size++;
}
}
}
else
{
add_saturate_8 (ap + lxi, N_X_FRAC(8), rxi - lxi);
}
/* Do not add in a 0 alpha here. This check is
* necessary to avoid a buffer overrun, (when rx
* is exactly on a pixel boundary). */
if (rxs)
WRITE(ap + rxi, clip255 (READ(ap + rxi) + rxs));
}
}
if (y == b) {
/* We're done, make sure we clean up any remaining fill. */
if (fill_start != fill_end) {
if (fill_size == N_Y_FRAC(8))
{
MEMSET_WRAPPED (ap + fill_start, 0xff, fill_end - fill_start);
}
else
{
add_saturate_8 (ap + fill_start, fill_size * N_X_FRAC(8),
fill_end - fill_start);
}
}
break;
}
if (xFixedFrac (y) != Y_FRAC_LAST(8))
{
RenderEdgeStepSmall (l);
RenderEdgeStepSmall (r);
y += STEP_Y_SMALL(8);
}
else
{
RenderEdgeStepBig (l);
RenderEdgeStepBig (r);
y += STEP_Y_BIG(8);
if (fill_start != fill_end)
{
if (fill_size == N_Y_FRAC(8))
{
MEMSET_WRAPPED (ap + fill_start, 0xff, fill_end - fill_start);
}
else
{
add_saturate_8 (ap + fill_start, fill_size * N_X_FRAC(8),
fill_end - fill_start);
}
fill_start = fill_end = -1;
fill_size = 0;
}
line += stride;
}
}
}
void
fbRasterizeEdges (FbBits *buf,
int bpp,
int width,
int stride,
RenderEdge *l,
RenderEdge *r,
xFixed t,
xFixed b)
{
switch (bpp) {
case 1:
fbRasterizeEdges1 (buf, width, stride, l, r, t, b);
break;
case 4:
fbRasterizeEdges4 (buf, width, stride, l, r, t, b);
break;
case 8:
fbRasterizeEdges8 (buf, width, stride, l, r, t, b);
break;
}
}
#endif /* RENDER */

View File

@ -1,145 +0,0 @@
/*
* $Id$
*
* Copyright © 2004 Keith Packard
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation, and that the name of Keith Packard not be used in
* advertising or publicity pertaining to distribution of the software without
* specific, written prior permission. Keith Packard makes no
* representations about the suitability of this software for any purpose. It
* is provided "as is" without express or implied warranty.
*
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
#ifdef HAVE_DIX_CONFIG_H
#include <dix-config.h>
#endif
#ifndef rasterizeSpan
#endif
static void
rasterizeEdges (FbBits *buf,
int width,
int stride,
RenderEdge *l,
RenderEdge *r,
xFixed t,
xFixed b)
{
xFixed y = t;
FbBits *line;
line = buf + xFixedToInt (y) * stride;
for (;;)
{
xFixed lx, rx;
int lxi, rxi;
/* clip X */
lx = l->x;
if (lx < 0)
lx = 0;
rx = r->x;
if (xFixedToInt (rx) >= width)
rx = IntToxFixed (width);
/* Skip empty (or backwards) sections */
if (rx > lx)
{
/* Find pixel bounds for span */
lxi = xFixedToInt (lx);
rxi = xFixedToInt (rx);
#if N_BITS == 1
{
FbBits *a = line;
FbBits startmask, endmask;
int nmiddle;
int width = rxi - lxi;
int x = lxi;
a += x >> FB_SHIFT;
x &= FB_MASK;
FbMaskBits (x, width, startmask, nmiddle, endmask);
if (startmask) {
WRITE(a, READ(a) | startmask);
a++;
}
while (nmiddle--)
WRITE(a++, FB_ALLONES);
if (endmask)
WRITE(a, READ(a) | endmask);
}
#else
{
DefineAlpha(line,lxi);
int lxs, rxs;
/* Sample coverage for edge pixels */
lxs = RenderSamplesX (lx, N_BITS);
rxs = RenderSamplesX (rx, N_BITS);
/* Add coverage across row */
if (lxi == rxi)
{
AddAlpha (rxs - lxs);
}
else
{
int xi;
AddAlpha (N_X_FRAC(N_BITS) - lxs);
StepAlpha;
for (xi = lxi + 1; xi < rxi; xi++)
{
AddAlpha (N_X_FRAC(N_BITS));
StepAlpha;
}
/* Do not add in a 0 alpha here. This check is necessary
* to avoid a buffer overrun when rx is exactly on a pixel
* boundary.
*/
if (rxs != 0)
AddAlpha (rxs);
}
}
#endif
}
if (y == b)
break;
#if N_BITS > 1
if (xFixedFrac (y) != Y_FRAC_LAST(N_BITS))
{
RenderEdgeStepSmall (l);
RenderEdgeStepSmall (r);
y += STEP_Y_SMALL(N_BITS);
}
else
#endif
{
RenderEdgeStepBig (l);
RenderEdgeStepBig (r);
y += STEP_Y_BIG(N_BITS);
line += stride;
}
}
}
#undef rasterizeSpan

View File

@ -108,7 +108,8 @@ create_conical_gradient_image (PictGradient *gradient)
}
static pixman_image_t *
create_bits_picture (PicturePtr pict)
create_bits_picture (PicturePtr pict,
Bool has_clip)
{
FbBits *bits;
FbStride stride;
@ -142,7 +143,8 @@ create_bits_picture (PicturePtr pict)
/* pCompositeClip is undefined for source pictures, so
* only set the clip region for pictures with drawables
*/
pixman_image_set_clip_region (image, pict->pCompositeClip);
if (has_clip)
pixman_image_set_clip_region (image, pict->pCompositeClip);
/* Indexed table */
if (pict->pFormat->index.devPrivate)
@ -153,114 +155,6 @@ create_bits_picture (PicturePtr pict)
return image;
}
static pixman_image_t *image_from_pict (PicturePtr pict);
static void
set_image_properties (pixman_image_t *image, PicturePtr pict)
{
pixman_repeat_t repeat;
pixman_filter_t filter;
if (pict->transform)
{
pixman_image_set_transform (
image, (pixman_transform_t *)pict->transform);
}
switch (pict->repeatType)
{
default:
case RepeatNone:
repeat = PIXMAN_REPEAT_NONE;
break;
case RepeatPad:
repeat = PIXMAN_REPEAT_PAD;
break;
case RepeatNormal:
repeat = PIXMAN_REPEAT_NORMAL;
break;
case RepeatReflect:
repeat = PIXMAN_REPEAT_REFLECT;
break;
}
pixman_image_set_repeat (image, repeat);
if (pict->alphaMap)
{
pixman_image_t *alpha_map = image_from_pict (pict->alphaMap);
pixman_image_set_alpha_map (
image, alpha_map, pict->alphaOrigin.x, pict->alphaOrigin.y);
pixman_image_unref (alpha_map);
}
pixman_image_set_component_alpha (image, pict->componentAlpha);
switch (pict->filter)
{
default:
case PictFilterNearest:
case PictFilterFast:
filter = PIXMAN_FILTER_NEAREST;
break;
case PictFilterBilinear:
case PictFilterGood:
filter = PIXMAN_FILTER_BILINEAR;
break;
case PictFilterConvolution:
filter = PIXMAN_FILTER_CONVOLUTION;
break;
}
pixman_image_set_filter (image, filter, (pixman_fixed_t *)pict->filter_params, pict->filter_nparams);
}
static pixman_image_t *
image_from_pict (PicturePtr pict)
{
pixman_image_t *image = NULL;
if (!pict)
return NULL;
if (pict->pDrawable)
{
image = create_bits_picture (pict);
}
else if (pict->pSourcePict)
{
SourcePict *sp = pict->pSourcePict;
if (sp->type == SourcePictTypeSolidFill)
{
image = create_solid_fill_image (pict);
}
else
{
PictGradient *gradient = &pict->pSourcePict->gradient;
if (sp->type == SourcePictTypeLinear)
image = create_linear_gradient_image (gradient);
else if (sp->type == SourcePictTypeRadial)
image = create_radial_gradient_image (gradient);
else if (sp->type == SourcePictTypeConical)
image = create_conical_gradient_image (gradient);
}
}
if (image)
set_image_properties (image, pict);
return image;
}
#define mod(a,b) ((b) == 1 ? 0 : (a) >= 0 ? (a) % (b) : (b) - (-a) % (b))
void
@ -401,9 +295,9 @@ fbComposite (CARD8 op,
xMask, yMask, xDst, yDst, width, height))
return;
src = image_from_pict (pSrc);
mask = image_from_pict (pMask);
dest = image_from_pict (pDst);
src = image_from_pict (pSrc, TRUE);
mask = image_from_pict (pMask, TRUE);
dest = image_from_pict (pDst, TRUE);
if (src && dest && !(pMask && !mask))
{
@ -466,6 +360,116 @@ fbPictureInit (ScreenPtr pScreen, PictFormatPtr formats, int nformats)
return TRUE;
}
static void
set_image_properties (pixman_image_t *image, PicturePtr pict)
{
pixman_repeat_t repeat;
pixman_filter_t filter;
if (pict->transform)
{
pixman_image_set_transform (
image, (pixman_transform_t *)pict->transform);
}
switch (pict->repeatType)
{
default:
case RepeatNone:
repeat = PIXMAN_REPEAT_NONE;
break;
case RepeatPad:
repeat = PIXMAN_REPEAT_PAD;
break;
case RepeatNormal:
repeat = PIXMAN_REPEAT_NORMAL;
break;
case RepeatReflect:
repeat = PIXMAN_REPEAT_REFLECT;
break;
}
pixman_image_set_repeat (image, repeat);
if (pict->alphaMap)
{
pixman_image_t *alpha_map = image_from_pict (pict->alphaMap, TRUE);
pixman_image_set_alpha_map (
image, alpha_map, pict->alphaOrigin.x, pict->alphaOrigin.y);
pixman_image_unref (alpha_map);
}
pixman_image_set_component_alpha (image, pict->componentAlpha);
switch (pict->filter)
{
default:
case PictFilterNearest:
case PictFilterFast:
filter = PIXMAN_FILTER_NEAREST;
break;
case PictFilterBilinear:
case PictFilterGood:
filter = PIXMAN_FILTER_BILINEAR;
break;
case PictFilterConvolution:
filter = PIXMAN_FILTER_CONVOLUTION;
break;
}
pixman_image_set_filter (image, filter, (pixman_fixed_t *)pict->filter_params, pict->filter_nparams);
}
pixman_image_t *
image_from_pict (PicturePtr pict,
Bool has_clip)
{
pixman_image_t *image = NULL;
if (!pict)
return NULL;
if (pict->pDrawable)
{
image = create_bits_picture (pict, has_clip);
}
else if (pict->pSourcePict)
{
SourcePict *sp = pict->pSourcePict;
if (sp->type == SourcePictTypeSolidFill)
{
image = create_solid_fill_image (pict);
}
else
{
PictGradient *gradient = &pict->pSourcePict->gradient;
if (sp->type == SourcePictTypeLinear)
image = create_linear_gradient_image (gradient);
else if (sp->type == SourcePictTypeRadial)
image = create_radial_gradient_image (gradient);
else if (sp->type == SourcePictTypeConical)
image = create_conical_gradient_image (gradient);
}
}
if (image)
set_image_properties (image, pict);
return image;
}
#ifdef USE_MMX
/* The CPU detection code needs to be in a file not compiled with
* "-mmmx -msse", as gcc would generate CMOV instructions otherwise

View File

@ -412,18 +412,6 @@ fbCompositeGeneral (CARD8 op,
CARD16 width,
CARD16 height);
/* fbedge.c */
void
fbRasterizeEdges (FbBits *buf,
int bpp,
int width,
int stride,
RenderEdge *l,
RenderEdge *r,
xFixed t,
xFixed b);
/* fbpict.c */
void
fbComposite (CARD8 op,

View File

@ -35,6 +35,7 @@
#include "renderedge.h"
#include "fbpict.h"
#if 0
void
fbAddTraps (PicturePtr pPicture,
INT16 x_off,
@ -98,6 +99,75 @@ fbAddTraps (PicturePtr pPicture,
fbFinishAccess (pPicture->pDrawable);
}
#endif
void
fbAddTraps (PicturePtr pPicture,
INT16 x_off,
INT16 y_off,
int ntrap,
xTrap *traps)
{
FbBits *buf;
int bpp;
int width;
int stride;
int height;
int pxoff, pyoff;
xFixed x_off_fixed;
xFixed y_off_fixed;
RenderEdge l, r;
xFixed t, b;
pixman_image_t *image = image_from_pict (pPicture, FALSE);
fbGetDrawable (pPicture->pDrawable, buf, stride, bpp, pxoff, pyoff);
width = pPicture->pDrawable->width;
height = pPicture->pDrawable->height;
#if 0
x_off += pxoff;
y_off += pyoff;
#endif
x_off_fixed = IntToxFixed(y_off);
y_off_fixed = IntToxFixed(y_off);
while (ntrap--)
{
t = traps->top.y + y_off_fixed;
if (t < 0)
t = 0;
t = RenderSampleCeilY (t, bpp);
b = traps->bot.y + y_off_fixed;
if (xFixedToInt (b) >= height)
b = IntToxFixed (height) - 1;
b = RenderSampleFloorY (b, bpp);
if (b >= t)
{
/* initialize edge walkers */
RenderEdgeInit (&l, bpp, t,
traps->top.l + x_off_fixed,
traps->top.y + y_off_fixed,
traps->bot.l + x_off_fixed,
traps->bot.y + y_off_fixed);
RenderEdgeInit (&r, bpp, t,
traps->top.r + x_off_fixed,
traps->top.y + y_off_fixed,
traps->bot.r + x_off_fixed,
traps->bot.y + y_off_fixed);
pixman_rasterize_edges (image, &l, &r, t, b);
}
traps++;
}
fbFinishAccess (pPicture->pDrawable);
}
void
fbRasterizeTrapezoid (PicturePtr pPicture,
@ -116,16 +186,21 @@ fbRasterizeTrapezoid (PicturePtr pPicture,
xFixed y_off_fixed;
RenderEdge l, r;
xFixed t, b;
pixman_image_t *image;
if (!xTrapezoidValid (trap))
return;
image = image_from_pict (pPicture, FALSE);
fbGetDrawable (pPicture->pDrawable, buf, stride, bpp, pxoff, pyoff);
width = pPicture->pDrawable->width;
height = pPicture->pDrawable->height;
#if 0
x_off += pxoff;
y_off += pyoff;
#endif
x_off_fixed = IntToxFixed(x_off);
y_off_fixed = IntToxFixed(y_off);
@ -144,8 +219,11 @@ fbRasterizeTrapezoid (PicturePtr pPicture,
/* initialize edge walkers */
RenderLineFixedEdgeInit (&l, bpp, t, &trap->left, x_off, y_off);
RenderLineFixedEdgeInit (&r, bpp, t, &trap->right, x_off, y_off);
pixman_rasterize_edges (image, &l, &r, t, b);
#if 0
fbRasterizeEdges (buf, bpp, width, stride, &l, &r, t, b);
#endif
}
fbFinishAccess (pPicture->pDrawable);