Refactoring visual-shader-factory 96/315396/10
authorsunghyun kim <scholb.kim@samsung.com>
Wed, 31 Jul 2024 08:41:37 +0000 (17:41 +0900)
committersunghyun kim <scholb.kim@samsung.com>
Mon, 2 Sep 2024 07:50:47 +0000 (16:50 +0900)
Change-Id: I3b1d9c4ba1aa45cb9c11192121b2fb286b002b6c

18 files changed:
automated-tests/src/dali-toolkit-internal/utc-Dali-Visuals-internal.cpp
dali-toolkit/devel-api/file.list
dali-toolkit/devel-api/visual-factory/visual-shader-factory-interface.h [new file with mode: 0644]
dali-toolkit/internal/file.list
dali-toolkit/internal/visuals/color/color-visual-shader-factory.cpp [new file with mode: 0644]
dali-toolkit/internal/visuals/color/color-visual-shader-factory.h [new file with mode: 0644]
dali-toolkit/internal/visuals/color/color-visual.cpp
dali-toolkit/internal/visuals/color/color-visual.h
dali-toolkit/internal/visuals/image/image-visual-shader-factory.cpp
dali-toolkit/internal/visuals/image/image-visual-shader-factory.h
dali-toolkit/internal/visuals/image/image-visual-shader-feature-builder.cpp
dali-toolkit/internal/visuals/image/image-visual-shader-feature-builder.h
dali-toolkit/internal/visuals/text/text-visual-shader-factory.cpp
dali-toolkit/internal/visuals/text/text-visual-shader-factory.h
dali-toolkit/internal/visuals/text/text-visual.cpp
dali-toolkit/internal/visuals/text/text-visual.h
dali-toolkit/internal/visuals/visual-factory-impl.cpp
dali-toolkit/internal/visuals/visual-factory-impl.h

index 84d1358e0b35208ff4baa450476fee14592c2f30..40ae0b80f21b274353c898a7e825807dd9b72e9b 100644 (file)
@@ -205,7 +205,7 @@ int UtcDaliVisualSetProperties(void)
   Property::Map propertyMap1;
   propertyMap1.Insert(Visual::Property::TYPE, Visual::COLOR);
   propertyMap1.Insert(ColorVisual::Property::MIX_COLOR, Color::RED);
-  Toolkit::Internal::ColorVisualPtr colorVisualPtr = Toolkit::Internal::ColorVisual::New(*factoryCache, propertyMap1);
+  Toolkit::Internal::DummyVisualPtr colorVisualPtr = Toolkit::Internal::DummyVisual::New(propertyMap1);
 
   DummyControl        dummyControl = DummyControl::New(true);
   Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
index f8a9d42a31fbd022c41b90d3d1d057c6bce4d5d6..b37f8a8f81acdb6f422368af0e0f0b8668eec3d4 100755 (executable)
@@ -183,6 +183,7 @@ SET( devel_api_visual_factory_header_files
   ${devel_api_src_dir}/visual-factory/transition-data.h
   ${devel_api_src_dir}/visual-factory/visual-factory.h
   ${devel_api_src_dir}/visual-factory/visual-base.h
+  ${devel_api_src_dir}/visual-factory/visual-shader-factory-interface.h
 )
 
 SET( devel_api_visuals_header_files
diff --git a/dali-toolkit/devel-api/visual-factory/visual-shader-factory-interface.h b/dali-toolkit/devel-api/visual-factory/visual-shader-factory-interface.h
new file mode 100644 (file)
index 0000000..875d26a
--- /dev/null
@@ -0,0 +1,51 @@
+#ifndef DALI_TOOLKIT_VISUAL_SHADER_FACTORY_INTERFACE_H
+#define DALI_TOOLKIT_VISUAL_SHADER_FACTORY_INTERFACE_H
+
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <dali/integration-api/adaptor-framework/shader-precompiler.h>
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/public-api/dali-toolkit-common.h>
+
+namespace Dali
+{
+namespace Toolkit
+{
+
+/**
+ * @brief The VisualShaderFactoryInterface class provides a factory interface for creating visual shader
+ */
+class DALI_TOOLKIT_API VisualShaderFactoryInterface
+{
+public:
+    VisualShaderFactoryInterface() = default;
+    virtual ~VisualShaderFactoryInterface() = default;
+
+    /**
+     * @brief Get precompiled shader for precompile
+     * @param[out] shaders shaderList for precompile
+     */
+    virtual void GetPreCompiledShader(RawShaderData& shaders) = 0;
+};
+
+} // namespace Toolkit
+} // namespace Dali
+
+#endif // DALI_TOOLKIT_VISUAL_SHADER_FACTORY_INTERFACE_H
index 8048a5dedc892e6d5e47e4b78f23b0261ccc06fe..735b3a4d9ccdd1eb967f9f116e43961c749e4811 100644 (file)
@@ -35,6 +35,7 @@ SET( toolkit_src_files
    ${toolkit_src_dir}/visuals/animated-vector-image/vector-animation-thread.cpp
    ${toolkit_src_dir}/visuals/arc/arc-visual.cpp
    ${toolkit_src_dir}/visuals/border/border-visual.cpp
+   ${toolkit_src_dir}/visuals/color/color-visual-shader-factory.cpp
    ${toolkit_src_dir}/visuals/color/color-visual.cpp
    ${toolkit_src_dir}/visuals/gradient/gradient-visual.cpp
    ${toolkit_src_dir}/visuals/gradient/gradient.cpp
diff --git a/dali-toolkit/internal/visuals/color/color-visual-shader-factory.cpp b/dali-toolkit/internal/visuals/color/color-visual-shader-factory.cpp
new file mode 100644 (file)
index 0000000..a79def5
--- /dev/null
@@ -0,0 +1,236 @@
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// CLASS HEADER
+#include <dali-toolkit/internal/visuals/color/color-visual-shader-factory.h>
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
+#include <dali-toolkit/internal/visuals/visual-string-constants.h>
+#include <dali/integration-api/debug.h>
+
+namespace Dali
+{
+namespace Toolkit
+{
+namespace Internal
+{
+
+namespace
+{
+
+constexpr VisualFactoryCache::ShaderType SHADER_TYPE_TABLE[] = {
+  VisualFactoryCache::COLOR_SHADER,
+  VisualFactoryCache::COLOR_SHADER_ROUNDED_CORNER,
+  VisualFactoryCache::COLOR_SHADER_BORDERLINE,
+  VisualFactoryCache::COLOR_SHADER_ROUNDED_BORDERLINE,
+  VisualFactoryCache::COLOR_SHADER_BLUR_EDGE,
+  VisualFactoryCache::COLOR_SHADER_ROUNDED_CORNER_BLUR_EDGE,
+};
+
+constexpr VisualFactoryCache::ShaderType SHADER_TYPE_WITH_CUTOUT_TABLE[] = {
+  VisualFactoryCache::COLOR_SHADER_CUTOUT,
+  VisualFactoryCache::COLOR_SHADER_CUTOUT_ROUNDED_CORNER,
+  VisualFactoryCache::COLOR_SHADER_CUTOUT_BORDERLINE,
+  VisualFactoryCache::COLOR_SHADER_CUTOUT_ROUNDED_BORDERLINE,
+  VisualFactoryCache::COLOR_SHADER_CUTOUT_BLUR_EDGE,
+  VisualFactoryCache::COLOR_SHADER_CUTOUT_ROUNDED_CORNER_BLUR_EDGE,
+};
+
+// enum of required list when we select shader
+enum ColorVisualRequireFlag
+{
+  DEFAULT        = 0,
+  ROUNDED_CORNER = 1 << 0,
+  BORDERLINE     = 1 << 1,
+  BLUR           = 1 << 2,
+};
+
+constexpr uint32_t MINIMUM_SHADER_VERSION_SUPPORT_ROUNDED_BLUR = 300;
+
+static constexpr auto PREDEFINED_SHADER_TYPE_COUNT = 2u;
+
+constexpr std::string_view VertexPredefines[PREDEFINED_SHADER_TYPE_COUNT]{
+  "",                                     //VisualFactoryCache::COLOR_SHADER
+  "#define IS_REQUIRED_ROUNDED_CORNER\n", //VisualFactoryCache::COLOR_SHADER_ROUNDED_CORNER
+};
+constexpr std::string_view FragmentPredefines[PREDEFINED_SHADER_TYPE_COUNT]{
+  "",                                     //VisualFactoryCache::COLOR_SHADER
+  "#define IS_REQUIRED_ROUNDED_CORNER\n", //VisualFactoryCache::COLOR_SHADER_ROUNDED_CORNER
+};
+constexpr VisualFactoryCache::ShaderType ShaderTypePredefines[PREDEFINED_SHADER_TYPE_COUNT]{
+  VisualFactoryCache::ShaderType::COLOR_SHADER,
+  VisualFactoryCache::ShaderType::COLOR_SHADER_ROUNDED_CORNER,
+};
+}
+
+ColorVisualShaderFeatureBuilder::ColorVisualShaderFeatureBuilder()
+: mColorRoundCorner(ColorVisualShaderFeature::RoundedCorner::DISABLED),
+  mColorBorderline(ColorVisualShaderFeature::Borderline::DISABLED),
+  mColorBlur(ColorVisualShaderFeature::Blur::DISABLED),
+  mColorCutout(ColorVisualShaderFeature::Cutout::DISABLED)
+{
+}
+
+ColorVisualShaderFeatureBuilder& ColorVisualShaderFeatureBuilder::EnableRoundCorner(bool enableRoundedCorner)
+{
+  mColorRoundCorner = (enableRoundedCorner ? ColorVisualShaderFeature::RoundedCorner::ENABLED : ColorVisualShaderFeature::RoundedCorner::DISABLED);
+  return *this;
+}
+
+ColorVisualShaderFeatureBuilder& ColorVisualShaderFeatureBuilder::EnableBorderLine(bool enableBorderLine)
+{
+  mColorBorderline = (enableBorderLine ? ColorVisualShaderFeature::Borderline::ENABLED : ColorVisualShaderFeature::Borderline::DISABLED);
+  return *this;
+}
+
+ColorVisualShaderFeatureBuilder& ColorVisualShaderFeatureBuilder::EnableBlur(bool enableBlur)
+{
+  mColorBlur = (enableBlur ? ColorVisualShaderFeature::Blur::ENABLED : ColorVisualShaderFeature::Blur::DISABLED);
+  return *this;
+}
+
+ColorVisualShaderFeatureBuilder& ColorVisualShaderFeatureBuilder::EnableCutout(bool enableCutout)
+{
+  mColorCutout = (enableCutout ? ColorVisualShaderFeature::Cutout::ENABLED : ColorVisualShaderFeature::Cutout::DISABLED);
+  return *this;
+}
+
+VisualFactoryCache::ShaderType ColorVisualShaderFeatureBuilder::GetShaderType() const
+{
+  VisualFactoryCache::ShaderType shaderType = VisualFactoryCache::COLOR_SHADER;
+  uint32_t  shaderTypeFlag = ColorVisualRequireFlag::DEFAULT;
+  if(mColorBlur)
+  {
+    shaderTypeFlag |= ColorVisualRequireFlag::BLUR;
+  }
+  if(mColorRoundCorner)
+  {
+    shaderTypeFlag |= ColorVisualRequireFlag::ROUNDED_CORNER;
+  }
+  if(mColorBorderline && !mColorBlur)
+  {
+    shaderTypeFlag |= ColorVisualRequireFlag::BORDERLINE;
+  }
+
+  shaderType = mColorCutout ? SHADER_TYPE_WITH_CUTOUT_TABLE[shaderTypeFlag] : SHADER_TYPE_TABLE[shaderTypeFlag];
+
+  return shaderType;
+}
+
+void ColorVisualShaderFeatureBuilder::GetVertexShaderPrefixList(std::string& vertexShaderPrefixList) const
+{
+  if(mColorRoundCorner == ColorVisualShaderFeature::RoundedCorner::ENABLED)
+  {
+    vertexShaderPrefixList += "#define IS_REQUIRED_ROUNDED_CORNER\n";
+  }
+  if(mColorBlur == ColorVisualShaderFeature::Blur::ENABLED)
+  {
+    vertexShaderPrefixList += "#define IS_REQUIRED_BLUR\n";
+  }
+  if(mColorBorderline == ColorVisualShaderFeature::Borderline::ENABLED && mColorBlur == ColorVisualShaderFeature::RoundedCorner::DISABLED)
+  {
+    vertexShaderPrefixList += "#define IS_REQUIRED_BORDERLINE\n";
+  }
+  if(mColorCutout == ColorVisualShaderFeature::Cutout::ENABLED)
+  {
+    vertexShaderPrefixList += "#define IS_REQUIRED_CUTOUT\n";
+  }
+}
+
+void ColorVisualShaderFeatureBuilder::GetFragmentShaderPrefixList(std::string& fragmentShaderPrefixList) const
+{
+  if(mColorRoundCorner == ColorVisualShaderFeature::RoundedCorner::ENABLED)
+  {
+    fragmentShaderPrefixList += "#define IS_REQUIRED_ROUNDED_CORNER\n";
+  }
+  if(mColorBlur == ColorVisualShaderFeature::Blur::ENABLED)
+  {
+    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(mColorBorderline == ColorVisualShaderFeature::Borderline::ENABLED && mColorBlur == ColorVisualShaderFeature::RoundedCorner::DISABLED)
+  {
+    fragmentShaderPrefixList += "#define IS_REQUIRED_BORDERLINE\n";
+  }
+  if(mColorCutout == ColorVisualShaderFeature::Cutout::ENABLED)
+  {
+    fragmentShaderPrefixList += "#define IS_REQUIRED_CUTOUT\n";
+  }
+}
+
+ColorVisualShaderFactory::ColorVisualShaderFactory()
+{
+}
+
+ColorVisualShaderFactory::~ColorVisualShaderFactory()
+{
+}
+
+Shader ColorVisualShaderFactory::GetShader(VisualFactoryCache& factoryCache, const ColorVisualShaderFeatureBuilder& featureBuilder)
+{
+  Shader                         shader;
+  VisualFactoryCache::ShaderType  shaderType = featureBuilder.GetShaderType();
+  shader     = factoryCache.GetShader(shaderType);
+
+  if(!shader)
+  {
+    std::string vertexShaderPrefixList;
+    std::string fragmentShaderPrefixList;
+    featureBuilder.GetVertexShaderPrefixList(vertexShaderPrefixList);
+    featureBuilder.GetFragmentShaderPrefixList(fragmentShaderPrefixList);
+
+    std::string vertexShader   = std::string(Dali::Shader::GetVertexShaderPrefix() + vertexShaderPrefixList + SHADER_COLOR_VISUAL_SHADER_VERT.data());
+    std::string fragmentShader = std::string(Dali::Shader::GetFragmentShaderPrefix() + fragmentShaderPrefixList + SHADER_COLOR_VISUAL_SHADER_FRAG.data());
+
+    shader = factoryCache.GenerateAndSaveShader(shaderType, vertexShader, fragmentShader);
+  }
+  return shader;
+
+}
+
+void ColorVisualShaderFactory::GetPreCompiledShader(RawShaderData& shaders)
+{
+  std::vector<std::string_view> vertexPrefix;
+  std::vector<std::string_view> fragmentPrefix;
+  std::vector<std::string_view> shaderName;
+  int                           shaderCount = 0;
+  shaders.shaderCount                       = 0;
+  for(uint32_t i = 0u; i < PREDEFINED_SHADER_TYPE_COUNT; ++i)
+  {
+    vertexPrefix.push_back(VertexPredefines[i]);
+    fragmentPrefix.push_back(FragmentPredefines[i]);
+    shaderName.push_back(Scripting::GetLinearEnumerationName<VisualFactoryCache::ShaderType>(ShaderTypePredefines[i], VISUAL_SHADER_TYPE_TABLE, VISUAL_SHADER_TYPE_TABLE_COUNT));
+    shaderCount++;
+  }
+
+  shaders.vertexPrefix   = std::move(vertexPrefix);
+  shaders.fragmentPrefix = std::move(fragmentPrefix);
+  shaders.shaderName     = std::move(shaderName);
+  shaders.vertexShader   = SHADER_COLOR_VISUAL_SHADER_VERT;
+  shaders.fragmentShader = SHADER_COLOR_VISUAL_SHADER_FRAG;
+  shaders.shaderCount    = shaderCount;
+}
+
+} // namespace Internal
+
+} // namespace Toolkit
+
+} // namespace Dali
diff --git a/dali-toolkit/internal/visuals/color/color-visual-shader-factory.h b/dali-toolkit/internal/visuals/color/color-visual-shader-factory.h
new file mode 100644 (file)
index 0000000..f55ea45
--- /dev/null
@@ -0,0 +1,172 @@
+#ifndef DALI_TOOLKIT_COLOR_VISUAL_SHADER_FACTORY_H
+#define DALI_TOOLKIT_COLOR_VISUAL_SHADER_FACTORY_H
+
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// EXTERNAL INCLUDES
+#include <dali/integration-api/adaptor-framework/shader-precompiler.h>
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/internal/visuals/visual-factory-cache.h>
+#include <dali-toolkit/devel-api/visual-factory/visual-shader-factory-interface.h>
+#include <string_view>
+
+namespace Dali
+{
+namespace Toolkit
+{
+namespace Internal
+{
+
+namespace ColorVisualShaderFeature
+{
+namespace RoundedCorner
+{
+/**
+ * @brief Whether use RoundedCorner, or not
+ */
+enum Type
+{
+  DISABLED = 0, ///< Color visual doesn't use rounded corner
+  ENABLED       ///< Color visual uses rounded corner
+};
+} // namespace RoundedCorner
+
+namespace Blur
+{
+/**
+ * @brief Whether use Blur, or not
+ */
+enum Type
+{
+  DISABLED = 0, ///< Color visual doesn't use blur
+  ENABLED       ///< Color visual uses blur
+};
+} // namespace Blur
+
+namespace Borderline
+{
+/**
+ * @brief Whether use Borderline
+ */
+enum Type
+{
+  DISABLED = 0, /// Color visual doesn't use Borderline
+  ENABLED       /// Color visual uses Borderline
+};
+} // namespace Borderline
+
+namespace Cutout
+{
+/**
+ * @brief Whether use Cutout, or not
+ */
+enum Type
+{
+  DISABLED = 0, ///< Color visual doesn't use Cutout
+  ENABLED       ///< Color visual uses Cutout
+};
+} // namespace Cutout
+} // namespace ColorVisualShaderFeature
+
+class ColorVisualShaderFeatureBuilder
+{
+public:
+  ColorVisualShaderFeatureBuilder();
+  ColorVisualShaderFeatureBuilder& EnableRoundCorner(bool enableRoundCorner);
+  ColorVisualShaderFeatureBuilder& EnableBorderLine(bool enableBorderLine);
+  ColorVisualShaderFeatureBuilder& EnableBlur(bool enableBlur);
+  ColorVisualShaderFeatureBuilder& EnableCutout(bool enableCutout);
+
+  VisualFactoryCache::ShaderType GetShaderType() const;
+  void GetVertexShaderPrefixList(std::string& vertexShaderPrefixList) const;
+  void GetFragmentShaderPrefixList(std::string& fragmentShaderPrefixList) const;
+
+  bool IsEnabledRoundCorner() const
+  {
+    return mColorRoundCorner == ColorVisualShaderFeature::RoundedCorner::ENABLED;
+  }
+  bool IsEnabledBorderLine() const
+  {
+    return mColorBorderline == ColorVisualShaderFeature::Borderline::ENABLED;
+  }
+  bool IsEnabledBlur() const
+  {
+    return mColorBlur == ColorVisualShaderFeature::Blur::ENABLED;
+  }
+  bool IsEnabledCutout() const
+  {
+    return mColorCutout == ColorVisualShaderFeature::Cutout::ENABLED;
+  }
+
+private:
+  ColorVisualShaderFeature::RoundedCorner::Type mColorRoundCorner : 2; ///< Whether use rounded corner, or not. default as RoundedCorner::DISABLED
+  ColorVisualShaderFeature::Borderline::Type    mColorBorderline : 2;  ///< Whether use border line, or not. default as Borderline::DISABLED
+  ColorVisualShaderFeature::Blur::Type          mColorBlur : 2;        ///< Whether use blur, or not. default as Blur::DISABLED
+  ColorVisualShaderFeature::Cutout::Type        mColorCutout : 2;      ///< Whether use cutout, or not. default as Cutout::DISABLED
+};
+
+/**
+ * ColorVisualShaderFactory is an object that provides and shares shaders between color visuals
+ */
+class ColorVisualShaderFactory : public VisualShaderFactoryInterface
+{
+public:
+  /**
+   * @brief Constructor
+   */
+  ColorVisualShaderFactory();
+
+  /**
+   * @brief Destructor
+   */
+  ~ColorVisualShaderFactory() override;
+
+public:
+  /**
+   * @brief Get the standard color rendering shader.
+   * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
+   * @param[in] featureBuilder Collection of current text shader's features
+   * @return The standard text rendering shader with features.
+  */
+  Shader GetShader(VisualFactoryCache& factoryCache, const ColorVisualShaderFeatureBuilder& featureBuilder);
+
+public: // Implementation of VisualShaderFactoryInterface
+  /**
+   * @copydoc Dali::Toolkit::VisualShaderFactoryInterface::GetPreCompiledShader
+   */
+  void GetPreCompiledShader(RawShaderData& shaders) override;
+
+protected:
+  /**
+   * Undefined copy constructor.
+   */
+  ColorVisualShaderFactory(const ColorVisualShaderFactory&) = delete;
+
+  /**
+   * Undefined assignment operator.
+   */
+  ColorVisualShaderFactory& operator=(const ColorVisualShaderFactory& rhs) = delete;
+};
+
+} // namespace Internal
+
+} // namespace Toolkit
+
+} // namespace Dali
+
+#endif // DALI_TOOLKIT_COLOR_VISUAL_SHADER_FACTORY_H
index 435eac05e5b81aef6c87277aa8de512113a2a372..943467233086d0cce2c704ca13fc874c676f7d71 100644 (file)
@@ -51,49 +51,22 @@ DALI_ENUM_TO_STRING_TABLE_BEGIN(CUTOUT_POLICY)
   DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::Toolkit::DevelColorVisual::CutoutPolicy, CUTOUT_VIEW_WITH_CORNER_RADIUS)
 DALI_ENUM_TO_STRING_TABLE_END(CUTOUT_POLICY)
 
-constexpr VisualFactoryCache::ShaderType SHADER_TYPE_TABLE[] = {
-  VisualFactoryCache::COLOR_SHADER,
-  VisualFactoryCache::COLOR_SHADER_ROUNDED_CORNER,
-  VisualFactoryCache::COLOR_SHADER_BORDERLINE,
-  VisualFactoryCache::COLOR_SHADER_ROUNDED_BORDERLINE,
-  VisualFactoryCache::COLOR_SHADER_BLUR_EDGE,
-  VisualFactoryCache::COLOR_SHADER_ROUNDED_CORNER_BLUR_EDGE,
-};
-
-constexpr VisualFactoryCache::ShaderType SHADER_TYPE_WITH_CUTOUT_TABLE[] = {
-  VisualFactoryCache::COLOR_SHADER_CUTOUT,
-  VisualFactoryCache::COLOR_SHADER_CUTOUT_ROUNDED_CORNER,
-  VisualFactoryCache::COLOR_SHADER_CUTOUT_BORDERLINE,
-  VisualFactoryCache::COLOR_SHADER_CUTOUT_ROUNDED_BORDERLINE,
-  VisualFactoryCache::COLOR_SHADER_CUTOUT_BLUR_EDGE,
-  VisualFactoryCache::COLOR_SHADER_CUTOUT_ROUNDED_CORNER_BLUR_EDGE,
-};
-
-// enum of required list when we select shader
-enum ColorVisualRequireFlag
-{
-  DEFAULT        = 0,
-  ROUNDED_CORNER = 1 << 0,
-  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)
+ColorVisualPtr ColorVisual::New(VisualFactoryCache& factoryCache, ColorVisualShaderFactory& shaderFactory, const Property::Map& properties)
 {
-  ColorVisualPtr colorVisualPtr(new ColorVisual(factoryCache));
+  ColorVisualPtr colorVisualPtr(new ColorVisual(factoryCache, shaderFactory));
   colorVisualPtr->SetProperties(properties);
   colorVisualPtr->Initialize();
   return colorVisualPtr;
 }
 
-ColorVisual::ColorVisual(VisualFactoryCache& factoryCache)
+ColorVisual::ColorVisual(VisualFactoryCache& factoryCache, ColorVisualShaderFactory& shaderFactory)
 : Visual::Base(factoryCache, Visual::FittingMode::DONT_CARE, Toolkit::Visual::COLOR),
   mBlurRadius(0.0f),
   mCutoutPolicy(DevelColorVisual::CutoutPolicy::NONE),
-  mAlwaysUsingBlurRadius(false)
+  mAlwaysUsingBlurRadius(false),
+  mColorVisualShaderFactory(shaderFactory)
 {
 }
 
@@ -269,67 +242,13 @@ void ColorVisual::OnInitialize()
 
 Shader ColorVisual::GenerateShader() const
 {
-  Shader                         shader;
-  VisualFactoryCache::ShaderType shaderType;
-
-  bool roundedCorner  = IsRoundedCornerRequired();
-  bool borderline     = IsBorderlineRequired();
-  bool blur           = IsBlurRequired();
-  bool cutout         = IsCutoutRequired();
-  int  shaderTypeFlag = ColorVisualRequireFlag::DEFAULT;
-
-  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;
-  }
-
-  shaderType = cutout ? SHADER_TYPE_WITH_CUTOUT_TABLE[shaderTypeFlag] : SHADER_TYPE_TABLE[shaderTypeFlag];
-  shader     = mFactoryCache.GetShader(shaderType);
-  if(!shader)
-  {
-    std::string vertexShaderPrefixList;
-    std::string fragmentShaderPrefixList;
-    if(roundedCorner)
-    {
-      vertexShaderPrefixList += "#define IS_REQUIRED_ROUNDED_CORNER\n";
-      fragmentShaderPrefixList += "#define IS_REQUIRED_ROUNDED_CORNER\n";
-    }
-    if(blur)
-    {
-      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";
-    }
-    if(cutout)
-    {
-      vertexShaderPrefixList += "#define IS_REQUIRED_CUTOUT\n";
-      fragmentShaderPrefixList += "#define IS_REQUIRED_CUTOUT\n";
-    }
-
-    shader = mFactoryCache.GenerateAndSaveShader(shaderType,
-                                                 Dali::Shader::GetVertexShaderPrefix() + vertexShaderPrefixList + SHADER_COLOR_VISUAL_SHADER_VERT.data(),
-                                                 Dali::Shader::GetFragmentShaderPrefix() + fragmentShaderPrefixList + SHADER_COLOR_VISUAL_SHADER_FRAG.data());
-  }
+  Shader shader = mColorVisualShaderFactory.GetShader(
+    mFactoryCache,
+    ColorVisualShaderFeatureBuilder()
+    .EnableBlur(IsBlurRequired())
+    .EnableBorderLine(IsBorderlineRequired())
+    .EnableRoundCorner(IsRoundedCornerRequired())
+    .EnableCutout(IsCutoutRequired()));
 
   return shader;
 }
index ae9388582a04466efae24bb5687074cc8a3a313a..44f1180525e4cbee23ce94f3b744667c18c44679 100644 (file)
@@ -24,6 +24,7 @@
 // INTERNAL INCLUDES
 #include <dali-toolkit/devel-api/visuals/color-visual-properties-devel.h>
 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
+#include <dali-toolkit/internal/visuals/color/color-visual-shader-factory.h>
 
 namespace Dali
 {
@@ -50,10 +51,11 @@ public:
    * @brief Create a new color visual.
    *
    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
+   * @param[in] shaderFactory A reference to the ColorVisualShaderFactory object
    * @param[in] properties A Property::Map containing settings for this visual
    * @return A smart-pointer to the newly allocated visual.
    */
-  static ColorVisualPtr New(VisualFactoryCache& factoryCache, const Property::Map& properties);
+  static ColorVisualPtr New(VisualFactoryCache& factoryCache, ColorVisualShaderFactory& shaderFactory, const Property::Map& properties);
 
 public: // from Visual
   /**
@@ -76,8 +78,9 @@ protected:
    * @brief Constructor.
    *
    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
+   * @param[in] shaderFactory A reference to the ColorVisualShaderFactory object
    */
-  ColorVisual(VisualFactoryCache& factoryCache);
+  ColorVisual(VisualFactoryCache& factoryCache, ColorVisualShaderFactory& shaderFactory);
 
   /**
    * @brief A reference counted object may only be deleted by calling Unreference().
@@ -151,6 +154,7 @@ private:
 
   DevelColorVisual::CutoutPolicy::Type mCutoutPolicy : 3;          ///< The policy of cutout
   bool                                 mAlwaysUsingBlurRadius : 1; ///< Whether we need the blur radius in shader always.
+  ColorVisualShaderFactory&            mColorVisualShaderFactory;  ///< The shader factory for color visual.
 };
 
 } // namespace Internal
index 77ea3c086f6eb017fb6375f03574357bd7c976fe..b254426ea964d66802c3b3666d3151b026e29741 100644 (file)
@@ -40,9 +40,9 @@ constexpr int              NATIVE_SHADER_TYPE_OFFSET = VisualFactoryCache::Shade
 constexpr std::string_view Y_FLIP_MASK_TEXTURE       = "uYFlipMaskTexture";
 constexpr float            NOT_FLIP_MASK_TEXTURE     = 0.0f;
 
-constexpr auto SHADER_TYPE_COUNT = 6u;
+constexpr auto PREDEFINED_SHADER_TYPE_COUNT = 6u;
 
-constexpr std::string_view VertexPredefines[SHADER_TYPE_COUNT]{
+constexpr std::string_view VertexPredefines[PREDEFINED_SHADER_TYPE_COUNT]{
   "",                                     // VisualFactoryCache::IMAGE_SHADER,
   "#define IS_REQUIRED_ROUNDED_CORNER\n", // VisualFactoryCache::IMAGE_SHADER_ROUNDED_CORNER,
   "",                                     // VisualFactoryCache::IMAGE_SHADER_YUV_TO_RGB,
@@ -50,7 +50,7 @@ constexpr std::string_view VertexPredefines[SHADER_TYPE_COUNT]{
   "",                                     // VisualFactoryCache::IMAGE_SHADER_YUV_AND_RGB,
   "#define IS_REQUIRED_ROUNDED_CORNER\n", // VisualFactoryCache::IMAGE_SHADER_ROUNDED_CORNER_YUV_AND_RGB,
 };
-constexpr std::string_view FragmentPredefines[SHADER_TYPE_COUNT]{
+constexpr std::string_view FragmentPredefines[PREDEFINED_SHADER_TYPE_COUNT]{
   "",                                                                              // VisualFactoryCache::IMAGE_SHADER,
   "#define IS_REQUIRED_ROUNDED_CORNER\n",                                          // VisualFactoryCache::IMAGE_SHADER_ROUNDED_CORNER,
   "#define IS_REQUIRED_YUV_TO_RGB\n",                                              // VisualFactoryCache::IMAGE_SHADER_YUV_TO_RGB,
@@ -58,7 +58,7 @@ constexpr std::string_view FragmentPredefines[SHADER_TYPE_COUNT]{
   "#define IS_REQUIRED_UNIFIED_YUV_AND_RGB\n",                                     // VisualFactoryCache::IMAGE_SHADER_YUV_AND_RGB,
   "#define IS_REQUIRED_ROUNDED_CORNER\n#define IS_REQUIRED_UNIFIED_YUV_AND_RGB\n", // VisualFactoryCache::IMAGE_SHADER_ROUNDED_CORNER_YUV_AND_RGB,
 };
-constexpr VisualFactoryCache::ShaderType ShaderTypePredefines[SHADER_TYPE_COUNT]{
+constexpr VisualFactoryCache::ShaderType ShaderTypePredefines[PREDEFINED_SHADER_TYPE_COUNT]{
   VisualFactoryCache::ShaderType::IMAGE_SHADER,
   VisualFactoryCache::ShaderType::IMAGE_SHADER_ROUNDED_CORNER,
   VisualFactoryCache::ShaderType::IMAGE_SHADER_YUV_TO_RGB,
@@ -77,7 +77,7 @@ ImageVisualShaderFactory::~ImageVisualShaderFactory()
 {
 }
 
-Shader ImageVisualShaderFactory::GetShader(VisualFactoryCache& factoryCache, ImageVisualShaderFeatureBuilder& featureBuilder)
+Shader ImageVisualShaderFactory::GetShader(VisualFactoryCache& factoryCache, const ImageVisualShaderFeatureBuilder& featureBuilder)
 {
   Shader                         shader;
   VisualFactoryCache::ShaderType shaderType = featureBuilder.GetShaderType();
@@ -181,7 +181,7 @@ void ImageVisualShaderFactory::GetPreCompiledShader(RawShaderData& shaders)
   std::vector<std::string_view> shaderName;
   shaders.shaderCount = 0;
   int shaderCount     = 0;
-  for(uint32_t i = 0; i < SHADER_TYPE_COUNT; ++i)
+  for(uint32_t i = 0; i < PREDEFINED_SHADER_TYPE_COUNT; ++i)
   {
     vertexPrefix.push_back(VertexPredefines[i]);
     fragmentPrefix.push_back(FragmentPredefines[i]);
@@ -189,9 +189,9 @@ void ImageVisualShaderFactory::GetPreCompiledShader(RawShaderData& shaders)
     shaderCount++;
   }
 
-  shaders.vertexPrefix   = vertexPrefix;
-  shaders.fragmentPrefix = fragmentPrefix;
-  shaders.shaderName     = shaderName;
+  shaders.vertexPrefix   = std::move(vertexPrefix);
+  shaders.fragmentPrefix = std::move(fragmentPrefix);
+  shaders.shaderName     = std::move(shaderName);
   shaders.vertexShader   = SHADER_IMAGE_VISUAL_SHADER_VERT;
   shaders.fragmentShader = SHADER_IMAGE_VISUAL_SHADER_FRAG;
   shaders.shaderCount    = shaderCount;
index 21f6ec391190bfc1fa25c399285a8569f4ce763b..d79d258466ab5aa6935c5f867c27a4e3946edef5 100644 (file)
@@ -23,6 +23,7 @@
 // INTERNAL INCLUDES
 #include <dali-toolkit/internal/visuals/image/image-visual-shader-feature-builder.h>
 #include <dali-toolkit/internal/visuals/visual-factory-cache.h>
+#include <dali-toolkit/devel-api/visual-factory/visual-shader-factory-interface.h>
 #include <string_view>
 
 namespace Dali
@@ -34,7 +35,7 @@ namespace Internal
 /**
  * ImageVisualShaderFactory is an object that provides and shares shaders between image visuals
  */
-class ImageVisualShaderFactory
+class ImageVisualShaderFactory : public VisualShaderFactoryInterface
 {
 public:
   /**
@@ -53,7 +54,7 @@ public:
    * @param[in] featureBuilder Collection of current image shader's features
    * @return The standard image rendering shader with features.
    */
-  Shader GetShader(VisualFactoryCache& factoryCache, ImageVisualShaderFeatureBuilder& featureBuilder);
+  Shader GetShader(VisualFactoryCache& factoryCache, const ImageVisualShaderFeatureBuilder& featureBuilder);
 
   /**
    * @brief Request the default vertex shader source.
@@ -67,11 +68,11 @@ public:
    */
   std::string_view GetFragmentShaderSource();
 
+public: // Implementation of VisualShaderFactoryInterface
   /**
-   * @brief Get the default shader source.
-   * @param[in] shaders shaderList for precompile
+   * @copydoc Dali::Toolkit::VisualShaderFactoryInterface::GetPreCompiledShader
    */
-  void GetPreCompiledShader(RawShaderData& shaders);
+  void GetPreCompiledShader(RawShaderData& shaders) override;
 
 protected:
   /**
index 7945470b082321716d2f9f259d3eae3be0a7979f..34aab0c5e76ddce89d57df7c27c4f6eca220045e 100644 (file)
@@ -111,7 +111,7 @@ ImageVisualShaderFeatureBuilder& ImageVisualShaderFeatureBuilder::EnableYuvToRgb
   return *this;
 }
 
-VisualFactoryCache::ShaderType ImageVisualShaderFeatureBuilder::GetShaderType()
+VisualFactoryCache::ShaderType ImageVisualShaderFeatureBuilder::GetShaderType() const
 {
   VisualFactoryCache::ShaderType shaderType = VisualFactoryCache::IMAGE_SHADER;
   if(mTextureAtlas == ImageVisualShaderFeature::TextureAtlas::ENABLED)
@@ -155,14 +155,14 @@ VisualFactoryCache::ShaderType ImageVisualShaderFeatureBuilder::GetShaderType()
   return shaderType;
 }
 
-ImageVisualShaderFeature::ChangeFragmentShader::Type ImageVisualShaderFeatureBuilder::NeedToChangeFragmentShader()
+ImageVisualShaderFeature::ChangeFragmentShader::Type ImageVisualShaderFeatureBuilder::NeedToChangeFragmentShader() const
 {
   return (mTexture && DevelTexture::IsNative(mTexture))
            ? ImageVisualShaderFeature::ChangeFragmentShader::NEED_CHANGE
            : ImageVisualShaderFeature::ChangeFragmentShader::DONT_CHANGE;
 }
 
-void ImageVisualShaderFeatureBuilder::GetVertexShaderPrefixList(std::string& vertexShaderPrefixList)
+void ImageVisualShaderFeatureBuilder::GetVertexShaderPrefixList(std::string& vertexShaderPrefixList) const
 {
   if(mTextureAtlas != ImageVisualShaderFeature::TextureAtlas::ENABLED)
   {
@@ -181,7 +181,7 @@ void ImageVisualShaderFeatureBuilder::GetVertexShaderPrefixList(std::string& ver
   }
 }
 
-void ImageVisualShaderFeatureBuilder::GetFragmentShaderPrefixList(std::string& fragmentShaderPrefixList)
+void ImageVisualShaderFeatureBuilder::GetFragmentShaderPrefixList(std::string& fragmentShaderPrefixList) const
 {
   if(mTextureAtlas == ImageVisualShaderFeature::TextureAtlas::ENABLED)
   {
@@ -219,7 +219,7 @@ void ImageVisualShaderFeatureBuilder::GetFragmentShaderPrefixList(std::string& f
   }
 }
 
-Dali::Texture ImageVisualShaderFeatureBuilder::GetTexture()
+Dali::Texture ImageVisualShaderFeatureBuilder::GetTexture() const
 {
   return mTexture;
 }
index 635a06c1108babbf294afdc34ab79d4868d82c2a..bef845f1ae0fc3a1ea54b8addc0671b6b4f10521 100644 (file)
@@ -145,14 +145,14 @@ public:
 
   ImageVisualShaderFeatureBuilder& EnableYuvToRgb(bool enableYuvToRgb, bool enableUnifiedYuvAndRgb = false);
 
-  VisualFactoryCache::ShaderType GetShaderType();
+  VisualFactoryCache::ShaderType GetShaderType() const;
 
-  ImageVisualShaderFeature::ChangeFragmentShader::Type NeedToChangeFragmentShader();
+  ImageVisualShaderFeature::ChangeFragmentShader::Type NeedToChangeFragmentShader() const;
 
-  void GetVertexShaderPrefixList(std::string& vertexShaderPrefixList);
-  void GetFragmentShaderPrefixList(std::string& fragmentShaderPrefixList);
+  void GetVertexShaderPrefixList(std::string& vertexShaderPrefixList) const;
+  void GetFragmentShaderPrefixList(std::string& fragmentShaderPrefixList) const;
 
-  Dali::Texture GetTexture();
+  Dali::Texture GetTexture() const;
 
   bool IsEnabledAlphaMaskingOnRendering() const;
 
index 693c39eb541ee6a1c90dbdfc7f222aec6b36d3fd..62928b439305735bb5078cf3d914aec199b9891c 100644 (file)
@@ -56,14 +56,14 @@ const VisualFactoryCache::ShaderType SHADER_TYPE_TABLE[] =
     VisualFactoryCache::TEXT_SHADER_MULTI_COLOR_TEXT_WITH_STYLE_AND_OVERLAY,
 };
 
-static constexpr auto      SHADER_TYPE_COUNT = 1u;
-constexpr std::string_view VertexPredefines[SHADER_TYPE_COUNT]{
+static constexpr auto      PREDEFINED_SHADER_TYPE_COUNT = 1u;
+constexpr std::string_view VertexPredefines[PREDEFINED_SHADER_TYPE_COUNT]{
   "", // VisualFactoryCache::TEXT_SHADER_SINGLE_COLOR_TEXT
 };
-constexpr std::string_view FragmentPredefines[SHADER_TYPE_COUNT]{
+constexpr std::string_view FragmentPredefines[PREDEFINED_SHADER_TYPE_COUNT]{
   "", // VisualFactoryCache::TEXT_SHADER_SINGLE_COLOR_TEXT
 };
-constexpr VisualFactoryCache::ShaderType ShaderTypePredefines[SHADER_TYPE_COUNT]{
+constexpr VisualFactoryCache::ShaderType ShaderTypePredefines[PREDEFINED_SHADER_TYPE_COUNT]{
   VisualFactoryCache::ShaderType::TEXT_SHADER_SINGLE_COLOR_TEXT,
 };
 
@@ -71,6 +71,14 @@ constexpr VisualFactoryCache::ShaderType ShaderTypePredefines[SHADER_TYPE_COUNT]
 
 namespace TextVisualShaderFeature
 {
+FeatureBuilder::FeatureBuilder()
+: mTextMultiColor(TextMultiColor::SINGLE_COLOR_TEXT),
+  mTextEmoji(TextEmoji::NO_EMOJI),
+  mTextStyle(TextStyle::NO_STYLES),
+  mTextOverlay(TextOverlay::NO_OVERLAY)
+{
+}
+
 FeatureBuilder& FeatureBuilder::EnableMultiColor(bool enableMultiColor)
 {
   mTextMultiColor = enableMultiColor ? TextMultiColor::MULTI_COLOR_TEXT : TextMultiColor::SINGLE_COLOR_TEXT;
@@ -91,70 +99,82 @@ FeatureBuilder& FeatureBuilder::EnableOverlay(bool enableOverlay)
   mTextOverlay = enableOverlay ? TextOverlay::HAS_OVERLAY : TextOverlay::NO_OVERLAY;
   return *this;
 }
-} // namespace TextVisualShaderFeature
-
-TextVisualShaderFactory::TextVisualShaderFactory()
-{
-}
 
-TextVisualShaderFactory::~TextVisualShaderFactory()
+VisualFactoryCache::ShaderType FeatureBuilder::GetShaderType() const
 {
-}
-
-Shader TextVisualShaderFactory::GetShader(VisualFactoryCache& factoryCache, const TextVisualShaderFeature::FeatureBuilder& featureBuilder)
-{
-  Shader                         shader;
   uint32_t                       shaderTypeFlag = static_cast<uint32_t>(TextVisualRequireFlag::DEFAULT);
   VisualFactoryCache::ShaderType shaderType     = VisualFactoryCache::TEXT_SHADER_SINGLE_COLOR_TEXT;
 
-  const auto& multiColor = featureBuilder.mTextMultiColor;
-  const auto& emoji      = featureBuilder.mTextEmoji;
-  const auto& style      = featureBuilder.mTextStyle;
-  const auto& overlay    = featureBuilder.mTextOverlay;
-
-  if(style == TextVisualShaderFeature::TextStyle::HAS_STYLES)
+  if(mTextStyle == TextVisualShaderFeature::TextStyle::HAS_STYLES)
   {
     shaderTypeFlag |= static_cast<uint32_t>(TextVisualRequireFlag::STYLES);
   }
-  if(overlay == TextVisualShaderFeature::TextOverlay::HAS_OVERLAY)
+  if(mTextOverlay == TextVisualShaderFeature::TextOverlay::HAS_OVERLAY)
   {
     shaderTypeFlag |= static_cast<uint32_t>(TextVisualRequireFlag::OVERLAY);
   }
   // multi color can also render emoji. If multi color text, dont consider emoji
-  if(multiColor != TextVisualShaderFeature::TextMultiColor::MULTI_COLOR_TEXT && emoji == TextVisualShaderFeature::TextEmoji::HAS_EMOJI)
+  if(mTextMultiColor != TextVisualShaderFeature::TextMultiColor::MULTI_COLOR_TEXT && mTextEmoji == TextVisualShaderFeature::TextEmoji::HAS_EMOJI)
   {
     shaderTypeFlag |= static_cast<uint32_t>(TextVisualRequireFlag::EMOJI);
   }
-  if(multiColor == TextVisualShaderFeature::TextMultiColor::MULTI_COLOR_TEXT)
+  if(mTextMultiColor == TextVisualShaderFeature::TextMultiColor::MULTI_COLOR_TEXT)
   {
     shaderTypeFlag |= static_cast<uint32_t>(TextVisualRequireFlag::MULTI_COLOR);
   }
 
   shaderType = SHADER_TYPE_TABLE[shaderTypeFlag];
+  return shaderType;
+}
+
+void FeatureBuilder::GetVertexShaderPrefixList(std::string& vertexShaderPrefixList) const
+{
+  // Do nothing
+}
+
+void FeatureBuilder::GetFragmentShaderPrefixList(std::string& fragmentShaderPrefixList) const
+{
+  if(mTextStyle == TextVisualShaderFeature::TextStyle::HAS_STYLES)
+  {
+    fragmentShaderPrefixList += "#define IS_REQUIRED_STYLE\n";
+  }
+  if(mTextOverlay == TextVisualShaderFeature::TextOverlay::HAS_OVERLAY)
+  {
+    fragmentShaderPrefixList += "#define IS_REQUIRED_OVERLAY\n";
+  }
+  // multi color can also render emoji. If multi color text, dont consider emoji
+  if(mTextMultiColor != TextVisualShaderFeature::TextMultiColor::MULTI_COLOR_TEXT && mTextEmoji == TextVisualShaderFeature::TextEmoji::HAS_EMOJI)
+  {
+    fragmentShaderPrefixList += "#define IS_REQUIRED_EMOJI\n";
+  }
+  if(mTextMultiColor == TextVisualShaderFeature::TextMultiColor::MULTI_COLOR_TEXT)
+  {
+    fragmentShaderPrefixList += "#define IS_REQUIRED_MULTI_COLOR\n";
+  }
+}
+
+} // namespace TextVisualShaderFeature
+
+TextVisualShaderFactory::TextVisualShaderFactory()
+{
+}
+
+TextVisualShaderFactory::~TextVisualShaderFactory()
+{
+}
+
+Shader TextVisualShaderFactory::GetShader(VisualFactoryCache& factoryCache, const TextVisualShaderFeature::FeatureBuilder& featureBuilder)
+{
+  Shader                         shader;
+  VisualFactoryCache::ShaderType  shaderType = featureBuilder.GetShaderType();
   shader     = factoryCache.GetShader(shaderType);
 
   if(!shader)
   {
     std::string vertexShaderPrefixList;
     std::string fragmentShaderPrefixList;
-
-    if(style == TextVisualShaderFeature::TextStyle::HAS_STYLES)
-    {
-      fragmentShaderPrefixList += "#define IS_REQUIRED_STYLE\n";
-    }
-    if(overlay == TextVisualShaderFeature::TextOverlay::HAS_OVERLAY)
-    {
-      fragmentShaderPrefixList += "#define IS_REQUIRED_OVERLAY\n";
-    }
-    // multi color can also render emoji. If multi color text, dont consider emoji
-    if(multiColor != TextVisualShaderFeature::TextMultiColor::MULTI_COLOR_TEXT && emoji == TextVisualShaderFeature::TextEmoji::HAS_EMOJI)
-    {
-      fragmentShaderPrefixList += "#define IS_REQUIRED_EMOJI\n";
-    }
-    if(multiColor == TextVisualShaderFeature::TextMultiColor::MULTI_COLOR_TEXT)
-    {
-      fragmentShaderPrefixList += "#define IS_REQUIRED_MULTI_COLOR\n";
-    }
+    featureBuilder.GetVertexShaderPrefixList(vertexShaderPrefixList);
+    featureBuilder.GetFragmentShaderPrefixList(fragmentShaderPrefixList);
 
     std::string vertexShader   = std::string(Dali::Shader::GetVertexShaderPrefix() + vertexShaderPrefixList + SHADER_TEXT_VISUAL_SHADER_VERT.data());
     std::string fragmentShader = std::string(Dali::Shader::GetFragmentShaderPrefix() + fragmentShaderPrefixList + SHADER_TEXT_VISUAL_SHADER_FRAG.data());
@@ -170,7 +190,7 @@ void TextVisualShaderFactory::GetPreCompiledShader(RawShaderData& shaders)
   std::vector<std::string_view> fragmentPrefix;
   std::vector<std::string_view> shaderName;
   int                           shaderCount = 0;
-  for(uint32_t i = 0; i < SHADER_TYPE_COUNT; ++i)
+  for(uint32_t i = 0; i < PREDEFINED_SHADER_TYPE_COUNT; ++i)
   {
     vertexPrefix.push_back(VertexPredefines[i]);
     fragmentPrefix.push_back(FragmentPredefines[i]);
@@ -178,9 +198,9 @@ void TextVisualShaderFactory::GetPreCompiledShader(RawShaderData& shaders)
     shaderCount++;
   }
 
-  shaders.vertexPrefix   = vertexPrefix;
-  shaders.fragmentPrefix = fragmentPrefix;
-  shaders.shaderName     = shaderName;
+  shaders.vertexPrefix   = std::move(vertexPrefix);
+  shaders.fragmentPrefix = std::move(fragmentPrefix);
+  shaders.shaderName     = std::move(shaderName);
   shaders.vertexShader   = SHADER_TEXT_VISUAL_SHADER_VERT;
   shaders.fragmentShader = SHADER_TEXT_VISUAL_SHADER_FRAG;
   shaders.shaderCount    = shaderCount;
index 237edc7242dc20a2d727692b537633ed1a0e4db4..f354f6449ed92b119a16bbbedd705c84e0c61908 100644 (file)
@@ -22,6 +22,7 @@
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/internal/visuals/visual-factory-cache.h>
+#include <dali-toolkit/devel-api/visual-factory/visual-shader-factory-interface.h>
 #include <string_view>
 
 namespace Dali
@@ -86,21 +87,19 @@ enum Type
 /**
  * @brief Collection of current text visual feature.
  */
-struct FeatureBuilder
+class FeatureBuilder
 {
-  FeatureBuilder()
-  : mTextMultiColor(TextMultiColor::SINGLE_COLOR_TEXT),
-    mTextEmoji(TextEmoji::NO_EMOJI),
-    mTextStyle(TextStyle::NO_STYLES),
-    mTextOverlay(TextOverlay::NO_OVERLAY)
-  {
-  }
-
+public:
+  FeatureBuilder();
   FeatureBuilder& EnableMultiColor(bool enableMultiColor);
   FeatureBuilder& EnableEmoji(bool enableEmoji);
   FeatureBuilder& EnableStyle(bool enableStyle);
   FeatureBuilder& EnableOverlay(bool enableOverlay);
 
+  VisualFactoryCache::ShaderType GetShaderType() const;
+  void GetVertexShaderPrefixList(std::string& vertexShaderPrefixList) const;
+  void GetFragmentShaderPrefixList(std::string& fragmentShaderPrefixList) const;
+
   bool IsEnabledMultiColor() const
   {
     return mTextMultiColor == TextMultiColor::MULTI_COLOR_TEXT;
@@ -118,6 +117,7 @@ struct FeatureBuilder
     return mTextOverlay == TextOverlay::HAS_OVERLAY;
   }
 
+private:
   TextMultiColor::Type mTextMultiColor : 2; ///< Whether text has multiple color, or not. default as TextMultiColor::SINGLE_COLOR_TEXT
   TextEmoji::Type      mTextEmoji : 2;      ///< Whether text has emoji, or not. default as TextEmoji::NO_EMOJI
   TextStyle::Type      mTextStyle : 2;      ///< Whether text has style, or not. default as TextStyle::NO_STYLES
@@ -129,7 +129,7 @@ struct FeatureBuilder
 /**
  * TextVisualShaderFactory is an object that provides and shares shaders for text visuals
  */
-class TextVisualShaderFactory
+class TextVisualShaderFactory : public VisualShaderFactoryInterface
 {
 public:
   /**
@@ -150,11 +150,11 @@ public:
    */
   Shader GetShader(VisualFactoryCache& factoryCache, const TextVisualShaderFeature::FeatureBuilder& featureBuilder);
 
+public: // Implementation of VisualShaderFactoryInterface
   /**
-   * @brief Get the default shader source.
-   * @param[in] shaders shaderList for precompile
+   * @copydoc Dali::Toolkit::VisualShaderFactoryInterface::GetPreCompiledShader
    */
-  void GetPreCompiledShader(RawShaderData& shaders);
+  void GetPreCompiledShader(RawShaderData& shaders) override;
 
 protected:
   /**
index 5b9e3440d209e2998f90f6945eb71799ebb7b002..da1874cab803f16f9c85600df13e0f19ebf5bf5a 100644 (file)
@@ -301,7 +301,8 @@ TextVisual::~TextVisual()
 void TextVisual::OnInitialize()
 {
   Geometry geometry = mFactoryCache.GetGeometry(VisualFactoryCache::QUAD_GEOMETRY);
-  Shader   shader   = GetTextShader(mFactoryCache, TextVisualShaderFeature::FeatureBuilder());
+  auto featureBuilder = TextVisualShaderFeature::FeatureBuilder();
+  Shader   shader   = GetTextShader(mFactoryCache, featureBuilder);
 
   mImpl->mRenderer = VisualRenderer::New(geometry, shader);
   mImpl->mRenderer.ReserveCustomProperties(CUSTOM_PROPERTY_COUNT);
@@ -1364,7 +1365,7 @@ TextureSet TextVisual::GetTextTexture(const Vector2& size)
   return textureSet;
 }
 
-Shader TextVisual::GetTextShader(VisualFactoryCache& factoryCache, const TextVisualShaderFeature::FeatureBuilder& featureBuilder)
+Shader TextVisual::GetTextShader(VisualFactoryCache& factoryCache, TextVisualShaderFeature::FeatureBuilder& featureBuilder)
 {
   // Cache feature builder informations.
   mTextShaderFeatureCache = featureBuilder;
index 0bc00d4b7fc367abb256e61e1d1af3166de892a8..69611484d1280ba5fb8fc20ee1f67b775addd16d 100644 (file)
@@ -350,7 +350,7 @@ private:
    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
    * @param[in] featureBuilder Collection of current text shader's features. It will be cached as text visual.
    */
-  Shader GetTextShader(VisualFactoryCache& factoryCache, const TextVisualShaderFeature::FeatureBuilder& featureBuilder);
+  Shader GetTextShader(VisualFactoryCache& factoryCache, TextVisualShaderFeature::FeatureBuilder& featureBuilder);
 
   /**
    * @brief Set the text to be always rendered
index 70a994b10e67ef91d21bee9e0b575de3dec9ed74..4c4c73613e944c081b7c969023c8ce80800e5ed3 100644 (file)
@@ -36,6 +36,7 @@
 #include <dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.h>
 #include <dali-toolkit/internal/visuals/arc/arc-visual.h>
 #include <dali-toolkit/internal/visuals/border/border-visual.h>
+#include <dali-toolkit/internal/visuals/color/color-visual-shader-factory.h>
 #include <dali-toolkit/internal/visuals/color/color-visual.h>
 #include <dali-toolkit/internal/visuals/gradient/gradient-visual.h>
 #include <dali-toolkit/internal/visuals/image/image-visual-shader-factory.h>
@@ -77,27 +78,13 @@ DALI_TYPE_REGISTRATION_BEGIN_CREATE(Toolkit::VisualFactory, Dali::BaseHandle, Cr
 DALI_TYPE_REGISTRATION_END()
 const char* const BROKEN_IMAGE_FILE_NAME = "broken.png"; ///< The file name of the broken image.
 
-static constexpr auto SHADER_TYPE_COUNT = 2u;
-
-constexpr std::string_view VertexPredefines[SHADER_TYPE_COUNT]{
-  "",                                     //VisualFactoryCache::COLOR_SHADER
-  "#define IS_REQUIRED_ROUNDED_CORNER\n", //VisualFactoryCache::COLOR_SHADER_ROUNDED_CORNER
-};
-constexpr std::string_view FragmentPredefines[SHADER_TYPE_COUNT]{
-  "",                                     //VisualFactoryCache::COLOR_SHADER
-  "#define IS_REQUIRED_ROUNDED_CORNER\n", //VisualFactoryCache::COLOR_SHADER_ROUNDED_CORNER
-};
-constexpr VisualFactoryCache::ShaderType ShaderTypePredefines[SHADER_TYPE_COUNT]{
-  VisualFactoryCache::ShaderType::COLOR_SHADER,
-  VisualFactoryCache::ShaderType::COLOR_SHADER_ROUNDED_CORNER,
-};
-
 } // namespace
 
 VisualFactory::VisualFactory(bool debugEnabled)
 : mFactoryCache(),
   mImageVisualShaderFactory(),
   mTextVisualShaderFactory(),
+  mColorVisualShaderFactory(),
   mSlotDelegate(this),
   mIdleCallback(nullptr),
   mDefaultCreationOptions(Toolkit::VisualFactory::CreationOptions::NONE),
@@ -170,7 +157,7 @@ Toolkit::Visual::Base VisualFactory::CreateVisual(const Property::Map& propertyM
 
     case Toolkit::Visual::COLOR:
     {
-      visualPtr = ColorVisual::New(GetFactoryCache(), propertyMap);
+      visualPtr = ColorVisual::New(GetFactoryCache(), GetColorVisualShaderFactory(), propertyMap);
       break;
     }
 
@@ -440,6 +427,8 @@ void VisualFactory::UsePreCompiledShader()
 
   ShaderPreCompiler::Get().Enable();
 
+  // To DO : Create all visual shader factory here.
+
   // Get image shader
   std::vector<RawShaderData> rawShaderList;
   RawShaderData              imageShaderData;
@@ -453,7 +442,7 @@ void VisualFactory::UsePreCompiledShader()
 
   // Get color shader
   RawShaderData colorShaderData;
-  GetPreCompiledShader(colorShaderData);
+  GetColorVisualShaderFactory().GetPreCompiledShader(colorShaderData);
   rawShaderList.push_back(colorShaderData);
 
   // Save all shader
@@ -490,29 +479,6 @@ void VisualFactory::SetBrokenImageUrl(Toolkit::StyleManager& styleManager)
   mFactoryCache->SetBrokenImageUrl(brokenImageUrl, customBrokenImageUrlList);
 }
 
-void VisualFactory::GetPreCompiledShader(RawShaderData& shaders)
-{
-  std::vector<std::string_view> vertexPrefix;
-  std::vector<std::string_view> fragmentPrefix;
-  std::vector<std::string_view> shaderName;
-  int                           shaderCount = 0;
-  shaders.shaderCount                       = 0;
-  for(uint32_t i = 0u; i < SHADER_TYPE_COUNT; ++i)
-  {
-    vertexPrefix.push_back(VertexPredefines[i]);
-    fragmentPrefix.push_back(FragmentPredefines[i]);
-    shaderName.push_back(Scripting::GetLinearEnumerationName<VisualFactoryCache::ShaderType>(ShaderTypePredefines[i], VISUAL_SHADER_TYPE_TABLE, VISUAL_SHADER_TYPE_TABLE_COUNT));
-    shaderCount++;
-  }
-
-  shaders.vertexPrefix   = vertexPrefix;
-  shaders.fragmentPrefix = fragmentPrefix;
-  shaders.shaderName     = shaderName;
-  shaders.vertexShader   = SHADER_COLOR_VISUAL_SHADER_VERT;
-  shaders.fragmentShader = SHADER_COLOR_VISUAL_SHADER_FRAG;
-  shaders.shaderCount    = shaderCount;
-}
-
 Internal::VisualFactoryCache& VisualFactory::GetFactoryCache()
 {
   if(!mFactoryCache)
@@ -548,6 +514,15 @@ TextVisualShaderFactory& VisualFactory::GetTextVisualShaderFactory()
   return *mTextVisualShaderFactory;
 }
 
+ColorVisualShaderFactory& VisualFactory::GetColorVisualShaderFactory()
+{
+  if(!mColorVisualShaderFactory)
+  {
+    mColorVisualShaderFactory = std::unique_ptr<ColorVisualShaderFactory>(new ColorVisualShaderFactory());
+  }
+  return *mColorVisualShaderFactory;
+}
+
 void VisualFactory::OnDiscardCallback()
 {
   mIdleCallback = nullptr;
index 418237a2709b37f58fa6a150509842abf9cf0a9b..913ded2c3140d0bcb559f6d029464c5daf8002b2 100644 (file)
@@ -37,6 +37,7 @@ namespace Internal
 class VisualFactoryCache;
 class ImageVisualShaderFactory;
 class TextVisualShaderFactory;
+class ColorVisualShaderFactory;
 
 /**
  * @copydoc Toolkit::VisualFactory
@@ -139,12 +140,6 @@ private:
    */
   void SetBrokenImageUrl(Toolkit::StyleManager& styleManager);
 
-  /**
-   * @brief Get the default shader source.
-   * @param[in] shaders shaderList for precompile
-   */
-  void GetPreCompiledShader(RawShaderData& shaders);
-
   /**
    * Get the factory cache, creating it if necessary.
    */
@@ -160,6 +155,11 @@ private:
    */
   TextVisualShaderFactory& GetTextVisualShaderFactory();
 
+  /**
+   * Get the color visual shader factory, creating it if necessary.
+   */
+  ColorVisualShaderFactory& GetColorVisualShaderFactory();
+
   /**
    * @brief Callbacks called for clear discarded visuals.
    */
@@ -183,6 +183,7 @@ private:
   std::unique_ptr<VisualFactoryCache>       mFactoryCache;
   std::unique_ptr<ImageVisualShaderFactory> mImageVisualShaderFactory;
   std::unique_ptr<TextVisualShaderFactory>  mTextVisualShaderFactory;
+  std::unique_ptr<ColorVisualShaderFactory> mColorVisualShaderFactory;
   SlotDelegate<VisualFactory>               mSlotDelegate;
   CallbackBase*                             mIdleCallback;
   using DiscardedVisualContainer = std::vector<Toolkit::Visual::Base>;