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

📄 qgfxsnap_qws.cpp

📁 qt-embedded-2.3.8.tar.gz源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
do much in here as we do most of the fun stuff up above in the connect()function. However we do initialise any shared memory blocks for sharinginformation between the server and connecting clients.*/bool QSNAPScreen::initDevice(){    // Initialise the default color palette    if (modeInfo.BitsPerPixel <= 8) {        GA_palette pal[256];        screencols = (modeInfo.BitsPerPixel == 8) ? 256 : 16;        if (screencols == 16) {            // Default 16 colour palette            uchar reds[16]   = { 0x00,0x7F,0xBF,0xFF,0xFF,0xA2,0x00,0xFF,0xFF,0x00,0x7F,0x7F,0x00,0x00,0x00,0x82 };            uchar greens[16] = { 0x00,0x7F,0xBF,0xFF,0x00,0xC5,0x00,0xFF,0x00,0xFF,0x00,0x00,0x00,0x7F,0x7F,0x7F };            uchar blues[16]  = { 0x00,0x7F,0xBF,0xFF,0x00,0x11,0xFF,0x00,0xFF,0xFF,0x00,0x7F,0x7F,0x7F,0x00,0x00 };            for (int i = 0; i < 16; i++) {                pal[i].Red = reds[i];                pal[i].Green = greens[i];                pal[i].Blue = blues[i];                screenclut[i] = qRgb(pal[i].Red,pal[i].Green,pal[i].Blue);                }            }        else {            // 6x6x6 216 color cube            int i = 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) {                        pal[i].Red = ir;                        pal[i].Green = ig;                        pal[i].Blue = ib;                        screenclut[i] = qRgb(pal[i].Red,pal[i].Green,pal[i].Blue);                        i++;                        }                    }                }            // Fill in rest with 0            for (int j = 0; j < 40; j++) {                pal[i].Red = 0;                pal[i].Green = 0;                pal[i].Blue = 0;                screenclut[i] = 0;                i++;                }            }        driver.SetPaletteData(pal,screencols,0,gaDontWait);        }    // Initialise the offscreen memory manager    if (useOffscreen) {        *entryp = 0;        *lowest = mapsize;        insert_entry(*entryp,*lowest,*lowest);  // dummy entry to mark start        }    initted = true;    return true;}/*!This is used to initialize the software cursor - \a end_of_locationpoints to the address after the area where the cursor image can be stored.\a init is true for the first application this method is called from(the Qt/Embedded server), false otherwise.HACK HACK HACK! BEWARE!Due to the fact that Qt/E 2.3 does not pass any shared memoryto the driver except via this function, we use this opportunityto steal some shared memory for the graphics driver beforewe init the software mouse cursor module. Eventually we would like to movethis code up into the initDevice() and connect() functions, but weneed a way to allocate shared memory from Qt/E's memory block before wecan do this. Rather than hack up the higher level code to allow this, Isimply hacked our needs into this function.*/int QSNAPScreen::initCursor(    void *end_of_location,    bool init){#ifndef QT_NO_QWS_CURSOR    // Allocate a block of shared memory to manage the shared state    // for all connected processes.    cntState = (QGfxSNAP_State*)end_of_location - 1;    if (init) {        // Initialise the shared state variables if this is the        // server instance.        cntState->optype = 0;        cntState->lastop = 0;        cntState->mix = -1;        cntState->foreColor = 0xFFFFFFFF;        cntState->backColor = 0xFFFFFFFF;        memset(&cntState->drawBuf,0,sizeof(cntState->drawBuf));        }    // Connect up the necessary shared variables that the generic code needs    optype = &cntState->optype;    lastop = &cntState->lastop;    return QScreen::initCursor(cntState,init) + sizeof(*cntState);#else#error QT_NO_QWS_CURSOR must be set for Qt/E 2.3 to support SNAP!    return 0;#endif}/*!\fn void QSNAPScreen::disconnect()This simply disconnects this client from the shared SNAP Graphics driver.*/void QSNAPScreen::disconnect(){    // Unload the ref2d and device context as necessary. Ref2d is not    // reference counted, so we have to specifically unload it only    // if it was actually loaded. One day we should change this to be    // reference counted also.    if (unloadRef2d)        GA_unloadRef2d(dc);    GA_unloadDriver(dc);}/*!\fn void QSNAPScreen::shutdownDevice()This is called by the Qt/Embedded server when it shuts down. Here weunload the SNAP graphics driver and restore the Linux console back tonormal.*/void QSNAPScreen::shutdownDevice(){    N_int32 virtualX,virtualY,bytesPerLine;    // Reset the original display mode before closing the console    virtualX = virtualY = bytesPerLine = -1;    init.SetVideoMode(prevMode | gaDontClear,&virtualX,&virtualY,&bytesPerLine,&maxMem,0,NULL);    // Restore the console state, close the console and free state buffer    PM_restoreConsoleState(stateBuf,hwndConsole);    PM_closeConsole(hwndConsole);    free(stateBuf);}/*!The offscreen memory manager's list of entries is stored at the bottomof the offscreen memory area and consistes of a series of QPoolEntry's,each of which keep track of a block of allocated memory. Unallocated memoryis implicitly indicated by the gap between blocks indicated by QPoolEntry's.The memory manager looks through any unallocated memory before the endof currently-allocated memory to see if a new block will fit in the gap;if it doesn't it allocated it from the end of currently-allocated memory.Memory is allocated from the top of the framebuffer downwards; if it hitsthe list of entries then offscreen memory is full and further allocationsare made from main RAM (and hence unaccelerated). Allocated memory canbe seen as a sort of upside-down stack; lowest keeps track of thebottom of the stack.*/void QSNAPScreen::delete_entry(    int pos){    if (pos > *entryp || pos < 0) {        qDebug("Attempt to delete odd pos! %d %d",pos,*entryp);        return;        }#ifdef DEBUG_CACHE    qDebug( "Remove entry: %d", pos );#endif    QPoolEntry * qpe = &entries[pos];    if(qpe->start <= *lowest) {        // Lowest goes up again        *lowest = entries[pos-1].start;#ifdef DEBUG_CACHE	qDebug( "   moved lowest to %d", *lowest );#endif        }    (*entryp)--;    if (pos == *entryp)        return;    int size = (*entryp) - pos;    memmove(&entries[pos], &entries[pos+1], size * sizeof(QPoolEntry));}/*!Insert an entry into the offscreen memory pool.*/void QSNAPScreen::insert_entry(    int pos,    uint start,    uint end){    if (pos > *entryp) {        qDebug("Attempt to insert odd pos! %d %d",pos,*entryp);        return;        }#ifdef DEBUG_CACHE    qDebug( "Insert entry: %d, %d -> %d", pos, start, end );#endif    if ( start < *lowest ) {	*lowest = start;#ifdef DEBUG_CACHE	qDebug( "    moved lowest to %d", *lowest );#endif        }    if (pos == *entryp) {        entries[pos].start = start;        entries[pos].end = end;        (*entryp)++;        return;        }    int size = (*entryp) - pos;    memmove(&entries[pos+1], &entries[pos], size * sizeof(QPoolEntry));    entries[pos].start = start;    entries[pos].end = end;    (*entryp)++;}/*!Initialise the offscreen memory manager variables.*/void QSNAPScreen::setupOffScreen(){    // We really should be using the buffer manager instead, since that    // will allow hardware to be used that does not support linear blits    // (as well as allow for more ref2d optimisations!). For now we use the    // current mechanism to get this working.    //    // Note also that storing variables in offscreen video memory is a    // *really*, *really* bad idea. This is because video memory is terribly    // slow for read operations (usually on the order of 10-20Mb/s even on    // the fastest AGP cards!), so doing this is a performance killer. We do    // it for now once again just to get this working properly. Ideally the    // offscreen memory pool should be managed in an expandable shared    // system memory block.    useOffscreen = false;    if (hwDraw2d.BitBltLin && ((mapsize - size) >= 16384)) {        // Figure out position of offscreen memory        // Set up pool entries pointer table and 64-bit align it        ulong pos = (ulong)data + ((size + 8) & ~0x7);        entryp = (int*)(pos+0);        lowest = (uint*)(pos+4);        entries = (QPoolEntry*)(pos+8);        cacheStart = pos + 8 + sizeof(QPoolEntry);        useOffscreen = true;        }}/*!Requests a block of offscreen graphics card memory from the memorymanager; it will be aligned at pixmapOffsetAlignment(). If no memoryis free 0 will be returned, otherwise a pointer to the data withinthe framebuffer. QScreen::onCard can be used to retrieve a byte offsetfrom the start of graphics card memory from this pointer. The displayis locked while memory is allocated and unallocated in order topreserve the memory pool's integrity, so cache and uncache should notbe called if the screen is locked.\a amount is the amount of memory to allocate, \a optim gives the optimizationlevel (same values as QPixmap::Optimization).*/uchar * QSNAPScreen::cache(    int amount,    int optim){    // Check to see if we should cache the bitmap in memory    if (!useOffscreen || entryp == 0 || optim == int(QPixmap::NoOptim) )        return NULL;    // Get exclusive access to video memory    qt_fbdpy->grab(true);    // Check that we have enough room to allocate a new block    uint startp = cacheStart + (*entryp+1) * sizeof(QPoolEntry);    if (startp >= *lowest) {#ifdef DEBUG_CACHE	qDebug( "No room for pool entry in VRAM" );#endif	qt_fbdpy->ungrab();	return NULL;        }    // Get pixemap offset alignemtn in bytes    int byteAlign = pixmapOffsetAlignment() / 8;    // Try to find a gap in the allocated blocks.    int hold = (*entryp-1);    for (int i = 0; i < hold-1; i++) {        int freestart = entries[i+1].end;        int freeend = entries[i].start;        if (freestart != freeend) {            while (freestart % byteAlign)                freestart++;            int len = freeend - freestart;            if (len >= amount) {                insert_entry(i+1, freestart, freestart+amount);                qt_fbdpy->ungrab();                return data + freestart;                }            }        }    // No free blocks in already-taken memory; get some more    // if we can    uint newlowest = (*lowest) - amount;    if (newlowest % byteAlign) {        newlowest -= byteAlign;        while (newlowest % byteAlign)            newlowest++;        }    if (startp >= newlowest) {        qt_fbdpy->ungrab();#ifdef DEBUG_CACHE	qDebug( "No VRAM available for %d bytes", amount);#endif        return NULL;        }    insert_entry(*entryp, newlowest, *lowest);    qt_fbdpy->ungrab();    return data + newlowest;}/*!Delete a block of memory \a c allocated from graphics card memory.*/void QSNAPScreen::uncache(    uchar *c){    // Get exclusive access to video memory    qt_fbdpy->grab(true);    hwState2d.WaitTillIdle();    ulong pos = (ulong)c;    pos -= ((ulong)data);    uint hold = (*entryp);    for (uint i = 0; i < hold; i++) {        if (entries[i].start == pos) {            delete_entry(i);            qt_fbdpy->ungrab();            return;            }        }    qt_fbdpy->ungrab();    qDebug("Attempt to delete unknown offset %ld",pos);}/*!This is called to create the graphics rendering object for thespecific resolution and color depth.*/QGfx * QSNAPScreen::createGfx(    unsigned char * b,    int w,    int h,    int d,    int linestep){    QGfx * ret = NULL;    if (onCard(b)) {        switch (d) {#ifndef QT_NO_QWS_DEPTH_8            case 8:                ret = new QGfxSNAP<8,0>(b,w,h,cntState,hwState2d,hwDraw2d,state2d,draw2d);                break;#endif#ifndef QT_NO_QWS_DEPTH_16            case 16:                ret = new QGfxSNAP<16,0>(b,w,h,cntState,hwState2d,hwDraw2d,state2d,draw2d);                break;#endif#ifndef QT_NO_QWS_DEPTH_24            case 24:                ret = new QGfxSNAP<24,0>(b,w,h,cntState,hwState2d,hwDraw2d,state2d,draw2d);                break;#endif#ifndef QT_NO_QWS_DEPTH_32            case 32:                ret = new QGfxSNAP<32,0>(b,w,h,cntState,hwState2d,hwDraw2d,state2d,draw2d);                break;#endif            }        if (ret) {            ret->setLineStep(linestep);            return ret;            }        }    return QScreen::createGfx(b,w,h,d,linestep);}/*!\fn void QSNAPScreen::save()Save the state of the graphics card. It's called by the Qt/Embedded serverwhen the virtual console is switched.*/void QSNAPScreen::save(){    // TODO: We may need to do stuff in here to save the screen}/*!\fn void QSNAPScreen::restore()This is called when the virtual console is switched back to Qt/Embeddedand restores the graphics screen.*/void QSNAPScreen::restore(){    // TODO: We may need to do stuff in here to restore the screen}/*!\fn void QSNAPScreen::blank()This is to power down the display monitor using DPMS.*/void QSNAPScreen::blank(    bool on){    if (DPMSStates)        dpms.DPMSsetState(on ? DPMS_on : DPMS_off);}/*!\fn void QSNAPScreen::set()In paletted graphics modes, this sets color index \a i to the specified RGBvalue, (\a r, \a g, \a b).*/void QSNAPScreen::set(    unsigned int i,    unsigned int r,    unsigned int g,    unsigned int b){    GA_palette pal;    pal.Red = r;    pal.Green = g;    pal.Blue = b;    driver.SetPaletteData(&pal,1,i,false);    screenclut[i] = qRgb( r, g, b );}extern "C" QScreen * qt_get_screen_snap(    int display_id){    return new QSNAPScreen( display_id );}#endif // QT_NO_QWS_SNAP

⌨️ 快捷键说明

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