rust-windowing / softbuffer

Easily write an image to a window
Apache License 2.0
333 stars 48 forks source link

Resize the surface at the correct time in examples #236

Closed madsmtm closed 2 months ago

madsmtm commented 2 months ago

The examples previously showed resizing just before rendering, which is inefficient, the user should only resize when needed. Tested on macOS.

I have not updated the winit_multithread example, as it was a bit more cumbersome, and I wouldn't be able to test it anyways, as it doesn't seem to work on macOS.

madsmtm commented 2 months ago

Does winit assume (for every backend) / guarantee that a surface is "always" created with "some" initial size, and always delivers a Resized event afterwards if it changed? Or otherwise, if it doesn't know/understand/have an initial size, always raises a Resized event?

Hmm, isn't this more of a Softbuffer issue? We're creating the surface from the window, which itself has an initial size (the examples use with_inner_size).

MarijnS95 commented 2 months ago

Hmm, isn't this more of a Softbuffer issue? We're creating the surface from the window, which itself has an initial size (the examples use with_inner_size).

It seems a bit surprising that creating a Softbuffer surface doesn't require an initial size, as if it's able to query/follow that from the underlying window handle - but then we have to forward the size explicitly whenever a resize event occurs.

Otherwise that would have been a valid reason to not have size queries on the Surface - the caller is always aware of the size already (and would reduce ambiguity).

madsmtm commented 2 months ago

Hmm, isn't this more of a Softbuffer issue? We're creating the surface from the window, which itself has an initial size (the examples use with_inner_size).

It seems a bit surprising that creating a Softbuffer surface doesn't require an initial size, as if it's able to query/follow that from the underlying window handle - but then we have to forward the size explicitly whenever a resize event occurs.

Well, on macOS/iOS at least I think we could fairly easily make the surface follow the size of the window automatically, but I don't know about the other platforms.

MarijnS95 commented 2 months ago

Well, on macOS/iOS at least I think we could fairly easily make the surface follow the size of the window automatically, but I don't know about the other platforms.

Same on Android, by requesting a buffer size of 0 (or never setting one). I'll move the rest of the planned reply to https://github.com/rust-windowing/softbuffer/issues/237 and post it in a second!