[cairo-commit] src/cairo-directfb.h src/cairo-directfb-surface.c

Claudio Ciccani klan at kemper.freedesktop.org
Tue Dec 11 06:50:30 PST 2007


 src/cairo-directfb-surface.c |   99 +++++++++++++++++++++++++++++++++----------
 src/cairo-directfb.h         |   12 ++++-
 2 files changed, 88 insertions(+), 23 deletions(-)

New commits:
commit 942e3d53088a4d2b05c86d3f82b76cfbe707b3b5
Author: Claudio Ciccani <klan at directfb.org>
Date:   Tue Dec 11 15:50:05 2007 +0100

    [cairo-directfb] Support some environment variables
    
    Added a couple of (boolean) env. vars affecting the backend:
    CAIRO_DIRECTFB_NO_ACCEL, disables acceleration
    CAIRO_DIRECTFB_ARGB_FONT, enables using ARGB fonts instead of A8

diff --git a/src/cairo-directfb-surface.c b/src/cairo-directfb-surface.c
index 6068796..2797050 100644
--- a/src/cairo-directfb-surface.c
+++ b/src/cairo-directfb-surface.c
@@ -34,6 +34,8 @@
  *    Michael Emmel <mike.emmel at gmail.com>
  *    Claudio Ciccani <klan at users.sf.net>
  */
+ 
+#include <stdlib.h>
 
 #include "cairoint.h"
 
@@ -115,6 +117,10 @@ static cairo_surface_backend_t cairo_directfb_surface_backend;
 
 /*****************************************************************************/
 
+static int _directfb_argb_font = 0;
+
+/*****************************************************************************/
+
 
 #define RUN_CLIPPED( surface, clip, func ) {\
     if ((surface)->clips) {\
@@ -461,7 +467,7 @@ _cairo_directfb_surface_create_similar (void            *abstract_src,
                                         _cairo_to_directfb_format (format),
                                         MAX (width, 8), MAX (height, 8));
         if (tmp) {
-            DFBRectangle rect = { x:0, y:0, w:width, h:height };
+            DFBRectangle rect = { .x=0, .y=0, .w=width, .h=height };
             tmp->GetSubSurface (tmp, &rect, &surface->dfbsurface);
             tmp->Release (tmp);
         }
@@ -1311,7 +1317,8 @@ _directfb_allocate_font_cache (IDirectFB *dfb, int width, int height)
         return NULL;
 
     cache->dfb = dfb;
-    cache->dfbsurface = _directfb_buffer_surface_create (dfb, DSPF_A8, width, height);
+    cache->dfbsurface = _directfb_buffer_surface_create (dfb, 
+                            _directfb_argb_font ? DSPF_ARGB : DSPF_A8, width, height);
     if (!cache->dfbsurface) {
         free (cache);
         return NULL;
@@ -1476,34 +1483,55 @@ _directfb_acquire_font_cache (cairo_directfb_surface_t     *surface,
         if (cache->dfbsurface->Lock (cache->dfbsurface, 
                                      DSLF_WRITE, (void *)&data, &pitch))
             return _cairo_error (CAIRO_STATUS_NO_MEMORY);
-    
+            
         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 + rect->y*pitch + rect->x;
+            unsigned char         *dst  = data;
             unsigned char         *src  = img->data;
+            int                    j;
             
+            dst += rect->y * pitch + (_directfb_argb_font ? (rect->x<<2) : rect->x);
+                        
             if (img->format == CAIRO_FORMAT_A1) {
-                int j;
                 for (h = rect->h; h; h--) {
-                    for (j = 0; j < rect->w; j++)
-                        dst[j] = (src[j>>3] & (1 << (j&7))) ? 0xff : 0x00;
+                    if (_directfb_argb_font) {
+                        for (j = 0; j < rect->w; j++)
+                            ((u32 *)dst)[j] = (src[j>>3] & (1 << (j&7))) ? 0xffffffff : 0;
+                    }
+                    else {
+                        for (j = 0; j < rect->w; j++)
+                            dst[j] = (src[j>>3] & (1 << (j&7))) ? 0xff : 0;
+                    }
+                    
                     dst += pitch;
                     src += img->stride;
                 }
             }
             else if (img->format == CAIRO_FORMAT_A8) {
                 for (h = rect->h; h; h--) {
-                    direct_memcpy (dst, src, rect->w);
+                    if (_directfb_argb_font) {
+                        for (j = 0; j < rect->w; j++)
+                            ((u32 *)dst)[j] = src[j] * 0x01010101;
+                    }
+                    else {
+                        direct_memcpy (dst, src, rect->w);
+                    }
+                    
                     dst += pitch;
                     src += img->stride;
                 }
             }
             else { /* ARGB32 */
-                int j;
                 for (h = rect->h; h; h--) {
-                    for (j = 0; j < rect->w; j++)
-                        dst[j] = ((unsigned int *)src)[j] >> 24;
+                    if (_directfb_argb_font) {
+                        direct_memcpy (dst, src, rect->w<<2);
+                    }
+                    else {
+                        for (j = 0; j < rect->w; j++)
+                            dst[j] = ((u32 *)src)[j] >> 24;
+                    }
+                    
                     dst += pitch;
                     src += img->stride;
                 }
@@ -1597,10 +1625,12 @@ _cairo_directfb_surface_show_glyphs (void                *abstract_dst,
     if (color.a != 0xff)
         flags |= DSBLIT_BLEND_COLORALPHA;
         
-    if (sblend == DSBF_ONE) {
-        sblend = DSBF_SRCALPHA;
-        if (dblend == DSBF_ZERO)
-            dblend = DSBF_INVSRCALPHA;
+    if (!_directfb_argb_font) {
+        if (sblend == DSBF_ONE) {
+            sblend = DSBF_SRCALPHA;
+            if (dblend == DSBF_ZERO)
+                dblend = DSBF_INVSRCALPHA;
+        }
     } 
         
     dst->dfbsurface->SetBlittingFlags (dst->dfbsurface, flags);
@@ -1686,23 +1716,48 @@ static cairo_surface_backend_t cairo_directfb_surface_backend = {
 static void
 cairo_directfb_surface_backend_init (IDirectFB *dfb)
 {
-    DFBGraphicsDeviceDescription dsc;
-    static int                   done = 0;
+    static int done = 0;
     
     if (done)
         return;
         
-    dfb->GetDeviceDescription (dfb, &dsc);
-    
+    if (getenv ("CAIRO_DIRECTFB_NO_ACCEL")) {
+#if DFB_RECTANGLES
+        cairo_directfb_surface_backend.fill_rectangles = NULL;
+#endif
 #if DFB_COMPOSITE
-    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;
 #endif
+#if DFB_SHOW_GLYPHS
+        cairo_directfb_surface_backend.scaled_font_fini = NULL;
+        cairo_directfb_surface_backend.scaled_glyph_fini = NULL;
+        cairo_directfb_surface_backend.show_glyphs = NULL;
+#endif
+        D_DEBUG_AT (Cairo_DirectFB, "Acceleration disabled.\n");
+    }
+    else {
+        DFBGraphicsDeviceDescription dsc;
+        
+        dfb->GetDeviceDescription (dfb, &dsc);
+    
+#if DFB_COMPOSITE
+        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;
+#endif
+    }
+    
+    if (getenv ("CAIRO_DIRECTFB_ARGB_FONT")) {
+        _directfb_argb_font = 1;
+        D_DEBUG_AT (Cairo_DirectFB, "Using ARGB fonts.\n");
+    }
 
     done = 1;
 }   
diff --git a/src/cairo-directfb.h b/src/cairo-directfb.h
index 5b35a44..59653d3 100644
--- a/src/cairo-directfb.h
+++ b/src/cairo-directfb.h
@@ -34,6 +34,16 @@
  *	Carl D. Worth <cworth at isi.edu>
  */
 
+/*
+ * Environment variables affecting the backend:
+ *
+ *  CAIRO_DIRECTFB_NO_ACCEL (boolean)
+ *      if found, disables acceleration at all
+ *
+ *  CAIRO_DIRECTFB_ARGB_FONT (boolean)
+ *      if found, enables using ARGB fonts instead of A8
+ */
+
 #ifndef CAIRO_DIRECTFB_H
 #define CAIRO_DIRECTFB_H
 
@@ -46,7 +56,7 @@
 CAIRO_BEGIN_DECLS
 
 cairo_public cairo_surface_t *
-cairo_directfb_surface_create (IDirectFB *dfb,IDirectFBSurface *surface);
+cairo_directfb_surface_create (IDirectFB *dfb, IDirectFBSurface *surface);
 
 CAIRO_END_DECLS
 


More information about the cairo-commit mailing list