[cairo] Can someone explain a little bit more the api to me?

David Trallero Mena ditiem at gmail.com
Sat Feb 4 04:16:59 PST 2006


Hi guys,

   I am completely new nebie trying to use the Cairo API. I want
to draw some stuff on X-window server, so what I have done (after
reading some code from the cairo tests set):


   // VIDEO MEMORY
   /////////////////

   // Create the Surface
   m_surface = cairo_xlib_surface_create( m_dpy,
					 m_drawable,
					 DefaultVisual(m_dpy, m_screen),
					 m_XL, m_YL ) ;

   m_cr = cairo_create( m_surface ) ;

   // Associate an image memory map to the surface
   m_vmem_surface = cairo_image_surface_create_for_data( m_video_mem,
						 CAIRO_FORMAT_RGB24,
							m_XL, m_YL,
							m_XL * 4 ) ;
   m_vmem_cr      = cairo_create( m_vmem_surface ) ;

   cairo_set_source_surface( m_vmem_cr, m_surface, 0, 0 ) ;


SO, this is what it does not match to me:

1.- Why 2 surfaces: m_surface and m_vmem_surface? The 1st one is the
backend (driver) and the second one the memory of the backend?

2.- The only way I have achieved to draw something is using m_cr in
cairo painting functions (move_to, arc, set_color...) and using
m_vmem_cr with ciaro_paint function. Is this correct? If it is, why not
using m_cr in cairo_paint???

Second, I want to create another "image-surface", i.e., a surface to
paint in a memory map, so what I did (deduced from reading the API
manual) is:

  m_select_surface = cairo_image_surface_create( CAIRO_FORMAT_RGB24, 
m_XL, m_YL) ;
   m_scr = cairo_create( m_select_surface ) ;

but if I use m_select_surface in cairo_set_source_surface (because I 
undestand the unique difference between cairo_image_surface_create and
cairo_image_surface_create_for_data is that you have access to the
memory map) I see nothing :(. Is this normal?

What am I doing wrong? I miss a tutorial explaining the basic concepts,
but I found nothing. If you please guys could tell me some link for a 
tutorial (not with GTK, because it hides from me the initialization of 
the surfaces that is what I want to study) I will really appreciate.

Thanks a lot,
David


More information about the cairo mailing list