OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 { | 56 { |
57 return adoptRef(m_skDrawLooperBuilder.detachLooper()); | 57 return adoptRef(m_skDrawLooperBuilder.detachLooper()); |
58 } | 58 } |
59 | 59 |
60 void DrawLooperBuilder::addUnmodifiedContent() | 60 void DrawLooperBuilder::addUnmodifiedContent() |
61 { | 61 { |
62 SkLayerDrawLooper::LayerInfo info; | 62 SkLayerDrawLooper::LayerInfo info; |
63 m_skDrawLooperBuilder.addLayerOnTop(info); | 63 m_skDrawLooperBuilder.addLayerOnTop(info); |
64 } | 64 } |
65 | 65 |
66 // This replicates the old skia behavior when it used to take radius for blur. N
ow it takes sigma. | |
67 static SkScalar RadiusToSigma(SkScalar radius) | |
68 { | |
69 SkASSERT(radius > 0); | |
70 return 0.57735f * radius + 0.5f; | |
71 } | |
72 | |
73 void DrawLooperBuilder::addShadow(const FloatSize& offset, float blur, const Col
or& color, | 66 void DrawLooperBuilder::addShadow(const FloatSize& offset, float blur, const Col
or& color, |
74 ShadowTransformMode shadowTransformMode, ShadowAlphaMode shadowAlphaMode) | 67 ShadowTransformMode shadowTransformMode, ShadowAlphaMode shadowAlphaMode) |
75 { | 68 { |
76 // Detect when there's no effective shadow. | 69 // Detect when there's no effective shadow. |
77 if (!color.alpha()) | 70 if (!color.alpha()) |
78 return; | 71 return; |
79 | 72 |
80 SkColor skColor = color.rgb(); | 73 SkColor skColor = color.rgb(); |
81 | 74 |
82 SkLayerDrawLooper::LayerInfo info; | 75 SkLayerDrawLooper::LayerInfo info; |
(...skipping 11 matching lines...) Expand all Loading... |
94 | 87 |
95 if (blur) | 88 if (blur) |
96 info.fPaintBits |= SkLayerDrawLooper::kMaskFilter_Bit; // our blur | 89 info.fPaintBits |= SkLayerDrawLooper::kMaskFilter_Bit; // our blur |
97 info.fPaintBits |= SkLayerDrawLooper::kColorFilter_Bit; | 90 info.fPaintBits |= SkLayerDrawLooper::kColorFilter_Bit; |
98 info.fOffset.set(offset.width(), offset.height()); | 91 info.fOffset.set(offset.width(), offset.height()); |
99 info.fPostTranslate = (shadowTransformMode == ShadowIgnoresTransforms); | 92 info.fPostTranslate = (shadowTransformMode == ShadowIgnoresTransforms); |
100 | 93 |
101 SkPaint* paint = m_skDrawLooperBuilder.addLayerOnTop(info); | 94 SkPaint* paint = m_skDrawLooperBuilder.addLayerOnTop(info); |
102 | 95 |
103 if (blur) { | 96 if (blur) { |
104 const SkScalar sigma = RadiusToSigma(blur / 2); | 97 const SkScalar sigma = skBlurRadiusToSigma(blur); |
105 uint32_t mfFlags = SkBlurMaskFilter::kHighQuality_BlurFlag; | 98 uint32_t mfFlags = SkBlurMaskFilter::kHighQuality_BlurFlag; |
106 if (shadowTransformMode == ShadowIgnoresTransforms) | 99 if (shadowTransformMode == ShadowIgnoresTransforms) |
107 mfFlags |= SkBlurMaskFilter::kIgnoreTransform_BlurFlag; | 100 mfFlags |= SkBlurMaskFilter::kIgnoreTransform_BlurFlag; |
108 RefPtr<SkMaskFilter> mf = adoptRef(SkBlurMaskFilter::Create(kNormal_SkBl
urStyle, sigma, mfFlags)); | 101 RefPtr<SkMaskFilter> mf = adoptRef(SkBlurMaskFilter::Create(kNormal_SkBl
urStyle, sigma, mfFlags)); |
109 paint->setMaskFilter(mf.get()); | 102 paint->setMaskFilter(mf.get()); |
110 } | 103 } |
111 | 104 |
112 RefPtr<SkColorFilter> cf = adoptRef(SkColorFilter::CreateModeFilter(skColor,
SkXfermode::kSrcIn_Mode)); | 105 RefPtr<SkColorFilter> cf = adoptRef(SkColorFilter::CreateModeFilter(skColor,
SkXfermode::kSrcIn_Mode)); |
113 paint->setColorFilter(cf.get()); | 106 paint->setColorFilter(cf.get()); |
114 } | 107 } |
115 | 108 |
116 } // namespace blink | 109 } // namespace blink |
OLD | NEW |