Skip to content

Cairo: Explore XLib backend #93

@tinchodias

Description

@tinchodias

Related to #92 and #91. There seems to exist a x11 backend for cairo, that allows user to create a platform-specific surface that I guess may be optimized, at least, for some scenarios: https://www.cairographics.org/manual/cairo-XLib-Surfaces.html

This is a demo: https://github.com/msteinert/cairo-demo/blob/master/cairo-demo-x11.c

To create a xlib surface, you need to provide a X's Display, a Drawable (a Window or Pixmap) and a Visual (a kind of image format). How to get them? SDL2 should provide it via the info structs.

As a preliminar test, I created a LibX11 as a duplicate of LibC but defined these methods:

unixLibraryName
	^ 'libX11.so'
defaultVisualOnDisplay: displayPointer screenNumber: screenNumber
	^ self ffiCall: #("Visual"void *XDefaultVisual("Display"void *displayPointer, int screenNumber))
displayWidthOf: displayPointer screenNumber: screenNumber
	^ self ffiCall: #(int XDisplayWidth("Display"void *displayPointer, int screenNumber))
displayHeightOf: displayPointer screenNumber: screenNumber
	^ self ffiCall: #(int XDisplayHeight("Display"void *displayPointer, int screenNumber))

The width and height were right, when executed on a Workspace:

w := SDL_Window allInstances detect: [ :each | each isNull not ].
wmInfo := SDL_SysWMinfo new version: SDL_Version bindingVersion.
w getWMInfo: wmInfo.
window := wmInfo info x11 window.
display := wmInfo info x11 display.
LibX11 uniqueInstance displayWidthOf: display screenNumber: 0. "1366"
LibX11 uniqueInstance displayHeightOf: display screenNumber: 0. "768"
visual := LibX11 uniqueInstance defaultVisualOnDisplay: display screenNumber: 0.

This should be enough to try the cairo-xlib surface create function.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions