[cairo-commit] 5 commits - boilerplate/cairo-boilerplate-directfb.c src/cairo-directfb-surface.c

Vladimir Vukicevic vladimir at kemper.freedesktop.org
Sat Aug 9 22:10:50 PDT 2008


 boilerplate/cairo-boilerplate-directfb.c |   28 +++++
 src/cairo-directfb-surface.c             |  162 +++++++++++++++++++------------
 2 files changed, 128 insertions(+), 62 deletions(-)

New commits:
commit ac2781ec0820e9352b28335e7d9553926d069ff2
Author: Vladimir Vukicevic <vladimir at pobox.com>
Date:   Sun Aug 10 05:05:28 2008 -0700

    [dfb] fix crashes due to cached glyphs going away during operation

diff --git a/src/cairo-directfb-surface.c b/src/cairo-directfb-surface.c
index a402bd1..ecfc0f4 100644
--- a/src/cairo-directfb-surface.c
+++ b/src/cairo-directfb-surface.c
@@ -1384,21 +1384,29 @@ _directfb_acquire_font_cache (cairo_directfb_surface_t     *surface,
     int                          h         = 8;
     int                          i;
     
+    D_DEBUG_AT (CairoDFB_Font, "%s( %p [%d] )\n", __FUNCTION__, glyphs, num_glyphs );
+
     if (scaled_font->surface_private) {
         cache = scaled_font->surface_private;
         x = cache->x;
         y = cache->y;
     }
-    
+
+    _cairo_cache_freeze( scaled_font->glyphs );
+
     for (i = 0; i < num_glyphs; i++) {
         cairo_scaled_glyph_t  *scaled_glyph;
         cairo_image_surface_t *img;
         
+        D_DEBUG_AT (CairoDFB_Font, "  -> [%2d] = %4lu\n", i, glyphs[i].index );
+
         ret = _cairo_scaled_glyph_lookup (scaled_font, glyphs[i].index,
                                           CAIRO_SCALED_GLYPH_INFO_SURFACE,
                                           &scaled_glyph);
-        if (ret)
+        if (ret) {
+            _cairo_cache_thaw( scaled_font->glyphs );
             return ret;
+        }
         
         img = scaled_glyph->surface;
         switch (img->format) {
@@ -1408,18 +1416,25 @@ _directfb_acquire_font_cache (cairo_directfb_surface_t     *surface,
                 break;
             default:
                 D_DEBUG_AT (CairoDFB_Font,
-                            "Unsupported font format %d!\n", img->format);
+                            "  -> Unsupported font format %d!\n", img->format);
+                _cairo_cache_thaw( scaled_font->glyphs );
                 return CAIRO_INT_STATUS_UNSUPPORTED;
         }
         
         points[n].x = _cairo_lround (glyphs[i].x - img->base.device_transform.x0);
         points[n].y = _cairo_lround (glyphs[i].y - img->base.device_transform.y0);
         
+//        D_DEBUG_AT (CairoDFB_Font, "            (%4d,%4d) [%2d]\n", points[n].x, points[n].y, n );
+
         if (points[n].x >= surface->width  ||
             points[n].y >= surface->height ||
             points[n].x+img->width  <= 0   ||
             points[n].y+img->height <= 0)
-            continue;
+        {
+             D_DEBUG_AT (CairoDFB_Font,
+                         "  -> Unsupported font format %d!\n", img->format);
+             continue;
+        }
         
         if (!scaled_glyph->surface_private) {
             DFBRectangle *rect;
@@ -1441,30 +1456,31 @@ _directfb_acquire_font_cache (cairo_directfb_surface_t     *surface,
             
             /* Remember glyph location */ 
             rect = malloc (sizeof(DFBRectangle));
-            if (!rect)
+            if (!rect) {
+                _cairo_cache_thaw( scaled_font->glyphs );
                 return _cairo_error (CAIRO_STATUS_NO_MEMORY);
+            }
             *rect = rects[n];
             
             scaled_glyph->surface_private = rect;
             chars[num_chars++] = scaled_glyph;
             
-            /*D_DEBUG_AT (CairoDFB_Font, 
-                        "Glyph %lu will be loaded at (%d,%d).\n",
-                        glyphs[i].index, rects[n].x, rects[n].y);*/
+            D_DEBUG_AT (CairoDFB_Font, "  -> loading at %4d,%2d <- rect %p, img %p, entry %p\n",
+                        rects[n].x, rects[n].y, rect, scaled_glyph->surface, scaled_glyph);
         }
         else {
             rects[n] = *((DFBRectangle *)scaled_glyph->surface_private);
             
-            /*D_DEBUG_AT (CairoDFB_Font, 
-                        "Glyph %lu already loaded at (%d,%d).\n",
-                        glyphs[i].index, rects[n].x, rects[n].y);*/
+            D_DEBUG_AT (CairoDFB_Font, "  -> exists at  %4d,%2d\n", rects[n].x, rects[n].y);
         }
             
         n++;
     }
     
-    if (!n)
+    if (!n) {
+        _cairo_cache_thaw( scaled_font->glyphs );
         return CAIRO_INT_STATUS_NOTHING_TO_DO;
+    }
     
     h += y;
     w = MAX (w, 8);
@@ -1477,12 +1493,13 @@ _directfb_acquire_font_cache (cairo_directfb_surface_t     *surface,
             w = MAX (w, cache->width);
             h = MAX (h, cache->height);
             
-            D_DEBUG_AT (CairoDFB_Font,
-                        "Reallocating font cache (%dx%d).\n", w, h);
+            D_DEBUG_AT (CairoDFB_Font, "  -> Reallocating font cache (%dx%d).\n", w, h);
             
             new_cache = _directfb_allocate_font_cache (surface->dfb, w, h);
-            if (!new_cache)
+            if (!new_cache) {
+                _cairo_cache_thaw( scaled_font->glyphs );
                 return _cairo_error (CAIRO_STATUS_NO_MEMORY);
+            }
             
             new_cache->dfbsurface->Blit (new_cache->dfbsurface,
                                          cache->dfbsurface, NULL, 0, 0);
@@ -1492,12 +1509,13 @@ _directfb_acquire_font_cache (cairo_directfb_surface_t     *surface,
         }
     }
     else {
-        D_DEBUG_AT (CairoDFB_Font,
-                    "Allocating font cache (%dx%d).\n", w, h);
+        D_DEBUG_AT (CairoDFB_Font, "  -> Allocating font cache (%dx%d).\n", w, h);
         
         cache = _directfb_allocate_font_cache (surface->dfb, w, h);
-        if (!cache)
+        if (!cache) {
+            _cairo_cache_thaw( scaled_font->glyphs );
             return _cairo_error (CAIRO_STATUS_NO_MEMORY);
+        }
             
         scaled_font->surface_backend = &cairo_directfb_surface_backend;
         scaled_font->surface_private = cache;
@@ -1509,17 +1527,30 @@ _directfb_acquire_font_cache (cairo_directfb_surface_t     *surface,
     
         if (cache->dfbsurface->Lock (cache->dfbsurface, 
                                      DSLF_WRITE, (void *)&data, &pitch))
+        {
+            _cairo_cache_thaw( scaled_font->glyphs );
             return _cairo_error (CAIRO_STATUS_NO_MEMORY);
+        }
             
+        D_DEBUG_AT (CairoDFB_Font, "  => %d chars to load, cache %dx%d\n", num_chars, cache->width, cache->height);
+
         for (i = 0; i < num_chars; i++) {
             cairo_image_surface_t *img  = chars[i]->surface;
             DFBRectangle          *rect = chars[i]->surface_private;
             unsigned char         *dst  = data;
-            unsigned char         *src  = img->data;
+            unsigned char         *src;
             int                    j;
             
+            D_DEBUG_AT (CairoDFB_Font, "  -> loading [%2d] <- rect %p, img %p, entry %p\n", i, rect, img, chars[i]);
+
+            src = img->data;
+
+            D_DEBUG_AT (CairoDFB_Font, "     from %p\n", src);
+
             dst += rect->y * pitch + (_directfb_argb_font ? (rect->x<<2) : rect->x);
                         
+            D_DEBUG_AT (CairoDFB_Font, "     to %4d,%2d (%p)\n", rect->x, rect->y, dst);
+
             if (img->format == CAIRO_FORMAT_A1) {
                 for (h = rect->h; h; h--) {
                     if (_directfb_argb_font) {
@@ -1568,9 +1599,13 @@ _directfb_acquire_font_cache (cairo_directfb_surface_t     *surface,
         cache->dfbsurface->Unlock (cache->dfbsurface);
     }
 
+    _cairo_cache_thaw( scaled_font->glyphs );
+
     cache->x = x;
     cache->y = y;
     
+    D_DEBUG_AT (CairoDFB_Font, "  => cache %d,%d, %p [%d]\n", x, y, cache, n);
+
     *ret_cache = cache;
     *ret_num   = n;
 
commit 7fbda72137d8685718a8e8fe1d3af5b1d377521c
Author: Vladimir Vukicevic <vladimir at pobox.com>
Date:   Sun Aug 10 05:05:27 2008 -0700

    [dfb] optimize DirectFB blits

diff --git a/boilerplate/cairo-boilerplate-directfb.c b/boilerplate/cairo-boilerplate-directfb.c
index 894672d..d6d616b 100644
--- a/boilerplate/cairo-boilerplate-directfb.c
+++ b/boilerplate/cairo-boilerplate-directfb.c
@@ -17,6 +17,11 @@ make check
 #include <stdio.h>
 #include <stdlib.h>
 
+#include <direct/debug.h>
+
+D_DEBUG_DOMAIN( CairoDFB_Boiler, "CairoDFB/Boiler", "Cairo DirectFB Boilerplate" );
+
+
 /* macro for a safe call to DirectFB functions */
 #define DFBCHECK(x...) \
 {                                                                \
@@ -67,6 +72,13 @@ _cairo_boilerplate_directfb_window_create_surface (DFBInfo		*info,
 {
 	DFBWindowDescription desc;
 	int err;
+
+        D_DEBUG_AT( CairoDFB_Boiler, "%s( %p, %s, %dx%d )\n", __FUNCTION__, info,
+                    content == CAIRO_CONTENT_ALPHA       ? "ALPHA" :
+                    content == CAIRO_CONTENT_COLOR       ? "RGB"   :
+                    content == CAIRO_CONTENT_COLOR_ALPHA ? "ARGB"  : "unknown content!",
+                    width, height );
+
 	desc.flags  = ( DWDESC_POSX | DWDESC_POSY |
 			DWDESC_WIDTH | DWDESC_HEIGHT /*| DWDESC_CAPS|DSDESC_PIXELFORMAT*/ );
 	desc.posx   = 0;
@@ -97,7 +109,13 @@ _cairo_boilerplate_directfb_bitmap_create_surface (DFBInfo		*info,
 	int  err;
 	DFBSurfaceDescription  desc;
 
-	desc.flags = DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT;
+        D_DEBUG_AT( CairoDFB_Boiler, "%s( %p, %s, %dx%d )\n", __FUNCTION__, info,
+                    content == CAIRO_CONTENT_ALPHA       ? "ALPHA" :
+                    content == CAIRO_CONTENT_COLOR       ? "RGB"   :
+                    content == CAIRO_CONTENT_COLOR_ALPHA ? "ARGB"  : "unknown content!",
+                    width, height );
+
+        desc.flags = DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT;
 	desc.caps = DSCAPS_NONE;
 	desc.width  = width;
 	desc.height = height;
@@ -135,6 +153,14 @@ _cairo_boilerplate_directfb_create_surface (const char			 *name,
         return NULL;
     }
 
+    D_DEBUG_AT( CairoDFB_Boiler, "%s( '%s', %s, %dx%d, %s )\n", __FUNCTION__, name,
+                content == CAIRO_CONTENT_ALPHA       ? "ALPHA" :
+                content == CAIRO_CONTENT_COLOR       ? "RGB"   :
+                content == CAIRO_CONTENT_COLOR_ALPHA ? "ARGB"  : "unknown content!",
+                width, height,
+                mode == CAIRO_BOILERPLATE_MODE_TEST ? "TEST" :
+                mode == CAIRO_BOILERPLATE_MODE_PERF ? "PERF" : "unknown mode!" );
+
     if (width == 0)
 	width = 1;
     if (height == 0)
diff --git a/src/cairo-directfb-surface.c b/src/cairo-directfb-surface.c
index c20dc83..a402bd1 100644
--- a/src/cairo-directfb-surface.c
+++ b/src/cairo-directfb-surface.c
@@ -63,7 +63,7 @@
 /*
  * CompositeTrapezoids works (without antialiasing).
  */
-#define DFB_COMPOSITE_TRAPEZOIDS 0
+#define DFB_COMPOSITE_TRAPEZOIDS 1
 
 /*
  * ShowGlyphs works fine.
@@ -71,7 +71,11 @@
 #define DFB_SHOW_GLYPHS 1
 
 
-D_DEBUG_DOMAIN (Cairo_DirectFB, "Cairo/DirectFB", "Cairo DirectFB backend");
+D_DEBUG_DOMAIN( CairoDFB_Acquire, "CairoDFB/Acquire", "Cairo DirectFB Acquire" );
+D_DEBUG_DOMAIN( CairoDFB_Clip,    "CairoDFB/Clip",    "Cairo DirectFB Clipping" );
+D_DEBUG_DOMAIN( CairoDFB_Font,    "CairoDFB/Font",    "Cairo DirectFB Font Rendering" );
+D_DEBUG_DOMAIN( CairoDFB_Render,  "CairoDFB/Render",  "Cairo DirectFB Rendering" );
+D_DEBUG_DOMAIN( CairoDFB_Surface, "CairoDFB/Surface", "Cairo DirectFB Surface" );
 
 /*****************************************************************************/
 
@@ -120,160 +124,38 @@ static int _directfb_argb_font = 0;
 
 /*****************************************************************************/
 
-typedef cairo_bool_t (*clipped_draw_func) (cairo_directfb_surface_t *dfs,
-                                           void *closure);
 
-static cairo_bool_t
-_cairo_directfb_run_clipped (cairo_directfb_surface_t *surface,
-                             const DFBRegion *clip,
-                             clipped_draw_func draw_func,
-                             void *draw_closure)
-{
-    cairo_bool_t ok = TRUE;
-
-    if (surface->clips) {
-        int k;
-        for (k = 0; k < surface->n_clips; k++) {
-            DFBRegion reg = surface->clips[k];
-
-            if (clip) {
-                if (reg.x2 < clip->x1 || reg.y2 < clip->y1 ||
-                    reg.x1 > clip->x2 || reg.y1 > clip->y2)
-                    continue;
-                if (reg.x1 < clip->x1)
-                    reg.x1 = clip->x1;
-                if (reg.y1 < clip->y1)
-                    reg.y1 = clip->y1;
-                if (reg.x2 > clip->x2)
-                    reg.x2 = clip->x2;
-                if (reg.y2 > clip->y2)
-                    reg.y2 = clip->y2;
-            }
-
-            surface->dfbsurface->SetClip (surface->dfbsurface, &reg);
-
-            ok = draw_func (surface, draw_closure);
-            if (!ok)
-                goto FAIL;
-        }
-    } else {
-        surface->dfbsurface->SetClip (surface->dfbsurface, clip);
-
-        ok = draw_func (surface, draw_closure);
-    }
-
-FAIL:
-
-    surface->dfbsurface->SetClip (surface->dfbsurface, NULL);
-
-    return ok;
-}
-
-// TextureTriangles
-
-typedef struct {
-    cairo_bool_t tile;
-    IDirectFBSurface *src;
-    DFBRectangle src_rect;
-    DFBRectangle dst_rect;
-} _dfb_blit_op;
-
-static cairo_bool_t
-_dfb_clip_func_blit (cairo_directfb_surface_t *dfs,
-                     void *closure)
-{
-    _dfb_blit_op *op = (_dfb_blit_op*) closure;
-    DFBResult rv;
-
-    if (op->tile) {
-        rv = dfs->dfbsurface->TileBlit (dfs->dfbsurface,
-                                        op->src,
-                                        &op->src_rect,
-                                        op->dst_rect.x,
-                                        op->dst_rect.y);
-    } else if (op->dst_rect.w != op->src_rect.w ||
-               op->dst_rect.h != op->src_rect.h)
-    {
-        rv = dfs->dfbsurface->StretchBlit (dfs->dfbsurface,
-                                           op->src,
-                                           &op->src_rect,
-                                           &op->dst_rect);
-    } else {
-        rv = dfs->dfbsurface->Blit (dfs->dfbsurface,
-                                    op->src,
-                                    &op->src_rect,
-                                    op->dst_rect.x,
-                                    op->dst_rect.y);
-    }
-
-    return (rv == DFB_OK);
-}
-
-typedef struct {
-    IDirectFBSurface *src;
-    int count;
-    const DFBRectangle *src_rects;
-    const DFBPoint *dst_points;
-} _dfb_batch_blit_op;
-
-static cairo_bool_t
-_dfb_clip_func_batch_blit (cairo_directfb_surface_t *dfs,
-                           void *closure)
-{
-    _dfb_batch_blit_op *op = (_dfb_batch_blit_op*) closure;
-    DFBResult rv;
-
-    rv = dfs->dfbsurface->BatchBlit (dfs->dfbsurface,
-                                     op->src,
-                                     op->src_rects,
-                                     op->dst_points,
-                                     op->count);
-
-    return (rv == DFB_OK);
-}
-
-typedef struct {
-    int count;
-    const DFBRectangle *rects;
-} _dfb_fill_rects_op;
-
-static cairo_bool_t
-_dfb_clip_func_fill_rects (cairo_directfb_surface_t *dfs,
-                           void *closure)
-{
-    _dfb_fill_rects_op *op = (_dfb_fill_rects_op*) closure;
-    DFBResult rv;
-
-    rv = dfs->dfbsurface->FillRectangles (dfs->dfbsurface,
-                                          op->rects,
-                                          op->count);
-
-    return (rv == DFB_OK);
-}
-
-typedef struct {
-    IDirectFBSurface *src;
-    const DFBVertex *vertices;
-    const int *indices;
-    int count;
-    DFBTriangleFormation formation;
-} _dfb_texture_triangles_op;
-
-static cairo_bool_t
-_dfb_clip_func_texture_triangles (cairo_directfb_surface_t *dfs,
-                                  void *closure)
-{
-    _dfb_texture_triangles_op *op = (_dfb_texture_triangles_op*) closure;
-    DFBResult rv;
-
-    rv = dfs->dfbsurface->TextureTriangles (dfs->dfbsurface,
-                                            op->src,
-                                            op->vertices,
-                                            op->indices,
-                                            op->count,
-                                            op->formation);
-
-    return (rv == DFB_OK);
+#define RUN_CLIPPED( surface, clip, func ) {\
+    if ((surface)->clips) {\
+        int k;\
+        for (k = 0; k < (surface)->n_clips; k++) {\
+            if (clip) {\
+                DFBRegion  reg = (surface)->clips[k];\
+                DFBRegion *cli = (clip);\
+                if (reg.x2 < cli->x1 || reg.y2 < cli->y1 ||\
+                    reg.x1 > cli->x2 || reg.y1 > cli->y2)\
+                    continue;\
+                if (reg.x1 < cli->x1)\
+                    reg.x1 = cli->x1;\
+                if (reg.y1 < cli->y1)\
+                    reg.y1 = cli->y1;\
+                if (reg.x2 > cli->x2)\
+                    reg.x2 = cli->x2;\
+                if (reg.y2 > cli->y2)\
+                    reg.y2 = cli->y2;\
+                (surface)->dfbsurface->SetClip ((surface)->dfbsurface, &reg);\
+            }\
+            else {\
+                (surface)->dfbsurface->SetClip ((surface)->dfbsurface,\
+                                           &(surface)->clips[k]);\
+            }\
+            func;\
+        }\
+    }\
+    else {\
+        (surface)->dfbsurface->SetClip ((surface)->dfbsurface, clip);\
+        func;\
+    }\
 }
 
 #define TRANSFORM_POINT2X( m, x, y, ret_x, ret_y ) {\
@@ -461,7 +343,7 @@ _directfb_acquire_surface (cairo_directfb_surface_t  *surface,
     cairo_format_t cairo_format;
     void *data;
     int   pitch; 
-        
+
     if (surface->format == (cairo_format_t) -1) {
         DFBSurfaceCapabilities caps;
         
@@ -488,7 +370,7 @@ _directfb_acquire_surface (cairo_directfb_surface_t  *surface,
         
         cairo_format = _cairo_format_from_content (surface->content);
         if (!surface->tmpsurface) {
-            D_DEBUG_AT (Cairo_DirectFB, "Allocating buffer for surface %p.\n", surface);
+            D_DEBUG_AT (CairoDFB_Acquire, "Allocating buffer for surface %p.\n", surface);
        
             surface->tmpsurface = 
                 _directfb_buffer_surface_create (surface->dfb, 
@@ -499,13 +381,13 @@ _directfb_acquire_surface (cairo_directfb_surface_t  *surface,
         }
         buffer = surface->tmpsurface;
         
-        surface->dfbsurface->GetCapabilities (surface->dfbsurface, &caps);
+/*        surface->dfbsurface->GetCapabilities (surface->dfbsurface, &caps);
         if (caps & DSCAPS_FLIPPING) {
             DFBRegion region = { .x1 = source_rect.x, .y1 = source_rect.y, 
                                  .x2 = source_rect.x + source_rect.w - 1,
                                  .y2 = source_rect.y + source_rect.h - 1 };
             surface->dfbsurface->Flip (surface->dfbsurface, &region, DSFLIP_BLIT);
-        } 
+        } */
         buffer->Blit (buffer, surface->dfbsurface, &source_rect, 0, 0);
     }
     else {
@@ -518,7 +400,7 @@ _directfb_acquire_surface (cairo_directfb_surface_t  *surface,
     *image_extra = buffer;
     
     if (buffer->Lock (buffer, lock_flags, &data, &pitch)) {
-        D_DEBUG_AT (Cairo_DirectFB, "Couldn't lock surface!\n");
+        D_DEBUG_AT (CairoDFB_Acquire, "Couldn't lock surface!\n");
         goto ERROR;
     }
             
@@ -565,7 +447,7 @@ _cairo_directfb_surface_create_similar (void            *abstract_src,
     cairo_directfb_surface_t *surface;
     cairo_format_t            format;
     
-    D_DEBUG_AT (Cairo_DirectFB, 
+    D_DEBUG_AT (CairoDFB_Surface, 
                 "%s( src=%p, content=0x%x, width=%d, height=%d).\n",
                 __FUNCTION__, source, content, width, height);
     
@@ -619,8 +501,7 @@ _cairo_directfb_surface_finish (void *data)
 {
     cairo_directfb_surface_t *surface = (cairo_directfb_surface_t *)data;
     
-    D_DEBUG_AT (Cairo_DirectFB, 
-                "%s( surface=%p ).\n", __FUNCTION__, surface);
+    D_DEBUG_AT (CairoDFB_Surface, "%s( surface=%p ).\n", __FUNCTION__, surface);
         
     if (surface->clips) {
         free (surface->clips);
@@ -656,7 +537,7 @@ _cairo_directfb_surface_acquire_source_image (void                   *abstract_s
 {
     cairo_directfb_surface_t *surface = abstract_surface;
     
-    D_DEBUG_AT (Cairo_DirectFB, 
+    D_DEBUG_AT (CairoDFB_Acquire, 
                 "%s( surface=%p ).\n", __FUNCTION__, surface);
     
     return _directfb_acquire_surface (surface, NULL, image_out, 
@@ -671,7 +552,7 @@ _cairo_directfb_surface_release_source_image (void                  *abstract_su
     cairo_directfb_surface_t *surface = abstract_surface;
     IDirectFBSurface *buffer = image_extra;
     
-    D_DEBUG_AT (Cairo_DirectFB, 
+    D_DEBUG_AT (CairoDFB_Acquire, 
                 "%s( surface=%p ).\n", __FUNCTION__, surface);
     
     buffer->Unlock (buffer);
@@ -687,57 +568,17 @@ _cairo_directfb_surface_acquire_dest_image (void                     *abstract_s
                                             void                    **image_extra)
 {
     cairo_directfb_surface_t *surface = abstract_surface;
-    cairo_status_t status;
-
-    D_DEBUG_AT (Cairo_DirectFB, 
-                "%s( surface=%p, interest_rect={ %d %d %d %d } ).\n", 
-                __FUNCTION__, surface, 
+    
+    D_DEBUG_AT (CairoDFB_Acquire, 
+                "%s( surface=%p (%dx%d), interest_rect={ %u %u %u %u } ).\n", 
+                __FUNCTION__, surface, surface->width, surface->height,
                 interest_rect ? interest_rect->x : 0,
                 interest_rect ? interest_rect->y : 0,
-                interest_rect ? interest_rect->width : surface->width,
-                interest_rect ? interest_rect->height : surface->height);
+                interest_rect ? interest_rect->width  : (unsigned) surface->width,
+                interest_rect ? interest_rect->height : (unsigned) surface->height);
     
-    status = _directfb_acquire_surface (surface, interest_rect, image_out,
-                                        image_rect_out, image_extra, DSLF_READ | DSLF_WRITE);
-    if (status)
-        return status;
-
-    /* Ensure that the new image has the same clip, if it's the same buffer */
-    if ((IDirectFBSurface*) *image_extra == surface->dfbsurface &&
-        surface->clips)
-    {
-        cairo_surface_t *s = (cairo_surface_t*) *image_out;
-
-        unsigned int clip_serial = _cairo_surface_allocate_clip_serial (s);
-
-        cairo_region_t clip_region;
-
-        if (surface->n_clips == 1) {
-            cairo_rectangle_int_t rect = { surface->clips[0].x1, surface->clips[0].y1,
-                                           surface->clips[0].x2 - surface->clips[0].x1,
-                                           surface->clips[0].y2 - surface->clips[0].y1 };
-            _cairo_region_init_rect (&clip_region, &rect);
-        } else {
-            cairo_box_int_t *boxes = _cairo_malloc_ab (surface->n_clips, sizeof(cairo_box_int_t));
-            int k;
-
-            for (k = 0; k < surface->n_clips; k++) {
-                boxes[k].p1.x = surface->clips[k].x1;
-                boxes[k].p1.y = surface->clips[k].y1;
-                boxes[k].p2.x = surface->clips[k].x2;
-                boxes[k].p2.y = surface->clips[k].y2;
-            }
-
-            _cairo_region_init_boxes (&clip_region, boxes, surface->n_clips);
-            free (boxes);
-        }
-
-        _cairo_surface_set_clip_region (s, &clip_region, clip_serial);
-
-        _cairo_region_fini (&clip_region);
-    }
-
-    return status;
+    return _directfb_acquire_surface (surface, interest_rect, image_out, 
+                                      image_rect_out, image_extra, DSLF_READ | DSLF_WRITE);
 }
 
 static void
@@ -750,24 +591,19 @@ _cairo_directfb_surface_release_dest_image (void                  *abstract_surf
     cairo_directfb_surface_t *surface = abstract_surface;
     IDirectFBSurface *buffer = image_extra; 
     
-    D_DEBUG_AT (Cairo_DirectFB, 
+    D_DEBUG_AT (CairoDFB_Acquire, 
                 "%s( surface=%p ).\n", __FUNCTION__, surface);
     
     buffer->Unlock (buffer);
 
     if (surface->dfbsurface != buffer) {
-        DFBRegion region = { interest_rect->x, interest_rect->y,
-                             interest_rect->x+interest_rect->width-1,
-                             interest_rect->y+interest_rect->height-1 };
-
-        DFBRectangle dr = { image_rect->x, image_rect->y,
-                            image_rect->width, image_rect->height };
-
-        _dfb_blit_op op = { FALSE, buffer, { 0, 0, dr.w, dr.h }, dr };
-
+        DFBRegion region = { .x1 = interest_rect->x, .y1 = interest_rect->y,
+                             .x2 = interest_rect->x+interest_rect->width-1,
+                             .y2 = interest_rect->y+interest_rect->height-1 };
+        surface->dfbsurface->SetClip (surface->dfbsurface, &region);
         surface->dfbsurface->SetBlittingFlags (surface->dfbsurface, DSBLIT_NOFX);
-
-        _cairo_directfb_run_clipped (surface, &region, _dfb_clip_func_blit, &op);
+        surface->dfbsurface->Blit (surface->dfbsurface, buffer,
+                                   NULL, image_rect->x, image_rect->y);
     }
     
     cairo_surface_destroy (&image->base);
@@ -785,7 +621,7 @@ _cairo_directfb_surface_clone_similar (void             *abstract_surface,
     cairo_directfb_surface_t *surface = abstract_surface;
     cairo_directfb_surface_t *clone;
     
-    D_DEBUG_AT (Cairo_DirectFB, 
+    D_DEBUG_AT (CairoDFB_Surface, 
                 "%s( surface=%p, src=%p ).\n", __FUNCTION__, surface, src);
 
     if (src->backend == surface->base.backend) {
@@ -893,7 +729,7 @@ _directfb_prepare_composite (cairo_directfb_surface_t    *dst,
                 sblend == DSBF_INVDESTALPHA) /* Doesn't work correctly */
                 return CAIRO_INT_STATUS_UNSUPPORTED;
                 
-            D_DEBUG_AT (Cairo_DirectFB, "Replacing src pattern by mask pattern.\n");
+            D_DEBUG_AT (CairoDFB_Render, "Replacing src pattern by mask pattern.\n");
                 
             tmp = src_pattern;
             tmp_x = *src_x; tmp_y = *src_y;
@@ -1050,7 +886,7 @@ _cairo_directfb_surface_composite (cairo_operator_t  op,
     DFBAccelerationMask         accel, mask;
     cairo_int_status_t          ret;
     
-    D_DEBUG_AT (Cairo_DirectFB,
+    D_DEBUG_AT (CairoDFB_Render,
                 "%s( op=%d, src_pattern=%p, mask_pattern=%p, dst=%p,"
                    " src_x=%d, src_y=%d, mask_x=%d, mask_y=%d, dst_x=%d,"
                    " dst_y=%d, width=%u, height=%u ).\n",
@@ -1067,7 +903,7 @@ _cairo_directfb_surface_composite (cairo_operator_t  op,
     
     dst->dfbsurface->GetAccelerationMask (dst->dfbsurface, src->dfbsurface, &mask);
     if (!(mask & accel)) {
-        D_DEBUG_AT (Cairo_DirectFB, "No acceleration (%08x)!\n", accel);
+        D_DEBUG_AT (CairoDFB_Render, "No acceleration (%08x)!\n", accel);
         if (accel != DFXL_BLIT) {
             _directfb_finish_composite (dst, src_pattern, &src->base, &src_attr);
             return CAIRO_INT_STATUS_UNSUPPORTED;
@@ -1087,12 +923,11 @@ _cairo_directfb_surface_composite (cairo_operator_t  op,
             sr.h = height;
         
             if (src_attr.extend == CAIRO_EXTEND_NONE) {
-                D_DEBUG_AT (Cairo_DirectFB, "Running Blit().\n");
-
-                {
-                    _dfb_blit_op op = { FALSE, src->dfbsurface, sr, { dst_x, dst_y, width, height } };
-                    _cairo_directfb_run_clipped (dst, NULL, _dfb_clip_func_blit, &op);
-                }
+                D_DEBUG_AT (CairoDFB_Render, "Running Blit().\n");
+        
+                RUN_CLIPPED( dst, NULL,
+                             dst->dfbsurface->Blit (dst->dfbsurface,
+                                            src->dfbsurface, &sr, dst_x, dst_y));
             }
             else if (src_attr.extend == CAIRO_EXTEND_REPEAT) {
                 DFBRegion clip;
@@ -1102,12 +937,11 @@ _cairo_directfb_surface_composite (cairo_operator_t  op,
                 clip.x2 = dst_x + width  - 1;
                 clip.y2 = dst_y + height - 1;
             
-                D_DEBUG_AT (Cairo_DirectFB, "Running TileBlit().\n");
+                D_DEBUG_AT (CairoDFB_Render, "Running TileBlit().\n");
             
-                {
-                    _dfb_blit_op op = { TRUE, src->dfbsurface, sr, { dst_x, dst_y, width, height } };
-                    _cairo_directfb_run_clipped (dst, &clip, _dfb_clip_func_blit, &op);
-                }
+                RUN_CLIPPED( dst, &clip,
+                             dst->dfbsurface->TileBlit (dst->dfbsurface, 
+                                            src->dfbsurface, &sr, dst_x, dst_y));
             }
         }   break;
         
@@ -1130,12 +964,11 @@ _cairo_directfb_surface_composite (cairo_operator_t  op,
             dr.w = width;
             dr.h = height;
             
-            D_DEBUG_AT (Cairo_DirectFB, "Running StretchBlit().\n");
+            D_DEBUG_AT (CairoDFB_Render, "Running StretchBlit().\n");
 
-            {
-                _dfb_blit_op op = { FALSE, src->dfbsurface, sr, dr };
-                _cairo_directfb_run_clipped (dst, NULL, _dfb_clip_func_blit, &op);
-            }
+            RUN_CLIPPED (dst, NULL,
+                         dst->dfbsurface->StretchBlit (dst->dfbsurface, 
+                                                       src->dfbsurface, &sr, &dr));
         }   break;
         
         case DFXL_TEXTRIANGLES: {
@@ -1189,13 +1022,11 @@ _cairo_directfb_surface_composite (cairo_operator_t  op,
             clip.x2 = dst_x + width  - 1;
             clip.y2 = dst_y + height - 1;
         
-            D_DEBUG_AT (Cairo_DirectFB, "Running TextureTriangles().\n");
+            D_DEBUG_AT (CairoDFB_Render, "Running TextureTriangles().\n");
             
-            {
-                _dfb_texture_triangles_op op = { src->dfbsurface, v, NULL, 4, DTTF_FAN };
-                _cairo_directfb_run_clipped (dst, &clip, _dfb_clip_func_texture_triangles, &op);
-            }
-
+            RUN_CLIPPED (dst, &clip,
+                         dst->dfbsurface->TextureTriangles (dst->dfbsurface, 
+                                            src->dfbsurface, v, NULL, 4, DTTF_FAN));
         }   break;
         
         default:
@@ -1224,7 +1055,7 @@ _cairo_directfb_surface_fill_rectangles (void                  *abstract_surface
     DFBRectangle              r[n_rects];
     int                       i;
     
-    D_DEBUG_AT (Cairo_DirectFB, 
+    D_DEBUG_AT (CairoDFB_Render, 
                 "%s( dst=%p, op=%d, color=%p, rects=%p, n_rects=%d ).\n",
                 __FUNCTION__, dst, op, color, rects, n_rects);
 
@@ -1273,11 +1104,9 @@ _cairo_directfb_surface_fill_rectangles (void                  *abstract_surface
         r[i].w = rects[i].width;
         r[i].h = rects[i].height;
     }
-
-    {
-        _dfb_fill_rects_op op = { n_rects, r };
-        _cairo_directfb_run_clipped (dst, NULL, _dfb_clip_func_fill_rects, &op);
-    }
+     
+    RUN_CLIPPED (dst, NULL,
+                 dst->dfbsurface->FillRectangles (dst->dfbsurface, r, n_rects));
     
     return CAIRO_STATUS_SUCCESS;
 }
@@ -1302,7 +1131,7 @@ _cairo_directfb_surface_composite_trapezoids (cairo_operator_t   op,
     cairo_status_t              ret;
     DFBAccelerationMask         accel;
     
-    D_DEBUG_AT (Cairo_DirectFB,
+    D_DEBUG_AT (CairoDFB_Render,
                 "%s( op=%d, pattern=%p, dst=%p, antialias=%d,"
                    " src_x=%d, src_y=%d, dst_x=%d, dst_y=%d,"
                    " width=%u, height=%u, traps=%p, num_traps=%d ).\n",
@@ -1409,13 +1238,12 @@ _cairo_directfb_surface_composite_trapezoids (cairo_operator_t   op,
         
 #undef ADD_TRI
               
-        D_DEBUG_AT (Cairo_DirectFB, "Running TextureTriangles().\n");
+        D_DEBUG_AT (CairoDFB_Render, "Running TextureTriangles().\n");
             
-        {
-            _dfb_texture_triangles_op op = { src->dfbsurface, vertex, NULL, n, DTTF_LIST };
-            _cairo_directfb_run_clipped (dst, &clip, _dfb_clip_func_texture_triangles, &op);
-        }
-
+        RUN_CLIPPED (dst, NULL,
+                     dst->dfbsurface->TextureTriangles (dst->dfbsurface, src->dfbsurface, 
+                                                    vertex, NULL, n, DTTF_LIST));
+                                            
         ret = CAIRO_STATUS_SUCCESS;
     }
     
@@ -1431,7 +1259,7 @@ _cairo_directfb_surface_set_clip_region (void           *abstract_surface,
 {
     cairo_directfb_surface_t *surface = abstract_surface;
     
-    D_DEBUG_AT (Cairo_DirectFB, 
+    D_DEBUG_AT (CairoDFB_Clip, 
                 "%s( surface=%p, region=%p ).\n",
                 __FUNCTION__, surface, region);
     
@@ -1487,7 +1315,7 @@ _cairo_directfb_abstract_surface_get_extents (void                  *abstract_su
 {
     cairo_directfb_surface_t *surface = abstract_surface;
     
-    D_DEBUG_AT (Cairo_DirectFB,
+    D_DEBUG_AT (CairoDFB_Surface,
                 "%s( surface=%p, rectangle=%p ).\n",
                 __FUNCTION__, surface, rectangle);
     
@@ -1579,7 +1407,7 @@ _directfb_acquire_font_cache (cairo_directfb_surface_t     *surface,
             case CAIRO_FORMAT_ARGB32:
                 break;
             default:
-                D_DEBUG_AT (Cairo_DirectFB,
+                D_DEBUG_AT (CairoDFB_Font,
                             "Unsupported font format %d!\n", img->format);
                 return CAIRO_INT_STATUS_UNSUPPORTED;
         }
@@ -1620,14 +1448,14 @@ _directfb_acquire_font_cache (cairo_directfb_surface_t     *surface,
             scaled_glyph->surface_private = rect;
             chars[num_chars++] = scaled_glyph;
             
-            /*D_DEBUG_AT (Cairo_DirectFB, 
+            /*D_DEBUG_AT (CairoDFB_Font, 
                         "Glyph %lu will be loaded at (%d,%d).\n",
                         glyphs[i].index, rects[n].x, rects[n].y);*/
         }
         else {
             rects[n] = *((DFBRectangle *)scaled_glyph->surface_private);
             
-            /*D_DEBUG_AT (Cairo_DirectFB, 
+            /*D_DEBUG_AT (CairoDFB_Font, 
                         "Glyph %lu already loaded at (%d,%d).\n",
                         glyphs[i].index, rects[n].x, rects[n].y);*/
         }
@@ -1649,7 +1477,7 @@ _directfb_acquire_font_cache (cairo_directfb_surface_t     *surface,
             w = MAX (w, cache->width);
             h = MAX (h, cache->height);
             
-            D_DEBUG_AT (Cairo_DirectFB,
+            D_DEBUG_AT (CairoDFB_Font,
                         "Reallocating font cache (%dx%d).\n", w, h);
             
             new_cache = _directfb_allocate_font_cache (surface->dfb, w, h);
@@ -1664,7 +1492,7 @@ _directfb_acquire_font_cache (cairo_directfb_surface_t     *surface,
         }
     }
     else {
-        D_DEBUG_AT (Cairo_DirectFB,
+        D_DEBUG_AT (CairoDFB_Font,
                     "Allocating font cache (%dx%d).\n", w, h);
         
         cache = _directfb_allocate_font_cache (surface->dfb, w, h);
@@ -1754,7 +1582,7 @@ _cairo_directfb_surface_scaled_font_fini (cairo_scaled_font_t *scaled_font)
 {
     cairo_directfb_font_cache_t *cache = scaled_font->surface_private;
     
-    D_DEBUG_AT (Cairo_DirectFB,
+    D_DEBUG_AT (CairoDFB_Font,
                 "%s( scaled_font=%p ).\n", __FUNCTION__, scaled_font);
     
     if (cache) {
@@ -1767,7 +1595,7 @@ static void
 _cairo_directfb_surface_scaled_glyph_fini (cairo_scaled_glyph_t *scaled_glyph,
                                            cairo_scaled_font_t  *scaled_font)
 {
-     D_DEBUG_AT (Cairo_DirectFB,
+     D_DEBUG_AT (CairoDFB_Font,
                  "%s( scaled_glyph=%p, scaled_font=%p ).\n",
                  __FUNCTION__, scaled_glyph, scaled_font);
 
@@ -1797,7 +1625,7 @@ _cairo_directfb_surface_show_glyphs (void                *abstract_dst,
     DFBPoint                     points[num_glyphs];
     int                          num;
     
-    D_DEBUG_AT (Cairo_DirectFB,
+    D_DEBUG_AT (CairoDFB_Font,
                 "%s( dst=%p, op=%d, pattern=%p, glyphs=%p, num_glyphs=%d, scaled_font=%p ).\n",
                 __FUNCTION__, dst, op, pattern, glyphs, num_glyphs, scaled_font);
                             
@@ -1838,12 +1666,11 @@ _cairo_directfb_surface_show_glyphs (void                *abstract_dst,
     dst->dfbsurface->SetDstBlendFunction (dst->dfbsurface, dblend);
     dst->dfbsurface->SetColor (dst->dfbsurface, color.r, color.g, color.b, color.a);
     
-    D_DEBUG_AT (Cairo_DirectFB, "Running BatchBlit().\n");
-
-    {
-        _dfb_batch_blit_op op = { cache->dfbsurface, num, rects, points };
-        _cairo_directfb_run_clipped (dst, NULL, _dfb_clip_func_batch_blit, &op);
-    }
+    D_DEBUG_AT (CairoDFB_Font, "Running BatchBlit().\n");
+        
+    RUN_CLIPPED (dst, NULL,
+                 dst->dfbsurface->BatchBlit (dst->dfbsurface,
+                                         cache->dfbsurface, rects, points, num));
         
     return CAIRO_STATUS_SUCCESS;
 }
@@ -1937,7 +1764,7 @@ cairo_directfb_surface_backend_init (IDirectFB *dfb)
         cairo_directfb_surface_backend.scaled_glyph_fini = NULL;
         cairo_directfb_surface_backend.show_glyphs = NULL;
 #endif
-        D_DEBUG_AT (Cairo_DirectFB, "Acceleration disabled.\n");
+        D_DEBUG_AT (CairoDFB_Surface, "Acceleration disabled.\n");
     }
     else {
         DFBGraphicsDeviceDescription dsc;
@@ -1945,19 +1772,19 @@ cairo_directfb_surface_backend_init (IDirectFB *dfb)
         dfb->GetDeviceDescription (dfb, &dsc);
     
 #if DFB_COMPOSITE
-        if (!(dsc.acceleration_mask & DFXL_BLIT))
-            cairo_directfb_surface_backend.composite = NULL;
+//        if (!(dsc.acceleration_mask & DFXL_BLIT))
+//            cairo_directfb_surface_backend.composite = NULL;
 #endif
 
 #if DFB_COMPOSITE_TRAPEZOIDS
-        if (!(dsc.acceleration_mask & DFXL_TEXTRIANGLES))
-            cairo_directfb_surface_backend.composite_trapezoids = NULL;
+//        if (!(dsc.acceleration_mask & DFXL_TEXTRIANGLES))
+//            cairo_directfb_surface_backend.composite_trapezoids = NULL;
 #endif
     }
     
     if (getenv ("CAIRO_DIRECTFB_ARGB_FONT")) {
         _directfb_argb_font = 1;
-        D_DEBUG_AT (Cairo_DirectFB, "Using ARGB fonts.\n");
+        D_DEBUG_AT (CairoDFB_Surface, "Using ARGB fonts.\n");
     }
 
     done = 1;
commit a097bafd287ae3ee5ed3677a83b31d8d9d225a0c
Author: Vladimir Vukicevic <vladimir at pobox.com>
Date:   Sun Aug 10 05:05:27 2008 -0700

    [dfb] correctly handle case of 0 boxes in clip region

diff --git a/src/cairo-directfb-surface.c b/src/cairo-directfb-surface.c
index 279aef7..c20dc83 100644
--- a/src/cairo-directfb-surface.c
+++ b/src/cairo-directfb-surface.c
@@ -1442,6 +1442,8 @@ _cairo_directfb_surface_set_clip_region (void           *abstract_surface,
         int              i;
 
         status = _cairo_region_get_boxes (region, &n_boxes, &boxes);
+        if (n_boxes == 0)
+            return CAIRO_STATUS_SUCCESS;
         if (status)
             return status;
         
commit a0cfd9962f5c7bbb047698d966923af30e9c3221
Author: Vladimir Vukicevic <vladimir at slide.(none)>
Date:   Sun Aug 10 05:05:27 2008 -0700

    [dfb] Propagate clip correctly to surface returned from acquire_dest_image
    
    If the internal buffer is wrapped in an image surface in acquire_dest_image,
    that image surface needs the current clip region propagated to it.  If not,
    then the clip needs to be applied at release_dest_image time.

diff --git a/src/cairo-directfb-surface.c b/src/cairo-directfb-surface.c
index 7b88d4c..279aef7 100644
--- a/src/cairo-directfb-surface.c
+++ b/src/cairo-directfb-surface.c
@@ -687,7 +687,8 @@ _cairo_directfb_surface_acquire_dest_image (void                     *abstract_s
                                             void                    **image_extra)
 {
     cairo_directfb_surface_t *surface = abstract_surface;
-    
+    cairo_status_t status;
+
     D_DEBUG_AT (Cairo_DirectFB, 
                 "%s( surface=%p, interest_rect={ %d %d %d %d } ).\n", 
                 __FUNCTION__, surface, 
@@ -696,8 +697,47 @@ _cairo_directfb_surface_acquire_dest_image (void                     *abstract_s
                 interest_rect ? interest_rect->width : surface->width,
                 interest_rect ? interest_rect->height : surface->height);
     
-    return _directfb_acquire_surface (surface, interest_rect, image_out, 
-                                      image_rect_out, image_extra, DSLF_READ | DSLF_WRITE);
+    status = _directfb_acquire_surface (surface, interest_rect, image_out,
+                                        image_rect_out, image_extra, DSLF_READ | DSLF_WRITE);
+    if (status)
+        return status;
+
+    /* Ensure that the new image has the same clip, if it's the same buffer */
+    if ((IDirectFBSurface*) *image_extra == surface->dfbsurface &&
+        surface->clips)
+    {
+        cairo_surface_t *s = (cairo_surface_t*) *image_out;
+
+        unsigned int clip_serial = _cairo_surface_allocate_clip_serial (s);
+
+        cairo_region_t clip_region;
+
+        if (surface->n_clips == 1) {
+            cairo_rectangle_int_t rect = { surface->clips[0].x1, surface->clips[0].y1,
+                                           surface->clips[0].x2 - surface->clips[0].x1,
+                                           surface->clips[0].y2 - surface->clips[0].y1 };
+            _cairo_region_init_rect (&clip_region, &rect);
+        } else {
+            cairo_box_int_t *boxes = _cairo_malloc_ab (surface->n_clips, sizeof(cairo_box_int_t));
+            int k;
+
+            for (k = 0; k < surface->n_clips; k++) {
+                boxes[k].p1.x = surface->clips[k].x1;
+                boxes[k].p1.y = surface->clips[k].y1;
+                boxes[k].p2.x = surface->clips[k].x2;
+                boxes[k].p2.y = surface->clips[k].y2;
+            }
+
+            _cairo_region_init_boxes (&clip_region, boxes, surface->n_clips);
+            free (boxes);
+        }
+
+        _cairo_surface_set_clip_region (s, &clip_region, clip_serial);
+
+        _cairo_region_fini (&clip_region);
+    }
+
+    return status;
 }
 
 static void
@@ -716,13 +756,18 @@ _cairo_directfb_surface_release_dest_image (void                  *abstract_surf
     buffer->Unlock (buffer);
 
     if (surface->dfbsurface != buffer) {
-        DFBRegion region = { .x1 = interest_rect->x, .y1 = interest_rect->y,
-                             .x2 = interest_rect->x+interest_rect->width-1,
-                             .y2 = interest_rect->y+interest_rect->height-1 };
-        surface->dfbsurface->SetClip (surface->dfbsurface, &region);
+        DFBRegion region = { interest_rect->x, interest_rect->y,
+                             interest_rect->x+interest_rect->width-1,
+                             interest_rect->y+interest_rect->height-1 };
+
+        DFBRectangle dr = { image_rect->x, image_rect->y,
+                            image_rect->width, image_rect->height };
+
+        _dfb_blit_op op = { FALSE, buffer, { 0, 0, dr.w, dr.h }, dr };
+
         surface->dfbsurface->SetBlittingFlags (surface->dfbsurface, DSBLIT_NOFX);
-        surface->dfbsurface->Blit (surface->dfbsurface, buffer,
-                                   NULL, image_rect->x, image_rect->y);
+
+        _cairo_directfb_run_clipped (surface, &region, _dfb_clip_func_blit, &op);
     }
     
     cairo_surface_destroy (&image->base);
commit 71f010bb522dd9387d749703a170de026a3fa8d6
Author: Vladimir Vukicevic <vladimir at slide.(none)>
Date:   Sun Aug 10 05:05:26 2008 -0700

    [dfb] convert RUN_CLIPPED macro to function with helpers
    
    This helps with debugging and prepares the way for some future
    code cleanup.

diff --git a/src/cairo-directfb-surface.c b/src/cairo-directfb-surface.c
index 7483048..7b88d4c 100644
--- a/src/cairo-directfb-surface.c
+++ b/src/cairo-directfb-surface.c
@@ -120,38 +120,160 @@ static int _directfb_argb_font = 0;
 
 /*****************************************************************************/
 
+typedef cairo_bool_t (*clipped_draw_func) (cairo_directfb_surface_t *dfs,
+                                           void *closure);
 
-#define RUN_CLIPPED( surface, clip, func ) {\
-    if ((surface)->clips) {\
-        int k;\
-        for (k = 0; k < (surface)->n_clips; k++) {\
-            if (clip) {\
-                DFBRegion  reg = (surface)->clips[k];\
-                DFBRegion *cli = (clip);\
-                if (reg.x2 < cli->x1 || reg.y2 < cli->y1 ||\
-                    reg.x1 > cli->x2 || reg.y1 > cli->y2)\
-                    continue;\
-                if (reg.x1 < cli->x1)\
-                    reg.x1 = cli->x1;\
-                if (reg.y1 < cli->y1)\
-                    reg.y1 = cli->y1;\
-                if (reg.x2 > cli->x2)\
-                    reg.x2 = cli->x2;\
-                if (reg.y2 > cli->y2)\
-                    reg.y2 = cli->y2;\
-                (surface)->dfbsurface->SetClip ((surface)->dfbsurface, &reg);\
-            }\
-            else {\
-                (surface)->dfbsurface->SetClip ((surface)->dfbsurface,\
-                                           &(surface)->clips[k]);\
-            }\
-            func;\
-        }\
-    }\
-    else {\
-        (surface)->dfbsurface->SetClip ((surface)->dfbsurface, clip);\
-        func;\
-    }\
+static cairo_bool_t
+_cairo_directfb_run_clipped (cairo_directfb_surface_t *surface,
+                             const DFBRegion *clip,
+                             clipped_draw_func draw_func,
+                             void *draw_closure)
+{
+    cairo_bool_t ok = TRUE;
+
+    if (surface->clips) {
+        int k;
+        for (k = 0; k < surface->n_clips; k++) {
+            DFBRegion reg = surface->clips[k];
+
+            if (clip) {
+                if (reg.x2 < clip->x1 || reg.y2 < clip->y1 ||
+                    reg.x1 > clip->x2 || reg.y1 > clip->y2)
+                    continue;
+                if (reg.x1 < clip->x1)
+                    reg.x1 = clip->x1;
+                if (reg.y1 < clip->y1)
+                    reg.y1 = clip->y1;
+                if (reg.x2 > clip->x2)
+                    reg.x2 = clip->x2;
+                if (reg.y2 > clip->y2)
+                    reg.y2 = clip->y2;
+            }
+
+            surface->dfbsurface->SetClip (surface->dfbsurface, &reg);
+
+            ok = draw_func (surface, draw_closure);
+            if (!ok)
+                goto FAIL;
+        }
+    } else {
+        surface->dfbsurface->SetClip (surface->dfbsurface, clip);
+
+        ok = draw_func (surface, draw_closure);
+    }
+
+FAIL:
+
+    surface->dfbsurface->SetClip (surface->dfbsurface, NULL);
+
+    return ok;
+}
+
+// TextureTriangles
+
+typedef struct {
+    cairo_bool_t tile;
+    IDirectFBSurface *src;
+    DFBRectangle src_rect;
+    DFBRectangle dst_rect;
+} _dfb_blit_op;
+
+static cairo_bool_t
+_dfb_clip_func_blit (cairo_directfb_surface_t *dfs,
+                     void *closure)
+{
+    _dfb_blit_op *op = (_dfb_blit_op*) closure;
+    DFBResult rv;
+
+    if (op->tile) {
+        rv = dfs->dfbsurface->TileBlit (dfs->dfbsurface,
+                                        op->src,
+                                        &op->src_rect,
+                                        op->dst_rect.x,
+                                        op->dst_rect.y);
+    } else if (op->dst_rect.w != op->src_rect.w ||
+               op->dst_rect.h != op->src_rect.h)
+    {
+        rv = dfs->dfbsurface->StretchBlit (dfs->dfbsurface,
+                                           op->src,
+                                           &op->src_rect,
+                                           &op->dst_rect);
+    } else {
+        rv = dfs->dfbsurface->Blit (dfs->dfbsurface,
+                                    op->src,
+                                    &op->src_rect,
+                                    op->dst_rect.x,
+                                    op->dst_rect.y);
+    }
+
+    return (rv == DFB_OK);
+}
+
+typedef struct {
+    IDirectFBSurface *src;
+    int count;
+    const DFBRectangle *src_rects;
+    const DFBPoint *dst_points;
+} _dfb_batch_blit_op;
+
+static cairo_bool_t
+_dfb_clip_func_batch_blit (cairo_directfb_surface_t *dfs,
+                           void *closure)
+{
+    _dfb_batch_blit_op *op = (_dfb_batch_blit_op*) closure;
+    DFBResult rv;
+
+    rv = dfs->dfbsurface->BatchBlit (dfs->dfbsurface,
+                                     op->src,
+                                     op->src_rects,
+                                     op->dst_points,
+                                     op->count);
+
+    return (rv == DFB_OK);
+}
+
+typedef struct {
+    int count;
+    const DFBRectangle *rects;
+} _dfb_fill_rects_op;
+
+static cairo_bool_t
+_dfb_clip_func_fill_rects (cairo_directfb_surface_t *dfs,
+                           void *closure)
+{
+    _dfb_fill_rects_op *op = (_dfb_fill_rects_op*) closure;
+    DFBResult rv;
+
+    rv = dfs->dfbsurface->FillRectangles (dfs->dfbsurface,
+                                          op->rects,
+                                          op->count);
+
+    return (rv == DFB_OK);
+}
+
+typedef struct {
+    IDirectFBSurface *src;
+    const DFBVertex *vertices;
+    const int *indices;
+    int count;
+    DFBTriangleFormation formation;
+} _dfb_texture_triangles_op;
+
+static cairo_bool_t
+_dfb_clip_func_texture_triangles (cairo_directfb_surface_t *dfs,
+                                  void *closure)
+{
+    _dfb_texture_triangles_op *op = (_dfb_texture_triangles_op*) closure;
+    DFBResult rv;
+
+    rv = dfs->dfbsurface->TextureTriangles (dfs->dfbsurface,
+                                            op->src,
+                                            op->vertices,
+                                            op->indices,
+                                            op->count,
+                                            op->formation);
+
+    return (rv == DFB_OK);
 }
 
 #define TRANSFORM_POINT2X( m, x, y, ret_x, ret_y ) {\
@@ -921,10 +1043,11 @@ _cairo_directfb_surface_composite (cairo_operator_t  op,
         
             if (src_attr.extend == CAIRO_EXTEND_NONE) {
                 D_DEBUG_AT (Cairo_DirectFB, "Running Blit().\n");
-        
-                RUN_CLIPPED( dst, NULL,
-                             dst->dfbsurface->Blit (dst->dfbsurface,
-                                            src->dfbsurface, &sr, dst_x, dst_y));
+
+                {
+                    _dfb_blit_op op = { FALSE, src->dfbsurface, sr, { dst_x, dst_y, width, height } };
+                    _cairo_directfb_run_clipped (dst, NULL, _dfb_clip_func_blit, &op);
+                }
             }
             else if (src_attr.extend == CAIRO_EXTEND_REPEAT) {
                 DFBRegion clip;
@@ -936,9 +1059,10 @@ _cairo_directfb_surface_composite (cairo_operator_t  op,
             
                 D_DEBUG_AT (Cairo_DirectFB, "Running TileBlit().\n");
             
-                RUN_CLIPPED( dst, &clip,
-                             dst->dfbsurface->TileBlit (dst->dfbsurface, 
-                                            src->dfbsurface, &sr, dst_x, dst_y));
+                {
+                    _dfb_blit_op op = { TRUE, src->dfbsurface, sr, { dst_x, dst_y, width, height } };
+                    _cairo_directfb_run_clipped (dst, &clip, _dfb_clip_func_blit, &op);
+                }
             }
         }   break;
         
@@ -963,9 +1087,10 @@ _cairo_directfb_surface_composite (cairo_operator_t  op,
             
             D_DEBUG_AT (Cairo_DirectFB, "Running StretchBlit().\n");
 
-            RUN_CLIPPED (dst, NULL,
-                         dst->dfbsurface->StretchBlit (dst->dfbsurface, 
-                                                       src->dfbsurface, &sr, &dr));
+            {
+                _dfb_blit_op op = { FALSE, src->dfbsurface, sr, dr };
+                _cairo_directfb_run_clipped (dst, NULL, _dfb_clip_func_blit, &op);
+            }
         }   break;
         
         case DFXL_TEXTRIANGLES: {
@@ -1021,9 +1146,11 @@ _cairo_directfb_surface_composite (cairo_operator_t  op,
         
             D_DEBUG_AT (Cairo_DirectFB, "Running TextureTriangles().\n");
             
-            RUN_CLIPPED (dst, &clip,
-                         dst->dfbsurface->TextureTriangles (dst->dfbsurface, 
-                                            src->dfbsurface, v, NULL, 4, DTTF_FAN));
+            {
+                _dfb_texture_triangles_op op = { src->dfbsurface, v, NULL, 4, DTTF_FAN };
+                _cairo_directfb_run_clipped (dst, &clip, _dfb_clip_func_texture_triangles, &op);
+            }
+
         }   break;
         
         default:
@@ -1101,9 +1228,11 @@ _cairo_directfb_surface_fill_rectangles (void                  *abstract_surface
         r[i].w = rects[i].width;
         r[i].h = rects[i].height;
     }
-     
-    RUN_CLIPPED (dst, NULL,
-                 dst->dfbsurface->FillRectangles (dst->dfbsurface, r, n_rects));
+
+    {
+        _dfb_fill_rects_op op = { n_rects, r };
+        _cairo_directfb_run_clipped (dst, NULL, _dfb_clip_func_fill_rects, &op);
+    }
     
     return CAIRO_STATUS_SUCCESS;
 }
@@ -1237,10 +1366,11 @@ _cairo_directfb_surface_composite_trapezoids (cairo_operator_t   op,
               
         D_DEBUG_AT (Cairo_DirectFB, "Running TextureTriangles().\n");
             
-        RUN_CLIPPED (dst, NULL,
-                     dst->dfbsurface->TextureTriangles (dst->dfbsurface, src->dfbsurface, 
-                                                    vertex, NULL, n, DTTF_LIST));
-                                            
+        {
+            _dfb_texture_triangles_op op = { src->dfbsurface, vertex, NULL, n, DTTF_LIST };
+            _cairo_directfb_run_clipped (dst, &clip, _dfb_clip_func_texture_triangles, &op);
+        }
+
         ret = CAIRO_STATUS_SUCCESS;
     }
     
@@ -1662,10 +1792,11 @@ _cairo_directfb_surface_show_glyphs (void                *abstract_dst,
     dst->dfbsurface->SetColor (dst->dfbsurface, color.r, color.g, color.b, color.a);
     
     D_DEBUG_AT (Cairo_DirectFB, "Running BatchBlit().\n");
-        
-    RUN_CLIPPED (dst, NULL,
-                 dst->dfbsurface->BatchBlit (dst->dfbsurface,
-                                         cache->dfbsurface, rects, points, num));
+
+    {
+        _dfb_batch_blit_op op = { cache->dfbsurface, num, rects, points };
+        _cairo_directfb_run_clipped (dst, NULL, _dfb_clip_func_batch_blit, &op);
+    }
         
     return CAIRO_STATUS_SUCCESS;
 }


More information about the cairo-commit mailing list