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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 bool FilterOperations::HasReferenceFilter() const { | 147 bool FilterOperations::HasReferenceFilter() const { |
148 for (size_t i = 0; i < operations_.size(); ++i) { | 148 for (size_t i = 0; i < operations_.size(); ++i) { |
149 if (operations_[i].type() == FilterOperation::REFERENCE) | 149 if (operations_[i].type() == FilterOperation::REFERENCE) |
150 return true; | 150 return true; |
151 } | 151 } |
152 return false; | 152 return false; |
153 } | 153 } |
154 | 154 |
155 FilterOperations FilterOperations::Blend(const FilterOperations& from, | 155 FilterOperations FilterOperations::Blend(const FilterOperations& from, |
156 double progress) const { | 156 double progress) const { |
157 FilterOperations blended_filters; | 157 if (HasReferenceFilter() || from.HasReferenceFilter()) |
158 if (from.size() == 0) { | 158 return *this; |
159 for (size_t i = 0; i < size(); i++) | 159 |
160 blended_filters.Append(FilterOperation::Blend(NULL, &at(i), progress)); | 160 bool from_is_longer = from.size() > size(); |
161 return blended_filters; | 161 |
| 162 size_t shorter_size, longer_size; |
| 163 if (size() == from.size()) { |
| 164 shorter_size = longer_size = size(); |
| 165 } else if (from_is_longer) { |
| 166 longer_size = from.size(); |
| 167 shorter_size = size(); |
| 168 } else { |
| 169 longer_size = size(); |
| 170 shorter_size = from.size(); |
162 } | 171 } |
163 | 172 |
164 if (size() == 0) { | 173 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()) | 174 if (from.at(i).type() != at(i).type()) |
177 return *this; | 175 return *this; |
178 } | 176 } |
179 | 177 |
180 for (size_t i = 0; i < size(); i++) { | 178 FilterOperations blended_filters; |
| 179 for (size_t i = 0; i < shorter_size; i++) { |
181 blended_filters.Append( | 180 blended_filters.Append( |
182 FilterOperation::Blend(&from.at(i), &at(i), progress)); | 181 FilterOperation::Blend(&from.at(i), &at(i), progress)); |
183 } | 182 } |
184 | 183 |
| 184 if (from_is_longer) { |
| 185 for (size_t i = shorter_size; i < longer_size; i++) { |
| 186 blended_filters.Append( |
| 187 FilterOperation::Blend(&from.at(i), NULL, progress)); |
| 188 } |
| 189 } else { |
| 190 for (size_t i = shorter_size; i < longer_size; i++) |
| 191 blended_filters.Append(FilterOperation::Blend(NULL, &at(i), progress)); |
| 192 } |
| 193 |
185 return blended_filters; | 194 return blended_filters; |
186 } | 195 } |
187 | 196 |
188 scoped_ptr<base::Value> FilterOperations::AsValue() const { | 197 scoped_ptr<base::Value> FilterOperations::AsValue() const { |
189 scoped_ptr<base::ListValue> value(new ListValue); | 198 scoped_ptr<base::ListValue> value(new ListValue); |
190 for (size_t i = 0; i < operations_.size(); ++i) | 199 for (size_t i = 0; i < operations_.size(); ++i) |
191 value->Append(operations_[i].AsValue().release()); | 200 value->Append(operations_[i].AsValue().release()); |
192 return value.PassAs<base::Value>(); | 201 return value.PassAs<base::Value>(); |
193 } | 202 } |
194 | 203 |
195 } // namespace cc | 204 } // namespace cc |
OLD | NEW |