IndexedDB: fsync after transactions.
[chromium-blink-merge.git] / cc / output / filter_operation.h
blobf5c6a8264fa7eb87e0f57451f277b0bcdb6d7107
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.
5 #ifndef CC_OUTPUT_FILTER_OPERATION_H_
6 #define CC_OUTPUT_FILTER_OPERATION_H_
8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "cc/base/cc_export.h"
11 #include "skia/ext/refptr.h"
12 #include "third_party/skia/include/core/SkColor.h"
13 #include "third_party/skia/include/core/SkImageFilter.h"
14 #include "third_party/skia/include/core/SkScalar.h"
15 #include "ui/gfx/point.h"
17 namespace base {
18 class Value;
21 namespace cc {
23 class CC_EXPORT FilterOperation {
24 public:
25 enum FilterType {
26 GRAYSCALE,
27 SEPIA,
28 SATURATE,
29 HUE_ROTATE,
30 INVERT,
31 BRIGHTNESS,
32 CONTRAST,
33 OPACITY,
34 BLUR,
35 DROP_SHADOW,
36 COLOR_MATRIX,
37 ZOOM,
38 REFERENCE,
39 SATURATING_BRIGHTNESS, // Not used in CSS/SVG.
42 FilterOperation(const FilterOperation& other);
44 ~FilterOperation();
46 FilterType type() const { return type_; }
48 float amount() const {
49 DCHECK_NE(type_, COLOR_MATRIX);
50 DCHECK_NE(type_, REFERENCE);
51 return amount_;
54 gfx::Point drop_shadow_offset() const {
55 DCHECK_EQ(type_, DROP_SHADOW);
56 return drop_shadow_offset_;
59 SkColor drop_shadow_color() const {
60 DCHECK_EQ(type_, DROP_SHADOW);
61 return drop_shadow_color_;
64 skia::RefPtr<SkImageFilter> image_filter() const {
65 DCHECK_EQ(type_, REFERENCE);
66 return image_filter_;
69 const SkScalar* matrix() const {
70 DCHECK_EQ(type_, COLOR_MATRIX);
71 return matrix_;
74 int zoom_inset() const {
75 DCHECK_EQ(type_, ZOOM);
76 return zoom_inset_;
79 static FilterOperation CreateGrayscaleFilter(float amount) {
80 return FilterOperation(GRAYSCALE, amount);
83 static FilterOperation CreateSepiaFilter(float amount) {
84 return FilterOperation(SEPIA, amount);
87 static FilterOperation CreateSaturateFilter(float amount) {
88 return FilterOperation(SATURATE, amount);
91 static FilterOperation CreateHueRotateFilter(float amount) {
92 return FilterOperation(HUE_ROTATE, amount);
95 static FilterOperation CreateInvertFilter(float amount) {
96 return FilterOperation(INVERT, amount);
99 static FilterOperation CreateBrightnessFilter(float amount) {
100 return FilterOperation(BRIGHTNESS, amount);
103 static FilterOperation CreateContrastFilter(float amount) {
104 return FilterOperation(CONTRAST, amount);
107 static FilterOperation CreateOpacityFilter(float amount) {
108 return FilterOperation(OPACITY, amount);
111 static FilterOperation CreateBlurFilter(float amount) {
112 return FilterOperation(BLUR, amount);
115 static FilterOperation CreateDropShadowFilter(gfx::Point offset,
116 float std_deviation,
117 SkColor color) {
118 return FilterOperation(DROP_SHADOW, offset, std_deviation, color);
121 static FilterOperation CreateColorMatrixFilter(SkScalar matrix[20]) {
122 return FilterOperation(COLOR_MATRIX, matrix);
125 static FilterOperation CreateZoomFilter(float amount, int inset) {
126 return FilterOperation(ZOOM, amount, inset);
129 static FilterOperation CreateReferenceFilter(
130 const skia::RefPtr<SkImageFilter>& image_filter) {
131 return FilterOperation(REFERENCE, image_filter);
134 static FilterOperation CreateSaturatingBrightnessFilter(float amount) {
135 return FilterOperation(SATURATING_BRIGHTNESS, amount);
138 bool operator==(const FilterOperation& other) const;
140 bool operator!=(const FilterOperation& other) const {
141 return !(*this == other);
144 // Methods for restoring a FilterOperation.
145 static FilterOperation CreateEmptyFilter() {
146 return FilterOperation(GRAYSCALE, 0.f);
149 void set_type(FilterType type) { type_ = type; }
151 void set_amount(float amount) {
152 DCHECK_NE(type_, COLOR_MATRIX);
153 DCHECK_NE(type_, REFERENCE);
154 amount_ = amount;
157 void set_drop_shadow_offset(gfx::Point offset) {
158 DCHECK_EQ(type_, DROP_SHADOW);
159 drop_shadow_offset_ = offset;
162 void set_drop_shadow_color(SkColor color) {
163 DCHECK_EQ(type_, DROP_SHADOW);
164 drop_shadow_color_ = color;
167 void set_image_filter(const skia::RefPtr<SkImageFilter>& image_filter) {
168 DCHECK_EQ(type_, REFERENCE);
169 image_filter_ = image_filter;
172 void set_matrix(const SkScalar matrix[20]) {
173 DCHECK_EQ(type_, COLOR_MATRIX);
174 for (unsigned i = 0; i < 20; ++i)
175 matrix_[i] = matrix[i];
178 void set_zoom_inset(int inset) {
179 DCHECK_EQ(type_, ZOOM);
180 zoom_inset_ = inset;
183 // Given two filters of the same type, returns a filter operation created by
184 // linearly interpolating a |progress| fraction from |from| to |to|. If either
185 // |from| or |to| (but not both) is null, it is treated as a no-op filter of
186 // the same type as the other given filter. If both |from| and |to| are null,
187 // or if |from| and |to| are non-null but of different types, returns a
188 // no-op filter.
189 static FilterOperation Blend(const FilterOperation* from,
190 const FilterOperation* to,
191 double progress);
193 scoped_ptr<base::Value> AsValue() const;
195 private:
196 FilterOperation(FilterType type, float amount);
198 FilterOperation(FilterType type,
199 gfx::Point offset,
200 float stdDeviation,
201 SkColor color);
203 FilterOperation(FilterType, SkScalar matrix[20]);
205 FilterOperation(FilterType type, float amount, int inset);
207 FilterOperation(FilterType type,
208 const skia::RefPtr<SkImageFilter>& image_filter);
210 FilterType type_;
211 float amount_;
212 gfx::Point drop_shadow_offset_;
213 SkColor drop_shadow_color_;
214 skia::RefPtr<SkImageFilter> image_filter_;
215 SkScalar matrix_[20];
216 int zoom_inset_;
219 } // namespace cc
221 #endif // CC_OUTPUT_FILTER_OPERATION_H_