Allocate bitmap structures using an itempool

This commit is contained in:
Chris Young 2016-01-29 19:39:37 +00:00
parent b002ba7357
commit e6b827979b
3 changed files with 18 additions and 3 deletions

View File

@ -52,13 +52,16 @@ enum {
AMI_NSBM_PALETTEMAPPED
};
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 = AllocVecTagList(sizeof(struct bitmap), NULL);
if(pool_bitmap == NULL) pool_bitmap = ami_misc_itempool_create(sizeof(struct bitmap));
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);
@ -128,7 +131,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;
}
}
@ -557,6 +560,12 @@ struct BitMap *ami_bitmap_get_native(struct bitmap *bitmap,
}
}
void ami_bitmap_fini(void)
{
if(pool_bitmap) ami_misc_itempool_delete(pool_bitmap);
pool_bitmap = NULL;
}
static nserror bitmap_render(struct bitmap *bitmap, hlcache_handle *content)
{
struct redraw_context ctx = {

View File

@ -54,6 +54,11 @@ 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);
/**
* Cleanup bitmap allocations
*/
void ami_bitmap_fini(void);
/**
* Create a bitmap.
*

View File

@ -5681,6 +5681,7 @@ int main(int argc, char** argv)
FreeSysObject(ASOT_PORT, schedulermsgport);
ami_object_fini();
ami_bitmap_fini();
ami_libs_close();
return RETURN_OK;