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

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Tue Jul 3 16:38:25 EEST 2007
Author: tko
Date: 2007-07-03 16:38:08 +0300 (Tue, 03 Jul 2007)
New Revision: 12629

Modified:
   projects/haf/trunk/sapwood/ChangeLog
   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:
Refactor painting of centered pixmaps using sapwood_pixmap_render_rects()

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)
	* src/sapwood-pixmap.c (sapwood_pixmap_render, get_scratch_gc): Remove
	as obsolete.


Modified: projects/haf/trunk/sapwood/ChangeLog
===================================================================
--- projects/haf/trunk/sapwood/ChangeLog	2007-07-03 13:27:50 UTC (rev 12628)
+++ projects/haf/trunk/sapwood/ChangeLog	2007-07-03 13:38:08 UTC (rev 12629)
@@ -1,5 +1,13 @@
 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)
+	* src/sapwood-pixmap.c (sapwood_pixmap_render, get_scratch_gc): Remove
+	as obsolete.
+
+2007-07-03  Tommi Komulainen  <tommi.komulainen at nokia.com>
+
 	* src/sapwood-render.c (theme_pixbuf_render): When clamping the mask
 	to clip mask, do not change the area to paint.
 

Modified: projects/haf/trunk/sapwood/src/sapwood-pixmap.c
===================================================================
--- projects/haf/trunk/sapwood/src/sapwood-pixmap.c	2007-07-03 13:27:50 UTC (rev 12628)
+++ projects/haf/trunk/sapwood/src/sapwood-pixmap.c	2007-07-03 13:38:08 UTC (rev 12629)
@@ -296,138 +296,7 @@
   return TRUE;
 }
 
-static GdkGC *
-get_scratch_gc (GdkDrawable *drawable)
-{
-  static GdkGC *gc[32] = { 0, };
-  int           depth;
-
-  depth = gdk_drawable_get_depth (drawable);
-  if (!gc[depth])
-    {
-      GdkGCValues gc_values;
-
-      gc_values.fill = GDK_TILED;
-      gc[depth] = gdk_gc_new_with_values (drawable, &gc_values, GDK_GC_FILL);
-    }
-  return gc[depth];
-}
-
-/* Scale the rectangle (src_x, src_y, src_width, src_height)
- * onto the rectangle (dest_x, dest_y, dest_width, dest_height)
- * of the destination, clip by clip_rect and render
- */
 void
-sapwood_pixmap_render (SapwoodPixmap *self,
-		      GdkWindow    *window,
-		      GdkBitmap    *mask,
-		      GdkRectangle *clip_rect,
-		      gint          src_x,
-		      gint          src_y,
-		      gint          src_width,
-		      gint          src_height,
-		      gint          dest_x,
-		      gint          dest_y,
-		      gint          dest_width,
-		      gint          dest_height)
-{
-  GdkPixmap    *pixmap;
-  GdkBitmap    *pixmask;
-  int           i, j;
-  GdkRectangle  rect;
-  GdkBitmap    *tmp_mask;
-  int           mask_x, mask_y;
-  GdkGC        *tmp_gc;
-
-  if (dest_width <= 0 || dest_height <= 0)
-    return;
-
-  rect.x = dest_x;
-  rect.y = dest_y;
-  rect.width = dest_width;
-  rect.height = dest_height;
-
-  /* FIXME: Because we use the mask to shape windows, we don't use
-   * clip_rect to clip what we draw to the mask, only to clip
-   * what we actually draw. But this leads to the horrible ineffiency
-   * of scale the whole image to get a little bit of it.
-   */
-  if (!mask && clip_rect)
-    {
-      if (!gdk_rectangle_intersect (clip_rect, &rect, &rect))
-	return;
-    }
-
-  if (src_y == 0 && src_height == self->height)
-    i = 1;
-  else if (src_y == self->border_top)
-    i = 1;
-  else if (src_y == 0)
-    i = 0;
-  else
-    i = 2;
-
-  if (src_x == 0 && src_width == self->width)
-    j = 1;
-  else if (src_x == self->border_left)
-    j = 1;
-  else if (src_x == 0)
-    j = 0;
-  else
-    j = 2;
-
-  pixmap  = self->pixmap[i][j];
-  pixmask = self->pixmask[i][j];
-
-  /* if we don't have the pixmap it's an error in gtkrc and the pixmap server
-   * has already complained about it, no need to flood the console
-   */
-  if (!pixmap)
-    return;
-
-  if (mask)
-    {
-      tmp_mask = mask;
-      mask_x = dest_x;
-      mask_y = dest_y;
-    }
-  else
-    {
-      tmp_mask = gdk_pixmap_new (NULL, dest_width, dest_height, 1);
-      mask_x = 0;
-      mask_y = 0;
-    }
-
-  /* tile mask */
-  tmp_gc = get_scratch_gc (tmp_mask);
-  if (pixmask)
-    {
-      gdk_gc_set_fill (tmp_gc, GDK_TILED);
-      gdk_gc_set_ts_origin (tmp_gc, mask_x, mask_y);
-      gdk_gc_set_tile (tmp_gc, pixmask);
-      gdk_draw_rectangle (tmp_mask, tmp_gc, TRUE, mask_x, mask_y, dest_width, dest_height);
-    }
-  else
-    {
-      GdkColor tmp_fg = { 1, 0, 0, 0 };
-      gdk_gc_set_fill (tmp_gc, GDK_SOLID);
-      gdk_gc_set_foreground (tmp_gc, &tmp_fg);
-      gdk_draw_rectangle (tmp_mask, tmp_gc, TRUE, mask_x, mask_y, dest_width, dest_height);
-    }
-
-  /* tile pixmap, use generated mask */
-  tmp_gc = get_scratch_gc (window);
-  gdk_gc_set_ts_origin (tmp_gc, dest_x, dest_y);
-  gdk_gc_set_tile (tmp_gc, pixmap);
-  gdk_gc_set_clip_mask (tmp_gc, tmp_mask);
-  gdk_gc_set_clip_origin (tmp_gc, dest_x - mask_x, dest_y - mask_y);
-  gdk_draw_rectangle (window, tmp_gc, TRUE, rect.x, rect.y, rect.width, rect.height);
-
-  if (tmp_mask != mask)
-    g_object_unref (tmp_mask);
-}
-
-void
 sapwood_pixmap_get_pixmap (SapwoodPixmap *self, gint x, gint y,
 			   GdkPixmap **pixmap, GdkBitmap **pixmask)
 {

Modified: projects/haf/trunk/sapwood/src/sapwood-pixmap.h
===================================================================
--- projects/haf/trunk/sapwood/src/sapwood-pixmap.h	2007-07-03 13:27:50 UTC (rev 12628)
+++ projects/haf/trunk/sapwood/src/sapwood-pixmap.h	2007-07-03 13:38:08 UTC (rev 12629)
@@ -60,19 +60,6 @@
 				       GdkPixmap    **ret_pixmap,
 				       GdkBitmap    **ret_pixmask) G_GNUC_INTERNAL;
 
-void      sapwood_pixmap_render       (SapwoodPixmap *self,
-				      GdkWindow    *window,
-				      GdkBitmap    *mask,
-				      GdkRectangle *clip_rect,
-				      gint          src_x,
-				      gint          src_y,
-				      gint          src_width,
-				      gint          src_height,
-				      gint          dest_x,
-				      gint          dest_y,
-				      gint          dest_width,
-				      gint          dest_height) G_GNUC_INTERNAL;
-
 void      sapwood_pixmap_render_rects (SapwoodPixmap *self,
 				      GdkDrawable  *draw,
 				      gint          draw_x,

Modified: projects/haf/trunk/sapwood/src/sapwood-render.c
===================================================================
--- projects/haf/trunk/sapwood/src/sapwood-render.c	2007-07-03 13:27:50 UTC (rev 12628)
+++ projects/haf/trunk/sapwood/src/sapwood-render.c	2007-07-03 13:38:08 UTC (rev 12629)
@@ -248,6 +248,7 @@
 		     gint          height)
 {
   gint dest_x[4], dest_y[4];
+  SapwoodPixmap *pixmap;
   gint pixbuf_width;
   gint pixbuf_height;
   SapwoodRect rect[9];
@@ -262,10 +263,10 @@
   if (!theme_pixbuf_get_geometry (theme_pb, &pixbuf_width, &pixbuf_height))
     return FALSE;
 
+  pixmap = theme_pixbuf_get_pixmap (theme_pb);
+
   if (theme_pb->stretch)
     {
-      SapwoodPixmap *pixmap;
-
       dest_x[0] = x;
       dest_x[1] = x + theme_pb->border_left;
       dest_x[2] = x + width - theme_pb->border_right;
@@ -279,8 +280,6 @@
       if (component_mask & COMPONENT_ALL)
 	component_mask = (COMPONENT_ALL - 1) & ~component_mask;
 
-      pixmap = theme_pixbuf_get_pixmap (theme_pb);
-
 #define RENDER_COMPONENT(X,Y) do {			           \
     sapwood_pixmap_get_pixmap (pixmap, X, Y, &rect[n_rect].pixmap, \
 			       &rect[n_rect].pixmask);	           \
@@ -363,22 +362,29 @@
 	  mask_required = TRUE;
 	}
 
-      sapwood_pixmap_render_rects (theme_pixbuf_get_pixmap (theme_pb),
-				  window, x, y,
-				  mask, mask_x, mask_y, mask_required,
-				  clip_rect, n_rect, rect);
+      sapwood_pixmap_render_rects (pixmap,
+                                   window, x, y,
+                                   mask, mask_x, mask_y, mask_required,
+                                   clip_rect, n_rect, rect);
 
       g_object_unref (mask);
     }
   else if (center)
     {
-	  x += (width - pixbuf_width) / 2;
-	  y += (height - pixbuf_height) / 2;
+      x += (width - pixbuf_width) / 2;
+      y += (height - pixbuf_height) / 2;
 
-	  sapwood_pixmap_render (theme_pixbuf_get_pixmap (theme_pb),
-				window, mask, clip_rect,
-				0, 0, pixbuf_width, pixbuf_height,
-				x, y, pixbuf_width, pixbuf_height);
+      sapwood_pixmap_get_pixmap (pixmap, 1, 1,
+                                 &rect[0].pixmap, &rect[0].pixmask);
+      rect[0].dest.x = x;
+      rect[0].dest.y = y;
+      rect[0].dest.width = pixbuf_width;
+      rect[0].dest.height = pixbuf_height;
+
+      sapwood_pixmap_render_rects (pixmap,
+                                   window, x, y,
+                                   mask, x, y, FALSE,
+                                   clip_rect, 1, rect);
     }
   else /* tile? */
     {


More information about the maemo-commits mailing list