cc: Added inline to Tile::IsReadyToDraw
[chromium-blink-merge.git] / cc / output / filter_operation.h
blobf56176213b14081081361bfc546b544df885eb0d
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 "third_party/skia/include/core/SkColor.h"
12 #include "third_party/skia/include/core/SkScalar.h"
13 #include "ui/gfx/point.h"
15 namespace base {
16 class Value;
19 namespace cc {
21 class CC_EXPORT FilterOperation {
22 public:
23 enum FilterType {
24 GRAYSCALE,
25 SEPIA,
26 SATURATE,
27 HUE_ROTATE,
28 INVERT,
29 BRIGHTNESS,
30 CONTRAST,
31 OPACITY,
32 BLUR,
33 DROP_SHADOW,
34 COLOR_MATRIX,
35 ZOOM,
36 SATURATING_BRIGHTNESS, // Not used in CSS/SVG.
39 FilterType type() const { return type_; }
41 float amount() const {
42 DCHECK_NE(type_, COLOR_MATRIX);
43 return amount_;
46 gfx::Point drop_shadow_offset() const {
47 DCHECK_EQ(type_, DROP_SHADOW);
48 return drop_shadow_offset_;
51 SkColor drop_shadow_color() const {
52 DCHECK_EQ(type_, DROP_SHADOW);
53 return drop_shadow_color_;
56 const SkScalar* matrix() const {
57 DCHECK_EQ(type_, COLOR_MATRIX);
58 return matrix_;
61 int zoom_inset() const {
62 DCHECK_EQ(type_, ZOOM);
63 return zoom_inset_;
66 static FilterOperation CreateGrayscaleFilter(float amount) {
67 return FilterOperation(GRAYSCALE, amount);
70 static FilterOperation CreateSepiaFilter(float amount) {
71 return FilterOperation(SEPIA, amount);
74 static FilterOperation CreateSaturateFilter(float amount) {
75 return FilterOperation(SATURATE, amount);
78 static FilterOperation CreateHueRotateFilter(float amount) {
79 return FilterOperation(HUE_ROTATE, amount);
82 static FilterOperation CreateInvertFilter(float amount) {
83 return FilterOperation(INVERT, amount);
86 static FilterOperation CreateBrightnessFilter(float amount) {
87 return FilterOperation(BRIGHTNESS, amount);
90 static FilterOperation CreateContrastFilter(float amount) {
91 return FilterOperation(CONTRAST, amount);
94 static FilterOperation CreateOpacityFilter(float amount) {
95 return FilterOperation(OPACITY, amount);
98 static FilterOperation CreateBlurFilter(float amount) {
99 return FilterOperation(BLUR, amount);
102 static FilterOperation CreateDropShadowFilter(gfx::Point offset,
103 float std_deviation,
104 SkColor color) {
105 return FilterOperation(DROP_SHADOW, offset, std_deviation, color);
108 static FilterOperation CreateColorMatrixFilter(SkScalar matrix[20]) {
109 return FilterOperation(COLOR_MATRIX, matrix);
112 static FilterOperation CreateZoomFilter(float amount, int inset) {
113 return FilterOperation(ZOOM, amount, inset);
116 static FilterOperation CreateSaturatingBrightnessFilter(float amount) {
117 return FilterOperation(SATURATING_BRIGHTNESS, amount);
120 bool operator==(const FilterOperation& other) const;
122 bool operator!=(const FilterOperation& other) const {
123 return !(*this == other);
126 // Methods for restoring a FilterOperation.
127 static FilterOperation CreateEmptyFilter() {
128 return FilterOperation(GRAYSCALE, 0.f);
131 void set_type(FilterType type) { type_ = type; }
133 void set_amount(float amount) {
134 DCHECK_NE(type_, COLOR_MATRIX);
135 amount_ = amount;
138 void set_drop_shadow_offset(gfx::Point offset) {
139 DCHECK_EQ(type_, DROP_SHADOW);
140 drop_shadow_offset_ = offset;
143 void set_drop_shadow_color(SkColor color) {
144 DCHECK_EQ(type_, DROP_SHADOW);
145 drop_shadow_color_ = color;
148 void set_matrix(const SkScalar matrix[20]) {
149 DCHECK_EQ(type_, COLOR_MATRIX);
150 for (unsigned i = 0; i < 20; ++i)
151 matrix_[i] = matrix[i];
154 void set_zoom_inset(int inset) {
155 DCHECK_EQ(type_, ZOOM);
156 zoom_inset_ = inset;
159 // Given two filters of the same type, returns a filter operation created by
160 // linearly interpolating a |progress| fraction from |from| to |to|. If either
161 // |from| or |to| (but not both) is null, it is treated as a no-op filter of
162 // the same type as the other given filter. If both |from| and |to| are null,
163 // or if |from| and |to| are non-null but of different types, returns a
164 // no-op filter.
165 static FilterOperation Blend(const FilterOperation* from,
166 const FilterOperation* to,
167 double progress);
169 scoped_ptr<base::Value> AsValue() const;
171 private:
172 FilterOperation(FilterType type, float amount);
174 FilterOperation(FilterType type,
175 gfx::Point offset,
176 float stdDeviation,
177 SkColor color);
179 FilterOperation(FilterType, SkScalar matrix[20]);
181 FilterOperation(FilterType type, float amount, int inset);
183 FilterType type_;
184 float amount_;
185 gfx::Point drop_shadow_offset_;
186 SkColor drop_shadow_color_;
187 SkScalar matrix_[20];
188 int zoom_inset_;
191 } // namespace cc
193 #endif // CC_OUTPUT_FILTER_OPERATION_H_