qt5.3 MIPS 移植

   

qt5.3 release版终于出来了

看了下源码,模块化做得很不错,很多东西都从原来的qtbase里抽出来,变成单独模块,依赖关系变得很明确

然后就抽了点时间(到年底了,事情也蛮多的)做了下移植工作

 

qt5.0可能刚出来,很多移植的东西没加进去,所以如果要移植到自己的开发板上,那就要做点移植的工作了

 

我的编译选项

export PATH=~/work/rtl819x-SDK-v3.4.6.4-full-package/rtl819x/toolchain/rsdk-1.5.5-4181-EB-2.6.30-0.
9.30.3-110225/bin/:$PATH

./configure -v -prefix /qt5.0 -xplatform linux-mips-g++ -confirm-license -release -shared -opensource -nomake tests -nomake examples \
-qt-sql-sqlite \
-no-openvg \
-no-eglfs

 

其中-xplatform linux-mips-g++就是交叉编译要找的目录

最原始的代码里是没有linux-mips-g++这个目录的

所以要自己添加

创建linux-mips-g++在qtbase/mkspecs下

然后添加文件qmake.conf

  1. MAKEFILE_GENERATOR      = UNIX  
  2. CONFIG                  += incremental gdb_dwarf_index  
  3. QMAKE_INCREMENTAL_STYLE = sublib  
  4.   
  5. include(../common/linux.conf)  
  6. include(../common/gcc-base-unix.conf)  
  7. include(../common/g++-unix.conf)  
  8.   
  9. # modifications to g++.conf  
  10. QMAKE_CC                = mipsel-linux-gcc  
  11. QMAKE_CXX               = mipsel-linux-g++  
  12. QMAKE_CFLAGS           += -mips32  
  13. QMAKE_CXXFLAGS         += -mips32  
  14. QMAKE_LINK              = mipsel-linux-g++  
  15. QMAKE_LINK_SHLIB        = mipsel-linux-g++  
  16.   
  17. # modifications to linux.conf  
  18. QMAKE_AR                = mipsel-linux-ar cqs  
  19. QMAKE_OBJCOPY           = mipsel-linux-objcopy  
  20. QMAKE_STRIP             = mipsel-linux-strip  
  21. load(qt_config)  
MAKEFILE_GENERATOR      = UNIX
CONFIG                  += incremental gdb_dwarf_index
QMAKE_INCREMENTAL_STYLE = sublib

include(../common/linux.conf)
include(../common/gcc-base-unix.conf)
include(../common/g++-unix.conf)

# modifications to g++.conf
QMAKE_CC                = mipsel-linux-gcc
QMAKE_CXX               = mipsel-linux-g++
QMAKE_CFLAGS           += -mips32
QMAKE_CXXFLAGS         += -mips32
QMAKE_LINK              = mipsel-linux-g++
QMAKE_LINK_SHLIB        = mipsel-linux-g++

# modifications to linux.conf
QMAKE_AR                = mipsel-linux-ar cqs
QMAKE_OBJCOPY           = mipsel-linux-objcopy
QMAKE_STRIP             = mipsel-linux-strip
load(qt_config)


就可以了

然后执行编译选项,然后make,make install就可以了

 

之后就是重点,写图形插件,就是将qt生成的图片的buffer copy到板子sdk提供的fb接口上

 

qt5对比qt4对于插件的改动还是蛮大的,至少目录结构改了

qt4是在plugins/gfxdrivers下

qt5则在plugins/platforms下

 

那么就进入plugins/platforms下

自己创建个目录,写工程文件和继承对应的插件类,进行扩展(看过很多开源代码,大部分都是这种设计模式,一来你增加功能只需要添加代码就可以,二来这种结构在运行时加载,你可以随时切换,大家设计自己的工程时不妨考虑这种设计模式)

 

1.创建xxx.json文件(xxx就是你自定义命名)

  1. {  
  2.     "Keys": [ "xxx"]  
  3. }  
{
    "Keys": [ "xxx"]
}


2.创建main.cpp

  1. #include <qpa/qplatformintegrationplugin.h>  
  2. #include "qxxxintegration.h"  
  3.   
  4. QT_BEGIN_NAMESPACE  
  5.   
  6. class QxxxIntegrationPlugin : public QPlatformIntegrationPlugin  
  7. {  
  8.     Q_OBJECT  
  9.     Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.1" FILE "bcm.json")  
  10. public:  
  11.     QPlatformIntegration *create(const QString&, const QStringList&);  
  12. };  
  13.   
  14. QPlatformIntegration * QxxxIntegrationPlugin::create(const QString& system, const QStringList& paramList)  
  15. {  
  16.     Q_UNUSED(paramList);  
  17.   
  18.     if (system.toLower() == "xxx")  
  19.         return new QxxxIntegration(paramList);  
  20.       
  21.     return 0;  
  22. }  
  23.   
  24. QT_END_NAMESPACE  
  25.   
  26. #include "main.moc"  
#include <qpa/qplatformintegrationplugin.h>
#include "qxxxintegration.h"

QT_BEGIN_NAMESPACE

class QxxxIntegrationPlugin : public QPlatformIntegrationPlugin
{
    Q_OBJECT
    Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.1" FILE "bcm.json")
public:
    QPlatformIntegration *create(const QString&, const QStringList&);
};

QPlatformIntegration * QxxxIntegrationPlugin::create(const QString& system, const QStringList& paramList)
{
    Q_UNUSED(paramList);

    if (system.toLower() == "xxx")
        return new QxxxIntegration(paramList);
	
    return 0;
}

QT_END_NAMESPACE

#include "main.moc"


 

3.qxxxintegration.h(这里和后面都用linuxfb里的例子)

  1. #ifndef QLINUXFBINTEGRATION_H  
  2. #define QLINUXFBINTEGRATION_H  
  3.   
  4. #include <qpa/qplatformintegration.h>  
  5.   
  6. QT_BEGIN_NAMESPACE  
  7.   
  8. class QLinuxFbIntegrationPrivate;  
  9. class QAbstractEventDispatcher;  
  10. class QLinuxFbScreen;  
  11.   
  12. class QLinuxFbIntegration : public QPlatformIntegration  
  13. {  
  14. public:  
  15.     QLinuxFbIntegration(const QStringList ¶mList);  
  16.     ~QLinuxFbIntegration();  
  17.   
  18.     bool hasCapability(QPlatformIntegration::Capability cap) const;  
  19.   
  20.     QPlatformPixmap *createPlatformPixmap(QPlatformPixmap::PixelType type) const;  
  21.     QPlatformWindow *createPlatformWindow(QWindow *window) const;  
  22.     QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const;  
  23.     QAbstractEventDispatcher *guiThreadEventDispatcher() const;  
  24.     QList<QPlatformScreen *> screens() const;  
  25.     QPlatformFontDatabase *fontDatabase() const;  
  26.   
  27. private:  
  28.     QLinuxFbScreen *m_primaryScreen;  
  29.     QPlatformFontDatabase *m_fontDb;  
  30.     QAbstractEventDispatcher *m_eventDispatcher;  
  31. };  
  32.   
  33. QT_END_NAMESPACE  
  34.   
  35. #endif // QLINUXFBINTEGRATION_H  
#ifndef QLINUXFBINTEGRATION_H
#define QLINUXFBINTEGRATION_H

#include <qpa/qplatformintegration.h>

QT_BEGIN_NAMESPACE

class QLinuxFbIntegrationPrivate;
class QAbstractEventDispatcher;
class QLinuxFbScreen;

class QLinuxFbIntegration : public QPlatformIntegration
{
public:
    QLinuxFbIntegration(const QStringList ¶mList);
    ~QLinuxFbIntegration();

    bool hasCapability(QPlatformIntegration::Capability cap) const;

    QPlatformPixmap *createPlatformPixmap(QPlatformPixmap::PixelType type) const;
    QPlatformWindow *createPlatformWindow(QWindow *window) const;
    QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const;
    QAbstractEventDispatcher *guiThreadEventDispatcher() const;
    QList<QPlatformScreen *> screens() const;
    QPlatformFontDatabase *fontDatabase() const;

private:
    QLinuxFbScreen *m_primaryScreen;
    QPlatformFontDatabase *m_fontDb;
    QAbstractEventDispatcher *m_eventDispatcher;
};

QT_END_NAMESPACE

#endif // QLINUXFBINTEGRATION_H



4.qxxxintegration.cpp

  1. #include "qlinuxfbintegration.h"  
  2. #include "qlinuxfbscreen.h"  
  3.   
  4. #include <QtPlatformSupport/private/qgenericunixfontdatabase_p.h>  
  5. #include <QtPlatformSupport/private/qgenericunixeventdispatcher_p.h>  
  6. #include <QtPlatformSupport/private/qfbbackingstore_p.h>  
  7. #include <QtPlatformSupport/private/qfbwindow_p.h>  
  8. #include <QtPlatformSupport/private/qfbcursor_p.h>  
  9.   
  10. #include <QtGui/private/qguiapplication_p.h>  
  11. #include <QtGui/private/qpixmap_raster_p.h>  
  12.   
  13. QT_BEGIN_NAMESPACE  
  14.   
  15. QLinuxFbIntegration::QLinuxFbIntegration(const QStringList ¶mList)  
  16.     : m_fontDb(new QGenericUnixFontDatabase()),  
  17.       m_eventDispatcher(createUnixEventDispatcher())  
  18. {  
  19.     QGuiApplicationPrivate::instance()->setEventDispatcher(m_eventDispatcher);  
  20.   
  21.     m_primaryScreen = new QLinuxFbScreen;  
  22.     if (m_primaryScreen->initialize(paramList))  
  23.         screenAdded(m_primaryScreen);  
  24. }  
  25.   
  26. QLinuxFbIntegration::~QLinuxFbIntegration()  
  27. {  
  28.     delete m_primaryScreen;  
  29. }  
  30.   
  31. bool QLinuxFbIntegration::hasCapability(QPlatformIntegration::Capability cap) const  
  32. {  
  33.     switch (cap) {  
  34.     case ThreadedPixmaps: return true;  
  35.     defaultreturn QPlatformIntegration::hasCapability(cap);  
  36.     }  
  37. }  
  38.   
  39. QPlatformPixmap *QLinuxFbIntegration::createPlatformPixmap(QPlatformPixmap::PixelType type) const  
  40. {  
  41.     return new QRasterPlatformPixmap(type);  
  42. }  
  43.   
  44. QPlatformBackingStore *QLinuxFbIntegration::createPlatformBackingStore(QWindow *window) const  
  45. {  
  46.     return new QFbBackingStore(window);  
  47. }  
  48.   
  49. QPlatformWindow *QLinuxFbIntegration::createPlatformWindow(QWindow *window) const  
  50. {  
  51.     return new QFbWindow(window);  
  52. }  
  53.   
  54. QAbstractEventDispatcher *QLinuxFbIntegration::guiThreadEventDispatcher() const  
  55. {  
  56.     return m_eventDispatcher;  
  57. }  
  58.   
  59. QList<QPlatformScreen *> QLinuxFbIntegration::screens() const  
  60. {  
  61.     QList<QPlatformScreen *> list;  
  62.     list.append(m_primaryScreen);  
  63.     return list;  
  64. }  
  65.   
  66. QPlatformFontDatabase *QLinuxFbIntegration::fontDatabase() const  
  67. {  
  68.     return m_fontDb;  
  69. }  
  70.   
  71. QT_END_NAMESPACE  
#include "qlinuxfbintegration.h"
#include "qlinuxfbscreen.h"

#include <QtPlatformSupport/private/qgenericunixfontdatabase_p.h>
#include <QtPlatformSupport/private/qgenericunixeventdispatcher_p.h>
#include <QtPlatformSupport/private/qfbbackingstore_p.h>
#include <QtPlatformSupport/private/qfbwindow_p.h>
#include <QtPlatformSupport/private/qfbcursor_p.h>

#include <QtGui/private/qguiapplication_p.h>
#include <QtGui/private/qpixmap_raster_p.h>

QT_BEGIN_NAMESPACE

QLinuxFbIntegration::QLinuxFbIntegration(const QStringList ¶mList)
    : m_fontDb(new QGenericUnixFontDatabase()),
      m_eventDispatcher(createUnixEventDispatcher())
{
    QGuiApplicationPrivate::instance()->setEventDispatcher(m_eventDispatcher);

    m_primaryScreen = new QLinuxFbScreen;
    if (m_primaryScreen->initialize(paramList))
        screenAdded(m_primaryScreen);
}

QLinuxFbIntegration::~QLinuxFbIntegration()
{
    delete m_primaryScreen;
}

bool QLinuxFbIntegration::hasCapability(QPlatformIntegration::Capability cap) const
{
    switch (cap) {
    case ThreadedPixmaps: return true;
    default: return QPlatformIntegration::hasCapability(cap);
    }
}

QPlatformPixmap *QLinuxFbIntegration::createPlatformPixmap(QPlatformPixmap::PixelType type) const
{
    return new QRasterPlatformPixmap(type);
}

QPlatformBackingStore *QLinuxFbIntegration::createPlatformBackingStore(QWindow *window) const
{
    return new QFbBackingStore(window);
}

QPlatformWindow *QLinuxFbIntegration::createPlatformWindow(QWindow *window) const
{
    return new QFbWindow(window);
}

QAbstractEventDispatcher *QLinuxFbIntegration::guiThreadEventDispatcher() const
{
    return m_eventDispatcher;
}

QList<QPlatformScreen *> QLinuxFbIntegration::screens() const
{
    QList<QPlatformScreen *> list;
    list.append(m_primaryScreen);
    return list;
}

QPlatformFontDatabase *QLinuxFbIntegration::fontDatabase() const
{
    return m_fontDb;
}

QT_END_NAMESPACE


5.qxxxscreen.h(这个我针对linuxfbscreen.h删改过的)

  1. #ifndef QLINUXFBSCREEN_H  
  2. #define QLINUXFBSCREEN_H  
  3.   
  4. #include <QtPlatformSupport/private/qfbscreen_p.h>  
  5.   
  6. QT_BEGIN_NAMESPACE  
  7.   
  8. class QPainter;  
  9. class QFbCursor;  
  10.   
  11. class QLinuxFbScreen : public QFbScreen  
  12. {  
  13.     Q_OBJECT  
  14. public:  
  15.     QLinuxFbScreen();  
  16.     ~QLinuxFbScreen();  
  17.   
  18.     bool initialize(const QStringList &args);  
  19.   
  20. public slots:  
  21.     QRegion doRedraw();  
  22.   
  23. private:  
  24.     QImage mFbScreenImage;  
  25.     int mBytesPerLine;  
  26.   
  27.     QPainter *mBlitter;  
  28. };  
  29.   
  30. QT_END_NAMESPACE  
  31.   
  32. #endif // QLINUXFBSCREEN_H  
#ifndef QLINUXFBSCREEN_H
#define QLINUXFBSCREEN_H

#include <QtPlatformSupport/private/qfbscreen_p.h>

QT_BEGIN_NAMESPACE

class QPainter;
class QFbCursor;

class QLinuxFbScreen : public QFbScreen
{
    Q_OBJECT
public:
    QLinuxFbScreen();
    ~QLinuxFbScreen();

    bool initialize(const QStringList &args);

public slots:
    QRegion doRedraw();

private:
    QImage mFbScreenImage;
    int mBytesPerLine;

    QPainter *mBlitter;
};

QT_END_NAMESPACE

#endif // QLINUXFBSCREEN_H


 

6.qxxxscreen.cpp

  1. #include "qlinuxfbscreen.h"  
  2. #include <QtPlatformSupport/private/qfbcursor_p.h>  
  3. #include <QtGui/QPainter>  
  4.   
  5. #include <private/qcore_unix_p.h> // overrides QT_OPEN  
  6. #include <qimage.h>  
  7. #include <qdebug.h>  
  8.   
  9. #include <unistd.h>  
  10. #include <stdlib.h>  
  11. #include <stdio.h>  
  12. #include "bcminterface.h"  
  13.   
  14.   
  15. QT_BEGIN_NAMESPACE  
  16.   
  17. #define WIDTH_FB 1440  
  18. #define HEIGHT_FB 1080  
  19. #define BYTESPERLINE (4 * WIDTH_FB)  
  20. #define DEPTH_FB (4 * 8)  
  21. #define DPI (72)  
  22. #define ROUND_PI ((double)25.4)  
  23.   
  24. QLinuxFbScreen::QLinuxFbScreen()  
  25.     : mBlitter(0)  
  26. {  
  27.     InitBCMInterface(WIDTH_FB, HEIGHT_FB);  
  28. }  
  29.   
  30. QLinuxFbScreen::~QLinuxFbScreen()  
  31. {  
  32.     delete mBlitter;  
  33. }  
  34.   
  35. static uchar* pBuffer = NULL;  
  36. static int nSize = 0;  
  37.   
  38. bool QLinuxFbScreen::initialize(const QStringList &args)  
  39. {  
  40. #if 1  
  41.     mDepth = DEPTH_FB;//determineDepth(vinfo);  
  42.     mBytesPerLine = BYTESPERLINE;//finfo.line_length;  
  43.     mGeometry = QRect(0, 0, WIDTH_FB, HEIGHT_FB);//determineGeometry(vinfo, userGeometry);  
  44.     mFormat = QImage::Format_ARGB32;//determineFormat(vinfo, mDepth);  
  45.     //printf("[GUM], format: %d, %d, <%s, %s, %d>\n", mFormat, QImage::Format_ARGB32_Premultiplied, __FILE__, __FUNCTION__, __LINE__);  
  46.     mPhysicalSize = QSize(qRound(WIDTH_FB * ROUND_PI / DPI), qRound(HEIGHT_FB * ROUND_PI / DPI));//determinePhysicalSize(vinfo, userMmSize, mGeometry.size());  
  47. #endif  
  48.   
  49.     nSize = (WIDTH_FB * HEIGHT_FB * 4);  
  50.     pBuffer = (uchar*)GetBcmBuffer(&nSize);  
  51.     memset(pBuffer, 0, nSize);  
  52.   
  53.   
  54.     QFbScreen::initializeCompositor();  
  55.     mFbScreenImage = QImage(pBuffer, mGeometry.width(), mGeometry.height(), mBytesPerLine, mFormat);  
  56.     mCursor = new QFbCursor(this);  
  57.   
  58.     return true;  
  59. }  
  60.   
  61. QRegion QLinuxFbScreen::doRedraw()  
  62. {  
  63.     QRegion touched = QFbScreen::doRedraw();  
  64.   
  65.     if (touched.isEmpty())  
  66.         {  
  67.         return touched;  
  68.         }  
  69.   
  70.   
  71.     if (!mBlitter)  
  72.         mBlitter = new QPainter(&mFbScreenImage);  
  73.   
  74.     QVector<QRect> rects = touched.rects();  
  75.     for (int i = 0; i < rects.size(); i++)  
  76.         mBlitter->drawImage(rects[i], *mScreenImage, rects[i]);  
  77.     return touched;  
  78. }  
  79.   
  80. QT_END_NAMESPACE  
#include "qlinuxfbscreen.h"
#include <QtPlatformSupport/private/qfbcursor_p.h>
#include <QtGui/QPainter>

#include <private/qcore_unix_p.h> // overrides QT_OPEN
#include <qimage.h>
#include <qdebug.h>

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include "bcminterface.h"


QT_BEGIN_NAMESPACE

#define WIDTH_FB 1440
#define HEIGHT_FB 1080
#define BYTESPERLINE (4 * WIDTH_FB)
#define DEPTH_FB (4 * 8)
#define DPI (72)
#define ROUND_PI ((double)25.4)

QLinuxFbScreen::QLinuxFbScreen()
    : mBlitter(0)
{
	InitBCMInterface(WIDTH_FB, HEIGHT_FB);
}

QLinuxFbScreen::~QLinuxFbScreen()
{
    delete mBlitter;
}

static uchar* pBuffer = NULL;
static int nSize = 0;

bool QLinuxFbScreen::initialize(const QStringList &args)
{
#if 1
    mDepth = DEPTH_FB;//determineDepth(vinfo);
    mBytesPerLine = BYTESPERLINE;//finfo.line_length;
    mGeometry = QRect(0, 0, WIDTH_FB, HEIGHT_FB);//determineGeometry(vinfo, userGeometry);
    mFormat = QImage::Format_ARGB32;//determineFormat(vinfo, mDepth);
	//printf("[GUM], format: %d, %d, <%s, %s, %d>\n", mFormat, QImage::Format_ARGB32_Premultiplied, __FILE__, __FUNCTION__, __LINE__);
    mPhysicalSize = QSize(qRound(WIDTH_FB * ROUND_PI / DPI), qRound(HEIGHT_FB * ROUND_PI / DPI));//determinePhysicalSize(vinfo, userMmSize, mGeometry.size());
#endif

	nSize = (WIDTH_FB * HEIGHT_FB * 4);
	pBuffer = (uchar*)GetBcmBuffer(&nSize);
	memset(pBuffer, 0, nSize);


    QFbScreen::initializeCompositor();
    mFbScreenImage = QImage(pBuffer, mGeometry.width(), mGeometry.height(), mBytesPerLine, mFormat);
    mCursor = new QFbCursor(this);

    return true;
}

QRegion QLinuxFbScreen::doRedraw()
{
    QRegion touched = QFbScreen::doRedraw();

    if (touched.isEmpty())
    	{
        return touched;
    	}


    if (!mBlitter)
        mBlitter = new QPainter(&mFbScreenImage);

    QVector<QRect> rects = touched.rects();
    for (int i = 0; i < rects.size(); i++)
        mBlitter->drawImage(rects[i], *mScreenImage, rects[i]);
    return touched;
}

QT_END_NAMESPACE


主要是继承了QFbScreen,要设一下成员变量的值

其中mDepth、mGeometry、mFormat、mPhysicalSize要设一下

然后初始化QFbScreen::initializeCompositor();

mCursor = new QFbCursor(this);

将你sdk上对应fb的指针传给mFbScreenImage对象,就是pBuffer的值,不同sdk有不同的做法,这里就不详说了

最后doredraw是由qt去调,进行绘画

 

我这里用了test/manual/qlayout作为测试例子

执行qlayout -platform xxx


  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值