X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fvisuals%2Fimage-visual-shader-factory.h;h=7dfefbc6ced5146139c861113046dd022eccd9e0;hp=604b49b5400c882243eeb4582ea7c0474b703617;hb=11e1ee5bb1a33525dd3016a0fd145a6a3ee2c133;hpb=8cd8392e5982d60111b0a2a5d33457c06e8532f5 diff --git a/dali-toolkit/internal/visuals/image-visual-shader-factory.h b/dali-toolkit/internal/visuals/image-visual-shader-factory.h index 604b49b..7dfefbc 100644 --- a/dali-toolkit/internal/visuals/image-visual-shader-factory.h +++ b/dali-toolkit/internal/visuals/image-visual-shader-factory.h @@ -2,7 +2,7 @@ #define DALI_TOOLKIT_IMAGE_VISUAL_SHADER_FACTORY_H /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 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. @@ -30,40 +30,129 @@ namespace Toolkit namespace Internal { /** + * ImageVisualShaderFeature contains feature lists what image visual shader need to know. + */ +namespace ImageVisualShaderFeature +{ +namespace TextureAtlas +{ +/** * @brief Whether use texture with atlas, or not */ -enum class TextureAtlas +enum Type { - DISABLED = 0, ///< Image visual use ATLAS - ENABLED ///< Image visual doesn't use ATLAS + DISABLED = 0, ///< Image visual doesn't use ATLAS + ENABLED ///< Image visual uses ATLAS }; +} // namespace TextureAtlas +namespace DefaultTextureWrapMode +{ /** * @brief Whether apply to texture wraping in default, or not */ -enum class DefaultTextureWrapMode +enum Type { - DO_NOT_APPLY = 0, ///< Image visual doesn't apply to wraping texture in default - APPLY ///< Image visual apply to wraping texture in default + APPLY = 0, ///< Image visual applies to wraping texture in default + DO_NOT_APPLY ///< Image visual doesn't apply to wraping texture in default }; +} // namespace DefaultTextureWrapMode +namespace RoundedCorner +{ /** * @brief Whether use rounded corner, or not */ -enum class RoundedCorner +enum Type { DISABLED = 0, ///< Image visual doesn't use rounded corner - ENABLED ///< Image visual use rounded corner + ENABLED ///< Image visual uses rounded corner }; +} // namespace RoundedCorner +namespace Borderline +{ /** * @brief Whether use borderline, or not */ -enum class Borderline +enum Type { DISABLED = 0, ///< Image visual doesn't use borderline - ENABLED ///< Image visual use borderline + ENABLED ///< Image visual uses borderline +}; +} // namespace Borderline + +namespace ChangeFragmentShader +{ +/** + * @brief Whether native image change the default fragment shader, or not + */ +enum Type +{ + DONT_CHANGE = 0, ///< Native image doesn't change default fragment shader. + NEED_CHANGE, ///< Native image changes default fragment shader. We need another shader cache. + UNDECIDED, ///< Undecided. +}; +} // namespace ChangeFragmentShader + +namespace AlphaMaskingOnRendering +{ +/** + * @brief Whether use runtime alpha masking in shader, or not + */ +enum Type +{ + DISABLED = 0, ///< Image visual doesn't use runtime alpha masking + ENABLED ///< Image visual uses runtime alpha masking }; +} // namespace AlphaMaskingOnRendering + +namespace ColorConversion +{ +/** + * @brief Whether the color format conversion is needed or not + */ +enum Type +{ + DONT_NEED = 0, ///< Not need to convert + YUV_TO_RGB ///< Need yuv to rgb conversion +}; +} // namespace ColorConversion + +/** + * @brief Collection of current image visual feature. Only use for ImageVisualShaderFactory::GetShader() + */ +struct FeatureBuilder +{ + FeatureBuilder() + : mTextureAtlas(TextureAtlas::DISABLED), + mDefaultTextureWrapMode(DefaultTextureWrapMode::APPLY), + mRoundedCorner(RoundedCorner::DISABLED), + mBorderline(Borderline::DISABLED), + mAlphaMaskingOnRendering(AlphaMaskingOnRendering::DISABLED), + mColorConversion(ColorConversion::DONT_NEED), + mTexture() + { + } + + FeatureBuilder& EnableTextureAtlas(bool enableTextureAtlas); + FeatureBuilder& ApplyDefaultTextureWrapMode(bool applyDefaultTextureWrapMode); + FeatureBuilder& EnableRoundedCorner(bool enableRoundedCorner); + FeatureBuilder& EnableBorderline(bool enableBorderline); + FeatureBuilder& SetTextureForFragmentShaderCheck(const Dali::Texture& texture); + FeatureBuilder& EnableAlphaMaskingOnRendering(bool enableAlphaMaskingOnRendering); + FeatureBuilder& EnableYuvToRgb(bool enableYuvToRgb); + + TextureAtlas::Type mTextureAtlas : 2; ///< Whether use texture with atlas, or not. default as TextureAtlas::DISABLED + DefaultTextureWrapMode::Type mDefaultTextureWrapMode : 2; ///< Whether apply to texture wraping in default, or not. default as DefaultTextureWrapMode::APPLY + RoundedCorner::Type mRoundedCorner : 2; ///< Whether use rounded corner, or not. default as RoundedCorner::DISABLED + Borderline::Type mBorderline : 2; ///< Whether use borderline, or not. default as Borderline::DISABLED + AlphaMaskingOnRendering::Type mAlphaMaskingOnRendering : 2; ///< Whether use runtime alpha masking, or not. default as AlphaMaskingOnRendering::DISABLED + ColorConversion::Type mColorConversion : 2; ///< Whether the color format conversion is needed or not + Dali::Texture mTexture; ///< Texture to check whether we need to change fragment shader or not +}; + +} // namespace ImageVisualShaderFeature /** * ImageVisualShaderFactory is an object that provides and shares shaders between image visuals @@ -71,7 +160,6 @@ enum class Borderline class ImageVisualShaderFactory { public: - /** * @brief Constructor */ @@ -83,23 +171,21 @@ public: ~ImageVisualShaderFactory(); /** - * Get the standard image rendering shader. + * @brief Get the standard image rendering shader. * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object - * @param[in] atlasing Whether texture atlasing is applied. - * @param[in] defaultTextureWrapping Whether the default texture wrap mode is applied. - * @param[in] roundedCorner Whether the rounded corder is applied. - * @param[in] borderline Whether the borderline of visual is applied. + * @param[in] featureBuilder Collection of current image shader's features + * @return The standard image rendering shader with features. */ - Shader GetShader(VisualFactoryCache& factoryCache, TextureAtlas atlasing, DefaultTextureWrapMode defaultTextureWrapping, RoundedCorner roundedCorner, Borderline borderline); + Shader GetShader(VisualFactoryCache& factoryCache, const ImageVisualShaderFeature::FeatureBuilder& featureBuilder); /** - * Request the default vertex shader source. + * @brief Request the default vertex shader source. * @return The default vertex shader source. */ std::string_view GetVertexShaderSource(); /** - * Request the default fragment shader source. + * @brief Request the default fragment shader source. * @return The default fragment shader source. */ std::string_view GetFragmentShaderSource(); @@ -116,6 +202,18 @@ protected: ImageVisualShaderFactory& operator=(const ImageVisualShaderFactory& rhs); private: + /** + * @brief Cached information whether native image should change fragment shader. + * Default it is ChangeFragmentShader::UNDECIDED. + * If we have any chance to check native image source apply fragment shader, + * this vaule will be changed one of these : ChangeFragmentShader::DONT_CHANGE or ChangeFragmentShader::NEED_CHANGE + * + * After result cached, this value will not be changed. + * + * If value is DONT_CHANGE, ImageVisualShaderFactory::GetShader never call ApplyNativeFragmentShader. + * Else, ImageVisualShaderFactory::GetShader will call ApplyNativeFragmentShader if native image source texture come. + */ + ImageVisualShaderFeature::ChangeFragmentShader::Type mFragmentShaderNeedChange : 3; }; } // namespace Internal