-
Notifications
You must be signed in to change notification settings - Fork 6k
Framework wide color linear gradients #54748
Changes from 6 commits
408f549
fc754cf
d9c6a96
976963c
5c0887f
0419148
66b244e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,12 +24,12 @@ void CanvasGradient::Create(Dart_Handle wrapper) { | |
| } | ||
|
|
||
| void CanvasGradient::initLinear(const tonic::Float32List& end_points, | ||
| const tonic::Int32List& colors, | ||
| const tonic::Float32List& colors, | ||
| const tonic::Float32List& color_stops, | ||
| DlTileMode tile_mode, | ||
| const tonic::Float64List& matrix4) { | ||
| FML_DCHECK(end_points.num_elements() == 4); | ||
| FML_DCHECK(colors.num_elements() == color_stops.num_elements() || | ||
| FML_DCHECK(colors.num_elements() == (color_stops.num_elements() * 4) || | ||
| color_stops.data() == nullptr); | ||
|
|
||
| static_assert(sizeof(SkPoint) == sizeof(float) * 2, | ||
|
|
@@ -46,14 +46,17 @@ void CanvasGradient::initLinear(const tonic::Float32List& end_points, | |
| SkPoint p0 = SkPoint::Make(end_points[0], end_points[1]); | ||
| SkPoint p1 = SkPoint::Make(end_points[2], end_points[3]); | ||
| std::vector<DlColor> dl_colors; | ||
| dl_colors.reserve(colors.num_elements()); | ||
| for (int i = 0; i < colors.num_elements(); ++i) { | ||
| /// TODO(gaaclarke): Make this preserve wide gamut colors. | ||
| dl_colors.emplace_back(DlColor(colors[i])); | ||
| dl_colors.reserve(color_stops.num_elements()); | ||
|
||
| for (int i = 0; i < colors.num_elements(); i += 4) { | ||
| DlScalar a = colors[i + 0]; | ||
| DlScalar r = colors[i + 1]; | ||
| DlScalar g = colors[i + 2]; | ||
| DlScalar b = colors[i + 3]; | ||
| dl_colors.emplace_back(DlColor(a, r, g, b, DlColorSpace::kExtendedSRGB)); | ||
| } | ||
|
|
||
| dl_shader_ = DlColorSource::MakeLinear( | ||
| p0, p1, colors.num_elements(), dl_colors.data(), color_stops.data(), | ||
| p0, p1, colors.num_elements() / 4, dl_colors.data(), color_stops.data(), | ||
| tile_mode, has_matrix ? &sk_matrix : nullptr); | ||
| // Just a sanity check, all gradient shaders should be thread-safe | ||
| FML_DCHECK(dl_shader_->isUIThreadSafe()); | ||
|
|
@@ -62,11 +65,11 @@ void CanvasGradient::initLinear(const tonic::Float32List& end_points, | |
| void CanvasGradient::initRadial(double center_x, | ||
| double center_y, | ||
| double radius, | ||
| const tonic::Int32List& colors, | ||
| const tonic::Float32List& colors, | ||
| const tonic::Float32List& color_stops, | ||
| DlTileMode tile_mode, | ||
| const tonic::Float64List& matrix4) { | ||
| FML_DCHECK(colors.num_elements() == color_stops.num_elements() || | ||
| FML_DCHECK(colors.num_elements() == (color_stops.num_elements() * 4) || | ||
| color_stops.data() == nullptr); | ||
|
|
||
| static_assert(sizeof(SkColor) == sizeof(int32_t), | ||
|
|
@@ -80,27 +83,31 @@ void CanvasGradient::initRadial(double center_x, | |
|
|
||
| std::vector<DlColor> dl_colors; | ||
| dl_colors.reserve(colors.num_elements()); | ||
| for (int i = 0; i < colors.num_elements(); ++i) { | ||
| dl_colors.emplace_back(DlColor(colors[i])); | ||
| for (int i = 0; i < colors.num_elements(); i += 4) { | ||
| DlScalar a = colors[i + 0]; | ||
| DlScalar r = colors[i + 1]; | ||
| DlScalar g = colors[i + 2]; | ||
| DlScalar b = colors[i + 3]; | ||
| dl_colors.emplace_back(DlColor(a, r, g, b, DlColorSpace::kExtendedSRGB)); | ||
| } | ||
|
|
||
| dl_shader_ = DlColorSource::MakeRadial( | ||
| SkPoint::Make(SafeNarrow(center_x), SafeNarrow(center_y)), | ||
| SafeNarrow(radius), colors.num_elements(), dl_colors.data(), | ||
| SafeNarrow(radius), colors.num_elements() / 4, dl_colors.data(), | ||
| color_stops.data(), tile_mode, has_matrix ? &sk_matrix : nullptr); | ||
| // Just a sanity check, all gradient shaders should be thread-safe | ||
| FML_DCHECK(dl_shader_->isUIThreadSafe()); | ||
| } | ||
|
|
||
| void CanvasGradient::initSweep(double center_x, | ||
| double center_y, | ||
| const tonic::Int32List& colors, | ||
| const tonic::Float32List& colors, | ||
| const tonic::Float32List& color_stops, | ||
| DlTileMode tile_mode, | ||
| double start_angle, | ||
| double end_angle, | ||
| const tonic::Float64List& matrix4) { | ||
| FML_DCHECK(colors.num_elements() == color_stops.num_elements() || | ||
| FML_DCHECK(colors.num_elements() == (color_stops.num_elements() * 4) || | ||
| color_stops.data() == nullptr); | ||
|
|
||
| static_assert(sizeof(SkColor) == sizeof(int32_t), | ||
|
|
@@ -114,16 +121,20 @@ void CanvasGradient::initSweep(double center_x, | |
|
|
||
| std::vector<DlColor> dl_colors; | ||
| dl_colors.reserve(colors.num_elements()); | ||
| for (int i = 0; i < colors.num_elements(); ++i) { | ||
| dl_colors.emplace_back(DlColor(colors[i])); | ||
| for (int i = 0; i < colors.num_elements(); i += 4) { | ||
| DlScalar a = colors[i + 0]; | ||
| DlScalar r = colors[i + 1]; | ||
| DlScalar g = colors[i + 2]; | ||
| DlScalar b = colors[i + 3]; | ||
| dl_colors.emplace_back(DlColor(a, r, g, b, DlColorSpace::kExtendedSRGB)); | ||
| } | ||
|
|
||
| dl_shader_ = DlColorSource::MakeSweep( | ||
| SkPoint::Make(SafeNarrow(center_x), SafeNarrow(center_y)), | ||
| SafeNarrow(start_angle) * 180.0f / static_cast<float>(M_PI), | ||
| SafeNarrow(end_angle) * 180.0f / static_cast<float>(M_PI), | ||
| colors.num_elements(), dl_colors.data(), color_stops.data(), tile_mode, | ||
| has_matrix ? &sk_matrix : nullptr); | ||
| colors.num_elements() / 4, dl_colors.data(), color_stops.data(), | ||
| tile_mode, has_matrix ? &sk_matrix : nullptr); | ||
| // Just a sanity check, all gradient shaders should be thread-safe | ||
| FML_DCHECK(dl_shader_->isUIThreadSafe()); | ||
| } | ||
|
|
@@ -134,11 +145,11 @@ void CanvasGradient::initTwoPointConical(double start_x, | |
| double end_x, | ||
| double end_y, | ||
| double end_radius, | ||
| const tonic::Int32List& colors, | ||
| const tonic::Float32List& colors, | ||
| const tonic::Float32List& color_stops, | ||
| DlTileMode tile_mode, | ||
| const tonic::Float64List& matrix4) { | ||
| FML_DCHECK(colors.num_elements() == color_stops.num_elements() || | ||
| FML_DCHECK(colors.num_elements() == (color_stops.num_elements() * 4) || | ||
| color_stops.data() == nullptr); | ||
|
|
||
| static_assert(sizeof(SkColor) == sizeof(int32_t), | ||
|
|
@@ -152,15 +163,19 @@ void CanvasGradient::initTwoPointConical(double start_x, | |
|
|
||
| std::vector<DlColor> dl_colors; | ||
| dl_colors.reserve(colors.num_elements()); | ||
| for (int i = 0; i < colors.num_elements(); ++i) { | ||
| dl_colors.emplace_back(DlColor(colors[i])); | ||
| for (int i = 0; i < colors.num_elements(); i += 4) { | ||
| DlScalar a = colors[i + 0]; | ||
| DlScalar r = colors[i + 1]; | ||
| DlScalar g = colors[i + 2]; | ||
| DlScalar b = colors[i + 3]; | ||
| dl_colors.emplace_back(DlColor(a, r, g, b, DlColorSpace::kExtendedSRGB)); | ||
| } | ||
|
|
||
| dl_shader_ = DlColorSource::MakeConical( | ||
| SkPoint::Make(SafeNarrow(start_x), SafeNarrow(start_y)), | ||
| SafeNarrow(start_radius), | ||
| SkPoint::Make(SafeNarrow(end_x), SafeNarrow(end_y)), | ||
| SafeNarrow(end_radius), colors.num_elements(), dl_colors.data(), | ||
| SafeNarrow(end_radius), colors.num_elements() / 4, dl_colors.data(), | ||
| color_stops.data(), tile_mode, has_matrix ? &sk_matrix : nullptr); | ||
| // Just a sanity check, all gradient shaders should be thread-safe | ||
| FML_DCHECK(dl_shader_->isUIThreadSafe()); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember talking about preserving the CS, but I'm guessing that gradients are going to want to normalize to a similar CS for lerping - and extendedSRGB is probably the best for fractional combinations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do preserve the colorspace from the users perspective. The conversion to extended srgb only happens when communicating the values to the engine.