1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- // Copyright 2020 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 UI_GFX_GEOMETRY_MASK_FILTER_INFO_H_
- #define UI_GFX_GEOMETRY_MASK_FILTER_INFO_H_
- #include "third_party/abseil-cpp/absl/types/optional.h"
- #include "ui/gfx/geometry/geometry_skia_export.h"
- #include "ui/gfx/geometry/linear_gradient.h"
- #include "ui/gfx/geometry/rect_f.h"
- #include "ui/gfx/geometry/rrect_f.h"
- namespace gfx {
- class Transform;
- // This class defines a mask filter to be applied to the given rect.
- class GEOMETRY_SKIA_EXPORT MaskFilterInfo {
- public:
- MaskFilterInfo() = default;
- explicit MaskFilterInfo(const RRectF& rrect)
- : rounded_corner_bounds_(rrect) {}
- MaskFilterInfo(const RRectF& rrect, const gfx::LinearGradient& gradient_mask)
- : rounded_corner_bounds_(rrect), gradient_mask_(gradient_mask) {}
- MaskFilterInfo(const RectF& bounds,
- const RoundedCornersF& radii,
- const gfx::LinearGradient& gradient_mask)
- : rounded_corner_bounds_(bounds, radii), gradient_mask_(gradient_mask) {}
- MaskFilterInfo(const MaskFilterInfo& copy) = default;
- ~MaskFilterInfo() = default;
- // The bounds the filter will be applied to.
- RectF bounds() const { return rounded_corner_bounds_.rect(); }
- // Defines the rounded corner bounds to clip.
- const RRectF& rounded_corner_bounds() const { return rounded_corner_bounds_; }
- // True if this contains a rounded corner mask.
- bool HasRoundedCorners() const {
- return rounded_corner_bounds_.GetType() != RRectF::Type::kEmpty &&
- rounded_corner_bounds_.GetType() != RRectF::Type::kRect;
- }
- const absl::optional<gfx::LinearGradient>& gradient_mask() const {
- return gradient_mask_;
- }
- // True if this contains an effective gradient mask (requires filter bounds).
- bool HasGradientMask() const {
- if (rounded_corner_bounds_.IsEmpty())
- return false;
- return gradient_mask_ && !gradient_mask_->IsEmpty();
- }
- // True if this contains no effective mask information.
- bool IsEmpty() const { return rounded_corner_bounds_.IsEmpty(); }
- // Transform the mask information. Returns false if the transform
- // cannot be applied.
- bool Transform(const gfx::Transform& transform);
- std::string ToString() const;
- private:
- // The rounded corner bounds. This also defines the bounds that the mask
- // filter will be applied to.
- RRectF rounded_corner_bounds_;
- // Shader based linear gradient mask to be applied to a layer.
- absl::optional<gfx::LinearGradient> gradient_mask_;
- };
- inline bool operator==(const MaskFilterInfo& lhs, const MaskFilterInfo& rhs) {
- return (lhs.rounded_corner_bounds() == rhs.rounded_corner_bounds()) &&
- (lhs.gradient_mask() == rhs.gradient_mask());
- }
- inline bool operator!=(const MaskFilterInfo& lhs, const MaskFilterInfo& rhs) {
- return !(lhs == rhs);
- }
- } // namespace gfx
- #endif // UI_GFX_GEOMETRY_MASK_FILTER_INFO_H_
|