|
@@ -24,6 +24,7 @@
|
|
|
|
|
|
#include <emscripten/emscripten.h>
|
|
|
#include <emscripten/html5.h>
|
|
|
+#include <emscripten/threading.h>
|
|
|
|
|
|
#include "SDL_emscriptenmouse.h"
|
|
|
#include "SDL_emscriptenvideo.h"
|
|
@@ -62,19 +63,9 @@ Emscripten_CreateDefaultCursor()
|
|
|
return Emscripten_CreateCursorFromString("default", SDL_FALSE);
|
|
|
}
|
|
|
|
|
|
-static SDL_Cursor*
|
|
|
-Emscripten_CreateCursor(SDL_Surface* surface, int hot_x, int hot_y)
|
|
|
+static const char *Emscripten_GetCursorUrl(int w, int h, int hot_x, int hot_y, int pixels)
|
|
|
{
|
|
|
- const char *cursor_url = NULL;
|
|
|
- SDL_Surface *conv_surf;
|
|
|
-
|
|
|
- conv_surf = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_ABGR8888, 0);
|
|
|
-
|
|
|
- if (!conv_surf) {
|
|
|
- return NULL;
|
|
|
- }
|
|
|
-
|
|
|
- cursor_url = (const char *)EM_ASM_INT({
|
|
|
+ return (const char *)EM_ASM_INT({
|
|
|
var w = $0;
|
|
|
var h = $1;
|
|
|
var hot_x = $2;
|
|
@@ -122,7 +113,40 @@ Emscripten_CreateCursor(SDL_Surface* surface, int hot_x, int hot_y)
|
|
|
stringToUTF8(url, urlBuf, url.length + 1);
|
|
|
|
|
|
return urlBuf;
|
|
|
- }, surface->w, surface->h, hot_x, hot_y, conv_surf->pixels);
|
|
|
+ }, w, h, hot_x, hot_y, pixels);
|
|
|
+}
|
|
|
+
|
|
|
+static SDL_Cursor*
|
|
|
+Emscripten_CreateCursor(SDL_Surface* surface, int hot_x, int hot_y)
|
|
|
+{
|
|
|
+ const char *cursor_url = NULL;
|
|
|
+ SDL_Surface *conv_surf;
|
|
|
+
|
|
|
+ conv_surf = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_ABGR8888, 0);
|
|
|
+
|
|
|
+ if (!conv_surf) {
|
|
|
+ return NULL;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (emscripten_is_main_runtime_thread()) {
|
|
|
+ cursor_url = Emscripten_GetCursorUrl(
|
|
|
+ surface->w,
|
|
|
+ surface->h,
|
|
|
+ hot_x,
|
|
|
+ hot_y,
|
|
|
+ conv_surf->pixels
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ cursor_url = emscripten_sync_run_in_main_runtime_thread(
|
|
|
+ EM_FUNC_SIG_IIIIIII,
|
|
|
+ Emscripten_GetCursorUrl,
|
|
|
+ surface->w,
|
|
|
+ surface->h,
|
|
|
+ hot_x,
|
|
|
+ hot_y,
|
|
|
+ conv_surf->pixels
|
|
|
+ );
|
|
|
+ }
|
|
|
|
|
|
SDL_FreeSurface(conv_surf);
|
|
|
|
|
@@ -206,7 +230,7 @@ Emscripten_ShowCursor(SDL_Cursor* cursor)
|
|
|
curdata = (Emscripten_CursorData *) cursor->driverdata;
|
|
|
|
|
|
if(curdata->system_cursor) {
|
|
|
- EM_ASM_INT({
|
|
|
+ MAIN_THREAD_EM_ASM_INT({
|
|
|
if (Module['canvas']) {
|
|
|
Module['canvas'].style['cursor'] = UTF8ToString($0);
|
|
|
}
|
|
@@ -215,7 +239,7 @@ Emscripten_ShowCursor(SDL_Cursor* cursor)
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
- EM_ASM(
|
|
|
+ MAIN_THREAD_EM_ASM_INT(
|
|
|
if (Module['canvas']) {
|
|
|
Module['canvas'].style['cursor'] = 'none';
|
|
|
}
|