diff options
author | Michael Drake <tlsa@netsurf-browser.org> | 2022-03-29 17:32:40 +0100 |
---|---|---|
committer | Michael Drake <tlsa@netsurf-browser.org> | 2022-03-29 17:32:40 +0100 |
commit | 7d5c449389162c3b11cecc0b4a969d50a693c8b1 (patch) | |
tree | 19bb35493ac737601a082c3aaea29a5ca0af4b38 /frontends | |
parent | 8e56cc3b1a0d9d18e35811a015cf42b57ede1025 (diff) | |
download | netsurf-7d5c449389162c3b11cecc0b4a969d50a693c8b1.tar.gz netsurf-7d5c449389162c3b11cecc0b4a969d50a693c8b1.tar.bz2 |
GTK: Simplify opaque bitmap handling.
Avoid creating new bitmaps and copying in set_opaque by always
using an RGBA format.
Diffstat (limited to 'frontends')
-rw-r--r-- | frontends/gtk/bitmap.c | 57 | ||||
-rw-r--r-- | frontends/gtk/bitmap.h | 1 |
2 files changed, 6 insertions, 52 deletions
diff --git a/frontends/gtk/bitmap.c b/frontends/gtk/bitmap.c index 595d5eae5..bfd29e1f4 100644 --- a/frontends/gtk/bitmap.c +++ b/frontends/gtk/bitmap.c @@ -55,12 +55,11 @@ static void *bitmap_create(int width, int height, enum gui_bitmap_flags flags) gbitmap = calloc(1, sizeof(struct bitmap)); if (gbitmap != NULL) { - 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); + if (flags & BITMAP_OPAQUE) { + gbitmap->opaque = true; } + gbitmap->surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); if (cairo_surface_status(gbitmap->surface) != CAIRO_STATUS_SUCCESS) { cairo_surface_destroy(gbitmap->surface); free(gbitmap); @@ -81,46 +80,8 @@ static void *bitmap_create(int width, int height, enum gui_bitmap_flags flags) static void bitmap_set_opaque(void *vbitmap, bool opaque) { struct bitmap *gbitmap = (struct bitmap *)vbitmap; - cairo_format_t fmt; - cairo_surface_t *nsurface = NULL; - assert(gbitmap); - - fmt = cairo_image_surface_get_format(gbitmap->surface); - if (fmt == CAIRO_FORMAT_RGB24) { - if (opaque == false) { - /* opaque to transparent */ - nsurface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, - cairo_image_surface_get_width(gbitmap->surface), - cairo_image_surface_get_height(gbitmap->surface)); - - } - - } else { - if (opaque == true) { - /* transparent to opaque */ - nsurface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, - cairo_image_surface_get_width(gbitmap->surface), - cairo_image_surface_get_height(gbitmap->surface)); - - } - } - - if (nsurface != NULL) { - if (cairo_surface_status(nsurface) != CAIRO_STATUS_SUCCESS) { - cairo_surface_destroy(nsurface); - } else { - memcpy(cairo_image_surface_get_data(nsurface), - cairo_image_surface_get_data(gbitmap->surface), - cairo_image_surface_get_stride(gbitmap->surface) * cairo_image_surface_get_height(gbitmap->surface)); - cairo_surface_destroy(gbitmap->surface); - gbitmap->surface = nsurface; - - cairo_surface_mark_dirty(gbitmap->surface); - - } - - } + gbitmap->opaque = opaque; } @@ -132,16 +93,8 @@ static void bitmap_set_opaque(void *vbitmap, bool opaque) static bool bitmap_get_opaque(void *vbitmap) { struct bitmap *gbitmap = (struct bitmap *)vbitmap; - cairo_format_t fmt; - - assert(gbitmap); - - fmt = cairo_image_surface_get_format(gbitmap->surface); - if (fmt == CAIRO_FORMAT_RGB24) { - return true; - } - return false; + return gbitmap->opaque; } diff --git a/frontends/gtk/bitmap.h b/frontends/gtk/bitmap.h index d899966bd..80a0e7a3a 100644 --- a/frontends/gtk/bitmap.h +++ b/frontends/gtk/bitmap.h @@ -26,6 +26,7 @@ extern struct gui_bitmap_table *nsgtk_bitmap_table; struct bitmap { cairo_surface_t *surface; /* original cairo surface */ cairo_surface_t *scsurface; /* scaled surface */ + bool opaque; }; int nsgtk_bitmap_get_width(void *vbitmap); |