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 +++++++++++++++++++++++- amiga/bitmap.h | 4 +- amiga/plotters.c | 241 +------------------------------------------------------ 3 files changed, 112 insertions(+), 240 deletions(-) (limited to 'amiga') 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; +} diff --git a/amiga/bitmap.h b/amiga/bitmap.h index cf49ffab9..80ae166d5 100755 --- a/amiga/bitmap.h +++ b/amiga/bitmap.h @@ -1,5 +1,5 @@ /* - * Copyright 2008 Chris Young + * Copyright 2008,2009 Chris Young * * This file is part of NetSurf, http://www.netsurf-browser.org/ * @@ -31,4 +31,6 @@ struct bitmap { int nativebmheight; }; +struct BitMap *ami_getcachenativebm(struct bitmap *bitmap,int width,int height,struct BitMap *friendbm); + #endif diff --git a/amiga/plotters.c b/amiga/plotters.c index 1f1ed04d2..d32731608 100755 --- a/amiga/plotters.c +++ b/amiga/plotters.c @@ -29,7 +29,6 @@ #include #include "amiga/options.h" #include -#include #include "utils/log.h" #include #include @@ -386,148 +385,13 @@ CommonFuncsPPC.lha */ bool ami_bitmap(int x, int y, int width, int height, struct bitmap *bitmap, colour bg, struct content *content) { - struct RenderInfo ri; struct BitMap *tbm; - struct RastPort trp; if(!width || !height) return true; -// ami_fill(x,y,x+width,y+height,bg); + tbm = ami_getcachenativebm(bitmap,width,height,currp->BitMap); -/* - SetRPAttrs(currp,RPTAG_BPenColor,p96EncodeColor(RGBFB_A8B8G8R8,bg), - TAG_DONE); -*/ - - if(bitmap->nativebm) - { - if((bitmap->nativebmwidth != width) || (bitmap->nativebmheight != height)) - { - p96FreeBitMap(bitmap->nativebm); - bitmap->nativebm = NULL; - } - else - { - tbm = bitmap->nativebm; - } - } - - if(!bitmap->nativebm) - { - ri.Memory = bitmap->pixdata; - ri.BytesPerRow = bitmap->width * 4; - ri.RGBFormat = RGBFB_R8G8B8A8; - - tbm = p96AllocBitMap(bitmap->width,bitmap->height,32,BMF_DISPLAYABLE,currp->BitMap,RGBFB_R8G8B8A8); - InitRastPort(&trp); - trp.BitMap = tbm; - p96WritePixelArray((struct RenderInfo *)&ri,0,0,&trp,0,0,bitmap->width,bitmap->height); - - if((bitmap->width != width) || (bitmap->height != height)) - { - struct BitMap *scaledbm; - struct BitScaleArgs bsa; - - scaledbm = p96AllocBitMap(width,height,32,BMF_DISPLAYABLE,currp->BitMap,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,currp->BitMap, - 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); - } - - BltBitMapTags(BLITA_Width,width, - BLITA_Height,height, - BLITA_Source,scaledbm, - BLITA_Dest,currp, - BLITA_DestX,x, - BLITA_DestY,y, - BLITA_SrcType,BLITT_BITMAP, - BLITA_DestType,BLITT_RASTPORT, - BLITA_UseSrcAlpha,!bitmap->opaque, - TAG_DONE); - - if(option_cache_bitmaps >= 1) - { - if(bitmap->nativebm) - { - p96FreeBitMap(bitmap->nativebm); - } - - bitmap->nativebm = scaledbm; - } - else - { - p96FreeBitMap(scaledbm); - } - - p96FreeBitMap(tbm); - } - else - { - BltBitMapTags(BLITA_Width,width, - BLITA_Height,height, - BLITA_Source,tbm, - BLITA_Dest,currp, - BLITA_DestX,x, - BLITA_DestY,y, - BLITA_SrcType,BLITT_BITMAP, - BLITA_DestType,BLITT_RASTPORT, - BLITA_UseSrcAlpha,!bitmap->opaque, - TAG_DONE); - - if(option_cache_bitmaps == 2) - { - if(bitmap->nativebm) - { - p96FreeBitMap(bitmap->nativebm); - } - - bitmap->nativebm = tbm; - } - else - { - p96FreeBitMap(tbm); - } - } - - bitmap->nativebmwidth = width; - bitmap->nativebmheight = height; - } - else - { - BltBitMapTags(BLITA_Width,width, + BltBitMapTags(BLITA_Width,width, BLITA_Height,height, BLITA_Source,tbm, BLITA_Dest,currp, @@ -537,7 +401,6 @@ bool ami_bitmap(int x, int y, int width, int height, BLITA_DestType,BLITT_RASTPORT, BLITA_UseSrcAlpha,!bitmap->opaque, TAG_DONE); - } return true; } @@ -546,12 +409,9 @@ bool ami_bitmap_tile(int x, int y, int width, int height, struct bitmap *bitmap, colour bg, bool repeat_x, bool repeat_y, struct content *content) { - struct RenderInfo ri; ULONG xf,yf,wf,hf; int max_width,max_height; struct BitMap *tbm = NULL; - struct RastPort trp; - bool gotscaledbm = false; /* SetRPAttrs(currp,RPTAG_BPenColor,p96EncodeColor(RGBFB_A8B8G8R8,bg), @@ -561,102 +421,7 @@ bool ami_bitmap_tile(int x, int y, int width, int height, if(!(repeat_x || repeat_y)) return ami_bitmap(x, y, width, height, bitmap, bg, content); - if(bitmap->nativebm) - { - if((bitmap->nativebmwidth == width) && (bitmap->nativebmheight==height)) - { - tbm = bitmap->nativebm; - gotscaledbm = true; - } - 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 && !gotscaledbm) - { - ri.Memory = bitmap->pixdata; - ri.BytesPerRow = bitmap->width * 4; - ri.RGBFormat = RGBFB_R8G8B8A8; - - tbm = p96AllocBitMap(bitmap->width,bitmap->height,32,0,currp->BitMap,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)) - { - if(!gotscaledbm) - { - struct BitMap *scaledbm; - struct BitScaleArgs bsa; - - scaledbm = p96AllocBitMap(width,height,32,BMF_DISPLAYABLE,currp->BitMap,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,currp->BitMap, - 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; - } - } - } + tbm = ami_getcachenativebm(bitmap,width,height,currp->BitMap); /* get left most tile position */ if (repeat_x) -- cgit v1.2.3