summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/drm++/mode/framebuffer.hpp105
1 files changed, 105 insertions, 0 deletions
diff --git a/include/drm++/mode/framebuffer.hpp b/include/drm++/mode/framebuffer.hpp
new file mode 100644
index 0000000..fd904f2
--- /dev/null
+++ b/include/drm++/mode/framebuffer.hpp
@@ -0,0 +1,105 @@
+/* SPDX-License-Identifier: MIT */
+
+#pragma once
+
+///
+/// * Framebuffers
+///
+/// ...
+///
+
+
+#include "../gem.hpp"
+#include "../helper/macros.hpp"
+#include "../helper/types.hpp"
+
+#include <optional>
+#include <utility>
+#include <vector>
+
+namespace drm::mode {
+
+///
+/// Framebuffer wrapping GEM objects.
+///
+/// @throws drm::ioctl::Exception on failure
+///
+class Framebuffer {
+public:
+ ///
+ /// Create a new framebuffer.
+ /// Requires DRM_CAP_ADDFB2_MODIFIERS when modifier is specified.
+ ///
+ /// Up to 4 planes can be specified for multi-planar formats.
+ ///
+ /// @param alignments Offset and pitch for each plane
+ /// @throws std::invalid_argument if planes or alignments are invalid
+ ///
+ Framebuffer(
+ int fd,
+ u32 width,
+ u32 height,
+ u32 format,
+ std::vector<ref<const gem::Object>> planes,
+ std::vector<std::pair<u32, u32>> alignments,
+ std::optional<u64> modifier,
+ bool interlaced = false
+ );
+
+ // Private access
+ GETTER(handle)
+ GETTER(width)
+ GETTER(height)
+ GETTER(format)
+ GETTER(alignments)
+ GETTER(modifier)
+ GETTER(interlaced)
+
+ // Move constructor/operator
+ Framebuffer(Framebuffer&& other) noexcept :
+ m_fd(other.m_fd), m_handle(other.m_handle),
+ m_width(other.m_width), m_height(other.m_height),
+ m_format(other.m_format), m_alignments(std::move(other.m_alignments)),
+ m_modifier(other.m_modifier), m_interlaced(other.m_interlaced) {
+ other.m_fd = -1; // invalidate other
+ }
+
+ Framebuffer& operator=(Framebuffer&& other) noexcept {
+ if (this != &other) {
+ this->destruct();
+ this->m_fd = other.m_fd;
+ this->m_handle = other.m_handle;
+ this->m_width = other.m_width;
+ this->m_height = other.m_height;
+ this->m_format = other.m_format;
+ this->m_alignments = std::move(other.m_alignments);
+ this->m_modifier = other.m_modifier;
+ this->m_interlaced = other.m_interlaced;
+ other.m_fd = -1; // invalidate other
+ }
+
+ return *this;
+ }
+
+ // Copy constructor/operator
+ NO_COPY(Framebuffer)
+
+ // Destructor
+ ~Framebuffer() noexcept {
+ this->destruct();
+ }
+private:
+ int m_fd; // indicates validity (>= 0)
+ u32 m_handle;
+
+ u32 m_width;
+ u32 m_height;
+ u32 m_format;
+ std::vector<std::pair<u32, u32>> m_alignments;
+ std::optional<u64> m_modifier;
+ bool m_interlaced;
+
+ void destruct() noexcept;
+};
+
+}