Add check for whether the Renderer has been created. 87/178587/2
authorthothamon <jason.perry@partner.samsung.com>
Thu, 10 May 2018 14:05:36 +0000 (15:05 +0100)
committerthothamon <jason.perry@partner.samsung.com>
Thu, 10 May 2018 16:46:57 +0000 (17:46 +0100)
 - the Renderer is not created until after an actor has been added to
the Stage
  - add test case 'UtcDaliImageVisualAnimateOpacity02' which checks
whether the Renderer is resident before the actor is staged but after a
transition has been created.

Change-Id: Ib9d450d98d8c482ff3396ddaea7b2e720d385d4e

automated-tests/src/dali-toolkit/utc-Dali-ImageVisual.cpp
dali-toolkit/internal/controls/control/control-data-impl.cpp
dali-toolkit/internal/visuals/visual-base-impl.cpp
dali-toolkit/internal/visuals/visual-base-impl.h

index 8b17338..5cbfc89 100644 (file)
@@ -890,6 +890,95 @@ int UtcDaliImageVisualAnimateOpacity(void)
   END_TEST;
 }
 
+
+
+int UtcDaliImageVisualAnimateOpacity02(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline( "Animate image visual opacity" );
+
+  application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
+
+  VisualFactory factory = VisualFactory::Get();
+  Property::Map propertyMap;
+  propertyMap.Insert(Visual::Property::TYPE,  Visual::IMAGE);
+  propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
+  propertyMap.Insert("opacity", 0.5f);
+  propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
+  Visual::Base visual = factory.CreateVisual( propertyMap );
+
+  DummyControl actor = DummyControl::New(true);
+  Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
+  dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
+
+  actor.SetSize(2000, 2000);
+  actor.SetParentOrigin(ParentOrigin::CENTER);
+  actor.SetColor(Color::BLACK);
+
+  tet_infoline( "Test that the opacity doesn't animate when actor not staged" );
+
+  Property::Array array;
+
+  Property::Map map;
+  map["target"] = "testVisual";
+  map["property"] = "opacity";
+  map["initialValue"] = 0.0f;
+  map["targetValue"] = 1.0f;
+  map["animator"] = Property::Map()
+    .Add("alphaFunction", "LINEAR")
+    .Add("timePeriod", Property::Map()
+         .Add("delay", 0.0f)
+         .Add("duration", 4.0f));
+
+  Property::Map map2;
+  map2["target"] = "testVisual";
+  map2["property"] = "size";
+  map2["targetValue"] = Vector2(1.0f, 1.0f);
+
+  array.Add( map ).Add(map2);
+
+  Dali::Toolkit::TransitionData transition = TransitionData::New( array );
+  Animation animation = dummyImpl.CreateTransition( transition );
+
+  Stage::GetCurrent().Add(actor);
+  application.SendNotification();
+  application.Render(0);     // Ensure animation starts
+
+  DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
+
+  Renderer renderer = actor.GetRendererAt(0);
+  Property::Value blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
+  DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION );
+
+  animation = dummyImpl.CreateTransition( transition );
+  animation.Play();
+
+  application.SendNotification();
+  application.Render(0);     // Ensure animation starts
+  application.Render(2000u); // Halfway point through animation
+  application.SendNotification(); // Handle any signals
+
+  blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
+  DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
+
+  Vector4 color;
+  DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
+  DALI_TEST_EQUALS( color.a, 0.5f, TEST_LOCATION );
+
+  application.Render(2001u); // end
+  application.SendNotification(); // ensure animation finished signal is sent
+
+  DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
+  DALI_TEST_EQUALS( color.a, 1.0f, TEST_LOCATION );
+
+  blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
+  DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION );
+
+  END_TEST;
+}
+
+
+
 int UtcDaliImageVisualAnimatePixelArea(void)
 {
   ToolkitTestApplication application;
index af3aac4..5619cd9 100755 (executable)
@@ -736,6 +736,7 @@ Dali::Animation Control::Impl::CreateTransition( const Toolkit::TransitionData&
                        visual.GetName().c_str(), typeInfo?typeInfo.GetName().c_str():"Unknown" );
 #endif
         Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
+
         visualImpl.AnimateProperty( transition, *animator );
       }
       else
index 064b13d..3dad561 100755 (executable)
@@ -699,17 +699,20 @@ void Visual::Base::SetupBlendMode( Animation& transition, bool isInitialOpaque,
   // turned off after the animation ends if the final value is opaque
   if( ! isInitialOpaque || mImpl->mMixColor.a < 1.0f )
   {
-    mImpl->mRenderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON );
-
-    if( animating == true && mImpl->mMixColor.a >= 1.0f )
+    if( mImpl->mRenderer )
     {
-      // When it becomes opaque, set the blend mode back to automatically
-      if( ! mImpl->mBlendSlotDelegate )
+      mImpl->mRenderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON );
+
+      if( animating == true && mImpl->mMixColor.a >= 1.0f )
       {
-        mImpl->mBlendSlotDelegate = new SlotDelegate<Visual::Base>(this);
+        // When it becomes opaque, set the blend mode back to automatically
+        if( ! mImpl->mBlendSlotDelegate )
+        {
+          mImpl->mBlendSlotDelegate = new SlotDelegate<Visual::Base>(this);
+        }
+        transition.FinishedSignal().Connect( *(mImpl->mBlendSlotDelegate),
+                                             &Visual::Base::OnMixColorFinished );
       }
-      transition.FinishedSignal().Connect( *(mImpl->mBlendSlotDelegate),
-                                           &Visual::Base::OnMixColorFinished );
     }
   }
 }
index 00c397d..4839551 100644 (file)
@@ -217,6 +217,9 @@ public:
    * If the visual isn't staged (i.e. it doesn't have a renderer),
    * then this will not add an animation.
    *
+   * If the animator is valid and the transition handle is empty - it will
+   * be created.
+   *
    * @param[in] transition The animation to create or attach to
    * @param[in] animator The animation parameters of the property.
    */