diff options
author | Michael Drake <tlsa@netsurf-browser.org> | 2011-06-30 15:48:07 +0000 |
---|---|---|
committer | Michael Drake <tlsa@netsurf-browser.org> | 2011-06-30 15:48:07 +0000 |
commit | eddae6af0663243a2677674d501f9a87d55798f5 (patch) | |
tree | 08562171f870a6b592d624adfbfd0d6fa11fcdcb /desktop | |
parent | a5dc6b9e6637c85d18510ac6446ee4a8a7955e7b (diff) | |
download | netsurf-eddae6af0663243a2677674d501f9a87d55798f5.tar.gz netsurf-eddae6af0663243a2677674d501f9a87d55798f5.tar.bz2 |
Remove plotter table global. Pass a redraw context around redraw functions. Knockout could be handled better. Note: untested on most front ends.
svn path=/trunk/netsurf/; revision=12543
Diffstat (limited to 'desktop')
-rw-r--r-- | desktop/browser.c | 25 | ||||
-rw-r--r-- | desktop/browser.h | 3 | ||||
-rw-r--r-- | desktop/history_core.c | 54 | ||||
-rw-r--r-- | desktop/history_core.h | 5 | ||||
-rw-r--r-- | desktop/knockout.c | 74 | ||||
-rw-r--r-- | desktop/knockout.h | 3 | ||||
-rw-r--r-- | desktop/plotters.h | 4 | ||||
-rw-r--r-- | desktop/print.c | 10 | ||||
-rw-r--r-- | desktop/scrollbar.c | 62 | ||||
-rw-r--r-- | desktop/scrollbar.h | 4 | ||||
-rw-r--r-- | desktop/textarea.c | 26 | ||||
-rw-r--r-- | desktop/textarea.h | 2 | ||||
-rw-r--r-- | desktop/thumbnail.c | 15 | ||||
-rw-r--r-- | desktop/thumbnail.h | 4 | ||||
-rw-r--r-- | desktop/tree.c | 91 | ||||
-rw-r--r-- | desktop/tree.h | 3 |
16 files changed, 208 insertions, 177 deletions
diff --git a/desktop/browser.c b/desktop/browser.c index 1f09465b1..827896835 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -94,8 +94,9 @@ static void browser_window_mouse_drag_end(struct browser_window *bw, /* exported interface, documented in browser.h */ bool browser_window_redraw(struct browser_window *bw, int x, int y, - const struct rect *clip) + const struct rect *clip, const struct redraw_context *ctx) { + struct redraw_context new_ctx = *ctx; int width = 0; int height = 0; bool plot_ok = true; @@ -109,17 +110,20 @@ bool browser_window_redraw(struct browser_window *bw, int x, int y, if (bw->current_content == NULL) { /* Browser window has no content, render blank fill */ - plot.clip(clip); - return plot.rectangle(clip->x0, clip->y0, clip->x1, clip->y1, + ctx->plot->clip(clip); + return ctx->plot->rectangle(clip->x0, clip->y0, + clip->x1, clip->y1, plot_style_fill_white); } - /* Browser window has content */ if (bw->browser_window_type != BROWSER_WINDOW_IFRAME && - plot.option_knockout) - knockout_plot_start(&plot); + ctx->plot->option_knockout) { + knockout_plot_start(ctx, &new_ctx); + } - plot.clip(clip); + /* Browser window has content */ + + new_ctx.plot->clip(clip); content_type = content_get_type(bw->current_content); if (content_type != CONTENT_HTML && content_type != CONTENT_TEXTPLAIN) { @@ -129,7 +133,7 @@ bool browser_window_redraw(struct browser_window *bw, int x, int y, /* Non-HTML may not fill viewport to extents, so plot white * background fill */ - plot_ok &= plot.rectangle(clip->x0, clip->y0, + plot_ok &= new_ctx.plot->rectangle(clip->x0, clip->y0, clip->x1, clip->y1, plot_style_fill_white); } @@ -145,11 +149,12 @@ bool browser_window_redraw(struct browser_window *bw, int x, int y, data.repeat_y = false; /* Render the content */ - plot_ok &= content_redraw(bw->current_content, &data, clip); + plot_ok &= content_redraw(bw->current_content, &data, clip, &new_ctx); if (bw->browser_window_type != BROWSER_WINDOW_IFRAME && - plot.option_knockout) + ctx->plot->option_knockout) { knockout_plot_end(); + } return plot_ok; } diff --git a/desktop/browser.h b/desktop/browser.h index 39d6bf942..136f97f0f 100644 --- a/desktop/browser.h +++ b/desktop/browser.h @@ -268,6 +268,7 @@ bool browser_window_stop_available(struct browser_window *bw); * \param x coordinate for top-left of redraw * \param y coordinate for top-left of redraw * \param clip clip rectangle coordinates + * \param ctx redraw context * \return true if successful, false otherwise * * The clip rectangle is guaranteed to be filled to its extents, so there is @@ -280,7 +281,7 @@ bool browser_window_stop_available(struct browser_window *bw); * Units for x, y and clip are pixels. */ bool browser_window_redraw(struct browser_window *bw, int x, int y, - const struct rect *clip); + const struct rect *clip, const struct redraw_context *ctx); /** * Check whether browser window is ready for redraw diff --git a/desktop/history_core.c b/desktop/history_core.c index 581b072dc..70e8f158c 100644 --- a/desktop/history_core.c +++ b/desktop/history_core.c @@ -89,7 +89,7 @@ static int history_layout_subtree(struct history *history, static bool history_redraw_entry(struct history *history, struct history_entry *entry, int x0, int y0, int x1, int y1, - int x, int y, bool clip); + int x, int y, bool clip, const struct redraw_context *ctx); static struct history_entry *history_find_position(struct history_entry *entry, int x, int y); static bool history_enumerate_entry(const struct history *history, @@ -558,40 +558,39 @@ void history_size(struct history *history, int *width, int *height) /** * Redraw a history. * - * \param history history to render - * - * The current plotter is used. + * \param history history to render + * \param ctx current redraw context */ -bool history_redraw(struct history *history) +bool history_redraw(struct history *history, const struct redraw_context *ctx) { if (!history->start) return true; - return history_redraw_entry(history, history->start, 0, 0, 0, 0, 0, 0, false); + return history_redraw_entry(history, history->start, 0, 0, 0, 0, 0, 0, + false, ctx); } /** * Redraw part of a history. * - * \param history history to render - * \param x0 left X co-ordinate of redraw area - * \param y0 top Y co-ordinate of redraw area - * \param x1 right X co-ordinate of redraw area - * \param y1 lower Y co-ordinate of redraw area - * \param x start X co-ordinate on plot canvas - * \param y start Y co-ordinate on plot canvas - * - * The current plotter is used. + * \param history history to render + * \param x0 left X co-ordinate of redraw area + * \param y0 top Y co-ordinate of redraw area + * \param x1 right X co-ordinate of redraw area + * \param y1 lower Y co-ordinate of redraw area + * \param x start X co-ordinate on plot canvas + * \param y start Y co-ordinate on plot canvas + * \param ctx current redraw context */ bool history_redraw_rectangle(struct history *history, int x0, int y0, int x1, int y1, - int x, int y) + int x, int y, const struct redraw_context *ctx) { if (!history->start) return true; return history_redraw_entry(history, history->start, - x0, y0, x1, y1, x, y, true); + x0, y0, x1, y1, x, y, true, ctx); } /** @@ -599,13 +598,15 @@ bool history_redraw_rectangle(struct history *history, * * \param history history containing the entry * \param history_entry entry to render + * \param ctx current redraw context */ bool history_redraw_entry(struct history *history, struct history_entry *entry, int x0, int y0, int x1, int y1, - int x, int y, bool clip) + int x, int y, bool clip, const struct redraw_context *ctx) { + const struct plotter_table *plot = ctx->plot; size_t char_offset; int actual_x; struct history_entry *child; @@ -626,14 +627,14 @@ bool history_redraw_entry(struct history *history, rect.y0 = y0 + yoffset; rect.x1 = x1 + xoffset; rect.y1 = y1 + yoffset; - if(!plot.clip(&rect)) + if(!plot->clip(&rect)) return false; } - if (!plot.bitmap(entry->x + xoffset, entry->y + yoffset, WIDTH, HEIGHT, + if (!plot->bitmap(entry->x + xoffset, entry->y + yoffset, WIDTH, HEIGHT, entry->bitmap, 0xffffff, 0)) return false; - if (!plot.rectangle(entry->x - 1 + xoffset, + if (!plot->rectangle(entry->x - 1 + xoffset, entry->y - 1 + yoffset, entry->x + xoffset + WIDTH, entry->y + yoffset + HEIGHT, @@ -649,29 +650,30 @@ bool history_redraw_entry(struct history *history, fstyle.foreground = c; fstyle.weight = entry == history->current ? 900 : 400; - if (!plot.text(entry->x + xoffset, entry->y + HEIGHT + 12 + yoffset, + if (!plot->text(entry->x + xoffset, entry->y + HEIGHT + 12 + yoffset, entry->page.title, char_offset, &fstyle)) return false; for (child = entry->forward; child; child = child->next) { - if (!plot.line(entry->x + WIDTH + xoffset, + if (!plot->line(entry->x + WIDTH + xoffset, entry->y + HEIGHT / 2 + yoffset, entry->x + WIDTH + tailsize + xoffset, entry->y + HEIGHT / 2 + yoffset, plot_style_stroke_history)) return false; - if (!plot.line(entry->x + WIDTH + tailsize + xoffset, + if (!plot->line(entry->x + WIDTH + tailsize + xoffset, entry->y + HEIGHT / 2 + yoffset, child->x - tailsize +xoffset, child->y + HEIGHT / 2 + yoffset, plot_style_stroke_history)) return false; - if (!plot.line(child->x - tailsize + xoffset, + if (!plot->line(child->x - tailsize + xoffset, child->y + HEIGHT / 2 + yoffset, child->x + xoffset, child->y + HEIGHT / 2 + yoffset, plot_style_stroke_history)) return false; - if (!history_redraw_entry(history, child, x0, y0, x1, y1, x, y, clip)) + if (!history_redraw_entry(history, child, x0, y0, x1, y1, x, y, + clip, ctx)) return false; } diff --git a/desktop/history_core.h b/desktop/history_core.h index be09fb1cb..883ee9cea 100644 --- a/desktop/history_core.h +++ b/desktop/history_core.h @@ -41,9 +41,10 @@ void history_forward(struct browser_window *bw, struct history *history); bool history_back_available(struct history *history); bool history_forward_available(struct history *history); void history_size(struct history *history, int *width, int *height); -bool history_redraw(struct history *history); +bool history_redraw(struct history *history, const struct redraw_context *ctx); bool history_redraw_rectangle(struct history *history, - int x0, int y0, int x1, int y1, int x, int y); + int x0, int y0, int x1, int y1, int x, int y, + const struct redraw_context *ctx); bool history_click(struct browser_window *bw, struct history *history, int x, int y, bool new_window); const char *history_position_url(struct history *history, int x, int y); diff --git a/desktop/knockout.c b/desktop/knockout.c index 5d0ecbc2a..0385ee80b 100644 --- a/desktop/knockout.c +++ b/desktop/knockout.c @@ -80,7 +80,6 @@ struct knockout_box; struct knockout_entry; -static void knockout_set_plotters(void); static void knockout_calculate(int x0, int y0, int x1, int y1, struct knockout_box *box); static bool knockout_plot_fill_recursive(struct knockout_box *box, plot_style_t *plot_style); static bool knockout_plot_bitmap_recursive(struct knockout_box *box, @@ -228,15 +227,18 @@ static int nested_depth = 0; /** * Start a knockout plotting session * - * \param plotter the plotter to use + * \param ctx the redraw context with real plotter table + * \param knk_ctx updated to copy of ctx, with plotter table replaced * \return true on success, false otherwise */ -bool knockout_plot_start(struct plotter_table *plotter) +bool knockout_plot_start(const struct redraw_context *ctx, + struct redraw_context *knk_ctx) { /* check if we're recursing */ if (nested_depth++ > 0) { /* we should already have the knockout renderer as default */ - assert(plotter->rectangle == knockout_plotters.rectangle); + assert(ctx->plot->rectangle == knockout_plotters.rectangle); + *knk_ctx = *ctx; return true; } @@ -244,9 +246,12 @@ bool knockout_plot_start(struct plotter_table *plotter) if (knockout_entry_cur > 0) knockout_plot_end(); - /* take over the plotter */ - real_plot = *plotter; - knockout_set_plotters(); + /* get copy of real plotter table */ + real_plot = *(ctx->plot); + + /* set up knockout rendering context */ + *knk_ctx = *ctx; + knk_ctx->plot = &knockout_plotters; return true; } @@ -286,13 +291,10 @@ bool knockout_plot_flush(void) knockout_polygon_cur, KNOCKOUT_POLYGONS)); #endif - /* release our plotter */ - plot = real_plot; - for (i = 0; i < knockout_entry_cur; i++) { switch (knockout_entries[i].type) { case KNOCKOUT_PLOT_RECTANGLE: - success &= plot.rectangle( + success &= real_plot.rectangle( knockout_entries[i].data.rectangle.x0, knockout_entries[i].data.rectangle.y0, knockout_entries[i].data.rectangle.x1, @@ -300,7 +302,7 @@ bool knockout_plot_flush(void) &knockout_entries[i].data.rectangle.plot_style); break; case KNOCKOUT_PLOT_LINE: - success &= plot.line( + success &= real_plot.line( knockout_entries[i].data.line.x0, knockout_entries[i].data.line.y0, knockout_entries[i].data.line.x1, @@ -308,7 +310,7 @@ bool knockout_plot_flush(void) &knockout_entries[i].data.line.plot_style); break; case KNOCKOUT_PLOT_POLYGON: - success &= plot.polygon( + success &= real_plot.polygon( knockout_entries[i].data.polygon.p, knockout_entries[i].data.polygon.n, &knockout_entries[i].data.polygon.plot_style); @@ -319,7 +321,7 @@ bool knockout_plot_flush(void) success &= knockout_plot_fill_recursive(box, &knockout_entries[i].data.fill.plot_style); else if (!knockout_entries[i].box->deleted) - success &= plot.rectangle( + success &= real_plot.rectangle( knockout_entries[i].data.fill.x0, knockout_entries[i].data.fill.y0, knockout_entries[i].data.fill.x1, @@ -327,11 +329,11 @@ bool knockout_plot_flush(void) &knockout_entries[i].data.fill.plot_style); break; case KNOCKOUT_PLOT_CLIP: - success &= plot.clip( + success &= real_plot.clip( &knockout_entries[i].data.clip); break; case KNOCKOUT_PLOT_TEXT: - success &= plot.text( + success &= real_plot.text( knockout_entries[i].data.text.x, knockout_entries[i].data.text.y, knockout_entries[i].data.text.text, @@ -339,14 +341,14 @@ bool knockout_plot_flush(void) &knockout_entries[i].data.text.font_style); break; case KNOCKOUT_PLOT_DISC: - success &= plot.disc( + success &= real_plot.disc( knockout_entries[i].data.disc.x, knockout_entries[i].data.disc.y, knockout_entries[i].data.disc.radius, &knockout_entries[i].data.disc.plot_style); break; case KNOCKOUT_PLOT_ARC: - success &= plot.arc( + success &= real_plot.arc( knockout_entries[i].data.arc.x, knockout_entries[i].data.arc.y, knockout_entries[i].data.arc.radius, @@ -360,7 +362,7 @@ bool knockout_plot_flush(void) success &= knockout_plot_bitmap_recursive(box, &knockout_entries[i]); } else if (!knockout_entries[i].box->deleted) { - success &= plot.bitmap( + success &= real_plot.bitmap( knockout_entries[i].data. bitmap.x, knockout_entries[i].data. @@ -378,11 +380,11 @@ bool knockout_plot_flush(void) } break; case KNOCKOUT_PLOT_GROUP_START: - success &= plot.group_start( + success &= real_plot.group_start( knockout_entries[i].data.group_start.name); break; case KNOCKOUT_PLOT_GROUP_END: - success &= plot.group_end(); + success &= real_plot.group_end(); break; } } @@ -392,27 +394,11 @@ bool knockout_plot_flush(void) knockout_polygon_cur = 0; knockout_list = NULL; - /* re-instate knockout plotters if we are still active */ - if (nested_depth > 0) - knockout_set_plotters(); return success; } /** - * Override the current plotters with the knockout plotters - */ -void knockout_set_plotters(void) -{ - plot = knockout_plotters; - if (!real_plot.group_start) - plot.group_start = NULL; - if (!real_plot.group_end) - plot.group_end = NULL; -} - - -/** * Knockout a section of previous rendering * * \param x0 the left edge of the removal box @@ -548,7 +534,7 @@ bool knockout_plot_fill_recursive(struct knockout_box *box, plot_style_t *plot_s if (parent->child) knockout_plot_fill_recursive(parent->child, plot_style); else - success &= plot.rectangle(parent->bbox.x0, + success &= real_plot.rectangle(parent->bbox.x0, parent->bbox.y0, parent->bbox.x1, parent->bbox.y1, @@ -570,8 +556,8 @@ bool knockout_plot_bitmap_recursive(struct knockout_box *box, if (parent->child) knockout_plot_bitmap_recursive(parent->child, entry); else { - success &= plot.clip(&parent->bbox); - success &= plot.bitmap(entry->data.bitmap.x, + success &= real_plot.clip(&parent->bbox); + success &= real_plot.bitmap(entry->data.bitmap.x, entry->data.bitmap.y, entry->data.bitmap.width, entry->data.bitmap.height, @@ -810,6 +796,10 @@ bool knockout_plot_bitmap(int x, int y, int width, int height, bool knockout_plot_group_start(const char *name) { + if (real_plot.group_start == NULL) { + return true; + } + knockout_entries[knockout_entry_cur].data.group_start.name = name; knockout_entries[knockout_entry_cur].type = KNOCKOUT_PLOT_GROUP_START; if (++knockout_entry_cur >= KNOCKOUT_ENTRIES) @@ -819,6 +809,10 @@ bool knockout_plot_group_start(const char *name) bool knockout_plot_group_end(void) { + if (real_plot.group_end == NULL) { + return true; + } + knockout_entries[knockout_entry_cur].type = KNOCKOUT_PLOT_GROUP_END; if (++knockout_entry_cur >= KNOCKOUT_ENTRIES) knockout_plot_flush(); diff --git a/desktop/knockout.h b/desktop/knockout.h index a3951a501..a6b61d836 100644 --- a/desktop/knockout.h +++ b/desktop/knockout.h @@ -26,7 +26,8 @@ #include "desktop/plotters.h" -bool knockout_plot_start(struct plotter_table *plotter); +bool knockout_plot_start(const struct redraw_context *ctx, + struct redraw_context *knk_ctx); bool knockout_plot_end(void); extern const struct plotter_table knockout_plotters; diff --git a/desktop/plotters.h b/desktop/plotters.h index ff5e8a9c7..448cedef5 100644 --- a/desktop/plotters.h +++ b/desktop/plotters.h @@ -27,7 +27,6 @@ #include "css/css.h" #include "content/content.h" #include "desktop/plot_style.h" -#include "utils/types.h" struct bitmap; @@ -137,9 +136,6 @@ struct plotter_table { bool option_knockout; /**< set if knockout rendering is required */ }; -/** Current plotters, must be assigned before use. */ -extern struct plotter_table plot; - enum path_command { PLOTTER_PATH_MOVE, PLOTTER_PATH_CLOSE, diff --git a/desktop/print.c b/desktop/print.c index 373c338fa..c6c361108 100644 --- a/desktop/print.c +++ b/desktop/print.c @@ -34,6 +34,7 @@ #include "render/box.h" #include "utils/log.h" #include "utils/talloc.h" +#include "utils/types.h" /* Default print settings */ #define DEFAULT_PAGE_WIDTH 595 @@ -123,8 +124,11 @@ bool print_draw_next_page(const struct printer *printer, { struct rect clip; struct content_redraw_data data; - - plot = *(printer->plotter); + struct redraw_context ctx = { + .interactive = false, + .plot = printer->plotter + }; + html_redraw_printing_top_cropped = INT_MAX; clip.x0 = 0; @@ -145,7 +149,7 @@ bool print_draw_next_page(const struct printer *printer, html_redraw_printing_border = clip.y1; printer->print_next_page(); - if (!content_redraw(printed_content, &data, &clip)) + if (!content_redraw(printed_content, &data, &clip, &ctx)) return false; done_height += page_content_height - diff --git a/desktop/scrollbar.c b/desktop/scrollbar.c index 1c99b14a6..6dd9b0b15 100644 --- a/desktop/scrollbar.c +++ b/desktop/scrollbar.c @@ -139,13 +139,17 @@ void scrollbar_destroy(struct scrollbar *s) * \param y1 bottom border of the outline * \param c base colour of the outline, the other colours are created by * lightening or darkening this one + * \param ctx current redraw context * \param inset true for inset outline, false for an outset one * \return */ static inline bool scrollbar_redraw_scrollbar_rectangle(int x0, int y0, - int x1, int y1, colour c, bool inset) + int x1, int y1, colour c, bool inset, + const struct redraw_context *ctx) { + const struct plotter_table *plot = ctx->plot; + static plot_style_t c0 = { .stroke_type = PLOT_OP_TYPE_SOLID, .stroke_width = 1, @@ -171,12 +175,12 @@ static inline bool scrollbar_redraw_scrollbar_rectangle(int x0, int y0, c2.stroke_colour = blend_colour(c0.stroke_colour, c1.stroke_colour); /* Plot the outline */ - if (!plot.line(x0, y0, x1, y0, &c0)) return false; - if (!plot.line(x1, y0, x1, y1 + 1, &c1)) return false; - if (!plot.line(x1, y0, x1, y0 + 1, &c2)) return false; - if (!plot.line(x1, y1, x0, y1, &c1)) return false; - if (!plot.line(x0, y1, x0, y0, &c0)) return false; - if (!plot.line(x0, y1, x0, y1 + 1, &c2)) return false; + if (!plot->line(x0, y0, x1, y0, &c0)) return false; + if (!plot->line(x1, y0, x1, y1 + 1, &c1)) return false; + if (!plot->line(x1, y0, x1, y0 + 1, &c2)) return false; + if (!plot->line(x1, y1, x0, y1, &c1)) return false; + if (!plot->line(x0, y1, x0, y0, &c0)) return false; + if (!plot->line(x0, y1, x0, y1 + 1, &c2)) return false; return true; } @@ -186,8 +190,10 @@ static inline bool scrollbar_redraw_scrollbar_rectangle(int x0, int y0, * Exported function. Documented in scrollbar.h */ bool scrollbar_redraw(struct scrollbar *s, int x, int y, - const struct rect *clip, float scale) + const struct rect *clip, float scale, + const struct redraw_context *ctx) { + const struct plotter_table *plot = ctx->plot; int w = SCROLLBAR_WIDTH; int bar_pos, bar_c0, bar_c1; int v[6]; /* array of triangle vertices */ @@ -237,17 +243,17 @@ bool scrollbar_redraw(struct scrollbar *s, int x, int y, /* scrollbar outline */ if (!scrollbar_redraw_scrollbar_rectangle(x0, y0, x1, y1, - scrollbar_widget_bg_colour, true)) + scrollbar_widget_bg_colour, true, ctx)) return false; /* left arrow icon border */ if (!scrollbar_redraw_scrollbar_rectangle(x0 + 1, y0 + 1, x0 + w - 2, y1 - 1, - scrollbar_widget_fg_colour, false)) + scrollbar_widget_fg_colour, false, ctx)) return false; /* left arrow icon background */ - if (!plot.rectangle(x0 + 2, + if (!plot->rectangle(x0 + 2, y0 + 2, x0 + w - 2, y1 - 1, @@ -260,10 +266,10 @@ bool scrollbar_redraw(struct scrollbar *s, int x, int y, v[3] = y0 + w / 4; v[4] = x0 + w * 3 / 4; v[5] = y0 + w * 3 / 4; - if (!plot.polygon(v, 3, &pstyle_scrollbar_widget_arrow_colour)) + if (!plot->polygon(v, 3, &pstyle_scrollbar_widget_arrow_colour)) return false; /* scrollbar well background */ - if (!plot.rectangle(x0 + w - 1, + if (!plot->rectangle(x0 + w - 1, y0 + 1, x1 - w + 2, y1, @@ -274,9 +280,9 @@ bool scrollbar_redraw(struct scrollbar *s, int x, int y, y0 + 1, bar_c1, y1 - 1, - scrollbar_widget_fg_colour, false)) + scrollbar_widget_fg_colour, false, ctx)) return false; - if (!plot.rectangle(bar_c0 + 1, + if (!plot->rectangle(bar_c0 + 1, y0 + 2, bar_c1, y1 - 1, @@ -287,10 +293,10 @@ bool scrollbar_redraw(struct scrollbar *s, int x, int y, y0 + 1, x1 - 1, y1 - 1, - scrollbar_widget_fg_colour, false)) + scrollbar_widget_fg_colour, false, ctx)) return false; /* right arrow icon background */ - if (!plot.rectangle(x1 - w + 3, + if (!plot->rectangle(x1 - w + 3, y0 + 2, x1 - 1, y1 - 1, @@ -303,7 +309,7 @@ bool scrollbar_redraw(struct scrollbar *s, int x, int y, v[3] = y0 + w / 4; v[4] = x1 - w * 3 / 4 + 1; v[5] = y0 + w * 3 / 4; - if (!plot.polygon(v, 3, &pstyle_scrollbar_widget_arrow_colour)) + if (!plot->polygon(v, 3, &pstyle_scrollbar_widget_arrow_colour)) return false; } else { /* scrollbar is vertical */ @@ -311,7 +317,7 @@ bool scrollbar_redraw(struct scrollbar *s, int x, int y, /* outline */ if (!scrollbar_redraw_scrollbar_rectangle(x0, y0, x1, y1, scrollbar_widget_bg_colour, - true)) + true, ctx)) return false; /* top arrow background */ if (!scrollbar_redraw_scrollbar_rectangle(x0 + 1, @@ -319,9 +325,9 @@ bool scrollbar_redraw(struct scrollbar *s, int x, int y, x1 - 1, y0 + w - 2, scrollbar_widget_fg_colour, - false)) + false, ctx)) return false; - if (!plot.rectangle(x0 + 2, + if (!plot->rectangle(x0 + 2, y0 + 2, x1 - 1, y0 + w - 2, @@ -334,10 +340,10 @@ bool scrollbar_redraw(struct scrollbar *s, int x, int y, v[3] = y0 + w * 3 / 4; v[4] = x0 + w * 3 / 4; v[5] = y0 + w * 3 / 4; - if (!plot.polygon(v, 3, &pstyle_scrollbar_widget_arrow_colour)) + if (!plot->polygon(v, 3, &pstyle_scrollbar_widget_arrow_colour)) return false; /* scrollbar well background */ - if (!plot.rectangle(x0 + 1, + if (!plot->rectangle(x0 + 1, y0 + w - 1, x1, y1 - w + 2, @@ -348,9 +354,9 @@ bool scrollbar_redraw(struct scrollbar *s, int x, int y, bar_c0, x1 - 1, bar_c1, - scrollbar_widget_fg_colour, false)) + scrollbar_widget_fg_colour, false, ctx)) return false; - if (!plot.rectangle(x0 + 2, + if (!plot->rectangle(x0 + 2, bar_c0 + 1, x1 - 1, bar_c1, @@ -361,9 +367,9 @@ bool scrollbar_redraw(struct scrollbar *s, int x, int y, y1 - w + 2, x1 - 1, y1 - 1, - scrollbar_widget_fg_colour, false)) + scrollbar_widget_fg_colour, false, ctx)) return false; - if (!plot.rectangle(x0 + 2, + if (!plot->rectangle(x0 + 2, y1 - w + 3, x1 - 1, y1 - 1, @@ -376,7 +382,7 @@ bool scrollbar_redraw(struct scrollbar *s, int x, int y, v[3] = y1 - w * 3 / 4 + 1; v[4] = x0 + w * 3 / 4; v[5] = y1 - w * 3 / 4 + 1; - if (!plot.polygon(v, 3, &pstyle_scrollbar_widget_arrow_colour)) + if (!plot->polygon(v, 3, &pstyle_scrollbar_widget_arrow_colour)) return false; } diff --git a/desktop/scrollbar.h b/desktop/scrollbar.h index 66bf83cf2..7c5307fff 100644 --- a/desktop/scrollbar.h +++ b/desktop/scrollbar.h @@ -93,10 +93,12 @@ void scrollbar_destroy(struct scrollbar *s); * \param y the Y coordinate to draw the scrollbar at * \param clip the clipping rectangle * \param scale scale for the redraw + * \param ctx current redraw context * \return true on succes false otherwise */ bool scrollbar_redraw(struct scrollbar *s, int x, int y, - const struct rect *clip, float scale); + const struct rect *clip, float scale, + const struct redraw_context *ctx); /** * Set the scroll value of the scrollbar. diff --git a/desktop/textarea.c b/desktop/textarea.c index 2feef0e6c..ccde1d976 100644 --- a/desktop/textarea.c +++ b/desktop/textarea.c @@ -720,14 +720,16 @@ bool textarea_reflow(struct text_area *ta, unsigned int line) * Handle redraw requests for text areas * * \param redraw Redraw request block - * \param x0 left X coordinate of redraw area - * \param y0 top Y coordinate of redraw area - * \param x1 right X coordinate of redraw area - * \param y1 bottom Y coordinate of redraw area + * \param x0 left X coordinate of redraw area + * \param y0 top Y coordinate of redraw area + * \param x1 right X coordinate of redraw area + * \param y1 bottom Y coordinate of redraw area + * \param ctx current redraw context */ void textarea_redraw(struct text_area *ta, int x, int y, - const struct rect *clip) + const struct rect *clip, const struct redraw_context *ctx) { + const struct plotter_table *plot = ctx->plot; int line0, line1, line; int chars, offset, text_y_offset, text_y_offset_baseline; unsigned int c_pos, c_len, b_start, b_end, line_len; @@ -775,9 +777,9 @@ void textarea_redraw(struct text_area *ta, int x, int y, if (r.y1 > y + ta->vis_height) r.y1 = y + ta->vis_height; - plot.clip(&r); - plot.rectangle(r.x0, r.y0, r.x1, r.y1, &plot_style_fill_bg); - plot.rectangle(x, y, + plot->clip(&r); + plot->rectangle(r.x0, r.y0, r.x1, r.y1, &plot_style_fill_bg); + plot->rectangle(x, y, x + ta->vis_width - 1, y + ta->vis_height - 1, &pstyle_stroke_border); @@ -785,7 +787,7 @@ void textarea_redraw(struct text_area *ta, int x, int y, r.x0 = x + MARGIN_LEFT; if (r.x1 > x + ta->vis_width - MARGIN_RIGHT) r.x1 = x + ta->vis_width - MARGIN_RIGHT; - plot.clip(&r); + plot->clip(&r); if (line0 > 0) c_pos = utf8_bounded_length(ta->text, @@ -869,7 +871,7 @@ void textarea_redraw(struct text_area *ta, int x, int y, b_start]), b_end, &r.x1); r.x1 += r.x0; - plot.rectangle(r.x0 - ta->scroll_x, y + + plot->rectangle(r.x0 - ta->scroll_x, y + line * ta->line_height + 1 - ta->scroll_y + text_y_offset, r.x1 - ta->scroll_x, @@ -887,7 +889,7 @@ void textarea_redraw(struct text_area *ta, int x, int y, (ta->flags & TEXTAREA_READONLY) ? READONLY_BG : BACKGROUND_COL, - plot.text(x + MARGIN_LEFT - ta->scroll_x, + plot->text(x + MARGIN_LEFT - ta->scroll_x, r.y0 - ta->scroll_y, ta->text + ta->lines[line].b_start, ta->lines[line].b_length, @@ -904,7 +906,7 @@ void textarea_redraw(struct text_area *ta, int x, int y, y += ta->caret_y + text_y_offset; if (y + caret_height >= clip->y0 && y <= clip->y1) /* Caret in vertical clip range; plot */ - plot.line(x + ta->caret_x, y + ta->caret_y, + plot->line(x + ta->caret_x, y + ta->caret_y, x + ta->caret_x, y + ta->caret_y + ta->line_height, &pstyle_stroke_caret); diff --git a/desktop/textarea.h b/desktop/textarea.h index 304b1ebfe..d8ec5c588 100644 --- a/desktop/textarea.h +++ b/desktop/textarea.h @@ -47,7 +47,7 @@ int textarea_get_text(struct text_area *ta, char *buf, unsigned int len); bool textarea_set_caret(struct text_area *ta, int caret); int textarea_get_caret(struct text_area *ta); void textarea_redraw(struct text_area *ta, int x, int y, - const struct rect *clip); + const struct rect *clip, const struct redraw_context *ctx); bool textarea_keypress(struct text_area *ta, uint32_t key); bool textarea_mouse_action(struct text_area *ta, browser_mouse_state mouse, int x, int y); diff --git a/desktop/thumbnail.c b/desktop/thumbnail.c index 6f5fd0318..b88065adb 100644 --- a/desktop/thumbnail.c +++ b/desktop/thumbnail.c @@ -57,8 +57,9 @@ static float thumbnail_get_redraw_scale(struct hlcache_handle *content, /* exported interface, documented in thumbnail.h */ bool thumbnail_redraw(struct hlcache_handle *content, - int width, int height) + int width, int height, const struct redraw_context *ctx) { + struct redraw_context new_ctx = *ctx; struct rect clip; struct content_redraw_data data; float scale; @@ -66,8 +67,8 @@ bool thumbnail_redraw(struct hlcache_handle *content, assert(content); - if (plot.option_knockout) - knockout_plot_start(&plot); + if (ctx->plot->option_knockout) + knockout_plot_start(ctx, &new_ctx); /* No selection */ current_redraw_browser = NULL; @@ -78,10 +79,10 @@ bool thumbnail_redraw(struct hlcache_handle *content, clip.x1 = width; clip.y1 = height; - plot.clip(&clip); + new_ctx.plot->clip(&clip); /* Plot white background */ - plot_ok &= plot.rectangle(clip.x0, clip.y0, clip.x1, clip.y1, + plot_ok &= new_ctx.plot->rectangle(clip.x0, clip.y0, clip.x1, clip.y1, plot_style_fill_white); /* Find the scale we're using */ @@ -99,9 +100,9 @@ bool thumbnail_redraw(struct hlcache_handle *content, data.repeat_y = false; /* Render the content */ - plot_ok &= content_redraw(content, &data, &clip); + plot_ok &= content_redraw(content, &data, &clip, &new_ctx); - if (plot.option_knockout) + if (ctx->plot->option_knockout) knockout_plot_end(); return plot_ok; diff --git a/desktop/thumbnail.h b/desktop/thumbnail.h index 71efdd81e..655c25339 100644 --- a/desktop/thumbnail.h +++ b/desktop/thumbnail.h @@ -24,6 +24,7 @@ #define _NETSURF_DESKTOP_THUMBNAIL_H_ #include <stdbool.h> +#include "utils/types.h" struct hlcache_handle; struct bitmap; @@ -37,6 +38,7 @@ struct bitmap; * \param content The content to redraw for thumbnail * \param width The thumbnail width * \param height The thumbnail height + * \param ctx current redraw context * \return true if successful, false otherwise * * The thumbnail is guaranteed to be filled to its width/height extents, so @@ -45,7 +47,7 @@ struct bitmap; * Units for width and height are pixels. */ bool thumbnail_redraw(struct hlcache_handle *content, - int width, int height); + int width, int height, const struct redraw_context *ctx); /* In platform specific thumbnail.c. */ diff --git a/desktop/tree.c b/desktop/tree.c index 0bf9ba625..c33f29df8 100644 --- a/desktop/tree.c +++ b/desktop/tree.c @@ -1570,14 +1570,17 @@ struct node *tree_node_get_next(struct node *node) /** * Draws an element's expansion icon * - * \param tree the tree to draw the expansion for - * \param element the element to draw the expansion for + * \param tree the tree to draw the expansion for + * \param element the element to draw the expansion for * \param tree_x X coordinate of the tree * \param tree_y Y coordinate of the tree + * \param ctx current redraw context */ static void tree_draw_node_expansion_toggle(struct tree *tree, - struct node *node, int tree_x, int tree_y) + struct node *node, int tree_x, int tree_y, + const struct redraw_context *ctx) { + const struct plotter_table *plot = ctx->plot; int x, y; assert(tree != NULL); @@ -1586,15 +1589,15 @@ static void tree_draw_node_expansion_toggle(struct tree *tree, if ((node->child != NULL) || (node->data.next != NULL)) { x = tree_x + node->box.x - (NODE_INSTEP / 2) - 4; y = tree_y + node->box.y + (TREE_LINE_HEIGHT - 9) / 2; - plot.rectangle(x, y, x + 9, y + 9, + plot->rectangle(x, y, x + 9, y + 9, &plot_style_fill_tree_furniture); - plot.rectangle(x , y, x + 8, y + 8, - &plot_style_stroke_tree_furniture); - plot.line(x + 2, y + 4, x + 7, y + 4, - &plot_style_stroke_tree_furniture); + plot->rectangle(x , y, x + 8, y + 8, + &plot_style_stroke_tree_furniture); + plot->line(x + 2, y + 4, x + 7, y + 4, + &plot_style_stroke_tree_furniture); if (!node->expanded) - plot.line(x + 4, y + 2, x + 4, y + 7, - &plot_style_stroke_tree_furniture); + plot->line(x + 4, y + 2, x + 4, y + 7, + &plot_style_stroke_tree_furniture); } @@ -1609,12 +1612,13 @@ static void tree_draw_node_expansion_toggle(struct tree *tree, * \param tree_x X coordinate to draw the tree at (wrt plot origin) * \param tree_y Y coordinate to draw the tree at (wrt plot origin) * \param clip clipping rectangle (wrt plot origin) + * \param ctx current redraw context */ static void tree_draw_node_element(struct tree *tree, struct node_element *element, int tree_x, int tree_y, - const struct rect *clip) + const struct rect *clip, const struct redraw_context *ctx) { - + const struct plotter_table *plot = ctx->plot; struct bitmap *bitmap = NULL; int x, y, width; bool selected = false; @@ -1657,7 +1661,7 @@ static void tree_draw_node_element(struct tree *tree, /* Valid clip rectangles only */ struct content_redraw_data data; - plot.clip(&c); + plot->clip(&c); data.x = x; data.y = y + icon_inset; @@ -1669,10 +1673,10 @@ static void tree_draw_node_element(struct tree *tree, data.repeat_x = false; data.repeat_y = false; - content_redraw(icon, &data, &c); + content_redraw(icon, &data, &c, ctx); /* Restore previous clipping area */ - plot.clip(clip); + plot->clip(clip); } } @@ -1689,14 +1693,14 @@ static void tree_draw_node_element(struct tree *tree, if (selected) { fstyle = &plot_fstyle_selected; - plot.rectangle(x, y, x + width, + plot->rectangle(x, y, x + width, y + element->box.height, &plot_style_fill_tree_selected); } else { fstyle = &plot_fstyle; } - plot.text(x + 4, y + (TREE_LINE_HEIGHT * 3 + 2) / 4, + plot->text(x + 4, y + (TREE_LINE_HEIGHT * 3 + 2) / 4, element->text, strlen(element->text), fstyle); break; @@ -1704,11 +1708,11 @@ static void tree_draw_node_element(struct tree *tree, bitmap = element->bitmap; if (bitmap == NULL) break; - plot.bitmap(x, y, element->box.width - 1, + plot->bitmap(x, y, element->box.width - 1, element->box.height - 2, bitmap, 0xFFFFFF, BITMAPF_NONE); if (!(tree->flags & TREE_NO_FURNITURE)) - plot.rectangle(x, y, x + element->box.width - 1, + plot->rectangle(x, y, x + element->box.width - 1, y + element->box.height - 3, &plot_style_stroke_tree_furniture); @@ -1726,10 +1730,13 @@ static void tree_draw_node_element(struct tree *tree, * \param tree_x X coordinate to draw the tree at (wrt plot origin) * \param tree_y Y coordinate to draw the tree at (wrt plot origin) * \param clip clipping rectangle (wrt plot origin) + * \param ctx current redraw context */ static void tree_draw_node(struct tree *tree, struct node *node, - int tree_x, int tree_y, struct rect clip) + int tree_x, int tree_y, struct rect clip, + const struct redraw_context *ctx) { + const struct plotter_table *plot = ctx->plot; struct node_element *element; struct node *parent; int x0, y0, x1, y1; @@ -1766,7 +1773,7 @@ static void tree_draw_node(struct tree *tree, struct node *node, } /* Set up the clipping area */ - plot.clip(&clip); + plot->clip(&clip); /* Draw node's furniture */ if (!(tree->flags & TREE_NO_FURNITURE)) { @@ -1777,7 +1784,7 @@ static void tree_draw_node(struct tree *tree, struct node *node, x0 = x1 = tree_x + node->box.x - (NODE_INSTEP / 2); y0 = tree_y + node->previous->box.y; y1 = tree_y + node->box.y + (TREE_LINE_HEIGHT / 2); - plot.line(x0, y0, x1, y1, + plot->line(x0, y0, x1, y1, &plot_style_stroke_tree_furniture); } if (node->next != NULL) { @@ -1786,7 +1793,7 @@ static void tree_draw_node(struct tree *tree, struct node *node, x0 = x1 = tree_x + node->box.x - (NODE_INSTEP / 2); y0 = tree_y + node->box.y + (TREE_LINE_HEIGHT / 2); y1 = tree_y + node->next->box.y; - plot.line(x0, y0, x1, y1, + plot->line(x0, y0, x1, y1, &plot_style_stroke_tree_furniture); } @@ -1798,7 +1805,7 @@ static void tree_draw_node(struct tree *tree, struct node *node, y0 = tree_y + parent->data.box.y + parent->data.box.height; y1 = y0 + (TREE_LINE_HEIGHT / 2); - plot.line(x0, y0, x1, y1, + plot->line(x0, y0, x1, y1, &plot_style_stroke_tree_furniture); } /* Line from expansion toggle to icon */ @@ -1806,9 +1813,10 @@ static void tree_draw_node(struct tree *tree, struct node *node, x1 = x0 + (NODE_INSTEP / 2) - 2; y0 = y1 = tree_y + node->data.box.y + node->data.box.height - (TREE_LINE_HEIGHT / 2); - plot.line(x0, y0, x1, y1, &plot_style_stroke_tree_furniture); + plot->line(x0, y0, x1, y1, &plot_style_stroke_tree_furniture); - tree_draw_node_expansion_toggle(tree, node, tree_x, tree_y); + tree_draw_node_expansion_toggle(tree, node, + tree_x, tree_y, ctx); } /* Draw node's element(s) @@ -1818,12 +1826,12 @@ static void tree_draw_node(struct tree *tree, struct node *node, element = element->next) { /* Draw each element of expanded node */ tree_draw_node_element(tree, element, tree_x, tree_y, - &clip); + &clip, ctx); } } else { /* Draw main title element of node */ tree_draw_node_element(tree, &node->data, tree_x, tree_y, - &clip); + &clip, ctx); } } @@ -1836,9 +1844,11 @@ static void tree_draw_node(struct tree *tree, struct node *node, * \param tree_x X coordinate to draw the tree at (wrt plot origin) * \param tree_y Y coordinate to draw the tree at (wrt plot origin) * \param clip clipping rectangle (wrt plot origin) + * \param ctx current redraw context */ static void tree_draw_tree(struct tree *tree, struct node *node, - int tree_x, int tree_y, struct rect clip) + int tree_x, int tree_y, struct rect clip, + const struct redraw_context *ctx) { struct node *child; @@ -1858,11 +1868,11 @@ static void tree_draw_tree(struct tree *tree, struct node *node, return; /* Draw current child */ - tree_draw_node(tree, child, tree_x, tree_y, clip); + tree_draw_node(tree, child, tree_x, tree_y, clip, ctx); /* And its children */ if ((child->child != NULL) && (child->expanded)) { /* Child has children and they are visible */ - tree_draw_tree(tree, child, tree_x, tree_y, clip); + tree_draw_tree(tree, child, tree_x, tree_y, clip, ctx); } } } @@ -1878,35 +1888,38 @@ static void tree_draw_tree(struct tree *tree, struct node *node, * \param clip_y minimum y of the clipping rectangle (wrt tree origin) * \param clip_width width of the clipping rectangle * \param clip_height height of the clipping rectangle + * \param ctx current redraw context */ void tree_draw(struct tree *tree, int x, int y, - int clip_x, int clip_y, int clip_width, int clip_height) + int clip_x, int clip_y, int clip_width, int clip_height, + const struct redraw_context *ctx) { + struct redraw_context new_ctx = *ctx; struct rect clip; assert(tree != NULL); assert(tree->root != NULL); /* Start knockout rendering if it's available for this plotter */ - if (plot.option_knockout) - knockout_plot_start(&plot); + if (ctx->plot->option_knockout) + knockout_plot_start(ctx, &new_ctx); /* Set up clip rectangle */ clip.x0 = x + clip_x; clip.y0 = y + clip_y; clip.x1 = clip.x0 + clip_width; clip.y1 = clip.y0 + clip_height; - plot.clip(&clip); + new_ctx.plot->clip(&clip); /* Flat fill extents of clipping area */ - plot.rectangle(clip.x0, clip.y0, clip.x1, clip.y1, + new_ctx.plot->rectangle(clip.x0, clip.y0, clip.x1, clip.y1, &plot_style_fill_tree_background); /* don't draw empty trees or trees with redraw flag set to false */ if (tree->root->child != NULL && tree->redraw) { /* Draw the tree */ - tree_draw_tree(tree, tree->root, x, y, clip); + tree_draw_tree(tree, tree->root, x, y, clip, &new_ctx); /* Draw textarea, if present */ if (tree->editing != NULL) { @@ -1914,12 +1927,12 @@ void tree_draw(struct tree *tree, int x, int y, y = y + tree->editing->box.y; if (tree->editing->type == NODE_ELEMENT_TEXT_PLUS_ICON) x += NODE_INSTEP; - textarea_redraw(tree->textarea, x, y, &clip); + textarea_redraw(tree->textarea, x, y, &clip, &new_ctx); } } /* Rendering complete */ - if (plot.option_knockout) + if (ctx->plot->option_knockout) knockout_plot_end(); } diff --git a/desktop/tree.h b/desktop/tree.h index 0fb904bb7..e3dc8c98a 100644 --- a/desktop/tree.h +++ b/desktop/tree.h @@ -177,7 +177,8 @@ struct node *tree_node_get_child(struct node *node); struct node *tree_node_get_next(struct node *node); void tree_draw(struct tree *tree, int x, int y, - int clip_x, int clip_y, int clip_width, int clip_height); + int clip_x, int clip_y, int clip_width, int clip_height, + const struct redraw_context *ctx); struct node_element *tree_node_find_element(struct node *node, unsigned int flag, struct node_element *after); |