Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Side by Side Diff: cc/output/filter_operations.cc

Issue 16968002: Move implementation of WebFilterOperations into cc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include <cmath>
6
7 #include "cc/output/filter_operation.h"
8 #include "cc/output/filter_operations.h"
9
10 namespace cc {
11
12 FilterOperations::FilterOperations() {
13 }
jamesr 2013/06/18 23:08:52 this can go on the previous line with no space bet
ajuma 2013/06/19 17:08:30 Done.
14
15 FilterOperations::FilterOperations(const FilterOperations& other)
16 : operations_(other.operations_) {
17 }
18
19 FilterOperations::~FilterOperations() {
20 }
21
22 FilterOperations& FilterOperations::operator=(const FilterOperations& other) {
23 operations_ = other.operations_;
24 return *this;
25 }
26
27 bool FilterOperations::operator==(const FilterOperations& other) const {
28 if (other.size() != size())
29 return false;
30 for (size_t i = 0; i < size(); ++i) {
31 if (other.at(i) != at(i))
32 return false;
33 }
34 return true;
35 }
36
37 void FilterOperations::Append(const FilterOperation& filter) {
38 operations_.push_back(filter);
39 }
40
41 void FilterOperations::Clear() {
42 operations_.clear();
43 }
44
45 bool FilterOperations::IsEmpty() const {
46 return operations_.empty();
47 }
48
49 static int SpreadForStdDeviation(float std_deviation) {
50 // https://dvcs.w3.org/hg/FXTF/raw-file/tip/filters/index.html#feGaussianBlurE lement
51 // provides this approximation for evaluating a gaussian blur by a triple box
52 // filter.
53 float d = floorf(std_deviation * 3 * sqrt(8.f * atan(1.f)) / 4 + 0.5);
54 return static_cast<int>(ceilf(d * 3 / 2));
55 }
56
57 void FilterOperations::GetOutsets(int* top,
58 int* right,
59 int* bottom,
60 int* left) const {
61 *top = *right = *bottom = *left = 0;
62 for (size_t i = 0; i < operations_.size(); ++i) {
63 const FilterOperation op = operations_[i];
64 if (op.type() == FilterOperation::FilterTypeBlur ||
65 op.type() == FilterOperation::FilterTypeDropShadow) {
66 int spread = SpreadForStdDeviation(op.amount());
67 if (op.type() == FilterOperation::FilterTypeBlur) {
68 *top += spread;
69 *right += spread;
70 *bottom += spread;
71 *left += spread;
72 } else {
73 *top += spread - op.drop_shadow_offset().y();
74 *right += spread + op.drop_shadow_offset().x();
75 *bottom += spread + op.drop_shadow_offset().y();
76 *left += spread - op.drop_shadow_offset().x();
77 }
78 }
79 }
80 }
81
82 bool FilterOperations::HasFilterThatMovesPixels() const {
83 for (size_t i = 0; i < operations_.size(); ++i) {
84 const FilterOperation op = operations_[i];
85 switch (op.type()) {
86 case FilterOperation::FilterTypeBlur:
87 case FilterOperation::FilterTypeDropShadow:
88 case FilterOperation::FilterTypeZoom:
89 return true;
90 default:
91 break;
92 }
93 }
94 return false;
95 }
96
97 bool FilterOperations::HasFilterThatAffectsOpacity() const {
98 for (size_t i = 0; i < operations_.size(); ++i) {
99 const FilterOperation op = operations_[i];
100 switch (op.type()) {
101 case FilterOperation::FilterTypeOpacity:
102 case FilterOperation::FilterTypeBlur:
103 case FilterOperation::FilterTypeDropShadow:
104 case FilterOperation::FilterTypeZoom:
105 return true;
106 case FilterOperation::FilterTypeColorMatrix: {
107 const SkScalar* matrix = op.matrix();
108 return matrix[15] || matrix[16] || matrix[17] || matrix[18] != 1 ||
109 matrix[19];
ajuma 2013/06/18 14:56:32 This early return seems wrong, since it means we c
110 }
111 default:
112 break;
113 }
114 }
115 return false;
116 }
117
118 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698