1 #ifndef DALI_TOOLKIT_IMAGE_ATLAS_IMPL_H
2 #define DALI_TOOLKIT_IMAGE_ATLAS_IMPL_H
5 * Copyright (c) 2021 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/devel-api/common/owner-container.h>
22 #include <dali/public-api/common/intrusive-ptr.h>
23 #include <dali/public-api/object/base-object.h>
24 #include <dali/public-api/signals/connection-tracker.h>
27 #include <dali-toolkit/devel-api/image-loader/image-atlas.h>
28 #include <dali-toolkit/internal/image-loader/atlas-packer.h>
29 #include <dali-toolkit/public-api/image-loader/async-image-loader.h>
33 class EventThreadCallback;
39 class ImageAtlas : public BaseObject, public ConnectionTracker
42 typedef Toolkit::ImageAtlas::SizeType SizeType;
45 * @copydoc ImageAtlas::PackToAtlas( const std::vector<PixelData>&, Dali::Vector<Vector4>& )
47 static Texture PackToAtlas(const std::vector<PixelData>& pixelData, Dali::Vector<Vector4>& textureRects);
51 * @param [in] width The atlas width in pixels.
52 * @param [in] height The atlas height in pixels.
53 * @param [in] pixelFormat The pixel format.
55 ImageAtlas(SizeType width, SizeType height, Pixel::Format pixelFormat);
58 * @copydoc Toolkit::ImageAtlas::New
60 static IntrusivePtr<ImageAtlas> New(SizeType width, SizeType height, Pixel::Format pixelFormat);
63 * @copydoc Toolkit::ImageAtlas::GetAtlas
68 * @copydoc Toolkit::ImageAtlas::GetOccupancyRate
70 float GetOccupancyRate() const;
73 * @copydoc Toolkit::ImageAtlas::SetBrokenImage
75 void SetBrokenImage(const std::string& brokenImageUrl);
78 * @copydoc Toolkit::ImageAtlas::Upload( Vector4&, const std::string&, ImageDimensions,FittingMode::Type, bool )
80 bool Upload(Vector4& textureRect,
81 const std::string& url,
83 FittingMode::Type fittingMode,
84 bool orientationCorrection,
85 AtlasUploadObserver* atlasUploadObserver);
88 * @copydoc Toolkit::ImageAtlas::Upload( Vector4&, PixelData )
90 bool Upload(Vector4& textureRect, PixelData pixelData);
93 * @copydoc Toolkit::ImageAtlas::Remove
95 void Remove(const Vector4& textureRect);
98 * Resets the destroying observer pointer so that we know not to call methods of this object any more.
100 void ObserverDestroyed(AtlasUploadObserver* observer);
110 * @copydoc PixelDataRequester::ProcessPixels
112 void UploadToAtlas(uint32_t id, PixelData pixelData);
115 * Upload broken image
117 * @param[in] area The pixel area for uploading.
119 void UploadBrokenImage(const Rect<unsigned int>& area);
122 ImageAtlas(const ImageAtlas& imageAtlas);
125 ImageAtlas& operator=(const ImageAtlas& imageAtlas);
129 * Each loading task( identified with an ID ) is associated with a rect region for packing the loaded pixel data into the atlas,
130 * and an AtlasUploadObserver whose UploadCompleted method should get executed once the sub texture is ready.
132 struct LoadingTaskInfo
134 LoadingTaskInfo(unsigned short loadTaskId,
135 unsigned int packPositionX,
136 unsigned int packPositionY,
139 AtlasUploadObserver* observer)
140 : loadTaskId(loadTaskId),
141 packRect(packPositionX, packPositionY, width, height),
146 unsigned short loadTaskId;
147 Rect<unsigned int> packRect;
148 AtlasUploadObserver* observer;
151 OwnerContainer<LoadingTaskInfo*> mLoadingTaskInfoContainer;
155 Toolkit::AsyncImageLoader mAsyncLoader;
156 std::string mBrokenImageUrl;
157 ImageDimensions mBrokenImageSize;
160 Pixel::Format mPixelFormat;
163 } // namespace Internal
165 inline const Internal::ImageAtlas& GetImplementation(const Toolkit::ImageAtlas& imageAtlas)
167 DALI_ASSERT_ALWAYS(imageAtlas && "ImageAtlas handle is empty");
169 const BaseObject& handle = imageAtlas.GetBaseObject();
171 return static_cast<const Internal::ImageAtlas&>(handle);
174 inline Internal::ImageAtlas& GetImplementation(Toolkit::ImageAtlas& imageAtlas)
176 DALI_ASSERT_ALWAYS(imageAtlas && "ImageAtlas handle is empty");
178 BaseObject& handle = imageAtlas.GetBaseObject();
180 return static_cast<Internal::ImageAtlas&>(handle);
183 } // namespace Toolkit
187 #endif // DALI_TOOLKIT_IMAGE_ATLAS_IMPL_H