navit-project.org
http://forum.navit-project.org/

Why do some OSD items use an "overlay" for drawing?
http://forum.navit-project.org/viewtopic.php?f=14&t=539
Page 1 of 1

Author:  sleske [ 29 Nov 2014, 15:58 ]
Post subject:  Why do some OSD items use an "overlay" for drawing?

Some OSD items use an "overlay" for drawing: Instead of being drawn directly, they seem to create a special buffer to draw into. The item is then drawn into that buffer, and the buffer in turn is drawn into the main window.

The graphics system has the method graphics_overlay_new to make this possible. The OSD code uses this from osd_set_std_graphic, which is used by the _init methods of some OSD items (e.g. by toggle_announcer_init).

However, not all OSD items use this "overlay" mechanism. Some (at least "button" and "scale") even let you select whether to use it or not through the attribute "use_overlay".

What I dont quite understand is: Why this is even used?

It makes the code considerably harder to understand, and it does not seem to work properly: The OSD button does not render its image correctly with use_overlay=1, and the bug #1270 also seems to be caused by the toggle_announcer using an overlay.

So: What is the point of this mechanism?
I'd be grateful for any pointers/explanations.

Author:  tryagain [ 29 Nov 2014, 22:40 ]
Post subject:  Re: Why do some OSD items use an "overlay" for drawing?

Hi!

I see the only purpose for use_overlay option: it makes possible to hide OSD elements drawn with this option while moving the map bitmap.

By default navit attempts to re-render the map from its vector representation on each move, and it may take a few seconds on certain regions with certain layouts, so becoming non-interactive. When there's an option drag_bitmap="1" specified in <navit> element, movements are drawn by displaying the main overlay bitmap at different offsets.

So OSDs drawn into the only existing overlay (i.e. do not enable use_overlay), are moved with the map, which looks unnatural. OSDs drawn with use_overlay simply disappear till the map is completely redrawn after dragging finishes.

My guess is that use_overlay option was introduced when it became clear that some navit graphics modules do not fully support overlay mode.

tryagain

Author:  sleske [ 30 Nov 2014, 15:40 ]
Post subject:  Re: Why do some OSD items use an "overlay" for drawing?

tryagain wrote:
Hi!
I see the only purpose for use_overlay option: it makes possible to hide OSD elements drawn with this option while moving the map bitmap.


Interesting, thanks for the information. I didn't know navit even supported moving the map bitmap instead of redrawing it.

Still, I wonder: Couldn't you get the same result more easily by just redrawing the map without the OSD items when dragging starts? I'll have a look at the code to figure out what exactly it is doing.

Incidentally, I just found out that if you comment out the line
Code:
graphics_overlay_disable(this_->gra, 1);

in navit.c:navit_motion_timeout and enable bitmap_drag, then the overlay OSD items will actually stay in place while the map moves "underneath". This may have been the original motivation for using overlays. Still, I wonder why overlays are currently disabled during panning.

Author:  sleske [ 22 Dec 2014, 22:46 ]
Post subject:  Re: Why do some OSD items use an "overlay" for drawing?

Reading some more Navit code, and GTK+/GDK docs, I think I now understand why these "overlays" are used.

The OSD items are supposed to be (partially) transparent, so the map is still visible underneath. However, GTK+/GDK do not support transparency - mainly because they are (or were originally) closely modeled on the X11 protocol, which does not support transparency either.

The only way to use (limited) transparency is to put the desired graphics into a GdkPixbuf (which does support transparency), then draw that - which is just what the code does.

So the "overlay" trick is only to make transparent OSDs possible.

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/