OLD | NEW |
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 "platform/graphics/filters/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/FEGaussianBlur.h" | 30 #include "platform/graphics/filters/FEGaussianBlur.h" |
31 #include "platform/graphics/filters/FilterEffect.h" | 31 #include "platform/graphics/filters/FilterEffect.h" |
32 #include "platform/graphics/filters/SkiaImageFilterBuilder.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) | 36 static inline FloatSize outsetSizeForBlur(float stdDeviation) |
37 { | 37 { |
38 IntSize kernelSize = FEGaussianBlur::calculateUnscaledKernelSize(FloatPoint(
stdDeviation, stdDeviation)); | 38 IntSize kernelSize = FEGaussianBlur::calculateUnscaledKernelSize(FloatPoint(
stdDeviation, stdDeviation)); |
39 FloatSize outset; | 39 FloatSize outset; |
40 // We take the half kernel size and multiply it with three, because we run b
ox blur three times. | 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); | 41 outset.setWidth(3.0f * kernelSize.width() * 0.5f); |
42 outset.setHeight(3.0f * kernelSize.height() * 0.5f); | 42 outset.setHeight(3.0f * kernelSize.height() * 0.5f); |
43 return outset; | 43 return outset; |
44 } | 44 } |
45 | 45 |
46 FilterOperation* FilterOperation::blend(const FilterOperation* from, const Filte
rOperation* to, double progress) | 46 FilterOperation* FilterOperation::blend(const FilterOperation* from, const Filte
rOperation* to, double progress) |
47 { | 47 { |
48 ASSERT(from || to); | 48 DCHECK(from || to); |
49 if (to) | 49 if (to) |
50 return to->blend(from, progress); | 50 return to->blend(from, progress); |
51 return from->blend(0, 1 - progress); | 51 return from->blend(0, 1 - progress); |
52 } | 52 } |
53 | 53 |
54 DEFINE_TRACE(ReferenceFilterOperation) | 54 DEFINE_TRACE(ReferenceFilterOperation) |
55 { | 55 { |
56 visitor->trace(m_filter); | 56 visitor->trace(m_filter); |
57 FilterOperation::trace(visitor); | 57 FilterOperation::trace(visitor); |
58 } | 58 } |
59 | 59 |
60 FloatRect ReferenceFilterOperation::mapRect(const FloatRect& rect) const | 60 FloatRect ReferenceFilterOperation::mapRect(const FloatRect& rect) const |
61 { | 61 { |
62 const auto* lastEffect = m_filter ? m_filter->lastEffect() : nullptr; | 62 const auto* lastEffect = m_filter ? m_filter->lastEffect() : nullptr; |
63 if (!lastEffect) | 63 if (!lastEffect) |
64 return rect; | 64 return rect; |
65 return lastEffect->mapRect(rect); | 65 return lastEffect->mapRect(rect); |
66 } | 66 } |
67 | 67 |
68 FilterOperation* BasicColorMatrixFilterOperation::blend(const FilterOperation* f
rom, double progress) const | 68 FilterOperation* BasicColorMatrixFilterOperation::blend(const FilterOperation* f
rom, double progress) const |
69 { | 69 { |
70 double fromAmount; | 70 double fromAmount; |
71 if (from) { | 71 if (from) { |
72 ASSERT_WITH_SECURITY_IMPLICATION(from->isSameType(*this)); | 72 SECURITY_DCHECK(from->isSameType(*this)); |
73 fromAmount = toBasicColorMatrixFilterOperation(from)->amount(); | 73 fromAmount = toBasicColorMatrixFilterOperation(from)->amount(); |
74 } else { | 74 } else { |
75 switch (m_type) { | 75 switch (m_type) { |
76 case GRAYSCALE: | 76 case GRAYSCALE: |
77 case SEPIA: | 77 case SEPIA: |
78 case HUE_ROTATE: | 78 case HUE_ROTATE: |
79 fromAmount = 0; | 79 fromAmount = 0; |
80 break; | 80 break; |
81 case SATURATE: | 81 case SATURATE: |
82 fromAmount = 1; | 82 fromAmount = 1; |
83 break; | 83 break; |
84 default: | 84 default: |
85 fromAmount = 0; | 85 fromAmount = 0; |
86 ASSERT_NOT_REACHED(); | 86 NOTREACHED(); |
87 } | 87 } |
88 } | 88 } |
89 | 89 |
90 double result = blink::blend(fromAmount, m_amount, progress); | 90 double result = blink::blend(fromAmount, m_amount, progress); |
91 switch (m_type) { | 91 switch (m_type) { |
92 case HUE_ROTATE: | 92 case HUE_ROTATE: |
93 break; | 93 break; |
94 case GRAYSCALE: | 94 case GRAYSCALE: |
95 case SEPIA: | 95 case SEPIA: |
96 result = clampTo<double>(result, 0, 1); | 96 result = clampTo<double>(result, 0, 1); |
97 break; | 97 break; |
98 case SATURATE: | 98 case SATURATE: |
99 result = clampTo<double>(result, 0); | 99 result = clampTo<double>(result, 0); |
100 break; | 100 break; |
101 default: | 101 default: |
102 ASSERT_NOT_REACHED(); | 102 NOTREACHED(); |
103 } | 103 } |
104 return BasicColorMatrixFilterOperation::create(result, m_type); | 104 return BasicColorMatrixFilterOperation::create(result, m_type); |
105 } | 105 } |
106 | 106 |
107 FilterOperation* BasicComponentTransferFilterOperation::blend(const FilterOperat
ion* from, double progress) const | 107 FilterOperation* BasicComponentTransferFilterOperation::blend(const FilterOperat
ion* from, double progress) const |
108 { | 108 { |
109 double fromAmount; | 109 double fromAmount; |
110 if (from) { | 110 if (from) { |
111 ASSERT_WITH_SECURITY_IMPLICATION(from->isSameType(*this)); | 111 SECURITY_DCHECK(from->isSameType(*this)); |
112 fromAmount = toBasicComponentTransferFilterOperation(from)->amount(); | 112 fromAmount = toBasicComponentTransferFilterOperation(from)->amount(); |
113 } else { | 113 } else { |
114 switch (m_type) { | 114 switch (m_type) { |
115 case OPACITY: | 115 case OPACITY: |
116 case CONTRAST: | 116 case CONTRAST: |
117 case BRIGHTNESS: | 117 case BRIGHTNESS: |
118 fromAmount = 1; | 118 fromAmount = 1; |
119 break; | 119 break; |
120 case INVERT: | 120 case INVERT: |
121 fromAmount = 0; | 121 fromAmount = 0; |
122 break; | 122 break; |
123 default: | 123 default: |
124 fromAmount = 0; | 124 fromAmount = 0; |
125 ASSERT_NOT_REACHED(); | 125 NOTREACHED(); |
126 } | 126 } |
127 } | 127 } |
128 | 128 |
129 double result = blink::blend(fromAmount, m_amount, progress); | 129 double result = blink::blend(fromAmount, m_amount, progress); |
130 switch (m_type) { | 130 switch (m_type) { |
131 case BRIGHTNESS: | 131 case BRIGHTNESS: |
132 case CONTRAST: | 132 case CONTRAST: |
133 result = clampTo<double>(result, 0); | 133 result = clampTo<double>(result, 0); |
134 break; | 134 break; |
135 case INVERT: | 135 case INVERT: |
136 case OPACITY: | 136 case OPACITY: |
137 result = clampTo<double>(result, 0, 1); | 137 result = clampTo<double>(result, 0, 1); |
138 break; | 138 break; |
139 default: | 139 default: |
140 ASSERT_NOT_REACHED(); | 140 NOTREACHED(); |
141 } | 141 } |
142 return BasicComponentTransferFilterOperation::create(result, m_type); | 142 return BasicComponentTransferFilterOperation::create(result, m_type); |
143 } | 143 } |
144 | 144 |
145 FloatRect BlurFilterOperation::mapRect(const FloatRect& rect) const | 145 FloatRect BlurFilterOperation::mapRect(const FloatRect& rect) const |
146 { | 146 { |
147 // Matches FEGaussianBlur::mapRect. | 147 // Matches FEGaussianBlur::mapRect. |
148 float stdDeviation = floatValueForLength(m_stdDeviation, 0); | 148 float stdDeviation = floatValueForLength(m_stdDeviation, 0); |
149 FloatSize outsetSize = outsetSizeForBlur(stdDeviation); | 149 FloatSize outsetSize = outsetSizeForBlur(stdDeviation); |
150 FloatRect mappedRect = rect; | 150 FloatRect mappedRect = rect; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 blink::blend(fromOp->getColor(), m_color, progress)); | 190 blink::blend(fromOp->getColor(), m_color, progress)); |
191 } | 191 } |
192 | 192 |
193 FloatRect BoxReflectFilterOperation::mapRect(const FloatRect& rect) const | 193 FloatRect BoxReflectFilterOperation::mapRect(const FloatRect& rect) const |
194 { | 194 { |
195 return m_reflection.mapRect(rect); | 195 return m_reflection.mapRect(rect); |
196 } | 196 } |
197 | 197 |
198 FilterOperation* BoxReflectFilterOperation::blend(const FilterOperation* from, d
ouble progress) const | 198 FilterOperation* BoxReflectFilterOperation::blend(const FilterOperation* from, d
ouble progress) const |
199 { | 199 { |
200 ASSERT_NOT_REACHED(); | 200 NOTREACHED(); |
201 return nullptr; | 201 return nullptr; |
202 } | 202 } |
203 | 203 |
204 bool BoxReflectFilterOperation::operator==(const FilterOperation& o) const | 204 bool BoxReflectFilterOperation::operator==(const FilterOperation& o) const |
205 { | 205 { |
206 if (!isSameType(o)) | 206 if (!isSameType(o)) |
207 return false; | 207 return false; |
208 const auto& other = static_cast<const BoxReflectFilterOperation&>(o); | 208 const auto& other = static_cast<const BoxReflectFilterOperation&>(o); |
209 return m_reflection == other.m_reflection; | 209 return m_reflection == other.m_reflection; |
210 } | 210 } |
211 | 211 |
212 } // namespace blink | 212 } // namespace blink |
213 | 213 |
OLD | NEW |