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> | |
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 { |
158 if (HasReferenceFilter() || from.HasReferenceFilter()) | |
159 return *this; | |
160 | |
157 FilterOperations blended_filters; | 161 FilterOperations blended_filters; |
158 if (from.size() == 0) { | 162 if (from.size() == 0) { |
159 for (size_t i = 0; i < size(); i++) | 163 for (size_t i = 0; i < size(); i++) |
160 blended_filters.Append(FilterOperation::Blend(NULL, &at(i), progress)); | 164 blended_filters.Append(FilterOperation::Blend(NULL, &at(i), progress)); |
161 return blended_filters; | 165 return blended_filters; |
162 } | 166 } |
163 | 167 |
164 if (size() == 0) { | 168 if (size() == 0) { |
165 for (size_t i = 0; i < from.size(); i++) { | 169 for (size_t i = 0; i < from.size(); i++) { |
166 blended_filters.Append( | 170 blended_filters.Append( |
167 FilterOperation::Blend(&from.at(i), NULL, progress)); | 171 FilterOperation::Blend(&from.at(i), NULL, progress)); |
168 } | 172 } |
169 return blended_filters; | 173 return blended_filters; |
170 } | 174 } |
171 | 175 |
172 if (from.size() != size()) | 176 if (from.size() != size()) |
173 return *this; | 177 return BlendRaggedOperations(from, progress); |
ajuma
2013/11/11 18:39:41
Could we merge the logic of blending different siz
avallee
2013/11/12 20:18:09
Done.
| |
174 | 178 |
175 for (size_t i = 0; i < size(); i++) { | 179 for (size_t i = 0; i < size(); i++) { |
176 if (from.at(i).type() != at(i).type()) | 180 if (from.at(i).type() != at(i).type()) |
177 return *this; | 181 return *this; |
178 } | 182 } |
179 | 183 |
180 for (size_t i = 0; i < size(); i++) { | 184 for (size_t i = 0; i < size(); i++) { |
181 blended_filters.Append( | 185 blended_filters.Append( |
182 FilterOperation::Blend(&from.at(i), &at(i), progress)); | 186 FilterOperation::Blend(&from.at(i), &at(i), progress)); |
183 } | 187 } |
184 | 188 |
185 return blended_filters; | 189 return blended_filters; |
186 } | 190 } |
187 | 191 |
188 scoped_ptr<base::Value> FilterOperations::AsValue() const { | 192 scoped_ptr<base::Value> FilterOperations::AsValue() const { |
189 scoped_ptr<base::ListValue> value(new ListValue); | 193 scoped_ptr<base::ListValue> value(new ListValue); |
190 for (size_t i = 0; i < operations_.size(); ++i) | 194 for (size_t i = 0; i < operations_.size(); ++i) |
191 value->Append(operations_[i].AsValue().release()); | 195 value->Append(operations_[i].AsValue().release()); |
192 return value.PassAs<base::Value>(); | 196 return value.PassAs<base::Value>(); |
193 } | 197 } |
194 | 198 |
199 FilterOperations FilterOperations::BlendRaggedOperations( | |
200 const FilterOperations& from, | |
201 double progress) const { | |
202 size_t shorter_size = std::min(from.size(), size()); | |
203 for (size_t i = 0; i < shorter_size; ++i) { | |
204 if (from.at(i).type() != at(i).type()) | |
205 return *this; | |
206 } | |
207 | |
208 FilterOperations blended_filters; | |
209 for (size_t i = 0; i < shorter_size; ++i) { | |
210 blended_filters.Append( | |
211 FilterOperation::Blend(&from.at(i), &at(i), progress)); | |
212 } | |
213 | |
214 bool from_is_longer = size() < from.size(); | |
215 | |
216 if (from_is_longer) { | |
217 for (size_t i = shorter_size; i < from.size(); ++i) { | |
218 blended_filters.Append( | |
219 FilterOperation::Blend(&from.at(i), NULL, progress)); | |
220 } | |
221 } else { | |
222 for (size_t i = shorter_size; i < size(); ++i) { | |
223 blended_filters.Append( | |
224 FilterOperation::Blend(NULL, &at(i), progress)); | |
225 } | |
226 } | |
227 | |
228 return blended_filters; | |
229 } | |
230 | |
195 } // namespace cc | 231 } // namespace cc |
OLD | NEW |