[3.0] Remove/move experimental features
[platform/core/uifw/dali-core.git] / dali / internal / event / images / resource-image-impl.h
1 #ifndef __DALI_INTERNAL_RESOURCE_IMAGE_H__
2 #define __DALI_INTERNAL_RESOURCE_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/images/resource-image.h>
26 #include <dali/internal/event/images/image-impl.h>
27 #include <dali/internal/event/images/image-factory-cache.h>
28 #include <dali/integration-api/debug.h> // For DALI_LOG_OBJECT_STRING_DECLARATION
29
30 namespace Dali
31 {
32
33 namespace Internal
34 {
35
36 class ResourceImage;
37 typedef IntrusivePtr<ResourceImage> ResourceImagePtr;
38
39 /**
40  * ResourceImage is an image loaded using a URL, it is an image resource that can be added to actors etc.
41  */
42 class ResourceImage : public Image
43 {
44 public:
45
46   /**
47    * Creates a pointer to an uninitialized Image object.
48    * @return a pointer to a newly created object.
49    */
50   static ResourceImagePtr New();
51
52   /**
53    * Creates object and loads image from filesystem
54    * the maximum size of the image is limited by GL_MAX_TEXTURE_SIZE
55    * @param [in] url The URL of the image file.
56    * @param [in] attributes requested parameters for loading (size, scaling etc.)
57    *                        if width or height is specified as 0, the natural size will be used.
58    * @return a pointer to a newly created object.
59    */
60   static ResourceImagePtr New( const std::string& url,
61                           const ImageAttributes& attributes );
62
63   /**
64    * @copydoc Dali::ResourceImage::GetLoadingState()
65    */
66   Dali::LoadingState GetLoadingState() const { return mTicket ? mTicket->GetLoadingState() : ResourceLoading; }
67
68   /**
69    * @copydoc Dali::ResourceImage::LoadingFinishedSignal()
70    */
71   Dali::ResourceImage::ResourceImageSignal& LoadingFinishedSignal() { return mLoadingFinished; }
72
73   /**
74    * Connects a callback function with the object's signals.
75    * @param[in] object The object providing the signal.
76    * @param[in] tracker Used to disconnect the signal.
77    * @param[in] signalName The signal to connect to.
78    * @param[in] functor A newly allocated FunctorDelegate.
79    * @return True if the signal was connected.
80    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
81    */
82   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
83
84   /**
85    * Get the attributes of the image.
86    * Only to be used after the image has finished loading.
87    * (Ticket's LoadingSucceeded callback was called)
88    * Reflects the last cached values after a LoadComplete.
89    * If requested width or height was 0, they are replaced by concrete dimensions.
90    * @return a copy of the attributes
91    */
92   const ImageAttributes& GetAttributes() const;
93
94   /**
95    * @copydoc Dali::ResourceImage::GetUrl()
96    */
97   const std::string& GetUrl() const;
98
99   /**
100    * @copydoc Dali::ResourceImage::Reload()
101    */
102   void Reload();
103
104   /**
105    * @copydoc Dali::Image::GetWidth()
106    */
107   virtual unsigned int GetWidth() const;
108
109   /**
110    * @copydoc Dali::Image::GetWidth()
111    */
112   virtual unsigned int GetHeight() const;
113
114   /**
115    * @copydoc Dali::Internal::Image::GetNaturalSize()
116    */
117   virtual Vector2 GetNaturalSize() const;
118
119   /**
120    * Indicates that the image is used.
121    */
122   virtual void Connect();
123
124   /**
125    * Indicates that the image is not used anymore.
126    */
127   virtual void Disconnect();
128
129 public: // From ResourceTicketObserver
130
131   /**
132    * @copydoc Dali::Internal::ResourceTicketObserver::ResourceLoadingFailed()
133    */
134   virtual void ResourceLoadingFailed(const ResourceTicket& ticket);
135
136   /**
137    * @copydoc Dali::Internal::ResourceTicketObserver::ResourceLoadingSucceeded()
138    */
139   virtual void ResourceLoadingSucceeded(const ResourceTicket& ticket);
140
141 protected:
142
143   /**
144    * A reference counted object may only be deleted by calling Unreference()
145    */
146   virtual ~ResourceImage();
147
148   /**
149    * Constructor, with default parameters
150    */
151   ResourceImage();
152
153 private:
154
155   /**
156    * Helper method to set new resource ticket. Stops observing current ticket if any, and starts observing
157    * the new one or just resets the intrusive pointer.
158    * @param[in] ticket pointer to new resource Ticket or NULL.
159    */
160   void SetTicket( ResourceTicket* ticket );
161
162 private:
163
164   ImageFactory& mImageFactory;
165
166   ImageFactoryCache::RequestPtr mRequest; ///< contains the initially requested attributes for image. Request is reissued when memory was released.
167
168   Dali::ResourceImage::ResourceImageSignal mLoadingFinished;
169
170   // Changes scope, should be at end of class
171   DALI_LOG_OBJECT_STRING_DECLARATION;
172 };
173
174 } // namespace Internal
175
176 /**
177  * Helper methods for public API.
178  */
179 inline Internal::ResourceImage& GetImplementation(Dali::ResourceImage& image)
180 {
181   DALI_ASSERT_ALWAYS( image && "Image handle is empty" );
182
183   BaseObject& handle = image.GetBaseObject();
184
185   return static_cast<Internal::ResourceImage&>(handle);
186 }
187
188 inline const Internal::ResourceImage& GetImplementation(const Dali::ResourceImage& image)
189 {
190   DALI_ASSERT_ALWAYS( image && "Image handle is empty" );
191
192   const BaseObject& handle = image.GetBaseObject();
193
194   return static_cast<const Internal::ResourceImage&>(handle);
195 }
196
197 } // namespace Dali
198 #endif // __DALI_INTERNAL_RESOURCE_IMAGE_H__