Chromium Code Reviews| Index: cc/output/filter_operation.cc |
| diff --git a/cc/output/filter_operation.cc b/cc/output/filter_operation.cc |
| index 78588748ba59d63c5d68bd35e1df56cba76f0d22..3660f05e623af2b4f69c301ca58998a1dca60f52 100644 |
| --- a/cc/output/filter_operation.cc |
| +++ b/cc/output/filter_operation.cc |
| @@ -315,36 +315,55 @@ void FilterOperation::AsValueInto(base::trace_event::TracedValue* value) const { |
| } |
| } |
| -static SkVector MapStdDeviation(float std_deviation, const SkMatrix& matrix) { |
| +namespace { |
| + |
| +enum class MapDirection { FORWARD, REVERSE }; |
|
Stephen White
2016/06/08 22:05:23
Why not just use SkImageFilter::MapDirection?
jbroman
2016/06/13 14:57:33
Sure, done. (No real reason, other than "it doesn'
|
| + |
| +SkVector MapStdDeviation(float std_deviation, const SkMatrix& matrix) { |
| // Corresponds to SpreadForStdDeviation in filter_operations.cc. |
| SkVector sigma = SkVector::Make(std_deviation, std_deviation); |
| matrix.mapVectors(&sigma, 1); |
| return sigma * SkIntToScalar(3); |
| } |
| -gfx::Rect FilterOperation::MapRect(const gfx::Rect& rect, |
| - const SkMatrix& matrix) const { |
| - switch (type_) { |
| +gfx::Rect MapRectInternal(const FilterOperation& op, |
| + const gfx::Rect& rect, |
| + const SkMatrix& matrix, |
| + MapDirection direction) { |
| + switch (op.type()) { |
| case FilterOperation::BLUR: { |
| - SkVector spread = MapStdDeviation(amount(), matrix); |
| + SkVector spread = MapStdDeviation(op.amount(), matrix); |
| + float spreadX = std::abs(spread.x()); |
| + float spreadY = std::abs(spread.y()); |
| gfx::Rect result = rect; |
| - result.Inset(-spread.x(), -spread.y(), -spread.x(), -spread.y()); |
| + result.Inset(-spreadX, -spreadY, -spreadX, -spreadY); |
| return result; |
| } |
| case FilterOperation::DROP_SHADOW: { |
| - SkVector spread = MapStdDeviation(amount(), matrix); |
| + SkVector spread = MapStdDeviation(op.amount(), matrix); |
| + float spreadX = std::abs(spread.x()); |
| + float spreadY = std::abs(spread.y()); |
| gfx::Rect result = rect; |
| - result.Inset(-spread.x(), -spread.y(), -spread.x(), -spread.y()); |
| - result += drop_shadow_offset().OffsetFromOrigin(); |
| + result.Inset(-spreadX, -spreadY, -spreadX, -spreadY); |
| + |
| + gfx::Vector2d drop_shadow_offset = |
| + op.drop_shadow_offset().OffsetFromOrigin(); |
| + if (direction == MapDirection::FORWARD) |
| + result += drop_shadow_offset; |
| + else |
| + result -= drop_shadow_offset; |
| + |
| result.Union(rect); |
| return result; |
| } |
| case FilterOperation::REFERENCE: { |
| - if (!image_filter()) |
| + if (!op.image_filter()) |
| return rect; |
| SkIRect in_rect = gfx::RectToSkIRect(rect); |
| - SkIRect out_rect = image_filter()->filterBounds( |
| - in_rect, matrix, SkImageFilter::kForward_MapDirection); |
| + SkIRect out_rect = op.image_filter()->filterBounds( |
| + in_rect, matrix, direction == MapDirection::FORWARD |
| + ? SkImageFilter::kForward_MapDirection |
| + : SkImageFilter::kReverse_MapDirection); |
| return gfx::SkIRectToRect(out_rect); |
| } |
| default: |
| @@ -352,4 +371,16 @@ gfx::Rect FilterOperation::MapRect(const gfx::Rect& rect, |
| } |
| } |
| +} // namespace |
| + |
| +gfx::Rect FilterOperation::MapRect(const gfx::Rect& rect, |
| + const SkMatrix& matrix) const { |
| + return MapRectInternal(*this, rect, matrix, MapDirection::FORWARD); |
| +} |
| + |
| +gfx::Rect FilterOperation::MapRectReverse(const gfx::Rect& rect, |
| + const SkMatrix& matrix) const { |
| + return MapRectInternal(*this, rect, matrix, MapDirection::REVERSE); |
| +} |
| + |
| } // namespace cc |