Commit 9ef3c969 authored by estade's avatar estade Committed by Commit bot

Update last few users of deprecated CreateShadowDrawLooper and remove

it.

As a general rule, doubling the blur values passed in will yield nearly
identical visuals. The main difference is that ShadowValues::GetMargins()
will now return the correct value because of the corrected blur values.
For example, ShadowBorder will now set the correct margins. Previous to
this change, the ShadowBorders in the AppList were clipped because of
the incorrect margins.

BUG=684627,624175
TBR=sadrul@chromium.org

Review-Url: https://codereview.chromium.org/2733363002
Cr-Commit-Position: refs/heads/master@{#455672}
parent 339b2ea6
......@@ -217,7 +217,7 @@ class ScrollContentsView : public views::View {
gfx::ShadowValues shadow;
shadow.emplace_back(gfx::Vector2d(0, kShadowOffsetY), kShadowBlur,
kMenuSeparatorColor);
flags.setLooper(gfx::CreateShadowDrawLooperCorrectBlur(shadow));
flags.setLooper(gfx::CreateShadowDrawLooper(shadow));
flags.setAntiAlias(true);
canvas->ClipRect(shadowed_area, SkClipOp::kDifference);
canvas->DrawRect(shadowed_area, flags);
......
......@@ -162,8 +162,7 @@ class PartialMagnificationController::BorderRenderer
cc::PaintFlags shadow_flags;
shadow_flags.setAntiAlias(true);
shadow_flags.setColor(SK_ColorTRANSPARENT);
shadow_flags.setLooper(
gfx::CreateShadowDrawLooperCorrectBlur(magnifier_shadows_));
shadow_flags.setLooper(gfx::CreateShadowDrawLooper(magnifier_shadows_));
gfx::Rect shadow_bounds(magnifier_window_bounds_.size());
recorder.canvas()->DrawCircle(
shadow_bounds.CenterPoint(),
......
......@@ -20,7 +20,7 @@ MessageCenterFrameView::MessageCenterFrameView() {
SetBorder(views::CreateSolidBorder(
kBorderWidth, message_center::kMessageCenterBorderColor));
#else
const int kShadowBlur = 8;
const int kShadowBlur = 16;
SetBorder(std::unique_ptr<views::Border>(new views::ShadowBorder(
gfx::ShadowValue(gfx::Vector2d(0, 0), kShadowBlur,
message_center::kMessageCenterShadowColor))));
......
......@@ -277,7 +277,7 @@ void GestureNavSimple::Affordance::OnPaintLayer(
gfx::ShadowValues shadow;
shadow.emplace_back(gfx::Vector2d(0, kBgShadowOffsetY), kBgShadowBlurRadius,
kBgShadowColor);
bg_flags.setLooper(gfx::CreateShadowDrawLooperCorrectBlur(shadow));
bg_flags.setLooper(gfx::CreateShadowDrawLooper(shadow));
canvas->DrawCircle(center_point, kBackgroundRadius, bg_flags);
// Draw the arrow.
......
......@@ -154,27 +154,27 @@ gfx::ShadowValue GetShadowForZHeight(int z_height) {
switch (z_height) {
case 1:
return gfx::ShadowValue(gfx::Vector2d(0, 1), 2,
return gfx::ShadowValue(gfx::Vector2d(0, 1), 4,
SkColorSetARGB(0x4C, 0, 0, 0));
case 2:
return gfx::ShadowValue(gfx::Vector2d(0, 2), 4,
return gfx::ShadowValue(gfx::Vector2d(0, 2), 8,
SkColorSetARGB(0x33, 0, 0, 0));
default:
return gfx::ShadowValue(gfx::Vector2d(0, 8), 12,
return gfx::ShadowValue(gfx::Vector2d(0, 8), 24,
SkColorSetARGB(0x3F, 0, 0, 0));
}
}
const gfx::ShadowValues& IconStartShadows() {
CR_DEFINE_STATIC_LOCAL(const gfx::ShadowValues, icon_shadows,
(1, gfx::ShadowValue(gfx::Vector2d(0, 1), 2,
(1, gfx::ShadowValue(gfx::Vector2d(0, 1), 4,
SkColorSetARGB(0x33, 0, 0, 0))));
return icon_shadows;
}
const gfx::ShadowValues& IconEndShadows() {
CR_DEFINE_STATIC_LOCAL(const gfx::ShadowValues, icon_shadows,
(1, gfx::ShadowValue(gfx::Vector2d(0, 4), 4,
(1, gfx::ShadowValue(gfx::Vector2d(0, 4), 8,
SkColorSetARGB(0x50, 0, 0, 0))));
return icon_shadows;
}
......
......@@ -410,7 +410,7 @@ class HorizontalShadowSource : public CanvasImageSource {
// CanvasImageSource overrides:
void Draw(Canvas* canvas) override {
cc::PaintFlags flags;
flags.setLooper(CreateShadowDrawLooperCorrectBlur(shadows_));
flags.setLooper(CreateShadowDrawLooper(shadows_));
canvas->DrawRect(RectF(0, fades_down_ ? -1 : size().height(), 1, 1), flags);
}
......
......@@ -1332,7 +1332,7 @@ void RenderText::ApplyFadeEffects(internal::SkiaTextRenderer* renderer) {
}
void RenderText::ApplyTextShadows(internal::SkiaTextRenderer* renderer) {
renderer->SetDrawLooper(CreateShadowDrawLooperCorrectBlur(shadows_));
renderer->SetDrawLooper(CreateShadowDrawLooper(shadows_));
}
base::i18n::TextDirection RenderText::GetTextDirection(
......
......@@ -37,7 +37,7 @@ class ShadowNineboxSource : public CanvasImageSource {
// CanvasImageSource overrides:
void Draw(Canvas* canvas) override {
cc::PaintFlags flags;
flags.setLooper(CreateShadowDrawLooperCorrectBlur(shadows_));
flags.setLooper(CreateShadowDrawLooper(shadows_));
Insets insets = -ShadowValue::GetMargin(shadows_);
gfx::Rect bounds(size());
bounds.Inset(insets);
......
......@@ -53,13 +53,6 @@ sk_sp<cc::PaintShader> CreateGradientShader(int start_point,
grad_points, grad_colors, NULL, 2, cc::PaintShader::kClamp_TileMode));
}
// TODO(estade): remove. Only exists to support legacy CreateShadowDrawLooper.
static SkScalar DeprecatedRadiusToSigma(double radius) {
// This captures historically what skia did under the hood. Now skia accepts
// sigma, not radius, so we perform the conversion.
return radius > 0 ? SkDoubleToScalar(0.57735f * radius + 0.5) : 0;
}
// This is copied from
// third_party/WebKit/Source/platform/graphics/skia/SkiaUtils.h
static SkScalar RadiusToSigma(double radius) {
......@@ -80,41 +73,6 @@ sk_sp<SkDrawLooper> CreateShadowDrawLooper(
layer_info.fPaintBits |= SkLayerDrawLooper::kColorFilter_Bit;
layer_info.fColorMode = SkBlendMode::kSrc;
for (size_t i = 0; i < shadows.size(); ++i) {
const ShadowValue& shadow = shadows[i];
layer_info.fOffset.set(SkIntToScalar(shadow.x()),
SkIntToScalar(shadow.y()));
SkPaint* paint = looper_builder.addLayer(layer_info);
// SkBlurMaskFilter's blur radius defines the range to extend the blur from
// original mask, which is half of blur amount as defined in ShadowValue.
// Note that because this function uses DeprecatedRadiusToSigma, it actually
// creates a draw looper with roughly twice the desired blur.
paint->setMaskFilter(SkBlurMaskFilter::Make(
kNormal_SkBlurStyle, DeprecatedRadiusToSigma(shadow.blur() / 2),
SkBlurMaskFilter::kHighQuality_BlurFlag));
paint->setColorFilter(
SkColorFilter::MakeModeFilter(shadow.color(), SkBlendMode::kSrcIn));
}
return looper_builder.detach();
}
sk_sp<SkDrawLooper> CreateShadowDrawLooperCorrectBlur(
const std::vector<ShadowValue>& shadows) {
if (shadows.empty())
return nullptr;
SkLayerDrawLooper::Builder looper_builder;
looper_builder.addLayer(); // top layer of the original.
SkLayerDrawLooper::LayerInfo layer_info;
layer_info.fPaintBits |= SkLayerDrawLooper::kMaskFilter_Bit;
layer_info.fPaintBits |= SkLayerDrawLooper::kColorFilter_Bit;
layer_info.fColorMode = SkBlendMode::kSrc;
for (size_t i = 0; i < shadows.size(); ++i) {
const ShadowValue& shadow = shadows[i];
......
......@@ -47,17 +47,9 @@ GFX_EXPORT sk_sp<cc::PaintShader> CreateGradientShader(int start_point,
// Creates a draw looper to generate |shadows|. The caller owns the draw looper.
// NULL is returned if |shadows| is empty since no draw looper is needed in
// this case.
// DEPRECATED: See below. TODO(estade): remove this: crbug.com/624175
GFX_EXPORT sk_sp<SkDrawLooper> CreateShadowDrawLooper(
const std::vector<ShadowValue>& shadows);
// Creates a draw looper to generate |shadows|. This creates a looper with the
// correct amount of blur. Callers of the existing CreateShadowDrawLooper may
// rely on the wrong amount of blur being applied but new code should use this
// function.
GFX_EXPORT sk_sp<SkDrawLooper> CreateShadowDrawLooperCorrectBlur(
const std::vector<ShadowValue>& shadows);
} // namespace gfx
#endif // UI_GFX_SKIA_UTIL_H_
......@@ -168,7 +168,7 @@ void BorderShadowLayerDelegate::OnPaintLayer(const ui::PaintContext& context) {
recorder.canvas()->sk_canvas()->drawRRect(r_rect, flags);
// Now the shadow.
flags.setLooper(gfx::CreateShadowDrawLooperCorrectBlur(shadows_));
flags.setLooper(gfx::CreateShadowDrawLooper(shadows_));
recorder.canvas()->sk_canvas()->clipRRect(r_rect, SkClipOp::kDifference,
true);
recorder.canvas()->sk_canvas()->drawRRect(r_rect, flags);
......
......@@ -539,7 +539,7 @@ void BubbleBorder::PaintMd(const View& view, gfx::Canvas* canvas) {
2 * kSmallShadowBlur, kSmallShadowColor);
shadows.emplace_back(gfx::Vector2d(0, kLargeShadowVerticalOffset),
2 * kLargeShadowBlur, kLargeShadowColor);
flags.setLooper(gfx::CreateShadowDrawLooperCorrectBlur(shadows));
flags.setLooper(gfx::CreateShadowDrawLooper(shadows));
flags.setColor(SkColorSetA(SK_ColorBLACK, 0x26));
flags.setAntiAlias(true);
......
......@@ -79,7 +79,7 @@ class ToggleButton::ThumbView : public InkDropHostView {
0x99));
shadows.push_back(shadow.Scale(dsf));
cc::PaintFlags thumb_flags;
thumb_flags.setLooper(gfx::CreateShadowDrawLooperCorrectBlur(shadows));
thumb_flags.setLooper(gfx::CreateShadowDrawLooper(shadows));
thumb_flags.setAntiAlias(true);
const SkColor thumb_on_color = GetNativeTheme()->GetSystemColor(
ui::NativeTheme::kColorId_ProminentButtonColor);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment