diff options
author | Vincent Sanders <vince@kyllikki.org> | 2015-04-13 23:19:04 +0100 |
---|---|---|
committer | Vincent Sanders <vince@kyllikki.org> | 2015-04-13 23:19:04 +0100 |
commit | f37e52c39475e6efd3740c5ae1ec4f290662928f (patch) | |
tree | 88d01618e903975743a3cb74bff9bf8df54c2a45 /desktop | |
parent | 7a28131e4953934150967eb7886bc06678e249e8 (diff) | |
download | netsurf-f37e52c39475e6efd3740c5ae1ec4f290662928f.tar.gz netsurf-f37e52c39475e6efd3740c5ae1ec4f290662928f.tar.bz2 |
Move bitmap operations into an operation table.
The generic bitmap handlers provided by each frontend are called back
from the core and therefore should be in an operation table. This was
one of the very few remaining interfaces stopping the core code from
being split into a library.
Diffstat (limited to 'desktop')
-rw-r--r-- | desktop/browser_history.c | 9 | ||||
-rw-r--r-- | desktop/gui_factory.c | 79 | ||||
-rw-r--r-- | desktop/gui_table.h | 10 | ||||
-rw-r--r-- | desktop/knockout.c | 8 | ||||
-rw-r--r-- | desktop/treeview.c | 63 |
5 files changed, 131 insertions, 38 deletions
diff --git a/desktop/browser_history.c b/desktop/browser_history.c index 1991bf9a1..e7fd87583 100644 --- a/desktop/browser_history.c +++ b/desktop/browser_history.c @@ -37,6 +37,7 @@ #include "css/css.h" #include "image/bitmap.h" +#include "desktop/gui_internal.h" #include "desktop/browser_history.h" #include "desktop/browser_private.h" #include "desktop/plotters.h" @@ -511,9 +512,9 @@ nserror browser_window_history_add(struct browser_window *bw, bitmap = urldb_get_thumbnail(nsurl); if (bitmap == NULL) { LOG(("Creating thumbnail for %s", nsurl_access(nsurl))); - bitmap = bitmap_create(WIDTH, HEIGHT, - BITMAP_NEW | BITMAP_CLEAR_MEMORY | - BITMAP_OPAQUE); + bitmap = guit->bitmap->create(WIDTH, HEIGHT, + BITMAP_NEW | BITMAP_CLEAR_MEMORY | + BITMAP_OPAQUE); if (bitmap != NULL) { if (thumbnail_create(content, bitmap)) { /* Successful thumbnail so register it @@ -525,7 +526,7 @@ nserror browser_window_history_add(struct browser_window *bw, * silently but clean up bitmap. */ LOG(("Thumbnail bitmap creation failed")); - bitmap_destroy(bitmap); + guit->bitmap->destroy(bitmap); bitmap = NULL; } } diff --git a/desktop/gui_factory.c b/desktop/gui_factory.c index df88b8c34..cab11eb0a 100644 --- a/desktop/gui_factory.c +++ b/desktop/gui_factory.c @@ -16,10 +16,16 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include <stdlib.h> +#include <stdint.h> +#include <stdbool.h> + +#include "utils/errors.h" +#include "utils/file.h" +#include "image/bitmap.h" #include "content/hlcache.h" #include "content/backing_store.h" -#include "utils/file.h" #include "desktop/save_pdf.h" #include "desktop/download.h" #include "desktop/searchweb.h" @@ -552,6 +558,71 @@ static nserror verify_file_register(struct gui_file_table *gft) return NSERROR_OK; } +/** + * verify bitmap table is valid + * + * \param gbt The bitmap table to verify. + * \return NSERROR_OK if teh table is valid else NSERROR_BAD_PARAMETER. + */ +static nserror verify_bitmap_register(struct gui_bitmap_table *gbt) +{ + /* check table is present */ + if (gbt == NULL) { + return NSERROR_BAD_PARAMETER; + } + + /* check the mandantory fields are set */ + if (gbt->create == NULL) { + return NSERROR_BAD_PARAMETER; + } + + if (gbt->destroy == NULL) { + return NSERROR_BAD_PARAMETER; + } + + if (gbt->set_opaque == NULL) { + return NSERROR_BAD_PARAMETER; + } + + if (gbt->get_opaque == NULL) { + return NSERROR_BAD_PARAMETER; + } + + if (gbt->test_opaque == NULL) { + return NSERROR_BAD_PARAMETER; + } + + if (gbt->get_buffer == NULL) { + return NSERROR_BAD_PARAMETER; + } + + if (gbt->get_rowstride == NULL) { + return NSERROR_BAD_PARAMETER; + } + + if (gbt->get_width == NULL) { + return NSERROR_BAD_PARAMETER; + } + + if (gbt->get_height == NULL) { + return NSERROR_BAD_PARAMETER; + } + + if (gbt->get_bpp == NULL) { + return NSERROR_BAD_PARAMETER; + } + + if (gbt->save == NULL) { + return NSERROR_BAD_PARAMETER; + } + + if (gbt->modified == NULL) { + return NSERROR_BAD_PARAMETER; + } + + return NSERROR_OK; +} + static void gui_default_quit(void) { } @@ -651,6 +722,12 @@ nserror netsurf_register(struct netsurf_table *gt) return err; } + /* bitmap table */ + err = verify_bitmap_register(gt->bitmap); + if (err != NSERROR_OK) { + return err; + } + /* file table */ if (gt->file == NULL) { gt->file = default_file_table; diff --git a/desktop/gui_table.h b/desktop/gui_table.h index 10f2bf17a..52cdde2ea 100644 --- a/desktop/gui_table.h +++ b/desktop/gui_table.h @@ -37,6 +37,7 @@ struct gui_utf8_table; struct gui_search_table; struct gui_search_web_table; struct gui_llcache_table; +struct gui_bitmap_table; /** * NetSurf operation function table @@ -119,6 +120,15 @@ struct netsurf_table { * uses the default implementation. */ struct gui_llcache_table *llcache; + + /** + * Bitmap table. + * + * Used by the image convertors as a generic interface to + * native platform-specific image formats. The table + * is mandantory and must be provided. + */ + struct gui_bitmap_table *bitmap; }; #endif diff --git a/desktop/knockout.c b/desktop/knockout.c index 0321423fd..303ba8f6c 100644 --- a/desktop/knockout.c +++ b/desktop/knockout.c @@ -66,9 +66,12 @@ #include <string.h> #include <stdio.h> -#include "image/bitmap.h" #include "utils/log.h" +#include "utils/errors.h" +#include "image/bitmap.h" #include "content/content.h" + +#include "desktop/gui_internal.h" #include "desktop/knockout.h" #include "desktop/plotters.h" @@ -772,8 +775,9 @@ bool knockout_plot_bitmap(int x, int y, int width, int height, } /* tiled bitmaps both knock out and get knocked out */ - if (bitmap_get_opaque(bitmap)) + if (guit->bitmap->get_opaque(bitmap)) { knockout_calculate(kx0, ky0, kx1, ky1, NULL); + } knockout_boxes[knockout_box_cur].bbox.x0 = kx0; knockout_boxes[knockout_box_cur].bbox.y0 = ky0; knockout_boxes[knockout_box_cur].bbox.x1 = kx1; diff --git a/desktop/treeview.c b/desktop/treeview.c index f6134ae71..35458f7fb 100644 --- a/desktop/treeview.c +++ b/desktop/treeview.c @@ -3698,12 +3698,12 @@ static struct bitmap * treeview_generate_triangle_bitmap( colour colour4 = fg; /* Create the bitmap */ - b = bitmap_create(size, size, BITMAP_NEW | BITMAP_OPAQUE); + b = guit->bitmap->create(size, size, BITMAP_NEW | BITMAP_OPAQUE); if (b == NULL) return NULL; - rpos = bitmap_get_buffer(b); - stride = bitmap_get_rowstride(b); + rpos = guit->bitmap->get_buffer(b); + stride = guit->bitmap->get_rowstride(b); /* Draw the triangle */ for (y = 0; y < size; y++) { @@ -3770,7 +3770,7 @@ static struct bitmap * treeview_generate_triangle_bitmap( rpos += stride; } - bitmap_modified(b); + guit->bitmap->modified(b); return b; } @@ -3793,29 +3793,29 @@ static struct bitmap * treeview_generate_copy_bitmap( if (orig == NULL) return NULL; - assert(size == bitmap_get_width(orig)); - assert(size == bitmap_get_height(orig)); + assert(size == guit->bitmap->get_width(orig)); + assert(size == guit->bitmap->get_height(orig)); /* Create the bitmap */ - b = bitmap_create(size, size, BITMAP_NEW | BITMAP_OPAQUE); + b = guit->bitmap->create(size, size, BITMAP_NEW | BITMAP_OPAQUE); if (b == NULL) return NULL; - stride = bitmap_get_rowstride(b); - assert(stride == bitmap_get_rowstride(orig)); + stride = guit->bitmap->get_rowstride(b); + assert(stride == guit->bitmap->get_rowstride(orig)); - data = bitmap_get_buffer(b); - orig_data = bitmap_get_buffer(orig); + data = guit->bitmap->get_buffer(b); + orig_data = guit->bitmap->get_buffer(orig); /* Copy the bitmap */ memcpy(data, orig_data, stride * size); - bitmap_modified(b); + guit->bitmap->modified(b); /* We've not modified the original image, but we called * bitmap_get_buffer(), so we need to pair that with a * bitmap_modified() call to appease certain front ends. */ - bitmap_modified(orig); + guit->bitmap->modified(orig); return b; } @@ -3841,19 +3841,19 @@ static struct bitmap * treeview_generate_rotate_bitmap( if (orig == NULL) return NULL; - assert(size == bitmap_get_width(orig)); - assert(size == bitmap_get_height(orig)); + assert(size == guit->bitmap->get_width(orig)); + assert(size == guit->bitmap->get_height(orig)); /* Create the bitmap */ - b = bitmap_create(size, size, BITMAP_NEW | BITMAP_OPAQUE); + b = guit->bitmap->create(size, size, BITMAP_NEW | BITMAP_OPAQUE); if (b == NULL) return NULL; - stride = bitmap_get_rowstride(b); - assert(stride == bitmap_get_rowstride(orig)); + stride = guit->bitmap->get_rowstride(b); + assert(stride == guit->bitmap->get_rowstride(orig)); - rpos = bitmap_get_buffer(b); - orig_data = bitmap_get_buffer(orig); + rpos = guit->bitmap->get_buffer(b); + orig_data = guit->bitmap->get_buffer(orig); /* Copy the rotated bitmap */ for (y = 0; y < size; y++) { @@ -3871,12 +3871,13 @@ static struct bitmap * treeview_generate_rotate_bitmap( rpos += stride; } - bitmap_modified(b); + guit->bitmap->modified(b); /* We've not modified the original image, but we called * bitmap_get_buffer(), so we need to pair that with a - * bitmap_modified() call to appease certain front ends. */ - bitmap_modified(orig); + * bitmap_modified() call to appease certain front ends. + */ + guit->bitmap->modified(orig); return b; } @@ -3988,14 +3989,14 @@ nserror treeview_fini(void) hlcache_handle_release(treeview_res[i].c); } - bitmap_destroy(plot_style_odd.furn[TREE_FURN_EXPAND].bmp); - bitmap_destroy(plot_style_odd.furn[TREE_FURN_EXPAND].sel); - bitmap_destroy(plot_style_even.furn[TREE_FURN_EXPAND].bmp); - bitmap_destroy(plot_style_even.furn[TREE_FURN_EXPAND].sel); - bitmap_destroy(plot_style_odd.furn[TREE_FURN_CONTRACT].bmp); - bitmap_destroy(plot_style_odd.furn[TREE_FURN_CONTRACT].sel); - bitmap_destroy(plot_style_even.furn[TREE_FURN_CONTRACT].bmp); - bitmap_destroy(plot_style_even.furn[TREE_FURN_CONTRACT].sel); + guit->bitmap->destroy(plot_style_odd.furn[TREE_FURN_EXPAND].bmp); + guit->bitmap->destroy(plot_style_odd.furn[TREE_FURN_EXPAND].sel); + guit->bitmap->destroy(plot_style_even.furn[TREE_FURN_EXPAND].bmp); + guit->bitmap->destroy(plot_style_even.furn[TREE_FURN_EXPAND].sel); + guit->bitmap->destroy(plot_style_odd.furn[TREE_FURN_CONTRACT].bmp); + guit->bitmap->destroy(plot_style_odd.furn[TREE_FURN_CONTRACT].sel); + guit->bitmap->destroy(plot_style_even.furn[TREE_FURN_CONTRACT].bmp); + guit->bitmap->destroy(plot_style_even.furn[TREE_FURN_CONTRACT].sel); tree_g.initialised = false; |