From 70ac013544f6ff67079a235ef5c67551654beea5 Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Fri, 16 Dec 2022 12:15:39 +0800 Subject: PangoWin32: Avoid initializing DirectWrite repeatedly Make sure that we use the GPrivate to grab the DirectWrite boilerplate items that we might have setup, and only attempt to initialize DirectWrite if the items have not been previously setup. --- pango/pangowin32-dwrite-fontmap.cpp | 2 +- pango/pangowin32.c | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/pango/pangowin32-dwrite-fontmap.cpp b/pango/pangowin32-dwrite-fontmap.cpp index a2c03675..8f3a3095 100644 --- a/pango/pangowin32-dwrite-fontmap.cpp +++ b/pango/pangowin32-dwrite-fontmap.cpp @@ -424,7 +424,7 @@ pango_win32_font_description_from_logfontw_dwrite (const LOGFONTW *logfontw) PangoStretch stretch; PangoWin32DWriteItems *dwrite_items; - dwrite_items = pango_win32_init_direct_write (); + dwrite_items = pango_win32_get_direct_write_items (); if (dwrite_items == NULL) return NULL; diff --git a/pango/pangowin32.c b/pango/pangowin32.c index 5a26ee98..7b6325a5 100644 --- a/pango/pangowin32.c +++ b/pango/pangowin32.c @@ -133,7 +133,6 @@ HDC _pango_win32_get_display_dc (void) { HDC hdc = g_private_get (&display_dc_key); - PangoWin32DWriteItems *items; if (hdc == NULL) { @@ -154,12 +153,8 @@ _pango_win32_get_display_dc (void) #endif } - items = g_private_get (&dwrite_items); - if (items == NULL) - { - items = pango_win32_init_direct_write (); - g_private_set (&dwrite_items, items); - } + /* ensure DirectWrite is initialized */ + pango_win32_get_direct_write_items (); return hdc; } @@ -167,7 +162,15 @@ _pango_win32_get_display_dc (void) PangoWin32DWriteItems * pango_win32_get_direct_write_items (void) { - return g_private_get (&dwrite_items); + PangoWin32DWriteItems *items = g_private_get (&dwrite_items); + + if (items == NULL) + { + items = pango_win32_init_direct_write (); + g_private_set (&dwrite_items, items); + } + + return items; } /** -- cgit v1.2.1