1a3e0fd82Sopenharmony_ci/* 2a3e0fd82Sopenharmony_ci * Copyright (c) 2020-2021 Huawei Device Co., Ltd. 3a3e0fd82Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4a3e0fd82Sopenharmony_ci * you may not use this file except in compliance with the License. 5a3e0fd82Sopenharmony_ci * You may obtain a copy of the License at 6a3e0fd82Sopenharmony_ci * 7a3e0fd82Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8a3e0fd82Sopenharmony_ci * 9a3e0fd82Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10a3e0fd82Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11a3e0fd82Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12a3e0fd82Sopenharmony_ci * See the License for the specific language governing permissions and 13a3e0fd82Sopenharmony_ci * limitations under the License. 14a3e0fd82Sopenharmony_ci */ 15a3e0fd82Sopenharmony_ci 16a3e0fd82Sopenharmony_ci#ifndef GRAPHIC_LITE_DRAW_ARC_H 17a3e0fd82Sopenharmony_ci#define GRAPHIC_LITE_DRAW_ARC_H 18a3e0fd82Sopenharmony_ci#include "common/image.h" 19a3e0fd82Sopenharmony_ci#include "draw_image.h" 20a3e0fd82Sopenharmony_ci#include "draw_utils.h" 21a3e0fd82Sopenharmony_ci#include "gfx_utils/graphic_math.h" 22a3e0fd82Sopenharmony_ci#include "gfx_utils/heap_base.h" 23a3e0fd82Sopenharmony_ci#include "imgdecode/cache_manager.h" 24a3e0fd82Sopenharmony_ci#include "gfx_utils/style.h" 25a3e0fd82Sopenharmony_ci 26a3e0fd82Sopenharmony_cinamespace OHOS { 27a3e0fd82Sopenharmony_ciclass DrawArc : public HeapBase { 28a3e0fd82Sopenharmony_cipublic: 29a3e0fd82Sopenharmony_ci static DrawArc* GetInstance(); 30a3e0fd82Sopenharmony_ci 31a3e0fd82Sopenharmony_ci void GetDrawRange(int16_t& start, int16_t& end); 32a3e0fd82Sopenharmony_ci 33a3e0fd82Sopenharmony_ci void Draw(BufferInfo& gfxDstBuffer, ArcInfo& arcInfo, const Rect& mask, 34a3e0fd82Sopenharmony_ci const Style& style, uint8_t opaScale, uint8_t cap); 35a3e0fd82Sopenharmony_ci 36a3e0fd82Sopenharmony_ciprivate: 37a3e0fd82Sopenharmony_ci static constexpr uint8_t DRAW_ARC_QUADRANT_NUM = 4; 38a3e0fd82Sopenharmony_ci static constexpr uint8_t ARC_QUADRANT_ONE = 0; 39a3e0fd82Sopenharmony_ci static constexpr uint8_t ARC_QUADRANT_TWO = 1; 40a3e0fd82Sopenharmony_ci static constexpr uint8_t ARC_QUADRANT_THREE = 2; 41a3e0fd82Sopenharmony_ci static constexpr uint8_t ARC_QUADRANT_FOUR = 3; 42a3e0fd82Sopenharmony_ci static constexpr int16_t IN_DEGREE_RANG = 0; 43a3e0fd82Sopenharmony_ci static constexpr int16_t OUT_DEGREE_RANG = 1; 44a3e0fd82Sopenharmony_ci static constexpr int16_t INTERSECT = 2; 45a3e0fd82Sopenharmony_ci static constexpr int16_t DOUBLE_INTERSECT = 3; 46a3e0fd82Sopenharmony_ci 47a3e0fd82Sopenharmony_ci int16_t lineStart_; 48a3e0fd82Sopenharmony_ci int16_t lineEnd_; 49a3e0fd82Sopenharmony_ci int16_t outAntiStart_; 50a3e0fd82Sopenharmony_ci int16_t outAntiEnd_; 51a3e0fd82Sopenharmony_ci int16_t inAntiStart_; 52a3e0fd82Sopenharmony_ci int16_t inAntiEnd_; 53a3e0fd82Sopenharmony_ci int16_t y_; 54a3e0fd82Sopenharmony_ci int16_t outRadius_; 55a3e0fd82Sopenharmony_ci int16_t inRadius_; 56a3e0fd82Sopenharmony_ci uint32_t ySqr_; 57a3e0fd82Sopenharmony_ci uint32_t outRadiusSqr_; 58a3e0fd82Sopenharmony_ci uint32_t inRadiusSqr_; 59a3e0fd82Sopenharmony_ci bool isCircle_; 60a3e0fd82Sopenharmony_ci uint32_t antiOutRadiusSqr_; 61a3e0fd82Sopenharmony_ci uint32_t antiInRadiusSqr_; 62a3e0fd82Sopenharmony_ci 63a3e0fd82Sopenharmony_ci DrawArc() 64a3e0fd82Sopenharmony_ci : lineStart_(0), 65a3e0fd82Sopenharmony_ci lineEnd_(0), 66a3e0fd82Sopenharmony_ci outAntiStart_(0), 67a3e0fd82Sopenharmony_ci outAntiEnd_(0), 68a3e0fd82Sopenharmony_ci inAntiStart_(0), 69a3e0fd82Sopenharmony_ci inAntiEnd_(0), 70a3e0fd82Sopenharmony_ci y_(0), 71a3e0fd82Sopenharmony_ci outRadius_(0), 72a3e0fd82Sopenharmony_ci inRadius_(0), 73a3e0fd82Sopenharmony_ci ySqr_(0), 74a3e0fd82Sopenharmony_ci outRadiusSqr_(0), 75a3e0fd82Sopenharmony_ci inRadiusSqr_(0), 76a3e0fd82Sopenharmony_ci isCircle_(false), 77a3e0fd82Sopenharmony_ci antiOutRadiusSqr_(0), 78a3e0fd82Sopenharmony_ci antiInRadiusSqr_(0) 79a3e0fd82Sopenharmony_ci { 80a3e0fd82Sopenharmony_ci } 81a3e0fd82Sopenharmony_ci 82a3e0fd82Sopenharmony_ci ~DrawArc() {} 83a3e0fd82Sopenharmony_ci 84a3e0fd82Sopenharmony_ci void DrawVerLine(BufferInfo& gfxDstBuffer, 85a3e0fd82Sopenharmony_ci const Point& begin, 86a3e0fd82Sopenharmony_ci const Point& imgPos, 87a3e0fd82Sopenharmony_ci const Rect& mask, 88a3e0fd82Sopenharmony_ci int16_t len, 89a3e0fd82Sopenharmony_ci const Style& style, 90a3e0fd82Sopenharmony_ci uint8_t opaScale, 91a3e0fd82Sopenharmony_ci const Image* imgSrc); 92a3e0fd82Sopenharmony_ci 93a3e0fd82Sopenharmony_ci void DrawHorLine(BufferInfo& gfxDstBuffer, 94a3e0fd82Sopenharmony_ci const Point& begin, 95a3e0fd82Sopenharmony_ci const Point& imgPos, 96a3e0fd82Sopenharmony_ci const Rect& mask, 97a3e0fd82Sopenharmony_ci int16_t len, 98a3e0fd82Sopenharmony_ci const Style& style, 99a3e0fd82Sopenharmony_ci uint8_t opaScale, 100a3e0fd82Sopenharmony_ci const Image* imgSrc); 101a3e0fd82Sopenharmony_ci 102a3e0fd82Sopenharmony_ci void DrawImg(BufferInfo& gfxDstBuffer, 103a3e0fd82Sopenharmony_ci const Point& imgPos, 104a3e0fd82Sopenharmony_ci Rect& area, 105a3e0fd82Sopenharmony_ci const Rect& invalidatedArea, 106a3e0fd82Sopenharmony_ci const Style& style, 107a3e0fd82Sopenharmony_ci uint8_t opaScale, 108a3e0fd82Sopenharmony_ci const Image* imgSrc); 109a3e0fd82Sopenharmony_ci 110a3e0fd82Sopenharmony_ci int16_t GetDegreeRangeIntersectState(uint16_t degreeStart, uint16_t degreeEnd, uint16_t start, uint16_t end); 111a3e0fd82Sopenharmony_ci 112a3e0fd82Sopenharmony_ci uint16_t CalculateTanDegree(uint16_t x, uint16_t y); 113a3e0fd82Sopenharmony_ci 114a3e0fd82Sopenharmony_ci int16_t GetDrawAngle(int16_t angle); 115a3e0fd82Sopenharmony_ci 116a3e0fd82Sopenharmony_ci void DrawCircleNoEndpoint(BufferInfo& gfxDstBuffer, ArcInfo& arcInfo, const Rect& mask, const Style& style, 117a3e0fd82Sopenharmony_ci uint8_t opa, bool anti); 118a3e0fd82Sopenharmony_ci 119a3e0fd82Sopenharmony_ci void DrawAxisLine(BufferInfo& gfxDstBuffer, ArcInfo& arcInfo, const Rect& mask, const Style& style, uint8_t opa); 120a3e0fd82Sopenharmony_ci 121a3e0fd82Sopenharmony_ci void DrawLineWithDegree(BufferInfo& gfxDstBuffer, 122a3e0fd82Sopenharmony_ci ArcInfo& arcInfo, 123a3e0fd82Sopenharmony_ci int16_t start, 124a3e0fd82Sopenharmony_ci int16_t end, 125a3e0fd82Sopenharmony_ci int16_t y, 126a3e0fd82Sopenharmony_ci const Rect& mask, 127a3e0fd82Sopenharmony_ci const Style& style, 128a3e0fd82Sopenharmony_ci uint8_t opaScale, 129a3e0fd82Sopenharmony_ci uint8_t quadrant); 130a3e0fd82Sopenharmony_ci 131a3e0fd82Sopenharmony_ci int16_t DrawLineWithDegreeInner(BufferInfo& gfxDstBuffer, 132a3e0fd82Sopenharmony_ci ArcInfo& arcInfo, 133a3e0fd82Sopenharmony_ci int16_t start, 134a3e0fd82Sopenharmony_ci int16_t end, 135a3e0fd82Sopenharmony_ci int16_t y, 136a3e0fd82Sopenharmony_ci const Rect& mask, 137a3e0fd82Sopenharmony_ci const Style& style, 138a3e0fd82Sopenharmony_ci uint8_t opaScale, 139a3e0fd82Sopenharmony_ci uint8_t quadrant); 140a3e0fd82Sopenharmony_ci#if defined(ENABLE_ANTIALIAS) && ENABLE_ANTIALIAS 141a3e0fd82Sopenharmony_ci void DrawLineAnti(BufferInfo& gfxDstBuffer, ArcInfo& arcInfo, const Rect& mask, const Style& style, uint8_t opa); 142a3e0fd82Sopenharmony_ci void DrawPointAnti(BufferInfo& gfxDstBuffer, 143a3e0fd82Sopenharmony_ci ArcInfo& arcInfo, 144a3e0fd82Sopenharmony_ci int16_t x, 145a3e0fd82Sopenharmony_ci const Rect& mask, 146a3e0fd82Sopenharmony_ci const Style& style, 147a3e0fd82Sopenharmony_ci uint8_t antiOpa); 148a3e0fd82Sopenharmony_ci#endif 149a3e0fd82Sopenharmony_ci uint16_t GetDegreeInQuadrant(uint16_t degree, uint8_t quadrant); 150a3e0fd82Sopenharmony_ci void SetArcInfo(ArcInfo& arcInfo, const Style& style); 151a3e0fd82Sopenharmony_ci void CalculatedYStartAndYEnd(int16_t& yStart, int16_t& yEnd); 152a3e0fd82Sopenharmony_ci}; 153a3e0fd82Sopenharmony_ci} // namespace OHOS 154a3e0fd82Sopenharmony_ci#endif // GRAPHIC_LITE_DRAW_ARC_H 155