Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(431)

Side by Side Diff: third_party/WebKit/Source/platform/graphics/filters/FilterEffect.cpp

Issue 2303703002: Revamp filter primitive region calculations for Filter Effects (Closed)
Patch Set: Baselines again; Manual for mac10.11-retina Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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)
40 , m_clipsToBounds(true) 36 , m_clipsToBounds(true)
41 , m_originTainted(false) 37 , m_originTainted(false)
42 , m_operatingColorSpace(ColorSpaceLinearRGB) 38 , m_operatingColorSpace(ColorSpaceLinearRGB)
43 { 39 {
44 ASSERT(m_filter); 40 ASSERT(m_filter);
45 } 41 }
46 42
47 FilterEffect::~FilterEffect() 43 FilterEffect::~FilterEffect()
48 { 44 {
49 } 45 }
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 return ColorSpaceUtilities::convertColor(deviceColor, operatingColorSpace()) ; 122 return ColorSpaceUtilities::convertColor(deviceColor, operatingColorSpace()) ;
127 } 123 }
128 124
129 TextStream& FilterEffect::externalRepresentation(TextStream& ts, int) const 125 TextStream& FilterEffect::externalRepresentation(TextStream& ts, int) const
130 { 126 {
131 // FIXME: We should dump the subRegions of the filter primitives here later. This isn't 127 // FIXME: We should dump the subRegions of the filter primitives here later. This isn't
132 // possible at the moment, because we need more detailed informations from t he target object. 128 // possible at the moment, because we need more detailed informations from t he target object.
133 return ts; 129 return ts;
134 } 130 }
135 131
136 FloatRect FilterEffect::applyEffectBoundaries(const FloatRect& rect) const 132 FloatRect FilterEffect::determineMaximumEffectRect(DetermineMaxEffectRectFlags f lags)
137 { 133 {
138 FloatRect clippedRect = rect; 134 DCHECK(getFilter());
139 if (hasX()) 135 Filter* filter = getFilter();
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 }
149 136
150 FloatRect FilterEffect::determineFilterPrimitiveSubregion(DetermineSubregionFlag s flags) 137 // Compute the union of the inputs. Always do this because it has
151 { 138 // side-effects. (It computes the maximum effect rect of the input.)
152 Filter* filter = this->getFilter(); 139 FloatRect absoluteInputUnion;
153 ASSERT(filter); 140 for (auto& effect : m_inputEffects)
141 absoluteInputUnion.unite(effect->determineMaximumEffectRect(flags));
154 142
155 // FETile, FETurbulence, FEFlood don't have input effects, take the filter r egion as unite rect. 143 FloatRect absoluteSubregion;
156 FloatRect subregion; 144 switch (getFilterEffectType()) {
157 if (unsigned numberOfInputEffects = inputEffects().size()) { 145 default:
158 subregion = inputEffect(0)->determineFilterPrimitiveSubregion(flags); 146 if (m_inputEffects.size()) {
159 for (unsigned i = 1; i < numberOfInputEffects; ++i) 147 absoluteSubregion = absoluteInputUnion;
160 subregion.unite(inputEffect(i)->determineFilterPrimitiveSubregion(fl ags)); 148 if (clipsToBounds())
161 } else { 149 absoluteSubregion.intersect(filter->mapLocalRectToAbsoluteRect(f ilterPrimitiveSubregion()));
162 subregion = filter->filterRegion(); 150 break;
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;
163 } 159 }
164 160
165 // After calling determineFilterPrimitiveSubregion on the target effect, res et the subregion again for <feTile>. 161 if (flags & MapRectForward)
166 if (getFilterEffectType() == FilterEffectTypeTile) 162 absoluteSubregion = mapRect(absoluteSubregion);
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);
180 163
181 // Clip every filter effect to the filter region. 164 // Clip every filter effect to the filter region.
182 if (flags & ClipToFilterRegion) { 165 if (flags & ClipToFilterRegion)
183 absoluteSubregion.intersect(filter->absoluteFilterRegion()); 166 absoluteSubregion.intersect(filter->absoluteFilterRegion());
184 }
185 167
186 setMaxEffectRect(absoluteSubregion); 168 m_maxEffectRect = absoluteSubregion;
187 return subregion; 169 return absoluteSubregion;
188 } 170 }
189 171
190 sk_sp<SkImageFilter> FilterEffect::createImageFilter() 172 sk_sp<SkImageFilter> FilterEffect::createImageFilter()
191 { 173 {
192 return nullptr; 174 return nullptr;
193 } 175 }
194 176
195 sk_sp<SkImageFilter> FilterEffect::createImageFilterWithoutValidation() 177 sk_sp<SkImageFilter> FilterEffect::createImageFilterWithoutValidation()
196 { 178 {
197 return createImageFilter(); 179 return createImageFilter();
(...skipping 11 matching lines...) Expand all
209 sk_sp<SkImageFilter> FilterEffect::createTransparentBlack() const 191 sk_sp<SkImageFilter> FilterEffect::createTransparentBlack() const
210 { 192 {
211 SkImageFilter::CropRect rect = getCropRect(); 193 SkImageFilter::CropRect rect = getCropRect();
212 sk_sp<SkColorFilter> colorFilter = SkColorFilter::MakeModeFilter(0, SkXfermo de::kClear_Mode); 194 sk_sp<SkColorFilter> colorFilter = SkColorFilter::MakeModeFilter(0, SkXfermo de::kClear_Mode);
213 return SkColorFilterImageFilter::Make(std::move(colorFilter), nullptr, &rect ); 195 return SkColorFilterImageFilter::Make(std::move(colorFilter), nullptr, &rect );
214 } 196 }
215 197
216 SkImageFilter::CropRect FilterEffect::getCropRect() const 198 SkImageFilter::CropRect FilterEffect::getCropRect() const
217 { 199 {
218 if (!filterPrimitiveSubregion().isEmpty()) { 200 if (!filterPrimitiveSubregion().isEmpty()) {
219 FloatRect rect = filterPrimitiveSubregion(); 201 FloatRect rect = getFilter()->mapLocalRectToAbsoluteRect(filterPrimitive Subregion());
220 rect.scale(getFilter()->scale());
221 return SkImageFilter::CropRect(rect); 202 return SkImageFilter::CropRect(rect);
222 } else { 203 } else {
223 return SkImageFilter::CropRect(SkRect::MakeEmpty(), 0); 204 return SkImageFilter::CropRect(SkRect::MakeEmpty(), 0);
224 } 205 }
225 } 206 }
226 207
227 static int getImageFilterIndex(ColorSpace colorSpace, bool requiresPMColorValida tion) 208 static int getImageFilterIndex(ColorSpace colorSpace, bool requiresPMColorValida tion)
228 { 209 {
229 // Map the (colorspace, bool) tuple to an integer index as follows: 210 // Map the (colorspace, bool) tuple to an integer index as follows:
230 // 0 == linear colorspace, no PM validation 211 // 0 == linear colorspace, no PM validation
231 // 1 == device colorspace, no PM validation 212 // 1 == device colorspace, no PM validation
232 // 2 == linear colorspace, PM validation 213 // 2 == linear colorspace, PM validation
233 // 3 == device colorspace, PM validation 214 // 3 == device colorspace, PM validation
234 return (colorSpace == ColorSpaceLinearRGB ? 0x1 : 0x0) | (requiresPMColorVal idation ? 0x2 : 0x0); 215 return (colorSpace == ColorSpaceLinearRGB ? 0x1 : 0x0) | (requiresPMColorVal idation ? 0x2 : 0x0);
235 } 216 }
236 217
237 SkImageFilter* FilterEffect::getImageFilter(ColorSpace colorSpace, bool requires PMColorValidation) const 218 SkImageFilter* FilterEffect::getImageFilter(ColorSpace colorSpace, bool requires PMColorValidation) const
238 { 219 {
239 int index = getImageFilterIndex(colorSpace, requiresPMColorValidation); 220 int index = getImageFilterIndex(colorSpace, requiresPMColorValidation);
240 return m_imageFilters[index].get(); 221 return m_imageFilters[index].get();
241 } 222 }
242 223
243 void FilterEffect::setImageFilter(ColorSpace colorSpace, bool requiresPMColorVal idation, sk_sp<SkImageFilter> imageFilter) 224 void FilterEffect::setImageFilter(ColorSpace colorSpace, bool requiresPMColorVal idation, sk_sp<SkImageFilter> imageFilter)
244 { 225 {
245 int index = getImageFilterIndex(colorSpace, requiresPMColorValidation); 226 int index = getImageFilterIndex(colorSpace, requiresPMColorValidation);
246 m_imageFilters[index] = std::move(imageFilter); 227 m_imageFilters[index] = std::move(imageFilter);
247 } 228 }
248 229
249 } // namespace blink 230 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698