X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Frender%2Fcommon%2Frender-item.cpp;h=0ba37c30fcff90f5f2c62aa9034f1fb1802a1dc4;hb=73a52536910edf1cbb6ec462217e09a9cbd0449d;hp=4a4733fcfa7f50784f15c51dbba21212330c567f;hpb=e4d2ccefc08e03ced31a1722875f53365fc5afd5;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/render/common/render-item.cpp b/dali/internal/render/common/render-item.cpp index 4a4733f..0ba37c3 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. @@ -26,8 +26,13 @@ namespace { //Memory pool used to allocate new RenderItems. Memory used by this pool will be released when shutting down DALi -Dali::Internal::MemoryPoolObjectAllocator gRenderItemPool; +Dali::Internal::MemoryPoolObjectAllocator& GetRenderItemPool() +{ + static Dali::Internal::MemoryPoolObjectAllocator gRenderItemPool; + return gRenderItemPool; +} } // namespace + namespace Dali { namespace Internal @@ -36,15 +41,22 @@ namespace SceneGraph { RenderItem* RenderItem::New() { - return new(gRenderItemPool.AllocateRaw()) RenderItem(); + return new(GetRenderItemPool().AllocateRaw()) RenderItem(); +} + +RenderItemKey RenderItem::NewKey() +{ + void* ptr = GetRenderItemPool().AllocateRaw(); + auto key = GetRenderItemPool().GetKeyFromPtr(static_cast(ptr)); + new(ptr) RenderItem(); + return RenderItemKey(key); } RenderItem::RenderItem() : mModelMatrix(false), mModelViewMatrix(false), - mColor(Vector4::ZERO), mSize(), - mRenderer(nullptr), + mRenderer{}, mNode(nullptr), mTextureSet(nullptr), mDepthIndex(0), @@ -55,7 +67,22 @@ RenderItem::RenderItem() RenderItem::~RenderItem() = default; -ClippingBox RenderItem::CalculateTransformSpaceAABB(const Matrix& transformMatrix, const Vector3& size) +RenderItem* RenderItem::Get(RenderItemKey::KeyType key) +{ + return GetRenderItemPool().GetPtrFromKey(key); +} + +RenderItemKey RenderItem::GetKey(const RenderItem& renderItem) +{ + return RenderItemKey(GetRenderItemPool().GetKeyFromPtr(const_cast(&renderItem))); +} + +RenderItemKey RenderItem::GetKey(RenderItem* renderItem) +{ + return RenderItemKey(GetRenderItemPool().GetKeyFromPtr(renderItem)); +} + +ClippingBox RenderItem::CalculateTransformSpaceAABB(const Matrix& transformMatrix, const Vector3& position, const Vector3& size) { // Calculate extent vector of the AABB: const float halfActorX = size.x * 0.5f; @@ -68,9 +95,9 @@ ClippingBox RenderItem::CalculateTransformSpaceAABB(const Matrix& transformMatri // We place the coords into the array in clockwise order, so we know opposite corners are always i + 2 from corner i. // We skip the 4th corner here as we can calculate that from the other 3, bypassing matrix multiplication. // Note: The below transform methods use a fast (2D) matrix multiply (only 4 multiplications are done). - Vector2 corners[4]{Transform2D(transformMatrix, -halfActorX, -halfActorY), - Transform2D(transformMatrix, halfActorX, -halfActorY), - Transform2D(transformMatrix, halfActorX, halfActorY)}; + Vector2 corners[4]{Transform2D(transformMatrix, -halfActorX + position.x, -halfActorY + position.y), + Transform2D(transformMatrix, halfActorX + position.x, -halfActorY + position.y), + Transform2D(transformMatrix, halfActorX + position.x, halfActorY + position.y)}; // As we are dealing with a rectangle, we can do a fast calculation to get the 4th corner from knowing the other 3 (even if rotated). corners[3] = Vector2(corners[0] + (corners[2] - corners[1])); @@ -106,7 +133,7 @@ ClippingBox RenderItem::CalculateTransformSpaceAABB(const Matrix& transformMatri return ClippingBox(x, y, z - x, fabsf(w - y)); } -ClippingBox RenderItem::CalculateViewportSpaceAABB(const Matrix& modelViewMatrix, const Vector3& size, const int viewportWidth, const int viewportHeight) +ClippingBox RenderItem::CalculateViewportSpaceAABB(const Matrix& modelViewMatrix, const Vector3& position, const Vector3& size, const int viewportWidth, const int viewportHeight) { // Calculate extent vector of the AABB: const float halfActorX = size.x * 0.5f; @@ -119,9 +146,9 @@ ClippingBox RenderItem::CalculateViewportSpaceAABB(const Matrix& modelViewMatrix // We place the coords into the array in clockwise order, so we know opposite corners are always i + 2 from corner i. // We skip the 4th corner here as we can calculate that from the other 3, bypassing matrix multiplication. // Note: The below transform methods use a fast (2D) matrix multiply (only 4 multiplications are done). - Vector2 corners[4]{Transform2D(modelViewMatrix, -halfActorX, -halfActorY), - Transform2D(modelViewMatrix, halfActorX, -halfActorY), - Transform2D(modelViewMatrix, halfActorX, halfActorY)}; + Vector2 corners[4]{Transform2D(modelViewMatrix, -halfActorX + position.x, -halfActorY + position.y), + Transform2D(modelViewMatrix, halfActorX + position.x, -halfActorY + position.y), + Transform2D(modelViewMatrix, halfActorX + position.x, halfActorY + position.y)}; // As we are dealing with a rectangle, we can do a fast calculation to get the 4th corner from knowing the other 3 (even if rotated). corners[3] = Vector2(corners[0] + (corners[2] - corners[1])); @@ -165,7 +192,12 @@ ClippingBox RenderItem::CalculateViewportSpaceAABB(const Matrix& modelViewMatrix void RenderItem::operator delete(void* ptr) { - gRenderItemPool.Free(static_cast(ptr)); + GetRenderItemPool().Free(static_cast(ptr)); +} + +uint32_t RenderItem::GetMemoryPoolCapacity() +{ + return GetRenderItemPool().GetCapacity(); } } // namespace SceneGraph