aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/context2d/qquickcanvasitem.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/quick/items/context2d/qquickcanvasitem.cpp')
-rw-r--r--src/quick/items/context2d/qquickcanvasitem.cpp38
1 files changed, 20 insertions, 18 deletions
diff --git a/src/quick/items/context2d/qquickcanvasitem.cpp b/src/quick/items/context2d/qquickcanvasitem.cpp
index e7546535a1..9c4cef1fe1 100644
--- a/src/quick/items/context2d/qquickcanvasitem.cpp
+++ b/src/quick/items/context2d/qquickcanvasitem.cpp
@@ -175,7 +175,6 @@ public:
uint hasTileSize :1;
uint hasCanvasWindow :1;
uint available :1;
- uint contextInitialized :1;
QQuickCanvasItem::RenderTarget renderTarget;
QQuickCanvasItem::RenderStrategy renderStrategy;
QString contextType;
@@ -193,7 +192,6 @@ QQuickCanvasItemPrivate::QQuickCanvasItemPrivate()
, hasTileSize(false)
, hasCanvasWindow(false)
, available(false)
- , contextInitialized(false)
, renderTarget(QQuickCanvasItem::Image)
, renderStrategy(QQuickCanvasItem::Cooperative)
{
@@ -272,7 +270,7 @@ QQuickCanvasItemPrivate::~QQuickCanvasItemPrivate()
requires the pixel data to be exchanged between the system memory and the
graphic card, which is significantly more expensive. Rendering may also be
synchronized with the V-sync signal (to avoid
- \l{en.wikipedia.org/wiki/Screen_tearing}{screen tearing}) which will further
+ \l{http://en.wikipedia.org/wiki/Screen_tearing}{screen tearing}) which will further
impact pixel operations with \c Canvas.FrambufferObject render target.
\section1 Tips for Porting Existing HTML5 Canvas applications
@@ -343,7 +341,7 @@ void QQuickCanvasItem::setContextType(const QString &contextType)
if (contextType.compare(d->contextType, Qt::CaseInsensitive) == 0)
return;
- if (d->contextInitialized) {
+ if (d->context) {
qmlInfo(this) << "Canvas already initialized with a different context type";
return;
}
@@ -368,7 +366,7 @@ void QQuickCanvasItem::setContextType(const QString &contextType)
QQmlV4Handle QQuickCanvasItem::context() const
{
Q_D(const QQuickCanvasItem);
- if (d->contextInitialized)
+ if (d->context)
return QQmlV4Handle(d->context->v4value());
return QQmlV4Handle(QV4::Value::nullValue());
@@ -402,7 +400,7 @@ void QQuickCanvasItem::setCanvasSize(const QSizeF & size)
d->canvasSize = size;
emit canvasSizeChanged();
- if (d->contextInitialized)
+ if (d->context)
polish();
}
}
@@ -437,7 +435,7 @@ void QQuickCanvasItem::setTileSize(const QSize & size)
emit tileSizeChanged();
- if (d->contextInitialized)
+ if (d->context)
polish();
}
}
@@ -470,7 +468,7 @@ void QQuickCanvasItem::setCanvasWindow(const QRectF& rect)
d->hasCanvasWindow = true;
emit canvasWindowChanged();
- if (d->contextInitialized)
+ if (d->context)
polish();
}
}
@@ -502,7 +500,7 @@ void QQuickCanvasItem::setRenderTarget(QQuickCanvasItem::RenderTarget target)
{
Q_D(QQuickCanvasItem);
if (d->renderTarget != target) {
- if (d->contextInitialized) {
+ if (d->context) {
qmlInfo(this) << "Canvas:renderTarget not changeble once context is active.";
return;
}
@@ -546,7 +544,7 @@ void QQuickCanvasItem::setRenderStrategy(QQuickCanvasItem::RenderStrategy strate
{
Q_D(QQuickCanvasItem);
if (d->renderStrategy != strategy) {
- if (d->contextInitialized) {
+ if (d->context) {
qmlInfo(this) << "Canvas:renderStrategy not changeable once context is active.";
return;
}
@@ -651,7 +649,7 @@ void QQuickCanvasItem::updatePolish()
Q_D(QQuickCanvasItem);
- if (d->contextInitialized)
+ if (d->context && d->renderStrategy != QQuickCanvasItem::Cooperative)
d->context->prepare(d->canvasSize.toSize(), d->tileSize, d->canvasWindow.toRect(), d->dirtyRect.toRect(), d->smooth, d->antialiasing);
if (d->animationCallbacks.size() > 0 && isVisible()) {
@@ -676,7 +674,7 @@ void QQuickCanvasItem::updatePolish()
}
}
- if (d->contextInitialized) {
+ if (d->context) {
if (d->renderStrategy == QQuickCanvasItem::Cooperative)
update();
else
@@ -688,8 +686,10 @@ QSGNode *QQuickCanvasItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData
{
Q_D(QQuickCanvasItem);
- if (!d->contextInitialized)
+ if (!d->context || d->canvasWindow.size().isEmpty()) {
+ delete oldNode;
return 0;
+ }
QSGSimpleTextureNode *node = static_cast<QSGSimpleTextureNode*>(oldNode);
if (!node)
@@ -700,10 +700,13 @@ QSGNode *QQuickCanvasItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData
else
node->setFiltering(QSGTexture::Nearest);
- if (d->renderStrategy == QQuickCanvasItem::Cooperative)
+ if (d->renderStrategy == QQuickCanvasItem::Cooperative) {
+ d->context->prepare(d->canvasSize.toSize(), d->tileSize, d->canvasWindow.toRect(), d->dirtyRect.toRect(), d->smooth, d->antialiasing);
d->context->flush();
+ }
node->setTexture(d->context->texture());
+ node->markDirty(QSGNode::DirtyMaterial);
node->setRect(QRectF(QPoint(0, 0), d->canvasWindow.size()));
return node;
}
@@ -763,7 +766,7 @@ void QQuickCanvasItem::getContext(QQmlV4Function *args)
/*!
\qmlmethod long QtQuick2::Canvas::requestAnimationFrame(callback)
- This function schedules callback to be invoked before composing the QtQuick
+ This function schedules callback to be invoked before composing the Qt Quick
scene.
*/
@@ -970,7 +973,7 @@ bool QQuickCanvasItem::isImageLoaded(const QUrl& url) const
QImage QQuickCanvasItem::toImage(const QRectF& rect) const
{
Q_D(const QQuickCanvasItem);
- if (d->contextInitialized) {
+ if (d->context) {
if (rect.isEmpty())
return d->context->toImage(canvasWindow());
else
@@ -1026,7 +1029,7 @@ void QQuickCanvasItem::delayedCreate()
{
Q_D(QQuickCanvasItem);
- if (!d->contextInitialized && !d->contextType.isNull())
+ if (!d->context && !d->contextType.isNull())
createContext(d->contextType);
requestPaint();
@@ -1055,7 +1058,6 @@ void QQuickCanvasItem::initializeContext(QQuickCanvasContext *context, const QVa
d->context = context;
d->context->init(this, args);
d->context->setV8Engine(QQmlEnginePrivate::getV8Engine(qmlEngine(this)));
- d->contextInitialized = true;
connect(d->context, SIGNAL(textureChanged()), SLOT(update()));
connect(d->context, SIGNAL(textureChanged()), SIGNAL(painted()));
emit contextChanged();