Chromium Code Reviews| 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): Add support for reference filters once SkImageFilter | |
| 88 // reports its outsets. | |
| 89 DCHECK(op.type() != FilterOperation::REFERENCE); | |
|
enne (OOO)
2013/09/11 17:57:24
This is a little awkward to DCHECK here because it
danakj
2013/09/11 18:01:55
I'd agree if the damage tracker didn't use invalid
enne (OOO)
2013/09/11 18:06:33
So DCHECK in GetOutsets, but don't DCHECK here?
danakj
2013/09/11 18:18:17
Hm, ya okay. I hadn't considered that originally.
ajuma
2013/09/11 18:24:56
Done.
| |
| 84 switch (op.type()) { | 90 switch (op.type()) { |
| 85 case FilterOperation::BLUR: | 91 case FilterOperation::BLUR: |
| 86 case FilterOperation::DROP_SHADOW: | 92 case FilterOperation::DROP_SHADOW: |
| 87 case FilterOperation::ZOOM: | 93 case FilterOperation::ZOOM: |
| 94 case FilterOperation::REFERENCE: | |
| 88 return true; | 95 return true; |
| 89 case FilterOperation::OPACITY: | 96 case FilterOperation::OPACITY: |
| 90 case FilterOperation::COLOR_MATRIX: | 97 case FilterOperation::COLOR_MATRIX: |
| 91 case FilterOperation::GRAYSCALE: | 98 case FilterOperation::GRAYSCALE: |
| 92 case FilterOperation::SEPIA: | 99 case FilterOperation::SEPIA: |
| 93 case FilterOperation::SATURATE: | 100 case FilterOperation::SATURATE: |
| 94 case FilterOperation::HUE_ROTATE: | 101 case FilterOperation::HUE_ROTATE: |
| 95 case FilterOperation::INVERT: | 102 case FilterOperation::INVERT: |
| 96 case FilterOperation::BRIGHTNESS: | 103 case FilterOperation::BRIGHTNESS: |
| 97 case FilterOperation::CONTRAST: | 104 case FilterOperation::CONTRAST: |
| 98 case FilterOperation::SATURATING_BRIGHTNESS: | 105 case FilterOperation::SATURATING_BRIGHTNESS: |
| 99 break; | 106 break; |
| 100 } | 107 } |
| 101 } | 108 } |
| 102 return false; | 109 return false; |
| 103 } | 110 } |
| 104 | 111 |
| 105 bool FilterOperations::HasFilterThatAffectsOpacity() const { | 112 bool FilterOperations::HasFilterThatAffectsOpacity() const { |
| 106 for (size_t i = 0; i < operations_.size(); ++i) { | 113 for (size_t i = 0; i < operations_.size(); ++i) { |
| 107 const FilterOperation op = operations_[i]; | 114 const FilterOperation& op = operations_[i]; |
| 115 // TODO(ajuma): Make this smarter for reference filters. Once SkImageFilter | |
| 116 // can report affectsOpacity(), call that. | |
| 108 switch (op.type()) { | 117 switch (op.type()) { |
| 109 case FilterOperation::OPACITY: | 118 case FilterOperation::OPACITY: |
| 110 case FilterOperation::BLUR: | 119 case FilterOperation::BLUR: |
| 111 case FilterOperation::DROP_SHADOW: | 120 case FilterOperation::DROP_SHADOW: |
| 112 case FilterOperation::ZOOM: | 121 case FilterOperation::ZOOM: |
| 122 case FilterOperation::REFERENCE: | |
| 113 return true; | 123 return true; |
| 114 case FilterOperation::COLOR_MATRIX: { | 124 case FilterOperation::COLOR_MATRIX: { |
| 115 const SkScalar* matrix = op.matrix(); | 125 const SkScalar* matrix = op.matrix(); |
| 116 if (matrix[15] || | 126 if (matrix[15] || |
| 117 matrix[16] || | 127 matrix[16] || |
| 118 matrix[17] || | 128 matrix[17] || |
| 119 matrix[18] != 1 || | 129 matrix[18] != 1 || |
| 120 matrix[19]) | 130 matrix[19]) |
| 121 return true; | 131 return true; |
| 122 break; | 132 break; |
| 123 } | 133 } |
| 124 case FilterOperation::GRAYSCALE: | 134 case FilterOperation::GRAYSCALE: |
| 125 case FilterOperation::SEPIA: | 135 case FilterOperation::SEPIA: |
| 126 case FilterOperation::SATURATE: | 136 case FilterOperation::SATURATE: |
| 127 case FilterOperation::HUE_ROTATE: | 137 case FilterOperation::HUE_ROTATE: |
| 128 case FilterOperation::INVERT: | 138 case FilterOperation::INVERT: |
| 129 case FilterOperation::BRIGHTNESS: | 139 case FilterOperation::BRIGHTNESS: |
| 130 case FilterOperation::CONTRAST: | 140 case FilterOperation::CONTRAST: |
| 131 case FilterOperation::SATURATING_BRIGHTNESS: | 141 case FilterOperation::SATURATING_BRIGHTNESS: |
| 132 break; | 142 break; |
| 133 } | 143 } |
| 134 } | 144 } |
| 135 return false; | 145 return false; |
| 136 } | 146 } |
| 137 | 147 |
| 148 bool FilterOperations::HasReferenceFilter() const { | |
| 149 for (size_t i = 0; i < operations_.size(); ++i) { | |
| 150 if (operations_[i].type() == FilterOperation::REFERENCE) | |
| 151 return true; | |
| 152 } | |
| 153 return false; | |
| 154 } | |
| 155 | |
| 138 FilterOperations FilterOperations::Blend(const FilterOperations& from, | 156 FilterOperations FilterOperations::Blend(const FilterOperations& from, |
| 139 double progress) const { | 157 double progress) const { |
| 140 FilterOperations blended_filters; | 158 FilterOperations blended_filters; |
| 141 if (from.size() == 0) { | 159 if (from.size() == 0) { |
| 142 for (size_t i = 0; i < size(); i++) | 160 for (size_t i = 0; i < size(); i++) |
| 143 blended_filters.Append(FilterOperation::Blend(NULL, &at(i), progress)); | 161 blended_filters.Append(FilterOperation::Blend(NULL, &at(i), progress)); |
| 144 return blended_filters; | 162 return blended_filters; |
| 145 } | 163 } |
| 146 | 164 |
| 147 if (size() == 0) { | 165 if (size() == 0) { |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 169 } | 187 } |
| 170 | 188 |
| 171 scoped_ptr<base::Value> FilterOperations::AsValue() const { | 189 scoped_ptr<base::Value> FilterOperations::AsValue() const { |
| 172 scoped_ptr<base::ListValue> value(new ListValue); | 190 scoped_ptr<base::ListValue> value(new ListValue); |
| 173 for (size_t i = 0; i < operations_.size(); ++i) | 191 for (size_t i = 0; i < operations_.size(); ++i) |
| 174 value->Append(operations_[i].AsValue().release()); | 192 value->Append(operations_[i].AsValue().release()); |
| 175 return value.PassAs<base::Value>(); | 193 return value.PassAs<base::Value>(); |
| 176 } | 194 } |
| 177 | 195 |
| 178 } // namespace cc | 196 } // namespace cc |
| OLD | NEW |