1 #ifndef __DALI_TOOLKIT_IMAGE_ATLAS_IMPL_H__
2 #define __DALI_TOOLKIT_IMAGE_ATLAS_IMPL_H__
5 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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/common/owner-container.h>
28 #include <dali-toolkit/devel-api/image-loader/image-atlas.h>
29 #include <dali-toolkit/internal/image-loader/atlas-packer.h>
30 #include <dali-toolkit/public-api/image-loader/async-image-loader.h>
34 class EventThreadCallback;
42 class ImageAtlas : public BaseObject, public ConnectionTracker
46 typedef Toolkit::ImageAtlas::SizeType SizeType;
49 * @copydoc ImageAtlas::PackToAtlas( const std::vector<PixelData>&, Dali::Vector<Vector4>& )
51 static Texture PackToAtlas( const std::vector<PixelData>& pixelData, Dali::Vector<Vector4>& textureRects );
55 * @param [in] width The atlas width in pixels.
56 * @param [in] height The atlas height in pixels.
57 * @param [in] pixelFormat The pixel format.
59 ImageAtlas( SizeType width, SizeType height, Pixel::Format pixelFormat );
62 * @copydoc Toolkit::ImageAtlas::New
64 static IntrusivePtr<ImageAtlas> New( SizeType width, SizeType height, Pixel::Format pixelFormat );
67 * @copydoc Toolkit::ImageAtlas::GetAtlas
72 * @copydoc Toolkit::ImageAtlas::GetOccupancyRate
74 float GetOccupancyRate() const;
77 * @copydoc Toolkit::ImageAtlas::SetBrokenImage
79 void SetBrokenImage( const std::string& brokenImageUrl );
82 * @copydoc Toolkit::ImageAtlas::Upload( Vector4&, const std::string&, ImageDimensions,FittingMode::Type, bool )
84 bool Upload( Vector4& textureRect,
85 const std::string& url,
87 FittingMode::Type fittingMode,
88 bool orientationCorrection,
89 AtlasUploadObserver* atlasUploadObserver );
92 * @copydoc Toolkit::ImageAtlas::Upload( Vector4&, PixelData )
94 bool Upload( Vector4& textureRect, PixelData pixelData );
97 * @copydoc Toolkit::ImageAtlas::Remove
99 void Remove( const Vector4& textureRect );
102 * Resets the destroying observer pointer so that we know not to call methods of this object any more.
104 void ObserverDestroyed( AtlasUploadObserver* observer );
116 * @copydoc PixelDataRequester::ProcessPixels
118 void UploadToAtlas( uint32_t id, PixelData pixelData );
121 * Upload broken image
123 * @param[in] area The pixel area for uploading.
125 void UploadBrokenImage( const Rect<unsigned int>& area );
128 ImageAtlas( const ImageAtlas& imageAtlas);
131 ImageAtlas& operator=( const ImageAtlas& imageAtlas );
136 * Each loading task( identified with an ID ) is associated with a rect region for packing the loaded pixel data into the atlas,
137 * and an AtlasUploadObserver whose UploadCompleted method should get executed once the sub texture is ready.
139 struct LoadingTaskInfo
141 LoadingTaskInfo( unsigned short loadTaskId,
142 unsigned int packPositionX,
143 unsigned int packPositionY,
146 AtlasUploadObserver* observer )
147 : loadTaskId( loadTaskId ),
148 packRect( packPositionX, packPositionY, width, height ),
152 unsigned short loadTaskId;
153 Rect<unsigned int> packRect;
154 AtlasUploadObserver* observer;
157 OwnerContainer<LoadingTaskInfo*> mLoadingTaskInfoContainer;
161 Toolkit::AsyncImageLoader mAsyncLoader;
162 std::string mBrokenImageUrl;
163 ImageDimensions mBrokenImageSize;
166 Pixel::Format mPixelFormat;
171 } // namespace Internal
173 inline const Internal::ImageAtlas& GetImplementation( const Toolkit::ImageAtlas& imageAtlas )
175 DALI_ASSERT_ALWAYS( imageAtlas && "ImageAtlas handle is empty" );
177 const BaseObject& handle = imageAtlas.GetBaseObject();
179 return static_cast<const Internal::ImageAtlas&>(handle);
182 inline Internal::ImageAtlas& GetImplementation( Toolkit::ImageAtlas& imageAtlas )
184 DALI_ASSERT_ALWAYS( imageAtlas && "ImageAtlas handle is empty" );
186 BaseObject& handle = imageAtlas.GetBaseObject();
188 return static_cast<Internal::ImageAtlas&>(handle);
191 } // namespace Toolkit
195 #endif /* __DALI_TOOLKIT_IMAGE_ATLAS_IMPL_H__ */