Removed heap allocations for conical, radial and sweep gradients (flutter/engine#57143)
fixes https://github.com/flutter/flutter/issues/154650 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I added new tests to check the change I am making or feature I am adding, or the PR is [test-exempt]. See [testing the engine] for instructions on writing and running engine tests. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I signed the [CLA]. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/master/docs/contributing/Style-guide-for-Flutter-repo.md [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style [testing the engine]: https://github.com/flutter/engine/blob/main/docs/testing/Testing-the-engine.md [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/master/docs/contributing/Chat.md
This commit is contained in:
@@ -6,24 +6,6 @@
|
||||
|
||||
namespace flutter {
|
||||
|
||||
DlConicalGradientColorSource::DlConicalGradientColorSource(
|
||||
DlPoint start_center,
|
||||
DlScalar start_radius,
|
||||
DlPoint end_center,
|
||||
DlScalar end_radius,
|
||||
uint32_t stop_count,
|
||||
const DlColor* colors,
|
||||
const float* stops,
|
||||
DlTileMode tile_mode,
|
||||
const DlMatrix* matrix)
|
||||
: DlGradientColorSourceBase(stop_count, tile_mode, matrix),
|
||||
start_center_(start_center),
|
||||
start_radius_(start_radius),
|
||||
end_center_(end_center),
|
||||
end_radius_(end_radius) {
|
||||
store_color_stops(this + 1, colors, stops);
|
||||
}
|
||||
|
||||
DlConicalGradientColorSource::DlConicalGradientColorSource(
|
||||
const DlConicalGradientColorSource* source)
|
||||
: DlGradientColorSourceBase(source->stop_count(),
|
||||
|
||||
@@ -35,15 +35,23 @@ class DlConicalGradientColorSource final : public DlGradientColorSourceBase {
|
||||
bool equals_(DlColorSource const& other) const override;
|
||||
|
||||
private:
|
||||
template <typename Colors>
|
||||
DlConicalGradientColorSource(DlPoint start_center,
|
||||
DlScalar start_radius,
|
||||
DlPoint end_center,
|
||||
DlScalar end_radius,
|
||||
uint32_t stop_count,
|
||||
const DlColor* colors,
|
||||
Colors colors,
|
||||
const float* stops,
|
||||
DlTileMode tile_mode,
|
||||
const DlMatrix* matrix = nullptr);
|
||||
const DlMatrix* matrix = nullptr)
|
||||
: DlGradientColorSourceBase(stop_count, tile_mode, matrix),
|
||||
start_center_(start_center),
|
||||
start_radius_(start_radius),
|
||||
end_center_(end_center),
|
||||
end_radius_(end_radius) {
|
||||
store_color_stops(this + 1, colors, stops);
|
||||
}
|
||||
|
||||
explicit DlConicalGradientColorSource(
|
||||
const DlConicalGradientColorSource* source);
|
||||
|
||||
@@ -6,34 +6,6 @@
|
||||
|
||||
namespace flutter {
|
||||
|
||||
DlLinearGradientColorSource::DlLinearGradientColorSource(
|
||||
const DlPoint start_point,
|
||||
const DlPoint end_point,
|
||||
uint32_t stop_count,
|
||||
const DlColor* colors,
|
||||
const float* stops,
|
||||
DlTileMode tile_mode,
|
||||
const DlMatrix* matrix)
|
||||
: DlGradientColorSourceBase(stop_count, tile_mode, matrix),
|
||||
start_point_(start_point),
|
||||
end_point_(end_point) {
|
||||
store_color_stops(this + 1, colors, stops);
|
||||
}
|
||||
|
||||
DlLinearGradientColorSource::DlLinearGradientColorSource(
|
||||
const DlPoint start_point,
|
||||
const DlPoint end_point,
|
||||
uint32_t stop_count,
|
||||
const DlScalar* colors,
|
||||
const float* stops,
|
||||
DlTileMode tile_mode,
|
||||
const DlMatrix* matrix)
|
||||
: DlGradientColorSourceBase(stop_count, tile_mode, matrix),
|
||||
start_point_(start_point),
|
||||
end_point_(end_point) {
|
||||
store_color_stops(this + 1, colors, stops);
|
||||
}
|
||||
|
||||
DlLinearGradientColorSource::DlLinearGradientColorSource(
|
||||
const DlLinearGradientColorSource* source)
|
||||
: DlGradientColorSourceBase(source->stop_count(),
|
||||
|
||||
@@ -33,21 +33,19 @@ class DlLinearGradientColorSource final : public DlGradientColorSourceBase {
|
||||
bool equals_(DlColorSource const& other) const override;
|
||||
|
||||
private:
|
||||
template <typename Colors>
|
||||
DlLinearGradientColorSource(const DlPoint start_point,
|
||||
const DlPoint end_point,
|
||||
uint32_t stop_count,
|
||||
const DlColor* colors,
|
||||
Colors colors,
|
||||
const float* stops,
|
||||
DlTileMode tile_mode,
|
||||
const DlMatrix* matrix = nullptr);
|
||||
|
||||
DlLinearGradientColorSource(const DlPoint start_point,
|
||||
const DlPoint end_point,
|
||||
uint32_t stop_count,
|
||||
const DlScalar* colors,
|
||||
const float* stops,
|
||||
DlTileMode tile_mode,
|
||||
const DlMatrix* matrix = nullptr);
|
||||
const DlMatrix* matrix = nullptr)
|
||||
: DlGradientColorSourceBase(stop_count, tile_mode, matrix),
|
||||
start_point_(start_point),
|
||||
end_point_(end_point) {
|
||||
store_color_stops(this + 1, colors, stops);
|
||||
}
|
||||
|
||||
explicit DlLinearGradientColorSource(
|
||||
const DlLinearGradientColorSource* source);
|
||||
|
||||
@@ -6,19 +6,6 @@
|
||||
|
||||
namespace flutter {
|
||||
|
||||
DlRadialGradientColorSource::DlRadialGradientColorSource(DlPoint center,
|
||||
DlScalar radius,
|
||||
uint32_t stop_count,
|
||||
const DlColor* colors,
|
||||
const float* stops,
|
||||
DlTileMode tile_mode,
|
||||
const DlMatrix* matrix)
|
||||
: DlGradientColorSourceBase(stop_count, tile_mode, matrix),
|
||||
center_(center),
|
||||
radius_(radius) {
|
||||
store_color_stops(this + 1, colors, stops);
|
||||
}
|
||||
|
||||
DlRadialGradientColorSource::DlRadialGradientColorSource(
|
||||
const DlRadialGradientColorSource* source)
|
||||
: DlGradientColorSourceBase(source->stop_count(),
|
||||
|
||||
@@ -33,13 +33,19 @@ class DlRadialGradientColorSource final : public DlGradientColorSourceBase {
|
||||
bool equals_(DlColorSource const& other) const override;
|
||||
|
||||
private:
|
||||
template <typename Colors>
|
||||
DlRadialGradientColorSource(DlPoint center,
|
||||
DlScalar radius,
|
||||
uint32_t stop_count,
|
||||
const DlColor* colors,
|
||||
Colors colors,
|
||||
const float* stops,
|
||||
DlTileMode tile_mode,
|
||||
const DlMatrix* matrix = nullptr);
|
||||
const DlMatrix* matrix = nullptr)
|
||||
: DlGradientColorSourceBase(stop_count, tile_mode, matrix),
|
||||
center_(center),
|
||||
radius_(radius) {
|
||||
store_color_stops(this + 1, colors, stops);
|
||||
}
|
||||
|
||||
explicit DlRadialGradientColorSource(
|
||||
const DlRadialGradientColorSource* source);
|
||||
|
||||
@@ -6,21 +6,6 @@
|
||||
|
||||
namespace flutter {
|
||||
|
||||
DlSweepGradientColorSource::DlSweepGradientColorSource(DlPoint center,
|
||||
DlScalar start,
|
||||
DlScalar end,
|
||||
uint32_t stop_count,
|
||||
const DlColor* colors,
|
||||
const float* stops,
|
||||
DlTileMode tile_mode,
|
||||
const DlMatrix* matrix)
|
||||
: DlGradientColorSourceBase(stop_count, tile_mode, matrix),
|
||||
center_(center),
|
||||
start_(start),
|
||||
end_(end) {
|
||||
store_color_stops(this + 1, colors, stops);
|
||||
}
|
||||
|
||||
DlSweepGradientColorSource::DlSweepGradientColorSource(
|
||||
const DlSweepGradientColorSource* source)
|
||||
: DlGradientColorSourceBase(source->stop_count(),
|
||||
|
||||
@@ -34,14 +34,21 @@ class DlSweepGradientColorSource final : public DlGradientColorSourceBase {
|
||||
bool equals_(DlColorSource const& other) const override;
|
||||
|
||||
private:
|
||||
template <typename Colors>
|
||||
DlSweepGradientColorSource(DlPoint center,
|
||||
DlScalar start,
|
||||
DlScalar end,
|
||||
uint32_t stop_count,
|
||||
const DlColor* colors,
|
||||
Colors colors,
|
||||
const float* stops,
|
||||
DlTileMode tile_mode,
|
||||
const DlMatrix* matrix = nullptr);
|
||||
const DlMatrix* matrix = nullptr)
|
||||
: DlGradientColorSourceBase(stop_count, tile_mode, matrix),
|
||||
center_(center),
|
||||
start_(start),
|
||||
end_(end) {
|
||||
store_color_stops(this + 1, colors, stops);
|
||||
}
|
||||
|
||||
explicit DlSweepGradientColorSource(const DlSweepGradientColorSource* source);
|
||||
|
||||
|
||||
@@ -31,8 +31,9 @@ std::shared_ptr<DlColorSource> DlColorSource::MakeImage(
|
||||
}
|
||||
|
||||
namespace {
|
||||
size_t CalculateLinearGradientSize(uint32_t stop_count) {
|
||||
return sizeof(DlLinearGradientColorSource) +
|
||||
template <typename GradientColorSource>
|
||||
size_t CalculateGradientSize(uint32_t stop_count) {
|
||||
return sizeof(GradientColorSource) +
|
||||
(stop_count * (sizeof(DlColor) + sizeof(float)));
|
||||
}
|
||||
} // namespace
|
||||
@@ -45,7 +46,8 @@ std::shared_ptr<DlColorSource> DlColorSource::MakeLinear(
|
||||
const float* stops,
|
||||
DlTileMode tile_mode,
|
||||
const DlMatrix* matrix) {
|
||||
size_t needed = CalculateLinearGradientSize(stop_count);
|
||||
size_t needed =
|
||||
CalculateGradientSize<DlLinearGradientColorSource>(stop_count);
|
||||
void* storage = ::operator new(needed);
|
||||
|
||||
std::shared_ptr<DlLinearGradientColorSource> ret;
|
||||
@@ -64,7 +66,8 @@ std::shared_ptr<DlColorSource> DlColorSource::MakeLinear(
|
||||
const float* stops,
|
||||
DlTileMode tile_mode,
|
||||
const DlMatrix* matrix) {
|
||||
size_t needed = CalculateLinearGradientSize(stop_count);
|
||||
size_t needed =
|
||||
CalculateGradientSize<DlLinearGradientColorSource>(stop_count);
|
||||
void* storage = ::operator new(needed);
|
||||
|
||||
std::shared_ptr<DlLinearGradientColorSource> ret;
|
||||
@@ -83,9 +86,8 @@ std::shared_ptr<DlColorSource> DlColorSource::MakeRadial(
|
||||
const float* stops,
|
||||
DlTileMode tile_mode,
|
||||
const DlMatrix* matrix) {
|
||||
size_t needed = sizeof(DlRadialGradientColorSource) +
|
||||
(stop_count * (sizeof(DlColor) + sizeof(float)));
|
||||
|
||||
size_t needed =
|
||||
CalculateGradientSize<DlRadialGradientColorSource>(stop_count);
|
||||
void* storage = ::operator new(needed);
|
||||
|
||||
std::shared_ptr<DlRadialGradientColorSource> ret;
|
||||
@@ -95,6 +97,26 @@ std::shared_ptr<DlColorSource> DlColorSource::MakeRadial(
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::shared_ptr<DlColorSource> DlColorSource::MakeRadial(
|
||||
DlPoint center,
|
||||
DlScalar radius,
|
||||
uint32_t stop_count,
|
||||
const DlScalar* colors_argb,
|
||||
const float* stops,
|
||||
DlTileMode tile_mode,
|
||||
const DlMatrix* matrix) {
|
||||
size_t needed =
|
||||
CalculateGradientSize<DlRadialGradientColorSource>(stop_count);
|
||||
void* storage = ::operator new(needed);
|
||||
|
||||
std::shared_ptr<DlRadialGradientColorSource> ret;
|
||||
ret.reset(
|
||||
new (storage) DlRadialGradientColorSource(
|
||||
center, radius, stop_count, colors_argb, stops, tile_mode, matrix),
|
||||
DlGradientDeleter);
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::shared_ptr<DlColorSource> DlColorSource::MakeConical(
|
||||
DlPoint start_center,
|
||||
DlScalar start_radius,
|
||||
@@ -105,9 +127,8 @@ std::shared_ptr<DlColorSource> DlColorSource::MakeConical(
|
||||
const float* stops,
|
||||
DlTileMode tile_mode,
|
||||
const DlMatrix* matrix) {
|
||||
size_t needed = sizeof(DlConicalGradientColorSource) +
|
||||
(stop_count * (sizeof(DlColor) + sizeof(float)));
|
||||
|
||||
size_t needed =
|
||||
CalculateGradientSize<DlConicalGradientColorSource>(stop_count);
|
||||
void* storage = ::operator new(needed);
|
||||
|
||||
std::shared_ptr<DlConicalGradientColorSource> ret;
|
||||
@@ -118,6 +139,29 @@ std::shared_ptr<DlColorSource> DlColorSource::MakeConical(
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::shared_ptr<DlColorSource> DlColorSource::MakeConical(
|
||||
DlPoint start_center,
|
||||
DlScalar start_radius,
|
||||
DlPoint end_center,
|
||||
DlScalar end_radius,
|
||||
uint32_t stop_count,
|
||||
const DlScalar* colors_argb,
|
||||
const float* stops,
|
||||
DlTileMode tile_mode,
|
||||
const DlMatrix* matrix) {
|
||||
size_t needed =
|
||||
CalculateGradientSize<DlConicalGradientColorSource>(stop_count);
|
||||
|
||||
void* storage = ::operator new(needed);
|
||||
|
||||
std::shared_ptr<DlConicalGradientColorSource> ret;
|
||||
ret.reset(new (storage) DlConicalGradientColorSource(
|
||||
start_center, start_radius, end_center, end_radius, stop_count,
|
||||
colors_argb, stops, tile_mode, matrix),
|
||||
DlGradientDeleter);
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::shared_ptr<DlColorSource> DlColorSource::MakeSweep(
|
||||
DlPoint center,
|
||||
DlScalar start,
|
||||
@@ -127,9 +171,7 @@ std::shared_ptr<DlColorSource> DlColorSource::MakeSweep(
|
||||
const float* stops,
|
||||
DlTileMode tile_mode,
|
||||
const DlMatrix* matrix) {
|
||||
size_t needed = sizeof(DlSweepGradientColorSource) +
|
||||
(stop_count * (sizeof(DlColor) + sizeof(float)));
|
||||
|
||||
size_t needed = CalculateGradientSize<DlSweepGradientColorSource>(stop_count);
|
||||
void* storage = ::operator new(needed);
|
||||
|
||||
std::shared_ptr<DlSweepGradientColorSource> ret;
|
||||
@@ -140,6 +182,26 @@ std::shared_ptr<DlColorSource> DlColorSource::MakeSweep(
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::shared_ptr<DlColorSource> DlColorSource::MakeSweep(
|
||||
DlPoint center,
|
||||
DlScalar start,
|
||||
DlScalar end,
|
||||
uint32_t stop_count,
|
||||
const DlScalar* colors_argb,
|
||||
const float* stops,
|
||||
DlTileMode tile_mode,
|
||||
const DlMatrix* matrix) {
|
||||
size_t needed = CalculateGradientSize<DlSweepGradientColorSource>(stop_count);
|
||||
void* storage = ::operator new(needed);
|
||||
|
||||
std::shared_ptr<DlSweepGradientColorSource> ret;
|
||||
ret.reset(new (storage) DlSweepGradientColorSource(center, start, end,
|
||||
stop_count, colors_argb,
|
||||
stops, tile_mode, matrix),
|
||||
DlGradientDeleter);
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::shared_ptr<DlColorSource> DlColorSource::MakeRuntimeEffect(
|
||||
sk_sp<DlRuntimeEffect> runtime_effect,
|
||||
std::vector<std::shared_ptr<DlColorSource>> samplers,
|
||||
|
||||
@@ -60,7 +60,8 @@ class DlColorSource : public DlAttribute<DlColorSource, DlColorSourceType> {
|
||||
const DlMatrix* matrix = nullptr);
|
||||
|
||||
/// @brief Make a linear gradient.
|
||||
/// @param colors_argb Array of DlScalars that represents colors in the ARGB.
|
||||
/// @param colors_argb Array of DlScalars that represents colors in the ARGB
|
||||
/// format, in the extended srgb colorspace.
|
||||
static std::shared_ptr<DlColorSource> MakeLinear(
|
||||
const DlPoint start_point,
|
||||
const DlPoint end_point,
|
||||
@@ -79,6 +80,18 @@ class DlColorSource : public DlAttribute<DlColorSource, DlColorSourceType> {
|
||||
DlTileMode tile_mode,
|
||||
const DlMatrix* matrix = nullptr);
|
||||
|
||||
/// @brief Make a radial gradient.
|
||||
/// @param colors_argb Array of DlScalars that represents colors in the ARGB
|
||||
/// format, in the extended srgb colorspace.
|
||||
static std::shared_ptr<DlColorSource> MakeRadial(
|
||||
DlPoint center,
|
||||
DlScalar radius,
|
||||
uint32_t stop_count,
|
||||
const DlScalar* colors_argb,
|
||||
const float* stops,
|
||||
DlTileMode tile_mode,
|
||||
const DlMatrix* matrix = nullptr);
|
||||
|
||||
static std::shared_ptr<DlColorSource> MakeConical(
|
||||
DlPoint start_center,
|
||||
DlScalar start_radius,
|
||||
@@ -90,6 +103,20 @@ class DlColorSource : public DlAttribute<DlColorSource, DlColorSourceType> {
|
||||
DlTileMode tile_mode,
|
||||
const DlMatrix* matrix = nullptr);
|
||||
|
||||
/// @brief Make a conical gradient.
|
||||
/// @param colors_argb colors_argb Array of DlScalars that represents colors
|
||||
/// in the ARGB format, in the extended srgb colorspace.
|
||||
static std::shared_ptr<DlColorSource> MakeConical(
|
||||
DlPoint start_center,
|
||||
DlScalar start_radius,
|
||||
DlPoint end_center,
|
||||
DlScalar end_radius,
|
||||
uint32_t stop_count,
|
||||
const DlScalar* colors_argb,
|
||||
const float* stops,
|
||||
DlTileMode tile_mode,
|
||||
const DlMatrix* matrix = nullptr);
|
||||
|
||||
static std::shared_ptr<DlColorSource> MakeSweep(
|
||||
DlPoint center,
|
||||
DlScalar start,
|
||||
@@ -100,6 +127,19 @@ class DlColorSource : public DlAttribute<DlColorSource, DlColorSourceType> {
|
||||
DlTileMode tile_mode,
|
||||
const DlMatrix* matrix = nullptr);
|
||||
|
||||
/// @brief Make a sweep gradient.
|
||||
/// @param colors_argb Array of DlScalars that represents colors in the ARGB
|
||||
/// format, in the extended srgb colorspace.
|
||||
static std::shared_ptr<DlColorSource> MakeSweep(
|
||||
DlPoint center,
|
||||
DlScalar start,
|
||||
DlScalar end,
|
||||
uint32_t stop_count,
|
||||
const DlScalar* colors_argb,
|
||||
const float* stops,
|
||||
DlTileMode tile_mode,
|
||||
const DlMatrix* matrix = nullptr);
|
||||
|
||||
static std::shared_ptr<DlColorSource> MakeRuntimeEffect(
|
||||
sk_sp<DlRuntimeEffect> runtime_effect,
|
||||
std::vector<std::shared_ptr<DlColorSource>> samplers,
|
||||
|
||||
@@ -333,6 +333,32 @@ TEST(DisplayListColorSource, RadialGradientConstructor) {
|
||||
DlTileMode::kClamp, &kTestMatrix1);
|
||||
}
|
||||
|
||||
TEST(DisplayListColorSource, RadialGradientARGBConstructor) {
|
||||
std::array<DlScalar, kTestStopCount * 4> colors;
|
||||
for (int i = 0; i < kTestStopCount; ++i) {
|
||||
colors[i * 4 + 0] = kTestColors[i].getAlphaF(); //
|
||||
colors[i * 4 + 1] = kTestColors[i].getRedF(); //
|
||||
colors[i * 4 + 2] = kTestColors[i].getGreenF(); //
|
||||
colors[i * 4 + 3] = kTestColors[i].getBlueF();
|
||||
}
|
||||
std::shared_ptr<DlColorSource> source = DlColorSource::MakeRadial(
|
||||
kTestPoints[0], 10.f, kTestStopCount, colors.data(), kTestStops,
|
||||
DlTileMode::kClamp, &kTestMatrix1);
|
||||
ASSERT_TRUE(source);
|
||||
ASSERT_TRUE(source->asRadialGradient());
|
||||
EXPECT_EQ(source->asRadialGradient()->center(), kTestPoints[0]);
|
||||
EXPECT_EQ(source->asRadialGradient()->radius(), 10.f);
|
||||
EXPECT_EQ(source->asRadialGradient()->stop_count(), kTestStopCount);
|
||||
for (int i = 0; i < kTestStopCount; i++) {
|
||||
EXPECT_EQ(source->asRadialGradient()->colors()[i],
|
||||
kTestColors[i].withColorSpace(DlColorSpace::kExtendedSRGB));
|
||||
EXPECT_EQ(source->asRadialGradient()->stops()[i], kTestStops[i]);
|
||||
}
|
||||
EXPECT_EQ(source->asRadialGradient()->tile_mode(), DlTileMode::kClamp);
|
||||
EXPECT_EQ(source->asRadialGradient()->matrix(), kTestMatrix1);
|
||||
EXPECT_EQ(source->is_opaque(), true);
|
||||
}
|
||||
|
||||
TEST(DisplayListColorSource, RadialGradientShared) {
|
||||
std::shared_ptr<DlColorSource> source = DlColorSource::MakeRadial(
|
||||
kTestPoints[0], 10.0, kTestStopCount, kTestColors, kTestStops,
|
||||
@@ -451,6 +477,34 @@ TEST(DisplayListColorSource, ConicalGradientConstructor) {
|
||||
kTestStops, DlTileMode::kClamp, &kTestMatrix1);
|
||||
}
|
||||
|
||||
TEST(DisplayListColorSource, ConicalGradientARGBConstructor) {
|
||||
std::array<DlScalar, kTestStopCount * 4> colors;
|
||||
for (int i = 0; i < kTestStopCount; ++i) {
|
||||
colors[i * 4 + 0] = kTestColors[i].getAlphaF(); //
|
||||
colors[i * 4 + 1] = kTestColors[i].getRedF(); //
|
||||
colors[i * 4 + 2] = kTestColors[i].getGreenF(); //
|
||||
colors[i * 4 + 3] = kTestColors[i].getBlueF();
|
||||
}
|
||||
std::shared_ptr<DlColorSource> source = DlColorSource::MakeConical(
|
||||
kTestPoints[0], 10.f, kTestPoints[1], 20.f, kTestStopCount, colors.data(),
|
||||
kTestStops, DlTileMode::kClamp, &kTestMatrix1);
|
||||
ASSERT_TRUE(source);
|
||||
ASSERT_TRUE(source->asConicalGradient());
|
||||
EXPECT_EQ(source->asConicalGradient()->start_center(), kTestPoints[0]);
|
||||
EXPECT_EQ(source->asConicalGradient()->start_radius(), 10.f);
|
||||
EXPECT_EQ(source->asConicalGradient()->end_center(), kTestPoints[1]);
|
||||
EXPECT_EQ(source->asConicalGradient()->end_radius(), 20.f);
|
||||
EXPECT_EQ(source->asConicalGradient()->stop_count(), kTestStopCount);
|
||||
for (int i = 0; i < kTestStopCount; i++) {
|
||||
EXPECT_EQ(source->asConicalGradient()->colors()[i],
|
||||
kTestColors[i].withColorSpace(DlColorSpace::kExtendedSRGB));
|
||||
EXPECT_EQ(source->asConicalGradient()->stops()[i], kTestStops[i]);
|
||||
}
|
||||
EXPECT_EQ(source->asConicalGradient()->tile_mode(), DlTileMode::kClamp);
|
||||
EXPECT_EQ(source->asConicalGradient()->matrix(), kTestMatrix1);
|
||||
EXPECT_EQ(source->is_opaque(), true);
|
||||
}
|
||||
|
||||
TEST(DisplayListColorSource, ConicalGradientShared) {
|
||||
std::shared_ptr<DlColorSource> source = DlColorSource::MakeConical(
|
||||
kTestPoints[0], 10.0, kTestPoints[1], 20.0, kTestStopCount, kTestColors,
|
||||
@@ -585,6 +639,33 @@ TEST(DisplayListColorSource, SweepGradientConstructor) {
|
||||
DlTileMode::kClamp, &kTestMatrix1);
|
||||
}
|
||||
|
||||
TEST(DisplayListColorSource, SweepGradientARGBConstructor) {
|
||||
std::array<DlScalar, kTestStopCount * 4> colors;
|
||||
for (int i = 0; i < kTestStopCount; ++i) {
|
||||
colors[i * 4 + 0] = kTestColors[i].getAlphaF(); //
|
||||
colors[i * 4 + 1] = kTestColors[i].getRedF(); //
|
||||
colors[i * 4 + 2] = kTestColors[i].getGreenF(); //
|
||||
colors[i * 4 + 3] = kTestColors[i].getBlueF();
|
||||
}
|
||||
std::shared_ptr<DlColorSource> source = DlColorSource::MakeSweep(
|
||||
kTestPoints[0], 10.f, 20.f, kTestStopCount, colors.data(), kTestStops,
|
||||
DlTileMode::kClamp, &kTestMatrix1);
|
||||
ASSERT_TRUE(source);
|
||||
ASSERT_TRUE(source->asSweepGradient());
|
||||
EXPECT_EQ(source->asSweepGradient()->center(), kTestPoints[0]);
|
||||
EXPECT_EQ(source->asSweepGradient()->start(), 10.f);
|
||||
EXPECT_EQ(source->asSweepGradient()->end(), 20.f);
|
||||
EXPECT_EQ(source->asSweepGradient()->stop_count(), kTestStopCount);
|
||||
for (int i = 0; i < kTestStopCount; i++) {
|
||||
EXPECT_EQ(source->asSweepGradient()->colors()[i],
|
||||
kTestColors[i].withColorSpace(DlColorSpace::kExtendedSRGB));
|
||||
EXPECT_EQ(source->asSweepGradient()->stops()[i], kTestStops[i]);
|
||||
}
|
||||
EXPECT_EQ(source->asSweepGradient()->tile_mode(), DlTileMode::kClamp);
|
||||
EXPECT_EQ(source->asSweepGradient()->matrix(), kTestMatrix1);
|
||||
EXPECT_EQ(source->is_opaque(), true);
|
||||
}
|
||||
|
||||
TEST(DisplayListColorSource, SweepGradientShared) {
|
||||
std::shared_ptr<DlColorSource> source = DlColorSource::MakeSweep(
|
||||
kTestPoints[0], 10.0, 20.0, kTestStopCount, kTestColors, kTestStops,
|
||||
|
||||
@@ -68,19 +68,9 @@ void CanvasGradient::initRadial(double center_x,
|
||||
dl_matrix = ToDlMatrix(matrix4);
|
||||
}
|
||||
|
||||
std::vector<DlColor> dl_colors;
|
||||
dl_colors.reserve(num_colors);
|
||||
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(
|
||||
DlPoint(SafeNarrow(center_x), SafeNarrow(center_y)), SafeNarrow(radius),
|
||||
num_colors, dl_colors.data(), color_stops.data(), tile_mode,
|
||||
num_colors, colors.data(), color_stops.data(), tile_mode,
|
||||
has_matrix ? &dl_matrix : nullptr);
|
||||
// Just a sanity check, all gradient shaders should be thread-safe
|
||||
FML_DCHECK(dl_shader_->isUIThreadSafe());
|
||||
@@ -104,21 +94,11 @@ void CanvasGradient::initSweep(double center_x,
|
||||
dl_matrix = ToDlMatrix(matrix4);
|
||||
}
|
||||
|
||||
std::vector<DlColor> dl_colors;
|
||||
dl_colors.reserve(num_colors);
|
||||
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(
|
||||
DlPoint(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), num_colors,
|
||||
dl_colors.data(), color_stops.data(), tile_mode,
|
||||
colors.data(), color_stops.data(), tile_mode,
|
||||
has_matrix ? &dl_matrix : nullptr);
|
||||
// Just a sanity check, all gradient shaders should be thread-safe
|
||||
FML_DCHECK(dl_shader_->isUIThreadSafe());
|
||||
@@ -144,20 +124,10 @@ void CanvasGradient::initTwoPointConical(double start_x,
|
||||
dl_matrix = ToDlMatrix(matrix4);
|
||||
}
|
||||
|
||||
std::vector<DlColor> dl_colors;
|
||||
dl_colors.reserve(num_colors);
|
||||
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(
|
||||
DlPoint(SafeNarrow(start_x), SafeNarrow(start_y)),
|
||||
SafeNarrow(start_radius), DlPoint(SafeNarrow(end_x), SafeNarrow(end_y)),
|
||||
SafeNarrow(end_radius), num_colors, dl_colors.data(), color_stops.data(),
|
||||
SafeNarrow(end_radius), num_colors, colors.data(), color_stops.data(),
|
||||
tile_mode, has_matrix ? &dl_matrix : nullptr);
|
||||
// Just a sanity check, all gradient shaders should be thread-safe
|
||||
FML_DCHECK(dl_shader_->isUIThreadSafe());
|
||||
|
||||
Reference in New Issue
Block a user