| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <cmath> |
| 6 |
| 7 #include "cc/output/filter_operation.h" |
| 8 #include "cc/output/filter_operations.h" |
| 9 |
| 10 namespace cc { |
| 11 |
| 12 FilterOperations::FilterOperations() {} |
| 13 |
| 14 FilterOperations::FilterOperations(const FilterOperations& other) |
| 15 : operations_(other.operations_) {} |
| 16 |
| 17 FilterOperations::~FilterOperations() {} |
| 18 |
| 19 FilterOperations& FilterOperations::operator=(const FilterOperations& other) { |
| 20 operations_ = other.operations_; |
| 21 return *this; |
| 22 } |
| 23 |
| 24 bool FilterOperations::operator==(const FilterOperations& other) const { |
| 25 if (other.size() != size()) |
| 26 return false; |
| 27 for (size_t i = 0; i < size(); ++i) { |
| 28 if (other.at(i) != at(i)) |
| 29 return false; |
| 30 } |
| 31 return true; |
| 32 } |
| 33 |
| 34 void FilterOperations::Append(const FilterOperation& filter) { |
| 35 operations_.push_back(filter); |
| 36 } |
| 37 |
| 38 void FilterOperations::Clear() { |
| 39 operations_.clear(); |
| 40 } |
| 41 |
| 42 bool FilterOperations::IsEmpty() const { |
| 43 return operations_.empty(); |
| 44 } |
| 45 |
| 46 static int SpreadForStdDeviation(float std_deviation) { |
| 47 // https://dvcs.w3.org/hg/FXTF/raw-file/tip/filters/index.html#feGaussianBlurE
lement |
| 48 // provides this approximation for evaluating a gaussian blur by a triple box |
| 49 // filter. |
| 50 float d = floorf(std_deviation * 3.f * sqrt(8.f * atan(1.f)) / 4.f + 0.5f); |
| 51 return static_cast<int>(ceilf(d * 3.f / 2.f)); |
| 52 } |
| 53 |
| 54 void FilterOperations::GetOutsets(int* top, |
| 55 int* right, |
| 56 int* bottom, |
| 57 int* left) const { |
| 58 *top = *right = *bottom = *left = 0; |
| 59 for (size_t i = 0; i < operations_.size(); ++i) { |
| 60 const FilterOperation op = operations_[i]; |
| 61 if (op.type() == FilterOperation::BLUR || |
| 62 op.type() == FilterOperation::DROP_SHADOW) { |
| 63 int spread = SpreadForStdDeviation(op.amount()); |
| 64 if (op.type() == FilterOperation::BLUR) { |
| 65 *top += spread; |
| 66 *right += spread; |
| 67 *bottom += spread; |
| 68 *left += spread; |
| 69 } else { |
| 70 *top += spread - op.drop_shadow_offset().y(); |
| 71 *right += spread + op.drop_shadow_offset().x(); |
| 72 *bottom += spread + op.drop_shadow_offset().y(); |
| 73 *left += spread - op.drop_shadow_offset().x(); |
| 74 } |
| 75 } |
| 76 } |
| 77 } |
| 78 |
| 79 bool FilterOperations::HasFilterThatMovesPixels() const { |
| 80 for (size_t i = 0; i < operations_.size(); ++i) { |
| 81 const FilterOperation op = operations_[i]; |
| 82 switch (op.type()) { |
| 83 case FilterOperation::BLUR: |
| 84 case FilterOperation::DROP_SHADOW: |
| 85 case FilterOperation::ZOOM: |
| 86 return true; |
| 87 default: |
| 88 break; |
| 89 } |
| 90 } |
| 91 return false; |
| 92 } |
| 93 |
| 94 bool FilterOperations::HasFilterThatAffectsOpacity() const { |
| 95 for (size_t i = 0; i < operations_.size(); ++i) { |
| 96 const FilterOperation op = operations_[i]; |
| 97 switch (op.type()) { |
| 98 case FilterOperation::OPACITY: |
| 99 case FilterOperation::BLUR: |
| 100 case FilterOperation::DROP_SHADOW: |
| 101 case FilterOperation::ZOOM: |
| 102 return true; |
| 103 case FilterOperation::COLOR_MATRIX: { |
| 104 const SkScalar* matrix = op.matrix(); |
| 105 return matrix[15] || matrix[16] || matrix[17] || matrix[18] != 1 || |
| 106 matrix[19]; |
| 107 } |
| 108 default: |
| 109 break; |
| 110 } |
| 111 } |
| 112 return false; |
| 113 } |
| 114 |
| 115 } // namespace cc |
| OLD | NEW |