#include <dali/devel-api/adaptor-framework/vector-animation-renderer.h>
#include <dali/public-api/object/base-object.h>
#include <toolkit-application.h>
+#include <toolkit-vector-animation-renderer.h>
namespace Dali
{
uint32_t GetTotalFrameNumber() const
{
- return 5;
+ return VECTOR_ANIMATION_TOTAL_FRAME_NUMBER;
}
float GetFrameRate() const
height = 100;
}
+ bool GetMarkerInfo( const std::string& marker, uint32_t& startFrame, uint32_t& endFrame ) const
+ {
+ if( marker.compare( VECTOR_ANIMATION_MARKER_NAME_1 ) == 0 )
+ {
+ startFrame = VECTOR_ANIMATION_MARKER_START_FRAME_1;
+ endFrame = VECTOR_ANIMATION_MARKER_END_FRAME_1;
+ }
+ else if( marker.compare( VECTOR_ANIMATION_MARKER_NAME_2 ) == 0 )
+ {
+ startFrame = VECTOR_ANIMATION_MARKER_START_FRAME_2;
+ endFrame = VECTOR_ANIMATION_MARKER_END_FRAME_2;
+ }
+ else
+ {
+ return false;
+ }
+ return true;
+ }
+
Dali::VectorAnimationRenderer::UploadCompletedSignalType& UploadCompletedSignal()
{
return mUploadCompletedSignal;
{
}
+bool VectorAnimationRenderer::GetMarkerInfo( const std::string& marker, uint32_t& startFrame, uint32_t& endFrame ) const
+{
+ return Internal::Adaptor::GetImplementation( *this ).GetMarkerInfo( marker, startFrame, endFrame );
+}
+
VectorAnimationRenderer::UploadCompletedSignalType& VectorAnimationRenderer::UploadCompletedSignal()
{
return Internal::Adaptor::GetImplementation( *this ).UploadCompletedSignal();
--- /dev/null
+#ifndef DALI_TOOLKIT_TEST_VECTOR_ANIMATION_RENDERER_H
+#define DALI_TOOLKIT_TEST_VECTOR_ANIMATION_RENDERER_H
+
+/*
+ * Copyright (c) 2019 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.
+ * 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.
+ *
+ */
+
+namespace Test
+{
+
+#define VECTOR_ANIMATION_TOTAL_FRAME_NUMBER 5
+#define VECTOR_ANIMATION_MARKER_NAME_1 "marker1"
+#define VECTOR_ANIMATION_MARKER_NAME_2 "marker2"
+#define VECTOR_ANIMATION_MARKER_START_FRAME_1 0
+#define VECTOR_ANIMATION_MARKER_END_FRAME_1 2
+#define VECTOR_ANIMATION_MARKER_START_FRAME_2 2
+#define VECTOR_ANIMATION_MARKER_END_FRAME_2 3
+
+} // Test
+
+
+#endif // DALI_TOOLKIT_TEST_VECTOR_ANIMATION_RENDERER_H
#include <dali-toolkit-test-suite-utils.h>
#include <toolkit-timer.h>
#include <toolkit-event-thread-callback.h>
+#include <toolkit-vector-animation-renderer.h>
#include <dali-toolkit/dali-toolkit.h>
#include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
#include <dali-toolkit/devel-api/controls/control-devel.h>
END_TEST;
}
+int UtcDaliAnimatedVectorImageVisualPlayRangeMarker(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline( "UtcDaliAnimatedVectorImageVisualPlayRangeMarker" );
+
+ Property::Array array;
+ array.PushBack( VECTOR_ANIMATION_MARKER_NAME_1 );
+
+ Property::Map propertyMap;
+ propertyMap.Add( Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE )
+ .Add( ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME )
+ .Add( DevelImageVisual::Property::PLAY_RANGE, array );
+
+ Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap );
+ DALI_TEST_CHECK( visual );
+
+ DummyControl actor = DummyControl::New( true );
+ DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
+ dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
+
+ Vector2 controlSize( 20.f, 30.f );
+ actor.SetSize( controlSize );
+
+ Stage::GetCurrent().Add( actor );
+
+ Property::Map attributes;
+ DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes );
+
+ application.SendNotification();
+ application.Render();
+
+ // renderer is added to actor
+ DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
+ Renderer renderer = actor.GetRendererAt( 0u );
+ DALI_TEST_CHECK( renderer );
+
+ Property::Map map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
+ Property::Value* value = map.Find( DevelImageVisual::Property::PLAY_RANGE );
+
+ int resultStartFrame, resultEndFrame;
+ Property::Array* result = value->GetArray();
+ result->GetElementAt( 0 ).Get( resultStartFrame );
+ result->GetElementAt( 1 ).Get( resultEndFrame );
+
+ DALI_TEST_EQUALS( VECTOR_ANIMATION_MARKER_START_FRAME_1, resultStartFrame, TEST_LOCATION );
+ DALI_TEST_EQUALS( VECTOR_ANIMATION_MARKER_END_FRAME_1, resultEndFrame, TEST_LOCATION );
+
+ // Set 2 markers
+ array.Clear();
+ array.PushBack( VECTOR_ANIMATION_MARKER_NAME_1 );
+ array.PushBack( VECTOR_ANIMATION_MARKER_NAME_2 );
+
+ attributes.Clear();
+ attributes.Add( DevelImageVisual::Property::PLAY_RANGE, array );
+ DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::UPDATE_PROPERTY, attributes );
+
+ application.SendNotification();
+ application.Render();
+
+ map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
+ value = map.Find( DevelImageVisual::Property::PLAY_RANGE );
+
+ result = value->GetArray();
+ result->GetElementAt( 0 ).Get( resultStartFrame );
+ result->GetElementAt( 1 ).Get( resultEndFrame );
+
+ DALI_TEST_EQUALS( VECTOR_ANIMATION_MARKER_START_FRAME_1, resultStartFrame, TEST_LOCATION );
+ DALI_TEST_EQUALS( VECTOR_ANIMATION_MARKER_END_FRAME_2, resultEndFrame, TEST_LOCATION );
+
+ // Set invalid play range
+ array.Clear();
+ array.PushBack( 1 );
+ array.PushBack( VECTOR_ANIMATION_MARKER_NAME_1 );
+
+ attributes.Clear();
+ attributes.Add( DevelImageVisual::Property::PLAY_RANGE, array );
+ DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::UPDATE_PROPERTY, attributes );
+
+ application.SendNotification();
+ application.Render();
+
+ map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
+ value = map.Find( DevelImageVisual::Property::PLAY_RANGE );
+
+ result = value->GetArray();
+ result->GetElementAt( 0 ).Get( resultStartFrame );
+ result->GetElementAt( 1 ).Get( resultEndFrame );
+
+ DALI_TEST_EQUALS( VECTOR_ANIMATION_MARKER_START_FRAME_1, resultStartFrame, TEST_LOCATION ); // Should not be changed
+ DALI_TEST_EQUALS( VECTOR_ANIMATION_MARKER_END_FRAME_2, resultEndFrame, TEST_LOCATION );
+
+ END_TEST;
+}
+
int UtcDaliAnimatedVectorImageVisualAnimationFinishedSignal(void)
{
ToolkitTestApplication application;
/**
* @brief The playing range the AnimatedVectorImageVisual will use.
*
- * Animation will play between the values specified. The array can only have two values, and more will be ignored.
+ * Animation will play between the values specified. The array can have two integer values.
+ * Or it can have one or two strings, which are markers. More will be ignored.
* Both values should be between 0 and the total frame number, otherwise they will be ignored.
* If the range provided is not in proper order ( minimum, maximum ), it will be reordered.
*
- * @details Name "playRange", Type Property::ARRAY of Property::INTEGER
+ * A marker has its start frame and end frame.
+ * Animation will play between the start frame and the end frame of the marker if one marker is specified.
+ * Or animation will play between the start frame of the first marker and the end frame of the second marker if two markers are specified.
+ *
+ * @details Name "playRange", Type Property::ARRAY of Property::INTEGER or Property::ARRAY of Property::STRING.
* @note Default 0 and the total frame number.
*/
PLAY_RANGE = ORIENTATION_CORRECTION + 4,
mImageVisualShaderFactory( shaderFactory ),
mVisualSize(),
mVisualScale( Vector2::ONE ),
+ mPlayRange(),
mPlacementActor(),
mLoopCount( LOOP_FOREVER ),
- mStartFrame( 0 ),
- mEndFrame( 0 ),
mResendFlag( 0 ),
mActionStatus( DevelAnimatedVectorImageVisual::Action::STOP ),
mStopBehavior( DevelImageVisual::StopBehavior::CURRENT_FRAME ),
Property::Array* array = value.GetArray();
if( array )
{
- size_t count = array->Count();
- if( count >= 2 )
- {
- int startFrame, endFrame;
- int totalFrame = mVectorAnimationTask->GetTotalFrameNumber();
- array->GetElementAt( 0 ).Get( startFrame );
- array->GetElementAt( 1 ).Get( endFrame );
-
- if( startFrame >= 0 && startFrame < totalFrame && endFrame >= 0 && endFrame < totalFrame )
- {
- mStartFrame = startFrame;
- mEndFrame = endFrame;
- mResendFlag |= RESEND_PLAY_RANGE;
- }
- else
- {
- DALI_LOG_ERROR( "Invalid play range [%d, %d / %d]\n", startFrame, endFrame, totalFrame );
- }
- }
+ mPlayRange = *array;
+ mResendFlag |= RESEND_PLAY_RANGE;
}
break;
}
if( mResendFlag & RESEND_PLAY_RANGE )
{
- mVectorAnimationTask->SetPlayRange( mStartFrame, mEndFrame );
+ mVectorAnimationTask->SetPlayRange( mPlayRange );
}
if( mResendFlag & RESEND_STOP_BEHAVIOR )
PropertyNotification mSizeNotification;
Vector2 mVisualSize;
Vector2 mVisualScale;
+ Property::Array mPlayRange;
WeakHandle< Actor > mPlacementActor;
int32_t mLoopCount;
- uint32_t mStartFrame;
- uint32_t mEndFrame;
uint32_t mResendFlag;
DevelAnimatedVectorImageVisual::Action::Type mActionStatus;
DevelImageVisual::StopBehavior::Type mStopBehavior;
// EXTERNAL INCLUDES
#include <dali/integration-api/debug.h>
+#include <dali/public-api/object/property-array.h>
// INTERNAL INCLUDES
#include <dali-toolkit/internal/visuals/image-visual-shader-factory.h>
}
}
-void VectorAnimationTask::SetPlayRange( uint32_t startFrame, uint32_t endFrame )
+void VectorAnimationTask::SetPlayRange( Property::Array& playRange )
{
+ ConditionalWait::ScopedLock lock( mConditionalWait );
+
+ bool valid = false;
+ uint32_t startFrame = 0, endFrame = 0;
+ size_t count = playRange.Count();
+
+ if( count >= 2 )
+ {
+ int32_t start = 0, end = 0;
+ if( playRange.GetElementAt( 0 ).Get( start ) && playRange.GetElementAt( 1 ).Get( end ) )
+ {
+ startFrame = static_cast< uint32_t >( start );
+ endFrame = static_cast< uint32_t >( end );
+ valid = true;
+ }
+ else
+ {
+ std::string startMarker, endMarker;
+ if( playRange.GetElementAt( 0 ).Get( startMarker ) && playRange.GetElementAt( 1 ).Get( endMarker ) )
+ {
+ if( mVectorRenderer )
+ {
+ uint32_t frame; // We don't use this later
+ if( mVectorRenderer.GetMarkerInfo( startMarker, startFrame, frame ) && mVectorRenderer.GetMarkerInfo( endMarker, frame, endFrame ) )
+ {
+ valid = true;
+ }
+ }
+ }
+ }
+ }
+ else if( count == 1 )
+ {
+ std::string marker;
+ if( playRange.GetElementAt( 0 ).Get( marker ) )
+ {
+ if( mVectorRenderer )
+ {
+ mVectorRenderer.GetMarkerInfo( marker, startFrame, endFrame );
+ valid = true;
+ }
+ }
+ }
+
+ if( !valid )
+ {
+ DALI_LOG_ERROR( "VectorAnimationTask::SetPlayRange: Invalid range [%p]\n", this );
+ return;
+ }
+
// Make sure the range specified is between 0 and the total frame number
- if( ( startFrame < mTotalFrame ) && ( endFrame < mTotalFrame ) )
+ if( startFrame >= 0 && startFrame < mTotalFrame && endFrame >= 0 && endFrame < mTotalFrame )
{
// If the range is not in order swap values
if( startFrame > endFrame )
if( startFrame != mStartFrame || endFrame != mEndFrame )
{
- ConditionalWait::ScopedLock lock( mConditionalWait );
-
mStartFrame = startFrame;
mEndFrame = endFrame;
DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorAnimationTask::SetPlayRange: [%d, %d] [%p]\n", mStartFrame, mEndFrame, this );
}
}
+ else
+ {
+ DALI_LOG_ERROR( "VectorAnimationTask::SetPlayRange: Invalid range (%d, %d) [%p]\n", startFrame, endFrame, this );
+ return;
+ }
}
void VectorAnimationTask::GetPlayRange( uint32_t& startFrame, uint32_t& endFrame )
/**
* @brief Set the playing range in frame number.
- * @param[in] startFrame The frame number to specify minimum progress.
- * @param[in] endFrame The frame number to specify maximum progress.
+ * @param[in] playRange The array to specify minimum and maximum progress.
* The animation will play between those values.
*/
- void SetPlayRange( uint32_t startFrame, uint32_t endFrame );
+ void SetPlayRange( Property::Array& playRange );
/**
* @brief Gets the playing range in frame number.