| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2011 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2013 Google Inc. All rights reserved. | 3 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| 11 * notice, this list of conditions and the following disclaimer in the | 11 * notice, this list of conditions and the following disclaimer in the |
| 12 * documentation and/or other materials provided with the distribution. | 12 * documentation and/or other materials provided with the distribution. |
| 13 * | 13 * |
| 14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | 14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
| 18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 */ | 25 */ |
| 26 | 26 |
| 27 #include "core/paint/FilterEffectBuilder.h" | 27 #include "core/paint/FilterEffectBuilder.h" |
| 28 | 28 |
| 29 #include "core/layout/svg/ReferenceFilterBuilder.h" | 29 #include "core/layout/svg/ReferenceFilterBuilder.h" |
| 30 #include "core/paint/PaintLayer.h" | |
| 31 #include "core/svg/SVGFilterElement.h" | 30 #include "core/svg/SVGFilterElement.h" |
| 32 #include "core/svg/SVGLengthContext.h" | 31 #include "core/svg/SVGLengthContext.h" |
| 33 #include "core/svg/graphics/filters/SVGFilterBuilder.h" | 32 #include "core/svg/graphics/filters/SVGFilterBuilder.h" |
| 34 #include "platform/LengthFunctions.h" | 33 #include "platform/LengthFunctions.h" |
| 35 #include "platform/graphics/ColorSpace.h" | 34 #include "platform/graphics/ColorSpace.h" |
| 36 #include "platform/graphics/filters/FEBoxReflect.h" | 35 #include "platform/graphics/filters/FEBoxReflect.h" |
| 37 #include "platform/graphics/filters/FEColorMatrix.h" | 36 #include "platform/graphics/filters/FEColorMatrix.h" |
| 38 #include "platform/graphics/filters/FEComponentTransfer.h" | 37 #include "platform/graphics/filters/FEComponentTransfer.h" |
| 39 #include "platform/graphics/filters/FEDropShadow.h" | 38 #include "platform/graphics/filters/FEDropShadow.h" |
| 40 #include "platform/graphics/filters/FEGaussianBlur.h" | 39 #include "platform/graphics/filters/FEGaussianBlur.h" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 | 111 |
| 113 matrix.uncheckedAppend(clampTo<float>(0.272 - 0.272 * oneMinusAmount)); | 112 matrix.uncheckedAppend(clampTo<float>(0.272 - 0.272 * oneMinusAmount)); |
| 114 matrix.uncheckedAppend(clampTo<float>(0.534 - 0.534 * oneMinusAmount)); | 113 matrix.uncheckedAppend(clampTo<float>(0.534 - 0.534 * oneMinusAmount)); |
| 115 matrix.uncheckedAppend(clampTo<float>(0.131 + 0.869 * oneMinusAmount)); | 114 matrix.uncheckedAppend(clampTo<float>(0.131 + 0.869 * oneMinusAmount)); |
| 116 endMatrixRow(matrix); | 115 endMatrixRow(matrix); |
| 117 | 116 |
| 118 lastMatrixRow(matrix); | 117 lastMatrixRow(matrix); |
| 119 return matrix; | 118 return matrix; |
| 120 } | 119 } |
| 121 | 120 |
| 122 FloatRect computeReferenceBox(const Element& element, const FloatSize* zoomedRef
erenceBoxSize, float zoom) | |
| 123 { | |
| 124 FloatRect box; | |
| 125 if (zoomedReferenceBoxSize) { | |
| 126 box = FloatRect(FloatPoint(), *zoomedReferenceBoxSize); | |
| 127 } else if (element.isConnected() && element.layoutObject() && element.layout
Object()->enclosingLayer()) { | |
| 128 box = FloatRect(element.layoutObject()->enclosingLayer()->physicalBoundi
ngBoxIncludingReflectionAndStackingChildren(LayoutPoint(), PaintLayer::Calculate
BoundsOptions::IncludeTransformsAndCompositedChildLayers)); | |
| 129 } | |
| 130 box.scale(1.0f / zoom); | |
| 131 return box; | |
| 132 } | |
| 133 | |
| 134 } // namespace | 121 } // namespace |
| 135 | 122 |
| 136 FilterEffectBuilder::FilterEffectBuilder() | 123 FilterEffectBuilder::FilterEffectBuilder() |
| 137 { | 124 { |
| 138 } | 125 } |
| 139 | 126 |
| 140 FilterEffectBuilder::~FilterEffectBuilder() | 127 FilterEffectBuilder::~FilterEffectBuilder() |
| 141 { | 128 { |
| 142 } | 129 } |
| 143 | 130 |
| 144 DEFINE_TRACE(FilterEffectBuilder) | 131 DEFINE_TRACE(FilterEffectBuilder) |
| 145 { | 132 { |
| 146 visitor->trace(m_lastEffect); | 133 visitor->trace(m_lastEffect); |
| 147 } | 134 } |
| 148 | 135 |
| 149 bool FilterEffectBuilder::build(Element* element, const FilterOperations& operat
ions, float zoom, const FloatSize* zoomedReferenceBoxSize, const SkPaint* fillPa
int, const SkPaint* strokePaint) | 136 bool FilterEffectBuilder::build(Element* element, const FilterOperations& operat
ions, float zoom, const FloatRect& zoomedReferenceBox, const SkPaint* fillPaint,
const SkPaint* strokePaint) |
| 150 { | 137 { |
| 151 // Create a parent filter for shorthand filters. These have already been sca
led by the CSS code for page zoom, so scale is 1.0 here. | 138 // Create a parent filter for shorthand filters. These have already been sca
led by the CSS code for page zoom, so scale is 1.0 here. |
| 152 Filter* parentFilter = Filter::create(1.0f); | 139 Filter* parentFilter = Filter::create(1.0f); |
| 153 FilterEffect* previousEffect = parentFilter->getSourceGraphic(); | 140 FilterEffect* previousEffect = parentFilter->getSourceGraphic(); |
| 154 for (size_t i = 0; i < operations.operations().size(); ++i) { | 141 for (size_t i = 0; i < operations.operations().size(); ++i) { |
| 155 FilterEffect* effect = nullptr; | 142 FilterEffect* effect = nullptr; |
| 156 FilterOperation* filterOperation = operations.operations().at(i).get(); | 143 FilterOperation* filterOperation = operations.operations().at(i).get(); |
| 157 switch (filterOperation->type()) { | 144 switch (filterOperation->type()) { |
| 158 case FilterOperation::REFERENCE: { | 145 case FilterOperation::REFERENCE: { |
| 159 Filter* referenceFilter = buildReferenceFilter(toReferenceFilterOper
ation(*filterOperation), zoomedReferenceBoxSize, fillPaint, strokePaint, *elemen
t, previousEffect, zoom); | 146 Filter* referenceFilter = buildReferenceFilter(toReferenceFilterOper
ation(*filterOperation), zoomedReferenceBox, fillPaint, strokePaint, *element, p
reviousEffect, zoom); |
| 160 if (referenceFilter) | 147 if (referenceFilter) |
| 161 effect = referenceFilter->lastEffect(); | 148 effect = referenceFilter->lastEffect(); |
| 162 break; | 149 break; |
| 163 } | 150 } |
| 164 case FilterOperation::GRAYSCALE: { | 151 case FilterOperation::GRAYSCALE: { |
| 165 Vector<float> inputParameters = grayscaleMatrix(toBasicColorMatrixFi
lterOperation(filterOperation)->amount()); | 152 Vector<float> inputParameters = grayscaleMatrix(toBasicColorMatrixFi
lterOperation(filterOperation)->amount()); |
| 166 effect = FEColorMatrix::create(parentFilter, FECOLORMATRIX_TYPE_MATR
IX, inputParameters); | 153 effect = FEColorMatrix::create(parentFilter, FECOLORMATRIX_TYPE_MATR
IX, inputParameters); |
| 167 break; | 154 break; |
| 168 } | 155 } |
| 169 case FilterOperation::SEPIA: { | 156 case FilterOperation::SEPIA: { |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 | 257 |
| 271 // If we didn't make any effects, tell our caller we are not valid | 258 // If we didn't make any effects, tell our caller we are not valid |
| 272 if (!m_lastEffect.get()) | 259 if (!m_lastEffect.get()) |
| 273 return false; | 260 return false; |
| 274 | 261 |
| 275 return true; | 262 return true; |
| 276 } | 263 } |
| 277 | 264 |
| 278 Filter* FilterEffectBuilder::buildReferenceFilter( | 265 Filter* FilterEffectBuilder::buildReferenceFilter( |
| 279 const ReferenceFilterOperation& referenceOperation, | 266 const ReferenceFilterOperation& referenceOperation, |
| 280 const FloatSize* zoomedReferenceBoxSize, | 267 const FloatRect& zoomedReferenceBox, |
| 281 const SkPaint* fillPaint, | 268 const SkPaint* fillPaint, |
| 282 const SkPaint* strokePaint, | 269 const SkPaint* strokePaint, |
| 283 Element& element, | 270 Element& element, |
| 284 FilterEffect* previousEffect, | 271 FilterEffect* previousEffect, |
| 285 float zoom) | 272 float zoom) |
| 286 { | 273 { |
| 287 SVGFilterElement* filterElement = ReferenceFilterBuilder::resolveFilterRefer
ence(referenceOperation, element); | 274 SVGFilterElement* filterElement = ReferenceFilterBuilder::resolveFilterRefer
ence(referenceOperation, element); |
| 288 if (!filterElement) | 275 if (!filterElement) |
| 289 return nullptr; | 276 return nullptr; |
| 290 | 277 FloatRect referenceBox = zoomedReferenceBox; |
| 291 const FloatRect referenceBox = computeReferenceBox(element, zoomedReferenceB
oxSize, zoom); | 278 referenceBox.scale(1.0f / zoom); |
| 292 return buildReferenceFilter(*filterElement, referenceBox, fillPaint, strokeP
aint, previousEffect, zoom); | 279 return buildReferenceFilter(*filterElement, referenceBox, fillPaint, strokeP
aint, previousEffect, zoom); |
| 293 } | 280 } |
| 294 | 281 |
| 295 Filter* FilterEffectBuilder::buildReferenceFilter( | 282 Filter* FilterEffectBuilder::buildReferenceFilter( |
| 296 SVGFilterElement& filterElement, | 283 SVGFilterElement& filterElement, |
| 297 const FloatRect& referenceBox, | 284 const FloatRect& referenceBox, |
| 298 const SkPaint* fillPaint, | 285 const SkPaint* fillPaint, |
| 299 const SkPaint* strokePaint, | 286 const SkPaint* strokePaint, |
| 300 FilterEffect* previousEffect, | 287 FilterEffect* previousEffect, |
| 301 float zoom, | 288 float zoom, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 314 if (!previousEffect) | 301 if (!previousEffect) |
| 315 previousEffect = result->getSourceGraphic(); | 302 previousEffect = result->getSourceGraphic(); |
| 316 SVGFilterBuilder builder(previousEffect, nodeMap, fillPaint, strokePaint); | 303 SVGFilterBuilder builder(previousEffect, nodeMap, fillPaint, strokePaint); |
| 317 builder.buildGraph(result, filterElement, referenceBox); | 304 builder.buildGraph(result, filterElement, referenceBox); |
| 318 result->setLastEffect(builder.lastEffect()); | 305 result->setLastEffect(builder.lastEffect()); |
| 319 return result; | 306 return result; |
| 320 } | 307 } |
| 321 | 308 |
| 322 } // namespace blink | 309 } // namespace blink |
| 323 | 310 |
| OLD | NEW |