Repository navigation
vello_gpu: Replace image_bicubic with extended_images
#1994
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0ce6f56
514c4df
667f044
db7098b
9bf8216
977fe1f
57348e7
499762a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,7 +25,7 @@ use vello_common::paint::{Paint, PaintType, PremulColor, Tint}; | |
| #[cfg(feature = "text")] | ||
| use vello_common::peniko::FontData; | ||
| use vello_common::peniko::color::palette::css::BLACK; | ||
| use vello_common::peniko::{BlendMode, Fill, GradientKind, ImageQuality}; | ||
| use vello_common::peniko::{BlendMode, Fill, GradientKind}; | ||
| use vello_common::record::{CommandRecorder, Drawable, LayerClip, LayerProps, PoppedLayer}; | ||
| use vello_common::render_state::RenderState; | ||
| use vello_common::strip::Strip; | ||
|
|
@@ -815,12 +815,16 @@ impl Scene { | |
| #[track_caller] | ||
| pub fn set_paint(&mut self, paint: impl Into<PaintType>) { | ||
| let paint = paint.into(); | ||
| assert_paint_supported(&paint); | ||
| assert_paint_supported(&paint, self.render_state.tint); | ||
|
|
||
| self.render_state.paint = paint; | ||
| } | ||
|
|
||
| /// Set the tint for subsequent image paint operations. | ||
| #[track_caller] | ||
| pub fn set_tint(&mut self, tint: Option<Tint>) { | ||
| assert_paint_supported(&self.render_state.paint, tint); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These checks make otherwise valid state updates depend on setter order: scene.set_paint(native_image);
scene.fill_rect(&r);
scene.set_tint(Some(red)); // Panics here.
scene.set_paint(BLUE); // The next draw would be solid.
scene.set_tint(Some(red));
scene.set_paint(native_image); // Panics here.
scene.reset_tint(); // The tint is cleared before drawing.I can see the argument that every intermediate state should remain renderable, so I don鈥檛 think this necessarily needs to block the PR. Should we allow sequences like these and validate only the final state?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm... Yeah let me add this as a TODO, not sure what the best thing to do is here. |
||
|
|
||
| self.render_state.tint = tint; | ||
| } | ||
|
|
||
|
|
@@ -937,7 +941,7 @@ impl Scene { | |
| /// Restore rendering state. | ||
| #[track_caller] | ||
| pub fn restore_state(&mut self, state: RenderState) { | ||
| assert_paint_supported(&state.paint); | ||
| assert_paint_supported(&state.paint, state.tint); | ||
|
|
||
| self.render_state = state; | ||
| } | ||
|
|
@@ -986,37 +990,41 @@ impl vello_common::probe::ProbeRenderer for Scene { | |
| } | ||
| } | ||
|
|
||
| // TODO: Consider validating paint/tint support at draw time so otherwise valid state updates | ||
| // do not depend on setter order. See: | ||
| // https://github.com/linebender/vello/pull/1994#discussion_r4278390451 | ||
| #[track_caller] | ||
| fn assert_paint_supported(paint: &PaintType) { | ||
| fn assert_paint_supported(paint: &PaintType, tint: Option<Tint>) { | ||
| match paint { | ||
| PaintType::Solid(_) => {} | ||
| PaintType::Gradient(gradient) => assert!( | ||
| cfg!(feature = "gradient_sweep") || !matches!(gradient.kind, GradientKind::Sweep(_)), | ||
| "sweep gradients require the `gradient_sweep` feature" | ||
| ), | ||
| PaintType::Image(image) => assert!( | ||
| cfg!(feature = "image_bicubic") || image.sampler.quality != ImageQuality::High, | ||
| "bicubic image sampling requires the `image_bicubic` feature" | ||
| cfg!(feature = "full_image_support") | ||
| || crate::paint::supports_native_image(&image.image, image.sampler.quality, tint), | ||
| "extended image sampling requires the `full_image_support` feature" | ||
| ), | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::{RecordedDraw, Scene}; | ||
| #[cfg(feature = "text")] | ||
| #[cfg(all(feature = "text", feature = "full_image_support"))] | ||
| use crate::resources::Resources; | ||
| #[cfg(feature = "text")] | ||
| #[cfg(all(feature = "text", feature = "full_image_support"))] | ||
| use alloc::sync::Arc; | ||
| #[cfg(feature = "text")] | ||
| #[cfg(all(feature = "text", feature = "full_image_support"))] | ||
| use glifo::Glyph; | ||
| use vello_common::TextureId; | ||
| use vello_common::geometry::RectU16; | ||
| use vello_common::kurbo::{BezPath, Rect}; | ||
| use vello_common::paint::{Image, ImageSource, Paint, PremulColor, TextureRegion}; | ||
| use vello_common::peniko::ImageSampler; | ||
| use vello_common::peniko::color::palette::css::BLUE; | ||
| #[cfg(feature = "text")] | ||
| #[cfg(all(feature = "text", feature = "full_image_support"))] | ||
| use vello_common::peniko::{Blob, FontData}; | ||
| use vello_common::record::Drawable; | ||
|
|
||
|
|
@@ -1101,7 +1109,7 @@ mod tests { | |
| assert!(scene.recorder.nodes.is_empty()); | ||
| } | ||
|
|
||
| #[cfg(feature = "text")] | ||
| #[cfg(all(feature = "text", feature = "full_image_support"))] | ||
| #[test] | ||
| fn glyph_atlas_resources_are_lazy() { | ||
| const ROBOTO_FONT: &[u8] = include_bytes!("../../assets/roboto/Roboto-Regular.ttf"); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to just compile out this method if the feature is disabled, instead of panicking at runtime.
However, internally we currently have a runtime feature flag, so unless we are willing to go "all-in" on external texture and remove that, we need to keep the method available, even if the feature is disabled.