X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fevent%2Fanimation%2Fkey-frames-impl.h;h=919fedf727240705aa02be2313d07e39841a9968;hb=73d3c11b85c8dbd1a05361cb86cec939997b2b98;hp=7146a2a0e20817bd7046d69e47c8eace32f57355;hpb=9ead8b67ae46e5fa75b6905ec0405b7d5ce1a8cc;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/event/animation/key-frames-impl.h b/dali/internal/event/animation/key-frames-impl.h index 7146a2a..919fedf 100644 --- a/dali/internal/event/animation/key-frames-impl.h +++ b/dali/internal/event/animation/key-frames-impl.h @@ -1,8 +1,8 @@ -#ifndef __DALI_INTERNAL_KEY_FRAMES_H__ -#define __DALI_INTERNAL_KEY_FRAMES_H__ +#ifndef DALI_INTERNAL_KEY_FRAMES_H +#define DALI_INTERNAL_KEY_FRAMES_H /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2021 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,13 +18,15 @@ * */ +// EXTERNAL INCLUDES +#include + // INTERNAL INCLUDES -#include +#include +#include #include +#include #include -#include -#include -#include namespace Dali { @@ -32,8 +34,6 @@ namespace Internal { class KeyFrameSpec; class KeyFrames; -typedef IntrusivePtr KeyFramesPtr; - /** * KeyFrames class is responsible for creating and building a specialized KeyFrame class @@ -44,26 +44,8 @@ class KeyFrames : public BaseObject public: static KeyFrames* New(); - /** - * Instantiate an empty KeyFrames object - */ - KeyFrames(); - -protected: - virtual ~KeyFrames(); - private: /** - * Don't allow copy constructor - */ - KeyFrames(const KeyFrames& rhs); - - /** - * Don't allow copy operator - */ - KeyFrames& operator=(const KeyFrames& rhs); - - /** * Create a specialization from the given type, and store it to the mSpec * member variable */ @@ -87,7 +69,7 @@ public: * @param[in] alpha An alpha function to blend between this key frame and the * next key frame. */ - void Add(float time, Property::Value value, AlphaFunction alpha); + void Add(float time, const Property::Value& value, AlphaFunction alpha); /** * Return the key frames without specialization. The GetSpecialization methods @@ -100,112 +82,52 @@ public: */ Dali::Property::Value GetLastKeyFrameValue() const; + /** + * @copydoc Dali::DevelKeyFrames::GetKeyFrameCount() + */ + std::size_t GetKeyFrameCount() const; + + /** + * @copydoc Dali::DevelKeyFrames::GetKeyFrame() + */ + void GetKeyFrame(std::size_t index, float& time, Property::Value& value) const; + private: - Dali::Property::Type mType; // Type of the specialization - IntrusivePtr mKeyFrames; // Pointer to the specialized key frame object + Dali::Property::Type mType{Property::NONE}; // Type of the specialization + std::unique_ptr mKeyFrames; // Pointer to the specialized key frame object }; - /** * This is the base class for the individual template specializations, allowing a ptr to be - * stored in the handle object above. It inherits from RefObject to allow smart pointers - * to be used for the specializations. Note that the derived template class below - * allows for a copy constructor so that the specialization object can be cloned before - * being passed to the scene-graph for animation. + * stored in the handle object above. */ -class KeyFrameSpec : public RefObject +class KeyFrameSpec { public: + virtual ~KeyFrameSpec() = default; - KeyFrameSpec() {} - - virtual unsigned int GetNumberOfKeyFrames() const = 0; + virtual std::size_t GetNumberOfKeyFrames() const = 0; /** * Get the key frame value as a Property::Value. * @param[in] index The index of the key frame to fetch + * @param[out] time The progress of the given key frame * @param[out] value The value of the given key frame */ - virtual void GetKeyFrameAsValue( unsigned int index, Property::Value& value ) = 0; - -protected: - - /** - * A reference counted object may only be deleted by calling Unreference() - */ - virtual ~KeyFrameSpec() {} + virtual void GetKeyFrameAsValue(std::size_t index, float& time, Property::Value& value) const = 0; }; - /** - * The base template class for each key frame specialization. It stores a vector of - * ProgressValue pairs in mPVs, and uses the existing interface for KeyFrameChannel - * to point at this vector. + * The base template class for each key frame specialization. */ template class KeyFrameBaseSpec : public KeyFrameSpec { -private: - typedef ProgressValue PV; - typedef std::vector PVContainer; - - PVContainer mPVs; // The ProgressValue pairs - KeyFrameChannel* mKeyFrames; // The key frame interpolator - -public: - static KeyFrameBaseSpec* New() - { - return new KeyFrameBaseSpec(); - } - - static KeyFrameBaseSpec* Clone(const KeyFrameBaseSpec& keyFrames) - { - return new KeyFrameBaseSpec(keyFrames); - } - - /** - * Constructor - */ - KeyFrameBaseSpec() - { - mKeyFrames = new KeyFrameChannel(KeyFrameChannelBase::Translate, mPVs); - } - -protected: - /** - * Copy Constructor - * Allow cloning of this object - */ - KeyFrameBaseSpec(const KeyFrameBaseSpec& keyFrames) - : mPVs(keyFrames.mPVs) - { - mKeyFrames = new KeyFrameChannel(KeyFrameChannelBase::Translate, mPVs); - } - - KeyFrameBaseSpec& operator=( const KeyFrameBaseSpec& keyFrames ) - { - if( this != &keyFrames ) - { - mPVs.clear(); - mPVs = keyFrames.mPVs; - delete mKeyFrames; - mKeyFrames = new KeyFrameChannel(KeyFrameChannelBase::Translate, mPVs); - } - return *this; - } - - /** - * Destructor. Ensure progress value pairs are cleared down - */ - virtual ~KeyFrameBaseSpec() - { - delete mKeyFrames; - mPVs.clear(); - } + KeyFrameChannel mChannel; // The key frame channel public: /** - * Add a key frame to the progress value vector. Key frames should be added + * Add a key frame to the channel. Key frames should be added * in time order (this method does not sort the vector by time) * @param[in] t - progress * @param[in] v - value @@ -213,16 +135,16 @@ public: */ void AddKeyFrame(float t, V v, AlphaFunction alpha) { - mPVs.push_back(PV(t, v)); + mChannel.mValues.push_back({t, v}); } /** * Get the number of key frames - * @return The size of the progress value vector + * @return Channel size */ - virtual unsigned int GetNumberOfKeyFrames() const + std::size_t GetNumberOfKeyFrames() const override { - return mPVs.size(); + return mChannel.mValues.size(); } /** @@ -231,19 +153,22 @@ public: * @param[out] time The progress of the given key frame * @param[out] value The value of the given key frame */ - virtual void GetKeyFrame(unsigned int index, float& time, V& value) const + void GetKeyFrame(unsigned int index, float& time, V& value) const { - DALI_ASSERT_ALWAYS( index < mPVs.size() && "KeyFrame index is out of bounds" ); - time = mPVs[index].mProgress; - value = mPVs[index].mValue; + DALI_ASSERT_ALWAYS(index < mChannel.mValues.size() && "KeyFrame index is out of bounds"); + const auto& element = mChannel.mValues[index]; + time = element.mProgress; + value = element.mValue; } /** * @copydoc KeyFrameSpec::GetKeyFrameAsValue() */ - virtual void GetKeyFrameAsValue( unsigned int index, Property::Value& value ) + void GetKeyFrameAsValue(std::size_t index, float& time, Property::Value& value) const override { - value = mPVs[index].mValue; + const auto& element = mChannel.mValues[index]; + time = element.mProgress; + value = element.mValue; } /** @@ -254,7 +179,7 @@ public: */ bool IsActive(float progress) const { - return mKeyFrames->IsActive(progress); + return mChannel.IsActive(progress); } /** @@ -264,116 +189,41 @@ public: */ V GetValue(float progress, Dali::Animation::Interpolation interpolation) const { - return mKeyFrames->GetValue(progress, interpolation); + return mChannel.GetValue(progress, interpolation); } }; -typedef KeyFrameBaseSpec KeyFrameNumber; -typedef KeyFrameBaseSpec KeyFrameBoolean; -typedef KeyFrameBaseSpec KeyFrameInteger; -typedef KeyFrameBaseSpec KeyFrameVector2; -typedef KeyFrameBaseSpec KeyFrameVector3; -typedef KeyFrameBaseSpec KeyFrameVector4; -typedef KeyFrameBaseSpec KeyFrameQuaternion; - -typedef IntrusivePtr KeyFrameBooleanPtr; -typedef IntrusivePtr KeyFrameNumberPtr; -typedef IntrusivePtr KeyFrameIntegerPtr; -typedef IntrusivePtr KeyFrameVector2Ptr; -typedef IntrusivePtr KeyFrameVector3Ptr; -typedef IntrusivePtr KeyFrameVector4Ptr; -typedef IntrusivePtr KeyFrameQuaternionPtr; - - -inline void GetSpecialization(Internal::KeyFrames& keyFrames, Internal::KeyFrameBoolean*& keyFrameSpec) -{ - keyFrameSpec = static_cast(keyFrames.GetKeyFramesBase()); -} - -inline void GetSpecialization(const Internal::KeyFrames& keyFrames, const Internal::KeyFrameBoolean*& keyFrameSpec) -{ - keyFrameSpec = static_cast(keyFrames.GetKeyFramesBase()); -} +using KeyFrameNumber = KeyFrameBaseSpec; +using KeyFrameBoolean = KeyFrameBaseSpec; +using KeyFrameInteger = KeyFrameBaseSpec; +using KeyFrameVector2 = KeyFrameBaseSpec; +using KeyFrameVector3 = KeyFrameBaseSpec; +using KeyFrameVector4 = KeyFrameBaseSpec; +using KeyFrameQuaternion = KeyFrameBaseSpec; -inline void GetSpecialization(Internal::KeyFrames& keyFrames, Internal::KeyFrameNumber*& keyFrameSpec) +template +auto GetSpecialization(const Internal::KeyFrames& keyFrames) { - keyFrameSpec = static_cast(keyFrames.GetKeyFramesBase()); + return static_cast(keyFrames.GetKeyFramesBase()); } -inline void GetSpecialization(const Internal::KeyFrames& keyFrames, const Internal::KeyFrameNumber*& keyFrameSpec) -{ - keyFrameSpec = static_cast(keyFrames.GetKeyFramesBase()); -} - -inline void GetSpecialization(Internal::KeyFrames& keyFrames, Internal::KeyFrameInteger*& keyFrameSpec) -{ - keyFrameSpec = static_cast(keyFrames.GetKeyFramesBase()); -} - -inline void GetSpecialization(const Internal::KeyFrames& keyFrames, const Internal::KeyFrameInteger*& keyFrameSpec) -{ - keyFrameSpec = static_cast(keyFrames.GetKeyFramesBase()); -} - -inline void GetSpecialization(Internal::KeyFrames& keyFrames, Internal::KeyFrameVector2*& keyFrameSpec) -{ - keyFrameSpec = static_cast(keyFrames.GetKeyFramesBase()); -} - -inline void GetSpecialization(const Internal::KeyFrames& keyFrames, const Internal::KeyFrameVector2*& keyFrameSpec) -{ - keyFrameSpec = static_cast(keyFrames.GetKeyFramesBase()); -} - -inline void GetSpecialization(Internal::KeyFrames& keyFrames, Internal::KeyFrameVector3*& keyFrameSpec) -{ - keyFrameSpec = static_cast(keyFrames.GetKeyFramesBase()); -} - -inline void GetSpecialization(const Internal::KeyFrames& keyFrames, const Internal::KeyFrameVector3*& keyFrameSpec) -{ - keyFrameSpec = static_cast(keyFrames.GetKeyFramesBase()); -} - -inline void GetSpecialization(Internal::KeyFrames& keyFrames, Internal::KeyFrameVector4*& keyFrameSpec) -{ - keyFrameSpec = static_cast(keyFrames.GetKeyFramesBase()); -} - -inline void GetSpecialization(const Internal::KeyFrames& keyFrames, const Internal::KeyFrameVector4*& keyFrameSpec) -{ - keyFrameSpec = static_cast(keyFrames.GetKeyFramesBase()); -} - -inline void GetSpecialization(Internal::KeyFrames& keyFrames, Internal::KeyFrameQuaternion*& keyFrameSpec) -{ - keyFrameSpec = static_cast(keyFrames.GetKeyFramesBase()); -} - -inline void GetSpecialization(const Internal::KeyFrames& keyFrames, const Internal::KeyFrameQuaternion*& keyFrameSpec) -{ - keyFrameSpec = static_cast(keyFrames.GetKeyFramesBase()); -} - -} // Internal - +} // namespace Internal // Get impl of handle inline Internal::KeyFrames& GetImplementation(Dali::KeyFrames& keyFrames) { - DALI_ASSERT_ALWAYS( keyFrames && "KeyFrames handle is empty" ); + DALI_ASSERT_ALWAYS(keyFrames && "KeyFrames handle is empty"); Dali::RefObject& object = keyFrames.GetBaseObject(); return static_cast(object); } inline const Internal::KeyFrames& GetImplementation(const Dali::KeyFrames& keyFrames) { - DALI_ASSERT_ALWAYS( keyFrames && "KeyFrames handle is empty" ); + DALI_ASSERT_ALWAYS(keyFrames && "KeyFrames handle is empty"); const Dali::RefObject& object = keyFrames.GetBaseObject(); return static_cast(object); } +} // namespace Dali -} // Dali - -#endif //__DALI_INTERNAL_KEY_FRAMES_H__ +#endif // DALI_INTERNAL_KEY_FRAMES_H