FrameBuffer result colortexture is premultiplied always.
So make we always use premultiplied texture.
And make a way to user determine native image source is premultiplied or not.
+
Since FBO texture always premultiplied, revert scene view's trick
https://review.tizen.org/gerrit/c/platform/core/uifw/dali-toolkit/+/285486
Change-Id: I72bfe4a04a69c259d983e9dc74086cefcdd4cc7d
Signed-off-by: Eunki Hong <eunkiki.hong@samsung.com>
/*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
END_TEST;
}
-int UtcDaliImageConvertPixelDataToUrl(void)
+int UtcDaliImageConvertPixelDataToUrl01(void)
{
ToolkitTestApplication application;
- tet_infoline("UtcDaliImageConvertPixelDataToUrl");
+ tet_infoline("UtcDaliImageConvertPixelDataToUrl01");
unsigned int width(64);
unsigned int height(64);
END_TEST;
}
-int UtcDaliImageConvertNativeImageSourceToUrl(void)
+int UtcDaliImageConvertPixelDataToUrl02(void)
{
ToolkitTestApplication application;
- tet_infoline("UtcDaliImageConvertNativeImageSourceToUrl");
+ tet_infoline("UtcDaliImageConvertPixelDataToUrl02");
+
+ unsigned int width(64);
+ unsigned int height(64);
+ unsigned int bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::RGBA8888);
+
+ unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
+ PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
+
+ DALI_TEST_CHECK(Dali::Toolkit::Image::GenerateUrl(pixelData, true).GetUrl().size() > 0u);
+
+ END_TEST;
+}
+
+int UtcDaliImageConvertNativeImageSourceToUrl01(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline("UtcDaliImageConvertNativeImageSourceToUrl01");
unsigned int width(64);
unsigned int height(64);
END_TEST;
}
+int UtcDaliImageConvertNativeImageSourceToUrl02(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline("UtcDaliImageConvertNativeImageSourceToUrl02");
+
+ unsigned int width(64);
+ unsigned int height(64);
+ try
+ {
+ NativeImageSourcePtr nativeImageSource = NativeImageSource::New(width, height, NativeImageSource::COLOR_DEPTH_DEFAULT);
+
+ DALI_TEST_CHECK(Dali::Toolkit::Image::GenerateUrl(nativeImageSource, true).GetUrl().size() > 0u);
+ }
+ catch(Dali::DaliException& e)
+ {
+ DALI_TEST_PRINT_ASSERT(e);
+ DALI_TEST_ASSERT(e, "Adaptor::IsAvailable()", TEST_LOCATION);
+ }
+ catch(...)
+ {
+ tet_printf("Assertion test failed - wrong Exception\n");
+ tet_result(TET_FAIL);
+ }
+
+ END_TEST;
+}
+
int UtcDaliImageConvertEncodedImageBufferToUrl(void)
{
ToolkitTestApplication application;
/*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
using namespace Dali;
using namespace Dali::Toolkit;
-int UtcImageUrlConstructor(void)
+int UtcImageUrlConstructor01(void)
{
ToolkitTestApplication application;
DALI_TEST_CHECK(downcastUrl);
END_TEST;
}
+
+int UtcImageUrlConstructor02(void)
+{
+ ToolkitTestApplication application;
+
+ tet_infoline(" UtcImageUrlValid ");
+
+ // Test default constructor.
+ ImageUrl imageUrl;
+ DALI_TEST_CHECK(!imageUrl);
+
+ // Test object creation
+ Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 4u, 4u); // test texture
+ imageUrl = ImageUrl::New(image, true);
+ DALI_TEST_CHECK(imageUrl);
+
+ // Test copy constructor
+ ImageUrl ImageUrlCopy(imageUrl);
+ DALI_TEST_CHECK(ImageUrlCopy);
+
+ // Test down cast
+ BaseHandle baseUrl;
+ baseUrl = imageUrl;
+ ImageUrl downcastUrl = ImageUrl::DownCast(baseUrl);
+ DALI_TEST_CHECK(downcastUrl);
+ END_TEST;
+}
/*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
END_TEST;
}
+int UtcDaliImageVisualWithFrameBufferPreMultipliedAlpha01(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline("Use FrameBuffer as url");
+
+ uint32_t width(64);
+ uint32_t height(64);
+ FrameBuffer frameBuffer = Dali::FrameBuffer::New(width, height, FrameBuffer::Attachment::NONE);
+
+ DALI_TEST_CHECK(frameBuffer);
+ ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(frameBuffer, Pixel::Format::RGBA8888, width, height);
+ std::string url = imageUrl.GetUrl();
+
+ VisualFactory factory = VisualFactory::Get();
+ DALI_TEST_CHECK(factory);
+
+ Property::Map propertyMap;
+ propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
+ propertyMap.Insert(ImageVisual::Property::URL, url);
+
+ Visual::Base visual = factory.CreateVisual(propertyMap);
+ DALI_TEST_CHECK(visual);
+
+ DummyControl actor = DummyControl::New();
+ DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
+ dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
+
+ DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
+
+ application.GetScene().Add(actor);
+
+ DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
+
+ application.SendNotification();
+ application.Render(16);
+
+ Renderer renderer = actor.GetRendererAt(0);
+
+ // Check whether preMultipliedAlpha is true.
+ auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
+ DALI_TEST_EQUALS(preMultipliedAlpha, true, TEST_LOCATION);
+
+ END_TEST;
+}
+
+int UtcDaliImageVisualWithFrameBufferPreMultipliedAlpha02(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline("Use FrameBuffer as url");
+
+ uint32_t width(64);
+ uint32_t height(64);
+ FrameBuffer frameBuffer = Dali::FrameBuffer::New(width, height, FrameBuffer::Attachment::NONE);
+
+ DALI_TEST_CHECK(frameBuffer);
+
+ Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
+ frameBuffer.AttachColorTexture(texture);
+
+ ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(frameBuffer, 0u);
+ std::string url = imageUrl.GetUrl();
+
+ VisualFactory factory = VisualFactory::Get();
+ DALI_TEST_CHECK(factory);
+
+ Property::Map propertyMap;
+ propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
+ propertyMap.Insert(ImageVisual::Property::URL, url);
+
+ Visual::Base visual = factory.CreateVisual(propertyMap);
+ DALI_TEST_CHECK(visual);
+
+ DummyControl actor = DummyControl::New();
+ DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
+ dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
+
+ DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
+
+ application.GetScene().Add(actor);
+
+ DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
+
+ application.SendNotification();
+ application.Render(16);
+
+ Renderer renderer = actor.GetRendererAt(0);
+
+ // Check whether preMultipliedAlpha is true.
+ auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
+ DALI_TEST_EQUALS(preMultipliedAlpha, true, TEST_LOCATION);
+
+ END_TEST;
+}
+
+int UtcDaliImageVisualWithPixelData(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline("Use PixelData as url");
+
+ uint32_t width(64);
+ uint32_t height(64);
+ uint32_t bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::RGBA8888);
+
+ uint8_t* buffer = reinterpret_cast<uint8_t*>(malloc(bufferSize));
+ PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
+
+ DALI_TEST_CHECK(pixelData);
+
+ ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(pixelData);
+ std::string url = imageUrl.GetUrl();
+
+ VisualFactory factory = VisualFactory::Get();
+ DALI_TEST_CHECK(factory);
+
+ Property::Map propertyMap;
+ propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
+ propertyMap.Insert(ImageVisual::Property::URL, url);
+
+ Visual::Base visual = factory.CreateVisual(propertyMap);
+ DALI_TEST_CHECK(visual);
+
+ DummyControl actor = DummyControl::New();
+ DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
+ dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
+
+ DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
+
+ application.GetScene().Add(actor);
+
+ DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
+
+ application.SendNotification();
+ application.Render(16);
+
+ Renderer renderer = actor.GetRendererAt(0);
+
+ // Check whether preMultipliedAlpha is false.
+ auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
+ DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
+
+ END_TEST;
+}
+
+int UtcDaliImageVisualWithPixelDataPreMultipliedAlpha(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline("Use PixelData as url");
+
+ uint32_t width(64);
+ uint32_t height(64);
+ uint32_t bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::RGBA8888);
+
+ uint8_t* buffer = reinterpret_cast<uint8_t*>(malloc(bufferSize));
+ PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
+
+ DALI_TEST_CHECK(pixelData);
+
+ ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(pixelData, true);
+ std::string url = imageUrl.GetUrl();
+
+ VisualFactory factory = VisualFactory::Get();
+ DALI_TEST_CHECK(factory);
+
+ Property::Map propertyMap;
+ propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
+ propertyMap.Insert(ImageVisual::Property::URL, url);
+
+ Visual::Base visual = factory.CreateVisual(propertyMap);
+ DALI_TEST_CHECK(visual);
+
+ DummyControl actor = DummyControl::New();
+ DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
+ dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
+
+ DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
+
+ application.GetScene().Add(actor);
+
+ DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
+
+ application.SendNotification();
+ application.Render(16);
+
+ Renderer renderer = actor.GetRendererAt(0);
+
+ // Check whether preMultipliedAlpha is true.
+ auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
+ DALI_TEST_EQUALS(preMultipliedAlpha, true, TEST_LOCATION);
+
+ END_TEST;
+}
+
int UtcDaliImageVisualWithNativeImage(void)
{
ToolkitTestApplication application;
DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
+ application.SendNotification();
+ application.Render(16);
+
Renderer renderer = actor.GetRendererAt(0);
Shader shader = renderer.GetShader();
DALI_TEST_EQUALS(pos != std::string::npos, true, TEST_LOCATION);
+ // Check whether preMultipliedAlpha is false.
+ auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
+ DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
+
+ END_TEST;
+}
+
+int UtcDaliImageVisualWithNativeImagePreMultipliedAlpha(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline("Use Native Image as url");
+
+ NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT);
+ ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSource, true);
+ std::string url = imageUrl.GetUrl();
+
+ VisualFactory factory = VisualFactory::Get();
+ DALI_TEST_CHECK(factory);
+
+ Property::Map propertyMap;
+ propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
+ propertyMap.Insert(ImageVisual::Property::URL, url);
+
+ Visual::Base visual = factory.CreateVisual(propertyMap);
+ DALI_TEST_CHECK(visual);
+
+ DummyControl actor = DummyControl::New();
+ DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
+ dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
+
+ DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
+
+ application.GetScene().Add(actor);
+
+ DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
+
+ application.SendNotification();
+ application.Render(16);
+
+ Renderer renderer = actor.GetRendererAt(0);
+ Shader shader = renderer.GetShader();
+
+ Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
+ DALI_TEST_CHECK(value.GetType() == Property::MAP);
+ const Property::Map* outMap = value.GetMap();
+ std::string fragmentShader = (*outMap)["fragment"].Get<std::string>();
+
+ const char* fragmentPrefix = Dali::NativeImageSourceTest::GetCustomFragmentPrefix();
+ size_t pos = fragmentShader.find(fragmentPrefix);
+
+ DALI_TEST_EQUALS(pos != std::string::npos, true, TEST_LOCATION);
+
+ // Check whether preMultipliedAlpha is true.
+ auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
+ DALI_TEST_EQUALS(preMultipliedAlpha, true, TEST_LOCATION);
+
END_TEST;
}
tet_infoline("Use Native Image as url and Use custom shader");
NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT);
- ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSource);
+ ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSource, true);
std::string url = imageUrl.GetUrl();
VisualFactory factory = VisualFactory::Get();
DALI_TEST_EQUALS(std::string(fragmentPrefix) + customFragmentShaderSource, fragmentShaderSource, TEST_LOCATION);
+ // Check whether preMultipliedAlpha is false.
+ // Note : We dont use preMultiplied alpha when app developer using custom shader.
+ auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
+ DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
+
END_TEST;
}
/*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
std::string url2;
std::string url3;
std::string url4;
+ std::string url5;
+ std::string url6;
// scope to ensure texturesets are kept alive by texture manager
{
auto texture = Texture::New(Dali::TextureType::TEXTURE_2D, Pixel::RGBA8888, 88, 99);
DALI_TEST_CHECK(url4 != url);
DALI_TEST_CHECK(url4 != url2);
DALI_TEST_CHECK(url4 != url3);
+
+ // add same texture again with preMultiplied, should give new Url
+ url5 = TextureManager::AddTexture(texture, true);
+ DALI_TEST_CHECK(url5.size() > 0u);
+ DALI_TEST_CHECK(url5 != url);
+ DALI_TEST_CHECK(url5 != url2);
+ DALI_TEST_CHECK(url5 != url3);
+ DALI_TEST_CHECK(url5 != url4);
+
+ textureSet = TextureSet::New();
+ url6 = TextureManager::AddTexture(textureSet, true);
+ DALI_TEST_CHECK(url6.size() > 0u);
+ DALI_TEST_CHECK(url6 != url);
+ DALI_TEST_CHECK(url6 != url2);
+ DALI_TEST_CHECK(url6 != url3);
+ DALI_TEST_CHECK(url6 != url4);
+ DALI_TEST_CHECK(url6 != url5);
}
auto textureSet = TextureManager::RemoveTexture(url);
textureSet = TextureManager::RemoveTexture(url4);
DALI_TEST_CHECK(!textureSet && "Texture needs to be removed from texture manager");
+ textureSet = TextureManager::RemoveTexture(url5);
+ DALI_TEST_CHECK(textureSet && "Texture needs to be non empty handle");
+ textureSet = TextureManager::RemoveTexture(url5);
+ DALI_TEST_CHECK(!textureSet && "Texture needs to be removed from texture manager");
+
+ textureSet = TextureManager::RemoveTexture(url6);
+ DALI_TEST_CHECK(textureSet && "Texture needs to be non empty handle");
+ textureSet = TextureManager::RemoveTexture(url6);
+ DALI_TEST_CHECK(!textureSet && "Texture needs to be removed from texture manager");
+
END_TEST;
}
Property::Map imagePropertyMap;
imagePropertyMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
imagePropertyMap.Insert(Toolkit::ImageVisual::Property::URL, imageUrl.GetUrl());
- // To make sure this visual call LoadTexture API immediate.
- imagePropertyMap.Insert(Toolkit::ImageVisual::Property::LOAD_POLICY, Toolkit::ImageVisual::LoadPolicy::IMMEDIATE);
- imagePropertyMap.Insert(Toolkit::ImageVisual::Property::RELEASE_POLICY, Toolkit::ImageVisual::ReleasePolicy::DESTROYED);
// To flip rendered scene without CameraActor::SetInvertYAxis() to avoid backface culling.
imagePropertyMap.Insert(Toolkit::ImageVisual::Property::PIXEL_AREA, Vector4(0.0f, 1.0f, 1.0f, -1.0f));
mVisual = Toolkit::VisualFactory::Get().CreateVisual(imagePropertyMap);
- // Use premultiplied alpha when we use FBO
- if(mVisual)
- {
- Toolkit::GetImplementation(mVisual).EnablePreMultipliedAlpha(true);
- }
-
Toolkit::DevelControl::RegisterVisual(*this, RENDERING_BUFFER, mVisual);
mRenderTask.SetFrameBuffer(mFrameBuffer);
/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
{
namespace TextureManager
{
-std::string AddTexture(Texture& texture)
+std::string AddTexture(Texture& texture, bool preMultiplied)
{
TextureSet set = TextureSet::New();
set.SetTexture(0u, texture);
- return AddTexture(set);
+ return AddTexture(set, preMultiplied);
}
-std::string AddTexture(TextureSet& textureSet)
+std::string AddTexture(TextureSet& textureSet, bool preMultiplied)
{
auto visualFactory = Toolkit::VisualFactory::Get();
auto& textureMgr = GetImplementation(visualFactory).GetTextureManager();
- return textureMgr.AddExternalTexture(textureSet);
+ return textureMgr.AddExternalTexture(textureSet, preMultiplied);
}
TextureSet RemoveTexture(const std::string& textureUrl)
#define DALI_TOOLKIT_DEVEL_API_TEXTURE_MANAGER_H
/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* @note this method does not check for duplicates,
* if same Texture is added multiple times, a different URL is returned each time
* @param[in] texture the Texture to add
+ * @param[in] preMultiplied Whether this external texture preMultiplied or not. Default as false.
* @return the Url string representing this texture
*/
-DALI_TOOLKIT_API std::string AddTexture(Texture& texture);
+DALI_TOOLKIT_API std::string AddTexture(Texture& texture, bool preMultiplied = false);
/**
* @brief Add a TextureSet to texture manager
* @note this method does not check for duplicates,
* if same TextureSet is added multiple times, a different URL is returned each time
* @param[in] textureSet the TextureSet to add
+ * @param[in] preMultiplied Whether this external texture preMultiplied or not. Default as false.
* @return the Url string representing this texture
*/
-DALI_TOOLKIT_API std::string AddTexture(TextureSet& textureSet);
+DALI_TOOLKIT_API std::string AddTexture(TextureSet& textureSet, bool preMultiplied = false);
/**
* @brief Removes a TextureSet from toolkit
/*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
{
namespace Internal
{
-ImageUrl::ImageUrl(Texture& texture)
+ImageUrl::ImageUrl(Texture& texture, bool preMultiplied)
{
- mUrl = Dali::Toolkit::TextureManager::AddTexture(texture);
+ mUrl = Dali::Toolkit::TextureManager::AddTexture(texture, preMultiplied);
}
ImageUrl::ImageUrl(const EncodedImageBuffer& encodedImageBuffer)
}
}
-ImageUrlPtr ImageUrl::New(Texture& texture)
+ImageUrlPtr ImageUrl::New(Texture& texture, bool preMultiplied)
{
- ImageUrlPtr imageUrlPtr = new ImageUrl(texture);
+ ImageUrlPtr imageUrlPtr = new ImageUrl(texture, preMultiplied);
return imageUrlPtr;
}
#define DALI_TOOLKIT_INTERNAL_IMAGE_URL_H
/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
/**
* @brief Constructor.
*/
- ImageUrl(Texture& texture);
+ ImageUrl(Texture& texture, bool preMultiplied);
/**
* @brief Constructor.
/**
* @copydoc Dali::Toolkit::ImageUrl::New
*/
- static ImageUrlPtr New(Texture& texture);
+ static ImageUrlPtr New(Texture& texture, bool preMultiplied);
/**
* @copydoc Dali::Toolkit::ImageUrl::New
/*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*/
// CLASS HEADER
-#include "texture-cache-manager.h"
+#include <dali-toolkit/internal/texture-manager/texture-cache-manager.h>
// EXTERNAL HEADERS
#include <dali/devel-api/common/hash.h>
return texture;
}
-TextureSet TextureCacheManager::GetExternalTextureSet(const TextureCacheManager::TextureId& textureId)
+TextureCacheManager::ExternalTextureInfo& TextureCacheManager::GetExternalTextureInfo(const TextureCacheManager::TextureId& textureId)
{
- TextureSet textureSet; // empty handle
TextureCacheIndex cacheIndex = GetCacheIndexFromExternalTextureId(textureId);
- if(cacheIndex != INVALID_CACHE_INDEX)
- {
- textureSet = mExternalTextures[cacheIndex.GetIndex()].textureSet;
- }
- return textureSet;
+ DALI_ASSERT_ALWAYS(cacheIndex != INVALID_CACHE_INDEX);
+
+ return mExternalTextures[cacheIndex.GetIndex()];
}
EncodedImageBuffer TextureCacheManager::GetEncodedImageBuffer(const TextureCacheManager::TextureId& bufferId)
return encodedImageBuffer;
}
-std::string TextureCacheManager::AddExternalTexture(const TextureSet& textureSet)
+std::string TextureCacheManager::AddExternalTexture(const TextureSet& textureSet, bool preMultiplied)
{
TextureId textureId = GenerateTextureId(TextureCacheIndex(TextureCacheIndexType::TEXTURE_CACHE_INDEX_TYPE_TEXTURE, mExternalTextures.size()));
- TextureCacheManager::ExternalTextureInfo textureInfo(textureId, textureSet);
+ TextureCacheManager::ExternalTextureInfo textureInfo(textureId, textureSet, preMultiplied);
mExternalTextures.emplace_back(textureInfo);
- DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureCacheManager::AddExternalTexture() : New texture registered. textureId:%d\n", textureInfo.textureId);
+ DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureCacheManager::AddExternalTexture() : New texture registered. textureId:%d, preMultiplied:%d\n", textureInfo.textureId, preMultiplied);
return VisualUrl::CreateTextureUrl(std::to_string(textureInfo.textureId));
}
#define DALI_TOOLKIT_TEXTURE_CACHE_MANAGER_H
/*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
static constexpr TextureId INVALID_TEXTURE_ID = TextureManagerType::INVALID_TEXTURE_ID;
static constexpr TextureCacheIndex INVALID_CACHE_INDEX = TextureManagerType::INVALID_CACHE_INDEX;
- using UseAtlas = TextureManagerType::UseAtlas;
- using StorageType = TextureManagerType::StorageType;
- using LoadType = TextureManagerType::LoadType;
- using LoadState = TextureManagerType::LoadState;
- using ReloadPolicy = TextureManagerType::ReloadPolicy;
- using MultiplyOnLoad = TextureManagerType::MultiplyOnLoad;
- using TextureInfo = TextureManagerType::TextureInfo;
+ using UseAtlas = TextureManagerType::UseAtlas;
+ using StorageType = TextureManagerType::StorageType;
+ using LoadType = TextureManagerType::LoadType;
+ using LoadState = TextureManagerType::LoadState;
+ using ReloadPolicy = TextureManagerType::ReloadPolicy;
+ using MultiplyOnLoad = TextureManagerType::MultiplyOnLoad;
+ using TextureInfo = TextureManagerType::TextureInfo;
+ using ExternalTextureInfo = TextureManagerType::ExternalTextureInfo;
public:
/**
Texture GetTexture(const TextureCacheManager::TextureId& textureId, uint32_t textureIndex = 0);
/**
- * @brief Get the external texture set if the texture id is valid
+ * @brief Get the external texture set information if the texture id is valid
* @param[in] textureId The texture Id to look up
- * @return the external texture set, or an empty handle if textureId is not valid
+ * @return the external texture information. Assert if textureId is not valid
*/
- TextureSet GetExternalTextureSet(const TextureCacheManager::TextureId& textureId);
+ TextureCacheManager::ExternalTextureInfo& GetExternalTextureInfo(const TextureCacheManager::TextureId& textureId);
/**
* @brief Get the encoded image buffer
/**
* Adds an external texture to the texture manager
* @param[in] texture The texture to add
+ * @param[in] preMultiplied Whether this external texture preMultiplied or not. Default as false.
* @return string containing the URL for the texture
*/
- std::string AddExternalTexture(const TextureSet& texture);
+ std::string AddExternalTexture(const TextureSet& texture, bool preMultiplied);
/**
* Adds an encoded image buffer to the texture manager
// Private defined structs.
/**
- * @brief This struct is used to manage the life-cycle of ExternalTexture url.
- */
- struct ExternalTextureInfo
- {
- ExternalTextureInfo(const TextureCacheManager::TextureId& textureId,
- const TextureSet& textureSet)
- : textureId(textureId),
- textureSet(textureSet),
- referenceCount(1u)
- {
- }
- TextureCacheManager::TextureId textureId;
- TextureSet textureSet;
- std::int16_t referenceCount;
- };
-
- /**
* @brief This struct is used to manage the life-cycle of EncodedImageBuffer url.
*/
struct EncodedImageBufferInfo
/*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*/
// CLASS HEADER
-#include "texture-manager-impl.h"
+#include <dali-toolkit/internal/texture-manager/texture-manager-impl.h>
// EXTERNAL HEADERS
#include <dali/devel-api/adaptor-framework/environment-variable.h>
if(location.size() > 0u)
{
TextureId id = std::stoi(location);
- textureSet = mTextureCacheManager.GetExternalTextureSet(id);
- if(textureSet)
+ auto externalTextureInfo = mTextureCacheManager.GetExternalTextureInfo(id);
+ if(externalTextureInfo.textureSet)
{
- preMultiplyOnLoad = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
- textureId = id;
- return textureSet;
+ textureId = id;
+
+ if(preMultiplyOnLoad == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD)
+ {
+ // Change preMultiplyOnLoad value so make caller determine to preMultiplyAlpha or not.
+ // TODO : Should we seperate input and output value?
+ preMultiplyOnLoad = externalTextureInfo.preMultiplied ? TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD : TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
+ }
+ return externalTextureInfo.textureSet;
}
}
}
#define DALI_TOOLKIT_TEXTURE_MANAGER_IMPL_H
/*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
/**
* @copydoc TextureCacheManager::AddExternalTexture
*/
- inline std::string AddExternalTexture(const TextureSet& texture)
+ inline std::string AddExternalTexture(const TextureSet& texture, bool preMultiplied = false)
{
- return mTextureCacheManager.AddExternalTexture(texture);
+ return mTextureCacheManager.AddExternalTexture(texture, preMultiplied);
}
/**
#define DALI_TOOLKIT_TEXTURE_MANAGER_TYPE_H
/*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
const TextureId& maskTextureId,
const VisualUrl& url,
const Dali::ImageDimensions& desiredSize,
- const float& scaleFactor,
+ float scaleFactor,
const Dali::FittingMode::Type& fittingMode,
const Dali::SamplingMode::Type& samplingMode,
- const bool& loadSynchronously,
- const bool& cropToMask,
+ bool loadSynchronously,
+ bool cropToMask,
const UseAtlas& useAtlas,
const TextureHash& hash,
- const bool& orientationCorrection,
- const bool& preMultiplyOnLoad,
+ bool orientationCorrection,
+ bool preMultiplyOnLoad,
const Dali::AnimatedImageLoading& animatedImageLoading,
- const std::uint32_t& frameIndex,
- const bool& loadYuvPlanes)
+ std::uint32_t frameIndex,
+ bool loadYuvPlanes)
: url(url),
desiredSize(desiredSize),
useSize(desiredSize),
bool loadYuvPlanes : 1; ///< true if the image should be loaded as yuv planes
};
+/**
+ * @brief This struct is used to manage the life-cycle of ExternalTexture url.
+ */
+struct ExternalTextureInfo
+{
+ ExternalTextureInfo(const TextureId& textureId,
+ const TextureSet& textureSet,
+ bool preMultiplied)
+ : textureId(textureId),
+ textureSet(textureSet),
+ referenceCount(1u),
+ preMultiplied(preMultiplied)
+ {
+ }
+
+ TextureId textureId; ///< The TextureId associated with this ExternalTexture
+ TextureSet textureSet; ///< The external texture
+ std::int16_t referenceCount; ///< The reference count of clients using this ExternalTexture
+ bool preMultiplied : 1; ///< True if the image's color was multiplied by it's alpha
+};
+
} // namespace TextureManagerType
} // namespace Internal
/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
{
}
-ImageUrl ImageUrl::New(Texture& texture)
+ImageUrl ImageUrl::New(Texture& texture, bool preMultiplied)
{
- Toolkit::Internal::ImageUrlPtr internal = Toolkit::Internal::ImageUrl::New(texture);
+ Toolkit::Internal::ImageUrlPtr internal = Toolkit::Internal::ImageUrl::New(texture, preMultiplied);
return ImageUrl(internal.Get());
}
#define DALI_TOOLKIT_IMAGE_URL_H
/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* @brief Create an initialized ImageUrl.
*
* @param[in] texture The texture url is got from external buffer.
+ * @param[in] preMultiplied Whether this external texture preMultiplied or not. Default as false.
* @return A handle to a newly allocated Dali resource.
*/
- static ImageUrl New(Texture& texture);
+ static ImageUrl New(Texture& texture, bool preMultiplied = false);
/**
* @brief Create an initialized ImageUrl.
/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*/
// CLASS HEADER
-#include "image.h"
+#include <dali-toolkit/public-api/image-loader/image.h>
// INTERNAL INCLUDES
#include <dali-toolkit/devel-api/image-loader/texture-manager.h>
{
Texture texture = Texture::New(Dali::TextureType::TEXTURE_2D, pixelFormat, width, height);
frameBuffer.AttachColorTexture(texture, 0u, 0u);
- Dali::Toolkit::ImageUrl imageUrl = Dali::Toolkit::ImageUrl::New(texture);
+ // TODO : Need to check frameBuffer result use preMultiplied color or not. By default, we use premultiplied
+ Dali::Toolkit::ImageUrl imageUrl = Dali::Toolkit::ImageUrl::New(texture, true);
return imageUrl;
}
Dali::Toolkit::ImageUrl GenerateUrl(const Dali::FrameBuffer frameBuffer, uint8_t index)
{
Texture texture = Dali::DevelFrameBuffer::GetColorTexture(frameBuffer, index);
- Dali::Toolkit::ImageUrl imageUrl = Dali::Toolkit::ImageUrl::New(texture);
+ // TODO : Need to check frameBuffer result use preMultiplied color or not. By default, we use premultiplied
+ Dali::Toolkit::ImageUrl imageUrl = Dali::Toolkit::ImageUrl::New(texture, true);
return imageUrl;
}
-Dali::Toolkit::ImageUrl GenerateUrl(const Dali::PixelData pixelData)
+Dali::Toolkit::ImageUrl GenerateUrl(const Dali::PixelData pixelData, bool preMultiplied)
{
Texture texture = Texture::New(TextureType::TEXTURE_2D, pixelData.GetPixelFormat(), pixelData.GetWidth(), pixelData.GetHeight());
texture.Upload(pixelData);
- Dali::Toolkit::ImageUrl imageUrl = Dali::Toolkit::ImageUrl::New(texture);
+ Dali::Toolkit::ImageUrl imageUrl = Dali::Toolkit::ImageUrl::New(texture, preMultiplied);
return imageUrl;
}
-Dali::Toolkit::ImageUrl GenerateUrl(const Dali::NativeImageSourcePtr nativeImageSource)
+Dali::Toolkit::ImageUrl GenerateUrl(const Dali::NativeImageSourcePtr nativeImageSource, bool preMultiplied)
{
Texture texture = Dali::Texture::New(*nativeImageSource);
- Dali::Toolkit::ImageUrl imageUrl = Dali::Toolkit::ImageUrl::New(texture);
+ Dali::Toolkit::ImageUrl imageUrl = Dali::Toolkit::ImageUrl::New(texture, preMultiplied);
return imageUrl;
}
#define DALI_TOOLKIT_IMAGE_H
/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* This Url can be used in visuals to render the pixel data.
* @note This method does not check for duplicates, If same pixel data is entered multiple times, a different URL is returned each time.
* @param[in] pixelData the pixel data to converted to Url
+ * @param[in] preMultiplied Whether this pixel data preMultiplied or not. Default as false.
* @return the ImageUrl representing this pixel data
*/
-DALI_TOOLKIT_API Dali::Toolkit::ImageUrl GenerateUrl(const Dali::PixelData pixelData);
+DALI_TOOLKIT_API Dali::Toolkit::ImageUrl GenerateUrl(const Dali::PixelData pixelData, bool preMultiplied = false);
/**
* @brief Generate a Url from native image source.
* This Url can be used in visuals to render the native image source.
* @note This method does not check for duplicates, If same native image source is entered multiple times, a different URL is returned each time.
* @param[in] nativeImageSource the native image source to converted to Url
+ * @param[in] preMultiplied Whether this native image source preMultiplied or not. Default as false.
* @return the ImageUrl representing this native image source
*/
-DALI_TOOLKIT_API Dali::Toolkit::ImageUrl GenerateUrl(const Dali::NativeImageSourcePtr nativeImageSource);
+DALI_TOOLKIT_API Dali::Toolkit::ImageUrl GenerateUrl(const Dali::NativeImageSourcePtr nativeImageSource, bool preMultiplied = false);
/**
* @brief Generate a Url from encoded image buffer.