This repository has been archived by the owner on Feb 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 64
[WIP] SDL2 thread proxying fixes #127
Open
jakogut
wants to merge
5
commits into
emscripten-ports:master
Choose a base branch
from
jakogut:sdl2-proxy-pthread-fixes
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
85b7de5
emscripten: use emscripten_get_screen_size api
jakogut 9928533
emscripten: use emscripten_set_window_title api
jakogut e4f8cd7
emscripten: mouse: proxy canvas access to main thread
jakogut 7eb4259
emscripten: framebuffer: proxy canvas access to main thread
jakogut 9aa3b44
emscripten: mouse: proxy canvas access to main thread
jakogut File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
|
||
#include <emscripten/emscripten.h> | ||
#include <emscripten/html5.h> | ||
#include <emscripten/threading.h> | ||
|
||
#include "SDL_emscriptenmouse.h" | ||
#include "SDL_emscriptenvideo.h" | ||
|
@@ -65,19 +66,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; | ||
|
@@ -125,7 +116,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); | ||
|
||
|
@@ -209,7 +233,7 @@ Emscripten_ShowCursor(SDL_Cursor* cursor) | |
curdata = (Emscripten_CursorData *) cursor->driverdata; | ||
|
||
if(curdata->system_cursor) { | ||
EM_ASM_INT({ | ||
MAIN_THREAD_EM_ASM_INT({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Switch this to |
||
if (Module['canvas']) { | ||
Module['canvas'].style['cursor'] = UTF8ToString($0); | ||
} | ||
|
@@ -218,7 +242,7 @@ Emscripten_ShowCursor(SDL_Cursor* cursor) | |
} | ||
} | ||
else { | ||
EM_ASM( | ||
MAIN_THREAD_EM_ASM( | ||
if (Module['canvas']) { | ||
Module['canvas'].style['cursor'] = 'none'; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slightly annoying that we have to proxy this as it just wants to create an image from some data... But I don't think it can be avoided.