2019-04-27 09:12:53 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2019-05-13 21:57:59 +00:00
|
|
|
#include "lottie/lottie_common.h"
|
2019-06-28 11:33:47 +00:00
|
|
|
#include "base/weak_ptr.h"
|
2019-05-13 21:57:59 +00:00
|
|
|
|
2019-08-01 11:42:24 +00:00
|
|
|
#include <QtGui/QImage>
|
|
|
|
|
2019-05-02 07:23:32 +00:00
|
|
|
class QString;
|
|
|
|
class QByteArray;
|
2019-04-27 09:12:53 +00:00
|
|
|
|
2019-06-26 17:14:46 +00:00
|
|
|
namespace rlottie {
|
|
|
|
class Animation;
|
|
|
|
} // namespace rlottie
|
|
|
|
|
2019-04-27 09:12:53 +00:00
|
|
|
namespace Lottie {
|
|
|
|
|
2019-06-28 11:33:47 +00:00
|
|
|
class Player;
|
2019-05-13 21:57:59 +00:00
|
|
|
class SharedState;
|
2019-07-02 14:29:26 +00:00
|
|
|
class FrameRenderer;
|
|
|
|
|
|
|
|
std::shared_ptr<FrameRenderer> MakeFrameRenderer();
|
2019-04-27 09:12:53 +00:00
|
|
|
|
2019-06-26 14:18:00 +00:00
|
|
|
QImage ReadThumbnail(const QByteArray &content);
|
|
|
|
|
|
|
|
namespace details {
|
|
|
|
|
|
|
|
using InitData = base::variant<std::unique_ptr<SharedState>, Error>;
|
|
|
|
|
2019-06-26 17:14:46 +00:00
|
|
|
std::unique_ptr<rlottie::Animation> CreateFromContent(
|
2019-08-07 14:22:51 +00:00
|
|
|
const QByteArray &content,
|
|
|
|
const ColorReplacements *replacements);
|
2019-06-26 17:14:46 +00:00
|
|
|
|
2019-06-26 14:18:00 +00:00
|
|
|
} // namespace details
|
2019-05-28 15:45:30 +00:00
|
|
|
|
2019-05-13 21:57:59 +00:00
|
|
|
class Animation final : public base::has_weak_ptr {
|
2019-04-27 09:12:53 +00:00
|
|
|
public:
|
2019-08-01 11:42:24 +00:00
|
|
|
struct FrameInfo {
|
|
|
|
QImage image;
|
|
|
|
int index = 0;
|
|
|
|
};
|
|
|
|
|
2019-06-28 11:33:47 +00:00
|
|
|
Animation(
|
|
|
|
not_null<Player*> player,
|
2019-06-27 16:57:32 +00:00
|
|
|
const QByteArray &content,
|
2019-07-05 17:15:25 +00:00
|
|
|
const FrameRequest &request,
|
2019-08-07 14:22:51 +00:00
|
|
|
Quality quality,
|
|
|
|
const ColorReplacements *replacements = nullptr);
|
2019-06-26 14:18:00 +00:00
|
|
|
Animation(
|
2019-06-28 11:33:47 +00:00
|
|
|
not_null<Player*> player,
|
2019-06-27 14:36:01 +00:00
|
|
|
FnMut<void(FnMut<void(QByteArray &&cached)>)> get, // Main thread.
|
|
|
|
FnMut<void(QByteArray &&cached)> put, // Unknown thread.
|
2019-06-26 14:18:00 +00:00
|
|
|
const QByteArray &content,
|
2019-07-05 17:15:25 +00:00
|
|
|
const FrameRequest &request,
|
2019-08-07 14:22:51 +00:00
|
|
|
Quality quality,
|
|
|
|
const ColorReplacements *replacements = nullptr);
|
2019-04-27 09:12:53 +00:00
|
|
|
|
|
|
|
[[nodiscard]] bool ready() const;
|
2019-07-02 13:20:04 +00:00
|
|
|
[[nodiscard]] QImage frame() const;
|
2019-06-28 11:33:47 +00:00
|
|
|
[[nodiscard]] QImage frame(const FrameRequest &request) const;
|
2019-08-01 11:42:24 +00:00
|
|
|
[[nodiscard]] FrameInfo frameInfo(const FrameRequest &request) const;
|
2019-04-27 09:12:53 +00:00
|
|
|
|
|
|
|
private:
|
2019-06-26 14:18:00 +00:00
|
|
|
void initDone(details::InitData &&data);
|
2019-05-13 21:57:59 +00:00
|
|
|
void parseDone(std::unique_ptr<SharedState> state);
|
2019-05-28 15:45:30 +00:00
|
|
|
void parseFailed(Error error);
|
2019-04-27 09:12:53 +00:00
|
|
|
|
2019-06-28 11:33:47 +00:00
|
|
|
not_null<Player*> _player;
|
2019-05-13 21:57:59 +00:00
|
|
|
SharedState *_state = nullptr;
|
2019-04-27 09:12:53 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Lottie
|