OLD | NEW |
1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2017 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 "ui/gfx/skia_paint_util.h" | 5 #include "ui/gfx/skia_paint_util.h" |
6 | 6 |
| 7 #include "base/memory/ptr_util.h" |
7 #include "third_party/skia/include/core/SkColorFilter.h" | 8 #include "third_party/skia/include/core/SkColorFilter.h" |
8 #include "third_party/skia/include/effects/SkBlurMaskFilter.h" | 9 #include "third_party/skia/include/effects/SkBlurMaskFilter.h" |
9 #include "third_party/skia/include/effects/SkGradientShader.h" | 10 #include "third_party/skia/include/effects/SkGradientShader.h" |
10 #include "third_party/skia/include/effects/SkLayerDrawLooper.h" | 11 #include "third_party/skia/include/effects/SkLayerDrawLooper.h" |
11 #include "ui/gfx/image/image_skia_rep.h" | 12 #include "ui/gfx/image/image_skia_rep.h" |
12 | 13 |
13 namespace gfx { | 14 namespace gfx { |
14 | 15 |
15 sk_sp<cc::PaintShader> CreateImageRepShader(const gfx::ImageSkiaRep& image_rep, | 16 std::unique_ptr<cc::PaintShader> CreateImageRepShader( |
16 cc::PaintShader::TileMode tile_mode, | 17 const gfx::ImageSkiaRep& image_rep, |
17 const SkMatrix& local_matrix) { | 18 SkShader::TileMode tile_mode, |
18 return cc::WrapSkShader(CreateImageRepShaderForScale( | 19 const SkMatrix& local_matrix) { |
19 image_rep, tile_mode, local_matrix, image_rep.scale())); | 20 return CreateImageRepShaderForScale(image_rep, tile_mode, local_matrix, |
| 21 image_rep.scale()); |
20 } | 22 } |
21 | 23 |
22 sk_sp<cc::PaintShader> CreateImageRepShaderForScale( | 24 std::unique_ptr<cc::PaintShader> CreateImageRepShaderForScale( |
23 const gfx::ImageSkiaRep& image_rep, | 25 const gfx::ImageSkiaRep& image_rep, |
24 cc::PaintShader::TileMode tile_mode, | 26 SkShader::TileMode tile_mode, |
25 const SkMatrix& local_matrix, | 27 const SkMatrix& local_matrix, |
26 SkScalar scale) { | 28 SkScalar scale) { |
27 // Unscale matrix by |scale| such that the bitmap is drawn at the | 29 // Unscale matrix by |scale| such that the bitmap is drawn at the |
28 // correct density. | 30 // correct density. |
29 // Convert skew and translation to pixel coordinates. | 31 // Convert skew and translation to pixel coordinates. |
30 // Thus, for |bitmap_scale| = 2: | 32 // Thus, for |bitmap_scale| = 2: |
31 // x scale = 2, x translation = 1 DIP, | 33 // x scale = 2, x translation = 1 DIP, |
32 // should be converted to | 34 // should be converted to |
33 // x scale = 1, x translation = 2 pixels. | 35 // x scale = 1, x translation = 2 pixels. |
34 SkMatrix shader_scale = local_matrix; | 36 SkMatrix shader_scale = local_matrix; |
35 shader_scale.preScale(scale, scale); | 37 shader_scale.preScale(scale, scale); |
36 shader_scale.setScaleX(local_matrix.getScaleX() / scale); | 38 shader_scale.setScaleX(local_matrix.getScaleX() / scale); |
37 shader_scale.setScaleY(local_matrix.getScaleY() / scale); | 39 shader_scale.setScaleY(local_matrix.getScaleY() / scale); |
38 | 40 |
39 return cc::PaintShader::MakeBitmapShader(image_rep.sk_bitmap(), tile_mode, | 41 return base::MakeUnique<cc::PaintShader>( |
40 tile_mode, &shader_scale); | 42 SkImage::MakeFromBitmap(image_rep.sk_bitmap()), tile_mode, tile_mode, |
| 43 &shader_scale); |
41 } | 44 } |
42 | 45 |
43 sk_sp<cc::PaintShader> CreateGradientShader(int start_point, | 46 std::unique_ptr<cc::PaintShader> CreateGradientShader(int start_point, |
44 int end_point, | 47 int end_point, |
45 SkColor start_color, | 48 SkColor start_color, |
46 SkColor end_color) { | 49 SkColor end_color) { |
47 SkColor grad_colors[2] = {start_color, end_color}; | 50 SkColor grad_colors[2] = {start_color, end_color}; |
48 SkPoint grad_points[2]; | 51 SkPoint grad_points[2]; |
49 grad_points[0].iset(0, start_point); | 52 grad_points[0].iset(0, start_point); |
50 grad_points[1].iset(0, end_point); | 53 grad_points[1].iset(0, end_point); |
51 | 54 |
52 return cc::WrapSkShader(SkGradientShader::MakeLinear( | 55 return base::MakeUnique<cc::PaintShader>(grad_points, grad_colors, nullptr, 2, |
53 grad_points, grad_colors, NULL, 2, cc::PaintShader::kClamp_TileMode)); | 56 SkShader::kClamp_TileMode); |
54 } | 57 } |
55 | 58 |
56 // This is copied from | 59 // This is copied from |
57 // third_party/WebKit/Source/platform/graphics/skia/SkiaUtils.h | 60 // third_party/WebKit/Source/platform/graphics/skia/SkiaUtils.h |
58 static SkScalar RadiusToSigma(double radius) { | 61 static SkScalar RadiusToSigma(double radius) { |
59 return radius > 0 ? SkDoubleToScalar(0.288675f * radius + 0.5f) : 0; | 62 return radius > 0 ? SkDoubleToScalar(0.288675f * radius + 0.5f) : 0; |
60 } | 63 } |
61 | 64 |
62 sk_sp<SkDrawLooper> CreateShadowDrawLooper( | 65 sk_sp<SkDrawLooper> CreateShadowDrawLooper( |
63 const std::vector<ShadowValue>& shadows) { | 66 const std::vector<ShadowValue>& shadows) { |
(...skipping 22 matching lines...) Expand all Loading... |
86 kNormal_SkBlurStyle, RadiusToSigma(shadow.blur() / 2), | 89 kNormal_SkBlurStyle, RadiusToSigma(shadow.blur() / 2), |
87 SkBlurMaskFilter::kHighQuality_BlurFlag)); | 90 SkBlurMaskFilter::kHighQuality_BlurFlag)); |
88 paint->setColorFilter( | 91 paint->setColorFilter( |
89 SkColorFilter::MakeModeFilter(shadow.color(), SkBlendMode::kSrcIn)); | 92 SkColorFilter::MakeModeFilter(shadow.color(), SkBlendMode::kSrcIn)); |
90 } | 93 } |
91 | 94 |
92 return looper_builder.detach(); | 95 return looper_builder.detach(); |
93 } | 96 } |
94 | 97 |
95 } // namespace gfx | 98 } // namespace gfx |
OLD | NEW |