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

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: 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
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 void FilterEffect::applyEffectBoundaries(FloatRect& rect) const
139 {
140 const FloatRect boundaries = effectBoundaries();
141 if (hasX())
142 rect.setX(boundaries.x());
143 if (hasY())
144 rect.setY(boundaries.y());
145 if (hasWidth())
146 rect.setWidth(boundaries.width());
147 if (hasHeight())
148 rect.setHeight(boundaries.height());
149 }
150
138 FloatRect FilterEffect::determineFilterPrimitiveSubregion(DetermineSubregionFlag s flags) 151 FloatRect FilterEffect::determineFilterPrimitiveSubregion(DetermineSubregionFlag s flags)
139 { 152 {
140 Filter* filter = this->filter(); 153 Filter* filter = this->filter();
141 ASSERT(filter); 154 ASSERT(filter);
142 155
143 // FETile, FETurbulence, FEFlood don't have input effects, take the filter r egion as unite rect. 156 // FETile, FETurbulence, FEFlood don't have input effects, take the filter r egion as unite rect.
144 FloatRect subregion; 157 FloatRect subregion;
145 if (unsigned numberOfInputEffects = inputEffects().size()) { 158 if (unsigned numberOfInputEffects = inputEffects().size()) {
146 subregion = inputEffect(0)->determineFilterPrimitiveSubregion(flags); 159 subregion = inputEffect(0)->determineFilterPrimitiveSubregion(flags);
147 for (unsigned i = 1; i < numberOfInputEffects; ++i) 160 for (unsigned i = 1; i < numberOfInputEffects; ++i)
148 subregion.unite(inputEffect(i)->determineFilterPrimitiveSubregion(fl ags)); 161 subregion.unite(inputEffect(i)->determineFilterPrimitiveSubregion(fl ags));
149 } else { 162 } else {
150 subregion = filter->filterRegion(); 163 subregion = filter->filterRegion();
151 } 164 }
152 165
153 // After calling determineFilterPrimitiveSubregion on the target effect, res et the subregion again for <feTile>. 166 // After calling determineFilterPrimitiveSubregion on the target effect, res et the subregion again for <feTile>.
154 if (filterEffectType() == FilterEffectTypeTile) 167 if (filterEffectType() == FilterEffectTypeTile)
155 subregion = filter->filterRegion(); 168 subregion = filter->filterRegion();
156 169
157 if (flags & MapRectForward) { 170 if (flags & MapRectForward) {
158 // mapRect works on absolute rectangles. 171 // mapRect works on absolute rectangles.
159 subregion = filter->mapAbsoluteRectToLocalRect(mapRect( 172 subregion = filter->mapAbsoluteRectToLocalRect(mapRect(
160 filter->mapLocalRectToAbsoluteRect(subregion))); 173 filter->mapLocalRectToAbsoluteRect(subregion)));
161 } 174 }
162 175
163 FloatRect boundaries = effectBoundaries(); 176 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 177
173 setFilterPrimitiveSubregion(subregion); 178 setFilterPrimitiveSubregion(subregion);
174 179
175 FloatRect absoluteSubregion = filter->mapLocalRectToAbsoluteRect(subregion); 180 FloatRect absoluteSubregion = filter->mapLocalRectToAbsoluteRect(subregion);
176 181
177 // Clip every filter effect to the filter region. 182 // Clip every filter effect to the filter region.
178 if (flags & ClipToFilterRegion) { 183 if (flags & ClipToFilterRegion) {
179 absoluteSubregion.intersect(filter->absoluteFilterRegion()); 184 absoluteSubregion.intersect(filter->absoluteFilterRegion());
180 } 185 }
181 186
(...skipping 28 matching lines...) Expand all
210 return false; 215 return false;
211 } 216 }
212 217
213 SkImageFilter::CropRect FilterEffect::getCropRect(const FloatSize& cropOffset) c onst 218 SkImageFilter::CropRect FilterEffect::getCropRect(const FloatSize& cropOffset) c onst
214 { 219 {
215 FloatRect rect; 220 FloatRect rect;
216 uint32_t flags = 0; 221 uint32_t flags = 0;
217 if (!hasConnectedInput() && !filter()->filterRegion().isEmpty()) { 222 if (!hasConnectedInput() && !filter()->filterRegion().isEmpty()) {
218 rect = filter()->filterRegion(); 223 rect = filter()->filterRegion();
219 flags = SkImageFilter::CropRect::kHasAll_CropEdge; 224 flags = SkImageFilter::CropRect::kHasAll_CropEdge;
220 rect.move(cropOffset);
221 } 225 }
222 FloatRect boundaries = effectBoundaries(); 226
223 boundaries.move(cropOffset); 227 applyEffectBoundaries(rect);
224 if (hasX()) { 228
225 rect.setX(boundaries.x()); 229 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()); 230 rect.scale(filter()->scale());
231
232 flags |= hasX() ? SkImageFilter::CropRect::kHasLeft_CropEdge : 0;
233 flags |= hasY() ? SkImageFilter::CropRect::kHasTop_CropEdge : 0;
234 flags |= hasWidth() ? SkImageFilter::CropRect::kHasWidth_CropEdge : 0;
235 flags |= hasHeight() ? SkImageFilter::CropRect::kHasHeight_CropEdge : 0;
236
241 return SkImageFilter::CropRect(rect, flags); 237 return SkImageFilter::CropRect(rect, flags);
242 } 238 }
243 239
244 static int getImageFilterIndex(ColorSpace colorSpace, bool requiresPMColorValida tion) 240 static int getImageFilterIndex(ColorSpace colorSpace, bool requiresPMColorValida tion)
245 { 241 {
246 // Map the (colorspace, bool) tuple to an integer index as follows: 242 // Map the (colorspace, bool) tuple to an integer index as follows:
247 // 0 == linear colorspace, no PM validation 243 // 0 == linear colorspace, no PM validation
248 // 1 == device colorspace, no PM validation 244 // 1 == device colorspace, no PM validation
249 // 2 == linear colorspace, PM validation 245 // 2 == linear colorspace, PM validation
250 // 3 == device colorspace, PM validation 246 // 3 == device colorspace, PM validation
251 return (colorSpace == ColorSpaceLinearRGB ? 0x1 : 0x0) | (requiresPMColorVal idation ? 0x2 : 0x0); 247 return (colorSpace == ColorSpaceLinearRGB ? 0x1 : 0x0) | (requiresPMColorVal idation ? 0x2 : 0x0);
252 } 248 }
253 249
254 SkImageFilter* FilterEffect::getImageFilter(ColorSpace colorSpace, bool requires PMColorValidation) const 250 SkImageFilter* FilterEffect::getImageFilter(ColorSpace colorSpace, bool requires PMColorValidation) const
255 { 251 {
256 int index = getImageFilterIndex(colorSpace, requiresPMColorValidation); 252 int index = getImageFilterIndex(colorSpace, requiresPMColorValidation);
257 return m_imageFilters[index].get(); 253 return m_imageFilters[index].get();
258 } 254 }
259 255
260 void FilterEffect::setImageFilter(ColorSpace colorSpace, bool requiresPMColorVal idation, PassRefPtr<SkImageFilter> imageFilter) 256 void FilterEffect::setImageFilter(ColorSpace colorSpace, bool requiresPMColorVal idation, PassRefPtr<SkImageFilter> imageFilter)
261 { 257 {
262 int index = getImageFilterIndex(colorSpace, requiresPMColorValidation); 258 int index = getImageFilterIndex(colorSpace, requiresPMColorValidation);
263 m_imageFilters[index] = imageFilter; 259 m_imageFilters[index] = imageFilter;
264 } 260 }
265 261
266 } // namespace blink 262 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698