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>
30 #include <dali-toolkit/internal/visuals/visual-url.h>
34 class EventThreadCallback;
40 class ImageAtlas : public BaseObject, public ConnectionTracker
43 typedef Toolkit::ImageAtlas::SizeType SizeType;
46 * @copydoc ImageAtlas::PackToAtlas( const std::vector<PixelData>&, Dali::Vector<Vector4>& )
48 static Texture PackToAtlas(const std::vector<PixelData>& pixelData, Dali::Vector<Vector4>& textureRects);
52 * @param [in] width The atlas width in pixels.
53 * @param [in] height The atlas height in pixels.
54 * @param [in] pixelFormat The pixel format.
56 ImageAtlas(SizeType width, SizeType height, Pixel::Format pixelFormat);
59 * @copydoc Toolkit::ImageAtlas::New
61 static IntrusivePtr<ImageAtlas> New(SizeType width, SizeType height, Pixel::Format pixelFormat);
64 * @copydoc Toolkit::ImageAtlas::GetAtlas
69 * @copydoc Toolkit::ImageAtlas::GetOccupancyRate
71 float GetOccupancyRate() const;
74 * @copydoc Toolkit::ImageAtlas::SetBrokenImage
76 void SetBrokenImage(const std::string& brokenImageUrl);
79 * @copydoc Toolkit::ImageAtlas::Upload( Vector4&, const std::string&, ImageDimensions,FittingMode::Type, bool )
81 bool Upload(Vector4& textureRect,
84 FittingMode::Type fittingMode,
85 bool orientationCorrection,
86 AtlasUploadObserver* atlasUploadObserver);
89 * @copydoc Toolkit::ImageAtlas::Upload( Vector4&, PixelData )
91 bool Upload(Vector4& textureRect, PixelData pixelData);
94 * @copydoc Toolkit::ImageAtlas::Remove
96 void Remove(const Vector4& textureRect);
99 * Resets the destroying observer pointer so that we know not to call methods of this object any more.
101 void ObserverDestroyed(AtlasUploadObserver* observer);
111 * @copydoc PixelDataRequester::ProcessPixels
113 void UploadToAtlas(uint32_t id, PixelData pixelData);
116 * Upload broken image
118 * @param[in] area The pixel area for uploading.
120 void UploadBrokenImage(const Rect<unsigned int>& area);
123 ImageAtlas(const ImageAtlas& imageAtlas);
126 ImageAtlas& operator=(const ImageAtlas& imageAtlas);
130 * Each loading task( identified with an ID ) is associated with a rect region for packing the loaded pixel data into the atlas,
131 * and an AtlasUploadObserver whose UploadCompleted method should get executed once the sub texture is ready.
133 struct LoadingTaskInfo
135 LoadingTaskInfo(unsigned short loadTaskId,
136 unsigned int packPositionX,
137 unsigned int packPositionY,
140 AtlasUploadObserver* observer)
141 : loadTaskId(loadTaskId),
142 packRect(packPositionX, packPositionY, width, height),
147 unsigned short loadTaskId;
148 Rect<unsigned int> packRect;
149 AtlasUploadObserver* observer;
152 OwnerContainer<LoadingTaskInfo*> mLoadingTaskInfoContainer;
156 Toolkit::AsyncImageLoader mAsyncLoader;
157 std::string mBrokenImageUrl;
158 ImageDimensions mBrokenImageSize;
161 Pixel::Format mPixelFormat;
164 } // namespace Internal
166 inline const Internal::ImageAtlas& GetImplementation(const Toolkit::ImageAtlas& imageAtlas)
168 DALI_ASSERT_ALWAYS(imageAtlas && "ImageAtlas handle is empty");
170 const BaseObject& handle = imageAtlas.GetBaseObject();
172 return static_cast<const Internal::ImageAtlas&>(handle);
175 inline Internal::ImageAtlas& GetImplementation(Toolkit::ImageAtlas& imageAtlas)
177 DALI_ASSERT_ALWAYS(imageAtlas && "ImageAtlas handle is empty");
179 BaseObject& handle = imageAtlas.GetBaseObject();
181 return static_cast<Internal::ImageAtlas&>(handle);
184 } // namespace Toolkit
188 #endif // DALI_TOOLKIT_IMAGE_ATLAS_IMPL_H