2 * Copyright (c) 2017 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-toolkit-test-suite-utils.h>
20 #include <toolkit-timer.h>
21 #include <toolkit-bitmap-loader.h>
22 #include <toolkit-event-thread-callback.h>
23 #include <dali/public-api/rendering/renderer.h>
24 #include <dali/public-api/rendering/texture-set.h>
25 #include <dali/public-api/rendering/shader.h>
26 #include <dali/devel-api/images/nine-patch-image.h>
27 #include <dali/devel-api/object/handle-devel.h>
28 #include <dali-toolkit/devel-api/align-enums.h>
29 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
30 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
31 #include <dali-toolkit/devel-api/visual-factory/transition-data.h>
32 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
33 #include <dali-toolkit/dali-toolkit.h>
34 #include "dummy-control.h"
37 using namespace Dali::Toolkit;
39 void dali_image_visual_startup(void)
41 test_return_value = TET_UNDEF;
44 void dali_image_visual_cleanup(void)
46 test_return_value = TET_PASS;
51 const char* TEST_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/gallery_small-1.jpg";
52 const char* TEST_LARGE_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/tbcol.png";
53 const char* TEST_SMALL_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/icon-edit.png";
54 const char* TEST_REMOTE_IMAGE_FILE_NAME = "https://www.tizen.org/sites/all/themes/tizen_theme/logo.png";
55 const char* TEST_INVALID_FILE_NAME = TEST_RESOURCE_DIR "/invalid.jpg";
56 const char* TEST_REMOTE_INVALID_FILE_NAME = "https://www.tizen.org/invalid.png";
60 Actor CreateActorWithImageVisual(const Property::Map& map)
62 VisualFactory factory = VisualFactory::Get();
63 DummyControl actor = DummyControl::New();
64 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
65 Visual::Base visual = factory.CreateVisual( map );
66 DALI_TEST_CHECK( visual );
67 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
68 actor.SetSize( 200.f, 200.f );
69 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
73 void TestVisualRender( ToolkitTestApplication& application,
76 std::size_t expectedSamplers = 0,
77 ImageDimensions imageDimensions = ImageDimensions(),
78 Integration::ResourcePointer resourcePtr = Integration::ResourcePointer())
80 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
81 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
85 // set the image size, for test case, this needs to be set before loading started
86 application.GetPlatform().SetClosestImageSize( Vector2(imageDimensions.GetWidth(), imageDimensions.GetHeight()) );
89 actor.SetSize( 200.f, 200.f );
90 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
92 Stage::GetCurrent().Add( actor );
94 application.SendNotification(); // Send messages to update
95 application.Render(); // process update and render
96 application.SendNotification(); // process any signals to event
100 DALI_TEST_EQUALS( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceSynchronouslyFunc ), true, TEST_LOCATION);
103 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
106 static void TestMixColor( Visual::Base visual, Property::Index mixColorIndex, const Vector4& testColor )
109 visual.CreatePropertyMap(map);
110 Property::Value* value = map.Find( mixColorIndex );
111 DALI_TEST_CHECK( value );
113 DALI_TEST_CHECK( value->Get( mixColor1 ) );
114 DALI_TEST_EQUALS( mixColor1, Vector3(testColor), 0.001, TEST_LOCATION );
116 value = map.Find( DevelVisual::Property::MIX_COLOR );
117 DALI_TEST_CHECK( value );
119 DALI_TEST_CHECK( value->Get( mixColor2 ) );
120 DALI_TEST_EQUALS( mixColor2, testColor, 0.001, TEST_LOCATION );
122 value = map.Find( DevelVisual::Property::OPACITY );
123 DALI_TEST_CHECK( value );
125 DALI_TEST_CHECK( value->Get( opacity ) );
126 DALI_TEST_EQUALS( opacity, testColor.a, 0.001, TEST_LOCATION );
131 int UtcDaliImageVisualPropertyMap(void)
133 ToolkitTestApplication application;
134 tet_infoline( "Request image visual with a Property::Map" );
136 VisualFactory factory = VisualFactory::Get();
137 DALI_TEST_CHECK( factory );
139 Property::Map propertyMap;
140 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
141 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
143 Visual::Base visual = factory.CreateVisual( propertyMap );
144 DALI_TEST_CHECK( visual );
146 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
147 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
149 TestGlAbstraction& gl = application.GetGlAbstraction();
150 TraceCallStack& textureTrace = gl.GetTextureTrace();
151 textureTrace.Enable(true);
153 DummyControl actor = DummyControl::New();
154 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
155 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
157 actor.SetSize( 200.f, 200.f );
158 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
160 Stage::GetCurrent().Add( actor );
161 application.SendNotification();
162 application.Render();
164 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
166 application.SendNotification();
167 application.Render();
169 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
171 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
173 Stage::GetCurrent().Remove( actor );
174 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
180 int UtcDaliImageVisualRemoteImageLoad(void)
182 ToolkitTestApplication application;
183 tet_infoline( "Request remote image visual with a Property::Map" );
185 VisualFactory factory = VisualFactory::Get();
186 DALI_TEST_CHECK( factory );
188 Property::Map propertyMap;
189 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
190 propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME );
192 Visual::Base visual = factory.CreateVisual( propertyMap );
193 DALI_TEST_CHECK( visual );
195 TestGlAbstraction& gl = application.GetGlAbstraction();
196 TraceCallStack& textureTrace = gl.GetTextureTrace();
197 textureTrace.Enable(true);
199 DummyControl actor = DummyControl::New();
200 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
201 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
203 actor.SetSize( 200.f, 200.f );
204 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
206 Stage::GetCurrent().Add( actor );
207 application.SendNotification();
209 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
211 application.SendNotification();
212 application.Render();
214 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
215 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
217 Stage::GetCurrent().Remove( actor );
218 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
223 int UtcDaliImageVisualTextureReuse1(void)
225 ToolkitTestApplication application;
226 tet_infoline( "Request remote image visual with a Property::Map; request a second visual with the same property map - should reuse texture" );
228 Property::Map propertyMap;
229 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
230 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
232 TestGlAbstraction& gl = application.GetGlAbstraction();
233 TraceCallStack& textureTrace = gl.GetTextureTrace();
234 textureTrace.Enable(true);
235 TraceCallStack& drawTrace = gl.GetDrawTrace();
236 drawTrace.Enable(true);
238 Actor actor = CreateActorWithImageVisual( propertyMap );
239 Stage::GetCurrent().Add( actor );
240 application.SendNotification();
242 // Wait for image to load
243 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
245 application.SendNotification();
246 application.Render();
248 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
249 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
250 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
251 DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION );
252 textureTrace.Reset();
255 Actor actor2 = CreateActorWithImageVisual( propertyMap );
256 Stage::GetCurrent().Add(actor2);
258 application.SendNotification(); // Send messages to update
259 application.Render(); // process update and render
260 application.SendNotification(); // process any signals to event
262 DALI_TEST_EQUALS( actor2.GetRendererCount(), 1u, TEST_LOCATION );
264 tet_infoline("Test that 2 draw calls occur with no new texture gens/binds, i.e. both\n"
265 "draw calls use the same texture as the previous draw call\n" );
267 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
268 DALI_TEST_EQUALS( drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION );
269 DALI_TEST_EQUALS( textureTrace.CountMethod("BindTexture"), 0, TEST_LOCATION );
271 tet_infoline("Test that removing 1 actor doesn't delete the texture\n");
273 Stage::GetCurrent().Remove( actor );
274 application.SendNotification();
275 application.Render();
277 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
278 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
280 tet_infoline("Test that removing last actor does delete the texture\n");
282 Stage::GetCurrent().Remove( actor2 );
283 application.SendNotification();
284 application.Render();
286 DALI_TEST_CHECK( actor2.GetRendererCount() == 0u );
287 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
293 int UtcDaliImageVisualTextureReuse2(void)
295 ToolkitTestApplication application;
296 tet_infoline( "Request remote image visual with a Property::Map; request a second visual with the same url but different property map - should create new texture" );
298 Property::Map propertyMap;
299 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
300 propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME );
302 TestGlAbstraction& gl = application.GetGlAbstraction();
303 TraceCallStack& textureTrace = gl.GetTextureTrace();
304 textureTrace.Enable(true);
305 TraceCallStack& drawTrace = gl.GetDrawTrace();
306 drawTrace.Enable(true);
308 Actor actor = CreateActorWithImageVisual( propertyMap );
309 Stage::GetCurrent().Add( actor );
310 application.SendNotification();
312 // Wait for image to load
313 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
315 application.SendNotification();
316 application.Render();
318 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
319 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
320 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
321 DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION );
322 textureTrace.Reset();
325 propertyMap.Insert( ImageVisual::Property::SAMPLING_MODE, Dali::SamplingMode::NEAREST );
326 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, 100 );
327 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, 100 );
328 Actor actor2 = CreateActorWithImageVisual( propertyMap );
329 Stage::GetCurrent().Add(actor2);
331 application.SendNotification();
333 // Wait for image to load
334 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
336 application.SendNotification();
337 application.Render();
339 DALI_TEST_EQUALS( actor2.GetRendererCount(), 1u, TEST_LOCATION );
341 tet_infoline("Test that 2 draw calls occur with 1 new texture gen/bind, i.e. both "
342 "renderers are using different textures\n" );
344 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
345 DALI_TEST_EQUALS( drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION );
346 DALI_TEST_EQUALS( textureTrace.CountMethod("BindTexture"), 2, TEST_LOCATION );
348 tet_infoline("Test that removing 1 actor deletes it's texture\n");
350 Stage::GetCurrent().Remove( actor );
351 application.SendNotification();
352 application.Render();
354 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
355 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
357 tet_infoline("Test that removing last actor deletes it's texture\n");
359 Stage::GetCurrent().Remove( actor2 );
360 application.SendNotification();
361 application.Render();
363 DALI_TEST_CHECK( actor2.GetRendererCount() == 0u );
364 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 2, TEST_LOCATION );
370 int UtcDaliImageVisualImageHandle(void)
372 ToolkitTestApplication application;
373 tet_infoline( "Request image visual with an image handle" );
375 VisualFactory factory = VisualFactory::Get();
376 DALI_TEST_CHECK( factory );
378 Image image = ResourceImage::New(TEST_IMAGE_FILE_NAME);
379 Visual::Base visual = factory.CreateVisual( image );
381 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
382 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
385 const int height=513;
387 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD );
388 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, width, height,width, height );
390 TestGlAbstraction& gl = application.GetGlAbstraction();
391 TraceCallStack& textureTrace = gl.GetTextureTrace();
392 textureTrace.Enable(true);
394 DummyControl actor = DummyControl::New();
395 TestVisualRender( application, actor, visual, 1u,
396 ImageDimensions(width, height),
397 Integration::ResourcePointer(bitmap) );
399 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
403 int UtcDaliImageVisualCustomWrapModePixelArea(void)
405 ToolkitTestApplication application;
406 tet_infoline( "Request image visual with a Property::Map, test custom wrap mode and pixel area with atlasing" );
408 VisualFactory factory = VisualFactory::Get();
409 DALI_TEST_CHECK( factory );
411 // Test wrap mode with atlasing. Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
414 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
416 Property::Map propertyMap;
417 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
418 propertyMap.Insert( ImageVisual::Property::URL, TEST_SMALL_IMAGE_FILE_NAME );
419 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, width );
420 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, height );
421 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
422 propertyMap.Insert( ImageVisual::Property::PIXEL_AREA, pixelArea );
423 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT );
424 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
425 propertyMap.Insert( DevelImageVisual::Property::ATLASING, true );
427 Visual::Base visual = factory.CreateVisual( propertyMap );
428 DALI_TEST_CHECK( visual );
430 TestGlAbstraction& gl = application.GetGlAbstraction();
431 TraceCallStack& textureTrace = gl.GetTextureTrace();
432 textureTrace.Enable(true);
433 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
434 texParameterTrace.Enable( true );
436 DummyControl actor = DummyControl::New();
437 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
438 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
439 actor.SetSize(2000, 2000);
440 actor.SetParentOrigin(ParentOrigin::CENTER);
441 Stage::GetCurrent().Add( actor );
444 application.SendNotification();
445 application.Render();
447 BitmapLoader loader = BitmapLoader::GetLatestCreated();
448 DALI_TEST_CHECK( loader );
449 loader.WaitForLoading();// waiting until the image to be loaded
450 DALI_TEST_CHECK( loader.IsLoaded() );
452 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
454 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
456 // WITH atlasing, the wrapping is handled manually in shader, so the following gl function should not be called
457 std::stringstream out;
458 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
459 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
461 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
462 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
464 // test the uniforms which used to handle the wrap mode
465 Renderer renderer = actor.GetRendererAt( 0u );
466 DALI_TEST_CHECK( renderer );
468 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
469 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
470 Vector4 pixelAreaUniform;
471 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
472 DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
474 Property::Value wrapModeValue = renderer.GetProperty( renderer.GetPropertyIndex( "wrapMode" ) );
475 Vector2 wrapMode( WrapMode::MIRRORED_REPEAT-1, WrapMode::REPEAT-1 );
476 DALI_TEST_EQUALS( wrapModeValue.Get<Vector2>(), wrapMode, TEST_LOCATION );
477 Vector2 wrapModeUniform;
478 DALI_TEST_CHECK( gl.GetUniformValue<Vector2>( "wrapMode", wrapModeUniform ) );
479 DALI_TEST_EQUALS( wrapMode, wrapModeUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
482 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
487 int UtcDaliImageVisualCustomWrapModeNoAtlas(void)
489 ToolkitTestApplication application;
490 tet_infoline( "Request image visual with a Property::Map, test custom wrap mode and pixel area without atlasing" );
492 VisualFactory factory = VisualFactory::Get();
493 DALI_TEST_CHECK( factory );
495 // Test wrap mode without atlasing. Image with a size bigger than 512*512 will NOT be uploaded as a part of the atlas.
497 const int height=600;
498 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
500 Property::Map propertyMap;
501 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
502 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
503 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, width );
504 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, height );
505 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
506 propertyMap.Insert( ImageVisual::Property::PIXEL_AREA, pixelArea );
507 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT );
508 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
510 Visual::Base visual = factory.CreateVisual( propertyMap );
511 DALI_TEST_CHECK( visual );
513 TestGlAbstraction& gl = application.GetGlAbstraction();
514 TraceCallStack& textureTrace = gl.GetTextureTrace();
515 textureTrace.Enable(true);
516 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
517 texParameterTrace.Enable( true );
519 DummyControl actor = DummyControl::New();
520 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
521 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
522 actor.SetSize(2000, 2000);
523 actor.SetParentOrigin(ParentOrigin::CENTER);
524 Stage::GetCurrent().Add( actor );
527 application.SendNotification();
528 application.Render();
530 BitmapLoader loader = BitmapLoader::GetLatestCreated();
531 DALI_TEST_CHECK( loader );
532 loader.WaitForLoading();// waiting until the image to be loaded
533 DALI_TEST_CHECK( loader.IsLoaded() );
535 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
537 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
539 // WITHOUT atlasing, the wrapping is handled by setting gl texture parameters
540 std::stringstream out;
541 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
542 DALI_TEST_CHECK( texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
544 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
545 DALI_TEST_CHECK( texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
547 // test the uniforms which used to handle the wrap mode
548 Renderer renderer = actor.GetRendererAt( 0u );
549 DALI_TEST_CHECK( renderer );
551 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
552 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
553 Vector4 pixelAreaUniform;
554 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
555 DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
557 Property::Index wrapModeIndex = renderer.GetPropertyIndex( "wrapMode" );
558 DALI_TEST_CHECK(wrapModeIndex == Property::INVALID_INDEX);
561 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
566 int UtcDaliImageVisualAnimateMixColor(void)
568 ToolkitTestApplication application;
569 tet_infoline( "Animate mix color" );
571 application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
573 VisualFactory factory = VisualFactory::Get();
574 Property::Map propertyMap;
575 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
576 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
577 propertyMap.Insert("mixColor", Color::BLUE);
578 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
579 Visual::Base visual = factory.CreateVisual( propertyMap );
581 DummyControl actor = DummyControl::New(true);
582 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
583 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
585 actor.SetSize(2000, 2000);
586 actor.SetParentOrigin(ParentOrigin::CENTER);
587 actor.SetColor(Color::BLACK);
588 Stage::GetCurrent().Add(actor);
590 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
592 Renderer renderer = actor.GetRendererAt(0);
593 Property::Index index = DevelHandle::GetPropertyIndex( renderer, DevelVisual::Property::MIX_COLOR );
594 Property::Value blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
595 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION );
597 tet_infoline("Test that the renderer has the mixColor property");
598 DALI_TEST_CHECK( index != Property::INVALID_INDEX );
600 const Vector4 TARGET_MIX_COLOR( 1.0f, 0.0f, 0.0f, 0.5f );
603 map["target"] = "testVisual";
604 map["property"] = "mixColor";
605 map["initialValue"] = Color::MAGENTA;
606 map["targetValue"] = TARGET_MIX_COLOR;
607 map["animator"] = Property::Map()
608 .Add("alphaFunction", "LINEAR")
609 .Add("timePeriod", Property::Map()
611 .Add("duration", 4.0f));
613 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
615 Animation animation = dummyImpl.CreateTransition( transition );
617 blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
618 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
620 animation.AnimateTo( Property(actor, Actor::Property::COLOR), Color::WHITE );
623 application.SendNotification();
624 application.Render(0); // Ensure animation starts
625 application.Render(2000u); // Halfway point
626 Vector4 testColor(1.0f, 0.0f, 0.5f, 0.75f );
628 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Vector4(0.5f, 0.5f, 0.5f, 1.0f )), true, TEST_LOCATION );
629 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector3>("mixColor", Vector3(testColor)), true, TEST_LOCATION );
630 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<float>("opacity", testColor.a), true, TEST_LOCATION );
632 application.Render(2000u); // Halfway point between blue and white
634 DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::WHITE, TEST_LOCATION );
635 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Color::WHITE ), true, TEST_LOCATION );
636 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector3>("mixColor", Vector3(TARGET_MIX_COLOR)), true, TEST_LOCATION );
637 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<float>("opacity", TARGET_MIX_COLOR.a), true, TEST_LOCATION );
639 TestMixColor( visual, DevelVisual::Property::MIX_COLOR, TARGET_MIX_COLOR );
641 blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
642 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
647 int UtcDaliImageVisualAnimateOpacity(void)
649 ToolkitTestApplication application;
650 tet_infoline( "Animate image visual opacity" );
652 application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
654 VisualFactory factory = VisualFactory::Get();
655 Property::Map propertyMap;
656 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
657 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
658 propertyMap.Insert("opacity", 0.5f);
659 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
660 Visual::Base visual = factory.CreateVisual( propertyMap );
662 DummyControl actor = DummyControl::New(true);
663 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
664 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
666 actor.SetSize(2000, 2000);
667 actor.SetParentOrigin(ParentOrigin::CENTER);
668 actor.SetColor(Color::BLACK);
669 Stage::GetCurrent().Add(actor);
671 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
673 Renderer renderer = actor.GetRendererAt(0);
674 tet_infoline("Test that the renderer has the opacity property");
675 Property::Index index = DevelHandle::GetPropertyIndex( renderer, DevelVisual::Property::OPACITY );
676 DALI_TEST_CHECK( index != Property::INVALID_INDEX );
679 Property::Value blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
680 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
683 tet_infoline( "Test that the opacity can be increased to full via animation, and that the blend mode is set appropriately at the start and end of the animation." );
686 map["target"] = "testVisual";
687 map["property"] = "opacity";
688 map["targetValue"] = 1.0f;
689 map["animator"] = Property::Map()
690 .Add("alphaFunction", "LINEAR")
691 .Add("timePeriod", Property::Map()
693 .Add("duration", 4.0f));
695 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
696 Animation animation = dummyImpl.CreateTransition( transition );
699 application.SendNotification();
700 application.Render(0); // Ensure animation starts
701 application.Render(2000u); // Halfway point through animation
702 application.SendNotification(); // Handle any signals
704 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<float>("opacity", 0.75f), true, TEST_LOCATION );
706 application.Render(2001u); // end
707 application.SendNotification(); // ensure animation finished signal is sent
709 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<float>("opacity", 1.0f), true, TEST_LOCATION );
711 blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
712 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION );
717 tet_infoline( "Test that the opacity can be reduced via animation, and that the blend mode is set appropriately at the start and end of the animation." );
720 map["target"] = "testVisual";
721 map["property"] = DevelVisual::Property::OPACITY;
722 map["targetValue"] = 0.1f;
723 map["animator"] = Property::Map()
724 .Add("alphaFunction", "LINEAR")
725 .Add("timePeriod", Property::Map()
727 .Add("duration", 4.0f));
729 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
730 Animation animation = dummyImpl.CreateTransition( transition );
733 blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
734 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
736 application.SendNotification();
737 application.Render(0); // Ensure animation starts
738 application.Render(2000u); // Halfway point
739 application.SendNotification();
741 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<float>("opacity", 0.55f), true, TEST_LOCATION );
743 application.Render(2016u); // end
744 application.SendNotification();
746 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<float>("opacity", 0.1f), true, TEST_LOCATION );
748 blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
749 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
756 int UtcDaliImageVisualAnimatePixelArea(void)
758 ToolkitTestApplication application;
759 tet_infoline( "ImageVisual animate pixel area" );
761 application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
763 VisualFactory factory = VisualFactory::Get();
764 Property::Map propertyMap;
765 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
766 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
767 propertyMap.Insert("mixColor", Color::BLUE);
768 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
769 Visual::Base visual = factory.CreateVisual( propertyMap );
771 DummyControl actor = DummyControl::New(true);
772 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
773 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
775 actor.SetSize(2000, 2000);
776 actor.SetParentOrigin(ParentOrigin::CENTER);
777 actor.SetColor(Color::BLACK);
778 Stage::GetCurrent().Add(actor);
780 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
782 Renderer renderer = actor.GetRendererAt(0);
783 Property::Index index = DevelHandle::GetPropertyIndex( renderer, DevelVisual::Property::MIX_COLOR );
785 tet_infoline("Test that the renderer has the mixColor property");
786 DALI_TEST_CHECK( index != Property::INVALID_INDEX );
788 // TransitionData only takes string keys
790 map["target"] = "testVisual";
791 map["property"] = "pixelArea";
792 map["initialValue"] = Vector4( 0,0,0,1 );
793 map["targetValue"] = Vector4( 0,0,1,1 ); // Animate width from zero to full
794 map["animator"] = Property::Map()
795 .Add("alphaFunction", "LINEAR")
796 .Add("timePeriod", Property::Map()
798 .Add("duration", 4.0f));
800 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
802 Animation animation = dummyImpl.CreateTransition( transition );
803 animation.AnimateTo( Property(actor, Actor::Property::COLOR), Color::WHITE );
806 application.SendNotification();
807 application.Render(0); // Ensure animation starts
808 application.Render(2000u); // Halfway point
810 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4(0.0f, 0.0f, 0.5f, 1.0f )), true, TEST_LOCATION );
812 application.Render(2000u); // End of animation
814 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4( 0.0f, 0.0f, 1.0f, 1.0f )), true, TEST_LOCATION );
819 int UtcDaliImageVisualTextureCancelRemoteLoad(void)
821 ToolkitTestApplication application;
822 tet_infoline( "Request remote image visual, then destroy visual to cancel load" );
824 Property::Map propertyMap;
825 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
826 propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME );
828 TestGlAbstraction& gl = application.GetGlAbstraction();
829 TraceCallStack& textureTrace = gl.GetTextureTrace();
830 textureTrace.Enable(true);
831 TraceCallStack& drawTrace = gl.GetDrawTrace();
832 drawTrace.Enable(true);
834 Actor actor = CreateActorWithImageVisual( propertyMap );
835 Stage::GetCurrent().Add( actor );
836 application.SendNotification();
838 Stage::GetCurrent().Remove( actor );
839 application.SendNotification();
841 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
842 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
843 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), false, TEST_LOCATION );
844 DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), false, TEST_LOCATION );
849 int UtcDaliImageVisualSetInvalidAsyncImage(void)
851 ToolkitTestApplication application;
852 tet_infoline( "Request image visual with invalid images - should draw broken.png" );
854 VisualFactory factory = VisualFactory::Get();
855 DALI_TEST_CHECK( factory );
857 Property::Map propertyMap;
858 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
859 propertyMap.Insert( ImageVisual::Property::URL, TEST_INVALID_FILE_NAME );
861 Visual::Base visual = factory.CreateVisual( propertyMap );
862 DALI_TEST_CHECK( visual );
864 TestGlAbstraction& gl = application.GetGlAbstraction();
865 TraceCallStack& textureTrace = gl.GetTextureTrace();
866 textureTrace.Enable(true);
868 DummyControl actor = DummyControl::New();
869 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
870 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
872 actor.SetSize( 200.f, 200.f );
873 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
875 Stage::GetCurrent().Add( actor );
877 application.SendNotification();
878 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
880 application.SendNotification();
881 application.Render();
883 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
884 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
886 Stage::GetCurrent().Remove( actor );
887 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
892 int UtcDaliImageVisualSetInvalidSyncImage(void)
894 ToolkitTestApplication application;
895 tet_infoline( "Request image visual with invalid images - should draw broken.png" );
897 VisualFactory factory = VisualFactory::Get();
898 DALI_TEST_CHECK( factory );
900 Property::Map propertyMap;
901 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
902 propertyMap.Insert( ImageVisual::Property::URL, TEST_INVALID_FILE_NAME );
903 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
905 Visual::Base visual = factory.CreateVisual( propertyMap );
906 DALI_TEST_CHECK( visual );
908 TestGlAbstraction& gl = application.GetGlAbstraction();
909 TraceCallStack& textureTrace = gl.GetTextureTrace();
910 textureTrace.Enable(true);
912 DummyControl actor = DummyControl::New();
913 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
914 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
916 actor.SetSize( 200.f, 200.f );
917 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
919 Stage::GetCurrent().Add( actor );
921 application.SendNotification();
922 application.Render();
924 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
925 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
927 Stage::GetCurrent().Remove( actor );
928 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
933 int UtcDaliImageVisualSetInvalidRemoteImage(void)
935 ToolkitTestApplication application;
936 tet_infoline( "Request image visual with invalid images - should draw broken.png" );
938 VisualFactory factory = VisualFactory::Get();
939 DALI_TEST_CHECK( factory );
941 // Local invalid file, asynchronous loading
942 Property::Map propertyMap;
943 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
944 propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_INVALID_FILE_NAME );
946 Visual::Base visual = factory.CreateVisual( propertyMap );
947 DALI_TEST_CHECK( visual );
949 TestGlAbstraction& gl = application.GetGlAbstraction();
950 TraceCallStack& textureTrace = gl.GetTextureTrace();
951 textureTrace.Enable(true);
953 DummyControl actor = DummyControl::New();
954 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
955 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
957 actor.SetSize( 200.f, 200.f );
958 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
960 Stage::GetCurrent().Add( actor );
962 application.SendNotification();
963 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
965 application.SendNotification();
966 application.Render();
968 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
969 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
971 Stage::GetCurrent().Remove( actor );
972 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );