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 Dali::VectorAnimationRenderer::UploadCompletedSignalType& UploadCompletedSignal()
113 return mUploadCompletedSignal;
118 static uint32_t mCount;
121 Dali::Renderer mRenderer;
124 uint32_t mPreviousFrame;
126 Dali::VectorAnimationRenderer::UploadCompletedSignalType mUploadCompletedSignal;
129 uint32_t VectorAnimationRenderer::mCount = 0;
131 inline VectorAnimationRenderer& GetImplementation( Dali::VectorAnimationRenderer& renderer )
133 DALI_ASSERT_ALWAYS( renderer && "VectorAnimationRenderer handle is empty." );
134 BaseObject& handle = renderer.GetBaseObject();
135 return static_cast< Internal::Adaptor::VectorAnimationRenderer& >( handle );
138 inline const VectorAnimationRenderer& GetImplementation( const Dali::VectorAnimationRenderer& renderer )
140 DALI_ASSERT_ALWAYS( renderer && "VectorAnimationRenderer handle is empty." );
141 const BaseObject& handle = renderer.GetBaseObject();
142 return static_cast< const Internal::Adaptor::VectorAnimationRenderer& >( handle );
145 } // namespace Adaptor
147 } // namespace Internal
150 /********************************************************************************/
151 /********************************* PUBLIC CLASS *******************************/
152 /********************************************************************************/
154 VectorAnimationRenderer VectorAnimationRenderer::New( const std::string& url )
156 Internal::Adaptor::VectorAnimationRenderer* animationRenderer = new Internal::Adaptor::VectorAnimationRenderer( url );
158 return VectorAnimationRenderer( animationRenderer );
161 VectorAnimationRenderer::VectorAnimationRenderer()
165 VectorAnimationRenderer::~VectorAnimationRenderer()
169 VectorAnimationRenderer::VectorAnimationRenderer( Internal::Adaptor::VectorAnimationRenderer* internal )
170 : BaseHandle( internal )
174 VectorAnimationRenderer::VectorAnimationRenderer( const VectorAnimationRenderer& handle )
175 : BaseHandle( handle )
179 VectorAnimationRenderer& VectorAnimationRenderer::operator=( const VectorAnimationRenderer& rhs )
181 BaseHandle::operator=( rhs );
185 void VectorAnimationRenderer::SetRenderer( Renderer renderer )
187 Internal::Adaptor::GetImplementation( *this ).SetRenderer( renderer );
190 void VectorAnimationRenderer::SetSize( uint32_t width, uint32_t height )
192 Internal::Adaptor::GetImplementation( *this ).SetSize( width, height );
195 bool VectorAnimationRenderer::Render( uint32_t frameNumber )
197 return Internal::Adaptor::GetImplementation( *this ).Render( frameNumber );
200 uint32_t VectorAnimationRenderer::GetTotalFrameNumber() const
202 return Internal::Adaptor::GetImplementation( *this ).GetTotalFrameNumber();
205 float VectorAnimationRenderer::GetFrameRate() const
207 return Internal::Adaptor::GetImplementation( *this ).GetFrameRate();
210 void VectorAnimationRenderer::GetDefaultSize( uint32_t& width, uint32_t& height ) const
212 Internal::Adaptor::GetImplementation( *this ).GetDefaultSize( width, height );
215 VectorAnimationRenderer::UploadCompletedSignalType& VectorAnimationRenderer::UploadCompletedSignal()
217 return Internal::Adaptor::GetImplementation( *this ).UploadCompletedSignal();