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 std::unique_ptr<PaintShader> ImagePattern::CreateShader( | 32 sk_sp<PaintShader> ImagePattern::CreateShader(const SkMatrix& local_matrix) { |
33 const SkMatrix& local_matrix) { | 33 if (!tile_image_) |
34 if (!tile_image_) { | 34 return WrapSkShader(SkShader::MakeColorShader(SK_ColorTRANSPARENT)); |
35 return PaintShader::MakeColor(SK_ColorTRANSPARENT); | |
36 } | |
37 | 35 |
38 if (IsRepeatXY()) { | 36 if (IsRepeatXY()) { |
39 // Fast path: for repeatXY we just return a shader from the original image. | 37 // Fast path: for repeatXY we just return a shader from the original image. |
40 return PaintShader::MakeImage(tile_image_, SkShader::kRepeat_TileMode, | 38 return MakePaintShaderImage(tile_image_, SkShader::kRepeat_TileMode, |
41 SkShader::kRepeat_TileMode, &local_matrix); | 39 SkShader::kRepeat_TileMode, &local_matrix); |
42 } | 40 } |
43 | 41 |
44 // Skia does not have a "draw the tile only once" option. Clamp_TileMode | 42 // Skia does not have a "draw the tile only once" option. Clamp_TileMode |
45 // repeats the last line of the image after drawing one tile. To avoid | 43 // repeats the last line of the image after drawing one tile. To avoid |
46 // filling the space with arbitrary pixels, this workaround forces the | 44 // filling the space with arbitrary pixels, this workaround forces the |
47 // image to have a line of transparent pixels on the "repeated" edge(s), | 45 // image to have a line of transparent pixels on the "repeated" edge(s), |
48 // thus causing extra space to be transparent filled. | 46 // thus causing extra space to be transparent filled. |
49 SkShader::TileMode tile_mode_x = | 47 SkShader::TileMode tile_mode_x = |
50 IsRepeatX() ? SkShader::kRepeat_TileMode : SkShader::kClamp_TileMode; | 48 IsRepeatX() ? SkShader::kRepeat_TileMode : SkShader::kClamp_TileMode; |
51 SkShader::TileMode tile_mode_y = | 49 SkShader::TileMode tile_mode_y = |
(...skipping 16 matching lines...) Expand all Loading... |
68 // Note: we use a picture *image* (as opposed to a picture *shader*) to | 66 // Note: we use a picture *image* (as opposed to a picture *shader*) to |
69 // lock-in the resolution (for 1px padding in particular). | 67 // lock-in the resolution (for 1px padding in particular). |
70 sk_sp<SkImage> tile_image = SkImage::MakeFromPicture( | 68 sk_sp<SkImage> tile_image = SkImage::MakeFromPicture( |
71 recorder.finishRecordingAsPicture(), tile_size, nullptr, nullptr, | 69 recorder.finishRecordingAsPicture(), tile_size, nullptr, nullptr, |
72 SkImage::BitDepth::kU8, SkColorSpace::MakeSRGB()); | 70 SkImage::BitDepth::kU8, SkColorSpace::MakeSRGB()); |
73 | 71 |
74 previous_local_matrix_ = local_matrix; | 72 previous_local_matrix_ = local_matrix; |
75 SkMatrix adjusted_matrix(local_matrix); | 73 SkMatrix adjusted_matrix(local_matrix); |
76 adjusted_matrix.postTranslate(-border_pixel_x, -border_pixel_y); | 74 adjusted_matrix.postTranslate(-border_pixel_x, -border_pixel_y); |
77 | 75 |
78 return PaintShader::MakeImage(std::move(tile_image), tile_mode_x, tile_mode_y, | 76 return MakePaintShaderImage(std::move(tile_image), tile_mode_x, tile_mode_y, |
79 &adjusted_matrix); | 77 &adjusted_matrix); |
80 } | 78 } |
81 | 79 |
82 bool ImagePattern::IsTextureBacked() const { | 80 bool ImagePattern::IsTextureBacked() const { |
83 return tile_image_ && tile_image_->isTextureBacked(); | 81 return tile_image_ && tile_image_->isTextureBacked(); |
84 } | 82 } |
85 | 83 |
86 } // namespace blink | 84 } // namespace blink |
OLD | NEW |