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

Side by Side Diff: Source/platform/graphics/DrawLooperBuilder.cpp

Issue 1008173003: Move SkPaint mangement for 2D canvas into CanvasRenderingContext2DState (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: applied review comments Created 5 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/html/canvas/CanvasStyle.cpp ('k') | Source/platform/graphics/GraphicsTypes.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 15 matching lines...) Expand all
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "platform/graphics/DrawLooperBuilder.h" 32 #include "platform/graphics/DrawLooperBuilder.h"
33 33
34 #include "platform/geometry/FloatSize.h" 34 #include "platform/geometry/FloatSize.h"
35 #include "platform/graphics/Color.h" 35 #include "platform/graphics/Color.h"
36 #include "platform/graphics/skia/SkiaUtils.h"
36 #include "third_party/skia/include/core/SkColor.h" 37 #include "third_party/skia/include/core/SkColor.h"
37 #include "third_party/skia/include/core/SkColorFilter.h" 38 #include "third_party/skia/include/core/SkColorFilter.h"
38 #include "third_party/skia/include/core/SkDrawLooper.h" 39 #include "third_party/skia/include/core/SkDrawLooper.h"
39 #include "third_party/skia/include/core/SkPaint.h" 40 #include "third_party/skia/include/core/SkPaint.h"
40 #include "third_party/skia/include/core/SkXfermode.h" 41 #include "third_party/skia/include/core/SkXfermode.h"
41 #include "third_party/skia/include/effects/SkBlurMaskFilter.h" 42 #include "third_party/skia/include/effects/SkBlurMaskFilter.h"
42 #include "wtf/RefPtr.h" 43 #include "wtf/RefPtr.h"
43 44
44 namespace blink { 45 namespace blink {
45 46
(...skipping 10 matching lines...) Expand all
56 { 57 {
57 return adoptRef(m_skDrawLooperBuilder.detachLooper()); 58 return adoptRef(m_skDrawLooperBuilder.detachLooper());
58 } 59 }
59 60
60 void DrawLooperBuilder::addUnmodifiedContent() 61 void DrawLooperBuilder::addUnmodifiedContent()
61 { 62 {
62 SkLayerDrawLooper::LayerInfo info; 63 SkLayerDrawLooper::LayerInfo info;
63 m_skDrawLooperBuilder.addLayerOnTop(info); 64 m_skDrawLooperBuilder.addLayerOnTop(info);
64 } 65 }
65 66
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, 67 void DrawLooperBuilder::addShadow(const FloatSize& offset, float blur, const Col or& color,
74 ShadowTransformMode shadowTransformMode, ShadowAlphaMode shadowAlphaMode) 68 ShadowTransformMode shadowTransformMode, ShadowAlphaMode shadowAlphaMode)
75 { 69 {
76 // Detect when there's no effective shadow. 70 // Detect when there's no effective shadow.
77 if (!color.alpha()) 71 if (!color.alpha())
78 return; 72 return;
79 73
80 SkColor skColor = color.rgb(); 74 SkColor skColor = color.rgb();
81 75
82 SkLayerDrawLooper::LayerInfo info; 76 SkLayerDrawLooper::LayerInfo info;
(...skipping 11 matching lines...) Expand all
94 88
95 if (blur) 89 if (blur)
96 info.fPaintBits |= SkLayerDrawLooper::kMaskFilter_Bit; // our blur 90 info.fPaintBits |= SkLayerDrawLooper::kMaskFilter_Bit; // our blur
97 info.fPaintBits |= SkLayerDrawLooper::kColorFilter_Bit; 91 info.fPaintBits |= SkLayerDrawLooper::kColorFilter_Bit;
98 info.fOffset.set(offset.width(), offset.height()); 92 info.fOffset.set(offset.width(), offset.height());
99 info.fPostTranslate = (shadowTransformMode == ShadowIgnoresTransforms); 93 info.fPostTranslate = (shadowTransformMode == ShadowIgnoresTransforms);
100 94
101 SkPaint* paint = m_skDrawLooperBuilder.addLayerOnTop(info); 95 SkPaint* paint = m_skDrawLooperBuilder.addLayerOnTop(info);
102 96
103 if (blur) { 97 if (blur) {
104 const SkScalar sigma = RadiusToSigma(blur / 2); 98 const SkScalar sigma = skBlurRadiusToSigma(blur);
105 uint32_t mfFlags = SkBlurMaskFilter::kHighQuality_BlurFlag; 99 uint32_t mfFlags = SkBlurMaskFilter::kHighQuality_BlurFlag;
106 if (shadowTransformMode == ShadowIgnoresTransforms) 100 if (shadowTransformMode == ShadowIgnoresTransforms)
107 mfFlags |= SkBlurMaskFilter::kIgnoreTransform_BlurFlag; 101 mfFlags |= SkBlurMaskFilter::kIgnoreTransform_BlurFlag;
108 RefPtr<SkMaskFilter> mf = adoptRef(SkBlurMaskFilter::Create(kNormal_SkBl urStyle, sigma, mfFlags)); 102 RefPtr<SkMaskFilter> mf = adoptRef(SkBlurMaskFilter::Create(kNormal_SkBl urStyle, sigma, mfFlags));
109 paint->setMaskFilter(mf.get()); 103 paint->setMaskFilter(mf.get());
110 } 104 }
111 105
112 RefPtr<SkColorFilter> cf = adoptRef(SkColorFilter::CreateModeFilter(skColor, SkXfermode::kSrcIn_Mode)); 106 RefPtr<SkColorFilter> cf = adoptRef(SkColorFilter::CreateModeFilter(skColor, SkXfermode::kSrcIn_Mode));
113 paint->setColorFilter(cf.get()); 107 paint->setColorFilter(cf.get());
114 } 108 }
115 109
116 } // namespace blink 110 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/html/canvas/CanvasStyle.cpp ('k') | Source/platform/graphics/GraphicsTypes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698