2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <dali/devel-api/adaptor-framework/vector-animation-renderer.h>
19 #include <dali/public-api/object/base-object.h>
20 #include <toolkit-application.h>
21 #include <toolkit-vector-animation-renderer.h>
22 #include <toolkit-event-thread-callback.h>
34 class VectorAnimationRenderer: public Dali::BaseObject
38 VectorAnimationRenderer()
45 mEventThreadCallback( new EventThreadCallback( MakeCallback( this, &VectorAnimationRenderer::OnTriggered ) ) )
55 ~VectorAnimationRenderer()
60 bool Load(const std::string& url)
63 if(mUrl == "invalid.json")
70 void SetRenderer( Dali::Renderer renderer )
74 if( mWidth != 0 && mHeight != 0 )
76 Dali::TextureSet textureSet = mRenderer.GetTextures();
77 Dali::Texture texture = Dali::Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, mWidth, mHeight );
78 textureSet.SetTexture( 0, texture );
79 mUploadCompletedSignal.Emit();
83 void SetSize( uint32_t width, uint32_t height )
90 Dali::TextureSet textureSet = mRenderer.GetTextures();
91 Dali::Texture texture = Dali::Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, mWidth, mHeight );
92 textureSet.SetTexture( 0, texture );
93 mUploadCompletedSignal.Emit();
97 bool Render( uint32_t frameNumber )
101 mEventThreadCallback->Trigger();
102 mNeedTrigger = false;
105 if( frameNumber == 1 && mPreviousFrame != frameNumber )
107 mPreviousFrame = frameNumber;
108 // For test corverage
111 mPreviousFrame = frameNumber;
115 uint32_t GetTotalFrameNumber() const
117 return VECTOR_ANIMATION_TOTAL_FRAME_NUMBER;
120 float GetFrameRate() const
125 void GetDefaultSize( uint32_t& width, uint32_t& height ) const
131 bool GetMarkerInfo( const std::string& marker, uint32_t& startFrame, uint32_t& endFrame ) const
133 if( marker.compare( VECTOR_ANIMATION_MARKER_NAME_1 ) == 0 )
135 startFrame = VECTOR_ANIMATION_MARKER_START_FRAME_1;
136 endFrame = VECTOR_ANIMATION_MARKER_END_FRAME_1;
138 else if( marker.compare( VECTOR_ANIMATION_MARKER_NAME_2 ) == 0 )
140 startFrame = VECTOR_ANIMATION_MARKER_START_FRAME_2;
141 endFrame = VECTOR_ANIMATION_MARKER_END_FRAME_2;
150 Dali::VectorAnimationRenderer::UploadCompletedSignalType& UploadCompletedSignal()
152 return mUploadCompletedSignal;
161 static uint32_t mCount;
162 static bool mNeedTrigger;
165 Dali::Renderer mRenderer;
168 uint32_t mPreviousFrame;
170 Dali::VectorAnimationRenderer::UploadCompletedSignalType mUploadCompletedSignal;
171 std::unique_ptr< EventThreadCallback > mEventThreadCallback;
174 uint32_t VectorAnimationRenderer::mCount = 0;
175 bool VectorAnimationRenderer::mNeedTrigger = true;
177 inline VectorAnimationRenderer& GetImplementation( Dali::VectorAnimationRenderer& renderer )
179 DALI_ASSERT_ALWAYS( renderer && "VectorAnimationRenderer handle is empty." );
180 BaseObject& handle = renderer.GetBaseObject();
181 return static_cast< Internal::Adaptor::VectorAnimationRenderer& >( handle );
184 inline const VectorAnimationRenderer& GetImplementation( const Dali::VectorAnimationRenderer& renderer )
186 DALI_ASSERT_ALWAYS( renderer && "VectorAnimationRenderer handle is empty." );
187 const BaseObject& handle = renderer.GetBaseObject();
188 return static_cast< const Internal::Adaptor::VectorAnimationRenderer& >( handle );
191 } // namespace Adaptor
193 } // namespace Internal
196 /********************************************************************************/
197 /********************************* PUBLIC CLASS *******************************/
198 /********************************************************************************/
200 VectorAnimationRenderer VectorAnimationRenderer::New()
202 Internal::Adaptor::VectorAnimationRenderer* animationRenderer = new Internal::Adaptor::VectorAnimationRenderer();
204 return VectorAnimationRenderer( animationRenderer );
207 VectorAnimationRenderer::VectorAnimationRenderer()
211 VectorAnimationRenderer::~VectorAnimationRenderer()
215 VectorAnimationRenderer::VectorAnimationRenderer( Internal::Adaptor::VectorAnimationRenderer* internal )
216 : BaseHandle( internal )
220 VectorAnimationRenderer::VectorAnimationRenderer( const VectorAnimationRenderer& handle )
221 : BaseHandle( handle )
225 VectorAnimationRenderer& VectorAnimationRenderer::operator=( const VectorAnimationRenderer& rhs )
227 BaseHandle::operator=( rhs );
231 void VectorAnimationRenderer::Finalize()
235 bool VectorAnimationRenderer::Load(const std::string& url)
237 return Internal::Adaptor::GetImplementation( *this ).Load(url);
240 void VectorAnimationRenderer::SetRenderer( Renderer renderer )
242 Internal::Adaptor::GetImplementation( *this ).SetRenderer( renderer );
245 void VectorAnimationRenderer::SetSize( uint32_t width, uint32_t height )
247 Internal::Adaptor::GetImplementation( *this ).SetSize( width, height );
250 bool VectorAnimationRenderer::Render( uint32_t frameNumber )
252 return Internal::Adaptor::GetImplementation( *this ).Render( frameNumber );
255 uint32_t VectorAnimationRenderer::GetTotalFrameNumber() const
257 return Internal::Adaptor::GetImplementation( *this ).GetTotalFrameNumber();
260 float VectorAnimationRenderer::GetFrameRate() const
262 return Internal::Adaptor::GetImplementation( *this ).GetFrameRate();
265 void VectorAnimationRenderer::GetDefaultSize( uint32_t& width, uint32_t& height ) const
267 Internal::Adaptor::GetImplementation( *this ).GetDefaultSize( width, height );
270 void VectorAnimationRenderer::GetLayerInfo( Property::Map& map ) const
274 bool VectorAnimationRenderer::GetMarkerInfo( const std::string& marker, uint32_t& startFrame, uint32_t& endFrame ) const
276 return Internal::Adaptor::GetImplementation( *this ).GetMarkerInfo( marker, startFrame, endFrame );
279 VectorAnimationRenderer::UploadCompletedSignalType& VectorAnimationRenderer::UploadCompletedSignal()
281 return Internal::Adaptor::GetImplementation( *this ).UploadCompletedSignal();
288 namespace VectorAnimationRenderer
291 void RequestTrigger()
293 Dali::Internal::Adaptor::VectorAnimationRenderer::mNeedTrigger = true;
296 } // VectorAnimationRenderer