From 57617f2ad8f17e9305d499d9100f2fca133154e2 Mon Sep 17 00:00:00 2001 From: lee Date: Mon, 14 Feb 2022 19:46:12 +0800 Subject: [PATCH] add ipc for rsFilter Signed-off-by: lee Change-Id: Ie12b5d65b0aa7d0928880856717597c97f353495 --- .../include/render/rs_filter.h | 17 ++++---- .../transaction/rs_marshalling_helper.h | 3 ++ .../src/animation/rs_value_estimator.cpp | 8 ++-- .../src/render/rs_blur_filter.cpp | 6 +-- .../src/render/rs_filter.cpp | 2 +- .../src/transaction/rs_marshalling_helper.cpp | 41 +++++++++++++++++++ 6 files changed, 61 insertions(+), 16 deletions(-) diff --git a/rosen/modules/render_service_base/include/render/rs_filter.h b/rosen/modules/render_service_base/include/render/rs_filter.h index 691f14dc42..0d88e00c81 100644 --- a/rosen/modules/render_service_base/include/render/rs_filter.h +++ b/rosen/modules/render_service_base/include/render/rs_filter.h @@ -22,24 +22,25 @@ namespace OHOS { namespace Rosen { -enum class FilterAnimType { - UNANIMATABLE, - BLUR, -}; class RS_EXPORT RSFilter : public std::enable_shared_from_this { public: virtual ~RSFilter(); static std::shared_ptr CreateBlurFilter(float blurRadiusX, float blurRadiusY); - FilterAnimType GetFilterAnimType() const + + enum FilterType { + NONE = 0, + BLUR, + }; + FilterType GetFilterType() const { return type_; } - bool IsAnimatable() const + bool IsValid() const { - return type_ != FilterAnimType::UNANIMATABLE; + return type_ != FilterType::NONE; } protected: - FilterAnimType type_; + FilterType type_; RSFilter(); virtual std::shared_ptr Add(const std::shared_ptr& rhs) { return nullptr; } virtual std::shared_ptr Sub(const std::shared_ptr& rhs) { return nullptr; } diff --git a/rosen/modules/render_service_base/include/transaction/rs_marshalling_helper.h b/rosen/modules/render_service_base/include/transaction/rs_marshalling_helper.h index 0a5ee2a2fa..5aeec12bfa 100644 --- a/rosen/modules/render_service_base/include/transaction/rs_marshalling_helper.h +++ b/rosen/modules/render_service_base/include/transaction/rs_marshalling_helper.h @@ -16,6 +16,7 @@ #ifndef RENDER_SERVICE_BASE_TRANSACTION_RS_MARSHALLING_HELPER_H #define RENDER_SERVICE_BASE_TRANSACTION_RS_MARSHALLING_HELPER_H +#include #ifdef ROSEN_OHOS #include @@ -30,6 +31,7 @@ class SkPath; namespace OHOS { namespace Rosen { +class RSFilter; class RSPath; class RSShader; template @@ -82,6 +84,7 @@ public: DECLARE_FUNCTION_OVERLOAD(SkPath) DECLARE_FUNCTION_OVERLOAD(RSShader) DECLARE_FUNCTION_OVERLOAD(RSPath) + DECLARE_FUNCTION_OVERLOAD(std::shared_ptr) // animation DECLARE_FUNCTION_OVERLOAD(std::shared_ptr) DECLARE_FUNCTION_OVERLOAD(std::shared_ptr) diff --git a/rosen/modules/render_service_base/src/animation/rs_value_estimator.cpp b/rosen/modules/render_service_base/src/animation/rs_value_estimator.cpp index 4dc264137d..a7b8404014 100644 --- a/rosen/modules/render_service_base/src/animation/rs_value_estimator.cpp +++ b/rosen/modules/render_service_base/src/animation/rs_value_estimator.cpp @@ -29,19 +29,19 @@ Quaternion RSValueEstimator::Estimate(float fraction, const Quaternion& startVal std::shared_ptr RSValueEstimator::Estimate( float fraction, const std::shared_ptr& startValue, const std::shared_ptr& endValue) { - if ((startValue == nullptr || !startValue->IsAnimatable()) && (endValue == nullptr || !endValue->IsAnimatable())) { + if ((startValue == nullptr || !startValue->IsValid()) && (endValue == nullptr || !endValue->IsValid())) { return endValue; } - if (startValue == nullptr || !startValue->IsAnimatable()) { + if (startValue == nullptr || !startValue->IsValid()) { return endValue * fraction; } - if (endValue == nullptr || !endValue->IsAnimatable()) { + if (endValue == nullptr || !endValue->IsValid()) { return (fraction < 0.5f) ? startValue * (1.0f - fraction * 2) : endValue; } - if (startValue->GetFilterAnimType() == endValue->GetFilterAnimType()) { + if (startValue->GetFilterType() == endValue->GetFilterType()) { return startValue * (1.0f - fraction) + endValue * fraction; } else { return (fraction < 0.5f) ? startValue * (1.0f - fraction * 2) : endValue * (fraction * 2 - 1.0f); diff --git a/rosen/modules/render_service_base/src/render/rs_blur_filter.cpp b/rosen/modules/render_service_base/src/render/rs_blur_filter.cpp index 2b85c6c174..8c378901f6 100644 --- a/rosen/modules/render_service_base/src/render/rs_blur_filter.cpp +++ b/rosen/modules/render_service_base/src/render/rs_blur_filter.cpp @@ -22,7 +22,7 @@ RSBlurFilter::RSBlurFilter(float blurRadiusX, float blurRadiusY) : RSSkiaFilter(SkBlurImageFilter::Make(blurRadiusX, blurRadiusY, nullptr)), blurRadiusX_(blurRadiusX), blurRadiusY_(blurRadiusY) { - type_ = FilterAnimType::BLUR; + type_ = FilterType::BLUR; } RSBlurFilter::~RSBlurFilter() {} @@ -39,7 +39,7 @@ float RSBlurFilter::GetBlurRadiusY() std::shared_ptr RSBlurFilter::Add(const std::shared_ptr& rhs) { - if ((rhs == nullptr) || (rhs->GetFilterAnimType() != FilterAnimType::BLUR)) { + if ((rhs == nullptr) || (rhs->GetFilterType() != FilterType::BLUR)) { return shared_from_this(); } auto blurR = std::static_pointer_cast(rhs); @@ -49,7 +49,7 @@ std::shared_ptr RSBlurFilter::Add(const std::shared_ptr& rhs std::shared_ptr RSBlurFilter::Sub(const std::shared_ptr& rhs) { - if ((rhs == nullptr) || (rhs->GetFilterAnimType() != FilterAnimType::BLUR)) { + if ((rhs == nullptr) || (rhs->GetFilterType() != FilterType::BLUR)) { return shared_from_this(); } auto blurR = std::static_pointer_cast(rhs); diff --git a/rosen/modules/render_service_base/src/render/rs_filter.cpp b/rosen/modules/render_service_base/src/render/rs_filter.cpp index b88e49c2be..4be33c3642 100644 --- a/rosen/modules/render_service_base/src/render/rs_filter.cpp +++ b/rosen/modules/render_service_base/src/render/rs_filter.cpp @@ -23,7 +23,7 @@ namespace OHOS { namespace Rosen { RSFilter::RSFilter() - : type_(FilterAnimType::UNANIMATABLE) + : type_(FilterType::NONE) {} RSFilter::~RSFilter() {} diff --git a/rosen/modules/render_service_base/src/transaction/rs_marshalling_helper.cpp b/rosen/modules/render_service_base/src/transaction/rs_marshalling_helper.cpp index 59b658ee7d..07532097b2 100644 --- a/rosen/modules/render_service_base/src/transaction/rs_marshalling_helper.cpp +++ b/rosen/modules/render_service_base/src/transaction/rs_marshalling_helper.cpp @@ -23,12 +23,15 @@ #include "common/rs_matrix3.h" #include "common/rs_vector4.h" #include "include/core/SkPaint.h" +#include "render/rs_blur_filter.h" +#include "render/rs_filter.h" #include "render/rs_path.h" #include "render/rs_shader.h" #include "src/core/SkAutoMalloc.h" #include "src/core/SkPaintPriv.h" #include "src/core/SkReadBuffer.h" #include "src/core/SkWriteBuffer.h" +#include #ifdef ROSEN_OHOS namespace OHOS { @@ -159,6 +162,44 @@ bool RSMarshallingHelper::Unmarshalling(Parcel& parcel, RSPath& val) return true; } +// RSFilter +bool RSMarshallingHelper::Marshalling(Parcel& parcel, const std::shared_ptr& val) +{ + if (!val) { + return parcel.WriteInt32(RSFilter::NONE); + } + bool success = parcel.WriteInt32(static_cast(val->GetFilterType())); + switch (val->GetFilterType()) { + case RSFilter::BLUR: { + auto blur = std::static_pointer_cast(val); + success &= parcel.WriteFloat(blur->GetBlurRadiusX()); + success &= parcel.WriteFloat(blur->GetBlurRadiusY()); + break; + } + default: + break; + } + return success; +} +bool RSMarshallingHelper::Unmarshalling(Parcel& parcel, std::shared_ptr& val) +{ + int type = 0; + bool success = parcel.ReadInt32(type); + switch (static_cast(type)) { + case RSFilter::BLUR: { + float blurRadiusX; + float blurRadiusY; + success &= parcel.ReadFloat(blurRadiusX); + success &= parcel.ReadFloat(blurRadiusY); + break; + } + default: + val = nullptr; + break; + } + return success; +} + #define MARSHALLING_AND_UNMARSHALLING(TYPE) \ bool RSMarshallingHelper::Marshalling(Parcel& parcel, const std::shared_ptr& val) \ { \