-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type-Driven Renderer Fallback #2351
Merged
Merged
Conversation
This file contains 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
geometry
APIs.In general, none of these changes break user code.
Type-Driven Renderer Fallback
The
iced_renderer
crate implemented a fallback strategy foriced_wgpu
andiced_tiny_skia
with 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
Renderer
andCompositor
types 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
Program
andApplication
Both the
Program
API and theApplication
trait support views with any properRenderer
that has acompositor::Default
implementation.Optional Backends
These changes also allow us to make the
tiny-skia
backend optional behind a feature gate.In fact, it is now possible to compile an
iced
application 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_assertions
enabled, sorelease
builds should fail by default if users disable the default features and forget to explicitly enable a renderer.Generic
geometry
APII have abstracted the
geometry
API and moved it fromiced_renderer
toiced_graphics
.Both
Frame
andCache
types should work with anyRenderer
that implements thegeometry::Renderer
trait. A newCached
trait has been introduced iniced_graphics
that abstracts the idea of primitive caching (i.e. loading a cache).Better Graphics Errors
I have also improved the errors reported by a
Compositor
when initialization fails—whether it is because of a surface error, incompatible limits, or simply a backend preference mismatch.