-
Notifications
You must be signed in to change notification settings - Fork 42
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
expose cairo_image_surface_create_for_data #252
base: master
Are you sure you want to change the base?
Conversation
Example of use (for any user who lands here): const width = 16, height = 16
const buf = new Uint32Array(width * height)
// set pixels to a greenish color
buf.fill(0x22AA00)
// create an ImageSurface operating on buf
const surface = Cairo.ImageSurface.createForData(buf, Cairo.Format.RGB24, width, height, width*4)
// make sure the buffer doesn't get destroyed while surface is alive
surface.buffer = buf |
Yes, that's fine, node-gtk already exposes a lot of low-level stuff, calling a C library comes with C responsabilities :) OTOH it would be possible to add an override for And the use-case makes sense, I can't remember why I left out the function when I did the cairo bindings. Sorry you had to go through the JS generators btw, it's a bit messy but Cairo isn't GObject-introspected so essentially it's a second set of bindings just for cairo -_- One thing, can you add a test for this use-case in tests/cairo/surface.js? The example with comments you have right there would do just fine, tests are a nice way to document API usage. Travis isn't linking to GH again so here is the link for CI: https://travis-ci.org/github/romgrk/node-gtk/builds/753106331 |
Don't worry! Fortunately it only needed a small change :)
Retaining a reference to the backing buffer would be a good option, yes. On the Node.js side this makes sense, backing buffers AFAIK should own their memory and manage its lifetime. But to do this correctly (since other things can hold a reference to the surface in addition to our bindings), we should attach the reference to the surface itself. According to the docs we should use
Will do! |
Unfortunately I haven't set up C++ overrides. For Cairo however it's possible to add an hand-written methods in the automatically-generated bindings (example). There is no mechanism in place to preserve those modifications if the generators are run again but they're rarely run and I just discard the git diff manually for those regions when I do. |
rendering works perfectly, keyboard input works perfectly, it's lightweight, and I'm happy NOTE: this depends on romgrk/node-gtk#252
716d97f
to
70411b3
Compare
node-gtk is really great, thank you 💙
AFAIK, the only current way to create an ImageSurface is from a PNG, and it has to be a file in the disk.
This PR exposes the
cairo_image_surface_create_for_data
function.I would be really grateful if we could make it happen, since that would allow:
The function is low-level (the user is responsible of allocating a large enough buffer for their width, height & format; the user is responsible of holding that buffer alive as long as the image surface is used; etc.)