Add IsRunning flag to async size computation
authorBowon Ryu <bowon.ryu@samsung.com>
Tue, 16 Jul 2024 07:37:54 +0000 (16:37 +0900)
committerBowon Ryu <bowon.ryu@samsung.com>
Tue, 16 Jul 2024 07:37:54 +0000 (16:37 +0900)
Duplicate size computation requests are ignored,
and only the last requested asynchronous size computation is performed.

Change-Id: Ia9c899ec846c959b933e4e72516737b50bacdcdd
Signed-off-by: Bowon Ryu <bowon.ryu@samsung.com>
dali-toolkit/internal/visuals/text/text-visual.cpp
dali-toolkit/internal/visuals/text/text-visual.h

index b8670aa..07307f4 100644 (file)
@@ -272,7 +272,9 @@ TextVisual::TextVisual(VisualFactoryCache& factoryCache, TextVisualShaderFactory
   mRendererUpdateNeeded(false),
   mTextRequireRender(false),
   mTaskId(0u),
-  mIsTaskRunning(false)
+  mSizeTaskId(0u),
+  mIsTaskRunning(false),
+  mIsSizeTaskRunning(false)
 {
   // Enable the pre-multiplied alpha to improve the text quality
   mImpl->mFlags |= Impl::IS_PREMULTIPLIED_ALPHA;
@@ -710,7 +712,16 @@ void TextVisual::LoadComplete(bool loadingSuccess, TextInformation textInformati
 {
   DALI_LOG_RELEASE_INFO("-->TextVisual::LoadComplete\n");
 
-  mIsTaskRunning = false;
+  Text::AsyncTextParameters parameters = textInformation.parameters;
+
+  if(parameters.requestType == Text::Async::COMPUTE_NATURAL_SIZE || parameters.requestType == Text::Async::COMPUTE_HEIGHT_FOR_WIDTH)
+  {
+    mIsSizeTaskRunning = false;
+  }
+  else
+  {
+    mIsTaskRunning = false;
+  }
 
   Toolkit::Visual::ResourceStatus resourceStatus;
 
@@ -719,7 +730,6 @@ void TextVisual::LoadComplete(bool loadingSuccess, TextInformation textInformati
     resourceStatus = Toolkit::Visual::ResourceStatus::READY;
 
     Text::AsyncTextRenderInfo renderInfo = textInformation.renderInfo;
-    Text::AsyncTextParameters parameters = textInformation.parameters;
 
     if(parameters.requestType == Text::Async::COMPUTE_NATURAL_SIZE || parameters.requestType == Text::Async::COMPUTE_HEIGHT_FOR_WIDTH)
     {
@@ -981,8 +991,18 @@ void TextVisual::RequestAsyncSizeComputation(Text::AsyncTextParameters& paramete
 {
   DALI_LOG_RELEASE_INFO("-->TextVisual::RequestAsyncSizeComputation RequestLoad\n");
 
+  // This does not mean whether task is actually running or waiting.
+  // It is whether text visual received a completion callback after requesting a task.
+  if(mIsSizeTaskRunning)
+  {
+    Text::AsyncTextManager::Get().RequestCancel(mSizeTaskId);
+  }
+
+  DALI_LOG_RELEASE_INFO("-->TextVisual::UpdateAsyncRenderer RequestLoad\n");
+
+  mIsSizeTaskRunning = true;
   TextLoadObserver* textLoadObserver = this;
-  Text::AsyncTextManager::Get().RequestLoad(parameters, textLoadObserver);
+  mSizeTaskId = Text::AsyncTextManager::Get().RequestLoad(parameters, textLoadObserver);
 }
 
 void TextVisual::UpdateAsyncRenderer(Text::AsyncTextParameters& parameters)
index 55f46e3..25ac1c3 100644 (file)
@@ -399,7 +399,9 @@ private:
   RendererContainer mRendererList;
 
   uint32_t          mTaskId;                           ///< The currently requested task Id.
-  bool              mIsTaskRunning;                    ///< Whether the requested task is running or not.
+  uint32_t          mSizeTaskId;                       ///< The currently requested size task Id.
+  bool              mIsTaskRunning    : 1;             ///< Whether the requested task is running or not.
+  bool              mIsSizeTaskRunning :1;             ///< Whether the requested size task is running or not.
 };
 
 } // namespace Internal