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 "third_party/skia/include/core/SkColorFilter.h" | 7 #include "third_party/skia/include/core/SkColorFilter.h" |
8 #include "third_party/skia/include/effects/SkBlurMaskFilter.h" | 8 #include "third_party/skia/include/effects/SkBlurMaskFilter.h" |
9 #include "third_party/skia/include/effects/SkGradientShader.h" | 9 #include "third_party/skia/include/effects/SkGradientShader.h" |
10 #include "third_party/skia/include/effects/SkLayerDrawLooper.h" | 10 #include "third_party/skia/include/effects/SkLayerDrawLooper.h" |
11 #include "ui/gfx/image/image_skia_rep.h" | 11 #include "ui/gfx/image/image_skia_rep.h" |
12 | 12 |
13 namespace gfx { | 13 namespace gfx { |
14 | 14 |
15 sk_sp<SkShader> CreateImageRepShader(const gfx::ImageSkiaRep& image_rep, | 15 sk_sp<cc::PaintShader> CreateImageRepShader(const gfx::ImageSkiaRep& image_rep, |
16 SkShader::TileMode tile_mode, | 16 cc::PaintShader::TileMode tile_mode, |
17 const SkMatrix& local_matrix) { | 17 const SkMatrix& local_matrix) { |
18 return CreateImageRepShaderForScale(image_rep, tile_mode, local_matrix, | 18 return cc::WrapSkShader(CreateImageRepShaderForScale( |
19 image_rep.scale()); | 19 image_rep, tile_mode, local_matrix, image_rep.scale())); |
20 } | 20 } |
21 | 21 |
22 sk_sp<SkShader> CreateImageRepShaderForScale(const gfx::ImageSkiaRep& image_rep, | 22 sk_sp<cc::PaintShader> CreateImageRepShaderForScale( |
23 SkShader::TileMode tile_mode, | 23 const gfx::ImageSkiaRep& image_rep, |
24 const SkMatrix& local_matrix, | 24 cc::PaintShader::TileMode tile_mode, |
25 SkScalar scale) { | 25 const SkMatrix& local_matrix, |
| 26 SkScalar scale) { |
26 // Unscale matrix by |scale| such that the bitmap is drawn at the | 27 // Unscale matrix by |scale| such that the bitmap is drawn at the |
27 // correct density. | 28 // correct density. |
28 // Convert skew and translation to pixel coordinates. | 29 // Convert skew and translation to pixel coordinates. |
29 // Thus, for |bitmap_scale| = 2: | 30 // Thus, for |bitmap_scale| = 2: |
30 // x scale = 2, x translation = 1 DIP, | 31 // x scale = 2, x translation = 1 DIP, |
31 // should be converted to | 32 // should be converted to |
32 // x scale = 1, x translation = 2 pixels. | 33 // x scale = 1, x translation = 2 pixels. |
33 SkMatrix shader_scale = local_matrix; | 34 SkMatrix shader_scale = local_matrix; |
34 shader_scale.preScale(scale, scale); | 35 shader_scale.preScale(scale, scale); |
35 shader_scale.setScaleX(local_matrix.getScaleX() / scale); | 36 shader_scale.setScaleX(local_matrix.getScaleX() / scale); |
36 shader_scale.setScaleY(local_matrix.getScaleY() / scale); | 37 shader_scale.setScaleY(local_matrix.getScaleY() / scale); |
37 | 38 |
38 return SkShader::MakeBitmapShader(image_rep.sk_bitmap(), tile_mode, tile_mode, | 39 return cc::PaintShader::MakeBitmapShader(image_rep.sk_bitmap(), tile_mode, |
39 &shader_scale); | 40 tile_mode, &shader_scale); |
40 } | 41 } |
41 | 42 |
42 sk_sp<SkShader> CreateGradientShader(int start_point, | 43 sk_sp<cc::PaintShader> CreateGradientShader(int start_point, |
43 int end_point, | 44 int end_point, |
44 SkColor start_color, | 45 SkColor start_color, |
45 SkColor end_color) { | 46 SkColor end_color) { |
46 SkColor grad_colors[2] = {start_color, end_color}; | 47 SkColor grad_colors[2] = {start_color, end_color}; |
47 SkPoint grad_points[2]; | 48 SkPoint grad_points[2]; |
48 grad_points[0].iset(0, start_point); | 49 grad_points[0].iset(0, start_point); |
49 grad_points[1].iset(0, end_point); | 50 grad_points[1].iset(0, end_point); |
50 | 51 |
51 return SkGradientShader::MakeLinear(grad_points, grad_colors, NULL, 2, | 52 return cc::WrapSkShader(SkGradientShader::MakeLinear( |
52 SkShader::kClamp_TileMode); | 53 grad_points, grad_colors, NULL, 2, cc::PaintShader::kClamp_TileMode)); |
53 } | 54 } |
54 | 55 |
55 // TODO(estade): remove. Only exists to support legacy CreateShadowDrawLooper. | 56 // TODO(estade): remove. Only exists to support legacy CreateShadowDrawLooper. |
56 static SkScalar DeprecatedRadiusToSigma(double radius) { | 57 static SkScalar DeprecatedRadiusToSigma(double radius) { |
57 // This captures historically what skia did under the hood. Now skia accepts | 58 // This captures historically what skia did under the hood. Now skia accepts |
58 // sigma, not radius, so we perform the conversion. | 59 // sigma, not radius, so we perform the conversion. |
59 return radius > 0 ? SkDoubleToScalar(0.57735f * radius + 0.5) : 0; | 60 return radius > 0 ? SkDoubleToScalar(0.57735f * radius + 0.5) : 0; |
60 } | 61 } |
61 | 62 |
62 // This is copied from | 63 // This is copied from |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 kNormal_SkBlurStyle, RadiusToSigma(shadow.blur() / 2), | 128 kNormal_SkBlurStyle, RadiusToSigma(shadow.blur() / 2), |
128 SkBlurMaskFilter::kHighQuality_BlurFlag)); | 129 SkBlurMaskFilter::kHighQuality_BlurFlag)); |
129 paint->setColorFilter( | 130 paint->setColorFilter( |
130 SkColorFilter::MakeModeFilter(shadow.color(), SkBlendMode::kSrcIn)); | 131 SkColorFilter::MakeModeFilter(shadow.color(), SkBlendMode::kSrcIn)); |
131 } | 132 } |
132 | 133 |
133 return looper_builder.detach(); | 134 return looper_builder.detach(); |
134 } | 135 } |
135 | 136 |
136 } // namespace gfx | 137 } // namespace gfx |
OLD | NEW |