| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Alex Mathews <possessedpenguinbob@gmail.com> | 2 * Copyright (C) 2008 Alex Mathews <possessedpenguinbob@gmail.com> |
| 3 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> | 3 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> |
| 4 * Copyright (C) Research In Motion Limited 2010. All rights reserved. | 4 * Copyright (C) Research In Motion Limited 2010. All rights reserved. |
| 5 * Copyright (C) 2012 University of Szeged | 5 * Copyright (C) 2012 University of Szeged |
| 6 * Copyright (C) 2013 Google Inc. All rights reserved. | 6 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 7 * | 7 * |
| 8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
| 9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
| 10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "platform/graphics/filters/Filter.h" | 26 #include "platform/graphics/filters/Filter.h" |
| 27 #include "platform/graphics/filters/SkiaImageFilterBuilder.h" | 27 #include "platform/graphics/filters/SkiaImageFilterBuilder.h" |
| 28 #include "third_party/skia/include/core/SkColorFilter.h" | 28 #include "third_party/skia/include/core/SkColorFilter.h" |
| 29 #include "third_party/skia/include/effects/SkColorFilterImageFilter.h" | 29 #include "third_party/skia/include/effects/SkColorFilterImageFilter.h" |
| 30 #include "third_party/skia/include/effects/SkPictureImageFilter.h" | 30 #include "third_party/skia/include/effects/SkPictureImageFilter.h" |
| 31 | 31 |
| 32 namespace blink { | 32 namespace blink { |
| 33 | 33 |
| 34 FilterEffect::FilterEffect(Filter* filter) | 34 FilterEffect::FilterEffect(Filter* filter) |
| 35 : m_filter(filter) | 35 : m_filter(filter) |
| 36 , m_hasX(false) |
| 37 , m_hasY(false) |
| 38 , m_hasWidth(false) |
| 39 , m_hasHeight(false) |
| 36 , m_clipsToBounds(true) | 40 , m_clipsToBounds(true) |
| 37 , m_originTainted(false) | 41 , m_originTainted(false) |
| 38 , m_operatingColorSpace(ColorSpaceLinearRGB) | 42 , m_operatingColorSpace(ColorSpaceLinearRGB) |
| 39 { | 43 { |
| 40 ASSERT(m_filter); | 44 ASSERT(m_filter); |
| 41 } | 45 } |
| 42 | 46 |
| 43 FilterEffect::~FilterEffect() | 47 FilterEffect::~FilterEffect() |
| 44 { | 48 { |
| 45 } | 49 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 return ColorSpaceUtilities::convertColor(deviceColor, operatingColorSpace())
; | 126 return ColorSpaceUtilities::convertColor(deviceColor, operatingColorSpace())
; |
| 123 } | 127 } |
| 124 | 128 |
| 125 TextStream& FilterEffect::externalRepresentation(TextStream& ts, int) const | 129 TextStream& FilterEffect::externalRepresentation(TextStream& ts, int) const |
| 126 { | 130 { |
| 127 // FIXME: We should dump the subRegions of the filter primitives here later.
This isn't | 131 // FIXME: We should dump the subRegions of the filter primitives here later.
This isn't |
| 128 // possible at the moment, because we need more detailed informations from t
he target object. | 132 // possible at the moment, because we need more detailed informations from t
he target object. |
| 129 return ts; | 133 return ts; |
| 130 } | 134 } |
| 131 | 135 |
| 132 FloatRect FilterEffect::determineMaximumEffectRect(DetermineMaxEffectRectFlags f
lags) | 136 FloatRect FilterEffect::applyEffectBoundaries(const FloatRect& rect) const |
| 133 { | 137 { |
| 134 DCHECK(getFilter()); | 138 FloatRect clippedRect = rect; |
| 135 Filter* filter = getFilter(); | 139 if (hasX()) |
| 140 clippedRect.setX(effectBoundaries().x()); |
| 141 if (hasY()) |
| 142 clippedRect.setY(effectBoundaries().y()); |
| 143 if (hasWidth()) |
| 144 clippedRect.setWidth(effectBoundaries().width()); |
| 145 if (hasHeight()) |
| 146 clippedRect.setHeight(effectBoundaries().height()); |
| 147 return clippedRect; |
| 148 } |
| 136 | 149 |
| 137 // Compute the union of the inputs. Always do this because it has | 150 FloatRect FilterEffect::determineFilterPrimitiveSubregion(DetermineSubregionFlag
s flags) |
| 138 // side-effects. (It computes the maximum effect rect of the input.) | 151 { |
| 139 FloatRect absoluteInputUnion; | 152 Filter* filter = this->getFilter(); |
| 140 for (auto& effect : m_inputEffects) | 153 ASSERT(filter); |
| 141 absoluteInputUnion.unite(effect->determineMaximumEffectRect(flags)); | |
| 142 | 154 |
| 143 FloatRect absoluteSubregion; | 155 // FETile, FETurbulence, FEFlood don't have input effects, take the filter r
egion as unite rect. |
| 144 switch (getFilterEffectType()) { | 156 FloatRect subregion; |
| 145 default: | 157 if (unsigned numberOfInputEffects = inputEffects().size()) { |
| 146 if (m_inputEffects.size()) { | 158 subregion = inputEffect(0)->determineFilterPrimitiveSubregion(flags); |
| 147 absoluteSubregion = absoluteInputUnion; | 159 for (unsigned i = 1; i < numberOfInputEffects; ++i) |
| 148 if (clipsToBounds()) | 160 subregion.unite(inputEffect(i)->determineFilterPrimitiveSubregion(fl
ags)); |
| 149 absoluteSubregion.intersect(filter->mapLocalRectToAbsoluteRect(f
ilterPrimitiveSubregion())); | 161 } else { |
| 150 break; | 162 subregion = filter->filterRegion(); |
| 151 } | |
| 152 // Else fall-through and use the primitive region. (FETurbulence/FEFlood
/FEImage) | |
| 153 case FilterEffectTypeTile: | |
| 154 absoluteSubregion = filter->mapLocalRectToAbsoluteRect(filterPrimitiveSu
bregion()); | |
| 155 break; | |
| 156 case FilterEffectTypeSourceInput: | |
| 157 absoluteSubregion = filter->absoluteFilterRegion(); | |
| 158 break; | |
| 159 } | 163 } |
| 160 | 164 |
| 161 if (flags & MapRectForward) | 165 // After calling determineFilterPrimitiveSubregion on the target effect, res
et the subregion again for <feTile>. |
| 162 absoluteSubregion = mapRect(absoluteSubregion); | 166 if (getFilterEffectType() == FilterEffectTypeTile) |
| 167 subregion = filter->filterRegion(); |
| 168 |
| 169 if (flags & MapRectForward) { |
| 170 // mapRect works on absolute rectangles. |
| 171 subregion = filter->mapAbsoluteRectToLocalRect(mapRect( |
| 172 filter->mapLocalRectToAbsoluteRect(subregion))); |
| 173 } |
| 174 |
| 175 subregion = applyEffectBoundaries(subregion); |
| 176 |
| 177 setFilterPrimitiveSubregion(subregion); |
| 178 |
| 179 FloatRect absoluteSubregion = filter->mapLocalRectToAbsoluteRect(subregion); |
| 163 | 180 |
| 164 // Clip every filter effect to the filter region. | 181 // Clip every filter effect to the filter region. |
| 165 if (flags & ClipToFilterRegion) | 182 if (flags & ClipToFilterRegion) { |
| 166 absoluteSubregion.intersect(filter->absoluteFilterRegion()); | 183 absoluteSubregion.intersect(filter->absoluteFilterRegion()); |
| 184 } |
| 167 | 185 |
| 168 m_maxEffectRect = absoluteSubregion; | 186 setMaxEffectRect(absoluteSubregion); |
| 169 return absoluteSubregion; | 187 return subregion; |
| 170 } | 188 } |
| 171 | 189 |
| 172 sk_sp<SkImageFilter> FilterEffect::createImageFilter() | 190 sk_sp<SkImageFilter> FilterEffect::createImageFilter() |
| 173 { | 191 { |
| 174 return nullptr; | 192 return nullptr; |
| 175 } | 193 } |
| 176 | 194 |
| 177 sk_sp<SkImageFilter> FilterEffect::createImageFilterWithoutValidation() | 195 sk_sp<SkImageFilter> FilterEffect::createImageFilterWithoutValidation() |
| 178 { | 196 { |
| 179 return createImageFilter(); | 197 return createImageFilter(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 191 sk_sp<SkImageFilter> FilterEffect::createTransparentBlack() const | 209 sk_sp<SkImageFilter> FilterEffect::createTransparentBlack() const |
| 192 { | 210 { |
| 193 SkImageFilter::CropRect rect = getCropRect(); | 211 SkImageFilter::CropRect rect = getCropRect(); |
| 194 sk_sp<SkColorFilter> colorFilter = SkColorFilter::MakeModeFilter(0, SkXfermo
de::kClear_Mode); | 212 sk_sp<SkColorFilter> colorFilter = SkColorFilter::MakeModeFilter(0, SkXfermo
de::kClear_Mode); |
| 195 return SkColorFilterImageFilter::Make(std::move(colorFilter), nullptr, &rect
); | 213 return SkColorFilterImageFilter::Make(std::move(colorFilter), nullptr, &rect
); |
| 196 } | 214 } |
| 197 | 215 |
| 198 SkImageFilter::CropRect FilterEffect::getCropRect() const | 216 SkImageFilter::CropRect FilterEffect::getCropRect() const |
| 199 { | 217 { |
| 200 if (!filterPrimitiveSubregion().isEmpty()) { | 218 if (!filterPrimitiveSubregion().isEmpty()) { |
| 201 FloatRect rect = getFilter()->mapLocalRectToAbsoluteRect(filterPrimitive
Subregion()); | 219 FloatRect rect = filterPrimitiveSubregion(); |
| 220 rect.scale(getFilter()->scale()); |
| 202 return SkImageFilter::CropRect(rect); | 221 return SkImageFilter::CropRect(rect); |
| 203 } else { | 222 } else { |
| 204 return SkImageFilter::CropRect(SkRect::MakeEmpty(), 0); | 223 return SkImageFilter::CropRect(SkRect::MakeEmpty(), 0); |
| 205 } | 224 } |
| 206 } | 225 } |
| 207 | 226 |
| 208 static int getImageFilterIndex(ColorSpace colorSpace, bool requiresPMColorValida
tion) | 227 static int getImageFilterIndex(ColorSpace colorSpace, bool requiresPMColorValida
tion) |
| 209 { | 228 { |
| 210 // Map the (colorspace, bool) tuple to an integer index as follows: | 229 // Map the (colorspace, bool) tuple to an integer index as follows: |
| 211 // 0 == linear colorspace, no PM validation | 230 // 0 == linear colorspace, no PM validation |
| 212 // 1 == device colorspace, no PM validation | 231 // 1 == device colorspace, no PM validation |
| 213 // 2 == linear colorspace, PM validation | 232 // 2 == linear colorspace, PM validation |
| 214 // 3 == device colorspace, PM validation | 233 // 3 == device colorspace, PM validation |
| 215 return (colorSpace == ColorSpaceLinearRGB ? 0x1 : 0x0) | (requiresPMColorVal
idation ? 0x2 : 0x0); | 234 return (colorSpace == ColorSpaceLinearRGB ? 0x1 : 0x0) | (requiresPMColorVal
idation ? 0x2 : 0x0); |
| 216 } | 235 } |
| 217 | 236 |
| 218 SkImageFilter* FilterEffect::getImageFilter(ColorSpace colorSpace, bool requires
PMColorValidation) const | 237 SkImageFilter* FilterEffect::getImageFilter(ColorSpace colorSpace, bool requires
PMColorValidation) const |
| 219 { | 238 { |
| 220 int index = getImageFilterIndex(colorSpace, requiresPMColorValidation); | 239 int index = getImageFilterIndex(colorSpace, requiresPMColorValidation); |
| 221 return m_imageFilters[index].get(); | 240 return m_imageFilters[index].get(); |
| 222 } | 241 } |
| 223 | 242 |
| 224 void FilterEffect::setImageFilter(ColorSpace colorSpace, bool requiresPMColorVal
idation, sk_sp<SkImageFilter> imageFilter) | 243 void FilterEffect::setImageFilter(ColorSpace colorSpace, bool requiresPMColorVal
idation, sk_sp<SkImageFilter> imageFilter) |
| 225 { | 244 { |
| 226 int index = getImageFilterIndex(colorSpace, requiresPMColorValidation); | 245 int index = getImageFilterIndex(colorSpace, requiresPMColorValidation); |
| 227 m_imageFilters[index] = std::move(imageFilter); | 246 m_imageFilters[index] = std::move(imageFilter); |
| 228 } | 247 } |
| 229 | 248 |
| 230 } // namespace blink | 249 } // namespace blink |
| OLD | NEW |