Don't reallocate drawables on every string op. - sam - An updated version of the sam text editor.
(HTM) git clone git://vernunftzentrum.de/sam.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) LICENSE
---
(DIR) commit 4e40c16f1a9abc8c426a65a69bc56800306439aa
(DIR) parent edf98760edc54f65d220af07e4b96c9599948fc8
(HTM) Author: Rob King <jking@deadpixi.com>
Date: Thu, 11 Aug 2016 14:15:48 -0500
Don't reallocate drawables on every string op.
Diffstat:
include/libg.h | 1 +
libXg/balloc.c | 5 ++++-
libXg/string.c | 6 +++---
libXg/xtbinit.c | 1 +
4 files changed, 9 insertions(+), 4 deletions(-)
---
(DIR) diff --git a/include/libg.h b/include/libg.h
@@ -48,6 +48,7 @@ struct Bitmap
int ldepth;
int id; /* as known by the X server */
Bitmap *cache; /* zero; distinguishes bitmap from layer */
+ XftDraw *fd; /* font drawable */
int flag; /* flag used by X implementation of libg */
};
(DIR) diff --git a/libXg/balloc.c b/libXg/balloc.c
@@ -22,7 +22,7 @@ _balloc(Rectangle r, int ldepth)
int ld;
Rectangle rx;
- b = (Bitmap *)malloc(sizeof(Bitmap));
+ b = (Bitmap *)calloc(1, sizeof(Bitmap));
if(b == 0)
berror("balloc malloc");
if (ldepth == 0)
@@ -55,6 +55,9 @@ _balloc(Rectangle r, int ldepth)
void
bfree(Bitmap *b)
{
+ if (b->fd)
+ XftDrawDestroy(b->fd);
+
XFreePixmap(_dpy, (Pixmap)b->id);
free(b);
}
(DIR) diff --git a/libXg/string.c b/libXg/string.c
@@ -25,10 +25,10 @@ string(Bitmap *b, Point p, XftFont *ft, char *s, Fcode f)
}
y += ft->ascent;
- XftDraw *drawable = XftDrawCreate(_dpy, (Drawable)(b->id), DefaultVisual(_dpy, DefaultScreen(_dpy)), DefaultColormap(_dpy, DefaultScreen(_dpy)));
+ if (!b->fd)
+ b->fd = XftDrawCreate(_dpy, (Drawable)(b->id), DefaultVisual(_dpy, DefaultScreen(_dpy)), DefaultColormap(_dpy, DefaultScreen(_dpy)));
- XftDrawStringUtf8(drawable, &fontcolor, ft, x, y, s, length);
- XftDrawDestroy(drawable);
+ XftDrawStringUtf8(b->fd, &fontcolor, ft, x, y, s, length);
x += extents.xOff;
(DIR) diff --git a/libXg/xtbinit.c b/libXg/xtbinit.c
@@ -181,6 +181,7 @@ xtbinit(Errfunc f, char *class, int *pargc, char **argv, char **fallbacks)
screen.id = 0;
XtRealizeWidget(_toplevel);
+
pid_t pid = getpid();
XChangeProperty(_dpy, XtWindow(_toplevel), XInternAtom(_dpy, "_NET_WM_PID", False), XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&pid, 1);