+bool ImageAtlas::Upload(Vector4& textureRect,
+ const EncodedImageBuffer& encodedImageBuffer,
+ ImageDimensions size,
+ FittingMode::Type fittingMode,
+ bool orientationCorrection,
+ AtlasUploadObserver* atlasUploadObserver)
+{
+ ImageDimensions zero;
+ if(size == zero) // image size not provided
+ {
+ DALI_LOG_ERROR("Desired size is zero! We need to setup desired size for Atlas.\n");
+ // EncodedImageBuffer didn't support to get closest image size.
+ // Just draw broken image.
+ if(!mBrokenImageUrl.empty())
+ {
+ return Upload(textureRect, mBrokenImageUrl, mBrokenImageSize, FittingMode::DEFAULT, true, atlasUploadObserver);
+ }
+ else
+ {
+ textureRect = Vector4::ZERO;
+ return true;
+ }
+ }
+
+ uint32_t packPositionX = 0;
+ uint32_t packPositionY = 0;
+ if(mPacker.Pack(size.GetWidth(), size.GetHeight(), packPositionX, packPositionY))
+ {
+ uint32_t loadId = GetImplementation(mAsyncLoader).LoadEncodedImageBuffer(encodedImageBuffer, size, fittingMode, SamplingMode::BOX_THEN_LINEAR, orientationCorrection, DevelAsyncImageLoader::PreMultiplyOnLoad::OFF);
+ mLoadingTaskInfoContainer.PushBack(new LoadingTaskInfo(loadId, packPositionX, packPositionY, size.GetWidth(), size.GetHeight(), atlasUploadObserver));
+ // apply the half pixel correction
+ textureRect.x = (static_cast<float>(packPositionX) + 0.5f) / mWidth; // left
+ textureRect.y = (static_cast<float>(packPositionY) + 0.5f) / mHeight; // top
+ textureRect.z = (static_cast<float>(packPositionX + size.GetX()) - 0.5f) / mWidth; // right
+ textureRect.w = (static_cast<float>(packPositionY + size.GetY()) - 0.5f) / mHeight; // bottom
+
+ if(atlasUploadObserver)
+ {
+ // register to the observer,
+ // Not that a matching unregister call should be invoked in UploadToAtlas if the observer is still alive by then.
+ atlasUploadObserver->Register(*this);
+ }
+
+ return true;
+ }
+
+ return false;
+}
+