1 /* 2 * Copyright (c) 2023 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 REGION_H 17 #define REGION_H 18 19 #include "impl_interface/region_impl.h" 20 #include "utils/drawing_macros.h" 21 22 namespace OHOS { 23 namespace Rosen { 24 namespace Drawing { 25 enum class RegionOp { 26 DIFFERENCE, 27 INTERSECT, 28 UNION, 29 XOR, 30 REVERSE_DIFFERENCE, 31 REPLACE, 32 }; 33 class DRAWING_API Region { 34 public: 35 Region(); 36 Region(const Region& other); 37 Region& operator=(const Region& other); 38 virtual ~Region() = default; 39 Clone(const Region & other)40 void Clone(const Region& other) 41 { 42 impl_->Clone(other); 43 } 44 GetDrawingType()45 virtual DrawingType GetDrawingType() const 46 { 47 return DrawingType::COMMON; 48 } 49 50 virtual bool Contains(int32_t x, int32_t y) const; 51 52 /** 53 * @brief Constructs a rectangular Region matching the bounds of rect. 54 * @param rectI Bounds of constructed Region. 55 * @return If rectI is empty, constructs empty and returns false. 56 */ 57 virtual bool SetRect(const RectI& rectI); 58 59 /** 60 * @brief Constructs Region to match outline of path within clip. 61 * @param path Providing outline. 62 * @param clip Containing path. 63 * @return Return true if constructed Region is not empty. 64 */ 65 virtual bool SetPath(const Path& path, const Region& clip); 66 67 /** 68 * @brief Appends outline of Region to path. 69 * @param path Path to append to. 70 * @return Return true if path changed. 71 */ 72 bool GetBoundaryPath(Path* path) const; 73 74 /** 75 * @brief Determines whether it intersects other. 76 * @param other Other Region object. 77 * @return If true indicates that other and Region have area in common. 78 */ 79 bool IsIntersects(const Region& other) const; 80 81 /** 82 * @brief Determines whether Region is empty. 83 * @return If true indicates that bounds has no width or height. 84 */ 85 bool IsEmpty() const; 86 87 /** 88 * @brief Determines whether Region is one Rect with positive dimensions. 89 * @return If true indicates that Region contains one Rect. 90 */ 91 bool IsRect() const; 92 93 /** 94 * @brief Determines whether other region is in the region. 95 * @param other Other region object. 96 * @return If true indicates that other and region have area in common. 97 */ 98 virtual bool IsRegionContained(const Region& other) const; 99 100 /** 101 * @brief Replaces Region with the result of Region op region. 102 * @param region Operand. 103 * @param op Operation type. 104 * @return Returns true if replaced Region is not empty. 105 */ 106 virtual bool Op(const Region& region, RegionOp op); 107 108 /** 109 * @brief Determines whether rect and region does not intersect. 110 * @param rectI RectI to intersect. 111 * @return Returns true if rect and region is not intersect. 112 */ 113 virtual bool QuickReject(const RectI& rectI) const; 114 115 std::shared_ptr<Data> Serialize() const; 116 bool Deserialize(std::shared_ptr<Data> data); 117 118 /** 119 * @brief Get the adaptation layer instance, called in the adaptation layer. 120 * @return Adaptation Layer instance. 121 */ 122 template<typename T> GetImpl()123 T* GetImpl() const 124 { 125 return impl_->DowncastingTo<T>(); 126 } 127 128 private: 129 std::shared_ptr<RegionImpl> impl_; 130 }; 131 } // namespace Drawing 132 } // namespace Rosen 133 } // namespace OHOS 134 #endif 135