[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()
This commit is contained in:
Behdad Esfahbod 2019-11-22 16:22:27 -05:00
parent e5c7ee9f75
commit d5338ba189
3 changed files with 61 additions and 3 deletions

View File

@ -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

View File

@ -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

View File

@ -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);