Support the blur radius of the ColorVisual
[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/public-api/math/uint-16-pair.h>
24 #include <dali/devel-api/common/owner-container.h>
25 #include <dali/devel-api/adaptor-framework/pixel-buffer.h>
26
27 // INTERNAL HEADERS
28 #include <dali-toolkit/internal/visuals/texture-manager-impl.h>
29
30 namespace Dali
31 {
32
33 namespace Toolkit
34 {
35
36 namespace Internal
37 {
38
39 namespace NPatchBuffer
40 {
41
42 void GetRedOffsetAndMask( Dali::Pixel::Format pixelFormat, int& byteOffset, int& bitMask );
43
44 } // namespace NPatchBuffer
45
46 /**
47  * The manager for loading Npatch textures.
48  * It caches them internally for better performance; i.e. to avoid loading and
49  * parsing the files over and over.
50  *
51  * Cache is not cleaned during app lifecycle as N patches take considerably
52  * small space and there's not usually a lot of them. Usually N patches are specified in
53  * toolkit default style and there is 1-2 per control that are shared across the whole application.
54  */
55 class NPatchLoader
56 {
57 public:
58
59   typedef Dali::Vector< Uint16Pair > StretchRanges;
60
61   enum
62   {
63     UNINITIALIZED_ID = 0 ///< uninitialised id, use to initialize ids
64   };
65
66   struct Data
67   {
68     Data()
69     : url(),
70       textureSet(),
71       hash( 0 ),
72       croppedWidth( 0 ),
73       croppedHeight( 0 ),
74       border( 0, 0, 0, 0 ),
75       loadCompleted( false )
76     {}
77
78     std::string url;                              ///< Url of the N-Patch
79     TextureSet textureSet;                        ///< Texture containing the cropped image
80     StretchRanges stretchPixelsX;                 ///< X stretch pixels
81     StretchRanges stretchPixelsY;                 ///< Y stretch pixels
82     std::size_t hash;                             ///< Hash code for the Url
83     uint32_t croppedWidth;                        ///< Width of the cropped middle part of N-patch
84     uint32_t croppedHeight;                       ///< Height of the cropped middle part of N-patch
85     Rect< int > border;                           ///< The size of the border
86     bool loadCompleted;                           ///< True if the data loading is completed
87   };
88
89 public:
90
91   /**
92    * Constructor
93    */
94   NPatchLoader();
95
96   /**
97    * Destructor, non-virtual as not a base class
98    */
99   ~NPatchLoader();
100
101   /**
102    * @brief Retrieve a texture matching the n-patch url.
103    *
104    * @param [in] textureManager that will be used to loading image
105    * @param [in] textureObserver The NPatchVisual that requested loading.
106    * @param [in] url to retrieve
107    * @param [in] border The border size of the image
108    * @param [in,out] preMultiplyOnLoad True if the image color should be multiplied by it's alpha. Set to false if the
109    *                                   image has no alpha channel
110    * @param [in] synchronousLoading True if the image will be loaded in synchronous time.
111    * @return id of the texture.
112    */
113   std::size_t Load( TextureManager& textureManager, TextureUploadObserver* textureObserver, const std::string& url, const Rect< int >& border, bool& preMultiplyOnLoad, bool synchronousLoading );
114
115   /**
116    * @brief Set loaded PixelBuffer and its information
117    *
118    * @param [in] id cache data id
119    * @param [in] pixelBuffer of loaded image
120    */
121   void SetNPatchData( std::size_t id, Devel::PixelBuffer& pixelBuffer );
122
123   /**
124    * @brief Retrieve N patch data matching to an id
125    * @param [in] id of data
126    * @param [out] data const pointer to the data
127    * @return true if data matching to id was really found
128    */
129   bool GetNPatchData( std::size_t id, const Data*& data );
130
131 protected:
132
133   /**
134    * Undefined copy constructor.
135    */
136   NPatchLoader(const NPatchLoader&);
137
138   /**
139    * Undefined assignment operator.
140    */
141   NPatchLoader& operator=(const NPatchLoader& rhs);
142
143 private:
144
145   OwnerContainer< Data* > mCache;
146
147 };
148
149 } // name Internal
150
151 } // namespace Toolkit
152
153 } // namespace Dali
154
155 #endif // DALI_TOOLKIT_NPATCH_LOADER_H