mirror of
https://github.com/vale981/tdesktop
synced 2025-03-09 12:36:39 -04:00
135 lines
3.2 KiB
C++
135 lines
3.2 KiB
C++
/*
|
|
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/weak_ptr.h"
|
|
#include "lottie/lottie_common.h"
|
|
|
|
#include <QImage>
|
|
#include <QSize>
|
|
#include <crl/crl_time.h>
|
|
#include <crl/crl_object_on_queue.h>
|
|
#include <limits>
|
|
|
|
namespace rlottie {
|
|
class Animation;
|
|
} // namespace rlottie
|
|
|
|
namespace Storage {
|
|
namespace Cache {
|
|
class Database;
|
|
struct Key;
|
|
} // namespace Cache
|
|
} // namespace Storage
|
|
|
|
namespace Lottie {
|
|
|
|
inline constexpr auto kMaxFrameRate = 120;
|
|
inline constexpr auto kMaxSize = 3096;
|
|
inline constexpr auto kMaxFramesCount = 600;
|
|
|
|
class Animation;
|
|
class CacheState;
|
|
|
|
struct Frame {
|
|
QImage original;
|
|
crl::time position = kTimeUnknown;
|
|
crl::time displayed = kTimeUnknown;
|
|
crl::time display = kTimeUnknown;
|
|
|
|
FrameRequest request;
|
|
QImage prepared;
|
|
};
|
|
|
|
QImage PrepareFrameByRequest(
|
|
not_null<Frame*> frame,
|
|
bool useExistingPrepared);
|
|
|
|
class SharedState {
|
|
public:
|
|
explicit SharedState(std::unique_ptr<rlottie::Animation> animation);
|
|
SharedState(
|
|
const QByteArray &content,
|
|
std::unique_ptr<rlottie::Animation> animation,
|
|
CacheState &&state,
|
|
not_null<Storage::Cache::Database*> cache,
|
|
Storage::Cache::Key key,
|
|
const FrameRequest &request);
|
|
|
|
void start(not_null<Animation*> owner, crl::time now);
|
|
|
|
[[nodiscard]] Information information() const;
|
|
[[nodiscard]] bool initialized() const;
|
|
|
|
[[nodiscard]] not_null<Frame*> frameForPaint();
|
|
[[nodiscard]] crl::time nextFrameDisplayTime() const;
|
|
crl::time markFrameDisplayed(crl::time now);
|
|
crl::time markFrameShown();
|
|
|
|
void renderFrame(QImage &image, const FrameRequest &request, int index);
|
|
[[nodiscard]] bool renderNextFrame(const FrameRequest &request);
|
|
|
|
~SharedState();
|
|
|
|
private:
|
|
struct Cache;
|
|
|
|
void construct(const FrameRequest &request);
|
|
void calculateProperties();
|
|
bool isValid() const;
|
|
void init(QImage cover, const FrameRequest &request);
|
|
void renderNextFrame(
|
|
not_null<Frame*> frame,
|
|
const FrameRequest &request);
|
|
[[nodiscard]] not_null<Frame*> getFrame(int index);
|
|
[[nodiscard]] not_null<const Frame*> getFrame(int index) const;
|
|
[[nodiscard]] int counter() const;
|
|
|
|
QByteArray _content;
|
|
std::unique_ptr<rlottie::Animation> _animation;
|
|
|
|
static constexpr auto kCounterUninitialized = -1;
|
|
std::atomic<int> _counter = kCounterUninitialized;
|
|
|
|
static constexpr auto kFramesCount = 4;
|
|
std::array<Frame, kFramesCount> _frames;
|
|
|
|
base::weak_ptr<Animation> _owner;
|
|
crl::time _started = kTimeUnknown;
|
|
crl::time _duration = kTimeUnknown;
|
|
int _frameIndex = 0;
|
|
int _framesCount = 0;
|
|
int _frameRate = 0;
|
|
QSize _size;
|
|
std::atomic<int> _accumulatedDelayMs = 0;
|
|
|
|
std::unique_ptr<Cache> _cache;
|
|
|
|
};
|
|
|
|
class FrameRendererObject;
|
|
|
|
class FrameRenderer final {
|
|
public:
|
|
static std::shared_ptr<FrameRenderer> Instance();
|
|
|
|
void append(std::unique_ptr<SharedState> entry);
|
|
void updateFrameRequest(
|
|
not_null<SharedState*> entry,
|
|
const FrameRequest &request);
|
|
void frameShown(not_null<SharedState*> entry);
|
|
void remove(not_null<SharedState*> state);
|
|
|
|
private:
|
|
using Implementation = FrameRendererObject;
|
|
crl::object_on_queue<Implementation> _wrapped;
|
|
|
|
};
|
|
|
|
} // namespace Lottie
|