(Vector) Support EncodedImageBuffer can use for vector image
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / visual-url.h
1 #ifndef DALI_TOOLKIT_INTERNAL_VISUAL_URL_H
2 #define DALI_TOOLKIT_INTERNAL_VISUAL_URL_H
3
4 /*
5  * Copyright (c) 2023 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 #include <cstdint>
22 #include <string>
23 #include <string_view>
24
25 namespace Dali
26 {
27 namespace Toolkit
28 {
29 namespace Internal
30 {
31 class VisualUrl
32 {
33 public:
34   /**
35    * The type of the URL based on the string contents
36    */
37   enum Type
38   {
39     REGULAR_IMAGE,
40     N_PATCH,
41     SVG,
42     GIF,
43     WEBP,
44     JSON,
45     TVG
46   };
47
48   enum ProtocolType
49   {
50     LOCAL,   ///< file in local file system
51     TEXTURE, ///< texture uploaded to texture manager
52     REMOTE,  ///< remote image
53     BUFFER   ///< encoded image buffer
54   };
55
56   /**
57    * Default Constructor.
58    * Resulting URL is not valid
59    */
60   VisualUrl();
61
62   /**
63    * Default Destructor.
64    * Delete an external texture if if protocolType is TEXTURE.
65    */
66   ~VisualUrl();
67
68   /**
69    * Constructor.
70    * Determines type of visual and whether the url is local or remote
71    * Notify that it is using an external texture if if protocolType is TEXTURE.
72    *
73    * @param[in] url The URL to store and resolve
74    */
75   VisualUrl(const std::string& url);
76
77   /**
78    * Copy constructor
79    * @param[in] url The VisualUrl to copy
80    */
81   VisualUrl(const VisualUrl& url);
82
83   /**
84    * Assignment operator
85    * @param[in] url The VisualUrl to copy
86    */
87   VisualUrl& operator=(const VisualUrl& url);
88
89   /**
90    * Move constructor
91    * @param[in] url The VisualUrl to move
92    */
93   VisualUrl(VisualUrl&& url) noexcept;
94
95   /**
96    * Move assignment operator
97    * @param[in] url The VisualUrl to move
98    */
99   VisualUrl& operator=(VisualUrl&& url) noexcept;
100
101   /**
102    * Get the full URL
103    * @return The url
104    */
105   const std::string& GetUrl() const;
106
107   /**
108    * Get the hash value of full URL
109    * @return The hash value of url
110    */
111   std::uint64_t GetUrlHash() const;
112
113   /**
114    * Get the visual type of the URL
115    * @return The visual type of the URL
116    */
117   Type GetType() const;
118
119   /**
120    * Is the URL is local to the device, or remote?
121    * @return the location of the resource
122    */
123   ProtocolType GetProtocolType() const;
124
125   /**
126    * Is the URL valid?
127    * @return true if the URL has length
128    */
129   bool IsValid() const;
130
131   /**
132    * @return true if the location is LOCAL, i.e. is loadable from local file system
133    */
134   bool IsLocalResource() const;
135
136   /**
137    * @return true if the location is BUFFER, i.e. may contain EncodedImageBuffer
138    */
139   bool IsBufferResource() const;
140
141   /**
142    * @return the location part of the url
143    */
144   std::string GetLocation() const;
145
146   /**
147    * @return the location part of the url without extension
148    */
149   std::string GetLocationWithoutExtension() const;
150
151   /**
152    * Helper to create a URL of type TEXTURE
153    * @param location the location of the texture
154    * @return the Url
155    */
156   static std::string CreateTextureUrl(const std::string& location);
157
158   /**
159    * Helper to create a URL of type BUFFER
160    * @param[in] location the location of the texture
161    * @param[in] extension the extension of url
162    * @return the Url
163    */
164   static std::string CreateBufferUrl(const std::string& location, const std::string_view& extension);
165
166   /**
167    * Helper to get a ProtocolType from url
168    * @param url the url of the texture
169    * @return the protocol type
170    */
171   static VisualUrl::ProtocolType GetProtocolType(const std::string& url);
172
173   /**
174    * Helper to get a location from url
175    * @param url the location of the texture
176    * @return the location
177    */
178   static std::string GetLocation(const std::string& url);
179
180   /**
181    * Helper to get a location from url without extension
182    * @param[in] url the location of the texture
183    * @return the location without extension
184    */
185   static std::string GetLocationWithoutExtension(const std::string& url);
186
187 private:
188   std::string  mUrl;
189   Type         mType;
190   ProtocolType mLocation;
191
192   mutable std::uint64_t mUrlHash;
193 };
194
195 } // namespace Internal
196
197 } // namespace Toolkit
198
199 } // namespace Dali
200
201 #endif /* DALI_TOOLKIT_INTERNAL_VISUAL_URL_H */