Skip to content

Commit 713ff7f

Browse files
committed
added LottieBigSize for performance measurement
1 parent 2cb87cd commit 713ff7f

3 files changed

Lines changed: 88 additions & 0 deletions

File tree

res/lottie/extensions/bigsize.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

src/LottieBigSize.cpp

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* Copyright (c) 2026 ThorVG project. All rights reserved.
3+
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
13+
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*/
22+
23+
#include "Example.h"
24+
25+
/************************************************************************/
26+
/* ThorVG Drawing Contents */
27+
/************************************************************************/
28+
29+
struct UserExample : tvgexam::Example
30+
{
31+
unique_ptr<tvg::Animation> animation;
32+
33+
bool content(tvg::Canvas* canvas, uint32_t w, uint32_t h) override
34+
{
35+
//The default font for fallback in case
36+
tvg::Text::load(EXAMPLE_DIR"/font/PublicSans-Regular.ttf");
37+
38+
//Animation Controller
39+
animation = unique_ptr<tvg::Animation>(tvg::Animation::gen());
40+
auto picture = animation->picture();
41+
picture->origin(0.5f, 0.5f); //center origin
42+
43+
//Background
44+
auto shape = tvg::Shape::gen();
45+
shape->appendRect(0, 0, w, h);
46+
shape->fill(50, 50, 50);
47+
48+
canvas->add(shape);
49+
50+
if (!tvgexam::verify(picture->load(EXAMPLE_DIR"/lottie/extensions/bigsize.json"))) return false;
51+
52+
//image scaling preserving its aspect ratio
53+
float w2, h2;
54+
picture->size(&w2, &h2);
55+
auto scale = (w2 > h2) ? w / w2 : h / h2;
56+
picture->scale(scale);
57+
picture->translate(float(w) * 0.5f, float(h) * 0.5f);
58+
59+
canvas->add(picture);
60+
61+
return true;
62+
}
63+
64+
bool update(tvg::Canvas* canvas, uint32_t elapsed) override
65+
{
66+
auto progress = tvgexam::progress(elapsed, animation->duration());
67+
68+
//Update animation frame only when it's changed
69+
if (animation->frame(animation->totalFrame() * progress) == tvg::Result(0)) {
70+
canvas->update();
71+
return true;
72+
}
73+
74+
return false;
75+
}
76+
};
77+
78+
79+
/************************************************************************/
80+
/* Entry Point */
81+
/************************************************************************/
82+
83+
int main(int argc, char **argv)
84+
{
85+
return tvgexam::main(new UserExample, argc, argv, false, 1280, 1280, 4, true);
86+
}

src/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ if cc.links(lottie_example, dependencies : thorvg_dep, include_directories : tho
101101
'LottieExpressions.cpp',
102102
'LottieExtension.cpp',
103103
'LottieInteraction.cpp',
104+
'LottieBigSize.cpp',
104105
'LottieTweening.cpp'
105106
]
106107
message('ThorVG Lottie found. Enabled Lottie examples.')

0 commit comments

Comments
 (0)