blob: 22cc295cd242d64b0ced65504dccf00a049f2911 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
// 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_
|