class DisplayCompositor

Defined at line 62 of file ../../src/ui/scenic/lib/flatland/engine/display_compositor.h

The `DisplayCompositor` is responsible for compositing Flatland render data onto the display(s).

It accomplishes this either by direct hardware compositing via the display coordinator

interface, or rendering on the GPU via a custom renderer API. It also handles the

registration of sysmem buffer collections and importation of images to both the

display coordinator and the renderer via the `BufferCollectionImporter` interface. The

`BufferCollectionImporter` interface is how Flatland sessions communicate with the

`DisplayCompositor`, providing it with the necessary data to render without exposing to Flatland

the `DisplayCoordinator` or other dependencies.

Public Methods

void DisplayCompositor (async_dispatcher_t * main_dispatcher, std::shared_ptr<display::CoordinatorProxy> coordinator_proxy, const std::shared_ptr<Renderer> & renderer, fidl::WireClient<fuchsia_sysmem2::Allocator> sysmem_allocator, const DisplayCompositorConfig & config, inspect::Node inspect_node)

TODO(https://fxbug.dev/42145655): The `DisplayCompositor` has multiple parts of its code where

usage of the display coordinator is protected by locks, because of the multithreaded

environment of flatland. Ideally, we'd want the `DisplayCompositor` to have sole ownership of

the display coordinator, i.e. it would require a `unique_ptr` instead of a `shared_ptr`.

But since access to the real display coordinator is provided to clients via a `shared_ptr`,

we take in a `shared_ptr` as a parameter here. However, this could cause problems with our

locking mechanisms, as other display-coordinator clients could be accessing the same functions

and/or state at the same time as the `DisplayCompositor` without making use of locks.

Defined at line 193 of file ../../src/ui/scenic/lib/flatland/engine/display_compositor.cc

display::CoordinatorProxy * GetDisplayCoordinatorForTest ()

Defined at line 194 of file ../../src/ui/scenic/lib/flatland/engine/display_compositor.h

void ~DisplayCompositor ()

Defined at line 245 of file ../../src/ui/scenic/lib/flatland/engine/display_compositor.cc

fpromise::promise<> ImportBufferCollection (allocation::GlobalBufferCollectionId collection_id, fidl::WireClient<fuchsia_sysmem2::Allocator> & sysmem_allocator, fidl::ClientEnd<fuchsia_sysmem2::BufferCollectionToken> token, BufferCollectionUsage usage, std::optional<fuchsia_math::SizeU> size)

`BufferCollectionImporter`

Only called from the main thread.

Defined at line 301 of file ../../src/ui/scenic/lib/flatland/engine/display_compositor.cc

void ReleaseBufferCollection (allocation::GlobalBufferCollectionId collection_id, BufferCollectionUsage usage_type)

`BufferCollectionImporter`

Only called from the main thread.

Defined at line 441 of file ../../src/ui/scenic/lib/flatland/engine/display_compositor.cc

fpromise::promise<> ImportBufferImage (const allocation::ImageMetadata & metadata, BufferCollectionUsage usage_type)

`BufferCollectionImporter`

Called from main thread or Flatland threads.

Defined at line 644 of file ../../src/ui/scenic/lib/flatland/engine/display_compositor.cc

void ReleaseBufferImage (allocation::GlobalImageId image_id)

`BufferCollectionImporter`

Called from main thread or Flatland threads.

Defined at line 740 of file ../../src/ui/scenic/lib/flatland/engine/display_compositor.cc

RenderFrameResult RenderFrame (uint64_t frame_number, zx::time presentation_time, std::span<const RenderData> render_data_list, std::vector<zx::event> release_fences, std::vector<zx::counter> release_counters, std::vector<zx::counter> present_fences, scheduling::FramePresentedCallback callback, RenderFrameTestArgs test_args)

Generates frame and presents it to display. This may involve directly scanning out client

images, or it may involve first using the GPU to composite (some of) these images into a single

image which is then scanned out.

`args` can be used to customize behavior in tests. Production code should omit this arg; the

default values are correct for production use cases.

Only called from the main thread.

Defined at line 1158 of file ../../src/ui/scenic/lib/flatland/engine/display_compositor.cc

void SkipFrame (uint64_t frame_number, std::vector<zx::event> release_fences, std::vector<zx::counter> release_counters, std::vector<zx::counter> present_fences, scheduling::FramePresentedCallback callback)

Notifies the compositor and `ReleaseFenceManager` that a frame was skipped without rendering.

`frame_number` must exceed every frame number previously passed to `RenderFrame()` or

`SkipFrame()`. Only called from the main thread.

Defined at line 1229 of file ../../src/ui/scenic/lib/flatland/engine/display_compositor.cc

fpromise::promise<> AddDisplay (display::Display * display, DisplayInfo info, uint32_t num_render_targets, fuchsia_sysmem2::BufferCollectionInfo * out_collection_info)

Register a new display to the `DisplayCompositor`, which also generates the render targets to

be presented on the display when compositing on the GPU. If `num_render_targets` is 0, this

function will not create any render targets for GPU composition for that display. The buffer

collection info is also returned back to the caller via an output parameter

`num_render_targets` is 0. Otherwise, a valid handle to return the buffer collection data is

required.

TODO(https://fxbug.dev/42137737): We need to figure out exactly how we want the display to

anchor to the Flatland hierarchy. Only called from the main thread.

Defined at line 1347 of file ../../src/ui/scenic/lib/flatland/engine/display_compositor.cc

void SetColorConversionValues (const fidl::Array<float, 9> & coefficients, const fidl::Array<float, 3> & preoffsets, const fidl::Array<float, 3> & postoffsets)

Values needed to adjust the color of the framebuffer as a postprocessing effect.

Only called from the main thread.

Defined at line 1462 of file ../../src/ui/scenic/lib/flatland/engine/display_compositor.cc

bool SetMinimumRgb (uint8_t minimum_rgb)

Clamps the minimum value for all channels on all pixels on the display to this number.

Only called from the main thread.

Defined at line 1474 of file ../../src/ui/scenic/lib/flatland/engine/display_compositor.cc

zx_status_t SetDisplayPowerMode (display::DisplayId display_id, fuchsia_hardware_display_types::PowerMode mode)

Sets the power mode of `display_id`, synchronously. Returns `ZX_OK`, or one of the

errors of `fuchsia.ui.display.singleton/DisplayPower`:

- `ZX_ERR_NOT_FOUND` if this compositor or the coordinator does not have the display

- `ZX_ERR_NOT_SUPPORTED` if the driver or hardware cannot do `mode`

- `ZX_ERR_INTERNAL` for any other failure.

On `kOff`, frames applied before this call will never be acknowledged by a vsync, so

their release fences are signaled and their frame-presented callbacks invoked now;

then a solid black config is committed, so that the panel shows black rather than the

last frame when it is powered on again. The dropped configs and flushed fences are

shared by all displays.

Only called from the main thread.

Defined at line 1491 of file ../../src/ui/scenic/lib/flatland/engine/display_compositor.cc

bool IsDisplayDark (display::DisplayId display_id)

False for a display this compositor does not have. Only called from the main

thread.

Defined at line 1563 of file ../../src/ui/scenic/lib/flatland/engine/display_compositor.cc

void EnsureGpuImagesImported (std::span<const ResolvedLayer> layers)

Runs any pending lazy GPU imports for image layers in `layers`. Used by screenshot /

screen-capture paths that call `Renderer::Render()` directly via `Engine::GetRenderables()`.

Must be called on the main thread (`main_dispatcher_`). Best-effort: if an import fails, the

image stays unimported, is not retried on subsequent calls, and `Renderer::Render()` skips it.

Defined at line 614 of file ../../src/ui/scenic/lib/flatland/engine/display_compositor.cc

Enumerations

enum class RenderFrameResult
Name Value
kDirectToDisplay 0
kGpuComposition 1
kFailure 2

Describes the result of `RenderFrame()`. If it succeeds it is either by showing client images

directly on the display, or by first using the GPU to composite them into a single image.

Defined at line 67 of file ../../src/ui/scenic/lib/flatland/engine/display_compositor.h

Records

Friends

class DisplayCompositorTest
class DisplayCompositorPixelTest
class DisplayCompositorSmokeTest