Visitar URL original
Support wide gamut colors in gradient_generator's CreateGradientTexture by b-luk · Pull Request #191980 · flutter/flutter · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
gemini comments
  • Loading branch information
b-luk committed Aug 31, 2026
commit 3ad71dc9ff35cbf25625a0b1208215f6dc4733ec
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ namespace {

std::vector<uint8_t> ToR32G32B32A32FloatBytes(
const std::vector<Color>& colors) {
static_assert(sizeof(Color) == sizeof(float) * 4,
"Color must be exactly 4 floats with no padding.");
static_assert(std::is_standard_layout_v<Color>,
"Color must be standard layout.");
// `Color` is a standard-layout struct of 4 contiguous 32-bit floats (RGBA),
// directly matching the `kR32G32B32A32Float` pixel format layout.
const auto* bytes = reinterpret_cast<const uint8_t*>(colors.data());
Expand Down
5 changes: 3 additions & 2 deletions engine/src/flutter/impeller/geometry/color.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,9 @@ struct Color {
/// @brief Returns true if any color channel lies outside the standard
/// [0.0, 1.0] sRGB gamut.
constexpr bool IsWideGamut() const {
return red < 0.0f || red > 1.0f || green < 0.0f || green > 1.0f ||
blue < 0.0f || blue > 1.0f;
return red < -kEhCloseEnough || red > 1.0f + kEhCloseEnough ||
green < -kEhCloseEnough || green > 1.0f + kEhCloseEnough ||
blue < -kEhCloseEnough || blue > 1.0f + kEhCloseEnough;
}
Comment thread
b-luk marked this conversation as resolved.
Resolved

/**
Expand Down
11 changes: 3 additions & 8 deletions engine/src/flutter/impeller/geometry/gradient.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,12 @@ GradientData CreateGradientBuffer(const std::vector<Color>& colors,
}
texture_size = static_cast<uint32_t>(std::round(1.0 / minimum_delta)) + 1;
}
GradientData result = {
.colors = {},
};
result.colors.reserve(texture_size);

GradientData result;
if (texture_size == colors.size() &&
colors.size() <= kMaxGradientTextureSize) {
for (auto i = 0u; i < colors.size(); i++) {
result.colors.push_back(colors[i]);
}
result.colors = colors;
} else {
result.colors.reserve(texture_size);
Color previous_color = colors[0];
auto previous_stop = 0.0;
auto previous_color_index = 0;
Expand Down