• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef RENDER_SERVICE_CLIENT_CORE_UI_RS_MASK_H
16 #define RENDER_SERVICE_CLIENT_CORE_UI_RS_MASK_H
17 
18 #include <memory>
19 #include "common/rs_macros.h"
20 #include "draw/pen.h"
21 #ifndef USE_ROSEN_DRAWING
22 #include "include/core/SkPaint.h"
23 #include "include/core/SkPath.h"
24 #include "include/core/SkPicture.h"
25 #else
26 #include "draw/brush.h"
27 #include "draw/path.h"
28 #include "image/picture.h"
29 #endif
30 #if defined(NEW_SKIA)
31 #include "modules/svg/include/SkSVGDOM.h"
32 #else
33 #include "experimental/svg/model/SkSVGDOM.h"
34 #endif
35 #include "transaction/rs_marshalling_helper.h"
36 
37 namespace OHOS {
38 namespace Rosen {
39 enum class MaskType {
40     NONE = 0,
41     SVG,
42     GRADIENT,
43     PATH,
44 };
45 
46 class RSB_EXPORT RSMask : public std::enable_shared_from_this<RSMask> {
47 public:
48     RSMask();
49     virtual ~RSMask();
50 #ifndef USE_ROSEN_DRAWING
51     static std::shared_ptr<RSMask> CreateGradientMask(const SkPaint& maskPaint);
52     static std::shared_ptr<RSMask> CreatePathMask(const SkPath& maskPath, const SkPaint& maskPaint);
53 #else
54     static std::shared_ptr<RSMask> CreateGradientMask(const Drawing::Brush& maskBrush);
55     static std::shared_ptr<RSMask> CreatePathMask(const Drawing::Path& maskPath, const Drawing::Brush& maskBrush);
56     static std::shared_ptr<RSMask> CreatePathMask(
57         const Drawing::Path& maskPath, const Drawing::Pen&  maskPen, const Drawing::Brush& maskBrush);
58 #endif
59     static std::shared_ptr<RSMask> CreateSVGMask(double x, double y, double scaleX, double scaleY,
60         const sk_sp<SkSVGDOM>& svgDom);
61 
62     void SetSvgX(double x);
63     double GetSvgX() const;
64     void SetSvgY(double y);
65     double GetSvgY() const;
66     void SetScaleX(double scaleX);
67     double GetScaleX() const;
68     void SetScaleY(double scaleY);
69     double GetScaleY() const;
70 #ifndef USE_ROSEN_DRAWING
71     void SetMaskPath(const SkPath& path);
72     SkPath GetMaskPath() const;
73     void SetMaskPaint(const SkPaint& paint);
74     SkPaint GetMaskPaint() const;
75 #else
76     void SetMaskPath(const Drawing::Path& path);
77     std::shared_ptr<Drawing::Path> GetMaskPath() const;
78     void SetMaskPen(const Drawing::Pen& pen);
79     Drawing::Pen GetMaskPen() const;
80     void SetMaskBrush(const Drawing::Brush& brush);
81     Drawing::Brush GetMaskBrush() const;
82     bool MarshallingPathAndBrush(Parcel& parcel) const;
83 #endif
84     void SetSvgDom(const sk_sp<SkSVGDOM>& svgDom);
85     sk_sp<SkSVGDOM> GetSvgDom() const;
86 #ifndef USE_ROSEN_DRAWING
87     sk_sp<SkPicture> GetSvgPicture() const;
88 #else
89     std::shared_ptr<Drawing::Picture> GetSvgPicture() const;
90 #endif
91     void SetMaskType(MaskType type);
92     bool IsSvgMask() const;
93     bool IsGradientMask() const;
94     bool IsPathMask() const;
95 
96 #ifdef ROSEN_OHOS
97     bool Marshalling(Parcel& parcel) const;
98     [[nodiscard]] static RSMask* Unmarshalling(Parcel& parcel);
99 #endif
100 
101 protected:
102     RSMask(const RSMask&) = delete;
103     RSMask(const RSMask&&) = delete;
104     RSMask& operator=(const RSMask&) = delete;
105     RSMask& operator=(const RSMask&&) = delete;
106 
107 private:
108     MaskType type_ = MaskType::NONE;
109     double svgX_ = 0.0f;
110     double svgY_ = 0.0f;
111     double scaleX_ = 1.0f;
112     double scaleY_ = 1.0f;
113     sk_sp<SkSVGDOM> svgDom_;
114 #ifndef USE_ROSEN_DRAWING
115     sk_sp<SkPicture> svgPicture_;
116     SkPaint maskPaint_;
117     SkPath maskPath_;
118 #else
119     std::shared_ptr<Drawing::Picture> svgPicture_;
120     Drawing::Pen maskPen_;
121     Drawing::Brush maskBrush_;
122     std::shared_ptr<Drawing::Path> maskPath_;
123 #endif
124 
125 };
126 } // namespace Rosen
127 } // namespace OHOS
128 
129 #endif // RENDER_SERVICE_CLIENT_CORE_UI_RS_MASK_H