⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qgfxlinuxfb_qws.cpp

📁 qte2.3.2版本,但是里面没有configure文件.需要重新添加
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************* $Id: qt/src/kernel/qgfxlinuxfb_qws.cpp   2.3.2   edited 2001-10-08 $**** Implementation of QLinuxFbScreen (unaccelerated Linux framebuffer) class for** Embedded Qt** Created : 940721**** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.**** This file is part of the kernel module of the Qt GUI Toolkit.**** 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.**** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition** licenses for Qt/Embedded may use this file in accordance with the** Qt Embedded Commercial License Agreement provided with the Software.**** 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://www.trolltech.com/pricing.html or email sales@trolltech.com for**   information about Qt Commercial License Agreements.** See http://www.trolltech.com/gpl/ for GPL licensing information.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************/#include "qgfxraster_qws.h"#include "qmemorymanager_qws.h"#include "qwsdisplay_qws.h"#include "qpixmap.h"#include <unistd.h>#include <sys/ioctl.h>#include <sys/types.h>#include <sys/stat.h>#include <sys/mman.h>#include <fcntl.h>#include <errno.h>#include "qgfxlinuxfb_qws.h"#include "qwindowsystem_qws.h"// Used when there's no hardware acceleration, since there's no point// in storing the state in shared memorystatic int dummy_optype = 0;static int dummy_lastop = 0;/*!  \class QLinuxFbScreen  \brief QLinuxFbScreen manages the Linux framebuffer. Accelerated drivers  for Linux should inherit from it; it contains code for reading information  about the framebuffer from the Linux framebuffer interface, managing  the color palette, managing offscreen graphics memory and mapping the   framebuffer interface itself, removing the need for drivers to do this.  It also acts as a factory for the unaccelerated screen cursor and  unaccelerated QGfxes. QLinuxFbScreen is a descendant of QScreen;  there is precisely one per Qt/Embedded application.*/// Unaccelerated screen/driver setup. Can be overridden by accelerated// drivers/*!  \fn QLinuxFbScreen::QLinuxFbScreen( int display_id   Constructs a QLinuxFbScreen.*/QLinuxFbScreen::QLinuxFbScreen( int display_id ) : QScreen( display_id ){    canaccel=false;}/*!  \fn QLinuxFbScreen::~QLinuxFbScreen()  Destroys a QLinuxFbScreen.*/QLinuxFbScreen::~QLinuxFbScreen(){}/*!  \fn bool QLinuxFbScreen::connect( const QString &displaySpec )  This is called by Qt/Embedded clients to map in the framebuffer.  It should be reimplemented by accelerated drivers to map in graphics  card registers; those drivers should then call this method in order to set   up offscreen memory management.*/bool QLinuxFbScreen::connect( const QString &displaySpec ){    // Check for explicitly specified device    QRegExp r( "/dev/fb[0-9]+" );    int len;    int m = r.match( displaySpec, 0, &len );    QString dev = (m>=0) ? displaySpec.mid( m, len ) : QString("/dev/fb0");    fd=open( dev.latin1(), O_RDWR );    if (fd<0) {	qWarning("Can't open framebuffer device %s",dev.latin1());	return FALSE;    }    fb_fix_screeninfo finfo;    fb_var_screeninfo vinfo;    /* Get fixed screen information */    if (ioctl(fd, FBIOGET_FSCREENINFO, &finfo)) {	perror("reading /dev/fb0");	qWarning("Error reading fixed information");	return FALSE;    }    /* Get variable screen information */    if (ioctl(fd, FBIOGET_VSCREENINFO, &vinfo)) {	perror("reading /dev/fb0");	qWarning("Error reading variable information");	return FALSE;    }    d=vinfo.bits_per_pixel;    lstep=finfo.line_length;    int xoff = vinfo.xoffset;    int yoff = vinfo.yoffset;    const char* qwssize;    if((qwssize=getenv("QWS_SIZE"))) {	sscanf(qwssize,"%dx%d",&w,&h);	if ( (uint)w > vinfo.xres ) w = vinfo.xres;	if ( (uint)h > vinfo.xres ) h = vinfo.yres;	dw=w;	dh=h;	xoff += (vinfo.xres - w)/2;	yoff += (vinfo.yres - h)/2;    } else {	dw=w=vinfo.xres;	dh=h=vinfo.yres;    }    dataoffset = yoff * lstep + xoff * d / 8;    //qDebug("Using %dx%dx%d screen",w,h,d);    /* Figure out the size of the screen in bytes */    size = h * lstep;    //    qDebug("Framebuffer base at %lx",finfo.smem_start);    //    qDebug("Registers base %lx",finfo.mmio_start);    mapsize=finfo.smem_len;    data = (unsigned char *)mmap(0, mapsize, PROT_READ | PROT_WRITE,				 MAP_SHARED, fd, 0);    data += dataoffset;    #ifdef QT_QWS_PSION    data += 32;    #endif    if ((int)data == -1) {	perror("mapping /dev/fb0");	qWarning("Error: failed to map framebuffer device to memory.");	return FALSE;    }    canaccel=useOffscreen();    if(mapsize-size<16384) {	canaccel=false;    }    if(canaccel) {	// Figure out position of offscreen memory	// Fetch size of pool entries table from memory	// Set up pool entries pointer table and 64-bit align it	int pos=(int)data;	pos+=size;	pos+=4096;	pos+=8;	pos&=~0x7;	entryp=((int *)pos);	lowest=((unsigned int *)pos)+1;	optype=((int *)pos)+2;	lastop=((int *)pos)+3;	pos+=(sizeof(int))*4;	entries=(QPoolEntry *)pos;    } else {	optype = &dummy_optype;	lastop = &dummy_lastop;    }    // Now read in palette    if((vinfo.bits_per_pixel==8) || (vinfo.bits_per_pixel==4)) {	screencols= (vinfo.bits_per_pixel==8) ? 256 : 16;	int loopc;	startcmap = new fb_cmap;	startcmap->start=0;	startcmap->len=screencols;	startcmap->red=(unsigned short int *)		 malloc(sizeof(unsigned short int)*screencols);	startcmap->green=(unsigned short int *)		   malloc(sizeof(unsigned short int)*screencols);	startcmap->blue=(unsigned short int *)		  malloc(sizeof(unsigned short int)*screencols);	startcmap->transp=(unsigned short int *)		    malloc(sizeof(unsigned short int)*screencols);	ioctl(fd,FBIOGETCMAP,startcmap);	for(loopc=0;loopc<screencols;loopc++) {	    screenclut[loopc]=qRgb(startcmap->red[loopc] >> 8,				   startcmap->green[loopc] >> 8,				   startcmap->blue[loopc] >> 8);	}    } else {	screencols=0;    }    initted=true;    return TRUE;}/*!\fn void QLinuxFbScreen::disconnect()This simply unmaps the framebuffer*/void QLinuxFbScreen::disconnect(){    data -= dataoffset;    munmap((char*)data,mapsize);    close(fd);}//#define DEBUG_VINFOstatic void writeTerm(const char* termctl, int sizeof_termctl){    const char* tt[]={"/dev/console","/dev/tty","/dev/tty0",0};    const char** dev=tt;    while (*dev) {	int tty=::open(*dev,O_WRONLY);	if ( tty>=0 ) {	    ::write(tty,termctl,sizeof_termctl);	    ::close(tty);	}	dev++;    }}/*!\fn bool QLinuxFbScreen::initDevice()This is called by the Qt/Embedded server at startup time.It turns off console blinking, sets up the color palette, enableswrite combining on the framebuffer and initialises the offscreenmemory manager.*/bool QLinuxFbScreen::initDevice(){    // No blankin' screen, no blinkin' cursor!, no cursor!    const char termctl[]="\033[9;0]\033[?33l\033[?25l";    writeTerm(termctl,sizeof(termctl));    // Grab current mode so we can reset it    fb_var_screeninfo vinfo;    fb_fix_screeninfo finfo;    if (ioctl(fd, FBIOGET_VSCREENINFO, &vinfo)) {	qFatal("Error reading variable information in card init");	return false;    }#ifdef DEBUG_VINFO    qDebug("Greyscale %d",vinfo.grayscale);    qDebug("Nonstd %d",vinfo.nonstd);    qDebug("Red %d %d %d",vinfo.red.offset,vinfo.red.length,	   vinfo.red.msb_right);    qDebug("Green %d %d %d",vinfo.green.offset,vinfo.green.length,	   vinfo.green.msb_right);    qDebug("Blue %d %d %d",vinfo.blue.offset,vinfo.blue.length,	   vinfo.blue.msb_right);    qDebug("Transparent %d %d %d",vinfo.transp.offset,vinfo.transp.length,	   vinfo.transp.msb_right);#endif    startupw=vinfo.xres;    startuph=vinfo.yres;    startupd=vinfo.bits_per_pixel;    if (ioctl(fd, FBIOGET_FSCREENINFO, &finfo)) {	qFatal("Error reading fixed information in card init");	// It's not an /error/ as such, though definitely a bad sign	// so we return true	return true;    }#ifdef __i386__    // Now init mtrr    if(!getenv("QWS_NOMTRR")) {	int mfd=open("/proc/mtrr",O_WRONLY,0);	// MTRR entry goes away when file is closed - i.e.	// hopefully when QWS is killed	if(mfd==-1) {	    // /proc/mtrr not writable - oh well.	} else {	    mtrr_sentry sentry;	    sentry.base=(unsigned long int)finfo.smem_start;	    //qDebug("Physical framebuffer address %p",(void*)finfo.smem_start);	    // Size needs to be in 4k chunks, but that's not always	    // what we get thanks to graphics card registers. Write combining	    // these is Not Good, so we write combine what we can	    // (which is not much - 4 megs on an 8 meg card, it seems)	    unsigned int size=finfo.smem_len;	    size=size >> 22;	    size=size << 22;	    sentry.size=size;	    sentry.type=MTRR_TYPE_WRCOMB;	    if(ioctl(mfd,MTRRIOC_ADD_ENTRY,&sentry)==-1) {		//printf("Couldn't add mtrr entry for %lx %lx, %s\n",		       //sentry.base,sentry.size,strerror(errno));	    }	}    }#endif    if((vinfo.bits_per_pixel==8) || (vinfo.bits_per_pixel==4)) {	screencols= (vinfo.bits_per_pixel==8) ? 256 : 16;	fb_cmap cmap;	cmap.start=0;	cmap.len=screencols;	cmap.red=(unsigned short int *)		 malloc(sizeof(unsigned short int)*screencols);	cmap.green=(unsigned short int *)		   malloc(sizeof(unsigned short int)*screencols);	cmap.blue=(unsigned short int *)		  malloc(sizeof(unsigned short int)*screencols);	cmap.transp=(unsigned short int *)		    malloc(sizeof(unsigned short int)*screencols);		if (screencols==16) {	    if ( finfo.type == FB_TYPE_PACKED_PIXELS ) {		// We'll setup a greyscale cmap for 4bpp linear		int val = 0;		for (int idx = 0; idx < 16; idx++, val += 17) {		    cmap.red[idx] = (val<<8)|val;		    cmap.green[idx] = (val<<8)|val;		    cmap.blue[idx] = (val<<8)|val;		    screenclut[idx]=qRgb( val, val, val );		}	    } else {		// Default 16 colour palette		// Green is now trolltech green so certain images look nicer 		//			     black  d_grey l_grey white  red  green  blue cyan magenta yellow		unsigned char reds[16]   = { 0x00, 0x7F, 0xBF, 0xFF, 0xFF, 0xA2, 0x00, 0xFF, 0xFF, 0x00, 0x7F, 0x7F, 0x00, 0x00, 0x00, 0x82 };		unsigned char greens[16] = { 0x00, 0x7F, 0xBF, 0xFF, 0x00, 0xC5, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x7F, 0x7F, 0x7F };		unsigned char blues[16]  = { 0x00, 0x7F, 0xBF, 0xFF, 0x00, 0x11, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0x7F, 0x7F, 0x7F, 0x00, 0x00 };		for (int idx = 0; idx < 16; idx++) {		    cmap.red[idx] = ((reds[idx]) << 8)|reds[idx];		    cmap.green[idx] = ((greens[idx]) << 8)|greens[idx];		    cmap.blue[idx] = ((blues[idx]) << 8)|blues[idx];		    cmap.transp[idx] = 0;		    screenclut[idx]=qRgb( reds[idx], greens[idx], blues[idx] );		}	    }	} else {#ifndef QT_NO_QWS_DEPTH_8GRAYSCALE	    // Build greyscale palette	    unsigned int loopc;	    for(loopc=0;loopc<256;loopc++) {		cmap.red[loopc]=loopc << 8;		cmap.green[loopc]=loopc << 8;		cmap.blue[loopc]=loopc << 8;		cmap.transp[loopc]=0;		screenclut[loopc]=qRgb(loopc,loopc,loopc);	    }#else	    // 6x6x6 216 color cube	    int idx = 0;	    for( int ir = 0x0; ir <= 0xff; ir+=0x33 ) {		for( int ig = 0x0; ig <= 0xff; ig+=0x33 ) {		    for( int ib = 0x0; ib <= 0xff; ib+=0x33 ) {			cmap.red[idx] = (ir << 8)|ir;			cmap.green[idx] = (ig << 8)|ig;			cmap.blue[idx] = (ib << 8)|ib;			cmap.transp[idx] = 0;			screenclut[idx]=qRgb( ir, ig, ib );			idx++;		    }		}	    }	    // Fill in rest with 0	    for ( int loopc=0; loopc<40; loopc++ ) {		screenclut[idx]=0;		idx++;	    }	    screencols=idx;#endif	}		ioctl(fd,FBIOPUTCMAP,&cmap);	free(cmap.red);	free(cmap.green);	free(cmap.blue);	free(cmap.transp);    } else if(finfo.visual==FB_VISUAL_DIRECTCOLOR) {	screencols=256;	fb_cmap cmap;	cmap.start=0;	int rbits=0,gbits=0,bbits=0;	switch (vinfo.bits_per_pixel) {	  case 8:		rbits=vinfo.red.length;		gbits=vinfo.green.length;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -