summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/configure.json24
-rw-r--r--src/gui/image/qicon.cpp42
-rw-r--r--src/gui/image/qicon_p.h2
-rw-r--r--src/gui/image/qimage.cpp157
-rw-r--r--src/gui/image/qimage.h1
-rw-r--r--src/gui/image/qimage_conversions.cpp17
-rw-r--r--src/gui/image/qimagewriter.cpp14
-rw-r--r--src/gui/image/qpixmap_raster.cpp23
-rw-r--r--src/gui/image/qpixmap_raster_p.h2
-rw-r--r--src/gui/kernel/qevent.cpp98
-rw-r--r--src/gui/kernel/qevent.h9
-rw-r--r--src/gui/kernel/qevent_p.h9
-rw-r--r--src/gui/kernel/qguiapplication.cpp106
-rw-r--r--src/gui/kernel/qguiapplication_p.h8
-rw-r--r--src/gui/kernel/qoffscreensurface.cpp37
-rw-r--r--src/gui/kernel/qoffscreensurface.h3
-rw-r--r--src/gui/kernel/qplatformdialoghelper.cpp21
-rw-r--r--src/gui/kernel/qplatformdialoghelper.h5
-rw-r--r--src/gui/kernel/qplatformintegration.cpp11
-rw-r--r--src/gui/kernel/qplatformintegration.h3
-rw-r--r--src/gui/kernel/qplatformmenu.cpp5
-rw-r--r--src/gui/kernel/qplatformmenu.h2
-rw-r--r--src/gui/kernel/qplatformscreen.cpp88
-rw-r--r--src/gui/kernel/qplatformscreen.h15
-rw-r--r--src/gui/kernel/qplatformtheme.cpp26
-rw-r--r--src/gui/kernel/qplatformtheme.h4
-rw-r--r--src/gui/kernel/qplatformwindow.cpp31
-rw-r--r--src/gui/kernel/qplatformwindow.h3
-rw-r--r--src/gui/kernel/qscreen.cpp36
-rw-r--r--src/gui/kernel/qscreen.h7
-rw-r--r--src/gui/kernel/qstylehints.cpp55
-rw-r--r--src/gui/kernel/qstylehints.h4
-rw-r--r--src/gui/kernel/qsurface.cpp2
-rw-r--r--src/gui/kernel/qsurface.h3
-rw-r--r--src/gui/kernel/qtouchdevice.h1
-rw-r--r--src/gui/kernel/qtouchdevice_p.h7
-rw-r--r--src/gui/kernel/qwindow.cpp124
-rw-r--r--src/gui/kernel/qwindow.h15
-rw-r--r--src/gui/kernel/qwindow_p.h17
-rw-r--r--src/gui/kernel/qwindowsysteminterface.cpp580
-rw-r--r--src/gui/kernel/qwindowsysteminterface.h74
-rw-r--r--src/gui/kernel/qwindowsysteminterface_p.h18
-rw-r--r--src/gui/opengl/opengl.pri6
-rw-r--r--src/gui/opengl/qopengl.cpp21
-rw-r--r--src/gui/opengl/qopengldebug.h5
-rw-r--r--src/gui/opengl/qopenglengineshadermanager.cpp199
-rw-r--r--src/gui/opengl/qopenglengineshadermanager_p.h1
-rw-r--r--src/gui/opengl/qopenglengineshadersource_p.h517
-rw-r--r--src/gui/opengl/qopenglfunctions.h568
-rw-r--r--src/gui/opengl/qopenglpaintengine.cpp136
-rw-r--r--src/gui/opengl/qopenglpaintengine_p.h74
-rw-r--r--src/gui/opengl/qopenglprogrambinarycache.cpp376
-rw-r--r--src/gui/opengl/qopenglprogrambinarycache_p.h100
-rw-r--r--src/gui/opengl/qopenglshaderprogram.cpp543
-rw-r--r--src/gui/opengl/qopenglshaderprogram.h12
-rw-r--r--src/gui/opengl/qopengltexture.cpp90
-rw-r--r--src/gui/opengl/qopengltexture.h6
-rw-r--r--src/gui/opengl/qopengltexture_p.h5
-rw-r--r--src/gui/opengl/qopengltextureblitter.cpp4
-rw-r--r--src/gui/opengl/qopengltexturecache.cpp2
-rw-r--r--src/gui/opengl/qopengltexturecache_p.h28
-rw-r--r--src/gui/opengl/qopengltextureglyphcache.cpp16
-rw-r--r--src/gui/painting/painting.pri3
-rw-r--r--src/gui/painting/qbrush.cpp27
-rw-r--r--src/gui/painting/qcolorprofile.cpp (renamed from src/gui/painting/qgammatables.cpp)47
-rw-r--r--src/gui/painting/qcolorprofile_p.h157
-rw-r--r--src/gui/painting/qcoregraphics.mm26
-rw-r--r--src/gui/painting/qdrawhelper.cpp1323
-rw-r--r--src/gui/painting/qdrawhelper_neon.cpp2
-rw-r--r--src/gui/painting/qdrawhelper_neon_p.h2
-rw-r--r--src/gui/painting/qdrawhelper_p.h18
-rw-r--r--src/gui/painting/qmemrotate.cpp275
-rw-r--r--src/gui/painting/qmemrotate_p.h13
-rw-r--r--src/gui/painting/qpaintengine_raster.cpp67
-rw-r--r--src/gui/painting/qpaintengine_raster_p.h2
-rw-r--r--src/gui/painting/qpainter.h3
-rw-r--r--src/gui/painting/qpdf.cpp13
-rw-r--r--src/gui/painting/qregion.cpp2
-rw-r--r--src/gui/painting/qrgba64_p.h100
-rw-r--r--src/gui/painting/qtriangulator.cpp40
-rw-r--r--src/gui/painting/qtriangulator_p.h17
-rw-r--r--src/gui/text/qfontengine.cpp7
-rw-r--r--src/gui/text/qfontengine_ft.cpp36
-rw-r--r--src/gui/text/qfontengine_ft_p.h2
-rw-r--r--src/gui/text/qfontengine_p.h1
-rw-r--r--src/gui/text/qplatformfontdatabase.cpp11
-rw-r--r--src/gui/text/qtextdocument.cpp19
-rw-r--r--src/gui/text/qtextdocument.h1
-rw-r--r--src/gui/text/qtexthtmlparser.cpp57
-rw-r--r--src/gui/text/qtextlayout.cpp10
-rw-r--r--src/gui/util/qdesktopservices.cpp9
91 files changed, 4184 insertions, 2524 deletions
diff --git a/src/gui/configure.json b/src/gui/configure.json
index 6f87eb5aed..02032dee8f 100644
--- a/src/gui/configure.json
+++ b/src/gui/configure.json
@@ -32,6 +32,7 @@
"opengl": { "type": "optionalString", "values": [ "no", "yes", "desktop", "es2", "dynamic" ] },
"opengl-es-2": { "type": "void", "name": "opengl", "value": "es2" },
"opengles3": "boolean",
+ "openvg": "boolean",
"qpa": { "type": "string", "name": "qpa_default_platform" },
"qpa-platform-guard": "boolean",
"sm": { "type": "boolean", "name": "sessionmanager" },
@@ -167,7 +168,7 @@
"label": "Mir client libraries",
"test": "qpa/mirclient",
"sources": [
- { "type": "pkgConfig", "args": "egl mirclient ubuntu-platform-api" }
+ { "type": "pkgConfig", "args": "egl mirclient ubuntu-platform-api libcontent-hub" }
]
},
"mtdev": {
@@ -193,6 +194,14 @@
{ "type": "makeSpec", "spec": "OPENGL_ES2" }
]
},
+ "openvg": {
+ "label": "OpenVG",
+ "test": "unix/openvg",
+ "sources": [
+ { "type": "pkgConfig", "args": "vg" },
+ { "type": "makeSpec", "spec": "OPENVG" }
+ ]
+ },
"tslib": {
"label": "tslib",
"test": "unix/tslib",
@@ -502,7 +511,7 @@
"kms": {
"label": "KMS",
"condition": "libs.drm",
- "output": [ "publicQtConfig" ]
+ "output": [ "publicQtConfig", "privateFeature" ]
},
"libinput": {
"label": "libinput",
@@ -587,9 +596,14 @@
"condition": "features.opengl-desktop || features.opengl-dynamic || features.opengles2",
"output": [ "publicFeature", "feature" ]
},
+ "openvg": {
+ "label": "OpenVG",
+ "condition": "libs.openvg",
+ "output": [ "publicFeature" ]
+ },
"egl": {
"label": "EGL",
- "condition": "features.opengl && (features.angle || libs.egl)",
+ "condition": "(features.opengl || features.openvg) && (features.angle || libs.egl)",
"output": [ "privateFeature", "feature" ]
},
"egl_x11": {
@@ -1047,6 +1061,8 @@ QMAKE_LIBDIR_OPENGL[_ES2] and QMAKE_LIBS_OPENGL[_ES2] in the mkspec for your pla
"gif", "ico", "jpeg", "system-jpeg", "png", "system-png"
]
},
+ "egl",
+ "openvg",
{
"section": "OpenGL",
"entries": [
@@ -1055,7 +1071,6 @@ QMAKE_LIBDIR_OPENGL[_ES2] and QMAKE_LIBS_OPENGL[_ES2] in the mkspec for your pla
"args": "angle",
"condition": "config.win32"
},
- "egl",
"opengl-desktop",
{
"type": "feature",
@@ -1093,6 +1108,7 @@ QMAKE_LIBDIR_OPENGL[_ES2] and QMAKE_LIBS_OPENGL[_ES2] in the mkspec for your pla
},
"linuxfb", "mirclient",
{
+ "type": "feature",
"message": "INTEGRITY framebuffer",
"condition": "config.integrity",
"args": "integrityfb"
diff --git a/src/gui/image/qicon.cpp b/src/gui/image/qicon.cpp
index 0d2f55b1c2..e8f2c878c8 100644
--- a/src/gui/image/qicon.cpp
+++ b/src/gui/image/qicon.cpp
@@ -137,8 +137,8 @@ static qreal qt_effective_device_pixel_ratio(QWindow *window = 0)
return qApp->devicePixelRatio(); // Don't know which window to target.
}
-QIconPrivate::QIconPrivate()
- : engine(0), ref(1),
+QIconPrivate::QIconPrivate(QIconEngine *e)
+ : engine(e), ref(1),
serialNum(serialNumCounter.fetchAndAddRelaxed(1)),
detach_no(0),
is_mask(false)
@@ -673,9 +673,8 @@ QIcon::QIcon(const QString &fileName)
ownership of the engine.
*/
QIcon::QIcon(QIconEngine *engine)
- :d(new QIconPrivate)
+ :d(new QIconPrivate(engine))
{
- d->engine = engine;
}
/*!
@@ -950,8 +949,7 @@ void QIcon::detach()
d = 0;
return;
} else if (d->ref.load() != 1) {
- QIconPrivate *x = new QIconPrivate;
- x->engine = d->engine->clone();
+ QIconPrivate *x = new QIconPrivate(d->engine->clone());
if (!d->ref.deref())
delete d;
d = x;
@@ -974,10 +972,8 @@ void QIcon::addPixmap(const QPixmap &pixmap, Mode mode, State state)
if (pixmap.isNull())
return;
detach();
- if (!d) {
- d = new QIconPrivate;
- d->engine = new QPixmapIconEngine;
- }
+ if (!d)
+ d = new QIconPrivate(new QPixmapIconEngine);
d->engine->addPixmap(pixmap, mode, state);
}
@@ -1037,8 +1033,7 @@ void QIcon::addFile(const QString &fileName, const QSize &size, Mode mode, State
if (!engine)
engine = iconEngineFromSuffix(fileName, QMimeDatabase().mimeTypeForFile(info).preferredSuffix());
#endif // !QT_NO_MIMETYPE
- d = new QIconPrivate;
- d->engine = engine ? engine : new QPixmapIconEngine;
+ d = new QIconPrivate(engine ? engine : new QPixmapIconEngine);
}
d->engine->addFile(fileName, size, mode, state);
@@ -1240,12 +1235,10 @@ bool QIcon::hasThemeIcon(const QString &name)
*/
void QIcon::setIsMask(bool isMask)
{
- if (!d) {
- d = new QIconPrivate;
- d->engine = new QPixmapIconEngine;
- } else {
+ if (!d)
+ d = new QIconPrivate(new QPixmapIconEngine);
+ else
detach();
- }
d->is_mask = isMask;
}
@@ -1326,22 +1319,17 @@ QDataStream &operator>>(QDataStream &s, QIcon &icon)
QString key;
s >> key;
if (key == QLatin1String("QPixmapIconEngine")) {
- icon.d = new QIconPrivate;
- QIconEngine *engine = new QPixmapIconEngine;
- icon.d->engine = engine;
- engine->read(s);
+ icon.d = new QIconPrivate(new QPixmapIconEngine);
+ icon.d->engine->read(s);
} else if (key == QLatin1String("QIconLoaderEngine")) {
- icon.d = new QIconPrivate;
- QIconEngine *engine = new QIconLoaderEngine();
- icon.d->engine = engine;
- engine->read(s);
+ icon.d = new QIconPrivate(new QIconLoaderEngine());
+ icon.d->engine->read(s);
} else {
const int index = loader()->indexOf(key);
if (index != -1) {
if (QIconEnginePlugin *factory = qobject_cast<QIconEnginePlugin*>(loader()->instance(index))) {
if (QIconEngine *engine= factory->create()) {
- icon.d = new QIconPrivate;
- icon.d->engine = engine;
+ icon.d = new QIconPrivate(engine);
engine->read(s);
} // factory
} // instance
diff --git a/src/gui/image/qicon_p.h b/src/gui/image/qicon_p.h
index a978a72192..aa358e88af 100644
--- a/src/gui/image/qicon_p.h
+++ b/src/gui/image/qicon_p.h
@@ -64,7 +64,7 @@ QT_BEGIN_NAMESPACE
class QIconPrivate
{
public:
- QIconPrivate();
+ explicit QIconPrivate(QIconEngine *e);
~QIconPrivate() {
delete engine;
diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp
index 9e9f01a46a..9870e19cec 100644
--- a/src/gui/image/qimage.cpp
+++ b/src/gui/image/qimage.cpp
@@ -2121,6 +2121,44 @@ QImage QImage::convertToFormat(Format format, const QVector<QRgb> &colorTable, Q
}
/*!
+ \since 5.9
+
+ Changes the format of the image without changing the data. Only
+ works between formats of the same depth.
+
+ Returns \c true if successful.
+
+ This function can be used to change images with alpha-channels to
+ their corresponding opaque formats if the data is known to be opaque-only,
+ or to change the format of a given image buffer before overwriting
+ it with new data.
+
+ \warning The function does not check if the image data is valid in the
+ new format and will still return \c true if the depths are compatible.
+ Operations on an image with invalid data are undefined.
+
+ \warning If the image is not detached, this will cause the data to be
+ copied.
+
+ \sa isDetached(), hasAlphaChannel(), convertToFormat()
+*/
+
+bool QImage::reinterpretAsFormat(Format format)
+{
+ if (!d)
+ return false;
+ if (d->format == format)
+ return true;
+ if (qt_depthForFormat(format) != qt_depthForFormat(d->format))
+ return false;
+ if (!isDetached()) // Detach only if shared, not for read-only data.
+ detach();
+
+ d->format = format;
+ return true;
+}
+
+/*!
\fn bool QImage::valid(const QPoint &pos) const
Returns \c true if \a pos is a valid coordinate pair within the
@@ -4458,7 +4496,8 @@ QImage QImage::smoothScaled(int w, int h) const {
return src;
}
-static QImage rotated90(const QImage &image) {
+static QImage rotated90(const QImage &image)
+{
QImage out(image.height(), image.width(), image.format());
out.setDotsPerMeterX(image.dotsPerMeterY());
out.setDotsPerMeterY(image.dotsPerMeterX());
@@ -4466,49 +4505,10 @@ static QImage rotated90(const QImage &image) {
out.setColorTable(image.colorTable());
int w = image.width();
int h = image.height();
- switch (image.format()) {
- case QImage::Format_RGB32:
- case QImage::Format_ARGB32:
- case QImage::Format_ARGB32_Premultiplied:
- case QImage::Format_RGBX8888:
- case QImage::Format_RGBA8888:
- case QImage::Format_RGBA8888_Premultiplied:
- case QImage::Format_BGR30:
- case QImage::Format_A2BGR30_Premultiplied:
- case QImage::Format_RGB30:
- case QImage::Format_A2RGB30_Premultiplied:
- qt_memrotate270(reinterpret_cast<const quint32*>(image.bits()),
- w, h, image.bytesPerLine(),
- reinterpret_cast<quint32*>(out.bits()),
- out.bytesPerLine());
- break;
- case QImage::Format_RGB666:
- case QImage::Format_ARGB6666_Premultiplied:
- case QImage::Format_ARGB8565_Premultiplied:
- case QImage::Format_ARGB8555_Premultiplied:
- case QImage::Format_RGB888:
- qt_memrotate270(reinterpret_cast<const quint24*>(image.bits()),
- w, h, image.bytesPerLine(),
- reinterpret_cast<quint24*>(out.bits()),
- out.bytesPerLine());
- break;
- case QImage::Format_RGB555:
- case QImage::Format_RGB16:
- case QImage::Format_ARGB4444_Premultiplied:
- qt_memrotate270(reinterpret_cast<const quint16*>(image.bits()),
- w, h, image.bytesPerLine(),
- reinterpret_cast<quint16*>(out.bits()),
- out.bytesPerLine());
- break;
- case QImage::Format_Alpha8:
- case QImage::Format_Grayscale8:
- case QImage::Format_Indexed8:
- qt_memrotate270(reinterpret_cast<const quint8*>(image.bits()),
- w, h, image.bytesPerLine(),
- reinterpret_cast<quint8*>(out.bits()),
- out.bytesPerLine());
- break;
- default:
+ const MemRotateFunc memrotate = qMemRotateFunctions[qPixelLayouts[image.format()].bpp][2];
+ if (memrotate) {
+ memrotate(image.constBits(), w, h, image.bytesPerLine(), out.bits(), out.bytesPerLine());
+ } else {
for (int y=0; y<h; ++y) {
if (image.colorCount())
for (int x=0; x<w; ++x)
@@ -4517,18 +4517,29 @@ static QImage rotated90(const QImage &image) {
for (int x=0; x<w; ++x)
out.setPixel(h-y-1, x, image.pixel(x, y));
}
- break;
}
return out;
}
+static QImage rotated180(const QImage &image)
+{
+ const MemRotateFunc memrotate = qMemRotateFunctions[qPixelLayouts[image.format()].bpp][1];
+ if (!memrotate)
+ return image.mirrored(true, true);
-static QImage rotated180(const QImage &image) {
- return image.mirrored(true, true);
+ QImage out(image.width(), image.height(), image.format());
+ out.setDotsPerMeterX(image.dotsPerMeterY());
+ out.setDotsPerMeterY(image.dotsPerMeterX());
+ if (image.colorCount() > 0)
+ out.setColorTable(image.colorTable());
+ int w = image.width();
+ int h = image.height();
+ memrotate(image.constBits(), w, h, image.bytesPerLine(), out.bits(), out.bytesPerLine());
+ return out;
}
-
-static QImage rotated270(const QImage &image) {
+static QImage rotated270(const QImage &image)
+{
QImage out(image.height(), image.width(), image.format());
out.setDotsPerMeterX(image.dotsPerMeterY());
out.setDotsPerMeterY(image.dotsPerMeterX());
@@ -4536,49 +4547,10 @@ static QImage rotated270(const QImage &image) {
out.setColorTable(image.colorTable());
int w = image.width();
int h = image.height();
- switch (image.format()) {
- case QImage::Format_RGB32:
- case QImage::Format_ARGB32:
- case QImage::Format_ARGB32_Premultiplied:
- case QImage::Format_RGBX8888:
- case QImage::Format_RGBA8888:
- case QImage::Format_RGBA8888_Premultiplied:
- case QImage::Format_BGR30:
- case QImage::Format_A2BGR30_Premultiplied:
- case QImage::Format_RGB30:
- case QImage::Format_A2RGB30_Premultiplied:
- qt_memrotate90(reinterpret_cast<const quint32*>(image.bits()),
- w, h, image.bytesPerLine(),
- reinterpret_cast<quint32*>(out.bits()),
- out.bytesPerLine());
- break;
- case QImage::Format_RGB666:
- case QImage::Format_ARGB6666_Premultiplied:
- case QImage::Format_ARGB8565_Premultiplied:
- case QImage::Format_ARGB8555_Premultiplied:
- case QImage::Format_RGB888:
- qt_memrotate90(reinterpret_cast<const quint24*>(image.bits()),
- w, h, image.bytesPerLine(),
- reinterpret_cast<quint24*>(out.bits()),
- out.bytesPerLine());
- break;
- case QImage::Format_RGB555:
- case QImage::Format_RGB16:
- case QImage::Format_ARGB4444_Premultiplied:
- qt_memrotate90(reinterpret_cast<const quint16*>(image.bits()),
- w, h, image.bytesPerLine(),
- reinterpret_cast<quint16*>(out.bits()),
- out.bytesPerLine());
- break;
- case QImage::Format_Alpha8:
- case QImage::Format_Grayscale8:
- case QImage::Format_Indexed8:
- qt_memrotate90(reinterpret_cast<const quint8*>(image.bits()),
- w, h, image.bytesPerLine(),
- reinterpret_cast<quint8*>(out.bits()),
- out.bytesPerLine());
- break;
- default:
+ const MemRotateFunc memrotate = qMemRotateFunctions[qPixelLayouts[image.format()].bpp][0];
+ if (memrotate) {
+ memrotate(image.constBits(), w, h, image.bytesPerLine(), out.bits(), out.bytesPerLine());
+ } else {
for (int y=0; y<h; ++y) {
if (image.colorCount())
for (int x=0; x<w; ++x)
@@ -4587,7 +4559,6 @@ static QImage rotated270(const QImage &image) {
for (int x=0; x<w; ++x)
out.setPixel(y, w-x-1, image.pixel(x, y));
}
- break;
}
return out;
}
diff --git a/src/gui/image/qimage.h b/src/gui/image/qimage.h
index fd2298561e..204e7a54b2 100644
--- a/src/gui/image/qimage.h
+++ b/src/gui/image/qimage.h
@@ -192,6 +192,7 @@ public:
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags = Qt::AutoColor) const Q_REQUIRED_RESULT;
#endif
QImage convertToFormat(Format f, const QVector<QRgb> &colorTable, Qt::ImageConversionFlags flags = Qt::AutoColor) const Q_REQUIRED_RESULT;
+ bool reinterpretAsFormat(Format f);
int width() const;
int height() const;
diff --git a/src/gui/image/qimage_conversions.cpp b/src/gui/image/qimage_conversions.cpp
index c646ee96b4..d685d50d49 100644
--- a/src/gui/image/qimage_conversions.cpp
+++ b/src/gui/image/qimage_conversions.cpp
@@ -39,6 +39,7 @@
#include <private/qdrawhelper_p.h>
#include <private/qguiapplication_p.h>
+#include <private/qcolorprofile_p.h>
#include <private/qsimd_p.h>
#include <private/qimage_p.h>
#include <qendian.h>
@@ -82,23 +83,17 @@ const uchar *qt_get_bitflip_array()
void qGamma_correct_back_to_linear_cs(QImage *image)
{
- const QDrawHelperGammaTables *tables = QGuiApplicationPrivate::instance()->gammaTables();
- if (!tables)
+ const QColorProfile *cp = QGuiApplicationPrivate::instance()->colorProfileForA32Text();
+ if (!cp)
return;
- const uchar *gamma = tables->qt_pow_rgb_gamma;
// gamma correct the pixels back to linear color space...
int h = image->height();
int w = image->width();
for (int y=0; y<h; ++y) {
- uint *pixels = (uint *) image->scanLine(y);
- for (int x=0; x<w; ++x) {
- uint p = pixels[x];
- uint r = gamma[qRed(p)];
- uint g = gamma[qGreen(p)];
- uint b = gamma[qBlue(p)];
- pixels[x] = (r << 16) | (g << 8) | b | 0xff000000;
- }
+ QRgb *pixels = reinterpret_cast<QRgb *>(image->scanLine(y));
+ for (int x=0; x<w; ++x)
+ pixels[x] = cp->toLinear(pixels[x]);
}
}
diff --git a/src/gui/image/qimagewriter.cpp b/src/gui/image/qimagewriter.cpp
index f3af2738af..ab15d8ee29 100644
--- a/src/gui/image/qimagewriter.cpp
+++ b/src/gui/image/qimagewriter.cpp
@@ -283,8 +283,13 @@ bool QImageWriterPrivate::canWriteHelper()
errorString = QImageWriter::tr("Device is not set");
return false;
}
- if (!device->isOpen())
- device->open(QIODevice::WriteOnly);
+ if (!device->isOpen()) {
+ if (!device->open(QIODevice::WriteOnly)) {
+ imageWriterError = QImageWriter::DeviceError;
+ errorString = QImageWriter::tr("Cannot open device for writing: %1").arg(device->errorString());
+ return false;
+ }
+ }
if (!device->isWritable()) {
imageWriterError = QImageWriter::DeviceError;
errorString = QImageWriter::tr("Device not writable");
@@ -705,6 +710,11 @@ bool QImageWriter::canWrite() const
if (QFile *file = qobject_cast<QFile *>(d->device)) {
const bool remove = !file->isOpen() && !file->exists();
const bool result = d->canWriteHelper();
+
+ // This looks strange (why remove if it doesn't exist?) but the issue
+ // here is that canWriteHelper will create the file in the process of
+ // checking if the write can succeed. If it subsequently fails, we
+ // should remove that empty file.
if (!result && remove)
file->remove();
return result;
diff --git a/src/gui/image/qpixmap_raster.cpp b/src/gui/image/qpixmap_raster.cpp
index 741f7713da..54a5b94840 100644
--- a/src/gui/image/qpixmap_raster.cpp
+++ b/src/gui/image/qpixmap_raster.cpp
@@ -51,7 +51,6 @@
#include <QImageReader>
#include <QGuiApplication>
#include <QScreen>
-#include <private/qimage_p.h>
#include <private/qsimd_p.h>
#include <private/qdrawhelper_p.h>
#include <qpa/qplatformscreen.h>
@@ -135,7 +134,7 @@ bool QRasterPlatformPixmap::fromData(const uchar *buffer, uint len, const char *
if (image.isNull())
return false;
- createPixmapForImage(image, flags, /* inplace = */true);
+ createPixmapForImage(std::move(image), flags);
return !isNull();
}
@@ -143,13 +142,13 @@ void QRasterPlatformPixmap::fromImage(const QImage &sourceImage,
Qt::ImageConversionFlags flags)
{
QImage image = sourceImage;
- createPixmapForImage(image, flags, /* inplace = */false);
+ createPixmapForImage(std::move(image), flags);
}
void QRasterPlatformPixmap::fromImageInPlace(QImage &sourceImage,
Qt::ImageConversionFlags flags)
{
- createPixmapForImage(sourceImage, flags, /* inplace = */true);
+ createPixmapForImage(std::move(sourceImage), flags);
}
void QRasterPlatformPixmap::fromImageReader(QImageReader *imageReader,
@@ -160,7 +159,7 @@ void QRasterPlatformPixmap::fromImageReader(QImageReader *imageReader,
if (image.isNull())
return;
- createPixmapForImage(image, flags, /* inplace = */true);
+ createPixmapForImage(std::move(image), flags);
}
// from qbackingstore.cpp
@@ -301,7 +300,7 @@ int QRasterPlatformPixmap::metric(QPaintDevice::PaintDeviceMetric metric) const
return 0;
}
-void QRasterPlatformPixmap::createPixmapForImage(QImage &sourceImage, Qt::ImageConversionFlags flags, bool inPlace)
+void QRasterPlatformPixmap::createPixmapForImage(QImage sourceImage, Qt::ImageConversionFlags flags)
{
QImage::Format format;
if (flags & Qt::NoFormatConversion)
@@ -335,16 +334,10 @@ void QRasterPlatformPixmap::createPixmapForImage(QImage &sourceImage, Qt::ImageC
if (format == QImage::Format_RGB32 && (sourceImage.format() == QImage::Format_ARGB32
|| sourceImage.format() == QImage::Format_ARGB32_Premultiplied))
{
- inPlace = inPlace && sourceImage.isDetached();
- image = sourceImage;
- if (!inPlace)
- image.detach();
- if (image.d)
- image.d->format = QImage::Format_RGB32;
- } else if (inPlace && sourceImage.d->convertInPlace(format, flags)) {
- image = sourceImage;
+ image = std::move(sourceImage);
+ image.reinterpretAsFormat(QImage::Format_RGB32);
} else {
- image = sourceImage.convertToFormat(format, flags);
+ image = std::move(sourceImage).convertToFormat(format, flags);
}
if (image.d) {
diff --git a/src/gui/image/qpixmap_raster_p.h b/src/gui/image/qpixmap_raster_p.h
index 95e018eb35..6ea965a324 100644
--- a/src/gui/image/qpixmap_raster_p.h
+++ b/src/gui/image/qpixmap_raster_p.h
@@ -85,7 +85,7 @@ public:
protected:
int metric(QPaintDevice::PaintDeviceMetric metric) const Q_DECL_OVERRIDE;
- void createPixmapForImage(QImage &sourceImage, Qt::ImageConversionFlags flags, bool inPlace);
+ void createPixmapForImage(QImage sourceImage, Qt::ImageConversionFlags flags);
void setImage(const QImage &image);
QImage image;
static QImage::Format systemOpaqueFormat();
diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp
index 219f782737..ac9edc8eb0 100644
--- a/src/gui/kernel/qevent.cpp
+++ b/src/gui/kernel/qevent.cpp
@@ -2939,6 +2939,7 @@ QDragMoveEvent::~QDragMoveEvent()
type information.
*/
+// ### pos is in which coordinate system?
/*!
Constructs a drop event of a certain \a type corresponding to a
drop at the point specified by \a pos in the destination widget's
@@ -2949,7 +2950,7 @@ QDragMoveEvent::~QDragMoveEvent()
The states of the mouse buttons and keyboard modifiers at the time of
the drop are specified by \a buttons and \a modifiers.
-*/ // ### pos is in which coordinate system?
+*/
QDropEvent::QDropEvent(const QPointF& pos, Qt::DropActions actions, const QMimeData *data,
Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Type type)
: QEvent(type), p(pos), mouseState(buttons),
@@ -3888,12 +3889,15 @@ QDebug operator<<(QDebug dbg, const QTouchEvent::TouchPoint &tp)
{
QDebugStateSaver saver(dbg);
dbg.nospace();
- dbg << "TouchPoint(" << tp.id() << " (";
- QtDebugUtils::formatQRect(dbg, tp.rect());
+ dbg << "TouchPoint(" << hex << tp.id() << dec << " (";
+ QtDebugUtils::formatQPoint(dbg, tp.pos());
dbg << ") ";
QtDebugUtils::formatQEnum(dbg, tp.state());
- dbg << " press " << tp.pressure() << " vel " << tp.velocity()
- << " start (";
+ dbg << " pressure " << tp.pressure() << " ellipse ("
+ << tp.ellipseDiameters().width() << " x " << tp.ellipseDiameters().height()
+ << " angle " << tp.rotation() << ") vel (";
+ QtDebugUtils::formatQPoint(dbg, tp.velocity().toPointF());
+ dbg << ") start (";
QtDebugUtils::formatQPoint(dbg, tp.startPos());
dbg << ") last (";
QtDebugUtils::formatQPoint(dbg, tp.lastPos());
@@ -4418,6 +4422,8 @@ QTouchEvent::~QTouchEvent()
\brief The TouchPoint class provides information about a touch point in a QTouchEvent.
\since 4.6
\inmodule QtGui
+
+ \image touchpoint-metrics.png
*/
/*! \enum TouchPoint::InfoFlag
@@ -4503,7 +4509,7 @@ Qt::TouchPointState QTouchEvent::TouchPoint::state() const
*/
QPointF QTouchEvent::TouchPoint::pos() const
{
- return d->rect.center();
+ return d->pos;
}
/*!
@@ -4518,7 +4524,7 @@ QPointF QTouchEvent::TouchPoint::pos() const
*/
QPointF QTouchEvent::TouchPoint::scenePos() const
{
- return d->sceneRect.center();
+ return d->scenePos;
}
/*!
@@ -4528,7 +4534,7 @@ QPointF QTouchEvent::TouchPoint::scenePos() const
*/
QPointF QTouchEvent::TouchPoint::screenPos() const
{
- return d->screenRect.center();
+ return d->screenPos;
}
/*!
@@ -4651,10 +4657,19 @@ QPointF QTouchEvent::TouchPoint::lastNormalizedPos() const
around the point returned by pos().
\note This function returns an empty rect if the device does not report touch point sizes.
+
+ \obsolete This function is deprecated in 5.9 because it returns the outer bounds
+ of the touchpoint regardless of rotation, whereas a touchpoint is more correctly
+ modeled as an ellipse at position pos() with ellipseDiameters()
+ which are independent of rotation().
+
+ \sa scenePos(), ellipseDiameters()
*/
QRectF QTouchEvent::TouchPoint::rect() const
{
- return d->rect;
+ QRectF ret(QPointF(), d->ellipseDiameters);
+ ret.moveCenter(d->pos);
+ return ret;
}
/*!
@@ -4662,11 +4677,18 @@ QRectF QTouchEvent::TouchPoint::rect() const
\note This function returns an empty rect if the device does not report touch point sizes.
- \sa scenePos(), rect()
+ \obsolete This function is deprecated in 5.9 because it returns the outer bounds
+ of the touchpoint regardless of rotation, whereas a touchpoint is more correctly
+ modeled as an ellipse at position scenePos() with ellipseDiameters()
+ which are independent of rotation().
+
+ \sa scenePos(), ellipseDiameters()
*/
QRectF QTouchEvent::TouchPoint::sceneRect() const
{
- return d->sceneRect;
+ QRectF ret(QPointF(), d->ellipseDiameters);
+ ret.moveCenter(d->scenePos);
+ return ret;
}
/*!
@@ -4674,11 +4696,18 @@ QRectF QTouchEvent::TouchPoint::sceneRect() const
\note This function returns an empty rect if the device does not report touch point sizes.
- \sa screenPos(), rect()
+ \obsolete This function is deprecated because it returns the outer bounds of the
+ touchpoint regardless of rotation, whereas a touchpoint is more correctly
+ modeled as an ellipse at position screenPos() with ellipseDiameters()
+ which are independent of rotation().
+
+ \sa screenPos(), ellipseDiameters()
*/
QRectF QTouchEvent::TouchPoint::screenRect() const
{
- return d->screenRect;
+ QRectF ret(QPointF(), d->ellipseDiameters);
+ ret.moveCenter(d->screenPos);
+ return ret;
}
/*!
@@ -4704,6 +4733,19 @@ qreal QTouchEvent::TouchPoint::rotation() const
}
/*!
+ \since 5.9
+ Returns the width and height of the bounding ellipse of this touch point.
+ The return value is in logical pixels. Most touchscreens do not detect the
+ shape of the contact point, so a null size is the most common value.
+ In other cases the diameters may be nonzero and equal (the ellipse is
+ approximated as a circle).
+*/
+QSizeF QTouchEvent::TouchPoint::ellipseDiameters() const
+{
+ return d->ellipseDiameters;
+}
+
+/*!
Returns a velocity vector for this touch point.
The vector is in the screen's coordinate system, using pixels per seconds for the magnitude.
@@ -4774,7 +4816,7 @@ void QTouchEvent::TouchPoint::setPos(const QPointF &pos)
{
if (d->ref.load() != 1)
d = d->detach();
- d->rect.moveCenter(pos);
+ d->pos = pos;
}
/*! \internal */
@@ -4782,7 +4824,7 @@ void QTouchEvent::TouchPoint::setScenePos(const QPointF &scenePos)
{
if (d->ref.load() != 1)
d = d->detach();
- d->sceneRect.moveCenter(scenePos);
+ d->scenePos = scenePos;
}
/*! \internal */
@@ -4790,7 +4832,7 @@ void QTouchEvent::TouchPoint::setScreenPos(const QPointF &screenPos)
{
if (d->ref.load() != 1)
d = d->detach();
- d->screenRect.moveCenter(screenPos);
+ d->screenPos = screenPos;
}
/*! \internal */
@@ -4865,28 +4907,32 @@ void QTouchEvent::TouchPoint::setLastNormalizedPos(const QPointF &lastNormalized
d->lastNormalizedPos = lastNormalizedPos;
}
-/*! \internal */
+// ### remove the following 3 setRect functions and their usages soon
+/*! \internal \obsolete */
void QTouchEvent::TouchPoint::setRect(const QRectF &rect)
{
if (d->ref.load() != 1)
d = d->detach();
- d->rect = rect;
+ d->pos = rect.center();
+ d->ellipseDiameters = rect.size();
}
-/*! \internal */
+/*! \internal \obsolete */
void QTouchEvent::TouchPoint::setSceneRect(const QRectF &sceneRect)
{
if (d->ref.load() != 1)
d = d->detach();
- d->sceneRect = sceneRect;
+ d->scenePos = sceneRect.center();
+ d->ellipseDiameters = sceneRect.size();
}
-/*! \internal */
+/*! \internal \obsolete */
void QTouchEvent::TouchPoint::setScreenRect(const QRectF &screenRect)
{
if (d->ref.load() != 1)
d = d->detach();
- d->screenRect = screenRect;
+ d->screenPos = screenRect.center();
+ d->ellipseDiameters = screenRect.size();
}
/*! \internal */
@@ -4906,6 +4952,14 @@ void QTouchEvent::TouchPoint::setRotation(qreal angle)
}
/*! \internal */
+void QTouchEvent::TouchPoint::setEllipseDiameters(const QSizeF &dia)
+{
+ if (d->ref.load() != 1)
+ d = d->detach();
+ d->ellipseDiameters = dia;
+}
+
+/*! \internal */
void QTouchEvent::TouchPoint::setVelocity(const QVector2D &v)
{
if (d->ref.load() != 1)
diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h
index 7881df205a..cfc3b842d7 100644
--- a/src/gui/kernel/qevent.h
+++ b/src/gui/kernel/qevent.h
@@ -885,6 +885,8 @@ public:
qreal pressure() const;
qreal rotation() const;
+ QSizeF ellipseDiameters() const;
+
QVector2D velocity() const;
InfoFlags flags() const;
QVector<QPointF> rawScreenPositions() const;
@@ -905,11 +907,12 @@ public:
void setLastScenePos(const QPointF &lastScenePos);
void setLastScreenPos(const QPointF &lastScreenPos);
void setLastNormalizedPos(const QPointF &lastNormalizedPos);
- void setRect(const QRectF &rect);
- void setSceneRect(const QRectF &sceneRect);
- void setScreenRect(const QRectF &screenRect);
+ void setRect(const QRectF &rect); // deprecated
+ void setSceneRect(const QRectF &sceneRect); // deprecated
+ void setScreenRect(const QRectF &screenRect); // deprecated
void setPressure(qreal pressure);
void setRotation(qreal angle);
+ void setEllipseDiameters(const QSizeF &dia);
void setVelocity(const QVector2D &v);
void setFlags(InfoFlags flags);
void setRawScreenPositions(const QVector<QPointF> &positions);
diff --git a/src/gui/kernel/qevent_p.h b/src/gui/kernel/qevent_p.h
index 898ad16cf6..1eccfaea78 100644
--- a/src/gui/kernel/qevent_p.h
+++ b/src/gui/kernel/qevent_p.h
@@ -65,8 +65,9 @@ public:
: ref(1),
id(id),
state(Qt::TouchPointReleased),
- pressure(qreal(-1.)),
- rotation(qreal(0.))
+ pressure(-1),
+ rotation(0),
+ ellipseDiameters(0, 0)
{ }
inline QTouchEventTouchPointPrivate *detach()
@@ -82,12 +83,12 @@ public:
int id;
QPointingDeviceUniqueId uniqueId;
Qt::TouchPointStates state;
- QRectF rect, sceneRect, screenRect;
- QPointF normalizedPos,
+ QPointF pos, scenePos, screenPos, normalizedPos,
startPos, startScenePos, startScreenPos, startNormalizedPos,
lastPos, lastScenePos, lastScreenPos, lastNormalizedPos;
qreal pressure;
qreal rotation;
+ QSizeF ellipseDiameters;
QVector2D velocity;
QTouchEvent::TouchPoint::InfoFlags flags;
QVector<QPointF> rawScreenPositions;
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp
index 3ba0d59102..e4eabc815e 100644
--- a/src/gui/kernel/qguiapplication.cpp
+++ b/src/gui/kernel/qguiapplication.cpp
@@ -68,8 +68,8 @@
#include <qpalette.h>
#include <qscreen.h>
#include "qsessionmanager.h"
+#include <private/qcolorprofile_p.h>
#include <private/qscreen_p.h>
-#include <private/qdrawhelper_p.h>
#include <QtGui/qgenericpluginfactory.h>
#include <QtGui/qstylehints.h>
@@ -84,6 +84,7 @@
#include "private/qcursor_p.h"
#include "private/qopenglcontext_p.h"
#include "private/qinputdevicemanager_p.h"
+#include "private/qtouchdevice_p.h"
#include "private/qdnd_p.h"
#include <qpa/qplatformthemefactory_p.h>
@@ -107,9 +108,6 @@
#elif defined(Q_OS_WIN)
# include <QtCore/qt_windows.h>
# include <QtCore/QLibraryInfo>
-# if defined(Q_OS_WINPHONE)
-# include <Objbase.h>
-# endif
#endif // Q_OS_WIN
#include <ctype.h>
@@ -821,19 +819,11 @@ bool QGuiApplicationPrivate::isWindowBlocked(QWindow *window, QWindow **blocking
for (int i = 0; i < modalWindowList.count(); ++i) {
QWindow *modalWindow = modalWindowList.at(i);
- {
- // check if the modal window is our window or a (transient) parent of our window
- QWindow *w = window;
- while (w) {
- if (w == modalWindow) {
- *blockingWindow = 0;
- return false;
- }
- QWindow *p = w->parent();
- if (!p)
- p = w->transientParent();
- w = p;
- }
+ // A window is not blocked by another modal window if the two are
+ // the same, or if the window is a child of the modal window.
+ if (window == modalWindow || modalWindow->isAncestorOf(window, QWindow::IncludeTransients)) {
+ *blockingWindow = 0;
+ return false;
}
Qt::WindowModality windowModality = modalWindow->modality();
@@ -940,15 +930,25 @@ QWindowList QGuiApplication::topLevelWindows()
{
const QWindowList &list = QGuiApplicationPrivate::window_list;
QWindowList topLevelWindows;
- for (int i = 0; i < list.size(); i++) {
- if (!list.at(i)->parent() && list.at(i)->type() != Qt::Desktop) {
- // Top windows of embedded QAxServers do not have QWindow parents,
- // but they are not true top level windows, so do not include them.
- const bool embedded = list.at(i)->handle() && list.at(i)->handle()->isEmbedded();
- if (!embedded)
- topLevelWindows.prepend(list.at(i));
- }
+ for (int i = 0; i < list.size(); ++i) {
+ QWindow *window = list.at(i);
+ if (!window->isTopLevel())
+ continue;
+
+ // Desktop windows are special, as each individual desktop window
+ // will report that it's a top level window, but we don't want to
+ // include them in the application wide list of top level windows.
+ if (window->type() == Qt::Desktop)
+ continue;
+
+ // Windows embedded in native windows do not have QWindow parents,
+ // but they are not true top level windows, so do not include them.
+ if (window->handle() && window->handle()->isEmbedded())
+ continue;
+
+ topLevelWindows.prepend(window);
}
+
return topLevelWindows;
}
@@ -1523,7 +1523,8 @@ QGuiApplicationPrivate::~QGuiApplicationPrivate()
platform_theme = 0;
delete platform_integration;
platform_integration = 0;
- delete m_gammaTables.load();
+ delete m_a8ColorProfile.load();
+ delete m_a32ColorProfile.load();
window_list.clear();
}
@@ -1958,7 +1959,8 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo
points << point;
QEvent::Type type;
- QList<QTouchEvent::TouchPoint> touchPoints = QWindowSystemInterfacePrivate::fromNativeTouchPoints(points, window, &type);
+ QList<QTouchEvent::TouchPoint> touchPoints =
+ QWindowSystemInterfacePrivate::fromNativeTouchPoints(points, window, QTouchDevicePrivate::get(m_fakeTouchDevice)->id, &type);
QWindowSystemInterfacePrivate::TouchEvent fake(window, e->timestamp, type, m_fakeTouchDevice, touchPoints, e->modifiers);
fake.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
@@ -2195,10 +2197,10 @@ void QGuiApplicationPrivate::processThemeChanged(QWindowSystemInterfacePrivate::
void QGuiApplicationPrivate::processGeometryChangeEvent(QWindowSystemInterfacePrivate::GeometryChangeEvent *e)
{
- if (e->tlw.isNull())
+ if (e->window.isNull())
return;
- QWindow *window = e->tlw.data();
+ QWindow *window = e->window.data();
if (!window)
return;
@@ -2563,7 +2565,10 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To
Q_ASSERT(w.data() != 0);
// make the *scene* functions return the same as the *screen* functions
- touchPoint.d->sceneRect = touchPoint.screenRect();
+ // Note: touchPoint is a reference to the one from activeTouchPoints,
+ // so we can modify it as long as we're careful NOT to call setters and
+ // otherwise NOT to cause the d-pointer to be detached.
+ touchPoint.d->scenePos = touchPoint.screenPos();
touchPoint.d->startScenePos = touchPoint.startScreenPos();
touchPoint.d->lastScenePos = touchPoint.lastScreenPos();
@@ -2618,8 +2623,8 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To
QTouchEvent touchEvent(eventType,
e->device,
e->modifiers,
- it.value().first,
- it.value().second);
+ it.value().first, // state flags
+ it.value().second); // list of touchpoints
touchEvent.setTimestamp(e->timestamp);
touchEvent.setWindow(w);
@@ -2628,13 +2633,14 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To
QTouchEvent::TouchPoint &touchPoint = touchEvent._touchPoints[i];
// preserve the sub-pixel resolution
- QRectF rect = touchPoint.screenRect();
- const QPointF screenPos = rect.center();
+ const QPointF screenPos = touchPoint.screenPos();
const QPointF delta = screenPos - screenPos.toPoint();
- rect.moveCenter(w->mapFromGlobal(screenPos.toPoint()) + delta);
- touchPoint.d->rect = rect;
+ touchPoint.d->pos = w->mapFromGlobal(screenPos.toPoint()) + delta;
if (touchPoint.state() == Qt::TouchPointPressed) {
+ // touchPoint is actually a reference to one that is stored in activeTouchPoints,
+ // and we are now going to store the startPos and lastPos there, for the benefit
+ // of future moves and releases. It's important that the d-pointer is NOT detached.
touchPoint.d->startPos = w->mapFromGlobal(touchPoint.startScreenPos().toPoint()) + delta;
touchPoint.d->lastPos = w->mapFromGlobal(touchPoint.lastScreenPos().toPoint()) + delta;
}
@@ -3674,14 +3680,30 @@ void QGuiApplicationPrivate::notifyDragStarted(const QDrag *drag)
}
#endif
-const QDrawHelperGammaTables *QGuiApplicationPrivate::gammaTables()
+const QColorProfile *QGuiApplicationPrivate::colorProfileForA8Text()
+{
+#ifdef Q_OS_WIN
+ QColorProfile *result = m_a8ColorProfile.load();
+ if (!result){
+ QColorProfile *cs = QColorProfile::fromGamma(2.31); // This is a hard-coded thing for Windows text rendering
+ if (!m_a8ColorProfile.testAndSetRelease(0, cs))
+ delete cs;
+ result = m_a8ColorProfile.load();
+ }
+ return result;
+#else
+ return colorProfileForA32Text();
+#endif
+}
+
+const QColorProfile *QGuiApplicationPrivate::colorProfileForA32Text()
{
- QDrawHelperGammaTables *result = m_gammaTables.load();
+ QColorProfile *result = m_a32ColorProfile.load();
if (!result){
- QDrawHelperGammaTables *tables = new QDrawHelperGammaTables(fontSmoothingGamma);
- if (!m_gammaTables.testAndSetRelease(0, tables))
- delete tables;
- result = m_gammaTables.load();
+ QColorProfile *cs = QColorProfile::fromGamma(fontSmoothingGamma);
+ if (!m_a32ColorProfile.testAndSetRelease(0, cs))
+ delete cs;
+ result = m_a32ColorProfile.load();
}
return result;
}
diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h
index 0d62490c75..3804667ef3 100644
--- a/src/gui/kernel/qguiapplication_p.h
+++ b/src/gui/kernel/qguiapplication_p.h
@@ -66,10 +66,10 @@
QT_BEGIN_NAMESPACE
+class QColorProfile;
class QPlatformIntegration;
class QPlatformTheme;
class QPlatformDragQtResponse;
-struct QDrawHelperGammaTables;
#ifndef QT_NO_DRAGANDDROP
class QDrag;
#endif // QT_NO_DRAGANDDROP
@@ -293,7 +293,8 @@ public:
static QInputDeviceManager *inputDeviceManager();
- const QDrawHelperGammaTables *gammaTables();
+ const QColorProfile *colorProfileForA8Text();
+ const QColorProfile *colorProfileForA32Text();
// hook reimplemented in QApplication to apply the QStyle function on the QIcon
virtual QPixmap applyQIconStyleHelper(QIcon::Mode, const QPixmap &basePixmap) const { return basePixmap; }
@@ -317,7 +318,8 @@ private:
static QGuiApplicationPrivate *self;
static QTouchDevice *m_fakeTouchDevice;
static int m_fakeMouseSourcePointId;
- QAtomicPointer<QDrawHelperGammaTables> m_gammaTables;
+ QAtomicPointer<QColorProfile> m_a8ColorProfile;
+ QAtomicPointer<QColorProfile> m_a32ColorProfile;
bool ownGlobalShareContext;
diff --git a/src/gui/kernel/qoffscreensurface.cpp b/src/gui/kernel/qoffscreensurface.cpp
index a9535a6ad7..307bc5e62f 100644
--- a/src/gui/kernel/qoffscreensurface.cpp
+++ b/src/gui/kernel/qoffscreensurface.cpp
@@ -102,6 +102,7 @@ public:
, requestedFormat(QSurfaceFormat::defaultFormat())
, screen(0)
, size(1, 1)
+ , nativeHandle(nullptr)
{
}
@@ -115,6 +116,7 @@ public:
QSurfaceFormat requestedFormat;
QScreen *screen;
QSize size;
+ void *nativeHandle;
};
@@ -217,6 +219,8 @@ void QOffscreenSurface::destroy()
delete d->offscreenWindow;
d->offscreenWindow = 0;
}
+
+ d->nativeHandle = nullptr;
}
/*!
@@ -331,6 +335,26 @@ void QOffscreenSurface::setScreen(QScreen *newScreen)
}
/*!
+ Sets the native handle to which the offscreen surface is connected to \a handle.
+
+ The native handle will be resolved in the create() function. Calling
+ this function after create() will not re-create a native surface.
+
+ \note The interpretation of the native handle is platform specific. Only
+ some platforms will support adopting native handles of offscreen surfaces
+ and platforms that do not implement this support will ignore the handle.
+
+ \since 5.9
+ \sa nativeHandle()
+*/
+
+void QOffscreenSurface::setNativeHandle(void *handle)
+{
+ Q_D(QOffscreenSurface);
+ d->nativeHandle = handle;
+}
+
+/*!
Called when the offscreen surface's screen is destroyed.
\internal
@@ -362,6 +386,19 @@ QPlatformOffscreenSurface *QOffscreenSurface::handle() const
}
/*!
+ Returns an optional native handle to which the offscreen surface is connected.
+
+ \since 5.9
+ \sa setNativeHandle()
+*/
+
+void *QOffscreenSurface::nativeHandle() const
+{
+ Q_D(const QOffscreenSurface);
+ return d->nativeHandle;
+}
+
+/*!
Returns the platform surface corresponding to the offscreen surface.
\internal
diff --git a/src/gui/kernel/qoffscreensurface.h b/src/gui/kernel/qoffscreensurface.h
index bacc9c851a..35c498c89a 100644
--- a/src/gui/kernel/qoffscreensurface.h
+++ b/src/gui/kernel/qoffscreensurface.h
@@ -79,6 +79,9 @@ public:
QPlatformOffscreenSurface *handle() const;
+ void *nativeHandle() const;
+ void setNativeHandle(void *handle);
+
Q_SIGNALS:
void screenChanged(QScreen *screen);
diff --git a/src/gui/kernel/qplatformdialoghelper.cpp b/src/gui/kernel/qplatformdialoghelper.cpp
index 5890eb4fb6..01cf98c7c9 100644
--- a/src/gui/kernel/qplatformdialoghelper.cpp
+++ b/src/gui/kernel/qplatformdialoghelper.cpp
@@ -451,6 +451,7 @@ public:
QString defaultSuffix;
QStringList history;
QUrl initialDirectory;
+ QString initiallySelectedMimeTypeFilter;
QString initiallySelectedNameFilter;
QList<QUrl> initiallySelectedFiles;
QStringList supportedSchemes;
@@ -668,6 +669,16 @@ void QFileDialogOptions::setInitialDirectory(const QUrl &directory)
d->initialDirectory = directory;
}
+QString QFileDialogOptions::initiallySelectedMimeTypeFilter() const
+{
+ return d->initiallySelectedMimeTypeFilter;
+}
+
+void QFileDialogOptions::setInitiallySelectedMimeTypeFilter(const QString &filter)
+{
+ d->initiallySelectedMimeTypeFilter = filter;
+}
+
QString QFileDialogOptions::initiallySelectedNameFilter() const
{
return d->initiallySelectedNameFilter;
@@ -699,6 +710,16 @@ QStringList QFileDialogOptions::supportedSchemes() const
return d->supportedSchemes;
}
+void QPlatformFileDialogHelper::selectMimeTypeFilter(const QString &filter)
+{
+ Q_UNUSED(filter)
+}
+
+QString QPlatformFileDialogHelper::selectedMimeTypeFilter() const
+{
+ return QString();
+}
+
// Return true if the URL is supported by the filedialog implementation *and* by the application.
bool QPlatformFileDialogHelper::isSupportedUrl(const QUrl &url) const
{
diff --git a/src/gui/kernel/qplatformdialoghelper.h b/src/gui/kernel/qplatformdialoghelper.h
index 6caef070e2..ed88c19c84 100644
--- a/src/gui/kernel/qplatformdialoghelper.h
+++ b/src/gui/kernel/qplatformdialoghelper.h
@@ -372,6 +372,9 @@ public:
QUrl initialDirectory() const;
void setInitialDirectory(const QUrl &);
+ QString initiallySelectedMimeTypeFilter() const;
+ void setInitiallySelectedMimeTypeFilter(const QString &);
+
QString initiallySelectedNameFilter() const;
void setInitiallySelectedNameFilter(const QString &);
@@ -397,7 +400,9 @@ public:
virtual void selectFile(const QUrl &filename) = 0;
virtual QList<QUrl> selectedFiles() const = 0;
virtual void setFilter() = 0;
+ virtual void selectMimeTypeFilter(const QString &filter);
virtual void selectNameFilter(const QString &filter) = 0;
+ virtual QString selectedMimeTypeFilter() const;
virtual QString selectedNameFilter() const = 0;
virtual bool isSupportedUrl(const QUrl &url) const;
diff --git a/src/gui/kernel/qplatformintegration.cpp b/src/gui/kernel/qplatformintegration.cpp
index 5bf0df67db..fe1861e08b 100644
--- a/src/gui/kernel/qplatformintegration.cpp
+++ b/src/gui/kernel/qplatformintegration.cpp
@@ -354,11 +354,16 @@ QPlatformInputContext *QPlatformIntegration::inputContext() const
/*!
Returns the platforms accessibility.
- The default implementation returns 0, implying no accessibility support.
+ The default implementation returns QPlatformAccessibility which
+ delegates handling of accessibility to accessiblebridge plugins.
*/
QPlatformAccessibility *QPlatformIntegration::accessibility() const
{
- return 0;
+ static QPlatformAccessibility *accessibility = 0;
+ if (Q_UNLIKELY(!accessibility)) {
+ accessibility = new QPlatformAccessibility;
+ }
+ return accessibility;
}
#endif
@@ -404,6 +409,8 @@ QVariant QPlatformIntegration::styleHint(StyleHint hint) const
return QPlatformTheme::defaultThemeHint(QPlatformTheme::ItemViewActivateItemOnSingleClick);
case UiEffects:
return QPlatformTheme::defaultThemeHint(QPlatformTheme::UiEffects);
+ case WheelScrollLines:
+ return QPlatformTheme::defaultThemeHint(QPlatformTheme::WheelScrollLines);
}
return 0;
diff --git a/src/gui/kernel/qplatformintegration.h b/src/gui/kernel/qplatformintegration.h
index 22a834f0e1..466b3348bd 100644
--- a/src/gui/kernel/qplatformintegration.h
+++ b/src/gui/kernel/qplatformintegration.h
@@ -157,7 +157,8 @@ public:
TabFocusBehavior,
ReplayMousePressOutsidePopup,
ItemViewActivateItemOnSingleClick,
- UiEffects
+ UiEffects,
+ WheelScrollLines,
};
virtual QVariant styleHint(StyleHint hint) const;
diff --git a/src/gui/kernel/qplatformmenu.cpp b/src/gui/kernel/qplatformmenu.cpp
index 2912416309..1eb146dd0f 100644
--- a/src/gui/kernel/qplatformmenu.cpp
+++ b/src/gui/kernel/qplatformmenu.cpp
@@ -55,4 +55,9 @@ QPlatformMenu *QPlatformMenu::createSubMenu() const
return QGuiApplicationPrivate::platformTheme()->createPlatformMenu();
}
+QPlatformMenu *QPlatformMenuBar::createMenu() const
+{
+ return QGuiApplicationPrivate::platformTheme()->createPlatformMenu();
+}
+
QT_END_NAMESPACE
diff --git a/src/gui/kernel/qplatformmenu.h b/src/gui/kernel/qplatformmenu.h
index f08f0ef494..f8561445b1 100644
--- a/src/gui/kernel/qplatformmenu.h
+++ b/src/gui/kernel/qplatformmenu.h
@@ -150,7 +150,7 @@ public:
virtual void handleReparent(QWindow *newParentWindow) = 0;
virtual QPlatformMenu *menuForTag(quintptr tag) const = 0;
- virtual QPlatformMenu *createMenu() const { return nullptr; }
+ virtual QPlatformMenu *createMenu() const;
};
QT_END_NAMESPACE
diff --git a/src/gui/kernel/qplatformscreen.cpp b/src/gui/kernel/qplatformscreen.cpp
index 1d519e84f9..e22037c1e9 100644
--- a/src/gui/kernel/qplatformscreen.cpp
+++ b/src/gui/kernel/qplatformscreen.cpp
@@ -280,6 +280,45 @@ QPlatformScreen * QPlatformScreen::platformScreenForWindow(const QWindow *window
}
/*!
+ Reimplement this function in subclass to return the manufacturer
+ of this screen.
+
+ The default implementation returns an empty string.
+
+ \since 5.9
+*/
+QString QPlatformScreen::manufacturer() const
+{
+ return QString();
+}
+
+/*!
+ Reimplement this function in subclass to return the model
+ of this screen.
+
+ The default implementation returns an empty string.
+
+ \since 5.9
+*/
+QString QPlatformScreen::model() const
+{
+ return QString();
+}
+
+/*!
+ Reimplement this function in subclass to return the serial number
+ of this screen.
+
+ The default implementation returns an empty string.
+
+ \since 5.9
+*/
+QString QPlatformScreen::serialNumber() const
+{
+ return QString();
+}
+
+/*!
\class QPlatformScreen
\since 4.8
\internal
@@ -494,4 +533,53 @@ void QPlatformScreen::setPowerState(PowerState state)
Q_UNUSED(state);
}
+/*!
+ Reimplement this function in subclass to return the list
+ of modes for this screen.
+
+ The default implementation returns a list with
+ only one mode from the current screen size and refresh rate.
+
+ \sa QPlatformScreen::geometry
+ \sa QPlatformScreen::refreshRate
+
+ \since 5.9
+*/
+QVector<QPlatformScreen::Mode> QPlatformScreen::modes() const
+{
+ QVector<QPlatformScreen::Mode> list;
+ list.append({geometry().size(), refreshRate()});
+ return list;
+}
+
+/*!
+ Reimplement this function in subclass to return the
+ index of the current mode from the modes list.
+
+ The default implementation returns 0.
+
+ \sa QPlatformScreen::modes
+
+ \since 5.9
+*/
+int QPlatformScreen::currentMode() const
+{
+ return 0;
+}
+
+/*!
+ Reimplement this function in subclass to return the preferred
+ mode index from the modes list.
+
+ The default implementation returns 0.
+
+ \sa QPlatformScreen::modes
+
+ \since 5.9
+*/
+int QPlatformScreen::preferredMode() const
+{
+ return 0;
+}
+
QT_END_NAMESPACE
diff --git a/src/gui/kernel/qplatformscreen.h b/src/gui/kernel/qplatformscreen.h
index 030edea880..97fe3fed03 100644
--- a/src/gui/kernel/qplatformscreen.h
+++ b/src/gui/kernel/qplatformscreen.h
@@ -66,7 +66,6 @@ QT_BEGIN_NAMESPACE
class QPlatformBackingStore;
-class QPlatformOpenGLContext;
class QPlatformScreenPrivate;
class QPlatformWindow;
class QPlatformCursor;
@@ -96,6 +95,11 @@ public:
PowerStateOff
};
+ struct Mode {
+ QSize size;
+ qreal refreshRate;
+ };
+
QPlatformScreen();
virtual ~QPlatformScreen();
@@ -130,12 +134,21 @@ public:
virtual QString name() const { return QString(); }
+ virtual QString manufacturer() const;
+ virtual QString model() const;
+ virtual QString serialNumber() const;
+
virtual QPlatformCursor *cursor() const;
virtual SubpixelAntialiasingType subpixelAntialiasingTypeHint() const;
virtual PowerState powerState() const;
virtual void setPowerState(PowerState state);
+ virtual QVector<Mode> modes() const;
+
+ virtual int currentMode() const;
+ virtual int preferredMode() const;
+
static int angleBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b);
static QTransform transformBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b, const QRect &target);
static QRect mapBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b, const QRect &rect);
diff --git a/src/gui/kernel/qplatformtheme.cpp b/src/gui/kernel/qplatformtheme.cpp
index fc1b607563..878f656f2e 100644
--- a/src/gui/kernel/qplatformtheme.cpp
+++ b/src/gui/kernel/qplatformtheme.cpp
@@ -156,6 +156,11 @@ QT_BEGIN_NAMESPACE
\value ContextMenuOnMouseRelease (bool) Whether the context menu should be shown on mouse release.
+ \value TouchDoubleTapDistance (int) The maximum distance in logical pixels which a touchpoint can travel
+ between taps in order for the tap sequence to be handled as a double tap.
+ The default value is double the MouseDoubleClickDistance, or 10 logical pixels
+ if that is not specified.
+
\sa themeHint(), QStyle::pixelMetric()
*/
@@ -540,6 +545,14 @@ QVariant QPlatformTheme::defaultThemeHint(ThemeHint hint)
}
case WheelScrollLines:
return QVariant(3);
+ case TouchDoubleTapDistance:
+ {
+ bool ok = false;
+ int dist = qEnvironmentVariableIntValue("QT_DBL_TAP_DIST", &ok);
+ if (!ok)
+ dist = defaultThemeHint(MouseDoubleClickDistance).toInt(&ok) * 2;
+ return QVariant(ok ? dist : 10);
+ }
}
return QVariant();
}
@@ -665,6 +678,19 @@ QString QPlatformTheme::standardButtonText(int button) const
return QPlatformTheme::defaultStandardButtonText(button);
}
+/*!
+ Returns the mnemonic that should be used for a standard \a button.
+
+ \since 5.9
+ \sa QPlatformDialogHelper::StandardButton
+ */
+
+QKeySequence QPlatformTheme::standardButtonShortcut(int button) const
+{
+ Q_UNUSED(button)
+ return QKeySequence();
+}
+
QString QPlatformTheme::defaultStandardButtonText(int button)
{
switch (button) {
diff --git a/src/gui/kernel/qplatformtheme.h b/src/gui/kernel/qplatformtheme.h
index 686dbed4b1..2ba2f8669f 100644
--- a/src/gui/kernel/qplatformtheme.h
+++ b/src/gui/kernel/qplatformtheme.h
@@ -114,7 +114,8 @@ public:
ContextMenuOnMouseRelease,
MousePressAndHoldInterval,
MouseDoubleClickDistance,
- WheelScrollLines
+ WheelScrollLines,
+ TouchDoubleTapDistance
};
enum DialogType {
@@ -311,6 +312,7 @@ public:
#endif
virtual QString standardButtonText(int button) const;
+ virtual QKeySequence standardButtonShortcut(int button) const;
static QVariant defaultThemeHint(ThemeHint hint);
static QString defaultStandardButtonText(int button);
diff --git a/src/gui/kernel/qplatformwindow.cpp b/src/gui/kernel/qplatformwindow.cpp
index 11432a4272..6fd2afb1aa 100644
--- a/src/gui/kernel/qplatformwindow.cpp
+++ b/src/gui/kernel/qplatformwindow.cpp
@@ -192,15 +192,30 @@ bool QPlatformWindow::isActive() const
}
/*!
- Returns \c true if the window is a descendant of an embedded non-Qt window.
- Example of an embedded non-Qt window is the parent window of an in-process QAxServer.
+ Returns \c true if the window is an ancestor of the given \a child.
- If \a parentWindow is nonzero, only check if the window is embedded in the
- specified \a parentWindow.
+ Platform overrides should iterate the native window hierarchy of the child,
+ to ensure that ancestary is reflected even with native windows in the window
+ hierarchy.
*/
-bool QPlatformWindow::isEmbedded(const QPlatformWindow *parentWindow) const
+bool QPlatformWindow::isAncestorOf(const QPlatformWindow *child) const
+{
+ for (const QPlatformWindow *parent = child->parent(); parent; parent = child->parent()) {
+ if (parent == this)
+ return true;
+ }
+
+ return false;
+}
+
+/*!
+ Returns \c true if the window is a child of a non-Qt window.
+
+ A embedded window has no parent platform window as reflected
+ though parent(), but will have a native parent window.
+*/
+bool QPlatformWindow::isEmbedded() const
{
- Q_UNUSED(parentWindow);
return false;
}
@@ -262,13 +277,13 @@ WId QPlatformWindow::winId() const
return WId(1);
}
+//jl: It would be useful to have a property on the platform window which indicated if the sub-class
+// supported the setParent. If not, then geometry would be in screen coordinates.
/*!
This function is called to enable native child window in QPA. It is common not to support this
feature in Window systems, but can be faked. When this function is called all geometry of this
platform window will be relative to the parent.
*/
-//jl: It would be useful to have a property on the platform window which indicated if the sub-class
-// supported the setParent. If not, then geometry would be in screen coordinates.
void QPlatformWindow::setParent(const QPlatformWindow *parent)
{
Q_UNUSED(parent);
diff --git a/src/gui/kernel/qplatformwindow.h b/src/gui/kernel/qplatformwindow.h
index dcee4d2d84..d7fdbb156e 100644
--- a/src/gui/kernel/qplatformwindow.h
+++ b/src/gui/kernel/qplatformwindow.h
@@ -102,7 +102,8 @@ public:
virtual bool isExposed() const;
virtual bool isActive() const;
- virtual bool isEmbedded(const QPlatformWindow *parentWindow = 0) const;
+ virtual bool isAncestorOf(const QPlatformWindow *child) const;
+ virtual bool isEmbedded() const;
virtual QPoint mapToGlobal(const QPoint &pos) const;
virtual QPoint mapFromGlobal(const QPoint &pos) const;
diff --git a/src/gui/kernel/qscreen.cpp b/src/gui/kernel/qscreen.cpp
index 1dd8fb5e67..96f75f37eb 100644
--- a/src/gui/kernel/qscreen.cpp
+++ b/src/gui/kernel/qscreen.cpp
@@ -161,6 +161,42 @@ QString QScreen::name() const
}
/*!
+ \property QScreen::manufacturer
+ \brief the manufacturer of the screen
+
+ \since 5.9
+*/
+QString QScreen::manufacturer() const
+{
+ Q_D(const QScreen);
+ return d->platformScreen->manufacturer();
+}
+
+/*!
+ \property QScreen::model
+ \brief the model of the screen
+
+ \since 5.9
+*/
+QString QScreen::model() const
+{
+ Q_D(const QScreen);
+ return d->platformScreen->model();
+}
+
+/*!
+ \property QScreen::serialNumber
+ \brief the serial number of the screen
+
+ \since 5.9
+*/
+QString QScreen::serialNumber() const
+{
+ Q_D(const QScreen);
+ return d->platformScreen->serialNumber();
+}
+
+/*!
\property QScreen::depth
\brief the color depth of the screen
*/
diff --git a/src/gui/kernel/qscreen.h b/src/gui/kernel/qscreen.h
index 98e35aff43..8c9b16e08e 100644
--- a/src/gui/kernel/qscreen.h
+++ b/src/gui/kernel/qscreen.h
@@ -69,6 +69,9 @@ class Q_GUI_EXPORT QScreen : public QObject
Q_DECLARE_PRIVATE(QScreen)
Q_PROPERTY(QString name READ name CONSTANT)
+ Q_PROPERTY(QString manufacturer READ manufacturer CONSTANT)
+ Q_PROPERTY(QString model READ model CONSTANT)
+ Q_PROPERTY(QString serialNumber READ serialNumber CONSTANT)
Q_PROPERTY(int depth READ depth CONSTANT)
Q_PROPERTY(QSize size READ size NOTIFY geometryChanged)
Q_PROPERTY(QSize availableSize READ availableSize NOTIFY availableGeometryChanged)
@@ -97,6 +100,10 @@ public:
QString name() const;
+ QString manufacturer() const;
+ QString model() const;
+ QString serialNumber() const;
+
int depth() const;
QSize size() const;
diff --git a/src/gui/kernel/qstylehints.cpp b/src/gui/kernel/qstylehints.cpp
index 7ccf1d86b0..85c0768e35 100644
--- a/src/gui/kernel/qstylehints.cpp
+++ b/src/gui/kernel/qstylehints.cpp
@@ -78,6 +78,7 @@ public:
, m_cursorFlashTime(-1)
, m_tabFocusBehavior(-1)
, m_uiEffects(-1)
+ , m_wheelScrollLines(-1)
{}
int m_mouseDoubleClickInterval;
@@ -88,6 +89,7 @@ public:
int m_cursorFlashTime;
int m_tabFocusBehavior;
int m_uiEffects;
+ int m_wheelScrollLines;
};
/*!
@@ -329,7 +331,9 @@ int QStyleHints::cursorFlashTime() const
/*!
\property QStyleHints::showIsFullScreen
- \brief \c true if the platform defaults to windows being fullscreen,
+ \brief whether the platform defaults to fullscreen windows.
+
+ This property is \c true if the platform defaults to windows being fullscreen,
otherwise \c false.
\note The platform may still choose to show certain windows non-fullscreen,
@@ -344,7 +348,9 @@ bool QStyleHints::showIsFullScreen() const
/*!
\property QStyleHints::showIsMaximized
- \brief \c true if the platform defaults to windows being maximized,
+ \brief whether the platform defaults to maximized windows.
+
+ This property is \c true if the platform defaults to windows being maximized,
otherwise \c false.
\note The platform may still choose to show certain windows non-maximized,
@@ -389,7 +395,9 @@ qreal QStyleHints::fontSmoothingGamma() const
/*!
\property QStyleHints::useRtlExtensions
- \brief \c true if right-to-left writing direction is enabled,
+ \brief the writing direction.
+
+ This property is \c true if right-to-left writing direction is enabled,
otherwise \c false.
*/
bool QStyleHints::useRtlExtensions() const
@@ -399,7 +407,9 @@ bool QStyleHints::useRtlExtensions() const
/*!
\property QStyleHints::setFocusOnTouchRelease
- \brief \c true if focus objects (line edits etc) should receive
+ \brief the event that should set input focus on focus objects.
+
+ This property is \c true if focus objects (line edits etc) should receive
input focus after a touch/mouse release. This is normal behavior on
touch platforms. On desktop platforms, the standard is to set
focus already on touch/mouse press.
@@ -443,7 +453,9 @@ void QStyleHints::setTabFocusBehavior(Qt::TabFocusBehavior tabFocusBehavior)
/*!
\property QStyleHints::singleClickActivation
- \brief \c true if items should be activated by single click, \b false
+ \brief whether items are activated by single or double click.
+
+ This property is \c true if items should be activated by single click, \c false
if they should be activated by double click instead.
\since 5.5
@@ -455,7 +467,9 @@ bool QStyleHints::singleClickActivation() const
/*!
\property QStyleHints::useHoverEffects
- \brief \c true if UI elements should use hover effects. This is the
+ \brief whether UI elements use hover effects.
+
+ This property is \c true if UI elements should use hover effects. This is the
standard behavior on desktop platforms with a mouse pointer, whereas
on touch platforms the overhead of hover event delivery can be avoided.
@@ -483,4 +497,33 @@ void QStyleHints::setUseHoverEffects(bool useHoverEffects)
emit useHoverEffectsChanged(useHoverEffects);
}
+/*!
+ \property QStyleHints::wheelScrollLines
+ \brief Number of lines to scroll by default for each wheel click.
+
+ \since 5.9
+*/
+int QStyleHints::wheelScrollLines() const
+{
+ Q_D(const QStyleHints);
+ if (d->m_wheelScrollLines > 0)
+ return d->m_wheelScrollLines;
+ return themeableHint(QPlatformTheme::WheelScrollLines, QPlatformIntegration::WheelScrollLines).toInt();
+}
+
+/*!
+ Sets the \a wheelScrollLines.
+ \internal
+ \sa wheelScrollLines()
+ \since 5.9
+*/
+void QStyleHints::setWheelScrollLines(int scrollLines)
+{
+ Q_D(QStyleHints);
+ if (d->m_wheelScrollLines == scrollLines)
+ return;
+ d->m_wheelScrollLines = scrollLines;
+ emit wheelScrollLinesChanged(scrollLines);
+}
+
QT_END_NAMESPACE
diff --git a/src/gui/kernel/qstylehints.h b/src/gui/kernel/qstylehints.h
index fb55cc7ed6..b9bf428edd 100644
--- a/src/gui/kernel/qstylehints.h
+++ b/src/gui/kernel/qstylehints.h
@@ -71,6 +71,7 @@ class Q_GUI_EXPORT QStyleHints : public QObject
Q_PROPERTY(Qt::TabFocusBehavior tabFocusBehavior READ tabFocusBehavior NOTIFY tabFocusBehaviorChanged FINAL)
Q_PROPERTY(bool singleClickActivation READ singleClickActivation STORED false CONSTANT FINAL)
Q_PROPERTY(bool useHoverEffects READ useHoverEffects WRITE setUseHoverEffects NOTIFY useHoverEffectsChanged FINAL)
+ Q_PROPERTY(int wheelScrollLines READ wheelScrollLines NOTIFY wheelScrollLinesChanged FINAL)
public:
void setMouseDoubleClickInterval(int mouseDoubleClickInterval);
@@ -99,6 +100,8 @@ public:
bool singleClickActivation() const;
bool useHoverEffects() const;
void setUseHoverEffects(bool useHoverEffects);
+ int wheelScrollLines() const;
+ void setWheelScrollLines(int scrollLines);
Q_SIGNALS:
void cursorFlashTimeChanged(int cursorFlashTime);
@@ -109,6 +112,7 @@ Q_SIGNALS:
void startDragTimeChanged(int startDragTime);
void tabFocusBehaviorChanged(Qt::TabFocusBehavior tabFocusBehavior);
void useHoverEffectsChanged(bool useHoverEffects);
+ void wheelScrollLinesChanged(int scrollLines);
private:
friend class QGuiApplication;
diff --git a/src/gui/kernel/qsurface.cpp b/src/gui/kernel/qsurface.cpp
index afe4cf93e1..3cdd11de8c 100644
--- a/src/gui/kernel/qsurface.cpp
+++ b/src/gui/kernel/qsurface.cpp
@@ -76,6 +76,8 @@ QT_BEGIN_NAMESPACE
\value RasterGLSurface The surface can be rendered to using a software rasterizer,
and also supports OpenGL. This surface type is intended for internal Qt use, and
requires the use of private API.
+ \value OpenVGSurface The surface is an OpenVG compatible surface and can be used
+ in conjunction with OpenVG contexts.
*/
diff --git a/src/gui/kernel/qsurface.h b/src/gui/kernel/qsurface.h
index d9ccdc096d..a96b7a6422 100644
--- a/src/gui/kernel/qsurface.h
+++ b/src/gui/kernel/qsurface.h
@@ -64,7 +64,8 @@ public:
enum SurfaceType {
RasterSurface,
OpenGLSurface,
- RasterGLSurface
+ RasterGLSurface,
+ OpenVGSurface,
};
virtual ~QSurface();
diff --git a/src/gui/kernel/qtouchdevice.h b/src/gui/kernel/qtouchdevice.h
index 0fb24e47bf..c98aa69236 100644
--- a/src/gui/kernel/qtouchdevice.h
+++ b/src/gui/kernel/qtouchdevice.h
@@ -87,6 +87,7 @@ public:
private:
QTouchDevicePrivate *d;
+ friend class QTouchDevicePrivate;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(QTouchDevice::Capabilities)
diff --git a/src/gui/kernel/qtouchdevice_p.h b/src/gui/kernel/qtouchdevice_p.h
index 203d9fca74..18d2af46a7 100644
--- a/src/gui/kernel/qtouchdevice_p.h
+++ b/src/gui/kernel/qtouchdevice_p.h
@@ -64,16 +64,21 @@ public:
: type(QTouchDevice::TouchScreen),
caps(QTouchDevice::Position),
maxTouchPoints(1)
- { }
+ {
+ static quint8 nextId = 2; // device 0 is not used, device 1 is for mouse device
+ id = nextId++;
+ }
QTouchDevice::DeviceType type;
QTouchDevice::Capabilities caps;
QString name;
int maxTouchPoints;
+ quint8 id;
static void registerDevice(const QTouchDevice *dev);
static void unregisterDevice(const QTouchDevice *dev);
static bool isRegistered(const QTouchDevice *dev);
+ static QTouchDevicePrivate *get(QTouchDevice *q) { return q->d; }
};
QT_END_NAMESPACE
diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp
index 94a34b5c27..5a27b19101 100644
--- a/src/gui/kernel/qwindow.cpp
+++ b/src/gui/kernel/qwindow.cpp
@@ -343,6 +343,30 @@ void QWindowPrivate::updateVisibility()
emit q->visibilityChanged(visibility);
}
+void QWindowPrivate::updateSiblingPosition(SiblingPosition position)
+{
+ Q_Q(QWindow);
+
+ if (!q->parent())
+ return;
+
+ QObjectList &siblings = q->parent()->d_ptr->children;
+
+ const int siblingCount = siblings.size() - 1;
+ if (siblingCount == 0)
+ return;
+
+ const int currentPosition = siblings.indexOf(q);
+ Q_ASSERT(currentPosition >= 0);
+
+ const int targetPosition = position == PositionTop ? siblingCount : 0;
+
+ if (currentPosition == targetPosition)
+ return;
+
+ siblings.move(currentPosition, targetPosition);
+}
+
inline bool QWindowPrivate::windowRecreationRequired(QScreen *newScreen) const
{
Q_Q(const QWindow);
@@ -605,6 +629,22 @@ WId QWindow::winId() const
return d->platformWindow->winId();
}
+ /*!
+ Returns the parent window, if any.
+
+ If \a mode is IncludeTransients, then the transient parent is returned
+ if there is no parent.
+
+ A window without a parent is known as a top level window.
+
+ \since 5.9
+*/
+QWindow *QWindow::parent(AncestorMode mode) const
+{
+ Q_D(const QWindow);
+ return d->parentWindow ? d->parentWindow : (mode == IncludeTransients ? transientParent() : nullptr);
+}
+
/*!
Returns the parent window, if any.
@@ -797,10 +837,15 @@ QSurfaceFormat QWindow::format() const
The actual window flags might differ from the flags set with setFlags()
if the requested flags could not be fulfilled.
+
+ \sa setFlag()
*/
void QWindow::setFlags(Qt::WindowFlags flags)
{
Q_D(QWindow);
+ if (d->windowFlags == flags)
+ return;
+
if (d->platformWindow)
d->platformWindow->setWindowFlags(flags);
d->windowFlags = flags;
@@ -813,6 +858,23 @@ Qt::WindowFlags QWindow::flags() const
}
/*!
+ \since 5.9
+
+ Sets the window flag \a flag on this window if \a on is true;
+ otherwise clears the flag.
+
+ \sa setFlags(), flags(), type()
+*/
+void QWindow::setFlag(Qt::WindowType flag, bool on)
+{
+ Q_D(QWindow);
+ if (on)
+ setFlags(d->windowFlags | flag);
+ else
+ setFlags(d->windowFlags & ~flag);
+}
+
+/*!
Returns the type of the window.
This returns the part of the window flags that represents
@@ -920,6 +982,9 @@ QIcon QWindow::icon() const
void QWindow::raise()
{
Q_D(QWindow);
+
+ d->updateSiblingPosition(QWindowPrivate::PositionTop);
+
if (d->platformWindow)
d->platformWindow->raise();
}
@@ -932,6 +997,9 @@ void QWindow::raise()
void QWindow::lower()
{
Q_D(QWindow);
+
+ d->updateSiblingPosition(QWindowPrivate::PositionBottom);
+
if (d->platformWindow)
d->platformWindow->lower();
}
@@ -1065,11 +1133,10 @@ bool QWindow::isActive() const
if (focus == this)
return true;
- if (!parent() && !transientParent()) {
+ if (QWindow *p = parent(IncludeTransients))
+ return p->isActive();
+ else
return isAncestorOf(focus);
- } else {
- return (parent() && parent()->isActive()) || (transientParent() && transientParent()->isActive());
- }
}
/*!
@@ -1233,8 +1300,15 @@ bool QWindow::isAncestorOf(const QWindow *child, AncestorMode mode) const
if (child->parent() == this || (mode == IncludeTransients && child->transientParent() == this))
return true;
- return (child->parent() && isAncestorOf(child->parent(), mode))
- || (mode == IncludeTransients && child->transientParent() && isAncestorOf(child->transientParent(), mode));
+ if (QWindow *parent = child->parent(mode)) {
+ if (isAncestorOf(parent, mode))
+ return true;
+ } else if (handle() && child->handle()) {
+ if (handle()->isAncestorOf(child->handle()))
+ return true;
+ }
+
+ return false;
}
/*!
@@ -1455,6 +1529,8 @@ void QWindow::setSizeIncrement(const QSize &size)
Sets the geometry of the window, excluding its window frame, to a
rectangle constructed from \a posx, \a posy, \a w and \a h.
+ The geometry is in relation to the virtualGeometry() of its screen.
+
\sa geometry()
*/
void QWindow::setGeometry(int posx, int posy, int w, int h)
@@ -1465,6 +1541,8 @@ void QWindow::setGeometry(int posx, int posy, int w, int h)
/*!
\brief Sets the geometry of the window, excluding its window frame, to \a rect.
+ The geometry is in relation to the virtualGeometry() of its screen.
+
\sa geometry()
*/
void QWindow::setGeometry(const QRect &rect)
@@ -1526,6 +1604,8 @@ QScreen *QWindowPrivate::screenForGeometry(const QRect &newGeometry)
/*!
Returns the geometry of the window, excluding its window frame.
+ The geometry is in relation to the virtualGeometry() of its screen.
+
\sa frameMargins(), frameGeometry()
*/
QRect QWindow::geometry() const
@@ -1552,6 +1632,8 @@ QMargins QWindow::frameMargins() const
/*!
Returns the geometry of the window, including its window frame.
+ The geometry is in relation to the virtualGeometry() of its screen.
+
\sa geometry(), frameMargins()
*/
QRect QWindow::frameGeometry() const
@@ -1584,6 +1666,8 @@ QPoint QWindow::framePosition() const
/*!
Sets the upper left position of the window (\a point) including its window frame.
+ The position is in relation to the virtualGeometry() of its screen.
+
\sa setGeometry(), frameGeometry()
*/
void QWindow::setFramePosition(const QPoint &point)
@@ -1601,6 +1685,8 @@ void QWindow::setFramePosition(const QPoint &point)
/*!
\brief set the position of the window on the desktop to \a pt
+ The position is in relation to the virtualGeometry() of its screen.
+
\sa position()
*/
void QWindow::setPosition(const QPoint &pt)
@@ -1611,6 +1697,8 @@ void QWindow::setPosition(const QPoint &pt)
/*!
\brief set the position of the window on the desktop to \a posx, \a posy
+ The position is in relation to the virtualGeometry() of its screen.
+
\sa position()
*/
void QWindow::setPosition(int posx, int posy)
@@ -1787,8 +1875,9 @@ QScreen *QWindow::screen() const
If the window has been created, it will be recreated on the \a newScreen.
- Note that if the screen is part of a virtual desktop of multiple screens,
- the window can appear on any of the screens returned by QScreen::virtualSiblings().
+ \note If the screen is part of a virtual desktop of multiple screens,
+ the window will not move automatically to \a newScreen. To place the
+ window relative to the screen, use the screen's topLeft() position.
This function only works for top level windows.
@@ -2377,6 +2466,20 @@ QPoint QWindow::mapFromGlobal(const QPoint &pos) const
return pos - d->globalPosition();
}
+QPoint QWindowPrivate::globalPosition() const
+{
+ Q_Q(const QWindow);
+ QPoint offset = q->position();
+ for (const QWindow *p = q->parent(); p; p = p->parent()) {
+ if (p->type() != Qt::ForeignWindow) {
+ offset += p->position();
+ } else { // Use mapToGlobal() for foreign windows
+ offset += p->mapToGlobal(QPoint(0, 0));
+ break;
+ }
+ }
+ return offset;
+}
Q_GUI_EXPORT QWindowPrivate *qt_window_private(QWindow *window)
{
@@ -2416,10 +2519,7 @@ QWindow *QWindowPrivate::topLevelWindow() const
QWindow *window = const_cast<QWindow *>(q);
while (window) {
- QWindow *parent = window->parent();
- if (!parent)
- parent = window->transientParent();
-
+ QWindow *parent = window->parent(QWindow::IncludeTransients);
if (!parent)
break;
diff --git a/src/gui/kernel/qwindow.h b/src/gui/kernel/qwindow.h
index bf25cf64c9..2883749d2e 100644
--- a/src/gui/kernel/qwindow.h
+++ b/src/gui/kernel/qwindow.h
@@ -132,6 +132,12 @@ public:
};
Q_ENUM(Visibility)
+ enum AncestorMode {
+ ExcludeTransients,
+ IncludeTransients
+ };
+ Q_ENUM(AncestorMode)
+
explicit QWindow(QScreen *screen = Q_NULLPTR);
explicit QWindow(QWindow *parent);
virtual ~QWindow();
@@ -148,7 +154,8 @@ public:
WId winId() const;
- QWindow *parent() const;
+ QWindow *parent(AncestorMode mode) const;
+ QWindow *parent() const; // ### Qt6: Merge with above
void setParent(QWindow *parent);
bool isTopLevel() const;
@@ -163,6 +170,7 @@ public:
void setFlags(Qt::WindowFlags flags);
Qt::WindowFlags flags() const;
+ void setFlag(Qt::WindowType, bool on = true);
Qt::WindowType type() const;
QString title() const;
@@ -186,11 +194,6 @@ public:
void setTransientParent(QWindow *parent);
QWindow *transientParent() const;
- enum AncestorMode {
- ExcludeTransients,
- IncludeTransients
- };
-
bool isAncestorOf(const QWindow *child, AncestorMode mode = IncludeTransients) const;
bool isExposed() const;
diff --git a/src/gui/kernel/qwindow_p.h b/src/gui/kernel/qwindow_p.h
index b8a9f5d3de..95c6abf428 100644
--- a/src/gui/kernel/qwindow_p.h
+++ b/src/gui/kernel/qwindow_p.h
@@ -123,19 +123,7 @@ public:
void deliverUpdateRequest();
- QPoint globalPosition() const {
- Q_Q(const QWindow);
- QPoint offset = q->position();
- for (const QWindow *p = q->parent(); p; p = p->parent()) {
- if (p->type() != Qt::ForeignWindow) {
- offset += p->position();
- } else { // QTBUG-43252, mapToGlobal() for foreign children.
- offset += p->mapToGlobal(QPoint(0, 0));
- break;
- }
- }
- return offset;
- }
+ QPoint globalPosition() const;
QWindow *topLevelWindow() const;
@@ -144,6 +132,9 @@ public:
void updateVisibility();
void _q_clearAlert();
+ enum SiblingPosition { PositionTop, PositionBottom };
+ void updateSiblingPosition(SiblingPosition);
+
bool windowRecreationRequired(QScreen *newScreen) const;
void create(bool recursive);
void setTopLevelScreen(QScreen *newScreen, bool recreate);
diff --git a/src/gui/kernel/qwindowsysteminterface.cpp b/src/gui/kernel/qwindowsysteminterface.cpp
index 8e86ce0b5c..b273682b97 100644
--- a/src/gui/kernel/qwindowsysteminterface.cpp
+++ b/src/gui/kernel/qwindowsysteminterface.cpp
@@ -59,41 +59,57 @@ QWaitCondition QWindowSystemInterfacePrivate::eventsFlushed;
QMutex QWindowSystemInterfacePrivate::flushEventMutex;
QAtomicInt QWindowSystemInterfacePrivate::eventAccepted;
QWindowSystemEventHandler *QWindowSystemInterfacePrivate::eventHandler;
-
-//------------------------------------------------------------
-//
-// Callback functions for plugins:
-//
-
QWindowSystemInterfacePrivate::WindowSystemEventList QWindowSystemInterfacePrivate::windowSystemEventQueue;
extern QPointer<QWindow> qt_last_mouse_receiver;
+
+// ------------------- QWindowSystemInterfacePrivate -------------------
+
/*!
Handles a window system event asynchronously by posting the event to Qt Gui.
- \sa postWindowSystemEvent()
+ This function posts the event on the window system event queue and wakes the
+ Gui event dispatcher. Qt Gui will then handle the event asynchonously at a
+ later point.
*/
template<>
bool QWindowSystemInterfacePrivate::handleWindowSystemEvent<QWindowSystemInterface::AsynchronousDelivery>(WindowSystemEvent *ev)
{
- QWindowSystemInterfacePrivate::postWindowSystemEvent(ev);
+ windowSystemEventQueue.append(ev);
+ if (QAbstractEventDispatcher *dispatcher = QGuiApplicationPrivate::qt_qpa_core_dispatcher())
+ dispatcher->wakeUp();
return true;
}
/*!
Handles a window system event synchronously.
+ Qt Gui will process the event immediately. The return value indicates if Qt
+ accepted the event.
+
If the event is delivered from another thread than the Qt main thread the
window system event queue is flushed, which may deliver other events as
well.
-
- \sa processWindowSystemEvent()
*/
template<>
bool QWindowSystemInterfacePrivate::handleWindowSystemEvent<QWindowSystemInterface::SynchronousDelivery>(WindowSystemEvent *ev)
{
- return QWindowSystemInterfacePrivate::processWindowSystemEvent(ev);
+ bool accepted = true;
+ if (QThread::currentThread() == QGuiApplication::instance()->thread()) {
+ // Process the event immediately on the current thread and return the accepted state.
+ QGuiApplicationPrivate::processWindowSystemEvent(ev);
+ accepted = ev->eventAccepted;
+ delete ev;
+ } else {
+ // Post the event on the Qt main thread queue and flush the queue.
+ // This will wake up the Gui thread which will process the event.
+ // Return the accepted state for the last event on the queue,
+ // which is the event posted by this function.
+ handleWindowSystemEvent<QWindowSystemInterface::AsynchronousDelivery>(ev);
+ accepted = QWindowSystemInterface::flushWindowSystemEvents();
+ }
+ return accepted;
}
/*!
@@ -109,7 +125,7 @@ bool QWindowSystemInterfacePrivate::handleWindowSystemEvent<QWindowSystemInterfa
than the Qt main thread the window system event queue is flushed, which may deliver
other events as well.
- \sa flushWindowSystemEvents(), processWindowSystemEvent(), setSynchronousWindowSystemEvents()
+ \sa flushWindowSystemEvents(), setSynchronousWindowSystemEvents()
*/
template<>
bool QWindowSystemInterfacePrivate::handleWindowSystemEvent<QWindowSystemInterface::DefaultDelivery>(QWindowSystemInterfacePrivate::WindowSystemEvent *ev)
@@ -120,6 +136,59 @@ bool QWindowSystemInterfacePrivate::handleWindowSystemEvent<QWindowSystemInterfa
return handleWindowSystemEvent<QWindowSystemInterface::AsynchronousDelivery>(ev);
}
+int QWindowSystemInterfacePrivate::windowSystemEventsQueued()
+{
+ return windowSystemEventQueue.count();
+}
+
+QWindowSystemInterfacePrivate::WindowSystemEvent * QWindowSystemInterfacePrivate::getWindowSystemEvent()
+{
+ return windowSystemEventQueue.takeFirstOrReturnNull();
+}
+
+QWindowSystemInterfacePrivate::WindowSystemEvent *QWindowSystemInterfacePrivate::getNonUserInputWindowSystemEvent()
+{
+ return windowSystemEventQueue.takeFirstNonUserInputOrReturnNull();
+}
+
+QWindowSystemInterfacePrivate::WindowSystemEvent *QWindowSystemInterfacePrivate::peekWindowSystemEvent(EventType t)
+{
+ return windowSystemEventQueue.peekAtFirstOfType(t);
+}
+
+void QWindowSystemInterfacePrivate::removeWindowSystemEvent(WindowSystemEvent *event)
+{
+ windowSystemEventQueue.remove(event);
+}
+
+void QWindowSystemInterfacePrivate::installWindowSystemEventHandler(QWindowSystemEventHandler *handler)
+{
+ if (!eventHandler)
+ eventHandler = handler;
+}
+
+void QWindowSystemInterfacePrivate::removeWindowSystemEventhandler(QWindowSystemEventHandler *handler)
+{
+ if (eventHandler == handler)
+ eventHandler = 0;
+}
+
+QWindowSystemEventHandler::~QWindowSystemEventHandler()
+{
+ QWindowSystemInterfacePrivate::removeWindowSystemEventhandler(this);
+}
+
+bool QWindowSystemEventHandler::sendEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *e)
+{
+ QGuiApplicationPrivate::processWindowSystemEvent(e);
+ return true;
+}
+
+//------------------------------------------------------------
+//
+// Callback functions for plugins:
+//
+
#define QT_DEFINE_QPA_EVENT_HANDLER(ReturnType, HandlerName, ...) \
template Q_GUI_EXPORT ReturnType QWindowSystemInterface::HandlerName<QWindowSystemInterface::DefaultDelivery>(__VA_ARGS__); \
template Q_GUI_EXPORT ReturnType QWindowSystemInterface::HandlerName<QWindowSystemInterface::SynchronousDelivery>(__VA_ARGS__); \
@@ -138,17 +207,17 @@ bool QWindowSystemInterfacePrivate::handleWindowSystemEvent<QWindowSystemInterfa
until sendWindowSystemEvents() is called by the event dispatcher.
*/
-QT_DEFINE_QPA_EVENT_HANDLER(void, handleEnterEvent, QWindow *tlw, const QPointF &local, const QPointF &global)
+QT_DEFINE_QPA_EVENT_HANDLER(void, handleEnterEvent, QWindow *window, const QPointF &local, const QPointF &global)
{
- if (tlw) {
- QWindowSystemInterfacePrivate::EnterEvent *e = new QWindowSystemInterfacePrivate::EnterEvent(tlw, local, global);
+ if (window) {
+ QWindowSystemInterfacePrivate::EnterEvent *e = new QWindowSystemInterfacePrivate::EnterEvent(window, local, global);
QWindowSystemInterfacePrivate::handleWindowSystemEvent<Delivery>(e);
}
}
-QT_DEFINE_QPA_EVENT_HANDLER(void, handleLeaveEvent, QWindow *tlw)
+QT_DEFINE_QPA_EVENT_HANDLER(void, handleLeaveEvent, QWindow *window)
{
- QWindowSystemInterfacePrivate::LeaveEvent *e = new QWindowSystemInterfacePrivate::LeaveEvent(tlw);
+ QWindowSystemInterfacePrivate::LeaveEvent *e = new QWindowSystemInterfacePrivate::LeaveEvent(window);
QWindowSystemInterfacePrivate::handleWindowSystemEvent<Delivery>(e);
}
@@ -165,24 +234,24 @@ void QWindowSystemInterface::handleEnterLeaveEvent(QWindow *enter, QWindow *leav
handleEnterEvent(enter, local, global);
}
-QT_DEFINE_QPA_EVENT_HANDLER(void, handleWindowActivated, QWindow *tlw, Qt::FocusReason r)
+QT_DEFINE_QPA_EVENT_HANDLER(void, handleWindowActivated, QWindow *window, Qt::FocusReason r)
{
QWindowSystemInterfacePrivate::ActivatedWindowEvent *e =
- new QWindowSystemInterfacePrivate::ActivatedWindowEvent(tlw, r);
+ new QWindowSystemInterfacePrivate::ActivatedWindowEvent(window, r);
QWindowSystemInterfacePrivate::handleWindowSystemEvent<Delivery>(e);
}
-void QWindowSystemInterface::handleWindowStateChanged(QWindow *tlw, Qt::WindowState newState)
+void QWindowSystemInterface::handleWindowStateChanged(QWindow *window, Qt::WindowState newState)
{
QWindowSystemInterfacePrivate::WindowStateChangedEvent *e =
- new QWindowSystemInterfacePrivate::WindowStateChangedEvent(tlw, newState);
+ new QWindowSystemInterfacePrivate::WindowStateChangedEvent(window, newState);
QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
}
-void QWindowSystemInterface::handleWindowScreenChanged(QWindow *tlw, QScreen *screen)
+void QWindowSystemInterface::handleWindowScreenChanged(QWindow *window, QScreen *screen)
{
QWindowSystemInterfacePrivate::WindowScreenChangedEvent *e =
- new QWindowSystemInterfacePrivate::WindowScreenChangedEvent(tlw, screen);
+ new QWindowSystemInterfacePrivate::WindowScreenChangedEvent(window, screen);
QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
}
@@ -197,9 +266,9 @@ void QWindowSystemInterface::handleApplicationStateChanged(Qt::ApplicationState
/*!
If \a oldRect is null, Qt will use the previously reported geometry instead.
*/
-QT_DEFINE_QPA_EVENT_HANDLER(void, handleGeometryChange, QWindow *tlw, const QRect &newRect, const QRect &oldRect)
+QT_DEFINE_QPA_EVENT_HANDLER(void, handleGeometryChange, QWindow *window, const QRect &newRect, const QRect &oldRect)
{
- QWindowSystemInterfacePrivate::GeometryChangeEvent *e = new QWindowSystemInterfacePrivate::GeometryChangeEvent(tlw, QHighDpi::fromNativePixels(newRect, tlw), QHighDpi::fromNativePixels(oldRect, tlw));
+ QWindowSystemInterfacePrivate::GeometryChangeEvent *e = new QWindowSystemInterfacePrivate::GeometryChangeEvent(window, QHighDpi::fromNativePixels(newRect, window), QHighDpi::fromNativePixels(oldRect, window));
QWindowSystemInterfacePrivate::handleWindowSystemEvent<Delivery>(e);
}
@@ -211,18 +280,18 @@ QWindowSystemInterfacePrivate::ExposeEvent::ExposeEvent(QWindow *window, const Q
{
}
-QT_DEFINE_QPA_EVENT_HANDLER(void, handleExposeEvent, QWindow *tlw, const QRegion &region)
+QT_DEFINE_QPA_EVENT_HANDLER(void, handleExposeEvent, QWindow *window, const QRegion &region)
{
QWindowSystemInterfacePrivate::ExposeEvent *e =
- new QWindowSystemInterfacePrivate::ExposeEvent(tlw, QHighDpi::fromNativeLocalExposedRegion(region, tlw));
+ new QWindowSystemInterfacePrivate::ExposeEvent(window, QHighDpi::fromNativeLocalExposedRegion(region, window));
QWindowSystemInterfacePrivate::handleWindowSystemEvent<Delivery>(e);
}
-void QWindowSystemInterface::handleCloseEvent(QWindow *tlw, bool *accepted)
+void QWindowSystemInterface::handleCloseEvent(QWindow *window, bool *accepted)
{
- if (tlw) {
+ if (window) {
QWindowSystemInterfacePrivate::CloseEvent *e =
- new QWindowSystemInterfacePrivate::CloseEvent(tlw, accepted);
+ new QWindowSystemInterfacePrivate::CloseEvent(window, accepted);
QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
}
}
@@ -232,35 +301,35 @@ void QWindowSystemInterface::handleCloseEvent(QWindow *tlw, bool *accepted)
\a w == 0 means that the event is in global coords only, \a local will be ignored in this case
*/
-QT_DEFINE_QPA_EVENT_HANDLER(void, handleMouseEvent, QWindow *w, const QPointF & local, const QPointF & global, Qt::MouseButtons b,
+QT_DEFINE_QPA_EVENT_HANDLER(void, handleMouseEvent, QWindow *window, const QPointF &local, const QPointF &global, Qt::MouseButtons b,
Qt::KeyboardModifiers mods, Qt::MouseEventSource source)
{
unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
- handleMouseEvent<Delivery>(w, time, local, global, b, mods, source);
+ handleMouseEvent<Delivery>(window, time, local, global, b, mods, source);
}
-QT_DEFINE_QPA_EVENT_HANDLER(void, handleMouseEvent, QWindow *w, ulong timestamp, const QPointF & local, const QPointF & global, Qt::MouseButtons b,
+QT_DEFINE_QPA_EVENT_HANDLER(void, handleMouseEvent, QWindow *window, ulong timestamp, const QPointF &local, const QPointF &global, Qt::MouseButtons b,
Qt::KeyboardModifiers mods, Qt::MouseEventSource source)
{
QWindowSystemInterfacePrivate::MouseEvent * e =
- new QWindowSystemInterfacePrivate::MouseEvent(w, timestamp, QHighDpi::fromNativeLocalPosition(local, w), QHighDpi::fromNativePixels(global, w), b, mods, source);
+ new QWindowSystemInterfacePrivate::MouseEvent(window, timestamp, QHighDpi::fromNativeLocalPosition(local, window), QHighDpi::fromNativePixels(global, window), b, mods, source);
QWindowSystemInterfacePrivate::handleWindowSystemEvent<Delivery>(e);
}
-void QWindowSystemInterface::handleFrameStrutMouseEvent(QWindow *w, const QPointF & local, const QPointF & global, Qt::MouseButtons b,
+void QWindowSystemInterface::handleFrameStrutMouseEvent(QWindow *window, const QPointF &local, const QPointF &global, Qt::MouseButtons b,
Qt::KeyboardModifiers mods, Qt::MouseEventSource source)
{
const unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
- handleFrameStrutMouseEvent(w, time, local, global, b, mods, source);
+ handleFrameStrutMouseEvent(window, time, local, global, b, mods, source);
}
-void QWindowSystemInterface::handleFrameStrutMouseEvent(QWindow *w, ulong timestamp, const QPointF & local, const QPointF & global, Qt::MouseButtons b,
+void QWindowSystemInterface::handleFrameStrutMouseEvent(QWindow *window, ulong timestamp, const QPointF &local, const QPointF &global, Qt::MouseButtons b,
Qt::KeyboardModifiers mods, Qt::MouseEventSource source)
{
QWindowSystemInterfacePrivate::MouseEvent * e =
- new QWindowSystemInterfacePrivate::MouseEvent(w, timestamp,
+ new QWindowSystemInterfacePrivate::MouseEvent(window, timestamp,
QWindowSystemInterfacePrivate::FrameStrutMouse,
- QHighDpi::fromNativeLocalPosition(local, w), QHighDpi::fromNativePixels(global, w), b, mods, source);
+ QHighDpi::fromNativeLocalPosition(local, window), QHighDpi::fromNativePixels(global, window), b, mods, source);
QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
}
@@ -309,35 +378,35 @@ bool QWindowSystemInterface::handleShortcutEvent(QWindow *window, ulong timestam
#endif
}
-QT_DEFINE_QPA_EVENT_HANDLER(bool, handleKeyEvent, QWindow *w, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString & text, bool autorep, ushort count) {
+QT_DEFINE_QPA_EVENT_HANDLER(bool, handleKeyEvent, QWindow *window, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString & text, bool autorep, ushort count) {
unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
- return handleKeyEvent<Delivery>(w, time, t, k, mods, text, autorep, count);
+ return handleKeyEvent<Delivery>(window, time, t, k, mods, text, autorep, count);
}
-QT_DEFINE_QPA_EVENT_HANDLER(bool, handleKeyEvent, QWindow *tlw, ulong timestamp, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString & text, bool autorep, ushort count)
+QT_DEFINE_QPA_EVENT_HANDLER(bool, handleKeyEvent, QWindow *window, ulong timestamp, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString & text, bool autorep, ushort count)
{
#if defined(Q_OS_OSX)
- if (t == QEvent::KeyPress && QWindowSystemInterface::handleShortcutEvent(tlw, timestamp, k, mods, 0, 0, 0, text, autorep, count))
+ if (t == QEvent::KeyPress && QWindowSystemInterface::handleShortcutEvent(window, timestamp, k, mods, 0, 0, 0, text, autorep, count))
return true;
#endif
QWindowSystemInterfacePrivate::KeyEvent * e =
- new QWindowSystemInterfacePrivate::KeyEvent(tlw, timestamp, t, k, mods, text, autorep, count);
+ new QWindowSystemInterfacePrivate::KeyEvent(window, timestamp, t, k, mods, text, autorep, count);
return QWindowSystemInterfacePrivate::handleWindowSystemEvent<Delivery>(e);
}
-bool QWindowSystemInterface::handleExtendedKeyEvent(QWindow *w, QEvent::Type type, int key, Qt::KeyboardModifiers modifiers,
+bool QWindowSystemInterface::handleExtendedKeyEvent(QWindow *window, QEvent::Type type, int key, Qt::KeyboardModifiers modifiers,
quint32 nativeScanCode, quint32 nativeVirtualKey,
quint32 nativeModifiers,
const QString& text, bool autorep,
ushort count, bool tryShortcutOverride)
{
unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
- return handleExtendedKeyEvent(w, time, type, key, modifiers, nativeScanCode, nativeVirtualKey, nativeModifiers,
+ return handleExtendedKeyEvent(window, time, type, key, modifiers, nativeScanCode, nativeVirtualKey, nativeModifiers,
text, autorep, count, tryShortcutOverride);
}
-bool QWindowSystemInterface::handleExtendedKeyEvent(QWindow *tlw, ulong timestamp, QEvent::Type type, int key,
+bool QWindowSystemInterface::handleExtendedKeyEvent(QWindow *window, ulong timestamp, QEvent::Type type, int key,
Qt::KeyboardModifiers modifiers,
quint32 nativeScanCode, quint32 nativeVirtualKey,
quint32 nativeModifiers,
@@ -345,7 +414,7 @@ bool QWindowSystemInterface::handleExtendedKeyEvent(QWindow *tlw, ulong timestam
ushort count, bool tryShortcutOverride)
{
#if defined(Q_OS_OSX)
- if (tryShortcutOverride && type == QEvent::KeyPress && QWindowSystemInterface::handleShortcutEvent(tlw,
+ if (tryShortcutOverride && type == QEvent::KeyPress && QWindowSystemInterface::handleShortcutEvent(window,
timestamp, key, modifiers, nativeScanCode, nativeVirtualKey, nativeModifiers, text, autorep, count)) {
return true;
}
@@ -354,29 +423,36 @@ bool QWindowSystemInterface::handleExtendedKeyEvent(QWindow *tlw, ulong timestam
#endif
QWindowSystemInterfacePrivate::KeyEvent * e =
- new QWindowSystemInterfacePrivate::KeyEvent(tlw, timestamp, type, key, modifiers,
+ new QWindowSystemInterfacePrivate::KeyEvent(window, timestamp, type, key, modifiers,
nativeScanCode, nativeVirtualKey, nativeModifiers, text, autorep, count);
return QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
}
-void QWindowSystemInterface::handleWheelEvent(QWindow *w, const QPointF & local, const QPointF & global, int d, Qt::Orientation o, Qt::KeyboardModifiers mods) {
+QWindowSystemInterfacePrivate::WheelEvent::WheelEvent(QWindow *window, ulong time, const QPointF &local, const QPointF &global, QPoint pixelD,
+ QPoint angleD, int qt4D, Qt::Orientation qt4O, Qt::KeyboardModifiers mods, Qt::ScrollPhase phase, Qt::MouseEventSource src, bool inverted)
+ : InputEvent(window, time, Wheel, mods), pixelDelta(pixelD), angleDelta(angleD), qt4Delta(qt4D),
+ qt4Orientation(qt4O), localPos(local), globalPos(global), phase(phase), source(src), inverted(inverted)
+{
+}
+
+void QWindowSystemInterface::handleWheelEvent(QWindow *window, const QPointF &local, const QPointF &global, int d, Qt::Orientation o, Qt::KeyboardModifiers mods) {
unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
- handleWheelEvent(w, time, local, global, d, o, mods);
+ handleWheelEvent(window, time, local, global, d, o, mods);
}
-void QWindowSystemInterface::handleWheelEvent(QWindow *tlw, ulong timestamp, const QPointF & local, const QPointF & global, int d, Qt::Orientation o, Qt::KeyboardModifiers mods)
+void QWindowSystemInterface::handleWheelEvent(QWindow *window, ulong timestamp, const QPointF &local, const QPointF &global, int d, Qt::Orientation o, Qt::KeyboardModifiers mods)
{
QPoint point = (o == Qt::Vertical) ? QPoint(0, d) : QPoint(d, 0);
- handleWheelEvent(tlw, timestamp, local, global, QPoint(), point, mods);
+ handleWheelEvent(window, timestamp, local, global, QPoint(), point, mods);
}
-void QWindowSystemInterface::handleWheelEvent(QWindow *w, const QPointF & local, const QPointF & global, QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods, Qt::ScrollPhase phase, Qt::MouseEventSource source)
+void QWindowSystemInterface::handleWheelEvent(QWindow *window, const QPointF &local, const QPointF &global, QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods, Qt::ScrollPhase phase, Qt::MouseEventSource source)
{
unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
- handleWheelEvent(w, time, local, global, pixelDelta, angleDelta, mods, phase, source);
+ handleWheelEvent(window, time, local, global, pixelDelta, angleDelta, mods, phase, source);
}
-void QWindowSystemInterface::handleWheelEvent(QWindow *tlw, ulong timestamp, const QPointF & local, const QPointF & global, QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods, Qt::ScrollPhase phase,
+void QWindowSystemInterface::handleWheelEvent(QWindow *window, ulong timestamp, const QPointF &local, const QPointF &global, QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods, Qt::ScrollPhase phase,
Qt::MouseEventSource source, bool invertedScrolling)
{
// Qt 4 sends two separate wheel events for horizontal and vertical
@@ -395,7 +471,7 @@ void QWindowSystemInterface::handleWheelEvent(QWindow *tlw, ulong timestamp, con
// Simple case: vertical deltas only:
if (angleDelta.y() != 0 && angleDelta.x() == 0) {
- e = new QWindowSystemInterfacePrivate::WheelEvent(tlw, timestamp, QHighDpi::fromNativeLocalPosition(local, tlw), QHighDpi::fromNativePixels(global, tlw), pixelDelta, angleDelta, angleDelta.y(), Qt::Vertical,
+ e = new QWindowSystemInterfacePrivate::WheelEvent(window, timestamp, QHighDpi::fromNativeLocalPosition(local, window), QHighDpi::fromNativePixels(global, window), pixelDelta, angleDelta, angleDelta.y(), Qt::Vertical,
mods, phase, source, invertedScrolling);
QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
return;
@@ -403,7 +479,7 @@ void QWindowSystemInterface::handleWheelEvent(QWindow *tlw, ulong timestamp, con
// Simple case: horizontal deltas only:
if (angleDelta.y() == 0 && angleDelta.x() != 0) {
- e = new QWindowSystemInterfacePrivate::WheelEvent(tlw, timestamp, QHighDpi::fromNativeLocalPosition(local, tlw), QHighDpi::fromNativePixels(global, tlw), pixelDelta, angleDelta, angleDelta.x(), Qt::Horizontal, mods, phase, source, invertedScrolling);
+ e = new QWindowSystemInterfacePrivate::WheelEvent(window, timestamp, QHighDpi::fromNativeLocalPosition(local, window), QHighDpi::fromNativePixels(global, window), pixelDelta, angleDelta, angleDelta.x(), Qt::Horizontal, mods, phase, source, invertedScrolling);
QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
return;
}
@@ -411,106 +487,65 @@ void QWindowSystemInterface::handleWheelEvent(QWindow *tlw, ulong timestamp, con
// Both horizontal and vertical deltas: Send two wheel events.
// The first event contains the Qt 5 pixel and angle delta as points,
// and in addition the Qt 4 compatibility vertical angle delta.
- e = new QWindowSystemInterfacePrivate::WheelEvent(tlw, timestamp, QHighDpi::fromNativeLocalPosition(local, tlw), QHighDpi::fromNativePixels(global, tlw), pixelDelta, angleDelta, angleDelta.y(), Qt::Vertical, mods, phase, source, invertedScrolling);
+ e = new QWindowSystemInterfacePrivate::WheelEvent(window, timestamp, QHighDpi::fromNativeLocalPosition(local, window), QHighDpi::fromNativePixels(global, window), pixelDelta, angleDelta, angleDelta.y(), Qt::Vertical, mods, phase, source, invertedScrolling);
QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
// The second event contains null pixel and angle points and the
// Qt 4 compatibility horizontal angle delta.
- e = new QWindowSystemInterfacePrivate::WheelEvent(tlw, timestamp, QHighDpi::fromNativeLocalPosition(local, tlw), QHighDpi::fromNativePixels(global, tlw), QPoint(), QPoint(), angleDelta.x(), Qt::Horizontal, mods, phase, source, invertedScrolling);
+ e = new QWindowSystemInterfacePrivate::WheelEvent(window, timestamp, QHighDpi::fromNativeLocalPosition(local, window), QHighDpi::fromNativePixels(global, window), QPoint(), QPoint(), angleDelta.x(), Qt::Horizontal, mods, phase, source, invertedScrolling);
QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
}
-int QWindowSystemInterfacePrivate::windowSystemEventsQueued()
-{
- return windowSystemEventQueue.count();
-}
-
-QWindowSystemInterfacePrivate::WindowSystemEvent * QWindowSystemInterfacePrivate::getWindowSystemEvent()
+void QWindowSystemInterface::registerTouchDevice(const QTouchDevice *device)
{
- return windowSystemEventQueue.takeFirstOrReturnNull();
+ QTouchDevicePrivate::registerDevice(device);
}
-QWindowSystemInterfacePrivate::WindowSystemEvent *QWindowSystemInterfacePrivate::getNonUserInputWindowSystemEvent()
+void QWindowSystemInterface::unregisterTouchDevice(const QTouchDevice *device)
{
- return windowSystemEventQueue.takeFirstNonUserInputOrReturnNull();
+ QTouchDevicePrivate::unregisterDevice(device);
}
-QWindowSystemInterfacePrivate::WindowSystemEvent *QWindowSystemInterfacePrivate::peekWindowSystemEvent(EventType t)
+bool QWindowSystemInterface::isTouchDeviceRegistered(const QTouchDevice *device)
{
- return windowSystemEventQueue.peekAtFirstOfType(t);
+ return QTouchDevicePrivate::isRegistered(device);
}
-void QWindowSystemInterfacePrivate::removeWindowSystemEvent(WindowSystemEvent *event)
-{
- windowSystemEventQueue.remove(event);
-}
+static int g_nextPointId = 1;
-/*!
- Posts a window system event to be handled asynchronously by Qt Gui.
-
- This function posts the event on the window system event queue and wakes the
- Gui event dispatcher. Qt Gui will then handle the event asynchonously at a
- later point.
-
- \sa flushWindowSystemEvents(), processWindowSystemEvent(), handleWindowSystemEvent()
-*/
-void QWindowSystemInterfacePrivate::postWindowSystemEvent(WindowSystemEvent *ev)
-{
- windowSystemEventQueue.append(ev);
- QAbstractEventDispatcher *dispatcher = QGuiApplicationPrivate::qt_qpa_core_dispatcher();
- if (dispatcher)
- dispatcher->wakeUp();
-}
+// map from device-independent point id (arbitrary) to "Qt point" ids
+typedef QMap<quint64, int> PointIdMap;
+Q_GLOBAL_STATIC(PointIdMap, g_pointIdMap)
/*!
- Processes a window system event synchronously.
-
- Qt Gui will process the event immediately. The return value indicates if Qt
- accepted the event.
-
- If the event is delivered from another thread than the Qt main thread the
- window system event queue is flushed, which may deliver other events as
- well.
-
- \sa flushWindowSystemEvents(), postWindowSystemEvent(), handleWindowSystemEvent()
+ \internal
+ This function maps potentially arbitrary point ids \a pointId in the 32 bit
+ value space to start from 1 and increase incrementally for each touch point
+ held down. If all touch points are released it will reset the id back to 1
+ for the following touch point.
+
+ We can then assume that the touch points ids will never become too large,
+ and it will then put the device identifier \a deviceId in the upper 8 bits.
+ This leaves us with max 255 devices, and 16.7M taps without full release
+ before we run out of value space.
*/
-bool QWindowSystemInterfacePrivate::processWindowSystemEvent(WindowSystemEvent *ev)
-{
- bool accepted = true;
- if (QThread::currentThread() == QGuiApplication::instance()->thread()) {
- // Process the event immediately on the current thread and return the accepted state.
- QGuiApplicationPrivate::processWindowSystemEvent(ev);
- accepted = ev->eventAccepted;
- delete ev;
+static int acquireCombinedPointId(quint8 deviceId, int pointId)
+{
+ quint64 combinedId64 = (quint64(deviceId) << 32) + pointId;
+ auto it = g_pointIdMap->constFind(combinedId64);
+ int uid;
+ if (it == g_pointIdMap->constEnd()) {
+ uid = g_nextPointId++;
+ g_pointIdMap->insert(combinedId64, uid);
} else {
- // Post the event on the Qt main thread queue and flush the queue.
- // This will wake up the Gui thread which will process the event.
- // Return the accepted state for the last event on the queue,
- // which is the event posted by this function.
- postWindowSystemEvent(ev);
- accepted = QWindowSystemInterface::flushWindowSystemEvents();
+ uid = *it;
}
- return accepted;
-}
-
-void QWindowSystemInterface::registerTouchDevice(const QTouchDevice *device)
-{
- QTouchDevicePrivate::registerDevice(device);
-}
-
-void QWindowSystemInterface::unregisterTouchDevice(const QTouchDevice *device)
-{
- QTouchDevicePrivate::unregisterDevice(device);
-}
-
-bool QWindowSystemInterface::isTouchDeviceRegistered(const QTouchDevice *device)
-{
- return QTouchDevicePrivate::isRegistered(device);
+ return (deviceId << 24) + uid;
}
QList<QTouchEvent::TouchPoint>
QWindowSystemInterfacePrivate::fromNativeTouchPoints(const QList<QWindowSystemInterface::TouchPoint> &points,
- const QWindow *window,
+ const QWindow *window, quint8 deviceId,
QEvent::Type *type)
{
QList<QTouchEvent::TouchPoint> touchPoints;
@@ -521,7 +556,7 @@ QList<QTouchEvent::TouchPoint>
QList<QWindowSystemInterface::TouchPoint>::const_iterator point = points.constBegin();
QList<QWindowSystemInterface::TouchPoint>::const_iterator end = points.constEnd();
while (point != end) {
- p.setId(point->id);
+ p.setId(acquireCombinedPointId(deviceId, point->id));
if (point->uniqueId >= 0)
p.setUniqueId(point->uniqueId);
p.setPressure(point->pressure);
@@ -554,6 +589,11 @@ QList<QTouchEvent::TouchPoint>
*type = QEvent::TouchEnd;
}
+ if (states == Qt::TouchPointReleased) {
+ g_nextPointId = 1;
+ g_pointIdMap->clear();
+ }
+
return touchPoints;
}
@@ -578,14 +618,14 @@ QList<QWindowSystemInterface::TouchPoint>
return newList;
}
-QT_DEFINE_QPA_EVENT_HANDLER(void, handleTouchEvent, QWindow *w, QTouchDevice *device,
+QT_DEFINE_QPA_EVENT_HANDLER(void, handleTouchEvent, QWindow *window, QTouchDevice *device,
const QList<TouchPoint> &points, Qt::KeyboardModifiers mods)
{
unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
- handleTouchEvent<Delivery>(w, time, device, points, mods);
+ handleTouchEvent<Delivery>(window, time, device, points, mods);
}
-QT_DEFINE_QPA_EVENT_HANDLER(void, handleTouchEvent, QWindow *tlw, ulong timestamp, QTouchDevice *device,
+QT_DEFINE_QPA_EVENT_HANDLER(void, handleTouchEvent, QWindow *window, ulong timestamp, QTouchDevice *device,
const QList<TouchPoint> &points, Qt::KeyboardModifiers mods)
{
if (!points.size()) // Touch events must have at least one point
@@ -595,25 +635,26 @@ QT_DEFINE_QPA_EVENT_HANDLER(void, handleTouchEvent, QWindow *tlw, ulong timestam
return;
QEvent::Type type;
- QList<QTouchEvent::TouchPoint> touchPoints = QWindowSystemInterfacePrivate::fromNativeTouchPoints(points, tlw, &type);
+ QList<QTouchEvent::TouchPoint> touchPoints =
+ QWindowSystemInterfacePrivate::fromNativeTouchPoints(points, window, QTouchDevicePrivate::get(device)->id, &type);
QWindowSystemInterfacePrivate::TouchEvent *e =
- new QWindowSystemInterfacePrivate::TouchEvent(tlw, timestamp, type, device, touchPoints, mods);
+ new QWindowSystemInterfacePrivate::TouchEvent(window, timestamp, type, device, touchPoints, mods);
QWindowSystemInterfacePrivate::handleWindowSystemEvent<Delivery>(e);
}
-QT_DEFINE_QPA_EVENT_HANDLER(void, handleTouchCancelEvent, QWindow *w, QTouchDevice *device,
+QT_DEFINE_QPA_EVENT_HANDLER(void, handleTouchCancelEvent, QWindow *window, QTouchDevice *device,
Qt::KeyboardModifiers mods)
{
unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
- handleTouchCancelEvent<Delivery>(w, time, device, mods);
+ handleTouchCancelEvent<Delivery>(window, time, device, mods);
}
-QT_DEFINE_QPA_EVENT_HANDLER(void, handleTouchCancelEvent, QWindow *w, ulong timestamp, QTouchDevice *device,
+QT_DEFINE_QPA_EVENT_HANDLER(void, handleTouchCancelEvent, QWindow *window, ulong timestamp, QTouchDevice *device,
Qt::KeyboardModifiers mods)
{
QWindowSystemInterfacePrivate::TouchEvent *e =
- new QWindowSystemInterfacePrivate::TouchEvent(w, timestamp, QEvent::TouchCancel, device,
+ new QWindowSystemInterfacePrivate::TouchEvent(window, timestamp, QEvent::TouchCancel, device,
QList<QTouchEvent::TouchPoint>(), mods);
QWindowSystemInterfacePrivate::handleWindowSystemEvent<Delivery>(e);
}
@@ -646,113 +687,21 @@ void QWindowSystemInterface::handleScreenRefreshRateChange(QScreen *screen, qrea
QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
}
-void QWindowSystemInterface::handleThemeChange(QWindow *tlw)
+void QWindowSystemInterface::handleThemeChange(QWindow *window)
{
- QWindowSystemInterfacePrivate::ThemeChangeEvent *e = new QWindowSystemInterfacePrivate::ThemeChangeEvent(tlw);
+ QWindowSystemInterfacePrivate::ThemeChangeEvent *e = new QWindowSystemInterfacePrivate::ThemeChangeEvent(window);
QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
}
-void QWindowSystemInterface::deferredFlushWindowSystemEvents(QEventLoop::ProcessEventsFlags flags)
-{
- Q_ASSERT(QThread::currentThread() == QGuiApplication::instance()->thread());
-
- QMutexLocker locker(&QWindowSystemInterfacePrivate::flushEventMutex);
- sendWindowSystemEvents(flags);
- QWindowSystemInterfacePrivate::eventsFlushed.wakeOne();
-}
-
-/*!
- Make Qt Gui process all events on the event queue immediately. Return the
- accepted state for the last event on the queue.
-*/
-bool QWindowSystemInterface::flushWindowSystemEvents(QEventLoop::ProcessEventsFlags flags)
-{
- const int count = QWindowSystemInterfacePrivate::windowSystemEventQueue.count();
- if (!count)
- return false;
- if (!QGuiApplication::instance()) {
- qWarning().nospace()
- << "QWindowSystemInterface::flushWindowSystemEvents() invoked after "
- "QGuiApplication destruction, discarding " << count << " events.";
- QWindowSystemInterfacePrivate::windowSystemEventQueue.clear();
- return false;
- }
- if (QThread::currentThread() != QGuiApplication::instance()->thread()) {
- // Post a FlushEvents event which will trigger a call back to
- // deferredFlushWindowSystemEvents from the Gui thread.
- QMutexLocker locker(&QWindowSystemInterfacePrivate::flushEventMutex);
- QWindowSystemInterfacePrivate::FlushEventsEvent *e = new QWindowSystemInterfacePrivate::FlushEventsEvent(flags);
- QWindowSystemInterfacePrivate::handleWindowSystemEvent<AsynchronousDelivery>(e);
- QWindowSystemInterfacePrivate::eventsFlushed.wait(&QWindowSystemInterfacePrivate::flushEventMutex);
- } else {
- sendWindowSystemEvents(flags);
- }
- return QWindowSystemInterfacePrivate::eventAccepted.load() > 0;
-}
-
-bool QWindowSystemInterface::sendWindowSystemEvents(QEventLoop::ProcessEventsFlags flags)
-{
- int nevents = 0;
-
- while (QWindowSystemInterfacePrivate::windowSystemEventsQueued()) {
- QWindowSystemInterfacePrivate::WindowSystemEvent *event =
- (flags & QEventLoop::ExcludeUserInputEvents) ?
- QWindowSystemInterfacePrivate::getNonUserInputWindowSystemEvent() :
- QWindowSystemInterfacePrivate::getWindowSystemEvent();
- if (!event)
- break;
-
- if (QWindowSystemInterfacePrivate::eventHandler) {
- if (QWindowSystemInterfacePrivate::eventHandler->sendEvent(event))
- nevents++;
- } else {
- nevents++;
- QGuiApplicationPrivate::processWindowSystemEvent(event);
- }
-
- // Record the accepted state for the processed event
- // (excluding flush events). This state can then be
- // returned by flushWindowSystemEvents().
- if (event->type != QWindowSystemInterfacePrivate::FlushEvents)
- QWindowSystemInterfacePrivate::eventAccepted.store(event->eventAccepted);
-
- delete event;
- }
-
- return (nevents > 0);
-}
-
-void QWindowSystemInterfacePrivate::installWindowSystemEventHandler(QWindowSystemEventHandler *handler)
-{
- if (!eventHandler)
- eventHandler = handler;
-}
-
-void QWindowSystemInterfacePrivate::removeWindowSystemEventhandler(QWindowSystemEventHandler *handler)
-{
- if (eventHandler == handler)
- eventHandler = 0;
-}
-
-void QWindowSystemInterface::setSynchronousWindowSystemEvents(bool enable)
-{
- QWindowSystemInterfacePrivate::synchronousWindowSystemEvents = enable;
-}
-
-int QWindowSystemInterface::windowSystemEventsQueued()
-{
- return QWindowSystemInterfacePrivate::windowSystemEventsQueued();
-}
-
#ifndef QT_NO_DRAGANDDROP
-QPlatformDragQtResponse QWindowSystemInterface::handleDrag(QWindow *w, const QMimeData *dropData, const QPoint &p, Qt::DropActions supportedActions)
+QPlatformDragQtResponse QWindowSystemInterface::handleDrag(QWindow *window, const QMimeData *dropData, const QPoint &p, Qt::DropActions supportedActions)
{
- return QGuiApplicationPrivate::processDrag(w, dropData, QHighDpi::fromNativeLocalPosition(p, w) ,supportedActions);
+ return QGuiApplicationPrivate::processDrag(window, dropData, QHighDpi::fromNativeLocalPosition(p, window) ,supportedActions);
}
-QPlatformDropQtResponse QWindowSystemInterface::handleDrop(QWindow *w, const QMimeData *dropData, const QPoint &p, Qt::DropActions supportedActions)
+QPlatformDropQtResponse QWindowSystemInterface::handleDrop(QWindow *window, const QMimeData *dropData, const QPoint &p, Qt::DropActions supportedActions)
{
- return QGuiApplicationPrivate::processDrop(w, dropData, QHighDpi::fromNativeLocalPosition(p, w),supportedActions);
+ return QGuiApplicationPrivate::processDrop(window, dropData, QHighDpi::fromNativeLocalPosition(p, window),supportedActions);
}
#endif // QT_NO_DRAGANDDROP
@@ -780,45 +729,50 @@ void QWindowSystemInterface::handleFileOpenEvent(const QUrl &url)
QGuiApplicationPrivate::processWindowSystemEvent(&e);
}
-void QWindowSystemInterface::handleTabletEvent(QWindow *w, ulong timestamp, const QPointF &local, const QPointF &global,
+void QWindowSystemInterfacePrivate::TabletEvent::setPlatformSynthesizesMouse(bool v)
+{
+ platformSynthesizesMouse = v;
+}
+
+void QWindowSystemInterface::handleTabletEvent(QWindow *window, ulong timestamp, const QPointF &local, const QPointF &global,
int device, int pointerType, Qt::MouseButtons buttons, qreal pressure, int xTilt, int yTilt,
qreal tangentialPressure, qreal rotation, int z, qint64 uid,
Qt::KeyboardModifiers modifiers)
{
QWindowSystemInterfacePrivate::TabletEvent *e =
- new QWindowSystemInterfacePrivate::TabletEvent(w,timestamp,
- QHighDpi::fromNativeLocalPosition(local, w),
- QHighDpi::fromNativePixels(global, w),
+ new QWindowSystemInterfacePrivate::TabletEvent(window, timestamp,
+ QHighDpi::fromNativeLocalPosition(local, window),
+ QHighDpi::fromNativePixels(global, window),
device, pointerType, buttons, pressure,
xTilt, yTilt, tangentialPressure, rotation, z, uid, modifiers);
QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
}
-void QWindowSystemInterface::handleTabletEvent(QWindow *w, const QPointF &local, const QPointF &global,
+void QWindowSystemInterface::handleTabletEvent(QWindow *window, const QPointF &local, const QPointF &global,
int device, int pointerType, Qt::MouseButtons buttons, qreal pressure, int xTilt, int yTilt,
qreal tangentialPressure, qreal rotation, int z, qint64 uid,
Qt::KeyboardModifiers modifiers)
{
ulong time = QWindowSystemInterfacePrivate::eventTime.elapsed();
- handleTabletEvent(w, time, local, global, device, pointerType, buttons, pressure,
+ handleTabletEvent(window, time, local, global, device, pointerType, buttons, pressure,
xTilt, yTilt, tangentialPressure, rotation, z, uid, modifiers);
}
-void QWindowSystemInterface::handleTabletEvent(QWindow *w, ulong timestamp, bool down, const QPointF &local, const QPointF &global,
+void QWindowSystemInterface::handleTabletEvent(QWindow *window, ulong timestamp, bool down, const QPointF &local, const QPointF &global,
int device, int pointerType, qreal pressure, int xTilt, int yTilt,
qreal tangentialPressure, qreal rotation, int z, qint64 uid,
Qt::KeyboardModifiers modifiers)
{
- handleTabletEvent(w, timestamp, local, global, device, pointerType, (down ? Qt::LeftButton : Qt::NoButton), pressure,
+ handleTabletEvent(window, timestamp, local, global, device, pointerType, (down ? Qt::LeftButton : Qt::NoButton), pressure,
xTilt, yTilt, tangentialPressure, rotation, z, uid, modifiers);
}
-void QWindowSystemInterface::handleTabletEvent(QWindow *w, bool down, const QPointF &local, const QPointF &global,
+void QWindowSystemInterface::handleTabletEvent(QWindow *window, bool down, const QPointF &local, const QPointF &global,
int device, int pointerType, qreal pressure, int xTilt, int yTilt,
qreal tangentialPressure, qreal rotation, int z, qint64 uid,
Qt::KeyboardModifiers modifiers)
{
- handleTabletEvent(w, local, global, device, pointerType, (down ? Qt::LeftButton : Qt::NoButton), pressure,
+ handleTabletEvent(window, local, global, device, pointerType, (down ? Qt::LeftButton : Qt::NoButton), pressure,
xTilt, yTilt, tangentialPressure, rotation, z, uid, modifiers);
}
@@ -885,12 +839,12 @@ void QWindowSystemInterface::handlePlatformPanelEvent(QWindow *w)
}
#ifndef QT_NO_CONTEXTMENU
-void QWindowSystemInterface::handleContextMenuEvent(QWindow *w, bool mouseTriggered,
+void QWindowSystemInterface::handleContextMenuEvent(QWindow *window, bool mouseTriggered,
const QPoint &pos, const QPoint &globalPos,
Qt::KeyboardModifiers modifiers)
{
QWindowSystemInterfacePrivate::ContextMenuEvent *e =
- new QWindowSystemInterfacePrivate::ContextMenuEvent(w, mouseTriggered, pos,
+ new QWindowSystemInterfacePrivate::ContextMenuEvent(window, mouseTriggered, pos,
globalPos, modifiers);
QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
}
@@ -915,13 +869,97 @@ Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QWindowSystemInterface::TouchPo
}
#endif
+// ------------------ Event dispatcher functionality ------------------
+
+/*!
+ Make Qt Gui process all events on the event queue immediately. Return the
+ accepted state for the last event on the queue.
+*/
+bool QWindowSystemInterface::flushWindowSystemEvents(QEventLoop::ProcessEventsFlags flags)
+{
+ const int count = QWindowSystemInterfacePrivate::windowSystemEventQueue.count();
+ if (!count)
+ return false;
+ if (!QGuiApplication::instance()) {
+ qWarning().nospace()
+ << "QWindowSystemInterface::flushWindowSystemEvents() invoked after "
+ "QGuiApplication destruction, discarding " << count << " events.";
+ QWindowSystemInterfacePrivate::windowSystemEventQueue.clear();
+ return false;
+ }
+ if (QThread::currentThread() != QGuiApplication::instance()->thread()) {
+ // Post a FlushEvents event which will trigger a call back to
+ // deferredFlushWindowSystemEvents from the Gui thread.
+ QMutexLocker locker(&QWindowSystemInterfacePrivate::flushEventMutex);
+ QWindowSystemInterfacePrivate::FlushEventsEvent *e = new QWindowSystemInterfacePrivate::FlushEventsEvent(flags);
+ QWindowSystemInterfacePrivate::handleWindowSystemEvent<AsynchronousDelivery>(e);
+ QWindowSystemInterfacePrivate::eventsFlushed.wait(&QWindowSystemInterfacePrivate::flushEventMutex);
+ } else {
+ sendWindowSystemEvents(flags);
+ }
+ return QWindowSystemInterfacePrivate::eventAccepted.load() > 0;
+}
+
+void QWindowSystemInterface::deferredFlushWindowSystemEvents(QEventLoop::ProcessEventsFlags flags)
+{
+ Q_ASSERT(QThread::currentThread() == QGuiApplication::instance()->thread());
+
+ QMutexLocker locker(&QWindowSystemInterfacePrivate::flushEventMutex);
+ sendWindowSystemEvents(flags);
+ QWindowSystemInterfacePrivate::eventsFlushed.wakeOne();
+}
+
+bool QWindowSystemInterface::sendWindowSystemEvents(QEventLoop::ProcessEventsFlags flags)
+{
+ int nevents = 0;
+
+ while (QWindowSystemInterfacePrivate::windowSystemEventsQueued()) {
+ QWindowSystemInterfacePrivate::WindowSystemEvent *event =
+ (flags & QEventLoop::ExcludeUserInputEvents) ?
+ QWindowSystemInterfacePrivate::getNonUserInputWindowSystemEvent() :
+ QWindowSystemInterfacePrivate::getWindowSystemEvent();
+ if (!event)
+ break;
+
+ if (QWindowSystemInterfacePrivate::eventHandler) {
+ if (QWindowSystemInterfacePrivate::eventHandler->sendEvent(event))
+ nevents++;
+ } else {
+ nevents++;
+ QGuiApplicationPrivate::processWindowSystemEvent(event);
+ }
+
+ // Record the accepted state for the processed event
+ // (excluding flush events). This state can then be
+ // returned by flushWindowSystemEvents().
+ if (event->type != QWindowSystemInterfacePrivate::FlushEvents)
+ QWindowSystemInterfacePrivate::eventAccepted.store(event->eventAccepted);
+
+ delete event;
+ }
+
+ return (nevents > 0);
+}
+
+void QWindowSystemInterface::setSynchronousWindowSystemEvents(bool enable)
+{
+ QWindowSystemInterfacePrivate::synchronousWindowSystemEvents = enable;
+}
+
+int QWindowSystemInterface::windowSystemEventsQueued()
+{
+ return QWindowSystemInterfacePrivate::windowSystemEventsQueued();
+}
+
+// --------------------- QtTestLib support ---------------------
+
// The following functions are used by testlib, and need to be synchronous to avoid
// race conditions with plugins delivering native events from secondary threads.
-Q_GUI_EXPORT void qt_handleMouseEvent(QWindow *w, const QPointF &local, const QPointF &global, Qt::MouseButtons b, Qt::KeyboardModifiers mods, int timestamp)
+Q_GUI_EXPORT void qt_handleMouseEvent(QWindow *window, const QPointF &local, const QPointF &global, Qt::MouseButtons b, Qt::KeyboardModifiers mods, int timestamp)
{
- const qreal factor = QHighDpiScaling::factor(w);
- QWindowSystemInterface::handleMouseEvent<QWindowSystemInterface::SynchronousDelivery>(w, timestamp, local * factor, global * factor, b, mods);
+ const qreal factor = QHighDpiScaling::factor(window);
+ QWindowSystemInterface::handleMouseEvent<QWindowSystemInterface::SynchronousDelivery>(window, timestamp, local * factor, global * factor, b, mods);
}
// Wrapper for compatibility with Qt < 5.6
@@ -931,9 +969,9 @@ Q_GUI_EXPORT void qt_handleMouseEvent(QWindow *w, const QPointF &local, const QP
qt_handleMouseEvent(w, local, global, b, mods, QWindowSystemInterfacePrivate::eventTime.elapsed());
}
-Q_GUI_EXPORT void qt_handleKeyEvent(QWindow *w, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString & text = QString(), bool autorep = false, ushort count = 1)
+Q_GUI_EXPORT void qt_handleKeyEvent(QWindow *window, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString & text = QString(), bool autorep = false, ushort count = 1)
{
- QWindowSystemInterface::handleKeyEvent<QWindowSystemInterface::SynchronousDelivery>(w, t, k, mods, text, autorep, count);
+ QWindowSystemInterface::handleKeyEvent<QWindowSystemInterface::SynchronousDelivery>(window, t, k, mods, text, autorep, count);
}
Q_GUI_EXPORT bool qt_sendShortcutOverrideEvent(QObject *o, ulong timestamp, int k, Qt::KeyboardModifiers mods, const QString &text = QString(), bool autorep = false, ushort count = 1)
@@ -984,35 +1022,13 @@ namespace QTest
}
}
-Q_GUI_EXPORT void qt_handleTouchEvent(QWindow *w, QTouchDevice *device,
+Q_GUI_EXPORT void qt_handleTouchEvent(QWindow *window, QTouchDevice *device,
const QList<QTouchEvent::TouchPoint> &points,
Qt::KeyboardModifiers mods = Qt::NoModifier)
{
- QWindowSystemInterface::handleTouchEvent<QWindowSystemInterface::SynchronousDelivery>(w, device,
- QWindowSystemInterfacePrivate::toNativeTouchPoints(points, w), mods);
-}
-
-QWindowSystemEventHandler::~QWindowSystemEventHandler()
-{
- QWindowSystemInterfacePrivate::removeWindowSystemEventhandler(this);
-}
-
-bool QWindowSystemEventHandler::sendEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *e)
-{
- QGuiApplicationPrivate::processWindowSystemEvent(e);
- return true;
+ QWindowSystemInterface::handleTouchEvent<QWindowSystemInterface::SynchronousDelivery>(window, device,
+ QWindowSystemInterfacePrivate::toNativeTouchPoints(points, window), mods);
}
-QWindowSystemInterfacePrivate::WheelEvent::WheelEvent(QWindow *w, ulong time, const QPointF &local, const QPointF &global, QPoint pixelD,
- QPoint angleD, int qt4D, Qt::Orientation qt4O, Qt::KeyboardModifiers mods, Qt::ScrollPhase phase, Qt::MouseEventSource src, bool inverted)
- : InputEvent(w, time, Wheel, mods), pixelDelta(pixelD), angleDelta(angleD), qt4Delta(qt4D),
- qt4Orientation(qt4O), localPos(local), globalPos(global), phase(phase), source(src), inverted(inverted)
-{
-}
-
-void QWindowSystemInterfacePrivate::TabletEvent::setPlatformSynthesizesMouse(bool v)
-{
- platformSynthesizesMouse = v;
-}
QT_END_NAMESPACE
diff --git a/src/gui/kernel/qwindowsysteminterface.h b/src/gui/kernel/qwindowsysteminterface.h
index a28d1c93df..11864e7adc 100644
--- a/src/gui/kernel/qwindowsysteminterface.h
+++ b/src/gui/kernel/qwindowsysteminterface.h
@@ -77,44 +77,44 @@ public:
struct DefaultDelivery {};
template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
- static void handleMouseEvent(QWindow *w, const QPointF & local, const QPointF & global, Qt::MouseButtons b,
+ static void handleMouseEvent(QWindow *window, const QPointF &local, const QPointF &global, Qt::MouseButtons b,
Qt::KeyboardModifiers mods = Qt::NoModifier,
Qt::MouseEventSource source = Qt::MouseEventNotSynthesized);
template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
- static void handleMouseEvent(QWindow *w, ulong timestamp, const QPointF & local, const QPointF & global, Qt::MouseButtons b,
+ static void handleMouseEvent(QWindow *window, ulong timestamp, const QPointF &local, const QPointF &global, Qt::MouseButtons b,
Qt::KeyboardModifiers mods = Qt::NoModifier,
Qt::MouseEventSource source = Qt::MouseEventNotSynthesized);
- static void handleFrameStrutMouseEvent(QWindow *w, const QPointF & local, const QPointF & global, Qt::MouseButtons b,
+ static void handleFrameStrutMouseEvent(QWindow *window, const QPointF &local, const QPointF &global, Qt::MouseButtons b,
Qt::KeyboardModifiers mods = Qt::NoModifier,
Qt::MouseEventSource source = Qt::MouseEventNotSynthesized);
- static void handleFrameStrutMouseEvent(QWindow *w, ulong timestamp, const QPointF & local, const QPointF & global, Qt::MouseButtons b,
+ static void handleFrameStrutMouseEvent(QWindow *window, ulong timestamp, const QPointF &local, const QPointF &global, Qt::MouseButtons b,
Qt::KeyboardModifiers mods = Qt::NoModifier,
Qt::MouseEventSource source = Qt::MouseEventNotSynthesized);
- static bool handleShortcutEvent(QWindow *w, ulong timestamp, int k, Qt::KeyboardModifiers mods, quint32 nativeScanCode,
+ static bool handleShortcutEvent(QWindow *window, ulong timestamp, int k, Qt::KeyboardModifiers mods, quint32 nativeScanCode,
quint32 nativeVirtualKey, quint32 nativeModifiers, const QString & text = QString(), bool autorep = false, ushort count = 1);
template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
- static bool handleKeyEvent(QWindow *w, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString & text = QString(), bool autorep = false, ushort count = 1);
+ static bool handleKeyEvent(QWindow *window, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString & text = QString(), bool autorep = false, ushort count = 1);
template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
- static bool handleKeyEvent(QWindow *w, ulong timestamp, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString & text = QString(), bool autorep = false, ushort count = 1);
+ static bool handleKeyEvent(QWindow *window, ulong timestamp, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString & text = QString(), bool autorep = false, ushort count = 1);
- static bool handleExtendedKeyEvent(QWindow *w, QEvent::Type type, int key, Qt::KeyboardModifiers modifiers,
+ static bool handleExtendedKeyEvent(QWindow *window, QEvent::Type type, int key, Qt::KeyboardModifiers modifiers,
quint32 nativeScanCode, quint32 nativeVirtualKey,
quint32 nativeModifiers,
const QString& text = QString(), bool autorep = false,
ushort count = 1, bool tryShortcutOverride = true);
- static bool handleExtendedKeyEvent(QWindow *w, ulong timestamp, QEvent::Type type, int key, Qt::KeyboardModifiers modifiers,
+ static bool handleExtendedKeyEvent(QWindow *window, ulong timestamp, QEvent::Type type, int key, Qt::KeyboardModifiers modifiers,
quint32 nativeScanCode, quint32 nativeVirtualKey,
quint32 nativeModifiers,
const QString& text = QString(), bool autorep = false,
ushort count = 1, bool tryShortcutOverride = true);
- static void handleWheelEvent(QWindow *w, const QPointF & local, const QPointF & global,
+ static void handleWheelEvent(QWindow *window, const QPointF &local, const QPointF &global,
QPoint pixelDelta, QPoint angleDelta,
Qt::KeyboardModifiers mods = Qt::NoModifier,
Qt::ScrollPhase phase = Qt::NoScrollPhase,
Qt::MouseEventSource source = Qt::MouseEventNotSynthesized);
- static void handleWheelEvent(QWindow *w, ulong timestamp, const QPointF & local, const QPointF & global,
+ static void handleWheelEvent(QWindow *window, ulong timestamp, const QPointF &local, const QPointF &global,
QPoint pixelDelta, QPoint angleDelta,
Qt::KeyboardModifiers mods = Qt::NoModifier,
Qt::ScrollPhase phase = Qt::NoScrollPhase,
@@ -122,8 +122,8 @@ public:
bool inverted = false);
// Wheel event compatibility functions. Will be removed: do not use.
- static void handleWheelEvent(QWindow *w, const QPointF & local, const QPointF & global, int d, Qt::Orientation o, Qt::KeyboardModifiers mods = Qt::NoModifier);
- static void handleWheelEvent(QWindow *w, ulong timestamp, const QPointF & local, const QPointF & global, int d, Qt::Orientation o, Qt::KeyboardModifiers mods = Qt::NoModifier);
+ static void handleWheelEvent(QWindow *window, const QPointF &local, const QPointF &global, int d, Qt::Orientation o, Qt::KeyboardModifiers mods = Qt::NoModifier);
+ static void handleWheelEvent(QWindow *window, ulong timestamp, const QPointF &local, const QPointF &global, int d, Qt::Orientation o, Qt::KeyboardModifiers mods = Qt::NoModifier);
struct TouchPoint {
TouchPoint() : id(0), uniqueId(-1), pressure(0), rotation(0), state(Qt::TouchPointStationary) { }
@@ -131,9 +131,11 @@ public:
qint64 uniqueId; // for TUIO: object/token ID; otherwise empty
// TODO for TUIO 2.0: add registerPointerUniqueID(QPointingDeviceUniqueId)
QPointF normalPosition; // touch device coordinates, (0 to 1, 0 to 1)
- QRectF area; // the touched area, centered at position in screen coordinates
+ QRectF area; // dimensions of the elliptical contact patch, unrotated, and centered at position in screen coordinates
+ // width is the horizontal diameter, height is the vertical diameter
qreal pressure; // 0 to 1
- qreal rotation; // 0 means pointing straight up; 0 if unknown (like QTabletEvent::rotation)
+ qreal rotation; // rotation applied to the elliptical contact patch
+ // 0 means pointing straight up; 0 if unknown (like QTabletEvent::rotation)
Qt::TouchPointState state; //Qt::TouchPoint{Pressed|Moved|Stationary|Released}
QVector2D velocity; // in screen coordinate system, pixels / seconds
QTouchEvent::TouchPoint::InfoFlags flags;
@@ -145,43 +147,43 @@ public:
static bool isTouchDeviceRegistered(const QTouchDevice *device);
template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
- static void handleTouchEvent(QWindow *w, QTouchDevice *device,
+ static void handleTouchEvent(QWindow *window, QTouchDevice *device,
const QList<struct TouchPoint> &points, Qt::KeyboardModifiers mods = Qt::NoModifier);
template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
- static void handleTouchEvent(QWindow *w, ulong timestamp, QTouchDevice *device,
+ static void handleTouchEvent(QWindow *window, ulong timestamp, QTouchDevice *device,
const QList<struct TouchPoint> &points, Qt::KeyboardModifiers mods = Qt::NoModifier);
template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
- static void handleTouchCancelEvent(QWindow *w, QTouchDevice *device, Qt::KeyboardModifiers mods = Qt::NoModifier);
+ static void handleTouchCancelEvent(QWindow *window, QTouchDevice *device, Qt::KeyboardModifiers mods = Qt::NoModifier);
template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
- static void handleTouchCancelEvent(QWindow *w, ulong timestamp, QTouchDevice *device, Qt::KeyboardModifiers mods = Qt::NoModifier);
+ static void handleTouchCancelEvent(QWindow *window, ulong timestamp, QTouchDevice *device, Qt::KeyboardModifiers mods = Qt::NoModifier);
// rect is relative to parent
template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
- static void handleGeometryChange(QWindow *w, const QRect &newRect, const QRect &oldRect = QRect());
+ static void handleGeometryChange(QWindow *window, const QRect &newRect, const QRect &oldRect = QRect());
// region is in local coordinates, do not confuse with geometry which is parent-relative
template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
- static void handleExposeEvent(QWindow *tlw, const QRegion &region);
+ static void handleExposeEvent(QWindow *window, const QRegion &region);
- static void handleCloseEvent(QWindow *w, bool *accepted = Q_NULLPTR);
+ static void handleCloseEvent(QWindow *window, bool *accepted = Q_NULLPTR);
template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
- static void handleEnterEvent(QWindow *w, const QPointF &local = QPointF(), const QPointF& global = QPointF());
+ static void handleEnterEvent(QWindow *window, const QPointF &local = QPointF(), const QPointF& global = QPointF());
template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
- static void handleLeaveEvent(QWindow *w);
+ static void handleLeaveEvent(QWindow *window);
static void handleEnterLeaveEvent(QWindow *enter, QWindow *leave, const QPointF &local = QPointF(), const QPointF& global = QPointF());
template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
- static void handleWindowActivated(QWindow *w, Qt::FocusReason r = Qt::OtherFocusReason);
+ static void handleWindowActivated(QWindow *window, Qt::FocusReason r = Qt::OtherFocusReason);
- static void handleWindowStateChanged(QWindow *w, Qt::WindowState newState);
- static void handleWindowScreenChanged(QWindow *w, QScreen *newScreen);
+ static void handleWindowStateChanged(QWindow *window, Qt::WindowState newState);
+ static void handleWindowScreenChanged(QWindow *window, QScreen *newScreen);
static void handleApplicationStateChanged(Qt::ApplicationState newState, bool forcePropagate = false);
#ifndef QT_NO_DRAGANDDROP
// Drag and drop. These events are sent immediately.
- static QPlatformDragQtResponse handleDrag(QWindow *w, const QMimeData *dropData, const QPoint &p, Qt::DropActions supportedActions);
- static QPlatformDropQtResponse handleDrop(QWindow *w, const QMimeData *dropData, const QPoint &p, Qt::DropActions supportedActions);
+ static QPlatformDragQtResponse handleDrag(QWindow *window, const QMimeData *dropData, const QPoint &p, Qt::DropActions supportedActions);
+ static QPlatformDropQtResponse handleDrop(QWindow *window, const QMimeData *dropData, const QPoint &p, Qt::DropActions supportedActions);
#endif
static bool handleNativeEvent(QWindow *window, const QByteArray &eventType, void *message, long *result);
@@ -192,24 +194,24 @@ public:
static void handleScreenLogicalDotsPerInchChange(QScreen *screen, qreal newDpiX, qreal newDpiY);
static void handleScreenRefreshRateChange(QScreen *screen, qreal newRefreshRate);
- static void handleThemeChange(QWindow *tlw);
+ static void handleThemeChange(QWindow *window);
static void handleFileOpenEvent(const QString& fileName);
static void handleFileOpenEvent(const QUrl &url);
- static void handleTabletEvent(QWindow *w, ulong timestamp, const QPointF &local, const QPointF &global,
+ static void handleTabletEvent(QWindow *window, ulong timestamp, const QPointF &local, const QPointF &global,
int device, int pointerType, Qt::MouseButtons buttons, qreal pressure, int xTilt, int yTilt,
qreal tangentialPressure, qreal rotation, int z, qint64 uid,
Qt::KeyboardModifiers modifiers = Qt::NoModifier);
- static void handleTabletEvent(QWindow *w, const QPointF &local, const QPointF &global,
+ static void handleTabletEvent(QWindow *window, const QPointF &local, const QPointF &global,
int device, int pointerType, Qt::MouseButtons buttons, qreal pressure, int xTilt, int yTilt,
qreal tangentialPressure, qreal rotation, int z, qint64 uid,
Qt::KeyboardModifiers modifiers = Qt::NoModifier);
- static void handleTabletEvent(QWindow *w, ulong timestamp, bool down, const QPointF &local, const QPointF &global,
+ static void handleTabletEvent(QWindow *window, ulong timestamp, bool down, const QPointF &local, const QPointF &global,
int device, int pointerType, qreal pressure, int xTilt, int yTilt,
qreal tangentialPressure, qreal rotation, int z, qint64 uid,
Qt::KeyboardModifiers modifiers = Qt::NoModifier); // ### remove in Qt 6
- static void handleTabletEvent(QWindow *w, bool down, const QPointF &local, const QPointF &global,
+ static void handleTabletEvent(QWindow *window, bool down, const QPointF &local, const QPointF &global,
int device, int pointerType, qreal pressure, int xTilt, int yTilt,
qreal tangentialPressure, qreal rotation, int z, qint64 uid,
Qt::KeyboardModifiers modifiers = Qt::NoModifier); // ### remove in Qt 6
@@ -227,9 +229,9 @@ public:
ulong sequenceId, quint64 value, QPointF &local, QPointF &global);
#endif // QT_NO_GESTURES
- static void handlePlatformPanelEvent(QWindow *w);
+ static void handlePlatformPanelEvent(QWindow *window);
#ifndef QT_NO_CONTEXTMENU
- static void handleContextMenuEvent(QWindow *w, bool mouseTriggered,
+ static void handleContextMenuEvent(QWindow *window, bool mouseTriggered,
const QPoint &pos, const QPoint &globalPos,
Qt::KeyboardModifiers modifiers);
#endif
diff --git a/src/gui/kernel/qwindowsysteminterface_p.h b/src/gui/kernel/qwindowsysteminterface_p.h
index 7c9b1f2852..1db60e8cb8 100644
--- a/src/gui/kernel/qwindowsysteminterface_p.h
+++ b/src/gui/kernel/qwindowsysteminterface_p.h
@@ -131,10 +131,10 @@ public:
class GeometryChangeEvent : public WindowSystemEvent {
public:
- GeometryChangeEvent(QWindow *tlw, const QRect &newGeometry, const QRect &oldGeometry)
- : WindowSystemEvent(GeometryChange), tlw(tlw), newGeometry(newGeometry), oldGeometry(oldGeometry)
+ GeometryChangeEvent(QWindow *window, const QRect &newGeometry, const QRect &oldGeometry)
+ : WindowSystemEvent(GeometryChange), window(window), newGeometry(newGeometry), oldGeometry(oldGeometry)
{ }
- QPointer<QWindow> tlw;
+ QPointer<QWindow> window;
QRect newGeometry;
QRect oldGeometry;
};
@@ -226,11 +226,11 @@ public:
class MouseEvent : public InputEvent {
public:
- MouseEvent(QWindow * w, ulong time, const QPointF & local, const QPointF & global,
+ MouseEvent(QWindow * w, ulong time, const QPointF &local, const QPointF &global,
Qt::MouseButtons b, Qt::KeyboardModifiers mods,
Qt::MouseEventSource src = Qt::MouseEventNotSynthesized)
: InputEvent(w, time, Mouse, mods), localPos(local), globalPos(global), buttons(b), source(src) { }
- MouseEvent(QWindow * w, ulong time, EventType t, const QPointF & local, const QPointF & global,
+ MouseEvent(QWindow * w, ulong time, EventType t, const QPointF &local, const QPointF &global,
Qt::MouseButtons b, Qt::KeyboardModifiers mods,
Qt::MouseEventSource src = Qt::MouseEventNotSynthesized)
: InputEvent(w, time, t, mods), localPos(local), globalPos(global), buttons(b), source(src) { }
@@ -242,7 +242,7 @@ public:
class WheelEvent : public InputEvent {
public:
- WheelEvent(QWindow *w, ulong time, const QPointF & local, const QPointF & global, QPoint pixelD, QPoint angleD, int qt4D, Qt::Orientation qt4O,
+ WheelEvent(QWindow *w, ulong time, const QPointF &local, const QPointF &global, QPoint pixelD, QPoint angleD, int qt4D, Qt::Orientation qt4O,
Qt::KeyboardModifiers mods, Qt::ScrollPhase phase = Qt::NoScrollPhase, Qt::MouseEventSource src = Qt::MouseEventNotSynthesized, bool inverted = false);
QPoint pixelDelta;
QPoint angleDelta;
@@ -494,10 +494,6 @@ public:
template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
static bool handleWindowSystemEvent(WindowSystemEvent *ev);
-private:
- static void postWindowSystemEvent(WindowSystemEvent *ev);
- static bool processWindowSystemEvent(WindowSystemEvent *ev);
-
public:
static QElapsedTimer eventTime;
static bool synchronousWindowSystemEvents;
@@ -508,7 +504,7 @@ public:
static QList<QTouchEvent::TouchPoint>
fromNativeTouchPoints(const QList<QWindowSystemInterface::TouchPoint> &points,
- const QWindow *window, QEvent::Type *type = Q_NULLPTR);
+ const QWindow *window, quint8 deviceId, QEvent::Type *type = Q_NULLPTR);
static QList<QWindowSystemInterface::TouchPoint>
toNativeTouchPoints(const QList<QTouchEvent::TouchPoint>& pointList,
const QWindow *window);
diff --git a/src/gui/opengl/opengl.pri b/src/gui/opengl/opengl.pri
index 1a1022b3a7..4c778b184e 100644
--- a/src/gui/opengl/opengl.pri
+++ b/src/gui/opengl/opengl.pri
@@ -33,7 +33,8 @@ qtConfig(opengl) {
opengl/qopengltexture_p.h \
opengl/qopengltexturehelper_p.h \
opengl/qopenglpixeltransferoptions.h \
- opengl/qopenglextrafunctions.h
+ opengl/qopenglextrafunctions.h \
+ opengl/qopenglprogrambinarycache_p.h
SOURCES += opengl/qopengl.cpp \
opengl/qopenglfunctions.cpp \
@@ -55,7 +56,8 @@ qtConfig(opengl) {
opengl/qopengltextureblitter.cpp \
opengl/qopengltexture.cpp \
opengl/qopengltexturehelper.cpp \
- opengl/qopenglpixeltransferoptions.cpp
+ opengl/qopenglpixeltransferoptions.cpp \
+ opengl/qopenglprogrambinarycache.cpp
!qtConfig(opengles2) {
HEADERS += opengl/qopenglfunctions_1_0.h \
diff --git a/src/gui/opengl/qopengl.cpp b/src/gui/opengl/qopengl.cpp
index 384cd0bd13..7e663d48bb 100644
--- a/src/gui/opengl/qopengl.cpp
+++ b/src/gui/opengl/qopengl.cpp
@@ -42,6 +42,7 @@
#include "qopenglcontext.h"
#include "qopenglfunctions.h"
+#include "qoperatingsystemversion.h"
#include "qoffscreensurface.h"
#include <QtCore/QDebug>
@@ -223,29 +224,25 @@ struct OsTypeTerm
static QString hostOsRelease() {
QString ver;
#ifdef Q_OS_WIN
- switch (QSysInfo::windowsVersion()) {
- case QSysInfo::WV_XP:
- case QSysInfo::WV_2003:
- ver = QStringLiteral("xp");
- break;
- case QSysInfo::WV_VISTA:
- ver = QStringLiteral("vista");
- break;
- case QSysInfo::WV_WINDOWS7:
+ const auto osver = QOperatingSystemVersion::current();
+#define Q_WINVER(major, minor) (major << 8 | minor)
+ switch (Q_WINVER(osver.majorVersion(), osver.minorVersion())) {
+ case Q_WINVER(6, 1):
ver = QStringLiteral("7");
break;
- case QSysInfo::WV_WINDOWS8:
+ case Q_WINVER(6, 2):
ver = QStringLiteral("8");
break;
- case QSysInfo::WV_WINDOWS8_1:
+ case Q_WINVER(6, 3):
ver = QStringLiteral("8.1");
break;
- case QSysInfo::WV_WINDOWS10:
+ case Q_WINVER(10, 0):
ver = QStringLiteral("10");
break;
default:
break;
}
+#undef Q_WINVER
#endif
return ver;
}
diff --git a/src/gui/opengl/qopengldebug.h b/src/gui/opengl/qopengldebug.h
index 74b2731f7e..6b10c36291 100644
--- a/src/gui/opengl/qopengldebug.h
+++ b/src/gui/opengl/qopengldebug.h
@@ -52,6 +52,11 @@
#include <QtCore/qdebug.h>
#include <QtGui/qopenglcontext.h>
+#if defined(Q_CLANG_QDOC)
+#undef GLuint
+typedef unsigned int GLuint;
+#endif
+
QT_BEGIN_NAMESPACE
class QOpenGLDebugLogger;
diff --git a/src/gui/opengl/qopenglengineshadermanager.cpp b/src/gui/opengl/qopenglengineshadermanager.cpp
index 1d3e47f93b..dd9e8e9d1e 100644
--- a/src/gui/opengl/qopenglengineshadermanager.cpp
+++ b/src/gui/opengl/qopenglengineshadermanager.cpp
@@ -126,11 +126,65 @@ QOpenGLEngineSharedShaders::QOpenGLEngineSharedShaders(QOpenGLContext* context)
around without having to change the order of the glsl strings. It is hoped this will
make future hard-to-find runtime bugs more obvious and generally give more solid code.
*/
- static bool snippetsPopulated = false;
- if (!snippetsPopulated) {
- const char** code = qShaderSnippets; // shortcut
+ // Check if the user has requested an OpenGL 3.2 Core Profile or higher
+ // and if so use GLSL 1.50 core shaders instead of legacy ones.
+ const QSurfaceFormat &fmt = context->format();
+ const bool isCoreProfile = fmt.profile() == QSurfaceFormat::CoreProfile && fmt.version() >= qMakePair(3,2);
+
+ const char** code = qShaderSnippets; // shortcut
+
+ if (isCoreProfile) {
+ code[MainVertexShader] = qopenglslMainVertexShader_core;
+ code[MainWithTexCoordsVertexShader] = qopenglslMainWithTexCoordsVertexShader_core;
+ code[MainWithTexCoordsAndOpacityVertexShader] = qopenglslMainWithTexCoordsAndOpacityVertexShader_core;
+
+ code[UntransformedPositionVertexShader] = qopenglslUntransformedPositionVertexShader_core;
+ code[PositionOnlyVertexShader] = qopenglslPositionOnlyVertexShader_core;
+ code[ComplexGeometryPositionOnlyVertexShader] = qopenglslComplexGeometryPositionOnlyVertexShader_core;
+ code[PositionWithPatternBrushVertexShader] = qopenglslPositionWithPatternBrushVertexShader_core;
+ code[PositionWithLinearGradientBrushVertexShader] = qopenglslPositionWithLinearGradientBrushVertexShader_core;
+ code[PositionWithConicalGradientBrushVertexShader] = qopenglslPositionWithConicalGradientBrushVertexShader_core;
+ code[PositionWithRadialGradientBrushVertexShader] = qopenglslPositionWithRadialGradientBrushVertexShader_core;
+ code[PositionWithTextureBrushVertexShader] = qopenglslPositionWithTextureBrushVertexShader_core;
+ code[AffinePositionWithPatternBrushVertexShader] = qopenglslAffinePositionWithPatternBrushVertexShader_core;
+ code[AffinePositionWithLinearGradientBrushVertexShader] = qopenglslAffinePositionWithLinearGradientBrushVertexShader_core;
+ code[AffinePositionWithConicalGradientBrushVertexShader] = qopenglslAffinePositionWithConicalGradientBrushVertexShader_core;
+ code[AffinePositionWithRadialGradientBrushVertexShader] = qopenglslAffinePositionWithRadialGradientBrushVertexShader_core;
+ code[AffinePositionWithTextureBrushVertexShader] = qopenglslAffinePositionWithTextureBrushVertexShader_core;
+
+ code[MainFragmentShader_CMO] = qopenglslMainFragmentShader_CMO_core;
+ code[MainFragmentShader_CM] = qopenglslMainFragmentShader_CM_core;
+ code[MainFragmentShader_MO] = qopenglslMainFragmentShader_MO_core;
+ code[MainFragmentShader_M] = qopenglslMainFragmentShader_M_core;
+ code[MainFragmentShader_CO] = qopenglslMainFragmentShader_CO_core;
+ code[MainFragmentShader_C] = qopenglslMainFragmentShader_C_core;
+ code[MainFragmentShader_O] = qopenglslMainFragmentShader_O_core;
+ code[MainFragmentShader] = qopenglslMainFragmentShader_core;
+ code[MainFragmentShader_ImageArrays] = qopenglslMainFragmentShader_ImageArrays_core;
+
+ code[ImageSrcFragmentShader] = qopenglslImageSrcFragmentShader_core;
+ code[ImageSrcWithPatternFragmentShader] = qopenglslImageSrcWithPatternFragmentShader_core;
+ code[NonPremultipliedImageSrcFragmentShader] = qopenglslNonPremultipliedImageSrcFragmentShader_core;
+ code[GrayscaleImageSrcFragmentShader] = qopenglslGrayscaleImageSrcFragmentShader_core;
+ code[AlphaImageSrcFragmentShader] = qopenglslAlphaImageSrcFragmentShader_core;
+ code[CustomImageSrcFragmentShader] = qopenglslCustomSrcFragmentShader_core; // Calls "customShader", which must be appended
+ code[SolidBrushSrcFragmentShader] = qopenglslSolidBrushSrcFragmentShader_core;
+
+ code[TextureBrushSrcFragmentShader] = qopenglslTextureBrushSrcFragmentShader_desktop_core;
+ code[TextureBrushSrcWithPatternFragmentShader] = qopenglslTextureBrushSrcWithPatternFragmentShader_core;
+ code[PatternBrushSrcFragmentShader] = qopenglslPatternBrushSrcFragmentShader_core;
+ code[LinearGradientBrushSrcFragmentShader] = qopenglslLinearGradientBrushSrcFragmentShader_core;
+ code[RadialGradientBrushSrcFragmentShader] = qopenglslRadialGradientBrushSrcFragmentShader_core;
+ code[ConicalGradientBrushSrcFragmentShader] = qopenglslConicalGradientBrushSrcFragmentShader_core;
+ code[ShockingPinkSrcFragmentShader] = qopenglslShockingPinkSrcFragmentShader_core;
+ code[NoMaskFragmentShader] = "";
+ code[MaskFragmentShader] = qopenglslMaskFragmentShader_core;
+ code[RgbMaskFragmentShaderPass1] = qopenglslRgbMaskFragmentShaderPass1_core;
+ code[RgbMaskFragmentShaderPass2] = qopenglslRgbMaskFragmentShaderPass2_core;
+ code[RgbMaskWithGammaFragmentShader] = ""; //###
+ } else {
code[MainVertexShader] = qopenglslMainVertexShader;
code[MainWithTexCoordsVertexShader] = qopenglslMainWithTexCoordsVertexShader;
code[MainWithTexCoordsAndOpacityVertexShader] = qopenglslMainWithTexCoordsAndOpacityVertexShader;
@@ -182,34 +236,34 @@ QOpenGLEngineSharedShaders::QOpenGLEngineSharedShaders(QOpenGLContext* context)
code[RgbMaskFragmentShaderPass1] = qopenglslRgbMaskFragmentShaderPass1;
code[RgbMaskFragmentShaderPass2] = qopenglslRgbMaskFragmentShaderPass2;
code[RgbMaskWithGammaFragmentShader] = ""; //###
+ }
- code[NoCompositionModeFragmentShader] = "";
- code[MultiplyCompositionModeFragmentShader] = ""; //###
- code[ScreenCompositionModeFragmentShader] = ""; //###
- code[OverlayCompositionModeFragmentShader] = ""; //###
- code[DarkenCompositionModeFragmentShader] = ""; //###
- code[LightenCompositionModeFragmentShader] = ""; //###
- code[ColorDodgeCompositionModeFragmentShader] = ""; //###
- code[ColorBurnCompositionModeFragmentShader] = ""; //###
- code[HardLightCompositionModeFragmentShader] = ""; //###
- code[SoftLightCompositionModeFragmentShader] = ""; //###
- code[DifferenceCompositionModeFragmentShader] = ""; //###
- code[ExclusionCompositionModeFragmentShader] = ""; //###
+ // These shaders are not implemented yet and therefore are the same
+ // for all profiles. Implementations should make a version for both
+ // profiles and put the appropriate lines in the if-statement above.
+ code[NoCompositionModeFragmentShader] = "";
+ code[MultiplyCompositionModeFragmentShader] = ""; //###
+ code[ScreenCompositionModeFragmentShader] = ""; //###
+ code[OverlayCompositionModeFragmentShader] = ""; //###
+ code[DarkenCompositionModeFragmentShader] = ""; //###
+ code[LightenCompositionModeFragmentShader] = ""; //###
+ code[ColorDodgeCompositionModeFragmentShader] = ""; //###
+ code[ColorBurnCompositionModeFragmentShader] = ""; //###
+ code[HardLightCompositionModeFragmentShader] = ""; //###
+ code[SoftLightCompositionModeFragmentShader] = ""; //###
+ code[DifferenceCompositionModeFragmentShader] = ""; //###
+ code[ExclusionCompositionModeFragmentShader] = ""; //###
#if defined(QT_DEBUG)
- // Check that all the elements have been filled:
- for (int i = 0; i < TotalSnippetCount; ++i) {
- if (Q_UNLIKELY(!qShaderSnippets[i])) {
- qFatal("Shader snippet for %s (#%d) is missing!",
- snippetNameStr(SnippetName(i)).constData(), i);
- }
+ // Check that all the elements have been filled:
+ for (int i = 0; i < TotalSnippetCount; ++i) {
+ if (Q_UNLIKELY(!qShaderSnippets[i])) {
+ qFatal("Shader snippet for %s (#%d) is missing!",
+ snippetNameStr(SnippetName(i)).constData(), i);
}
-#endif
- snippetsPopulated = true;
}
+#endif
- QOpenGLShader* fragShader;
- QOpenGLShader* vertexShader;
QByteArray vertexSource;
QByteArray fragSource;
@@ -227,19 +281,11 @@ QOpenGLEngineSharedShaders::QOpenGLEngineSharedShaders(QOpenGLContext* context)
bool inCache = simpleShaderCache.load(simpleShaderProg, context);
if (!inCache) {
- vertexShader = new QOpenGLShader(QOpenGLShader::Vertex);
- shaders.append(vertexShader);
- if (!vertexShader->compileSourceCode(vertexSource))
+ if (!simpleShaderProg->addCacheableShaderFromSourceCode(QOpenGLShader::Vertex, vertexSource))
qWarning("Vertex shader for simpleShaderProg (MainVertexShader & PositionOnlyVertexShader) failed to compile");
-
- fragShader = new QOpenGLShader(QOpenGLShader::Fragment);
- shaders.append(fragShader);
- if (!fragShader->compileSourceCode(fragSource))
+ if (!simpleShaderProg->addCacheableShaderFromSourceCode(QOpenGLShader::Fragment, fragSource))
qWarning("Fragment shader for simpleShaderProg (MainFragmentShader & ShockingPinkSrcFragmentShader) failed to compile");
- simpleShaderProg->addShader(vertexShader);
- simpleShaderProg->addShader(fragShader);
-
simpleShaderProg->bindAttributeLocation("vertexCoordsArray", QT_VERTEX_COORDS_ATTR);
simpleShaderProg->bindAttributeLocation("pmvMatrix1", QT_PMV_MATRIX_1_ATTR);
simpleShaderProg->bindAttributeLocation("pmvMatrix2", QT_PMV_MATRIX_2_ATTR);
@@ -271,19 +317,11 @@ QOpenGLEngineSharedShaders::QOpenGLEngineSharedShaders(QOpenGLContext* context)
inCache = blitShaderCache.load(blitShaderProg, context);
if (!inCache) {
- vertexShader = new QOpenGLShader(QOpenGLShader::Vertex);
- shaders.append(vertexShader);
- if (!vertexShader->compileSourceCode(vertexSource))
+ if (!blitShaderProg->addCacheableShaderFromSourceCode(QOpenGLShader::Vertex, vertexSource))
qWarning("Vertex shader for blitShaderProg (MainWithTexCoordsVertexShader & UntransformedPositionVertexShader) failed to compile");
-
- fragShader = new QOpenGLShader(QOpenGLShader::Fragment);
- shaders.append(fragShader);
- if (!fragShader->compileSourceCode(fragSource))
+ if (!blitShaderProg->addCacheableShaderFromSourceCode(QOpenGLShader::Fragment, fragSource))
qWarning("Fragment shader for blitShaderProg (MainFragmentShader & ImageSrcFragmentShader) failed to compile");
- blitShaderProg->addShader(vertexShader);
- blitShaderProg->addShader(fragShader);
-
blitShaderProg->bindAttributeLocation("textureCoordArray", QT_TEXTURE_COORDS_ATTR);
blitShaderProg->bindAttributeLocation("vertexCoordsArray", QT_VERTEX_COORDS_ATTR);
}
@@ -306,9 +344,6 @@ QOpenGLEngineSharedShaders::~QOpenGLEngineSharedShaders()
#ifdef QT_GL_SHARED_SHADER_DEBUG
qDebug(" -> ~QOpenGLEngineSharedShaders() %p for thread %p.", this, QThread::currentThread());
#endif
- qDeleteAll(shaders);
- shaders.clear();
-
qDeleteAll(cachedPrograms);
cachedPrograms.clear();
@@ -370,50 +405,37 @@ QOpenGLEngineShaderProg *QOpenGLEngineSharedShaders::findProgramInCache(const QO
bool inCache = shaderCache.load(shaderProgram.data(), QOpenGLContext::currentContext());
if (!inCache) {
-
- QScopedPointer<QOpenGLShader> fragShader(new QOpenGLShader(QOpenGLShader::Fragment));
- QByteArray description;
+ if (!shaderProgram->addCacheableShaderFromSourceCode(QOpenGLShader::Vertex, vertexSource)) {
+ QByteArray description;
#if defined(QT_DEBUG)
- // Name the shader for easier debugging
- description.append("Fragment shader: main=");
- description.append(snippetNameStr(prog.mainFragShader));
- description.append(", srcPixel=");
- description.append(snippetNameStr(prog.srcPixelFragShader));
- if (prog.compositionFragShader) {
- description.append(", composition=");
- description.append(snippetNameStr(prog.compositionFragShader));
- }
- if (prog.maskFragShader) {
- description.append(", mask=");
- description.append(snippetNameStr(prog.maskFragShader));
- }
- fragShader->setObjectName(QString::fromLatin1(description));
+ description.append("Vertex shader: main=");
+ description.append(snippetNameStr(prog.mainVertexShader));
+ description.append(", position=");
+ description.append(snippetNameStr(prog.positionVertexShader));
#endif
- if (!fragShader->compileSourceCode(fragSource)) {
qWarning("Warning: \"%s\" failed to compile!", description.constData());
break;
}
-
- QScopedPointer<QOpenGLShader> vertexShader(new QOpenGLShader(QOpenGLShader::Vertex));
+ if (!shaderProgram->addCacheableShaderFromSourceCode(QOpenGLShader::Fragment, fragSource)) {
+ QByteArray description;
#if defined(QT_DEBUG)
- // Name the shader for easier debugging
- description.clear();
- description.append("Vertex shader: main=");
- description.append(snippetNameStr(prog.mainVertexShader));
- description.append(", position=");
- description.append(snippetNameStr(prog.positionVertexShader));
- vertexShader->setObjectName(QString::fromLatin1(description));
+ description.append("Fragment shader: main=");
+ description.append(snippetNameStr(prog.mainFragShader));
+ description.append(", srcPixel=");
+ description.append(snippetNameStr(prog.srcPixelFragShader));
+ if (prog.compositionFragShader) {
+ description.append(", composition=");
+ description.append(snippetNameStr(prog.compositionFragShader));
+ }
+ if (prog.maskFragShader) {
+ description.append(", mask=");
+ description.append(snippetNameStr(prog.maskFragShader));
+ }
#endif
- if (!vertexShader->compileSourceCode(vertexSource)) {
qWarning("Warning: \"%s\" failed to compile!", description.constData());
break;
}
- shaders.append(vertexShader.data());
- shaders.append(fragShader.data());
- shaderProgram->addShader(vertexShader.take());
- shaderProgram->addShader(fragShader.take());
-
// We have to bind the vertex attribute names before the program is linked:
shaderProgram->bindAttributeLocation("vertexCoordsArray", QT_VERTEX_COORDS_ATTR);
if (prog.useTextureCoords)
@@ -436,18 +458,9 @@ QOpenGLEngineShaderProg *QOpenGLEngineSharedShaders::findProgramInCache(const QO
shaderCache.store(newProg->program, QOpenGLContext::currentContext());
} else {
QString error;
- error = QLatin1String("Shader program failed to link,");
-#if defined(QT_DEBUG)
- QLatin1String br("\n");
- error += QLatin1String("\n Shaders Used:\n");
- for (int i = 0; i < newProg->program->shaders().count(); ++i) {
- QOpenGLShader *shader = newProg->program->shaders().at(i);
- error += QLatin1String(" ") + shader->objectName() + QLatin1String(": \n")
- + QLatin1String(shader->sourceCode()) + br;
- }
-#endif
- error += QLatin1String(" Error Log:\n")
- + QLatin1String(" ") + newProg->program->log();
+ error = QLatin1String("Shader program failed to link")
+ + QLatin1String(" Error Log:\n")
+ + QLatin1String(" ") + newProg->program->log();
qWarning() << error;
break;
}
diff --git a/src/gui/opengl/qopenglengineshadermanager_p.h b/src/gui/opengl/qopenglengineshadermanager_p.h
index 23b2ccf486..377501457d 100644
--- a/src/gui/opengl/qopenglengineshadermanager_p.h
+++ b/src/gui/opengl/qopenglengineshadermanager_p.h
@@ -366,7 +366,6 @@ private:
QOpenGLShaderProgram *blitShaderProg;
QOpenGLShaderProgram *simpleShaderProg;
QList<QOpenGLEngineShaderProg*> cachedPrograms;
- QList<QOpenGLShader *> shaders;
static const char* qShaderSnippets[TotalSnippetCount];
};
diff --git a/src/gui/opengl/qopenglengineshadersource_p.h b/src/gui/opengl/qopenglengineshadersource_p.h
index 1e88ac63b5..a165643839 100644
--- a/src/gui/opengl/qopenglengineshadersource_p.h
+++ b/src/gui/opengl/qopenglengineshadersource_p.h
@@ -58,7 +58,6 @@
QT_BEGIN_NAMESPACE
-
static const char* const qopenglslMainVertexShader = "\n\
void setPosition(); \n\
void main(void) \n\
@@ -532,40 +531,498 @@ static const char* const qopenglslRgbMaskFragmentShaderPass2 = "\n\
ExclusionCompositionModeFragmentShader,
*/
-// OpenGL 3.2 core profile versions of shaders that are used by QOpenGLTextureGlyphCache
+/*
+ OpenGL 3.2+ Core Profile shaders
+ The following shader snippets are copies of the snippets above
+ but use the modern GLSL 1.5 keywords. New shaders should make
+ a snippet for both profiles and add them appropriately in the
+ shader manager.
+*/
+static const char* const qopenglslMainVertexShader_core =
+ "#version 150 core\n\
+ void setPosition(); \n\
+ void main(void) \n\
+ { \n\
+ setPosition(); \n\
+ }\n";
+
+static const char* const qopenglslMainWithTexCoordsVertexShader_core =
+ "#version 150 core\n\
+ in vec2 textureCoordArray; \n\
+ out vec2 textureCoords; \n\
+ void setPosition(); \n\
+ void main(void) \n\
+ { \n\
+ setPosition(); \n\
+ textureCoords = textureCoordArray; \n\
+ }\n";
+
+static const char* const qopenglslMainWithTexCoordsAndOpacityVertexShader_core =
+ "#version 150 core\n\
+ in vec2 textureCoordArray; \n\
+ in float opacityArray; \n\
+ out vec2 textureCoords; \n\
+ out float opacity; \n\
+ void setPosition(); \n\
+ void main(void) \n\
+ { \n\
+ setPosition(); \n\
+ textureCoords = textureCoordArray; \n\
+ opacity = opacityArray; \n\
+ }\n";
+
+// NOTE: We let GL do the perspective correction so texture lookups in the fragment
+// shader are also perspective corrected.
+static const char* const qopenglslPositionOnlyVertexShader_core = "\n\
+ in vec2 vertexCoordsArray; \n\
+ in vec3 pmvMatrix1; \n\
+ in vec3 pmvMatrix2; \n\
+ in vec3 pmvMatrix3; \n\
+ void setPosition(void) \n\
+ { \n\
+ mat3 pmvMatrix = mat3(pmvMatrix1, pmvMatrix2, pmvMatrix3); \n\
+ vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \n\
+ gl_Position = vec4(transformedPos.xy, 0.0, transformedPos.z); \n\
+ }\n";
-static const char* const qopenglslMainWithTexCoordsVertexShader_core = "#version 150 core \n\
- in vec2 textureCoordArray; \n\
- out vec2 textureCoords; \n\
- void setPosition(); \n\
- void main(void) \n\
- { \n\
- setPosition(); \n\
- textureCoords = textureCoordArray; \n\
- }\n";
+static const char* const qopenglslComplexGeometryPositionOnlyVertexShader_core = "\n\
+ in vec2 vertexCoordsArray; \n\
+ uniform mat3 matrix; \n\
+ void setPosition(void) \n\
+ { \n\
+ gl_Position = vec4(matrix * vec3(vertexCoordsArray, 1), 1);\n\
+ } \n";
static const char* const qopenglslUntransformedPositionVertexShader_core = "\n\
- in vec4 vertexCoordsArray; \n\
- void setPosition(void) \n\
- { \n\
- gl_Position = vertexCoordsArray; \n\
- }\n";
-
-static const char* const qopenglslMainFragmentShader_core = "#version 150 core \n\
- vec4 srcPixel(); \n\
- out vec4 fragColor; \n\
- void main() \n\
- { \n\
- fragColor = srcPixel(); \n\
- }\n";
+ in vec4 vertexCoordsArray; \n\
+ void setPosition(void) \n\
+ { \n\
+ gl_Position = vertexCoordsArray; \n\
+ }\n";
+
+// Pattern Brush - This assumes the texture size is 8x8 and thus, the inverted size is 0.125
+static const char* const qopenglslPositionWithPatternBrushVertexShader_core = "\n\
+ in vec2 vertexCoordsArray; \n\
+ in vec3 pmvMatrix1; \n\
+ in vec3 pmvMatrix2; \n\
+ in vec3 pmvMatrix3; \n\
+ out vec2 patternTexCoords; \n\
+ uniform vec2 halfViewportSize; \n\
+ uniform vec2 invertedTextureSize; \n\
+ uniform mat3 brushTransform; \n\
+ void setPosition(void) \n\
+ { \n\
+ mat3 pmvMatrix = mat3(pmvMatrix1, pmvMatrix2, pmvMatrix3); \n\
+ vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \n\
+ gl_Position.xy = transformedPos.xy / transformedPos.z; \n\
+ vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \n\
+ vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1.0); \n\
+ float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \n\
+ gl_Position = vec4(gl_Position.xy * invertedHTexCoordsZ, 0.0, invertedHTexCoordsZ); \n\
+ patternTexCoords.xy = (hTexCoords.xy * 0.125) * invertedHTexCoordsZ; \n\
+ }\n";
+
+static const char* const qopenglslAffinePositionWithPatternBrushVertexShader_core
+ = qopenglslPositionWithPatternBrushVertexShader_core;
+
+static const char* const qopenglslPatternBrushSrcFragmentShader_core = "\n\
+ in vec2 patternTexCoords;\n\
+ uniform sampler2D brushTexture; \n\
+ uniform vec4 patternColor; \n\
+ vec4 srcPixel() \n\
+ { \n\
+ return patternColor * (1.0 - texture(brushTexture, patternTexCoords).r); \n\
+ }\n";
+
+
+// Linear Gradient Brush
+static const char* const qopenglslPositionWithLinearGradientBrushVertexShader_core = "\n\
+ in vec2 vertexCoordsArray; \n\
+ in vec3 pmvMatrix1; \n\
+ in vec3 pmvMatrix2; \n\
+ in vec3 pmvMatrix3; \n\
+ out float index; \n\
+ uniform vec2 halfViewportSize; \n\
+ uniform vec3 linearData; \n\
+ uniform mat3 brushTransform; \n\
+ void setPosition() \n\
+ { \n\
+ mat3 pmvMatrix = mat3(pmvMatrix1, pmvMatrix2, pmvMatrix3); \n\
+ vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \n\
+ gl_Position.xy = transformedPos.xy / transformedPos.z; \n\
+ vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \n\
+ vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \n\
+ float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \n\
+ gl_Position = vec4(gl_Position.xy * invertedHTexCoordsZ, 0.0, invertedHTexCoordsZ); \n\
+ index = (dot(linearData.xy, hTexCoords.xy) * linearData.z) * invertedHTexCoordsZ; \n\
+ }\n";
+
+static const char* const qopenglslAffinePositionWithLinearGradientBrushVertexShader_core
+ = qopenglslPositionWithLinearGradientBrushVertexShader_core;
+
+static const char* const qopenglslLinearGradientBrushSrcFragmentShader_core = "\n\
+ uniform sampler2D brushTexture; \n\
+ in float index; \n\
+ vec4 srcPixel() \n\
+ { \n\
+ vec2 val = vec2(index, 0.5); \n\
+ return texture(brushTexture, val); \n\
+ }\n";
+
+
+// Conical Gradient Brush
+static const char* const qopenglslPositionWithConicalGradientBrushVertexShader_core = "\n\
+ in vec2 vertexCoordsArray; \n\
+ in vec3 pmvMatrix1; \n\
+ in vec3 pmvMatrix2; \n\
+ in vec3 pmvMatrix3; \n\
+ out vec2 A; \n\
+ uniform vec2 halfViewportSize; \n\
+ uniform mat3 brushTransform; \n\
+ void setPosition(void) \n\
+ { \n\
+ mat3 pmvMatrix = mat3(pmvMatrix1, pmvMatrix2, pmvMatrix3); \n\
+ vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \n\
+ gl_Position.xy = transformedPos.xy / transformedPos.z; \n\
+ vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \n\
+ vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \n\
+ float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \n\
+ gl_Position = vec4(gl_Position.xy * invertedHTexCoordsZ, 0.0, invertedHTexCoordsZ); \n\
+ A = hTexCoords.xy * invertedHTexCoordsZ; \n\
+ }\n";
+
+static const char* const qopenglslAffinePositionWithConicalGradientBrushVertexShader_core
+ = qopenglslPositionWithConicalGradientBrushVertexShader_core;
+
+static const char* const qopenglslConicalGradientBrushSrcFragmentShader_core = "\n\
+ #define INVERSE_2PI 0.1591549430918953358 \n\
+ in vec2 A; \n\
+ uniform sampler2D brushTexture; \n\
+ uniform float angle; \n\
+ vec4 srcPixel() \n\
+ { \n\
+ float t; \n\
+ if (abs(A.y) == abs(A.x)) \n\
+ t = (atan(-A.y + 0.002, A.x) + angle) * INVERSE_2PI; \n\
+ else \n\
+ t = (atan(-A.y, A.x) + angle) * INVERSE_2PI; \n\
+ return texture(brushTexture, vec2(t - floor(t), 0.5)); \n\
+ }\n";
+
+
+// Radial Gradient Brush
+static const char* const qopenglslPositionWithRadialGradientBrushVertexShader_core = "\n\
+ in vec2 vertexCoordsArray;\n\
+ in vec3 pmvMatrix1; \n\
+ in vec3 pmvMatrix2; \n\
+ in vec3 pmvMatrix3; \n\
+ out float b; \n\
+ out vec2 A; \n\
+ uniform vec2 halfViewportSize; \n\
+ uniform mat3 brushTransform; \n\
+ uniform vec2 fmp; \n\
+ uniform vec3 bradius; \n\
+ void setPosition(void) \n\
+ {\n\
+ mat3 pmvMatrix = mat3(pmvMatrix1, pmvMatrix2, pmvMatrix3); \n\
+ vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \n\
+ gl_Position.xy = transformedPos.xy / transformedPos.z; \n\
+ vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \n\
+ vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \n\
+ float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \n\
+ gl_Position = vec4(gl_Position.xy * invertedHTexCoordsZ, 0.0, invertedHTexCoordsZ); \n\
+ A = hTexCoords.xy * invertedHTexCoordsZ; \n\
+ b = bradius.x + 2.0 * dot(A, fmp); \n\
+ }\n";
+
+static const char* const qopenglslAffinePositionWithRadialGradientBrushVertexShader_core
+ = qopenglslPositionWithRadialGradientBrushVertexShader_core;
+
+static const char* const qopenglslRadialGradientBrushSrcFragmentShader_core = "\n\
+ in float b; \n\
+ in vec2 A; \n\
+ uniform sampler2D brushTexture; \n\
+ uniform float fmp2_m_radius2; \n\
+ uniform float inverse_2_fmp2_m_radius2; \n\
+ uniform float sqrfr; \n\
+ uniform vec3 bradius; \n\
+ \n\
+ vec4 srcPixel() \n\
+ { \n\
+ float c = sqrfr-dot(A, A); \n\
+ float det = b*b - 4.0*fmp2_m_radius2*c; \n\
+ vec4 result = vec4(0.0); \n\
+ if (det >= 0.0) { \n\
+ float detSqrt = sqrt(det); \n\
+ float w = max((-b - detSqrt) * inverse_2_fmp2_m_radius2, (-b + detSqrt) * inverse_2_fmp2_m_radius2); \n\
+ if (bradius.y + w * bradius.z >= 0.0) \n\
+ result = texture(brushTexture, vec2(w, 0.5)); \n\
+ } \n\
+ return result; \n\
+ }\n";
+
+
+// Texture Brush
+static const char* const qopenglslPositionWithTextureBrushVertexShader_core = "\n\
+ in vec2 vertexCoordsArray; \n\
+ in vec3 pmvMatrix1; \n\
+ in vec3 pmvMatrix2; \n\
+ in vec3 pmvMatrix3; \n\
+ out vec2 brushTextureCoords; \n\
+ uniform vec2 halfViewportSize; \n\
+ uniform vec2 invertedTextureSize; \n\
+ uniform mat3 brushTransform; \n\
+ \n\
+ void setPosition(void) \n\
+ { \n\
+ mat3 pmvMatrix = mat3(pmvMatrix1, pmvMatrix2, pmvMatrix3); \n\
+ vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \n\
+ gl_Position.xy = transformedPos.xy / transformedPos.z; \n\
+ vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \n\
+ vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \n\
+ float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \n\
+ gl_Position = vec4(gl_Position.xy * invertedHTexCoordsZ, 0.0, invertedHTexCoordsZ); \n\
+ brushTextureCoords.xy = (hTexCoords.xy * invertedTextureSize) * gl_Position.w; \n\
+ }\n";
+
+static const char* const qopenglslAffinePositionWithTextureBrushVertexShader_core
+ = qopenglslPositionWithTextureBrushVertexShader_core;
+
+static const char* const qopenglslTextureBrushSrcFragmentShader_desktop_core = "\n\
+ in vec2 brushTextureCoords; \n\
+ uniform sampler2D brushTexture; \n\
+ vec4 srcPixel() \n\
+ { \n\
+ return texture(brushTexture, brushTextureCoords); \n\
+ }\n";
+
+static const char* const qopenglslTextureBrushSrcWithPatternFragmentShader_core = "\n\
+ in vec2 brushTextureCoords; \n\
+ uniform vec4 patternColor; \n\
+ uniform sampler2D brushTexture; \n\
+ vec4 srcPixel() \n\
+ { \n\
+ return patternColor * (1.0 - texture(brushTexture, brushTextureCoords).r); \n\
+ }\n";
+
+// Solid Fill Brush
+static const char* const qopenglslSolidBrushSrcFragmentShader_core = "\n\
+ uniform vec4 fragmentColor; \n\
+ vec4 srcPixel() \n\
+ { \n\
+ return fragmentColor; \n\
+ }\n";
static const char* const qopenglslImageSrcFragmentShader_core = "\n\
- in vec2 textureCoords; \n\
- uniform sampler2D imageTexture; \n\
- vec4 srcPixel() \n\
- { \n"
- "return texture(imageTexture, textureCoords); \n"
- "}\n";
+ in vec2 textureCoords; \n\
+ uniform sampler2D imageTexture; \n\
+ vec4 srcPixel() \n\
+ { \n\
+ return texture(imageTexture, textureCoords); \n\
+ }\n";
+
+static const char* const qopenglslCustomSrcFragmentShader_core = "\n\
+ in vec2 textureCoords; \n\
+ uniform sampler2D imageTexture; \n\
+ vec4 srcPixel() \n\
+ { \n\
+ return customShader(imageTexture, textureCoords); \n\
+ }\n";
+
+static const char* const qopenglslImageSrcWithPatternFragmentShader_core = "\n\
+ in vec2 textureCoords; \n\
+ uniform vec4 patternColor; \n\
+ uniform sampler2D imageTexture; \n\
+ vec4 srcPixel() \n\
+ { \n\
+ return patternColor * (1.0 - texture(imageTexture, textureCoords).r); \n\
+ }\n";
+
+static const char* const qopenglslNonPremultipliedImageSrcFragmentShader_core = "\n\
+ in vec2 textureCoords; \n\
+ uniform sampler2D imageTexture; \n\
+ vec4 srcPixel() \n\
+ { \n\
+ vec4 sample = texture(imageTexture, textureCoords); \n\
+ sample.rgb = sample.rgb * sample.a; \n\
+ return sample; \n\
+ }\n";
+
+static const char* const qopenglslGrayscaleImageSrcFragmentShader_core = "\n\
+ in vec2 textureCoords; \n\
+ uniform sampler2D imageTexture; \n\
+ vec4 srcPixel() \n\
+ { \n\
+ return texture(imageTexture, textureCoords).rrra; \n\
+ }\n";
+
+static const char* const qopenglslAlphaImageSrcFragmentShader_core = "\n\
+ in vec2 textureCoords; \n\
+ uniform sampler2D imageTexture; \n\
+ vec4 srcPixel() \n\
+ { \n\
+ return vec4(0, 0, 0, texture(imageTexture, textureCoords).r); \n\
+ }\n";
+
+static const char* const qopenglslShockingPinkSrcFragmentShader_core = "\n\
+ vec4 srcPixel() \n\
+ { \n\
+ return vec4(0.98, 0.06, 0.75, 1.0); \n\
+ }\n";
+
+static const char* const qopenglslMainFragmentShader_ImageArrays_core =
+ "#version 150 core\n\
+ in float opacity; \n\
+ out vec4 fragColor; \n\
+ vec4 srcPixel(); \n\
+ void main() \n\
+ { \n\
+ fragColor = srcPixel() * opacity; \n\
+ }\n";
+
+static const char* const qopenglslMainFragmentShader_CMO_core =
+ "#version 150 core\n\
+ out vec4 fragColor; \n\
+ uniform float globalOpacity; \n\
+ vec4 srcPixel(); \n\
+ vec4 applyMask(vec4); \n\
+ vec4 compose(vec4); \n\
+ void main() \n\
+ { \n\
+ fragColor = applyMask(compose(srcPixel()*globalOpacity))); \n\
+ }\n";
+
+static const char* const qopenglslMainFragmentShader_CM_core =
+ "#version 150 core\n\
+ out vec4 fragColor; \n\
+ vec4 srcPixel(); \n\
+ vec4 applyMask(vec4); \n\
+ vec4 compose(vec4); \n\
+ void main() \n\
+ { \n\
+ fragColor = applyMask(compose(srcPixel())); \n\
+ }\n";
+
+static const char* const qopenglslMainFragmentShader_MO_core =
+ "#version 150 core\n\
+ out vec4 fragColor; \n\
+ uniform float globalOpacity; \n\
+ vec4 srcPixel(); \n\
+ vec4 applyMask(vec4); \n\
+ void main() \n\
+ { \n\
+ fragColor = applyMask(srcPixel()*globalOpacity); \n\
+ }\n";
+
+static const char* const qopenglslMainFragmentShader_M_core =
+ "#version 150 core\n\
+ out vec4 fragColor; \n\
+ vec4 srcPixel(); \n\
+ vec4 applyMask(vec4); \n\
+ void main() \n\
+ { \n\
+ fragColor = applyMask(srcPixel()); \n\
+ }\n";
+
+static const char* const qopenglslMainFragmentShader_CO_core =
+ "#version 150 core\n\
+ out vec4 fragColor; \n\
+ uniform float globalOpacity; \n\
+ vec4 srcPixel(); \n\
+ vec4 compose(vec4); \n\
+ void main() \n\
+ { \n\
+ fragColor = compose(srcPixel()*globalOpacity); \n\
+ }\n";
+
+static const char* const qopenglslMainFragmentShader_C_core =
+ "#version 150 core\n\
+ out vec4 fragColor; \n\
+ vec4 srcPixel(); \n\
+ vec4 compose(vec4); \n\
+ void main() \n\
+ { \n\
+ fragColor = compose(srcPixel()); \n\
+ }\n";
+
+static const char* const qopenglslMainFragmentShader_O_core =
+ "#version 150 core\n\
+ out vec4 fragColor; \n\
+ uniform float globalOpacity; \n\
+ vec4 srcPixel(); \n\
+ void main() \n\
+ { \n\
+ fragColor = srcPixel()*globalOpacity; \n\
+ }\n";
+
+static const char* const qopenglslMainFragmentShader_core =
+ "#version 150 core\n\
+ out vec4 fragColor; \n\
+ vec4 srcPixel(); \n\
+ void main() \n\
+ { \n\
+ fragColor = srcPixel(); \n\
+ }\n";
+
+static const char* const qopenglslMaskFragmentShader_core = "\n\
+ in vec2 textureCoords;\n\
+ uniform sampler2D maskTexture;\n\
+ vec4 applyMask(vec4 src) \n\
+ {\n\
+ vec4 mask = texture(maskTexture, textureCoords); \n\
+ return src * mask.r; \n\
+ }\n";
+
+// For source over with subpixel antialiasing, the final color is calculated per component as follows
+// (.a is alpha component, .c is red, green or blue component):
+// alpha = src.a * mask.c * opacity
+// dest.c = dest.c * (1 - alpha) + src.c * alpha
+//
+// In the first pass, calculate: dest.c = dest.c * (1 - alpha) with blend funcs: zero, 1 - source color
+// In the second pass, calculate: dest.c = dest.c + src.c * alpha with blend funcs: one, one
+//
+// If source is a solid color (src is constant), only the first pass is needed, with blend funcs: constant, 1 - source color
+
+// For source composition with subpixel antialiasing, the final color is calculated per component as follows:
+// alpha = src.a * mask.c * opacity
+// dest.c = dest.c * (1 - mask.c) + src.c * alpha
+//
+
+static const char* const qopenglslRgbMaskFragmentShaderPass1_core = "\n\
+ in vec2 textureCoords;\n\
+ uniform sampler2D maskTexture;\n\
+ vec4 applyMask(vec4 src) \n\
+ { \n\
+ vec4 mask = texture(maskTexture, textureCoords); \n\
+ return src.a * mask; \n\
+ }\n";
+
+static const char* const qopenglslRgbMaskFragmentShaderPass2_core = "\n\
+ in vec2 textureCoords;\n\
+ uniform sampler2D maskTexture;\n\
+ vec4 applyMask(vec4 src) \n\
+ { \n\
+ vec4 mask = texture(maskTexture, textureCoords); \n\
+ return src * mask; \n\
+ }\n";
+
+/*
+ Left to implement:
+ RgbMaskFragmentShader_core,
+ RgbMaskWithGammaFragmentShader_core,
+
+ MultiplyCompositionModeFragmentShader_core,
+ ScreenCompositionModeFragmentShader_core,
+ OverlayCompositionModeFragmentShader_core,
+ DarkenCompositionModeFragmentShader_core,
+ LightenCompositionModeFragmentShader_core,
+ ColorDodgeCompositionModeFragmentShader_core,
+ ColorBurnCompositionModeFragmentShader_core,
+ HardLightCompositionModeFragmentShader_core,
+ SoftLightCompositionModeFragmentShader_core,
+ DifferenceCompositionModeFragmentShader_core,
+ ExclusionCompositionModeFragmentShader_core,
+*/
QT_END_NAMESPACE
diff --git a/src/gui/opengl/qopenglfunctions.h b/src/gui/opengl/qopenglfunctions.h
index aad48571b3..f1a717f659 100644
--- a/src/gui/opengl/qopenglfunctions.h
+++ b/src/gui/opengl/qopenglfunctions.h
@@ -591,499 +591,319 @@ struct QOpenGLFunctionsPrivate
inline void QOpenGLFunctions::glBindTexture(GLenum target, GLuint texture)
{
-#ifdef QT_OPENGL_ES_2
- ::glBindTexture(target, texture);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.BindTexture(target, texture);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glBlendFunc(GLenum sfactor, GLenum dfactor)
{
-#ifdef QT_OPENGL_ES_2
- ::glBlendFunc(sfactor, dfactor);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.BlendFunc(sfactor, dfactor);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glClear(GLbitfield mask)
{
-#ifdef QT_OPENGL_ES_2
- ::glClear(mask);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.Clear(mask);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
{
-#ifdef QT_OPENGL_ES_2
- ::glClearColor(red, green, blue, alpha);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.ClearColor(red, green, blue, alpha);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glClearStencil(GLint s)
{
-#ifdef QT_OPENGL_ES_2
- ::glClearStencil(s);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.ClearStencil(s);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
{
-#ifdef QT_OPENGL_ES_2
- ::glColorMask(red, green, blue, alpha);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.ColorMask(red, green, blue, alpha);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
{
-#ifdef QT_OPENGL_ES_2
- ::glCopyTexImage2D(target, level, internalformat, x, y, width,height, border);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.CopyTexImage2D(target, level, internalformat, x, y, width,height, border);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
{
-#ifdef QT_OPENGL_ES_2
- ::glCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.CopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glCullFace(GLenum mode)
{
-#ifdef QT_OPENGL_ES_2
- ::glCullFace(mode);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.CullFace(mode);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glDeleteTextures(GLsizei n, const GLuint* textures)
{
-#ifdef QT_OPENGL_ES_2
- ::glDeleteTextures(n, textures);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.DeleteTextures(n, textures);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glDepthFunc(GLenum func)
{
-#ifdef QT_OPENGL_ES_2
- ::glDepthFunc(func);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.DepthFunc(func);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glDepthMask(GLboolean flag)
{
-#ifdef QT_OPENGL_ES_2
- ::glDepthMask(flag);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.DepthMask(flag);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glDisable(GLenum cap)
{
-#ifdef QT_OPENGL_ES_2
- ::glDisable(cap);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.Disable(cap);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glDrawArrays(GLenum mode, GLint first, GLsizei count)
{
-#ifdef QT_OPENGL_ES_2
- ::glDrawArrays(mode, first, count);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.DrawArrays(mode, first, count);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices)
{
-#ifdef QT_OPENGL_ES_2
- ::glDrawElements(mode, count, type, indices);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.DrawElements(mode, count, type, indices);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glEnable(GLenum cap)
{
-#ifdef QT_OPENGL_ES_2
- ::glEnable(cap);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.Enable(cap);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glFinish()
{
-#ifdef QT_OPENGL_ES_2
- ::glFinish();
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.Finish();
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glFlush()
{
-#ifdef QT_OPENGL_ES_2
- ::glFlush();
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.Flush();
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glFrontFace(GLenum mode)
{
-#ifdef QT_OPENGL_ES_2
- ::glFrontFace(mode);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.FrontFace(mode);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glGenTextures(GLsizei n, GLuint* textures)
{
-#ifdef QT_OPENGL_ES_2
- ::glGenTextures(n, textures);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.GenTextures(n, textures);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glGetBooleanv(GLenum pname, GLboolean* params)
{
-#ifdef QT_OPENGL_ES_2
- ::glGetBooleanv(pname, params);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.GetBooleanv(pname, params);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline GLenum QOpenGLFunctions::glGetError()
{
-#ifdef QT_OPENGL_ES_2
- GLenum result = ::glGetError();
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
GLenum result = d_ptr->f.GetError();
-#endif
return result;
}
inline void QOpenGLFunctions::glGetFloatv(GLenum pname, GLfloat* params)
{
-#ifdef QT_OPENGL_ES_2
- ::glGetFloatv(pname, params);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.GetFloatv(pname, params);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glGetIntegerv(GLenum pname, GLint* params)
{
-#ifdef QT_OPENGL_ES_2
- ::glGetIntegerv(pname, params);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.GetIntegerv(pname, params);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline const GLubyte *QOpenGLFunctions::glGetString(GLenum name)
{
-#ifdef QT_OPENGL_ES_2
- const GLubyte *result = ::glGetString(name);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
const GLubyte *result = d_ptr->f.GetString(name);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
return result;
}
inline void QOpenGLFunctions::glGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
{
-#ifdef QT_OPENGL_ES_2
- ::glGetTexParameterfv(target, pname, params);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.GetTexParameterfv(target, pname, params);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glGetTexParameteriv(GLenum target, GLenum pname, GLint* params)
{
-#ifdef QT_OPENGL_ES_2
- ::glGetTexParameteriv(target, pname, params);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.GetTexParameteriv(target, pname, params);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glHint(GLenum target, GLenum mode)
{
-#ifdef QT_OPENGL_ES_2
- ::glHint(target, mode);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.Hint(target, mode);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline GLboolean QOpenGLFunctions::glIsEnabled(GLenum cap)
{
-#ifdef QT_OPENGL_ES_2
- GLboolean result = ::glIsEnabled(cap);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
GLboolean result = d_ptr->f.IsEnabled(cap);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
return result;
}
inline GLboolean QOpenGLFunctions::glIsTexture(GLuint texture)
{
-#ifdef QT_OPENGL_ES_2
- GLboolean result = ::glIsTexture(texture);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
GLboolean result = d_ptr->f.IsTexture(texture);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
return result;
}
inline void QOpenGLFunctions::glLineWidth(GLfloat width)
{
-#ifdef QT_OPENGL_ES_2
- ::glLineWidth(width);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.LineWidth(width);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glPixelStorei(GLenum pname, GLint param)
{
-#ifdef QT_OPENGL_ES_2
- ::glPixelStorei(pname, param);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.PixelStorei(pname, param);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glPolygonOffset(GLfloat factor, GLfloat units)
{
-#ifdef QT_OPENGL_ES_2
- ::glPolygonOffset(factor, units);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.PolygonOffset(factor, units);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid* pixels)
{
-#ifdef QT_OPENGL_ES_2
- ::glReadPixels(x, y, width, height, format, type, pixels);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.ReadPixels(x, y, width, height, format, type, pixels);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
{
-#ifdef QT_OPENGL_ES_2
- ::glScissor(x, y, width, height);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.Scissor(x, y, width, height);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glStencilFunc(GLenum func, GLint ref, GLuint mask)
{
-#ifdef QT_OPENGL_ES_2
- ::glStencilFunc(func, ref, mask);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.StencilFunc(func, ref, mask);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glStencilMask(GLuint mask)
{
-#ifdef QT_OPENGL_ES_2
- ::glStencilMask(mask);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.StencilMask(mask);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
{
-#ifdef QT_OPENGL_ES_2
- ::glStencilOp(fail, zfail, zpass);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.StencilOp(fail, zfail, zpass);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
{
-#ifdef QT_OPENGL_ES_2
- ::glTexImage2D(target, level, internalformat, width,height, border, format, type, pixels);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.TexImage2D(target, level, internalformat, width,height, border, format, type, pixels);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glTexParameterf(GLenum target, GLenum pname, GLfloat param)
{
-#ifdef QT_OPENGL_ES_2
- ::glTexParameterf(target, pname, param);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.TexParameterf(target, pname, param);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
{
-#ifdef QT_OPENGL_ES_2
- ::glTexParameterfv(target, pname, params);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.TexParameterfv(target, pname, params);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glTexParameteri(GLenum target, GLenum pname, GLint param)
{
-#ifdef QT_OPENGL_ES_2
- ::glTexParameteri(target, pname, param);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.TexParameteri(target, pname, param);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glTexParameteriv(GLenum target, GLenum pname, const GLint* params)
{
-#ifdef QT_OPENGL_ES_2
- ::glTexParameteriv(target, pname, params);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.TexParameteriv(target, pname, params);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid* pixels)
{
-#ifdef QT_OPENGL_ES_2
- ::glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.TexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
{
-#ifdef QT_OPENGL_ES_2
- ::glViewport(x, y, width, height);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.Viewport(x, y, width, height);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
@@ -1091,45 +911,29 @@ inline void QOpenGLFunctions::glViewport(GLint x, GLint y, GLsizei width, GLsize
inline void QOpenGLFunctions::glActiveTexture(GLenum texture)
{
-#ifdef QT_OPENGL_ES_2
- ::glActiveTexture(texture);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.ActiveTexture(texture);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glAttachShader(GLuint program, GLuint shader)
{
-#ifdef QT_OPENGL_ES_2
- ::glAttachShader(program, shader);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.AttachShader(program, shader);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glBindAttribLocation(GLuint program, GLuint index, const char* name)
{
-#ifdef QT_OPENGL_ES_2
- ::glBindAttribLocation(program, index, name);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.BindAttribLocation(program, index, name);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glBindBuffer(GLenum target, GLuint buffer)
{
-#ifdef QT_OPENGL_ES_2
- ::glBindBuffer(target, buffer);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.BindBuffer(target, buffer);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
@@ -1137,1034 +941,662 @@ inline void QOpenGLFunctions::glBindFramebuffer(GLenum target, GLuint framebuffe
{
if (framebuffer == 0)
framebuffer = QOpenGLContext::currentContext()->defaultFramebufferObject();
-#ifdef QT_OPENGL_ES_2
- ::glBindFramebuffer(target, framebuffer);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.BindFramebuffer(target, framebuffer);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glBindRenderbuffer(GLenum target, GLuint renderbuffer)
{
-#ifdef QT_OPENGL_ES_2
- ::glBindRenderbuffer(target, renderbuffer);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.BindRenderbuffer(target, renderbuffer);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
{
-#ifdef QT_OPENGL_ES_2
- ::glBlendColor(red, green, blue, alpha);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.BlendColor(red, green, blue, alpha);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glBlendEquation(GLenum mode)
{
-#ifdef QT_OPENGL_ES_2
- ::glBlendEquation(mode);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.BlendEquation(mode);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
{
-#ifdef QT_OPENGL_ES_2
- ::glBlendEquationSeparate(modeRGB, modeAlpha);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.BlendEquationSeparate(modeRGB, modeAlpha);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
{
-#ifdef QT_OPENGL_ES_2
- ::glBlendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.BlendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glBufferData(GLenum target, qopengl_GLsizeiptr size, const void* data, GLenum usage)
{
-#ifdef QT_OPENGL_ES_2
- ::glBufferData(target, size, data, usage);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.BufferData(target, size, data, usage);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glBufferSubData(GLenum target, qopengl_GLintptr offset, qopengl_GLsizeiptr size, const void* data)
{
-#ifdef QT_OPENGL_ES_2
- ::glBufferSubData(target, offset, size, data);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.BufferSubData(target, offset, size, data);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline GLenum QOpenGLFunctions::glCheckFramebufferStatus(GLenum target)
{
-#ifdef QT_OPENGL_ES_2
- GLenum result = ::glCheckFramebufferStatus(target);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
GLenum result = d_ptr->f.CheckFramebufferStatus(target);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
return result;
}
inline void QOpenGLFunctions::glClearDepthf(GLclampf depth)
{
-#ifndef QT_OPENGL_ES
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.ClearDepthf(depth);
-#else
- ::glClearDepthf(depth);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glCompileShader(GLuint shader)
{
-#ifdef QT_OPENGL_ES_2
- ::glCompileShader(shader);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.CompileShader(shader);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void* data)
{
-#ifdef QT_OPENGL_ES_2
- ::glCompressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.CompressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void* data)
{
-#ifdef QT_OPENGL_ES_2
- ::glCompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize, data);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.CompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize, data);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline GLuint QOpenGLFunctions::glCreateProgram()
{
-#ifdef QT_OPENGL_ES_2
- GLuint result = ::glCreateProgram();
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
GLuint result = d_ptr->f.CreateProgram();
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
return result;
}
inline GLuint QOpenGLFunctions::glCreateShader(GLenum type)
{
-#ifdef QT_OPENGL_ES_2
- GLuint result = ::glCreateShader(type);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
GLuint result = d_ptr->f.CreateShader(type);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
return result;
}
inline void QOpenGLFunctions::glDeleteBuffers(GLsizei n, const GLuint* buffers)
{
-#ifdef QT_OPENGL_ES_2
- ::glDeleteBuffers(n, buffers);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.DeleteBuffers(n, buffers);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
{
-#ifdef QT_OPENGL_ES_2
- ::glDeleteFramebuffers(n, framebuffers);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.DeleteFramebuffers(n, framebuffers);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glDeleteProgram(GLuint program)
{
-#ifdef QT_OPENGL_ES_2
- ::glDeleteProgram(program);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.DeleteProgram(program);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
{
-#ifdef QT_OPENGL_ES_2
- ::glDeleteRenderbuffers(n, renderbuffers);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.DeleteRenderbuffers(n, renderbuffers);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glDeleteShader(GLuint shader)
{
-#ifdef QT_OPENGL_ES_2
- ::glDeleteShader(shader);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.DeleteShader(shader);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glDepthRangef(GLclampf zNear, GLclampf zFar)
{
-#ifndef QT_OPENGL_ES
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.DepthRangef(zNear, zFar);
-#else
- ::glDepthRangef(zNear, zFar);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glDetachShader(GLuint program, GLuint shader)
{
-#ifdef QT_OPENGL_ES_2
- ::glDetachShader(program, shader);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.DetachShader(program, shader);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glDisableVertexAttribArray(GLuint index)
{
-#ifdef QT_OPENGL_ES_2
- ::glDisableVertexAttribArray(index);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.DisableVertexAttribArray(index);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glEnableVertexAttribArray(GLuint index)
{
-#ifdef QT_OPENGL_ES_2
- ::glEnableVertexAttribArray(index);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.EnableVertexAttribArray(index);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
{
-#ifdef QT_OPENGL_ES_2
- ::glFramebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.FramebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
{
-#ifdef QT_OPENGL_ES_2
- ::glFramebufferTexture2D(target, attachment, textarget, texture, level);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.FramebufferTexture2D(target, attachment, textarget, texture, level);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glGenBuffers(GLsizei n, GLuint* buffers)
{
-#ifdef QT_OPENGL_ES_2
- ::glGenBuffers(n, buffers);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.GenBuffers(n, buffers);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glGenerateMipmap(GLenum target)
{
-#ifdef QT_OPENGL_ES_2
- ::glGenerateMipmap(target);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.GenerateMipmap(target);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glGenFramebuffers(GLsizei n, GLuint* framebuffers)
{
-#ifdef QT_OPENGL_ES_2
- ::glGenFramebuffers(n, framebuffers);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.GenFramebuffers(n, framebuffers);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glGenRenderbuffers(GLsizei n, GLuint* renderbuffers)
{
-#ifdef QT_OPENGL_ES_2
- ::glGenRenderbuffers(n, renderbuffers);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.GenRenderbuffers(n, renderbuffers);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, char* name)
{
-#ifdef QT_OPENGL_ES_2
- ::glGetActiveAttrib(program, index, bufsize, length, size, type, name);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.GetActiveAttrib(program, index, bufsize, length, size, type, name);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, char* name)
{
-#ifdef QT_OPENGL_ES_2
- ::glGetActiveUniform(program, index, bufsize, length, size, type, name);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.GetActiveUniform(program, index, bufsize, length, size, type, name);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders)
{
-#ifdef QT_OPENGL_ES_2
- ::glGetAttachedShaders(program, maxcount, count, shaders);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.GetAttachedShaders(program, maxcount, count, shaders);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline GLint QOpenGLFunctions::glGetAttribLocation(GLuint program, const char* name)
{
-#ifdef QT_OPENGL_ES_2
- GLint result = ::glGetAttribLocation(program, name);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
GLint result = d_ptr->f.GetAttribLocation(program, name);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
return result;
}
inline void QOpenGLFunctions::glGetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
{
-#ifdef QT_OPENGL_ES_2
- ::glGetBufferParameteriv(target, pname, params);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.GetBufferParameteriv(target, pname, params);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
{
-#ifdef QT_OPENGL_ES_2
- ::glGetFramebufferAttachmentParameteriv(target, attachment, pname, params);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.GetFramebufferAttachmentParameteriv(target, attachment, pname, params);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glGetProgramiv(GLuint program, GLenum pname, GLint* params)
{
-#ifdef QT_OPENGL_ES_2
- ::glGetProgramiv(program, pname, params);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.GetProgramiv(program, pname, params);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, char* infolog)
{
-#ifdef QT_OPENGL_ES_2
- ::glGetProgramInfoLog(program, bufsize, length, infolog);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.GetProgramInfoLog(program, bufsize, length, infolog);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
{
-#ifdef QT_OPENGL_ES_2
- ::glGetRenderbufferParameteriv(target, pname, params);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.GetRenderbufferParameteriv(target, pname, params);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glGetShaderiv(GLuint shader, GLenum pname, GLint* params)
{
-#ifdef QT_OPENGL_ES_2
- ::glGetShaderiv(shader, pname, params);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.GetShaderiv(shader, pname, params);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, char* infolog)
{
-#ifdef QT_OPENGL_ES_2
- ::glGetShaderInfoLog(shader, bufsize, length, infolog);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.GetShaderInfoLog(shader, bufsize, length, infolog);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
{
-#ifdef QT_OPENGL_ES_2
- ::glGetShaderPrecisionFormat(shadertype, precisiontype, range, precision);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.GetShaderPrecisionFormat(shadertype, precisiontype, range, precision);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, char* source)
{
-#ifdef QT_OPENGL_ES_2
- ::glGetShaderSource(shader, bufsize, length, source);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.GetShaderSource(shader, bufsize, length, source);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glGetUniformfv(GLuint program, GLint location, GLfloat* params)
{
-#ifdef QT_OPENGL_ES_2
- ::glGetUniformfv(program, location, params);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.GetUniformfv(program, location, params);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glGetUniformiv(GLuint program, GLint location, GLint* params)
{
-#ifdef QT_OPENGL_ES_2
- ::glGetUniformiv(program, location, params);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.GetUniformiv(program, location, params);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline GLint QOpenGLFunctions::glGetUniformLocation(GLuint program, const char* name)
{
-#ifdef QT_OPENGL_ES_2
- GLint result = ::glGetUniformLocation(program, name);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
GLint result = d_ptr->f.GetUniformLocation(program, name);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
return result;
}
inline void QOpenGLFunctions::glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
{
-#ifdef QT_OPENGL_ES_2
- ::glGetVertexAttribfv(index, pname, params);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.GetVertexAttribfv(index, pname, params);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
{
-#ifdef QT_OPENGL_ES_2
- ::glGetVertexAttribiv(index, pname, params);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.GetVertexAttribiv(index, pname, params);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glGetVertexAttribPointerv(GLuint index, GLenum pname, void** pointer)
{
-#ifdef QT_OPENGL_ES_2
- ::glGetVertexAttribPointerv(index, pname, pointer);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.GetVertexAttribPointerv(index, pname, pointer);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline GLboolean QOpenGLFunctions::glIsBuffer(GLuint buffer)
{
-#ifdef QT_OPENGL_ES_2
- GLboolean result = ::glIsBuffer(buffer);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
GLboolean result = d_ptr->f.IsBuffer(buffer);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
return result;
}
inline GLboolean QOpenGLFunctions::glIsFramebuffer(GLuint framebuffer)
{
-#ifdef QT_OPENGL_ES_2
- GLboolean result = ::glIsFramebuffer(framebuffer);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
GLboolean result = d_ptr->f.IsFramebuffer(framebuffer);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
return result;
}
inline GLboolean QOpenGLFunctions::glIsProgram(GLuint program)
{
-#ifdef QT_OPENGL_ES_2
- GLboolean result = ::glIsProgram(program);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
GLboolean result = d_ptr->f.IsProgram(program);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
return result;
}
inline GLboolean QOpenGLFunctions::glIsRenderbuffer(GLuint renderbuffer)
{
-#ifdef QT_OPENGL_ES_2
- GLboolean result = ::glIsRenderbuffer(renderbuffer);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
GLboolean result = d_ptr->f.IsRenderbuffer(renderbuffer);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
return result;
}
inline GLboolean QOpenGLFunctions::glIsShader(GLuint shader)
{
-#ifdef QT_OPENGL_ES_2
- GLboolean result = ::glIsShader(shader);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
GLboolean result = d_ptr->f.IsShader(shader);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
return result;
}
inline void QOpenGLFunctions::glLinkProgram(GLuint program)
{
-#ifdef QT_OPENGL_ES_2
- ::glLinkProgram(program);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.LinkProgram(program);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glReleaseShaderCompiler()
{
-#ifdef QT_OPENGL_ES_2
- ::glReleaseShaderCompiler();
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.ReleaseShaderCompiler();
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
{
-#ifdef QT_OPENGL_ES_2
- ::glRenderbufferStorage(target, internalformat, width, height);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.RenderbufferStorage(target, internalformat, width, height);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glSampleCoverage(GLclampf value, GLboolean invert)
{
-#ifdef QT_OPENGL_ES_2
- ::glSampleCoverage(value, invert);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.SampleCoverage(value, invert);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glShaderBinary(GLint n, const GLuint* shaders, GLenum binaryformat, const void* binary, GLint length)
{
-#ifdef QT_OPENGL_ES_2
- ::glShaderBinary(n, shaders, binaryformat, binary, length);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.ShaderBinary(n, shaders, binaryformat, binary, length);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glShaderSource(GLuint shader, GLsizei count, const char** string, const GLint* length)
{
-#ifdef QT_OPENGL_ES_2
- ::glShaderSource(shader, count, string, length);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.ShaderSource(shader, count, string, length);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
{
-#ifdef QT_OPENGL_ES_2
- ::glStencilFuncSeparate(face, func, ref, mask);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.StencilFuncSeparate(face, func, ref, mask);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glStencilMaskSeparate(GLenum face, GLuint mask)
{
-#ifdef QT_OPENGL_ES_2
- ::glStencilMaskSeparate(face, mask);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.StencilMaskSeparate(face, mask);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
{
-#ifdef QT_OPENGL_ES_2
- ::glStencilOpSeparate(face, fail, zfail, zpass);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.StencilOpSeparate(face, fail, zfail, zpass);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glUniform1f(GLint location, GLfloat x)
{
-#ifdef QT_OPENGL_ES_2
- ::glUniform1f(location, x);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.Uniform1f(location, x);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glUniform1fv(GLint location, GLsizei count, const GLfloat* v)
{
-#ifdef QT_OPENGL_ES_2
- ::glUniform1fv(location, count, v);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.Uniform1fv(location, count, v);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glUniform1i(GLint location, GLint x)
{
-#ifdef QT_OPENGL_ES_2
- ::glUniform1i(location, x);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.Uniform1i(location, x);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glUniform1iv(GLint location, GLsizei count, const GLint* v)
{
-#ifdef QT_OPENGL_ES_2
- ::glUniform1iv(location, count, v);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.Uniform1iv(location, count, v);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glUniform2f(GLint location, GLfloat x, GLfloat y)
{
-#ifdef QT_OPENGL_ES_2
- ::glUniform2f(location, x, y);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.Uniform2f(location, x, y);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glUniform2fv(GLint location, GLsizei count, const GLfloat* v)
{
-#ifdef QT_OPENGL_ES_2
- ::glUniform2fv(location, count, v);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.Uniform2fv(location, count, v);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glUniform2i(GLint location, GLint x, GLint y)
{
-#ifdef QT_OPENGL_ES_2
- ::glUniform2i(location, x, y);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.Uniform2i(location, x, y);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glUniform2iv(GLint location, GLsizei count, const GLint* v)
{
-#ifdef QT_OPENGL_ES_2
- ::glUniform2iv(location, count, v);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.Uniform2iv(location, count, v);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
{
-#ifdef QT_OPENGL_ES_2
- ::glUniform3f(location, x, y, z);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.Uniform3f(location, x, y, z);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glUniform3fv(GLint location, GLsizei count, const GLfloat* v)
{
-#ifdef QT_OPENGL_ES_2
- ::glUniform3fv(location, count, v);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.Uniform3fv(location, count, v);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glUniform3i(GLint location, GLint x, GLint y, GLint z)
{
-#ifdef QT_OPENGL_ES_2
- ::glUniform3i(location, x, y, z);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.Uniform3i(location, x, y, z);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glUniform3iv(GLint location, GLsizei count, const GLint* v)
{
-#ifdef QT_OPENGL_ES_2
- ::glUniform3iv(location, count, v);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.Uniform3iv(location, count, v);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
{
-#ifdef QT_OPENGL_ES_2
- ::glUniform4f(location, x, y, z, w);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.Uniform4f(location, x, y, z, w);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glUniform4fv(GLint location, GLsizei count, const GLfloat* v)
{
-#ifdef QT_OPENGL_ES_2
- ::glUniform4fv(location, count, v);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.Uniform4fv(location, count, v);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
{
-#ifdef QT_OPENGL_ES_2
- ::glUniform4i(location, x, y, z, w);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.Uniform4i(location, x, y, z, w);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glUniform4iv(GLint location, GLsizei count, const GLint* v)
{
-#ifdef QT_OPENGL_ES_2
- ::glUniform4iv(location, count, v);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.Uniform4iv(location, count, v);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
{
-#ifdef QT_OPENGL_ES_2
- ::glUniformMatrix2fv(location, count, transpose, value);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.UniformMatrix2fv(location, count, transpose, value);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
{
-#ifdef QT_OPENGL_ES_2
- ::glUniformMatrix3fv(location, count, transpose, value);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.UniformMatrix3fv(location, count, transpose, value);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
{
-#ifdef QT_OPENGL_ES_2
- ::glUniformMatrix4fv(location, count, transpose, value);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.UniformMatrix4fv(location, count, transpose, value);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glUseProgram(GLuint program)
{
-#ifdef QT_OPENGL_ES_2
- ::glUseProgram(program);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.UseProgram(program);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glValidateProgram(GLuint program)
{
-#ifdef QT_OPENGL_ES_2
- ::glValidateProgram(program);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.ValidateProgram(program);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glVertexAttrib1f(GLuint indx, GLfloat x)
{
-#ifdef QT_OPENGL_ES_2
- ::glVertexAttrib1f(indx, x);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.VertexAttrib1f(indx, x);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glVertexAttrib1fv(GLuint indx, const GLfloat* values)
{
-#ifdef QT_OPENGL_ES_2
- ::glVertexAttrib1fv(indx, values);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.VertexAttrib1fv(indx, values);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glVertexAttrib2f(GLuint indx, GLfloat x, GLfloat y)
{
-#ifdef QT_OPENGL_ES_2
- ::glVertexAttrib2f(indx, x, y);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.VertexAttrib2f(indx, x, y);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glVertexAttrib2fv(GLuint indx, const GLfloat* values)
{
-#ifdef QT_OPENGL_ES_2
- ::glVertexAttrib2fv(indx, values);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.VertexAttrib2fv(indx, values);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glVertexAttrib3f(GLuint indx, GLfloat x, GLfloat y, GLfloat z)
{
-#ifdef QT_OPENGL_ES_2
- ::glVertexAttrib3f(indx, x, y, z);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.VertexAttrib3f(indx, x, y, z);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glVertexAttrib3fv(GLuint indx, const GLfloat* values)
{
-#ifdef QT_OPENGL_ES_2
- ::glVertexAttrib3fv(indx, values);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.VertexAttrib3fv(indx, values);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glVertexAttrib4f(GLuint indx, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
{
-#ifdef QT_OPENGL_ES_2
- ::glVertexAttrib4f(indx, x, y, z, w);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.VertexAttrib4f(indx, x, y, z, w);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glVertexAttrib4fv(GLuint indx, const GLfloat* values)
{
-#ifdef QT_OPENGL_ES_2
- ::glVertexAttrib4fv(indx, values);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.VertexAttrib4fv(indx, values);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
inline void QOpenGLFunctions::glVertexAttribPointer(GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void* ptr)
{
-#ifdef QT_OPENGL_ES_2
- ::glVertexAttribPointer(indx, size, type, normalized, stride, ptr);
-#else
Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->f.VertexAttribPointer(indx, size, type, normalized, stride, ptr);
-#endif
Q_OPENGL_FUNCTIONS_DEBUG
}
diff --git a/src/gui/opengl/qopenglpaintengine.cpp b/src/gui/opengl/qopenglpaintengine.cpp
index 90652a5ab8..aeb4fc0b7a 100644
--- a/src/gui/opengl/qopenglpaintengine.cpp
+++ b/src/gui/opengl/qopenglpaintengine.cpp
@@ -99,6 +99,12 @@ QOpenGL2PaintEngineExPrivate::~QOpenGL2PaintEngineExPrivate()
{
delete shaderManager;
+ vertexBuffer.destroy();
+ texCoordBuffer.destroy();
+ opacityBuffer.destroy();
+ indexBuffer.destroy();
+ vao.destroy();
+
if (elementIndicesVBOId != 0) {
funcs.glDeleteBuffers(1, &elementIndicesVBOId);
elementIndicesVBOId = 0;
@@ -578,6 +584,12 @@ void QOpenGL2PaintEngineExPrivate::drawTexture(const QOpenGLRect& dest, const QO
setCoords(staticVertexCoordinateArray, dest);
setCoords(staticTextureCoordinateArray, srcTextureRect);
+ setVertexAttribArrayEnabled(QT_VERTEX_COORDS_ATTR, true);
+ setVertexAttribArrayEnabled(QT_TEXTURE_COORDS_ATTR, true);
+
+ uploadData(QT_VERTEX_COORDS_ATTR, staticVertexCoordinateArray, 8);
+ uploadData(QT_TEXTURE_COORDS_ATTR, staticTextureCoordinateArray, 8);
+
funcs.glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
}
@@ -664,6 +676,11 @@ void QOpenGL2PaintEngineExPrivate::resetGLState()
float color[] = { 1.0f, 1.0f, 1.0f, 1.0f };
funcs.glVertexAttrib4fv(3, color);
}
+ if (vao.isCreated()) {
+ vao.release();
+ funcs.glBindBuffer(GL_ARRAY_BUFFER, 0);
+ funcs.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
+ }
}
void QOpenGL2PaintEngineEx::endNativePainting()
@@ -696,16 +713,16 @@ void QOpenGL2PaintEngineExPrivate::transferMode(EngineMode newMode)
}
if (newMode == ImageDrawingMode) {
- setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, staticVertexCoordinateArray);
- setVertexAttributePointer(QT_TEXTURE_COORDS_ATTR, staticTextureCoordinateArray);
+ uploadData(QT_VERTEX_COORDS_ATTR, staticVertexCoordinateArray, 8);
+ uploadData(QT_TEXTURE_COORDS_ATTR, staticTextureCoordinateArray, 8);
}
if (newMode == ImageArrayDrawingMode || newMode == ImageOpacityArrayDrawingMode) {
- setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, (GLfloat*)vertexCoordinateArray.data());
- setVertexAttributePointer(QT_TEXTURE_COORDS_ATTR, (GLfloat*)textureCoordinateArray.data());
+ uploadData(QT_VERTEX_COORDS_ATTR, (GLfloat*)vertexCoordinateArray.data(), vertexCoordinateArray.vertexCount() * 2);
+ uploadData(QT_TEXTURE_COORDS_ATTR, (GLfloat*)textureCoordinateArray.data(), textureCoordinateArray.vertexCount() * 2);
if (newMode == ImageOpacityArrayDrawingMode)
- setVertexAttributePointer(QT_OPACITY_ATTR, (GLfloat*)opacityArray.data());
+ uploadData(QT_OPACITY_ATTR, (GLfloat*)opacityArray.data(), opacityArray.size());
}
// This needs to change when we implement high-quality anti-aliasing...
@@ -761,6 +778,8 @@ void QOpenGL2PaintEngineExPrivate::fill(const QVectorPath& path)
if (matrixDirty)
updateMatrix();
+ const bool supportsElementIndexUint = funcs.hasOpenGLExtension(QOpenGLExtensions::ElementIndexUint);
+
const QPointF* const points = reinterpret_cast<const QPointF*>(path.points());
// Check to see if there's any hints
@@ -824,9 +843,10 @@ void QOpenGL2PaintEngineExPrivate::fill(const QVectorPath& path)
prepareForDraw(currentBrush.isOpaque());
#ifdef QT_OPENGL_CACHE_AS_VBOS
funcs.glBindBuffer(GL_ARRAY_BUFFER, cache->vbo);
+ uploadData(QT_VERTEX_COORD_ATTR, 0, cache->vertexCount);
setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, 0);
#else
- setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, cache->vertices);
+ uploadData(QT_VERTEX_COORDS_ATTR, cache->vertices, cache->vertexCount * 2);
#endif
funcs.glDrawArrays(cache->primitiveType, 0, cache->vertexCount);
@@ -881,7 +901,7 @@ void QOpenGL2PaintEngineExPrivate::fill(const QVectorPath& path)
// Flatten the path at the current scale factor and fill it into the cache struct.
if (updateCache) {
- QTriangleSet polys = qTriangulate(path, QTransform().scale(1 / inverseScale, 1 / inverseScale));
+ QTriangleSet polys = qTriangulate(path, QTransform().scale(1 / inverseScale, 1 / inverseScale), 1, supportsElementIndexUint);
cache->vertexCount = polys.vertices.size() / 2;
cache->indexCount = polys.indices.size();
cache->primitiveType = GL_TRIANGLES;
@@ -920,6 +940,7 @@ void QOpenGL2PaintEngineExPrivate::fill(const QVectorPath& path)
#ifdef QT_OPENGL_CACHE_AS_VBOS
funcs.glBindBuffer(GL_ARRAY_BUFFER, cache->vbo);
funcs.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, cache->ibo);
+ uploadData(QT_VERTEX_COORDS_ATTR, 0, cache->vertexCount);
setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, 0);
if (cache->indexType == QVertexIndexVector::UnsignedInt)
funcs.glDrawElements(cache->primitiveType, cache->indexCount, GL_UNSIGNED_INT, 0);
@@ -928,11 +949,10 @@ void QOpenGL2PaintEngineExPrivate::fill(const QVectorPath& path)
funcs.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
funcs.glBindBuffer(GL_ARRAY_BUFFER, 0);
#else
- setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, cache->vertices);
- if (cache->indexType == QVertexIndexVector::UnsignedInt)
- funcs.glDrawElements(cache->primitiveType, cache->indexCount, GL_UNSIGNED_INT, (qint32 *)cache->indices);
- else
- funcs.glDrawElements(cache->primitiveType, cache->indexCount, GL_UNSIGNED_SHORT, (qint16 *)cache->indices);
+ uploadData(QT_VERTEX_COORDS_ATTR, cache->vertices, cache->vertexCount * 2);
+ const GLenum indexValueType = cache->indexType == QVertexIndexVector::UnsignedInt ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT;
+ const bool useIndexVbo = uploadIndexData(cache->indices, indexValueType, cache->indexCount);
+ funcs.glDrawElements(cache->primitiveType, cache->indexCount, indexValueType, useIndexVbo ? nullptr : cache->indices);
#endif
} else {
@@ -950,18 +970,17 @@ void QOpenGL2PaintEngineExPrivate::fill(const QVectorPath& path)
&& (bbox.top() > -0x8000 * inverseScale)
&& (bbox.bottom() < 0x8000 * inverseScale);
if (withinLimits) {
- QTriangleSet polys = qTriangulate(path, QTransform().scale(1 / inverseScale, 1 / inverseScale));
+ QTriangleSet polys = qTriangulate(path, QTransform().scale(1 / inverseScale, 1 / inverseScale), 1, supportsElementIndexUint);
QVarLengthArray<float> vertices(polys.vertices.size());
for (int i = 0; i < polys.vertices.size(); ++i)
vertices[i] = float(inverseScale * polys.vertices.at(i));
prepareForDraw(currentBrush.isOpaque());
- setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, vertices.constData());
- if (funcs.hasOpenGLExtension(QOpenGLExtensions::ElementIndexUint))
- funcs.glDrawElements(GL_TRIANGLES, polys.indices.size(), GL_UNSIGNED_INT, polys.indices.data());
- else
- funcs.glDrawElements(GL_TRIANGLES, polys.indices.size(), GL_UNSIGNED_SHORT, polys.indices.data());
+ uploadData(QT_VERTEX_COORDS_ATTR, vertices.constData(), vertices.size());
+ const GLenum indexValueType = funcs.hasOpenGLExtension(QOpenGLExtensions::ElementIndexUint) ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT;
+ const bool useIndexVbo = uploadIndexData(polys.indices.data(), indexValueType, polys.indices.size());
+ funcs.glDrawElements(GL_TRIANGLES, polys.indices.size(), indexValueType, useIndexVbo ? nullptr : polys.indices.data());
} else {
// We can't handle big, concave painter paths with OpenGL without stencil buffer.
qWarning("Painter path exceeds +/-32767 pixels.");
@@ -1083,7 +1102,8 @@ void QOpenGL2PaintEngineExPrivate::fillStencilWithVertexArray(const float *data,
} else {
funcs.glStencilFunc(GL_ALWAYS, GL_STENCIL_HIGH_BIT, 0xff);
}
- setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, data);
+
+ uploadData(QT_VERTEX_COORDS_ATTR, data, count * 2);
funcs.glDrawArrays(GL_TRIANGLE_STRIP, 0, count);
#endif
}
@@ -1213,7 +1233,8 @@ bool QOpenGL2PaintEngineExPrivate::prepareForDraw(bool srcPixelsAreOpaque)
void QOpenGL2PaintEngineExPrivate::composite(const QOpenGLRect& boundingRect)
{
setCoords(staticVertexCoordinateArray, boundingRect);
- setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, staticVertexCoordinateArray);
+
+ uploadData(QT_VERTEX_COORDS_ATTR, staticVertexCoordinateArray, 8);
funcs.glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
}
@@ -1222,16 +1243,12 @@ void QOpenGL2PaintEngineExPrivate::drawVertexArrays(const float *data, int *stop
GLenum primitive)
{
// Now setup the pointer to the vertex array:
- setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, data);
+ uploadData(QT_VERTEX_COORDS_ATTR, data, stops[stopCount-1] * 2);
int previousStop = 0;
for (int i=0; i<stopCount; ++i) {
int stop = stops[i];
-/*
- qDebug("Drawing triangle fan for vertecies %d -> %d:", previousStop, stop-1);
- for (int i=previousStop; i<stop; ++i)
- qDebug(" %02d: [%.2f, %.2f]", i, vertexArray.data()[i].x, vertexArray.data()[i].y);
-*/
+
funcs.glDrawArrays(primitive, previousStop, stop - previousStop);
previousStop = stop;
}
@@ -1323,14 +1340,9 @@ void QOpenGL2PaintEngineExPrivate::stroke(const QVectorPath &path, const QPen &p
if (opaque) {
prepareForDraw(opaque);
- setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, stroker.vertices());
- funcs.glDrawArrays(GL_TRIANGLE_STRIP, 0, stroker.vertexCount() / 2);
-
-// QBrush b(Qt::green);
-// d->setBrush(&b);
-// d->prepareForDraw(true);
-// glDrawArrays(GL_LINE_STRIP, 0, d->stroker.vertexCount() / 2);
+ uploadData(QT_VERTEX_COORDS_ATTR, stroker.vertices(), stroker.vertexCount());
+ funcs.glDrawArrays(GL_TRIANGLE_STRIP, 0, stroker.vertexCount() / 2);
} else {
qreal width = qpen_widthf(pen) / 2;
if (width == 0)
@@ -1839,8 +1851,8 @@ void QOpenGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngine::GlyphFormat gly
}
if (glyphFormat != QFontEngine::Format_ARGB || recreateVertexArrays) {
- setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, (GLfloat*)vertexCoordinates->data());
- setVertexAttributePointer(QT_TEXTURE_COORDS_ATTR, (GLfloat*)textureCoordinates->data());
+ uploadData(QT_VERTEX_COORDS_ATTR, (GLfloat*)vertexCoordinates->data(), vertexCoordinates->vertexCount() * 2);
+ uploadData(QT_TEXTURE_COORDS_ATTR, (GLfloat*)textureCoordinates->data(), textureCoordinates->vertexCount() * 2);
}
if (!snapToPixelGrid) {
@@ -1904,7 +1916,8 @@ void QOpenGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngine::GlyphFormat gly
#if defined(QT_OPENGL_DRAWCACHEDGLYPHS_INDEX_ARRAY_VBO)
funcs.glDrawElements(GL_TRIANGLE_STRIP, 6 * numGlyphs, GL_UNSIGNED_SHORT, 0);
#else
- funcs.glDrawElements(GL_TRIANGLE_STRIP, 6 * numGlyphs, GL_UNSIGNED_SHORT, elementIndices.data());
+ const bool useIndexVbo = uploadIndexData(elementIndices.data(), GL_UNSIGNED_SHORT, 6 * numGlyphs);
+ funcs.glDrawElements(GL_TRIANGLE_STRIP, 6 * numGlyphs, GL_UNSIGNED_SHORT, useIndexVbo ? nullptr : elementIndices.data());
#endif
shaderManager->setMaskType(QOpenGLEngineShaderManager::SubPixelMaskPass2);
@@ -1955,7 +1968,8 @@ void QOpenGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngine::GlyphFormat gly
funcs.glDrawElements(GL_TRIANGLE_STRIP, 6 * numGlyphs, GL_UNSIGNED_SHORT, 0);
funcs.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
#else
- funcs.glDrawElements(GL_TRIANGLE_STRIP, 6 * numGlyphs, GL_UNSIGNED_SHORT, elementIndices.data());
+ const bool useIndexVbo = uploadIndexData(elementIndices.data(), GL_UNSIGNED_SHORT, 6 * numGlyphs);
+ funcs.glDrawElements(GL_TRIANGLE_STRIP, 6 * numGlyphs, GL_UNSIGNED_SHORT, useIndexVbo ? nullptr : elementIndices.data());
#endif
}
@@ -2074,6 +2088,15 @@ bool QOpenGL2PaintEngineEx::begin(QPaintDevice *pdev)
return false;
}
+ if (d->ctx != QOpenGLContext::currentContext()
+ || (d->ctx && QOpenGLContext::currentContext() && d->ctx->format() != QOpenGLContext::currentContext()->format())) {
+ d->vertexBuffer.destroy();
+ d->texCoordBuffer.destroy();
+ d->opacityBuffer.destroy();
+ d->indexBuffer.destroy();
+ d->vao.destroy();
+ }
+
d->ctx = QOpenGLContext::currentContext();
d->ctx->d_func()->active_engine = this;
@@ -2081,6 +2104,42 @@ bool QOpenGL2PaintEngineEx::begin(QPaintDevice *pdev)
d->funcs.initializeOpenGLFunctions();
+ // Generate a new Vertex Array Object if we don't have one already. We can
+ // only hit the VAO-based path when using a core profile context. This is
+ // because while non-core contexts can support VAOs via extensions, legacy
+ // components like the QtOpenGL module do not know about VAOs. There are
+ // still tests for QGL-QOpenGL paint engine interoperability, so keep the
+ // status quo for now, and avoid introducing a VAO in non-core contexts.
+ const bool needsVAO = d->ctx->format().profile() == QSurfaceFormat::CoreProfile
+ && d->ctx->format().version() >= qMakePair(3, 2);
+ if (needsVAO && !d->vao.isCreated()) {
+ bool created = d->vao.create();
+
+ // If we managed to create it then we have a profile that supports VAOs
+ if (created) {
+ d->vao.bind();
+
+ // Generate a new Vertex Buffer Object if we don't have one already
+ if (!d->vertexBuffer.isCreated()) {
+ d->vertexBuffer.create();
+ // Set its usage to StreamDraw, we will use this buffer only a few times before refilling it
+ d->vertexBuffer.setUsagePattern(QOpenGLBuffer::StreamDraw);
+ }
+ if (!d->texCoordBuffer.isCreated()) {
+ d->texCoordBuffer.create();
+ d->texCoordBuffer.setUsagePattern(QOpenGLBuffer::StreamDraw);
+ }
+ if (!d->opacityBuffer.isCreated()) {
+ d->opacityBuffer.create();
+ d->opacityBuffer.setUsagePattern(QOpenGLBuffer::StreamDraw);
+ }
+ if (!d->indexBuffer.isCreated()) {
+ d->indexBuffer.create();
+ d->indexBuffer.setUsagePattern(QOpenGLBuffer::StreamDraw);
+ }
+ }
+ }
+
for (int i = 0; i < QT_GL_VERTEX_ARRAY_TRACKED_COUNT; ++i)
d->vertexAttributeArraysEnabledState[i] = false;
@@ -2162,6 +2221,9 @@ void QOpenGL2PaintEngineEx::ensureActive()
Q_D(QOpenGL2PaintEngineEx);
QOpenGLContext *ctx = d->ctx;
+ if (d->vao.isCreated())
+ d->vao.bind();
+
if (isActive() && ctx->d_func()->active_engine != this) {
ctx->d_func()->active_engine = this;
d->needsSync = true;
diff --git a/src/gui/opengl/qopenglpaintengine_p.h b/src/gui/opengl/qopenglpaintengine_p.h
index 807efb1ec2..679b3c0557 100644
--- a/src/gui/opengl/qopenglpaintengine_p.h
+++ b/src/gui/opengl/qopenglpaintengine_p.h
@@ -65,6 +65,9 @@
#include <private/qopenglextensions_p.h>
+#include <QOpenGLVertexArrayObject>
+#include <QOpenGLBuffer>
+
enum EngineMode {
ImageDrawingMode,
TextDrawingMode,
@@ -193,7 +196,11 @@ public:
snapToPixelGrid(false),
nativePaintingActive(false),
inverseScale(1),
- lastTextureUnitUsed(QT_UNKNOWN_TEXTURE_UNIT)
+ lastTextureUnitUsed(QT_UNKNOWN_TEXTURE_UNIT),
+ vertexBuffer(QOpenGLBuffer::VertexBuffer),
+ texCoordBuffer(QOpenGLBuffer::VertexBuffer),
+ opacityBuffer(QOpenGLBuffer::VertexBuffer),
+ indexBuffer(QOpenGLBuffer::IndexBuffer)
{ }
~QOpenGL2PaintEngineExPrivate();
@@ -222,7 +229,8 @@ public:
void drawCachedGlyphs(QFontEngine::GlyphFormat glyphFormat, QStaticTextItem *staticTextItem);
// Calls glVertexAttributePointer if the pointer has changed
- inline void setVertexAttributePointer(unsigned int arrayIndex, const GLfloat *pointer);
+ inline void uploadData(unsigned int arrayIndex, const GLfloat *data, GLuint count);
+ inline bool uploadIndexData(const void *data, GLenum indexValueType, GLuint count);
// draws whatever is in the vertex array:
void drawVertexArrays(const float *data, int *stops, int stopCount, GLenum primitive);
@@ -313,6 +321,12 @@ public:
GLenum lastTextureUnitUsed;
GLuint lastTextureUsed;
+ QOpenGLVertexArrayObject vao;
+ QOpenGLBuffer vertexBuffer;
+ QOpenGLBuffer texCoordBuffer;
+ QOpenGLBuffer opacityBuffer;
+ QOpenGLBuffer indexBuffer;
+
bool needsSync;
bool multisamplingAlwaysEnabled;
@@ -326,17 +340,55 @@ public:
};
-void QOpenGL2PaintEngineExPrivate::setVertexAttributePointer(unsigned int arrayIndex, const GLfloat *pointer)
+void QOpenGL2PaintEngineExPrivate::uploadData(unsigned int arrayIndex, const GLfloat *data, GLuint count)
{
Q_ASSERT(arrayIndex < 3);
- if (pointer == vertexAttribPointers[arrayIndex])
- return;
-
- vertexAttribPointers[arrayIndex] = pointer;
- if (arrayIndex == QT_OPACITY_ATTR)
- funcs.glVertexAttribPointer(arrayIndex, 1, GL_FLOAT, GL_FALSE, 0, pointer);
- else
- funcs.glVertexAttribPointer(arrayIndex, 2, GL_FLOAT, GL_FALSE, 0, pointer);
+
+ // If a vertex array object is created we have a profile that supports them
+ // and we will upload the data via a QOpenGLBuffer. Otherwise we will use
+ // the legacy way of uploading the data via glVertexAttribPointer.
+ if (vao.isCreated()) {
+ if (arrayIndex == QT_VERTEX_COORDS_ATTR) {
+ vertexBuffer.bind();
+ vertexBuffer.allocate(data, count * sizeof(float));
+ }
+ if (arrayIndex == QT_TEXTURE_COORDS_ATTR) {
+ texCoordBuffer.bind();
+ texCoordBuffer.allocate(data, count * sizeof(float));
+ }
+ if (arrayIndex == QT_OPACITY_ATTR) {
+ opacityBuffer.bind();
+ opacityBuffer.allocate(data, count * sizeof(float));
+ }
+ if (arrayIndex == QT_OPACITY_ATTR)
+ funcs.glVertexAttribPointer(arrayIndex, 1, GL_FLOAT, GL_FALSE, 0, 0);
+ else
+ funcs.glVertexAttribPointer(arrayIndex, 2, GL_FLOAT, GL_FALSE, 0, 0);
+ } else {
+ // If we already uploaded the data we don't have to do it again
+ if (data == vertexAttribPointers[arrayIndex])
+ return;
+
+ // Store the data in cache and upload it to the graphics card.
+ vertexAttribPointers[arrayIndex] = data;
+ if (arrayIndex == QT_OPACITY_ATTR)
+ funcs.glVertexAttribPointer(arrayIndex, 1, GL_FLOAT, GL_FALSE, 0, data);
+ else
+ funcs.glVertexAttribPointer(arrayIndex, 2, GL_FLOAT, GL_FALSE, 0, data);
+ }
+}
+
+bool QOpenGL2PaintEngineExPrivate::uploadIndexData(const void *data, GLenum indexValueType, GLuint count)
+{
+ // Follow the uploadData() logic: VBOs are used only when VAO support is available.
+ // Otherwise the legacy client-side pointer path is used.
+ if (vao.isCreated()) {
+ Q_ASSERT(indexValueType == GL_UNSIGNED_SHORT || indexValueType == GL_UNSIGNED_INT);
+ indexBuffer.bind();
+ indexBuffer.allocate(data, count * (indexValueType == GL_UNSIGNED_SHORT ? sizeof(quint16) : sizeof(quint32)));
+ return true;
+ }
+ return false;
}
QT_END_NAMESPACE
diff --git a/src/gui/opengl/qopenglprogrambinarycache.cpp b/src/gui/opengl/qopenglprogrambinarycache.cpp
new file mode 100644
index 0000000000..06373e1113
--- /dev/null
+++ b/src/gui/opengl/qopenglprogrambinarycache.cpp
@@ -0,0 +1,376 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qopenglprogrambinarycache_p.h"
+#include <QOpenGLContext>
+#include <QOpenGLExtraFunctions>
+#include <QStandardPaths>
+#include <QDir>
+#include <QSaveFile>
+#include <QLoggingCategory>
+
+#ifdef Q_OS_UNIX
+#include <sys/mman.h>
+#include <private/qcore_unix_p.h>
+#endif
+
+QT_BEGIN_NAMESPACE
+
+Q_DECLARE_LOGGING_CATEGORY(DBG_SHADER_CACHE)
+
+#ifndef GL_PROGRAM_BINARY_LENGTH
+#define GL_PROGRAM_BINARY_LENGTH 0x8741
+#endif
+
+const quint32 BINSHADER_MAGIC = 0x5174;
+const quint32 BINSHADER_VERSION = 0x2;
+const quint32 BINSHADER_QTVERSION = QT_VERSION;
+
+struct GLEnvInfo
+{
+ GLEnvInfo();
+
+ QByteArray glvendor;
+ QByteArray glrenderer;
+ QByteArray glversion;
+};
+
+GLEnvInfo::GLEnvInfo()
+{
+ QOpenGLContext *ctx = QOpenGLContext::currentContext();
+ Q_ASSERT(ctx);
+ QOpenGLFunctions *f = ctx->functions();
+ const char *vendor = reinterpret_cast<const char *>(f->glGetString(GL_VENDOR));
+ const char *renderer = reinterpret_cast<const char *>(f->glGetString(GL_RENDERER));
+ const char *version = reinterpret_cast<const char *>(f->glGetString(GL_VERSION));
+ if (vendor)
+ glvendor = QByteArray(vendor);
+ if (renderer)
+ glrenderer = QByteArray(renderer);
+ if (version)
+ glversion = QByteArray(version);
+}
+
+static inline bool qt_ensureWritableDir(const QString &name)
+{
+ QDir::root().mkpath(name);
+ return QFileInfo(name).isWritable();
+}
+
+QOpenGLProgramBinaryCache::QOpenGLProgramBinaryCache()
+ : m_cacheWritable(false)
+{
+ const QString subPath = QLatin1String("/qtshadercache/");
+ const QString sharedCachePath = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation);
+ if (!sharedCachePath.isEmpty()) {
+ m_cacheDir = sharedCachePath + subPath;
+ m_cacheWritable = qt_ensureWritableDir(m_cacheDir);
+ }
+ if (!m_cacheWritable) {
+ m_cacheDir = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + subPath;
+ m_cacheWritable = qt_ensureWritableDir(m_cacheDir);
+ }
+ qCDebug(DBG_SHADER_CACHE, "Cache location '%s' writable = %d", qPrintable(m_cacheDir), m_cacheWritable);
+}
+
+QString QOpenGLProgramBinaryCache::cacheFileName(const QByteArray &cacheKey) const
+{
+ return m_cacheDir + QString::fromUtf8(cacheKey);
+}
+
+#define BASE_HEADER_SIZE (int(3 * sizeof(quint32)))
+#define FULL_HEADER_SIZE(stringsSize) (BASE_HEADER_SIZE + 12 + stringsSize + 8)
+#define PADDING_SIZE(fullHeaderSize) (((fullHeaderSize + 3) & ~3) - fullHeaderSize)
+
+static inline quint32 readUInt(const uchar **p)
+{
+ quint32 v;
+ memcpy(&v, *p, sizeof(quint32));
+ *p += sizeof(quint32);
+ return v;
+}
+
+static inline QByteArray readStr(const uchar **p)
+{
+ quint32 len = readUInt(p);
+ QByteArray ba = QByteArray::fromRawData(reinterpret_cast<const char *>(*p), len);
+ *p += len;
+ return ba;
+}
+
+bool QOpenGLProgramBinaryCache::verifyHeader(const QByteArray &buf) const
+{
+ if (buf.size() < BASE_HEADER_SIZE) {
+ qCDebug(DBG_SHADER_CACHE, "Cached size too small");
+ return false;
+ }
+ const uchar *p = reinterpret_cast<const uchar *>(buf.constData());
+ if (readUInt(&p) != BINSHADER_MAGIC) {
+ qCDebug(DBG_SHADER_CACHE, "Magic does not match");
+ return false;
+ }
+ if (readUInt(&p) != BINSHADER_VERSION) {
+ qCDebug(DBG_SHADER_CACHE, "Version does not match");
+ return false;
+ }
+ if (readUInt(&p) != BINSHADER_QTVERSION) {
+ qCDebug(DBG_SHADER_CACHE, "Qt version does not match");
+ return false;
+ }
+ return true;
+}
+
+bool QOpenGLProgramBinaryCache::setProgramBinary(uint programId, uint blobFormat, const void *p, uint blobSize)
+{
+ QOpenGLExtraFunctions *funcs = QOpenGLContext::currentContext()->extraFunctions();
+ while (funcs->glGetError() != GL_NO_ERROR) { }
+ funcs->glProgramBinary(programId, blobFormat, p, blobSize);
+ int err = funcs->glGetError();
+ qCDebug(DBG_SHADER_CACHE, "Program binary set for program %u, size %d, format 0x%x, err = 0x%x",
+ programId, blobSize, blobFormat, err);
+ return err == 0;
+}
+
+#ifdef Q_OS_UNIX
+class FdWrapper
+{
+public:
+ FdWrapper(const QString &fn)
+ : ptr(MAP_FAILED)
+ {
+ fd = qt_safe_open(QFile::encodeName(fn).constData(), O_RDONLY);
+ }
+ ~FdWrapper()
+ {
+ if (ptr != MAP_FAILED)
+ munmap(ptr, mapSize);
+ if (fd != -1)
+ qt_safe_close(fd);
+ }
+ bool map()
+ {
+ off_t offs = lseek(fd, 0, SEEK_END);
+ if (offs == (off_t) -1) {
+ qErrnoWarning(errno, "lseek failed for program binary");
+ return false;
+ }
+ mapSize = static_cast<size_t>(offs);
+ ptr = mmap(nullptr, mapSize, PROT_READ, MAP_SHARED, fd, 0);
+ return ptr != MAP_FAILED;
+ }
+
+ int fd;
+ void *ptr;
+ size_t mapSize;
+};
+#endif
+
+class DeferredFileRemove
+{
+public:
+ DeferredFileRemove(const QString &fn)
+ : fn(fn),
+ active(false)
+ {
+ }
+ ~DeferredFileRemove()
+ {
+ if (active)
+ QFile(fn).remove();
+ }
+ void setActive()
+ {
+ active = true;
+ }
+
+ QString fn;
+ bool active;
+};
+
+bool QOpenGLProgramBinaryCache::load(const QByteArray &cacheKey, uint programId)
+{
+ if (m_memCache.contains(cacheKey)) {
+ const MemCacheEntry *e = m_memCache[cacheKey];
+ return setProgramBinary(programId, e->format, e->blob.constData(), e->blob.size());
+ }
+
+ QByteArray buf;
+ const QString fn = cacheFileName(cacheKey);
+ DeferredFileRemove undertaker(fn);
+#ifdef Q_OS_UNIX
+ FdWrapper fdw(fn);
+ if (fdw.fd == -1)
+ return false;
+ char header[BASE_HEADER_SIZE];
+ qint64 bytesRead = qt_safe_read(fdw.fd, header, BASE_HEADER_SIZE);
+ if (bytesRead == BASE_HEADER_SIZE)
+ buf = QByteArray::fromRawData(header, BASE_HEADER_SIZE);
+#else
+ QFile f(fn);
+ if (!f.open(QIODevice::ReadOnly))
+ return false;
+ buf = f.read(BASE_HEADER_SIZE);
+#endif
+
+ if (!verifyHeader(buf)) {
+ undertaker.setActive();
+ return false;
+ }
+
+ const uchar *p;
+#ifdef Q_OS_UNIX
+ if (!fdw.map()) {
+ undertaker.setActive();
+ return false;
+ }
+ p = static_cast<const uchar *>(fdw.ptr) + BASE_HEADER_SIZE;
+#else
+ buf = f.readAll();
+ p = reinterpret_cast<const uchar *>(buf.constData());
+#endif
+
+ GLEnvInfo info;
+
+ QByteArray vendor = readStr(&p);
+ if (vendor != info.glvendor) {
+ // readStr returns non-null terminated strings just pointing to inside
+ // 'p' so must print these via the stream qCDebug and not constData().
+ qCDebug(DBG_SHADER_CACHE) << "GL_VENDOR does not match" << vendor << info.glvendor;
+ undertaker.setActive();
+ return false;
+ }
+ QByteArray renderer = readStr(&p);
+ if (renderer != info.glrenderer) {
+ qCDebug(DBG_SHADER_CACHE) << "GL_RENDERER does not match" << renderer << info.glrenderer;
+ undertaker.setActive();
+ return false;
+ }
+ QByteArray version = readStr(&p);
+ if (version != info.glversion) {
+ qCDebug(DBG_SHADER_CACHE) << "GL_VERSION does not match" << version << info.glversion;
+ undertaker.setActive();
+ return false;
+ }
+
+ quint32 blobFormat = readUInt(&p);
+ quint32 blobSize = readUInt(&p);
+
+ p += PADDING_SIZE(FULL_HEADER_SIZE(vendor.size() + renderer.size() + version.size()));
+
+ return setProgramBinary(programId, blobFormat, p, blobSize)
+ && m_memCache.insert(cacheKey, new MemCacheEntry(p, blobSize, blobFormat));
+}
+
+static inline void writeUInt(uchar **p, quint32 value)
+{
+ memcpy(*p, &value, sizeof(quint32));
+ *p += sizeof(quint32);
+}
+
+static inline void writeStr(uchar **p, const QByteArray &str)
+{
+ writeUInt(p, str.size());
+ memcpy(*p, str.constData(), str.size());
+ *p += str.size();
+}
+
+void QOpenGLProgramBinaryCache::save(const QByteArray &cacheKey, uint programId)
+{
+ if (!m_cacheWritable)
+ return;
+
+ GLEnvInfo info;
+
+ QOpenGLExtraFunctions *funcs = QOpenGLContext::currentContext()->extraFunctions();
+ GLint blobSize = 0;
+ while (funcs->glGetError() != GL_NO_ERROR) { }
+ funcs->glGetProgramiv(programId, GL_PROGRAM_BINARY_LENGTH, &blobSize);
+
+ const int headerSize = FULL_HEADER_SIZE(info.glvendor.size() + info.glrenderer.size() + info.glversion.size());
+
+ // Add padding to make the blob start 4-byte aligned in order to support
+ // OpenGL implementations on ARM that choke on non-aligned pointers passed
+ // to glProgramBinary.
+ const int paddingSize = PADDING_SIZE(headerSize);
+
+ const int totalSize = headerSize + paddingSize + blobSize;
+
+ qCDebug(DBG_SHADER_CACHE, "Program binary is %d bytes, err = 0x%x, total %d", blobSize, funcs->glGetError(), totalSize);
+ if (!blobSize)
+ return;
+
+ QByteArray blob(totalSize, Qt::Uninitialized);
+ uchar *p = reinterpret_cast<uchar *>(blob.data());
+
+ writeUInt(&p, BINSHADER_MAGIC);
+ writeUInt(&p, BINSHADER_VERSION);
+ writeUInt(&p, BINSHADER_QTVERSION);
+
+ writeStr(&p, info.glvendor);
+ writeStr(&p, info.glrenderer);
+ writeStr(&p, info.glversion);
+
+ quint32 blobFormat = 0;
+ uchar *blobFormatPtr = p;
+ writeUInt(&p, blobFormat);
+ writeUInt(&p, blobSize);
+
+ for (int i = 0; i < paddingSize; ++i)
+ *p++ = 0;
+
+ GLint outSize = 0;
+ funcs->glGetProgramBinary(programId, blobSize, &outSize, &blobFormat, p);
+ if (blobSize != outSize) {
+ qCDebug(DBG_SHADER_CACHE, "glGetProgramBinary returned size %d instead of %d", outSize, blobSize);
+ return;
+ }
+
+ writeUInt(&blobFormatPtr, blobFormat);
+
+ QSaveFile f(cacheFileName(cacheKey));
+ if (f.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
+ f.write(blob);
+ if (!f.commit())
+ qCDebug(DBG_SHADER_CACHE, "Failed to write %s to shader cache", qPrintable(f.fileName()));
+ } else {
+ qCDebug(DBG_SHADER_CACHE, "Failed to create %s in shader cache", qPrintable(f.fileName()));
+ }
+}
+
+QT_END_NAMESPACE
diff --git a/src/gui/opengl/qopenglprogrambinarycache_p.h b/src/gui/opengl/qopenglprogrambinarycache_p.h
new file mode 100644
index 0000000000..a0e1f91e25
--- /dev/null
+++ b/src/gui/opengl/qopenglprogrambinarycache_p.h
@@ -0,0 +1,100 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QOPENGLPROGRAMBINARYCACHE_P_H
+#define QOPENGLPROGRAMBINARYCACHE_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtGui/qtguiglobal.h>
+#include <QtGui/qopenglshaderprogram.h>
+#include <QtCore/qcache.h>
+
+QT_BEGIN_NAMESPACE
+
+class QOpenGLProgramBinaryCache
+{
+public:
+ struct ShaderDesc {
+ ShaderDesc() { }
+ ShaderDesc(QOpenGLShader::ShaderType type, const QByteArray &source = QByteArray())
+ : type(type), source(source)
+ { }
+ QOpenGLShader::ShaderType type;
+ QByteArray source;
+ };
+ struct ProgramDesc {
+ QVector<ShaderDesc> shaders;
+ };
+
+ QOpenGLProgramBinaryCache();
+
+ bool load(const QByteArray &cacheKey, uint programId);
+ void save(const QByteArray &cacheKey, uint programId);
+
+private:
+ QString cacheFileName(const QByteArray &cacheKey) const;
+ bool verifyHeader(const QByteArray &buf) const;
+ bool setProgramBinary(uint programId, uint blobFormat, const void *p, uint blobSize);
+
+ QString m_cacheDir;
+ bool m_cacheWritable;
+ struct MemCacheEntry {
+ MemCacheEntry(const void *p, int size, uint format)
+ : blob(reinterpret_cast<const char *>(p), size),
+ format(format)
+ { }
+ QByteArray blob;
+ uint format;
+ };
+ QCache<QByteArray, MemCacheEntry> m_memCache;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/gui/opengl/qopenglshaderprogram.cpp b/src/gui/opengl/qopenglshaderprogram.cpp
index cd582c5285..c9552fd321 100644
--- a/src/gui/opengl/qopenglshaderprogram.cpp
+++ b/src/gui/opengl/qopenglshaderprogram.cpp
@@ -38,6 +38,7 @@
****************************************************************************/
#include "qopenglshaderprogram.h"
+#include "qopenglprogrambinarycache_p.h"
#include "qopenglfunctions.h"
#include "private/qopenglcontext_p.h"
#include <QtCore/private/qobject_p.h>
@@ -46,6 +47,9 @@
#include <QtCore/qvarlengtharray.h>
#include <QtCore/qvector.h>
#include <QtCore/qregularexpression.h>
+#include <QtCore/qloggingcategory.h>
+#include <QtCore/qcryptographichash.h>
+#include <QtCore/qcoreapplication.h>
#include <QtGui/qtransform.h>
#include <QtGui/QColor>
#include <QtGui/QSurfaceFormat>
@@ -127,6 +131,20 @@ QT_BEGIN_NAMESPACE
on the shader program. The shader program's id can be explicitly
created using the create() function.
+ \section2 Caching Program Binaries
+
+ As of Qt 5.9, support for caching program binaries on disk is built in. To
+ enable this, switch to using addCacheableShaderFromSourceCode() and
+ addCacheableShaderFromSourceFile(). With an OpenGL ES 3.x context or support
+ for \c{GL_ARB_get_program_binary}, this will transparently cache program
+ binaries under QStandardPaths::GenericCacheLocation or
+ QStandardPaths::CacheLocation. When support is not available, calling the
+ cacheable function variants is equivalent to the normal ones.
+
+ \note Some drivers do not have any binary formats available, even though
+ they advertise the extension or offer OpenGL ES 3.0. In this case program
+ binary support will be disabled.
+
\sa QOpenGLShader
*/
@@ -162,6 +180,84 @@ QT_BEGIN_NAMESPACE
based on the core feature (requires OpenGL >= 4.3).
*/
+Q_LOGGING_CATEGORY(DBG_SHADER_CACHE, "qt.opengl.diskcache")
+
+// For GLES 3.1/3.2
+#ifndef GL_GEOMETRY_SHADER
+#define GL_GEOMETRY_SHADER 0x8DD9
+#endif
+#ifndef GL_TESS_CONTROL_SHADER
+#define GL_TESS_CONTROL_SHADER 0x8E88
+#endif
+#ifndef GL_TESS_EVALUATION_SHADER
+#define GL_TESS_EVALUATION_SHADER 0x8E87
+#endif
+#ifndef GL_COMPUTE_SHADER
+#define GL_COMPUTE_SHADER 0x91B9
+#endif
+#ifndef GL_MAX_GEOMETRY_OUTPUT_VERTICES
+#define GL_MAX_GEOMETRY_OUTPUT_VERTICES 0x8DE0
+#endif
+#ifndef GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS
+#define GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS 0x8DE1
+#endif
+#ifndef GL_PATCH_VERTICES
+#define GL_PATCH_VERTICES 0x8E72
+#endif
+#ifndef GL_PATCH_DEFAULT_OUTER_LEVEL
+#define GL_PATCH_DEFAULT_OUTER_LEVEL 0x8E74
+#endif
+#ifndef GL_PATCH_DEFAULT_INNER_LEVEL
+#define GL_PATCH_DEFAULT_INNER_LEVEL 0x8E73
+#endif
+
+#ifndef GL_NUM_PROGRAM_BINARY_FORMATS
+#define GL_NUM_PROGRAM_BINARY_FORMATS 0x87FE
+#endif
+
+static inline bool isFormatGLES(const QSurfaceFormat &f)
+{
+ return (f.renderableType() == QSurfaceFormat::OpenGLES);
+}
+
+static inline bool supportsGeometry(const QSurfaceFormat &f)
+{
+#ifndef QT_OPENGL_ES_2
+ if (!isFormatGLES(f))
+ return (f.version() >= qMakePair<int, int>(3, 2));
+ else
+ return false;
+#else
+ Q_UNUSED(f);
+ return false;
+#endif
+}
+
+static inline bool supportsCompute(const QSurfaceFormat &f)
+{
+#ifndef QT_OPENGL_ES_2
+ if (!isFormatGLES(f))
+ return (f.version() >= qMakePair<int, int>(4, 3));
+ else
+ return (f.version() >= qMakePair<int, int>(3, 1));
+#else
+ return (f.version() >= qMakePair<int, int>(3, 1));
+#endif
+}
+
+static inline bool supportsTessellation(const QSurfaceFormat &f)
+{
+#ifndef QT_OPENGL_ES_2
+ if (!isFormatGLES(f))
+ return (f.version() >= qMakePair<int, int>(4, 0));
+ else
+ return false;
+#else
+ Q_UNUSED(f);
+ return false;
+#endif
+}
+
class QOpenGLShaderPrivate : public QObjectPrivate
{
Q_DECLARE_PUBLIC(QOpenGLShader)
@@ -171,22 +267,16 @@ public:
, shaderType(type)
, compiled(false)
, glfuncs(new QOpenGLFunctions(ctx))
-#ifndef QT_OPENGL_ES_2
, supportsGeometryShaders(false)
, supportsTessellationShaders(false)
-#endif
+ , supportsComputeShaders(false)
{
-#ifndef QT_OPENGL_ES_2
- if (!ctx->isOpenGLES()) {
- QSurfaceFormat f = ctx->format();
-
- // Geometry shaders require OpenGL >= 3.2
- if (shaderType & QOpenGLShader::Geometry)
- supportsGeometryShaders = (f.version() >= qMakePair<int, int>(3, 2));
- else if (shaderType & (QOpenGLShader::TessellationControl | QOpenGLShader::TessellationEvaluation))
- supportsTessellationShaders = (f.version() >= qMakePair<int, int>(4, 0));
- }
-#endif
+ if (shaderType & QOpenGLShader::Geometry)
+ supportsGeometryShaders = supportsGeometry(ctx->format());
+ else if (shaderType & (QOpenGLShader::TessellationControl | QOpenGLShader::TessellationEvaluation))
+ supportsTessellationShaders = supportsTessellation(ctx->format());
+ else if (shaderType & QOpenGLShader::Compute)
+ supportsComputeShaders = supportsCompute(ctx->format());
}
~QOpenGLShaderPrivate();
@@ -197,13 +287,13 @@ public:
QOpenGLFunctions *glfuncs;
-#ifndef QT_OPENGL_ES_2
// Support for geometry shaders
bool supportsGeometryShaders;
-
// Support for tessellation shaders
bool supportsTessellationShaders;
-#endif
+ // Support for compute shaders
+ bool supportsComputeShaders;
+
bool create();
bool compile(QOpenGLShader *q);
@@ -229,24 +319,18 @@ bool QOpenGLShaderPrivate::create()
QOpenGLContext *context = const_cast<QOpenGLContext *>(QOpenGLContext::currentContext());
if (!context)
return false;
- GLuint shader;
+ GLuint shader = 0;
if (shaderType == QOpenGLShader::Vertex) {
shader = glfuncs->glCreateShader(GL_VERTEX_SHADER);
-#if defined(QT_OPENGL_3_2)
} else if (shaderType == QOpenGLShader::Geometry && supportsGeometryShaders) {
shader = glfuncs->glCreateShader(GL_GEOMETRY_SHADER);
-#endif
-#if defined(QT_OPENGL_4)
} else if (shaderType == QOpenGLShader::TessellationControl && supportsTessellationShaders) {
shader = glfuncs->glCreateShader(GL_TESS_CONTROL_SHADER);
} else if (shaderType == QOpenGLShader::TessellationEvaluation && supportsTessellationShaders) {
shader = glfuncs->glCreateShader(GL_TESS_EVALUATION_SHADER);
-#endif
-#if defined(QT_OPENGL_4_3)
- } else if (shaderType == QOpenGLShader::Compute) {
+ } else if (shaderType == QOpenGLShader::Compute && supportsComputeShaders) {
shader = glfuncs->glCreateShader(GL_COMPUTE_SHADER);
-#endif
- } else {
+ } else if (shaderType == QOpenGLShader::Fragment) {
shader = glfuncs->glCreateShader(GL_FRAGMENT_SHADER);
}
if (!shader) {
@@ -710,6 +794,7 @@ public:
#ifndef QT_OPENGL_ES_2
, tessellationFuncs(0)
#endif
+ , linkBinaryRecursion(false)
{
}
~QOpenGLShaderProgramPrivate();
@@ -731,6 +816,13 @@ public:
#endif
bool hasShader(QOpenGLShader::ShaderType type) const;
+
+ QOpenGLProgramBinaryCache::ProgramDesc binaryProgram;
+ bool isCacheDisabled() const;
+ bool compileCacheable();
+ bool linkBinary();
+
+ bool linkBinaryRecursion;
};
namespace {
@@ -962,6 +1054,139 @@ bool QOpenGLShaderProgram::addShaderFromSourceFile
}
/*!
+ Registers the shader of the specified \a type and \a source to this
+ program. Unlike addShaderFromSourceCode(), this function does not perform
+ compilation. Compilation is deferred to link(), and may not happen at all,
+ because link() may potentially use a program binary from Qt's shader disk
+ cache. This will typically lead to a significant increase in performance.
+
+ \return true if the shader has been registered or, in the non-cached case,
+ compiled successfully; false if there was an error. The compilation error
+ messages can be retrieved via log().
+
+ When the disk cache is disabled, via Qt::AA_DisableShaderDiskCache for
+ example, or the OpenGL context has no support for context binaries, calling
+ this function is equivalent to addShaderFromSourceCode().
+
+ \since 5.9
+ \sa addShaderFromSourceCode(), addCacheableShaderFromSourceFile()
+ */
+bool QOpenGLShaderProgram::addCacheableShaderFromSourceCode(QOpenGLShader::ShaderType type, const char *source)
+{
+ Q_D(QOpenGLShaderProgram);
+ if (!init())
+ return false;
+ if (d->isCacheDisabled())
+ return addShaderFromSourceCode(type, source);
+
+ return addCacheableShaderFromSourceCode(type, QByteArray(source));
+}
+
+/*!
+ \overload
+
+ Registers the shader of the specified \a type and \a source to this
+ program. Unlike addShaderFromSourceCode(), this function does not perform
+ compilation. Compilation is deferred to link(), and may not happen at all,
+ because link() may potentially use a program binary from Qt's shader disk
+ cache. This will typically lead to a significant increase in performance.
+
+ \return true if the shader has been registered or, in the non-cached case,
+ compiled successfully; false if there was an error. The compilation error
+ messages can be retrieved via log().
+
+ When the disk cache is disabled, via Qt::AA_DisableShaderDiskCache for
+ example, or the OpenGL context has no support for context binaries, calling
+ this function is equivalent to addShaderFromSourceCode().
+
+ \since 5.9
+ \sa addShaderFromSourceCode(), addCacheableShaderFromSourceFile()
+ */
+bool QOpenGLShaderProgram::addCacheableShaderFromSourceCode(QOpenGLShader::ShaderType type, const QByteArray &source)
+{
+ Q_D(QOpenGLShaderProgram);
+ if (!init())
+ return false;
+ if (d->isCacheDisabled())
+ return addShaderFromSourceCode(type, source);
+
+ d->binaryProgram.shaders.append(QOpenGLProgramBinaryCache::ShaderDesc(type, source));
+ return true;
+}
+
+/*!
+ \overload
+
+ Registers the shader of the specified \a type and \a source to this
+ program. Unlike addShaderFromSourceCode(), this function does not perform
+ compilation. Compilation is deferred to link(), and may not happen at all,
+ because link() may potentially use a program binary from Qt's shader disk
+ cache. This will typically lead to a significant increase in performance.
+
+ When the disk cache is disabled, via Qt::AA_DisableShaderDiskCache for
+ example, or the OpenGL context has no support for context binaries, calling
+ this function is equivalent to addShaderFromSourceCode().
+
+ \since 5.9
+ \sa addShaderFromSourceCode(), addCacheableShaderFromSourceFile()
+ */
+bool QOpenGLShaderProgram::addCacheableShaderFromSourceCode(QOpenGLShader::ShaderType type, const QString &source)
+{
+ Q_D(QOpenGLShaderProgram);
+ if (!init())
+ return false;
+ if (d->isCacheDisabled())
+ return addShaderFromSourceCode(type, source);
+
+ return addCacheableShaderFromSourceCode(type, source.toUtf8().constData());
+}
+
+/*!
+ Registers the shader of the specified \a type and \a fileName to this
+ program. Unlike addShaderFromSourceFile(), this function does not perform
+ compilation. Compilation is deferred to link(), and may not happen at all,
+ because link() may potentially use a program binary from Qt's shader disk
+ cache. This will typically lead to a significant increase in performance.
+
+ \return true if the file has been read successfully, false if the file could
+ not be opened or the normal, non-cached compilation of the shader has
+ failed. The compilation error messages can be retrieved via log().
+
+ When the disk cache is disabled, via Qt::AA_DisableShaderDiskCache for
+ example, or the OpenGL context has no support for context binaries, calling
+ this function is equivalent to addShaderFromSourceFile().
+
+ \since 5.9
+ \sa addShaderFromSourceFile(), addCacheableShaderFromSourceCode()
+ */
+bool QOpenGLShaderProgram::addCacheableShaderFromSourceFile(QOpenGLShader::ShaderType type, const QString &fileName)
+{
+ Q_D(QOpenGLShaderProgram);
+ if (!init())
+ return false;
+ if (d->isCacheDisabled())
+ return addShaderFromSourceFile(type, fileName);
+
+ QOpenGLProgramBinaryCache::ShaderDesc shader(type);
+ // NB! It could be tempting to defer reading the file contents and just
+ // hash the filename as the cache key, perhaps combined with last-modified
+ // timestamp checks. However, this would raise a number of issues (no
+ // timestamps for files in the resource system; preference for global, not
+ // per-application cache items (where filenames may clash); resource-based
+ // shaders from libraries like Qt Quick; etc.), so just avoid it.
+ QFile f(fileName);
+ if (f.open(QIODevice::ReadOnly | QIODevice::Text)) {
+ shader.source = f.readAll();
+ f.close();
+ } else {
+ qWarning("QOpenGLShaderProgram: Unable to open file %s", qPrintable(fileName));
+ return false;
+ }
+ d->binaryProgram.shaders.append(shader);
+ return true;
+}
+
+/*!
Removes \a shader from this shader program. The object is not deleted.
The shader program must be valid in the current QOpenGLContext.
@@ -1019,6 +1244,7 @@ void QOpenGLShaderProgram::removeAllShaders()
qDeleteAll(d->anonShaders);
d->shaders.clear();
d->anonShaders.clear();
+ d->binaryProgram = QOpenGLProgramBinaryCache::ProgramDesc();
d->linked = false; // Program needs to be relinked.
d->removingShaders = false;
}
@@ -1035,6 +1261,16 @@ void QOpenGLShaderProgram::removeAllShaders()
If the shader program was already linked, calling this
function again will force it to be re-linked.
+ When shaders were added to this program via
+ addCacheableShaderFromSourceCode() or addCacheableShaderFromSourceFile(),
+ program binaries are supported, and a cached binary is available on disk,
+ actual compilation and linking are skipped. Instead, link() will initialize
+ the program with the binary blob via glProgramBinary(). If there is no
+ cached version of the program or it was generated with a different driver
+ version, the shaders will be compiled from source and the program will get
+ linked normally. This allows seamless upgrading of the graphics drivers,
+ without having to worry about potentially incompatible binary formats.
+
\sa addShader(), log()
*/
bool QOpenGLShaderProgram::link()
@@ -1044,12 +1280,17 @@ bool QOpenGLShaderProgram::link()
if (!program)
return false;
+ if (!d->linkBinaryRecursion && d->shaders.isEmpty() && !d->binaryProgram.shaders.isEmpty())
+ return d->linkBinary();
+
GLint value;
if (d->shaders.isEmpty()) {
// If there are no explicit shaders, then it is possible that the
- // application added a program binary with glProgramBinaryOES(),
- // or otherwise populated the shaders itself. Check to see if the
- // program is already linked and bail out if so.
+ // application added a program binary with glProgramBinaryOES(), or
+ // otherwise populated the shaders itself. This is also the case when
+ // we are recursively called back from linkBinary() after a successful
+ // glProgramBinary(). Check to see if the program is already linked and
+ // bail out if so.
value = 0;
d->glfuncs->glGetProgramiv(program, GL_LINK_STATUS, &value);
d->linked = (value != 0);
@@ -1069,7 +1310,7 @@ bool QOpenGLShaderProgram::link()
GLint len;
d->glfuncs->glGetProgramInfoLog(program, value, &len, logbuf);
d->log = QString::fromLatin1(logbuf);
- if (!d->linked) {
+ if (!d->linked && !d->linkBinaryRecursion) {
QString name = objectName();
if (name.isEmpty())
qWarning("QOpenGLShader::link: %ls", qUtf16Printable(d->log));
@@ -3230,10 +3471,8 @@ void QOpenGLShaderProgram::setUniformValueArray(const char *name, const QMatrix4
int QOpenGLShaderProgram::maxGeometryOutputVertices() const
{
GLint n = 0;
-#if defined(QT_OPENGL_3_2)
Q_D(const QOpenGLShaderProgram);
d->glfuncs->glGetIntegerv(GL_MAX_GEOMETRY_OUTPUT_VERTICES, &n);
-#endif
return n;
}
@@ -3257,7 +3496,7 @@ int QOpenGLShaderProgram::maxGeometryOutputVertices() const
*/
void QOpenGLShaderProgram::setPatchVertexCount(int count)
{
-#if defined(QT_OPENGL_4)
+#ifndef QT_OPENGL_ES_2
Q_D(QOpenGLShaderProgram);
if (d->tessellationFuncs)
d->tessellationFuncs->glPatchParameteri(GL_PATCH_VERTICES, count);
@@ -3276,13 +3515,15 @@ void QOpenGLShaderProgram::setPatchVertexCount(int count)
*/
int QOpenGLShaderProgram::patchVertexCount() const
{
+#ifndef QT_OPENGL_ES_2
int patchVertices = 0;
-#if defined(QT_OPENGL_4)
Q_D(const QOpenGLShaderProgram);
if (d->tessellationFuncs)
d->tessellationFuncs->glGetIntegerv(GL_PATCH_VERTICES, &patchVertices);
-#endif
return patchVertices;
+#else
+ return 0;
+#endif
}
/*!
@@ -3304,21 +3545,21 @@ int QOpenGLShaderProgram::patchVertexCount() const
*/
void QOpenGLShaderProgram::setDefaultOuterTessellationLevels(const QVector<float> &levels)
{
-#if defined(QT_OPENGL_4)
- QVector<float> tessLevels = levels;
-
- // Ensure we have the required 4 outer tessellation levels
- // Use default of 1 for missing entries (same as spec)
- const int argCount = 4;
- if (tessLevels.size() < argCount) {
- tessLevels.reserve(argCount);
- for (int i = tessLevels.size(); i < argCount; ++i)
- tessLevels.append(1.0f);
- }
-
+#ifndef QT_OPENGL_ES_2
Q_D(QOpenGLShaderProgram);
- if (d->tessellationFuncs)
+ if (d->tessellationFuncs) {
+ QVector<float> tessLevels = levels;
+
+ // Ensure we have the required 4 outer tessellation levels
+ // Use default of 1 for missing entries (same as spec)
+ const int argCount = 4;
+ if (tessLevels.size() < argCount) {
+ tessLevels.reserve(argCount);
+ for (int i = tessLevels.size(); i < argCount; ++i)
+ tessLevels.append(1.0f);
+ }
d->tessellationFuncs->glPatchParameterfv(GL_PATCH_DEFAULT_OUTER_LEVEL, tessLevels.data());
+ }
#else
Q_UNUSED(levels);
#endif
@@ -3341,13 +3582,15 @@ void QOpenGLShaderProgram::setDefaultOuterTessellationLevels(const QVector<float
*/
QVector<float> QOpenGLShaderProgram::defaultOuterTessellationLevels() const
{
+#ifndef QT_OPENGL_ES_2
QVector<float> tessLevels(4, 1.0f);
-#if defined(QT_OPENGL_4)
Q_D(const QOpenGLShaderProgram);
if (d->tessellationFuncs)
d->tessellationFuncs->glGetFloatv(GL_PATCH_DEFAULT_OUTER_LEVEL, tessLevels.data());
-#endif
return tessLevels;
+#else
+ return QVector<float>();
+#endif
}
/*!
@@ -3369,21 +3612,21 @@ QVector<float> QOpenGLShaderProgram::defaultOuterTessellationLevels() const
*/
void QOpenGLShaderProgram::setDefaultInnerTessellationLevels(const QVector<float> &levels)
{
-#if defined(QT_OPENGL_4)
- QVector<float> tessLevels = levels;
-
- // Ensure we have the required 2 inner tessellation levels
- // Use default of 1 for missing entries (same as spec)
- const int argCount = 2;
- if (tessLevels.size() < argCount) {
- tessLevels.reserve(argCount);
- for (int i = tessLevels.size(); i < argCount; ++i)
- tessLevels.append(1.0f);
- }
-
+#ifndef QT_OPENGL_ES_2
Q_D(QOpenGLShaderProgram);
- if (d->tessellationFuncs)
+ if (d->tessellationFuncs) {
+ QVector<float> tessLevels = levels;
+
+ // Ensure we have the required 2 inner tessellation levels
+ // Use default of 1 for missing entries (same as spec)
+ const int argCount = 2;
+ if (tessLevels.size() < argCount) {
+ tessLevels.reserve(argCount);
+ for (int i = tessLevels.size(); i < argCount; ++i)
+ tessLevels.append(1.0f);
+ }
d->tessellationFuncs->glPatchParameterfv(GL_PATCH_DEFAULT_INNER_LEVEL, tessLevels.data());
+ }
#else
Q_UNUSED(levels);
#endif
@@ -3406,13 +3649,15 @@ void QOpenGLShaderProgram::setDefaultInnerTessellationLevels(const QVector<float
*/
QVector<float> QOpenGLShaderProgram::defaultInnerTessellationLevels() const
{
+#ifndef QT_OPENGL_ES_2
QVector<float> tessLevels(2, 1.0f);
-#if defined(QT_OPENGL_4)
Q_D(const QOpenGLShaderProgram);
if (d->tessellationFuncs)
d->tessellationFuncs->glGetFloatv(GL_PATCH_DEFAULT_INNER_LEVEL, tessLevels.data());
-#endif
return tessLevels;
+#else
+ return QVector<float>();
+#endif
}
@@ -3425,16 +3670,11 @@ QVector<float> QOpenGLShaderProgram::defaultInnerTessellationLevels() const
*/
bool QOpenGLShaderProgram::hasOpenGLShaderPrograms(QOpenGLContext *context)
{
-#if !defined(QT_OPENGL_ES_2)
if (!context)
context = QOpenGLContext::currentContext();
if (!context)
return false;
return QOpenGLFunctions(context).hasOpenGLFeature(QOpenGLFunctions::Shaders);
-#else
- Q_UNUSED(context);
- return true;
-#endif
}
/*!
@@ -3465,37 +3705,148 @@ bool QOpenGLShader::hasOpenGLShaders(ShaderType type, QOpenGLContext *context)
if ((type & ~(Geometry | Vertex | Fragment | TessellationControl | TessellationEvaluation | Compute)) || type == 0)
return false;
- QSurfaceFormat format = context->format();
- if (type == Geometry) {
-#ifndef QT_OPENGL_ES_2
- // Geometry shaders require OpenGL 3.2 or newer
- QSurfaceFormat format = context->format();
- return (!context->isOpenGLES())
- && (format.version() >= qMakePair<int, int>(3, 2));
-#else
- // No geometry shader support in OpenGL ES2
- return false;
-#endif
- } else if (type == TessellationControl || type == TessellationEvaluation) {
-#if !defined(QT_OPENGL_ES_2)
- return (!context->isOpenGLES())
- && (format.version() >= qMakePair<int, int>(4, 0));
-#else
- // No tessellation shader support in OpenGL ES2
- return false;
-#endif
- } else if (type == Compute) {
-#if defined(QT_OPENGL_4_3)
- return (format.version() >= qMakePair<int, int>(4, 3));
-#else
- // No compute shader support without OpenGL 4.3 or newer
- return false;
-#endif
- }
+ if (type & QOpenGLShader::Geometry)
+ return supportsGeometry(context->format());
+ else if (type & (QOpenGLShader::TessellationControl | QOpenGLShader::TessellationEvaluation))
+ return supportsTessellation(context->format());
+ else if (type & QOpenGLShader::Compute)
+ return supportsCompute(context->format());
// Unconditional support of vertex and fragment shaders implicitly assumes
// a minimum OpenGL version of 2.0
return true;
}
+// While unlikely, one application can in theory use contexts with different versions
+// or profiles. Therefore any version- or extension-specific checks must be done on a
+// per-context basis, not just once per process. QOpenGLSharedResource enables this,
+// although it's once-per-sharing-context-group, not per-context. Still, this should
+// be good enough in practice.
+class QOpenGLProgramBinarySupportCheck : public QOpenGLSharedResource
+{
+public:
+ QOpenGLProgramBinarySupportCheck(QOpenGLContext *context);
+ void invalidateResource() override { }
+ void freeResource(QOpenGLContext *) override { }
+
+ bool isSupported() const { return m_supported; }
+
+private:
+ bool m_supported;
+};
+
+QOpenGLProgramBinarySupportCheck::QOpenGLProgramBinarySupportCheck(QOpenGLContext *context)
+ : QOpenGLSharedResource(context->shareGroup()),
+ m_supported(false)
+{
+ if (QCoreApplication::testAttribute(Qt::AA_DisableShaderDiskCache)) {
+ qCDebug(DBG_SHADER_CACHE, "Shader cache disabled via app attribute");
+ return;
+ }
+ if (qEnvironmentVariableIntValue("QT_DISABLE_SHADER_DISK_CACHE")) {
+ qCDebug(DBG_SHADER_CACHE, "Shader cache disabled via env var");
+ return;
+ }
+
+ QOpenGLContext *ctx = QOpenGLContext::currentContext();
+ if (ctx) {
+ if (ctx->isOpenGLES()) {
+ qCDebug(DBG_SHADER_CACHE, "OpenGL ES v%d context", ctx->format().majorVersion());
+ if (ctx->format().majorVersion() >= 3)
+ m_supported = true;
+ } else {
+ const bool hasExt = ctx->hasExtension("GL_ARB_get_program_binary");
+ qCDebug(DBG_SHADER_CACHE, "GL_ARB_get_program_binary support = %d", hasExt);
+ if (hasExt)
+ m_supported = true;
+ }
+ if (m_supported) {
+ GLint fmtCount = 0;
+ ctx->functions()->glGetIntegerv(GL_NUM_PROGRAM_BINARY_FORMATS, &fmtCount);
+ qCDebug(DBG_SHADER_CACHE, "Supported binary format count = %d", fmtCount);
+ m_supported = fmtCount > 0;
+ }
+ }
+ qCDebug(DBG_SHADER_CACHE, "Shader cache supported = %d", m_supported);
+}
+
+class QOpenGLProgramBinarySupportCheckWrapper
+{
+public:
+ QOpenGLProgramBinarySupportCheck *get(QOpenGLContext *context)
+ {
+ return m_resource.value<QOpenGLProgramBinarySupportCheck>(context);
+ }
+
+private:
+ QOpenGLMultiGroupSharedResource m_resource;
+};
+
+bool QOpenGLShaderProgramPrivate::isCacheDisabled() const
+{
+ static QOpenGLProgramBinarySupportCheckWrapper binSupportCheck;
+ return !binSupportCheck.get(QOpenGLContext::currentContext())->isSupported();
+}
+
+bool QOpenGLShaderProgramPrivate::compileCacheable()
+{
+ Q_Q(QOpenGLShaderProgram);
+ for (const QOpenGLProgramBinaryCache::ShaderDesc &shader : qAsConst(binaryProgram.shaders)) {
+ QScopedPointer<QOpenGLShader> s(new QOpenGLShader(shader.type, q));
+ if (!s->compileSourceCode(shader.source)) {
+ log = s->log();
+ return false;
+ }
+ anonShaders.append(s.take());
+ if (!q->addShader(anonShaders.last()))
+ return false;
+ }
+ return true;
+}
+
+bool QOpenGLShaderProgramPrivate::linkBinary()
+{
+ static QOpenGLProgramBinaryCache binCache;
+
+ Q_Q(QOpenGLShaderProgram);
+
+ QCryptographicHash keyBuilder(QCryptographicHash::Sha1);
+ for (const QOpenGLProgramBinaryCache::ShaderDesc &shader : qAsConst(binaryProgram.shaders))
+ keyBuilder.addData(shader.source);
+
+ const QByteArray cacheKey = keyBuilder.result().toHex();
+ if (DBG_SHADER_CACHE().isEnabled(QtDebugMsg))
+ qCDebug(DBG_SHADER_CACHE, "program with %d shaders, cache key %s",
+ binaryProgram.shaders.count(), cacheKey.constData());
+
+ bool needsCompile = true;
+ if (binCache.load(cacheKey, q->programId())) {
+ qCDebug(DBG_SHADER_CACHE, "Program binary received from cache");
+ linkBinaryRecursion = true;
+ bool ok = q->link();
+ linkBinaryRecursion = false;
+ if (ok)
+ needsCompile = false;
+ else
+ qCDebug(DBG_SHADER_CACHE, "Link failed after glProgramBinary");
+ }
+
+ bool needsSave = false;
+ if (needsCompile) {
+ qCDebug(DBG_SHADER_CACHE, "Program binary not in cache, compiling");
+ if (compileCacheable())
+ needsSave = true;
+ else
+ return false;
+ }
+
+ linkBinaryRecursion = true;
+ bool ok = q->link();
+ linkBinaryRecursion = false;
+ if (ok && needsSave)
+ binCache.save(cacheKey, q->programId());
+
+ return ok;
+}
+
QT_END_NAMESPACE
diff --git a/src/gui/opengl/qopenglshaderprogram.h b/src/gui/opengl/qopenglshaderprogram.h
index 2da359c535..fd4d82ecf9 100644
--- a/src/gui/opengl/qopenglshaderprogram.h
+++ b/src/gui/opengl/qopenglshaderprogram.h
@@ -50,6 +50,13 @@
#include <QtGui/qvector4d.h>
#include <QtGui/qmatrix4x4.h>
+#if defined(Q_CLANG_QDOC)
+#undef GLint
+typedef int GLint;
+#undef GLfloat
+typedef double GLfloat;
+#endif
+
QT_BEGIN_NAMESPACE
@@ -119,6 +126,11 @@ public:
bool addShaderFromSourceCode(QOpenGLShader::ShaderType type, const QString& source);
bool addShaderFromSourceFile(QOpenGLShader::ShaderType type, const QString& fileName);
+ bool addCacheableShaderFromSourceCode(QOpenGLShader::ShaderType type, const char *source);
+ bool addCacheableShaderFromSourceCode(QOpenGLShader::ShaderType type, const QByteArray &source);
+ bool addCacheableShaderFromSourceCode(QOpenGLShader::ShaderType type, const QString &source);
+ bool addCacheableShaderFromSourceFile(QOpenGLShader::ShaderType type, const QString &fileName);
+
void removeAllShaders();
virtual bool link();
diff --git a/src/gui/opengl/qopengltexture.cpp b/src/gui/opengl/qopengltexture.cpp
index c9b08f60b1..3696378bd1 100644
--- a/src/gui/opengl/qopengltexture.cpp
+++ b/src/gui/opengl/qopengltexture.cpp
@@ -1351,7 +1351,7 @@ void QOpenGLTexturePrivate::allocateImmutableStorage()
storageAllocated = true;
}
-void QOpenGLTexturePrivate::setData(int mipLevel, int layer, QOpenGLTexture::CubeMapFace cubeFace,
+void QOpenGLTexturePrivate::setData(int mipLevel, int layer, int layerCount, QOpenGLTexture::CubeMapFace cubeFace,
QOpenGLTexture::PixelFormat sourceFormat, QOpenGLTexture::PixelType sourceType,
const void *data, const QOpenGLPixelTransferOptions * const options)
{
@@ -1359,6 +1359,7 @@ void QOpenGLTexturePrivate::setData(int mipLevel, int layer, QOpenGLTexture::Cub
case QOpenGLTexture::Target1D:
Q_UNUSED(layer);
Q_UNUSED(cubeFace);
+ Q_UNUSED(layerCount);
texFuncs->glTextureSubImage1D(textureId, target, bindingTarget, mipLevel,
0, mipLevelSize( mipLevel, dimensions[0] ),
sourceFormat, sourceType, data, options);
@@ -1369,13 +1370,14 @@ void QOpenGLTexturePrivate::setData(int mipLevel, int layer, QOpenGLTexture::Cub
texFuncs->glTextureSubImage2D(textureId, target, bindingTarget, mipLevel,
0, layer,
mipLevelSize(mipLevel, dimensions[0]),
- 1,
+ layerCount,
sourceFormat, sourceType, data, options);
break;
case QOpenGLTexture::Target2D:
Q_UNUSED(layer);
Q_UNUSED(cubeFace);
+ Q_UNUSED(layerCount);
texFuncs->glTextureSubImage2D(textureId, target, bindingTarget, mipLevel,
0, 0,
mipLevelSize(mipLevel, dimensions[0]),
@@ -1389,12 +1391,13 @@ void QOpenGLTexturePrivate::setData(int mipLevel, int layer, QOpenGLTexture::Cub
0, 0, layer,
mipLevelSize(mipLevel, dimensions[0]),
mipLevelSize(mipLevel, dimensions[1]),
- 1,
+ layerCount,
sourceFormat, sourceType, data, options);
break;
case QOpenGLTexture::Target3D:
Q_UNUSED(cubeFace);
+ Q_UNUSED(layerCount);
texFuncs->glTextureSubImage3D(textureId, target, bindingTarget, mipLevel,
0, 0, layer,
mipLevelSize(mipLevel, dimensions[0]),
@@ -1405,6 +1408,7 @@ void QOpenGLTexturePrivate::setData(int mipLevel, int layer, QOpenGLTexture::Cub
case QOpenGLTexture::TargetCubeMap:
Q_UNUSED(layer);
+ Q_UNUSED(layerCount);
texFuncs->glTextureSubImage2D(textureId, cubeFace, bindingTarget, mipLevel,
0, 0,
mipLevelSize(mipLevel, dimensions[0]),
@@ -1419,7 +1423,7 @@ void QOpenGLTexturePrivate::setData(int mipLevel, int layer, QOpenGLTexture::Cub
0, 0, layerFace,
mipLevelSize(mipLevel, dimensions[0]),
mipLevelSize(mipLevel, dimensions[1]),
- 1,
+ layerCount,
sourceFormat, sourceType, data, options);
break;
}
@@ -1428,6 +1432,7 @@ void QOpenGLTexturePrivate::setData(int mipLevel, int layer, QOpenGLTexture::Cub
Q_UNUSED(mipLevel);
Q_UNUSED(layer);
Q_UNUSED(cubeFace);
+ Q_UNUSED(layerCount);
texFuncs->glTextureSubImage2D(textureId, target, bindingTarget, 0,
0, 0,
dimensions[0],
@@ -1450,7 +1455,8 @@ void QOpenGLTexturePrivate::setData(int mipLevel, int layer, QOpenGLTexture::Cub
}
}
-void QOpenGLTexturePrivate::setCompressedData(int mipLevel, int layer, QOpenGLTexture::CubeMapFace cubeFace,
+void QOpenGLTexturePrivate::setCompressedData(int mipLevel, int layer, int layerCount,
+ QOpenGLTexture::CubeMapFace cubeFace,
int dataSize, const void *data,
const QOpenGLPixelTransferOptions * const options)
{
@@ -1465,6 +1471,7 @@ void QOpenGLTexturePrivate::setCompressedData(int mipLevel, int layer, QOpenGLTe
case QOpenGLTexture::Target1D:
Q_UNUSED(layer);
Q_UNUSED(cubeFace);
+ Q_UNUSED(layerCount);
if (needsFullSpec) {
texFuncs->glCompressedTextureImage1D(textureId, target, bindingTarget, mipLevel,
format,
@@ -1483,7 +1490,7 @@ void QOpenGLTexturePrivate::setCompressedData(int mipLevel, int layer, QOpenGLTe
texFuncs->glCompressedTextureSubImage2D(textureId, target, bindingTarget, mipLevel,
0, layer,
mipLevelSize(mipLevel, dimensions[0]),
- 1,
+ layerCount,
format, dataSize, data, options);
}
break;
@@ -1491,6 +1498,7 @@ void QOpenGLTexturePrivate::setCompressedData(int mipLevel, int layer, QOpenGLTe
case QOpenGLTexture::Target2D:
Q_UNUSED(layer);
Q_UNUSED(cubeFace);
+ Q_UNUSED(layerCount);
if (needsFullSpec) {
texFuncs->glCompressedTextureImage2D(textureId, target, bindingTarget, mipLevel,
format,
@@ -1513,13 +1521,14 @@ void QOpenGLTexturePrivate::setCompressedData(int mipLevel, int layer, QOpenGLTe
0, 0, layer,
mipLevelSize(mipLevel, dimensions[0]),
mipLevelSize(mipLevel, dimensions[1]),
- 1,
+ layerCount,
format, dataSize, data, options);
}
break;
case QOpenGLTexture::Target3D:
Q_UNUSED(cubeFace);
+ Q_UNUSED(layerCount);
if (needsFullSpec) {
texFuncs->glCompressedTextureImage3D(textureId, target, bindingTarget, mipLevel,
format,
@@ -1539,6 +1548,7 @@ void QOpenGLTexturePrivate::setCompressedData(int mipLevel, int layer, QOpenGLTe
case QOpenGLTexture::TargetCubeMap:
Q_UNUSED(layer);
+ Q_UNUSED(layerCount);
if (needsFullSpec) {
texFuncs->glCompressedTextureImage2D(textureId, cubeFace, bindingTarget, mipLevel,
format,
@@ -1562,7 +1572,7 @@ void QOpenGLTexturePrivate::setCompressedData(int mipLevel, int layer, QOpenGLTe
0, 0, layerFace,
mipLevelSize(mipLevel, dimensions[0]),
mipLevelSize(mipLevel, dimensions[1]),
- 1,
+ layerCount,
format, dataSize, data, options);
}
break;
@@ -3286,7 +3296,23 @@ void QOpenGLTexture::setData(int mipLevel, int layer, CubeMapFace cubeFace,
"To do so call allocateStorage() before this function");
return;
}
- d->setData(mipLevel, layer, cubeFace, sourceFormat, sourceType, data, options);
+ d->setData(mipLevel, layer, 1, cubeFace, sourceFormat, sourceType, data, options);
+}
+
+/*!
+ \since 5.9
+ \overload
+*/
+void QOpenGLTexture::setData(int mipLevel, int layer, int layerCount, QOpenGLTexture::CubeMapFace cubeFace, QOpenGLTexture::PixelFormat sourceFormat, QOpenGLTexture::PixelType sourceType, const void *data, const QOpenGLPixelTransferOptions * const options)
+{
+ Q_D(QOpenGLTexture);
+ Q_ASSERT(d->textureId);
+ if (!isStorageAllocated()) {
+ qWarning("Cannot set data on a texture that does not have storage allocated.\n"
+ "To do so call allocateStorage() before this function");
+ return;
+ }
+ d->setData(mipLevel, layer, layerCount, cubeFace, sourceFormat, sourceType, data, options);
}
/*!
@@ -3299,7 +3325,7 @@ void QOpenGLTexture::setData(int mipLevel, int layer,
{
Q_D(QOpenGLTexture);
Q_ASSERT(d->textureId);
- d->setData(mipLevel, layer, QOpenGLTexture::CubeMapPositiveX, sourceFormat, sourceType, data, options);
+ d->setData(mipLevel, layer, 1, QOpenGLTexture::CubeMapPositiveX, sourceFormat, sourceType, data, options);
}
/*!
@@ -3312,7 +3338,7 @@ void QOpenGLTexture::setData(int mipLevel,
{
Q_D(QOpenGLTexture);
Q_ASSERT(d->textureId);
- d->setData(mipLevel, 0, QOpenGLTexture::CubeMapPositiveX, sourceFormat, sourceType, data, options);
+ d->setData(mipLevel, 0, 1, QOpenGLTexture::CubeMapPositiveX, sourceFormat, sourceType, data, options);
}
/*!
@@ -3324,7 +3350,7 @@ void QOpenGLTexture::setData(PixelFormat sourceFormat, PixelType sourceType,
{
Q_D(QOpenGLTexture);
Q_ASSERT(d->textureId);
- d->setData(0, 0, QOpenGLTexture::CubeMapPositiveX, sourceFormat, sourceType, data, options);
+ d->setData(0, 0, 1, QOpenGLTexture::CubeMapPositiveX, sourceFormat, sourceType, data, options);
}
#if QT_DEPRECATED_SINCE(5, 3)
@@ -3345,7 +3371,7 @@ void QOpenGLTexture::setData(int mipLevel, int layer, CubeMapFace cubeFace,
"To do so call allocateStorage() before this function");
return;
}
- d->setData(mipLevel, layer, cubeFace, sourceFormat, sourceType, data, options);
+ d->setData(mipLevel, layer, 1, cubeFace, sourceFormat, sourceType, data, options);
}
/*!
@@ -3358,7 +3384,7 @@ void QOpenGLTexture::setData(int mipLevel, int layer,
{
Q_D(QOpenGLTexture);
Q_ASSERT(d->textureId);
- d->setData(mipLevel, layer, QOpenGLTexture::CubeMapPositiveX, sourceFormat, sourceType, data, options);
+ d->setData(mipLevel, layer, 1, QOpenGLTexture::CubeMapPositiveX, sourceFormat, sourceType, data, options);
}
/*!
@@ -3371,7 +3397,7 @@ void QOpenGLTexture::setData(int mipLevel,
{
Q_D(QOpenGLTexture);
Q_ASSERT(d->textureId);
- d->setData(mipLevel, 0, QOpenGLTexture::CubeMapPositiveX, sourceFormat, sourceType, data, options);
+ d->setData(mipLevel, 0, 1, QOpenGLTexture::CubeMapPositiveX, sourceFormat, sourceType, data, options);
}
/*!
@@ -3383,7 +3409,7 @@ void QOpenGLTexture::setData(PixelFormat sourceFormat, PixelType sourceType,
{
Q_D(QOpenGLTexture);
Q_ASSERT(d->textureId);
- d->setData(0, 0, QOpenGLTexture::CubeMapPositiveX, sourceFormat, sourceType, data, options);
+ d->setData(0, 0, 1, QOpenGLTexture::CubeMapPositiveX, sourceFormat, sourceType, data, options);
}
#endif
@@ -3444,7 +3470,23 @@ void QOpenGLTexture::setCompressedData(int mipLevel, int layer, CubeMapFace cube
"To do so call allocateStorage() before this function");
return;
}
- d->setCompressedData(mipLevel, layer, cubeFace, dataSize, data, options);
+ d->setCompressedData(mipLevel, layer, 1, cubeFace, dataSize, data, options);
+}
+
+/*!
+ \since 5.9
+ \overload
+*/
+void QOpenGLTexture::setCompressedData(int mipLevel, int layer, int layerCount, QOpenGLTexture::CubeMapFace cubeFace, int dataSize, const void *data, const QOpenGLPixelTransferOptions * const options)
+{
+ Q_D(QOpenGLTexture);
+ Q_ASSERT(d->textureId);
+ if (!isStorageAllocated()) {
+ qWarning("Cannot set data on a texture that does not have storage allocated.\n"
+ "To do so call allocateStorage() before this function");
+ return;
+ }
+ d->setCompressedData(mipLevel, layer, layerCount, cubeFace, dataSize, data, options);
}
/*!
@@ -3455,7 +3497,7 @@ void QOpenGLTexture::setCompressedData(int mipLevel, int layer, int dataSize, co
{
Q_D(QOpenGLTexture);
Q_ASSERT(d->textureId);
- d->setCompressedData(mipLevel, layer, QOpenGLTexture::CubeMapPositiveX, dataSize, data, options);
+ d->setCompressedData(mipLevel, layer, 1, QOpenGLTexture::CubeMapPositiveX, dataSize, data, options);
}
/*!
@@ -3466,7 +3508,7 @@ void QOpenGLTexture::setCompressedData(int mipLevel, int dataSize, const void *d
{
Q_D(QOpenGLTexture);
Q_ASSERT(d->textureId);
- d->setCompressedData(mipLevel, 0, QOpenGLTexture::CubeMapPositiveX, dataSize, data, options);
+ d->setCompressedData(mipLevel, 0, 1, QOpenGLTexture::CubeMapPositiveX, dataSize, data, options);
}
/*!
@@ -3477,7 +3519,7 @@ void QOpenGLTexture::setCompressedData(int dataSize, const void *data,
{
Q_D(QOpenGLTexture);
Q_ASSERT(d->textureId);
- d->setCompressedData(0, 0, QOpenGLTexture::CubeMapPositiveX, dataSize, data, options);
+ d->setCompressedData(0, 0, 1, QOpenGLTexture::CubeMapPositiveX, dataSize, data, options);
}
#if QT_DEPRECATED_SINCE(5, 3)
@@ -3496,7 +3538,7 @@ void QOpenGLTexture::setCompressedData(int mipLevel, int layer, CubeMapFace cube
"To do so call allocateStorage() before this function");
return;
}
- d->setCompressedData(mipLevel, layer, cubeFace, dataSize, data, options);
+ d->setCompressedData(mipLevel, layer, 1, cubeFace, dataSize, data, options);
}
/*!
@@ -3508,7 +3550,7 @@ void QOpenGLTexture::setCompressedData(int mipLevel, int layer, int dataSize, vo
{
Q_D(QOpenGLTexture);
Q_ASSERT(d->textureId);
- d->setCompressedData(mipLevel, layer, QOpenGLTexture::CubeMapPositiveX, dataSize, data, options);
+ d->setCompressedData(mipLevel, layer, 1, QOpenGLTexture::CubeMapPositiveX, dataSize, data, options);
}
/*!
@@ -3520,7 +3562,7 @@ void QOpenGLTexture::setCompressedData(int mipLevel, int dataSize, void *data,
{
Q_D(QOpenGLTexture);
Q_ASSERT(d->textureId);
- d->setCompressedData(mipLevel, 0, QOpenGLTexture::CubeMapPositiveX, dataSize, data, options);
+ d->setCompressedData(mipLevel, 0, 1, QOpenGLTexture::CubeMapPositiveX, dataSize, data, options);
}
/*!
@@ -3532,7 +3574,7 @@ void QOpenGLTexture::setCompressedData(int dataSize, void *data,
{
Q_D(QOpenGLTexture);
Q_ASSERT(d->textureId);
- d->setCompressedData(0, 0, QOpenGLTexture::CubeMapPositiveX, dataSize, data, options);
+ d->setCompressedData(0, 0, 1, QOpenGLTexture::CubeMapPositiveX, dataSize, data, options);
}
#endif
diff --git a/src/gui/opengl/qopengltexture.h b/src/gui/opengl/qopengltexture.h
index d0a3bfec8b..6e6f7ef1f2 100644
--- a/src/gui/opengl/qopengltexture.h
+++ b/src/gui/opengl/qopengltexture.h
@@ -472,6 +472,9 @@ public:
void setData(int mipLevel, int layer, CubeMapFace cubeFace,
PixelFormat sourceFormat, PixelType sourceType,
const void *data, const QOpenGLPixelTransferOptions * const options = Q_NULLPTR);
+ void setData(int mipLevel, int layer, int layerCount, CubeMapFace cubeFace,
+ PixelFormat sourceFormat, PixelType sourceType,
+ const void *data, const QOpenGLPixelTransferOptions * const options = Q_NULLPTR);
void setData(int mipLevel, int layer,
PixelFormat sourceFormat, PixelType sourceType,
const void *data, const QOpenGLPixelTransferOptions * const options = Q_NULLPTR);
@@ -499,6 +502,9 @@ public:
void setCompressedData(int mipLevel, int layer, CubeMapFace cubeFace,
int dataSize, const void *data,
const QOpenGLPixelTransferOptions * const options = Q_NULLPTR);
+ void setCompressedData(int mipLevel, int layer, int layerCount, CubeMapFace cubeFace,
+ int dataSize, const void *data,
+ const QOpenGLPixelTransferOptions * const options = Q_NULLPTR);
void setCompressedData(int mipLevel, int layer,
int dataSize, const void *data,
const QOpenGLPixelTransferOptions * const options = Q_NULLPTR);
diff --git a/src/gui/opengl/qopengltexture_p.h b/src/gui/opengl/qopengltexture_p.h
index 9914316bb4..f7694f77bc 100644
--- a/src/gui/opengl/qopengltexture_p.h
+++ b/src/gui/opengl/qopengltexture_p.h
@@ -98,13 +98,14 @@ public:
void allocateStorage(QOpenGLTexture::PixelFormat pixelFormat, QOpenGLTexture::PixelType pixelType);
void allocateMutableStorage(QOpenGLTexture::PixelFormat pixelFormat, QOpenGLTexture::PixelType pixelType);
void allocateImmutableStorage();
- void setData(int mipLevel, int layer, QOpenGLTexture::CubeMapFace cubeFace,
+ void setData(int mipLevel, int layer, int layerCount, QOpenGLTexture::CubeMapFace cubeFace,
QOpenGLTexture::PixelFormat sourceFormat, QOpenGLTexture::PixelType sourceType,
const void *data, const QOpenGLPixelTransferOptions * const options);
- void setCompressedData(int mipLevel, int layer, QOpenGLTexture::CubeMapFace cubeFace,
+ void setCompressedData(int mipLevel, int layer, int layerCount, QOpenGLTexture::CubeMapFace cubeFace,
int dataSize, const void *data,
const QOpenGLPixelTransferOptions * const options);
+
void setWrapMode(QOpenGLTexture::WrapMode mode);
void setWrapMode(QOpenGLTexture::CoordinateDirection direction, QOpenGLTexture::WrapMode mode);
QOpenGLTexture::WrapMode wrapMode(QOpenGLTexture::CoordinateDirection direction) const;
diff --git a/src/gui/opengl/qopengltextureblitter.cpp b/src/gui/opengl/qopengltextureblitter.cpp
index 858fc0d857..b65df9dc82 100644
--- a/src/gui/opengl/qopengltextureblitter.cpp
+++ b/src/gui/opengl/qopengltextureblitter.cpp
@@ -330,8 +330,8 @@ bool QOpenGLTextureBlitterPrivate::buildProgram(ProgramIndex idx, const char *vs
p->glProgram.reset(new QOpenGLShaderProgram);
- p->glProgram->addShaderFromSourceCode(QOpenGLShader::Vertex, vs);
- p->glProgram->addShaderFromSourceCode(QOpenGLShader::Fragment, fs);
+ p->glProgram->addCacheableShaderFromSourceCode(QOpenGLShader::Vertex, vs);
+ p->glProgram->addCacheableShaderFromSourceCode(QOpenGLShader::Fragment, fs);
p->glProgram->link();
if (!p->glProgram->isLinked()) {
qWarning() << "Could not link shader program:\n" << p->glProgram->log();
diff --git a/src/gui/opengl/qopengltexturecache.cpp b/src/gui/opengl/qopengltexturecache.cpp
index 688226551d..27aa8db33a 100644
--- a/src/gui/opengl/qopengltexturecache.cpp
+++ b/src/gui/opengl/qopengltexturecache.cpp
@@ -371,7 +371,7 @@ static void freeTexture(QOpenGLFunctions *funcs, GLuint id)
funcs->glDeleteTextures(1, &id);
}
-QOpenGLCachedTexture::QOpenGLCachedTexture(GLuint id, int options, QOpenGLContext *context) : m_options(options)
+QOpenGLCachedTexture::QOpenGLCachedTexture(GLuint id, QOpenGLTextureCache::BindOptions options, QOpenGLContext *context) : m_options(options)
{
m_resource = new QOpenGLSharedResourceGuard(context, id, freeTexture);
}
diff --git a/src/gui/opengl/qopengltexturecache_p.h b/src/gui/opengl/qopengltexturecache_p.h
index c68b068739..4a438c8d95 100644
--- a/src/gui/opengl/qopengltexturecache_p.h
+++ b/src/gui/opengl/qopengltexturecache_p.h
@@ -60,19 +60,7 @@
QT_BEGIN_NAMESPACE
-class QOpenGLCachedTexture
-{
-public:
- QOpenGLCachedTexture(GLuint id, int options, QOpenGLContext *context);
- ~QOpenGLCachedTexture() { m_resource->free(); }
-
- GLuint id() const { return m_resource->id(); }
- int options() const { return m_options; }
-
-private:
- QOpenGLSharedResourceGuard *m_resource;
- int m_options;
-};
+class QOpenGLCachedTexture;
class Q_GUI_EXPORT QOpenGLTextureCache : public QOpenGLSharedResource
{
@@ -106,6 +94,20 @@ private:
Q_DECLARE_OPERATORS_FOR_FLAGS(QOpenGLTextureCache::BindOptions)
+class QOpenGLCachedTexture
+{
+public:
+ QOpenGLCachedTexture(GLuint id, QOpenGLTextureCache::BindOptions options, QOpenGLContext *context);
+ ~QOpenGLCachedTexture() { m_resource->free(); }
+
+ GLuint id() const { return m_resource->id(); }
+ QOpenGLTextureCache::BindOptions options() const { return m_options; }
+
+private:
+ QOpenGLSharedResourceGuard *m_resource;
+ QOpenGLTextureCache::BindOptions m_options;
+};
+
QT_END_NAMESPACE
#endif
diff --git a/src/gui/opengl/qopengltextureglyphcache.cpp b/src/gui/opengl/qopengltextureglyphcache.cpp
index 9a7b1eb21d..62b069a1d0 100644
--- a/src/gui/opengl/qopengltextureglyphcache.cpp
+++ b/src/gui/opengl/qopengltextureglyphcache.cpp
@@ -342,22 +342,14 @@ void QOpenGLTextureGlyphCache::resizeTextureData(int width, int height)
QString source;
source.append(QLatin1String(isCoreProfile ? qopenglslMainWithTexCoordsVertexShader_core : qopenglslMainWithTexCoordsVertexShader));
source.append(QLatin1String(isCoreProfile ? qopenglslUntransformedPositionVertexShader_core : qopenglslUntransformedPositionVertexShader));
-
- QOpenGLShader *vertexShader = new QOpenGLShader(QOpenGLShader::Vertex, m_blitProgram);
- vertexShader->compileSourceCode(source);
-
- m_blitProgram->addShader(vertexShader);
+ m_blitProgram->addCacheableShaderFromSourceCode(QOpenGLShader::Vertex, source);
}
{
QString source;
source.append(QLatin1String(isCoreProfile ? qopenglslMainFragmentShader_core : qopenglslMainFragmentShader));
source.append(QLatin1String(isCoreProfile ? qopenglslImageSrcFragmentShader_core : qopenglslImageSrcFragmentShader));
-
- QOpenGLShader *fragmentShader = new QOpenGLShader(QOpenGLShader::Fragment, m_blitProgram);
- fragmentShader->compileSourceCode(source);
-
- m_blitProgram->addShader(fragmentShader);
+ m_blitProgram->addCacheableShaderFromSourceCode(QOpenGLShader::Fragment, source);
}
m_blitProgram->bindAttributeLocation("vertexCoordsArray", QT_VERTEX_COORDS_ATTR);
@@ -380,8 +372,8 @@ void QOpenGLTextureGlyphCache::resizeTextureData(int width, int height)
blitProgram = m_blitProgram;
} else {
- pex->setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, m_vertexCoordinateArray);
- pex->setVertexAttributePointer(QT_TEXTURE_COORDS_ATTR, m_textureCoordinateArray);
+ pex->uploadData(QT_VERTEX_COORDS_ATTR, m_vertexCoordinateArray, 8);
+ pex->uploadData(QT_TEXTURE_COORDS_ATTR, m_textureCoordinateArray, 8);
pex->shaderManager->useBlitProgram();
blitProgram = pex->shaderManager->blitProgram();
diff --git a/src/gui/painting/painting.pri b/src/gui/painting/painting.pri
index 86e35c39f8..63e345545c 100644
--- a/src/gui/painting/painting.pri
+++ b/src/gui/painting/painting.pri
@@ -8,6 +8,7 @@ HEADERS += \
painting/qbrush.h \
painting/qcolor.h \
painting/qcolor_p.h \
+ painting/qcolorprofile_p.h \
painting/qcosmeticstroker_p.h \
painting/qdatabuffer_p.h \
painting/qdrawhelper_p.h \
@@ -63,11 +64,11 @@ SOURCES += \
painting/qblittable.cpp \
painting/qbrush.cpp \
painting/qcolor.cpp \
+ painting/qcolorprofile.cpp \
painting/qcompositionfunctions.cpp \
painting/qcosmeticstroker.cpp \
painting/qdrawhelper.cpp \
painting/qemulationpaintengine.cpp \
- painting/qgammatables.cpp \
painting/qgrayraster.c \
painting/qimagescale.cpp \
painting/qmatrix.cpp \
diff --git a/src/gui/painting/qbrush.cpp b/src/gui/painting/qbrush.cpp
index ebb035a2c1..06a820a859 100644
--- a/src/gui/painting/qbrush.cpp
+++ b/src/gui/painting/qbrush.cpp
@@ -1419,6 +1419,25 @@ void QGradient::setColorAt(qreal pos, const QColor &color)
m_stops.insert(index, QGradientStop(pos, color));
}
+static inline bool ok(QGradientStop stop)
+{
+ return stop.first >= 0 && stop.first <= 1; // rejects NaNs
+}
+
+static inline bool ok(const QGradientStops &stops)
+{
+ qreal lastPos = -1;
+ for (const QGradientStop &stop : stops) {
+ if (Q_UNLIKELY(!ok(stop)))
+ return false;
+ const bool sorted = stop.first > lastPos; // rejects duplicates
+ if (Q_UNLIKELY(!sorted))
+ return false;
+ lastPos = stop.first;
+ }
+ return true;
+}
+
/*!
\fn void QGradient::setStops(const QGradientStops &stopPoints)
@@ -1430,6 +1449,14 @@ void QGradient::setColorAt(qreal pos, const QColor &color)
*/
void QGradient::setStops(const QGradientStops &stops)
{
+ // ## Qt 6: consider taking \a stops by value, so we can move into m_stops
+ if (Q_LIKELY(ok(stops))) {
+ // fast path for the common case: if everything is ok with the stops, just copy them
+ m_stops = stops;
+ return;
+ }
+ // otherwise, to keep the pre-5.9 behavior, add them one after another,
+ // so each stop is checked, invalid ones are skipped, they are added in-order (which may be O(N^2)).
m_stops.clear();
for (int i=0; i<stops.size(); ++i)
setColorAt(stops.at(i).first, stops.at(i).second);
diff --git a/src/gui/painting/qgammatables.cpp b/src/gui/painting/qcolorprofile.cpp
index 1d76f7ee3c..3b7b0a248b 100644
--- a/src/gui/painting/qgammatables.cpp
+++ b/src/gui/painting/qcolorprofile.cpp
@@ -37,28 +37,51 @@
**
****************************************************************************/
-#include <private/qdrawhelper_p.h>
+#include "qcolorprofile_p.h"
+#include <qmath.h>
QT_BEGIN_NAMESPACE
+QColorProfile *QColorProfile::fromGamma(qreal gamma)
+{
+ QColorProfile *cp = new QColorProfile;
+
+ for (int i = 0; i <= (255 * 16); ++i) {
+ cp->m_toLinear[i] = ushort(qRound(qPow(i / qreal(255 * 16), gamma) * (255 * 256)));
+ cp->m_fromLinear[i] = ushort(qRound(qPow(i / qreal(255 * 16), qreal(1) / gamma) * (255 * 256)));
+ }
+
+ return cp;
+}
-QDrawHelperGammaTables::QDrawHelperGammaTables(qreal smoothing)
+static qreal srgbToLinear(qreal v)
{
- const qreal gray_gamma = 2.31;
- for (int i=0; i<256; ++i)
- qt_pow_gamma[i] = uint(qRound(qPow(i / qreal(255.), gray_gamma) * 2047));
- for (int i=0; i<2048; ++i)
- qt_pow_invgamma[i] = uchar(qRound(qPow(i / qreal(2047.0), 1 / gray_gamma) * 255));
+ const qreal a = 0.055;
+ if (v <= qreal(0.04045))
+ return v / qreal(12.92);
+ else
+ return qPow((v + a) / (qreal(1) + a), qreal(2.4));
+}
- refresh(smoothing);
+static qreal linearToSrgb(qreal v)
+{
+ const qreal a = 0.055;
+ if (v <= qreal(0.0031308))
+ return v * qreal(12.92);
+ else
+ return (qreal(1) + a) * qPow(v, qreal(1.0 / 2.4)) - a;
}
-void QDrawHelperGammaTables::refresh(qreal smoothing)
+QColorProfile *QColorProfile::fromSRgb()
{
- for (int i=0; i<256; ++i) {
- qt_pow_rgb_gamma[i] = uchar(qRound(qPow(i / qreal(255.0), smoothing) * 255));
- qt_pow_rgb_invgamma[i] = uchar(qRound(qPow(i / qreal(255.), 1 / smoothing) * 255));
+ QColorProfile *cp = new QColorProfile;
+
+ for (int i = 0; i <= (255 * 16); ++i) {
+ cp->m_toLinear[i] = ushort(qRound(srgbToLinear(i / qreal(255 * 16)) * (255 * 256)));
+ cp->m_fromLinear[i] = ushort(qRound(linearToSrgb(i / qreal(255 * 16)) * (255 * 256)));
}
+
+ return cp;
}
QT_END_NAMESPACE
diff --git a/src/gui/painting/qcolorprofile_p.h b/src/gui/painting/qcolorprofile_p.h
new file mode 100644
index 0000000000..ca1786ee6d
--- /dev/null
+++ b/src/gui/painting/qcolorprofile_p.h
@@ -0,0 +1,157 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QCOLORPROFILE_P_H
+#define QCOLORPROFILE_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtGui/private/qtguiglobal_p.h>
+#include <QtGui/qrgb.h>
+#include <QtGui/qrgba64.h>
+
+QT_BEGIN_NAMESPACE
+
+class Q_GUI_EXPORT QColorProfile
+{
+public:
+ static QColorProfile *fromGamma(qreal gamma);
+ static QColorProfile *fromSRgb();
+
+ // The following methods all convert opaque or unpremultiplied colors:
+
+ QRgba64 toLinear64(QRgb rgb32) const
+ {
+ ushort r = m_toLinear[qRed(rgb32) << 4];
+ ushort g = m_toLinear[qGreen(rgb32) << 4];
+ ushort b = m_toLinear[qBlue(rgb32) << 4];
+ r = r + (r >> 8);
+ g = g + (g >> 8);
+ b = b + (b >> 8);
+ return QRgba64::fromRgba64(r, g, b, qAlpha(rgb32) * 257);
+ }
+
+ QRgb toLinear(QRgb rgb32) const
+ {
+ uchar r = (m_toLinear[qRed(rgb32) << 4] + 0x80) >> 8;
+ uchar g = (m_toLinear[qGreen(rgb32) << 4] + 0x80) >> 8;
+ uchar b = (m_toLinear[qBlue(rgb32) << 4] + 0x80) >> 8;
+ return qRgba(r, g, b, qAlpha(rgb32));
+ }
+
+ QRgba64 toLinear(QRgba64 rgb64) const
+ {
+ ushort r = rgb64.red();
+ ushort g = rgb64.green();
+ ushort b = rgb64.blue();
+ r = r - (r >> 8);
+ g = g - (g >> 8);
+ b = b - (b >> 8);
+ r = m_toLinear[r >> 4];
+ g = m_toLinear[g >> 4];
+ b = m_toLinear[b >> 4];
+ r = r + (r >> 8);
+ g = g + (g >> 8);
+ b = b + (b >> 8);
+ return QRgba64::fromRgba64(r, g, b, rgb64.alpha());
+ }
+
+ QRgb fromLinear64(QRgba64 rgb64) const
+ {
+ ushort r = rgb64.red();
+ ushort g = rgb64.green();
+ ushort b = rgb64.blue();
+ r = r - (r >> 8);
+ g = g - (g >> 8);
+ b = b - (b >> 8);
+ r = (m_fromLinear[r >> 4] + 0x80) >> 8;
+ g = (m_fromLinear[g >> 4] + 0x80) >> 8;
+ b = (m_fromLinear[b >> 4] + 0x80) >> 8;
+ return qRgba(r, g, b, rgb64.alpha8());
+ }
+
+ QRgb fromLinear(QRgb rgb32) const
+ {
+ uchar r = (m_fromLinear[qRed(rgb32) << 4] + 0x80) >> 8;
+ uchar g = (m_fromLinear[qGreen(rgb32) << 4] + 0x80) >> 8;
+ uchar b = (m_fromLinear[qBlue(rgb32) << 4] + 0x80) >> 8;
+ return qRgba(r, g, b, qAlpha(rgb32));
+ }
+
+ QRgba64 fromLinear(QRgba64 rgb64) const
+ {
+ ushort r = rgb64.red();
+ ushort g = rgb64.green();
+ ushort b = rgb64.blue();
+ r = r - (r >> 8);
+ g = g - (g >> 8);
+ b = b - (b >> 8);
+ r = m_fromLinear[r >> 4];
+ g = m_fromLinear[g >> 4];
+ b = m_fromLinear[b >> 4];
+ r = r + (r >> 8);
+ g = g + (g >> 8);
+ b = b + (b >> 8);
+ return QRgba64::fromRgba64(r, g, b, rgb64.alpha());
+ }
+
+private:
+ QColorProfile() { }
+
+ // We translate to 0-65280 (255*256) instead to 0-65535 to make simple
+ // shifting an accurate conversion.
+ // We translate from 0-4080 (255*16) for the same speed up, and to keep
+ // the tables small enough to fit in most inner caches.
+ ushort m_toLinear[(255 * 16) + 1]; // [0-4080] -> [0-65280]
+ ushort m_fromLinear[(255 * 16) + 1]; // [0-4080] -> [0-65280]
+
+};
+
+QT_END_NAMESPACE
+
+#endif // QCOLORPROFILE_P_H
diff --git a/src/gui/painting/qcoregraphics.mm b/src/gui/painting/qcoregraphics.mm
index 3753fa4e88..a64a184e25 100644
--- a/src/gui/painting/qcoregraphics.mm
+++ b/src/gui/painting/qcoregraphics.mm
@@ -39,6 +39,7 @@
#include <QtGui/private/qpaintengine_p.h>
#include <QtCore/qdebug.h>
#include <QtCore/qcoreapplication.h>
+#include <QtCore/qoperatingsystemversion.h>
QT_BEGIN_NAMESPACE
@@ -106,29 +107,6 @@ QImage qt_mac_toQImage(CGImageRef image)
#ifdef Q_OS_MACOS
-QT_END_NAMESPACE
-
-@interface NSGraphicsContext (QtAdditions)
-
-+ (NSGraphicsContext *)qt_graphicsContextWithCGContext:(CGContextRef)graphicsPort flipped:(BOOL)initialFlippedState;
-
-@end
-
-@implementation NSGraphicsContext (QtAdditions)
-
-+ (NSGraphicsContext *)qt_graphicsContextWithCGContext:(CGContextRef)graphicsPort flipped:(BOOL)initialFlippedState
-{
-#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_10, __IPHONE_NA)
- if (QT_PREPEND_NAMESPACE(QSysInfo::MacintoshVersion) >= QT_PREPEND_NAMESPACE(QSysInfo::MV_10_10))
- return [self graphicsContextWithCGContext:graphicsPort flipped:initialFlippedState];
-#endif
- return [self graphicsContextWithGraphicsPort:graphicsPort flipped:initialFlippedState];
-}
-
-@end
-
-QT_BEGIN_NAMESPACE
-
static NSImage *qt_mac_cgimage_to_nsimage(CGImageRef image)
{
NSImage *newImage = [[NSImage alloc] initWithCGImage:image size:NSZeroSize];
@@ -179,7 +157,7 @@ QPixmap qt_mac_toQPixmap(const NSImage *image, const QSizeF &size)
QMacCGContext ctx(&pixmap);
if (!ctx)
return QPixmap();
- NSGraphicsContext *gc = [NSGraphicsContext qt_graphicsContextWithCGContext:ctx flipped:YES];
+ NSGraphicsContext *gc = [NSGraphicsContext graphicsContextWithCGContext:ctx flipped:YES];
if (!gc)
return QPixmap();
[NSGraphicsContext saveGraphicsState];
diff --git a/src/gui/painting/qdrawhelper.cpp b/src/gui/painting/qdrawhelper.cpp
index 298304c4ef..9b5f15470e 100644
--- a/src/gui/painting/qdrawhelper.cpp
+++ b/src/gui/painting/qdrawhelper.cpp
@@ -43,6 +43,7 @@
#include <qstylehints.h>
#include <qguiapplication.h>
#include <qatomic.h>
+#include <private/qcolorprofile_p.h>
#include <private/qdrawhelper_p.h>
#include <private/qpaintengine_raster_p.h>
#include <private/qpainter_p.h>
@@ -1320,7 +1321,7 @@ static void QT_FASTCALL destStore(QRasterBuffer *rasterBuffer, int x, int y, con
static void QT_FASTCALL convertFromRgb64(uint *dest, const QRgba64 *src, int length)
{
for (int i = 0; i < length; ++i) {
- dest[i] = src[i].toArgb32();
+ dest[i] = toArgb32(src[i]);
}
}
@@ -1411,7 +1412,7 @@ static void QT_FASTCALL destStore64ARGB32(QRasterBuffer *rasterBuffer, int x, in
{
uint *dest = (uint*)rasterBuffer->scanLine(y) + x;
for (int i = 0; i < length; ++i) {
- dest[i] = buffer[i].unpremultiplied().toArgb32();
+ dest[i] = toArgb32(buffer[i].unpremultiplied());
}
}
@@ -1419,7 +1420,7 @@ static void QT_FASTCALL destStore64RGBA8888(QRasterBuffer *rasterBuffer, int x,
{
uint *dest = (uint*)rasterBuffer->scanLine(y) + x;
for (int i = 0; i < length; ++i) {
- dest[i] = ARGB2RGBA(buffer[i].unpremultiplied().toArgb32());
+ dest[i] = toRgba8888(buffer[i].unpremultiplied());
}
}
@@ -1918,562 +1919,695 @@ inline void fetchTransformedBilinear_pixelBounds<BlendTransformedBilinear>(int,
Q_ASSERT(v2 >= l1 && v2 <= l2);
}
-template<TextureBlendType blendType> /* blendType = BlendTransformedBilinear or BlendTransformedBilinearTiled */
-static const uint * QT_FASTCALL fetchTransformedBilinearARGB32PM(uint *buffer, const Operator *,
- const QSpanData *data, int y, int x,
- int length)
-{
- int image_width = data->texture.width;
- int image_height = data->texture.height;
-
- int image_x1 = data->texture.x1;
- int image_y1 = data->texture.y1;
- int image_x2 = data->texture.x2 - 1;
- int image_y2 = data->texture.y2 - 1;
-
- const qreal cx = x + qreal(0.5);
- const qreal cy = y + qreal(0.5);
-
- uint *end = buffer + length;
- uint *b = buffer;
- if (data->fast_matrix) {
- // The increment pr x in the scanline
- int fdx = (int)(data->m11 * fixed_scale);
- int fdy = (int)(data->m12 * fixed_scale);
-
- int fx = int((data->m21 * cy
- + data->m11 * cx + data->dx) * fixed_scale);
- int fy = int((data->m22 * cy
- + data->m12 * cx + data->dy) * fixed_scale);
-
- fx -= half_point;
- fy -= half_point;
-
- if (fdy == 0) { //simple scale, no rotation
- int y1 = (fy >> 16);
- int y2;
- fetchTransformedBilinear_pixelBounds<blendType>(image_height, image_y1, image_y2, y1, y2);
- const uint *s1 = (const uint *)data->texture.scanLine(y1);
- const uint *s2 = (const uint *)data->texture.scanLine(y2);
-
- if (fdx <= fixed_scale && fdx > 0) { // scale up on X
- int disty = (fy & 0x0000ffff) >> 8;
- int idisty = 256 - disty;
- int x = fx >> 16;
+enum FastTransformTypes {
+ SimpleUpscaleTransform,
+ UpscaleTransform,
+ DownscaleTransform,
+ RotateTransform,
+ FastRotateTransform,
+ NFastTransformTypes
+};
- // The idea is first to do the interpolation between the row s1 and the row s2
- // into an intermediate buffer, then we interpolate between two pixel of this buffer.
+typedef void (QT_FASTCALL *BilinearFastTransformHelper)(uint *b, uint *end, const QTextureData &image, int &fx, int &fy, int fdx, int fdy);
- // intermediate_buffer[0] is a buffer of red-blue component of the pixel, in the form 0x00RR00BB
- // intermediate_buffer[1] is the alpha-green component of the pixel, in the form 0x00AA00GG
- // +1 for the last pixel to interpolate with, and +1 for rounding errors.
- quint32 intermediate_buffer[2][buffer_size + 2];
- // count is the size used in the intermediate_buffer.
- int count = (qint64(length) * fdx + fixed_scale - 1) / fixed_scale + 2;
- Q_ASSERT(count <= buffer_size + 2); //length is supposed to be <= buffer_size and data->m11 < 1 in this case
- int f = 0;
- int lim = count;
- if (blendType == BlendTransformedBilinearTiled) {
- x %= image_width;
- if (x < 0) x += image_width;
- } else {
- lim = qMin(count, image_x2-x+1);
- if (x < image_x1) {
- Q_ASSERT(x <= image_x2);
- uint t = s1[image_x1];
- uint b = s2[image_x1];
- quint32 rb = (((t & 0xff00ff) * idisty + (b & 0xff00ff) * disty) >> 8) & 0xff00ff;
- quint32 ag = ((((t>>8) & 0xff00ff) * idisty + ((b>>8) & 0xff00ff) * disty) >> 8) & 0xff00ff;
- do {
- intermediate_buffer[0][f] = rb;
- intermediate_buffer[1][f] = ag;
- f++;
- x++;
- } while (x < image_x1 && f < lim);
- }
- }
+template<TextureBlendType blendType>
+static void QT_FASTCALL fetchTransformedBilinearARGB32PM_simple_upscale_helper(uint *b, uint *end, const QTextureData &image,
+ int &fx, int &fy, int fdx, int /*fdy*/)
+{
+ int y1 = (fy >> 16);
+ int y2;
+ fetchTransformedBilinear_pixelBounds<blendType>(image.height, image.y1, image.y2 - 1, y1, y2);
+ const uint *s1 = (const uint *)image.scanLine(y1);
+ const uint *s2 = (const uint *)image.scanLine(y2);
+
+ int disty = (fy & 0x0000ffff) >> 8;
+ int idisty = 256 - disty;
+ int x = fx >> 16;
+ int length = end - b;
+
+ // The idea is first to do the interpolation between the row s1 and the row s2
+ // into an intermediate buffer, then we interpolate between two pixel of this buffer.
+
+ // intermediate_buffer[0] is a buffer of red-blue component of the pixel, in the form 0x00RR00BB
+ // intermediate_buffer[1] is the alpha-green component of the pixel, in the form 0x00AA00GG
+ // +1 for the last pixel to interpolate with, and +1 for rounding errors.
+ quint32 intermediate_buffer[2][buffer_size + 2];
+ // count is the size used in the intermediate_buffer.
+ int count = (qint64(length) * fdx + fixed_scale - 1) / fixed_scale + 2;
+ Q_ASSERT(count <= buffer_size + 2); //length is supposed to be <= buffer_size and data->m11 < 1 in this case
+ int f = 0;
+ int lim = count;
+ if (blendType == BlendTransformedBilinearTiled) {
+ x %= image.width;
+ if (x < 0) x += image.width;
+ } else {
+ lim = qMin(count, image.x2 - x);
+ if (x < image.x1) {
+ Q_ASSERT(x < image.x2);
+ uint t = s1[image.x1];
+ uint b = s2[image.x1];
+ quint32 rb = (((t & 0xff00ff) * idisty + (b & 0xff00ff) * disty) >> 8) & 0xff00ff;
+ quint32 ag = ((((t>>8) & 0xff00ff) * idisty + ((b>>8) & 0xff00ff) * disty) >> 8) & 0xff00ff;
+ do {
+ intermediate_buffer[0][f] = rb;
+ intermediate_buffer[1][f] = ag;
+ f++;
+ x++;
+ } while (x < image.x1 && f < lim);
+ }
+ }
- if (blendType != BlendTransformedBilinearTiled) {
+ if (blendType != BlendTransformedBilinearTiled) {
#if defined(__SSE2__)
- const __m128i disty_ = _mm_set1_epi16(disty);
- const __m128i idisty_ = _mm_set1_epi16(idisty);
- const __m128i colorMask = _mm_set1_epi32(0x00ff00ff);
-
- lim -= 3;
- for (; f < lim; x += 4, f += 4) {
- // Load 4 pixels from s1, and split the alpha-green and red-blue component
- __m128i top = _mm_loadu_si128((const __m128i*)((const uint *)(s1)+x));
- __m128i topAG = _mm_srli_epi16(top, 8);
- __m128i topRB = _mm_and_si128(top, colorMask);
- // Multiplies each colour component by idisty
- topAG = _mm_mullo_epi16 (topAG, idisty_);
- topRB = _mm_mullo_epi16 (topRB, idisty_);
-
- // Same for the s2 vector
- __m128i bottom = _mm_loadu_si128((const __m128i*)((const uint *)(s2)+x));
- __m128i bottomAG = _mm_srli_epi16(bottom, 8);
- __m128i bottomRB = _mm_and_si128(bottom, colorMask);
- bottomAG = _mm_mullo_epi16 (bottomAG, disty_);
- bottomRB = _mm_mullo_epi16 (bottomRB, disty_);
-
- // Add the values, and shift to only keep 8 significant bits per colors
- __m128i rAG =_mm_add_epi16(topAG, bottomAG);
- rAG = _mm_srli_epi16(rAG, 8);
- _mm_storeu_si128((__m128i*)(&intermediate_buffer[1][f]), rAG);
- __m128i rRB =_mm_add_epi16(topRB, bottomRB);
- rRB = _mm_srli_epi16(rRB, 8);
- _mm_storeu_si128((__m128i*)(&intermediate_buffer[0][f]), rRB);
- }
+ const __m128i disty_ = _mm_set1_epi16(disty);
+ const __m128i idisty_ = _mm_set1_epi16(idisty);
+ const __m128i colorMask = _mm_set1_epi32(0x00ff00ff);
+
+ lim -= 3;
+ for (; f < lim; x += 4, f += 4) {
+ // Load 4 pixels from s1, and split the alpha-green and red-blue component
+ __m128i top = _mm_loadu_si128((const __m128i*)((const uint *)(s1)+x));
+ __m128i topAG = _mm_srli_epi16(top, 8);
+ __m128i topRB = _mm_and_si128(top, colorMask);
+ // Multiplies each color component by idisty
+ topAG = _mm_mullo_epi16 (topAG, idisty_);
+ topRB = _mm_mullo_epi16 (topRB, idisty_);
+
+ // Same for the s2 vector
+ __m128i bottom = _mm_loadu_si128((const __m128i*)((const uint *)(s2)+x));
+ __m128i bottomAG = _mm_srli_epi16(bottom, 8);
+ __m128i bottomRB = _mm_and_si128(bottom, colorMask);
+ bottomAG = _mm_mullo_epi16 (bottomAG, disty_);
+ bottomRB = _mm_mullo_epi16 (bottomRB, disty_);
+
+ // Add the values, and shift to only keep 8 significant bits per colors
+ __m128i rAG =_mm_add_epi16(topAG, bottomAG);
+ rAG = _mm_srli_epi16(rAG, 8);
+ _mm_storeu_si128((__m128i*)(&intermediate_buffer[1][f]), rAG);
+ __m128i rRB =_mm_add_epi16(topRB, bottomRB);
+ rRB = _mm_srli_epi16(rRB, 8);
+ _mm_storeu_si128((__m128i*)(&intermediate_buffer[0][f]), rRB);
+ }
#elif defined(__ARM_NEON__)
- const int16x8_t disty_ = vdupq_n_s16(disty);
- const int16x8_t idisty_ = vdupq_n_s16(idisty);
- const int16x8_t colorMask = vdupq_n_s16(0x00ff);
-
- lim -= 3;
- for (; f < lim; x += 4, f += 4) {
- // Load 4 pixels from s1, and split the alpha-green and red-blue component
- int16x8_t top = vld1q_s16((int16_t*)((const uint *)(s1)+x));
- int16x8_t topAG = vreinterpretq_s16_u16(vshrq_n_u16(vreinterpretq_u16_s16(top), 8));
- int16x8_t topRB = vandq_s16(top, colorMask);
- // Multiplies each colour component by idisty
- topAG = vmulq_s16(topAG, idisty_);
- topRB = vmulq_s16(topRB, idisty_);
-
- // Same for the s2 vector
- int16x8_t bottom = vld1q_s16((int16_t*)((const uint *)(s2)+x));
- int16x8_t bottomAG = vreinterpretq_s16_u16(vshrq_n_u16(vreinterpretq_u16_s16(bottom), 8));
- int16x8_t bottomRB = vandq_s16(bottom, colorMask);
- bottomAG = vmulq_s16(bottomAG, disty_);
- bottomRB = vmulq_s16(bottomRB, disty_);
-
- // Add the values, and shift to only keep 8 significant bits per colors
- int16x8_t rAG = vaddq_s16(topAG, bottomAG);
- rAG = vreinterpretq_s16_u16(vshrq_n_u16(vreinterpretq_u16_s16(rAG), 8));
- vst1q_s16((int16_t*)(&intermediate_buffer[1][f]), rAG);
- int16x8_t rRB = vaddq_s16(topRB, bottomRB);
- rRB = vreinterpretq_s16_u16(vshrq_n_u16(vreinterpretq_u16_s16(rRB), 8));
- vst1q_s16((int16_t*)(&intermediate_buffer[0][f]), rRB);
- }
+ const int16x8_t disty_ = vdupq_n_s16(disty);
+ const int16x8_t idisty_ = vdupq_n_s16(idisty);
+ const int16x8_t colorMask = vdupq_n_s16(0x00ff);
+
+ lim -= 3;
+ for (; f < lim; x += 4, f += 4) {
+ // Load 4 pixels from s1, and split the alpha-green and red-blue component
+ int16x8_t top = vld1q_s16((int16_t*)((const uint *)(s1)+x));
+ int16x8_t topAG = vreinterpretq_s16_u16(vshrq_n_u16(vreinterpretq_u16_s16(top), 8));
+ int16x8_t topRB = vandq_s16(top, colorMask);
+ // Multiplies each color component by idisty
+ topAG = vmulq_s16(topAG, idisty_);
+ topRB = vmulq_s16(topRB, idisty_);
+
+ // Same for the s2 vector
+ int16x8_t bottom = vld1q_s16((int16_t*)((const uint *)(s2)+x));
+ int16x8_t bottomAG = vreinterpretq_s16_u16(vshrq_n_u16(vreinterpretq_u16_s16(bottom), 8));
+ int16x8_t bottomRB = vandq_s16(bottom, colorMask);
+ bottomAG = vmulq_s16(bottomAG, disty_);
+ bottomRB = vmulq_s16(bottomRB, disty_);
+
+ // Add the values, and shift to only keep 8 significant bits per colors
+ int16x8_t rAG = vaddq_s16(topAG, bottomAG);
+ rAG = vreinterpretq_s16_u16(vshrq_n_u16(vreinterpretq_u16_s16(rAG), 8));
+ vst1q_s16((int16_t*)(&intermediate_buffer[1][f]), rAG);
+ int16x8_t rRB = vaddq_s16(topRB, bottomRB);
+ rRB = vreinterpretq_s16_u16(vshrq_n_u16(vreinterpretq_u16_s16(rRB), 8));
+ vst1q_s16((int16_t*)(&intermediate_buffer[0][f]), rRB);
+ }
#endif
- }
- for (; f < count; f++) { // Same as above but without sse2
- if (blendType == BlendTransformedBilinearTiled) {
- if (x >= image_width) x -= image_width;
- } else {
- x = qMin(x, image_x2);
- }
+ }
+ for (; f < count; f++) { // Same as above but without simd
+ if (blendType == BlendTransformedBilinearTiled) {
+ if (x >= image.width) x -= image.width;
+ } else {
+ x = qMin(x, image.x2 - 1);
+ }
- uint t = s1[x];
- uint b = s2[x];
+ uint t = s1[x];
+ uint b = s2[x];
- intermediate_buffer[0][f] = (((t & 0xff00ff) * idisty + (b & 0xff00ff) * disty) >> 8) & 0xff00ff;
- intermediate_buffer[1][f] = ((((t>>8) & 0xff00ff) * idisty + ((b>>8) & 0xff00ff) * disty) >> 8) & 0xff00ff;
- x++;
- }
- // Now interpolate the values from the intermediate_buffer to get the final result.
- fx &= fixed_scale - 1;
- Q_ASSERT((fx >> 16) == 0);
- while (b < end) {
- int x1 = (fx >> 16);
- int x2 = x1 + 1;
- Q_ASSERT(x1 >= 0);
- Q_ASSERT(x2 < count);
+ intermediate_buffer[0][f] = (((t & 0xff00ff) * idisty + (b & 0xff00ff) * disty) >> 8) & 0xff00ff;
+ intermediate_buffer[1][f] = ((((t>>8) & 0xff00ff) * idisty + ((b>>8) & 0xff00ff) * disty) >> 8) & 0xff00ff;
+ x++;
+ }
+ // Now interpolate the values from the intermediate_buffer to get the final result.
+ fx &= fixed_scale - 1;
+ Q_ASSERT((fx >> 16) == 0);
+ while (b < end) {
+ int x1 = (fx >> 16);
+ int x2 = x1 + 1;
+ Q_ASSERT(x1 >= 0);
+ Q_ASSERT(x2 < count);
+
+ int distx = (fx & 0x0000ffff) >> 8;
+ int idistx = 256 - distx;
+ int rb = ((intermediate_buffer[0][x1] * idistx + intermediate_buffer[0][x2] * distx) >> 8) & 0xff00ff;
+ int ag = (intermediate_buffer[1][x1] * idistx + intermediate_buffer[1][x2] * distx) & 0xff00ff00;
+ *b = rb | ag;
+ b++;
+ fx += fdx;
+ }
+}
- int distx = (fx & 0x0000ffff) >> 8;
- int idistx = 256 - distx;
- int rb = ((intermediate_buffer[0][x1] * idistx + intermediate_buffer[0][x2] * distx) >> 8) & 0xff00ff;
- int ag = (intermediate_buffer[1][x1] * idistx + intermediate_buffer[1][x2] * distx) & 0xff00ff00;
- *b = rb | ag;
- b++;
- fx += fdx;
- }
- } else if ((fdx < 0 && fdx > -(fixed_scale / 8)) || std::abs(data->m22) < (1./8.)) { // scale up more than 8x
- int y1 = (fy >> 16);
- int y2;
- fetchTransformedBilinear_pixelBounds<blendType>(image_height, image_y1, image_y2, y1, y2);
- const uint *s1 = (const uint *)data->texture.scanLine(y1);
- const uint *s2 = (const uint *)data->texture.scanLine(y2);
- int disty = (fy & 0x0000ffff) >> 8;
- while (b < end) {
- int x1 = (fx >> 16);
- int x2;
- fetchTransformedBilinear_pixelBounds<blendType>(image_width, image_x1, image_x2, x1, x2);
- uint tl = s1[x1];
- uint tr = s1[x2];
- uint bl = s2[x1];
- uint br = s2[x2];
- int distx = (fx & 0x0000ffff) >> 8;
- *b = interpolate_4_pixels(tl, tr, bl, br, distx, disty);
+template<TextureBlendType blendType>
+static void QT_FASTCALL fetchTransformedBilinearARGB32PM_upscale_helper(uint *b, uint *end, const QTextureData &image,
+ int &fx, int &fy, int fdx, int /*fdy*/)
+{
+ int y1 = (fy >> 16);
+ int y2;
+ fetchTransformedBilinear_pixelBounds<blendType>(image.height, image.y1, image.y2 - 1, y1, y2);
+ const uint *s1 = (const uint *)image.scanLine(y1);
+ const uint *s2 = (const uint *)image.scanLine(y2);
+ const int disty = (fy & 0x0000ffff) >> 8;
+
+ if (blendType != BlendTransformedBilinearTiled) {
+ const qint64 min_fx = qint64(image.x1) * fixed_scale;
+ const qint64 max_fx = qint64(image.x2 - 1) * fixed_scale;
+ while (b < end) {
+ int x1 = (fx >> 16);
+ int x2;
+ fetchTransformedBilinear_pixelBounds<blendType>(image.width, image.x1, image.x2 - 1, x1, x2);
+ if (x1 != x2)
+ break;
+ uint top = s1[x1];
+ uint bot = s2[x1];
+ *b = INTERPOLATE_PIXEL_256(top, 256 - disty, bot, disty);
+ fx += fdx;
+ ++b;
+ }
+ uint *boundedEnd = end;
+ if (fdx > 0)
+ boundedEnd = qMin(boundedEnd, b + (max_fx - fx) / fdx);
+ else if (fdx < 0)
+ boundedEnd = qMin(boundedEnd, b + (min_fx - fx) / fdx);
+
+ // A fast middle part without boundary checks
+ while (b < boundedEnd) {
+ int x = (fx >> 16);
+ int distx = (fx & 0x0000ffff) >> 8;
+ *b = interpolate_4_pixels(s1 + x, s2 + x, distx, disty);
+ fx += fdx;
+ ++b;
+ }
+ }
- fx += fdx;
- ++b;
- }
- } else { //scale down
- int y1 = (fy >> 16);
- int y2;
- fetchTransformedBilinear_pixelBounds<blendType>(image_height, image_y1, image_y2, y1, y2);
- const uint *s1 = (const uint *)data->texture.scanLine(y1);
- const uint *s2 = (const uint *)data->texture.scanLine(y2);
- const int disty8 = (fy & 0x0000ffff) >> 8;
- const int disty4 = (disty8 + 0x08) >> 4;
-
- if (blendType != BlendTransformedBilinearTiled) {
-#define BILINEAR_DOWNSCALE_BOUNDS_PROLOG \
- const qint64 min_fx = qint64(image_x1) * fixed_scale; \
- const qint64 max_fx = qint64(image_x2) * fixed_scale; \
- while (b < end) { \
- int x1 = (fx >> 16); \
- int x2; \
- fetchTransformedBilinear_pixelBounds<blendType>(image_width, image_x1, image_x2, x1, x2); \
- if (x1 != x2) \
- break; \
- uint top = s1[x1]; \
- uint bot = s2[x1]; \
- *b = INTERPOLATE_PIXEL_256(top, 256 - disty8, bot, disty8); \
- fx += fdx; \
- ++b; \
- } \
- uint *boundedEnd = end; \
- if (fdx > 0) \
- boundedEnd = qMin(boundedEnd, b + (max_fx - fx) / fdx); \
- else if (fdx < 0) \
- boundedEnd = qMin(boundedEnd, b + (min_fx - fx) / fdx); \
- boundedEnd -= 3;
+ while (b < end) {
+ int x1 = (fx >> 16);
+ int x2;
+ fetchTransformedBilinear_pixelBounds<blendType>(image.width, image.x1, image.x2 - 1 , x1, x2);
+ uint tl = s1[x1];
+ uint tr = s1[x2];
+ uint bl = s2[x1];
+ uint br = s2[x2];
+ int distx = (fx & 0x0000ffff) >> 8;
+ *b = interpolate_4_pixels(tl, tr, bl, br, distx, disty);
+
+ fx += fdx;
+ ++b;
+ }
+}
+template<TextureBlendType blendType>
+static void QT_FASTCALL fetchTransformedBilinearARGB32PM_downscale_helper(uint *b, uint *end, const QTextureData &image,
+ int &fx, int &fy, int fdx, int /*fdy*/)
+{
+ int y1 = (fy >> 16);
+ int y2;
+ fetchTransformedBilinear_pixelBounds<blendType>(image.height, image.y1, image.y2 - 1, y1, y2);
+ const uint *s1 = (const uint *)image.scanLine(y1);
+ const uint *s2 = (const uint *)image.scanLine(y2);
+ const int disty8 = (fy & 0x0000ffff) >> 8;
+ const int disty4 = (disty8 + 0x08) >> 4;
+
+ if (blendType != BlendTransformedBilinearTiled) {
+ const qint64 min_fx = qint64(image.x1) * fixed_scale;
+ const qint64 max_fx = qint64(image.x2 - 1) * fixed_scale;
+ while (b < end) {
+ int x1 = (fx >> 16);
+ int x2;
+ fetchTransformedBilinear_pixelBounds<blendType>(image.width, image.x1, image.x2 - 1, x1, x2);
+ if (x1 != x2)
+ break;
+ uint top = s1[x1];
+ uint bot = s2[x1];
+ *b = INTERPOLATE_PIXEL_256(top, 256 - disty8, bot, disty8);
+ fx += fdx;
+ ++b;
+ }
+ uint *boundedEnd = end;
+ if (fdx > 0)
+ boundedEnd = qMin(boundedEnd, b + (max_fx - fx) / fdx);
+ else if (fdx < 0)
+ boundedEnd = qMin(boundedEnd, b + (min_fx - fx) / fdx);
+ // A fast middle part without boundary checks
#if defined(__SSE2__)
- BILINEAR_DOWNSCALE_BOUNDS_PROLOG
-
- const __m128i colorMask = _mm_set1_epi32(0x00ff00ff);
- const __m128i v_256 = _mm_set1_epi16(256);
- const __m128i v_disty = _mm_set1_epi16(disty4);
- const __m128i v_fdx = _mm_set1_epi32(fdx*4);
- const __m128i v_fx_r = _mm_set1_epi32(0x8);
- __m128i v_fx = _mm_setr_epi32(fx, fx + fdx, fx + fdx + fdx, fx + fdx + fdx + fdx);
-
- while (b < boundedEnd) {
- __m128i offset = _mm_srli_epi32(v_fx, 16);
- const int offset0 = _mm_cvtsi128_si32(offset); offset = _mm_srli_si128(offset, 4);
- const int offset1 = _mm_cvtsi128_si32(offset); offset = _mm_srli_si128(offset, 4);
- const int offset2 = _mm_cvtsi128_si32(offset); offset = _mm_srli_si128(offset, 4);
- const int offset3 = _mm_cvtsi128_si32(offset);
- const __m128i tl = _mm_setr_epi32(s1[offset0], s1[offset1], s1[offset2], s1[offset3]);
- const __m128i tr = _mm_setr_epi32(s1[offset0 + 1], s1[offset1 + 1], s1[offset2 + 1], s1[offset3 + 1]);
- const __m128i bl = _mm_setr_epi32(s2[offset0], s2[offset1], s2[offset2], s2[offset3]);
- const __m128i br = _mm_setr_epi32(s2[offset0 + 1], s2[offset1 + 1], s2[offset2 + 1], s2[offset3 + 1]);
-
- __m128i v_distx = _mm_srli_epi16(v_fx, 8);
- v_distx = _mm_srli_epi16(_mm_add_epi32(v_distx, v_fx_r), 4);
- v_distx = _mm_shufflehi_epi16(v_distx, _MM_SHUFFLE(2,2,0,0));
- v_distx = _mm_shufflelo_epi16(v_distx, _MM_SHUFFLE(2,2,0,0));
-
- interpolate_4_pixels_16_sse2(tl, tr, bl, br, v_distx, v_disty, colorMask, v_256, b);
- b += 4;
- v_fx = _mm_add_epi32(v_fx, v_fdx);
- }
- fx = _mm_cvtsi128_si32(v_fx);
+ const __m128i colorMask = _mm_set1_epi32(0x00ff00ff);
+ const __m128i v_256 = _mm_set1_epi16(256);
+ const __m128i v_disty = _mm_set1_epi16(disty4);
+ const __m128i v_fdx = _mm_set1_epi32(fdx*4);
+ const __m128i v_fx_r = _mm_set1_epi32(0x8);
+ __m128i v_fx = _mm_setr_epi32(fx, fx + fdx, fx + fdx + fdx, fx + fdx + fdx + fdx);
+
+ while (b < boundedEnd - 3) {
+ __m128i offset = _mm_srli_epi32(v_fx, 16);
+ const int offset0 = _mm_cvtsi128_si32(offset); offset = _mm_srli_si128(offset, 4);
+ const int offset1 = _mm_cvtsi128_si32(offset); offset = _mm_srli_si128(offset, 4);
+ const int offset2 = _mm_cvtsi128_si32(offset); offset = _mm_srli_si128(offset, 4);
+ const int offset3 = _mm_cvtsi128_si32(offset);
+ const __m128i tl = _mm_setr_epi32(s1[offset0], s1[offset1], s1[offset2], s1[offset3]);
+ const __m128i tr = _mm_setr_epi32(s1[offset0 + 1], s1[offset1 + 1], s1[offset2 + 1], s1[offset3 + 1]);
+ const __m128i bl = _mm_setr_epi32(s2[offset0], s2[offset1], s2[offset2], s2[offset3]);
+ const __m128i br = _mm_setr_epi32(s2[offset0 + 1], s2[offset1 + 1], s2[offset2 + 1], s2[offset3 + 1]);
+
+ __m128i v_distx = _mm_srli_epi16(v_fx, 8);
+ v_distx = _mm_srli_epi16(_mm_add_epi32(v_distx, v_fx_r), 4);
+ v_distx = _mm_shufflehi_epi16(v_distx, _MM_SHUFFLE(2,2,0,0));
+ v_distx = _mm_shufflelo_epi16(v_distx, _MM_SHUFFLE(2,2,0,0));
+
+ interpolate_4_pixels_16_sse2(tl, tr, bl, br, v_distx, v_disty, colorMask, v_256, b);
+ b += 4;
+ v_fx = _mm_add_epi32(v_fx, v_fdx);
+ }
+ fx = _mm_cvtsi128_si32(v_fx);
#elif defined(__ARM_NEON__)
- BILINEAR_DOWNSCALE_BOUNDS_PROLOG
-
- const int16x8_t colorMask = vdupq_n_s16(0x00ff);
- const int16x8_t invColorMask = vmvnq_s16(colorMask);
- const int16x8_t v_256 = vdupq_n_s16(256);
- const int16x8_t v_disty = vdupq_n_s16(disty4);
- const int16x8_t v_disty_ = vshlq_n_s16(v_disty, 4);
- int32x4_t v_fdx = vdupq_n_s32(fdx*4);
+ const int16x8_t colorMask = vdupq_n_s16(0x00ff);
+ const int16x8_t invColorMask = vmvnq_s16(colorMask);
+ const int16x8_t v_256 = vdupq_n_s16(256);
+ const int16x8_t v_disty = vdupq_n_s16(disty4);
+ const int16x8_t v_disty_ = vshlq_n_s16(v_disty, 4);
+ int32x4_t v_fdx = vdupq_n_s32(fdx*4);
- int32x4_t v_fx = vmovq_n_s32(fx);
- v_fx = vsetq_lane_s32(fx + fdx, v_fx, 1);
- v_fx = vsetq_lane_s32(fx + fdx * 2, v_fx, 2);
- v_fx = vsetq_lane_s32(fx + fdx * 3, v_fx, 3);
+ int32x4_t v_fx = vmovq_n_s32(fx);
+ v_fx = vsetq_lane_s32(fx + fdx, v_fx, 1);
+ v_fx = vsetq_lane_s32(fx + fdx * 2, v_fx, 2);
+ v_fx = vsetq_lane_s32(fx + fdx * 3, v_fx, 3);
- const int32x4_t v_ffff_mask = vdupq_n_s32(0x0000ffff);
- const int32x4_t v_fx_r = vdupq_n_s32(0x0800);
+ const int32x4_t v_ffff_mask = vdupq_n_s32(0x0000ffff);
+ const int32x4_t v_fx_r = vdupq_n_s32(0x0800);
- while (b < boundedEnd) {
- uint32x4x2_t v_top, v_bot;
+ while (b < boundedEnd - 3) {
+ uint32x4x2_t v_top, v_bot;
- int x1 = (fx >> 16);
- fx += fdx;
- v_top = vld2q_lane_u32(s1 + x1, v_top, 0);
- v_bot = vld2q_lane_u32(s2 + x1, v_bot, 0);
- x1 = (fx >> 16);
- fx += fdx;
- v_top = vld2q_lane_u32(s1 + x1, v_top, 1);
- v_bot = vld2q_lane_u32(s2 + x1, v_bot, 1);
- x1 = (fx >> 16);
- fx += fdx;
- v_top = vld2q_lane_u32(s1 + x1, v_top, 2);
- v_bot = vld2q_lane_u32(s2 + x1, v_bot, 2);
- x1 = (fx >> 16);
- fx += fdx;
- v_top = vld2q_lane_u32(s1 + x1, v_top, 3);
- v_bot = vld2q_lane_u32(s2 + x1, v_bot, 3);
-
- int32x4_t v_distx = vshrq_n_s32(vaddq_s32(vandq_s32(v_fx, v_ffff_mask), v_fx_r), 12);
- v_distx = vorrq_s32(v_distx, vshlq_n_s32(v_distx, 16));
-
- interpolate_4_pixels_16_neon(
- vreinterpretq_s16_u32(v_top.val[0]), vreinterpretq_s16_u32(v_top.val[1]),
- vreinterpretq_s16_u32(v_bot.val[0]), vreinterpretq_s16_u32(v_bot.val[1]),
- vreinterpretq_s16_s32(v_distx), v_disty, v_disty_,
- colorMask, invColorMask, v_256, b);
- b+=4;
- v_fx = vaddq_s32(v_fx, v_fdx);
- }
+ int x1 = (fx >> 16);
+ fx += fdx;
+ v_top = vld2q_lane_u32(s1 + x1, v_top, 0);
+ v_bot = vld2q_lane_u32(s2 + x1, v_bot, 0);
+ x1 = (fx >> 16);
+ fx += fdx;
+ v_top = vld2q_lane_u32(s1 + x1, v_top, 1);
+ v_bot = vld2q_lane_u32(s2 + x1, v_bot, 1);
+ x1 = (fx >> 16);
+ fx += fdx;
+ v_top = vld2q_lane_u32(s1 + x1, v_top, 2);
+ v_bot = vld2q_lane_u32(s2 + x1, v_bot, 2);
+ x1 = (fx >> 16);
+ fx += fdx;
+ v_top = vld2q_lane_u32(s1 + x1, v_top, 3);
+ v_bot = vld2q_lane_u32(s2 + x1, v_bot, 3);
+
+ int32x4_t v_distx = vshrq_n_s32(vaddq_s32(vandq_s32(v_fx, v_ffff_mask), v_fx_r), 12);
+ v_distx = vorrq_s32(v_distx, vshlq_n_s32(v_distx, 16));
+
+ interpolate_4_pixels_16_neon(
+ vreinterpretq_s16_u32(v_top.val[0]), vreinterpretq_s16_u32(v_top.val[1]),
+ vreinterpretq_s16_u32(v_bot.val[0]), vreinterpretq_s16_u32(v_bot.val[1]),
+ vreinterpretq_s16_s32(v_distx), v_disty, v_disty_,
+ colorMask, invColorMask, v_256, b);
+ b+=4;
+ v_fx = vaddq_s32(v_fx, v_fdx);
+ }
#endif
- }
+ while (b < boundedEnd) {
+ int x = (fx >> 16);
+#if defined(__SSE2__) || defined(__ARM_NEON__)
+ int distx8 = (fx & 0x0000ffff) >> 8;
+ *b = interpolate_4_pixels(s1 + x, s2 + x, distx8, disty8);
+#else
+ uint tl = s1[x];
+ uint tr = s1[x + 1];
+ uint bl = s2[x];
+ uint br = s2[x + 1];
+ int distx4 = ((fx & 0x0000ffff) + 0x0800) >> 12;
+ *b = interpolate_4_pixels_16(tl, tr, bl, br, distx4, disty4);
+#endif
+ fx += fdx;
+ ++b;
+ }
+ }
- while (b < end) {
- int x1 = (fx >> 16);
- int x2;
- fetchTransformedBilinear_pixelBounds<blendType>(image_width, image_x1, image_x2, x1, x2);
- uint tl = s1[x1];
- uint tr = s1[x2];
- uint bl = s2[x1];
- uint br = s2[x2];
+ while (b < end) {
+ int x1 = (fx >> 16);
+ int x2;
+ fetchTransformedBilinear_pixelBounds<blendType>(image.width, image.x1, image.x2 - 1, x1, x2);
+ uint tl = s1[x1];
+ uint tr = s1[x2];
+ uint bl = s2[x1];
+ uint br = s2[x2];
#if defined(__SSE2__) || defined(__ARM_NEON__)
- // The optimized interpolate_4_pixels are faster than interpolate_4_pixels_16.
- int distx8 = (fx & 0x0000ffff) >> 8;
- *b = interpolate_4_pixels(tl, tr, bl, br, distx8, disty8);
+ // The optimized interpolate_4_pixels are faster than interpolate_4_pixels_16.
+ int distx8 = (fx & 0x0000ffff) >> 8;
+ *b = interpolate_4_pixels(tl, tr, bl, br, distx8, disty8);
#else
- int distx4 = ((fx & 0x0000ffff) + 0x0800) >> 12;
- *b = interpolate_4_pixels_16(tl, tr, bl, br, distx4, disty4);
+ int distx4 = ((fx & 0x0000ffff) + 0x0800) >> 12;
+ *b = interpolate_4_pixels_16(tl, tr, bl, br, distx4, disty4);
#endif
- fx += fdx;
- ++b;
- }
- }
- } else { //rotation
- if (std::abs(data->m11) < (1./8.) || std::abs(data->m22) < (1./8.)) {
- //if we are zooming more than 8 times, we use 8bit precision for the position.
- while (b < end) {
- int x1 = (fx >> 16);
- int x2;
- int y1 = (fy >> 16);
- int y2;
+ fx += fdx;
+ ++b;
+ }
+}
- fetchTransformedBilinear_pixelBounds<blendType>(image_width, image_x1, image_x2, x1, x2);
- fetchTransformedBilinear_pixelBounds<blendType>(image_height, image_y1, image_y2, y1, y2);
+template<TextureBlendType blendType>
+static void QT_FASTCALL fetchTransformedBilinearARGB32PM_rotate_helper(uint *b, uint *end, const QTextureData &image,
+ int &fx, int &fy, int fdx, int fdy)
+{
+ // if we are zooming more than 8 times, we use 8bit precision for the position.
+ while (b < end) {
+ int x1 = (fx >> 16);
+ int x2;
+ int y1 = (fy >> 16);
+ int y2;
- const uint *s1 = (const uint *)data->texture.scanLine(y1);
- const uint *s2 = (const uint *)data->texture.scanLine(y2);
+ fetchTransformedBilinear_pixelBounds<blendType>(image.width, image.x1, image.x2 - 1, x1, x2);
+ fetchTransformedBilinear_pixelBounds<blendType>(image.height, image.y1, image.y2 - 1, y1, y2);
- uint tl = s1[x1];
- uint tr = s1[x2];
- uint bl = s2[x1];
- uint br = s2[x2];
+ const uint *s1 = (const uint *)image.scanLine(y1);
+ const uint *s2 = (const uint *)image.scanLine(y2);
- int distx = (fx & 0x0000ffff) >> 8;
- int disty = (fy & 0x0000ffff) >> 8;
+ uint tl = s1[x1];
+ uint tr = s1[x2];
+ uint bl = s2[x1];
+ uint br = s2[x2];
- *b = interpolate_4_pixels(tl, tr, bl, br, distx, disty);
+ int distx = (fx & 0x0000ffff) >> 8;
+ int disty = (fy & 0x0000ffff) >> 8;
- fx += fdx;
- fy += fdy;
- ++b;
- }
- } else {
- //we are zooming less than 8x, use 4bit precision
-
- if (blendType != BlendTransformedBilinearTiled) {
-#define BILINEAR_ROTATE_BOUNDS_PROLOG \
- const qint64 min_fx = qint64(image_x1) * fixed_scale; \
- const qint64 max_fx = qint64(image_x2) * fixed_scale; \
- const qint64 min_fy = qint64(image_y1) * fixed_scale; \
- const qint64 max_fy = qint64(image_y2) * fixed_scale; \
- while (b < end) { \
- int x1 = (fx >> 16); \
- int x2; \
- int y1 = (fy >> 16); \
- int y2; \
- fetchTransformedBilinear_pixelBounds<blendType>(image_width, image_x1, image_x2, x1, x2); \
- fetchTransformedBilinear_pixelBounds<blendType>(image_height, image_y1, image_y2, y1, y2); \
- if (x1 != x2 && y1 != y2) \
- break; \
- const uint *s1 = (const uint *)data->texture.scanLine(y1); \
- const uint *s2 = (const uint *)data->texture.scanLine(y2); \
- uint tl = s1[x1]; \
- uint tr = s1[x2]; \
- uint bl = s2[x1]; \
- uint br = s2[x2]; \
- int distx = (fx & 0x0000ffff) >> 8; \
- int disty = (fy & 0x0000ffff) >> 8; \
- *b = interpolate_4_pixels(tl, tr, bl, br, distx, disty); \
- fx += fdx; \
- fy += fdy; \
- ++b; \
- } \
- uint *boundedEnd = end; \
- if (fdx > 0) \
- boundedEnd = qMin(boundedEnd, b + (max_fx - fx) / fdx); \
- else if (fdx < 0) \
- boundedEnd = qMin(boundedEnd, b + (min_fx - fx) / fdx); \
- if (fdy > 0) \
- boundedEnd = qMin(boundedEnd, b + (max_fy - fy) / fdy); \
- else if (fdy < 0) \
- boundedEnd = qMin(boundedEnd, b + (min_fy - fy) / fdy); \
- boundedEnd -= 3;
+ *b = interpolate_4_pixels(tl, tr, bl, br, distx, disty);
-#if defined(__SSE2__)
- BILINEAR_ROTATE_BOUNDS_PROLOG
+ fx += fdx;
+ fy += fdy;
+ ++b;
+ }
+}
- const __m128i colorMask = _mm_set1_epi32(0x00ff00ff);
- const __m128i v_256 = _mm_set1_epi16(256);
- const __m128i v_fdx = _mm_set1_epi32(fdx*4);
- const __m128i v_fdy = _mm_set1_epi32(fdy*4);
- const __m128i v_fxy_r = _mm_set1_epi32(0x8);
- __m128i v_fx = _mm_setr_epi32(fx, fx + fdx, fx + fdx + fdx, fx + fdx + fdx + fdx);
- __m128i v_fy = _mm_setr_epi32(fy, fy + fdy, fy + fdy + fdy, fy + fdy + fdy + fdy);
+template<TextureBlendType blendType>
+static void QT_FASTCALL fetchTransformedBilinearARGB32PM_fast_rotate_helper(uint *b, uint *end, const QTextureData &image,
+ int &fx, int &fy, int fdx, int fdy)
+{
+ //we are zooming less than 8x, use 4bit precision
+ if (blendType != BlendTransformedBilinearTiled) {
+ const qint64 min_fx = qint64(image.x1) * fixed_scale;
+ const qint64 max_fx = qint64(image.x2 - 1) * fixed_scale;
+ const qint64 min_fy = qint64(image.y1) * fixed_scale;
+ const qint64 max_fy = qint64(image.y2 - 1) * fixed_scale;
+ // first handle the possibly bounded part in the beginning
+ while (b < end) {
+ int x1 = (fx >> 16);
+ int x2;
+ int y1 = (fy >> 16);
+ int y2;
+ fetchTransformedBilinear_pixelBounds<blendType>(image.width, image.x1, image.x2 - 1, x1, x2);
+ fetchTransformedBilinear_pixelBounds<blendType>(image.height, image.y1, image.y2 - 1, y1, y2);
+ if (x1 != x2 && y1 != y2)
+ break;
+ const uint *s1 = (const uint *)image.scanLine(y1);
+ const uint *s2 = (const uint *)image.scanLine(y2);
+ uint tl = s1[x1];
+ uint tr = s1[x2];
+ uint bl = s2[x1];
+ uint br = s2[x2];
+#if defined(__SSE2__) || defined(__ARM_NEON__)
+ int distx = (fx & 0x0000ffff) >> 8;
+ int disty = (fy & 0x0000ffff) >> 8;
+ *b = interpolate_4_pixels(tl, tr, bl, br, distx, disty);
+#else
+ int distx = ((fx & 0x0000ffff) + 0x0800) >> 12;
+ int disty = ((fy & 0x0000ffff) + 0x0800) >> 12;
+ *b = interpolate_4_pixels_16(tl, tr, bl, br, distx, disty);
+#endif
+ fx += fdx;
+ fy += fdy;
+ ++b;
+ }
+ uint *boundedEnd = end; \
+ if (fdx > 0) \
+ boundedEnd = qMin(boundedEnd, b + (max_fx - fx) / fdx); \
+ else if (fdx < 0) \
+ boundedEnd = qMin(boundedEnd, b + (min_fx - fx) / fdx); \
+ if (fdy > 0) \
+ boundedEnd = qMin(boundedEnd, b + (max_fy - fy) / fdy); \
+ else if (fdy < 0) \
+ boundedEnd = qMin(boundedEnd, b + (min_fy - fy) / fdy); \
+
+ // until boundedEnd we can now have a fast middle part without boundary checks
+#if defined(__SSE2__)
+ const __m128i colorMask = _mm_set1_epi32(0x00ff00ff);
+ const __m128i v_256 = _mm_set1_epi16(256);
+ const __m128i v_fdx = _mm_set1_epi32(fdx*4);
+ const __m128i v_fdy = _mm_set1_epi32(fdy*4);
+ const __m128i v_fxy_r = _mm_set1_epi32(0x8);
+ __m128i v_fx = _mm_setr_epi32(fx, fx + fdx, fx + fdx + fdx, fx + fdx + fdx + fdx);
+ __m128i v_fy = _mm_setr_epi32(fy, fy + fdy, fy + fdy + fdy, fy + fdy + fdy + fdy);
+
+ const uchar *textureData = image.imageData;
+ const int bytesPerLine = image.bytesPerLine;
+ const __m128i vbpl = _mm_shufflelo_epi16(_mm_cvtsi32_si128(bytesPerLine/4), _MM_SHUFFLE(0, 0, 0, 0));
+
+ while (b < boundedEnd - 3) {
+ const __m128i vy = _mm_packs_epi32(_mm_srli_epi32(v_fy, 16), _mm_setzero_si128());
+ // 4x16bit * 4x16bit -> 4x32bit
+ __m128i offset = _mm_unpacklo_epi16(_mm_mullo_epi16(vy, vbpl), _mm_mulhi_epi16(vy, vbpl));
+ offset = _mm_add_epi32(offset, _mm_srli_epi32(v_fx, 16));
+ const int offset0 = _mm_cvtsi128_si32(offset); offset = _mm_srli_si128(offset, 4);
+ const int offset1 = _mm_cvtsi128_si32(offset); offset = _mm_srli_si128(offset, 4);
+ const int offset2 = _mm_cvtsi128_si32(offset); offset = _mm_srli_si128(offset, 4);
+ const int offset3 = _mm_cvtsi128_si32(offset);
+ const uint *topData = (const uint *)(textureData);
+ const __m128i tl = _mm_setr_epi32(topData[offset0], topData[offset1], topData[offset2], topData[offset3]);
+ const __m128i tr = _mm_setr_epi32(topData[offset0 + 1], topData[offset1 + 1], topData[offset2 + 1], topData[offset3 + 1]);
+ const uint *bottomData = (const uint *)(textureData + bytesPerLine);
+ const __m128i bl = _mm_setr_epi32(bottomData[offset0], bottomData[offset1], bottomData[offset2], bottomData[offset3]);
+ const __m128i br = _mm_setr_epi32(bottomData[offset0 + 1], bottomData[offset1 + 1], bottomData[offset2 + 1], bottomData[offset3 + 1]);
+
+ __m128i v_distx = _mm_srli_epi16(v_fx, 8);
+ __m128i v_disty = _mm_srli_epi16(v_fy, 8);
+ v_distx = _mm_srli_epi16(_mm_add_epi32(v_distx, v_fxy_r), 4);
+ v_disty = _mm_srli_epi16(_mm_add_epi32(v_disty, v_fxy_r), 4);
+ v_distx = _mm_shufflehi_epi16(v_distx, _MM_SHUFFLE(2,2,0,0));
+ v_distx = _mm_shufflelo_epi16(v_distx, _MM_SHUFFLE(2,2,0,0));
+ v_disty = _mm_shufflehi_epi16(v_disty, _MM_SHUFFLE(2,2,0,0));
+ v_disty = _mm_shufflelo_epi16(v_disty, _MM_SHUFFLE(2,2,0,0));
+
+ interpolate_4_pixels_16_sse2(tl, tr, bl, br, v_distx, v_disty, colorMask, v_256, b);
+ b += 4;
+ v_fx = _mm_add_epi32(v_fx, v_fdx);
+ v_fy = _mm_add_epi32(v_fy, v_fdy);
+ }
+ fx = _mm_cvtsi128_si32(v_fx);
+ fy = _mm_cvtsi128_si32(v_fy);
+#elif defined(__ARM_NEON__)
+ const int16x8_t colorMask = vdupq_n_s16(0x00ff);
+ const int16x8_t invColorMask = vmvnq_s16(colorMask);
+ const int16x8_t v_256 = vdupq_n_s16(256);
+ int32x4_t v_fdx = vdupq_n_s32(fdx * 4);
+ int32x4_t v_fdy = vdupq_n_s32(fdy * 4);
+
+ const uchar *textureData = image.imageData;
+ const int bytesPerLine = image.bytesPerLine;
+
+ int32x4_t v_fx = vmovq_n_s32(fx);
+ int32x4_t v_fy = vmovq_n_s32(fy);
+ v_fx = vsetq_lane_s32(fx + fdx, v_fx, 1);
+ v_fy = vsetq_lane_s32(fy + fdy, v_fy, 1);
+ v_fx = vsetq_lane_s32(fx + fdx * 2, v_fx, 2);
+ v_fy = vsetq_lane_s32(fy + fdy * 2, v_fy, 2);
+ v_fx = vsetq_lane_s32(fx + fdx * 3, v_fx, 3);
+ v_fy = vsetq_lane_s32(fy + fdy * 3, v_fy, 3);
+
+ const int32x4_t v_ffff_mask = vdupq_n_s32(0x0000ffff);
+ const int32x4_t v_round = vdupq_n_s32(0x0800);
+
+ while (b < boundedEnd - 3) {
+ uint32x4x2_t v_top, v_bot;
+
+ int x1 = (fx >> 16);
+ int y1 = (fy >> 16);
+ fx += fdx; fy += fdy;
+ const uchar *sl = textureData + bytesPerLine * y1;
+ const uint *s1 = reinterpret_cast<const uint *>(sl);
+ const uint *s2 = reinterpret_cast<const uint *>(sl + bytesPerLine);
+ v_top = vld2q_lane_u32(s1 + x1, v_top, 0);
+ v_bot = vld2q_lane_u32(s2 + x1, v_bot, 0);
+ x1 = (fx >> 16);
+ y1 = (fy >> 16);
+ fx += fdx; fy += fdy;
+ sl = textureData + bytesPerLine * y1;
+ s1 = reinterpret_cast<const uint *>(sl);
+ s2 = reinterpret_cast<const uint *>(sl + bytesPerLine);
+ v_top = vld2q_lane_u32(s1 + x1, v_top, 1);
+ v_bot = vld2q_lane_u32(s2 + x1, v_bot, 1);
+ x1 = (fx >> 16);
+ y1 = (fy >> 16);
+ fx += fdx; fy += fdy;
+ sl = textureData + bytesPerLine * y1;
+ s1 = reinterpret_cast<const uint *>(sl);
+ s2 = reinterpret_cast<const uint *>(sl + bytesPerLine);
+ v_top = vld2q_lane_u32(s1 + x1, v_top, 2);
+ v_bot = vld2q_lane_u32(s2 + x1, v_bot, 2);
+ x1 = (fx >> 16);
+ y1 = (fy >> 16);
+ fx += fdx; fy += fdy;
+ sl = textureData + bytesPerLine * y1;
+ s1 = reinterpret_cast<const uint *>(sl);
+ s2 = reinterpret_cast<const uint *>(sl + bytesPerLine);
+ v_top = vld2q_lane_u32(s1 + x1, v_top, 3);
+ v_bot = vld2q_lane_u32(s2 + x1, v_bot, 3);
+
+ int32x4_t v_distx = vshrq_n_s32(vaddq_s32(vandq_s32(v_fx, v_ffff_mask), v_round), 12);
+ int32x4_t v_disty = vshrq_n_s32(vaddq_s32(vandq_s32(v_fy, v_ffff_mask), v_round), 12);
+ v_distx = vorrq_s32(v_distx, vshlq_n_s32(v_distx, 16));
+ v_disty = vorrq_s32(v_disty, vshlq_n_s32(v_disty, 16));
+ int16x8_t v_disty_ = vshlq_n_s16(vreinterpretq_s16_s32(v_disty), 4);
+
+ interpolate_4_pixels_16_neon(
+ vreinterpretq_s16_u32(v_top.val[0]), vreinterpretq_s16_u32(v_top.val[1]),
+ vreinterpretq_s16_u32(v_bot.val[0]), vreinterpretq_s16_u32(v_bot.val[1]),
+ vreinterpretq_s16_s32(v_distx), vreinterpretq_s16_s32(v_disty),
+ v_disty_, colorMask, invColorMask, v_256, b);
+ b += 4;
+ v_fx = vaddq_s32(v_fx, v_fdx);
+ v_fy = vaddq_s32(v_fy, v_fdy);
+ }
+#endif
+ while (b < boundedEnd) {
+ int x = (fx >> 16);
+ int y = (fy >> 16);
- const uchar *textureData = data->texture.imageData;
- const int bytesPerLine = data->texture.bytesPerLine;
- const __m128i vbpl = _mm_shufflelo_epi16(_mm_cvtsi32_si128(bytesPerLine/4), _MM_SHUFFLE(0, 0, 0, 0));
+ const uint *s1 = (const uint *)image.scanLine(y);
+ const uint *s2 = (const uint *)image.scanLine(y + 1);
- while (b < boundedEnd) {
- const __m128i vy = _mm_packs_epi32(_mm_srli_epi32(v_fy, 16), _mm_setzero_si128());
- // 4x16bit * 4x16bit -> 4x32bit
- __m128i offset = _mm_unpacklo_epi16(_mm_mullo_epi16(vy, vbpl), _mm_mulhi_epi16(vy, vbpl));
- offset = _mm_add_epi32(offset, _mm_srli_epi32(v_fx, 16));
- const int offset0 = _mm_cvtsi128_si32(offset); offset = _mm_srli_si128(offset, 4);
- const int offset1 = _mm_cvtsi128_si32(offset); offset = _mm_srli_si128(offset, 4);
- const int offset2 = _mm_cvtsi128_si32(offset); offset = _mm_srli_si128(offset, 4);
- const int offset3 = _mm_cvtsi128_si32(offset);
- const uint *topData = (const uint *)(textureData);
- const __m128i tl = _mm_setr_epi32(topData[offset0], topData[offset1], topData[offset2], topData[offset3]);
- const __m128i tr = _mm_setr_epi32(topData[offset0 + 1], topData[offset1 + 1], topData[offset2 + 1], topData[offset3 + 1]);
- const uint *bottomData = (const uint *)(textureData + bytesPerLine);
- const __m128i bl = _mm_setr_epi32(bottomData[offset0], bottomData[offset1], bottomData[offset2], bottomData[offset3]);
- const __m128i br = _mm_setr_epi32(bottomData[offset0 + 1], bottomData[offset1 + 1], bottomData[offset2 + 1], bottomData[offset3 + 1]);
-
- __m128i v_distx = _mm_srli_epi16(v_fx, 8);
- __m128i v_disty = _mm_srli_epi16(v_fy, 8);
- v_distx = _mm_srli_epi16(_mm_add_epi32(v_distx, v_fxy_r), 4);
- v_disty = _mm_srli_epi16(_mm_add_epi32(v_disty, v_fxy_r), 4);
- v_distx = _mm_shufflehi_epi16(v_distx, _MM_SHUFFLE(2,2,0,0));
- v_distx = _mm_shufflelo_epi16(v_distx, _MM_SHUFFLE(2,2,0,0));
- v_disty = _mm_shufflehi_epi16(v_disty, _MM_SHUFFLE(2,2,0,0));
- v_disty = _mm_shufflelo_epi16(v_disty, _MM_SHUFFLE(2,2,0,0));
-
- interpolate_4_pixels_16_sse2(tl, tr, bl, br, v_distx, v_disty, colorMask, v_256, b);
- b += 4;
- v_fx = _mm_add_epi32(v_fx, v_fdx);
- v_fy = _mm_add_epi32(v_fy, v_fdy);
- }
- fx = _mm_cvtsi128_si32(v_fx);
- fy = _mm_cvtsi128_si32(v_fy);
-#elif defined(__ARM_NEON__)
- BILINEAR_ROTATE_BOUNDS_PROLOG
+#if defined(__SSE2__) || defined(__ARM_NEON__)
+ int distx = (fx & 0x0000ffff) >> 8;
+ int disty = (fy & 0x0000ffff) >> 8;
+ *b = interpolate_4_pixels(s1 + x, s2 + x, distx, disty);
+#else
+ uint tl = s1[x];
+ uint tr = s1[x + 1];
+ uint bl = s2[x];
+ uint br = s2[x + 1];
+ int distx = ((fx & 0x0000ffff) + 0x0800) >> 12;
+ int disty = ((fy & 0x0000ffff) + 0x0800) >> 12;
+ *b = interpolate_4_pixels_16(tl, tr, bl, br, distx, disty);
+#endif
- const int16x8_t colorMask = vdupq_n_s16(0x00ff);
- const int16x8_t invColorMask = vmvnq_s16(colorMask);
- const int16x8_t v_256 = vdupq_n_s16(256);
- int32x4_t v_fdx = vdupq_n_s32(fdx * 4);
- int32x4_t v_fdy = vdupq_n_s32(fdy * 4);
+ fx += fdx;
+ fy += fdy;
+ ++b;
+ }
+ }
- const uchar *textureData = data->texture.imageData;
- const int bytesPerLine = data->texture.bytesPerLine;
+ while (b < end) {
+ int x1 = (fx >> 16);
+ int x2;
+ int y1 = (fy >> 16);
+ int y2;
- int32x4_t v_fx = vmovq_n_s32(fx);
- int32x4_t v_fy = vmovq_n_s32(fy);
- v_fx = vsetq_lane_s32(fx + fdx, v_fx, 1);
- v_fy = vsetq_lane_s32(fy + fdy, v_fy, 1);
- v_fx = vsetq_lane_s32(fx + fdx * 2, v_fx, 2);
- v_fy = vsetq_lane_s32(fy + fdy * 2, v_fy, 2);
- v_fx = vsetq_lane_s32(fx + fdx * 3, v_fx, 3);
- v_fy = vsetq_lane_s32(fy + fdy * 3, v_fy, 3);
+ fetchTransformedBilinear_pixelBounds<blendType>(image.width, image.x1, image.x2 - 1, x1, x2);
+ fetchTransformedBilinear_pixelBounds<blendType>(image.height, image.y1, image.y2 - 1, y1, y2);
- const int32x4_t v_ffff_mask = vdupq_n_s32(0x0000ffff);
- const int32x4_t v_round = vdupq_n_s32(0x0800);
+ const uint *s1 = (const uint *)image.scanLine(y1);
+ const uint *s2 = (const uint *)image.scanLine(y2);
- while (b < boundedEnd) {
- uint32x4x2_t v_top, v_bot;
+ uint tl = s1[x1];
+ uint tr = s1[x2];
+ uint bl = s2[x1];
+ uint br = s2[x2];
- int x1 = (fx >> 16);
- int y1 = (fy >> 16);
- fx += fdx; fy += fdy;
- const uchar *sl = textureData + bytesPerLine * y1;
- const uint *s1 = reinterpret_cast<const uint *>(sl);
- const uint *s2 = reinterpret_cast<const uint *>(sl + bytesPerLine);
- v_top = vld2q_lane_u32(s1 + x1, v_top, 0);
- v_bot = vld2q_lane_u32(s2 + x1, v_bot, 0);
- x1 = (fx >> 16);
- y1 = (fy >> 16);
- fx += fdx; fy += fdy;
- sl = textureData + bytesPerLine * y1;
- s1 = reinterpret_cast<const uint *>(sl);
- s2 = reinterpret_cast<const uint *>(sl + bytesPerLine);
- v_top = vld2q_lane_u32(s1 + x1, v_top, 1);
- v_bot = vld2q_lane_u32(s2 + x1, v_bot, 1);
- x1 = (fx >> 16);
- y1 = (fy >> 16);
- fx += fdx; fy += fdy;
- sl = textureData + bytesPerLine * y1;
- s1 = reinterpret_cast<const uint *>(sl);
- s2 = reinterpret_cast<const uint *>(sl + bytesPerLine);
- v_top = vld2q_lane_u32(s1 + x1, v_top, 2);
- v_bot = vld2q_lane_u32(s2 + x1, v_bot, 2);
- x1 = (fx >> 16);
- y1 = (fy >> 16);
- fx += fdx; fy += fdy;
- sl = textureData + bytesPerLine * y1;
- s1 = reinterpret_cast<const uint *>(sl);
- s2 = reinterpret_cast<const uint *>(sl + bytesPerLine);
- v_top = vld2q_lane_u32(s1 + x1, v_top, 3);
- v_bot = vld2q_lane_u32(s2 + x1, v_bot, 3);
-
- int32x4_t v_distx = vshrq_n_s32(vaddq_s32(vandq_s32(v_fx, v_ffff_mask), v_round), 12);
- int32x4_t v_disty = vshrq_n_s32(vaddq_s32(vandq_s32(v_fy, v_ffff_mask), v_round), 12);
- v_distx = vorrq_s32(v_distx, vshlq_n_s32(v_distx, 16));
- v_disty = vorrq_s32(v_disty, vshlq_n_s32(v_disty, 16));
- int16x8_t v_disty_ = vshlq_n_s16(vreinterpretq_s16_s32(v_disty), 4);
-
- interpolate_4_pixels_16_neon(
- vreinterpretq_s16_u32(v_top.val[0]), vreinterpretq_s16_u32(v_top.val[1]),
- vreinterpretq_s16_u32(v_bot.val[0]), vreinterpretq_s16_u32(v_bot.val[1]),
- vreinterpretq_s16_s32(v_distx), vreinterpretq_s16_s32(v_disty),
- v_disty_, colorMask, invColorMask, v_256, b);
- b += 4;
- v_fx = vaddq_s32(v_fx, v_fdx);
- v_fy = vaddq_s32(v_fy, v_fdy);
- }
+#if defined(__SSE2__) || defined(__ARM_NEON__)
+ // The optimized interpolate_4_pixels are faster than interpolate_4_pixels_16.
+ int distx = (fx & 0x0000ffff) >> 8;
+ int disty = (fy & 0x0000ffff) >> 8;
+ *b = interpolate_4_pixels(tl, tr, bl, br, distx, disty);
+#else
+ int distx = ((fx & 0x0000ffff) + 0x0800) >> 12;
+ int disty = ((fy & 0x0000ffff) + 0x0800) >> 12;
+ *b = interpolate_4_pixels_16(tl, tr, bl, br, distx, disty);
#endif
- }
- while (b < end) {
- int x1 = (fx >> 16);
- int x2;
- int y1 = (fy >> 16);
- int y2;
+ fx += fdx;
+ fy += fdy;
+ ++b;
+ }
+}
- fetchTransformedBilinear_pixelBounds<blendType>(image_width, image_x1, image_x2, x1, x2);
- fetchTransformedBilinear_pixelBounds<blendType>(image_height, image_y1, image_y2, y1, y2);
- const uint *s1 = (const uint *)data->texture.scanLine(y1);
- const uint *s2 = (const uint *)data->texture.scanLine(y2);
+static BilinearFastTransformHelper bilinearFastTransformHelperARGB32PM[2][NFastTransformTypes] = {
+ {
+ fetchTransformedBilinearARGB32PM_simple_upscale_helper<BlendTransformedBilinear>,
+ fetchTransformedBilinearARGB32PM_upscale_helper<BlendTransformedBilinear>,
+ fetchTransformedBilinearARGB32PM_downscale_helper<BlendTransformedBilinear>,
+ fetchTransformedBilinearARGB32PM_rotate_helper<BlendTransformedBilinear>,
+ fetchTransformedBilinearARGB32PM_fast_rotate_helper<BlendTransformedBilinear>
+ },
+ {
+ fetchTransformedBilinearARGB32PM_simple_upscale_helper<BlendTransformedBilinearTiled>,
+ fetchTransformedBilinearARGB32PM_upscale_helper<BlendTransformedBilinearTiled>,
+ fetchTransformedBilinearARGB32PM_downscale_helper<BlendTransformedBilinearTiled>,
+ fetchTransformedBilinearARGB32PM_rotate_helper<BlendTransformedBilinearTiled>,
+ fetchTransformedBilinearARGB32PM_fast_rotate_helper<BlendTransformedBilinearTiled>
+ }
+};
- uint tl = s1[x1];
- uint tr = s1[x2];
- uint bl = s2[x1];
- uint br = s2[x2];
+template<TextureBlendType blendType> /* blendType = BlendTransformedBilinear or BlendTransformedBilinearTiled */
+static const uint * QT_FASTCALL fetchTransformedBilinearARGB32PM(uint *buffer, const Operator *,
+ const QSpanData *data, int y, int x,
+ int length)
+{
+ const qreal cx = x + qreal(0.5);
+ const qreal cy = y + qreal(0.5);
+ Q_CONSTEXPR int tiled = (blendType == BlendTransformedBilinearTiled) ? 1 : 0;
-#if defined(__SSE2__) || defined(__ARM_NEON__)
- // The optimized interpolate_4_pixels are faster than interpolate_4_pixels_16.
- int distx = (fx & 0x0000ffff) >> 8;
- int disty = (fy & 0x0000ffff) >> 8;
- *b = interpolate_4_pixels(tl, tr, bl, br, distx, disty);
-#else
- int distx = ((fx & 0x0000ffff) + 0x0800) >> 12;
- int disty = ((fy & 0x0000ffff) + 0x0800) >> 12;
- *b = interpolate_4_pixels_16(tl, tr, bl, br, distx, disty);
-#endif
+ uint *end = buffer + length;
+ uint *b = buffer;
+ if (data->fast_matrix) {
+ // The increment pr x in the scanline
+ int fdx = (int)(data->m11 * fixed_scale);
+ int fdy = (int)(data->m12 * fixed_scale);
- fx += fdx;
- fy += fdy;
- ++b;
- }
+ int fx = int((data->m21 * cy
+ + data->m11 * cx + data->dx) * fixed_scale);
+ int fy = int((data->m22 * cy
+ + data->m12 * cx + data->dy) * fixed_scale);
+
+ fx -= half_point;
+ fy -= half_point;
+
+ if (fdy == 0) { // simple scale, no rotation or shear
+ if (fdx <= fixed_scale && fdx > 0) {
+ // simple scale up on X without mirroring
+ bilinearFastTransformHelperARGB32PM[tiled][SimpleUpscaleTransform](b, end, data->texture, fx, fy, fdx, fdy);
+ } else if ((fdx < 0 && fdx > -(fixed_scale / 8)) || qAbs(data->m22) < qreal(1./8.)) {
+ // scale up more than 8x (on either Y or on X mirrored)
+ bilinearFastTransformHelperARGB32PM[tiled][UpscaleTransform](b, end, data->texture, fx, fy, fdx, fdy);
+ } else {
+ // scale down on X (or up on X mirrored less than 8x)
+ bilinearFastTransformHelperARGB32PM[tiled][DownscaleTransform](b, end, data->texture, fx, fy, fdx, fdy);
+ }
+ } else { // rotation or shear
+ if (qAbs(data->m11) < qreal(1./8.) || qAbs(data->m22) < qreal(1./8.) ) {
+ // if we are zooming more than 8 times, we use 8bit precision for the position.
+ bilinearFastTransformHelperARGB32PM[tiled][RotateTransform](b, end, data->texture, fx, fy, fdx, fdy);
+ } else {
+ // we are zooming less than 8x, use 4bit precision
+ bilinearFastTransformHelperARGB32PM[tiled][FastRotateTransform](b, end, data->texture, fx, fy, fdx, fdy);
}
}
} else {
+ const QTextureData &image = data->texture;
+
const qreal fdx = data->m11;
const qreal fdy = data->m12;
const qreal fdw = data->m13;
@@ -2495,8 +2629,8 @@ static const uint * QT_FASTCALL fetchTransformedBilinearARGB32PM(uint *buffer, c
int distx = int((px - x1) * 256);
int disty = int((py - y1) * 256);
- fetchTransformedBilinear_pixelBounds<blendType>(image_width, image_x1, image_x2, x1, x2);
- fetchTransformedBilinear_pixelBounds<blendType>(image_height, image_y1, image_y2, y1, y2);
+ fetchTransformedBilinear_pixelBounds<blendType>(image.width, image.x1, image.x2 - 1, x1, x2);
+ fetchTransformedBilinear_pixelBounds<blendType>(image.height, image.y1, image.y2 - 1, y1, y2);
const uint *s1 = (const uint *)data->texture.scanLine(y1);
const uint *s2 = (const uint *)data->texture.scanLine(y2);
@@ -2678,7 +2812,7 @@ static const uint *QT_FASTCALL fetchTransformedBilinear(uint *buffer, const Oper
layout->convertToARGB32PM(buf1, buf1, len * 2, clut, 0);
layout->convertToARGB32PM(buf2, buf2, len * 2, clut, 0);
- if ((fdx < 0 && fdx > -(fixed_scale / 8)) || std::abs(data->m22) < (1./8.)) { // scale up more than 8x
+ if ((fdx < 0 && fdx > -(fixed_scale / 8)) || qAbs(data->m22) < qreal(1./8.)) { // scale up more than 8x
int disty = (fy & 0x0000ffff) >> 8;
for (int i = 0; i < len; ++i) {
int distx = (fracX & 0x0000ffff) >> 8;
@@ -2730,7 +2864,7 @@ static const uint *QT_FASTCALL fetchTransformedBilinear(uint *buffer, const Oper
layout->convertToARGB32PM(buf1, buf1, len * 2, clut, 0);
layout->convertToARGB32PM(buf2, buf2, len * 2, clut, 0);
- if (std::abs(data->m11) < (1./8.) || std::abs(data->m22) < (1./8.)) {
+ if (qAbs(data->m11) < qreal(1./8.) || qAbs(data->m22) < qreal(1./8.) ) {
//if we are zooming more than 8 times, we use 8bit precision for the position.
for (int i = 0; i < len; ++i) {
int distx = (fracX & 0x0000ffff) >> 8;
@@ -5195,6 +5329,8 @@ void qBlendTexture(int count, const QSpan *spans, void *userData)
case QImage::Format_RGB16:
proc = processTextureSpansRGB16[blendType];
break;
+ case QImage::Format_ARGB32:
+ case QImage::Format_RGBA8888:
case QImage::Format_BGR30:
case QImage::Format_A2BGR30_Premultiplied:
case QImage::Format_RGB30:
@@ -5411,7 +5547,7 @@ static void qt_alphamapblit_quint16(QRasterBuffer *rasterBuffer,
int x, int y, const QRgba64 &color,
const uchar *map,
int mapWidth, int mapHeight, int mapStride,
- const QClipData *)
+ const QClipData *, bool /*useGammaCorrection*/)
{
const quint16 c = color.toRgb16();
quint16 *dest = reinterpret_cast<quint16*>(rasterBuffer->scanLine(y)) + x;
@@ -5436,105 +5572,43 @@ static void qt_alphamapblit_quint16(QRasterBuffer *rasterBuffer,
}
}
-static inline void rgbBlendPixel(quint32 *dst, int coverage, int sr, int sg, int sb, const uchar *gamma, const uchar *invgamma)
+static inline void rgbBlendPixel(quint32 *dst, int coverage, QRgba64 slinear, const QColorProfile *colorProfile, bool useGammaCorrection)
{
- // Do a gray alphablend...
- int da = qAlpha(*dst);
- int dr = qRed(*dst);
- int dg = qGreen(*dst);
- int db = qBlue(*dst);
-
- if (da != 255
- ) {
-
- int a = qGray(coverage);
- sr = qt_div_255(invgamma[sr] * a);
- sg = qt_div_255(invgamma[sg] * a);
- sb = qt_div_255(invgamma[sb] * a);
-
- int ia = 255 - a;
- dr = qt_div_255(dr * ia);
- dg = qt_div_255(dg * ia);
- db = qt_div_255(db * ia);
-
- *dst = ((a + qt_div_255((255 - a) * da)) << 24)
- | ((sr + dr) << 16)
- | ((sg + dg) << 8)
- | ((sb + db));
- return;
- }
-
- int mr = qRed(coverage);
- int mg = qGreen(coverage);
- int mb = qBlue(coverage);
-
- dr = gamma[dr];
- dg = gamma[dg];
- db = gamma[db];
-
- int nr = qt_div_255(sr * mr + dr * (255 - mr));
- int ng = qt_div_255(sg * mg + dg * (255 - mg));
- int nb = qt_div_255(sb * mb + db * (255 - mb));
+ // Do a gammacorrected RGB alphablend...
+ const QRgba64 dlinear = useGammaCorrection ? colorProfile->toLinear64(*dst) : QRgba64::fromArgb32(*dst);
- nr = invgamma[nr];
- ng = invgamma[ng];
- nb = invgamma[nb];
+ QRgba64 blend = rgbBlend(dlinear, slinear, coverage);
- *dst = qRgb(nr, ng, nb);
+ *dst = useGammaCorrection ? colorProfile->fromLinear64(blend) : toArgb32(blend);
}
-#if defined(Q_OS_WIN)
-Q_GUI_EXPORT bool qt_needs_a8_gamma_correction = false;
-
-static inline void grayBlendPixel(quint32 *dst, int coverage, int sr, int sg, int sb, const uint *gamma, const uchar *invgamma)
+static inline void grayBlendPixel(quint32 *dst, int coverage, QRgba64 slinear, const QColorProfile *colorProfile)
{
// Do a gammacorrected gray alphablend...
- int dr = qRed(*dst);
- int dg = qGreen(*dst);
- int db = qBlue(*dst);
-
- dr = gamma[dr];
- dg = gamma[dg];
- db = gamma[db];
-
- int alpha = coverage;
- int ialpha = 255 - alpha;
- int nr = qt_div_255(sr * alpha + dr * ialpha);
- int ng = qt_div_255(sg * alpha + dg * ialpha);
- int nb = qt_div_255(sb * alpha + db * ialpha);
+ const QRgba64 dlinear = colorProfile->toLinear64(*dst);
- nr = invgamma[nr];
- ng = invgamma[ng];
- nb = invgamma[nb];
+ QRgba64 blend = interpolate255(slinear, coverage, dlinear, 255 - coverage);
- *dst = qRgb(nr, ng, nb);
+ *dst = colorProfile->fromLinear64(blend);
}
-#endif
static void qt_alphamapblit_uint32(QRasterBuffer *rasterBuffer,
int x, int y, quint32 color,
const uchar *map,
int mapWidth, int mapHeight, int mapStride,
- const QClipData *clip)
+ const QClipData *clip, bool useGammaCorrection)
{
const quint32 c = color;
const int destStride = rasterBuffer->bytesPerLine() / sizeof(quint32);
-#if defined(Q_OS_WIN)
- const QDrawHelperGammaTables *tables = QGuiApplicationPrivate::instance()->gammaTables();
- if (!tables)
+ const QColorProfile *colorProfile = QGuiApplicationPrivate::instance()->colorProfileForA8Text();
+ if (!colorProfile)
return;
- const uint *gamma = tables->qt_pow_gamma;
- const uchar *invgamma = tables->qt_pow_invgamma;
-
- int sr = gamma[qRed(color)];
- int sg = gamma[qGreen(color)];
- int sb = gamma[qBlue(color)];
+ const QRgba64 slinear = colorProfile->toLinear64(c);
bool opaque_src = (qAlpha(color) == 255);
- bool doGrayBlendPixel = opaque_src && qt_needs_a8_gamma_correction;
-#endif
+ bool doGrayBlendPixel = opaque_src && useGammaCorrection;
if (!clip) {
quint32 *dest = reinterpret_cast<quint32*>(rasterBuffer->scanLine(y)) + x;
@@ -5547,13 +5621,9 @@ static void qt_alphamapblit_uint32(QRasterBuffer *rasterBuffer,
} else if (coverage == 255) {
dest[i] = c;
} else {
-#if defined(Q_OS_WIN)
- if (QSysInfo::WindowsVersion >= QSysInfo::WV_XP && doGrayBlendPixel
- && qAlpha(dest[i]) == 255) {
- grayBlendPixel(dest+i, coverage, sr, sg, sb, gamma, invgamma);
- } else
-#endif
- {
+ if (doGrayBlendPixel && qAlpha(dest[i]) == 255) {
+ grayBlendPixel(dest+i, coverage, slinear, colorProfile);
+ } else {
int ialpha = 255 - coverage;
dest[i] = INTERPOLATE_PIXEL_255(c, coverage, dest[i], ialpha);
}
@@ -5588,13 +5658,9 @@ static void qt_alphamapblit_uint32(QRasterBuffer *rasterBuffer,
} else if (coverage == 255) {
dest[xp] = c;
} else {
-#if defined(Q_OS_WIN)
- if (QSysInfo::WindowsVersion >= QSysInfo::WV_XP && doGrayBlendPixel
- && qAlpha(dest[xp]) == 255) {
- grayBlendPixel(dest+xp, coverage, sr, sg, sb, gamma, invgamma);
- } else
-#endif
- {
+ if (doGrayBlendPixel && qAlpha(dest[xp]) == 255) {
+ grayBlendPixel(dest+xp, coverage, slinear, colorProfile);
+ } else {
int ialpha = 255 - coverage;
dest[xp] = INTERPOLATE_PIXEL_255(c, coverage, dest[xp], ialpha);
}
@@ -5612,9 +5678,9 @@ static void qt_alphamapblit_argb32(QRasterBuffer *rasterBuffer,
int x, int y, const QRgba64 &color,
const uchar *map,
int mapWidth, int mapHeight, int mapStride,
- const QClipData *clip)
+ const QClipData *clip, bool useGammaCorrection)
{
- qt_alphamapblit_uint32(rasterBuffer, x, y, color.toArgb32(), map, mapWidth, mapHeight, mapStride, clip);
+ qt_alphamapblit_uint32(rasterBuffer, x, y, color.toArgb32(), map, mapWidth, mapHeight, mapStride, clip, useGammaCorrection);
}
#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
@@ -5622,34 +5688,31 @@ static void qt_alphamapblit_rgba8888(QRasterBuffer *rasterBuffer,
int x, int y, const QRgba64 &color,
const uchar *map,
int mapWidth, int mapHeight, int mapStride,
- const QClipData *clip)
+ const QClipData *clip, bool useGammaCorrection)
{
- qt_alphamapblit_uint32(rasterBuffer, x, y, ARGB2RGBA(color.toArgb32()), map, mapWidth, mapHeight, mapStride, clip);
+ qt_alphamapblit_uint32(rasterBuffer, x, y, ARGB2RGBA(color.toArgb32()), map, mapWidth, mapHeight, mapStride, clip, useGammaCorrection);
}
#endif
+inline static int qRgbAvg(QRgb rgb)
+{
+ return (qRed(rgb) * 5 + qGreen(rgb) * 6 + qBlue(rgb) * 5) / 16;
+}
+
static void qt_alphargbblit_argb32(QRasterBuffer *rasterBuffer,
int x, int y, const QRgba64 &color,
const uint *src, int mapWidth, int mapHeight, int srcStride,
- const QClipData *clip)
+ const QClipData *clip, bool useGammaCorrection)
{
const quint32 c = color.toArgb32();
- int sr = qRed(c);
- int sg = qGreen(c);
- int sb = qBlue(c);
int sa = qAlpha(c);
- const QDrawHelperGammaTables *tables = QGuiApplicationPrivate::instance()->gammaTables();
- if (!tables)
+ const QColorProfile *colorProfile = QGuiApplicationPrivate::instance()->colorProfileForA32Text();
+ if (!colorProfile)
return;
- const uchar *gamma = tables->qt_pow_rgb_gamma;
- const uchar *invgamma = tables->qt_pow_rgb_invgamma;
-
- sr = gamma[sr];
- sg = gamma[sg];
- sb = gamma[sb];
+ const QRgba64 slinear = useGammaCorrection ? colorProfile->toLinear64(c) : color;
if (sa == 0)
return;
@@ -5663,7 +5726,13 @@ static void qt_alphargbblit_argb32(QRasterBuffer *rasterBuffer,
if (coverage == 0xffffffff) {
dst[i] = c;
} else if (coverage != 0xff000000) {
- rgbBlendPixel(dst+i, coverage, sr, sg, sb, gamma, invgamma);
+ if (dst[i] >= 0xff000000) {
+ rgbBlendPixel(dst+i, coverage, slinear, colorProfile, useGammaCorrection);
+ } else {
+ // Give up and do a naive blend.
+ const int a = qRgbAvg(coverage);
+ dst[i] = INTERPOLATE_PIXEL_255(c, a, dst[i], 255 - a);
+ }
}
}
@@ -5693,7 +5762,13 @@ static void qt_alphargbblit_argb32(QRasterBuffer *rasterBuffer,
if (coverage == 0xffffffff) {
dst[xp] = c;
} else if (coverage != 0xff000000) {
- rgbBlendPixel(dst+xp, coverage, sr, sg, sb, gamma, invgamma);
+ if (dst[xp] >= 0xff000000) {
+ rgbBlendPixel(dst+xp, coverage, slinear, colorProfile, useGammaCorrection);
+ } else {
+ // Give up and do a naive blend.
+ const int a = qRgbAvg(coverage);
+ dst[xp] = INTERPOLATE_PIXEL_255(c, a, dst[xp], 255 - coverage);
+ }
}
}
} // for (i -> line.count)
diff --git a/src/gui/painting/qdrawhelper_neon.cpp b/src/gui/painting/qdrawhelper_neon.cpp
index a833520b00..cdb374f823 100644
--- a/src/gui/painting/qdrawhelper_neon.cpp
+++ b/src/gui/painting/qdrawhelper_neon.cpp
@@ -539,7 +539,7 @@ void qt_alphamapblit_quint16_neon(QRasterBuffer *rasterBuffer,
int x, int y, const QRgba64 &color,
const uchar *bitmap,
int mapWidth, int mapHeight, int mapStride,
- const QClipData *)
+ const QClipData *, bool /*useGammaCorrection*/)
{
quint16 *dest = reinterpret_cast<quint16*>(rasterBuffer->scanLine(y)) + x;
const int destStride = rasterBuffer->bytesPerLine() / sizeof(quint16);
diff --git a/src/gui/painting/qdrawhelper_neon_p.h b/src/gui/painting/qdrawhelper_neon_p.h
index 3cf949fc32..40475a9bde 100644
--- a/src/gui/painting/qdrawhelper_neon_p.h
+++ b/src/gui/painting/qdrawhelper_neon_p.h
@@ -91,7 +91,7 @@ void qt_alphamapblit_quint16_neon(QRasterBuffer *rasterBuffer,
int x, int y, const QRgba64 &color,
const uchar *bitmap,
int mapWidth, int mapHeight, int mapStride,
- const QClipData *clip);
+ const QClipData *clip, bool /*useGammaCorrection*/);
void qt_scale_image_argb32_on_rgb16_neon(uchar *destPixels, int dbpl,
const uchar *srcPixels, int sbpl, int srch,
diff --git a/src/gui/painting/qdrawhelper_p.h b/src/gui/painting/qdrawhelper_p.h
index 0e46962784..cf2213042d 100644
--- a/src/gui/painting/qdrawhelper_p.h
+++ b/src/gui/painting/qdrawhelper_p.h
@@ -113,13 +113,13 @@ typedef void (*AlphamapBlitFunc)(QRasterBuffer *rasterBuffer,
int x, int y, const QRgba64 &color,
const uchar *bitmap,
int mapWidth, int mapHeight, int mapStride,
- const QClipData *clip);
+ const QClipData *clip, bool useGammaCorrection);
typedef void (*AlphaRGBBlitFunc)(QRasterBuffer *rasterBuffer,
int x, int y, const QRgba64 &color,
const uint *rgbmask,
int mapWidth, int mapHeight, int mapStride,
- const QClipData *clip);
+ const QClipData *clip, bool useGammaCorrection);
typedef void (*RectFillFunc)(QRasterBuffer *rasterBuffer,
int x, int y, int width, int height,
@@ -159,7 +159,6 @@ struct DrawHelper {
extern SrcOverBlendFunc qBlendFunctions[QImage::NImageFormats][QImage::NImageFormats];
extern SrcOverScaleFunc qScaleFunctions[QImage::NImageFormats][QImage::NImageFormats];
extern SrcOverTransformFunc qTransformFunctions[QImage::NImageFormats][QImage::NImageFormats];
-extern MemRotateFunc qMemRotateFunctions[QImage::NImageFormats][3];
extern DrawHelper qDrawHelper[QImage::NImageFormats];
@@ -351,18 +350,6 @@ struct QSpanData
void adjustSpanMethods();
};
-struct QDrawHelperGammaTables
-{
- explicit QDrawHelperGammaTables(qreal smoothing);
-
- void refresh(qreal smoothing);
-
- uchar qt_pow_rgb_gamma[256];
- uchar qt_pow_rgb_invgamma[256];
- uint qt_pow_gamma[256];
- uchar qt_pow_invgamma[2048];
-};
-
static inline uint qt_gradient_clamp(const QGradientData *data, int ipos)
{
if (ipos < 0 || ipos >= GRADIENT_STOPTABLE_SIZE) {
@@ -1244,6 +1231,7 @@ extern QPixelLayout qPixelLayouts[QImage::NImageFormats];
extern const FetchPixelsFunc qFetchPixels[QPixelLayout::BPPCount];
extern StorePixelsFunc qStorePixels[QPixelLayout::BPPCount];
+extern MemRotateFunc qMemRotateFunctions[QPixelLayout::BPPCount][3];
QT_END_NAMESPACE
diff --git a/src/gui/painting/qmemrotate.cpp b/src/gui/painting/qmemrotate.cpp
index 3fbae76de5..25aa6a3122 100644
--- a/src/gui/painting/qmemrotate.cpp
+++ b/src/gui/painting/qmemrotate.cpp
@@ -41,164 +41,10 @@
QT_BEGIN_NAMESPACE
-#if QT_ROTATION_ALGORITHM == QT_ROTATION_TILED
static const int tileSize = 32;
-#endif
-
-#if Q_BYTE_ORDER == Q_BIG_ENDIAN
-#if QT_ROTATION_ALGORITHM == QT_ROTATION_PACKED || QT_ROTATION_ALGORITHM == QT_ROTATION_TILED
-#error Big endian version not implemented for the transformed driver!
-#endif
-#endif
-
-template <class T>
-Q_STATIC_TEMPLATE_FUNCTION
-inline void qt_memrotate90_cachedRead(const T *src, int w, int h, int sstride, T *dest,
- int dstride)
-{
- const char *s = reinterpret_cast<const char*>(src);
- char *d = reinterpret_cast<char*>(dest);
- for (int y = 0; y < h; ++y) {
- for (int x = w - 1; x >= 0; --x) {
- T *destline = reinterpret_cast<T *>(d + (w - x - 1) * dstride);
- destline[y] = src[x];
- }
- s += sstride;
- src = reinterpret_cast<const T*>(s);
- }
-}
template <class T>
Q_STATIC_TEMPLATE_FUNCTION
-inline void qt_memrotate270_cachedRead(const T *src, int w, int h, int sstride, T *dest,
- int dstride)
-{
- const char *s = reinterpret_cast<const char*>(src);
- char *d = reinterpret_cast<char*>(dest);
- s += (h - 1) * sstride;
- for (int y = h - 1; y >= 0; --y) {
- src = reinterpret_cast<const T*>(s);
- for (int x = 0; x < w; ++x) {
- T *destline = reinterpret_cast<T *>(d + x * dstride);
- destline[h - y - 1] = src[x];
- }
- s -= sstride;
- }
-}
-
-#if QT_ROTATION_ALGORITHM == QT_ROTATION_CACHEDWRITE
-
-template <class T>
-Q_STATIC_TEMPLATE_FUNCTION
-inline void qt_memrotate90_cachedWrite(const T *src, int w, int h, int sstride, T *dest,
- int dstride)
-{
- for (int x = w - 1; x >= 0; --x) {
- T *d = dest + (w - x - 1) * dstride;
- for (int y = 0; y < h; ++y) {
- *d++ = src[y * sstride + x];
- }
- }
-
-}
-
-template <class T>
-Q_STATIC_TEMPLATE_FUNCTION
-inline void qt_memrotate270_cachedWrite(const T *src, int w, int h, int sstride, T *dest,
- int dstride)
-{
- for (int x = 0; x < w; ++x) {
- T *d = dest + x * dstride;
- for (int y = h - 1; y >= 0; --y) {
- *d++ = src[y * sstride + x];
- }
- }
-}
-
-#endif // QT_ROTATION_CACHEDWRITE
-
-#if QT_ROTATION_ALGORITHM == QT_ROTATION_PACKING
-
-// TODO: packing algorithms should probably be modified on 64-bit architectures
-
-template <class T>
-Q_STATIC_TEMPLATE_FUNCTION
-inline void qt_memrotate90_packing(const T *src, int w, int h, int sstride, T *dest, int dstride)
-{
- sstride /= sizeof(T);
- dstride /= sizeof(T);
-
- const int pack = sizeof(quint32) / sizeof(T);
- const int unaligned = int((long(dest) & (sizeof(quint32)-1))) / sizeof(T);
-
- for (int x = w - 1; x >= 0; --x) {
- int y = 0;
-
- for (int i = 0; i < unaligned; ++i) {
- dest[(w - x - 1) * dstride + y] = src[y * sstride + x];
- ++y;
- }
-
- quint32 *d = reinterpret_cast<quint32*>(dest + (w - x - 1) * dstride
- + unaligned);
- const int rest = (h - unaligned) % pack;
- while (y < h - rest) {
- quint32 c = src[y * sstride + x];
- for (int i = 1; i < pack; ++i) {
- c |= src[(y + i) * sstride + x] << (sizeof(int) * 8 / pack * i);
- }
- *d++ = c;
- y += pack;
- }
-
- while (y < h) {
- dest[(w - x - 1) * dstride + y] = src[y * sstride + x];
- ++y;
- }
- }
-}
-
-template <class T>
-Q_STATIC_TEMPLATE_FUNCTION
-inline void qt_memrotate270_packing(const T *src, int w, int h, int sstride, T *dest, int dstride)
-{
- sstride /= sizeof(T);
- dstride /= sizeof(T);
-
- const int pack = sizeof(quint32) / sizeof(T);
- const int unaligned = int((long(dest) & (sizeof(quint32)-1))) / sizeof(T);
-
- for (int x = 0; x < w; ++x) {
- int y = h - 1;
-
- for (int i = 0; i < unaligned; ++i) {
- dest[x * dstride + h - y - 1] = src[y * sstride + x];
- --y;
- }
-
- quint32 *d = reinterpret_cast<quint32*>(dest + x * dstride
- + unaligned);
- const int rest = (h - unaligned) % pack;
- while (y > rest) {
- quint32 c = src[y * sstride + x];
- for (int i = 1; i < pack; ++i) {
- c |= src[(y - i) * sstride + x] << (sizeof(int) * 8 / pack * i);
- }
- *d++ = c;
- y -= pack;
- }
- while (y >= 0) {
- dest[x * dstride + h - y - 1] = src[y * sstride + x];
- --y;
- }
- }
-}
-
-#endif // QT_ROTATION_PACKING
-
-#if QT_ROTATION_ALGORITHM == QT_ROTATION_TILED
-template <class T>
-Q_STATIC_TEMPLATE_FUNCTION
inline void qt_memrotate90_tiled(const T *src, int w, int h, int sstride, T *dest, int dstride)
{
sstride /= sizeof(T);
@@ -235,7 +81,7 @@ inline void qt_memrotate90_tiled(const T *src, int w, int h, int sstride, T *des
for (int y = starty; y < stopy; y += pack) {
quint32 c = src[y * sstride + x];
for (int i = 1; i < pack; ++i) {
- const int shift = (sizeof(int) * 8 / pack * i);
+ const int shift = (sizeof(T) * 8 * i);
const T color = src[(y + i) * sstride + x];
c |= color << shift;
}
@@ -293,7 +139,7 @@ inline void qt_memrotate270_tiled(const T *src, int w, int h, int sstride, T *de
const int pack = sizeof(quint32) / sizeof(T);
const int unaligned =
- qMin(uint((long(dest) & (sizeof(quint32)-1)) / sizeof(T)), uint(h));
+ qMin(uint((quintptr(dest) & (sizeof(quint32)-1)) / sizeof(T)), uint(h));
const int restX = w % tileSize;
const int restY = (h - unaligned) % tileSize;
const int unoptimizedY = restY % pack;
@@ -320,10 +166,10 @@ inline void qt_memrotate270_tiled(const T *src, int w, int h, int sstride, T *de
for (int x = startx; x < stopx; ++x) {
quint32 *d = reinterpret_cast<quint32*>(dest + x * dstride
+ h - 1 - starty);
- for (int y = starty; y > stopy; y -= pack) {
+ for (int y = starty; y >= stopy; y -= pack) {
quint32 c = src[y * sstride + x];
for (int i = 1; i < pack; ++i) {
- const int shift = (sizeof(int) * 8 / pack * i);
+ const int shift = (sizeof(T) * 8 * i);
const T color = src[(y - i) * sstride + x];
c |= color << shift;
}
@@ -371,22 +217,26 @@ inline void qt_memrotate270_tiled_unpacked(const T *src, int w, int h, int sstri
}
}
-#endif // QT_ROTATION_ALGORITHM
template <class T>
Q_STATIC_TEMPLATE_FUNCTION
inline void qt_memrotate90_template(const T *src, int srcWidth, int srcHeight, int srcStride,
T *dest, int dstStride)
{
-#if QT_ROTATION_ALGORITHM == QT_ROTATION_CACHEDREAD
- qt_memrotate90_cachedRead<T>(src, srcWidth, srcHeight, srcStride, dest, dstStride);
-#elif QT_ROTATION_ALGORITHM == QT_ROTATION_CACHEDWRITE
- qt_memrotate90_cachedWrite<T>(src, srcWidth, srcHeight, srcStride, dest, dstStride);
-#elif QT_ROTATION_ALGORITHM == QT_ROTATION_PACKING
- qt_memrotate90_packing<T>(src, srcWidth, srcHeight, srcStride, dest, dstStride);
-#elif QT_ROTATION_ALGORITHM == QT_ROTATION_TILED
- qt_memrotate90_tiled<T>(src, srcWidth, srcHeight, srcStride, dest, dstStride);
+#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
+ // packed algorithm assumes little endian and that sizeof(quint32)/sizeof(T) is an integer
+ if (sizeof(quint32) % sizeof(T) == 0)
+ qt_memrotate90_tiled<T>(src, srcWidth, srcHeight, srcStride, dest, dstStride);
+ else
#endif
+ qt_memrotate90_tiled_unpacked<T>(src, srcWidth, srcHeight, srcStride, dest, dstStride);
+}
+
+template <>
+inline void qt_memrotate90_template<quint32>(const quint32 *src, int w, int h, int sstride, quint32 *dest, int dstride)
+{
+ // packed algorithm doesn't have any benefit for quint32
+ qt_memrotate90_tiled_unpacked(src, w, h, sstride, dest, dstride);
}
template <class T>
@@ -394,11 +244,11 @@ Q_STATIC_TEMPLATE_FUNCTION
inline void qt_memrotate180_template(const T *src, int w, int h, int sstride, T *dest, int dstride)
{
const char *s = (const char*)(src) + (h - 1) * sstride;
- for (int y = h - 1; y >= 0; --y) {
- T *d = reinterpret_cast<T*>((char *)(dest) + (h - y - 1) * dstride);
+ for (int dy = 0; dy < h; ++dy) {
+ T *d = reinterpret_cast<T*>((char *)(dest) + dy * dstride);
src = reinterpret_cast<const T*>(s);
- for (int x = w - 1; x >= 0; --x) {
- d[w - x - 1] = src[x];
+ for (int dx = 0; dx < w; ++dx) {
+ d[dx] = src[w - 1 - dx];
}
s -= sstride;
}
@@ -409,32 +259,20 @@ Q_STATIC_TEMPLATE_FUNCTION
inline void qt_memrotate270_template(const T *src, int srcWidth, int srcHeight, int srcStride,
T *dest, int dstStride)
{
-#if QT_ROTATION_ALGORITHM == QT_ROTATION_CACHEDREAD
- qt_memrotate270_cachedRead<T>(src, srcWidth, srcHeight, srcStride, dest, dstStride);
-#elif QT_ROTATION_ALGORITHM == QT_ROTATION_CACHEDWRITE
- qt_memrotate270_cachedWrite<T>(src, srcWidth, srcHeight, srcStride, dest, dstStride);
-#elif QT_ROTATION_ALGORITHM == QT_ROTATION_PACKING
- qt_memrotate270_packing<T>(src, srcWidth, srcHeight, srcStride, dest, dstStride);
-#elif QT_ROTATION_ALGORITHM == QT_ROTATION_TILED
- qt_memrotate270_tiled_unpacked<T>(src, srcWidth, srcHeight, srcStride, dest, dstStride);
+#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
+ // packed algorithm assumes little endian and that sizeof(quint32)/sizeof(T) is an integer
+ if (sizeof(quint32) % sizeof(T) == 0)
+ qt_memrotate270_tiled<T>(src, srcWidth, srcHeight, srcStride, dest, dstStride);
+ else
#endif
+ qt_memrotate270_tiled_unpacked<T>(src, srcWidth, srcHeight, srcStride, dest, dstStride);
}
template <>
-inline void qt_memrotate90_template<quint24>(const quint24 *src, int srcWidth, int srcHeight,
- int srcStride, quint24 *dest, int dstStride)
+inline void qt_memrotate270_template<quint32>(const quint32 *src, int w, int h, int sstride, quint32 *dest, int dstride)
{
-#if QT_ROTATION_ALGORITHM == QT_ROTATION_CACHEDREAD
- qt_memrotate90_cachedRead<quint24>(src, srcWidth, srcHeight, srcStride, dest, dstStride);
-#elif QT_ROTATION_ALGORITHM == QT_ROTATION_CACHEDWRITE
- qt_memrotate90_cachedWrite<quint24>(src, srcWidth, srcHeight, srcStride, dest, dstStride);
-#elif QT_ROTATION_ALGORITHM == QT_ROTATION_PACKING
- // packed algorithm not implemented
- qt_memrotate90_cachedRead<quint24>(src, srcWidth, srcHeight, srcStride, dest, dstStride);
-#elif QT_ROTATION_ALGORITHM == QT_ROTATION_TILED
- // packed algorithm not implemented
- qt_memrotate90_tiled_unpacked<quint24>(src, srcWidth, srcHeight, srcStride, dest, dstStride);
-#endif
+ // packed algorithm doesn't have any benefit for quint32
+ qt_memrotate270_tiled_unpacked(src, w, h, sstride, dest, dstride);
}
#define QT_IMPL_MEMROTATE(type) \
@@ -458,7 +296,7 @@ Q_GUI_EXPORT void qt_memrotate270(const type *src, int w, int h, int sstride, \
Q_GUI_EXPORT void qt_memrotate90(const type *src, int w, int h, int sstride, \
type *dest, int dstride) \
{ \
- qt_memrotate90_tiled_unpacked<type>(src, w, h, sstride, dest, dstride); \
+ qt_memrotate90_tiled_unpacked(src, w, h, sstride, dest, dstride); \
} \
Q_GUI_EXPORT void qt_memrotate180(const type *src, int w, int h, int sstride, \
type *dest, int dstride) \
@@ -468,7 +306,7 @@ Q_GUI_EXPORT void qt_memrotate180(const type *src, int w, int h, int sstride, \
Q_GUI_EXPORT void qt_memrotate270(const type *src, int w, int h, int sstride, \
type *dest, int dstride) \
{ \
- qt_memrotate270_tiled_unpacked<type>(src, w, h, sstride, dest, dstride); \
+ qt_memrotate270_tiled_unpacked(src, w, h, sstride, dest, dstride); \
}
@@ -509,6 +347,21 @@ void qt_memrotate270_16(const uchar *srcPixels, int w, int h, int sbpl, uchar *d
qt_memrotate270((const ushort *)srcPixels, w, h, sbpl, (ushort *)destPixels, dbpl);
}
+void qt_memrotate90_24(const uchar *srcPixels, int w, int h, int sbpl, uchar *destPixels, int dbpl)
+{
+ qt_memrotate90((const quint24 *)srcPixels, w, h, sbpl, (quint24 *)destPixels, dbpl);
+}
+
+void qt_memrotate180_24(const uchar *srcPixels, int w, int h, int sbpl, uchar *destPixels, int dbpl)
+{
+ qt_memrotate180((const quint24 *)srcPixels, w, h, sbpl, (quint24 *)destPixels, dbpl);
+}
+
+void qt_memrotate270_24(const uchar *srcPixels, int w, int h, int sbpl, uchar *destPixels, int dbpl)
+{
+ qt_memrotate270((const quint24 *)srcPixels, w, h, sbpl, (quint24 *)destPixels, dbpl);
+}
+
void qt_memrotate90_32(const uchar *srcPixels, int w, int h, int sbpl, uchar *destPixels, int dbpl)
{
qt_memrotate90((const uint *)srcPixels, w, h, sbpl, (uint *)destPixels, dbpl);
@@ -524,34 +377,16 @@ void qt_memrotate270_32(const uchar *srcPixels, int w, int h, int sbpl, uchar *d
qt_memrotate270((const uint *)srcPixels, w, h, sbpl, (uint *)destPixels, dbpl);
}
-MemRotateFunc qMemRotateFunctions[QImage::NImageFormats][3] =
+MemRotateFunc qMemRotateFunctions[QPixelLayout::BPPCount][3] =
// 90, 180, 270
{
- { 0, 0, 0 }, // Format_Invalid,
- { 0, 0, 0 }, // Format_Mono,
- { 0, 0, 0 }, // Format_MonoLSB,
- { 0, 0, 0 }, // Format_Indexed8,
- { qt_memrotate90_32, qt_memrotate180_32, qt_memrotate270_32 }, // Format_RGB32,
- { qt_memrotate90_32, qt_memrotate180_32, qt_memrotate270_32 }, // Format_ARGB32,
- { qt_memrotate90_32, qt_memrotate180_32, qt_memrotate270_32 }, // Format_ARGB32_Premultiplied,
- { qt_memrotate90_16, qt_memrotate180_16, qt_memrotate270_16 }, // Format_RGB16,
- { 0, 0, 0 }, // Format_ARGB8565_Premultiplied,
- { 0, 0, 0 }, // Format_RGB666,
- { 0, 0, 0 }, // Format_ARGB6666_Premultiplied,
- { 0, 0, 0 }, // Format_RGB555,
- { 0, 0, 0 }, // Format_ARGB8555_Premultiplied,
- { 0, 0, 0 }, // Format_RGB888,
- { 0, 0, 0 }, // Format_RGB444,
- { 0, 0, 0 }, // Format_ARGB4444_Premultiplied,
- { qt_memrotate90_32, qt_memrotate180_32, qt_memrotate270_32 }, // Format_RGBX8888,
- { qt_memrotate90_32, qt_memrotate180_32, qt_memrotate270_32 }, // Format_RGBA8888,
- { qt_memrotate90_32, qt_memrotate180_32, qt_memrotate270_32 }, // Format_RGBA8888_Premultiplied,
- { qt_memrotate90_32, qt_memrotate180_32, qt_memrotate270_32 }, // Format_BGB30,
- { qt_memrotate90_32, qt_memrotate180_32, qt_memrotate270_32 }, // Format_A2BGR30_Premultiplied,
- { qt_memrotate90_32, qt_memrotate180_32, qt_memrotate270_32 }, // Format_RGB30,
- { qt_memrotate90_32, qt_memrotate180_32, qt_memrotate270_32 }, // Format_A2RGB30_Premultiplied,
- { qt_memrotate90_8, qt_memrotate180_8, qt_memrotate270_8 }, // Format_Alpha8,
- { qt_memrotate90_8, qt_memrotate180_8, qt_memrotate270_8 }, // Format_Grayscale8,
+ { 0, 0, 0 }, // BPPNone,
+ { 0, 0, 0 }, // BPP1MSB,
+ { 0, 0, 0 }, // BPP1LSB,
+ { qt_memrotate90_8, qt_memrotate180_8, qt_memrotate270_8 }, // BPP8,
+ { qt_memrotate90_16, qt_memrotate180_16, qt_memrotate270_16 }, // BPP16,
+ { qt_memrotate90_24, qt_memrotate180_24, qt_memrotate270_24 }, // BPP24
+ { qt_memrotate90_32, qt_memrotate180_32, qt_memrotate270_32 }, // BPP32
};
QT_END_NAMESPACE
diff --git a/src/gui/painting/qmemrotate_p.h b/src/gui/painting/qmemrotate_p.h
index 62613d301a..9bc3fd1010 100644
--- a/src/gui/painting/qmemrotate_p.h
+++ b/src/gui/painting/qmemrotate_p.h
@@ -56,19 +56,6 @@
QT_BEGIN_NAMESPACE
-#define QT_ROTATION_CACHEDREAD 1
-#define QT_ROTATION_CACHEDWRITE 2
-#define QT_ROTATION_PACKING 3
-#define QT_ROTATION_TILED 4
-
-#ifndef QT_ROTATION_ALGORITHM
-#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
-#define QT_ROTATION_ALGORITHM QT_ROTATION_TILED
-#else
-#define QT_ROTATION_ALGORITHM QT_ROTATION_CACHEDREAD
-#endif
-#endif
-
#define QT_DECL_MEMROTATE(type) \
void Q_GUI_EXPORT qt_memrotate90(const type*, int, int, int, type*, int); \
void Q_GUI_EXPORT qt_memrotate180(const type*, int, int, int, type*, int); \
diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp
index 6d5eaf5aed..fc4f2a9944 100644
--- a/src/gui/painting/qpaintengine_raster.cpp
+++ b/src/gui/painting/qpaintengine_raster.cpp
@@ -272,6 +272,35 @@ static void qt_debug_path(const QPainterPath &path)
}
#endif
+// QRect::normalized() will change the width/height of the rectangle due to
+// its incusive-integer definition of left/right vs width. This is not
+// something we want to change in QRect as that would potentially introduce
+// regressions all over the place, so we implement a straightforward
+// normalized here. QRectF already does this, so QRectF::normalized() is ok to
+// use.
+static QRect qrect_normalized(const QRect &rect)
+{
+ int x, y, w, h;
+ if (Q_UNLIKELY(rect.width() < 0)) {
+ x = rect.x() + rect.width();
+ w = -rect.width();
+ } else {
+ x = rect.x();
+ w = rect.width();
+ }
+
+ if (Q_UNLIKELY(rect.height() < 0)) {
+ y = rect.y() + rect.height();
+ h = -rect.height();
+ } else {
+ y = rect.y();
+ h = rect.height();
+ }
+
+ return QRect(x, y, w, h);
+}
+
+
QRasterPaintEnginePrivate::QRasterPaintEnginePrivate() :
QPaintEngineExPrivate(),
cachedLines(0)
@@ -1236,7 +1265,9 @@ void QRasterPaintEngine::clip(const QRect &rect, Qt::ClipOperation op)
bool QRasterPaintEngine::setClipRectInDeviceCoords(const QRect &r, Qt::ClipOperation op)
{
Q_D(QRasterPaintEngine);
- QRect clipRect = r & d->deviceRect;
+ // normalize before using the & operator which uses QRect::normalize()
+ // internally which will give us the wrong values.
+ QRect clipRect = qrect_normalized(r) & d->deviceRect;
QRasterPaintEngineState *s = state();
if (op == Qt::ReplaceClip || s->clip == 0) {
@@ -1471,7 +1502,7 @@ void QRasterPaintEngine::drawRects(const QRect *rects, int rectCount)
int offset_x = int(s->matrix.dx());
int offset_y = int(s->matrix.dy());
while (r < lastRect) {
- QRect rect = r->normalized();
+ QRect rect = qrect_normalized(*r);
QRect rr = rect.translated(offset_x, offset_y);
fillRect_normalized(rr, &s->brushData, d);
++r;
@@ -2266,8 +2297,9 @@ void QRasterPaintEngine::drawImage(const QRectF &r, const QImage &img, const QRe
&& d->rasterBuffer->compositionMode == QPainter::CompositionMode_Source)))
{
RotationType rotationType = qRotationType(s->matrix);
+ const QPixelLayout::BPP plBpp = qPixelLayouts[d->rasterBuffer->format].bpp;
- if (rotationType != NoRotation && qMemRotateFunctions[d->rasterBuffer->format][rotationType] && img.rect().contains(sr.toAlignedRect())) {
+ if (rotationType != NoRotation && qMemRotateFunctions[plBpp][rotationType] && img.rect().contains(sr.toAlignedRect())) {
QRectF transformedTargetRect = s->matrix.mapRect(r);
if ((!(s->renderHints & QPainter::SmoothPixmapTransform) && !(s->renderHints & QPainter::Antialiasing))
@@ -2297,7 +2329,7 @@ void QRasterPaintEngine::drawImage(const QRectF &r, const QImage &img, const QRe
uint cw = clippedSourceRect.width();
uint ch = clippedSourceRect.height();
- qMemRotateFunctions[d->rasterBuffer->format][rotationType](srcBase, cw, ch, sbpl, dstBase, dbpl);
+ qMemRotateFunctions[plBpp][rotationType](srcBase, cw, ch, sbpl, dstBase, dbpl);
return;
}
@@ -2500,7 +2532,7 @@ void QRasterPaintEngine::drawTiledPixmap(const QRectF &r, const QPixmap &pixmap,
QRectF rr = r;
rr.translate(s->matrix.dx(), s->matrix.dy());
- fillRect_normalized(rr.toRect().normalized(), &d->image_filler, d);
+ fillRect_normalized(rr.normalized().toRect(), &d->image_filler, d);
}
}
@@ -2523,7 +2555,7 @@ QRasterBuffer *QRasterPaintEngine::rasterBuffer()
/*!
\internal
*/
-void QRasterPaintEngine::alphaPenBlt(const void* src, int bpl, int depth, int rx,int ry,int w,int h)
+void QRasterPaintEngine::alphaPenBlt(const void* src, int bpl, int depth, int rx,int ry,int w,int h, bool useGammaCorrection)
{
Q_D(QRasterPaintEngine);
QRasterPaintEngineState *s = state();
@@ -2578,14 +2610,14 @@ void QRasterPaintEngine::alphaPenBlt(const void* src, int bpl, int depth, int rx
} else if (depth == 8) {
if (s->penData.alphamapBlit) {
s->penData.alphamapBlit(rb, rx, ry, s->penData.solid.color,
- scanline, w, h, bpl, 0);
+ scanline, w, h, bpl, 0, useGammaCorrection);
return;
}
} else if (depth == 32) {
// (A)RGB Alpha mask where the alpha component is not used.
if (s->penData.alphaRGBBlit) {
s->penData.alphaRGBBlit(rb, rx, ry, s->penData.solid.color,
- (const uint *) scanline, w, h, bpl / 4, 0);
+ (const uint *) scanline, w, h, bpl / 4, 0, useGammaCorrection);
return;
}
}
@@ -2614,10 +2646,10 @@ void QRasterPaintEngine::alphaPenBlt(const void* src, int bpl, int depth, int rx
}
if (depth == 8)
s->penData.alphamapBlit(rb, rx, ry, s->penData.solid.color,
- scanline, w, h, bpl, clip);
+ scanline, w, h, bpl, clip, useGammaCorrection);
else if (depth == 32)
s->penData.alphaRGBBlit(rb, rx, ry, s->penData.solid.color,
- (const uint *) scanline, w, h, bpl / 4, clip);
+ (const uint *) scanline, w, h, bpl / 4, clip, useGammaCorrection);
return;
}
}
@@ -2775,7 +2807,8 @@ bool QRasterPaintEngine::drawCachedGlyphs(int numGlyphs, const glyph_t *glyphs,
alphaPenBlt(alphaMap->constBits(), alphaMap->bytesPerLine(), alphaMap->depth(),
qFloor(positions[i].x) + offset.x(),
qRound(positions[i].y) + offset.y(),
- alphaMap->width(), alphaMap->height());
+ alphaMap->width(), alphaMap->height(),
+ fontEngine->expectsGammaCorrectedBlending());
fontEngine->unlockAlphaMapForGlyph();
}
@@ -2836,7 +2869,7 @@ bool QRasterPaintEngine::drawCachedGlyphs(int numGlyphs, const glyph_t *glyphs,
drawImage(QPoint(x, y), QImage(glyphBits, c.w, c.h, bpl, image.format()));
s->matrix = originalTransform;
} else {
- alphaPenBlt(glyphBits, bpl, depth, x, y, c.w, c.h);
+ alphaPenBlt(glyphBits, bpl, depth, x, y, c.w, c.h, fontEngine->expectsGammaCorrectedBlending());
}
}
}
@@ -2880,7 +2913,7 @@ bool QRasterPaintEnginePrivate::isUnclipped(const QRect &rect,
const QRasterPaintEngineState *s = q->state();
const QClipData *cl = clip();
if (!cl) {
- QRect r = rect.normalized();
+ QRect r = qrect_normalized(rect);
// inline contains() for performance (we know the rects are normalized)
const QRect &r1 = deviceRect;
return (r.left() >= r1.left() && r.right() <= r1.right()
@@ -2895,7 +2928,7 @@ bool QRasterPaintEnginePrivate::isUnclipped(const QRect &rect,
if (s->flags.antialiased)
++penWidth;
- QRect r = rect.normalized();
+ QRect r = qrect_normalized(rect);
if (penWidth > 0) {
r.setX(r.x() - penWidth);
r.setY(r.y() - penWidth);
@@ -4439,9 +4472,9 @@ void QSpanData::setup(const QBrush &brush, int alpha, QPainter::CompositionMode
gradient.alphaColor = !brush.isOpaque() || alpha != 256;
auto cacheInfo = qt_gradient_cache()->getBuffer(*g, alpha);
- cachedGradient = cacheInfo;
gradient.colorTable32 = cacheInfo->buffer32;
gradient.colorTable64 = cacheInfo->buffer64;
+ cachedGradient = std::move(cacheInfo);
gradient.spread = g->spread();
@@ -4461,9 +4494,9 @@ void QSpanData::setup(const QBrush &brush, int alpha, QPainter::CompositionMode
gradient.alphaColor = !brush.isOpaque() || alpha != 256;
auto cacheInfo = qt_gradient_cache()->getBuffer(*g, alpha);
- cachedGradient = cacheInfo;
gradient.colorTable32 = cacheInfo->buffer32;
gradient.colorTable64 = cacheInfo->buffer64;
+ cachedGradient = std::move(cacheInfo);
gradient.spread = g->spread();
@@ -4487,9 +4520,9 @@ void QSpanData::setup(const QBrush &brush, int alpha, QPainter::CompositionMode
gradient.alphaColor = !brush.isOpaque() || alpha != 256;
auto cacheInfo = qt_gradient_cache()->getBuffer(*g, alpha);
- cachedGradient = cacheInfo;
gradient.colorTable32 = cacheInfo->buffer32;
gradient.colorTable64 = cacheInfo->buffer64;
+ cachedGradient = std::move(cacheInfo);
gradient.spread = QGradient::RepeatSpread;
diff --git a/src/gui/painting/qpaintengine_raster_p.h b/src/gui/painting/qpaintengine_raster_p.h
index 59213220a6..d0b82b3a93 100644
--- a/src/gui/painting/qpaintengine_raster_p.h
+++ b/src/gui/painting/qpaintengine_raster_p.h
@@ -225,7 +225,7 @@ public:
#endif
QRasterBuffer *rasterBuffer();
- void alphaPenBlt(const void* src, int bpl, int depth, int rx,int ry,int w,int h);
+ void alphaPenBlt(const void* src, int bpl, int depth, int rx,int ry,int w,int h, bool useGammaCorrection);
Type type() const Q_DECL_OVERRIDE { return Raster; }
diff --git a/src/gui/painting/qpainter.h b/src/gui/painting/qpainter.h
index 46817b9c73..64d15d5296 100644
--- a/src/gui/painting/qpainter.h
+++ b/src/gui/painting/qpainter.h
@@ -83,7 +83,6 @@ class Q_GUI_EXPORT QPainter
{
Q_DECLARE_PRIVATE(QPainter)
Q_GADGET
- Q_FLAGS(RenderHint RenderHints)
public:
enum RenderHint {
@@ -94,8 +93,10 @@ public:
NonCosmeticDefaultPen = 0x10,
Qt4CompatiblePainting = 0x20
};
+ Q_FLAG(RenderHint)
Q_DECLARE_FLAGS(RenderHints, RenderHint)
+ Q_FLAG(RenderHints)
class PixmapFragment {
public:
diff --git a/src/gui/painting/qpdf.cpp b/src/gui/painting/qpdf.cpp
index 84e18a64dd..7b8bae1642 100644
--- a/src/gui/painting/qpdf.cpp
+++ b/src/gui/painting/qpdf.cpp
@@ -1504,16 +1504,25 @@ void QPdfEnginePrivate::writeInfo()
printString(creator);
xprintf("\n/Producer ");
printString(QString::fromLatin1("Qt " QT_VERSION_STR));
- QDateTime now = QDateTime::currentDateTimeUtc();
+ QDateTime now = QDateTime::currentDateTime();
QTime t = now.time();
QDate d = now.date();
- xprintf("\n/CreationDate (D:%d%02d%02d%02d%02d%02d)\n",
+ xprintf("\n/CreationDate (D:%d%02d%02d%02d%02d%02d",
d.year(),
d.month(),
d.day(),
t.hour(),
t.minute(),
t.second());
+ int offset = now.offsetFromUtc();
+ int hours = (offset / 60) / 60;
+ int mins = (offset / 60) % 60;
+ if (offset < 0)
+ xprintf("-%02d'%02d')\n", -hours, -mins);
+ else if (offset > 0)
+ xprintf("+%02d'%02d')\n", hours , mins);
+ else
+ xprintf("Z)\n");
xprintf(">>\n"
"endobj\n");
}
diff --git a/src/gui/painting/qregion.cpp b/src/gui/painting/qregion.cpp
index 0571e1a328..3fb6f925b3 100644
--- a/src/gui/painting/qregion.cpp
+++ b/src/gui/painting/qregion.cpp
@@ -739,7 +739,7 @@ bool QRegion::intersects(const QRegion &region) const
*/
-#if !defined (Q_OS_UNIX) && !defined (Q_OS_WIN)
+#if !defined (Q_OS_UNIX) && !defined (Q_OS_WIN) || defined(Q_CLANG_QDOC)
/*!
\overload
\since 4.4
diff --git a/src/gui/painting/qrgba64_p.h b/src/gui/painting/qrgba64_p.h
index 0dadc038fa..2a17d8a624 100644
--- a/src/gui/painting/qrgba64_p.h
+++ b/src/gui/painting/qrgba64_p.h
@@ -185,6 +185,60 @@ inline QRgba64 addWithSaturation(QRgba64 a, QRgba64 b)
qMin(a.alpha() + b.alpha(), 65535));
}
+#if defined __SSE2__
+Q_ALWAYS_INLINE uint toArgb32(__m128i v)
+{
+ v = _mm_unpacklo_epi16(v, _mm_setzero_si128());
+ v = _mm_add_epi32(v, _mm_set1_epi32(128));
+ v = _mm_sub_epi32(v, _mm_srli_epi32(v, 8));
+ v = _mm_srli_epi32(v, 8);
+ v = _mm_packs_epi32(v, v);
+ v = _mm_packus_epi16(v, v);
+ return _mm_cvtsi128_si32(v);
+}
+#elif defined __ARM_NEON__
+Q_ALWAYS_INLINE uint toArgb32(uint16x4_t v)
+{
+ v = vsub_u16(v, vrshr_n_u16(v, 8));
+ v = vrshr_n_u16(v, 8);
+ uint8x8_t v8 = vmovn_u16(vcombine_u16(v, v));
+ return vget_lane_u32(vreinterpret_u32_u8(v8), 0);
+}
+#endif
+
+inline uint toArgb32(QRgba64 rgba64)
+{
+#if defined __SSE2__
+ __m128i v = _mm_loadl_epi64((const __m128i *)&rgba64);
+ v = _mm_shufflelo_epi16(v, _MM_SHUFFLE(3, 0, 1, 2));
+ return toArgb32(v);
+#elif defined __ARM_NEON__
+ uint16x4_t v = vreinterpret_u16_u64(vld1_u64(reinterpret_cast<const uint64_t *>(&rgba64)));
+#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
+ const uint8x8_t shuffleMask = { 4, 5, 2, 3, 0, 1, 6, 7 };
+ v = vreinterpret_u16_u8(vtbl1_u8(vreinterpret_u8_u16(v), shuffleMask));
+#else
+ v = vext_u16(v, v, 3);
+#endif
+ return toArgb32(v);
+#else
+ return rgba64.toArgb32();
+#endif
+}
+
+inline uint toRgba8888(QRgba64 rgba64)
+{
+#if defined __SSE2__
+ __m128i v = _mm_loadl_epi64((const __m128i *)&rgba64);
+ return toArgb32(v);
+#elif defined __ARM_NEON__
+ uint16x4_t v = vreinterpret_u16_u64(vld1_u64(reinterpret_cast<const uint64_t *>(&rgba64)));
+ return toArgb32(v);
+#else
+ return ARGB2RGBA(toArgb32(rgba64));
+#endif
+}
+
#if defined(__SSE2__)
Q_ALWAYS_INLINE __m128i addWithSaturation(__m128i a, __m128i b)
{
@@ -199,6 +253,52 @@ Q_ALWAYS_INLINE uint16x4_t addWithSaturation(uint16x4_t a, uint16x4_t b)
}
#endif
+inline QRgba64 rgbBlend(QRgba64 d, QRgba64 s, uint rgbAlpha)
+{
+ QRgba64 blend;
+#ifdef __SSE2__
+ __m128i vd = _mm_loadl_epi64((const __m128i *)&d);
+ __m128i vs = _mm_loadl_epi64((const __m128i *)&s);
+ __m128i va = _mm_cvtsi32_si128(rgbAlpha);
+ va = _mm_unpacklo_epi8(va, va);
+ __m128i vb = _mm_xor_si128(_mm_set1_epi16(-1), va);
+
+ vs = _mm_unpacklo_epi16(_mm_mullo_epi16(vs, va), _mm_mulhi_epu16(vs, va));
+ vd = _mm_unpacklo_epi16(_mm_mullo_epi16(vd, vb), _mm_mulhi_epu16(vd, vb));
+ vd = _mm_add_epi32(vd, vs);
+ vd = _mm_add_epi32(vd, _mm_srli_epi32(vd, 16));
+ vd = _mm_add_epi32(vd, _mm_set1_epi32(0x8000));
+ vd = _mm_srai_epi32(vd, 16);
+ vd = _mm_packs_epi32(vd, _mm_setzero_si128());
+
+ _mm_storel_epi64((__m128i *)&blend, vd);
+#elif defined(__ARM_NEON__)
+ uint16x4_t vd = vreinterpret_u16_u64(vmov_n_u64(d));
+ uint16x4_t vs = vreinterpret_u16_u64(vmov_n_u64(s));
+ uint8x8_t va8 = vreinterpret_u8_u32(vmov_n_u32(rgbAlpha));
+ uint16x4_t va = vreinterpret_u16_u8(vzip_u8(va8, va8).val[0]);
+ uint16x4_t vb = vdup_n_u16(0xffff);
+ vb = vsub_u16(vb, va);
+
+ uint32x4_t vs32 = vmull_u16(vs, va);
+ uint32x4_t vd32 = vmull_u16(vd, vb);
+ vd32 = vaddq_u32(vd32, vs32);
+ vd32 = vsraq_n_u32(vd32, vd32, 16);
+ vd = vrshrn_n_u32(vd32, 16);
+ vst1_u64(reinterpret_cast<uint64_t *>(&blend), vreinterpret_u64_u16(vd));
+#else
+ const int mr = qRed(rgbAlpha);
+ const int mg = qGreen(rgbAlpha);
+ const int mb = qBlue(rgbAlpha);
+ blend.setRed (qt_div_255(s.red() * mr + d.red() * (255 - mr)));
+ blend.setGreen(qt_div_255(s.green() * mg + d.green() * (255 - mg)));
+ blend.setBlue (qt_div_255(s.blue() * mb + d.blue() * (255 - mb)));
+ blend.setAlpha(s.alpha());
+#endif
+ return blend;
+}
+
+
QT_END_NAMESPACE
#endif // QRGBA64_P_H
diff --git a/src/gui/painting/qtriangulator.cpp b/src/gui/painting/qtriangulator.cpp
index 6604d407f0..6d57eba123 100644
--- a/src/gui/painting/qtriangulator.cpp
+++ b/src/gui/painting/qtriangulator.cpp
@@ -50,10 +50,6 @@
#include <QtCore/qglobal.h>
#include <QtCore/qpoint.h>
#include <QtCore/qalgorithms.h>
-#ifndef QT_NO_OPENGL
-# include <private/qopenglcontext_p.h>
-# include <private/qopenglextensions_p.h>
-#endif
#include <private/qrbtree_p.h>
QT_BEGIN_NAMESPACE
@@ -2266,23 +2262,12 @@ void QTriangulator<T>::MonotoneToTriangles::decompose()
// qTriangulate //
//============================================================================//
-static bool hasElementIndexUint()
-{
-#ifndef QT_NO_OPENGL
- QOpenGLContext *context = QOpenGLContext::currentContext();
- if (!context)
- return false;
- return static_cast<QOpenGLExtensions *>(context->functions())->hasOpenGLExtension(QOpenGLExtensions::ElementIndexUint);
-#else
- return false;
-#endif
-}
-
Q_GUI_EXPORT QTriangleSet qTriangulate(const qreal *polygon,
- int count, uint hint, const QTransform &matrix)
+ int count, uint hint, const QTransform &matrix,
+ bool allowUintIndices)
{
QTriangleSet triangleSet;
- if (hasElementIndexUint()) {
+ if (allowUintIndices) {
QTriangulator<quint32> triangulator;
triangulator.initialize(polygon, count, hint, matrix);
QVertexSet<quint32> vertexSet = triangulator.triangulate();
@@ -2300,10 +2285,13 @@ Q_GUI_EXPORT QTriangleSet qTriangulate(const qreal *polygon,
}
Q_GUI_EXPORT QTriangleSet qTriangulate(const QVectorPath &path,
- const QTransform &matrix, qreal lod)
+ const QTransform &matrix, qreal lod, bool allowUintIndices)
{
QTriangleSet triangleSet;
- if (hasElementIndexUint()) {
+ // For now systems that support 32-bit index values will always get 32-bit
+ // index values. This is not necessary ideal since 16-bit would be enough in
+ // many cases. TODO revisit this at a later point.
+ if (allowUintIndices) {
QTriangulator<quint32> triangulator;
triangulator.initialize(path, matrix, lod);
QVertexSet<quint32> vertexSet = triangulator.triangulate();
@@ -2320,10 +2308,10 @@ Q_GUI_EXPORT QTriangleSet qTriangulate(const QVectorPath &path,
}
QTriangleSet qTriangulate(const QPainterPath &path,
- const QTransform &matrix, qreal lod)
+ const QTransform &matrix, qreal lod, bool allowUintIndices)
{
QTriangleSet triangleSet;
- if (hasElementIndexUint()) {
+ if (allowUintIndices) {
QTriangulator<quint32> triangulator;
triangulator.initialize(path, matrix, lod);
QVertexSet<quint32> vertexSet = triangulator.triangulate();
@@ -2340,10 +2328,10 @@ QTriangleSet qTriangulate(const QPainterPath &path,
}
QPolylineSet qPolyline(const QVectorPath &path,
- const QTransform &matrix, qreal lod)
+ const QTransform &matrix, qreal lod, bool allowUintIndices)
{
QPolylineSet polyLineSet;
- if (hasElementIndexUint()) {
+ if (allowUintIndices) {
QTriangulator<quint32> triangulator;
triangulator.initialize(path, matrix, lod);
QVertexSet<quint32> vertexSet = triangulator.polyline();
@@ -2360,10 +2348,10 @@ QPolylineSet qPolyline(const QVectorPath &path,
}
QPolylineSet qPolyline(const QPainterPath &path,
- const QTransform &matrix, qreal lod)
+ const QTransform &matrix, qreal lod, bool allowUintIndices)
{
QPolylineSet polyLineSet;
- if (hasElementIndexUint()) {
+ if (allowUintIndices) {
QTriangulator<quint32> triangulator;
triangulator.initialize(path, matrix, lod);
QVertexSet<quint32> vertexSet = triangulator.polyline();
diff --git a/src/gui/painting/qtriangulator_p.h b/src/gui/painting/qtriangulator_p.h
index 4d1aba099c..8f043fc925 100644
--- a/src/gui/painting/qtriangulator_p.h
+++ b/src/gui/painting/qtriangulator_p.h
@@ -137,11 +137,18 @@ struct Q_GUI_EXPORT QPolylineSet
// integers, the polygon is triangulated, and then scaled back by 1/32.
// 'hint' should be a combination of QVectorPath::Hints.
// 'lod' is the level of detail. Default is 1. Curves are split into more lines when 'lod' is higher.
-QTriangleSet Q_GUI_EXPORT qTriangulate(const qreal *polygon, int count, uint hint = QVectorPath::PolygonHint | QVectorPath::OddEvenFill, const QTransform &matrix = QTransform());
-QTriangleSet Q_GUI_EXPORT qTriangulate(const QVectorPath &path, const QTransform &matrix = QTransform(), qreal lod = 1);
-QTriangleSet Q_GUI_EXPORT qTriangulate(const QPainterPath &path, const QTransform &matrix = QTransform(), qreal lod = 1);
-QPolylineSet qPolyline(const QVectorPath &path, const QTransform &matrix = QTransform(), qreal lod = 1);
-QPolylineSet Q_GUI_EXPORT qPolyline(const QPainterPath &path, const QTransform &matrix = QTransform(), qreal lod = 1);
+QTriangleSet Q_GUI_EXPORT qTriangulate(const qreal *polygon, int count,
+ uint hint = QVectorPath::PolygonHint | QVectorPath::OddEvenFill,
+ const QTransform &matrix = QTransform(),
+ bool allowUintIndices = true);
+QTriangleSet Q_GUI_EXPORT qTriangulate(const QVectorPath &path, const QTransform &matrix = QTransform(),
+ qreal lod = 1, bool allowUintIndices = true);
+QTriangleSet Q_GUI_EXPORT qTriangulate(const QPainterPath &path, const QTransform &matrix = QTransform(),
+ qreal lod = 1, bool allowUintIndices = true);
+QPolylineSet qPolyline(const QVectorPath &path, const QTransform &matrix = QTransform(),
+ qreal lod = 1, bool allowUintIndices = true);
+QPolylineSet Q_GUI_EXPORT qPolyline(const QPainterPath &path, const QTransform &matrix = QTransform(),
+ qreal lod = 1, bool allowUintIndices = true);
QT_END_NAMESPACE
diff --git a/src/gui/text/qfontengine.cpp b/src/gui/text/qfontengine.cpp
index 0b2972f189..596c79fd05 100644
--- a/src/gui/text/qfontengine.cpp
+++ b/src/gui/text/qfontengine.cpp
@@ -445,6 +445,11 @@ bool QFontEngine::supportsTransformation(const QTransform &transform) const
return transform.type() < QTransform::TxProject;
}
+bool QFontEngine::expectsGammaCorrectedBlending() const
+{
+ return true;
+}
+
void QFontEngine::getGlyphPositions(const QGlyphLayout &glyphs, const QTransform &matrix, QTextItem::RenderFlags flags,
QVarLengthArray<glyph_t> &glyphs_out, QVarLengthArray<QFixedPoint> &positions)
{
@@ -1268,7 +1273,7 @@ const uchar *QFontEngine::getCMap(const uchar *table, uint tableSize, bool *isSy
if (!qSafeFromBigEndian(maps + 8 * n, endPtr, &platformId))
return 0;
- quint16 platformSpecificId;
+ quint16 platformSpecificId = 0;
if (!qSafeFromBigEndian(maps + 8 * n + 2, endPtr, &platformSpecificId))
return 0;
diff --git a/src/gui/text/qfontengine_ft.cpp b/src/gui/text/qfontengine_ft.cpp
index de6da88245..03e72546eb 100644
--- a/src/gui/text/qfontengine_ft.cpp
+++ b/src/gui/text/qfontengine_ft.cpp
@@ -61,17 +61,19 @@
#include FT_TRUETYPE_TABLES_H
#include FT_TYPE1_TABLES_H
#include FT_GLYPH_H
+#include FT_MODULE_H
#if defined(FT_LCD_FILTER_H)
#include FT_LCD_FILTER_H
+#define QT_USE_FREETYPE_LCDFILTER
#endif
#if defined(FT_CONFIG_OPTIONS_H)
#include FT_CONFIG_OPTIONS_H
#endif
-#if defined(FT_LCD_FILTER_H)
-#define QT_USE_FREETYPE_LCDFILTER
+#if defined(FT_FONT_FORMATS_H)
+#include FT_FONT_FORMATS_H
#endif
#ifdef QT_LINUXBASE
@@ -151,6 +153,14 @@ QtFreetypeData *qt_getFreetypeData()
QtFreetypeData *&freetypeData = theFreetypeData()->localData();
if (!freetypeData)
freetypeData = new QtFreetypeData;
+ if (!freetypeData->library) {
+ FT_Init_FreeType(&freetypeData->library);
+#if defined(FT_FONT_FORMATS_H)
+ // Freetype defaults to disabling stem-darkening on CFF, we re-enable it.
+ FT_Bool no_darkening = false;
+ FT_Property_Set(freetypeData->library, "cff", "no-stem-darkening", &no_darkening);
+#endif
+ }
return freetypeData;
}
#endif
@@ -158,8 +168,7 @@ QtFreetypeData *qt_getFreetypeData()
FT_Library qt_getFreetype()
{
QtFreetypeData *freetypeData = qt_getFreetypeData();
- if (!freetypeData->library)
- FT_Init_FreeType(&freetypeData->library);
+ Q_ASSERT(freetypeData->library);
return freetypeData->library;
}
@@ -218,8 +227,6 @@ QFreetypeFace *QFreetypeFace::getFace(const QFontEngine::FaceId &face_id,
return 0;
QtFreetypeData *freetypeData = qt_getFreetypeData();
- if (!freetypeData->library)
- FT_Init_FreeType(&freetypeData->library);
QFreetypeFace *freetype = freetypeData->faces.value(face_id, 0);
if (freetype) {
@@ -687,6 +694,7 @@ QFontEngineFT::QFontEngineFT(const QFontDef &fd)
cacheEnabled = env.isEmpty() || env.toInt() == 0;
m_subPixelPositionCount = 4;
forceAutoHint = false;
+ stemDarkeningDriver = false;
}
QFontEngineFT::~QFontEngineFT()
@@ -798,6 +806,17 @@ bool QFontEngineFT::init(FaceId faceId, bool antialias, GlyphFormat format,
}
}
}
+#if defined(FT_FONT_FORMATS_H)
+ const char *fmt = FT_Get_Font_Format(face);
+ if (fmt && qstrncmp(fmt, "CFF", 4) == 0) {
+ FT_Bool no_stem_darkening = true;
+ FT_Error err = FT_Property_Get(qt_getFreetype(), "cff", "no-stem-darkening", &no_stem_darkening);
+ if (err == FT_Err_Ok)
+ stemDarkeningDriver = !no_stem_darkening;
+ else
+ stemDarkeningDriver = false;
+ }
+#endif
fontDef.styleName = QString::fromUtf8(face->style_name);
@@ -841,6 +860,11 @@ void QFontEngineFT::setDefaultHintStyle(HintStyle style)
default_hint_style = style;
}
+bool QFontEngineFT::expectsGammaCorrectedBlending() const
+{
+ return stemDarkeningDriver;
+}
+
int QFontEngineFT::loadFlags(QGlyphSet *set, GlyphFormat format, int flags,
bool &hsubpixel, int &vfactor) const
{
diff --git a/src/gui/text/qfontengine_ft_p.h b/src/gui/text/qfontengine_ft_p.h
index 32357d0076..47f13eb274 100644
--- a/src/gui/text/qfontengine_ft_p.h
+++ b/src/gui/text/qfontengine_ft_p.h
@@ -252,6 +252,7 @@ private:
QPoint *offset) Q_DECL_OVERRIDE;
bool hasInternalCaching() const Q_DECL_OVERRIDE { return cacheEnabled; }
void unlockAlphaMapForGlyph() Q_DECL_OVERRIDE;
+ bool expectsGammaCorrectedBlending() const Q_DECL_OVERRIDE;
void removeGlyphFromCache(glyph_t glyph) Q_DECL_OVERRIDE;
int glyphMargin(QFontEngine::GlyphFormat /* format */) Q_DECL_OVERRIDE { return 0; }
@@ -311,6 +312,7 @@ protected:
bool embeddedbitmap;
bool cacheEnabled;
bool forceAutoHint;
+ bool stemDarkeningDriver;
private:
friend class QFontEngineFTRawFont;
diff --git a/src/gui/text/qfontengine_p.h b/src/gui/text/qfontengine_p.h
index c0e350f755..514e9424b2 100644
--- a/src/gui/text/qfontengine_p.h
+++ b/src/gui/text/qfontengine_p.h
@@ -254,6 +254,7 @@ public:
static QByteArray convertToPostscriptFontFamilyName(const QByteArray &fontFamily);
virtual bool hasUnreliableGlyphOutline() const;
+ virtual bool expectsGammaCorrectedBlending() const;
enum HintStyle {
HintNone,
diff --git a/src/gui/text/qplatformfontdatabase.cpp b/src/gui/text/qplatformfontdatabase.cpp
index b83affecdc..ac3d274b36 100644
--- a/src/gui/text/qplatformfontdatabase.cpp
+++ b/src/gui/text/qplatformfontdatabase.cpp
@@ -423,14 +423,14 @@ QFont QPlatformFontDatabase::defaultFont() const
return QFont(QLatin1String("Helvetica"));
}
+
+QString qt_resolveFontFamilyAlias(const QString &alias);
+
/*!
Resolve alias to actual font family names.
\since 5.0
*/
-
-QString qt_resolveFontFamilyAlias(const QString &alias);
-
QString QPlatformFontDatabase::resolveFontFamilyAlias(const QString &family) const
{
return qt_resolveFontFamilyAlias(family);
@@ -628,12 +628,13 @@ QSupportedWritingSystems QPlatformFontDatabase::writingSystemsFromTrueTypeBits(q
}
/*!
- Helper function that returns the Qt font weight matching a given opentype integer value.
+ Helper function that returns the Qt font weight matching
+ a given opentype integer value. Converts the integer
+ \a weight (0 ~ 1000) to QFont::Weight and returns it.
\since 5.5
*/
-// convert 0 ~ 1000 integer to QFont::Weight
QFont::Weight QPlatformFontDatabase::weightFromInteger(int weight)
{
if (weight < 150)
diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp
index c006e7f427..6074917087 100644
--- a/src/gui/text/qtextdocument.cpp
+++ b/src/gui/text/qtextdocument.cpp
@@ -1145,13 +1145,30 @@ void QTextDocument::setMetaInformation(MetaInformation info, const QString &stri
}
/*!
+ Returns the raw text contained in the document without any
+ formatting information. If you want formatting information
+ use a QTextCursor instead.
+
+ \since 5.9
+ \sa toPlainText()
+*/
+QString QTextDocument::toRawText() const
+{
+ Q_D(const QTextDocument);
+ return d->plainText();
+}
+
+/*!
Returns the plain text contained in the document. If you want
formatting information use a QTextCursor instead.
- Some formatting characters are replaced by ASCII equivalents.
+ This function returns the same as toRawText(), but will replace
+ some unicode characters with ASCII alternatives.
In particular, no-break space (U+00A0) is replaced by a regular
space (U+0020), and both paragraph (U+2029) and line (U+2028)
separators are replaced by line feed (U+000A).
+ If you need the precise contents of the document, use toRawText()
+ instead.
\note Embedded objects, such as images, are represented by a
Unicode value U+FFFC (OBJECT REPLACEMENT CHARACTER).
diff --git a/src/gui/text/qtextdocument.h b/src/gui/text/qtextdocument.h
index 1888088f0d..c2761a39b9 100644
--- a/src/gui/text/qtextdocument.h
+++ b/src/gui/text/qtextdocument.h
@@ -151,6 +151,7 @@ public:
void setHtml(const QString &html);
#endif
+ QString toRawText() const;
QString toPlainText() const;
void setPlainText(const QString &text);
diff --git a/src/gui/text/qtexthtmlparser.cpp b/src/gui/text/qtexthtmlparser.cpp
index d4c43b3069..269e505a56 100644
--- a/src/gui/text/qtexthtmlparser.cpp
+++ b/src/gui/text/qtexthtmlparser.cpp
@@ -329,17 +329,17 @@ bool operator<(const QTextHtmlEntity &entity1, const QTextHtmlEntity &entity2)
}
#endif
-static bool operator<(const QString &entityStr, const QTextHtmlEntity &entity)
+static bool operator<(const QStringRef &entityStr, const QTextHtmlEntity &entity)
{
return entityStr < QLatin1String(entity.name);
}
-static bool operator<(const QTextHtmlEntity &entity, const QString &entityStr)
+static bool operator<(const QTextHtmlEntity &entity, const QStringRef &entityStr)
{
return QLatin1String(entity.name) < entityStr;
}
-static QChar resolveEntity(const QString &entity)
+static QChar resolveEntity(const QStringRef &entity)
{
const QTextHtmlEntity *start = &entities[0];
const QTextHtmlEntity *end = &entities[MAX_ENTITY];
@@ -801,8 +801,9 @@ void QTextHtmlParser::parseExclamationTag()
// parses an entity after "&", and returns it
QString QTextHtmlParser::parseEntity()
{
- int recover = pos;
- QString entity;
+ const int recover = pos;
+ int entityLen = 0;
+ QStringRef entity;
while (pos < len) {
QChar c = txt.at(pos++);
if (c.isSpace() || pos - recover > 9) {
@@ -810,36 +811,38 @@ QString QTextHtmlParser::parseEntity()
}
if (c == QLatin1Char(';'))
break;
- entity += c;
+ ++entityLen;
}
- {
+ if (entityLen) {
+ entity = QStringRef(&txt, recover, entityLen);
QChar resolved = resolveEntity(entity);
if (!resolved.isNull())
return QString(resolved);
- }
- if (entity.length() > 1 && entity.at(0) == QLatin1Char('#')) {
- entity.remove(0, 1); // removing leading #
- int base = 10;
- bool ok = false;
+ if (entityLen > 1 && entity.at(0) == QLatin1Char('#')) {
+ entity = entity.mid(1); // removing leading #
- if (entity.at(0).toLower() == QLatin1Char('x')) { // hex entity?
- entity.remove(0, 1);
- base = 16;
- }
+ int base = 10;
+ bool ok = false;
- uint uc = entity.toUInt(&ok, base);
- if (ok) {
- if (uc >= 0x80 && uc < 0x80 + (sizeof(windowsLatin1ExtendedCharacters)/sizeof(windowsLatin1ExtendedCharacters[0])))
- uc = windowsLatin1ExtendedCharacters[uc - 0x80];
- QString str;
- if (QChar::requiresSurrogates(uc)) {
- str += QChar(QChar::highSurrogate(uc));
- str += QChar(QChar::lowSurrogate(uc));
- } else {
- str = QChar(uc);
+ if (entity.at(0).toLower() == QLatin1Char('x')) { // hex entity?
+ entity = entity.mid(1);
+ base = 16;
+ }
+
+ uint uc = entity.toUInt(&ok, base);
+ if (ok) {
+ if (uc >= 0x80 && uc < 0x80 + (sizeof(windowsLatin1ExtendedCharacters)/sizeof(windowsLatin1ExtendedCharacters[0])))
+ uc = windowsLatin1ExtendedCharacters[uc - 0x80];
+ QString str;
+ if (QChar::requiresSurrogates(uc)) {
+ str += QChar(QChar::highSurrogate(uc));
+ str += QChar(QChar::lowSurrogate(uc));
+ } else {
+ str = QChar(uc);
+ }
+ return str;
}
- return str;
}
}
error:
diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp
index 540bbf5d54..023a1b7f52 100644
--- a/src/gui/text/qtextlayout.cpp
+++ b/src/gui/text/qtextlayout.cpp
@@ -1653,6 +1653,7 @@ namespace {
int maxGlyphs;
int currentPosition;
glyph_t previousGlyph;
+ QFontEngine *previousGlyphFontEngine;
QFixed minw;
QFixed softHyphenWidth;
@@ -1686,13 +1687,14 @@ namespace {
if (currentPosition > 0 &&
logClusters[currentPosition - 1] < glyphs.numGlyphs) {
previousGlyph = currentGlyph(); // needed to calculate right bearing later
+ previousGlyphFontEngine = fontEngine;
}
}
- inline void calculateRightBearing(glyph_t glyph)
+ inline void calculateRightBearing(QFontEngine *engine, glyph_t glyph)
{
qreal rb;
- fontEngine->getGlyphBearings(glyph, 0, &rb);
+ engine->getGlyphBearings(glyph, 0, &rb);
// We only care about negative right bearings, so we limit the range
// of the bearing here so that we can assume it's negative in the rest
@@ -1705,13 +1707,13 @@ namespace {
{
if (currentPosition <= 0)
return;
- calculateRightBearing(currentGlyph());
+ calculateRightBearing(fontEngine, currentGlyph());
}
inline void calculateRightBearingForPreviousGlyph()
{
if (previousGlyph > 0)
- calculateRightBearing(previousGlyph);
+ calculateRightBearing(previousGlyphFontEngine, previousGlyph);
}
static const QFixed RightBearingNotCalculated;
diff --git a/src/gui/util/qdesktopservices.cpp b/src/gui/util/qdesktopservices.cpp
index 085c073bb1..c9747877f7 100644
--- a/src/gui/util/qdesktopservices.cpp
+++ b/src/gui/util/qdesktopservices.cpp
@@ -198,8 +198,15 @@ bool QDesktopServices::openUrl(const QUrl &url)
return false;
QPlatformIntegration *platformIntegration = QGuiApplicationPrivate::platformIntegration();
- if (!platformIntegration)
+ if (Q_UNLIKELY(!platformIntegration)) {
+ QCoreApplication *application = QCoreApplication::instance();
+ if (Q_UNLIKELY(!application))
+ qWarning("QDesktopServices::openUrl: Please instantiate the QGuiApplication object "
+ "first");
+ else if (Q_UNLIKELY(!qobject_cast<QGuiApplication *>(application)))
+ qWarning("QDesktopServices::openUrl: Application is not a GUI application");
return false;
+ }
QPlatformServices *platformServices = platformIntegration->services();
if (!platformServices) {