Automatic image atlasing
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / image-atlas / 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/devel-api/images/atlas.h>
24
25 // INTERNAL INCLUDES
26 #include <dali-toolkit/devel-api/image-atlas/image-atlas.h>
27 #include <dali-toolkit/internal/image-atlas/atlas-packer.h>
28 #include <dali-toolkit/internal/image-atlas/image-load-thread.h>
29
30 namespace Dali
31 {
32 class EventThreadCallback;
33
34 namespace Toolkit
35 {
36
37 namespace Internal
38 {
39
40 class ImageAtlas : public BaseObject
41 {
42 public:
43
44   typedef Toolkit::ImageAtlas::SizeType SizeType;
45
46   /**
47    * Constructor
48    * @param [in] width          The atlas width in pixels.
49    * @param [in] height         The atlas height in pixels.
50    * @param [in] pixelFormat    The pixel format.
51    */
52   ImageAtlas( SizeType width, SizeType height, Pixel::Format pixelFormat );
53
54   /**
55    * @copydoc Toolkit::ImageAtlas::New
56    */
57   static IntrusivePtr<ImageAtlas> New( SizeType width, SizeType height, Pixel::Format pixelFormat );
58
59   /**
60    * @copydoc Toolkit::ImageAtlas::GetAtlas
61    */
62   Image GetAtlas();
63
64   /**
65    * @copydoc Toolkit::ImageAtlas::SetBrokenImage
66    */
67   void SetBrokenImage( const std::string& brokenImageUrl );
68
69   /**
70    * @copydoc Toolkit::ImageAtlas::Upload
71    */
72   bool Upload( Vector4& textureRect,
73                const std::string& url,
74                ImageDimensions size,
75                FittingMode::Type fittingMode,
76                bool orientationCorrection);
77
78   /**
79    * @copydoc Toolkit::ImageAtlas::Remove
80    */
81   void Remove( const Vector4& textureRect );
82
83 protected:
84
85   /**
86    * Destructor
87    */
88   ~ImageAtlas();
89
90 private:
91
92   /**
93    * Upload the bitmap to atlas when the image is loaded in the worker thread.
94    */
95   void UploadToAtlas();
96
97   /**
98    * Upload broken image
99    *
100    * @param[in] area The pixel area for uploading.
101    */
102   void UploadBrokenImage( const Rect<SizeType>& area );
103
104   // Undefined
105   ImageAtlas( const ImageAtlas& imageAtlas);
106
107   // Undefined
108   ImageAtlas& operator=( const ImageAtlas& imageAtlas );
109
110 private:
111
112   Atlas                mAtlas;
113   AtlasPacker          mPacker;
114
115   LoadQueue            mLoadQueue;
116   CompleteQueue        mCompleteQueue;
117   ImageLoadThread      mLoadingThread;
118
119   std::string          mBrokenImageUrl;
120   ImageDimensions      mBrokenImageSize;
121   float                mWidth;
122   float                mHeight;
123   Pixel::Format        mPixelFormat;
124   bool                 mLoadingThreadStarted;
125
126 };
127
128 } // namespace Internal
129
130 inline const Internal::ImageAtlas& GetImplementation( const Toolkit::ImageAtlas& imageAtlas )
131 {
132   DALI_ASSERT_ALWAYS( imageAtlas && "ImageAtlas handle is empty" );
133
134   const BaseObject& handle = imageAtlas.GetBaseObject();
135
136   return static_cast<const Internal::ImageAtlas&>(handle);
137 }
138
139 inline Internal::ImageAtlas& GetImplementation( Toolkit::ImageAtlas& imageAtlas )
140 {
141   DALI_ASSERT_ALWAYS( imageAtlas && "ImageAtlas handle is empty" );
142
143   BaseObject& handle = imageAtlas.GetBaseObject();
144
145   return static_cast<Internal::ImageAtlas&>(handle);
146 }
147
148 } // namespace Toolkit
149
150 } // namespace Dali
151
152 #endif /* __DALI_TOOLKIT_IMAGE_ATLAS_IMPL_H__ */