From 246e4e45bdfd701ca291e2136332789a97f04ae7 Mon Sep 17 00:00:00 2001 From: John Preston Date: Sun, 12 May 2019 22:48:15 +0300 Subject: [PATCH] QtLottie: Add partial support for masksProperties. --- Telegram/ThirdParty/qtlottie | 2 +- .../QtBodymovin/private/bmlayer_p.h | 4 +- .../QtBodymovin/private/bmmasks_p.h | 67 ++++++++++ .../QtBodymovin/private/bmmaskshape_p.h | 118 ++++++++++++++++++ .../QtBodymovin/private/bmprecomplayer_p.h | 3 - .../QtBodymovin/private/bmproperty_p.h | 4 + .../QtBodymovin/private/bmshapelayer_p.h | 3 - .../QtBodymovin/private/lottierenderer_p.h | 6 + Telegram/gyp/lib_lottie.gyp | 4 + 9 files changed, 203 insertions(+), 8 deletions(-) create mode 100644 Telegram/ThirdParty/qtlottie_helper/QtBodymovin/private/bmmasks_p.h create mode 100644 Telegram/ThirdParty/qtlottie_helper/QtBodymovin/private/bmmaskshape_p.h diff --git a/Telegram/ThirdParty/qtlottie b/Telegram/ThirdParty/qtlottie index 2f299eed51..741b80b10c 160000 --- a/Telegram/ThirdParty/qtlottie +++ b/Telegram/ThirdParty/qtlottie @@ -1 +1 @@ -Subproject commit 2f299eed51619c3943fb22a7efb6dcd9727703d6 +Subproject commit 741b80b10cf8b2a06ed7dfda1bf9d64896ac0249 diff --git a/Telegram/ThirdParty/qtlottie_helper/QtBodymovin/private/bmlayer_p.h b/Telegram/ThirdParty/qtlottie_helper/QtBodymovin/private/bmlayer_p.h index 3992b890d9..3ca2fba74b 100644 --- a/Telegram/ThirdParty/qtlottie_helper/QtBodymovin/private/bmlayer_p.h +++ b/Telegram/ThirdParty/qtlottie_helper/QtBodymovin/private/bmlayer_p.h @@ -46,6 +46,7 @@ QT_BEGIN_NAMESPACE class LottieRenderer; +class BMMasks; class BODYMOVIN_EXPORT BMLayer : public BMBase { @@ -63,7 +64,6 @@ public: void parse(const QJsonObject &definition) override; void updateProperties(int frame) override; - void render(LottieRenderer &renderer, int frame) const override; BMBase *findChild(const QString &childName) override; @@ -90,6 +90,7 @@ protected: BMBase *m_effects = nullptr; qreal m_stretch; BMBasicTransform *m_layerTransform = nullptr; + BMMasks *m_masks = nullptr; int m_parentLayer = 0; int m_td = 0; @@ -99,6 +100,7 @@ protected: private: void parseEffects(const QJsonArray &definition, BMBase *effectRoot = nullptr); + void parseMasks(const QJsonArray &definition); BMLayer *m_linkedLayer = nullptr; }; diff --git a/Telegram/ThirdParty/qtlottie_helper/QtBodymovin/private/bmmasks_p.h b/Telegram/ThirdParty/qtlottie_helper/QtBodymovin/private/bmmasks_p.h new file mode 100644 index 0000000000..d3dc429fd4 --- /dev/null +++ b/Telegram/ThirdParty/qtlottie_helper/QtBodymovin/private/bmmasks_p.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the lottie-qt module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** 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 General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) 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.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-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef BMMASKS_P_H +#define BMMASKS_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 +#include + +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QJsonObject; + +class BODYMOVIN_EXPORT BMMasks : public BMBase +{ +public: + BMBase *clone() const override; + + void render(LottieRenderer &renderer, int frame) const override; + +}; + +QT_END_NAMESPACE + +#endif // BMMASKCLIP_P_H diff --git a/Telegram/ThirdParty/qtlottie_helper/QtBodymovin/private/bmmaskshape_p.h b/Telegram/ThirdParty/qtlottie_helper/QtBodymovin/private/bmmaskshape_p.h new file mode 100644 index 0000000000..2e938d7a8f --- /dev/null +++ b/Telegram/ThirdParty/qtlottie_helper/QtBodymovin/private/bmmaskshape_p.h @@ -0,0 +1,118 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the lottie-qt module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** 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 General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) 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.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-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef BMMASKSHAPE_P_H +#define BMMASKSHAPE_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 +#include + +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QJsonObject; + +class BODYMOVIN_EXPORT BMMaskShape : public BMShape +{ +public: + BMMaskShape(); + explicit BMMaskShape(const BMMaskShape &other); + BMMaskShape(const QJsonObject &definition, BMBase *parent = nullptr); + + BMBase *clone() const override; + + void construct(const QJsonObject &definition); + + void updateProperties(int frame) override; + void render(LottieRenderer &renderer, int frame) const override; + + enum class Mode { + Additive, + Intersect, + }; + + Mode mode() const; + + bool inverted() const; + +protected: + struct VertexInfo { + BMProperty2D pos; + BMProperty2D ci; + BMProperty2D co; + }; + + void parseShapeKeyframes(QJsonObject &keyframes); + void buildShape(const QJsonObject &keyframe); + void buildShape(int frame); + void parseEasedVertices(const QJsonObject &keyframe, int startFrame); + + QHash m_vertexMap; + QList m_vertexList; + QMap m_closedShape; + + bool m_inverted = false; + BMProperty m_opacity; + Mode m_mode = Mode::Additive; + +private: + struct VertexBuildInfo + { + QJsonArray posKeyframes; + QJsonArray ciKeyframes; + QJsonArray coKeyframes; + }; + + void finalizeVertices(); + + QMap m_vertexInfos; + + QJsonObject createKeyframe(QJsonArray startValue, QJsonArray endValue, + int startFrame, QJsonObject easingIn, + QJsonObject easingOut); +}; + +QT_END_NAMESPACE + +#endif // BMMASKSHAPE_P_H diff --git a/Telegram/ThirdParty/qtlottie_helper/QtBodymovin/private/bmprecomplayer_p.h b/Telegram/ThirdParty/qtlottie_helper/QtBodymovin/private/bmprecomplayer_p.h index 7880441790..176eadd0f7 100644 --- a/Telegram/ThirdParty/qtlottie_helper/QtBodymovin/private/bmprecomplayer_p.h +++ b/Telegram/ThirdParty/qtlottie_helper/QtBodymovin/private/bmprecomplayer_p.h @@ -68,9 +68,6 @@ public: QString refId() const; -protected: - QList m_maskProperties; - private: QString m_refId; BMBase *m_layers = nullptr; diff --git a/Telegram/ThirdParty/qtlottie_helper/QtBodymovin/private/bmproperty_p.h b/Telegram/ThirdParty/qtlottie_helper/QtBodymovin/private/bmproperty_p.h index c33ed6be92..b51a1e2448 100644 --- a/Telegram/ThirdParty/qtlottie_helper/QtBodymovin/private/bmproperty_p.h +++ b/Telegram/ThirdParty/qtlottie_helper/QtBodymovin/private/bmproperty_p.h @@ -131,6 +131,10 @@ public: return m_value; } + bool animated() const { + return m_animated; + } + virtual bool update(int frame) { if (!m_animated) diff --git a/Telegram/ThirdParty/qtlottie_helper/QtBodymovin/private/bmshapelayer_p.h b/Telegram/ThirdParty/qtlottie_helper/QtBodymovin/private/bmshapelayer_p.h index d8dbbd37b3..9d6607fd84 100644 --- a/Telegram/ThirdParty/qtlottie_helper/QtBodymovin/private/bmshapelayer_p.h +++ b/Telegram/ThirdParty/qtlottie_helper/QtBodymovin/private/bmshapelayer_p.h @@ -65,9 +65,6 @@ public: void updateProperties(int frame) override; void render(LottieRenderer &render, int frame) const override; -protected: - QList m_maskProperties; - private: BMTrimPath *m_appliedTrim = nullptr; }; diff --git a/Telegram/ThirdParty/qtlottie_helper/QtBodymovin/private/lottierenderer_p.h b/Telegram/ThirdParty/qtlottie_helper/QtBodymovin/private/lottierenderer_p.h index 0a55c2b63d..486eaa38f1 100644 --- a/Telegram/ThirdParty/qtlottie_helper/QtBodymovin/private/lottierenderer_p.h +++ b/Telegram/ThirdParty/qtlottie_helper/QtBodymovin/private/lottierenderer_p.h @@ -65,6 +65,9 @@ class BMTrimPath; class BMFillEffect; class BMRepeater; +class BMMasks; +class BMMaskShape; + class BODYMOVIN_EXPORT LottieRenderer { public: @@ -95,6 +98,9 @@ public: virtual void render(const BMFillEffect &effect) = 0; virtual void render(const BMRepeater &repeater) = 0; + virtual void render(const BMMaskShape &shape) = 0; + virtual void render(const BMMasks &masks) = 0; + protected: void saveTrimmingState(); void restoreTrimmingState(); diff --git a/Telegram/gyp/lib_lottie.gyp b/Telegram/gyp/lib_lottie.gyp index e792a770f5..e594c8a757 100644 --- a/Telegram/gyp/lib_lottie.gyp +++ b/Telegram/gyp/lib_lottie.gyp @@ -128,12 +128,16 @@ '<(lottie_loc)/bodymovin/bmnulllayer.cpp', '<(lottie_loc)/bodymovin/bmprecomplayer.cpp', '<(lottie_loc)/bodymovin/bmscene.cpp', + '<(lottie_loc)/bodymovin/bmmasks.cpp', + '<(lottie_loc)/bodymovin/bmmaskshape.cpp', '<(lottie_loc)/bodymovin/bmasset_p.h', '<(lottie_loc)/bodymovin/bmprecompasset_p.h', '<(lottie_loc)/bodymovin/bmnulllayer_p.h', '<(lottie_loc)/bodymovin/bmprecomplayer_p.h', '<(lottie_loc)/bodymovin/bmscene_p.h', + '<(lottie_loc)/bodymovin/bmmasks_p.h', + '<(lottie_loc)/bodymovin/bmmaskshape_p.h', ], 'conditions': [[ 'build_macold', { 'xcode_settings': {