Add API for buffer age
Closed this issue · 1 comments
Compare https://registry.khronos.org/EGL/extensions/EXT/EGL_EXT_buffer_age.txt:
For example, with a double buffered surface and an
implementation that swaps via buffer exchanges, the age would
usually be 2. With a triple buffered surface the age would
usually be 3. An age of 1 means the previous swap was
implemented as a copy. An age of 0 means the buffer has only
just been initialized and the contents are undefined. Single
buffered surfaces have no frame boundaries and therefore
always have an age of 0.
We can have a method on softbuffer::Surface
, something like fn age(&self) -> Option<NonZeroU8>
. An application rendering with softbuffer could use this to avoid redrawing everything every frame when not much has changed, regardless of whether a backend uses double-buffering, etc.
Currently buffer_mut
is documented saying "The initial contents of the buffer may be zeroed, or may contain a previous frame." So this would provide a way to know which previous frame.
The way this interacts with buffer resizing is interesting. Depending on the backend, it may be able to grow or shrink a buffer while using the same memory. If height increased, it may only be necessary to draw the extra height. If width changed, everything needs to be shifted over.
It could return an age of None
here like a fresh buffer, but we'll have to be clear that this doesn't guarantee a zeroed buffer then (not that it matters, generally, since an application typically won't rely on the default value of the buffer).