aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/quick/items/qquickwindow.cpp1
-rw-r--r--src/quick/util/qquickanimatorcontroller.cpp42
-rw-r--r--src/quick/util/qquickanimatorcontroller_p.h4
-rw-r--r--src/quick/util/qquickanimatorjob.cpp26
-rw-r--r--src/quick/util/qquickanimatorjob_p.h4
-rw-r--r--tests/auto/qmltest/animators/tst_multiwindow.qml103
6 files changed, 171 insertions, 9 deletions
diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp
index d258b63484..6220ea2e1f 100644
--- a/src/quick/items/qquickwindow.cpp
+++ b/src/quick/items/qquickwindow.cpp
@@ -2449,6 +2449,7 @@ void QQuickWindowPrivate::cleanupNodesOnShutdown()
QSet<QQuickItem *>::const_iterator it = parentlessItems.begin();
for (; it != parentlessItems.end(); ++it)
cleanupNodesOnShutdown(*it);
+ animationController->windowNodesDestroyed();
q->cleanupSceneGraph();
}
diff --git a/src/quick/util/qquickanimatorcontroller.cpp b/src/quick/util/qquickanimatorcontroller.cpp
index 7991dd8110..697c25b211 100644
--- a/src/quick/util/qquickanimatorcontroller.cpp
+++ b/src/quick/util/qquickanimatorcontroller.cpp
@@ -54,6 +54,7 @@ QT_BEGIN_NAMESPACE
QQuickAnimatorController::QQuickAnimatorController()
: m_window(0)
+ , m_nodesAreInvalid(false)
{
}
@@ -80,6 +81,26 @@ QQuickAnimatorController::~QQuickAnimatorController()
}
}
+static void qquickanimator_invalidate_node(QAbstractAnimationJob *job)
+{
+ if (job->isRenderThreadJob()) {
+ static_cast<QQuickAnimatorJob *>(job)->nodeWasDestroyed();
+ } else if (job->isGroup()) {
+ QAnimationGroupJob *g = static_cast<QAnimationGroupJob *>(job);
+ for (QAbstractAnimationJob *a = g->firstChild(); a; a = a->nextSibling())
+ qquickanimator_invalidate_node(a);
+ }
+}
+
+void QQuickAnimatorController::windowNodesDestroyed()
+{
+ m_nodesAreInvalid = true;
+ for (QHash<QAbstractAnimationJob *, QQuickAnimatorProxyJob *>::const_iterator it = m_animatorRoots.constBegin();
+ it != m_animatorRoots.constEnd(); ++it) {
+ qquickanimator_invalidate_node(it.key());
+ }
+}
+
void QQuickAnimatorController::itemDestroyed(QObject *o)
{
m_deletedSinceLastFrame << (QQuickItem *) o;
@@ -112,7 +133,7 @@ void QQuickAnimatorController::advance()
m_window->update();
}
-static void qquick_initialize_helper(QAbstractAnimationJob *job, QQuickAnimatorController *c)
+static void qquick_initialize_helper(QAbstractAnimationJob *job, QQuickAnimatorController *c, bool attachListener)
{
if (job->isRenderThreadJob()) {
QQuickAnimatorJob *j = static_cast<QQuickAnimatorJob *>(job);
@@ -121,13 +142,14 @@ static void qquick_initialize_helper(QAbstractAnimationJob *job, QQuickAnimatorC
} else if (c->m_deletedSinceLastFrame.contains(j->target())) {
j->targetWasDeleted();
} else {
- j->addAnimationChangeListener(c, QAbstractAnimationJob::StateChange);
+ if (attachListener)
+ j->addAnimationChangeListener(c, QAbstractAnimationJob::StateChange);
j->initialize(c);
}
} else if (job->isGroup()) {
QAnimationGroupJob *g = static_cast<QAnimationGroupJob *>(job);
for (QAbstractAnimationJob *a = g->firstChild(); a; a = a->nextSibling())
- qquick_initialize_helper(a, c);
+ qquick_initialize_helper(a, c, attachListener);
}
}
@@ -147,7 +169,7 @@ void QQuickAnimatorController::beforeNodeSync()
foreach (QQuickAnimatorProxyJob *proxy, m_starting) {
QAbstractAnimationJob *job = proxy->job();
job->addAnimationChangeListener(this, QAbstractAnimationJob::Completion);
- qquick_initialize_helper(job, this);
+ qquick_initialize_helper(job, this, true);
m_animatorRoots[job] = proxy;
job->start();
proxy->startedByController();
@@ -160,6 +182,18 @@ void QQuickAnimatorController::beforeNodeSync()
}
m_stopping.clear();
+ // First sync after a window was hidden or otherwise invalidated.
+ // call initialize again to pick up new nodes..
+ if (m_nodesAreInvalid) {
+ for (QHash<QAbstractAnimationJob *, QQuickAnimatorProxyJob *>::const_iterator it = m_animatorRoots.constBegin();
+ it != m_animatorRoots.constEnd(); ++it) {
+ qquick_initialize_helper(it.key(), this, false);
+ }
+ m_nodesAreInvalid = false;
+ }
+
+
+
foreach (QQuickAnimatorJob *job, m_activeLeafAnimations) {
if (!job->target())
continue;
diff --git a/src/quick/util/qquickanimatorcontroller_p.h b/src/quick/util/qquickanimatorcontroller_p.h
index 6223a9938f..745a494eec 100644
--- a/src/quick/util/qquickanimatorcontroller_p.h
+++ b/src/quick/util/qquickanimatorcontroller_p.h
@@ -76,6 +76,8 @@ public:
void lock() { m_mutex.lock(); }
void unlock() { m_mutex.unlock(); }
+ void windowNodesDestroyed();
+
public Q_SLOTS:
void itemDestroyed(QObject *);
@@ -92,6 +94,8 @@ public:
QSet<QQuickItem *> m_deletedSinceLastFrame;
QQuickWindow *m_window;
QMutex m_mutex;
+
+ bool m_nodesAreInvalid;
};
QT_END_NAMESPACE
diff --git a/src/quick/util/qquickanimatorjob.cpp b/src/quick/util/qquickanimatorjob.cpp
index 3bc4cef5b9..0bf95a49b4 100644
--- a/src/quick/util/qquickanimatorjob.cpp
+++ b/src/quick/util/qquickanimatorjob.cpp
@@ -281,6 +281,12 @@ void QQuickTransformAnimatorJob::initialize(QQuickAnimatorController *controller
}
}
+void QQuickTransformAnimatorJob::nodeWasDestroyed()
+{
+ if (m_helper)
+ m_helper->node = 0;
+}
+
void QQuickTransformAnimatorJob::Helper::sync()
{
const quint32 mask = QQuickItemPrivate::Position
@@ -326,7 +332,7 @@ void QQuickTransformAnimatorJob::Helper::sync()
void QQuickTransformAnimatorJob::Helper::apply()
{
- if (!wasChanged)
+ if (!wasChanged || !node)
return;
QMatrix4x4 m;
@@ -412,6 +418,11 @@ void QQuickOpacityAnimatorJob::initialize(QQuickAnimatorController *controller)
}
}
+void QQuickOpacityAnimatorJob::nodeWasDestroyed()
+{
+ m_opacityNode = 0;
+}
+
void QQuickOpacityAnimatorJob::writeBack()
{
if (m_target)
@@ -420,7 +431,7 @@ void QQuickOpacityAnimatorJob::writeBack()
void QQuickOpacityAnimatorJob::updateCurrentTime(int time)
{
- if (!m_controller)
+ if (!m_controller || !m_opacityNode)
return;
Q_ASSERT(m_controller->m_window->openglContext()->thread() == QThread::currentThread());
@@ -504,13 +515,18 @@ void QQuickUniformAnimatorJob::setTarget(QQuickItem *target)
m_target = target;
}
+void QQuickUniformAnimatorJob::nodeWasDestroyed()
+{
+ m_node = 0;
+ m_uniformIndex = -1;
+ m_uniformType = -1;
+}
+
void QQuickUniformAnimatorJob::afterNodeSync()
{
m_node = static_cast<QQuickShaderEffectNode *>(QQuickItemPrivate::get(m_target)->paintNode);
- if (m_node) {
- m_uniformIndex = -1;
- m_uniformType = -1;
+ if (m_node && m_uniformIndex == -1 && m_uniformType == -1) {
QQuickShaderEffectMaterial *material =
static_cast<QQuickShaderEffectMaterial *>(m_node->material());
bool found = false;
diff --git a/src/quick/util/qquickanimatorjob_p.h b/src/quick/util/qquickanimatorjob_p.h
index 8aae121106..03b13bcd30 100644
--- a/src/quick/util/qquickanimatorjob_p.h
+++ b/src/quick/util/qquickanimatorjob_p.h
@@ -131,6 +131,7 @@ public:
void targetWasDeleted();
virtual void initialize(QQuickAnimatorController *controller);
virtual void writeBack() = 0;
+ virtual void nodeWasDestroyed() = 0;
bool isTransform() const { return m_isTransform; }
bool isUniform() const { return m_isUniform; }
@@ -208,6 +209,7 @@ public:
protected:
QQuickTransformAnimatorJob();
void initialize(QQuickAnimatorController *controller);
+ void nodeWasDestroyed();
Helper *m_helper;
};
@@ -256,6 +258,7 @@ public:
void initialize(QQuickAnimatorController *controller);
void updateCurrentTime(int time);
void writeBack();
+ void nodeWasDestroyed();
private:
QSGOpacityNode *m_opacityNode;
@@ -275,6 +278,7 @@ public:
void updateCurrentTime(int time);
void writeBack();
+ void nodeWasDestroyed();
private:
QByteArray m_uniform;
diff --git a/tests/auto/qmltest/animators/tst_multiwindow.qml b/tests/auto/qmltest/animators/tst_multiwindow.qml
new file mode 100644
index 0000000000..7f7ca253d3
--- /dev/null
+++ b/tests/auto/qmltest/animators/tst_multiwindow.qml
@@ -0,0 +1,103 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Jolla Ltd, author: <gunnar.sletta@jollamobile.com>
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the test suite 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.2
+import QtTest 1.0
+import QtQuick.Window 2.0
+
+Item {
+ id: root;
+ width: 200
+ height: 200
+
+ TestCase {
+ id: testCase
+ name: "animators-mixed"
+ when: countdown == 0
+ function test_endresult() {
+ verify(true, "Just making sure we didn't crash");
+ }
+ }
+
+ property int countdown: 5;
+
+ Window {
+ id: window
+
+ width: 100
+ height: 100
+
+ ShaderEffect {
+ width: 50
+ height: 50
+
+ property real t;
+ UniformAnimator on t { from: 0; to: 1; duration: 1000; loops: Animation.Infinite }
+ RotationAnimator on rotation { from: 0; to: 360; duration: 1000; loops: Animation.Infinite }
+ ScaleAnimator on scale { from: 0.5; to: 1.5; duration: 1000; loops: Animation.Infinite }
+ XAnimator on x { from: 0; to: 50; duration: 1000; loops: Animation.Infinite }
+ YAnimator on y { from: 0; to: 50; duration: 1000; loops: Animation.Infinite }
+ OpacityAnimator on opacity { from: 1; to: 0.5; duration: 1000; loops: Animation.Infinite }
+
+ fragmentShader: "
+ uniform lowp float t;
+ uniform lowp float qt_Opacity;
+ varying highp vec2 qt_TexCoord0;
+ void main() {
+ gl_FragColor = vec4(qt_TexCoord0, t, 1) * qt_Opacity;
+ }
+ "
+ }
+
+ visible: true
+ }
+
+ Timer {
+ interval: 250
+ running: true
+ repeat: true
+ onTriggered: {
+ if (window.visible)
+ --countdown
+ window.visible = !window.visible;
+ }
+ }
+}