diff options
author | Felix H. Dahlke <fhd@ubercode.de> | 2013-07-17 00:26:30 +0200 |
---|---|---|
committer | Felix H. Dahlke <fhd@ubercode.de> | 2013-07-17 00:26:30 +0200 |
commit | f7a5c31270c96cf8fd28a0725460b33faa6b5db4 (patch) | |
tree | 17a28a0e07843dff9cdfea53552591c49a893999 | |
parent | 9bf755607fc7a0e7f446a5e2d6c82738d77d876f (diff) |
Implement SDL_Surface refcounting
-rw-r--r-- | src/library_sdl.js | 7 | ||||
-rwxr-xr-x | tests/runner.py | 3 | ||||
-rw-r--r-- | tests/sdl_surface_refcount.c | 14 |
3 files changed, 24 insertions, 0 deletions
diff --git a/src/library_sdl.js b/src/library_sdl.js index b7d73862..34c9551a 100644 --- a/src/library_sdl.js +++ b/src/library_sdl.js @@ -361,6 +361,13 @@ var LibrarySDL = { }, freeSurface: function(surf) { + var refcountPointer = surf + Runtime.QUANTUM_SIZE * 14; + var refcount = {{{ makeGetValue('refcountPointer', '0', 'i32') }}}; + if (refcount > 0) { + {{{ makeSetValue('refcountPointer', '0', 'refcount - 1', 'i32') }}}; + return; + } + var info = SDL.surfaces[surf]; if (!info.usePageCanvas && info.canvas) SDL.canvasPool.push(info.canvas); _free(info.buffer); diff --git a/tests/runner.py b/tests/runner.py index 0efcce86..6daa9c36 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -13172,6 +13172,9 @@ Press any key to continue.''' def test_sdl_alloctext(self): self.btest('sdl_alloctext.c', expected='1', args=['-O2', '-s', 'TOTAL_MEMORY=' + str(1024*1024*8)]) + def test_sdl_surface_refcount(self): + self.btest('sdl_surface_refcount.c', expected='1') + def test_glbegin_points(self): shutil.copyfile(path_from_root('tests', 'screenshot.png'), os.path.join(self.get_dir(), 'screenshot.png')) self.btest('glbegin_points.c', reference='glbegin_points.png', args=['--preload-file', 'screenshot.png']) diff --git a/tests/sdl_surface_refcount.c b/tests/sdl_surface_refcount.c new file mode 100644 index 00000000..4e9b4896 --- /dev/null +++ b/tests/sdl_surface_refcount.c @@ -0,0 +1,14 @@ +#include <SDL.h> + +int main(int argc, char *argv[]) +{ + SDL_Init(SDL_INIT_VIDEO); + SDL_Surface *screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE); + SDL_Surface *reference = screen; + reference->refcount++; + SDL_FreeSurface(screen); + SDL_FreeSurface(reference); + int result = 1; + REPORT_RESULT(); + return 0; +} |