[videodb] remove unused seasons table from episode_view
[xbmc.git] / xbmc / windowing / gbm / drm / DRMPlane.cpp
blob865beccacb41535aada2f7fb7de2308a09b3659d
1 /*
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.
7 */
9 #include "DRMPlane.h"
11 #include "DRMUtils.h"
12 #include "utils/DRMHelpers.h"
13 #include "utils/StringUtils.h"
14 #include "utils/log.h"
16 #include <algorithm>
18 using namespace KODI::WINDOWING::GBM;
20 CDRMPlane::CDRMPlane(int fd, uint32_t plane) : CDRMObject(fd), m_plane(drmModeGetPlane(m_fd, plane))
22 if (!m_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)
34 return true;
36 return false;
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));
54 return false;
57 else
59 auto formatModifiers = &m_modifiers_map[format];
60 if (formatModifiers->empty())
62 CLog::Log(LOGDEBUG, "CDRMPlane::{} - format not supported: {}", __FUNCTION__,
63 DRMHELPERS::FourCCToString(format));
64 return false;
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));
73 return false;
77 CLog::Log(LOGDEBUG, "CDRMPlane::{} - found plane format ({}) and modifier ({})", __FUNCTION__,
78 DRMHELPERS::FourCCToString(format), DRMHELPERS::ModifierToString(modifier));
80 return true;
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");
87 });
89 uint64_t blob_id = 0;
90 if (property != m_propsInfo.end())
91 blob_id = m_props->prop_values[std::distance(m_propsInfo.begin(), property)];
93 if (blob_id == 0)
94 return;
96 drmModePropertyBlobPtr blob = drmModeGetPropertyBlob(m_fd, blob_id);
97 if (!blob)
98 return;
100 drm_format_modifier_blob* header = static_cast<drm_format_modifier_blob*>(blob->data);
101 uint32_t* formats =
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);
118 if (blob)
119 drmModeFreePropertyBlob(blob);