[RFC] Separation of renderers and map sources



While working on the new map loading mechanism, I've noticed one more
thing I didn't like. Basically every map source has to know how to
interpret the data it is dealing with. For instance, the network tile
source has to know that the data it is downloading are PNG images and
the cache has to know this as well when fill_tile() is called on it in
order to draw the tile correctly. What if some web sites start storing
the tiles as jpg's?

This problem became even more apparent when I started changing the
memphis map source - it defines two new data sources - to load the
data from the network (basically duplication of network tile source
code) and from files. I can also imagine that we would want to cache
the xml's with vector data that are loaded from the network (e.g. to
be able to re-render the tiles with different rendering options) so we
would need one more different cache for that.

This leads to the following calculation - for M sources of map data
and N formats, with the current architecture we need totally M * N map
sources.

For libchamplain 0.8 I would propose to separate renderers (the part
of the code that transforms raw data into tiles) from map sources
(which would become sources of raw data without knowing what this data
represents).

In principle, the renderers would have one main function:

bool render_tile(tile, data, data_size)

where data is byte sequence, data_size is number of bytes and the
function would call set_content() on the tile when it renders the tile
successfully (if there is some problem, it returns FALSE). Every map
source would have exactly one map renderer assigned. In its
fill_tile() function it would get the raw data from network/local
file/cache and pass the data to render_tile() of the assigned tile
renderer. This way we would have M map sources and N renderers only
without the need to create M * N different map sources.

What would have to be done (slightly simplified description):
* the png rendering code from network tile source and cache would be
moved to png_renderer class (quite trivial, png rendering is done by
GTK)
* transform memphis_tile_source to memphis_tile_renderer - this means
to remove all the stuff that deals with caches and data sources and
make some other minor modifications
* remove network_map_data_source - we have the code in
network_tile_source already
* transform local_map_data_source to file_tile_source - a map source
that loads its data from a single file
* for interface purists, split error_tile_source into null_map_source
(map source that doesn't load data from anything and passes no data to
the renderer) and error_tile_renderer (takes this nothing and
generates error tile from it)

I think that the amount of changes needed is much smaller than what
I've done to introduce the loading chains. Also some helper function
can be added to make the interface look the same way as before for the
existing applications. Well, and of course, proposing this means that
I would implement this, which I hope is a good news as well :-).

Comments?

Jiri


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]