Skip to content
This repository has been archived by the owner on Feb 17, 2022. It is now read-only.

Commit

Permalink
video: emscripten: framebuffer: proxy canvas access to main thread
Browse files Browse the repository at this point in the history
  • Loading branch information
jakogut committed Feb 27, 2019
1 parent b4f41a0 commit fe548de
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions src/video/emscripten/SDL_emscriptenframebuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "SDL_emscriptenvideo.h"
#include "SDL_emscriptenframebuffer.h"

#include <emscripten/threading.h>


int Emscripten_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch)
{
Expand Down Expand Up @@ -56,18 +58,8 @@ int Emscripten_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * form
return 0;
}

int Emscripten_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects)
static void Emscripten_UpdateWindowFramebufferWorker(SDL_Surface *surface)
{
SDL_Surface *surface;

SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
surface = data->surface;
if (!surface) {
return SDL_SetError("Couldn't find framebuffer surface for window");
}

/* Send the data to the display */

EM_ASM_INT({
var w = $0;
var h = $1;
Expand Down Expand Up @@ -154,6 +146,29 @@ int Emscripten_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rec
SDL2.ctx.putImageData(SDL2.image, 0, 0);
return 0;
}, surface->w, surface->h, surface->pixels);
}

int Emscripten_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects)
{
SDL_Surface *surface;

SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
surface = data->surface;
if (!surface) {
return SDL_SetError("Couldn't find framebuffer surface for window");
}

/* Send the data to the display */

if (emscripten_is_main_runtime_thread()) {
Emscripten_UpdateWindowFramebufferWorker(surface);
} else {
emscripten_sync_run_in_main_runtime_thread(
EM_FUNC_SIG_VI,
Emscripten_UpdateWindowFramebufferWorker,
(uint32_t)surface
);
}

/*if (SDL_getenv("SDL_VIDEO_Emscripten_SAVE_FRAMES")) {
static int frame_number = 0;
Expand Down

0 comments on commit fe548de

Please sign in to comment.