Skip to main content

Compositor

Struct Compositor 

Source
pub struct Compositor { /* private fields */ }
Expand description

The compositor: manages the composition objects of the UI thread and commits their changes to the server compositor in batches.

Implementations§

Source§

impl Compositor

Source

pub const MAX_GLOBAL_PLAYBACK_RATE: f32 = 1000.0

The highest global playback rate (WinUI MaxGlobalPlaybackRate).

Source

pub const MIN_GLOBAL_PLAYBACK_RATE: f32 = 0.0

The lowest global playback rate (WinUI MinGlobalPlaybackRate).

Source

pub fn create_animation_controller(&self) -> Rc<AnimationController>

Creates an animation controller (WinUI CreateAnimationController).

Source

pub fn global_playback_rate(&self) -> f32

The rate at which the time of every animation of the compositor runs (WinUI GlobalPlaybackRate): 1 by default, 0.5 for half speed.

Source

pub fn set_global_playback_rate(&self, value: f32)

Sets the global playback rate, clamped to MIN_GLOBAL_PLAYBACK_RATE..MAX_GLOBAL_PLAYBACK_RATE. It applies from the next frame to running animations and to those started later: their time from then on runs at the new rate.

Source§

impl Compositor

The easing factories of WinUI Compositor. They return the typed function (Rc), which key frames take as it is (insert_key_frame_with_easing) or as an Easing (.into()).

Source

pub fn create_cubic_bezier_easing_function( &self, control_point1: Vector2, control_point2: Vector2, ) -> Rc<CubicBezierEasingFunction>

A cubic Bezier curve with the given control points (WinUI CreateCubicBezierEasingFunction).

Source

pub fn create_linear_easing_function(&self) -> Rc<LinearEasingFunction>

The linear curve (WinUI CreateLinearEasingFunction).

Source

pub fn create_step_easing_function(&self) -> Rc<StepEasingFunction>

A step function with one step (WinUI CreateStepEasingFunction()).

Source

pub fn create_step_easing_function_with_step_count( &self, step_count: i32, ) -> Rc<StepEasingFunction>

A step function with step_count steps (WinUI CreateStepEasingFunction(stepCount)).

Source§

impl Compositor

Source§

impl Compositor

Source§

impl Compositor

Source§

impl Compositor

Source§

impl Compositor

Source§

impl Compositor

Source§

impl Compositor

Source§

impl Compositor

Source§

impl Compositor

Source§

impl Compositor

Source§

impl Compositor

Source§

impl Compositor

Source§

impl Compositor

Source

pub fn create_spring_scalar_animation( &self, ) -> Rc<SpringScalarNaturalMotionAnimation>

Creates a SpringScalarNaturalMotionAnimation.

Source§

impl Compositor

Source

pub fn create_spring_vector2_animation( &self, ) -> Rc<SpringVector2NaturalMotionAnimation>

Creates a SpringVector2NaturalMotionAnimation.

Source§

impl Compositor

Source

pub fn create_spring_vector3_animation( &self, ) -> Rc<SpringVector3NaturalMotionAnimation>

Creates a SpringVector3NaturalMotionAnimation.

Source§

impl Compositor

Source

pub fn create_effect_factory( &self, effect: impl Into<GraphicsEffect>, ) -> Rc<CompositionEffectFactory>

CreateEffectFactory(graphicsEffect): a factory of brushes that draw effect, without animatable properties.

Source

pub fn create_effect_factory_with_properties( &self, effect: impl Into<GraphicsEffect>, animatable_properties: &[&str], ) -> Rc<CompositionEffectFactory>

CreateEffectFactory(graphicsEffect, animatableProperties): a factory of brushes that draw effect, whose properties named in animatable_properties (EffectName.PropertyName, as Blur.BlurAmount) can be changed and animated on the brushes.

Source

pub fn create_backdrop_brush(&self) -> CompositionBackdropBrush

CreateBackdropBrush: a brush that shows what is behind the visual that paints it: the compositor draws again what was drawn under the visual (winui-materials.md, the backdrop).

Source

pub fn create_host_backdrop_brush(&self) -> CompositionHostBackdropBrush

CreateHostBackdropBrush: a brush that shows what is behind the window (see CompositionHostBackdropBrush).

Source§

impl Compositor

Source

pub fn create_scoped_batch( &self, batch_type: CompositionBatchTypes, ) -> Rc<CompositionScopedBatch>

Creates a scoped batch that aggregates the animations of the given types started from now on (WinUI CreateScopedBatch).

Source

pub fn get_commit_batch( &self, batch_type: CompositionBatchTypes, ) -> Rc<CompositionCommitBatch>

The batch of the animations started in the current frame, which the next commit ends (WinUI GetCommitBatch). The animations started in the frame before the call belong to it too. A commit is requested, so the batch ends even if nothing else changes.

Source

pub fn create_property_set(&self) -> Rc<CompositionPropertySet>

Creates a property set (WinUI CreatePropertySet).

Source§

impl Compositor

Source

pub fn create_ambient_light(&self) -> AmbientLight

CreateAmbientLight.

Source

pub fn create_distant_light(&self) -> DistantLight

CreateDistantLight.

Source

pub fn create_point_light(&self) -> PointLight

CreatePointLight.

Source

pub fn create_spot_light(&self) -> SpotLight

CreateSpotLight.

Source§

impl Compositor

Source

pub fn create_shape_visual(&self) -> ShapeVisual

CreateShapeVisual: a visual that draws shapes.

Source

pub fn create_sprite_shape(&self) -> CompositionSpriteShape

CreateSpriteShape: a shape without a geometry.

Source

pub fn create_sprite_shape_with_geometry( &self, geometry: Option<Rc<CompositionGeometry>>, ) -> CompositionSpriteShape

CreateSpriteShape(geometry): a shape that draws geometry.

Source

pub fn create_container_shape(&self) -> CompositionContainerShape

CreateContainerShape: a shape that groups shapes.

Source

pub fn create_rectangle_geometry(&self) -> CompositionRectangleGeometry

CreateRectangleGeometry: an empty rectangle at the origin.

Source

pub fn create_rounded_rectangle_geometry( &self, ) -> CompositionRoundedRectangleGeometry

CreateRoundedRectangleGeometry: an empty rounded rectangle at the origin.

Source

pub fn create_ellipse_geometry(&self) -> CompositionEllipseGeometry

CreateEllipseGeometry: an ellipse with zero radii at the origin.

Source

pub fn create_line_geometry(&self) -> CompositionLineGeometry

CreateLineGeometry: a line from the origin to the origin.

Source

pub fn create_path_geometry(&self) -> CompositionPathGeometry

CreatePathGeometry: a geometry without a path.

Source

pub fn create_path_geometry_with_path( &self, path: Option<CompositionPath>, ) -> CompositionPathGeometry

CreatePathGeometry(path): a geometry that shows path.

Source

pub fn create_view_box(&self) -> Rc<CompositionViewBox>

CreateViewBox: a view box with a zero size.

Source

pub fn create_geometric_clip(&self) -> GeometricClip

CreateGeometricClip: a clip without a geometry.

Source

pub fn create_geometric_clip_with_geometry( &self, geometry: Option<Rc<CompositionGeometry>>, ) -> GeometricClip

CreateGeometricClip(geometry): a clip to the inside of geometry.

Source§

impl Compositor

Source

pub fn create_sprite_visual(&self) -> SpriteVisual

CreateSpriteVisual: a visual that paints its size with a brush.

Source

pub fn create_color_brush(&self) -> CompositionSolidColorBrush

CreateColorBrush: the WinUI name of create_solid_color_brush.

Source

pub fn create_color_brush_with_color( &self, color: Color, ) -> CompositionSolidColorBrush

CreateColorBrush(color): the WinUI name of create_solid_color_brush_with.

Source

pub fn create_surface_brush(&self) -> CompositionSurfaceBrush

CreateSurfaceBrush: a brush that paints a surface, without a surface.

Source

pub fn create_surface_brush_with_surface( &self, surface: Rc<dyn ICompositionSurface>, ) -> CompositionSurfaceBrush

CreateSurfaceBrush(surface): a brush that paints surface.

Source

pub fn create_visual_surface(&self) -> Rc<CompositionVisualSurface>

CreateVisualSurface: a live image of the subtree of a visual.

Source

pub fn create_drop_shadow(&self) -> Rc<DropShadow>

CreateDropShadow: a shadow for a sprite visual.

Source

pub fn create_inset_clip(&self) -> InsetClip

CreateInsetClip: a clip with zero insets.

Source

pub fn create_inset_clip_with_insets( &self, left: f32, top: f32, right: f32, bottom: f32, ) -> InsetClip

CreateInsetClip(leftInset, topInset, rightInset, bottomInset).

Source

pub fn create_rectangle_clip(&self) -> RectangleClip

CreateRectangleClip: a clip whose edges are all zero (it leaves nothing visible until its edges are set).

Source

pub fn create_rectangle_clip_with( &self, left: f32, top: f32, right: f32, bottom: f32, ) -> RectangleClip

CreateRectangleClip(left, top, right, bottom).

Source

pub fn create_rectangle_clip_with_radii( &self, left: f32, top: f32, right: f32, bottom: f32, top_left_radius: Vector, top_right_radius: Vector, bottom_right_radius: Vector, bottom_left_radius: Vector, ) -> RectangleClip

CreateRectangleClip(left, top, right, bottom, topLeftRadius, topRightRadius, bottomRightRadius, bottomLeftRadius).

Source§

impl Compositor

Source

pub fn create_layer_visual(&self) -> LayerVisual

CreateLayerVisual: a container visual whose children are composed into one layer.

Source

pub fn create_redirect_visual(&self) -> RedirectVisual

CreateRedirectVisual: a visual that shows the subtree of another visual, without a source.

Source

pub fn create_redirect_visual_with_source_visual( &self, source: Option<Rc<CompositionVisual>>, ) -> RedirectVisual

CreateRedirectVisual(source): a visual that shows the subtree of source.

Source

pub fn create_nine_grid_brush(&self) -> CompositionNineGridBrush

CreateNineGridBrush: a brush that paints another brush as a nine-grid.

Source

pub fn create_mask_brush(&self) -> CompositionMaskBrush

CreateMaskBrush: a brush that paints a brush through the alpha of another.

Source

pub fn create_color_gradient_stop( &self, offset: f32, color: Color, ) -> Rc<CompositionGradientStop>

CreateColorGradientStop(offset, color): the WinUI name of create_gradient_stop_with.

Source

pub fn create_color_gradient_stop_default(&self) -> Rc<CompositionGradientStop>

CreateColorGradientStop(): the WinUI name of create_gradient_stop.

Source§

impl Compositor

Source

pub fn create_composition_target( &self, surfaces: RenderSurfaces, ) -> Rc<CompositionTarget>

Creates a composition target that renders to one of the surfaces surfaces returns.

Source

pub fn create_container_visual(&self) -> Rc<CompositionContainerVisual>

Source

pub fn create_expression_animation(&self) -> Rc<ExpressionAnimation>

Source

pub fn create_expression_animation_with( &self, expression: &str, ) -> Rc<ExpressionAnimation>

Source

pub fn create_implicit_animation_collection( &self, ) -> Rc<ImplicitAnimationCollection>

Source

pub fn create_animation_group(&self) -> Rc<CompositionAnimationGroup>

Source

pub fn create_solid_color_visual(&self) -> CompositionSolidColorVisual

Source

pub fn create_custom_visual( &self, handler: impl FnOnce() -> Rc<dyn ICompositionCustomVisualHandler> + Send + 'static, ) -> CompositionCustomVisual

The handler belongs to the render thread: handler creates it there.

Source

pub fn create_drawing_surface(&self) -> CompositionDrawingSurface

Source

pub fn create_surface_visual(&self) -> CompositionSurfaceVisual

Source

pub fn create_solid_color_brush(&self) -> CompositionSolidColorBrush

Source

pub fn create_solid_color_brush_with( &self, color: Color, ) -> CompositionSolidColorBrush

Source

pub fn create_linear_gradient_brush(&self) -> CompositionLinearGradientBrush

Source

pub fn create_conic_gradient_brush(&self) -> CompositionConicGradientBrush

Source

pub fn create_radial_gradient_brush(&self) -> CompositionRadialGradientBrush

Source

pub fn create_gradient_stop_with( &self, offset: f64, color: Color, ) -> Rc<CompositionGradientStop>

Source

pub fn create_gradient_stop(&self) -> Rc<CompositionGradientStop>

Source§

impl Compositor

Source

pub fn with_render_thread( render_loop: Arc<dyn IRenderLoop>, gpu: Option<Arc<dyn IPlatformGraphics>>, use_ui_thread_for_synchronous_commits: bool, scheduler: &Rc<dyn ICompositorScheduler>, dispatcher: Arc<Dispatcher>, options: Option<CompositionOptions>, clock: Option<Arc<dyn Fn() -> Duration + Send + Sync>>, ) -> Rc<Compositor>

Creates a compositor in the render-thread mode: the thread that ticks render_loop renders the frames.

The server compositor is confined to the compositor lock, not to a thread: with use_ui_thread_for_synchronous_commits the thread of this compositor renders too, at the synchronous points (a resize, the first show), as the reference does on platforms that ask for it.

Without it, and with a loop that runs in the background, the server compositor is also confined to the thread that ticks (see is_confined_to_render_thread). The loop says where it runs when the compositor is created.

gpu is shared with the caller, who may keep its handle: the server side holds one of its own and the thread that renders asks it for the graphics context.

Source

pub fn new( gpu: Option<Arc<dyn IPlatformGraphics>>, use_ui_thread_for_synchronous_commits: bool, ) -> Rc<Compositor>

Creates a compositor that renders on the render loop registered in the service locator and commits through the media context.

The threads follow the render loop, as in the reference: with a loop that runs in the background (the thread of the platform’s render timer) that thread renders the frames, under the compositor lock (the render-thread mode); with a loop of the UI thread the UI thread renders. FERROUI_RENDER_THREAD=0 in the environment keeps the rendering on the UI thread with a background loop too (each tick is marshalled to it): a way back while the mode is young.

Source

pub fn with_scheduler( render_loop: Arc<dyn IRenderLoop>, gpu: Option<Arc<dyn IPlatformGraphics>>, use_ui_thread_for_synchronous_commits: bool, scheduler: &Rc<dyn ICompositorScheduler>, dispatcher: Arc<Dispatcher>, options: Option<CompositionOptions>, clock: Option<CompositorClock>, ) -> Rc<Compositor>

Creates a compositor with every collaborator given explicitly.

options defaults to the options registered in the service locator; clock defaults to the dispatcher’s clock.

Source

pub fn render_loop(&self) -> &Arc<dyn IRenderLoop> ⓘ

The render loop the server compositor is driven by.

Source

pub fn use_ui_thread_for_synchronous_commits(&self) -> bool

Source

pub fn server(&self) -> &Rc<ServerCompositor>

The server compositor. It belongs to the render thread: UI-thread code may only use it to drive a frame when the render loop runs on the UI thread, and in tests.

Source

pub fn with_server<R>(&self, f: impl FnOnce(&Rc<ServerCompositor>) -> R) -> R

Runs f with the server compositor under the compositor lock: the way in from this thread in either mode. What f gets must not leave it.

Source

pub fn locked_server(&self) -> Arc<LockedServerCompositor> ⓘ

The server compositor behind its lock, as a handle that may cross to the thread that renders: for work of that thread that cannot be a job of a batch, because it has to run whether or not this compositor commits again and whether or not its graphics are ready (the release of a surface that is closed). The work enters the graph with try_with, which answers None once the graph is released.

Not from upstream, where such work captures the server compositor itself.

Source

pub fn render_on_this_thread(&self) -> bool

Renders a frame on this thread, under the compositor lock: what the synchronous points do (Server.Render upstream).

§Panics

When the compositor is confined to its render thread: this thread waits for a frame there, it never renders one.

Source

pub fn renders_on_render_thread(&self) -> bool

Whether the thread that ticks the render loop renders the frames, not the thread of this compositor.

Source

pub fn is_confined_to_render_thread(&self) -> bool

Whether the thread that ticks the render loop is the only one that renders: the render-thread mode without use_ui_thread_for_synchronous_commits, on a loop that runs in the background (the condition under which the reference waits for the render thread at the synchronous points).

The render targets, the graphics context and everything else that belongs to the thread that draws are then created, used and dropped by the render thread alone. This thread still enters the compositor lock (with_server), for what does not render: it commits batches, posts jobs and waits for them.

Source

pub fn readback(&self) -> &Arc<ReadbackIndices> ⓘ

The readback indices the server writes and this side reads.

Source

pub fn dispatcher(&self) -> &Arc<Dispatcher> ⓘ

The dispatcher of the thread the compositor belongs to.

Source

pub fn clock_elapsed(&self) -> Duration

The time elapsed on the compositor clock.

Source

pub fn after_commit(&self, handler: impl Fn() + 'static) -> Rc<dyn IDisposable>

Subscribes to the notification raised after each commit.

Source

pub fn request_composition_batch_commit_async(&self) -> Arc<CompositionBatch> ⓘ

Requests the pending changes to be committed and returns the batch they will be part of.

Source

pub fn request_commit_async(&self) -> Arc<CompositionBatch> ⓘ

Requests the pending changes to be committed.

Source

pub fn commit(&self) -> Arc<CompositionBatch> ⓘ

Serializes the pending changes into a batch and hands it to the server compositor.

Source

pub fn create_server_object( &self, factory: impl FnOnce(&Rc<ServerCompositor>, ServerObjectId) -> Rc<dyn IServerObject> + Send + 'static, ) -> ServerObjectId

Allocates the id of a new server object and queues its creation for the next batch. factory runs on the render thread.

Source

pub fn register_for_serialization( &self, composition_object: Rc<dyn ICompositorSerializable>, )

Queues an object whose changes must be written to the next batch.

Source

pub fn dispose_on_next_batch(&self, obj: ServerObjectId)

Disposes a server object with the next batch, and releases it: the server compositor drops it and its id can be reused.

Source

pub fn request_composition_update(&self, action: impl FnOnce() + 'static)

Enqueues a callback to be run before the next commit.

Source

pub fn post_server_job( &self, job: impl FnOnce(&ServerCompositor) + Send + 'static, post_target: bool, )

Posts a job that runs on the render thread with the next batch: before the composition targets are rendered, or after them when post_target is set.

Source

pub fn post_server_object_job( &self, target: ServerObjectId, job: impl FnOnce(&ServerCompositor, Option<Rc<dyn IServerObject>>) + Send + 'static, post_target: bool, )

Posts a job that runs on the render thread with the next batch and receives the server object target (None when it does not exist). Upstream a job holds the server object itself; this job names it, and the object is resolved when the batch is read, so the job reaches an object that the same batch disposes.

Source

pub fn invoke_server_object_job_async<T: Send + 'static>( &self, target: ServerObjectId, job: impl FnOnce(&ServerCompositor, Option<Rc<dyn IServerObject>>) -> Result<T, ServerJobError> + Send + 'static, post_target: bool, ) -> ServerJobTask<T>

invoke_server_job_async with a job that receives the server object target; see post_server_object_job.

Source

pub fn invoke_server_job_async<T: Send + 'static>( &self, job: impl FnOnce(&ServerCompositor) -> Result<T, ServerJobError> + Send + 'static, post_target: bool, ) -> ServerJobTask<T>

Runs job on the render thread with the next batch and returns a task that completes with its result (InvokeServerJobAsync). A job that fails faults the task with its error.

Source

pub fn create_composition_visual_snapshot( &self, visual: &CompositionVisual, scaling: f64, ) -> ServerJobTask<Bitmap>

Renders a visual and its children into a new bitmap, on the render thread with the next batch, after the composition targets are rendered (CreateCompositionVisualSnapshot).

The task is faulted with a CompositionVisualSnapshotError when the visual belongs to another compositor or is not attached to a composition target (InvalidOperationException upstream, which the asynchronous method also reports through its task).

Source

pub fn try_get_render_interface_feature( &self, feature_type: TypeId, ) -> LocalFuture<Option<RenderInterfaceFeature>>

Attempts to query for a feature from the platform render interface (TryGetRenderInterfaceFeature): a future that completes with the feature, or None when the render interface has none. Awaited on the thread of the compositor; see get_render_interface_public_features for when it completes.

Upstream hands out the feature object itself, which the two threads then share. Here the feature is an Rc of the server side, so what is handed out is a RenderInterfaceFeature: a handle to the same feature that stays inside the compositor lock and lends the feature there. It keeps the feature alive as the object upstream does.

Source

pub fn try_get_composition_gpu_interop( &self, ) -> LocalFuture<Option<Rc<dyn ICompositionGpuInterop>>>

Attempts to query for the GPU interop feature from the platform render interface (TryGetCompositionGpuInterop): a future that completes with the interop with GPU objects created outside of the framework, or None when the render interface does not support it. Awaited on the thread of the compositor.

Upstream awaits the feature (TryGetRenderInterfaceFeature) and constructs the interop where the await continues: on the render thread, when a job of the render thread gave the feature. Here the feature is an object of the server side: the server part of the interop is made from it inside the lock, where the feature is read (in that job, for a confined compositor without a cache), and this thread makes the interop around it.

Source

pub fn unit_test_is_registered_for_serialization( &self, serializable: &dyn ICompositorSerializable, ) -> bool

Whether an object is queued for serialization (for unit tests).

Source

pub fn try_get_default_compositor() -> Option<Rc<Compositor>>

The compositor registered in the service locator, if any.

Trait Implementations§

Source§

impl Drop for Compositor

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

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> 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<T> ClassDefaults for T
where T: ?Sized,

Source§

fn static_constructor()

The static constructor of a type: work done once per thread, after the properties of the type are registered and before its first instance exists (class handlers, affects_render, metadata overrides). Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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.