Merge pull request #6321 from Daft-Freak/no-ie

Delete emscripten CanvasPixelArray (IE10/11) support
main
Ryan C. Gordon 2022-11-23 14:03:35 -05:00 committed by GitHub
commit 712457ec28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 81 deletions

View File

@ -95,66 +95,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 (SDL3.data32Data !== data) {
SDL3.data32 = new Int32Array(data.buffer);
SDL3.data8 = new Uint8Array(data.buffer);
SDL3.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 = SDL3.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 (SDL3.data32Data !== data) {
SDL3.data32 = new Int32Array(data.buffer);
SDL3.data8 = new Uint8Array(data.buffer);
SDL3.data32Data = data;
}
var data32 = SDL3.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 = SDL3.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;
}
}

View File

@ -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