Chromium Code Reviews| Index: cc/output/filter_operation.h |
| diff --git a/cc/output/filter_operation.h b/cc/output/filter_operation.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d9733345955897fdbd106aca80d013eb2f286d75 |
| --- /dev/null |
| +++ b/cc/output/filter_operation.h |
| @@ -0,0 +1,176 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CC_OUTPUT_FILTER_OPERATION_H_ |
| +#define CC_OUTPUT_FILTER_OPERATION_H_ |
| + |
| +#include "base/logging.h" |
| +#include "cc/base/cc_export.h" |
| +#include "third_party/skia/include/core/SkColor.h" |
| +#include "third_party/skia/include/core/SkScalar.h" |
| +#include "ui/gfx/point.h" |
| + |
| +namespace cc { |
| + |
| +class CC_EXPORT FilterOperation { |
| + public: |
| + enum FilterType { |
| + FilterTypeGrayscale, |
|
jamesr
2013/06/18 23:08:52
This isn't the correct enum style for Chromium (ht
ajuma
2013/06/19 17:08:30
Done.
|
| + FilterTypeSepia, |
| + FilterTypeSaturate, |
| + FilterTypeHueRotate, |
| + FilterTypeInvert, |
| + FilterTypeBrightness, |
| + FilterTypeContrast, |
| + FilterTypeOpacity, |
| + FilterTypeBlur, |
| + FilterTypeDropShadow, |
| + FilterTypeColorMatrix, |
| + FilterTypeZoom, |
| + FilterTypeSaturatingBrightness, // Not used in CSS/SVG. |
| + }; |
| + |
| + FilterType type() const { return type_; } |
| + |
| + float amount() const { |
| + DCHECK(type_ != FilterTypeColorMatrix); |
|
jamesr
2013/06/18 23:08:52
DCHECK_NE
ajuma
2013/06/19 17:08:30
Done.
|
| + return amount_; |
| + } |
| + |
| + gfx::Point drop_shadow_offset() const { |
| + DCHECK(type_ == FilterTypeDropShadow); |
|
jamesr
2013/06/18 23:08:52
DCHECK_EQ, etc
ajuma
2013/06/19 17:08:30
Done.
|
| + return drop_shadow_offset_; |
| + } |
| + |
| + SkColor drop_shadow_color() const { |
| + DCHECK(type_ == FilterTypeDropShadow); |
| + return drop_shadow_color_; |
| + } |
| + |
| + const SkScalar* matrix() const { |
| + DCHECK(type_ == FilterTypeColorMatrix); |
| + return matrix_; |
| + } |
| + |
| + int zoom_inset() const { |
| + DCHECK(type_ == FilterTypeZoom); |
| + return zoom_inset_; |
| + } |
| + |
| + static FilterOperation CreateGrayscaleFilter(float amount) { |
| + return FilterOperation(FilterTypeGrayscale, amount); |
| + } |
| + |
| + static FilterOperation CreateSepiaFilter(float amount) { |
| + return FilterOperation(FilterTypeSepia, amount); |
| + } |
| + |
| + static FilterOperation CreateSaturateFilter(float amount) { |
| + return FilterOperation(FilterTypeSaturate, amount); |
| + } |
| + |
| + static FilterOperation CreateHueRotateFilter(float amount) { |
| + return FilterOperation(FilterTypeHueRotate, amount); |
| + } |
| + |
| + static FilterOperation CreateInvertFilter(float amount) { |
| + return FilterOperation(FilterTypeInvert, amount); |
| + } |
| + |
| + static FilterOperation CreateBrightnessFilter(float amount) { |
| + return FilterOperation(FilterTypeBrightness, amount); |
| + } |
| + |
| + static FilterOperation CreateContrastFilter(float amount) { |
| + return FilterOperation(FilterTypeContrast, amount); |
| + } |
| + |
| + static FilterOperation CreateOpacityFilter(float amount) { |
| + return FilterOperation(FilterTypeOpacity, amount); |
| + } |
| + |
| + static FilterOperation CreateBlurFilter(float amount) { |
| + return FilterOperation(FilterTypeBlur, amount); |
| + } |
| + |
| + static FilterOperation CreateDropShadowFilter(gfx::Point offset, |
| + float std_deviation, |
| + SkColor color) { |
| + return FilterOperation(FilterTypeDropShadow, offset, std_deviation, color); |
| + } |
| + |
| + static FilterOperation CreateColorMatrixFilter(SkScalar matrix[20]) { |
| + return FilterOperation(FilterTypeColorMatrix, matrix); |
| + } |
| + |
| + static FilterOperation CreateZoomFilter(float amount, int inset) { |
| + return FilterOperation(FilterTypeZoom, amount, inset); |
| + } |
| + |
| + static FilterOperation CreateSaturatingBrightnessFilter(float amount) { |
| + return FilterOperation(FilterTypeSaturatingBrightness, amount); |
| + } |
| + |
| + bool operator==(const FilterOperation& other) const; |
| + |
| + bool operator!=(const FilterOperation& other) const { |
| + return !(*this == other); |
| + } |
| + |
| + // Methods for restoring a FilterOperation. |
| + static FilterOperation CreateEmptyFilter() { |
| + return FilterOperation(FilterTypeGrayscale, 0.0); |
| + } |
| + |
| + void set_type(FilterType type) { type_ = type; } |
| + |
| + void set_amount(float amount) { |
| + DCHECK(type_ != FilterTypeColorMatrix); |
| + amount_ = amount; |
| + } |
| + |
| + void set_drop_shadow_offset(gfx::Point offset) { |
| + DCHECK(type_ == FilterTypeDropShadow); |
| + drop_shadow_offset_ = offset; |
| + } |
| + |
| + void set_drop_shadow_color(SkColor color) { |
| + DCHECK(type_ == FilterTypeDropShadow); |
| + drop_shadow_color_ = color; |
| + } |
| + |
| + void set_matrix(const SkScalar matrix[20]) { |
| + DCHECK(type_ == FilterTypeColorMatrix); |
| + for (unsigned i = 0; i < 20; ++i) |
| + matrix_[i] = matrix[i]; |
| + } |
| + |
| + void set_zoom_inset(int inset) { |
| + DCHECK(type_ == FilterTypeZoom); |
| + zoom_inset_ = inset; |
| + } |
| + |
| + private: |
| + FilterOperation(FilterType type, float amount); |
| + |
| + FilterOperation(FilterType type, |
| + gfx::Point offset, |
| + float stdDeviation, |
| + SkColor color); |
| + |
| + FilterOperation(FilterType, SkScalar matrix[20]); |
| + |
| + FilterOperation(FilterType type, float amount, int inset); |
| + |
| + FilterType type_; |
| + float amount_; |
| + gfx::Point drop_shadow_offset_; |
| + SkColor drop_shadow_color_; |
| + SkScalar matrix_[20]; |
| + int zoom_inset_; |
| +}; |
| + |
| +} // namespace cc |
| + |
| +#endif // CC_OUTPUT_FILTER_OPERATION_H_ |