win32: Make font dc thread local

This commit is contained in:
Yongsu Park 2020-03-11 21:13:09 +09:00
parent aee96d175d
commit e2ba2e00a9
2 changed files with 18 additions and 1 deletions

View file

@ -53,6 +53,7 @@ CAIRO_MUTEX_DECLARE (_cairo_ft_unscaled_font_map_mutex)
#if CAIRO_HAS_WIN32_FONT
CAIRO_MUTEX_DECLARE (_cairo_win32_font_face_mutex)
CAIRO_MUTEX_DECLARE (_cairo_win32_font_dc_mutex)
#endif
#if CAIRO_HAS_XLIB_SURFACE

View file

@ -162,8 +162,19 @@ _cairo_win32_scaled_font_init_glyph_path (cairo_win32_scaled_font_t *scaled_font
static HDC
_get_global_font_dc (void)
{
static HDC hdc;
static DWORD hdc_tls_index;
HDC hdc;
if (!hdc_tls_index) {
CAIRO_MUTEX_LOCK (_cairo_win32_font_dc_mutex);
if (!hdc_tls_index) {
hdc_tls_index = TlsAlloc ();
assert (hdc_tls_index != TLS_OUT_OF_INDEXES);
}
CAIRO_MUTEX_UNLOCK (_cairo_win32_font_dc_mutex);
}
hdc = TlsGetValue (hdc_tls_index);
if (!hdc) {
hdc = CreateCompatibleDC (NULL);
if (!hdc) {
@ -176,6 +187,11 @@ _get_global_font_dc (void)
DeleteDC (hdc);
return NULL;
}
if (!TlsSetValue (hdc_tls_index, hdc)) {
DeleteDC (hdc);
return NULL;
}
}
return hdc;