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

Side by Side Diff: cc/output/filter_operation.cc

Issue 1998233002: cc: Implement and use FilterOperations::MapRectReverse for mapping backdrop bounding box. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
« no previous file with comments | « cc/output/filter_operation.h ('k') | cc/output/filter_operations.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 value->AppendInteger(it.rect().y()); 308 value->AppendInteger(it.rect().y());
309 value->AppendInteger(it.rect().width()); 309 value->AppendInteger(it.rect().width());
310 value->AppendInteger(it.rect().height()); 310 value->AppendInteger(it.rect().height());
311 } 311 }
312 value->EndArray(); 312 value->EndArray();
313 } 313 }
314 break; 314 break;
315 } 315 }
316 } 316 }
317 317
318 static SkVector MapStdDeviation(float std_deviation, const SkMatrix& matrix) { 318 namespace {
319
320 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'
321
322 SkVector MapStdDeviation(float std_deviation, const SkMatrix& matrix) {
319 // Corresponds to SpreadForStdDeviation in filter_operations.cc. 323 // Corresponds to SpreadForStdDeviation in filter_operations.cc.
320 SkVector sigma = SkVector::Make(std_deviation, std_deviation); 324 SkVector sigma = SkVector::Make(std_deviation, std_deviation);
321 matrix.mapVectors(&sigma, 1); 325 matrix.mapVectors(&sigma, 1);
322 return sigma * SkIntToScalar(3); 326 return sigma * SkIntToScalar(3);
323 } 327 }
324 328
325 gfx::Rect FilterOperation::MapRect(const gfx::Rect& rect, 329 gfx::Rect MapRectInternal(const FilterOperation& op,
326 const SkMatrix& matrix) const { 330 const gfx::Rect& rect,
327 switch (type_) { 331 const SkMatrix& matrix,
332 MapDirection direction) {
333 switch (op.type()) {
328 case FilterOperation::BLUR: { 334 case FilterOperation::BLUR: {
329 SkVector spread = MapStdDeviation(amount(), matrix); 335 SkVector spread = MapStdDeviation(op.amount(), matrix);
336 float spreadX = std::abs(spread.x());
337 float spreadY = std::abs(spread.y());
330 gfx::Rect result = rect; 338 gfx::Rect result = rect;
331 result.Inset(-spread.x(), -spread.y(), -spread.x(), -spread.y()); 339 result.Inset(-spreadX, -spreadY, -spreadX, -spreadY);
332 return result; 340 return result;
333 } 341 }
334 case FilterOperation::DROP_SHADOW: { 342 case FilterOperation::DROP_SHADOW: {
335 SkVector spread = MapStdDeviation(amount(), matrix); 343 SkVector spread = MapStdDeviation(op.amount(), matrix);
344 float spreadX = std::abs(spread.x());
345 float spreadY = std::abs(spread.y());
336 gfx::Rect result = rect; 346 gfx::Rect result = rect;
337 result.Inset(-spread.x(), -spread.y(), -spread.x(), -spread.y()); 347 result.Inset(-spreadX, -spreadY, -spreadX, -spreadY);
338 result += drop_shadow_offset().OffsetFromOrigin(); 348
349 gfx::Vector2d drop_shadow_offset =
350 op.drop_shadow_offset().OffsetFromOrigin();
351 if (direction == MapDirection::FORWARD)
352 result += drop_shadow_offset;
353 else
354 result -= drop_shadow_offset;
355
339 result.Union(rect); 356 result.Union(rect);
340 return result; 357 return result;
341 } 358 }
342 case FilterOperation::REFERENCE: { 359 case FilterOperation::REFERENCE: {
343 if (!image_filter()) 360 if (!op.image_filter())
344 return rect; 361 return rect;
345 SkIRect in_rect = gfx::RectToSkIRect(rect); 362 SkIRect in_rect = gfx::RectToSkIRect(rect);
346 SkIRect out_rect = image_filter()->filterBounds( 363 SkIRect out_rect = op.image_filter()->filterBounds(
347 in_rect, matrix, SkImageFilter::kForward_MapDirection); 364 in_rect, matrix, direction == MapDirection::FORWARD
365 ? SkImageFilter::kForward_MapDirection
366 : SkImageFilter::kReverse_MapDirection);
348 return gfx::SkIRectToRect(out_rect); 367 return gfx::SkIRectToRect(out_rect);
349 } 368 }
350 default: 369 default:
351 return rect; 370 return rect;
352 } 371 }
353 } 372 }
354 373
374 } // namespace
375
376 gfx::Rect FilterOperation::MapRect(const gfx::Rect& rect,
377 const SkMatrix& matrix) const {
378 return MapRectInternal(*this, rect, matrix, MapDirection::FORWARD);
379 }
380
381 gfx::Rect FilterOperation::MapRectReverse(const gfx::Rect& rect,
382 const SkMatrix& matrix) const {
383 return MapRectInternal(*this, rect, matrix, MapDirection::REVERSE);
384 }
385
355 } // namespace cc 386 } // namespace cc
OLDNEW
« no previous file with comments | « cc/output/filter_operation.h ('k') | cc/output/filter_operations.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698