• 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 
20 #include "experimental/svg/model/SkSVGDOM.h"
21 #include "third_party/skia/include/core/SkPaint.h"
22 #include "third_party/skia/include/core/SkPath.h"
23 #include "third_party/skia/include/core/SkPicture.h"
24 
25 #include "common/rs_macros.h"
26 #include "transaction/rs_marshalling_helper.h"
27 
28 namespace OHOS {
29 namespace Rosen {
30 enum class MaskType {
31     NONE = 0,
32     SVG,
33     GRADIENT,
34     PATH,
35 };
36 
37 class RSB_EXPORT RSMask : public std::enable_shared_from_this<RSMask> {
38 public:
39     RSMask();
40     virtual ~RSMask();
41     static std::shared_ptr<RSMask> CreateGradientMask(const SkPaint& maskPaint);
42     static std::shared_ptr<RSMask> CreatePathMask(const SkPath& maskPath, const SkPaint& maskPaint);
43     static std::shared_ptr<RSMask> CreateSVGMask(double x, double y, double scaleX, double scaleY,
44         const sk_sp<SkSVGDOM>& svgDom);
45 
46     void SetSvgX(double x);
47     double GetSvgX() const;
48     void SetSvgY(double y);
49     double GetSvgY() const;
50     void SetScaleX(double scaleX);
51     double GetScaleX() const;
52     void SetScaleY(double scaleY);
53     double GetScaleY() const;
54     void SetMaskPath(const SkPath& path);
55     SkPath GetMaskPath() const;
56     void SetMaskPaint(const SkPaint& paint);
57     SkPaint GetMaskPaint() const;
58     void SetSvgDom(const sk_sp<SkSVGDOM>& svgDom);
59     sk_sp<SkSVGDOM> GetSvgDom() const;
60     sk_sp<SkPicture> GetSvgPicture() const;
61     void SetMaskType(MaskType type);
62     bool IsSvgMask() const;
63     bool IsGradientMask() const;
64     bool IsPathMask() const;
65 
66 #ifdef ROSEN_OHOS
67     bool Marshalling(Parcel& parcel) const;
68     static RSMask* Unmarshalling(Parcel& parcel);
69 #endif
70 
71 protected:
72     RSMask(const RSMask&) = delete;
73     RSMask(const RSMask&&) = delete;
74     RSMask& operator=(const RSMask&) = delete;
75     RSMask& operator=(const RSMask&&) = delete;
76 
77 private:
78     MaskType type_ = MaskType::NONE;
79     double svgX_ = 0.0f;
80     double svgY_ = 0.0f;
81     double scaleX_ = 1.0f;
82     double scaleY_ = 1.0f;
83     sk_sp<SkSVGDOM> svgDom_;
84     sk_sp<SkPicture> svgPicture_;
85     SkPaint maskPaint_;
86     SkPath maskPath_;
87 
88 };
89 } // namespace Rosen
90 } // namespace OHOS
91 
92 #endif // RENDER_SERVICE_CLIENT_CORE_UI_RS_MASK_H