Skip to main content

Scene

Struct Scene 

Source
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>§filter_boundaries: Vec<FilterBoundary>

Start and end markers of content-filter groups. They always come in matched pairs.

Implementations§

Source§

impl Scene

Source

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.

Source

pub fn len(&self) -> usize

Returns the number of paint operations in this scene, including layer boundaries.

Source

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.

Source

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.

Source

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.

Source

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());
Source

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.

Source

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.

Source

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 }],
);
Source

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.

Source

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.

Source

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.

Source

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§

Source§

impl Default for Scene

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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 S
where 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) -> D
where M: TransformMatrix<T>,

👎Deprecated since 0.7.7:

replaced by palette::chromatic_adaptation::AdaptIntoUnclamped

Convert the source color to the destination color using the specified method.
Source§

fn adapt_into(self) -> D

👎Deprecated since 0.7.7:

replaced by palette::chromatic_adaptation::AdaptIntoUnclamped

Convert the source color to the destination color using the bradford method by default.
Source§

impl<T, C> AdaptIntoUnclamped<T> for C
where T: AdaptFromUnclamped<C>,

Source§

type Scalar = <T as AdaptFromUnclamped<C>>::Scalar

The number type that’s used as the color’s components.
Source§

fn adapt_into_unclamped_with<M>(self) -> T

Adapt a color of type Self into a color of type T, using the custom matrix M. Read more
Source§

fn adapt_into_unclamped(self) -> T
where Bradford: LmsToXyz<Self::Scalar> + XyzToLms<Self::Scalar>,

Adapt a color of type Self into a color of type T, using the Bradford matrix. Read more
Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T, C> ArraysFrom<C> for T
where C: IntoArrays<T>,

Source§

fn arrays_from(colors: C) -> T

Cast a collection of colors into a collection of arrays.
Source§

impl<T, C> ArraysInto<C> for T
where C: FromArrays<T>,

Source§

fn arrays_into(self) -> C

Cast this collection of arrays into a collection of colors.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for U
where T: FromCam16Unclamped<WpParam, U>,

Source§

type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar

The number type that’s used in parameters when converting.
Source§

fn cam16_into_unclamped( self, parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>, ) -> T

Converts self into C, using the provided parameters.
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T, C> ComponentsFrom<C> for T
where C: IntoComponents<T>,

Source§

fn components_from(colors: C) -> T

Cast a collection of colors into a collection of color components.
Source§

impl<T, C> ComponentsInto<C> for T

Source§

fn components_into(self) -> C

Cast this collection of color components into a collection of colors. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromAngle<T> for T

Source§

fn from_angle(angle: T) -> T

Performs a conversion from angle.
Source§

impl<T, U> FromStimulus<U> for T
where U: IntoStimulus<T>,

Source§

fn from_stimulus(other: U) -> T

Converts other into Self, while performing the appropriate scaling, rounding and clamping.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> IntoAngle<U> for T
where U: FromAngle<T>,

Source§

fn into_angle(self) -> U

Performs a conversion into T.
Source§

impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for U
where T: Cam16FromUnclamped<WpParam, U>,

Source§

type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar

The number type that’s used in parameters when converting.
Source§

fn into_cam16_unclamped( self, parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>, ) -> T

Converts self into C, using the provided parameters.
Source§

impl<T, U> IntoColor<U> for T
where U: FromColor<T>,

Source§

fn into_color(self) -> U

Convert into T with values clamped to the color defined bounds Read more
Source§

impl<T, U> IntoColorUnclamped<U> for T
where U: FromColorUnclamped<T>,

Source§

fn into_color_unclamped(self) -> U

Convert into T. The resulting color might be invalid in its color space Read more
Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> IntoStimulus<T> for T

Source§

fn into_stimulus(self) -> T

Converts self into T, while performing the appropriate scaling, rounding and clamping.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T, C> TryComponentsInto<C> for T
where C: TryFromComponents<T>,

Source§

type Error = <C as TryFromComponents<T>>::Error

The error for when try_into_colors fails to cast.
Source§

fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>

Try to cast this collection of color components into a collection of colors. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T, U> TryIntoColor<U> for T
where U: TryFromColor<T>,

Source§

fn try_into_color(self) -> Result<U, OutOfBounds<U>>

Convert into T, returning ok if the color is inside of its defined range, otherwise an OutOfBounds error is returned which contains the unclamped color. Read more
Source§

impl<C, U> UintsFrom<C> for U
where C: IntoUints<U>,

Source§

fn uints_from(colors: C) -> U

Cast a collection of colors into a collection of unsigned integers.
Source§

impl<C, U> UintsInto<C> for U
where C: FromUints<U>,

Source§

fn uints_into(self) -> C

Cast this collection of unsigned integers into a collection of colors.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more