X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fupdate%2Fmanager%2Frender-instruction-processor.cpp;h=e15862aa18b60d01bb6e42af43d8b0db7ffd38b4;hb=5de727a5d6b9ef995c93eff4d4e47a086784a332;hp=2436ff34433fe1afaf38a1b3df11ff1e669d08e4;hpb=716d916ef3929bbf21238c341f83817354386c22;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 index 2436ff3..e15862a 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) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 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. @@ -20,6 +20,7 @@ // INTERNAL INCLUDES #include +#include #include // for the default sorting function #include #include @@ -28,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -137,6 +139,39 @@ bool CompareItems3DWithClipping(const RenderInstructionProcessor::SortAttributes } /** + * Set the update area of the node + * @param[in] node The node of the renderer + * @param[in] isLayer3d Whether we are processing a 3D layer or not + * @param[in,out] nodeWorldMatrix The world matrix of the node + * @param[in,out] nodeSize The size of the node + * @param[in,out] nodeUpdateArea The update area of the node + * + * @return True if node use it's own UpdateAreaHint, or z transform occured. False if we use nodeUpdateArea equal with Vector4(0, 0, nodeSize.width, nodeSize.height). + */ +inline bool SetNodeUpdateArea(Node* node, bool isLayer3d, Matrix& nodeWorldMatrix, Vector3& nodeSize, Vector4& nodeUpdateArea) +{ + node->GetWorldMatrixAndSize(nodeWorldMatrix, nodeSize); + + if(node->GetUpdateAreaHint() == Vector4::ZERO) + { + // RenderItem::CalculateViewportSpaceAABB cannot cope with z transform + // I don't use item.mModelMatrix.GetTransformComponents() for z transform, would be too slow + if(!isLayer3d && nodeWorldMatrix.GetZAxis() == Vector3(0.0f, 0.0f, 1.0f)) + { + nodeUpdateArea = Vector4(0.0f, 0.0f, nodeSize.width, nodeSize.height); + return false; + } + // Keep nodeUpdateArea as Vector4::ZERO, and return true. + return true; + } + else + { + nodeUpdateArea = node->GetUpdateAreaHint(); + return true; + } +} + +/** * Add a renderer to the list * @param updateBufferIndex to read the model matrix from * @param renderList to add the item to @@ -144,64 +179,95 @@ bool CompareItems3DWithClipping(const RenderInstructionProcessor::SortAttributes * @param viewMatrix used to calculate modelview matrix for the item * @param camera The camera used to render * @param isLayer3d Whether we are processing a 3D layer or not + * @param viewportSet Whether the viewport is set or not + * @param viewport The viewport * @param cull Whether frustum culling is enabled or not */ -inline void AddRendererToRenderList(BufferIndex updateBufferIndex, - RenderList& renderList, - Renderable& renderable, - const Matrix& viewMatrix, - SceneGraph::Camera& camera, - bool isLayer3d, - bool cull) +inline void AddRendererToRenderList(BufferIndex updateBufferIndex, + RenderList& renderList, + Renderable& renderable, + const Matrix& viewMatrix, + const SceneGraph::Camera& camera, + bool isLayer3d, + bool viewportSet, + const Viewport& viewport, + bool cull) { - bool inside(true); - Node* node = renderable.mNode; - - if(cull && renderable.mRenderer && !renderable.mRenderer->GetShader().HintEnabled(Dali::Shader::Hint::MODIFIES_GEOMETRY)) + bool inside(true); + Node* node = renderable.mNode; + Matrix nodeWorldMatrix(false); + Vector3 nodeSize; + Vector4 nodeUpdateArea; + bool nodeUpdateAreaSet(false); + Matrix nodeModelViewMatrix(false); + bool nodeModelViewMatrixSet(false); + + // Don't cull items which have render callback + bool hasRenderCallback = (renderable.mRenderer && renderable.mRenderer->GetRenderCallback()); + + if(cull && renderable.mRenderer && !hasRenderCallback && !renderable.mRenderer->GetShader().HintEnabled(Dali::Shader::Hint::MODIFIES_GEOMETRY) && node->GetClippingMode() == ClippingMode::DISABLED) { const Vector4& boundingSphere = node->GetBoundingSphere(); inside = (boundingSphere.w > Math::MACHINE_EPSILON_1000) && (camera.CheckSphereInFrustum(updateBufferIndex, Vector3(boundingSphere), boundingSphere.w)); + + if(inside && !isLayer3d && viewportSet) + { + SetNodeUpdateArea(node, isLayer3d, nodeWorldMatrix, nodeSize, nodeUpdateArea); + nodeUpdateAreaSet = true; + + const Vector3& scale = node->GetWorldScale(updateBufferIndex); + const Vector3& size = Vector3(nodeUpdateArea.z, nodeUpdateArea.w, 1.0f) * scale; + + if(size.LengthSquared() > Math::MACHINE_EPSILON_1000) + { + MatrixUtils::Multiply(nodeModelViewMatrix, nodeWorldMatrix, viewMatrix); + nodeModelViewMatrixSet = true; + + // Assume actors are at z=0, compute AABB in view space & test rect intersection + // against z=0 plane boundaries for frustum. (NOT viewport). This should take into account + // magnification due to FOV etc. + + // TODO : Below logic might need to refactor it. + // If camera is Perspective, we need to calculate clipping box by FoV. Currently, we just believe default camera setup OrthographicSize well. + // - If then, It must use math calculate like tan(fov) internally. So, we might need calculate it only one times, and cache. + ClippingBox boundingBox = RenderItem::CalculateTransformSpaceAABB(nodeModelViewMatrix, Vector3(nodeUpdateArea.x, nodeUpdateArea.y, 0.0f), Vector3(nodeUpdateArea.z, nodeUpdateArea.w, 0.0f)); + ClippingBox clippingBox = camera.GetOrthographicClippingBox(updateBufferIndex); + inside = clippingBox.Intersects(boundingBox); + } + } + /* + * Note, the API Camera::CheckAABBInFrustum() can be used to test if a bounding box is (partially/fully) inside the view frustum. + */ } if(inside) { - Renderer::OpacityType opacityType = renderable.mRenderer ? renderable.mRenderer->GetOpacityType(updateBufferIndex, *renderable.mNode) : Renderer::OPAQUE; - if(opacityType != Renderer::TRANSPARENT || node->GetClippingMode() == ClippingMode::CLIP_CHILDREN) + bool skipRender(false); + bool isOpaque = true; + if(!hasRenderCallback) { - // Get the next free RenderItem. - RenderItem& item = renderList.GetNextFreeItem(); + Renderer::OpacityType opacityType = renderable.mRenderer ? renderable.mRenderer->GetOpacityType(updateBufferIndex, *node) : Renderer::OPAQUE; - // Get cached values - auto& partialRenderingData = node->GetPartialRenderingData(); + // We can skip render when node is not clipping and transparent + skipRender = (opacityType == Renderer::TRANSPARENT && node->GetClippingMode() == ClippingMode::DISABLED); - auto& partialRenderingCacheInfo = node->GetPartialRenderingData().GetCurrentCacheInfo(); - - partialRenderingCacheInfo.node = node; - partialRenderingCacheInfo.isOpaque = (opacityType == Renderer::OPAQUE); - partialRenderingCacheInfo.renderer = renderable.mRenderer; - partialRenderingCacheInfo.color = renderable.mNode->GetColor(updateBufferIndex); - partialRenderingCacheInfo.depthIndex = renderable.mNode->GetDepthIndex(); + isOpaque = (opacityType == Renderer::OPAQUE); + } - if(renderable.mRenderer) - { - partialRenderingCacheInfo.textureSet = renderable.mRenderer->GetTextures(); - } + if(!skipRender) + { + // Get the next free RenderItem. + RenderItem& item = renderList.GetNextFreeItem(); - item.mNode = renderable.mNode; - item.mIsOpaque = (opacityType == Renderer::OPAQUE); - item.mColor = renderable.mNode->GetColor(updateBufferIndex); - - item.mDepthIndex = 0; - if(!isLayer3d) - { - item.mDepthIndex = renderable.mNode->GetDepthIndex(); - } + item.mNode = node; + item.mIsOpaque = isOpaque; + item.mDepthIndex = isLayer3d ? 0 : node->GetDepthIndex(); if(DALI_LIKELY(renderable.mRenderer)) { item.mRenderer = &renderable.mRenderer->GetRenderer(); - item.mTextureSet = renderable.mRenderer->GetTextures(); + item.mTextureSet = renderable.mRenderer->GetTextureSet(); item.mDepthIndex += renderable.mRenderer->GetDepthIndex(); } else @@ -211,36 +277,47 @@ inline void AddRendererToRenderList(BufferIndex updateBufferIndex, item.mIsUpdated |= isLayer3d; - // Save ModelView matrix onto the item. - node->GetWorldMatrixAndSize(item.mModelMatrix, item.mSize); - Matrix::Multiply(item.mModelViewMatrix, item.mModelMatrix, viewMatrix); - - partialRenderingCacheInfo.matrix = item.mModelViewMatrix; - partialRenderingCacheInfo.size = item.mSize; - - if(renderable.mNode->GetUpdateSizeHint() == Vector3::ZERO) + if(!nodeUpdateAreaSet) { - // RenderItem::CalculateViewportSpaceAABB cannot cope with z transform - // I don't use item.mModelMatrix.GetTransformComponents() for z transform, would be to slow - if(!isLayer3d && item.mModelMatrix.GetZAxis() == Vector3(0.0f, 0.0f, 1.0f)) - { - item.mUpdateSize = item.mSize; - } + SetNodeUpdateArea(node, isLayer3d, nodeWorldMatrix, nodeSize, nodeUpdateArea); } - else + + item.mSize = nodeSize; + item.mUpdateArea = nodeUpdateArea; + item.mModelMatrix = nodeWorldMatrix; + + if(!nodeModelViewMatrixSet) { - item.mUpdateSize = renderable.mNode->GetUpdateSizeHint(); + MatrixUtils::Multiply(nodeModelViewMatrix, nodeWorldMatrix, viewMatrix); } + item.mModelViewMatrix = nodeModelViewMatrix; + + PartialRenderingData partialRenderingData; + partialRenderingData.color = node->GetWorldColor(updateBufferIndex); + partialRenderingData.matrix = item.mModelViewMatrix; + partialRenderingData.updatedPositionSize = item.mUpdateArea; + partialRenderingData.size = item.mSize; - partialRenderingCacheInfo.updatedSize = item.mUpdateSize; + auto& nodePartialRenderingData = node->GetPartialRenderingData(); + item.mIsUpdated = nodePartialRenderingData.IsUpdated(partialRenderingData) || item.mIsUpdated; - item.mIsUpdated = partialRenderingData.IsUpdated() || item.mIsUpdated; - partialRenderingData.SwapBuffers(); + nodePartialRenderingData.Update(partialRenderingData); } + else + { + // Mark as not rendered + auto& nodePartialRenderingData = node->GetPartialRenderingData(); + nodePartialRenderingData.mRendered = false; + } + node->SetCulled(updateBufferIndex, false); } else { + // Mark as not rendered + auto& nodePartialRenderingData = node->GetPartialRenderingData(); + nodePartialRenderingData.mRendered = false; + node->SetCulled(updateBufferIndex, true); } } @@ -256,13 +333,15 @@ inline void AddRendererToRenderList(BufferIndex updateBufferIndex, * @param isLayer3d Whether we are processing a 3D layer or not * @param cull Whether frustum culling is enabled or not */ -inline void AddRenderersToRenderList(BufferIndex updateBufferIndex, - RenderList& renderList, - RenderableContainer& renderers, - const Matrix& viewMatrix, - SceneGraph::Camera& camera, - bool isLayer3d, - bool cull) +inline void AddRenderersToRenderList(BufferIndex updateBufferIndex, + RenderList& renderList, + RenderableContainer& renderers, + const Matrix& viewMatrix, + const SceneGraph::Camera& camera, + bool isLayer3d, + bool viewportSet, + const Viewport& viewport, + bool cull) { DALI_LOG_INFO(gRenderListLogFilter, Debug::Verbose, "AddRenderersToRenderList()\n"); @@ -274,6 +353,8 @@ inline void AddRenderersToRenderList(BufferIndex updateBufferIndex, viewMatrix, camera, isLayer3d, + viewportSet, + viewport, cull); } } @@ -303,9 +384,15 @@ inline bool TryReuseCachedRenderers(Layer& layer, size_t checkSumOld = 0; for(uint32_t index = 0; index < renderableCount; ++index) { - const Render::Renderer& renderer = renderables[index].mRenderer->GetRenderer(); - checkSumNew += reinterpret_cast(&renderer); - checkSumOld += reinterpret_cast(&renderList.GetRenderer(index)); + if(DALI_LIKELY(renderables[index].mRenderer)) + { + const Render::Renderer& renderer = renderables[index].mRenderer->GetRenderer(); + checkSumNew += reinterpret_cast(&renderer); + } + if(DALI_LIKELY(renderList.GetItem(index).mRenderer)) + { + checkSumOld += reinterpret_cast(&renderList.GetRenderer(index)); + } } if(checkSumNew == checkSumOld) { @@ -347,7 +434,7 @@ RenderInstructionProcessor::RenderInstructionProcessor() RenderInstructionProcessor::~RenderInstructionProcessor() = default; -inline void RenderInstructionProcessor::SortRenderItems(BufferIndex bufferIndex, RenderList& renderList, Layer& layer, bool respectClippingOrder) +inline void RenderInstructionProcessor::SortRenderItems(BufferIndex bufferIndex, RenderList& renderList, Layer& layer, bool respectClippingOrder, bool isOrthographicCamera) { const uint32_t renderableCount = static_cast(renderList.Count()); // Reserve space if needed. @@ -368,44 +455,40 @@ inline void RenderInstructionProcessor::SortRenderItems(BufferIndex bufferIndex, // Calculate the sorting value, once per item by calling the layers sort function. // Using an if and two for-loops rather than if inside for as its better for branch prediction. - if(layer.UsesDefaultSortFunction()) - { - for(uint32_t index = 0; index < renderableCount; ++index) - { - RenderItem& item = renderList.GetItem(index); - if(item.mRenderer) - { - item.mRenderer->SetSortAttributes(mSortingHelper[index]); - } + // List of zValue calculating functions. + const Dali::Layer::SortFunctionType zValueFunctionFromVector3[] = { + [](const Vector3& position) { return position.z; }, + [](const Vector3& position) { return position.LengthSquared(); }, + layer.GetSortFunction(), + }; - // texture set - mSortingHelper[index].textureSet = item.mTextureSet; + // Determine whether we need to use zValue as Euclidean distance or translatoin's z value. + // If layer is LAYER_UI or camera is OrthographicProjection mode, we don't need to calculate + // renderItem's distance from camera. - // The default sorting function should get inlined here. - mSortingHelper[index].zValue = Internal::Layer::ZValue(item.mModelViewMatrix.GetTranslation3()) - static_cast(item.mDepthIndex); + // Here we determine which zValue SortFunctionType (of the 3) to use. + // 0 is position z value : Default LAYER_UI or Orthographic camera + // 1 is distance square value : Default LAYER_3D and Perspective camera + // 2 is user defined function. + const int zValueFunctionIndex = layer.UsesDefaultSortFunction() ? ((layer.GetBehavior() == Dali::Layer::LAYER_UI || isOrthographicCamera) ? 0 : 1) : 2; - // Keep the renderitem pointer in the helper so we can quickly reorder items after sort. - mSortingHelper[index].renderItem = &item; - } - } - else + for(uint32_t index = 0; index < renderableCount; ++index) { - const Dali::Layer::SortFunctionType sortFunction = layer.GetSortFunction(); - for(uint32_t index = 0; index < renderableCount; ++index) - { - RenderItem& item = renderList.GetItem(index); + RenderItem& item = renderList.GetItem(index); + if(DALI_LIKELY(item.mRenderer)) + { item.mRenderer->SetSortAttributes(mSortingHelper[index]); + } - // texture set - mSortingHelper[index].textureSet = item.mTextureSet; + // texture set + mSortingHelper[index].textureSet = item.mTextureSet; - mSortingHelper[index].zValue = (*sortFunction)(item.mModelViewMatrix.GetTranslation3()) - static_cast(item.mDepthIndex); + 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; - } + // Keep the renderitem pointer in the helper so we can quickly reorder items after sort. + mSortingHelper[index].renderItem = &item; } // Here we determine which comparitor (of the 3) to use. @@ -440,14 +523,18 @@ void RenderInstructionProcessor::Prepare(BufferIndex updateBuffe bool isRenderListAdded = false; bool isRootLayerDirty = false; - const Matrix& viewMatrix = renderTask.GetViewMatrix(updateBufferIndex); - SceneGraph::Camera& camera = renderTask.GetCamera(); + const Matrix& viewMatrix = renderTask.GetViewMatrix(updateBufferIndex); + const SceneGraph::Camera& camera = renderTask.GetCamera(); + const bool isOrthographicCamera = camera.mProjectionMode == Dali::Camera::ProjectionMode::ORTHOGRAPHIC_PROJECTION; + + Viewport viewport; + bool viewportSet = renderTask.QueryViewport(updateBufferIndex, viewport); const SortedLayersIter endIter = sortedLayers.end(); for(SortedLayersIter iter = sortedLayers.begin(); iter != endIter; ++iter) { Layer& layer = **iter; - const bool tryReuseRenderList(viewMatrixHasNotChanged && layer.CanReuseRenderers(&renderTask.GetCamera())); + const bool tryReuseRenderList(viewMatrixHasNotChanged && layer.CanReuseRenderers(&camera)); const bool isLayer3D = layer.GetBehavior() == Dali::Layer::LAYER_3D; RenderList* renderList = nullptr; @@ -470,10 +557,12 @@ void RenderInstructionProcessor::Prepare(BufferIndex updateBuffe viewMatrix, camera, isLayer3D, + viewportSet, + viewport, cull); // We only use the clipping version of the sort comparitor if any clipping nodes exist within the RenderList. - SortRenderItems(updateBufferIndex, *renderList, layer, hasClippingNodes); + SortRenderItems(updateBufferIndex, *renderList, layer, hasClippingNodes, isOrthographicCamera); } isRenderListAdded = true; @@ -492,10 +581,12 @@ void RenderInstructionProcessor::Prepare(BufferIndex updateBuffe viewMatrix, camera, isLayer3D, + viewportSet, + viewport, cull); // 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); + SortRenderItems(updateBufferIndex, *renderList, layer, false, isOrthographicCamera); } isRenderListAdded = true;