Update copyright year to 2015 for public api: core
[platform/core/uifw/dali-core.git] / dali / public-api / images / image.h
1 #ifndef __DALI_IMAGE_H__
2 #define __DALI_IMAGE_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 <string>
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/object/base-handle.h>
26 #include <dali/public-api/signals/dali-signal.h>
27
28 namespace Dali
29 {
30
31 namespace Internal DALI_INTERNAL
32 {
33 class Image;
34 }
35
36 /**
37  * @brief An Image object represents an image resource that can be added to ImageActors.
38  *
39  * Image objects can be shared between ImageActors. This is practical if you have a visual element on screen
40  * which is repeatedly used. An example would be a button background image.
41  * The image resource is discarded when all ImageActors using the Image object are discarded or in case they
42  * were created with ReleasePolicy::Unused, taken off stage.
43  * Note: if a resource was shared between Image objects it exists until its last reference is gone.
44  *
45  * Image objects are responsible for the underlying resource's lifetime.
46  *
47  * <i>ReleasePolicies</i>
48  * - Unused: release resource once ImageActor using it is taken off stage.
49  * - Never: keep resource alive until Image object is thrown away.
50  *
51  * <i>Resolution of conflicting policies</i>
52  * If the same image is created more than once with conflicting policies, ReleasePolicy "Never" overrides "Unused".
53  *
54  * Signals
55  * | %Signal Name           | Method                       |
56  * |------------------------|------------------------------|
57  * | uploaded               | @ref UploadedSignal()        |
58  */
59 class DALI_IMPORT_API Image : public BaseHandle
60 {
61 public:
62   /**
63    * @brief Resource management options.
64    */
65
66   /**
67    * @brief ReleasePolicy controls the way images are deleted from memory.
68    */
69   enum ReleasePolicy
70   {
71     UNUSED, ///< release resource once image is not in use anymore (eg. all actors using it become offstage). Reload when resource is required again.
72     NEVER   ///< keep image data for the lifetime of the object. (default)
73   };
74
75   /**
76    * @brief Type of signal for Image Uploaded.
77    */
78   typedef Signal< void (Image) > ImageSignalType;
79
80 public:
81
82   /**
83    * @brief Constructor which creates an empty Image handle.
84    *
85    * Use Image::New(...) to create an initialised handle.
86    */
87   Image();
88
89   /**
90    * @brief Destructor
91    *
92    * This is non-virtual since derived Handle types must not contain data or virtual methods.
93    */
94   ~Image();
95
96   /**
97    * @brief This copy constructor is required for (smart) pointer semantics.
98    *
99    * @param [in] handle A reference to the copied handle
100    */
101   Image(const Image& handle);
102
103   /**
104    * @brief This assignment operator is required for (smart) pointer semantics.
105    *
106    * @param [in] rhs  A reference to the copied handle
107    * @return A reference to this
108    */
109   Image& operator=(const Image& rhs);
110
111   /**
112    * @brief Downcast an Object handle to Image handle.
113    *
114    * If handle points to a Image object the
115    * downcast produces valid handle. If not the returned handle is left uninitialized.
116    * @param[in] handle to An object
117    * @return handle to a Image object or an uninitialized handle
118    */
119   static Image DownCast( BaseHandle handle );
120
121   /**
122    * @brief Return resource release policy.
123    *
124    * @return resource release policy
125    */
126   ReleasePolicy GetReleasePolicy() const;
127
128   /**
129    * @brief Returns the width of the image.
130    *
131    * Returns either the requested width or the actual loaded width if no specific size was requested.
132    *
133    * @return width of the image in pixels.
134    */
135   unsigned int GetWidth() const;
136
137   /**
138    * @brief Returns the height of the image.
139    *
140    * Returns either the requested height or the actual loaded height if no specific size was requested.
141    *
142    * @return height of the image in pixels.
143    */
144   unsigned int GetHeight() const;
145
146 public: // Signals
147
148   /**
149    * @brief This signal is emitted when the image data gets uploaded to GL.
150    *
151    * It Will be sent after an actor using the image is added to
152    * the stage, when such a staged image is reloaded, or when a staged
153    * BufferImage calls Update().
154    * @return A signal object to Connect() with.
155    */
156   ImageSignalType& UploadedSignal();
157
158 public: // Not intended for application developers
159
160   explicit DALI_INTERNAL Image(Internal::Image*);
161 };
162
163 } // namespace Dali
164
165 #endif // __DALI_IMAGE_H__