How is Cairo related to GDK?

1.2k views Asked by At

What exactly is the function of the GDK library and how does Cairo fit in? Are they competing or complementary technologies? Does one of them depend upon the other in any way?

2

There are 2 answers

2
lvella On BEST ANSWER

Cairo is the drawing backend used by gdk.

0
sleske On

TL;DR:

In recent versions, GDK is the platform abstraction layer for GTK+. It also offers some platform integration for Cairo (for example for showing images created using Cairo), but is otherwise independent from it.

Longer version:

GDK started out as a wrapper around Xlib, the client library for the X Window System. It supported all the parts of the X Windows API that GTK+ needed, including drawing operations.

When GTK+ was ported to other windowing systems (like Windows), GDK evolved into a platform abstraction layer. It then turned out that the drawing API "inherited" from Xlib was problematic - it made porting difficult, and was limited (for example, little support for transparency). Thus the drawing functionality of GDK was deprecated, and removed in GTK+ 3 (see Migrating from GTK+ 2.x to GTK+ 3: Use cairo for drawing).

So GDK started out as a platform abstraction layer including a drawing backend. In recent versions, Cairo is the drawing backend used by GTK+, and GDK exists alongside Cairo, to handle platform aspects like window creation and input handling.

GDK has some functions that use Cairo, but these are only to allow interoperation with Cairo. For example, gdk_cairo_create () lets you create a Cairo surface for a window that allows drawing to that window using Cairo.