Blame src/hb-shape-plan.cc

Packit 874993
/*
Packit 874993
 * Copyright © 2012  Google, Inc.
Packit 874993
 *
Packit 874993
 *  This is part of HarfBuzz, a text shaping library.
Packit 874993
 *
Packit 874993
 * Permission is hereby granted, without written agreement and without
Packit 874993
 * license or royalty fees, to use, copy, modify, and distribute this
Packit 874993
 * software and its documentation for any purpose, provided that the
Packit 874993
 * above copyright notice and the following two paragraphs appear in
Packit 874993
 * all copies of this software.
Packit 874993
 *
Packit 874993
 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
Packit 874993
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
Packit 874993
 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
Packit 874993
 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
Packit 874993
 * DAMAGE.
Packit 874993
 *
Packit 874993
 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
Packit 874993
 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
Packit 874993
 * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
Packit 874993
 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
Packit 874993
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
Packit 874993
 *
Packit 874993
 * Google Author(s): Behdad Esfahbod
Packit 874993
 */
Packit 874993
Packit 874993
#include "hb-shape-plan-private.hh"
Packit 874993
#include "hb-shaper-private.hh"
Packit 874993
#include "hb-font-private.hh"
Packit 874993
#include "hb-buffer-private.hh"
Packit 874993
Packit 874993
Packit 874993
#ifndef HB_DEBUG_SHAPE_PLAN
Packit 874993
#define HB_DEBUG_SHAPE_PLAN (HB_DEBUG+0)
Packit 874993
#endif
Packit 874993
Packit 874993
Packit 874993
static void
Packit 874993
hb_shape_plan_plan (hb_shape_plan_t    *shape_plan,
Packit 874993
		    const hb_feature_t *user_features,
Packit 874993
		    unsigned int        num_user_features,
Packit 874993
		    const int          *coords,
Packit 874993
		    unsigned int        num_coords,
Packit 874993
		    const char * const *shaper_list)
Packit 874993
{
Packit 874993
  DEBUG_MSG_FUNC (SHAPE_PLAN, shape_plan,
Packit 874993
		  "num_features=%d num_coords=%d shaper_list=%p",
Packit 874993
		  num_user_features,
Packit 874993
		  num_coords,
Packit 874993
		  shaper_list);
Packit 874993
Packit 874993
  const hb_shaper_pair_t *shapers = _hb_shapers_get ();
Packit 874993
Packit 874993
#define HB_SHAPER_PLAN(shaper) \
Packit 874993
	HB_STMT_START { \
Packit 874993
	  if (hb_##shaper##_shaper_face_data_ensure (shape_plan->face_unsafe)) { \
Packit 874993
	    HB_SHAPER_DATA (shaper, shape_plan) = \
Packit 874993
	      HB_SHAPER_DATA_CREATE_FUNC (shaper, shape_plan) (shape_plan, \
Packit 874993
							       user_features, num_user_features, \
Packit 874993
							       coords, num_coords); \
Packit 874993
	    shape_plan->shaper_func = _hb_##shaper##_shape; \
Packit 874993
	    shape_plan->shaper_name = #shaper; \
Packit 874993
	    return; \
Packit 874993
	  } \
Packit 874993
	} HB_STMT_END
Packit 874993
Packit 874993
  if (likely (!shaper_list)) {
Packit 874993
    for (unsigned int i = 0; i < HB_SHAPERS_COUNT; i++)
Packit 874993
      if (0)
Packit 874993
	;
Packit 874993
#define HB_SHAPER_IMPLEMENT(shaper) \
Packit 874993
      else if (shapers[i].func == _hb_##shaper##_shape) \
Packit 874993
	HB_SHAPER_PLAN (shaper);
Packit 874993
#include "hb-shaper-list.hh"
Packit 874993
#undef HB_SHAPER_IMPLEMENT
Packit 874993
  } else {
Packit 874993
    for (; *shaper_list; shaper_list++)
Packit 874993
      if (0)
Packit 874993
	;
Packit 874993
#define HB_SHAPER_IMPLEMENT(shaper) \
Packit 874993
      else if (0 == strcmp (*shaper_list, #shaper)) \
Packit 874993
	HB_SHAPER_PLAN (shaper);
Packit 874993
#include "hb-shaper-list.hh"
Packit 874993
#undef HB_SHAPER_IMPLEMENT
Packit 874993
  }
Packit 874993
Packit 874993
#undef HB_SHAPER_PLAN
Packit 874993
}
Packit 874993
Packit 874993
Packit 874993
/*
Packit 874993
 * hb_shape_plan_t
Packit 874993
 */
Packit 874993
Packit 874993
/**
Packit 874993
 * hb_shape_plan_create: (Xconstructor)
Packit 874993
 * @face: 
Packit 874993
 * @props: 
Packit 874993
 * @user_features: (array length=num_user_features):
Packit 874993
 * @num_user_features: 
Packit 874993
 * @shaper_list: (array zero-terminated=1):
Packit 874993
 *
Packit 874993
 * 
Packit 874993
 *
Packit 874993
 * Return value: (transfer full):
Packit 874993
 *
Packit 874993
 * Since: 0.9.7
Packit 874993
 **/
Packit 874993
hb_shape_plan_t *
Packit 874993
hb_shape_plan_create (hb_face_t                     *face,
Packit 874993
		      const hb_segment_properties_t *props,
Packit 874993
		      const hb_feature_t            *user_features,
Packit 874993
		      unsigned int                   num_user_features,
Packit 874993
		      const char * const            *shaper_list)
Packit 874993
{
Packit 874993
  return hb_shape_plan_create2 (face, props,
Packit 874993
				user_features, num_user_features,
Packit 874993
				NULL, 0,
Packit 874993
				shaper_list);
Packit 874993
}
Packit 874993
Packit 874993
hb_shape_plan_t *
Packit 874993
hb_shape_plan_create2 (hb_face_t                     *face,
Packit 874993
		       const hb_segment_properties_t *props,
Packit 874993
		       const hb_feature_t            *user_features,
Packit 874993
		       unsigned int                   num_user_features,
Packit 874993
		       const int                     *orig_coords,
Packit 874993
		       unsigned int                   num_coords,
Packit 874993
		       const char * const            *shaper_list)
Packit 874993
{
Packit 874993
  DEBUG_MSG_FUNC (SHAPE_PLAN, NULL,
Packit 874993
		  "face=%p num_features=%d num_coords=%d shaper_list=%p",
Packit 874993
		  face,
Packit 874993
		  num_user_features,
Packit 874993
		  num_coords,
Packit 874993
		  shaper_list);
Packit 874993
Packit 874993
  hb_shape_plan_t *shape_plan;
Packit 874993
  hb_feature_t *features = NULL;
Packit 874993
  int *coords = NULL;
Packit 874993
Packit 874993
  if (unlikely (!face))
Packit 874993
    face = hb_face_get_empty ();
Packit 874993
  if (unlikely (!props))
Packit 874993
    return hb_shape_plan_get_empty ();
Packit 874993
  if (num_user_features && !(features = (hb_feature_t *) calloc (num_user_features, sizeof (hb_feature_t))))
Packit 874993
    return hb_shape_plan_get_empty ();
Packit 874993
  if (num_coords && !(coords = (int *) calloc (num_coords, sizeof (int))))
Packit 874993
  {
Packit 874993
    free (features);
Packit 874993
    return hb_shape_plan_get_empty ();
Packit 874993
  }
Packit 874993
  if (!(shape_plan = hb_object_create<hb_shape_plan_t> ()))
Packit 874993
  {
Packit 874993
    free (coords);
Packit 874993
    free (features);
Packit 874993
    return hb_shape_plan_get_empty ();
Packit 874993
  }
Packit 874993
Packit 874993
  assert (props->direction != HB_DIRECTION_INVALID);
Packit 874993
Packit 874993
  hb_face_make_immutable (face);
Packit 874993
  shape_plan->default_shaper_list = shaper_list == NULL;
Packit 874993
  shape_plan->face_unsafe = face;
Packit 874993
  shape_plan->props = *props;
Packit 874993
  shape_plan->num_user_features = num_user_features;
Packit 874993
  shape_plan->user_features = features;
Packit 874993
  if (num_user_features)
Packit 874993
    memcpy (features, user_features, num_user_features * sizeof (hb_feature_t));
Packit 874993
  shape_plan->num_coords = num_coords;
Packit 874993
  shape_plan->coords = coords;
Packit 874993
  if (num_coords)
Packit 874993
    memcpy (coords, orig_coords, num_coords * sizeof (int));
Packit 874993
Packit 874993
  hb_shape_plan_plan (shape_plan,
Packit 874993
		      user_features, num_user_features,
Packit 874993
		      coords, num_coords,
Packit 874993
		      shaper_list);
Packit 874993
Packit 874993
  return shape_plan;
Packit 874993
}
Packit 874993
Packit 874993
/**
Packit 874993
 * hb_shape_plan_get_empty:
Packit 874993
 *
Packit 874993
 * 
Packit 874993
 *
Packit 874993
 * Return value: (transfer full):
Packit 874993
 *
Packit 874993
 * Since: 0.9.7
Packit 874993
 **/
Packit 874993
hb_shape_plan_t *
Packit 874993
hb_shape_plan_get_empty (void)
Packit 874993
{
Packit 874993
  static const hb_shape_plan_t _hb_shape_plan_nil = {
Packit 874993
    HB_OBJECT_HEADER_STATIC,
Packit 874993
Packit 874993
    true, /* default_shaper_list */
Packit 874993
    NULL, /* face */
Packit 874993
    HB_SEGMENT_PROPERTIES_DEFAULT, /* props */
Packit 874993
Packit 874993
    NULL, /* shaper_func */
Packit 874993
    NULL, /* shaper_name */
Packit 874993
Packit 874993
    NULL, /* user_features */
Packit 874993
    0,    /* num_user_featurs */
Packit 874993
Packit 874993
    NULL, /* coords */
Packit 874993
    0,    /* num_coords */
Packit 874993
Packit 874993
    {
Packit 874993
#define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_INVALID,
Packit 874993
#include "hb-shaper-list.hh"
Packit 874993
#undef HB_SHAPER_IMPLEMENT
Packit 874993
    }
Packit 874993
  };
Packit 874993
Packit 874993
  return const_cast<hb_shape_plan_t *> (&_hb_shape_plan_nil);
Packit 874993
}
Packit 874993
Packit 874993
/**
Packit 874993
 * hb_shape_plan_reference: (skip)
Packit 874993
 * @shape_plan: a shape plan.
Packit 874993
 *
Packit 874993
 * 
Packit 874993
 *
Packit 874993
 * Return value: (transfer full):
Packit 874993
 *
Packit 874993
 * Since: 0.9.7
Packit 874993
 **/
Packit 874993
hb_shape_plan_t *
Packit 874993
hb_shape_plan_reference (hb_shape_plan_t *shape_plan)
Packit 874993
{
Packit 874993
  return hb_object_reference (shape_plan);
Packit 874993
}
Packit 874993
Packit 874993
/**
Packit 874993
 * hb_shape_plan_destroy: (skip)
Packit 874993
 * @shape_plan: a shape plan.
Packit 874993
 *
Packit 874993
 * 
Packit 874993
 *
Packit 874993
 * Since: 0.9.7
Packit 874993
 **/
Packit 874993
void
Packit 874993
hb_shape_plan_destroy (hb_shape_plan_t *shape_plan)
Packit 874993
{
Packit 874993
  if (!hb_object_destroy (shape_plan)) return;
Packit 874993
Packit 874993
#define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_DESTROY(shaper, shape_plan);
Packit 874993
#include "hb-shaper-list.hh"
Packit 874993
#undef HB_SHAPER_IMPLEMENT
Packit 874993
Packit 874993
  free (shape_plan->user_features);
Packit 874993
  free (shape_plan->coords);
Packit 874993
Packit 874993
  free (shape_plan);
Packit 874993
}
Packit 874993
Packit 874993
/**
Packit 874993
 * hb_shape_plan_set_user_data: (skip)
Packit 874993
 * @shape_plan: a shape plan.
Packit 874993
 * @key: 
Packit 874993
 * @data: 
Packit 874993
 * @destroy: 
Packit 874993
 * @replace: 
Packit 874993
 *
Packit 874993
 * 
Packit 874993
 *
Packit 874993
 * Return value: 
Packit 874993
 *
Packit 874993
 * Since: 0.9.7
Packit 874993
 **/
Packit 874993
hb_bool_t
Packit 874993
hb_shape_plan_set_user_data (hb_shape_plan_t    *shape_plan,
Packit 874993
			     hb_user_data_key_t *key,
Packit 874993
			     void *              data,
Packit 874993
			     hb_destroy_func_t   destroy,
Packit 874993
			     hb_bool_t           replace)
Packit 874993
{
Packit 874993
  return hb_object_set_user_data (shape_plan, key, data, destroy, replace);
Packit 874993
}
Packit 874993
Packit 874993
/**
Packit 874993
 * hb_shape_plan_get_user_data: (skip)
Packit 874993
 * @shape_plan: a shape plan.
Packit 874993
 * @key: 
Packit 874993
 *
Packit 874993
 * 
Packit 874993
 *
Packit 874993
 * Return value: (transfer none):
Packit 874993
 *
Packit 874993
 * Since: 0.9.7
Packit 874993
 **/
Packit 874993
void *
Packit 874993
hb_shape_plan_get_user_data (hb_shape_plan_t    *shape_plan,
Packit 874993
			     hb_user_data_key_t *key)
Packit 874993
{
Packit 874993
  return hb_object_get_user_data (shape_plan, key);
Packit 874993
}
Packit 874993
Packit 874993
Packit 874993
/**
Packit 874993
 * hb_shape_plan_execute:
Packit 874993
 * @shape_plan: a shape plan.
Packit 874993
 * @font: a font.
Packit 874993
 * @buffer: a buffer.
Packit 874993
 * @features: (array length=num_features):
Packit 874993
 * @num_features: 
Packit 874993
 *
Packit 874993
 * 
Packit 874993
 *
Packit 874993
 * Return value: 
Packit 874993
 *
Packit 874993
 * Since: 0.9.7
Packit 874993
 **/
Packit 874993
hb_bool_t
Packit 874993
hb_shape_plan_execute (hb_shape_plan_t    *shape_plan,
Packit 874993
		       hb_font_t          *font,
Packit 874993
		       hb_buffer_t        *buffer,
Packit 874993
		       const hb_feature_t *features,
Packit 874993
		       unsigned int        num_features)
Packit 874993
{
Packit 874993
  DEBUG_MSG_FUNC (SHAPE_PLAN, shape_plan,
Packit 874993
		  "num_features=%d shaper_func=%p, shaper_name=%s",
Packit 874993
		  num_features,
Packit 874993
		  shape_plan->shaper_func,
Packit 874993
		  shape_plan->shaper_name);
Packit 874993
Packit 874993
  if (unlikely (!buffer->len))
Packit 874993
    return true;
Packit 874993
Packit 874993
  assert (!hb_object_is_inert (buffer));
Packit 874993
  assert (buffer->content_type == HB_BUFFER_CONTENT_TYPE_UNICODE);
Packit 874993
Packit 874993
  if (unlikely (hb_object_is_inert (shape_plan)))
Packit 874993
    return false;
Packit 874993
Packit 874993
  assert (shape_plan->face_unsafe == font->face);
Packit 874993
  assert (hb_segment_properties_equal (&shape_plan->props, &buffer->props));
Packit 874993
Packit 874993
#define HB_SHAPER_EXECUTE(shaper) \
Packit 874993
	HB_STMT_START { \
Packit 874993
	  return HB_SHAPER_DATA (shaper, shape_plan) && \
Packit 874993
		 hb_##shaper##_shaper_font_data_ensure (font) && \
Packit 874993
		 _hb_##shaper##_shape (shape_plan, font, buffer, features, num_features); \
Packit 874993
	} HB_STMT_END
Packit 874993
Packit 874993
  if (0)
Packit 874993
    ;
Packit 874993
#define HB_SHAPER_IMPLEMENT(shaper) \
Packit 874993
  else if (shape_plan->shaper_func == _hb_##shaper##_shape) \
Packit 874993
    HB_SHAPER_EXECUTE (shaper);
Packit 874993
#include "hb-shaper-list.hh"
Packit 874993
#undef HB_SHAPER_IMPLEMENT
Packit 874993
Packit 874993
#undef HB_SHAPER_EXECUTE
Packit 874993
Packit 874993
  return false;
Packit 874993
}
Packit 874993
Packit 874993
Packit 874993
/*
Packit 874993
 * caching
Packit 874993
 */
Packit 874993
Packit 874993
#if 0
Packit 874993
static unsigned int
Packit 874993
hb_shape_plan_hash (const hb_shape_plan_t *shape_plan)
Packit 874993
{
Packit 874993
  return hb_segment_properties_hash (&shape_plan->props) +
Packit 874993
	 shape_plan->default_shaper_list ? 0 : (intptr_t) shape_plan->shaper_func;
Packit 874993
}
Packit 874993
#endif
Packit 874993
Packit 874993
/* User-feature caching is currently somewhat dumb:
Packit 874993
 * it only finds matches where the feature array is identical,
Packit 874993
 * not cases where the feature lists would be compatible for plan purposes
Packit 874993
 * but have different ranges, for example.
Packit 874993
 */
Packit 874993
struct hb_shape_plan_proposal_t
Packit 874993
{
Packit 874993
  const hb_segment_properties_t  props;
Packit 874993
  const char * const            *shaper_list;
Packit 874993
  const hb_feature_t            *user_features;
Packit 874993
  unsigned int                   num_user_features;
Packit 874993
  const int                     *coords;
Packit 874993
  unsigned int                   num_coords;
Packit 874993
  hb_shape_func_t               *shaper_func;
Packit 874993
};
Packit 874993
Packit 874993
static inline hb_bool_t
Packit 874993
hb_shape_plan_user_features_match (const hb_shape_plan_t          *shape_plan,
Packit 874993
				   const hb_shape_plan_proposal_t *proposal)
Packit 874993
{
Packit 874993
  if (proposal->num_user_features != shape_plan->num_user_features)
Packit 874993
    return false;
Packit 874993
  for (unsigned int i = 0, n = proposal->num_user_features; i < n; i++)
Packit 874993
    if (proposal->user_features[i].tag   != shape_plan->user_features[i].tag   ||
Packit 874993
        proposal->user_features[i].value != shape_plan->user_features[i].value ||
Packit 874993
        proposal->user_features[i].start != shape_plan->user_features[i].start ||
Packit 874993
        proposal->user_features[i].end   != shape_plan->user_features[i].end)
Packit 874993
      return false;
Packit 874993
  return true;
Packit 874993
}
Packit 874993
Packit 874993
static inline hb_bool_t
Packit 874993
hb_shape_plan_coords_match (const hb_shape_plan_t          *shape_plan,
Packit 874993
			    const hb_shape_plan_proposal_t *proposal)
Packit 874993
{
Packit 874993
  if (proposal->num_coords != shape_plan->num_coords)
Packit 874993
    return false;
Packit 874993
  for (unsigned int i = 0, n = proposal->num_coords; i < n; i++)
Packit 874993
    if (proposal->coords[i] != shape_plan->coords[i])
Packit 874993
      return false;
Packit 874993
  return true;
Packit 874993
}
Packit 874993
Packit 874993
static hb_bool_t
Packit 874993
hb_shape_plan_matches (const hb_shape_plan_t          *shape_plan,
Packit 874993
		       const hb_shape_plan_proposal_t *proposal)
Packit 874993
{
Packit 874993
  return hb_segment_properties_equal (&shape_plan->props, &proposal->props) &&
Packit 874993
	 hb_shape_plan_user_features_match (shape_plan, proposal) &&
Packit 874993
	 hb_shape_plan_coords_match (shape_plan, proposal) &&
Packit 874993
	 ((shape_plan->default_shaper_list && proposal->shaper_list == NULL) ||
Packit 874993
	  (shape_plan->shaper_func == proposal->shaper_func));
Packit 874993
}
Packit 874993
Packit 874993
static inline hb_bool_t
Packit 874993
hb_non_global_user_features_present (const hb_feature_t *user_features,
Packit 874993
				     unsigned int        num_user_features)
Packit 874993
{
Packit 874993
  while (num_user_features) {
Packit 874993
    if (user_features->start != 0 || user_features->end != (unsigned int) -1)
Packit 874993
      return true;
Packit 874993
    num_user_features--;
Packit 874993
    user_features++;
Packit 874993
  }
Packit 874993
  return false;
Packit 874993
}
Packit 874993
Packit 874993
static inline hb_bool_t
Packit 874993
hb_coords_present (const int *coords,
Packit 874993
		   unsigned int num_coords)
Packit 874993
{
Packit 874993
  return num_coords != 0;
Packit 874993
}
Packit 874993
Packit 874993
/**
Packit 874993
 * hb_shape_plan_create_cached:
Packit 874993
 * @face: 
Packit 874993
 * @props: 
Packit 874993
 * @user_features: (array length=num_user_features):
Packit 874993
 * @num_user_features: 
Packit 874993
 * @shaper_list: (array zero-terminated=1):
Packit 874993
 *
Packit 874993
 * 
Packit 874993
 *
Packit 874993
 * Return value: (transfer full):
Packit 874993
 *
Packit 874993
 * Since: 0.9.7
Packit 874993
 **/
Packit 874993
hb_shape_plan_t *
Packit 874993
hb_shape_plan_create_cached (hb_face_t                     *face,
Packit 874993
			     const hb_segment_properties_t *props,
Packit 874993
			     const hb_feature_t            *user_features,
Packit 874993
			     unsigned int                   num_user_features,
Packit 874993
			     const char * const            *shaper_list)
Packit 874993
{
Packit 874993
  return hb_shape_plan_create_cached2 (face, props,
Packit 874993
				       user_features, num_user_features,
Packit 874993
				       NULL, 0,
Packit 874993
				       shaper_list);
Packit 874993
}
Packit 874993
Packit 874993
hb_shape_plan_t *
Packit 874993
hb_shape_plan_create_cached2 (hb_face_t                     *face,
Packit 874993
			      const hb_segment_properties_t *props,
Packit 874993
			      const hb_feature_t            *user_features,
Packit 874993
			      unsigned int                   num_user_features,
Packit 874993
			      const int                     *coords,
Packit 874993
			      unsigned int                   num_coords,
Packit 874993
			      const char * const            *shaper_list)
Packit 874993
{
Packit 874993
  DEBUG_MSG_FUNC (SHAPE_PLAN, NULL,
Packit 874993
		  "face=%p num_features=%d shaper_list=%p",
Packit 874993
		  face,
Packit 874993
		  num_user_features,
Packit 874993
		  shaper_list);
Packit 874993
Packit 874993
  hb_shape_plan_proposal_t proposal = {
Packit 874993
    *props,
Packit 874993
    shaper_list,
Packit 874993
    user_features,
Packit 874993
    num_user_features,
Packit 874993
    NULL
Packit 874993
  };
Packit 874993
Packit 874993
  if (shaper_list) {
Packit 874993
    /* Choose shaper.  Adapted from hb_shape_plan_plan().
Packit 874993
     * Must choose shaper exactly the same way as that function. */
Packit 874993
    for (const char * const *shaper_item = shaper_list; *shaper_item; shaper_item++)
Packit 874993
      if (0)
Packit 874993
	;
Packit 874993
#define HB_SHAPER_IMPLEMENT(shaper) \
Packit 874993
      else if (0 == strcmp (*shaper_item, #shaper) && \
Packit 874993
	       hb_##shaper##_shaper_face_data_ensure (face)) \
Packit 874993
      { \
Packit 874993
	proposal.shaper_func = _hb_##shaper##_shape; \
Packit 874993
	break; \
Packit 874993
      }
Packit 874993
#include "hb-shaper-list.hh"
Packit 874993
#undef HB_SHAPER_IMPLEMENT
Packit 874993
Packit 874993
    if (unlikely (!proposal.shaper_func))
Packit 874993
      return hb_shape_plan_get_empty ();
Packit 874993
  }
Packit 874993
Packit 874993
Packit 874993
retry:
Packit 874993
  hb_face_t::plan_node_t *cached_plan_nodes = (hb_face_t::plan_node_t *) hb_atomic_ptr_get (&face->shape_plans);
Packit 874993
  for (hb_face_t::plan_node_t *node = cached_plan_nodes; node; node = node->next)
Packit 874993
    if (hb_shape_plan_matches (node->shape_plan, &proposal))
Packit 874993
    {
Packit 874993
      DEBUG_MSG_FUNC (SHAPE_PLAN, node->shape_plan, "fulfilled from cache");
Packit 874993
      return hb_shape_plan_reference (node->shape_plan);
Packit 874993
    }
Packit 874993
Packit 874993
  /* Not found. */
Packit 874993
Packit 874993
  hb_shape_plan_t *shape_plan = hb_shape_plan_create2 (face, props,
Packit 874993
						       user_features, num_user_features,
Packit 874993
						       coords, num_coords,
Packit 874993
						       shaper_list);
Packit 874993
Packit 874993
  /* Don't add to the cache if face is inert. */
Packit 874993
  if (unlikely (hb_object_is_inert (face)))
Packit 874993
    return shape_plan;
Packit 874993
Packit 874993
  /* Don't add the plan to the cache if there were user features with non-global ranges */
Packit 874993
  if (hb_non_global_user_features_present (user_features, num_user_features))
Packit 874993
    return shape_plan;
Packit 874993
  /* Don't add the plan to the cache if there were variation coordinates XXX Fix me. */
Packit 874993
  if (hb_coords_present (coords, num_coords))
Packit 874993
    return shape_plan;
Packit 874993
Packit 874993
  hb_face_t::plan_node_t *node = (hb_face_t::plan_node_t *) calloc (1, sizeof (hb_face_t::plan_node_t));
Packit 874993
  if (unlikely (!node))
Packit 874993
    return shape_plan;
Packit 874993
Packit 874993
  node->shape_plan = shape_plan;
Packit 874993
  node->next = cached_plan_nodes;
Packit 874993
Packit 874993
  if (!hb_atomic_ptr_cmpexch (&face->shape_plans, cached_plan_nodes, node)) {
Packit 874993
    hb_shape_plan_destroy (shape_plan);
Packit 874993
    free (node);
Packit 874993
    goto retry;
Packit 874993
  }
Packit 874993
  DEBUG_MSG_FUNC (SHAPE_PLAN, shape_plan, "inserted into cache");
Packit 874993
Packit 874993
  return hb_shape_plan_reference (shape_plan);
Packit 874993
}
Packit 874993
Packit 874993
/**
Packit 874993
 * hb_shape_plan_get_shaper:
Packit 874993
 * @shape_plan: a shape plan.
Packit 874993
 *
Packit 874993
 * 
Packit 874993
 *
Packit 874993
 * Return value: (transfer none):
Packit 874993
 *
Packit 874993
 * Since: 0.9.7
Packit 874993
 **/
Packit 874993
const char *
Packit 874993
hb_shape_plan_get_shaper (hb_shape_plan_t *shape_plan)
Packit 874993
{
Packit 874993
  return shape_plan->shaper_name;
Packit 874993
}