#include <dali-toolkit/internal/visuals/npatch-loader.h>
#include <dali/devel-api/adaptor-framework/image-loading.h>
#include <dali/integration-api/debug.h>
+#include <dali/integration-api/adaptor-framework/shader-precompiler.h>
using namespace Dali;
using namespace Dali::Toolkit;
END_TEST;
}
+
+
+int UtcDaliVisualFactoryGetPreCompiler(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline("UtcDaliVisualFactoryGetAnimatedImageVisual2: Request animated image visual with a Property::Map, test custom wrap mode and pixel area");
+
+
+ std::vector<RawShaderData> precompiledShaderList;
+ DALI_TEST_CHECK(precompiledShaderList.size() == 0u); // before Get Shader
+ ShaderPreCompiler::Get().GetPreCompileShaderList(precompiledShaderList);
+ DALI_TEST_CHECK(precompiledShaderList.size() == 0u); // after Get Shader
+
+ VisualFactory factory = VisualFactory::Get();
+ DALI_TEST_CHECK(factory);
+
+ factory.UsePreCompiledShader();
+
+ ShaderPreCompiler::Get().GetPreCompileShaderList(precompiledShaderList);
+ DALI_TEST_CHECK(precompiledShaderList.size() != 0u); // after Get Shader
+
+ Property::Map propertyMap;
+ propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
+ propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
+ Visual::Base visual = factory.CreateVisual(propertyMap);
+ DALI_TEST_CHECK(visual);
+
+ DummyControl actor = DummyControl::New(true);
+ DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
+ dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
+ actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
+ application.GetScene().Add(actor);
+
+ application.SendNotification();
+ application.Render();
+
+ END_TEST;
+}
GetImplementation(*this).DiscardVisual(visual);
}
+void VisualFactory::UsePreCompiledShader()
+{
+ GetImplementation(*this).UsePreCompiledShader();
+}
+
} // namespace Toolkit
} // namespace Dali
*/
void DiscardVisual(Visual::Base visual);
+ /**
+ * @brief Compile the visual shader in advance. Afterwards,
+ * when a visual using a new shader is requested, the pre-compiled shader is used.
+ *
+ * @note It is recommended that this method be called at the top of the application code.
+ * @note Using precompiled shaders is helpful when the application is complex and uses
+ * many different styles of visual options. On the other hand,if most visuals are the same
+ * and the application is simple, it may use memory unnecessarily or slow down the application launching speed.
+ */
+ void UsePreCompiledShader();
+
private:
explicit DALI_INTERNAL VisualFactory(Internal::VisualFactory* impl);
};
const Vector4 FULL_TEXTURE_RECT(0.f, 0.f, 1.f, 1.f);
const int NATIVE_SHADER_TYPE_OFFSET = VisualFactoryCache::ShaderType::NATIVE_IMAGE_SHADER - VisualFactoryCache::ShaderType::IMAGE_SHADER;
+
} // unnamed namespace
+static constexpr auto SHADER_TYPE_COUNT = 6u;
+
+const std::string_view VertexPredefines[SHADER_TYPE_COUNT]
+{
+ "", // VisualFactoryCache::IMAGE_SHADER,
+ "#define IS_REQUIRED_ROUNDED_CORNER\n", //VisualFactoryCache::IMAGE_SHADER_ROUNDED_CORNER,
+ "",//VisualFactoryCache::IMAGE_SHADER_YUV_TO_RGB,
+ "#define IS_REQUIRED_ROUNDED_CORNER\n",//VisualFactoryCache::IMAGE_SHADER_ROUNDED_CORNER_YUV_TO_RGB,
+ "",//VisualFactoryCache::IMAGE_SHADER_YUV_AND_RGB,
+ "#define IS_REQUIRED_ROUNDED_CORNER\n",//VisualFactoryCache::IMAGE_SHADER_ROUNDED_CORNER_YUV_AND_RGB,
+};
+const std::string_view FragmentPredefines[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_YUV_TO_RGB\n#define IS_REQUIRED_ROUNDED_CORNER\n",//VisualFactoryCache::IMAGE_SHADER_ROUNDED_CORNER_YUV_TO_RGB,
+ "#define IS_REQUIRED_UNIFIED_YUV_AND_RGB\n",//VisualFactoryCache::IMAGE_SHADER_YUV_AND_RGB,
+ "#define IS_REQUIRED_UNIFIED_YUV_AND_RGB\n#define IS_REQUIRED_ROUNDED_CORNER\n",//VisualFactoryCache::IMAGE_SHADER_ROUNDED_CORNER_YUV_AND_RGB,
+};
+
ImageVisualShaderFactory::ImageVisualShaderFactory()
: mFragmentShaderNeedChange(ImageVisualShaderFeature::ChangeFragmentShader::UNDECIDED)
{
return gFragmentShaderNoAtlas;
}
+void ImageVisualShaderFactory::GetPreCompiledShader(RawShaderData& shaders)
+{
+ std::vector<std::string_view> vertexPrefix;
+ std::vector<std::string_view> fragmentPrefix;
+ shaders.shaderCount = 0;
+ int shaderCount = 0;
+ for(uint32_t i=0; i< SHADER_TYPE_COUNT; ++i)
+ {
+ vertexPrefix.push_back(VertexPredefines[i]);
+ fragmentPrefix.push_back(FragmentPredefines[i]);
+ shaderCount++;
+ }
+
+ shaders.vertexPrefix= vertexPrefix;
+ shaders.fragmentPrefix = fragmentPrefix;
+ shaders.vertexShader = SHADER_IMAGE_VISUAL_SHADER_VERT;
+ shaders.fragmentShader = SHADER_IMAGE_VISUAL_SHADER_FRAG;
+ shaders.shaderCount = shaderCount;
+}
+
} // namespace Internal
} // namespace Toolkit
*/
std::string_view GetFragmentShaderSource();
+ /**
+ * @brief Get the default shader source.
+ * @param[in] shaders shaderList for precompile
+ */
+ void GetPreCompiledShader(RawShaderData& shaders);
+
protected:
/**
* Undefined copy constructor.
VisualFactoryCache::TEXT_SHADER_MULTI_COLOR_TEXT_WITH_STYLE_AND_OVERLAY,
};
+static constexpr auto SHADER_TYPE_COUNT = 1u;
+const std::string_view VertexPredefines[SHADER_TYPE_COUNT]
+{
+ "", // VisualFactoryCache::TEXT_SHADER_SINGLE_COLOR_TEXT
+};
+const std::string_view FragmentPredefines[SHADER_TYPE_COUNT]
+{
+ "", // VisualFactoryCache::TEXT_SHADER_SINGLE_COLOR_TEXT
+};
+
} // unnamed namespace
namespace TextVisualShaderFeature
return shader;
}
+void TextVisualShaderFactory::GetPreCompiledShader(RawShaderData& shaders)
+{
+ std::vector<std::string_view> vertexPrefix;
+ std::vector<std::string_view> fragmentPrefix;
+ int shaderCount = 0;
+ for(uint32_t i=0; i< SHADER_TYPE_COUNT; ++i)
+ {
+ vertexPrefix.push_back(VertexPredefines[i]);
+ fragmentPrefix.push_back(FragmentPredefines[i]);
+ shaderCount++;
+ }
+
+ shaders.vertexPrefix= vertexPrefix;
+ shaders.fragmentPrefix = fragmentPrefix;
+ shaders.vertexShader = SHADER_TEXT_VISUAL_SHADER_VERT;
+ shaders.fragmentShader = SHADER_TEXT_VISUAL_SHADER_FRAG;
+ shaders.shaderCount = shaderCount;
+}
+
} // namespace Internal
} // namespace Toolkit
*/
Shader GetShader(VisualFactoryCache& factoryCache, const TextVisualShaderFeature::FeatureBuilder& featureBuilder);
+ /**
+ * @brief Get the default shader source.
+ * @param[in] shaders shaderList for precompile
+ */
+ void GetPreCompiledShader(RawShaderData& shaders);
+
protected:
/**
* Undefined copy constructor.
#include <dali/public-api/object/ref-object.h>
#include <dali/public-api/rendering/geometry.h>
#include <dali/public-api/rendering/shader.h>
+#include <dali/integration-api/adaptor-framework/shader-precompiler.h>
// INTERNAL INCLUDES
#include <dali-toolkit/internal/texture-manager/texture-manager-impl.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>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
#include <dali-toolkit/internal/visuals/text-visual-shader-factory.h>
#include <dali-toolkit/internal/visuals/text/text-visual.h>
#include <dali-toolkit/internal/visuals/visual-factory-cache.h>
#include <dali-toolkit/public-api/visuals/text-visual-properties.h>
#include <dali-toolkit/public-api/visuals/visual-properties.h>
+
namespace Dali
{
namespace Toolkit
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;
+const std::string_view VertexPredefines[SHADER_TYPE_COUNT]
+{
+ "", //VisualFactoryCache::COLOR_SHADER
+ "#define IS_REQUIRED_ROUNDED_CORNER\n", //VisualFactoryCache::COLOR_SHADER_ROUNDED_CORNER
+};
+const std::string_view FragmentPredefines[SHADER_TYPE_COUNT]
+{
+ "", //VisualFactoryCache::COLOR_SHADER
+ "#define IS_REQUIRED_ROUNDED_CORNER\n", //VisualFactoryCache::COLOR_SHADER_ROUNDED_CORNER
+};
+
} // namespace
VisualFactory::VisualFactory(bool debugEnabled)
mSlotDelegate(this),
mIdleCallback(nullptr),
mDebugEnabled(debugEnabled),
- mPreMultiplyOnLoad(true)
+ mPreMultiplyOnLoad(true),
+ mPrecompiledShaderRequested(false)
{
}
RegisterDiscardCallback();
}
+void VisualFactory::UsePreCompiledShader()
+{
+ if(mPrecompiledShaderRequested)
+ {
+ return;
+ }
+ mPrecompiledShaderRequested = true;
+
+ ShaderPreCompiler::Get().Enable();
+
+ // Get image shader
+ std::vector<RawShaderData> rawShaderList;
+ RawShaderData imageShaderData;
+ GetImageVisualShaderFactory().GetPreCompiledShader(imageShaderData);
+ rawShaderList.push_back(imageShaderData);
+
+ // Get text shader
+ RawShaderData textShaderData;
+ GetTextVisualShaderFactory().GetPreCompiledShader(textShaderData);
+ rawShaderList.push_back(textShaderData);
+
+ // Get color shader
+ RawShaderData colorShaderData;
+ GetPreCompiledShader(colorShaderData);
+ rawShaderList.push_back(colorShaderData);
+
+
+ // Save all shader
+ ShaderPreCompiler::Get().SavePreCompileShaderList(rawShaderList);
+}
+
Internal::TextureManager& VisualFactory::GetTextureManager()
{
return GetFactoryCache().GetTextureManager();
mFactoryCache->SetBrokenImageUrl(brokenImageUrl, customBrokenImageUrlList);
}
+void VisualFactory::GetPreCompiledShader(RawShaderData& shaders)
+{
+ std::vector<std::string_view> vertexPrefix;
+ std::vector<std::string_view> fragmentPrefix;
+ 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]);
+ shaderCount++;
+ }
+
+ shaders.vertexPrefix = vertexPrefix;
+ shaders.fragmentPrefix = fragmentPrefix;
+ shaders.vertexShader = SHADER_COLOR_VISUAL_SHADER_VERT;
+ shaders.fragmentShader = SHADER_COLOR_VISUAL_SHADER_FRAG;
+ shaders.shaderCount = shaderCount;
+}
+
Internal::VisualFactoryCache& VisualFactory::GetFactoryCache()
{
if(!mFactoryCache)
}
SetBrokenImageUrl(styleManager);
}
+
return *mFactoryCache;
}
// EXTERNAL INCLUDES
#include <dali/public-api/common/vector-wrapper.h>
#include <dali/public-api/object/base-object.h>
+#include <dali/integration-api/adaptor-framework/shader-precompiler.h>
// INTERNAL INCLUDES
#include <dali-toolkit/devel-api/visual-factory/visual-base.h>
void DiscardVisual(Toolkit::Visual::Base visual);
/**
+ * @copydoc Toolkit::VisualFactory::UsePreCompiledShader()
+ */
+ void UsePreCompiledShader();
+
+ /**
* @return the reference to texture manager
*/
Internal::TextureManager& GetTextureManager();
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.
*/
Internal::VisualFactoryCache& GetFactoryCache();
std::unique_ptr<TextVisualShaderFactory> mTextVisualShaderFactory;
SlotDelegate<VisualFactory> mSlotDelegate;
CallbackBase* mIdleCallback;
-
using DiscardedVisualContainer = std::vector<Toolkit::Visual::Base>;
DiscardedVisualContainer mDiscardedVisuals{};
-
- bool mDebugEnabled : 1;
- bool mPreMultiplyOnLoad : 1; ///< Local store for this flag
+ bool mDebugEnabled : 1;
+ bool mPreMultiplyOnLoad : 1; ///< Local store for this flag
+ bool mPrecompiledShaderRequested : 1;
};
/**