Migrated Render::Texture to use memory pool 77/286777/6
authorDavid Steele <david.steele@samsung.com>
Thu, 12 Jan 2023 16:18:02 +0000 (16:18 +0000)
committerDavid Steele <david.steele@samsung.com>
Fri, 20 Jan 2023 16:46:50 +0000 (16:46 +0000)
Changing Render::Texture to use memory pool enables
use of 32bit keys instead of 64bit ptrs in general
stores (Internal::Texture, SceneGraph::TextureSet, RenderManager)
and messaging.

Change-Id: I26bd5ff57ad7d8c034fdb51b6c9a869635ed8849
Signed-off-by: David Steele <david.steele@samsung.com>
19 files changed:
dali/internal/common/owner-key-container.h [moved from dali/internal/update/manager/owner-key-container.h with 93% similarity]
dali/internal/event/rendering/frame-buffer-impl.cpp
dali/internal/event/rendering/texture-impl.cpp
dali/internal/event/rendering/texture-impl.h
dali/internal/event/rendering/texture-set-impl.cpp
dali/internal/render/common/render-list.h
dali/internal/render/common/render-manager.cpp
dali/internal/render/common/render-manager.h
dali/internal/render/data-providers/render-data-provider.h
dali/internal/render/renderers/render-renderer.cpp
dali/internal/render/renderers/render-texture-key.h [new file with mode: 0644]
dali/internal/render/renderers/render-texture.cpp
dali/internal/render/renderers/render-texture.h
dali/internal/update/manager/update-manager.cpp
dali/internal/update/manager/update-manager.h
dali/internal/update/rendering/scene-graph-renderer.cpp
dali/internal/update/rendering/scene-graph-renderer.h
dali/internal/update/rendering/scene-graph-texture-set.cpp
dali/internal/update/rendering/scene-graph-texture-set.h

@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_OWNER_KEY_CONTAINER_H
 
 /*
- * 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.
@@ -54,10 +54,10 @@ public:
   }
 
   // Not copyable or movable
-  OwnerKeyContainer(const OwnerKeyContainer&)            = delete; ///< Deleted copy constructor
-  OwnerKeyContainer(OwnerKeyContainer&&)                 = delete; ///< Deleted move constructor
+  OwnerKeyContainer(const OwnerKeyContainer&) = delete;            ///< Deleted copy constructor
+  OwnerKeyContainer(OwnerKeyContainer&&)      = delete;            ///< Deleted move constructor
   OwnerKeyContainer& operator=(const OwnerKeyContainer&) = delete; ///< Deleted copy assignment operator
-  OwnerKeyContainer& operator=(OwnerKeyContainer&&)      = delete; ///< Deleted move assignment operator
+  OwnerKeyContainer& operator=(OwnerKeyContainer&&) = delete;      ///< Deleted move assignment operator
 
   /**
    * Test whether the container is empty.
@@ -90,8 +90,7 @@ public:
     auto begin = BaseType::Begin();
     auto end   = BaseType::End();
 
-    auto function = [predicate](auto& key)
-    {
+    auto function = [predicate](auto& key) {
       if(predicate(key.Get()))
       {
         delete key.Get();
index bd6b118..eb01d3c 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.
@@ -75,7 +75,7 @@ void FrameBuffer::AttachColorTexture(TexturePtr texture, uint32_t mipmapLevel, u
     mColor[mColorAttachmentCount] = texture;
     ++mColorAttachmentCount;
 
-    AttachColorTextureToFrameBuffer(mEventThreadServices.GetUpdateManager(), *mRenderObject, texture->GetRenderObject(), mipmapLevel, layer);
+    AttachColorTextureToFrameBuffer(mEventThreadServices.GetUpdateManager(), *mRenderObject, texture->GetRenderTextureKey().Get(), mipmapLevel, layer);
   }
 }
 
@@ -89,7 +89,7 @@ void FrameBuffer::AttachDepthTexture(TexturePtr texture, uint32_t mipmapLevel)
   else
   {
     mDepth = texture;
-    AttachDepthTextureToFrameBuffer(mEventThreadServices.GetUpdateManager(), *mRenderObject, texture->GetRenderObject(), mipmapLevel);
+    AttachDepthTextureToFrameBuffer(mEventThreadServices.GetUpdateManager(), *mRenderObject, texture->GetRenderTextureKey().Get(), mipmapLevel);
   }
 }
 
@@ -103,7 +103,7 @@ void FrameBuffer::AttachDepthStencilTexture(TexturePtr texture, unsigned int mip
   else
   {
     mStencil = texture;
-    AttachDepthStencilTextureToFrameBuffer(mEventThreadServices.GetUpdateManager(), *mRenderObject, texture->GetRenderObject(), mipmapLevel);
+    AttachDepthStencilTextureToFrameBuffer(mEventThreadServices.GetUpdateManager(), *mRenderObject, texture->GetRenderTextureKey().Get(), mipmapLevel);
   }
 }
 
index d386150..3a0fd17 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.
@@ -47,14 +47,14 @@ TexturePtr Texture::New(NativeImageInterface& nativeImageInterface)
   return texture;
 }
 
-Render::Texture* Texture::GetRenderObject() const
+Render::TextureKey Texture::GetRenderTextureKey() const
 {
-  return mRenderObject;
+  return mTextureKey;
 }
 
 Texture::Texture(TextureType::Type type, Pixel::Format format, ImageDimensions size)
 : mEventThreadServices(EventThreadServices::Get()),
-  mRenderObject(nullptr),
+  mTextureKey{},
   mNativeImage(),
   mSize(size),
   mType(type),
@@ -64,7 +64,7 @@ Texture::Texture(TextureType::Type type, Pixel::Format format, ImageDimensions s
 
 Texture::Texture(NativeImageInterfacePtr nativeImageInterface)
 : mEventThreadServices(EventThreadServices::Get()),
-  mRenderObject(nullptr),
+  mTextureKey{},
   mNativeImage(nativeImageInterface),
   mSize(nativeImageInterface->GetWidth(), nativeImageInterface->GetHeight()),
   mType(TextureType::TEXTURE_2D),
@@ -78,23 +78,22 @@ void Texture::Initialize()
   {
     if(mNativeImage)
     {
-      mRenderObject = new Render::Texture(mNativeImage);
+      mTextureKey = Render::Texture::NewKey(mNativeImage);
     }
     else
     {
-      mRenderObject = new Render::Texture(mType, mFormat, mSize);
+      mTextureKey = Render::Texture::NewKey(mType, mFormat, mSize);
     }
 
-    OwnerPointer<Render::Texture> transferOwnership(mRenderObject);
-    AddTexture(mEventThreadServices.GetUpdateManager(), transferOwnership);
+    AddTextureMessage(mEventThreadServices.GetUpdateManager(), mTextureKey);
   }
 }
 
 Texture::~Texture()
 {
-  if(EventThreadServices::IsCoreRunning() && mRenderObject)
+  if(EventThreadServices::IsCoreRunning() && mTextureKey)
   {
-    RemoveTexture(mEventThreadServices.GetUpdateManager(), *mRenderObject);
+    RemoveTextureMessage(mEventThreadServices.GetUpdateManager(), mTextureKey);
   }
 }
 
@@ -147,7 +146,7 @@ bool Texture::UploadSubPixelData(PixelDataPtr pixelData,
                      "Parameter value out of range");
 
   bool result(false);
-  if(EventThreadServices::IsCoreRunning() && mRenderObject)
+  if(EventThreadServices::IsCoreRunning() && mTextureKey)
   {
     if(mNativeImage)
     {
@@ -200,7 +199,7 @@ bool Texture::UploadSubPixelData(PixelDataPtr pixelData,
                                    static_cast<uint16_t>(yOffset),
                                    static_cast<uint16_t>(width),
                                    static_cast<uint16_t>(height)};
-            UploadTextureMessage(mEventThreadServices.GetUpdateManager(), *mRenderObject, pixelData, params);
+            UploadTextureMessage(mEventThreadServices.GetUpdateManager(), mTextureKey, pixelData, params);
 
             // Request event processing and update forcely
             mEventThreadServices.GetRenderController().RequestProcessEventsOnIdle(true);
@@ -222,9 +221,9 @@ bool Texture::UploadSubPixelData(PixelDataPtr pixelData,
 
 void Texture::GenerateMipmaps()
 {
-  if(EventThreadServices::IsCoreRunning() && mRenderObject)
+  if(EventThreadServices::IsCoreRunning() && mTextureKey)
   {
-    GenerateMipmapsMessage(mEventThreadServices.GetUpdateManager(), *mRenderObject);
+    GenerateMipmapsMessage(mEventThreadServices.GetUpdateManager(), mTextureKey);
   }
 }
 
index c00e663..3f6166b 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_NEW_TEXTURE_H
 
 /*
- * 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.
@@ -21,6 +21,7 @@
 // INTERNAL INCLUDES
 #include <dali/internal/event/common/event-thread-services.h>
 #include <dali/internal/event/images/pixel-data-impl.h>
+#include <dali/internal/render/renderers/render-texture-key.h>
 #include <dali/public-api/common/dali-common.h>      // DALI_ASSERT_ALWAYS
 #include <dali/public-api/common/intrusive-ptr.h>    // Dali::IntrusivePtr
 #include <dali/public-api/images/image-operations.h> // Dali::ImageDimensions
@@ -32,11 +33,6 @@ namespace Dali
 {
 namespace Internal
 {
-namespace Render
-{
-class Texture;
-}
-
 class Texture;
 using TexturePtr = IntrusivePtr<Texture>;
 
@@ -83,7 +79,7 @@ public:
    *
    * @return the texture render object
    */
-  Render::Texture* GetRenderObject() const;
+  Render::TextureKey GetRenderTextureKey() const;
 
   /**
    * @copydoc Dali::Texture::Upload()
@@ -192,7 +188,7 @@ private: // unimplemented methods
 
 private:                                               // data
   Internal::EventThreadServices& mEventThreadServices; ///<Used to send messages to the render thread via update thread
-  Internal::Render::Texture*     mRenderObject;        ///<The Render::Texture associated to this texture
+  Internal::Render::TextureKey   mTextureKey;          ///<The Render::Texture associated to this texture
 
   NativeImageInterfacePtr mNativeImage; ///< Pointer to native image
   ImageDimensions         mSize;        ///< Size of the texture
index f7b4ab0..43ce456 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.
@@ -61,10 +61,10 @@ void TextureSet::SetTexture(uint32_t index, TexturePtr texture)
 
   mTextures[index] = texture;
 
-  Render::Texture* renderTexture(nullptr);
+  Render::TextureKey renderTexture{};
   if(texture)
   {
-    renderTexture = texture->GetRenderObject();
+    renderTexture = texture->GetRenderTextureKey();
   }
 
   SceneGraph::SetTextureMessage(mEventThreadServices, *mSceneObject, index, renderTexture);
index 6621c8c..720eec1 100644 (file)
@@ -26,8 +26,8 @@
 #include <dali/public-api/math/rect.h>
 
 #include <dali/graphics-api/graphics-controller.h>
+#include <dali/internal/common/owner-key-container.h>
 #include <dali/internal/render/common/render-item.h>
-#include <dali/internal/update/manager/owner-key-container.h>
 
 namespace Dali
 {
index ba07eac..715c3e0 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.
@@ -31,6 +31,8 @@
 #include <dali/internal/update/nodes/scene-graph-layer.h>
 #include <dali/internal/update/render-tasks/scene-graph-camera.h>
 
+#include <dali/internal/common/owner-key-container.h>
+
 #include <dali/internal/render/common/render-algorithms.h>
 #include <dali/internal/render/common/render-debug.h>
 #include <dali/internal/render/common/render-instruction.h>
@@ -107,15 +109,7 @@ struct RenderManager::Impl
        Integration::StencilBufferAvailable stencilBufferAvailableParam,
        Integration::PartialUpdateAvailable partialUpdateAvailableParam)
   : graphicsController(graphicsController),
-    renderQueue(),
     renderAlgorithms(graphicsController),
-    frameCount(0u),
-    renderBufferIndex(SceneGraphBuffers::INITIAL_UPDATE_BUFFER_INDEX),
-    rendererContainer(),
-    samplerContainer(),
-    textureContainer(),
-    frameBufferContainer(),
-    lastFrameWasRendered(false),
     programController(graphicsController),
     shaderCache(graphicsController),
     depthBufferAvailable(depthBufferAvailableParam),
@@ -155,26 +149,18 @@ struct RenderManager::Impl
   }
 
   // the order is important for destruction,
-  Graphics::Controller& graphicsController;
-  RenderQueue           renderQueue; ///< A message queue for receiving messages from the update-thread.
-
-  std::vector<SceneGraph::Scene*> sceneContainer; ///< List of pointers to the scene graph objects of the scenes
-
-  Render::RenderAlgorithms renderAlgorithms; ///< The RenderAlgorithms object is used to action the renders required by a RenderInstruction
-
-  uint32_t    frameCount;        ///< The current frame count
-  BufferIndex renderBufferIndex; ///< The index of the buffer to read from; this is opposite of the "update" buffer
-
-  OwnerContainer<Render::Renderer*>     rendererContainer;     ///< List of owned renderers
-  OwnerContainer<Render::Sampler*>      samplerContainer;      ///< List of owned samplers
-  OwnerContainer<Render::Texture*>      textureContainer;      ///< List of owned textures
-  OwnerContainer<Render::FrameBuffer*>  frameBufferContainer;  ///< List of owned framebuffers
-  OwnerContainer<Render::VertexBuffer*> vertexBufferContainer; ///< List of owned vertex buffers
-  OwnerContainer<Render::Geometry*>     geometryContainer;     ///< List of owned Geometries
-
-  bool lastFrameWasRendered; ///< Keeps track of the last frame being rendered due to having render instructions
-
-  OwnerContainer<Render::RenderTracker*> mRenderTrackers; ///< List of render trackers
+  Graphics::Controller&           graphicsController;
+  RenderQueue                     renderQueue;      ///< A message queue for receiving messages from the update-thread.
+  std::vector<SceneGraph::Scene*> sceneContainer;   ///< List of pointers to the scene graph objects of the scenes
+  Render::RenderAlgorithms        renderAlgorithms; ///< The RenderAlgorithms object is used to action the renders required by a RenderInstruction
+
+  OwnerContainer<Render::Renderer*>      rendererContainer;     ///< List of owned renderers
+  OwnerContainer<Render::Sampler*>       samplerContainer;      ///< List of owned samplers
+  OwnerContainer<Render::FrameBuffer*>   frameBufferContainer;  ///< List of owned framebuffers
+  OwnerContainer<Render::VertexBuffer*>  vertexBufferContainer; ///< List of owned vertex buffers
+  OwnerContainer<Render::Geometry*>      geometryContainer;     ///< List of owned Geometries
+  OwnerContainer<Render::RenderTracker*> mRenderTrackers;       ///< List of render trackers
+  OwnerKeyContainer<Render::Texture>     textureContainer;      ///< List of owned textures
 
   ProgramController   programController; ///< Owner of the programs
   Render::ShaderCache shaderCache;       ///< The cache for the graphics shaders
@@ -190,6 +176,10 @@ struct RenderManager::Impl
   Vector<Graphics::Texture*>        boundTextures;         ///< The textures bound for rendering
   Vector<Graphics::Texture*>        textureDependencyList; ///< The dependency list of bound textures
 
+  uint32_t    frameCount{0u};                                                    ///< The current frame count
+  BufferIndex renderBufferIndex{SceneGraphBuffers::INITIAL_UPDATE_BUFFER_INDEX}; ///< The index of the buffer to read from; this is opposite of the "update" buffer
+
+  bool lastFrameWasRendered{false}; ///< Keeps track of the last frame being rendered due to having render instructions
   bool commandBufferSubmitted{false};
 };
 
@@ -249,34 +239,38 @@ void RenderManager::RemoveSampler(Render::Sampler* sampler)
   mImpl->samplerContainer.EraseObject(sampler);
 }
 
-void RenderManager::AddTexture(OwnerPointer<Render::Texture>& texture)
+void RenderManager::AddTexture(const Render::TextureKey& textureKey)
 {
-  texture->Initialize(mImpl->graphicsController);
-  mImpl->textureContainer.PushBack(texture.Release());
+  DALI_ASSERT_DEBUG(textureKey && "Trying to add empty texture key");
+
+  textureKey->Initialize(mImpl->graphicsController);
+  mImpl->textureContainer.PushBack(textureKey);
 }
 
-void RenderManager::RemoveTexture(Render::Texture* texture)
+void RenderManager::RemoveTexture(const Render::TextureKey& textureKey)
 {
-  DALI_ASSERT_DEBUG(NULL != texture);
+  DALI_ASSERT_DEBUG(textureKey && "Trying to remove empty texture key");
 
   // Find the texture, use std::find so we can do the erase safely
-  auto iter = std::find(mImpl->textureContainer.begin(), mImpl->textureContainer.end(), texture);
+  auto iter = std::find(mImpl->textureContainer.begin(), mImpl->textureContainer.end(), textureKey);
 
   if(iter != mImpl->textureContainer.end())
   {
-    texture->Destroy();
+    textureKey->Destroy();
     mImpl->textureContainer.Erase(iter); // Texture found; now destroy it
   }
 }
 
-void RenderManager::UploadTexture(Render::Texture* texture, PixelDataPtr pixelData, const Texture::UploadParams& params)
+void RenderManager::UploadTexture(const Render::TextureKey& textureKey, PixelDataPtr pixelData, const Texture::UploadParams& params)
 {
-  texture->Upload(pixelData, params);
+  DALI_ASSERT_DEBUG(textureKey && "Trying to upload to empty texture key");
+  textureKey->Upload(pixelData, params);
 }
 
-void RenderManager::GenerateMipmaps(Render::Texture* texture)
+void RenderManager::GenerateMipmaps(const Render::TextureKey& textureKey)
 {
-  texture->GenerateMipmaps();
+  DALI_ASSERT_DEBUG(textureKey && "Trying to generate mipmaps on empty texture key");
+  textureKey->GenerateMipmaps();
 }
 
 void RenderManager::SetFilterMode(Render::Sampler* sampler, uint32_t minFilterMode, uint32_t magFilterMode)
index 3a5c231..5b49aeb 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H
 
 /*
- * 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.
@@ -223,13 +223,13 @@ public:
    * Adds a texture to the render manager
    * @param[in] texture The texture to add
    */
-  void AddTexture(OwnerPointer<Render::Texture>& texture);
+  void AddTexture(const Render::TextureKey& texture);
 
   /**
    * Removes a texture from the render manager
    * @param[in] texture The texture to remove
    */
-  void RemoveTexture(Render::Texture* texture);
+  void RemoveTexture(const Render::TextureKey& texture);
 
   /**
    * Uploads data to an existing texture
@@ -237,13 +237,13 @@ public:
    * @param[in] pixelData The pixel data object
    * @param[in] params The parameters for the upload
    */
-  void UploadTexture(Render::Texture* texture, PixelDataPtr pixelData, const Texture::UploadParams& params);
+  void UploadTexture(const Render::TextureKey& texture, PixelDataPtr pixelData, const Texture::UploadParams& params);
 
   /**
    * Generates mipmaps for a given texture
    * @param[in] texture The texture
    */
-  void GenerateMipmaps(Render::Texture* texture);
+  void GenerateMipmaps(const Render::TextureKey& texture);
 
   /**
    * Adds a framebuffer to the render manager
index 3c015b8..06d9e9b 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_SCENE_GRAPH_RENDER_DATA_PROVIDER_H
 
 /*
- * 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.
@@ -19,6 +19,7 @@
  */
 
 #include <dali/internal/render/data-providers/uniform-map-data-provider.h>
+#include <dali/internal/render/renderers/render-texture-key.h>
 #include <dali/public-api/common/dali-vector.h>
 
 namespace Dali
@@ -75,7 +76,7 @@ public:
    * Returns the list of Textures
    * @return The list of Textures
    */
-  virtual const Dali::Vector<Render::Texture*>* GetTextures() const = 0;
+  virtual const Dali::Vector<Render::TextureKey>* GetTextures() const = 0;
 
   /**
    * Get the opacity
index db30a4e..d9a0351 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.
@@ -221,8 +221,8 @@ void Renderer::BindTextures(Graphics::CommandBuffer& commandBuffer, Vector<Graph
 {
   uint32_t textureUnit = 0;
 
-  const Dali::Vector<Render::Texture*>* textures(mRenderDataProvider->GetTextures());
-  const Dali::Vector<Render::Sampler*>* samplers(mRenderDataProvider->GetSamplers());
+  auto textures(mRenderDataProvider->GetTextures());
+  auto samplers(mRenderDataProvider->GetSamplers());
 
   std::vector<Graphics::TextureBinding> textureBindings;
 
@@ -450,7 +450,7 @@ bool Renderer::Render(Graphics::CommandBuffer&                             comma
       for(auto& texture : textureResources)
       {
         auto& textureImpl     = GetImplementation(texture);
-        auto  graphicsTexture = textureImpl.GetRenderObject()->GetGraphicsObject();
+        auto  graphicsTexture = textureImpl.GetRenderTextureKey()->GetGraphicsObject();
 
         auto properties = mGraphicsController->GetTextureProperties(*graphicsTexture);
 
diff --git a/dali/internal/render/renderers/render-texture-key.h b/dali/internal/render/renderers/render-texture-key.h
new file mode 100644 (file)
index 0000000..97a64be
--- /dev/null
@@ -0,0 +1,41 @@
+#ifndef DALI_INTERNAL_RENDER_RENDER_TEXTURE_KEY_H
+#define DALI_INTERNAL_RENDER_RENDER_TEXTURE_KEY_H
+
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <dali/internal/common/memory-pool-key.h>
+
+namespace Dali
+{
+namespace Internal::Render
+{
+class Texture;
+using TextureKey = MemoryPoolKey<Texture>;
+} // namespace Internal::Render
+
+template<>
+struct TypeTraits<Internal::Render::TextureKey> : public BasicTypes<Internal::Render::TextureKey>
+{
+  enum
+  {
+    IS_TRIVIAL_TYPE = true
+  };
+};
+
+} // namespace Dali
+
+#endif //DALI_INTERNAL_RENDER_RENDER_TEXTURE_KEY_H
index 086a9f2..2a455fd 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.
@@ -22,6 +22,7 @@
 
 // INTERNAL INCLUDES
 #include <dali/integration-api/debug.h>
+#include <dali/internal/common/memory-pool-object-allocator.h>
 
 namespace Dali
 {
@@ -35,6 +36,9 @@ namespace
 Debug::Filter* gTextureFilter = Debug::Filter::New(Debug::Concise, false, "LOG_TEXTURE");
 #endif
 
+// Memory pool used to allocate new textures. Memory used by this pool will be released when shutting down DALi
+MemoryPoolObjectAllocator<Texture> gTextureMemoryPool;
+
 /**
  * Converts DALi pixel format to Graphics::Format
  * @param format
@@ -205,6 +209,24 @@ constexpr Graphics::TextureType ConvertType(Texture::Type type)
 
 } //Unnamed namespace
 
+TextureKey Texture::NewKey(Type type, Pixel::Format format, ImageDimensions size)
+{
+  void* ptr = gTextureMemoryPool.AllocateRawThreadSafe();
+  auto  key = gTextureMemoryPool.GetKeyFromPtr(static_cast<Texture*>(ptr));
+  new(ptr) Texture(type, format, size);
+
+  return TextureKey(key);
+}
+
+TextureKey Texture::NewKey(NativeImageInterfacePtr nativeImageInterface)
+{
+  void* ptr = gTextureMemoryPool.AllocateRawThreadSafe();
+  auto  key = gTextureMemoryPool.GetKeyFromPtr(static_cast<Texture*>(ptr));
+  new(ptr) Texture(nativeImageInterface);
+
+  return TextureKey(key);
+}
+
 Texture::Texture(Type type, Pixel::Format format, ImageDimensions size)
 : mGraphicsController(nullptr),
   mGraphicsTexture(nullptr),
@@ -235,6 +257,16 @@ Texture::Texture(NativeImageInterfacePtr nativeImageInterface)
 
 Texture::~Texture() = default;
 
+void Texture::operator delete(void* ptr)
+{
+  gTextureMemoryPool.FreeThreadSafe(static_cast<Texture*>(ptr));
+}
+
+Render::Texture* Texture::Get(TextureKey::KeyType key)
+{
+  return gTextureMemoryPool.GetPtrFromKey(key);
+}
+
 void Texture::Initialize(Graphics::Controller& graphicsController)
 {
   mGraphicsController = &graphicsController;
index dffbff9..c7a0ff7 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_RENDER_TEXTURE_H
 
 /*
- * 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.
@@ -47,6 +47,16 @@ public:
   using Type = Dali::TextureType::Type;
 
   /**
+   * Factory method to return a new texture accessed by key.
+   */
+  static TextureKey NewKey(Type type, Pixel::Format format, ImageDimensions size);
+
+  /**
+   * Factory method to return a new texture accessed by key.
+   */
+  static TextureKey NewKey(NativeImageInterfacePtr nativeImageInterface);
+
+  /**
    * Constructor
    * @param[in] type The type of the texture
    * @param[in] format The format of the pixel data
@@ -66,6 +76,28 @@ public:
   ~Texture();
 
   /**
+   * Deletes the texture from it's global memory pool
+   */
+  void operator delete(void* ptr);
+
+  static Texture* Get(TextureKey::KeyType);
+
+  /**
+   * Get the key of the given renderer in the associated memory pool.
+   * @param[in] renderer the given renderer
+   * @return The key in the associated memory pool.
+   */
+  static TextureKey GetKey(const Render::Texture& renderer);
+
+  /**
+   * Get the key of the given renderer in the associated memory pool.
+   * @param[in] renderer the given renderer
+   * @return The key in the associated memory pool, or -1 if not
+   * found.
+   */
+  static TextureKey GetKey(Render::Texture* renderer);
+
+  /**
    * Stores the graphics controller for use when required.
    *
    * @param[in] graphicsController The graphics controller to use
index 5294e0a..c9060d2 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.
@@ -21,6 +21,8 @@
 // INTERNAL INCLUDES
 #include <dali/integration-api/core.h>
 
+#include <dali/internal/common/owner-key-container.h>
+
 #include <dali/internal/event/animation/animation-playlist.h>
 #include <dali/internal/event/common/notification-manager.h>
 #include <dali/internal/event/common/property-notifier.h>
@@ -30,7 +32,6 @@
 #include <dali/internal/update/controllers/render-message-dispatcher.h>
 #include <dali/internal/update/controllers/scene-controller-impl.h>
 #include <dali/internal/update/manager/frame-callback-processor.h>
-#include <dali/internal/update/manager/owner-key-container.h>
 #include <dali/internal/update/manager/render-task-processor.h>
 #include <dali/internal/update/manager/transform-manager.h>
 #include <dali/internal/update/manager/update-algorithms.h>
@@ -136,8 +137,7 @@ inline void EraseUsingDiscardQueue(OwnerKeyContainer<Type>& container, const Mem
 void SortSiblingNodesRecursively(Node& node)
 {
   NodeContainer& container = node.GetChildren();
-  std::sort(container.Begin(), container.End(), [](Node* a, Node* b)
-            { return a->GetDepthIndex() < b->GetDepthIndex(); });
+  std::sort(container.Begin(), container.End(), [](Node* a, Node* b) { return a->GetDepthIndex() < b->GetDepthIndex(); });
 
   // Descend tree and sort as well
   for(auto&& iter : container)
@@ -161,11 +161,11 @@ struct UpdateManager::Impl
     {
     }
 
-    ~SceneInfo()                               = default; ///< Default non-virtual destructor
-    SceneInfo(SceneInfo&& rhs)                 = default; ///< Move constructor
-    SceneInfo& operator=(SceneInfo&& rhs)      = default; ///< Move assignment operator
-    SceneInfo& operator=(const SceneInfo& rhs) = delete;  ///< Assignment operator
-    SceneInfo(const SceneInfo& rhs)            = delete;  ///< Copy constructor
+    ~SceneInfo()               = default;                ///< Default non-virtual destructor
+    SceneInfo(SceneInfo&& rhs) = default;                ///< Move constructor
+    SceneInfo& operator=(SceneInfo&& rhs) = default;     ///< Move assignment operator
+    SceneInfo& operator=(const SceneInfo& rhs) = delete; ///< Assignment operator
+    SceneInfo(const SceneInfo& rhs)            = delete; ///< Copy constructor
 
     Layer*                       root{nullptr};   ///< Root node (root is a layer). The layer is not stored in the node memory pool.
     OwnerPointer<RenderTaskList> taskList;        ///< Scene graph render task list
@@ -364,8 +364,7 @@ void UpdateManager::InstallRoot(OwnerPointer<Layer>& layer)
 
   Layer* rootLayer = layer.Release();
 
-  DALI_ASSERT_DEBUG(std::find_if(mImpl->scenes.begin(), mImpl->scenes.end(), [rootLayer](Impl::SceneInfoPtr& scene)
-                                 { return scene && scene->root == rootLayer; }) == mImpl->scenes.end() &&
+  DALI_ASSERT_DEBUG(std::find_if(mImpl->scenes.begin(), mImpl->scenes.end(), [rootLayer](Impl::SceneInfoPtr& scene) { return scene && scene->root == rootLayer; }) == mImpl->scenes.end() &&
                     "Root Node already installed");
 
   rootLayer->CreateTransform(&mImpl->transformManager);
@@ -1465,10 +1464,9 @@ void UpdateManager::AttachVertexBuffer(Render::Geometry* geometry, Render::Verte
   new(slot) DerivedType(&mImpl->renderManager, &RenderManager::AttachVertexBuffer, geometry, vertexBuffer);
 }
 
-void UpdateManager::AddTexture(OwnerPointer<Render::Texture>& texture)
+void UpdateManager::AddTexture(const Render::TextureKey& texture)
 {
-  // Message has ownership of Texture while in transit from update -> render
-  using DerivedType = MessageValue1<RenderManager, OwnerPointer<Render::Texture>>;
+  using DerivedType = MessageValue1<RenderManager, Render::TextureKey>;
 
   // Reserve some memory inside the render queue
   uint32_t* slot = mImpl->renderQueue.ReserveMessageSlot(mSceneGraphBuffers.GetUpdateBufferIndex(), sizeof(DerivedType));
@@ -1477,9 +1475,9 @@ void UpdateManager::AddTexture(OwnerPointer<Render::Texture>& texture)
   new(slot) DerivedType(&mImpl->renderManager, &RenderManager::AddTexture, texture);
 }
 
-void UpdateManager::RemoveTexture(Render::Texture* texture)
+void UpdateManager::RemoveTexture(const Render::TextureKey& texture)
 {
-  using DerivedType = MessageValue1<RenderManager, Render::Texture*>;
+  using DerivedType = MessageValue1<RenderManager, Render::TextureKey>;
 
   // Reserve some memory inside the render queue
   uint32_t* slot = mImpl->renderQueue.ReserveMessageSlot(mSceneGraphBuffers.GetUpdateBufferIndex(), sizeof(DerivedType));
@@ -1488,9 +1486,9 @@ void UpdateManager::RemoveTexture(Render::Texture* texture)
   new(slot) DerivedType(&mImpl->renderManager, &RenderManager::RemoveTexture, texture);
 }
 
-void UpdateManager::UploadTexture(Render::Texture* texture, PixelDataPtr pixelData, const Texture::UploadParams& params)
+void UpdateManager::UploadTexture(const Render::TextureKey& texture, PixelDataPtr pixelData, const Texture::UploadParams& params)
 {
-  using DerivedType = MessageValue3<RenderManager, Render::Texture*, PixelDataPtr, Texture::UploadParams>;
+  using DerivedType = MessageValue3<RenderManager, Render::TextureKey, PixelDataPtr, Texture::UploadParams>;
 
   // Reserve some memory inside the message queue
   uint32_t* slot = mImpl->renderQueue.ReserveMessageSlot(mSceneGraphBuffers.GetUpdateBufferIndex(), sizeof(DerivedType));
@@ -1499,9 +1497,9 @@ void UpdateManager::UploadTexture(Render::Texture* texture, PixelDataPtr pixelDa
   new(slot) DerivedType(&mImpl->renderManager, &RenderManager::UploadTexture, texture, pixelData, params);
 }
 
-void UpdateManager::GenerateMipmaps(Render::Texture* texture)
+void UpdateManager::GenerateMipmaps(const Render::TextureKey& texture)
 {
-  using DerivedType = MessageValue1<RenderManager, Render::Texture*>;
+  using DerivedType = MessageValue1<RenderManager, Render::TextureKey>;
 
   // Reserve some memory inside the render queue
   uint32_t* slot = mImpl->renderQueue.ReserveMessageSlot(mSceneGraphBuffers.GetUpdateBufferIndex(), sizeof(DerivedType));
index 3cb78b5..ee5cf87 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_SCENE_GRAPH_UPDATE_MANAGER_H
 
 /*
- * 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.
@@ -29,7 +29,8 @@
 #include <dali/internal/common/type-abstraction-enums.h>
 #include <dali/internal/event/common/event-thread-services.h>
 #include <dali/internal/event/rendering/texture-impl.h>
-#include <dali/internal/render/renderers/render-texture.h> // For OwnerPointer<Render::Texture>
+#include <dali/internal/render/renderers/render-texture-key.h> // For RenderTextureKey
+#include <dali/internal/render/renderers/render-texture.h>     // For OwnerPointer<Render::Texture>
 #include <dali/internal/render/renderers/render-vertex-buffer.h>
 #include <dali/internal/render/shaders/render-shader.h> // for OwnerPointer< Shader >
 #include <dali/internal/update/animation/scene-graph-animation.h>
@@ -518,14 +519,14 @@ public:
    * @param[in] texture The texture to add
    * The texture will be owned by RenderManager
    */
-  void AddTexture(OwnerPointer<Render::Texture>& texture);
+  void AddTexture(const Render::TextureKey& texture);
 
   /**
    * Removes a texture from the render manager
    * @param[in] texture The texture to remove
    * @post The texture will be destroyed in the render thread
    */
-  void RemoveTexture(Render::Texture* texture);
+  void RemoveTexture(const Render::TextureKey& texture);
 
   /**
    * Uploads data to a texture owned by the RenderManager
@@ -533,13 +534,13 @@ public:
    * @param[in] pixelData The pixel data object
    * @param[in] params The parameters for the upload
    */
-  void UploadTexture(Render::Texture* texture, PixelDataPtr pixelData, const Texture::UploadParams& params);
+  void UploadTexture(const Render::TextureKey& texture, PixelDataPtr pixelData, const Texture::UploadParams& params);
 
   /**
    * Generates mipmaps for a texture owned by the RenderManager
    * @param[in] texture The texture
    */
-  void GenerateMipmaps(Render::Texture* texture);
+  void GenerateMipmaps(const Render::TextureKey& texture);
 
   /**
    * Adds a framebuffer to the render manager
@@ -1353,10 +1354,9 @@ inline void SetGeometryTypeMessage(UpdateManager& manager, Render::Geometry& geo
   new(slot) LocalType(&manager, &UpdateManager::SetGeometryType, &geometry, geometryType);
 }
 
-inline void AddTexture(UpdateManager& manager, OwnerPointer<Render::Texture>& texture)
+inline void AddTextureMessage(UpdateManager& manager, const Render::TextureKey& texture)
 {
-  // Message has ownership of Texture while in transit from event -> update
-  using LocalType = MessageValue1<UpdateManager, OwnerPointer<Render::Texture>>;
+  using LocalType = MessageValue1<UpdateManager, Render::TextureKey>;
 
   // Reserve some memory inside the message queue
   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
@@ -1365,37 +1365,37 @@ inline void AddTexture(UpdateManager& manager, OwnerPointer<Render::Texture>& te
   new(slot) LocalType(&manager, &UpdateManager::AddTexture, texture);
 }
 
-inline void RemoveTexture(UpdateManager& manager, Render::Texture& texture)
+inline void RemoveTextureMessage(UpdateManager& manager, const Render::TextureKey& texture)
 {
-  using LocalType = MessageValue1<UpdateManager, Render::Texture*>;
+  using LocalType = MessageValue1<UpdateManager, Render::TextureKey>;
 
   // Reserve some memory inside the message queue
   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
 
   // Construct message in the message queue memory; note that delete should not be called on the return value
-  new(slot) LocalType(&manager, &UpdateManager::RemoveTexture, &texture);
+  new(slot) LocalType(&manager, &UpdateManager::RemoveTexture, texture);
 }
 
-inline void UploadTextureMessage(UpdateManager& manager, Render::Texture& texture, PixelDataPtr pixelData, const Texture::UploadParams& params)
+inline void UploadTextureMessage(UpdateManager& manager, Render::TextureKey texture, PixelDataPtr pixelData, const Texture::UploadParams& params)
 {
-  using LocalType = MessageValue3<UpdateManager, Render::Texture*, PixelDataPtr, Texture::UploadParams>;
+  using LocalType = MessageValue3<UpdateManager, Render::TextureKey, PixelDataPtr, Texture::UploadParams>;
 
   // Reserve some memory inside the message queue
   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
 
   // Construct message in the message queue memory; note that delete should not be called on the return value
-  new(slot) LocalType(&manager, &UpdateManager::UploadTexture, &texture, pixelData, params);
+  new(slot) LocalType(&manager, &UpdateManager::UploadTexture, texture, pixelData, params);
 }
 
-inline void GenerateMipmapsMessage(UpdateManager& manager, Render::Texture& texture)
+inline void GenerateMipmapsMessage(UpdateManager& manager, Render::TextureKey texture)
 {
-  using LocalType = MessageValue1<UpdateManager, Render::Texture*>;
+  using LocalType = MessageValue1<UpdateManager, Render::TextureKey>;
 
   // Reserve some memory inside the message queue
   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
 
   // Construct message in the message queue memory; note that delete should not be called on the return value
-  new(slot) LocalType(&manager, &UpdateManager::GenerateMipmaps, &texture);
+  new(slot) LocalType(&manager, &UpdateManager::GenerateMipmaps, texture);
 }
 
 inline void AddFrameBuffer(UpdateManager& manager, OwnerPointer<Render::FrameBuffer>& frameBuffer)
index ce0d718..e5a2f05 100644 (file)
@@ -338,7 +338,7 @@ void Renderer::SetTextures(TextureSet* textureSet)
   SetUpdated(true);
 }
 
-const Vector<Render::Texture*>* Renderer::GetTextures() const
+const Vector<Render::TextureKey>* Renderer::GetTextures() const
 {
   return mTextureSet ? &(mTextureSet->GetTextures()) : nullptr;
 }
index c1796c3..84243ca 100644 (file)
@@ -67,7 +67,6 @@ namespace Internal
 {
 namespace SceneGraph
 {
-
 using RendererContainer = Dali::Vector<RendererKey>;
 using RendererIter      = RendererContainer::Iterator;
 using RendererConstIter = RendererContainer::ConstIterator;
@@ -224,7 +223,7 @@ public:
   /**
    * @copydoc RenderDataProvider::GetTextures()
    */
-  const Vector<Render::Texture*>* GetTextures() const override;
+  const Vector<Render::TextureKey>* GetTextures() const override;
 
   /**
    * @copydoc RenderDataProvider::GetSamplers()
index 1e95d3b..2008805 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.
@@ -75,7 +75,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 +91,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)
       {
index 5e00716..8f58ce2 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_SCENE_GRAPH_TEXTURE_SET_H
 
 /*
- * 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.
  */
 
 // INTERNAL INCLUDES
+#include <dali/public-api/rendering/texture-set.h>
+
 #include <dali/internal/common/buffer-index.h>
 #include <dali/internal/common/message.h>
 #include <dali/internal/event/common/event-thread-services.h>
-#include <dali/public-api/rendering/texture-set.h>
+#include <dali/internal/render/renderers/render-texture-key.h>
 
 namespace Dali
 {
@@ -67,7 +69,7 @@ public:
    * @param[in] index The index of the texture
    * @param[in] texture The texture
    */
-  void SetTexture(uint32_t index, Render::Texture* texture);
+  void SetTexture(uint32_t index, const Render::TextureKey& texture);
 
   /**
    * Return whether any texture in the texture set has an alpha channel
@@ -78,7 +80,7 @@ public:
   /**
    * Accessor for textures (used by RenderDataProvider impl)
    */
-  const Vector<Render::Texture*>& GetTextures()
+  const Vector<Render::TextureKey>& GetTextures()
   {
     return mTextures;
   }
@@ -103,21 +105,21 @@ private:
    */
   TextureSet();
 
-private:                              // Data
-  Vector<Render::Sampler*> mSamplers; ///< List of samplers used by each texture. Not owned
-  Vector<Render::Texture*> mTextures; ///< List of Textures. Not owned
-  bool                     mHasAlpha; ///< if any of the textures has an alpha channel
+private:
+  Vector<Render::Sampler*>   mSamplers; ///< List of samplers used by each texture. Not owned
+  Vector<Render::TextureKey> mTextures; ///< List of Textures. Not owned
+  bool                       mHasAlpha; ///< if any of the textures has an alpha channel
 };
 
-inline void SetTextureMessage(EventThreadServices& eventThreadServices, const TextureSet& textureSet, uint32_t index, Render::Texture* texture)
+inline void SetTextureMessage(EventThreadServices& eventThreadServices, const TextureSet& textureSet, uint32_t index, const Render::TextureKey& textureKey)
 {
-  using LocalType = MessageValue2<TextureSet, uint32_t, Render::Texture*>;
+  using LocalType = MessageValue2<TextureSet, uint32_t, Render::TextureKey>;
 
   // Reserve some memory inside the message queue
   uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
 
   // Construct message in the message queue memory; note that delete should not be called on the return value
-  new(slot) LocalType(&textureSet, &TextureSet::SetTexture, index, texture);
+  new(slot) LocalType(&textureSet, &TextureSet::SetTexture, index, textureKey);
 }
 
 inline void SetSamplerMessage(EventThreadServices& eventThreadServices, const TextureSet& textureSet, uint32_t index, Render::Sampler* sampler)