1/*
2 * Copyright (c) 2020-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 GRAPHIC_LITE_DRAW_ARC_H
17#define GRAPHIC_LITE_DRAW_ARC_H
18#include "common/image.h"
19#include "draw_image.h"
20#include "draw_utils.h"
21#include "gfx_utils/graphic_math.h"
22#include "gfx_utils/heap_base.h"
23#include "imgdecode/cache_manager.h"
24#include "gfx_utils/style.h"
25
26namespace OHOS {
27class DrawArc : public HeapBase {
28public:
29    static DrawArc* GetInstance();
30
31    void GetDrawRange(int16_t& start, int16_t& end);
32
33    void Draw(BufferInfo& gfxDstBuffer, ArcInfo& arcInfo, const Rect& mask,
34              const Style& style, uint8_t opaScale, uint8_t cap);
35
36private:
37    static constexpr uint8_t DRAW_ARC_QUADRANT_NUM = 4;
38    static constexpr uint8_t ARC_QUADRANT_ONE = 0;
39    static constexpr uint8_t ARC_QUADRANT_TWO = 1;
40    static constexpr uint8_t ARC_QUADRANT_THREE = 2;
41    static constexpr uint8_t ARC_QUADRANT_FOUR = 3;
42    static constexpr int16_t IN_DEGREE_RANG = 0;
43    static constexpr int16_t OUT_DEGREE_RANG = 1;
44    static constexpr int16_t INTERSECT = 2;
45    static constexpr int16_t DOUBLE_INTERSECT = 3;
46
47    int16_t lineStart_;
48    int16_t lineEnd_;
49    int16_t outAntiStart_;
50    int16_t outAntiEnd_;
51    int16_t inAntiStart_;
52    int16_t inAntiEnd_;
53    int16_t y_;
54    int16_t outRadius_;
55    int16_t inRadius_;
56    uint32_t ySqr_;
57    uint32_t outRadiusSqr_;
58    uint32_t inRadiusSqr_;
59    bool isCircle_;
60    uint32_t antiOutRadiusSqr_;
61    uint32_t antiInRadiusSqr_;
62
63    DrawArc()
64        : lineStart_(0),
65          lineEnd_(0),
66          outAntiStart_(0),
67          outAntiEnd_(0),
68          inAntiStart_(0),
69          inAntiEnd_(0),
70          y_(0),
71          outRadius_(0),
72          inRadius_(0),
73          ySqr_(0),
74          outRadiusSqr_(0),
75          inRadiusSqr_(0),
76          isCircle_(false),
77          antiOutRadiusSqr_(0),
78          antiInRadiusSqr_(0)
79    {
80    }
81
82    ~DrawArc() {}
83
84    void DrawVerLine(BufferInfo& gfxDstBuffer,
85                     const Point& begin,
86                     const Point& imgPos,
87                     const Rect& mask,
88                     int16_t len,
89                     const Style& style,
90                     uint8_t opaScale,
91                     const Image* imgSrc);
92
93    void DrawHorLine(BufferInfo& gfxDstBuffer,
94                     const Point& begin,
95                     const Point& imgPos,
96                     const Rect& mask,
97                     int16_t len,
98                     const Style& style,
99                     uint8_t opaScale,
100                     const Image* imgSrc);
101
102    void DrawImg(BufferInfo& gfxDstBuffer,
103                 const Point& imgPos,
104                 Rect& area,
105                 const Rect& invalidatedArea,
106                 const Style& style,
107                 uint8_t opaScale,
108                 const Image* imgSrc);
109
110    int16_t GetDegreeRangeIntersectState(uint16_t degreeStart, uint16_t degreeEnd, uint16_t start, uint16_t end);
111
112    uint16_t CalculateTanDegree(uint16_t x, uint16_t y);
113
114    int16_t GetDrawAngle(int16_t angle);
115
116    void DrawCircleNoEndpoint(BufferInfo& gfxDstBuffer, ArcInfo& arcInfo, const Rect& mask, const Style& style,
117                              uint8_t opa, bool anti);
118
119    void DrawAxisLine(BufferInfo& gfxDstBuffer, ArcInfo& arcInfo, const Rect& mask, const Style& style, uint8_t opa);
120
121    void DrawLineWithDegree(BufferInfo& gfxDstBuffer,
122                            ArcInfo& arcInfo,
123                            int16_t start,
124                            int16_t end,
125                            int16_t y,
126                            const Rect& mask,
127                            const Style& style,
128                            uint8_t opaScale,
129                            uint8_t quadrant);
130
131    int16_t DrawLineWithDegreeInner(BufferInfo& gfxDstBuffer,
132                                    ArcInfo& arcInfo,
133                                    int16_t start,
134                                    int16_t end,
135                                    int16_t y,
136                                    const Rect& mask,
137                                    const Style& style,
138                                    uint8_t opaScale,
139                                    uint8_t quadrant);
140#if defined(ENABLE_ANTIALIAS) && ENABLE_ANTIALIAS
141    void DrawLineAnti(BufferInfo& gfxDstBuffer, ArcInfo& arcInfo, const Rect& mask, const Style& style, uint8_t opa);
142    void DrawPointAnti(BufferInfo& gfxDstBuffer,
143                       ArcInfo& arcInfo,
144                       int16_t x,
145                       const Rect& mask,
146                       const Style& style,
147                       uint8_t antiOpa);
148#endif
149    uint16_t GetDegreeInQuadrant(uint16_t degree, uint8_t quadrant);
150    void SetArcInfo(ArcInfo& arcInfo, const Style& style);
151    void CalculatedYStartAndYEnd(int16_t& yStart, int16_t& yEnd);
152};
153} // namespace OHOS
154#endif // GRAPHIC_LITE_DRAW_ARC_H
155