1 #ifndef DALI_TOOLKIT_NPATCH_LOADER_H
2 #define DALI_TOOLKIT_NPATCH_LOADER_H
5 * Copyright (c) 2021 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.
21 #include <dali/devel-api/adaptor-framework/pixel-buffer.h>
22 #include <dali/devel-api/common/owner-container.h>
23 #include <dali/public-api/rendering/texture-set.h>
27 #include <dali-toolkit/devel-api/utility/npatch-utilities.h>
28 #include <dali-toolkit/internal/visuals/npatch-data.h>
29 #include <dali-toolkit/internal/visuals/texture-manager-impl.h>
38 * The manager for loading Npatch textures.
39 * It caches them internally for better performance; i.e. to avoid loading and
40 * parsing the files over and over.
42 * Cache is not cleaned during app lifecycle as N patches take considerably
43 * small space and there's not usually a lot of them. Usually N patches are specified in
44 * toolkit default style and there is 1-2 per control that are shared across the whole application.
55 * Destructor, non-virtual as not a base class
60 * @brief Retrieve a texture matching the n-patch url.
62 * @param [in] textureManager that will be used to loading image
63 * @param [in] textureObserver The NPatchVisual that requested loading.
64 * @param [in] url to retrieve
65 * @param [in] border The border size of the image
66 * @param [in,out] preMultiplyOnLoad True if the image color should be multiplied by it's alpha. Set to false if the
67 * image has no alpha channel
68 * @param [in] synchronousLoading True if the image will be loaded in synchronous time.
69 * @return id of the texture.
71 std::size_t Load(TextureManager& textureManager, TextureUploadObserver* textureObserver, const std::string& url, const Rect<int>& border, bool& preMultiplyOnLoad, bool synchronousLoading);
74 * @brief Set loaded PixelBuffer and its information
76 * @param [in] id cache data id
77 * @param [in] pixelBuffer of loaded image
78 * @param [in] preMultiplied True if the image had pre-multiplied alpha applied
80 void SetNPatchData(std::size_t id, Devel::PixelBuffer& pixelBuffer, bool preMultiplied);
83 * @brief Retrieve N patch data matching to an id
84 * @param [in] id of data
85 * @param [out] data const pointer to the NPatchData
86 * @return true if data matching to id was really found
88 bool GetNPatchData(const NPatchData::NPatchDataId id, const NPatchData*& data);
91 * @brief Remove a texture matching id.
92 * Erase the observer from the observer list of cache.
93 * If the observer list is empty, the textureSet will be reset.
95 * @param [in] id cache data id
96 * @param [in] textureObserver The NPatchVisual that requested loading.
98 void Remove(std::size_t id, TextureUploadObserver* textureObserver);
101 NPatchData::NPatchDataId GenerateUniqueNPatchDataId();
103 int32_t GetCacheIndexFromId(const NPatchData::NPatchDataId id);
107 * Undefined copy constructor.
109 NPatchLoader(const NPatchLoader&);
112 * Undefined assignment operator.
114 NPatchLoader& operator=(const NPatchLoader& rhs);
117 NPatchData::NPatchDataId mCurrentNPatchDataId;
118 OwnerContainer<NPatchData*> mCache;
121 } // namespace Internal
123 } // namespace Toolkit
127 #endif // DALI_TOOLKIT_NPATCH_LOADER_H