Qtopia Core 4.2 Screen Drivers

Материал из Wiki.crossplatform.ru

Перейти к: навигация, поиск
Image:qt-logo_new.png Image:qq-title-article.png
Qt Quarterly | Выпуск 19 | Документация


by Hеvard Wall

QScreen is a class that is specific to Qtopia Core (previously calledQt/Embedded). It is the base class for Qtopia Core's built-in andcustom screen drivers. In this article, we will review the changesthat were made to QScreen in Qtopia Core 4.2 and show how to takefull advantage of hardware acceleration.

Содержание

[править] Multihead Support

QScreen now features two virtual functions that can bereimplemented by subclasses to support multiple screens:

QList<QScreen *> subScreens() const;
QRegion region() const;
Qtopia Core 4.2 also include a "Multi" screen driver, which createsother QScreen instances and forwards all function calls to theappropriate QScreen. Here's an example of how to run a QtopiaCore application on three different screens simultaneously:
app -qws -display "Multi: QVFb:0 QVFb:offset=640,0:1 VNC"
Using -display, we tell Qtopia Core to create two instances ofthe Qt virtual buffer driver (" QVFb") and one instance of the VNCdriver. The second QVFb instance is given an offset of (640, 0), sothat it doesn't overlap the first instance.

The coordinates passed to your reimplementations of QScreen's virtual functions are always specifiedin global coordinates. In most cases, your existing custom drivers will workwith no change, but if you perform some kind of lookup in a data structurethat assumes the screen's origin is (0, 0), you will need to subtractQScreen::offset() to convert the globalcoordinates into screen coordinates.

[править] Window Surface Abstraction

Qtopia Core 4.2 introduces "window surfaces" as a mechanism to control the memory used when painting a QWidget.This provides a way to accelerate painting beyond what is possible byreimplementing QScreen's solidFill() andblit() functions. To support window surfaces, these factory functionswere added to QScreen:

QWSWindowSurface *createSurface(QWidget *widget) const;
QWSWindowSurface *createSurface(const QString &amp;key) const;

QWSWindowSurface is the abstraction of thearea a top-level QWidget (i.e., a window) is drawnonto. By default, if you are creating a window in the QWS server, this will bea chunk of local memory. If you are creating a window in a client process, itwill be a chunk of shared memory. And if you set theQt::WA_PaintOnScreen attribute on the window, it will be an areainside the framebuffer. This default behavior can be overridden byreimplementing the createSurface() functions in a subclass.

If you're writing a driver for a device with little memory and noframebuffer, you probably want to avoid drawing into memory at alland rather use an I/O controller to send drawing commands directlyto the video card. To achieve this, you would subclass QWSWindowSurface to avoid the memoryallocation and reimplement the paintDevice() function to return a QCustomRasterPaintDevice subclass.The paint device's paintEngine() function would return an instance ofan accelerated paint engine.

[править] Writing an Accelerated Paint Engine

Writing an accelerated paint engine consists of subclassing QRasterPaintEngine and reimplementingthe following two virtual functions, which are new in Qtopia Core 4.2:

void drawColorSpans(const QSpan *spans, int count,
                    uint color);
void drawBufferSpan(const uint *buffer, int bufferSize,
                    int x, int y, int length,
                    uint constantAlpha);

These functions are only called if the paint device's memory()function is reimplemented to return 0. The drawColorSpans()function is called to draw one or more spans with the given coloron the screen. The drawBufferSpan() function is called to draw abuffer of pixels from memory.

Be aware that both QWSWindowSurface andthe accelerated paint engine technique described above are included in QtopiaCore 4.2 as "preliminary APIs", meaning that they may change in a laterrelease.


Copyright © 2006 Trolltech Trademarks