index 86b1e9eabbbb75580a0063238e705e55754a2aed..a558774c451dd35933405a22f40da46d439e5cea 100644 (file)
#include <gtk/gtkmain.h>
#include <gtk/gtksignal.h>
+#include <gtk/gtkversion.h>
#include <gtkmm.h>
#if ENABLE_LCMS
#include "color-profile-fns.h"
#endif // ENABLE_LCMS
+#include "display/rendermode.h"
+#include "libnr/nr-blit.h"
+#include "display/inkscape-cairo.h"
+#include "debug/gdk-event-latency-tracker.h"
+
+using Inkscape::Debug::GdkEventLatencyTracker;
+
+// GTK_CHECK_VERSION returns false on failure
+#define HAS_GDK_EVENT_REQUEST_MOTIONS GTK_CHECK_VERSION(2, 12, 0)
+
+// gtk_check_version returns non-NULL on failure
+static bool const HAS_BROKEN_MOTION_HINTS =
+ true || gtk_check_version(2, 12, 0) != NULL || !HAS_GDK_EVENT_REQUEST_MOTIONS;
// Define this to visualize the regions to be redrawn
//#define DEBUG_REDRAW 1;
// If any part of it is dirtied, the entire tile is dirtied (its int is nonzero) and repainted.
#define TILE_SIZE 16
-enum {
- RENDERMODE_NORMAL,
- RENDERMODE_NOAA,
- RENDERMODE_OUTLINE
-};
-
static gint const sp_canvas_update_priority = G_PRIORITY_HIGH_IDLE;
#define SP_CANVAS_WINDOW(c) (((GtkWidget *) (c))->window)
static void sp_canvas_request_update (SPCanvas *canvas);
+static void track_latency(GdkEvent const *event);
static void sp_canvas_item_class_init (SPCanvasItemClass *klass);
static void sp_canvas_item_init (SPCanvasItem *item);
static void sp_canvas_item_dispose (GObject *object);
@@ -534,6 +543,10 @@ sp_canvas_item_grab (SPCanvasItem *item, guint event_mask, GdkCursor *cursor, gu
if (!(item->flags & SP_CANVAS_ITEM_VISIBLE))
return -1;
+ if (HAS_BROKEN_MOTION_HINTS) {
+ event_mask &= ~GDK_POINTER_MOTION_HINT_MASK;
+ }
+
/* fixme: Top hack (Lauris) */
/* fixme: If we add key masks to event mask, Gdk will abort (Lauris) */
/* fixme: But Canvas actualle does get key events, so all we need is routing these here */
/**
* Registers SPCanvasGroup class with Gtk and returns its type number.
*/
-GtkType
-sp_canvas_group_get_type (void)
+GType sp_canvas_group_get_type(void)
{
- static GtkType group_type = 0;
-
- if (!group_type) {
- static GtkTypeInfo const group_info = {
- "SPCanvasGroup",
- sizeof (SPCanvasGroup),
- sizeof (SPCanvasGroupClass),
- (GtkClassInitFunc) sp_canvas_group_class_init,
- (GtkObjectInitFunc) sp_canvas_group_init,
- NULL, NULL, NULL
+ static GType type = 0;
+ if (!type) {
+ GTypeInfo info = {
+ sizeof(SPCanvasGroupClass),
+ 0, // base_init
+ 0, // base_finalize
+ (GClassInitFunc)sp_canvas_group_class_init,
+ 0, // class_finalize
+ 0, // class_data
+ sizeof(SPCanvasGroup),
+ 0, // n_preallocs
+ (GInstanceInitFunc)sp_canvas_group_init,
+ 0 // value_table
};
-
- group_type = gtk_type_unique (sp_canvas_item_get_type (), &group_info);
+ type = g_type_register_static(sp_canvas_item_get_type(), "SPCanvasGroup", &info, static_cast<GTypeFlags>(0));
}
-
- return group_type;
+ return type;
}
/**
@@ -779,7 +792,7 @@ sp_canvas_group_update (SPCanvasItem *item, NR::Matrix const &affine, unsigned i
}
}
- NR::Maybe<NR::Rect> const bounds = corners.bounds();
+ boost::optional<NR::Rect> const bounds = corners.bounds();
if (bounds) {
item->x1 = bounds->min()[NR::X];
item->y1 = bounds->min()[NR::Y];
*
* \return The type ID of the SPCanvas class.
**/
-GtkType
-sp_canvas_get_type (void)
-{
- static GtkType canvas_type = 0;
-
- if (!canvas_type) {
- static GtkTypeInfo const canvas_info = {
- "SPCanvas",
- sizeof (SPCanvas),
- sizeof (SPCanvasClass),
- (GtkClassInitFunc) sp_canvas_class_init,
- (GtkObjectInitFunc) sp_canvas_init,
- NULL, NULL, NULL
+GType sp_canvas_get_type(void)
+{
+ static GType type = 0;
+ if (!type) {
+ GTypeInfo info = {
+ sizeof(SPCanvasClass),
+ 0, // base_init
+ 0, // base_finalize
+ (GClassInitFunc)sp_canvas_class_init,
+ 0, // class_finalize
+ 0, // class_data
+ sizeof(SPCanvas),
+ 0, // n_preallocs
+ (GInstanceInitFunc)sp_canvas_init,
+ 0 // value_table
};
-
- canvas_type = gtk_type_unique (GTK_TYPE_WIDGET, &canvas_info);
+ type = g_type_register_static(GTK_TYPE_WIDGET, "SPCanvas", &info, static_cast<GTypeFlags>(0));
}
-
- return canvas_type;
+ return type;
}
/**
(* GTK_OBJECT_CLASS (canvas_parent_class)->destroy) (object);
}
+static void track_latency(GdkEvent const *event) {
+ GdkEventLatencyTracker &tracker = GdkEventLatencyTracker::default_tracker();
+ boost::optional<double> latency = tracker.process(event);
+ if (latency && *latency > 2.0) {
+ g_warning("Event latency reached %f sec (%1.4f)", *latency, tracker.getSkew());
+ }
+}
+
/**
* Returns new canvas as widget.
*/
GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK |
GDK_POINTER_MOTION_MASK |
+ ( HAS_BROKEN_MOTION_HINTS ?
+ 0 : GDK_POINTER_MOTION_HINT_MASK ) |
GDK_PROXIMITY_IN_MASK |
GDK_PROXIMITY_OUT_MASK |
GDK_KEY_PRESS_MASK |
{
SPCanvas *canvas = SP_CANVAS (widget);
+ canvas->current_item = NULL;
+ canvas->grabbed_item = NULL;
+ canvas->focused_item = NULL;
+
shutdown_transients (canvas);
gdk_gc_destroy (canvas->pixmap_gc);
return emit_event (SP_CANVAS (widget), (GdkEvent *) event);
}
+static inline void request_motions(GdkWindow *w, GdkEventMotion *event) {
+ gdk_window_get_pointer(w, NULL, NULL, NULL);
+#if HAS_GDK_EVENT_REQUEST_MOTIONS
+ gdk_event_request_motions(event);
+#endif
+}
+
/**
* Motion event handler for the canvas.
*/
static int
sp_canvas_motion (GtkWidget *widget, GdkEventMotion *event)
{
+ int status;
SPCanvas *canvas = SP_CANVAS (widget);
+ track_latency((GdkEvent *)event);
+
if (event->window != SP_CANVAS_WINDOW (canvas))
return FALSE;
- if (canvas->grabbed_event_mask & GDK_POINTER_MOTION_HINT_MASK) {
- gint x, y;
- gdk_window_get_pointer (widget->window, &x, &y, NULL);
- event->x = x;
- event->y = y;
- }
+ if (canvas->pixmap_gc == NULL) // canvas being deleted
+ return FALSE;
canvas->state = event->state;
pick_current_item (canvas, (GdkEvent *) event);
- return emit_event (canvas, (GdkEvent *) event);
+ status = emit_event (canvas, (GdkEvent *) event);
+
+ if (event->is_hint) {
+ request_motions(widget->window, event);
+ }
+
+ return status;
}
static void
@@ -1563,7 +1602,7 @@ sp_canvas_paint_single_buffer (SPCanvas *canvas, int x0, int y0, int x1, int y1,
GtkWidget *widget = GTK_WIDGET (canvas);
SPCanvasBuf buf;
- if (canvas->rendermode != RENDERMODE_OUTLINE) {
+ if (canvas->rendermode != Inkscape::RENDERMODE_OUTLINE) {
buf.buf = nr_pixelstore_256K_new (FALSE, 0);
} else {
buf.buf = nr_pixelstore_1M_new (FALSE, 0);
@@ -1572,7 +1611,7 @@ sp_canvas_paint_single_buffer (SPCanvas *canvas, int x0, int y0, int x1, int y1,
// Mark the region clean
sp_canvas_mark_rect(canvas, x0, y0, x1, y1, 0);
- buf.buf_rowstride = sw * 3; // CAIRO FIXME: for cairo output, the buffer must be RGB unpacked, i.e. sw * 4
+ buf.buf_rowstride = sw * 4;
buf.rect.x0 = x0;
buf.rect.y0 = y0;
buf.rect.x1 = x1;
@@ -1587,6 +1626,8 @@ sp_canvas_paint_single_buffer (SPCanvas *canvas, int x0, int y0, int x1, int y1,
| (color->blue >> 8));
buf.is_empty = true;
+ buf.ct = nr_create_cairo_context_canvasbuf (&(buf.visible_rect), &buf);
+
if (canvas->root->flags & SP_CANVAS_ITEM_VISIBLE) {
SP_CANVAS_ITEM_GET_CLASS (canvas->root)->render (canvas->root, &buf);
}
@@ -1614,27 +1655,6 @@ sp_canvas_paint_single_buffer (SPCanvas *canvas, int x0, int y0, int x1, int y1,
x0 - canvas->x0, y0 - canvas->y0,
x1 - x0, y1 - y0);
} else {
-/*
-// CAIRO FIXME: after SPCanvasBuf is made 32bpp throughout, this rgb_draw below can be replaced with the below.
-// Why this must not be done currently:
-// - all canvas items (handles, nodes etc) paint themselves assuming 24bpp
-// - cairo assumes bgra, but we have rgba, so r and b get swapped (until we paint all with cairo too)
-// - it does not seem to be any faster; in fact since with 32bpp, buf contains less pixels,
-// we need more bufs to paint a given area and as a result it's even a bit slower
-
- cairo_surface_t* cst = cairo_image_surface_create_for_data (
- buf.buf,
- CAIRO_FORMAT_RGB24, // unpacked, i.e. 32 bits! one byte is unused
- x1 - x0, y1 - y0,
- buf.buf_rowstride
- );
- cairo_t *ct = gdk_cairo_create(SP_CANVAS_WINDOW (canvas));
- cairo_set_source_surface (ct, cst, x0 - canvas->x0, y0 - canvas->y0);
- cairo_paint (ct);
- cairo_destroy (ct);
- cairo_surface_finish (cst);
- cairo_surface_destroy (cst);
-*/
#if ENABLE_LCMS
if ( transf && canvas->enable_cms_display_adj ) {
@@ -1645,17 +1665,64 @@ sp_canvas_paint_single_buffer (SPCanvas *canvas, int x0, int y0, int x1, int y1,
}
#endif // ENABLE_LCMS
+// Now we only need to output the prepared pixmap to the actual screen, and this define chooses one
+// of the two ways to do it. The cairo way is direct and straightforward, but unfortunately
+// noticeably slower. I asked Carl Worth but he was unable so far to suggest any specific reason
+// for this slowness. So, for now we use the oldish method: squeeze out 32bpp buffer to 24bpp and
+// use gdk_draw_rgb_image_dithalign, for unfortunately gdk can only handle 24 bpp, which cairo
+// cannot handle at all. Still, this way is currently faster even despite the blit with squeeze.
+
+///#define CANVAS_OUTPUT_VIA_CAIRO
+
+#ifdef CANVAS_OUTPUT_VIA_CAIRO
+
+ buf.cst = cairo_image_surface_create_for_data (
+ buf.buf,
+ CAIRO_FORMAT_ARGB32, // unpacked, i.e. 32 bits! one byte is unused
+ x1 - x0, y1 - y0,
+ buf.buf_rowstride
+ );
+ cairo_t *window_ct = gdk_cairo_create(SP_CANVAS_WINDOW (canvas));
+ cairo_set_source_surface (window_ct, buf.cst, x0 - canvas->x0, y0 - canvas->y0);
+ cairo_paint (window_ct);
+ cairo_destroy (window_ct);
+ cairo_surface_finish (buf.cst);
+ cairo_surface_destroy (buf.cst);
+
+#else
+
+ NRPixBlock b3;
+ nr_pixblock_setup_fast (&b3, NR_PIXBLOCK_MODE_R8G8B8, x0, y0, x1, y1, TRUE);
+
+ NRPixBlock b4;
+ nr_pixblock_setup_extern (&b4, NR_PIXBLOCK_MODE_R8G8B8A8P, x0, y0, x1, y1,
+ buf.buf,
+ buf.buf_rowstride,
+ FALSE, FALSE);
+
+ // this does the 32->24 squishing, using an assembler routine:
+ nr_blit_pixblock_pixblock (&b3, &b4);
+
gdk_draw_rgb_image_dithalign (SP_CANVAS_WINDOW (canvas),
canvas->pixmap_gc,
x0 - canvas->x0, y0 - canvas->y0,
x1 - x0, y1 - y0,
GDK_RGB_DITHER_MAX,
- buf.buf,
+ NR_PIXBLOCK_PX(&b3),
sw * 3,
x0 - canvas->x0, y0 - canvas->y0);
+
+ nr_pixblock_release (&b3);
+ nr_pixblock_release (&b4);
+#endif
}
- if (canvas->rendermode != RENDERMODE_OUTLINE) {
+ cairo_surface_t *cst = cairo_get_target(buf.ct);
+ cairo_destroy (buf.ct);
+ cairo_surface_finish (cst);
+ cairo_surface_destroy (cst);
+
+ if (canvas->rendermode != Inkscape::RENDERMODE_OUTLINE) {
nr_pixelstore_256K_free (buf.buf);
} else {
nr_pixelstore_1M_free (buf.buf);
gdk_window_get_pointer (GTK_WIDGET(canvas)->window, &x, &y, NULL);
setup.mouse_loc = sp_canvas_window_to_world (canvas, NR::Point(x,y));
- // CAIRO FIXME: the sw/sh calculations below all assume 24bpp, need fixing for 32bpp
- if (canvas->rendermode != RENDERMODE_OUTLINE) {
+ if (canvas->rendermode != Inkscape::RENDERMODE_OUTLINE) {
// use 256K as a compromise to not slow down gradients
- // 256K is the cached buffer and we need 3 channels
- setup.max_pixels = 87381; // 256K/3
+ // 256K is the cached buffer and we need 4 channels
+ setup.max_pixels = 65536; // 256K/4
} else {
// paths only, so 1M works faster
- // 1M is the cached buffer and we need 3 channels
- setup.max_pixels = 349525;
+ // 1M is the cached buffer and we need 4 channels
+ setup.max_pixels = 262144;
}
// Start the clock
static int
do_update (SPCanvas *canvas)
{
- if (!canvas->root) // canvas may have already be destroyed by closing desktop durring interrupted display!
+ if (!canvas->root || !canvas->pixmap_gc) // canvas may have already be destroyed by closing desktop durring interrupted display!
return TRUE;
/* Cause the update if necessary */