Make ImageVisual::Property::PIXEL_AREA animatable 20/299120/1
authorEunki, Hong <eunkiki.hong@samsung.com>
Wed, 20 Sep 2023 06:47:59 +0000 (15:47 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Wed, 20 Sep 2023 07:01:07 +0000 (16:01 +0900)
Since PixelArea was not animatable for visual side,
we cannot animate some cases who register image visual hardly.

This patch make we allow to animate PixelArea at ImageVisual,
instead of ImageView directly.

Change-Id: Ib00b771a2db938cf8ece17ffa4566c7b0b9bb800
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp
dali-toolkit/internal/visuals/image/image-visual.cpp
dali-toolkit/internal/visuals/image/image-visual.h

index 30b0e1e227ef023ebb7452f83677f77e5c64b76f..2186760503c4640abc7a8f155b3914027e31a5a9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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.
@@ -5250,6 +5250,7 @@ int UtcDaliVisualGetVisualProperty03(void)
 
   static std::vector<UniformData> customUniforms =
     {
+      UniformData("pixelArea", Property::Type::VECTOR4),
       UniformData("cornerRadius", Property::Type::VECTOR4),
       UniformData("borderlineWidth", Property::Type::FLOAT),
       UniformData("borderlineColor", Property::Type::VECTOR4),
@@ -5279,6 +5280,7 @@ int UtcDaliVisualGetVisualProperty03(void)
   application.Render();
 
   float   targetOpacity = 0.5f;
+  Vector4 targetPixelArea(0.0f, 1.0f, 2.0f, -0.5f);
   Vector4 targetCornerRadius(20.0f, 20.0f, 0.0f, 0.0f);
   float   targetBorderlineWidth = 10.0f;
   Vector4 targetBorderlineColor(1.0f, 0.0f, 1.0f, 0.5f);
@@ -5286,6 +5288,7 @@ int UtcDaliVisualGetVisualProperty03(void)
 
   Animation animation = Animation::New(1.0f);
   animation.AnimateTo(DevelControl::GetVisualProperty(dummyControl, DummyControl::Property::TEST_VISUAL, Visual::Property::OPACITY), targetOpacity);
+  animation.AnimateTo(DevelControl::GetVisualProperty(dummyControl, DummyControl::Property::TEST_VISUAL, ImageVisual::Property::PIXEL_AREA), targetPixelArea);
   animation.AnimateTo(DevelControl::GetVisualProperty(dummyControl, DummyControl::Property::TEST_VISUAL, DevelVisual::Property::CORNER_RADIUS), targetCornerRadius);
   animation.AnimateTo(DevelControl::GetVisualProperty(dummyControl, DummyControl::Property::TEST_VISUAL, DevelVisual::Property::BORDERLINE_WIDTH), targetBorderlineWidth);
   animation.AnimateTo(DevelControl::GetVisualProperty(dummyControl, DummyControl::Property::TEST_VISUAL, DevelVisual::Property::BORDERLINE_COLOR), targetBorderlineColor);
@@ -5304,6 +5307,10 @@ int UtcDaliVisualGetVisualProperty03(void)
   DALI_TEST_CHECK(colorValue);
   DALI_TEST_EQUALS(colorValue->Get<Vector4>(), Vector4(1.0f, 1.0f, 1.0f, targetOpacity), TEST_LOCATION);
 
+  Property::Value* pixelAreaValue = resultMap.Find(ImageVisual::Property::PIXEL_AREA, Property::VECTOR4);
+  DALI_TEST_CHECK(pixelAreaValue);
+  DALI_TEST_EQUALS(pixelAreaValue->Get<Vector4>(), targetPixelArea, TEST_LOCATION);
+
   Property::Value* cornerRadiusValue = resultMap.Find(DevelVisual::Property::CORNER_RADIUS, Property::VECTOR4);
   DALI_TEST_CHECK(cornerRadiusValue);
   DALI_TEST_EQUALS(cornerRadiusValue->Get<Vector4>(), targetCornerRadius, TEST_LOCATION);
@@ -5321,11 +5328,15 @@ int UtcDaliVisualGetVisualProperty03(void)
   DALI_TEST_EQUALS(borderlineOffsetValue->Get<float>(), targetBorderlineOffset, TEST_LOCATION);
 
   // Test uniform value
+  DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", targetPixelArea), true, TEST_LOCATION);
   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("cornerRadius", targetCornerRadius), true, TEST_LOCATION);
   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<float>("borderlineWidth", targetBorderlineWidth), true, TEST_LOCATION);
   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("borderlineColor", targetBorderlineColor), true, TEST_LOCATION);
   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<float>("borderlineOffset", targetBorderlineOffset), true, TEST_LOCATION);
 
+  // Test non-animatable index, for coverage.
+  DALI_TEST_EQUALS(DevelControl::GetVisualProperty(dummyControl, DummyControl::Property::TEST_VISUAL, ImageVisual::Property::URL).propertyIndex, Property::INVALID_INDEX, TEST_LOCATION);
+
   END_TEST;
 }
 
index 2f0e800cd5aa88a372f8b8d27c8bcfeb626b16f6..e6e07e8afdd08deee1114e9dc04c437874dd66a1 100644 (file)
@@ -152,6 +152,7 @@ ImageVisual::ImageVisual(VisualFactoryCache&       factoryCache,
                          Dali::SamplingMode::Type  samplingMode)
 : Visual::Base(factoryCache, Visual::FittingMode::FILL, Toolkit::Visual::IMAGE),
   mPixelArea(FULL_TEXTURE_RECT),
+  mPixelAreaIndex(Property::INVALID_INDEX),
   mPlacementActor(),
   mImageUrl(imageUrl),
   mMaskingData(),
@@ -372,6 +373,13 @@ void ImageVisual::DoSetProperty(Property::Index index, const Property::Value& va
     case Toolkit::ImageVisual::Property::PIXEL_AREA:
     {
       value.Get(mPixelArea);
+
+      if(DALI_UNLIKELY(mImpl->mRenderer))
+      {
+        // Unusual case. SetProperty called after OnInitialize().
+        // Assume that DoAction call UPDATE_PROPERTY.
+        mPixelAreaIndex = mImpl->mRenderer.RegisterProperty(mPixelAreaIndex, PIXEL_AREA_UNIFORM_NAME, mPixelArea);
+      }
       break;
     }
 
@@ -864,7 +872,7 @@ void ImageVisual::DoSetOnScene(Actor& actor)
 
   if(mPixelArea != FULL_TEXTURE_RECT)
   {
-    mImpl->mRenderer.RegisterProperty(PIXEL_AREA_UNIFORM_NAME, mPixelArea);
+    mPixelAreaIndex = mImpl->mRenderer.RegisterProperty(mPixelAreaIndex, PIXEL_AREA_UNIFORM_NAME, mPixelArea);
   }
 
   if(mLoadState == TextureManager::LoadState::LOAD_FINISHED)
@@ -924,7 +932,17 @@ void ImageVisual::DoCreatePropertyMap(Property::Map& map) const
   map.Insert(Toolkit::ImageVisual::Property::FITTING_MODE, mFittingMode);
   map.Insert(Toolkit::ImageVisual::Property::SAMPLING_MODE, mSamplingMode);
 
-  map.Insert(Toolkit::ImageVisual::Property::PIXEL_AREA, mPixelArea);
+  if(mImpl->mRenderer && mPixelAreaIndex != Property::INVALID_INDEX)
+  {
+    // Update values from Renderer
+    Vector4 pixelArea = mImpl->mRenderer.GetProperty<Vector4>(mPixelAreaIndex);
+    map.Insert(Toolkit::ImageVisual::Property::PIXEL_AREA, pixelArea);
+  }
+  else
+  {
+    map.Insert(Toolkit::ImageVisual::Property::PIXEL_AREA, mPixelArea);
+  }
+
   map.Insert(Toolkit::ImageVisual::Property::WRAP_MODE_U, mWrapModeU);
   map.Insert(Toolkit::ImageVisual::Property::WRAP_MODE_V, mWrapModeV);
 
@@ -1329,6 +1347,24 @@ Shader ImageVisual::GenerateShader() const
   return shader;
 }
 
+Dali::Property ImageVisual::OnGetPropertyObject(Dali::Property::Key key)
+{
+  if((key.type == Property::Key::INDEX && key.indexKey == Toolkit::ImageVisual::Property::PIXEL_AREA) || (key.type == Property::Key::STRING && key.stringKey == PIXEL_AREA_UNIFORM_NAME))
+  {
+    if(DALI_LIKELY(mImpl->mRenderer))
+    {
+      if(mPixelAreaIndex == Property::INVALID_INDEX)
+      {
+        mPixelAreaIndex = mImpl->mRenderer.RegisterProperty(mPixelAreaIndex, PIXEL_AREA_UNIFORM_NAME, mPixelArea);
+      }
+      return Dali::Property(mImpl->mRenderer, mPixelAreaIndex);
+    }
+  }
+
+  Handle handle;
+  return Dali::Property(handle, Property::INVALID_INDEX);
+}
+
 void ImageVisual::CheckMaskTexture()
 {
   if(mMaskingData && !mMaskingData->mPreappliedMasking)
index 7358f8a27dd9a5ae3bcd64e9e05c91b34c28feb3..0770f034715fb725be908423b32e0a4b13bb5670 100644 (file)
@@ -235,6 +235,11 @@ protected:
    */
   Shader GenerateShader() const override;
 
+  /**
+   * @copydoc Visual::Base::OnGetPropertyObject
+   */
+  Dali::Property OnGetPropertyObject(Dali::Property::Key key) override;
+
 public:
   /**
    * @copydoc AtlasUploadObserver::UploadCompleted
@@ -349,6 +354,7 @@ private:
 
 private:
   Vector4                            mPixelArea;
+  Property::Index                    mPixelAreaIndex;
   WeakHandle<Actor>                  mPlacementActor;
   VisualUrl                          mImageUrl;
   TextureManager::MaskingDataPointer mMaskingData;