[Tizen] Add DesiredWidth/Height and samplingMode in animated image visual 29/268629/3 accepted/tizen/6.5/unified/20220104.122930 submit/tizen_6.5/20220103.151838
authorseungho <sbsh.baek@samsung.com>
Tue, 28 Dec 2021 08:28:07 +0000 (17:28 +0900)
committerseungho <sbsh.baek@samsung.com>
Wed, 29 Dec 2021 06:56:51 +0000 (15:56 +0900)
Change-Id: Icd2205738a6d9c7af0f2aa06c7887ac9ea85b576
Signed-off-by: seungho <sbsh.baek@samsung.com>
13 files changed:
dali-toolkit/internal/image-loader/image-load-thread.cpp
dali-toolkit/internal/visuals/animated-image/animated-image-visual.cpp
dali-toolkit/internal/visuals/animated-image/animated-image-visual.h
dali-toolkit/internal/visuals/animated-image/fixed-image-cache.cpp
dali-toolkit/internal/visuals/animated-image/fixed-image-cache.h
dali-toolkit/internal/visuals/animated-image/image-cache.cpp
dali-toolkit/internal/visuals/animated-image/image-cache.h
dali-toolkit/internal/visuals/animated-image/rolling-animated-image-cache.cpp
dali-toolkit/internal/visuals/animated-image/rolling-animated-image-cache.h
dali-toolkit/internal/visuals/animated-image/rolling-image-cache.cpp
dali-toolkit/internal/visuals/animated-image/rolling-image-cache.h
dali-toolkit/internal/visuals/texture-manager-impl.cpp
dali-toolkit/internal/visuals/texture-manager-impl.h

index 43b0707..3c4ee19 100644 (file)
@@ -111,7 +111,7 @@ void LoadingTask::Load()
 {
   if(animatedImageLoading)
   {
-    pixelBuffer = animatedImageLoading.LoadFrame(frameIndex);
+    pixelBuffer = animatedImageLoading.LoadFrame(frameIndex, dimensions, fittingMode, samplingMode);
   }
   else if(encodedImageBuffer)
   {
index 5025862..bfa0118 100644 (file)
@@ -46,6 +46,18 @@ namespace Internal
 {
 namespace
 {
+
+// sampling modes
+DALI_ENUM_TO_STRING_TABLE_BEGIN(SAMPLING_MODE)
+  DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::SamplingMode, BOX)
+  DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::SamplingMode, NEAREST)
+  DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::SamplingMode, LINEAR)
+  DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::SamplingMode, BOX_THEN_NEAREST)
+  DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::SamplingMode, BOX_THEN_LINEAR)
+  DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::SamplingMode, NO_FILTER)
+  DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::SamplingMode, DONT_CARE)
+DALI_ENUM_TO_STRING_TABLE_END(SAMPLING_MODE)
+
 // stop behavior
 DALI_ENUM_TO_STRING_TABLE_BEGIN(STOP_BEHAVIOR)
   DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::Toolkit::DevelImageVisual::StopBehavior, CURRENT_FRAME)
@@ -176,7 +188,7 @@ void AnimatedImageVisual::CreateImageCache()
 
   if(mAnimatedImageLoading)
   {
-    mImageCache = new RollingAnimatedImageCache(textureManager, mAnimatedImageLoading, mMaskingData, *this, mCacheSize, mBatchSize, IsSynchronousLoadingRequired());
+    mImageCache = new RollingAnimatedImageCache(textureManager, mDesiredSize, mSamplingMode, mAnimatedImageLoading, mMaskingData, *this, mCacheSize, mBatchSize, IsSynchronousLoadingRequired());
   }
   else if(mImageUrls)
   {
@@ -187,11 +199,11 @@ void AnimatedImageVisual::CreateImageCache()
     uint16_t cacheSize = std::max(std::min(std::max(batchSize, mCacheSize), numUrls), MINIMUM_CACHESIZE);
     if(cacheSize < numUrls)
     {
-      mImageCache = new RollingImageCache(textureManager, *mImageUrls, mMaskingData, *this, cacheSize, batchSize, mFrameDelay);
+      mImageCache = new RollingImageCache(textureManager, mDesiredSize, mSamplingMode, *mImageUrls, mMaskingData, *this, cacheSize, batchSize, mFrameDelay);
     }
     else
     {
-      mImageCache = new FixedImageCache(textureManager, *mImageUrls, mMaskingData, *this, batchSize, mFrameDelay);
+      mImageCache = new FixedImageCache(textureManager, mDesiredSize, mSamplingMode, *mImageUrls, mMaskingData, *this, batchSize, mFrameDelay);
     }
   }
 
@@ -221,6 +233,8 @@ AnimatedImageVisual::AnimatedImageVisual(VisualFactoryCache& factoryCache, Image
   mLoadPolicy(Toolkit::ImageVisual::LoadPolicy::ATTACHED),
   mReleasePolicy(Toolkit::ImageVisual::ReleasePolicy::DETACHED),
   mMaskingData(),
+  mSamplingMode(SamplingMode::BOX_THEN_LINEAR),
+  mDesiredSize(),
   mFrameCount(0),
   mImageSize(),
   mActionStatus(DevelAnimatedImageVisual::Action::PLAY),
@@ -246,6 +260,13 @@ AnimatedImageVisual::~AnimatedImageVisual()
 
 void AnimatedImageVisual::GetNaturalSize(Vector2& naturalSize)
 {
+  if(mDesiredSize.GetWidth() > 0 && mDesiredSize.GetHeight() > 0)
+  {
+    naturalSize.x = mDesiredSize.GetWidth();
+    naturalSize.y = mDesiredSize.GetHeight();
+    return;
+  }
+
   naturalSize = Vector2::ZERO;
   if(mImageSize.GetWidth() == 0 && mImageSize.GetHeight() == 0)
   {
@@ -346,11 +367,20 @@ void AnimatedImageVisual::DoCreatePropertyMap(Property::Map& map) const
 
   map.Insert(Toolkit::ImageVisual::Property::LOAD_POLICY, mLoadPolicy);
   map.Insert(Toolkit::ImageVisual::Property::RELEASE_POLICY, mReleasePolicy);
+  map.Insert(Toolkit::ImageVisual::Property::SAMPLING_MODE, mSamplingMode);
+  map.Insert(Toolkit::ImageVisual::Property::DESIRED_WIDTH, mDesiredSize.GetWidth());
+  map.Insert(Toolkit::ImageVisual::Property::DESIRED_HEIGHT, mDesiredSize.GetHeight());
 }
 
 void AnimatedImageVisual::DoCreateInstancePropertyMap(Property::Map& map) const
 {
-  // Do nothing
+  map.Clear();
+  map.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::ANIMATED_IMAGE);
+  if(mImageUrl.IsValid())
+  {
+    map.Insert(Toolkit::ImageVisual::Property::DESIRED_WIDTH, mDesiredSize.GetWidth());
+    map.Insert(Toolkit::ImageVisual::Property::DESIRED_HEIGHT, mDesiredSize.GetHeight());
+  }
 }
 
 void AnimatedImageVisual::OnDoAction(const Dali::Property::Index actionId, const Dali::Property::Value& attributes)
@@ -487,6 +517,18 @@ void AnimatedImageVisual::DoSetProperties(const Property::Map& propertyMap)
       {
         DoSetProperty(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, keyValue.second);
       }
+      else if(keyValue.first == IMAGE_SAMPLING_MODE)
+      {
+        DoSetProperty(Toolkit::ImageVisual::Property::SAMPLING_MODE, keyValue.second);
+      }
+      else if(keyValue.first == IMAGE_DESIRED_WIDTH)
+      {
+        DoSetProperty(Toolkit::ImageVisual::Property::DESIRED_WIDTH, keyValue.second);
+      }
+      else if(keyValue.first == IMAGE_DESIRED_HEIGHT)
+      {
+        DoSetProperty(Toolkit::ImageVisual::Property::DESIRED_HEIGHT, keyValue.second);
+      }
     }
   }
   // Load image immediately if LOAD_POLICY requires it
@@ -675,6 +717,42 @@ void AnimatedImageVisual::DoSetProperty(Property::Index        index,
       mLoadPolicy = Toolkit::ImageVisual::LoadPolicy::Type(loadPolicy);
       break;
     }
+
+    case Toolkit::ImageVisual::Property::SAMPLING_MODE:
+    {
+      int samplingMode = 0;
+      Scripting::GetEnumerationProperty(value, SAMPLING_MODE_TABLE, SAMPLING_MODE_TABLE_COUNT, samplingMode);
+      mSamplingMode = Dali::SamplingMode::Type(samplingMode);
+      break;
+    }
+
+    case Toolkit::ImageVisual::Property::DESIRED_WIDTH:
+    {
+      float desiredWidth = 0.0f;
+      if(value.Get(desiredWidth))
+      {
+        mDesiredSize.SetWidth(desiredWidth);
+      }
+      else
+      {
+        DALI_LOG_ERROR("AnimatedImageVisual: desiredWidth property has incorrect type\n");
+      }
+      break;
+    }
+
+    case Toolkit::ImageVisual::Property::DESIRED_HEIGHT:
+    {
+      float desiredHeight = 0.0f;
+      if(value.Get(desiredHeight))
+      {
+        mDesiredSize.SetHeight(desiredHeight);
+      }
+      else
+      {
+        DALI_LOG_ERROR("AnimatedImageVisual: desiredHeight property has incorrect type\n");
+      }
+      break;
+    }
   }
 }
 
index 210b588..a963249 100644 (file)
@@ -284,6 +284,8 @@ private:
   Dali::Toolkit::ImageVisual::LoadPolicy::Type    mLoadPolicy;
   Dali::Toolkit::ImageVisual::ReleasePolicy::Type mReleasePolicy;
   TextureManager::MaskingDataPointer              mMaskingData;
+  Dali::SamplingMode::Type                        mSamplingMode : 4;
+  Dali::ImageDimensions                           mDesiredSize;
 
   // Shared variables
   uint32_t        mFrameCount; // Number of frames
index 004cff3..56ef741 100644 (file)
@@ -37,12 +37,14 @@ static constexpr uint32_t FIRST_FRAME_INDEX = 0u;
 } // namespace
 
 FixedImageCache::FixedImageCache(TextureManager&                     textureManager,
+                                 ImageDimensions                     size,
+                                 Dali::SamplingMode::Type            samplingMode,
                                  UrlList&                            urlList,
                                  TextureManager::MaskingDataPointer& maskingData,
                                  ImageCache::FrameReadyObserver&     observer,
                                  uint32_t                            batchSize,
                                  uint32_t                            interval)
-: ImageCache(textureManager, maskingData, observer, batchSize, interval),
+: ImageCache(textureManager, size, samplingMode, maskingData, observer, batchSize, interval),
   mImageUrls(urlList),
   mFront(FIRST_FRAME_INDEX)
 {
@@ -137,7 +139,25 @@ void FixedImageCache::LoadBatch()
     auto                               preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
 
     TextureSet textureSet = mTextureManager.LoadTexture(
-      url, ImageDimensions(), FittingMode::SCALE_TO_FILL, SamplingMode::BOX_THEN_LINEAR, mMaskingData, synchronousLoading, mImageUrls[frameIndex].mTextureId, textureRect, textureRectSize, atlasingStatus, loadingStatus, Dali::WrapMode::Type::DEFAULT, Dali::WrapMode::Type::DEFAULT, this, atlasObserver, imageAtlasManager, ENABLE_ORIENTATION_CORRECTION, TextureManager::ReloadPolicy::CACHED, preMultiply);
+      url,
+      mDesiredSize,
+      FittingMode::SCALE_TO_FILL,
+      mSamplingMode,
+      mMaskingData,
+      synchronousLoading,
+      mImageUrls[frameIndex].mTextureId,
+      textureRect,
+      textureRectSize,
+      atlasingStatus,
+      loadingStatus,
+      Dali::WrapMode::Type::DEFAULT,
+      Dali::WrapMode::Type::DEFAULT,
+      this,
+      atlasObserver,
+      imageAtlasManager,
+      ENABLE_ORIENTATION_CORRECTION,
+      TextureManager::ReloadPolicy::CACHED,
+      preMultiply);
 
     // If textureSet is returned but loadingState is false than load state is LOAD_FINISHED. (Notification is not comming yet.)
     // If textureSet is null and the request is synchronous, load state is LOAD_FAILED.
index 3d80db0..96ed506 100644 (file)
@@ -33,6 +33,8 @@ public:
   /**
    * Constructor.
    * @param[in] textureManager The texture manager
+   * @param[in] size           The width and height to fit the loaded image to.
+   * @param[in] samplingMode   The SamplingMode of the resource to load
    * @param[in] urlList        List of urls to cache
    * @param[in] maskingData    Masking data to be applied.
    * @param[in] observer       FrameReady observer
@@ -43,6 +45,8 @@ public:
    * batch and cache sizes. The cache is as large as the number of urls.
    */
   FixedImageCache(TextureManager&                     textureManager,
+                  ImageDimensions                     size,
+                  Dali::SamplingMode::Type            samplingMode,
                   UrlList&                            urlList,
                   TextureManager::MaskingDataPointer& maskingData,
                   ImageCache::FrameReadyObserver&     observer,
index 8f001f7..4913b7d 100644 (file)
@@ -23,6 +23,8 @@ namespace Toolkit
 namespace Internal
 {
 ImageCache::ImageCache(TextureManager&                     textureManager,
+                       ImageDimensions                     size,
+                       Dali::SamplingMode::Type            samplingMode,
                        TextureManager::MaskingDataPointer& maskingData,
                        ImageCache::FrameReadyObserver&     observer,
                        uint32_t                            batchSize,
@@ -30,6 +32,8 @@ ImageCache::ImageCache(TextureManager&                     textureManager,
 : mTextureManager(textureManager),
   mObserver(observer),
   mMaskingData(maskingData),
+  mDesiredSize(size),
+  mSamplingMode(samplingMode),
   mBatchSize(batchSize),
   mInterval(interval),
   mRequestingLoad(false),
index dba45fa..e717187 100644 (file)
@@ -59,6 +59,8 @@ public:
   /**
    * @brief Constructor.
    * @param[in] textureManager The texture manager
+   * @param[in] size           The width and height to fit the loaded image to.
+   * @param[in] samplingMode   The SamplingMode of the resource to load
    * @param[in] observer       FrameReady observer
    * @param[in] maskingData    Masking data to be applied.
    * @param[in] batchSize      The size of a batch to load
@@ -68,6 +70,8 @@ public:
    * batch and cache sizes. The cache is as large as the number of urls.
    */
   ImageCache(TextureManager&                     textureManager,
+             ImageDimensions                     size,
+             Dali::SamplingMode::Type            samplingMode,
              TextureManager::MaskingDataPointer& maskingData,
              ImageCache::FrameReadyObserver&     observer,
              uint32_t                            batchSize,
@@ -146,6 +150,8 @@ protected:
   TextureManager&                     mTextureManager;
   FrameReadyObserver&                 mObserver;
   TextureManager::MaskingDataPointer& mMaskingData;
+  Dali::ImageDimensions               mDesiredSize;
+  Dali::SamplingMode::Type            mSamplingMode : 4;
   uint32_t                            mBatchSize;
   uint32_t                            mInterval;
   bool                                mRequestingLoad : 1;
index a950ac7..2fdf71f 100644 (file)
@@ -60,13 +60,15 @@ static constexpr uint32_t FIRST_FRAME_INDEX  = 0u;
 } // namespace
 
 RollingAnimatedImageCache::RollingAnimatedImageCache(TextureManager&                     textureManager,
+                                                     ImageDimensions                     size,
+                                                     Dali::SamplingMode::Type            samplingMode,
                                                      AnimatedImageLoading&               animatedImageLoading,
                                                      TextureManager::MaskingDataPointer& maskingData,
                                                      ImageCache::FrameReadyObserver&     observer,
                                                      uint16_t                            cacheSize,
                                                      uint16_t                            batchSize,
                                                      bool                                isSynchronousLoading)
-: ImageCache(textureManager, maskingData, observer, batchSize, 0u),
+: ImageCache(textureManager, size, samplingMode, maskingData, observer, batchSize, 0u),
   mAnimatedImageLoading(animatedImageLoading),
   mFrameCount(SINGLE_IMAGE_COUNT),
   mFrameIndex(FIRST_FRAME_INDEX),
@@ -195,7 +197,8 @@ TextureSet RollingAnimatedImageCache::RequestFrameLoading(uint32_t frameIndex, b
                                                                    loadingStatus,
                                                                    mImageUrls[frameIndex].mTextureId,
                                                                    mMaskingData,
-                                                                   SamplingMode::BOX_THEN_LINEAR,
+                                                                   mDesiredSize,
+                                                                   mSamplingMode,
                                                                    Dali::WrapMode::Type::DEFAULT,
                                                                    Dali::WrapMode::Type::DEFAULT,
                                                                    synchronousLoading,
index a35ba7c..a978379 100644 (file)
@@ -42,7 +42,9 @@ public:
   /**
    * @brief Constructor.
    * @param[in] textureManager       The texture manager
-   * @param[in] animatedImageLoading  The loaded animated image
+   * @param[in] size                 The width and height to fit the loaded image to.
+   * @param[in] samplingMode         The SamplingMode of the resource to load
+   * @param[in] animatedImageLoading The loaded animated image
    * @param[in] maskingData          Masking data to be applied.
    * @param[in] observer             FrameReady observer
    * @param[in] cacheSize            The size of the cache
@@ -53,6 +55,8 @@ public:
    * batch and cache sizes.
    */
   RollingAnimatedImageCache(TextureManager&                     textureManager,
+                            ImageDimensions                     size,
+                            Dali::SamplingMode::Type            samplingMode,
                             AnimatedImageLoading&               animatedImageLoading,
                             TextureManager::MaskingDataPointer& maskingData,
                             ImageCache::FrameReadyObserver&     observer,
index df41982..444d97b 100644 (file)
@@ -57,13 +57,15 @@ namespace Toolkit
 namespace Internal
 {
 RollingImageCache::RollingImageCache(TextureManager&                     textureManager,
+                                     ImageDimensions                     size,
+                                     Dali::SamplingMode::Type            samplingMode,
                                      UrlList&                            urlList,
                                      TextureManager::MaskingDataPointer& maskingData,
                                      ImageCache::FrameReadyObserver&     observer,
                                      uint16_t                            cacheSize,
                                      uint16_t                            batchSize,
                                      uint32_t                            interval)
-: ImageCache(textureManager, maskingData, observer, batchSize, interval),
+: ImageCache(textureManager, size, samplingMode, maskingData, observer, batchSize, interval),
   mImageUrls(urlList),
   mQueue(cacheSize)
 {
@@ -169,7 +171,25 @@ void RollingImageCache::LoadBatch(uint32_t frameIndex)
     auto                               preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
 
     TextureSet textureSet = mTextureManager.LoadTexture(
-      url, ImageDimensions(), FittingMode::SCALE_TO_FILL, SamplingMode::BOX_THEN_LINEAR, mMaskingData, synchronousLoading, mImageUrls[imageFrame.mUrlIndex].mTextureId, textureRect, textureRectSize, atlasingStatus, loadingStatus, Dali::WrapMode::Type::DEFAULT, Dali::WrapMode::Type::DEFAULT, this, atlasObserver, imageAtlasManager, ENABLE_ORIENTATION_CORRECTION, TextureManager::ReloadPolicy::CACHED, preMultiply);
+      url,
+      mDesiredSize,
+      FittingMode::SCALE_TO_FILL,
+      mSamplingMode,
+      mMaskingData,
+      synchronousLoading,
+      mImageUrls[imageFrame.mUrlIndex].mTextureId,
+      textureRect,
+      textureRectSize,
+      atlasingStatus,
+      loadingStatus,
+      Dali::WrapMode::Type::DEFAULT,
+      Dali::WrapMode::Type::DEFAULT,
+      this,
+      atlasObserver,
+      imageAtlasManager,
+      ENABLE_ORIENTATION_CORRECTION,
+      TextureManager::ReloadPolicy::CACHED,
+      preMultiply);
 
     // If textureSet is returned but loadingState is false than load state is LOAD_FINISHED. (Notification is not comming yet.)
     // If textureSet is null and the request is synchronous, load state is LOAD_FAILED.
index 0f0d883..b686137 100644 (file)
@@ -39,6 +39,8 @@ public:
   /**
    * Constructor.
    * @param[in] textureManager The texture manager
+   * @param[in] size           The width and height to fit the loaded image to.
+   * @param[in] samplingMode   The SamplingMode of the resource to load
    * @param[in] urlList        List of urls to cache
    * @param[in] maskingData    Masking data to be applied.
    * @param[in] observer       FrameReady observer
@@ -50,6 +52,8 @@ public:
    * batch and cache sizes.
    */
   RollingImageCache(TextureManager&                     textureManager,
+                    ImageDimensions                     size,
+                    Dali::SamplingMode::Type            samplingMode,
                     UrlList&                            urlList,
                     TextureManager::MaskingDataPointer& maskingData,
                     ImageCache::FrameReadyObserver&     observer,
index 9171032..5286717 100644 (file)
@@ -148,6 +148,7 @@ TextureSet TextureManager::LoadAnimatedImageTexture(Dali::AnimatedImageLoading a
                                                     bool&                      loadingStatus,
                                                     TextureManager::TextureId& textureId,
                                                     MaskingDataPointer&        maskInfo,
+                                                    Dali::ImageDimensions      desiredSize,
                                                     Dali::SamplingMode::Type   samplingMode,
                                                     Dali::WrapMode::Type       wrapModeU,
                                                     Dali::WrapMode::Type       wrapModeV,
@@ -162,7 +163,7 @@ TextureSet TextureManager::LoadAnimatedImageTexture(Dali::AnimatedImageLoading a
     Devel::PixelBuffer pixelBuffer;
     if(animatedImageLoading)
     {
-      pixelBuffer = animatedImageLoading.LoadFrame(frameIndex);
+      pixelBuffer = animatedImageLoading.LoadFrame(frameIndex, desiredSize, FittingMode::SCALE_TO_FILL, samplingMode);
     }
     if(!pixelBuffer)
     {
@@ -222,9 +223,9 @@ TextureSet TextureManager::LoadAnimatedImageTexture(Dali::AnimatedImageLoading a
                                     alphaMaskId,
                                     contentScaleFactor,
                                     cropToMask,
-                                    ImageDimensions(),
+                                    desiredSize,
                                     FittingMode::SCALE_TO_FILL,
-                                    SamplingMode::BOX_THEN_LINEAR,
+                                    samplingMode,
                                     TextureManager::NO_ATLAS,
                                     StorageType::UPLOAD_TO_TEXTURE,
                                     textureObserver,
index 823fc0d..4098dd8 100644 (file)
@@ -172,6 +172,7 @@ public:
    * @param[out] loadingStatus         The loading status of the texture
    * @param[out] textureId             The textureId of the frame
    * @param[in, out] maskInfo          Mask info structure
+   * @param[in]  desiredSize           The size the image is likely to appear at. This can be set to 0,0 for automatic
    * @param[in]  samplingMode          The SamplingMode to use
    * @param[in]  wrapModeU             Horizontal Wrap mode
    * @param[in]  wrapModeV             Vertical Wrap mode
@@ -188,6 +189,7 @@ public:
                                       bool&                      loadingStatus,
                                       TextureManager::TextureId& textureId,
                                       MaskingDataPointer&        maskInfo,
+                                      Dali::ImageDimensions      desiredSize,
                                       Dali::SamplingMode::Type   samplingMode,
                                       Dali::WrapMode::Type       wrapModeU,
                                       Dali::WrapMode::Type       wrapModeV,