+
+int UtcDaliImageVisualLoadPolicy01(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline( "UtcDaliImageVisualLoadPolicy01 Load a visual image before attaching to stage" );
+
+ // Set up trace debug
+ TestGlAbstraction& gl = application.GetGlAbstraction();
+ TraceCallStack& textureTrace = gl.GetTextureTrace();
+ textureTrace.Enable(true);
+
+ tet_infoline( "Create visual with IMMEDIATE load policy" );
+ Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, DevelImageVisual::Property::LOAD_POLICY, DevelImageVisual::LoadPolicy::IMMEDIATE );
+
+ DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
+
+ // Ensure texture has been uploaded
+ application.SendNotification();
+ application.Render();
+
+ tet_infoline( "Ensure texture loading starts after visual created" );
+ DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
+ textureTrace.Reset();
+
+ tet_infoline( "Register visuals with control and ensure it has the only handles" );
+ DummyControl actor = DummyControl::New(true);
+ Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
+ dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
+ imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
+
+ actor.SetSize(200.f, 200.f);
+ Stage::GetCurrent().Add( actor );
+ tet_infoline( "Ensure nothing triggers another load as texure already loaded" );
+ const unsigned int TIME_OUT_3_SECONDS = 3;
+ DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, TIME_OUT_3_SECONDS ), false, TEST_LOCATION );
+
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
+ DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
+
+ // Ensure texture is deleted when no longer needed (ref count was correct )
+ dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
+
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
+ DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliImageVisualLoadPolicy02(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline( "UtcDaliImageVisualLoadPolicy01 Load a visual image only after attached to stage" );
+
+ // Set up trace debug
+ TestGlAbstraction& gl = application.GetGlAbstraction();
+ TraceCallStack& textureTrace = gl.GetTextureTrace();
+ textureTrace.Enable(true);
+
+ tet_infoline( "Create visual with IMMEDIATE load policy" );
+ Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, DevelImageVisual::Property::LOAD_POLICY, DevelImageVisual::LoadPolicy::ATTACHED );
+
+ const unsigned int TIME_OUT_3_SECONDS = 3;
+ DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, TIME_OUT_3_SECONDS ), false, TEST_LOCATION );
+
+ // Act on meeage queue even although nothing expected to load
+ application.SendNotification();
+ application.Render();
+
+ tet_infoline( "Ensure texture is not generated yet" );
+ DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
+ textureTrace.Reset();
+
+ tet_infoline( "Register visuals with control and ensure it has the only handles" );
+ DummyControl actor = DummyControl::New(true);
+ Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
+ dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
+ imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
+
+ actor.SetSize(200.f, 200.f);
+ Stage::GetCurrent().Add( actor );
+ tet_infoline( "Allow image time to load" );
+ DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
+
+ application.SendNotification();
+ application.Render();
+
+ tet_infoline( "Ensure texture generated and renderer created" );
+ DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
+ DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
+
+ // Ensure texture is delete when no longer needed
+ dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
+
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
+ DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliImageVisualLoadPolicy03(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline( "UtcDaliImageVisualLoadPolicy03 Load a visual image before attaching to stage and receive ResourceReady signal" );
+
+ // Set up trace debug
+ TestGlAbstraction& gl = application.GetGlAbstraction();
+ TraceCallStack& textureTrace = gl.GetTextureTrace();
+ textureTrace.Enable(true);
+
+ tet_infoline( "Create visual with IMMEDIATE load policy" );
+ Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, DevelImageVisual::Property::LOAD_POLICY, DevelImageVisual::LoadPolicy::IMMEDIATE );
+
+ // Wait for image to load, ResourceReady signal will not be emitted until Visual is registered with a control and on stage.
+ DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
+
+ // Ensure texture has been uploaded
+ application.SendNotification();
+ application.Render();
+
+ tet_infoline( "Ensure texture loading starts after visual created" );
+ DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
+ textureTrace.Reset();
+
+ tet_infoline( "Register visuals with control and ensure it has the only handles" );
+ DummyControl actor = DummyControl::New(true);
+ actor.ResourceReadySignal().Connect( &ResourceReadySignal);
+ Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
+
+ tet_infoline( "Registering visual attaches it to stage and trigger the loading signal if Image loaded" );
+ dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
+ imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
+ actor.SetSize(200.f, 200.f);
+ // Adding the Control hence Visual to stage will cause the Visual to trigger ResourceReadySignal if the image is already loaded.
+ 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
+
+ DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
+
+ END_TEST;
+}