OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "platform/graphics/ImagePattern.h" | 5 #include "platform/graphics/ImagePattern.h" |
6 | 6 |
7 #include "platform/graphics/Image.h" | 7 #include "platform/graphics/Image.h" |
8 #include "platform/graphics/paint/PaintShader.h" | 8 #include "platform/graphics/paint/PaintShader.h" |
9 #include "platform/graphics/skia/SkiaUtils.h" | 9 #include "platform/graphics/skia/SkiaUtils.h" |
10 #include "third_party/skia/include/core/SkImage.h" | 10 #include "third_party/skia/include/core/SkImage.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 : Pattern(repeat_mode), tile_image_(image->ImageForCurrentFrame()) { | 22 : Pattern(repeat_mode), tile_image_(image->ImageForCurrentFrame()) { |
23 previous_local_matrix_.setIdentity(); | 23 previous_local_matrix_.setIdentity(); |
24 } | 24 } |
25 | 25 |
26 bool ImagePattern::IsLocalMatrixChanged(const SkMatrix& local_matrix) const { | 26 bool ImagePattern::IsLocalMatrixChanged(const SkMatrix& local_matrix) const { |
27 if (IsRepeatXY()) | 27 if (IsRepeatXY()) |
28 return Pattern::IsLocalMatrixChanged(local_matrix); | 28 return Pattern::IsLocalMatrixChanged(local_matrix); |
29 return local_matrix != previous_local_matrix_; | 29 return local_matrix != previous_local_matrix_; |
30 } | 30 } |
31 | 31 |
32 sk_sp<PaintShader> ImagePattern::CreateShader(const SkMatrix& local_matrix) { | 32 std::unique_ptr<PaintShader> ImagePattern::CreateShader( |
33 if (!tile_image_) | 33 const SkMatrix& local_matrix) { |
34 return WrapSkShader(SkShader::MakeColorShader(SK_ColorTRANSPARENT)); | 34 if (!tile_image_) { |
| 35 return PaintShader::MakeColor(SK_ColorTRANSPARENT); |
| 36 } |
35 | 37 |
36 if (IsRepeatXY()) { | 38 if (IsRepeatXY()) { |
37 // Fast path: for repeatXY we just return a shader from the original image. | 39 // Fast path: for repeatXY we just return a shader from the original image. |
38 return MakePaintShaderImage(tile_image_, SkShader::kRepeat_TileMode, | 40 return PaintShader::MakeImage(tile_image_, SkShader::kRepeat_TileMode, |
39 SkShader::kRepeat_TileMode, &local_matrix); | 41 SkShader::kRepeat_TileMode, &local_matrix); |
40 } | 42 } |
41 | 43 |
42 // Skia does not have a "draw the tile only once" option. Clamp_TileMode | 44 // Skia does not have a "draw the tile only once" option. Clamp_TileMode |
43 // repeats the last line of the image after drawing one tile. To avoid | 45 // repeats the last line of the image after drawing one tile. To avoid |
44 // filling the space with arbitrary pixels, this workaround forces the | 46 // filling the space with arbitrary pixels, this workaround forces the |
45 // image to have a line of transparent pixels on the "repeated" edge(s), | 47 // image to have a line of transparent pixels on the "repeated" edge(s), |
46 // thus causing extra space to be transparent filled. | 48 // thus causing extra space to be transparent filled. |
47 SkShader::TileMode tile_mode_x = | 49 SkShader::TileMode tile_mode_x = |
48 IsRepeatX() ? SkShader::kRepeat_TileMode : SkShader::kClamp_TileMode; | 50 IsRepeatX() ? SkShader::kRepeat_TileMode : SkShader::kClamp_TileMode; |
49 SkShader::TileMode tile_mode_y = | 51 SkShader::TileMode tile_mode_y = |
(...skipping 16 matching lines...) Expand all Loading... |
66 // Note: we use a picture *image* (as opposed to a picture *shader*) to | 68 // Note: we use a picture *image* (as opposed to a picture *shader*) to |
67 // lock-in the resolution (for 1px padding in particular). | 69 // lock-in the resolution (for 1px padding in particular). |
68 sk_sp<SkImage> tile_image = SkImage::MakeFromPicture( | 70 sk_sp<SkImage> tile_image = SkImage::MakeFromPicture( |
69 recorder.finishRecordingAsPicture(), tile_size, nullptr, nullptr, | 71 recorder.finishRecordingAsPicture(), tile_size, nullptr, nullptr, |
70 SkImage::BitDepth::kU8, SkColorSpace::MakeSRGB()); | 72 SkImage::BitDepth::kU8, SkColorSpace::MakeSRGB()); |
71 | 73 |
72 previous_local_matrix_ = local_matrix; | 74 previous_local_matrix_ = local_matrix; |
73 SkMatrix adjusted_matrix(local_matrix); | 75 SkMatrix adjusted_matrix(local_matrix); |
74 adjusted_matrix.postTranslate(-border_pixel_x, -border_pixel_y); | 76 adjusted_matrix.postTranslate(-border_pixel_x, -border_pixel_y); |
75 | 77 |
76 return MakePaintShaderImage(std::move(tile_image), tile_mode_x, tile_mode_y, | 78 return PaintShader::MakeImage(std::move(tile_image), tile_mode_x, tile_mode_y, |
77 &adjusted_matrix); | 79 &adjusted_matrix); |
78 } | 80 } |
79 | 81 |
80 bool ImagePattern::IsTextureBacked() const { | 82 bool ImagePattern::IsTextureBacked() const { |
81 return tile_image_ && tile_image_->isTextureBacked(); | 83 return tile_image_ && tile_image_->isTextureBacked(); |
82 } | 84 } |
83 | 85 |
84 } // namespace blink | 86 } // namespace blink |
OLD | NEW |