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

Side by Side Diff: third_party/WebKit/Source/core/style/FilterOperation.cpp

Issue 2393993004: Consolidate FilterOperation and FilterEffect mapRect implementations (Closed)
Patch Set: Fixup indent; make independent Created 4 years, 2 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2011 Apple 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #include "core/style/FilterOperation.h" 26 #include "core/style/FilterOperation.h"
27 27
28 #include "platform/LengthFunctions.h" 28 #include "platform/LengthFunctions.h"
29 #include "platform/animation/AnimationUtilities.h" 29 #include "platform/animation/AnimationUtilities.h"
30 #include "platform/graphics/filters/FEDropShadow.h"
30 #include "platform/graphics/filters/FEGaussianBlur.h" 31 #include "platform/graphics/filters/FEGaussianBlur.h"
31 #include "platform/graphics/filters/FilterEffect.h" 32 #include "platform/graphics/filters/FilterEffect.h"
32 #include "platform/graphics/filters/SkiaImageFilterBuilder.h"
33 33
34 namespace blink { 34 namespace blink {
35 35
36 static inline FloatSize outsetSizeForBlur(float stdDeviation) {
37 IntSize kernelSize = FEGaussianBlur::calculateUnscaledKernelSize(
38 FloatPoint(stdDeviation, stdDeviation));
39 FloatSize outset;
40 // We take the half kernel size and multiply it with three, because we run box
41 // blur three times.
42 outset.setWidth(3.0f * kernelSize.width() * 0.5f);
43 outset.setHeight(3.0f * kernelSize.height() * 0.5f);
44 return outset;
45 }
46
47 FilterOperation* FilterOperation::blend(const FilterOperation* from, 36 FilterOperation* FilterOperation::blend(const FilterOperation* from,
48 const FilterOperation* to, 37 const FilterOperation* to,
49 double progress) { 38 double progress) {
50 DCHECK(from || to); 39 DCHECK(from || to);
51 if (to) 40 if (to)
52 return to->blend(from, progress); 41 return to->blend(from, progress);
53 return from->blend(0, 1 - progress); 42 return from->blend(0, 1 - progress);
54 } 43 }
55 44
56 DEFINE_TRACE(ReferenceFilterOperation) { 45 DEFINE_TRACE(ReferenceFilterOperation) {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 case OPACITY: 127 case OPACITY:
139 result = clampTo<double>(result, 0, 1); 128 result = clampTo<double>(result, 0, 1);
140 break; 129 break;
141 default: 130 default:
142 NOTREACHED(); 131 NOTREACHED();
143 } 132 }
144 return BasicComponentTransferFilterOperation::create(result, m_type); 133 return BasicComponentTransferFilterOperation::create(result, m_type);
145 } 134 }
146 135
147 FloatRect BlurFilterOperation::mapRect(const FloatRect& rect) const { 136 FloatRect BlurFilterOperation::mapRect(const FloatRect& rect) const {
148 // Matches FEGaussianBlur::mapRect.
149 float stdDeviation = floatValueForLength(m_stdDeviation, 0); 137 float stdDeviation = floatValueForLength(m_stdDeviation, 0);
150 FloatSize outsetSize = outsetSizeForBlur(stdDeviation); 138 return FEGaussianBlur::mapEffect(FloatSize(stdDeviation, stdDeviation), rect);
151 FloatRect mappedRect = rect;
152 mappedRect.inflateX(outsetSize.width());
153 mappedRect.inflateY(outsetSize.height());
154 return mappedRect;
155 } 139 }
156 140
157 FilterOperation* BlurFilterOperation::blend(const FilterOperation* from, 141 FilterOperation* BlurFilterOperation::blend(const FilterOperation* from,
158 double progress) const { 142 double progress) const {
159 LengthType lengthType = m_stdDeviation.type(); 143 LengthType lengthType = m_stdDeviation.type();
160 if (!from) 144 if (!from)
161 return BlurFilterOperation::create(m_stdDeviation.blend( 145 return BlurFilterOperation::create(m_stdDeviation.blend(
162 Length(lengthType), progress, ValueRangeNonNegative)); 146 Length(lengthType), progress, ValueRangeNonNegative));
163 147
164 const BlurFilterOperation* fromOp = toBlurFilterOperation(from); 148 const BlurFilterOperation* fromOp = toBlurFilterOperation(from);
165 return BlurFilterOperation::create(m_stdDeviation.blend( 149 return BlurFilterOperation::create(m_stdDeviation.blend(
166 fromOp->m_stdDeviation, progress, ValueRangeNonNegative)); 150 fromOp->m_stdDeviation, progress, ValueRangeNonNegative));
167 } 151 }
168 152
169 FloatRect DropShadowFilterOperation::mapRect(const FloatRect& rect) const { 153 FloatRect DropShadowFilterOperation::mapRect(const FloatRect& rect) const {
170 FloatSize outsetSize = outsetSizeForBlur(m_stdDeviation); 154 float stdDeviation = m_stdDeviation;
Stephen Chennney 2016/10/10 19:43:25 Why does this not do the floatValueForLength that
fs 2016/10/10 20:40:03 This caught me by surprise too, but it turns out t
171 FloatRect mappedRect = rect; 155 return FEDropShadow::mapEffect(FloatSize(stdDeviation, stdDeviation),
172 mappedRect.inflateX(outsetSize.width()); 156 FloatPoint(m_location), rect);
173 mappedRect.inflateY(outsetSize.height());
174 mappedRect.moveBy(m_location);
175 mappedRect.unite(rect);
176 return mappedRect;
177 } 157 }
178 158
179 FilterOperation* DropShadowFilterOperation::blend(const FilterOperation* from, 159 FilterOperation* DropShadowFilterOperation::blend(const FilterOperation* from,
180 double progress) const { 160 double progress) const {
181 if (!from) { 161 if (!from) {
182 return DropShadowFilterOperation::create( 162 return DropShadowFilterOperation::create(
183 blink::blend(IntPoint(), m_location, progress), 163 blink::blend(IntPoint(), m_location, progress),
184 blink::blend(0, m_stdDeviation, progress), 164 blink::blend(0, m_stdDeviation, progress),
185 blink::blend(Color(Color::transparent), m_color, progress)); 165 blink::blend(Color(Color::transparent), m_color, progress));
186 } 166 }
(...skipping 16 matching lines...) Expand all
203 } 183 }
204 184
205 bool BoxReflectFilterOperation::operator==(const FilterOperation& o) const { 185 bool BoxReflectFilterOperation::operator==(const FilterOperation& o) const {
206 if (!isSameType(o)) 186 if (!isSameType(o))
207 return false; 187 return false;
208 const auto& other = static_cast<const BoxReflectFilterOperation&>(o); 188 const auto& other = static_cast<const BoxReflectFilterOperation&>(o);
209 return m_reflection == other.m_reflection; 189 return m_reflection == other.m_reflection;
210 } 190 }
211 191
212 } // namespace blink 192 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698