1 #pragma once
3 #include "kms++.h"
5 namespace kms
6 {
8 class MappedBuffer {
9 public:
10 MappedBuffer()
11 {
12 }
14 virtual ~MappedBuffer()
15 {
16 }
18 virtual uint32_t width() const = 0;
19 virtual uint32_t height() const = 0;
21 virtual PixelFormat format() const = 0;
22 virtual unsigned num_planes() const = 0;
24 virtual uint32_t stride(unsigned plane) const = 0;
25 virtual uint32_t size(unsigned plane) const = 0;
26 virtual uint32_t offset(unsigned plane) const = 0;
27 virtual uint8_t* map(unsigned plane) = 0;
28 };
30 class MappedDumbBuffer : public MappedBuffer {
31 public:
32 MappedDumbBuffer(DumbFramebuffer& dumbfb)
33 : m_fb(dumbfb)
34 {
36 }
38 virtual ~MappedDumbBuffer()
39 {
41 }
43 uint32_t width() const { return m_fb.width(); }
44 uint32_t height() const { return m_fb.height(); }
46 PixelFormat format() const { return m_fb.format(); }
47 unsigned num_planes() const { return m_fb.num_planes(); }
49 uint32_t stride(unsigned plane) const { return m_fb.stride(plane); }
50 uint32_t size(unsigned plane) const { return m_fb.size(plane); }
51 uint32_t offset(unsigned plane) const { return m_fb.offset(plane); }
52 uint8_t* map(unsigned plane) { return m_fb.map(plane); }
54 private:
55 DumbFramebuffer& m_fb;
56 };
58 class MappedCPUBuffer : public MappedBuffer {
59 public:
60 MappedCPUBuffer(uint32_t width, uint32_t height, PixelFormat format);
62 virtual ~MappedCPUBuffer();
64 MappedCPUBuffer(const MappedCPUBuffer& other) = delete;
65 MappedCPUBuffer& operator=(const MappedCPUBuffer& other) = delete;
67 uint32_t width() const { return m_width; }
68 uint32_t height() const { return m_height; }
70 PixelFormat format() const { return m_format; }
71 unsigned num_planes() const { return m_num_planes; }
73 uint32_t stride(unsigned plane) const { return m_planes[plane].stride; }
74 uint32_t size(unsigned plane) const { return m_planes[plane].size; }
75 uint32_t offset(unsigned plane) const { return m_planes[plane].offset; }
76 uint8_t* map(unsigned plane) { return m_planes[plane].map; }
79 private:
80 struct FramebufferPlane {
81 uint32_t size;
82 uint32_t stride;
83 uint32_t offset;
84 uint8_t *map;
85 };
87 uint32_t m_width;
88 uint32_t m_height;
89 PixelFormat m_format;
91 unsigned m_num_planes;
92 struct FramebufferPlane m_planes[4];
93 };
95 }