Sunshine0.0.5917
Sunshine 0.0.5917
Self-hosted game stream host for Moonlight.
Loading...
Searching...
No Matches
wayland.h File Reference

Declarations for Wayland capture. More...

#include <array>
#include <bitset>
#include <chrono>
#include <cstdint>
#include <map>
#include <optional>
#include <string>
#include <vector>
#include <linux-dmabuf-unstable-v1.h>
#include <wlr-screencopy-unstable-v1.h>
#include <xdg-output-unstable-v1.h>
#include "graphics.h"
Include dependency graph for wayland.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  wl::display_t
 Wayland display connection used to dispatch capture events. More...
class  wl::dmabuf_t
 Listener state for Wayland screencopy frames backed by DMA-BUFs. More...
class  wl::frame_t
 Captured Wayland frame metadata and DMA-BUF surface state. More...
struct  wl::gbm_bo_accessors_t
 GBM buffer accessors used to export DMA-BUF plane metadata. More...
struct  wl::gbm_device_accessors_t
 Functions used to open a render node and create/destroy a GBM device on it. More...
class  wl::gbm_device_t
 Owner of a GBM device together with the render-node descriptor it was created from. More...
class  wl::interface_t
 Wayland registry state for screencopy, DMA-BUF, and output globals. More...
class  wl::monitor_t
 Wayland output metadata used to match a configured display name. More...

Typedefs

using wl::display_internal_t = util::safe_ptr<wl_display, wl_display_disconnect>
 Owning pointer for a Wayland display connection.

Enumerations

enum class  wl::screencopy_request_e { keep , copy , copy_with_damage }
 What a capture does about its screencopy request before waiting for a frame. More...

Functions

std::chrono::steady_clock::time_point wl::damage_frame_time (std::optional< std::chrono::steady_clock::time_point > compositor_time, std::chrono::steady_clock::time_point now, std::chrono::nanoseconds delay)
 Pick the time a captured frame is charged to the damage-driven budget at.
std::optional< std::uint32_t > wl::export_gbm_bo_planes (gbm_bo *bo, frame_t &frame, const gbm_bo_accessors_t &accessors)
 Export every GBM buffer plane into a captured frame descriptor.
int wl::init ()
 Initialize Wayland registry interfaces required for capture.
std::map< std::uint32_t, std::vector< std::uint64_t > > wl::intersect_modifiers (const std::map< std::uint32_t, std::vector< std::uint64_t > > &compositor_modifiers, const std::map< std::uint32_t, std::vector< std::uint64_t > > &encoder_modifiers)
 Intersect compositor and encoder modifiers to find common formats.
std::vector< std::unique_ptr< monitor_t > > wl::monitors (const char *display_name)
 Refresh the monitor list reported by the display server.
std::chrono::steady_clock::time_point wl::next_damage_request (std::chrono::steady_clock::time_point next_request, std::chrono::steady_clock::time_point frame_time, std::chrono::nanoseconds delay)
 Move the earliest time of the next damage-driven request on by one captured frame.
screencopy_request_e wl::next_screencopy_request (bool pending, bool requested_cursor, bool cursor, bool event_driven, bool have_frame)
 Decide which screencopy request a capture waits on next.
bool wl::should_wait_for_damage_request (std::chrono::steady_clock::time_point next_request, std::chrono::steady_clock::time_point now, std::chrono::nanoseconds delay)
 Determine whether a damage-driven request should wait for its budget.
bool wl::use_damage_capture (std::uint32_t screencopy_version, double stream_fps, std::int32_t refresh_mhz)
 Determine whether wlroots capture should ask for frames with copy_with_damage.
bool wl::use_vram_capture (platf::mem_type_e hwdevice_type)
 Determine whether wlroots capture should keep frames in VRAM for the requested memory type.

Detailed Description

Declarations for Wayland capture.

Enumeration Type Documentation

◆ screencopy_request_e

enum class wl::screencopy_request_e
strong

What a capture does about its screencopy request before waiting for a frame.

Enumerator
keep 

Keep waiting for the request that is already out.

copy 

Ask for a frame now.

copy_with_damage 

Ask for the next frame that differs.

Function Documentation

◆ damage_frame_time()

std::chrono::steady_clock::time_point wl::damage_frame_time ( std::optional< std::chrono::steady_clock::time_point > compositor_time,
std::chrono::steady_clock::time_point now,
std::chrono::nanoseconds delay )

Pick the time a captured frame is charged to the damage-driven budget at.

The compositor's own timestamp is the better one, it does not carry the delay of getting the frame to Sunshine. The screencopy protocol does not say which clock it is on, though. A time ahead of now, or more than one interval behind it, is not from the clock the budget runs on and would leave the budget permanently due or permanently out of reach, so the frame is charged at now instead.

Parameters
compositor_timeTime the compositor gave for the frame, if any.
nowTime the frame was received, on Sunshine's clock.
delayFrame interval of the stream.
Returns
compositor_time when it lies within one interval before now, otherwise now.

◆ export_gbm_bo_planes()

std::optional< std::uint32_t > wl::export_gbm_bo_planes ( gbm_bo * bo,
frame_t & frame,
const gbm_bo_accessors_t & accessors )

Export every GBM buffer plane into a captured frame descriptor.

Parameters
boGBM buffer whose DMA-BUF planes will be exported.
frameFrame that takes ownership of the exported file descriptors.
accessorsGBM accessors used to query the buffer.
Returns
Number of exported planes, or no value when the buffer cannot be exported.

◆ init()

int wl::init ( )

Initialize Wayland registry interfaces required for capture.

Returns
0 on success; nonzero or negative platform status on failure.

◆ intersect_modifiers()

std::map< std::uint32_t, std::vector< std::uint64_t > > wl::intersect_modifiers ( const std::map< std::uint32_t, std::vector< std::uint64_t > > & compositor_modifiers,
const std::map< std::uint32_t, std::vector< std::uint64_t > > & encoder_modifiers )

Intersect compositor and encoder modifiers to find common formats.

Parameters
compositor_modifiersModifiers supported by the compositor for each format.
encoder_modifiersModifiers supported by the encoder for each format.
Returns
Intersection of formats and modifiers supported by both.

◆ monitors()

std::vector< std::unique_ptr< monitor_t > > wl::monitors ( const char * display_name = nullptr)

Refresh the monitor list reported by the display server.

Parameters
display_nameDisplay name.
Returns
Monitors reported by the Wayland compositor, optionally filtered by name.

◆ next_damage_request()

std::chrono::steady_clock::time_point wl::next_damage_request ( std::chrono::steady_clock::time_point next_request,
std::chrono::steady_clock::time_point frame_time,
std::chrono::nanoseconds delay )

Move the earliest time of the next damage-driven request on by one captured frame.

Every captured frame costs one frame interval of budget, which holds an output that changes faster than the stream to the stream's rate. A frame that arrives after the budget ran out resets it to a quarter interval before the frame's own time, so a source running at the stream's rate is asked for with room to spare.

Parameters
next_requestEarliest request time before this frame.
frame_timeTime the compositor presented the captured frame.
delayFrame interval of the stream.
Returns
Earliest time the next frame may be asked for.

◆ next_screencopy_request()

screencopy_request_e wl::next_screencopy_request ( bool pending,
bool requested_cursor,
bool cursor,
bool event_driven,
bool have_frame )

Decide which screencopy request a capture waits on next.

A request that outlived a timeout is kept: with copy_with_damage a still picture never answers, and asking again on every timeout would pile requests up in the compositor. It is replaced when the cursor setting changed since it was made. The setting is fixed when a request is created and changing it does not damage the output, so on a still picture the old request would go on answering with the cursor as it was. The replacement is a plain copy, which brings the picture up to date at once.

The same holds when no request is out. The last frame was captured with the setting of the last request, so if the setting changed since then, the picture the stream is showing is out of date and the next request is a plain copy as well. This covers a change between two requests, and a request that could not be withdrawn and was answered with the old setting.

Parameters
pendingWhether a request is still waiting for the compositor.
requested_cursorCursor setting the last request was made with, pending or answered.
cursorCursor setting wanted now.
event_drivenWhether frames are requested with copy_with_damage.
have_frameWhether this capture has delivered a frame yet.
Returns
The request to wait on.

◆ should_wait_for_damage_request()

bool wl::should_wait_for_damage_request ( std::chrono::steady_clock::time_point next_request,
std::chrono::steady_clock::time_point now,
std::chrono::nanoseconds delay )

Determine whether a damage-driven request should wait for its budget.

Parameters
next_requestEarliest time the next frame may be asked for.
nowCurrent time.
delayFrame interval of the stream.
Returns
true when the caller should sleep until next_request. A time further off than one interval is never waited for. With frame times from damage_frame_time the budget does not get that far ahead; the bound keeps a wrong budget from stalling capture.

◆ use_damage_capture()

bool wl::use_damage_capture ( std::uint32_t screencopy_version,
double stream_fps,
std::int32_t refresh_mhz )

Determine whether wlroots capture should ask for frames with copy_with_damage.

With copy_with_damage the compositor answers when the output has a new picture, so capture follows the compositor's frames instead of sampling them on a clock of Sunshine's own. That needs version 2 of the screencopy protocol and an output that refreshes at least half again as fast as the stream. On an output running at the stream's own rate, the commits a paced copy forces are part of what keeps the output's clients on time.

Parameters
screencopy_versionVersion of the screencopy global the compositor offered.
stream_fpsFrame rate requested for the stream.
refresh_mhzRefresh rate of the captured output in mHz, 0 when the compositor did not say.
Returns
true when frames should be asked for with copy_with_damage.

◆ use_vram_capture()

bool wl::use_vram_capture ( platf::mem_type_e hwdevice_type)

Determine whether wlroots capture should keep frames in VRAM for the requested memory type.

Parameters
hwdevice_typeHardware device type requested for capture or encode.
Returns
true when the requested memory type should use the wlroots VRAM path.