X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fupdate%2Fmanager%2Frender-instruction-processor.cpp;h=a76632e1a25160d6bddc3607cadc3802f6de3233;hb=55827866fcb8c7ee47581ac4335a3390472090e8;hp=f69b9c5d17186912b2f8faee75c508b083a97516;hpb=810916ea11828926b21bc73ea363d52c0a540d7b;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/update/manager/render-instruction-processor.cpp b/dali/internal/update/manager/render-instruction-processor.cpp old mode 100644 new mode 100755 index f69b9c5..a76632e --- a/dali/internal/update/manager/render-instruction-processor.cpp +++ b/dali/internal/update/manager/render-instruction-processor.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2019 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. @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include @@ -34,6 +33,7 @@ #include #include #include +#include namespace { @@ -60,8 +60,8 @@ namespace * @param[in] rhs Right hand side item * @return True if left item is greater than right */ -bool PartialCompareItems( const RenderInstructionProcessor::SortAttributes& lhs, - const RenderInstructionProcessor::SortAttributes& rhs ) +inline bool PartialCompareItems( const RenderInstructionProcessor::SortAttributes& lhs, + const RenderInstructionProcessor::SortAttributes& rhs ) { if( lhs.shader == rhs.shader ) { @@ -87,30 +87,12 @@ bool CompareItems( const RenderInstructionProcessor::SortAttributes& lhs, const // encapsulates the same data (e.g. the middle-order bits of the ptrs). if( lhs.renderItem->mDepthIndex == rhs.renderItem->mDepthIndex ) { - return PartialCompareItems(lhs, rhs); + return PartialCompareItems( lhs, rhs ); } return lhs.renderItem->mDepthIndex < rhs.renderItem->mDepthIndex; } /** - * Function which sorts render items by clipping hierarchy, then depth index and instance - * ptrs of shader/geometry/material. - * @param[in] lhs Left hand side item - * @param[in] rhs Right hand side item - * @return True if left item is greater than right - */ -bool CompareItemsWithClipping( const RenderInstructionProcessor::SortAttributes& lhs, const RenderInstructionProcessor::SortAttributes& rhs ) -{ - // Items must be sorted in order of clipping first, otherwise incorrect clipping regions could be used. - if( lhs.renderItem->mNode->mClippingSortModifier == rhs.renderItem->mNode->mClippingSortModifier ) - { - return CompareItems( lhs, rhs ); - } - - return lhs.renderItem->mNode->mClippingSortModifier < rhs.renderItem->mNode->mClippingSortModifier; -} - -/** * Function which sorts the render items by Z function, then * by instance ptrs of shader / geometry / material. * @param[in] lhs Left hand side item @@ -119,7 +101,7 @@ bool CompareItemsWithClipping( const RenderInstructionProcessor::SortAttributes& */ bool CompareItems3D( const RenderInstructionProcessor::SortAttributes& lhs, const RenderInstructionProcessor::SortAttributes& rhs ) { - bool lhsIsOpaque = lhs.renderItem->mIsOpaque; + const bool lhsIsOpaque = lhs.renderItem->mIsOpaque; if( lhsIsOpaque == rhs.renderItem->mIsOpaque ) { if( lhsIsOpaque ) @@ -179,9 +161,9 @@ inline void AddRendererToRenderList( BufferIndex updateBufferIndex, bool cull ) { bool inside( true ); - const Node* node = renderable.mNode; - - if( cull && !renderable.mRenderer->GetShader().HintEnabled( Dali::Shader::Hint::MODIFIES_GEOMETRY ) ) + Node* node = renderable.mNode; + bool isModifiesGeometryHint = false; + if( cull && renderable.mRenderer && !( isModifiesGeometryHint = renderable.mRenderer->GetShader().HintEnabled( Dali::Shader::Hint::MODIFIES_GEOMETRY ) ) ) { const Vector4& boundingSphere = node->GetBoundingSphere(); inside = ( boundingSphere.w > Math::MACHINE_EPSILON_1000 ) && @@ -190,27 +172,67 @@ inline void AddRendererToRenderList( BufferIndex updateBufferIndex, if( inside ) { - Renderer::Opacity opacity = renderable.mRenderer->GetOpacity( updateBufferIndex, *renderable.mNode ); - if( opacity != Renderer::TRANSPARENT ) + Renderer::OpacityType opacityType = renderable.mRenderer ? renderable.mRenderer->GetOpacityType( updateBufferIndex, *renderable.mNode ) : Renderer::OPAQUE; + if( opacityType != Renderer::TRANSPARENT || node->GetClippingMode() == ClippingMode::CLIP_CHILDREN ) { // Get the next free RenderItem. RenderItem& item = renderList.GetNextFreeItem(); - item.mRenderer = &renderable.mRenderer->GetRenderer(); + item.mNode = renderable.mNode; - item.mTextureSet = renderable.mRenderer->GetTextures(); - item.mIsOpaque = ( opacity == Renderer::OPAQUE ); - item.mDepthIndex = renderable.mRenderer->GetDepthIndex(); + item.mIsOpaque = ( opacityType == Renderer::OPAQUE ); + item.mDepthIndex = 0; + item.mPartialUpdateEnabled = false; if( !isLayer3d ) { - item.mDepthIndex += renderable.mNode->GetDepthIndex(); + item.mDepthIndex = renderable.mNode->GetDepthIndex(); + } + if( isLayer3d || isModifiesGeometryHint ) + { + renderList.SetPartialUpdateEnabled( false ); + } + + if( DALI_LIKELY( renderable.mRenderer ) ) + { + item.mRenderer = &renderable.mRenderer->GetRenderer(); + item.mTextureSet = renderable.mRenderer->GetTextures(); + item.mDepthIndex += renderable.mRenderer->GetDepthIndex(); + + if( FaceCullingMode::NONE != renderable.mRenderer->GetFaceCullingMode() ) + { + renderList.SetPartialUpdateEnabled( false ); + } + } + else + { + item.mRenderer = nullptr; } // Save ModelView matrix onto the item. node->GetWorldMatrixAndSize( item.mModelMatrix, item.mSize ); Matrix::Multiply( item.mModelViewMatrix, item.mModelMatrix, viewMatrix ); + + if( DALI_LIKELY( item.mRenderer ) && renderList.IsPartialUpdateEnabled() ) + { + if( node->IsPropertyDirty() || node->IsComponentChanged() ) + { + item.mPartialUpdateEnabled = true; + + item.mUpdateSizeHint = item.mSize; + Vector3 updateSizeHint = node->GetUpdateSizeHint( updateBufferIndex ); + if( updateSizeHint != Vector3::ZERO ) + { + item.mUpdateSizeHint = updateSizeHint; + } + } + } } + node->SetCulled( updateBufferIndex, false ); + } + else + { + node->SetCulled( updateBufferIndex, true ); } } @@ -235,12 +257,11 @@ inline void AddRenderersToRenderList( BufferIndex updateBufferIndex, { DALI_LOG_INFO( gRenderListLogFilter, Debug::Verbose, "AddRenderersToRenderList()\n"); - unsigned int rendererCount( renderers.Size() ); - for( unsigned int i(0); i < rendererCount; ++i ) + for( auto&& renderer : renderers ) { AddRendererToRenderList( updateBufferIndex, renderList, - renderers[i], + renderer, viewMatrix, camera, isLayer3d, @@ -261,7 +282,7 @@ inline bool TryReuseCachedRenderers( Layer& layer, RenderableContainer& renderables ) { bool retValue = false; - size_t renderableCount = renderables.Size(); + uint32_t renderableCount = static_cast( renderables.Size() ); // Check that the cached list originates from this layer and that the counts match if( ( renderList.GetSourceLayer() == &layer )&& ( renderList.GetCachedItemCount() == renderableCount ) ) @@ -271,11 +292,11 @@ inline bool TryReuseCachedRenderers( Layer& layer, // Therefore we check a combined sum of all renderer addresses. size_t checkSumNew = 0; size_t checkSumOld = 0; - for( size_t index = 0; index < renderableCount; ++index ) + for( uint32_t index = 0; index < renderableCount; ++index ) { const Render::Renderer& renderer = renderables[index].mRenderer->GetRenderer(); - checkSumNew += size_t( &renderer ); - checkSumOld += size_t( &renderList.GetRenderer( index ) ); + checkSumNew += reinterpret_cast( &renderer ); + checkSumOld += reinterpret_cast( &renderList.GetRenderer( index ) ); } if( checkSumNew == checkSumOld ) { @@ -308,10 +329,9 @@ RenderInstructionProcessor::RenderInstructionProcessor() : mSortingHelper() { // Set up a container of comparators for fast run-time selection. - mSortComparitors.Reserve( 4u ); + mSortComparitors.Reserve( 3u ); mSortComparitors.PushBack( CompareItems ); - mSortComparitors.PushBack( CompareItemsWithClipping ); mSortComparitors.PushBack( CompareItems3D ); mSortComparitors.PushBack( CompareItems3DWithClipping ); } @@ -322,9 +342,9 @@ RenderInstructionProcessor::~RenderInstructionProcessor() inline void RenderInstructionProcessor::SortRenderItems( BufferIndex bufferIndex, RenderList& renderList, Layer& layer, bool respectClippingOrder ) { - const size_t renderableCount = renderList.Count(); + const uint32_t renderableCount = static_cast( renderList.Count() ); // Reserve space if needed. - const unsigned int oldcapacity = mSortingHelper.size(); + const uint32_t oldcapacity = static_cast( mSortingHelper.size() ); if( oldcapacity < renderableCount ) { mSortingHelper.reserve( renderableCount ); @@ -343,17 +363,20 @@ inline void RenderInstructionProcessor::SortRenderItems( BufferIndex bufferIndex // Using an if and two for-loops rather than if inside for as its better for branch prediction. if( layer.UsesDefaultSortFunction() ) { - for( size_t index = 0; index < renderableCount; ++index ) + for( uint32_t index = 0; index < renderableCount; ++index ) { RenderItem& item = renderList.GetItem( index ); - item.mRenderer->SetSortAttributes( bufferIndex, mSortingHelper[ index ] ); + if( item.mRenderer ) + { + item.mRenderer->SetSortAttributes( bufferIndex, mSortingHelper[ index ] ); + } // texture set mSortingHelper[ index ].textureSet = item.mTextureSet; // The default sorting function should get inlined here. - mSortingHelper[ index ].zValue = Internal::Layer::ZValue( item.mModelViewMatrix.GetTranslation3() ) - item.mDepthIndex; + mSortingHelper[ index ].zValue = Internal::Layer::ZValue( 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; @@ -362,7 +385,7 @@ inline void RenderInstructionProcessor::SortRenderItems( BufferIndex bufferIndex else { const Dali::Layer::SortFunctionType sortFunction = layer.GetSortFunction(); - for( size_t index = 0; index < renderableCount; ++index ) + for( uint32_t index = 0; index < renderableCount; ++index ) { RenderItem& item = renderList.GetItem( index ); @@ -372,26 +395,25 @@ inline void RenderInstructionProcessor::SortRenderItems( BufferIndex bufferIndex mSortingHelper[ index ].textureSet = item.mTextureSet; - mSortingHelper[ index ].zValue = (*sortFunction)( item.mModelViewMatrix.GetTranslation3() ) - item.mDepthIndex; + mSortingHelper[ index ].zValue = (*sortFunction)( 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; } } - // Here we detemine which comparitor (of the 4) to use. - // The comparitors work like a bitmask. - // 1 << 0 is added to select a clipping comparitor. - // 1 << 1 is added for 3D comparitors. - const unsigned int comparitorIndex = ( respectClippingOrder ? ( 1u << 0u ) : 0u ) | - ( layer.GetBehavior() == Dali::Layer::LAYER_3D ? ( 1u << 1u ) : 0u ); + // Here we determine which comparitor (of the 3) to use. + // 0 is LAYER_UI + // 1 is LAYER_3D + // 2 is LAYER_3D + Clipping + const unsigned int comparitorIndex = layer.GetBehavior() == Dali::Layer::LAYER_3D ? respectClippingOrder ? 2u : 1u : 0u; std::stable_sort( mSortingHelper.begin(), mSortingHelper.end(), mSortComparitors[ comparitorIndex ] ); // Reorder / re-populate the RenderItems in the RenderList to correct order based on the sortinghelper. DALI_LOG_INFO( gRenderListLogFilter, Debug::Verbose, "Sorted Transparent List:\n"); RenderItemContainer::Iterator renderListIter = renderList.GetContainer().Begin(); - for( unsigned int index = 0; index < renderableCount; ++index, ++renderListIter ) + for( uint32_t index = 0; index < renderableCount; ++index, ++renderListIter ) { *renderListIter = mSortingHelper[ index ].renderItem; DALI_LOG_INFO( gRenderListLogFilter, Debug::Verbose, " sortedList[%d] = %p\n", index, mSortingHelper[ index ].renderItem->mRenderer); @@ -410,6 +432,8 @@ void RenderInstructionProcessor::Prepare( BufferIndex updateBufferIndex, RenderInstruction& instruction = instructions.GetNextInstruction( updateBufferIndex ); renderTask.PrepareRenderInstruction( instruction, updateBufferIndex ); bool viewMatrixHasNotChanged = !renderTask.ViewMatrixUpdated(); + bool isRenderListAdded = false; + bool isRootLayerDirty = false; const Matrix& viewMatrix = renderTask.GetViewMatrix( updateBufferIndex ); SceneGraph::Camera& camera = renderTask.GetCamera(); @@ -422,6 +446,12 @@ void RenderInstructionProcessor::Prepare( BufferIndex updateBufferIndex, const bool isLayer3D = layer.GetBehavior() == Dali::Layer::LAYER_3D; RenderList* renderList = NULL; + if( layer.IsRoot() && ( layer.GetDirtyFlags() != NodePropertyFlags::NOTHING ) ) + { + // If root-layer & dirty, i.e. a property has changed or a child has been deleted, then we need to ensure we render once more + isRootLayerDirty = true; + } + if( !layer.colorRenderables.Empty() ) { RenderableContainer& renderables = layer.colorRenderables; @@ -429,6 +459,10 @@ void RenderInstructionProcessor::Prepare( BufferIndex updateBufferIndex, if( !SetupRenderList( renderables, layer, instruction, tryReuseRenderList, &renderList ) ) { renderList->SetHasColorRenderItems( true ); + if( !isLayer3D ) + { + renderList->SetPartialUpdateEnabled( true ); + } AddRenderersToRenderList( updateBufferIndex, *renderList, renderables, @@ -440,6 +474,8 @@ void RenderInstructionProcessor::Prepare( BufferIndex updateBufferIndex, // We only use the clipping version of the sort comparitor if any clipping nodes exist within the RenderList. SortRenderItems( updateBufferIndex, *renderList, layer, hasClippingNodes ); } + + isRenderListAdded = true; } if( !layer.overlayRenderables.Empty() ) @@ -449,6 +485,10 @@ void RenderInstructionProcessor::Prepare( BufferIndex updateBufferIndex, if( !SetupRenderList( renderables, layer, instruction, tryReuseRenderList, &renderList ) ) { renderList->SetHasColorRenderItems( false ); + if( !isLayer3D ) + { + renderList->SetPartialUpdateEnabled( true ); + } AddRenderersToRenderList( updateBufferIndex, *renderList, renderables, @@ -460,13 +500,19 @@ void RenderInstructionProcessor::Prepare( BufferIndex updateBufferIndex, // Clipping hierarchy is irrelevant when sorting overlay items, so we specify using the non-clipping version of the sort comparitor. SortRenderItems( updateBufferIndex, *renderList, layer, false ); } + + isRenderListAdded = true; } } // Inform the render instruction that all renderers have been added and this frame is complete. instruction.UpdateCompleted(); -} + if( !isRenderListAdded && !instruction.mIsClearColorSet && !isRootLayerDirty ) + { + instructions.DiscardCurrentInstruction( updateBufferIndex ); + } +} } // SceneGraph