[gtkada] GTK and GTKAda

Ludovic Brenta ludovic.brenta at insalien.org
Sat May 15 00:16:37 CEST 2004


"Andrew Carroll" writes:
> What does the method that draws the Frame contain?  If I wanted to
> create my own "Windows" wouldn't it be a bunch of methods like
> OpenGL 2D (if there is such a thing)?

Something like that, except not open; each operating system has its
own set of graphics primitives, the low-level implementation of which
is delegated to the device driver for the particular graphics card.
Windows has such a set of graphics primitives.

> GtkAda [...] has to "interface" with the native windows for Gtk, and
> then again, with the Ada syntax it has to interface with Gtk to make
> GtkAda.  Would that make GtkAda slower than Java?  It's a pointer to
> a pointer that points to function right?  Each of those references
> has to be dereferenced before they can be used.  That's a lot of
> overhead.

Not really; when you declare an Ada subprogram with pragma Import (C,
...) the pointer to the imported subprogram is known at link time; I
believe this causes in the first dereference (GtkAda to GTK+) to occur
at link time.  The other dereference (GTK+ to the OS-level graphics
primitive) would also occur at link time.  In the case of dynamic
linking (with DLLs) this link time normally occurs once, when the
program is first launched.

Now there is indeed some overhead if GtkAda has to marshal and
unmarshal arguments passed to and from the windowing system.
Marshalling and unmarshalling means converting the data from the
Windows format and the Ada format.  In most cases, this conversion is
trivial and is a no-op in microcode (e.g. converting between an
Interfaces.C.char and a Character, maybe also from
Interfaces.C.char_array to a String with known bounds).

So I wouldn't worry too much about the overhead.  Any overhead there
is is likely to be good for you, as it corresponds to Ada's constraint
checks.

> Then I started thinking about the Java AWT toolkit.  It's not
> native, but they have the 'class' Window.  How do they do that?  Is
> a window just a bitmap with layers of other bitmaps and transparent
> bitmaps with text?  How does this all work?  More importantly, where
> do I find out?

They expose a Java interface (class Window) and implement it using the
Java Native Interface.  This is Java's equivalent of Ada's pragma
Interface (C), except that it requires the C language DLL to export
functions with special Java-friendly names.  This is because JNI
cannot specify the link name of the imported functions; only their
Java name.  As a result, Java requires an intermediate "glue" DLL that
exposes Java-friendly functions that, in turn, call the operating
system's graphics primitives.  This additional overhead is probably
also resolved at link time.

> Never the less, I chose GtkAda mainly because I can compile for both
> Windows and FreeBSD and will keep the benefits of Ada as a system.
> but I am still curious as to how a Window is actually drawn.  Is it
> just like a curses window except with finer detail and control?

Basically, yes.  You normally would write a curses program as you
would a window proram: a loop that polls for key presses and generates
events from them, then a kind of finite state machine that handles
events and issues commands to redraw part of the screen.

In windowing systems, the system generates the events for you; you
cannot poll for key presses by reading standard input or the console
anymore.  Instead, you have a loop that polls for events from the
windowing system and handle events as they arrive.  There are very
many events; each time the mouse moves by one pixel there is an event.

GtkAda hides this polling loop from the programmer.  All you have to
do is register handlers for events, called "signals" in GtkAda.

> Well, thanks for letting me ramble and ask some questions.  If you
> understand anything I said and have some answers then hopefully you
> will not mind sending me some links or something so that I can learn
> more.  Thanks all!!!

For your time keeping app, maybe you may want to just port GTimer to
GtkAda.  You'll get the job done quicker and learn GtkAda in the
process.  GTimer is a simple GTK+ 1.2 app; I have ported it to GTK+
2.0 and I can send you the patch if you want.  It's not big.

-- 
Ludovic Brenta.




More information about the gtkada mailing list