Make sure that global variables are initialized lazily. 84/288284/14
authorhuayong.xu <huayong.xu@samsung.com>
Wed, 15 Feb 2023 05:37:56 +0000 (13:37 +0800)
committerhuayong.xu <huayong.xu@samsung.com>
Mon, 20 Feb 2023 07:30:54 +0000 (15:30 +0800)
Global variables are initialized before main function or
when dali so is loaded firstly.
This patch is to reduce loading time of dali in theory.

Change-Id: Ica5e9c063e1be2dfe2aa5f7865705481422063d9

13 files changed:
dali-toolkit/internal/controls/web-view/web-view-impl.cpp
dali-toolkit/internal/controls/web-view/web-view-impl.h
dali-toolkit/internal/feedback/feedback-style.cpp
dali-toolkit/internal/text/rendering/styles/character-spacing-helper-functions.cpp
dali-toolkit/internal/text/rendering/styles/character-spacing-helper-functions.h
dali-toolkit/internal/text/text-view-interface.h
dali-toolkit/internal/text/text-view.cpp
dali-toolkit/internal/text/text-view.h
dali-toolkit/internal/transition/transition-base-impl.cpp [changed mode: 0644->0755]
dali-toolkit/internal/transition/transition-impl.cpp
dali-toolkit/internal/visuals/animated-image/rolling-animated-image-cache.cpp
dali-toolkit/internal/visuals/image-visual-shader-factory.cpp
dali-toolkit/internal/visuals/text-visual-shader-factory.cpp

index 6321695..716a151 100755 (executable)
@@ -51,6 +51,7 @@
 
 #include <functional>
 #include <memory>
+#include <unordered_map>
 
 namespace Dali
 {
@@ -89,10 +90,13 @@ DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "loadProgressPercentage",  FLOAT,
 DALI_TYPE_REGISTRATION_END()
 // clang-format on
 
+std::unordered_map<Dali::WebEnginePlugin*, Dali::WeakHandle<Toolkit::WebView>>& GetPluginWebViewTable()
+{
+  static std::unordered_map<Dali::WebEnginePlugin*, Dali::WeakHandle<Toolkit::WebView>> pluginWebViewMap;
+  return pluginWebViewMap;
+}
 } // namespace
 
-std::unordered_map<Dali::WebEnginePlugin*, Dali::WeakHandle<Toolkit::WebView>> WebView::mPluginWebViewMap;
-
 WebView::WebView(const std::string& locale, const std::string& timezoneId)
 : Control(ControlBehaviour(ACTOR_BEHAVIOUR_DEFAULT | DISABLE_STYLE_CHANGE_SIGNALS)),
   mVisual(),
@@ -144,10 +148,10 @@ WebView::~WebView()
 {
   if(mWebEngine)
   {
-    auto iter = mPluginWebViewMap.find(mWebEngine.GetPlugin());
-    if (iter != mPluginWebViewMap.end())
+    auto iter = GetPluginWebViewTable().find(mWebEngine.GetPlugin());
+    if (iter != GetPluginWebViewTable().end())
     {
-      mPluginWebViewMap.erase(iter);
+      GetPluginWebViewTable().erase(iter);
     }
     mWebEngine.Destroy();
   }
@@ -159,7 +163,7 @@ Toolkit::WebView WebView::New()
   Toolkit::WebView handle = Toolkit::WebView(*impl);
   if (impl->GetPlugin())
   {
-    mPluginWebViewMap[impl->GetPlugin()] = handle;
+    GetPluginWebViewTable()[impl->GetPlugin()] = handle;
   }
   impl->Initialize();
   return handle;
@@ -171,7 +175,7 @@ Toolkit::WebView WebView::New(const std::string& locale, const std::string& time
   Toolkit::WebView handle = Toolkit::WebView(*impl);
   if (impl->GetPlugin())
   {
-    mPluginWebViewMap[impl->GetPlugin()] = handle;
+    GetPluginWebViewTable()[impl->GetPlugin()] = handle;
   }
   impl->Initialize();
   return handle;
@@ -183,7 +187,7 @@ Toolkit::WebView WebView::New(uint32_t argc, char** argv)
   Toolkit::WebView handle = Toolkit::WebView(*impl);
   if (impl->GetPlugin())
   {
-    mPluginWebViewMap[impl->GetPlugin()] = handle;
+    GetPluginWebViewTable()[impl->GetPlugin()] = handle;
   }
   impl->Initialize();
   return handle;
@@ -191,8 +195,8 @@ Toolkit::WebView WebView::New(uint32_t argc, char** argv)
 
 Toolkit::WebView WebView::FindWebView(Dali::WebEnginePlugin* plugin)
 {
-  auto iter = mPluginWebViewMap.find(plugin);
-  if (iter != mPluginWebViewMap.end())
+  auto iter = GetPluginWebViewTable().find(plugin);
+  if (iter != GetPluginWebViewTable().end())
   {
     return iter->second.GetHandle();
   }
index fc5d06a..61834a2 100755 (executable)
@@ -25,7 +25,6 @@
 #include <dali/public-api/images/image-operations.h>
 #include <dali/public-api/object/property-notification.h>
 #include <memory>
-#include <unordered_map>
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/devel-api/controls/control-accessible.h>
@@ -725,8 +724,6 @@ private:
 
   Dali::Toolkit::WebView::WebViewScreenshotCapturedCallback mScreenshotCapturedCallback;
   Dali::WebEnginePlugin::WebEngineFrameRenderedCallback     mFrameRenderedCallback;
-
-  static std::unordered_map<Dali::WebEnginePlugin*, Dali::WeakHandle<Toolkit::WebView>> mPluginWebViewMap;
 };
 
 } // namespace Internal
index 1e8607e..a5ed3b1 100644 (file)
@@ -94,8 +94,6 @@ struct FeedbackStyleInfo
   SignalFeedbackInfoContainer mSignalFeedbackInfoList;
 };
 
-static const FeedbackStyleInfo DEFAULT_FEEDBACK_STYLE_INFO;
-
 FeedbackStyle::FeedbackStyle()
 {
   mFeedback = Dali::FeedbackPlayer::Get();
@@ -180,6 +178,7 @@ const FeedbackStyleInfo& FeedbackStyle::GetStyleInfo(const std::string& type) co
   }
   else
   {
+    static const FeedbackStyleInfo DEFAULT_FEEDBACK_STYLE_INFO;
     return DEFAULT_FEEDBACK_STYLE_INFO;
   }
 }
index b166c99..a65a4f2 100644 (file)
@@ -24,10 +24,6 @@ namespace Toolkit
 {
 namespace Text
 {
-namespace
-{
-static const Vector<CharacterSpacingGlyphRun> EMPTY_CHARACTER_SPACING_GLYPH_RUNS;
-}
 float GetGlyphCharacterSpacing(const GlyphIndex&                       index,
                                const Vector<CharacterSpacingGlyphRun>& characterSpacingGlyphRuns,
                                const float                             modelCharacterSpacing)
@@ -50,14 +46,8 @@ float GetGlyphCharacterSpacing(const GlyphIndex&                       index,
 
   return characterSpacing;
 }
-
-const Vector<CharacterSpacingGlyphRun>& GetEmptyCharacterSpacingGlyphRuns()
-{
-  // This is needed to return a common empty vector for CharacterSpacingGlyphRun
-  return EMPTY_CHARACTER_SPACING_GLYPH_RUNS;
-}
 } // namespace Text
 
 } // namespace Toolkit
 
-} // namespace Dali
\ No newline at end of file
+} // namespace Dali
index 3865b97..a15aa5e 100644 (file)
@@ -44,18 +44,10 @@ namespace Text
 float GetGlyphCharacterSpacing(const GlyphIndex&                       index,
                                const Vector<CharacterSpacingGlyphRun>& characterSpacingGlyphRuns,
                                const float                             modelCharacterSpacing);
-
-/**
- * @brief Create static empty vector and retrun it.
- *
- * @return The reference for the empty character-spacing glyph runs.
- */
-const Vector<CharacterSpacingGlyphRun>& GetEmptyCharacterSpacingGlyphRuns();
-
 } // namespace Text
 
 } // namespace Toolkit
 
 } // namespace Dali
 
-#endif // DALI_TOOLKIT_TEXT_RENDERING_STYLES_CHARACTER_SPACING_HELPER_FUNCTIONS_H
\ No newline at end of file
+#endif // DALI_TOOLKIT_TEXT_RENDERING_STYLES_CHARACTER_SPACING_HELPER_FUNCTIONS_H
index 8a23485..24fcfff 100644 (file)
@@ -353,20 +353,6 @@ public:
   virtual const Vector<BoundedParagraphRun>& GetBoundedParagraphRuns() const = 0;
 
   /**
-   * @brief Retrieves the number of character-spacing glyph runs.
-   *
-   * @return The number of character-spacing glyph runs.
-   */
-  virtual Length GetNumberOfCharacterSpacingGlyphRuns() const = 0;
-
-  /**
-   * @brief Retrieves the reference for character-spacing glyph runs.
-   *
-   * @return The reference for character-spacing glyph runs.
-   */
-  virtual const Vector<CharacterSpacingGlyphRun>& GetCharacterSpacingGlyphRuns() const = 0;
-
-  /**
    * @brief Retrieves the strikethrough runs.
    *
    * @param[out] strikethroughRuns Pointer to a buffer where the strikethrough runs are copied.
index e89d434..334d922 100644 (file)
@@ -917,24 +917,14 @@ const Vector<BoundedParagraphRun>& View::GetBoundedParagraphRuns() const
   return mImpl->mLogicalModel->GetBoundedParagraphRuns();
 }
 
-Length View::GetNumberOfCharacterSpacingGlyphRuns() const
-{
-  return (mImpl->mVisualModel) ? mImpl->mVisualModel->GetNumberOfCharacterSpacingGlyphRuns() : 0u;
-}
-
-const Vector<CharacterSpacingGlyphRun>& View::GetCharacterSpacingGlyphRuns() const
-{
-  return (mImpl->mVisualModel) ? mImpl->mVisualModel->GetCharacterSpacingGlyphRuns() : GetEmptyCharacterSpacingGlyphRuns();
-}
-
 float View::GetCharacterSpacing() const
 {
-  return (mImpl->mVisualModel) ? mImpl->mVisualModel->GetCharacterSpacing() : 0.f;
+  return mImpl->mVisualModel->GetCharacterSpacing();
 }
 
 const Character* View::GetTextBuffer() const
 {
-  return (mImpl->mVisualModel) ? mImpl->mLogicalModel->mText.Begin() : nullptr;
+  return mImpl->mLogicalModel->mText.Begin();
 }
 
 const Vector<CharacterIndex>& View::GetGlyphsToCharacters() const
index 893c802..5bf55e1 100644 (file)
@@ -269,16 +269,6 @@ public:
   virtual const Vector<BoundedParagraphRun>& GetBoundedParagraphRuns() const;
 
   /**
-   * @copydoc Dali::Toolkit::Text::ViewInterface::GetNumberOfCharacterSpacingGlyphRuns()
-   */
-  Length GetNumberOfCharacterSpacingGlyphRuns() const override;
-
-  /**
-   * @copydoc Dali::Toolkit::Text::ViewInterface::GetCharacterSpacingGlyphRuns()
-   */
-  const Vector<CharacterSpacingGlyphRun>& GetCharacterSpacingGlyphRuns() const override;
-
-  /**
    * @copydoc Dali::Toolkit::Text::ViewInterface::GetCharacterSpacing()
    */
   float GetCharacterSpacing() const override;
old mode 100644 (file)
new mode 100755 (executable)
index 5a88901..1c3ca66
@@ -36,20 +36,6 @@ namespace Internal
 {
 namespace
 {
-static constexpr float OPACITY_TRANSPARENT = 0.0f;
-
-const Dali::AlphaFunction DEFAULT_ALPHA_FUNCTION(Dali::AlphaFunction::DEFAULT);
-
-const Property::Map PROPERTY_MAP_INDEPENDENT_CONTROL{
-  {Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER},
-  {Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER},
-  {Dali::Actor::Property::POSITION_USES_ANCHOR_POINT, true},
-  {Dali::Actor::Property::INHERIT_POSITION, false},
-  {Dali::Actor::Property::INHERIT_ORIENTATION, false},
-  {Dali::Actor::Property::INHERIT_SCALE, false},
-  {Dali::Actor::Property::COLOR_MODE, Dali::ColorMode::USE_OWN_COLOR},
-};
-
 Property::Map GetOriginalProperties(Dali::Toolkit::Control control)
 {
   Property::Map propertyMap;
@@ -69,7 +55,6 @@ Property::Map GetOriginalProperties(Dali::Toolkit::Control control)
 
   return propertyMap;
 }
-
 } // anonymous namespace
 
 TransitionBasePtr TransitionBase::New()
@@ -83,7 +68,7 @@ TransitionBasePtr TransitionBase::New()
 }
 
 TransitionBase::TransitionBase()
-: mAlphaFunction(DEFAULT_ALPHA_FUNCTION),
+: mAlphaFunction(Dali::AlphaFunction::DEFAULT),
   mTimePeriod(TimePeriod(0.0f)),
   mTransitionWithChild(false),
   mMoveTargetChildren(false),
@@ -159,7 +144,14 @@ void TransitionBase::Play()
   targetWorldTransform.GetTransformComponents(targetPosition, targetOrientation, targetScale);
   Vector4 targetColor = DevelActor::GetWorldColor(mTarget);
 
-  mTarget.SetProperties(PROPERTY_MAP_INDEPENDENT_CONTROL);
+  mTarget[Dali::Actor::Property::ANCHOR_POINT]               = AnchorPoint::CENTER;
+  mTarget[Dali::Actor::Property::PARENT_ORIGIN]              = ParentOrigin::CENTER;
+  mTarget[Dali::Actor::Property::POSITION_USES_ANCHOR_POINT] = true;
+  mTarget[Dali::Actor::Property::INHERIT_POSITION]           = false;
+  mTarget[Dali::Actor::Property::INHERIT_ORIENTATION]        = false;
+  mTarget[Dali::Actor::Property::INHERIT_SCALE]              = false;
+  mTarget[Dali::Actor::Property::COLOR_MODE]                 = Dali::ColorMode::USE_OWN_COLOR;
+
   mTarget[Dali::Actor::Property::POSITION]    = targetPosition;
   mTarget[Dali::Actor::Property::SCALE]       = targetScale;
   mTarget[Dali::Actor::Property::ORIENTATION] = targetOrientation;
index 3f78a6f..332c9e0 100644 (file)
@@ -35,11 +35,6 @@ namespace Toolkit
 {
 namespace Internal
 {
-namespace
-{
-const Dali::AlphaFunction DEFAULT_ALPHA_FUNCTION(Dali::AlphaFunction::DEFAULT);
-} // anonymous namespace
-
 TransitionPtr Transition::New(Dali::Toolkit::Control source, Dali::Toolkit::Control destination, bool useDestinationTarget, TimePeriod timePeriod)
 {
   float delaySeconds = timePeriod.delaySeconds;
index f23456c..b6a9ae8 100644 (file)
@@ -43,9 +43,6 @@ Debug::Filter* gAnimImgLogFilter = Debug::Filter::New(Debug::NoLogging, false, "
 #else
 #define LOG_CACHE
 #endif
-
-static constexpr bool ENABLE_ORIENTATION_CORRECTION(true);
-
 } // namespace
 
 namespace Dali
index 728c219..2c98a4f 100644 (file)
@@ -35,12 +35,6 @@ namespace
 {
 const Vector4 FULL_TEXTURE_RECT(0.f, 0.f, 1.f, 1.f);
 
-// global string variable to caching complate vertex shader
-static std::string gVertexShader;
-
-// global string variable to caching complate fragment shader (no atlas)
-static std::string gFragmentShaderNoAtlas;
-
 const int NATIVE_SHADER_TYPE_OFFSET = VisualFactoryCache::ShaderType::NATIVE_IMAGE_SHADER - VisualFactoryCache::ShaderType::IMAGE_SHADER;
 
 // enum of required list when we select shader
@@ -279,6 +273,8 @@ Shader ImageVisualShaderFactory::GetShader(VisualFactoryCache& factoryCache, con
 
 std::string_view ImageVisualShaderFactory::GetVertexShaderSource()
 {
+  // static string variable to cache complete vertex shader
+  static std::string gVertexShader;
   if(gVertexShader.empty())
   {
     gVertexShader = Dali::Shader::GetVertexShaderPrefix() + SHADER_IMAGE_VISUAL_SHADER_VERT.data();
@@ -289,6 +285,8 @@ std::string_view ImageVisualShaderFactory::GetVertexShaderSource()
 
 std::string_view ImageVisualShaderFactory::GetFragmentShaderSource()
 {
+  // static string variable to cache complete fragment shader (no atlas)
+  static std::string gFragmentShaderNoAtlas;
   if(gFragmentShaderNoAtlas.empty())
   {
     gFragmentShaderNoAtlas = Dali::Shader::GetFragmentShaderPrefix() + SHADER_IMAGE_VISUAL_SHADER_FRAG.data();
index 5a2eba8..5f9b04b 100644 (file)
@@ -30,12 +30,6 @@ namespace Internal
 {
 namespace
 {
-// global string variable to caching complate vertex shader
-static std::string gVertexShader;
-
-// global string variable to caching complate fragment shader (no atlas)
-static std::string gFragmentShaderNoAtlas;
-
 // enum of required list when we select shader
 enum class TextVisualRequireFlag : uint32_t
 {