/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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.
{
const Vector4 FULL_TEXTURE_RECT(0.f, 0.f, 1.f, 1.f);
-// global string variable to caching complate vertex shader
-static std::string gVertexShader;
-
-// global string variable to caching complate fragment shader (no atlas)
-static std::string gFragmentShaderNoAtlas;
-
const int NATIVE_SHADER_TYPE_OFFSET = VisualFactoryCache::ShaderType::NATIVE_IMAGE_SHADER - VisualFactoryCache::ShaderType::IMAGE_SHADER;
// enum of required list when we select shader
enum class ImageVisualRequireFlag : uint32_t
{
- DEFAULT = 0,
- ROUNDED_CORNER = 1 << 0,
- BORDERLINE = 1 << 1,
- ALPHA_MASKING = 1 << 2,
-};
+ DEFAULT = 0,
+ ROUNDED_CORNER = 1 << 0,
+ BORDERLINE = 1 << 1,
+ ALPHA_MASKING = 1 << 2,
+ COLOR_CONVERSION = 1 << 3,
-static constexpr auto SHADER_TYPE_COUNT = 8u;
-VisualFactoryCache::ShaderType SHADER_TYPE_TABLE[SHADER_TYPE_COUNT] =
-{
- VisualFactoryCache::IMAGE_SHADER,
- VisualFactoryCache::IMAGE_SHADER_ROUNDED_CORNER,
- VisualFactoryCache::IMAGE_SHADER_BORDERLINE,
- VisualFactoryCache::IMAGE_SHADER_ROUNDED_BORDERLINE,
- VisualFactoryCache::IMAGE_SHADER_MASKING,
- VisualFactoryCache::IMAGE_SHADER_ROUNDED_CORNER_MASKING,
- VisualFactoryCache::IMAGE_SHADER_BORDERLINE_MASKING,
- VisualFactoryCache::IMAGE_SHADER_ROUNDED_BORDERLINE_MASKING
+ UNIFIED_YUV_AND_RGB = 1 << 2, // Special enum to trick unified YUV and RGB.
};
+static constexpr auto SHADER_TYPE_COUNT = 16u;
+VisualFactoryCache::ShaderType SHADER_TYPE_TABLE[SHADER_TYPE_COUNT] =
+ {
+ VisualFactoryCache::IMAGE_SHADER,
+ VisualFactoryCache::IMAGE_SHADER_ROUNDED_CORNER,
+ VisualFactoryCache::IMAGE_SHADER_BORDERLINE,
+ VisualFactoryCache::IMAGE_SHADER_ROUNDED_BORDERLINE,
+ VisualFactoryCache::IMAGE_SHADER_MASKING,
+ VisualFactoryCache::IMAGE_SHADER_ROUNDED_CORNER_MASKING,
+ VisualFactoryCache::IMAGE_SHADER_BORDERLINE_MASKING,
+ VisualFactoryCache::IMAGE_SHADER_ROUNDED_BORDERLINE_MASKING,
+ VisualFactoryCache::IMAGE_SHADER_YUV_TO_RGB,
+ VisualFactoryCache::IMAGE_SHADER_ROUNDED_CORNER_YUV_TO_RGB,
+ VisualFactoryCache::IMAGE_SHADER_BORDERLINE_YUV_TO_RGB,
+ VisualFactoryCache::IMAGE_SHADER_ROUNDED_BORDERLINE_YUV_TO_RGB,
+ VisualFactoryCache::IMAGE_SHADER_YUV_AND_RGB,
+ VisualFactoryCache::IMAGE_SHADER_ROUNDED_CORNER_YUV_AND_RGB,
+ VisualFactoryCache::IMAGE_SHADER_BORDERLINE_YUV_AND_RGB,
+ VisualFactoryCache::IMAGE_SHADER_ROUNDED_BORDERLINE_YUV_AND_RGB};
} // unnamed namespace
namespace ImageVisualShaderFeature
mTextureAtlas = (enableAtlas ? TextureAtlas::ENABLED : TextureAtlas::DISABLED);
return *this;
}
+
FeatureBuilder& FeatureBuilder::ApplyDefaultTextureWrapMode(bool applyDefaultTextureWrapMode)
{
mDefaultTextureWrapMode = (applyDefaultTextureWrapMode ? DefaultTextureWrapMode::APPLY : DefaultTextureWrapMode::DO_NOT_APPLY);
return *this;
}
+
FeatureBuilder& FeatureBuilder::EnableRoundedCorner(bool enableRoundedCorner)
{
mRoundedCorner = (enableRoundedCorner ? RoundedCorner::ENABLED : RoundedCorner::DISABLED);
return *this;
}
+
FeatureBuilder& FeatureBuilder::EnableBorderline(bool enableBorderline)
{
mBorderline = (enableBorderline ? Borderline::ENABLED : Borderline::DISABLED);
return *this;
}
+
FeatureBuilder& FeatureBuilder::SetTextureForFragmentShaderCheck(const Dali::Texture& texture)
{
mTexture = texture;
return *this;
}
+
FeatureBuilder& FeatureBuilder::EnableAlphaMaskingOnRendering(bool enableAlphaMaskingOnRendering)
{
mAlphaMaskingOnRendering = (enableAlphaMaskingOnRendering ? AlphaMaskingOnRendering::ENABLED : AlphaMaskingOnRendering::DISABLED);
return *this;
}
+
+FeatureBuilder& FeatureBuilder::EnableYuvToRgb(bool enableYuvToRgb, bool enableUnifiedYuvAndRgb)
+{
+ mColorConversion = (enableUnifiedYuvAndRgb ? ColorConversion::UNIFIED_YUV_AND_RGB : (enableYuvToRgb ? ColorConversion::YUV_TO_RGB : ColorConversion::DONT_NEED));
+ return *this;
+}
} // namespace ImageVisualShaderFeature
ImageVisualShaderFactory::ImageVisualShaderFactory()
Shader ImageVisualShaderFactory::GetShader(VisualFactoryCache& factoryCache, const ImageVisualShaderFeature::FeatureBuilder& featureBuilder)
{
- Shader shader;
+ Shader shader;
VisualFactoryCache::ShaderType shaderType = VisualFactoryCache::IMAGE_SHADER;
const auto& atlasing = featureBuilder.mTextureAtlas;
const auto& roundedCorner = featureBuilder.mRoundedCorner;
const auto& borderline = featureBuilder.mBorderline;
const auto& alphaMaskingOnRendering = featureBuilder.mAlphaMaskingOnRendering;
+ const auto& colorConversion = featureBuilder.mColorConversion;
const auto& changeFragmentShader = (featureBuilder.mTexture && DevelTexture::IsNative(featureBuilder.mTexture))
? ImageVisualShaderFeature::ChangeFragmentShader::NEED_CHANGE
: ImageVisualShaderFeature::ChangeFragmentShader::DONT_CHANGE;
{
shaderTypeFlag |= static_cast<uint32_t>(ImageVisualRequireFlag::ALPHA_MASKING);
}
+ else if(colorConversion == ImageVisualShaderFeature::ColorConversion::YUV_TO_RGB) // Not support gpu masking and color conversion at the same time now
+ {
+ shaderTypeFlag |= static_cast<uint32_t>(ImageVisualRequireFlag::COLOR_CONVERSION);
+ }
+ else if(colorConversion == ImageVisualShaderFeature::ColorConversion::UNIFIED_YUV_AND_RGB)
+ {
+ shaderTypeFlag |= static_cast<uint32_t>(ImageVisualRequireFlag::COLOR_CONVERSION);
+ shaderTypeFlag |= static_cast<uint32_t>(ImageVisualRequireFlag::UNIFIED_YUV_AND_RGB);
+ }
shaderType = SHADER_TYPE_TABLE[shaderTypeFlag];
}
{
if(defaultTextureWrapping == ImageVisualShaderFeature::DefaultTextureWrapMode::APPLY)
{
- fragmentShaderPrefixList += "#define ATLAS_DEFAULT_WARP 1\n";
+ fragmentShaderPrefixList += "#define ATLAS_DEFAULT_WARP\n";
}
else
{
- fragmentShaderPrefixList += "#define ATLAS_CUSTOM_WARP 1\n";
+ fragmentShaderPrefixList += "#define ATLAS_CUSTOM_WARP\n";
}
}
else
{
if(roundedCorner == ImageVisualShaderFeature::RoundedCorner::ENABLED)
{
- vertexShaderPrefixList += "#define IS_REQUIRED_ROUNDED_CORNER 1\n";
- fragmentShaderPrefixList += "#define IS_REQUIRED_ROUNDED_CORNER 1\n";
+ vertexShaderPrefixList += "#define IS_REQUIRED_ROUNDED_CORNER\n";
+ fragmentShaderPrefixList += "#define IS_REQUIRED_ROUNDED_CORNER\n";
}
if(borderline == ImageVisualShaderFeature::Borderline::ENABLED)
{
- vertexShaderPrefixList += "#define IS_REQUIRED_BORDERLINE 1\n";
- fragmentShaderPrefixList += "#define IS_REQUIRED_BORDERLINE 1\n";
+ vertexShaderPrefixList += "#define IS_REQUIRED_BORDERLINE\n";
+ fragmentShaderPrefixList += "#define IS_REQUIRED_BORDERLINE\n";
}
if(alphaMaskingOnRendering == ImageVisualShaderFeature::AlphaMaskingOnRendering::ENABLED)
{
- vertexShaderPrefixList += "#define IS_REQUIRED_ALPHA_MASKING 1\n";
- fragmentShaderPrefixList += "#define IS_REQUIRED_ALPHA_MASKING 1\n";
+ vertexShaderPrefixList += "#define IS_REQUIRED_ALPHA_MASKING\n";
+ fragmentShaderPrefixList += "#define IS_REQUIRED_ALPHA_MASKING\n";
+ }
+ else if(colorConversion == ImageVisualShaderFeature::ColorConversion::YUV_TO_RGB)
+ {
+ fragmentShaderPrefixList += "#define IS_REQUIRED_YUV_TO_RGB\n";
+ }
+ else if(colorConversion == ImageVisualShaderFeature::ColorConversion::UNIFIED_YUV_AND_RGB)
+ {
+ fragmentShaderPrefixList += "#define IS_REQUIRED_UNIFIED_YUV_AND_RGB\n";
}
}
- std::string vertexShader = std::string(Dali::Shader::GetVertexShaderPrefix() + vertexShaderPrefixList + SHADER_IMAGE_VISUAL_SHADER_VERT.data());
+ std::string vertexShader = std::string(Dali::Shader::GetVertexShaderPrefix() + vertexShaderPrefixList + SHADER_IMAGE_VISUAL_SHADER_VERT.data());
std::string fragmentShader = std::string(Dali::Shader::GetFragmentShaderPrefix() + fragmentShaderPrefixList + SHADER_IMAGE_VISUAL_SHADER_FRAG.data());
if(changeFragmentShader == ImageVisualShaderFeature::ChangeFragmentShader::NEED_CHANGE)
std::string_view ImageVisualShaderFactory::GetVertexShaderSource()
{
+ // static string variable to cache complete vertex shader
+ static std::string gVertexShader;
if(gVertexShader.empty())
{
gVertexShader = Dali::Shader::GetVertexShaderPrefix() + SHADER_IMAGE_VISUAL_SHADER_VERT.data();
std::string_view ImageVisualShaderFactory::GetFragmentShaderSource()
{
+ // static string variable to cache complete fragment shader (no atlas)
+ static std::string gFragmentShaderNoAtlas;
if(gFragmentShaderNoAtlas.empty())
{
gFragmentShaderNoAtlas = Dali::Shader::GetFragmentShaderPrefix() + SHADER_IMAGE_VISUAL_SHADER_FRAG.data();