- In current implementation, npatch textureSet is cached in npatch-loader.
- This patch prevent to sent empty loadComplete call from texture manager to npatch-visual.
- And also, this patch let the npatch-loader handle all the caching process without texture-manager caching.
Change-Id: Ibd5f14996420f8651cab6f5b6ccefa67689e4f7f
Signed-off-by: seungho <sbsh.baek@samsung.com>
END_TEST;
}
-int UtcDaliNPatchVisualAuxiliaryImage(void)
+int UtcDaliNPatchVisualAuxiliaryImage01(void)
{
ToolkitTestApplication application;
tet_infoline( "NPatchVisual with aux image" );
END_TEST;
}
+int UtcDaliNPatchVisualAuxiliaryImage02(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline( "Multiple NPatchVisual with aux image coincidentally" );
+
+ const Property::Value NPATCH_TEST{
+ {ImageVisual::Property::URL, TEST_9_PATCH_FILE_NAME},
+ {DevelImageVisual::Property::AUXILIARY_IMAGE, TEST_AUX_IMAGE}};
+
+ ImageView imageView1 = ImageView::New();
+ imageView1[ImageView::Property::IMAGE] = NPATCH_TEST;
+ application.GetScene().Add( imageView1 );
+
+ ImageView imageView2 = ImageView::New();
+ imageView2[ImageView::Property::IMAGE] = NPATCH_TEST;
+ application.GetScene().Add( imageView2 );
+
+ DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
+
+ application.SendNotification();
+ application.Render();
+
+ Renderer renderer1 = imageView1.GetRendererAt( 0 );
+ auto textureSet1 = renderer1.GetTextures();
+
+ Renderer renderer2 = imageView2.GetRendererAt( 0 );
+ auto textureSet2 = renderer2.GetTextures();
+ DALI_TEST_EQUALS( textureSet1 == textureSet2, true, TEST_LOCATION );
+
+ END_TEST;
+}
+
int UtcDaliVisualFactoryGetNPatchVisualN1(void)
{
{
return index + 1u; // valid indices are from 1 onwards
}
+ mCache[ index ]->observerList.PushBack( textureObserver );
data = mCache[ index ];
- cachedIndex = index + 1u; // valid indices are from 1 onwards
- break;
+ return index + 1u; // valid indices are from 1 onwards
}
else
{
return cachedIndex;
}
-void NPatchLoader::SetNPatchData( std::size_t id, Devel::PixelBuffer& pixelBuffer )
+void NPatchLoader::SetNPatchData( bool loadSuccess, std::size_t id, Devel::PixelBuffer& pixelBuffer, const Internal::VisualUrl& url, bool preMultiplied )
{
Data* data;
data = mCache[ id - 1u ];
- if( !data->loadCompleted )
+ // To prevent recursion.
+ // data->loadCompleted will be set true in the NPatchBuffer::SetLoadedNPatchData when the first observer called this method.
+ if( data->loadCompleted )
{
- NPatchBuffer::SetLoadedNPatchData( data, pixelBuffer );
+ return;
+ }
+
+ NPatchBuffer::SetLoadedNPatchData( data, pixelBuffer );
+
+ while( data->observerList.Count() )
+ {
+ TextureUploadObserver* observer = data->observerList[0];
+ observer->LoadComplete( loadSuccess, Devel::PixelBuffer(), url, preMultiplied );
+ data->observerList.Erase( data->observerList.begin() );
}
}
~Data();
+ using ObserverListType = Dali::Vector< TextureUploadObserver* >;
+
+ ObserverListType observerList; ///< Container used to store all observer clients of this Texture
std::string url; ///< Url of the N-Patch
TextureSet textureSet; ///< Texture containing the cropped image
NPatchUtility::StretchRanges stretchPixelsX; ///< X stretch pixels
/**
* @brief Set loaded PixelBuffer and its information
*
+ * @param [in] loadSuccess True if the texture load was successful (i.e. the resource is available). If false, then the resource failed to load.
* @param [in] id cache data id
* @param [in] pixelBuffer of loaded image
+ * @param [in] url The url address of the loaded image.
+ * @param [in] preMultiplied True if the image had pre-multiplied alpha applied
*/
- void SetNPatchData( std::size_t id, Devel::PixelBuffer& pixelBuffer );
+ void SetNPatchData( bool loadSuccess, std::size_t id, Devel::PixelBuffer& pixelBuffer, const Internal::VisualUrl& url, bool preMultiplied );
/**
* @brief Retrieve N patch data matching to an id
}
else
{
+ Devel::PixelBuffer loadedPixelBuffer;
if( loadSuccess )
{
- mLoader.SetNPatchData( mId, pixelBuffer );
+ loadedPixelBuffer = pixelBuffer;
EnablePreMultipliedAlpha( preMultiplied );
}
+ else
+ {
+ loadedPixelBuffer = LoadImageFromFile( mFactoryCache.GetTextureManager().GetBrokenImageUrl() );
+ }
+ mLoader.SetNPatchData( loadSuccess, mId, loadedPixelBuffer, url, preMultiplied );
if( mAuxiliaryPixelBuffer || !mAuxiliaryUrl.IsValid() )
{
namespace
{
+constexpr auto INITIAL_CACHE_NUMBER = size_t{0u};
constexpr auto DEFAULT_NUMBER_OF_LOCAL_LOADER_THREADS = size_t{4u};
constexpr auto DEFAULT_NUMBER_OF_REMOTE_LOADER_THREADS = size_t{8u};
{
// First check if the requested Texture is cached.
bool isAnimatedImage = ( animatedImageLoading ) ? true : false;
- const TextureHash textureHash = GenerateHash( url.GetUrl(), desiredSize, fittingMode, samplingMode, useAtlas,
- maskTextureId, storageType, isAnimatedImage, frameIndex );
+
+ TextureHash textureHash = INITIAL_CACHE_NUMBER;
+ int cacheIndex = INVALID_CACHE_INDEX;
+ if(storageType != StorageType::RETURN_PIXEL_BUFFER)
+ {
+ textureHash = GenerateHash(url.GetUrl(), desiredSize, fittingMode, samplingMode, useAtlas, maskTextureId, isAnimatedImage, frameIndex);
+
+ // Look up the texture by hash. Note: The extra parameters are used in case of a hash collision.
+ cacheIndex = FindCachedTexture(textureHash, url.GetUrl(), desiredSize, fittingMode, samplingMode, useAtlas, maskTextureId, preMultiplyOnLoad, isAnimatedImage, frameIndex);
+ }
TextureManager::TextureId textureId = INVALID_TEXTURE_ID;
- // Look up the texture by hash. Note: The extra parameters are used in case of a hash collision.
- int cacheIndex = FindCachedTexture( textureHash, url.GetUrl(), desiredSize, fittingMode, samplingMode, useAtlas,
- maskTextureId, preMultiplyOnLoad, storageType, isAnimatedImage, frameIndex );
// Check if the requested Texture exists in the cache.
if( cacheIndex != INVALID_CACHE_INDEX )
const Dali::SamplingMode::Type samplingMode,
const UseAtlas useAtlas,
TextureId maskTextureId,
- StorageType storageType,
bool isAnimationImage,
uint32_t frameIndex )
{
*hashTargetPtr++ = ( size.GetHeight() >> 8u ) & 0xff;
// Bit-pack the FittingMode, SamplingMode and atlasing.
- // FittingMode=2bits, SamplingMode=3bits, useAtlas=1bit, storageType=2bits
- *hashTargetPtr = ( fittingMode << 6u ) | ( samplingMode << 3 ) | ( useAtlas << 2 ) | static_cast<unsigned int>(storageType);
+ // FittingMode=2bits, SamplingMode=3bits, useAtlas=1bit
+ *hashTargetPtr = ( fittingMode << 4u ) | ( samplingMode << 1 ) | useAtlas;
}
else
{
const bool useAtlas,
TextureId maskTextureId,
TextureManager::MultiplyOnLoad preMultiplyOnLoad,
- StorageType storageType,
bool isAnimatedImage,
uint32_t frameIndex )
{
( ( size.GetWidth() == 0 && size.GetHeight() == 0 ) ||
( fittingMode == textureInfo.fittingMode &&
samplingMode == textureInfo.samplingMode ) ) &&
- ( storageType == textureInfo.storageType ) &&
( isAnimatedImage == ( ( textureInfo.animatedImageLoading ) ? true : false ) ) &&
( frameIndex == textureInfo.frameIndex ) )
{
mBrokenImageUrl = brokenImageUrl;
}
+const std::string TextureManager::GetBrokenImageUrl()
+{
+ return mBrokenImageUrl;
+}
+
Geometry TextureManager::GetRenderGeometry(TextureId textureId, uint32_t& frontElements, uint32_t& backElements )
{
return RenderingAddOn::Get().IsValid() ?
void SetBrokenImageUrl(const std::string& brokenImageUrl);
/**
+ * @brief Get an image to be used when a visual has failed to correctly render
+ * @return Returns The broken image url.
+ */
+ const std::string GetBrokenImageUrl();
+
+ /**
* @brief Returns the geometry associated with texture.
* @param[in] textureId Id of the texture
* @param[out] frontElements number of front elements
TextureHash GenerateHash( const std::string& url, const ImageDimensions size,
const FittingMode::Type fittingMode,
const Dali::SamplingMode::Type samplingMode, const UseAtlas useAtlas,
- TextureId maskTextureId, StorageType storageType, bool isAnimatedImage, uint32_t frameIndex );
+ TextureId maskTextureId, bool isAnimatedImage, uint32_t frameIndex );
/**
* @brief Looks up a cached texture by its hash.
* @param[in] useAtlas True if atlased
* @param[in] maskTextureId Optional texture ID to use to mask this image
* @param[in] preMultiplyOnLoad if the image's color should be multiplied by it's alpha. Set to OFF if there is no alpha.
- * @param[in] storageType Whether the pixel data is stored in the cache, returned with PixelBuffer or uploaded to the GPU
* @param[in] isAnimatedImage The boolean value to know whether the request is for animated image or not
* @param[in] frameIndex The frame index of a frame to be loaded frame
* @return A TextureId of a cached Texture if found. Or INVALID_TEXTURE_ID if not found.
const bool useAtlas,
TextureId maskTextureId,
MultiplyOnLoad preMultiplyOnLoad,
- StorageType storageType,
bool isAnimatedImage,
uint32_t frameIndex );