ruffle
ruffle copied to clipboard
core: Only store viewport dimensions in `RenderBackend`
Previously, the viewport height and width were stored in
both Stage
and the RenderBackend
. Any changes to the viewport
dimensions (e.g. due to window resizing) needed to be updated in both
places to keep our handling of the viewport consistent.
This PR adds a new ViewportDimensions
type, which holds the
width, height, and scale factor. It is stored inside the
RenderBackend
impl, and is retrieved using the newly added
method RenderBackend.get_viewport_dimensions
. After a Player
has been constructed, any code that needes access to the viewport
dimensions will ultimate go through this method.
Unfortunately, Stage
needs to use the viewport dimensions
in build_matrices
. Therefore, any code modifying the viewport
dimensions should go through player.set_viewport_dimensions
,
which ensures that the stage matrices are rebuilt after the render
backend is updated.
Just curious, does this do anything for #7533?
I don't think so - none of the previous code around viewport dimensions depended on whether or not hardware acceleration is available.
Wouldn't it be easier to store the viewport in Stage
(or even better IMO, Player
) instead? This way we won't need to duplicate the same code in each of the 3 render backends, and an additional RenderBacked
method can be avoided.
@relrelb I'm returning the actual dimensions used by the backend (e.g. renderbuffer_width
), so there's only ever one field used to store a dimension. Having a copy in Player risks it getting out of sync with the dimensions used by the backend.