OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2011 Apple Inc. All rights reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions | |
6 * are met: | |
7 * 1. Redistributions of source code must retain the above copyright | |
8 * notice, this list of conditions and the following disclaimer. | |
9 * 2. Redistributions in binary form must reproduce the above copyright | |
10 * notice, this list of conditions and the following disclaimer in the | |
11 * documentation and/or other materials provided with the distribution. | |
12 * | |
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | |
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
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. | |
24 */ | |
25 | |
26 #include "platform/graphics/filters/FilterOperation.h" | |
27 | |
28 #include "platform/LengthFunctions.h" | |
29 #include "platform/animation/AnimationUtilities.h" | |
30 #include "platform/graphics/filters/FEGaussianBlur.h" | |
31 #include "platform/graphics/filters/FilterEffect.h" | |
32 #include "platform/graphics/filters/SkiaImageFilterBuilder.h" | |
33 | |
34 namespace blink { | |
35 | |
36 static inline FloatSize outsetSizeForBlur(float stdDeviation) | |
37 { | |
38 IntSize kernelSize = FEGaussianBlur::calculateUnscaledKernelSize(FloatPoint(
stdDeviation, stdDeviation)); | |
39 FloatSize outset; | |
40 // We take the half kernel size and multiply it with three, because we run b
ox blur three times. | |
41 outset.setWidth(3.0f * kernelSize.width() * 0.5f); | |
42 outset.setHeight(3.0f * kernelSize.height() * 0.5f); | |
43 return outset; | |
44 } | |
45 | |
46 FilterOperation* FilterOperation::blend(const FilterOperation* from, const Filte
rOperation* to, double progress) | |
47 { | |
48 ASSERT(from || to); | |
49 if (to) | |
50 return to->blend(from, progress); | |
51 return from->blend(0, 1 - progress); | |
52 } | |
53 | |
54 DEFINE_TRACE(ReferenceFilterOperation) | |
55 { | |
56 visitor->trace(m_filter); | |
57 FilterOperation::trace(visitor); | |
58 } | |
59 | |
60 FloatRect ReferenceFilterOperation::mapRect(const FloatRect& rect) const | |
61 { | |
62 const auto* lastEffect = m_filter ? m_filter->lastEffect() : nullptr; | |
63 if (!lastEffect) | |
64 return rect; | |
65 return lastEffect->mapRect(rect); | |
66 } | |
67 | |
68 FilterOperation* BasicColorMatrixFilterOperation::blend(const FilterOperation* f
rom, double progress) const | |
69 { | |
70 double fromAmount; | |
71 if (from) { | |
72 ASSERT_WITH_SECURITY_IMPLICATION(from->isSameType(*this)); | |
73 fromAmount = toBasicColorMatrixFilterOperation(from)->amount(); | |
74 } else { | |
75 switch (m_type) { | |
76 case GRAYSCALE: | |
77 case SEPIA: | |
78 case HUE_ROTATE: | |
79 fromAmount = 0; | |
80 break; | |
81 case SATURATE: | |
82 fromAmount = 1; | |
83 break; | |
84 default: | |
85 fromAmount = 0; | |
86 ASSERT_NOT_REACHED(); | |
87 } | |
88 } | |
89 | |
90 double result = blink::blend(fromAmount, m_amount, progress); | |
91 switch (m_type) { | |
92 case HUE_ROTATE: | |
93 break; | |
94 case GRAYSCALE: | |
95 case SEPIA: | |
96 result = clampTo<double>(result, 0, 1); | |
97 break; | |
98 case SATURATE: | |
99 result = clampTo<double>(result, 0); | |
100 break; | |
101 default: | |
102 ASSERT_NOT_REACHED(); | |
103 } | |
104 return BasicColorMatrixFilterOperation::create(result, m_type); | |
105 } | |
106 | |
107 FilterOperation* BasicComponentTransferFilterOperation::blend(const FilterOperat
ion* from, double progress) const | |
108 { | |
109 double fromAmount; | |
110 if (from) { | |
111 ASSERT_WITH_SECURITY_IMPLICATION(from->isSameType(*this)); | |
112 fromAmount = toBasicComponentTransferFilterOperation(from)->amount(); | |
113 } else { | |
114 switch (m_type) { | |
115 case OPACITY: | |
116 case CONTRAST: | |
117 case BRIGHTNESS: | |
118 fromAmount = 1; | |
119 break; | |
120 case INVERT: | |
121 fromAmount = 0; | |
122 break; | |
123 default: | |
124 fromAmount = 0; | |
125 ASSERT_NOT_REACHED(); | |
126 } | |
127 } | |
128 | |
129 double result = blink::blend(fromAmount, m_amount, progress); | |
130 switch (m_type) { | |
131 case BRIGHTNESS: | |
132 case CONTRAST: | |
133 result = clampTo<double>(result, 0); | |
134 break; | |
135 case INVERT: | |
136 case OPACITY: | |
137 result = clampTo<double>(result, 0, 1); | |
138 break; | |
139 default: | |
140 ASSERT_NOT_REACHED(); | |
141 } | |
142 return BasicComponentTransferFilterOperation::create(result, m_type); | |
143 } | |
144 | |
145 FloatRect BlurFilterOperation::mapRect(const FloatRect& rect) const | |
146 { | |
147 // Matches FEGaussianBlur::mapRect. | |
148 float stdDeviation = floatValueForLength(m_stdDeviation, 0); | |
149 FloatSize outsetSize = outsetSizeForBlur(stdDeviation); | |
150 FloatRect mappedRect = rect; | |
151 mappedRect.inflateX(outsetSize.width()); | |
152 mappedRect.inflateY(outsetSize.height()); | |
153 return mappedRect; | |
154 } | |
155 | |
156 FilterOperation* BlurFilterOperation::blend(const FilterOperation* from, double
progress) const | |
157 { | |
158 LengthType lengthType = m_stdDeviation.type(); | |
159 if (!from) | |
160 return BlurFilterOperation::create(m_stdDeviation.blend(Length(lengthTyp
e), progress, ValueRangeNonNegative)); | |
161 | |
162 const BlurFilterOperation* fromOp = toBlurFilterOperation(from); | |
163 return BlurFilterOperation::create(m_stdDeviation.blend(fromOp->m_stdDeviati
on, progress, ValueRangeNonNegative)); | |
164 } | |
165 | |
166 FloatRect DropShadowFilterOperation::mapRect(const FloatRect& rect) const | |
167 { | |
168 FloatSize outsetSize = outsetSizeForBlur(m_stdDeviation); | |
169 FloatRect mappedRect = rect; | |
170 mappedRect.inflateX(outsetSize.width()); | |
171 mappedRect.inflateY(outsetSize.height()); | |
172 mappedRect.moveBy(m_location); | |
173 mappedRect.unite(rect); | |
174 return mappedRect; | |
175 } | |
176 | |
177 FilterOperation* DropShadowFilterOperation::blend(const FilterOperation* from, d
ouble progress) const | |
178 { | |
179 if (!from) { | |
180 return DropShadowFilterOperation::create( | |
181 blink::blend(IntPoint(), m_location, progress), | |
182 blink::blend(0, m_stdDeviation, progress), | |
183 blink::blend(Color(Color::transparent), m_color, progress)); | |
184 } | |
185 | |
186 const DropShadowFilterOperation* fromOp = toDropShadowFilterOperation(from); | |
187 return DropShadowFilterOperation::create( | |
188 blink::blend(fromOp->location(), m_location, progress), | |
189 blink::blend(fromOp->stdDeviation(), m_stdDeviation, progress), | |
190 blink::blend(fromOp->getColor(), m_color, progress)); | |
191 } | |
192 | |
193 FloatRect BoxReflectFilterOperation::mapRect(const FloatRect& rect) const | |
194 { | |
195 return m_reflection.mapRect(rect); | |
196 } | |
197 | |
198 FilterOperation* BoxReflectFilterOperation::blend(const FilterOperation* from, d
ouble progress) const | |
199 { | |
200 ASSERT_NOT_REACHED(); | |
201 return nullptr; | |
202 } | |
203 | |
204 bool BoxReflectFilterOperation::operator==(const FilterOperation& o) const | |
205 { | |
206 if (!isSameType(o)) | |
207 return false; | |
208 const auto& other = static_cast<const BoxReflectFilterOperation&>(o); | |
209 return m_reflection == other.m_reflection; | |
210 } | |
211 | |
212 } // namespace blink | |
213 | |
OLD | NEW |