From 17917e95879c04d5b4ff9c10b1af01b03ccc3ff2 Mon Sep 17 00:00:00 2001 From: xumale Date: Thu, 12 Jun 2025 10:20:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9EborderLight?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BUILD.gn | 1 + include/ge_border_light_shader.h | 64 ++++++++++++++++++++++++++++++++ include/ge_visual_effect_impl.h | 1 + src/ge_border_light_shader.cpp | 62 +++++++++++++++++++++++++++++++ 4 files changed, 128 insertions(+) create mode 100644 include/ge_border_light_shader.h create mode 100644 src/ge_border_light_shader.cpp diff --git a/BUILD.gn b/BUILD.gn index e12ecf7..635873c 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -78,6 +78,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_border_light_shader.cpp", ] deps = [ ":utils" ] diff --git a/include/ge_border_light_shader.h b/include/ge_border_light_shader.h new file mode 100644 index 0000000..b88b0d8 --- /dev/null +++ b/include/ge_border_light_shader.h @@ -0,0 +1,64 @@ +/* + * 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_BORDER_LIGHT_SHADER_H +#define GRAPHICS_EFFECT_BORDER_LIGHT_SHADER_H + +#include "ge_shader.h" +#include "common/vector3.h" +#include "common/vector4.h" +#include "utils/matrix.h" + +namespace OHOS { +namespace Rosen { + +struct GE_EXPORT BorderLightParams { + Vector3f lightPosition_; + Vector4f lightColor_; + float lightIntensity_; + float lightWidth_; + Drawing::Matrix matrix_; +}; +class GE_EXPORT GEBorderLightShader : public GEShader { +public: + GEBorderLightShader(); + GEBorderLightShader(BorderLightParams borderLightParams); + + ~GEBorderLightShader() override = default; + + void MakeDrawingShader(const Drawing::Rect& rect, float progress) override; + + const std::string GetDescription() const override { return "GEBorderLightShader"; } + + void SetBorderLightParams(const BorderLightParams& params) + { + borderLightParams_ = params; + } + + void MakeBorderLightShader(const Drawing::Rect& rect); + std::shared_ptr CreateBorderLightShader(BorderLightParams& param); + +private: + + GEBorderLightShader(const GEBorderLightShader&) = delete; + GEBorderLightShader(const GEBorderLightShader&&) = delete; + GEBorderLightShader& operator=(const GEBorderLightShader&) = delete; + GEBorderLightShader& operator=(const GEBorderLightShader&&) = delete; + + BorderLightParams borderLightParams_; +}; + +} // namespace Rosen +} // namespace OHOS +#endif // GRAPHICS_EFFECT_EXT_DOT_MATRIX_SHADER_H \ No newline at end of file diff --git a/include/ge_visual_effect_impl.h b/include/ge_visual_effect_impl.h index 0e656f0..e71060a 100644 --- a/include/ge_visual_effect_impl.h +++ b/include/ge_visual_effect_impl.h @@ -55,6 +55,7 @@ public: EDGE_LIGHT, BEZIER_WARP, DISPERSION, + BORDER_LIGHT, MAX }; diff --git a/src/ge_border_light_shader.cpp b/src/ge_border_light_shader.cpp new file mode 100644 index 0000000..40a6eef --- /dev/null +++ b/src/ge_border_light_shader.cpp @@ -0,0 +1,62 @@ +/* + * 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_log.h" +#include "ge_border_light_shader.h" +#include "effect/runtime_effect.h" + +namespace OHOS{ +namespace Rosen { +GEBorderLightShader::GEBorderLightShader() {} + +std::shared_ptr GEBorderLightShader::CreateBorderLightShader(BorderLightParams& param) +{ + auto type = static_cast(Drawing::GEVisualEffectImpl::FilterType::BORDER_LIGHT); + + return new GEBorderLightShader(param); +} + +void GEBorderLightShader::MakeDrawingShader(const Drawing::Rect& rect, float progress) +{ + drShader_ = MakeBorderLightShader(rect); +} + + +std::shared_ptr GEBorderLightShader::GetBorderLightBuilder() +{ + thread_local std::shared_ptr borderLightShaderEffect_ = nullptr; + + if (borderLightShaderEffect_ == nullptr) { + static constexpr char prog[] = R"()"; + } + + borderLightShaderEffect_ = Drawing::RuntimeEffect::CreateForShader(prog); + + if (borderLightShaderEffect_ == nullptr) { + GE_LOGE("GEBorderLightShader::GetBorderLightBuilder borderLightShaderEffect_ is nullptr."); + return nullptr; + } + return std::make_shared(borderLightShaderEffect_); +} + +void GEBorderLightShader::MakeBorderLightShader(const Drawing::Rect& rect) +{ + auto width = rect.GetWidth(); + auto height = rect.GetHeight(); + auto builder = GetBorderLightBuilder(); + builder.SetUniform("iResolution", width, height); +} + +} // namespace Rosen +} // namespace OHOS \ No newline at end of file -- Gitee