Chromium Code Reviews| 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..23674ba94fa8a662941bc5de2e2f5758c193a9c1 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,23 @@ 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) { |
| + std::unique_ptr<PaintShader> shader = |
| + CreateShader(colors, pos, tile, flags, local_matrix); |
| + if (!shader || !shader->is_valid()) { |
| // use last color, since our "geometry" was degenerate (e.g. radius==0) |
| - shader = SkShader::MakeColorShader(colors.back()); |
| + shader = WTF::MakeUnique<PaintShader>(colors.back()); |
| } |
| - 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_)); |
|
enne (OOO)
2017/05/23 18:55:02
This line is probably the one that's most concerni
|
| // Legacy behavior: gradients are always dithered. |
| flags.setDither(true); |
| @@ -183,13 +186,14 @@ 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) const override { |
| SkPoint pts[2] = {p0_.Data(), p1_.Data()}; |
| - return SkGradientShader::MakeLinear(pts, colors.data(), pos.data(), |
| + return WTF::MakeUnique<PaintShader>(pts, colors.data(), pos.data(), |
| static_cast<int>(colors.size()), |
| tile_mode, flags, &local_matrix); |
| } |
| @@ -216,11 +220,12 @@ 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) const override { |
| SkTCopyOnFirstWrite<SkMatrix> adjusted_local_matrix(local_matrix); |
| if (aspect_ratio_ != 1) { |
| // CSS3 elliptical gradients: apply the elliptical scaling at the |
| @@ -233,7 +238,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,7 +248,7 @@ 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); |
| @@ -267,11 +272,12 @@ 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) 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,7 +288,7 @@ class ConicGradient final : public Gradient { |
| position_.Y()); |
| } |
| - return SkGradientShader::MakeSweep( |
| + return WTF::MakeUnique<PaintShader>( |
| position_.X(), position_.Y(), colors.data(), pos.data(), |
| static_cast<int>(colors.size()), flags, adjusted_local_matrix); |
| } |