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;
62 Actor CreateActorWithImageVisual(const Property::Map& map)
64 VisualFactory factory = VisualFactory::Get();
65 DummyControl actor = DummyControl::New();
66 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
67 Visual::Base visual = factory.CreateVisual( map );
68 DALI_TEST_CHECK( visual );
69 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
70 actor.SetSize( 200.f, 200.f );
71 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
76 Visual::Base CreateVisualWithPolicy( const char* url, Property::Index key, const Property::Value& value )
78 VisualFactory factory = VisualFactory::Get();
80 Property::Map propertyMap;
81 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
82 propertyMap.Insert( ImageVisual::Property::URL, url );
83 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, 20 );
84 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, 30 );
85 propertyMap.Insert( key , value );
87 return factory.CreateVisual( propertyMap );
92 void TestVisualRender( ToolkitTestApplication& application,
95 std::size_t expectedSamplers = 0,
96 ImageDimensions imageDimensions = ImageDimensions(),
97 Integration::ResourcePointer resourcePtr = Integration::ResourcePointer())
99 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
100 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
104 // set the image size, for test case, this needs to be set before loading started
105 application.GetPlatform().SetClosestImageSize( Vector2(imageDimensions.GetWidth(), imageDimensions.GetHeight()) );
108 actor.SetSize( 200.f, 200.f );
109 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
111 Stage::GetCurrent().Add( actor );
113 application.SendNotification(); // Send messages to update
114 application.Render(); // process update and render
115 application.SendNotification(); // process any signals to event
119 DALI_TEST_EQUALS( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceSynchronouslyFunc ), true, TEST_LOCATION);
122 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
125 static void TestMixColor( Visual::Base visual, Property::Index mixColorIndex, const Vector4& testColor )
128 visual.CreatePropertyMap(map);
129 Property::Value* value = map.Find( mixColorIndex );
130 DALI_TEST_CHECK( value );
132 DALI_TEST_CHECK( value->Get( mixColor1 ) );
133 DALI_TEST_EQUALS( mixColor1, Vector3(testColor), 0.001, TEST_LOCATION );
135 value = map.Find( Visual::Property::MIX_COLOR );
136 DALI_TEST_CHECK( value );
138 DALI_TEST_CHECK( value->Get( mixColor2 ) );
139 DALI_TEST_EQUALS( mixColor2, testColor, 0.001, TEST_LOCATION );
141 value = map.Find( Visual::Property::OPACITY );
142 DALI_TEST_CHECK( value );
144 DALI_TEST_CHECK( value->Get( opacity ) );
145 DALI_TEST_EQUALS( opacity, testColor.a, 0.001, TEST_LOCATION );
150 int UtcDaliImageVisualPropertyMap(void)
152 ToolkitTestApplication application;
153 tet_infoline( "Request image visual with a Property::Map" );
155 VisualFactory factory = VisualFactory::Get();
156 DALI_TEST_CHECK( factory );
158 Property::Map propertyMap;
159 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
160 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
162 Visual::Base visual = factory.CreateVisual( propertyMap );
163 DALI_TEST_CHECK( visual );
165 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
166 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
168 TestGlAbstraction& gl = application.GetGlAbstraction();
169 TraceCallStack& textureTrace = gl.GetTextureTrace();
170 textureTrace.Enable(true);
172 DummyControl actor = DummyControl::New();
173 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
174 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
176 actor.SetSize( 200.f, 200.f );
177 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
179 Stage::GetCurrent().Add( actor );
180 application.SendNotification();
181 application.Render();
183 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
185 application.SendNotification();
186 application.Render();
188 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
190 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
192 Stage::GetCurrent().Remove( actor );
193 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
199 int UtcDaliImageVisualRemoteImageLoad(void)
201 ToolkitTestApplication application;
202 tet_infoline( "Request remote image visual with a Property::Map" );
204 VisualFactory factory = VisualFactory::Get();
205 DALI_TEST_CHECK( factory );
207 Property::Map propertyMap;
208 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
209 propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME );
211 Visual::Base visual = factory.CreateVisual( propertyMap );
212 DALI_TEST_CHECK( visual );
214 TestGlAbstraction& gl = application.GetGlAbstraction();
215 TraceCallStack& textureTrace = gl.GetTextureTrace();
216 textureTrace.Enable(true);
218 DummyControl actor = DummyControl::New();
219 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
220 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
222 actor.SetSize( 200.f, 200.f );
223 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
225 Stage::GetCurrent().Add( actor );
226 application.SendNotification();
228 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
230 application.SendNotification();
231 application.Render();
233 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
234 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
236 Stage::GetCurrent().Remove( actor );
237 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
242 int UtcDaliImageVisualTextureReuse1(void)
244 ToolkitTestApplication application;
245 tet_infoline( "Request remote image visual with a Property::Map; request a second visual with the same property map - should reuse texture" );
247 Property::Map propertyMap;
248 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
249 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
250 propertyMap.Insert( DevelImageVisual::Property::RELEASE_POLICY, DevelImageVisual::ReleasePolicy::DETACHED );
252 TestGlAbstraction& gl = application.GetGlAbstraction();
253 TraceCallStack& textureTrace = gl.GetTextureTrace();
254 textureTrace.Enable(true);
255 TraceCallStack& drawTrace = gl.GetDrawTrace();
256 drawTrace.Enable(true);
258 Actor actor = CreateActorWithImageVisual( propertyMap );
259 Stage::GetCurrent().Add( actor );
260 application.SendNotification();
262 // Wait for image to load
263 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
265 application.SendNotification();
266 application.Render();
268 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
269 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
270 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
271 DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION );
272 textureTrace.Reset();
275 Actor actor2 = CreateActorWithImageVisual( propertyMap );
276 Stage::GetCurrent().Add(actor2);
278 application.SendNotification(); // Send messages to update
279 application.Render(); // process update and render
280 application.SendNotification(); // process any signals to event
282 DALI_TEST_EQUALS( actor2.GetRendererCount(), 1u, TEST_LOCATION );
284 tet_infoline("Test that 2 draw calls occur with no new texture gens/binds, i.e. both\n"
285 "draw calls use the same texture as the previous draw call\n" );
287 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
288 DALI_TEST_EQUALS( drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION );
289 DALI_TEST_EQUALS( textureTrace.CountMethod("BindTexture"), 0, TEST_LOCATION );
291 tet_infoline("Test that removing 1 actor doesn't delete the texture\n");
293 Stage::GetCurrent().Remove( actor );
294 application.SendNotification();
295 application.Render();
297 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
298 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
300 tet_infoline("Test that removing last actor does delete the texture\n");
302 Stage::GetCurrent().Remove( actor2 ); // Detaches remaining ImageVisual
303 application.SendNotification();
304 application.Render();
306 DALI_TEST_CHECK( actor2.GetRendererCount() == 0u );
307 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
313 int UtcDaliImageVisualTextureReuse2(void)
315 ToolkitTestApplication application;
316 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" );
318 Property::Map propertyMap;
319 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
320 propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME );
322 TestGlAbstraction& gl = application.GetGlAbstraction();
323 TraceCallStack& textureTrace = gl.GetTextureTrace();
324 textureTrace.Enable(true);
325 TraceCallStack& drawTrace = gl.GetDrawTrace();
326 drawTrace.Enable(true);
328 Actor actor = CreateActorWithImageVisual( propertyMap );
329 Stage::GetCurrent().Add( actor );
330 application.SendNotification();
332 // Wait for image to load
333 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
335 application.SendNotification();
336 application.Render();
338 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
339 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
340 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
341 DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION );
342 textureTrace.Reset();
345 propertyMap.Insert( ImageVisual::Property::SAMPLING_MODE, Dali::SamplingMode::NEAREST );
346 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, 100 );
347 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, 100 );
348 Actor actor2 = CreateActorWithImageVisual( propertyMap );
349 Stage::GetCurrent().Add(actor2);
351 application.SendNotification();
353 // Wait for image to load
354 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
356 application.SendNotification();
357 application.Render();
359 DALI_TEST_EQUALS( actor2.GetRendererCount(), 1u, TEST_LOCATION );
361 tet_infoline("Test that 2 draw calls occur with 1 new texture gen/bind, i.e. both "
362 "renderers are using different textures\n" );
364 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
365 DALI_TEST_EQUALS( drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION );
366 TraceCallStack::NamedParams tex1;
367 tex1["texture"] = "1";
368 TraceCallStack::NamedParams tex2;
369 tex1["texture"] = "2";
370 DALI_TEST_EQUALS( textureTrace.FindMethodAndParams("BindTexture", tex1), true, TEST_LOCATION );
371 DALI_TEST_EQUALS( textureTrace.FindMethodAndParams("BindTexture", tex2), true, TEST_LOCATION );
373 tet_infoline("Test that removing 1 actor deletes it's texture\n");
375 Stage::GetCurrent().Remove( actor );
376 application.SendNotification();
377 application.Render();
379 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
380 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
382 tet_infoline("Test that removing last actor deletes it's texture\n");
384 Stage::GetCurrent().Remove( actor2 );
385 application.SendNotification();
386 application.Render();
388 DALI_TEST_CHECK( actor2.GetRendererCount() == 0u );
389 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 2, TEST_LOCATION );
395 int UtcDaliImageVisualImageHandle(void)
397 ToolkitTestApplication application;
398 tet_infoline( "Request image visual with an image handle" );
400 VisualFactory factory = VisualFactory::Get();
401 DALI_TEST_CHECK( factory );
403 Image image = ResourceImage::New(TEST_IMAGE_FILE_NAME);
404 Visual::Base visual = factory.CreateVisual( image );
406 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
407 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
410 const int height=513;
412 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD );
413 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, width, height,width, height );
415 TestGlAbstraction& gl = application.GetGlAbstraction();
416 TraceCallStack& textureTrace = gl.GetTextureTrace();
417 textureTrace.Enable(true);
419 DummyControl actor = DummyControl::New();
420 TestVisualRender( application, actor, visual, 1u,
421 ImageDimensions(width, height),
422 Integration::ResourcePointer(bitmap) );
424 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
428 int UtcDaliImageVisualCustomWrapModePixelArea(void)
430 ToolkitTestApplication application;
431 tet_infoline( "Request image visual with a Property::Map, test custom wrap mode and pixel area with atlasing" );
433 VisualFactory factory = VisualFactory::Get();
434 DALI_TEST_CHECK( factory );
436 // Test wrap mode with atlasing. Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
439 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
441 Property::Map propertyMap;
442 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
443 propertyMap.Insert( ImageVisual::Property::URL, TEST_SMALL_IMAGE_FILE_NAME );
444 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, width );
445 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, height );
446 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
447 propertyMap.Insert( ImageVisual::Property::PIXEL_AREA, pixelArea );
448 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT );
449 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
450 propertyMap.Insert( ImageVisual::Property::ATLASING, true );
452 Visual::Base visual = factory.CreateVisual( propertyMap );
453 DALI_TEST_CHECK( visual );
455 TestGlAbstraction& gl = application.GetGlAbstraction();
456 TraceCallStack& textureTrace = gl.GetTextureTrace();
457 textureTrace.Enable(true);
458 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
459 texParameterTrace.Enable( true );
461 DummyControl actor = DummyControl::New();
462 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
463 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
464 actor.SetSize(2000, 2000);
465 actor.SetParentOrigin(ParentOrigin::CENTER);
466 Stage::GetCurrent().Add( actor );
469 application.SendNotification();
470 application.Render();
472 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
474 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
476 // WITH atlasing, the wrapping is handled manually in shader, so the following gl function should not be called
477 std::stringstream out;
478 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
479 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
481 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
482 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
484 // test the uniforms which used to handle the wrap mode
485 Renderer renderer = actor.GetRendererAt( 0u );
486 DALI_TEST_CHECK( renderer );
488 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
489 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
490 Vector4 pixelAreaUniform;
491 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
492 DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
494 Property::Value wrapModeValue = renderer.GetProperty( renderer.GetPropertyIndex( "wrapMode" ) );
495 Vector2 wrapMode( WrapMode::MIRRORED_REPEAT-1, WrapMode::REPEAT-1 );
496 DALI_TEST_EQUALS( wrapModeValue.Get<Vector2>(), wrapMode, TEST_LOCATION );
497 Vector2 wrapModeUniform;
498 DALI_TEST_CHECK( gl.GetUniformValue<Vector2>( "wrapMode", wrapModeUniform ) );
499 DALI_TEST_EQUALS( wrapMode, wrapModeUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
502 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
507 int UtcDaliImageVisualCustomWrapModeNoAtlas(void)
509 ToolkitTestApplication application;
510 tet_infoline( "Request image visual with a Property::Map, test custom wrap mode and pixel area without atlasing" );
512 VisualFactory factory = VisualFactory::Get();
513 DALI_TEST_CHECK( factory );
515 // Test wrap mode without atlasing. Image with a size bigger than 512*512 will NOT be uploaded as a part of the atlas.
517 const int height=600;
518 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
520 Property::Map propertyMap;
521 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
522 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
523 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, width );
524 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, height );
525 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
526 propertyMap.Insert( ImageVisual::Property::PIXEL_AREA, pixelArea );
527 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT );
528 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
530 Visual::Base visual = factory.CreateVisual( propertyMap );
531 DALI_TEST_CHECK( visual );
533 TestGlAbstraction& gl = application.GetGlAbstraction();
534 TraceCallStack& textureTrace = gl.GetTextureTrace();
535 textureTrace.Enable(true);
536 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
537 texParameterTrace.Enable( true );
539 DummyControl actor = DummyControl::New();
540 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
541 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
542 actor.SetSize(2000, 2000);
543 actor.SetParentOrigin(ParentOrigin::CENTER);
544 Stage::GetCurrent().Add( actor );
547 application.SendNotification();
548 application.Render();
550 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
552 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
554 // WITHOUT atlasing, the wrapping is handled by setting gl texture parameters
555 std::stringstream out;
556 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
557 DALI_TEST_CHECK( texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
559 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
560 DALI_TEST_CHECK( texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
562 // test the uniforms which used to handle the wrap mode
563 Renderer renderer = actor.GetRendererAt( 0u );
564 DALI_TEST_CHECK( renderer );
566 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
567 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
568 Vector4 pixelAreaUniform;
569 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
570 DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
572 Property::Index wrapModeIndex = renderer.GetPropertyIndex( "wrapMode" );
573 DALI_TEST_CHECK(wrapModeIndex == Property::INVALID_INDEX);
576 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
581 int UtcDaliImageVisualAnimateMixColor(void)
583 ToolkitTestApplication application;
584 tet_infoline( "Animate mix color" );
586 application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
588 VisualFactory factory = VisualFactory::Get();
589 Property::Map propertyMap;
590 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
591 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
592 propertyMap.Insert("mixColor", Color::BLUE);
593 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
594 Visual::Base visual = factory.CreateVisual( propertyMap );
596 DummyControl actor = DummyControl::New(true);
597 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
598 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
600 actor.SetSize(2000, 2000);
601 actor.SetParentOrigin(ParentOrigin::CENTER);
602 actor.SetColor(Color::BLACK);
603 Stage::GetCurrent().Add(actor);
605 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
607 Renderer renderer = actor.GetRendererAt(0);
608 Property::Index index = DevelHandle::GetPropertyIndex( renderer, Visual::Property::MIX_COLOR );
609 Property::Value blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
610 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION );
612 tet_infoline("Test that the renderer has the mixColor property");
613 DALI_TEST_CHECK( index != Property::INVALID_INDEX );
615 const Vector4 TARGET_MIX_COLOR( 1.0f, 0.0f, 0.0f, 0.5f );
618 map["target"] = "testVisual";
619 map["property"] = "mixColor";
620 map["initialValue"] = Color::MAGENTA;
621 map["targetValue"] = TARGET_MIX_COLOR;
622 map["animator"] = Property::Map()
623 .Add("alphaFunction", "LINEAR")
624 .Add("timePeriod", Property::Map()
626 .Add("duration", 4.0f));
628 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
630 Animation animation = dummyImpl.CreateTransition( transition );
632 blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
633 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
635 animation.AnimateTo( Property(actor, Actor::Property::COLOR), Color::WHITE );
638 application.SendNotification();
639 application.Render(0); // Ensure animation starts
640 application.Render(2000u); // Halfway point
641 Vector4 testColor(1.0f, 0.0f, 0.5f, 0.75f );
643 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Vector4(0.5f, 0.5f, 0.5f, 1.0f )), true, TEST_LOCATION );
644 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector3>("mixColor", Vector3(testColor)), true, TEST_LOCATION );
645 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<float>("opacity", testColor.a), true, TEST_LOCATION );
647 application.Render(2000u); // Halfway point between blue and white
649 DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::WHITE, TEST_LOCATION );
650 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Color::WHITE ), true, TEST_LOCATION );
651 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector3>("mixColor", Vector3(TARGET_MIX_COLOR)), true, TEST_LOCATION );
652 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<float>("opacity", TARGET_MIX_COLOR.a), true, TEST_LOCATION );
654 TestMixColor( visual, Visual::Property::MIX_COLOR, TARGET_MIX_COLOR );
656 blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
657 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
662 int UtcDaliImageVisualAnimateOpacity(void)
664 ToolkitTestApplication application;
665 tet_infoline( "Animate image visual opacity" );
667 application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
669 VisualFactory factory = VisualFactory::Get();
670 Property::Map propertyMap;
671 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
672 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
673 propertyMap.Insert("opacity", 0.5f);
674 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
675 Visual::Base visual = factory.CreateVisual( propertyMap );
677 DummyControl actor = DummyControl::New(true);
678 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
679 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
681 actor.SetSize(2000, 2000);
682 actor.SetParentOrigin(ParentOrigin::CENTER);
683 actor.SetColor(Color::BLACK);
684 Stage::GetCurrent().Add(actor);
686 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
688 Renderer renderer = actor.GetRendererAt(0);
689 tet_infoline("Test that the renderer has the opacity property");
690 Property::Index index = DevelHandle::GetPropertyIndex( renderer, Visual::Property::OPACITY );
691 DALI_TEST_CHECK( index != Property::INVALID_INDEX );
694 Property::Value blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
695 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
698 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." );
701 map["target"] = "testVisual";
702 map["property"] = "opacity";
703 map["targetValue"] = 1.0f;
704 map["animator"] = Property::Map()
705 .Add("alphaFunction", "LINEAR")
706 .Add("timePeriod", Property::Map()
708 .Add("duration", 4.0f));
710 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
711 Animation animation = dummyImpl.CreateTransition( transition );
714 application.SendNotification();
715 application.Render(0); // Ensure animation starts
716 application.Render(2000u); // Halfway point through animation
717 application.SendNotification(); // Handle any signals
719 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<float>("opacity", 0.75f), true, TEST_LOCATION );
721 application.Render(2001u); // end
722 application.SendNotification(); // ensure animation finished signal is sent
724 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<float>("opacity", 1.0f), true, TEST_LOCATION );
726 blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
727 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION );
732 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." );
735 map["target"] = "testVisual";
736 map["property"] = Visual::Property::OPACITY;
737 map["targetValue"] = 0.1f;
738 map["animator"] = Property::Map()
739 .Add("alphaFunction", "LINEAR")
740 .Add("timePeriod", Property::Map()
742 .Add("duration", 4.0f));
744 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
745 Animation animation = dummyImpl.CreateTransition( transition );
748 blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
749 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
751 application.SendNotification();
752 application.Render(0); // Ensure animation starts
753 application.Render(2000u); // Halfway point
754 application.SendNotification();
756 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<float>("opacity", 0.55f), true, TEST_LOCATION );
758 application.Render(2016u); // end
759 application.SendNotification();
761 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<float>("opacity", 0.1f), true, TEST_LOCATION );
763 blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
764 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
771 int UtcDaliImageVisualAnimatePixelArea(void)
773 ToolkitTestApplication application;
774 tet_infoline( "ImageVisual animate pixel area" );
776 application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
778 VisualFactory factory = VisualFactory::Get();
779 Property::Map propertyMap;
780 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
781 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
782 propertyMap.Insert("mixColor", Color::BLUE);
783 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
784 Visual::Base visual = factory.CreateVisual( propertyMap );
786 DummyControl actor = DummyControl::New(true);
787 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
788 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
790 actor.SetSize(2000, 2000);
791 actor.SetParentOrigin(ParentOrigin::CENTER);
792 actor.SetColor(Color::BLACK);
793 Stage::GetCurrent().Add(actor);
795 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
797 Renderer renderer = actor.GetRendererAt(0);
798 Property::Index index = DevelHandle::GetPropertyIndex( renderer, Visual::Property::MIX_COLOR );
800 tet_infoline("Test that the renderer has the mixColor property");
801 DALI_TEST_CHECK( index != Property::INVALID_INDEX );
803 // TransitionData only takes string keys
805 map["target"] = "testVisual";
806 map["property"] = "pixelArea";
807 map["initialValue"] = Vector4( 0,0,0,1 );
808 map["targetValue"] = Vector4( 0,0,1,1 ); // Animate width from zero to full
809 map["animator"] = Property::Map()
810 .Add("alphaFunction", "LINEAR")
811 .Add("timePeriod", Property::Map()
813 .Add("duration", 4.0f));
815 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
817 Animation animation = dummyImpl.CreateTransition( transition );
818 animation.AnimateTo( Property(actor, Actor::Property::COLOR), Color::WHITE );
821 application.SendNotification();
822 application.Render(0); // Ensure animation starts
823 application.Render(2000u); // Halfway point
825 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4(0.0f, 0.0f, 0.5f, 1.0f )), true, TEST_LOCATION );
827 application.Render(2000u); // End of animation
829 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4( 0.0f, 0.0f, 1.0f, 1.0f )), true, TEST_LOCATION );
834 int UtcDaliImageVisualTextureCancelRemoteLoad(void)
836 ToolkitTestApplication application;
837 tet_infoline( "Request remote image visual, then destroy visual to cancel load" );
839 Property::Map propertyMap;
840 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
841 propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME );
843 TestGlAbstraction& gl = application.GetGlAbstraction();
844 TraceCallStack& textureTrace = gl.GetTextureTrace();
845 textureTrace.Enable(true);
846 TraceCallStack& drawTrace = gl.GetDrawTrace();
847 drawTrace.Enable(true);
849 Actor actor = CreateActorWithImageVisual( propertyMap );
850 Stage::GetCurrent().Add( actor );
851 application.SendNotification();
853 Stage::GetCurrent().Remove( actor );
854 application.SendNotification();
856 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
857 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
858 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), false, TEST_LOCATION );
859 DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), false, TEST_LOCATION );
864 int UtcDaliImageVisualTextureCancelAsyncLoad(void)
866 ToolkitTestApplication application;
867 tet_infoline( "Load image asynchronosly, cancel loading, then load again" );
869 VisualFactory factory = VisualFactory::Get();
870 DALI_TEST_CHECK( factory );
872 Property::Map propertyMap;
873 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
874 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
876 Visual::Base visual = factory.CreateVisual( propertyMap );
877 DALI_TEST_CHECK( visual );
879 TestGlAbstraction& gl = application.GetGlAbstraction();
880 TraceCallStack& textureTrace = gl.GetTextureTrace();
881 textureTrace.Enable( true );
882 TraceCallStack& drawTrace = gl.GetDrawTrace();
883 drawTrace.Enable( true );
885 DummyControl actor = DummyControl::New();
886 DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
887 dummyImpl.RegisterVisual( Control::Property::BACKGROUND, visual );
889 Stage::GetCurrent().Add( actor );
892 Stage::GetCurrent().Remove( actor );
894 Stage::GetCurrent().Add( actor );
896 // Create another visual with the same image
897 visual = factory.CreateVisual( propertyMap );
898 DALI_TEST_CHECK( visual );
900 dummyImpl.RegisterVisual( Control::Property::BACKGROUND, visual );
902 application.SendNotification();
903 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
905 application.SendNotification();
906 application.Render();
908 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
909 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
910 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
911 DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION );
916 int UtcDaliImageVisualSetInvalidAsyncImage(void)
918 ToolkitTestApplication application;
919 tet_infoline( "Request image visual with invalid images - should draw broken.png" );
921 VisualFactory factory = VisualFactory::Get();
922 DALI_TEST_CHECK( factory );
924 Property::Map propertyMap;
925 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
926 propertyMap.Insert( ImageVisual::Property::URL, TEST_INVALID_FILE_NAME );
928 Visual::Base visual = factory.CreateVisual( propertyMap );
929 DALI_TEST_CHECK( visual );
931 TestGlAbstraction& gl = application.GetGlAbstraction();
932 TraceCallStack& textureTrace = gl.GetTextureTrace();
933 textureTrace.Enable(true);
935 DummyControl actor = DummyControl::New();
936 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
937 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
939 actor.SetSize( 200.f, 200.f );
940 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
942 Stage::GetCurrent().Add( actor );
944 application.SendNotification();
945 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
947 application.SendNotification();
948 application.Render();
950 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
951 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
953 Stage::GetCurrent().Remove( actor );
954 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
959 int UtcDaliImageVisualSetInvalidSyncImage(void)
961 ToolkitTestApplication application;
962 tet_infoline( "Request image visual with invalid images - should draw broken.png" );
964 VisualFactory factory = VisualFactory::Get();
965 DALI_TEST_CHECK( factory );
967 Property::Map propertyMap;
968 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
969 propertyMap.Insert( ImageVisual::Property::URL, TEST_INVALID_FILE_NAME );
970 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
972 Visual::Base visual = factory.CreateVisual( propertyMap );
973 DALI_TEST_CHECK( visual );
975 TestGlAbstraction& gl = application.GetGlAbstraction();
976 TraceCallStack& textureTrace = gl.GetTextureTrace();
977 textureTrace.Enable(true);
979 DummyControl actor = DummyControl::New();
980 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
981 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
983 actor.SetSize( 200.f, 200.f );
984 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
986 Stage::GetCurrent().Add( actor );
988 application.SendNotification();
989 application.Render();
991 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
992 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
994 Stage::GetCurrent().Remove( actor );
995 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1000 int UtcDaliImageVisualSetInvalidRemoteImage(void)
1002 ToolkitTestApplication application;
1003 tet_infoline( "Request image visual with invalid images - should draw broken.png" );
1005 VisualFactory factory = VisualFactory::Get();
1006 DALI_TEST_CHECK( factory );
1008 // Local invalid file, asynchronous loading
1009 Property::Map propertyMap;
1010 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1011 propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_INVALID_FILE_NAME );
1013 Visual::Base visual = factory.CreateVisual( propertyMap );
1014 DALI_TEST_CHECK( visual );
1016 TestGlAbstraction& gl = application.GetGlAbstraction();
1017 TraceCallStack& textureTrace = gl.GetTextureTrace();
1018 textureTrace.Enable(true);
1020 DummyControl actor = DummyControl::New();
1021 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1022 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1024 actor.SetSize( 200.f, 200.f );
1025 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1027 Stage::GetCurrent().Add( actor );
1029 application.SendNotification();
1030 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1032 application.SendNotification();
1033 application.Render();
1035 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1036 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1038 Stage::GetCurrent().Remove( actor );
1039 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1044 int UtcDaliImageVisualAlphaMask(void)
1046 ToolkitTestApplication application;
1047 tet_infoline( "Request image visual with a Property::Map containing an Alpha mask" );
1049 VisualFactory factory = VisualFactory::Get();
1050 DALI_TEST_CHECK( factory );
1052 Property::Map propertyMap;
1053 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1054 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
1055 propertyMap.Insert( ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME );
1057 Visual::Base visual = factory.CreateVisual( propertyMap );
1058 DALI_TEST_CHECK( visual );
1060 Property::Map testMap;
1061 visual.CreatePropertyMap(testMap);
1062 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL),Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION );
1064 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1065 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1067 TestGlAbstraction& gl = application.GetGlAbstraction();
1068 TraceCallStack& textureTrace = gl.GetTextureTrace();
1069 textureTrace.Enable(true);
1071 DummyControl actor = DummyControl::New();
1072 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1073 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1075 actor.SetSize( 200.f, 200.f );
1076 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1077 DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
1079 Stage::GetCurrent().Add( actor );
1080 application.SendNotification();
1081 application.Render();
1083 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
1085 application.SendNotification();
1086 application.Render();
1088 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1089 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1090 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
1092 dummyImpl.UnregisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1 );
1093 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1098 int UtcDaliImageVisualRemoteAlphaMask(void)
1100 ToolkitTestApplication application;
1101 tet_infoline( "Request image visual with a Property::Map containing an Alpha mask" );
1103 VisualFactory factory = VisualFactory::Get();
1104 DALI_TEST_CHECK( factory );
1106 const std::string MASK_IMAGE = TEST_REMOTE_IMAGE_FILE_NAME;
1108 Property::Map propertyMap;
1109 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1110 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1111 propertyMap.Insert( "alphaMaskUrl", MASK_IMAGE );
1113 Visual::Base visual = factory.CreateVisual( propertyMap );
1114 DALI_TEST_CHECK( visual );
1116 Property::Map testMap;
1117 visual.CreatePropertyMap(testMap);
1118 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL),Property::Value(MASK_IMAGE), TEST_LOCATION );
1120 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1121 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1123 TestGlAbstraction& gl = application.GetGlAbstraction();
1124 TraceCallStack& textureTrace = gl.GetTextureTrace();
1125 textureTrace.Enable(true);
1127 DummyControl actor = DummyControl::New();
1128 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1129 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1130 DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
1132 actor.SetSize( 200.f, 200.f );
1133 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1135 Stage::GetCurrent().Add( actor );
1136 application.SendNotification();
1137 application.Render();
1139 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
1141 application.SendNotification();
1142 application.Render();
1144 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1145 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1146 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
1152 int UtcDaliImageVisualAlphaMaskCrop(void)
1154 ToolkitTestApplication application;
1155 tet_infoline( "Request image visual with an Alpha mask and scale/cropping" );
1157 VisualFactory factory = VisualFactory::Get();
1158 DALI_TEST_CHECK( factory );
1160 Property::Map propertyMap;
1161 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1162 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
1163 propertyMap.Insert( ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME );
1164 propertyMap.Insert( ImageVisual::Property::MASK_CONTENT_SCALE, 1.6f );
1165 propertyMap.Insert( ImageVisual::Property::CROP_TO_MASK, true );
1167 Visual::Base visual = factory.CreateVisual( propertyMap );
1168 DALI_TEST_CHECK( visual );
1170 Property::Map testMap;
1171 visual.CreatePropertyMap(testMap);
1172 DALI_TEST_EQUALS( *testMap.Find(ImageVisual::Property::ALPHA_MASK_URL),Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION );
1173 DALI_TEST_EQUALS( *testMap.Find(ImageVisual::Property::MASK_CONTENT_SCALE), Property::Value(1.6f), TEST_LOCATION );
1174 DALI_TEST_EQUALS( *testMap.Find(ImageVisual::Property::CROP_TO_MASK),Property::Value(true), TEST_LOCATION );
1176 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1177 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1179 TestGlAbstraction& gl = application.GetGlAbstraction();
1180 TraceCallStack& textureTrace = gl.GetTextureTrace();
1181 textureTrace.Enable(true);
1183 DummyControl actor = DummyControl::New();
1184 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1185 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1187 actor.SetSize( 200.f, 200.f );
1188 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1189 DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
1191 Stage::GetCurrent().Add( actor );
1192 application.SendNotification();
1193 application.Render();
1195 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
1197 application.SendNotification();
1198 application.Render();
1201 visual.GetNaturalSize(size);
1203 DALI_TEST_EQUALS( size, Vector2( 100.0f, 100.0f ), 0.001f, TEST_LOCATION );
1204 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1205 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1206 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
1211 int UtcDaliImageVisualReleasePolicy01(void)
1213 ToolkitTestApplication application;
1214 tet_infoline( "UtcDaliImageVisualReleasePolicy01 Detached Policy, disabling visual with this policy deletes texture" );
1216 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, DevelImageVisual::Property::RELEASE_POLICY, DevelImageVisual::ReleasePolicy::DETACHED );
1217 DALI_TEST_CHECK( imageVisual );
1219 // Set up debug trace
1220 TestGlAbstraction& gl = application.GetGlAbstraction();
1221 TraceCallStack& textureTrace = gl.GetTextureTrace();
1222 textureTrace.Enable(true);
1224 tet_infoline( "Register visual with control and ensure it has the only handle" );
1225 DummyControl actor = DummyControl::New(true);
1226 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1227 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1228 imageVisual.Reset();
1230 actor.SetSize(200.f, 200.f);
1232 application.SendNotification();
1233 application.Render(0);
1234 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1235 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1237 Stage::GetCurrent().Add( actor );
1239 // Wait for image to load
1240 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1242 application.SendNotification();
1243 application.Render(0);
1244 // Test renderer and texture created
1245 tet_infoline( "Confirm texture created" );
1246 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1247 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1249 tet_infoline( "Disable visual causing the texture to be deleted" );
1250 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, false );
1252 application.SendNotification();
1253 application.Render(0);
1254 // Test renderer and textures removed.
1255 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1256 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
1261 int UtcDaliImageVisualReleasePolicy02(void)
1263 ToolkitTestApplication application;
1264 tet_infoline( "UtcDaliImageVisualReleasePolicy02 Destroyed Policy, Texture should be deleted when visual destroyed" );
1266 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, DevelImageVisual::Property::RELEASE_POLICY, DevelImageVisual::ReleasePolicy::DESTROYED );
1267 DALI_TEST_CHECK( imageVisual );
1269 // Setup debug trace
1270 TestGlAbstraction& gl = application.GetGlAbstraction();
1271 TraceCallStack& textureTrace = gl.GetTextureTrace();
1272 textureTrace.Enable(true);
1274 tet_infoline( "Register visual with control and ensure it has the only handle" );
1275 DummyControl actor = DummyControl::New(true);
1276 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1277 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1278 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1280 actor.SetSize(200.f, 200.f);
1282 application.SendNotification();
1283 application.Render(0);
1284 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1285 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1287 Stage::GetCurrent().Add( actor );
1289 // Wait for image to load
1290 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1292 application.SendNotification();
1293 application.Render(0);
1294 // Test renderer and texture created
1295 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1296 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1299 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1300 tet_infoline( "Destroy visual by UnRegistering visual with control, check renderer is destroyed" );
1301 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1302 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1303 application.SendNotification();
1304 application.Render();
1306 // Test texture removed after visual destroyed.
1307 tet_infoline( "Ensure texture is deleted after visual destroyed" );
1308 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
1313 int UtcDaliImageVisualReleasePolicy03(void)
1315 ToolkitTestApplication application;
1316 tet_infoline( "UtcDaliImageVisualReleasePolicy03 Never Policy, texture should not be deleted after visual destroyed" );
1318 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, DevelImageVisual::Property::RELEASE_POLICY, DevelImageVisual::ReleasePolicy::NEVER );
1319 DALI_TEST_CHECK( imageVisual );
1321 TestGlAbstraction& gl = application.GetGlAbstraction();
1322 TraceCallStack& textureTrace = gl.GetTextureTrace();
1323 textureTrace.Enable(true);
1325 tet_infoline( "Register visual with control and ensure it has the only handle" );
1326 DummyControl actor = DummyControl::New(true);
1327 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1328 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1329 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1331 actor.SetSize(200.f, 200.f);
1333 application.SendNotification();
1334 application.Render(0);
1335 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1336 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1338 Stage::GetCurrent().Add( actor );
1340 // Wait for image to load
1341 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1343 application.SendNotification();
1344 application.Render(0);
1345 // Test renderer and texture created
1346 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1347 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1349 tet_infoline( "Destroy visual by UnRegistering visual with control, check renderer is destroyed" );
1350 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1351 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1352 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1353 application.SendNotification();
1354 application.Render();
1356 tet_infoline( "Ensure texture is not deleted as policy is set to NEVER" );
1357 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1362 int UtcDaliImageVisualReleasePolicy04(void)
1364 ToolkitTestApplication application;
1365 tet_infoline( "UtcDaliImageVisualReleasePolicy04 Two visuals with different policies sharing a texture" );
1367 tet_infoline( "Create first visual with Never release policy" );
1368 Visual::Base imageVisualNever = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, DevelImageVisual::Property::RELEASE_POLICY, DevelImageVisual::ReleasePolicy::NEVER );
1370 tet_infoline( "Create second visual with Destroyed release policy");
1371 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, DevelImageVisual::Property::RELEASE_POLICY, DevelImageVisual::ReleasePolicy::DESTROYED );
1373 // Set up trace debug
1374 TestGlAbstraction& gl = application.GetGlAbstraction();
1375 TraceCallStack& textureTrace = gl.GetTextureTrace();
1376 textureTrace.Enable(true);
1378 tet_infoline( "Register visuals with control and ensure it has the only handles" );
1379 DummyControl actor = DummyControl::New(true);
1380 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1381 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisualNever );
1382 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL2, imageVisualDestroyed );
1383 imageVisualNever.Reset(); // reduce ref count so only the control keeps the visual alive.
1384 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
1386 actor.SetSize(200.f, 200.f);
1388 // Test initially zero renderers
1389 application.SendNotification();
1390 application.Render(0);
1391 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1392 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1394 Stage::GetCurrent().Add( actor );
1396 // Wait for image to load
1397 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1399 application.SendNotification();
1400 application.Render(0);
1401 tet_infoline( "Ensure a texture is created, shared amongst both visuals. Each visual has its own renderer" );
1402 DALI_TEST_EQUALS( actor.GetRendererCount(), 2u, TEST_LOCATION );
1403 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1405 // Test renderer removed when visual destroyed
1406 DALI_TEST_CHECK( actor.GetRendererCount() == 2u );
1407 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL2 ); // TEST_VISUAL2 no longer requires the texture as release policy DESTROYED
1408 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1409 application.SendNotification();
1410 application.Render();
1412 // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
1413 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1415 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1416 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1417 application.SendNotification();
1418 application.Render();
1420 tet_infoline( "Ensure a texture is not deleted as second visual used the NEVER release policy" );
1421 // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
1422 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1427 int UtcDaliImageVisualReleasePolicy05(void)
1429 ToolkitTestApplication application;
1430 tet_infoline( "UtcDaliImageVisualReleasePolicy05 Testing settung by string currents correct enum" );
1432 VisualFactory factory = VisualFactory::Get();
1434 Property::Map propertyMapNeverReleasePolicy;
1435 propertyMapNeverReleasePolicy.Insert( Visual::Property::TYPE, Visual::IMAGE );
1436 propertyMapNeverReleasePolicy.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1437 propertyMapNeverReleasePolicy.Insert( ImageVisual::Property::DESIRED_WIDTH, 20 );
1438 propertyMapNeverReleasePolicy.Insert( ImageVisual::Property::DESIRED_HEIGHT, 30 );
1439 propertyMapNeverReleasePolicy.Insert( "releasePolicy" , "never" );
1441 Visual::Base imageVisualNever = factory.CreateVisual( propertyMapNeverReleasePolicy );
1443 Property::Map resultMap;
1444 imageVisualNever.CreatePropertyMap( resultMap );
1445 DALI_TEST_CHECK( ! resultMap.Empty() );
1447 DALI_TEST_EQUALS( ( resultMap.Find( DevelImageVisual::Property::RELEASE_POLICY ) )->Get<int>(), (int)DevelImageVisual::ReleasePolicy::NEVER, TEST_LOCATION );
1452 int UtcDaliImageVisualReleasePolicy06(void)
1454 ToolkitTestApplication application;
1455 tet_infoline( "UtcDaliImageVisualReleasePolicy06 Never Policy, texture should not be affected by Disabling and Enabling visual" );
1457 Visual::Base imageVisual= CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, DevelImageVisual::Property::RELEASE_POLICY, DevelImageVisual::ReleasePolicy::NEVER );
1458 DALI_TEST_CHECK( imageVisual );
1460 TestGlAbstraction& gl = application.GetGlAbstraction();
1461 TraceCallStack& textureTrace = gl.GetTextureTrace();
1462 textureTrace.Enable(true);
1464 tet_infoline( "Register visual with control and ensure it has the only handle" );
1465 DummyControl actor = DummyControl::New(true);
1466 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1467 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1468 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1470 actor.SetSize(200.f, 200.f);
1472 application.SendNotification();
1473 application.Render(0);
1474 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1475 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1477 Stage::GetCurrent().Add( actor );
1479 // Wait for image to load
1480 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1482 application.SendNotification();
1483 application.Render(0);
1484 // Test renderer and texture created
1485 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1486 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1487 textureTrace.Reset();
1489 tet_infoline( "Disable Visual and check texture not affected" );
1490 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, false );
1491 application.SendNotification();
1492 application.Render(0);
1493 tet_infoline( "Check renderer is destroyed when visual off stage" );
1494 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1495 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1496 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1497 textureTrace.Reset();
1499 tet_infoline( "Re-enable Visual and check texture not affected" );
1500 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, true );
1501 application.SendNotification();
1502 application.Render(0);
1503 tet_infoline( "Check texture not affected and renderer is destroyed when visual off stage" );
1504 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1505 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1506 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1511 int UtcDaliImageVisualReleasePolicy07(void)
1513 ToolkitTestApplication application;
1514 tet_infoline( "UtcDaliImageVisualReleasePolicy07 Two visuals with different policies sharing a texture DETACHED and DESTROYED" );
1516 tet_infoline( "Create first visual with DESTROYED release policy" );
1517 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, DevelImageVisual::Property::RELEASE_POLICY, DevelImageVisual::ReleasePolicy::DESTROYED );
1520 tet_infoline( "Create second visual with DETACHED release policy");
1521 Visual::Base imageVisualDetached = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, DevelImageVisual::Property::RELEASE_POLICY, DevelImageVisual::ReleasePolicy::DETACHED );
1523 // Set up trace debug
1524 TestGlAbstraction& gl = application.GetGlAbstraction();
1525 TraceCallStack& textureTrace = gl.GetTextureTrace();
1526 textureTrace.Enable(true);
1528 tet_infoline( "Register visuals with control and ensure it has the only handles" );
1529 DummyControl actor = DummyControl::New(true);
1530 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1531 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisualDestroyed );
1532 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL2, imageVisualDetached );
1533 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
1534 imageVisualDetached.Reset(); // reduce ref count so only the control keeps the visual alive.
1536 actor.SetSize(200.f, 200.f);
1538 // Test initially zero renderers
1539 application.SendNotification();
1540 application.Render(0);
1541 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1542 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1544 Stage::GetCurrent().Add( actor );
1546 // Wait for image to load
1547 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1549 application.SendNotification();
1550 application.Render(0);
1551 tet_infoline( "Ensure a texture is created, shared amongst both visuals. Each visual has its own renderer" );
1552 DALI_TEST_EQUALS( actor.GetRendererCount(), 2u, TEST_LOCATION );
1553 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1555 // Test renderer removed when visual destroyed
1556 DALI_TEST_CHECK( actor.GetRendererCount() == 2u );
1557 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL2, false ); // TEST_VISUAL2 no longer requires the texture as release policy DETACHED
1558 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1559 application.SendNotification();
1560 application.Render();
1562 // Test texture was not deleted as TEST_VISUAL release policy is DESTROYED and is still required.
1563 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1565 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, false );
1566 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1567 application.SendNotification();
1568 application.Render();
1570 tet_infoline( "Ensure a texture is not deleted as second visual used the DESTROYED release policy" );
1571 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1576 int UtcDaliImageVisualLoadPolicy01(void)
1578 ToolkitTestApplication application;
1579 tet_infoline( "UtcDaliImageVisualLoadPolicy01 Load a visual image before attaching to stage" );
1581 // Set up trace debug
1582 TestGlAbstraction& gl = application.GetGlAbstraction();
1583 TraceCallStack& textureTrace = gl.GetTextureTrace();
1584 textureTrace.Enable(true);
1586 tet_infoline( "Create visual with IMMEDIATE load policy" );
1587 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, DevelImageVisual::Property::LOAD_POLICY, DevelImageVisual::LoadPolicy::IMMEDIATE );
1589 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1591 // Ensure texture has been uploaded
1592 application.SendNotification();
1593 application.Render();
1595 tet_infoline( "Ensure texture loading starts after visual created" );
1596 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1597 textureTrace.Reset();
1599 tet_infoline( "Register visuals with control and ensure it has the only handles" );
1600 DummyControl actor = DummyControl::New(true);
1601 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1602 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1603 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1605 actor.SetSize(200.f, 200.f);
1606 Stage::GetCurrent().Add( actor );
1607 tet_infoline( "Ensure nothing triggers another load as texure already loaded" );
1608 const unsigned int TIME_OUT_3_SECONDS = 3;
1609 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, TIME_OUT_3_SECONDS ), false, TEST_LOCATION );
1611 application.SendNotification();
1612 application.Render();
1614 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1615 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1617 // Ensure texture is deleted when no longer needed (ref count was correct )
1618 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1620 application.SendNotification();
1621 application.Render();
1623 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1624 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
1629 int UtcDaliImageVisualLoadPolicy02(void)
1631 ToolkitTestApplication application;
1632 tet_infoline( "UtcDaliImageVisualLoadPolicy01 Load a visual image only after attached to stage" );
1634 // Set up trace debug
1635 TestGlAbstraction& gl = application.GetGlAbstraction();
1636 TraceCallStack& textureTrace = gl.GetTextureTrace();
1637 textureTrace.Enable(true);
1639 tet_infoline( "Create visual with IMMEDIATE load policy" );
1640 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, DevelImageVisual::Property::LOAD_POLICY, DevelImageVisual::LoadPolicy::ATTACHED );
1642 const unsigned int TIME_OUT_3_SECONDS = 3;
1643 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, TIME_OUT_3_SECONDS ), false, TEST_LOCATION );
1645 // Act on meeage queue even although nothing expected to load
1646 application.SendNotification();
1647 application.Render();
1649 tet_infoline( "Ensure texture is not generated yet" );
1650 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1651 textureTrace.Reset();
1653 tet_infoline( "Register visuals with control and ensure it has the only handles" );
1654 DummyControl actor = DummyControl::New(true);
1655 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1656 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1657 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1659 actor.SetSize(200.f, 200.f);
1660 Stage::GetCurrent().Add( actor );
1661 tet_infoline( "Allow image time to load" );
1662 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1664 application.SendNotification();
1665 application.Render();
1667 tet_infoline( "Ensure texture generated and renderer created" );
1668 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1669 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1671 // Ensure texture is delete when no longer needed
1672 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1674 application.SendNotification();
1675 application.Render();
1677 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1678 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
1683 int UtcDaliImageVisualLoadPolicy03(void)
1685 ToolkitTestApplication application;
1686 tet_infoline( "UtcDaliImageVisualLoadPolicy03 Load a visual image and receive ResourceReady Signal when loaded" );
1688 const bool VISUAL_NOT_ENABLED( false ); // Instead of just passing 'false' into an API.
1690 // Set up trace debug
1691 TestGlAbstraction& gl = application.GetGlAbstraction();
1692 TraceCallStack& textureTrace = gl.GetTextureTrace();
1693 textureTrace.Enable(true);
1695 tet_infoline( "Create a control and connect to resource ready signal without adding to stage" );
1696 DummyControl actor = DummyControl::New(true);
1697 actor.ResourceReadySignal().Connect( &ResourceReadySignal);
1698 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1699 actor.SetSize(200.f, 200.f);
1701 tet_infoline( "Create visual with IMMEDIATE load policy" );
1702 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, DevelImageVisual::Property::LOAD_POLICY, DevelImageVisual::LoadPolicy::IMMEDIATE );
1704 tet_infoline( "Registering visual allows control to get a signal once loaded even if visual not enabled( not staged )" );
1705 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED );
1706 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1708 tet_infoline( "Allow image time to load resource" );
1709 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1710 application.SendNotification();
1711 application.Render();
1713 // Ensure texture has been uploaded
1714 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1715 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1720 int UtcDaliImageVisualLoadPolicy04(void)
1722 ToolkitTestApplication application;
1723 tet_infoline( "UtcDaliImageVisualLoadPolicy04 First part Load a visual image before attaching to stage");
1724 tet_infoline( "Second part, Reuse the same image in aonther control and check resource ready signal fired" );
1726 const bool VISUAL_NOT_ENABLED( false ); // Instead of just passing false into an API.
1728 // Set up trace debug
1729 TestGlAbstraction& gl = application.GetGlAbstraction();
1730 TraceCallStack& textureTrace = gl.GetTextureTrace();
1731 textureTrace.Enable(true);
1733 tet_infoline( "Create a control and connect to resource ready signal" );
1734 DummyControl actor = DummyControl::New(true);
1735 actor.ResourceReadySignal().Connect( &ResourceReadySignal);
1736 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1737 actor.SetSize(200.f, 200.f);
1739 tet_infoline( "Create visual with IMMEDIATE load policy" );
1740 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, DevelImageVisual::Property::LOAD_POLICY, DevelImageVisual::LoadPolicy::IMMEDIATE );
1742 tet_infoline( "Registering visual allows control to get a signal once loaded even if visual not enabled( staged )" );
1743 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED );
1744 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1746 tet_infoline( "Allow image time to load" );
1747 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1748 application.SendNotification();
1749 application.Render();
1751 tet_infoline( "Testing texture is loaded and resource ready signal fired" );
1752 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1753 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1755 tet_infoline( "Original control correctly signalled, now testing for signal with new Control reusing the image" );
1757 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
1758 Visual::Base imageVisual2 = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, DevelImageVisual::Property::LOAD_POLICY, DevelImageVisual::LoadPolicy::IMMEDIATE );
1759 DummyControl actor2 = DummyControl::New(true);
1760 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1761 actor2.ResourceReadySignal().Connect( &ResourceReadySignal);
1763 tet_infoline( "Registering visual this should trigger the loading signal as is already image loaded for previous control" );
1764 dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual2 );
1765 imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
1766 actor2.SetSize(200.f, 200.f);
1767 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 0 ), true, TEST_LOCATION ); // Not expecting any further loading as texture is being reused.
1768 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1773 int UtcDaliImageVisualLoadPolicy05(void)
1775 ToolkitTestApplication application;
1776 tet_infoline( "UtcDaliImageVisualLoadPolicy05 LoadPolicy::ATTACHED (default) First part Load a visual image before attaching to stage");
1777 tet_infoline( "Second part, Reuse the same image in aonther control and check resource ready signal fired" );
1778 // Set up trace debug
1779 TestGlAbstraction& gl = application.GetGlAbstraction();
1780 TraceCallStack& textureTrace = gl.GetTextureTrace();
1781 textureTrace.Enable(true);
1783 tet_infoline( "Create a control and connect to resource ready signal" );
1784 DummyControl actor = DummyControl::New(true);
1785 actor.ResourceReadySignal().Connect( &ResourceReadySignal);
1786 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1787 actor.SetSize(200.f, 200.f);
1788 Stage::GetCurrent().Add( actor );
1790 tet_infoline( "Create visual with ATTACHED load policy" );
1791 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, DevelImageVisual::Property::LOAD_POLICY, DevelImageVisual::LoadPolicy::ATTACHED );
1793 tet_infoline( "Registering visual allows control to get a signal once loaded" );
1794 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1795 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1797 tet_infoline( "Allow image time to load" );
1798 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1799 application.SendNotification();
1800 application.Render();
1802 tet_infoline( "Testing texture is loaded and resource ready signal fired" );
1803 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1804 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1806 tet_infoline( "Original control correctly signalled, now testing for signal with new Control reusing the image" );
1808 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
1809 Visual::Base imageVisual2 = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, DevelImageVisual::Property::LOAD_POLICY, DevelImageVisual::LoadPolicy::ATTACHED );
1810 DummyControl actor2 = DummyControl::New(true);
1811 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1812 actor2.ResourceReadySignal().Connect( &ResourceReadySignal);
1814 tet_infoline( "Registering visual this should trigger the loading signal as is already image loaded for previous control" );
1815 dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual2 );
1816 imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
1817 actor2.SetSize(200.f, 200.f);
1818 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 0 ), true, TEST_LOCATION ); // Not expecting any further loading as texture is being reused.
1819 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1825 int UtcDaliImageVisualOrientationCorrection(void)
1827 ToolkitTestApplication application;
1828 tet_infoline( "UtcDaliImageVisualOrientationCorrection Enabling OrientationCorrection should rotate an image with exif (90deg) orientation data with requested" );
1830 VisualFactory factory = VisualFactory::Get();
1831 tet_infoline( "Create visual with Orientation correction set OFF" );
1832 Property::Map propertyMap;
1833 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
1834 propertyMap.Insert( ImageVisual::Property::URL, TEST_ROTATED_IMAGE );
1835 propertyMap.Insert( DevelImageVisual::Property::ORIENTATION_CORRECTION, false );
1836 Visual::Base imageVisual = factory.CreateVisual( propertyMap );
1838 tet_infoline( "Create control for visual, need to loaded it" );
1839 DummyControl actor = DummyControl::New(true);
1840 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1841 Stage::GetCurrent().Add( actor );
1843 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1844 // Wait for image to load
1845 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1847 Vector2 originalImageSize;
1848 tet_infoline( "Get size of original visual to compare later with rotated image" );
1849 imageVisual.GetNaturalSize( originalImageSize );
1850 DALI_TEST_GREATER( originalImageSize.width, originalImageSize.height, TEST_LOCATION ); // Width and Height must be different for this test.
1851 imageVisual.Reset(); // remove handle so can unregister it and remove from cache
1852 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1853 application.SendNotification();
1854 application.Render();
1856 tet_infoline( "Create visual with Orientation correction set ON " );
1857 propertyMap.Clear();
1858 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
1859 propertyMap.Insert( ImageVisual::Property::URL, TEST_ROTATED_IMAGE );
1860 propertyMap.Insert( DevelImageVisual::Property::ORIENTATION_CORRECTION, true );
1861 imageVisual = factory.CreateVisual( propertyMap );
1863 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1864 // Wait for image to load
1865 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1867 Vector2 rotatedImageSize;
1868 imageVisual.GetNaturalSize( rotatedImageSize );
1869 tet_infoline( "Confirm that visual has rotated" );
1870 DALI_TEST_EQUALS( originalImageSize.width, rotatedImageSize.height , TEST_LOCATION );
1871 DALI_TEST_EQUALS( originalImageSize.height, rotatedImageSize.width , TEST_LOCATION );
1873 Property::Map resultMap;
1874 imageVisual.CreatePropertyMap( resultMap );
1876 // check the Property::ORIENTATION_CORRECTION value from the returned map
1877 Property::Value* typeValue = resultMap.Find( DevelImageVisual::Property::ORIENTATION_CORRECTION, Property::BOOLEAN );
1878 DALI_TEST_EQUALS( typeValue->Get<bool>(), true, TEST_LOCATION );