summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/.cvsignore7
-rw-r--r--src/Xr.h91
-rw-r--r--src/xr.c50
-rw-r--r--src/xrfont.c4
-rw-r--r--src/xrgstate.c240
-rw-r--r--src/xrint.h123
-rw-r--r--src/xrstate.c9
-rw-r--r--src/xrsurface.c434
-rw-r--r--src/xrtransform.c10
9 files changed, 546 insertions, 422 deletions
diff --git a/src/.cvsignore b/src/.cvsignore
new file mode 100644
index 00000000..cf92059f
--- /dev/null
+++ b/src/.cvsignore
@@ -0,0 +1,7 @@
+.deps
+.libs
+Makefile
+Makefile.am
+Makefile.in
+*.la
+*.lo
diff --git a/src/Xr.h b/src/Xr.h
index 636d78a2..1a2a1657 100644
--- a/src/Xr.h
+++ b/src/Xr.h
@@ -26,13 +26,14 @@
#ifndef _XR_H_
#define _XR_H_
-#include <X11/Xc/Xc.h>
+#include <Xc.h>
typedef struct _XrState XrState;
+typedef struct _XrSurface XrSurface;
/* Functions for manipulating state objects */
XrState *
-XrCreate(Display *dpy);
+XrCreate(void);
void
XrDestroy(XrState *xrs);
@@ -43,18 +44,17 @@ XrSave(XrState *xrs);
void
XrRestore(XrState *xrs);
+/* XXX: I want to rethink this API
void
XrPushGroup(XrState *xrs);
void
XrPopGroup(XrState *xrs);
+*/
/* Modify state */
void
-XrSetDrawable(XrState *xrs, Drawable drawable);
-
-void
-XrSetVisual(XrState *xrs, Visual *visual);
+XrSetTargetSurface (XrState *xrs, XrSurface *surface);
typedef enum _XrFormat {
XrFormatARGB32 = PictStandardARGB32,
@@ -62,9 +62,11 @@ typedef enum _XrFormat {
XrFormatA8 = PictStandardA8,
XrFormatA1 = PictStandardA1
} XrFormat;
-
+
void
-XrSetFormat(XrState *xrs, XrFormat format);
+XrSetTargetDrawable (XrState *xrs,
+ Display *dpy,
+ Drawable drawable);
typedef enum _XrOperator {
XrOperatorClear = PictOpClear,
@@ -238,6 +240,9 @@ XrShowText(XrState *xrs, const unsigned char *utf8);
/* Image functions */
+/* XXX: Is "Show" the right term here? With operators such as
+ OutReverse we may not actually be showing any part of the
+ surface. */
void
XrShowImage(XrState *xrs,
char *data,
@@ -257,6 +262,24 @@ XrShowImageTransform(XrState *xrs,
double c, double d,
double tx, double ty);
+/* XXX: The ShowImage/ShowSurface APIs definitely need some work. If
+ we want both then one should be a convenience function for the
+ other and the interfaces should be consistent in some sense. One
+ trick is to resolve the interaction with XrSurfaceSetTransform (if
+ it is to be exposed) */
+void
+XrShowSurface (XrState *xrs,
+ XrSurface *surface,
+ int x,
+ int y,
+ int width,
+ int height);
+
+/* Query functions */
+
+XrSurface *
+XrGetTargetSurface (XrState *xrs);
+
/* Error status queries */
typedef enum _XrStatus {
@@ -274,5 +297,57 @@ XrGetStatus(XrState *xrs);
const char *
XrGetStatusString(XrState *xrs);
+/* Surface mainpulation */
+
+/* XXX: This is a mess from the user's POV. Should the Visual or the
+ XrFormat control what render format is used? Maybe I can have
+ XrSurfaceCreateForWindow with a visual, and
+ XrSurfaceCreateForPixmap with an XrFormat. Would that work?
+*/
+XrSurface *
+XrSurfaceCreateForDrawable (Display *dpy,
+ Drawable drawable,
+ Visual *visual,
+ XrFormat format,
+ Colormap colormap);
+
+XrSurface *
+XrSurfaceCreateForImage (char *data,
+ XrFormat format,
+ int width,
+ int height,
+ int stride);
+
+XrSurface *
+XrSurfaceCreateNextTo (XrSurface *neighbor,
+ XrFormat format,
+ int width,
+ int height);
+
+/* XXX: One problem with having RGB and A here in one function is that
+ it introduces the question of pre-multiplied vs. non-pre-multiplied
+ alpha. Do I want to export an XrColor structure instead? So far, no
+ other public functions need it. */
+XrSurface *
+XrSurfaceCreateNextToSolid (XrSurface *neighbor,
+ XrFormat format,
+ int width,
+ int height,
+ double red,
+ double green,
+ double blue,
+ double alpha);
+
+void
+XrSurfaceDestroy(XrSurface *surface);
+
+/* XXX: The Xc version of this function isn't quite working yet
+XrStatus
+XrSurfaceSetClipRegion (XrSurface *surface, Region region);
+*/
+
+XrStatus
+XrSurfaceSetRepeat (XrSurface *surface, int repeat);
+
#endif
diff --git a/src/xr.c b/src/xr.c
index 19232db4..b07e6de0 100644
--- a/src/xr.c
+++ b/src/xr.c
@@ -33,9 +33,9 @@ static void
_XrClipValue(double *value, double min, double max);
XrState *
-XrCreate(Display *dpy)
+XrCreate(void)
{
- return _XrStateCreate(dpy);
+ return _XrStateCreate();
}
void
@@ -62,6 +62,7 @@ XrRestore(XrState *xrs)
xrs->status = _XrStatePop(xrs);
}
+/* XXX: I want to rethink this API
void
XrPushGroup(XrState *xrs)
{
@@ -87,32 +88,29 @@ XrPopGroup(XrState *xrs)
xrs->status = _XrStatePop(xrs);
}
+*/
void
-XrSetDrawable(XrState *xrs, Drawable drawable)
+XrSetTargetSurface (XrState *xrs, XrSurface *surface)
{
if (xrs->status)
return;
- xrs->status = _XrGStateSetDrawable(_XR_CURRENT_GSTATE(xrs), drawable);
+ xrs->status = _XrGStateSetTargetSurface (_XR_CURRENT_GSTATE (xrs), surface);
}
void
-XrSetVisual(XrState *xrs, Visual *visual)
+XrSetTargetDrawable (XrState *xrs,
+ Display *dpy,
+ Drawable drawable)
{
if (xrs->status)
return;
- xrs->status = _XrGStateSetVisual(_XR_CURRENT_GSTATE(xrs), visual);
-}
-
-void
-XrSetFormat(XrState *xrs, XrFormat format)
-{
- if (xrs->status)
- return;
-
- xrs->status = _XrGStateSetFormat(_XR_CURRENT_GSTATE(xrs), format);
+ xrs->status = _XrGStateSetTargetDrawable (_XR_CURRENT_GSTATE (xrs),
+ dpy, drawable,
+ DefaultVisual (dpy, DefaultScreen (dpy)),
+ 0);
}
void
@@ -475,6 +473,28 @@ XrShowImageTransform(XrState *xrs,
tx, ty);
}
+void
+XrShowSurface (XrState *xrs,
+ XrSurface *surface,
+ int x,
+ int y,
+ int width,
+ int height)
+{
+ if (xrs->status)
+ return;
+
+ xrs->status = _XrGStateShowSurface (_XR_CURRENT_GSTATE (xrs),
+ surface,
+ x, y,
+ width, height);
+}
+
+XrSurface *
+XrGetTargetSurface (XrState *xrs)
+{
+ return _XrGStateGetTargetSurface (_XR_CURRENT_GSTATE (xrs));
+}
XrStatus
XrGetStatus(XrState *xrs)
diff --git a/src/xrfont.c b/src/xrfont.c
index d1416bce..9349cee2 100644
--- a/src/xrfont.c
+++ b/src/xrfont.c
@@ -155,7 +155,9 @@ _XrFontResolveXftFont(XrFont *font, XrGState *gstate, XftFont **xft_font)
FcPatternAddMatrix(pattern, "matrix", &fc_matrix);
- font->dpy = gstate->dpy;
+ /* XXX: Need to abandon Xft and use Xc instead */
+ /* When I do that I can throw away these Display pointers */
+ font->dpy = gstate->surface->dpy;
match = XftFontMatch (font->dpy, DefaultScreen(font->dpy), pattern, &result);
if (!match)
return 0;
diff --git a/src/xrgstate.c b/src/xrgstate.c
index 90a4e773..4fb25eb2 100644
--- a/src/xrgstate.c
+++ b/src/xrgstate.c
@@ -28,30 +28,22 @@
#include "xrint.h"
-static Picture
-_XrGStateGetPicture(XrGState *gstate);
-
-static Picture
-_XrGStateGetSrcPicture(XrGState *gstate);
-
XrGState *
-_XrGStateCreate(Display *dpy)
+_XrGStateCreate()
{
XrGState *gstate;
gstate = malloc(sizeof(XrGState));
if (gstate)
- _XrGStateInit(gstate, dpy);
+ _XrGStateInit(gstate);
return gstate;
}
void
-_XrGStateInit(XrGState *gstate, Display *dpy)
+_XrGStateInit(XrGState *gstate)
{
- gstate->dpy = dpy;
-
gstate->operator = XR_GSTATE_OPERATOR_DEFAULT;
gstate->tolerance = XR_GSTATE_TOLERANCE_DEFAULT;
@@ -67,18 +59,15 @@ _XrGStateInit(XrGState *gstate, Display *dpy)
gstate->num_dashes = 0;
gstate->dash_offset = 0.0;
- gstate->alphaFormat = XcFindStandardFormat(dpy, PictStandardA8);
-
_XrFontInit(&gstate->font);
- gstate->parent_surface = NULL;
- gstate->surface = _XrSurfaceCreate(dpy);
- gstate->src = _XrSurfaceCreate(dpy);
+ gstate->surface = NULL;
+ gstate->solid = NULL;
+ gstate->pattern = NULL;
gstate->mask = NULL;
gstate->alpha = 1.0;
_XrColorInit(&gstate->color);
- _XrSurfaceSetSolidColor(gstate->src, &gstate->color);
_XrTransformInitIdentity(&gstate->ctm);
_XrTransformInitIdentity(&gstate->ctm_inverse);
@@ -109,11 +98,10 @@ _XrGStateInitCopy(XrGState *gstate, XrGState *other)
if (status)
goto CLEANUP_DASHES;
- gstate->parent_surface = NULL;
_XrSurfaceReference(gstate->surface);
- _XrSurfaceReference(gstate->src);
- if (gstate->mask)
- _XrSurfaceReference(gstate->mask);
+ _XrSurfaceReference(gstate->solid);
+ _XrSurfaceReference(gstate->pattern);
+ _XrSurfaceReference(gstate->mask);
status = _XrPathInitCopy(&gstate->path, &other->path);
if (status)
@@ -139,15 +127,12 @@ _XrGStateInitCopy(XrGState *gstate, XrGState *other)
void
_XrGStateDeinit(XrGState *gstate)
{
- if (gstate->parent_surface)
- _XrGStateEndGroup(gstate);
-
_XrFontDeinit(&gstate->font);
- _XrSurfaceDereferenceDestroy(gstate->surface);
- _XrSurfaceDereferenceDestroy(gstate->src);
- if (gstate->mask)
- _XrSurfaceDereferenceDestroy(gstate->mask);
+ XrSurfaceDestroy(gstate->surface);
+ XrSurfaceDestroy(gstate->solid);
+ XrSurfaceDestroy(gstate->pattern);
+ XrSurfaceDestroy(gstate->mask);
_XrColorDeinit(&gstate->color);
@@ -190,6 +175,7 @@ _XrGStateClone(XrGState *gstate)
}
/* Push rendering off to an off-screen group. */
+/* XXX: Rethinking this API
XrStatus
_XrGStateBeginGroup(XrGState *gstate)
{
@@ -209,7 +195,7 @@ _XrGStateBeginGroup(XrGState *gstate)
if (pix == 0)
return XrStatusNoMemory;
- gstate->surface = _XrSurfaceCreate(gstate->dpy);
+ gstate->surface = XrSurfaceCreate(gstate->dpy);
if (gstate->surface == NULL)
return XrStatusNoMemory;
@@ -218,8 +204,7 @@ _XrGStateBeginGroup(XrGState *gstate)
_XrColorInit(&clear);
_XrColorSetAlpha(&clear, 0);
- XcFillRectangle(gstate->dpy,
- XrOperatorSrc,
+ XcFillRectangle(XrOperatorSrc,
_XrSurfaceGetXcSurface(gstate->surface),
&clear.xc_color,
0, 0,
@@ -228,8 +213,10 @@ _XrGStateBeginGroup(XrGState *gstate)
return XrStatusSuccess;
}
+*/
/* Complete the current offscreen group, composing its contents onto the parent surface. */
+/* XXX: Rethinking this API
XrStatus
_XrGStateEndGroup(XrGState *gstate)
{
@@ -246,10 +233,10 @@ _XrGStateEndGroup(XrGState *gstate)
_XrSurfaceSetSolidColor(&mask, &mask_color);
- /* XXX: This could be made much more efficient by using
+ * XXX: This could be made much more efficient by using
_XrSurfaceGetDamagedWidth/Height if XrSurface actually kept
- track of such informaton. */
- XcComposite(gstate->dpy, gstate->operator,
+ track of such informaton. *
+ XcComposite(gstate->operator,
_XrSurfaceGetXcSurface(gstate->surface),
_XrSurfaceGetXcSurface(&mask),
_XrSurfaceGetXcSurface(gstate->parent_surface),
@@ -264,35 +251,58 @@ _XrGStateEndGroup(XrGState *gstate)
pix = _XrSurfaceGetDrawable(gstate->surface);
XFreePixmap(gstate->dpy, pix);
- _XrSurfaceDestroy(gstate->surface);
+ XrSurfaceDestroy(gstate->surface);
gstate->surface = gstate->parent_surface;
gstate->parent_surface = NULL;
return XrStatusSuccess;
}
+*/
XrStatus
-_XrGStateSetDrawable(XrGState *gstate, Drawable drawable)
+_XrGStateSetTargetSurface (XrGState *gstate, XrSurface *surface)
{
- _XrSurfaceSetDrawable(gstate->surface, drawable);
+ XrSurfaceDestroy (gstate->surface);
+
+ gstate->surface = surface;
+ _XrSurfaceReference (surface);
return XrStatusSuccess;
}
-XrStatus
-_XrGStateSetVisual(XrGState *gstate, Visual *visual)
+/* XXX: Need to decide the memory mangement semantics of this
+ function. Should it reference the surface again? */
+XrSurface *
+_XrGStateGetTargetSurface (XrGState *gstate)
{
- _XrSurfaceSetVisual(gstate->surface, visual);
+ if (gstate == NULL)
+ return NULL;
- return XrStatusSuccess;
+ return gstate->surface;
}
XrStatus
-_XrGStateSetFormat(XrGState *gstate, XrFormat format)
+_XrGStateSetTargetDrawable (XrGState *gstate,
+ Display *dpy,
+ Drawable drawable,
+ Visual *visual,
+ XrFormat format)
{
- _XrSurfaceSetFormat(gstate->surface, format);
+ XrStatus status;
+ XrSurface *surface;
- return XrStatusSuccess;
+ surface = XrSurfaceCreateForDrawable (dpy, drawable,
+ visual,
+ format,
+ DefaultColormap (dpy, DefaultScreen (dpy)));
+ if (surface == NULL)
+ return XrStatusNoMemory;
+
+ status = _XrGStateSetTargetSurface (gstate, surface);
+
+ XrSurfaceDestroy (surface);
+
+ return status;
}
XrStatus
@@ -307,7 +317,13 @@ XrStatus
_XrGStateSetRGBColor(XrGState *gstate, double red, double green, double blue)
{
_XrColorSetRGB(&gstate->color, red, green, blue);
- _XrSurfaceSetSolidColor(gstate->src, &gstate->color);
+
+ XrSurfaceDestroy(gstate->solid);
+ gstate->solid = XrSurfaceCreateNextToSolid (gstate->surface, XrFormatARGB32,
+ 1, 1,
+ red, green, blue,
+ gstate->alpha);
+ XrSurfaceSetRepeat (gstate->solid, 1);
return XrStatusSuccess;
}
@@ -324,8 +340,18 @@ XrStatus
_XrGStateSetAlpha(XrGState *gstate, double alpha)
{
gstate->alpha = alpha;
+
_XrColorSetAlpha(&gstate->color, alpha);
- _XrSurfaceSetSolidColor(gstate->src, &gstate->color);
+
+ XrSurfaceDestroy (gstate->solid);
+ gstate->solid = XrSurfaceCreateNextToSolid (gstate->surface,
+ XrFormatARGB32,
+ 1, 1,
+ gstate->color.red,
+ gstate->color.green,
+ gstate->color.blue,
+ gstate->color.alpha);
+ XrSurfaceSetRepeat (gstate->solid, 1);
return XrStatusSuccess;
}
@@ -446,7 +472,7 @@ _XrGStateConcatMatrix(XrGState *gstate,
_XrTransformInitMatrix(&tmp, a, b, c, d, tx, ty);
_XrTransformMultiplyIntoRight(&tmp, &gstate->ctm);
- _XrTransformComputeInverse(&tmp);
+ _XrTransformInvert(&tmp);
_XrTransformMultiplyIntoLeft(&gstate->ctm_inverse, &tmp);
return XrStatusSuccess;
@@ -463,7 +489,7 @@ _XrGStateSetMatrix(XrGState *gstate,
_XrTransformInitMatrix(&gstate->ctm, a, b, c, d, tx, ty);
gstate->ctm_inverse = gstate->ctm;
- status = _XrTransformComputeInverse(&gstate->ctm_inverse);
+ status = _XrTransformInvert (&gstate->ctm_inverse);
if (status)
return status;
@@ -660,10 +686,9 @@ _XrGStateStroke(XrGState *gstate)
return status;
}
- XcCompositeTrapezoids(gstate->dpy, gstate->operator,
- _XrSurfaceGetXcSurface(gstate->src),
- _XrSurfaceGetXcSurface(gstate->surface),
- gstate->alphaFormat,
+ XcCompositeTrapezoids(gstate->operator,
+ gstate->pattern ? gstate->pattern->xc_surface : gstate->solid->xc_surface,
+ gstate->surface->xc_surface,
0, 0,
traps.xtraps,
traps.num_xtraps);
@@ -700,10 +725,9 @@ _XrGStateFill(XrGState *gstate)
return status;
}
- XcCompositeTrapezoids(gstate->dpy, gstate->operator,
- _XrSurfaceGetXcSurface(gstate->src),
- _XrSurfaceGetXcSurface(gstate->surface),
- gstate->alphaFormat,
+ XcCompositeTrapezoids(gstate->operator,
+ gstate->pattern ? gstate->pattern->xc_surface : gstate->solid->xc_surface,
+ gstate->surface->xc_surface,
0, 0,
traps.xtraps,
traps.num_xtraps);
@@ -749,7 +773,9 @@ _XrGStateTextExtents(XrGState *gstate,
_XrFontResolveXftFont(&gstate->font, gstate, &xft_font);
- XftTextExtentsUtf8(gstate->dpy,
+ /* XXX: Need to abandon Xft and use Xc instead */
+ /* (until I do, this call will croak on IcImage XrSurfaces */
+ XftTextExtentsUtf8(gstate->surface->dpy,
xft_font,
utf8,
strlen((char *) utf8),
@@ -778,11 +804,13 @@ _XrGStateShowText(XrGState *gstate, const unsigned char *utf8)
_XrFontResolveXftFont(&gstate->font, gstate, &xft_font);
- XftTextRenderUtf8(gstate->dpy,
+ /* XXX: Need to abandon Xft and use Xc instead */
+ /* (until I do, this call will croak on IcImage XrSurfaces */
+ XftTextRenderUtf8(gstate->surface->dpy,
gstate->operator,
- _XrGStateGetSrcPicture(gstate),
+ _XrSurfaceGetPicture (gstate->solid),
xft_font,
- _XrGStateGetPicture(gstate),
+ _XrSurfaceGetPicture (gstate->surface),
0, 0,
gstate->current_pt.x,
gstate->current_pt.y,
@@ -818,35 +846,38 @@ _XrGStateShowImageTransform(XrGState *gstate,
double c, double d,
double tx, double ty)
{
- XrStatus status;
- XrColor mask_color;
- XrSurface image_surface, mask;
+ XrSurface *image_surface, *mask;
XrTransform user_to_image, image_to_user;
XrTransform image_to_device, device_to_image;
double dst_x, dst_y;
double dst_width, dst_height;
- _XrSurfaceInit(&mask, gstate->dpy);
- _XrColorInit(&mask_color);
- _XrColorSetAlpha(&mask_color, gstate->alpha);
-
- _XrSurfaceSetSolidColor(&mask, &mask_color);
-
- _XrSurfaceInit(&image_surface, gstate->dpy);
+ mask = XrSurfaceCreateNextToSolid (gstate->surface,
+ XrFormatA8,
+ 1, 1,
+ 1.0, 1.0, 1.0,
+ gstate->alpha);
+ if (mask == NULL)
+ return XrStatusNoMemory;
+ XrSurfaceSetRepeat (mask, 1);
- _XrSurfaceSetFormat(&image_surface, format);
+ image_surface = XrSurfaceCreateNextTo (gstate->surface, format, width, height);
+ if (image_surface == NULL) {
+ XrSurfaceDestroy (mask);
+ return XrStatusNoMemory;
+ }
- status = _XrSurfaceSetImage(&image_surface, data,width, height, stride);
- if (status)
- return status;
+ /* XXX: Need a way to transfer bits to an XcSurface
+ XcPutImage (image_surface->xc_surface, data, width, height, stride);
+ */
_XrTransformInitMatrix(&user_to_image, a, b, c, d, tx, ty);
_XrTransformMultiply(&gstate->ctm_inverse, &user_to_image, &device_to_image);
- _XrSurfaceSetTransform(&image_surface, &device_to_image);
+ _XrSurfaceSetTransform(image_surface, &device_to_image);
image_to_user = user_to_image;
- _XrTransformComputeInverse(&image_to_user);
- _XrTransformMultiply(&image_to_user, &gstate->ctm, &image_to_device);
+ _XrTransformInvert (&image_to_user);
+ _XrTransformMultiply (&image_to_user, &gstate->ctm, &image_to_device);
dst_x = 0;
dst_y = 0;
@@ -856,30 +887,53 @@ _XrGStateShowImageTransform(XrGState *gstate,
&dst_x, &dst_y,
&dst_width, &dst_height);
- XcComposite(gstate->dpy, gstate->operator,
- _XrSurfaceGetXcSurface(&image_surface),
- _XrSurfaceGetXcSurface(&mask),
- _XrSurfaceGetXcSurface(gstate->surface),
+ XcComposite(gstate->operator,
+ image_surface->xc_surface,
+ mask->xc_surface,
+ gstate->surface->xc_surface,
dst_x, dst_y,
0, 0,
dst_x, dst_y,
- dst_width + 1,
- dst_height + 1);
+ dst_width + 2,
+ dst_height + 2);
- _XrSurfaceDeinit(&image_surface);
- _XrSurfaceDeinit(&mask);
+ XrSurfaceDestroy (image_surface);
+ XrSurfaceDestroy (mask);
return XrStatusSuccess;
}
-static Picture
-_XrGStateGetPicture(XrGState *gstate)
+XrStatus
+_XrGStateShowSurface(XrGState *gstate,
+ XrSurface *surface,
+ int x,
+ int y,
+ int width,
+ int height)
{
- return _XrSurfaceGetPicture(gstate->surface);
-}
+ XrSurface *mask;
-static Picture
-_XrGStateGetSrcPicture(XrGState *gstate)
-{
- return _XrSurfaceGetPicture(gstate->src);
+ mask = XrSurfaceCreateNextToSolid (gstate->surface,
+ XrFormatARGB32,
+ 1, 1,
+ 1.0, 1.0, 1.0,
+ gstate->alpha);
+ if (mask == NULL)
+ return XrStatusNoMemory;
+
+ XrSurfaceSetRepeat (mask, 1);
+
+ XcComposite (gstate->operator,
+ surface->xc_surface,
+ mask->xc_surface,
+ gstate->surface->xc_surface,
+ x, y,
+ 0, 0,
+ x, y,
+ width,
+ height);
+
+ XrSurfaceDestroy (mask);
+
+ return XrStatusSuccess;
}
diff --git a/src/xrint.h b/src/xrint.h
index 89b9b45c..763374f4 100644
--- a/src/xrint.h
+++ b/src/xrint.h
@@ -159,27 +159,14 @@ typedef struct _XrPen {
XrPenVertex *vertex;
} XrPen;
-typedef struct _XrSurface {
+struct _XrSurface {
Display *dpy;
-
- Drawable drawable;
- GC gc;
-
- unsigned int width;
- unsigned int height;
- unsigned int depth;
-
- unsigned long xc_sa_mask;
- XcSurfaceAttributes xc_sa;
-
- XrFormat format;
- XcFormat *xc_format;
+ char *image_data;
XcSurface *xc_surface;
- int needs_new_xc_surface;
unsigned int ref_count;
-} XrSurface;
+};
typedef struct _XrColor {
double red;
@@ -224,8 +211,6 @@ typedef struct _XrFont {
#define XR_GSTATE_MITER_LIMIT_DEFAULT 10.0
typedef struct _XrGState {
- Display *dpy;
-
XrOperator operator;
double tolerance;
@@ -242,13 +227,11 @@ typedef struct _XrGState {
int num_dashes;
double dash_offset;
- XcFormat *alphaFormat;
-
XrFont font;
- XrSurface *parent_surface;
XrSurface *surface;
- XrSurface *src;
+ XrSurface *solid;
+ XrSurface *pattern;
XrSurface *mask;
double alpha;
@@ -269,7 +252,6 @@ typedef struct _XrGState {
} XrGState;
struct _XrState {
- Display *dpy;
XrGState *stack;
XrStatus status;
};
@@ -306,10 +288,10 @@ typedef struct _XrFiller {
/* xrstate.c */
XrState *
-_XrStateCreate(Display *dpy);
+_XrStateCreate(void);
XrStatus
-_XrStateInit(XrState *state, Display *dpy);
+_XrStateInit(XrState *state);
void
_XrStateDeinit(XrState *xrs);
@@ -325,10 +307,10 @@ _XrStatePop(XrState *xrs);
/* xrgstate.c */
XrGState *
-_XrGStateCreate(Display *dpy);
+_XrGStateCreate(void);
void
-_XrGStateInit(XrGState *gstate, Display *dpy);
+_XrGStateInit(XrGState *gstate);
XrStatus
_XrGStateInitCopy(XrGState *gstate, XrGState *other);
@@ -358,6 +340,19 @@ XrStatus
_XrGStateSetFormat(XrGState *gstate, XrFormat format);
XrStatus
+_XrGStateSetTargetSurface (XrGState *gstate, XrSurface *surface);
+
+XrSurface *
+_XrGStateGetTargetSurface (XrGState *gstate);
+
+XrStatus
+_XrGStateSetTargetDrawable (XrGState *gstate,
+ Display *dpy,
+ Drawable drawable,
+ Visual *visual,
+ XrFormat format);
+
+XrStatus
_XrGStateSetOperator(XrGState *gstate, XrOperator operator);
XrStatus
@@ -487,6 +482,14 @@ _XrGStateShowImageTransform(XrGState *gstate,
double c, double d,
double tx, double ty);
+XrStatus
+_XrGStateShowSurface(XrGState *gstate,
+ XrSurface *surface,
+ int x,
+ int y,
+ int width,
+ int height);
+
/* xrcolor.c */
void
_XrColorInit(XrColor *color);
@@ -554,72 +557,28 @@ XrStatus
_XrPathInterpret(XrPath *path, XrPathDirection dir, XrPathCallbacks *cb, void *closure);
/* xrsurface.c */
-XrSurface *
-_XrSurfaceCreate(Display *dpy);
-
-void
-_XrSurfaceInit(XrSurface *surface, Display *dpy);
-
-void
-_XrSurfaceDeinit(XrSurface *surface);
-
-void
-_XrSurfaceDestroy(XrSurface *surface);
void
_XrSurfaceReference(XrSurface *surface);
-void
-_XrSurfaceDereference(XrSurface *surface);
-
-void
-_XrSurfaceDereferenceDestroy(XrSurface *surface);
-
-void
-_XrSurfaceSetSolidColor(XrSurface *surface, XrColor *color);
-
-XrStatus
-_XrSurfaceSetImage(XrSurface *surface,
- char *data,
- unsigned int width,
- unsigned int height,
- unsigned int stride);
-
XrStatus
_XrSurfaceSetTransform(XrSurface *surface, XrTransform *transform);
-void
-_XrSurfaceSetDrawable(XrSurface *surface, Drawable drawable);
-
-void
-_XrSurfaceSetDrawableWH(XrSurface *surface,
- Drawable drawable,
- unsigned int width,
- unsigned int height);
-
-void
-_XrSurfaceSetVisual(XrSurface *surface, Visual *visual);
-
-void
-_XrSurfaceSetFormat(XrSurface *surface, XrFormat format);
-
XcSurface *
_XrSurfaceGetXcSurface(XrSurface *surface);
+/* XXX: This function is going away, right? */
Picture
_XrSurfaceGetPicture(XrSurface *surface);
-Drawable
-_XrSurfaceGetDrawable(XrSurface *surface);
-
-unsigned int
-_XrSurfaceGetWidth(XrSurface *surface);
-
-unsigned int
-_XrSurfaceGetHeight(XrSurface *surface);
-
-unsigned int
-_XrSurfaceGetDepth(XrSurface *surface);
+void
+_XrSurfaceFillRectangle (XrSurface *surface,
+ XrOperator operator,
+ XrColor *color,
+ int x,
+ int y,
+ int width,
+ int height);
/* xrpen.c */
XrStatus
@@ -762,13 +721,13 @@ _XrTransformBoundingBox(XrTransform *transform,
double *width, double *height);
XrStatus
-_XrTransformComputeInverse(XrTransform *transform);
+_XrTransformInvert(XrTransform *transform);
void
_XrTransformComputeDeterminant(XrTransform *transform, double *det);
void
-_XrTransformEigenValues(XrTransform *transform, double *lambda1, double *lambda2);
+_XrTransformComputeEigenValues(XrTransform *transform, double *lambda1, double *lambda2);
/* xrtraps.c */
void
diff --git a/src/xrstate.c b/src/xrstate.c
index 720f3370..92768097 100644
--- a/src/xrstate.c
+++ b/src/xrstate.c
@@ -27,7 +27,7 @@
#include "xrint.h"
XrState *
-_XrStateCreate(Display *dpy)
+_XrStateCreate(void)
{
XrStatus status;
XrState *xrs;
@@ -35,7 +35,7 @@ _XrStateCreate(Display *dpy)
xrs = malloc(sizeof(XrState));
if (xrs) {
- status = _XrStateInit(xrs, dpy);
+ status = _XrStateInit(xrs);
if (status) {
free(xrs);
return NULL;
@@ -46,9 +46,8 @@ _XrStateCreate(Display *dpy)
}
XrStatus
-_XrStateInit(XrState *xrs, Display *dpy)
+_XrStateInit(XrState *xrs)
{
- xrs->dpy = dpy;
xrs->stack = NULL;
xrs->status = XrStatusSuccess;
@@ -79,7 +78,7 @@ _XrStatePush(XrState *xrs)
if (xrs->stack) {
top = _XrGStateClone(xrs->stack);
} else {
- top = _XrGStateCreate(xrs->dpy);
+ top = _XrGStateCreate();
}
if (top == NULL)
diff --git a/src/xrsurface.c b/src/xrsurface.c
index d3a849a5..a1dd69f0 100644
--- a/src/xrsurface.c
+++ b/src/xrsurface.c
@@ -28,151 +28,238 @@
#include "xrint.h"
XrSurface *
-_XrSurfaceCreate(Display *dpy)
+XrSurfaceCreateForDrawable (Display *dpy,
+ Drawable drawable,
+ Visual *visual,
+ XrFormat format,
+ Colormap colormap)
{
XrSurface *surface;
surface = malloc(sizeof(XrSurface));
+ if (surface == NULL)
+ return NULL;
+
+ surface->dpy = dpy;
+ surface->image_data = NULL;
- if (surface)
- _XrSurfaceInit(surface, dpy);
+ surface->xc_surface = XcSurfaceCreateForDrawable (dpy, drawable, visual, format, colormap);
+ if (surface->xc_surface == NULL) {
+ free (surface);
+ return NULL;
+ }
+
+ surface->ref_count = 1;
return surface;
}
-void
-_XrSurfaceInit(XrSurface *surface, Display *dpy)
-{
- surface->dpy = dpy;
+/* XXX: These definitions are 100% bogus. The problem that needs to be
+ fixed is that Ic needs to export a real API for passing in
+ formats. */
+#define PICT_FORMAT(bpp,type,a,r,g,b) (((bpp) << 24) | \
+ ((type) << 16) | \
+ ((a) << 12) | \
+ ((r) << 8) | \
+ ((g) << 4) | \
+ ((b)))
- surface->drawable = 0;
- surface->gc = 0;
+/*
+ * gray/color formats use a visual index instead of argb
+ */
+#define PICT_VISFORMAT(bpp,type,vi) (((bpp) << 24) | \
+ ((type) << 16) | \
+ ((vi)))
- surface->width = 0;
- surface->height = 0;
- surface->depth = 0;
+#define PICT_TYPE_A 1
+#define PICT_TYPE_ARGB 2
- surface->xc_sa_mask = 0;
+#define PICT_FORMAT_COLOR(f) (PICT_FORMAT_TYPE(f) & 2)
- _XrSurfaceSetFormat(surface, XrFormatARGB32);
+/* 32bpp formats */
- surface->xc_surface = 0;
- surface->needs_new_xc_surface = 1;
+#define PICT_a8r8g8b8 PICT_FORMAT(32,PICT_TYPE_ARGB,8,8,8,8)
+#define PICT_x8r8g8b8 PICT_FORMAT(32,PICT_TYPE_ARGB,0,8,8,8)
+#define PICT_a8 PICT_FORMAT(8,PICT_TYPE_A,8,0,0,0)
+#define PICT_a1 PICT_FORMAT(1,PICT_TYPE_A,1,0,0,0)
- surface->ref_count = 0;
+static int
+_XrFormatBPP (XrFormat format)
+{
+ switch (format) {
+ case XrFormatA1:
+ return 1;
+ break;
+ case XrFormatA8:
+ return 8;
+ break;
+ case XrFormatARGB32:
+ case XrFormatRGB32:
+ default:
+ return 32;
+ break;
+ }
}
-void
-_XrSurfaceDeinit(XrSurface *surface)
+XrSurface *
+XrSurfaceCreateForImage (char *data,
+ XrFormat format,
+ int width,
+ int height,
+ int stride)
{
- if (surface->xc_surface)
- XcFreeSurface(surface->dpy, surface->xc_surface);
- if (surface->gc)
- XFreeGC(surface->dpy, surface->gc);
+ XrSurface *surface;
+ IcFormat icformat;
+ IcImage *image;
+ int bpp;
+
+ /* XXX: This all needs to change, (but IcFormatInit interface needs to change first) */
+ switch (format) {
+ case XrFormatARGB32:
+ IcFormatInit (&icformat, PICT_a8r8g8b8);
+ bpp = 32;
+ break;
+ case XrFormatRGB32:
+ IcFormatInit (&icformat, PICT_x8r8g8b8);
+ bpp = 32;
+ break;
+ case XrFormatA8:
+ IcFormatInit (&icformat, PICT_a8);
+ bpp = 8;
+ break;
+ case XrFormatA1:
+ IcFormatInit (&icformat, PICT_a1);
+ bpp = 1;
+ break;
+ default:
+ return NULL;
+ }
+
+ surface = malloc(sizeof(XrSurface));
+ if (surface == NULL)
+ return NULL;
+
+ surface->dpy = NULL;
+ surface->image_data = NULL;
+ image = IcImageCreateForData ((IcBits *) data, &icformat, width, height, _XrFormatBPP (format), stride);
+ if (image == NULL) {
+ free (surface);
+ return NULL;
+ }
+
+ surface->xc_surface = XcSurfaceCreateForIcImage (image);
+ if (surface->xc_surface == NULL) {
+ IcImageDestroy (image);
+ free (surface);
+ return NULL;
+ }
+
+ surface->ref_count = 1;
+
+ return surface;
}
-void
-_XrSurfaceDestroy(XrSurface *surface)
+XrSurface *
+XrSurfaceCreateNextTo (XrSurface *neighbor, XrFormat format, int width, int height)
{
- _XrSurfaceDeinit(surface);
- free(surface);
+ return XrSurfaceCreateNextToSolid (neighbor, format, width, height, 0, 0, 0, 0);
}
-void
-_XrSurfaceReference(XrSurface *surface)
+static int
+_XrFormatDepth (XrFormat format)
{
- surface->ref_count++;
+ switch (format) {
+ case XrFormatA1:
+ return 1;
+ case XrFormatA8:
+ return 8;
+ case XrFormatARGB32:
+ case XrFormatRGB32:
+ default:
+ return 32;
+ }
}
-void
-_XrSurfaceDereference(XrSurface *surface)
+XrSurface *
+XrSurfaceCreateNextToSolid (XrSurface *neighbor,
+ XrFormat format,
+ int width,
+ int height,
+ double red,
+ double green,
+ double blue,
+ double alpha)
{
- if (surface->ref_count == 0)
- _XrSurfaceDeinit(surface);
- else
- surface->ref_count--;
+ XrSurface *surface = NULL;
+ XrColor color;
+
+ /* XXX: CreateNextTo should perhaps move down to Xc, (then we
+ could drop xrsurface->dpy as well) */
+ if (neighbor->dpy) {
+ Display *dpy = neighbor->dpy;
+ int scr = DefaultScreen (dpy);
+
+ Pixmap pix = XCreatePixmap(dpy,
+ DefaultRootWindow (dpy),
+ width, height,
+ _XrFormatDepth (format));
+
+ surface = XrSurfaceCreateForDrawable (dpy, pix,
+ NULL,
+ format,
+ DefaultColormap (dpy, scr));
+ XFreePixmap(surface->dpy, pix);
+ } else {
+ char *data;
+ int stride;
+
+ stride = ((width * _XrFormatBPP (format)) + 7) >> 3;
+ data = malloc (stride * height);
+ if (data == NULL)
+ return NULL;
+
+ surface = XrSurfaceCreateForImage (data, format,
+ width, height, stride);
+
+ /* lodge data in the surface structure to be freed with the surface */
+ surface->image_data = data;
+ }
+
+ /* XXX: Initializing the color in this way assumes
+ non-pre-multiplied alpha. I'm not sure that that's what I want
+ to do or not. */
+ _XrColorInit (&color);
+ _XrColorSetRGB (&color, red, green, blue);
+ _XrColorSetAlpha (&color, alpha);
+ _XrSurfaceFillRectangle (surface, XrOperatorSrc, &color, 0, 0, width, height);
+ return surface;
}
void
-_XrSurfaceDereferenceDestroy(XrSurface *surface)
+_XrSurfaceReference(XrSurface *surface)
{
- if (surface->ref_count == 0)
- _XrSurfaceDestroy(surface);
- else
- _XrSurfaceDereference(surface);
+ if (surface == NULL)
+ return;
+
+ surface->ref_count++;
}
void
-_XrSurfaceSetSolidColor(XrSurface *surface, XrColor *color)
+XrSurfaceDestroy(XrSurface *surface)
{
- /* XXX: QUESTION: Special handling for depth==1 ala xftdraw.c? */
- if (surface->xc_surface == 0) {
- Pixmap pix = XCreatePixmap(surface->dpy,
- DefaultRootWindow(surface->dpy),
- 1, 1,
- surface->xc_format->depth);
- _XrSurfaceSetDrawableWH(surface, pix, 1, 1);
- surface->xc_sa_mask |= CPRepeat;
- surface->xc_sa.repeat = True;
- _XrSurfaceGetXcSurface(surface);
- XFreePixmap(surface->dpy, pix);
- }
-
- XcFillRectangle(surface->dpy, PictOpSrc,
- surface->xc_surface, &color->xc_color,
- 0, 0, 1, 1);
-}
+ if (surface == NULL)
+ return;
-XrStatus
-_XrSurfaceSetImage(XrSurface *surface,
- char *data,
- unsigned int width,
- unsigned int height,
- unsigned int stride)
-{
- XImage *image;
- unsigned int depth, bitmap_pad;
- Pixmap pix;
-
- depth = surface->xc_format->depth;
-
- if (depth > 16)
- bitmap_pad = 32;
- else if (depth > 8)
- bitmap_pad = 16;
- else
- bitmap_pad = 8;
-
- pix = XCreatePixmap(surface->dpy,
- DefaultRootWindow(surface->dpy),
- width, height,
- depth);
- _XrSurfaceSetDrawableWH(surface, pix, width, height);
-
- image = XCreateImage(surface->dpy,
- DefaultVisual(surface->dpy, DefaultScreen(surface->dpy)),
- depth, ZPixmap, 0,
- data, width, height,
- bitmap_pad,
- stride);
- if (image == NULL)
- return XrStatusNoMemory;
-
- XPutImage(surface->dpy, surface->drawable, surface->gc,
- image, 0, 0, 0, 0, width, height);
-
-
- /* I want to free the pixmap, so I have to commit to an xc_surface
- to reference the pixmap in the Picture. */
- _XrSurfaceGetXcSurface(surface);
- XFreePixmap(surface->dpy, pix);
-
- /* Foolish XDestroyImage thinks it can free my data, but I won't
- stand for it. */
- image->data = NULL;
- XDestroyImage(image);
+ surface->ref_count--;
+ if (surface->ref_count)
+ return;
- return XrStatusSuccess;
+ surface->dpy = 0;
+
+ XcSurfaceDestroy (surface->xc_surface);
+ surface->xc_surface = NULL;
+
+ free(surface);
}
/* XXX: We may want to move to projective matrices at some point. If
@@ -195,129 +282,50 @@ _XrSurfaceSetTransform(XrSurface *surface, XrTransform *transform)
xtransform.matrix[2][1] = 0;
xtransform.matrix[2][2] = XDoubleToFixed(1);
- XcSetSurfaceTransform(surface->dpy,
- _XrSurfaceGetXcSurface(surface),
+ XcSurfaceSetTransform(surface->xc_surface,
&xtransform);
return XrStatusSuccess;
}
-void
-_XrSurfaceSetDrawable(XrSurface *surface, Drawable drawable)
-{
- Window root;
- int x, y;
- unsigned int border, depth;
- unsigned int width, height;
-
- XGetGeometry (surface->dpy, drawable,
- &root, &x, &y,
- &width, &height,
- &border, &depth);
-
- _XrSurfaceSetDrawableWH(surface, drawable, width, height);
-}
-
-void
-_XrSurfaceSetDrawableWH(XrSurface *surface,
- Drawable drawable,
- unsigned int width,
- unsigned int height)
-{
- if (surface->gc)
- XFreeGC(surface->dpy, surface->gc);
-
- surface->drawable = drawable;
- surface->width = width;
- surface->height = height;
- surface->gc = XCreateGC(surface->dpy, surface->drawable, 0, 0);
-
- surface->needs_new_xc_surface = 1;
-}
-
-void
-_XrSurfaceSetVisual(XrSurface *surface, Visual *visual)
-{
- surface->xc_format = XcFindVisualFormat(surface->dpy, visual);
- surface->needs_new_xc_surface = 1;
-}
-
-void
-_XrSurfaceSetFormat(XrSurface *surface, XrFormat format)
+/* XXX: The Xc version of this function isn't quite working yet
+XrStatus
+XrSurfaceSetClipRegion (XrSurface *surface, Region region)
{
- surface->format = format;
- surface->xc_format = XcFindStandardFormat(surface->dpy, format);
-
- switch (surface->format) {
- case XrFormatARGB32:
- surface->depth = 32;
- case XrFormatRGB32:
- /* XXX: Is this correct? */
- surface->depth = 24;
- case XrFormatA8:
- surface->depth = 8;
- case XrFormatA1:
- surface->depth = 1;
- default:
- surface->depth = 32;
- }
+ XcSurfaceSetClipRegion (surface->xc_surface, region);
- surface->needs_new_xc_surface = 1;
+ return XrStatusSuccess;
}
+*/
-XcSurface *
-_XrSurfaceGetXcSurface(XrSurface *surface)
+XrStatus
+XrSurfaceSetRepeat (XrSurface *surface, int repeat)
{
- if (surface == NULL)
- return NULL;
+ XcSurfaceSetRepeat (surface->xc_surface, repeat);
- if (! surface->needs_new_xc_surface)
- return surface->xc_surface;
-
- if (surface->xc_surface)
- XcFreeSurface(surface->dpy, surface->xc_surface);
-
- if (surface->drawable)
- surface->xc_surface = XcCreateDrawableSurface(surface->dpy,
- surface->drawable,
- surface->xc_format,
- surface->xc_sa_mask,
- &surface->xc_sa);
- else
- /* XXX: Is this what we wnat to do here? */
- surface->xc_surface = 0;
-
- surface->needs_new_xc_surface = 0;
-
- return surface->xc_surface;
+ return XrStatusSuccess;
}
+/* XXX: This function is going away, right? */
Picture
_XrSurfaceGetPicture(XrSurface *surface)
{
- return XcSurfaceGetPicture(_XrSurfaceGetXcSurface(surface));
-}
-
-Drawable
-_XrSurfaceGetDrawable(XrSurface *surface)
-{
- return surface->drawable;
-}
-
-unsigned int
-_XrSurfaceGetWidth(XrSurface *surface)
-{
- return surface->width;
+ return XcSurfaceGetPicture(surface->xc_surface);
}
-unsigned int
-_XrSurfaceGetHeight(XrSurface *surface)
+void
+_XrSurfaceFillRectangle (XrSurface *surface,
+ XrOperator operator,
+ XrColor *color,
+ int x,
+ int y,
+ int width,
+ int height)
{
- return surface->height;
+ XcFillRectangle (operator,
+ surface->xc_surface,
+ &color->xc_color,
+ x, y,
+ width, height);
}
-unsigned int
-_XrSurfaceGetDepth(XrSurface *surface)
-{
- return surface->depth;
-}
diff --git a/src/xrtransform.c b/src/xrtransform.c
index 93e7ea23..e8eee7ee 100644
--- a/src/xrtransform.c
+++ b/src/xrtransform.c
@@ -241,18 +241,18 @@ _XrTransformComputeAdjoint(XrTransform *transform)
}
XrStatus
-_XrTransformComputeInverse(XrTransform *transform)
+_XrTransformInvert (XrTransform *transform)
{
/* inv(A) = 1/det(A) * adj(A) */
double det;
- _XrTransformComputeDeterminant(transform, &det);
+ _XrTransformComputeDeterminant (transform, &det);
if (det == 0)
return XrStatusInvalidMatrix;
- _XrTransformComputeAdjoint(transform);
- _XrTransformScalarMultiply(transform, 1 / det);
+ _XrTransformComputeAdjoint (transform);
+ _XrTransformScalarMultiply (transform, 1 / det);
return XrStatusSuccess;
}
@@ -269,7 +269,7 @@ _XrTransformComputeDeterminant(XrTransform *transform, double *det)
}
void
-_XrTransformEigenValues(XrTransform *transform, double *lambda1, double *lambda2)
+_XrTransformComputeEigenValues (XrTransform *transform, double *lambda1, double *lambda2)
{
/* The eigenvalues of an NxN matrix M are found by solving the polynomial: