Questions about map and unmap image surface

Carlos López González <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <CAF52pz+F28qrvkoxLqnXajbcYeLmvrt+TjLc9=9qyW6vcZZO2w@mail.gmail.com>
Hi!
I'm learning to use Cairo libraries and I have a doubt related to
cairo_surface_map_to_image() and cairo_surface_unmap_image().
Say I have a generic cairo_surface_t created by one custom function.
Also I have another cairo_surface_t* to hold the image surface type.
I make initially cs_image NULL to don't use it if not initialized.
Then as I want to make direct operations on the surface I've created
two custom functions map_cairo_image() and unmap_cairo_image():

////CODE

cairo_surface_t* cs(get_cairo_surface());
cairo_surface_t* cs_image(NULL);
bool
map_cairo_image()
{
	if(cs==NULL) return false;
	cairo_surface_flush(cs);
	cs_image=cairo_surface_map_to_image (cs, NULL);
	if(cs_image_!=NULL)
	{
		cairo_format_t t=cairo_image_surface_get_format(cs_image_);
		// I only can modify two types of image formats
		if(t==CAIRO_FORMAT_ARGB32 || t==CAIRO_FORMAT_RGB24)
		{
			//cairo_surface_flush(cs_image); // (**)
			unsigned char* data(cairo_image_surface_get_data(cs_image));
			int w(cairo_image_surface_get_width(cs_image));
			int h(cairo_image_surface_get_height(cs_image));
			int stride(cairo_image_surface_get_stride(cs_image));
			// this function passes the data, w, h and stride to a custom surface that
			// allows to directly manipulate the data values.
			set_wh(w, h, data, stride);
			return true;
		}
		return false;	
	}
	return false;
}

void
unmap_cairo_image()
{
	assert(cs_image);
	assert(cs);
	cairo_surface_mark_dirty(cs_image);
	cairo_surface_unmap_image(cs, cs_image);
	cairo_surface_mark_dirty(cs); // (*)
}
//////// END CODE

My questions are:

(*) Is it needed to mark dirty cs too? Doesn't the unmap operation
mark dirty the receiving surface?
(**) Also I think that I don't need to call
cairo_surface_flush(cs_image);
before
unsigned char* data(cairo_image_surface_get_data(cs_image));
Is that right?

At this moment I can't test the code because the code change is quite
complex and I cannot make it work without finish it completely. But I
need to know if I'm doing things well.
Thanks!

-- 
Carlos
http://synfig.org
-- 
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.