2022-01-06 22:15:29 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
//
|
|
|
|
// EmulationStation Desktop Edition
|
|
|
|
// LottieComponent.h
|
|
|
|
//
|
|
|
|
// Component to play Lottie animations using the rlottie library.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef ES_CORE_COMPONENTS_LOTTIE_COMPONENT_H
|
|
|
|
#define ES_CORE_COMPONENTS_LOTTIE_COMPONENT_H
|
|
|
|
|
|
|
|
#include "GuiComponent.h"
|
|
|
|
#include "renderers/Renderer.h"
|
|
|
|
#include "resources/TextureResource.h"
|
2022-01-08 14:04:10 +00:00
|
|
|
#include "utils/MathUtil.h"
|
2022-01-06 22:15:29 +00:00
|
|
|
|
|
|
|
#include "rlottie.h"
|
|
|
|
|
|
|
|
#include <chrono>
|
2022-01-07 18:09:07 +00:00
|
|
|
#include <future>
|
2022-01-08 14:04:10 +00:00
|
|
|
#include <unordered_map>
|
2022-01-06 22:15:29 +00:00
|
|
|
|
|
|
|
class LottieComponent : public GuiComponent
|
|
|
|
{
|
|
|
|
public:
|
2022-01-19 17:01:54 +00:00
|
|
|
LottieComponent();
|
2022-01-08 14:04:10 +00:00
|
|
|
~LottieComponent();
|
2022-01-06 22:15:29 +00:00
|
|
|
|
2022-01-08 10:25:29 +00:00
|
|
|
void setAnimation(const std::string& path);
|
|
|
|
void setKeepAspectRatio(bool value) { mKeepAspectRatio = value; }
|
2022-01-08 14:04:10 +00:00
|
|
|
void setFrameCaching(bool value) { mCacheFrames = value; }
|
|
|
|
void setMaxCacheSize(int value)
|
|
|
|
{
|
|
|
|
mMaxCacheSize = static_cast<size_t>(glm::clamp(value, 0, 1024) * 1024 * 1024);
|
|
|
|
}
|
2022-01-08 10:25:29 +00:00
|
|
|
|
2022-01-09 17:17:23 +00:00
|
|
|
void resetFileAnimation() override;
|
2022-01-08 10:25:29 +00:00
|
|
|
void onSizeChanged() override;
|
|
|
|
|
2022-01-06 22:15:29 +00:00
|
|
|
virtual void applyTheme(const std::shared_ptr<ThemeData>& theme,
|
|
|
|
const std::string& view,
|
|
|
|
const std::string& element,
|
|
|
|
unsigned int properties) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void update(int deltaTime) override;
|
|
|
|
void render(const glm::mat4& parentTrans) override;
|
|
|
|
|
|
|
|
std::shared_ptr<TextureResource> mTexture;
|
|
|
|
std::vector<uint8_t> mPictureRGBA;
|
2022-01-08 14:04:10 +00:00
|
|
|
std::unordered_map<size_t, std::vector<uint8_t>> mFrameCache;
|
|
|
|
// Set a 1024 MiB total Lottie animation cache as default.
|
2022-01-29 17:41:22 +00:00
|
|
|
static inline size_t mMaxTotalFrameCache = 1024 * 1024 * 1024;
|
|
|
|
static inline size_t mTotalFrameCache;
|
2022-01-08 14:04:10 +00:00
|
|
|
bool mCacheFrames;
|
|
|
|
size_t mMaxCacheSize;
|
|
|
|
size_t mCacheSize;
|
|
|
|
size_t mFrameSize;
|
2022-01-06 22:15:29 +00:00
|
|
|
|
2022-01-09 17:17:23 +00:00
|
|
|
std::chrono::time_point<std::chrono::system_clock> mAnimationStartTime;
|
2022-01-07 18:09:07 +00:00
|
|
|
std::unique_ptr<rlottie::Animation> mAnimation;
|
2022-01-06 22:15:29 +00:00
|
|
|
std::unique_ptr<rlottie::Surface> mSurface;
|
2022-01-07 18:09:07 +00:00
|
|
|
std::future<rlottie::Surface> mFuture;
|
2022-01-08 10:25:29 +00:00
|
|
|
std::string mPath;
|
2022-01-09 17:17:23 +00:00
|
|
|
std::string mStartDirection;
|
|
|
|
std::string mDirection;
|
2022-01-06 22:15:29 +00:00
|
|
|
size_t mTotalFrames;
|
2022-01-07 18:09:07 +00:00
|
|
|
size_t mFrameNum;
|
2022-01-09 17:17:23 +00:00
|
|
|
|
2022-01-06 22:15:29 +00:00
|
|
|
double mFrameRate;
|
2022-01-09 17:17:23 +00:00
|
|
|
float mSpeedModifier;
|
2022-01-06 22:15:29 +00:00
|
|
|
int mTargetPacing;
|
2022-01-07 18:09:07 +00:00
|
|
|
int mTimeAccumulator;
|
2022-01-10 16:42:01 +00:00
|
|
|
int mLastRenderedFrame;
|
2022-01-09 17:17:23 +00:00
|
|
|
int mSkippedFrames;
|
2022-01-09 12:43:42 +00:00
|
|
|
|
2022-01-09 17:17:23 +00:00
|
|
|
bool mHoldFrame;
|
2022-01-09 12:43:42 +00:00
|
|
|
bool mPause;
|
2022-01-09 17:17:23 +00:00
|
|
|
bool mAlternate;
|
2022-01-08 10:25:29 +00:00
|
|
|
bool mKeepAspectRatio;
|
2022-01-06 22:15:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // ES_CORE_COMPONENTS_LOTTIE_COMPONENT_H
|