From e87b1b3ec3a67bf42edac41236e1e70a56ff7072 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 23 Feb 2023 12:23:52 -0700 Subject: [PATCH] [wasm-api] Try to add face_reference_table --- src/hb-wasm-api-face.hh | 51 +++++++++++++++++++++++++++++++++++++++++ src/hb-wasm-api-list.hh | 3 +++ src/hb-wasm-api.cc | 4 +--- src/hb-wasm-api.h | 41 +++++++++++++++++++++++++-------- src/hb-wasm-api.hh | 19 +++++++++++++-- 5 files changed, 104 insertions(+), 14 deletions(-) create mode 100644 src/hb-wasm-api-face.hh diff --git a/src/hb-wasm-api-face.hh b/src/hb-wasm-api-face.hh new file mode 100644 index 000000000..08e6671c8 --- /dev/null +++ b/src/hb-wasm-api-face.hh @@ -0,0 +1,51 @@ +/* + * Copyright © 2023 Behdad Esfahbod + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + */ + +#ifndef HB_WASM_FACE_HH +#define HB_WASM_FACE_HH + +#include + +namespace hb { +namespace wasm { + + +void +face_reference_table (HB_WASM_EXEC_ENV_COMPOUND + face_t faceref, + tag_t table_tag) +{ + HB_RETURN_TYPE (blob_t, blob); + + HB_REF2OBJ (face); + if (unlikely (!face)) + return; + + blob.length = 1; +} + + +}} + +#endif /* HB_WASM_FACE_HH */ diff --git a/src/hb-wasm-api-list.hh b/src/hb-wasm-api-list.hh index 11ec2b618..35beb807b 100644 --- a/src/hb-wasm-api-list.hh +++ b/src/hb-wasm-api-list.hh @@ -45,6 +45,9 @@ debugprint (HB_WASM_EXEC_ENV static NativeSymbol _hb_wasm_native_symbols[] = { + /* face */ + NATIVE_SYMBOL ("(iii)", face_reference_table), + /* font */ NATIVE_SYMBOL ("(i)i", font_get_face), diff --git a/src/hb-wasm-api.cc b/src/hb-wasm-api.cc index 74b18435d..de55bd1a7 100644 --- a/src/hb-wasm-api.cc +++ b/src/hb-wasm-api.cc @@ -27,12 +27,10 @@ #define module_inst wasm_runtime_get_module_inst (exec_env) +#include "hb-wasm-api-face.hh" #include "hb-wasm-api-font.hh" #undef module_inst -#undef HB_WASM_EXEC_ENV -#undef HB_REF2OBJ -#undef HB_OBJ2REF hb_user_data_key_t _hb_wasm_ref_type_key = {}; diff --git a/src/hb-wasm-api.h b/src/hb-wasm-api.h index 59228f977..7f25b996a 100644 --- a/src/hb-wasm-api.h +++ b/src/hb-wasm-api.h @@ -46,14 +46,20 @@ HB_WASM_BEGIN_DECLS #ifndef HB_WASM_API -#define HB_WASM_API(x) x +#define HB_WASM_API(ret_t, name) ret_t name +#endif +#ifndef HB_WASM_API_COMPOUND /* compound return type */ +#define HB_WASM_API_COMPOUND(ret_t, name) HB_WASM_API(ret_t, name) #endif #ifndef HB_WASM_INTERFACE -#define HB_WASM_INTERFACE(x) x +#define HB_WASM_INTERFACE(ret_t, name) ret_t name #endif #ifndef HB_WASM_EXEC_ENV #define HB_WASM_EXEC_ENV #endif +#ifndef HB_WASM_EXEC_ENV_COMPOUND +#define HB_WASM_EXEC_ENV_COMPOUND HB_WASM_EXEC_ENV +#endif #ifndef bool_t @@ -62,24 +68,41 @@ HB_WASM_BEGIN_DECLS #ifndef ref_t #define ref_t uint32_t #endif +#ifndef ptr_t +#define ptr_t uint32_t +#endif + +typedef uint32_t tag_t; +#define TAG(c1,c2,c3,c4) ((tag_t)((((uint32_t)(c1)&0xFF)<<24)|(((uint32_t)(c2)&0xFF)<<16)|(((uint32_t)(c3)&0xFF)<<8)|((uint32_t)(c4)&0xFF))) + typedef ref_t face_t; typedef ref_t font_t; typedef ref_t buffer_t; +typedef struct { + ref_t data; + uint32_t length; +} blob_t; + + +/* face */ + +HB_WASM_API_COMPOUND (blob_t, face_reference_table) (HB_WASM_EXEC_ENV_COMPOUND + face_t faceref, + tag_t table_tag); + /* font */ -face_t -HB_WASM_API (font_get_face) (HB_WASM_EXEC_ENV - font_t); +HB_WASM_API (face_t, font_get_face) (HB_WASM_EXEC_ENV + font_t fontref); /* shape interface */ -bool_t -HB_WASM_INTERFACE (shape) (HB_WASM_EXEC_ENV - font_t, - buffer_t); +HB_WASM_INTERFACE (bool_t, shape) (HB_WASM_EXEC_ENV + font_t fontref, + buffer_t bufferref); HB_WASM_END_DECLS diff --git a/src/hb-wasm-api.hh b/src/hb-wasm-api.hh index a53f3f5b0..8f9c7d8ce 100644 --- a/src/hb-wasm-api.hh +++ b/src/hb-wasm-api.hh @@ -29,11 +29,14 @@ #include -#define HB_WASM_API(x) HB_INTERNAL x #define HB_WASM_BEGIN_DECLS namespace hb { namespace wasm { #define HB_WASM_END_DECLS }} +#define HB_WASM_API(ret_t, name) HB_INTERNAL ret_t name +#define HB_WASM_API_COMPOUND(ret_t, name) HB_INTERNAL void name + #define HB_WASM_EXEC_ENV wasm_exec_env_t exec_env, +#define HB_WASM_EXEC_ENV_COMPOUND wasm_exec_env_t exec_env, ptr_t retptr, #include "hb-wasm-api.h" @@ -63,7 +66,6 @@ HB_INTERNAL extern hb_user_data_key_t _hb_wasm_ref_type_key; (void *) hb_wasm_ref_type_##obj)) \ obj = nullptr; \ } HB_STMT_END - #define HB_OBJ2REF(obj) \ uint32_t obj##ref = nullref; \ HB_STMT_START { \ @@ -73,5 +75,18 @@ HB_INTERNAL extern hb_user_data_key_t _hb_wasm_ref_type_key; (void) wasm_externref_obj2ref (module_inst, obj, &obj##ref); \ } HB_STMT_END +#define HB_RETURN_TYPE(type, name) \ + type *_name_ptr = nullptr; \ + { \ + if (likely (wasm_runtime_validate_app_addr (module_inst, \ + retptr, sizeof (type)))) \ + { \ + _name_ptr = (type *) wasm_runtime_addr_app_to_native (module_inst, retptr); \ + if (unlikely (!_name_ptr)) \ + return; \ + } \ + } \ + type &name = *_name_ptr + #endif /* HB_WASM_API_HH */