| 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 "cc/output/filter_operations.h" | 5 #include "cc/output/filter_operations.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <cmath> | 9 #include <cmath> |
| 10 #include <numeric> |
| 10 | 11 |
| 11 #include "base/trace_event/trace_event_argument.h" | 12 #include "base/trace_event/trace_event_argument.h" |
| 12 #include "base/values.h" | 13 #include "base/values.h" |
| 13 #include "cc/output/filter_operation.h" | 14 #include "cc/output/filter_operation.h" |
| 15 #include "ui/gfx/geometry/rect.h" |
| 14 | 16 |
| 15 namespace cc { | 17 namespace cc { |
| 16 | 18 |
| 17 FilterOperations::FilterOperations() {} | 19 FilterOperations::FilterOperations() {} |
| 18 | 20 |
| 19 FilterOperations::FilterOperations(const FilterOperations& other) | 21 FilterOperations::FilterOperations(const FilterOperations& other) |
| 20 : operations_(other.operations_) {} | 22 : operations_(other.operations_) {} |
| 21 | 23 |
| 22 FilterOperations::~FilterOperations() {} | 24 FilterOperations::~FilterOperations() {} |
| 23 | 25 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 49 } | 51 } |
| 50 | 52 |
| 51 static int SpreadForStdDeviation(float std_deviation) { | 53 static int SpreadForStdDeviation(float std_deviation) { |
| 52 // https://dvcs.w3.org/hg/FXTF/raw-file/tip/filters/index.html#feGaussianBlurE
lement | 54 // https://dvcs.w3.org/hg/FXTF/raw-file/tip/filters/index.html#feGaussianBlurE
lement |
| 53 // provides this approximation for evaluating a gaussian blur by a triple box | 55 // provides this approximation for evaluating a gaussian blur by a triple box |
| 54 // filter. | 56 // filter. |
| 55 float d = floorf(std_deviation * 3.f * sqrt(8.f * atan(1.f)) / 4.f + 0.5f); | 57 float d = floorf(std_deviation * 3.f * sqrt(8.f * atan(1.f)) / 4.f + 0.5f); |
| 56 return static_cast<int>(ceilf(d * 3.f / 2.f)); | 58 return static_cast<int>(ceilf(d * 3.f / 2.f)); |
| 57 } | 59 } |
| 58 | 60 |
| 61 gfx::Rect FilterOperations::MapRect(const gfx::Rect& rect) const { |
| 62 auto accumulate_rect = [](const gfx::Rect& rect, const FilterOperation& op) { |
| 63 return op.MapRect(rect); |
| 64 }; |
| 65 return std::accumulate(operations_.begin(), operations_.end(), rect, |
| 66 accumulate_rect); |
| 67 } |
| 68 |
| 59 void FilterOperations::GetOutsets(int* top, | 69 void FilterOperations::GetOutsets(int* top, |
| 60 int* right, | 70 int* right, |
| 61 int* bottom, | 71 int* bottom, |
| 62 int* left) const { | 72 int* left) const { |
| 63 *top = *right = *bottom = *left = 0; | 73 *top = *right = *bottom = *left = 0; |
| 64 for (size_t i = 0; i < operations_.size(); ++i) { | 74 for (size_t i = 0; i < operations_.size(); ++i) { |
| 65 const FilterOperation& op = operations_[i]; | 75 const FilterOperation& op = operations_[i]; |
| 66 // TODO(hendrikw): We should refactor some of this. See crbug.com/523534. | 76 // TODO(hendrikw): We should refactor some of this. See crbug.com/523534. |
| 67 if (op.type() == FilterOperation::REFERENCE) { | 77 if (op.type() == FilterOperation::REFERENCE) { |
| 68 if (!op.image_filter()) | 78 if (!op.image_filter()) |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 void FilterOperations::AsValueInto( | 222 void FilterOperations::AsValueInto( |
| 213 base::trace_event::TracedValue* value) const { | 223 base::trace_event::TracedValue* value) const { |
| 214 for (size_t i = 0; i < operations_.size(); ++i) { | 224 for (size_t i = 0; i < operations_.size(); ++i) { |
| 215 value->BeginDictionary(); | 225 value->BeginDictionary(); |
| 216 operations_[i].AsValueInto(value); | 226 operations_[i].AsValueInto(value); |
| 217 value->EndDictionary(); | 227 value->EndDictionary(); |
| 218 } | 228 } |
| 219 } | 229 } |
| 220 | 230 |
| 221 } // namespace cc | 231 } // namespace cc |
| OLD | NEW |