Author: miguel
Date: 2007-06-07 01:31:30 -0400 (Thu, 07 Jun 2007)
New Revision: 78819

Modified:
   trunk/moon/src/demo.cpp
   trunk/moon/src/runtime.cpp
   trunk/moon/src/runtime.h
Log:
So it seems that using a Cairo xlib surface was reported as slow
by Rolf on his machine, added a -fps option to start collecting
data, I will restore the old gdk-pixbuf based copy code as well
and see if that helps



Modified: trunk/moon/src/demo.cpp
===================================================================
--- trunk/moon/src/demo.cpp     2007-06-07 04:49:50 UTC (rev 78818)
+++ trunk/moon/src/demo.cpp     2007-06-07 05:31:30 UTC (rev 78819)
@@ -6,7 +6,7 @@
 #include <glib.h>
 #include <stdlib.h>
 #include <unistd.h>
-
+#include <sys/time.h>
 #include "runtime.h"
 #include "transform.h"
 #include "shape.h"
@@ -19,7 +19,49 @@
 static ScaleTransform *s_trans;
 static TranslateTransform *t_trans;
 
+static int do_fps = FALSE;
+static uint64_t last_time;
+
+static GtkWidget *w;
+
+static int64_t
+gettime ()
+{
+    struct timeval tv;
+
+    gettimeofday (&tv, NULL);
+
+    return (int64_t) tv.tv_sec * 1000000 + tv.tv_usec;
+}
+
 static gboolean
+my_expose_event (GtkWidget *widget, GdkEventExpose *event, gpointer data)
+{
+}
+
+static gboolean
+invalidator (gpointer data)
+{
+       Surface *s = (Surface *) data;
+
+       gtk_widget_queue_draw (s->drawing_area);
+
+       int64_t now = gettime ();
+
+       int64_t diff = now - last_time;
+       if ((now - last_time) > 1000000){
+               last_time = now;
+               char *res = g_strdup_printf ("%d fps", s->frames);
+
+               gtk_window_set_title (GTK_WINDOW (w), res);
+               g_free (res);
+               s->frames = 0;
+       }
+
+       return TRUE;
+}
+
+static gboolean
 animate (gpointer data)
 {
        rotate_transform_set_angle (v_trans,
@@ -52,9 +94,10 @@
 int
 main (int argc, char *argv [])
 {
-       GtkWidget *w, *w2, *box, *button;
+       GtkWidget *w2, *box, *button;
        cairo_matrix_t trans;
        double dash = 3.5;
+       char *file = NULL;
 
        gtk_init (&argc, &argv);
        g_thread_init (NULL);
@@ -66,11 +109,20 @@
        Surface *t = surface_new (600, 600);
        gtk_container_add (GTK_CONTAINER(w), t->drawing_area);
                
+       for (int i = 1; i < argc; i++){
+               if (strcmp (argv [i], "-h") == 0){
+                       printf ("usage is: demo [-fps] [file.xaml]\n");
+                       return 0;
+               } else if (strcmp (argv [i], "-fps")== 0){
+                       do_fps = TRUE;
+               }else
+                       file = argv [i];
+       }
 
-       if (argc == 2){
-               gtk_window_set_title (GTK_WINDOW (w), argv [1]);
+       if (file){
+               gtk_window_set_title (GTK_WINDOW (w), file);
 
-               UIElement *e = xaml_create_from_file (argv [1]);
+               UIElement *e = xaml_create_from_file (file);
                if (e == NULL){
                        printf ("Was not able to load the file\n");
                }
@@ -131,7 +183,7 @@
                panel_child_add (canvas, r);
                
 #ifdef VIDEO_DEMO
-               //UIElement *v2 = video_new 
("file:///tmp/Countdown-Colbert-BestNailings.wmv", 100, 100);
+               //UIElement *v2 = video_new 
("file:///tmp/Countdown-Colbert-BestNailings.wmv");
                //UIElement *v2 = video_new ("file:///tmp/red.wmv", 100, 100);
                UIElement *v2 = video_new 
("file:///tmp/BoxerSmacksdownInhoffe.wmv");
                v2->SetValue (Canvas::LeftProperty, Value (100.0));
@@ -141,6 +193,11 @@
 #endif
                gtk_timeout_add (60, animate, NULL);
        }               
+       if (do_fps){
+               t->frames = 0;
+               last_time = gettime ();
+               gtk_idle_add (invalidator, t);
+       }
        gtk_widget_set_usize (w, 600, 400);
        gtk_widget_show_all (w);
        gtk_main ();

Modified: trunk/moon/src/runtime.cpp
===================================================================
--- trunk/moon/src/runtime.cpp  2007-06-07 04:49:50 UTC (rev 78818)
+++ trunk/moon/src/runtime.cpp  2007-06-07 05:31:30 UTC (rev 78819)
@@ -495,6 +495,8 @@
 void 
 surface_destroy (Surface *s)
 {
+       base_unref (s->toplevel);
+
        cairo_destroy (s->cairo_buffer);
        if (s->cairo_xlib)
                cairo_destroy (s->cairo_xlib);
@@ -506,6 +508,8 @@
        if (s->xlib_surface)
                cairo_surface_destroy (s->xlib_surface);
 
+       gtk_widget_destroy (s->drawing_area);
+
        // TODO: add everything
        delete s;
 }
@@ -551,6 +555,8 @@
 {
        Surface *s = (Surface *) data;
 
+       s->frames++;
+
        if (event->area.x > s->width || event->area.y > s->height)
                return TRUE;
 

Modified: trunk/moon/src/runtime.h
===================================================================
--- trunk/moon/src/runtime.h    2007-06-07 04:49:50 UTC (rev 78818)
+++ trunk/moon/src/runtime.h    2007-06-07 05:31:30 UTC (rev 78819)
@@ -603,14 +603,14 @@
 typedef struct _SurfacePrivate SurfacePrivate;
 
 //
-// We probably should make the Surface not derive from Canvas, but for now
-// it will do.
+// Surface:
 //
 class Surface {
  public:
        Surface () : width (0), height (0), buffer (0), 
                cairo_buffer_surface (NULL), cairo_buffer(NULL),
                xlib_surface(NULL), cairo_xlib(NULL), pixmap(NULL),
+               using_cairo_xlib_surface(0), pixbuf(NULL),
                cairo (NULL) {}
        
        int width, height;
@@ -618,6 +618,11 @@
        // The data lives here
        unsigned char *buffer;
 
+       // The above buffer, as a pixbuf, for the software mode
+       GdkPixbuf *pixbuf;
+       
+       bool using_cairo_xlib_surface;
+       
        cairo_surface_t *cairo_buffer_surface;
        cairo_t         *cairo_buffer;
        cairo_surface_t *xlib_surface;
@@ -638,6 +643,8 @@
 
        // This currently can only be a canvas.
        UIElement *toplevel;
+
+       int frames;
 };
 
 Surface *surface_new       (int width, int height);

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to