[dali_1.4.51] Merge branch '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 #include <toolkit-vector-animation-renderer.h>
22
23 namespace Dali
24 {
25
26 namespace Internal
27 {
28
29 namespace Adaptor
30 {
31
32 class VectorAnimationRenderer: public Dali::BaseObject
33 {
34 public:
35
36   VectorAnimationRenderer( const std::string& url )
37   : mUrl( url ),
38     mRenderer(),
39     mWidth( 0 ),
40     mHeight( 0 ),
41     mPreviousFrame( 0 ),
42     mFrameRate( 60.0f )
43   {
44     mCount++;
45
46     if( mCount == 2 )
47     {
48       mFrameRate = 0.1f;
49     }
50   }
51
52   ~VectorAnimationRenderer()
53   {
54     mCount--;
55   }
56
57   void SetRenderer( Dali::Renderer renderer )
58   {
59     mRenderer = renderer;
60
61     if( mWidth != 0 && mHeight != 0 )
62     {
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();
67     }
68   }
69
70   void SetSize( uint32_t width, uint32_t height )
71   {
72     mWidth = width;
73     mHeight = height;
74
75     if( mRenderer )
76     {
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();
81     }
82   }
83
84   bool Render( uint32_t frameNumber )
85   {
86     if( frameNumber == 1 && mPreviousFrame != frameNumber )
87     {
88       mPreviousFrame = frameNumber;
89       // For test corverage
90       return false;
91     }
92     mPreviousFrame = frameNumber;
93     return true;
94   }
95
96   uint32_t GetTotalFrameNumber() const
97   {
98     return VECTOR_ANIMATION_TOTAL_FRAME_NUMBER;
99   }
100
101   float GetFrameRate() const
102   {
103     return mFrameRate;
104   }
105
106   void GetDefaultSize( uint32_t& width, uint32_t& height ) const
107   {
108     width = 100;
109     height = 100;
110   }
111
112   bool GetMarkerInfo( const std::string& marker, uint32_t& startFrame, uint32_t& endFrame ) const
113   {
114     if( marker.compare( VECTOR_ANIMATION_MARKER_NAME_1 ) == 0 )
115     {
116       startFrame = VECTOR_ANIMATION_MARKER_START_FRAME_1;
117       endFrame = VECTOR_ANIMATION_MARKER_END_FRAME_1;
118     }
119     else if( marker.compare( VECTOR_ANIMATION_MARKER_NAME_2 ) == 0 )
120     {
121       startFrame = VECTOR_ANIMATION_MARKER_START_FRAME_2;
122       endFrame = VECTOR_ANIMATION_MARKER_END_FRAME_2;
123     }
124     else
125     {
126       return false;
127     }
128     return true;
129   }
130
131   Dali::VectorAnimationRenderer::UploadCompletedSignalType& UploadCompletedSignal()
132   {
133     return mUploadCompletedSignal;
134   }
135
136 public:
137
138   static uint32_t mCount;
139
140   std::string mUrl;
141   Dali::Renderer mRenderer;
142   uint32_t mWidth;
143   uint32_t mHeight;
144   uint32_t mPreviousFrame;
145   float mFrameRate;
146   Dali::VectorAnimationRenderer::UploadCompletedSignalType mUploadCompletedSignal;
147 };
148
149 uint32_t VectorAnimationRenderer::mCount = 0;
150
151 inline VectorAnimationRenderer& GetImplementation( Dali::VectorAnimationRenderer& renderer )
152 {
153   DALI_ASSERT_ALWAYS( renderer && "VectorAnimationRenderer handle is empty." );
154   BaseObject& handle = renderer.GetBaseObject();
155   return static_cast< Internal::Adaptor::VectorAnimationRenderer& >( handle );
156 }
157
158 inline const VectorAnimationRenderer& GetImplementation( const Dali::VectorAnimationRenderer& renderer )
159 {
160   DALI_ASSERT_ALWAYS( renderer && "VectorAnimationRenderer handle is empty." );
161   const BaseObject& handle = renderer.GetBaseObject();
162   return static_cast< const Internal::Adaptor::VectorAnimationRenderer& >( handle );
163 }
164
165 } // namespace Adaptor
166
167 } // namespace Internal
168
169
170 /********************************************************************************/
171 /*********************************  PUBLIC CLASS  *******************************/
172 /********************************************************************************/
173
174 VectorAnimationRenderer VectorAnimationRenderer::New( const std::string& url )
175 {
176   Internal::Adaptor::VectorAnimationRenderer* animationRenderer = new Internal::Adaptor::VectorAnimationRenderer( url );
177
178   return VectorAnimationRenderer( animationRenderer );
179 }
180
181 VectorAnimationRenderer::VectorAnimationRenderer()
182 {
183 }
184
185 VectorAnimationRenderer::~VectorAnimationRenderer()
186 {
187 }
188
189 VectorAnimationRenderer::VectorAnimationRenderer( Internal::Adaptor::VectorAnimationRenderer* internal )
190 : BaseHandle( internal )
191 {
192 }
193
194 VectorAnimationRenderer::VectorAnimationRenderer( const VectorAnimationRenderer& handle )
195 : BaseHandle( handle )
196 {
197 }
198
199 VectorAnimationRenderer& VectorAnimationRenderer::operator=( const VectorAnimationRenderer& rhs )
200 {
201   BaseHandle::operator=( rhs );
202   return *this;
203 }
204
205 void VectorAnimationRenderer::Finalize()
206 {
207 }
208
209 void VectorAnimationRenderer::SetRenderer( Renderer renderer )
210 {
211   Internal::Adaptor::GetImplementation( *this ).SetRenderer( renderer );
212 }
213
214 void VectorAnimationRenderer::SetSize( uint32_t width, uint32_t height )
215 {
216   Internal::Adaptor::GetImplementation( *this ).SetSize( width, height );
217 }
218
219 bool VectorAnimationRenderer::Render( uint32_t frameNumber )
220 {
221   return Internal::Adaptor::GetImplementation( *this ).Render( frameNumber );
222 }
223
224 uint32_t VectorAnimationRenderer::GetTotalFrameNumber() const
225 {
226   return Internal::Adaptor::GetImplementation( *this ).GetTotalFrameNumber();
227 }
228
229 float VectorAnimationRenderer::GetFrameRate() const
230 {
231   return Internal::Adaptor::GetImplementation( *this ).GetFrameRate();
232 }
233
234 void VectorAnimationRenderer::GetDefaultSize( uint32_t& width, uint32_t& height ) const
235 {
236   Internal::Adaptor::GetImplementation( *this ).GetDefaultSize( width, height );
237 }
238
239 void VectorAnimationRenderer::GetLayerInfo( Property::Map& map ) const
240 {
241 }
242
243 bool VectorAnimationRenderer::GetMarkerInfo( const std::string& marker, uint32_t& startFrame, uint32_t& endFrame ) const
244 {
245   return Internal::Adaptor::GetImplementation( *this ).GetMarkerInfo( marker, startFrame, endFrame );
246 }
247
248 VectorAnimationRenderer::UploadCompletedSignalType& VectorAnimationRenderer::UploadCompletedSignal()
249 {
250   return Internal::Adaptor::GetImplementation( *this ).UploadCompletedSignal();
251 }
252
253 } // namespace Dali;
254