[xlib] Defer querying of font options until first use

Constructing the font options cause the initialisation of Xlc and invoke
several round-trips to the X server, significantly delaying the creation
of the first surface. By deferring that operation until the first use of
fonts then we avoid that overhead for very simple applications (like the
test suite) and should improve start-up latency for larger application.
This commit is contained in:
Chris Wilson 2008-10-24 08:39:29 +01:00
parent 6706590d4e
commit a002375810
3 changed files with 30 additions and 4 deletions

View file

@ -97,6 +97,7 @@ struct _cairo_xlib_screen_info {
Screen *screen;
cairo_bool_t has_render;
cairo_bool_t has_font_options;
cairo_font_options_t font_options;
GC gc[9];
@ -151,6 +152,9 @@ _cairo_xlib_screen_get_gc (cairo_xlib_screen_info_t *info, int depth);
cairo_private cairo_status_t
_cairo_xlib_screen_put_gc (cairo_xlib_screen_info_t *info, int depth, GC gc, cairo_bool_t reset_clip);
cairo_private cairo_font_options_t *
_cairo_xlib_screen_get_font_options (cairo_xlib_screen_info_t *info);
cairo_private cairo_status_t
_cairo_xlib_screen_get_visual_info (cairo_xlib_screen_info_t *info,
Visual *visual,

View file

@ -144,7 +144,8 @@ get_integer_default (Display *dpy,
#endif
static void
_cairo_xlib_init_screen_font_options (Display *dpy, cairo_xlib_screen_info_t *info)
_cairo_xlib_init_screen_font_options (Display *dpy,
cairo_xlib_screen_info_t *info)
{
cairo_bool_t xft_hinting;
cairo_bool_t xft_antialias;
@ -353,7 +354,7 @@ _cairo_xlib_screen_info_get (cairo_xlib_display_t *display, Screen *screen)
info->display = _cairo_xlib_display_reference (display);
info->screen = screen;
info->has_render = FALSE;
_cairo_font_options_init_default (&info->font_options);
info->has_font_options = FALSE;
memset (info->gc, 0, sizeof (info->gc));
info->gc_needs_clip_reset = 0;
@ -366,7 +367,6 @@ _cairo_xlib_screen_info_get (cairo_xlib_display_t *display, Screen *screen)
info->has_render = (XRenderQueryExtension (dpy, &event_base, &error_base) &&
(XRenderFindVisualFormat (dpy, DefaultVisual (dpy, DefaultScreen (dpy))) != 0));
_cairo_xlib_init_screen_font_options (dpy, info);
}
CAIRO_MUTEX_LOCK (display->mutex);
@ -502,3 +502,25 @@ _cairo_xlib_screen_get_visual_info (cairo_xlib_screen_info_t *info,
*out = ret;
return CAIRO_STATUS_SUCCESS;
}
cairo_font_options_t *
_cairo_xlib_screen_get_font_options (cairo_xlib_screen_info_t *info)
{
if (info->has_font_options)
return &info->font_options;
CAIRO_MUTEX_LOCK (info->mutex);
if (! info->has_font_options) {
Display *dpy = info->display->display;
_cairo_font_options_init_default (&info->font_options);
if (info->screen != NULL)
_cairo_xlib_init_screen_font_options (dpy, info);
info->has_font_options = TRUE;
}
CAIRO_MUTEX_UNLOCK (info->mutex);
return &info->font_options;
}

View file

@ -2348,7 +2348,7 @@ _cairo_xlib_surface_get_font_options (void *abstract_surface,
{
cairo_xlib_surface_t *surface = abstract_surface;
*options = surface->screen_info->font_options;
*options = *_cairo_xlib_screen_get_font_options (surface->screen_info);
}
static void