ToolkitTestApplication application;
tet_infoline("UtcDaliVisualFactoryUsePreCompiledShader: Test a UsePreCompiledShader fucntion");
- std::vector<RawShaderData> precompiledShaderList;
+ ShaderPreCompiler::RawShaderDataList precompiledShaderList;
DALI_TEST_CHECK(precompiledShaderList.size() == 0u); // before Get Shader
ShaderPreCompiler::Get().GetPreCompileShaderList(precompiledShaderList);
DALI_TEST_CHECK(precompiledShaderList.size() == 0u); // after Get Shader
ToolkitTestApplication application;
tet_infoline("UtcDaliVisualFactoryUsePreCompiledShader: Test a UsePreCompiledShader fucntion with invalid options");
- std::vector<RawShaderData> precompiledShaderList;
+ ShaderPreCompiler::RawShaderDataList precompiledShaderList;
DALI_TEST_CHECK(precompiledShaderList.size() == 0u); // before Get Shader
ShaderPreCompiler::Get().GetPreCompileShaderList(precompiledShaderList);
DALI_TEST_CHECK(precompiledShaderList.size() == 0u); // after Get Shader
${toolkit_src_dir}/visuals/color/color-visual-shader-factory.cpp
${toolkit_src_dir}/visuals/color/color-visual.cpp
${toolkit_src_dir}/visuals/custom-shader-factory.cpp
- ${toolkit_src_dir}/visuals/npatch-shader-factory.cpp
${toolkit_src_dir}/visuals/gradient/gradient-visual.cpp
${toolkit_src_dir}/visuals/gradient/gradient.cpp
${toolkit_src_dir}/visuals/gradient/linear-gradient.cpp
${toolkit_src_dir}/visuals/mesh/mesh-visual.cpp
${toolkit_src_dir}/visuals/npatch/npatch-data.cpp
${toolkit_src_dir}/visuals/npatch/npatch-loader.cpp
+ ${toolkit_src_dir}/visuals/npatch/npatch-shader-factory.cpp
${toolkit_src_dir}/visuals/npatch/npatch-visual.cpp
${toolkit_src_dir}/visuals/primitive/primitive-visual.cpp
${toolkit_src_dir}/visuals/svg/svg-loader-observer.cpp
VisualFactoryCache::ShaderType type = featureBuilder.GetShaderType();
featureBuilder.GetVertexShaderPrefixList(vertexPrefixList);
featureBuilder.GetFragmentShaderPrefixList(fragmentPrefixList);
- return SavePrecompileShader(type, vertexPrefixList, fragmentPrefixList);
+ return SavePrecompileShader(type, std::move(vertexPrefixList), std::move(fragmentPrefixList));
}
-void ColorVisualShaderFactory::GetPreCompiledShader(RawShaderData& shaders)
+void ColorVisualShaderFactory::GetPreCompiledShader(ShaderPreCompiler::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;
+ std::vector<std::string> vertexPrefix;
+ std::vector<std::string> fragmentPrefix;
+ std::vector<std::string> shaderName;
+
+ uint32_t shaderCount = 0;
+
+ shaders.shaderCount = 0;
// precompile requested shader first
for(uint32_t i = 0u; i < mRequestedPrecompileShader.size(); i++)
{
- vertexPrefix.push_back(mRequestedPrecompileShader[i].vertexPrefix);
- fragmentPrefix.push_back(mRequestedPrecompileShader[i].fragmentPrefix);
- shaderName.push_back(Scripting::GetLinearEnumerationName<VisualFactoryCache::ShaderType>(mRequestedPrecompileShader[i].type, VISUAL_SHADER_TYPE_TABLE, VISUAL_SHADER_TYPE_TABLE_COUNT));
+ vertexPrefix.push_back(std::move(mRequestedPrecompileShader[i].vertexPrefix));
+ fragmentPrefix.push_back(std::move(mRequestedPrecompileShader[i].fragmentPrefix));
+ shaderName.push_back(std::string(Scripting::GetLinearEnumerationName<VisualFactoryCache::ShaderType>(mRequestedPrecompileShader[i].type, VISUAL_SHADER_TYPE_TABLE, VISUAL_SHADER_TYPE_TABLE_COUNT)));
shaderCount++;
}
+ // Clean up requested precompile shader list
+ mRequestedPrecompileShader.clear();
+
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));
+ vertexPrefix.push_back(std::string(VertexPredefines[i]));
+ fragmentPrefix.push_back(std::string(FragmentPredefines[i]));
+ shaderName.push_back(std::string(Scripting::GetLinearEnumerationName<VisualFactoryCache::ShaderType>(ShaderTypePredefines[i], VISUAL_SHADER_TYPE_TABLE, VISUAL_SHADER_TYPE_TABLE_COUNT)));
shaderCount++;
}
}
}
-bool ColorVisualShaderFactory::SavePrecompileShader(VisualFactoryCache::ShaderType shader, std::string& vertexPrefix, std::string& fragmentPrefix)
+bool ColorVisualShaderFactory::SavePrecompileShader(VisualFactoryCache::ShaderType shader, std::string&& vertexPrefix, std::string&& fragmentPrefix)
{
for(uint32_t i = 0u; i < PREDEFINED_SHADER_TYPE_COUNT; i++)
{
RequestShaderInfo info;
info.type = shader;
- info.vertexPrefix = vertexPrefix;
- info.fragmentPrefix = fragmentPrefix;
- mRequestedPrecompileShader.push_back(info);
+ info.vertexPrefix = std::move(vertexPrefix);
+ info.fragmentPrefix = std::move(fragmentPrefix);
+ mRequestedPrecompileShader.emplace_back(std::move(info));
DALI_LOG_RELEASE_INFO("Add precompile shader success!!(%s)\n", Scripting::GetLinearEnumerationName<VisualFactoryCache::ShaderType>(shader, VISUAL_SHADER_TYPE_TABLE, VISUAL_SHADER_TYPE_TABLE_COUNT));
return true;
}
{
namespace Internal
{
-
namespace ColorVisualShaderFeature
{
namespace RoundedCorner
FeatureBuilder& EnableCutout(bool enableCutout);
VisualFactoryCache::ShaderType GetShaderType() const;
- void GetVertexShaderPrefixList(std::string& vertexShaderPrefixList) const;
- void GetFragmentShaderPrefixList(std::string& fragmentShaderPrefixList) const;
+ void GetVertexShaderPrefixList(std::string& vertexShaderPrefixList) const;
+ void GetFragmentShaderPrefixList(std::string& fragmentShaderPrefixList) const;
bool IsEnabledRoundCorner() const
{
/**
* @copydoc Dali::Toolkit::VisualShaderFactoryInterface::GetPreCompiledShader
*/
- void GetPreCompiledShader(RawShaderData& shaders) override;
+ void GetPreCompiledShader(ShaderPreCompiler::RawShaderData& shaders) override;
private:
/**
/**
* @brief Check if cached hash value is valid or not.
*/
- bool SavePrecompileShader(VisualFactoryCache::ShaderType shader, std::string& vertexPrefix, std::string& fragmentPrefix);
+ bool SavePrecompileShader(VisualFactoryCache::ShaderType shader, std::string&& vertexPrefix, std::string&& fragmentPrefix);
protected:
/**
auto shaderName = option.GetShaderName();
auto vertexShader = option.GetVertexShader();
auto fragmentShader = option.GetFragmentShader();
- return SavePrecompileShader(shaderName, vertexShader, fragmentShader);
+ return SavePrecompileShader(std::move(shaderName), std::move(vertexShader), std::move(fragmentShader));
}
-void CustomShaderFactory::GetPreCompiledShader(RawShaderData& shaders)
+void CustomShaderFactory::GetPreCompiledShader(ShaderPreCompiler::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;
+ std::vector<std::string> vertexPrefix;
+ std::vector<std::string> fragmentPrefix;
+ std::vector<std::string> shaderName;
+
+ uint32_t shaderCount = 0;
+
+ shaders.shaderCount = 0;
// precompile requested shader first
for(uint32_t i = 0; i < mRequestedPrecompileShader.size(); i++)
{
- vertexPrefix.push_back(mRequestedPrecompileShader[i].vertexPrefix);
- fragmentPrefix.push_back(mRequestedPrecompileShader[i].fragmentPrefix);
- shaderName.push_back(mRequestedPrecompileShader[i].name);
+ vertexPrefix.push_back(std::move(mRequestedPrecompileShader[i].vertexPrefix));
+ fragmentPrefix.push_back(std::move(mRequestedPrecompileShader[i].fragmentPrefix));
+ shaderName.push_back(std::move(mRequestedPrecompileShader[i].name));
shaderCount++;
}
+ // Clean up requested precompile shader list
+ mRequestedPrecompileShader.clear();
+
shaders.vertexPrefix = std::move(vertexPrefix);
shaders.fragmentPrefix = std::move(fragmentPrefix);
shaders.shaderName = std::move(shaderName);
shaders.vertexShader = ""; // Custom shader use prefix shader only. No need to set vertexShader and fragmentShader.
shaders.fragmentShader = ""; // Custom shader use prefix shader only. No need to set vertexShader and fragmentShader.
- shaders.shaderCount = std::move(shaderCount);
+ shaders.shaderCount = shaderCount;
shaders.custom = true;
}
-bool CustomShaderFactory::SavePrecompileShader(std::string& shaderName, std::string& vertexShader, std::string& fragmentShader)
+bool CustomShaderFactory::SavePrecompileShader(std::string&& shaderName, std::string&& vertexShader, std::string&& fragmentShader)
{
+ DALI_LOG_RELEASE_INFO("Add precompile shader success!!(%s)", shaderName.c_str());
+
RequestShaderInfo info;
info.type = VisualFactoryCache::SHADER_TYPE_MAX; ///< Not be used
- info.name = shaderName;
- info.vertexPrefix = vertexShader;
- info.fragmentPrefix = fragmentShader;
- mRequestedPrecompileShader.push_back(info);
- DALI_LOG_RELEASE_INFO("Add precompile shader success!!(%s)", shaderName.c_str());
+ info.name = std::move(shaderName);
+ info.vertexPrefix = std::move(vertexShader);
+ info.fragmentPrefix = std::move(fragmentShader);
+ mRequestedPrecompileShader.emplace_back(std::move(info));
return true;
}
{
namespace Internal
{
-
/**
* CustomShaderFactory is an object that provides custom shader
*/
/**
* @copydoc Dali::Toolkit::VisualShaderFactoryInterface::GetPreCompiledShader
*/
- void GetPreCompiledShader(RawShaderData& shaders) override;
+ void GetPreCompiledShader(ShaderPreCompiler::RawShaderData& shaders) override;
private:
/**
* @brief Save the custom shader
*/
- bool SavePrecompileShader(std::string& shaderName, std::string& vertexPrefix, std::string& fragmentPrefix);
+ bool SavePrecompileShader(std::string&& shaderName, std::string&& vertexPrefix, std::string&& fragmentPrefix);
protected:
/**
VisualFactoryCache::ShaderType type = featureBuilder.GetShaderType();
featureBuilder.GetVertexShaderPrefixList(vertexPrefixList);
featureBuilder.GetFragmentShaderPrefixList(fragmentPrefixList);
- return SavePrecompileShader(type, vertexPrefixList, fragmentPrefixList);
+ return SavePrecompileShader(type, std::move(vertexPrefixList), std::move(fragmentPrefixList));
}
-void ImageVisualShaderFactory::GetPreCompiledShader(RawShaderData& shaders)
+void ImageVisualShaderFactory::GetPreCompiledShader(ShaderPreCompiler::RawShaderData& shaders)
{
- std::vector<std::string_view> vertexPrefix;
- std::vector<std::string_view> fragmentPrefix;
- std::vector<std::string_view> shaderName;
+ std::vector<std::string> vertexPrefix;
+ std::vector<std::string> fragmentPrefix;
+ std::vector<std::string> shaderName;
+
+ uint32_t shaderCount = 0;
+
shaders.shaderCount = 0;
- int shaderCount = 0;
- for(uint32_t i = 0u; i < mRequestedPrecompileShader.size(); i++)
+ // precompile requested shader first
+ for(uint32_t i = 0; i < mRequestedPrecompileShader.size(); i++)
{
- vertexPrefix.push_back(mRequestedPrecompileShader[i].vertexPrefix);
- fragmentPrefix.push_back(mRequestedPrecompileShader[i].fragmentPrefix);
- shaderName.push_back(Scripting::GetLinearEnumerationName<VisualFactoryCache::ShaderType>(mRequestedPrecompileShader[i].type, VISUAL_SHADER_TYPE_TABLE, VISUAL_SHADER_TYPE_TABLE_COUNT));
+ vertexPrefix.push_back(std::move(mRequestedPrecompileShader[i].vertexPrefix));
+ fragmentPrefix.push_back(std::move(mRequestedPrecompileShader[i].fragmentPrefix));
+ shaderName.push_back(std::string(Scripting::GetLinearEnumerationName<VisualFactoryCache::ShaderType>(mRequestedPrecompileShader[i].type, VISUAL_SHADER_TYPE_TABLE, VISUAL_SHADER_TYPE_TABLE_COUNT)));
shaderCount++;
}
+ // Clean up requested precompile shader list
+ mRequestedPrecompileShader.clear();
+
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));
+ vertexPrefix.push_back(std::string(VertexPredefines[i]));
+ fragmentPrefix.push_back(std::string(FragmentPredefines[i]));
+ shaderName.push_back(std::string(Scripting::GetLinearEnumerationName<VisualFactoryCache::ShaderType>(ShaderTypePredefines[i], VISUAL_SHADER_TYPE_TABLE, VISUAL_SHADER_TYPE_TABLE_COUNT)));
shaderCount++;
}
}
}
-bool ImageVisualShaderFactory::SavePrecompileShader(VisualFactoryCache::ShaderType shader, std::string& vertexPrefix, std::string& fragmentPrefix)
+bool ImageVisualShaderFactory::SavePrecompileShader(VisualFactoryCache::ShaderType shader, std::string&& vertexPrefix, std::string&& fragmentPrefix)
{
for(uint32_t i = 0u; i < PREDEFINED_SHADER_TYPE_COUNT; i++)
{
RequestShaderInfo info;
info.type = shader;
- info.vertexPrefix = vertexPrefix;
- info.fragmentPrefix = fragmentPrefix;
- mRequestedPrecompileShader.push_back(info);
+ info.vertexPrefix = std::move(vertexPrefix);
+ info.fragmentPrefix = std::move(fragmentPrefix);
+ mRequestedPrecompileShader.emplace_back(std::move(info));
DALI_LOG_RELEASE_INFO("Add precompile shader success!!(%s)\n", Scripting::GetLinearEnumerationName<VisualFactoryCache::ShaderType>(shader, VISUAL_SHADER_TYPE_TABLE, VISUAL_SHADER_TYPE_TABLE_COUNT));
return true;
}
{
namespace Internal
{
-
/**
* ImageVisualShaderFactory is an object that provides and shares shaders between image visuals
*/
/**
* @copydoc Dali::Toolkit::VisualShaderFactoryInterface::GetPreCompiledShader
*/
- void GetPreCompiledShader(RawShaderData& shaders) override;
+ void GetPreCompiledShader(ShaderPreCompiler::RawShaderData& shaders) override;
private:
/**
/**
* @brief Check if cached hash value is valid or not.
*/
- bool SavePrecompileShader(VisualFactoryCache::ShaderType shader, std::string& vertexPrefix, std::string& fragmentPrefix);
+ bool SavePrecompileShader(VisualFactoryCache::ShaderType shader, std::string&& vertexPrefix, std::string&& fragmentPrefix);
protected:
/**
+++ /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/npatch-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
-{
-
-NpatchShaderFactory::NpatchShaderFactory()
-: mNpatchXStretchCount(0),
- mNpatchYStretchCount(0),
- mNpatchMaskingEnable(false)
-{
-}
-
-NpatchShaderFactory::~NpatchShaderFactory()
-{
-}
-
-bool NpatchShaderFactory::AddPrecompiledShader(PrecompileShaderOption& option)
-{
- ShaderFlagList shaderOption = option.GetShaderOptions();
-
- // Find Masking flag
- for(uint32_t i = 0; i < shaderOption.size(); ++i)
- {
- if(shaderOption[i] == PrecompileShaderOption::Flag::MASKING)
- {
- mNpatchMaskingEnable = true;
- }
- }
-
- mNpatchXStretchCount = option.GetNpatchXStretchCount();
- mNpatchYStretchCount = option.GetNpatchYStretchCount();
-
- std::string vertexShader;
- std::string fragmentShader;
- GetVertexShader(vertexShader);
- GetFragmentShader(fragmentShader);
-
- VisualFactoryCache::ShaderType shaderType = mNpatchMaskingEnable? VisualFactoryCache::ShaderType::NINE_PATCH_MASK_SHADER : VisualFactoryCache::ShaderType::NINE_PATCH_SHADER;
- return SavePrecompileShader(shaderType, vertexShader, fragmentShader);
-}
-
-void NpatchShaderFactory::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;
-
- // precompile requested shader first
- for(uint32_t i = 0; i < mRequestedPrecompileShader.size(); i++ )
- {
- vertexPrefix.push_back(mRequestedPrecompileShader[i].vertexPrefix);
- fragmentPrefix.push_back(mRequestedPrecompileShader[i].fragmentPrefix);
- shaderName.push_back(mRequestedPrecompileShader[i].name);
- shaderCount++;
- }
-
- shaders.vertexPrefix = std::move(vertexPrefix);
- shaders.fragmentPrefix = std::move(fragmentPrefix);
- shaders.shaderName = std::move(shaderName);
- shaders.vertexShader = ""; // Custom shader use prefix shader only. No need to set vertexShader and fragmentShader.
- shaders.fragmentShader = ""; // Custom shader use prefix shader only. No need to set vertexShader and fragmentShader.
- shaders.shaderCount = std::move(shaderCount);
- shaders.custom = true;
-}
-
-void NpatchShaderFactory::GetVertexShader(std::string& vertexShader) const
-{
- if(DALI_LIKELY((mNpatchXStretchCount == 1 && mNpatchYStretchCount == 1) ||
- (mNpatchXStretchCount == 0 && mNpatchYStretchCount == 0)))
- {
- vertexShader += SHADER_NPATCH_VISUAL_3X3_SHADER_VERT;
- }
- else if(mNpatchXStretchCount > 0 || mNpatchYStretchCount > 0)
- {
- std::stringstream vertextShaderStream;
- vertextShaderStream << "#define FACTOR_SIZE_X " << mNpatchXStretchCount + 2 << "\n"
- << "#define FACTOR_SIZE_Y " << mNpatchYStretchCount + 2 << "\n"
- << SHADER_NPATCH_VISUAL_SHADER_VERT;
- vertexShader += vertextShaderStream.str();
- }
-}
-
-void NpatchShaderFactory::GetFragmentShader(std::string& fragmentShader) const
-{
- fragmentShader += (mNpatchMaskingEnable ? SHADER_NPATCH_VISUAL_MASK_SHADER_FRAG : SHADER_NPATCH_VISUAL_SHADER_FRAG);
-}
-
-bool NpatchShaderFactory::SavePrecompileShader(VisualFactoryCache::ShaderType shader, std::string& vertexShader, std::string& fragmentShader)
-{
- for(uint32_t i = 0u; i< mRequestedPrecompileShader.size(); i++)
- {
- if(mRequestedPrecompileShader[i].type == shader)
- {
- DALI_LOG_WARNING("This shader already requsted(%s).", Scripting::GetLinearEnumerationName<VisualFactoryCache::ShaderType>(mRequestedPrecompileShader[i].type, VISUAL_SHADER_TYPE_TABLE, VISUAL_SHADER_TYPE_TABLE_COUNT));
- return false;
- }
- }
-
- std::string shaderName = Scripting::GetLinearEnumerationName<VisualFactoryCache::ShaderType>(shader, VISUAL_SHADER_TYPE_TABLE, VISUAL_SHADER_TYPE_TABLE_COUNT);
- if(!((mNpatchXStretchCount == 1 && mNpatchYStretchCount == 1) || (mNpatchXStretchCount == 0 && mNpatchYStretchCount == 0)))
- {
- if(mNpatchXStretchCount > 0 || mNpatchYStretchCount > 0)
- {
- std::stringstream shaderNameStream;
- shaderNameStream << "NINE_PATCH_SHADER_" << mNpatchXStretchCount << "x" << mNpatchYStretchCount;
- shaderName = shaderNameStream.str();
- }
- }
-
- RequestShaderInfo info;
- info.type = shader;
- info.name = shaderName;
- info.vertexPrefix = vertexShader;
- info.fragmentPrefix = fragmentShader;
- mRequestedPrecompileShader.push_back(info);
- DALI_LOG_RELEASE_INFO("Add precompile shader success!!(%s)",Scripting::GetLinearEnumerationName<VisualFactoryCache::ShaderType>(shader, VISUAL_SHADER_TYPE_TABLE, VISUAL_SHADER_TYPE_TABLE_COUNT));
- return true;
-}
-
-
-} // namespace Internal
-
-} // namespace Toolkit
-
-} // namespace Dali
+++ /dev/null
-#ifndef DALI_TOOLKIT_NPATCH_SHADER_FACTORY_H
-#define DALI_TOOLKIT_NPATCH_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/internal/visuals/visual-shader-factory-interface.h>
-#include <string_view>
-
-namespace Dali
-{
-namespace Toolkit
-{
-namespace Internal
-{
-
-/**
- * NpatchShaderFactory is an object that provides custom shader
- */
-class NpatchShaderFactory : public VisualShaderFactoryInterface
-{
-public:
- /**
- * @brief Constructor
- */
- NpatchShaderFactory();
-
- /**
- * @brief Destructor
- */
- ~NpatchShaderFactory() override;
-
-public: // Implementation of VisualShaderFactoryInterface
- /**
- * @copydoc Dali::Toolkit::VisualShaderFactoryInterface::AddPrecompiledShader
- */
- bool AddPrecompiledShader(PrecompileShaderOption& option) override;
-
- /**
- * @copydoc Dali::Toolkit::VisualShaderFactoryInterface::GetPreCompiledShader
- */
- void GetPreCompiledShader(RawShaderData& shaders) override;
-
-private:
- /**
- * @brief Get the NPatch vertex shader. this is used for generating pre-compiled shader.
- */
- void GetVertexShader(std::string& vertexShader) const;
-
- /**
- * @brief Get the NPatch fragment shader. this is used for generating pre-compiled shader
- */
- void GetFragmentShader(std::string& fragmentShader) const;
-
- /**
- * @brief Save the npatch shader
- */
- bool SavePrecompileShader(VisualFactoryCache::ShaderType shader, std::string& vertexPrefix, std::string& fragmentPrefix);
-
-protected:
- /**
- * Undefined copy constructor.
- */
- NpatchShaderFactory(const NpatchShaderFactory&) = delete;
-
- /**
- * Undefined assignment operator.
- */
- NpatchShaderFactory& operator=(const NpatchShaderFactory& rhs) = delete;
-
-private:
- // For Npatch
- uint32_t mNpatchXStretchCount;
- uint32_t mNpatchYStretchCount;
- bool mNpatchMaskingEnable;
-};
-
-} // namespace Internal
-
-} // namespace Toolkit
-
-} // namespace Dali
-
-#endif // DALI_TOOLKIT_NPATCH_SHADER_FACTORY_H
--- /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/npatch/npatch-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
+{
+NpatchShaderFactory::NpatchShaderFactory()
+: mNpatchXStretchCount(0),
+ mNpatchYStretchCount(0),
+ mNpatchMaskingEnable(false)
+{
+}
+
+NpatchShaderFactory::~NpatchShaderFactory()
+{
+}
+
+bool NpatchShaderFactory::AddPrecompiledShader(PrecompileShaderOption& option)
+{
+ ShaderFlagList shaderOption = option.GetShaderOptions();
+
+ // Find Masking flag
+ for(uint32_t i = 0; i < shaderOption.size(); ++i)
+ {
+ if(shaderOption[i] == PrecompileShaderOption::Flag::MASKING)
+ {
+ mNpatchMaskingEnable = true;
+ }
+ }
+
+ mNpatchXStretchCount = option.GetNpatchXStretchCount();
+ mNpatchYStretchCount = option.GetNpatchYStretchCount();
+
+ std::string vertexShader;
+ std::string fragmentShader;
+ GetVertexShader(vertexShader);
+ GetFragmentShader(fragmentShader);
+
+ VisualFactoryCache::ShaderType shaderType = mNpatchMaskingEnable ? VisualFactoryCache::ShaderType::NINE_PATCH_MASK_SHADER : VisualFactoryCache::ShaderType::NINE_PATCH_SHADER;
+ return SavePrecompileShader(shaderType, std::move(vertexShader), std::move(fragmentShader));
+}
+
+void NpatchShaderFactory::GetPreCompiledShader(ShaderPreCompiler::RawShaderData& shaders)
+{
+ std::vector<std::string> vertexPrefix;
+ std::vector<std::string> fragmentPrefix;
+ std::vector<std::string> shaderName;
+
+ uint32_t shaderCount = 0;
+
+ shaders.shaderCount = 0;
+
+ // precompile requested shader first
+ for(uint32_t i = 0; i < mRequestedPrecompileShader.size(); i++)
+ {
+ vertexPrefix.push_back(std::move(mRequestedPrecompileShader[i].vertexPrefix));
+ fragmentPrefix.push_back(std::move(mRequestedPrecompileShader[i].fragmentPrefix));
+ shaderName.push_back(std::move(mRequestedPrecompileShader[i].name));
+ shaderCount++;
+ }
+
+ // Clean up requested precompile shader list
+ mRequestedPrecompileShader.clear();
+
+ shaders.vertexPrefix = std::move(vertexPrefix);
+ shaders.fragmentPrefix = std::move(fragmentPrefix);
+ shaders.shaderName = std::move(shaderName);
+ shaders.vertexShader = ""; // Custom shader use prefix shader only. No need to set vertexShader and fragmentShader.
+ shaders.fragmentShader = ""; // Custom shader use prefix shader only. No need to set vertexShader and fragmentShader.
+ shaders.shaderCount = shaderCount;
+ shaders.custom = true; ///< Note that npatch shader is kind of custom shader.
+}
+
+void NpatchShaderFactory::GetVertexShader(std::string& vertexShader) const
+{
+ if(DALI_LIKELY((mNpatchXStretchCount == 1 && mNpatchYStretchCount == 1) ||
+ (mNpatchXStretchCount == 0 && mNpatchYStretchCount == 0)))
+ {
+ vertexShader += SHADER_NPATCH_VISUAL_3X3_SHADER_VERT;
+ }
+ else if(mNpatchXStretchCount > 0 || mNpatchYStretchCount > 0)
+ {
+ std::stringstream vertextShaderStream;
+ vertextShaderStream << "#define FACTOR_SIZE_X " << mNpatchXStretchCount + 2 << "\n"
+ << "#define FACTOR_SIZE_Y " << mNpatchYStretchCount + 2 << "\n"
+ << SHADER_NPATCH_VISUAL_SHADER_VERT;
+ vertexShader += vertextShaderStream.str();
+ }
+}
+
+void NpatchShaderFactory::GetFragmentShader(std::string& fragmentShader) const
+{
+ fragmentShader += (mNpatchMaskingEnable ? SHADER_NPATCH_VISUAL_MASK_SHADER_FRAG : SHADER_NPATCH_VISUAL_SHADER_FRAG);
+}
+
+bool NpatchShaderFactory::SavePrecompileShader(VisualFactoryCache::ShaderType shader, std::string&& vertexShader, std::string&& fragmentShader)
+{
+ for(uint32_t i = 0u; i < mRequestedPrecompileShader.size(); i++)
+ {
+ if(mRequestedPrecompileShader[i].type == shader)
+ {
+ DALI_LOG_WARNING("This shader already requsted(%s).", Scripting::GetLinearEnumerationName<VisualFactoryCache::ShaderType>(mRequestedPrecompileShader[i].type, VISUAL_SHADER_TYPE_TABLE, VISUAL_SHADER_TYPE_TABLE_COUNT));
+ return false;
+ }
+ }
+
+ std::string shaderName = Scripting::GetLinearEnumerationName<VisualFactoryCache::ShaderType>(shader, VISUAL_SHADER_TYPE_TABLE, VISUAL_SHADER_TYPE_TABLE_COUNT);
+ if(!((mNpatchXStretchCount == 1 && mNpatchYStretchCount == 1) || (mNpatchXStretchCount == 0 && mNpatchYStretchCount == 0)))
+ {
+ if(mNpatchXStretchCount > 0 || mNpatchYStretchCount > 0)
+ {
+ std::stringstream shaderNameStream;
+ shaderNameStream << "NINE_PATCH_SHADER_" << mNpatchXStretchCount << "x" << mNpatchYStretchCount;
+ shaderName = shaderNameStream.str();
+ }
+ }
+
+ DALI_LOG_RELEASE_INFO("Add precompile shader success!!(%s)", shaderName.c_str());
+
+ RequestShaderInfo info;
+ info.type = shader;
+ info.name = std::move(shaderName);
+ info.vertexPrefix = std::move(vertexShader);
+ info.fragmentPrefix = std::move(fragmentShader);
+ mRequestedPrecompileShader.emplace_back(std::move(info));
+ return true;
+}
+
+} // namespace Internal
+
+} // namespace Toolkit
+
+} // namespace Dali
--- /dev/null
+#ifndef DALI_TOOLKIT_NPATCH_SHADER_FACTORY_H
+#define DALI_TOOLKIT_NPATCH_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/internal/visuals/visual-shader-factory-interface.h>
+#include <string_view>
+
+namespace Dali
+{
+namespace Toolkit
+{
+namespace Internal
+{
+/**
+ * NpatchShaderFactory is an object that provides custom shader
+ */
+class NpatchShaderFactory : public VisualShaderFactoryInterface
+{
+public:
+ /**
+ * @brief Constructor
+ */
+ NpatchShaderFactory();
+
+ /**
+ * @brief Destructor
+ */
+ ~NpatchShaderFactory() override;
+
+public: // Implementation of VisualShaderFactoryInterface
+ /**
+ * @copydoc Dali::Toolkit::VisualShaderFactoryInterface::AddPrecompiledShader
+ */
+ bool AddPrecompiledShader(PrecompileShaderOption& option) override;
+
+ /**
+ * @copydoc Dali::Toolkit::VisualShaderFactoryInterface::GetPreCompiledShader
+ */
+ void GetPreCompiledShader(ShaderPreCompiler::RawShaderData& shaders) override;
+
+private:
+ /**
+ * @brief Get the NPatch vertex shader. this is used for generating pre-compiled shader.
+ */
+ void GetVertexShader(std::string& vertexShader) const;
+
+ /**
+ * @brief Get the NPatch fragment shader. this is used for generating pre-compiled shader
+ */
+ void GetFragmentShader(std::string& fragmentShader) const;
+
+ /**
+ * @brief Save the npatch shader
+ */
+ bool SavePrecompileShader(VisualFactoryCache::ShaderType shader, std::string&& vertexPrefix, std::string&& fragmentPrefix);
+
+protected:
+ /**
+ * Undefined copy constructor.
+ */
+ NpatchShaderFactory(const NpatchShaderFactory&) = delete;
+
+ /**
+ * Undefined assignment operator.
+ */
+ NpatchShaderFactory& operator=(const NpatchShaderFactory& rhs) = delete;
+
+private:
+ // For Npatch
+ uint32_t mNpatchXStretchCount;
+ uint32_t mNpatchYStretchCount;
+ bool mNpatchMaskingEnable;
+};
+
+} // namespace Internal
+
+} // namespace Toolkit
+
+} // namespace Dali
+
+#endif // DALI_TOOLKIT_NPATCH_SHADER_FACTORY_H
VisualFactoryCache::ShaderType type = featureBuilder.GetShaderType();
featureBuilder.GetVertexShaderPrefixList(vertexPrefixList);
featureBuilder.GetFragmentShaderPrefixList(fragmentPrefixList);
- return SavePrecompileShader(type, vertexPrefixList, fragmentPrefixList);
+ return SavePrecompileShader(type, std::move(vertexPrefixList), std::move(fragmentPrefixList));
}
-void TextVisualShaderFactory::GetPreCompiledShader(RawShaderData& shaders)
+void TextVisualShaderFactory::GetPreCompiledShader(ShaderPreCompiler::RawShaderData& shaders)
{
- std::vector<std::string_view> vertexPrefix;
- std::vector<std::string_view> fragmentPrefix;
- std::vector<std::string_view> shaderName;
- int shaderCount = 0;
+ std::vector<std::string> vertexPrefix;
+ std::vector<std::string> fragmentPrefix;
+ std::vector<std::string> shaderName;
+
+ uint32_t shaderCount = 0;
// precompile requested shader first
for(uint32_t i = 0u; i < mRequestedPrecompileShader.size(); i++)
{
- vertexPrefix.push_back(mRequestedPrecompileShader[i].vertexPrefix);
- fragmentPrefix.push_back(mRequestedPrecompileShader[i].fragmentPrefix);
- shaderName.push_back(Scripting::GetLinearEnumerationName<VisualFactoryCache::ShaderType>(mRequestedPrecompileShader[i].type, VISUAL_SHADER_TYPE_TABLE, VISUAL_SHADER_TYPE_TABLE_COUNT));
+ vertexPrefix.push_back(std::move(mRequestedPrecompileShader[i].vertexPrefix));
+ fragmentPrefix.push_back(std::move(mRequestedPrecompileShader[i].fragmentPrefix));
+ shaderName.push_back(std::string(Scripting::GetLinearEnumerationName<VisualFactoryCache::ShaderType>(mRequestedPrecompileShader[i].type, VISUAL_SHADER_TYPE_TABLE, VISUAL_SHADER_TYPE_TABLE_COUNT)));
shaderCount++;
}
+ // Clean up requested precompile shader list
+ mRequestedPrecompileShader.clear();
+
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));
+ vertexPrefix.push_back(std::string(VertexPredefines[i]));
+ fragmentPrefix.push_back(std::string(FragmentPredefines[i]));
+ shaderName.push_back(std::string(Scripting::GetLinearEnumerationName<VisualFactoryCache::ShaderType>(ShaderTypePredefines[i], VISUAL_SHADER_TYPE_TABLE, VISUAL_SHADER_TYPE_TABLE_COUNT)));
shaderCount++;
}
}
}
-bool TextVisualShaderFactory::SavePrecompileShader(VisualFactoryCache::ShaderType shader, std::string& vertexPrefix, std::string& fragmentPrefix)
+bool TextVisualShaderFactory::SavePrecompileShader(VisualFactoryCache::ShaderType shader, std::string&& vertexPrefix, std::string&& fragmentPrefix)
{
for(uint32_t i = 0u; i < PREDEFINED_SHADER_TYPE_COUNT; i++)
{
RequestShaderInfo info;
info.type = shader;
- info.vertexPrefix = vertexPrefix;
- info.fragmentPrefix = fragmentPrefix;
- mRequestedPrecompileShader.push_back(info);
+ info.vertexPrefix = std::move(vertexPrefix);
+ info.fragmentPrefix = std::move(fragmentPrefix);
+ mRequestedPrecompileShader.emplace_back(std::move(info));
DALI_LOG_RELEASE_INFO("Add precompile shader success!!(%s)\n", Scripting::GetLinearEnumerationName<VisualFactoryCache::ShaderType>(shader, VISUAL_SHADER_TYPE_TABLE, VISUAL_SHADER_TYPE_TABLE_COUNT));
return true;
}
FeatureBuilder& EnableOverlay(bool enableOverlay);
VisualFactoryCache::ShaderType GetShaderType() const;
- void GetVertexShaderPrefixList(std::string& vertexShaderPrefixList) const;
- void GetFragmentShaderPrefixList(std::string& fragmentShaderPrefixList) const;
+ void GetVertexShaderPrefixList(std::string& vertexShaderPrefixList) const;
+ void GetFragmentShaderPrefixList(std::string& fragmentShaderPrefixList) const;
bool IsEnabledMultiColor() const
{
/**
* @copydoc Dali::Toolkit::VisualShaderFactoryInterface::GetPreCompiledShader
*/
- void GetPreCompiledShader(RawShaderData& shaders) override;
+ void GetPreCompiledShader(ShaderPreCompiler::RawShaderData& shaders) override;
private:
/**
/**
* @brief Check if cached hash value is valid or not.
*/
- bool SavePrecompileShader(VisualFactoryCache::ShaderType shader, std::string& vertexPrefix, std::string& fragmentPrefix);
+ bool SavePrecompileShader(VisualFactoryCache::ShaderType shader, std::string&& vertexPrefix, std::string&& fragmentPrefix);
protected:
/**
#include <dali-toolkit/internal/visuals/image/image-visual-shader-factory.h>
#include <dali-toolkit/internal/visuals/image/image-visual.h>
#include <dali-toolkit/internal/visuals/mesh/mesh-visual.h>
-#include <dali-toolkit/internal/visuals/npatch-shader-factory.h>
+#include <dali-toolkit/internal/visuals/npatch/npatch-shader-factory.h>
#include <dali-toolkit/internal/visuals/npatch/npatch-visual.h>
#include <dali-toolkit/internal/visuals/primitive/primitive-visual.h>
#include <dali-toolkit/internal/visuals/svg/svg-visual.h>
}
mPrecompiledShaderRequested = true;
- ShaderPreCompiler::Get().Enable();
+ ShaderPreCompiler::Get().Enable(true);
// Get image shader
- std::vector<RawShaderData> rawShaderList;
- RawShaderData imageShaderData;
+ ShaderPreCompiler::RawShaderDataList rawShaderList;
+ ShaderPreCompiler::RawShaderData imageShaderData;
GetImageVisualShaderFactory().GetPreCompiledShader(imageShaderData);
- rawShaderList.push_back(imageShaderData);
+ rawShaderList.emplace_back(std::move(imageShaderData));
// Get text shader
- RawShaderData textShaderData;
+ ShaderPreCompiler::RawShaderData textShaderData;
GetTextVisualShaderFactory().GetPreCompiledShader(textShaderData);
- rawShaderList.push_back(textShaderData);
+ rawShaderList.emplace_back(std::move(textShaderData));
// Get color shader
- RawShaderData colorShaderData;
+ ShaderPreCompiler::RawShaderData colorShaderData;
GetColorVisualShaderFactory().GetPreCompiledShader(colorShaderData);
- rawShaderList.push_back(colorShaderData);
+ rawShaderList.emplace_back(std::move(colorShaderData));
- RawShaderData npatchShaderData;
+ // Get npatch shader
+ ShaderPreCompiler::RawShaderData npatchShaderData;
GetNpatchShaderFactory().GetPreCompiledShader(npatchShaderData);
- rawShaderList.push_back(npatchShaderData);
+ rawShaderList.emplace_back(std::move(npatchShaderData));
// Get 3D shader
+ // TODO
+
// Get Custom shader
- RawShaderData customShaderData;
+ ShaderPreCompiler::RawShaderData customShaderData;
GetCustomShaderFactory().GetPreCompiledShader(customShaderData);
- rawShaderList.push_back(customShaderData);
+ rawShaderList.emplace_back(std::move(customShaderData));
// Save all shader
- ShaderPreCompiler::Get().SavePreCompileShaderList(rawShaderList);
+ ShaderPreCompiler::Get().SavePreCompileShaderList(std::move(rawShaderList));
}
Internal::TextureManager& VisualFactory::GetTextureManager()
#include <dali/integration-api/adaptor-framework/shader-precompiler.h>
// INTERNAL INCLUDES
-#include <dali-toolkit/public-api/dali-toolkit-common.h>
#include <dali-toolkit/devel-api/visual-factory/precompile-shader-option.h>
#include <dali-toolkit/internal/visuals/visual-factory-cache.h>
+#include <dali-toolkit/public-api/dali-toolkit-common.h>
namespace Dali
{
namespace Toolkit
{
-
-using HashType = uint64_t;
+using HashType = uint64_t;
using ShaderFlagList = std::vector<PrecompileShaderOption::Flag>;
namespace Internal
class VisualShaderFactoryInterface
{
public:
-
/**
* @brief Structure to request shader info from visual shader factory.
*/
struct RequestShaderInfo
{
- VisualFactoryCache::ShaderType type;
- std::string name;
- std::string vertexPrefix;
- std::string fragmentPrefix;
+ VisualFactoryCache::ShaderType type{VisualFactoryCache::ShaderType::SHADER_TYPE_MAX};
+ std::string name{};
+ std::string vertexPrefix{};
+ std::string fragmentPrefix{};
};
- VisualShaderFactoryInterface() = default;
+ VisualShaderFactoryInterface() = default;
virtual ~VisualShaderFactoryInterface() = default;
/**
* @brief Get precompiled shader for precompile
* @param[out] shaders shaderList for precompile
*/
- virtual void GetPreCompiledShader(RawShaderData& shaders) = 0;
+ virtual void GetPreCompiledShader(ShaderPreCompiler::RawShaderData& shaders) = 0;
protected:
std::vector<RequestShaderInfo> mRequestedPrecompileShader;