SVG support for ImageView ( CPU rendering version )
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / renderers / 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) 2015 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/devel-api/rendering/material.h>
25
26 // INTERNAL INCLUDES
27 #include <dali-toolkit/devel-api/image-atlas/image-atlas.h>
28
29 namespace Dali
30 {
31
32 namespace Toolkit
33 {
34
35 namespace Internal
36 {
37
38 /**
39  * The manager for automatic image atlasing. Owned by RendererFactory
40  */
41 class ImageAtlasManager : public RefObject
42 {
43 public:
44   typedef std::vector< Toolkit::ImageAtlas > AtlasContainer;
45   typedef std::vector< Material > MaterialContainer;
46
47 public:
48
49   /**
50    * Construtor
51    *
52    * @param[in] shader The shader for material.
53    * @param[in] textureUniformName The texture uniform name for the atlas image.
54    */
55   ImageAtlasManager( Shader shader, const std::string& textureUniformName );
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    * @return The material containing the image.
71    */
72   Material Add( Vector4& textureRect,
73                 const std::string& url,
74                 ImageDimensions size = ImageDimensions(),
75                 FittingMode::Type fittingMode = FittingMode::DEFAULT,
76                 bool orientationCorrection = true );
77
78   /**
79    * @brief Add a pixel buffer to the atlas
80    *
81    * @param [out] textureRect The texture area of the resource image in the atlas.
82    * @param [in] pixelData The pixel data.
83    * @return The material containing the image.
84    */
85   Material Add( Vector4& textureRect,
86                 PixelDataPtr pixelData );
87
88   /**
89    * Remove the image at the given rectangle from the material.
90    *
91    * @param [in] material The material containing the atlas image.
92    * @param [in] textureRect The texture area to be removed.
93    */
94   void Remove( Material material, const Vector4& textureRect );
95
96   /**
97    * @brief Set the broken image which is used to replace the image if loading fails.
98    *
99    * @param[in] brokenImageUrl The url of the broken image.
100    */
101   void SetBrokenImage( const std::string& brokenImageUrl );
102
103 private:
104
105   /**
106    * @brief Create a new atlas.
107    *
108    * This method is called when the newly added image or pixel buffer cannot fit into the current atlas list.
109    */
110   void CreateNewAtlas();
111
112 protected:
113
114   /**
115    * Destructor
116    */
117   virtual ~ImageAtlasManager();
118
119   /**
120    * Undefined copy constructor.
121    */
122   ImageAtlasManager(const ImageAtlasManager&);
123
124   /**
125    * Undefined assignment operator.
126    */
127   ImageAtlasManager& operator=(const ImageAtlasManager& rhs);
128
129
130 private:
131
132   AtlasContainer    mAtlasList;
133   MaterialContainer mMaterialList;
134   Shader            mShader;
135   std::string       mTextureUniformName;
136   std::string       mBrokenImageUrl;
137
138 };
139
140 } // name Internal
141
142 } // namespace Toolkit
143
144 } // namespace Dali
145
146 #endif // __DALI_TOOLKIT_ATLAS_MANAGER_H__