aboutsummaryrefslogtreecommitdiffstats
path: root/src/imports/shapes
diff options
context:
space:
mode:
Diffstat (limited to 'src/imports/shapes')
-rw-r--r--src/imports/shapes/qquickshape.cpp134
-rw-r--r--src/imports/shapes/qquickshape_p_p.h103
-rw-r--r--src/imports/shapes/qquickshapegenericrenderer.cpp7
-rw-r--r--src/imports/shapes/qquickshapegenericrenderer_p.h1
-rw-r--r--src/imports/shapes/qquickshapenvprrenderer.cpp84
-rw-r--r--src/imports/shapes/qquickshapenvprrenderer_p.h2
-rw-r--r--src/imports/shapes/qquickshapesoftwarerenderer.cpp8
-rw-r--r--src/imports/shapes/qquickshapesoftwarerenderer_p.h1
8 files changed, 49 insertions, 291 deletions
diff --git a/src/imports/shapes/qquickshape.cpp b/src/imports/shapes/qquickshape.cpp
index 3d90ca0c1f..b8a138507a 100644
--- a/src/imports/shapes/qquickshape.cpp
+++ b/src/imports/shapes/qquickshape.cpp
@@ -77,50 +77,6 @@ QQuickShapeStrokeFillParams::QQuickShapeStrokeFillParams()
dashPattern << 4 << 2; // 4 * strokeWidth dash followed by 2 * strokeWidth space
}
-QPainterPath QQuickShapePathCommands::toPainterPath() const
-{
- QPainterPath p;
- int coordIdx = 0;
- for (int i = 0; i < cmd.count(); ++i) {
- switch (cmd[i]) {
- case QQuickShapePathCommands::MoveTo:
- p.moveTo(coords[coordIdx], coords[coordIdx + 1]);
- coordIdx += 2;
- break;
- case QQuickShapePathCommands::LineTo:
- p.lineTo(coords[coordIdx], coords[coordIdx + 1]);
- coordIdx += 2;
- break;
- case QQuickShapePathCommands::QuadTo:
- p.quadTo(coords[coordIdx], coords[coordIdx + 1],
- coords[coordIdx + 2], coords[coordIdx + 3]);
- coordIdx += 4;
- break;
- case QQuickShapePathCommands::CubicTo:
- p.cubicTo(coords[coordIdx], coords[coordIdx + 1],
- coords[coordIdx + 2], coords[coordIdx + 3],
- coords[coordIdx + 4], coords[coordIdx + 5]);
- coordIdx += 6;
- break;
- case QQuickShapePathCommands::ArcTo:
- // does not map to the QPainterPath API; reuse the helper code from QQuickSvgParser
- QQuickSvgParser::pathArc(p,
- coords[coordIdx], coords[coordIdx + 1], // radius
- coords[coordIdx + 2], // xAxisRotation
- !qFuzzyIsNull(coords[coordIdx + 6]), // useLargeArc
- !qFuzzyIsNull(coords[coordIdx + 5]), // sweep flag
- coords[coordIdx + 3], coords[coordIdx + 4], // end
- p.currentPosition().x(), p.currentPosition().y());
- coordIdx += 7;
- break;
- default:
- qWarning("Unknown JS path command: %d", cmd[i]);
- break;
- }
- }
- return p;
-}
-
/*!
\qmltype ShapePath
\instantiates QQuickShapePath
@@ -815,7 +771,7 @@ static void vpe_append(QQmlListProperty<QObject> *property, QObject *obj)
QQuickShapePrivate *d = QQuickShapePrivate::get(item);
QQuickShapePath *path = qobject_cast<QQuickShapePath *>(obj);
if (path)
- d->qmlData.sp.append(path);
+ d->sp.append(path);
QQuickItemPrivate::data_append(property, obj);
@@ -830,10 +786,10 @@ static void vpe_clear(QQmlListProperty<QObject> *property)
QQuickShape *item = static_cast<QQuickShape *>(property->object);
QQuickShapePrivate *d = QQuickShapePrivate::get(item);
- for (QQuickShapePath *p : d->qmlData.sp)
+ for (QQuickShapePath *p : d->sp)
QObject::disconnect(p, SIGNAL(shapePathChanged()), item, SLOT(_q_shapePathChanged()));
- d->qmlData.sp.clear();
+ d->sp.clear();
QQuickItemPrivate::data_clear(property);
@@ -872,7 +828,7 @@ void QQuickShape::componentComplete()
QQuickItem::componentComplete();
- for (QQuickShapePath *p : d->qmlData.sp)
+ for (QQuickShapePath *p : d->sp)
connect(p, SIGNAL(shapePathChanged()), this, SLOT(_q_shapePathChanged()));
d->_q_shapePathChanged();
@@ -1010,65 +966,37 @@ void QQuickShapePrivate::sync()
renderer->setAsyncCallback(q_asyncShapeReady, this);
}
- if (!jsData.isValid()) {
- // Standard route: The path and stroke/fill parameters are provided via
- // QML elements.
- const int count = qmlData.sp.count();
- renderer->beginSync(count);
-
- for (int i = 0; i < count; ++i) {
- QQuickShapePath *p = qmlData.sp[i];
- int &dirty(QQuickShapePathPrivate::get(p)->dirty);
-
- if (dirty & QQuickShapePathPrivate::DirtyPath)
- renderer->setPath(i, p);
- if (dirty & QQuickShapePathPrivate::DirtyStrokeColor)
- renderer->setStrokeColor(i, p->strokeColor());
- if (dirty & QQuickShapePathPrivate::DirtyStrokeWidth)
- renderer->setStrokeWidth(i, p->strokeWidth());
- if (dirty & QQuickShapePathPrivate::DirtyFillColor)
- renderer->setFillColor(i, p->fillColor());
- if (dirty & QQuickShapePathPrivate::DirtyFillRule)
- renderer->setFillRule(i, p->fillRule());
- if (dirty & QQuickShapePathPrivate::DirtyStyle) {
- renderer->setJoinStyle(i, p->joinStyle(), p->miterLimit());
- renderer->setCapStyle(i, p->capStyle());
- }
- if (dirty & QQuickShapePathPrivate::DirtyDash)
- renderer->setStrokeStyle(i, p->strokeStyle(), p->dashOffset(), p->dashPattern());
- if (dirty & QQuickShapePathPrivate::DirtyFillGradient)
- renderer->setFillGradient(i, p->fillGradient());
-
- dirty = 0;
- }
-
- renderer->endSync(useAsync);
- } else {
-
- // ### there is no public API to reach this code path atm
- Q_UNREACHABLE();
-
- // Path and stroke/fill params provided from JavaScript. This avoids
- // QObjects at the expense of not supporting changes afterwards.
- const int count = jsData.paths.count();
- renderer->beginSync(count);
-
- for (int i = 0; i < count; ++i) {
- renderer->setJSPath(i, jsData.paths[i]);
- const QQuickShapeStrokeFillParams sfp(jsData.sfp[i]);
- renderer->setStrokeColor(i, sfp.strokeColor);
- renderer->setStrokeWidth(i, sfp.strokeWidth);
- renderer->setFillColor(i, sfp.fillColor);
- renderer->setFillRule(i, sfp.fillRule);
- renderer->setJoinStyle(i, sfp.joinStyle, sfp.miterLimit);
- renderer->setCapStyle(i, sfp.capStyle);
- renderer->setStrokeStyle(i, sfp.strokeStyle, sfp.dashOffset, sfp.dashPattern);
- renderer->setFillGradient(i, sfp.fillGradient);
+ const int count = sp.count();
+ renderer->beginSync(count);
+
+ for (int i = 0; i < count; ++i) {
+ QQuickShapePath *p = sp[i];
+ int &dirty(QQuickShapePathPrivate::get(p)->dirty);
+
+ if (dirty & QQuickShapePathPrivate::DirtyPath)
+ renderer->setPath(i, p);
+ if (dirty & QQuickShapePathPrivate::DirtyStrokeColor)
+ renderer->setStrokeColor(i, p->strokeColor());
+ if (dirty & QQuickShapePathPrivate::DirtyStrokeWidth)
+ renderer->setStrokeWidth(i, p->strokeWidth());
+ if (dirty & QQuickShapePathPrivate::DirtyFillColor)
+ renderer->setFillColor(i, p->fillColor());
+ if (dirty & QQuickShapePathPrivate::DirtyFillRule)
+ renderer->setFillRule(i, p->fillRule());
+ if (dirty & QQuickShapePathPrivate::DirtyStyle) {
+ renderer->setJoinStyle(i, p->joinStyle(), p->miterLimit());
+ renderer->setCapStyle(i, p->capStyle());
}
+ if (dirty & QQuickShapePathPrivate::DirtyDash)
+ renderer->setStrokeStyle(i, p->strokeStyle(), p->dashOffset(), p->dashPattern());
+ if (dirty & QQuickShapePathPrivate::DirtyFillGradient)
+ renderer->setFillGradient(i, p->fillGradient());
- renderer->endSync(useAsync);
+ dirty = 0;
}
+ renderer->endSync(useAsync);
+
if (!useAsync)
setStatus(QQuickShape::Ready);
}
diff --git a/src/imports/shapes/qquickshape_p_p.h b/src/imports/shapes/qquickshape_p_p.h
index dc62994af2..6ca752de56 100644
--- a/src/imports/shapes/qquickshape_p_p.h
+++ b/src/imports/shapes/qquickshape_p_p.h
@@ -62,39 +62,6 @@ QT_BEGIN_NAMESPACE
class QSGPlainTexture;
-struct QQuickShapePathCommands
-{
- enum Command {
- MoveTo,
- LineTo,
- QuadTo,
- CubicTo,
- ArcTo
- };
-
- QVector<Command> cmd;
- QVector<float> coords;
-
- QPainterPath toPainterPath() const;
-};
-
-struct QQuickShapeStrokeFillParams
-{
- QQuickShapeStrokeFillParams();
-
- QColor strokeColor;
- qreal strokeWidth;
- QColor fillColor;
- QQuickShapePath::FillRule fillRule;
- QQuickShapePath::JoinStyle joinStyle;
- int miterLimit;
- QQuickShapePath::CapStyle capStyle;
- QQuickShapePath::StrokeStyle strokeStyle;
- qreal dashOffset;
- QVector<qreal> dashPattern;
- QQuickShapeGradient *fillGradient;
-};
-
class QQuickAbstractPathRenderer
{
public:
@@ -110,11 +77,7 @@ public:
virtual void endSync(bool async) = 0;
virtual void setAsyncCallback(void (*)(void *), void *) { }
virtual Flags flags() const { return 0; }
- // - QML API
virtual void setPath(int index, const QQuickPath *path) = 0;
- // - JS API
- virtual void setJSPath(int index, const QQuickShapePathCommands &path) = 0;
- // - stroke/fill parameters
virtual void setStrokeColor(int index, const QColor &color) = 0;
virtual void setStrokeWidth(int index, qreal w) = 0;
virtual void setFillColor(int index, const QColor &color) = 0;
@@ -131,6 +94,23 @@ public:
Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickAbstractPathRenderer::Flags)
+struct QQuickShapeStrokeFillParams
+{
+ QQuickShapeStrokeFillParams();
+
+ QColor strokeColor;
+ qreal strokeWidth;
+ QColor fillColor;
+ QQuickShapePath::FillRule fillRule;
+ QQuickShapePath::JoinStyle joinStyle;
+ int miterLimit;
+ QQuickShapePath::CapStyle capStyle;
+ QQuickShapePath::StrokeStyle strokeStyle;
+ qreal dashOffset;
+ QVector<qreal> dashPattern;
+ QQuickShapeGradient *fillGradient;
+};
+
class QQuickShapePathPrivate : public QQuickPathPrivate
{
Q_DECLARE_PUBLIC(QQuickShapePath)
@@ -182,57 +162,10 @@ public:
bool async;
QQuickShape::Status status;
QQuickAbstractPathRenderer *renderer;
-
- struct {
- QVector<QQuickShapePath *> sp;
- } qmlData;
-
- struct {
- bool isValid() const { Q_ASSERT(paths.count() == sfp.count()); return !paths.isEmpty(); }
- QVector<QQuickShapePathCommands> paths;
- QVector<QQuickShapeStrokeFillParams> sfp;
- } jsData;
-
+ QVector<QQuickShapePath *> sp;
bool enableVendorExts;
};
-class QQuickShapePathObject : public QObject
-{
- Q_OBJECT
-
-public:
- QQuickShapePathObject(QObject *parent = nullptr) : QObject(parent) { }
-
- void setV4Engine(QV4::ExecutionEngine *engine);
- QV4::ReturnedValue v4value() const { return m_v4value.value(); }
-
- QQuickShapePath path;
-
- void clear();
-
-private:
- QV4::PersistentValue m_v4value;
-};
-
-class QQuickShapeStrokeFillParamsObject : public QObject
-{
- Q_OBJECT
-
-public:
- QQuickShapeStrokeFillParamsObject(QObject *parent = nullptr) : QObject(parent) { }
-
- void setV4Engine(QV4::ExecutionEngine *engine);
- QV4::ReturnedValue v4value() const { return m_v4value.value(); }
-
- QQuickShapeStrokeFillParams sfp;
- QV4::PersistentValue v4fillGradient;
-
- void clear();
-
-private:
- QV4::PersistentValue m_v4value;
-};
-
#if QT_CONFIG(opengl)
class QQuickShapeGradientCache : public QOpenGLSharedResource
diff --git a/src/imports/shapes/qquickshapegenericrenderer.cpp b/src/imports/shapes/qquickshapegenericrenderer.cpp
index 41bab83582..398106af3d 100644
--- a/src/imports/shapes/qquickshapegenericrenderer.cpp
+++ b/src/imports/shapes/qquickshapegenericrenderer.cpp
@@ -178,13 +178,6 @@ void QQuickShapeGenericRenderer::setPath(int index, const QQuickPath *path)
d.syncDirty |= DirtyFillGeom | DirtyStrokeGeom;
}
-void QQuickShapeGenericRenderer::setJSPath(int index, const QQuickShapePathCommands &path)
-{
- ShapePathData &d(m_sp[index]);
- d.path = path.toPainterPath();
- d.syncDirty |= DirtyFillGeom | DirtyStrokeGeom;
-}
-
void QQuickShapeGenericRenderer::setStrokeColor(int index, const QColor &color)
{
ShapePathData &d(m_sp[index]);
diff --git a/src/imports/shapes/qquickshapegenericrenderer_p.h b/src/imports/shapes/qquickshapegenericrenderer_p.h
index 1f36e3decf..dadeba3467 100644
--- a/src/imports/shapes/qquickshapegenericrenderer_p.h
+++ b/src/imports/shapes/qquickshapegenericrenderer_p.h
@@ -88,7 +88,6 @@ public:
void beginSync(int totalCount) override;
void setPath(int index, const QQuickPath *path) override;
- void setJSPath(int index, const QQuickShapePathCommands &path) override;
void setStrokeColor(int index, const QColor &color) override;
void setStrokeWidth(int index, qreal w) override;
void setFillColor(int index, const QColor &color) override;
diff --git a/src/imports/shapes/qquickshapenvprrenderer.cpp b/src/imports/shapes/qquickshapenvprrenderer.cpp
index 57306a4d53..4f49bb5256 100644
--- a/src/imports/shapes/qquickshapenvprrenderer.cpp
+++ b/src/imports/shapes/qquickshapenvprrenderer.cpp
@@ -62,14 +62,6 @@ void QQuickShapeNvprRenderer::setPath(int index, const QQuickPath *path)
m_accDirty |= DirtyPath;
}
-void QQuickShapeNvprRenderer::setJSPath(int index, const QQuickShapePathCommands &path)
-{
- ShapePathGuiData &d(m_sp[index]);
- convertJSPath(path, &d);
- d.dirty |= DirtyPath;
- m_accDirty |= DirtyPath;
-}
-
void QQuickShapeNvprRenderer::setStrokeColor(int index, const QColor &color)
{
ShapePathGuiData &d(m_sp[index]);
@@ -296,82 +288,6 @@ void QQuickShapeNvprRenderer::convertPath(const QQuickPath *path, ShapePathGuiDa
d->path.cmd.append(GL_CLOSE_PATH_NV);
}
-void QQuickShapeNvprRenderer::convertJSPath(const QQuickShapePathCommands &path, ShapePathGuiData *d)
-{
- d->path = NvprPath();
- if (path.cmd.isEmpty())
- return;
-
- QPointF startPos(0, 0);
- QPointF pos(startPos);
- int coordIdx = 0;
-
- for (QQuickShapePathCommands::Command cmd : path.cmd) {
- switch (cmd) {
- case QQuickShapePathCommands::MoveTo:
- d->path.cmd.append(GL_MOVE_TO_NV);
- pos = QPointF(path.coords[coordIdx], path.coords[coordIdx + 1]);
- startPos = pos;
- d->path.coord.append(pos.x());
- d->path.coord.append(pos.y());
- coordIdx += 2;
- break;
- case QQuickShapePathCommands::LineTo:
- d->path.cmd.append(GL_LINE_TO_NV);
- pos = QPointF(path.coords[coordIdx], path.coords[coordIdx + 1]);
- d->path.coord.append(pos.x());
- d->path.coord.append(pos.y());
- coordIdx += 2;
- break;
- case QQuickShapePathCommands::QuadTo:
- d->path.cmd.append(GL_QUADRATIC_CURVE_TO_NV);
- d->path.coord.append(path.coords[coordIdx]);
- d->path.coord.append(path.coords[coordIdx + 1]);
- pos = QPointF(path.coords[coordIdx + 2], path.coords[coordIdx + 3]);
- d->path.coord.append(pos.x());
- d->path.coord.append(pos.y());
- coordIdx += 4;
- break;
- case QQuickShapePathCommands::CubicTo:
- d->path.cmd.append(GL_CUBIC_CURVE_TO_NV);
- d->path.coord.append(path.coords[coordIdx]);
- d->path.coord.append(path.coords[coordIdx + 1]);
- d->path.coord.append(path.coords[coordIdx + 2]);
- d->path.coord.append(path.coords[coordIdx + 3]);
- pos = QPointF(path.coords[coordIdx + 4], path.coords[coordIdx + 5]);
- d->path.coord.append(pos.x());
- d->path.coord.append(pos.y());
- coordIdx += 6;
- break;
- case QQuickShapePathCommands::ArcTo:
- {
- const bool sweepFlag = !qFuzzyIsNull(path.coords[coordIdx + 5]);
- const bool useLargeArc = !qFuzzyIsNull(path.coords[coordIdx + 6]);
- GLenum cmd;
- if (useLargeArc)
- cmd = sweepFlag ? GL_LARGE_CCW_ARC_TO_NV : GL_LARGE_CW_ARC_TO_NV;
- else
- cmd = sweepFlag ? GL_SMALL_CCW_ARC_TO_NV : GL_SMALL_CW_ARC_TO_NV;
- d->path.cmd.append(cmd);
- d->path.coord.append(path.coords[coordIdx]); // rx
- d->path.coord.append(path.coords[coordIdx + 1]); // ry
- d->path.coord.append(path.coords[coordIdx + 2]); // xrot
- pos = QPointF(path.coords[coordIdx + 3], path.coords[coordIdx + 4]);
- d->path.coord.append(pos.x());
- d->path.coord.append(pos.y());
- coordIdx += 7;
- }
- break;
- default:
- qWarning("Unknown JS path command: %d", cmd);
- break;
- }
- }
-
- if (pos == startPos)
- d->path.cmd.append(GL_CLOSE_PATH_NV);
-}
-
static inline QVector4D qsg_premultiply(const QColor &c, float globalOpacity)
{
const float o = c.alphaF() * globalOpacity;
diff --git a/src/imports/shapes/qquickshapenvprrenderer_p.h b/src/imports/shapes/qquickshapenvprrenderer_p.h
index ec7ba498f9..7eb2924ab7 100644
--- a/src/imports/shapes/qquickshapenvprrenderer_p.h
+++ b/src/imports/shapes/qquickshapenvprrenderer_p.h
@@ -81,7 +81,6 @@ public:
void beginSync(int totalCount) override;
void setPath(int index, const QQuickPath *path) override;
- void setJSPath(int index, const QQuickShapePathCommands &path) override;
void setStrokeColor(int index, const QColor &color) override;
void setStrokeWidth(int index, qreal w) override;
void setFillColor(int index, const QColor &color) override;
@@ -122,7 +121,6 @@ private:
};
void convertPath(const QQuickPath *path, ShapePathGuiData *d);
- void convertJSPath(const QQuickShapePathCommands &path, ShapePathGuiData *d);
QQuickShapeNvprRenderNode *m_node = nullptr;
int m_accDirty = 0;
diff --git a/src/imports/shapes/qquickshapesoftwarerenderer.cpp b/src/imports/shapes/qquickshapesoftwarerenderer.cpp
index b3373106af..4e6e758697 100644
--- a/src/imports/shapes/qquickshapesoftwarerenderer.cpp
+++ b/src/imports/shapes/qquickshapesoftwarerenderer.cpp
@@ -58,14 +58,6 @@ void QQuickShapeSoftwareRenderer::setPath(int index, const QQuickPath *path)
m_accDirty |= DirtyPath;
}
-void QQuickShapeSoftwareRenderer::setJSPath(int index, const QQuickShapePathCommands &path)
-{
- ShapePathGuiData &d(m_sp[index]);
- d.path = path.toPainterPath();
- d.dirty |= DirtyPath;
- m_accDirty |= DirtyPath;
-}
-
void QQuickShapeSoftwareRenderer::setStrokeColor(int index, const QColor &color)
{
ShapePathGuiData &d(m_sp[index]);
diff --git a/src/imports/shapes/qquickshapesoftwarerenderer_p.h b/src/imports/shapes/qquickshapesoftwarerenderer_p.h
index 53982ce347..0abc2e37b0 100644
--- a/src/imports/shapes/qquickshapesoftwarerenderer_p.h
+++ b/src/imports/shapes/qquickshapesoftwarerenderer_p.h
@@ -73,7 +73,6 @@ public:
void beginSync(int totalCount) override;
void setPath(int index, const QQuickPath *path) override;
- void setJSPath(int index, const QQuickShapePathCommands &path) override;
void setStrokeColor(int index, const QColor &color) override;
void setStrokeWidth(int index, qreal w) override;
void setFillColor(int index, const QColor &color) override;