| OLD | NEW |
| 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 <cmath> | 5 #include <cmath> |
| 6 | 6 |
| 7 #include "cc/output/filter_operations.h" | 7 #include "cc/output/filter_operations.h" |
| 8 | 8 |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "cc/output/filter_operation.h" | 10 #include "cc/output/filter_operation.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 float d = floorf(std_deviation * 3.f * sqrt(8.f * atan(1.f)) / 4.f + 0.5f); | 52 float d = floorf(std_deviation * 3.f * sqrt(8.f * atan(1.f)) / 4.f + 0.5f); |
| 53 return static_cast<int>(ceilf(d * 3.f / 2.f)); | 53 return static_cast<int>(ceilf(d * 3.f / 2.f)); |
| 54 } | 54 } |
| 55 | 55 |
| 56 void FilterOperations::GetOutsets(int* top, | 56 void FilterOperations::GetOutsets(int* top, |
| 57 int* right, | 57 int* right, |
| 58 int* bottom, | 58 int* bottom, |
| 59 int* left) const { | 59 int* left) const { |
| 60 *top = *right = *bottom = *left = 0; | 60 *top = *right = *bottom = *left = 0; |
| 61 for (size_t i = 0; i < operations_.size(); ++i) { | 61 for (size_t i = 0; i < operations_.size(); ++i) { |
| 62 const FilterOperation op = operations_[i]; | 62 const FilterOperation& op = operations_[i]; |
| 63 // TODO(ajuma): Add support for reference filters once SkImageFilter |
| 64 // reports its outsets. |
| 65 DCHECK(op.type() != FilterOperation::REFERENCE); |
| 63 if (op.type() == FilterOperation::BLUR || | 66 if (op.type() == FilterOperation::BLUR || |
| 64 op.type() == FilterOperation::DROP_SHADOW) { | 67 op.type() == FilterOperation::DROP_SHADOW) { |
| 65 int spread = SpreadForStdDeviation(op.amount()); | 68 int spread = SpreadForStdDeviation(op.amount()); |
| 66 if (op.type() == FilterOperation::BLUR) { | 69 if (op.type() == FilterOperation::BLUR) { |
| 67 *top += spread; | 70 *top += spread; |
| 68 *right += spread; | 71 *right += spread; |
| 69 *bottom += spread; | 72 *bottom += spread; |
| 70 *left += spread; | 73 *left += spread; |
| 71 } else { | 74 } else { |
| 72 *top += spread - op.drop_shadow_offset().y(); | 75 *top += spread - op.drop_shadow_offset().y(); |
| 73 *right += spread + op.drop_shadow_offset().x(); | 76 *right += spread + op.drop_shadow_offset().x(); |
| 74 *bottom += spread + op.drop_shadow_offset().y(); | 77 *bottom += spread + op.drop_shadow_offset().y(); |
| 75 *left += spread - op.drop_shadow_offset().x(); | 78 *left += spread - op.drop_shadow_offset().x(); |
| 76 } | 79 } |
| 77 } | 80 } |
| 78 } | 81 } |
| 79 } | 82 } |
| 80 | 83 |
| 81 bool FilterOperations::HasFilterThatMovesPixels() const { | 84 bool FilterOperations::HasFilterThatMovesPixels() const { |
| 82 for (size_t i = 0; i < operations_.size(); ++i) { | 85 for (size_t i = 0; i < operations_.size(); ++i) { |
| 83 const FilterOperation op = operations_[i]; | 86 const FilterOperation& op = operations_[i]; |
| 87 // TODO(ajuma): Once SkImageFilter reports its outsets, use those here to |
| 88 // determine whether a reference filter really moves pixels. |
| 84 switch (op.type()) { | 89 switch (op.type()) { |
| 85 case FilterOperation::BLUR: | 90 case FilterOperation::BLUR: |
| 86 case FilterOperation::DROP_SHADOW: | 91 case FilterOperation::DROP_SHADOW: |
| 87 case FilterOperation::ZOOM: | 92 case FilterOperation::ZOOM: |
| 93 case FilterOperation::REFERENCE: |
| 88 return true; | 94 return true; |
| 89 case FilterOperation::OPACITY: | 95 case FilterOperation::OPACITY: |
| 90 case FilterOperation::COLOR_MATRIX: | 96 case FilterOperation::COLOR_MATRIX: |
| 91 case FilterOperation::GRAYSCALE: | 97 case FilterOperation::GRAYSCALE: |
| 92 case FilterOperation::SEPIA: | 98 case FilterOperation::SEPIA: |
| 93 case FilterOperation::SATURATE: | 99 case FilterOperation::SATURATE: |
| 94 case FilterOperation::HUE_ROTATE: | 100 case FilterOperation::HUE_ROTATE: |
| 95 case FilterOperation::INVERT: | 101 case FilterOperation::INVERT: |
| 96 case FilterOperation::BRIGHTNESS: | 102 case FilterOperation::BRIGHTNESS: |
| 97 case FilterOperation::CONTRAST: | 103 case FilterOperation::CONTRAST: |
| 98 case FilterOperation::SATURATING_BRIGHTNESS: | 104 case FilterOperation::SATURATING_BRIGHTNESS: |
| 99 break; | 105 break; |
| 100 } | 106 } |
| 101 } | 107 } |
| 102 return false; | 108 return false; |
| 103 } | 109 } |
| 104 | 110 |
| 105 bool FilterOperations::HasFilterThatAffectsOpacity() const { | 111 bool FilterOperations::HasFilterThatAffectsOpacity() const { |
| 106 for (size_t i = 0; i < operations_.size(); ++i) { | 112 for (size_t i = 0; i < operations_.size(); ++i) { |
| 107 const FilterOperation op = operations_[i]; | 113 const FilterOperation& op = operations_[i]; |
| 114 // TODO(ajuma): Make this smarter for reference filters. Once SkImageFilter |
| 115 // can report affectsOpacity(), call that. |
| 108 switch (op.type()) { | 116 switch (op.type()) { |
| 109 case FilterOperation::OPACITY: | 117 case FilterOperation::OPACITY: |
| 110 case FilterOperation::BLUR: | 118 case FilterOperation::BLUR: |
| 111 case FilterOperation::DROP_SHADOW: | 119 case FilterOperation::DROP_SHADOW: |
| 112 case FilterOperation::ZOOM: | 120 case FilterOperation::ZOOM: |
| 121 case FilterOperation::REFERENCE: |
| 113 return true; | 122 return true; |
| 114 case FilterOperation::COLOR_MATRIX: { | 123 case FilterOperation::COLOR_MATRIX: { |
| 115 const SkScalar* matrix = op.matrix(); | 124 const SkScalar* matrix = op.matrix(); |
| 116 if (matrix[15] || | 125 if (matrix[15] || |
| 117 matrix[16] || | 126 matrix[16] || |
| 118 matrix[17] || | 127 matrix[17] || |
| 119 matrix[18] != 1 || | 128 matrix[18] != 1 || |
| 120 matrix[19]) | 129 matrix[19]) |
| 121 return true; | 130 return true; |
| 122 break; | 131 break; |
| 123 } | 132 } |
| 124 case FilterOperation::GRAYSCALE: | 133 case FilterOperation::GRAYSCALE: |
| 125 case FilterOperation::SEPIA: | 134 case FilterOperation::SEPIA: |
| 126 case FilterOperation::SATURATE: | 135 case FilterOperation::SATURATE: |
| 127 case FilterOperation::HUE_ROTATE: | 136 case FilterOperation::HUE_ROTATE: |
| 128 case FilterOperation::INVERT: | 137 case FilterOperation::INVERT: |
| 129 case FilterOperation::BRIGHTNESS: | 138 case FilterOperation::BRIGHTNESS: |
| 130 case FilterOperation::CONTRAST: | 139 case FilterOperation::CONTRAST: |
| 131 case FilterOperation::SATURATING_BRIGHTNESS: | 140 case FilterOperation::SATURATING_BRIGHTNESS: |
| 132 break; | 141 break; |
| 133 } | 142 } |
| 134 } | 143 } |
| 135 return false; | 144 return false; |
| 136 } | 145 } |
| 137 | 146 |
| 147 bool FilterOperations::HasReferenceFilter() const { |
| 148 for (size_t i = 0; i < operations_.size(); ++i) { |
| 149 if (operations_[i].type() == FilterOperation::REFERENCE) |
| 150 return true; |
| 151 } |
| 152 return false; |
| 153 } |
| 154 |
| 138 FilterOperations FilterOperations::Blend(const FilterOperations& from, | 155 FilterOperations FilterOperations::Blend(const FilterOperations& from, |
| 139 double progress) const { | 156 double progress) const { |
| 140 FilterOperations blended_filters; | 157 FilterOperations blended_filters; |
| 141 if (from.size() == 0) { | 158 if (from.size() == 0) { |
| 142 for (size_t i = 0; i < size(); i++) | 159 for (size_t i = 0; i < size(); i++) |
| 143 blended_filters.Append(FilterOperation::Blend(NULL, &at(i), progress)); | 160 blended_filters.Append(FilterOperation::Blend(NULL, &at(i), progress)); |
| 144 return blended_filters; | 161 return blended_filters; |
| 145 } | 162 } |
| 146 | 163 |
| 147 if (size() == 0) { | 164 if (size() == 0) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 169 } | 186 } |
| 170 | 187 |
| 171 scoped_ptr<base::Value> FilterOperations::AsValue() const { | 188 scoped_ptr<base::Value> FilterOperations::AsValue() const { |
| 172 scoped_ptr<base::ListValue> value(new ListValue); | 189 scoped_ptr<base::ListValue> value(new ListValue); |
| 173 for (size_t i = 0; i < operations_.size(); ++i) | 190 for (size_t i = 0; i < operations_.size(); ++i) |
| 174 value->Append(operations_[i].AsValue().release()); | 191 value->Append(operations_[i].AsValue().release()); |
| 175 return value.PassAs<base::Value>(); | 192 return value.PassAs<base::Value>(); |
| 176 } | 193 } |
| 177 | 194 |
| 178 } // namespace cc | 195 } // namespace cc |
| OLD | NEW |