Type-Driven Renderer Fallback#2351
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR sets the foundations for supporting custom renderers with the built-in APIs by implementing a composable, type-driven renderer fallback strategy and properly abstracting our
geometryAPIs.In general, none of these changes break user code.
Type-Driven Renderer Fallback
The
iced_renderercrate implemented a fallback strategy foriced_wgpuandiced_tiny_skiawith a simple enum:iced/renderer/src/lib.rs
Lines 37 to 41 in 3013463
The changes here abstract this pattern and make it composable:
iced/renderer/src/fallback.rs
Lines 11 to 14 in 4f5b63f
Effectively, this means that we can build fallback strategies at the type level. For instance, here are the
RendererandCompositortypes exposed byiced_renderer:iced/renderer/src/lib.rs
Lines 25 to 54 in 4f5b63f
So, let's say you build a custom renderer:
MyRenderer. You can easily plug it in front of the official ones:Compositors can be composed analogously!
Custom Renderers in
ProgramandApplicationBoth the
ProgramAPI and theApplicationtrait support views with any properRendererthat has acompositor::Defaultimplementation.Optional Backends
These changes also allow us to make the
tiny-skiabackend optional behind a feature gate.In fact, it is now possible to compile an
icedapplication without a renderer whatsoever; which may be useful for testing and reducing compilation times. The runtime will simply create an empty window in this case.The null (unit) renderer is only available with
debug_assertionsenabled, soreleasebuilds should fail by default if users disable the default features and forget to explicitly enable a renderer.Generic
geometryAPII have abstracted the
geometryAPI and moved it fromiced_renderertoiced_graphics.Both
FrameandCachetypes should work with anyRendererthat implements thegeometry::Renderertrait. A newCachedtrait has been introduced iniced_graphicsthat abstracts the idea of primitive caching (i.e. loading a cache).Better Graphics Errors
I have also improved the errors reported by a
Compositorwhen initialization fails—whether it is because of a surface error, incompatible limits, or simply a backend preference mismatch.