summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libkms++/dumbframebuffer.h5
-rw-r--r--libkms++/framebuffer.h18
-rw-r--r--libkmstest/colorbar.cpp8
-rw-r--r--libkmstest/cpuframebuffer.cpp (renamed from libkmstest/mappedbuffer.cpp)6
-rw-r--r--libkmstest/cpuframebuffer.h44
-rw-r--r--libkmstest/kmstest.h12
-rw-r--r--libkmstest/mappedbuffer.h95
-rw-r--r--libkmstest/testpat.cpp28
-rw-r--r--tests/fbtestpat.cpp4
9 files changed, 88 insertions, 132 deletions
diff --git a/libkms++/dumbframebuffer.h b/libkms++/dumbframebuffer.h
index 226a8dc..6b3ee64 100644
--- a/libkms++/dumbframebuffer.h
+++ b/libkms++/dumbframebuffer.h
@@ -5,13 +5,16 @@
namespace kms
{
-class DumbFramebuffer : public Framebuffer
+class DumbFramebuffer : public Framebuffer, public IMappedFramebuffer
{
public:
DumbFramebuffer(Card& card, uint32_t width, uint32_t height, const std::string& fourcc);
DumbFramebuffer(Card& card, uint32_t width, uint32_t height, PixelFormat format);
virtual ~DumbFramebuffer();
+ uint32_t width() const { return Framebuffer::width(); }
+ uint32_t height() const { return Framebuffer::height(); }
+
PixelFormat format() const { return m_format; }
unsigned num_planes() const { return m_num_planes; }
diff --git a/libkms++/framebuffer.h b/libkms++/framebuffer.h
index 77a6c32..25659c6 100644
--- a/libkms++/framebuffer.h
+++ b/libkms++/framebuffer.h
@@ -1,6 +1,7 @@
#pragma once
#include "drmobject.h"
+#include "pixelformats.h"
namespace kms
{
@@ -19,4 +20,21 @@ private:
uint32_t m_width;
uint32_t m_height;
};
+
+class IMappedFramebuffer {
+public:
+ virtual ~IMappedFramebuffer() { }
+
+ virtual uint32_t width() const = 0;
+ virtual uint32_t height() const = 0;
+
+ virtual PixelFormat format() const = 0;
+ virtual unsigned num_planes() const = 0;
+
+ virtual uint32_t stride(unsigned plane) const = 0;
+ virtual uint32_t size(unsigned plane) const = 0;
+ virtual uint32_t offset(unsigned plane) const = 0;
+ virtual uint8_t* map(unsigned plane) = 0;
+};
+
}
diff --git a/libkmstest/colorbar.cpp b/libkmstest/colorbar.cpp
index 811b81c..9daf4d6 100644
--- a/libkmstest/colorbar.cpp
+++ b/libkmstest/colorbar.cpp
@@ -37,7 +37,7 @@ static const uint16_t colors16[] = {
colors32[11].rgb565(),
};
-static void drm_draw_color_bar_rgb888(DumbFramebuffer& buf, int old_xpos, int xpos, int width)
+static void drm_draw_color_bar_rgb888(IMappedFramebuffer& buf, int old_xpos, int xpos, int width)
{
for (unsigned y = 0; y < buf.height(); ++y) {
RGB bcol = colors32[y * ARRAY_SIZE(colors32) / buf.height()];
@@ -53,7 +53,7 @@ static void drm_draw_color_bar_rgb888(DumbFramebuffer& buf, int old_xpos, int xp
}
}
-static void drm_draw_color_bar_rgb565(DumbFramebuffer& buf, int old_xpos, int xpos, int width)
+static void drm_draw_color_bar_rgb565(IMappedFramebuffer& buf, int old_xpos, int xpos, int width)
{
static_assert(ARRAY_SIZE(colors32) == ARRAY_SIZE(colors16), "bad colors arrays");
@@ -71,7 +71,7 @@ static void drm_draw_color_bar_rgb565(DumbFramebuffer& buf, int old_xpos, int xp
}
}
-static void drm_draw_color_bar_semiplanar_yuv(DumbFramebuffer& buf, int old_xpos, int xpos, int width)
+static void drm_draw_color_bar_semiplanar_yuv(IMappedFramebuffer& buf, int old_xpos, int xpos, int width)
{
const uint8_t colors[] = {
0xff,
@@ -99,7 +99,7 @@ static void drm_draw_color_bar_semiplanar_yuv(DumbFramebuffer& buf, int old_xpos
}
}
-void draw_color_bar(DumbFramebuffer& buf, int old_xpos, int xpos, int width)
+void draw_color_bar(IMappedFramebuffer& buf, int old_xpos, int xpos, int width)
{
switch (buf.format()) {
case PixelFormat::NV12:
diff --git a/libkmstest/mappedbuffer.cpp b/libkmstest/cpuframebuffer.cpp
index 40d5f37..3a9e52d 100644
--- a/libkmstest/mappedbuffer.cpp
+++ b/libkmstest/cpuframebuffer.cpp
@@ -1,6 +1,6 @@
#include <map>
-#include "mappedbuffer.h"
+#include "cpuframebuffer.h"
using namespace std;
@@ -37,7 +37,7 @@ static const map<PixelFormat, FormatInfo> format_info_array = {
{ PixelFormat::ABGR8888, { 1, { { 32, 1, 1 } }, } },
};
-MappedCPUBuffer::MappedCPUBuffer(uint32_t width, uint32_t height, PixelFormat format)
+CPUFramebuffer::CPUFramebuffer(uint32_t width, uint32_t height, PixelFormat format)
: m_width(width), m_height(height), m_format(format)
{
const FormatInfo& format_info = format_info_array.at(m_format);
@@ -55,7 +55,7 @@ MappedCPUBuffer::MappedCPUBuffer(uint32_t width, uint32_t height, PixelFormat fo
}
}
-MappedCPUBuffer::~MappedCPUBuffer()
+CPUFramebuffer::~CPUFramebuffer()
{
for (unsigned i = 0; i < m_num_planes; ++i) {
FramebufferPlane& plane = m_planes[i];
diff --git a/libkmstest/cpuframebuffer.h b/libkmstest/cpuframebuffer.h
new file mode 100644
index 0000000..d2073bc
--- /dev/null
+++ b/libkmstest/cpuframebuffer.h
@@ -0,0 +1,44 @@
+#pragma once
+
+#include "kms++.h"
+
+namespace kms
+{
+
+class CPUFramebuffer : public IMappedFramebuffer {
+public:
+ CPUFramebuffer(uint32_t width, uint32_t height, PixelFormat format);
+
+ virtual ~CPUFramebuffer();
+
+ CPUFramebuffer(const CPUFramebuffer& other) = delete;
+ CPUFramebuffer& operator=(const CPUFramebuffer& other) = delete;
+
+ uint32_t width() const { return m_width; }
+ uint32_t height() const { return m_height; }
+
+ PixelFormat format() const { return m_format; }
+ unsigned num_planes() const { return m_num_planes; }
+
+ uint32_t stride(unsigned plane) const { return m_planes[plane].stride; }
+ uint32_t size(unsigned plane) const { return m_planes[plane].size; }
+ uint32_t offset(unsigned plane) const { return m_planes[plane].offset; }
+ uint8_t* map(unsigned plane) { return m_planes[plane].map; }
+
+private:
+ struct FramebufferPlane {
+ uint32_t size;
+ uint32_t stride;
+ uint32_t offset;
+ uint8_t *map;
+ };
+
+ uint32_t m_width;
+ uint32_t m_height;
+ PixelFormat m_format;
+
+ unsigned m_num_planes;
+ struct FramebufferPlane m_planes[4];
+};
+
+}
diff --git a/libkmstest/kmstest.h b/libkmstest/kmstest.h
index 0564ab5..aed40fe 100644
--- a/libkmstest/kmstest.h
+++ b/libkmstest/kmstest.h
@@ -1,17 +1,15 @@
#pragma once
#include "color.h"
+#include "framebuffer.h"
namespace kms
{
-class MappedBuffer;
-class DumbFramebuffer;
+class IMappedFramebuffer;
-void draw_color_bar(kms::DumbFramebuffer& buf, int old_xpos, int xpos, int width);
+void draw_color_bar(IMappedFramebuffer& buf, int old_xpos, int xpos, int width);
-void draw_test_pattern(MappedBuffer& fb);
-void draw_test_pattern(DumbFramebuffer &fb);
+void draw_test_pattern(IMappedFramebuffer &fb);
-void draw_rect(MappedBuffer &fb, uint32_t x, uint32_t y, uint32_t w, uint32_t h, RGB color);
-void draw_rect(DumbFramebuffer &fb, uint32_t x, uint32_t y, uint32_t w, uint32_t h, RGB color);
+void draw_rect(IMappedFramebuffer &fb, uint32_t x, uint32_t y, uint32_t w, uint32_t h, RGB color);
}
diff --git a/libkmstest/mappedbuffer.h b/libkmstest/mappedbuffer.h
deleted file mode 100644
index 7c1215c..0000000
--- a/libkmstest/mappedbuffer.h
+++ /dev/null
@@ -1,95 +0,0 @@
-#pragma once
-
-#include "kms++.h"
-
-namespace kms
-{
-
-class MappedBuffer {
-public:
- MappedBuffer()
- {
- }
-
- virtual ~MappedBuffer()
- {
- }
-
- virtual uint32_t width() const = 0;
- virtual uint32_t height() const = 0;
-
- virtual PixelFormat format() const = 0;
- virtual unsigned num_planes() const = 0;
-
- virtual uint32_t stride(unsigned plane) const = 0;
- virtual uint32_t size(unsigned plane) const = 0;
- virtual uint32_t offset(unsigned plane) const = 0;
- virtual uint8_t* map(unsigned plane) = 0;
-};
-
-class MappedDumbBuffer : public MappedBuffer {
-public:
- MappedDumbBuffer(DumbFramebuffer& dumbfb)
- : m_fb(dumbfb)
- {
-
- }
-
- virtual ~MappedDumbBuffer()
- {
-
- }
-
- uint32_t width() const { return m_fb.width(); }
- uint32_t height() const { return m_fb.height(); }
-
- PixelFormat format() const { return m_fb.format(); }
- unsigned num_planes() const { return m_fb.num_planes(); }
-
- uint32_t stride(unsigned plane) const { return m_fb.stride(plane); }
- uint32_t size(unsigned plane) const { return m_fb.size(plane); }
- uint32_t offset(unsigned plane) const { return m_fb.offset(plane); }
- uint8_t* map(unsigned plane) { return m_fb.map(plane); }
-
-private:
- DumbFramebuffer& m_fb;
-};
-
-class MappedCPUBuffer : public MappedBuffer {
-public:
- MappedCPUBuffer(uint32_t width, uint32_t height, PixelFormat format);
-
- virtual ~MappedCPUBuffer();
-
- MappedCPUBuffer(const MappedCPUBuffer& other) = delete;
- MappedCPUBuffer& operator=(const MappedCPUBuffer& other) = delete;
-
- uint32_t width() const { return m_width; }
- uint32_t height() const { return m_height; }
-
- PixelFormat format() const { return m_format; }
- unsigned num_planes() const { return m_num_planes; }
-
- uint32_t stride(unsigned plane) const { return m_planes[plane].stride; }
- uint32_t size(unsigned plane) const { return m_planes[plane].size; }
- uint32_t offset(unsigned plane) const { return m_planes[plane].offset; }
- uint8_t* map(unsigned plane) { return m_planes[plane].map; }
-
-
-private:
- struct FramebufferPlane {
- uint32_t size;
- uint32_t stride;
- uint32_t offset;
- uint8_t *map;
- };
-
- uint32_t m_width;
- uint32_t m_height;
- PixelFormat m_format;
-
- unsigned m_num_planes;
- struct FramebufferPlane m_planes[4];
-};
-
-}
diff --git a/libkmstest/testpat.cpp b/libkmstest/testpat.cpp
index 059c1bc..c0541bb 100644
--- a/libkmstest/testpat.cpp
+++ b/libkmstest/testpat.cpp
@@ -13,13 +13,13 @@
#include "kms++.h"
#include "test.h"
-#include "mappedbuffer.h"
+#include "cpuframebuffer.h"
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
namespace kms
{
-static void draw_rgb_pixel(MappedBuffer& buf, unsigned x, unsigned y, RGB color)
+static void draw_rgb_pixel(IMappedFramebuffer& buf, unsigned x, unsigned y, RGB color)
{
switch (buf.format()) {
case PixelFormat::XRGB8888:
@@ -47,7 +47,7 @@ static void draw_rgb_pixel(MappedBuffer& buf, unsigned x, unsigned y, RGB color)
}
}
-static void draw_yuv422_macropixel(MappedBuffer& buf, unsigned x, unsigned y, YUV yuv1, YUV yuv2)
+static void draw_yuv422_macropixel(IMappedFramebuffer& buf, unsigned x, unsigned y, YUV yuv1, YUV yuv2)
{
ASSERT((x & 1) == 0);
@@ -92,7 +92,7 @@ static void draw_yuv422_macropixel(MappedBuffer& buf, unsigned x, unsigned y, YU
}
}
-static void draw_yuv420_macropixel(MappedBuffer& buf, unsigned x, unsigned y,
+static void draw_yuv420_macropixel(IMappedFramebuffer& buf, unsigned x, unsigned y,
YUV yuv1, YUV yuv2, YUV yuv3, YUV yuv4)
{
ASSERT((x & 1) == 0);
@@ -134,7 +134,7 @@ static void draw_yuv420_macropixel(MappedBuffer& buf, unsigned x, unsigned y,
}
}
-static RGB get_test_pattern_pixel(MappedBuffer& fb, unsigned x, unsigned y)
+static RGB get_test_pattern_pixel(IMappedFramebuffer& fb, unsigned x, unsigned y)
{
const unsigned w = fb.width();
const unsigned h = fb.height();
@@ -215,7 +215,7 @@ static RGB get_test_pattern_pixel(MappedBuffer& fb, unsigned x, unsigned y)
}
}
-static void draw_test_pattern_impl(MappedBuffer& fb)
+static void draw_test_pattern_impl(IMappedFramebuffer& fb)
{
unsigned x, y;
unsigned w = fb.width();
@@ -267,13 +267,7 @@ static void draw_test_pattern_impl(MappedBuffer& fb)
}
}
-void draw_test_pattern(DumbFramebuffer &fb)
-{
- MappedDumbBuffer mfb(fb);
- draw_test_pattern(mfb);
-}
-
-void draw_test_pattern(MappedBuffer &fb)
+void draw_test_pattern(IMappedFramebuffer &fb)
{
#ifdef DRAW_PERF_PRINT
using namespace std::chrono;
@@ -291,7 +285,7 @@ void draw_test_pattern(MappedBuffer &fb)
#endif
}
-void draw_rect(MappedBuffer &fb, uint32_t x, uint32_t y, uint32_t w, uint32_t h, RGB color)
+void draw_rect(IMappedFramebuffer &fb, uint32_t x, uint32_t y, uint32_t w, uint32_t h, RGB color)
{
for (unsigned i = x; i < x + w; ++i) {
for (unsigned j = y; j < y + h; ++j) {
@@ -300,10 +294,4 @@ void draw_rect(MappedBuffer &fb, uint32_t x, uint32_t y, uint32_t w, uint32_t h,
}
}
-void draw_rect(DumbFramebuffer &fb, uint32_t x, uint32_t y, uint32_t w, uint32_t h, RGB color)
-{
- MappedDumbBuffer mfb(fb);
- draw_rect(mfb, x, y, w, h, color);
-}
-
}
diff --git a/tests/fbtestpat.cpp b/tests/fbtestpat.cpp
index 529a688..a29ae24 100644
--- a/tests/fbtestpat.cpp
+++ b/tests/fbtestpat.cpp
@@ -12,7 +12,7 @@
#include <linux/fb.h>
#include "test.h"
-#include "mappedbuffer.h"
+#include "cpuframebuffer.h"
using namespace kms;
@@ -41,7 +41,7 @@ int main(int argc, char** argv)
FAIL_IF(ptr == MAP_FAILED, "mmap failed");
- MappedCPUBuffer buf(var.xres_virtual, var.yres_virtual, PixelFormat::XRGB8888);
+ CPUFramebuffer buf(var.xres_virtual, var.yres_virtual, PixelFormat::XRGB8888);
printf("%s: res %dx%d, virtual %dx%d, line_len %d\n",
fbdev,