[dali_1.4.33] 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
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   {
42   }
43
44   void SetRenderer( Dali::Renderer renderer )
45   {
46     mRenderer = renderer;
47
48     if( mWidth != 0 && mHeight != 0 )
49     {
50       Dali::TextureSet textureSet = mRenderer.GetTextures();
51       Dali::Texture texture = Dali::Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, mWidth, mHeight );
52       textureSet.SetTexture( 0, texture );
53     }
54   }
55
56   void SetSize( uint32_t width, uint32_t height )
57   {
58     mWidth = width;
59     mHeight = height;
60
61     if( mRenderer )
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     }
67   }
68
69   void StopRender()
70   {
71   }
72
73   bool Render( uint32_t frameNumber )
74   {
75     if( frameNumber == 1 && mPreviousFrame != frameNumber )
76     {
77       mPreviousFrame = frameNumber;
78       // For test corverage
79       return false;
80     }
81     mPreviousFrame = frameNumber;
82     return true;
83   }
84
85   uint32_t GetTotalFrameNumber() const
86   {
87     return 5;
88   }
89
90   float GetFrameRate() const
91   {
92     return 60.0f;
93   }
94
95   void GetDefaultSize( uint32_t& width, uint32_t& height ) const
96   {
97     width = 100;
98     height = 100;
99   }
100
101 public:
102
103   std::string mUrl;
104   Dali::Renderer mRenderer;
105   uint32_t mWidth;
106   uint32_t mHeight;
107   uint32_t mPreviousFrame;
108 };
109
110 inline VectorAnimationRenderer& GetImplementation( Dali::VectorAnimationRenderer& renderer )
111 {
112   DALI_ASSERT_ALWAYS( renderer && "VectorAnimationRenderer handle is empty." );
113   BaseObject& handle = renderer.GetBaseObject();
114   return static_cast< Internal::Adaptor::VectorAnimationRenderer& >( handle );
115 }
116
117 inline const VectorAnimationRenderer& GetImplementation( const Dali::VectorAnimationRenderer& renderer )
118 {
119   DALI_ASSERT_ALWAYS( renderer && "VectorAnimationRenderer handle is empty." );
120   const BaseObject& handle = renderer.GetBaseObject();
121   return static_cast< const Internal::Adaptor::VectorAnimationRenderer& >( handle );
122 }
123
124 } // namespace Adaptor
125
126 } // namespace Internal
127
128
129 /********************************************************************************/
130 /*********************************  PUBLIC CLASS  *******************************/
131 /********************************************************************************/
132
133 VectorAnimationRenderer VectorAnimationRenderer::New( const std::string& url )
134 {
135   Internal::Adaptor::VectorAnimationRenderer* animationRenderer = new Internal::Adaptor::VectorAnimationRenderer( url );
136
137   return VectorAnimationRenderer( animationRenderer );
138 }
139
140 VectorAnimationRenderer::VectorAnimationRenderer()
141 {
142 }
143
144 VectorAnimationRenderer::~VectorAnimationRenderer()
145 {
146 }
147
148 VectorAnimationRenderer::VectorAnimationRenderer( Internal::Adaptor::VectorAnimationRenderer* internal )
149 : BaseHandle( internal )
150 {
151 }
152
153 VectorAnimationRenderer::VectorAnimationRenderer( const VectorAnimationRenderer& handle )
154 : BaseHandle( handle )
155 {
156 }
157
158 VectorAnimationRenderer& VectorAnimationRenderer::operator=( const VectorAnimationRenderer& rhs )
159 {
160   BaseHandle::operator=( rhs );
161   return *this;
162 }
163
164 void VectorAnimationRenderer::SetRenderer( Renderer renderer )
165 {
166   Internal::Adaptor::GetImplementation( *this ).SetRenderer( renderer );
167 }
168
169 void VectorAnimationRenderer::SetSize( uint32_t width, uint32_t height )
170 {
171   Internal::Adaptor::GetImplementation( *this ).SetSize( width, height );
172 }
173
174 void VectorAnimationRenderer::StopRender()
175 {
176   Internal::Adaptor::GetImplementation( *this ).StopRender();
177 }
178
179 bool VectorAnimationRenderer::Render( uint32_t frameNumber )
180 {
181   return Internal::Adaptor::GetImplementation( *this ).Render( frameNumber );
182 }
183
184 uint32_t VectorAnimationRenderer::GetTotalFrameNumber() const
185 {
186   return Internal::Adaptor::GetImplementation( *this ).GetTotalFrameNumber();
187 }
188
189 float VectorAnimationRenderer::GetFrameRate() const
190 {
191   return Internal::Adaptor::GetImplementation( *this ).GetFrameRate();
192 }
193
194 void VectorAnimationRenderer::GetDefaultSize( uint32_t& width, uint32_t& height ) const
195 {
196   Internal::Adaptor::GetImplementation( *this ).GetDefaultSize( width, height );
197 }
198
199 } // namespace Dali;
200