Commit graph

100 commits

Author SHA1 Message Date
John Nunley
c2ec494336
feat: Enable creating an X11 display without connection
For pure-Rust connections, there is no XCB connection that can be passed into
the display constructor. Thus, this PR enables the display to be created without
needing an XCB or Xlib handle, by providing `None` in the constructor.

cc rust-windowing/raw-window-handle#120

Signed-off-by: John Nunley <dev@notgull.net>
2023-11-01 22:26:10 -07:00
Ian Douglas Scott
3b98da7e28
x11: dup fd before passing to shm_attach_fd
This function takes `Into<RawFdContainer>`. So it accepts an owned fd,
and closes it. So as long as the API is like this, we need to dup a new
fd it can close when calling it.

`Into<RawFdContainer>` is implemented for anything implementing `IntoRawFd`,
so passing `OwnedFd` works.

Fixes https://github.com/rust-windowing/softbuffer/issues/168. Should be
backported to 0.3.x.
2023-10-31 07:09:50 -07:00
Liam Murphy
2eef592745
docs: Fix missing paragraph break in the docs for Buffer 2023-10-29 07:54:05 -07:00
John Nunley
0bcd2e22a2
breaking: Use raw-window-handle version 0.6
Signed-off-by: John Nunley <dev@notgull.net>
Co-Authored-By: dAxpeDDa <daxpedda@gmail.com>
2023-10-26 19:15:51 -07:00
John Nunley
c0e8723081
x11: Use POSIX shared memory in X11 backend
The X11 backend used System-V shared memory to communicate shared
buffers to the server, but rustix does not support SysV SHM so we had to
use libc in this backend. However, there is an alternate X11 API which
uses POSIX shared memory, which rustix does support. This PR switches
the X11 backend to POSIX shared memory and purges the previous
usages of libc.

The goal is to remove libc totally. Therefore this PR also removes the
default libc dependency from rustix.

Signed-off-by: John Nunley <dev@notgull.net>
2023-10-17 19:15:15 -07:00
Ian Douglas Scott
d0d3881099 Use rustix/libc instead of nix
Partly addresses
https://github.com/rust-windowing/softbuffer/issues/147, though it would
still be desirable to have a good safe API for SYSV shm in Rustix. But
using `libc` directly for now is no worse than using the `nix::libc`
re-export, so we don't lose anything.
2023-10-13 15:54:32 -07:00
Ian Douglas Scott
ea81ff2078
Merge pull request #163 from rust-windowing/update-deps
Update `drm`, `nix`, and `criterion` dependencies
2023-10-13 13:54:00 -07:00
Ian Douglas Scott
e667df2da6 Update drm and nix dependencies 2023-10-13 08:42:30 -07:00
Benoît Cortier
9736fe9e37
docs: present_with_damage is supported on web platform 2023-10-13 08:32:21 -07:00
Ian Douglas Scott
36618b63eb
Merge pull request #149 from rust-windowing/update-wayland
wayland: Update to wayland-client 0.31
2023-09-09 16:42:57 -07:00
Benoît Cortier
908408ba80
fix(web): optimize and fix present_with_damage (#150)
Co-authored-by: daxpedda <daxpedda@gmail.com>
2023-09-09 17:30:38 +02:00
Ian Douglas Scott
a9d7e159e0 wayland: Update to wayland-client 0.31
Updates `rust-version` from 1.64 to 1.65.
2023-09-07 19:12:01 -07:00
Simon Hausmann
9b44f2eaea
bugfix: Fix length of returned buffer on x11 when using the wire-transferred buffer
total_len() computes the number of bytes, while the wire Vec holds u32.
2023-09-06 08:05:17 -07:00
Ian Douglas Scott
1770b331bf orbital: Use syscall::MAP_SHARED for mapping
This seems to be required to work correctly since
https://gitlab.redox-os.org/redox-os/orbital/-/merge_requests/51.

Orbclient had a similar change:
9097e71c9a.
2023-08-16 18:59:40 -07:00
John Nunley
ac0b7f5e14
feat: Add a DRM/KMS backend
This adds a DRM/KMS based backend to the system, as per #42. This system finds a CRTC and a connector, then uses that to create a frame buffer and a DUMB buffer that it can render to.

There's much more to do, and is left as an exercise for anyone with a significant DRM-based use case to pick up and fix.

Signed-off-by: John Nunley <dev@notgull.net>
2023-08-12 13:39:13 -07:00
John Nunley
2689cec2ca
bugfix: Mark fetch as unsupported on Windows for now
This fetch function has been broken and is probably unsound. This also
fixes the flakey Windows CI that we've been dealing with.

Signed-off-by: John Nunley <dev@notgull.net>
2023-08-10 19:28:04 -07:00
Ian Douglas Scott
e10c360929 cg: Require non-zero width/height; panic instead of segfault
Fixes https://github.com/rust-windowing/softbuffer/issues/124.
2023-07-24 18:24:23 -07:00
Fenhl
1f326b2199
bugfix: Reintroduce Error trait impl for SoftBufferError 2023-07-12 18:43:49 -07:00
John Nunley
abb7a4e9ac
version: Use fastrand v2.0.0 2023-07-03 07:59:34 -07:00
John Nunley
3404953bdb
m: Use tiny-xlib instead of x11-dl
My new tiny-xlib crate takes up a fraction of the space that the x11-dl crate uses, supports
feature-based static linking and involves less of Xlib's ridiculous surface.
2023-07-02 15:08:01 -07:00
dAxpeDDa
6c78268502 Implement OffscreenCanvas support 2023-06-05 01:39:28 +02:00
John Nunley
7b089d46b2
Remove the thiserror dependency (#116) 2023-06-03 07:08:35 -07:00
Ian Douglas Scott
1e7b9213d2 Merge remote-tracking branch 'origin/master' into damage 2023-06-02 15:03:10 -07:00
John Nunley
44248477be
feat: Add a function for retrieving the window contents
This function is useful for testing the window contents in certain cases. In addition,
this means that we can now have reliable tests for softbuffer's actual functionality.

Signed-off-by: John Nunley <jtnunley01@gmail.com>
Co-authored-by: dAxpeDDa <daxpedda@gmail.com>
2023-06-01 20:09:30 -07:00
Ian Douglas Scott
591a40c0a6 Fix doc link 2023-05-30 15:36:14 -07:00
Ian Douglas Scott
a147a15d45 Use u32/NonZeroU32 for Rect, and return error if out of range 2023-05-30 15:27:59 -07:00
Ian Douglas Scott
199a016f44 Merge remote-tracking branch 'origin/master' into damage 2023-05-30 14:25:45 -07:00
daxpedda
fcda747ddf
Add from_canvas() to Surface for Wasm (#76)
Co-authored-by: Toniman575 <toniman575@gmail.com>
2023-05-08 15:43:34 +02:00
daxpedda
d7888ef806
Implement present_with_damage for Web (#101) 2023-04-27 10:19:29 -07:00
Ian Douglas Scott
29b3f4a978 Add a Buffer::age() method
Fixes https://github.com/rust-windowing/softbuffer/issues/90.
2023-04-26 15:04:20 -07:00
Ian Douglas Scott
c1d6716eec Add a Buffer::present_with_damage() method
Supported on Wayland, X11, and Win32.

Fixes https://github.com/rust-windowing/softbuffer/issues/39.

try_for_each
2023-04-26 11:58:11 -07:00
Luna
5efa5d8898 x11: Assert that size >= buffer_size 2023-04-24 20:31:39 -03:00
Luna
c68f41bf10 x11: Limit returned shm buffer size 2023-04-24 19:37:41 -03:00
John Nunley
92e8eb7d22
Don't use the borrowing trick under Windows (#89) 2023-04-07 17:31:21 -07:00
John Nunley
885c76bf02
m: Don't use the borrowing trick under X11 (#86) 2023-04-07 11:54:50 -07:00
jtnunley
74a3357ce8 Use the SwResultExt trait in more places 2023-04-06 11:09:47 -07:00
John Nunley
379910cb8e
Merge pull request #77 from daxpedda/wasm-atomics
Fix multi-threaded Wasm
2023-04-06 10:40:23 -07:00
Ian Douglas Scott
7a687105e3 Update windows-sys and image 2023-04-06 08:37:57 -07:00
dAxpeDDa
c0af587718
Fix multi-threaded Wasm 2023-04-06 17:35:14 +02:00
Ian Douglas Scott
a09e4cf679
Owned pixel buffer for no-copy presentation
This is based on the API that will be used for no-copy presentation. But
wraps it in `set_buffer`.

This also fixes the Wayland buffer code to set `self.width` and
`self.height` on resize, and set the length of the shared memory file
when the buffer is created.

Co-authored-by: jtnunley <jtnunley01@gmail.com>
2023-04-06 10:30:59 +03:00
Ashley Wulber
0bdbf1a752
fix: update width and height when resizing buffer 2023-01-22 22:23:44 -05:00
Simon Hausmann
4c6631c764 mac: retain the NSWindow to ensure that the call to retrieving the backing scale factor in set_buffer works 2023-01-15 17:04:57 +01:00
Simon Hausmann
2832a6e42b mac: Fix layer scale not being updated when contents is updated and window is on a new screen
cc #67
2023-01-15 09:12:28 +01:00
John Nunley
33a4c3741b
m: Cache document in web frontend (#66) 2023-01-14 05:48:44 +00:00
Ian Douglas Scott
129069996e Split GraphicsContext into Context and Surface
A `Context` is created with a display handle, and a `Surface` is created
with a `&Context` and a window handle. Thus multiple windows can be
created from the same context without duplicating anything that can be
shared. This API is broadly similar to `wgpu` or `glutin`.

On Wayland, the `Context` contains the `EventQueue`, which is shared
between windows, and the `WlShm` global. On X11, `Context::new` checks
for the availability of XShm, and contains a bool representing that as
well as the `XCBConnection`. The shared context data is stored within
the window in an `Arc`.

On other platforms, the display isn't used and `Context` is empty. This
does however test that the display handle has the right type on those
platforms and fail otherwise. Previously the code didn't test that.

Closes https://github.com/rust-windowing/softbuffer/issues/37.
2023-01-06 21:36:53 -08:00
Jeremy Soller
c0142e9faf
Merge pull request #59 from thedjinn/disable-calayer-actions
Disable CALayer fade action when setting buffers
2023-01-06 09:06:51 -07:00
Ian Douglas Scott
165a15e92c wayland: Seal memfd to prevent shrinking
I believe this should be possible wherever `memfd_create` is available.

Sealing isn't required, but Wayland doesn't allow a client to shrink an
shm pool, so there's no reason we should shrink the file. And if we mmap
the file, this prevents a `SIGBUS` if the compositor (incorrectly)
shrunk it.

So we might as well do this.
2023-01-06 07:52:59 -08:00
John Nunley
a6042f664d
x11: Implement image transfer using the MIT-SHM extension (#46)
* Implement shared memory transfer for X11

* Change to x11rb

* Fix leak + review from psychon

* Add waits to prevent illegal writes to SHM

* @ids1024 code review
2023-01-05 19:27:54 -08:00
Emil Loer
b72055d122
Disable CALayer fade action when setting buffers
This commit fixes a bug in the Core Graphics backend that causes a new
buffer not be shown immediately but instead use a quarter second fade
transition. This happens because the CALayer has a default action
associated with a change in the layer contents.

The problem was mitigated by wrapping the contents change in a
transaction and disabling all actions for the duration of this
transaction.
2023-01-05 22:17:10 +01:00
Jeremy Soller
13853fe967
Merge pull request #54 from ids1024/bsd
Add support and CI tests for BSDs
2023-01-04 07:04:37 -07:00