Enable AoT and wamr-sdk, and change arguments of call wasm API (#157)
* Implement memory profiler, optimize memory usage, modify code indent * Implement memory.grow and limit heap space base offset to 1G; modify iwasm build type to Release and 64 bit by default * Add a new extension library: connection * Fix bug of reading magic number and version in big endian platform * Re-org platform APIs: move most platform APIs from iwasm to shared-lib * Enhance wasm loader to fix some security issues * Fix issue about illegal load of EXC_RETURN into PC on stm32 board * Updates that let a restricted version of the interpreter run in SGX * Enable native/app address validation and conversion for wasm app * Remove wasm_application_exectue_* APIs from wasm_export.h which makes confused * Refine binary size and fix several minor issues Optimize interpreter LOAD/STORE opcodes to decrease the binary size Fix issues when using iwasm library: _bh_log undefined, bh_memory.h not found Remove unused _stdin/_stdout/_stderr global variables resolve in libc wrapper Add macros of global heap size, stack size, heap size for Zephyr main.c Clear compile warning of wasm_application.c * Add more strict security checks for libc wrapper API's * Use one libc wrapper copy for sgx and other platforms; remove bh_printf macro for other platform header files * Enhance security of libc strcpy/sprintf wrapper function * Fix issue of call native for x86_64/arm/mips, add module inst parameter for native wrapper functions * Remove get_module_inst() and fix issue of call native * Refine wgl lib: remove module_inst parameter from widget functions; move function index check to runtime instantiate * Refine interpreter call native process, refine memory boudary check * Fix issues of invokeNative function of arm/mips/general version * Add a switch to build simple sample without gui support * Add BUILD_TARGET setting in makefile to replace cpu compiler flags in source code * Re-org shared lib header files, remove unused info; fix compile issues of vxworks * Add build target general * Remove unused files * Update license header * test push * Restore file * Sync up with internal/feature * Sync up with internal/feature * Rename build_wamr_app to build_wasm_app * Fix small issues of README * Enhance malformed wasm file checking Fix issue of print hex int and implement utf8 string check Fix wasi file read/write right issue Fix minor issue of build wasm app doc * Sync up with internal/feature * Sync up with internal/feature: fix interpreter arm issue, fix read leb issue * Sync up with internal/feature * Fix bug of config.h and rename wasi config.h to ssp_config.h * Sync up with internal/feature * Import wamr aot * update document * update document * Update document, disable WASI in 32bit * update document * remove files * update document * Update document * update document * update document * update samples * Sync up with internal repo
This commit is contained in:
36
core/app-framework/wgl/app/gui_api.h
Normal file
36
core/app-framework/wgl/app/gui_api.h
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#ifndef _GUI_API_H_
|
||||
#define _GUI_API_H_
|
||||
|
||||
#include "bh_platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void
|
||||
wasm_obj_native_call(int32 func_id, uint32 *argv, uint32 argc);
|
||||
|
||||
void
|
||||
wasm_btn_native_call(int32 func_id, uint32 *argv, uint32 argc);
|
||||
|
||||
void
|
||||
wasm_label_native_call(int32 func_id, uint32 *argv, uint32 argc);
|
||||
|
||||
void
|
||||
wasm_cb_native_call(int32 func_id, uint32 *argv, uint32 argc);
|
||||
|
||||
void
|
||||
wasm_list_native_call(int32 func_id, uint32 *argv, uint32 argc);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* end of _GUI_API_H_ */
|
||||
121
core/app-framework/wgl/app/src/wgl_btn.c
Normal file
121
core/app-framework/wgl/app/src/wgl_btn.c
Normal file
@ -0,0 +1,121 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#include "wa-inc/wgl.h"
|
||||
#include "bh_platform.h"
|
||||
#include "gui_api.h"
|
||||
|
||||
#define ARGC sizeof(argv)/sizeof(uint32)
|
||||
#define CALL_BTN_NATIVE_FUNC(id) wasm_btn_native_call(id, argv, ARGC)
|
||||
|
||||
wgl_obj_t wgl_btn_create(wgl_obj_t par, wgl_obj_t copy)
|
||||
{
|
||||
uint32 argv[2] = {0};
|
||||
|
||||
argv[0] = (uint32)par;
|
||||
argv[1] = (uint32)copy;
|
||||
CALL_BTN_NATIVE_FUNC(BTN_FUNC_ID_CREATE);
|
||||
return (wgl_obj_t)argv[0];
|
||||
}
|
||||
|
||||
void wgl_btn_set_toggle(wgl_obj_t btn, bool tgl)
|
||||
{
|
||||
uint32 argv[2] = {0};
|
||||
argv[0] = (uint32)btn;
|
||||
argv[1] = tgl;
|
||||
CALL_BTN_NATIVE_FUNC(BTN_FUNC_ID_SET_TOGGLE);
|
||||
}
|
||||
|
||||
void wgl_btn_set_state(wgl_obj_t btn, wgl_btn_state_t state)
|
||||
{
|
||||
uint32 argv[2] = {0};
|
||||
argv[0] = (uint32)btn;
|
||||
argv[1] = state;
|
||||
CALL_BTN_NATIVE_FUNC(BTN_FUNC_ID_SET_STATE);
|
||||
}
|
||||
|
||||
void wgl_btn_toggle(wgl_obj_t btn)
|
||||
{
|
||||
uint32 argv[1] = {0};
|
||||
argv[0] = (uint32)btn;
|
||||
CALL_BTN_NATIVE_FUNC(BTN_FUNC_ID_TOGGLE);
|
||||
}
|
||||
|
||||
void wgl_btn_set_ink_in_time(wgl_obj_t btn, uint16_t time)
|
||||
{
|
||||
uint32 argv[2] = {0};
|
||||
argv[0] = (uint32)btn;
|
||||
argv[1] = time;
|
||||
CALL_BTN_NATIVE_FUNC(BTN_FUNC_ID_SET_INK_IN_TIME);
|
||||
}
|
||||
|
||||
void wgl_btn_set_ink_wait_time(wgl_obj_t btn, uint16_t time)
|
||||
{
|
||||
uint32 argv[2] = {0};
|
||||
argv[0] = (uint32)btn;
|
||||
argv[1] = time;
|
||||
CALL_BTN_NATIVE_FUNC(BTN_FUNC_ID_SET_INK_WAIT_TIME);
|
||||
}
|
||||
|
||||
void wgl_btn_set_ink_out_time(wgl_obj_t btn, uint16_t time)
|
||||
{
|
||||
uint32 argv[2] = {0};
|
||||
argv[0] = (uint32)btn;
|
||||
argv[1] = time;
|
||||
CALL_BTN_NATIVE_FUNC(BTN_FUNC_ID_SET_INK_OUT_TIME);
|
||||
}
|
||||
|
||||
//void wgl_btn_set_style(wgl_obj_t btn, wgl_btn_style_t type, const wgl_style_t * style)
|
||||
//{
|
||||
// //TODO: pack style
|
||||
// //wasm_btn_set_style(btn, type, style);
|
||||
//}
|
||||
//
|
||||
wgl_btn_state_t wgl_btn_get_state(const wgl_obj_t btn)
|
||||
{
|
||||
uint32 argv[1] = {0};
|
||||
argv[0] = (uint32)btn;
|
||||
CALL_BTN_NATIVE_FUNC(BTN_FUNC_ID_GET_STATE);
|
||||
return (wgl_btn_state_t)argv[0];
|
||||
}
|
||||
|
||||
bool wgl_btn_get_toggle(const wgl_obj_t btn)
|
||||
{
|
||||
uint32 argv[1] = {0};
|
||||
argv[0] = (uint32)btn;
|
||||
CALL_BTN_NATIVE_FUNC(BTN_FUNC_ID_GET_TOGGLE);
|
||||
return (bool)argv[0];
|
||||
}
|
||||
|
||||
uint16_t wgl_btn_get_ink_in_time(const wgl_obj_t btn)
|
||||
{
|
||||
uint32 argv[1] = {0};
|
||||
argv[0] = (uint32)btn;
|
||||
CALL_BTN_NATIVE_FUNC(BTN_FUNC_ID_GET_INK_IN_TIME);
|
||||
return (uint16_t)argv[0];
|
||||
}
|
||||
|
||||
uint16_t wgl_btn_get_ink_wait_time(const wgl_obj_t btn)
|
||||
{
|
||||
uint32 argv[1] = {0};
|
||||
argv[0] = (uint32)btn;
|
||||
CALL_BTN_NATIVE_FUNC(BTN_FUNC_ID_GET_INK_WAIT_TIME);
|
||||
return (uint16_t)argv[0];
|
||||
}
|
||||
|
||||
uint16_t wgl_btn_get_ink_out_time(const wgl_obj_t btn)
|
||||
{
|
||||
uint32 argv[1] = {0};
|
||||
argv[0] = (uint32)btn;
|
||||
CALL_BTN_NATIVE_FUNC(BTN_FUNC_ID_GET_INK_OUT_TIME);
|
||||
return (uint16_t)argv[0];
|
||||
}
|
||||
//
|
||||
//const wgl_style_t * wgl_btn_get_style(const wgl_obj_t btn, wgl_btn_style_t type)
|
||||
//{
|
||||
// //TODO: pack style
|
||||
// //wasm_btn_get_style(btn, type);
|
||||
// return NULL;
|
||||
//}
|
||||
73
core/app-framework/wgl/app/src/wgl_cb.c
Normal file
73
core/app-framework/wgl/app/src/wgl_cb.c
Normal file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#include "wa-inc/wgl.h"
|
||||
#include "gui_api.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#define ARGC sizeof(argv)/sizeof(uint32)
|
||||
#define CALL_CB_NATIVE_FUNC(id) wasm_cb_native_call(id, argv, ARGC)
|
||||
|
||||
wgl_obj_t wgl_cb_create(wgl_obj_t par, const wgl_obj_t copy)
|
||||
{
|
||||
uint32 argv[2] = {0};
|
||||
|
||||
argv[0] = (uint32)par;
|
||||
argv[1] = (uint32)copy;
|
||||
CALL_CB_NATIVE_FUNC(CB_FUNC_ID_CREATE);
|
||||
return (wgl_obj_t)argv[0];
|
||||
}
|
||||
|
||||
void wgl_cb_set_text(wgl_obj_t cb, const char * txt)
|
||||
{
|
||||
uint32 argv[3] = {0};
|
||||
argv[0] = (uint32)cb;
|
||||
argv[1] = (uint32)txt;
|
||||
argv[2] = strlen(txt) + 1;
|
||||
CALL_CB_NATIVE_FUNC(CB_FUNC_ID_SET_TEXT);
|
||||
}
|
||||
|
||||
void wgl_cb_set_static_text(wgl_obj_t cb, const char * txt)
|
||||
{
|
||||
uint32 argv[3] = {0};
|
||||
argv[0] = (uint32)cb;
|
||||
argv[1] = (uint32)txt;
|
||||
argv[2] = strlen(txt) + 1;
|
||||
CALL_CB_NATIVE_FUNC(CB_FUNC_ID_SET_STATIC_TEXT);
|
||||
}
|
||||
|
||||
//void wgl_cb_set_style(wgl_obj_t cb, wgl_cb_style_t type, const wgl_style_t * style)
|
||||
//{
|
||||
// //TODO:
|
||||
//}
|
||||
//
|
||||
|
||||
unsigned int wgl_cb_get_text_length(wgl_obj_t cb)
|
||||
{
|
||||
uint32 argv[1] = {0};
|
||||
argv[0] = (uint32)cb;
|
||||
CALL_CB_NATIVE_FUNC(CB_FUNC_ID_GET_TEXT_LENGTH);
|
||||
return argv[0];
|
||||
}
|
||||
|
||||
char *wgl_cb_get_text(wgl_obj_t cb, char *buffer, int buffer_len)
|
||||
{
|
||||
uint32 argv[3] = {0};
|
||||
argv[0] = (uint32)cb;
|
||||
argv[1] = (uint32)buffer;
|
||||
argv[2] = buffer_len;
|
||||
CALL_CB_NATIVE_FUNC(CB_FUNC_ID_GET_TEXT);
|
||||
return (char *)argv[0];
|
||||
}
|
||||
|
||||
//const wgl_style_t * wgl_cb_get_style(const wgl_obj_t cb, wgl_cb_style_t type)
|
||||
//{
|
||||
// //TODO
|
||||
// return NULL;
|
||||
//}
|
||||
//
|
||||
|
||||
|
||||
252
core/app-framework/wgl/app/src/wgl_label.c
Normal file
252
core/app-framework/wgl/app/src/wgl_label.c
Normal file
@ -0,0 +1,252 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
|
||||
#include "wa-inc/wgl.h"
|
||||
#include "gui_api.h"
|
||||
#include <string.h>
|
||||
|
||||
|
||||
#define ARGC sizeof(argv)/sizeof(uint32)
|
||||
#define CALL_LABEL_NATIVE_FUNC(id) wasm_label_native_call(id, argv, ARGC)
|
||||
|
||||
wgl_obj_t wgl_label_create(wgl_obj_t par, wgl_obj_t copy)
|
||||
{
|
||||
uint32 argv[2] = {0};
|
||||
|
||||
argv[0] = (uint32)par;
|
||||
argv[1] = (uint32)copy;
|
||||
CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_CREATE);
|
||||
return (wgl_obj_t)argv[0];
|
||||
}
|
||||
|
||||
void wgl_label_set_text(wgl_obj_t label, const char * text)
|
||||
{
|
||||
uint32 argv[3] = {0};
|
||||
argv[0] = (uint32)label;
|
||||
argv[1] = (uint32)text;
|
||||
argv[2] = strlen(text) + 1;
|
||||
CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_SET_TEXT);
|
||||
}
|
||||
|
||||
|
||||
void wgl_label_set_array_text(wgl_obj_t label, const char * array, uint16_t size)
|
||||
{
|
||||
uint32 argv[3] = {0};
|
||||
argv[0] = (uint32)label;
|
||||
argv[1] = (uint32)array;
|
||||
argv[2] = size;
|
||||
CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_SET_ARRAY_TEXT);
|
||||
}
|
||||
|
||||
|
||||
void wgl_label_set_static_text(wgl_obj_t label, const char * text)
|
||||
{
|
||||
uint32 argv[3] = {0};
|
||||
argv[0] = (uint32)label;
|
||||
argv[1] = (uint32)text;
|
||||
argv[2] = strlen(text) + 1;
|
||||
CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_SET_STATIC_TEXT);
|
||||
}
|
||||
|
||||
|
||||
void wgl_label_set_long_mode(wgl_obj_t label, wgl_label_long_mode_t long_mode)
|
||||
{
|
||||
uint32 argv[2] = {0};
|
||||
argv[0] = (uint32)label;
|
||||
argv[1] = long_mode;
|
||||
CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_SET_LONG_MODE);
|
||||
}
|
||||
|
||||
|
||||
void wgl_label_set_align(wgl_obj_t label, wgl_label_align_t align)
|
||||
{
|
||||
uint32 argv[2] = {0};
|
||||
argv[0] = (uint32)label;
|
||||
argv[1] = align;
|
||||
CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_SET_ALIGN);
|
||||
}
|
||||
|
||||
|
||||
void wgl_label_set_recolor(wgl_obj_t label, bool en)
|
||||
{
|
||||
uint32 argv[2] = {0};
|
||||
argv[0] = (uint32)label;
|
||||
argv[1] = en;
|
||||
CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_SET_RECOLOR);
|
||||
}
|
||||
|
||||
|
||||
void wgl_label_set_body_draw(wgl_obj_t label, bool en)
|
||||
{
|
||||
uint32 argv[2] = {0};
|
||||
argv[0] = (uint32)label;
|
||||
argv[1] = en;
|
||||
CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_SET_BODY_DRAW);
|
||||
}
|
||||
|
||||
|
||||
void wgl_label_set_anim_speed(wgl_obj_t label, uint16_t anim_speed)
|
||||
{
|
||||
uint32 argv[2] = {0};
|
||||
argv[0] = (uint32)label;
|
||||
argv[1] = anim_speed;
|
||||
CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_SET_ANIM_SPEED);
|
||||
}
|
||||
|
||||
|
||||
void wgl_label_set_text_sel_start(wgl_obj_t label, uint16_t index)
|
||||
{
|
||||
uint32 argv[2] = {0};
|
||||
argv[0] = (uint32)label;
|
||||
argv[1] = index;
|
||||
CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_SET_TEXT_SEL_START);
|
||||
}
|
||||
|
||||
|
||||
void wgl_label_set_text_sel_end(wgl_obj_t label, uint16_t index)
|
||||
{
|
||||
uint32 argv[2] = {0};
|
||||
argv[0] = (uint32)label;
|
||||
argv[1] = index;
|
||||
CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_SET_TEXT_SEL_END);
|
||||
}
|
||||
|
||||
unsigned int wgl_label_get_text_length(wgl_obj_t label)
|
||||
{
|
||||
uint32 argv[1] = {0};
|
||||
argv[0] = (uint32)label;
|
||||
CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_GET_TEXT_LENGTH);
|
||||
return argv[0];
|
||||
}
|
||||
|
||||
char * wgl_label_get_text(wgl_obj_t label, char *buffer, int buffer_len)
|
||||
{
|
||||
uint32 argv[3] = {0};
|
||||
argv[0] = (uint32)label;
|
||||
argv[1] = (uint32)buffer;
|
||||
argv[2] = buffer_len;
|
||||
CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_GET_TEXT);
|
||||
return (char *)argv[0];
|
||||
}
|
||||
|
||||
|
||||
wgl_label_long_mode_t wgl_label_get_long_mode(const wgl_obj_t label)
|
||||
{
|
||||
uint32 argv[1] = {0};
|
||||
argv[0] = (uint32)label;
|
||||
CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_GET_LONG_MODE);
|
||||
return (wgl_label_long_mode_t)argv[0];
|
||||
}
|
||||
|
||||
|
||||
wgl_label_align_t wgl_label_get_align(const wgl_obj_t label)
|
||||
{
|
||||
uint32 argv[1] = {0};
|
||||
argv[0] = (uint32)label;
|
||||
CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_GET_ALIGN);
|
||||
return (wgl_label_align_t)argv[0];
|
||||
}
|
||||
|
||||
|
||||
bool wgl_label_get_recolor(const wgl_obj_t label)
|
||||
{
|
||||
uint32 argv[1] = {0};
|
||||
argv[0] = (uint32)label;
|
||||
CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_GET_RECOLOR);
|
||||
return (bool)argv[0];
|
||||
}
|
||||
|
||||
|
||||
bool wgl_label_get_body_draw(const wgl_obj_t label)
|
||||
{
|
||||
uint32 argv[1] = {0};
|
||||
argv[0] = (uint32)label;
|
||||
CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_GET_BODY_DRAW);
|
||||
return (bool)argv[0];
|
||||
}
|
||||
|
||||
|
||||
uint16_t wgl_label_get_anim_speed(const wgl_obj_t label)
|
||||
{
|
||||
uint32 argv[1] = {0};
|
||||
argv[0] = (uint32)label;
|
||||
CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_GET_ANIM_SPEED);
|
||||
return (uint16_t)argv[0];
|
||||
}
|
||||
|
||||
|
||||
void wgl_label_get_letter_pos(const wgl_obj_t label, uint16_t index, wgl_point_t * pos)
|
||||
{
|
||||
uint32 argv[4] = {0};
|
||||
argv[0] = (uint32)label;
|
||||
argv[1] = index;
|
||||
CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_GET_LETTER_POS);
|
||||
pos->x = argv[2];
|
||||
pos->y = argv[3];
|
||||
}
|
||||
|
||||
|
||||
uint16_t wgl_label_get_letter_on(const wgl_obj_t label, wgl_point_t * pos)
|
||||
{
|
||||
uint32 argv[3] = {0};
|
||||
argv[0] = (uint32)label;
|
||||
argv[1] = pos->x;
|
||||
argv[2] = pos->y;
|
||||
CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_GET_LETTER_POS);
|
||||
return (uint16_t)argv[0];
|
||||
}
|
||||
|
||||
|
||||
bool wgl_label_is_char_under_pos(const wgl_obj_t label, wgl_point_t * pos)
|
||||
{
|
||||
uint32 argv[3] = {0};
|
||||
argv[0] = (uint32)label;
|
||||
argv[1] = pos->x;
|
||||
argv[2] = pos->y;
|
||||
CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_GET_LETTER_POS);
|
||||
return (bool)argv[0];
|
||||
}
|
||||
|
||||
|
||||
uint16_t wgl_label_get_text_sel_start(const wgl_obj_t label)
|
||||
{
|
||||
uint32 argv[1] = {0};
|
||||
argv[0] = (uint32)label;
|
||||
CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_GET_TEXT_SEL_START);
|
||||
return (uint16_t)argv[0];
|
||||
}
|
||||
|
||||
|
||||
uint16_t wgl_label_get_text_sel_end(const wgl_obj_t label)
|
||||
{
|
||||
uint32 argv[1] = {0};
|
||||
argv[0] = (uint32)label;
|
||||
CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_GET_TEXT_SEL_END);
|
||||
return (uint16_t)argv[0];
|
||||
}
|
||||
|
||||
|
||||
void wgl_label_ins_text(wgl_obj_t label, uint32_t pos, const char * txt)
|
||||
{
|
||||
uint32 argv[4] = {0};
|
||||
argv[0] = (uint32)label;
|
||||
argv[1] = pos;
|
||||
argv[2] = (uint32)txt;
|
||||
argv[3] = strlen(txt) + 1;
|
||||
CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_INS_TEXT);
|
||||
}
|
||||
|
||||
|
||||
void wgl_label_cut_text(wgl_obj_t label, uint32_t pos, uint32_t cnt)
|
||||
{
|
||||
uint32 argv[3] = {0};
|
||||
argv[0] = (uint32)label;
|
||||
argv[1] = pos;
|
||||
argv[2] = cnt;
|
||||
CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_CUT_TEXT);
|
||||
}
|
||||
|
||||
|
||||
154
core/app-framework/wgl/app/src/wgl_list.c
Normal file
154
core/app-framework/wgl/app/src/wgl_list.c
Normal file
@ -0,0 +1,154 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#include "wa-inc/wgl.h"
|
||||
#include "gui_api.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#define ARGC sizeof(argv)/sizeof(uint32)
|
||||
#define CALL_LIST_NATIVE_FUNC(id) wasm_list_native_call(id, argv, ARGC)
|
||||
|
||||
|
||||
wgl_obj_t wgl_list_create(wgl_obj_t par, const wgl_obj_t copy)
|
||||
{
|
||||
uint32 argv[2] = {0};
|
||||
|
||||
argv[0] = (uint32)par;
|
||||
argv[1] = (uint32)copy;
|
||||
|
||||
CALL_LIST_NATIVE_FUNC(LIST_FUNC_ID_CREATE);
|
||||
return (wgl_obj_t)argv[0];
|
||||
}
|
||||
//
|
||||
//
|
||||
//void wgl_list_clean(wgl_obj_t obj)
|
||||
//{
|
||||
// wasm_list_clean(obj);
|
||||
//}
|
||||
//
|
||||
|
||||
wgl_obj_t wgl_list_add_btn(wgl_obj_t list, const void * img_src, const char * txt)
|
||||
{
|
||||
uint32 argv[3] = {0};
|
||||
|
||||
(void)img_src; /* doesn't support img src currently */
|
||||
|
||||
argv[0] = (uint32)list;
|
||||
argv[1] = (uint32)txt;
|
||||
argv[2] = strlen(txt) + 1;
|
||||
CALL_LIST_NATIVE_FUNC(LIST_FUNC_ID_ADD_BTN);
|
||||
return (wgl_obj_t)argv[0];
|
||||
}
|
||||
//
|
||||
//
|
||||
//bool wgl_list_remove(const wgl_obj_t list, uint16_t index)
|
||||
//{
|
||||
// return wasm_list_remove(list, index);
|
||||
//}
|
||||
//
|
||||
//
|
||||
//void wgl_list_set_single_mode(wgl_obj_t list, bool mode)
|
||||
//{
|
||||
// wasm_list_set_single_mode(list, mode);
|
||||
//}
|
||||
//
|
||||
//#if LV_USE_GROUP
|
||||
//
|
||||
//
|
||||
//void wgl_list_set_btn_selected(wgl_obj_t list, wgl_obj_t btn)
|
||||
//{
|
||||
// wasm_list_set_btn_selected(list, btn);
|
||||
//}
|
||||
//#endif
|
||||
//
|
||||
//
|
||||
//void wgl_list_set_style(wgl_obj_t list, wgl_list_style_t type, const wgl_style_t * style)
|
||||
//{
|
||||
// //TODO
|
||||
//}
|
||||
//
|
||||
//
|
||||
//bool wgl_list_get_single_mode(wgl_obj_t list)
|
||||
//{
|
||||
// return wasm_list_get_single_mode(list);
|
||||
//}
|
||||
//
|
||||
//
|
||||
//const char * wgl_list_get_btn_text(const wgl_obj_t btn)
|
||||
//{
|
||||
// return wasm_list_get_btn_text(btn);
|
||||
//}
|
||||
//
|
||||
//wgl_obj_t wgl_list_get_btn_label(const wgl_obj_t btn)
|
||||
//{
|
||||
// return wasm_list_get_btn_label(btn);
|
||||
//}
|
||||
//
|
||||
//
|
||||
//wgl_obj_t wgl_list_get_btn_img(const wgl_obj_t btn)
|
||||
//{
|
||||
// return wasm_list_get_btn_img(btn);
|
||||
//}
|
||||
//
|
||||
//
|
||||
//wgl_obj_t wgl_list_get_prev_btn(const wgl_obj_t list, wgl_obj_t prev_btn)
|
||||
//{
|
||||
// return wasm_list_get_prev_btn(list, prev_btn);
|
||||
//}
|
||||
//
|
||||
//
|
||||
//wgl_obj_t wgl_list_get_next_btn(const wgl_obj_t list, wgl_obj_t prev_btn)
|
||||
//{
|
||||
// return wasm_list_get_next_btn(list, prev_btn);
|
||||
//}
|
||||
//
|
||||
//
|
||||
//int32_t wgl_list_get_btn_index(const wgl_obj_t list, const wgl_obj_t btn)
|
||||
//{
|
||||
// return wasm_list_get_btn_index(list, btn);
|
||||
//}
|
||||
//
|
||||
//
|
||||
//uint16_t wgl_list_get_size(const wgl_obj_t list)
|
||||
//{
|
||||
// return wasm_list_get_size(list);
|
||||
//}
|
||||
//
|
||||
//#if LV_USE_GROUP
|
||||
//
|
||||
//wgl_obj_t wgl_list_get_btn_selected(const wgl_obj_t list)
|
||||
//{
|
||||
// return wasm_list_get_btn_selected(list);
|
||||
//}
|
||||
//#endif
|
||||
//
|
||||
//
|
||||
//
|
||||
//const wgl_style_t * wgl_list_get_style(const wgl_obj_t list, wgl_list_style_t type)
|
||||
//{
|
||||
// //TODO
|
||||
// return NULL;
|
||||
//}
|
||||
//
|
||||
//
|
||||
//void wgl_list_up(const wgl_obj_t list)
|
||||
//{
|
||||
// wasm_list_up(list);
|
||||
//}
|
||||
//
|
||||
//void wgl_list_down(const wgl_obj_t list)
|
||||
//{
|
||||
// wasm_list_down(list);
|
||||
//}
|
||||
//
|
||||
//
|
||||
//void wgl_list_focus(const wgl_obj_t btn, wgl_anim_enable_t anim)
|
||||
//{
|
||||
// wasm_list_focus(btn, anim);
|
||||
//}
|
||||
//
|
||||
|
||||
|
||||
116
core/app-framework/wgl/app/src/wgl_obj.c
Normal file
116
core/app-framework/wgl/app/src/wgl_obj.c
Normal file
@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#include "wa-inc/wgl.h"
|
||||
#include "gui_api.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define ARGC sizeof(argv)/sizeof(uint32)
|
||||
#define CALL_OBJ_NATIVE_FUNC(id) wasm_obj_native_call(id, argv, ARGC)
|
||||
|
||||
typedef struct _obj_evt_cb {
|
||||
struct _obj_evt_cb *next;
|
||||
|
||||
wgl_obj_t obj;
|
||||
|
||||
wgl_event_cb_t event_cb;
|
||||
} obj_evt_cb_t;
|
||||
|
||||
static obj_evt_cb_t *g_obj_evt_cb_list = NULL;
|
||||
|
||||
/* For lvgl compatible */
|
||||
char g_widget_text[100];
|
||||
|
||||
wgl_res_t wgl_obj_del(wgl_obj_t obj)
|
||||
{
|
||||
uint32 argv[1] = {0};
|
||||
argv[0] = (uint32)obj;
|
||||
CALL_OBJ_NATIVE_FUNC(OBJ_FUNC_ID_DEL);
|
||||
return (wgl_res_t)argv[0];
|
||||
}
|
||||
|
||||
void wgl_obj_del_async(wgl_obj_t obj)
|
||||
{
|
||||
uint32 argv[1] = {0};
|
||||
argv[0] = (uint32)obj;
|
||||
CALL_OBJ_NATIVE_FUNC(OBJ_FUNC_ID_DEL_ASYNC);
|
||||
}
|
||||
|
||||
void wgl_obj_clean(wgl_obj_t obj)
|
||||
{
|
||||
uint32 argv[1] = {0};
|
||||
argv[0] = (uint32)obj;
|
||||
CALL_OBJ_NATIVE_FUNC(OBJ_FUNC_ID_CLEAN);
|
||||
}
|
||||
|
||||
void wgl_obj_align(wgl_obj_t obj, const wgl_obj_t base, wgl_align_t align, wgl_coord_t x_mod, wgl_coord_t y_mod)
|
||||
{
|
||||
uint32 argv[5] = {0};
|
||||
argv[0] = (uint32)obj;
|
||||
argv[1] = (uint32)base;
|
||||
argv[2] = align;
|
||||
argv[3] = x_mod;
|
||||
argv[4] = y_mod;
|
||||
CALL_OBJ_NATIVE_FUNC(OBJ_FUNC_ID_ALIGN);
|
||||
}
|
||||
|
||||
wgl_event_cb_t wgl_obj_get_event_cb(const wgl_obj_t obj)
|
||||
{
|
||||
obj_evt_cb_t *obj_evt_cb = g_obj_evt_cb_list;
|
||||
while (obj_evt_cb != NULL) {
|
||||
if (obj_evt_cb->obj == obj) {
|
||||
return obj_evt_cb->event_cb;
|
||||
}
|
||||
obj_evt_cb = obj_evt_cb->next;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void wgl_obj_set_event_cb(wgl_obj_t obj, wgl_event_cb_t event_cb)
|
||||
{
|
||||
obj_evt_cb_t *obj_evt_cb;
|
||||
uint32 argv[1] = {0};
|
||||
|
||||
obj_evt_cb = g_obj_evt_cb_list;
|
||||
while (obj_evt_cb) {
|
||||
if (obj_evt_cb->obj == obj) {
|
||||
obj_evt_cb->event_cb = event_cb;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
obj_evt_cb = (obj_evt_cb_t *)malloc(sizeof(*obj_evt_cb));
|
||||
if (obj_evt_cb == NULL)
|
||||
return;
|
||||
|
||||
memset(obj_evt_cb, 0, sizeof(*obj_evt_cb));
|
||||
obj_evt_cb->obj = obj;
|
||||
obj_evt_cb->event_cb = event_cb;
|
||||
|
||||
if (g_obj_evt_cb_list != NULL) {
|
||||
obj_evt_cb->next = g_obj_evt_cb_list;
|
||||
g_obj_evt_cb_list = obj_evt_cb;
|
||||
} else {
|
||||
g_obj_evt_cb_list = obj_evt_cb;
|
||||
}
|
||||
|
||||
argv[0] = (uint32)obj;
|
||||
CALL_OBJ_NATIVE_FUNC(OBJ_FUNC_ID_SET_EVT_CB);
|
||||
}
|
||||
|
||||
void on_widget_event(wgl_obj_t obj, wgl_event_t event)
|
||||
{
|
||||
obj_evt_cb_t *obj_evt_cb = g_obj_evt_cb_list;
|
||||
|
||||
while (obj_evt_cb != NULL) {
|
||||
if (obj_evt_cb->obj == obj) {
|
||||
obj_evt_cb->event_cb(obj, event);
|
||||
return;
|
||||
}
|
||||
obj_evt_cb = obj_evt_cb->next;
|
||||
}
|
||||
}
|
||||
8
core/app-framework/wgl/app/wa-inc/inc/LICENCE.txt
Normal file
8
core/app-framework/wgl/app/wa-inc/inc/LICENCE.txt
Normal file
@ -0,0 +1,8 @@
|
||||
MIT licence
|
||||
Copyright (c) 2016 Gábor Kiss-Vámosi
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
162
core/app-framework/wgl/app/wa-inc/inc/wgl_btn.h
Normal file
162
core/app-framework/wgl/app/wa-inc/inc/wgl_btn.h
Normal file
@ -0,0 +1,162 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#ifndef WAMR_GRAPHIC_LIBRARY_BTN_H
|
||||
#define WAMR_GRAPHIC_LIBRARY_BTN_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** Possible states of a button.
|
||||
* It can be used not only by buttons but other button-like objects too*/
|
||||
enum {
|
||||
/**Released*/
|
||||
WGL_BTN_STATE_REL,
|
||||
|
||||
/**Pressed*/
|
||||
WGL_BTN_STATE_PR,
|
||||
|
||||
/**Toggled released*/
|
||||
WGL_BTN_STATE_TGL_REL,
|
||||
|
||||
/**Toggled pressed*/
|
||||
WGL_BTN_STATE_TGL_PR,
|
||||
|
||||
/**Inactive*/
|
||||
WGL_BTN_STATE_INA,
|
||||
|
||||
/**Number of states*/
|
||||
_WGL_BTN_STATE_NUM,
|
||||
};
|
||||
typedef uint8_t wgl_btn_state_t;
|
||||
|
||||
/**Styles*/
|
||||
enum {
|
||||
/** Release style */
|
||||
WGL_BTN_STYLE_REL,
|
||||
|
||||
/**Pressed style*/
|
||||
WGL_BTN_STYLE_PR,
|
||||
|
||||
/** Toggle released style*/
|
||||
WGL_BTN_STYLE_TGL_REL,
|
||||
|
||||
/** Toggle pressed style */
|
||||
WGL_BTN_STYLE_TGL_PR,
|
||||
|
||||
/** Inactive style*/
|
||||
WGL_BTN_STYLE_INA,
|
||||
};
|
||||
typedef uint8_t wgl_btn_style_t;
|
||||
|
||||
|
||||
/* Create a button */
|
||||
wgl_obj_t wgl_btn_create(wgl_obj_t par, wgl_obj_t copy);
|
||||
|
||||
/*=====================
|
||||
* Setter functions
|
||||
*====================*/
|
||||
|
||||
/**
|
||||
* Enable the toggled states. On release the button will change from/to toggled state.
|
||||
* @param btn pointer to a button object
|
||||
* @param tgl true: enable toggled states, false: disable
|
||||
*/
|
||||
void wgl_btn_set_toggle(wgl_obj_t btn, bool tgl);
|
||||
|
||||
/**
|
||||
* Set the state of the button
|
||||
* @param btn pointer to a button object
|
||||
* @param state the new state of the button (from wgl_btn_state_t enum)
|
||||
*/
|
||||
void wgl_btn_set_state(wgl_obj_t btn, wgl_btn_state_t state);
|
||||
|
||||
/**
|
||||
* Toggle the state of the button (ON->OFF, OFF->ON)
|
||||
* @param btn pointer to a button object
|
||||
*/
|
||||
void wgl_btn_toggle(wgl_obj_t btn);
|
||||
|
||||
/**
|
||||
* Set time of the ink effect (draw a circle on click to animate in the new state)
|
||||
* @param btn pointer to a button object
|
||||
* @param time the time of the ink animation
|
||||
*/
|
||||
void wgl_btn_set_ink_in_time(wgl_obj_t btn, uint16_t time);
|
||||
|
||||
/**
|
||||
* Set the wait time before the ink disappears
|
||||
* @param btn pointer to a button object
|
||||
* @param time the time of the ink animation
|
||||
*/
|
||||
void wgl_btn_set_ink_wait_time(wgl_obj_t btn, uint16_t time);
|
||||
|
||||
/**
|
||||
* Set time of the ink out effect (animate to the released state)
|
||||
* @param btn pointer to a button object
|
||||
* @param time the time of the ink animation
|
||||
*/
|
||||
void wgl_btn_set_ink_out_time(wgl_obj_t btn, uint16_t time);
|
||||
|
||||
/**
|
||||
* Set a style of a button.
|
||||
* @param btn pointer to button object
|
||||
* @param type which style should be set
|
||||
* @param style pointer to a style
|
||||
* */
|
||||
//void wgl_btn_set_style(wgl_obj_t btn, wgl_btn_style_t type, const wgl_style_t * style);
|
||||
|
||||
/*=====================
|
||||
* Getter functions
|
||||
*====================*/
|
||||
|
||||
/**
|
||||
* Get the current state of the button
|
||||
* @param btn pointer to a button object
|
||||
* @return the state of the button (from wgl_btn_state_t enum)
|
||||
*/
|
||||
wgl_btn_state_t wgl_btn_get_state(wgl_obj_t btn);
|
||||
|
||||
/**
|
||||
* Get the toggle enable attribute of the button
|
||||
* @param btn pointer to a button object
|
||||
* @return true: toggle enabled, false: disabled
|
||||
*/
|
||||
bool wgl_btn_get_toggle(wgl_obj_t btn);
|
||||
|
||||
/**
|
||||
* Get time of the ink in effect (draw a circle on click to animate in the new state)
|
||||
* @param btn pointer to a button object
|
||||
* @return the time of the ink animation
|
||||
*/
|
||||
uint16_t wgl_btn_get_ink_in_time(wgl_obj_t btn);
|
||||
|
||||
/**
|
||||
* Get the wait time before the ink disappears
|
||||
* @param btn pointer to a button object
|
||||
* @return the time of the ink animation
|
||||
*/
|
||||
uint16_t wgl_btn_get_ink_wait_time(wgl_obj_t btn);
|
||||
|
||||
/**
|
||||
* Get time of the ink out effect (animate to the releases state)
|
||||
* @param btn pointer to a button object
|
||||
* @return the time of the ink animation
|
||||
*/
|
||||
uint16_t wgl_btn_get_ink_out_time(wgl_obj_t btn);
|
||||
|
||||
/**
|
||||
* Get style of a button.
|
||||
* @param btn pointer to button object
|
||||
* @param type which style should be get
|
||||
* @return style pointer to the style
|
||||
* */
|
||||
//const wgl_style_t * wgl_btn_get_style(const wgl_obj_t btn, wgl_btn_style_t type);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* WAMR_GRAPHIC_LIBRARY_BTN_H */
|
||||
79
core/app-framework/wgl/app/wa-inc/inc/wgl_cb.h
Normal file
79
core/app-framework/wgl/app/wa-inc/inc/wgl_cb.h
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#ifndef WAMR_GRAPHIC_LIBRARY_CB_H
|
||||
#define WAMR_GRAPHIC_LIBRARY_CB_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** Checkbox styles. */
|
||||
enum {
|
||||
WGL_CB_STYLE_BG, /**< Style of object background. */
|
||||
WGL_CB_STYLE_BOX_REL, /**< Style of box (released). */
|
||||
WGL_CB_STYLE_BOX_PR, /**< Style of box (pressed). */
|
||||
WGL_CB_STYLE_BOX_TGL_REL, /**< Style of box (released but checked). */
|
||||
WGL_CB_STYLE_BOX_TGL_PR, /**< Style of box (pressed and checked). */
|
||||
WGL_CB_STYLE_BOX_INA, /**< Style of disabled box */
|
||||
};
|
||||
typedef uint8_t wgl_cb_style_t;
|
||||
|
||||
|
||||
/**
|
||||
* Create a check box objects
|
||||
* @param par pointer to an object, it will be the parent of the new check box
|
||||
* @param copy pointer to a check box object, if not NULL then the new object will be copied from it
|
||||
* @return pointer to the created check box
|
||||
*/
|
||||
wgl_obj_t wgl_cb_create(wgl_obj_t par, const wgl_obj_t copy);
|
||||
|
||||
/*=====================
|
||||
* Setter functions
|
||||
*====================*/
|
||||
|
||||
/**
|
||||
* Set the text of a check box. `txt` will be copied and may be deallocated
|
||||
* after this function returns.
|
||||
* @param cb pointer to a check box
|
||||
* @param txt the text of the check box. NULL to refresh with the current text.
|
||||
*/
|
||||
void wgl_cb_set_text(wgl_obj_t cb, const char * txt);
|
||||
|
||||
/**
|
||||
* Set the text of a check box. `txt` must not be deallocated during the life
|
||||
* of this checkbox.
|
||||
* @param cb pointer to a check box
|
||||
* @param txt the text of the check box. NULL to refresh with the current text.
|
||||
*/
|
||||
void wgl_cb_set_static_text(wgl_obj_t cb, const char * txt);
|
||||
|
||||
|
||||
/*=====================
|
||||
* Getter functions
|
||||
*====================*/
|
||||
|
||||
|
||||
/**
|
||||
* Get the length of the text of a check box
|
||||
* @param label the check box object
|
||||
* @return the length of the text of the check box
|
||||
*/
|
||||
unsigned int wgl_cb_get_text_length(wgl_obj_t cb);
|
||||
|
||||
/**
|
||||
* Get the text of a check box
|
||||
* @param label the check box object
|
||||
* @param buffer buffer to save the text
|
||||
* @param buffer_len length of the buffer
|
||||
* @return the text of the check box, note that the text will be truncated if buffer is not long enough
|
||||
*/
|
||||
char *wgl_cb_get_text(wgl_obj_t cb, char *buffer, int buffer_len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* WAMR_GRAPHIC_LIBRARY_CB_H */
|
||||
66
core/app-framework/wgl/app/wa-inc/inc/wgl_label.h
Normal file
66
core/app-framework/wgl/app/wa-inc/inc/wgl_label.h
Normal file
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#ifndef WAMR_GRAPHIC_LIBRARY_LABEL_H
|
||||
#define WAMR_GRAPHIC_LIBRARY_LABEL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** Long mode behaviors. Used in 'wgl_label_ext_t' */
|
||||
enum {
|
||||
WGL_LABEL_LONG_EXPAND, /**< Expand the object size to the text size*/
|
||||
WGL_LABEL_LONG_BREAK, /**< Keep the object width, break the too long lines and expand the object
|
||||
height*/
|
||||
WGL_LABEL_LONG_DOT, /**< Keep the size and write dots at the end if the text is too long*/
|
||||
WGL_LABEL_LONG_SROLL, /**< Keep the size and roll the text back and forth*/
|
||||
WGL_LABEL_LONG_SROLL_CIRC, /**< Keep the size and roll the text circularly*/
|
||||
WGL_LABEL_LONG_CROP, /**< Keep the size and crop the text out of it*/
|
||||
};
|
||||
typedef uint8_t wgl_label_long_mode_t;
|
||||
|
||||
/** Label align policy*/
|
||||
enum {
|
||||
WGL_LABEL_ALIGN_LEFT, /**< Align text to left */
|
||||
WGL_LABEL_ALIGN_CENTER, /**< Align text to center */
|
||||
WGL_LABEL_ALIGN_RIGHT, /**< Align text to right */
|
||||
};
|
||||
typedef uint8_t wgl_label_align_t;
|
||||
|
||||
/** Label styles*/
|
||||
enum {
|
||||
WGL_LABEL_STYLE_MAIN,
|
||||
};
|
||||
typedef uint8_t wgl_label_style_t;
|
||||
|
||||
/* Create a label */
|
||||
wgl_obj_t wgl_label_create(wgl_obj_t par, wgl_obj_t copy);
|
||||
|
||||
/* Set text for the label */
|
||||
void wgl_label_set_text(wgl_obj_t label, const char * text);
|
||||
|
||||
/**
|
||||
* Get the length of the text of a label
|
||||
* @param label the label object
|
||||
* @return the length of the text of the label
|
||||
*/
|
||||
unsigned int wgl_label_get_text_length(wgl_obj_t label);
|
||||
|
||||
/**
|
||||
* Get the text of a label
|
||||
* @param label the label object
|
||||
* @param buffer buffer to save the text
|
||||
* @param buffer_len length of the buffer
|
||||
* @return the text of the label, note that the text will be truncated if buffer is not long enough
|
||||
*/
|
||||
char *wgl_label_get_text(wgl_obj_t label, char *buffer, int buffer_len);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* WAMR_GRAPHIC_LIBRARY_LABEL_H */
|
||||
54
core/app-framework/wgl/app/wa-inc/inc/wgl_list.h
Normal file
54
core/app-framework/wgl/app/wa-inc/inc/wgl_list.h
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#ifndef WAMR_GRAPHIC_LIBRARY_LIST_H
|
||||
#define WAMR_GRAPHIC_LIBRARY_LIST_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** List styles. */
|
||||
enum {
|
||||
WGL_LIST_STYLE_BG, /**< List background style */
|
||||
WGL_LIST_STYLE_SCRL, /**< List scrollable area style. */
|
||||
WGL_LIST_STYLE_SB, /**< List scrollbar style. */
|
||||
WGL_LIST_STYLE_EDGE_FLASH, /**< List edge flash style. */
|
||||
WGL_LIST_STYLE_BTN_REL, /**< Same meaning as the ordinary button styles. */
|
||||
WGL_LIST_STYLE_BTN_PR,
|
||||
WGL_LIST_STYLE_BTN_TGL_REL,
|
||||
WGL_LIST_STYLE_BTN_TGL_PR,
|
||||
WGL_LIST_STYLE_BTN_INA,
|
||||
};
|
||||
typedef uint8_t wgl_list_style_t;
|
||||
|
||||
|
||||
/**
|
||||
* Create a list objects
|
||||
* @param par pointer to an object, it will be the parent of the new list
|
||||
* @param copy pointer to a list object, if not NULL then the new object will be copied from it
|
||||
* @return pointer to the created list
|
||||
*/
|
||||
wgl_obj_t wgl_list_create(wgl_obj_t par, wgl_obj_t copy);
|
||||
|
||||
|
||||
/*======================
|
||||
* Add/remove functions
|
||||
*=====================*/
|
||||
|
||||
/**
|
||||
* Add a list element to the list
|
||||
* @param list pointer to list object
|
||||
* @param img_fn file name of an image before the text (NULL if unused)
|
||||
* @param txt text of the list element (NULL if unused)
|
||||
* @return pointer to the new list element which can be customized (a button)
|
||||
*/
|
||||
wgl_obj_t wgl_list_add_btn(wgl_obj_t list, const void * img_src, const char * txt);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* WAMR_GRAPHIC_LIBRARY_LIST_H */
|
||||
90
core/app-framework/wgl/app/wa-inc/inc/wgl_obj.h
Normal file
90
core/app-framework/wgl/app/wa-inc/inc/wgl_obj.h
Normal file
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#ifndef WAMR_GRAPHIC_LIBRARY_OBJ_H
|
||||
#define WAMR_GRAPHIC_LIBRARY_OBJ_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef void * wgl_obj_t;
|
||||
|
||||
enum {
|
||||
WGL_EVENT_PRESSED, /**< The object has been pressed*/
|
||||
WGL_EVENT_PRESSING, /**< The object is being pressed (called continuously while pressing)*/
|
||||
WGL_EVENT_PRESS_LOST, /**< User is still pressing but slid cursor/finger off of the object */
|
||||
WGL_EVENT_SHORT_CLICKED, /**< User pressed object for a short period of time, then released it. Not called if dragged. */
|
||||
WGL_EVENT_LONG_PRESSED, /**< Object has been pressed for at least `WGL_INDEV_LONG_PRESS_TIME`. Not called if dragged.*/
|
||||
WGL_EVENT_LONG_PRESSED_REPEAT, /**< Called after `WGL_INDEV_LONG_PRESS_TIME` in every
|
||||
`WGL_INDEV_LONG_PRESS_REP_TIME` ms. Not called if dragged.*/
|
||||
WGL_EVENT_CLICKED, /**< Called on release if not dragged (regardless to long press)*/
|
||||
WGL_EVENT_RELEASED, /**< Called in every cases when the object has been released*/
|
||||
WGL_EVENT_DRAG_BEGIN,
|
||||
WGL_EVENT_DRAG_END,
|
||||
WGL_EVENT_DRAG_THROW_BEGIN,
|
||||
WGL_EVENT_KEY,
|
||||
WGL_EVENT_FOCUSED,
|
||||
WGL_EVENT_DEFOCUSED,
|
||||
WGL_EVENT_VALUE_CHANGED, /**< The object's value has changed (i.e. slider moved) */
|
||||
WGL_EVENT_INSERT,
|
||||
WGL_EVENT_REFRESH,
|
||||
WGL_EVENT_APPLY, /**< "Ok", "Apply" or similar specific button has clicked*/
|
||||
WGL_EVENT_CANCEL, /**< "Close", "Cancel" or similar specific button has clicked*/
|
||||
WGL_EVENT_DELETE, /**< Object is being deleted */
|
||||
};
|
||||
typedef uint8_t wgl_event_t; /**< Type of event being sent to the object. */
|
||||
|
||||
|
||||
/** Object alignment. */
|
||||
enum {
|
||||
WGL_ALIGN_CENTER = 0,
|
||||
WGL_ALIGN_IN_TOP_LEFT,
|
||||
WGL_ALIGN_IN_TOP_MID,
|
||||
WGL_ALIGN_IN_TOP_RIGHT,
|
||||
WGL_ALIGN_IN_BOTTOM_LEFT,
|
||||
WGL_ALIGN_IN_BOTTOM_MID,
|
||||
WGL_ALIGN_IN_BOTTOM_RIGHT,
|
||||
WGL_ALIGN_IN_LEFT_MID,
|
||||
WGL_ALIGN_IN_RIGHT_MID,
|
||||
WGL_ALIGN_OUT_TOP_LEFT,
|
||||
WGL_ALIGN_OUT_TOP_MID,
|
||||
WGL_ALIGN_OUT_TOP_RIGHT,
|
||||
WGL_ALIGN_OUT_BOTTOM_LEFT,
|
||||
WGL_ALIGN_OUT_BOTTOM_MID,
|
||||
WGL_ALIGN_OUT_BOTTOM_RIGHT,
|
||||
WGL_ALIGN_OUT_LEFT_TOP,
|
||||
WGL_ALIGN_OUT_LEFT_MID,
|
||||
WGL_ALIGN_OUT_LEFT_BOTTOM,
|
||||
WGL_ALIGN_OUT_RIGHT_TOP,
|
||||
WGL_ALIGN_OUT_RIGHT_MID,
|
||||
WGL_ALIGN_OUT_RIGHT_BOTTOM,
|
||||
};
|
||||
typedef uint8_t wgl_align_t;
|
||||
|
||||
|
||||
enum {
|
||||
WGL_DRAG_DIR_HOR = 0x1, /**< Object can be dragged horizontally. */
|
||||
WGL_DRAG_DIR_VER = 0x2, /**< Object can be dragged vertically. */
|
||||
WGL_DRAG_DIR_ALL = 0x3, /**< Object can be dragged in all directions. */
|
||||
};
|
||||
|
||||
typedef uint8_t wgl_drag_dir_t;
|
||||
|
||||
typedef void (*wgl_event_cb_t)(wgl_obj_t obj, wgl_event_t event);
|
||||
|
||||
void wgl_obj_align(wgl_obj_t obj, wgl_obj_t base, wgl_align_t align, wgl_coord_t x_mod, wgl_coord_t y_mod);
|
||||
void wgl_obj_set_event_cb(wgl_obj_t obj, wgl_event_cb_t event_cb);
|
||||
wgl_res_t wgl_obj_del(wgl_obj_t obj);
|
||||
void wgl_obj_del_async(wgl_obj_t obj);
|
||||
void wgl_obj_clean(wgl_obj_t obj);
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* WAMR_GRAPHIC_LIBRARY_OBJ_H */
|
||||
29
core/app-framework/wgl/app/wa-inc/inc/wgl_types.h
Normal file
29
core/app-framework/wgl/app/wa-inc/inc/wgl_types.h
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#ifndef WAMR_GRAPHIC_LIBRARY_TYPES_H
|
||||
#define WAMR_GRAPHIC_LIBRARY_TYPES_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* WGL error codes.
|
||||
*/
|
||||
enum {
|
||||
WGL_RES_INV = 0, /*Typically indicates that the object is deleted (become invalid) in the action
|
||||
function or an operation was failed*/
|
||||
WGL_RES_OK, /*The object is valid (no deleted) after the action*/
|
||||
};
|
||||
typedef uint8_t wgl_res_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* WAMR_GRAPHIC_LIBRARY_TYPES_H */
|
||||
@ -0,0 +1,8 @@
|
||||
MIT licence
|
||||
Copyright (c) 2016 Gábor Kiss-Vámosi
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
75
core/app-framework/wgl/app/wa-inc/lvgl-compatible/lv_btn.h
Normal file
75
core/app-framework/wgl/app/wa-inc/lvgl-compatible/lv_btn.h
Normal file
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#ifndef WAMR_GRAPHIC_LIBRARY_BTN_LVGL_COMPATIBLE_H
|
||||
#define WAMR_GRAPHIC_LIBRARY_BTN_LVGL_COMPATIBLE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../inc/wgl_btn.h"
|
||||
|
||||
/** Possible states of a button.
|
||||
* It can be used not only by buttons but other button-like objects too*/
|
||||
enum {
|
||||
/**Released*/
|
||||
LV_BTN_STATE_REL,
|
||||
|
||||
/**Pressed*/
|
||||
LV_BTN_STATE_PR,
|
||||
|
||||
/**Toggled released*/
|
||||
LV_BTN_STATE_TGL_REL,
|
||||
|
||||
/**Toggled pressed*/
|
||||
LV_BTN_STATE_TGL_PR,
|
||||
|
||||
/**Inactive*/
|
||||
LV_BTN_STATE_INA,
|
||||
|
||||
/**Number of states*/
|
||||
_LV_BTN_STATE_NUM,
|
||||
};
|
||||
typedef wgl_btn_state_t lv_btn_state_t;
|
||||
|
||||
/**Styles*/
|
||||
enum {
|
||||
/** Release style */
|
||||
LV_BTN_STYLE_REL,
|
||||
|
||||
/**Pressed style*/
|
||||
LV_BTN_STYLE_PR,
|
||||
|
||||
/** Toggle released style*/
|
||||
LV_BTN_STYLE_TGL_REL,
|
||||
|
||||
/** Toggle pressed style */
|
||||
LV_BTN_STYLE_TGL_PR,
|
||||
|
||||
/** Inactive style*/
|
||||
LV_BTN_STYLE_INA,
|
||||
};
|
||||
typedef wgl_btn_style_t lv_btn_style_t;
|
||||
|
||||
|
||||
#define lv_btn_create wgl_btn_create
|
||||
#define lv_btn_set_toggle wgl_btn_set_toggle
|
||||
#define lv_btn_set_state wgl_btn_set_state
|
||||
#define lv_btn_toggle wgl_btn_toggle
|
||||
#define lv_btn_set_ink_in_time wgl_btn_set_ink_in_time
|
||||
#define lv_btn_set_ink_wait_time wgl_btn_set_ink_wait_time
|
||||
#define lv_btn_set_ink_out_time wgl_btn_set_ink_out_time
|
||||
#define lv_btn_get_state wgl_btn_get_state
|
||||
#define lv_btn_get_toggle wgl_btn_get_toggle
|
||||
#define lv_btn_get_ink_in_time wgl_btn_get_ink_in_time
|
||||
#define lv_btn_get_ink_wait_time wgl_btn_get_ink_wait_time
|
||||
#define lv_btn_get_ink_out_time wgl_btn_get_ink_out_time
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* WAMR_GRAPHIC_LIBRARY_BTN_LVGL_COMPATIBLE_H */
|
||||
36
core/app-framework/wgl/app/wa-inc/lvgl-compatible/lv_cb.h
Normal file
36
core/app-framework/wgl/app/wa-inc/lvgl-compatible/lv_cb.h
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#ifndef WAMR_GRAPHIC_LIBRARY_CB_LVGL_COMPATIBLE_H
|
||||
#define WAMR_GRAPHIC_LIBRARY_CB_LVGL_COMPATIBLE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../inc/wgl_cb.h"
|
||||
|
||||
/** Checkbox styles. */
|
||||
enum {
|
||||
LV_CB_STYLE_BG, /**< Style of object background. */
|
||||
LV_CB_STYLE_BOX_REL, /**< Style of box (released). */
|
||||
LV_CB_STYLE_BOX_PR, /**< Style of box (pressed). */
|
||||
LV_CB_STYLE_BOX_TGL_REL, /**< Style of box (released but checked). */
|
||||
LV_CB_STYLE_BOX_TGL_PR, /**< Style of box (pressed and checked). */
|
||||
LV_CB_STYLE_BOX_INA, /**< Style of disabled box */
|
||||
};
|
||||
typedef wgl_cb_style_t lv_cb_style_t;
|
||||
|
||||
|
||||
#define lv_cb_create wgl_cb_create
|
||||
#define lv_cb_set_text wgl_cb_set_text
|
||||
#define lv_cb_set_static_text wgl_cb_set_static_text
|
||||
#define lv_cb_get_text(cb) wgl_cb_get_text(cb, g_widget_text, 100)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* WAMR_GRAPHIC_LIBRARY_CB_LVGL_COMPATIBLE_H */
|
||||
50
core/app-framework/wgl/app/wa-inc/lvgl-compatible/lv_label.h
Normal file
50
core/app-framework/wgl/app/wa-inc/lvgl-compatible/lv_label.h
Normal file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#ifndef WAMR_GRAPHIC_LIBRARY_LABEL_LVGL_COMPATIBLE_H
|
||||
#define WAMR_GRAPHIC_LIBRARY_LABEL_LVGL_COMPATIBLE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../inc/wgl_label.h"
|
||||
|
||||
/** Long mode behaviors. Used in 'lv_label_ext_t' */
|
||||
enum {
|
||||
LV_LABEL_LONG_EXPAND, /**< Expand the object size to the text size*/
|
||||
LV_LABEL_LONG_BREAK, /**< Keep the object width, break the too long lines and expand the object
|
||||
height*/
|
||||
LV_LABEL_LONG_DOT, /**< Keep the size and write dots at the end if the text is too long*/
|
||||
LV_LABEL_LONG_SROLL, /**< Keep the size and roll the text back and forth*/
|
||||
LV_LABEL_LONG_SROLL_CIRC, /**< Keep the size and roll the text circularly*/
|
||||
LV_LABEL_LONG_CROP, /**< Keep the size and crop the text out of it*/
|
||||
};
|
||||
typedef wgl_label_long_mode_t lv_label_long_mode_t;
|
||||
|
||||
/** Label align policy*/
|
||||
enum {
|
||||
LV_LABEL_ALIGN_LEFT, /**< Align text to left */
|
||||
LV_LABEL_ALIGN_CENTER, /**< Align text to center */
|
||||
LV_LABEL_ALIGN_RIGHT, /**< Align text to right */
|
||||
};
|
||||
typedef wgl_label_align_t lv_label_align_t;
|
||||
|
||||
/** Label styles*/
|
||||
enum {
|
||||
LV_LABEL_STYLE_MAIN,
|
||||
};
|
||||
typedef wgl_label_style_t lv_label_style_t;
|
||||
|
||||
|
||||
#define lv_label_create wgl_label_create
|
||||
#define lv_label_set_text wgl_label_set_text
|
||||
#define lv_label_get_text(label) wgl_label_get_text(label, g_widget_text, 100)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* WAMR_GRAPHIC_LIBRARY_LABEL_LVGL_COMPATIBLE_H */
|
||||
37
core/app-framework/wgl/app/wa-inc/lvgl-compatible/lv_list.h
Normal file
37
core/app-framework/wgl/app/wa-inc/lvgl-compatible/lv_list.h
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#ifndef WAMR_GRAPHIC_LIBRARY_LIST_LVGL_COMPATIBLE_H
|
||||
#define WAMR_GRAPHIC_LIBRARY_LIST_LVGL_COMPATIBLE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../inc/wgl_list.h"
|
||||
|
||||
/** List styles. */
|
||||
enum {
|
||||
LV_LIST_STYLE_BG, /**< List background style */
|
||||
LV_LIST_STYLE_SCRL, /**< List scrollable area style. */
|
||||
LV_LIST_STYLE_SB, /**< List scrollbar style. */
|
||||
LV_LIST_STYLE_EDGE_FLASH, /**< List edge flash style. */
|
||||
LV_LIST_STYLE_BTN_REL, /**< Same meaning as the ordinary button styles. */
|
||||
LV_LIST_STYLE_BTN_PR,
|
||||
LV_LIST_STYLE_BTN_TGL_REL,
|
||||
LV_LIST_STYLE_BTN_TGL_PR,
|
||||
LV_LIST_STYLE_BTN_INA,
|
||||
};
|
||||
typedef wgl_list_style_t lv_list_style_t;
|
||||
|
||||
|
||||
#define lv_list_create wgl_list_create
|
||||
#define lv_list_add_btn wgl_list_add_btn
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* WAMR_GRAPHIC_LIBRARY_LIST_LVGL_COMPATIBLE_H */
|
||||
89
core/app-framework/wgl/app/wa-inc/lvgl-compatible/lv_obj.h
Normal file
89
core/app-framework/wgl/app/wa-inc/lvgl-compatible/lv_obj.h
Normal file
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#ifndef WAMR_GRAPHIC_LIBRARY_OBJ_LVGL_COMPATIBLE_H
|
||||
#define WAMR_GRAPHIC_LIBRARY_OBJ_LVGL_COMPATIBLE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../inc/wgl_obj.h"
|
||||
|
||||
typedef void lv_obj_t;
|
||||
|
||||
enum {
|
||||
LV_EVENT_PRESSED,
|
||||
LV_EVENT_PRESSING,
|
||||
LV_EVENT_PRESS_LOST,
|
||||
LV_EVENT_SHORT_CLICKED,
|
||||
LV_EVENT_LONG_PRESSED,
|
||||
LV_EVENT_LONG_PRESSED_REPEAT,
|
||||
LV_EVENT_CLICKED,
|
||||
LV_EVENT_RELEASED,
|
||||
LV_EVENT_DRAG_BEGIN,
|
||||
LV_EVENT_DRAG_END,
|
||||
LV_EVENT_DRAG_THROW_BEGIN,
|
||||
LV_EVENT_KEY,
|
||||
LV_EVENT_FOCUSED,
|
||||
LV_EVENT_DEFOCUSED,
|
||||
LV_EVENT_VALUE_CHANGED,
|
||||
LV_EVENT_INSERT,
|
||||
LV_EVENT_REFRESH,
|
||||
LV_EVENT_APPLY,
|
||||
LV_EVENT_CANCEL,
|
||||
LV_EVENT_DELETE,
|
||||
};
|
||||
typedef wgl_event_t lv_event_t;
|
||||
|
||||
|
||||
/** Object alignment. */
|
||||
enum {
|
||||
LV_ALIGN_CENTER,
|
||||
LV_ALIGN_IN_TOP_LEFT,
|
||||
LV_ALIGN_IN_TOP_MID,
|
||||
LV_ALIGN_IN_TOP_RIGHT,
|
||||
LV_ALIGN_IN_BOTTOM_LEFT,
|
||||
LV_ALIGN_IN_BOTTOM_MID,
|
||||
LV_ALIGN_IN_BOTTOM_RIGHT,
|
||||
LV_ALIGN_IN_LEFT_MID,
|
||||
LV_ALIGN_IN_RIGHT_MID,
|
||||
LV_ALIGN_OUT_TOP_LEFT,
|
||||
LV_ALIGN_OUT_TOP_MID,
|
||||
LV_ALIGN_OUT_TOP_RIGHT,
|
||||
LV_ALIGN_OUT_BOTTOM_LEFT,
|
||||
LV_ALIGN_OUT_BOTTOM_MID,
|
||||
LV_ALIGN_OUT_BOTTOM_RIGHT,
|
||||
LV_ALIGN_OUT_LEFT_TOP,
|
||||
LV_ALIGN_OUT_LEFT_MID,
|
||||
LV_ALIGN_OUT_LEFT_BOTTOM,
|
||||
LV_ALIGN_OUT_RIGHT_TOP,
|
||||
LV_ALIGN_OUT_RIGHT_MID,
|
||||
LV_ALIGN_OUT_RIGHT_BOTTOM,
|
||||
};
|
||||
typedef wgl_align_t lv_align_t;
|
||||
|
||||
|
||||
enum {
|
||||
LV_DRAG_DIR_HOR,
|
||||
LV_DRAG_DIR_VER,
|
||||
LV_DRAG_DIR_ALL,
|
||||
};
|
||||
|
||||
typedef wgl_drag_dir_t lv_drag_dir_t;
|
||||
|
||||
|
||||
#define lv_obj_align wgl_obj_align
|
||||
#define lv_obj_set_event_cb wgl_obj_set_event_cb
|
||||
#define lv_obj_del wgl_obj_del
|
||||
#define lv_obj_del_async wgl_obj_del_async
|
||||
#define lv_obj_clean wgl_obj_clean
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* WAMR_GRAPHIC_LIBRARY_OBJ_LVGL_COMPATIBLE_H */
|
||||
28
core/app-framework/wgl/app/wa-inc/lvgl-compatible/lv_types.h
Normal file
28
core/app-framework/wgl/app/wa-inc/lvgl-compatible/lv_types.h
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#ifndef WAMR_GRAPHIC_LIBRARY_TYPES_LVGL_COMPATIBLE_H
|
||||
#define WAMR_GRAPHIC_LIBRARY_TYPES_LVGL_COMPATIBLE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../inc/wgl_types.h"
|
||||
|
||||
/**
|
||||
* error codes.
|
||||
*/
|
||||
enum {
|
||||
LV_RES_INV,
|
||||
LV_RES_OK,
|
||||
};
|
||||
typedef wgl_res_t lv_res_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* WAMR_GRAPHIC_LIBRARY_TYPES_LVGL_COMPATIBLE_H */
|
||||
26
core/app-framework/wgl/app/wa-inc/lvgl.h
Normal file
26
core/app-framework/wgl/app/wa-inc/lvgl.h
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#ifndef WAMR_GRAPHIC_LIBRARY_LVGL_COMPATIBLE_H
|
||||
#define WAMR_GRAPHIC_LIBRARY_LVGL_COMPATIBLE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "bi-inc/wgl_shared_utils.h" /* shared types between app and native */
|
||||
#include "lvgl-compatible/lv_types.h"
|
||||
#include "lvgl-compatible/lv_obj.h"
|
||||
#include "lvgl-compatible/lv_btn.h"
|
||||
#include "lvgl-compatible/lv_cb.h"
|
||||
#include "lvgl-compatible/lv_label.h"
|
||||
#include "lvgl-compatible/lv_list.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* WAMR_GRAPHIC_LIBRARY_LVGL_COMPATIBLE_H */
|
||||
26
core/app-framework/wgl/app/wa-inc/wgl.h
Normal file
26
core/app-framework/wgl/app/wa-inc/wgl.h
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#ifndef WAMR_GRAPHIC_LIBRARY_H
|
||||
#define WAMR_GRAPHIC_LIBRARY_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "bi-inc/wgl_shared_utils.h" /* shared types between app and native */
|
||||
|
||||
#include "inc/wgl_types.h"
|
||||
#include "inc/wgl_obj.h"
|
||||
#include "inc/wgl_btn.h"
|
||||
#include "inc/wgl_cb.h"
|
||||
#include "inc/wgl_label.h"
|
||||
#include "inc/wgl_list.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* WAMR_GRAPHIC_LIBRARY_H */
|
||||
15
core/app-framework/wgl/app/wasm_app.cmake
Normal file
15
core/app-framework/wgl/app/wasm_app.cmake
Normal file
@ -0,0 +1,15 @@
|
||||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
set (WASM_APP_GUI_DIR ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
set (DEPS_DIR ${WASM_APP_GUI_DIR}/../../../deps)
|
||||
|
||||
include_directories(${WASM_APP_GUI_DIR}
|
||||
${DEPS_DIR}
|
||||
${DEPS_DIR}/lvgl
|
||||
${DEPS_DIR}/lvgl/src)
|
||||
|
||||
file (GLOB_RECURSE source_all ${WASM_APP_GUI_DIR}/src/*.c)
|
||||
|
||||
set (WASM_APP_CURRENT_SOURCE ${source_all})
|
||||
36
core/app-framework/wgl/native/gui_api.h
Normal file
36
core/app-framework/wgl/native/gui_api.h
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#ifndef _GUI_API_H_
|
||||
#define _GUI_API_H_
|
||||
|
||||
#include "bh_platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void
|
||||
wasm_obj_native_call(int32 func_id, int32 argv_offset, uint32 argc);
|
||||
|
||||
void
|
||||
wasm_btn_native_call(int32 func_id, int32 argv_offset, uint32 argc);
|
||||
|
||||
void
|
||||
wasm_label_native_call(int32 func_id, int32 argv_offset, uint32 argc);
|
||||
|
||||
void
|
||||
wasm_cb_native_call(int32 func_id, int32 argv_offset, uint32 argc);
|
||||
|
||||
void
|
||||
wasm_list_native_call(int32 func_id, int32 argv_offset, uint32 argc);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* end of _GUI_API_H_ */
|
||||
28
core/app-framework/wgl/native/wamr_gui.inl
Normal file
28
core/app-framework/wgl/native/wamr_gui.inl
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
/* button */
|
||||
EXPORT_WASM_API(wasm_btn_native_call),
|
||||
|
||||
/* obj */
|
||||
EXPORT_WASM_API(wasm_obj_native_call),
|
||||
|
||||
/* label */
|
||||
EXPORT_WASM_API(wasm_label_native_call),
|
||||
|
||||
/* cont */
|
||||
//EXPORT_WASM_API(wasm_cont_native_call),
|
||||
|
||||
/* page */
|
||||
//EXPORT_WASM_API(wasm_page_native_call),
|
||||
|
||||
/* list */
|
||||
EXPORT_WASM_API(wasm_list_native_call),
|
||||
|
||||
/* drop down list */
|
||||
//EXPORT_WASM_API(wasm_ddlist_native_call),
|
||||
|
||||
/* check box */
|
||||
EXPORT_WASM_API(wasm_cb_native_call),
|
||||
18
core/app-framework/wgl/native/wasm_lib.cmake
Normal file
18
core/app-framework/wgl/native/wasm_lib.cmake
Normal file
@ -0,0 +1,18 @@
|
||||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
set (WASM_LIB_GUI_DIR ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
set (DEPS_DIR ${WASM_LIB_GUI_DIR}/../../../deps)
|
||||
|
||||
add_definitions(-DLV_CONF_INCLUDE_SIMPLE)
|
||||
|
||||
include_directories(${WASM_LIB_GUI_DIR}
|
||||
${DEPS_DIR}
|
||||
${DEPS_DIR}/lvgl
|
||||
${DEPS_DIR}/lvgl/src)
|
||||
|
||||
file (GLOB_RECURSE lvgl_source ${DEPS_DIR}/lvgl/*.c)
|
||||
file (GLOB_RECURSE wrapper_source ${WASM_LIB_GUI_DIR}/*.c)
|
||||
|
||||
set (WASM_APP_LIB_CURRENT_SOURCE ${wrapper_source} ${lvgl_source})
|
||||
20
core/app-framework/wgl/native/wgl.h
Normal file
20
core/app-framework/wgl/native/wgl.h
Normal file
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#ifndef WAMR_GRAPHIC_LIBRARY_H
|
||||
#define WAMR_GRAPHIC_LIBRARY_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void wgl_init(void);
|
||||
void wgl_exit(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* WAMR_GRAPHIC_LIBRARY_H */
|
||||
140
core/app-framework/wgl/native/wgl_btn_wrapper.c
Normal file
140
core/app-framework/wgl/native/wgl_btn_wrapper.c
Normal file
@ -0,0 +1,140 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#include "native_interface.h"
|
||||
#include "lvgl.h"
|
||||
#include "module_wasm_app.h"
|
||||
#include "wgl_native_utils.h"
|
||||
|
||||
/* -------------------------------------------------------------------------
|
||||
* Button widget native function wrappers
|
||||
* -------------------------------------------------------------------------*/
|
||||
static int32
|
||||
lv_btn_create_wrapper(wasm_module_inst_t module_inst,
|
||||
lv_obj_t *par, lv_obj_t *copy)
|
||||
{
|
||||
return wgl_native_wigdet_create(WIDGET_TYPE_BTN, par, copy, module_inst);
|
||||
}
|
||||
|
||||
static void
|
||||
lv_btn_set_toggle_wrapper(wasm_module_inst_t module_inst,
|
||||
lv_obj_t * btn, bool tgl)
|
||||
{
|
||||
(void)module_inst;
|
||||
lv_btn_set_toggle(btn, tgl);
|
||||
}
|
||||
|
||||
static void
|
||||
lv_btn_set_state_wrapper(wasm_module_inst_t module_inst,
|
||||
lv_obj_t * btn, lv_btn_state_t state)
|
||||
{
|
||||
(void)module_inst;
|
||||
lv_btn_set_state(btn, state);
|
||||
}
|
||||
|
||||
static void
|
||||
lv_btn_set_ink_in_time_wrapper(wasm_module_inst_t module_inst,
|
||||
lv_obj_t * btn, uint16_t time)
|
||||
{
|
||||
(void)module_inst;
|
||||
lv_btn_set_ink_in_time(btn, time);
|
||||
}
|
||||
|
||||
static void
|
||||
lv_btn_set_ink_out_time_wrapper(wasm_module_inst_t module_inst,
|
||||
lv_obj_t * btn, uint16_t time)
|
||||
{
|
||||
(void)module_inst;
|
||||
lv_btn_set_ink_out_time(btn, time);
|
||||
}
|
||||
|
||||
static void
|
||||
lv_btn_set_ink_wait_time_wrapper(wasm_module_inst_t module_inst,
|
||||
lv_obj_t * btn, uint16_t time)
|
||||
{
|
||||
(void)module_inst;
|
||||
lv_btn_set_ink_wait_time(btn, time);
|
||||
}
|
||||
|
||||
static uint16_t
|
||||
lv_btn_get_ink_in_time_wrapper(wasm_module_inst_t module_inst,
|
||||
lv_obj_t * btn)
|
||||
{
|
||||
(void)module_inst;
|
||||
return lv_btn_get_ink_in_time(btn);
|
||||
}
|
||||
|
||||
static uint16_t
|
||||
lv_btn_get_ink_out_time_wrapper(wasm_module_inst_t module_inst,
|
||||
lv_obj_t * btn)
|
||||
{
|
||||
(void)module_inst;
|
||||
return lv_btn_get_ink_out_time(btn);
|
||||
}
|
||||
|
||||
static uint16_t
|
||||
lv_btn_get_ink_wait_time_wrapper(wasm_module_inst_t module_inst,
|
||||
lv_obj_t * btn)
|
||||
{
|
||||
(void)module_inst;
|
||||
return lv_btn_get_ink_wait_time(btn);
|
||||
}
|
||||
|
||||
static lv_btn_state_t
|
||||
lv_btn_get_state_wrapper(wasm_module_inst_t module_inst,
|
||||
lv_obj_t * btn)
|
||||
{
|
||||
(void)module_inst;
|
||||
return lv_btn_get_state(btn);
|
||||
}
|
||||
|
||||
static bool
|
||||
lv_btn_get_toggle_wrapper(wasm_module_inst_t module_inst,
|
||||
lv_obj_t * btn)
|
||||
{
|
||||
(void)module_inst;
|
||||
return lv_btn_get_toggle(btn);
|
||||
}
|
||||
|
||||
static void
|
||||
lv_btn_toggle_wrapper(wasm_module_inst_t module_inst,
|
||||
lv_obj_t * btn)
|
||||
{
|
||||
(void)module_inst;
|
||||
lv_btn_toggle(btn);
|
||||
}
|
||||
|
||||
static WGLNativeFuncDef btn_native_func_defs[] = {
|
||||
{ BTN_FUNC_ID_CREATE, lv_btn_create_wrapper, HAS_RET, 3, {1 | NULL_OK, 2 | NULL_OK, -1}, {-1} },
|
||||
{ BTN_FUNC_ID_SET_TOGGLE, lv_btn_set_toggle_wrapper, NO_RET, 3, {1, -1}, {-1} },
|
||||
{ BTN_FUNC_ID_SET_STATE, lv_btn_set_state_wrapper, NO_RET, 3, {1, -1}, {-1} },
|
||||
// { BTN_FUNC_ID_SET_STYLE, _btn_set_style, NO_RET, 2, {0, -1}, {-1} },
|
||||
{ BTN_FUNC_ID_SET_INK_IN_TIME, lv_btn_set_ink_in_time_wrapper, NO_RET, 3, {1, -1}, {-1} },
|
||||
{ BTN_FUNC_ID_SET_INK_OUT_TIME, lv_btn_set_ink_out_time_wrapper, NO_RET, 3, {1, -1}, {-1} },
|
||||
{ BTN_FUNC_ID_SET_INK_WAIT_TIME, lv_btn_set_ink_wait_time_wrapper, NO_RET, 3, {1, -1}, {-1} },
|
||||
{ BTN_FUNC_ID_GET_INK_IN_TIME, lv_btn_get_ink_in_time_wrapper, HAS_RET, 2, {1, -1}, {-1} },
|
||||
{ BTN_FUNC_ID_GET_INK_OUT_TIME, lv_btn_get_ink_out_time_wrapper, HAS_RET, 2, {1, -1}, {-1} },
|
||||
{ BTN_FUNC_ID_GET_INK_WAIT_TIME, lv_btn_get_ink_wait_time_wrapper, HAS_RET, 2, {1, -1}, {-1} },
|
||||
{ BTN_FUNC_ID_GET_STATE, lv_btn_get_state_wrapper, HAS_RET, 2, {1, -1}, {-1} },
|
||||
{ BTN_FUNC_ID_GET_TOGGLE, lv_btn_get_toggle_wrapper, HAS_RET, 2, {1, -1}, {-1} },
|
||||
{ BTN_FUNC_ID_TOGGLE, lv_btn_toggle_wrapper, NO_RET, 2, {1, -1}, {-1} },
|
||||
|
||||
};
|
||||
|
||||
/*************** Native Interface to Wasm App ***********/
|
||||
void
|
||||
wasm_btn_native_call(wasm_exec_env_t exec_env,
|
||||
int32 func_id, uint32 argv_offset, uint32 argc)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uint32 size = sizeof(btn_native_func_defs) / sizeof(WGLNativeFuncDef);
|
||||
|
||||
wgl_native_func_call(module_inst,
|
||||
btn_native_func_defs,
|
||||
size,
|
||||
func_id,
|
||||
argv_offset,
|
||||
argc);
|
||||
}
|
||||
87
core/app-framework/wgl/native/wgl_cb_wrapper.c
Normal file
87
core/app-framework/wgl/native/wgl_cb_wrapper.c
Normal file
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#include "lvgl.h"
|
||||
#include "wasm_export.h"
|
||||
#include "native_interface.h"
|
||||
#include "module_wasm_app.h"
|
||||
#include "wgl_native_utils.h"
|
||||
|
||||
/* -------------------------------------------------------------------------
|
||||
* Label widget native function wrappers
|
||||
* -------------------------------------------------------------------------*/
|
||||
static int32
|
||||
lv_cb_create_wrapper(wasm_module_inst_t module_inst,
|
||||
lv_obj_t *par, lv_obj_t *copy)
|
||||
{
|
||||
return wgl_native_wigdet_create(WIDGET_TYPE_CB, par, copy, module_inst);
|
||||
}
|
||||
|
||||
static void
|
||||
lv_cb_set_text_wrapper(wasm_module_inst_t module_inst,
|
||||
lv_obj_t * cb, const char * txt)
|
||||
{
|
||||
(void)module_inst;
|
||||
lv_cb_set_text(cb, txt);
|
||||
}
|
||||
|
||||
static void
|
||||
lv_cb_set_static_text_wrapper(wasm_module_inst_t module_inst,
|
||||
lv_obj_t * cb, const char * txt)
|
||||
{
|
||||
(void)module_inst;
|
||||
lv_cb_set_static_text(cb, txt);
|
||||
}
|
||||
|
||||
static int32
|
||||
lv_cb_get_text_length_wrapper(wasm_module_inst_t module_inst,
|
||||
lv_obj_t *cb)
|
||||
{
|
||||
const char *text = lv_cb_get_text(cb);
|
||||
|
||||
if (text == NULL)
|
||||
return 0;
|
||||
|
||||
return strlen(text);
|
||||
}
|
||||
|
||||
static char *
|
||||
lv_cb_get_text_wrapper(wasm_module_inst_t module_inst,
|
||||
lv_obj_t *cb, char *buffer, int buffer_len)
|
||||
{
|
||||
const char *text = lv_cb_get_text(cb);
|
||||
|
||||
if (text == NULL)
|
||||
return 0;
|
||||
|
||||
strncpy(buffer, text, buffer_len - 1);
|
||||
buffer[buffer_len - 1] = '\0';
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
static WGLNativeFuncDef cb_native_func_defs[] = {
|
||||
{ CB_FUNC_ID_CREATE, lv_cb_create_wrapper, HAS_RET, 3, {1 | NULL_OK, 2 | NULL_OK, -1}, {-1} },
|
||||
{ CB_FUNC_ID_SET_TEXT, lv_cb_set_text_wrapper, NO_RET, 3, {1, -1}, {2, -1} },
|
||||
{ CB_FUNC_ID_SET_STATIC_TEXT, lv_cb_set_static_text_wrapper, NO_RET, 3, {1, -1}, {2, -1} },
|
||||
{ CB_FUNC_ID_GET_TEXT_LENGTH, lv_cb_get_text_length_wrapper, HAS_RET, 2, {1, -1}, {-1} },
|
||||
{ CB_FUNC_ID_GET_TEXT, lv_cb_get_text_wrapper, RET_PTR, 4, {1, -1}, {2, -1} },
|
||||
};
|
||||
|
||||
/*************** Native Interface to Wasm App ***********/
|
||||
void
|
||||
wasm_cb_native_call(wasm_exec_env_t exec_env,
|
||||
int32 func_id, uint32 argv_offset, uint32 argc)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uint32 size = sizeof(cb_native_func_defs) / sizeof(WGLNativeFuncDef);
|
||||
|
||||
wgl_native_func_call(module_inst,
|
||||
cb_native_func_defs,
|
||||
size,
|
||||
func_id,
|
||||
argv_offset,
|
||||
argc);
|
||||
}
|
||||
7
core/app-framework/wgl/native/wgl_cont_wrapper.c
Normal file
7
core/app-framework/wgl/native/wgl_cont_wrapper.c
Normal file
@ -0,0 +1,7 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#include "lvgl.h"
|
||||
#include "module_wasm_app.h"
|
||||
78
core/app-framework/wgl/native/wgl_label_wrapper.c
Normal file
78
core/app-framework/wgl/native/wgl_label_wrapper.c
Normal file
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#include "lvgl.h"
|
||||
#include "wasm_export.h"
|
||||
#include "native_interface.h"
|
||||
#include "module_wasm_app.h"
|
||||
#include "wgl_native_utils.h"
|
||||
|
||||
/* -------------------------------------------------------------------------
|
||||
* Label widget native function wrappers
|
||||
* -------------------------------------------------------------------------*/
|
||||
static int32
|
||||
lv_label_create_wrapper(wasm_module_inst_t module_inst,
|
||||
lv_obj_t *par, lv_obj_t *copy)
|
||||
{
|
||||
return wgl_native_wigdet_create(WIDGET_TYPE_LABEL, par, copy, module_inst);
|
||||
}
|
||||
|
||||
static void
|
||||
lv_label_set_text_wrapper(wasm_module_inst_t module_inst,
|
||||
lv_obj_t * label, const char * text)
|
||||
{
|
||||
(void)module_inst;
|
||||
lv_label_set_text(label, text);
|
||||
}
|
||||
|
||||
static int32
|
||||
lv_label_get_text_length_wrapper(wasm_module_inst_t module_inst,
|
||||
lv_obj_t *label)
|
||||
{
|
||||
char *text = lv_label_get_text(label);
|
||||
|
||||
if (text == NULL)
|
||||
return 0;
|
||||
|
||||
return strlen(text);
|
||||
}
|
||||
|
||||
static char *
|
||||
lv_label_get_text_wrapper(wasm_module_inst_t module_inst,
|
||||
lv_obj_t *label, char *buffer, int buffer_len)
|
||||
{
|
||||
char *text = lv_label_get_text(label);
|
||||
|
||||
if (text == NULL)
|
||||
return 0;
|
||||
|
||||
strncpy(buffer, text, buffer_len - 1);
|
||||
buffer[buffer_len - 1] = '\0';
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
static WGLNativeFuncDef label_native_func_defs[] = {
|
||||
{ LABEL_FUNC_ID_CREATE, lv_label_create_wrapper, HAS_RET, 3, {1 | NULL_OK, 2 | NULL_OK, -1}, {-1} },
|
||||
{ LABEL_FUNC_ID_SET_TEXT, lv_label_set_text_wrapper, NO_RET, 3, {1, -1}, {2, -1} },
|
||||
{ LABEL_FUNC_ID_GET_TEXT_LENGTH, lv_label_get_text_length_wrapper, HAS_RET, 2, {1, -1}, {-1} },
|
||||
{ LABEL_FUNC_ID_GET_TEXT, lv_label_get_text_wrapper, RET_PTR, 4, {1, -1}, {2, -1} },
|
||||
};
|
||||
|
||||
/*************** Native Interface to Wasm App ***********/
|
||||
void
|
||||
wasm_label_native_call(wasm_exec_env_t exec_env,
|
||||
int32 func_id, uint32 argv_offset, uint32 argc)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uint32 size = sizeof(label_native_func_defs) / sizeof(WGLNativeFuncDef);
|
||||
|
||||
wgl_native_func_call(module_inst,
|
||||
label_native_func_defs,
|
||||
size,
|
||||
func_id,
|
||||
argv_offset,
|
||||
argc);
|
||||
}
|
||||
63
core/app-framework/wgl/native/wgl_list_wrapper.c
Normal file
63
core/app-framework/wgl/native/wgl_list_wrapper.c
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#include "native_interface.h"
|
||||
#include "lvgl.h"
|
||||
#include "module_wasm_app.h"
|
||||
#include "wgl_native_utils.h"
|
||||
#include "bh_assert.h"
|
||||
|
||||
/* -------------------------------------------------------------------------
|
||||
* List widget native function wrappers
|
||||
* -------------------------------------------------------------------------*/
|
||||
static int32
|
||||
lv_list_create_wrapper(wasm_module_inst_t module_inst,
|
||||
lv_obj_t *par, lv_obj_t *copy)
|
||||
{
|
||||
return wgl_native_wigdet_create(WIDGET_TYPE_LIST, par, copy, module_inst);
|
||||
}
|
||||
|
||||
static int32
|
||||
lv_list_add_btn_wrapper(wasm_module_inst_t module_inst,
|
||||
lv_obj_t *list, const char *text)
|
||||
{
|
||||
uint32 btn_obj_id;
|
||||
lv_obj_t *btn;
|
||||
uint32 mod_id;
|
||||
|
||||
btn = lv_list_add_btn(list, NULL, text);
|
||||
|
||||
if (btn == NULL)
|
||||
return 0;
|
||||
|
||||
mod_id = app_manager_get_module_id(Module_WASM_App, module_inst);
|
||||
bh_assert(mod_id != ID_NONE);
|
||||
|
||||
if (wgl_native_add_object(btn, mod_id, &btn_obj_id))
|
||||
return btn_obj_id; /* success return */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static WGLNativeFuncDef list_native_func_defs[] = {
|
||||
{ LIST_FUNC_ID_CREATE, lv_list_create_wrapper, HAS_RET, 3, {1 | NULL_OK, 2 | NULL_OK, -1}, {-1} },
|
||||
{ LIST_FUNC_ID_ADD_BTN, lv_list_add_btn_wrapper, HAS_RET, 3, {1, -1}, {2, -1} },
|
||||
};
|
||||
|
||||
/*************** Native Interface to Wasm App ***********/
|
||||
void
|
||||
wasm_list_native_call(wasm_exec_env_t exec_env,
|
||||
int32 func_id, uint32 argv_offset, uint32 argc)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uint32 size = sizeof(list_native_func_defs) / sizeof(WGLNativeFuncDef);
|
||||
|
||||
wgl_native_func_call(module_inst,
|
||||
list_native_func_defs,
|
||||
size,
|
||||
func_id,
|
||||
argv_offset,
|
||||
argc);
|
||||
}
|
||||
215
core/app-framework/wgl/native/wgl_native_utils.c
Normal file
215
core/app-framework/wgl/native/wgl_native_utils.c
Normal file
@ -0,0 +1,215 @@
|
||||
|
||||
|
||||
#include "wgl_native_utils.h"
|
||||
#include "lvgl.h"
|
||||
#include "module_wasm_app.h"
|
||||
#include "wasm_export.h"
|
||||
#include "bh_assert.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define THROW_EXC(msg) wasm_runtime_set_exception(module_inst, msg);
|
||||
|
||||
void
|
||||
wasm_runtime_set_exception(wasm_module_inst_t module, const char *exception);
|
||||
|
||||
uint32 wgl_native_wigdet_create(int8 widget_type, lv_obj_t *par, lv_obj_t *copy,
|
||||
wasm_module_inst_t module_inst)
|
||||
{
|
||||
uint32 obj_id;
|
||||
lv_obj_t *wigdet = NULL;
|
||||
uint32 mod_id;
|
||||
|
||||
//TODO: limit total widget number
|
||||
|
||||
if (par == NULL)
|
||||
par = lv_disp_get_scr_act(NULL);
|
||||
|
||||
if (widget_type == WIDGET_TYPE_BTN)
|
||||
wigdet = lv_btn_create(par, copy);
|
||||
else if (widget_type == WIDGET_TYPE_LABEL)
|
||||
wigdet = lv_label_create(par, copy);
|
||||
else if (widget_type == WIDGET_TYPE_CB)
|
||||
wigdet = lv_cb_create(par, copy);
|
||||
else if (widget_type == WIDGET_TYPE_LIST)
|
||||
wigdet = lv_list_create(par, copy);
|
||||
else if (widget_type == WIDGET_TYPE_DDLIST)
|
||||
wigdet = lv_ddlist_create(par, copy);
|
||||
|
||||
if (wigdet == NULL)
|
||||
return 0;
|
||||
|
||||
mod_id = app_manager_get_module_id(Module_WASM_App, module_inst);
|
||||
bh_assert(mod_id != ID_NONE);
|
||||
|
||||
if (wgl_native_add_object(wigdet, mod_id, &obj_id))
|
||||
return obj_id; /* success return */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void invokeNative(intptr_t argv[], uint32 argc, void (*native_code)())
|
||||
{
|
||||
bh_assert(argc >= 1);
|
||||
|
||||
switch(argc) {
|
||||
case 1:
|
||||
native_code(argv[0]);
|
||||
break;
|
||||
case 2:
|
||||
native_code(argv[0], argv[1]);
|
||||
break;
|
||||
case 3:
|
||||
native_code(argv[0], argv[1], argv[2]);
|
||||
break;
|
||||
case 4:
|
||||
native_code(argv[0], argv[1], argv[2], argv[3]);
|
||||
break;
|
||||
case 5:
|
||||
native_code(argv[0], argv[1], argv[2], argv[3], argv[4]);
|
||||
break;
|
||||
case 6:
|
||||
native_code(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]);
|
||||
break;
|
||||
case 7:
|
||||
native_code(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5],
|
||||
argv[6]);
|
||||
break;
|
||||
case 8:
|
||||
native_code(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5],
|
||||
argv[6], argv[7]);
|
||||
break;
|
||||
case 9:
|
||||
native_code(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5],
|
||||
argv[6], argv[7], argv[8]);
|
||||
break;
|
||||
case 10:
|
||||
native_code(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5],
|
||||
argv[6], argv[7], argv[8], argv[9]);
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
/* FIXME: If this happen, add more cases. */
|
||||
wasm_module_inst_t module_inst = (wasm_module_inst_t)argv[0];
|
||||
THROW_EXC("the argument number of native function exceeds maximum");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
typedef void (*GenericFunctionPointer)();
|
||||
typedef int32 (*Int32FuncPtr)(intptr_t *, uint32, GenericFunctionPointer);
|
||||
typedef void (*VoidFuncPtr)(intptr_t *, uint32, GenericFunctionPointer);
|
||||
|
||||
static Int32FuncPtr invokeNative_Int32 = (Int32FuncPtr)invokeNative;
|
||||
static VoidFuncPtr invokeNative_Void = (VoidFuncPtr)invokeNative;
|
||||
|
||||
void wgl_native_func_call(wasm_module_inst_t module_inst,
|
||||
WGLNativeFuncDef *funcs,
|
||||
uint32 size,
|
||||
int32 func_id,
|
||||
uint32 argv_offset,
|
||||
uint32 argc)
|
||||
{
|
||||
WGLNativeFuncDef *func_def = funcs;
|
||||
WGLNativeFuncDef *func_def_end = func_def + size;
|
||||
uint32 *argv;
|
||||
|
||||
if (!validate_app_addr(argv_offset, argc * sizeof(uint32)))
|
||||
return;
|
||||
|
||||
argv = addr_app_to_native(argv_offset);
|
||||
|
||||
while (func_def < func_def_end) {
|
||||
if (func_def->func_id == func_id) {
|
||||
int i, obj_arg_num = 0, ptr_arg_num = 0, argc1 = 0;
|
||||
intptr_t argv_copy_buf[16];
|
||||
intptr_t *argv_copy = argv_copy_buf;
|
||||
|
||||
argc1++; /* module_inst */
|
||||
argc1 += func_def->arg_num;
|
||||
if (argc1 > 16) {
|
||||
argv_copy = (intptr_t *)bh_malloc(func_def->arg_num *
|
||||
sizeof(intptr_t));
|
||||
if (argv_copy == NULL)
|
||||
return;
|
||||
}
|
||||
|
||||
/* Init argv_copy */
|
||||
argv_copy[0] = (intptr_t)module_inst;
|
||||
for (i = 0; i < func_def->arg_num; i++)
|
||||
argv_copy[i + 1] = (intptr_t)argv[i];
|
||||
|
||||
/* Validate object arguments */
|
||||
i = 0;
|
||||
for (; i < OBJ_ARG_NUM_MAX && func_def->obj_arg_indexes[i] != 0xff;
|
||||
i++, obj_arg_num++) {
|
||||
uint8 index = func_def->obj_arg_indexes[i];
|
||||
bool null_ok = index & NULL_OK;
|
||||
|
||||
index = index & (~NULL_OK);
|
||||
|
||||
/* Some API's allow to pass NULL obj, such as xxx_create() */
|
||||
if (argv_copy[index] == 0) {
|
||||
if (!null_ok) {
|
||||
THROW_EXC("the object id is 0 and invalid");
|
||||
goto fail;
|
||||
}
|
||||
/* Continue so that to pass null object validation */
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!wgl_native_validate_object(argv_copy[index],
|
||||
(lv_obj_t **)&argv_copy[index])) {
|
||||
THROW_EXC("the object is invalid");
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
/* Validate address arguments */
|
||||
i = 0;
|
||||
for (; i < PTR_ARG_NUM_MAX && func_def->ptr_arg_indexes[i] != 0xff;
|
||||
i++, ptr_arg_num++) {
|
||||
uint8 index = func_def->ptr_arg_indexes[i];
|
||||
|
||||
/* The index+1 arg is the data size to be validated */
|
||||
if (!validate_app_addr(argv_copy[index], argv_copy[index + 1]))
|
||||
goto fail;
|
||||
|
||||
/* Convert to native address before call lvgl function */
|
||||
argv_copy[index] = (intptr_t)addr_app_to_native(argv_copy[index]);
|
||||
}
|
||||
|
||||
if (func_def->has_ret == NO_RET)
|
||||
invokeNative_Void(argv_copy,
|
||||
argc1,
|
||||
func_def->func_ptr);
|
||||
else {
|
||||
argv[0] = invokeNative_Int32(argv_copy,
|
||||
argc1,
|
||||
func_def->func_ptr);
|
||||
/* Convert to app memory offset if return value is a
|
||||
* native address pointer */
|
||||
if (func_def->has_ret == RET_PTR)
|
||||
argv[0] = addr_native_to_app((char *)(intptr_t)argv[0]);
|
||||
}
|
||||
|
||||
if (argv_copy != argv_copy_buf)
|
||||
bh_free(argv_copy);
|
||||
|
||||
/* success return */
|
||||
return;
|
||||
|
||||
fail:
|
||||
if (argv_copy != argv_copy_buf)
|
||||
bh_free(argv_copy);
|
||||
return;
|
||||
}
|
||||
|
||||
func_def++;
|
||||
}
|
||||
|
||||
THROW_EXC("the native widget function is not found!");
|
||||
}
|
||||
|
||||
84
core/app-framework/wgl/native/wgl_native_utils.h
Normal file
84
core/app-framework/wgl/native/wgl_native_utils.h
Normal file
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#ifndef WAMR_GRAPHIC_LIBRARY_NATIVE_UTILS_H
|
||||
#define WAMR_GRAPHIC_LIBRARY_NATIVE_UTILS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "bh_platform.h"
|
||||
#include "lvgl.h"
|
||||
#include "wasm_export.h"
|
||||
#include "bi-inc/wgl_shared_utils.h"
|
||||
|
||||
#define OBJ_ARG_NUM_MAX 4
|
||||
#define PTR_ARG_NUM_MAX 4
|
||||
|
||||
#define NULL_OK 0x80
|
||||
|
||||
enum {
|
||||
/* The function has a normal return value (not a pointer) */
|
||||
HAS_RET,
|
||||
/* The function doesn't have return value */
|
||||
NO_RET,
|
||||
/* The function's return value is a native address pointer */
|
||||
RET_PTR
|
||||
};
|
||||
|
||||
enum {
|
||||
WIDGET_TYPE_BTN,
|
||||
WIDGET_TYPE_LABEL,
|
||||
WIDGET_TYPE_CB,
|
||||
WIDGET_TYPE_LIST,
|
||||
WIDGET_TYPE_DDLIST,
|
||||
|
||||
_WIDGET_TYPE_NUM,
|
||||
};
|
||||
|
||||
typedef struct WGLNativeFuncDef {
|
||||
/* Function id */
|
||||
int32 func_id;
|
||||
|
||||
/* Native function pointer */
|
||||
void *func_ptr;
|
||||
|
||||
/* whether has return value */
|
||||
uint8 has_ret;
|
||||
|
||||
/* argument number */
|
||||
uint8 arg_num;
|
||||
|
||||
/* low 7 bit: obj argument index
|
||||
* highest 1 bit: allow obj be null or not
|
||||
* -1 means the end of this array */
|
||||
uint8 obj_arg_indexes[OBJ_ARG_NUM_MAX];
|
||||
|
||||
/* pointer argument indexes, -1 means the end of this array */
|
||||
uint8 ptr_arg_indexes[PTR_ARG_NUM_MAX];
|
||||
} WGLNativeFuncDef;
|
||||
|
||||
bool wgl_native_validate_object(int32 obj_id, lv_obj_t **obj);
|
||||
|
||||
bool wgl_native_add_object(lv_obj_t *obj, uint32 module_id, uint32 *obj_id);
|
||||
|
||||
uint32 wgl_native_wigdet_create(int8 widget_type,
|
||||
lv_obj_t *par,
|
||||
lv_obj_t *copy,
|
||||
wasm_module_inst_t module_inst);
|
||||
|
||||
void wgl_native_func_call(wasm_module_inst_t module_inst,
|
||||
WGLNativeFuncDef *funcs,
|
||||
uint32 size,
|
||||
int32 func_id,
|
||||
uint32 argv_offset,
|
||||
uint32 argc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* WAMR_GRAPHIC_LIBRARY_NATIVE_UTILS_H */
|
||||
389
core/app-framework/wgl/native/wgl_obj_wrapper.c
Normal file
389
core/app-framework/wgl/native/wgl_obj_wrapper.c
Normal file
@ -0,0 +1,389 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#include "lvgl.h"
|
||||
#include "app_manager_export.h"
|
||||
#include "module_wasm_app.h"
|
||||
#include "bh_list.h"
|
||||
#include "bh_thread.h"
|
||||
#include "wgl_native_utils.h"
|
||||
#include "wgl.h"
|
||||
|
||||
|
||||
typedef struct {
|
||||
bh_list_link l;
|
||||
|
||||
/* The object id. */
|
||||
uint32 obj_id;
|
||||
|
||||
/* The lv object */
|
||||
lv_obj_t *obj;
|
||||
|
||||
/* Module id that the obj belongs to */
|
||||
uint32 module_id;
|
||||
} object_node_t;
|
||||
|
||||
typedef struct {
|
||||
int32 obj_id;
|
||||
lv_event_t event;
|
||||
} object_event_t;
|
||||
|
||||
/* Max obj id */
|
||||
static uint32 g_obj_id_max = 0;
|
||||
|
||||
static bh_list g_object_list;
|
||||
|
||||
static korp_mutex g_object_list_mutex;
|
||||
|
||||
static bool lv_task_handler_thread_run = true;
|
||||
|
||||
static void app_mgr_object_event_callback(module_data *m_data, bh_message_t msg)
|
||||
{
|
||||
uint32 argv[2];
|
||||
wasm_function_inst_t func_on_object_event;
|
||||
bh_assert(WIDGET_EVENT_WASM == bh_message_type(msg));
|
||||
wasm_data *wasm_app_data = (wasm_data*)m_data->internal_data;
|
||||
wasm_module_inst_t inst = wasm_app_data->wasm_module_inst;
|
||||
object_event_t *object_event
|
||||
= (object_event_t *)bh_message_payload(msg);
|
||||
|
||||
if (object_event == NULL)
|
||||
return;
|
||||
|
||||
func_on_object_event = wasm_runtime_lookup_function(inst, "_on_widget_event",
|
||||
"(i32i32)");
|
||||
if (!func_on_object_event)
|
||||
func_on_object_event = wasm_runtime_lookup_function(inst, "on_widget_event",
|
||||
"(i32i32)");
|
||||
if (!func_on_object_event) {
|
||||
printf("Cannot find function on_widget_event\n");
|
||||
return;
|
||||
}
|
||||
|
||||
argv[0] = object_event->obj_id;
|
||||
argv[1] = object_event->event;
|
||||
if (!wasm_runtime_call_wasm(wasm_app_data->exec_env, func_on_object_event,
|
||||
2, argv)) {
|
||||
const char *exception = wasm_runtime_get_exception(inst);
|
||||
bh_assert(exception);
|
||||
printf(":Got exception running wasm code: %s\n",
|
||||
exception);
|
||||
wasm_runtime_clear_exception(inst);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static void cleanup_object_list(uint32 module_id)
|
||||
{
|
||||
object_node_t *elem;
|
||||
|
||||
vm_mutex_lock(&g_object_list_mutex);
|
||||
|
||||
while (true) {
|
||||
bool found = false;
|
||||
elem = (object_node_t *)bh_list_first_elem(&g_object_list);
|
||||
while (elem) {
|
||||
/* delete the leaf node belongs to the module firstly */
|
||||
if (module_id == elem->module_id &&
|
||||
lv_obj_count_children(elem->obj) == 0) {
|
||||
object_node_t *next = (object_node_t *)bh_list_elem_next(elem);
|
||||
|
||||
found = true;
|
||||
lv_obj_del(elem->obj);
|
||||
bh_list_remove(&g_object_list, elem);
|
||||
bh_free(elem);
|
||||
elem = next;
|
||||
} else {
|
||||
elem = (object_node_t *)bh_list_elem_next(elem);
|
||||
}
|
||||
}
|
||||
|
||||
if (!found)
|
||||
break;
|
||||
}
|
||||
|
||||
vm_mutex_unlock(&g_object_list_mutex);
|
||||
}
|
||||
|
||||
static bool init_object_event_callback_framework()
|
||||
{
|
||||
if (!wasm_register_cleanup_callback(cleanup_object_list)) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (!wasm_register_msg_callback(WIDGET_EVENT_WASM,
|
||||
app_mgr_object_event_callback)) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
fail:
|
||||
return false;
|
||||
}
|
||||
|
||||
bool wgl_native_validate_object(int32 obj_id, lv_obj_t **obj)
|
||||
{
|
||||
object_node_t *elem;
|
||||
|
||||
vm_mutex_lock(&g_object_list_mutex);
|
||||
|
||||
elem = (object_node_t *)bh_list_first_elem(&g_object_list);
|
||||
while (elem) {
|
||||
if (obj_id == elem->obj_id) {
|
||||
if (obj != NULL)
|
||||
*obj = elem->obj;
|
||||
vm_mutex_unlock(&g_object_list_mutex);
|
||||
return true;
|
||||
}
|
||||
elem = (object_node_t *) bh_list_elem_next(elem);
|
||||
}
|
||||
|
||||
vm_mutex_unlock(&g_object_list_mutex);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool wgl_native_add_object(lv_obj_t *obj, uint32 module_id, uint32 *obj_id)
|
||||
{
|
||||
object_node_t *node;
|
||||
|
||||
node = (object_node_t *) bh_malloc(sizeof(object_node_t));
|
||||
|
||||
if (node == NULL)
|
||||
return false;
|
||||
|
||||
/* Generate an obj id */
|
||||
g_obj_id_max++;
|
||||
if (g_obj_id_max == -1)
|
||||
g_obj_id_max = 1;
|
||||
|
||||
memset(node, 0, sizeof(*node));
|
||||
node->obj = obj;
|
||||
node->obj_id = g_obj_id_max;
|
||||
node->module_id = module_id;
|
||||
|
||||
vm_mutex_lock(&g_object_list_mutex);
|
||||
bh_list_insert(&g_object_list, node);
|
||||
vm_mutex_unlock(&g_object_list_mutex);
|
||||
|
||||
if (obj_id != NULL)
|
||||
*obj_id = node->obj_id;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void _obj_del_recursive(lv_obj_t *obj)
|
||||
{
|
||||
object_node_t *elem;
|
||||
lv_obj_t * i;
|
||||
lv_obj_t * i_next;
|
||||
|
||||
i = lv_ll_get_head(&(obj->child_ll));
|
||||
|
||||
while (i != NULL) {
|
||||
/*Get the next object before delete this*/
|
||||
i_next = lv_ll_get_next(&(obj->child_ll), i);
|
||||
|
||||
/*Call the recursive del to the child too*/
|
||||
_obj_del_recursive(i);
|
||||
|
||||
/*Set i to the next node*/
|
||||
i = i_next;
|
||||
}
|
||||
|
||||
vm_mutex_lock(&g_object_list_mutex);
|
||||
|
||||
elem = (object_node_t *)bh_list_first_elem(&g_object_list);
|
||||
while (elem) {
|
||||
if (obj == elem->obj) {
|
||||
bh_list_remove(&g_object_list, elem);
|
||||
bh_free(elem);
|
||||
vm_mutex_unlock(&g_object_list_mutex);
|
||||
return;
|
||||
}
|
||||
elem = (object_node_t *) bh_list_elem_next(elem);
|
||||
}
|
||||
|
||||
vm_mutex_unlock(&g_object_list_mutex);
|
||||
}
|
||||
|
||||
static void _obj_clean_recursive(lv_obj_t *obj)
|
||||
{
|
||||
lv_obj_t * i;
|
||||
lv_obj_t * i_next;
|
||||
|
||||
i = lv_ll_get_head(&(obj->child_ll));
|
||||
|
||||
while (i != NULL) {
|
||||
/*Get the next object before delete this*/
|
||||
i_next = lv_ll_get_next(&(obj->child_ll), i);
|
||||
|
||||
/*Call the recursive del to the child too*/
|
||||
_obj_del_recursive(i);
|
||||
|
||||
/*Set i to the next node*/
|
||||
i = i_next;
|
||||
}
|
||||
}
|
||||
|
||||
static void post_widget_msg_to_module(object_node_t *object_node, lv_event_t event)
|
||||
{
|
||||
module_data *module = module_data_list_lookup_id(object_node->module_id);
|
||||
object_event_t *object_event;
|
||||
|
||||
if (module == NULL)
|
||||
return;
|
||||
|
||||
object_event = (object_event_t *)bh_malloc(sizeof(*object_event));
|
||||
if (object_event == NULL)
|
||||
return;
|
||||
|
||||
memset(object_event, 0, sizeof(*object_event));
|
||||
object_event->obj_id = object_node->obj_id;
|
||||
object_event->event = event;
|
||||
|
||||
bh_post_msg(module->queue,
|
||||
WIDGET_EVENT_WASM,
|
||||
object_event,
|
||||
sizeof(*object_event));
|
||||
}
|
||||
|
||||
static void internal_lv_obj_event_cb(lv_obj_t *obj, lv_event_t event)
|
||||
{
|
||||
object_node_t *elem;
|
||||
|
||||
vm_mutex_lock(&g_object_list_mutex);
|
||||
|
||||
elem = (object_node_t *)bh_list_first_elem(&g_object_list);
|
||||
while (elem) {
|
||||
if (obj == elem->obj) {
|
||||
post_widget_msg_to_module(elem, event);
|
||||
vm_mutex_unlock(&g_object_list_mutex);
|
||||
return;
|
||||
}
|
||||
elem = (object_node_t *) bh_list_elem_next(elem);
|
||||
}
|
||||
|
||||
vm_mutex_unlock(&g_object_list_mutex);
|
||||
}
|
||||
|
||||
static void* lv_task_handler_thread_routine (void *arg)
|
||||
{
|
||||
korp_sem sem;
|
||||
|
||||
vm_sem_init(&sem, 0);
|
||||
|
||||
while (lv_task_handler_thread_run) {
|
||||
vm_sem_reltimedwait(&sem, 100);
|
||||
lv_task_handler();
|
||||
}
|
||||
|
||||
vm_sem_destroy(&sem);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void wgl_init(void)
|
||||
{
|
||||
korp_thread tid;
|
||||
|
||||
lv_init();
|
||||
|
||||
bh_list_init(&g_object_list);
|
||||
vm_recursive_mutex_init(&g_object_list_mutex);
|
||||
init_object_event_callback_framework();
|
||||
|
||||
/* new a thread, call lv_task_handler periodically */
|
||||
vm_thread_create(&tid,
|
||||
lv_task_handler_thread_routine,
|
||||
NULL,
|
||||
BH_APPLET_PRESERVED_STACK_SIZE);
|
||||
}
|
||||
|
||||
void wgl_exit(void)
|
||||
{
|
||||
lv_task_handler_thread_run = false;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------
|
||||
* Obj native function wrappers
|
||||
* -------------------------------------------------------------------------*/
|
||||
static lv_res_t
|
||||
lv_obj_del_wrapper(wasm_module_inst_t module_inst, lv_obj_t *obj)
|
||||
{
|
||||
(void)module_inst;
|
||||
|
||||
/* Recursively delete object node in the list belong to this
|
||||
* parent object including itself */
|
||||
_obj_del_recursive(obj);
|
||||
|
||||
return lv_obj_del(obj);
|
||||
}
|
||||
|
||||
static void
|
||||
lv_obj_del_async_wrapper(wasm_module_inst_t module_inst, lv_obj_t * obj)
|
||||
{
|
||||
(void)module_inst;
|
||||
lv_obj_del_async(obj);
|
||||
}
|
||||
|
||||
static void
|
||||
lv_obj_clean_wrapper(wasm_module_inst_t module_inst, lv_obj_t *obj)
|
||||
{
|
||||
(void)module_inst;
|
||||
|
||||
/* Recursively delete child object node in the list belong to this
|
||||
* parent object */
|
||||
_obj_clean_recursive(obj);
|
||||
|
||||
/* Delete all of its children */
|
||||
lv_obj_clean(obj);
|
||||
}
|
||||
|
||||
static void
|
||||
lv_obj_align_wrapper(wasm_module_inst_t module_inst,
|
||||
lv_obj_t * obj,
|
||||
const lv_obj_t * base,
|
||||
lv_align_t align,
|
||||
lv_coord_t x_mod,
|
||||
lv_coord_t y_mod)
|
||||
{
|
||||
(void)module_inst;
|
||||
lv_obj_align(obj, base, align, x_mod, y_mod);
|
||||
}
|
||||
|
||||
static void
|
||||
lv_obj_set_event_cb_wrapper(wasm_module_inst_t module_inst, lv_obj_t *obj)
|
||||
{
|
||||
(void)module_inst;
|
||||
lv_obj_set_event_cb(obj, internal_lv_obj_event_cb);
|
||||
}
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
static WGLNativeFuncDef obj_native_func_defs[] = {
|
||||
{ OBJ_FUNC_ID_DEL, lv_obj_del_wrapper, HAS_RET, 2, {1, -1}, {-1} },
|
||||
{ OBJ_FUNC_ID_DEL_ASYNC, lv_obj_del_async_wrapper, NO_RET, 2, {1, -1}, {-1} },
|
||||
{ OBJ_FUNC_ID_CLEAN, lv_obj_clean_wrapper, NO_RET, 2, {1, -1}, {-1} },
|
||||
{ OBJ_FUNC_ID_ALIGN, lv_obj_align_wrapper, NO_RET, 6, {1, 2 | NULL_OK, -1}, {-1} },
|
||||
{ OBJ_FUNC_ID_SET_EVT_CB, lv_obj_set_event_cb_wrapper, NO_RET, 2, {1, -1}, {-1} },
|
||||
};
|
||||
|
||||
/*************** Native Interface to Wasm App ***********/
|
||||
void
|
||||
wasm_obj_native_call(wasm_exec_env_t exec_env,
|
||||
int32 func_id, uint32 argv_offset, uint32 argc)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uint32 size = sizeof(obj_native_func_defs) / sizeof(WGLNativeFuncDef);
|
||||
|
||||
wgl_native_func_call(module_inst,
|
||||
obj_native_func_defs,
|
||||
size,
|
||||
func_id,
|
||||
argv_offset,
|
||||
argc);
|
||||
}
|
||||
Reference in New Issue
Block a user