aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick
diff options
context:
space:
mode:
authorMorten Johan Sørvig <morten.sorvig@qt.io>2018-06-04 10:45:14 +0200
committerMorten Johan Sørvig <morten.sorvig@qt.io>2018-06-04 10:45:14 +0200
commit3ca5f33c8b9c273f0169ec4c11417328f8071e97 (patch)
tree155da80482fb4593ca074f7a1bf9b22d031dba4a /src/quick
parent5f4698c4e7952d64e78e3a06de5ac28d68415b19 (diff)
parentb7a1bcd83a8f68185b617b860cef6f2d2d7c8d9b (diff)
Merge remote-tracking branch 'gerrit/5.11' into wip/webassembly
Diffstat (limited to 'src/quick')
-rw-r--r--src/quick/configure.json1
-rw-r--r--src/quick/doc/src/guidelines/qtquick-bestpractices.qdoc5
-rw-r--r--src/quick/handlers/qquickmultipointhandler.cpp2
-rw-r--r--src/quick/handlers/qquickpinchhandler.cpp7
-rw-r--r--src/quick/items/context2d/qquickcontext2d.cpp2
-rw-r--r--src/quick/items/qquickanimatedimage.cpp16
-rw-r--r--src/quick/items/qquickanimatedsprite.cpp4
-rw-r--r--src/quick/items/qquickevents.cpp34
-rw-r--r--src/quick/items/qquickevents_p_p.h10
-rw-r--r--src/quick/items/qquickimagebase_p.h2
-rw-r--r--src/quick/items/qquickitem.cpp11
-rw-r--r--src/quick/items/qquicklistview.cpp7
-rw-r--r--src/quick/items/qquickmousearea.cpp2
-rw-r--r--src/quick/items/qquicksprite.cpp7
-rw-r--r--src/quick/items/qquicksprite_p.h12
-rw-r--r--src/quick/items/qquickspriteengine.cpp50
-rw-r--r--src/quick/items/qquickspritesequence.cpp2
-rw-r--r--src/quick/items/qquicktextcontrol.cpp8
-rw-r--r--src/quick/items/qquickwindow.cpp9
-rw-r--r--src/quick/scenegraph/adaptations/software/qsgsoftwareinternalimagenode.cpp11
-rw-r--r--src/quick/scenegraph/adaptations/software/qsgsoftwarespritenode.cpp2
-rw-r--r--src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp117
-rw-r--r--src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h10
-rw-r--r--src/quick/scenegraph/qsgdefaultrendercontext.cpp12
-rw-r--r--src/quick/scenegraph/qsgdefaultrendercontext_p.h3
-rw-r--r--src/quick/scenegraph/scenegraph.pri1
26 files changed, 205 insertions, 142 deletions
diff --git a/src/quick/configure.json b/src/quick/configure.json
index b77ea863b3..ea1d49baad 100644
--- a/src/quick/configure.json
+++ b/src/quick/configure.json
@@ -120,6 +120,7 @@
"label": "Path support",
"purpose": "Provides Path elements.",
"section": "Qt Quick",
+ "condition": "features.quick-shadereffect",
"output": [
"privateFeature"
]
diff --git a/src/quick/doc/src/guidelines/qtquick-bestpractices.qdoc b/src/quick/doc/src/guidelines/qtquick-bestpractices.qdoc
index e70791d1c9..30aca38678 100644
--- a/src/quick/doc/src/guidelines/qtquick-bestpractices.qdoc
+++ b/src/quick/doc/src/guidelines/qtquick-bestpractices.qdoc
@@ -29,6 +29,7 @@
\page qtquick-bestpractices.html
\title Best Practices for QML and Qt Quick
\brief Lists best practices for working with QML and Qt Quick
+\ingroup best-practices
Despite all of the benefits that QML and Qt Quick offer, they can be
challenging in certain situations. The following sections elaborate on some of
@@ -317,8 +318,8 @@ component loaded by the engine. Context properties are useful for objects that
must be available as soon as the QML is loaded and cannot be instantiated in
QML.
-\l {Integrating QML and C++} demonstrates an alternative approach where QML is
-made aware of a C++ type so that it can instantiate it itself.
+For a quick guide to choosing the correct approach to expose C++ types to QML,
+see \l {Choosing the Correct Integration Method Between C++ and QML}.
\section2 Related Information
\list
diff --git a/src/quick/handlers/qquickmultipointhandler.cpp b/src/quick/handlers/qquickmultipointhandler.cpp
index b126b93211..d595b4c9b4 100644
--- a/src/quick/handlers/qquickmultipointhandler.cpp
+++ b/src/quick/handlers/qquickmultipointhandler.cpp
@@ -76,8 +76,10 @@ bool QQuickMultiPointHandler::wantsPointerEvent(QQuickPointerEvent *event)
if (!QQuickPointerDeviceHandler::wantsPointerEvent(event))
return false;
+#if QT_CONFIG(gestures)
if (event->asPointerNativeGestureEvent())
return true;
+#endif
if (sameAsCurrentPoints(event))
return true;
diff --git a/src/quick/handlers/qquickpinchhandler.cpp b/src/quick/handlers/qquickpinchhandler.cpp
index 155822197f..fc69accffc 100644
--- a/src/quick/handlers/qquickpinchhandler.cpp
+++ b/src/quick/handlers/qquickpinchhandler.cpp
@@ -248,6 +248,7 @@ bool QQuickPinchHandler::wantsPointerEvent(QQuickPointerEvent *event)
if (!QQuickMultiPointHandler::wantsPointerEvent(event))
return false;
+#if QT_CONFIG(gestures)
if (const auto gesture = event->asPointerNativeGestureEvent()) {
if (minimumPointCount() == 2) {
switch (gesture->type()) {
@@ -263,6 +264,7 @@ bool QQuickPinchHandler::wantsPointerEvent(QQuickPointerEvent *event)
return false;
}
}
+#endif
return true;
}
@@ -319,6 +321,7 @@ void QQuickPinchHandler::handlePointerEventImpl(QQuickPointerEvent *event)
}
qreal dist = 0;
+#if QT_CONFIG(gestures)
if (const auto gesture = event->asPointerNativeGestureEvent()) {
switch (gesture->type()) {
case Qt::EndNativeGesture:
@@ -349,7 +352,9 @@ void QQuickPinchHandler::handlePointerEventImpl(QQuickPointerEvent *event)
m_centroidVelocity = QVector2D();
m_activeTranslation = QVector2D();
}
- } else {
+ } else
+#endif // QT_CONFIG(gestures)
+ {
bool containsReleasedPoints = event->isReleaseEvent();
if (!active()) {
// Verify that at least one of the points has moved beyond threshold needed to activate the handler
diff --git a/src/quick/items/context2d/qquickcontext2d.cpp b/src/quick/items/context2d/qquickcontext2d.cpp
index af8048f2e4..addcf9b540 100644
--- a/src/quick/items/context2d/qquickcontext2d.cpp
+++ b/src/quick/items/context2d/qquickcontext2d.cpp
@@ -1637,7 +1637,7 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_createRadialGradient(const
QV4::Scoped<QQuickContext2DStyle> gradient(scope, scope.engine->memoryManager->allocObject<QQuickContext2DStyle>());
QV4::ScopedObject p(scope, ed->gradientProto.value());
gradient->setPrototype(p);
- *gradient->d()->brush = QRadialGradient(QPointF(x1, y1), r0+r1, QPointF(x0, y0));
+ *gradient->d()->brush = QRadialGradient(QPointF(x1, y1), r1, QPointF(x0, y0), r0);
RETURN_RESULT(*gradient);
}
diff --git a/src/quick/items/qquickanimatedimage.cpp b/src/quick/items/qquickanimatedimage.cpp
index 26dfdb07a6..075c4a7d72 100644
--- a/src/quick/items/qquickanimatedimage.cpp
+++ b/src/quick/items/qquickanimatedimage.cpp
@@ -426,15 +426,18 @@ void QQuickAnimatedImage::movieRequestFinished()
}
bool pausedAtStart = d->paused;
- if (d->playing)
+ if (d->movie && d->playing)
d->movie->start();
- if (pausedAtStart)
+ if (d->movie && pausedAtStart)
d->movie->setPaused(true);
- if (d->paused || !d->playing) {
+ if (d->movie && (d->paused || !d->playing)) {
d->movie->jumpToFrame(d->presetCurrentFrame);
d->presetCurrentFrame = 0;
}
- d->setPixmap(*d->infoForCurrentFrame(qmlEngine(this)));
+
+ QQuickPixmap *pixmap = d->infoForCurrentFrame(qmlEngine(this));
+ if (pixmap)
+ d->setPixmap(*pixmap);
if (isPlaying() != d->oldPlaying)
emit playingChanged();
@@ -512,7 +515,10 @@ void QQuickAnimatedImagePrivate::setMovie(QMovie *m)
Q_Q(QQuickAnimatedImage);
const int oldFrameCount = q->frameCount();
- delete movie;
+ if (movie) {
+ movie->disconnect();
+ movie->deleteLater();
+ }
movie = m;
if (oldFrameCount != q->frameCount())
diff --git a/src/quick/items/qquickanimatedsprite.cpp b/src/quick/items/qquickanimatedsprite.cpp
index 190c48ac88..887c30f999 100644
--- a/src/quick/items/qquickanimatedsprite.cpp
+++ b/src/quick/items/qquickanimatedsprite.cpp
@@ -527,6 +527,8 @@ void QQuickAnimatedSprite::setSource(QUrl arg)
Q_D(QQuickAnimatedSprite);
if (d->m_sprite->m_source != arg) {
+ const qreal targetDevicePixelRatio = (window() ? window()->effectiveDevicePixelRatio() : qApp->devicePixelRatio());
+ d->m_sprite->setDevicePixelRatio(targetDevicePixelRatio);
d->m_sprite->setSource(arg);
Q_EMIT sourceChanged(arg);
reloadImage();
@@ -713,7 +715,7 @@ QSGSpriteNode* QQuickAnimatedSprite::initNode()
QSGSpriteNode *node = d->sceneGraphContext()->createSpriteNode();
- d->m_sheetSize = QSize(image.size());
+ d->m_sheetSize = QSize(image.size() / image.devicePixelRatioF());
node->setTexture(window()->createTextureFromImage(image));
d->m_spriteEngine->start(0);
node->setTime(0.0f);
diff --git a/src/quick/items/qquickevents.cpp b/src/quick/items/qquickevents.cpp
index 1be4bafe28..d020ad7c4c 100644
--- a/src/quick/items/qquickevents.cpp
+++ b/src/quick/items/qquickevents.cpp
@@ -849,14 +849,16 @@ void QQuickEventPoint::setGrabberItem(QQuickItem *grabber)
qCDebug(lcPointerGrab) << pointDeviceName(this) << "point" << hex << m_pointId << pointStateString(this)
<< ": grab" << m_exclusiveGrabber << "->" << grabber;
}
+ QQuickItem *oldGrabberItem = grabberItem();
m_exclusiveGrabber = QPointer<QObject>(grabber);
m_grabberIsHandler = false;
m_sceneGrabPos = m_scenePos;
- QQuickItem *oldGrabberItem = grabberItem();
- if (oldGrabberHandler)
+ if (oldGrabberHandler) {
oldGrabberHandler->onGrabChanged(oldGrabberHandler, (grabber ? CancelGrabExclusive : UngrabExclusive), this);
- else if (oldGrabberItem && oldGrabberItem != grabber && grabber && pointerEvent()->asPointerTouchEvent())
- oldGrabberItem->touchUngrabEvent();
+ } else if (oldGrabberItem && oldGrabberItem != grabber && grabber && grabber->window()) {
+ QQuickWindowPrivate *windowPriv = QQuickWindowPrivate::get(grabber->window());
+ windowPriv->sendUngrabEvent(oldGrabberItem, windowPriv->isDeliveringTouchAsMouse());
+ }
for (QPointer<QQuickPointerHandler> passiveGrabber : m_passiveGrabbers)
passiveGrabber->onGrabChanged(passiveGrabber, OverrideGrabPassive, this);
}
@@ -1388,6 +1390,7 @@ void QQuickPointerTouchEvent::localize(QQuickItem *target)
point->localizePosition(target);
}
+#if QT_CONFIG(gestures)
QQuickPointerEvent *QQuickPointerNativeGestureEvent::reset(QEvent *event)
{
auto ev = static_cast<QNativeGestureEvent*>(event);
@@ -1417,6 +1420,7 @@ void QQuickPointerNativeGestureEvent::localize(QQuickItem *target)
{
m_gesturePoint->localizePosition(target);
}
+#endif // QT_CONFIG(gestures)
QQuickEventPoint *QQuickPointerMouseEvent::point(int i) const {
if (i == 0)
@@ -1430,11 +1434,13 @@ QQuickEventPoint *QQuickPointerTouchEvent::point(int i) const {
return nullptr;
}
+#if QT_CONFIG(gestures)
QQuickEventPoint *QQuickPointerNativeGestureEvent::point(int i) const {
if (i == 0)
return m_gesturePoint;
return nullptr;
}
+#endif // QT_CONFIG(gestures)
QQuickEventPoint::QQuickEventPoint(QQuickPointerEvent *parent)
: QObject(parent), m_pointId(0), m_exclusiveGrabber(nullptr), m_timestamp(0), m_pressTimestamp(0),
@@ -1572,6 +1578,13 @@ void QQuickPointerTouchEvent::clearGrabbers() const {
}
}
+Qt::TouchPointStates QQuickPointerTouchEvent::touchPointStates() const
+{
+ return m_event
+ ? static_cast<QTouchEvent*>(m_event)->touchPointStates()
+ : Qt::TouchPointStates();
+}
+
/*!
Returns whether the given \a handler is the exclusive grabber of any
touchpoint within this event.
@@ -1586,17 +1599,17 @@ bool QQuickPointerTouchEvent::hasExclusiveGrabber(const QQuickPointerHandler *ha
bool QQuickPointerTouchEvent::isPressEvent() const
{
- return static_cast<QTouchEvent*>(m_event)->touchPointStates() & Qt::TouchPointPressed;
+ return touchPointStates() & Qt::TouchPointPressed;
}
bool QQuickPointerTouchEvent::isUpdateEvent() const
{
- return static_cast<QTouchEvent*>(m_event)->touchPointStates() & (Qt::TouchPointMoved | Qt::TouchPointStationary);
+ return touchPointStates() & (Qt::TouchPointMoved | Qt::TouchPointStationary);
}
bool QQuickPointerTouchEvent::isReleaseEvent() const
{
- return static_cast<QTouchEvent*>(m_event)->touchPointStates() & Qt::TouchPointReleased;
+ return touchPointStates() & Qt::TouchPointReleased;
}
QVector<QPointF> QQuickPointerEvent::unacceptedPressedPointScenePositions() const
@@ -1655,6 +1668,7 @@ QMouseEvent *QQuickPointerTouchEvent::syntheticMouseEvent(int pointID, QQuickIte
return &m_synthMouseEvent;
}
+#if QT_CONFIG(gestures)
/*!
Returns the exclusive grabber of this event, if any, in a vector.
*/
@@ -1712,6 +1726,7 @@ qreal QQuickPointerNativeGestureEvent::value() const
{
return static_cast<QNativeGestureEvent *>(m_event)->value();
}
+#endif // QT_CONFIG(gestures)
/*!
\internal
@@ -1735,12 +1750,13 @@ QQuickEventPoint *QQuickPointerTouchEvent::pointById(int pointId) const {
return nullptr;
}
+#if QT_CONFIG(gestures)
QQuickEventPoint *QQuickPointerNativeGestureEvent::pointById(int pointId) const {
if (m_gesturePoint && pointId == m_gesturePoint->pointId())
return m_gesturePoint;
return nullptr;
}
-
+#endif
/*!
\internal
@@ -1859,6 +1875,7 @@ QTouchEvent *QQuickPointerTouchEvent::asTouchEvent() const
return static_cast<QTouchEvent *>(m_event);
}
+#if QT_CONFIG(gestures)
bool QQuickPointerNativeGestureEvent::allPointsAccepted() const {
return m_gesturePoint->isAccepted();
}
@@ -1871,6 +1888,7 @@ bool QQuickPointerNativeGestureEvent::allPointsGrabbed() const
{
return m_gesturePoint->exclusiveGrabber() != nullptr;
}
+#endif // QT_CONFIG(gestures)
#ifndef QT_NO_DEBUG_STREAM
diff --git a/src/quick/items/qquickevents_p_p.h b/src/quick/items/qquickevents_p_p.h
index 2a1e9dc184..bb6726706d 100644
--- a/src/quick/items/qquickevents_p_p.h
+++ b/src/quick/items/qquickevents_p_p.h
@@ -66,7 +66,9 @@ QT_BEGIN_NAMESPACE
class QQuickPointerDevice;
class QQuickPointerEvent;
class QQuickPointerMouseEvent;
+#if QT_CONFIG(gestures)
class QQuickPointerNativeGestureEvent;
+#endif
class QQuickPointerTabletEvent;
class QQuickPointerTouchEvent;
class QQuickPointerHandler;
@@ -414,11 +416,15 @@ public: // helpers for C++ only (during event delivery)
virtual QQuickPointerMouseEvent *asPointerMouseEvent() { return nullptr; }
virtual QQuickPointerTouchEvent *asPointerTouchEvent() { return nullptr; }
virtual QQuickPointerTabletEvent *asPointerTabletEvent() { return nullptr; }
+#if QT_CONFIG(gestures)
virtual QQuickPointerNativeGestureEvent *asPointerNativeGestureEvent() { return nullptr; }
+#endif
virtual const QQuickPointerMouseEvent *asPointerMouseEvent() const { return nullptr; }
virtual const QQuickPointerTouchEvent *asPointerTouchEvent() const { return nullptr; }
virtual const QQuickPointerTabletEvent *asPointerTabletEvent() const { return nullptr; }
+#if QT_CONFIG(gestures)
virtual const QQuickPointerNativeGestureEvent *asPointerNativeGestureEvent() const { return nullptr; }
+#endif
virtual bool allPointsAccepted() const = 0;
virtual bool allUpdatedPointsAccepted() const = 0;
virtual bool allPointsGrabbed() const = 0;
@@ -510,6 +516,8 @@ public:
QTouchEvent *asTouchEvent() const;
private:
+ Qt::TouchPointStates touchPointStates() const;
+
int m_pointCount = 0;
QVector<QQuickEventTouchPoint *> m_touchPoints;
mutable QMouseEvent m_synthMouseEvent;
@@ -517,6 +525,7 @@ private:
Q_DISABLE_COPY(QQuickPointerTouchEvent)
};
+#if QT_CONFIG(gestures)
class Q_QUICK_PRIVATE_EXPORT QQuickPointerNativeGestureEvent : public QQuickPointerEvent
{
Q_OBJECT
@@ -551,6 +560,7 @@ private:
Q_DISABLE_COPY(QQuickPointerNativeGestureEvent)
};
+#endif // QT_CONFIG(gestures)
// ### Qt 6: move this to qtbase, replace QTouchDevice and the enums in QTabletEvent
diff --git a/src/quick/items/qquickimagebase_p.h b/src/quick/items/qquickimagebase_p.h
index eb04a1d162..d8d0be9b8c 100644
--- a/src/quick/items/qquickimagebase_p.h
+++ b/src/quick/items/qquickimagebase_p.h
@@ -98,7 +98,7 @@ public:
virtual void setAutoTransform(bool transform);
bool autoTransform() const;
- void resolve2xLocalFile(const QUrl &url, qreal targetDevicePixelRatio, QUrl *sourceUrl, qreal *sourceDevicePixelRatio);
+ static void resolve2xLocalFile(const QUrl &url, qreal targetDevicePixelRatio, QUrl *sourceUrl, qreal *sourceDevicePixelRatio);
// Use a virtual rather than a signal->signal to avoid the huge
// connect/conneciton overhead for this rare case.
diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp
index 3a0aea517c..70bb7db2b0 100644
--- a/src/quick/items/qquickitem.cpp
+++ b/src/quick/items/qquickitem.cpp
@@ -3134,6 +3134,9 @@ void QQuickItemPrivate::itemToParentTransform(QTransform &t) const
*/
QTransform QQuickItemPrivate::windowToGlobalTransform() const
{
+ if (Q_UNLIKELY(window == nullptr))
+ return QTransform();
+
QPoint quickWidgetOffset;
QWindow *renderWindow = QQuickRenderControl::renderWindowFor(window, &quickWidgetOffset);
QPointF pos = (renderWindow ? renderWindow : window)->mapToGlobal(quickWidgetOffset);
@@ -3145,6 +3148,9 @@ QTransform QQuickItemPrivate::windowToGlobalTransform() const
*/
QTransform QQuickItemPrivate::globalToWindowTransform() const
{
+ if (Q_UNLIKELY(window == nullptr))
+ return QTransform();
+
QPoint quickWidgetOffset;
QWindow *renderWindow = QQuickRenderControl::renderWindowFor(window, &quickWidgetOffset);
QPointF pos = (renderWindow ? renderWindow : window)->mapToGlobal(quickWidgetOffset);
@@ -7456,11 +7462,8 @@ void QQuickItem::grabMouse()
auto point = fromTouch ?
windowPriv->pointerEventInstance(windowPriv->touchMouseDevice)->pointById(windowPriv->touchMouseId) :
windowPriv->pointerEventInstance(QQuickPointerDevice::genericMouseDevice())->point(0);
- if (point) {
- QQuickItem *oldGrabber = point->grabberItem();
+ if (point)
point->setGrabberItem(this);
- windowPriv->sendUngrabEvent(oldGrabber, fromTouch);
- }
}
/*!
diff --git a/src/quick/items/qquicklistview.cpp b/src/quick/items/qquicklistview.cpp
index 33becd71ec..60f7efae12 100644
--- a/src/quick/items/qquicklistview.cpp
+++ b/src/quick/items/qquicklistview.cpp
@@ -538,8 +538,13 @@ FxViewItem *QQuickListViewPrivate::snapItemAt(qreal pos)
qreal itemTop = item->position();
if (highlight && itemTop >= pos && item->endPosition() <= pos + highlight->size())
return item;
- if (itemTop+item->size()/2 >= pos && itemTop-prevItemSize/2 < pos)
+
+ // Middle of item and spacing (i.e. the middle of the distance between this item and the next
+ qreal halfwayToNextItem = itemTop + (item->size()+spacing) / 2;
+ qreal halfwayToPrevItem = itemTop - (prevItemSize+spacing) / 2;
+ if (halfwayToNextItem >= pos && halfwayToPrevItem < pos)
snapItem = item;
+
prevItemSize = item->size();
}
return snapItem;
diff --git a/src/quick/items/qquickmousearea.cpp b/src/quick/items/qquickmousearea.cpp
index 052da9fe82..c9316c0406 100644
--- a/src/quick/items/qquickmousearea.cpp
+++ b/src/quick/items/qquickmousearea.cpp
@@ -910,7 +910,7 @@ void QQuickMouseArea::ungrabMouse()
if (d->pressed) {
// if our mouse grab has been removed (probably by Flickable), fix our
// state
- d->pressed = nullptr;
+ d->pressed = Qt::NoButton;
d->stealMouse = false;
d->doubleClick = false;
d->overThreshold = false;
diff --git a/src/quick/items/qquicksprite.cpp b/src/quick/items/qquicksprite.cpp
index 6b8567439b..8c59a68982 100644
--- a/src/quick/items/qquicksprite.cpp
+++ b/src/quick/items/qquicksprite.cpp
@@ -38,6 +38,7 @@
****************************************************************************/
#include "qquicksprite_p.h"
+#include "qquickimagebase_p.h"
#include <qqml.h>
#include <QDebug>
#include <QRandomGenerator>
@@ -222,6 +223,7 @@ QQuickSprite::QQuickSprite(QObject *parent)
, m_frameDuration(unsetDuration)
, m_frameDurationVariation(0)
, m_frameSync(false)
+ , m_devicePixelRatio(1.0)
{
}
@@ -265,7 +267,10 @@ void QQuickSprite::startImageLoading()
if (!e)
qWarning() << "QQuickSprite: Cannot find QQmlEngine - this class is only for use in QML and may not work";
}
- m_pix.load(e, m_source);
+ QUrl loadUrl = m_source;
+ QQuickImageBase::resolve2xLocalFile(m_source, m_devicePixelRatio, &loadUrl, &m_devicePixelRatio);
+
+ m_pix.load(e, loadUrl);
}
}
diff --git a/src/quick/items/qquicksprite_p.h b/src/quick/items/qquicksprite_p.h
index 8e119a80a9..fab9e75190 100644
--- a/src/quick/items/qquicksprite_p.h
+++ b/src/quick/items/qquicksprite_p.h
@@ -168,6 +168,16 @@ public:
return m_frameSync;
}
+ void setDevicePixelRatio(qreal dpr)
+ {
+ m_devicePixelRatio = dpr;
+ }
+
+ qreal devicePixelRatio() const
+ {
+ return m_devicePixelRatio;
+ }
+
Q_SIGNALS:
void sourceChanged(QUrl arg);
@@ -308,6 +318,7 @@ private:
friend class QQuickAnimatedSprite;
friend class QQuickSpriteEngine;
friend class QQuickStochasticEngine;
+
int m_generatedCount;
int m_framesPerRow;
int m_rowY;
@@ -325,6 +336,7 @@ private:
int m_frameDuration;
int m_frameDurationVariation;
bool m_frameSync;
+ qreal m_devicePixelRatio;
QQuickPixmap m_pix;
};
diff --git a/src/quick/items/qquickspriteengine.cpp b/src/quick/items/qquickspriteengine.cpp
index 1fd15e61e3..be297bbe76 100644
--- a/src/quick/items/qquickspriteengine.cpp
+++ b/src/quick/items/qquickspriteengine.cpp
@@ -390,6 +390,7 @@ QImage QQuickSpriteEngine::assembledImage(int maxSize)
int w = 0;
m_maxFrames = 0;
m_imageStateCount = 0;
+ qreal pixelRatio = 1.0;
for (QQuickSprite* state : qAsConst(m_sprites)) {
if (state->frames() > m_maxFrames)
@@ -413,6 +414,8 @@ QImage QQuickSpriteEngine::assembledImage(int maxSize)
if (!state->m_frameHeight)
state->m_frameHeight = img.height();
+ pixelRatio = qMax(pixelRatio, state->devicePixelRatio());
+
if (state->frames() * state->frameWidth() > maxSize){
struct helper{
static int divRoundUp(int a, int b){return (a+b-1)/b;}
@@ -437,43 +440,58 @@ QImage QQuickSpriteEngine::assembledImage(int maxSize)
}
}
+ if (h > maxSize){
+ qWarning() << "SpriteEngine: Too many animations to fit in one texture...";
+ qWarning() << "SpriteEngine: Your texture max size today is " << maxSize;
+ return QImage();
+ }
+
//maxFrames is max number in a line of the texture
- QImage image(w, h, QImage::Format_ARGB32_Premultiplied);
+ QImage image(w * pixelRatio, h * pixelRatio, QImage::Format_ARGB32_Premultiplied);
+ image.setDevicePixelRatio(pixelRatio);
image.fill(0);
QPainter p(&image);
int y = 0;
for (QQuickSprite* state : qAsConst(m_sprites)) {
QImage img(state->m_pix.image());
- int frameWidth = state->m_frameWidth;
- int frameHeight = state->m_frameHeight;
- if (img.height() == frameHeight && img.width() < maxSize){//Simple case
- p.drawImage(0,y,img.copy(state->m_frameX,0,state->m_frames * frameWidth, frameHeight));
+ const int frameWidth = state->m_frameWidth;
+ const int frameHeight = state->m_frameHeight;
+ const int imgHeight = img.height() / img.devicePixelRatioF();
+ const int imgWidth = img.width() / img.devicePixelRatioF();
+ if (imgHeight == frameHeight && imgWidth < maxSize){ //Simple case
+ p.drawImage(QRect(0, y, state->m_frames * frameWidth, frameHeight),
+ img,
+ QRect(state->m_frameX * img.devicePixelRatioF(), 0, state->m_frames * frameWidth * img.devicePixelRatioF(), frameHeight * img.devicePixelRatioF()));
state->m_rowStartX = 0;
state->m_rowY = y;
y += frameHeight;
- }else{//Chopping up image case
- state->m_framesPerRow = image.width()/frameWidth;
+ } else { //Chopping up image case
+ state->m_framesPerRow = w/frameWidth;
state->m_rowY = y;
int x = 0;
int curX = state->m_frameX;
int curY = state->m_frameY;
int framesLeft = state->frames();
while (framesLeft > 0){
- if (image.width() - x + curX <= img.width()){//finish a row in image (dest)
- int copied = image.width() - x;
+ if (w - x + curX <= imgWidth){//finish a row in image (dest)
+ int copied = w - x;
framesLeft -= copied/frameWidth;
- p.drawImage(x,y,img.copy(curX,curY,copied,frameHeight));
+ p.drawImage(QRect(x, y, copied, frameHeight),
+ img,
+ QRect(curX * img.devicePixelRatioF(), curY * img.devicePixelRatioF(), copied * img.devicePixelRatioF(), frameHeight * img.devicePixelRatioF()));
y += frameHeight;
curX += copied;
x = 0;
- if (curX == img.width()){
+ if (curX == imgWidth){
curX = 0;
curY += frameHeight;
}
}else{//finish a row in img (src)
- int copied = img.width() - curX;
+ int copied = imgWidth - curX;
framesLeft -= copied/frameWidth;
- p.drawImage(x,y,img.copy(curX,curY,copied,frameHeight));
+ p.drawImage(QRect(x, y, copied, frameHeight),
+ img,
+ QRect(curX * img.devicePixelRatioF(), curY * img.devicePixelRatioF(), copied * img.devicePixelRatioF(), frameHeight * img.devicePixelRatioF()));
curY += frameHeight;
x += copied;
curX = 0;
@@ -484,12 +502,6 @@ QImage QQuickSpriteEngine::assembledImage(int maxSize)
}
}
- if (image.height() > maxSize){
- qWarning() << "SpriteEngine: Too many animations to fit in one texture...";
- qWarning() << "SpriteEngine: Your texture max size today is " << maxSize;
- return QImage();
- }
-
#ifdef SPRITE_IMAGE_DEBUG
QString fPath = QDir::tempPath() + "/SpriteImage.%1.png";
int acc = 0;
diff --git a/src/quick/items/qquickspritesequence.cpp b/src/quick/items/qquickspritesequence.cpp
index 72761ab82b..df6a6e336e 100644
--- a/src/quick/items/qquickspritesequence.cpp
+++ b/src/quick/items/qquickspritesequence.cpp
@@ -226,7 +226,7 @@ QSGSpriteNode *QQuickSpriteSequence::initNode()
QSGSpriteNode *node = d->sceneGraphContext()->createSpriteNode();
- d->m_sheetSize = QSize(image.size());
+ d->m_sheetSize = QSize(image.size() / image.devicePixelRatioF());
node->setTexture(window()->createTextureFromImage(image));
d->m_spriteEngine->start(0);
node->setTime(0.0f);
diff --git a/src/quick/items/qquicktextcontrol.cpp b/src/quick/items/qquicktextcontrol.cpp
index e3080dfe48..1cb12235c1 100644
--- a/src/quick/items/qquicktextcontrol.cpp
+++ b/src/quick/items/qquicktextcontrol.cpp
@@ -1304,8 +1304,12 @@ void QQuickTextControlPrivate::inputMethodEvent(QInputMethodEvent *e)
cursor.removeSelectedText();
}
+ QTextBlock block;
+
// insert commit string
if (!e->commitString().isEmpty() || e->replacementLength()) {
+ if (e->commitString().endsWith(QChar::LineFeed))
+ block = cursor.block(); // Remember the block where the preedit text is
QTextCursor c = cursor;
c.setPosition(c.position() + e->replacementStart());
c.setPosition(c.position() + e->replacementLength(), QTextCursor::KeepAnchor);
@@ -1324,7 +1328,9 @@ void QQuickTextControlPrivate::inputMethodEvent(QInputMethodEvent *e)
}
}
- QTextBlock block = cursor.block();
+ if (!block.isValid())
+ block = cursor.block();
+
QTextLayout *layout = block.layout();
if (isGettingInput) {
layout->setPreeditArea(cursor.position() - block.position(), e->preeditString());
diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp
index 02fe4809ab..fb81a835e9 100644
--- a/src/quick/items/qquickwindow.cpp
+++ b/src/quick/items/qquickwindow.cpp
@@ -2227,8 +2227,10 @@ QQuickPointerEvent *QQuickWindowPrivate::queryPointerEventInstance(QQuickPointer
for (QQuickPointerEvent *e : pointerEventInstances) {
// If device can generate native gestures (e.g. a trackpad), there might be two QQuickPointerEvents:
// QQuickPointerNativeGestureEvent and QQuickPointerTouchEvent. Use eventType to disambiguate.
+#if QT_CONFIG(gestures)
if (eventType == QEvent::NativeGesture && !qobject_cast<QQuickPointerNativeGestureEvent*>(e))
continue;
+#endif
// Otherwise we assume there's only one event type per device.
// More disambiguation tests might need to be added above if that changes later.
if (e->device() == device)
@@ -2252,9 +2254,11 @@ QQuickPointerEvent *QQuickWindowPrivate::pointerEventInstance(QQuickPointerDevic
break;
case QQuickPointerDevice::TouchPad:
case QQuickPointerDevice::TouchScreen:
+#if QT_CONFIG(gestures)
if (eventType == QEvent::NativeGesture)
ev = new QQuickPointerNativeGestureEvent(q, device);
else // assume QEvent::Type is one of TouchBegin/Update/End
+#endif
ev = new QQuickPointerTouchEvent(q, device);
break;
default:
@@ -2289,9 +2293,11 @@ QQuickPointerEvent *QQuickWindowPrivate::pointerEventInstance(QEvent *event) con
dev = QQuickPointerDevice::touchDevice(static_cast<QTouchEvent *>(event)->device());
break;
// TODO tablet event types
+#if QT_CONFIG(gestures)
case QEvent::NativeGesture:
dev = QQuickPointerDevice::touchDevice(static_cast<QNativeGestureEvent *>(event)->device());
break;
+#endif
default:
break;
}
@@ -2313,8 +2319,9 @@ void QQuickWindowPrivate::deliverPointerEvent(QQuickPointerEvent *event)
deliverMouseEvent(event->asPointerMouseEvent());
// failsafe: never allow any kind of grab to persist after release
if (event->isReleaseEvent() && event->buttons() == Qt::NoButton) {
+ QQuickItem *oldGrabber = q->mouseGrabberItem();
event->clearGrabbers();
- sendUngrabEvent(q->mouseGrabberItem(), false);
+ sendUngrabEvent(oldGrabber, false);
}
} else if (event->asPointerTouchEvent()) {
deliverTouchEvent(event->asPointerTouchEvent());
diff --git a/src/quick/scenegraph/adaptations/software/qsgsoftwareinternalimagenode.cpp b/src/quick/scenegraph/adaptations/software/qsgsoftwareinternalimagenode.cpp
index aa83709b72..74426c5c4d 100644
--- a/src/quick/scenegraph/adaptations/software/qsgsoftwareinternalimagenode.cpp
+++ b/src/quick/scenegraph/adaptations/software/qsgsoftwareinternalimagenode.cpp
@@ -68,6 +68,9 @@ void qDrawBorderPixmap(QPainter *painter, const QRect &targetRect, const QMargin
QMargins sourceMargins = normalizedMargins(sourceMarginsIn);
QMargins targetMargins = normalizedMargins(targetMarginsIn);
+ const qreal sourceDpr = pixmap.devicePixelRatioF();
+ sourceMargins *= sourceDpr;
+
// source center
const int sourceCenterTop = sourceRect.top() + sourceMargins.top();
const int sourceCenterLeft = sourceRect.left() + sourceMargins.left();
@@ -89,9 +92,9 @@ void qDrawBorderPixmap(QPainter *painter, const QRect &targetRect, const QMargin
int columns = 3;
int rows = 3;
if (rules.horizontal != Qt::StretchTile && sourceCenterWidth != 0)
- columns = qMax(3, 2 + qCeil(targetCenterWidth / qreal(sourceCenterWidth)));
+ columns = qMax(3, 2 + qCeil((targetCenterWidth * sourceDpr) / qreal(sourceCenterWidth)));
if (rules.vertical != Qt::StretchTile && sourceCenterHeight != 0)
- rows = qMax(3, 2 + qCeil(targetCenterHeight / qreal(sourceCenterHeight)));
+ rows = qMax(3, 2 + qCeil((targetCenterHeight * sourceDpr) / qreal(sourceCenterHeight)));
xTarget.resize(columns + 1);
yTarget.resize(rows + 1);
@@ -121,7 +124,7 @@ void qDrawBorderPixmap(QPainter *painter, const QRect &targetRect, const QMargin
dx = targetCenterWidth;
break;
case Qt::RepeatTile:
- dx = sourceCenterWidth;
+ dx = sourceCenterWidth / sourceDpr;
break;
case Qt::RoundTile:
dx = targetCenterWidth / qreal(columns - 2);
@@ -136,7 +139,7 @@ void qDrawBorderPixmap(QPainter *painter, const QRect &targetRect, const QMargin
dy = targetCenterHeight;
break;
case Qt::RepeatTile:
- dy = sourceCenterHeight;
+ dy = sourceCenterHeight / sourceDpr;
break;
case Qt::RoundTile:
dy = targetCenterHeight / qreal(rows - 2);
diff --git a/src/quick/scenegraph/adaptations/software/qsgsoftwarespritenode.cpp b/src/quick/scenegraph/adaptations/software/qsgsoftwarespritenode.cpp
index ba7bbc2d11..d4e5e98d68 100644
--- a/src/quick/scenegraph/adaptations/software/qsgsoftwarespritenode.cpp
+++ b/src/quick/scenegraph/adaptations/software/qsgsoftwarespritenode.cpp
@@ -123,7 +123,7 @@ void QSGSoftwareSpriteNode::paint(QPainter *painter)
// XXX try to do some kind of interpolation between sourceA and sourceB using time
painter->drawPixmap(QRectF(0, 0, m_size.width(), m_size.height()),
pixmap,
- QRectF(m_sourceA, m_spriteSize));
+ QRectF(m_sourceA * pixmap.devicePixelRatioF(), m_spriteSize * pixmap.devicePixelRatioF()));
}
bool QSGSoftwareSpriteNode::isOpaque() const
diff --git a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp
index ba71551302..afe3380494 100644
--- a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp
+++ b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp
@@ -775,9 +775,7 @@ Renderer::Renderer(QSGDefaultRenderContext *ctx)
, m_currentClip(nullptr)
, m_currentClipType(NoClip)
, m_vertexUploadPool(256)
-#ifdef QSG_SEPARATE_INDEX_BUFFER
, m_indexUploadPool(64)
-#endif
, m_vao(nullptr)
, m_visualizeMode(VisualizeNothing)
{
@@ -834,12 +832,11 @@ static void qsg_wipeBuffer(Buffer *buffer, QOpenGLFunctions *funcs)
free(buffer->data);
}
-static void qsg_wipeBatch(Batch *batch, QOpenGLFunctions *funcs)
+static void qsg_wipeBatch(Batch *batch, QOpenGLFunctions *funcs, bool separateIndexBuffer)
{
qsg_wipeBuffer(&batch->vbo, funcs);
-#ifdef QSG_SEPARATE_INDEX_BUFFER
- qsg_wipeBuffer(&batch->ibo, funcs);
-#endif
+ if (separateIndexBuffer)
+ qsg_wipeBuffer(&batch->ibo, funcs);
delete batch;
}
@@ -847,9 +844,13 @@ Renderer::~Renderer()
{
if (QOpenGLContext::currentContext()) {
// Clean up batches and buffers
- for (int i=0; i<m_opaqueBatches.size(); ++i) qsg_wipeBatch(m_opaqueBatches.at(i), this);
- for (int i=0; i<m_alphaBatches.size(); ++i) qsg_wipeBatch(m_alphaBatches.at(i), this);
- for (int i=0; i<m_batchPool.size(); ++i) qsg_wipeBatch(m_batchPool.at(i), this);
+ const bool separateIndexBuffer = m_context->separateIndexBuffer();
+ for (int i = 0; i < m_opaqueBatches.size(); ++i)
+ qsg_wipeBatch(m_opaqueBatches.at(i), this, separateIndexBuffer);
+ for (int i = 0; i < m_alphaBatches.size(); ++i)
+ qsg_wipeBatch(m_alphaBatches.at(i), this, separateIndexBuffer);
+ for (int i = 0; i < m_batchPool.size(); ++i)
+ qsg_wipeBatch(m_batchPool.at(i), this, separateIndexBuffer);
}
for (Node *n : qAsConst(m_nodes))
@@ -889,13 +890,8 @@ void Renderer::map(Buffer *buffer, int byteSize, bool isIndexBuf)
if (!m_context->hasBrokenIndexBufferObjects() && m_visualizeMode == VisualizeNothing) {
// Common case, use a shared memory pool for uploading vertex data to avoid
// excessive reevaluation
- QDataBuffer<char> &pool =
-#ifdef QSG_SEPARATE_INDEX_BUFFER
- isIndexBuf ? m_indexUploadPool : m_vertexUploadPool;
-#else
- m_vertexUploadPool;
- Q_UNUSED(isIndexBuf);
-#endif
+ QDataBuffer<char> &pool = m_context->separateIndexBuffer() && isIndexBuf
+ ? m_indexUploadPool : m_vertexUploadPool;
if (byteSize > pool.size())
pool.resize(byteSize);
buffer->data = pool.data();
@@ -1864,11 +1860,11 @@ void Renderer::uploadBatch(Batch *b)
ibufferSize = unmergedIndexSize;
}
-#ifdef QSG_SEPARATE_INDEX_BUFFER
- map(&b->ibo, ibufferSize, true);
-#else
- bufferSize += ibufferSize;
-#endif
+ const bool separateIndexBuffer = m_context->separateIndexBuffer();
+ if (separateIndexBuffer)
+ map(&b->ibo, ibufferSize, true);
+ else
+ bufferSize += ibufferSize;
map(&b->vbo, bufferSize);
if (Q_UNLIKELY(debug_upload())) qDebug() << " - batch" << b << " first:" << b->first << " root:"
@@ -1878,22 +1874,17 @@ void Renderer::uploadBatch(Batch *b)
if (b->merged) {
char *vertexData = b->vbo.data;
char *zData = vertexData + b->vertexCount * g->sizeOfVertex();
-#ifdef QSG_SEPARATE_INDEX_BUFFER
- char *indexData = b->ibo.data;
-#else
- char *indexData = zData + (m_useDepthBuffer ? b->vertexCount * sizeof(float) : 0);
-#endif
+ char *indexData = separateIndexBuffer
+ ? b->ibo.data
+ : zData + (int(m_useDepthBuffer) * b->vertexCount * sizeof(float));
quint16 iOffset = 0;
e = b->first;
int verticesInSet = 0;
int indicesInSet = 0;
b->drawSets.reset();
-#ifdef QSG_SEPARATE_INDEX_BUFFER
- int drawSetIndices = 0;
-#else
- int drawSetIndices = indexData - vertexData;
-#endif
+ int drawSetIndices = separateIndexBuffer ? 0 : indexData - vertexData;
+ const auto indexBase = separateIndexBuffer ? b->ibo.data : b->vbo.data;
b->drawSets << DrawSet(0, zData - vertexData, drawSetIndices);
while (e) {
verticesInSet += e->node->geometry()->vertexCount();
@@ -1903,11 +1894,7 @@ void Renderer::uploadBatch(Batch *b)
b->drawSets.last().indices += 1 * sizeof(quint16);
b->drawSets.last().indexCount -= 2;
}
-#ifdef QSG_SEPARATE_INDEX_BUFFER
- drawSetIndices = indexData - b->ibo.data;
-#else
- drawSetIndices = indexData - b->vbo.data;
-#endif
+ drawSetIndices = indexData - indexBase;
b->drawSets << DrawSet(vertexData - b->vbo.data,
zData - b->vbo.data,
drawSetIndices);
@@ -1927,11 +1914,8 @@ void Renderer::uploadBatch(Batch *b)
}
} else {
char *vboData = b->vbo.data;
-#ifdef QSG_SEPARATE_INDEX_BUFFER
- char *iboData = b->ibo.data;
-#else
- char *iboData = vboData + b->vertexCount * g->sizeOfVertex();
-#endif
+ char *iboData = separateIndexBuffer ? b->ibo.data
+ : vboData + b->vertexCount * g->sizeOfVertex();
Element *e = b->first;
while (e) {
QSGGeometry *g = e->node->geometry();
@@ -1979,12 +1963,9 @@ void Renderer::uploadBatch(Batch *b)
}
if (!b->drawSets.isEmpty()) {
- const quint16 *id =
-# ifdef QSG_SEPARATE_INDEX_BUFFER
- (const quint16 *) (b->ibo.data);
-# else
- (const quint16 *) (b->vbo.data + b->drawSets.at(0).indices);
-# endif
+ const quint16 *id = (const quint16 *)(separateIndexBuffer
+ ? b->ibo.data
+ : b->vbo.data + b->drawSets.at(0).indices);
{
QDebug iDump = qDebug();
iDump << " -- Index Data, count:" << b->indexCount;
@@ -2004,9 +1985,8 @@ void Renderer::uploadBatch(Batch *b)
#endif // QT_NO_DEBUG_OUTPUT
unmap(&b->vbo);
-#ifdef QSG_SEPARATE_INDEX_BUFFER
- unmap(&b->ibo, true);
-#endif
+ if (separateIndexBuffer)
+ unmap(&b->ibo, true);
if (Q_UNLIKELY(debug_upload())) qDebug() << " --- vertex/index buffers unmapped, batch upload completed...";
@@ -2299,11 +2279,7 @@ void Renderer::renderMergedBatch(const Batch *batch)
glBindBuffer(GL_ARRAY_BUFFER, batch->vbo.id);
char *indexBase = nullptr;
-#ifdef QSG_SEPARATE_INDEX_BUFFER
- const Buffer *indexBuf = &batch->ibo;
-#else
- const Buffer *indexBuf = &batch->vbo;
-#endif
+ const Buffer *indexBuf = m_context->separateIndexBuffer() ? &batch->ibo : &batch->vbo;
if (m_context->hasBrokenIndexBufferObjects()) {
indexBase = indexBuf->data;
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
@@ -2395,11 +2371,8 @@ void Renderer::renderUnmergedBatch(const Batch *batch)
glBindBuffer(GL_ARRAY_BUFFER, batch->vbo.id);
char *indexBase = nullptr;
-#ifdef QSG_SEPARATE_INDEX_BUFFER
- const Buffer *indexBuf = &batch->ibo;
-#else
- const Buffer *indexBuf = &batch->vbo;
-#endif
+ const auto separateIndexBuffer = m_context->separateIndexBuffer();
+ const Buffer *indexBuf = separateIndexBuffer ? &batch->ibo : &batch->vbo;
if (batch->indexCount) {
if (m_context->hasBrokenIndexBufferObjects()) {
indexBase = indexBuf->data;
@@ -2428,11 +2401,9 @@ void Renderer::renderUnmergedBatch(const Batch *batch)
}
int vOffset = 0;
-#ifdef QSG_SEPARATE_INDEX_BUFFER
char *iOffset = indexBase;
-#else
- char *iOffset = indexBase + batch->vertexCount * gn->geometry()->sizeOfVertex();
-#endif
+ if (!separateIndexBuffer)
+ iOffset += batch->vertexCount * gn->geometry()->sizeOfVertex();
QMatrix4x4 rootMatrix = batch->root ? qsg_matrixForRoot(batch->root) : QMatrix4x4();
@@ -2735,17 +2706,13 @@ void Renderer::render()
if (Q_UNLIKELY(debug_render())) timeSorting = timer.restart();
int largestVBO = 0;
-#ifdef QSG_SEPARATE_INDEX_BUFFER
int largestIBO = 0;
-#endif
if (Q_UNLIKELY(debug_upload())) qDebug("Uploading Opaque Batches:");
for (int i=0; i<m_opaqueBatches.size(); ++i) {
Batch *b = m_opaqueBatches.at(i);
largestVBO = qMax(b->vbo.size, largestVBO);
-#ifdef QSG_SEPARATE_INDEX_BUFFER
largestIBO = qMax(b->ibo.size, largestIBO);
-#endif
uploadBatch(b);
}
if (Q_UNLIKELY(debug_render())) timeUploadOpaque = timer.restart();
@@ -2756,18 +2723,14 @@ void Renderer::render()
Batch *b = m_alphaBatches.at(i);
uploadBatch(b);
largestVBO = qMax(b->vbo.size, largestVBO);
-#ifdef QSG_SEPARATE_INDEX_BUFFER
largestIBO = qMax(b->ibo.size, largestIBO);
-#endif
}
if (Q_UNLIKELY(debug_render())) timeUploadAlpha = timer.restart();
if (largestVBO * 2 < m_vertexUploadPool.size())
m_vertexUploadPool.resize(largestVBO * 2);
-#ifdef QSG_SEPARATE_INDEX_BUFFER
- if (largestIBO * 2 < m_indexUploadPool.size())
+ if (m_context->separateIndexBuffer() && largestIBO * 2 < m_indexUploadPool.size())
m_indexUploadPool.resize(largestIBO * 2);
-#endif
renderBatches();
@@ -2978,14 +2941,12 @@ void Renderer::visualizeBatch(Batch *b)
if (b->merged) {
shader->setUniformValue(shader->matrix, matrix);
+ const auto &dataStart = m_context->separateIndexBuffer() ? b->ibo.data : b->vbo.data;
for (int ds=0; ds<b->drawSets.size(); ++ds) {
const DrawSet &set = b->drawSets.at(ds);
glVertexAttribPointer(a.position, 2, a.type, false, g->sizeOfVertex(), (void *) (qintptr) (set.vertices));
-#ifdef QSG_SEPARATE_INDEX_BUFFER
- glDrawElements(g->drawingMode(), set.indexCount, GL_UNSIGNED_SHORT, (void *) (qintptr) (b->ibo.data + set.indices));
-#else
- glDrawElements(g->drawingMode(), set.indexCount, GL_UNSIGNED_SHORT, (void *) (qintptr) (b->vbo.data + set.indices));
-#endif
+ glDrawElements(g->drawingMode(), set.indexCount, GL_UNSIGNED_SHORT,
+ (void *)(qintptr)(dataStart + set.indices));
}
} else {
Element *e = b->first;
diff --git a/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h b/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h
index 918f3ce82c..12b48c1451 100644
--- a/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h
+++ b/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h
@@ -433,9 +433,7 @@ struct Batch
mutable uint uploadedThisFrame : 1; // solely for debugging purposes
Buffer vbo;
-#ifdef QSG_SEPARATE_INDEX_BUFFER
Buffer ibo;
-#endif
QDataBuffer<DrawSet> drawSets;
};
@@ -738,9 +736,7 @@ private:
ClipType m_currentClipType;
QDataBuffer<char> m_vertexUploadPool;
-#ifdef QSG_SEPARATE_INDEX_BUFFER
QDataBuffer<char> m_indexUploadPool;
-#endif
// For minimal OpenGL core profile support
QOpenGLVertexArrayObject *m_vao;
@@ -760,10 +756,8 @@ Batch *Renderer::newBatch()
m_batchPool.resize(size - 1);
} else {
b = new Batch();
- memset(&b->vbo, 0, sizeof(Buffer));
-#ifdef QSG_SEPARATE_INDEX_BUFFER
- memset(&b->ibo, 0, sizeof(Buffer));
-#endif
+ Q_ASSERT(offsetof(Batch, ibo) == sizeof(Buffer) + offsetof(Batch, vbo));
+ memset(&b->vbo, 0, sizeof(Buffer) * 2); // Clear VBO & IBO
}
b->init();
return b;
diff --git a/src/quick/scenegraph/qsgdefaultrendercontext.cpp b/src/quick/scenegraph/qsgdefaultrendercontext.cpp
index 7882496062..22e97a2dc9 100644
--- a/src/quick/scenegraph/qsgdefaultrendercontext.cpp
+++ b/src/quick/scenegraph/qsgdefaultrendercontext.cpp
@@ -39,6 +39,7 @@
#include "qsgdefaultrendercontext_p.h"
+#include <QtGui/QGuiApplication>
#include <QtGui/QOpenGLFramebufferObject>
#include <QtQuick/private/qsgbatchrenderer_p.h>
@@ -317,6 +318,17 @@ QSGDefaultRenderContext *QSGDefaultRenderContext::from(QOpenGLContext *context)
return qobject_cast<QSGDefaultRenderContext *>(context->property(QSG_RENDERCONTEXT_PROPERTY).value<QObject *>());
}
+bool QSGDefaultRenderContext::separateIndexBuffer() const
+{
+ // WebGL: A given WebGLBuffer object may only be bound to one of
+ // the ARRAY_BUFFER or ELEMENT_ARRAY_BUFFER target in its
+ // lifetime. An attempt to bind a buffer object to the other
+ // target will generate an INVALID_OPERATION error, and the
+ // current binding will remain untouched.
+ static const bool isWebGL = qGuiApp->platformName().compare(QLatin1String("webgl")) == 0;
+ return isWebGL;
+}
+
QSGDistanceFieldGlyphCache *QSGDefaultRenderContext::distanceFieldGlyphCache(const QRawFont &font)
{
QString key = fontKey(font);
diff --git a/src/quick/scenegraph/qsgdefaultrendercontext_p.h b/src/quick/scenegraph/qsgdefaultrendercontext_p.h
index eb62586a94..57aa4b4c90 100644
--- a/src/quick/scenegraph/qsgdefaultrendercontext_p.h
+++ b/src/quick/scenegraph/qsgdefaultrendercontext_p.h
@@ -95,6 +95,7 @@ public:
bool hasBrokenIndexBufferObjects() const { return m_brokenIBOs; }
int maxTextureSize() const override { return m_maxTextureSize; }
+ bool separateIndexBuffer() const;
protected:
static QString fontKey(const QRawFont &font);
@@ -106,8 +107,6 @@ protected:
bool m_serializedRender;
bool m_attachToGLContext;
QSGAtlasTexture::Manager *m_atlasManager;
-
-
};
QT_END_NAMESPACE
diff --git a/src/quick/scenegraph/scenegraph.pri b/src/quick/scenegraph/scenegraph.pri
index ac70c3153f..a9a71b1324 100644
--- a/src/quick/scenegraph/scenegraph.pri
+++ b/src/quick/scenegraph/scenegraph.pri
@@ -1,4 +1,3 @@
-# DEFINES += QSG_SEPARATE_INDEX_BUFFER
# DEFINES += QSG_DISTANCEFIELD_CACHE_DEBUG
emscripten: DEFINES += QSG_SEPARATE_INDEX_BUFFER