From 83d27aa30549194068fef320f735245a7735a5ea Mon Sep 17 00:00:00 2001 From: Tomi Valkeinen Date: Tue, 15 Mar 2016 11:46:09 +0200 Subject: Add IMappedFramebuffer and remove MappedBuffer --- libkmstest/colorbar.cpp | 8 ++-- libkmstest/cpuframebuffer.cpp | 67 ++++++++++++++++++++++++++++++ libkmstest/cpuframebuffer.h | 44 ++++++++++++++++++++ libkmstest/kmstest.h | 12 +++--- libkmstest/mappedbuffer.cpp | 67 ------------------------------ libkmstest/mappedbuffer.h | 95 ------------------------------------------- libkmstest/testpat.cpp | 28 ++++--------- 7 files changed, 128 insertions(+), 193 deletions(-) create mode 100644 libkmstest/cpuframebuffer.cpp create mode 100644 libkmstest/cpuframebuffer.h delete mode 100644 libkmstest/mappedbuffer.cpp delete mode 100644 libkmstest/mappedbuffer.h (limited to 'libkmstest') 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/cpuframebuffer.cpp b/libkmstest/cpuframebuffer.cpp new file mode 100644 index 0000000..3a9e52d --- /dev/null +++ b/libkmstest/cpuframebuffer.cpp @@ -0,0 +1,67 @@ +#include + +#include "cpuframebuffer.h" + +using namespace std; + +namespace kms { + +struct FormatPlaneInfo +{ + uint8_t bitspp; /* bits per (macro) pixel */ + uint8_t xsub; + uint8_t ysub; +}; + +struct FormatInfo +{ + uint8_t num_planes; + struct FormatPlaneInfo planes[4]; +}; + +static const map format_info_array = { + /* YUV packed */ + { PixelFormat::UYVY, { 1, { { 32, 2, 1 } }, } }, + { PixelFormat::YUYV, { 1, { { 32, 2, 1 } }, } }, + { PixelFormat::YVYU, { 1, { { 32, 2, 1 } }, } }, + { PixelFormat::VYUY, { 1, { { 32, 2, 1 } }, } }, + /* YUV semi-planar */ + { PixelFormat::NV12, { 2, { { 8, 1, 1, }, { 16, 2, 2 } }, } }, + { PixelFormat::NV21, { 2, { { 8, 1, 1, }, { 16, 2, 2 } }, } }, + /* RGB16 */ + { PixelFormat::RGB565, { 1, { { 16, 1, 1 } }, } }, + /* RGB32 */ + { PixelFormat::XRGB8888, { 1, { { 32, 1, 1 } }, } }, + { PixelFormat::XBGR8888, { 1, { { 32, 1, 1 } }, } }, + { PixelFormat::ARGB8888, { 1, { { 32, 1, 1 } }, } }, + { PixelFormat::ABGR8888, { 1, { { 32, 1, 1 } }, } }, +}; + +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); + + m_num_planes = format_info.num_planes; + + for (unsigned i = 0; i < format_info.num_planes; ++i) { + const FormatPlaneInfo& pi = format_info.planes[i]; + FramebufferPlane& plane = m_planes[i]; + + plane.stride = width * pi.bitspp / 8 / pi.xsub; + plane.size = plane.stride * height/ pi.ysub; + plane.offset = 0; + plane.map = new uint8_t[plane.size]; + } +} + +CPUFramebuffer::~CPUFramebuffer() +{ + for (unsigned i = 0; i < m_num_planes; ++i) { + FramebufferPlane& plane = m_planes[i]; + + delete plane.map; + } +} + +} 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.cpp b/libkmstest/mappedbuffer.cpp deleted file mode 100644 index 40d5f37..0000000 --- a/libkmstest/mappedbuffer.cpp +++ /dev/null @@ -1,67 +0,0 @@ -#include - -#include "mappedbuffer.h" - -using namespace std; - -namespace kms { - -struct FormatPlaneInfo -{ - uint8_t bitspp; /* bits per (macro) pixel */ - uint8_t xsub; - uint8_t ysub; -}; - -struct FormatInfo -{ - uint8_t num_planes; - struct FormatPlaneInfo planes[4]; -}; - -static const map format_info_array = { - /* YUV packed */ - { PixelFormat::UYVY, { 1, { { 32, 2, 1 } }, } }, - { PixelFormat::YUYV, { 1, { { 32, 2, 1 } }, } }, - { PixelFormat::YVYU, { 1, { { 32, 2, 1 } }, } }, - { PixelFormat::VYUY, { 1, { { 32, 2, 1 } }, } }, - /* YUV semi-planar */ - { PixelFormat::NV12, { 2, { { 8, 1, 1, }, { 16, 2, 2 } }, } }, - { PixelFormat::NV21, { 2, { { 8, 1, 1, }, { 16, 2, 2 } }, } }, - /* RGB16 */ - { PixelFormat::RGB565, { 1, { { 16, 1, 1 } }, } }, - /* RGB32 */ - { PixelFormat::XRGB8888, { 1, { { 32, 1, 1 } }, } }, - { PixelFormat::XBGR8888, { 1, { { 32, 1, 1 } }, } }, - { PixelFormat::ARGB8888, { 1, { { 32, 1, 1 } }, } }, - { PixelFormat::ABGR8888, { 1, { { 32, 1, 1 } }, } }, -}; - -MappedCPUBuffer::MappedCPUBuffer(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); - - m_num_planes = format_info.num_planes; - - for (unsigned i = 0; i < format_info.num_planes; ++i) { - const FormatPlaneInfo& pi = format_info.planes[i]; - FramebufferPlane& plane = m_planes[i]; - - plane.stride = width * pi.bitspp / 8 / pi.xsub; - plane.size = plane.stride * height/ pi.ysub; - plane.offset = 0; - plane.map = new uint8_t[plane.size]; - } -} - -MappedCPUBuffer::~MappedCPUBuffer() -{ - for (unsigned i = 0; i < m_num_planes; ++i) { - FramebufferPlane& plane = m_planes[i]; - - delete plane.map; - } -} - -} 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); -} - } -- cgit v1.2.3