Merge "This patch is for refining dali application to support tizen c# application...
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / image-loader / image-atlas-impl.h
1 #ifndef __DALI_TOOLKIT_IMAGE_ATLAS_IMPL_H__
2 #define __DALI_TOOLKIT_IMAGE_ATLAS_IMPL_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 // EXTERNAL INCLUDES
21 #include <dali/public-api/common/intrusive-ptr.h>
22 #include <dali/public-api/object/base-object.h>
23 #include <dali/public-api/signals/connection-tracker.h>
24 #include <dali/devel-api/common/owner-container.h>
25 #include <dali/devel-api/images/atlas.h>
26
27 // INTERNAL INCLUDES
28 #include <dali-toolkit/devel-api/image-loader/image-atlas.h>
29 #include <dali-toolkit/devel-api/image-loader/async-image-loader.h>
30 #include <dali-toolkit/internal/image-loader/atlas-packer.h>
31
32 namespace Dali
33 {
34 class EventThreadCallback;
35
36 namespace Toolkit
37 {
38
39 namespace Internal
40 {
41
42 class ImageAtlas : public BaseObject, public ConnectionTracker
43 {
44 public:
45
46   typedef Toolkit::ImageAtlas::SizeType SizeType;
47
48   /**
49    * Constructor
50    * @param [in] width          The atlas width in pixels.
51    * @param [in] height         The atlas height in pixels.
52    * @param [in] pixelFormat    The pixel format.
53    */
54   ImageAtlas( SizeType width, SizeType height, Pixel::Format pixelFormat );
55
56   /**
57    * @copydoc Toolkit::ImageAtlas::New
58    */
59   static IntrusivePtr<ImageAtlas> New( SizeType width, SizeType height, Pixel::Format pixelFormat );
60
61   /**
62    * @copydoc Toolkit::ImageAtlas::GetAtlas
63    */
64   Texture GetAtlas();
65
66   /**
67    * @copydoc Toolkit::ImageAtlas::GetOccupancyRate
68    */
69   float GetOccupancyRate() const;
70
71   /**
72    * @copydoc Toolkit::ImageAtlas::SetBrokenImage
73    */
74   void SetBrokenImage( const std::string& brokenImageUrl );
75
76   /**
77    * @copydoc Toolkit::ImageAtlas::Upload( Vector4&, const std::string&, ImageDimensions,FittingMode::Type, bool )
78    */
79   bool Upload( Vector4& textureRect,
80                const std::string& url,
81                ImageDimensions size,
82                FittingMode::Type fittingMode,
83                bool orientationCorrection);
84
85   /**
86    * @copydoc Toolkit::ImageAtlas::Upload( Vector4&, PixelData )
87    */
88   bool Upload( Vector4& textureRect, PixelData pixelData );
89
90   /**
91    * @copydoc Toolkit::ImageAtlas::Remove
92    */
93   void Remove( const Vector4& textureRect );
94
95 protected:
96
97   /**
98    * Destructor
99    */
100   ~ImageAtlas();
101
102 private:
103
104   /**
105    * @copydoc PixelDataRequester::ProcessPixels
106    */
107   void UploadToAtlas( unsigned int id, PixelData pixelData );
108
109   /**
110    * Upload broken image
111    *
112    * @param[in] area The pixel area for uploading.
113    */
114   void UploadBrokenImage( const Rect<unsigned int>& area );
115
116   // Undefined
117   ImageAtlas( const ImageAtlas& imageAtlas);
118
119   // Undefined
120   ImageAtlas& operator=( const ImageAtlas& imageAtlas );
121
122 private:
123
124   struct IdRectPair
125   {
126     IdRectPair( unsigned short loadTaskId,
127                 unsigned int packPositionX,
128                 unsigned int packPositionY,
129                 unsigned int width,
130                 unsigned int height )
131     : loadTaskId( loadTaskId ),
132       packRect( packPositionX, packPositionY, width, height )
133     {}
134
135     unsigned short loadTaskId;
136     Rect<unsigned int> packRect;
137   };
138
139   OwnerContainer<IdRectPair*> mIdRectContainer;
140
141   Texture                   mAtlas;
142   AtlasPacker               mPacker;
143   Toolkit::AsyncImageLoader mAsyncLoader;
144   std::string               mBrokenImageUrl;
145   ImageDimensions           mBrokenImageSize;
146   float                     mWidth;
147   float                     mHeight;
148   Pixel::Format             mPixelFormat;
149
150 };
151
152 } // namespace Internal
153
154 inline const Internal::ImageAtlas& GetImplementation( const Toolkit::ImageAtlas& imageAtlas )
155 {
156   DALI_ASSERT_ALWAYS( imageAtlas && "ImageAtlas handle is empty" );
157
158   const BaseObject& handle = imageAtlas.GetBaseObject();
159
160   return static_cast<const Internal::ImageAtlas&>(handle);
161 }
162
163 inline Internal::ImageAtlas& GetImplementation( Toolkit::ImageAtlas& imageAtlas )
164 {
165   DALI_ASSERT_ALWAYS( imageAtlas && "ImageAtlas handle is empty" );
166
167   BaseObject& handle = imageAtlas.GetBaseObject();
168
169   return static_cast<Internal::ImageAtlas&>(handle);
170 }
171
172 } // namespace Toolkit
173
174 } // namespace Dali
175
176 #endif /* __DALI_TOOLKIT_IMAGE_ATLAS_IMPL_H__ */