(Vector) Add CONTENT_INFO property
[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   void GetLayerInfo( Property::Map& map ) const
112   {
113   }
114
115   Dali::VectorAnimationRenderer::UploadCompletedSignalType& UploadCompletedSignal()
116   {
117     return mUploadCompletedSignal;
118   }
119
120 public:
121
122   static uint32_t mCount;
123
124   std::string mUrl;
125   Dali::Renderer mRenderer;
126   uint32_t mWidth;
127   uint32_t mHeight;
128   uint32_t mPreviousFrame;
129   float mFrameRate;
130   Dali::VectorAnimationRenderer::UploadCompletedSignalType mUploadCompletedSignal;
131 };
132
133 uint32_t VectorAnimationRenderer::mCount = 0;
134
135 inline VectorAnimationRenderer& GetImplementation( Dali::VectorAnimationRenderer& renderer )
136 {
137   DALI_ASSERT_ALWAYS( renderer && "VectorAnimationRenderer handle is empty." );
138   BaseObject& handle = renderer.GetBaseObject();
139   return static_cast< Internal::Adaptor::VectorAnimationRenderer& >( handle );
140 }
141
142 inline const VectorAnimationRenderer& GetImplementation( const Dali::VectorAnimationRenderer& renderer )
143 {
144   DALI_ASSERT_ALWAYS( renderer && "VectorAnimationRenderer handle is empty." );
145   const BaseObject& handle = renderer.GetBaseObject();
146   return static_cast< const Internal::Adaptor::VectorAnimationRenderer& >( handle );
147 }
148
149 } // namespace Adaptor
150
151 } // namespace Internal
152
153
154 /********************************************************************************/
155 /*********************************  PUBLIC CLASS  *******************************/
156 /********************************************************************************/
157
158 VectorAnimationRenderer VectorAnimationRenderer::New( const std::string& url )
159 {
160   Internal::Adaptor::VectorAnimationRenderer* animationRenderer = new Internal::Adaptor::VectorAnimationRenderer( url );
161
162   return VectorAnimationRenderer( animationRenderer );
163 }
164
165 VectorAnimationRenderer::VectorAnimationRenderer()
166 {
167 }
168
169 VectorAnimationRenderer::~VectorAnimationRenderer()
170 {
171 }
172
173 VectorAnimationRenderer::VectorAnimationRenderer( Internal::Adaptor::VectorAnimationRenderer* internal )
174 : BaseHandle( internal )
175 {
176 }
177
178 VectorAnimationRenderer::VectorAnimationRenderer( const VectorAnimationRenderer& handle )
179 : BaseHandle( handle )
180 {
181 }
182
183 VectorAnimationRenderer& VectorAnimationRenderer::operator=( const VectorAnimationRenderer& rhs )
184 {
185   BaseHandle::operator=( rhs );
186   return *this;
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   Internal::Adaptor::GetImplementation( *this ).GetLayerInfo( map );
222 }
223
224 VectorAnimationRenderer::UploadCompletedSignalType& VectorAnimationRenderer::UploadCompletedSignal()
225 {
226   return Internal::Adaptor::GetImplementation( *this ).UploadCompletedSignal();
227 }
228
229 } // namespace Dali;
230