1 /* 2 * Copyright (c) 2021-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 ROSEN_ENGINE_CORE_RENDER_RS_FILTER_H 17 #define ROSEN_ENGINE_CORE_RENDER_RS_FILTER_H 18 19 #include <memory> 20 #include <stdint.h> 21 22 #include "common/rs_color.h" 23 #include "common/rs_macros.h" 24 25 namespace OHOS { 26 namespace Rosen { 27 enum BLUR_COLOR_MODE : int { 28 PRE_DEFINED = 0, // use the pre-defined mask color 29 AVERAGE = 1, // use the average color of the blurred area as mask color 30 DEFAULT = PRE_DEFINED 31 }; 32 33 class RSB_EXPORT RSFilter : public std::enable_shared_from_this<RSFilter> { 34 public: 35 virtual ~RSFilter(); 36 RSFilter(const RSFilter&) = delete; 37 RSFilter(const RSFilter&&) = delete; 38 RSFilter& operator=(const RSFilter&) = delete; 39 RSFilter& operator=(const RSFilter&&) = delete; 40 virtual std::string GetDescription(); 41 static std::shared_ptr<RSFilter> CreateBlurFilter(float blurRadiusX, float blurRadiusY); 42 static std::shared_ptr<RSFilter> CreateMaterialFilter( 43 int style, float dipScale, BLUR_COLOR_MODE mode = DEFAULT, float ratio = 1.0); 44 static std::shared_ptr<RSFilter> CreateMaterialFilter( 45 float radius, float saturation, float brightness, uint32_t colorValue); 46 static std::shared_ptr<RSFilter> CreateLightUpEffectFilter(float lightUpDegree); 47 48 enum FilterType { 49 NONE = 0, 50 BLUR, 51 MATERIAL, 52 LIGHT_UP_EFFECT, 53 }; GetFilterType()54 FilterType GetFilterType() const 55 { 56 return type_; 57 } IsValid()58 virtual bool IsValid() const 59 { 60 return type_ != FilterType::NONE; 61 } 62 Hash()63 uint32_t Hash() const 64 { 65 return hash_; 66 } 67 68 protected: 69 FilterType type_; 70 uint32_t hash_ = 0; 71 RSFilter(); Add(const std::shared_ptr<RSFilter> & rhs)72 virtual std::shared_ptr<RSFilter> Add(const std::shared_ptr<RSFilter>& rhs) { return nullptr; } Sub(const std::shared_ptr<RSFilter> & rhs)73 virtual std::shared_ptr<RSFilter> Sub(const std::shared_ptr<RSFilter>& rhs) { return nullptr; } Multiply(float rhs)74 virtual std::shared_ptr<RSFilter> Multiply(float rhs) { return nullptr; } Negate()75 virtual std::shared_ptr<RSFilter> Negate() { return nullptr; } 76 friend RSB_EXPORT std::shared_ptr<RSFilter> operator+(const std::shared_ptr<RSFilter>& lhs, 77 const std::shared_ptr<RSFilter>& rhs); 78 friend RSB_EXPORT std::shared_ptr<RSFilter> operator-(const std::shared_ptr<RSFilter>& lhs, 79 const std::shared_ptr<RSFilter>& rhs); 80 friend RSB_EXPORT std::shared_ptr<RSFilter> operator*(const std::shared_ptr<RSFilter>& lhs, float rhs); 81 }; 82 } // namespace Rosen 83 } // namespace OHOS 84 85 #endif // ROSEN_ENGINE_CORE_RENDER_RS_FILTER_H 86