Make sure that global variables are initialized lazily.
[platform/core/uifw/dali-core.git] / dali / internal / update / rendering / scene-graph-texture-set.cpp
index 1e95d3b..106b711 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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 //Unnamed namespace
 {
 //Memory pool used to allocate new texture sets. Memory used by this pool will be released when shutting down DALi
-Dali::Internal::MemoryPoolObjectAllocator<Dali::Internal::SceneGraph::TextureSet> gTextureSetMemoryPool;
+Dali::Internal::MemoryPoolObjectAllocator<Dali::Internal::SceneGraph::TextureSet>& GetTextureSetMemoryPool()
+{
+  static Dali::Internal::MemoryPoolObjectAllocator<Dali::Internal::SceneGraph::TextureSet> gTextureSetMemoryPool;
+  return gTextureSetMemoryPool;
+}
 } // namespace
 
 namespace Dali
@@ -37,7 +41,7 @@ namespace SceneGraph
 {
 TextureSet* TextureSet::New()
 {
-  return new(gTextureSetMemoryPool.AllocateRawThreadSafe()) TextureSet();
+  return new(GetTextureSetMemoryPool().AllocateRawThreadSafe()) TextureSet();
 }
 
 TextureSet::TextureSet()
@@ -52,7 +56,7 @@ TextureSet::~TextureSet()
 
 void TextureSet::operator delete(void* ptr)
 {
-  gTextureSetMemoryPool.FreeThreadSafe(static_cast<TextureSet*>(ptr));
+  GetTextureSetMemoryPool().FreeThreadSafe(static_cast<TextureSet*>(ptr));
 }
 
 void TextureSet::SetSampler(uint32_t index, Render::Sampler* sampler)
@@ -75,7 +79,7 @@ void TextureSet::SetSampler(uint32_t index, Render::Sampler* sampler)
   }
 }
 
-void TextureSet::SetTexture(uint32_t index, Render::Texture* texture)
+void TextureSet::SetTexture(uint32_t index, const Render::TextureKey& texture)
 {
   const uint32_t textureCount = static_cast<uint32_t>(mTextures.Size());
   if(textureCount < index + 1)
@@ -91,7 +95,7 @@ void TextureSet::SetTexture(uint32_t index, Render::Texture* texture)
 
     for(uint32_t i(textureCount); i <= index; ++i)
     {
-      mTextures[i] = nullptr;
+      mTextures[i] = Render::TextureKey{};
 
       if(!samplerExist)
       {
@@ -115,7 +119,7 @@ bool TextureSet::HasAlpha() const
 
 uint32_t TextureSet::GetMemoryPoolCapacity()
 {
-  return gTextureSetMemoryPool.GetCapacity();
+  return GetTextureSetMemoryPool().GetCapacity();
 }
 
 } // namespace SceneGraph