Index: third_party/WebKit/Source/platform/graphics/Gradient.cpp |
diff --git a/third_party/WebKit/Source/platform/graphics/Gradient.cpp b/third_party/WebKit/Source/platform/graphics/Gradient.cpp |
index a96f9f74a609d32fa19066705ba1ff18cbb3d990..cc4701e4e89242f6c6289f6d3b7bd6b9cdfa84d5 100644 |
--- a/third_party/WebKit/Source/platform/graphics/Gradient.cpp |
+++ b/third_party/WebKit/Source/platform/graphics/Gradient.cpp |
@@ -121,7 +121,7 @@ void Gradient::FillSkiaStops(ColorBuffer& colors, OffsetBuffer& pos) const { |
} |
} |
-sk_sp<PaintShader> Gradient::CreateShaderInternal( |
+std::unique_ptr<PaintShader> Gradient::CreateShaderInternal( |
const SkMatrix& local_matrix) { |
SortStopsIfNecessary(); |
DCHECK(stops_sorted_); |
@@ -151,20 +151,20 @@ sk_sp<PaintShader> Gradient::CreateShaderInternal( |
uint32_t flags = color_interpolation_ == ColorInterpolation::kPremultiplied |
? SkGradientShader::kInterpolateColorsInPremul_Flag |
: 0; |
- sk_sp<SkShader> shader = CreateShader(colors, pos, tile, flags, local_matrix); |
- if (!shader) { |
- // use last color, since our "geometry" was degenerate (e.g. radius==0) |
- shader = SkShader::MakeColorShader(colors.back()); |
- } |
+ std::unique_ptr<PaintShader> shader = |
+ CreateShader(colors, pos, tile, flags, local_matrix, colors.back()); |
+ DCHECK(shader); |
- return WrapSkShader(std::move(shader)); |
+ return shader; |
} |
void Gradient::ApplyToFlags(PaintFlags& flags, const SkMatrix& local_matrix) { |
- if (!cached_shader_ || local_matrix != cached_shader_->getLocalMatrix()) |
+ if (!cached_shader_ || |
+ local_matrix != cached_shader_->sk_shader()->getLocalMatrix()) { |
cached_shader_ = CreateShaderInternal(local_matrix); |
+ } |
- flags.setShader(cached_shader_); |
+ flags.setShader(WTF::MakeUnique<PaintShader>(*cached_shader_)); |
// Legacy behavior: gradients are always dithered. |
flags.setDither(true); |
@@ -183,15 +183,17 @@ class LinearGradient final : public Gradient { |
p1_(p1) {} |
protected: |
- sk_sp<SkShader> CreateShader(const ColorBuffer& colors, |
- const OffsetBuffer& pos, |
- SkShader::TileMode tile_mode, |
- uint32_t flags, |
- const SkMatrix& local_matrix) const override { |
+ std::unique_ptr<PaintShader> CreateShader( |
+ const ColorBuffer& colors, |
+ const OffsetBuffer& pos, |
+ SkShader::TileMode tile_mode, |
+ uint32_t flags, |
+ const SkMatrix& local_matrix, |
+ SkColor fallback_color) const override { |
SkPoint pts[2] = {p0_.Data(), p1_.Data()}; |
- return SkGradientShader::MakeLinear(pts, colors.data(), pos.data(), |
- static_cast<int>(colors.size()), |
- tile_mode, flags, &local_matrix); |
+ return WTF::MakeUnique<PaintShader>( |
+ pts, colors.data(), pos.data(), static_cast<int>(colors.size()), |
+ tile_mode, flags, &local_matrix, fallback_color); |
} |
private: |
@@ -216,11 +218,13 @@ class RadialGradient final : public Gradient { |
aspect_ratio_(aspect_ratio) {} |
protected: |
- sk_sp<SkShader> CreateShader(const ColorBuffer& colors, |
- const OffsetBuffer& pos, |
- SkShader::TileMode tile_mode, |
- uint32_t flags, |
- const SkMatrix& local_matrix) const override { |
+ std::unique_ptr<PaintShader> CreateShader( |
+ const ColorBuffer& colors, |
+ const OffsetBuffer& pos, |
+ SkShader::TileMode tile_mode, |
+ uint32_t flags, |
+ const SkMatrix& local_matrix, |
+ SkColor fallback_color) const override { |
SkTCopyOnFirstWrite<SkMatrix> adjusted_local_matrix(local_matrix); |
if (aspect_ratio_ != 1) { |
// CSS3 elliptical gradients: apply the elliptical scaling at the |
@@ -233,7 +237,7 @@ class RadialGradient final : public Gradient { |
// Since the two-point radial gradient is slower than the plain radial, |
// only use it if we have to. |
if (p0_ == p1_ && r0_ <= 0.0f) { |
- return SkGradientShader::MakeRadial( |
+ return WTF::MakeUnique<PaintShader>( |
p1_.Data(), r1_, colors.data(), pos.data(), |
static_cast<int>(colors.size()), tile_mode, flags, |
adjusted_local_matrix); |
@@ -243,10 +247,10 @@ class RadialGradient final : public Gradient { |
// negative radius, ask for zero instead. |
const SkScalar radius0 = std::max(WebCoreFloatToSkScalar(r0_), 0.0f); |
const SkScalar radius1 = std::max(WebCoreFloatToSkScalar(r1_), 0.0f); |
- return SkGradientShader::MakeTwoPointConical( |
+ return WTF::MakeUnique<PaintShader>( |
p0_.Data(), radius0, p1_.Data(), radius1, colors.data(), pos.data(), |
static_cast<int>(colors.size()), tile_mode, flags, |
- adjusted_local_matrix); |
+ adjusted_local_matrix, fallback_color); |
} |
private: |
@@ -267,11 +271,13 @@ class ConicGradient final : public Gradient { |
angle_(angle) {} |
protected: |
- sk_sp<SkShader> CreateShader(const ColorBuffer& colors, |
- const OffsetBuffer& pos, |
- SkShader::TileMode tile_mode, |
- uint32_t flags, |
- const SkMatrix& local_matrix) const override { |
+ std::unique_ptr<PaintShader> CreateShader( |
+ const ColorBuffer& colors, |
+ const OffsetBuffer& pos, |
+ SkShader::TileMode tile_mode, |
+ uint32_t flags, |
+ const SkMatrix& local_matrix, |
+ SkColor fallback_color) const override { |
DCHECK_NE(tile_mode, SkShader::kMirror_TileMode); |
// Skia's sweep gradient angles are relative to the x-axis, not the y-axis. |
@@ -282,9 +288,10 @@ class ConicGradient final : public Gradient { |
position_.Y()); |
} |
- return SkGradientShader::MakeSweep( |
- position_.X(), position_.Y(), colors.data(), pos.data(), |
- static_cast<int>(colors.size()), flags, adjusted_local_matrix); |
+ return WTF::MakeUnique<PaintShader>(position_.X(), position_.Y(), |
+ colors.data(), pos.data(), |
+ static_cast<int>(colors.size()), flags, |
+ adjusted_local_matrix, fallback_color); |
} |
private: |