Making panels stacking order aware of launcher alignment
[chromium-blink-merge.git] / cc / output / filter_operation.h
blobad25cf48f6cb43438590b1aeb18e5782ddb2ac44
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 "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"
14 namespace cc {
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.
34 FilterType type() const { return type_; }
36 float amount() const {
37 DCHECK_NE(type_, COLOR_MATRIX);
38 return amount_;
41 gfx::Point drop_shadow_offset() const {
42 DCHECK_EQ(type_, DROP_SHADOW);
43 return drop_shadow_offset_;
46 SkColor drop_shadow_color() const {
47 DCHECK_EQ(type_, DROP_SHADOW);
48 return drop_shadow_color_;
51 const SkScalar* matrix() const {
52 DCHECK_EQ(type_, COLOR_MATRIX);
53 return matrix_;
56 int zoom_inset() const {
57 DCHECK_EQ(type_, ZOOM);
58 return zoom_inset_;
61 static FilterOperation CreateGrayscaleFilter(float amount) {
62 return FilterOperation(GRAYSCALE, amount);
65 static FilterOperation CreateSepiaFilter(float amount) {
66 return FilterOperation(SEPIA, amount);
69 static FilterOperation CreateSaturateFilter(float amount) {
70 return FilterOperation(SATURATE, amount);
73 static FilterOperation CreateHueRotateFilter(float amount) {
74 return FilterOperation(HUE_ROTATE, amount);
77 static FilterOperation CreateInvertFilter(float amount) {
78 return FilterOperation(INVERT, amount);
81 static FilterOperation CreateBrightnessFilter(float amount) {
82 return FilterOperation(BRIGHTNESS, amount);
85 static FilterOperation CreateContrastFilter(float amount) {
86 return FilterOperation(CONTRAST, amount);
89 static FilterOperation CreateOpacityFilter(float amount) {
90 return FilterOperation(OPACITY, amount);
93 static FilterOperation CreateBlurFilter(float amount) {
94 return FilterOperation(BLUR, amount);
97 static FilterOperation CreateDropShadowFilter(gfx::Point offset,
98 float std_deviation,
99 SkColor color) {
100 return FilterOperation(DROP_SHADOW, offset, std_deviation, color);
103 static FilterOperation CreateColorMatrixFilter(SkScalar matrix[20]) {
104 return FilterOperation(COLOR_MATRIX, matrix);
107 static FilterOperation CreateZoomFilter(float amount, int inset) {
108 return FilterOperation(ZOOM, amount, inset);
111 static FilterOperation CreateSaturatingBrightnessFilter(float amount) {
112 return FilterOperation(SATURATING_BRIGHTNESS, amount);
115 bool operator==(const FilterOperation& other) const;
117 bool operator!=(const FilterOperation& other) const {
118 return !(*this == other);
121 // Methods for restoring a FilterOperation.
122 static FilterOperation CreateEmptyFilter() {
123 return FilterOperation(GRAYSCALE, 0.f);
126 void set_type(FilterType type) { type_ = type; }
128 void set_amount(float amount) {
129 DCHECK_NE(type_, COLOR_MATRIX);
130 amount_ = amount;
133 void set_drop_shadow_offset(gfx::Point offset) {
134 DCHECK_EQ(type_, DROP_SHADOW);
135 drop_shadow_offset_ = offset;
138 void set_drop_shadow_color(SkColor color) {
139 DCHECK_EQ(type_, DROP_SHADOW);
140 drop_shadow_color_ = color;
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];
149 void set_zoom_inset(int inset) {
150 DCHECK_EQ(type_, ZOOM);
151 zoom_inset_ = inset;
154 // Given two filters of the same type, returns a filter operation created by
155 // linearly interpolating a |progress| fraction from |from| to |to|. If either
156 // |from| or |to| (but not both) is null, it is treated as a no-op filter of
157 // the same type as the other given filter. If both |from| and |to| are null,
158 // or if |from| and |to| are non-null but of different types, returns a
159 // no-op filter.
160 static FilterOperation Blend(const FilterOperation* from,
161 const FilterOperation* to,
162 double progress);
164 private:
165 FilterOperation(FilterType type, float amount);
167 FilterOperation(FilterType type,
168 gfx::Point offset,
169 float stdDeviation,
170 SkColor color);
172 FilterOperation(FilterType, SkScalar matrix[20]);
174 FilterOperation(FilterType type, float amount, int inset);
176 FilterType type_;
177 float amount_;
178 gfx::Point drop_shadow_offset_;
179 SkColor drop_shadow_color_;
180 SkScalar matrix_[20];
181 int zoom_inset_;
184 } // namespace cc
186 #endif // CC_OUTPUT_FILTER_OPERATION_H_