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

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

Issue 2733363002: Update last few users of deprecated CreateShadowDrawLooper and remove (Closed)
Patch Set: Created 3 years, 9 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/views/animation/ink_drop_painted_layer_delegates.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 "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"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 SkColor end_color) { 46 SkColor end_color) {
47 SkColor grad_colors[2] = {start_color, end_color}; 47 SkColor grad_colors[2] = {start_color, end_color};
48 SkPoint grad_points[2]; 48 SkPoint grad_points[2];
49 grad_points[0].iset(0, start_point); 49 grad_points[0].iset(0, start_point);
50 grad_points[1].iset(0, end_point); 50 grad_points[1].iset(0, end_point);
51 51
52 return cc::WrapSkShader(SkGradientShader::MakeLinear( 52 return cc::WrapSkShader(SkGradientShader::MakeLinear(
53 grad_points, grad_colors, NULL, 2, cc::PaintShader::kClamp_TileMode)); 53 grad_points, grad_colors, NULL, 2, cc::PaintShader::kClamp_TileMode));
54 } 54 }
55 55
56 // TODO(estade): remove. Only exists to support legacy CreateShadowDrawLooper.
57 static SkScalar DeprecatedRadiusToSigma(double radius) {
58 // This captures historically what skia did under the hood. Now skia accepts
59 // sigma, not radius, so we perform the conversion.
60 return radius > 0 ? SkDoubleToScalar(0.57735f * radius + 0.5) : 0;
61 }
62
63 // This is copied from 56 // This is copied from
64 // third_party/WebKit/Source/platform/graphics/skia/SkiaUtils.h 57 // third_party/WebKit/Source/platform/graphics/skia/SkiaUtils.h
65 static SkScalar RadiusToSigma(double radius) { 58 static SkScalar RadiusToSigma(double radius) {
66 return radius > 0 ? SkDoubleToScalar(0.288675f * radius + 0.5f) : 0; 59 return radius > 0 ? SkDoubleToScalar(0.288675f * radius + 0.5f) : 0;
67 } 60 }
68 61
69 sk_sp<SkDrawLooper> CreateShadowDrawLooper( 62 sk_sp<SkDrawLooper> CreateShadowDrawLooper(
70 const std::vector<ShadowValue>& shadows) { 63 const std::vector<ShadowValue>& shadows) {
71 if (shadows.empty()) 64 if (shadows.empty())
72 return nullptr; 65 return nullptr;
73 66
74 SkLayerDrawLooper::Builder looper_builder; 67 SkLayerDrawLooper::Builder looper_builder;
75 68
76 looper_builder.addLayer(); // top layer of the original. 69 looper_builder.addLayer(); // top layer of the original.
77 70
78 SkLayerDrawLooper::LayerInfo layer_info; 71 SkLayerDrawLooper::LayerInfo layer_info;
79 layer_info.fPaintBits |= SkLayerDrawLooper::kMaskFilter_Bit; 72 layer_info.fPaintBits |= SkLayerDrawLooper::kMaskFilter_Bit;
80 layer_info.fPaintBits |= SkLayerDrawLooper::kColorFilter_Bit; 73 layer_info.fPaintBits |= SkLayerDrawLooper::kColorFilter_Bit;
81 layer_info.fColorMode = SkBlendMode::kSrc; 74 layer_info.fColorMode = SkBlendMode::kSrc;
82 75
83 for (size_t i = 0; i < shadows.size(); ++i) { 76 for (size_t i = 0; i < shadows.size(); ++i) {
84 const ShadowValue& shadow = shadows[i]; 77 const ShadowValue& shadow = shadows[i];
85 78
86 layer_info.fOffset.set(SkIntToScalar(shadow.x()), 79 layer_info.fOffset.set(SkIntToScalar(shadow.x()),
87 SkIntToScalar(shadow.y())); 80 SkIntToScalar(shadow.y()));
88 81
89 SkPaint* paint = looper_builder.addLayer(layer_info); 82 SkPaint* paint = looper_builder.addLayer(layer_info);
90 // SkBlurMaskFilter's blur radius defines the range to extend the blur from 83 // SkBlurMaskFilter's blur radius defines the range to extend the blur from
91 // original mask, which is half of blur amount as defined in ShadowValue. 84 // original mask, which is half of blur amount as defined in ShadowValue.
92 // Note that because this function uses DeprecatedRadiusToSigma, it actually
93 // creates a draw looper with roughly twice the desired blur.
94 paint->setMaskFilter(SkBlurMaskFilter::Make(
95 kNormal_SkBlurStyle, DeprecatedRadiusToSigma(shadow.blur() / 2),
96 SkBlurMaskFilter::kHighQuality_BlurFlag));
97 paint->setColorFilter(
98 SkColorFilter::MakeModeFilter(shadow.color(), SkBlendMode::kSrcIn));
99 }
100
101 return looper_builder.detach();
102 }
103
104 sk_sp<SkDrawLooper> CreateShadowDrawLooperCorrectBlur(
105 const std::vector<ShadowValue>& shadows) {
106 if (shadows.empty())
107 return nullptr;
108
109 SkLayerDrawLooper::Builder looper_builder;
110
111 looper_builder.addLayer(); // top layer of the original.
112
113 SkLayerDrawLooper::LayerInfo layer_info;
114 layer_info.fPaintBits |= SkLayerDrawLooper::kMaskFilter_Bit;
115 layer_info.fPaintBits |= SkLayerDrawLooper::kColorFilter_Bit;
116 layer_info.fColorMode = SkBlendMode::kSrc;
117
118 for (size_t i = 0; i < shadows.size(); ++i) {
119 const ShadowValue& shadow = shadows[i];
120
121 layer_info.fOffset.set(SkIntToScalar(shadow.x()),
122 SkIntToScalar(shadow.y()));
123
124 SkPaint* paint = looper_builder.addLayer(layer_info);
125 // SkBlurMaskFilter's blur radius defines the range to extend the blur from
126 // original mask, which is half of blur amount as defined in ShadowValue.
127 paint->setMaskFilter(SkBlurMaskFilter::Make( 85 paint->setMaskFilter(SkBlurMaskFilter::Make(
128 kNormal_SkBlurStyle, RadiusToSigma(shadow.blur() / 2), 86 kNormal_SkBlurStyle, RadiusToSigma(shadow.blur() / 2),
129 SkBlurMaskFilter::kHighQuality_BlurFlag)); 87 SkBlurMaskFilter::kHighQuality_BlurFlag));
130 paint->setColorFilter( 88 paint->setColorFilter(
131 SkColorFilter::MakeModeFilter(shadow.color(), SkBlendMode::kSrcIn)); 89 SkColorFilter::MakeModeFilter(shadow.color(), SkBlendMode::kSrcIn));
132 } 90 }
133 91
134 return looper_builder.detach(); 92 return looper_builder.detach();
135 } 93 }
136 94
137 } // namespace gfx 95 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/skia_paint_util.h ('k') | ui/views/animation/ink_drop_painted_layer_delegates.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698