[dali_2.3.28] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / color / color-visual.cpp
index 09fd60e..10856d3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2022 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.
@@ -62,6 +62,8 @@ enum ColorVisualRequireFlag
   BORDERLINE     = 1 << 1,
   BLUR           = 1 << 2,
 };
+
+constexpr uint32_t MINIMUM_SHADER_VERSION_SUPPORT_ROUNDED_BLUR = 300;
 } // unnamed namespace
 ColorVisualPtr ColorVisual::New(VisualFactoryCache& factoryCache, const Property::Map& properties)
 {
@@ -72,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)
 {
@@ -235,16 +237,16 @@ Shader ColorVisual::GenerateShader() const
   bool blur           = IsBlurRequired();
   int  shaderTypeFlag = ColorVisualRequireFlag::DEFAULT;
 
-  if(roundedCorner)
-  {
-    shaderTypeFlag |= ColorVisualRequireFlag::ROUNDED_CORNER;
-  }
   if(blur)
   {
     // If we use blur, just ignore borderline
     borderline = false;
     shaderTypeFlag |= ColorVisualRequireFlag::BLUR;
   }
+  if(roundedCorner)
+  {
+    shaderTypeFlag |= ColorVisualRequireFlag::ROUNDED_CORNER;
+  }
   if(borderline)
   {
     shaderTypeFlag |= ColorVisualRequireFlag::BORDERLINE;
@@ -265,15 +267,22 @@ Shader ColorVisual::GenerateShader() const
     {
       vertexShaderPrefixList += "#define IS_REQUIRED_BLUR\n";
       fragmentShaderPrefixList += "#define IS_REQUIRED_BLUR\n";
+
+      // If shader version doesn't support latest blur with corner radius, Let we use legacy code.
+      if(DALI_UNLIKELY(Dali::Shader::GetShaderLanguageVersion() < MINIMUM_SHADER_VERSION_SUPPORT_ROUNDED_BLUR))
+      {
+        fragmentShaderPrefixList += "#define SL_VERSION_LOW\n";
+      }
     }
     if(borderline)
     {
       vertexShaderPrefixList += "#define IS_REQUIRED_BORDERLINE\n";
       fragmentShaderPrefixList += "#define IS_REQUIRED_BORDERLINE\n";
     }
-    shader = Shader::New(Dali::Shader::GetVertexShaderPrefix() + vertexShaderPrefixList + SHADER_COLOR_VISUAL_SHADER_VERT.data(),
-                         Dali::Shader::GetFragmentShaderPrefix() + fragmentShaderPrefixList + SHADER_COLOR_VISUAL_SHADER_FRAG.data());
-    mFactoryCache.SaveShader(shaderType, shader);
+
+    shader = mFactoryCache.GenerateAndSaveShader(shaderType,
+                                                 Dali::Shader::GetVertexShaderPrefix() + vertexShaderPrefixList + SHADER_COLOR_VISUAL_SHADER_VERT.data(),
+                                                 Dali::Shader::GetFragmentShaderPrefix() + fragmentShaderPrefixList + SHADER_COLOR_VISUAL_SHADER_FRAG.data());
   }
 
   return shader;