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-event-thread-callback.h>
22 #include <dali/devel-api/object/handle-devel.h>
23 #include <dali-toolkit/devel-api/visual-factory/transition-data.h>
24 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
25 #include <dali-toolkit/devel-api/controls/control-devel.h>
26 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
27 #include <dali-toolkit/dali-toolkit.h>
28 #include "dummy-control.h"
31 using namespace Dali::Toolkit;
33 void dali_image_visual_startup(void)
35 test_return_value = TET_UNDEF;
38 void dali_image_visual_cleanup(void)
40 test_return_value = TET_PASS;
45 const char* TEST_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
46 const char* TEST_LARGE_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/tbcol.png";
47 const char* TEST_SMALL_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/icon-edit.png";
48 const char* TEST_REMOTE_IMAGE_FILE_NAME = "https://www.tizen.org/sites/all/themes/tizen_theme/logo.png";
49 const char* TEST_INVALID_FILE_NAME = TEST_RESOURCE_DIR "/invalid.jpg";
50 const char* TEST_REMOTE_INVALID_FILE_NAME = "https://www.tizen.org/invalid.png";
51 const char* TEST_MASK_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/mask.png";
52 const char* TEST_ROTATED_IMAGE = TEST_RESOURCE_DIR "/keyboard-Landscape.jpg";
55 bool gResourceReadySignalFired = false;
57 void ResourceReadySignal( Control control )
59 gResourceReadySignalFired = true;
63 Actor CreateActorWithImageVisual(const Property::Map& map)
65 VisualFactory factory = VisualFactory::Get();
66 DummyControl actor = DummyControl::New();
67 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
68 Visual::Base visual = factory.CreateVisual( map );
69 DALI_TEST_CHECK( visual );
70 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
71 actor.SetSize( 200.f, 200.f );
72 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
77 Visual::Base CreateVisualWithPolicy( const char* url, Property::Index key, const Property::Value& value )
79 VisualFactory factory = VisualFactory::Get();
81 Property::Map propertyMap;
82 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
83 propertyMap.Insert( ImageVisual::Property::URL, url );
84 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, 20 );
85 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, 30 );
86 propertyMap.Insert( key , value );
88 return factory.CreateVisual( propertyMap );
93 void TestVisualRender( ToolkitTestApplication& application,
96 std::size_t expectedSamplers = 0,
97 ImageDimensions imageDimensions = ImageDimensions(),
98 Integration::ResourcePointer resourcePtr = Integration::ResourcePointer())
100 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
101 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
105 // set the image size, for test case, this needs to be set before loading started
106 application.GetPlatform().SetClosestImageSize( Vector2(imageDimensions.GetWidth(), imageDimensions.GetHeight()) );
109 actor.SetSize( 200.f, 200.f );
110 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
112 Stage::GetCurrent().Add( actor );
114 application.SendNotification(); // Send messages to update
115 application.Render(); // process update and render
116 application.SendNotification(); // process any signals to event
120 DALI_TEST_EQUALS( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceSynchronouslyFunc ), true, TEST_LOCATION);
123 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
126 static void TestMixColor( Visual::Base visual, Property::Index mixColorIndex, const Vector4& testColor )
129 visual.CreatePropertyMap(map);
130 Property::Value* value = map.Find( mixColorIndex );
131 DALI_TEST_CHECK( value );
133 DALI_TEST_CHECK( value->Get( mixColor1 ) );
134 DALI_TEST_EQUALS( mixColor1, Vector3(testColor), 0.001, TEST_LOCATION );
136 value = map.Find( Visual::Property::MIX_COLOR );
137 DALI_TEST_CHECK( value );
139 DALI_TEST_CHECK( value->Get( mixColor2 ) );
140 DALI_TEST_EQUALS( mixColor2, testColor, 0.001, TEST_LOCATION );
142 value = map.Find( Visual::Property::OPACITY );
143 DALI_TEST_CHECK( value );
145 DALI_TEST_CHECK( value->Get( opacity ) );
146 DALI_TEST_EQUALS( opacity, testColor.a, 0.001, TEST_LOCATION );
151 int UtcDaliImageVisualPropertyMap(void)
153 ToolkitTestApplication application;
154 tet_infoline( "Request image visual with a Property::Map" );
156 VisualFactory factory = VisualFactory::Get();
157 DALI_TEST_CHECK( factory );
159 Property::Map propertyMap;
160 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
161 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
163 Visual::Base visual = factory.CreateVisual( propertyMap );
164 DALI_TEST_CHECK( visual );
166 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
167 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
169 TestGlAbstraction& gl = application.GetGlAbstraction();
170 TraceCallStack& textureTrace = gl.GetTextureTrace();
171 textureTrace.Enable(true);
173 DummyControl actor = DummyControl::New();
174 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
175 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
177 actor.SetSize( 200.f, 200.f );
178 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
180 Stage::GetCurrent().Add( actor );
181 application.SendNotification();
182 application.Render();
184 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
186 application.SendNotification();
187 application.Render();
189 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
191 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
193 Stage::GetCurrent().Remove( actor );
194 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
200 int UtcDaliImageVisualRemoteImageLoad(void)
202 ToolkitTestApplication application;
203 tet_infoline( "Request remote image visual with a Property::Map" );
205 VisualFactory factory = VisualFactory::Get();
206 DALI_TEST_CHECK( factory );
208 Property::Map propertyMap;
209 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
210 propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME );
212 Visual::Base visual = factory.CreateVisual( propertyMap );
213 DALI_TEST_CHECK( visual );
215 TestGlAbstraction& gl = application.GetGlAbstraction();
216 TraceCallStack& textureTrace = gl.GetTextureTrace();
217 textureTrace.Enable(true);
219 DummyControl actor = DummyControl::New();
220 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
221 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
223 actor.SetSize( 200.f, 200.f );
224 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
226 Stage::GetCurrent().Add( actor );
227 application.SendNotification();
229 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
231 application.SendNotification();
232 application.Render();
234 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
235 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
237 Stage::GetCurrent().Remove( actor );
238 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
243 int UtcDaliImageVisualTextureReuse1(void)
245 ToolkitTestApplication application;
246 tet_infoline( "Request remote image visual with a Property::Map; request a second visual with the same property map - should reuse texture" );
248 Property::Map propertyMap;
249 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
250 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
251 propertyMap.Insert( DevelImageVisual::Property::RELEASE_POLICY, DevelImageVisual::ReleasePolicy::DETACHED );
253 TestGlAbstraction& gl = application.GetGlAbstraction();
254 TraceCallStack& textureTrace = gl.GetTextureTrace();
255 textureTrace.Enable(true);
256 TraceCallStack& drawTrace = gl.GetDrawTrace();
257 drawTrace.Enable(true);
259 Actor actor = CreateActorWithImageVisual( propertyMap );
260 Stage::GetCurrent().Add( actor );
261 application.SendNotification();
263 // Wait for image to load
264 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
266 application.SendNotification();
267 application.Render();
269 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
270 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
271 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
272 DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION );
273 textureTrace.Reset();
276 Actor actor2 = CreateActorWithImageVisual( propertyMap );
277 Stage::GetCurrent().Add(actor2);
279 application.SendNotification(); // Send messages to update
280 application.Render(); // process update and render
281 application.SendNotification(); // process any signals to event
283 DALI_TEST_EQUALS( actor2.GetRendererCount(), 1u, TEST_LOCATION );
285 tet_infoline("Test that 2 draw calls occur with no new texture gens/binds, i.e. both\n"
286 "draw calls use the same texture as the previous draw call\n" );
288 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
289 DALI_TEST_EQUALS( drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION );
290 DALI_TEST_EQUALS( textureTrace.CountMethod("BindTexture"), 0, TEST_LOCATION );
292 tet_infoline("Test that removing 1 actor doesn't delete the texture\n");
294 Stage::GetCurrent().Remove( actor );
295 application.SendNotification();
296 application.Render();
298 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
299 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
301 tet_infoline("Test that removing last actor does delete the texture\n");
303 Stage::GetCurrent().Remove( actor2 ); // Detaches remaining ImageVisual
304 application.SendNotification();
305 application.Render();
307 DALI_TEST_CHECK( actor2.GetRendererCount() == 0u );
308 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
314 int UtcDaliImageVisualTextureReuse2(void)
316 ToolkitTestApplication application;
317 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" );
319 Property::Map propertyMap;
320 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
321 propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME );
323 TestGlAbstraction& gl = application.GetGlAbstraction();
324 TraceCallStack& textureTrace = gl.GetTextureTrace();
325 textureTrace.Enable(true);
326 TraceCallStack& drawTrace = gl.GetDrawTrace();
327 drawTrace.Enable(true);
329 Actor actor = CreateActorWithImageVisual( propertyMap );
330 Stage::GetCurrent().Add( actor );
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( actor.GetRendererCount(), 1u, TEST_LOCATION );
340 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
341 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
342 DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION );
343 textureTrace.Reset();
346 propertyMap.Insert( ImageVisual::Property::SAMPLING_MODE, Dali::SamplingMode::NEAREST );
347 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, 100 );
348 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, 100 );
349 Actor actor2 = CreateActorWithImageVisual( propertyMap );
350 Stage::GetCurrent().Add(actor2);
352 application.SendNotification();
354 // Wait for image to load
355 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
357 application.SendNotification();
358 application.Render();
360 DALI_TEST_EQUALS( actor2.GetRendererCount(), 1u, TEST_LOCATION );
362 tet_infoline("Test that 2 draw calls occur with 1 new texture gen/bind, i.e. both "
363 "renderers are using different textures\n" );
365 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
366 DALI_TEST_EQUALS( drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION );
367 TraceCallStack::NamedParams tex1;
368 tex1["texture"] = "1";
369 TraceCallStack::NamedParams tex2;
370 tex1["texture"] = "2";
371 DALI_TEST_EQUALS( textureTrace.FindMethodAndParams("BindTexture", tex1), true, TEST_LOCATION );
372 DALI_TEST_EQUALS( textureTrace.FindMethodAndParams("BindTexture", tex2), true, TEST_LOCATION );
374 tet_infoline("Test that removing 1 actor deletes it's texture\n");
376 Stage::GetCurrent().Remove( actor );
377 application.SendNotification();
378 application.Render();
380 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
381 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
383 tet_infoline("Test that removing last actor deletes it's texture\n");
385 Stage::GetCurrent().Remove( actor2 );
386 application.SendNotification();
387 application.Render();
389 DALI_TEST_CHECK( actor2.GetRendererCount() == 0u );
390 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 2, TEST_LOCATION );
396 int UtcDaliImageVisualImageHandle(void)
398 ToolkitTestApplication application;
399 tet_infoline( "Request image visual with an image handle" );
401 VisualFactory factory = VisualFactory::Get();
402 DALI_TEST_CHECK( factory );
404 Image image = ResourceImage::New(TEST_IMAGE_FILE_NAME);
405 Visual::Base visual = factory.CreateVisual( image );
407 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
408 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
411 const int height=513;
413 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD );
414 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, width, height,width, height );
416 TestGlAbstraction& gl = application.GetGlAbstraction();
417 TraceCallStack& textureTrace = gl.GetTextureTrace();
418 textureTrace.Enable(true);
420 DummyControl actor = DummyControl::New();
421 TestVisualRender( application, actor, visual, 1u,
422 ImageDimensions(width, height),
423 Integration::ResourcePointer(bitmap) );
425 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
429 int UtcDaliImageVisualCustomWrapModePixelArea(void)
431 ToolkitTestApplication application;
432 tet_infoline( "Request image visual with a Property::Map, test custom wrap mode and pixel area with atlasing" );
434 VisualFactory factory = VisualFactory::Get();
435 DALI_TEST_CHECK( factory );
437 // Test wrap mode with atlasing. Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
440 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
442 Property::Map propertyMap;
443 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
444 propertyMap.Insert( ImageVisual::Property::URL, TEST_SMALL_IMAGE_FILE_NAME );
445 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, width );
446 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, height );
447 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
448 propertyMap.Insert( ImageVisual::Property::PIXEL_AREA, pixelArea );
449 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT );
450 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
451 propertyMap.Insert( ImageVisual::Property::ATLASING, true );
453 Visual::Base visual = factory.CreateVisual( propertyMap );
454 DALI_TEST_CHECK( visual );
456 TestGlAbstraction& gl = application.GetGlAbstraction();
457 TraceCallStack& textureTrace = gl.GetTextureTrace();
458 textureTrace.Enable(true);
459 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
460 texParameterTrace.Enable( true );
462 DummyControl actor = DummyControl::New();
463 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
464 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
465 actor.SetSize(2000, 2000);
466 actor.SetParentOrigin(ParentOrigin::CENTER);
467 Stage::GetCurrent().Add( actor );
470 application.SendNotification();
471 application.Render();
473 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
475 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
477 // WITH atlasing, the wrapping is handled manually in shader, so the following gl function should not be called
478 std::stringstream out;
479 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
480 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
482 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
483 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
485 // test the uniforms which used to handle the wrap mode
486 Renderer renderer = actor.GetRendererAt( 0u );
487 DALI_TEST_CHECK( renderer );
489 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
490 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
491 Vector4 pixelAreaUniform;
492 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
493 DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
495 Property::Value wrapModeValue = renderer.GetProperty( renderer.GetPropertyIndex( "wrapMode" ) );
496 Vector2 wrapMode( WrapMode::MIRRORED_REPEAT-1, WrapMode::REPEAT-1 );
497 DALI_TEST_EQUALS( wrapModeValue.Get<Vector2>(), wrapMode, TEST_LOCATION );
498 Vector2 wrapModeUniform;
499 DALI_TEST_CHECK( gl.GetUniformValue<Vector2>( "wrapMode", wrapModeUniform ) );
500 DALI_TEST_EQUALS( wrapMode, wrapModeUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
503 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
508 int UtcDaliImageVisualCustomWrapModeNoAtlas(void)
510 ToolkitTestApplication application;
511 tet_infoline( "Request image visual with a Property::Map, test custom wrap mode and pixel area without atlasing" );
513 VisualFactory factory = VisualFactory::Get();
514 DALI_TEST_CHECK( factory );
516 // Test wrap mode without atlasing. Image with a size bigger than 512*512 will NOT be uploaded as a part of the atlas.
518 const int height=600;
519 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
521 Property::Map propertyMap;
522 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
523 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
524 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, width );
525 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, height );
526 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
527 propertyMap.Insert( ImageVisual::Property::PIXEL_AREA, pixelArea );
528 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT );
529 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
531 Visual::Base visual = factory.CreateVisual( propertyMap );
532 DALI_TEST_CHECK( visual );
534 TestGlAbstraction& gl = application.GetGlAbstraction();
535 TraceCallStack& textureTrace = gl.GetTextureTrace();
536 textureTrace.Enable(true);
537 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
538 texParameterTrace.Enable( true );
540 DummyControl actor = DummyControl::New();
541 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
542 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
543 actor.SetSize(2000, 2000);
544 actor.SetParentOrigin(ParentOrigin::CENTER);
545 Stage::GetCurrent().Add( actor );
548 application.SendNotification();
549 application.Render();
551 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
553 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
555 // WITHOUT atlasing, the wrapping is handled by setting gl texture parameters
556 std::stringstream out;
557 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
558 DALI_TEST_CHECK( texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
560 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
561 DALI_TEST_CHECK( texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
563 // test the uniforms which used to handle the wrap mode
564 Renderer renderer = actor.GetRendererAt( 0u );
565 DALI_TEST_CHECK( renderer );
567 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
568 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
569 Vector4 pixelAreaUniform;
570 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
571 DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
573 Property::Index wrapModeIndex = renderer.GetPropertyIndex( "wrapMode" );
574 DALI_TEST_CHECK(wrapModeIndex == Property::INVALID_INDEX);
577 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
582 int UtcDaliImageVisualAnimateMixColor(void)
584 ToolkitTestApplication application;
585 tet_infoline( "Animate mix color" );
587 application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
589 VisualFactory factory = VisualFactory::Get();
590 Property::Map propertyMap;
591 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
592 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
593 propertyMap.Insert("mixColor", Color::BLUE);
594 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
595 Visual::Base visual = factory.CreateVisual( propertyMap );
597 DummyControl actor = DummyControl::New(true);
598 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
599 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
601 actor.SetSize(2000, 2000);
602 actor.SetParentOrigin(ParentOrigin::CENTER);
603 actor.SetColor(Color::BLACK);
604 Stage::GetCurrent().Add(actor);
606 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
608 Renderer renderer = actor.GetRendererAt(0);
609 Property::Index index = DevelHandle::GetPropertyIndex( renderer, Visual::Property::MIX_COLOR );
610 Property::Value blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
611 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION );
613 tet_infoline("Test that the renderer has the mixColor property");
614 DALI_TEST_CHECK( index != Property::INVALID_INDEX );
616 const Vector4 TARGET_MIX_COLOR( 1.0f, 0.0f, 0.0f, 0.5f );
619 map["target"] = "testVisual";
620 map["property"] = "mixColor";
621 map["initialValue"] = Color::MAGENTA;
622 map["targetValue"] = TARGET_MIX_COLOR;
623 map["animator"] = Property::Map()
624 .Add("alphaFunction", "LINEAR")
625 .Add("timePeriod", Property::Map()
627 .Add("duration", 4.0f));
629 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
631 Animation animation = dummyImpl.CreateTransition( transition );
633 blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
634 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
636 animation.AnimateTo( Property(actor, Actor::Property::COLOR), Color::WHITE );
639 application.SendNotification();
640 application.Render(0); // Ensure animation starts
641 application.Render(2000u); // Halfway point
642 Vector4 testColor(1.0f, 0.0f, 0.5f, 0.75f );
644 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Vector4(0.5f, 0.5f, 0.5f, 1.0f )), true, TEST_LOCATION );
645 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector3>("mixColor", Vector3(testColor)), true, TEST_LOCATION );
646 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<float>("opacity", testColor.a), true, TEST_LOCATION );
648 application.Render(2000u); // Halfway point between blue and white
650 DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::WHITE, TEST_LOCATION );
651 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Color::WHITE ), true, TEST_LOCATION );
652 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector3>("mixColor", Vector3(TARGET_MIX_COLOR)), true, TEST_LOCATION );
653 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<float>("opacity", TARGET_MIX_COLOR.a), true, TEST_LOCATION );
655 TestMixColor( visual, Visual::Property::MIX_COLOR, TARGET_MIX_COLOR );
657 blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
658 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
663 int UtcDaliImageVisualAnimateOpacity(void)
665 ToolkitTestApplication application;
666 tet_infoline( "Animate image visual opacity" );
668 application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
670 VisualFactory factory = VisualFactory::Get();
671 Property::Map propertyMap;
672 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
673 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
674 propertyMap.Insert("opacity", 0.5f);
675 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
676 Visual::Base visual = factory.CreateVisual( propertyMap );
678 DummyControl actor = DummyControl::New(true);
679 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
680 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
682 actor.SetSize(2000, 2000);
683 actor.SetParentOrigin(ParentOrigin::CENTER);
684 actor.SetColor(Color::BLACK);
685 Stage::GetCurrent().Add(actor);
687 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
689 Renderer renderer = actor.GetRendererAt(0);
690 tet_infoline("Test that the renderer has the opacity property");
691 Property::Index index = DevelHandle::GetPropertyIndex( renderer, Visual::Property::OPACITY );
692 DALI_TEST_CHECK( index != Property::INVALID_INDEX );
695 Property::Value blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
696 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
699 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." );
702 map["target"] = "testVisual";
703 map["property"] = "opacity";
704 map["targetValue"] = 1.0f;
705 map["animator"] = Property::Map()
706 .Add("alphaFunction", "LINEAR")
707 .Add("timePeriod", Property::Map()
709 .Add("duration", 4.0f));
711 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
712 Animation animation = dummyImpl.CreateTransition( transition );
715 application.SendNotification();
716 application.Render(0); // Ensure animation starts
717 application.Render(2000u); // Halfway point through animation
718 application.SendNotification(); // Handle any signals
720 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<float>("opacity", 0.75f), true, TEST_LOCATION );
722 application.Render(2001u); // end
723 application.SendNotification(); // ensure animation finished signal is sent
725 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<float>("opacity", 1.0f), true, TEST_LOCATION );
727 blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
728 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION );
733 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." );
736 map["target"] = "testVisual";
737 map["property"] = Visual::Property::OPACITY;
738 map["targetValue"] = 0.1f;
739 map["animator"] = Property::Map()
740 .Add("alphaFunction", "LINEAR")
741 .Add("timePeriod", Property::Map()
743 .Add("duration", 4.0f));
745 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
746 Animation animation = dummyImpl.CreateTransition( transition );
749 blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
750 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
752 application.SendNotification();
753 application.Render(0); // Ensure animation starts
754 application.Render(2000u); // Halfway point
755 application.SendNotification();
757 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<float>("opacity", 0.55f), true, TEST_LOCATION );
759 application.Render(2016u); // end
760 application.SendNotification();
762 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<float>("opacity", 0.1f), true, TEST_LOCATION );
764 blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
765 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
772 int UtcDaliImageVisualAnimatePixelArea(void)
774 ToolkitTestApplication application;
775 tet_infoline( "ImageVisual animate pixel area" );
777 application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
779 VisualFactory factory = VisualFactory::Get();
780 Property::Map propertyMap;
781 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
782 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
783 propertyMap.Insert("mixColor", Color::BLUE);
784 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
785 Visual::Base visual = factory.CreateVisual( propertyMap );
787 DummyControl actor = DummyControl::New(true);
788 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
789 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
791 actor.SetSize(2000, 2000);
792 actor.SetParentOrigin(ParentOrigin::CENTER);
793 actor.SetColor(Color::BLACK);
794 Stage::GetCurrent().Add(actor);
796 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
798 Renderer renderer = actor.GetRendererAt(0);
799 Property::Index index = DevelHandle::GetPropertyIndex( renderer, Visual::Property::MIX_COLOR );
801 tet_infoline("Test that the renderer has the mixColor property");
802 DALI_TEST_CHECK( index != Property::INVALID_INDEX );
804 // TransitionData only takes string keys
806 map["target"] = "testVisual";
807 map["property"] = "pixelArea";
808 map["initialValue"] = Vector4( 0,0,0,1 );
809 map["targetValue"] = Vector4( 0,0,1,1 ); // Animate width from zero to full
810 map["animator"] = Property::Map()
811 .Add("alphaFunction", "LINEAR")
812 .Add("timePeriod", Property::Map()
814 .Add("duration", 4.0f));
816 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
818 Animation animation = dummyImpl.CreateTransition( transition );
819 animation.AnimateTo( Property(actor, Actor::Property::COLOR), Color::WHITE );
822 application.SendNotification();
823 application.Render(0); // Ensure animation starts
824 application.Render(2000u); // Halfway point
826 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4(0.0f, 0.0f, 0.5f, 1.0f )), true, TEST_LOCATION );
828 application.Render(2000u); // End of animation
830 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4( 0.0f, 0.0f, 1.0f, 1.0f )), true, TEST_LOCATION );
835 int UtcDaliImageVisualTextureCancelRemoteLoad(void)
837 ToolkitTestApplication application;
838 tet_infoline( "Request remote image visual, then destroy visual to cancel load" );
840 Property::Map propertyMap;
841 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
842 propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME );
844 TestGlAbstraction& gl = application.GetGlAbstraction();
845 TraceCallStack& textureTrace = gl.GetTextureTrace();
846 textureTrace.Enable(true);
847 TraceCallStack& drawTrace = gl.GetDrawTrace();
848 drawTrace.Enable(true);
850 Actor actor = CreateActorWithImageVisual( propertyMap );
851 Stage::GetCurrent().Add( actor );
852 application.SendNotification();
854 Stage::GetCurrent().Remove( actor );
855 application.SendNotification();
857 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
858 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
859 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), false, TEST_LOCATION );
860 DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), false, TEST_LOCATION );
865 int UtcDaliImageVisualTextureCancelAsyncLoad(void)
867 ToolkitTestApplication application;
868 tet_infoline( "Load image asynchronosly, cancel loading, then load again" );
870 VisualFactory factory = VisualFactory::Get();
871 DALI_TEST_CHECK( factory );
873 Property::Map propertyMap;
874 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
875 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
877 Visual::Base visual = factory.CreateVisual( propertyMap );
878 DALI_TEST_CHECK( visual );
880 TestGlAbstraction& gl = application.GetGlAbstraction();
881 TraceCallStack& textureTrace = gl.GetTextureTrace();
882 textureTrace.Enable( true );
883 TraceCallStack& drawTrace = gl.GetDrawTrace();
884 drawTrace.Enable( true );
886 DummyControl actor = DummyControl::New();
887 DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
888 dummyImpl.RegisterVisual( Control::Property::BACKGROUND, visual );
890 Stage::GetCurrent().Add( actor );
893 Stage::GetCurrent().Remove( actor );
895 Stage::GetCurrent().Add( actor );
897 // Create another visual with the same image
898 visual = factory.CreateVisual( propertyMap );
899 DALI_TEST_CHECK( visual );
901 dummyImpl.RegisterVisual( Control::Property::BACKGROUND, visual );
903 application.SendNotification();
904 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
906 application.SendNotification();
907 application.Render();
909 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
910 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
911 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
912 DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION );
917 int UtcDaliImageVisualSetInvalidAsyncImage(void)
919 ToolkitTestApplication application;
920 tet_infoline( "Request image visual with invalid images - should draw broken.png" );
922 VisualFactory factory = VisualFactory::Get();
923 DALI_TEST_CHECK( factory );
925 Property::Map propertyMap;
926 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
927 propertyMap.Insert( ImageVisual::Property::URL, TEST_INVALID_FILE_NAME );
929 Visual::Base visual = factory.CreateVisual( propertyMap );
930 DALI_TEST_CHECK( visual );
932 TestGlAbstraction& gl = application.GetGlAbstraction();
933 TraceCallStack& textureTrace = gl.GetTextureTrace();
934 textureTrace.Enable(true);
936 DummyControl actor = DummyControl::New();
937 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
938 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
940 actor.SetSize( 200.f, 200.f );
941 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
943 Stage::GetCurrent().Add( actor );
945 application.SendNotification();
946 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
948 application.SendNotification();
949 application.Render();
951 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
952 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
954 Stage::GetCurrent().Remove( actor );
955 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
960 int UtcDaliImageVisualSetInvalidSyncImage(void)
962 ToolkitTestApplication application;
963 tet_infoline( "Request image visual with invalid images - should draw broken.png" );
965 VisualFactory factory = VisualFactory::Get();
966 DALI_TEST_CHECK( factory );
968 Property::Map propertyMap;
969 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
970 propertyMap.Insert( ImageVisual::Property::URL, TEST_INVALID_FILE_NAME );
971 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
973 Visual::Base visual = factory.CreateVisual( propertyMap );
974 DALI_TEST_CHECK( visual );
976 TestGlAbstraction& gl = application.GetGlAbstraction();
977 TraceCallStack& textureTrace = gl.GetTextureTrace();
978 textureTrace.Enable(true);
980 DummyControl actor = DummyControl::New();
981 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
982 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
984 actor.SetSize( 200.f, 200.f );
985 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
987 Stage::GetCurrent().Add( actor );
989 application.SendNotification();
990 application.Render();
992 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
993 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
995 Stage::GetCurrent().Remove( actor );
996 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1001 int UtcDaliImageVisualSetInvalidRemoteImage(void)
1003 ToolkitTestApplication application;
1004 tet_infoline( "Request image visual with invalid images - should draw broken.png" );
1006 VisualFactory factory = VisualFactory::Get();
1007 DALI_TEST_CHECK( factory );
1009 // Local invalid file, asynchronous loading
1010 Property::Map propertyMap;
1011 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1012 propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_INVALID_FILE_NAME );
1014 Visual::Base visual = factory.CreateVisual( propertyMap );
1015 DALI_TEST_CHECK( visual );
1017 TestGlAbstraction& gl = application.GetGlAbstraction();
1018 TraceCallStack& textureTrace = gl.GetTextureTrace();
1019 textureTrace.Enable(true);
1021 DummyControl actor = DummyControl::New();
1022 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1023 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1025 actor.SetSize( 200.f, 200.f );
1026 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1028 Stage::GetCurrent().Add( actor );
1030 application.SendNotification();
1031 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1033 application.SendNotification();
1034 application.Render();
1036 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1037 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1039 Stage::GetCurrent().Remove( actor );
1040 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1045 int UtcDaliImageVisualAlphaMask(void)
1047 ToolkitTestApplication application;
1048 tet_infoline( "Request image visual with a Property::Map containing an Alpha mask" );
1050 VisualFactory factory = VisualFactory::Get();
1051 DALI_TEST_CHECK( factory );
1053 Property::Map propertyMap;
1054 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1055 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
1056 propertyMap.Insert( ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME );
1058 Visual::Base visual = factory.CreateVisual( propertyMap );
1059 DALI_TEST_CHECK( visual );
1061 Property::Map testMap;
1062 visual.CreatePropertyMap(testMap);
1063 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL),Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION );
1065 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1066 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1068 TestGlAbstraction& gl = application.GetGlAbstraction();
1069 TraceCallStack& textureTrace = gl.GetTextureTrace();
1070 textureTrace.Enable(true);
1072 DummyControl actor = DummyControl::New();
1073 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1074 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1076 actor.SetSize( 200.f, 200.f );
1077 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1078 DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
1080 Stage::GetCurrent().Add( actor );
1081 application.SendNotification();
1082 application.Render();
1084 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
1086 application.SendNotification();
1087 application.Render();
1089 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1090 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1091 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
1093 dummyImpl.UnregisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1 );
1094 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1099 int UtcDaliImageVisualRemoteAlphaMask(void)
1101 ToolkitTestApplication application;
1102 tet_infoline( "Request image visual with a Property::Map containing an Alpha mask" );
1104 VisualFactory factory = VisualFactory::Get();
1105 DALI_TEST_CHECK( factory );
1107 const std::string MASK_IMAGE = TEST_REMOTE_IMAGE_FILE_NAME;
1109 Property::Map propertyMap;
1110 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1111 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1112 propertyMap.Insert( "alphaMaskUrl", MASK_IMAGE );
1114 Visual::Base visual = factory.CreateVisual( propertyMap );
1115 DALI_TEST_CHECK( visual );
1117 Property::Map testMap;
1118 visual.CreatePropertyMap(testMap);
1119 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL),Property::Value(MASK_IMAGE), TEST_LOCATION );
1121 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1122 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1124 TestGlAbstraction& gl = application.GetGlAbstraction();
1125 TraceCallStack& textureTrace = gl.GetTextureTrace();
1126 textureTrace.Enable(true);
1128 DummyControl actor = DummyControl::New();
1129 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1130 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1131 DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
1133 actor.SetSize( 200.f, 200.f );
1134 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1136 Stage::GetCurrent().Add( actor );
1137 application.SendNotification();
1138 application.Render();
1140 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
1142 application.SendNotification();
1143 application.Render();
1145 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1146 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1147 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
1153 int UtcDaliImageVisualAlphaMaskCrop(void)
1155 ToolkitTestApplication application;
1156 tet_infoline( "Request image visual with an Alpha mask and scale/cropping" );
1158 VisualFactory factory = VisualFactory::Get();
1159 DALI_TEST_CHECK( factory );
1161 Property::Map propertyMap;
1162 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1163 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
1164 propertyMap.Insert( ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME );
1165 propertyMap.Insert( ImageVisual::Property::MASK_CONTENT_SCALE, 1.6f );
1166 propertyMap.Insert( ImageVisual::Property::CROP_TO_MASK, true );
1168 Visual::Base visual = factory.CreateVisual( propertyMap );
1169 DALI_TEST_CHECK( visual );
1171 Property::Map testMap;
1172 visual.CreatePropertyMap(testMap);
1173 DALI_TEST_EQUALS( *testMap.Find(ImageVisual::Property::ALPHA_MASK_URL),Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION );
1174 DALI_TEST_EQUALS( *testMap.Find(ImageVisual::Property::MASK_CONTENT_SCALE), Property::Value(1.6f), TEST_LOCATION );
1175 DALI_TEST_EQUALS( *testMap.Find(ImageVisual::Property::CROP_TO_MASK),Property::Value(true), TEST_LOCATION );
1177 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1178 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1180 TestGlAbstraction& gl = application.GetGlAbstraction();
1181 TraceCallStack& textureTrace = gl.GetTextureTrace();
1182 textureTrace.Enable(true);
1184 DummyControl actor = DummyControl::New();
1185 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1186 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1188 actor.SetSize( 200.f, 200.f );
1189 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1190 DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
1192 Stage::GetCurrent().Add( actor );
1193 application.SendNotification();
1194 application.Render();
1196 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
1198 application.SendNotification();
1199 application.Render();
1202 visual.GetNaturalSize(size);
1204 DALI_TEST_EQUALS( size, Vector2( 100.0f, 100.0f ), 0.001f, TEST_LOCATION );
1205 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1206 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1207 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
1212 int UtcDaliImageVisualReleasePolicy01(void)
1214 ToolkitTestApplication application;
1215 tet_infoline( "UtcDaliImageVisualReleasePolicy01 Detached Policy, disabling visual with this policy deletes texture" );
1217 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, DevelImageVisual::Property::RELEASE_POLICY, DevelImageVisual::ReleasePolicy::DETACHED );
1218 DALI_TEST_CHECK( imageVisual );
1220 // Set up debug trace
1221 TestGlAbstraction& gl = application.GetGlAbstraction();
1222 TraceCallStack& textureTrace = gl.GetTextureTrace();
1223 textureTrace.Enable(true);
1225 tet_infoline( "Register visual with control and ensure it has the only handle" );
1226 DummyControl actor = DummyControl::New(true);
1227 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1228 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1229 imageVisual.Reset();
1231 actor.SetSize(200.f, 200.f);
1233 application.SendNotification();
1234 application.Render(0);
1235 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1236 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1238 Stage::GetCurrent().Add( actor );
1240 // Wait for image to load
1241 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1243 application.SendNotification();
1244 application.Render(0);
1245 // Test renderer and texture created
1246 tet_infoline( "Confirm texture created" );
1247 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1248 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1250 tet_infoline( "Disable visual causing the texture to be deleted" );
1251 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, false );
1253 application.SendNotification();
1254 application.Render(0);
1255 // Test renderer and textures removed.
1256 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1257 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
1262 int UtcDaliImageVisualReleasePolicy02(void)
1264 ToolkitTestApplication application;
1265 tet_infoline( "UtcDaliImageVisualReleasePolicy02 Destroyed Policy, Texture should be deleted when visual destroyed" );
1267 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, DevelImageVisual::Property::RELEASE_POLICY, DevelImageVisual::ReleasePolicy::DESTROYED );
1268 DALI_TEST_CHECK( imageVisual );
1270 // Setup debug trace
1271 TestGlAbstraction& gl = application.GetGlAbstraction();
1272 TraceCallStack& textureTrace = gl.GetTextureTrace();
1273 textureTrace.Enable(true);
1275 tet_infoline( "Register visual with control and ensure it has the only handle" );
1276 DummyControl actor = DummyControl::New(true);
1277 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1278 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1279 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1281 actor.SetSize(200.f, 200.f);
1283 application.SendNotification();
1284 application.Render(0);
1285 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1286 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1288 Stage::GetCurrent().Add( actor );
1290 // Wait for image to load
1291 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1293 application.SendNotification();
1294 application.Render(0);
1295 // Test renderer and texture created
1296 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1297 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1300 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1301 tet_infoline( "Destroy visual by UnRegistering visual with control, check renderer is destroyed" );
1302 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1303 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1304 application.SendNotification();
1305 application.Render();
1307 // Test texture removed after visual destroyed.
1308 tet_infoline( "Ensure texture is deleted after visual destroyed" );
1309 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
1314 int UtcDaliImageVisualReleasePolicy03(void)
1316 ToolkitTestApplication application;
1317 tet_infoline( "UtcDaliImageVisualReleasePolicy03 Never Policy, texture should not be deleted after visual destroyed" );
1319 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, DevelImageVisual::Property::RELEASE_POLICY, DevelImageVisual::ReleasePolicy::NEVER );
1320 DALI_TEST_CHECK( imageVisual );
1322 TestGlAbstraction& gl = application.GetGlAbstraction();
1323 TraceCallStack& textureTrace = gl.GetTextureTrace();
1324 textureTrace.Enable(true);
1326 tet_infoline( "Register visual with control and ensure it has the only handle" );
1327 DummyControl actor = DummyControl::New(true);
1328 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1329 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1330 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1332 actor.SetSize(200.f, 200.f);
1334 application.SendNotification();
1335 application.Render(0);
1336 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1337 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1339 Stage::GetCurrent().Add( actor );
1341 // Wait for image to load
1342 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1344 application.SendNotification();
1345 application.Render(0);
1346 // Test renderer and texture created
1347 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1348 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1350 tet_infoline( "Destroy visual by UnRegistering visual with control, check renderer is destroyed" );
1351 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1352 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1353 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1354 application.SendNotification();
1355 application.Render();
1357 tet_infoline( "Ensure texture is not deleted as policy is set to NEVER" );
1358 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1363 int UtcDaliImageVisualReleasePolicy04(void)
1365 ToolkitTestApplication application;
1366 tet_infoline( "UtcDaliImageVisualReleasePolicy04 Two visuals with different policies sharing a texture" );
1368 tet_infoline( "Create first visual with Never release policy" );
1369 Visual::Base imageVisualNever = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, DevelImageVisual::Property::RELEASE_POLICY, DevelImageVisual::ReleasePolicy::NEVER );
1371 tet_infoline( "Create second visual with Destroyed release policy");
1372 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, DevelImageVisual::Property::RELEASE_POLICY, DevelImageVisual::ReleasePolicy::DESTROYED );
1374 // Set up trace debug
1375 TestGlAbstraction& gl = application.GetGlAbstraction();
1376 TraceCallStack& textureTrace = gl.GetTextureTrace();
1377 textureTrace.Enable(true);
1379 tet_infoline( "Register visuals with control and ensure it has the only handles" );
1380 DummyControl actor = DummyControl::New(true);
1381 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1382 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisualNever );
1383 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL2, imageVisualDestroyed );
1384 imageVisualNever.Reset(); // reduce ref count so only the control keeps the visual alive.
1385 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
1387 actor.SetSize(200.f, 200.f);
1389 // Test initially zero renderers
1390 application.SendNotification();
1391 application.Render(0);
1392 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1393 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1395 Stage::GetCurrent().Add( actor );
1397 // Wait for image to load
1398 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1400 application.SendNotification();
1401 application.Render(0);
1402 tet_infoline( "Ensure a texture is created, shared amongst both visuals. Each visual has its own renderer" );
1403 DALI_TEST_EQUALS( actor.GetRendererCount(), 2u, TEST_LOCATION );
1404 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1406 // Test renderer removed when visual destroyed
1407 DALI_TEST_CHECK( actor.GetRendererCount() == 2u );
1408 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL2 ); // TEST_VISUAL2 no longer requires the texture as release policy DESTROYED
1409 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1410 application.SendNotification();
1411 application.Render();
1413 // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
1414 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1416 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1417 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1418 application.SendNotification();
1419 application.Render();
1421 tet_infoline( "Ensure a texture is not deleted as second visual used the NEVER release policy" );
1422 // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
1423 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1428 int UtcDaliImageVisualReleasePolicy05(void)
1430 ToolkitTestApplication application;
1431 tet_infoline( "UtcDaliImageVisualReleasePolicy05 Testing settung by string currents correct enum" );
1433 VisualFactory factory = VisualFactory::Get();
1435 Property::Map propertyMapNeverReleasePolicy;
1436 propertyMapNeverReleasePolicy.Insert( Visual::Property::TYPE, Visual::IMAGE );
1437 propertyMapNeverReleasePolicy.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1438 propertyMapNeverReleasePolicy.Insert( ImageVisual::Property::DESIRED_WIDTH, 20 );
1439 propertyMapNeverReleasePolicy.Insert( ImageVisual::Property::DESIRED_HEIGHT, 30 );
1440 propertyMapNeverReleasePolicy.Insert( "releasePolicy" , "never" );
1442 Visual::Base imageVisualNever = factory.CreateVisual( propertyMapNeverReleasePolicy );
1444 Property::Map resultMap;
1445 imageVisualNever.CreatePropertyMap( resultMap );
1446 DALI_TEST_CHECK( ! resultMap.Empty() );
1448 DALI_TEST_EQUALS( ( resultMap.Find( DevelImageVisual::Property::RELEASE_POLICY ) )->Get<int>(), (int)DevelImageVisual::ReleasePolicy::NEVER, TEST_LOCATION );
1453 int UtcDaliImageVisualReleasePolicy06(void)
1455 ToolkitTestApplication application;
1456 tet_infoline( "UtcDaliImageVisualReleasePolicy06 Never Policy, texture should not be affected by Disabling and Enabling visual" );
1458 Visual::Base imageVisual= CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, DevelImageVisual::Property::RELEASE_POLICY, DevelImageVisual::ReleasePolicy::NEVER );
1459 DALI_TEST_CHECK( imageVisual );
1461 TestGlAbstraction& gl = application.GetGlAbstraction();
1462 TraceCallStack& textureTrace = gl.GetTextureTrace();
1463 textureTrace.Enable(true);
1465 tet_infoline( "Register visual with control and ensure it has the only handle" );
1466 DummyControl actor = DummyControl::New(true);
1467 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1468 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1469 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1471 actor.SetSize(200.f, 200.f);
1473 application.SendNotification();
1474 application.Render(0);
1475 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1476 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1478 Stage::GetCurrent().Add( actor );
1480 // Wait for image to load
1481 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1483 application.SendNotification();
1484 application.Render(0);
1485 // Test renderer and texture created
1486 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1487 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1488 textureTrace.Reset();
1490 tet_infoline( "Disable Visual and check texture not affected" );
1491 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, false );
1492 application.SendNotification();
1493 application.Render(0);
1494 tet_infoline( "Check renderer is destroyed when visual off stage" );
1495 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1496 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1497 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1498 textureTrace.Reset();
1500 tet_infoline( "Re-enable Visual and check texture not affected" );
1501 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, true );
1502 application.SendNotification();
1503 application.Render(0);
1504 tet_infoline( "Check texture not affected and renderer is destroyed when visual off stage" );
1505 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1506 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1507 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1512 int UtcDaliImageVisualReleasePolicy07(void)
1514 ToolkitTestApplication application;
1515 tet_infoline( "UtcDaliImageVisualReleasePolicy07 Two visuals with different policies sharing a texture DETACHED and DESTROYED" );
1517 tet_infoline( "Create first visual with DESTROYED release policy" );
1518 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, DevelImageVisual::Property::RELEASE_POLICY, DevelImageVisual::ReleasePolicy::DESTROYED );
1521 tet_infoline( "Create second visual with DETACHED release policy");
1522 Visual::Base imageVisualDetached = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, DevelImageVisual::Property::RELEASE_POLICY, DevelImageVisual::ReleasePolicy::DETACHED );
1524 // Set up trace debug
1525 TestGlAbstraction& gl = application.GetGlAbstraction();
1526 TraceCallStack& textureTrace = gl.GetTextureTrace();
1527 textureTrace.Enable(true);
1529 tet_infoline( "Register visuals with control and ensure it has the only handles" );
1530 DummyControl actor = DummyControl::New(true);
1531 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1532 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisualDestroyed );
1533 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL2, imageVisualDetached );
1534 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
1535 imageVisualDetached.Reset(); // reduce ref count so only the control keeps the visual alive.
1537 actor.SetSize(200.f, 200.f);
1539 // Test initially zero renderers
1540 application.SendNotification();
1541 application.Render(0);
1542 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1543 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1545 Stage::GetCurrent().Add( actor );
1547 // Wait for image to load
1548 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1550 application.SendNotification();
1551 application.Render(0);
1552 tet_infoline( "Ensure a texture is created, shared amongst both visuals. Each visual has its own renderer" );
1553 DALI_TEST_EQUALS( actor.GetRendererCount(), 2u, TEST_LOCATION );
1554 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1556 // Test renderer removed when visual destroyed
1557 DALI_TEST_CHECK( actor.GetRendererCount() == 2u );
1558 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL2, false ); // TEST_VISUAL2 no longer requires the texture as release policy DETACHED
1559 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1560 application.SendNotification();
1561 application.Render();
1563 // Test texture was not deleted as TEST_VISUAL release policy is DESTROYED and is still required.
1564 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1566 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, false );
1567 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1568 application.SendNotification();
1569 application.Render();
1571 tet_infoline( "Ensure a texture is not deleted as second visual used the DESTROYED release policy" );
1572 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1577 int UtcDaliImageVisualLoadPolicy01(void)
1579 ToolkitTestApplication application;
1580 tet_infoline( "UtcDaliImageVisualLoadPolicy01 Load a visual image before attaching to stage" );
1582 // Set up trace debug
1583 TestGlAbstraction& gl = application.GetGlAbstraction();
1584 TraceCallStack& textureTrace = gl.GetTextureTrace();
1585 textureTrace.Enable(true);
1587 tet_infoline( "Create visual with IMMEDIATE load policy" );
1588 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, DevelImageVisual::Property::LOAD_POLICY, DevelImageVisual::LoadPolicy::IMMEDIATE );
1590 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1592 // Ensure texture has been uploaded
1593 application.SendNotification();
1594 application.Render();
1596 tet_infoline( "Ensure texture loading starts after visual created" );
1597 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1598 textureTrace.Reset();
1600 tet_infoline( "Register visuals with control and ensure it has the only handles" );
1601 DummyControl actor = DummyControl::New(true);
1602 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1603 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1604 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1606 actor.SetSize(200.f, 200.f);
1607 Stage::GetCurrent().Add( actor );
1608 tet_infoline( "Ensure nothing triggers another load as texure already loaded" );
1609 const unsigned int TIME_OUT_3_SECONDS = 3;
1610 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, TIME_OUT_3_SECONDS ), false, TEST_LOCATION );
1612 application.SendNotification();
1613 application.Render();
1615 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1616 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1618 // Ensure texture is deleted when no longer needed (ref count was correct )
1619 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1621 application.SendNotification();
1622 application.Render();
1624 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1625 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
1630 int UtcDaliImageVisualLoadPolicy02(void)
1632 ToolkitTestApplication application;
1633 tet_infoline( "UtcDaliImageVisualLoadPolicy01 Load a visual image only after attached to stage" );
1635 // Set up trace debug
1636 TestGlAbstraction& gl = application.GetGlAbstraction();
1637 TraceCallStack& textureTrace = gl.GetTextureTrace();
1638 textureTrace.Enable(true);
1640 tet_infoline( "Create visual with IMMEDIATE load policy" );
1641 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, DevelImageVisual::Property::LOAD_POLICY, DevelImageVisual::LoadPolicy::ATTACHED );
1643 const unsigned int TIME_OUT_3_SECONDS = 3;
1644 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, TIME_OUT_3_SECONDS ), false, TEST_LOCATION );
1646 // Act on meeage queue even although nothing expected to load
1647 application.SendNotification();
1648 application.Render();
1650 tet_infoline( "Ensure texture is not generated yet" );
1651 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1652 textureTrace.Reset();
1654 tet_infoline( "Register visuals with control and ensure it has the only handles" );
1655 DummyControl actor = DummyControl::New(true);
1656 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1657 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1658 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1660 actor.SetSize(200.f, 200.f);
1661 Stage::GetCurrent().Add( actor );
1662 tet_infoline( "Allow image time to load" );
1663 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1665 application.SendNotification();
1666 application.Render();
1668 tet_infoline( "Ensure texture generated and renderer created" );
1669 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1670 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1672 // Ensure texture is delete when no longer needed
1673 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1675 application.SendNotification();
1676 application.Render();
1678 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1679 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
1684 int UtcDaliImageVisualLoadPolicy03(void)
1686 ToolkitTestApplication application;
1687 tet_infoline( "UtcDaliImageVisualLoadPolicy03 Load a visual image before attaching to stage and receive ResourceReady signal" );
1689 // Set up trace debug
1690 TestGlAbstraction& gl = application.GetGlAbstraction();
1691 TraceCallStack& textureTrace = gl.GetTextureTrace();
1692 textureTrace.Enable(true);
1694 tet_infoline( "Create visual with IMMEDIATE load policy" );
1695 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, DevelImageVisual::Property::LOAD_POLICY, DevelImageVisual::LoadPolicy::IMMEDIATE );
1697 // Wait for image to load, ResourceReady signal will not be emitted until Visual is registered with a control and on stage.
1698 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1700 // Ensure texture has been uploaded
1701 application.SendNotification();
1702 application.Render();
1704 tet_infoline( "Ensure texture loading starts after visual created" );
1705 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1706 textureTrace.Reset();
1708 tet_infoline( "Register visuals with control and ensure it has the only handles" );
1709 DummyControl actor = DummyControl::New(true);
1710 actor.ResourceReadySignal().Connect( &ResourceReadySignal);
1711 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1713 tet_infoline( "Registering visual attaches it to stage and trigger the loading signal if Image loaded" );
1714 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1715 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1716 actor.SetSize(200.f, 200.f);
1717 // Adding the Control hence Visual to stage will cause the Visual to trigger ResourceReadySignal if the image is already loaded.
1718 Stage::GetCurrent().Add( actor ); // If LoadPolicy was not IMMEDIATE then as this point (after attached to stage) the test would need to wait for Loading
1720 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1725 int UtcDaliImageVisualOrientationCorrection(void)
1727 ToolkitTestApplication application;
1728 tet_infoline( "UtcDaliImageVisualOrientationCorrection Enabling OrientationCorrection should rotate an image with exif (90deg) orientation data with requested" );
1730 VisualFactory factory = VisualFactory::Get();
1731 tet_infoline( "Create visual with Orientation correction set OFF" );
1732 Property::Map propertyMap;
1733 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
1734 propertyMap.Insert( ImageVisual::Property::URL, TEST_ROTATED_IMAGE );
1735 propertyMap.Insert( DevelImageVisual::Property::ORIENTATION_CORRECTION, false );
1736 Visual::Base imageVisual = factory.CreateVisual( propertyMap );
1738 tet_infoline( "Create control for visual, need to loaded it" );
1739 DummyControl actor = DummyControl::New(true);
1740 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1741 Stage::GetCurrent().Add( actor );
1743 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1744 // Wait for image to load
1745 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1747 Vector2 originalImageSize;
1748 tet_infoline( "Get size of original visual to compare later with rotated image" );
1749 imageVisual.GetNaturalSize( originalImageSize );
1750 DALI_TEST_GREATER( originalImageSize.width, originalImageSize.height, TEST_LOCATION ); // Width and Height must be different for this test.
1751 imageVisual.Reset(); // remove handle so can unregister it and remove from cache
1752 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1753 application.SendNotification();
1754 application.Render();
1756 tet_infoline( "Create visual with Orientation correction set ON " );
1757 propertyMap.Clear();
1758 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
1759 propertyMap.Insert( ImageVisual::Property::URL, TEST_ROTATED_IMAGE );
1760 propertyMap.Insert( DevelImageVisual::Property::ORIENTATION_CORRECTION, true );
1761 imageVisual = factory.CreateVisual( propertyMap );
1763 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1764 // Wait for image to load
1765 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1767 Vector2 rotatedImageSize;
1768 imageVisual.GetNaturalSize( rotatedImageSize );
1769 tet_infoline( "Confirm that visual has rotated" );
1770 DALI_TEST_EQUALS( originalImageSize.width, rotatedImageSize.height , TEST_LOCATION );
1771 DALI_TEST_EQUALS( originalImageSize.height, rotatedImageSize.width , TEST_LOCATION );
1773 Property::Map resultMap;
1774 imageVisual.CreatePropertyMap( resultMap );
1776 // check the Property::ORIENTATION_CORRECTION value from the returned map
1777 Property::Value* typeValue = resultMap.Find( DevelImageVisual::Property::ORIENTATION_CORRECTION, Property::BOOLEAN );
1778 DALI_TEST_EQUALS( typeValue->Get<bool>(), true, TEST_LOCATION );