1 /* 2 * Copyright (c) 2025 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 RENDER_SERVICE_BASE_RENDER_FILTER_BASE_H 17 #define RENDER_SERVICE_BASE_RENDER_FILTER_BASE_H 18 19 #include "draw/canvas.h" 20 #include "effect/rs_render_property_tag.h" 21 #include "effect/runtime_shader_builder.h" 22 #include "render/rs_filter.h" 23 24 namespace OHOS { 25 namespace Rosen { 26 27 namespace Drawing { 28 class GEVisualEffectContainer; 29 class GEVisualEffect; 30 struct CanvasInfo; 31 } // namespace Drawing 32 33 enum class RSUIFilterType : int16_t { 34 INVALID = -1, 35 NONE = 0, 36 // filter type 37 AIBAR, 38 GREY, 39 MATERIAL, 40 MAGNIFIER, 41 MESA, 42 MASK_COLOR, 43 KAWASE, 44 LIGHT_BLUR, 45 PIXEL_STRETCH, 46 WATER_RIPPLE, 47 48 LINEAR_GRADIENT_BLUR, 49 FLY_OUT, 50 DISTORTION, 51 ALWAYS_SNAPSHOT, 52 }; 53 54 using RSUIFilterTypeUnderlying = std::underlying_type<RSUIFilterType>::type; 55 56 class RSB_EXPORT RSRenderFilterParaBase : public RSRenderPropertyBase, 57 public std::enable_shared_from_this<RSRenderFilterParaBase> { 58 public: 59 RSRenderFilterParaBase() = default; RSRenderFilterParaBase(RSUIFilterType type)60 RSRenderFilterParaBase(RSUIFilterType type) : type_(type) {} 61 virtual ~RSRenderFilterParaBase() = default; 62 DeepCopy()63 virtual std::shared_ptr<RSRenderFilterParaBase> DeepCopy() const 64 { 65 return nullptr; 66 } 67 68 RSUIFilterType GetType() const; 69 70 virtual bool IsValid() const; 71 GetDescription(std::string & out)72 virtual void GetDescription(std::string& out) const {} 73 74 void Dump(std::string& out) const override; 75 76 virtual bool WriteToParcel(Parcel& parcel); 77 78 virtual bool ReadFromParcel(Parcel& parcel); 79 80 std::shared_ptr<RSRenderPropertyBase> GetRenderProperty(RSUIFilterType type) const; 81 82 virtual std::vector<std::shared_ptr<RSRenderPropertyBase>> GetLeafRenderProperties(); 83 ParseFilterValues()84 virtual bool ParseFilterValues() 85 { 86 return false; 87 } 88 PreProcess(std::shared_ptr<Drawing::Image> & image)89 virtual void PreProcess(std::shared_ptr<Drawing::Image>& image) {}; ProcessImage(Drawing::Canvas & canvas,const std::shared_ptr<Drawing::Image> image,const Drawing::Rect & src,const Drawing::Rect & dst)90 virtual std::shared_ptr<Drawing::Image> ProcessImage(Drawing::Canvas& canvas, 91 const std::shared_ptr<Drawing::Image> image, const Drawing::Rect& src, const Drawing::Rect& dst) 92 { 93 return image; 94 } 95 GenerateGEVisualEffect(std::shared_ptr<Drawing::GEVisualEffectContainer> visualEffectContainer)96 virtual void GenerateGEVisualEffect(std::shared_ptr<Drawing::GEVisualEffectContainer> visualEffectContainer) {}; PostProcess(Drawing::Canvas & canvas)97 virtual void PostProcess(Drawing::Canvas& canvas) {}; 98 NeedForceSubmit()99 virtual bool NeedForceSubmit() const { return false; } 100 Hash()101 uint32_t Hash() const 102 { 103 return hash_; 104 } GetPropertyType()105 RSPropertyType GetPropertyType() const override {return RSPropertyType::INVALID;} GetSize()106 size_t GetSize() const override {return sizeof(*this);} Marshalling(Parcel & parcel)107 bool Marshalling(Parcel& parcel) override {return false;} 108 109 virtual void SetGeometry(Drawing::Canvas& canvas, float geoWidth, float geoHeight); 110 Drawing::CanvasInfo GetFilterCanvasInfo() const; 111 112 protected: 113 RSUIFilterType type_; 114 std::map<RSUIFilterType, std::shared_ptr<RSRenderPropertyBase>> properties_; 115 float geoWidth_ = 0.f; 116 float geoHeight_ = 0.f; 117 float tranX_ = 0.f; 118 float tranY_ = 0.f; 119 Drawing::Matrix mat_; 120 uint32_t basicHash_ = 0; 121 uint32_t hash_ = 0; 122 }; 123 } // namespace Rosen 124 } // namespace OHOS 125 126 #endif // RENDER_SERVICE_BASE_RENDER_FILTER_BASE_H 127