Merge "Refactorying code related to broken image" into devel/master
authorsunghyun kim <scholb.kim@samsung.com>
Thu, 6 Jan 2022 04:49:03 +0000 (04:49 +0000)
committerGerrit Code Review <gerrit@review>
Thu, 6 Jan 2022 04:49:03 +0000 (04:49 +0000)
automated-tests/src/dali-toolkit-internal/utc-Dali-DebugRendering.cpp
automated-tests/src/dali-toolkit/utc-Dali-ImageView.cpp
dali-toolkit/internal/controls/image-view/image-view-impl.cpp

index 8184dd7..2887613 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -257,6 +257,57 @@ int UtcDaliDebugRenderingGetVisual2(void)
   END_TEST;
 }
 
+
+int UtcDaliDebugRenderingGetVisual3(void)
+{
+  EnvironmentVariable::SetTestingEnvironmentVariable( true );
+  ToolkitTestApplication application;
+  tet_infoline( "UtcDaliDebugRenderingGetVisual3: Request visual with various parameters" );
+
+  VisualFactory factory = VisualFactory::Get();
+  DALI_TEST_CHECK( factory );
+
+  // Test that image visual is replaced with debug visual
+  Dali::Property::Map map;
+  map[ Toolkit::Visual::Property::TYPE ] = Visual::IMAGE;
+  map[ ImageVisual::Property::URL ] = TEST_IMAGE_FILE_NAME;
+  Visual::Base imageVisual = factory.CreateVisual( map );
+  DALI_TEST_CHECK( imageVisual );
+  TestDebugVisual( application.GetScene(),  imageVisual, Visual::IMAGE, Vector2(64.0f, 64.0f /* Broken Image Size */ ));
+
+  // Test that image visual with null string don't make visual
+  map.Clear();
+  map[ Toolkit::Visual::Property::TYPE ] = Visual::IMAGE;
+  map[ ImageVisual::Property::URL ] = "";
+  Visual::Base emptyVisual = factory.CreateVisual( map );
+  DALI_TEST_CHECK( emptyVisual );
+  TestDebugVisual( application.GetScene(), emptyVisual, Visual::WIREFRAME, Vector2::ZERO);
+
+  tet_infoline( "Check that GetVisualObject returns the actual WireframeVisual" );
+  Toolkit::Internal::Visual::Base& visualImpl = GetImplementation( emptyVisual ).GetVisualObject();
+  DALI_TEST_CHECK( dynamic_cast< Toolkit::Internal::WireframeVisual* >( &visualImpl ) );
+
+  tet_infoline( "Compare the returned emptyVisual with the visual implementation, should be the same" );
+  DALI_TEST_CHECK( emptyVisual.GetObjectPtr() == &visualImpl );
+
+  // Test that image view with empty property map don't make visual even DebugRendering is enabled.
+  map.Clear();
+  ImageView imageView = ImageView::New();
+  imageView.SetProperty(Control::Property::BACKGROUND, map);
+  imageView.SetProperty(ImageView::Property::IMAGE, map);
+
+  application.GetScene().Add(imageView);
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS( imageView.GetRendererCount(), 0u, TEST_LOCATION );
+
+  EnvironmentVariable::SetTestingEnvironmentVariable(false);
+  END_TEST;
+}
+
+
 int UtcDaliDebugRenderingGetVisualObject01(void)
 {
   EnvironmentVariable::SetTestingEnvironmentVariable( true );
@@ -281,6 +332,7 @@ int UtcDaliDebugRenderingGetVisualObject01(void)
   tet_infoline( "Compare the returned TextVisual with the visual implementation, should differ" );
   DALI_TEST_CHECK( textVisual.GetObjectPtr() != &visualImpl );
 
+  EnvironmentVariable::SetTestingEnvironmentVariable( false );
   END_TEST;
 }
 
@@ -352,4 +404,4 @@ int UtcDaliDebugRenderingRenderText(void)
   }
 
   END_TEST;
-}
+}
\ No newline at end of file
index 7c0e975..e81bb5f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -1170,6 +1170,35 @@ int UtcDaliImageViewSetImageTypeChangesP(void)
   DALI_TEST_CHECK( value.Get( map ) );   // Value should NOT be empty
   DALI_TEST_CHECK( ! visual );           // Visual should be invalid
 
+  // Set a URL in property map again
+  propertyMap[ImageVisual::Property::URL] = gImage_34_RGBA;
+  imageView.SetProperty( ImageView::Property::IMAGE, propertyMap );
+
+  application.SendNotification();
+  application.Render( 16 );
+
+  value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
+  visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
+
+  DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
+  DALI_TEST_CHECK( value.Get( map ) );   // Value should NOT be empty
+  DALI_TEST_CHECK( visual );             // Visual should be valid
+
+  // Set an empty property map
+  propertyMap.Clear();
+  imageView.SetProperty( ImageView::Property::IMAGE, propertyMap );
+
+  application.SendNotification();
+  application.Render( 16 );
+
+  value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
+  visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
+
+  DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
+  DALI_TEST_CHECK( value.Get( map ) );   // Value should NOT be empty
+  DALI_TEST_CHECK( map.Empty() );        // But PropertyMap should be empty
+  DALI_TEST_CHECK( ! visual );           // Visual should be invalid
+
   END_TEST;
 }
 
index c299886..1d9deec 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -479,27 +479,43 @@ void ImageView::SetProperty(BaseObject* object, Property::Index index, const Pro
           map = value.GetMap();
           if(map)
           {
-            Property::Value* shaderValue = map->Find(Toolkit::Visual::Property::SHADER, CUSTOM_SHADER);
-            // set image only if property map contains image information other than custom shader
-            if(map->Count() > 1u || !shaderValue)
+            // the property map is emtpy map. Unregister visual.
+            if(DALI_UNLIKELY(map->Count() == 0u))
             {
-              impl.SetImage(*map);
+              // Clear cached properties
+              impl.mPropertyMap.Clear();
+              impl.mUrl.clear();
+
+              // Unregister the exsiting visual
+              DevelControl::UnregisterVisual(impl, Toolkit::ImageView::Property::IMAGE);
+
+              // Trigger a size negotiation request that may be needed when unregistering a visual.
+              impl.RelayoutRequest();
             }
-            // the property map contains only the custom shader
-            else if((map->Count() == 1u) && (shaderValue))
+            else
             {
-              Property::Map* shaderMap = shaderValue->GetMap();
-              if(shaderMap)
+              Property::Value* shaderValue = map->Find(Toolkit::Visual::Property::SHADER, CUSTOM_SHADER);
+              // set image only if property map contains image information other than custom shader
+              if(map->Count() > 1u || !shaderValue)
               {
-                impl.mShaderMap = *shaderMap;
-
-                if(!impl.mUrl.empty())
-                {
-                  impl.SetImage(impl.mUrl, impl.mImageSize);
-                }
-                else if(!impl.mPropertyMap.Empty())
+                impl.SetImage(*map);
+              }
+              // the property map contains only the custom shader
+              else if((map->Count() == 1u) && (shaderValue))
+              {
+                Property::Map* shaderMap = shaderValue->GetMap();
+                if(shaderMap)
                 {
-                  impl.SetImage(impl.mPropertyMap);
+                  impl.mShaderMap = *shaderMap;
+
+                  if(!impl.mUrl.empty())
+                  {
+                    impl.SetImage(impl.mUrl, impl.mImageSize);
+                  }
+                  else if(!impl.mPropertyMap.Empty())
+                  {
+                    impl.SetImage(impl.mPropertyMap);
+                  }
                 }
               }
             }