1 /* 2 * Copyright (c) 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 MASK_FILTER_H 17 #define MASK_FILTER_H 18 19 #include <memory> 20 21 #include "common/rs_macros.h" 22 #include "drawing/engine_adapter/impl_interface/mask_filter_impl.h" 23 #include "utils/drawing_macros.h" 24 #include "utils/scalar.h" 25 26 namespace OHOS { 27 namespace Rosen { 28 namespace Drawing { 29 enum class BlurType { 30 NORMAL, 31 SOLID, 32 OUTER, 33 INNER, 34 }; 35 36 class DRAWING_API MaskFilter { 37 public: 38 enum class FilterType { 39 NO_TYPE, 40 BLUR, 41 }; 42 43 /** 44 * @brief Create a blur Maskfilter. 45 * @param style The Drawing::BlurStyle to use. 46 * @param sigma Standard deviation of the Gaussian blur to apply. Must be > 0. 47 * @param respectCTM if true the blur's sigma is modified by the CTM. 48 * @return A shared pointer to MaskFilter 49 */ 50 static std::shared_ptr<MaskFilter> CreateBlurMaskFilter(BlurType blurType, scalar sigma, bool respectCTM = true); 51 52 virtual ~MaskFilter() = default; 53 FilterType GetType() const; GetDrawingType()54 virtual DrawingType GetDrawingType() const 55 { 56 return DrawingType::COMMON; 57 } 58 59 template<typename T> GetImpl()60 T* GetImpl() const 61 { 62 return impl_->DowncastingTo<T>(); 63 } 64 65 MaskFilter(FilterType t, BlurType blurType, scalar sigma, bool respectCTM = true) noexcept; 66 MaskFilter(FilterType t) noexcept; 67 68 std::shared_ptr<Data> Serialize() const; 69 bool Deserialize(std::shared_ptr<Data> data); 70 protected: 71 MaskFilter() noexcept; 72 73 private: 74 FilterType type_; 75 std::shared_ptr<MaskFilterImpl> impl_; 76 }; 77 } // namespace Drawing 78 } // namespace Rosen 79 } // namespace OHOS 80 #endif