[3.0] Remove/move experimental features
[platform/core/uifw/dali-core.git] / dali / internal / event / images / image-impl.h
1 #ifndef __DALI_INTERNAL_IMAGE_H__
2 #define __DALI_INTERNAL_IMAGE_H__
3
4 /*
5  * Copyright (c) 2014 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/images/image.h>
26 #include <dali/public-api/object/base-object.h>
27 #include <dali/internal/event/resources/resource-client.h>
28 #include <dali/internal/event/resources/resource-ticket-observer.h>
29
30 namespace Dali
31 {
32
33 namespace Internal
34 {
35
36 class Image;
37 class ImageFactory;
38 typedef IntrusivePtr<Image> ImagePtr;
39
40 /**
41  * Image represents an image resource that can be added to actors etc.
42  * When the Image object is created, resource loading will be attempted.
43  * Provided this is successful, the resource will exist until the Image is destroyed.
44  */
45 class Image : public BaseObject, public ResourceTicketObserver
46 {
47 public:
48
49   /**
50    * @copydoc Dali::Image::UploadedSignal()
51    */
52   Dali::Image::ImageSignalType& UploadedSignal() { return mUploaded; }
53
54   /**
55    * Connects a callback function with the object's signals.
56    * @param[in] object The object providing the signal.
57    * @param[in] tracker Used to disconnect the signal.
58    * @param[in] signalName The signal to connect to.
59    * @param[in] functor A newly allocated FunctorDelegate.
60    * @return True if the signal was connected.
61    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
62    */
63   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
64
65   /**
66    * returns the Id used for lookups
67    * @note if LoadPolicy::OnDemand is used and Image is off Stage, this will return 0.
68    * @return the unique ID of the image data resource. This is actually also the same as Dali Texture id.
69    */
70   ResourceId GetResourceId() const;
71
72   /**
73    * Get the width of the image.
74    * Only to be used after the image has finished loading.
75    * (Ticket's LoadingSucceeded callback was called)
76    * The returned value will reflect the true image dimensions once the asynchronous loading has finished.
77    * @pre image should be loaded
78    */
79   virtual unsigned int GetWidth() const;
80
81   /**
82    * Get the height of the image.
83    * Only to be used after the image has finished loading.
84    * (Ticket's LoadingSucceeded callback was called)
85    * The returned value will reflect the true image dimensions once the asynchronous loading has finished.
86    * @pre image should be loaded
87    */
88   virtual unsigned int GetHeight() const;
89
90   /**
91    * Return the natural size of the image.
92    * This is the size that the loaded image will take
93    */
94   virtual Vector2 GetNaturalSize() const;
95
96 public: // From ResourceTicketObserver
97
98   /**
99    * @copydoc Dali::Internal::ResourceTicketObserver::ResourceLoadingFailed()
100    */
101   virtual void ResourceLoadingFailed(const ResourceTicket& ticket);
102
103   /**
104    * @copydoc Dali::Internal::ResourceTicketObserver::ResourceLoadingSucceeded()
105    */
106   virtual void ResourceLoadingSucceeded(const ResourceTicket& ticket);
107
108   /**
109    * @copydoc Dali::Internal::ResourceTicketObserver::ResourceUploaded()
110    */
111   virtual void ResourceUploaded(const ResourceTicket& ticket);
112
113 public:
114
115   /**
116    * Indicates that the image is used.
117    */
118   virtual void Connect() {}
119
120   /**
121    * Indicates that the image is not used anymore.
122    */
123   virtual void Disconnect() {}
124
125 protected:
126
127   /**
128    * A reference counted object may only be deleted by calling Unreference()
129    */
130   virtual ~Image();
131
132   /**
133    * Constructor, with default parameters
134    */
135   Image();
136
137   /**
138    * Second stage initialization
139    */
140   void Initialize();
141
142 protected:
143
144   ResourceTicketPtr mTicket;              ///< smart pointer to the ticket object that gets completed when load finishes
145
146   mutable unsigned int mWidth;     ///< natural width of the image, needs to be mutable for lazy resolving and as the API for GetWidth is const
147   mutable unsigned int mHeight;    ///< natural height of the image, needs to be mutable for lazy resolving and as the API for GetHeight is const
148
149   unsigned int mConnectionCount; ///< number of on-stage objects using this image
150
151 private:
152
153   Dali::Image::ImageSignalType mUploaded;
154 };
155
156 } // namespace Internal
157
158 /**
159  * Helper methods for public API.
160  */
161 inline Internal::Image& GetImplementation(Dali::Image& image)
162 {
163   DALI_ASSERT_ALWAYS( image && "Image handle is empty" );
164
165   BaseObject& handle = image.GetBaseObject();
166
167   return static_cast<Internal::Image&>(handle);
168 }
169
170 inline const Internal::Image& GetImplementation(const Dali::Image& image)
171 {
172   DALI_ASSERT_ALWAYS( image && "Image handle is empty" );
173
174   const BaseObject& handle = image.GetBaseObject();
175
176   return static_cast<const Internal::Image&>(handle);
177 }
178
179 } // namespace Dali
180 #endif // __DALI_INTERNAL_IMAGE_H__