X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Frender%2Fcommon%2Frender-item.cpp;h=e5620366c9a16f4da7b17ce3f4d652b741873c4b;hb=b43741a90b40ca9dfbd33d6a9d390d3c09230e89;hp=c7eeab56cf3b590cb255c2c62e04714a155a3422;hpb=8f2c5571c924479b6a07a2c2187dedd9c685baf0;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 old mode 100644 new mode 100755 index c7eeab5..e562036 --- a/dali/internal/render/common/render-item.cpp +++ b/dali/internal/render/common/render-item.cpp @@ -1,25 +1,33 @@ -// -// Copyright (c) 2014 Samsung Electronics Co., Ltd. -// -// Licensed under the Flora License, Version 1.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://floralicense.org/license/ -// -// 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. -// +/* + * Copyright (c) 2018 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. + * + */ // CLASS HEADER #include // INTERNAL INCLUDES -#include +#include +#include +#include +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 Dali { @@ -29,41 +37,104 @@ namespace Internal namespace SceneGraph { -RenderItem::RenderItem() -: mRenderer( NULL ), - mModelViewMatrix( false ) +RenderItem* RenderItem::New() { + return new ( gRenderItemPool.AllocateRaw() ) RenderItem(); } -RenderItem::~RenderItem() +RenderItem::RenderItem() +: mModelMatrix( false ), + mModelViewMatrix( false ), + mSize(), + mUpdateSizeHint(), + mRenderer( NULL ), + mNode( NULL ), + mTextureSet( NULL ), + mDepthIndex( 0 ), + mIsOpaque( true ), + mPartialUpdateEnabled( false ) { } -void RenderItem::Reset() +RenderItem::~RenderItem() { - mRenderer = NULL; } -void RenderItem::SetRenderer( Renderer* renderer ) -{ - mRenderer = renderer; -} -const Renderer* RenderItem::GetRenderer() const +ClippingBox RenderItem::CalculateViewportSpaceAABB( const int viewportWidth, const int viewportHeight, const bool useUpdateSizeHint ) const { - return mRenderer; -} + // Calculate extent vector of the AABB: + float halfActorX; + float halfActorY; + if( useUpdateSizeHint ) + { + halfActorX = mUpdateSizeHint.x * 0.5f; + halfActorY = mUpdateSizeHint.y * 0.5f; + } + else + { + halfActorX = mSize.x * 0.5f; + halfActorY = mSize.y * 0.5f; + } -Matrix& RenderItem::GetModelViewMatrix() -{ - return mModelViewMatrix; + + // To transform the actor bounds to screen-space, We do a fast, 2D version of a matrix multiply optimized for 2D quads. + // This reduces float multiplications from 64 (16 * 4) to 12 (4 * 3). + // We create an array of 4 corners and directly initialize the first 3 with the matrix multiplication result of the respective corner. + // This causes the construction of the vector arrays contents in-place for optimization. + // 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( mModelViewMatrix, -halfActorX, -halfActorY ), + Transform2D( mModelViewMatrix, halfActorX, -halfActorY ), + Transform2D( mModelViewMatrix, halfActorX, halfActorY ) }; + + // 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] ) ); + + // Calculate the AABB: + // We use knowledge that opposite corners will be the max/min of each other. Doing this reduces the normal 12 branching comparisons to 3. + // The standard equivalent min/max code of the below would be: + // Vector2 AABBmax( std::max( corners[0].x, std::max( corners[1].x, std::max( corners[3].x, corners[2].x ) ) ), + // std::max( corners[0].y, std::max( corners[1].y, std::max( corners[3].y, corners[2].y ) ) ) ); + // Vector2 AABBmin( std::min( corners[0].x, std::min( corners[1].x, std::min( corners[3].x, corners[2].x ) ) ), + // std::min( corners[0].y, std::min( corners[1].y, std::min( corners[3].y, corners[2].y ) ) ) ); + unsigned int smallestX = 0u; + // Loop 3 times to find the index of the smallest X value. + // Note: We deliberately do NOT unroll the code here as this hampers the compilers output. + for( unsigned int i = 1u; i < 4u; ++i ) + { + if( corners[i].x < corners[smallestX].x ) + { + smallestX = i; + } + } + + // As we are dealing with a rectangle, we can assume opposite corners are the largest. + // So without doing min/max branching, we can fetch the min/max values of all the remaining X/Y coords from this one index. + Vector4 aabb( corners[smallestX].x, corners[( smallestX + 3u ) % 4].y, corners[( smallestX + 2u ) % 4].x, corners[( smallestX + 1u ) % 4].y ); + + // Return the AABB in screen-space pixels (x, y, width, height). + // Note: This is a algebraic simplification of: ( viewport.x - aabb.width ) / 2 - ( ( aabb.width / 2 ) + aabb.x ) per axis. + Vector4 aabbInScreen( static_cast( viewportWidth ) * 0.5f - aabb.z, + static_cast( viewportHeight ) * 0.5f - aabb.w, + static_cast( viewportWidth ) * 0.5f - aabb.x, + static_cast( viewportHeight ) * 0.5f - aabb.y ); + + int x = static_cast< int >( roundf( aabbInScreen.x ) ); + int y = static_cast< int >( roundf( aabbInScreen.y ) ); + int z = static_cast< int >( roundf( aabbInScreen.z ) ); + int w = static_cast< int >( roundf( aabbInScreen.w ) ); + + return ClippingBox( x, y, z - x, w - y ); } -const Matrix& RenderItem::GetModelViewMatrix() const +void RenderItem::operator delete( void* ptr ) { - return mModelViewMatrix; + gRenderItemPool.Free( static_cast( ptr ) ); } + } // namespace SceneGraph } // namespace Internal