Chromium Code Reviews| 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 #ifndef CC_OUTPUT_FILTER_OPERATION_H_ | 5 #ifndef CC_OUTPUT_FILTER_OPERATION_H_ |
| 6 #define CC_OUTPUT_FILTER_OPERATION_H_ | 6 #define CC_OUTPUT_FILTER_OPERATION_H_ |
| 7 | 7 |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "cc/base/cc_export.h" | 10 #include "cc/base/cc_export.h" |
| 11 #include "skia/ext/refptr.h" | |
| 11 #include "third_party/skia/include/core/SkColor.h" | 12 #include "third_party/skia/include/core/SkColor.h" |
| 13 #include "third_party/skia/include/core/SkImageFilter.h" | |
| 12 #include "third_party/skia/include/core/SkScalar.h" | 14 #include "third_party/skia/include/core/SkScalar.h" |
| 13 #include "ui/gfx/point.h" | 15 #include "ui/gfx/point.h" |
| 14 | 16 |
| 15 namespace base { | 17 namespace base { |
| 16 class Value; | 18 class Value; |
| 17 } | 19 } |
| 18 | 20 |
| 19 namespace cc { | 21 namespace cc { |
| 20 | 22 |
| 21 class CC_EXPORT FilterOperation { | 23 class CC_EXPORT FilterOperation { |
| 22 public: | 24 public: |
| 23 enum FilterType { | 25 enum FilterType { |
| 24 GRAYSCALE, | 26 GRAYSCALE, |
| 25 SEPIA, | 27 SEPIA, |
| 26 SATURATE, | 28 SATURATE, |
| 27 HUE_ROTATE, | 29 HUE_ROTATE, |
| 28 INVERT, | 30 INVERT, |
| 29 BRIGHTNESS, | 31 BRIGHTNESS, |
| 30 CONTRAST, | 32 CONTRAST, |
| 31 OPACITY, | 33 OPACITY, |
| 32 BLUR, | 34 BLUR, |
| 33 DROP_SHADOW, | 35 DROP_SHADOW, |
| 34 COLOR_MATRIX, | 36 COLOR_MATRIX, |
| 35 ZOOM, | 37 ZOOM, |
| 38 REFERENCE, | |
| 36 SATURATING_BRIGHTNESS, // Not used in CSS/SVG. | 39 SATURATING_BRIGHTNESS, // Not used in CSS/SVG. |
| 37 }; | 40 }; |
| 38 | 41 |
| 42 FilterOperation(const FilterOperation& other); | |
| 43 | |
| 44 ~FilterOperation(); | |
| 45 | |
| 39 FilterType type() const { return type_; } | 46 FilterType type() const { return type_; } |
| 40 | 47 |
| 41 float amount() const { | 48 float amount() const { |
| 42 DCHECK_NE(type_, COLOR_MATRIX); | 49 DCHECK_NE(type_, COLOR_MATRIX); |
| 50 DCHECK_NE(type_, REFERENCE); | |
| 43 return amount_; | 51 return amount_; |
| 44 } | 52 } |
| 45 | 53 |
| 46 gfx::Point drop_shadow_offset() const { | 54 gfx::Point drop_shadow_offset() const { |
| 47 DCHECK_EQ(type_, DROP_SHADOW); | 55 DCHECK_EQ(type_, DROP_SHADOW); |
| 48 return drop_shadow_offset_; | 56 return drop_shadow_offset_; |
| 49 } | 57 } |
| 50 | 58 |
| 51 SkColor drop_shadow_color() const { | 59 SkColor drop_shadow_color() const { |
| 52 DCHECK_EQ(type_, DROP_SHADOW); | 60 DCHECK_EQ(type_, DROP_SHADOW); |
| 53 return drop_shadow_color_; | 61 return drop_shadow_color_; |
| 54 } | 62 } |
| 55 | 63 |
| 64 skia::RefPtr<SkImageFilter> image_filter() const { | |
| 65 DCHECK_EQ(type_, REFERENCE); | |
| 66 return image_filter_; | |
| 67 } | |
| 68 | |
| 56 const SkScalar* matrix() const { | 69 const SkScalar* matrix() const { |
| 57 DCHECK_EQ(type_, COLOR_MATRIX); | 70 DCHECK_EQ(type_, COLOR_MATRIX); |
| 58 return matrix_; | 71 return matrix_; |
| 59 } | 72 } |
| 60 | 73 |
| 61 int zoom_inset() const { | 74 int zoom_inset() const { |
| 62 DCHECK_EQ(type_, ZOOM); | 75 DCHECK_EQ(type_, ZOOM); |
| 63 return zoom_inset_; | 76 return zoom_inset_; |
| 64 } | 77 } |
| 65 | 78 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 106 } | 119 } |
| 107 | 120 |
| 108 static FilterOperation CreateColorMatrixFilter(SkScalar matrix[20]) { | 121 static FilterOperation CreateColorMatrixFilter(SkScalar matrix[20]) { |
| 109 return FilterOperation(COLOR_MATRIX, matrix); | 122 return FilterOperation(COLOR_MATRIX, matrix); |
| 110 } | 123 } |
| 111 | 124 |
| 112 static FilterOperation CreateZoomFilter(float amount, int inset) { | 125 static FilterOperation CreateZoomFilter(float amount, int inset) { |
| 113 return FilterOperation(ZOOM, amount, inset); | 126 return FilterOperation(ZOOM, amount, inset); |
| 114 } | 127 } |
| 115 | 128 |
| 129 static FilterOperation CreateReferenceFilter( | |
| 130 const skia::RefPtr<SkImageFilter> image_filter) { | |
|
danakj
2013/09/09 22:04:50
did you mean const& ?
ajuma
2013/09/10 21:17:58
Done.
| |
| 131 return FilterOperation(REFERENCE, image_filter); | |
| 132 } | |
| 133 | |
| 116 static FilterOperation CreateSaturatingBrightnessFilter(float amount) { | 134 static FilterOperation CreateSaturatingBrightnessFilter(float amount) { |
| 117 return FilterOperation(SATURATING_BRIGHTNESS, amount); | 135 return FilterOperation(SATURATING_BRIGHTNESS, amount); |
| 118 } | 136 } |
| 119 | 137 |
| 120 bool operator==(const FilterOperation& other) const; | 138 bool operator==(const FilterOperation& other) const; |
| 121 | 139 |
| 122 bool operator!=(const FilterOperation& other) const { | 140 bool operator!=(const FilterOperation& other) const { |
| 123 return !(*this == other); | 141 return !(*this == other); |
| 124 } | 142 } |
| 125 | 143 |
| 126 // Methods for restoring a FilterOperation. | 144 // Methods for restoring a FilterOperation. |
| 127 static FilterOperation CreateEmptyFilter() { | 145 static FilterOperation CreateEmptyFilter() { |
| 128 return FilterOperation(GRAYSCALE, 0.f); | 146 return FilterOperation(GRAYSCALE, 0.f); |
| 129 } | 147 } |
| 130 | 148 |
| 131 void set_type(FilterType type) { type_ = type; } | 149 void set_type(FilterType type) { type_ = type; } |
| 132 | 150 |
| 133 void set_amount(float amount) { | 151 void set_amount(float amount) { |
| 134 DCHECK_NE(type_, COLOR_MATRIX); | 152 DCHECK_NE(type_, COLOR_MATRIX); |
| 153 DCHECK_NE(type_, REFERENCE); | |
| 135 amount_ = amount; | 154 amount_ = amount; |
| 136 } | 155 } |
| 137 | 156 |
| 138 void set_drop_shadow_offset(gfx::Point offset) { | 157 void set_drop_shadow_offset(gfx::Point offset) { |
| 139 DCHECK_EQ(type_, DROP_SHADOW); | 158 DCHECK_EQ(type_, DROP_SHADOW); |
| 140 drop_shadow_offset_ = offset; | 159 drop_shadow_offset_ = offset; |
| 141 } | 160 } |
| 142 | 161 |
| 143 void set_drop_shadow_color(SkColor color) { | 162 void set_drop_shadow_color(SkColor color) { |
| 144 DCHECK_EQ(type_, DROP_SHADOW); | 163 DCHECK_EQ(type_, DROP_SHADOW); |
| 145 drop_shadow_color_ = color; | 164 drop_shadow_color_ = color; |
| 146 } | 165 } |
| 147 | 166 |
| 167 void set_image_filter(const skia::RefPtr<SkImageFilter>& image_filter) { | |
| 168 DCHECK_EQ(type_, REFERENCE); | |
| 169 image_filter_ = image_filter; | |
| 170 } | |
| 171 | |
| 148 void set_matrix(const SkScalar matrix[20]) { | 172 void set_matrix(const SkScalar matrix[20]) { |
| 149 DCHECK_EQ(type_, COLOR_MATRIX); | 173 DCHECK_EQ(type_, COLOR_MATRIX); |
| 150 for (unsigned i = 0; i < 20; ++i) | 174 for (unsigned i = 0; i < 20; ++i) |
| 151 matrix_[i] = matrix[i]; | 175 matrix_[i] = matrix[i]; |
| 152 } | 176 } |
| 153 | 177 |
| 154 void set_zoom_inset(int inset) { | 178 void set_zoom_inset(int inset) { |
| 155 DCHECK_EQ(type_, ZOOM); | 179 DCHECK_EQ(type_, ZOOM); |
| 156 zoom_inset_ = inset; | 180 zoom_inset_ = inset; |
| 157 } | 181 } |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 173 | 197 |
| 174 FilterOperation(FilterType type, | 198 FilterOperation(FilterType type, |
| 175 gfx::Point offset, | 199 gfx::Point offset, |
| 176 float stdDeviation, | 200 float stdDeviation, |
| 177 SkColor color); | 201 SkColor color); |
| 178 | 202 |
| 179 FilterOperation(FilterType, SkScalar matrix[20]); | 203 FilterOperation(FilterType, SkScalar matrix[20]); |
| 180 | 204 |
| 181 FilterOperation(FilterType type, float amount, int inset); | 205 FilterOperation(FilterType type, float amount, int inset); |
| 182 | 206 |
| 207 FilterOperation(FilterType type, | |
| 208 const skia::RefPtr<SkImageFilter>& image_filter); | |
| 209 | |
| 183 FilterType type_; | 210 FilterType type_; |
| 184 float amount_; | 211 float amount_; |
| 185 gfx::Point drop_shadow_offset_; | 212 gfx::Point drop_shadow_offset_; |
| 186 SkColor drop_shadow_color_; | 213 SkColor drop_shadow_color_; |
| 214 skia::RefPtr<SkImageFilter> image_filter_; | |
| 187 SkScalar matrix_[20]; | 215 SkScalar matrix_[20]; |
| 188 int zoom_inset_; | 216 int zoom_inset_; |
| 189 }; | 217 }; |
| 190 | 218 |
| 191 } // namespace cc | 219 } // namespace cc |
| 192 | 220 |
| 193 #endif // CC_OUTPUT_FILTER_OPERATION_H_ | 221 #endif // CC_OUTPUT_FILTER_OPERATION_H_ |
| OLD | NEW |