Make Cairo rendering a run-time option in nsgtk - also add infrastructure for nsgtk-specific options.

svn path=/trunk/netsurf/; revision=2793
This commit is contained in:
Rob Kendrick 2006-07-23 22:32:33 +00:00
parent 754b0c0c73
commit 18d84f0c10
6 changed files with 132 additions and 84 deletions

View File

@ -29,8 +29,10 @@
#include "netsurf/utils/messages.h"
#include "netsurf/utils/utils.h"
#ifdef riscos
#if defined(riscos)
#include "netsurf/riscos/options.h"
#elif defined(nsgtk)
#include "netsurf/gtk/options.h"
#else
#define EXTRA_OPTION_DEFINE
#define EXTRA_OPTION_TABLE

View File

@ -12,8 +12,8 @@
#include <glade/glade.h>
#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);

View File

@ -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 (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
} else
#endif
gdk_draw_rectangle(current_drawable, current_gc,
FALSE, x0, y0, width, height);
#endif
return true;
}
@ -113,6 +116,7 @@ bool nsgtk_plot_line(int x0, int y0, int x1, int y1, int width,
nsgtk_set_solid();
#ifdef CAIRO_VERSION
if (option_render_cairo) {
if (width == 0)
width = 1;
@ -120,10 +124,10 @@ bool nsgtk_plot_line(int x0, int y0, int x1, int y1, int width,
cairo_move_to(current_cr, x0, y0 - 0.5);
cairo_line_to(current_cr, x1, y1 - 0.5);
cairo_stroke(current_cr);
#else
} else
#endif
gdk_draw_line(current_drawable, current_gc,
x0, y0, x1, y1);
#endif
return true;
}
@ -135,6 +139,7 @@ bool nsgtk_plot_polygon(int *p, unsigned int n, colour fill)
nsgtk_set_colour(fill);
nsgtk_set_solid();
#ifdef CAIRO_VERSION
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++) {
@ -142,7 +147,9 @@ bool nsgtk_plot_polygon(int *p, unsigned int n, colour fill)
}
cairo_fill(current_cr);
cairo_stroke(current_cr);
#else
} else
#endif
{
GdkPoint q[n];
for (i = 0; i != n; i++) {
q[i].x = p[i * 2];
@ -150,7 +157,7 @@ bool nsgtk_plot_polygon(int *p, unsigned int n, colour fill)
}
gdk_draw_polygon(current_drawable, current_gc,
TRUE, q, n);
#endif
}
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
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
} 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
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,6 +212,7 @@ 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 (option_render_cairo) {
if (filled)
cairo_set_line_width(current_cr, 0);
else
@ -213,13 +224,14 @@ bool nsgtk_plot_disc(int x, int y, int radius, colour c, bool filled)
cairo_fill(current_cr);
cairo_stroke(current_cr);
#else
} 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
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
} 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;
if (option_render_cairo)
cairo_set_dash(current_cr, &dashes, 0, 0);
#else
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 };
#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);
#endif
}
}
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 };
#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);
#endif
}
}
void nsgtk_plot_set_scale(float s)

View File

@ -1235,7 +1235,6 @@ NTML authentication</property>
<child>
<widget class="GtkCheckButton" id="checkUseCairo">
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="tooltip" translatable="yes">Enable the use of Cairo, which provides better looking results at the cost of speed.</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Use Cairo for anti-aliased drawing</property>

23
gtk/options.h Normal file
View File

@ -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 <rjek@rjek.com>
*/
#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

View File

@ -120,7 +120,7 @@ CFLAGS_RISCOS_SMALL = $(CFLAGS_RISCOS) -Dsmall
CFLAGS_NCOS = $(CFLAGS_RISCOS) -Dncos
CFLAGS_DEBUG = -std=c9x -D_BSD_SOURCE -DDEBUG_BUILD $(WARNFLAGS) -I.. \
$(PLATFORM_CFLAGS_DEBUG) -g
CFLAGS_GTK = -std=c9x -D_BSD_SOURCE -D_POSIX_C_SOURCE -Dgtk \
CFLAGS_GTK = -Dnsgtk -std=c9x -D_BSD_SOURCE -D_POSIX_C_SOURCE -Dgtk \
$(WARNFLAGS) -I.. -g -O0 -Wformat=2 \
`pkg-config --cflags libglade-2.0 gtk+-2.0` `xml2-config --cflags`