From: Bowon Ryu Date: Wed, 10 Jul 2024 08:36:48 +0000 (+0900) Subject: Optimization of constraint in async text X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5d89fec23d213746ca8593210ba73177607d0602;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git Optimization of constraint in async text In constraint mode, both the natural size of the text and the height for width should be calculated. Avoids redundant calculations of Initialize and Update, and calculates only the Layout anew as needed. Change-Id: I49ba19e0f0844a1941bdecc825e0fa19ab2fc40a Signed-off-by: Bowon Ryu --- diff --git a/dali-toolkit/internal/text/async-text/async-text-loader-impl.cpp b/dali-toolkit/internal/text/async-text/async-text-loader-impl.cpp index f81d1b9..74fcfa0 100644 --- a/dali-toolkit/internal/text/async-text/async-text-loader-impl.cpp +++ b/dali-toolkit/internal/text/async-text/async-text-loader-impl.cpp @@ -1082,9 +1082,13 @@ AsyncTextRenderInfo AsyncTextLoader::RenderText(AsyncTextParameters& parameters) if(parameters.renderType == AsyncTextParameters::FIXED_WIDTH || parameters.renderType == AsyncTextParameters::CONSTRAINT) { - uint32_t height = ComputeHeightForWidth(parameters, parameters.textWidth); + // In case of CONSTRAINT, the natural size has already been calculated. + // So we can skip Initialize and Update at this stage. + // Only the layout is newly calculated to obtain the height. + bool layoutOnly = (parameters.renderType == AsyncTextParameters::CONSTRAINT); + float height = ComputeHeightForWidth(parameters, parameters.textWidth, layoutOnly); - // textHeight is heightConstraint + // textHeight is heightConstraint. if(parameters.textHeight < height) { bool layoutUpdated = false; @@ -1109,7 +1113,7 @@ AsyncTextRenderInfo AsyncTextLoader::RenderText(AsyncTextParameters& parameters) return Render(parameters); } -uint32_t AsyncTextLoader::ComputeHeightForWidth(AsyncTextParameters& parameters, uint32_t width) +float AsyncTextLoader::ComputeHeightForWidth(AsyncTextParameters& parameters, float width, bool layoutOnly) { DALI_LOG_RELEASE_INFO("-->AsyncTextLoader::ComputeHeightForWidth\n"); @@ -1119,10 +1123,13 @@ uint32_t AsyncTextLoader::ComputeHeightForWidth(AsyncTextParameters& parameters, parameters.textWidth = width; parameters.textHeight = MAX_FLOAT; - Initialize(); - Update(parameters); - bool layoutUpdated = false; + if(!layoutOnly) + { + Initialize(); + Update(parameters); + } + bool layoutUpdated = false; Size layoutSize = Layout(parameters, layoutUpdated); // Restore actual size. @@ -1258,7 +1265,11 @@ AsyncTextRenderInfo AsyncTextLoader::RenderTextFit(AsyncTextParameters& paramete if(parameters.renderType == AsyncTextParameters::FIXED_WIDTH || parameters.renderType == AsyncTextParameters::CONSTRAINT) { - uint32_t height = ComputeHeightForWidth(parameters, parameters.textWidth); + // In case of CONSTRAINT, the natural size has already been calculated. + // So we can skip Initialize and Update at this stage. + // Only the layout is newly calculated to obtain the height. + bool layoutOnly = (parameters.renderType == AsyncTextParameters::CONSTRAINT); + float height = ComputeHeightForWidth(parameters, parameters.textWidth, layoutOnly); // textHeight is heightConstraint if(parameters.textHeight > height) diff --git a/dali-toolkit/internal/text/async-text/async-text-loader-impl.h b/dali-toolkit/internal/text/async-text/async-text-loader-impl.h index f7d80d9..432a695 100644 --- a/dali-toolkit/internal/text/async-text/async-text-loader-impl.h +++ b/dali-toolkit/internal/text/async-text/async-text-loader-impl.h @@ -141,10 +141,11 @@ private: * * @param[in] parameters All options required to compute height of text. * @param[in] width The width of text to compute. + * @param[in] layoutOnly If there is no need to Initialize/Update, only the Layout is performed. * * @return The height for width of text. */ - uint32_t ComputeHeightForWidth(AsyncTextParameters& parameters, uint32_t width); + float ComputeHeightForWidth(AsyncTextParameters& parameters, float width, bool layoutOnly); /** * @brief Check if the text fits.