tdesktop/Telegram/SourceFiles/lottie/lottie_animation.h

78 lines
1.7 KiB
C
Raw Normal View History

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
#include "base/basic_types.h"
#include "base/flat_map.h"
#include "base/weak_ptr.h"
#include "base/timer.h"
#include "lottie/lottie_common.h"
#include <QSize>
2019-04-27 09:12:53 +00:00
#include <crl/crl_time.h>
#include <rpl/event_stream.h>
2019-05-03 13:56:29 +00:00
#include <vector>
#include <optional>
2019-05-02 07:23:32 +00:00
class QImage;
class QString;
class QByteArray;
2019-04-27 09:12:53 +00:00
namespace Lottie {
2019-05-28 15:45:30 +00:00
constexpr auto kMaxFileSize = 1024 * 1024;
2019-04-27 09:12:53 +00:00
class Animation;
class SharedState;
class FrameRenderer;
2019-04-27 09:12:53 +00:00
std::unique_ptr<Animation> FromFile(const QString &path);
std::unique_ptr<Animation> FromData(const QByteArray &data);
2019-04-27 09:12:53 +00:00
2019-05-28 15:45:30 +00:00
QImage ReadThumbnail(QByteArray &&content);
class Animation final : public base::has_weak_ptr {
2019-04-27 09:12:53 +00:00
public:
explicit Animation(QByteArray &&content);
2019-04-27 09:12:53 +00:00
~Animation();
//void play(const PlaybackOptions &options);
2019-04-27 09:12:53 +00:00
[[nodiscard]] QImage frame(const FrameRequest &request) const;
2019-04-27 09:12:53 +00:00
[[nodiscard]] rpl::producer<Update, Error> updates() const;
2019-04-27 09:12:53 +00:00
[[nodiscard]] bool ready() const;
// Returns frame position, if any frame was marked as displayed.
crl::time markFrameDisplayed(crl::time now);
crl::time markFrameShown();
2019-04-27 09:12:53 +00:00
2019-05-28 11:39:38 +00:00
void checkStep();
2019-04-27 09:12:53 +00:00
private:
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-05-28 11:39:38 +00:00
void checkNextFrameAvailability();
void checkNextFrameRender();
//crl::time _started = 0;
//PlaybackOptions _options;
2019-04-27 09:12:53 +00:00
base::Timer _timer;
2019-05-28 11:39:38 +00:00
crl::time _nextFrameTime = kTimeUnknown;
SharedState *_state = nullptr;
std::shared_ptr<FrameRenderer> _renderer;
rpl::event_stream<Update, Error> _updates;
rpl::lifetime _lifetime;
2019-04-27 09:12:53 +00:00
};
} // namespace Lottie