Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[Impeller] Fix golden flake due to rand use. #50743

Merged
merged 2 commits into from
Feb 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions impeller/aiks/aiks_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -798,12 +798,12 @@ TEST_P(AiksTest, CanRenderTextFrameSTB) {
}

TEST_P(AiksTest, TextFrameSubpixelAlignment) {
std::array<Scalar, 20> phase_offsets;
for (Scalar& offset : phase_offsets) {
auto rand = std::rand(); // NOLINT
offset = (static_cast<float>(rand) / static_cast<float>(RAND_MAX)) * k2Pi;
}

// "Random" numbers between 0 and 1. Hardcoded to avoid flakiness in goldens.
std::array<Scalar, 20> phase_offsets = {
7.82637e-06, 0.131538, 0.755605, 0.45865, 0.532767,
0.218959, 0.0470446, 0.678865, 0.679296, 0.934693,
0.383502, 0.519416, 0.830965, 0.0345721, 0.0534616,
0.5297, 0.671149, 0.00769819, 0.383416, 0.0668422};
auto callback = [&](AiksContext& renderer) -> std::optional<Picture> {
static float font_size = 20;
static float phase_variation = 0.2;
Expand All @@ -822,11 +822,12 @@ TEST_P(AiksTest, TextFrameSubpixelAlignment) {
canvas.Scale(GetContentScale());

for (size_t i = 0; i < phase_offsets.size(); i++) {
auto position = Point(
200 + magnitude * std::sin((-phase_offsets[i] * phase_variation +
GetSecondsElapsed() * speed)), //
200 + i * font_size * 1.1 //
);
auto position =
Point(200 + magnitude *
std::sin((-phase_offsets[i] * k2Pi * phase_variation +
GetSecondsElapsed() * speed)), //
200 + i * font_size * 1.1 //
);
if (!RenderTextInCanvasSkia(
GetContext(), canvas,
"the quick brown fox jumped over "
Expand Down