Apply WrapMode in animated visual 34/277334/3
authortscholb <scholb.kim@samsung.com>
Tue, 5 Jul 2022 07:44:03 +0000 (16:44 +0900)
committertscholb <scholb.kim@samsung.com>
Wed, 6 Jul 2022 06:06:40 +0000 (15:06 +0900)
animated visual only support default wrap mode.
After this patch, animated visual can use other wrap mode.

Change-Id: I8ac58895a724d1ff510577d76d30320cf501739f

automated-tests/resources/dali-logo.webp [new file with mode: 0644]
automated-tests/src/dali-toolkit/utc-Dali-AnimatedImageVisual.cpp
dali-toolkit/internal/visuals/animated-image/animated-image-visual.cpp
dali-toolkit/internal/visuals/animated-image/rolling-animated-image-cache.cpp
dali-toolkit/internal/visuals/animated-image/rolling-animated-image-cache.h

diff --git a/automated-tests/resources/dali-logo.webp b/automated-tests/resources/dali-logo.webp
new file mode 100644 (file)
index 0000000..2f0eb2b
Binary files /dev/null and b/automated-tests/resources/dali-logo.webp differ
index 6e8c9d7..9870308 100644 (file)
@@ -49,6 +49,7 @@ namespace
 const char* TEST_IMAGE_FILE_NAME      = TEST_RESOURCE_DIR "/application-icon-%02d.png";
 const char* TEST_GIF_FILE_NAME        = TEST_RESOURCE_DIR "/anim.gif";
 const char* TEST_MASK_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/mask.png";
+const char* TEST_WEBP_FILE_NAME       = TEST_RESOURCE_DIR "/dali-logo.webp";
 } // namespace
 
 void CopyUrlsIntoArray(Property::Array& urls, int startIndex = 0)
@@ -1779,3 +1780,71 @@ int UtcDaliAnimatedImageVisualPlayback(void)
 
   END_TEST;
 }
+
+int UtcDaliAnimatedImageVisualWrapMode(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline("UtcDaliAnimatedImageVisualWrapMode");
+
+  VisualFactory factory = VisualFactory::Get();
+  DALI_TEST_CHECK(factory);
+
+  // Test wrap mode in animated image visual.
+  const int     width  = 950;
+  const int     height = 1080;
+  const Vector4 pixelArea(0.0f, 0.0f, 950/ 40, 1.0f);
+
+  Property::Map propertyMap;
+  propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
+  propertyMap.Insert(ImageVisual::Property::URL, TEST_WEBP_FILE_NAME);
+  propertyMap.Insert(ImageVisual::Property::PIXEL_AREA, pixelArea);
+  propertyMap.Insert(ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT);
+
+  Visual::Base visual = factory.CreateVisual(propertyMap);
+  DALI_TEST_CHECK(visual);
+
+  TestGlAbstraction& gl           = application.GetGlAbstraction();
+  TraceCallStack&    textureTrace = gl.GetTextureTrace();
+  textureTrace.Enable(true);
+  textureTrace.EnableLogging(true);
+  TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
+  texParameterTrace.Enable(true);
+  texParameterTrace.EnableLogging(true);
+
+  DummyControl      actor     = DummyControl::New();
+  DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
+  dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
+  actor.SetProperty(Actor::Property::SIZE, Vector2(width, height));
+  actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
+
+  DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
+  application.GetScene().Add(actor);
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
+
+  DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
+
+  // WITHOUT atlasing, the wrapping is handled by setting gl texture parameters
+  std::stringstream out;
+  out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_REPEAT;
+  DALI_TEST_CHECK(texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
+
+  // test the uniforms which used to handle the wrap mode
+  Renderer renderer = actor.GetRendererAt(0u);
+  DALI_TEST_CHECK(renderer);
+
+  Property::Value pixelAreaValue = renderer.GetProperty(renderer.GetPropertyIndex("pixelArea"));
+  DALI_TEST_EQUALS(pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION);
+
+  actor.Unparent();
+  DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
+
+  END_TEST;
+}
index 382d52b..db00ff5 100644 (file)
@@ -178,7 +178,7 @@ void AnimatedImageVisual::CreateImageCache()
 
   if(mAnimatedImageLoading)
   {
-    mImageCache = new RollingAnimatedImageCache(textureManager, mAnimatedImageLoading, mMaskingData, *this, mCacheSize, mBatchSize, IsSynchronousLoadingRequired(), mFactoryCache.GetPreMultiplyOnLoad());
+    mImageCache = new RollingAnimatedImageCache(textureManager, mAnimatedImageLoading, mMaskingData, *this, mCacheSize, mBatchSize,  mWrapModeU, mWrapModeV, IsSynchronousLoadingRequired(), mFactoryCache.GetPreMultiplyOnLoad());
   }
   else if(mImageUrls)
   {
index 74ec088..b8a6961 100644 (file)
@@ -66,6 +66,8 @@ RollingAnimatedImageCache::RollingAnimatedImageCache(TextureManager&
                                                      ImageCache::FrameReadyObserver&     observer,
                                                      uint16_t                            cacheSize,
                                                      uint16_t                            batchSize,
+                                                     const Dali::WrapMode::Type&         wrapModeU,
+                                                     const Dali::WrapMode::Type&         wrapModeV,
                                                      bool                                isSynchronousLoading,
                                                      bool                                preMultiplyOnLoad)
 : ImageCache(textureManager, maskingData, observer, batchSize, 0u),
@@ -75,6 +77,8 @@ RollingAnimatedImageCache::RollingAnimatedImageCache(TextureManager&
   mFrameIndex(FIRST_FRAME_INDEX),
   mCacheSize(cacheSize),
   mQueue(cacheSize),
+  mWrapModeU(wrapModeU),
+  mWrapModeV(wrapModeV),
   mIsSynchronousLoading(isSynchronousLoading),
   mPreMultiplyOnLoad(preMultiplyOnLoad)
 {
@@ -204,8 +208,8 @@ TextureSet RollingAnimatedImageCache::RequestFrameLoading(uint32_t frameIndex, b
                                                                    loadTextureId,
                                                                    mMaskingData,
                                                                    SamplingMode::BOX_THEN_LINEAR,
-                                                                   Dali::WrapMode::Type::DEFAULT,
-                                                                   Dali::WrapMode::Type::DEFAULT,
+                                                                   mWrapModeU,
+                                                                   mWrapModeV,
                                                                    synchronousLoading,
                                                                    this,
                                                                    preMultiplyOnLoading);
@@ -328,7 +332,15 @@ void RollingAnimatedImageCache::LoadComplete(bool loadSuccess, TextureInformatio
   DALI_LOG_INFO(gAnimImgLogFilter, Debug::Concise, "AnimatedImageVisual::LoadComplete(textureId:%d) start\n", textureInformation.textureId);
   LOG_CACHE;
 
-  MakeFrameReady(loadSuccess, mTextureManager.GetTextureSet(textureInformation.textureId), textureInformation.interval);
+  TextureSet textureSet = mTextureManager.GetTextureSet(textureInformation.textureId);
+  if(textureSet)
+  {
+    Sampler sampler = Sampler::New();
+    sampler.SetWrapMode(mWrapModeU, mWrapModeV);
+    textureSet.SetSampler(0u, sampler);
+  }
+
+  MakeFrameReady(loadSuccess, textureSet, textureInformation.interval);
 
   if(loadSuccess)
   {
index 59729de..8fed2d7 100644 (file)
@@ -47,7 +47,10 @@ public:
    * @param[in] observer             FrameReady observer
    * @param[in] cacheSize            The size of the cache
    * @param[in] batchSize            The size of a batch to load
+   * @param[in] wrapModeU            Horizontal Wrap mode
+   * @param[in] wrapModeV            Vertical Wrap mode
    * @param[in] isSynchronousLoading The flag to define whether to load first frame synchronously
+   * @param[in] preMultiplyOnLoad    The flag if image's color should be multiplied by it's alpha
    *
    * This will start loading textures immediately, according to the
    * batch and cache sizes.
@@ -58,6 +61,8 @@ public:
                             ImageCache::FrameReadyObserver&     observer,
                             uint16_t                            cacheSize,
                             uint16_t                            batchSize,
+                            const Dali::WrapMode::Type&         wrapModeU,
+                            const Dali::WrapMode::Type&         wrapModeV,
                             bool                                isSynchronousLoading,
                             bool                                preMultiplyOnLoad);
 
@@ -181,6 +186,8 @@ private:
   std::vector<int32_t>       mIntervals;
   std::vector<uint32_t>      mLoadWaitingQueue;
   CircularQueue<ImageFrame>  mQueue;
+  Dali::WrapMode::Type       mWrapModeU : 3;
+  Dali::WrapMode::Type       mWrapModeV : 3;
   bool                       mIsSynchronousLoading;
   bool                       mPreMultiplyOnLoad;
 };