[dali_2.3.20] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / text-visual-shader-factory.h
1 #ifndef DALI_TOOLKIT_TEXT_VISUAL_SHADER_FACTORY_H
2 #define DALI_TOOLKIT_TEXT_VISUAL_SHADER_FACTORY_H
3
4 /*
5  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 // EXTERNAL INCLUDES
21
22 // INTERNAL INCLUDES
23 #include <dali-toolkit/internal/visuals/visual-factory-cache.h>
24 #include <string_view>
25
26 namespace Dali
27 {
28 namespace Toolkit
29 {
30 namespace Internal
31 {
32 /**
33  * TextVisualShaderFeature contains feature lists what text visual shader need to know.
34  */
35 namespace TextVisualShaderFeature
36 {
37 namespace TextMultiColor
38 {
39 /**
40  * @brief Whether text contains single color or not.
41  */
42 enum Type
43 {
44   SINGLE_COLOR_TEXT = 0, ///< The text contains single color only.
45   MULTI_COLOR_TEXT       ///< The text contains multiple colors.
46 };
47 } // namespace TextMultiColor
48
49 namespace TextEmoji
50 {
51 /**
52  * @brief Whether text contains emoji or not.
53  */
54 enum Type
55 {
56   NO_EMOJI = 0, ///< The text contains no emoji.
57   HAS_EMOJI     ///< The text contains emoji.
58 };
59 } // namespace TextEmoji
60
61 namespace TextStyle
62 {
63 /**
64  * @brief Whether text contains styles (like shadow or background color) or not.
65  */
66 enum Type
67 {
68   NO_STYLES = 0, ///< The text contains contains no styles.
69   HAS_STYLES     ///< The text contains contains styles.
70 };
71 } // namespace TextStyle
72
73 namespace TextOverlay
74 {
75 /**
76  * @brief Whether text contains overlay styles (like markdown) or not.
77  */
78 enum Type
79 {
80   NO_OVERLAY = 0, ///< The text contains contains no overlay.
81   HAS_OVERLAY     ///< The text contains contains overlay.
82 };
83 } // namespace TextOverlay
84
85 /**
86  * @brief Collection of current text visual feature.
87  */
88 struct FeatureBuilder
89 {
90   FeatureBuilder()
91   : mTextMultiColor(TextMultiColor::SINGLE_COLOR_TEXT),
92     mTextEmoji(TextEmoji::NO_EMOJI),
93     mTextStyle(TextStyle::NO_STYLES),
94     mTextOverlay(TextOverlay::NO_OVERLAY)
95   {
96   }
97
98   FeatureBuilder& EnableMultiColor(bool enableMultiColor);
99   FeatureBuilder& EnableEmoji(bool enableEmoji);
100   FeatureBuilder& EnableStyle(bool enableStyle);
101   FeatureBuilder& EnableOverlay(bool enableOverlay);
102
103   bool IsEnabledMultiColor() const
104   {
105     return mTextMultiColor == TextMultiColor::MULTI_COLOR_TEXT;
106   }
107   bool IsEnabledEmoji() const
108   {
109     return mTextEmoji == TextEmoji::HAS_EMOJI;
110   }
111   bool IsEnabledStyle() const
112   {
113     return mTextStyle == TextStyle::HAS_STYLES;
114   }
115   bool IsEnabledOverlay() const
116   {
117     return mTextOverlay == TextOverlay::HAS_OVERLAY;
118   }
119
120   TextMultiColor::Type mTextMultiColor : 2; ///< Whether text has multiple color, or not. default as TextMultiColor::SINGLE_COLOR_TEXT
121   TextEmoji::Type      mTextEmoji : 2;      ///< Whether text has emoji, or not. default as TextEmoji::NO_EMOJI
122   TextStyle::Type      mTextStyle : 2;      ///< Whether text has style, or not. default as TextStyle::NO_STYLES
123   TextOverlay::Type    mTextOverlay : 2;    ///< Whether text has overlay style, or not. default as TextOverlay::NO_OVERLAY
124 };
125
126 } // namespace TextVisualShaderFeature
127
128 /**
129  * TextVisualShaderFactory is an object that provides and shares shaders for text visuals
130  */
131 class TextVisualShaderFactory
132 {
133 public:
134   /**
135    * @brief Constructor
136    */
137   TextVisualShaderFactory();
138
139   /**
140    * @brief Destructor
141    */
142   ~TextVisualShaderFactory();
143
144   /**
145    * @brief Get the standard text rendering shader.
146    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
147    * @param[in] featureBuilder Collection of current text shader's features
148    * @return The standard text rendering shader with features.
149    */
150   Shader GetShader(VisualFactoryCache& factoryCache, const TextVisualShaderFeature::FeatureBuilder& featureBuilder);
151
152   /**
153    * @brief Get the default shader source.
154    * @param[in] shaders shaderList for precompile
155    */
156   void GetPreCompiledShader(RawShaderData& shaders);
157
158 protected:
159   /**
160    * Undefined copy constructor.
161    */
162   TextVisualShaderFactory(const TextVisualShaderFactory&);
163
164   /**
165    * Undefined assignment operator.
166    */
167   TextVisualShaderFactory& operator=(const TextVisualShaderFactory& rhs);
168
169 private:
170 };
171
172 } // namespace Internal
173
174 } // namespace Toolkit
175
176 } // namespace Dali
177
178 #endif // DALI_TOOLKIT_TEXT_VISUAL_SHADER_FACTORY_H