diff --git a/Telegram/SourceFiles/lottie/lottie_animation.cpp b/Telegram/SourceFiles/lottie/lottie_animation.cpp index 945a871271..0a97d8b49d 100644 --- a/Telegram/SourceFiles/lottie/lottie_animation.cpp +++ b/Telegram/SourceFiles/lottie/lottie_animation.cpp @@ -173,6 +173,35 @@ void Animation::parse(const QByteArray &content) { _unsupported = true; } } + + resolveAssets(); +} + +void Animation::resolveAssets() { + if (_assets.empty()) { + return; + } + + std::function resolver = [&](const QString &refId) + -> BMAsset* { + const auto i = _assetIndexById.find(refId); + if (i == end(_assetIndexById)) { + return nullptr; + } + const auto result = _assets[i->second].get(); + result->resolveAssets(resolver); + return result->clone(); + }; + for (const auto &asset : _assets) { + asset->resolveAssets(resolver); + } + + _treeBlueprint->resolveAssets([&](const QString &refId) { + const auto i = _assetIndexById.find(refId); + return (i != end(_assetIndexById)) + ? _assets[i->second]->clone() + : nullptr; + }); } } // namespace Lottie diff --git a/Telegram/SourceFiles/lottie/lottie_animation.h b/Telegram/SourceFiles/lottie/lottie_animation.h index 48bae857aa..9b9cc4e9f8 100644 --- a/Telegram/SourceFiles/lottie/lottie_animation.h +++ b/Telegram/SourceFiles/lottie/lottie_animation.h @@ -62,6 +62,7 @@ public: private: void parse(const QByteArray &content); + void resolveAssets(); int _startFrame = 0; int _endFrame = 0; diff --git a/Telegram/ThirdParty/qtlottie b/Telegram/ThirdParty/qtlottie index 1e81797fd7..57e54b3d58 160000 --- a/Telegram/ThirdParty/qtlottie +++ b/Telegram/ThirdParty/qtlottie @@ -1 +1 @@ -Subproject commit 1e81797fd7ec924f49e13866b08f57708537251a +Subproject commit 57e54b3d5839431d935899c111f63daec3f53c30 diff --git a/Telegram/ThirdParty/qtlottie_helper/QtBodymovin/private/bmasset_p.h b/Telegram/ThirdParty/qtlottie_helper/QtBodymovin/private/bmasset_p.h index a60d1b0303..76bcc12dd3 100644 --- a/Telegram/ThirdParty/qtlottie_helper/QtBodymovin/private/bmasset_p.h +++ b/Telegram/ThirdParty/qtlottie_helper/QtBodymovin/private/bmasset_p.h @@ -54,16 +54,19 @@ public: explicit BMAsset (const BMAsset &other) = default; ~BMAsset() = default; - BMBase *clone() const override; + BMAsset *clone() const override; static BMAsset *construct(QJsonObject definition); void parse(const QJsonObject &definition) override; + void resolveAssets(const std::function &resolver) override; + QString id() const; private: QString m_id; + bool m_resolved = false; }; diff --git a/Telegram/ThirdParty/qtlottie_helper/QtBodymovin/private/bmbase_p.h b/Telegram/ThirdParty/qtlottie_helper/QtBodymovin/private/bmbase_p.h index 90818dc532..c7cc354d3a 100644 --- a/Telegram/ThirdParty/qtlottie_helper/QtBodymovin/private/bmbase_p.h +++ b/Telegram/ThirdParty/qtlottie_helper/QtBodymovin/private/bmbase_p.h @@ -49,8 +49,12 @@ #include +#include + QT_BEGIN_NAMESPACE +class BMAsset; + class BODYMOVIN_EXPORT BMBase { public: @@ -86,6 +90,8 @@ public: virtual void updateProperties(int frame); virtual void render(LottieRenderer &renderer) const; + virtual void resolveAssets(const std::function &resolver); + protected: void resolveTopRoot(); BMBase *topRoot() const; diff --git a/Telegram/ThirdParty/qtlottie_helper/QtBodymovin/private/bmprecompasset_p.h b/Telegram/ThirdParty/qtlottie_helper/QtBodymovin/private/bmprecompasset_p.h index 6fb19b4e9f..01e098b886 100644 --- a/Telegram/ThirdParty/qtlottie_helper/QtBodymovin/private/bmprecompasset_p.h +++ b/Telegram/ThirdParty/qtlottie_helper/QtBodymovin/private/bmprecompasset_p.h @@ -55,11 +55,7 @@ public: BMPreCompAsset(const QJsonObject &definition); ~BMPreCompAsset() = default; - BMBase *clone() const override; - -private: - void parseLayers(const QJsonArray &definition); - + BMPreCompAsset *clone() const override; }; QT_END_NAMESPACE diff --git a/Telegram/ThirdParty/qtlottie_helper/QtBodymovin/private/bmprecomplayer_p.h b/Telegram/ThirdParty/qtlottie_helper/QtBodymovin/private/bmprecomplayer_p.h new file mode 100644 index 0000000000..7b55dc47af --- /dev/null +++ b/Telegram/ThirdParty/qtlottie_helper/QtBodymovin/private/bmprecomplayer_p.h @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** 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 BMPRECOMPLAYER_P_H +#define BMPRECOMPLAYER_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 + +QT_BEGIN_NAMESPACE + +class QJsonObject; + +class LottieRenderer; +class BMShape; +class BMTrimPath; +class BMBasicTransform; + +class BODYMOVIN_EXPORT BMPreCompLayer : public BMLayer +{ +public: + BMPreCompLayer() = default; + explicit BMPreCompLayer(const BMPreCompLayer &other); + BMPreCompLayer(const QJsonObject &definition); + ~BMPreCompLayer() override; + + BMBase *clone() const override; + + void updateProperties(int frame) override; + void render(LottieRenderer &renderer) const; + void resolveAssets(const std::function &resolver) override; + + QString refId() const; + +protected: + QList m_maskProperties; + +private: + QString m_refId; + BMBase *m_layers = nullptr; + int m_layersFrame = 0; + bool m_resolving = false; + +}; + +QT_END_NAMESPACE + +#endif // BMPRECOMPLAYER_P_H diff --git a/Telegram/gyp/lib_lottie.gyp b/Telegram/gyp/lib_lottie.gyp index a8927bf07e..87e41c9212 100644 --- a/Telegram/gyp/lib_lottie.gyp +++ b/Telegram/gyp/lib_lottie.gyp @@ -126,10 +126,12 @@ '<(lottie_loc)/bodymovin/bmasset.cpp', '<(lottie_loc)/bodymovin/bmprecompasset.cpp', '<(lottie_loc)/bodymovin/bmnulllayer.cpp', + '<(lottie_loc)/bodymovin/bmprecomplayer.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', ], 'conditions': [[ 'build_macold', { 'xcode_settings': {