1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-05-09 13:42:09 -05:00

GTK/x11font/Cairo: use XDrawString16 instead of XDrawImageString16

On my test case, this reduces Xwayland's CPU usage by 5-10%, though
curiously in glamor_block_handler rather than the drawing routine
itself.

XDrawImageString16 isn't as helpful as it might be for two reasons.
First, "M" type fonts (e.g. Courier Oblique) can extend beyond the
rectangle erased by XDrawImageString16, and PuTTY tries to support such
fonts.  And second, we really want to blank the pixmap after drawing
rather than before, because otherwise we have to muck around clipping
the mask operation.  So avoinding the XFillRectangle calls is difficult,
at which point we may as well use XDrawString16.
This commit is contained in:
Ben Harris 2025-05-06 22:17:45 +01:00
parent 649c8155e7
commit b66ec0c257

View File

@ -686,16 +686,10 @@ static void x11font_cairo_ensure_pixmap(
xfi->pattern = cairo_pattern_create_for_surface(xfi->surface);
/* We really don't want bilinear interpolation of bitmap fonts. */
cairo_pattern_set_filter(xfi->pattern, CAIRO_FILTER_NEAREST);
XGCValues gcvals = {
.function = GXclear,
.foreground = 0xffffffff,
.background = 0,
.font = xfi->xfs->fid,
};
xfi->gc = XCreateGC(disp, newpixmap,
GCFunction | GCForeground | GCBackground | GCFont,
&gcvals);
XGCValues gcvals = { .font = xfi->xfs->fid };
xfi->gc = XCreateGC(disp, newpixmap, GCFont, &gcvals);
}
XSetFunction(disp, xfi->gc, GXclear);
XFillRectangle(disp, newpixmap, xfi->gc, 0, 0, width, height);
xfi->pixmap = newpixmap;
xfi->pixwidth = width;
@ -715,7 +709,8 @@ static void x11font_cairo_draw(
pixheight = bounds.ascent + bounds.descent;
if (pixwidth > 0 && pixheight > 0) {
x11font_cairo_ensure_pixmap(ctx, xfi, disp, pixwidth, pixheight);
XDrawImageString16(disp, xfi->pixmap, xfi->gc,
XSetFunction(disp, xfi->gc, GXset);
XDrawString16(disp, xfi->pixmap, xfi->gc,
-bounds.lbearing, bounds.ascent,
string+start, length);
cairo_surface_mark_dirty(xfi->surface);
@ -725,6 +720,7 @@ static void x11font_cairo_draw(
cairo_pattern_set_matrix(xfi->pattern, &xfrm);
cairo_mask(ctx->u.cairo.cr, xfi->pattern);
/* Clear the part of the pixmap that we used. */
XSetFunction(disp, xfi->gc, GXclear);
XFillRectangle(disp, xfi->pixmap, xfi->gc, 0, 0, pixwidth, pixheight);
}
}