From 0c6d5b3ac8b05786128f211d9ec7dd981f34ddb4 Mon Sep 17 00:00:00 2001 From: Charlie Birks Date: Fri, 30 Sep 2022 16:28:57 +0100 Subject: [PATCH 1/2] emscripten: drop CanvasPixelArray support from framebuffer --- .../emscripten/SDL_emscriptenframebuffer.c | 102 ++++++++---------- 1 file changed, 43 insertions(+), 59 deletions(-) diff --git a/src/video/emscripten/SDL_emscriptenframebuffer.c b/src/video/emscripten/SDL_emscriptenframebuffer.c index 03fea04ef..93620213a 100644 --- a/src/video/emscripten/SDL_emscriptenframebuffer.c +++ b/src/video/emscripten/SDL_emscriptenframebuffer.c @@ -92,66 +92,50 @@ int Emscripten_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rec var src = pixels >> 2; var dst = 0; var num; - if (typeof CanvasPixelArray !== 'undefined' && data instanceof CanvasPixelArray) { - // IE10/IE11: ImageData objects are backed by the deprecated CanvasPixelArray, - // not UInt8ClampedArray. These don't have buffers, so we need to revert - // to copying a byte at a time. We do the undefined check because modern - // browsers do not define CanvasPixelArray anymore. - num = data.length; - while (dst < num) { - var val = HEAP32[src]; // This is optimized. Instead, we could do {{{ makeGetValue('buffer', 'dst', 'i32') }}}; - data[dst ] = val & 0xff; - data[dst+1] = (val >> 8) & 0xff; - data[dst+2] = (val >> 16) & 0xff; - data[dst+3] = 0xff; - src++; - dst += 4; + + if (SDL2.data32Data !== data) { + SDL2.data32 = new Int32Array(data.buffer); + SDL2.data8 = new Uint8Array(data.buffer); + SDL2.data32Data = data; + } + var data32 = SDL2.data32; + num = data32.length; + // logically we need to do + // while (dst < num) { + // data32[dst++] = HEAP32[src++] | 0xff000000 + // } + // the following code is faster though, because + // .set() is almost free - easily 10x faster due to + // native SDL_memcpy efficiencies, and the remaining loop + // just stores, not load + store, so it is faster + data32.set(HEAP32.subarray(src, src + num)); + var data8 = SDL2.data8; + var i = 3; + var j = i + 4*num; + if (num % 8 == 0) { + // unrolling gives big speedups + while (i < j) { + data8[i] = 0xff; + i = i + 4 | 0; + data8[i] = 0xff; + i = i + 4 | 0; + data8[i] = 0xff; + i = i + 4 | 0; + data8[i] = 0xff; + i = i + 4 | 0; + data8[i] = 0xff; + i = i + 4 | 0; + data8[i] = 0xff; + i = i + 4 | 0; + data8[i] = 0xff; + i = i + 4 | 0; + data8[i] = 0xff; + i = i + 4 | 0; } - } else { - if (SDL2.data32Data !== data) { - SDL2.data32 = new Int32Array(data.buffer); - SDL2.data8 = new Uint8Array(data.buffer); - SDL2.data32Data = data; - } - var data32 = SDL2.data32; - num = data32.length; - // logically we need to do - // while (dst < num) { - // data32[dst++] = HEAP32[src++] | 0xff000000 - // } - // the following code is faster though, because - // .set() is almost free - easily 10x faster due to - // native SDL_memcpy efficiencies, and the remaining loop - // just stores, not load + store, so it is faster - data32.set(HEAP32.subarray(src, src + num)); - var data8 = SDL2.data8; - var i = 3; - var j = i + 4*num; - if (num % 8 == 0) { - // unrolling gives big speedups - while (i < j) { - data8[i] = 0xff; - i = i + 4 | 0; - data8[i] = 0xff; - i = i + 4 | 0; - data8[i] = 0xff; - i = i + 4 | 0; - data8[i] = 0xff; - i = i + 4 | 0; - data8[i] = 0xff; - i = i + 4 | 0; - data8[i] = 0xff; - i = i + 4 | 0; - data8[i] = 0xff; - i = i + 4 | 0; - data8[i] = 0xff; - i = i + 4 | 0; - } - } else { - while (i < j) { - data8[i] = 0xff; - i = i + 4 | 0; - } + } else { + while (i < j) { + data8[i] = 0xff; + i = i + 4 | 0; } } From 90e7d05c3b44ff2212574e853c9d12dad332d66e Mon Sep 17 00:00:00 2001 From: Charlie Birks Date: Fri, 30 Sep 2022 16:33:10 +0100 Subject: [PATCH 2/2] emscripten: drop CanvasPixelArray support from cursor --- src/video/emscripten/SDL_emscriptenmouse.c | 25 +++------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/src/video/emscripten/SDL_emscriptenmouse.c b/src/video/emscripten/SDL_emscriptenmouse.c index 38e394ac1..80c42cb3e 100644 --- a/src/video/emscripten/SDL_emscriptenmouse.c +++ b/src/video/emscripten/SDL_emscriptenmouse.c @@ -92,28 +92,9 @@ Emscripten_CreateCursor(SDL_Surface* surface, int hot_x, int hot_y) var image = ctx.createImageData(w, h); var data = image.data; var src = pixels >> 2; - var dst = 0; - var num; - if (typeof CanvasPixelArray !== 'undefined' && data instanceof CanvasPixelArray) { - // IE10/IE11: ImageData objects are backed by the deprecated CanvasPixelArray, - // not UInt8ClampedArray. These don't have buffers, so we need to revert - // to copying a byte at a time. We do the undefined check because modern - // browsers do not define CanvasPixelArray anymore. - num = data.length; - while (dst < num) { - var val = HEAP32[src]; // This is optimized. Instead, we could do {{{ makeGetValue('buffer', 'dst', 'i32') }}}; - data[dst ] = val & 0xff; - data[dst+1] = (val >> 8) & 0xff; - data[dst+2] = (val >> 16) & 0xff; - data[dst+3] = (val >> 24) & 0xff; - src++; - dst += 4; - } - } else { - var data32 = new Int32Array(data.buffer); - num = data32.length; - data32.set(HEAP32.subarray(src, src + num)); - } + + var data32 = new Int32Array(data.buffer); + data32.set(HEAP32.subarray(src, src + data32.length)); ctx.putImageData(image, 0, 0); var url = hot_x === 0 && hot_y === 0