[wasm-api] Try to add face_reference_table
This commit is contained in:
parent
e03726d269
commit
e87b1b3ec3
|
@ -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 <hb-wasm-api.hh>
|
||||
|
||||
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 */
|
|
@ -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),
|
||||
|
||||
|
|
|
@ -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 = {};
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -29,11 +29,14 @@
|
|||
|
||||
#include <wasm_export.h>
|
||||
|
||||
#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 */
|
||||
|
|
Loading…
Reference in New Issue