FittingMode Refactoring 12/307712/19
authorsunghyun kim <scholb.kim@samsung.com>
Tue, 12 Mar 2024 10:06:42 +0000 (19:06 +0900)
committersunghyun kim <scholb.kim@samsung.com>
Wed, 29 May 2024 01:28:35 +0000 (10:28 +0900)
1. Transfer the function implemented in ImageView to the control side
2. Reduce the desired calculation part implemented in the NUI ImageView side to dali.
3. Remove the part where the file was opened to obtain the original image size in the process

Change-Id: Ifbd260b14477c2f327b82b9310a084da689d06fd

27 files changed:
automated-tests/src/dali-toolkit/utc-Dali-AnimatedImageVisual.cpp
automated-tests/src/dali-toolkit/utc-Dali-ImageView.cpp
dali-toolkit/devel-api/visuals/visual-properties-devel.h
dali-toolkit/internal/controls/control/control-data-impl.cpp
dali-toolkit/internal/controls/control/control-data-impl.h
dali-toolkit/internal/controls/image-view/image-view-impl.cpp
dali-toolkit/internal/controls/image-view/image-view-impl.h
dali-toolkit/internal/visuals/animated-gradient/animated-gradient-visual.cpp
dali-toolkit/internal/visuals/animated-image/animated-image-visual.cpp
dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.cpp
dali-toolkit/internal/visuals/arc/arc-visual.cpp
dali-toolkit/internal/visuals/border/border-visual.cpp
dali-toolkit/internal/visuals/color/color-visual.cpp
dali-toolkit/internal/visuals/gradient/gradient-visual.cpp
dali-toolkit/internal/visuals/image/image-visual.cpp
dali-toolkit/internal/visuals/image/image-visual.h
dali-toolkit/internal/visuals/mesh/mesh-visual.cpp
dali-toolkit/internal/visuals/npatch/npatch-visual.cpp
dali-toolkit/internal/visuals/primitive/primitive-visual.cpp
dali-toolkit/internal/visuals/svg/svg-visual.cpp
dali-toolkit/internal/visuals/text/text-visual.cpp
dali-toolkit/internal/visuals/visual-base-data-impl.cpp
dali-toolkit/internal/visuals/visual-base-data-impl.h
dali-toolkit/internal/visuals/visual-base-impl.cpp
dali-toolkit/internal/visuals/visual-base-impl.h
dali-toolkit/internal/visuals/wireframe/wireframe-visual.cpp
dali-toolkit/public-api/controls/control-impl.cpp

index ba02befb388e65e259ef505c878ac9cec385b807..835b271609a96ac1bc614738643fb90139380f57 100644 (file)
@@ -1937,6 +1937,10 @@ int UtcDaliAnimatedImageVisualDesiredSize(void)
   int desiredWidth  = 15;
   int desiredHeight = 20;
 
+  // texture size have to keep it's ratio. So, the size of texture should be 20x20.
+  const int resultWidth = 20;
+  const int resultHeight = 20;
+
   Visual::Base visual = VisualFactory::Get().CreateVisual(TEST_GIF_FILE_NAME, ImageDimensions(desiredWidth, desiredHeight));
   DALI_TEST_CHECK(visual);
 
@@ -1960,7 +1964,7 @@ int UtcDaliAnimatedImageVisualDesiredSize(void)
 
   {
     std::stringstream out;
-    out << GL_TEXTURE_2D << ", " << 0u << ", " << desiredWidth << ", " << desiredHeight;
+    out << GL_TEXTURE_2D << ", " << 0u << ", " << resultWidth << ", " << resultHeight;
     DALI_TEST_CHECK(textureTrace.FindMethodAndParams("TexImage2D", out.str().c_str()));
   }
 
@@ -1987,8 +1991,8 @@ int UtcDaliAnimatedImageVisualDesiredSize(void)
 
   {
     std::stringstream out;
-    out << GL_TEXTURE_2D << ", " << 0u << ", " << desiredWidth << ", " << desiredHeight;
-    DALI_TEST_CHECK(textureTrace.FindMethodAndParams("TexImage2D", out.str().c_str())); // The size should not be changed
+    out << GL_TEXTURE_2D << ", " << 0u << ", " << resultWidth << ", " << resultHeight;
+    DALI_TEST_CHECK(textureTrace.FindMethodAndParams("TexImage2D", out.str().c_str())); // The size should be changed for keeping the aspect ratio.
   }
 
   END_TEST;
index efc772ddd6e8ea011463dfda557f6073e802a955..ea8a7ca07ab0dd283a9717ffdd0b0eec6728394e 100644 (file)
@@ -1194,7 +1194,7 @@ void ResourceReadySignal(Control control)
 
 void OnResourceReadySignalSVG(Control control)
 {
-  // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
+  // Check whether Image Visual transforms on ImageView::OnRelayout()
   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(control);
   Toolkit::Visual::Base       imageVisual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
   Property::Map               resultMap;
@@ -1205,8 +1205,8 @@ void OnResourceReadySignalSVG(Control control)
   Property::Map* retMap = transformValue->GetMap();
   DALI_TEST_CHECK(retMap);
 
-  // Fitting mode should not be applied at this point
-  DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::SIZE)->Get<Vector2>(), Vector2::ZERO, TEST_LOCATION);
+  // Fitting mode is applied at this point. because we do FittingMode in control
+  DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::SIZE)->Get<Vector2>(), Vector2::ONE, TEST_LOCATION);
 }
 
 int UtcDaliImageViewCheckResourceReady(void)
index 679a31f12ce273fd5e25f07f04dbdf99f9b00ba2..12e2e2139c1822ce72aca1a4418855b615e1fe65 100644 (file)
@@ -132,7 +132,8 @@ enum FittingMode
   OVER_FIT_KEEP_ASPECT_RATIO, ///< The visual should be scaled to fit, preserving aspect ratio. The visual will be filled without empty area, and outside is cropped away.
   CENTER,                     ///< The visual should keep original size of image. It is not scaled and not strecthed.
   FIT_HEIGHT,                 ///< The visual should be scaled to fit, preserving aspect ratio. Height is scaled proportionately to maintain aspect ratio. It will be deprecated.
-  FIT_WIDTH                   ///< The visual should be scaled to fit, preserving aspect ratio. Width is scaled proportionately to maintain aspect ratio. It will be deprecated.
+  FIT_WIDTH,                  ///< The visual should be scaled to fit, preserving aspect ratio. Width is scaled proportionately to maintain aspect ratio. It will be deprecated.
+  DONT_CARE                   ///< The visual should be not use fittingMode.
 };
 
 /**
index 4e99e5ce1220d77ca8f6b27a4220d927f0b0163b..1cb7b3c93d9eb689a974e5036c1619c268f8ca6f 100644 (file)
@@ -49,6 +49,7 @@
 #include <dali-toolkit/public-api/focus-manager/keyboard-focus-manager.h>
 #include <dali-toolkit/public-api/visuals/image-visual-properties.h>
 #include <dali-toolkit/public-api/visuals/visual-properties.h>
+#include <dali-toolkit/public-api/align-enumerations.h>
 
 namespace
 {
@@ -76,6 +77,7 @@ const Scripting::StringEnum ControlStateTable[] = {
   {"DISABLED", Toolkit::DevelControl::DISABLED},
 };
 const unsigned int ControlStateTableCount = sizeof(ControlStateTable) / sizeof(ControlStateTable[0]);
+const Vector4 FULL_TEXTURE_RECT(0.f, 0.f, 1.f, 1.f);
 
 namespace
 {
@@ -554,6 +556,7 @@ Control::Impl::Impl(Control& controlImpl)
   mStartingPinchScale(nullptr),
   mMargin(0, 0, 0, 0),
   mPadding(0, 0, 0, 0),
+  mSize(0, 0),
   mKeyEventSignal(),
   mKeyInputFocusGainedSignal(),
   mKeyInputFocusLostSignal(),
@@ -574,7 +577,8 @@ Control::Impl::Impl(Control& controlImpl)
   mIsKeyboardFocusGroup(false),
   mIsEmittingResourceReadySignal(false),
   mIdleCallbackRegistered(false),
-  mDispatchKeyEvents(true)
+  mDispatchKeyEvents(true),
+  mProcessorRegistered(false)
 {
   Dali::Accessibility::Accessible::RegisterExternalAccessibleGetter(&ExternalAccessibleGetter);
 }
@@ -594,6 +598,12 @@ Control::Impl::~Impl()
   // All gesture detectors will be destroyed so no need to disconnect.
   delete mStartingPinchScale;
 
+  if(mProcessorRegistered && Adaptor::IsAvailable())
+  {
+    // Unregister the processor from the adaptor
+    Adaptor::Get().UnregisterProcessorOnce(*this, true);
+  }
+
   if(mIdleCallback && Adaptor::IsAvailable())
   {
     // Removes the callback from the callback manager in case the control is destroyed before the callback is executed.
@@ -2308,6 +2318,197 @@ bool Control::Impl::IsCreateAccessibleEnabled() const
   return mAccessibleCreatable;
 }
 
+void Control::Impl::ApplyFittingMode(const Vector2& size)
+{
+  Actor self = mControlImpl.Self();
+  for(RegisteredVisualContainer::Iterator iter = mVisuals.Begin(); iter != mVisuals.End(); iter++)
+  {
+    // Check whether the visual is empty and enabled
+    if((*iter)->visual && (*iter)->enabled)
+    {
+      Internal::Visual::Base& visualImpl = Toolkit::GetImplementation((*iter)->visual);
+
+      // If the current visual is using the transform property map, fittingMode will not be applied.
+      if(visualImpl.IsIgnoreFittingMode())
+      {
+        continue;
+      }
+
+      Visual::FittingMode fittingMode = visualImpl.GetFittingMode();
+      Property::Map transformMap = Property::Map();
+
+      // If the fittingMode is DONT_CARE, we don't need to apply fittingMode, just Set empty transformMap
+      if(fittingMode == Visual::FittingMode::DONT_CARE)
+      {
+        ((*iter)->visual).SetTransformAndSize(transformMap, size);
+        continue;
+      }
+
+      Extents padding = self.GetProperty<Extents>(Toolkit::Control::Property::PADDING);
+
+      bool zeroPadding = (padding == Extents());
+
+      Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>(
+      self.GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
+      if(Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection)
+      {
+        std::swap(padding.start, padding.end);
+      }
+
+      // remove padding from the size to know how much is left for the visual
+      Vector2 finalSize   = size - Vector2(padding.start + padding.end, padding.top + padding.bottom);
+      Vector2 finalOffset = Vector2(padding.start, padding.top);
+
+      // Reset PIXEL_AREA after using OVER_FIT_KEEP_ASPECT_RATIO
+      if(visualImpl.IsPixelAreaSetForFittingMode())
+      {
+        visualImpl.SetPixelAreaForFittingMode(FULL_TEXTURE_RECT);
+      }
+
+      if((!zeroPadding) || // If padding is not zero
+        (fittingMode != Visual::FittingMode::FILL))
+      {
+        visualImpl.SetTransformMapUsageForFittingMode(true);
+
+        Vector2 naturalSize;
+        // NaturalSize will not be used for FILL fitting mode, which is default.
+        // Skip GetNaturalSize
+        if(fittingMode != Visual::FittingMode::FILL)
+        {
+          ((*iter)->visual).GetNaturalSize(naturalSize);
+        }
+
+        // If FittingMode use FIT_WIDTH or FIT_HEIGTH, it need to change proper fittingMode
+        if(fittingMode == Visual::FittingMode::FIT_WIDTH)
+        {
+          fittingMode = (finalSize.height / naturalSize.height) < (finalSize.width / naturalSize.width) ? Visual::FittingMode::OVER_FIT_KEEP_ASPECT_RATIO : Visual::FittingMode::FIT_KEEP_ASPECT_RATIO;
+        }
+        else if(fittingMode == Visual::FittingMode::FIT_HEIGHT)
+        {
+          fittingMode = (finalSize.height / naturalSize.height) < (finalSize.width / naturalSize.width) ? Visual::FittingMode::FIT_KEEP_ASPECT_RATIO : Visual::FittingMode::OVER_FIT_KEEP_ASPECT_RATIO;
+        }
+
+        // Calculate size for fittingMode
+        switch(fittingMode)
+        {
+          case Visual::FittingMode::FIT_KEEP_ASPECT_RATIO:
+          {
+            auto availableVisualSize = finalSize;
+
+            // scale to fit the padded area
+            finalSize = naturalSize * std::min((!Dali::EqualsZero(naturalSize.width) ? (availableVisualSize.width / naturalSize.width) : 0),
+                                              (!Dali::EqualsZero(naturalSize.height) ? (availableVisualSize.height / naturalSize.height) : 0));
+
+            // calculate final offset within the padded area
+            finalOffset += (availableVisualSize - finalSize) * .5f;
+
+            // populate the transform map
+            transformMap.Add(Toolkit::Visual::Transform::Property::OFFSET, finalOffset)
+              .Add(Toolkit::Visual::Transform::Property::SIZE, finalSize);
+            break;
+          }
+          case Visual::FittingMode::OVER_FIT_KEEP_ASPECT_RATIO:
+          {
+            auto availableVisualSize            = finalSize;
+            finalSize                           = naturalSize * std::max((!Dali::EqualsZero(naturalSize.width) ? (availableVisualSize.width / naturalSize.width) : 0.0f),
+                                              (!Dali::EqualsZero(naturalSize.height) ? (availableVisualSize.height / naturalSize.height) : 0.0f));
+
+            auto originalOffset = finalOffset;
+            finalOffset += (availableVisualSize - finalSize) * .5f;
+
+            float   x           = abs((availableVisualSize.width - finalSize.width) / finalSize.width) * .5f;
+            float   y           = abs((availableVisualSize.height - finalSize.height) / finalSize.height) * .5f;
+            float   widthRatio  = 1.f - abs((availableVisualSize.width - finalSize.width) / finalSize.width);
+            float   heightRatio = 1.f - abs((availableVisualSize.height - finalSize.height) / finalSize.height);
+            Vector4 pixelArea   = Vector4(x, y, widthRatio, heightRatio);
+
+            if(!visualImpl.IsPixelAreaSetForFittingMode())
+            {
+              visualImpl.SetPixelAreaForFittingMode(pixelArea);
+            }
+
+            // populate the transform map
+            transformMap.Add(Toolkit::Visual::Transform::Property::OFFSET, originalOffset)
+              .Add(Toolkit::Visual::Transform::Property::SIZE, availableVisualSize);
+            break;
+          }
+          case Visual::FittingMode::CENTER:
+          {
+            auto availableVisualSize = finalSize;
+            if(availableVisualSize.width > naturalSize.width && availableVisualSize.height > naturalSize.height)
+            {
+              finalSize = naturalSize;
+            }
+            else
+            {
+              finalSize = naturalSize * std::min((!Dali::EqualsZero(naturalSize.width) ? (availableVisualSize.width / naturalSize.width) : 0.0f),
+                                                (!Dali::EqualsZero(naturalSize.height) ? (availableVisualSize.height / naturalSize.height) : 0.0f));
+            }
+
+            finalOffset += (availableVisualSize - finalSize) * .5f;
+
+            // populate the transform map
+            transformMap.Add(Toolkit::Visual::Transform::Property::OFFSET, finalOffset)
+              .Add(Toolkit::Visual::Transform::Property::SIZE, finalSize);
+            break;
+          }
+          case Visual::FittingMode::FILL:
+          {
+            transformMap.Add(Toolkit::Visual::Transform::Property::OFFSET, finalOffset)
+              .Add(Toolkit::Visual::Transform::Property::SIZE, finalSize);
+            break;
+          }
+          case Visual::FittingMode::FIT_WIDTH:
+          case Visual::FittingMode::FIT_HEIGHT:
+          case Visual::FittingMode::DONT_CARE:
+          {
+            // This FittingMode already converted
+            break;
+          }
+        }
+
+        // Set extra value for applying transformMap
+        transformMap.Add(Toolkit::Visual::Transform::Property::OFFSET_POLICY,
+                        Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE))
+          .Add(Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN)
+          .Add(Toolkit::Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::TOP_BEGIN)
+          .Add(Toolkit::Visual::Transform::Property::SIZE_POLICY,
+              Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE));
+      }
+      else if(visualImpl.IsTransformMapSetForFittingMode() && zeroPadding) // Reset offset to zero only if padding applied previously
+      {
+        visualImpl.SetTransformMapUsageForFittingMode(false);
+
+        // Reset the transform map
+        transformMap.Add(Toolkit::Visual::Transform::Property::OFFSET, Vector2::ZERO)
+          .Add(Toolkit::Visual::Transform::Property::OFFSET_POLICY,
+              Vector2(Toolkit::Visual::Transform::Policy::RELATIVE, Toolkit::Visual::Transform::Policy::RELATIVE))
+          .Add(Toolkit::Visual::Transform::Property::SIZE, Vector2::ONE)
+          .Add(Toolkit::Visual::Transform::Property::SIZE_POLICY,
+              Vector2(Toolkit::Visual::Transform::Policy::RELATIVE, Toolkit::Visual::Transform::Policy::RELATIVE));
+      }
+
+      ((*iter)->visual).SetTransformAndSize(transformMap, size);
+    }
+  }
+}
+
+void Control::Impl::RegisterProcessorOnce()
+{
+  if(!mProcessorRegistered)
+  {
+    Adaptor::Get().RegisterProcessorOnce(*this, true);
+    mProcessorRegistered = true;
+  }
+}
+
+void Control::Impl::Process(bool postProcessor)
+{
+  // Call ApplyFittingMode
+  ApplyFittingMode(mSize);
+  mProcessorRegistered = false;
+}
+
 } // namespace Internal
 
 } // namespace Toolkit
index ed38e3fdd3a2947a67f3dfffddbda88f4f2c0b86..064176441135b590acf8dc57d9e26517e304270c 100644 (file)
@@ -22,6 +22,7 @@
 #include <dali/devel-api/adaptor-framework/accessibility.h>
 #include <dali/public-api/object/property-notification.h>
 #include <dali/public-api/object/type-registry.h>
+#include <dali/integration-api/processor-interface.h>
 #include <string>
 
 // INTERNAL INCLUDES
@@ -72,7 +73,7 @@ typedef Dali::OwnerContainer<RegisteredVisual*> RegisteredVisualContainer;
 /**
  * @brief Holds the Implementation for the internal control class
  */
-class Control::Impl : public ConnectionTracker, public Visual::EventObserver
+class Control::Impl : public ConnectionTracker, public Visual::EventObserver, public Integration::Processor
 {
   friend class Toolkit::DevelControl::ControlAccessible;
 
@@ -471,6 +472,32 @@ public:
    */
   bool IsCreateAccessibleEnabled() const;
 
+  /**
+   * @brief Apply fittingMode
+   *
+   * @param[in] size The size of the control
+   */
+  void ApplyFittingMode(const Vector2& size);
+
+  /**
+   * @brief Register processor
+  */
+  void RegisterProcessorOnce();
+
+protected: // From processor-interface
+  /**
+   * @copydoc Dali::Integration::Processor::Process()
+   */
+  void Process(bool postProcessor) override;
+
+  /**
+   * @copydoc Dali::Integration::Processor::GetProcessorName()
+   */
+  std::string_view GetProcessorName() const override
+  {
+    return "ControlDataImpl";
+  }
+
 private:
   /**
    * Used as an alternative to boolean so that it is obvious whether a visual is enabled/disabled.
@@ -576,6 +603,7 @@ public:
   Vector3*                                  mStartingPinchScale; ///< The scale when a pinch gesture starts, TODO: consider removing this
   Extents                                   mMargin;             ///< The margin values
   Extents                                   mPadding;            ///< The padding values
+  Vector2                                   mSize;               ///< The size of the control
   Toolkit::Control::KeyEventSignalType      mKeyEventSignal;
   Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusGainedSignal;
   Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusLostSignal;
@@ -626,6 +654,7 @@ public:
   bool             mIsEmittingResourceReadySignal : 1;    ///< True during ResourceReady().
   bool             mIdleCallbackRegistered : 1;           ///< True if need to emit the resource ready signal again.
   bool             mDispatchKeyEvents : 1;                ///< Whether the actor emits key event signals
+  bool             mProcessorRegistered : 1;              ///< Whether the processor is registered.
 
   RegisteredVisualContainer mRemoveVisuals; ///< List of visuals that are being replaced by another visual once ready
 
index 200aebf106f0078927ccf0155efd4db56c911430..91e33df1ed6e43da01f8c2bdd0500aaa9039b124 100644 (file)
@@ -44,10 +44,8 @@ namespace Internal
 {
 namespace
 {
-const Vector4 FULL_TEXTURE_RECT(0.f, 0.f, 1.f, 1.f);
-
-constexpr float FULL_OPACITY            = 1.0f;
-constexpr float LOW_OPACITY             = 0.2f;
+constexpr float FULL_OPACITY = 1.0f;
+constexpr float LOW_OPACITY  = 0.2f;
 constexpr float TRANSITION_EFFECT_SPEED = 0.3f;
 
 constexpr int PLACEHOLDER_DEPTH_INDEX     = -2;
@@ -77,10 +75,7 @@ ImageView::ImageView(ControlBehaviour additionalBehaviour)
 : Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT | additionalBehaviour)),
   mImageSize(),
   mTransitionTargetAlpha(FULL_OPACITY),
-  mImageVisualPaddingSetByTransform(false),
-  mImageViewPixelAreaSetByFittingMode(false),
   mTransitionEffect(false),
-  mNeedLazyFittingMode(false),
   mImageReplaced(false)
 {
 }
@@ -163,6 +158,12 @@ void ImageView::SetImage(const Property::Map& map)
   Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual(mPropertyMap);
   if(visual)
   {
+    Internal::Visual::Base& visualImpl = Toolkit::GetImplementation(visual);
+    if(visualImpl.GetFittingMode() == Visual::FittingMode::DONT_CARE)
+    {
+      visualImpl.SetFittingMode(Visual::FittingMode::FILL);
+    }
+
     // Don't set mVisual until it is ready and shown. Getters will still use current visual.
     if(!mVisual)
     {
@@ -171,7 +172,6 @@ void ImageView::SetImage(const Property::Map& map)
 
     if(!mShaderMap.Empty())
     {
-      Internal::Visual::Base& visualImpl = Toolkit::GetImplementation(visual);
       visualImpl.SetCustomShader(mShaderMap);
     }
 
@@ -228,6 +228,12 @@ void ImageView::SetImage(const std::string& url, ImageDimensions size)
   Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual(url, size);
   if(visual)
   {
+    Internal::Visual::Base& visualImpl = Toolkit::GetImplementation(visual);
+    if(visualImpl.GetFittingMode() == Visual::FittingMode::DONT_CARE)
+    {
+      visualImpl.SetFittingMode(Visual::FittingMode::FILL);
+    }
+
     if(!mVisual)
     {
       mVisual = visual;
@@ -235,7 +241,6 @@ void ImageView::SetImage(const std::string& url, ImageDimensions size)
 
     if(!mShaderMap.Empty())
     {
-      Internal::Visual::Base& visualImpl = Toolkit::GetImplementation(visual);
       visualImpl.SetCustomShader(mShaderMap);
     }
 
@@ -387,16 +392,6 @@ void ImageView::OnRelayout(const Vector2& size, RelayoutContainer& container)
   Control::OnRelayout(size, container);
   if(mVisual)
   {
-    // If Resource is not ready, fittingMode is not working well.
-    // in this case, imageview set the flag for working applyFittingMode again when the resource is ready
-    if(!IsResourceReady())
-    {
-      mNeedLazyFittingMode = true;
-    }
-
-    // Apply FittingMode using actor's size
-    ApplyFittingMode(size);
-
     // mVisual is not updated util the resource is ready in the case of visual replacement.
     // in this case, the Property Map must be initialized so that the previous value is not reused.
     // after mVisual is updated, the correct value will be reset.
@@ -471,170 +466,9 @@ void ImageView::OnResourceReady(Toolkit::Control control)
   // Visual ready so update visual attached to this ImageView, following call to RelayoutRequest will use this visual.
   mVisual = DevelControl::GetVisual(*this, Toolkit::ImageView::Property::IMAGE);
 
-  // Applying FittingMode again if it is not working well on OnRelayout().
-  if(mNeedLazyFittingMode)
-  {
-    const Vector2& size = Self().GetProperty(Dali::Actor::Property::SIZE).Get<Vector2>();
-    ApplyFittingMode(size);
-    mNeedLazyFittingMode = false;
-  }
-
   // Signal that a Relayout may be needed
 }
 
-void ImageView::SetTransformMapForFittingMode(Vector2 finalSize, Vector2 naturalSize, Vector2 finalOffset, Visual::FittingMode fittingMode, Property::Map& transformMap)
-{
-  switch(fittingMode)
-  {
-    case Visual::FittingMode::FIT_KEEP_ASPECT_RATIO:
-    {
-      auto availableVisualSize = finalSize;
-
-      // scale to fit the padded area
-      finalSize = naturalSize * std::min((!Dali::EqualsZero(naturalSize.width) ? (availableVisualSize.width / naturalSize.width) : 0),
-                                         (!Dali::EqualsZero(naturalSize.height) ? (availableVisualSize.height / naturalSize.height) : 0));
-
-      // calculate final offset within the padded area
-      finalOffset += (availableVisualSize - finalSize) * .5f;
-
-      // populate the transform map
-      transformMap.Add(Toolkit::Visual::Transform::Property::OFFSET, finalOffset)
-        .Add(Toolkit::Visual::Transform::Property::SIZE, finalSize);
-      break;
-    }
-    case Visual::FittingMode::OVER_FIT_KEEP_ASPECT_RATIO:
-    {
-      mImageViewPixelAreaSetByFittingMode = true;
-      auto availableVisualSize            = finalSize;
-      finalSize                           = naturalSize * std::max((!Dali::EqualsZero(naturalSize.width) ? (availableVisualSize.width / naturalSize.width) : 0.0f),
-                                         (!Dali::EqualsZero(naturalSize.height) ? (availableVisualSize.height / naturalSize.height) : 0.0f));
-
-      auto originalOffset = finalOffset;
-      finalOffset += (availableVisualSize - finalSize) * .5f;
-
-      float   x           = abs((availableVisualSize.width - finalSize.width) / finalSize.width) * .5f;
-      float   y           = abs((availableVisualSize.height - finalSize.height) / finalSize.height) * .5f;
-      float   widthRatio  = 1.f - abs((availableVisualSize.width - finalSize.width) / finalSize.width);
-      float   heightRatio = 1.f - abs((availableVisualSize.height - finalSize.height) / finalSize.height);
-      Vector4 pixelArea   = Vector4(x, y, widthRatio, heightRatio);
-      Self().SetProperty(Toolkit::ImageView::Property::PIXEL_AREA, pixelArea);
-
-      // populate the transform map
-      transformMap.Add(Toolkit::Visual::Transform::Property::OFFSET, originalOffset)
-        .Add(Toolkit::Visual::Transform::Property::SIZE, availableVisualSize);
-      break;
-    }
-    case Visual::FittingMode::CENTER:
-    {
-      auto availableVisualSize = finalSize;
-      if(availableVisualSize.width > naturalSize.width && availableVisualSize.height > naturalSize.height)
-      {
-        finalSize = naturalSize;
-      }
-      else
-      {
-        finalSize = naturalSize * std::min((!Dali::EqualsZero(naturalSize.width) ? (availableVisualSize.width / naturalSize.width) : 0.0f),
-                                           (!Dali::EqualsZero(naturalSize.height) ? (availableVisualSize.height / naturalSize.height) : 0.0f));
-      }
-
-      finalOffset += (availableVisualSize - finalSize) * .5f;
-
-      // populate the transform map
-      transformMap.Add(Toolkit::Visual::Transform::Property::OFFSET, finalOffset)
-        .Add(Toolkit::Visual::Transform::Property::SIZE, finalSize);
-      break;
-    }
-    case Visual::FittingMode::FILL:
-    {
-      transformMap.Add(Toolkit::Visual::Transform::Property::OFFSET, finalOffset)
-        .Add(Toolkit::Visual::Transform::Property::SIZE, finalSize);
-      break;
-    }
-    case Visual::FittingMode::FIT_WIDTH:
-    case Visual::FittingMode::FIT_HEIGHT:
-    {
-      // This FittingMode already converted
-      break;
-    }
-  }
-}
-
-void ImageView::ApplyFittingMode(const Vector2& size)
-{
-  Property::Map transformMap = Property::Map();
-
-  Extents padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
-
-  bool zeroPadding = (padding == Extents());
-
-  Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>(
-    Self().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
-  if(Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection)
-  {
-    std::swap(padding.start, padding.end);
-  }
-
-  // remove padding from the size to know how much is left for the visual
-  Vector2 finalSize   = size - Vector2(padding.start + padding.end, padding.top + padding.bottom);
-  Vector2 finalOffset = Vector2(padding.start, padding.top);
-
-  Visual::FittingMode fittingMode = Toolkit::GetImplementation(mVisual).GetFittingMode();
-
-  // Reset PIXEL_AREA after using OVER_FIT_KEEP_ASPECT_RATIO
-  if(mImageViewPixelAreaSetByFittingMode)
-  {
-    Self().SetProperty(Toolkit::ImageView::Property::PIXEL_AREA, FULL_TEXTURE_RECT);
-    mImageViewPixelAreaSetByFittingMode = false;
-  }
-
-  if((!zeroPadding) || // If padding is not zero
-     (fittingMode != Visual::FittingMode::FILL))
-  {
-    mImageVisualPaddingSetByTransform = true;
-
-    Vector2 naturalSize;
-    // NaturalSize will not be used for FILL fitting mode, which is default.
-    // Skip GetNaturalSize
-    if(fittingMode != Visual::FittingMode::FILL)
-    {
-      mVisual.GetNaturalSize(naturalSize);
-    }
-
-    // If FittingMode use FIT_WIDTH or FIT_HEIGTH, it need to change proper fittingMode
-    if(fittingMode == Visual::FittingMode::FIT_WIDTH)
-    {
-      fittingMode = (finalSize.height / naturalSize.height) < (finalSize.width / naturalSize.width) ? Visual::FittingMode::OVER_FIT_KEEP_ASPECT_RATIO : Visual::FittingMode::FIT_KEEP_ASPECT_RATIO;
-    }
-    else if(fittingMode == Visual::FittingMode::FIT_HEIGHT)
-    {
-      fittingMode = (finalSize.height / naturalSize.height) < (finalSize.width / naturalSize.width) ? Visual::FittingMode::FIT_KEEP_ASPECT_RATIO : Visual::FittingMode::OVER_FIT_KEEP_ASPECT_RATIO;
-    }
-
-    SetTransformMapForFittingMode(finalSize, naturalSize, finalOffset, fittingMode, transformMap);
-
-    // Set extra value for applying transformMap
-    transformMap.Add(Toolkit::Visual::Transform::Property::OFFSET_POLICY,
-                     Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE))
-      .Add(Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN)
-      .Add(Toolkit::Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::TOP_BEGIN)
-      .Add(Toolkit::Visual::Transform::Property::SIZE_POLICY,
-           Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE));
-  }
-  else if(mImageVisualPaddingSetByTransform && zeroPadding) // Reset offset to zero only if padding applied previously
-  {
-    mImageVisualPaddingSetByTransform = false;
-    // Reset the transform map
-    transformMap.Add(Toolkit::Visual::Transform::Property::OFFSET, Vector2::ZERO)
-      .Add(Toolkit::Visual::Transform::Property::OFFSET_POLICY,
-           Vector2(Toolkit::Visual::Transform::Policy::RELATIVE, Toolkit::Visual::Transform::Policy::RELATIVE))
-      .Add(Toolkit::Visual::Transform::Property::SIZE, Vector2::ONE)
-      .Add(Toolkit::Visual::Transform::Property::SIZE_POLICY,
-           Vector2(Toolkit::Visual::Transform::Policy::RELATIVE, Toolkit::Visual::Transform::Policy::RELATIVE));
-  }
-
-  mVisual.SetTransformAndSize(transformMap, size);
-}
-
 void ImageView::CreatePlaceholderImage()
 {
   Property::Map propertyMap;
index a4cf2e704a5a9fd81db3957a106f31700ee1ef62..8deb323958ad9c9ba836863acb0675c6a8c81662 100644 (file)
@@ -194,21 +194,6 @@ private:
    */
   void OnResourceReady(Toolkit::Control control);
 
-  /**
-   * @brief Set TransformMap for fittingMode
-   * param[in] finalSize The size for fittingMode
-   * param[in] textureSize The size of texture
-   * param[in] offset The offset for fittingMode
-   * param[in] fittingMode The mode for fitting image
-   * param[in] transformMap  The map for fitting image
-   */
-  void SetTransformMapForFittingMode(Vector2 finalSize, Vector2 textureSize, Vector2 offset, Visual::FittingMode fittingMode, Property::Map& transformMap);
-
-  /**
-   * @brief Apply fittingMode
-   */
-  void ApplyFittingMode(const Vector2& size);
-
    /**
    * @brief Create placeholder image if it set. placeholder image is shown when image view is waiting for the image to load.
    */
@@ -253,10 +238,7 @@ private:
 
   Animation       mTransitionAnimation;                    ///< the animation for transition effect
   float           mTransitionTargetAlpha;                  ///< Keep image's alpha value
-  bool            mImageVisualPaddingSetByTransform : 1;   ///< Flag to indicate Padding was set using a transform.
-  bool            mImageViewPixelAreaSetByFittingMode : 1; ///< Flag to indicate pixel area was set by fitting Mode
   bool            mTransitionEffect :1;                    ///< Flag to indicate TransitionEffect is enabled
-  bool            mNeedLazyFittingMode:1;                  ///< Flag to indicate FittingMode will be applying lazy
   bool            mImageReplaced:1;                        ///< Flag to indicate image is replaced
 };
 
index 08355520e90a446c7c0231841afaa9bcc86444c0..905c9d9a33c786d1cbfc39737c43be014907e06d 100644 (file)
@@ -133,7 +133,7 @@ AnimatedGradientVisualPtr AnimatedGradientVisual::New(VisualFactoryCache& factor
 }
 
 AnimatedGradientVisual::AnimatedGradientVisual(VisualFactoryCache& factoryCache)
-: Visual::Base(factoryCache, Visual::FittingMode::FILL, static_cast<Toolkit::Visual::Type>(Toolkit::DevelVisual::ANIMATED_GRADIENT))
+: Visual::Base(factoryCache, Visual::FittingMode::DONT_CARE, static_cast<Toolkit::Visual::Type>(Toolkit::DevelVisual::ANIMATED_GRADIENT))
 {
   SetupDefaultValue();
 }
index d8de5da46457d3945ae9fdb0c0f984cb51321669..f30f9441e3c1168b4ef9879d7f967017e3e3b0d2 100644 (file)
@@ -226,7 +226,7 @@ void AnimatedImageVisual::CreateImageCache()
 }
 
 AnimatedImageVisual::AnimatedImageVisual(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, ImageDimensions desiredSize)
-: Visual::Base(factoryCache, Visual::FittingMode::FILL, Toolkit::Visual::ANIMATED_IMAGE),
+: Visual::Base(factoryCache, Visual::FittingMode::DONT_CARE, Toolkit::Visual::ANIMATED_IMAGE),
   mFrameDelayTimer(),
   mPlacementActor(),
   mImageVisualShaderFactory(shaderFactory),
@@ -251,7 +251,7 @@ AnimatedImageVisual::AnimatedImageVisual(VisualFactoryCache& factoryCache, Image
   mActionStatus(DevelAnimatedImageVisual::Action::PLAY),
   mWrapModeU(WrapMode::DEFAULT),
   mWrapModeV(WrapMode::DEFAULT),
-  mFittingMode(FittingMode::SCALE_TO_FILL),
+  mFittingMode(FittingMode::VISUAL_FITTING),
   mSamplingMode(SamplingMode::BOX_THEN_LINEAR),
   mStopBehavior(DevelImageVisual::StopBehavior::CURRENT_FRAME),
   mStartFirstFrame(false),
@@ -276,6 +276,26 @@ void AnimatedImageVisual::GetNaturalSize(Vector2& naturalSize)
 {
   if(mDesiredSize.GetWidth() > 0 && mDesiredSize.GetHeight() > 0)
   {
+    if(mImpl->mRenderer)
+    {
+      auto textureSet = mImpl->mRenderer.GetTextures();
+      if(textureSet && textureSet.GetTextureCount())
+      {
+        auto texture = textureSet.GetTexture(0);
+        if(texture)
+        {
+          Dali::Vector2 textureSize;
+          textureSize.x = texture.GetWidth();
+          textureSize.y = texture.GetHeight();
+          if(textureSize != Vector2::ZERO)
+          {
+            naturalSize = textureSize;
+            return;
+          }
+        }
+      }
+    }
+
     naturalSize.x = mDesiredSize.GetWidth();
     naturalSize.y = mDesiredSize.GetHeight();
     return;
index 9fc2fda36a7ad0ce24c72cb5d043633a245d235f..61aab8a756804bb0e62fe5579cf00b7cf004c748 100644 (file)
@@ -87,7 +87,7 @@ AnimatedVectorImageVisualPtr AnimatedVectorImageVisual::New(VisualFactoryCache&
 }
 
 AnimatedVectorImageVisual::AnimatedVectorImageVisual(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, ImageDimensions size)
-: Visual::Base(factoryCache, Visual::FittingMode::FILL, static_cast<Toolkit::Visual::Type>(Toolkit::DevelVisual::ANIMATED_VECTOR_IMAGE)),
+: Visual::Base(factoryCache, Visual::FittingMode::DONT_CARE, static_cast<Toolkit::Visual::Type>(Toolkit::DevelVisual::ANIMATED_VECTOR_IMAGE)),
   mImageUrl(imageUrl),
   mAnimationData(),
   mVectorAnimationTask(new VectorAnimationTask(factoryCache)),
index 8c9f0feedde1b6c301acdbea5e6adbf20893fd04..b830276ccc9e9439c854a92e1e4b72ff05a9716f 100644 (file)
@@ -56,7 +56,7 @@ ArcVisualPtr ArcVisual::New(VisualFactoryCache& factoryCache, const Property::Ma
 }
 
 ArcVisual::ArcVisual(VisualFactoryCache& factoryCache)
-: Visual::Base(factoryCache, Visual::FittingMode::FILL, static_cast<Toolkit::Visual::Type>(Toolkit::DevelVisual::ARC)),
+: Visual::Base(factoryCache, Visual::FittingMode::DONT_CARE, static_cast<Toolkit::Visual::Type>(Toolkit::DevelVisual::ARC)),
   mThickness(0.0f),
   mRadius(0.0f),
   mStartAngle(0.0f),
index 322017f68b64a2eb8c04a1cd1406d62cdfb0f006..ea6ea67ef0ab1227d0a021fc8b0d1c8da37680e5 100644 (file)
@@ -55,7 +55,7 @@ BorderVisualPtr BorderVisual::New(VisualFactoryCache& factoryCache, const Proper
 }
 
 BorderVisual::BorderVisual(VisualFactoryCache& factoryCache)
-: Visual::Base(factoryCache, Visual::FittingMode::FILL, Toolkit::Visual::BORDER),
+: Visual::Base(factoryCache, Visual::FittingMode::DONT_CARE, Toolkit::Visual::BORDER),
   mBorderColor(Color::TRANSPARENT),
   mBorderSize(0.f),
   mBorderColorIndex(Property::INVALID_INDEX),
index cb20865a9fc81ff4d347ba5a46c83d84ff9237cc..10856d39e02a132d0d72db30c23b0b4e759c59be 100644 (file)
@@ -74,7 +74,7 @@ ColorVisualPtr ColorVisual::New(VisualFactoryCache& factoryCache, const Property
 }
 
 ColorVisual::ColorVisual(VisualFactoryCache& factoryCache)
-: Visual::Base(factoryCache, Visual::FittingMode::FILL, Toolkit::Visual::COLOR),
+: Visual::Base(factoryCache, Visual::FittingMode::DONT_CARE, Toolkit::Visual::COLOR),
   mBlurRadius(0.0f),
   mAlwaysUsingBlurRadius(false)
 {
index 066d50644a12fc050d03d10021d2b0f8630ec3b0..6884fbe1fe0e4b3fd7358c6fe88ed6249b5070fb 100644 (file)
@@ -129,7 +129,7 @@ GradientVisualPtr GradientVisual::New(VisualFactoryCache& factoryCache, const Pr
 }
 
 GradientVisual::GradientVisual(VisualFactoryCache& factoryCache)
-: Visual::Base(factoryCache, Visual::FittingMode::FILL, Toolkit::Visual::GRADIENT),
+: Visual::Base(factoryCache, Visual::FittingMode::DONT_CARE, Toolkit::Visual::GRADIENT),
   mGradientType(LINEAR),
   mIsOpaque(true)
 {
index 02d08af9bb95b419e7207cc9b82c3cf7d19e326b..65af749c00ddaa1c9d53e2e9536c0c5a9fde08da 100644 (file)
@@ -62,6 +62,7 @@ DALI_ENUM_TO_STRING_TABLE_BEGIN(FITTING_MODE)
   DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::FittingMode, SCALE_TO_FILL)
   DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::FittingMode, FIT_WIDTH)
   DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::FittingMode, FIT_HEIGHT)
+  DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::FittingMode, VISUAL_FITTING)
   DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::FittingMode, DEFAULT)
 DALI_ENUM_TO_STRING_TABLE_END(FITTING_MODE)
 
@@ -180,7 +181,7 @@ ImageVisual::ImageVisual(VisualFactoryCache&       factoryCache,
                          ImageDimensions           size,
                          FittingMode::Type         fittingMode,
                          Dali::SamplingMode::Type  samplingMode)
-: Visual::Base(factoryCache, Visual::FittingMode::FILL, Toolkit::Visual::IMAGE),
+: Visual::Base(factoryCache, Visual::FittingMode::DONT_CARE, Toolkit::Visual::IMAGE),
   mPixelArea(FULL_TEXTURE_RECT),
   mPixelAreaIndex(Property::INVALID_INDEX),
   mPlacementActor(),
@@ -475,6 +476,23 @@ void ImageVisual::GetNaturalSize(Vector2& naturalSize)
 {
   if(mDesiredSize.GetWidth() > 0 && mDesiredSize.GetHeight() > 0)
   {
+    if(mImpl->mRenderer)
+    {
+      auto textureSet = mImpl->mRenderer.GetTextures();
+      if(textureSet && textureSet.GetTextureCount())
+      {
+        auto texture = textureSet.GetTexture(0);
+        if(texture)
+        {
+          if(mTextureSize != Vector2::ZERO)
+          {
+            naturalSize = mTextureSize;
+            return;
+          }
+        }
+      }
+    }
+
     naturalSize.x = mDesiredSize.GetWidth();
     naturalSize.y = mDesiredSize.GetHeight();
     return;
index 60a67f17b59ed9306e2cea719e614fecdfbabbd9..5680d619fb055cd676c7fb440f553bf3c11f9bcf 100644 (file)
@@ -131,7 +131,7 @@ public:
                             const VisualUrl&          imageUrl,
                             const Property::Map&      properties,
                             ImageDimensions           size         = ImageDimensions(),
-                            FittingMode::Type         fittingMode  = FittingMode::DEFAULT,
+                            FittingMode::Type         fittingMode  = FittingMode::VISUAL_FITTING,
                             Dali::SamplingMode::Type  samplingMode = SamplingMode::BOX_THEN_LINEAR);
 
   /**
@@ -151,7 +151,7 @@ public:
                             ImageVisualShaderFactory& shaderFactory,
                             const VisualUrl&          imageUrl,
                             ImageDimensions           size         = ImageDimensions(),
-                            FittingMode::Type         fittingMode  = FittingMode::DEFAULT,
+                            FittingMode::Type         fittingMode  = FittingMode::VISUAL_FITTING,
                             Dali::SamplingMode::Type  samplingMode = SamplingMode::BOX_THEN_LINEAR);
 
 public: // from Visual
index 3196a1a82c43d385305f95223582306a42dc73a7..7c8b0b8782c7f3f6ad5171266410979ea58e9a4a 100644 (file)
@@ -103,7 +103,7 @@ MeshVisualPtr MeshVisual::New(VisualFactoryCache& factoryCache, const Property::
 }
 
 MeshVisual::MeshVisual(VisualFactoryCache& factoryCache)
-: Visual::Base(factoryCache, Visual::FittingMode::FIT_KEEP_ASPECT_RATIO, Toolkit::Visual::MESH),
+: Visual::Base(factoryCache, Visual::FittingMode::DONT_CARE, Toolkit::Visual::MESH),
   mShadingMode(Toolkit::MeshVisual::ShadingMode::TEXTURED_WITH_DETAILED_SPECULAR_LIGHTING),
   mUseTexture(true),
   mUseMipmapping(true),
index 1047eaf08bf1f3e4aec199a1a88efeb8d02a31aa..dba0a1673b8691dd4987fb01e6ec49b2a9b325d4 100644 (file)
@@ -287,7 +287,7 @@ void NPatchVisual::DoCreateInstancePropertyMap(Property::Map& map) const
 }
 
 NPatchVisual::NPatchVisual(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory)
-: Visual::Base(factoryCache, Visual::FittingMode::FILL, Toolkit::Visual::N_PATCH),
+: Visual::Base(factoryCache, Visual::FittingMode::DONT_CARE, Toolkit::Visual::N_PATCH),
   mPlacementActor(),
   mLoader(factoryCache.GetNPatchLoader()),
   mImageVisualShaderFactory(shaderFactory),
index 1afbfcdbf5b253494f9be5526fa58c098d5a4c80..f55415b2e8299ea95b5a045520abe52fe8de1272 100644 (file)
@@ -100,7 +100,7 @@ PrimitiveVisualPtr PrimitiveVisual::New(VisualFactoryCache& factoryCache, const
 }
 
 PrimitiveVisual::PrimitiveVisual(VisualFactoryCache& factoryCache)
-: Visual::Base(factoryCache, Visual::FittingMode::FIT_KEEP_ASPECT_RATIO, Toolkit::Visual::PRIMITIVE),
+: Visual::Base(factoryCache, Visual::FittingMode::DONT_CARE, Toolkit::Visual::PRIMITIVE),
   mScaleDimensions(Vector3::ONE),
   mScaleTopRadius(DEFAULT_SCALE_TOP_RADIUS),
   mScaleBottomRadius(DEFAULT_SCALE_BOTTOM_RADIUS),
index 49d62abbb065f43da53100c4d0e40151827242af..616924218d446b6406ce7b4b95f8b5331300c64a 100644 (file)
@@ -63,7 +63,7 @@ SvgVisualPtr SvgVisual::New(VisualFactoryCache& factoryCache, ImageVisualShaderF
 }
 
 SvgVisual::SvgVisual(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, ImageDimensions size)
-: Visual::Base(factoryCache, Visual::FittingMode::FILL, Toolkit::Visual::SVG),
+: Visual::Base(factoryCache, Visual::FittingMode::DONT_CARE, Toolkit::Visual::SVG),
   mImageVisualShaderFactory(shaderFactory),
   mAtlasRect(FULL_TEXTURE_RECT),
   mImageUrl(imageUrl),
index 5d2de158109a0e55c034463c938396d2f36a20aa..ec51c0065ee94457c3fa0ea2f027ac82611fcf6c 100644 (file)
@@ -251,7 +251,7 @@ void TextVisual::EnablePreMultipliedAlpha(bool preMultiplied)
 }
 
 TextVisual::TextVisual(VisualFactoryCache& factoryCache, TextVisualShaderFactory& shaderFactory)
-: Visual::Base(factoryCache, Visual::FittingMode::FIT_KEEP_ASPECT_RATIO, Toolkit::Visual::TEXT),
+: Visual::Base(factoryCache, Visual::FittingMode::DONT_CARE, Toolkit::Visual::TEXT),
   mController(Text::Controller::New()),
   mTypesetter(Text::Typesetter::New(mController->GetTextModel())),
   mTextVisualShaderFactory(shaderFactory),
index aee602dacf87c8454365658638d1a4c8db5790ad..029a4ccc08712420cafb0b73845b8afd8aadcfa9 100644 (file)
@@ -128,7 +128,10 @@ Internal::Visual::Base::Impl::Impl(FittingMode fittingMode, Toolkit::Visual::Typ
   mResourceStatus(Toolkit::Visual::ResourceStatus::PREPARING),
   mType(type),
   mAlwaysUsingBorderline(false),
-  mAlwaysUsingCornerRadius(false)
+  mAlwaysUsingCornerRadius(false),
+  mIgnoreFittingMode(false),
+  mPixelAreaSetByFittingMode(false),
+  mTransformMapSetForFittingMode(false)
 {
 }
 
index e54c3aeba29259f6abc8588fc189c73a6f4492bc..d8e7f34547a246366866b41967411360f88c1523 100644 (file)
@@ -254,8 +254,11 @@ struct Base::Impl
   int                             mFlags;
   Toolkit::Visual::ResourceStatus mResourceStatus;
   const Toolkit::Visual::Type     mType;
-  bool                            mAlwaysUsingBorderline : 1;     ///< Whether we need the borderline in shader always.
-  bool                            mAlwaysUsingCornerRadius : 1;   ///< Whether we need the corner radius in shader always.
+  bool                            mAlwaysUsingBorderline : 1;        ///< Whether we need the borderline in shader always.
+  bool                            mAlwaysUsingCornerRadius : 1;      ///< Whether we need the corner radius in shader always.
+  bool                            mIgnoreFittingMode : 1;            ///< Whether we need to ignore fitting mode.
+  bool                            mPixelAreaSetByFittingMode : 1;    ///< Whether the pixel area is set for fitting mode.
+  bool                            mTransformMapSetForFittingMode :1; ///< Whether the transformMap is set for fitting mode.
 };
 
 } // namespace Visual
index ed6e00cf9a7fb12d6344f75e67bedf29bc4f1045..150dc3df5f5fe6a5e1165aa32d15c213aae84454 100644 (file)
@@ -56,6 +56,9 @@ namespace Toolkit
 {
 namespace Internal
 {
+
+const Vector4 FULL_TEXTURE_RECT(0.f, 0.f, 1.f, 1.f);
+
 namespace
 {
 DALI_ENUM_TO_STRING_TABLE_BEGIN(VISUAL_FITTING_MODE)
@@ -65,6 +68,7 @@ DALI_ENUM_TO_STRING_TABLE_BEGIN(VISUAL_FITTING_MODE)
   DALI_ENUM_TO_STRING_WITH_SCOPE(Visual::FittingMode, CENTER)
   DALI_ENUM_TO_STRING_WITH_SCOPE(Visual::FittingMode, FIT_HEIGHT)
   DALI_ENUM_TO_STRING_WITH_SCOPE(Visual::FittingMode, FIT_WIDTH)
+  DALI_ENUM_TO_STRING_WITH_SCOPE(Visual::FittingMode, DONT_CARE)
 DALI_ENUM_TO_STRING_TABLE_END(VISUAL_FITTING_MODE)
 
 /**
@@ -849,6 +853,41 @@ Visual::FittingMode Visual::Base::GetFittingMode() const
   return mImpl->mFittingMode;
 }
 
+void Visual::Base::SetFittingMode(Visual::FittingMode fittingMode)
+{
+  mImpl->mFittingMode = fittingMode;
+}
+
+bool Visual::Base::IsIgnoreFittingMode() const
+{
+  return mImpl->mIgnoreFittingMode;
+}
+
+bool Visual::Base::IsPixelAreaSetForFittingMode() const
+{
+  return mImpl->mPixelAreaSetByFittingMode;
+}
+
+void Visual::Base::SetPixelAreaForFittingMode(const Vector4& pixelArea)
+{
+  if(mImpl->mRenderer)
+  {
+    mImpl->mRenderer.RegisterProperty(PIXEL_AREA_UNIFORM_NAME, pixelArea);
+  }
+
+  mImpl->mPixelAreaSetByFittingMode = (pixelArea != FULL_TEXTURE_RECT) ? true : false;
+}
+
+bool Visual::Base::IsTransformMapSetForFittingMode() const
+{
+  return mImpl->mTransformMapSetForFittingMode;
+}
+
+void Visual::Base::SetTransformMapUsageForFittingMode(bool used)
+{
+  mImpl->mTransformMapSetForFittingMode = used;
+}
+
 Visual::Base& Visual::Base::GetVisualObject()
 {
   return *this;
@@ -1148,6 +1187,8 @@ void Visual::Base::AnimateRendererProperty(
         map.Add(animator.propertyKey.stringKey, animator.targetValue);
       }
 
+      // Set flag to ignore fitting mode when we set the transform property map
+      mImpl->mIgnoreFittingMode = true;
       mImpl->mTransform.UpdatePropertyMap(map);
     }
     SetupTransition(transition, animator, index, animator.initialValue, animator.targetValue);
index 7ebf239f2d274a927178ffa846c6538d02352f61..1ee8b9190075e69a5ef891227d0a9cd3eeedfbdd 100644 (file)
@@ -263,6 +263,42 @@ public:
    */
   FittingMode GetFittingMode() const;
 
+  /**
+   * @brief Set the fitting mode for the visual
+   *
+   * @param[in] fittingMode The fitting mode for the visual
+   */
+  void SetFittingMode(FittingMode fittingMode);
+
+  /**
+   * @brief Query whether the fittingMode is ignored.
+   *
+   * @return Returns true if the fittingMode is ignored, false otherwise.
+   */
+  bool IsIgnoreFittingMode() const;
+
+  /**
+   * @brief Query whether the pixel area is set by fitting mode.
+   */
+  bool IsPixelAreaSetForFittingMode() const;
+
+  /**
+   * @brief Set the pixel area of the visual.
+   *
+   * @param[in] pixelArea The pixel area of the visual.
+   */
+  void SetPixelAreaForFittingMode(const Vector4& pixelArea);
+
+  /**
+   * @brief Checks whether the trasformMap is being used in the FittingMode situation.
+   */
+  bool IsTransformMapSetForFittingMode() const;
+
+  /**
+   * @brief Set the flag to use transformMap in the FittingMode.
+   */
+  void SetTransformMapUsageForFittingMode(bool used);
+
   /**
    * @brief Get the actual Visual Object.
    * @return The actual visual object
index 7611dd63b52ed538e062c3a1fd3e08133c329afa..ae76d870cc9d238a48a02da81a130c539d308035 100644 (file)
@@ -68,7 +68,7 @@ WireframeVisualPtr WireframeVisual::New(VisualFactoryCache& factoryCache, Visual
 }
 
 WireframeVisual::WireframeVisual(VisualFactoryCache& factoryCache, Visual::BasePtr actualVisual)
-: Visual::Base(factoryCache, Visual::FittingMode::FILL, actualVisual ? actualVisual->GetType() : Toolkit::Visual::WIREFRAME),
+: Visual::Base(factoryCache, Visual::FittingMode::DONT_CARE, actualVisual ? actualVisual->GetType() : Toolkit::Visual::WIREFRAME),
   mActualVisual(actualVisual)
 {
 }
index 40f34a0094663390f8641d0ecb71be6d9a4e8db7..914e8126117d992818cfc413414f35b36b147464 100644 (file)
@@ -37,6 +37,7 @@
 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
 #include <dali-toolkit/devel-api/visuals/color-visual-properties-devel.h>
 #include <dali-toolkit/devel-api/visuals/visual-actions-devel.h>
+#include <dali-toolkit/internal/visuals/visual-base-impl.h>
 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
 #include <dali-toolkit/internal/styling/style-manager-impl.h>
 #include <dali-toolkit/internal/visuals/color/color-visual.h>
@@ -601,12 +602,16 @@ void Control::OnPropertySet(Property::Index index, const Property::Value& proper
 
 void Control::OnSizeSet(const Vector3& targetSize)
 {
+  Vector2 size(targetSize);
   Toolkit::Visual::Base visual = mImpl->GetVisual(Toolkit::Control::Property::BACKGROUND);
   if(visual)
   {
-    Vector2 size(targetSize);
     visual.SetTransformAndSize(Property::Map(), size); // Send an empty map as we do not want to modify the visual's set transform
   }
+
+  // Apply FittingMode here
+  mImpl->mSize = size;
+  mImpl->RegisterProcessorOnce();
 }
 
 void Control::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
@@ -654,11 +659,8 @@ void Control::OnRelayout(const Vector2& size, RelayoutContainer& container)
     container.Add(child, newChildSize);
   }
 
-  Toolkit::Visual::Base visual = mImpl->GetVisual(Toolkit::Control::Property::BACKGROUND);
-  if(visual)
-  {
-    visual.SetTransformAndSize(Property::Map(), size); // Send an empty map as we do not want to modify the visual's set transform
-  }
+  // Apply FittingMode here
+  mImpl->ApplyFittingMode(size);
 }
 
 void Control::OnSetResizePolicy(ResizePolicy::Type policy, Dimension::Type dimension)