/*
- * Copyright (c) 2020 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::MemoryPoolObjectAllocator<MemoryPoolObjectAllocatorTestObject> allocator;
// Allocate an object
- MemoryPoolObjectAllocatorTestObject* testObject1 = allocator.Allocate();
+ void* ptr = allocator.AllocateRaw();
+ MemoryPoolObjectAllocatorTestObject* testObject1 = new(ptr) MemoryPoolObjectAllocatorTestObject();
DALI_TEST_CHECK(testObject1);
MemoryPoolObjectAllocatorTestObjectTracking tracking1;
// Reset and allocate another object
allocator.ResetMemoryPool();
- MemoryPoolObjectAllocatorTestObject* testObject2 = allocator.Allocate();
+ ptr = allocator.AllocateRaw();
+ MemoryPoolObjectAllocatorTestObject* testObject2 = new(ptr) MemoryPoolObjectAllocatorTestObject();
DALI_TEST_CHECK(testObject2);
MemoryPoolObjectAllocatorTestObjectTracking tracking2;
{
Internal::MemoryPoolObjectAllocator<bool> allocator;
- bool* testObject1 = allocator.Allocate();
+ void* ptr = allocator.AllocateRaw();
+ bool* testObject1 = new(ptr) bool();
DALI_TEST_CHECK(testObject1);
allocator.Destroy(testObject1);
allocator.ResetMemoryPool();
- bool* testObject2 = allocator.Allocate();
+ ptr = allocator.AllocateRaw();
+ bool* testObject2 = new(ptr) bool();
DALI_TEST_CHECK(testObject2);
allocator.Destroy(testObject2);
--- /dev/null
+#ifndef DALI_INTERNAL_SCENE_GRAPH_RENDER_ITEM_KEY_H
+#define DALI_INTERNAL_SCENE_GRAPH_RENDER_ITEM_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>
+#include <dali/internal/common/type-abstraction-enums.h>
+
+namespace Dali
+{
+namespace Internal::SceneGraph
+{
+struct RenderItem;
+
+using RenderItemKey = MemoryPoolKey<RenderItem>;
+} // namespace Internal::SceneGraph
+
+// Ensure RenderItemKey can be used in Dali::Vector
+template<>
+struct TypeTraits<Internal::SceneGraph::RenderItemKey> : public BasicTypes<Internal::SceneGraph::RenderItemKey>
+{
+ enum
+ {
+ IS_TRIVIAL_TYPE = true
+ };
+};
+
+} // namespace Dali
+
+#endif // DALI_INTERNAL_SCENE_GRAPH_RENDER_ITEM_KEY_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.
//Memory pool used to allocate new RenderItems. Memory used by this pool will be released when shutting down DALi
Dali::Internal::MemoryPoolObjectAllocator<Dali::Internal::SceneGraph::RenderItem> gRenderItemPool;
} // namespace
+
namespace Dali
{
namespace Internal
return new(gRenderItemPool.AllocateRaw()) RenderItem();
}
+RenderItemKey RenderItem::NewKey()
+{
+ void* ptr = gRenderItemPool.AllocateRaw();
+ auto key = gRenderItemPool.GetKeyFromPtr(static_cast<RenderItem*>(ptr));
+ new(ptr) RenderItem();
+ return RenderItemKey(key);
+}
+
RenderItem::RenderItem()
: mModelMatrix(false),
mModelViewMatrix(false),
RenderItem::~RenderItem() = default;
+RenderItem* RenderItem::Get(RenderItemKey::KeyType key)
+{
+ return gRenderItemPool.GetPtrFromKey(key);
+}
+
+RenderItemKey RenderItem::GetKey(const RenderItem& renderItem)
+{
+ return RenderItemKey(gRenderItemPool.GetKeyFromPtr(const_cast<RenderItem*>(&renderItem)));
+}
+
+RenderItemKey RenderItem::GetKey(RenderItem* renderItem)
+{
+ return RenderItemKey(gRenderItemPool.GetKeyFromPtr(renderItem));
+}
+
ClippingBox RenderItem::CalculateTransformSpaceAABB(const Matrix& transformMatrix, const Vector3& position, const Vector3& size)
{
// Calculate extent vector of the AABB:
#define DALI_INTERNAL_SCENE_GRAPH_RENDER_ITEM_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/internal/render/common/render-item-key.h>
#include <dali/internal/update/nodes/node.h>
#include <dali/public-api/actors/layer.h>
#include <dali/public-api/common/vector-wrapper.h>
static RenderItem* New();
/**
+ * Construct a new RenderItem
+ * @return A key to a new RenderItem
+ */
+ static RenderItemKey NewKey();
+
+ /**
* Non-virtual destructor; RenderItem is not suitable as a base class.
*/
~RenderItem();
/**
+ * Get a pointer to the given object in the associated memory pool.
+ * @param[in] key A key to the memory pool object
+ * @return a ptr to the given object, or nullptr if not found/invalid
+ */
+ static RenderItem* Get(RenderItemKey::KeyType key);
+
+ /**
+ * 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 RenderItemKey GetKey(const RenderItem& 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 RenderItemKey GetKey(RenderItem* renderer);
+
+ /**
* Produce a 2D AABB in transformed space
* See below for caveats.
*
RenderItem();
// RenderItems should not be copied as they are heavy
- RenderItem(const RenderItem& item);
- RenderItem& operator=(const RenderItem& item);
+ RenderItem(const RenderItem& item) = delete;
+ RenderItem& operator=(const RenderItem& item) = delete;
};
} // namespace SceneGraph
#define DALI_INTERNAL_SCENE_GRAPH_RENDER_LIST_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.
// INTERNAL INCLUDES
#include <dali/devel-api/common/owner-container.h>
+#include <dali/public-api/math/rect.h>
+
#include <dali/graphics-api/graphics-controller.h>
#include <dali/internal/render/common/render-item.h>
-#include <dali/public-api/math/rect.h>
+#include <dali/internal/update/manager/owner-key-container.h>
namespace Dali
{
{
class Layer;
-using RenderItemContainer = OwnerContainer<RenderItem*>;
+using RenderItemContainer = OwnerKeyContainer<RenderItem>;
struct RenderList;
using RenderListContainer = OwnerContainer<RenderList*>;
/**
- * The RenderList structure provides the renderer with a list of renderers.
+ * The RenderList structure provides the renderer manager with a list of renderers.
*/
struct RenderList
{
// check if we have enough items, we can only be one behind at worst
if(mItems.Count() <= mNextFree)
{
- mItems.PushBack(RenderItem::New()); // Push a new empty render item
+ mItems.PushBack(RenderItem::NewKey()); // Push a new empty render item
}
// get the item mNextFree points to and increase by one
- RenderItem& item = *mItems[mNextFree++];
- return item;
+ RenderItem* item = mItems[mNextFree++].Get();
+ return *item;
}
/**
RenderItem& GetItem(uint32_t index) const
{
DALI_ASSERT_DEBUG(index < GetCachedItemCount());
- return *mItems[index];
+ RenderItem* item = mItems[index].Get();
+ return *item;
+ }
+
+ RenderItemKey GetItemKey(uint32_t index) const
+ {
+ DALI_ASSERT_DEBUG(index < GetCachedItemCount());
+ return mItems[index];
}
/**
}
private:
- RenderItemContainer mItems; ///< Each item is a renderer and matrix pair
+ RenderItemContainer mItems; ///< Container of render items
uint32_t mNextFree; ///< index for the next free item to use
mutable Graphics::UniquePtr<Graphics::CommandBuffer> mGraphicsCommandBuffer{nullptr};
/*
- * 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.
// List of zValue calculating functions.
const Dali::Layer::SortFunctionType zValueFunctionFromVector3[] = {
- [](const Vector3& position)
- { return position.z; },
- [](const Vector3& position)
- { return position.LengthSquared(); },
+ [](const Vector3& position) { return position.z; },
+ [](const Vector3& position) { return position.LengthSquared(); },
layer.GetSortFunction(),
};
for(uint32_t index = 0; index < renderableCount; ++index)
{
- RenderItem& item = renderList.GetItem(index);
-
+ RenderItemKey itemKey = renderList.GetItemKey(index);
+ RenderItem& item = *itemKey.Get();
if(DALI_LIKELY(item.mRenderer))
{
item.mRenderer->SetSortAttributes(mSortingHelper[index]);
mSortingHelper[index].zValue = zValueFunctionFromVector3[zValueFunctionIndex](item.mModelViewMatrix.GetTranslation3()) - static_cast<float>(item.mDepthIndex);
// Keep the renderitem pointer in the helper so we can quickly reorder items after sort.
- mSortingHelper[index].renderItem = &item;
+ mSortingHelper[index].renderItem = itemKey;
}
// Here we determine which comparitor (of the 3) to use.
#define DALI_INTERNAL_SCENE_GRAPH_RENDER_INSTRUCTION_PROCESSOR_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/common/dali-vector.h>
+
#include <dali/internal/common/buffer-index.h>
+#include <dali/internal/render/common/render-item-key.h>
#include <dali/internal/update/manager/sorted-layers.h>
-#include <dali/public-api/common/dali-vector.h>
namespace Dali
{
struct SortAttributes
{
SortAttributes()
- : renderItem(nullptr),
+ : renderItem{},
shader(nullptr),
textureSet(nullptr),
geometry(nullptr),
{
}
- RenderItem* renderItem; ///< The render item that is being sorted (includes depth index)
+ RenderItemKey renderItem; ///< The render item that is being sorted (includes depth index)
const Shader* shader; ///< The shader instance
const void* textureSet; ///< The textureSet instance
const Render::Geometry* geometry; ///< The geometry instance