From 18d84f0c108c207f90d64803dd8834cfe6525374 Mon Sep 17 00:00:00 2001 From: Rob Kendrick Date: Sun, 23 Jul 2006 22:32:33 +0000 Subject: Make Cairo rendering a run-time option in nsgtk - also add infrastructure for nsgtk-specific options. svn path=/trunk/netsurf/; revision=2793 --- gtk/gtk_options.c | 11 ++-- gtk/gtk_plotters.c | 179 ++++++++++++++++++++++++++++++----------------------- gtk/netsurf.glade | 1 - gtk/options.h | 23 +++++++ 4 files changed, 130 insertions(+), 84 deletions(-) create mode 100644 gtk/options.h (limited to 'gtk') diff --git a/gtk/gtk_options.c b/gtk/gtk_options.c index 86bf5ff54..5ee4ee8d8 100644 --- a/gtk/gtk_options.c +++ b/gtk/gtk_options.c @@ -12,8 +12,8 @@ #include #include "netsurf/utils/log.h" #include "netsurf/desktop/options.h" +#include "netsurf/gtk/options.h" #include "netsurf/gtk/gtk_gui.h" -#include "netsurf/desktop/options.h" #include "netsurf/gtk/gtk_options.h" GtkWindow *wndChoices; @@ -102,8 +102,8 @@ void nsgtk_options_init(void) { } #define SET_ENTRY(x, y) gtk_entry_set_text(GTK_ENTRY((x)), (y)) -#define SET_SPIN(x, y) gtk_spin_button_set_value((x), (y)) -#define SET_CHECK(x, y) gtk_toggle_button_set_active((x), (y)) +#define SET_SPIN(x, y) gtk_spin_button_set_value(GTK_SPIN_BUTTON((x)), (y)) +#define SET_CHECK(x, y) gtk_toggle_button_set_active(GTK_CHECK_BUTTON((x)), (y)) void nsgtk_options_load(void) { char *b[20]; @@ -122,7 +122,8 @@ void nsgtk_options_load(void) { SET_SPIN(spinFetchesPerHost, option_max_fetchers_per_host); SET_SPIN(spinCachedConnections, option_max_cached_fetch_handles); - /* TODO: set checkUseCairo and checkReampleImages here */ + /* TODO: set checkResampleImages here */ + SET_CHECK(checkUseCairo, option_render_cairo); SET_SPIN(spinAnimationSpeed, option_minimum_gif_delay); SET_CHECK(checkDisableAnimations, !option_animate_images); @@ -136,10 +137,12 @@ void nsgtk_options_load(void) { #define GET_ENTRY(x, y) if ((y)) free((y)); \ (y) = strdup(gtk_entry_get_text(GTK_ENTRY((x)))) +#define GET_CHECK(x, y) (y) = gtk_toggle_button_get_active(GTK_CHECK_BUTTON((x))) void nsgtk_options_save(void) { GET_ENTRY(entryHomePageURL, option_homepage_url); + GET_CHECK(checkUseCairo, option_render_cairo); /* TODO: save the other options */ options_write(options_file_location); diff --git a/gtk/gtk_plotters.c b/gtk/gtk_plotters.c index 27f173eef..8eda4a83d 100644 --- a/gtk/gtk_plotters.c +++ b/gtk/gtk_plotters.c @@ -24,6 +24,8 @@ #include "netsurf/gtk/gtk_window.h" #include "netsurf/render/font.h" #include "netsurf/utils/log.h" +#include "netsurf/desktop/options.h" +#include "netsurf/gtk/options.h" static bool nsgtk_plot_clg(colour c); static bool nsgtk_plot_rectangle(int x0, int y0, int width, int height, @@ -87,16 +89,17 @@ bool nsgtk_plot_rectangle(int x0, int y0, int width, int height, nsgtk_set_solid(); #ifdef CAIRO_VERSION - if (line_width == 0) - line_width = 1; - - cairo_set_line_width(current_cr, line_width); - cairo_rectangle(current_cr, x0, y0, width, height); - cairo_stroke(current_cr); -#else + if (option_render_cairo) { + if (line_width == 0) + line_width = 1; + + cairo_set_line_width(current_cr, line_width); + cairo_rectangle(current_cr, x0, y0, width, height); + cairo_stroke(current_cr); + } else +#endif gdk_draw_rectangle(current_drawable, current_gc, FALSE, x0, y0, width, height); -#endif return true; } @@ -113,17 +116,18 @@ bool nsgtk_plot_line(int x0, int y0, int x1, int y1, int width, nsgtk_set_solid(); #ifdef CAIRO_VERSION - if (width == 0) - width = 1; - - cairo_set_line_width(current_cr, width); - cairo_move_to(current_cr, x0, y0 - 0.5); - cairo_line_to(current_cr, x1, y1 - 0.5); - cairo_stroke(current_cr); -#else + if (option_render_cairo) { + if (width == 0) + width = 1; + + cairo_set_line_width(current_cr, width); + cairo_move_to(current_cr, x0, y0 - 0.5); + cairo_line_to(current_cr, x1, y1 - 0.5); + cairo_stroke(current_cr); + } else +#endif gdk_draw_line(current_drawable, current_gc, x0, y0, x1, y1); -#endif return true; } @@ -135,22 +139,25 @@ bool nsgtk_plot_polygon(int *p, unsigned int n, colour fill) nsgtk_set_colour(fill); nsgtk_set_solid(); #ifdef CAIRO_VERSION - cairo_set_line_width(current_cr, 0); - cairo_move_to(current_cr, p[0], p[1]); - for (i = 1; i != n; i++) { - cairo_line_to(current_cr, p[i * 2], p[i * 2 + 1]); - } - cairo_fill(current_cr); - cairo_stroke(current_cr); -#else - GdkPoint q[n]; - for (i = 0; i != n; i++) { - q[i].x = p[i * 2]; - q[i].y = p[i * 2 + 1]; - } - gdk_draw_polygon(current_drawable, current_gc, - TRUE, q, n); + if (option_render_cairo) { + cairo_set_line_width(current_cr, 0); + cairo_move_to(current_cr, p[0], p[1]); + for (i = 1; i != n; i++) { + cairo_line_to(current_cr, p[i * 2], p[i * 2 + 1]); + } + cairo_fill(current_cr); + cairo_stroke(current_cr); + } else #endif + { + GdkPoint q[n]; + for (i = 0; i != n; i++) { + q[i].x = p[i * 2]; + q[i].y = p[i * 2 + 1]; + } + gdk_draw_polygon(current_drawable, current_gc, + TRUE, q, n); + } return true; } @@ -160,14 +167,15 @@ bool nsgtk_plot_fill(int x0, int y0, int x1, int y1, colour c) nsgtk_set_colour(c); nsgtk_set_solid(); #ifdef CAIRO_VERSION - cairo_set_line_width(current_cr, 0); - cairo_rectangle(current_cr, x0, y0, x1 - x0, y1 - y0); - cairo_fill(current_cr); - cairo_stroke(current_cr); -#else + if (option_render_cairo) { + cairo_set_line_width(current_cr, 0); + cairo_rectangle(current_cr, x0, y0, x1 - x0, y1 - y0); + cairo_fill(current_cr); + cairo_stroke(current_cr); + } else +#endif gdk_draw_rectangle(current_drawable, current_gc, TRUE, x0, y0, x1 - x0, y1 - y0); -#endif return true; } @@ -176,10 +184,12 @@ bool nsgtk_plot_clip(int clip_x0, int clip_y0, int clip_x1, int clip_y1) { #ifdef CAIRO_VERSION - cairo_reset_clip(current_cr); - cairo_rectangle(current_cr, clip_x0 - 1, clip_y0 - 1, - clip_x1 - clip_x0 + 1, clip_y1 - clip_y0 + 1); - cairo_clip(current_cr); + if (option_render_cairo) { + cairo_reset_clip(current_cr); + cairo_rectangle(current_cr, clip_x0 - 1, clip_y0 - 1, + clip_x1 - clip_x0 + 1, clip_y1 - clip_y0 + 1); + cairo_clip(current_cr); + } #endif cliprect.x = clip_x0; cliprect.y = clip_y0; @@ -202,24 +212,26 @@ bool nsgtk_plot_disc(int x, int y, int radius, colour c, bool filled) nsgtk_set_colour(c); nsgtk_set_solid(); #ifdef CAIRO_VERSION - if (filled) - cairo_set_line_width(current_cr, 0); - else - cairo_set_line_width(current_cr, 1); + if (option_render_cairo) { + if (filled) + cairo_set_line_width(current_cr, 0); + else + cairo_set_line_width(current_cr, 1); - cairo_arc(current_cr, x, y, radius, 0, M_PI * 2); + cairo_arc(current_cr, x, y, radius, 0, M_PI * 2); - if (filled) - cairo_fill(current_cr); + if (filled) + cairo_fill(current_cr); - cairo_stroke(current_cr); -#else + cairo_stroke(current_cr); + } else +#endif gdk_draw_arc(current_drawable, current_gc, filled ? TRUE : FALSE, x - (radius), y - radius, radius * 2, radius * 2, 0, 360 * 64); -#endif + return true; } @@ -228,17 +240,19 @@ bool nsgtk_plot_arc(int x, int y, int radius, int angle1, int angle2, colour c) nsgtk_set_colour(c); nsgtk_set_solid(); #ifdef CAIRO_VERSION - cairo_set_line_width(current_cr, 1); - cairo_arc(current_cr, x, y, radius, - (angle1 + 90) * (M_PI / 180), - (angle2 + 90) * (M_PI / 180)); - cairo_stroke(current_cr); -#else + if (option_render_cairo) { + cairo_set_line_width(current_cr, 1); + cairo_arc(current_cr, x, y, radius, + (angle1 + 90) * (M_PI / 180), + (angle2 + 90) * (M_PI / 180)); + cairo_stroke(current_cr); + } else +#endif gdk_draw_arc(current_drawable, current_gc, FALSE, x - (radius), y - radius, radius * 2, radius * 2, angle1 * 64, angle2 * 64); -#endif + return true; } @@ -337,7 +351,9 @@ void nsgtk_set_colour(colour c) &colour); gdk_gc_set_foreground(current_gc, &colour); #ifdef CAIRO_VERSION - cairo_set_source_rgba(current_cr, r / 255.0, g / 255.0, b / 255.0, 1.0); + if (option_render_cairo) + cairo_set_source_rgba(current_cr, r / 255.0, + g / 255.0, b / 255.0, 1.0); #endif } @@ -345,39 +361,44 @@ void nsgtk_set_solid() { #ifdef CAIRO_VERSION double dashes = 0; - cairo_set_dash(current_cr, &dashes, 0, 0); -#else + if (option_render_cairo) + cairo_set_dash(current_cr, &dashes, 0, 0); + else +#endif gdk_gc_set_line_attributes(current_gc, 1, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER); -#endif } void nsgtk_set_dotted() { -#ifdef CAIRO_VERSION - double dashes = 1; - cairo_set_dash(current_cr, &dashes, 1, 0); -#else + double cdashes = 1; gint8 dashes[] = { 1, 1 }; - - gdk_gc_set_dashes(current_gc, 0, dashes, 2); - gdk_gc_set_line_attributes(current_gc, 1, GDK_LINE_ON_OFF_DASH, - GDK_CAP_BUTT, GDK_JOIN_MITER); +#ifdef CAIRO_VERSION + if (option_render_cairo) + cairo_set_dash(current_cr, &cdashes, 1, 0); + else #endif + { + gdk_gc_set_dashes(current_gc, 0, dashes, 2); + gdk_gc_set_line_attributes(current_gc, 1, GDK_LINE_ON_OFF_DASH, + GDK_CAP_BUTT, GDK_JOIN_MITER); + } } void nsgtk_set_dashed() { -#ifdef CAIRO_VERSION - double dashes = 3; - cairo_set_dash(current_cr, &dashes, 1, 0); -#else + double cdashes = 3; gint8 dashes[] = { 3, 3 }; - - gdk_gc_set_dashes(current_gc, 0, dashes, 2); - gdk_gc_set_line_attributes(current_gc, 1, GDK_LINE_ON_OFF_DASH, - GDK_CAP_BUTT, GDK_JOIN_MITER); +#ifdef CAIRO_VERSION + if (option_render_cairo) + cairo_set_dash(current_cr, &cdashes, 1, 0); + else #endif + { + gdk_gc_set_dashes(current_gc, 0, dashes, 2); + gdk_gc_set_line_attributes(current_gc, 1, GDK_LINE_ON_OFF_DASH, + GDK_CAP_BUTT, GDK_JOIN_MITER); + } } void nsgtk_plot_set_scale(float s) diff --git a/gtk/netsurf.glade b/gtk/netsurf.glade index 9507c50ec..7c0abc64d 100644 --- a/gtk/netsurf.glade +++ b/gtk/netsurf.glade @@ -1235,7 +1235,6 @@ NTML authentication True - False Enable the use of Cairo, which provides better looking results at the cost of speed. True Use Cairo for anti-aliased drawing diff --git a/gtk/options.h b/gtk/options.h new file mode 100644 index 000000000..62bc633a3 --- /dev/null +++ b/gtk/options.h @@ -0,0 +1,23 @@ +/* This s file is part of NetSurf, http://netsurf.sourceforge.net/ + * Licensed under the GNU General Public License, + * http://www.opensource.org/licenses/gpl-license + * Copyright 2006 Rob Kendrick + */ + +#ifndef _NETSURF_GTK_OPTIONS_H_ +#define _NETSURF_GTK_OPTIONS_H_ + +#include "netsurf/desktop/options.h" + +extern bool option_render_cairo; +extern bool option_render_resample; + +#define EXTRA_OPTION_DEFINE \ +bool option_render_cairo = true; \ +bool option_render_resample = false; + +#define EXTRA_OPTION_TABLE \ +{ "render_cairo", OPTION_BOOL, &option_render_cairo }, \ +{ "render_resample", OPTION_BOOL, &option_render_resample }, + +#endif -- cgit v1.2.3