| OLD | NEW |
| (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 #ifndef CC_OUTPUT_FILTER_OPERATION_H_ |
| 6 #define CC_OUTPUT_FILTER_OPERATION_H_ |
| 7 |
| 8 #include "base/logging.h" |
| 9 #include "cc/base/cc_export.h" |
| 10 #include "third_party/skia/include/core/SkColor.h" |
| 11 #include "third_party/skia/include/core/SkScalar.h" |
| 12 #include "ui/gfx/point.h" |
| 13 |
| 14 namespace cc { |
| 15 |
| 16 class CC_EXPORT FilterOperation { |
| 17 public: |
| 18 enum FilterType { |
| 19 GRAYSCALE, |
| 20 SEPIA, |
| 21 SATURATE, |
| 22 HUE_ROTATE, |
| 23 INVERT, |
| 24 BRIGHTNESS, |
| 25 CONTRAST, |
| 26 OPACITY, |
| 27 BLUR, |
| 28 DROP_SHADOW, |
| 29 COLOR_MATRIX, |
| 30 ZOOM, |
| 31 SATURATING_BRIGHTNESS, // Not used in CSS/SVG. |
| 32 }; |
| 33 |
| 34 FilterType type() const { return type_; } |
| 35 |
| 36 float amount() const { |
| 37 DCHECK_NE(type_, COLOR_MATRIX); |
| 38 return amount_; |
| 39 } |
| 40 |
| 41 gfx::Point drop_shadow_offset() const { |
| 42 DCHECK_EQ(type_, DROP_SHADOW); |
| 43 return drop_shadow_offset_; |
| 44 } |
| 45 |
| 46 SkColor drop_shadow_color() const { |
| 47 DCHECK_EQ(type_, DROP_SHADOW); |
| 48 return drop_shadow_color_; |
| 49 } |
| 50 |
| 51 const SkScalar* matrix() const { |
| 52 DCHECK_EQ(type_, COLOR_MATRIX); |
| 53 return matrix_; |
| 54 } |
| 55 |
| 56 int zoom_inset() const { |
| 57 DCHECK_EQ(type_, ZOOM); |
| 58 return zoom_inset_; |
| 59 } |
| 60 |
| 61 static FilterOperation CreateGrayscaleFilter(float amount) { |
| 62 return FilterOperation(GRAYSCALE, amount); |
| 63 } |
| 64 |
| 65 static FilterOperation CreateSepiaFilter(float amount) { |
| 66 return FilterOperation(SEPIA, amount); |
| 67 } |
| 68 |
| 69 static FilterOperation CreateSaturateFilter(float amount) { |
| 70 return FilterOperation(SATURATE, amount); |
| 71 } |
| 72 |
| 73 static FilterOperation CreateHueRotateFilter(float amount) { |
| 74 return FilterOperation(HUE_ROTATE, amount); |
| 75 } |
| 76 |
| 77 static FilterOperation CreateInvertFilter(float amount) { |
| 78 return FilterOperation(INVERT, amount); |
| 79 } |
| 80 |
| 81 static FilterOperation CreateBrightnessFilter(float amount) { |
| 82 return FilterOperation(BRIGHTNESS, amount); |
| 83 } |
| 84 |
| 85 static FilterOperation CreateContrastFilter(float amount) { |
| 86 return FilterOperation(CONTRAST, amount); |
| 87 } |
| 88 |
| 89 static FilterOperation CreateOpacityFilter(float amount) { |
| 90 return FilterOperation(OPACITY, amount); |
| 91 } |
| 92 |
| 93 static FilterOperation CreateBlurFilter(float amount) { |
| 94 return FilterOperation(BLUR, amount); |
| 95 } |
| 96 |
| 97 static FilterOperation CreateDropShadowFilter(gfx::Point offset, |
| 98 float std_deviation, |
| 99 SkColor color) { |
| 100 return FilterOperation(DROP_SHADOW, offset, std_deviation, color); |
| 101 } |
| 102 |
| 103 static FilterOperation CreateColorMatrixFilter(SkScalar matrix[20]) { |
| 104 return FilterOperation(COLOR_MATRIX, matrix); |
| 105 } |
| 106 |
| 107 static FilterOperation CreateZoomFilter(float amount, int inset) { |
| 108 return FilterOperation(ZOOM, amount, inset); |
| 109 } |
| 110 |
| 111 static FilterOperation CreateSaturatingBrightnessFilter(float amount) { |
| 112 return FilterOperation(SATURATING_BRIGHTNESS, amount); |
| 113 } |
| 114 |
| 115 bool operator==(const FilterOperation& other) const; |
| 116 |
| 117 bool operator!=(const FilterOperation& other) const { |
| 118 return !(*this == other); |
| 119 } |
| 120 |
| 121 // Methods for restoring a FilterOperation. |
| 122 static FilterOperation CreateEmptyFilter() { |
| 123 return FilterOperation(GRAYSCALE, 0.f); |
| 124 } |
| 125 |
| 126 void set_type(FilterType type) { type_ = type; } |
| 127 |
| 128 void set_amount(float amount) { |
| 129 DCHECK_NE(type_, COLOR_MATRIX); |
| 130 amount_ = amount; |
| 131 } |
| 132 |
| 133 void set_drop_shadow_offset(gfx::Point offset) { |
| 134 DCHECK_EQ(type_, DROP_SHADOW); |
| 135 drop_shadow_offset_ = offset; |
| 136 } |
| 137 |
| 138 void set_drop_shadow_color(SkColor color) { |
| 139 DCHECK_EQ(type_, DROP_SHADOW); |
| 140 drop_shadow_color_ = color; |
| 141 } |
| 142 |
| 143 void set_matrix(const SkScalar matrix[20]) { |
| 144 DCHECK_EQ(type_, COLOR_MATRIX); |
| 145 for (unsigned i = 0; i < 20; ++i) |
| 146 matrix_[i] = matrix[i]; |
| 147 } |
| 148 |
| 149 void set_zoom_inset(int inset) { |
| 150 DCHECK_EQ(type_, ZOOM); |
| 151 zoom_inset_ = inset; |
| 152 } |
| 153 |
| 154 private: |
| 155 FilterOperation(FilterType type, float amount); |
| 156 |
| 157 FilterOperation(FilterType type, |
| 158 gfx::Point offset, |
| 159 float stdDeviation, |
| 160 SkColor color); |
| 161 |
| 162 FilterOperation(FilterType, SkScalar matrix[20]); |
| 163 |
| 164 FilterOperation(FilterType type, float amount, int inset); |
| 165 |
| 166 FilterType type_; |
| 167 float amount_; |
| 168 gfx::Point drop_shadow_offset_; |
| 169 SkColor drop_shadow_color_; |
| 170 SkScalar matrix_[20]; |
| 171 int zoom_inset_; |
| 172 }; |
| 173 |
| 174 } // namespace cc |
| 175 |
| 176 #endif // CC_OUTPUT_FILTER_OPERATION_H_ |
| OLD | NEW |