Keep NativeTexture and use it whenever we call UpdateShader() 40/320940/1
authorEunki, Hong <eunkiki.hong@samsung.com>
Tue, 11 Mar 2025 11:07:50 +0000 (20:07 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Tue, 11 Mar 2025 11:16:36 +0000 (20:16 +0900)
Until now, we use mTextures informations.
Since that handle be removed after InitializeRenderer() done,
it might make some unmatched shader if we call UpdateShader()
after InitializeRenderer() finished.

To avoid that case, let we keep native texture handle, and use it.

Change-Id: I133b2f0d9659f18f24b3f594f173f5fa109d9be9
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
dali-toolkit/internal/visuals/image/image-visual.cpp
dali-toolkit/internal/visuals/image/image-visual.h

index 4a3429077305e1ce717ee49dbc9ef17c87754211..e4363c518674cb6bcde2b90d07b34f5266fd717b 100644 (file)
@@ -201,6 +201,7 @@ ImageVisual::ImageVisual(VisualFactoryCache&       factoryCache,
   mLastRequiredSize(size),
   mTextureId(TextureManager::INVALID_TEXTURE_ID),
   mTextures(),
+  mNativeTexture(),
   mImageVisualShaderFactory(shaderFactory),
   mFittingMode(fittingMode),
   mSamplingMode(samplingMode),
@@ -213,7 +214,13 @@ ImageVisual::ImageVisual(VisualFactoryCache&       factoryCache,
   mLoadState(TextureManager::LoadState::NOT_STARTED),
   mAttemptAtlasing(false),
   mOrientationCorrection(true),
-  mEnableBrokenImage(true)
+  mNeedYuvToRgb(false),
+  mNeedUnifiedYuvAndRgb(false),
+  mEnableBrokenImage(true),
+  mUseFastTrackUploading(false),
+  mRendererAdded(false),
+  mUseBrokenImageRenderer(false),
+  mUseSynchronousSizing(false)
 {
   EnablePreMultipliedAlpha(mFactoryCache.GetPreMultiplyOnLoad());
 }
@@ -379,7 +386,11 @@ void ImageVisual::DoSetProperty(Property::Index index, const Property::Value& va
 
     case Toolkit::ImageVisual::Property::ATLASING:
     {
-      value.Get(mAttemptAtlasing);
+      bool attemptAtlasing = false;
+      if(value.Get(attemptAtlasing))
+      {
+        mAttemptAtlasing = attemptAtlasing;
+      }
       break;
     }
 
@@ -463,7 +474,11 @@ void ImageVisual::DoSetProperty(Property::Index index, const Property::Value& va
 
     case Toolkit::DevelImageVisual::Property::ENABLE_BROKEN_IMAGE:
     {
-      value.Get(mEnableBrokenImage);
+      bool enableBrokenImage = true;
+      if(value.Get(enableBrokenImage))
+      {
+        mEnableBrokenImage = enableBrokenImage;
+      }
       break;
     }
 
@@ -484,19 +499,31 @@ void ImageVisual::DoSetProperty(Property::Index index, const Property::Value& va
     }
     case Toolkit::ImageVisual::Property::ORIENTATION_CORRECTION:
     {
-      value.Get(mOrientationCorrection);
+      bool orientationCorrection = true;
+      if(value.Get(orientationCorrection))
+      {
+        mOrientationCorrection = orientationCorrection;
+      }
       break;
     }
 
     case Toolkit::DevelImageVisual::Property::FAST_TRACK_UPLOADING:
     {
-      value.Get(mUseFastTrackUploading);
+      bool useFastTrackUploading = false;
+      if(value.Get(useFastTrackUploading))
+      {
+        mUseFastTrackUploading = useFastTrackUploading;
+      }
       break;
     }
 
     case Toolkit::DevelImageVisual::Property::SYNCHRONOUS_SIZING:
     {
-      value.Get(mUseSynchronousSizing);
+      bool useSynchronousSizing = false;
+      if(value.Get(useSynchronousSizing))
+      {
+        mUseSynchronousSizing = useSynchronousSizing;
+      }
       break;
     }
   }
@@ -855,8 +882,9 @@ void ImageVisual::InitializeRenderer()
     mImpl->mRenderer.SetTextures(mTextures);
     ComputeTextureSize();
     CheckMaskTexture();
+    UpdateNativeTextureInfomation(mTextures);
 
-    bool needToUpdateShader = DevelTexture::IsNative(mTextures.GetTexture(0)) || mUseBrokenImageRenderer;
+    bool needToUpdateShader = (!!mNativeTexture) || mUseBrokenImageRenderer;
 
     if(mTextures.GetTextureCount() == 3)
     {
@@ -1056,6 +1084,7 @@ void ImageVisual::OnDoAction(const Dali::Property::Index actionId, const Dali::P
 
       // Need to reset textureset after change load state.
       mTextures.Reset();
+      UpdateNativeTextureInfomation(Dali::TextureSet());
 
       Dali::ImageDimensions size = mUseSynchronousSizing ? mLastRequiredSize : mDesiredSize;
       LoadTexture(attemptAtlasing, mAtlasRect, mTextures, size, TextureManager::ReloadPolicy::FORCED);
@@ -1090,6 +1119,7 @@ void ImageVisual::OnSetTransform()
 
       // Need to reset textureset after change load state.
       mTextures.Reset();
+      UpdateNativeTextureInfomation(Dali::TextureSet());
 
       bool attemptAtlasing = AttemptAtlasing();
       LoadTexture(attemptAtlasing, mAtlasRect, mTextures, visualSize, TextureManager::ReloadPolicy::CACHED);
@@ -1211,6 +1241,7 @@ void ImageVisual::LoadComplete(bool loadingSuccess, TextureInformation textureIn
       mImpl->mRenderer.SetTextures(textureInformation.textureSet);
       ComputeTextureSize();
       CheckMaskTexture();
+      UpdateNativeTextureInfomation(textureInformation.textureSet);
 
       bool needToUpdateShader = mUseBrokenImageRenderer;
 
@@ -1255,6 +1286,8 @@ void ImageVisual::LoadComplete(bool loadingSuccess, TextureInformation textureIn
   if(!mImpl->mRenderer)
   {
     mTextures = textureInformation.textureSet;
+
+    UpdateNativeTextureInfomation(mTextures);
   }
 
   // Image loaded, set status regardless of staged status.
@@ -1360,7 +1393,7 @@ Shader ImageVisual::GenerateShader() const
   Shader shader;
 
   const bool useStandardShader = !mImpl->mCustomShader;
-  const bool useNativeImage    = (mTextures && DevelTexture::IsNative(mTextures.GetTexture(0)));
+  const bool useNativeImage    = (!!mNativeTexture);
 
   if(useStandardShader)
   {
@@ -1373,7 +1406,7 @@ Shader ImageVisual::GenerateShader() const
         .ApplyDefaultTextureWrapMode(mWrapModeU <= WrapMode::CLAMP_TO_EDGE && mWrapModeV <= WrapMode::CLAMP_TO_EDGE)
         .EnableRoundedCorner(IsRoundedCornerRequired(), IsSquircleCornerRequired())
         .EnableBorderline(IsBorderlineRequired())
-        .SetTextureForFragmentShaderCheck(useNativeImage ? mTextures.GetTexture(0) : Dali::Texture())
+        .SetTextureForFragmentShaderCheck(useNativeImage ? mNativeTexture : Dali::Texture())
         .EnableAlphaMaskingOnRendering(requiredAlphaMaskingOnRendering)
         .EnableYuvToRgb(mNeedYuvToRgb, mNeedUnifiedYuvAndRgb));
   }
@@ -1407,10 +1440,9 @@ Shader ImageVisual::GenerateShader() const
     if(useNativeImage)
     {
       bool        modifiedFragmentShader = false;
-      Texture     nativeTexture          = mTextures.GetTexture(0);
       std::string fragmentShaderString   = std::string(fragmentShaderView);
 
-      modifiedFragmentShader = DevelTexture::ApplyNativeFragmentShader(nativeTexture, fragmentShaderString);
+      modifiedFragmentShader = DevelTexture::ApplyNativeFragmentShader(mNativeTexture, fragmentShaderString);
       if(modifiedFragmentShader)
       {
         fragmentShaderView = fragmentShaderString;
@@ -1496,6 +1528,7 @@ void ImageVisual::ResetRenderer()
 
   // Need to reset textureset after change load state.
   mTextures.Reset();
+  UpdateNativeTextureInfomation(Dali::TextureSet());
 }
 
 void ImageVisual::ShowBrokenImage()
@@ -1604,6 +1637,22 @@ Geometry ImageVisual::GenerateGeometry(TextureManager::TextureId textureId, bool
   return geometry;
 }
 
+void ImageVisual::UpdateNativeTextureInfomation(TextureSet textureSet)
+{
+  // Reset previous flags and infomations.
+  mNativeTexture.Reset();
+
+  if(textureSet && textureSet.GetTextureCount() > 0u)
+  {
+    Texture texture = textureSet.GetTexture(0u);
+    if(DevelTexture::IsNative(texture))
+    {
+      // Keep native texture handle.
+      mNativeTexture = texture;
+    }
+  }
+}
+
 } // namespace Internal
 
 } // namespace Toolkit
index e5060af6859f98ef834c05d3bc931416d09db5db..14f1ae8b1dada8e8e02ef60fc0ca8e2149ef5d82 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_INTERNAL_IMAGE_VISUAL_H
 
 /*
- * Copyright (c) 2024 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2025 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.
@@ -368,6 +368,11 @@ private:
    */
   Geometry GenerateGeometry(TextureManager::TextureId textureId, bool createForce);
 
+  /**
+   * @brief Update the informations whether this visual using native texture or not.
+   */
+  void UpdateNativeTextureInfomation(TextureSet textureSet);
+
 private:
   Vector4         mPixelArea;
   Property::Index mPixelAreaIndex;
@@ -381,6 +386,7 @@ private:
   Dali::ImageDimensions     mLastRequiredSize;
   TextureManager::TextureId mTextureId;
   TextureSet                mTextures;
+  Dali::Texture             mNativeTexture; ///< The handle of native texture if we are using it.
   Vector2                   mTextureSize;
   Vector2                   mPlacementActorSize;
 
@@ -396,16 +402,17 @@ private:
   Dali::Toolkit::ImageVisual::ReleasePolicy::Type mReleasePolicy;
   Vector4                                         mAtlasRect;
   Dali::ImageDimensions                           mAtlasRectSize;
-  TextureManager::LoadState                       mLoadState;                     ///< The texture loading state
-  bool                                            mAttemptAtlasing;               ///< If true will attempt atlasing, otherwise create unique texture
-  bool                                            mOrientationCorrection;         ///< true if the image will have it's orientation corrected.
-  bool                                            mNeedYuvToRgb{false};           ///< true if we need to convert yuv to rgb.
-  bool                                            mNeedUnifiedYuvAndRgb{false};   ///< true if we need to support both yuv and rgb.
-  bool                                            mEnableBrokenImage{true};       ///< true if enable broken image.
-  bool                                            mUseFastTrackUploading{false};  ///< True if we use fast tack feature.
-  bool                                            mRendererAdded{false};          ///< True if renderer added into actor.
-  bool                                            mUseBrokenImageRenderer{false}; ///< True if renderer changed as broken image.
-  bool                                            mUseSynchronousSizing{false};   ///< True if we need to synchronize image texture size to visual size, otherwise use mDesiredSize.
+  TextureManager::LoadState                       mLoadState; ///< The texture loading state
+
+  bool mAttemptAtlasing : 1;        ///< If true will attempt atlasing, otherwise create unique texture
+  bool mOrientationCorrection : 1;  ///< true if the image will have it's orientation corrected.
+  bool mNeedYuvToRgb : 1;           ///< true if we need to convert yuv to rgb.
+  bool mNeedUnifiedYuvAndRgb : 1;   ///< true if we need to support both yuv and rgb.
+  bool mEnableBrokenImage : 1;      ///< true if enable broken image.
+  bool mUseFastTrackUploading : 1;  ///< True if we use fast tack feature.
+  bool mRendererAdded : 1;          ///< True if renderer added into actor.
+  bool mUseBrokenImageRenderer : 1; ///< True if renderer changed as broken image.
+  bool mUseSynchronousSizing : 1;   ///< True if we need to synchronize image texture size to visual size, otherwise use mDesiredSize.
 };
 
 } // namespace Internal