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