[gthumb] [image_viewer] use the region field to optimize redraw times
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb] [image_viewer] use the region field to optimize redraw times
- Date: Sun, 18 Jul 2010 10:47:56 +0000 (UTC)
commit 482a422038b8e4fa763c1ef6b4dcfa0fd4cf886e
Author: Paolo Bacchilega <paobac src gnome org>
Date: Sun Jul 18 12:43:51 2010 +0200
[image_viewer] use the region field to optimize redraw times
gthumb/gth-image-dragger.c | 20 ++++-----
gthumb/gth-image-selector.c | 88 +++++++++++++++-------------------------
gthumb/gth-image-viewer-tool.c | 12 +++---
gthumb/gth-image-viewer-tool.h | 12 +++---
gthumb/gth-image-viewer.c | 38 +++++++++++++++++-
gthumb/gth-image-viewer.h | 7 +++
6 files changed, 97 insertions(+), 80 deletions(-)
---
diff --git a/gthumb/gth-image-dragger.c b/gthumb/gth-image-dragger.c
index 635b124..a6e294e 100644
--- a/gthumb/gth-image-dragger.c
+++ b/gthumb/gth-image-dragger.c
@@ -128,12 +128,11 @@ gth_image_dragger_unmap (GthImageViewerTool *base)
static void
gth_image_dragger_expose (GthImageViewerTool *self,
- GdkRectangle *event_area)
+ GdkEventExpose *event)
{
GthImageDragger *dragger;
GthImageViewer *viewer;
GdkInterpType interp_type;
- GdkRectangle paint_area;
dragger = (GthImageDragger *) self;
viewer = dragger->priv->viewer;
@@ -149,16 +148,13 @@ gth_image_dragger_expose (GthImageViewerTool *self,
if (gth_image_viewer_get_zoom (viewer) == 1.0)
interp_type = GDK_INTERP_NEAREST;
- if (gdk_rectangle_intersect (&viewer->image_area, event_area, &paint_area))
- gth_image_viewer_paint (viewer,
- gth_image_viewer_get_current_pixbuf (viewer),
- viewer->x_offset + paint_area.x - viewer->image_area.x,
- viewer->y_offset + paint_area.y - viewer->image_area.y,
- paint_area.x,
- paint_area.y,
- paint_area.width,
- paint_area.height,
- interp_type);
+ gth_image_viewer_paint_region (viewer,
+ gth_image_viewer_get_current_pixbuf (viewer),
+ viewer->x_offset - viewer->image_area.x,
+ viewer->y_offset - viewer->image_area.y,
+ &viewer->image_area,
+ event->region,
+ interp_type);
}
diff --git a/gthumb/gth-image-selector.c b/gthumb/gth-image-selector.c
index fc05d48..17ab49e 100644
--- a/gthumb/gth-image-selector.c
+++ b/gthumb/gth-image-selector.c
@@ -586,58 +586,43 @@ gth_image_selector_unmap (GthImageViewerTool *base)
}
-G_GNUC_UNUSED
-static void
-print_rectangle (const char *name,
- GdkRectangle *r)
-{
- g_print ("%s ==> (%d,%d) [%d,%d]\n", name, r->x, r->y, r->width, r->height);
-}
-
-
static void
paint_background (GthImageSelector *self,
- GdkRectangle *event_area)
+ GdkEventExpose *event)
{
- GdkRectangle paint_area;
-
- if (! gdk_rectangle_intersect (&self->priv->viewer->image_area, event_area, &paint_area))
- return;
-
- gth_image_viewer_paint (self->priv->viewer,
- self->priv->background,
- self->priv->viewer->x_offset + paint_area.x - self->priv->viewer->image_area.x,
- self->priv->viewer->y_offset + paint_area.y - self->priv->viewer->image_area.y,
- paint_area.x,
- paint_area.y,
- paint_area.width,
- paint_area.height,
- GDK_INTERP_TILES);
+ gth_image_viewer_paint_region (self->priv->viewer,
+ self->priv->background,
+ self->priv->viewer->x_offset - self->priv->viewer->image_area.x,
+ self->priv->viewer->y_offset - self->priv->viewer->image_area.y,
+ &self->priv->viewer->image_area,
+ event->region,
+ GDK_INTERP_TILES);
}
static void
paint_selection (GthImageSelector *self,
- GdkRectangle *event_area)
+ GdkEventExpose *event)
{
- GdkRectangle selection_area, paint_area;
+ GdkRectangle selection_area;
+ GdkRectangle paint_area;
selection_area = self->priv->selection_area;
selection_area.x += self->priv->viewer->image_area.x - self->priv->viewer->x_offset;
selection_area.y += self->priv->viewer->image_area.y - self->priv->viewer->y_offset;
- if (! gdk_rectangle_intersect (&selection_area, event_area, &paint_area))
+ if (! gdk_rectangle_intersect (&selection_area, &event->area, &paint_area))
return;
- gth_image_viewer_paint (self->priv->viewer,
- self->priv->pixbuf,
- self->priv->viewer->x_offset + paint_area.x - self->priv->viewer->image_area.x,
- self->priv->viewer->y_offset + paint_area.y - self->priv->viewer->image_area.y,
- paint_area.x,
- paint_area.y,
- paint_area.width,
- paint_area.height,
- GDK_INTERP_TILES);
+ gth_image_viewer_paint_region (self->priv->viewer,
+ self->priv->pixbuf,
+ self->priv->viewer->x_offset - self->priv->viewer->image_area.x,
+ self->priv->viewer->y_offset - self->priv->viewer->image_area.y,
+ &selection_area,
+ event->region,
+ GDK_INTERP_TILES);
+
+ gdk_gc_set_clip_region (self->priv->selection_gc, event->region);
if (self->priv->grid_type != GTH_GRID_NONE) {
int grid_x0, grid_x1, grid_x2, grid_x3;
@@ -694,28 +679,21 @@ paint_selection (GthImageSelector *self,
static void
paint_image (GthImageSelector *self,
- GdkRectangle *event_area)
+ GdkEventExpose *event)
{
- GdkRectangle paint_area;
-
- if (! gdk_rectangle_intersect (&self->priv->viewer->image_area, event_area, &paint_area))
- return;
-
- gth_image_viewer_paint (self->priv->viewer,
- self->priv->pixbuf,
- self->priv->viewer->x_offset + paint_area.x - self->priv->viewer->image_area.x,
- self->priv->viewer->y_offset + paint_area.y - self->priv->viewer->image_area.y,
- paint_area.x,
- paint_area.y,
- paint_area.width,
- paint_area.height,
- GDK_INTERP_TILES);
+ gth_image_viewer_paint_region (self->priv->viewer,
+ self->priv->pixbuf,
+ self->priv->viewer->x_offset - self->priv->viewer->image_area.x,
+ self->priv->viewer->y_offset - self->priv->viewer->image_area.y,
+ &self->priv->viewer->image_area,
+ event->region,
+ GDK_INTERP_TILES);
}
static void
gth_image_selector_expose (GthImageViewerTool *base,
- GdkRectangle *event_area)
+ GdkEventExpose *event)
{
GthImageSelector *self = GTH_IMAGE_SELECTOR (base);
@@ -723,11 +701,11 @@ gth_image_selector_expose (GthImageViewerTool *base,
return;
if (self->priv->mask_visible) {
- paint_background (self, event_area);
- paint_selection (self, event_area);
+ paint_background (self, event);
+ paint_selection (self, event);
}
else
- paint_image (self, event_area);
+ paint_image (self, event);
}
diff --git a/gthumb/gth-image-viewer-tool.c b/gthumb/gth-image-viewer-tool.c
index 46c82fb..be6c7f1 100644
--- a/gthumb/gth-image-viewer-tool.c
+++ b/gthumb/gth-image-viewer-tool.c
@@ -80,7 +80,7 @@ gth_image_viewer_tool_unrealize (GthImageViewerTool *self)
void
gth_image_viewer_tool_size_allocate (GthImageViewerTool *self,
- GtkAllocation *allocation)
+ GtkAllocation *allocation)
{
GTH_IMAGE_VIEWER_TOOL_GET_INTERFACE (self)->size_allocate (self, allocation);
}
@@ -88,15 +88,15 @@ gth_image_viewer_tool_size_allocate (GthImageViewerTool *self,
void
gth_image_viewer_tool_expose (GthImageViewerTool *self,
- GdkRectangle *paint_area)
+ GdkEventExpose *event)
{
- GTH_IMAGE_VIEWER_TOOL_GET_INTERFACE (self)->expose (self, paint_area);
+ GTH_IMAGE_VIEWER_TOOL_GET_INTERFACE (self)->expose (self, event);
}
gboolean
gth_image_viewer_tool_button_press (GthImageViewerTool *self,
- GdkEventButton *event)
+ GdkEventButton *event)
{
return GTH_IMAGE_VIEWER_TOOL_GET_INTERFACE (self)->button_press (self, event);
}
@@ -104,7 +104,7 @@ gth_image_viewer_tool_button_press (GthImageViewerTool *self,
gboolean
gth_image_viewer_tool_button_release (GthImageViewerTool *self,
- GdkEventButton *event)
+ GdkEventButton *event)
{
return GTH_IMAGE_VIEWER_TOOL_GET_INTERFACE (self)->button_release (self, event);
}
@@ -112,7 +112,7 @@ gth_image_viewer_tool_button_release (GthImageViewerTool *self,
gboolean
gth_image_viewer_tool_motion_notify (GthImageViewerTool *self,
- GdkEventMotion *event)
+ GdkEventMotion *event)
{
return GTH_IMAGE_VIEWER_TOOL_GET_INTERFACE (self)->motion_notify (self, event);
}
diff --git a/gthumb/gth-image-viewer-tool.h b/gthumb/gth-image-viewer-tool.h
index 1a30398..c69cfcf 100644
--- a/gthumb/gth-image-viewer-tool.h
+++ b/gthumb/gth-image-viewer-tool.h
@@ -43,15 +43,15 @@ struct _GthImageViewerToolIface {
void (*realize) (GthImageViewerTool *self);
void (*unrealize) (GthImageViewerTool *self);
void (*size_allocate) (GthImageViewerTool *self,
- GtkAllocation *allocation);
+ GtkAllocation *allocation);
void (*expose) (GthImageViewerTool *self,
- GdkRectangle *paint_area);
+ GdkEventExpose *event);
gboolean (*button_press) (GthImageViewerTool *self,
- GdkEventButton *event);
+ GdkEventButton *event);
gboolean (*button_release) (GthImageViewerTool *self,
- GdkEventButton *event);
+ GdkEventButton *event);
gboolean (*motion_notify) (GthImageViewerTool *self,
- GdkEventMotion *event);
+ GdkEventMotion *event);
void (*image_changed) (GthImageViewerTool *self);
void (*zoom_changed) (GthImageViewerTool *self);
};
@@ -64,7 +64,7 @@ void gth_image_viewer_tool_unrealize (GthImageViewerTool *self);
void gth_image_viewer_tool_size_allocate (GthImageViewerTool *self,
GtkAllocation *allocation);
void gth_image_viewer_tool_expose (GthImageViewerTool *self,
- GdkRectangle *paint_area);
+ GdkEventExpose *event);
gboolean gth_image_viewer_tool_button_press (GthImageViewerTool *self,
GdkEventButton *event);
gboolean gth_image_viewer_tool_button_release (GthImageViewerTool *self,
diff --git a/gthumb/gth-image-viewer.c b/gthumb/gth-image-viewer.c
index 9cb01f6..553d548 100644
--- a/gthumb/gth-image-viewer.c
+++ b/gthumb/gth-image-viewer.c
@@ -858,7 +858,7 @@ gth_image_viewer_expose (GtkWidget *widget,
x2, y2);
}
- gth_image_viewer_tool_expose (viewer->priv->tool, &event->area);
+ gth_image_viewer_tool_expose (viewer->priv->tool, event);
/* Draw the focus. */
@@ -965,8 +965,11 @@ expose_area (GthImageViewer *viewer,
event.area.y = y;
event.area.width = width;
event.area.height = height;
+ event.region = gdk_region_rectangle (&event.area);
gth_image_viewer_expose (GTK_WIDGET (viewer), &event);
+
+ gdk_region_destroy (event.region);
}
@@ -2681,6 +2684,39 @@ gth_image_viewer_paint (GthImageViewer *viewer,
void
+gth_image_viewer_paint_region (GthImageViewer *viewer,
+ GdkPixbuf *pixbuf,
+ int src_x,
+ int src_y,
+ GdkRectangle *pixbuf_area,
+ GdkRegion *region,
+ int interp_type)
+{
+ GdkRectangle *rects;
+ int n_rects;
+ int i;
+
+ gdk_region_get_rectangles (region, &rects, &n_rects);
+ for (i = 0; i < n_rects; i++) {
+ GdkRectangle paint_area;
+
+ if (gdk_rectangle_intersect (pixbuf_area, &rects[i], &paint_area))
+ gth_image_viewer_paint (viewer,
+ pixbuf,
+ src_x + paint_area.x,
+ src_y + paint_area.y,
+ paint_area.x,
+ paint_area.y,
+ paint_area.width,
+ paint_area.height,
+ interp_type);
+ }
+
+ g_free (rects);
+}
+
+
+void
gth_image_viewer_crop_area (GthImageViewer *viewer,
GdkRectangle *area)
{
diff --git a/gthumb/gth-image-viewer.h b/gthumb/gth-image-viewer.h
index 338ea4c..5d48f67 100644
--- a/gthumb/gth-image-viewer.h
+++ b/gthumb/gth-image-viewer.h
@@ -274,6 +274,13 @@ void gth_image_viewer_paint (GthImageViewer *vi
int width,
int height,
int interp_type);
+void gth_image_viewer_paint_region (GthImageViewer *viewer,
+ GdkPixbuf *pixbuf,
+ int src_x,
+ int src_y,
+ GdkRectangle *pixbuf_area,
+ GdkRegion *region,
+ int interp_type);
void gth_image_viewer_crop_area (GthImageViewer *viewer,
GdkRectangle *area);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]