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/images/atlas.h>
26 #include <dali/devel-api/common/owner-container.h>
29 #include <dali-toolkit/devel-api/image-loader/image-atlas.h>
30 #include <dali-toolkit/internal/image-loader/atlas-packer.h>
31 #include <dali-toolkit/public-api/image-loader/async-image-loader.h>
35 class EventThreadCallback;
43 class ImageAtlas : public BaseObject, public ConnectionTracker
47 typedef Toolkit::ImageAtlas::SizeType SizeType;
50 * @copydoc ImageAtlas::PackToAtlas( const std::vector<PixelData>&, Dali::Vector<Vector4>& )
52 static Texture PackToAtlas( const std::vector<PixelData>& pixelData, Dali::Vector<Vector4>& textureRects );
56 * @param [in] width The atlas width in pixels.
57 * @param [in] height The atlas height in pixels.
58 * @param [in] pixelFormat The pixel format.
60 ImageAtlas( SizeType width, SizeType height, Pixel::Format pixelFormat );
63 * @copydoc Toolkit::ImageAtlas::New
65 static IntrusivePtr<ImageAtlas> New( SizeType width, SizeType height, Pixel::Format pixelFormat );
68 * @copydoc Toolkit::ImageAtlas::GetAtlas
73 * @copydoc Toolkit::ImageAtlas::GetOccupancyRate
75 float GetOccupancyRate() const;
78 * @copydoc Toolkit::ImageAtlas::SetBrokenImage
80 void SetBrokenImage( const std::string& brokenImageUrl );
83 * @copydoc Toolkit::ImageAtlas::Upload( Vector4&, const std::string&, ImageDimensions,FittingMode::Type, bool )
85 bool Upload( Vector4& textureRect,
86 const std::string& url,
88 FittingMode::Type fittingMode,
89 bool orientationCorrection,
90 AtlasUploadObserver* atlasUploadObserver );
93 * @copydoc Toolkit::ImageAtlas::Upload( Vector4&, PixelData )
95 bool Upload( Vector4& textureRect, PixelData pixelData );
98 * @copydoc Toolkit::ImageAtlas::Remove
100 void Remove( const Vector4& textureRect );
103 * Resets the destroying observer pointer so that we know not to call methods of this object any more.
105 void ObserverDestroyed( AtlasUploadObserver* observer );
117 * @copydoc PixelDataRequester::ProcessPixels
119 void UploadToAtlas( uint32_t id, PixelData pixelData );
122 * Upload broken image
124 * @param[in] area The pixel area for uploading.
126 void UploadBrokenImage( const Rect<unsigned int>& area );
129 ImageAtlas( const ImageAtlas& imageAtlas);
132 ImageAtlas& operator=( const ImageAtlas& imageAtlas );
137 * Each loading task( identified with an ID ) is associated with a rect region for packing the loaded pixel data into the atlas,
138 * and an AtlasUploadObserver whose UploadCompleted method should get executed once the sub texture is ready.
140 struct LoadingTaskInfo
142 LoadingTaskInfo( unsigned short loadTaskId,
143 unsigned int packPositionX,
144 unsigned int packPositionY,
147 AtlasUploadObserver* observer )
148 : loadTaskId( loadTaskId ),
149 packRect( packPositionX, packPositionY, width, height ),
153 unsigned short loadTaskId;
154 Rect<unsigned int> packRect;
155 AtlasUploadObserver* observer;
158 OwnerContainer<LoadingTaskInfo*> mLoadingTaskInfoContainer;
162 Toolkit::AsyncImageLoader mAsyncLoader;
163 std::string mBrokenImageUrl;
164 ImageDimensions mBrokenImageSize;
167 Pixel::Format mPixelFormat;
172 } // namespace Internal
174 inline const Internal::ImageAtlas& GetImplementation( const Toolkit::ImageAtlas& imageAtlas )
176 DALI_ASSERT_ALWAYS( imageAtlas && "ImageAtlas handle is empty" );
178 const BaseObject& handle = imageAtlas.GetBaseObject();
180 return static_cast<const Internal::ImageAtlas&>(handle);
183 inline Internal::ImageAtlas& GetImplementation( Toolkit::ImageAtlas& imageAtlas )
185 DALI_ASSERT_ALWAYS( imageAtlas && "ImageAtlas handle is empty" );
187 BaseObject& handle = imageAtlas.GetBaseObject();
189 return static_cast<Internal::ImageAtlas&>(handle);
192 } // namespace Toolkit
196 #endif /* __DALI_TOOLKIT_IMAGE_ATLAS_IMPL_H__ */