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

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: senorblanco review 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
« no previous file with comments | « cc/output/filter_operation.h ('k') | cc/output/filter_operations.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/output/filter_operation.cc
diff --git a/cc/output/filter_operation.cc b/cc/output/filter_operation.cc
index 1b2cca70060d2868caae9c49701f49ee8fa692e5..37ff8711c2b6a2c628747d5defb18395f4d6301f 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,41 @@ 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(), SkImageFilter::kForward_MapDirection);
+ return gfx::SkIRectToRect(out_rect);
+ }
+ default:
+ return rect;
+ }
+}
+
} // namespace cc
« 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