• 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 #ifndef RENDER_SERVICE_CLIENT_CORE_RENDER_RS_BORDER_H
17 #define RENDER_SERVICE_CLIENT_CORE_RENDER_RS_BORDER_H
18 
19 #include <iostream>
20 #include <sstream>
21 #include <vector>
22 #include <cinttypes>
23 
24 #include "common/rs_color_palette.h"
25 #include "common/rs_vector4.h"
26 #include "property/rs_properties_def.h"
27 
28 #ifndef USE_ROSEN_DRAWING
29 class SkCanvas;
30 class SkPaint;
31 class SkRRect;
32 #else
33 #include "draw/canvas.h"
34 #include "draw/brush.h"
35 #include "draw/pen.h"
36 #include "utils/rect.h"
37 #include "utils/round_rect.h"
38 #endif
39 
40 namespace OHOS {
41 namespace Rosen {
42 enum class BorderStyle : uint32_t {
43     SOLID = 0,
44     DASHED,
45     DOTTED,
46     NONE
47 };
48 
49 // also used for Outline
50 class RSBorder final {
51 public:
52     RSBorder() = default;
53     RSBorder(const bool& isOutline);
~RSBorder()54     ~RSBorder() {}
55 
56     enum BorderType : int {
57         LEFT = 0,
58         TOP,
59         RIGHT,
60         BOTTOM,
61     };
62 
63     void SetColor(Color color);
64     void SetWidth(float width);
65     void SetStyle(BorderStyle style);
66     Color GetColor(int idx = RSBorder::LEFT) const;
67     float GetWidth(int idx = RSBorder::LEFT) const;
68     BorderStyle GetStyle(int idx = RSBorder::LEFT) const;
69 
70     void SetColorFour(const Vector4<Color>& color);
71     void SetWidthFour(const Vector4f& width);
72     void SetStyleFour(const Vector4<uint32_t>& style);
73     void SetRadiusFour(const Vector4f& radius);
74     Vector4<Color> GetColorFour() const;
75     Vector4f GetWidthFour() const;
76     Vector4<uint32_t> GetStyleFour() const;
77     Vector4f GetRadiusFour() const;
78 
79     bool HasBorder() const;
80 
81     std::string ToString() const;
82 
83 #ifndef USE_ROSEN_DRAWING
84     bool ApplyFillStyle(SkPaint& paint) const;
85     bool ApplyPathStyle(SkPaint& paint) const;
86     bool ApplyFourLine(SkPaint& paint) const;
87     bool ApplyLineStyle(SkPaint& paint, int borderIdx, float length) const;
88     void PaintFourLine(SkCanvas& canvas, SkPaint& paint, RectF rect) const;
89     void PaintTopPath(SkCanvas& canvas, SkPaint& paint, const SkRRect& rrect, const SkPoint& innerRectCenter) const;
90     void PaintRightPath(SkCanvas& canvas, SkPaint& paint, const SkRRect& rrect, const SkPoint& innerRectCenter) const;
91     void PaintBottomPath(SkCanvas& canvas, SkPaint& paint, const SkRRect& rrect, const SkPoint& innerRectCenter) const;
92     void PaintLeftPath(SkCanvas& canvas, SkPaint& paint, const SkRRect& rrect, const SkPoint& innerRectCenter) const;
93 #else
94     bool ApplyFillStyle(Drawing::Brush& brush) const;
95     bool ApplyPathStyle(Drawing::Pen& pen) const;
96     bool ApplyFourLine(Drawing::Pen& pen) const;
97     bool ApplyLineStyle(Drawing::Pen& pen, int borderIdx, float length) const;
98 
99     void PaintFourLine(Drawing::Canvas& canvas, Drawing::Pen& pen, RectF rect) const;
100     void PaintTopPath(Drawing::Canvas& canvas, Drawing::Pen& pen, const Drawing::RoundRect& rrect,
101         const Drawing::Point& innerRectCenter) const;
102     void PaintRightPath(Drawing::Canvas& canvas, Drawing::Pen& pen, const Drawing::RoundRect& rrect,
103         const Drawing::Point& innerRectCenter) const;
104     void PaintBottomPath(Drawing::Canvas& canvas, Drawing::Pen& pen, const Drawing::RoundRect& rrect,
105         const Drawing::Point& innerRectCenter) const;
106     void PaintLeftPath(Drawing::Canvas& canvas, Drawing::Pen& pen, const Drawing::RoundRect& rrect,
107         const Drawing::Point& innerRectCenter) const;
108 #endif
109 
110 private:
111     // Vectors containing uniform or four-sided border attributes.
112     // If four-sided, the order of contents is left, top, right, bottom.
113     std::vector<Color> colors_;
114     std::vector<float> widths_;
115     std::vector<BorderStyle> styles_;
116 
117     // only be used by outline, innerBorder(border_) uses corner radius.
118     Vector4f radius_;
119 };
120 } // namespace Rosen
121 } // namespace OHOS
122 
123 #endif // RENDER_SERVICE_CLIENT_CORE_RENDER_RS_BORDER_H
124