| 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 "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/Filter.h" | 32 #include "platform/graphics/filters/Filter.h" |
| 32 #include "platform/graphics/filters/FilterEffect.h" | 33 #include "platform/graphics/filters/FilterEffect.h" |
| 33 #include "platform/graphics/filters/SkiaImageFilterBuilder.h" | |
| 34 | 34 |
| 35 namespace blink { | 35 namespace blink { |
| 36 | 36 |
| 37 static inline FloatSize outsetSizeForBlur(float stdDeviation) { | |
| 38 IntSize kernelSize = FEGaussianBlur::calculateUnscaledKernelSize( | |
| 39 FloatPoint(stdDeviation, stdDeviation)); | |
| 40 FloatSize outset; | |
| 41 // We take the half kernel size and multiply it with three, because we run box | |
| 42 // blur three times. | |
| 43 outset.setWidth(3.0f * kernelSize.width() * 0.5f); | |
| 44 outset.setHeight(3.0f * kernelSize.height() * 0.5f); | |
| 45 return outset; | |
| 46 } | |
| 47 | |
| 48 FilterOperation* FilterOperation::blend(const FilterOperation* from, | 37 FilterOperation* FilterOperation::blend(const FilterOperation* from, |
| 49 const FilterOperation* to, | 38 const FilterOperation* to, |
| 50 double progress) { | 39 double progress) { |
| 51 DCHECK(from || to); | 40 DCHECK(from || to); |
| 52 if (to) | 41 if (to) |
| 53 return to->blend(from, progress); | 42 return to->blend(from, progress); |
| 54 return from->blend(0, 1 - progress); | 43 return from->blend(0, 1 - progress); |
| 55 } | 44 } |
| 56 | 45 |
| 57 DEFINE_TRACE(ReferenceFilterOperation) { | 46 DEFINE_TRACE(ReferenceFilterOperation) { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 case OPACITY: | 128 case OPACITY: |
| 140 result = clampTo<double>(result, 0, 1); | 129 result = clampTo<double>(result, 0, 1); |
| 141 break; | 130 break; |
| 142 default: | 131 default: |
| 143 NOTREACHED(); | 132 NOTREACHED(); |
| 144 } | 133 } |
| 145 return BasicComponentTransferFilterOperation::create(result, m_type); | 134 return BasicComponentTransferFilterOperation::create(result, m_type); |
| 146 } | 135 } |
| 147 | 136 |
| 148 FloatRect BlurFilterOperation::mapRect(const FloatRect& rect) const { | 137 FloatRect BlurFilterOperation::mapRect(const FloatRect& rect) const { |
| 149 // Matches FEGaussianBlur::mapRect. | |
| 150 float stdDeviation = floatValueForLength(m_stdDeviation, 0); | 138 float stdDeviation = floatValueForLength(m_stdDeviation, 0); |
| 151 FloatSize outsetSize = outsetSizeForBlur(stdDeviation); | 139 return FEGaussianBlur::mapEffect(FloatSize(stdDeviation, stdDeviation), rect); |
| 152 FloatRect mappedRect = rect; | |
| 153 mappedRect.inflateX(outsetSize.width()); | |
| 154 mappedRect.inflateY(outsetSize.height()); | |
| 155 return mappedRect; | |
| 156 } | 140 } |
| 157 | 141 |
| 158 FilterOperation* BlurFilterOperation::blend(const FilterOperation* from, | 142 FilterOperation* BlurFilterOperation::blend(const FilterOperation* from, |
| 159 double progress) const { | 143 double progress) const { |
| 160 LengthType lengthType = m_stdDeviation.type(); | 144 LengthType lengthType = m_stdDeviation.type(); |
| 161 if (!from) | 145 if (!from) |
| 162 return BlurFilterOperation::create(m_stdDeviation.blend( | 146 return BlurFilterOperation::create(m_stdDeviation.blend( |
| 163 Length(lengthType), progress, ValueRangeNonNegative)); | 147 Length(lengthType), progress, ValueRangeNonNegative)); |
| 164 | 148 |
| 165 const BlurFilterOperation* fromOp = toBlurFilterOperation(from); | 149 const BlurFilterOperation* fromOp = toBlurFilterOperation(from); |
| 166 return BlurFilterOperation::create(m_stdDeviation.blend( | 150 return BlurFilterOperation::create(m_stdDeviation.blend( |
| 167 fromOp->m_stdDeviation, progress, ValueRangeNonNegative)); | 151 fromOp->m_stdDeviation, progress, ValueRangeNonNegative)); |
| 168 } | 152 } |
| 169 | 153 |
| 170 FloatRect DropShadowFilterOperation::mapRect(const FloatRect& rect) const { | 154 FloatRect DropShadowFilterOperation::mapRect(const FloatRect& rect) const { |
| 171 FloatSize outsetSize = outsetSizeForBlur(m_stdDeviation); | 155 float stdDeviation = m_stdDeviation; |
| 172 FloatRect mappedRect = rect; | 156 return FEDropShadow::mapEffect(FloatSize(stdDeviation, stdDeviation), |
| 173 mappedRect.inflateX(outsetSize.width()); | 157 FloatPoint(m_location), rect); |
| 174 mappedRect.inflateY(outsetSize.height()); | |
| 175 mappedRect.moveBy(m_location); | |
| 176 mappedRect.unite(rect); | |
| 177 return mappedRect; | |
| 178 } | 158 } |
| 179 | 159 |
| 180 FilterOperation* DropShadowFilterOperation::blend(const FilterOperation* from, | 160 FilterOperation* DropShadowFilterOperation::blend(const FilterOperation* from, |
| 181 double progress) const { | 161 double progress) const { |
| 182 if (!from) { | 162 if (!from) { |
| 183 return DropShadowFilterOperation::create( | 163 return DropShadowFilterOperation::create( |
| 184 blink::blend(IntPoint(), m_location, progress), | 164 blink::blend(IntPoint(), m_location, progress), |
| 185 blink::blend(0, m_stdDeviation, progress), | 165 blink::blend(0, m_stdDeviation, progress), |
| 186 blink::blend(Color(Color::transparent), m_color, progress)); | 166 blink::blend(Color(Color::transparent), m_color, progress)); |
| 187 } | 167 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 204 } | 184 } |
| 205 | 185 |
| 206 bool BoxReflectFilterOperation::operator==(const FilterOperation& o) const { | 186 bool BoxReflectFilterOperation::operator==(const FilterOperation& o) const { |
| 207 if (!isSameType(o)) | 187 if (!isSameType(o)) |
| 208 return false; | 188 return false; |
| 209 const auto& other = static_cast<const BoxReflectFilterOperation&>(o); | 189 const auto& other = static_cast<const BoxReflectFilterOperation&>(o); |
| 210 return m_reflection == other.m_reflection; | 190 return m_reflection == other.m_reflection; |
| 211 } | 191 } |
| 212 | 192 |
| 213 } // namespace blink | 193 } // namespace blink |
| OLD | NEW |