[Tizen] Revert "Remove TypeRegistration from deprecated Image classes"
[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/rendering/texture-impl.h>
28
29 namespace Dali
30 {
31
32 namespace Internal
33 {
34
35 class Image;
36 class ImageFactory;
37 typedef IntrusivePtr<Image> ImagePtr;
38
39 /**
40  * Image represents an image resource that can be added to actors etc.
41  * When the Image object is created, resource loading will be attempted.
42  * Provided this is successful, the resource will exist until the Image is destroyed.
43  */
44 class Image : public BaseObject
45 {
46 public:
47
48   /**
49    * @copydoc Dali::Image::UploadedSignal()
50    */
51   Dali::Image::ImageSignalType& UploadedSignal() { return mUploaded; }
52
53   /**
54    * Connects a callback function with the object's signals.
55    * @param[in] object The object providing the signal.
56    * @param[in] tracker Used to disconnect the signal.
57    * @param[in] signalName The signal to connect to.
58    * @param[in] functor A newly allocated FunctorDelegate.
59    * @return True if the signal was connected.
60    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
61    */
62   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
63
64   /**
65    * Get the width of the image.
66    * Only to be used after the image has finished loading.
67    * (Ticket's LoadingSucceeded callback was called)
68    * The returned value will reflect the true image dimensions once the asynchronous loading has finished.
69    * @pre image should be loaded
70    */
71   virtual unsigned int GetWidth() const;
72
73   /**
74    * Get the height of the image.
75    * Only to be used after the image has finished loading.
76    * (Ticket's LoadingSucceeded callback was called)
77    * The returned value will reflect the true image dimensions once the asynchronous loading has finished.
78    * @pre image should be loaded
79    */
80   virtual unsigned int GetHeight() const;
81
82   /**
83    * Return the natural size of the image.
84    * This is the size that the loaded image will take
85    */
86   virtual Vector2 GetNaturalSize() const;
87
88   /**
89    * Returns a pointer to the internal texture used by the image
90    */
91   Texture* GetTexture() const
92   {
93     return mTexture.Get();
94   }
95
96 public:
97
98   /**
99    * Indicates that the image is used.
100    */
101   virtual void Connect() {}
102
103   /**
104    * Indicates that the image is not used anymore.
105    */
106   virtual void Disconnect() {}
107
108 protected:
109
110   /**
111    * A reference counted object may only be deleted by calling Unreference()
112    */
113   virtual ~Image();
114
115   /**
116    * Constructor, with default parameters
117    */
118   Image();
119
120   /**
121    * Second stage initialization
122    */
123   void Initialize();
124
125 protected:
126
127   TexturePtr mTexture;  ///< smart pointer to the texture used by the image
128
129   unsigned int mWidth;     ///< natural width of the image
130   unsigned int mHeight;    ///< natural height of the image
131
132   unsigned int mConnectionCount; ///< number of on-stage objects using this image
133
134 private:
135
136   Dali::Image::ImageSignalType mUploaded;
137 };
138
139 } // namespace Internal
140
141 /**
142  * Helper methods for public API.
143  */
144 inline Internal::Image& GetImplementation(Dali::Image& image)
145 {
146   DALI_ASSERT_ALWAYS( image && "Image handle is empty" );
147
148   BaseObject& handle = image.GetBaseObject();
149
150   return static_cast<Internal::Image&>(handle);
151 }
152
153 inline const Internal::Image& GetImplementation(const Dali::Image& image)
154 {
155   DALI_ASSERT_ALWAYS( image && "Image handle is empty" );
156
157   const BaseObject& handle = image.GetBaseObject();
158
159   return static_cast<const Internal::Image&>(handle);
160 }
161
162 } // namespace Dali
163 #endif // __DALI_INTERNAL_IMAGE_H__