本文以qte 2.3.10为例,虽然这已经是很老的版本了,但是在某些场合它仍然是非常适合的。
qpainter_qws.cpp
QPainter::begin():
gfx = ((QPaintDevice *)pdev)->graphicsContext();
qwidget_qws.cpp
QWidget::graphicsContext():
qgfx_qws=qwsDisplay()->screenGfx();
QPaintDevice::qwsDisplay(){ return qt_fbdpy; }->screenGfx();
QGfx * QWSDisplay::screenGfx(){ return qt_screen->screenGfx(); }
从qgfx_qws.cpp开始:
QGfx *QGfx::createGfx()调用qt_screen->createGfx()来进行关联。qt_screen是个全局变量,它在qgfxraser_qws.cpp中的QScreen *qt_get_screen( int display_id, const char *spec )被初始化。初始化语句为:
qt_screen = driverTable[i].qt_get_screen( display_id );而driverTable又是全局变量,在当qgfxraser_qws.cpp中直接在编译时被赋值:
struct DriverTable
{
char *name;
QScreen *(*qt_get_screen)(int);
int accel;
} driverTable [] = {
#if !defined(QT_NO_QWS_LINUXFB)
{ "LinuxFb", qt_get_screen_linuxfb, 0 },
#endif
#if !defined(QT_NO_QWS_VNC)
{ "VNC", qt_get_screen_vnc, 0 },
#endif
{ 0, 0, 0 },
};
而且qgfxraser_qws.cpp根据编译时的参数来包含不同的设备相关的cpp源码文件,如:
#if !defined(QT_NO_QWS_LINUXFB)
#include "qgfxlinuxfb_qws.cpp"
#endif
而且,qgfxraser_qws.cpp中用C++的模板功能实现了最底层的画图功能,如drawLine,drawPoint,但是不包含硬件加速。需要硬件加速的需要要自己另外实现。