summaryrefslogtreecommitdiffstats
path: root/examples/qws/svgalib
diff options
context:
space:
mode:
Diffstat (limited to 'examples/qws/svgalib')
-rw-r--r--examples/qws/svgalib/README5
-rw-r--r--examples/qws/svgalib/svgalib.pro19
-rw-r--r--examples/qws/svgalib/svgalibpaintdevice.cpp67
-rw-r--r--examples/qws/svgalib/svgalibpaintdevice.h66
-rw-r--r--examples/qws/svgalib/svgalibpaintengine.cpp192
-rw-r--r--examples/qws/svgalib/svgalibpaintengine.h79
-rw-r--r--examples/qws/svgalib/svgalibplugin.cpp75
-rw-r--r--examples/qws/svgalib/svgalibscreen.cpp354
-rw-r--r--examples/qws/svgalib/svgalibscreen.h84
-rw-r--r--examples/qws/svgalib/svgalibsurface.cpp87
-rw-r--r--examples/qws/svgalib/svgalibsurface.h76
11 files changed, 1104 insertions, 0 deletions
diff --git a/examples/qws/svgalib/README b/examples/qws/svgalib/README
new file mode 100644
index 0000000..0b2831f
--- /dev/null
+++ b/examples/qws/svgalib/README
@@ -0,0 +1,5 @@
+This is the SVGA screen driver plugin example from Qt 4.4. The code does
+not compile with Qt 4.5, because the internal graphics engine has changed.
+
+This is unsupported code, provided for convenience in case there is
+interest in porting it to Qt 4.5.
diff --git a/examples/qws/svgalib/svgalib.pro b/examples/qws/svgalib/svgalib.pro
new file mode 100644
index 0000000..8a47c1d
--- /dev/null
+++ b/examples/qws/svgalib/svgalib.pro
@@ -0,0 +1,19 @@
+TEMPLATE = lib
+CONFIG += plugin
+
+LIBS += -lvgagl -lvga
+
+TARGET = svgalibscreen
+target.path = $$[QT_INSTALL_PLUGINS]/gfxdrivers
+INSTALLS += target
+
+HEADERS = svgalibscreen.h \
+ svgalibpaintengine.h \
+ svgalibsurface.h \
+ svgalibpaintdevice.h
+SOURCES = svgalibscreen.cpp \
+ svgalibpaintengine.cpp \
+ svgalibsurface.cpp \
+ svgalibpaintdevice.cpp \
+ svgalibplugin.cpp
+
diff --git a/examples/qws/svgalib/svgalibpaintdevice.cpp b/examples/qws/svgalib/svgalibpaintdevice.cpp
new file mode 100644
index 0000000..b4e0276
--- /dev/null
+++ b/examples/qws/svgalib/svgalibpaintdevice.cpp
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "svgalibpaintdevice.h"
+#include "svgalibpaintengine.h"
+
+#include <QApplication>
+#include <QDesktopWidget>
+
+SvgalibPaintDevice::SvgalibPaintDevice(QWidget *w)
+ : QCustomRasterPaintDevice(w)
+{
+ pengine = new SvgalibPaintEngine;
+}
+
+SvgalibPaintDevice::~SvgalibPaintDevice()
+{
+ delete pengine;
+}
+
+int SvgalibPaintDevice::metric(PaintDeviceMetric m) const
+{
+ if (m == PdmWidth)
+ return QApplication::desktop()->screenGeometry().width();
+ else if (m == PdmHeight)
+ return QApplication::desktop()->screenGeometry().height();
+ return QCustomRasterPaintDevice::metric(m);
+}
+
diff --git a/examples/qws/svgalib/svgalibpaintdevice.h b/examples/qws/svgalib/svgalibpaintdevice.h
new file mode 100644
index 0000000..bf6cc7a
--- /dev/null
+++ b/examples/qws/svgalib/svgalibpaintdevice.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SVGALIBPAINTDEVICE_H
+#define SVGALIBPAINTDEVICE_H
+
+#include "svgalibpaintengine.h"
+#include <private/qpaintengine_raster_p.h>
+#include <qscreen_qws.h>
+
+//! [0]
+class SvgalibPaintDevice : public QCustomRasterPaintDevice
+{
+public:
+ SvgalibPaintDevice(QWidget *w);
+ ~SvgalibPaintDevice();
+
+ void* memory() const { return QScreen::instance()->base(); }
+
+ QPaintEngine *paintEngine() const { return pengine; }
+ int metric(PaintDeviceMetric m) const;
+
+private:
+ SvgalibPaintEngine *pengine;
+};
+//! [0]
+
+#endif // SVGALIBPAINTDEVICE_H
diff --git a/examples/qws/svgalib/svgalibpaintengine.cpp b/examples/qws/svgalib/svgalibpaintengine.cpp
new file mode 100644
index 0000000..3621db7
--- /dev/null
+++ b/examples/qws/svgalib/svgalibpaintengine.cpp
@@ -0,0 +1,192 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "svgalibpaintengine.h"
+
+#include <QColor>
+#include <vga.h>
+#include <vgagl.h>
+
+SvgalibPaintEngine::SvgalibPaintEngine()
+{
+}
+
+SvgalibPaintEngine::~SvgalibPaintEngine()
+{
+}
+
+//! [0]
+bool SvgalibPaintEngine::begin(QPaintDevice *dev)
+{
+ device = dev;
+ pen = Qt::NoPen;
+ simplePen = true;
+ brush = Qt::NoBrush;
+ simpleBrush = true;
+ matrix = QMatrix();
+ simpleMatrix = true;
+ setClip(QRect(0, 0, device->width(), device->height()));
+ opaque = true;
+ aliased = true;
+ sourceOver = true;
+
+ return QRasterPaintEngine::begin(dev);
+}
+//! [0]
+
+//! [1]
+bool SvgalibPaintEngine::end()
+{
+ gl_setclippingwindow(0, 0, device->width() - 1, device->height() - 1);
+ return QRasterPaintEngine::end();
+}
+//! [1]
+
+//! [2]
+void SvgalibPaintEngine::updateState(const QPaintEngineState &state)
+{
+ QPaintEngine::DirtyFlags flags = state.state();
+
+ if (flags & DirtyTransform) {
+ matrix = state.matrix();
+ simpleMatrix = (matrix.m12() == 0 && matrix.m21() == 0);
+ }
+
+ if (flags & DirtyPen) {
+ pen = state.pen();
+ simplePen = (pen.width() == 0 || pen.widthF() <= 1)
+ && (pen.style() == Qt::NoPen || pen.style() == Qt::SolidLine)
+ && (pen.color().alpha() == 255);
+ }
+
+ if (flags & DirtyBrush) {
+ brush = state.brush();
+ simpleBrush = (brush.style() == Qt::SolidPattern
+ || brush.style() == Qt::NoBrush)
+ && (brush.color().alpha() == 255);
+ }
+
+ if (flags & DirtyClipRegion)
+ setClip(state.clipRegion());
+
+ if (flags & DirtyClipEnabled) {
+ clipEnabled = state.isClipEnabled();
+ updateClip();
+ }
+
+ if (flags & DirtyClipPath) {
+ setClip(QRegion());
+ simpleClip = false;
+ }
+
+ if (flags & DirtyCompositionMode) {
+ const QPainter::CompositionMode m = state.compositionMode();
+ sourceOver = (m == QPainter::CompositionMode_SourceOver);
+ }
+
+ if (flags & DirtyOpacity)
+ opaque = (state.opacity() == 256);
+
+ if (flags & DirtyHints)
+ aliased = !(state.renderHints() & QPainter::Antialiasing);
+
+ QRasterPaintEngine::updateState(state);
+}
+//! [2]
+
+//! [3]
+void SvgalibPaintEngine::setClip(const QRegion &region)
+{
+ if (region.isEmpty())
+ clip = QRect(0, 0, device->width(), device->height());
+ else
+ clip = matrix.map(region) & QRect(0, 0, device->width(), device->height());
+ clipEnabled = true;
+ updateClip();
+}
+//! [3]
+
+//! [4]
+void SvgalibPaintEngine::updateClip()
+{
+ QRegion clipRegion = QRect(0, 0, device->width(), device->height());
+
+ if (!systemClip().isEmpty())
+ clipRegion &= systemClip();
+ if (clipEnabled)
+ clipRegion &= clip;
+
+ simpleClip = (clipRegion.rects().size() <= 1);
+
+ const QRect r = clipRegion.boundingRect();
+ gl_setclippingwindow(r.left(), r.top(),
+ r.x() + r.width(),
+ r.y() + r.height());
+}
+//! [4]
+
+//! [5]
+void SvgalibPaintEngine::drawRects(const QRect *rects, int rectCount)
+{
+ const bool canAccelerate = simplePen && simpleBrush && simpleMatrix
+ && simpleClip && opaque && aliased
+ && sourceOver;
+ if (!canAccelerate) {
+ QRasterPaintEngine::drawRects(rects, rectCount);
+ return;
+ }
+
+ for (int i = 0; i < rectCount; ++i) {
+ const QRect r = matrix.mapRect(rects[i]);
+ if (brush != Qt::NoBrush) {
+ gl_fillbox(r.left(), r.top(), r.width(), r.height(),
+ brush.color().rgba());
+ }
+ if (pen != Qt::NoPen) {
+ const int c = pen.color().rgba();
+ gl_hline(r.left(), r.top(), r.right(), c);
+ gl_hline(r.left(), r.bottom(), r.right(), c);
+ gl_line(r.left(), r.top(), r.left(), r.bottom(), c);
+ gl_line(r.right(), r.top(), r.right(), r.bottom(), c);
+ }
+ }
+}
+//! [5]
diff --git a/examples/qws/svgalib/svgalibpaintengine.h b/examples/qws/svgalib/svgalibpaintengine.h
new file mode 100644
index 0000000..1fa9770
--- /dev/null
+++ b/examples/qws/svgalib/svgalibpaintengine.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SVGALIBPAINTENGINE_H
+#define SVGALIBPAINTENGINE_H
+
+//! [0]
+#include <private/qpaintengine_raster_p.h>
+
+class SvgalibPaintEngine : public QRasterPaintEngine
+{
+public:
+ SvgalibPaintEngine();
+ ~SvgalibPaintEngine();
+
+ bool begin(QPaintDevice *device);
+ bool end();
+ void updateState(const QPaintEngineState &state);
+ void drawRects(const QRect *rects, int rectCount);
+
+private:
+ void setClip(const QRegion &region);
+ void updateClip();
+
+ QPen pen;
+ bool simplePen;
+ QBrush brush;
+ bool simpleBrush;
+ QMatrix matrix;
+ bool simpleMatrix;
+ QRegion clip;
+ bool clipEnabled;
+ bool simpleClip;
+ bool opaque;
+ bool aliased;
+ bool sourceOver;
+ QPaintDevice *device;
+};
+//! [0]
+
+#endif // SVGALIBPAINTENGINE_H
diff --git a/examples/qws/svgalib/svgalibplugin.cpp b/examples/qws/svgalib/svgalibplugin.cpp
new file mode 100644
index 0000000..080a350
--- /dev/null
+++ b/examples/qws/svgalib/svgalibplugin.cpp
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "svgalibscreen.h"
+
+#include <QScreenDriverPlugin>
+#include <QStringList>
+
+class SvgalibPlugin : public QScreenDriverPlugin
+{
+public:
+ SvgalibPlugin();
+
+ QStringList keys() const;
+ QScreen *create(const QString&, int displayId);
+};
+
+SvgalibPlugin::SvgalibPlugin()
+ : QScreenDriverPlugin()
+{
+}
+
+QStringList SvgalibPlugin::keys() const
+{
+ return (QStringList() << "svgalib");
+}
+
+QScreen* SvgalibPlugin::create(const QString& driver, int displayId)
+{
+ if (driver.toLower() != "svgalib")
+ return 0;
+
+ return new SvgalibScreen(displayId);
+}
+
+Q_EXPORT_STATIC_PLUGIN(Svgalib)
+Q_EXPORT_PLUGIN2(svgalibscreendriver, SvgalibPlugin)
diff --git a/examples/qws/svgalib/svgalibscreen.cpp b/examples/qws/svgalib/svgalibscreen.cpp
new file mode 100644
index 0000000..1961d3c
--- /dev/null
+++ b/examples/qws/svgalib/svgalibscreen.cpp
@@ -0,0 +1,354 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "svgalibscreen.h"
+#include "svgalibsurface.h"
+
+#include <QVector>
+#include <QApplication>
+#include <QColor>
+#include <QWidget>
+
+#include <math.h>
+
+static int getModeDepth(vga_modeinfo *mode)
+{
+ const int bits = int(log2(mode->colors));
+ if (bits == 24 && mode->bytesperpixel == 4)
+ return 32;
+ return bits;
+}
+
+//! [0]
+bool SvgalibScreen::connect(const QString &displaySpec)
+{
+ int mode = vga_getdefaultmode();
+ if (mode <= 0) {
+ qCritical("SvgalibScreen::connect(): invalid vga mode");
+ return false;
+ }
+
+ vga_modeinfo *modeinfo = vga_getmodeinfo(mode);
+
+ QScreen::lstep = modeinfo->linewidth;
+ QScreen::dw = QScreen::w = modeinfo->width;
+ QScreen::dh = QScreen::h = modeinfo->height;
+ QScreen::d = getModeDepth(modeinfo);
+ QScreen::size = QScreen::lstep * dh;
+ QScreen::data = 0;
+
+ switch (depth()) {
+ case 32:
+ setPixelFormat(QImage::Format_ARGB32_Premultiplied);
+ break;
+ case 24:
+ setPixelFormat(QImage::Format_RGB888);
+ break;
+ case 16:
+ setPixelFormat(QImage::Format_RGB16);
+ break;
+ case 15:
+ setPixelFormat(QImage::Format_RGB555);
+ break;
+ default:
+ break;
+ }
+
+ const int dpi = 72;
+ QScreen::physWidth = qRound(QScreen::dw * 25.4 / dpi);
+ QScreen::physHeight = qRound(QScreen::dh * 25.4 / dpi);
+
+ const QStringList args = displaySpec.split(QLatin1Char(':'),
+ QString::SkipEmptyParts);
+ grayscale = args.contains(QLatin1String("grayscale"), Qt::CaseInsensitive);
+
+ return true;
+}
+//! [0]
+
+void SvgalibScreen::initColorMap()
+{
+ const int numColors = vga_getcolors();
+ if (numColors == 2 || numColors > 256) {
+ screencols = 0;
+ return; // not a palette based mode
+ }
+
+ if (numColors == 16) {
+ if (grayscale) {
+ for (int i = 0; i < 256; ++i) {
+ const int c = i * 16 / 256;
+ vga_setpalette(i, c, c, c);
+ }
+ screencols = 256; // XXX: takes advantage of optimization in alloc()
+ } else { // read in EGA palette
+ int r, g, b;
+ for (int i = 0; i < 16; ++i) {
+ vga_getpalette(i, &r, &g, &b);
+ screenclut[i] = qRgb(r, g, b);
+ }
+ screencols = 16;
+ }
+
+ return;
+ }
+
+ Q_ASSERT(numColors == 256);
+
+ if (grayscale) {
+ for (int i = 0; i < 256; ++i) {
+ const int c = i * 64 / 256;
+ vga_setpalette(i, c, c, c);
+ }
+ } else {
+ int i = 0;
+
+#if 0
+ // read in EGA palette
+ while (i < 16) {
+ int r, g, b;
+ vga_getpalette(i, &r, &g, &b);
+ screenclut[i] = qRgb(r, g, b);
+ ++i;
+ }
+ screencols = 16;
+#endif
+
+ // 6 * 6 * 6 color cube
+ for (int r = 0; r < 6; ++r) {
+ for (int g = 0; g < 6; ++g) {
+ for (int b = 0; b < 6; ++b) {
+ vga_setpalette(i, r * 64/6, g * 64/6, b * 64/6);
+ screenclut[i] = qRgb(r * 256/6, g * 256/6, b * 256/6);
+ ++i;
+ }
+ }
+ }
+ screencols = i;
+
+ while (i < 256) {
+ screenclut[i] = qRgb(0, 0, 0);
+ ++i;
+ }
+ }
+}
+
+//! [1]
+bool SvgalibScreen::initDevice()
+{
+ if (vga_init() != 0) {
+ qCritical("SvgalibScreen::initDevice(): unable to initialize svgalib");
+ return false;
+ }
+
+ int mode = vga_getdefaultmode();
+ if (vga_setmode(mode) == -1) {
+ qCritical("SvgalibScreen::initialize(): unable to set graphics mode");
+ return false;
+ }
+
+ if (gl_setcontextvga(mode) != 0) {
+ qCritical("SvgalibScreen::initDevice(): unable to set vga context");
+ return false;
+ }
+ context = gl_allocatecontext();
+ gl_getcontext(context);
+
+ vga_modeinfo *modeinfo = vga_getmodeinfo(mode);
+ if (modeinfo->flags & IS_LINEAR)
+ QScreen::data = vga_getgraphmem();
+
+ initColorMap();
+
+ QScreenCursor::initSoftwareCursor();
+ return true;
+}
+//! [1]
+
+//! [2]
+void SvgalibScreen::shutdownDevice()
+{
+ gl_freecontext(context);
+ vga_setmode(TEXT);
+}
+//! [2]
+
+//! [3]
+void SvgalibScreen::disconnect()
+{
+}
+//! [3]
+
+//! [4]
+void SvgalibScreen::solidFill(const QColor &color, const QRegion &reg)
+{
+ int c;
+ if (depth() == 4 || depth() == 8)
+ c = alloc(color.red(), color.green(), color.blue());
+ else
+ c = gl_rgbcolor(color.red(), color.green(), color.blue());
+
+ const QVector<QRect> rects = (reg & region()).rects();
+ for (int i = 0; i < rects.size(); ++i) {
+ const QRect r = rects.at(i);
+ gl_fillbox(r.left(), r.top(), r.width(), r.height(), c);
+ }
+}
+//! [4]
+
+void SvgalibScreen::blit16To8(const QImage &image,
+ const QPoint &topLeft, const QRegion &region)
+{
+ const int imageStride = image.bytesPerLine() / 2;
+ const QVector<QRect> rects = region.rects();
+
+ for (int i = 0; i < rects.size(); ++i) {
+ const QRect r = rects.at(i).translated(-topLeft);
+ int y = r.y();
+ const quint16 *s = reinterpret_cast<const quint16*>(image.scanLine(y));
+
+ while (y <= r.bottom()) {
+ int x1 = r.x();
+ while (x1 <= r.right()) {
+ const quint16 c = s[x1];
+ int x2 = x1;
+ // find span length
+ while ((x2+1 < r.right()) && (s[x2+1] == c))
+ ++x2;
+ gl_hline(x1 + topLeft.x(), y + topLeft.y(), x2 + topLeft.x(),
+ qt_colorConvert<quint8, quint16>(c, 0));
+ x1 = x2 + 1;
+ }
+ s += imageStride;
+ ++y;
+ }
+ }
+}
+
+void SvgalibScreen::blit32To8(const QImage &image,
+ const QPoint &topLeft, const QRegion &region)
+{
+ const int imageStride = image.bytesPerLine() / 4;
+ const QVector<QRect> rects = region.rects();
+
+ for (int i = 0; i < rects.size(); ++i) {
+ const QRect r = rects.at(i).translated(-topLeft);
+ int y = r.y();
+ const quint32 *s = reinterpret_cast<const quint32*>(image.scanLine(y));
+
+ while (y <= r.bottom()) {
+ int x1 = r.x();
+ while (x1 <= r.right()) {
+ const quint32 c = s[x1];
+ int x2 = x1;
+ // find span length
+ while ((x2+1 < r.right()) && (s[x2+1] == c))
+ ++x2;
+ gl_hline(x1 + topLeft.x(), y + topLeft.y(), x2 + topLeft.x(),
+ qt_colorConvert<quint8, quint32>(c, 0));
+ x1 = x2 + 1;
+ }
+ s += imageStride;
+ ++y;
+ }
+ }
+}
+
+//! [5]
+void SvgalibScreen::blit(const QImage &img, const QPoint &topLeft,
+ const QRegion &reg)
+{
+ if (depth() == 8) {
+ switch (img.format()) {
+ case QImage::Format_RGB16:
+ blit16To8(img, topLeft, reg);
+ return;
+ case QImage::Format_RGB32:
+ case QImage::Format_ARGB32:
+ case QImage::Format_ARGB32_Premultiplied:
+ blit32To8(img, topLeft, reg);
+ return;
+ default:
+ break;
+ }
+ }
+
+ if (img.format() != pixelFormat()) {
+ if (base())
+ QScreen::blit(img, topLeft, reg);
+ return;
+ }
+
+ const QVector<QRect> rects = (reg & region()).rects();
+
+ for (int i = 0; i < rects.size(); ++i) {
+ const QRect r = rects.at(i);
+ gl_putboxpart(r.x(), r.y(), r.width(), r.height(),
+ img.width(), img.height(),
+ static_cast<void*>(const_cast<uchar*>(img.bits())),
+ r.x() - topLeft.x(), r.y() - topLeft.y());
+ }
+}
+//! [5]
+
+//! [7]
+QWSWindowSurface* SvgalibScreen::createSurface(QWidget *widget) const
+{
+ if (base()) {
+ static int onScreenPaint = -1;
+ if (onScreenPaint == -1)
+ onScreenPaint = qgetenv("QT_ONSCREEN_PAINT").toInt();
+
+ if (onScreenPaint > 0 || widget->testAttribute(Qt::WA_PaintOnScreen))
+ return new SvgalibSurface(widget);
+ }
+ return QScreen::createSurface(widget);
+}
+//! [7]
+
+//! [8]
+QWSWindowSurface* SvgalibScreen::createSurface(const QString &key) const
+{
+ if (key == QLatin1String("svgalib"))
+ return new SvgalibSurface;
+ return QScreen::createSurface(key);
+}
+//! [8]
diff --git a/examples/qws/svgalib/svgalibscreen.h b/examples/qws/svgalib/svgalibscreen.h
new file mode 100644
index 0000000..4d32b7c
--- /dev/null
+++ b/examples/qws/svgalib/svgalibscreen.h
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SVGALIBSCREEN_H
+#define SVGALIBSCREEN_H
+
+#include <QScreen>
+
+#include <vga.h>
+#include <vgagl.h>
+
+//! [0]
+class SvgalibScreen : public QScreen
+{
+public:
+ SvgalibScreen(int displayId) : QScreen(displayId) {}
+ ~SvgalibScreen() {}
+
+ bool connect(const QString &displaySpec);
+ bool initDevice();
+ void shutdownDevice();
+ void disconnect();
+
+ void setMode(int, int, int) {}
+ void blank(bool) {}
+
+ void blit(const QImage &img, const QPoint &topLeft, const QRegion &region);
+ void solidFill(const QColor &color, const QRegion &region);
+//! [0]
+
+ QWSWindowSurface* createSurface(QWidget *widget) const;
+ QWSWindowSurface* createSurface(const QString &key) const;
+
+//! [1]
+private:
+ void initColorMap();
+ void blit16To8(const QImage &image,
+ const QPoint &topLeft, const QRegion &region);
+ void blit32To8(const QImage &image,
+ const QPoint &topLeft, const QRegion &region);
+
+ GraphicsContext *context;
+};
+//! [1]
+
+#endif // SVGALIBSCREEN_H
diff --git a/examples/qws/svgalib/svgalibsurface.cpp b/examples/qws/svgalib/svgalibsurface.cpp
new file mode 100644
index 0000000..8e7e6b6
--- /dev/null
+++ b/examples/qws/svgalib/svgalibsurface.cpp
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "svgalibsurface.h"
+#include "svgalibpaintdevice.h"
+
+#include <vgagl.h>
+
+SvgalibSurface::SvgalibSurface() : QWSWindowSurface(), pdevice(0)
+{
+ setSurfaceFlags(Opaque);
+}
+
+SvgalibSurface::SvgalibSurface(QWidget *w)
+ : QWSWindowSurface(w)
+{
+ setSurfaceFlags(Opaque);
+ pdevice = new SvgalibPaintDevice(w);
+}
+
+SvgalibSurface::~SvgalibSurface()
+{
+ delete pdevice;
+}
+
+void SvgalibSurface::setGeometry(const QRect &rect)
+{
+ QWSWindowSurface::setGeometry(rect);
+}
+
+QPoint SvgalibSurface::painterOffset() const
+{
+ return geometry().topLeft() + QWSWindowSurface::painterOffset();
+}
+
+//! [0]
+bool SvgalibSurface::scroll(const QRegion &region, int dx, int dy)
+{
+ const QVector<QRect> rects = region.rects();
+ for (int i = 0; i < rects.size(); ++i) {
+ const QRect r = rects.at(i);
+ gl_copybox(r.left(), r.top(), r.width(), r.height(),
+ r.left() + dx, r.top() + dy);
+ }
+
+ return true;
+}
+//! [0]
+
diff --git a/examples/qws/svgalib/svgalibsurface.h b/examples/qws/svgalib/svgalibsurface.h
new file mode 100644
index 0000000..c33d51a
--- /dev/null
+++ b/examples/qws/svgalib/svgalibsurface.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SVGALIBSURFACE_H
+#define SVGALIBSURFACE_H
+
+#include "svgalibpaintengine.h"
+#include "svgalibpaintdevice.h"
+#include <private/qwindowsurface_qws_p.h>
+
+class SvgalibPaintDevice;
+
+//! [0]
+class SvgalibSurface : public QWSWindowSurface
+{
+public:
+ SvgalibSurface();
+ SvgalibSurface(QWidget *w);
+ ~SvgalibSurface();
+
+ void setGeometry(const QRect &rect);
+ bool isValid() const { return true; }
+ bool scroll(const QRegion &region, int dx, int dy);
+ QString key() const { return QLatin1String("svgalib"); }
+
+ bool attach(const QByteArray &) { return true; }
+ void detach() {}
+
+ QImage image() const { return QImage(); }
+ QPaintDevice *paintDevice() { return pdevice; }
+ QPoint painterOffset() const;
+
+private:
+ SvgalibPaintDevice *pdevice;
+};
+//! [0]
+
+#endif // SVGALIBSURFACE_H