As the content interface is now doing the scaling, we render to a native BitMap and then copy that to the RGBA32 bitmap buffer without re-scaling.

The native BitMap is currently discarded and will be re-created when it is displayed.
This commit is contained in:
Chris Young 2015-04-25 13:13:30 +01:00
parent 5b5e621c7a
commit c8caf08ef1
3 changed files with 49 additions and 52 deletions

View File

@ -236,6 +236,16 @@ static size_t bitmap_get_bpp(void *vbitmap)
return 4; return 4;
} }
static void ami_bitmap_argb_to_rgba(struct bitmap *bm)
{
if(bm == NULL) return;
ULONG *data = (ULONG *)amiga_bitmap_get_buffer(bm);
for(int i = 0; i < ((amiga_bitmap_get_rowstride(bm) / sizeof(ULONG)) * bm->height); i++) {
data[i] = (data[i] << 8) | (data[i] >> 24);
}
}
#ifdef BITMAP_DUMP #ifdef BITMAP_DUMP
void bitmap_dump(struct bitmap *bitmap) void bitmap_dump(struct bitmap *bitmap)
{ {
@ -508,76 +518,59 @@ struct BitMap *ami_bitmap_get_native(struct bitmap *bitmap,
static nserror bitmap_render(struct bitmap *bitmap, hlcache_handle *content) static nserror bitmap_render(struct bitmap *bitmap, hlcache_handle *content)
{ {
struct BitScaleArgs bsa;
int plot_width; int plot_width;
int plot_height; int plot_height;
int redraw_tile_size = nsoption_int(redraw_tile_size_x); struct MinList shared_pens;
struct gui_globals bm_globals;
struct redraw_context ctx = { struct redraw_context ctx = {
.interactive = false, .interactive = false,
.background_images = true, .background_images = true,
.plot = &amiplot .plot = &amiplot
}; };
if(nsoption_int(redraw_tile_size_y) < nsoption_int(redraw_tile_size_x)) plot_width = MIN(content_get_width(content), bitmap->width);
redraw_tile_size = nsoption_int(redraw_tile_size_y);
plot_width = MIN(content_get_width(content), redraw_tile_size);
plot_height = ((plot_width * bitmap->height) + (bitmap->width / 2)) / plot_height = ((plot_width * bitmap->height) + (bitmap->width / 2)) /
bitmap->width; bitmap->width;
bitmap->nativebm = ami_rtg_allocbitmap(bitmap->width, bitmap->height, 32, ami_init_layers(&bm_globals, bitmap->width, bitmap->height);
BMF_CLEAR, browserglob.bm, RGBFB_A8R8G8B8); NewMinList(&shared_pens);
bm_globals.shared_pens = &shared_pens;
bitmap->nativebmwidth = bitmap->width; glob = &bm_globals;
bitmap->nativebmheight = bitmap->height; ami_clearclipreg(&bm_globals);
ami_clearclipreg(&browserglob);
content_scaled_redraw(content, plot_width, plot_height, &ctx); content_scaled_redraw(content, plot_width, plot_height, &ctx);
#ifdef __amigaos4__ #ifdef __amigaos4__
if(__builtin_expect(GfxBase->LibNode.lib_Version >= 53, 1)) { /* Create a RGBA32 version in case we lose the native BitMap for some reason */
/* AutoDoc says v52, but this function isn't in OS4.0, so checking for v53 (OS4.1) */ BltBitMapTags( BLITA_SrcX, 0,
float resample_scale = bitmap->width / (float)plot_width; BLITA_SrcY, 0,
uint32 flags = COMPFLAG_IgnoreDestAlpha; BLITA_Width, bitmap->width,
if(nsoption_bool(scale_quality)) flags |= COMPFLAG_SrcFilter; BLITA_Height, bitmap->height,
BLITA_Source, bm_globals.bm,
CompositeTags(COMPOSITE_Src,browserglob.bm,bitmap->nativebm, BLITA_SrcType, BLITT_BITMAP,
COMPTAG_ScaleX, BLITA_Dest, bitmap->pixdata,
COMP_FLOAT_TO_FIX(resample_scale), BLITA_DestType, BLITT_ARGB32,
COMPTAG_ScaleY, BLITA_DestBytesPerRow, 4 * bitmap->width,
COMP_FLOAT_TO_FIX(resample_scale), BLITA_DestX, 0,
COMPTAG_Flags,flags, BLITA_DestY, 0,
COMPTAG_DestX,0,
COMPTAG_DestY,0,
COMPTAG_DestWidth,bitmap->width,
COMPTAG_DestHeight,bitmap->height,
COMPTAG_OffsetX,0,
COMPTAG_OffsetY,0,
COMPTAG_FriendBitMap, scrn->RastPort.BitMap,
TAG_DONE); TAG_DONE);
} else
ami_bitmap_argb_to_rgba(bitmap);
#else
#warning FIXME for OS3
#endif #endif
{
bsa.bsa_SrcX = 0;
bsa.bsa_SrcY = 0;
bsa.bsa_SrcWidth = plot_width;
bsa.bsa_SrcHeight = plot_height;
bsa.bsa_DestX = 0;
bsa.bsa_DestY = 0;
// bsa.bsa_DestWidth = width;
// bsa.bsa_DestHeight = height;
bsa.bsa_XSrcFactor = plot_width;
bsa.bsa_XDestFactor = bitmap->width;
bsa.bsa_YSrcFactor = plot_height;
bsa.bsa_YDestFactor = bitmap->height;
bsa.bsa_SrcBitMap = browserglob.bm;
bsa.bsa_DestBitMap = bitmap->nativebm;
bsa.bsa_Flags = 0;
BitMapScale(&bsa); /**\todo In theory we should be able to move the bitmap to our native area
} to try to avoid re-conversion */
return true; ami_free_layers(&bm_globals);
ami_plot_release_pens(&shared_pens);
amiga_bitmap_set_opaque(bitmap, true);
return NSERROR_OK;
} }
static struct gui_bitmap_table bitmap_table = { static struct gui_bitmap_table bitmap_table = {

View File

@ -115,6 +115,8 @@ void ami_init_layers(struct gui_globals *gg, ULONG width, ULONG height)
if(!width) width = nsoption_int(redraw_tile_size_x); if(!width) width = nsoption_int(redraw_tile_size_x);
if(!height) height = nsoption_int(redraw_tile_size_y); if(!height) height = nsoption_int(redraw_tile_size_y);
gg->width = width;
gg->height = height;
gg->layerinfo = NewLayerInfo(); gg->layerinfo = NewLayerInfo();
gg->areabuf = AllocVecTagList(AREA_SIZE, NULL); gg->areabuf = AllocVecTagList(AREA_SIZE, NULL);
@ -177,9 +179,9 @@ void ami_free_layers(struct gui_globals *gg)
FreeVec(gg->areabuf); FreeVec(gg->areabuf);
DisposeLayerInfo(gg->layerinfo); DisposeLayerInfo(gg->layerinfo);
if(palette_mapped == false) { if(palette_mapped == false) {
ami_rtg_freebitmap(gg->bm); if(gg->bm) ami_rtg_freebitmap(gg->bm);
} else { } else {
FreeBitMap(gg->bm); if(gg->bm) FreeBitMap(gg->bm);
} }
} }

View File

@ -33,6 +33,8 @@ struct gui_globals
APTR tmprasbuf; APTR tmprasbuf;
struct Rectangle rect; struct Rectangle rect;
struct MinList *shared_pens; struct MinList *shared_pens;
int width; /* size of bm and */
int height; /* associated memory */
}; };
extern const struct plotter_table amiplot; extern const struct plotter_table amiplot;