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>
32 class VectorAnimationRenderer: public Dali::BaseObject
36 VectorAnimationRenderer( const std::string& url )
52 ~VectorAnimationRenderer()
57 void SetRenderer( Dali::Renderer renderer )
61 if( mWidth != 0 && mHeight != 0 )
63 Dali::TextureSet textureSet = mRenderer.GetTextures();
64 Dali::Texture texture = Dali::Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, mWidth, mHeight );
65 textureSet.SetTexture( 0, texture );
66 mUploadCompletedSignal.Emit();
70 void SetSize( uint32_t width, uint32_t height )
77 Dali::TextureSet textureSet = mRenderer.GetTextures();
78 Dali::Texture texture = Dali::Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, mWidth, mHeight );
79 textureSet.SetTexture( 0, texture );
80 mUploadCompletedSignal.Emit();
84 bool Render( uint32_t frameNumber )
86 if( frameNumber == 1 && mPreviousFrame != frameNumber )
88 mPreviousFrame = frameNumber;
92 mPreviousFrame = frameNumber;
96 uint32_t GetTotalFrameNumber() const
98 return VECTOR_ANIMATION_TOTAL_FRAME_NUMBER;
101 float GetFrameRate() const
106 void GetDefaultSize( uint32_t& width, uint32_t& height ) const
112 bool GetMarkerInfo( const std::string& marker, uint32_t& startFrame, uint32_t& endFrame ) const
114 if( marker.compare( VECTOR_ANIMATION_MARKER_NAME_1 ) == 0 )
116 startFrame = VECTOR_ANIMATION_MARKER_START_FRAME_1;
117 endFrame = VECTOR_ANIMATION_MARKER_END_FRAME_1;
119 else if( marker.compare( VECTOR_ANIMATION_MARKER_NAME_2 ) == 0 )
121 startFrame = VECTOR_ANIMATION_MARKER_START_FRAME_2;
122 endFrame = VECTOR_ANIMATION_MARKER_END_FRAME_2;
131 Dali::VectorAnimationRenderer::UploadCompletedSignalType& UploadCompletedSignal()
133 return mUploadCompletedSignal;
138 static uint32_t mCount;
141 Dali::Renderer mRenderer;
144 uint32_t mPreviousFrame;
146 Dali::VectorAnimationRenderer::UploadCompletedSignalType mUploadCompletedSignal;
149 uint32_t VectorAnimationRenderer::mCount = 0;
151 inline VectorAnimationRenderer& GetImplementation( Dali::VectorAnimationRenderer& renderer )
153 DALI_ASSERT_ALWAYS( renderer && "VectorAnimationRenderer handle is empty." );
154 BaseObject& handle = renderer.GetBaseObject();
155 return static_cast< Internal::Adaptor::VectorAnimationRenderer& >( handle );
158 inline const VectorAnimationRenderer& GetImplementation( const Dali::VectorAnimationRenderer& renderer )
160 DALI_ASSERT_ALWAYS( renderer && "VectorAnimationRenderer handle is empty." );
161 const BaseObject& handle = renderer.GetBaseObject();
162 return static_cast< const Internal::Adaptor::VectorAnimationRenderer& >( handle );
165 } // namespace Adaptor
167 } // namespace Internal
170 /********************************************************************************/
171 /********************************* PUBLIC CLASS *******************************/
172 /********************************************************************************/
174 VectorAnimationRenderer VectorAnimationRenderer::New( const std::string& url )
176 Internal::Adaptor::VectorAnimationRenderer* animationRenderer = new Internal::Adaptor::VectorAnimationRenderer( url );
178 return VectorAnimationRenderer( animationRenderer );
181 VectorAnimationRenderer::VectorAnimationRenderer()
185 VectorAnimationRenderer::~VectorAnimationRenderer()
189 VectorAnimationRenderer::VectorAnimationRenderer( Internal::Adaptor::VectorAnimationRenderer* internal )
190 : BaseHandle( internal )
194 VectorAnimationRenderer::VectorAnimationRenderer( const VectorAnimationRenderer& handle )
195 : BaseHandle( handle )
199 VectorAnimationRenderer& VectorAnimationRenderer::operator=( const VectorAnimationRenderer& rhs )
201 BaseHandle::operator=( rhs );
205 void VectorAnimationRenderer::Finalize()
209 void VectorAnimationRenderer::SetRenderer( Renderer renderer )
211 Internal::Adaptor::GetImplementation( *this ).SetRenderer( renderer );
214 void VectorAnimationRenderer::SetSize( uint32_t width, uint32_t height )
216 Internal::Adaptor::GetImplementation( *this ).SetSize( width, height );
219 bool VectorAnimationRenderer::Render( uint32_t frameNumber )
221 return Internal::Adaptor::GetImplementation( *this ).Render( frameNumber );
224 uint32_t VectorAnimationRenderer::GetTotalFrameNumber() const
226 return Internal::Adaptor::GetImplementation( *this ).GetTotalFrameNumber();
229 float VectorAnimationRenderer::GetFrameRate() const
231 return Internal::Adaptor::GetImplementation( *this ).GetFrameRate();
234 void VectorAnimationRenderer::GetDefaultSize( uint32_t& width, uint32_t& height ) const
236 Internal::Adaptor::GetImplementation( *this ).GetDefaultSize( width, height );
239 void VectorAnimationRenderer::GetLayerInfo( Property::Map& map ) const
243 bool VectorAnimationRenderer::GetMarkerInfo( const std::string& marker, uint32_t& startFrame, uint32_t& endFrame ) const
245 return Internal::Adaptor::GetImplementation( *this ).GetMarkerInfo( marker, startFrame, endFrame );
248 VectorAnimationRenderer::UploadCompletedSignalType& VectorAnimationRenderer::UploadCompletedSignal()
250 return Internal::Adaptor::GetImplementation( *this ).UploadCompletedSignal();