• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_LAYERS_CLIP_LAYER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_LAYERS_CLIP_LAYER_H
18 
19 #include "base/geometry/rrect.h"
20 #include "core/pipeline/layers/layer.h"
21 #include "core/pipeline/layers/offset_layer.h"
22 #include "core/pipeline/layers/scene_builder.h"
23 #ifdef NEW_SKIA
24 #include "modules/svg/include/SkSVGDOM.h"
25 #else
26 #include "experimental/svg/model/SkSVGDOM.h"
27 #endif
28 #include "include/core/SkPaint.h"
29 #include "include/core/SkData.h"
30 
31 namespace OHOS::Ace::Flutter {
32 
33 enum class Clip {
34     NONE = 0,
35     HARD_EDGE,
36     ANTI_ALIAS,
37     ANTI_ALIAS_WITH_SAVE_LAYER,
38 };
39 
40 class ClipLayer : public OffsetLayer {
DECLARE_ACE_TYPE(ClipLayer,OffsetLayer)41     DECLARE_ACE_TYPE(ClipLayer, OffsetLayer)
42 public:
43     ClipLayer(double left, double right, double top, double bottom, Clip clipBehavior)
44         : OffsetLayer(0, 0), clipBehavior_(clipBehavior)
45     {
46         rrect_.sk_rrect = SkRRect::MakeRect(SkRect::MakeLTRB(static_cast<SkScalar>(left), static_cast<SkScalar>(top),
47             static_cast<SkScalar>(right), static_cast<SkScalar>(bottom)));
48         rrect_.is_null = false;
49     }
50     ~ClipLayer() override = default;
51 
52     void AddToScene(SceneBuilder& builder, double x, double y) override;
53 
54     void SetClip(double left, double right, double top, double bottom, Clip clipBehavior);
55     void SetClipRRect(const RRect& rrect, Clip clipBehavior);
56     void SetClipPath(const fml::RefPtr<flutter::CanvasPath>& canvasPath, Clip clipBehavior);
57     void SetClipPath(const fml::RefPtr<flutter::CanvasPath>& canvasPath);
58     void SetClipRRect(const Rect& rect, double x, double y, Clip clipBehavior);
59     void SetClipRRect(const flutter::RRect& rrect);
60     SkVector GetSkRadii(const Radius& radius);
61     void Dump() override;
62 
63     void CancelMask();
64     void SetSvgMask(const sk_sp<SkSVGDOM>& svgDom, double x, double y, double scaleX, double scaleY);
65     void SetColorMask(const SkPaint& maskPaint);
66     void SetPathMask(const SkPaint& maskPaint, const SkPath& path);
67 
68 private:
69     bool isPath_ = false;
70     fml::RefPtr<flutter::CanvasPath> canvasPath_;
71     flutter::RRect rrect_;
72     Clip clipBehavior_ { Clip::NONE };
73 
74     bool isMask_ = false;
75     bool isSvgMask_ = false;
76     bool isGradientMask_ = false;
77     bool isPathMask_ = false;
78     double svgX_ = 0.0f;
79     double svgY_ = 0.0f;
80     double scaleX_ = 1.0f;
81     double scaleY_ = 1.0f;
82     sk_sp<SkSVGDOM> svgDom_;
83     SkPaint maskPaint_;
84     SkPath maskPath_;
85 };
86 
87 } // namespace OHOS::Ace::Flutter
88 
89 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_LAYERS_CLIP_LAYER_H
90