Add ExtCPUFramebuffer
authorTomi Valkeinen <tomi.valkeinen@ti.com>
Thu, 24 Mar 2016 15:05:23 +0000 (17:05 +0200)
committerTomi Valkeinen <tomi.valkeinen@ti.com>
Thu, 24 Mar 2016 15:05:23 +0000 (17:05 +0200)
libkmstest/extcpuframebuffer.cpp [new file with mode: 0644]
libkmstest/extcpuframebuffer.h [new file with mode: 0644]

diff --git a/libkmstest/extcpuframebuffer.cpp b/libkmstest/extcpuframebuffer.cpp
new file mode 100644 (file)
index 0000000..145168f
--- /dev/null
@@ -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 (file)
index 0000000..172841f
--- /dev/null
@@ -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];
+};
+}