Allocate uncompressed bitmap data in extended memory.

This currently isn't working correctly - it simply freezes at some point after loading the page.
This commit is contained in:
Chris Young 2016-03-22 23:47:07 +00:00
parent 5382ad2aa6
commit 0804c43bf1
2 changed files with 74 additions and 5 deletions

View File

@ -40,6 +40,7 @@
#endif
#ifdef __amigaos4__
#include <exec/extmem.h>
#include <sys/param.h>
#endif
#include "assert.h"
@ -67,6 +68,8 @@ struct bitmap {
int width;
int height;
UBYTE *pixdata;
struct ExtMemIFace *iextmem;
uint32 size;
bool opaque;
int native;
struct BitMap *nativebm;
@ -113,7 +116,25 @@ void *amiga_bitmap_create(int width, int height, unsigned int state)
bitmap = ami_memory_itempool_alloc(pool_bitmap, sizeof(struct bitmap));
if(bitmap == NULL) return NULL;
bitmap->pixdata = ami_memory_clear_alloc(width*height*4, 0xff);
bitmap->size = width * height * 4;
#ifdef __amigaos4__
if(nsoption_bool(use_extmem) == true) {
uint64 size64 = bitmap->size;
bitmap->iextmem = AllocSysObjectTags(ASOT_EXTMEM,
ASOEXTMEM_Size, &size64,
ASOEXTMEM_AllocationPolicy, EXTMEMPOLICY_IMMEDIATE,
TAG_END);
bitmap->pixdata = NULL;
UBYTE *pixdata = amiga_bitmap_get_buffer(bitmap);
memset(pixdata, 0xff, bitmap->size);
} else
#endif
{
bitmap->pixdata = ami_memory_clear_alloc(bitmap->size, 0xff);
}
bitmap->width = width;
bitmap->height = height;
@ -133,11 +154,27 @@ void *amiga_bitmap_create(int width, int height, unsigned int state)
return bitmap;
}
static inline void amiga_bitmap_unmap_buffer(struct bitmap *bm)
{
#ifdef __amigaos4__
if((nsoption_bool(use_extmem) == true) && (bm->pixdata != NULL)) {
bm->iextmem->Unmap(bm->pixdata, bm->size);
bm->pixdata = NULL;
}
#endif
}
/* exported function documented in amiga/bitmap.h */
unsigned char *amiga_bitmap_get_buffer(void *bitmap)
{
struct bitmap *bm = bitmap;
#ifdef __amigaos4__
if((nsoption_bool(use_extmem) == true) && (bm->pixdata == NULL)) {
bm->pixdata = bm->iextmem->Map(NULL, bm->size, 0LL, 0);
}
#endif
return bm->pixdata;
}
@ -169,8 +206,17 @@ void amiga_bitmap_destroy(void *bitmap)
}
if(bm->native_mask) FreeRaster(bm->native_mask, bm->width, bm->height);
if(bm->drawhandle) ReleaseDrawHandle(bm->drawhandle);
ami_memory_clear_free(bm->pixdata);
#ifdef __amigaos4__
if(nsoption_bool(use_extmem) == true) {
amiga_bitmap_unmap_buffer(bm);
FreeSysObject(ASOT_EXTMEM, bm->iextmem);
} else
#endif
{
if(bm->drawhandle) ReleaseDrawHandle(bm->drawhandle);
ami_memory_clear_free(bm->pixdata);
}
if(bm->url) nsurl_unref(bm->url);
if(bm->title) free(bm->title);
@ -218,7 +264,11 @@ void amiga_bitmap_modified(void *bitmap)
{
struct bitmap *bm = bitmap;
if((bm->nativebm)) // && (bm->native == AMI_NSBM_TRUECOLOUR))
#ifdef __amigaos4__
amiga_bitmap_unmap_buffer(bm);
#endif
if((bm->nativebm))
ami_rtg_freebitmap(bm->nativebm);
if(bm->drawhandle) ReleaseDrawHandle(bm->drawhandle);
@ -387,6 +437,10 @@ Object *ami_datatype_object_from_bitmap(struct bitmap *bitmap)
bitmap_get_width(bitmap), bitmap_get_height(bitmap));
}
#ifdef __amigaos4__
amiga_bitmap_unmap_buffer(bitmap);
#endif
return dto;
}
@ -416,6 +470,10 @@ struct bitmap *ami_bitmap_from_datatype(char *filename)
DisposeDTObject(dto);
}
#ifdef __amigaos4__
amiga_bitmap_unmap_buffer(bm);
#endif
return bm;
}
@ -587,6 +645,10 @@ static inline struct BitMap *ami_bitmap_get_generic(struct bitmap *bitmap,
}
}
#ifdef __amigaos4__
amiga_bitmap_unmap_buffer(bitmap);
#endif
return tbm;
}
@ -706,6 +768,10 @@ static nserror bitmap_render(struct bitmap *bitmap, struct hlcache_handle *conte
ami_free_layers(&bm_globals);
amiga_bitmap_set_opaque(bitmap, true);
#ifdef __amigaos4__
amiga_bitmap_unmap_buffer(bitmap);
#endif
/* Restore previous render area. This is set when plotting starts,
* but if bitmap_render is called *during* a browser render then
* having an invalid pointer here causes NetSurf to crash.

View File

@ -89,8 +89,11 @@ NSOPTION_INTEGER(monitor_aspect_x, 0)
NSOPTION_INTEGER(monitor_aspect_y, 0)
NSOPTION_BOOL(accept_lang_locale, true)
NSOPTION_STRING(local_charset, "ISO-8859-1")
#ifdef __amigaos4__
/* Options relevant for OS4 only */
NSOPTION_BOOL(use_extmem, true)
#else
/* Options relevant for OS3 only */
#ifndef __amigaos4__
NSOPTION_BOOL(friend_bitmap, false)
#endif