window_size_title_api #61

Merged
MartinFouilleul merged 8 commits from window_size_title_api into main 2023-08-25 13:29:28 +00:00
7 changed files with 38 additions and 15 deletions
Showing only changes of commit d4cb93c61a - Show all commits

View File

@ -397,6 +397,7 @@ def gen_all_bindings():
) )
bindgen("core", "src/wasmbind/core_api.json", bindgen("core", "src/wasmbind/core_api.json",
guest_stubs="src/wasmbind/core_api_stubs.c",
wasm3_bindings="src/wasmbind/core_api_bind_gen.c", wasm3_bindings="src/wasmbind/core_api_bind_gen.c",
) )

View File

@ -405,7 +405,7 @@ ORCA_API int oc_directory_create(oc_str8 path);
void ORCA_IMPORT(oc_request_quit)(void); void ORCA_IMPORT(oc_request_quit)(void);
void ORCA_IMPORT(oc_runtime_window_set_title)(const char* title); void ORCA_IMPORT(oc_runtime_window_set_title)(oc_str8 title);
void ORCA_IMPORT(oc_runtime_window_set_size)(f32 width, f32 height); void ORCA_IMPORT(oc_runtime_window_set_size)(f32 width, f32 height);

View File

@ -96,6 +96,7 @@
//NOTE: macos application layer and graphics backends are defined in orca.m //NOTE: macos application layer and graphics backends are defined in orca.m
#elif OC_PLATFORM_ORCA #elif OC_PLATFORM_ORCA
#include "app/orca_app.c" #include "app/orca_app.c"
#include "wasmbind/core_api_stubs.c"
#include "graphics/graphics_common.c" #include "graphics/graphics_common.c"
#include "graphics/orca_surface_stubs.c" #include "graphics/orca_surface_stubs.c"
#else #else

View File

@ -66,9 +66,30 @@ oc_runtime_env* oc_runtime_env_get()
return (&__orcaApp.runtime); return (&__orcaApp.runtime);
} }
void oc_runtime_window_set_title(const char* title) void* oc_runtime_ptr_to_native(oc_runtime* orca, void* wasmPtr, u32 length)
{ {
oc_window_set_title(__orcaApp.window, OC_STR8(title)); // We can't use the runtime's memory pointer directly because wasm3 embeds a
// header at the beginning of the block we give it.
u64 bufferIndex = (u64)wasmPtr & 0xffffffff;
u32 memSize = 0;
char* memory = (char*)m3_GetMemory(orca->runtime.m3Runtime, &memSize, 0);
if(bufferIndex + length < memSize)
{
char* nativePtr = memory + bufferIndex;
return nativePtr;
}
return NULL;
}
void oc_runtime_window_set_title(oc_str8 title)
{
title.ptr = oc_runtime_ptr_to_native(oc_runtime_get(), title.ptr, title.len);
if(title.ptr)
{
oc_window_set_title(__orcaApp.window, title);
}
} }
void oc_runtime_window_set_size(f32 width, f32 height) void oc_runtime_window_set_size(f32 width, f32 height)

View File

@ -125,4 +125,6 @@ typedef struct oc_runtime
oc_runtime* oc_runtime_get(); oc_runtime* oc_runtime_get();
oc_runtime_env* oc_runtime_env_get(); oc_runtime_env* oc_runtime_env_get();
void* oc_runtime_ptr_to_native(oc_runtime* runtime, void* wasmPtr, u32 length);
#endif //__RUNTIME_H_ #endif //__RUNTIME_H_

View File

@ -14,19 +14,12 @@ oc_io_cmp oc_runtime_io_wait_single_req(oc_io_req* wasmReq)
oc_io_cmp cmp = { 0 }; oc_io_cmp cmp = { 0 };
oc_io_req req = *wasmReq; oc_io_req req = *wasmReq;
//NOTE: convert the req->buffer wasm pointer to a native pointer
// for some reason, wasm3 memory doesn't start at the beginning of the block we give it.
u64 bufferIndex = (u64)req.buffer & 0xffffffff;
u32 memSize = 0;
char* memory = (char*)m3_GetMemory(orca->runtime.m3Runtime, &memSize, 0);
if(bufferIndex + req.size > memSize) void* buffer = oc_runtime_ptr_to_native(orca, req.buffer, req.size);
if(buffer)
{ {
cmp.error = OC_IO_ERR_ARG; req.buffer = buffer;
}
else
{
req.buffer = memory + bufferIndex;
if(req.op == OC_IO_OPEN_AT) if(req.op == OC_IO_OPEN_AT)
{ {
@ -39,5 +32,10 @@ oc_io_cmp oc_runtime_io_wait_single_req(oc_io_req* wasmReq)
} }
cmp = oc_io_wait_single_req_with_table(&req, &orca->fileTable); cmp = oc_io_wait_single_req_with_table(&req, &orca->fileTable);
} }
else
{
cmp.error = OC_IO_ERR_ARG;
}
return (cmp); return (cmp);
} }

View File

@ -76,7 +76,7 @@
"ret": {"name": "void", "tag": "v"}, "ret": {"name": "void", "tag": "v"},
"args": [ "args": [
{ "name": "title", { "name": "title",
"type": {"name": "const char*", "tag": "p"}} "type": {"name": "oc_str8", "tag": "S"}}
] ]
}, },
{ {