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 <algorithm> | |
ajuma
2013/11/12 21:39:42
Can this be removed?
avallee
2013/11/12 21:42:16
Sorry, missed that before. Done.
| |
5 #include <cmath> | 6 #include <cmath> |
6 | 7 |
7 #include "cc/output/filter_operations.h" | 8 #include "cc/output/filter_operations.h" |
8 | 9 |
9 #include "base/values.h" | 10 #include "base/values.h" |
10 #include "cc/output/filter_operation.h" | 11 #include "cc/output/filter_operation.h" |
11 | 12 |
12 namespace cc { | 13 namespace cc { |
13 | 14 |
14 FilterOperations::FilterOperations() {} | 15 FilterOperations::FilterOperations() {} |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
147 bool FilterOperations::HasReferenceFilter() const { | 148 bool FilterOperations::HasReferenceFilter() const { |
148 for (size_t i = 0; i < operations_.size(); ++i) { | 149 for (size_t i = 0; i < operations_.size(); ++i) { |
149 if (operations_[i].type() == FilterOperation::REFERENCE) | 150 if (operations_[i].type() == FilterOperation::REFERENCE) |
150 return true; | 151 return true; |
151 } | 152 } |
152 return false; | 153 return false; |
153 } | 154 } |
154 | 155 |
155 FilterOperations FilterOperations::Blend(const FilterOperations& from, | 156 FilterOperations FilterOperations::Blend(const FilterOperations& from, |
156 double progress) const { | 157 double progress) const { |
157 FilterOperations blended_filters; | 158 if (HasReferenceFilter() || from.HasReferenceFilter()) |
158 if (from.size() == 0) { | 159 return *this; |
159 for (size_t i = 0; i < size(); i++) | 160 |
160 blended_filters.Append(FilterOperation::Blend(NULL, &at(i), progress)); | 161 bool from_is_longer = from.size() > size(); |
161 return blended_filters; | 162 |
163 size_t shorter_size, longer_size; | |
164 if (size() == from.size()) { | |
165 shorter_size = longer_size = size(); | |
166 } else if (from_is_longer) { | |
167 longer_size = from.size(); | |
168 shorter_size = size(); | |
169 } else { | |
170 longer_size = size(); | |
171 shorter_size = from.size(); | |
162 } | 172 } |
163 | 173 |
164 if (size() == 0) { | 174 for (size_t i = 0; i < shorter_size; i++) { |
165 for (size_t i = 0; i < from.size(); i++) { | |
166 blended_filters.Append( | |
167 FilterOperation::Blend(&from.at(i), NULL, progress)); | |
168 } | |
169 return blended_filters; | |
170 } | |
171 | |
172 if (from.size() != size()) | |
173 return *this; | |
174 | |
175 for (size_t i = 0; i < size(); i++) { | |
176 if (from.at(i).type() != at(i).type()) | 175 if (from.at(i).type() != at(i).type()) |
177 return *this; | 176 return *this; |
178 } | 177 } |
179 | 178 |
180 for (size_t i = 0; i < size(); i++) { | 179 FilterOperations blended_filters; |
180 for (size_t i = 0; i < shorter_size; i++) { | |
181 blended_filters.Append( | 181 blended_filters.Append( |
182 FilterOperation::Blend(&from.at(i), &at(i), progress)); | 182 FilterOperation::Blend(&from.at(i), &at(i), progress)); |
183 } | 183 } |
184 | 184 |
185 if (from_is_longer) { | |
186 for (size_t i = shorter_size; i < longer_size; i++) { | |
187 blended_filters.Append( | |
188 FilterOperation::Blend(&from.at(i), NULL, progress)); | |
189 } | |
190 } else { | |
191 for (size_t i = shorter_size; i < longer_size; i++) | |
192 blended_filters.Append(FilterOperation::Blend(NULL, &at(i), progress)); | |
193 } | |
194 | |
185 return blended_filters; | 195 return blended_filters; |
186 } | 196 } |
187 | 197 |
188 scoped_ptr<base::Value> FilterOperations::AsValue() const { | 198 scoped_ptr<base::Value> FilterOperations::AsValue() const { |
189 scoped_ptr<base::ListValue> value(new ListValue); | 199 scoped_ptr<base::ListValue> value(new ListValue); |
190 for (size_t i = 0; i < operations_.size(); ++i) | 200 for (size_t i = 0; i < operations_.size(); ++i) |
191 value->Append(operations_[i].AsValue().release()); | 201 value->Append(operations_[i].AsValue().release()); |
192 return value.PassAs<base::Value>(); | 202 return value.PassAs<base::Value>(); |
193 } | 203 } |
194 | 204 |
195 } // namespace cc | 205 } // namespace cc |
OLD | NEW |