pub struct Scene {
pub shadows: Vec<Shadow>,
pub quads: Vec<Quad>,
pub paths: Vec<Path<ScaledPixels>>,
pub underlines: Vec<Underline>,
pub monochrome_sprites: Vec<MonochromeSprite>,
pub subpixel_sprites: Vec<SubpixelSprite>,
pub polychrome_sprites: Vec<PolychromeSprite>,
pub surfaces: Vec<PaintSurface>,
pub backdrop_filters: Vec<BackdropFilter>,
pub filter_boundaries: Vec<FilterBoundary>,
/* private fields */
}Expand description
The primitives painted for one frame, ready for a renderer to consume.
crate::Window fills a scene while it paints. You rarely create one yourself, but it is
public so tests and custom renderers can inspect the result. Add primitives with
Scene::insert_primitive in paint order, then call Scene::finish before reading the
renderer-facing vectors: finish sorts them by draw order and compiles the render plan.
§Examples
let bounds = Bounds {
origin: point(ScaledPixels(0.), ScaledPixels(0.)),
size: size(ScaledPixels(100.), ScaledPixels(40.)),
};
let mut scene = Scene::default();
scene.insert_primitive(Quad {
bounds,
content_mask: ContentMask { bounds, ..Default::default() },
background: rgb(0x2563eb).into(),
..Default::default()
});
scene.finish();
assert_eq!(scene.quads.len(), 1);Fields§
§shadows: Vec<Shadow>Shadow primitives. Sorted by draw order after Scene::finish.
quads: Vec<Quad>Quad primitives. Sorted by draw order after Scene::finish.
paths: Vec<Path<ScaledPixels>>Path primitives. A PathId is the index the path had when it was inserted, which
Scene::finish can change by sorting this vector.
underlines: Vec<Underline>Underline primitives. Sorted by draw order after Scene::finish.
monochrome_sprites: Vec<MonochromeSprite>Single-color sprites, such as icons and glyph masks.
subpixel_sprites: Vec<SubpixelSprite>Glyphs drawn with subpixel anti-aliasing.
polychrome_sprites: Vec<PolychromeSprite>Full-color sprites, such as images and color emoji.
surfaces: Vec<PaintSurface>crate::PaintSurface primitives, such as video frames.
backdrop_filters: Vec<BackdropFilter>crate::BackdropFilter primitives.
filter_boundaries: Vec<FilterBoundary>Start and end markers of content-filter groups. They always come in matched pairs.
Implementations§
Source§impl Scene
impl Scene
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Removes every primitive and resets the scene so that it can be painted again.
The vectors keep their capacity, so a scene that is cleared and refilled each frame reuses its allocations.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of paint operations in this scene, including layer boundaries.
Sourcepub fn push_layer(&mut self, bounds: Bounds<ScaledPixels>)
pub fn push_layer(&mut self, bounds: Bounds<ScaledPixels>)
Starts a layer. Every primitive inserted until the matching Scene::pop_layer receives
the layer’s draw order, so the layer’s contents are not interleaved with surrounding
primitives. Within a layer, the renderer still groups work by primitive type.
crate::Window::paint_layer calls this for you.
Sourcepub fn pop_layer(&mut self)
pub fn pop_layer(&mut self)
Ends the layer started by the most recent Scene::push_layer. The scene does not check
that the calls are balanced, so callers must keep the nesting correct.
Sourcepub fn raise_order_floor(&mut self)
pub fn raise_order_floor(&mut self)
Makes every primitive inserted after this call draw above every primitive inserted before it.
Use this to put overlays, such as tooltips and drag images, above the rest of the scene. The renderer draws primitives in ascending draw order.
Sourcepub fn insert_primitive(&mut self, primitive: impl Into<Primitive>)
pub fn insert_primitive(&mut self, primitive: impl Into<Primitive>)
Adds a primitive in paint order and assigns it a draw order.
A primitive whose bounds are empty after clipping to its content mask is dropped. A
transformed sprite is clipped by its transformed bounds. Filter boundaries are never
dropped. Inside a layer started with Scene::push_layer, the primitive takes the layer’s
draw order. Otherwise it takes one more than the highest draw order of any primitive that
it overlaps, so it draws above them. In either case the order is at least the floor set by
Scene::raise_order_floor.
§Examples
let mut scene = Scene::default();
let bounds = Bounds {
origin: point(ScaledPixels(0.), ScaledPixels(0.)),
size: size(ScaledPixels(100.), ScaledPixels(40.)),
};
// The default content mask is empty, so this quad is clipped away.
scene.insert_primitive(Quad { bounds, ..Default::default() });
scene.finish();
assert!(scene.quads.is_empty());Sourcepub fn replay(&mut self, range: Range<usize>, prev_scene: &Scene)
pub fn replay(&mut self, range: Range<usize>, prev_scene: &Scene)
Inserts the paint operations in range from prev_scene into this scene, as if they had been
painted again.
Use this to reuse the output of an earlier frame for a view that hasn’t changed. Draw orders are assigned again in this scene.
§Panics
Panics if range extends past the end of prev_scene’s paint operations.
Sourcepub fn finish(&mut self)
pub fn finish(&mut self)
Sorts the primitives by draw order and compiles the renderer’s plan.
Call this after painting and before rendering. Adding a primitive after finish marks the
scene unfinished again; call finish again before reading Scene::batches or
Scene::render_commands.
Sourcepub fn batches(&self) -> impl Iterator<Item = PrimitiveBatch> + '_
pub fn batches(&self) -> impl Iterator<Item = PrimitiveBatch> + '_
Returns the draw batches of a finished scene, in drawing order.
Each batch is a run of one primitive type that the renderer draws in one call.
PrimitiveBatch::FilterBoundary entries mark the start and end of content-filter groups.
Use Scene::render_commands when you also need the offscreen target for each group.
§Panics
In debug builds, panics if the scene hasn’t been finished.
§Examples
let bounds = Bounds {
origin: point(ScaledPixels(0.), ScaledPixels(0.)),
size: size(ScaledPixels(100.), ScaledPixels(40.)),
};
let mut scene = Scene::default();
scene.insert_primitive(Quad {
bounds,
content_mask: ContentMask { bounds, ..Default::default() },
..Default::default()
});
scene.finish();
assert_eq!(
scene.batches().collect::<Vec<_>>(),
vec![PrimitiveBatch::Quads { range: 0..1, smoothed: false }],
);Sourcepub fn render_commands(&self) -> &[RenderCommand]
pub fn render_commands(&self) -> &[RenderCommand]
Returns the render commands of a finished scene, in drawing order.
Commands are primitive batches, plus begin and end markers for content-filter groups that say
whether each group draws into an isolated target. Renderers use these instead of
Scene::batches when they manage offscreen targets.
§Panics
In debug builds, panics if the scene hasn’t been finished.
Sourcepub fn render_plan(&self) -> &ScenePlan
pub fn render_plan(&self) -> &ScenePlan
Returns the compiled ScenePlan of a finished scene.
§Panics
In debug builds, panics if the scene hasn’t been finished, or if its primitive storage changed
after Scene::finish.
Sourcepub fn surface_opacities(&self) -> &[f32]
pub fn surface_opacities(&self) -> &[f32]
Returns the opacity of each entry in Scene::surfaces, in the same order.
Surfaces are fully opaque here; group opacity is applied when compositing.
Sourcepub fn requires_offscreen_rendering(&self) -> bool
pub fn requires_offscreen_rendering(&self) -> bool
Returns true if rendering this scene needs an offscreen target. That is the case when it has
backdrop filters, content filters, or grouped opacity.
§Panics
In debug builds, panics if the scene hasn’t been finished.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Scene
impl !UnwindSafe for Scene
impl Freeze for Scene
impl Send for Scene
impl Sync for Scene
impl Unpin for Scene
impl UnsafeUnpin for Scene
Blanket Implementations§
Source§impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
Source§fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
replaced by palette::chromatic_adaptation::AdaptIntoUnclamped
Source§fn adapt_into(self) -> D
fn adapt_into(self) -> D
replaced by palette::chromatic_adaptation::AdaptIntoUnclamped
Source§impl<T, C> AdaptIntoUnclamped<T> for Cwhere
T: AdaptFromUnclamped<C>,
impl<T, C> AdaptIntoUnclamped<T> for Cwhere
T: AdaptFromUnclamped<C>,
Source§type Scalar = <T as AdaptFromUnclamped<C>>::Scalar
type Scalar = <T as AdaptFromUnclamped<C>>::Scalar
Source§fn adapt_into_unclamped_with<M>(self) -> Twhere
M: LmsToXyz<<C as AdaptIntoUnclamped<T>>::Scalar> + XyzToLms<<C as AdaptIntoUnclamped<T>>::Scalar>,
fn adapt_into_unclamped_with<M>(self) -> Twhere
M: LmsToXyz<<C as AdaptIntoUnclamped<T>>::Scalar> + XyzToLms<<C as AdaptIntoUnclamped<T>>::Scalar>,
Source§impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
Source§fn arrays_from(colors: C) -> T
fn arrays_from(colors: C) -> T
Source§impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
Source§fn arrays_into(self) -> C
fn arrays_into(self) -> C
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
Source§type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
parameters when converting.Source§fn cam16_into_unclamped(
self,
parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>,
) -> T
fn cam16_into_unclamped( self, parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
Source§fn components_from(colors: C) -> T
fn components_from(colors: C) -> T
Source§impl<T, C> ComponentsInto<C> for T
impl<T, C> ComponentsInto<C> for T
Source§fn components_into(self) -> C
fn components_into(self) -> C
Source§impl<T> FromAngle<T> for T
impl<T> FromAngle<T> for T
Source§fn from_angle(angle: T) -> T
fn from_angle(angle: T) -> T
angle.Source§impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
Source§fn from_stimulus(other: U) -> T
fn from_stimulus(other: U) -> T
other into Self, while performing the appropriate scaling,
rounding and clamping.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
Source§fn into_angle(self) -> U
fn into_angle(self) -> U
T.Source§impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
Source§type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
parameters when converting.Source§fn into_cam16_unclamped(
self,
parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>,
) -> T
fn into_cam16_unclamped( self, parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.Source§impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
Source§fn into_color(self) -> U
fn into_color(self) -> U
Source§impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
Source§fn into_color_unclamped(self) -> U
fn into_color_unclamped(self) -> U
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoStimulus<T> for T
impl<T> IntoStimulus<T> for T
Source§fn into_stimulus(self) -> T
fn into_stimulus(self) -> T
self into T, while performing the appropriate scaling,
rounding and clamping.Source§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().Source§impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
Source§type Error = <C as TryFromComponents<T>>::Error
type Error = <C as TryFromComponents<T>>::Error
try_into_colors fails to cast.Source§fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
Source§impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
Source§fn try_into_color(self) -> Result<U, OutOfBounds<U>>
fn try_into_color(self) -> Result<U, OutOfBounds<U>>
OutOfBounds error is returned which contains
the unclamped color. Read more