Fix async text issue during scene on/off
authorBowon Ryu <bowon.ryu@samsung.com>
Wed, 24 Jul 2024 09:24:06 +0000 (18:24 +0900)
committerBowon Ryu <bowon.ryu@samsung.com>
Wed, 24 Jul 2024 09:24:06 +0000 (18:24 +0900)
Cancel running async render task when scene off.
Async size computation works regardless of scene status.

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

index 88ea007..c3ede91 100644 (file)
@@ -324,13 +324,13 @@ void TextLabel::SetProperty(BaseObject* object, Property::Index index, const Pro
 
         DALI_LOG_INFO(gLogFilter, Debug::Verbose, "TextLabel::SetProperty Property::FONT_FAMILY newFont(%s)\n", fontFamily.c_str());
         impl.mController->SetDefaultFontFamily(fontFamily);
-        impl.mIsPropertyUpdated = true;
+        impl.mIsAsyncRenderNeeded = true;
         break;
       }
       case Toolkit::TextLabel::Property::FONT_STYLE:
       {
         SetFontStyleProperty(impl.mController, value, Text::FontStyle::DEFAULT);
-        impl.mIsPropertyUpdated = true;
+        impl.mIsAsyncRenderNeeded = true;
         break;
       }
       case Toolkit::TextLabel::Property::POINT_SIZE:
@@ -340,14 +340,14 @@ void TextLabel::SetProperty(BaseObject* object, Property::Index index, const Pro
         if(!Equals(impl.mController->GetDefaultFontSize(Text::Controller::POINT_SIZE), pointSize))
         {
           impl.mController->SetDefaultFontSize(pointSize, Text::Controller::POINT_SIZE);
-          impl.mIsPropertyUpdated = true;
+          impl.mIsAsyncRenderNeeded = true;
         }
         break;
       }
       case Toolkit::TextLabel::Property::MULTI_LINE:
       {
         impl.mController->SetMultiLineEnabled(value.Get<bool>());
-        impl.mIsPropertyUpdated = true;
+        impl.mIsAsyncRenderNeeded = true;
         break;
       }
       case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
@@ -356,7 +356,7 @@ void TextLabel::SetProperty(BaseObject* object, Property::Index index, const Pro
         if(Text::GetHorizontalAlignmentEnumeration(value, alignment))
         {
           impl.mController->SetHorizontalAlignment(alignment);
-          impl.mIsPropertyUpdated = true;
+          impl.mIsAsyncRenderNeeded = true;
         }
         break;
       }
@@ -366,7 +366,7 @@ void TextLabel::SetProperty(BaseObject* object, Property::Index index, const Pro
         if(Text::GetVerticalAlignmentEnumeration(value, alignment))
         {
           impl.mController->SetVerticalAlignment(alignment);
-          impl.mIsPropertyUpdated = true;
+          impl.mIsAsyncRenderNeeded = true;
         }
         break;
       }
@@ -406,7 +406,7 @@ void TextLabel::SetProperty(BaseObject* object, Property::Index index, const Pro
           {
             impl.mController->SetAutoScrollEnabled(enableAutoScroll);
           }
-          impl.mIsPropertyUpdated = true;
+          impl.mIsAsyncRenderNeeded = true;
         }
         break;
       }
@@ -477,7 +477,7 @@ void TextLabel::SetProperty(BaseObject* object, Property::Index index, const Pro
         if(!Equals(impl.mController->GetDefaultFontSize(Text::Controller::PIXEL_SIZE), pixelSize))
         {
           impl.mController->SetDefaultFontSize(pixelSize, Text::Controller::PIXEL_SIZE);
-          impl.mIsPropertyUpdated = true;
+          impl.mIsAsyncRenderNeeded = true;
         }
         break;
       }
@@ -487,7 +487,7 @@ void TextLabel::SetProperty(BaseObject* object, Property::Index index, const Pro
         DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis);
 
         impl.mController->SetTextElideEnabled(ellipsis);
-        impl.mIsPropertyUpdated = true;
+        impl.mIsAsyncRenderNeeded = true;
         break;
       }
       case Toolkit::TextLabel::Property::LINE_WRAP_MODE:
@@ -497,7 +497,7 @@ void TextLabel::SetProperty(BaseObject* object, Property::Index index, const Pro
         {
           DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel %p LineWrap::MODE %d\n", impl.mController.Get(), lineWrapMode);
           impl.mController->SetLineWrapMode(lineWrapMode);
-          impl.mIsPropertyUpdated = true;
+          impl.mIsAsyncRenderNeeded = true;
         }
         break;
       }
@@ -514,7 +514,7 @@ void TextLabel::SetProperty(BaseObject* object, Property::Index index, const Pro
 
           // No need to trigger full re-layout. Instead call UpdateRenderer() directly
           TextVisual::UpdateRenderer(impl.mVisual);
-          impl.mIsPropertyUpdated = true;
+          impl.mIsAsyncRenderNeeded = true;
         }
         break;
       }
@@ -526,13 +526,13 @@ void TextLabel::SetProperty(BaseObject* object, Property::Index index, const Pro
       case Toolkit::DevelTextLabel::Property::IGNORE_SPACES_AFTER_TEXT:
       {
         impl.mController->SetIgnoreSpacesAfterText(value.Get<bool>());
-        impl.mIsPropertyUpdated = true;
+        impl.mIsAsyncRenderNeeded = true;
         break;
       }
       case Toolkit::DevelTextLabel::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
       {
         impl.mController->SetMatchLayoutDirection(value.Get<bool>() ? DevelText::MatchLayoutDirection::LOCALE : DevelText::MatchLayoutDirection::CONTENTS);
-        impl.mIsPropertyUpdated = true;
+        impl.mIsAsyncRenderNeeded = true;
         break;
       }
       case Toolkit::DevelTextLabel::Property::TEXT_FIT:
@@ -546,7 +546,7 @@ void TextLabel::SetProperty(BaseObject* object, Property::Index index, const Pro
 
         ParseTextFitProperty(impl.mController, value.GetMap());
         impl.mController->SetTextFitChanged(true);
-        impl.mIsPropertyUpdated = true;
+        impl.mIsAsyncRenderNeeded = true;
         break;
       }
       case Toolkit::DevelTextLabel::Property::MIN_LINE_SIZE:
@@ -558,7 +558,7 @@ void TextLabel::SetProperty(BaseObject* object, Property::Index index, const Pro
           impl.mTextUpdateNeeded = impl.mController->SetDefaultLineSize(lineSize) || impl.mTextUpdateNeeded;
         }
         impl.mController->SetCurrentLineSize(lineSize);
-        impl.mIsPropertyUpdated = true;
+        impl.mIsAsyncRenderNeeded = true;
         break;
       }
       case Toolkit::DevelTextLabel::Property::FONT_SIZE_SCALE:
@@ -569,7 +569,7 @@ void TextLabel::SetProperty(BaseObject* object, Property::Index index, const Pro
         if(!Equals(impl.mController->GetFontSizeScale(), scale))
         {
           impl.mController->SetFontSizeScale(scale);
-          impl.mIsPropertyUpdated = true;
+          impl.mIsAsyncRenderNeeded = true;
         }
         break;
       }
@@ -579,7 +579,7 @@ void TextLabel::SetProperty(BaseObject* object, Property::Index index, const Pro
         if(!Equals(impl.mController->IsFontSizeScaleEnabled(), enableFontSizeScale))
         {
           impl.mController->SetFontSizeScaleEnabled(enableFontSizeScale);
-          impl.mIsPropertyUpdated = true;
+          impl.mIsAsyncRenderNeeded = true;
         }
         break;
       }
@@ -590,7 +590,7 @@ void TextLabel::SetProperty(BaseObject* object, Property::Index index, const Pro
         {
           DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel %p EllipsisPosition::Type %d\n", impl.mController.Get(), ellipsisPositionType);
           impl.mController->SetEllipsisPosition(ellipsisPositionType);
-          impl.mIsPropertyUpdated = true;
+          impl.mIsAsyncRenderNeeded = true;
         }
         break;
       }
@@ -603,7 +603,7 @@ void TextLabel::SetProperty(BaseObject* object, Property::Index index, const Pro
       {
         const float characterSpacing = value.Get<float>();
         impl.mController->SetCharacterSpacing(characterSpacing);
-        impl.mIsPropertyUpdated = true;
+        impl.mIsAsyncRenderNeeded = true;
         break;
       }
       case Toolkit::DevelTextLabel::Property::RELATIVE_LINE_SIZE:
@@ -612,7 +612,7 @@ void TextLabel::SetProperty(BaseObject* object, Property::Index index, const Pro
         DALI_LOG_INFO(gLogFilter, Debug::Verbose, "TextLabel %p RELATIVE_LINE_SIZE %f\n", impl.mController.Get(), relativeLineSize);
 
         impl.mController->SetRelativeLineSize(relativeLineSize);
-        impl.mIsPropertyUpdated = true;
+        impl.mIsAsyncRenderNeeded = true;
         break;
       }
       case Toolkit::DevelTextLabel::Property::ANCHOR_COLOR:
@@ -639,14 +639,14 @@ void TextLabel::SetProperty(BaseObject* object, Property::Index index, const Pro
       {
         const bool remove = value.Get<bool>();
         impl.mController->SetRemoveFrontInset(remove);
-        impl.mIsPropertyUpdated = true;
+        impl.mIsAsyncRenderNeeded = true;
         break;
       }
       case Toolkit::DevelTextLabel::Property::REMOVE_BACK_INSET:
       {
         const bool remove = value.Get<bool>();
         impl.mController->SetRemoveBackInset(remove);
-        impl.mIsPropertyUpdated = true;
+        impl.mIsAsyncRenderNeeded = true;
         break;
       }
       case Toolkit::DevelTextLabel::Property::CUTOUT:
@@ -654,7 +654,7 @@ void TextLabel::SetProperty(BaseObject* object, Property::Index index, const Pro
         const bool cutout = value.Get<bool>();
 
         impl.mController->SetTextCutout(cutout);
-        impl.mIsPropertyUpdated = true;
+        impl.mIsAsyncRenderNeeded = true;
         break;
       }
       case Toolkit::DevelTextLabel::Property::RENDER_MODE:
@@ -670,7 +670,7 @@ void TextLabel::SetProperty(BaseObject* object, Property::Index index, const Pro
           impl.mController->SetRenderMode(renderMode);
           if(renderMode == DevelTextLabel::Render::ASYNC_AUTO)
           {
-            impl.mIsPropertyUpdated = true;
+            impl.RequestTextRelayout();
           }
         }
       }
@@ -683,7 +683,7 @@ void TextLabel::SetProperty(BaseObject* object, Property::Index index, const Pro
     {
       // need to request relayout as size of text may have changed
       impl.RequestTextRelayout();
-      impl.mIsPropertyUpdated = true;
+      impl.mIsAsyncRenderNeeded = true;
     }
   }
 }
@@ -1232,7 +1232,7 @@ void TextLabel::OnPropertySet(Property::Index index, const Property::Value& prop
       {
         mController->SetDefaultColor(textColor);
         mTextUpdateNeeded = true;
-        mIsPropertyUpdated = true;
+        mIsAsyncRenderNeeded = true;
       }
       break;
     }
@@ -1254,7 +1254,7 @@ void TextLabel::OnPropertySet(Property::Index index, const Property::Value& prop
         {
           EnableControlBackground(false);
         }
-        mIsPropertyUpdated = true;
+        mIsAsyncRenderNeeded = true;
       }
       break;
     }
@@ -1278,7 +1278,7 @@ void TextLabel::OnPropertySet(Property::Index index, const Property::Value& prop
         EnableControlBackground(!cutoutEnabled);
         TextVisual::SetRequireRender(mVisual, cutoutEnabled);
       }
-      mIsPropertyUpdated = true;
+      mIsAsyncRenderNeeded = true;
       break;
     }
     default:
@@ -1291,6 +1291,8 @@ void TextLabel::OnPropertySet(Property::Index index, const Property::Value& prop
 
 void TextLabel::OnSceneConnection(int depth)
 {
+  mIsAsyncRenderNeeded = true;
+
   if(mController->IsAutoScrollEnabled() || mLastAutoScrollEnabled)
   {
     mController->SetAutoScrollEnabled(true);
@@ -1300,6 +1302,10 @@ void TextLabel::OnSceneConnection(int depth)
 
 void TextLabel::OnSceneDisconnection()
 {
+  mIsSizeChanged = false;
+  mIsManualRender = false;
+  mIsManualRendered = false;
+
   if(mTextScroller)
   {
     if(mLastAutoScrollEnabled && !mController->IsAutoScrollEnabled())
@@ -1362,13 +1368,13 @@ void TextLabel::OnRelayout(const Vector2& size, RelayoutContainer& container)
       return;
     }
 
-    if(mIsManualRender || !(sizeChanged || mIsPropertyUpdated))
+    if(mIsManualRender || !(sizeChanged || mIsAsyncRenderNeeded))
     {
       // Do not request async render if the manual render is still ongoing or if there are no size or property updates.
       return;
     }
 
-    if(manualRendered && sizeChanged && !mIsPropertyUpdated)
+    if(manualRendered && sizeChanged && !mIsAsyncRenderNeeded)
     {
       // Do not request async render if only the size has changed when manual render is completed.
       // Users may attempt to change the size inside the completed callback post manual render.
@@ -1381,7 +1387,7 @@ void TextLabel::OnRelayout(const Vector2& size, RelayoutContainer& container)
     AsyncTextParameters parameters = GetAsyncTextParameters(Async::RENDER_FIXED_SIZE, contentSize, padding, layoutDirection);
     TextVisual::UpdateAsyncRenderer(mVisual, parameters);
     mTextUpdateNeeded = false;
-    mIsPropertyUpdated = false;
+    mIsAsyncRenderNeeded = false;
     return;
   }
 
@@ -1775,7 +1781,7 @@ TextLabel::TextLabel(ControlBehaviour additionalBehaviour)
   mTextUpdateNeeded(false),
   mLastAutoScrollEnabled(false),
   mControlBackgroundEnabeld(true),
-  mIsPropertyUpdated(false),
+  mIsAsyncRenderNeeded(false),
   mIsSizeChanged(false),
   mIsManualRender(false),
   mIsManualRendered(false),
@@ -1906,8 +1912,6 @@ void TextLabel::RequestAsyncRenderWithFixedSize(float width, float height)
     return;
   }
 
-  mIsManualRender = true;
-
   Actor self = Self();
 
   Extents padding;
@@ -1927,9 +1931,9 @@ void TextLabel::RequestAsyncRenderWithFixedSize(float width, float height)
   AsyncTextParameters parameters = GetAsyncTextParameters(Async::RENDER_FIXED_SIZE, contentSize, padding, layoutDirection);
   parameters.manualRender = true;
 
-  TextVisual::UpdateAsyncRenderer(mVisual, parameters);
+  mIsManualRender = TextVisual::UpdateAsyncRenderer(mVisual, parameters);
   mTextUpdateNeeded = false;
-  mIsPropertyUpdated = false;
+  mIsAsyncRenderNeeded = false;
 }
 
 void TextLabel::RequestAsyncRenderWithFixedWidth(float width, float heightConstraint)
@@ -1942,8 +1946,6 @@ void TextLabel::RequestAsyncRenderWithFixedWidth(float width, float heightConstr
     return;
   }
 
-  mIsManualRender = true;
-
   Actor self = Self();
 
   Extents padding;
@@ -1963,9 +1965,9 @@ void TextLabel::RequestAsyncRenderWithFixedWidth(float width, float heightConstr
   AsyncTextParameters parameters = GetAsyncTextParameters(Async::RENDER_FIXED_WIDTH, contentSize, padding, layoutDirection);
   parameters.manualRender = true;
 
-  TextVisual::UpdateAsyncRenderer(mVisual, parameters);
+  mIsManualRender = TextVisual::UpdateAsyncRenderer(mVisual, parameters);
   mTextUpdateNeeded = false;
-  mIsPropertyUpdated = false;
+  mIsAsyncRenderNeeded = false;
 }
 
 void TextLabel::RequestAsyncRenderWithConstraint(float widthConstraint, float heightConstraint)
@@ -1978,8 +1980,6 @@ void TextLabel::RequestAsyncRenderWithConstraint(float widthConstraint, float he
     return;
   }
 
-  mIsManualRender = true;
-
   Actor self = Self();
 
   Extents padding;
@@ -1999,9 +1999,9 @@ void TextLabel::RequestAsyncRenderWithConstraint(float widthConstraint, float he
   AsyncTextParameters parameters = GetAsyncTextParameters(Async::RENDER_CONSTRAINT, contentSize, padding, layoutDirection);
   parameters.manualRender = true;
 
-  TextVisual::UpdateAsyncRenderer(mVisual, parameters);
+  mIsManualRender = TextVisual::UpdateAsyncRenderer(mVisual, parameters);
   mTextUpdateNeeded = false;
-  mIsPropertyUpdated = false;
+  mIsAsyncRenderNeeded = false;
 }
 
 std::string TextLabel::TextLabelAccessible::GetNameRaw() const
index 4f9fbe1..ddd6e48 100644 (file)
@@ -494,11 +494,11 @@ private: // Data
   bool mLastAutoScrollEnabled    : 1;
   bool mControlBackgroundEnabeld : 1;
 
-  bool mIsPropertyUpdated : 1; // true if a render request is required in ASYNC_AUTO mode, otherwise false.
-  bool mIsSizeChanged     : 1; // whether the size has been changed or not.
-  bool mIsManualRender    : 1; // whether an async manual render has been requested, returns false when completed.
-  bool mIsManualRendered  : 1; // whether an async manual render has been completed, returns false on the next relayout.
-  bool mManualRendered    : 1;
+  bool mIsAsyncRenderNeeded : 1; // true if a render request is required in ASYNC_AUTO mode, otherwise false.
+  bool mIsSizeChanged       : 1; // whether the size has been changed or not.
+  bool mIsManualRender      : 1; // whether an async manual render has been requested, returns false when completed.
+  bool mIsManualRendered    : 1; // whether an async manual render has been completed, returns false on the next relayout.
+  bool mManualRendered      : 1;
 
 protected:
   /**
index 6256104..a843f40 100644 (file)
@@ -387,6 +387,12 @@ void TextVisual::RemoveRenderer(Actor& actor, bool removeDefaultRenderer)
 
 void TextVisual::DoSetOffScene(Actor& actor)
 {
+  if(mController->GetRenderMode() != DevelTextLabel::Render::SYNC && mIsRenderTaskRunning)
+  {
+    DALI_LOG_RELEASE_INFO("-->TextVisual::DoSetOffScene RequestCancel:%u\n", mRenderTaskId);
+    Text::AsyncTextManager::Get().RequestCancel(mRenderTaskId);
+    mIsRenderTaskRunning = false;
+  }
   if(mColorConstraint)
   {
     mColorConstraint.Remove();
@@ -1049,14 +1055,14 @@ void TextVisual::RequestAsyncSizeComputation(Text::AsyncTextParameters& paramete
   }
 }
 
-void TextVisual::UpdateAsyncRenderer(Text::AsyncTextParameters& parameters)
+bool TextVisual::UpdateAsyncRenderer(Text::AsyncTextParameters& parameters)
 {
   Actor control = mControl.GetHandle();
   if(!control)
   {
     // Nothing to do.
     ResourceReady(Toolkit::Visual::ResourceStatus::READY);
-    return;
+    return false;
   }
 
   if(parameters.requestType == Text::Async::RENDER_FIXED_SIZE &&
@@ -1067,7 +1073,7 @@ void TextVisual::UpdateAsyncRenderer(Text::AsyncTextParameters& parameters)
 
     // Nothing else to do if the relayout size is zero.
     ResourceReady(Toolkit::Visual::ResourceStatus::READY);
-    return;
+    return false;
   }
 
   // Get the maximum texture size.
@@ -1091,6 +1097,8 @@ void TextVisual::UpdateAsyncRenderer(Text::AsyncTextParameters& parameters)
   mIsRenderTaskRunning = true;
   TextLoadObserver* textLoadObserver = this;
   mRenderTaskId = Text::AsyncTextManager::Get().RequestLoad(parameters, textLoadObserver);
+
+  return true;
 }
 
 void TextVisual::AddRenderer(Actor& actor, const Vector2& size, bool hasMultipleTextColors, bool containsColorGlyph, bool styleEnabled, bool isOverlayStyle)
index c84c2e0..65d5361 100644 (file)
@@ -140,10 +140,11 @@ public:
    * @brief Instantly updates the async renderer
    * @param[in] visual The text visual.
    * @param[in] parameters The async text parameters.
+   * @return true if the async text render request was successful, false otherwise.
    */
-  static void UpdateAsyncRenderer(Toolkit::Visual::Base visual, Text::AsyncTextParameters& parameters)
+  static bool UpdateAsyncRenderer(Toolkit::Visual::Base visual, Text::AsyncTextParameters& parameters)
   {
-    GetVisualObject(visual).UpdateAsyncRenderer(parameters);
+    return GetVisualObject(visual).UpdateAsyncRenderer(parameters);
   };
 
   /**
@@ -279,8 +280,9 @@ private:
   /**
    * @brief Updates the text's async renderer.
    * @param[in] parameters The async text parameters.
+   * @return true if the async text render request was successful, false otherwise.
    */
-  void UpdateAsyncRenderer(Text::AsyncTextParameters& parameters);
+  bool UpdateAsyncRenderer(Text::AsyncTextParameters& parameters);
 
   /**
    * @brief Requests the async size computation.