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>
31 class VectorAnimationRenderer: public Dali::BaseObject
35 VectorAnimationRenderer( const std::string& url )
51 ~VectorAnimationRenderer()
56 void SetRenderer( Dali::Renderer renderer )
60 if( mWidth != 0 && mHeight != 0 )
62 Dali::TextureSet textureSet = mRenderer.GetTextures();
63 Dali::Texture texture = Dali::Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, mWidth, mHeight );
64 textureSet.SetTexture( 0, texture );
65 mUploadCompletedSignal.Emit();
69 void SetSize( uint32_t width, uint32_t height )
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 bool Render( uint32_t frameNumber )
85 if( frameNumber == 1 && mPreviousFrame != frameNumber )
87 mPreviousFrame = frameNumber;
91 mPreviousFrame = frameNumber;
95 uint32_t GetTotalFrameNumber() const
100 float GetFrameRate() const
105 void GetDefaultSize( uint32_t& width, uint32_t& height ) const
111 void GetLayerInfo( Property::Map& map ) const
115 Dali::VectorAnimationRenderer::UploadCompletedSignalType& UploadCompletedSignal()
117 return mUploadCompletedSignal;
122 static uint32_t mCount;
125 Dali::Renderer mRenderer;
128 uint32_t mPreviousFrame;
130 Dali::VectorAnimationRenderer::UploadCompletedSignalType mUploadCompletedSignal;
133 uint32_t VectorAnimationRenderer::mCount = 0;
135 inline VectorAnimationRenderer& GetImplementation( Dali::VectorAnimationRenderer& renderer )
137 DALI_ASSERT_ALWAYS( renderer && "VectorAnimationRenderer handle is empty." );
138 BaseObject& handle = renderer.GetBaseObject();
139 return static_cast< Internal::Adaptor::VectorAnimationRenderer& >( handle );
142 inline const VectorAnimationRenderer& GetImplementation( const Dali::VectorAnimationRenderer& renderer )
144 DALI_ASSERT_ALWAYS( renderer && "VectorAnimationRenderer handle is empty." );
145 const BaseObject& handle = renderer.GetBaseObject();
146 return static_cast< const Internal::Adaptor::VectorAnimationRenderer& >( handle );
149 } // namespace Adaptor
151 } // namespace Internal
154 /********************************************************************************/
155 /********************************* PUBLIC CLASS *******************************/
156 /********************************************************************************/
158 VectorAnimationRenderer VectorAnimationRenderer::New( const std::string& url )
160 Internal::Adaptor::VectorAnimationRenderer* animationRenderer = new Internal::Adaptor::VectorAnimationRenderer( url );
162 return VectorAnimationRenderer( animationRenderer );
165 VectorAnimationRenderer::VectorAnimationRenderer()
169 VectorAnimationRenderer::~VectorAnimationRenderer()
173 VectorAnimationRenderer::VectorAnimationRenderer( Internal::Adaptor::VectorAnimationRenderer* internal )
174 : BaseHandle( internal )
178 VectorAnimationRenderer::VectorAnimationRenderer( const VectorAnimationRenderer& handle )
179 : BaseHandle( handle )
183 VectorAnimationRenderer& VectorAnimationRenderer::operator=( const VectorAnimationRenderer& rhs )
185 BaseHandle::operator=( rhs );
189 void VectorAnimationRenderer::SetRenderer( Renderer renderer )
191 Internal::Adaptor::GetImplementation( *this ).SetRenderer( renderer );
194 void VectorAnimationRenderer::SetSize( uint32_t width, uint32_t height )
196 Internal::Adaptor::GetImplementation( *this ).SetSize( width, height );
199 bool VectorAnimationRenderer::Render( uint32_t frameNumber )
201 return Internal::Adaptor::GetImplementation( *this ).Render( frameNumber );
204 uint32_t VectorAnimationRenderer::GetTotalFrameNumber() const
206 return Internal::Adaptor::GetImplementation( *this ).GetTotalFrameNumber();
209 float VectorAnimationRenderer::GetFrameRate() const
211 return Internal::Adaptor::GetImplementation( *this ).GetFrameRate();
214 void VectorAnimationRenderer::GetDefaultSize( uint32_t& width, uint32_t& height ) const
216 Internal::Adaptor::GetImplementation( *this ).GetDefaultSize( width, height );
219 void VectorAnimationRenderer::GetLayerInfo( Property::Map& map ) const
221 Internal::Adaptor::GetImplementation( *this ).GetLayerInfo( map );
224 VectorAnimationRenderer::UploadCompletedSignalType& VectorAnimationRenderer::UploadCompletedSignal()
226 return Internal::Adaptor::GetImplementation( *this ).UploadCompletedSignal();