Sunshine latest
Self-hosted game stream host for Moonlight.
kmsgrab.cpp File Reference

Definitions for KMS screen capture. More...

#include <errno.h>
#include <fcntl.h>
#include <filesystem>
#include <thread>
#include <unistd.h>
#include <drm_fourcc.h>
#include <linux/dma-buf.h>
#include <sys/capability.h>
#include <sys/mman.h>
#include <xf86drm.h>
#include <xf86drmMode.h>
#include "cuda.h"
#include "graphics.h"
#include "src/config.h"
#include "src/logging.h"
#include "src/platform/common.h"
#include "src/round_robin.h"
#include "src/utility.h"
#include "src/video.h"
#include "vaapi.h"
#include "wayland.h"
Include dependency graph for kmsgrab.cpp:

Classes

class  platf::kms::cap_sys_admin
 
struct  platf::kms::card_descriptor_t
 
class  platf::kms::card_t
 
struct  platf::kms::connector_t
 
struct  platf::kms::cursor_t
 
class  platf::kms::display_ram_t
 
class  platf::kms::display_t
 
class  platf::kms::display_vram_t
 
struct  platf::kms::kms_img_t
 
struct  platf::kms::monitor_t
 
class  platf::kms::plane_it_t
 
class  platf::kms::wrapper_fb
 

Macros

#define _CONVERT(x, y)
 

Typedefs

using platf::kms::conn_type_count_t = std::map<std::uint32_t, std::uint32_t>
 
using platf::kms::crtc_t = util::safe_ptr<drmModeCrtc, drmModeFreeCrtc>
 
using platf::kms::encoder_t = util::safe_ptr<drmModeEncoder, drmModeFreeEncoder>
 
using platf::kms::fb_t = std::unique_ptr<wrapper_fb>
 
using platf::kms::obj_prop_t = util::safe_ptr<drmModeObjectProperties, drmModeFreeObjectProperties>
 
using platf::kms::plane_res_t = util::safe_ptr<drmModePlaneRes, drmModeFreePlaneResources>
 
using platf::kms::plane_t = util::safe_ptr<drmModePlane, drmModeFreePlane>
 
using platf::kms::prop_blob_t = util::safe_ptr<drmModePropertyBlobRes, drmModeFreePropertyBlob>
 
using platf::kms::prop_t = util::safe_ptr<drmModePropertyRes, drmModeFreeProperty>
 
using platf::kms::res_t = util::safe_ptr<drmModeRes, drmModeFreeResources>
 
using platf::kms::version_t = util::safe_ptr<drmVersion, drmFreeVersion>
 

Functions

void platf::correlate_to_wayland (std::vector< kms::card_descriptor_t > &cds)
 
std::shared_ptr< display_tplatf::kms_display (mem_type_e hwdevice_type, const std::string &display_name, const ::video::config_t &config)
 
std::vector< std::string > platf::kms_display_names (mem_type_e hwdevice_type)
 
std::map< std::uint32_t, monitor_tplatf::kms::map_crtc_to_monitor (const std::vector< connector_t > &connectors)
 
std::string_view platf::kms::plane_type (std::uint64_t val)
 
void platf::kms::print (plane_t::pointer plane, fb_t::pointer fb, crtc_t::pointer crtc)
 

Detailed Description

Definitions for KMS screen capture.

Macro Definition Documentation

◆ _CONVERT

#define _CONVERT ( x,
y )
Value:
if (string == x) \
return DRM_MODE_CONNECTOR_##y

Function Documentation

◆ correlate_to_wayland()

void platf::correlate_to_wayland ( std::vector< kms::card_descriptor_t > & cds)

On Wayland, it's not possible to determine the position of the monitor on the desktop with KMS. Wayland does allow applications to query attached monitors on the desktop, however, the naming scheme is not standardized across implementations.

As a result, correlating the KMS output to the wayland outputs is guess work at best. But, it's necessary for absolute mouse coordinates to work.

This is an ugly hack :(