!3724 添加渐亮效果

Merge pull request !3724 from Claudia335/cc
This commit is contained in:
openharmony_ci 2023-02-25 03:11:40 +00:00 committed by Gitee
commit ab253e5955
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
6 changed files with 145 additions and 0 deletions

View File

@ -122,6 +122,7 @@ ohos_source_set("render_service_base_src") {
"src/render/rs_filter.cpp",
"src/render/rs_image.cpp",
"src/render/rs_image_cache.cpp",
"src/render/rs_light_up_effect_filter.cpp",
"src/render/rs_mask.cpp",
"src/render/rs_material_filter.cpp",
"src/render/rs_path.cpp",

View File

@ -33,11 +33,13 @@ public:
virtual ~RSFilter();
static std::shared_ptr<RSFilter> CreateBlurFilter(float blurRadiusX, float blurRadiusY);
static std::shared_ptr<RSFilter> CreateMaterialFilter(int style, float dipScale, BLUR_COLOR_MODE mode = DEFAULT);
static std::shared_ptr<RSFilter> CreateLightUpEffectFilter(float lightUpDegree);
enum FilterType {
NONE = 0,
BLUR,
MATERIAL,
LIGHTUPEFFECT,
};
FilterType GetFilterType() const
{

View File

@ -0,0 +1,43 @@
/*
* Copyright (c) 2023 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 RENDER_SERVICE_CLIENT_CORE_RENDER_RS_LIGHT_UP_EFFECT_FILTER_H
#define RENDER_SERVICE_CLIENT_CORE_RENDER_RS_LIGHT_UP_EFFECT_FILTER_H
#include "include/core/SkColorFilter.h"
#include "include/effects/SkImageFilters.h"
#include "render/rs_skia_filter.h"
namespace OHOS {
namespace Rosen {
class RSLightUpEffectFilter : public RSSkiaFilter {
public:
RSLightUpEffectFilter(float lightUpDegree);
~RSLightUpEffectFilter() override;
float GetLightUpDegree();
std::shared_ptr<RSFilter> Add(const std::shared_ptr<RSFilter>& rhs) override;
std::shared_ptr<RSFilter> Sub(const std::shared_ptr<RSFilter>& rhs) override;
std::shared_ptr<RSFilter> Multiply(float rhs) override;
std::shared_ptr<RSFilter> Negate() override;
private:
float lightUpDegree_ = 0.f;
sk_sp<SkImageFilter> CreateLightUpEffectFilter(float lightUpDegree);
friend class RSMarshallingHelper;
};
} // namespace Rosen
} // namespace OHOS
#endif // RENDER_SERVICE_CLIENT_CORE_RENDER_RS_LIGHT_UP_EFFECT_FILTER_H

View File

@ -53,6 +53,7 @@
#include "render/rs_blur_filter.h"
#include "render/rs_filter.h"
#include "render/rs_image.h"
#include "render/rs_light_up_effect_filter.h"
#include "render/rs_material_filter.h"
#include "render/rs_path.h"
#include "render/rs_shader.h"
@ -642,6 +643,11 @@ bool RSMarshallingHelper::Marshalling(Parcel& parcel, const std::shared_ptr<RSFi
parcel.WriteInt32(material->colorMode_);
break;
}
case RSFilter::LIGHTUPEFFECT: {
auto lightUp = std::static_pointer_cast<RSLightUpEffectFilter>(val);
success = success && parcel.WriteFloat(lightUp->lightUpDegree_);
break;
}
default:
break;
}
@ -671,6 +677,14 @@ bool RSMarshallingHelper::Unmarshalling(Parcel& parcel, std::shared_ptr<RSFilter
}
break;
}
case RSFilter::LIGHTUPEFFECT: {
float lightUpDegree;
success = success && parcel.ReadFloat(lightUpDegree);
if (success) {
val = RSFilter::CreateLightUpEffectFilter(lightUpDegree);
}
break;
}
default: {
val = nullptr;
break;

View File

@ -18,6 +18,7 @@
#include "platform/common/rs_log.h"
#include "render/rs_blur_filter.h"
#include "render/rs_material_filter.h"
#include "render/rs_light_up_effect_filter.h"
namespace OHOS {
namespace Rosen {
@ -41,6 +42,15 @@ std::shared_ptr<RSFilter> RSFilter::CreateMaterialFilter(int style, float dipSca
#endif
}
std::shared_ptr<RSFilter> RSFilter::CreateLightUpEffectFilter(float lightUpDegree)
{
#ifdef ROSEN_OHOS
return std::make_shared<RSLightUpEffectFilter>(lightUpDegree);
#else
return nullptr;
#endif
}
std::shared_ptr<RSFilter> operator+(const std::shared_ptr<RSFilter>& lhs, const std::shared_ptr<RSFilter>& rhs)
{
if (lhs == nullptr) {

View File

@ -0,0 +1,75 @@
/*
* Copyright (c) 2023 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 "render/rs_light_up_effect_filter.h"
namespace OHOS {
namespace Rosen {
RSLightUpEffectFilter::RSLightUpEffectFilter(float lightUpDegree)
: RSSkiaFilter(RSLightUpEffectFilter::CreateLightUpEffectFilter(lightUpDegree)),
lightUpDegree_(lightUpDegree)
{
type_ = FilterType::LIGHTUPEFFECT;
}
RSLightUpEffectFilter::~RSLightUpEffectFilter() = default;
sk_sp<SkImageFilter> RSLightUpEffectFilter::CreateLightUpEffectFilter(float lightUpDegree)
{
float normalizedDegree = lightUpDegree - 1.0;
const float lightUp[] = {
1.000000f, 0.000000f, 0.000000f, 0.000000f, normalizedDegree,
0.000000f, 1.000000f, 0.000000f, 0.000000f, normalizedDegree,
0.000000f, 0.000000f, 1.000000f, 0.000000f, normalizedDegree,
0.000000f, 0.000000f, 0.000000f, 1.000000f, 0.000000f,
};
sk_sp<SkColorFilter> lightUpFilter = SkColorFilters::Matrix(lightUp);
return SkImageFilters::ColorFilter(lightUpFilter, nullptr);
}
float RSLightUpEffectFilter::GetLightUpDegree()
{
return lightUpDegree_;
}
std::shared_ptr<RSFilter> RSLightUpEffectFilter::Add(const std::shared_ptr<RSFilter>& rhs)
{
if ((rhs == nullptr) || (rhs->GetFilterType() != FilterType::LIGHTUPEFFECT)) {
return shared_from_this();
}
auto lightUpFilter = std::static_pointer_cast<RSLightUpEffectFilter>(rhs);
return std::make_shared<RSLightUpEffectFilter>(lightUpDegree_ + lightUpFilter->GetLightUpDegree());
}
std::shared_ptr<RSFilter> RSLightUpEffectFilter::Sub(const std::shared_ptr<RSFilter>& rhs)
{
if ((rhs == nullptr) || (rhs->GetFilterType() != FilterType::LIGHTUPEFFECT)) {
return shared_from_this();
}
auto lightUpFilter = std::static_pointer_cast<RSLightUpEffectFilter>(rhs);
return std::make_shared<RSLightUpEffectFilter>(lightUpDegree_ - lightUpFilter->GetLightUpDegree());
}
std::shared_ptr<RSFilter> RSLightUpEffectFilter::Multiply(float rhs)
{
return std::make_shared<RSLightUpEffectFilter>(lightUpDegree_ * rhs);
}
std::shared_ptr<RSFilter> RSLightUpEffectFilter::Negate()
{
return std::make_shared<RSLightUpEffectFilter>(-lightUpDegree_);
}
} // namespace Rosen
} // namespace OHOS