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

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

Issue 2101863002: Adjust sizes of material design shadows based on Sebastien's feedback. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add bug link Created 4 years, 5 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_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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_util.h" 5 #include "ui/gfx/skia_util.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/numerics/safe_conversions.h" 10 #include "base/numerics/safe_conversions.h"
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 SkColor end_color) { 125 SkColor end_color) {
126 SkColor grad_colors[2] = { start_color, end_color}; 126 SkColor grad_colors[2] = { start_color, end_color};
127 SkPoint grad_points[2]; 127 SkPoint grad_points[2];
128 grad_points[0].iset(0, start_point); 128 grad_points[0].iset(0, start_point);
129 grad_points[1].iset(0, end_point); 129 grad_points[1].iset(0, end_point);
130 130
131 return SkGradientShader::MakeLinear( 131 return SkGradientShader::MakeLinear(
132 grad_points, grad_colors, NULL, 2, SkShader::kClamp_TileMode); 132 grad_points, grad_colors, NULL, 2, SkShader::kClamp_TileMode);
133 } 133 }
134 134
135 static SkScalar RadiusToSigma(double radius) { 135 // TODO(estade): remove. Only exists to support legacy CreateShadowDrawLooper.
136 static SkScalar DeprecatedRadiusToSigma(double radius) {
136 // This captures historically what skia did under the hood. Now skia accepts 137 // This captures historically what skia did under the hood. Now skia accepts
137 // sigma, not radius, so we perform the conversion. 138 // sigma, not radius, so we perform the conversion.
138 return radius > 0 ? SkDoubleToScalar(0.57735f * radius + 0.5) : 0; 139 return radius > 0 ? SkDoubleToScalar(0.57735f * radius + 0.5) : 0;
139 } 140 }
140 141
142 // This is copied from
143 // third_party/WebKit/Source/platform/graphics/skia/SkiaUtils.h
144 static SkScalar RadiusToSigma(double radius) {
145 return radius > 0 ? SkDoubleToScalar(0.288675f * radius + 0.5f) : 0;
146 }
147
141 sk_sp<SkDrawLooper> CreateShadowDrawLooper( 148 sk_sp<SkDrawLooper> CreateShadowDrawLooper(
142 const std::vector<ShadowValue>& shadows) { 149 const std::vector<ShadowValue>& shadows) {
143 if (shadows.empty()) 150 if (shadows.empty())
144 return nullptr; 151 return nullptr;
145 152
146 SkLayerDrawLooper::Builder looper_builder; 153 SkLayerDrawLooper::Builder looper_builder;
147 154
148 looper_builder.addLayer(); // top layer of the original. 155 looper_builder.addLayer(); // top layer of the original.
149 156
150 SkLayerDrawLooper::LayerInfo layer_info; 157 SkLayerDrawLooper::LayerInfo layer_info;
151 layer_info.fPaintBits |= SkLayerDrawLooper::kMaskFilter_Bit; 158 layer_info.fPaintBits |= SkLayerDrawLooper::kMaskFilter_Bit;
152 layer_info.fPaintBits |= SkLayerDrawLooper::kColorFilter_Bit; 159 layer_info.fPaintBits |= SkLayerDrawLooper::kColorFilter_Bit;
153 layer_info.fColorMode = SkXfermode::kSrc_Mode; 160 layer_info.fColorMode = SkXfermode::kSrc_Mode;
154 161
155 for (size_t i = 0; i < shadows.size(); ++i) { 162 for (size_t i = 0; i < shadows.size(); ++i) {
156 const ShadowValue& shadow = shadows[i]; 163 const ShadowValue& shadow = shadows[i];
157 164
158 layer_info.fOffset.set(SkIntToScalar(shadow.x()), 165 layer_info.fOffset.set(SkIntToScalar(shadow.x()),
159 SkIntToScalar(shadow.y())); 166 SkIntToScalar(shadow.y()));
160 167
161 SkPaint* paint = looper_builder.addLayer(layer_info); 168 SkPaint* paint = looper_builder.addLayer(layer_info);
162 // SkBlurMaskFilter's blur radius defines the range to extend the blur from 169 // SkBlurMaskFilter's blur radius defines the range to extend the blur from
163 // original mask, which is half of blur amount as defined in ShadowValue. 170 // original mask, which is half of blur amount as defined in ShadowValue.
171 // Note that because this function uses DeprecatedRadiusToSigma, it actually
172 // creates a draw looper with roughly twice the desired blur.
173 paint->setMaskFilter(SkBlurMaskFilter::Make(
174 kNormal_SkBlurStyle, DeprecatedRadiusToSigma(shadow.blur() / 2),
175 SkBlurMaskFilter::kHighQuality_BlurFlag));
176 paint->setColorFilter(
177 SkColorFilter::MakeModeFilter(shadow.color(),
178 SkXfermode::kSrcIn_Mode));
179 }
180
181 return looper_builder.detach();
182 }
183
184 sk_sp<SkDrawLooper> CreateShadowDrawLooperCorrectBlur(
185 const std::vector<ShadowValue>& shadows) {
186 if (shadows.empty())
187 return nullptr;
188
189 SkLayerDrawLooper::Builder looper_builder;
190
191 looper_builder.addLayer(); // top layer of the original.
192
193 SkLayerDrawLooper::LayerInfo layer_info;
194 layer_info.fPaintBits |= SkLayerDrawLooper::kMaskFilter_Bit;
195 layer_info.fPaintBits |= SkLayerDrawLooper::kColorFilter_Bit;
196 layer_info.fColorMode = SkXfermode::kSrc_Mode;
197
198 for (size_t i = 0; i < shadows.size(); ++i) {
199 const ShadowValue& shadow = shadows[i];
200
201 layer_info.fOffset.set(SkIntToScalar(shadow.x()),
202 SkIntToScalar(shadow.y()));
203
204 SkPaint* paint = looper_builder.addLayer(layer_info);
205 // SkBlurMaskFilter's blur radius defines the range to extend the blur from
206 // original mask, which is half of blur amount as defined in ShadowValue.
164 paint->setMaskFilter(SkBlurMaskFilter::Make( 207 paint->setMaskFilter(SkBlurMaskFilter::Make(
165 kNormal_SkBlurStyle, RadiusToSigma(shadow.blur() / 2), 208 kNormal_SkBlurStyle, RadiusToSigma(shadow.blur() / 2),
166 SkBlurMaskFilter::kHighQuality_BlurFlag)); 209 SkBlurMaskFilter::kHighQuality_BlurFlag));
167 paint->setColorFilter( 210 paint->setColorFilter(
168 SkColorFilter::MakeModeFilter(shadow.color(), 211 SkColorFilter::MakeModeFilter(shadow.color(),
169 SkXfermode::kSrcIn_Mode)); 212 SkXfermode::kSrcIn_Mode));
170 } 213 }
171 214
172 return looper_builder.detach(); 215 return looper_builder.detach();
173 } 216 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 static const SkScalar kSkToHbRatio = SK_Scalar1 / kHbUnit1; 276 static const SkScalar kSkToHbRatio = SK_Scalar1 / kHbUnit1;
234 return kSkToHbRatio * value; 277 return kSkToHbRatio * value;
235 } 278 }
236 279
237 float HarfBuzzUnitsToFloat(int value) { 280 float HarfBuzzUnitsToFloat(int value) {
238 static const float kFloatToHbRatio = 1.0f / kHbUnit1; 281 static const float kFloatToHbRatio = 1.0f / kHbUnit1;
239 return kFloatToHbRatio * value; 282 return kFloatToHbRatio * value;
240 } 283 }
241 284
242 } // namespace gfx 285 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/skia_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