Expand description
The composition renderer.
§Architecture and threading
As upstream, there are two compositors. The Compositor lives on the
UI thread together with the composition objects; the
server::ServerCompositor owns the server-side counterparts of those
objects and renders them. They exchange data in one direction only,
through batches: at commit the UI-thread compositor serializes the
changes of its objects into a transport::CommittedBatch and enqueues
it; at the start of each frame the server compositor applies the queued
batches.
The object model of the UI thread is Rc-based and thread-affine, so
the two sides are kept apart by construction rather than by locks:
- UI-thread objects never hold their server counterpart. They hold a
server::ServerObjectId, a plain value. A server object is created by the server compositor itself, from a factory carried by the batch (Compositor::create_server_object); changes and disposal refer to it by id. Server objects therefore need not beSend: they are created, mutated and dropped on the render thread only. - The batch queue (
server::BatchQueue) is the only crossing point. What may cross is exactly what atransport::BatchObjectcan hold plus plain values. - The few values the UI thread reads back (the clock, the readback
indices, batch completion) are
Send + Synctypes shared throughArc.
Today the server compositor runs on the thread of its compositor in
every configuration: the render loop may tick on any thread (its tasks
are Send + Sync), and a tick that arrives elsewhere is marshalled to
the compositor’s dispatcher. Running the server on a dedicated render
thread is blocked by one thing outside this module: the platform
resource handles carried by batches (std::sync::Arc<dyn IGeometryImpl>,
std::sync::Arc<crate::platform::SharedBitmapImpl>, std::sync::Arc<dyn IGlyphRunImpl>, immutable brushes and
pens) are Rc-based and so are the render contracts the server draws
with. Once those are shareable across threads, the remaining steps are
local: require Send on the Job, Create and Value payloads of
BatchObject, make the batch queue a mutex-protected queue, and
construct the server compositor on the render thread. No unsafe is
used anywhere in the composition renderer.
The browser target has no threads; it uses the same single-thread mode with a UI-thread render timer.
Re-exports§
pub use brushes::CompositionBrush;pub use brushes::CompositionConicGradientBrush;pub use brushes::CompositionGradientBrush;pub use brushes::CompositionLinearGradientBrush;pub use brushes::CompositionRadialGradientBrush;pub use brushes::CompositionSolidColorBrush;pub use brushes::CompositionSurfaceBrush;pub use brushes::CompositionMaskBrush;pub use brushes::CompositionNineGridBrush;pub use brushes::CompositionBackdropBrush;pub use brushes::CompositionEffectBrush;pub use brushes::CompositionHostBackdropBrush;pub use effects::CompositionEffectFactory;pub use effects::CompositionEffectFactoryError;pub use effects::CompositionEffectFactoryLoadStatus;pub use effects::CompositionEffectSourceParameter;pub use server::RenderSurfaces;pub use animations::BooleanKeyFrameAnimation;pub use animations::ColorKeyFrameAnimation;pub use animations::DoubleKeyFrameAnimation;pub use animations::QuaternionKeyFrameAnimation;pub use animations::RelativePointKeyFrameAnimation;pub use animations::RelativeScalarKeyFrameAnimation;pub use animations::ScalarKeyFrameAnimation;pub use animations::Vector2KeyFrameAnimation;pub use animations::Vector3DKeyFrameAnimation;pub use animations::Vector3KeyFrameAnimation;pub use animations::Vector4KeyFrameAnimation;pub use animations::VectorKeyFrameAnimation;pub use animations::AnimationController;pub use animations::AnimationControllerProgressBehavior;pub use animations::CompositionColorSpace;pub use animations::NaturalMotionAnimation;pub use animations::ScalarNaturalMotionAnimation;pub use animations::SpringScalarNaturalMotionAnimation;pub use animations::SpringVector2NaturalMotionAnimation;pub use animations::SpringVector3NaturalMotionAnimation;pub use animations::Vector2NaturalMotionAnimation;pub use animations::Vector3NaturalMotionAnimation;
Modules§
- animations
- Composition animations.
- brushes
- The composition brushes and their server-side counterparts.
- drawing
- Render data: the recorded form of what a visual draws, its resources, and the operations on it (replay, bounds, hit testing).
- effects
- The effects of the WinUI composition API (phase 6, scoped): the effect descriptions an effect factory is made from (the FerroUI form of the Win2D effects WinUI takes), the factory, and the loaded graph its brushes draw.
- expressions
- Expressions of composition animations: the variant value type, the expression tree, its parser and the functions callable from expressions.
- generated
- The composition object model generated from the composition schema.
- hit_
testing - Hit testing of the composition visual tree.
- interactions
Microsoft.UI.Composition.Interactions: interaction trackers and the visual interaction sources that drive them with input.- server
- The server (render thread) side of the composition renderer.
- system_
backdrops Microsoft.UI.Composition.SystemBackdrops(winui-materials.md): the controllers of the system backdrops (Mica and desktop acrylic), their configuration and their targets.- transport
- The transport between the UI-thread compositor and the server compositor: batches of serialized changes.
Structs§
- Alpha
Mask - The alpha mask of an element: a
CompositionSurfaceBrushthat shows the alpha of what the element draws, for aDropShadow.Maskand other composition effects. - Ambient
Light - A light that lights every point of its targets alike (WinUI
Microsoft.UI.Composition.AmbientLight):ColortimesIntensity, both animatable. - Animation
Completion - The guards of the batches a running animation belongs to. It is
Send: it is created on the UI thread with the animation and moved to the server instance of the animation, which releases it when the animation is over. - Batch
Completion Guard - The share of one batch in a running animation: dropping it tells the batch that the animation is over.
- Compositing
Renderer - A renderer that utilizes a
Compositorto render the visual tree. - Composition
Batch Completed Event Args - The arguments of the
Completedevent of a batch (WinUICompositionBatchCompletedEventArgs, which has no members of its own). - Composition
Batch Types - Batch types for
CompositionCommitBatchandCompositionScopedBatch(WinUICompositionBatchTypes, a flags enumeration). - Composition
Bitmap Cache - Caches the subtree of a visual in a bitmap.
- Composition
Clip - A clip of a visual (WinUI
Microsoft.UI.Composition.CompositionClip): the area of the visual that stays visible, with its own animatable transform (AnchorPoint,CenterPoint,Offset,RotationAngle,Scale,TransformMatrix) in the space of the visual. - Composition
Commit Batch - The group of the animations started in the current frame (WinUI
CompositionCommitBatch): it is ended when the compositor commits the frame and raisescompletedonce the animations started in the frame are over. - Composition
Container Shape - A shape that groups shapes under its transform (WinUI
Microsoft.UI.Composition.CompositionContainerShape): its shapes are drawn in order, in its space. - Composition
Custom Visual - A container visual that draws through a handler on the render thread.
- Composition
Custom Visual Handler - The state upstream’s abstract
CompositionCustomVisualHandlerkeeps, and its protected members: what a handler class embeds and returns fromICompositionCustomVisualHandler::handler_base. - Composition
Draw List Visual - The composition visual of a visual of the visual tree: draws what the visual rendered.
- Composition
Drawing Surface - A composition surface whose content is set from imported GPU images.
- Composition
Ellipse Geometry - An ellipse (WinUI
Microsoft.UI.Composition.CompositionEllipseGeometry): itscenterand its radiiradius, both animatable (Center,Radius). - Composition
Experimental Acrylic Visual - A draw list visual that draws an acrylic rectangle below its content.
- Composition
Geometry - The geometry of a sprite shape or a geometric clip (WinUI
Microsoft.UI.Composition.CompositionGeometry), with the animatable trimming of its outline:TrimStartandTrimEnd(fractions of the length of the outline, default 0 and 1) andTrimOffset(added to both, wrapping around the outline). - Composition
GpuImported Image Synchronization Capabilities - The ways the access to an imported GPU image can be synchronized.
- Composition
GpuImported Object Base - What upstream’s
CompositionGpuImportedObjectBaseholds on the side of the caller: the compositor, the task of the import and the handle of the server part. - Composition
Gradient Stop - A gradient stop of the composition brushes, with animatable color and offset.
- Composition
Imported GpuImage - A GPU image imported into the compositor.
- Composition
Imported GpuSemaphore - A GPU semaphore imported into the compositor.
- Composition
Interop - The interop of a compositor with the GPU objects of its render interface context.
- Composition
Light - A light (WinUI
Microsoft.UI.Composition.CompositionLight): it lights the visuals oftargetsand their subtrees, minus the visuals ofexclusions_from_targetsand their subtrees, while itis_enabled. A visual that some enabled light reaches shows its content multiplied by the sum of the lights that reach it, so it is dark where none of them shines. - Composition
Line Geometry - A line (WinUI
Microsoft.UI.Composition.CompositionLineGeometry) fromstarttoend, both animatable (Start,End). - Composition
Object - The part every composition object embeds: what upstream’s abstract
CompositionObjectholds. - Composition
Options - Options of the composition renderer.
- Composition
Path - The path of a
CompositionPathGeometry(WinUIMicrosoft.UI.Composition.CompositionPath): an immutable platform geometry, made from a FerroUIGeometry(aStreamGeometry, aPathGeometry, …) or from a string of path data. - Composition
Path Geometry - A geometry that shows a
CompositionPath(WinUIMicrosoft.UI.Composition.CompositionPathGeometry). - Composition
Property Set - Property sets are composition objects that allow storage of key values pairs that can be shared across the application and are not tied to the lifetime of another composition object. Property sets are most commonly used with animations, where they maintain key-value pairs that are referenced to drive portions of composition animations. Property sets provide the ability to insert key-value pairs or retrieve a value for a given key. A property set does not support a delete function – ensure you use property sets to store values that will be shared across the application.
- Composition
Rectangle Geometry - A rectangle (WinUI
Microsoft.UI.Composition.CompositionRectangleGeometry):(offset, size), both animatable (Offset,Size). - Composition
Rounded Rectangle Geometry - A rectangle with rounded corners (WinUI
Microsoft.UI.Composition.CompositionRoundedRectangleGeometry):(offset, size)with the elliptical radiicorner_radius, all animatable (CornerRadius,Offset,Size). The radii are limited to half the size. - Composition
Scoped Batch - An explicitly created group of active animations or effects (WinUI
CompositionScopedBatch). - Composition
Shape - A shape of a shape visual (WinUI
Microsoft.UI.Composition.CompositionShape), with its own animatable transform in the space of its parent (CenterPoint,Offset,RotationAngle,Scale,TransformMatrix), applied as the transform of a visual: the transform matrix, the scale and the rotation about the center point, then the offset. - Composition
Shape Collection - The shapes of a shape visual or of a container shape (WinUI
Microsoft.UI.Composition.CompositionShapeCollection), drawn in order. - Composition
Solid Color Visual - A visual that fills its size with a color.
- Composition
Sprite Shape - A shape that fills and strokes a geometry (WinUI
Microsoft.UI.Composition.CompositionSpriteShape). - Composition
Surface - A surface that a surface visual shows. The server-side counterpart provides the bitmap.
- Composition
Surface Visual - A visual that shows a composition surface.
- Composition
Target - The root of a composition visual tree: what a renderer draws to a render target.
- Composition
Tile Mode - Composition
View Box - The area of the shape coordinates a shape visual or a geometric clip
shows (WinUI
Microsoft.UI.Composition.CompositionViewBox): the rectangle(offset, size)of the shapes is mapped onto the visual bystretchand placed by the alignment ratios, as a surface brush lays out its surface.Offset,Sizeand the ratios are animatable. - Composition
Visual - A node of the composition visual tree.
- Composition
Visual Collection - The children of a composition visual.
- Composition
Visual Snapshot Error - The error of a snapshot that cannot be taken (
InvalidOperationException): seeCompositor::create_composition_visual_snapshot. - Composition
Visual Surface - A live image of the subtree of a visual, shown by a surface brush
(WinUI
Microsoft.UI.Composition.CompositionVisualSurface). - Compositor
- The compositor: manages the composition objects of the UI thread and commits their changes to the server compositor in batches.
- Distant
Light - A light from far away in one direction (WinUI
Microsoft.UI.Composition.DistantLight): every point of a flat visual is lit alike, by the cosine of the angle between the direction and the visual.Color,DirectionandIntensityare animatable. - Drop
Shadow - The shadow of a sprite or layer visual (WinUI
Microsoft.UI.Composition.DropShadow), with animatableBlurRadius,Color,OffsetandOpacity. - Element
Composition - Access to the composition visuals of the visuals of the visual tree.
- Geometric
Clip - A clip that leaves visible the inside of a geometry (WinUI
Microsoft.UI.Composition.GeometricClip), in the coordinates of the visual it is set on, or of itsview_boxwhen it has one: the view box maps the geometry onto the size of the visual as for a shape visual. The transform of the clip applies after the view box. A change of the geometry (its trimming and animations included) or of the view box changes the clip. - Inset
Clip - A clip that leaves visible the rectangle
(left_inset, top_inset, width - right_inset, height - bottom_inset)of the visual it is set on (WinUIMicrosoft.UI.Composition.InsetClip). The insets are animatable (LeftInset,TopInset,RightInset,BottomInset). - Layer
Visual - A container visual whose children are composed into one offscreen layer,
which is then drawn with the opacity of the visual and its shadow (WinUI
Microsoft.UI.Composition.LayerVisual). - Loaded
Image Surface - A composition surface whose content is an image (WinUI
Microsoft.UI.Xaml.Media.LoadedImageSurface), here backed by aBitmap. - Matrix
Utils - Helpers computing the transform of a composition visual.
- Pending
Animations - The animation instances created on the UI thread (as their factories) that have not been sent to the server yet, by the property they animate.
- Point
Light - A light from a point (WinUI
Microsoft.UI.Composition.PointLight): a point of a visual is lit by the cosine of the angle of the light to the visual, weakened by the attenuation of the distance1 / (constant + linear * d + quadratic * d^2)between the minimum and the maximum cutoff. Every member butCoordinateSpaceis animatable. - Rectangle
Clip - A clip that leaves visible a rectangle, with optional rounded corners,
in the coordinates of the visual it is set on (WinUI
Microsoft.UI.Composition.RectangleClip). Every member is animatable (Left,Top,Right,Bottom,TopLeftRadius,TopRightRadius,BottomLeftRadius,BottomRightRadius); the radii are elliptical (WinUIVector2). - Redirect
Visual - A visual that shows the subtree of another visual in its own place
(WinUI
Microsoft.UI.Composition.RedirectVisual): the source keeps rendering where it is, and the redirect visual draws the content and the children of the source again, in its own coordinates, under its own children. - Render
Interface Feature - A feature of the platform render interface
(
Compositor::try_get_render_interface_feature). - Server
GpuImported Object Base - What the server part of every imported object holds: the context and the feature the object is imported with, and the outcome of the import.
- Server
Imported GpuImage - The server part of an imported GPU image.
- Server
Imported GpuSemaphore - The server part of an imported GPU semaphore.
- Server
JobTask - The outcome of a job run on the render thread: what
Compositor::invoke_server_job_asyncreturns (a task upstream). - Shape
Visual - A visual that draws shapes (WinUI
Microsoft.UI.Composition.ShapeVisual): itsshapesin order, through itsview_boxwhen it has one, then its children. - Spot
Light - A light from a point into a cone (WinUI
Microsoft.UI.Composition.SpotLight): a point light whose light is the inner cone colour inside the inner cone, falls off to the outer cone colour and to nothing at the edge of the outer cone, and is nothing outside it. The cone angles are measured from the direction to the edge of the cone, in radians. Every member butCoordinateSpaceis animatable. - Sprite
Visual - A visual that paints its size with a composition brush and casts a
shadow (WinUI
Microsoft.UI.Composition.SpriteVisual): the shadow of its rectangle, then the brush over(0, 0, size), then its children. - Theme
Shadow Visual - The shadow visual of a caster: created by the caster’s
Visual, shown by its parent before the caster’s own visual. - Visual
Unordered Collection - A set of visuals (WinUI
Microsoft.UI.Composition.VisualUnorderedCollection): the targets or the exclusions of a light.
Enums§
- Composition
Backface Visibility - Whether the back of a visual rotated in 3D is shown (WinUI
CompositionBackfaceVisibility). - Composition
Bitmap Interpolation Mode - How a bitmap is resampled when a composition surface brush scales it
(WinUI
CompositionBitmapInterpolationMode). - Composition
Blend Mode - Composition
Border Mode - How the edges of a visual are antialiased (WinUI
CompositionBorderMode). - Composition
Composite Mode - How a visual is blended with what is behind it (WinUI
CompositionCompositeMode). - Composition
Drop Shadow Source Policy - What a drop shadow is cast from (WinUI
CompositionDropShadowSourcePolicy). - Composition
GetValue Status - The result of reading a value of a
CompositionPropertySet. - Composition
Gradient Extend Mode - Composition
Mapping Mode - How the points of a gradient brush are measured (WinUI
CompositionMappingMode). - Composition
Stretch - How the content of a composition surface brush fills the area of the
brush (WinUI
CompositionStretch). - Composition
Stroke Cap - The shape at an end of a stroke or of a dash (WinUI
CompositionStrokeCap). - Composition
Stroke Line Join - How the segments of a stroke are joined (WinUI
CompositionStrokeLineJoin). - Composition
Transparency Level - The level of transparency a composition target is rendered with.
- Loaded
Image Source Load Status - The outcome of loading a
LoadedImageSurface(WinUIMicrosoft.UI.Xaml.Media.LoadedImageSourceLoadStatus).
Constants§
- ALPHA_
MASK_ MAX_ SIZE - The largest side of the image of a mask, in pixels. A mask that would be larger is drawn smaller, and its brush scaled back up.
Traits§
- AsComposition
Object - A composition object as code refers to any composition object: a
reference parameter of an animation, an object stored in a property set
(upstream
CompositionObjectas a parameter type). - IComposition
Custom Visual Handler - The overridable members of a custom visual handler. A handler class
embeds a
CompositionCustomVisualHandlerand implements this trait. - IComposition
Draw List Visual Extension - What a class derived from the draw list visual outside of this module (the custom composition visual of a control) adds to its UI-thread side: the serialization of its own changes.
- IComposition
GpuImported Object - An imported GPU object that’s usable by composition APIs
- IComposition
GpuInterop - The import of GPU objects created outside of the framework into the compositor.
- IComposition
Importable Shared GpuContext Image - An GPU image descriptor obtained from a context from the same share group as one used by the compositor
- IComposition
Importable Shared GpuContext Object - An GPU object descriptor obtained from a context from the same share group as one used by the compositor
- IComposition
Importable Shared GpuContext Semaphore - An GPU semaphore descriptor obtained from a context from the same share group as one used by the compositor
- IComposition
Imported GpuImage - An imported GPU image object that’s usable by composition APIs
- IComposition
Imported GpuSemaphore - An imported GPU semaphore object that’s usable by composition APIs
- IComposition
Object - A UI-thread composition object as other composition objects refer to it: something with a server-side counterpart.
- IComposition
Object Animations - The animation members of
CompositionObject, written against the class that embeds one. - IComposition
Object Host - What a generated client property block needs from the composition
object that embeds it (the members of upstream
CompositionObjectthe generated code uses). - IComposition
Surface - A surface a composition surface brush shows (WinUI
ICompositionSurface): aCompositionSurface(a drawing surface), aCompositionVisualSurfaceor aLoadedImageSurface. - IComposition
Target Debug Events - Receives debugging information from a composition target while it renders a frame.
- ICompositor
Scheduler - Receives the request to commit a compositor’s pending changes; the media context implements it and schedules the commit with the next frame.
- ICompositor
Serializable - An object whose changes are serialized into the next batch of a compositor.
- IServer
GpuImported Object - The server part of an imported object: what the jobs of the render thread import, use and dispose.
Type Aliases§
- Composition
Cache Mode - The cache mode of a composition visual.
- Composition
Container Visual - A visual that can have children: every visual.
- Local
Future - A future of the thread of the compositor: what its asynchronous members
return (a
ValueTaskupstream), awaited on that thread. - Server
JobError - The error of a job run on the render thread: it crosses to the thread that asked for the job.