1 #pragma once 2 3 #include <array> 4 #include <vector> 5 6 #include "framebuffer.h" 7 #include "pixelformats.h" 8 9 namespace kms 10 { 11 class DmabufFramebuffer : public Framebuffer 12 { 13 public: 14 DmabufFramebuffer(Card& card, uint32_t width, uint32_t height, const std::string& format, 15 std::vector<int> fds, std::vector<uint32_t> pitches, std::vector<uint32_t> offsets, std::vector<uint64_t> modifiers = {}); 16 DmabufFramebuffer(Card& card, uint32_t width, uint32_t height, PixelFormat format, 17 std::vector<int> fds, std::vector<uint32_t> pitches, std::vector<uint32_t> offsets, std::vector<uint64_t> modifiers = {}); 18 ~DmabufFramebuffer() override; 19 width()20 uint32_t width() const override { return Framebuffer::width(); } height()21 uint32_t height() const override { return Framebuffer::height(); } 22 format()23 PixelFormat format() const override { return m_format; } num_planes()24 unsigned num_planes() const override { return m_num_planes; } 25 handle(unsigned plane)26 uint32_t handle(unsigned plane) const { return m_planes.at(plane).handle; } stride(unsigned plane)27 uint32_t stride(unsigned plane) const override { return m_planes.at(plane).stride; } size(unsigned plane)28 uint32_t size(unsigned plane) const override { return m_planes.at(plane).size; } offset(unsigned plane)29 uint32_t offset(unsigned plane) const override { return m_planes.at(plane).offset; } 30 uint8_t* map(unsigned plane) override; 31 int prime_fd(unsigned plane) override; 32 33 void begin_cpu_access(CpuAccess access) override; 34 void end_cpu_access() override; 35 36 private: 37 struct FramebufferPlane { 38 uint32_t handle; 39 int prime_fd; 40 uint32_t size; 41 uint32_t stride; 42 uint32_t offset; 43 uint64_t modifier; 44 uint8_t* map; 45 }; 46 47 unsigned m_num_planes; 48 std::array<FramebufferPlane, 4> m_planes; 49 50 PixelFormat m_format; 51 52 uint32_t m_sync_flags = 0; 53 }; 54 55 } // namespace kms 56