2 * Copyright (C) 2005-2020 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
12 #include "utils/DRMHelpers.h"
13 #include "utils/StringUtils.h"
14 #include "utils/log.h"
18 using namespace KODI::WINDOWING::GBM
;
20 CDRMPlane::CDRMPlane(int fd
, uint32_t plane
) : CDRMObject(fd
), m_plane(drmModeGetPlane(m_fd
, plane
))
23 throw std::runtime_error("drmModeGetPlane failed: " + std::string
{strerror(errno
)});
25 if (!GetProperties(m_plane
->plane_id
, DRM_MODE_OBJECT_PLANE
))
26 throw std::runtime_error("failed to get properties for plane: " +
27 std::to_string(m_plane
->plane_id
));
30 bool CDRMPlane::SupportsFormat(uint32_t format
)
32 for (uint32_t i
= 0; i
< m_plane
->count_formats
; i
++)
33 if (m_plane
->formats
[i
] == format
)
39 bool CDRMPlane::SupportsFormatAndModifier(uint32_t format
, uint64_t modifier
)
42 * Some broadcom modifiers have parameters encoded which need to be
43 * masked out before comparing with reported modifiers.
45 if (modifier
>> 56 == DRM_FORMAT_MOD_VENDOR_BROADCOM
)
46 modifier
= fourcc_mod_broadcom_mod(modifier
);
48 if (modifier
== DRM_FORMAT_MOD_LINEAR
)
50 if (!SupportsFormat(format
))
52 CLog::Log(LOGDEBUG
, "CDRMPlane::{} - format not supported: {}", __FUNCTION__
,
53 DRMHELPERS::FourCCToString(format
));
59 auto formatModifiers
= &m_modifiers_map
[format
];
60 if (formatModifiers
->empty())
62 CLog::Log(LOGDEBUG
, "CDRMPlane::{} - format not supported: {}", __FUNCTION__
,
63 DRMHELPERS::FourCCToString(format
));
67 auto formatModifier
= std::find(formatModifiers
->begin(), formatModifiers
->end(), modifier
);
68 if (formatModifier
== formatModifiers
->end())
70 CLog::Log(LOGDEBUG
, "CDRMPlane::{} - modifier ({}) not supported for format ({})",
71 __FUNCTION__
, DRMHELPERS::ModifierToString(modifier
),
72 DRMHELPERS::FourCCToString(format
));
77 CLog::Log(LOGDEBUG
, "CDRMPlane::{} - found plane format ({}) and modifier ({})", __FUNCTION__
,
78 DRMHELPERS::FourCCToString(format
), DRMHELPERS::ModifierToString(modifier
));
83 void CDRMPlane::FindModifiers()
85 auto property
= std::find_if(m_propsInfo
.begin(), m_propsInfo
.end(), [](auto& prop
) {
86 return StringUtils::EqualsNoCase(prop
->name
, "IN_FORMATS");
90 if (property
!= m_propsInfo
.end())
91 blob_id
= m_props
->prop_values
[std::distance(m_propsInfo
.begin(), property
)];
96 drmModePropertyBlobPtr blob
= drmModeGetPropertyBlob(m_fd
, blob_id
);
100 drm_format_modifier_blob
* header
= static_cast<drm_format_modifier_blob
*>(blob
->data
);
102 reinterpret_cast<uint32_t*>(reinterpret_cast<char*>(header
) + header
->formats_offset
);
103 drm_format_modifier
* mod
= reinterpret_cast<drm_format_modifier
*>(
104 reinterpret_cast<char*>(header
) + header
->modifiers_offset
);
106 for (uint32_t i
= 0; i
< header
->count_formats
; i
++)
108 std::vector
<uint64_t> modifiers
;
109 for (uint32_t j
= 0; j
< header
->count_modifiers
; j
++)
111 if (mod
[j
].formats
& 1ULL << i
)
112 modifiers
.emplace_back(mod
[j
].modifier
);
115 m_modifiers_map
.emplace(formats
[i
], modifiers
);
119 drmModeFreePropertyBlob(blob
);