src/java.desktop/share/native/libfontmanager/harfbuzz/hb-blob.cc
changeset 48274 51772bf1fb0c
parent 47216 71c04702a3d5
child 50352 25db2c8f3cf8
equal deleted inserted replaced
48273:e2065f7505eb 48274:51772bf1fb0c
    28 #ifndef _POSIX_C_SOURCE
    28 #ifndef _POSIX_C_SOURCE
    29 #define _POSIX_C_SOURCE 199309L
    29 #define _POSIX_C_SOURCE 199309L
    30 #endif
    30 #endif
    31 
    31 
    32 #include "hb-private.hh"
    32 #include "hb-private.hh"
       
    33 #include "hb-debug.hh"
    33 
    34 
    34 #include "hb-object-private.hh"
    35 #include "hb-object-private.hh"
    35 
    36 
    36 #ifdef HAVE_SYS_MMAN_H
    37 #ifdef HAVE_SYS_MMAN_H
    37 #ifdef HAVE_UNISTD_H
    38 #ifdef HAVE_UNISTD_H
    42 
    43 
    43 #include <stdio.h>
    44 #include <stdio.h>
    44 #include <errno.h>
    45 #include <errno.h>
    45 
    46 
    46 
    47 
    47 
       
    48 #ifndef HB_DEBUG_BLOB
       
    49 #define HB_DEBUG_BLOB (HB_DEBUG+0)
       
    50 #endif
       
    51 
       
    52 
       
    53 struct hb_blob_t {
    48 struct hb_blob_t {
    54   hb_object_header_t header;
    49   hb_object_header_t header;
    55   ASSERT_POD ();
    50   ASSERT_POD ();
    56 
    51 
    57   bool immutable;
    52   bool immutable;
    70 static void
    65 static void
    71 _hb_blob_destroy_user_data (hb_blob_t *blob)
    66 _hb_blob_destroy_user_data (hb_blob_t *blob)
    72 {
    67 {
    73   if (blob->destroy) {
    68   if (blob->destroy) {
    74     blob->destroy (blob->user_data);
    69     blob->destroy (blob->user_data);
    75     blob->user_data = NULL;
    70     blob->user_data = nullptr;
    76     blob->destroy = NULL;
    71     blob->destroy = nullptr;
    77   }
    72   }
    78 }
    73 }
    79 
    74 
    80 /**
    75 /**
    81  * hb_blob_create: (skip)
    76  * hb_blob_create: (skip)
   126   }
   121   }
   127 
   122 
   128   return blob;
   123   return blob;
   129 }
   124 }
   130 
   125 
       
   126 static void
       
   127 _hb_blob_destroy (void *data)
       
   128 {
       
   129   hb_blob_destroy ((hb_blob_t *) data);
       
   130 }
       
   131 
   131 /**
   132 /**
   132  * hb_blob_create_sub_blob:
   133  * hb_blob_create_sub_blob:
   133  * @parent: Parent blob.
   134  * @parent: Parent blob.
   134  * @offset: Start offset of sub-blob within @parent, in bytes.
   135  * @offset: Start offset of sub-blob within @parent, in bytes.
   135  * @length: Length of sub-blob.
   136  * @length: Length of sub-blob.
   162 
   163 
   163   blob = hb_blob_create (parent->data + offset,
   164   blob = hb_blob_create (parent->data + offset,
   164                          MIN (length, parent->length - offset),
   165                          MIN (length, parent->length - offset),
   165                          HB_MEMORY_MODE_READONLY,
   166                          HB_MEMORY_MODE_READONLY,
   166                          hb_blob_reference (parent),
   167                          hb_blob_reference (parent),
   167                          (hb_destroy_func_t) hb_blob_destroy);
   168                          _hb_blob_destroy);
   168 
   169 
   169   return blob;
   170   return blob;
   170 }
   171 }
   171 
   172 
   172 /**
   173 /**
   186   static const hb_blob_t _hb_blob_nil = {
   187   static const hb_blob_t _hb_blob_nil = {
   187     HB_OBJECT_HEADER_STATIC,
   188     HB_OBJECT_HEADER_STATIC,
   188 
   189 
   189     true, /* immutable */
   190     true, /* immutable */
   190 
   191 
   191     NULL, /* data */
   192     nullptr, /* data */
   192     0, /* length */
   193     0, /* length */
   193     HB_MEMORY_MODE_READONLY, /* mode */
   194     HB_MEMORY_MODE_READONLY, /* mode */
   194 
   195 
   195     NULL, /* user_data */
   196     nullptr, /* user_data */
   196     NULL  /* destroy */
   197     nullptr  /* destroy */
   197   };
   198   };
   198 
   199 
   199   return const_cast<hb_blob_t *> (&_hb_blob_nil);
   200   return const_cast<hb_blob_t *> (&_hb_blob_nil);
   200 }
   201 }
   201 
   202 
   245  * @key: key for data to set.
   246  * @key: key for data to set.
   246  * @data: data to set.
   247  * @data: data to set.
   247  * @destroy: callback to call when @data is not needed anymore.
   248  * @destroy: callback to call when @data is not needed anymore.
   248  * @replace: whether to replace an existing data with the same key.
   249  * @replace: whether to replace an existing data with the same key.
   249  *
   250  *
   250  * Return value: 
   251  * Return value:
   251  *
   252  *
   252  * Since: 0.9.2
   253  * Since: 0.9.2
   253  **/
   254  **/
   254 hb_bool_t
   255 hb_bool_t
   255 hb_blob_set_user_data (hb_blob_t          *blob,
   256 hb_blob_set_user_data (hb_blob_t          *blob,
   264 /**
   265 /**
   265  * hb_blob_get_user_data: (skip)
   266  * hb_blob_get_user_data: (skip)
   266  * @blob: a blob.
   267  * @blob: a blob.
   267  * @key: key for data to get.
   268  * @key: key for data to get.
   268  *
   269  *
   269  * 
   270  *
   270  *
   271  *
   271  * Return value: (transfer none): 
   272  * Return value: (transfer none):
   272  *
   273  *
   273  * Since: 0.9.2
   274  * Since: 0.9.2
   274  **/
   275  **/
   275 void *
   276 void *
   276 hb_blob_get_user_data (hb_blob_t          *blob,
   277 hb_blob_get_user_data (hb_blob_t          *blob,
   282 
   283 
   283 /**
   284 /**
   284  * hb_blob_make_immutable:
   285  * hb_blob_make_immutable:
   285  * @blob: a blob.
   286  * @blob: a blob.
   286  *
   287  *
   287  * 
   288  *
   288  *
   289  *
   289  * Since: 0.9.2
   290  * Since: 0.9.2
   290  **/
   291  **/
   291 void
   292 void
   292 hb_blob_make_immutable (hb_blob_t *blob)
   293 hb_blob_make_immutable (hb_blob_t *blob)
   299 
   300 
   300 /**
   301 /**
   301  * hb_blob_is_immutable:
   302  * hb_blob_is_immutable:
   302  * @blob: a blob.
   303  * @blob: a blob.
   303  *
   304  *
   304  * 
   305  *
   305  *
   306  *
   306  * Return value: TODO
   307  * Return value: TODO
   307  *
   308  *
   308  * Since: 0.9.2
   309  * Since: 0.9.2
   309  **/
   310  **/
   316 
   317 
   317 /**
   318 /**
   318  * hb_blob_get_length:
   319  * hb_blob_get_length:
   319  * @blob: a blob.
   320  * @blob: a blob.
   320  *
   321  *
   321  * 
   322  *
   322  *
   323  *
   323  * Return value: the length of blob data in bytes.
   324  * Return value: the length of blob data in bytes.
   324  *
   325  *
   325  * Since: 0.9.2
   326  * Since: 0.9.2
   326  **/
   327  **/
   333 /**
   334 /**
   334  * hb_blob_get_data:
   335  * hb_blob_get_data:
   335  * @blob: a blob.
   336  * @blob: a blob.
   336  * @length: (out):
   337  * @length: (out):
   337  *
   338  *
   338  * 
   339  *
   339  *
   340  *
   340  * Returns: (transfer none) (array length=length): 
   341  * Returns: (transfer none) (array length=length):
   341  *
   342  *
   342  * Since: 0.9.2
   343  * Since: 0.9.2
   343  **/
   344  **/
   344 const char *
   345 const char *
   345 hb_blob_get_data (hb_blob_t *blob, unsigned int *length)
   346 hb_blob_get_data (hb_blob_t *blob, unsigned int *length)
   371 {
   372 {
   372   if (!_try_writable (blob)) {
   373   if (!_try_writable (blob)) {
   373     if (length)
   374     if (length)
   374       *length = 0;
   375       *length = 0;
   375 
   376 
   376     return NULL;
   377     return nullptr;
   377   }
   378   }
   378 
   379 
   379   if (length)
   380   if (length)
   380     *length = blob->length;
   381     *length = blob->length;
   381 
   382