From 0cc19b10fcd9f43bb4c9d83654d2d07cad139b12 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Thu, 21 Jan 2016 20:30:02 +0000 Subject: alloc bitmap structures using itempools --- amiga/bitmap.c | 43 ++++++++++++++++++++++++++++++++----------- amiga/bitmap.h | 3 +++ amiga/gui.c | 18 ++++++++++++++---- 3 files changed, 49 insertions(+), 15 deletions(-) diff --git a/amiga/bitmap.c b/amiga/bitmap.c index 6984d3e0c..5ba74020c 100644 --- a/amiga/bitmap.c +++ b/amiga/bitmap.c @@ -44,21 +44,28 @@ #include "amiga/misc.h" #include "amiga/rtg.h" +static APTR pool_bitmap = NULL; + /* exported function documented in amiga/bitmap.h */ void *amiga_bitmap_create(int width, int height, unsigned int state) { struct bitmap *bitmap; - - bitmap = ami_misc_allocvec_clear(sizeof(struct bitmap), 0); - if(bitmap) - { - bitmap->pixdata = ami_misc_allocvec_clear(width*height*4, 0xff); - bitmap->width = width; - bitmap->height = height; - if(state & BITMAP_OPAQUE) bitmap->opaque = true; - else bitmap->opaque = false; - } + bitmap = ami_misc_itempool_alloc(pool_bitmap, sizeof(struct bitmap)); + if(bitmap == NULL) return NULL; + + bitmap->pixdata = ami_misc_allocvec_clear(width*height*4, 0xff); + bitmap->width = width; + bitmap->height = height; + + if(state & BITMAP_OPAQUE) bitmap->opaque = true; + else bitmap->opaque = false; + + bitmap->nativebm = NULL; + bitmap->nativebmwidth = 0; + bitmap->nativebmheight = 0; + bitmap->native_mask = NULL; + bitmap->dto = NULL; return bitmap; } @@ -109,7 +116,7 @@ void amiga_bitmap_destroy(void *bitmap) bm->native_mask = NULL; bm->dto = NULL; - FreeVec(bm); + ami_misc_itempool_free(pool_bitmap, bm, sizeof(struct bitmap)); bm = NULL; } } @@ -582,6 +589,20 @@ static nserror bitmap_render(struct bitmap *bitmap, hlcache_handle *content) return NSERROR_OK; } +void amiga_bitmap_fini(void) +{ + if(pool_bitmap) ami_misc_itempool_delete(pool_bitmap); +} + +bool amiga_bitmap_init(void) +{ + if((pool_bitmap = ami_misc_itempool_create(sizeof(struct bitmap)))) { + return true; + } else { + return false; + } +} + static struct gui_bitmap_table bitmap_table = { .create = amiga_bitmap_create, .destroy = amiga_bitmap_destroy, diff --git a/amiga/bitmap.h b/amiga/bitmap.h index ff1b01c6e..4607d9f99 100755 --- a/amiga/bitmap.h +++ b/amiga/bitmap.h @@ -53,6 +53,9 @@ PLANEPTR ami_bitmap_get_mask(struct bitmap *bitmap, int width, Object *ami_datatype_object_from_bitmap(struct bitmap *bitmap); struct bitmap *ami_bitmap_from_datatype(char *filename); +void amiga_bitmap_fini(void); +bool amiga_bitmap_init(void); + #ifndef __amigaos4__ void ami_bitmap_argb_to_rgba(struct bitmap *bm); #endif diff --git a/amiga/gui.c b/amiga/gui.c index 58e7938fd..9aedad86f 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -405,8 +405,21 @@ bool ami_locate_resource(char *fullpath, const char *file) return found; } +/* Frees stuff opened by ami_open_resources() */ +static void ami_resources_free(void) +{ + FreeSysObject(ASOT_PORT, appport); + FreeSysObject(ASOT_PORT, sport); + FreeSysObject(ASOT_PORT, schedulermsgport); + + FreeStringClass(urlStringClass); + amiga_bitmap_fini(); +} + static bool ami_open_resources(void) { + if(!amiga_bitmap_init()) return false; + urlStringClass = MakeStringClass(); if(!(appport = AllocSysObjectTags(ASOT_PORT, @@ -3034,13 +3047,10 @@ static void gui_quit(void) LOG("Freeing scheduler resources"); ami_schedule_free(); - FreeSysObject(ASOT_PORT, appport); - FreeSysObject(ASOT_PORT, sport); - FreeSysObject(ASOT_PORT, schedulermsgport); + ami_resources_free(); ami_file_req_free(); ami_openurl_close(); - FreeStringClass(urlStringClass); FreeObjList(window_list); -- cgit v1.2.3