30#include <EGL/eglext.h>
33#include <drm_fourcc.h>
35#include <xf86drmMode.h>
52 m_userDrmDevice(m_pConfig->ConfigDrmDevice),
53 m_userDrmConnector(m_pConfig->ConfigDrmConnector)
284 return std::abs(
a - b) < 0.001;
303 for (
size_t i = 0;
i <
modes.size();
i++) {
306 if (mode->hdisplay !=
modes[
i].width ||
307 mode->vdisplay !=
modes[
i].height ||
309 interlaced !=
modes[
i].interlaced) {
332 for (
size_t i = 0;
i <
modes.size();
i++) {
466 LOGINFO(
"DRM Setup: Using Monitor Mode %dx%d@%.2fHz on %s (%s), m_crtcId %d crtc_idx %d",
517 for (
k = 0;
k <
plane->count_formats;
k++) {
520 switch (
plane->formats[
k]) {
613 LOGWARNING(
"drmdevice: %s: No suitable plane for Picture-in-Picture found. PIP will be disabled.",
__FUNCTION__);
666 strcat(
str_zpos,
"hardcode them to 0 and 1, because they are equal");
694 LOGINFO(
"DRM setup - CRTC: %i video_plane: %i (%s %" PRIu64 ") osd_plane: %i (%s %" PRIu64 ") pip_plane: %i (%s %" PRIu64 ") m_useZpos: %d",
707 LOGINFO(
"DRM setup - CRTC: %i video_plane: %i (%s %" PRIu64 ") osd_plane: %i (%s %" PRIu64 ") m_useZpos: %d (pip disbled)",
760 for (
int i = 0, width = 0;
i <
connector->count_modes;
i++) {
784 LOGERROR(
"drmdevice: %s: No monitor mode found! Probably no monitor connected, giving up!",
__FUNCTION__);
984 LOGINFO(
"DRM Setup: EGL context initialized");
1048 buf->SetNumPlanes(num_planes);
1049 for (
int i = 0;
i < num_planes;
i++) {
1057 buf->SetNumObjects(1);
1058 buf->SetObjectIndex(0, 0);
1077 buf->SetNumPlanes(1);
1085 buf->SetNumObjects(1);
1086 buf->SetObjectIndex(0, 0);
1091 buf->PrimeHandle(),
buf->Pitch(),
buf->Offset(), &
id, 0);
1433 LOGDEBUG2(
L_DRM,
"drmdevice: %s: failed to set hdr property blob: blob id %d connector_id %d, m_hdrMetadata %d ret %d",
bool m_glInitiated
true, if OpenGL/ES context is initiated
int SetConnectorHdrOutputMetadata(drmModeAtomicReqPtr, uint32_t)
int m_userReqDisplayHeight
user requested display height
drmModeModeInfo m_drmModeInfo
mode info
cDrmDevice(cVideoRender *, cSoftHdConfig *)
Create a drm device.
const char * m_userDrmConnector
user requested drm connector
int InitGbm(void)
Init gbm device and surface.
cDrmBuffer * GetBufFromBo(struct gbm_bo *)
Get a drm buffer from a gbm buffer object.
int GetPropertyValue(uint32_t, uint32_t, const char *, uint64_t *)
Get a drm property value.
int SetConnectorColorspace(drmModeAtomicReqPtr, uint32_t)
int InitEGL(void)
Init EGL context.
int CreateModeBlob(uint32_t *)
int m_userReqOsdWidth
user requested osd width
int CreatePropertyBlob(uint32_t *)
Wrapper to create a property blob.
uint32_t m_hdrMetadata
property id of HDR_OUTPUT_METADATA
int GetVideoPlaneColorRange(uint64_t *)
cDrmPlane m_videoPlane
the video drm plane
int DestroyHdrBlob(uint32_t)
struct gbm_surface * m_pGbmSurface
pointer to the gbm surface
uint32_t GetPropertyID(uint32_t, uint32_t, const char *)
Get a property ID.
int FindMode(void)
Find a suitable mode from the current connector.
int SetVideoPlaneColorEncoding(drmModeAtomicReqPtr, uint32_t)
EGLContext m_eglContext
EGL context.
int SetPropertyRequest(drmModeAtomicReqPtr, uint32_t, uint32_t, const char *, uint64_t)
Add a drm property to an atomic modeset request.
int SetCrtcModeId(drmModeAtomicReqPtr, uint32_t)
int32_t FindCrtcForConnector(const drmModeRes *, const drmModeConnector *)
Find the CRTC_ID for the given connector.
EGLSurface m_eglSurface
EGL surface.
int HandleEvent(void)
Poll for a drm event.
bool CanHandleMode(sDrmMode *)
Return true, if the given mode is one of the collected ones.
bool m_userReqDisplayInterlaced
user requested display interlaced mode
double m_userReqDisplayRefreshRate
user requested display refresh rate
int m_userReqDisplayWidth
user requested display width
cSoftHdConfig * m_pConfig
pointer to cSoftHdConfig object
int DestroyModeBlob(uint32_t)
cDrmPlane m_pipPlane
the pip drm plane
drmModeCrtc * m_drmModeCrtcSaved
saved CRTC infos
int CreateHdrBlob(struct hdr_output_metadata *, size_t, uint32_t *)
int m_userReqOsdHeight
user requested osd height
int m_fdDrm
drm file descriptor
uint64_t m_zposPip
zpos of pip plane
std::string m_connectorName
drm connector name
int SetConnectorHdrBlobProperty(uint32_t)
EGLDisplay m_eglDisplay
EGL display.
void SaveCrtc(void)
Save information of a CRTC.
int ReInit(void)
Re-Init the drm device with a new connector mode.
uint32_t m_connectorId
connector id
void RestoreCrtc(void)
Restore information of a CRTC.
void Close(void)
Close the drm file handle.
uint32_t m_crtcId
current crtc ID
int SetConnectorCrtcId(drmModeAtomicReqPtr)
uint32_t m_crtcIndex
current crtc index
int SetCrtcActive(drmModeAtomicReqPtr, uint32_t)
cVideoRender * m_pRender
pointer to cVideoRender object
int Init(void)
Initiate the drm device.
uint64_t m_zposPrimary
zpos of primary plane
drmEventContext m_drmEventCtx
drm event context
bool m_useZpos
is set, if drm hardware can use zpos
struct gbm_device * m_pGbmDevice
pointer to the gbm device
cDrmPlane m_osdPlane
the osd drm plane
int SetVideoPlaneColorRange(drmModeAtomicReqPtr, uint32_t)
void InitEvent(void)
Init the event context.
const char * m_userDrmDevice
user requested drm device
uint64_t m_zposOverlay
zpos of overlay plane
int HasZpos(int)
Check, if the plane is able to set the zpos property.
void FillProperties(int)
Fill the plane properties.
void SetZpos(uint64_t zpos)
void SetType(uint64_t type)
sDrmMode RequestedDrmMode
is set to the requested mode which should be changed to
std::vector< sDrmMode > CollectedDrmModes
collected available drm modes on the current connector
sDrmMode AutoDetectedDrmMode
auto detected mode on the first startup (maybe equal to UserSetMode)
const char * ConfigOsdResolution
osd resolution (syntax: "1920x1080")
sDrmMode UserSetDrmMode
user requested drm mode on the current connector
sDrmMode CurrentDrmMode
currently used drm mode on the current connector
void SetScreenSize(int, int, double, bool)
Wrapper to set the screen size in the device.
void SetOsdSize(int, int)
Wrapper to set the osd size in the device.
Plugin Configuration Header File.
static double GetRefreshRateHz(drmModeModeInfo *modeInfo)
Calculate the refresh rate of the given mode to get the precise value and don't use m_drmModeInfo....
PFNEGLGETPLATFORMDISPLAYEXTPROC get_platform_display
static int TestCaps(int fd)
Test drm capabilities.
PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC get_platform_surface
static std::string ConnectorName(drmModeConnector *connector)
Returns the connector type name if available.
__attribute__((weak)) union gbm_bo_handle gbm_bo_get_handle_for_plane(struct gbm_bo *bo
static bool InterlacedMode(uint32_t flags)
Returns true, if the interlaced flag of the mode is set.
static bool AlmostEqual(double a, double b)
Return true, if both values are equivalent within a tolerance.
constexpr std::array DrmModeWhitelist
Whitelist of possible drm modes.
drmModeConnector * FindDrmConnector(int, drmModeRes *, const char *)
Find a suitable connector, preferably a connected one.
static void drm_fb_destroy_callback(struct gbm_bo *bo, void *data)
Callback function to destroy a drm buffer which stays in the gbm_bo's user data.
EGLConfig GetEGLConfig(void)
Get a suitable EGLConfig.
static int FindDrmDevice(drmModeRes **resources)
Find and open a suitable device with the wanted capabilities.
static int32_t FindCrtcForEncoder(const drmModeRes *resources, const drmModeEncoder *encoder)
Find the CRTC_ID for the given encoder.
static int get_resources(int fd, drmModeRes **resources)
static bool Contains(drmModeModeInfo *mode, std::vector< sDrmMode > modes)
Test, if the given mode is included in the given array.
static const EGLint context_attribute_list[]
static int OpenDrmDevice(const char *device, drmModeRes **resources)
Open the given device.
#define LOGDEBUG2
log to LOG_DEBUG and add a prefix
#define LOGDEBUG
log to LOG_DEBUG
#define LOGERROR
log to LOG_ERR
#define LOGWARNING
log to LOG_WARN
#define LOGINFO
log to LOG_INFO
#define LOGFATAL
log to LOG_ERR and abort
#define EGL_CHECK(stmt)
eglCheckError macro
@ L_OPENGL
opengl osd logs
Holds possible display configurations.
bool interlaced
is this an interlaced mode?
double refreshRateHz
display refresh rate
Video Renderer (Display) Header File.