Merge "Make sure that global variables are initialized lazily." into devel/master
authorDavid Steele <david.steele@samsung.com>
Wed, 22 Mar 2023 15:22:00 +0000 (15:22 +0000)
committerGerrit Code Review <gerrit@review>
Wed, 22 Mar 2023 15:22:00 +0000 (15:22 +0000)
dali/internal/common/image-attributes.cpp
dali/internal/common/image-attributes.h
dali/internal/common/shader-data.h
dali/internal/render/renderers/render-renderer.cpp
dali/internal/render/renderers/render-texture.cpp

index cdce973..3a3b12e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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.
@@ -25,8 +25,6 @@ namespace Dali
 {
 namespace Internal
 {
-const ImageAttributes ImageAttributes::DEFAULT_ATTRIBUTES;
-
 struct ImageAttributes::ImageAttributesImpl
 {
   ImageAttributesImpl()
index 3a0dc21..5d04147 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_IMAGE_ATTRIBUTES_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.
@@ -91,8 +91,6 @@ public:
    */
   using FilterMode = Dali::SamplingMode::Type;
 
-  static const ImageAttributes DEFAULT_ATTRIBUTES; ///< Default attributes have no size
-
   /**
    * @brief Default constructor, initializes to default values.
    */
index 3d50cfa..81992b1 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_SHADER_DATA_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.
@@ -36,8 +36,6 @@ using ShaderDataPtr = IntrusivePtr<ShaderData>;
 
 namespace
 {
-static const std::vector<char> emptyShader;
-
 inline std::vector<char> StringToVector(const std::string& str)
 {
   auto retval = std::vector<char>{};
@@ -150,6 +148,7 @@ public: // API
     else
     {
       //      DALI_LOG_ERROR("Unsupported shader stage\n");
+      static const std::vector<char> emptyShader;
       return emptyShader;
     }
   }
index 7a19c6b..c6e4b24 100644 (file)
@@ -169,7 +169,11 @@ namespace Render
 {
 namespace
 {
-MemoryPoolObjectAllocator<Renderer> gRenderRendererMemoryPool;
+MemoryPoolObjectAllocator<Renderer>& GetRenderRendererMemoryPool()
+{
+  static MemoryPoolObjectAllocator<Renderer> gRenderRendererMemoryPool;
+  return gRenderRendererMemoryPool;
+}
 }
 
 void Renderer::PrepareCommandBuffer()
@@ -191,8 +195,8 @@ RendererKey Renderer::NewKey(SceneGraph::RenderDataProvider* dataProvider,
                              DepthFunction::Type             depthFunction,
                              StencilParameters&              stencilParameters)
 {
-  void* ptr = gRenderRendererMemoryPool.AllocateRawThreadSafe();
-  auto  key = gRenderRendererMemoryPool.GetKeyFromPtr(static_cast<Renderer*>(ptr));
+  void* ptr = GetRenderRendererMemoryPool().AllocateRawThreadSafe();
+  auto  key = GetRenderRendererMemoryPool().GetKeyFromPtr(static_cast<Renderer*>(ptr));
 
   // Use placement new to construct renderer.
   new(ptr) Renderer(dataProvider, geometry, blendingBitmask, blendColor, faceCullingMode, preMultipliedAlphaEnabled, depthWriteMode, depthTestMode, depthFunction, stencilParameters);
@@ -245,12 +249,12 @@ Renderer::~Renderer() = default;
 
 void Renderer::operator delete(void* ptr)
 {
-  gRenderRendererMemoryPool.FreeThreadSafe(static_cast<Renderer*>(ptr));
+  GetRenderRendererMemoryPool().FreeThreadSafe(static_cast<Renderer*>(ptr));
 }
 
 Renderer* Renderer::Get(RendererKey::KeyType rendererKey)
 {
-  return gRenderRendererMemoryPool.GetPtrFromKey(rendererKey);
+  return GetRenderRendererMemoryPool().GetPtrFromKey(rendererKey);
 }
 
 void Renderer::SetGeometry(Render::Geometry* geometry)
index f016af6..6adf66f 100644 (file)
@@ -37,7 +37,11 @@ Debug::Filter* gTextureFilter = Debug::Filter::New(Debug::Concise, false, "LOG_T
 #endif
 
 // Memory pool used to allocate new textures. Memory used by this pool will be released when shutting down DALi
-MemoryPoolObjectAllocator<Texture> gTextureMemoryPool;
+MemoryPoolObjectAllocator<Texture>& GetTextureMemoryPool()
+{
+  static MemoryPoolObjectAllocator<Texture> gTextureMemoryPool;
+  return gTextureMemoryPool;
+}
 
 /**
  * Converts DALi pixel format to Graphics::Format
@@ -211,8 +215,8 @@ constexpr Graphics::TextureType ConvertType(Texture::Type type)
 
 TextureKey Texture::NewKey(Type type, Pixel::Format format, ImageDimensions size)
 {
-  void* ptr = gTextureMemoryPool.AllocateRawThreadSafe();
-  auto  key = gTextureMemoryPool.GetKeyFromPtr(static_cast<Texture*>(ptr));
+  void* ptr = GetTextureMemoryPool().AllocateRawThreadSafe();
+  auto  key = GetTextureMemoryPool().GetKeyFromPtr(static_cast<Texture*>(ptr));
   new(ptr) Texture(type, format, size);
 
   return TextureKey(key);
@@ -220,8 +224,8 @@ TextureKey Texture::NewKey(Type type, Pixel::Format format, ImageDimensions size
 
 TextureKey Texture::NewKey(NativeImageInterfacePtr nativeImageInterface)
 {
-  void* ptr = gTextureMemoryPool.AllocateRawThreadSafe();
-  auto  key = gTextureMemoryPool.GetKeyFromPtr(static_cast<Texture*>(ptr));
+  void* ptr = GetTextureMemoryPool().AllocateRawThreadSafe();
+  auto  key = GetTextureMemoryPool().GetKeyFromPtr(static_cast<Texture*>(ptr));
   new(ptr) Texture(nativeImageInterface);
 
   return TextureKey(key);
@@ -259,12 +263,12 @@ Texture::~Texture() = default;
 
 void Texture::operator delete(void* ptr)
 {
-  gTextureMemoryPool.FreeThreadSafe(static_cast<Texture*>(ptr));
+  GetTextureMemoryPool().FreeThreadSafe(static_cast<Texture*>(ptr));
 }
 
 Render::Texture* Texture::Get(TextureKey::KeyType key)
 {
-  return gTextureMemoryPool.GetPtrFromKey(key);
+  return GetTextureMemoryPool().GetPtrFromKey(key);
 }
 
 void Texture::Initialize(Graphics::Controller& graphicsController)