I'm seeking feedback on my changes to make the knockout plotting optional
based on the plotter backend (patch attached). I've added a new entry
'option_knockout' to 'struct plotter_table' which basically is a request
from that plotter backend for the content redraw routine to get called in
such a way that overlapping render areas are avoided as much as possible
(that's what I'm assuming the knockout.c code is doing).
However, it is up to the content redraw code to actually implement this
option if it is reasonably profitable. This was and is currently done
explicitly by the html content redraw code. On top of that the riscos
plotter code was installing the knockout plotter itself for all content
types except plaintext and SVG and this is no longer being done in this
patch.
In patch more detail:
- desktop/plotters.h: added struct plotter_table::option_knockout
- render/html_redraw.c(html_redraw): if the plotter backend wants the
knockout calling behaviour, install the knockout plotter which will then
call the real backend. Also check on the return values of clg and clip
plotter calls.
- Plotter backend changes:
-> no longer plotting in knockout mode:
- gtk/gtk_print.c: BTW, also removed what I think is a 2nd instance
of "struct plotter_table plot" (the first one is in
gtk/gtk_plotters.c), right ?
- riscos/save_draw.c
- riscos/print.c: in addition I noticed that the path plotter
function pointer wasn't filled in and this is now fixed.
- pdf/pdf_plotters.c: I also removed the flush function as this is
optional and we only had a dummy implementation there.
-> remaining to request knockout mode if it makes sense based on the
content type:
- gtk/gtk_plotters.c: but I guess this needs testing by the GTK
developers if this remains a good choice or not.
- riscos/plotters.c
- desktop/knockout.c: I believe its option_knockout needs to be
'true' because knockout_plot_start/knockout_plot_end needs to
be called for each recursive html_redraw() call.
- riscos/window.c: I'm a bit confused why there were tests on the
content type which determine to additionally install the
knockout plotter in front of the real plotter code as as far as
I believe that only HTML content is profitable to be plotted
in knockout mode, no ?
Does this change make sense ? Anything which I'm overlooking here ?
John.
--
John Tytgat
[EMAIL PROTECTED]
Index: render/html_redraw.c
===================================================================
--- render/html_redraw.c (revision 4811)
+++ render/html_redraw.c (working copy)
@@ -115,24 +115,27 @@
float scale, unsigned long background_colour)
{
struct box *box;
- bool result;
+ bool result, want_knockout;
box = c->data.html.layout;
assert(box);
- knockout_plot_start(&plot);
+ want_knockout = plot.option_knockout;
+ if (want_knockout)
+ knockout_plot_start(&plot);
/* clear to background colour */
- plot.clip(clip_x0, clip_y0, clip_x1, clip_y1);
+ result = plot.clip(clip_x0, clip_y0, clip_x1, clip_y1);
if (c->data.html.background_colour != TRANSPARENT)
background_colour = c->data.html.background_colour;
- plot.clg(background_colour);
+ result &= plot.clg(background_colour);
- result = html_redraw_box(box, x, y,
+ result &= html_redraw_box(box, x, y,
clip_x0, clip_y0, clip_x1, clip_y1,
scale, background_colour, 0);
- knockout_plot_end();
+ if (want_knockout)
+ knockout_plot_end();
return result;
Index: gtk/gtk_print.c
===================================================================
--- gtk/gtk_print.c (revision 4810)
+++ gtk/gtk_print.c (working copy)
@@ -92,8 +92,6 @@
static GdkRectangle cliprect;
-struct plotter_table plot;
-
static const struct plotter_table nsgtk_print_plotters = {
nsgtk_print_plot_clg,
nsgtk_print_plot_rectangle,
@@ -109,7 +107,8 @@
NULL,
NULL,
NULL,
- nsgtk_print_plot_path
+ nsgtk_print_plot_path,
+ false
};
static const struct printer gtk_printer= {
Index: gtk/gtk_plotters.c
===================================================================
--- gtk/gtk_plotters.c (revision 4810)
+++ gtk/gtk_plotters.c (working copy)
@@ -93,7 +93,8 @@
NULL,
NULL,
NULL,
- nsgtk_plot_path
+ nsgtk_plot_path,
+ true
};
Index: riscos/save_draw.c
===================================================================
--- riscos/save_draw.c (revision 4812)
+++ riscos/save_draw.c (working copy)
@@ -79,6 +79,7 @@
ro_save_draw_group_end,
NULL,
ro_save_draw_path,
+ false
};
static struct pencil_diagram *ro_save_draw_diagram;
Index: riscos/window.c
===================================================================
--- riscos/window.c (revision 4810)
+++ riscos/window.c (working copy)
@@ -45,7 +45,6 @@
#include "css/css.h"
#include "desktop/browser.h"
#include "desktop/frames.h"
-#include "desktop/knockout.h"
#include "desktop/plotters.h"
#include "desktop/textinput.h"
#include "desktop/tree.h"
@@ -1409,11 +1408,9 @@
void ro_gui_window_redraw(wimp_draw *redraw)
{
osbool more;
- bool knockout = true;
struct gui_window *g = (struct gui_window
*)ro_gui_wimp_event_get_user_data(redraw->w);
float scale = g->bw->scale;
struct content *c = g->bw->current_content;
- int clip_x0, clip_y0, clip_x1, clip_y1, clear_x1, clear_y1;
os_error *error;
/* Handle no content quickly
@@ -1435,15 +1432,6 @@
ro_gui_current_redraw_gui = g;
current_redraw_browser = g->bw;
- /* rendering textplain has no advantages using knockout rendering other
- * than to slow things down. */
- if (c->type == CONTENT_TEXTPLAIN
-#ifdef WITH_NS_SVG
- || c->type == CONTENT_SVG
-#endif
- )
- knockout = false;
-
/* HTML rendering handles scale itself */
if (c->type == CONTENT_HTML)
scale = 1;
@@ -1456,6 +1444,8 @@
return;
}
while (more) {
+ int clip_x0, clip_y0, clip_x1, clip_y1, clear_x1, clear_y1;
+
ro_plot_origin_x = redraw->box.x0 - redraw->xscroll;
ro_plot_origin_y = redraw->box.y1 - redraw->yscroll;
clip_x0 = (redraw->clip.x0 - ro_plot_origin_x) / 2;
@@ -1468,10 +1458,7 @@
if (ro_gui_current_redraw_gui->option.buffer_everything)
ro_gui_buffer_open(redraw);
- if (knockout) {
- knockout_plot_start(&plot);
- plot.clip(clip_x0, clip_y0, clip_x1, clip_y1);
- }
+ plot.clip(clip_x0, clip_y0, clip_x1, clip_y1);
if (c->type != CONTENT_HTML)
plot.clg(0x00ffffff);
@@ -1481,8 +1468,7 @@
clip_x0, clip_y0, clip_x1, clip_y1,
g->bw->scale,
0xFFFFFF);
- if (knockout)
- knockout_plot_end();
+
if (ro_gui_current_redraw_gui->option.buffer_everything)
ro_gui_buffer_close();
Index: riscos/plotters.c
===================================================================
--- riscos/plotters.c (revision 4810)
+++ riscos/plotters.c (working copy)
@@ -77,6 +77,7 @@
NULL,
NULL,
ro_plot_path,
+ true
};
int ro_plot_origin_x = 0;
Index: riscos/print.c
===================================================================
--- riscos/print.c (revision 4810)
+++ riscos/print.c (working copy)
@@ -119,8 +119,8 @@
static bool print_fonts_plot_bitmap_tile(int x, int y, int width, int height,
struct bitmap *bitmap, colour bg,
bool repeat_x, bool repeat_y, struct content *content);
-static bool print_fonts_plot_group_start(const char *name);
-static bool print_fonts_plot_group_end(void);
+static bool print_fonts_plot_path(float *p, unsigned int n, colour fill, float
width,
+ colour c, float *transform);
static void print_fonts_callback(void *context,
const char *font_name, unsigned int font_size,
const char *s8, unsigned short *s16, unsigned int n,
@@ -141,10 +141,11 @@
print_fonts_plot_arc,
print_fonts_plot_bitmap,
print_fonts_plot_bitmap_tile,
- print_fonts_plot_group_start,
- print_fonts_plot_group_end,
NULL,
- NULL
+ NULL,
+ NULL,
+ print_fonts_plot_path,
+ false
};
@@ -629,6 +630,7 @@
}
plot = ro_plotters;
+ plot.option_knockout = false;
ro_plot_set_scale(print_scale);
ro_gui_current_redraw_gui = g;
current_redraw_browser = NULL; /* we don't want to print the
@@ -863,14 +865,11 @@
{
return true;
}
-bool print_fonts_plot_group_start(const char *name)
+bool print_fonts_plot_path(float *p, unsigned int n, colour fill, float width,
+ colour c, float *transform)
{
return true;
}
-bool print_fonts_plot_group_end(void)
-{
- return true;
-}
/**
Index: desktop/plotters.h
===================================================================
--- desktop/plotters.h (revision 4810)
+++ desktop/plotters.h (working copy)
@@ -52,11 +52,12 @@
bool (*bitmap_tile)(int x, int y, int width, int height,
struct bitmap *bitmap, colour bg,
bool repeat_x, bool repeat_y, struct content *content);
- bool (*group_start)(const char *name); /** optional */
- bool (*group_end)(void); /** optional */
- bool (*flush)(void);
+ bool (*group_start)(const char *name); /**< optional, may be NULL */
+ bool (*group_end)(void); /**< optional, may be NULL */
+ bool (*flush)(void); /**< optional, may be NULL */
bool (*path)(float *p, unsigned int n, colour fill, float width,
colour c, float *transform);
+ bool option_knockout; /**< when set, avoid areas are replotted more
than once. */
};
/** Current plotters, must be assigned before use. */
Index: desktop/knockout.c
===================================================================
--- desktop/knockout.c (revision 4812)
+++ desktop/knockout.c (working copy)
@@ -38,7 +38,6 @@
static void knockout_set_plotters(void);
-static bool knockout_plot_flush(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, colour c);
static bool knockout_plot_bitmap_tile_recursive(struct knockout_box *box,
@@ -50,8 +49,6 @@
static bool knockout_plot_line(int x0, int y0, int x1, int y1, int width,
colour c, bool dotted, bool dashed);
static bool knockout_plot_polygon(int *p, unsigned int n, colour fill);
-static bool knockout_plot_path(float *p, unsigned int n, colour fill,
- float width, colour c, float *transform);
static bool knockout_plot_fill(int x0, int y0, int x1, int y1, colour c);
static bool knockout_plot_clip(int clip_x0, int clip_y0,
int clip_x1, int clip_y1);
@@ -65,8 +62,11 @@
static bool knockout_plot_bitmap_tile(int x, int y, int width, int height,
struct bitmap *bitmap, colour bg,
bool repeat_x, bool repeat_y, struct content *content);
+static bool knockout_plot_flush(void);
static bool knockout_plot_group_start(const char *name);
static bool knockout_plot_group_end(void);
+static bool knockout_plot_path(float *p, unsigned int n, colour fill,
+ float width, colour c, float *transform);
const struct plotter_table knockout_plotters = {
@@ -85,6 +85,7 @@
knockout_plot_group_end,
knockout_plot_flush,
knockout_plot_path,
+ true
};
Index: pdf/pdf_plotters.c
===================================================================
--- pdf/pdf_plotters.c (revision 4813)
+++ pdf/pdf_plotters.c (working copy)
@@ -64,7 +64,6 @@
static bool pdf_plot_bitmap_tile(int x, int y, int width, int height,
struct bitmap *bitmap, colour bg,
bool repeat_x, bool repeat_y, struct content *content);
-static bool pdf_plot_flush(void);
static bool pdf_plot_path(float *p, unsigned int n, colour fill, float width,
colour c, float *transform);
@@ -113,8 +112,9 @@
pdf_plot_bitmap_tile,
NULL,
NULL,
- pdf_plot_flush,
- pdf_plot_path
+ NULL,
+ pdf_plot_path,
+ false
};
struct printer pdf_printer= {
@@ -515,19 +515,12 @@
return image;
}
-
-bool pdf_plot_flush(void)
+static inline float transform_x(float *transform, float x, float y)
{
- return true;
-}
-
-
-static inline float transform_x(float *transform,float x,float y)
-{
return ((transform[0] * x) + (transform[2] * (-y) ) + transform[4]) * 2;
}
-static inline float transform_y(float *transform,float x,float y)
+static inline float transform_y(float *transform, float x, float y)
{
return page_height - (((transform[1] * x) +
(transform[3] * (-y)) - transform[5]) * 2);