# MediaContext

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-base/media/struct-mediacontext/

**struct** · [`ferroui-base`](/docs/0.5.0/api/ferroui-base/) · v0.5.0

```rust
struct MediaContext
```

Coordinates the work that has to happen once per frame on the UI thread:
the animation clock, layout passes and other callbacks that must run
right before rendering, and the commit of the compositors.

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/media_context.rs#L25)

## Members

- [`instance`](#function-instance)
- [`is_render_scheduled`](#function-is_render_scheduled)
- [`render`](#function-render)
- [`is_top_level_active`](#function-is_top_level_active)
- [`remove_top_level`](#function-remove_top_level)
- [`begin_invoke_on_render`](#function-begin_invoke_on_render)
- [`clock`](#function-clock)
- [`media_context_clock`](#function-media_context_clock)
- [`request_animation_frame`](#function-request_animation_frame)
- [`has_composition_batches_in_flight`](#function-has_composition_batches_in_flight)
- [`immediate_render_requested`](#function-immediate_render_requested)
- [`commit_and_request_frame`](#function-commit_and_request_frame)

<a id="function-instance"></a>

### instance

```rust
fn instance() -> Rc<MediaContext>
```

The media context of the application.

It is registered in the service locator and created on first use, so
a locator scope (a unit test) gets a fresh one.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/media_context.rs#L96)

<a id="function-is_render_scheduled"></a>

### is_render_scheduled

```rust
fn is_render_scheduled(self: &Self) -> bool
```

Whether a render pass has been requested and not yet run.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/media_context.rs#L120)

<a id="function-render"></a>

### render

```rust
fn render(self: &Self)
```

Runs a render pass: pulses the animation clock, fires the queued
pre-render callbacks and commits the compositors.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/media_context.rs#L180)

<a id="function-is_top_level_active"></a>

### is_top_level_active

```rust
fn is_top_level_active(self: &Self, key: usize) -> bool
```

Whether a top-level is registered (for unit tests).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/media_context.rs#L244)

<a id="function-remove_top_level"></a>

### remove_top_level

```rust
fn remove_top_level(self: &Self, key: usize)
```

Unregisters a top-level and stops its renderer.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/media_context.rs#L260)

<a id="function-begin_invoke_on_render"></a>

### begin_invoke_on_render

```rust
fn begin_invoke_on_render(self: &Self, callback: Rc<dyn Fn() -> ()>)
```

Queues a callback to run before the next render.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/media_context.rs#L303)

<a id="function-clock"></a>

### clock

```rust
fn clock(self: &Self) -> Rc<dyn IGlobalClock>
```

The global animation clock: what the application registers as the
`dyn IGlobalClock` service, so that every animation without an
explicit clock is pulsed by the render passes of this context.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/media_context.rs#L321)

<a id="function-media_context_clock"></a>

### media_context_clock

```rust
fn media_context_clock(self: &Self) -> &Rc<MediaContextClock>
```

The global animation clock, as its concrete type.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/media_context.rs#L326)

<a id="function-request_animation_frame"></a>

### request_animation_frame

```rust
fn request_animation_frame(self: &Self, action: impl FnOnce(SignedDuration) -> () + 'static)
```

Runs `action` with the frame time on the next pulse of the animation
clock.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/media_context.rs#L332)

<a id="function-has_composition_batches_in_flight"></a>

### has_composition_batches_in_flight

```rust
fn has_composition_batches_in_flight(self: &Self) -> bool
```

Whether a committed composition batch has not been accepted by its
server compositor yet: while one is, the render passes hold the next
commits back. Not in upstream: the session of the headless platform
asks it between two tests of a shared application.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/media_context.rs#L342)

<a id="function-immediate_render_requested"></a>

### immediate_render_requested

```rust
fn immediate_render_requested(self: &Self, compositor: &Rc<Compositor>)
```

Commits the compositor of a composition target right away and
renders it.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/media_context.rs#L459)

<a id="function-commit_and_request_frame"></a>

### commit_and_request_frame

```rust
fn commit_and_request_frame(self: &Self, compositor: &Rc<Compositor>)
```

Commits the compositor of a composition target right away and asks
its render loop for a frame out of turn, without waiting for the
frame. Not from upstream: for a platform whose frames are rendered by
another thread and shown asynchronously (the render worker of the
browser), where waiting would block this thread without the frame
being shown any sooner.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/media_context.rs#L469)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- [`ClassDefaults`](/docs/0.5.0/api/ferroui-base/trait-classdefaults/)
- `Borrow<T>`
- `BorrowMut<T>`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`
- `ErasedDestructor`
- `IntoEither`
- `ICompositorScheduler`

## Availability

Extracted for `aarch64-apple-darwin`. Cargo features are listed in the [crate index](/docs/0.5.0/api/).
