| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/trace_event/trace_event_argument.h" | 9 #include "base/trace_event/trace_event_argument.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 value->AppendInteger(it.rect().y()); | 311 value->AppendInteger(it.rect().y()); |
| 312 value->AppendInteger(it.rect().width()); | 312 value->AppendInteger(it.rect().width()); |
| 313 value->AppendInteger(it.rect().height()); | 313 value->AppendInteger(it.rect().height()); |
| 314 } | 314 } |
| 315 value->EndArray(); | 315 value->EndArray(); |
| 316 } | 316 } |
| 317 break; | 317 break; |
| 318 } | 318 } |
| 319 } | 319 } |
| 320 | 320 |
| 321 static SkVector MapStdDeviation(float std_deviation, const SkMatrix& matrix) { | 321 namespace { |
| 322 |
| 323 SkVector MapStdDeviation(float std_deviation, const SkMatrix& matrix) { |
| 322 // Corresponds to SpreadForStdDeviation in filter_operations.cc. | 324 // Corresponds to SpreadForStdDeviation in filter_operations.cc. |
| 323 SkVector sigma = SkVector::Make(std_deviation, std_deviation); | 325 SkVector sigma = SkVector::Make(std_deviation, std_deviation); |
| 324 matrix.mapVectors(&sigma, 1); | 326 matrix.mapVectors(&sigma, 1); |
| 325 return sigma * SkIntToScalar(3); | 327 return sigma * SkIntToScalar(3); |
| 326 } | 328 } |
| 327 | 329 |
| 328 gfx::Rect FilterOperation::MapRect(const gfx::Rect& rect, | 330 gfx::Rect MapRectInternal(const FilterOperation& op, |
| 329 const SkMatrix& matrix) const { | 331 const gfx::Rect& rect, |
| 330 switch (type_) { | 332 const SkMatrix& matrix, |
| 333 SkImageFilter::MapDirection direction) { |
| 334 switch (op.type()) { |
| 331 case FilterOperation::BLUR: { | 335 case FilterOperation::BLUR: { |
| 332 SkVector spread = MapStdDeviation(amount(), matrix); | 336 SkVector spread = MapStdDeviation(op.amount(), matrix); |
| 337 float spreadX = std::abs(spread.x()); |
| 338 float spreadY = std::abs(spread.y()); |
| 333 gfx::Rect result = rect; | 339 gfx::Rect result = rect; |
| 334 result.Inset(-spread.x(), -spread.y(), -spread.x(), -spread.y()); | 340 result.Inset(-spreadX, -spreadY, -spreadX, -spreadY); |
| 335 return result; | 341 return result; |
| 336 } | 342 } |
| 337 case FilterOperation::DROP_SHADOW: { | 343 case FilterOperation::DROP_SHADOW: { |
| 338 SkVector spread = MapStdDeviation(amount(), matrix); | 344 SkVector spread = MapStdDeviation(op.amount(), matrix); |
| 345 float spreadX = std::abs(spread.x()); |
| 346 float spreadY = std::abs(spread.y()); |
| 339 gfx::Rect result = rect; | 347 gfx::Rect result = rect; |
| 340 result.Inset(-spread.x(), -spread.y(), -spread.x(), -spread.y()); | 348 result.Inset(-spreadX, -spreadY, -spreadX, -spreadY); |
| 341 result += drop_shadow_offset().OffsetFromOrigin(); | 349 |
| 350 gfx::Vector2d drop_shadow_offset = |
| 351 op.drop_shadow_offset().OffsetFromOrigin(); |
| 352 if (direction == SkImageFilter::kForward_MapDirection) |
| 353 result += drop_shadow_offset; |
| 354 else |
| 355 result -= drop_shadow_offset; |
| 356 |
| 342 result.Union(rect); | 357 result.Union(rect); |
| 343 return result; | 358 return result; |
| 344 } | 359 } |
| 345 case FilterOperation::REFERENCE: { | 360 case FilterOperation::REFERENCE: { |
| 346 if (!image_filter()) | 361 if (!op.image_filter()) |
| 347 return rect; | 362 return rect; |
| 348 SkIRect in_rect = gfx::RectToSkIRect(rect); | 363 return gfx::SkIRectToRect(op.image_filter()->filterBounds( |
| 349 SkIRect out_rect = image_filter()->filterBounds( | 364 gfx::RectToSkIRect(rect), matrix, direction)); |
| 350 in_rect, matrix, SkImageFilter::kForward_MapDirection); | |
| 351 return gfx::SkIRectToRect(out_rect); | |
| 352 } | 365 } |
| 353 default: | 366 default: |
| 354 return rect; | 367 return rect; |
| 355 } | 368 } |
| 356 } | 369 } |
| 357 | 370 |
| 371 } // namespace |
| 372 |
| 373 gfx::Rect FilterOperation::MapRect(const gfx::Rect& rect, |
| 374 const SkMatrix& matrix) const { |
| 375 return MapRectInternal(*this, rect, matrix, |
| 376 SkImageFilter::kForward_MapDirection); |
| 377 } |
| 378 |
| 379 gfx::Rect FilterOperation::MapRectReverse(const gfx::Rect& rect, |
| 380 const SkMatrix& matrix) const { |
| 381 return MapRectInternal(*this, rect, matrix, |
| 382 SkImageFilter::kReverse_MapDirection); |
| 383 } |
| 384 |
| 358 } // namespace cc | 385 } // namespace cc |
| OLD | NEW |