tdesktop/Telegram/SourceFiles/lottie/lottie_animation.h

70 lines
1.6 KiB
C
Raw Normal View History

2019-04-27 13:12:53 +04: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
#include "lottie/lottie_common.h"
#include "base/weak_ptr.h"
2019-05-02 11:23:32 +04:00
class QImage;
class QString;
class QByteArray;
2019-04-27 13:12:53 +04:00
2019-06-26 19:14:46 +02:00
namespace rlottie {
class Animation;
} // namespace rlottie
2019-04-27 13:12:53 +04:00
namespace Lottie {
class Player;
class SharedState;
class FrameRenderer;
std::shared_ptr<FrameRenderer> MakeFrameRenderer();
2019-04-27 13:12:53 +04:00
2019-06-26 16:18:00 +02:00
QImage ReadThumbnail(const QByteArray &content);
namespace details {
using InitData = base::variant<std::unique_ptr<SharedState>, Error>;
2019-06-26 19:14:46 +02:00
std::unique_ptr<rlottie::Animation> CreateFromContent(
const QByteArray &content);
2019-06-26 16:18:00 +02:00
} // namespace details
2019-05-28 17:45:30 +02:00
class Animation final : public base::has_weak_ptr {
2019-04-27 13:12:53 +04:00
public:
Animation(
not_null<Player*> player,
2019-06-27 18:57:32 +02:00
const QByteArray &content,
2019-07-05 19:15:25 +02:00
const FrameRequest &request,
Quality quality);
2019-06-26 16:18:00 +02:00
Animation(
not_null<Player*> player,
FnMut<void(FnMut<void(QByteArray &&cached)>)> get, // Main thread.
FnMut<void(QByteArray &&cached)> put, // Unknown thread.
2019-06-26 16:18:00 +02:00
const QByteArray &content,
2019-07-05 19:15:25 +02:00
const FrameRequest &request,
Quality quality);
2019-04-27 13:12:53 +04:00
[[nodiscard]] bool ready() const;
2019-07-02 15:20:04 +02:00
[[nodiscard]] QImage frame() const;
[[nodiscard]] QImage frame(const FrameRequest &request) const;
2019-04-27 13:12:53 +04:00
private:
2019-06-26 16:18:00 +02:00
void initDone(details::InitData &&data);
void parseDone(std::unique_ptr<SharedState> state);
2019-05-28 17:45:30 +02:00
void parseFailed(Error error);
2019-04-27 13:12:53 +04:00
not_null<Player*> _player;
SharedState *_state = nullptr;
2019-04-27 13:12:53 +04:00
};
} // namespace Lottie