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

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

Issue 1463513002: Move application of filter effect boundaries to a helper (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make method "functional". Created 5 years, 1 month 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
« no previous file with comments | « third_party/WebKit/Source/platform/graphics/filters/FilterEffect.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 return ColorSpaceUtilities::convertColor(deviceColor, operatingColorSpace()) ; 128 return ColorSpaceUtilities::convertColor(deviceColor, operatingColorSpace()) ;
129 } 129 }
130 130
131 TextStream& FilterEffect::externalRepresentation(TextStream& ts, int) const 131 TextStream& FilterEffect::externalRepresentation(TextStream& ts, int) const
132 { 132 {
133 // FIXME: We should dump the subRegions of the filter primitives here later. This isn't 133 // FIXME: We should dump the subRegions of the filter primitives here later. This isn't
134 // possible at the moment, because we need more detailed informations from t he target object. 134 // possible at the moment, because we need more detailed informations from t he target object.
135 return ts; 135 return ts;
136 } 136 }
137 137
138 FloatRect FilterEffect::applyEffectBoundaries(const FloatRect& rect) const
139 {
140 FloatRect clippedRect = rect;
141 if (hasX())
142 clippedRect.setX(effectBoundaries().x());
143 if (hasY())
144 clippedRect.setY(effectBoundaries().y());
145 if (hasWidth())
146 clippedRect.setWidth(effectBoundaries().width());
147 if (hasHeight())
148 clippedRect.setHeight(effectBoundaries().height());
149 return clippedRect;
150 }
151
138 FloatRect FilterEffect::determineFilterPrimitiveSubregion(DetermineSubregionFlag s flags) 152 FloatRect FilterEffect::determineFilterPrimitiveSubregion(DetermineSubregionFlag s flags)
139 { 153 {
140 Filter* filter = this->filter(); 154 Filter* filter = this->filter();
141 ASSERT(filter); 155 ASSERT(filter);
142 156
143 // FETile, FETurbulence, FEFlood don't have input effects, take the filter r egion as unite rect. 157 // FETile, FETurbulence, FEFlood don't have input effects, take the filter r egion as unite rect.
144 FloatRect subregion; 158 FloatRect subregion;
145 if (unsigned numberOfInputEffects = inputEffects().size()) { 159 if (unsigned numberOfInputEffects = inputEffects().size()) {
146 subregion = inputEffect(0)->determineFilterPrimitiveSubregion(flags); 160 subregion = inputEffect(0)->determineFilterPrimitiveSubregion(flags);
147 for (unsigned i = 1; i < numberOfInputEffects; ++i) 161 for (unsigned i = 1; i < numberOfInputEffects; ++i)
148 subregion.unite(inputEffect(i)->determineFilterPrimitiveSubregion(fl ags)); 162 subregion.unite(inputEffect(i)->determineFilterPrimitiveSubregion(fl ags));
149 } else { 163 } else {
150 subregion = filter->filterRegion(); 164 subregion = filter->filterRegion();
151 } 165 }
152 166
153 // After calling determineFilterPrimitiveSubregion on the target effect, res et the subregion again for <feTile>. 167 // After calling determineFilterPrimitiveSubregion on the target effect, res et the subregion again for <feTile>.
154 if (filterEffectType() == FilterEffectTypeTile) 168 if (filterEffectType() == FilterEffectTypeTile)
155 subregion = filter->filterRegion(); 169 subregion = filter->filterRegion();
156 170
157 if (flags & MapRectForward) { 171 if (flags & MapRectForward) {
158 // mapRect works on absolute rectangles. 172 // mapRect works on absolute rectangles.
159 subregion = filter->mapAbsoluteRectToLocalRect(mapRect( 173 subregion = filter->mapAbsoluteRectToLocalRect(mapRect(
160 filter->mapLocalRectToAbsoluteRect(subregion))); 174 filter->mapLocalRectToAbsoluteRect(subregion)));
161 } 175 }
162 176
163 FloatRect boundaries = effectBoundaries(); 177 subregion = applyEffectBoundaries(subregion);
164 if (hasX())
165 subregion.setX(boundaries.x());
166 if (hasY())
167 subregion.setY(boundaries.y());
168 if (hasWidth())
169 subregion.setWidth(boundaries.width());
170 if (hasHeight())
171 subregion.setHeight(boundaries.height());
172 178
173 setFilterPrimitiveSubregion(subregion); 179 setFilterPrimitiveSubregion(subregion);
174 180
175 FloatRect absoluteSubregion = filter->mapLocalRectToAbsoluteRect(subregion); 181 FloatRect absoluteSubregion = filter->mapLocalRectToAbsoluteRect(subregion);
176 182
177 // Clip every filter effect to the filter region. 183 // Clip every filter effect to the filter region.
178 if (flags & ClipToFilterRegion) { 184 if (flags & ClipToFilterRegion) {
179 absoluteSubregion.intersect(filter->absoluteFilterRegion()); 185 absoluteSubregion.intersect(filter->absoluteFilterRegion());
180 } 186 }
181 187
(...skipping 28 matching lines...) Expand all
210 return false; 216 return false;
211 } 217 }
212 218
213 SkImageFilter::CropRect FilterEffect::getCropRect(const FloatSize& cropOffset) c onst 219 SkImageFilter::CropRect FilterEffect::getCropRect(const FloatSize& cropOffset) c onst
214 { 220 {
215 FloatRect rect; 221 FloatRect rect;
216 uint32_t flags = 0; 222 uint32_t flags = 0;
217 if (!hasConnectedInput() && !filter()->filterRegion().isEmpty()) { 223 if (!hasConnectedInput() && !filter()->filterRegion().isEmpty()) {
218 rect = filter()->filterRegion(); 224 rect = filter()->filterRegion();
219 flags = SkImageFilter::CropRect::kHasAll_CropEdge; 225 flags = SkImageFilter::CropRect::kHasAll_CropEdge;
220 rect.move(cropOffset);
221 } 226 }
222 FloatRect boundaries = effectBoundaries(); 227
223 boundaries.move(cropOffset); 228 rect = applyEffectBoundaries(rect);
224 if (hasX()) { 229
225 rect.setX(boundaries.x()); 230 rect.move(cropOffset);
226 flags |= SkImageFilter::CropRect::kHasLeft_CropEdge;
227 }
228 if (hasY()) {
229 rect.setY(boundaries.y());
230 flags |= SkImageFilter::CropRect::kHasTop_CropEdge;
231 }
232 if (hasWidth()) {
233 rect.setWidth(boundaries.width());
234 flags |= SkImageFilter::CropRect::kHasWidth_CropEdge;
235 }
236 if (hasHeight()) {
237 rect.setHeight(boundaries.height());
238 flags |= SkImageFilter::CropRect::kHasHeight_CropEdge;
239 }
240 rect.scale(filter()->scale()); 231 rect.scale(filter()->scale());
232
233 flags |= hasX() ? SkImageFilter::CropRect::kHasLeft_CropEdge : 0;
234 flags |= hasY() ? SkImageFilter::CropRect::kHasTop_CropEdge : 0;
235 flags |= hasWidth() ? SkImageFilter::CropRect::kHasWidth_CropEdge : 0;
236 flags |= hasHeight() ? SkImageFilter::CropRect::kHasHeight_CropEdge : 0;
237
241 return SkImageFilter::CropRect(rect, flags); 238 return SkImageFilter::CropRect(rect, flags);
242 } 239 }
243 240
244 static int getImageFilterIndex(ColorSpace colorSpace, bool requiresPMColorValida tion) 241 static int getImageFilterIndex(ColorSpace colorSpace, bool requiresPMColorValida tion)
245 { 242 {
246 // Map the (colorspace, bool) tuple to an integer index as follows: 243 // Map the (colorspace, bool) tuple to an integer index as follows:
247 // 0 == linear colorspace, no PM validation 244 // 0 == linear colorspace, no PM validation
248 // 1 == device colorspace, no PM validation 245 // 1 == device colorspace, no PM validation
249 // 2 == linear colorspace, PM validation 246 // 2 == linear colorspace, PM validation
250 // 3 == device colorspace, PM validation 247 // 3 == device colorspace, PM validation
251 return (colorSpace == ColorSpaceLinearRGB ? 0x1 : 0x0) | (requiresPMColorVal idation ? 0x2 : 0x0); 248 return (colorSpace == ColorSpaceLinearRGB ? 0x1 : 0x0) | (requiresPMColorVal idation ? 0x2 : 0x0);
252 } 249 }
253 250
254 SkImageFilter* FilterEffect::getImageFilter(ColorSpace colorSpace, bool requires PMColorValidation) const 251 SkImageFilter* FilterEffect::getImageFilter(ColorSpace colorSpace, bool requires PMColorValidation) const
255 { 252 {
256 int index = getImageFilterIndex(colorSpace, requiresPMColorValidation); 253 int index = getImageFilterIndex(colorSpace, requiresPMColorValidation);
257 return m_imageFilters[index].get(); 254 return m_imageFilters[index].get();
258 } 255 }
259 256
260 void FilterEffect::setImageFilter(ColorSpace colorSpace, bool requiresPMColorVal idation, PassRefPtr<SkImageFilter> imageFilter) 257 void FilterEffect::setImageFilter(ColorSpace colorSpace, bool requiresPMColorVal idation, PassRefPtr<SkImageFilter> imageFilter)
261 { 258 {
262 int index = getImageFilterIndex(colorSpace, requiresPMColorValidation); 259 int index = getImageFilterIndex(colorSpace, requiresPMColorValidation);
263 m_imageFilters[index] = imageFilter; 260 m_imageFilters[index] = imageFilter;
264 } 261 }
265 262
266 } // namespace blink 263 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/graphics/filters/FilterEffect.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698