 ! one performs the cairo ops once and caches the bytes, the other
 ! performs cairo ops every refresh
 
-TUPLE: cairo-gadget width height quot cache? bytes ;
+TUPLE: cairo-gadget width height quot cache? texture ;
 PREDICATE: cached-cairo < cairo-gadget cache?>> ;
 : <cairo-gadget> ( width height quot -- cairo-gadget )
     cairo-gadget construct-gadget 

    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 ;

    [ cairo_image_surface_create_for_data ] 3bi
    r> with-cairo-from-surface ;

: cairo>bytes ( gadget -- byte-array )
    [ width>> ] [ height>> ] [ quot>> ] tri copy-cairo ;

: cairo>png ( gadget path -- )
    >r [ cairo>bytes CAIRO_FORMAT_ARGB32 ] [ width>> ]
