From 002c3c1a7c2ae7229afac3f1966892fd42895aec Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Thu, 24 Mar 2022 18:09:28 +0000 Subject: [PATCH] Bitmap API: Clean up creation flags. --- content/handlers/image/bmp.c | 4 +-- content/handlers/image/gif.c | 2 +- content/handlers/image/ico.c | 4 +-- content/handlers/image/jpeg.c | 2 +- content/handlers/image/nssprite.c | 2 +- content/handlers/image/png.c | 4 +-- content/handlers/image/rsvg.c | 2 +- content/handlers/image/webp.c | 4 +-- .../duktape/CanvasRenderingContext2D.bnd | 6 ++-- desktop/browser_history.c | 4 +-- desktop/treeview.c | 6 ++-- frontends/amiga/bitmap.c | 5 ++- frontends/amiga/bitmap.h | 6 ++-- frontends/amiga/dt_anim.c | 2 +- frontends/amiga/dt_picture.c | 2 +- frontends/amiga/icon.c | 2 +- frontends/atari/bitmap.c | 32 +++++++++---------- frontends/atari/bitmap.h | 2 +- frontends/atari/plot/font_freetype.c | 1 + frontends/atari/plot/font_internal.c | 1 + frontends/beos/bitmap.cpp | 18 +++++------ frontends/framebuffer/bitmap.c | 13 +++----- frontends/gtk/bitmap.c | 8 ++--- frontends/monkey/bitmap.c | 27 +++++++--------- frontends/riscos/bitmap.c | 14 ++++---- frontends/riscos/bitmap.h | 9 +++--- frontends/riscos/save.c | 2 +- frontends/riscos/window.c | 2 +- frontends/windows/bitmap.c | 14 ++++---- frontends/windows/bitmap.h | 2 -- include/netsurf/bitmap.h | 17 ++++++---- 31 files changed, 107 insertions(+), 112 deletions(-) diff --git a/content/handlers/image/bmp.c b/content/handlers/image/bmp.c index 6ef4aacdf..5f9708be4 100644 --- a/content/handlers/image/bmp.c +++ b/content/handlers/image/bmp.c @@ -57,12 +57,12 @@ typedef struct nsbmp_content { */ static void *nsbmp_bitmap_create(int width, int height, unsigned int bmp_state) { - unsigned int bitmap_state = BITMAP_NEW; + unsigned int bitmap_state = BITMAP_NONE; /* set bitmap state based on bmp state */ bitmap_state |= (bmp_state & BMP_OPAQUE) ? BITMAP_OPAQUE : 0; bitmap_state |= (bmp_state & BMP_CLEAR_MEMORY) ? - BITMAP_CLEAR_MEMORY : 0; + BITMAP_CLEAR : 0; /* return the created bitmap */ return guit->bitmap->create(width, height, bitmap_state); diff --git a/content/handlers/image/gif.c b/content/handlers/image/gif.c index 9ecc472bd..f06805d12 100644 --- a/content/handlers/image/gif.c +++ b/content/handlers/image/gif.c @@ -88,7 +88,7 @@ static inline nserror gif__nsgif_error_to_ns(nsgif_error gif_res) */ static void *gif_bitmap_create(int width, int height) { - return guit->bitmap->create(width, height, BITMAP_NEW); + return guit->bitmap->create(width, height, BITMAP_NONE); } static nserror gif_create_gif_data(gif_content *c) diff --git a/content/handlers/image/ico.c b/content/handlers/image/ico.c index 63ca254ba..ac617f79e 100644 --- a/content/handlers/image/ico.c +++ b/content/handlers/image/ico.c @@ -54,12 +54,12 @@ typedef struct nsico_content { */ static void *nsico_bitmap_create(int width, int height, unsigned int bmp_state) { - unsigned int bitmap_state = BITMAP_NEW; + unsigned int bitmap_state = BITMAP_NONE; /* set bitmap state based on bmp state */ bitmap_state |= (bmp_state & BMP_OPAQUE) ? BITMAP_OPAQUE : 0; bitmap_state |= (bmp_state & BMP_CLEAR_MEMORY) ? - BITMAP_CLEAR_MEMORY : 0; + BITMAP_CLEAR : 0; /* return the created bitmap */ return guit->bitmap->create(width, height, bitmap_state); diff --git a/content/handlers/image/jpeg.c b/content/handlers/image/jpeg.c index 549c2b674..9daf06b3f 100644 --- a/content/handlers/image/jpeg.c +++ b/content/handlers/image/jpeg.c @@ -235,7 +235,7 @@ jpeg_cache_convert(struct content *c) height = cinfo.output_height; /* create opaque bitmap (jpegs cannot be transparent) */ - bitmap = guit->bitmap->create(width, height, BITMAP_NEW | BITMAP_OPAQUE); + bitmap = guit->bitmap->create(width, height, BITMAP_OPAQUE); if (bitmap == NULL) { /* empty bitmap could not be created */ jpeg_destroy_decompress(&cinfo); diff --git a/content/handlers/image/nssprite.c b/content/handlers/image/nssprite.c index a4ce6b574..a6c2909f8 100644 --- a/content/handlers/image/nssprite.c +++ b/content/handlers/image/nssprite.c @@ -116,7 +116,7 @@ static bool nssprite_convert(struct content *c) struct rosprite* sprite = sprite_area->sprites[0]; - nssprite->bitmap = guit->bitmap->create(sprite->width, sprite->height, BITMAP_NEW); + nssprite->bitmap = guit->bitmap->create(sprite->width, sprite->height, BITMAP_NONE); if (!nssprite->bitmap) { content_broadcast_error(c, NSERROR_NOMEM, NULL); return false; diff --git a/content/handlers/image/png.c b/content/handlers/image/png.c index a1db3f697..d4c2ae061 100644 --- a/content/handlers/image/png.c +++ b/content/handlers/image/png.c @@ -163,7 +163,7 @@ static void info_callback(png_structp png_s, png_infop info) } /* Claim the required memory for the converted PNG */ - png_c->bitmap = guit->bitmap->create(width, height, BITMAP_NEW); + png_c->bitmap = guit->bitmap->create(width, height, BITMAP_NONE); if (png_c->bitmap == NULL) { /* Failed to create bitmap skip pre-conversion */ longjmp(png_jmpbuf(png_s), CBERR_NOPRE); @@ -483,7 +483,7 @@ png_cache_convert(struct content *c) height = png_get_image_height(png_ptr, info_ptr); /* Claim the required memory for the converted PNG */ - bitmap = guit->bitmap->create(width, height, BITMAP_NEW); + bitmap = guit->bitmap->create(width, height, BITMAP_NONE); if (bitmap == NULL) { /* cleanup and bail */ goto png_cache_convert_error; diff --git a/content/handlers/image/rsvg.c b/content/handlers/image/rsvg.c index 0051df38f..46179985a 100644 --- a/content/handlers/image/rsvg.c +++ b/content/handlers/image/rsvg.c @@ -187,7 +187,7 @@ static bool rsvg_convert(struct content *c) c->height = rsvgsize.height; if ((d->bitmap = guit->bitmap->create(c->width, c->height, - BITMAP_NEW)) == NULL) { + BITMAP_NONE)) == NULL) { NSLOG(netsurf, INFO, "Failed to create bitmap for rsvg render."); content_broadcast_error(c, NSERROR_NOMEM, NULL); diff --git a/content/handlers/image/webp.c b/content/handlers/image/webp.c index 721e92438..59667a883 100644 --- a/content/handlers/image/webp.c +++ b/content/handlers/image/webp.c @@ -107,9 +107,9 @@ webp_cache_convert(struct content *c) } if (webpfeatures.has_alpha == 0) { - bmap_flags = BITMAP_NEW | BITMAP_OPAQUE; + bmap_flags = BITMAP_OPAQUE; } else { - bmap_flags = BITMAP_NEW; + bmap_flags = BITMAP_NONE; } /* create bitmap */ diff --git a/content/handlers/javascript/duktape/CanvasRenderingContext2D.bnd b/content/handlers/javascript/duktape/CanvasRenderingContext2D.bnd index db3c4efa3..2fe73f4e1 100644 --- a/content/handlers/javascript/duktape/CanvasRenderingContext2D.bnd +++ b/content/handlers/javascript/duktape/CanvasRenderingContext2D.bnd @@ -90,7 +90,7 @@ canvas2d_user_data_handler(dom_node_operation operation, height = guit->bitmap->get_height(bitmap); stride = guit->bitmap->get_rowstride(bitmap); newbitmap = guit->bitmap->create(width, height, - BITMAP_NEW); + BITMAP_NONE); if (newbitmap != NULL) { if (guit->bitmap->get_rowstride(newbitmap) == stride) { // Compatible bitmap, bung the data over @@ -173,7 +173,7 @@ static nserror canvas2d_create_bitmap(dom_node *node, struct bitmap **bitmap_out bitmap = guit->bitmap->create( (int)width, (int)height, - BITMAP_NEW); + BITMAP_NONE); if (bitmap == NULL) { return NSERROR_NOMEM; @@ -242,7 +242,7 @@ canvas2d__handle_dom_event(dom_event *evt, void *pw) /* Okay, we need to reallocate our bitmap and re-cache values */ - newbitmap = guit->bitmap->create(width, height, BITMAP_NEW); + newbitmap = guit->bitmap->create(width, height, BITMAP_NONE); stride = guit->bitmap->get_rowstride(newbitmap); if (newbitmap != NULL) { diff --git a/desktop/browser_history.c b/desktop/browser_history.c index 2fbc80f89..ce9821af8 100644 --- a/desktop/browser_history.c +++ b/desktop/browser_history.c @@ -106,7 +106,7 @@ browser_window_history__clone_entry(struct history *history, new_entry->page.bitmap = guit->bitmap->create( LOCAL_HISTORY_WIDTH, LOCAL_HISTORY_HEIGHT, - BITMAP_NEW | BITMAP_OPAQUE); + BITMAP_OPAQUE); if (new_entry->page.bitmap != NULL) { bmsrc_data = guit->bitmap->get_buffer(entry->page.bitmap); @@ -388,7 +388,7 @@ browser_window_history_add(struct browser_window *bw, entry->page.bitmap = guit->bitmap->create( LOCAL_HISTORY_WIDTH, LOCAL_HISTORY_HEIGHT, - BITMAP_NEW | BITMAP_CLEAR_MEMORY | BITMAP_OPAQUE); + BITMAP_CLEAR | BITMAP_OPAQUE); if (entry->page.bitmap != NULL) { ret = guit->bitmap->render(entry->page.bitmap, content); if (ret != NSERROR_OK) { diff --git a/desktop/treeview.c b/desktop/treeview.c index feb1a7c6e..d49be0fa8 100644 --- a/desktop/treeview.c +++ b/desktop/treeview.c @@ -5077,7 +5077,7 @@ treeview_generate_triangle_bitmap(colour bg, colour fg, int size) colour colour4 = fg; /* Create the bitmap */ - b = guit->bitmap->create(size, size, BITMAP_NEW | BITMAP_OPAQUE); + b = guit->bitmap->create(size, size, BITMAP_OPAQUE); if (b == NULL) return NULL; @@ -5176,7 +5176,7 @@ treeview_generate_copy_bitmap(struct bitmap *orig, int size) assert(size == guit->bitmap->get_height(orig)); /* Create the bitmap */ - b = guit->bitmap->create(size, size, BITMAP_NEW | BITMAP_OPAQUE); + b = guit->bitmap->create(size, size, BITMAP_OPAQUE); if (b == NULL) return NULL; @@ -5224,7 +5224,7 @@ treeview_generate_rotate_bitmap(struct bitmap *orig, int size) assert(size == guit->bitmap->get_height(orig)); /* Create the bitmap */ - b = guit->bitmap->create(size, size, BITMAP_NEW | BITMAP_OPAQUE); + b = guit->bitmap->create(size, size, BITMAP_OPAQUE); if (b == NULL) return NULL; diff --git a/frontends/amiga/bitmap.c b/frontends/amiga/bitmap.c index ec1a90a24..c39f3842c 100644 --- a/frontends/amiga/bitmap.c +++ b/frontends/amiga/bitmap.c @@ -108,7 +108,7 @@ static APTR pool_bitmap = NULL; static bool guigfx_warned = false; /* exported function documented in amiga/bitmap.h */ -void *amiga_bitmap_create(int width, int height, unsigned int state) +void *amiga_bitmap_create(int width, int height, enum gui_bitmap_flags flags) { struct bitmap *bitmap; @@ -139,8 +139,7 @@ void *amiga_bitmap_create(int width, int height, unsigned int state) bitmap->width = width; bitmap->height = height; - if(state & BITMAP_OPAQUE) bitmap->opaque = true; - else bitmap->opaque = false; + bitmap->opaque = (flags & BITMAP_OPAQUE) == BITMAP_OPAQUE; bitmap->nativebm = NULL; bitmap->nativebmwidth = 0; diff --git a/frontends/amiga/bitmap.h b/frontends/amiga/bitmap.h index aaec26ac2..ae072c0cd 100755 --- a/frontends/amiga/bitmap.h +++ b/frontends/amiga/bitmap.h @@ -25,6 +25,8 @@ #include #include +#include "netsurf/bitmap.h" + #define AMI_BITMAP_FORMAT RGBFB_R8G8B8A8 #define AMI_BITMAP_SCALE_ICON 0xFF @@ -101,10 +103,10 @@ void ami_bitmap_fini(void); * * \param width width of image in pixels * \param height width of image in pixels - * \param state a flag word indicating the initial state + * \param flags flags for bitmap creation * \return an opaque struct bitmap, or NULL on memory exhaustion */ -void *amiga_bitmap_create(int width, int height, unsigned int state); +void *amiga_bitmap_create(int width, int height, enum gui_bitmap_flags flags); /** * Return a pointer to the pixel data in a bitmap. diff --git a/frontends/amiga/dt_anim.c b/frontends/amiga/dt_anim.c index a9fe809cf..1162d7214 100644 --- a/frontends/amiga/dt_anim.c +++ b/frontends/amiga/dt_anim.c @@ -173,7 +173,7 @@ bool amiga_dt_anim_convert(struct content *c) size_t size; UBYTE *bm_buffer; struct BitMapHeader *bmh; - unsigned int bm_flags = BITMAP_NEW | BITMAP_OPAQUE; + unsigned int bm_flags = BITMAP_OPAQUE; struct adtFrame adt_frame; APTR clut; diff --git a/frontends/amiga/dt_picture.c b/frontends/amiga/dt_picture.c index ed1272bc1..f84e0e016 100644 --- a/frontends/amiga/dt_picture.c +++ b/frontends/amiga/dt_picture.c @@ -187,7 +187,7 @@ static struct bitmap *amiga_dt_picture_cache_convert(struct content *c) if((dto = amiga_dt_picture_newdtobject(adt))) { - bitmap = amiga_bitmap_create(c->width, c->height, BITMAP_NEW); + bitmap = amiga_bitmap_create(c->width, c->height, BITMAP_NONE); if (!bitmap) { msg_data.errordata.errorcode = NSERROR_NOMEM; msg_data.errordata.errormsg = messages_get("NoMemory"); diff --git a/frontends/amiga/icon.c b/frontends/amiga/icon.c index 001874c86..2b7f61281 100644 --- a/frontends/amiga/icon.c +++ b/frontends/amiga/icon.c @@ -201,7 +201,7 @@ bool amiga_icon_convert(struct content *c) return false; } - icon_c->bitmap = amiga_bitmap_create(width, height, BITMAP_NEW); + icon_c->bitmap = amiga_bitmap_create(width, height, BITMAP_NONE); if (!icon_c->bitmap) { msg_data.errordata.errorcode = NSERROR_NOMEM; msg_data.errordata.errormsg = messages_get("NoMemory"); diff --git a/frontends/atari/bitmap.c b/frontends/atari/bitmap.c index 5ac15ad4f..8c467c7d6 100644 --- a/frontends/atari/bitmap.c +++ b/frontends/atari/bitmap.c @@ -77,36 +77,36 @@ int init_mfdb(int bpp, int w, int h, uint32_t flags, MFDB * out ) * \param pixdata NULL or an memory address to use as the bitmap pixdata * \return an opaque struct bitmap, or NULL on memory exhaustion */ -static void *atari_bitmap_create_ex( int w, int h, short bpp, int rowstride, unsigned int state, void * pixdata ) +static void *atari_bitmap_create_ex( int w, int h, short bpp, int rowstride, enum gui_bitmap_flags flags, void * pixdata ) { - struct bitmap * bitmap; + struct bitmap * bitmap; - NSLOG(netsurf, INFO, - "width %d (rowstride: %d, bpp: %d), height %d, state %u", w, - rowstride, bpp, h, state); + NSLOG(netsurf, INFO, + "width %d (rowstride: %d, bpp: %d), height %d, flags %u", w, + rowstride, bpp, h, (unsigned)flags); if( rowstride == 0) { rowstride = bpp * w; } assert( rowstride >= (w * bpp) ); - bitmap = calloc(1 , sizeof(struct bitmap) ); - if (bitmap) { + bitmap = calloc(1 , sizeof(struct bitmap) ); + if (bitmap) { if( pixdata == NULL) { - bitmap->pixdata = calloc(1, (rowstride * h)+128); + bitmap->pixdata = calloc(1, (rowstride * h)+128); } else { bitmap->pixdata = pixdata; } - if (bitmap->pixdata != NULL) { + if (bitmap->pixdata != NULL) { bitmap->width = w; bitmap->height = h; - bitmap->opaque = (state & BITMAP_OPAQUE) ? true : false; + bitmap->opaque = (flags & BITMAP_OPAQUE) ? true : false; bitmap->bpp = bpp; bitmap->resized = NULL; bitmap->rowstride = rowstride; - } else { + } else { free(bitmap); bitmap=NULL; NSLOG(netsurf, INFO, "Out of memory!"); @@ -118,9 +118,9 @@ static void *atari_bitmap_create_ex( int w, int h, short bpp, int rowstride, uns /* exported interface documented in atari/bitmap.h */ -void *atari_bitmap_create(int w, int h, unsigned int state) +void *atari_bitmap_create(int w, int h, enum gui_bitmap_flags flags) { - return atari_bitmap_create_ex( w, h, NS_BMP_DEFAULT_BPP, w * NS_BMP_DEFAULT_BPP, state, NULL ); + return atari_bitmap_create_ex( w, h, NS_BMP_DEFAULT_BPP, w * NS_BMP_DEFAULT_BPP, flags, NULL ); } /** @@ -347,7 +347,7 @@ int atari_bitmap_get_height(void *bitmap) bool atari_bitmap_resize(struct bitmap *img, HermesHandle hermes_h, HermesFormat *fmt, int nw, int nh) { - unsigned int state = 0; + enum gui_bitmap_flags flags = 0; short bpp = img->bpp; int stride = atari_bitmap_get_rowstride( img ); int err; @@ -364,9 +364,9 @@ bool atari_bitmap_resize(struct bitmap *img, HermesHandle hermes_h, /* allocate the mem for resized bitmap */ if (img->opaque == true) { - state |= BITMAP_OPAQUE; + flags |= BITMAP_OPAQUE; } - img->resized = atari_bitmap_create_ex( nw, nh, bpp, nw*bpp, state, NULL ); + img->resized = atari_bitmap_create_ex( nw, nh, bpp, nw*bpp, flags, NULL ); if( img->resized == NULL ) { printf("W: %d, H: %d, bpp: %d\n", nw, nh, bpp); assert(img->resized); diff --git a/frontends/atari/bitmap.h b/frontends/atari/bitmap.h index 72bad555e..88985ad3c 100644 --- a/frontends/atari/bitmap.h +++ b/frontends/atari/bitmap.h @@ -90,7 +90,7 @@ int init_mfdb(int bpp, int w, int h, uint32_t flags, MFDB * out ); * \param state a flag word indicating the initial state * \return an opaque struct bitmap, or NULL on memory exhaustion */ -void *atari_bitmap_create(int w, int h, unsigned int state); +void *atari_bitmap_create(int w, int h, enum gui_bitmap_flags flags); /** * Find the width of a pixel row in bytes. diff --git a/frontends/atari/plot/font_freetype.c b/frontends/atari/plot/font_freetype.c index f8109f6f2..3ff4ab115 100644 --- a/frontends/atari/plot/font_freetype.c +++ b/frontends/atari/plot/font_freetype.c @@ -25,6 +25,7 @@ #include "utils/log.h" #include "utils/nsoption.h" #include "netsurf/mouse.h" +#include "netsurf/bitmap.h" #include "netsurf/plot_style.h" #include "atari/gui.h" diff --git a/frontends/atari/plot/font_internal.c b/frontends/atari/plot/font_internal.c index 709697f74..11732c5ea 100644 --- a/frontends/atari/plot/font_internal.c +++ b/frontends/atari/plot/font_internal.c @@ -25,6 +25,7 @@ #include "utils/utf8.h" #include "utils/log.h" #include "netsurf/mouse.h" +#include "netsurf/bitmap.h" #include "netsurf/plot_style.h" #include "atari/gui.h" diff --git a/frontends/beos/bitmap.cpp b/frontends/beos/bitmap.cpp index 7b6d00d1a..83e69fce5 100644 --- a/frontends/beos/bitmap.cpp +++ b/frontends/beos/bitmap.cpp @@ -114,28 +114,28 @@ static inline void nsbeos_rgba_to_bgra(void *src, * Create a bitmap. * * \param width width of image in pixels - * \param height width of image in pixels - * \param state a flag word indicating the initial state + * \param height height of image in pixels + * \param bflags flags for bitmap creation * \return an opaque struct bitmap, or NULL on memory exhaustion */ -static void *bitmap_create(int width, int height, unsigned int state) +static void *bitmap_create(int width, int height, enum gui_bitmap_flags flags) { struct bitmap *bmp = (struct bitmap *)malloc(sizeof(struct bitmap)); if (bmp == NULL) return NULL; - int32 flags = 0; - if (state & BITMAP_CLEAR_MEMORY) - flags |= B_BITMAP_CLEAR_TO_WHITE; + int32 Bflags = 0; + if (flags & BITMAP_CLEAR) + Bflags |= B_BITMAP_CLEAR_TO_WHITE; BRect frame(0, 0, width - 1, height - 1); //XXX: bytes per row ? - bmp->primary = new BBitmap(frame, flags, B_RGBA32); - bmp->shadow = new BBitmap(frame, flags, B_RGBA32); + bmp->primary = new BBitmap(frame, Bflags, B_RGBA32); + bmp->shadow = new BBitmap(frame, Bflags, B_RGBA32); bmp->pretile_x = bmp->pretile_y = bmp->pretile_xy = NULL; - bmp->opaque = (state & BITMAP_OPAQUE) != 0; + bmp->opaque = (flags & BITMAP_OPAQUE) != 0; return bmp; } diff --git a/frontends/framebuffer/bitmap.c b/frontends/framebuffer/bitmap.c index 7b522f262..9fb5db159 100644 --- a/frontends/framebuffer/bitmap.c +++ b/frontends/framebuffer/bitmap.c @@ -47,19 +47,16 @@ * \param state a flag word indicating the initial state * \return an opaque struct bitmap, or NULL on memory exhaustion */ -static void *bitmap_create(int width, int height, unsigned int state) +static void *bitmap_create(int width, int height, enum gui_bitmap_flags flags) { - nsfb_t *bm; - - NSLOG(netsurf, INFO, "width %d, height %d, state %u", width, height, - state); + nsfb_t *bm; bm = nsfb_new(NSFB_SURFACE_RAM); if (bm == NULL) { return NULL; } - if ((state & BITMAP_OPAQUE) == 0) { + if ((flags & BITMAP_OPAQUE) == 0) { nsfb_set_geometry(bm, width, height, NSFB_FMT_ABGR8888); } else { nsfb_set_geometry(bm, width, height, NSFB_FMT_XBGR8888); @@ -70,9 +67,7 @@ static void *bitmap_create(int width, int height, unsigned int state) return NULL; } - NSLOG(netsurf, INFO, "bitmap %p", bm); - - return bm; + return bm; } diff --git a/frontends/gtk/bitmap.c b/frontends/gtk/bitmap.c index cafe22262..1f1a6dcd2 100644 --- a/frontends/gtk/bitmap.c +++ b/frontends/gtk/bitmap.c @@ -45,17 +45,17 @@ * Create a bitmap. * * \param width width of image in pixels - * \param height width of image in pixels - * \param state a flag word indicating the initial state + * \param height height of image in pixels + * \param flags flags for bitmap creation * \return an opaque struct bitmap, or NULL on memory exhaustion */ -static void *bitmap_create(int width, int height, unsigned int state) +static void *bitmap_create(int width, int height, enum gui_bitmap_flags flags) { struct bitmap *gbitmap; gbitmap = calloc(1, sizeof(struct bitmap)); if (gbitmap != NULL) { - if ((state & BITMAP_OPAQUE) != 0) { + if ((flags & BITMAP_OPAQUE) != 0) { gbitmap->surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, width, height); } else { gbitmap->surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); diff --git a/frontends/monkey/bitmap.c b/frontends/monkey/bitmap.c index ba3b83cf5..36016988c 100644 --- a/frontends/monkey/bitmap.c +++ b/frontends/monkey/bitmap.c @@ -31,26 +31,26 @@ struct bitmap { size_t rowstride; int width; int height; - unsigned int state; + bool opaque; }; -static void *bitmap_create(int width, int height, unsigned int state) +static void *bitmap_create(int width, int height, enum gui_bitmap_flags flags) { struct bitmap *ret = calloc(sizeof(*ret), 1); if (ret == NULL) return NULL; - + ret->width = width; ret->height = height; - ret->state = state; - + ret->opaque = (flags & BITMAP_OPAQUE) == BITMAP_OPAQUE; + ret->ptr = calloc(width, height * 4); - + if (ret->ptr == NULL) { free(ret); return NULL; } - + return ret; } @@ -64,11 +64,8 @@ static void bitmap_destroy(void *bitmap) static void bitmap_set_opaque(void *bitmap, bool opaque) { struct bitmap *bmap = bitmap; - - if (opaque) - bmap->state |= (BITMAP_OPAQUE); - else - bmap->state &= ~(BITMAP_OPAQUE); + + bmap->opaque = opaque; } static bool bitmap_test_opaque(void *bitmap) @@ -79,8 +76,8 @@ static bool bitmap_test_opaque(void *bitmap) static bool bitmap_get_opaque(void *bitmap) { struct bitmap *bmap = bitmap; - - return (bmap->state & BITMAP_OPAQUE) == BITMAP_OPAQUE; + + return bmap->opaque; } static unsigned char *bitmap_get_buffer(void *bitmap) @@ -98,7 +95,7 @@ static size_t bitmap_get_rowstride(void *bitmap) static void bitmap_modified(void *bitmap) { - struct bitmap *bmap = bitmap; + return; } static int bitmap_get_width(void *bitmap) diff --git a/frontends/riscos/bitmap.c b/frontends/riscos/bitmap.c index e724d443f..3454c66e5 100644 --- a/frontends/riscos/bitmap.c +++ b/frontends/riscos/bitmap.c @@ -91,7 +91,7 @@ static bool bitmap_initialise(struct bitmap *bitmap) assert(!bitmap->sprite_area); area_size = 16 + 44 + bitmap->width * bitmap->height * 4; - if (bitmap->state & BITMAP_CLEAR_MEMORY) + if (bitmap->clear) bitmap->sprite_area = calloc(1, area_size); else bitmap->sprite_area = malloc(area_size); @@ -123,7 +123,7 @@ static bool bitmap_initialise(struct bitmap *bitmap) /* exported interface documented in riscos/bitmap.h */ -void *riscos_bitmap_create(int width, int height, unsigned int state) +void *riscos_bitmap_create(int width, int height, enum gui_bitmap_flags flags) { struct bitmap *bitmap; @@ -135,7 +135,8 @@ void *riscos_bitmap_create(int width, int height, unsigned int state) return NULL; bitmap->width = width; bitmap->height = height; - bitmap->state = state; + bitmap->opaque = (flags & BITMAP_OPAQUE) == BITMAP_OPAQUE; + bitmap->clear = (flags & BITMAP_CLEAR) == BITMAP_CLEAR; return bitmap; } @@ -172,10 +173,7 @@ static void bitmap_set_opaque(void *vbitmap, bool opaque) struct bitmap *bitmap = (struct bitmap *) vbitmap; assert(bitmap); - if (opaque) - bitmap->state |= BITMAP_OPAQUE; - else - bitmap->state &= ~BITMAP_OPAQUE; + bitmap->opaque = opaque; } @@ -246,7 +244,7 @@ bool riscos_bitmap_get_opaque(void *vbitmap) { struct bitmap *bitmap = (struct bitmap *) vbitmap; assert(bitmap); - return (bitmap->state & BITMAP_OPAQUE); + return bitmap->opaque; } diff --git a/frontends/riscos/bitmap.h b/frontends/riscos/bitmap.h index f66ebb317..dd3904d67 100644 --- a/frontends/riscos/bitmap.h +++ b/frontends/riscos/bitmap.h @@ -37,7 +37,8 @@ struct bitmap { int width; /**< width of bitmap */ int height; /**< height of bitmap */ - unsigned int state; /**< The bitmap attributes (opaque/dirty etc.) */ + bool opaque; /**< Whether the bitmap is opaque. */ + bool clear; /**< Whether the bitmap should be initialised to zeros. */ struct osspriteop_area *sprite_area; /**< Uncompressed data, or NULL */ }; @@ -71,11 +72,11 @@ void riscos_bitmap_overlay_sprite(struct bitmap *bitmap, const struct osspriteop * Create a bitmap. * * \param width width of image in pixels - * \param height width of image in pixels - * \param state the state to create the bitmap in. + * \param height height of image in pixels + * \param flags flags for bitmap creation. * \return an opaque struct bitmap, or NULL on memory exhaustion */ -void *riscos_bitmap_create(int width, int height, unsigned int state); +void *riscos_bitmap_create(int width, int height, enum gui_bitmap_flags flags); /** * Free a bitmap. diff --git a/frontends/riscos/save.c b/frontends/riscos/save.c index 86797602b..85fefead3 100644 --- a/frontends/riscos/save.c +++ b/frontends/riscos/save.c @@ -243,7 +243,7 @@ ro_gui_save_create_thumbnail(struct hlcache_handle *h, const char *name) struct bitmap *bitmap; osspriteop_area *area; - bitmap = riscos_bitmap_create(34, 34, BITMAP_NEW | BITMAP_OPAQUE | BITMAP_CLEAR_MEMORY); + bitmap = riscos_bitmap_create(34, 34, BITMAP_OPAQUE | BITMAP_CLEAR); if (!bitmap) { NSLOG(netsurf, INFO, "Thumbnail initialisation failed."); return false; diff --git a/frontends/riscos/window.c b/frontends/riscos/window.c index 28ef06fa9..cb1e5484b 100644 --- a/frontends/riscos/window.c +++ b/frontends/riscos/window.c @@ -4568,7 +4568,7 @@ ro_gui_window_iconise(struct gui_window *g, wimp_full_message_window_info *wi) /* create the thumbnail sprite */ bitmap = riscos_bitmap_create(width, height, - BITMAP_NEW | BITMAP_OPAQUE | BITMAP_CLEAR_MEMORY); + BITMAP_OPAQUE | BITMAP_CLEAR); if (!bitmap) { NSLOG(netsurf, INFO, "Thumbnail initialisation failed."); return; diff --git a/frontends/windows/bitmap.c b/frontends/windows/bitmap.c index 82b902db2..26bc807ce 100644 --- a/frontends/windows/bitmap.c +++ b/frontends/windows/bitmap.c @@ -41,19 +41,19 @@ * Create a bitmap. * * \param width width of image in pixels - * \param height width of image in pixels - * \param state a flag word indicating the initial state + * \param height height of image in pixels + * \param state flags flags for bitmap creation * \return an opaque struct bitmap, or NULL on memory exhaustion */ -void *win32_bitmap_create(int width, int height, unsigned int state) +static void *win32_bitmap_create(int width, int height, enum gui_bitmap_flags flags) { struct bitmap *bitmap; BITMAPV5HEADER *pbmi; HBITMAP windib; uint8_t *pixdata; - NSLOG(netsurf, INFO, "width %d, height %d, state %u", width, height, - state); + NSLOG(netsurf, INFO, "width %d, height %d, flags %u", width, height, + (unsigned)flags); pbmi = calloc(1, sizeof(BITMAPV5HEADER)); if (pbmi == NULL) { @@ -91,7 +91,7 @@ void *win32_bitmap_create(int width, int height, unsigned int state) bitmap->windib = windib; bitmap->pbmi = pbmi; bitmap->pixdata = pixdata; - if ((state & BITMAP_OPAQUE) != 0) { + if ((flags & BITMAP_OPAQUE) != 0) { bitmap->opaque = true; } else { bitmap->opaque = false; @@ -327,7 +327,7 @@ bitmap_render(struct bitmap *bitmap, struct hlcache_handle *content) } /* create a full size bitmap and plot into it */ - fsbitmap = win32_bitmap_create(width, height, BITMAP_NEW | BITMAP_CLEAR_MEMORY | BITMAP_OPAQUE); + fsbitmap = win32_bitmap_create(width, height, BITMAP_CLEAR | BITMAP_OPAQUE); SelectObject(bufferdc, fsbitmap->windib); diff --git a/frontends/windows/bitmap.h b/frontends/windows/bitmap.h index c57061d77..a370dd619 100644 --- a/frontends/windows/bitmap.h +++ b/frontends/windows/bitmap.h @@ -33,8 +33,6 @@ struct bitmap { struct bitmap *bitmap_scale(struct bitmap *prescale, int width, int height); -void *win32_bitmap_create(int width, int height, unsigned int state); - void win32_bitmap_destroy(void *bitmap); #endif diff --git a/include/netsurf/bitmap.h b/include/netsurf/bitmap.h index db207cf58..dfd11880d 100644 --- a/include/netsurf/bitmap.h +++ b/include/netsurf/bitmap.h @@ -54,9 +54,12 @@ #ifndef _NETSURF_BITMAP_H_ #define _NETSURF_BITMAP_H_ -#define BITMAP_NEW 0 -#define BITMAP_OPAQUE (1 << 0) /**< image is opaque */ -#define BITMAP_CLEAR_MEMORY (1 << 2) /**< memory should be wiped */ +/** Bitmap creation flags. */ +enum gui_bitmap_flags { + BITMAP_NONE = 0, + BITMAP_OPAQUE = (1 << 0), /**< image is opaque */ + BITMAP_CLEAR = (1 << 1), /**< memory should be wiped to 0 */ +}; struct content; struct bitmap; @@ -71,12 +74,12 @@ struct gui_bitmap_table { /** * Create a new bitmap. * - * \param width width of image in pixels - * \param height width of image in pixels - * \param state The state to create the bitmap in. + * \param width width of image in pixels + * \param height height of image in pixels + * \param flags flags for bitmap creation * \return A bitmap structure or NULL on error. */ - void *(*create)(int width, int height, unsigned int state); + void *(*create)(int width, int height, enum gui_bitmap_flags flags); /** * Destroy a bitmap.