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_EFFECT_RS_RENDER_MASK_BASE_H 17 #define RENDER_SERVICE_BASE_EFFECT_RS_RENDER_MASK_BASE_H 18 19 #include "effect/rs_render_effect_template.h" 20 #include "effect/rs_render_property_tag.h" 21 #include "transaction/rs_marshalling_helper.h" 22 23 namespace OHOS { 24 namespace Rosen { 25 26 namespace Drawing { 27 class GEShaderMask; 28 } // namespace Drawing 29 30 class RSB_EXPORT RSNGRenderMaskBase : public RSNGRenderEffectBase<RSNGRenderMaskBase> { 31 public: 32 virtual ~RSNGRenderMaskBase() = default; 33 34 static std::shared_ptr<RSNGRenderMaskBase> Create(RSNGEffectType type); 35 36 [[nodiscard]] static bool Unmarshalling(Parcel& parcel, std::shared_ptr<RSNGRenderMaskBase>& val); 37 GenerateGEVisualEffect()38 virtual std::shared_ptr<Drawing::GEVisualEffect> GenerateGEVisualEffect() { return nullptr; } 39 }; 40 41 template<RSNGEffectType Type, typename... PropertyTags> 42 class RSNGRenderMaskTemplate : public RSNGRenderEffectTemplate<RSNGRenderMaskBase, Type, PropertyTags...> { 43 public: 44 using EffectTemplateBase = RSNGRenderEffectTemplate<RSNGRenderMaskBase, Type, PropertyTags...>; 45 RSNGRenderMaskTemplate()46 RSNGRenderMaskTemplate() : EffectTemplateBase() {} 47 ~RSNGRenderMaskTemplate() override = default; RSNGRenderMaskTemplate(const std::tuple<PropertyTags...> & properties)48 RSNGRenderMaskTemplate(const std::tuple<PropertyTags...>& properties) noexcept 49 : EffectTemplateBase(properties) {} 50 GenerateGEVisualEffect()51 std::shared_ptr<Drawing::GEVisualEffect> GenerateGEVisualEffect() override 52 { 53 RS_OPTIONAL_TRACE_FMT("RSNGRenderMaskTemplate::GenerateGEVisualEffect, Type: %s", 54 RSNGRenderEffectHelper::GetEffectTypeString(Type).c_str()); 55 auto geMask = RSNGRenderEffectHelper::CreateGEVisualEffect(Type); 56 OnGenerateGEVisualEffect(geMask); 57 std::apply([&geMask](const auto&... propTag) { 58 (RSNGRenderEffectHelper::UpdateVisualEffectParam<std::decay_t<decltype(propTag)>>( 59 geMask, propTag), ...); 60 }, EffectTemplateBase::properties_); 61 // Currently only a single mask is used, so we do not handle the nextEffect_ here. 62 return geMask; 63 } 64 65 protected: OnGenerateGEVisualEffect(std::shared_ptr<Drawing::GEVisualEffect>)66 virtual void OnGenerateGEVisualEffect(std::shared_ptr<Drawing::GEVisualEffect>) {} 67 }; 68 69 70 #define ADD_PROPERTY_TAG(Effect, Prop) Effect##Prop##RenderTag 71 72 #define DECLARE_MASK(MaskName, MaskType, ...) \ 73 using RSNGRender##MaskName = RSNGRenderMaskTemplate<RSNGEffectType::MaskType, __VA_ARGS__> 74 75 DECLARE_MASK(RippleMask, RIPPLE_MASK, 76 ADD_PROPERTY_TAG(RippleMask, Center), 77 ADD_PROPERTY_TAG(RippleMask, Radius), 78 ADD_PROPERTY_TAG(RippleMask, Width), 79 ADD_PROPERTY_TAG(RippleMask, Offset) 80 ); 81 82 DECLARE_MASK(PixelMapMask, PIXEL_MAP_MASK, 83 ADD_PROPERTY_TAG(PixelMapMask, Src), 84 ADD_PROPERTY_TAG(PixelMapMask, Dst), 85 ADD_PROPERTY_TAG(PixelMapMask, FillColor), 86 ADD_PROPERTY_TAG(PixelMapMask, Image) 87 ); 88 89 DECLARE_MASK(RadialGradientMask, RADIAL_GRADIENT_MASK, 90 ADD_PROPERTY_TAG(RadialGradientMask, Center), 91 ADD_PROPERTY_TAG(RadialGradientMask, RadiusX), 92 ADD_PROPERTY_TAG(RadialGradientMask, RadiusY), 93 ADD_PROPERTY_TAG(RadialGradientMask, Colors), 94 ADD_PROPERTY_TAG(RadialGradientMask, Positions) 95 ); 96 97 DECLARE_MASK(WaveGradientMask, WAVE_GRADIENT_MASK, 98 ADD_PROPERTY_TAG(WaveGradientMask, WaveCenter), 99 ADD_PROPERTY_TAG(WaveGradientMask, WaveWidth), 100 ADD_PROPERTY_TAG(WaveGradientMask, PropagationRadius), 101 ADD_PROPERTY_TAG(WaveGradientMask, BlurRadius), 102 ADD_PROPERTY_TAG(WaveGradientMask, TurbulenceStrength) 103 ); 104 105 DECLARE_MASK(DoubleRippleMask, DOUBLE_RIPPLE_MASK, 106 ADD_PROPERTY_TAG(DoubleRippleMask, Center1), 107 ADD_PROPERTY_TAG(DoubleRippleMask, Center2), 108 ADD_PROPERTY_TAG(DoubleRippleMask, Radius), 109 ADD_PROPERTY_TAG(DoubleRippleMask, Width), 110 ADD_PROPERTY_TAG(DoubleRippleMask, Turbulence), 111 ADD_PROPERTY_TAG(DoubleRippleMask, HaloThickness) 112 ); 113 114 #undef ADD_PROPERTY_TAG 115 #undef DECLARE_MASK 116 117 } // namespace Rosen 118 } // namespace OHOS 119 120 #endif // RENDER_SERVICE_BASE_EFFECT_RS_RENDER_MASK_BASE_H 121