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

Unified Diff: cc/output/filter_operations.cc

Issue 16968002: Move implementation of WebFilterOperations into cc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 side-by-side diff with in-line comments
Download patch
Index: cc/output/filter_operations.cc
diff --git a/cc/output/filter_operations.cc b/cc/output/filter_operations.cc
new file mode 100644
index 0000000000000000000000000000000000000000..30d573e1b0f2d5fab35f7d3640527201ec99b7a0
--- /dev/null
+++ b/cc/output/filter_operations.cc
@@ -0,0 +1,118 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <cmath>
+
+#include "cc/output/filter_operation.h"
+#include "cc/output/filter_operations.h"
+
+namespace cc {
+
+FilterOperations::FilterOperations() {
+}
jamesr 2013/06/18 23:08:52 this can go on the previous line with no space bet
ajuma 2013/06/19 17:08:30 Done.
+
+FilterOperations::FilterOperations(const FilterOperations& other)
+ : operations_(other.operations_) {
+}
+
+FilterOperations::~FilterOperations() {
+}
+
+FilterOperations& FilterOperations::operator=(const FilterOperations& other) {
+ operations_ = other.operations_;
+ return *this;
+}
+
+bool FilterOperations::operator==(const FilterOperations& other) const {
+ if (other.size() != size())
+ return false;
+ for (size_t i = 0; i < size(); ++i) {
+ if (other.at(i) != at(i))
+ return false;
+ }
+ return true;
+}
+
+void FilterOperations::Append(const FilterOperation& filter) {
+ operations_.push_back(filter);
+}
+
+void FilterOperations::Clear() {
+ operations_.clear();
+}
+
+bool FilterOperations::IsEmpty() const {
+ return operations_.empty();
+}
+
+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 * sqrt(8.f * atan(1.f)) / 4 + 0.5);
+ return static_cast<int>(ceilf(d * 3 / 2));
+}
+
+void FilterOperations::GetOutsets(int* top,
+ int* right,
+ int* bottom,
+ int* left) const {
+ *top = *right = *bottom = *left = 0;
+ for (size_t i = 0; i < operations_.size(); ++i) {
+ const FilterOperation op = operations_[i];
+ if (op.type() == FilterOperation::FilterTypeBlur ||
+ op.type() == FilterOperation::FilterTypeDropShadow) {
+ int spread = SpreadForStdDeviation(op.amount());
+ if (op.type() == FilterOperation::FilterTypeBlur) {
+ *top += spread;
+ *right += spread;
+ *bottom += spread;
+ *left += spread;
+ } else {
+ *top += spread - op.drop_shadow_offset().y();
+ *right += spread + op.drop_shadow_offset().x();
+ *bottom += spread + op.drop_shadow_offset().y();
+ *left += spread - op.drop_shadow_offset().x();
+ }
+ }
+ }
+}
+
+bool FilterOperations::HasFilterThatMovesPixels() const {
+ for (size_t i = 0; i < operations_.size(); ++i) {
+ const FilterOperation op = operations_[i];
+ switch (op.type()) {
+ case FilterOperation::FilterTypeBlur:
+ case FilterOperation::FilterTypeDropShadow:
+ case FilterOperation::FilterTypeZoom:
+ return true;
+ default:
+ break;
+ }
+ }
+ return false;
+}
+
+bool FilterOperations::HasFilterThatAffectsOpacity() const {
+ for (size_t i = 0; i < operations_.size(); ++i) {
+ const FilterOperation op = operations_[i];
+ switch (op.type()) {
+ case FilterOperation::FilterTypeOpacity:
+ case FilterOperation::FilterTypeBlur:
+ case FilterOperation::FilterTypeDropShadow:
+ case FilterOperation::FilterTypeZoom:
+ return true;
+ case FilterOperation::FilterTypeColorMatrix: {
+ const SkScalar* matrix = op.matrix();
+ return matrix[15] || matrix[16] || matrix[17] || matrix[18] != 1 ||
+ matrix[19];
ajuma 2013/06/18 14:56:32 This early return seems wrong, since it means we c
+ }
+ default:
+ break;
+ }
+ }
+ return false;
+}
+
+} // namespace cc

Powered by Google App Engine
This is Rietveld 408576698