]> gitweb.factorcode.org Git - factor.git/commitdiff
enhanced performance of pango and cairo gadgets by making the intermediate byte-array...
authorMatthew Willis <matthew.willis@mac.com>
Sun, 1 Jun 2008 17:35:40 +0000 (10:35 -0700)
committerMatthew Willis <matthew.willis@mac.com>
Sun, 1 Jun 2008 17:35:40 +0000 (10:35 -0700)
extra/cairo/gadgets/gadgets.factor
extra/pango/cairo/cairo.factor

index f5f4d3e9651bdad04d08103e4f0857fa1dc85527..69252f83037a9d0f172c2976ee1fdcf58e76c1a7 100644 (file)
@@ -2,7 +2,8 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: sequences math opengl.gadgets kernel
 byte-arrays cairo.ffi cairo io.backend
-opengl.gl arrays ;
+ui.gadgets accessors opengl.gl
+arrays ;
 
 IN: cairo.gadgets
 
@@ -14,9 +15,17 @@ IN: cairo.gadgets
     [ cairo_image_surface_create_for_data ] 3bi
     r> with-cairo-from-surface ;
 
-: <cairo-gadget> ( dim quot -- )
-    over 2^-bounds swap copy-cairo
-    GL_BGRA rot <texture-gadget> ;
+TUPLE: cairo-gadget < texture-gadget quot ;
+
+: <cairo-gadget> ( dim quot -- gadget )
+    cairo-gadget construct-gadget
+        swap >>quot
+        swap >>dim ;
+
+M: cairo-gadget graft* ( gadget -- )
+    GL_BGRA >>format dup
+    [ dim>> 2^-bounds ] [ quot>> copy-cairo ] bi
+    >>bytes call-next-method ;
 
 ! maybe also texture>png
 ! : cairo>png ( gadget path -- )
index 889052c3857606dc8c2a479db8b5a96f6844153b..907233a335bf59ac96567c91ba29d4efce8a40ec 100644 (file)
@@ -4,6 +4,7 @@
 ! pangocairo bindings, from pango/pangocairo.h
 USING: cairo.ffi alien.c-types math
 alien.syntax system combinators alien
+memoize
 arrays pango pango.fonts ;
 IN: pango.cairo
 
@@ -111,9 +112,11 @@ M: pango-layout dispose ( alien -- ) alien>> g_object_unref ;
     0 <int> 0 <int> [ pango_layout_get_pixel_size ] 2keep
     [ *int ] bi@ ;
 
+MEMO: dummy-cairo ( -- cr )
+    CAIRO_FORMAT_ARGB32 0 0 cairo_image_surface_create cairo_create ;
+
 : dummy-pango ( quot -- )
-    >r CAIRO_FORMAT_ARGB32 0 0 cairo_image_surface_create
-    r> [ with-pango ] curry with-cairo-from-surface ; inline
+    >r dummy-cairo cairo r> [ with-pango ] curry with-variable ; inline
 
 : layout-size ( quot -- dim )
     [ layout pango-layout-get-pixel-size 2array ] compose dummy-pango ; inline