MCPcopy Create free account
hub / github.com/Tencent/libpag / CompareFileFrames

Function CompareFileFrames

test/src/PAGCompareFrameTest.cpp:46–146  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

44};
45
46static void CompareFileFrames(Semaphore* semaphore, std::string pagPath) {
47 Clock fileClock = {};
48 auto fileName = pagPath.substr(pagPath.rfind('/') + 1, pagPath.size());
49 auto pagFile = PAGFile::Load(pagPath);
50 ASSERT_NE(pagFile, nullptr);
51 auto width = static_cast<float>(pagFile->width());
52 auto height = static_cast<float>(pagFile->height());
53 if (std::max(width, height) > MAX_FRAME_SIZE) {
54 if (width > height) {
55 height = static_cast<int>(
56 ceilf(static_cast<float>(height) * MAX_FRAME_SIZE / static_cast<float>(width)));
57 width = MAX_FRAME_SIZE;
58 } else {
59 width = static_cast<int>(
60 ceilf(static_cast<float>(width) * MAX_FRAME_SIZE / static_cast<float>(height)));
61 height = MAX_FRAME_SIZE;
62 }
63 }
64 auto pagSurface =
65 OffscreenSurface::Make(static_cast<int>(roundf(width)), static_cast<int>(roundf(height)));
66 ASSERT_NE(pagSurface, nullptr);
67 auto pagPlayer = std::make_shared<PAGPlayer>();
68 pagPlayer->setSurface(pagSurface);
69 pagPlayer->setComposition(pagFile);
70 Frame totalFrames = TimeToFrame(pagFile->duration(), pagFile->frameRate());
71 Frame currentFrame = 0;
72 std::string errorMsg;
73 std::map<Frame, RenderCost> performanceMap = {};
74
75 Bitmap currentSnapshot = {};
76 std::shared_ptr<Task> lastTask = nullptr;
77 Frame lastFrame = 0;
78 bool lastResult = false;
79
80 auto CompareFrame = [&](Frame currentFrame) {
81 if (lastTask == nullptr) {
82 return;
83 }
84 Clock clock = {};
85 lastTask->wait();
86 auto compareCost = clock.measure();
87 if (currentFrame == lastFrame) {
88 auto& cost = performanceMap[currentFrame];
89 cost.compareCost = compareCost;
90 cost.totalTime += compareCost;
91 }
92 if (!lastResult) {
93 errorMsg += (std::to_string(currentFrame) + ";");
94 }
95 lastTask = nullptr;
96 };
97
98 while (currentFrame < totalFrames) {
99 auto changed = pagPlayer->flush();
100 if (changed) {
101 RenderCost cost = {};
102 Clock clock = {};
103 currentSnapshot = MakeSnapshot(pagSurface);

Callers

nothing calls this directly

Calls 15

ToStringFunction · 0.85
sizeMethod · 0.80
getPerformanceStringMethod · 0.80
signalMethod · 0.80
MakeFunction · 0.50
TimeToFrameFunction · 0.50
MakeSnapshotFunction · 0.50
widthMethod · 0.45
heightMethod · 0.45
setSurfaceMethod · 0.45
setCompositionMethod · 0.45
durationMethod · 0.45

Tested by

no test coverage detected