/*
- * 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.
// EXTERNAL HEADERS
#include <dali/devel-api/common/hash.h>
+#include <dali/integration-api/adaptor-framework/adaptor.h>
#include <dali/integration-api/debug.h>
namespace Dali
} // Anonymous namespace
NPatchLoader::NPatchLoader()
-: mCurrentNPatchDataId(0)
+: mCurrentNPatchDataId(0),
+ mRemoveProcessorRegistered(false)
{
}
NPatchLoader::~NPatchLoader()
{
+ if(mRemoveProcessorRegistered && Adaptor::IsAvailable())
+ {
+ Adaptor::Get().UnregisterProcessor(*this, true);
+ mRemoveProcessorRegistered = false;
+ }
}
NPatchData::NPatchDataId NPatchLoader::GenerateUniqueNPatchDataId()
{
+ // Skip invalid id generation.
+ if(DALI_UNLIKELY(mCurrentNPatchDataId == NPatchData::INVALID_NPATCH_DATA_ID))
+ {
+ mCurrentNPatchDataId = 0;
+ }
return mCurrentNPatchDataId++;
}
-std::size_t NPatchLoader::Load(TextureManager& textureManager, TextureUploadObserver* textureObserver, const VisualUrl& url, const Rect<int>& border, bool& preMultiplyOnLoad, bool synchronousLoading)
+NPatchData::NPatchDataId NPatchLoader::Load(TextureManager& textureManager, TextureUploadObserver* textureObserver, const VisualUrl& url, const Rect<int>& border, bool& preMultiplyOnLoad, bool synchronousLoading)
{
- NPatchData* data = GetNPatchData(url, border, preMultiplyOnLoad);
+ NPatchDataPtr data = GetNPatchData(url, border, preMultiplyOnLoad);
- DALI_ASSERT_ALWAYS(data && "NPatchData creation failed!");
+ DALI_ASSERT_ALWAYS(data.Get() && "NPatchData creation failed!");
if(data->GetLoadingState() == NPatchData::LoadingState::LOAD_COMPLETE)
{
auto preMultiplyOnLoading = preMultiplyOnLoad ? TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD
: TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
- Devel::PixelBuffer pixelBuffer = textureManager.LoadPixelBuffer(url, Dali::ImageDimensions(), FittingMode::DEFAULT, SamplingMode::BOX_THEN_LINEAR, synchronousLoading, data, true, preMultiplyOnLoading);
+ Devel::PixelBuffer pixelBuffer = textureManager.LoadPixelBuffer(url, Dali::ImageDimensions(), FittingMode::DEFAULT, SamplingMode::BOX_THEN_LINEAR, synchronousLoading, data.Get(), true, preMultiplyOnLoading);
if(pixelBuffer)
{
return INVALID_CACHE_INDEX;
}
-bool NPatchLoader::GetNPatchData(const NPatchData::NPatchDataId id, const NPatchData*& data)
+bool NPatchLoader::GetNPatchData(const NPatchData::NPatchDataId id, NPatchDataPtr& data)
{
int32_t cacheIndex = GetCacheIndexFromId(id);
if(cacheIndex != INVALID_CACHE_INDEX)
return false;
}
-void NPatchLoader::Remove(std::size_t id, TextureUploadObserver* textureObserver)
+void NPatchLoader::RequestRemove(NPatchData::NPatchDataId id, TextureUploadObserver* textureObserver)
+{
+ // Remove observer first
+ if(textureObserver)
+ {
+ int32_t cacheIndex = GetCacheIndexFromId(id);
+ if(cacheIndex != INVALID_CACHE_INDEX)
+ {
+ NPatchInfo& info(mCache[cacheIndex]);
+
+ info.mData->RemoveObserver(textureObserver);
+ }
+ }
+
+ mRemoveQueue.push_back({id, nullptr});
+
+ if(!mRemoveProcessorRegistered && Adaptor::IsAvailable())
+ {
+ mRemoveProcessorRegistered = true;
+ Adaptor::Get().RegisterProcessor(*this, true);
+ }
+}
+
+void NPatchLoader::Remove(NPatchData::NPatchDataId id, TextureUploadObserver* textureObserver)
{
int32_t cacheIndex = GetCacheIndexFromId(id);
if(cacheIndex == INVALID_CACHE_INDEX)
}
}
-NPatchData* NPatchLoader::GetNPatchData(const VisualUrl& url, const Rect<int>& border, bool& preMultiplyOnLoad)
+void NPatchLoader::Process(bool postProcessor)
+{
+ for(auto& iter : mRemoveQueue)
+ {
+ Remove(iter.first, iter.second);
+ }
+ mRemoveQueue.clear();
+
+ if(Adaptor::IsAvailable())
+ {
+ Adaptor::Get().UnregisterProcessor(*this, true);
+ mRemoveProcessorRegistered = false;
+ }
+}
+
+NPatchDataPtr NPatchLoader::GetNPatchData(const VisualUrl& url, const Rect<int>& border, bool& preMultiplyOnLoad)
{
std::size_t hash = CalculateHash(url.GetUrl());
std::vector<NPatchInfo>::size_type index = UNINITIALIZED_ID;