|
25 | 25 | #include "SDL_emscriptenvideo.h" |
26 | 26 | #include "SDL_emscriptenframebuffer.h" |
27 | 27 |
|
| 28 | +#include <emscripten/threading.h> |
| 29 | + |
28 | 30 |
|
29 | 31 | int Emscripten_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch) |
30 | 32 | { |
@@ -56,18 +58,8 @@ int Emscripten_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * form |
56 | 58 | return 0; |
57 | 59 | } |
58 | 60 |
|
59 | | -int Emscripten_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects) |
| 61 | +static void Emscripten_UpdateWindowFramebufferWorker(SDL_Surface *surface) |
60 | 62 | { |
61 | | - SDL_Surface *surface; |
62 | | - |
63 | | - SDL_WindowData *data = (SDL_WindowData *) window->driverdata; |
64 | | - surface = data->surface; |
65 | | - if (!surface) { |
66 | | - return SDL_SetError("Couldn't find framebuffer surface for window"); |
67 | | - } |
68 | | - |
69 | | - /* Send the data to the display */ |
70 | | - |
71 | 63 | EM_ASM_INT({ |
72 | 64 | var w = $0; |
73 | 65 | var h = $1; |
@@ -154,6 +146,29 @@ int Emscripten_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rec |
154 | 146 | SDL2.ctx.putImageData(SDL2.image, 0, 0); |
155 | 147 | return 0; |
156 | 148 | }, surface->w, surface->h, surface->pixels); |
| 149 | +} |
| 150 | + |
| 151 | +int Emscripten_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects) |
| 152 | +{ |
| 153 | + SDL_Surface *surface; |
| 154 | + |
| 155 | + SDL_WindowData *data = (SDL_WindowData *) window->driverdata; |
| 156 | + surface = data->surface; |
| 157 | + if (!surface) { |
| 158 | + return SDL_SetError("Couldn't find framebuffer surface for window"); |
| 159 | + } |
| 160 | + |
| 161 | + /* Send the data to the display */ |
| 162 | + |
| 163 | + if (emscripten_is_main_runtime_thread()) { |
| 164 | + Emscripten_UpdateWindowFramebufferWorker(surface); |
| 165 | + } else { |
| 166 | + emscripten_sync_run_in_main_runtime_thread( |
| 167 | + EM_FUNC_SIG_VI, |
| 168 | + Emscripten_UpdateWindowFramebufferWorker, |
| 169 | + (uint32_t)surface |
| 170 | + ); |
| 171 | + } |
157 | 172 |
|
158 | 173 | /*if (SDL_getenv("SDL_VIDEO_Emscripten_SAVE_FRAMES")) { |
159 | 174 | static int frame_number = 0; |
|
0 commit comments