mirror of
https://github.com/gnustep/libs-back.git
synced 2025-04-22 15:31:14 +00:00
cache Xft draw state in XGGState and use this to speed glyph rendering in GSXftFontInfo
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/back/trunk@21218 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
738cc721ad
commit
940139127e
4 changed files with 78 additions and 111 deletions
|
@ -1,3 +1,12 @@
|
|||
2005-03-29 Adrian Robert <arobert@cogsci.ucsd.edu>
|
||||
|
||||
* Headers/xlib/XGGState.h (xft_draw, xft_alpha_draw, xft_color,
|
||||
-xftDrawForDrawable, -xftColor): New ivars and methods for caching
|
||||
Xft (freetype) draw state.
|
||||
* Source/xlib/XGGState.m (-xftDrawForDrawable:, -xftColor): Cache
|
||||
Xft draw state.
|
||||
* Source/xlib/GSXftFontInfo.m: Use cached Xft draw state for rendering.
|
||||
|
||||
2005-04-20 Adam Fedor <fedor@gnu.org>
|
||||
|
||||
* Fonts/GNUmakefile.postamble: Make sure to install in
|
||||
|
|
|
@ -31,6 +31,11 @@
|
|||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include "x11/XGServer.h"
|
||||
#ifdef HAVE_LIBXFT
|
||||
#define id xwindowsid
|
||||
#include <X11/Xft/Xft.h>
|
||||
#undef id
|
||||
#endif
|
||||
|
||||
@class NSBezierPath;
|
||||
@class NSFont;
|
||||
|
@ -47,6 +52,11 @@
|
|||
Drawable draw;
|
||||
Drawable alpha_buffer;
|
||||
Region clipregion;
|
||||
#ifdef HAVE_LIBXFT
|
||||
XftDraw *xft_draw;
|
||||
XftDraw *xft_alpha_draw;
|
||||
XftColor xft_color;
|
||||
#endif
|
||||
|
||||
BOOL drawingAlpha;
|
||||
BOOL sharedGC; /* Do we own the GC or share it? */
|
||||
|
@ -64,6 +74,10 @@
|
|||
- (Drawable) drawable;
|
||||
- (GC) graphicContext;
|
||||
- (NSRect) clipRect;
|
||||
#ifdef HAVE_LIBXFT
|
||||
- (XftDraw *)xftDrawForDrawable: (Drawable)d;
|
||||
- (XftColor)xftColor;
|
||||
#endif
|
||||
|
||||
- (XPoint) viewPointToX: (NSPoint)aPoint;
|
||||
- (XRectangle) viewRectToX: (NSRect)aRect;
|
||||
|
|
|
@ -374,62 +374,22 @@ static NSArray *faFromFc(FcPattern *pat)
|
|||
allowLossyConversion: YES];
|
||||
int length = [d length];
|
||||
const char *cstr = (const char*)[d bytes];
|
||||
XftDraw *xftdraw;
|
||||
XftColor xftcolor;
|
||||
XColor dummyc;
|
||||
XGCValues values;
|
||||
XGGState *state = [(XGContext *)GSCurrentContext() currentGState];
|
||||
Region xregion = [state xClipRegion];
|
||||
int defaultScreen = DefaultScreen(xdpy);
|
||||
Colormap colmap = DefaultColormap(xdpy, defaultScreen);
|
||||
|
||||
/* ready to draw */
|
||||
xftdraw = XftDrawCreate(xdpy, draw,
|
||||
DefaultVisual(xdpy, defaultScreen),
|
||||
colmap);
|
||||
if(xftdraw == NULL)
|
||||
return;
|
||||
|
||||
/* sort out the drawing colour */
|
||||
XGetGCValues(xdpy, xgcntxt,
|
||||
GCForeground | GCBackground,
|
||||
&values);
|
||||
|
||||
dummyc.pixel = values.foreground;
|
||||
XQueryColor(xdpy, colmap, &dummyc);
|
||||
xftcolor.color.red = dummyc.red;
|
||||
xftcolor.color.green = dummyc.green;
|
||||
xftcolor.color.blue = dummyc.blue;
|
||||
xftcolor.color.alpha = 0xffff;
|
||||
xftcolor.pixel = values.foreground;
|
||||
|
||||
// set up clipping
|
||||
if(xregion != None)
|
||||
{
|
||||
XftDrawSetClip(xftdraw, xregion);
|
||||
XDestroyRegion(xregion);
|
||||
}
|
||||
XftDraw *xftdraw = [state xftDrawForDrawable: draw];
|
||||
XftColor xftcolor = [state xftColor];
|
||||
|
||||
/* do it */
|
||||
XftDrawString16(xftdraw, &xftcolor, font_info,
|
||||
xp.x, xp.y, (XftChar16*)cstr, length);
|
||||
|
||||
/* tidy up */
|
||||
XftDrawDestroy(xftdraw);
|
||||
}
|
||||
|
||||
- (void) drawGlyphs: (const NSGlyph *) glyphs lenght: (int) len
|
||||
onDisplay: (Display*) xdpy drawable: (Drawable) draw
|
||||
with: (GC) xgcntxt at: (XPoint) xp
|
||||
{
|
||||
XftDraw *xftdraw;
|
||||
XftColor xftcolor;
|
||||
XColor dummyc;
|
||||
XGCValues values;
|
||||
XGGState *state = [(XGContext *)GSCurrentContext() currentGState];
|
||||
Region xregion = [state xClipRegion];
|
||||
int defaultScreen = DefaultScreen(xdpy);
|
||||
Colormap colmap = DefaultColormap(xdpy, defaultScreen);
|
||||
XftDraw *xftdraw = [state xftDrawForDrawable: draw];
|
||||
XftColor xftcolor = [state xftColor];
|
||||
unichar buf[len];
|
||||
int i;
|
||||
|
||||
|
@ -438,39 +398,9 @@ static NSArray *faFromFc(FcPattern *pat)
|
|||
buf[i] = glyphs[i];
|
||||
}
|
||||
|
||||
/* ready to draw */
|
||||
xftdraw = XftDrawCreate(xdpy, draw,
|
||||
DefaultVisual(xdpy, defaultScreen),
|
||||
colmap);
|
||||
if(xftdraw == NULL)
|
||||
return;
|
||||
|
||||
/* sort out the drawing colour */
|
||||
XGetGCValues(xdpy, xgcntxt,
|
||||
GCForeground | GCBackground,
|
||||
&values);
|
||||
|
||||
dummyc.pixel = values.foreground;
|
||||
XQueryColor(xdpy, colmap, &dummyc);
|
||||
xftcolor.color.red = dummyc.red;
|
||||
xftcolor.color.green = dummyc.green;
|
||||
xftcolor.color.blue = dummyc.blue;
|
||||
xftcolor.color.alpha = 0xffff;
|
||||
xftcolor.pixel = values.foreground;
|
||||
|
||||
// set up clipping
|
||||
if(xregion != None)
|
||||
{
|
||||
XftDrawSetClip(xftdraw, xregion);
|
||||
XDestroyRegion(xregion);
|
||||
}
|
||||
|
||||
/* do it */
|
||||
XftDrawString16(xftdraw, &xftcolor, font_info,
|
||||
xp.x, xp.y, (XftChar16*)buf, len);
|
||||
|
||||
/* tidy up */
|
||||
XftDrawDestroy(xftdraw);
|
||||
}
|
||||
|
||||
- (void) draw: (const char*) s lenght: (int) len
|
||||
|
@ -478,41 +408,9 @@ static NSArray *faFromFc(FcPattern *pat)
|
|||
with: (GC) xgcntxt at: (XPoint) xp
|
||||
{
|
||||
int length = strlen(s);
|
||||
XftDraw *xftdraw;
|
||||
XftColor xftcolor;
|
||||
XColor dummyc;
|
||||
XGCValues values;
|
||||
XGGState *state = [(XGContext *)GSCurrentContext() currentGState];
|
||||
Region xregion = [state xClipRegion];
|
||||
int defaultScreen = DefaultScreen(xdpy);
|
||||
Colormap colmap = DefaultColormap(xdpy, defaultScreen);
|
||||
|
||||
/* ready to draw */
|
||||
xftdraw = XftDrawCreate(xdpy, draw,
|
||||
DefaultVisual(xdpy, defaultScreen),
|
||||
colmap);
|
||||
if(xftdraw == NULL)
|
||||
return;
|
||||
|
||||
/* sort out the drawing colour */
|
||||
XGetGCValues(xdpy, xgcntxt,
|
||||
GCForeground | GCBackground,
|
||||
&values);
|
||||
|
||||
dummyc.pixel = values.foreground;
|
||||
XQueryColor(xdpy, colmap, &dummyc);
|
||||
xftcolor.color.red = dummyc.red;
|
||||
xftcolor.color.green = dummyc.green;
|
||||
xftcolor.color.blue = dummyc.blue;
|
||||
xftcolor.color.alpha = 0xffff;
|
||||
xftcolor.pixel = values.foreground;
|
||||
|
||||
// set up clipping
|
||||
if(xregion != None)
|
||||
{
|
||||
XftDrawSetClip(xftdraw, xregion);
|
||||
XDestroyRegion(xregion);
|
||||
}
|
||||
XftDraw *xftdraw = [state xftDrawForDrawable: draw];
|
||||
XftColor xftcolor = [state xftColor];
|
||||
|
||||
#ifdef HAVE_UTF8
|
||||
/* do it */
|
||||
|
@ -527,9 +425,6 @@ static NSArray *faFromFc(FcPattern *pat)
|
|||
XftDrawString8(xftdraw, &xftcolor, font_info,
|
||||
xp.x, xp.y, (XftChar8*)s, length);
|
||||
}
|
||||
|
||||
/* tidy up */
|
||||
XftDrawDestroy(xftdraw);
|
||||
}
|
||||
|
||||
- (float) widthOf: (const char*) s lenght: (int) len
|
||||
|
|
|
@ -107,6 +107,11 @@ static Region emptyRegion;
|
|||
alpha_buffer = 0;
|
||||
xgcntxt = None;
|
||||
agcntxt = None;
|
||||
#ifdef HAVE_LIBXFT
|
||||
xft_draw = NULL;
|
||||
xft_alpha_draw = NULL;
|
||||
memset(&xft_color, 0, sizeof(XftColor));
|
||||
#endif
|
||||
return self;
|
||||
}
|
||||
|
||||
|
@ -252,6 +257,13 @@ static Region emptyRegion;
|
|||
gsColorToRGB(&c);
|
||||
gcv.foreground = xrRGBToPixel(context, c);
|
||||
[self setGCValues: gcv withMask: GCForeground];
|
||||
#ifdef HAVE_LIBXFT
|
||||
xft_color.color.red = 65535.0 * c.field[0];
|
||||
xft_color.color.green = 65535.0 * c.field[1];
|
||||
xft_color.color.blue = 65535.0 * c.field[2];
|
||||
xft_color.color.alpha = 0xffff;
|
||||
xft_color.pixel = gcv.foreground;
|
||||
#endif
|
||||
}
|
||||
|
||||
- (void) setAlphaColor: (float)value
|
||||
|
@ -268,6 +280,9 @@ static Region emptyRegion;
|
|||
agcntxt = XCreateGC(XDPY, draw, GCForeground, &gcv);
|
||||
else
|
||||
XChangeGC(XDPY, agcntxt, GCForeground, &gcv);
|
||||
#ifdef HAVE_LIBXFT
|
||||
xft_color.color.alpha = 65535.0 * value;
|
||||
#endif
|
||||
}
|
||||
|
||||
- (void) copyGraphicContext
|
||||
|
@ -348,6 +363,40 @@ static Region emptyRegion;
|
|||
return xgcntxt;
|
||||
}
|
||||
|
||||
- (XftColor) xftColor
|
||||
{
|
||||
return xft_color;
|
||||
}
|
||||
|
||||
- (XftDraw *)xftDrawForDrawable: (Drawable)d
|
||||
{
|
||||
if (d == 0)
|
||||
return 0; //PENDING: warn? throw?
|
||||
|
||||
if (d == draw)
|
||||
{
|
||||
if (xft_draw == NULL)
|
||||
xft_draw =
|
||||
XftDrawCreate(XDPY, d, DefaultVisual(XDPY, DefaultScreen(XDPY)),
|
||||
DefaultColormap(XDPY, DefaultScreen(XDPY)));
|
||||
if (clipregion != None)
|
||||
XftDrawSetClip(xft_draw, clipregion);
|
||||
return xft_draw;
|
||||
}
|
||||
else if (d == alpha_buffer)
|
||||
{
|
||||
if (xft_alpha_draw == NULL)
|
||||
xft_alpha_draw =
|
||||
XftDrawCreate(XDPY, d, DefaultVisual(XDPY, DefaultScreen(XDPY)),
|
||||
DefaultColormap(XDPY, DefaultScreen(XDPY)));
|
||||
if (clipregion != None)
|
||||
XftDrawSetClip(xft_alpha_draw, clipregion);
|
||||
return xft_alpha_draw;
|
||||
}
|
||||
|
||||
return 0; //PENDING: warn? throw?
|
||||
}
|
||||
|
||||
- (void) copyBits: (XGGState*)source fromRect: (NSRect)aRect
|
||||
toPoint: (NSPoint)aPoint
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue