Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cairo: Explore XLib backend #93

Open
tinchodias opened this issue Feb 19, 2025 · 1 comment
Open

Cairo: Explore XLib backend #93

tinchodias opened this issue Feb 19, 2025 · 1 comment

Comments

@tinchodias
Copy link
Contributor

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.

tinchodias added a commit that referenced this issue Feb 19, 2025
@tinchodias
Copy link
Contributor Author

I added a draft demo of the surface working in a branch that has "93-" as prefix.

It worked on my Debian with wayland. It draws directly to the main window. It doesn't make sense to invest time on this right now. To draw on a separate image (not the window), we should implement 2 functions: https://tronche.com/gui/x/xlib/pixmap-and-cursor/pixmap.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant