Support animation of Visual transform properties
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / npatch-loader.h
1 #ifndef DALI_TOOLKIT_NPATCH_LOADER_H
2 #define DALI_TOOLKIT_NPATCH_LOADER_H
3
4 /*
5  * Copyright (c) 2020 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 <string>
22 #include <dali/public-api/rendering/texture-set.h>
23 #include <dali/devel-api/common/owner-container.h>
24 #include <dali/devel-api/adaptor-framework/pixel-buffer.h>
25
26 // INTERNAL INCLUDES
27 #include <dali-toolkit/internal/visuals/npatch-data.h>
28 #include <dali-toolkit/internal/visuals/texture-manager-impl.h>
29 #include <dali-toolkit/devel-api/utility/npatch-utilities.h>
30
31 namespace Dali
32 {
33
34 namespace Toolkit
35 {
36
37 namespace Internal
38 {
39
40 /**
41  * The manager for loading Npatch textures.
42  * It caches them internally for better performance; i.e. to avoid loading and
43  * parsing the files over and over.
44  *
45  * Cache is not cleaned during app lifecycle as N patches take considerably
46  * small space and there's not usually a lot of them. Usually N patches are specified in
47  * toolkit default style and there is 1-2 per control that are shared across the whole application.
48  */
49 class NPatchLoader
50 {
51 public:
52
53   /**
54    * Constructor
55    */
56   NPatchLoader();
57
58   /**
59    * Destructor, non-virtual as not a base class
60    */
61   ~NPatchLoader();
62
63   /**
64    * @brief Retrieve a texture matching the n-patch url.
65    *
66    * @param [in] textureManager that will be used to loading image
67    * @param [in] textureObserver The NPatchVisual that requested loading.
68    * @param [in] url to retrieve
69    * @param [in] border The border size of the image
70    * @param [in,out] preMultiplyOnLoad True if the image color should be multiplied by it's alpha. Set to false if the
71    *                                   image has no alpha channel
72    * @param [in] synchronousLoading True if the image will be loaded in synchronous time.
73    * @return id of the texture.
74    */
75   std::size_t Load( TextureManager& textureManager, TextureUploadObserver* textureObserver, const std::string& url, const Rect< int >& border, bool& preMultiplyOnLoad, bool synchronousLoading );
76
77   /**
78    * @brief Set loaded PixelBuffer and its information
79    *
80    * @param [in] id cache data id
81    * @param [in] pixelBuffer of loaded image
82    * @param [in] preMultiplied True if the image had pre-multiplied alpha applied
83    */
84   void SetNPatchData( std::size_t id, Devel::PixelBuffer& pixelBuffer, bool preMultiplied );
85
86   /**
87    * @brief Retrieve N patch data matching to an id
88    * @param [in] id of data
89    * @param [out] data const pointer to the NPatchData
90    * @return true if data matching to id was really found
91    */
92   bool GetNPatchData( const NPatchData::NPatchDataId id, const NPatchData*& data );
93
94   /**
95    * @brief Remove a texture matching id.
96    * Erase the observer from the observer list of cache.
97    * If the observer list is empty, the textureSet will be reset.
98    *
99    * @param [in] id cache data id
100    * @param [in] textureObserver The NPatchVisual that requested loading.
101    */
102   void Remove( std::size_t id, TextureUploadObserver* textureObserver );
103
104 private:
105
106   NPatchData::NPatchDataId GenerateUniqueNPatchDataId();
107
108   int32_t GetCacheIndexFromId( const NPatchData::NPatchDataId id );
109
110 protected:
111
112   /**
113    * Undefined copy constructor.
114    */
115   NPatchLoader(const NPatchLoader&);
116
117   /**
118    * Undefined assignment operator.
119    */
120   NPatchLoader& operator=(const NPatchLoader& rhs);
121
122 private:
123
124   NPatchData::NPatchDataId mCurrentNPatchDataId;
125   OwnerContainer< NPatchData* > mCache;
126 };
127
128 } // name Internal
129
130 } // namespace Toolkit
131
132 } // namespace Dali
133
134 #endif // DALI_TOOLKIT_NPATCH_LOADER_H