From: Adeel Kazmi Date: Tue, 7 Jun 2022 09:59:22 +0000 (+0000) Subject: Merge "Minor reduce textlabel creation time." into devel/master X-Git-Tag: dali_2.1.26~9 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=3b814735ce65594bfe644190ed83c381edb66c88;hp=aeddb4e028e43d5c25729f1b0e947c1138a8779d Merge "Minor reduce textlabel creation time." into devel/master --- diff --git a/dali-toolkit/devel-api/styling/style-manager-devel.cpp b/dali-toolkit/devel-api/styling/style-manager-devel.cpp index cc96d45..d7778d8 100644 --- a/dali-toolkit/devel-api/styling/style-manager-devel.cpp +++ b/dali-toolkit/devel-api/styling/style-manager-devel.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 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. @@ -25,7 +25,7 @@ namespace Toolkit { namespace DevelStyleManager { -const Property::Map GetConfigurations(StyleManager styleManager) +const Property::Map& GetConfigurations(StyleManager styleManager) { return GetImpl(styleManager).GetConfigurations(); } diff --git a/dali-toolkit/devel-api/styling/style-manager-devel.h b/dali-toolkit/devel-api/styling/style-manager-devel.h index f1e05d7..23c7999 100644 --- a/dali-toolkit/devel-api/styling/style-manager-devel.h +++ b/dali-toolkit/devel-api/styling/style-manager-devel.h @@ -2,7 +2,7 @@ #define DALI_TOOLKIT_STYLE_MANAGER_DEVEL_H /* - * Copyright (c) 2020 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. @@ -46,7 +46,7 @@ using BrokenImageChangedSignalType = Signal; * @param[in] styleManager The instance of StyleManager * @return A property map to the currently defined configurations **/ -DALI_TOOLKIT_API const Property::Map GetConfigurations(StyleManager styleManager); +DALI_TOOLKIT_API const Property::Map& GetConfigurations(StyleManager styleManager); /** * @brief Sets an image to be used when a visual has failed to correctly render diff --git a/dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.cpp b/dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.cpp index 4383c1a..20186ef 100644 --- a/dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.cpp +++ b/dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.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. @@ -183,8 +183,10 @@ void KeyboardFocusManager::GetConfigurationFromStyleManger() Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get(); if(styleManager) { - Property::Map config = Toolkit::DevelStyleManager::GetConfigurations(styleManager); - mAlwaysShowIndicator = config["alwaysShowFocus"].Get() ? ALWAYS_SHOW : NONE; + const Property::Map& config = Toolkit::DevelStyleManager::GetConfigurations(styleManager); + const auto alwaysShowFocusValue = config.Find("alwaysShowFocus", Property::Type::BOOLEAN); + + mAlwaysShowIndicator = (alwaysShowFocusValue && alwaysShowFocusValue->Get()) ? ALWAYS_SHOW : NONE; mIsFocusIndicatorShown = (mAlwaysShowIndicator == ALWAYS_SHOW) ? SHOW : HIDE; mClearFocusOnTouch = (mIsFocusIndicatorShown == SHOW) ? false : true; } @@ -520,16 +522,16 @@ bool KeyboardFocusManager::MoveFocus(Toolkit::Control::KeyboardFocus::Direction nextFocusableActor = mPreFocusChangeSignal.Emit(currentFocusActor, Actor(), direction); mIsWaitingKeyboardFocusChangeCommit = false; } - else if (mEnableDefaultAlgorithm) + else if(mEnableDefaultAlgorithm) { Actor rootActor = mFocusFinderRootActor.GetHandle(); if(!rootActor) { - if (currentFocusActor) + if(currentFocusActor) { // Find the window of the focused actor. Integration::SceneHolder window = Integration::SceneHolder::Get(currentFocusActor); - if (window) + if(window) { rootActor = window.GetRootLayer(); } @@ -799,7 +801,7 @@ Actor KeyboardFocusManager::GetFocusIndicatorActor() void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event) { - const std::string& keyName = event.GetKeyName(); + const std::string& keyName = event.GetKeyName(); const std::string& deviceName = event.GetDeviceName(); if(mIsFocusIndicatorShown == UNKNOWN) @@ -1045,8 +1047,8 @@ void KeyboardFocusManager::OnWheelEvent(const WheelEvent& event) bool KeyboardFocusManager::OnCustomWheelEvent(const WheelEvent& event) { - bool consumed = false; - Actor actor = GetCurrentFocusActor(); + bool consumed = false; + Actor actor = GetCurrentFocusActor(); if(actor) { // Notify the actor about the wheel event diff --git a/dali-toolkit/internal/styling/style-manager-impl.cpp b/dali-toolkit/internal/styling/style-manager-impl.cpp index 959724b..e6ad82f 100644 --- a/dali-toolkit/internal/styling/style-manager-impl.cpp +++ b/dali-toolkit/internal/styling/style-manager-impl.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. @@ -285,44 +285,40 @@ void StyleManager::SetTheme(const std::string& themeFile) } } -const Property::Map StyleManager::GetConfigurations() +const Property::Map& StyleManager::GetConfigurations() { DALI_LOG_STREAM(gLogFilter, Debug::Concise, "GetConfigurations()\n On entry, mThemeBuilder: " << (bool(mThemeBuilder) ? "Created" : "Empty") << " mThemeFile: " << mThemeFile); - Property::Map result; - if(mThemeBuilder) - { - result = mThemeBuilder.GetConfigurations(); - } - else + if(!mThemeBuilder) { DALI_LOG_STREAM(gLogFilter, Debug::Concise, "GetConfigurations() Loading default theme"); - bool themeLoaded = false; - mThemeBuilder = CreateBuilder(mThemeBuilderConstants); // Load default theme because this is first try to load stylesheet. - themeLoaded = LoadJSON(mThemeBuilder, mDefaultThemeFilePath); - mThemeFile = mDefaultThemeFilePath; - - if(themeLoaded) - { - result = mThemeBuilder.GetConfigurations(); - } +#if defined(DEBUG_ENABLED) + bool themeLoaded = LoadJSON(mThemeBuilder, mDefaultThemeFilePath); DALI_LOG_STREAM(gLogFilter, Debug::Concise, " themeLoaded" << (themeLoaded ? "success" : "failure")); +#else + LoadJSON(mThemeBuilder, mDefaultThemeFilePath); +#endif + + mThemeFile = mDefaultThemeFilePath; } +#if defined(DEBUG_ENABLED) + Property::Map result = mThemeBuilder.GetConfigurations(); DALI_LOG_STREAM(gLogFilter, Debug::Concise, "GetConfigurations()\n On exit, result Count: " << (result.Count() != 0)); DALI_LOG_STREAM(gLogFilter, Debug::Verbose, " result: " << result); +#endif - return result; + return mThemeBuilder.GetConfigurations(); } void StyleManager::SetBrokenImageUrl(DevelStyleManager::BrokenImageType brokenImageType, const std::string& brokenImageUrl) { - int brokenType = static_cast(brokenImageType); - mBrokenImageUrls[brokenType] = brokenImageUrl; + int brokenType = static_cast(brokenImageType); + mBrokenImageUrls[brokenType] = brokenImageUrl; Toolkit::StyleManager styleManager = StyleManager::Get(); mBrokenImageChangedSignal.Emit(styleManager); } diff --git a/dali-toolkit/internal/styling/style-manager-impl.h b/dali-toolkit/internal/styling/style-manager-impl.h index 56e61f0..3aacf79 100644 --- a/dali-toolkit/internal/styling/style-manager-impl.h +++ b/dali-toolkit/internal/styling/style-manager-impl.h @@ -2,7 +2,7 @@ #define DALI_TOOLKIT_INTERNAL_STYLE_MANAGER_H /* - * 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. @@ -28,9 +28,9 @@ // INTERNAL INCLUDES #include +#include #include #include -#include namespace Dali { @@ -93,7 +93,7 @@ public: // Public API /** * @copydoc Toolkit::StyleManager::GetConfigurations */ - const Property::Map GetConfigurations(); + const Property::Map& GetConfigurations(); /** * @copydoc Toolkit::DevelStyleManager::SetBrokenImageUrl @@ -255,7 +255,7 @@ private: Toolkit::Internal::FeedbackStyle* mFeedbackStyle; ///< Feedback style - std::vector mBrokenImageUrls; ///< Broken Image Urls received from user + std::vector mBrokenImageUrls; ///< Broken Image Urls received from user // Signals Toolkit::StyleManager::StyleChangedSignalType mControlStyleChangeSignal; ///< Emitted when the style( theme/font ) changes for the controls to style themselves diff --git a/dali-toolkit/internal/text/rendering/text-typesetter.cpp b/dali-toolkit/internal/text/rendering/text-typesetter.cpp index b1502a9..30f76fc 100644 --- a/dali-toolkit/internal/text/rendering/text-typesetter.cpp +++ b/dali-toolkit/internal/text/rendering/text-typesetter.cpp @@ -98,7 +98,6 @@ void TypesetGlyph(GlyphData& data, // Whether the given glyph is a color one. const bool isColorGlyph = data.glyphBitmap.isColorEmoji || data.glyphBitmap.isColorBitmap; const uint32_t glyphPixelSize = Pixel::GetBytesPerPixel(data.glyphBitmap.format); - const uint32_t alphaIndex = glyphPixelSize - 1u; // Determinate iterator range. const int32_t lineIndexRangeMin = std::max(0, -yOffset); @@ -114,9 +113,9 @@ void TypesetGlyph(GlyphData& data, if(Pixel::RGBA8888 == pixelFormat) { - const bool swapChannelsBR = Pixel::BGRA8888 == data.glyphBitmap.format; - uint32_t* bitmapBuffer = reinterpret_cast(data.bitmapBuffer.GetBuffer()); + // Skip basic line. + bitmapBuffer += (lineIndexRangeMin + yOffset) * static_cast(data.width); // Fast-cut if style is MASK or OUTLINE. Outline not shown for color glyph. // Just overwrite transparent color and return. @@ -124,17 +123,17 @@ void TypesetGlyph(GlyphData& data, { for(int32_t lineIndex = lineIndexRangeMin; lineIndex < lineIndexRangeMax; ++lineIndex) { - const int32_t yOffsetIndex = yOffset + lineIndex; - const int32_t verticalOffset = yOffsetIndex * data.width; - // We can use memset here. - memset(bitmapBuffer + verticalOffset + xOffset + indexRangeMin, 0, (indexRangeMax - indexRangeMin) * sizeof(uint32_t)); + memset(bitmapBuffer + xOffset + indexRangeMin, 0, (indexRangeMax - indexRangeMin) * sizeof(uint32_t)); + bitmapBuffer += data.width; } return; } + const bool swapChannelsBR = Pixel::BGRA8888 == data.glyphBitmap.format; + // Pointer to the color glyph if there is one. - const uint32_t* const colorGlyphBuffer = isColorGlyph ? reinterpret_cast(data.glyphBitmap.buffer) : NULL; + const uint8_t* glyphBuffer = data.glyphBitmap.buffer; // Precalculate input color's packed result. uint32_t packedInputColor = 0u; @@ -145,21 +144,20 @@ void TypesetGlyph(GlyphData& data, *(packedInputColorBuffer + 1u) = static_cast(color->g * 255); *(packedInputColorBuffer) = static_cast(color->r * 255); + // Skip basic line of glyph. + glyphBuffer += (lineIndexRangeMin) * static_cast(data.glyphBitmap.width) * glyphPixelSize; + // Traverse the pixels of the glyph line per line. - for(int32_t lineIndex = lineIndexRangeMin; lineIndex < lineIndexRangeMax; ++lineIndex) + if(isColorGlyph) { - const int32_t yOffsetIndex = yOffset + lineIndex; - - const int32_t verticalOffset = yOffsetIndex * data.width; - const int32_t glyphBufferOffset = lineIndex * static_cast(data.glyphBitmap.width); - for(int32_t index = indexRangeMin; index < indexRangeMax; ++index) + for(int32_t lineIndex = lineIndexRangeMin; lineIndex < lineIndexRangeMax; ++lineIndex) { - const int32_t xOffsetIndex = xOffset + index; - - if(isColorGlyph) + for(int32_t index = indexRangeMin; index < indexRangeMax; ++index) { + const int32_t xOffsetIndex = xOffset + index; + // Retrieves the color from the color glyph. - uint32_t packedColorGlyph = *(colorGlyphBuffer + glyphBufferOffset + index); + uint32_t packedColorGlyph = *(reinterpret_cast(glyphBuffer + (index << 2))); uint8_t* packedColorGlyphBuffer = reinterpret_cast(&packedColorGlyph); // Update the alpha channel. @@ -193,23 +191,28 @@ void TypesetGlyph(GlyphData& data, } // Set the color into the final pixel buffer. - *(bitmapBuffer + verticalOffset + xOffsetIndex) = packedColorGlyph; + *(bitmapBuffer + xOffsetIndex) = packedColorGlyph; } - else + bitmapBuffer += data.width; + glyphBuffer += data.glyphBitmap.width * glyphPixelSize; + } + } + else + { + for(int32_t lineIndex = lineIndexRangeMin; lineIndex < lineIndexRangeMax; ++lineIndex) + { + for(int32_t index = indexRangeMin; index < indexRangeMax; ++index) { - // Pack the given color into a 32bit buffer. The alpha channel will be updated later for each pixel. - // The format is RGBA8888. - uint32_t packedColor = 0u; - uint8_t* packedColorBuffer = reinterpret_cast(&packedColor); - // Update the alpha channel. - const uint8_t alpha = *(data.glyphBitmap.buffer + glyphPixelSize * (glyphBufferOffset + index) + alphaIndex); + const uint8_t alpha = *(glyphBuffer + index); // Copy non-transparent pixels only if(alpha > 0u) { + const int32_t xOffsetIndex = xOffset + index; + // Check alpha of overlapped pixels - uint32_t& currentColor = *(bitmapBuffer + verticalOffset + xOffsetIndex); + uint32_t& currentColor = *(bitmapBuffer + xOffsetIndex); uint8_t* packedCurrentColorBuffer = reinterpret_cast(¤tColor); // For any pixel overlapped with the pixel in previous glyphs, make sure we don't @@ -225,6 +228,11 @@ void TypesetGlyph(GlyphData& data, } else { + // Pack the given color into a 32bit buffer. The alpha channel will be updated later for each pixel. + // The format is RGBA8888. + uint32_t packedColor = 0u; + uint8_t* packedColorBuffer = reinterpret_cast(&packedColor); + // Color is pre-muliplied with its alpha. *(packedColorBuffer + 3u) = MultiplyAndNormalizeColor(*(packedInputColorBuffer + 3u), currentAlpha); *(packedColorBuffer + 2u) = MultiplyAndNormalizeColor(*(packedInputColorBuffer + 2u), currentAlpha); @@ -236,35 +244,38 @@ void TypesetGlyph(GlyphData& data, } } } + bitmapBuffer += data.width; + glyphBuffer += data.glyphBitmap.width * glyphPixelSize; } } } - else + else // Pixel::L8 { // Below codes required only if not color glyph. if(!isColorGlyph) { - uint8_t* bitmapBuffer = reinterpret_cast(data.bitmapBuffer.GetBuffer()); + uint8_t* bitmapBuffer = data.bitmapBuffer.GetBuffer(); + const uint8_t* glyphBuffer = data.glyphBitmap.buffer; + + // Skip basic line. + bitmapBuffer += (lineIndexRangeMin + yOffset) * static_cast(data.width); + glyphBuffer += (lineIndexRangeMin) * static_cast(data.glyphBitmap.width); // Traverse the pixels of the glyph line per line. for(int32_t lineIndex = lineIndexRangeMin; lineIndex < lineIndexRangeMax; ++lineIndex) { - const int32_t yOffsetIndex = yOffset + lineIndex; - - const int32_t verticalOffset = yOffsetIndex * data.width; - const int32_t glyphBufferOffset = lineIndex * static_cast(data.glyphBitmap.width); for(int32_t index = indexRangeMin; index < indexRangeMax; ++index) { const int32_t xOffsetIndex = xOffset + index; // Update the alpha channel. - const uint8_t alpha = *(data.glyphBitmap.buffer + glyphPixelSize * (glyphBufferOffset + index) + alphaIndex); + const uint8_t alpha = *(glyphBuffer + index); // Copy non-transparent pixels only if(alpha > 0u) { // Check alpha of overlapped pixels - uint8_t& currentAlpha = *(bitmapBuffer + verticalOffset + xOffsetIndex); + uint8_t& currentAlpha = *(bitmapBuffer + xOffsetIndex); // For any pixel overlapped with the pixel in previous glyphs, make sure we don't // overwrite a previous bigger alpha with a smaller alpha (in order to avoid @@ -273,6 +284,9 @@ void TypesetGlyph(GlyphData& data, currentAlpha = std::max(currentAlpha, alpha); } } + + bitmapBuffer += data.width; + glyphBuffer += data.glyphBitmap.width; } } } diff --git a/dali-toolkit/internal/text/text-controller-impl.h b/dali-toolkit/internal/text/text-controller-impl.h index 5944039..5e28f9c 100644 --- a/dali-toolkit/internal/text/text-controller-impl.h +++ b/dali-toolkit/internal/text/text-controller-impl.h @@ -37,10 +37,10 @@ namespace Toolkit { namespace Text { -const float DEFAULT_TEXTFIT_MIN = 10.f; -const float DEFAULT_TEXTFIT_MAX = 100.f; -const float DEFAULT_TEXTFIT_STEP = 1.f; -const float DEFAULT_FONT_SIZE_SCALE = 1.f; +const float DEFAULT_TEXTFIT_MIN = 10.f; +const float DEFAULT_TEXTFIT_MAX = 100.f; +const float DEFAULT_TEXTFIT_STEP = 1.f; +const float DEFAULT_FONT_SIZE_SCALE = 1.f; const float DEFAULT_DISABLED_COLOR_OPACITY = 0.3f; //Forward declarations @@ -385,12 +385,11 @@ struct Controller::Impl Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get(); if(styleManager) { - bool temp; - Property::Map config = Toolkit::DevelStyleManager::GetConfigurations(styleManager); - if(config["clearFocusOnEscape"].Get(temp)) - { - mShouldClearFocusOnEscape = temp; - } + const Property::Map& config = Toolkit::DevelStyleManager::GetConfigurations(styleManager); + const auto clearFocusOnEscapeValue = config.Find("clearFocusOnEscape", Property::Type::BOOLEAN); + + // Default is true. If config don't have "clearFocusOnEscape" property, make it true. + mShouldClearFocusOnEscape = (!clearFocusOnEscapeValue || clearFocusOnEscapeValue->Get()); } } diff --git a/dali-toolkit/internal/visuals/visual-factory-impl.cpp b/dali-toolkit/internal/visuals/visual-factory-impl.cpp index ce19a6b..a4b0a0a 100644 --- a/dali-toolkit/internal/visuals/visual-factory-impl.cpp +++ b/dali-toolkit/internal/visuals/visual-factory-impl.cpp @@ -388,9 +388,13 @@ void VisualFactory::SetBrokenImageUrl(Toolkit::StyleManager& styleManager) if(styleManager) { - customBrokenImageUrlList = Toolkit::DevelStyleManager::GetBrokenImageUrlList(styleManager); - Property::Map config = Toolkit::DevelStyleManager::GetConfigurations(styleManager); - config["brokenImageUrl"].Get(brokenImageUrl); + customBrokenImageUrlList = Toolkit::DevelStyleManager::GetBrokenImageUrlList(styleManager); + const Property::Map& config = Toolkit::DevelStyleManager::GetConfigurations(styleManager); + const auto brokenImageUrlValue = config.Find("brokenImageUrl", Property::Type::STRING); + if(brokenImageUrlValue) + { + brokenImageUrlValue->Get(brokenImageUrl); + } } // Add default image