diff options
-rw-r--r-- | src/jsifier.js | 3 | ||||
-rw-r--r-- | src/proxyWorker.js | 53 | ||||
-rw-r--r-- | tests/sdl_canvas_proxy.c | 27 | ||||
-rw-r--r-- | tests/test_browser.py | 2 |
4 files changed, 84 insertions, 1 deletions
diff --git a/src/jsifier.js b/src/jsifier.js index 3d8059b1..a3b26aa9 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -1843,6 +1843,9 @@ function JSify(data, functionsOnly, givenFunctions) { print(read('headless.js').replace("'%s'", "'http://emscripten.org'").replace("'?%s'", "''").replace("'?%s'", "'/'").replace('%s,', 'null,').replace('%d', '0')); print('}'); } + if (PROXY_TO_WORKER) { + print(read('proxyWorker.js')); + } if (RUNTIME_TYPE_INFO) { Types.cleanForRuntime(); print('Runtime.typeInfo = ' + JSON.stringify(Types.types)); diff --git a/src/proxyWorker.js b/src/proxyWorker.js new file mode 100644 index 00000000..2798b3d0 --- /dev/null +++ b/src/proxyWorker.js @@ -0,0 +1,53 @@ + +function EventListener() { + this.listeners = {}; + + this.addEventListener = function(event, func) { + if (!this.listeners[event]) this.listeners[event] = []; + this.listeners[event].push(func); + }; +}; + +var window = new EventListener(); +var document = new EventListener(); + +document.createElement = function(what) { + switch(what) { + case 'canvas': { + var canvas = new EventListener(); + canvas.ensureData = function() { + if (!canvas.data || canvas.data.width !== canvas.width || canvas.data.height !== canvas.height) { + canvas.data = { + width: canvas.width, + height: canvas.height, + buffer: new Uint8Array(canvas.width*canvas.height*4) + }; + } + }; + canvas.getContext = function(type) { + assert(type == '2d'); + return { + getImageData: function(x, y, w, h) { + assert(x == 0 && y == 0 && w == canvas.width && h == canvas.height); + canvas.ensureData(); + return { + width: canvas.data.width, + height: canvas.data.height, + data: new Uint8Array(canvas.data.buffer) // TODO: can we avoid this copy? + }; + }, + putImageData: function(image, x, y) { + canvas.ensureData(); + assert(x == 0 && y == 0 && image.width == canvas.width && image.height == canvas.height); + canvas.data.buffer.set(image.data); // TODO: can we avoid this copy? + } + }; + }; + return canvas; + } + default: throw 'document.createElement ' + what; + } +}; + +Module.canvas = document.createElement('canvas'); + diff --git a/tests/sdl_canvas_proxy.c b/tests/sdl_canvas_proxy.c new file mode 100644 index 00000000..a9e9179b --- /dev/null +++ b/tests/sdl_canvas_proxy.c @@ -0,0 +1,27 @@ +#include <stdio.h> +#include <stdlib.h> +#include <SDL/SDL.h> + +int main(int argc, char **argv) { + SDL_Init(SDL_INIT_VIDEO); + SDL_Surface *screen = SDL_SetVideoMode(600, 450, 32, SDL_HWSURFACE); + + SDL_LockSurface(screen); + unsigned int *pixels = (unsigned int *)screen->pixels; + for (int x = 0; x < screen->w; x++) { + for (int y = 0; y < screen->h; y++) { + pixels[x + y*screen->h] = x < 300 ? (y < 200 ? 0x3377AA88 : 0xAA3377CC) : (y < 200 ? 0x0066AA77 : 0xAA006699); + } + } + SDL_UnlockSurface(screen); + + SDL_Quit(); + + printf("done.\n"); + + int result = 1; + REPORT_RESULT(); + + return 0; +} + diff --git a/tests/test_browser.py b/tests/test_browser.py index 59c50aca..7465711b 100644 --- a/tests/test_browser.py +++ b/tests/test_browser.py @@ -628,7 +628,7 @@ If manually bisecting: self.run_browser('page.html', '', '/report_result?1') def test_sdl_canvas_proxy(self): - self.btest('sdl_canvas.c', '1', args=['--proxy-to-worker']) + self.btest('sdl_canvas_proxy.c', '1', args=['--proxy-to-worker']) def test_sdl_key(self): open(os.path.join(self.get_dir(), 'pre.js'), 'w').write(''' |