1 #ifndef DALI_TOOLKIT_NPATCH_LOADER_H
2 #define DALI_TOOLKIT_NPATCH_LOADER_H
5 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
27 #include <dali-toolkit/internal/visuals/texture-manager-impl.h>
28 #include <dali-toolkit/devel-api/utility/npatch-utilities.h>
40 * The manager for loading Npatch textures.
41 * It caches them internally for better performance; i.e. to avoid loading and
42 * parsing the files over and over.
44 * Cache is not cleaned during app lifecycle as N patches take considerably
45 * small space and there's not usually a lot of them. Usually N patches are specified in
46 * toolkit default style and there is 1-2 per control that are shared across the whole application.
54 UNINITIALIZED_ID = 0 ///< uninitialised id, use to initialize ids
66 loadCompleted( false ),
67 renderingMap{ nullptr }
72 std::string url; ///< Url of the N-Patch
73 TextureSet textureSet; ///< Texture containing the cropped image
74 NPatchUtility::StretchRanges stretchPixelsX; ///< X stretch pixels
75 NPatchUtility::StretchRanges stretchPixelsY; ///< Y stretch pixels
76 std::size_t hash; ///< Hash code for the Url
77 uint32_t croppedWidth; ///< Width of the cropped middle part of N-patch
78 uint32_t croppedHeight; ///< Height of the cropped middle part of N-patch
79 Rect< int > border; ///< The size of the border
80 bool loadCompleted; ///< True if the data loading is completed
81 void* renderingMap; ///< NPatch rendering data
92 * Destructor, non-virtual as not a base class
97 * @brief Retrieve a texture matching the n-patch url.
99 * @param [in] textureManager that will be used to loading image
100 * @param [in] textureObserver The NPatchVisual that requested loading.
101 * @param [in] url to retrieve
102 * @param [in] border The border size of the image
103 * @param [in,out] preMultiplyOnLoad True if the image color should be multiplied by it's alpha. Set to false if the
104 * image has no alpha channel
105 * @param [in] synchronousLoading True if the image will be loaded in synchronous time.
106 * @return id of the texture.
108 std::size_t Load( TextureManager& textureManager, TextureUploadObserver* textureObserver, const std::string& url, const Rect< int >& border, bool& preMultiplyOnLoad, bool synchronousLoading );
111 * @brief Set loaded PixelBuffer and its information
113 * @param [in] id cache data id
114 * @param [in] pixelBuffer of loaded image
116 void SetNPatchData( std::size_t id, Devel::PixelBuffer& pixelBuffer );
119 * @brief Retrieve N patch data matching to an id
120 * @param [in] id of data
121 * @param [out] data const pointer to the data
122 * @return true if data matching to id was really found
124 bool GetNPatchData( std::size_t id, const Data*& data );
129 * Undefined copy constructor.
131 NPatchLoader(const NPatchLoader&);
134 * Undefined assignment operator.
136 NPatchLoader& operator=(const NPatchLoader& rhs);
140 OwnerContainer< Data* > mCache;
146 } // namespace Toolkit
150 #endif // DALI_TOOLKIT_NPATCH_LOADER_H