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

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: allow for negative scale (due to framebuffer flipping) in gaussian blur calculation 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
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 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 SkVector sigma = SkVector::Make(std_deviation, std_deviation); 320 SkVector sigma = SkVector::Make(std_deviation, std_deviation);
321 matrix.mapVectors(&sigma, 1); 321 matrix.mapVectors(&sigma, 1);
322 return sigma * SkIntToScalar(3); 322 return sigma * SkIntToScalar(3);
323 } 323 }
324 324
325 gfx::Rect FilterOperation::MapRect(const gfx::Rect& rect, 325 gfx::Rect FilterOperation::MapRect(const gfx::Rect& rect,
326 const SkMatrix& matrix) const { 326 const SkMatrix& matrix) const {
327 switch (type_) { 327 switch (type_) {
328 case FilterOperation::BLUR: { 328 case FilterOperation::BLUR: {
329 SkVector spread = MapStdDeviation(amount(), matrix); 329 SkVector spread = MapStdDeviation(amount(), matrix);
330 float spreadX = std::abs(spread.x());
331 float spreadY = std::abs(spread.y());
330 gfx::Rect result = rect; 332 gfx::Rect result = rect;
331 result.Inset(-spread.x(), -spread.y(), -spread.x(), -spread.y()); 333 result.Inset(-spreadX, -spreadY, -spreadX, -spreadY);
332 return result; 334 return result;
333 } 335 }
334 case FilterOperation::DROP_SHADOW: { 336 case FilterOperation::DROP_SHADOW: {
335 SkVector spread = MapStdDeviation(amount(), matrix); 337 SkVector spread = MapStdDeviation(amount(), matrix);
338 float spreadX = std::abs(spread.x());
339 float spreadY = std::abs(spread.y());
336 gfx::Rect result = rect; 340 gfx::Rect result = rect;
337 result.Inset(-spread.x(), -spread.y(), -spread.x(), -spread.y()); 341 result.Inset(-spreadX, -spreadY, -spreadX, -spreadY);
338 result += drop_shadow_offset().OffsetFromOrigin(); 342 result += drop_shadow_offset().OffsetFromOrigin();
339 result.Union(rect); 343 result.Union(rect);
340 return result; 344 return result;
341 } 345 }
342 case FilterOperation::REFERENCE: { 346 case FilterOperation::REFERENCE: {
343 if (!image_filter()) 347 if (!image_filter())
344 return rect; 348 return rect;
345 SkIRect in_rect = gfx::RectToSkIRect(rect); 349 SkIRect in_rect = gfx::RectToSkIRect(rect);
346 SkIRect out_rect = image_filter()->filterBounds( 350 SkIRect out_rect = image_filter()->filterBounds(
347 in_rect, matrix, SkImageFilter::kForward_MapDirection); 351 in_rect, matrix, SkImageFilter::kForward_MapDirection);
348 return gfx::SkIRectToRect(out_rect); 352 return gfx::SkIRectToRect(out_rect);
349 } 353 }
350 default: 354 default:
351 return rect; 355 return rect;
352 } 356 }
353 } 357 }
354 358
359 gfx::Rect FilterOperation::MapRectReverse(const gfx::Rect& rect,
Stephen White 2016/06/07 16:00:34 This looks awfully similar to the existing flavour
jbroman 2016/06/08 15:17:37 Done.
360 const SkMatrix& matrix) const {
361 switch (type_) {
362 case FilterOperation::BLUR: {
363 SkVector spread = MapStdDeviation(amount(), matrix);
364 float spreadX = std::abs(spread.x());
Stephen White 2016/06/07 16:00:34 If this needs to be abs'ed to handle negative scal
jbroman 2016/06/08 15:17:37 SkBlurImageFilter does apply abs: sigma.fX = SkMi
Stephen White 2016/06/08 22:05:23 So it does. Thanks!
365 float spreadY = std::abs(spread.y());
366 gfx::Rect result = rect;
367 result.Inset(-spreadX, -spreadY, -spreadX, -spreadY);
368 return result;
369 }
370 case FilterOperation::DROP_SHADOW: {
371 SkVector spread = MapStdDeviation(amount(), matrix);
372 float spreadX = std::abs(spread.x());
373 float spreadY = std::abs(spread.y());
374 gfx::Rect result = rect;
375 result.Inset(-spreadX, -spreadY, -spreadX, -spreadY);
376 result -= drop_shadow_offset().OffsetFromOrigin();
377 result.Union(rect);
378 return result;
379 }
380 case FilterOperation::REFERENCE: {
381 if (!image_filter())
382 return rect;
383 SkIRect in_rect = gfx::RectToSkIRect(rect);
384 SkIRect out_rect = image_filter()->filterBounds(
385 in_rect, matrix, SkImageFilter::kReverse_MapDirection);
386 return gfx::SkIRectToRect(out_rect);
387 }
388 default:
389 return rect;
390 }
391 }
392
355 } // namespace cc 393 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698