[cairo] Implementing cairo_read_func_t/cairo_write_func_t properly

Bernhard Fischer bf at abenteuerland.at
Sat Jan 2 11:16:17 PST 2016


On Saturday 02 January 2016 15:05:04 Enrico Weigelt, metux IT consult wrote:
> On 02.01.2016 12:35, Behdad Esfahbod wrote:
> >> Actually, I really wonder what that stream API is really for.
> >> Why not just let everything operate on an fd or directly mmap()
> >> the whole file ?
> > 
> > A very simple reason is language binding, or in general, hooking up to
> > other IO libraries (gio, etc).
> 
> hmm, what for, exactly ?
> 
> The application has to provide its own implementation for the callback
> anyways, so why doesn't it just load/mmap the file as it is and call
> the cairo's image loader then ?


Memory mapping (mmap()) and streaming (independently if buffered or on a file 
descriptor) are two completely different approaches.

Have a look at my code. It provides a cairo_...._mem() function which operates 
on a memory buffer, i.e. you can pass a memory region. This may be where ever 
in memory, hence, also a mmap()ed area.

To the functions cairo_..._stream() a callback function is passed. Thus it is 
up to the caller if you implemented this with direct io on a file descriptor 
(read()/write()) or with buffered io (fread()/fwrite()).

Bernhard



More information about the cairo mailing list