Skip to content

Commit

Permalink
Limit animated emoji to 30 FPS.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Jul 25, 2022
1 parent 3017082 commit c453766
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lottie/lottie_emoji.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ EmojiGenerator::EmojiGenerator(const QByteArray &bytes)
std::string(),
false)) {
if (_rlottie) {
const auto rate = _rlottie->frameRate();
_multiplier = (rate == 60) ? 2 : 1;
auto width = size_t();
auto height = size_t();
_rlottie->size(width, height);
_size = QSize(width, height);
_framesCount = _rlottie->totalFrame();
const auto rate = _rlottie->frameRate();
_frameDuration = (rate > 0) ? (1000 / rate) : 0;
_framesCount = _rlottie->totalFrame() / _multiplier;
_frameDuration = (rate > 0) ? (1000 * _multiplier / rate) : 0;
}
if (!_framesCount || !_frameDuration || _size.isEmpty()) {
_rlottie = nullptr;
Expand Down Expand Up @@ -67,7 +68,7 @@ EmojiGenerator::Frame EmojiGenerator::renderNext(
render.width(),
render.height(),
storage.bytesPerLine());
_rlottie->renderSync(index, std::move(surface));
_rlottie->renderSync(index * _multiplier, std::move(surface));
return {
.image = std::move(storage),
.duration = _frameDuration,
Expand Down
1 change: 1 addition & 0 deletions lottie/lottie_emoji.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class EmojiGenerator final : public Ui::FrameGenerator {
private:
std::unique_ptr<rlottie::Animation> _rlottie;
QSize _size;
int _multiplier = 1;
int _frameDuration = 0;
int _framesCount = 0;
int _frameIndex = 0;
Expand Down

0 comments on commit c453766

Please sign in to comment.