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