From 781405d1952d9efe3a379e55c0384b7460e0f3a2 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Wed, 25 Feb 2009 19:56:04 +0000 Subject: Move native bitmap creation/caching routine into bitmap.c svn path=/trunk/netsurf/; revision=6619 --- amiga/bitmap.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 106 insertions(+), 1 deletion(-) (limited to 'amiga/bitmap.c') diff --git a/amiga/bitmap.c b/amiga/bitmap.c index 271f4af1b..47c2b424a 100644 --- a/amiga/bitmap.c +++ b/amiga/bitmap.c @@ -1,5 +1,5 @@ /* - * Copyright 2008 Chris Young + * Copyright 2008,2009 Chris Young * * This file is part of NetSurf, http://www.netsurf-browser.org/ * @@ -21,6 +21,8 @@ #include "amiga/bitmap.h" #include #include +#include +#include "amiga/options.h" /** * Create a bitmap. @@ -243,3 +245,106 @@ size_t bitmap_get_bpp(void *vbitmap) assert(bitmap); return 4; } + +struct BitMap *ami_getcachenativebm(struct bitmap *bitmap,int width,int height,struct BitMap *friendbm) +{ + struct RenderInfo ri; + struct BitMap *tbm = NULL; + struct RastPort trp; + + if(bitmap->nativebm) + { + if((bitmap->nativebmwidth == width) && (bitmap->nativebmheight==height)) + { + tbm = bitmap->nativebm; + return tbm; + } + else if((bitmap->nativebmwidth == bitmap->width) && (bitmap->nativebmheight==bitmap->height)) + { + tbm = bitmap->nativebm; + } + else + { + if(bitmap->nativebm) p96FreeBitMap(bitmap->nativebm); + bitmap->nativebm = NULL; + } + } + + if(!tbm) + { + ri.Memory = bitmap->pixdata; + ri.BytesPerRow = bitmap->width * 4; + ri.RGBFormat = RGBFB_R8G8B8A8; + + tbm = p96AllocBitMap(bitmap->width,bitmap->height,32,0,friendbm,RGBFB_R8G8B8A8); + InitRastPort(&trp); + trp.BitMap = tbm; + p96WritePixelArray((struct RenderInfo *)&ri,0,0,&trp,0,0,bitmap->width,bitmap->height); + + if(option_cache_bitmaps == 2) + { + bitmap->nativebm = tbm; + bitmap->nativebmwidth = bitmap->width; + bitmap->nativebmheight = bitmap->height; + } + } + + if((bitmap->width != width) || (bitmap->height != height)) + { + struct BitMap *scaledbm; + struct BitScaleArgs bsa; + + scaledbm = p96AllocBitMap(width,height,32,BMF_DISPLAYABLE,friendbm,RGBFB_R8G8B8A8); + + if(GfxBase->lib_Version >= 53) // AutoDoc says v52, but this function isn't in OS4.0, so checking for v53 (OS4.1) + { + CompositeTags(COMPOSITE_Src,tbm,scaledbm, + COMPTAG_ScaleX,COMP_FLOAT_TO_FIX(width/bitmap->width), + COMPTAG_ScaleY,COMP_FLOAT_TO_FIX(height/bitmap->height), + COMPTAG_Flags,COMPFLAG_IgnoreDestAlpha, + COMPTAG_DestX,0, + COMPTAG_DestY,0, + COMPTAG_DestWidth,width, + COMPTAG_DestHeight,height, + COMPTAG_OffsetX,0, + COMPTAG_OffsetY,0, + COMPTAG_FriendBitMap,friendbm, + TAG_DONE); + } + else /* do it the old-fashioned way. This is pretty slow, but probably + uses Composite() on OS4.1 anyway, so we're only saving a blit really. */ + { + bsa.bsa_SrcX = 0; + bsa.bsa_SrcY = 0; + bsa.bsa_SrcWidth = bitmap->width; + bsa.bsa_SrcHeight = bitmap->height; + bsa.bsa_DestX = 0; + bsa.bsa_DestY = 0; +// bsa.bsa_DestWidth = width; +// bsa.bsa_DestHeight = height; + bsa.bsa_XSrcFactor = bitmap->width; + bsa.bsa_XDestFactor = width; + bsa.bsa_YSrcFactor = bitmap->height; + bsa.bsa_YDestFactor = height; + bsa.bsa_SrcBitMap = tbm; + bsa.bsa_DestBitMap = scaledbm; + bsa.bsa_Flags = 0; + + BitMapScale(&bsa); + } + + if(bitmap->nativebm != tbm) p96FreeBitMap(bitmap->nativebm); + p96FreeBitMap(tbm); + tbm = scaledbm; + bitmap->nativebm = NULL; + + if(option_cache_bitmaps >= 1) + { + bitmap->nativebm = tbm; + bitmap->nativebmwidth = width; + bitmap->nativebmheight = height; + } + } + + return tbm; +} -- cgit v1.2.3