2 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
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"
36 void visual_renderer_test_startup(void)
38 test_return_value = TET_UNDEF;
41 void visual_renderer_test_cleanup(void)
43 test_return_value = TET_PASS;
46 int UtcDaliVisualRendererNew01(void)
48 TestApplication application;
50 Geometry geometry = CreateQuadGeometry();
51 Shader shader = CreateShader();
52 VisualRenderer renderer = VisualRenderer::New(geometry, shader);
54 DALI_TEST_EQUALS((bool)renderer, true, TEST_LOCATION);
58 int UtcDaliVisualRendererNew02(void)
60 TestApplication application;
61 VisualRenderer renderer;
62 DALI_TEST_EQUALS((bool)renderer, false, TEST_LOCATION);
66 int UtcDaliVisualRendererCopyConstructor(void)
68 TestApplication application;
70 Geometry geometry = CreateQuadGeometry();
71 Shader shader = CreateShader();
72 VisualRenderer renderer = VisualRenderer::New(geometry, shader);
74 VisualRenderer rendererCopy(renderer);
75 DALI_TEST_EQUALS((bool)rendererCopy, true, TEST_LOCATION);
80 int UtcDaliVisualRendererAssignmentOperator(void)
82 TestApplication application;
84 Geometry geometry = CreateQuadGeometry();
85 Shader shader = CreateShader();
86 VisualRenderer renderer = VisualRenderer::New(geometry, shader);
88 VisualRenderer renderer2;
89 DALI_TEST_EQUALS((bool)renderer2, false, TEST_LOCATION);
92 DALI_TEST_EQUALS((bool)renderer2, true, TEST_LOCATION);
96 int UtcDaliVisualRendererMoveConstructor(void)
98 TestApplication application;
100 Geometry geometry = CreateQuadGeometry();
101 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
102 VisualRenderer renderer = VisualRenderer::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);
107 auto testColor = Vector3(1.0f, 0.0f, 1.0f);
108 renderer.SetProperty(VisualRenderer::Property::VISUAL_MIX_COLOR, testColor);
109 application.SendNotification();
110 application.Render();
111 DALI_TEST_EQUALS(renderer.GetProperty<Vector3>(VisualRenderer::Property::VISUAL_MIX_COLOR), testColor, TEST_LOCATION);
113 VisualRenderer move = std::move(renderer);
114 DALI_TEST_CHECK(move);
115 DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
116 DALI_TEST_EQUALS(move.GetProperty<Vector3>(VisualRenderer::Property::VISUAL_MIX_COLOR), testColor, TEST_LOCATION);
117 DALI_TEST_CHECK(!renderer);
122 int UtcDaliVisualRendererMoveAssignment(void)
124 TestApplication application;
126 Geometry geometry = CreateQuadGeometry();
127 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
128 VisualRenderer renderer = VisualRenderer::New(geometry, shader);
129 DALI_TEST_CHECK(renderer);
130 DALI_TEST_EQUALS(1, renderer.GetBaseObject().ReferenceCount(), TEST_LOCATION);
131 DALI_TEST_EQUALS(renderer.GetProperty<Vector3>(VisualRenderer::Property::VISUAL_MIX_COLOR), Vector3::ONE, TEST_LOCATION);
133 renderer.SetProperty(VisualRenderer::Property::VISUAL_MIX_COLOR, Vector3(1.0f, 0.0f, 1.0f));
134 application.SendNotification();
135 application.Render();
136 DALI_TEST_EQUALS(renderer.GetProperty<Vector3>(VisualRenderer::Property::VISUAL_MIX_COLOR), Vector3(1.0f, 0.0f, 1.0f), TEST_LOCATION);
139 move = std::move(renderer);
140 DALI_TEST_CHECK(move);
141 DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
142 DALI_TEST_EQUALS(move.GetProperty<Vector3>(VisualRenderer::Property::VISUAL_MIX_COLOR), Vector3(1.0f, 0.0f, 1.0f), TEST_LOCATION);
143 DALI_TEST_CHECK(!renderer);
148 int UtcDaliVisualRendererDownCast01(void)
150 TestApplication application;
152 Geometry geometry = CreateQuadGeometry();
153 Shader shader = CreateShader();
154 VisualRenderer renderer = VisualRenderer::New(geometry, shader);
156 BaseHandle handle(renderer);
157 VisualRenderer renderer2 = VisualRenderer::DownCast(handle);
158 DALI_TEST_EQUALS((bool)renderer2, true, TEST_LOCATION);
162 int UtcDaliVisualRendererDownCast02(void)
164 TestApplication application;
166 Handle handle = Handle::New(); // Create a custom object
167 VisualRenderer renderer = VisualRenderer::DownCast(handle);
168 DALI_TEST_EQUALS((bool)renderer, false, TEST_LOCATION);
172 // using a template to auto deduce the parameter types
173 template<typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8>
174 void TEST_RENDERER_PROPERTY(P1 renderer, P2 stringName, P3 type, P4 isWriteable, P5 isAnimateable, P6 isConstraintInput, P7 enumName, P8 LOCATION)
176 DALI_TEST_EQUALS(renderer.GetPropertyName(enumName), stringName, LOCATION);
177 DALI_TEST_EQUALS(renderer.GetPropertyIndex(stringName), static_cast<Property::Index>(enumName), LOCATION);
178 DALI_TEST_EQUALS(renderer.GetPropertyType(enumName), type, LOCATION);
179 DALI_TEST_EQUALS(renderer.IsPropertyWritable(enumName), isWriteable, LOCATION);
180 DALI_TEST_EQUALS(renderer.IsPropertyAnimatable(enumName), isAnimateable, LOCATION);
181 DALI_TEST_EQUALS(renderer.IsPropertyAConstraintInput(enumName), isConstraintInput, LOCATION);
184 int UtcDaliVisualRendererDefaultProperties(void)
186 TestApplication application;
187 Geometry geometry = CreateQuadGeometry();
188 Shader shader = CreateShader();
189 VisualRenderer renderer = VisualRenderer::New(geometry, shader);
190 Renderer baseRenderer = Renderer::New(geometry, shader);
192 DALI_TEST_EQUALS(baseRenderer.GetPropertyCount(), 27, TEST_LOCATION);
193 DALI_TEST_EQUALS(renderer.GetPropertyCount(), 27 + 8, TEST_LOCATION);
195 TEST_RENDERER_PROPERTY(renderer, "transformOffset", Property::VECTOR2, true, true, true, VisualRenderer::Property::TRANSFORM_OFFSET, TEST_LOCATION);
196 TEST_RENDERER_PROPERTY(renderer, "transformSize", Property::VECTOR2, true, true, true, VisualRenderer::Property::TRANSFORM_SIZE, TEST_LOCATION);
197 TEST_RENDERER_PROPERTY(renderer, "transformOrigin", Property::VECTOR2, true, false, false, VisualRenderer::Property::TRANSFORM_ORIGIN, TEST_LOCATION);
198 TEST_RENDERER_PROPERTY(renderer, "transformAnchorPoint", Property::VECTOR2, true, false, false, VisualRenderer::Property::TRANSFORM_ANCHOR_POINT, TEST_LOCATION);
199 TEST_RENDERER_PROPERTY(renderer, "transformOffsetSizeMode", Property::VECTOR4, true, false, false, VisualRenderer::Property::TRANSFORM_OFFSET_SIZE_MODE, TEST_LOCATION);
200 TEST_RENDERER_PROPERTY(renderer, "extraSize", Property::VECTOR2, true, true, true, VisualRenderer::Property::EXTRA_SIZE, TEST_LOCATION);
202 TEST_RENDERER_PROPERTY(renderer, "visualMixColor", Property::VECTOR3, true, true, true, VisualRenderer::Property::VISUAL_MIX_COLOR, TEST_LOCATION);
203 TEST_RENDERER_PROPERTY(renderer, "preMultipliedAlpha", Property::FLOAT, true, false, false, VisualRenderer::Property::VISUAL_PRE_MULTIPLIED_ALPHA, TEST_LOCATION);
208 int UtcDaliVisualRendererAnimatedProperty01(void)
210 TestApplication application;
212 tet_infoline("Test that a visual renderer property can be animated");
214 Shader shader = Shader::New("VertexSource", "FragmentSource");
215 Geometry geometry = CreateQuadGeometry();
216 VisualRenderer renderer = VisualRenderer::New(geometry, shader);
218 Actor actor = Actor::New();
219 actor.AddRenderer(renderer);
220 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
221 application.GetScene().Add(actor);
223 Property::Index colorIndex = VisualRenderer::Property::VISUAL_MIX_COLOR;
224 renderer.SetProperty(colorIndex, Vector3(1.0f, 1.0f, 1.0f));
226 application.SendNotification();
227 application.Render(0);
228 DALI_TEST_EQUALS(renderer.GetProperty<Vector3>(colorIndex), Vector3(1.0f, 1.0f, 1.0f), 0.001f, TEST_LOCATION);
230 Animation animation = Animation::New(1.0f);
231 KeyFrames keyFrames = KeyFrames::New();
232 keyFrames.Add(0.0f, Vector3(1.0f, 0.0f, 1.0f));
233 keyFrames.Add(1.0f, Vector3(0.0f, 0.0f, 0.0f));
234 animation.AnimateBetween(Property(renderer, colorIndex), keyFrames);
237 application.SendNotification();
238 application.Render(500);
240 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector3>(colorIndex), Vector3(0.5f, 0.f, 0.5f), TEST_LOCATION);
242 application.Render(400);
243 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector3>(colorIndex), Vector3(0.1f, 0.f, 0.1f), TEST_LOCATION);
245 application.Render(100);
246 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector3>(colorIndex), Vector3(0.f, 0.f, 0.f), TEST_LOCATION);
247 DALI_TEST_EQUALS(renderer.GetProperty<Vector3>(colorIndex), Vector3(0.f, 0.f, 0.f), TEST_LOCATION);
249 // Can we test to see if the actor has stopped being drawn?
253 int UtcDaliVisualRendererAnimatedProperty02(void)
255 TestApplication application;
257 tet_infoline("Test that a visual renderer property can be animated");
259 Shader shader = Shader::New("VertexSource", "FragmentSource");
260 Geometry geometry = CreateQuadGeometry();
261 VisualRenderer renderer = VisualRenderer::New(geometry, shader);
263 Actor actor = Actor::New();
264 actor.AddRenderer(renderer);
265 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
266 application.GetScene().Add(actor);
268 Property::Index index = VisualRenderer::Property::TRANSFORM_OFFSET;
269 renderer.SetProperty(index, Vector2(1.0f, 0.0f));
271 application.SendNotification();
272 application.Render(0);
273 application.SendNotification();
274 application.Render(0);
275 DALI_TEST_EQUALS(renderer.GetProperty<Vector2>(index), Vector2(1.0f, 0.0f), 0.001f, TEST_LOCATION);
277 Animation animation = Animation::New(1.0f);
278 KeyFrames keyFrames = KeyFrames::New();
279 keyFrames.Add(0.0f, Vector2(1.0f, 0.0f));
280 keyFrames.Add(1.0f, Vector2(0.0f, 1.0f));
281 animation.AnimateBetween(Property(renderer, index), keyFrames);
284 application.SendNotification();
285 application.Render(500);
287 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector2>(index), Vector2(0.5f, 0.5f), TEST_LOCATION);
289 application.Render(400);
290 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector2>(index), Vector2(0.1f, 0.9f), TEST_LOCATION);
292 application.Render(100);
293 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector2>(index), Vector2(0.f, 1.0f), TEST_LOCATION);
294 DALI_TEST_EQUALS(renderer.GetProperty<Vector2>(index), Vector2(0.f, 1.f), TEST_LOCATION);
299 struct VisualProperties
301 VisualProperties() = default;
303 VisualProperties(Vector2 offset, Vector2 size, Vector2 origin, Vector2 pivot, Vector4 modes, Vector2 extraSize, Vector3 mixColor, float preMultipliedAlpha)
304 : mTransformOffset(offset),
305 mTransformSize(size),
306 mTransformOrigin(origin),
307 mTransformAnchorPoint(pivot),
308 mTransformOffsetSizeMode(modes),
309 mExtraSize(extraSize),
311 mPreMultipliedAlpha(preMultipliedAlpha)
315 Vector2 mTransformOffset{Vector2::ZERO};
316 Vector2 mTransformSize{Vector2::ONE};
317 Vector2 mTransformOrigin{Vector2::ZERO};
318 Vector2 mTransformAnchorPoint{Vector2::ZERO};
319 Vector4 mTransformOffsetSizeMode{Vector2::ZERO};
320 Vector2 mExtraSize{Vector2::ZERO};
321 Vector3 mMixColor{Vector3::ONE};
322 float mPreMultipliedAlpha{0.0f};
324 static VisualProperties GetPropsAt(float alpha, const VisualProperties& start, const VisualProperties& end)
326 VisualProperties progress;
327 progress.mTransformOffset = start.mTransformOffset + (end.mTransformOffset - start.mTransformOffset) * alpha;
328 progress.mTransformSize = start.mTransformSize + (end.mTransformSize - start.mTransformSize) * alpha;
329 progress.mExtraSize = start.mExtraSize + (end.mExtraSize - start.mExtraSize) * alpha;
330 progress.mMixColor = start.mMixColor + (end.mMixColor - start.mMixColor) * alpha;
331 progress.mTransformOffsetSizeMode = end.mTransformOffsetSizeMode;
332 progress.mTransformOrigin = end.mTransformOrigin;
333 progress.mTransformAnchorPoint = end.mTransformAnchorPoint;
334 progress.mPreMultipliedAlpha = end.mPreMultipliedAlpha;
339 void PrintVisualProperties(const VisualProperties& props, const std::string& prefix)
342 "%s: offset:(%5.3f, %5.3f)\n"
343 "%*c size:(%5.3f, %5.3f)\n"
344 "%*c origin:(%5.3f, %5.3f)\n"
345 "%*c anchorPoint:(%5.3f, %5.3f)\n"
346 "%*c offsetSizeMode:(%5.3f, %5.3f, %5.3f, %5.3f)\n"
347 "%*c extraSize:(%5.3f, %5.3f)\n"
348 "%*c mixColor:(%5.3f, %5.3f, %5.3f)\n"
349 "%*c preMultipliedAlpha:(%5.3f)\n",
351 props.mTransformOffset.x,
352 props.mTransformOffset.y,
355 props.mTransformSize.x,
356 props.mTransformSize.y,
359 props.mTransformOrigin.x,
360 props.mTransformOrigin.y,
363 props.mTransformAnchorPoint.x,
364 props.mTransformAnchorPoint.y,
367 props.mTransformOffsetSizeMode.x,
368 props.mTransformOffsetSizeMode.y,
369 props.mTransformOffsetSizeMode.z,
370 props.mTransformOffsetSizeMode.w,
382 props.mPreMultipliedAlpha);
385 void SetVisualProperties(VisualRenderer renderer, VisualProperties props)
387 renderer.SetProperty(VisualRenderer::Property::TRANSFORM_OFFSET, props.mTransformOffset);
388 renderer.SetProperty(VisualRenderer::Property::TRANSFORM_SIZE, props.mTransformSize);
389 renderer.SetProperty(VisualRenderer::Property::TRANSFORM_ORIGIN, props.mTransformOrigin);
390 renderer.SetProperty(VisualRenderer::Property::TRANSFORM_ANCHOR_POINT, props.mTransformAnchorPoint);
391 renderer.SetProperty(VisualRenderer::Property::TRANSFORM_OFFSET_SIZE_MODE, props.mTransformOffsetSizeMode);
392 renderer.SetProperty(VisualRenderer::Property::EXTRA_SIZE, props.mExtraSize);
393 renderer.SetProperty(VisualRenderer::Property::VISUAL_MIX_COLOR, props.mMixColor);
394 renderer.SetProperty(VisualRenderer::Property::VISUAL_PRE_MULTIPLIED_ALPHA, props.mPreMultipliedAlpha);
397 void CheckEventVisualProperties(VisualRenderer renderer, VisualProperties expectedProps)
399 tet_infoline("CheckEventVisualProperties\n");
401 VisualProperties actualProps;
402 actualProps.mTransformOffset = renderer.GetProperty<Vector2>(VisualRenderer::Property::TRANSFORM_OFFSET);
403 actualProps.mTransformSize = renderer.GetProperty<Vector2>(VisualRenderer::Property::TRANSFORM_SIZE);
404 actualProps.mTransformOrigin = renderer.GetProperty<Vector2>(VisualRenderer::Property::TRANSFORM_ORIGIN);
405 actualProps.mTransformAnchorPoint = renderer.GetProperty<Vector2>(VisualRenderer::Property::TRANSFORM_ANCHOR_POINT);
406 actualProps.mTransformOffsetSizeMode = renderer.GetProperty<Vector4>(VisualRenderer::Property::TRANSFORM_OFFSET_SIZE_MODE);
407 actualProps.mExtraSize = renderer.GetProperty<Vector2>(VisualRenderer::Property::EXTRA_SIZE);
408 actualProps.mMixColor = renderer.GetProperty<Vector3>(VisualRenderer::Property::VISUAL_MIX_COLOR);
409 actualProps.mPreMultipliedAlpha = renderer.GetProperty<float>(VisualRenderer::Property::VISUAL_PRE_MULTIPLIED_ALPHA);
411 PrintVisualProperties(actualProps, "Actual event props");
413 DALI_TEST_EQUALS(actualProps.mTransformOffset, expectedProps.mTransformOffset, TEST_LOCATION);
414 DALI_TEST_EQUALS(actualProps.mTransformSize, expectedProps.mTransformSize, TEST_LOCATION);
415 DALI_TEST_EQUALS(actualProps.mTransformOrigin, expectedProps.mTransformOrigin, TEST_LOCATION);
416 DALI_TEST_EQUALS(actualProps.mTransformAnchorPoint, expectedProps.mTransformAnchorPoint, TEST_LOCATION);
417 DALI_TEST_EQUALS(actualProps.mTransformOffsetSizeMode, expectedProps.mTransformOffsetSizeMode, TEST_LOCATION);
418 DALI_TEST_EQUALS(actualProps.mExtraSize, expectedProps.mExtraSize, TEST_LOCATION);
419 DALI_TEST_EQUALS(actualProps.mMixColor, expectedProps.mMixColor, TEST_LOCATION);
420 DALI_TEST_EQUALS(actualProps.mPreMultipliedAlpha, expectedProps.mPreMultipliedAlpha, TEST_LOCATION);
423 void CheckSceneGraphVisualProperties(VisualRenderer renderer, VisualProperties expectedProps)
425 tet_infoline("CheckSceneGraphVisualProperties\n");
427 VisualProperties actualProps;
429 actualProps.mTransformOffset = renderer.GetCurrentProperty<Vector2>(VisualRenderer::Property::TRANSFORM_OFFSET);
430 actualProps.mTransformSize = renderer.GetCurrentProperty<Vector2>(VisualRenderer::Property::TRANSFORM_SIZE);
431 actualProps.mTransformOrigin = renderer.GetCurrentProperty<Vector2>(VisualRenderer::Property::TRANSFORM_ORIGIN);
432 actualProps.mTransformAnchorPoint = renderer.GetCurrentProperty<Vector2>(VisualRenderer::Property::TRANSFORM_ANCHOR_POINT);
433 actualProps.mTransformOffsetSizeMode = renderer.GetCurrentProperty<Vector4>(VisualRenderer::Property::TRANSFORM_OFFSET_SIZE_MODE);
434 actualProps.mExtraSize = renderer.GetCurrentProperty<Vector2>(VisualRenderer::Property::EXTRA_SIZE);
435 actualProps.mMixColor = renderer.GetCurrentProperty<Vector3>(VisualRenderer::Property::VISUAL_MIX_COLOR);
436 actualProps.mPreMultipliedAlpha = renderer.GetProperty<float>(VisualRenderer::Property::VISUAL_PRE_MULTIPLIED_ALPHA);
438 PrintVisualProperties(actualProps, "Actual update props");
440 DALI_TEST_EQUALS(actualProps.mTransformOffset, expectedProps.mTransformOffset, TEST_LOCATION);
441 DALI_TEST_EQUALS(actualProps.mTransformSize, expectedProps.mTransformSize, TEST_LOCATION);
442 DALI_TEST_EQUALS(actualProps.mTransformOrigin, expectedProps.mTransformOrigin, TEST_LOCATION);
443 DALI_TEST_EQUALS(actualProps.mTransformAnchorPoint, expectedProps.mTransformAnchorPoint, TEST_LOCATION);
444 DALI_TEST_EQUALS(actualProps.mTransformOffsetSizeMode, expectedProps.mTransformOffsetSizeMode, TEST_LOCATION);
445 DALI_TEST_EQUALS(actualProps.mExtraSize, expectedProps.mExtraSize, TEST_LOCATION);
446 DALI_TEST_EQUALS(actualProps.mMixColor, expectedProps.mMixColor, TEST_LOCATION);
447 DALI_TEST_EQUALS(actualProps.mPreMultipliedAlpha, expectedProps.mPreMultipliedAlpha, TEST_LOCATION);
450 void CheckUniforms(VisualRenderer renderer, VisualProperties props, std::vector<UniformData>& uniforms, TraceCallStack& callStack, TestGlAbstraction& gl)
452 tet_infoline("CheckUniforms\n");
454 TraceCallStack::NamedParams params;
456 tet_printf("Callback trace: \n%s\n", callStack.GetTraceString().c_str());
458 DALI_TEST_CHECK(callStack.FindMethodAndGetParameters(uniforms[0].name, params));
459 DALI_TEST_CHECK(gl.GetUniformValue<Vector2>(uniforms[0].name.c_str(), props.mTransformOffset));
461 DALI_TEST_CHECK(callStack.FindMethodAndGetParameters(uniforms[1].name, params));
462 DALI_TEST_CHECK(gl.GetUniformValue<Vector2>(uniforms[1].name.c_str(), props.mTransformSize));
464 DALI_TEST_CHECK(callStack.FindMethodAndGetParameters(uniforms[2].name, params));
465 DALI_TEST_CHECK(gl.GetUniformValue<Vector2>(uniforms[2].name.c_str(), props.mTransformOrigin));
467 DALI_TEST_CHECK(callStack.FindMethodAndGetParameters(uniforms[3].name, params));
468 DALI_TEST_CHECK(gl.GetUniformValue<Vector2>(uniforms[3].name.c_str(), props.mTransformAnchorPoint));
470 DALI_TEST_CHECK(callStack.FindMethodAndGetParameters(uniforms[4].name, params));
471 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>(uniforms[4].name.c_str(), props.mTransformOffsetSizeMode));
473 DALI_TEST_CHECK(callStack.FindMethodAndGetParameters(uniforms[5].name, params));
474 DALI_TEST_CHECK(gl.GetUniformValue<Vector2>(uniforms[5].name.c_str(), props.mExtraSize));
476 DALI_TEST_CHECK(callStack.FindMethodAndGetParameters(uniforms[6].name, params));
477 DALI_TEST_CHECK(gl.GetUniformValue<Vector3>(uniforms[6].name.c_str(), props.mMixColor));
479 DALI_TEST_CHECK(callStack.FindMethodAndGetParameters(uniforms[7].name, params));
480 DALI_TEST_CHECK(gl.GetUniformValue<float>(uniforms[7].name.c_str(), props.mPreMultipliedAlpha));
483 int UtcDaliVisualRendererAnimatedProperty03(void)
485 TestApplication application;
486 TestGlAbstraction& gl = application.GetGlAbstraction();
487 TraceCallStack& callStack = gl.GetSetUniformTrace();
488 gl.EnableSetUniformCallTrace(true);
490 tet_infoline("Test that a visual renderer property can be animated and that the uniforms are set");
492 std::vector<UniformData> customUniforms{{"offset", Property::VECTOR2},
493 {"size", Property::VECTOR2},
494 {"origin", Property::VECTOR2},
495 {"anchorPoint", Property::VECTOR2},
496 {"offsetSizeMode", Property::VECTOR4},
497 {"extraSize", Property::VECTOR2},
498 {"mixColor", Property::VECTOR3},
499 {"preMultipliedAlpha", Property::FLOAT}};
501 application.GetGraphicsController().AddCustomUniforms(customUniforms);
503 Shader shader = Shader::New("VertexSource", "FragmentSource");
504 Geometry geometry = CreateQuadGeometry();
505 VisualRenderer renderer = VisualRenderer::New(geometry, shader);
507 Actor actor = Actor::New();
508 actor.AddRenderer(renderer);
509 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
510 application.GetScene().Add(actor);
512 VisualProperties 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};
513 VisualProperties 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};
515 SetVisualProperties(renderer, props);
516 CheckEventVisualProperties(renderer, props);
517 application.SendNotification();
518 application.Render(0);
519 CheckSceneGraphVisualProperties(renderer, props);
520 CheckUniforms(renderer, props, customUniforms, callStack, gl);
522 // Set up a 1 second anim.
523 Animation animation = Animation::New(1.0f);
525 animation.AnimateTo(Property(renderer, VisualRenderer::Property::TRANSFORM_OFFSET), targetProps.mTransformOffset);
526 animation.AnimateTo(Property(renderer, VisualRenderer::Property::TRANSFORM_SIZE), targetProps.mTransformSize);
527 animation.AnimateTo(Property(renderer, VisualRenderer::Property::EXTRA_SIZE), targetProps.mExtraSize);
528 animation.AnimateTo(Property(renderer, VisualRenderer::Property::VISUAL_MIX_COLOR), targetProps.mMixColor);
531 CheckEventVisualProperties(renderer, targetProps);
533 for(int i = 0; i <= 10; ++i)
535 tet_printf("\n########### Animation progress: %d%%\n\n", i * 10);
536 VisualProperties propsProgress = VisualProperties::GetPropsAt(0.1f * i, props, targetProps);
537 PrintVisualProperties(propsProgress, "Expected values");
540 application.SendNotification();
541 application.Render((i == 0 ? 0 : 100));
543 CheckEventVisualProperties(renderer, targetProps);
545 CheckSceneGraphVisualProperties(renderer, propsProgress);
546 CheckUniforms(renderer, propsProgress, customUniforms, callStack, gl);
549 // Ensure animation finishes
550 application.SendNotification();
551 application.Render(100);
552 CheckSceneGraphVisualProperties(renderer, targetProps);
553 CheckUniforms(renderer, targetProps, customUniforms, callStack, gl);
558 int UtcDaliVisualRendererAnimatedProperty04(void)
560 TestApplication application;
562 tet_infoline("Test that a visual renderer property can't be animated");
564 Shader shader = Shader::New("VertexSource", "FragmentSource");
565 Geometry geometry = CreateQuadGeometry();
566 VisualRenderer renderer = VisualRenderer::New(geometry, shader);
568 Actor actor = Actor::New();
569 actor.AddRenderer(renderer);
570 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
571 application.GetScene().Add(actor);
573 Property::Index index = VisualRenderer::Property::TRANSFORM_ANCHOR_POINT;
574 renderer.SetProperty(index, Vector2(AnchorPoint::TOP_RIGHT));
576 application.SendNotification();
577 application.Render(0);
578 DALI_TEST_EQUALS(renderer.GetProperty<Vector2>(index), Vector2(AnchorPoint::TOP_RIGHT), 0.001f, TEST_LOCATION);
580 Animation animation = Animation::New(1.0f);
581 KeyFrames keyFrames = KeyFrames::New();
582 keyFrames.Add(0.0f, Vector2::ZERO);
583 keyFrames.Add(1.0f, Vector2(10.0f, 10.0f));
586 animation.AnimateBetween(Property(renderer, index), keyFrames);
587 tet_result(TET_FAIL);
589 catch(DaliException& e)
591 DALI_TEST_ASSERT(e, "baseProperty && \"Property is not animatable\"", TEST_LOCATION);
597 int UtcDaliVisualRendererAnimatedProperty05(void)
599 TestApplication application;
601 tet_infoline("Test that a visual renderer property can't be animated");
603 Shader shader = Shader::New("VertexSource", "FragmentSource");
604 Geometry geometry = CreateQuadGeometry();
605 VisualRenderer renderer = VisualRenderer::New(geometry, shader);
607 Actor actor = Actor::New();
608 actor.AddRenderer(renderer);
609 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
610 application.GetScene().Add(actor);
612 Property::Index index = VisualRenderer::Property::VISUAL_PRE_MULTIPLIED_ALPHA;
613 renderer.SetProperty(index, 1.0f);
615 application.SendNotification();
616 application.Render(0);
617 DALI_TEST_EQUALS(renderer.GetProperty<float>(index), 1.0f, 0.001f, TEST_LOCATION);
619 Animation animation = Animation::New(1.0f);
620 KeyFrames keyFrames = KeyFrames::New();
621 keyFrames.Add(0.0f, 0.5f);
622 keyFrames.Add(1.0f, 1.0f);
625 animation.AnimateBetween(Property(renderer, index), keyFrames);
626 tet_result(TET_FAIL);
628 catch(DaliException& e)
630 DALI_TEST_ASSERT(e, "baseProperty && \"Property is not animatable\"", TEST_LOCATION);
633 DALI_TEST_EQUALS(renderer.GetProperty<float>(index), 1.0f, 0.0001f, TEST_LOCATION);
634 DALI_TEST_EQUALS(renderer.GetCurrentProperty<float>(index), 1.0f, 0.0001f, TEST_LOCATION);
639 int UtcDaliVisualRendererAnimatedProperty06(void)
641 TestApplication application;
643 tet_infoline("Test that a parent renderer property can still be animated");
645 Shader shader = Shader::New("VertexSource", "FragmentSource");
646 Geometry geometry = CreateQuadGeometry();
647 VisualRenderer renderer = VisualRenderer::New(geometry, shader);
649 Actor actor = Actor::New();
650 actor.AddRenderer(renderer);
651 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
652 application.GetScene().Add(actor);
654 Property::Index index = DevelRenderer::Property::OPACITY;
655 renderer.SetProperty(index, 1.0f);
657 application.SendNotification();
658 application.Render(0);
659 DALI_TEST_EQUALS(renderer.GetProperty<float>(index), 1.0f, 0.001f, TEST_LOCATION);
660 DALI_TEST_EQUALS(renderer.GetCurrentProperty<float>(DevelRenderer::Property::OPACITY), 1.0f, 0.0001f, TEST_LOCATION);
662 Animation animation = Animation::New(1.0f);
663 KeyFrames keyFrames = KeyFrames::New();
664 keyFrames.Add(0.0f, float(0.5f));
665 keyFrames.Add(1.0f, float(0.0f));
666 animation.AnimateBetween(Property(renderer, index), keyFrames);
669 application.SendNotification();
671 // Test that the event side properties are set to target value of 0
672 DALI_TEST_EQUALS(renderer.GetProperty<float>(DevelRenderer::Property::OPACITY), 0.0f, 0.0001f, TEST_LOCATION);
674 application.Render(500);
676 DALI_TEST_EQUALS(renderer.GetCurrentProperty<float>(index), 0.25f, 0.0001f, TEST_LOCATION);
677 DALI_TEST_EQUALS(renderer.GetCurrentProperty<float>(DevelRenderer::Property::OPACITY), 0.25f, 0.0001f, TEST_LOCATION);
679 // Test that the event side properties are set to target value 0f 0
680 DALI_TEST_EQUALS(renderer.GetProperty<float>(DevelRenderer::Property::OPACITY), 0.0f, 0.0001f, TEST_LOCATION);
682 // Complete the animation
683 application.Render(500);
685 DALI_TEST_EQUALS(renderer.GetCurrentProperty<float>(index), 0.0f, 0.0001f, TEST_LOCATION);
686 DALI_TEST_EQUALS(renderer.GetCurrentProperty<float>(DevelRenderer::Property::OPACITY), 0.0f, 0.0001f, TEST_LOCATION);
687 DALI_TEST_EQUALS(renderer.GetProperty<float>(DevelRenderer::Property::OPACITY), 0.0f, 0.0001f, TEST_LOCATION);
691 int UtcDaliVisualRendererPartialUpdate(void)
693 TestApplication application(
694 TestApplication::DEFAULT_SURFACE_WIDTH,
695 TestApplication::DEFAULT_SURFACE_HEIGHT,
696 TestApplication::DEFAULT_HORIZONTAL_DPI,
697 TestApplication::DEFAULT_VERTICAL_DPI,
701 tet_infoline("Test that partial update works well when we set visual renderer's animated properties");
703 const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
705 Shader shader = Shader::New("VertexSource", "FragmentSource");
706 Geometry geometry = CreateQuadGeometry();
707 VisualRenderer renderer = VisualRenderer::New(geometry, shader);
709 Actor actor = Actor::New();
710 actor.AddRenderer(renderer);
711 actor[Actor::Property::ANCHOR_POINT] = AnchorPoint::TOP_LEFT;
712 actor[Actor::Property::POSITION] = Vector3(64.0f, 64.0f, 0.0f);
713 actor[Actor::Property::SIZE] = Vector3(64.0f, 64.0f, 0.0f);
714 actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
715 application.GetScene().Add(actor);
717 application.SendNotification();
719 std::vector<Rect<int>> damagedRects;
721 // Actor added, damaged rect is added size of actor
722 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
723 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
726 Rect<int> clippingRect = Rect<int>(64, 672, 80, 80); // in screen coordinates, includes 3 last frames updates
727 DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
729 application.RenderWithPartialUpdate(damagedRects, clippingRect);
730 DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
731 DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
732 DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
733 DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
735 damagedRects.clear();
736 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
737 application.RenderWithPartialUpdate(damagedRects, clippingRect);
739 damagedRects.clear();
740 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
741 application.RenderWithPartialUpdate(damagedRects, clippingRect);
743 // Set clippingRect as full surface now. TODO : Set valid rect if we can.
744 clippingRect = TestApplication::DEFAULT_SURFACE_RECT;
746 Property::Index index = VisualRenderer::Property::TRANSFORM_SIZE;
747 renderer.SetProperty(index, Vector2(2.0f, 0.5f));
749 // Now current actor show as 128x32 rectangle, with center position (96, 96).
750 // So, rectangle's top left position is (32, 80), and bottom right position is (160, 112).
751 // NOTE : VisualTransform's anchor point is not relative with actor's anchor point
753 application.SendNotification();
754 damagedRects.clear();
755 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
756 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
758 // Note, this damagedRect is combine of previous rect and current rect
759 DALI_TEST_EQUALS<Rect<int>>(Rect<int>(32, 672, 144, 80), damagedRects[0], TEST_LOCATION);
761 application.RenderWithPartialUpdate(damagedRects, clippingRect);
763 application.SendNotification();
764 damagedRects.clear();
765 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
766 application.RenderWithPartialUpdate(damagedRects, clippingRect);
768 // Update dummy property to damangeRect buffer aging
769 actor.SetProperty(Actor::Property::COLOR, Color::RED);
771 application.SendNotification();
772 damagedRects.clear();
773 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
774 application.RenderWithPartialUpdate(damagedRects, clippingRect);
775 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
777 // Update dummy property to damangeRect buffer aging
778 actor.SetProperty(Actor::Property::COLOR, Color::BLUE);
780 application.SendNotification();
781 damagedRects.clear();
782 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
783 application.RenderWithPartialUpdate(damagedRects, clippingRect);
784 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
787 // Note, this damagedRect don't contain previous rect now.
788 // Current rectangle's top left position is (32, 80), and bottom right position is (160, 112).
789 DALI_TEST_EQUALS<Rect<int>>(Rect<int>(32, 688, 144, 48), damagedRects[0], TEST_LOCATION);
791 application.SendNotification();
792 damagedRects.clear();
793 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
794 application.RenderWithPartialUpdate(damagedRects, clippingRect);
796 application.SendNotification();
797 damagedRects.clear();
798 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
799 application.RenderWithPartialUpdate(damagedRects, clippingRect);
801 application.SendNotification();
802 damagedRects.clear();
803 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
804 application.RenderWithPartialUpdate(damagedRects, clippingRect);
806 // 3 frame spended after change actor property. Ensure the damaged rect is empty
807 DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
809 DALI_TEST_EQUALS(renderer.GetProperty<Vector2>(index), Vector2(2.0f, 0.5f), 0.001f, TEST_LOCATION);
811 // Make flickered animation from Vector2(2.0f, 0.5f) --> Vector2(1.0f, 1.0f) --> Vector2(0.5f, 2.0f)
812 // After finish the animation,actor show as 32x128 rectangle, with center position (96, 96).
813 // So, rectangle's top left position is (80, 32), and bottom right position is (112, 160).
814 Animation animation = Animation::New(1.0f);
815 KeyFrames keyFrames = KeyFrames::New();
816 keyFrames.Add(0.0f, Vector2(2.0f, 0.5f));
817 keyFrames.Add(0.299f, Vector2(2.0f, 0.5f));
818 keyFrames.Add(0.301f, Vector2(1.0f, 1.0f));
819 keyFrames.Add(0.699f, Vector2(1.0f, 1.0f));
820 keyFrames.Add(0.701f, Vector2(0.5f, 2.0f));
821 keyFrames.Add(1.0f, Vector2(0.5f, 2.0f));
822 animation.AnimateBetween(Property(renderer, index), keyFrames);
825 application.SendNotification();
826 damagedRects.clear();
827 application.PreRenderWithPartialUpdate(200, nullptr, damagedRects); // 200 ms
828 application.RenderWithPartialUpdate(damagedRects, clippingRect);
830 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector2>(index), Vector2(2.0f, 0.5f), TEST_LOCATION);
832 // 302 ~ 600. TransformSize become Vector2(1.0f, 1.0f)
833 application.SendNotification();
834 damagedRects.clear();
835 application.PreRenderWithPartialUpdate(102, nullptr, damagedRects); // 302 ms
836 application.RenderWithPartialUpdate(damagedRects, clippingRect);
838 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector2>(index), Vector2(1.0f, 1.0f), TEST_LOCATION);
840 // Update dummy property to damangeRect buffer aging
841 actor.SetProperty(Actor::Property::COLOR, Color::RED);
843 application.SendNotification();
844 damagedRects.clear();
845 application.PreRenderWithPartialUpdate(16, nullptr, damagedRects); // 318 ms
846 application.RenderWithPartialUpdate(damagedRects, clippingRect);
848 // Update dummy property to damangeRect buffer aging
849 actor.SetProperty(Actor::Property::COLOR, Color::GREEN);
851 application.SendNotification();
852 damagedRects.clear();
853 application.PreRenderWithPartialUpdate(16, nullptr, damagedRects); // 334 ms
854 application.RenderWithPartialUpdate(damagedRects, clippingRect);
856 // Update dummy property to damangeRect buffer aging
857 actor.SetProperty(Actor::Property::COLOR, Color::RED);
859 application.SendNotification();
860 damagedRects.clear();
861 application.PreRenderWithPartialUpdate(16, nullptr, damagedRects); // 350 ms
862 application.RenderWithPartialUpdate(damagedRects, clippingRect);
864 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
866 DALI_TEST_EQUALS<Rect<int>>(Rect<int>(64, 672, 80, 80), damagedRects[0], TEST_LOCATION);
868 application.SendNotification();
869 damagedRects.clear();
870 application.PreRenderWithPartialUpdate(250, nullptr, damagedRects); // 600 ms
871 application.RenderWithPartialUpdate(damagedRects, clippingRect);
873 // 702 ~ 1000. TransformSize become Vector2(0.5f, 2.0f)
874 damagedRects.clear();
875 application.PreRenderWithPartialUpdate(102, nullptr, damagedRects); // 702 ms
876 application.RenderWithPartialUpdate(damagedRects, clippingRect);
878 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector2>(index), Vector2(0.5f, 2.0f), TEST_LOCATION);
880 // Update dummy property to damangeRect buffer aging
881 actor.SetProperty(Actor::Property::COLOR, Color::GREEN);
883 application.SendNotification();
884 damagedRects.clear();
885 application.PreRenderWithPartialUpdate(16, nullptr, damagedRects); // 718 ms
886 application.RenderWithPartialUpdate(damagedRects, clippingRect);
888 // Update dummy property to damangeRect buffer aging
889 actor.SetProperty(Actor::Property::COLOR, Color::BLUE);
891 application.SendNotification();
892 damagedRects.clear();
893 application.PreRenderWithPartialUpdate(16, nullptr, damagedRects); // 734 ms
894 application.RenderWithPartialUpdate(damagedRects, clippingRect);
896 // Update dummy property to damangeRect buffer aging
897 actor.SetProperty(Actor::Property::COLOR, Color::RED);
899 application.SendNotification();
900 damagedRects.clear();
901 application.PreRenderWithPartialUpdate(16, nullptr, damagedRects); // 750 ms
902 application.RenderWithPartialUpdate(damagedRects, clippingRect);
904 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
906 DALI_TEST_EQUALS<Rect<int>>(Rect<int>(80, 640, 48, 144), damagedRects[0], TEST_LOCATION);
908 application.SendNotification();
909 damagedRects.clear();
910 application.PreRenderWithPartialUpdate(52, nullptr, damagedRects); // 1002 ms. animation finished.
911 application.RenderWithPartialUpdate(damagedRects, clippingRect);
913 // Check finished value bake.
914 DALI_TEST_EQUALS(renderer.GetProperty<Vector2>(index), Vector2(0.5f, 2.0f), TEST_LOCATION);