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