diff options
author | alon@honor <none@none> | 2010-09-28 20:15:21 -0700 |
---|---|---|
committer | alon@honor <none@none> | 2010-09-28 20:15:21 -0700 |
commit | d451428fb3312717c9e6cdf7c58c2e119d160bfb (patch) | |
tree | 75fbbd81ed414f4a178d7599edb44036c1e7600e | |
parent | 8d76adec420ef2abe0d5afe3ec1e72cb1ede76b7 (diff) |
SDL fixes, do not malloc for each frame
-rw-r--r-- | demos/raytrace.js | 4 | ||||
-rw-r--r-- | src/library_sdl.js | 4 |
2 files changed, 2 insertions, 6 deletions
diff --git a/demos/raytrace.js b/demos/raytrace.js index 684cf3b9..1d36c6dd 100644 --- a/demos/raytrace.js +++ b/demos/raytrace.js @@ -288,7 +288,6 @@ _SDL_LockSurface = function (surf) { surfData.image = surfData.ctx.getImageData(0, 0, surfData.width, surfData.height); // Copy pixel data to somewhere accessible to 'C/C++' var num = surfData.image.data.length; - surfData.buffer = _malloc(num); for (var i = 0; i < num; i++) { HEAP[surfData.buffer+i] = surfData.image.data[i]; } @@ -311,8 +310,6 @@ _SDL_UnlockSurface = function (surf) { surfData.ctx.putImageData(surfData.image, 0, 0); // Cleanup surfData.image = null; - _free(surfData.buffer); - surfData.buffer = null; } _SDL_Flip = function (surf) { // We actually do this in Unlock... @@ -332,6 +329,7 @@ _SDL_SetVideoMode = function (width, height, depth, flags, canvas) { canvas: canvas, ctx: canvas.getContext('2d'), surf: surf, + buffer: _malloc(width*height*4), }; return surf; } diff --git a/src/library_sdl.js b/src/library_sdl.js index 95842271..fb6d7775 100644 --- a/src/library_sdl.js +++ b/src/library_sdl.js @@ -13,6 +13,7 @@ mergeInto(Library, { canvas: canvas, ctx: canvas.getContext('2d'), surf: surf, + buffer: _malloc(width*height*4), }; return surf; }, @@ -26,7 +27,6 @@ mergeInto(Library, { surfData.image = surfData.ctx.getImageData(0, 0, surfData.width, surfData.height); // Copy pixel data to somewhere accessible to 'C/C++' var num = surfData.image.data.length; - surfData.buffer = _malloc(num); for (var i = 0; i < num; i++) { HEAP[surfData.buffer+i] = surfData.image.data[i]; } @@ -50,8 +50,6 @@ mergeInto(Library, { surfData.ctx.putImageData(surfData.image, 0, 0); // Cleanup surfData.image = null; - _free(surfData.buffer); - surfData.buffer = null; }, SDL_Flip: function(surf) { |