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

Side by Side Diff: public/platform/WebFilterOperation.h

Issue 15079005: Create a minimal webkit_common static library for use in browser process (Closed) Base URL: svn://svn.chromium.org/blink/trunk
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
1 /* 1 #include "../common/WebFilterOperation.h"
2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #ifndef WebFilterOperation_h
27 #define WebFilterOperation_h
28
29 #include "SkScalar.h"
30 #include "WebCommon.h"
31 #include "WebColor.h"
32 #include "WebPoint.h"
33
34 namespace WebKit {
35
36 class WebFilterOperation {
37 public:
38 enum FilterType {
39 FilterTypeGrayscale,
40 FilterTypeSepia,
41 FilterTypeSaturate,
42 FilterTypeHueRotate,
43 FilterTypeInvert,
44 FilterTypeBrightness,
45 FilterTypeContrast,
46 FilterTypeOpacity,
47 FilterTypeBlur,
48 FilterTypeDropShadow,
49 FilterTypeColorMatrix,
50 FilterTypeZoom,
51 FilterTypeSaturatingBrightness, // Not used in CSS/SVG.
52 };
53
54 FilterType type() const { return m_type; }
55
56 float amount() const
57 {
58 WEBKIT_ASSERT(m_type == FilterTypeGrayscale
59 || m_type == FilterTypeSepia
60 || m_type == FilterTypeSaturate
61 || m_type == FilterTypeHueRotate
62 || m_type == FilterTypeInvert
63 || m_type == FilterTypeBrightness
64 || m_type == FilterTypeContrast
65 || m_type == FilterTypeOpacity
66 || m_type == FilterTypeBlur
67 || m_type == FilterTypeDropShadow
68 || m_type == FilterTypeZoom
69 || m_type == FilterTypeSaturatingBrightness);
70 return m_amount;
71 }
72 WebPoint dropShadowOffset() const
73 {
74 WEBKIT_ASSERT(m_type == FilterTypeDropShadow);
75 return m_dropShadowOffset;
76 }
77 WebColor dropShadowColor() const
78 {
79 WEBKIT_ASSERT(m_type == FilterTypeDropShadow);
80 return m_dropShadowColor;
81 }
82 const SkScalar* matrix() const
83 {
84 WEBKIT_ASSERT(m_type == FilterTypeColorMatrix);
85 return m_matrix;
86 }
87
88 int zoomInset() const
89 {
90 WEBKIT_ASSERT(m_type == FilterTypeZoom);
91 return m_zoomInset;
92 }
93
94 static WebFilterOperation createGrayscaleFilter(float amount) { return WebFi lterOperation(FilterTypeGrayscale, amount); }
95 static WebFilterOperation createSepiaFilter(float amount) { return WebFilter Operation(FilterTypeSepia, amount); }
96 static WebFilterOperation createSaturateFilter(float amount) { return WebFil terOperation(FilterTypeSaturate, amount); }
97 static WebFilterOperation createHueRotateFilter(float amount) { return WebFi lterOperation(FilterTypeHueRotate, amount); }
98 static WebFilterOperation createInvertFilter(float amount) { return WebFilte rOperation(FilterTypeInvert, amount); }
99 static WebFilterOperation createBrightnessFilter(float amount) { return WebF ilterOperation(FilterTypeBrightness, amount); }
100 static WebFilterOperation createContrastFilter(float amount) { return WebFil terOperation(FilterTypeContrast, amount); }
101 static WebFilterOperation createOpacityFilter(float amount) { return WebFilt erOperation(FilterTypeOpacity, amount); }
102 static WebFilterOperation createBlurFilter(float amount) { return WebFilterO peration(FilterTypeBlur, amount); }
103 static WebFilterOperation createDropShadowFilter(WebPoint offset, float stdD eviation, WebColor color) { return WebFilterOperation(FilterTypeDropShadow, offs et, stdDeviation, color); }
104 static WebFilterOperation createColorMatrixFilter(SkScalar matrix[20]) { ret urn WebFilterOperation(FilterTypeColorMatrix, matrix); }
105 static WebFilterOperation createZoomFilter(float amount, int inset) { return WebFilterOperation(FilterTypeZoom, amount, inset); }
106 static WebFilterOperation createSaturatingBrightnessFilter(float amount) { r eturn WebFilterOperation(FilterTypeSaturatingBrightness, amount); }
107
108 bool equals(const WebFilterOperation& other) const;
109
110 // Methods for restoring a WebFilterOperation.
111 static WebFilterOperation createEmptyFilter() { return WebFilterOperation(Fi lterTypeGrayscale, 0.0); }
112 void setType(FilterType type) { m_type = type; }
113 void setAmount(float amount)
114 {
115 WEBKIT_ASSERT(m_type == FilterTypeGrayscale
116 || m_type == FilterTypeSepia
117 || m_type == FilterTypeSaturate
118 || m_type == FilterTypeHueRotate
119 || m_type == FilterTypeInvert
120 || m_type == FilterTypeBrightness
121 || m_type == FilterTypeContrast
122 || m_type == FilterTypeOpacity
123 || m_type == FilterTypeBlur
124 || m_type == FilterTypeDropShadow
125 || m_type == FilterTypeZoom
126 || m_type == FilterTypeSaturatingBrightness);
127 m_amount = amount;
128 }
129 void setDropShadowOffset(WebPoint offset)
130 {
131 WEBKIT_ASSERT(m_type == FilterTypeDropShadow);
132 m_dropShadowOffset = offset;
133 }
134 void setDropShadowColor(WebColor color)
135 {
136 WEBKIT_ASSERT(m_type == FilterTypeDropShadow);
137 m_dropShadowColor = color;
138 }
139 void setMatrix(const SkScalar matrix[20])
140 {
141 WEBKIT_ASSERT(m_type == FilterTypeColorMatrix);
142 for (unsigned i = 0; i < 20; ++i)
143 m_matrix[i] = matrix[i];
144 }
145 void setZoomInset(int inset)
146 {
147 WEBKIT_ASSERT(m_type == FilterTypeZoom);
148 m_zoomInset = inset;
149 }
150
151 private:
152 FilterType m_type;
153
154 float m_amount;
155 WebPoint m_dropShadowOffset;
156 WebColor m_dropShadowColor;
157 SkScalar m_matrix[20];
158 int m_zoomInset;
159
160 WebFilterOperation(FilterType type, float amount)
161 : m_type(type)
162 , m_amount(amount)
163 , m_dropShadowOffset(0, 0)
164 , m_dropShadowColor(0)
165 , m_zoomInset(0)
166 {
167 WEBKIT_ASSERT(m_type != FilterTypeDropShadow && m_type != FilterTypeColo rMatrix);
168 memset(m_matrix, 0, sizeof(m_matrix));
169 }
170
171 WebFilterOperation(FilterType type, WebPoint offset, float stdDeviation, Web Color color)
172 : m_type(type)
173 , m_amount(stdDeviation)
174 , m_dropShadowOffset(offset)
175 , m_dropShadowColor(color)
176 , m_zoomInset(0)
177 {
178 WEBKIT_ASSERT(m_type == FilterTypeDropShadow);
179 memset(m_matrix, 0, sizeof(m_matrix));
180 }
181
182 WEBKIT_EXPORT WebFilterOperation(FilterType, SkScalar matrix[20]);
183
184 WebFilterOperation(FilterType type, float amount, int inset)
185 : m_type(type)
186 , m_amount(amount)
187 , m_dropShadowOffset(0, 0)
188 , m_dropShadowColor(0)
189 , m_zoomInset(inset)
190 {
191 WEBKIT_ASSERT(m_type == FilterTypeZoom);
192 memset(m_matrix, 0, sizeof(m_matrix));
193 }
194 };
195
196 inline bool operator==(const WebFilterOperation& a, const WebFilterOperation& b)
197 {
198 return a.equals(b);
199 }
200
201 inline bool operator!=(const WebFilterOperation& a, const WebFilterOperation& b)
202 {
203 return !(a == b);
204 }
205
206 }
207
208 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698