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

Add Buffer::present_with_damage() and Buffer::age() #99

Merged
merged 7 commits into from
Jun 3, 2023
Merged

Conversation

ids1024
Copy link
Member

@ids1024 ids1024 commented Apr 21, 2023

#39.

Implemented only for Wayland. Should be able to add an X implementation using XDamage, but I haven't looked at how that works yet. On web we could use this to update only the changed part of the canvas possibly. If we need to convert the format anyway. I don't see any API for damage that could be used on macOS or Windows.

Also should be tested in some way.

@ids1024 ids1024 force-pushed the damage branch 2 times, most recently from c42958f to 71ae6df Compare April 24, 2023 21:09
@ids1024
Copy link
Member Author

ids1024 commented Apr 25, 2023

https://www.x.org/releases/X11R7.7/doc/damageproto/damageproto.txt

Damage is automatically computed by the X Server for X rendering operations,
but direct rendering extensions have allowed clients to perform rendering
outside of the control of the X Server. The 1.1 version of the protocol
added a request to allow direct rendering clients to report damage to a
drawable.

If we're using put_image/shm_put_image, we're not doing "direct rendering" (like a DRI based OpenGL client), and those calls already report damage to region we "put" to? And I don't see a way to disable that damage reporting.

So I guess on X, we'd not use XDamage here, but could call put_image/shm_put_image once per damage rectangle, with different src_x/src_y/dest_x/dest_y/width/height arguments?

@ids1024
Copy link
Member Author

ids1024 commented Apr 26, 2023

Yep, iterating over rects and calling X11_XShmPutImage or X11_XPutImage is what SDL's X11_UpdateWindowFramebuffer does.

Now to look at how https://wiki.libsdl.org/SDL2/SDL_UpdateWindowSurfaceRects is implemented in other backends to see if it can be done elsewhere...

Edit: Ah, WIN_UpdateWindowFramebuffer calls BitBlt for each rect. So we can do the same easily enough.

@ids1024 ids1024 force-pushed the damage branch 4 times, most recently from 007c74e to 0720d64 Compare April 26, 2023 18:46
Supported on Wayland, X11, and Win32.

Fixes #39.

try_for_each
@ids1024 ids1024 force-pushed the damage branch 2 times, most recently from f36f86e to 7f78a60 Compare April 26, 2023 20:21
@ids1024 ids1024 changed the title WIP Buffer::present_with_damage() Add Buffer::present_with_damage() and Buffer::age() Apr 26, 2023
@ids1024
Copy link
Member Author

ids1024 commented Apr 26, 2023

Everything here should work now, but is untested.

@ids1024
Copy link
Member Author

ids1024 commented May 30, 2023

Updated to use u32/NonZeroU32 and return an error for out-of-range damage rects. It also now panics on present if resize wasn't called on X11 and Windows now, though we may want to require an initial window size instead (#106).

Still not properly tested, but there shouldn't be much that could go wrong here, and merging would help us work on other things without accumulating more conflicts. I still need to see about making use of both of these features in Iced's new software renderer.

@ids1024 ids1024 marked this pull request as ready for review May 30, 2023 22:48
@ids1024 ids1024 requested a review from john01dav as a code owner May 30, 2023 22:48
@ids1024
Copy link
Member Author

ids1024 commented Jun 2, 2023

Updated to address conflicts with #104.

Copy link
Member

@notgull notgull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@ids1024
Copy link
Member Author

ids1024 commented Jun 3, 2023

I think we can merge this now. So more backend code changes can be made without adding conflicts. If any issues come up later, they can be fixed.

@ids1024 ids1024 merged commit efdfb52 into master Jun 3, 2023
@ids1024 ids1024 deleted the damage branch June 3, 2023 03:15
@notgull notgull mentioned this pull request Jun 4, 2023
notgull added a commit that referenced this pull request Jun 4, 2023
* On MacOS, the contents scale is updated when set_buffer() is called, to adapt when the window is on a new screen (#68).
* **Breaking:** Split the `GraphicsContext` type into `Context` and `Surface` (#64).
* On Web, cache the document in the `Context` type (#66).
* **Breaking:** Introduce a new "owned buffer" for no-copy presentation (#65).
* Enable support for multi-threaded WASM (#77).
* Fix buffer resizing on X11 (#69).
* Add a set of functions for handling buffer damage (#99).
* Add a `fetch()` function for getting the window contents (#104).
* Bump MSRV to 1.64 (#81).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants