From: David Steele Date: Wed, 22 Mar 2023 15:22:00 +0000 (+0000) Subject: Merge "Make sure that global variables are initialized lazily." into devel/master X-Git-Tag: dali_2.2.19~1 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-core.git;a=commitdiff_plain;h=72b5450e22ef9097d4c935e564cc5232d3308318;hp=cbd74c00a6ea2b47bddb44e24b7d7c3ea642295d Merge "Make sure that global variables are initialized lazily." into devel/master --- diff --git a/dali/internal/common/image-attributes.cpp b/dali/internal/common/image-attributes.cpp index cdce973..3a3b12e 100644 --- a/dali/internal/common/image-attributes.cpp +++ b/dali/internal/common/image-attributes.cpp @@ -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() diff --git a/dali/internal/common/image-attributes.h b/dali/internal/common/image-attributes.h index 3a0dc21..5d04147 100644 --- a/dali/internal/common/image-attributes.h +++ b/dali/internal/common/image-attributes.h @@ -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. */ diff --git a/dali/internal/common/shader-data.h b/dali/internal/common/shader-data.h index 3d50cfa..81992b1 100644 --- a/dali/internal/common/shader-data.h +++ b/dali/internal/common/shader-data.h @@ -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; namespace { -static const std::vector emptyShader; - inline std::vector StringToVector(const std::string& str) { auto retval = std::vector{}; @@ -150,6 +148,7 @@ public: // API else { // DALI_LOG_ERROR("Unsupported shader stage\n"); + static const std::vector emptyShader; return emptyShader; } } diff --git a/dali/internal/render/renderers/render-renderer.cpp b/dali/internal/render/renderers/render-renderer.cpp index 7a19c6b..c6e4b24 100644 --- a/dali/internal/render/renderers/render-renderer.cpp +++ b/dali/internal/render/renderers/render-renderer.cpp @@ -169,7 +169,11 @@ namespace Render { namespace { -MemoryPoolObjectAllocator gRenderRendererMemoryPool; +MemoryPoolObjectAllocator& GetRenderRendererMemoryPool() +{ + static MemoryPoolObjectAllocator 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(ptr)); + void* ptr = GetRenderRendererMemoryPool().AllocateRawThreadSafe(); + auto key = GetRenderRendererMemoryPool().GetKeyFromPtr(static_cast(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(ptr)); + GetRenderRendererMemoryPool().FreeThreadSafe(static_cast(ptr)); } Renderer* Renderer::Get(RendererKey::KeyType rendererKey) { - return gRenderRendererMemoryPool.GetPtrFromKey(rendererKey); + return GetRenderRendererMemoryPool().GetPtrFromKey(rendererKey); } void Renderer::SetGeometry(Render::Geometry* geometry) diff --git a/dali/internal/render/renderers/render-texture.cpp b/dali/internal/render/renderers/render-texture.cpp index f016af6..6adf66f 100644 --- a/dali/internal/render/renderers/render-texture.cpp +++ b/dali/internal/render/renderers/render-texture.cpp @@ -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 gTextureMemoryPool; +MemoryPoolObjectAllocator& GetTextureMemoryPool() +{ + static MemoryPoolObjectAllocator 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(ptr)); + void* ptr = GetTextureMemoryPool().AllocateRawThreadSafe(); + auto key = GetTextureMemoryPool().GetKeyFromPtr(static_cast(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(ptr)); + void* ptr = GetTextureMemoryPool().AllocateRawThreadSafe(); + auto key = GetTextureMemoryPool().GetKeyFromPtr(static_cast(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(ptr)); + GetTextureMemoryPool().FreeThreadSafe(static_cast(ptr)); } Render::Texture* Texture::Get(TextureKey::KeyType key) { - return gTextureMemoryPool.GetPtrFromKey(key); + return GetTextureMemoryPool().GetPtrFromKey(key); } void Texture::Initialize(Graphics::Controller& graphicsController)