[shape-plan] Turn hb_shape_plan_proposal_t into hb_shape_plan_key_t

And include it in hb_shape_plan_t itself.
This commit is contained in:
Behdad Esfahbod 2018-11-12 17:19:45 -05:00
parent af123bd1b8
commit 566612295b
2 changed files with 93 additions and 142 deletions

View File

@ -45,41 +45,26 @@
static void static void
hb_shape_plan_choose_shaper (hb_shape_plan_t *shape_plan, hb_shape_plan_key_choose_shaper (hb_shape_plan_key_t *key,
const hb_feature_t *user_features, hb_face_t *face,
unsigned int num_user_features, const hb_feature_t *user_features,
const int *coords, unsigned int num_user_features,
unsigned int num_coords, const int *coords,
const char * const *shaper_list) unsigned int num_coords,
const char * const *shaper_list)
{ {
DEBUG_MSG_FUNC (SHAPE_PLAN, shape_plan,
"num_features=%d num_coords=%d shaper_list=%p",
num_user_features,
num_coords,
shaper_list);
const hb_shaper_pair_static_t *shapers = _hb_shapers_get ();
#define HB_SHAPER_PLAN(shaper) \ #define HB_SHAPER_PLAN(shaper) \
HB_STMT_START { \ HB_STMT_START { \
if (hb_##shaper##_shaper_face_data_ensure (shape_plan->face_unsafe)) \ if (hb_##shaper##_shaper_face_data_ensure (face)) \
{ \ { \
shape_plan->shaper_func = _hb_##shaper##_shape; \ key->shaper_func = _hb_##shaper##_shape; \
shape_plan->shaper_name = #shaper; \ key->shaper_name = #shaper; \
return; \ return; \
} \ } \
} HB_STMT_END } HB_STMT_END
if (likely (!shaper_list)) { if (unlikely (shaper_list))
for (unsigned int i = 0; i < HB_SHAPERS_COUNT; i++) {
if (false)
;
#define HB_SHAPER_IMPLEMENT(shaper) \
else if (shapers[i].func == _hb_##shaper##_shape) \
HB_SHAPER_PLAN (shaper);
#include "hb-shaper-list.hh"
#undef HB_SHAPER_IMPLEMENT
} else {
for (; *shaper_list; shaper_list++) for (; *shaper_list; shaper_list++)
if (false) if (false)
; ;
@ -90,6 +75,16 @@ hb_shape_plan_choose_shaper (hb_shape_plan_t *shape_plan,
#undef HB_SHAPER_IMPLEMENT #undef HB_SHAPER_IMPLEMENT
} }
const hb_shaper_pair_static_t *shapers = _hb_shapers_get ();
for (unsigned int i = 0; i < HB_SHAPERS_COUNT; i++)
if (false)
;
#define HB_SHAPER_IMPLEMENT(shaper) \
else if (shapers[i].func == _hb_##shaper##_shape) \
HB_SHAPER_PLAN (shaper);
#include "hb-shaper-list.hh"
#undef HB_SHAPER_IMPLEMENT
#undef HB_SHAPER_PLAN #undef HB_SHAPER_PLAN
} }
@ -142,6 +137,8 @@ hb_shape_plan_create2 (hb_face_t *face,
num_coords, num_coords,
shaper_list); shaper_list);
assert (props->direction != HB_DIRECTION_INVALID);
hb_shape_plan_t *shape_plan; hb_shape_plan_t *shape_plan;
hb_feature_t *features = nullptr; hb_feature_t *features = nullptr;
int *coords = nullptr; int *coords = nullptr;
@ -152,30 +149,32 @@ hb_shape_plan_create2 (hb_face_t *face,
goto bail; goto bail;
if (num_coords && !(coords = (int *) calloc (num_coords, sizeof (int)))) if (num_coords && !(coords = (int *) calloc (num_coords, sizeof (int))))
goto bail; goto bail;
if (!(shape_plan = hb_object_create<hb_shape_plan_t> ())) if (!(shape_plan = hb_object_create<hb_shape_plan_t> ()))
goto bail; goto bail;
assert (props->direction != HB_DIRECTION_INVALID);
if (unlikely (!face)) if (unlikely (!face))
face = hb_face_get_empty (); face = hb_face_get_empty ();
hb_face_make_immutable (face); hb_face_make_immutable (face);
shape_plan->face_unsafe = face; shape_plan->face_unsafe = face;
shape_plan->props = *props;
shape_plan->num_user_features = num_user_features; {
shape_plan->user_features = features; hb_shape_plan_key_t *key = &shape_plan->key;
if (num_user_features) key->props = *props;
memcpy (features, user_features, num_user_features * sizeof (hb_feature_t)); key->num_user_features = num_user_features;
shape_plan->num_coords = num_coords; key->user_features = features;
shape_plan->coords = coords; if (num_user_features)
if (num_coords) memcpy (features, user_features, num_user_features * sizeof (hb_feature_t));
memcpy (coords, orig_coords, num_coords * sizeof (int)); key->num_coords = num_coords;
shape_plan->custom_shaper_list = shaper_list; key->coords = coords;
hb_shape_plan_choose_shaper (shape_plan, if (num_coords)
user_features, num_user_features, memcpy (coords, orig_coords, num_coords * sizeof (int));
coords, num_coords, hb_shape_plan_key_choose_shaper (key,
shaper_list); face,
user_features, num_user_features,
coords, num_coords,
shaper_list);
}
if (unlikely (!shape_plan->ot.init0 (face, if (unlikely (!shape_plan->ot.init0 (face,
props, props,
@ -239,8 +238,8 @@ hb_shape_plan_destroy (hb_shape_plan_t *shape_plan)
shape_plan->ot.fini (); shape_plan->ot.fini ();
free (shape_plan->user_features); free ((void *) shape_plan->key.user_features);
free (shape_plan->coords); free ((void *) shape_plan->key.coords);
free (shape_plan); free (shape_plan);
} }
@ -312,8 +311,8 @@ hb_shape_plan_execute (hb_shape_plan_t *shape_plan,
DEBUG_MSG_FUNC (SHAPE_PLAN, shape_plan, DEBUG_MSG_FUNC (SHAPE_PLAN, shape_plan,
"num_features=%d shaper_func=%p, shaper_name=%s", "num_features=%d shaper_func=%p, shaper_name=%s",
num_features, num_features,
shape_plan->shaper_func, shape_plan->key.shaper_func,
shape_plan->shaper_name); shape_plan->key.shaper_name);
if (unlikely (!buffer->len)) if (unlikely (!buffer->len))
return true; return true;
@ -325,7 +324,7 @@ hb_shape_plan_execute (hb_shape_plan_t *shape_plan,
return false; return false;
assert (shape_plan->face_unsafe == font->face); assert (shape_plan->face_unsafe == font->face);
assert (hb_segment_properties_equal (&shape_plan->props, &buffer->props)); assert (hb_segment_properties_equal (&shape_plan->key.props, &buffer->props));
#define HB_SHAPER_EXECUTE(shaper) \ #define HB_SHAPER_EXECUTE(shaper) \
HB_STMT_START { \ HB_STMT_START { \
@ -336,7 +335,7 @@ hb_shape_plan_execute (hb_shape_plan_t *shape_plan,
if (false) if (false)
; ;
#define HB_SHAPER_IMPLEMENT(shaper) \ #define HB_SHAPER_IMPLEMENT(shaper) \
else if (shape_plan->shaper_func == _hb_##shaper##_shape) \ else if (shape_plan->key.shaper_func == _hb_##shaper##_shape) \
HB_SHAPER_EXECUTE (shaper); HB_SHAPER_EXECUTE (shaper);
#include "hb-shaper-list.hh" #include "hb-shaper-list.hh"
#undef HB_SHAPER_IMPLEMENT #undef HB_SHAPER_IMPLEMENT
@ -351,67 +350,36 @@ hb_shape_plan_execute (hb_shape_plan_t *shape_plan,
* caching * caching
*/ */
#if 0 static inline bool
static unsigned int hb_shape_plan_key_user_features_equal (const hb_shape_plan_key_t *key1,
hb_shape_plan_hash (const hb_shape_plan_t *shape_plan) const hb_shape_plan_key_t *key2)
{ {
return hb_segment_properties_hash (&shape_plan->props) + if (key1->num_user_features != key2->num_user_features)
shape_plan->custom_shaper_list ? (intptr_t) shape_plan->shaper_func : 0;
}
#endif
/* User-feature caching is currently somewhat dumb:
* it only finds matches where the feature array is identical,
* not cases where the feature lists would be compatible for plan purposes
* but have different ranges, for example.
*/
struct hb_shape_plan_proposal_t
{
const hb_segment_properties_t props;
const hb_feature_t *user_features;
unsigned int num_user_features;
const int *coords;
unsigned int num_coords;
bool custom_shaper_list;
hb_shape_func_t *shaper_func;
};
static inline hb_bool_t
hb_shape_plan_user_features_match (const hb_shape_plan_t *shape_plan,
const hb_shape_plan_proposal_t *proposal)
{
if (proposal->num_user_features != shape_plan->num_user_features)
return false; return false;
for (unsigned int i = 0, n = proposal->num_user_features; i < n; i++) return 0 == hb_memcmp(key1->user_features,
if (proposal->user_features[i].tag != shape_plan->user_features[i].tag || key2->user_features,
proposal->user_features[i].value != shape_plan->user_features[i].value || key1->num_user_features * sizeof (key1->user_features[0]));
proposal->user_features[i].start != shape_plan->user_features[i].start ||
proposal->user_features[i].end != shape_plan->user_features[i].end)
return false;
return true;
} }
static inline hb_bool_t static inline bool
hb_shape_plan_coords_match (const hb_shape_plan_t *shape_plan, hb_shape_plan_key_coords_equal (const hb_shape_plan_key_t *key2,
const hb_shape_plan_proposal_t *proposal) const hb_shape_plan_key_t *key1)
{ {
if (proposal->num_coords != shape_plan->num_coords) if (key1->num_coords != key2->num_coords)
return false; return false;
for (unsigned int i = 0, n = proposal->num_coords; i < n; i++) return 0 == hb_memcmp(key1->coords,
if (proposal->coords[i] != shape_plan->coords[i]) key2->coords,
return false; key1->num_coords * sizeof (key1->coords[0]));
return true;
} }
static hb_bool_t static bool
hb_shape_plan_matches (const hb_shape_plan_t *shape_plan, hb_shape_plan_key_equal (const hb_shape_plan_key_t *key1,
const hb_shape_plan_proposal_t *proposal) const hb_shape_plan_key_t *key2)
{ {
return hb_segment_properties_equal (&shape_plan->props, &proposal->props) && return hb_segment_properties_equal (&key1->props, &key2->props) &&
hb_shape_plan_user_features_match (shape_plan, proposal) && hb_shape_plan_key_user_features_equal (key1, key2) &&
hb_shape_plan_coords_match (shape_plan, proposal) && hb_shape_plan_key_coords_equal (key1, key2) &&
((!shape_plan->custom_shaper_list && !proposal->custom_shaper_list) || key1->shaper_func == key2->shaper_func;
(shape_plan->shaper_func == proposal->shaper_func));
} }
static inline hb_bool_t static inline hb_bool_t
@ -476,38 +444,20 @@ hb_shape_plan_create_cached2 (hb_face_t *face,
num_user_features, num_user_features,
shaper_list); shaper_list);
hb_shape_plan_proposal_t proposal = hb_shape_plan_key_t key =
{ {
*props, *props,
user_features, user_features,
num_user_features, num_user_features,
coords, coords,
num_coords, num_coords,
shaper_list,
nullptr nullptr
}; };
hb_shape_plan_key_choose_shaper (&key,
if (shaper_list) face,
{ user_features, num_user_features,
/* Choose shaper. Adapted from hb_shape_plan_choose_shaper(). coords, num_coords,
* Must choose shaper exactly the same way as that function. */ shaper_list);
for (const char * const *shaper_item = shaper_list; *shaper_item; shaper_item++)
if (false)
;
#define HB_SHAPER_IMPLEMENT(shaper) \
else if (0 == strcmp (*shaper_item, #shaper) && \
hb_##shaper##_shaper_face_data_ensure (face)) \
{ \
proposal.shaper_func = _hb_##shaper##_shape; \
break; \
}
#include "hb-shaper-list.hh"
#undef HB_SHAPER_IMPLEMENT
if (unlikely (!proposal.shaper_func))
return hb_shape_plan_get_empty ();
}
retry: retry:
hb_face_t::plan_node_t *cached_plan_nodes = face->shape_plans; hb_face_t::plan_node_t *cached_plan_nodes = face->shape_plans;
@ -515,7 +465,7 @@ retry:
/* Don't look for plan in the cache if there were variation coordinates XXX Fix me. */ /* Don't look for plan in the cache if there were variation coordinates XXX Fix me. */
if (!hb_coords_present (coords, num_coords)) if (!hb_coords_present (coords, num_coords))
for (hb_face_t::plan_node_t *node = cached_plan_nodes; node; node = node->next) for (hb_face_t::plan_node_t *node = cached_plan_nodes; node; node = node->next)
if (hb_shape_plan_matches (node->shape_plan, &proposal)) if (hb_shape_plan_key_equal (&node->shape_plan->key, &key))
{ {
DEBUG_MSG_FUNC (SHAPE_PLAN, node->shape_plan, "fulfilled from cache"); DEBUG_MSG_FUNC (SHAPE_PLAN, node->shape_plan, "fulfilled from cache");
return hb_shape_plan_reference (node->shape_plan); return hb_shape_plan_reference (node->shape_plan);
@ -569,5 +519,5 @@ retry:
const char * const char *
hb_shape_plan_get_shaper (hb_shape_plan_t *shape_plan) hb_shape_plan_get_shaper (hb_shape_plan_t *shape_plan)
{ {
return shape_plan->shaper_name; return shape_plan->key.shaper_name;
} }

View File

@ -32,24 +32,25 @@
#include "hb-ot-shape.hh" #include "hb-ot-shape.hh"
struct hb_shape_plan_key_t
{
hb_segment_properties_t props;
const hb_feature_t *user_features;
unsigned int num_user_features;
const int *coords;
unsigned int num_coords;
hb_shape_func_t *shaper_func;
const char *shaper_name;
};
struct hb_shape_plan_t struct hb_shape_plan_t
{ {
hb_object_header_t header; hb_object_header_t header;
hb_face_t *face_unsafe; /* We don't carry a reference to face. */ hb_face_t *face_unsafe; /* We don't carry a reference to face. */
hb_shape_plan_key_t key;
hb_segment_properties_t props;
hb_feature_t *user_features;
unsigned int num_user_features;
int *coords;
unsigned int num_coords;
bool custom_shaper_list;
hb_shape_func_t *shaper_func;
const char *shaper_name;
hb_ot_shape_plan_t ot; hb_ot_shape_plan_t ot;
}; };