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

Side by Side Diff: trunk/Source/core/platform/graphics/DrawLooper.cpp

Issue 23507002: Revert 156733 "Refactoring DrawLooper so that it can apply shado..." (Closed) Base URL: svn://svn.chromium.org/blink/
Patch Set: Created 7 years, 3 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
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 "core/platform/graphics/DrawLooper.h" 32 #include "core/platform/graphics/DrawLooper.h"
33 33
34 #include "core/platform/graphics/Color.h" 34 #include "core/platform/graphics/Color.h"
35 #include "core/platform/graphics/FloatSize.h" 35 #include "core/platform/graphics/FloatSize.h"
36 #include "third_party/skia/include/core/SkBitmap.h"
37 #include "third_party/skia/include/core/SkColor.h" 36 #include "third_party/skia/include/core/SkColor.h"
38 #include "third_party/skia/include/core/SkColorFilter.h" 37 #include "third_party/skia/include/core/SkColorFilter.h"
39 #include "third_party/skia/include/core/SkDrawLooper.h" 38 #include "third_party/skia/include/core/SkDrawLooper.h"
40 #include "third_party/skia/include/core/SkPaint.h" 39 #include "third_party/skia/include/core/SkPaint.h"
41 #include "third_party/skia/include/core/SkXfermode.h" 40 #include "third_party/skia/include/core/SkXfermode.h"
42 #include "third_party/skia/include/effects/SkBlurMaskFilter.h" 41 #include "third_party/skia/include/effects/SkBlurMaskFilter.h"
43 #include "third_party/skia/include/effects/SkDropShadowImageFilter.h"
44 #include "third_party/skia/include/effects/SkLayerDrawLooper.h" 42 #include "third_party/skia/include/effects/SkLayerDrawLooper.h"
45 43
46 namespace WebCore { 44 namespace WebCore {
47 45
48 DrawLooper::DrawLooper() { } 46 DrawLooper::DrawLooper() : m_skDrawLooper(adoptRef(new SkLayerDrawLooper)) { }
49 47
50 DrawLooper::~DrawLooper() { } 48 DrawLooper::~DrawLooper() { }
51 49
52 SkDrawLooper* DrawLooper::skDrawLooper() const 50 SkDrawLooper* DrawLooper::skDrawLooper() const
53 { 51 {
54 if (!m_cachedDrawLooper) 52 return m_skDrawLooper.get();
55 buildCachedDrawLooper();
56 return m_cachedDrawLooper.get();
57 }
58
59 SkImageFilter* DrawLooper::imageFilter() const
60 {
61 if (!m_cachedImageFilter)
62 buildCachedImageFilter();
63 return m_cachedImageFilter.get();
64 }
65
66 void DrawLooper::clearCached()
67 {
68 m_cachedDrawLooper.clear();
69 m_cachedImageFilter.clear();
70 } 53 }
71 54
72 void DrawLooper::addUnmodifiedContent() 55 void DrawLooper::addUnmodifiedContent()
73 { 56 {
74 DrawLooperLayerInfo info; 57 SkLayerDrawLooper::LayerInfo info;
75 info.m_layerType = UnmodifiedLayer; 58 m_skDrawLooper->addLayerOnTop(info);
76 m_layerInfo.append(info);
77 clearCached();
78 } 59 }
79 60
80 void DrawLooper::addShadow(const FloatSize& offset, float blur, const Color& col or, 61 void DrawLooper::addShadow(const FloatSize& offset, float blur, const Color& col or,
81 ShadowTransformMode shadowTransformMode, ShadowAlphaMode shadowAlphaMode) 62 ShadowTransformMode shadowTransformMode, ShadowAlphaMode shadowAlphaMode)
82 { 63 {
83 // Detect when there's no effective shadow. 64 // Detect when there's no effective shadow.
84 if (!color.alpha()) 65 if (!color.alpha())
85 return; 66 return;
86 DrawLooperLayerInfo info;
87 info.m_layerType = ShadowLayer;
88 info.m_blur = blur;
89 info.m_color = color;
90 info.m_offset = offset;
91 info.m_shadowAlphaMode = shadowAlphaMode;
92 info.m_shadowTransformMode = shadowTransformMode;
93 m_layerInfo.append(info);
94 clearCached();
95 };
96 67
97 void DrawLooper::buildCachedDrawLooper() const 68 SkColor skColor = color.rgb();
98 {
99 m_cachedDrawLooper = adoptRef(new SkLayerDrawLooper);
100 LayerVector::const_iterator info;
101 for (info = m_layerInfo.begin(); info < m_layerInfo.end(); ++info) {
102 if (info->m_layerType == ShadowLayer) {
103 SkColor skColor = info->m_color.rgb();
104 69
105 SkLayerDrawLooper::LayerInfo skInfo; 70 SkLayerDrawLooper::LayerInfo info;
106 71
107 switch (info->m_shadowAlphaMode) { 72 switch (shadowAlphaMode) {
108 case ShadowRespectsAlpha: 73 case ShadowRespectsAlpha:
109 skInfo.fColorMode = SkXfermode::kDst_Mode; 74 info.fColorMode = SkXfermode::kDst_Mode;
110 break; 75 break;
111 case ShadowIgnoresAlpha: 76 case ShadowIgnoresAlpha:
112 skInfo.fColorMode = SkXfermode::kSrc_Mode; 77 info.fColorMode = SkXfermode::kSrc_Mode;
113 break; 78 break;
114 default: 79 default:
115 ASSERT_NOT_REACHED(); 80 ASSERT_NOT_REACHED();
116 } 81 }
117 82
118 if (info->m_blur) 83 if (blur)
119 skInfo.fPaintBits |= SkLayerDrawLooper::kMaskFilter_Bit; // our blur 84 info.fPaintBits |= SkLayerDrawLooper::kMaskFilter_Bit; // our blur
120 skInfo.fPaintBits |= SkLayerDrawLooper::kColorFilter_Bit; 85 info.fPaintBits |= SkLayerDrawLooper::kColorFilter_Bit;
121 skInfo.fOffset.set(info->m_offset.width(), info->m_offset.height()); 86 info.fOffset.set(offset.width(), offset.height());
122 skInfo.fPostTranslate = (info->m_shadowTransformMode == ShadowIgnore sTransforms); 87 info.fPostTranslate = (shadowTransformMode == ShadowIgnoresTransforms);
123 88
124 SkPaint* paint = m_cachedDrawLooper->addLayerOnTop(skInfo); 89 SkPaint* paint = m_skDrawLooper->addLayerOnTop(info);
125 90
126 if (info->m_blur) { 91 if (blur) {
127 uint32_t mfFlags = SkBlurMaskFilter::kHighQuality_BlurFlag; 92 uint32_t mfFlags = SkBlurMaskFilter::kHighQuality_BlurFlag;
128 if (info->m_shadowTransformMode == ShadowIgnoresTransforms) 93 if (shadowTransformMode == ShadowIgnoresTransforms)
129 mfFlags |= SkBlurMaskFilter::kIgnoreTransform_BlurFlag; 94 mfFlags |= SkBlurMaskFilter::kIgnoreTransform_BlurFlag;
130 RefPtr<SkMaskFilter> mf = adoptRef(SkBlurMaskFilter::Create( 95 RefPtr<SkMaskFilter> mf = adoptRef(SkBlurMaskFilter::Create(
131 (double)info->m_blur / 2.0, SkBlurMaskFilter::kNormal_BlurSt yle, mfFlags)); 96 (double)blur / 2.0, SkBlurMaskFilter::kNormal_BlurStyle, mfFlags));
132 paint->setMaskFilter(mf.get()); 97 paint->setMaskFilter(mf.get());
133 } 98 }
134 99
135 RefPtr<SkColorFilter> cf = adoptRef(SkColorFilter::CreateModeFilter( skColor, SkXfermode::kSrcIn_Mode)); 100 RefPtr<SkColorFilter> cf = adoptRef(SkColorFilter::CreateModeFilter(skColor, SkXfermode::kSrcIn_Mode));
136 paint->setColorFilter(cf.get()); 101 paint->setColorFilter(cf.get());
137 } else {
138 // Unmodified layer
139 SkLayerDrawLooper::LayerInfo skInfo;
140 m_cachedDrawLooper->addLayerOnTop(skInfo);
141 }
142 }
143 }
144
145 void DrawLooper::buildCachedImageFilter() const
146 {
147 ASSERT(m_layerInfo.size() == 2);
148 ASSERT(m_layerInfo[0].m_layerType == ShadowLayer);
149 ASSERT(m_layerInfo[1].m_layerType == UnmodifiedLayer);
150 ASSERT(m_layerInfo[0].m_shadowAlphaMode == ShadowRespectsAlpha);
151 ASSERT(m_layerInfo[0].m_shadowTransformMode == ShadowIgnoresTransforms);
152 const float blurToSigmaFactor = 0.25;
153 SkColor skColor = m_layerInfo[0].m_color.rgb();
154 m_cachedImageFilter = adoptRef(new SkDropShadowImageFilter(m_layerInfo[0].m_ offset.width(), m_layerInfo[0].m_offset.height(), m_layerInfo[0].m_blur * blurTo SigmaFactor, skColor));
155 }
156
157 bool DrawLooper::shouldUseImageFilterToDrawBitmap(const SkBitmap& bitmap) const
158 {
159 if (bitmap.isOpaque() || !m_layerInfo.size())
160 return false;
161
162 #if !ASSERT_DISABLED
163 // Verify that cases that require a mask filter to render correctly are of
164 // a form that can be handled by DropShadowImageFilter.
165 LayerVector::const_iterator info;
166 int unmodifiedCount = 0;
167 int shadowCount = 0;
168 bool needsFilter = false;
169 for (info = m_layerInfo.begin(); info < m_layerInfo.end(); ++info) {
170 if (info->m_layerType == ShadowLayer) {
171 needsFilter = needsFilter || (info->m_blur && info->m_shadowAlphaMod e == ShadowRespectsAlpha);
172 shadowCount++;
173 } else {
174 unmodifiedCount++;
175 }
176
177 }
178 if (needsFilter) {
179 // If any of the following assertions ever fire, it means that we are hi tting
180 // case that may not be rendered correclty by the DrawLooper and cannot be
181 // handled by DropShadowImageFilter.
182 ASSERT(shadowCount == 1);
183 ASSERT(unmodifiedCount == 1);
184 ASSERT(m_layerInfo[0].m_layerType == ShadowLayer);
185 ASSERT(m_layerInfo[0].m_shadowTransformMode == ShadowIgnoresTransforms);
186 }
187 #endif
188
189 return m_layerInfo.size() == 2
190 && m_layerInfo[0].m_layerType == ShadowLayer
191 && m_layerInfo[0].m_shadowAlphaMode == ShadowRespectsAlpha
192 && m_layerInfo[0].m_shadowTransformMode == ShadowIgnoresTransforms
193 && m_layerInfo[0].m_blur
194 && m_layerInfo[1].m_layerType == UnmodifiedLayer;
195 } 102 }
196 103
197 } // namespace WebCore 104 } // namespace WebCore
OLDNEW
« no previous file with comments | « trunk/Source/core/platform/graphics/DrawLooper.h ('k') | trunk/Source/core/platform/graphics/GraphicsContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698