[maemo-commits] [maemo-commits] r12631 - in projects/haf/trunk/sapwood: . src

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Tue Jul 3 17:43:10 EEST 2007
Author: tko
Date: 2007-07-03 17:42:55 +0300 (Tue, 03 Jul 2007)
New Revision: 12631

Modified:
   projects/haf/trunk/sapwood/ChangeLog
   projects/haf/trunk/sapwood/configure.in
   projects/haf/trunk/sapwood/src/sapwood-pixmap.c
   projects/haf/trunk/sapwood/src/sapwood-pixmap.h
   projects/haf/trunk/sapwood/src/sapwood-render.c
Log:
Implement downscaling

2007-07-03  Tommi Komulainen  <tommi.komulainen at nokia.com>

	* src/sapwood-pixmap.c (sapwood_pixmap_render_rects): Rename to
	sapwood_pixmap_render_rects_internal.
	* src/sapwood-pixmap.h (sapwood_pixmap_render_rects): Add width and
	height parameters in order to do downscaling.
	* src/sapwood-pixmap.c (sapwood_pixmap_render_rects): When rendering
	to a target smaller than the pixmap, paint first at least as big as
	the pixmaps and scale down to target size using cairo.
	* configure.in: bump gtk+ dependency to 2.8 due to cairo


Modified: projects/haf/trunk/sapwood/ChangeLog
===================================================================
--- projects/haf/trunk/sapwood/ChangeLog	2007-07-03 13:59:38 UTC (rev 12630)
+++ projects/haf/trunk/sapwood/ChangeLog	2007-07-03 14:42:55 UTC (rev 12631)
@@ -1,5 +1,16 @@
 2007-07-03  Tommi Komulainen  <tommi.komulainen at nokia.com>
 
+	* src/sapwood-pixmap.c (sapwood_pixmap_render_rects): Rename to
+	sapwood_pixmap_render_rects_internal.
+	* src/sapwood-pixmap.h (sapwood_pixmap_render_rects): Add width and
+	height parameters in order to do downscaling.
+	* src/sapwood-pixmap.c (sapwood_pixmap_render_rects): When rendering
+	to a target smaller than the pixmap, paint first at least as big as
+	the pixmaps and scale down to target size using cairo.
+	* configure.in: bump gtk+ dependency to 2.8 due to cairo
+
+2007-07-03  Tommi Komulainen  <tommi.komulainen at nokia.com>
+
 	* src/sapwood-render.c (theme_pixbuf_render): Refactor painting of
 	centered pixmaps using sapwood_pixmap_render_rects()
 	* src/sapwood-pixmap.h (sapwood_pixmap_render)

Modified: projects/haf/trunk/sapwood/configure.in
===================================================================
--- projects/haf/trunk/sapwood/configure.in	2007-07-03 13:59:38 UTC (rev 12630)
+++ projects/haf/trunk/sapwood/configure.in	2007-07-03 14:42:55 UTC (rev 12631)
@@ -89,7 +89,7 @@
 AM_DISABLE_STATIC
 AM_PROG_LIBTOOL
 
-PKG_CHECK_MODULES(GTK, gtk+-2.0 >= 1.3.12)
+PKG_CHECK_MODULES(GTK, gtk+-2.0 >= 2.8)
 
 GTK_VERSION=`$PKG_CONFIG --variable=gtk_binary_version gtk+-2.0`
 AC_SUBST(GTK_CFLAGS)

Modified: projects/haf/trunk/sapwood/src/sapwood-pixmap.c
===================================================================
--- projects/haf/trunk/sapwood/src/sapwood-pixmap.c	2007-07-03 13:59:38 UTC (rev 12630)
+++ projects/haf/trunk/sapwood/src/sapwood-pixmap.c	2007-07-03 14:42:55 UTC (rev 12631)
@@ -304,18 +304,18 @@
   *pixmask = self->pixmask[y][x];
 }
 
-void
-sapwood_pixmap_render_rects (SapwoodPixmap *self,
-			    GdkDrawable  *draw,
-			    gint          draw_x,
-			    gint          draw_y,
-			    GdkBitmap    *mask,
-			    gint          mask_x,
-			    gint          mask_y,
-			    gboolean      mask_required,
-			    GdkRectangle *clip_rect,
-			    gint          n_rect,
-			    SapwoodRect   *rect)
+static void
+sapwood_pixmap_render_rects_internal (SapwoodPixmap *self,
+                                      GdkDrawable   *draw,
+                                      gint           draw_x,
+                                      gint           draw_y,
+                                      GdkBitmap     *mask,
+                                      gint           mask_x,
+                                      gint           mask_y,
+                                      gboolean       mask_required,
+                                      GdkRectangle  *clip_rect,
+                                      gint           n_rect,
+                                      SapwoodRect   *rect)
 {
   static GdkGC *mask_gc = NULL;
   static GdkGC *draw_gc = NULL;
@@ -396,3 +396,97 @@
 	}
     }
 }
+
+void
+sapwood_pixmap_render_rects (SapwoodPixmap *self,
+                             GdkDrawable   *draw,
+                             gint           draw_x,
+                             gint           draw_y,
+                             gint           width,
+                             gint           height,
+                             GdkBitmap     *mask,
+                             gint           mask_x,
+                             gint           mask_y,
+                             gboolean       mask_required,
+                             GdkRectangle  *clip_rect,
+                             gint           n_rect,
+                             SapwoodRect   *rect)
+{
+  gint       tmp_width;
+  gint       tmp_height;
+  GdkPixmap *tmp;
+  gboolean   need_tmp_mask = FALSE;
+  GdkPixmap *tmp_mask = NULL;
+  cairo_t   *mask_cr = NULL;
+  cairo_t   *tmp_cr;
+  cairo_t   *cr;
+  gint       n;
+  
+  /* Don't even try to scale down shape masks (should never be useful, and
+   * implementing would add some complexity.) Areas larger than the pixmap
+   * can be tiled fine.
+   */
+  if (mask_required || (width >= self->width && height >= self->height))
+    {
+      sapwood_pixmap_render_rects_internal (self, draw, draw_x, draw_y, mask, mask_x, mask_y, mask_required, clip_rect, n_rect, rect);
+      return;
+    }
+
+  /* offset the drawing on temporary pixmap */
+  for (n = 0; n < n_rect; n++)
+    {
+      SapwoodRect *r = &rect[n];
+      r->dest.x -= draw_x;
+      r->dest.y -= draw_y;
+      if (r->pixmap && r->pixmask)
+	need_tmp_mask = TRUE;
+    }
+
+  /* prepare temporary pixmap and mask to draw in full size */
+  tmp_width = MAX(width, self->width);
+  tmp_height = MAX(height, self->height);
+
+  tmp = gdk_pixmap_new (draw, tmp_width, tmp_height, -1);
+
+  if (need_tmp_mask)
+    {
+      tmp_mask = gdk_pixmap_new (draw, tmp_width, tmp_height, 1);
+
+      mask_cr = gdk_cairo_create (tmp_mask);
+      cairo_set_source_rgb (mask_cr, 1., 1., 1.);
+      cairo_paint (mask_cr);
+    }
+
+  sapwood_pixmap_render_rects_internal (self, tmp, 0, 0, tmp_mask, 0, 0, mask_required, NULL, n_rect, rect);
+
+  tmp_cr = gdk_cairo_create (tmp);
+
+  /* finally, render downscaled at draw_x,draw_y */
+  cr = gdk_cairo_create (draw);
+  if (clip_rect)
+    {
+      gdk_cairo_rectangle (cr, clip_rect);
+      cairo_clip (cr);
+    }
+  cairo_rectangle (cr, draw_x, draw_y, width, height);
+  cairo_clip (cr);
+
+  cairo_translate (cr, draw_x, draw_y);
+  cairo_scale (cr, (double)width / (double)tmp_width,
+		   (double)height / (double)tmp_height);
+
+  cairo_set_source_surface (cr, cairo_get_target (tmp_cr), 0, 0);
+  if (mask_cr)
+    cairo_mask_surface (cr, cairo_get_target (mask_cr), 0, 0);
+  else
+    cairo_paint (cr);
+
+  /* clean up */
+  cairo_destroy (cr);
+  if (mask_cr)
+    cairo_destroy (mask_cr);
+  if (tmp_mask)
+    g_object_unref (tmp_mask);
+  cairo_destroy (tmp_cr);
+  g_object_unref (tmp);
+}

Modified: projects/haf/trunk/sapwood/src/sapwood-pixmap.h
===================================================================
--- projects/haf/trunk/sapwood/src/sapwood-pixmap.h	2007-07-03 13:59:38 UTC (rev 12630)
+++ projects/haf/trunk/sapwood/src/sapwood-pixmap.h	2007-07-03 14:42:55 UTC (rev 12631)
@@ -64,6 +64,8 @@
 				      GdkDrawable  *draw,
 				      gint          draw_x,
 				      gint          draw_y,
+				      gint          width,
+				      gint          height,
 				      GdkBitmap    *mask,
 				      gint          mask_x,
 				      gint          mask_y,

Modified: projects/haf/trunk/sapwood/src/sapwood-render.c
===================================================================
--- projects/haf/trunk/sapwood/src/sapwood-render.c	2007-07-03 13:59:38 UTC (rev 12630)
+++ projects/haf/trunk/sapwood/src/sapwood-render.c	2007-07-03 14:42:55 UTC (rev 12631)
@@ -251,6 +251,8 @@
   SapwoodPixmap *pixmap;
   gint pixbuf_width;
   gint pixbuf_height;
+  gint draw_width;
+  gint draw_height;
   SapwoodRect rect[9];
   gint       n_rect;
   gint       mask_x;
@@ -265,17 +267,21 @@
 
   pixmap = theme_pixbuf_get_pixmap (theme_pb);
 
+  /* if we do scaling we want to draw at least the whole pixmap */
+  draw_width  = MAX(width, pixbuf_width);
+  draw_height = MAX(height, pixbuf_height);
+
   if (theme_pb->stretch)
     {
       dest_x[0] = x;
       dest_x[1] = x + theme_pb->border_left;
-      dest_x[2] = x + width - theme_pb->border_right;
-      dest_x[3] = x + width;
+      dest_x[2] = x + draw_width - theme_pb->border_right;
+      dest_x[3] = x + draw_width;
 
       dest_y[0] = y;
       dest_y[1] = y + theme_pb->border_top;
-      dest_y[2] = y + height - theme_pb->border_bottom;
-      dest_y[3] = y + height;
+      dest_y[2] = y + draw_height - theme_pb->border_bottom;
+      dest_y[3] = y + draw_height;
 
       if (component_mask & COMPONENT_ALL)
 	component_mask = (COMPONENT_ALL - 1) & ~component_mask;
@@ -363,7 +369,7 @@
 	}
 
       sapwood_pixmap_render_rects (pixmap,
-                                   window, x, y,
+                                   window, x, y, width, height,
                                    mask, mask_x, mask_y, mask_required,
                                    clip_rect, n_rect, rect);
 
@@ -371,8 +377,8 @@
     }
   else if (center)
     {
-      x += (width - pixbuf_width) / 2;
-      y += (height - pixbuf_height) / 2;
+      x += (draw_width - pixbuf_width) / 2;
+      y += (draw_height - pixbuf_height) / 2;
 
       sapwood_pixmap_get_pixmap (pixmap, 1, 1,
                                  &rect[0].pixmap, &rect[0].pixmask);
@@ -382,7 +388,7 @@
       rect[0].dest.height = pixbuf_height;
 
       sapwood_pixmap_render_rects (pixmap,
-                                   window, x, y,
+                                   window, x, y, width, height,
                                    mask, x, y, FALSE,
                                    clip_rect, 1, rect);
     }


More information about the maemo-commits mailing list