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());
${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
--- /dev/null
+#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
${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
--- /dev/null
+/*
+ * 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
--- /dev/null
+#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
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)
{
}
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;
}
// 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
{
* @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
/**
* @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().
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
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,
"", // 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,
"#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,
{
}
-Shader ImageVisualShaderFactory::GetShader(VisualFactoryCache& factoryCache, ImageVisualShaderFeatureBuilder& featureBuilder)
+Shader ImageVisualShaderFactory::GetShader(VisualFactoryCache& factoryCache, const ImageVisualShaderFeatureBuilder& featureBuilder)
{
Shader shader;
VisualFactoryCache::ShaderType shaderType = featureBuilder.GetShaderType();
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]);
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;
// 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
/**
* ImageVisualShaderFactory is an object that provides and shares shaders between image visuals
*/
-class ImageVisualShaderFactory
+class ImageVisualShaderFactory : public VisualShaderFactoryInterface
{
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.
*/
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:
/**
return *this;
}
-VisualFactoryCache::ShaderType ImageVisualShaderFeatureBuilder::GetShaderType()
+VisualFactoryCache::ShaderType ImageVisualShaderFeatureBuilder::GetShaderType() const
{
VisualFactoryCache::ShaderType shaderType = VisualFactoryCache::IMAGE_SHADER;
if(mTextureAtlas == ImageVisualShaderFeature::TextureAtlas::ENABLED)
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)
{
}
}
-void ImageVisualShaderFeatureBuilder::GetFragmentShaderPrefixList(std::string& fragmentShaderPrefixList)
+void ImageVisualShaderFeatureBuilder::GetFragmentShaderPrefixList(std::string& fragmentShaderPrefixList) const
{
if(mTextureAtlas == ImageVisualShaderFeature::TextureAtlas::ENABLED)
{
}
}
-Dali::Texture ImageVisualShaderFeatureBuilder::GetTexture()
+Dali::Texture ImageVisualShaderFeatureBuilder::GetTexture() const
{
return mTexture;
}
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;
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,
};
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;
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());
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]);
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;
// 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
/**
* @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;
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
/**
* TextVisualShaderFactory is an object that provides and shares shaders for text visuals
*/
-class TextVisualShaderFactory
+class TextVisualShaderFactory : public VisualShaderFactoryInterface
{
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:
/**
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);
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;
* @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
#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>
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),
case Toolkit::Visual::COLOR:
{
- visualPtr = ColorVisual::New(GetFactoryCache(), propertyMap);
+ visualPtr = ColorVisual::New(GetFactoryCache(), GetColorVisualShaderFactory(), propertyMap);
break;
}
ShaderPreCompiler::Get().Enable();
+ // To DO : Create all visual shader factory here.
+
// Get image shader
std::vector<RawShaderData> rawShaderList;
RawShaderData imageShaderData;
// Get color shader
RawShaderData colorShaderData;
- GetPreCompiledShader(colorShaderData);
+ GetColorVisualShaderFactory().GetPreCompiledShader(colorShaderData);
rawShaderList.push_back(colorShaderData);
// Save all shader
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)
return *mTextVisualShaderFactory;
}
+ColorVisualShaderFactory& VisualFactory::GetColorVisualShaderFactory()
+{
+ if(!mColorVisualShaderFactory)
+ {
+ mColorVisualShaderFactory = std::unique_ptr<ColorVisualShaderFactory>(new ColorVisualShaderFactory());
+ }
+ return *mColorVisualShaderFactory;
+}
+
void VisualFactory::OnDiscardCallback()
{
mIdleCallback = nullptr;
class VisualFactoryCache;
class ImageVisualShaderFactory;
class TextVisualShaderFactory;
+class ColorVisualShaderFactory;
/**
* @copydoc Toolkit::VisualFactory
*/
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.
*/
*/
TextVisualShaderFactory& GetTextVisualShaderFactory();
+ /**
+ * Get the color visual shader factory, creating it if necessary.
+ */
+ ColorVisualShaderFactory& GetColorVisualShaderFactory();
+
/**
* @brief Callbacks called for clear discarded visuals.
*/
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>;