I want to move very quickly a rectangle over a framebuffer in an embedded linux application. I have found that the function cfb_copyarea
may be useful. But I cannot find any ioctl over the /dev/fb device to call the function. Or can this function be called directly?
Asked
Active
Viewed 8,654 times
7

danatel
- 4,844
- 11
- 48
- 62
3 Answers
10
Here is a code to init and close FrameBuffer
class CFrameBuffer
{
void* m_FrameBuffer;
struct fb_fix_screeninfo m_FixInfo;
struct fb_var_screeninfo m_VarInfo;
int m_FBFD;
int InitFB()
{
int iFrameBufferSize;
/* Open the framebuffer device in read write */
m_FBFD = open(FB_NAME, O_RDWR);
if (m_FBFD < 0) {
printf("Unable to open %s.\n", FB_NAME);
return 1;
}
/* Do Ioctl. Retrieve fixed screen info. */
if (ioctl(m_FBFD, FBIOGET_FSCREENINFO, &m_FixInfo) < 0) {
printf("get fixed screen info failed: %s\n",
strerror(errno));
close(m_FBFD);
return 1;
}
/* Do Ioctl. Get the variable screen info. */
if (ioctl(m_FBFD, FBIOGET_VSCREENINFO, &m_VarInfo) < 0) {
printf("Unable to retrieve variable screen info: %s\n",
strerror(errno));
close(m_FBFD);
return 1;
}
/* Calculate the size to mmap */
iFrameBufferSize = m_FixInfo.line_length * m_VarInfo.yres;
printf("Line length %d\n", m_FixInfo.line_length);
/* Now mmap the framebuffer. */
m_FrameBuffer = mmap(NULL, iFrameBufferSize, PROT_READ | PROT_WRITE,
MAP_SHARED, m_FBFD,0);
if (m_FrameBuffer == NULL) {
printf("mmap failed:\n");
close(m_FBFD);
return 1;
}
return 0;
}
void CloseFB()
{
munmap(m_FrameBuffer,0);
close(m_FBFD);
}
};

SunnyShah
- 28,934
- 30
- 90
- 137
-
Than you for your answer. But this is not what I asked for. I do not want to move the pixels myself in the nmaped memory - I want to use kernel function cfb_copyarea for this. – danatel Sep 13 '09 at 15:02
-
2I like this answer. I created a test program based on this here: https://gist.github.com/1482697 – Rafal Rusin Dec 15 '11 at 20:23
-
@RafalRusin: Thanks for sharing the program. It will be of much help to me. :) – Anoop K. Prabhu Apr 29 '12 at 09:27
-
You forgot `#include
`. – Sauron Jan 21 '23 at 15:19
3
Note that this code is not entirely correct, although it will work on many linux devices, on some it won't. To calculate the framebuffer size, do not do this:
iFrameBufferSize = m_FixInfo.line_length * m_VarInfo.yres;
Instead, do this:
iFrameBufferSize = m_FixInfo.smem_len;
And your code will be more portable.
1
As far as I know after a few days of research, there is no ioctl for invoking this function. I have to write my own system call preferrably in a kernel module. Or copy the algorithm the from kernel source and use it in the user space via nmaped memory.

danatel
- 4,844
- 11
- 48
- 62