Merge "Text cleaning." into devel/master
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / toolkit-vector-animation-renderer.cpp
1 /*
2  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
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
22 namespace Dali
23 {
24
25 namespace Internal
26 {
27
28 namespace Adaptor
29 {
30
31 class VectorAnimationRenderer: public Dali::BaseObject
32 {
33 public:
34
35   VectorAnimationRenderer( const std::string& url )
36   : mUrl( url ),
37     mRenderer(),
38     mWidth( 0 ),
39     mHeight( 0 ),
40     mPreviousFrame( 0 ),
41     mFrameRate( 60.0f )
42   {
43     mCount++;
44
45     if( mCount == 2 )
46     {
47       mFrameRate = 0.1f;
48     }
49   }
50
51   ~VectorAnimationRenderer()
52   {
53     mCount--;
54   }
55
56   void SetRenderer( Dali::Renderer renderer )
57   {
58     mRenderer = renderer;
59
60     if( mWidth != 0 && mHeight != 0 )
61     {
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();
66     }
67   }
68
69   void SetSize( uint32_t width, uint32_t height )
70   {
71     mWidth = width;
72     mHeight = height;
73
74     if( mRenderer )
75     {
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();
80     }
81   }
82
83   bool Render( uint32_t frameNumber )
84   {
85     if( frameNumber == 1 && mPreviousFrame != frameNumber )
86     {
87       mPreviousFrame = frameNumber;
88       // For test corverage
89       return false;
90     }
91     mPreviousFrame = frameNumber;
92     return true;
93   }
94
95   uint32_t GetTotalFrameNumber() const
96   {
97     return 5;
98   }
99
100   float GetFrameRate() const
101   {
102     return mFrameRate;
103   }
104
105   void GetDefaultSize( uint32_t& width, uint32_t& height ) const
106   {
107     width = 100;
108     height = 100;
109   }
110
111   Dali::VectorAnimationRenderer::UploadCompletedSignalType& UploadCompletedSignal()
112   {
113     return mUploadCompletedSignal;
114   }
115
116 public:
117
118   static uint32_t mCount;
119
120   std::string mUrl;
121   Dali::Renderer mRenderer;
122   uint32_t mWidth;
123   uint32_t mHeight;
124   uint32_t mPreviousFrame;
125   float mFrameRate;
126   Dali::VectorAnimationRenderer::UploadCompletedSignalType mUploadCompletedSignal;
127 };
128
129 uint32_t VectorAnimationRenderer::mCount = 0;
130
131 inline VectorAnimationRenderer& GetImplementation( Dali::VectorAnimationRenderer& renderer )
132 {
133   DALI_ASSERT_ALWAYS( renderer && "VectorAnimationRenderer handle is empty." );
134   BaseObject& handle = renderer.GetBaseObject();
135   return static_cast< Internal::Adaptor::VectorAnimationRenderer& >( handle );
136 }
137
138 inline const VectorAnimationRenderer& GetImplementation( const Dali::VectorAnimationRenderer& renderer )
139 {
140   DALI_ASSERT_ALWAYS( renderer && "VectorAnimationRenderer handle is empty." );
141   const BaseObject& handle = renderer.GetBaseObject();
142   return static_cast< const Internal::Adaptor::VectorAnimationRenderer& >( handle );
143 }
144
145 } // namespace Adaptor
146
147 } // namespace Internal
148
149
150 /********************************************************************************/
151 /*********************************  PUBLIC CLASS  *******************************/
152 /********************************************************************************/
153
154 VectorAnimationRenderer VectorAnimationRenderer::New( const std::string& url )
155 {
156   Internal::Adaptor::VectorAnimationRenderer* animationRenderer = new Internal::Adaptor::VectorAnimationRenderer( url );
157
158   return VectorAnimationRenderer( animationRenderer );
159 }
160
161 VectorAnimationRenderer::VectorAnimationRenderer()
162 {
163 }
164
165 VectorAnimationRenderer::~VectorAnimationRenderer()
166 {
167 }
168
169 VectorAnimationRenderer::VectorAnimationRenderer( Internal::Adaptor::VectorAnimationRenderer* internal )
170 : BaseHandle( internal )
171 {
172 }
173
174 VectorAnimationRenderer::VectorAnimationRenderer( const VectorAnimationRenderer& handle )
175 : BaseHandle( handle )
176 {
177 }
178
179 VectorAnimationRenderer& VectorAnimationRenderer::operator=( const VectorAnimationRenderer& rhs )
180 {
181   BaseHandle::operator=( rhs );
182   return *this;
183 }
184
185 void VectorAnimationRenderer::Finalize()
186 {
187 }
188
189 void VectorAnimationRenderer::SetRenderer( Renderer renderer )
190 {
191   Internal::Adaptor::GetImplementation( *this ).SetRenderer( renderer );
192 }
193
194 void VectorAnimationRenderer::SetSize( uint32_t width, uint32_t height )
195 {
196   Internal::Adaptor::GetImplementation( *this ).SetSize( width, height );
197 }
198
199 bool VectorAnimationRenderer::Render( uint32_t frameNumber )
200 {
201   return Internal::Adaptor::GetImplementation( *this ).Render( frameNumber );
202 }
203
204 uint32_t VectorAnimationRenderer::GetTotalFrameNumber() const
205 {
206   return Internal::Adaptor::GetImplementation( *this ).GetTotalFrameNumber();
207 }
208
209 float VectorAnimationRenderer::GetFrameRate() const
210 {
211   return Internal::Adaptor::GetImplementation( *this ).GetFrameRate();
212 }
213
214 void VectorAnimationRenderer::GetDefaultSize( uint32_t& width, uint32_t& height ) const
215 {
216   Internal::Adaptor::GetImplementation( *this ).GetDefaultSize( width, height );
217 }
218
219 void VectorAnimationRenderer::GetLayerInfo( Property::Map& map ) const
220 {
221 }
222
223 VectorAnimationRenderer::UploadCompletedSignalType& VectorAnimationRenderer::UploadCompletedSignal()
224 {
225   return Internal::Adaptor::GetImplementation( *this ).UploadCompletedSignal();
226 }
227
228 } // namespace Dali;
229