From d5338ba1894f73629528a2a505e30cd681a5f1c6 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 22 Nov 2019 16:22:27 -0500 Subject: [PATCH] [ft] Add locking FT_Face API Now that we mutex our internal FT_Face, share it with clients. New API: - hb_ft_font_lock_face() - hb_ft_font_unlock_face() --- docs/harfbuzz-sections.txt | 2 ++ src/hb-ft.cc | 56 ++++++++++++++++++++++++++++++++++++-- src/hb-ft.h | 6 ++++ 3 files changed, 61 insertions(+), 3 deletions(-) diff --git a/docs/harfbuzz-sections.txt b/docs/harfbuzz-sections.txt index c625b921b..93d6de6ef 100644 --- a/docs/harfbuzz-sections.txt +++ b/docs/harfbuzz-sections.txt @@ -365,6 +365,8 @@ hb_ft_font_create hb_ft_font_create_referenced hb_ft_font_changed hb_ft_font_get_face +hb_ft_font_lock_face +hb_ft_font_unlock_face hb_ft_font_set_load_flags hb_ft_font_get_load_flags hb_ft_font_set_funcs diff --git a/src/hb-ft.cc b/src/hb-ft.cc index 1901e22e5..2a7b0de11 100644 --- a/src/hb-ft.cc +++ b/src/hb-ft.cc @@ -140,7 +140,7 @@ hb_ft_font_set_load_flags (hb_font_t *font, int load_flags) if (hb_object_is_immutable (font)) return; - if (font->destroy != (hb_destroy_func_t) _hb_ft_font_destroy) + if (unlikely (font->destroy != (hb_destroy_func_t) _hb_ft_font_destroy)) return; hb_ft_font_t *ft_font = (hb_ft_font_t *) font->user_data; @@ -160,7 +160,7 @@ hb_ft_font_set_load_flags (hb_font_t *font, int load_flags) int hb_ft_font_get_load_flags (hb_font_t *font) { - if (font->destroy != (hb_destroy_func_t) _hb_ft_font_destroy) + if (unlikely (font->destroy != (hb_destroy_func_t) _hb_ft_font_destroy)) return 0; const hb_ft_font_t *ft_font = (const hb_ft_font_t *) font->user_data; @@ -168,10 +168,19 @@ hb_ft_font_get_load_flags (hb_font_t *font) return ft_font->load_flags; } +/** + * hb_ft_font_get_face: + * @font: + * + * + * + * Return value: + * Since: 0.9.2 + **/ FT_Face hb_ft_font_get_face (hb_font_t *font) { - if (font->destroy != (hb_destroy_func_t) _hb_ft_font_destroy) + if (unlikely (font->destroy != (hb_destroy_func_t) _hb_ft_font_destroy)) return nullptr; const hb_ft_font_t *ft_font = (const hb_ft_font_t *) font->user_data; @@ -179,6 +188,47 @@ hb_ft_font_get_face (hb_font_t *font) return ft_font->ft_face; } +/** + * hb_ft_font_lock_face: + * @font: + * + * + * + * Return value: + * Since: REPLACEME + **/ +FT_Face +hb_ft_font_lock_face (hb_font_t *font) +{ + if (unlikely (font->destroy != (hb_destroy_func_t) _hb_ft_font_destroy)) + return nullptr; + + const hb_ft_font_t *ft_font = (const hb_ft_font_t *) font->user_data; + + ft_font->lock.lock (); + + return ft_font->ft_face; +} + +/** + * hb_ft_font_unlock_face: + * @font: + * + * + * + * Return value: + * Since: REPLACEME + **/ +void +hb_ft_font_unlock_face (hb_font_t *font) +{ + if (unlikely (font->destroy != (hb_destroy_func_t) _hb_ft_font_destroy)) + return; + + const hb_ft_font_t *ft_font = (const hb_ft_font_t *) font->user_data; + + ft_font->lock.unlock (); +} static hb_bool_t diff --git a/src/hb-ft.h b/src/hb-ft.h index 94013eeb9..bf07115ab 100644 --- a/src/hb-ft.h +++ b/src/hb-ft.h @@ -110,6 +110,12 @@ hb_ft_font_create_referenced (FT_Face ft_face); HB_EXTERN FT_Face hb_ft_font_get_face (hb_font_t *font); +HB_EXTERN FT_Face +hb_ft_font_lock_face (hb_font_t *font); + +HB_EXTERN void +hb_ft_font_unlock_face (hb_font_t *font); + HB_EXTERN void hb_ft_font_set_load_flags (hb_font_t *font, int load_flags);