{
public:
- VectorAnimationRenderer( const std::string& url )
- : mUrl( url ),
+ VectorAnimationRenderer()
+ : mUrl(),
mRenderer(),
mWidth( 0 ),
mHeight( 0 ),
mCount--;
}
+ bool Load(const std::string& url)
+ {
+ mUrl = url;
+ if(mUrl == "invalid.json")
+ {
+ return false;
+ }
+ return true;
+ }
+
void SetRenderer( Dali::Renderer renderer )
{
mRenderer = renderer;
/********************************* PUBLIC CLASS *******************************/
/********************************************************************************/
-VectorAnimationRenderer VectorAnimationRenderer::New( const std::string& url )
+VectorAnimationRenderer VectorAnimationRenderer::New()
{
- Internal::Adaptor::VectorAnimationRenderer* animationRenderer = new Internal::Adaptor::VectorAnimationRenderer( url );
+ Internal::Adaptor::VectorAnimationRenderer* animationRenderer = new Internal::Adaptor::VectorAnimationRenderer();
return VectorAnimationRenderer( animationRenderer );
}
{
}
+bool VectorAnimationRenderer::Load(const std::string& url)
+{
+ return Internal::Adaptor::GetImplementation( *this ).Load(url);
+}
+
void VectorAnimationRenderer::SetRenderer( Renderer renderer )
{
Internal::Adaptor::GetImplementation( *this ).SetRenderer( renderer );
{
const char* TEST_VECTOR_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/insta_camera.json";
+const char* TEST_VECTOR_IMAGE_INVALID_FILE_NAME = "invalid.json";
bool gAnimationFinishedSignalFired = false;
END_TEST;
}
+
+int UtcDaliAnimatedVectorImageVisualInvalidFile(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline("Request loading with invalid file - should draw broken image");
+
+ TestGlAbstraction& gl = application.GetGlAbstraction();
+ TraceCallStack& textureTrace = gl.GetTextureTrace();
+ textureTrace.Enable(true);
+
+ Property::Map propertyMap;
+ propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
+ .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_INVALID_FILE_NAME);
+
+ 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);
+
+ actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
+
+ application.GetScene().Add(actor);
+
+ application.SendNotification();
+ application.Render();
+
+ // Check resource status
+ Visual::ResourceStatus status = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL);
+ DALI_TEST_EQUALS(status, Visual::ResourceStatus::FAILED, TEST_LOCATION);
+
+ // The broken image should be shown.
+ DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
+ DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
+
+ END_TEST;
+}
: Visual::Base(factoryCache, Visual::FittingMode::FILL, static_cast<Toolkit::Visual::Type>(Toolkit::DevelVisual::ANIMATED_VECTOR_IMAGE)),
mUrl(imageUrl),
mAnimationData(),
- mVectorAnimationTask(new VectorAnimationTask(factoryCache, imageUrl.GetUrl())),
+ mVectorAnimationTask(new VectorAnimationTask(factoryCache)),
mImageVisualShaderFactory(shaderFactory),
mVisualSize(),
mVisualScale(Vector2::ONE),
mPlacementActor(),
mPlayState(DevelImageVisual::PlayState::STOPPED),
mEventCallback(nullptr),
+ mLoadFailed(false),
mRendererAdded(false),
mCoreShutdown(false),
mRedrawInScalingDown(true)
// the rasterized image is with pre-multiplied alpha format
mImpl->mFlags |= Impl::IS_PREMULTIPLIED_ALPHA;
+ if(!mVectorAnimationTask->Load(mUrl.GetUrl()))
+ {
+ mLoadFailed = true;
+ }
+
mVectorAnimationTask->UploadCompletedSignal().Connect(this, &AnimatedVectorImageVisual::OnUploadCompleted);
mVectorAnimationTask->SetAnimationFinishedCallback(new EventThreadCallback(MakeCallback(this, &AnimatedVectorImageVisual::OnAnimationFinished)));
// Hold the weak handle of the placement actor and delay the adding of renderer until the rasterization is finished.
mPlacementActor = actor;
- mVectorAnimationTask->SetRenderer(mImpl->mRenderer);
-
- // Add property notification for scaling & size
- mScaleNotification = actor.AddPropertyNotification(Actor::Property::WORLD_SCALE, StepCondition(0.1f, 1.0f));
- mScaleNotification.NotifySignal().Connect(this, &AnimatedVectorImageVisual::OnScaleNotification);
+ if(mLoadFailed)
+ {
+ TextureSet textureSet = TextureSet::New();
+ mImpl->mRenderer.SetTextures(textureSet);
- mSizeNotification = actor.AddPropertyNotification(Actor::Property::SIZE, StepCondition(3.0f));
- mSizeNotification.NotifySignal().Connect(this, &AnimatedVectorImageVisual::OnSizeNotification);
+ Texture brokenImage = mFactoryCache.GetBrokenVisualImage();
+ textureSet.SetTexture(0u, brokenImage);
- DevelActor::VisibilityChangedSignal(actor).Connect(this, &AnimatedVectorImageVisual::OnControlVisibilityChanged);
+ actor.AddRenderer(mImpl->mRenderer);
- Window window = DevelWindow::Get(actor);
- if(window)
+ ResourceReady(Toolkit::Visual::ResourceStatus::FAILED);
+ }
+ else
{
- DevelWindow::VisibilityChangedSignal(window).Connect(this, &AnimatedVectorImageVisual::OnWindowVisibilityChanged);
+ mVectorAnimationTask->SetRenderer(mImpl->mRenderer);
+
+ // Add property notification for scaling & size
+ mScaleNotification = actor.AddPropertyNotification(Actor::Property::WORLD_SCALE, StepCondition(0.1f, 1.0f));
+ mScaleNotification.NotifySignal().Connect(this, &AnimatedVectorImageVisual::OnScaleNotification);
+
+ mSizeNotification = actor.AddPropertyNotification(Actor::Property::SIZE, StepCondition(3.0f));
+ mSizeNotification.NotifySignal().Connect(this, &AnimatedVectorImageVisual::OnSizeNotification);
+
+ DevelActor::VisibilityChangedSignal(actor).Connect(this, &AnimatedVectorImageVisual::OnControlVisibilityChanged);
+
+ Window window = DevelWindow::Get(actor);
+ if(window)
+ {
+ DevelWindow::VisibilityChangedSignal(window).Connect(this, &AnimatedVectorImageVisual::OnWindowVisibilityChanged);
+ }
}
DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::DoSetOnScene [%p]\n", this);
WeakHandle<Actor> mPlacementActor;
DevelImageVisual::PlayState::Type mPlayState;
CallbackBase* mEventCallback; // Not owned
+ bool mLoadFailed;
bool mRendererAdded;
bool mCoreShutdown;
bool mRedrawInScalingDown;
} // unnamed namespace
-VectorAnimationTask::VectorAnimationTask(VisualFactoryCache& factoryCache, const std::string& url)
-: mUrl(url),
- mVectorRenderer(),
+VectorAnimationTask::VectorAnimationTask(VisualFactoryCache& factoryCache)
+: mUrl(),
+ mVectorRenderer(VectorAnimationRenderer::New()),
mAnimationData(),
mVectorAnimationThread(factoryCache.GetVectorAnimationManager().GetVectorAnimationThread()),
mConditionalWait(),
mAnimationDataUpdated(false),
mDestroyTask(false)
{
- Initialize();
}
VectorAnimationTask::~VectorAnimationTask()
mDestroyTask = true;
}
+bool VectorAnimationTask::Load(const std::string& url)
+{
+ mUrl = url;
+
+ if(!mVectorRenderer.Load(mUrl))
+ {
+ DALI_LOG_ERROR("VectorAnimationTask::Load: Load failed [%s]\n", mUrl.c_str());
+ return false;
+ }
+
+ mTotalFrame = mVectorRenderer.GetTotalFrameNumber();
+
+ mEndFrame = mTotalFrame - 1;
+
+ mFrameRate = mVectorRenderer.GetFrameRate();
+ mFrameDurationNanoSeconds = NANOSECONDS_PER_SECOND / mFrameRate;
+
+ uint32_t width, height;
+ mVectorRenderer.GetDefaultSize(width, height);
+
+ SetSize(width, height);
+
+ DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "VectorAnimationTask::Load: file = %s [%d frames, %f fps] [%p]\n", mUrl.c_str(), mTotalFrame, mFrameRate, this);
+
+ return true;
+}
+
void VectorAnimationTask::SetRenderer(Renderer renderer)
{
ConditionalWait::ScopedLock lock(mConditionalWait);
return mVectorRenderer.UploadCompletedSignal();
}
-void VectorAnimationTask::Initialize()
-{
- mVectorRenderer = VectorAnimationRenderer::New(mUrl);
-
- mTotalFrame = mVectorRenderer.GetTotalFrameNumber();
-
- mEndFrame = mTotalFrame - 1;
-
- mFrameRate = mVectorRenderer.GetFrameRate();
- mFrameDurationNanoSeconds = NANOSECONDS_PER_SECOND / mFrameRate;
-
- uint32_t width, height;
- mVectorRenderer.GetDefaultSize(width, height);
-
- SetSize(width, height);
-
- DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "VectorAnimationTask::Initialize: file = %s [%d frames, %f fps] [%p]\n", mUrl.c_str(), mTotalFrame, mFrameRate, this);
-}
-
bool VectorAnimationTask::Rasterize()
{
bool stopped = false;
* @brief Constructor.
*
* @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
- * @param[in] url The url of the vector animation file
*/
- VectorAnimationTask(VisualFactoryCache& factoryCache, const std::string& url);
+ VectorAnimationTask(VisualFactoryCache& factoryCache);
/**
* @brief Destructor.
void Finalize();
/**
+ * @brief Loads the animation file.
+ *
+ * @param[in] url The url of the vector animation file
+ * @return True if loading success, false otherwise.
+ */
+ bool Load(const std::string& url);
+
+ /**
* @brief Sets the renderer used to display the result image.
*
* @param[in] renderer The renderer used to display the result image
private:
/**
- * @brief Initializes the vector renderer.
- */
- void Initialize();
-
- /**
* @brief Play the vector animation.
*/
void PlayAnimation();