From d1b34f77d1145b2237d6c22ca7e1c5eca3eb0631 Mon Sep 17 00:00:00 2001 From: Tomi Valkeinen Date: Thu, 24 Mar 2016 17:05:23 +0200 Subject: Add ExtCPUFramebuffer --- libkmstest/extcpuframebuffer.cpp | 50 ++++++++++++++++++++++++++++++++++++++++ libkmstest/extcpuframebuffer.h | 42 +++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 libkmstest/extcpuframebuffer.cpp create mode 100644 libkmstest/extcpuframebuffer.h diff --git a/libkmstest/extcpuframebuffer.cpp b/libkmstest/extcpuframebuffer.cpp new file mode 100644 index 0000000..145168f --- /dev/null +++ b/libkmstest/extcpuframebuffer.cpp @@ -0,0 +1,50 @@ + +#include "extcpuframebuffer.h" +#include "test.h" + +using namespace std; + +namespace kms +{ + +ExtCPUFramebuffer::ExtCPUFramebuffer(uint32_t width, uint32_t height, PixelFormat format, + uint8_t* buffer, uint32_t pitch) + : m_width(width), m_height(height), m_format(format) +{ + const PixelFormatInfo& format_info = get_pixel_format_info(m_format); + + m_num_planes = format_info.num_planes; + + ASSERT(m_num_planes == 1); + + const PixelFormatPlaneInfo& pi = format_info.planes[0]; + FramebufferPlane& plane = m_planes[0]; + + plane.stride = pitch; + plane.size = plane.stride * height / pi.ysub; + plane.map = buffer; +} + +ExtCPUFramebuffer::ExtCPUFramebuffer(uint32_t width, uint32_t height, PixelFormat format, + uint8_t* buffers[4], uint32_t pitches[4]) + : m_width(width), m_height(height), m_format(format) +{ + const PixelFormatInfo& format_info = get_pixel_format_info(m_format); + + m_num_planes = format_info.num_planes; + + for (unsigned i = 0; i < format_info.num_planes; ++i) { + const PixelFormatPlaneInfo& pi = format_info.planes[i]; + FramebufferPlane& plane = m_planes[i]; + + plane.stride = pitches[i]; + plane.size = plane.stride * height / pi.ysub; + plane.map = buffers[i]; + } +} + +ExtCPUFramebuffer::~ExtCPUFramebuffer() +{ +} + +} diff --git a/libkmstest/extcpuframebuffer.h b/libkmstest/extcpuframebuffer.h new file mode 100644 index 0000000..172841f --- /dev/null +++ b/libkmstest/extcpuframebuffer.h @@ -0,0 +1,42 @@ +#pragma once + +#include "kms++.h" + +namespace kms +{ + +class ExtCPUFramebuffer : public IMappedFramebuffer +{ +public: + ExtCPUFramebuffer(uint32_t width, uint32_t height, PixelFormat format, + uint8_t* buffer, uint32_t pitch); + ExtCPUFramebuffer(uint32_t width, uint32_t height, PixelFormat format, + uint8_t* buffers[4], uint32_t pitches[4]); + virtual ~ExtCPUFramebuffer(); + + 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 0; } + uint8_t* map(unsigned plane) { return m_planes[plane].map; } + +private: + struct FramebufferPlane { + uint32_t size; + uint32_t stride; + uint8_t *map; + }; + + uint32_t m_width; + uint32_t m_height; + PixelFormat m_format; + + unsigned m_num_planes; + struct FramebufferPlane m_planes[4]; +}; +} -- cgit v1.2.3