• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 
16 #include "render/rs_mask.h"
17 
18 #include "platform/common/rs_log.h"
19 
20 namespace OHOS {
21 namespace Rosen {
CreateGradientMask(const SkPaint & maskPaint)22 std::shared_ptr<RSMask> RSMask::CreateGradientMask(const SkPaint& maskPaint)
23 {
24     auto mask = std::make_shared<RSMask>();
25     if (mask) {
26         mask->SetMaskPaint(maskPaint);
27         mask->SetMaskType(MaskType::GRADIENT);
28     }
29     return mask;
30 }
31 
CreatePathMask(const SkPath & maskPath,const SkPaint & maskPaint)32 std::shared_ptr<RSMask> RSMask::CreatePathMask(const SkPath& maskPath, const SkPaint& maskPaint)
33 {
34     auto mask = std::make_shared<RSMask>();
35     if (mask) {
36         mask->SetMaskPath(maskPath);
37         mask->SetMaskPaint(maskPaint);
38         mask->SetMaskType(MaskType::PATH);
39     }
40     return mask;
41 }
42 
CreateSVGMask(double x,double y,double scaleX,double scaleY,const sk_sp<SkSVGDOM> & svgDom)43 std::shared_ptr<RSMask> RSMask::CreateSVGMask(double x, double y, double scaleX, double scaleY,
44     const sk_sp<SkSVGDOM>& svgDom)
45 {
46     auto mask = std::make_shared<RSMask>();
47     if (mask) {
48         mask->SetSvgX(x);
49         mask->SetSvgY(y);
50         mask->SetScaleX(scaleX);
51         mask->SetScaleY(scaleY);
52         mask->SetSvgDom(svgDom);
53         mask->SetMaskType(MaskType::SVG);
54     }
55     return mask;
56 }
57 
RSMask()58 RSMask::RSMask()
59 {
60 }
61 
~RSMask()62 RSMask::~RSMask()
63 {
64 }
65 
SetSvgX(double x)66 void RSMask::SetSvgX(double x)
67 {
68     svgX_ = x;
69 }
70 
GetSvgX() const71 double RSMask::GetSvgX() const
72 {
73     return svgX_;
74 }
75 
SetSvgY(double y)76 void RSMask::SetSvgY(double y)
77 {
78     svgY_ = y;
79 }
80 
GetSvgY() const81 double RSMask::GetSvgY() const
82 {
83     return svgY_;
84 }
85 
SetScaleX(double scaleX)86 void RSMask::SetScaleX(double scaleX)
87 {
88     scaleX_ = scaleX;
89 }
90 
GetScaleX() const91 double RSMask::GetScaleX() const
92 {
93     return scaleX_;
94 }
95 
SetScaleY(double scaleY)96 void RSMask::SetScaleY(double scaleY)
97 {
98     scaleY_ = scaleY;
99 }
100 
GetScaleY() const101 double RSMask::GetScaleY() const
102 {
103     return scaleY_;
104 }
105 
SetMaskPath(const SkPath & path)106 void RSMask::SetMaskPath(const SkPath& path)
107 {
108     maskPath_ = path;
109 }
110 
GetMaskPath() const111 SkPath RSMask::GetMaskPath() const
112 {
113     return maskPath_;
114 }
115 
SetMaskPaint(const SkPaint & paint)116 void RSMask::SetMaskPaint(const SkPaint& paint)
117 {
118     maskPaint_ = paint;
119 }
120 
GetMaskPaint() const121 SkPaint RSMask::GetMaskPaint() const
122 {
123     return maskPaint_;
124 }
125 
SetSvgDom(const sk_sp<SkSVGDOM> & svgDom)126 void RSMask::SetSvgDom(const sk_sp<SkSVGDOM>& svgDom)
127 {
128     svgDom_ = svgDom;
129 }
130 
GetSvgDom() const131 sk_sp<SkSVGDOM> RSMask::GetSvgDom() const
132 {
133     return svgDom_;
134 }
135 
SetMaskType(MaskType type)136 void RSMask::SetMaskType(MaskType type)
137 {
138     type_ = type;
139 }
140 
IsSvgMask() const141 bool RSMask::IsSvgMask() const
142 {
143     return (type_ == MaskType::SVG);
144 }
145 
IsGradientMask() const146 bool RSMask::IsGradientMask() const
147 {
148     return (type_ == MaskType::GRADIENT);
149 }
150 
IsPathMask() const151 bool RSMask::IsPathMask() const
152 {
153     return (type_ == MaskType::PATH);
154 }
155 } // namespace Rosen
156 } // namespace OHOS