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

📄 qgfxsnap_qws.cpp

📁 qt-embedded-2.3.8.tar.gz源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/****************************************************************************** $Id: qt/src/3rdparty/kernel/qgfxsnap_qws.cpp   2.3.8   edited 2004-08-05 $**** Implementation of QSNAPScreen and QGfxSNAP classes for Embedded Qt**** Copyright (C) SciTech Software, Inc.  All rights reserved.**** Author:  Kendall Bennett**** 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.**** This module requires the SciTech SNAP SDK to build and also requires** the SciTech SNAP runtime device driver modules to be present in order** to run.**** See http://www.scitechsoft.com or email sales@scitechsoft.com for** information about SciTech SNAP Commercial License Agreements.************************************************************************/#ifndef QT_NO_QWS_SNAP#include "qgfxsnap_qws.h"#include "qgfxraster_qws.h"// TODO: Can we eliminate these external references here, and just set up optype//       ourselves instead of using these values that are not referenced anywhere?extern volatile int *optype;extern volatile int *lastop;// An integer, optype, is stored in shared memory and is set to one// of these values.#define OPTYPE_ACCEL        1// Mix table to translate from non-standard Qt ROP codes to standard 4-bit// two way hardware ROP codes.static int mixTable[] = {    GA_R2_COPYSRC,      // S    - CopyROP    GA_R2_MERGESRC,     // DSo  - OrROP    GA_R2_XORSRC,       // DSx  - XorROP    GA_R2_MASKNOTSRC,   // DSna - NotAndROP    GA_R2_NOTCOPYSRC,   // Sn   - NotCopyROP    GA_R2_MERGENOTSRC,  // DSno - NotOrROP    GA_R2_NOTXORSRC,    // DSxn - NotXorROP    GA_R2_MASKSRC,      // DSa  - AndROP    GA_R2_NOT,          // Dn   - NotROP    GA_R2_BLACK,        // 0    - ClearROP    GA_R2_WHITE,        // 1    - SetROP    GA_R2_NOP,          // D    - NopROP    GA_R2_MASKSRCNOT,   // SDna - AndNotROP    GA_R2_MERGESRCNOT,  // SDno - OrNotROP    GA_R2_NOTMASKSRC,   // DSan - NandROP    GA_R2_NOTMERGESRC,  // DSon - NorROP    };/*!\struct QGfxSNAP_State\brief The QGfxSNAP_State class manages the shared rendering stateMain structure to manage the shared rendering state for all processesconnected to the main server process.*/struct QGfxSNAP_State {    int         optype;    int         lastop;    N_int32     mix;    GA_color    foreColor;    GA_color    backColor;    GA_buffer   drawBuf;    };/*!\class QGfxSNAP\brief The QGfxSNAP class manages rendering to SNAP Graphics devicesMain class to create a graphics rendering object for the specific colordepth and type*/template <const int depth, const int type>class QGfxSNAP : public QGfxRaster<depth,type> {public:    QGfxSNAP(unsigned char *buffer,int width,int height,QGfxSNAP_State *cntState,        GA_2DStateFuncs &hwState2d,GA_2DRenderFuncs &hwDraw2d,        GA_2DStateFuncs &state2d,GA_2DRenderFuncs &draw2d);//    virtual void drawPoint(int,int);//    virtual void drawPoints(const QPointArray &,int,int);//    virtual void drawPolyline(const QPointArray &,int,int);    virtual void fillRect(int,int,int,int);    virtual void blt(int,int,int,int,int,int);    virtual void scroll(int,int,int,int,int,int);//    virtual void stretchBlt(int,int,int,int,int,int);//    virtual void tiledBlt(int,int,int,int);    virtual void drawLine(int,int,int,int);    virtual void sync();    // TODO: We need a way to override and accelerate the optimised    //       horizontal and vertical line functions. Right now they are    //       not virtual functions in the QGfxRaster class, so we either    //       need to make them virtual (ala the QNX6 HLine) or find some    //       other way to hook this out.//    void vline(int,int,int);//    void hline(int,int,int);//    void hlineUnclipped(int,int,unsigned char* );private:    bool checkDest();    bool checkSourceDest();private:    GA_buffer           drawBuf;    ulong               srcOffset;    QGfxSNAP_State      *cntState;    GA_2DStateFuncs     &hwState2d;    GA_2DRenderFuncs    &hwDraw2d;    GA_2DStateFuncs     &state2d;    GA_2DRenderFuncs    &draw2d;};/*!Constructor for the QGfxSNAP class*/template<const int depth,const int type>QGfxSNAP<depth,type>::QGfxSNAP(    unsigned char * buffer,    int width,    int height,    QGfxSNAP_State *cntState,    GA_2DStateFuncs &hwState2d,    GA_2DRenderFuncs &hwDraw2d,    GA_2DStateFuncs &state2d,    GA_2DRenderFuncs &draw2d)    : QGfxRaster<depth,type>(buffer,width,height),        cntState(cntState),        hwState2d(hwState2d), hwDraw2d(hwDraw2d),        state2d(state2d), draw2d(draw2d){}/*!Internal function to check that the destination buffer is in graphicsmemory or not. If it is in graphics memory, we go ahead and set thedestination draw buffer to that location.*/template<const int depth,const int type>inline bool QGfxSNAP<depth,type>::checkDest(){    ulong   offset;    if (!qt_screen->onCard(buffer,offset))        return false;    drawBuf.dwSize = sizeof(drawBuf);    drawBuf.Offset = offset;    drawBuf.Stride = linestep();    drawBuf.Width = pixelWidth();    drawBuf.Height = pixelHeight();    return true;}/*!Internal function to check that the source and destination buffers arein graphics memory. If they are, we set up for drawing and return true.TODO: We can handle system memory blits with hardware ROP's etc, so we      need to add code to allow a hardware destination buffer but a      software source buffer!*/template<const int depth,const int type>inline bool QGfxSNAP<depth,type>::checkSourceDest(){    if (!checkDest())        return false;    return qt_screen->onCard(srcbits,srcOffset);}/*!This is called to draw a rectangle. We try and draw the rectanglein hardware if possible.*/template<const int depth,const int type>void QGfxSNAP<depth,type>::fillRect(    int left,    int top,    int width,    int height){    // Check that it is not trivially clipped    if (ncliprect < 1)        return;    // Check that there is no pattern applied to the rectangle    if (cbrush.style() != SolidPattern) {        QGfxRaster<depth,type>::fillRect(left,top,width,height);        return;        }    // Check that the buffer is a hardware buffer, punting to software if not    if (!checkDest()) {        QGfxRaster<depth,type>::fillRect(left,top,width,height);        return;        }    // Get exclusive write access to the display and get ready for drawing    QWSDisplay::grab(true);    GFX_START(QRect(left+xoffs, top+yoffs, width+1, height+1));    // Set the required hardware state if is has changed    if (memcmp(&cntState->drawBuf,&drawBuf,sizeof(drawBuf)) != 0) {        cntState->drawBuf = drawBuf;        state2d.SetDrawBuffer(&drawBuf);        }    if (mixTable[myrop] != cntState->mix)        state2d.SetMix(cntState->mix = mixTable[myrop]);    useBrush();    if (pixel != cntState->foreColor)        state2d.SetForeColor(cntState->foreColor = pixel);    // Draw the rectangle clipped to all clip rectangles    int i;    int right = (left += xoffs) + (width - 1);    int bottom = (top += yoffs) + (height - 1);    int numrects = ncliprect;    for (i = 0; i < numrects; i++) {        QRect clip(cliprect[i]);        if (left <= clip.right() && top <= clip.bottom() && right >= clip.left() && bottom >= clip.top()) {            int clipLeft = clip.left() > left ? clip.left() : left;            int clipTop = clip.top() > top ? clip.top() : top;            int clipRight = clip.right() > right ? right : clip.right();            int clipBottom = clip.bottom() > bottom ? bottom : clip.bottom();            draw2d.DrawRect(clipLeft,clipTop,(clipRight-clipLeft)+1,(clipBottom-clipTop)+1);            }        }    // Indicate that we have done an accelerated drawing function, so that    // software rendering code will need to do a sync() before accessing    // video memory.    (*optype) = OPTYPE_ACCEL;    // Clean up and exit    GFX_END;    QWSDisplay::ungrab();}/*!Function to sort rectangle clip list for down and right blit operations.Since the rectangles are always guaranteed to be non-overlapping, we canmake this fast by only comparing the (top,left) coordinates of therectangles.*/static int cmp_down_right(    const void *p1,const void *p2){    const QRect *r1 = (const QRect*)p1;    const QRect *r2 = (const QRect*)p2;    if (r1->left() >= r2->left()) {        if (r1->top() >= r2->top())            return -1;  // R1        else            return 1;   // R2        }    else {        if (r1->top() > r2->top())            return -1;  // R1        else            return 1;   // R2        }}/*!Function to sort rectangle clip list for down and left blit operations*/static int cmp_down_left(    const void *p1,const void *p2){    const QRect *r1 = (const QRect*)p1;    const QRect *r2 = (const QRect*)p2;    if (r1->left() > r2->left()) {        if (r1->top() > r2->top())            return -1;  // R1        else            return 1;   // R2        }    else {        if (r1->top() >= r2->top())            return -1;  // R1        else            return 1;   // R2        }}/*!Function to sort rectangle clip list for up and right blit operations*/static int cmp_up_right(    const void *p1,const void *p2){    const QRect *r1 = (const QRect*)p1;    const QRect *r2 = (const QRect*)p2;    if (r1->left() >= r2->left()) {        if (r1->top() <= r2->top())            return -1;  // R1        else            return 1;   // R2        }    else {        if (r1->top() < r2->top())            return -1;  // R1        else            return 1;   // R2        }}/*!Function to sort rectangle clip list for up and left blit operations*/static int cmp_up_left(    const void *p1,const void *p2){    const QRect *r1 = (const QRect*)p1;    const QRect *r2 = (const QRect*)p2;    if (r1->left() >= r2->left()) {        if (r1->top() < r2->top())            return -1;  // R1        else            return 1;   // R2        }    else {        if (r1->top() <= r2->top())            return -1;  // R1        else            return 1;   // R2        }}/*!Function to handle the common case of blting a rectangle a small distancewithin the same drawing surface (for example when scrolling a listbox).*/template <const int depth, const int type>void QGfxSNAP<depth,type>::scroll(    int left,    int top,    int width,    int height,    int srcLeft,    int srcTop){    // Check to see if we can trivially reject the blit    if (ncliprect < 1)        return;    if (!width || !height)        return;    int dy = srcTop - top;    int dx = srcLeft - left;    if (dx == 0 && dy == 0)        return;    // Check that the buffers are in hardware, punting to software if not    srcbits = buffer;    if (!checkSourceDest()) {        QGfxRaster<depth,type>::scroll(left,top,width,height,srcLeft,srcTop);        return;        }    // Setup pixel coordinates and loop variables    left += xoffs;    top += yoffs;    srcLeft += xoffs;    srcTop += yoffs;    int right = left + width - 1;    int bottom = top + height - 1;    int mix = mixTable[myrop];    int i,numrects = ncliprect;    // If we have to do complex clipping, we need to sort the clip rectangle list    // for the correct order based on the direction of the scroll. If we don't do that    // we end up with incorrect results!    if (numrects > 1) {        if (srcTop < top) {            // Down direction            if (srcLeft < left) {                // Down and right direction                qsort(cliprect, numrects, sizeof(cliprect[0]), cmp_down_right);                }            else {                // Down and left direction                qsort(cliprect, numrects, sizeof(cliprect[0]), cmp_down_left);                }            }        else {            // Up direction            if (srcLeft < left) {                // Up and right direction                qsort(cliprect, numrects, sizeof(cliprect[0]), cmp_up_right);                }            else {                // Up and left direction.                qsort(cliprect, numrects, sizeof(cliprect[0]), cmp_up_left);                }            }        }    // Get exclusive write access to the display and get ready for drawing    QWSDisplay::grab(true);    GFX_START(QRect(QMIN(left+xoffs,srcLeft+xoffs), QMIN(top+yoffs,srcTop+yoffs), width+QABS(dx)+1, height+QABS(dy)+1));    // Set the required hardware state if is has changed    if (memcmp(&cntState->drawBuf,&drawBuf,sizeof(drawBuf)) != 0) {        cntState->drawBuf = drawBuf;        state2d.SetDrawBuffer(&drawBuf);        }    // Now clip the blit to each clip rectangle do the blit    for (i = 0; i < numrects; i++) {        QRect clip(cliprect[i]);        if (left <= clip.right() && top <= clip.bottom() && right >= clip.left() && bottom >= clip.top()) {            int clipLeft = clip.left() > left ? clip.left() : left;            int clipTop = clip.top() > top ? clip.top() : top;            int clipRight = clip.right() > right ? right : clip.right();            int clipBottom = clip.bottom() > bottom ? bottom : clip.bottom();            int clipSrcLeft = srcLeft + (clipLeft - left);            int clipSrcTop = srcTop + (clipTop - top);            draw2d.BitBlt(clipSrcLeft,clipSrcTop,(clipRight-clipLeft)+1,(clipBottom-clipTop)+1,clipLeft,clipTop,mix);

⌨️ 快捷键说明

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