Move more public-api headers to devel-api. PART 2
[platform/core/uifw/dali-core.git] / dali / devel-api / images / atlas.h
1 #ifndef __DALI_ATLAS_H__
2 #define __DALI_ATLAS_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
21 // EXTERNAL INCLUDES
22 #include <stdint.h>
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/common/dali-common.h>
26 #include <dali/public-api/images/image.h>
27 #include <dali/public-api/images/buffer-image.h>
28
29 namespace Dali
30 {
31
32 namespace Internal DALI_INTERNAL
33 {
34 class Atlas;
35 }
36
37 /**
38  * @brief An Atlas is a large image containing multiple smaller images.
39  *
40  * Buffer image and resource image( by providing the url ) are supported for uploading.
41  * Images must be uploaded at a specified position, to populate the Atlas.
42  * The client is responsible for generating the appropriate geometry (UV coordinates) needed to draw images within the Atlas.
43  *
44  * For context recovery after loss:
45  * By default, the atlas will re-upload the resource images automatically,
46  * while the buffer images are left to the client to upload again by connecting to the Stage::ContextRegainedSignal().
47  * If resource and buffer images are mixed and they overlap inside the atlas, the recovered contents may be incorrect.
48  * In these case, switch off the context recovery by calling SetContextRecovery( false ),
49  * and upload both buffer images and resource image to the atlas in order to restore the atlas.
50  */
51 class DALI_IMPORT_API Atlas : public Image
52 {
53 public:
54
55   typedef uint32_t SizeType;
56
57 public:
58
59   /**
60    * @brief Create a new Atlas.
61    *
62    * @pre width & height are greater than zero.
63    * The maximum size of the atlas is limited by GL_MAX_TEXTURE_SIZE.
64    * @param [in] width          The atlas width in pixels.
65    * @param [in] height         The atlas height in pixels.
66    * @param [in] pixelFormat    The pixel format (rgba 32 bit by default).
67    * @param [in] recoverContext Whether re-uploading the resource images automatically when regaining the context( true by default )
68    * @return A handle to a new Atlas.
69    */
70   static Atlas New( SizeType width,
71                     SizeType height,
72                     Pixel::Format pixelFormat = Pixel::RGBA8888,
73                     bool recoverContext = true );
74
75   /**
76    * @brief Create an empty handle.
77    *
78    * Calling member functions of an empty handle is not allowed.
79    */
80   Atlas();
81
82   /**
83    * @brief Clear the Atlas with the given color
84    *
85    * @note The Atlas does not clear itself automatically during construction.
86    * Application should call this clear function to avoid getting garbage pixels in the atlas.
87    * By calling Clear, all the current uploaded image information will be lost.
88    * @param [in] color The color used to clear the Atlas.
89    */
90   void Clear( const Vector4& color  );
91
92   /**
93    * @brief Upload a buffer image to the atlas.
94    *
95    * @pre The pixel format of this buffer image must match the Atlas format.
96    * @param [in] bufferImage The buffer image to upload.
97    * @param [in] xOffset Specifies an offset in the x direction within the atlas.
98    * @param [in] yOffset Specifies an offset in the y direction within the atlas.
99    * @return True if the image has compatible pixel format and fits within the atlas at the specified offset.
100    */
101   bool Upload( BufferImage bufferImage,
102                SizeType xOffset,
103                SizeType yOffset );
104
105   /**
106    * @brief Upload a resource image to atlas
107    *
108    * @param [in] url The URL of the resource image file to use
109    * @param [in] xOffset Specifies an offset in the x direction within the atlas.
110    * @param [in] yOffset Specifies an offset in the y direction within the atlas.
111    * @return True if the image has compatible pixel format and fits within the atlas at the specified offset.
112    */
113   bool Upload( const std::string& url,
114                SizeType xOffset,
115                SizeType yOffset );
116   /**
117    * @brief Downcast an Object handle to Atlas.
118    *
119    * If handle points to a Atlas the downcast produces valid
120    * handle. If not the returned handle is left uninitialized.
121    *
122    * @param[in] handle to An object
123    * @return handle to a Atlas or an empty handle
124    */
125   static Atlas DownCast( BaseHandle handle );
126
127   /**
128    * @brief Destructor
129    *
130    * This is non-virtual since derived Handle types must not contain data or virtual methods.
131    */
132   ~Atlas();
133
134   /**
135    * @brief This copy constructor is required for (smart) pointer semantics.
136    *
137    * @param [in] handle A reference to the copied handle
138    */
139   Atlas( const Atlas& handle );
140
141   /**
142    * @brief This assignment operator is required for (smart) pointer semantics.
143    *
144    * @param [in] rhs  A reference to the copied handle
145    * @return A reference to this
146    */
147   Atlas& operator=( const Atlas& rhs);
148
149 public: // Not intended for application developers
150
151   explicit DALI_INTERNAL Atlas( Internal::Atlas* );
152 };
153
154 } // namespace Dali
155
156 #endif // __DALI_ATLAS_H__