diff --git a/BUILD.gn b/BUILD.gn index 56634c1c69ecfa0d74c87e5390d6ae5a52e6289f..e499e53ff4eca7b7df688002b3ce8fd2107ac4c6 100755 --- a/BUILD.gn +++ b/BUILD.gn @@ -83,6 +83,7 @@ ohos_source_set("graphics_effect_src") { "src/ge_visual_effect_container.cpp", "src/ge_visual_effect_impl.cpp", "src/ge_water_ripple_filter.cpp", + "src/ge_wavy_ripple_light_shader.cpp", "src/ge_hps_effect_filter.cpp", ] diff --git a/include/ge_contour_diagonal_flow_light_shader.h b/include/ge_contour_diagonal_flow_light_shader.h index 49d8c3de6b01d6e45969367e7452a87e6b8894ea..ae225785612035ad26baf59706014cda2f4a0a5b 100755 --- a/include/ge_contour_diagonal_flow_light_shader.h +++ b/include/ge_contour_diagonal_flow_light_shader.h @@ -41,7 +41,7 @@ public: contourDiagonalFlowLightParams_ = params; } - void Preprocess(Drawing::Canvas& canvas, const Drawing::Rect& rect); + void Preprocess(Drawing::Canvas& canvas, const Drawing::Rect& rect) override; std::shared_ptr MakeContourDiagonalFlowLightShader(const Drawing::Rect& rect); diff --git a/include/ge_render.h b/include/ge_render.h index 309305db37aa5876460610c1385bdc897e7e39a6..7e0c37300c83d859c6c0db7c6555c010f5b01e59 100644 --- a/include/ge_render.h +++ b/include/ge_render.h @@ -56,7 +56,7 @@ public: const Drawing::Rect& src, const Drawing::Rect& dst, Drawing::Brush& brush); private: - std::vector> GenerateShaderEffect(Drawing::GEVisualEffectContainer& veContainer); + std::shared_ptr GenerateShaderEffect(std::shared_ptr ve); std::vector> GenerateShaderFilter(Drawing::GEVisualEffectContainer& veContainer); diff --git a/include/ge_shader.h b/include/ge_shader.h index 9e7d61f5cc89965d453d86b07caf46ca9ad46251..f5328a23bf6adf9b0f15fc80317c44b427e56532 100644 --- a/include/ge_shader.h +++ b/include/ge_shader.h @@ -15,7 +15,6 @@ #ifndef GRAPHICS_EFFECT_GE_SHADER_H #define GRAPHICS_EFFECT_GE_SHADER_H - #include #include "draw/canvas.h" #include "utils/rect.h" @@ -36,12 +35,15 @@ public: uint32_t Hash() const { return hash_; } - void SetCache(std::shared_ptr cacheData) + // to calculate your cache data + virtual void Preprocess(Drawing::Canvas& canvas, const Drawing::Rect& rect) {} + + void SetCache(const std::shared_ptr& cacheData) { cacheAnyPtr_ = cacheData; } - std::shared_ptr GetCache() + std::shared_ptr GetCache() const { return cacheAnyPtr_; } diff --git a/include/ge_shader_filter_params.h b/include/ge_shader_filter_params.h index 62c19f8bf5c057a22b1d2c8c8201673a93a86804..702051ddfa9a43534de392e03a9cc9655a998566 100644 --- a/include/ge_shader_filter_params.h +++ b/include/ge_shader_filter_params.h @@ -19,6 +19,7 @@ #include #include +#include "common/rs_vector2.h" #include "common/rs_vector3.h" #include "common/rs_vector4.h" #include "utils/matrix.h" @@ -313,7 +314,7 @@ constexpr char GE_SHADER_CONTOUR_DIAGONAL_FLOW_LIGHT_LINE2_START[] = "ContourDia constexpr char GE_SHADER_CONTOUR_DIAGONAL_FLOW_LIGHT_LINE2_LENGTH[] = "ContourDiagonalFlowLight_Line2Length"; constexpr char GE_SHADER_CONTOUR_DIAGONAL_FLOW_LIGHT_LINE2_COLOR[] = "ContourDiagonalFlowLight_Line2Color"; struct GEContentDiagonalFlowLightShaderParams { - std::shared_ptr contour_ = nullptr; + std::shared_ptr contour_{}; float line1Start_ = 0.f; float line1Length_ = 0.f; Vector4f line1Color_ = Vector4f(0.f, 0.f, 0.f, 0.f); diff --git a/include/ge_visual_effect.h b/include/ge_visual_effect.h index 584679c44ce475293844489eea0e9d0a64b8fd4c..01e7141f443339e95d0227a704f60cb098fd2055 100644 --- a/include/ge_visual_effect.h +++ b/include/ge_visual_effect.h @@ -52,10 +52,10 @@ public: void SetParam(const std::string& tag, const std::shared_ptr param) {} void SetParam(const std::string& tag, const std::shared_ptr param) {} - void SetParam(const std::string& tag, const std::shared_ptr param); void SetParam(const std::string& tag, const Drawing::Matrix param); void SetParam(const std::string& tag, const std::pair& param); - void SetParam(const std::string& tag, const std::vector>); + void SetParam(const std::string& tag, const std::vector>&); + void SetParam(const std::string& tag, const std::vector&); void SetParam(const std::string& tag, const std::array& param); void SetParam(const std::string& tag, bool param); void SetParam(const std::string& tag, uint32_t param); diff --git a/include/ge_visual_effect_container.h b/include/ge_visual_effect_container.h index 7c771b4f92e922205628124cf5be42d553cb1e30..82561acb6f2266608b09a275d41054688105967d 100644 --- a/include/ge_visual_effect_container.h +++ b/include/ge_visual_effect_container.h @@ -33,7 +33,11 @@ public: return filterVec_; } + void UpdateCacheDataFrom(const std::shared_ptr& ge); + private: + std::shared_ptr GetGEVisualEffect(const std::string& name); + std::vector> filterVec_; }; diff --git a/include/ge_visual_effect_impl.h b/include/ge_visual_effect_impl.h index ef50e05b8ff35e3ec616d180c53986c843cb1fef..285e4774bfed690df075e5c0ac959ef5eb032ad8 100644 --- a/include/ge_visual_effect_impl.h +++ b/include/ge_visual_effect_impl.h @@ -80,11 +80,11 @@ public: void SetParam(const std::string& tag, const char* const param); void SetParam(const std::string& tag, const std::shared_ptr param); - void SetParam(const std::string& tag, const std::shared_ptr param); void SetParam(const std::string& tag, const std::shared_ptr param); void SetParam(const std::string& tag, const Drawing::Matrix param); void SetParam(const std::string& tag, const std::pair& param); void SetParam(const std::string& tag, const std::vector>); + void SetParam(const std::string& tag, const std::vector&); void SetParam(const std::string& tag, const std::array& param); void SetParam(const std::string& tag, bool param); void SetParam(const std::string& tag, uint32_t param); @@ -290,7 +290,7 @@ public: cacheAnyPtr_ = cacheData; } - std::shared_ptr GetCache() + std::shared_ptr GetCache() const { return cacheAnyPtr_; } @@ -327,7 +327,6 @@ public: private: static std::map> g_initialMap; - std::shared_ptr cacheAnyPtr_ = nullptr; void SetMESABlurParams(const std::string& tag, float param); void SetAIBarParams(const std::string& tag, float param); void SetGreyParams(const std::string& tag, float param); @@ -377,6 +376,8 @@ private: std::shared_ptr contentDiagonalParams_ = nullptr; std::shared_ptr wavyRippleLightParams_ = nullptr; std::shared_ptr auroNoiseParams_ = nullptr; + + std::shared_ptr cacheAnyPtr_ = nullptr; std::shared_ptr particleCircularHaloParams_ = nullptr; }; diff --git a/include/ge_wavy_ripple_light_shader.h b/include/ge_wavy_ripple_light_shader.h new file mode 100644 index 0000000000000000000000000000000000000000..1b51dcd05eaa3937d207e585697cb74c504560af --- /dev/null +++ b/include/ge_wavy_ripple_light_shader.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef GRAPHICS_EFFECT_WAVY_RIPPLE_LIGHT_SHADER_H +#define GRAPHICS_EFFECT_WAVY_RIPPLE_LIGHT_SHADER_H + +#include + +#include "ge_shader.h" +#include "common/rs_vector2.h" +#include "effect/runtime_shader_builder.h" +#include "utils/matrix.h" +#include "ge_shader_filter_params.h" + +namespace OHOS { +namespace Rosen { + +class GE_EXPORT GEWavyRippleLightShader : public GEShader { +public: + GEWavyRippleLightShader(); + GEWavyRippleLightShader(Drawing::GEWavyRippleLightShaderParams& param); + ~GEWavyRippleLightShader() override = default; + + void MakeDrawingShader(const Drawing::Rect& rect, float progress) override; + + const std::string GetDescription() const { return "GEWavyRippleLightShader";} + + void SetWavyRippleLightParams(const Drawing::GEWavyRippleLightShaderParams& param); + + std::shared_ptr MakeWavyRippleLightShader(const Drawing::Rect& rect); + + static std::shared_ptr CreateWavyRippleLightShader(Drawing::GEWavyRippleLightShaderParams& + param); + + std::shared_ptr GetWavyRippleLightBuilder(); + +private: + GEWavyRippleLightShader(const GEWavyRippleLightShader&) = delete; + GEWavyRippleLightShader(const GEWavyRippleLightShader&&) = delete; + GEWavyRippleLightShader& operator=(const GEWavyRippleLightShader&) = delete; + GEWavyRippleLightShader& operator=(const GEWavyRippleLightShader&&) = delete; + Drawing::GEWavyRippleLightShaderParams wavyRippleLightParams_; + std::shared_ptr builder_; +}; + +} // namespace Rosen +} // namespace OHOS + +#endif // GRAPHICS_EFFECT_WAVY_RIPPLE_LIGHT_SHADER_H \ No newline at end of file diff --git a/src/ge_render.cpp b/src/ge_render.cpp index ae9bf5945872f7d9f16cf7c17df034c42490f74d..4aae5fb9046f2d719b3839f07e90d00666d220fd 100755 --- a/src/ge_render.cpp +++ b/src/ge_render.cpp @@ -28,6 +28,7 @@ #include "ge_particle_circular_halo_shader.h" #include "ge_visual_effect_impl.h" #include "ge_water_ripple_filter.h" +#include "ge_wavy_ripple_light_shader.h" #include "ge_sound_wave_filter.h" #include "ge_external_dynamic_loader.h" #include "ge_edge_light_shader_filter.h" @@ -37,7 +38,50 @@ namespace OHOS { namespace GraphicsEffectEngine { +using namespace Rosen::Drawing; +using ShaderCreator = std::function(std::shared_ptr)>; +static std::unordered_map shaderCreatorLUT = { + {GEVisualEffectImpl::FilterType::CONTOUR_DIAGONAL_FLOW_LIGHT, [] (std::shared_ptr ve) + { + std::shared_ptr out = nullptr; + if (ve == nullptr || ve->GetContenDiagonalParams() == nullptr) { + return out; + } + const auto& params = ve->GetContenDiagonalParams(); + out = std::make_shared(*params); + return out; + } + }, + {GEVisualEffectImpl::FilterType::WAVY_RIPPLE_LIGHT, [] (std::shared_ptr ve) + { + std::shared_ptr out = nullptr; + if (ve == nullptr || ve->GetWavyRippleLightParams() == nullptr) { + return out; + } + const auto& params = ve->GetWavyRippleLightParams(); + out = std::make_shared(*params); + return out; + } + }, + {GEVisualEffectImpl::FilterType::AURORA_NOISE, [] (std::shared_ptr ve) + { + std::shared_ptr out = nullptr; + return out; + } + }, + {GEVisualEffectImpl::FilterType::PARTICLE_CIRCULAR_HALO, [] (std::shared_ptr ve) + { + std::shared_ptr out = nullptr; + if (ve == nullptr || ve->GetParticleCircularHaloParams() == nullptr) { + return out; + } + const auto& params = ve->GetParticleCircularHaloParams(); + out = std::make_shared(*params); + return out; + } + } +}; GERender::GERender() {} GERender::~GERender() {} @@ -254,59 +298,36 @@ std::vector> GERender::GenerateShaderFilter( void GERender::DrawShaderEffect(Drawing::Canvas& canvas, Drawing::GEVisualEffectContainer& veContainer, const Drawing::Rect& bounds) { - std::vector> geShaderEffects = GenerateShaderEffect(veContainer); - for (auto geShaderEffect : geShaderEffects) { + LOGD("GERender::DrawShaderEffect %{public}zu", veContainer.GetFilters().size()); + for (auto vef : veContainer.GetFilters()) { + if (vef == nullptr) { + LOGD("GERender::DrawShaderEffect vef is null"); + continue; + } + auto ve = vef->GetImpl(); + std::shared_ptr geShaderEffect = GenerateShaderEffect(ve); if (geShaderEffect == nullptr) { LOGD("GERender::DrawShaderEffect shader is null"); continue; } - geShaderEffect->MakeDrawingShader(bounds, -1.f); // new flow not use progress + geShaderEffect->SetCache(ve->GetCache()); + geShaderEffect->Preprocess(canvas, bounds); // to calculate your cache data + geShaderEffect->MakeDrawingShader(bounds, -1.f); // not use progress auto shader = geShaderEffect->GetDrawingShader(); Drawing::Brush brush; brush.SetShaderEffect(shader); canvas.AttachBrush(brush); canvas.DrawRect(bounds); canvas.DetachBrush(); + + ve->SetCache(geShaderEffect->GetCache()); } } -std::vector> GERender::GenerateShaderEffect(Drawing::GEVisualEffectContainer& veContainer) +std::shared_ptr GERender::GenerateShaderEffect(std::shared_ptr ve) { - LOGD("GERender::shaderEffects %{public}zu", veContainer.GetFilters().size()); - std::vector> shaderEffects; - for (auto vef : veContainer.GetFilters()) { - auto ve = vef->GetImpl(); - std::shared_ptr shaderEffect; - LOGD("GERender::shaderEffects %{public}d", static_cast(ve->GetFilterType())); - switch (ve->GetFilterType()) { - case Drawing::GEVisualEffectImpl::FilterType::CONTOUR_DIAGONAL_FLOW_LIGHT: { - const auto& params = ve->GetContenDiagonalParams(); - shaderEffect = GEContourDiagonalFlowLightShader::CreateContourDiagonalFlowLightShader(*params); - shaderEffects.push_back(shaderEffect); - return shaderEffects; - } - - case Drawing::GEVisualEffectImpl::FilterType::WAVY_RIPPLE_LIGHT: { - const auto& params = ve->GetWavyRippleLightParams(); - (void)params; - break; - } - case Drawing::GEVisualEffectImpl::FilterType::AURORA_NOISE: { - const auto& params = ve->GetAuroraNoiseParams(); - (void)params; - break; - } - case Drawing::GEVisualEffectImpl::FilterType::PARTICLE_CIRCULAR_HALO: { - const auto& params = ve->GetParticleCircularHaloParams(); - (void)params; - break; - } - default: - break; - } - shaderEffects.push_back(shaderEffect); - } - return shaderEffects; + auto it = shaderCreatorLUT.find(ve->GetFilterType()); + return it != shaderCreatorLUT.end() ? it->second(ve) : nullptr; } } // namespace GraphicsEffectEngine } // namespace OHOS diff --git a/src/ge_visual_effect.cpp b/src/ge_visual_effect.cpp index 02aa063221eca10a7996cea19204cdfa93a037fc..8d83022a66c793d615c67b7117fdc900b98d10b3 100644 --- a/src/ge_visual_effect.cpp +++ b/src/ge_visual_effect.cpp @@ -64,22 +64,22 @@ void GEVisualEffect::SetParam(const std::string& tag, const char* const param) visualEffectImpl_->SetParam(tag, param); } -void GEVisualEffect::SetParam(const std::string& tag, const std::shared_ptr param) +void GEVisualEffect::SetParam(const std::string& tag, const Drawing::Matrix param) { visualEffectImpl_->SetParam(tag, param); } -void GEVisualEffect::SetParam(const std::string& tag, const Drawing::Matrix param) +void GEVisualEffect::SetParam(const std::string& tag, const std::pair& param) { visualEffectImpl_->SetParam(tag, param); } -void GEVisualEffect::SetParam(const std::string& tag, const std::pair& param) +void GEVisualEffect::SetParam(const std::string& tag, const std::vector> param) { visualEffectImpl_->SetParam(tag, param); } -void GEVisualEffect::SetParam(const std::string& tag, const std::vector> param) +void GEVisualEffect::SetParam(const std::string& tag, const std::vector param) { visualEffectImpl_->SetParam(tag, param); } diff --git a/src/ge_visual_effect_container.cpp b/src/ge_visual_effect_container.cpp index cf717c310457acc5018f9253b26abf7a9ce505c5..56b6a01d02505d19a07ea6dc7f8e8479b5b6fef2 100644 --- a/src/ge_visual_effect_container.cpp +++ b/src/ge_visual_effect_container.cpp @@ -16,6 +16,7 @@ #include "ge_visual_effect_container.h" #include "ge_log.h" +#include "ge_visual_effect_impl.h" namespace OHOS { namespace Rosen { @@ -33,6 +34,39 @@ void GEVisualEffectContainer::AddToChainedFilter(std::shared_ptr& ge) +{ + if (ge == nullptr) { + return; + } + for (auto vef : ge->GetFilters()) { + if (vef == nullptr) { + LOGD("GEVisualEffectContainer::UpdateCacheDataFrom vef is null"); + continue; + } + auto vefTarget = GetGEVisualEffect(vef->GetName()); + if (vef->GetImpl() == nullptr || vefTarget == nullptr || vefTarget->GetImpl() == nullptr) { + LOGD("GEVisualEffectContainer::UpdateCacheDataFrom ve is null"); + continue; + } + vefTarget->GetImpl()->SetCache(vef->GetImpl()->GetCache()); + } +} + +std::shared_ptr GEVisualEffectContainer::GetGEVisualEffect(const std::string& name) +{ + for (auto vef : filterVec_) { + if (vef == nullptr) { + LOGD("GEVisualEffectContainer::GetGEVisualEffect vef is null"); + continue; + } + if (vef->GetName() == name) { + return vef; + } + } + return nullptr; +} + } // namespace Drawing } // namespace Rosen } // namespace OHOS diff --git a/src/ge_visual_effect_impl.cpp b/src/ge_visual_effect_impl.cpp index 149d4a1da7f61dc684d53f7765ea6225ca40965e..e9ab7e8d132b5cae08932ba48d1717fbad4b13e0 100644 --- a/src/ge_visual_effect_impl.cpp +++ b/src/ge_visual_effect_impl.cpp @@ -345,24 +345,6 @@ void GEVisualEffectImpl::SetParam(const std::string& tag, const std::shared_ptr< } } -void GEVisualEffectImpl::SetParam(const std::string& tag, const std::shared_ptr param) -{ - switch (filterType_) { - case FilterType::CONTOUR_DIAGONAL_FLOW_LIGHT: { - if (contentDiagonalParams_ == nullptr) { - return; - } - - if (tag == GE_SHADER_CONTOUR_DIAGONAL_FLOW_LIGHT_CONTOUR) { - contentDiagonalParams_->contour_ = param; - } - break; - } - default: - break; - } -} - void GEVisualEffectImpl::SetParam(const std::string& tag, const std::shared_ptr param) {} void GEVisualEffectImpl::SetParam(const std::string& tag, const Drawing::Matrix param) @@ -443,6 +425,24 @@ void GEVisualEffectImpl::SetParam(const std::string& tag, const std::vector param) +{ + switch (filterType_) { + case FilterType::CONTOUR_DIAGONAL_FLOW_LIGHT: { + if (contentDiagonalParams_ == nullptr) { + return; + } + + if (tag == GE_SHADER_CONTOUR_DIAGONAL_FLOW_LIGHT_CONTOUR) { + contentDiagonalParams_->contour_ = param; + } + break; + } + default: + break; + } +} + void GEVisualEffectImpl::SetParam(const std::string& tag, const std::array& param) { switch (filterType_) { diff --git a/src/ge_wavy_ripple_light_shader.cpp b/src/ge_wavy_ripple_light_shader.cpp new file mode 100644 index 0000000000000000000000000000000000000000..54829e407912ad92fb58ea719a1047730965aab8 --- /dev/null +++ b/src/ge_wavy_ripple_light_shader.cpp @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ge_wavy_ripple_light_shader.h" +#include "ge_log.h" + +namespace OHOS { +namespace Rosen { + +namespace { + static constexpr char PROG[] = R"( + uniform vec2 iResolution; + uniform vec2 center; + uniform float radius; + + const float noiseScale = 0.3; + const float waveScale = 0.5; + + const float freqX = 4.0; + const float freqY = 6.0; + const float freqDiag = 8.0; + + const float thickness = 0.2; + + float ShapeSDF(vec2 p, float radius) + { + float dist = length(p); + + float noise = 0.0; + noise += sin(p.x * freqX) * 0.25; + noise += sin(p.y * freqY) * 0.35; + noise += sin((p.x + p.y) * freqDiag) * 0.3; + + float distortedDist = dist + noise * noiseScale; + float attenuation = waveScale / (1.0 + distortedDist * 5.0); + float wave = sin(distortedDist * 30.0) * attenuation; + return distortedDist - radius + wave * 0.05; + } + + vec4 main(vec2 fragCoord) + { + vec2 uv = fragCoord.xy / iResolution.xy; + float aspect = iResolution.x / iResolution.y; + vec3 color = vec3(0.0); + + vec2 p = uv * 2.0 - 1.0; + c.x *= aspect; + + vec2 delta = p -c; + + float dis0 = length(c - vec2(-aspect, -1.0)); + float dis1 = length(c - vec2(-aspect, -1.0)); + float dis2 = length(c - vec2(-aspect, -1.0)); + float dis3 = length(c - vec2(-aspect, -1.0)); + float maxRadius = max(max(dist0, dist1), max(dist2, dist3)); + + float currentRadius = maxRadius * radius; + float d = abs(ShapeSDF(delta, currentRadius)); + float mask = smoothstep(thickness, 0.0, d); + + vec3 baseColor = vec3(0.8, 0.5, 1.0); + color = baseColor * mask; + return vec4(color, mask); + } + )"; +} + +GEWavyRippleLightShader::GEWavyRippleLightShader() {} + +GEWavyRippleLightShader::GEWavyRippleLightShader(Drawing::GEWavyRippleLightShaderParams& param) +{ + wavyRippleLightParams_ = param; +} +std::shared_ptr GEWavyRippleLightShader::CreateWavyRippleLightShader( + Drawing::GEWavyRippleLightShaderParams& param) +{ + std::shared_ptr wavyRippleLightShader = std::make_shared(param); + return wavyRippleLightShader; +} + +void GEWavyRippleLightShader::MakeDrawingShader(const Drawing::Rect& rect, float progress) +{ + drShader_ = MakeWavyRippleLightShader(rect); +} + +void GEWavyRippleLightShader::SetWavyRippleLightParams(const Drawing::GEWavyRippleLightShaderParams& param) +{ + wavyRippleLightParams_ = param; +} + +std::shared_ptr GEWavyRippleLightShader::GetWavyRippleLightBuilder() +{ + thread_local std::shared_ptr wavyRippleLightShaderEffect_ = nullptr; + if (wavyRippleLightShaderEffect_ == nullptr) { + wavyRippleLightShaderEffect_ = Drawing::RuntimeEffect::CreateForShader(PROG); + } + if (wavyRippleLightShaderEffect_ == nullptr) { + GE_LOGE("GEWavyRippleLightShader::GetWavyRippleLightBuilder wavyRippleLightShaderEffect_ is nullptr"); + return nullptr; + } + return std::make_shared(wavyRippleLightShaderEffect_); +} + +std::shared_ptr GEWavyRippleLightShader::MakeWavyRippleLightShader(const Drawing::Rect& rect) +{ + auto width = rect.GetWidth(); + auto height = rect.GetHeight(); + builder_ = GetWavyRippleLightBuilder(); + builder_->SetUniform("iResolution", width, height); + builder_->SetUniform("center", wavyRippleLightParams_.center_.first, wavyRippleLightParams_.center_.second); + builder_->SetUniform("radius", wavyRippleLightParams_.radius_); + auto wavyRippleLightShader = builder_->MakeShader(nullptr, false); + if (wavyRippleLightShader == nullptr) { + GE_LOGE("GEWavyRippleLightShader::MakeWavyRippleLightShader wavyRippleLightShader is nullptr"); + return nullptr; + } + return wavyRippleLightShader; +} +} // namespace Rosen +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 436f8f49e976f2b81603fa3e6b4419daae1c4195..e0eb7062c46d61a06226e06b39a51741432e8827 100755 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -74,6 +74,7 @@ ohos_source_set("graphics_effect_test_src") { "${graphics_effect_root}/src/ge_visual_effect_container.cpp", "${graphics_effect_root}/src/ge_visual_effect_impl.cpp", "${graphics_effect_root}/src/ge_water_ripple_filter.cpp", + "${graphics_effect_root}/src/ge_wavy_ripple_light_shader.cpp", "${graphics_effect_root}/src/ge_hps_effect_filter.cpp", ] diff --git a/test/unittest/ge_render_test.cpp b/test/unittest/ge_render_test.cpp index e1ceb62e97d9ea126ea03696bc2b74507e80f201..9fad04fc0fab88dacb55944d14411d883f7a3541 100644 --- a/test/unittest/ge_render_test.cpp +++ b/test/unittest/ge_render_test.cpp @@ -538,6 +538,37 @@ HWTEST_F(GERenderTest, GenerateShaderFilterDispersion_001, TestSize.Level1) } /** + * @tc.name: GenerateShaderEffect + * @tc.desc: Verify the GenerateShaderFilter + * @tc.type: FUNC + */ +HWTEST_F(GERenderTest, GenerateShaderEffect, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GERenderTest GenerateShaderEffect start"; + + Drawing::GEVisualEffectContainer veContainer; + auto diagonalVE = std::make_shared( + Drawing::GE_SHADER_CONTOUR_DIAGONAL_FLOW_LIGHT); + veContainer.AddToChainedFilter(diagonalVE); + auto wavyVE = std::make_shared( + Drawing::GE_SHADER_WAVY_RIPPLE_LIGHT); + veContainer.AddToChainedFilter(wavyVE); + auto nullMemberVE = std::make_shared( + std::string("null")); + auto geRender = std::make_shared(); + EXPECT_EQ(geRender->GenerateShaderEffect(nullMemberVE->GetImpl()), nullptr); + nullMemberVE->visualEffectImpl_ = nullptr; + veContainer.AddToChainedFilter(nullMemberVE); + std::shared_ptr nullVE = nullptr; + veContainer.AddToChainedFilter(nullVE); + + geRender->DrawShaderEffect(canvas_, veContainer, Drawing::Rect{0, 0, 100, 100}); + EXPECT_NE(veContainer.GetFilters().empty(), true); + + EXPECT_NE(geRender->GenerateShaderEffect(diagonalVE->GetImpl()), nullptr); + GTEST_LOG_(INFO) << "GERenderTest GenerateShaderEffect end"; +} + * @tc.name: ApplyHpsImageEffect_001 * @tc.desc: Verify the ApplyHpsImageEffect * @tc.type: FUNC