Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: ui/gfx/skia_paint_util.cc

Issue 2928703005: Revert of cc: Move SkShader construction to a single spot in PaintShader (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/gfx/skia_paint_util.h ('k') | ui/native_theme/native_theme_base.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
8 #include "third_party/skia/include/core/SkColorFilter.h" 7 #include "third_party/skia/include/core/SkColorFilter.h"
9 #include "third_party/skia/include/effects/SkBlurMaskFilter.h" 8 #include "third_party/skia/include/effects/SkBlurMaskFilter.h"
10 #include "third_party/skia/include/effects/SkGradientShader.h" 9 #include "third_party/skia/include/effects/SkGradientShader.h"
11 #include "third_party/skia/include/effects/SkLayerDrawLooper.h" 10 #include "third_party/skia/include/effects/SkLayerDrawLooper.h"
12 #include "ui/gfx/image/image_skia_rep.h" 11 #include "ui/gfx/image/image_skia_rep.h"
13 12
14 namespace gfx { 13 namespace gfx {
15 14
16 std::unique_ptr<cc::PaintShader> CreateImageRepShader( 15 sk_sp<cc::PaintShader> CreateImageRepShader(const gfx::ImageSkiaRep& image_rep,
17 const gfx::ImageSkiaRep& image_rep, 16 cc::PaintShader::TileMode tile_mode,
18 SkShader::TileMode tile_mode, 17 const SkMatrix& local_matrix) {
19 const SkMatrix& local_matrix) { 18 return cc::WrapSkShader(CreateImageRepShaderForScale(
20 return CreateImageRepShaderForScale(image_rep, tile_mode, local_matrix, 19 image_rep, tile_mode, local_matrix, image_rep.scale()));
21 image_rep.scale());
22 } 20 }
23 21
24 std::unique_ptr<cc::PaintShader> CreateImageRepShaderForScale( 22 sk_sp<cc::PaintShader> CreateImageRepShaderForScale(
25 const gfx::ImageSkiaRep& image_rep, 23 const gfx::ImageSkiaRep& image_rep,
26 SkShader::TileMode tile_mode, 24 cc::PaintShader::TileMode tile_mode,
27 const SkMatrix& local_matrix, 25 const SkMatrix& local_matrix,
28 SkScalar scale) { 26 SkScalar scale) {
29 // 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
30 // correct density. 28 // correct density.
31 // Convert skew and translation to pixel coordinates. 29 // Convert skew and translation to pixel coordinates.
32 // Thus, for |bitmap_scale| = 2: 30 // Thus, for |bitmap_scale| = 2:
33 // x scale = 2, x translation = 1 DIP, 31 // x scale = 2, x translation = 1 DIP,
34 // should be converted to 32 // should be converted to
35 // x scale = 1, x translation = 2 pixels. 33 // x scale = 1, x translation = 2 pixels.
36 SkMatrix shader_scale = local_matrix; 34 SkMatrix shader_scale = local_matrix;
37 shader_scale.preScale(scale, scale); 35 shader_scale.preScale(scale, scale);
38 shader_scale.setScaleX(local_matrix.getScaleX() / scale); 36 shader_scale.setScaleX(local_matrix.getScaleX() / scale);
39 shader_scale.setScaleY(local_matrix.getScaleY() / scale); 37 shader_scale.setScaleY(local_matrix.getScaleY() / scale);
40 38
41 return cc::PaintShader::MakeImage( 39 return cc::PaintShader::MakeBitmapShader(image_rep.sk_bitmap(), tile_mode,
42 SkImage::MakeFromBitmap(image_rep.sk_bitmap()), tile_mode, tile_mode, 40 tile_mode, &shader_scale);
43 &shader_scale);
44 } 41 }
45 42
46 std::unique_ptr<cc::PaintShader> CreateGradientShader(int start_point, 43 sk_sp<cc::PaintShader> CreateGradientShader(int start_point,
47 int end_point, 44 int end_point,
48 SkColor start_color, 45 SkColor start_color,
49 SkColor end_color) { 46 SkColor end_color) {
50 SkColor grad_colors[2] = {start_color, end_color}; 47 SkColor grad_colors[2] = {start_color, end_color};
51 SkPoint grad_points[2]; 48 SkPoint grad_points[2];
52 grad_points[0].iset(0, start_point); 49 grad_points[0].iset(0, start_point);
53 grad_points[1].iset(0, end_point); 50 grad_points[1].iset(0, end_point);
54 51
55 return cc::PaintShader::MakeLinearGradient(grad_points, grad_colors, nullptr, 52 return cc::WrapSkShader(SkGradientShader::MakeLinear(
56 2, SkShader::kClamp_TileMode); 53 grad_points, grad_colors, NULL, 2, cc::PaintShader::kClamp_TileMode));
57 } 54 }
58 55
59 // This is copied from 56 // This is copied from
60 // third_party/WebKit/Source/platform/graphics/skia/SkiaUtils.h 57 // third_party/WebKit/Source/platform/graphics/skia/SkiaUtils.h
61 static SkScalar RadiusToSigma(double radius) { 58 static SkScalar RadiusToSigma(double radius) {
62 return radius > 0 ? SkDoubleToScalar(0.288675f * radius + 0.5f) : 0; 59 return radius > 0 ? SkDoubleToScalar(0.288675f * radius + 0.5f) : 0;
63 } 60 }
64 61
65 sk_sp<SkDrawLooper> CreateShadowDrawLooper( 62 sk_sp<SkDrawLooper> CreateShadowDrawLooper(
66 const std::vector<ShadowValue>& shadows) { 63 const std::vector<ShadowValue>& shadows) {
(...skipping 22 matching lines...) Expand all
89 kNormal_SkBlurStyle, RadiusToSigma(shadow.blur() / 2), 86 kNormal_SkBlurStyle, RadiusToSigma(shadow.blur() / 2),
90 SkBlurMaskFilter::kHighQuality_BlurFlag)); 87 SkBlurMaskFilter::kHighQuality_BlurFlag));
91 paint->setColorFilter( 88 paint->setColorFilter(
92 SkColorFilter::MakeModeFilter(shadow.color(), SkBlendMode::kSrcIn)); 89 SkColorFilter::MakeModeFilter(shadow.color(), SkBlendMode::kSrcIn));
93 } 90 }
94 91
95 return looper_builder.detach(); 92 return looper_builder.detach();
96 } 93 }
97 94
98 } // namespace gfx 95 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/skia_paint_util.h ('k') | ui/native_theme/native_theme_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698