Re: Building multiple backends on on same system

On Wed, 2010-11-24 at 08:46 -0500, Matthias Clasen wrote:
> On Wed, Nov 24, 2010 at 7:28 AM, Alexander Larsson <alexl redhat com> wrote:

> > In my opinion we should move all the supported public entrypoints to the
> > core gdk library and make the backend a loadable module. I'm not sure
> > how exactly we should expose e.g. the X specific stuff, but I think it
> > would be doable with some kind of loose coupling like an interface.
> >
> Yes, something along these lines needs to happen.

I've started looking at this a bit. Here is how I think it should work:

Support specifying multiple targets in --with-gdktarget, then build a
single supporting all of these, switching at runtime. At
one time i was thinking we could load the backends dynamically to avoid
linking to all the dependencies of all backends, but since cairo links
in all backends in the same library anyway this will not work.

We then have a gtk+-3.0.pc file that does not pull in any backend
libraries (like xlib) into the app. The we add e.g. gtk+-x11-3.0 that
contains the backend specific headers like gdkx.h, the backend libraries
and headers. This file would be installed only if gtk+ was built with X
support of course.

Then we take the current internal defines like GDK_WINDOWING_X11 and put
the supported ones in a public header, so that apps can build
conditional backend support. Additionally we now allow multiple of these
to be defined in the same build.

Then we add a GdkBackend type that each backend implements. This is a
singleton created at init to hang global stuff off. Its also useful for
backend specific code. For instance:

  if (timestamp != GDK_CURRENT_TIME)
    gdk_x11_window_set_user_time (gdk_window, timestamp);

Will turn into:

   if (GDK_IS_BACKEND_X11 (gdk_backend_get ()))
      if (timestamp != GDK_CURRENT_TIME)
	gdk_x11_window_set_user_time (gdk_window, timestamp);

Or suchlike, where the GdkBackendX11 type is specified in the gdkx.h

Additionally, I think we should drop and just combine the two
into one. There are no users of gdk without gtk anyway, and gtk has
backend specific code in it anyway, so gdk is not a full abstraction.
This will get us one less library, plus it will make all gdk calls from
gtk+ intra-object calls which is a (minor) performance gain.

The road to this looks something like this:

* Hide the class structs for all backend-implemented object types
(GdkDisplay, GdkDevice, etc) to let us change the internals later.

* Convert all backend object method calls to true vtable calls, rather
than have the linker pick the right one. (For instance,
gdk_device_ungrab() is right now duplicated in each backend, and relies
on the linker to pick the one from the backend you link with. Obviously
this will not work in a multi-backend scenario, instead we need a single
gdk_device_ungrab() call in the common code that does a vcall on the
GdkDevice class.)

* Convert GdkCursor to a GObject so we get a class vtable

* (Optionally) move code common to all backends (for instance,  
  typechecks, etc) from the backend code to the common code that does
  the vtable call.

* Add a GdkBackend type, derive from this in all backends

* Convert all global functions (both external and gdk internal ones) in
  the backend to vtable calls on the backend object.

* Now we should have no globally accessible symbols in the backends, so 
  change the makefiles to allow multiple backends to be build, picking
  one of the supported on on init based on e.g env vars.

* Fix gtk to do runtime checks as well as compiletime checks for backend
  specific code.

* Profit

All this is pretty boring grunt-work. I've started to do some vtable
conversions in the gdk-backend branch, and I will keep chugging on this,
but my time is quite limited. If anyone wants to help out, pick some
class and start converting (just sync on the list to avoid duplication).

 Alexander Larsson                                            Red Hat, Inc 
       alexl redhat com            alexander larsson gmail com 
He's an all-American moralistic dwarf on the edge. She's an orphaned 
thirtysomething former first lady from a secret island of warrior women. They 
fight crime! 

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