1 /* 2 * Copyright (c) 2021-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 GRAPHIC_LITE_CLIP_UTILS_H 17 #define GRAPHIC_LITE_CLIP_UTILS_H 18 19 #include "gfx_utils/diagram/vertexprimitive/geometry_path_storage.h" 20 #include "gfx_utils/geometry2d.h" 21 #include "gfx_utils/image_info.h" 22 #include "gfx_utils/list.h" 23 #include "gfx_utils/vector.h" 24 #include "render/render_buffer.h" 25 #include "render/render_scanline.h" 26 27 namespace OHOS { 28 /* 29 * Indicates a path to be cliped. 30 * Note: The path will be automatically closed. Only non-self-intersecting path are supported. 31 */ 32 class ClipPath : public HeapBase { 33 public: ClipPath()34 ClipPath() 35 { 36 vertices_ = new UICanvasVertices(); 37 } ~ClipPath()38 ~ClipPath() 39 { 40 if (vertices_ != nullptr) { 41 vertices_->FreeAll(); 42 delete vertices_; 43 vertices_ = nullptr; 44 } 45 } 46 47 ClipPath& MoveTo(const PointF& point); 48 ClipPath& LineTo(const PointF& point); 49 ClipPath& CurveTo(const PointF& control1, const PointF& control2, const PointF& end); 50 ClipPath& Arc(const PointF& center, float radius, int16_t startAngle, int16_t endAngle); 51 ClipPath& Circle(const PointF& center, float radius); 52 GetVertices()53 UICanvasVertices& GetVertices() const 54 { 55 return *vertices_; 56 } 57 private: 58 UICanvasVertices* vertices_; 59 }; 60 61 class ClipUtils : public HeapBase { 62 public: ClipUtils()63 ClipUtils() {} ~ClipUtils()64 ~ClipUtils() {} 65 66 void PerformScan(const ClipPath& path, const ImageInfo* imageInfo); 67 private: 68 UICanvasVertices& CloseVertices(const ClipPath& path); 69 void DrawPixel(int16_t x, int16_t y, uint8_t opa, const ImageInfo* imageInfo); 70 void DrawHorLine(int16_t x, int16_t y, int16_t width, uint8_t opa, const ImageInfo* imageInfo); 71 }; 72 }; 73 #endif 74