Merge "Update the refined dali c# application to support more argument options" into...
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / image-atlas-manager.h
1 #ifndef DALI_TOOLKIT_IMAGE_ATLAS_MANAGER_H
2 #define DALI_TOOLKIT_IMAGE_ATLAS_MANAGER_H
3
4 /*
5  * Copyright (c) 2016 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/common/vector-wrapper.h>
23 #include <dali/public-api/object/ref-object.h>
24 #include <dali/public-api/rendering/texture-set.h>
25
26 // INTERNAL INCLUDES
27 #include <dali-toolkit/devel-api/image-loader/image-atlas.h>
28
29 namespace Dali
30 {
31
32 namespace Toolkit
33 {
34
35 class AtlasUploadObserver;
36
37 namespace Internal
38 {
39
40 /**
41  * The manager for automatic image atlasing. Owned by VisualFactory
42  */
43 class ImageAtlasManager : public RefObject
44 {
45 public:
46   typedef std::vector< Toolkit::ImageAtlas > AtlasContainer;
47   typedef std::vector< TextureSet > TextureSetContainer;
48
49 public:
50
51   /**
52    * Construtor
53    *
54    */
55   ImageAtlasManager();
56
57   /**
58    * @brief Add an image to the atlas.
59    *
60    * @note To make the atlasing efficient, an valid size should be provided.
61    *       If size is not provided, then the image file will be opened to read the actual size for loading.
62    *
63    * SamplingMode::BOX_THEN_LINEAR is used to sampling pixels from the input image while fitting it to desired size.
64    *
65    * @param [out] textureRect The texture area of the resource image in the atlas.
66    * @param [in] url The URL of the resource image file to use.
67    * @param [in] size The width and height to fit the loaded image to.
68    * @param [in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter.
69    * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
70    * @param [in] atlasUploadObserver The object to observe the uploading state inside ImageAtlas.
71    * @return The texture set containing the image.
72    */
73   TextureSet Add( Vector4& textureRect,
74                   const std::string& url,
75                   ImageDimensions size = ImageDimensions(),
76                   FittingMode::Type fittingMode = FittingMode::DEFAULT,
77                   bool orientationCorrection = true,
78                   AtlasUploadObserver* atlasUploadObserver = NULL );
79   /**
80    * @brief Add a pixel buffer to the atlas
81    *
82    * @param [out] textureRect The texture area of the resource image in the atlas.
83    * @param [in] pixelData The pixel data.
84    * @return The texture set containing the image.
85    */
86   TextureSet Add( Vector4& textureRect,
87                   PixelData pixelData );
88
89   /**
90    * Remove the image at the given rectangle from the texture set.
91    *
92    * @param [in] textureSet The texture set containing the atlas image.
93    * @param [in] textureRect The texture area to be removed.
94    */
95   void Remove( TextureSet textureSet, const Vector4& textureRect );
96
97   /**
98    * @brief Set the broken image which is used to replace the image if loading fails.
99    *
100    * @param[in] brokenImageUrl The url of the broken image.
101    */
102   void SetBrokenImage( const std::string& brokenImageUrl );
103
104   /**
105    * @brief Get shader
106    */
107   Shader GetShader() const;
108
109 private:
110
111   /**
112    * @brief Create a new atlas.
113    *
114    * This method is called when the newly added image or pixel buffer cannot fit into the current atlas list.
115    */
116   void CreateNewAtlas();
117
118 protected:
119
120   /**
121    * Destructor
122    */
123   virtual ~ImageAtlasManager();
124
125   /**
126    * Undefined copy constructor.
127    */
128   ImageAtlasManager(const ImageAtlasManager&);
129
130   /**
131    * Undefined assignment operator.
132    */
133   ImageAtlasManager& operator=(const ImageAtlasManager& rhs);
134
135
136 private:
137
138   AtlasContainer    mAtlasList;
139   TextureSetContainer mTextureSetList;
140   std::string       mBrokenImageUrl;
141
142 };
143
144 } // name Internal
145
146 } // namespace Toolkit
147
148 } // namespace Dali
149
150 #endif // DALI_TOOLKIT_ATLAS_MANAGER_H