From e1e11ab7d00e48b535ea770df2039608aa7af4d9 Mon Sep 17 00:00:00 2001 From: Richard Date: Thu, 6 Jul 2023 10:39:37 +0100 Subject: [PATCH] Updated FrameCallback to return value to specify whether we should keep rendering Change-Id: If1e53ef0291074dcb53116cc05f2fd69dcc3da87 --- .../src/dali/utc-Dali-FrameCallbackInterface.cpp | 31 +++++++++++++++++----- dali/devel-api/update/frame-callback-interface.h | 17 ++++++++++-- .../update/manager/frame-callback-processor.cpp | 12 ++++++--- .../update/manager/frame-callback-processor.h | 5 ++-- .../update/manager/scene-graph-frame-callback.cpp | 11 +++++--- .../update/manager/scene-graph-frame-callback.h | 16 ++++++++--- dali/internal/update/manager/update-manager.cpp | 2 +- 7 files changed, 73 insertions(+), 21 deletions(-) diff --git a/automated-tests/src/dali/utc-Dali-FrameCallbackInterface.cpp b/automated-tests/src/dali/utc-Dali-FrameCallbackInterface.cpp index df9d213..656f49e 100644 --- a/automated-tests/src/dali/utc-Dali-FrameCallbackInterface.cpp +++ b/automated-tests/src/dali/utc-Dali-FrameCallbackInterface.cpp @@ -46,9 +46,10 @@ class FrameCallbackBasic : public FrameCallbackInterface public: FrameCallbackBasic() = default; - virtual void Update(Dali::UpdateProxy& updateProxy, float elapsedSeconds) + virtual bool Update(Dali::UpdateProxy& updateProxy, float elapsedSeconds) { mCalled = true; + return false; } virtual void Reset() @@ -67,7 +68,7 @@ public: { } - virtual void Update(Dali::UpdateProxy& updateProxy, float elapsedSeconds) override + virtual bool Update(Dali::UpdateProxy& updateProxy, float elapsedSeconds) override { FrameCallbackBasic::Update(updateProxy, elapsedSeconds); updateProxy.GetPosition(mActorId, mPositionGetPositionCall); @@ -79,6 +80,8 @@ public: updateProxy.GetWorldPositionScaleAndSize(mActorId, mWorldPosition, mWorldScale, mSizeGetWorldPositionAndSizeCall); updateProxy.GetWorldTransformAndSize(mActorId, mWorldTransformPosition, mWorldTransformScale, mWorldTransformOrientation, mSizeGetWorldTransform); + + return false; } const unsigned int mActorId; @@ -120,7 +123,7 @@ public: { } - virtual void Update(Dali::UpdateProxy& updateProxy, float elapsedSeconds) override + virtual bool Update(Dali::UpdateProxy& updateProxy, float elapsedSeconds) override { Vector3 size; FrameCallbackBasic::Update(updateProxy, elapsedSeconds); @@ -134,6 +137,8 @@ public: updateProxy.GetColor(mActorId, mColorAfterSetting); updateProxy.GetScale(mActorId, mScaleAfterSetting); updateProxy.GetOrientation(mActorId, mOrientationAfterSetting); + + return false; } const unsigned int mActorId; @@ -169,7 +174,7 @@ public: { } - virtual void Update(Dali::UpdateProxy& updateProxy, float elapsedSeconds) override + virtual bool Update(Dali::UpdateProxy& updateProxy, float elapsedSeconds) override { Vector3 size; FrameCallbackBasic::Update(updateProxy, elapsedSeconds); @@ -183,6 +188,8 @@ public: updateProxy.GetColor(mActorId, mColorAfterSetting); updateProxy.GetScale(mActorId, mScaleAfterSetting); updateProxy.GetOrientation(mActorId, mOrientationAfterSetting); + + return false; } const unsigned int mActorId; @@ -206,7 +213,7 @@ public: { } - virtual void Update(Dali::UpdateProxy& updateProxy, float elapsedSeconds) override + virtual bool Update(Dali::UpdateProxy& updateProxy, float elapsedSeconds) override { FrameCallbackBasic::Update(updateProxy, elapsedSeconds); for(auto&& i : mActorIds) @@ -217,6 +224,8 @@ public: mPositions[i] = position; mSizes[i] = size; } + + return false; } Vector mActorIds; @@ -233,7 +242,7 @@ public: { } - virtual void Update(Dali::UpdateProxy& updateProxy, float elapsedSeconds) override + virtual bool Update(Dali::UpdateProxy& updateProxy, float elapsedSeconds) override { FrameCallbackBasic::Update(updateProxy, elapsedSeconds); Vector3 vec3; @@ -259,6 +268,8 @@ public: mSetOrientationCallSuccess = updateProxy.SetOrientation(mActorId, quat); mBakeOrientationCallSuccess = updateProxy.BakeOrientation(mActorId, quat); mGetWorldTransformCallSuccess = updateProxy.GetWorldTransformAndSize(mActorId, vec3, vec3, quat, vec3); + + return false; } virtual void Reset() override @@ -1022,3 +1033,11 @@ int UtcDaliFrameCallbackDoubleAddition(void) END_TEST; } + +int UtcDaliFrameCallbackGetExtension(void) +{ + FrameCallbackBasic frameCallback; + DALI_TEST_CHECK(frameCallback.GetExtension() == nullptr); + + END_TEST; +} diff --git a/dali/devel-api/update/frame-callback-interface.h b/dali/devel-api/update/frame-callback-interface.h index fa9fec5..1b59366 100644 --- a/dali/devel-api/update/frame-callback-interface.h +++ b/dali/devel-api/update/frame-callback-interface.h @@ -2,7 +2,7 @@ #define DALI_FRAME_CALLBACK_INTERFACE_H /* - * 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. @@ -47,13 +47,26 @@ class UpdateProxy; class DALI_CORE_API FrameCallbackInterface { public: + class Extension; ///< Forward declare future extension interface + /** * @brief Called from the update-thread after the scene has been updated, and is ready to render. * @param[in] updateProxy Use this to get/set required values for the Actor. * @param[in] elapsedSeconds Time elapsed time since the last frame (in seconds) + * @return Whether we should keep rendering. * @see FrameCallbackInterface */ - virtual void Update(UpdateProxy& updateProxy, float elapsedSeconds) = 0; + virtual bool Update(UpdateProxy& updateProxy, float elapsedSeconds) = 0; + + /** + * @brief Retrieves the extension for the interface. + * + * @return The extension if available, nullptr otherwise + */ + virtual Extension* GetExtension() + { + return nullptr; + } protected: /** diff --git a/dali/internal/update/manager/frame-callback-processor.cpp b/dali/internal/update/manager/frame-callback-processor.cpp index ad4e495..06ca265 100644 --- a/dali/internal/update/manager/frame-callback-processor.cpp +++ b/dali/internal/update/manager/frame-callback-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. @@ -63,8 +63,10 @@ void FrameCallbackProcessor::RemoveFrameCallback(FrameCallbackInterface* frameCa mFrameCallbacks.erase(iter, mFrameCallbacks.end()); } -void FrameCallbackProcessor::Update(BufferIndex bufferIndex, float elapsedSeconds) +bool FrameCallbackProcessor::Update(BufferIndex bufferIndex, float elapsedSeconds) { + bool keepRendering = false; + if(!mFrameCallbacks.empty()) { DALI_TRACE_SCOPE(gTraceFilter, "DALI_FRAME_CALLBACK_UPDATE"); @@ -72,12 +74,16 @@ void FrameCallbackProcessor::Update(BufferIndex bufferIndex, float elapsedSecond // If any of the FrameCallback::Update calls returns false, then they are no longer required & can be removed. auto iter = std::remove_if( mFrameCallbacks.begin(), mFrameCallbacks.end(), [&](OwnerPointer& frameCallback) { - return !frameCallback->Update(bufferIndex, elapsedSeconds, mNodeHierarchyChanged); + FrameCallback::RequestFlags requests = frameCallback->Update(bufferIndex, elapsedSeconds, mNodeHierarchyChanged); + keepRendering |= (requests & FrameCallback::KEEP_RENDERING); + return (requests & FrameCallback::CONTINUE_CALLING) == 0; }); mFrameCallbacks.erase(iter, mFrameCallbacks.end()); } mNodeHierarchyChanged = false; + + return keepRendering; } } // namespace SceneGraph diff --git a/dali/internal/update/manager/frame-callback-processor.h b/dali/internal/update/manager/frame-callback-processor.h index 09822d1..685856e 100644 --- a/dali/internal/update/manager/frame-callback-processor.h +++ b/dali/internal/update/manager/frame-callback-processor.h @@ -2,7 +2,7 @@ #define DALI_INTERNAL_SCENE_GRAPH_FRAME_CALLBACK_PROCESSOR_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. @@ -82,8 +82,9 @@ public: * Called on Update by the UpdateManager. * @param[in] bufferIndex The bufferIndex to use * @param[in] elapsedSeconds Time elapsed time since the last frame (in seconds) + * @return Whether we should keep rendering. */ - void Update(BufferIndex bufferIndex, float elapsedSeconds); + bool Update(BufferIndex bufferIndex, float elapsedSeconds); /** * Called by the UpdateManager when the node hierarchy changes. diff --git a/dali/internal/update/manager/scene-graph-frame-callback.cpp b/dali/internal/update/manager/scene-graph-frame-callback.cpp index 1f8aa62..e5011fc 100644 --- a/dali/internal/update/manager/scene-graph-frame-callback.cpp +++ b/dali/internal/update/manager/scene-graph-frame-callback.cpp @@ -1,5 +1,5 @@ /* - * 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. @@ -52,9 +52,11 @@ void FrameCallback::ConnectToSceneGraph(UpdateManager& updateManager, TransformM rootNode.AddObserver(*this); } -bool FrameCallback::Update(BufferIndex bufferIndex, float elapsedSeconds, bool nodeHierarchyChanged) +FrameCallback::RequestFlags FrameCallback::Update(BufferIndex bufferIndex, float elapsedSeconds, bool nodeHierarchyChanged) { bool continueCalling = false; + bool keepRendering = false; + if(mUpdateProxy) { mUpdateProxy->SetCurrentBufferIndex(bufferIndex); @@ -68,11 +70,12 @@ bool FrameCallback::Update(BufferIndex bufferIndex, float elapsedSeconds, bool n if(mFrameCallbackInterface && mValid) { Dali::UpdateProxy updateProxy(*mUpdateProxy); - mFrameCallbackInterface->Update(updateProxy, elapsedSeconds); + keepRendering = mFrameCallbackInterface->Update(updateProxy, elapsedSeconds); continueCalling = true; } } - return continueCalling; + + return static_cast(continueCalling | (keepRendering << 1)); } void FrameCallback::Invalidate() diff --git a/dali/internal/update/manager/scene-graph-frame-callback.h b/dali/internal/update/manager/scene-graph-frame-callback.h index 4d3a061..0481253 100644 --- a/dali/internal/update/manager/scene-graph-frame-callback.h +++ b/dali/internal/update/manager/scene-graph-frame-callback.h @@ -2,7 +2,7 @@ #define DALI_INTERNAL_SCENE_GRAPH_FRAME_CALLBACK_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. @@ -45,6 +45,16 @@ class FrameCallback final : public PropertyOwner::Observer { public: /** + * A set of bit mask options that, when combined, define the requests from this FrameCallback + * after being called from the update-thread. + */ + enum RequestFlags + { + CONTINUE_CALLING = 1 << 0, ///< True if we request to continue calling this FrameCallback. + KEEP_RENDERING = 1 << 1 ///< True if we request to keep rendering + }; + + /** * Creates a new FrameCallback. * @param[in] frameCallbackInterface A reference to the FrameCallbackInterface implementation * @return A new FrameCallback. @@ -76,9 +86,9 @@ public: * @param[in] bufferIndex The bufferIndex to use * @param[in] elapsedSeconds Time elapsed time since the last frame (in seconds) * @param[in] nodeHierarchyChanged Whether the node hierarchy has changed - * @return Whether to continue calling this FrameCallback or not. + * @return The requests from this FrameCallback. */ - bool Update(BufferIndex bufferIndex, float elapsedSeconds, bool nodeHierarchyChanged); + RequestFlags Update(BufferIndex bufferIndex, float elapsedSeconds, bool nodeHierarchyChanged); /** * Invalidates this FrameCallback and will no longer be associated with the FrameCallbackInterface. diff --git a/dali/internal/update/manager/update-manager.cpp b/dali/internal/update/manager/update-manager.cpp index 808c8fd..0ae0a48 100644 --- a/dali/internal/update/manager/update-manager.cpp +++ b/dali/internal/update/manager/update-manager.cpp @@ -1051,7 +1051,7 @@ uint32_t UpdateManager::Update(float elapsedSeconds, // Call the frame-callback-processor if set if(mImpl->frameCallbackProcessor) { - mImpl->frameCallbackProcessor->Update(bufferIndex, elapsedSeconds); + keepRendererRendering |= mImpl->frameCallbackProcessor->Update(bufferIndex, elapsedSeconds); } // Update node hierarchy, apply constraints, -- 2.7.4