Fix cache-miss if orientation correction value mismatched 14/314414/2
authorEunki, Hong <eunkiki.hong@samsung.com>
Thu, 11 Jul 2024 09:34:36 +0000 (18:34 +0900)
committerEunki Hong <eunkiki.hong@samsung.com>
Tue, 23 Jul 2024 02:40:26 +0000 (02:40 +0000)
Since we don't check the orientation correction value when we check cache,
it might be return unmatched image.

Change-Id: I781103ceaaa5e3e73f4c819beb11a2cd4adb46d5
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
automated-tests/src/dali-toolkit/utc-Dali-ImageVisual.cpp
dali-toolkit/internal/texture-manager/texture-cache-manager.cpp
dali-toolkit/internal/texture-manager/texture-cache-manager.h
dali-toolkit/internal/texture-manager/texture-manager-impl.cpp

index 5ced42c..01d5b21 100644 (file)
@@ -3464,6 +3464,58 @@ int UtcDaliImageVisualOrientationCorrection(void)
   END_TEST;
 }
 
+int UtcDaliImageVisualOrientationCorrectionCache(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline("UtcDaliImageVisualOrientationCorrectionCache Check orientation correction value give effort to cache hit");
+
+  VisualFactory factory = VisualFactory::Get();
+  tet_infoline("Create visual with Orientation correction set OFF");
+  Property::Map propertyMap;
+  propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
+  propertyMap.Insert(ImageVisual::Property::URL, TEST_ROTATED_IMAGE);
+  propertyMap.Insert("orientationCorrection", false);
+  Visual::Base imageVisual1 = factory.CreateVisual(propertyMap);
+
+  tet_infoline("Create control for visual, need to loaded it");
+  DummyControl        actor1     = DummyControl::New(true);
+  Impl::DummyControl& dummyImpl1 = static_cast<Impl::DummyControl&>(actor1.GetImplementation());
+  dummyImpl1.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual1);
+  application.GetScene().Add(actor1);
+
+  // Wait for image to load
+  DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+
+  tet_infoline("Create visual with Orientation correction set ON ");
+  propertyMap.Clear();
+  propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
+  propertyMap.Insert(ImageVisual::Property::URL, TEST_ROTATED_IMAGE);
+  propertyMap.Insert(ImageVisual::Property::ORIENTATION_CORRECTION, true);
+  Visual::Base imageVisual2 = factory.CreateVisual(propertyMap);
+
+  tet_infoline("Create control for visual2, need to loaded it");
+  DummyControl        actor2     = DummyControl::New(true);
+  Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor2.GetImplementation());
+  dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
+  application.GetScene().Add(actor2);
+
+  // Wait for image to load. Check whether each correction and non-correction image have difference size.
+  DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+
+  Vector2 visual1NaturalSize;
+  imageVisual1.GetNaturalSize(visual1NaturalSize);
+  Vector2 visual2NaturalSize;
+  imageVisual2.GetNaturalSize(visual2NaturalSize);
+
+  DALI_TEST_NOT_EQUALS(visual1NaturalSize.width, visual1NaturalSize.height, 0.01f, TEST_LOCATION); // Width and Height must be different for this test.
+
+  tet_infoline("Confirm that visual has rotated");
+  DALI_TEST_EQUALS(visual1NaturalSize.width, visual2NaturalSize.height, TEST_LOCATION);
+  DALI_TEST_EQUALS(visual1NaturalSize.height, visual2NaturalSize.width, TEST_LOCATION);
+
+  END_TEST;
+}
+
 int UtcDaliImageVisualCustomShader(void)
 {
   ToolkitTestApplication application;
index 2dfd16f..19c19bf 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 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.
@@ -504,6 +504,7 @@ TextureCacheManager::TextureHash TextureCacheManager::GenerateHash(
   const Dali::SamplingMode::Type       samplingMode,
   const TextureCacheManager::TextureId maskTextureId,
   const bool                           cropToMask,
+  const bool                           orientationCorrection,
   const uint32_t                       frameIndex)
 {
   std::vector<std::uint8_t> hashTarget;
@@ -528,6 +529,15 @@ TextureCacheManager::TextureHash TextureCacheManager::GenerateHash(
     *hashTargetPtr = (fittingMode << 3u) | (samplingMode);
   }
 
+  // Append whether we will not correction orientation. We don't do additional job when it is true, the general cases.
+  if(!orientationCorrection)
+  {
+    auto textureIdIndex = hashTarget.size();
+    hashTarget.resize(hashTarget.size() + 1u);
+    std::uint8_t* hashTargetPtr = reinterpret_cast<std::uint8_t*>(&(hashTarget[textureIdIndex]));
+    *hashTargetPtr++            = 'F';
+  }
+
   if(maskTextureId != INVALID_TEXTURE_ID)
   {
     auto textureIdIndex = hashTarget.size();
@@ -574,6 +584,7 @@ TextureCacheManager::TextureCacheIndex TextureCacheManager::FindCachedTexture(
   const TextureCacheManager::StorageType    storageType,
   const TextureCacheManager::TextureId      maskTextureId,
   const bool                                cropToMask,
+  const bool                                orientationCorrection,
   const TextureCacheManager::MultiplyOnLoad preMultiplyOnLoad,
   const bool                                isAnimatedImage,
   const uint32_t                            frameIndex)
@@ -597,6 +608,7 @@ TextureCacheManager::TextureCacheIndex TextureCacheManager::FindCachedTexture(
            (isAnimatedImage == textureInfo.isAnimatedImageFormat) &&
            (storageType == textureInfo.storageType) &&
            (frameIndex == textureInfo.frameIndex) &&
+           (orientationCorrection == textureInfo.orientationCorrection) &&
            ((size.GetWidth() == 0 && size.GetHeight() == 0) ||
             (fittingMode == textureInfo.fittingMode &&
              samplingMode == textureInfo.samplingMode)))
index 03075f4..10bf73d 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_TEXTURE_CACHE_MANAGER_H
 
 /*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 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.
@@ -218,6 +218,7 @@ public:
     const Dali::SamplingMode::Type       samplingMode,
     const TextureCacheManager::TextureId maskTextureId,
     const bool                           cropToMask,
+    const bool                           orientationCorrection,
     const uint32_t                       frameIndex);
 
   /**
@@ -245,6 +246,7 @@ public:
     const TextureCacheManager::StorageType    storageType,
     const TextureCacheManager::TextureId      maskTextureId,
     const bool                                cropToMask,
+    const bool                                orientationCorrection,
     const TextureCacheManager::MultiplyOnLoad preMultiplyOnLoad,
     const bool                                isAnimatedImage,
     const uint32_t                            frameIndex);
index f2ff1e3..36ff456 100644 (file)
@@ -528,10 +528,10 @@ TextureManager::TextureId TextureManager::RequestLoadInternal(
 
   if(storageType != TextureManager::StorageType::RETURN_PIXEL_BUFFER)
   {
-    textureHash = mTextureCacheManager.GenerateHash(url, desiredSize, fittingMode, samplingMode, maskTextureId, cropToMask, frameIndex);
+    textureHash = mTextureCacheManager.GenerateHash(url, desiredSize, fittingMode, samplingMode, maskTextureId, cropToMask, orientationCorrection, frameIndex);
 
     // Look up the texture by hash. Note: The extra parameters are used in case of a hash collision.
-    cacheIndex = mTextureCacheManager.FindCachedTexture(textureHash, url, desiredSize, fittingMode, samplingMode, storageType, maskTextureId, cropToMask, preMultiplyOnLoad, (animatedImageLoading) ? true : false, frameIndex);
+    cacheIndex = mTextureCacheManager.FindCachedTexture(textureHash, url, desiredSize, fittingMode, samplingMode, storageType, maskTextureId, cropToMask, orientationCorrection, preMultiplyOnLoad, (animatedImageLoading) ? true : false, frameIndex);
   }
 
   TextureManager::TextureId textureId = INVALID_TEXTURE_ID;