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( const std::string& url )
45 mEventThreadCallback( new EventThreadCallback( MakeCallback( this, &VectorAnimationRenderer::OnTriggered ) ) )
55 ~VectorAnimationRenderer()
60 void SetRenderer( Dali::Renderer renderer )
64 if( mWidth != 0 && mHeight != 0 )
66 Dali::TextureSet textureSet = mRenderer.GetTextures();
67 Dali::Texture texture = Dali::Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, mWidth, mHeight );
68 textureSet.SetTexture( 0, texture );
69 mUploadCompletedSignal.Emit();
73 void SetSize( uint32_t width, uint32_t height )
80 Dali::TextureSet textureSet = mRenderer.GetTextures();
81 Dali::Texture texture = Dali::Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, mWidth, mHeight );
82 textureSet.SetTexture( 0, texture );
83 mUploadCompletedSignal.Emit();
87 bool Render( uint32_t frameNumber )
91 mEventThreadCallback->Trigger();
95 if( frameNumber == 1 && mPreviousFrame != frameNumber )
97 mPreviousFrame = frameNumber;
101 mPreviousFrame = frameNumber;
105 uint32_t GetTotalFrameNumber() const
107 return VECTOR_ANIMATION_TOTAL_FRAME_NUMBER;
110 float GetFrameRate() const
115 void GetDefaultSize( uint32_t& width, uint32_t& height ) const
121 bool GetMarkerInfo( const std::string& marker, uint32_t& startFrame, uint32_t& endFrame ) const
123 if( marker.compare( VECTOR_ANIMATION_MARKER_NAME_1 ) == 0 )
125 startFrame = VECTOR_ANIMATION_MARKER_START_FRAME_1;
126 endFrame = VECTOR_ANIMATION_MARKER_END_FRAME_1;
128 else if( marker.compare( VECTOR_ANIMATION_MARKER_NAME_2 ) == 0 )
130 startFrame = VECTOR_ANIMATION_MARKER_START_FRAME_2;
131 endFrame = VECTOR_ANIMATION_MARKER_END_FRAME_2;
140 Dali::VectorAnimationRenderer::UploadCompletedSignalType& UploadCompletedSignal()
142 return mUploadCompletedSignal;
151 static uint32_t mCount;
152 static bool mNeedTrigger;
155 Dali::Renderer mRenderer;
158 uint32_t mPreviousFrame;
160 Dali::VectorAnimationRenderer::UploadCompletedSignalType mUploadCompletedSignal;
161 std::unique_ptr< EventThreadCallback > mEventThreadCallback;
164 uint32_t VectorAnimationRenderer::mCount = 0;
165 bool VectorAnimationRenderer::mNeedTrigger = true;
167 inline VectorAnimationRenderer& GetImplementation( Dali::VectorAnimationRenderer& renderer )
169 DALI_ASSERT_ALWAYS( renderer && "VectorAnimationRenderer handle is empty." );
170 BaseObject& handle = renderer.GetBaseObject();
171 return static_cast< Internal::Adaptor::VectorAnimationRenderer& >( handle );
174 inline const VectorAnimationRenderer& GetImplementation( const Dali::VectorAnimationRenderer& renderer )
176 DALI_ASSERT_ALWAYS( renderer && "VectorAnimationRenderer handle is empty." );
177 const BaseObject& handle = renderer.GetBaseObject();
178 return static_cast< const Internal::Adaptor::VectorAnimationRenderer& >( handle );
181 } // namespace Adaptor
183 } // namespace Internal
186 /********************************************************************************/
187 /********************************* PUBLIC CLASS *******************************/
188 /********************************************************************************/
190 VectorAnimationRenderer VectorAnimationRenderer::New( const std::string& url )
192 Internal::Adaptor::VectorAnimationRenderer* animationRenderer = new Internal::Adaptor::VectorAnimationRenderer( url );
194 return VectorAnimationRenderer( animationRenderer );
197 VectorAnimationRenderer::VectorAnimationRenderer()
201 VectorAnimationRenderer::~VectorAnimationRenderer()
205 VectorAnimationRenderer::VectorAnimationRenderer( Internal::Adaptor::VectorAnimationRenderer* internal )
206 : BaseHandle( internal )
210 VectorAnimationRenderer::VectorAnimationRenderer( const VectorAnimationRenderer& handle )
211 : BaseHandle( handle )
215 VectorAnimationRenderer& VectorAnimationRenderer::operator=( const VectorAnimationRenderer& rhs )
217 BaseHandle::operator=( rhs );
221 void VectorAnimationRenderer::Finalize()
225 void VectorAnimationRenderer::SetRenderer( Renderer renderer )
227 Internal::Adaptor::GetImplementation( *this ).SetRenderer( renderer );
230 void VectorAnimationRenderer::SetSize( uint32_t width, uint32_t height )
232 Internal::Adaptor::GetImplementation( *this ).SetSize( width, height );
235 bool VectorAnimationRenderer::Render( uint32_t frameNumber )
237 return Internal::Adaptor::GetImplementation( *this ).Render( frameNumber );
240 uint32_t VectorAnimationRenderer::GetTotalFrameNumber() const
242 return Internal::Adaptor::GetImplementation( *this ).GetTotalFrameNumber();
245 float VectorAnimationRenderer::GetFrameRate() const
247 return Internal::Adaptor::GetImplementation( *this ).GetFrameRate();
250 void VectorAnimationRenderer::GetDefaultSize( uint32_t& width, uint32_t& height ) const
252 Internal::Adaptor::GetImplementation( *this ).GetDefaultSize( width, height );
255 void VectorAnimationRenderer::GetLayerInfo( Property::Map& map ) const
259 bool VectorAnimationRenderer::GetMarkerInfo( const std::string& marker, uint32_t& startFrame, uint32_t& endFrame ) const
261 return Internal::Adaptor::GetImplementation( *this ).GetMarkerInfo( marker, startFrame, endFrame );
264 VectorAnimationRenderer::UploadCompletedSignalType& VectorAnimationRenderer::UploadCompletedSignal()
266 return Internal::Adaptor::GetImplementation( *this ).UploadCompletedSignal();
273 namespace VectorAnimationRenderer
276 void RequestTrigger()
278 Dali::Internal::Adaptor::VectorAnimationRenderer::mNeedTrigger = true;
281 } // VectorAnimationRenderer