Attempt to minimize redraws when not in "animation" mode.
authorDerek Foreman <foremande@gmail.com>
Fri, 25 Jun 2010 21:19:45 +0000 (17:19 -0400)
committerDana Jansens <danakj@orodu.net>
Sat, 26 Jun 2010 23:30:52 +0000 (01:30 +0200)
Note: this code is incorrect.  Some events seem to be delayed.

openbox/composite.c
openbox/composite.h
openbox/event.c

index 7efe0b3b8ca3cc34f39e313f992e330d8feb251e..395fe55e466c2c871a0b324ce5e68026ed8407e2 100644 (file)
@@ -64,6 +64,7 @@ static GLXContext composite_ctx = NULL;
 static ObCompositeFBConfig pixmap_config[MAX_DEPTH + 1]; /* depth is index */
 static guint composite_idle_source = 0;
 static gboolean need_redraw = FALSE;
+static gboolean animating = FALSE;
 static Window composite_support_win = None;
 #ifdef DEBUG
 static gboolean composite_started = FALSE;
@@ -151,6 +152,11 @@ static void get_best_fbcon(GLXFBConfig *in, int count, int depth,
     out->tf = rgba ? GLX_TEXTURE_FORMAT_RGBA_EXT : GLX_TEXTURE_FORMAT_RGB_EXT;
 }
 
+void composite_dirty(void)
+{
+    need_redraw = 1;
+}
+
 static gboolean composite_annex(void)
 {
     gchar *astr;
@@ -427,11 +433,12 @@ static gboolean composite(gpointer data)
     struct timeval start, end, dif;
     GList *it;
     ObWindow *win;
-    ObClient *client = NULL;
+    ObClient *client;
 
     if (!composite_enabled()) return FALSE;
 
-/*    if (!need_redraw) return FALSE; */
+    if (!animating && !need_redraw)
+        return animating;
 
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
@@ -450,7 +457,7 @@ static gboolean composite(gpointer data)
             client = WINDOW_AS_CLIENT(win);
             if (!client->frame->visible)
                 continue;
-        }
+        } else client = NULL;
 
         d = window_depth(win);
 
@@ -638,8 +645,8 @@ static gboolean composite(gpointer data)
     }
 #endif
 
-    need_redraw = 0;
-    return TRUE;
+    need_redraw = FALSE;
+    return animating;
 }
 
 static void composite_window_redir(ObWindow *w)
@@ -674,8 +681,8 @@ void composite_window_setup(ObWindow *w)
 #endif
 
     obt_display_ignore_errors(TRUE);
-    w->damage = XDamageCreate(obt_display, window_top(w),
-                              XDamageReportNonEmpty);
+    w->damage = XDamageCreate(obt_display, window_redir(w),
+                              XDamageReportRawRectangles);
     obt_display_ignore_errors(FALSE);
     glGenTextures(1, &w->texture);
 
@@ -723,6 +730,7 @@ void composite_disable        (void)          {}
 void composite_window_setup   (ObWindow *w)   {}
 void composite_window_cleanup (ObWindow *w)   {}
 void composite_window_invalid (ObWindow *w)   {}
+void composite_dirty          (void)          {}
 
 void composite_enable(void)
 {
index 6e159828413b9a76e4265296026990a1c06a444c..b61a7b1abccb54fceb17aa23d3b4e2aaf1fa3966 100644 (file)
@@ -38,6 +38,9 @@ gboolean composite_enable(void);
 /*! Turn composite off */
 void composite_disable(void);
 
+/*! Flag need for a redraw */
+void composite_dirty(void);
+
 /*! Called when the screen changes its size */
 void composite_resize(void);
 
index 01653b0dc38d9ba8caf926422b70847da0c87684..e4f99d66db2a741d5261c3d40f52bd04dc2392aa 100644 (file)
@@ -231,6 +231,13 @@ static Window event_get_window(XEvent *e)
         {
             window = None;
         } else
+#endif
+#ifdef USE_COMPOSITING
+        if (e->type == obt_display_extension_damage_basep + XDamageNotify)
+        {
+            XDamageNotifyEvent *d = (XDamageNotifyEvent *)e;
+            window = d->drawable;
+        } else
 #endif
             window = e->xany.window;
     }
@@ -1757,6 +1764,7 @@ static gboolean event_handle_window(ObWindow *wi, XEvent *e)
 
     switch (e->type) {
     case ConfigureNotify:
+        composite_dirty();
         if (e->xconfigure.send_event) break;
 
         if (e->xconfigure.window == window_redir(wi)) {
@@ -1805,6 +1813,7 @@ static gboolean event_handle_window(ObWindow *wi, XEvent *e)
         break;
 
     case MapNotify:
+        composite_dirty();
         if (e->xmap.window == window_redir(wi)) {
             wi->mapped = TRUE;
             pixchange = TRUE;
@@ -1812,24 +1821,33 @@ static gboolean event_handle_window(ObWindow *wi, XEvent *e)
         }
         break;
     case UnmapNotify:
+        composite_dirty();
         if (e->xunmap.window == window_top(wi)) {
             wi->mapped = FALSE;
             used = TRUE;
         }
         break;
     default:
-#ifdef SHAPE
 #ifdef USE_COMPOSITING
+#ifdef SHAPE
         if (obt_display_extension_shape &&
             e->type == obt_display_extension_shape_basep + ShapeNotify)
         {
             XShapeEvent *s = (XShapeEvent*)e;
+            composite_dirty();
             if (s->window == window_redir(wi) && s->kind == ShapeBounding) {
                 window_adjust_redir_shape(wi);
                 used = FALSE; /* let other people get this event also */
             }
         }
 #endif
+        if (obt_display_extension_damage &&
+            e->type == obt_display_extension_damage_basep + XDamageNotify)
+        {
+            XDamageNotifyEvent *ev = (XDamageNotifyEvent *)e;
+            composite_dirty();
+            used = TRUE;
+        }
 #endif
     }
     if (pixchange)