summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libkms++/dumbframebuffer.cpp46
-rw-r--r--libkms++/dumbframebuffer.h4
-rw-r--r--libkmstest/conv.cpp12
3 files changed, 28 insertions, 34 deletions
diff --git a/libkms++/dumbframebuffer.cpp b/libkms++/dumbframebuffer.cpp
index 46a6e5a..730d297 100644
--- a/libkms++/dumbframebuffer.cpp
+++ b/libkms++/dumbframebuffer.cpp
@@ -104,28 +104,7 @@ void DumbFramebuffer::Create()
plane.stride = creq.pitch;
plane.size = creq.height * creq.pitch;
plane.offset = 0;
-
- /*
- printf("buf %d: %dx%d, bitspp %d, stride %d, size %d\n",
- i, creq.width, creq.height, pi->bitspp, plane->stride, plane->size);
- */
-
- /* prepare buffer for memory mapping */
- struct drm_mode_map_dumb mreq = drm_mode_map_dumb();
- mreq.handle = plane.handle;
- r = drmIoctl(card().fd(), DRM_IOCTL_MODE_MAP_DUMB, &mreq);
- if (r)
- throw invalid_argument(string("DRM_IOCTL_MODE_MAP_DUMB failed") + strerror(errno));
-
- /* perform actual memory mapping */
- m_planes[i].map = (uint8_t *)mmap(0, plane.size, PROT_READ | PROT_WRITE, MAP_SHARED,
- card().fd(), mreq.offset);
- if (plane.map == MAP_FAILED)
- throw invalid_argument(string("mmap failed: ") + strerror(errno));
-
- /* clear the framebuffer to 0 */
- memset(plane.map, 0, plane.size);
-
+ plane.map = 0;
plane.prime_fd = -1;
}
@@ -162,10 +141,27 @@ void DumbFramebuffer::Destroy()
}
}
-void DumbFramebuffer::clear()
+uint8_t* DumbFramebuffer::map(unsigned plane)
{
- for (unsigned i = 0; i < m_num_planes; ++i)
- memset(m_planes[i].map, 0, m_planes[i].size);
+ FramebufferPlane& p = m_planes[plane];
+
+ if (p.map)
+ return p.map;
+
+ /* prepare buffer for memory mapping */
+ struct drm_mode_map_dumb mreq = drm_mode_map_dumb();
+ mreq.handle = p.handle;
+ int r = drmIoctl(card().fd(), DRM_IOCTL_MODE_MAP_DUMB, &mreq);
+ if (r)
+ throw invalid_argument(string("DRM_IOCTL_MODE_MAP_DUMB failed") + strerror(errno));
+
+ /* perform actual memory mapping */
+ p.map = (uint8_t *)mmap(0, p.size, PROT_READ | PROT_WRITE, MAP_SHARED,
+ card().fd(), mreq.offset);
+ if (p.map == MAP_FAILED)
+ throw invalid_argument(string("mmap failed: ") + strerror(errno));
+
+ return p.map;
}
}
diff --git a/libkms++/dumbframebuffer.h b/libkms++/dumbframebuffer.h
index 51f5123..c221421 100644
--- a/libkms++/dumbframebuffer.h
+++ b/libkms++/dumbframebuffer.h
@@ -16,14 +16,12 @@ public:
unsigned num_planes() const { return m_num_planes; }
uint32_t handle(unsigned plane) const { return m_planes[plane].handle; }
- uint8_t* map(unsigned plane) const { return m_planes[plane].map; }
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);
uint32_t prime_fd(unsigned plane);
- void clear();
-
private:
struct FramebufferPlane {
uint32_t handle;
diff --git a/libkmstest/conv.cpp b/libkmstest/conv.cpp
index 45f4a75..cd5f8d6 100644
--- a/libkmstest/conv.cpp
+++ b/libkmstest/conv.cpp
@@ -6,7 +6,7 @@
namespace kms
{
-static RGB read_rgb(const DumbFramebuffer& fb, int x, int y)
+static RGB read_rgb(DumbFramebuffer& fb, int x, int y)
{
uint32_t *pc = (uint32_t *)(fb.map(0) + fb.stride(0) * y);
@@ -15,13 +15,13 @@ static RGB read_rgb(const DumbFramebuffer& fb, int x, int y)
return RGB((c >> 16) & 0xff, (c >> 8) & 0xff, c & 0xff);
}
-static YUV read_rgb_as_yuv(const DumbFramebuffer& fb, int x, int y)
+static YUV read_rgb_as_yuv(DumbFramebuffer& fb, int x, int y)
{
RGB rgb = read_rgb(fb, x, y);
return YUV(rgb);
}
-static void fb_rgb_to_packed_yuv(DumbFramebuffer& dst_fb, const DumbFramebuffer& src_fb)
+static void fb_rgb_to_packed_yuv(DumbFramebuffer& dst_fb, DumbFramebuffer& src_fb)
{
unsigned w = src_fb.width();
unsigned h = src_fb.height();
@@ -56,7 +56,7 @@ static void fb_rgb_to_packed_yuv(DumbFramebuffer& dst_fb, const DumbFramebuffer&
}
}
-static void fb_rgb_to_semiplanar_yuv(DumbFramebuffer& dst_fb, const DumbFramebuffer& src_fb)
+static void fb_rgb_to_semiplanar_yuv(DumbFramebuffer& dst_fb, DumbFramebuffer& src_fb)
{
unsigned w = src_fb.width();
unsigned h = src_fb.height();
@@ -91,7 +91,7 @@ static void fb_rgb_to_semiplanar_yuv(DumbFramebuffer& dst_fb, const DumbFramebuf
}
}
-static void fb_rgb_to_rgb565(DumbFramebuffer& dst_fb, const DumbFramebuffer& src_fb)
+static void fb_rgb_to_rgb565(DumbFramebuffer& dst_fb, DumbFramebuffer& src_fb)
{
unsigned w = src_fb.width();
unsigned h = src_fb.height();
@@ -113,7 +113,7 @@ static void fb_rgb_to_rgb565(DumbFramebuffer& dst_fb, const DumbFramebuffer& src
}
}
-void color_convert(DumbFramebuffer& dst, const DumbFramebuffer &src)
+void color_convert(DumbFramebuffer& dst, DumbFramebuffer &src)
{
switch (dst.format()) {
case PixelFormat::NV12: