Skip to content

Commit

Permalink
platforms/common: Add mgk::get_cap_checked()
Browse files Browse the repository at this point in the history
  • Loading branch information
RAOF committed Aug 5, 2024
1 parent 8797d0d commit 1a04ed1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/platforms/common/server/kms-utils/drm_mode_resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
#include "drm_mode_resources.h"

#include <boost/throw_exception.hpp>
#include <drm_mode.h>
#include <system_error>
#include <format>
#include <xf86drm.h>

namespace mgk = mir::graphics::kms;
namespace mgkd = mgk::detail;
Expand Down Expand Up @@ -460,3 +463,17 @@ template bool mgkd::ObjectCollection<mgk::DRMModeConnectorUPtr, &mgk::get_connec
template bool mgkd::ObjectCollection<mgk::DRMModeEncoderUPtr, &mgk::get_encoder>::iterator::operator!=(iterator const&) const;
template bool mgkd::ObjectCollection<mgk::DRMModeCrtcUPtr, &mgk::get_crtc>::iterator::operator!=(iterator const&) const;
template bool mgkd::ObjectCollection<mgk::DRMModePlaneUPtr, &mgk::get_plane>::iterator::operator!=(iterator const&) const;

auto mgk::get_cap_checked(mir::Fd const& drm_node, uint64_t cap) -> uint64_t
{
uint64_t result;
if (auto err = drmGetCap(drm_node, cap, &result))
{
BOOST_THROW_EXCEPTION((
std::system_error{
-err,
std::system_category(),
std::format("Failed to query DRM capability {}", cap)}));
}
return result;
}
3 changes: 3 additions & 0 deletions src/platforms/common/server/kms-utils/drm_mode_resources.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#ifndef MIR_GRAPHICS_COMMON_KMS_UTILS_DRM_MODE_RESOURCES_H_
#define MIR_GRAPHICS_COMMON_KMS_UTILS_DRM_MODE_RESOURCES_H_

#include "mir/fd.h"
#include <xf86drm.h>
#include <xf86drmMode.h>

Expand Down Expand Up @@ -164,6 +165,8 @@ class DRMModeResources
DRMModeResUPtr const resources;
};

auto get_cap_checked(mir::Fd const& drm_node, uint64_t cap) -> uint64_t;

}
}
}
Expand Down

0 comments on commit 1a04ed1

Please sign in to comment.