Automatically dis/connect registered visuals to stage
[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( Vector4&, const std::string&, ImageDimensions,FittingMode::Type, bool )
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::Upload( Vector4&, PixelData )
80    */
81   bool Upload( Vector4& textureRect, PixelData pixelData );
82
83   /**
84    * @copydoc Toolkit::ImageAtlas::Remove
85    */
86   void Remove( const Vector4& textureRect );
87
88 protected:
89
90   /**
91    * Destructor
92    */
93   ~ImageAtlas();
94
95 private:
96
97   /**
98    * Upload the bitmap to atlas when the image is loaded in the worker thread.
99    */
100   void UploadToAtlas();
101
102   /**
103    * Upload broken image
104    *
105    * @param[in] area The pixel area for uploading.
106    */
107   void UploadBrokenImage( const Rect<SizeType>& area );
108
109   // Undefined
110   ImageAtlas( const ImageAtlas& imageAtlas);
111
112   // Undefined
113   ImageAtlas& operator=( const ImageAtlas& imageAtlas );
114
115 private:
116
117   Atlas                mAtlas;
118   AtlasPacker          mPacker;
119
120   LoadQueue            mLoadQueue;
121   CompleteQueue        mCompleteQueue;
122   ImageLoadThread      mLoadingThread;
123
124   std::string          mBrokenImageUrl;
125   ImageDimensions      mBrokenImageSize;
126   float                mWidth;
127   float                mHeight;
128   Pixel::Format        mPixelFormat;
129   bool                 mLoadingThreadStarted;
130
131 };
132
133 } // namespace Internal
134
135 inline const Internal::ImageAtlas& GetImplementation( const Toolkit::ImageAtlas& imageAtlas )
136 {
137   DALI_ASSERT_ALWAYS( imageAtlas && "ImageAtlas handle is empty" );
138
139   const BaseObject& handle = imageAtlas.GetBaseObject();
140
141   return static_cast<const Internal::ImageAtlas&>(handle);
142 }
143
144 inline Internal::ImageAtlas& GetImplementation( Toolkit::ImageAtlas& imageAtlas )
145 {
146   DALI_ASSERT_ALWAYS( imageAtlas && "ImageAtlas handle is empty" );
147
148   BaseObject& handle = imageAtlas.GetBaseObject();
149
150   return static_cast<Internal::ImageAtlas&>(handle);
151 }
152
153 } // namespace Toolkit
154
155 } // namespace Dali
156
157 #endif /* __DALI_TOOLKIT_IMAGE_ATLAS_IMPL_H__ */