From: David Steele Date: Fri, 6 Jan 2023 16:41:53 +0000 (+0000) Subject: Changed RenderItem* to RenderItemKey X-Git-Tag: dali_2.2.11~2^2~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9b507add67ea9bc4fefdf8953182e7730a54c3d1;p=platform%2Fcore%2Fuifw%2Fdali-core.git Changed RenderItem* to RenderItemKey Change-Id: I255b92f4f7e35209cdbe28d10bd3f2bc991bf843 Signed-off-by: David Steele --- diff --git a/automated-tests/src/dali-internal/utc-Dali-Internal-MemoryPoolObjectAllocator.cpp b/automated-tests/src/dali-internal/utc-Dali-Internal-MemoryPoolObjectAllocator.cpp index 25d2838..af1d3e1 100644 --- a/automated-tests/src/dali-internal/utc-Dali-Internal-MemoryPoolObjectAllocator.cpp +++ b/automated-tests/src/dali-internal/utc-Dali-Internal-MemoryPoolObjectAllocator.cpp @@ -1,5 +1,5 @@ /* - * 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. @@ -102,7 +102,8 @@ int UtcDaliMemoryPoolObjectAllocatorObjectAllocation(void) Internal::MemoryPoolObjectAllocator allocator; // Allocate an object - MemoryPoolObjectAllocatorTestObject* testObject1 = allocator.Allocate(); + void* ptr = allocator.AllocateRaw(); + MemoryPoolObjectAllocatorTestObject* testObject1 = new(ptr) MemoryPoolObjectAllocatorTestObject(); DALI_TEST_CHECK(testObject1); MemoryPoolObjectAllocatorTestObjectTracking tracking1; @@ -120,7 +121,8 @@ int UtcDaliMemoryPoolObjectAllocatorObjectAllocation(void) // 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; @@ -164,14 +166,16 @@ int UtcDaliMemoryPoolObjectAllocatorObjectAllocationPOD(void) { Internal::MemoryPoolObjectAllocator 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); diff --git a/dali/internal/render/common/render-item-key.h b/dali/internal/render/common/render-item-key.h new file mode 100644 index 0000000..dd4360a --- /dev/null +++ b/dali/internal/render/common/render-item-key.h @@ -0,0 +1,45 @@ +#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 +#include + +namespace Dali +{ +namespace Internal::SceneGraph +{ +struct RenderItem; + +using RenderItemKey = MemoryPoolKey; +} // namespace Internal::SceneGraph + +// Ensure RenderItemKey can be used in Dali::Vector +template<> +struct TypeTraits : public BasicTypes +{ + enum + { + IS_TRIVIAL_TYPE = true + }; +}; + +} // namespace Dali + +#endif // DALI_INTERNAL_SCENE_GRAPH_RENDER_ITEM_KEY_H diff --git a/dali/internal/render/common/render-item.cpp b/dali/internal/render/common/render-item.cpp index 1aafa37..9949611 100644 --- a/dali/internal/render/common/render-item.cpp +++ b/dali/internal/render/common/render-item.cpp @@ -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. @@ -28,6 +28,7 @@ namespace //Memory pool used to allocate new RenderItems. Memory used by this pool will be released when shutting down DALi Dali::Internal::MemoryPoolObjectAllocator gRenderItemPool; } // namespace + namespace Dali { namespace Internal @@ -39,6 +40,14 @@ RenderItem* RenderItem::New() return new(gRenderItemPool.AllocateRaw()) RenderItem(); } +RenderItemKey RenderItem::NewKey() +{ + void* ptr = gRenderItemPool.AllocateRaw(); + auto key = gRenderItemPool.GetKeyFromPtr(static_cast(ptr)); + new(ptr) RenderItem(); + return RenderItemKey(key); +} + RenderItem::RenderItem() : mModelMatrix(false), mModelViewMatrix(false), @@ -54,6 +63,21 @@ RenderItem::RenderItem() 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))); +} + +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: diff --git a/dali/internal/render/common/render-item.h b/dali/internal/render/common/render-item.h index 0a82320..cda4331 100644 --- a/dali/internal/render/common/render-item.h +++ b/dali/internal/render/common/render-item.h @@ -2,7 +2,7 @@ #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. @@ -19,6 +19,8 @@ */ // INTERNAL INCLUDES + +#include #include #include #include @@ -47,11 +49,39 @@ struct RenderItem 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. * @@ -111,8 +141,8 @@ private: 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 diff --git a/dali/internal/render/common/render-list.h b/dali/internal/render/common/render-list.h index a694624..6621c8c 100644 --- a/dali/internal/render/common/render-list.h +++ b/dali/internal/render/common/render-list.h @@ -2,7 +2,7 @@ #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. @@ -23,9 +23,11 @@ // INTERNAL INCLUDES #include +#include + #include #include -#include +#include namespace Dali { @@ -42,13 +44,13 @@ namespace SceneGraph { class Layer; -using RenderItemContainer = OwnerContainer; +using RenderItemContainer = OwnerKeyContainer; struct RenderList; using RenderListContainer = OwnerContainer; /** - * 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 { @@ -118,11 +120,11 @@ public: // 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; } /** @@ -131,7 +133,14 @@ public: 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]; } /** @@ -277,7 +286,7 @@ public: } 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 mGraphicsCommandBuffer{nullptr}; diff --git a/dali/internal/update/manager/render-instruction-processor.cpp b/dali/internal/update/manager/render-instruction-processor.cpp index 9486e91..cf81d88 100644 --- a/dali/internal/update/manager/render-instruction-processor.cpp +++ b/dali/internal/update/manager/render-instruction-processor.cpp @@ -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. @@ -459,10 +459,8 @@ inline void RenderInstructionProcessor::SortRenderItems(BufferIndex bufferIndex, // 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(), }; @@ -478,8 +476,8 @@ inline void RenderInstructionProcessor::SortRenderItems(BufferIndex bufferIndex, 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]); @@ -491,7 +489,7 @@ inline void RenderInstructionProcessor::SortRenderItems(BufferIndex bufferIndex, mSortingHelper[index].zValue = zValueFunctionFromVector3[zValueFunctionIndex](item.mModelViewMatrix.GetTranslation3()) - static_cast(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. diff --git a/dali/internal/update/manager/render-instruction-processor.h b/dali/internal/update/manager/render-instruction-processor.h index abaa466..138c3bd 100644 --- a/dali/internal/update/manager/render-instruction-processor.h +++ b/dali/internal/update/manager/render-instruction-processor.h @@ -2,7 +2,7 @@ #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. @@ -19,9 +19,11 @@ */ // INTERNAL INCLUDES +#include + #include +#include #include -#include namespace Dali { @@ -64,7 +66,7 @@ public: struct SortAttributes { SortAttributes() - : renderItem(nullptr), + : renderItem{}, shader(nullptr), textureSet(nullptr), geometry(nullptr), @@ -72,7 +74,7 @@ public: { } - 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