Revert "[Tizen] Appendix log for ttrace + Print keycode and timestamp"
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-DecoratedVisualRenderer.cpp
1 /*
2  * Copyright (c) 2023 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 // EXTERNAL INCLUDES
19 #include <dali/devel-api/actors/actor-devel.h>
20 #include <dali/devel-api/common/capabilities.h>
21 #include <dali/devel-api/common/stage.h>
22 #include <dali/devel-api/rendering/renderer-devel.h>
23 #include <dali/integration-api/render-task-list-integ.h>
24 #include <dali/public-api/dali-core.h>
25 #include <cstdio>
26 #include <string>
27
28 // INTERNAL INCLUDES
29 #include <dali-test-suite-utils.h>
30 #include <mesh-builder.h>
31 #include <test-trace-call-stack.h>
32 #include "test-graphics-command-buffer.h"
33
34 using namespace Dali;
35
36 void decorated_visual_renderer_test_startup(void)
37 {
38   test_return_value = TET_UNDEF;
39 }
40
41 void decorated_visual_renderer_test_cleanup(void)
42 {
43   test_return_value = TET_PASS;
44 }
45
46 int UtcDaliDecoratedVisualRendererNew01(void)
47 {
48   TestApplication application;
49
50   Geometry                geometry = CreateQuadGeometry();
51   Shader                  shader   = CreateShader();
52   DecoratedVisualRenderer renderer = DecoratedVisualRenderer::New(geometry, shader);
53
54   DALI_TEST_EQUALS((bool)renderer, true, TEST_LOCATION);
55   END_TEST;
56 }
57
58 int UtcDaliDecoratedVisualRendererNew02(void)
59 {
60   TestApplication         application;
61   DecoratedVisualRenderer renderer;
62   DALI_TEST_EQUALS((bool)renderer, false, TEST_LOCATION);
63   END_TEST;
64 }
65
66 int UtcDaliDecoratedVisualRendererCopyConstructor(void)
67 {
68   TestApplication application;
69
70   Geometry                geometry = CreateQuadGeometry();
71   Shader                  shader   = CreateShader();
72   DecoratedVisualRenderer renderer = DecoratedVisualRenderer::New(geometry, shader);
73
74   DecoratedVisualRenderer rendererCopy(renderer);
75   DALI_TEST_EQUALS((bool)rendererCopy, true, TEST_LOCATION);
76
77   END_TEST;
78 }
79
80 int UtcDaliDecoratedVisualRendererAssignmentOperator(void)
81 {
82   TestApplication application;
83
84   Geometry                geometry = CreateQuadGeometry();
85   Shader                  shader   = CreateShader();
86   DecoratedVisualRenderer renderer = DecoratedVisualRenderer::New(geometry, shader);
87
88   DecoratedVisualRenderer renderer2;
89   DALI_TEST_EQUALS((bool)renderer2, false, TEST_LOCATION);
90
91   renderer2 = renderer;
92   DALI_TEST_EQUALS((bool)renderer2, true, TEST_LOCATION);
93   END_TEST;
94 }
95
96 int UtcDaliDecoratedVisualRendererMoveConstructor(void)
97 {
98   TestApplication application;
99
100   Geometry                geometry = CreateQuadGeometry();
101   Shader                  shader   = Shader::New("vertexSrc", "fragmentSrc");
102   DecoratedVisualRenderer renderer = DecoratedVisualRenderer::New(geometry, shader);
103   DALI_TEST_CHECK(renderer);
104   DALI_TEST_EQUALS(1, renderer.GetBaseObject().ReferenceCount(), TEST_LOCATION);
105   DALI_TEST_EQUALS(renderer.GetProperty<Vector3>(VisualRenderer::Property::VISUAL_MIX_COLOR), Vector3::ONE, TEST_LOCATION);
106   DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(DecoratedVisualRenderer::Property::BORDERLINE_COLOR), Color::BLACK, TEST_LOCATION);
107
108   auto testColor           = Vector3(1.0f, 0.0f, 1.0f);
109   auto testBorderlineColor = Vector4(1.0f, 0.0f, 1.0f, 0.5f);
110   renderer.SetProperty(VisualRenderer::Property::VISUAL_MIX_COLOR, testColor);
111   renderer.SetProperty(DecoratedVisualRenderer::Property::BORDERLINE_COLOR, testBorderlineColor);
112   application.SendNotification();
113   application.Render();
114   DALI_TEST_EQUALS(renderer.GetProperty<Vector3>(VisualRenderer::Property::VISUAL_MIX_COLOR), testColor, TEST_LOCATION);
115   DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(DecoratedVisualRenderer::Property::BORDERLINE_COLOR), testBorderlineColor, TEST_LOCATION);
116
117   DecoratedVisualRenderer move = std::move(renderer);
118   DALI_TEST_CHECK(move);
119   DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
120   DALI_TEST_EQUALS(move.GetProperty<Vector3>(VisualRenderer::Property::VISUAL_MIX_COLOR), testColor, TEST_LOCATION);
121   DALI_TEST_EQUALS(move.GetProperty<Vector4>(DecoratedVisualRenderer::Property::BORDERLINE_COLOR), testBorderlineColor, TEST_LOCATION);
122
123   DALI_TEST_CHECK(!renderer);
124
125   END_TEST;
126 }
127
128 int UtcDaliDecoratedVisualRendererMoveAssignment(void)
129 {
130   TestApplication application;
131
132   Geometry                geometry = CreateQuadGeometry();
133   Shader                  shader   = Shader::New("vertexSrc", "fragmentSrc");
134   DecoratedVisualRenderer renderer = DecoratedVisualRenderer::New(geometry, shader);
135   DALI_TEST_CHECK(renderer);
136   DALI_TEST_EQUALS(1, renderer.GetBaseObject().ReferenceCount(), TEST_LOCATION);
137   DALI_TEST_EQUALS(renderer.GetProperty<Vector3>(VisualRenderer::Property::VISUAL_MIX_COLOR), Vector3::ONE, TEST_LOCATION);
138   DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(DecoratedVisualRenderer::Property::BORDERLINE_COLOR), Color::BLACK, TEST_LOCATION);
139
140   auto testColor           = Vector3(1.0f, 0.0f, 1.0f);
141   auto testBorderlineColor = Vector4(1.0f, 0.0f, 1.0f, 0.5f);
142   renderer.SetProperty(VisualRenderer::Property::VISUAL_MIX_COLOR, testColor);
143   renderer.SetProperty(DecoratedVisualRenderer::Property::BORDERLINE_COLOR, testBorderlineColor);
144   application.SendNotification();
145   application.Render();
146   DALI_TEST_EQUALS(renderer.GetProperty<Vector3>(VisualRenderer::Property::VISUAL_MIX_COLOR), testColor, TEST_LOCATION);
147   DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(DecoratedVisualRenderer::Property::BORDERLINE_COLOR), testBorderlineColor, TEST_LOCATION);
148
149   DecoratedVisualRenderer move;
150   move = std::move(renderer);
151   DALI_TEST_CHECK(move);
152   DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
153   DALI_TEST_EQUALS(move.GetProperty<Vector3>(VisualRenderer::Property::VISUAL_MIX_COLOR), testColor, TEST_LOCATION);
154   DALI_TEST_EQUALS(move.GetProperty<Vector4>(DecoratedVisualRenderer::Property::BORDERLINE_COLOR), testBorderlineColor, TEST_LOCATION);
155   DALI_TEST_CHECK(!renderer);
156
157   END_TEST;
158 }
159
160 int UtcDaliDecoratedVisualRendererDownCast01(void)
161 {
162   TestApplication application;
163
164   Geometry                geometry = CreateQuadGeometry();
165   Shader                  shader   = CreateShader();
166   DecoratedVisualRenderer renderer = DecoratedVisualRenderer::New(geometry, shader);
167
168   BaseHandle              handle(renderer);
169   DecoratedVisualRenderer renderer2 = DecoratedVisualRenderer::DownCast(handle);
170   DALI_TEST_EQUALS((bool)renderer2, true, TEST_LOCATION);
171   END_TEST;
172 }
173
174 int UtcDaliDecoratedVisualRendererDownCast02(void)
175 {
176   TestApplication application;
177
178   Handle                  handle   = Handle::New(); // Create a custom object
179   DecoratedVisualRenderer renderer = DecoratedVisualRenderer::DownCast(handle);
180   DALI_TEST_EQUALS((bool)renderer, false, TEST_LOCATION);
181   END_TEST;
182 }
183
184 // using a template to auto deduce the parameter types
185 template<typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8>
186 void TEST_RENDERER_PROPERTY(P1 renderer, P2 stringName, P3 type, P4 isWriteable, P5 isAnimateable, P6 isConstraintInput, P7 enumName, P8 LOCATION)
187 {
188   DALI_TEST_EQUALS(renderer.GetPropertyName(enumName), stringName, LOCATION);
189   DALI_TEST_EQUALS(renderer.GetPropertyIndex(stringName), static_cast<Property::Index>(enumName), LOCATION);
190   DALI_TEST_EQUALS(renderer.GetPropertyType(enumName), type, LOCATION);
191   DALI_TEST_EQUALS(renderer.IsPropertyWritable(enumName), isWriteable, LOCATION);
192   DALI_TEST_EQUALS(renderer.IsPropertyAnimatable(enumName), isAnimateable, LOCATION);
193   DALI_TEST_EQUALS(renderer.IsPropertyAConstraintInput(enumName), isConstraintInput, LOCATION);
194 }
195
196 int UtcDaliDecoratedVisualRendererDefaultProperties(void)
197 {
198   TestApplication         application;
199   Geometry                geometry           = CreateQuadGeometry();
200   Shader                  shader             = CreateShader();
201   DecoratedVisualRenderer renderer           = DecoratedVisualRenderer::New(geometry, shader);
202   VisualRenderer          baseVisualRenderer = VisualRenderer::New(geometry, shader);
203   Renderer                baseRenderer       = Renderer::New(geometry, shader);
204
205   DALI_TEST_EQUALS(baseRenderer.GetPropertyCount(), 27, TEST_LOCATION);
206   DALI_TEST_EQUALS(baseVisualRenderer.GetPropertyCount(), 27 + 8, TEST_LOCATION);
207   DALI_TEST_EQUALS(renderer.GetPropertyCount(), 27 + 8 + 6, TEST_LOCATION);
208
209   TEST_RENDERER_PROPERTY(renderer, "cornerRadius", Property::VECTOR4, true, true, true, DecoratedVisualRenderer::Property::CORNER_RADIUS, TEST_LOCATION);
210   TEST_RENDERER_PROPERTY(renderer, "cornerRadiusPolicy", Property::FLOAT, true, false, true, DecoratedVisualRenderer::Property::CORNER_RADIUS_POLICY, TEST_LOCATION);
211   TEST_RENDERER_PROPERTY(renderer, "borderlineWidth", Property::FLOAT, true, true, true, DecoratedVisualRenderer::Property::BORDERLINE_WIDTH, TEST_LOCATION);
212   TEST_RENDERER_PROPERTY(renderer, "borderlineColor", Property::VECTOR4, true, true, true, DecoratedVisualRenderer::Property::BORDERLINE_COLOR, TEST_LOCATION);
213   TEST_RENDERER_PROPERTY(renderer, "borderlineOffset", Property::FLOAT, true, true, true, DecoratedVisualRenderer::Property::BORDERLINE_OFFSET, TEST_LOCATION);
214   TEST_RENDERER_PROPERTY(renderer, "blurRadius", Property::FLOAT, true, true, true, DecoratedVisualRenderer::Property::BLUR_RADIUS, TEST_LOCATION);
215
216   END_TEST;
217 }
218
219 int UtcDaliDecoratedVisualRendererAnimatedProperty01(void)
220 {
221   TestApplication application;
222
223   tet_infoline("Test that a decorated visual renderer property can be animated");
224
225   Shader                  shader   = Shader::New("VertexSource", "FragmentSource");
226   Geometry                geometry = CreateQuadGeometry();
227   DecoratedVisualRenderer renderer = DecoratedVisualRenderer::New(geometry, shader);
228
229   Actor actor = Actor::New();
230   actor.AddRenderer(renderer);
231   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
232   application.GetScene().Add(actor);
233
234   Property::Index cornerRadiusIndex = DecoratedVisualRenderer::Property::CORNER_RADIUS;
235   renderer.SetProperty(cornerRadiusIndex, Vector4(1.0f, 10.0f, 5.0f, 0.0f));
236
237   application.SendNotification();
238   application.Render(0);
239   DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(cornerRadiusIndex), Vector4(1.0f, 10.0f, 5.0f, 0.0f), 0.001f, TEST_LOCATION);
240
241   Animation animation = Animation::New(1.0f);
242   KeyFrames keyFrames = KeyFrames::New();
243   keyFrames.Add(0.0f, Vector4(1.0f, 0.0f, 1.0f, 0.0f));
244   keyFrames.Add(1.0f, Vector4(0.0f, 1.0f, 0.0f, 1.0f));
245   animation.AnimateBetween(Property(renderer, cornerRadiusIndex), keyFrames);
246   animation.Play();
247
248   application.SendNotification();
249   application.Render(500);
250
251   DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(cornerRadiusIndex), Vector4(0.5f, 0.5f, 0.5f, 0.5f), TEST_LOCATION);
252
253   application.Render(400);
254   DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(cornerRadiusIndex), Vector4(0.1f, 0.9f, 0.1f, 0.9f), TEST_LOCATION);
255
256   application.Render(100);
257   DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(cornerRadiusIndex), Vector4(0.f, 1.f, 0.f, 1.f), TEST_LOCATION);
258   DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(cornerRadiusIndex), Vector4(0.f, 1.f, 0.f, 1.f), TEST_LOCATION);
259
260   END_TEST;
261 }
262
263 int UtcDaliDecoratedVisualRendererAnimatedProperty02(void)
264 {
265   TestApplication application;
266
267   tet_infoline("Test that a decorated visual renderer property can be animated");
268
269   Shader                  shader   = Shader::New("VertexSource", "FragmentSource");
270   Geometry                geometry = CreateQuadGeometry();
271   DecoratedVisualRenderer renderer = DecoratedVisualRenderer::New(geometry, shader);
272
273   Actor actor = Actor::New();
274   actor.AddRenderer(renderer);
275   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
276   application.GetScene().Add(actor);
277
278   renderer.SetProperty(DecoratedVisualRenderer::Property::CORNER_RADIUS, Vector4(1.0f, 1.0f, 0.0f, 0.0f));
279   renderer.SetProperty(DecoratedVisualRenderer::Property::BORDERLINE_WIDTH, 1.0f);
280   renderer.SetProperty(DecoratedVisualRenderer::Property::BORDERLINE_COLOR, Vector4(1.0f, 0.0f, 0.0f, 1.0f));
281   renderer.SetProperty(DecoratedVisualRenderer::Property::BORDERLINE_OFFSET, -1.0f);
282   renderer.SetProperty(DecoratedVisualRenderer::Property::BLUR_RADIUS, 0.0f);
283
284   application.SendNotification();
285   application.Render(0);
286   application.SendNotification();
287   application.Render(0);
288   DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(DecoratedVisualRenderer::Property::CORNER_RADIUS), Vector4(1.0f, 1.0f, 0.0f, 0.0f), 0.001f, TEST_LOCATION);
289   DALI_TEST_EQUALS(renderer.GetProperty<float>(DecoratedVisualRenderer::Property::BORDERLINE_WIDTH), 1.0f, 0.001f, TEST_LOCATION);
290   DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(DecoratedVisualRenderer::Property::BORDERLINE_COLOR), Vector4(1.0f, 0.0f, 0.0f, 1.0f), 0.001f, TEST_LOCATION);
291   DALI_TEST_EQUALS(renderer.GetProperty<float>(DecoratedVisualRenderer::Property::BORDERLINE_OFFSET), -1.0f, 0.001f, TEST_LOCATION);
292   DALI_TEST_EQUALS(renderer.GetProperty<float>(DecoratedVisualRenderer::Property::BLUR_RADIUS), 0.0f, 0.001f, TEST_LOCATION);
293
294   Animation animation = Animation::New(1.0f);
295   animation.AnimateBy(Property(renderer, DecoratedVisualRenderer::Property::CORNER_RADIUS), Vector4(10.0f, 100.0f, 100.0f, 10.0f));
296   animation.AnimateBy(Property(renderer, DecoratedVisualRenderer::Property::BORDERLINE_WIDTH), 10.0f);
297   animation.AnimateBy(Property(renderer, DecoratedVisualRenderer::Property::BORDERLINE_COLOR), Vector4(-1.0f, 1.0f, 1.0f, 0.0f));
298   animation.AnimateBy(Property(renderer, DecoratedVisualRenderer::Property::BORDERLINE_OFFSET), 2.0f);
299   animation.AnimateBy(Property(renderer, DecoratedVisualRenderer::Property::BLUR_RADIUS), 20.0f);
300   animation.Play();
301
302   application.SendNotification();
303   application.Render(500);
304
305   DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(DecoratedVisualRenderer::Property::CORNER_RADIUS), Vector4(6.0f, 51.0f, 50.0f, 5.0f), 0.001f, TEST_LOCATION);
306   DALI_TEST_EQUALS(renderer.GetCurrentProperty<float>(DecoratedVisualRenderer::Property::BORDERLINE_WIDTH), 6.0f, 0.001f, TEST_LOCATION);
307   DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(DecoratedVisualRenderer::Property::BORDERLINE_COLOR), Vector4(0.5f, 0.5f, 0.5f, 1.0f), 0.001f, TEST_LOCATION);
308   DALI_TEST_EQUALS(renderer.GetCurrentProperty<float>(DecoratedVisualRenderer::Property::BORDERLINE_OFFSET), 0.0f, 0.001f, TEST_LOCATION);
309   DALI_TEST_EQUALS(renderer.GetCurrentProperty<float>(DecoratedVisualRenderer::Property::BLUR_RADIUS), 10.0f, 0.001f, TEST_LOCATION);
310
311   application.Render(400);
312   DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(DecoratedVisualRenderer::Property::CORNER_RADIUS), Vector4(10.0f, 91.0f, 90.0f, 9.0f), 0.001f, TEST_LOCATION);
313   DALI_TEST_EQUALS(renderer.GetCurrentProperty<float>(DecoratedVisualRenderer::Property::BORDERLINE_WIDTH), 10.0f, 0.001f, TEST_LOCATION);
314   DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(DecoratedVisualRenderer::Property::BORDERLINE_COLOR), Vector4(0.1f, 0.9f, 0.9f, 1.0f), 0.001f, TEST_LOCATION);
315   DALI_TEST_EQUALS(renderer.GetCurrentProperty<float>(DecoratedVisualRenderer::Property::BORDERLINE_OFFSET), 0.8f, 0.001f, TEST_LOCATION);
316   DALI_TEST_EQUALS(renderer.GetCurrentProperty<float>(DecoratedVisualRenderer::Property::BLUR_RADIUS), 18.0f, 0.001f, TEST_LOCATION);
317
318   application.Render(100);
319   DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(DecoratedVisualRenderer::Property::CORNER_RADIUS), Vector4(11.0f, 101.0f, 100.0f, 10.0f), 0.001f, TEST_LOCATION);
320   DALI_TEST_EQUALS(renderer.GetCurrentProperty<float>(DecoratedVisualRenderer::Property::BORDERLINE_WIDTH), 11.0f, 0.001f, TEST_LOCATION);
321   DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(DecoratedVisualRenderer::Property::BORDERLINE_COLOR), Vector4(0.0f, 1.0f, 1.0f, 1.0f), 0.001f, TEST_LOCATION);
322   DALI_TEST_EQUALS(renderer.GetCurrentProperty<float>(DecoratedVisualRenderer::Property::BORDERLINE_OFFSET), 1.0f, 0.001f, TEST_LOCATION);
323   DALI_TEST_EQUALS(renderer.GetCurrentProperty<float>(DecoratedVisualRenderer::Property::BLUR_RADIUS), 20.0f, 0.001f, TEST_LOCATION);
324
325   DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(DecoratedVisualRenderer::Property::CORNER_RADIUS), Vector4(11.0f, 101.0f, 100.0f, 10.0f), 0.001f, TEST_LOCATION);
326   DALI_TEST_EQUALS(renderer.GetProperty<float>(DecoratedVisualRenderer::Property::BORDERLINE_WIDTH), 11.0f, 0.001f, TEST_LOCATION);
327   DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(DecoratedVisualRenderer::Property::BORDERLINE_COLOR), Vector4(0.0f, 1.0f, 1.0f, 1.0f), 0.001f, TEST_LOCATION);
328   DALI_TEST_EQUALS(renderer.GetProperty<float>(DecoratedVisualRenderer::Property::BORDERLINE_OFFSET), 1.0f, 0.001f, TEST_LOCATION);
329   DALI_TEST_EQUALS(renderer.GetProperty<float>(DecoratedVisualRenderer::Property::BLUR_RADIUS), 20.0f, 0.001f, TEST_LOCATION);
330
331   END_TEST;
332 }
333
334 struct DecoratedVisualProperties
335 {
336   DecoratedVisualProperties() = default;
337
338   DecoratedVisualProperties(Vector2 offset, Vector2 size, Vector2 origin, Vector2 pivot, Vector4 modes, Vector2 extraSize, Vector3 mixColor, float preMultipliedAlpha, Vector4 cornerRadius, float cornerRadiusPolicy, float borderlineWidth, Vector4 borderlineColor, float borderlineOffset, float blurRadius)
339   : mTransformOffset(offset),
340     mTransformSize(size),
341     mTransformOrigin(origin),
342     mTransformAnchorPoint(pivot),
343     mTransformOffsetSizeMode(modes),
344     mExtraSize(extraSize),
345     mMixColor(mixColor),
346     mPreMultipliedAlpha(preMultipliedAlpha),
347     mCornerRadius(cornerRadius),
348     mCornerRadiusPolicy(cornerRadiusPolicy),
349     mBorderlineWidth(borderlineWidth),
350     mBorderlineColor(borderlineColor),
351     mBorderlineOffset(borderlineOffset),
352     mBlurRadius(blurRadius)
353   {
354   }
355
356   Vector2 mTransformOffset{Vector2::ZERO};
357   Vector2 mTransformSize{Vector2::ONE};
358   Vector2 mTransformOrigin{Vector2::ZERO};
359   Vector2 mTransformAnchorPoint{Vector2::ZERO};
360   Vector4 mTransformOffsetSizeMode{Vector2::ZERO};
361   Vector2 mExtraSize{Vector2::ZERO};
362   Vector3 mMixColor{Vector3::ONE};
363   float   mPreMultipliedAlpha{0.0f};
364
365   Vector4 mCornerRadius{Vector4::ZERO};
366   float   mCornerRadiusPolicy{1.0f};
367   float   mBorderlineWidth{0.0f};
368   Vector4 mBorderlineColor{Vector4::ZERO};
369   float   mBorderlineOffset{0.0f};
370   float   mBlurRadius{0.0f};
371
372   static DecoratedVisualProperties GetPropsAt(float alpha, const DecoratedVisualProperties& start, const DecoratedVisualProperties& end)
373   {
374     DecoratedVisualProperties progress;
375     progress.mTransformOffset  = start.mTransformOffset + (end.mTransformOffset - start.mTransformOffset) * alpha;
376     progress.mTransformSize    = start.mTransformSize + (end.mTransformSize - start.mTransformSize) * alpha;
377     progress.mExtraSize        = start.mExtraSize + (end.mExtraSize - start.mExtraSize) * alpha;
378     progress.mMixColor         = start.mMixColor + (end.mMixColor - start.mMixColor) * alpha;
379     progress.mCornerRadius     = start.mCornerRadius + (end.mCornerRadius - start.mCornerRadius) * alpha;
380     progress.mBorderlineWidth  = start.mBorderlineWidth + (end.mBorderlineWidth - start.mBorderlineWidth) * alpha;
381     progress.mBorderlineColor  = start.mBorderlineColor + (end.mBorderlineColor - start.mBorderlineColor) * alpha;
382     progress.mBorderlineOffset = start.mBorderlineOffset + (end.mBorderlineOffset - start.mBorderlineOffset) * alpha;
383     progress.mBlurRadius       = start.mBlurRadius + (end.mBlurRadius - start.mBlurRadius) * alpha;
384
385     progress.mTransformOffsetSizeMode = end.mTransformOffsetSizeMode;
386     progress.mTransformOrigin         = end.mTransformOrigin;
387     progress.mTransformAnchorPoint    = end.mTransformAnchorPoint;
388     progress.mPreMultipliedAlpha      = end.mPreMultipliedAlpha;
389     progress.mCornerRadiusPolicy      = end.mCornerRadiusPolicy;
390     return progress;
391   }
392 };
393
394 void PrintDecoratedVisualProperties(const DecoratedVisualProperties& props, const std::string& prefix)
395 {
396   tet_printf(
397     "%s: offset:(%5.3f, %5.3f)\n"
398     "%*c size:(%5.3f, %5.3f)\n"
399     "%*c origin:(%5.3f, %5.3f)\n"
400     "%*c anchorPoint:(%5.3f, %5.3f)\n"
401     "%*c offsetSizeMode:(%5.3f, %5.3f, %5.3f, %5.3f)\n"
402     "%*c extraSize:(%5.3f, %5.3f)\n"
403     "%*c mixColor:(%5.3f, %5.3f, %5.3f)\n"
404     "%*c preMultipliedAlpha:(%5.3f)\n"
405     "%*c cornerRadius:(%5.3f, %5.3f, %5.3f, %5.3f)\n"
406     "%*c cornerRadiusPolicy:(%5.3f)\n"
407     "%*c borderlineWidth:(%5.3f)\n"
408     "%*c borderlineColor:(%5.3f, %5.3f, %5.3f, %5.3f)\n"
409     "%*c borderlineOffset:(%5.3f)\n"
410     "%*c blurRadius:(%5.3f)\n",
411     prefix.c_str(),
412     props.mTransformOffset.x,
413     props.mTransformOffset.y,
414     prefix.length() + 1,
415     ' ',
416     props.mTransformSize.x,
417     props.mTransformSize.y,
418     prefix.length() + 1,
419     ' ',
420     props.mTransformOrigin.x,
421     props.mTransformOrigin.y,
422     prefix.length() + 1,
423     ' ',
424     props.mTransformAnchorPoint.x,
425     props.mTransformAnchorPoint.y,
426     prefix.length() + 1,
427     ' ',
428     props.mTransformOffsetSizeMode.x,
429     props.mTransformOffsetSizeMode.y,
430     props.mTransformOffsetSizeMode.z,
431     props.mTransformOffsetSizeMode.w,
432     prefix.length() + 1,
433     ' ',
434     props.mExtraSize.x,
435     props.mExtraSize.y,
436     prefix.length() + 1,
437     ' ',
438     props.mMixColor.x,
439     props.mMixColor.y,
440     props.mMixColor.z,
441     prefix.length() + 1,
442     ' ',
443     props.mPreMultipliedAlpha,
444     prefix.length() + 1,
445     ' ',
446     props.mCornerRadius.x,
447     props.mCornerRadius.y,
448     props.mCornerRadius.z,
449     props.mCornerRadius.w,
450     prefix.length() + 1,
451     ' ',
452     props.mCornerRadiusPolicy,
453     prefix.length() + 1,
454     ' ',
455     props.mBorderlineWidth,
456     prefix.length() + 1,
457     ' ',
458     props.mBorderlineColor.x,
459     props.mBorderlineColor.y,
460     props.mBorderlineColor.z,
461     props.mBorderlineColor.w,
462     prefix.length() + 1,
463     ' ',
464     props.mBorderlineOffset,
465     prefix.length() + 1,
466     ' ',
467     props.mBlurRadius);
468 }
469
470 void SetDecoratedVisualProperties(DecoratedVisualRenderer renderer, DecoratedVisualProperties props)
471 {
472   renderer.SetProperty(VisualRenderer::Property::TRANSFORM_OFFSET, props.mTransformOffset);
473   renderer.SetProperty(VisualRenderer::Property::TRANSFORM_SIZE, props.mTransformSize);
474   renderer.SetProperty(VisualRenderer::Property::TRANSFORM_ORIGIN, props.mTransformOrigin);
475   renderer.SetProperty(VisualRenderer::Property::TRANSFORM_ANCHOR_POINT, props.mTransformAnchorPoint);
476   renderer.SetProperty(VisualRenderer::Property::TRANSFORM_OFFSET_SIZE_MODE, props.mTransformOffsetSizeMode);
477   renderer.SetProperty(VisualRenderer::Property::EXTRA_SIZE, props.mExtraSize);
478   renderer.SetProperty(VisualRenderer::Property::VISUAL_MIX_COLOR, props.mMixColor);
479   renderer.SetProperty(VisualRenderer::Property::VISUAL_PRE_MULTIPLIED_ALPHA, props.mPreMultipliedAlpha);
480
481   renderer.SetProperty(DecoratedVisualRenderer::Property::CORNER_RADIUS, props.mCornerRadius);
482   renderer.SetProperty(DecoratedVisualRenderer::Property::CORNER_RADIUS_POLICY, props.mCornerRadiusPolicy);
483   renderer.SetProperty(DecoratedVisualRenderer::Property::BORDERLINE_WIDTH, props.mBorderlineWidth);
484   renderer.SetProperty(DecoratedVisualRenderer::Property::BORDERLINE_COLOR, props.mBorderlineColor);
485   renderer.SetProperty(DecoratedVisualRenderer::Property::BORDERLINE_OFFSET, props.mBorderlineOffset);
486   renderer.SetProperty(DecoratedVisualRenderer::Property::BLUR_RADIUS, props.mBlurRadius);
487 }
488
489 void CheckEventDecoratedVisualProperties(DecoratedVisualRenderer renderer, DecoratedVisualProperties expectedProps)
490 {
491   tet_infoline("CheckEventDecoratedVisualProperties\n");
492
493   DecoratedVisualProperties actualProps;
494   actualProps.mTransformOffset         = renderer.GetProperty<Vector2>(VisualRenderer::Property::TRANSFORM_OFFSET);
495   actualProps.mTransformSize           = renderer.GetProperty<Vector2>(VisualRenderer::Property::TRANSFORM_SIZE);
496   actualProps.mTransformOrigin         = renderer.GetProperty<Vector2>(VisualRenderer::Property::TRANSFORM_ORIGIN);
497   actualProps.mTransformAnchorPoint    = renderer.GetProperty<Vector2>(VisualRenderer::Property::TRANSFORM_ANCHOR_POINT);
498   actualProps.mTransformOffsetSizeMode = renderer.GetProperty<Vector4>(VisualRenderer::Property::TRANSFORM_OFFSET_SIZE_MODE);
499   actualProps.mExtraSize               = renderer.GetProperty<Vector2>(VisualRenderer::Property::EXTRA_SIZE);
500   actualProps.mMixColor                = renderer.GetProperty<Vector3>(VisualRenderer::Property::VISUAL_MIX_COLOR);
501   actualProps.mPreMultipliedAlpha      = renderer.GetProperty<float>(VisualRenderer::Property::VISUAL_PRE_MULTIPLIED_ALPHA);
502
503   actualProps.mCornerRadius       = renderer.GetProperty<Vector4>(DecoratedVisualRenderer::Property::CORNER_RADIUS);
504   actualProps.mCornerRadiusPolicy = renderer.GetProperty<float>(DecoratedVisualRenderer::Property::CORNER_RADIUS_POLICY);
505   actualProps.mBorderlineWidth    = renderer.GetProperty<float>(DecoratedVisualRenderer::Property::BORDERLINE_WIDTH);
506   actualProps.mBorderlineColor    = renderer.GetProperty<Vector4>(DecoratedVisualRenderer::Property::BORDERLINE_COLOR);
507   actualProps.mBorderlineOffset   = renderer.GetProperty<float>(DecoratedVisualRenderer::Property::BORDERLINE_OFFSET);
508   actualProps.mBlurRadius         = renderer.GetProperty<float>(DecoratedVisualRenderer::Property::BLUR_RADIUS);
509
510   PrintDecoratedVisualProperties(actualProps, "Actual event props");
511
512   DALI_TEST_EQUALS(actualProps.mTransformOffset, expectedProps.mTransformOffset, TEST_LOCATION);
513   DALI_TEST_EQUALS(actualProps.mTransformSize, expectedProps.mTransformSize, TEST_LOCATION);
514   DALI_TEST_EQUALS(actualProps.mTransformOrigin, expectedProps.mTransformOrigin, TEST_LOCATION);
515   DALI_TEST_EQUALS(actualProps.mTransformAnchorPoint, expectedProps.mTransformAnchorPoint, TEST_LOCATION);
516   DALI_TEST_EQUALS(actualProps.mTransformOffsetSizeMode, expectedProps.mTransformOffsetSizeMode, TEST_LOCATION);
517   DALI_TEST_EQUALS(actualProps.mExtraSize, expectedProps.mExtraSize, TEST_LOCATION);
518   DALI_TEST_EQUALS(actualProps.mMixColor, expectedProps.mMixColor, TEST_LOCATION);
519   DALI_TEST_EQUALS(actualProps.mPreMultipliedAlpha, expectedProps.mPreMultipliedAlpha, TEST_LOCATION);
520
521   DALI_TEST_EQUALS(actualProps.mCornerRadius, expectedProps.mCornerRadius, TEST_LOCATION);
522   DALI_TEST_EQUALS(actualProps.mCornerRadiusPolicy, expectedProps.mCornerRadiusPolicy, TEST_LOCATION);
523   DALI_TEST_EQUALS(actualProps.mBorderlineWidth, expectedProps.mBorderlineWidth, TEST_LOCATION);
524   DALI_TEST_EQUALS(actualProps.mBorderlineColor, expectedProps.mBorderlineColor, TEST_LOCATION);
525   DALI_TEST_EQUALS(actualProps.mBorderlineOffset, expectedProps.mBorderlineOffset, TEST_LOCATION);
526   DALI_TEST_EQUALS(actualProps.mBlurRadius, expectedProps.mBlurRadius, TEST_LOCATION);
527 }
528
529 void CheckSceneGraphDecoratedVisualProperties(DecoratedVisualRenderer renderer, DecoratedVisualProperties expectedProps)
530 {
531   tet_infoline("CheckSceneGraphVisualProperties\n");
532
533   DecoratedVisualProperties actualProps;
534
535   actualProps.mTransformOffset         = renderer.GetCurrentProperty<Vector2>(VisualRenderer::Property::TRANSFORM_OFFSET);
536   actualProps.mTransformSize           = renderer.GetCurrentProperty<Vector2>(VisualRenderer::Property::TRANSFORM_SIZE);
537   actualProps.mTransformOrigin         = renderer.GetCurrentProperty<Vector2>(VisualRenderer::Property::TRANSFORM_ORIGIN);
538   actualProps.mTransformAnchorPoint    = renderer.GetCurrentProperty<Vector2>(VisualRenderer::Property::TRANSFORM_ANCHOR_POINT);
539   actualProps.mTransformOffsetSizeMode = renderer.GetCurrentProperty<Vector4>(VisualRenderer::Property::TRANSFORM_OFFSET_SIZE_MODE);
540   actualProps.mExtraSize               = renderer.GetCurrentProperty<Vector2>(VisualRenderer::Property::EXTRA_SIZE);
541   actualProps.mMixColor                = renderer.GetCurrentProperty<Vector3>(VisualRenderer::Property::VISUAL_MIX_COLOR);
542
543   actualProps.mCornerRadius       = renderer.GetCurrentProperty<Vector4>(DecoratedVisualRenderer::Property::CORNER_RADIUS);
544   actualProps.mCornerRadiusPolicy = renderer.GetCurrentProperty<float>(DecoratedVisualRenderer::Property::CORNER_RADIUS_POLICY);
545   actualProps.mBorderlineWidth    = renderer.GetCurrentProperty<float>(DecoratedVisualRenderer::Property::BORDERLINE_WIDTH);
546   actualProps.mBorderlineColor    = renderer.GetCurrentProperty<Vector4>(DecoratedVisualRenderer::Property::BORDERLINE_COLOR);
547   actualProps.mBorderlineOffset   = renderer.GetCurrentProperty<float>(DecoratedVisualRenderer::Property::BORDERLINE_OFFSET);
548   actualProps.mBlurRadius         = renderer.GetCurrentProperty<float>(DecoratedVisualRenderer::Property::BLUR_RADIUS);
549
550   PrintDecoratedVisualProperties(actualProps, "Actual update props");
551
552   DALI_TEST_EQUALS(actualProps.mTransformOffset, expectedProps.mTransformOffset, TEST_LOCATION);
553   DALI_TEST_EQUALS(actualProps.mTransformSize, expectedProps.mTransformSize, TEST_LOCATION);
554   DALI_TEST_EQUALS(actualProps.mTransformOrigin, expectedProps.mTransformOrigin, TEST_LOCATION);
555   DALI_TEST_EQUALS(actualProps.mTransformAnchorPoint, expectedProps.mTransformAnchorPoint, TEST_LOCATION);
556   DALI_TEST_EQUALS(actualProps.mTransformOffsetSizeMode, expectedProps.mTransformOffsetSizeMode, TEST_LOCATION);
557   DALI_TEST_EQUALS(actualProps.mExtraSize, expectedProps.mExtraSize, TEST_LOCATION);
558   DALI_TEST_EQUALS(actualProps.mMixColor, expectedProps.mMixColor, TEST_LOCATION);
559   DALI_TEST_EQUALS(actualProps.mPreMultipliedAlpha, expectedProps.mPreMultipliedAlpha, TEST_LOCATION);
560
561   DALI_TEST_EQUALS(actualProps.mCornerRadius, expectedProps.mCornerRadius, TEST_LOCATION);
562   DALI_TEST_EQUALS(actualProps.mCornerRadiusPolicy, expectedProps.mCornerRadiusPolicy, TEST_LOCATION);
563   DALI_TEST_EQUALS(actualProps.mBorderlineWidth, expectedProps.mBorderlineWidth, TEST_LOCATION);
564   DALI_TEST_EQUALS(actualProps.mBorderlineColor, expectedProps.mBorderlineColor, TEST_LOCATION);
565   DALI_TEST_EQUALS(actualProps.mBorderlineOffset, expectedProps.mBorderlineOffset, TEST_LOCATION);
566   DALI_TEST_EQUALS(actualProps.mBlurRadius, expectedProps.mBlurRadius, TEST_LOCATION);
567 }
568
569 void CheckUniforms(DecoratedVisualRenderer renderer, DecoratedVisualProperties props, std::vector<UniformData>& uniforms, TraceCallStack& callStack, TestGlAbstraction& gl)
570 {
571   tet_infoline("CheckUniforms\n");
572
573   TraceCallStack::NamedParams params;
574
575   tet_printf("Callback trace: \n%s\n", callStack.GetTraceString().c_str());
576
577   DALI_TEST_CHECK(callStack.FindMethodAndGetParameters(uniforms[0].name, params));
578   DALI_TEST_CHECK(gl.GetUniformValue<Vector2>(uniforms[0].name.c_str(), props.mTransformOffset));
579
580   DALI_TEST_CHECK(callStack.FindMethodAndGetParameters(uniforms[1].name, params));
581   DALI_TEST_CHECK(gl.GetUniformValue<Vector2>(uniforms[1].name.c_str(), props.mTransformSize));
582
583   DALI_TEST_CHECK(callStack.FindMethodAndGetParameters(uniforms[2].name, params));
584   DALI_TEST_CHECK(gl.GetUniformValue<Vector2>(uniforms[2].name.c_str(), props.mTransformOrigin));
585
586   DALI_TEST_CHECK(callStack.FindMethodAndGetParameters(uniforms[3].name, params));
587   DALI_TEST_CHECK(gl.GetUniformValue<Vector2>(uniforms[3].name.c_str(), props.mTransformAnchorPoint));
588
589   DALI_TEST_CHECK(callStack.FindMethodAndGetParameters(uniforms[4].name, params));
590   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>(uniforms[4].name.c_str(), props.mTransformOffsetSizeMode));
591
592   DALI_TEST_CHECK(callStack.FindMethodAndGetParameters(uniforms[5].name, params));
593   DALI_TEST_CHECK(gl.GetUniformValue<Vector2>(uniforms[5].name.c_str(), props.mExtraSize));
594
595   DALI_TEST_CHECK(callStack.FindMethodAndGetParameters(uniforms[6].name, params));
596   DALI_TEST_CHECK(gl.GetUniformValue<Vector3>(uniforms[6].name.c_str(), props.mMixColor));
597
598   DALI_TEST_CHECK(callStack.FindMethodAndGetParameters(uniforms[7].name, params));
599   DALI_TEST_CHECK(gl.GetUniformValue<float>(uniforms[7].name.c_str(), props.mPreMultipliedAlpha));
600
601   DALI_TEST_CHECK(callStack.FindMethodAndGetParameters(uniforms[8].name, params));
602   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>(uniforms[8].name.c_str(), props.mCornerRadius));
603
604   DALI_TEST_CHECK(callStack.FindMethodAndGetParameters(uniforms[9].name, params));
605   DALI_TEST_CHECK(gl.GetUniformValue<float>(uniforms[9].name.c_str(), props.mCornerRadiusPolicy));
606
607   DALI_TEST_CHECK(callStack.FindMethodAndGetParameters(uniforms[10].name, params));
608   DALI_TEST_CHECK(gl.GetUniformValue<float>(uniforms[10].name.c_str(), props.mBorderlineWidth));
609
610   DALI_TEST_CHECK(callStack.FindMethodAndGetParameters(uniforms[11].name, params));
611   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>(uniforms[11].name.c_str(), props.mBorderlineColor));
612
613   DALI_TEST_CHECK(callStack.FindMethodAndGetParameters(uniforms[12].name, params));
614   DALI_TEST_CHECK(gl.GetUniformValue<float>(uniforms[12].name.c_str(), props.mBorderlineOffset));
615
616   DALI_TEST_CHECK(callStack.FindMethodAndGetParameters(uniforms[13].name, params));
617   DALI_TEST_CHECK(gl.GetUniformValue<float>(uniforms[13].name.c_str(), props.mBlurRadius));
618 }
619
620 int UtcDaliDecoratedVisualRendererAnimatedProperty03(void)
621 {
622   TestApplication    application;
623   TestGlAbstraction& gl        = application.GetGlAbstraction();
624   TraceCallStack&    callStack = gl.GetSetUniformTrace();
625   gl.EnableSetUniformCallTrace(true);
626
627   tet_infoline("Test that a decorated visual renderer property can be animated and that the uniforms are set");
628
629   std::vector<UniformData> customUniforms{{"offset", Property::VECTOR2},
630                                           {"size", Property::VECTOR2},
631                                           {"origin", Property::VECTOR2},
632                                           {"anchorPoint", Property::VECTOR2},
633                                           {"offsetSizeMode", Property::VECTOR4},
634                                           {"extraSize", Property::VECTOR2},
635                                           {"mixColor", Property::VECTOR3},
636                                           {"preMultipliedAlpha", Property::FLOAT},
637                                           {"cornerRadius", Property::VECTOR4},
638                                           {"cornerRadiusPolicy", Property::FLOAT},
639                                           {"borderlineWidth", Property::FLOAT},
640                                           {"borderlineColor", Property::VECTOR4},
641                                           {"borderlineOffset", Property::FLOAT},
642                                           {"blurRadius", Property::FLOAT}};
643
644   application.GetGraphicsController().AddCustomUniforms(customUniforms);
645
646   Shader                  shader   = Shader::New("VertexSource", "FragmentSource");
647   Geometry                geometry = CreateQuadGeometry();
648   DecoratedVisualRenderer renderer = DecoratedVisualRenderer::New(geometry, shader);
649
650   // Add all uniform mappings
651   renderer.RegisterCornerRadiusUniform();
652   renderer.RegisterBorderlineUniform();
653   renderer.RegisterBlurRadiusUniform();
654
655   Actor actor = Actor::New();
656   actor.AddRenderer(renderer);
657   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
658   application.GetScene().Add(actor);
659
660   DecoratedVisualProperties props{Vector2(10.f, 10.f), Vector2(200.f, 100.f), Vector2(0.5f, 0.5f), Vector2(0.5f, 0.5f), Vector4::ZERO, Vector2(0.0f, 0.0f), Vector3(Color::SEA_GREEN), 0.0f, Vector4(100.0f, 10.0f, 1.0f, 0.1f), 1.0f, 20.0f, Vector4(1.0f, 0.0f, 1.0f, 0.5f), 1.0f, 10.0f};
661   DecoratedVisualProperties targetProps{Vector2(40.f, 40.f), Vector2(100.f, 200.f), Vector2(0.5f, 0.5f), Vector2(0.5f, 0.5f), Vector4::ZERO, Vector2(25.0f, 25.0f), Vector3(Color::MEDIUM_PURPLE), 0.0f, Vector4(0.2f, 2.0f, 20.0f, 200.0f), 1.0f, 40.0f, Vector4(0.0f, 0.2f, 0.0f, 1.0f), -1.0f, 2.0f};
662
663   SetDecoratedVisualProperties(renderer, props);
664   CheckEventDecoratedVisualProperties(renderer, props);
665   application.SendNotification();
666   application.Render(0);
667   CheckSceneGraphDecoratedVisualProperties(renderer, props);
668   CheckUniforms(renderer, props, customUniforms, callStack, gl);
669
670   // Set up a 1 second anim.
671   Animation animation = Animation::New(1.0f);
672
673   animation.AnimateTo(Property(renderer, VisualRenderer::Property::TRANSFORM_OFFSET), targetProps.mTransformOffset);
674   animation.AnimateTo(Property(renderer, VisualRenderer::Property::TRANSFORM_SIZE), targetProps.mTransformSize);
675   animation.AnimateTo(Property(renderer, VisualRenderer::Property::EXTRA_SIZE), targetProps.mExtraSize);
676   animation.AnimateTo(Property(renderer, VisualRenderer::Property::VISUAL_MIX_COLOR), targetProps.mMixColor);
677
678   animation.AnimateTo(Property(renderer, DecoratedVisualRenderer::Property::CORNER_RADIUS), targetProps.mCornerRadius);
679   animation.AnimateTo(Property(renderer, DecoratedVisualRenderer::Property::BORDERLINE_WIDTH), targetProps.mBorderlineWidth);
680   animation.AnimateTo(Property(renderer, DecoratedVisualRenderer::Property::BORDERLINE_COLOR), targetProps.mBorderlineColor);
681   animation.AnimateTo(Property(renderer, DecoratedVisualRenderer::Property::BORDERLINE_OFFSET), targetProps.mBorderlineOffset);
682   animation.AnimateTo(Property(renderer, DecoratedVisualRenderer::Property::BLUR_RADIUS), targetProps.mBlurRadius);
683   animation.Play();
684
685   CheckEventDecoratedVisualProperties(renderer, targetProps);
686
687   for(int i = 0; i <= 10; ++i)
688   {
689     tet_printf("\n###########  Animation progress: %d%%\n\n", i * 10);
690     DecoratedVisualProperties propsProgress = DecoratedVisualProperties::GetPropsAt(0.1f * i, props, targetProps);
691     PrintDecoratedVisualProperties(propsProgress, "Expected values");
692
693     callStack.Reset();
694     application.SendNotification();
695     application.Render((i == 0 ? 0 : 100));
696
697     CheckEventDecoratedVisualProperties(renderer, targetProps);
698
699     CheckSceneGraphDecoratedVisualProperties(renderer, propsProgress);
700     CheckUniforms(renderer, propsProgress, customUniforms, callStack, gl);
701   }
702
703   // Ensure animation finishes
704   application.SendNotification();
705   application.Render(100);
706   CheckSceneGraphDecoratedVisualProperties(renderer, targetProps);
707   CheckUniforms(renderer, targetProps, customUniforms, callStack, gl);
708
709   END_TEST;
710 }
711
712 int UtcDaliDecoratedVisualRendererAnimatedProperty04(void)
713 {
714   TestApplication application;
715
716   tet_infoline("Test that a decorated visual renderer property can't be animated");
717
718   Shader                  shader   = Shader::New("VertexSource", "FragmentSource");
719   Geometry                geometry = CreateQuadGeometry();
720   DecoratedVisualRenderer renderer = DecoratedVisualRenderer::New(geometry, shader);
721
722   Actor actor = Actor::New();
723   actor.AddRenderer(renderer);
724   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
725   application.GetScene().Add(actor);
726
727   Property::Index index = DecoratedVisualRenderer::Property::CORNER_RADIUS_POLICY;
728   renderer.SetProperty(index, 0.0f);
729
730   application.SendNotification();
731   application.Render(0);
732   DALI_TEST_EQUALS(renderer.GetProperty<float>(index), 0.0f, 0.001f, TEST_LOCATION);
733
734   Animation animation = Animation::New(1.0f);
735   KeyFrames keyFrames = KeyFrames::New();
736   keyFrames.Add(0.0f, 0.0f);
737   keyFrames.Add(1.0f, 1.0f);
738   try
739   {
740     animation.AnimateBetween(Property(renderer, index), keyFrames);
741     tet_result(TET_FAIL);
742   }
743   catch(DaliException& e)
744   {
745     DALI_TEST_ASSERT(e, "baseProperty && \"Property is not animatable\"", TEST_LOCATION);
746   }
747
748   END_TEST;
749 }
750
751 int UtcDaliDecoratedVisualRendererAnimatedProperty05(void)
752 {
753   TestApplication application;
754
755   tet_infoline("Test that a parent visual renderer property can still be animated");
756
757   Shader                  shader   = Shader::New("VertexSource", "FragmentSource");
758   Geometry                geometry = CreateQuadGeometry();
759   DecoratedVisualRenderer renderer = DecoratedVisualRenderer::New(geometry, shader);
760
761   Actor actor = Actor::New();
762   actor.AddRenderer(renderer);
763   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
764   application.GetScene().Add(actor);
765
766   Property::Index index = VisualRenderer::Property::TRANSFORM_SIZE;
767   renderer.SetProperty(index, Vector2(1.0f, 0.5f));
768
769   application.SendNotification();
770   application.Render(0);
771   DALI_TEST_EQUALS(renderer.GetProperty<Vector2>(index), Vector2(1.0f, 0.5f), 0.001f, TEST_LOCATION);
772   DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector2>(VisualRenderer::Property::TRANSFORM_SIZE), Vector2(1.0f, 0.5f), 0.0001f, TEST_LOCATION);
773
774   Animation animation = Animation::New(1.0f);
775   KeyFrames keyFrames = KeyFrames::New();
776   keyFrames.Add(0.0f, Vector2(1.0f, 0.0f));
777   keyFrames.Add(1.0f, Vector2(0.0f, 1.0f));
778   animation.AnimateBetween(Property(renderer, index), keyFrames);
779   animation.Play();
780
781   application.SendNotification();
782
783   // Test that the event side properties are set to target value of (0, 1)
784   DALI_TEST_EQUALS(renderer.GetProperty<Vector2>(VisualRenderer::Property::TRANSFORM_SIZE), Vector2(0.0f, 1.0f), 0.0001f, TEST_LOCATION);
785
786   application.Render(500);
787
788   DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector2>(index), Vector2(0.5f, 0.5f), 0.0001f, TEST_LOCATION);
789   DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector2>(VisualRenderer::Property::TRANSFORM_SIZE), Vector2(0.5f, 0.5f), 0.0001f, TEST_LOCATION);
790
791   // Test that the event side properties are set to target value 0f (0, 1)
792   DALI_TEST_EQUALS(renderer.GetProperty<Vector2>(VisualRenderer::Property::TRANSFORM_SIZE), Vector2(0.0f, 1.0f), 0.0001f, TEST_LOCATION);
793
794   // Complete the animation
795   application.Render(500);
796
797   DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector2>(index), Vector2(0.0f, 1.0f), 0.0001f, TEST_LOCATION);
798   DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector2>(VisualRenderer::Property::TRANSFORM_SIZE), Vector2(0.0f, 1.0f), 0.0001f, TEST_LOCATION);
799   DALI_TEST_EQUALS(renderer.GetProperty<Vector2>(VisualRenderer::Property::TRANSFORM_SIZE), Vector2(0.0f, 1.0f), 0.0001f, TEST_LOCATION);
800   END_TEST;
801 }
802
803 int UtcDaliDecoratedVisualRendererPartialUpdate(void)
804 {
805   TestApplication application(
806     TestApplication::DEFAULT_SURFACE_WIDTH,
807     TestApplication::DEFAULT_SURFACE_HEIGHT,
808     TestApplication::DEFAULT_HORIZONTAL_DPI,
809     TestApplication::DEFAULT_VERTICAL_DPI,
810     true,
811     true);
812
813   tet_infoline("Test that partial update works well when we set visual renderer's animated properties");
814
815   const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
816
817   Shader                  shader   = Shader::New("VertexSource", "FragmentSource");
818   Geometry                geometry = CreateQuadGeometry();
819   DecoratedVisualRenderer renderer = DecoratedVisualRenderer::New(geometry, shader);
820
821   Actor actor = Actor::New();
822   actor.AddRenderer(renderer);
823   actor[Actor::Property::ANCHOR_POINT] = AnchorPoint::TOP_LEFT;
824   actor[Actor::Property::POSITION]     = Vector3(66.0f, 66.0f, 0.0f);
825   actor[Actor::Property::SIZE]         = Vector3(60.0f, 60.0f, 0.0f);
826   actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
827   application.GetScene().Add(actor);
828
829   application.SendNotification();
830
831   std::vector<Rect<int>> damagedRects;
832
833   // Actor added, damaged rect is added size of actor
834   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
835   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
836
837   // Aligned by 16
838   Rect<int> clippingRect = Rect<int>(64, 672, 64, 64); // in screen coordinates, includes 3 last frames updates
839   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
840
841   application.RenderWithPartialUpdate(damagedRects, clippingRect);
842   DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
843   DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
844   DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
845   DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
846
847   damagedRects.clear();
848   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
849   application.RenderWithPartialUpdate(damagedRects, clippingRect);
850
851   // Ensure the damaged rect is empty
852   DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
853
854   // Set clippingRect as full surface now. TODO : Set valid rect if we can.
855   clippingRect = TestApplication::DEFAULT_SURFACE_RECT;
856
857   // Set decoration with borderline as 32 units.
858   renderer.RegisterBorderlineUniform();
859   renderer.SetProperty(DecoratedVisualRenderer::Property::BORDERLINE_WIDTH, 32.0f);
860
861   Property::Index index = DecoratedVisualRenderer::Property::BORDERLINE_OFFSET;
862   renderer.SetProperty(index, 1.0f);
863
864   // Now current actor show as 124x124 rectangle, with center position (96, 96).
865   // So, rectangle's top left position is (34, 34), and bottom right position is (158, 158).
866
867   application.SendNotification();
868   damagedRects.clear();
869   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
870   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
871   // Aligned by 16
872   DALI_TEST_EQUALS<Rect<int>>(Rect<int>(32, 640, 128, 128), damagedRects[0], TEST_LOCATION);
873
874   application.RenderWithPartialUpdate(damagedRects, clippingRect);
875
876   application.SendNotification();
877   damagedRects.clear();
878   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
879   application.RenderWithPartialUpdate(damagedRects, clippingRect);
880
881   // Update dummy property to damangeRect buffer aging
882   actor.SetProperty(Actor::Property::COLOR, Color::RED);
883
884   application.SendNotification();
885   damagedRects.clear();
886   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
887   application.RenderWithPartialUpdate(damagedRects, clippingRect);
888   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
889
890   // Update dummy property to damangeRect buffer aging
891   actor.SetProperty(Actor::Property::COLOR, Color::BLUE);
892
893   application.SendNotification();
894   damagedRects.clear();
895   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
896   application.RenderWithPartialUpdate(damagedRects, clippingRect);
897   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
898   // Aligned by 16
899   DALI_TEST_EQUALS<Rect<int>>(Rect<int>(32, 640, 128, 128), damagedRects[0], TEST_LOCATION);
900
901   application.SendNotification();
902   damagedRects.clear();
903   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
904   application.RenderWithPartialUpdate(damagedRects, clippingRect);
905
906   application.SendNotification();
907   damagedRects.clear();
908   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
909   application.RenderWithPartialUpdate(damagedRects, clippingRect);
910
911   application.SendNotification();
912   damagedRects.clear();
913   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
914   application.RenderWithPartialUpdate(damagedRects, clippingRect);
915
916   // 3 frame spended after change actor property. Ensure the damaged rect is empty
917   DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
918
919   DALI_TEST_EQUALS(renderer.GetProperty<float>(index), 1.0f, 0.001f, TEST_LOCATION);
920
921   // Make flickered animation from 1.0f --> 0.0f --> -1.0f of borderline offset
922   // After finish the animation, actor show as 64x64 rectangle, with center position (96, 96).
923   // So, rectangle's top left position is (64, 64), and bottom right position is (128, 128).
924   Animation animation = Animation::New(1.0f);
925   KeyFrames keyFrames = KeyFrames::New();
926   keyFrames.Add(0.0f, float(1.0f));
927   keyFrames.Add(0.299f, float(1.0f));
928   keyFrames.Add(0.301f, float(0.0f));
929   keyFrames.Add(0.699f, float(0.0f));
930   keyFrames.Add(0.701f, float(-1.0f));
931   keyFrames.Add(1.0f, float(-1.0f));
932   animation.AnimateBetween(Property(renderer, index), keyFrames);
933   animation.Play();
934
935   application.SendNotification();
936   damagedRects.clear();
937   application.PreRenderWithPartialUpdate(200, nullptr, damagedRects); // 200 ms
938   application.RenderWithPartialUpdate(damagedRects, clippingRect);
939
940   DALI_TEST_EQUALS(renderer.GetCurrentProperty<float>(index), 1.0f, TEST_LOCATION);
941
942   // 302 ~ 600. TransformSize become 0.0f
943   application.SendNotification();
944   damagedRects.clear();
945   application.PreRenderWithPartialUpdate(102, nullptr, damagedRects); // 302 ms
946   application.RenderWithPartialUpdate(damagedRects, clippingRect);
947
948   DALI_TEST_EQUALS(renderer.GetCurrentProperty<float>(index), 0.0f, TEST_LOCATION);
949
950   // Update dummy property to damangeRect buffer aging
951   actor.SetProperty(Actor::Property::COLOR, Color::RED);
952
953   application.SendNotification();
954   damagedRects.clear();
955   application.PreRenderWithPartialUpdate(16, nullptr, damagedRects); // 318 ms
956   application.RenderWithPartialUpdate(damagedRects, clippingRect);
957
958   // Update dummy property to damangeRect buffer aging
959   actor.SetProperty(Actor::Property::COLOR, Color::GREEN);
960
961   application.SendNotification();
962   damagedRects.clear();
963   application.PreRenderWithPartialUpdate(16, nullptr, damagedRects); // 334 ms
964   application.RenderWithPartialUpdate(damagedRects, clippingRect);
965
966   // Update dummy property to damangeRect buffer aging
967   actor.SetProperty(Actor::Property::COLOR, Color::RED);
968
969   application.SendNotification();
970   damagedRects.clear();
971   application.PreRenderWithPartialUpdate(16, nullptr, damagedRects); // 350 ms
972   application.RenderWithPartialUpdate(damagedRects, clippingRect);
973
974   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
975   // Aligned by 16
976   // Now current actor show as 92x92 rectangle, with center position (96, 96).
977   DALI_TEST_EQUALS<Rect<int>>(Rect<int>(48, 656, 96, 96), damagedRects[0], TEST_LOCATION);
978
979   application.SendNotification();
980   damagedRects.clear();
981   application.PreRenderWithPartialUpdate(250, nullptr, damagedRects); // 600 ms
982   application.RenderWithPartialUpdate(damagedRects, clippingRect);
983
984   // 702 ~ 1000. TransformSize become -1.0f
985   damagedRects.clear();
986   application.PreRenderWithPartialUpdate(102, nullptr, damagedRects); // 702 ms
987   application.RenderWithPartialUpdate(damagedRects, clippingRect);
988
989   DALI_TEST_EQUALS(renderer.GetCurrentProperty<float>(index), -1.0f, TEST_LOCATION);
990
991   // Update dummy property to damangeRect buffer aging
992   actor.SetProperty(Actor::Property::COLOR, Color::GREEN);
993
994   application.SendNotification();
995   damagedRects.clear();
996   application.PreRenderWithPartialUpdate(16, nullptr, damagedRects); // 718 ms
997   application.RenderWithPartialUpdate(damagedRects, clippingRect);
998
999   // Update dummy property to damangeRect buffer aging
1000   actor.SetProperty(Actor::Property::COLOR, Color::BLUE);
1001
1002   application.SendNotification();
1003   damagedRects.clear();
1004   application.PreRenderWithPartialUpdate(16, nullptr, damagedRects); // 734 ms
1005   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1006
1007   // Update dummy property to damangeRect buffer aging
1008   actor.SetProperty(Actor::Property::COLOR, Color::RED);
1009
1010   application.SendNotification();
1011   damagedRects.clear();
1012   application.PreRenderWithPartialUpdate(16, nullptr, damagedRects); // 750 ms
1013   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1014
1015   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1016   // Aligned by 16
1017   // Now current actor show as 60x60 rectangle, with center position (96, 96).
1018   DALI_TEST_EQUALS<Rect<int>>(Rect<int>(64, 672, 64, 64), damagedRects[0], TEST_LOCATION);
1019
1020   application.SendNotification();
1021   damagedRects.clear();
1022   application.PreRenderWithPartialUpdate(52, nullptr, damagedRects); // 1002 ms. animation finished.
1023   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1024
1025   // Check finished value bake.
1026   DALI_TEST_EQUALS(renderer.GetProperty<float>(index), -1.0f, TEST_LOCATION);
1027
1028   END_TEST;
1029 }