diff --git a/rosen/modules/render_service_base/include/animation/rs_animation_manager.h b/rosen/modules/render_service_base/include/animation/rs_animation_manager.h index 4c509ace6b..1d08a7986c 100644 --- a/rosen/modules/render_service_base/include/animation/rs_animation_manager.h +++ b/rosen/modules/render_service_base/include/animation/rs_animation_manager.h @@ -30,10 +30,11 @@ class RSPaintFilterCanvas; class RSProperties; class RSRenderAnimation; class RSRenderNode; +class RSTransitionProperties; class RSAnimationManager { public: - using TransitionCallback = std::function; + using TransitionCallback = std::function& transitionProperties)>; RSAnimationManager() = default; ~RSAnimationManager() = default; @@ -45,7 +46,7 @@ public: void RegisterTransition(AnimationId id, const TransitionCallback& transition); void UnregisterTransition(AnimationId id); - void DoTransition(RSPaintFilterCanvas& canvas, const RSProperties& renderProperties); + std::unique_ptr GetTransitionProperties(); bool HasTransition() const; private: diff --git a/rosen/modules/render_service_base/include/animation/rs_render_transition_effect.h b/rosen/modules/render_service_base/include/animation/rs_render_transition_effect.h index c43e62a093..109f10996a 100644 --- a/rosen/modules/render_service_base/include/animation/rs_render_transition_effect.h +++ b/rosen/modules/render_service_base/include/animation/rs_render_transition_effect.h @@ -30,6 +30,7 @@ namespace Rosen { class RSCanvasRenderNode; class RSPaintFilterCanvas; class RSProperties; +class RSTransitionProperties; #ifdef ROSEN_OHOS class RSRenderTransitionEffect : public Parcelable { @@ -39,7 +40,7 @@ class RSRenderTransitionEffect { public: RSRenderTransitionEffect() = default; virtual ~RSRenderTransitionEffect() = default; - virtual void OnTransition(RSPaintFilterCanvas& canvas, const RSProperties& renderProperties, float fraction) = 0; + virtual void OnTransition(const std::unique_ptr& transitionProperties, float fraction) = 0; #ifdef ROSEN_OHOS virtual bool Marshalling(Parcel& parcel) const override = 0; @@ -53,7 +54,7 @@ class RSTransitionFade : public RSRenderTransitionEffect { public: explicit RSTransitionFade(float alpha) : alpha_(alpha = 0.0f) {} virtual ~RSTransitionFade() = default; - void OnTransition(RSPaintFilterCanvas& canvas, const RSProperties& renderProperties, float fraction) override; + void OnTransition(const std::unique_ptr& transitionProperties, float fraction) override; #ifdef ROSEN_OHOS bool Marshalling(Parcel& parcel) const override; @@ -66,12 +67,11 @@ private: class RSTransitionScale : public RSRenderTransitionEffect { public: RSTransitionScale() = default; - explicit RSTransitionScale( - float scaleX = 0.0f, float scaleY = 0.0f, float scaleZ = 0.0f, float pivotX = 0.5, float pivotY = 0.5) - : scaleX_(scaleX), scaleY_(scaleY), scaleZ_(scaleZ), pivotX_(pivotX), pivotY_(pivotY) + explicit RSTransitionScale(float scaleX = 0.0f, float scaleY = 0.0f, float scaleZ = 0.0f) + : scaleX_(scaleX), scaleY_(scaleY), scaleZ_(scaleZ) {} virtual ~RSTransitionScale() = default; - void OnTransition(RSPaintFilterCanvas& canvas, const RSProperties& renderProperties, float fraction) override; + void OnTransition(const std::unique_ptr& transitionProperties, float fraction) override; #ifdef ROSEN_OHOS bool Marshalling(Parcel& parcel) const override; @@ -81,8 +81,6 @@ private: float scaleX_; float scaleY_; float scaleZ_; - float pivotX_; - float pivotY_; }; class RSTransitionTranslate : public RSRenderTransitionEffect { @@ -92,7 +90,7 @@ public: : translateX_(translateX), translateY_(translateY), translateZ_(translateZ) {} virtual ~RSTransitionTranslate() = default; - void OnTransition(RSPaintFilterCanvas& canvas, const RSProperties& renderProperties, float fraction) override; + void OnTransition(const std::unique_ptr& transitionProperties, float fraction) override; #ifdef ROSEN_OHOS bool Marshalling(Parcel& parcel) const override; @@ -107,11 +105,9 @@ private: class RSTransitionRotate : public RSRenderTransitionEffect { public: RSTransitionRotate() = default; - explicit RSTransitionRotate(float dx, float dy, float dz, float angle, float pivotX = 0.5, float pivotY = 0.5) - : dx_(dx), dy_(dy), dz_(dz), angle_(angle), pivotX_(pivotX), pivotY_(pivotY) - {} + explicit RSTransitionRotate(float dx, float dy, float dz, float angle) : dx_(dx), dy_(dy), dz_(dz), angle_(angle) {} virtual ~RSTransitionRotate() = default; - void OnTransition(RSPaintFilterCanvas& canvas, const RSProperties& renderProperties, float fraction) override; + void OnTransition(const std::unique_ptr& transitionProperties, float fraction) override; #ifdef ROSEN_OHOS bool Marshalling(Parcel& parcel) const override; @@ -122,8 +118,6 @@ private: float dy_; float dz_; float angle_; - float pivotX_; - float pivotY_; }; } // namespace Rosen } // namespace OHOS diff --git a/rosen/modules/render_service_base/include/animation/rs_transition_effect.h b/rosen/modules/render_service_base/include/animation/rs_transition_effect.h index 7fdd964d69..3414b6ddd4 100644 --- a/rosen/modules/render_service_base/include/animation/rs_transition_effect.h +++ b/rosen/modules/render_service_base/include/animation/rs_transition_effect.h @@ -20,7 +20,6 @@ #include #include "common/rs_macros.h" -#include "common/rs_vector2.h" #include "common/rs_vector3.h" #include "common/rs_vector4.h" @@ -42,9 +41,9 @@ public: const std::shared_ptr& transitionOut); std::shared_ptr Opacity(float opacity = 0.0f); - std::shared_ptr Scale(const Vector3f& scale, const Vector2f& pivot = { 0.5f, 0.5f }); + std::shared_ptr Scale(const Vector3f& scale); std::shared_ptr Translate(const Vector3f& translate); - std::shared_ptr Rotate(const Vector4f& axisAngle, const Vector2f& pivot = { 0.5f, 0.5f }); + std::shared_ptr Rotate(const Vector4f& axisAngle); private: RSTransitionEffect() = default; diff --git a/rosen/modules/render_service_base/include/common/rs_vector3.h b/rosen/modules/render_service_base/include/common/rs_vector3.h index 73ab95e302..2e56340698 100644 --- a/rosen/modules/render_service_base/include/common/rs_vector3.h +++ b/rosen/modules/render_service_base/include/common/rs_vector3.h @@ -17,7 +17,7 @@ #define RENDER_SERVICE_CLIENT_CORE_COMMON_RS_VECTOR3_H #include -#include "common/rs_macros.h" +#include "common/rs_common_def.h" namespace OHOS { namespace Rosen { diff --git a/rosen/modules/render_service_base/include/pipeline/rs_surface_render_node.h b/rosen/modules/render_service_base/include/pipeline/rs_surface_render_node.h index 1c556fa922..bc09904237 100644 --- a/rosen/modules/render_service_base/include/pipeline/rs_surface_render_node.h +++ b/rosen/modules/render_service_base/include/pipeline/rs_surface_render_node.h @@ -20,14 +20,14 @@ #include #include "display_type.h" - -#include "pipeline/rs_render_node.h" #include "ipc_callbacks/buffer_available_callback.h" +#include "pipeline/rs_render_node.h" #include "refbase.h" class SkCanvas; namespace OHOS { namespace Rosen { +class RSCommand; class RSSurfaceRenderNode : public RSRenderNode { public: using WeakPtr = std::weak_ptr; diff --git a/rosen/modules/render_service_base/include/property/rs_properties.h b/rosen/modules/render_service_base/include/property/rs_properties.h index 03697dcf38..48f5760786 100644 --- a/rosen/modules/render_service_base/include/property/rs_properties.h +++ b/rosen/modules/render_service_base/include/property/rs_properties.h @@ -18,7 +18,6 @@ #include -#include "command/rs_command.h" #include "common/rs_matrix3.h" #include "common/rs_vector4.h" #include "property/rs_properties_def.h" diff --git a/rosen/modules/render_service_base/include/property/rs_properties_painter.h b/rosen/modules/render_service_base/include/property/rs_properties_painter.h index f189cae8e3..c588094200 100644 --- a/rosen/modules/render_service_base/include/property/rs_properties_painter.h +++ b/rosen/modules/render_service_base/include/property/rs_properties_painter.h @@ -16,13 +16,15 @@ #ifndef RENDER_SERVICE_CLIENT_CORE_PROPERTY_RS_PROPERTIES_PAINTER_H #define RENDER_SERVICE_CLIENT_CORE_PROPERTY_RS_PROPERTIES_PAINTER_H -#include "pipeline/rs_draw_cmd_list.h" #include "property/rs_properties.h" namespace OHOS { namespace Rosen { +class DrawCmdList; class RSSkiaFilter; class RSPaintFilterCanvas; +class RSTransitionProperties; + class RSPropertiesPainter { public: static void Clip(SkCanvas& canvas, RectF rect); @@ -35,6 +37,8 @@ public: const RSProperties& properties, SkCanvas& canvas, std::shared_ptr& filter); static void RestoreForFilter(SkCanvas& canvas); static void DrawForegroundColor(const RSProperties& properties, SkCanvas& canvas); + static void DrawTransitionProperties(const std::unique_ptr& transitionProperties, + const RSProperties& properties, RSPaintFilterCanvas& canvas); }; } // namespace Rosen } // namespace OHOS diff --git a/rosen/modules/render_service_base/include/property/rs_transition_properties.h b/rosen/modules/render_service_base/include/property/rs_transition_properties.h new file mode 100644 index 0000000000..674b767c94 --- /dev/null +++ b/rosen/modules/render_service_base/include/property/rs_transition_properties.h @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2021 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_PROPERTY_RS_TRANSITION_PROPERTIES_H +#define RENDER_SERVICE_CLIENT_CORE_PROPERTY_RS_TRANSITION_PROPERTIES_H + +#include + +#include "common/rs_vector3.h" +#include "include/core/SkMatrix44.h" + +namespace OHOS { +namespace Rosen { +class RSTransitionProperties final { +public: + RSTransitionProperties() = default; + ~RSTransitionProperties() = default; + + void DoAlphaTransition(float alpha) + { + alpha_ *= alpha; + } + void DoTranslateTransition(const Vector3f& translate) + { + translate_ += translate; + } + void DoScaleTransition(const Vector3f& scale) + { + scale_ *= scale; + } + void DoRotateTransition(const SkMatrix44& rotateMatrix) + { + rotate_.postConcat(rotateMatrix); + } + + float GetAlpha() const + { + return alpha_; + } + Vector3f GetTranslate() const + { + return translate_; + } + Vector3f GetScale() const + { + return scale_; + } + SkMatrix44 GetRotate() const + { + return rotate_; + } + +private: + float alpha_ = 1.0f; + Vector3f translate_ = { 0.0f, 0.0f, 0.0f }; + Vector3f scale_ = { 1.0f, 1.0f, 1.0f }; + SkMatrix44 rotate_ = SkMatrix44::I(); +}; +} // namespace Rosen +} // namespace OHOS + +#endif // RENDER_SERVICE_CLIENT_CORE_PROPERTY_RS_TRANSITION_PROPERTIES_H 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 606357b909..0a5ee2a2fa 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 @@ -59,11 +59,12 @@ public: return false; } - // specialized marshalling & unmarshalling function for certain types + // reloaded marshalling & unmarshalling function for types #define DECLARE_FUNCTION_OVERLOAD(TYPE) \ static bool Marshalling(Parcel& parcel, const TYPE& val); \ static bool Unmarshalling(Parcel& parcel, TYPE& val); + // basic types DECLARE_FUNCTION_OVERLOAD(bool) DECLARE_FUNCTION_OVERLOAD(int8_t) DECLARE_FUNCTION_OVERLOAD(uint8_t) @@ -75,16 +76,19 @@ public: DECLARE_FUNCTION_OVERLOAD(uint64_t) DECLARE_FUNCTION_OVERLOAD(float) DECLARE_FUNCTION_OVERLOAD(double) + // skia types DECLARE_FUNCTION_OVERLOAD(sk_sp) DECLARE_FUNCTION_OVERLOAD(sk_sp) DECLARE_FUNCTION_OVERLOAD(SkPath) DECLARE_FUNCTION_OVERLOAD(RSShader) DECLARE_FUNCTION_OVERLOAD(RSPath) + // animation DECLARE_FUNCTION_OVERLOAD(std::shared_ptr) DECLARE_FUNCTION_OVERLOAD(std::shared_ptr) DECLARE_FUNCTION_OVERLOAD(std::shared_ptr) #undef DECLARE_FUNCTION_OVERLOAD + // reloaded marshalling & unmarshalling function for animation template #define DECLARE_TEMPLATE_OVERLOAD(TEMPLATE) \ template \ static bool Marshalling(Parcel& parcel, const std::shared_ptr>& val); \ @@ -95,6 +99,7 @@ public: DECLARE_TEMPLATE_OVERLOAD(RSRenderKeyframeAnimation) #undef DECLARE_TEMPLATE_OVERLOAD + // reloaded marshalling & unmarshalling function for std::vector template static bool Marshalling(Parcel& parcel, const std::vector& val); template diff --git a/rosen/modules/render_service_base/src/animation/rs_animation_manager.cpp b/rosen/modules/render_service_base/src/animation/rs_animation_manager.cpp index 10a187a75f..95477a6e5e 100644 --- a/rosen/modules/render_service_base/src/animation/rs_animation_manager.cpp +++ b/rosen/modules/render_service_base/src/animation/rs_animation_manager.cpp @@ -24,8 +24,8 @@ #include "pipeline/rs_dirty_region_manager.h" #include "pipeline/rs_paint_filter_canvas.h" #include "pipeline/rs_render_node.h" -#include "pipeline/rs_render_node_map.h" #include "platform/common/rs_log.h" +#include "property/rs_transition_properties.h" namespace OHOS { namespace Rosen { @@ -134,16 +134,18 @@ void RSAnimationManager::ClearTransition(AnimationId id) }); } -void RSAnimationManager::DoTransition(RSPaintFilterCanvas& canvas, const RSProperties& renderProperties) +std::unique_ptr RSAnimationManager::GetTransitionProperties() { if (transition_.empty()) { - return; + return nullptr; } + auto transitionProperties = std::make_unique(); for (auto& [animationId, transition] : transition_) { if (transition != nullptr) { - transition(canvas, renderProperties); + transition(transitionProperties); } } + return transitionProperties; } bool RSAnimationManager::HasTransition() const diff --git a/rosen/modules/render_service_base/src/animation/rs_render_transition.cpp b/rosen/modules/render_service_base/src/animation/rs_render_transition.cpp index 949892c1ec..3db7b0b0bf 100644 --- a/rosen/modules/render_service_base/src/animation/rs_render_transition.cpp +++ b/rosen/modules/render_service_base/src/animation/rs_render_transition.cpp @@ -16,7 +16,7 @@ #include "animation/rs_render_transition.h" #include "animation/rs_transition_effect.h" -#include "pipeline/rs_canvas_render_node.h" +#include "pipeline/rs_render_node.h" #include "platform/common/rs_log.h" #include "transaction/rs_marshalling_helper.h" @@ -100,9 +100,9 @@ void RSRenderTransition::OnAttach() return; } target->GetAnimationManager().RegisterTransition( - GetAnimationId(), [=](RSPaintFilterCanvas& canvas, const RSProperties& renderProperties) { + GetAnimationId(), [=](const std::unique_ptr& transitionProperties) { for (auto& effect : effects_) { - effect->OnTransition(canvas, renderProperties, currentFraction_); + effect->OnTransition(transitionProperties, currentFraction_); } }); } diff --git a/rosen/modules/render_service_base/src/animation/rs_render_transition_effect.cpp b/rosen/modules/render_service_base/src/animation/rs_render_transition_effect.cpp index 62315fd133..a736585b08 100644 --- a/rosen/modules/render_service_base/src/animation/rs_render_transition_effect.cpp +++ b/rosen/modules/render_service_base/src/animation/rs_render_transition_effect.cpp @@ -17,9 +17,8 @@ #include "animation/rs_animation_common.h" #include "animation/rs_value_estimator.h" -#include "pipeline/rs_canvas_render_node.h" -#include "pipeline/rs_paint_filter_canvas.h" #include "platform/common/rs_log.h" +#include "property/rs_transition_properties.h" #include "transaction/rs_marshalling_helper.h" namespace OHOS { @@ -80,8 +79,7 @@ RSRenderTransitionEffect* RSTransitionFade::Unmarshalling(Parcel& parcel) bool RSTransitionScale::Marshalling(Parcel& parcel) const { return parcel.WriteUint16(RSTransitionEffectType::SCALE) && parcel.WriteFloat(scaleX_) && - parcel.WriteFloat(scaleY_) && parcel.WriteFloat(scaleZ_) && parcel.WriteFloat(pivotX_) && - parcel.WriteFloat(pivotY_); + parcel.WriteFloat(scaleY_) && parcel.WriteFloat(scaleZ_); } RSRenderTransitionEffect* RSTransitionScale::Unmarshalling(Parcel& parcel) @@ -89,14 +87,11 @@ RSRenderTransitionEffect* RSTransitionScale::Unmarshalling(Parcel& parcel) float scaleX; float scaleY; float scaleZ; - float pivotX; - float pivotY; - if (!parcel.ReadFloat(scaleX) || !parcel.ReadFloat(scaleY) || !parcel.ReadFloat(scaleZ) || - !parcel.ReadFloat(pivotX) || !parcel.ReadFloat(pivotY)) { + if (!parcel.ReadFloat(scaleX) || !parcel.ReadFloat(scaleY) || !parcel.ReadFloat(scaleZ)) { ROSEN_LOGE("RSTransitionScale::Unmarshalling, unmarshalling failed"); return nullptr; } - return new RSTransitionScale(scaleX, scaleY, scaleZ, pivotX, pivotY); + return new RSTransitionScale(scaleX, scaleY, scaleZ); } bool RSTransitionTranslate::Marshalling(Parcel& parcel) const @@ -120,8 +115,7 @@ RSRenderTransitionEffect* RSTransitionTranslate::Unmarshalling(Parcel& parcel) bool RSTransitionRotate::Marshalling(Parcel& parcel) const { return parcel.WriteUint16(RSTransitionEffectType::ROTATE) && parcel.WriteFloat(dx_) && parcel.WriteFloat(dy_) && - parcel.WriteFloat(dz_) && parcel.WriteFloat(angle_) && parcel.WriteFloat(pivotX_) && - parcel.WriteFloat(pivotY_); + parcel.WriteFloat(dz_) && parcel.WriteFloat(angle_); } RSRenderTransitionEffect* RSTransitionRotate::Unmarshalling(Parcel& parcel) @@ -131,62 +125,53 @@ RSRenderTransitionEffect* RSTransitionRotate::Unmarshalling(Parcel& parcel) float dy; float dz; float angle; - float pivotX; - float pivotY; - if (!parcel.ReadFloat(dx) || !parcel.ReadFloat(dy) || !parcel.ReadFloat(dz) || !parcel.ReadFloat(angle) || - !parcel.ReadFloat(pivotX) || !parcel.ReadFloat(pivotY)) { + if (!parcel.ReadFloat(dx) || !parcel.ReadFloat(dy) || !parcel.ReadFloat(dz) || !parcel.ReadFloat(angle)) { ROSEN_LOGE("RSTransitionRotate::Unmarshalling, unmarshalling failed"); return nullptr; } - return new RSTransitionRotate(dx, dy, dz, angle, pivotX, pivotY); + return new RSTransitionRotate(dx, dy, dz, angle); } #endif -void RSTransitionFade::OnTransition(RSPaintFilterCanvas& canvas, const RSProperties& renderProperties, float fraction) +void RSTransitionFade::OnTransition(const std::unique_ptr& transitionProperties, float fraction) { #ifdef ROSEN_OHOS - canvas.MultiplyAlpha(1.0f - fraction); + transitionProperties->DoAlphaTransition(1.0f - fraction); #endif } -void RSTransitionScale::OnTransition(RSPaintFilterCanvas& canvas, const RSProperties& renderProperties, float fraction) +void RSTransitionScale::OnTransition( + const std::unique_ptr& transitionProperties, float fraction) { #ifdef ROSEN_OHOS - Vector2f startValue(1.0f, 1.0f); - Vector2f endValue(scaleX_, scaleY_); + Vector3f startValue(1.0f, 1.0f, 1.0f); + Vector3f endValue(scaleX_, scaleY_, scaleZ_); auto value = RSValueEstimator::Estimate(fraction, startValue, endValue); - SkMatrix matrix; - Vector2f pivot { renderProperties.GetBoundsWidth() * pivotX_, renderProperties.GetBoundsHeight() * pivotY_ }; - matrix.setScale(value.x_, value.y_, pivot.x_, pivot.y_); - - canvas.concat(matrix); + transitionProperties->DoScaleTransition(value); #endif } void RSTransitionTranslate::OnTransition( - RSPaintFilterCanvas& canvas, const RSProperties& renderProperties, float fraction) + const std::unique_ptr& transitionProperties, float fraction) { #ifdef ROSEN_OHOS - Vector2f startValue(0.0f, 0.0f); - Vector2f endValue(translateX_, translateY_); + Vector3f startValue(0.0f, 0.0f, 0.0f); + Vector3f endValue(translateX_, translateY_, translateZ_); auto value = RSValueEstimator::Estimate(fraction, startValue, endValue); - canvas.translate(value.x_, value.y_); + transitionProperties->DoTranslateTransition(value); #endif } -void RSTransitionRotate::OnTransition(RSPaintFilterCanvas& canvas, const RSProperties& renderProperties, float fraction) +void RSTransitionRotate::OnTransition( + const std::unique_ptr& transitionProperties, float fraction) { #ifdef ROSEN_OHOS auto angle = angle_ * fraction; auto rotateMatrix = SkMatrix44::I(); rotateMatrix.setRotateDegreesAbout(dx_, dy_, dz_, angle); - Vector2f pivot { renderProperties.GetBoundsWidth() * pivotX_, renderProperties.GetBoundsHeight() * pivotY_ }; - - canvas.translate(pivot.x_, pivot.y_); - canvas.concat(rotateMatrix); - canvas.translate(-pivot.x_, -pivot.y_); + transitionProperties->DoRotateTransition(rotateMatrix); #endif } } // namespace Rosen diff --git a/rosen/modules/render_service_base/src/animation/rs_transition_effect.cpp b/rosen/modules/render_service_base/src/animation/rs_transition_effect.cpp index 67dff10a5d..251c75a98e 100644 --- a/rosen/modules/render_service_base/src/animation/rs_transition_effect.cpp +++ b/rosen/modules/render_service_base/src/animation/rs_transition_effect.cpp @@ -22,7 +22,7 @@ namespace Rosen { const std::shared_ptr RSTransitionEffect::OPACITY = RSTransitionEffect::Create()->Opacity(0); const std::shared_ptr RSTransitionEffect::SCALE = - RSTransitionEffect::Create()->Scale({ 0.f, 0.f, 0.f }, { 0.5f, 0.5f }); + RSTransitionEffect::Create()->Scale({ 0.f, 0.f, 0.f }); const std::shared_ptr RSTransitionEffect::EMPTY = RSTransitionEffect::Create(); @@ -39,9 +39,9 @@ std::shared_ptr RSTransitionEffect::Opacity(float opacity) return shared_from_this(); } -std::shared_ptr RSTransitionEffect::Scale(const Vector3f& scale, const Vector2f& pivot) +std::shared_ptr RSTransitionEffect::Scale(const Vector3f& scale) { - auto scaleEffect = std::make_shared(scale.x_, scale.y_, scale.z_, pivot.x_, pivot.y_); + auto scaleEffect = std::make_shared(scale.x_, scale.y_, scale.z_); transitionInEffects_.push_back(scaleEffect); transitionOutEffects_.push_back(scaleEffect); return shared_from_this(); @@ -55,10 +55,9 @@ std::shared_ptr RSTransitionEffect::Translate(const Vector3f return shared_from_this(); } -std::shared_ptr RSTransitionEffect::Rotate(const Vector4f& axisAngle, const Vector2f& pivot) +std::shared_ptr RSTransitionEffect::Rotate(const Vector4f& axisAngle) { - auto rotateEffect = std::make_shared( - axisAngle.x_, axisAngle.y_, axisAngle.z_, axisAngle.w_, pivot.x_, pivot.y_); + auto rotateEffect = std::make_shared(axisAngle.x_, axisAngle.y_, axisAngle.z_, axisAngle.w_); transitionInEffects_.push_back(rotateEffect); transitionOutEffects_.push_back(rotateEffect); return shared_from_this(); diff --git a/rosen/modules/render_service_base/src/pipeline/rs_render_node.cpp b/rosen/modules/render_service_base/src/pipeline/rs_render_node.cpp index 9b9eff308a..d4a27ec861 100644 --- a/rosen/modules/render_service_base/src/pipeline/rs_render_node.cpp +++ b/rosen/modules/render_service_base/src/pipeline/rs_render_node.cpp @@ -19,9 +19,12 @@ #include "animation/rs_render_animation.h" #include "common/rs_obj_abs_geometry.h" +#include "pipeline/rs_context.h" #include "platform/common/rs_log.h" #ifdef ROSEN_OHOS #include "pipeline/rs_paint_filter_canvas.h" +#include "property/rs_properties_painter.h" +#include "property/rs_transition_properties.h" #endif namespace OHOS { @@ -116,7 +119,8 @@ void RSRenderNode::ProcessRenderBeforeChildren(RSPaintFilterCanvas& canvas) if (boundsGeo && !boundsGeo->IsEmpty()) { canvas.concat(boundsGeo->GetMatrix()); } - GetAnimationManager().DoTransition(canvas, GetRenderProperties()); + auto transitionProperties = GetAnimationManager().GetTransitionProperties(); + RSPropertiesPainter::DrawTransitionProperties(transitionProperties, GetRenderProperties(), canvas); #endif } diff --git a/rosen/modules/render_service_base/src/property/rs_properties.cpp b/rosen/modules/render_service_base/src/property/rs_properties.cpp index 65bc02684b..40d9abe8a3 100644 --- a/rosen/modules/render_service_base/src/property/rs_properties.cpp +++ b/rosen/modules/render_service_base/src/property/rs_properties.cpp @@ -18,10 +18,8 @@ #include #include -#include "command/rs_node_command.h" #include "platform/common/rs_log.h" #include "render/rs_filter.h" -#include "transaction/rs_transaction_proxy.h" #ifdef ROSEN_OHOS #include "common/rs_obj_abs_geometry.h" #else diff --git a/rosen/modules/render_service_base/src/property/rs_properties_painter.cpp b/rosen/modules/render_service_base/src/property/rs_properties_painter.cpp index 876c9b6dd6..5d9cf0a200 100644 --- a/rosen/modules/render_service_base/src/property/rs_properties_painter.cpp +++ b/rosen/modules/render_service_base/src/property/rs_properties_painter.cpp @@ -15,25 +15,24 @@ #include "property/rs_properties_painter.h" +#include "common/rs_obj_abs_geometry.h" #include "include/core/SkCanvas.h" +#include "include/core/SkColorFilter.h" +#include "include/core/SkMaskFilter.h" #include "include/core/SkPaint.h" +#include "include/core/SkPoint3.h" #include "include/core/SkRRect.h" #include "include/effects/Sk1DPathEffect.h" #include "include/effects/SkDashPathEffect.h" -#include "include/core/SkColorFilter.h" -#include "include/core/SkPoint3.h" #include "include/utils/SkShadowUtils.h" -#include "include/core/SkMaskFilter.h" - -#include "platform/common/rs_log.h" -#include "common/rs_obj_abs_geometry.h" -#include "pipeline/rs_render_node_map.h" +#include "pipeline/rs_draw_cmd_list.h" #include "pipeline/rs_paint_filter_canvas.h" -#include "pipeline/rs_render_node.h" +#include "platform/common/rs_log.h" +#include "property/rs_transition_properties.h" +#include "render/rs_blur_filter.h" #include "render/rs_image.h" #include "render/rs_path.h" #include "render/rs_shader.h" -#include "render/rs_blur_filter.h" #include "render/rs_skia_filter.h" namespace OHOS { @@ -133,8 +132,7 @@ void SetBorderEffect(SkPaint& paint, BorderStyle style, float width, float space spaceBetweenDot = width * PARAM_DOUBLE; } dotPath.addCircle(0.0f, 0.0f, width / PARAM_DOUBLE); - paint.setPathEffect( - SkPath1DPathEffect::Make(dotPath, spaceBetweenDot, 0.0, SkPath1DPathEffect::kRotate_Style)); + paint.setPathEffect(SkPath1DPathEffect::Make(dotPath, spaceBetweenDot, 0.0, SkPath1DPathEffect::kRotate_Style)); } else if (style == BorderStyle::DASHED) { double addLen = 0.0; // When left < 2 * gap, splits left to gaps. double delLen = 0.0; // When left > 2 * gap, add one dash and shortening them. @@ -143,12 +141,12 @@ void SetBorderEffect(SkPaint& paint, BorderStyle style, float width, float space float leftLen = fmod((count - DASHED_LINE_LENGTH), (DASHED_LINE_LENGTH + 1)); if (leftLen > DASHED_LINE_LENGTH - 1) { delLen = (DASHED_LINE_LENGTH + 1 - leftLen) * width / - static_cast((count - DASHED_LINE_LENGTH) / (DASHED_LINE_LENGTH + 1) + 2); + static_cast((count - DASHED_LINE_LENGTH) / (DASHED_LINE_LENGTH + 1) + 2); } else { addLen = leftLen * width / static_cast((count - DASHED_LINE_LENGTH) / (DASHED_LINE_LENGTH + 1)); } } - const float intervals[] = { width * DASHED_LINE_LENGTH - delLen, width + addLen }; + const float intervals[] = { width * DASHED_LINE_LENGTH - delLen, width + addLen }; paint.setPathEffect(SkDashPathEffect::Make(intervals, SK_ARRAY_COUNT(intervals), 0.0)); } else { paint.setPathEffect(nullptr); @@ -194,8 +192,8 @@ void RSPropertiesPainter::DrawShadow(const RSProperties& properties, SkCanvas& c } } -void RSPropertiesPainter::SaveLayerForFilter(const RSProperties& properties, SkCanvas& canvas, - std::shared_ptr& filter) +void RSPropertiesPainter::SaveLayerForFilter( + const RSProperties& properties, SkCanvas& canvas, std::shared_ptr& filter) { SkPaint paint; paint.setAntiAlias(true); @@ -309,8 +307,8 @@ void RSPropertiesPainter::DrawBorder(const RSProperties& properties, SkCanvas& c rect.GetRight() - borderWidth / PARAM_DOUBLE, rect.GetBottom(), paint); // draw top and bottom border SetBorderEffect(paint, borderStyle, borderWidth, borderLengthHoriz / rawNumberHoriz, borderLengthHoriz); - canvas.drawLine(rect.left_ + addLen * borderWidth, rect.top_ + borderWidth / PARAM_DOUBLE, - rect.GetRight(), rect.top_ + borderWidth / PARAM_DOUBLE, paint); + canvas.drawLine(rect.left_ + addLen * borderWidth, rect.top_ + borderWidth / PARAM_DOUBLE, rect.GetRight(), + rect.top_ + borderWidth / PARAM_DOUBLE, paint); canvas.drawLine(rect.left_ + addLen * borderWidth, rect.GetBottom() - borderWidth / PARAM_DOUBLE, rect.GetRight(), rect.GetBottom() - borderWidth / PARAM_DOUBLE, paint); } @@ -335,5 +333,28 @@ void RSPropertiesPainter::DrawForegroundColor(const RSProperties& properties, Sk paint.setAntiAlias(true); canvas.drawRRect(RRect2SkRRect(properties.GetRRect()), paint); } + +void RSPropertiesPainter::DrawTransitionProperties(const std::unique_ptr& transitionProperties, + const RSProperties& properties, RSPaintFilterCanvas& canvas) +{ + if (transitionProperties == nullptr) { + return; + } + // alpha + canvas.MultiplyAlpha(transitionProperties->GetAlpha()); + + // translate, currently translateZ is not used + auto translate = transitionProperties->GetTranslate(); + canvas.translate(translate.x_, translate.y_); + + // scale and rotate about the center of node, currently scaleZ is not used + auto center = properties.GetBoundsSize() * 0.5f; + auto scale = transitionProperties->GetScale(); + canvas.translate(center.x_, center.y_); + canvas.scale(scale.x_, scale.y_); + canvas.concat(transitionProperties->GetRotate()); + canvas.translate(-center.x_, -center.y_); +} + } // namespace Rosen } // namespace OHOS 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 005e231252..59b658ee7d 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 @@ -225,7 +225,7 @@ bool RSMarshallingHelper::Marshalling(Parcel& parcel, const std::vector& val) template bool RSMarshallingHelper::Unmarshalling(Parcel& parcel, std::vector& val) { - auto size = parcel.ReadUint32(); + uint32_t size = 0; if (!Unmarshalling(parcel, size)) { return false; } diff --git a/rosen/modules/render_service_client/core/ui/rs_node.cpp b/rosen/modules/render_service_client/core/ui/rs_node.cpp index fb49db3d5a..5ce516ab5a 100644 --- a/rosen/modules/render_service_client/core/ui/rs_node.cpp +++ b/rosen/modules/render_service_client/core/ui/rs_node.cpp @@ -20,10 +20,8 @@ #include #include "animation/rs_animation.h" -#include "animation/rs_curve_animation.h" #include "animation/rs_implicit_animator.h" #include "command/rs_node_command.h" -#include "command/rs_node_showing_command.h" #include "common/rs_color.h" #include "common/rs_obj_geometry.h" #include "pipeline/rs_node_map.h" diff --git a/rosen/modules/render_service_client/test/render_service_client_rs_animation_demo.cpp b/rosen/modules/render_service_client/test/render_service_client_rs_animation_demo.cpp index be2bb11704..c4e23f9dd8 100644 --- a/rosen/modules/render_service_client/test/render_service_client_rs_animation_demo.cpp +++ b/rosen/modules/render_service_client/test/render_service_client_rs_animation_demo.cpp @@ -17,6 +17,7 @@ #include #include "animation/rs_curve_animation.h" +#include "animation/rs_transition.h" #include "display_type.h" #include "include/core/SkCanvas.h" #include "include/core/SkImageInfo.h" @@ -143,6 +144,18 @@ int main() RSTransaction::FlushImplicitTransaction(); sleep(5); + std::cout << "adding transition" << std::endl; + auto animation2 = std::make_shared(RSTransitionEffect::OPACITY, true); + animation2->SetDuration(100); + animation2->SetTimingCurve(RSAnimationTimingCurve::EASE_IN_OUT); + animation2->SetFinishCallback([]() { + std::cout << "animation2 finish" << std::endl; + }); + surfaceNode->AddAnimation(animation2); + + RSTransaction::FlushImplicitTransaction(); + sleep(5); + std::cout << "rs app demo end!" << std::endl; window->Hide(); window->Destroy();