ruffle icon indicating copy to clipboard operation
ruffle copied to clipboard

core: Only store viewport dimensions in `RenderBackend`

Open Aaron1011 opened this issue 2 years ago • 4 comments

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.

Aaron1011 avatar Aug 04 '22 05:08 Aaron1011

Just curious, does this do anything for #7533?

torokati44 avatar Aug 04 '22 16:08 torokati44

I don't think so - none of the previous code around viewport dimensions depended on whether or not hardware acceleration is available.

Aaron1011 avatar Aug 04 '22 16:08 Aaron1011

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 avatar Aug 08 '22 18:08 relrelb

@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.

Aaron1011 avatar Aug 08 '22 19:08 Aaron1011