使用 directfb绘制图像(draw image with directfb)

本文档详细介绍了如何使用DirectFB库在Linux环境下初始化帧缓冲,并创建和管理DirectFB表面,用于在全屏模式下绘制图像。代码示例包括了创建和释放DirectFB对象、设置合作级别、创建输入事件缓冲区、处理鼠标事件以及更新屏幕显示。此外,还展示了如何在屏幕上绘制鼠标光标并处理鼠标移动。
摘要由CSDN通过智能技术生成

/**********************************************************************
** Copyright (C) 2010 FreeC ORG.  All rights reserved.
** Author: Carlson Lee.
**
** This file is part of FreeC.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://freec.sourceforge.net
**
** Contact CarlsonLee_FreeC@hotmail.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
 
#include "config.h"
#include "typedef.h"
#include <linux/fb.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
//#include <asm/page.h>
#include <sys/mman.h>
#include <directfb.h>
 
#include <asm/errno.h>
#include <pthread.h>
#include "errcode.h"
#include "cncui.h"
#include "disp.h"
#include "cncdisplay.h"
#include "cnctask.h"
 
static IDirectFB *dfb = NULL;
static IDirectFBSurface *primary = NULL;
static IDirectFBDisplayLayer *layer = NULL;
static IDirectFBSurface *imageSurface = NULL;
static IDirectFBEventBuffer *mouse_events = NULL;
 
static pthread_mutex_t mutex_display = PTHREAD_MUTEX_INITIALIZER;
 
static UINT8 *pCursorBuf = NULL;
static UINT8 *mouse_bg_data = NULL;
 
#define DFBCHECK(x...)                                         /
{                                                            /
    DFBResult err = x;                                         /
    if (err != DFB_OK)                                         /
    {                                                        /
        printf("%s <%d>:/n/t", __FILE__, __LINE__ ); /
        DirectFBErrorFatal( #x, err );                         /
        goto exit;                                            /
    }                                                        /
}
#define MOUSE_WIDTH        12
#define MOUSE_HEIGHT    20
 
/* init framebuffer*/
CNC_RET dispInit(void)
{
    DFBSurfaceDescription dsc;
    pthread_t key_thread_id;    
 
    if(dfb || primary || imageSurface)
        return CERR_NONE;
 
    DFBCHECK (DirectFBInit (0, 0));
    DFBCHECK (DirectFBCreate (&dfb));
    DFBCHECK (dfb->SetCooperativeLevel (dfb, DFSCL_FULLSCREEN));
    dsc.flags = DSDESC_CAPS | DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT;
    dsc.caps  = DSCAPS_PRIMARY;
    dsc.width   = SCREEN_WIDTH;
    dsc.height   = SCREEN_HEIGHT;
//#if BYTES_PER_PIXEL==3
//    dsc.pixelformat  = DSPF_RGB24 ;
//#elif BYTES_PER_PIXEL==4
    dsc.pixelformat  = DSPF_RGB32 ;
    dfb->GetDisplayLayer(dfb, 0, &layer);
    layer->EnableCursor(layer, 1);
//#endif
    DFBCHECK (dfb->CreateSurface( dfb, &dsc, &primary ));
    dsc.flags = DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT;
    dsc.width   = SCREEN_WIDTH;
    dsc.height   = SCREEN_HEIGHT;
//#if BYTES_PER_PIXEL==3
//    dsc.pixelformat  = DSPF_RGB24 ;
//#elif BYTES_PER_PIXEL==4
    dsc.pixelformat  = DSPF_RGB32 ;
//#endif
    DFBCHECK(dfb->CreateSurface( dfb, &dsc, &imageSurface));
    DFBCHECK(dfb->CreateInputEventBuffer( dfb, DICAPS_ALL,
                                   DFB_FALS

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值