     [ cairo_image_surface_create_for_data ] 3bi
     r> with-cairo-from-surface ;
 
-: (cairo>bytes) ( gadget -- byte-array )
+: cairo>bytes ( gadget -- byte-array )
     [ width>> ] [ height>> ] [ quot>> ] tri copy-cairo ;
-
-GENERIC: cairo>bytes
-M: cairo-gadget cairo>bytes ( gadget -- byte-array )
-    (cairo>bytes) ;
-
-M: cached-cairo cairo>bytes ( gadget -- byte-array )
-    dup bytes>> [ ] [
-        dup (cairo>bytes) [ >>bytes drop ] keep
-    ] ?if ;
 
 : cairo>png ( gadget path -- )
     >r [ cairo>bytes CAIRO_FORMAT_ARGB32 ] [ width>> ]

    cairo_image_surface_create_for_data
    r> [ cairo_surface_write_to_png check-cairo ] curry with-surface ;

M: cairo-gadget draw-gadget* ( gadget -- )
    origin get [
        0 0 glRasterPos2i
        1.0 -1.0 glPixelZoom
        [ width>> ] [ height>> GL_BGRA GL_UNSIGNED_BYTE ]
        [ cairo>bytes ] tri glDrawPixels
    ] with-translation ;
    
M: cairo-gadget pref-dim* ( gadget -- rect )
    [ width>> ] [ height>> ] bi 2array ;

! See http://factorcode.org/license.txt for BSD license.
USING: cairo cairo.ffi ui.render kernel opengl.gl opengl
math byte-arrays ui.gadgets accessors arrays 
namespaces io.backend memoize ;

IN: cairo.gadgets

