Using cairo with GTK

  1. How do I use cairo to draw in GTK applications?

    Use gtk_snapshot_append_cairo() in your GtkWidgetClass.snapshot() vfunc to obtain a cairo context and draw with that.

  2. Can I improve the performance of my application by using another backend of cairo (such as GL)?

    No. Most drawing in GTK is not done via cairo anymore (but instead by the GL or Vulkan renderers of GSK).

    If you use cairo for drawing your own widgets, gtk_snapshot_append_cairo() will choose the most appropriate surface type for you.

    If you are interested in using GL for your own drawing, see GtkGLArea.

  3. Can I use cairo to draw on a GdkPixbuf?

    No. The cairo image surface does not support the pixel format used by GdkPixbuf.

    If you need to get cairo drawing into a format that can be displayed efficiently by GTK, you may want to use an image surface and gdk_memory_texture_new().