[xiph-commits] r17906 - trunk/planarity

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Wed Mar 23 02:33:07 PDT 2011


Author: xiphmont
Date: 2011-03-23 02:33:07 -0700 (Wed, 23 Mar 2011)
New Revision: 17906

Modified:
   trunk/planarity/gameboard.c
   trunk/planarity/gameboard.h
   trunk/planarity/gameboard_draw_curtain.c
   trunk/planarity/gameboard_draw_main.c
   trunk/planarity/gameboard_draw_vertex.c
   trunk/planarity/gameboard_logic_button.c
   trunk/planarity/levelstate.c
   trunk/planarity/version.h
Log:
Numerous cleanups to keep gPlanarity up to date.

A change in GDK/cairo caching behavior (since documented, but not originally part of the API) caused cached gdk_cairo surfaces to 
become invalid between expose events.  The cairo_t must be regenerated for each event.  This fixes the behavior on some machines 
where the main window pops but is blank until it is resized.

Minor include cleanups.



Modified: trunk/planarity/gameboard.c
===================================================================
--- trunk/planarity/gameboard.c	2011-03-23 08:17:13 UTC (rev 17905)
+++ trunk/planarity/gameboard.c	2011-03-23 09:33:07 UTC (rev 17906)
@@ -104,6 +104,7 @@
   Gameboard *g = GAMEBOARD (widget);
   GdkWindowAttr attributes;
   gint      attributes_mask;
+  cairo_t *wc;
 
   GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
 
@@ -132,30 +133,31 @@
   gdk_window_set_user_data (widget->window, widget);
   gtk_widget_set_double_buffered (widget, FALSE);
 
-  g->wc = gdk_cairo_create(widget->window);
+  wc = gdk_cairo_create(widget->window);
 
   g->forescore = 
-    cairo_surface_create_similar (cairo_get_target (g->wc),
+    cairo_surface_create_similar (cairo_get_target (wc),
 				  CAIRO_CONTENT_COLOR_ALPHA,
 				  widget->allocation.width,
 				  SCOREHEIGHT);
 
   g->forebutton = 
-    cairo_surface_create_similar (cairo_get_target (g->wc),
+    cairo_surface_create_similar (cairo_get_target (wc),
 				  CAIRO_CONTENT_COLOR_ALPHA,
 				  widget->allocation.width,
 				  SCOREHEIGHT);
 
   g->background = 
-    cairo_surface_create_similar (cairo_get_target (g->wc),
+    cairo_surface_create_similar (cairo_get_target (wc),
 				  CAIRO_CONTENT_COLOR,
 				  widget->allocation.width,
 				  widget->allocation.height);
   g->foreground = 
-    cairo_surface_create_similar (cairo_get_target (g->wc),
+    cairo_surface_create_similar (cairo_get_target (wc),
 				  CAIRO_CONTENT_COLOR,
 				  widget->allocation.width,
 				  widget->allocation.height);  
+  cairo_destroy(wc);
 
   g->vertex = cache_vertex(g);
   g->vertex_lit = cache_vertex_lit(g);
@@ -174,6 +176,7 @@
 void gameboard_size_allocate (GtkWidget     *widget,
 			      GtkAllocation *allocation){
   Gameboard *g = GAMEBOARD (widget);
+  cairo_t *wc;
 
   if (GTK_WIDGET_REALIZED (widget)){
 
@@ -197,8 +200,6 @@
     if(widget->allocation.width == allocation->width &&
        widget->allocation.height == allocation->height) return;
 
-    if(g->wc)
-      cairo_destroy(g->wc);
     if (g->forescore)
       cairo_surface_destroy(g->forescore);
     if (g->forebutton)
@@ -216,29 +217,30 @@
     gdk_window_move_resize (widget->window, allocation->x, allocation->y, 
 			    allocation->width, allocation->height);
     
-    g->wc = gdk_cairo_create(widget->window);
+    wc = gdk_cairo_create(widget->window);
 
     g->background = 
-      cairo_surface_create_similar (cairo_get_target (g->wc),
+      cairo_surface_create_similar (cairo_get_target (wc),
 				    CAIRO_CONTENT_COLOR, // don't need alpha
 				    allocation->width,
 				    allocation->height);
     g->forescore = 
-      cairo_surface_create_similar (cairo_get_target (g->wc),
+      cairo_surface_create_similar (cairo_get_target (wc),
 				    CAIRO_CONTENT_COLOR_ALPHA,
 				    allocation->width,
 				    SCOREHEIGHT);
     g->forebutton = 
-      cairo_surface_create_similar (cairo_get_target (g->wc),
+      cairo_surface_create_similar (cairo_get_target (wc),
 				    CAIRO_CONTENT_COLOR_ALPHA,
 				    allocation->width,
 				    SCOREHEIGHT);
 
     g->foreground = 
-      cairo_surface_create_similar (cairo_get_target (g->wc),
+      cairo_surface_create_similar (cairo_get_target (wc),
 				    CAIRO_CONTENT_COLOR, // don't need alpha
 				    allocation->width,
 				    allocation->height);  
+    cairo_destroy(wc);
 
     cache_curtain(g);
 

Modified: trunk/planarity/gameboard.h
===================================================================
--- trunk/planarity/gameboard.h	2011-03-23 08:17:13 UTC (rev 17905)
+++ trunk/planarity/gameboard.h	2011-03-23 09:33:07 UTC (rev 17906)
@@ -167,7 +167,6 @@
   int pushed_curtain;
   void (*redraw_callback)(Gameboard *g);
 
-  cairo_t         *wc;
   cairo_surface_t *vertex;
   cairo_surface_t *vertex_lit;
   cairo_surface_t *vertex_grabbed;

Modified: trunk/planarity/gameboard_draw_curtain.c
===================================================================
--- trunk/planarity/gameboard_draw_curtain.c	2011-03-23 08:17:13 UTC (rev 17905)
+++ trunk/planarity/gameboard_draw_curtain.c	2011-03-23 09:33:07 UTC (rev 17906)
@@ -41,12 +41,14 @@
 #define CW 4
 void cache_curtain(Gameboard *g){
   int x,y;
+  cairo_t *wc = gdk_cairo_create(g->w.window);
   cairo_t *c;
   g->curtains=
-    cairo_surface_create_similar (cairo_get_target (g->wc),
+    cairo_surface_create_similar (cairo_get_target (wc),
 				  CAIRO_CONTENT_COLOR_ALPHA,
 				  CW,CW);
-  
+  cairo_destroy(wc);
+
   c = cairo_create(g->curtains);
   cairo_save(c);
   cairo_set_operator(c,CAIRO_OPERATOR_CLEAR);

Modified: trunk/planarity/gameboard_draw_main.c
===================================================================
--- trunk/planarity/gameboard_draw_main.c	2011-03-23 08:17:13 UTC (rev 17905)
+++ trunk/planarity/gameboard_draw_main.c	2011-03-23 09:33:07 UTC (rev 17906)
@@ -347,9 +347,13 @@
   cairo_destroy(c);
   
   // blit to window
-  cairo_set_source_surface(g->wc,g->foreground,0,0);
-  cairo_rectangle(g->wc,x,y,w,h);
-  cairo_fill(g->wc);
+  {
+    cairo_t *wc = gdk_cairo_create(g->w.window);
+    cairo_set_source_surface(wc,g->foreground,0,0);
+    cairo_rectangle(wc,x,y,w,h);
+    cairo_fill(wc);
+    cairo_destroy(wc);
+  }
 
   if(g->delayed_background)update_full(g);
   g->first_expose=1;

Modified: trunk/planarity/gameboard_draw_vertex.c
===================================================================
--- trunk/planarity/gameboard_draw_vertex.c	2011-03-23 08:17:13 UTC (rev 17905)
+++ trunk/planarity/gameboard_draw_vertex.c	2011-03-23 09:33:07 UTC (rev 17906)
@@ -57,13 +57,15 @@
 
 // normal unlit vertex
 cairo_surface_t *cache_vertex(Gameboard *g){
+  cairo_t *wc = gdk_cairo_create(g->w.window);
   cairo_surface_t *ret=
-    cairo_surface_create_similar (cairo_get_target (g->wc),
+    cairo_surface_create_similar (cairo_get_target (wc),
 				  CAIRO_CONTENT_COLOR_ALPHA,
 				  (V_RADIUS+V_LINE)*2,
 				  (V_RADIUS+V_LINE)*2);
   cairo_t *c = cairo_create(ret);
-  
+  cairo_destroy(wc);
+
   cairo_set_line_width(c,V_LINE);
   cairo_arc(c,V_RADIUS+V_LINE,V_RADIUS+V_LINE,V_RADIUS,0,2*M_PI);
   cairo_set_source_rgb(c,V_FILL_IDLE_COLOR);
@@ -77,13 +79,15 @@
 
 // selected vertex
 cairo_surface_t *cache_vertex_sel(Gameboard *g){
+  cairo_t *wc = gdk_cairo_create(g->w.window);
   cairo_surface_t *ret=
-    cairo_surface_create_similar (cairo_get_target (g->wc),
+    cairo_surface_create_similar (cairo_get_target (wc),
 				  CAIRO_CONTENT_COLOR_ALPHA,
 				  (V_RADIUS+V_LINE)*2,
 				  (V_RADIUS+V_LINE)*2);
   cairo_t *c = cairo_create(ret);
-  
+  cairo_destroy(wc);
+
   cairo_set_line_width(c,V_LINE);
   cairo_arc(c,V_RADIUS+V_LINE,V_RADIUS+V_LINE,V_RADIUS,0,2*M_PI);
   cairo_set_source_rgb(c,V_FILL_LIT_COLOR);
@@ -100,13 +104,15 @@
 
 // grabbed vertex
 cairo_surface_t *cache_vertex_grabbed(Gameboard *g){
+  cairo_t *wc = gdk_cairo_create(g->w.window);
   cairo_surface_t *ret=
-    cairo_surface_create_similar (cairo_get_target (g->wc),
+    cairo_surface_create_similar (cairo_get_target (wc),
 				  CAIRO_CONTENT_COLOR_ALPHA,
 				  (V_RADIUS+V_LINE)*2,
 				  (V_RADIUS+V_LINE)*2);
   cairo_t *c = cairo_create(ret);
-  
+  cairo_destroy(wc);
+
   cairo_set_line_width(c,V_LINE);
   cairo_arc(c,V_RADIUS+V_LINE,V_RADIUS+V_LINE,V_RADIUS,0,2*M_PI);
   cairo_set_source_rgb(c,V_FILL_LIT_COLOR);
@@ -123,13 +129,15 @@
 
 // vertex under mouse rollover
 cairo_surface_t *cache_vertex_lit(Gameboard *g){
+  cairo_t *wc = gdk_cairo_create(g->w.window);
   cairo_surface_t *ret=
-    cairo_surface_create_similar (cairo_get_target (g->wc),
+    cairo_surface_create_similar (cairo_get_target (wc),
 				  CAIRO_CONTENT_COLOR_ALPHA,
 				  (V_RADIUS+V_LINE)*2,
 				  (V_RADIUS+V_LINE)*2);
   cairo_t *c = cairo_create(ret);
-  
+  cairo_destroy(wc);
+
   cairo_set_line_width(c,V_LINE);
   cairo_arc(c,V_RADIUS+V_LINE,V_RADIUS+V_LINE,V_RADIUS,0,2*M_PI);
   cairo_set_source_rgb(c,V_FILL_LIT_COLOR);
@@ -143,13 +151,15 @@
 
 // verticies attached to grabbed vertex
 cairo_surface_t *cache_vertex_attached(Gameboard *g){
+  cairo_t *wc = gdk_cairo_create(g->w.window);
   cairo_surface_t *ret=
-    cairo_surface_create_similar (cairo_get_target (g->wc),
+    cairo_surface_create_similar (cairo_get_target (wc),
 				  CAIRO_CONTENT_COLOR_ALPHA,
 				  (V_RADIUS+V_LINE)*2,
 				  (V_RADIUS+V_LINE)*2);
   cairo_t *c = cairo_create(ret);
-  
+  cairo_destroy(wc);
+
   cairo_set_line_width(c,V_LINE);
   cairo_arc(c,V_RADIUS+V_LINE,V_RADIUS+V_LINE,V_RADIUS,0,2*M_PI);
   cairo_set_source_rgb(c,V_FILL_ADJ_COLOR);
@@ -163,13 +173,15 @@
 
 // vertex being dragged in a group
 cairo_surface_t *cache_vertex_ghost(Gameboard *g){
+  cairo_t *wc = gdk_cairo_create(g->w.window);
   cairo_surface_t *ret=
-    cairo_surface_create_similar (cairo_get_target (g->wc),
+    cairo_surface_create_similar (cairo_get_target (wc),
 				  CAIRO_CONTENT_COLOR_ALPHA,
 				  (V_RADIUS+V_LINE)*2,
 				  (V_RADIUS+V_LINE)*2);
   cairo_t *c = cairo_create(ret);
-  
+  cairo_destroy (wc);
+
   cairo_set_line_width(c,V_LINE);
   cairo_arc(c,V_RADIUS+V_LINE,V_RADIUS+V_LINE,V_RADIUS,0,2*M_PI);
   cairo_set_source_rgb(c,V_FILL_LIT_COLOR);

Modified: trunk/planarity/gameboard_logic_button.c
===================================================================
--- trunk/planarity/gameboard_logic_button.c	2011-03-23 08:17:13 UTC (rev 17905)
+++ trunk/planarity/gameboard_logic_button.c	2011-03-23 09:33:07 UTC (rev 17906)
@@ -170,13 +170,14 @@
 						  double y),
 				     double pR,double pG,double pB,double pA,
 				     double fR,double fG,double fB,double fA){
+  cairo_t *wc = gdk_cairo_create(g->w.window);
   cairo_surface_t *ret = 
-    cairo_surface_create_similar (cairo_get_target (g->wc),
+    cairo_surface_create_similar (cairo_get_target (wc),
 				  CAIRO_CONTENT_COLOR_ALPHA,
 				  BUTTON_RADIUS*2+1,
 				  BUTTON_RADIUS*2+1);
-  
   cairo_t *c = cairo_create(ret);
+  cairo_destroy (wc);
 
   cairo_save(c);
   cairo_set_operator(c,CAIRO_OPERATOR_CLEAR);

Modified: trunk/planarity/levelstate.c
===================================================================
--- trunk/planarity/levelstate.c	2011-03-23 08:17:13 UTC (rev 17905)
+++ trunk/planarity/levelstate.c	2011-03-23 09:33:07 UTC (rev 17906)
@@ -31,6 +31,7 @@
 #include <string.h>
 #include <errno.h>
 #include "graph.h"
+#include "timer.h"
 #include "levelstate.h"
 #include "gameboard.h"
 #include "dialog_pause.h"
@@ -170,15 +171,15 @@
 	    curr->gm.id,strerror(errno));
     return errno;
   }
-  
-  fprintf(f,"current %d : %s\n",strlen(curr->gm.id),curr->gm.id);
 
+  fprintf(f,"current %d : %s\n",(int)strlen(curr->gm.id),curr->gm.id);
+
   {
     levelstate *l=head;
     while(l){
       fprintf(f,"level %ld %d %d : %s\n",
 	      l->highscore,l->in_progress,
-	      strlen(l->gm.id),l->gm.id);
+	      (int)strlen(l->gm.id),l->gm.id);
       l=l->next;
     }
   }

Modified: trunk/planarity/version.h
===================================================================
--- trunk/planarity/version.h	2011-03-23 08:17:13 UTC (rev 17905)
+++ trunk/planarity/version.h	2011-03-23 09:33:07 UTC (rev 17906)
@@ -1,2 +1,2 @@
 #define VERSION "$Id$ "
-/* DO NOT EDIT: Automated versioning hack [Wed Mar 23 04:15:47 EDT 2011] */
+/* DO NOT EDIT: Automated versioning hack [Wed Mar 23 05:30:26 EDT 2011] */



More information about the commits mailing list