直接访问linux帧缓冲区——copyarea

发布于 2024-08-05 03:34:23 字数 114 浏览 2 评论 0原文

我想在嵌入式 Linux 应用程序中的帧缓冲区上快速移动一个矩形。我发现函数 cfb_copyarea 可能很有用。但我无法在 /dev/fb 设备上找到任何 ioctl 来调用该函数。或者可以直接调用这个函数吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

书间行客 2024-08-12 03:34:23

这是初始化和关闭 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);
}

};

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);
}

};
执着的年纪 2024-08-12 03:34:23

请注意,此代码并不完全正确,尽管它可以在许多 Linux 设备上运行,但在某些设备上则不能。要计算帧缓冲区大小,请不要执行以下操作:

iFrameBufferSize = m_FixInfo.line_length * m_VarInfo.yres;

相反,执行以下操作:

iFrameBufferSize = m_FixInfo.smem_len;

您的代码将更加可移植。

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.

不忘初心 2024-08-12 03:34:23

据我研究几天后得知,没有ioctl来调用这个函数。我必须最好在内核模块中编写自己的系统调用。或者从内核源代码复制算法并通过 nmaped 内存在用户空间中使用它。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文