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

Unified Diff: cc/output/filter_operation.cc

Issue 1867913002: Implement cc::FilterOperations::MapRect. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: IWYU: <numeric> Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: cc/output/filter_operation.cc
diff --git a/cc/output/filter_operation.cc b/cc/output/filter_operation.cc
index a37d27d3b2b9728e896f9327c65d4a80dff5e7d2..c8afb679f595fda0dc0da44e8e4dd4b1d534645e 100644
--- a/cc/output/filter_operation.cc
+++ b/cc/output/filter_operation.cc
@@ -11,6 +11,9 @@
#include "cc/base/math_util.h"
#include "cc/output/filter_operation.h"
#include "ui/gfx/animation/tween.h"
+#include "ui/gfx/geometry/rect.h"
+#include "ui/gfx/geometry/rect_conversions.h"
+#include "ui/gfx/skia_util.h"
namespace cc {
@@ -317,4 +320,40 @@ void FilterOperation::AsValueInto(base::trace_event::TracedValue* value) const {
}
}
+static int SpreadForStdDeviation(float std_deviation) {
+ // https://dvcs.w3.org/hg/FXTF/raw-file/tip/filters/index.html#feGaussianBlurElement
+ // provides this approximation for evaluating a gaussian blur by a triple box
+ // filter.
+ float d = floorf(std_deviation * 3.f * sqrt(8.f * atan(1.f)) / 4.f + 0.5f);
+ return static_cast<int>(ceilf(d * 3.f / 2.f));
+}
+
+gfx::Rect FilterOperation::MapRect(const gfx::Rect& rect) const {
+ switch (type_) {
+ case FilterOperation::BLUR: {
+ int spread = SpreadForStdDeviation(amount());
+ gfx::Rect result = rect;
+ result.Inset(-spread, -spread, -spread, -spread);
+ return result;
+ }
+ case FilterOperation::DROP_SHADOW: {
+ int spread = SpreadForStdDeviation(amount());
+ gfx::Rect result = rect;
+ result.Inset(-spread, -spread, -spread, -spread);
+ result += drop_shadow_offset().OffsetFromOrigin();
+ result.Union(rect);
+ return result;
+ }
+ case FilterOperation::REFERENCE: {
+ if (!image_filter())
+ return rect;
+ SkIRect in_rect = gfx::RectToSkIRect(rect);
+ SkIRect out_rect = image_filter()->filterBounds(in_rect, SkMatrix::I());
Stephen White 2016/04/11 18:05:00 SkImageFilter::filterBounds() defaults to the reve
jbroman 2016/04/11 20:21:52 Good catch. What's troubling to me is that GetOuts
Stephen White 2016/04/11 20:56:04 Yeah, I think this was an existing bug. IIRC, this
+ return gfx::SkIRectToRect(out_rect);
+ }
+ default:
+ return rect;
+ }
+}
+
} // namespace cc

Powered by Google App Engine
This is Rietveld 408576698