mirror of
https://gitee.com/openharmony/graphic_graphic_2d
synced 2024-11-27 09:10:54 +00:00
commit
959ec87f30
@ -68,15 +68,6 @@ public:
|
||||
Drawing::RecordingCanvas::DrawFunc CreateDrawFunc() const override;
|
||||
};
|
||||
|
||||
class RSColorfulShadowDrawable : public RSPropertyDrawable {
|
||||
public:
|
||||
RSColorfulShadowDrawable(
|
||||
std::shared_ptr<Drawing::DrawCmdList>&& drawCmdList) : RSPropertyDrawable(std::move(drawCmdList))
|
||||
{}
|
||||
RSColorfulShadowDrawable() = default;
|
||||
bool OnUpdate(const RSRenderNode& node) override;
|
||||
};
|
||||
|
||||
class RSMaskDrawable : public RSPropertyDrawable {
|
||||
public:
|
||||
RSMaskDrawable(std::shared_ptr<Drawing::DrawCmdList>&& drawCmdList) : RSPropertyDrawable(std::move(drawCmdList)) {}
|
||||
|
@ -349,7 +349,7 @@ public:
|
||||
|
||||
bool IsBackgroundMaterialFilterValid() const;
|
||||
bool IsForegroundMaterialFilterVaild() const;
|
||||
|
||||
|
||||
// shadow properties
|
||||
void SetShadowColor(Color color);
|
||||
void SetShadowOffsetX(float offsetX);
|
||||
@ -626,7 +626,7 @@ private:
|
||||
int foregroundColorMode_ = BLUR_COLOR_MODE::DEFAULT;
|
||||
float foregroundBlurRadiusX_ = 0.f;
|
||||
float foregroundBlurRadiusY_ = 0.f;
|
||||
|
||||
|
||||
std::weak_ptr<RSRenderNode> backref_;
|
||||
|
||||
std::optional<Vector4f> pixelStretch_;
|
||||
@ -658,6 +658,7 @@ private:
|
||||
void CheckGreyCoef();
|
||||
|
||||
void UpdateFilter();
|
||||
void UpdateForegroundFilter();
|
||||
|
||||
// partial update
|
||||
bool colorFilterNeedUpdate_ = false;
|
||||
|
@ -54,8 +54,8 @@ RSDrawable::Ptr RSShadowDrawable::OnGenerate(const RSRenderNode& node)
|
||||
bool RSShadowDrawable::OnUpdate(const RSRenderNode& node)
|
||||
{
|
||||
const RSProperties& properties = node.GetRenderProperties();
|
||||
// skip shadow if not valid. ShadowMask is processed by foregound
|
||||
if (!properties.IsShadowValid() || node.GetRenderProperties().GetShadowMask()) {
|
||||
// skip shadow if not valid. ShadowMask is processed by foreground
|
||||
if (!properties.IsShadowValid() || properties.GetShadowMask()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -120,8 +120,8 @@ Drawing::RecordingCanvas::DrawFunc RSShadowDrawable::CreateDrawFunc() const
|
||||
|
||||
bool RSMaskShadowDrawable::OnUpdate(const RSRenderNode& node)
|
||||
{
|
||||
// skip shadow if not valid
|
||||
if (!node.GetRenderProperties().IsShadowValid()) {
|
||||
// skip shadow if not valid. ShadowMask is processed by foreground
|
||||
if (!node.GetRenderProperties().IsShadowValid() || node.GetRenderProperties().GetShadowMask()) {
|
||||
return false;
|
||||
}
|
||||
RSPropertyDrawCmdListUpdater updater(0, 0, this);
|
||||
@ -189,41 +189,6 @@ Drawing::RecordingCanvas::DrawFunc RSMaskShadowDrawable::CreateDrawFunc() const
|
||||
};
|
||||
}
|
||||
|
||||
bool RSColorfulShadowDrawable::OnUpdate(const RSRenderNode& node)
|
||||
{
|
||||
// regenerate stagingDrawCmdList_
|
||||
RSPropertyDrawCmdListUpdater updater(0, 0, this);
|
||||
Drawing::Canvas& canvas = *updater.GetRecordingCanvas();
|
||||
const RSProperties& properties = node.GetRenderProperties();
|
||||
// skip shadow if not valid or cache is enabled
|
||||
if (!properties.IsShadowValid() || canvas.GetCacheType() == Drawing::CacheType::ENABLED) {
|
||||
return false;
|
||||
}
|
||||
Drawing::AutoCanvasRestore acr(canvas, true);
|
||||
Drawing::Path path = RSPropertyDrawableUtils::CreateShadowPath(properties.GetShadowPath(),
|
||||
properties.GetClipBounds(), properties.GetRRect());
|
||||
if (!properties.GetShadowIsFilled()) {
|
||||
canvas.ClipPath(path, Drawing::ClipOp::DIFFERENCE, true);
|
||||
}
|
||||
// blurRadius calculation is based on the formula in Canvas::DrawShadow, 0.25f and 128.0f are constants
|
||||
const Drawing::scalar blurRadius =
|
||||
properties.GetShadowElevation() > 0.f
|
||||
? 0.25f * properties.GetShadowElevation() * (1 + properties.GetShadowElevation() / 128.0f)
|
||||
: properties.GetShadowRadius();
|
||||
// save layer, draw image with clipPath, blur and draw back
|
||||
Drawing::Brush blurBrush;
|
||||
Drawing::Filter filter;
|
||||
filter.SetImageFilter(
|
||||
Drawing::ImageFilter::CreateBlurImageFilter(blurRadius, blurRadius, Drawing::TileMode::DECAL, nullptr));
|
||||
blurBrush.SetFilter(filter);
|
||||
canvas.SaveLayer({ nullptr, &blurBrush });
|
||||
canvas.Translate(properties.GetShadowOffsetX(), properties.GetShadowOffsetY());
|
||||
canvas.ClipPath(path, Drawing::ClipOp::INTERSECT, false);
|
||||
// draw node content as shadow
|
||||
// [PLANNING]: maybe we should also draw background color / image here, and we should cache the shadow image
|
||||
return true;
|
||||
}
|
||||
|
||||
RSDrawable::Ptr RSMaskDrawable::OnGenerate(const RSRenderNode& node)
|
||||
{
|
||||
if (auto ret = std::make_shared<RSMaskDrawable>(); ret->OnUpdate(node)) {
|
||||
|
@ -2326,7 +2326,7 @@ float RSProperties::GetBackgroundBlurBrightness() const
|
||||
{
|
||||
return backgroundBlurBrightness_;
|
||||
}
|
||||
|
||||
|
||||
bool RSProperties::IsBackgroundBlurBrightnessValid() const
|
||||
{
|
||||
return (!ROSEN_EQ(GetBackgroundBlurBrightness(), 1.0f)) && ROSEN_GE(GetBackgroundBlurBrightness(), 0.0f);
|
||||
@ -2342,7 +2342,7 @@ void RSProperties::SetBackgroundBlurMaskColor(Color backgroundMaskColor)
|
||||
SetDirty();
|
||||
contentDirty_ = true;
|
||||
}
|
||||
|
||||
|
||||
const Color& RSProperties::GetBackgroundBlurMaskColor() const
|
||||
{
|
||||
return backgroundMaskColor_;
|
||||
@ -2360,12 +2360,12 @@ void RSProperties::SetBackgroundBlurColorMode(int backgroundColorMode)
|
||||
SetDirty();
|
||||
contentDirty_ = true;
|
||||
}
|
||||
|
||||
|
||||
int RSProperties::GetBackgroundBlurColorMode() const
|
||||
{
|
||||
return backgroundColorMode_;
|
||||
}
|
||||
|
||||
|
||||
void RSProperties::SetBackgroundBlurRadiusX(float backgroundBlurRadiusX)
|
||||
{
|
||||
backgroundBlurRadiusX_ = backgroundBlurRadiusX;
|
||||
@ -2381,7 +2381,7 @@ float RSProperties::GetBackgroundBlurRadiusX() const
|
||||
{
|
||||
return backgroundBlurRadiusX_;
|
||||
}
|
||||
|
||||
|
||||
bool RSProperties::IsBackgroundBlurRadiusXValid() const
|
||||
{
|
||||
return ROSEN_GNE(GetBackgroundBlurRadiusX(), 0.999f);
|
||||
@ -2397,12 +2397,12 @@ void RSProperties::SetBackgroundBlurRadiusY(float backgroundBlurRadiusY)
|
||||
SetDirty();
|
||||
contentDirty_ = true;
|
||||
}
|
||||
|
||||
|
||||
float RSProperties::GetBackgroundBlurRadiusY() const
|
||||
{
|
||||
return backgroundBlurRadiusY_;
|
||||
}
|
||||
|
||||
|
||||
bool RSProperties::IsBackgroundBlurRadiusYValid() const
|
||||
{
|
||||
return ROSEN_GNE(GetBackgroundBlurRadiusY(), 0.999f);
|
||||
@ -2439,7 +2439,7 @@ void RSProperties::SetForegroundBlurSaturation(float foregroundBlurSaturation)
|
||||
SetDirty();
|
||||
contentDirty_ = true;
|
||||
}
|
||||
|
||||
|
||||
float RSProperties::GetForegroundBlurSaturation() const
|
||||
{
|
||||
return foregroundBlurSaturation_;
|
||||
@ -2460,12 +2460,12 @@ void RSProperties::SetForegroundBlurBrightness(float foregroundBlurBrightness)
|
||||
SetDirty();
|
||||
contentDirty_ = true;
|
||||
}
|
||||
|
||||
|
||||
float RSProperties::GetForegroundBlurBrightness() const
|
||||
{
|
||||
return foregroundBlurBrightness_;
|
||||
}
|
||||
|
||||
|
||||
bool RSProperties::IsForegroundBlurBrightnessValid() const
|
||||
{
|
||||
return ROSEN_GE(GetForegroundBlurBrightness(), 1.0);
|
||||
@ -2481,7 +2481,7 @@ void RSProperties::SetForegroundBlurMaskColor(Color foregroundMaskColor)
|
||||
SetDirty();
|
||||
contentDirty_ = true;
|
||||
}
|
||||
|
||||
|
||||
const Color& RSProperties::GetForegroundBlurMaskColor() const
|
||||
{
|
||||
return foregroundMaskColor_;
|
||||
@ -2499,7 +2499,7 @@ void RSProperties::SetForegroundBlurColorMode(int foregroundColorMode)
|
||||
SetDirty();
|
||||
contentDirty_ = true;
|
||||
}
|
||||
|
||||
|
||||
int RSProperties::GetForegroundBlurColorMode() const
|
||||
{
|
||||
return foregroundColorMode_;
|
||||
@ -2520,7 +2520,7 @@ float RSProperties::GetForegroundBlurRadiusX() const
|
||||
{
|
||||
return foregroundBlurRadiusX_;
|
||||
}
|
||||
|
||||
|
||||
bool RSProperties::IsForegroundBlurRadiusXValid() const
|
||||
{
|
||||
return ROSEN_GNE(GetForegroundBlurRadiusX(), 0.999f);
|
||||
@ -2536,12 +2536,12 @@ void RSProperties::SetForegroundBlurRadiusY(float foregroundBlurRadiusY)
|
||||
SetDirty();
|
||||
contentDirty_ = true;
|
||||
}
|
||||
|
||||
|
||||
float RSProperties::GetForegroundBlurRadiusY() const
|
||||
{
|
||||
return foregroundBlurRadiusY_;
|
||||
}
|
||||
|
||||
|
||||
bool RSProperties::IsForegroundBlurRadiusYValid() const
|
||||
{
|
||||
return ROSEN_GNE(GetForegroundBlurRadiusY(), 0.999f);
|
||||
@ -2612,7 +2612,7 @@ void RSProperties::GenerateBackgroundBlurFilter()
|
||||
backgroundFilter_ = originalFilter;
|
||||
backgroundFilter_->SetFilterType(RSFilter::BLUR);
|
||||
}
|
||||
|
||||
|
||||
void RSProperties::GenerateBackgroundMaterialBlurFilter()
|
||||
{
|
||||
if (backgroundColorMode_ == BLUR_COLOR_MODE::FASTAVERAGE) {
|
||||
@ -2623,7 +2623,7 @@ void RSProperties::GenerateBackgroundMaterialBlurFilter()
|
||||
backgroundBlurSaturation_, backgroundBlurBrightness_);
|
||||
std::shared_ptr<Drawing::ImageFilter> blurColorFilter =
|
||||
Drawing::ImageFilter::CreateColorBlurImageFilter(*colorFilter, backgroundBlurRadius_, backgroundBlurRadius_);
|
||||
|
||||
|
||||
std::shared_ptr<RSDrawingFilter> originalFilter = nullptr;
|
||||
if (greyCoef_.has_value()) {
|
||||
std::shared_ptr<RSGreyShaderFilter> greyShaderFilter =
|
||||
@ -2659,7 +2659,7 @@ void RSProperties::GenerateBackgroundMaterialBlurFilter()
|
||||
maskColorShaderFilter->InitColorMod();
|
||||
backgroundFilter_->SetFilterType(RSFilter::MATERIAL);
|
||||
}
|
||||
|
||||
|
||||
void RSProperties::GenerateForegroundBlurFilter()
|
||||
{
|
||||
std::shared_ptr<Drawing::ImageFilter> blurFilter = Drawing::ImageFilter::CreateBlurImageFilter(
|
||||
@ -2697,7 +2697,7 @@ void RSProperties::GenerateForegroundBlurFilter()
|
||||
filter_ = originalFilter;
|
||||
filter_->SetFilterType(RSFilter::BLUR);
|
||||
}
|
||||
|
||||
|
||||
void RSProperties::GenerateForegroundMaterialBlurFilter()
|
||||
{
|
||||
if (foregroundColorMode_ == BLUR_COLOR_MODE::FASTAVERAGE) {
|
||||
@ -2708,9 +2708,9 @@ void RSProperties::GenerateForegroundMaterialBlurFilter()
|
||||
foregroundBlurSaturation_, foregroundBlurBrightness_);
|
||||
std::shared_ptr<Drawing::ImageFilter> blurColorFilter =
|
||||
Drawing::ImageFilter::CreateColorBlurImageFilter(*colorFilter, foregroundBlurRadius_, foregroundBlurRadius_);
|
||||
|
||||
|
||||
std::shared_ptr<RSDrawingFilter> originalFilter = nullptr;
|
||||
|
||||
|
||||
if (greyCoef_.has_value()) {
|
||||
std::shared_ptr<RSGreyShaderFilter> greyShaderFilter =
|
||||
std::make_shared<RSGreyShaderFilter>(greyCoef_->x_, greyCoef_->y_);
|
||||
@ -2777,11 +2777,11 @@ void RSProperties::GenerateLinearGradientBlurFilter()
|
||||
auto linearBlurFilter = std::make_shared<RSLinearGradientBlurShaderFilter>(linearGradientBlurPara_,
|
||||
frameGeo_->GetWidth(), frameGeo_->GetHeight());
|
||||
std::shared_ptr<RSDrawingFilter> originalFilter = std::make_shared<RSDrawingFilter>(linearBlurFilter);
|
||||
|
||||
|
||||
filter_ = originalFilter;
|
||||
filter_->SetFilterType(RSFilter::LINEAR_GRADIENT_BLUR);
|
||||
}
|
||||
|
||||
|
||||
void RSProperties::GenerateBackgroundFilter()
|
||||
{
|
||||
if (aiInvert_.has_value() || systemBarEffect_) {
|
||||
@ -2797,7 +2797,7 @@ void RSProperties::GenerateBackgroundFilter()
|
||||
ROSEN_LOGD("RSProperties::GenerateBackgroundFilter failed");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void RSProperties::GenerateForegroundFilter()
|
||||
{
|
||||
IfLinearGradientBlurInvalid();
|
||||
@ -3923,6 +3923,18 @@ void RSProperties::UpdateFilter()
|
||||
if (filter_ != nullptr && !filter_->IsValid()) {
|
||||
filter_.reset();
|
||||
}
|
||||
|
||||
UpdateForegroundFilter();
|
||||
|
||||
needFilter_ = backgroundFilter_ != nullptr || filter_ != nullptr || useEffect_ || IsLightUpEffectValid() ||
|
||||
IsDynamicLightUpValid() || greyCoef_.has_value() || linearGradientBlurPara_ != nullptr ||
|
||||
IsDynamicDimValid() || GetShadowColorStrategy() != SHADOW_COLOR_STRATEGY::COLOR_STRATEGY_NONE ||
|
||||
foregroundFilter_ != nullptr || motionBlurPara_ != nullptr || IsFgBrightnessValid() ||
|
||||
IsBgBrightnessValid() || foregroundFilterCache_ != nullptr;
|
||||
}
|
||||
|
||||
void RSProperties::UpdateForegroundFilter()
|
||||
{
|
||||
if (IsForegroundEffectRadiusValid()) {
|
||||
auto foregroundEffectFilter = std::make_shared<RSForegroundEffectFilter>(foregroundEffectRadius_);
|
||||
if (IS_UNI_RENDER) {
|
||||
@ -3938,12 +3950,15 @@ void RSProperties::UpdateFilter()
|
||||
foregroundFilter_ = spherizeEffectFilter;
|
||||
}
|
||||
} else if (GetShadowMask()) {
|
||||
foregroundFilter_.reset();
|
||||
float elevation = GetShadowElevation();
|
||||
Drawing::scalar n1 = 0.25f * elevation * (1 + elevation / 128.0f); // 0.25f 128.0f
|
||||
Drawing::scalar blurRadius = elevation > 0.0f ? n1 : GetShadowRadius();
|
||||
auto colorfulShadowFilter =
|
||||
std::make_shared<RSColorfulShadowFilter>(blurRadius, GetShadowOffsetX(), GetShadowOffsetY());
|
||||
foregroundFilter_ = colorfulShadowFilter;
|
||||
if (ROSEN_GE(blurRadius, 1.0)) {
|
||||
auto colorfulShadowFilter =
|
||||
std::make_shared<RSColorfulShadowFilter>(blurRadius, GetShadowOffsetX(), GetShadowOffsetY());
|
||||
foregroundFilter_ = colorfulShadowFilter;
|
||||
}
|
||||
} else {
|
||||
foregroundFilter_.reset();
|
||||
foregroundFilterCache_.reset();
|
||||
@ -3952,11 +3967,6 @@ void RSProperties::UpdateFilter()
|
||||
auto motionBlurFilter = std::make_shared<RSMotionBlurFilter>(motionBlurPara_);
|
||||
foregroundFilter_ = motionBlurFilter;
|
||||
}
|
||||
needFilter_ = backgroundFilter_ != nullptr || filter_ != nullptr || useEffect_ || IsLightUpEffectValid() ||
|
||||
IsDynamicLightUpValid() || greyCoef_.has_value() || linearGradientBlurPara_ != nullptr ||
|
||||
IsDynamicDimValid() || GetShadowColorStrategy() != SHADOW_COLOR_STRATEGY::COLOR_STRATEGY_NONE ||
|
||||
foregroundFilter_ != nullptr || motionBlurPara_ != nullptr || IsFgBrightnessValid() ||
|
||||
IsBgBrightnessValid() || foregroundFilterCache_ != nullptr;
|
||||
}
|
||||
|
||||
void RSProperties::CalculatePixelStretch()
|
||||
|
@ -42,6 +42,11 @@ bool RSColorfulShadowFilter::IsValid() const
|
||||
void RSColorfulShadowFilter::DrawImageRect(Drawing::Canvas &canvas, const std::shared_ptr<Drawing::Image> &image,
|
||||
const Drawing::Rect &src, const Drawing::Rect &dst) const
|
||||
{
|
||||
if (image == nullptr) {
|
||||
ROSEN_LOGE("RSColorfulShadowFilter::DrawImageRect error");
|
||||
return;
|
||||
}
|
||||
|
||||
// draw blur image
|
||||
canvas.Translate(offsetX_, offsetY_);
|
||||
RSForegroundEffectFilter::DrawImageRect(canvas, image, src, dst);
|
||||
|
Loading…
Reference in New Issue
Block a user