1 /* 2 * Copyright (c) 2024 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 #ifndef GRAPHICS_EFFECT_GE_VISUAL_EFFECT_H 16 #define GRAPHICS_EFFECT_GE_VISUAL_EFFECT_H 17 18 #include <memory> 19 #include <optional> 20 #include <vector> 21 22 #include "common/rs_vector2.h" 23 #include "common/rs_vector3.h" 24 #include "common/rs_vector4.h" 25 #include "effect/color_filter.h" 26 #include "effect/runtime_effect.h" 27 #include "effect/runtime_shader_builder.h" 28 29 #include "ge_shader_filter_params.h" 30 #include "ge_common.h" 31 #include "ge_shader_mask.h" 32 33 namespace OHOS { 34 namespace Rosen { 35 namespace Drawing { 36 constexpr size_t POINT_NUM = 12; 37 38 enum class DrawingPaintType { NONE, BRUSH, PEN, PAINT, BRUSH_PEN }; 39 40 class GEVisualEffectImpl; 41 42 class GE_EXPORT GEVisualEffect { 43 public: 44 GEVisualEffect(const std::string& name, DrawingPaintType type = DrawingPaintType::BRUSH, 45 const std::optional<Drawing::CanvasInfo>& canvasInfo = std::nullopt); 46 ~GEVisualEffect(); 47 48 void SetParam(const std::string& tag, int32_t param); 49 void SetParam(const std::string& tag, int64_t param); 50 void SetParam(const std::string& tag, float param); 51 void SetParam(const std::string& tag, double param); 52 void SetParam(const std::string& tag, const char* const param); 53 54 void SetParam(const std::string& tag, const std::shared_ptr<Drawing::Image> param); SetParam(const std::string & tag,const std::shared_ptr<Drawing::ColorFilter> param)55 void SetParam(const std::string& tag, const std::shared_ptr<Drawing::ColorFilter> param) {} 56 void SetParam(const std::string& tag, const Drawing::Matrix param); 57 void SetParam(const std::string& tag, const std::pair<float, float>& param); 58 void SetParam(const std::string& tag, const std::vector<std::pair<float, float>>&); 59 void SetParam(const std::string& tag, const std::vector<Vector2f>& param); 60 void SetParam(const std::string& tag, const std::array<Drawing::Point, POINT_NUM>& param); 61 void SetParam(const std::string& tag, bool param); 62 void SetParam(const std::string& tag, uint32_t param); 63 void SetParam(const std::string& tag, const std::vector<float>& param); 64 void SetParam(const std::string& tag, const std::shared_ptr<Drawing::GEShaderMask> param); 65 void SetParam(const std::string& tag, const Drawing::Color4f& param); 66 void SetParam(const std::string& tag, const Vector3f& param); 67 void SetParam(const std::string& tag, const Vector4f& param); 68 GetName()69 const std::string& GetName() const 70 { 71 return visualEffectName_; 72 } 73 GetImpl()74 const std::shared_ptr<GEVisualEffectImpl> GetImpl() const 75 { 76 return visualEffectImpl_; 77 } 78 SetCanvasInfo(Drawing::CanvasInfo info)79 void SetCanvasInfo(Drawing::CanvasInfo info) 80 { 81 canvasInfo_ = info; 82 } 83 GetCanvasInfo()84 const Drawing::CanvasInfo GetCanvasInfo() const 85 { 86 return canvasInfo_; 87 } 88 SetSupportHeadroom(float headroom)89 void SetSupportHeadroom(float headroom) 90 { 91 supportHeadroom_ = headroom; 92 } 93 GetSupportHeadroom()94 float GetSupportHeadroom() const 95 { 96 return supportHeadroom_; 97 } 98 99 const std::shared_ptr<Drawing::GEShaderMask> GenerateShaderMask() const; 100 101 private: 102 std::string visualEffectName_; 103 DrawingPaintType type_; 104 std::shared_ptr<GEVisualEffectImpl> visualEffectImpl_; 105 Drawing::CanvasInfo canvasInfo_; 106 float supportHeadroom_ = 0.0f; 107 }; 108 109 } // namespace Drawing 110 } // namespace Rosen 111 } // namespace OHOS 112 113 #endif // GRAPHICS_EFFECT_GE_VISUAL_EFFECT_H 114