Create Renderer when the Visual is created 88/252188/5
authorHeeyong Song <heeyong.song@samsung.com>
Mon, 25 Jan 2021 08:43:44 +0000 (17:43 +0900)
committerHeeyong Song <heeyong.song@samsung.com>
Tue, 2 Feb 2021 04:59:40 +0000 (13:59 +0900)
Change-Id: I08ad0e53774094acf39dda4daaa98f5b899f0d2d

36 files changed:
automated-tests/src/dali-toolkit-internal/dali-toolkit-test-utils/dummy-visual.cpp
automated-tests/src/dali-toolkit-internal/dali-toolkit-test-utils/dummy-visual.h
automated-tests/src/dali-toolkit/utc-Dali-TransitionData.cpp
automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp
dali-toolkit/devel-api/controls/control-devel.h
dali-toolkit/internal/visuals/animated-gradient/animated-gradient-visual.cpp
dali-toolkit/internal/visuals/animated-gradient/animated-gradient-visual.h
dali-toolkit/internal/visuals/animated-image/animated-image-visual.cpp
dali-toolkit/internal/visuals/animated-image/animated-image-visual.h
dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.cpp
dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.h
dali-toolkit/internal/visuals/arc/arc-visual.cpp
dali-toolkit/internal/visuals/arc/arc-visual.h
dali-toolkit/internal/visuals/border/border-visual.cpp
dali-toolkit/internal/visuals/border/border-visual.h
dali-toolkit/internal/visuals/color/color-visual.cpp
dali-toolkit/internal/visuals/color/color-visual.h
dali-toolkit/internal/visuals/gradient/gradient-visual.cpp
dali-toolkit/internal/visuals/gradient/gradient-visual.h
dali-toolkit/internal/visuals/image/image-visual.cpp
dali-toolkit/internal/visuals/image/image-visual.h
dali-toolkit/internal/visuals/mesh/mesh-visual.cpp
dali-toolkit/internal/visuals/mesh/mesh-visual.h
dali-toolkit/internal/visuals/npatch/npatch-visual.cpp
dali-toolkit/internal/visuals/npatch/npatch-visual.h
dali-toolkit/internal/visuals/primitive/primitive-visual.cpp
dali-toolkit/internal/visuals/primitive/primitive-visual.h
dali-toolkit/internal/visuals/svg/svg-visual.cpp
dali-toolkit/internal/visuals/svg/svg-visual.h
dali-toolkit/internal/visuals/text/text-visual.cpp
dali-toolkit/internal/visuals/text/text-visual.h
dali-toolkit/internal/visuals/visual-base-impl.cpp
dali-toolkit/internal/visuals/visual-base-impl.h
dali-toolkit/internal/visuals/visual-factory-impl.cpp
dali-toolkit/internal/visuals/wireframe/wireframe-visual.cpp
dali-toolkit/internal/visuals/wireframe/wireframe-visual.h

index c1d058539490f8c63d1645e6cf26cf1a4baae4db..1d8d611eb13352dfdf4d4734885f7851f591c2b4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
@@ -33,7 +33,7 @@ DummyVisualPtr DummyVisual::New( const Property::Map& properties )
   VisualFactoryCache* factoryCache = new VisualFactoryCache(false);
 
   DummyVisualPtr dummyVisualPtr( new DummyVisual( *factoryCache ) );
-
+  dummyVisualPtr->Initialize();
   return dummyVisualPtr;
 }
 
@@ -43,6 +43,11 @@ DummyVisual::DummyVisual( VisualFactoryCache& factoryCache )
 {
 }
 
+void DummyVisual::OnInitialize()
+{
+  // Implement if required
+}
+
 void DummyVisual::DoCreatePropertyMap( Property::Map& map ) const
 {
   // Implement if required
index ef4c37b44147bf04aacb2d21a3d5226bc89012b1..41b2c214304c1734cccedca8f2674bf2e68553f7 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_TEST_DUMMY_VISUAL_H
 
 /*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
@@ -75,6 +75,7 @@ protected:
 
   DummyVisual( VisualFactoryCache& factoryCache );
 
+  void OnInitialize() override;
   void DoCreatePropertyMap( Property::Map& map ) const override;
   void DoCreateInstancePropertyMap( Property::Map& map ) const override;
   void DoSetProperties( const Property::Map& propertyMap ) override;
index ca57b44396705da7aa692c81bfc89255b41979dc..a68ac7a0de0a5479e505ae4c5657f73a173e1806 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
@@ -755,49 +755,6 @@ int UtcDaliTransitionDataMap1N(void)
   END_TEST;
 }
 
-
-int UtcDaliTransitionDataMapN3(void)
-{
-  ToolkitTestApplication application;
-
-  tet_printf("Testing visual lookup with no renderers\n");
-
-  Property::Map map;
-  map["target"] = "visual1";
-  map["property"] = "mixColor";
-  map["initialValue"] = Vector3(Color::MAGENTA);
-  map["targetValue"] = Vector3(Color::RED);
-  map["animator"] = Property::Map()
-    .Add("alphaFunction", "EASE_OUT_BACK")
-    .Add("timePeriod", Property::Map()
-         .Add("delay", 0.5f)
-         .Add("duration", 1.0f));
-
-  Dali::Toolkit::TransitionData transition = TransitionData::New( map );
-  CHECK_MAP_EQUALS( map, transition.GetAnimatorAt(0) );
-
-  DummyControl actor = DummyControl::New();
-  actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
-  actor.SetProperty( Dali::Actor::Property::NAME,"Actor1");
-  actor.SetProperty( Actor::Property::COLOR,Color::CYAN);
-  // Don't stage actor
-
-  DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
-  Property::Map visualMap;
-  visualMap[Visual::Property::TYPE] = Visual::COLOR;
-  visualMap[ColorVisual::Property::MIX_COLOR] = Vector3(Color::MAGENTA);
-  Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
-  visual.SetName( "visual1" );
-
-  Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
-  dummyImpl.RegisterVisual( visualIndex, visual );
-
-  Animation anim = dummyImpl.CreateTransition( transition );
-  DALI_TEST_CHECK( !anim );
-  END_TEST;
-}
-
-
 int UtcDaliTransitionDataMapN4(void)
 {
   ToolkitTestApplication application;
index 761e88e2669a4d8d508d81fac70b4377ec6cc2cc..fbf343864fa91e4eb15b2ccc574e02e5251d9842 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
@@ -4136,13 +4136,6 @@ int UtcDaliVisualGetVisualProperty01(void)
   DALI_TEST_CHECK(!property3.object);
   DALI_TEST_CHECK(property3.propertyIndex == Property::INVALID_INDEX);
 
-  // Test after the control is unparented
-  dummyControl.Unparent();
-
-  Property property4 = DevelControl::GetVisualProperty(dummyControl, DummyControl::Property::TEST_VISUAL, Visual::Property::MIX_COLOR);
-  DALI_TEST_CHECK(!property4.object);
-  DALI_TEST_CHECK(property4.propertyIndex == Property::INVALID_INDEX);
-
   END_TEST;
 }
 
index af6c76cc32824c4155fbd172b4b161b5ffe13db2..9baeeb2cdff83c1d6fa907fa63827db8a98ac69d 100644 (file)
@@ -364,8 +364,6 @@ DALI_TOOLKIT_API VisualEventSignalType& VisualEventSignal(Control control);
  * @param[in] index The Property index of the visual.
  * @param[in] visualPropertyKey The key of the visual's property.
  * @return The Property object
- * @pre The control should be added to the Scene.
- * @pre The returned object is valid for as long as the control is on the Scene.
  */
 DALI_TOOLKIT_API Dali::Property GetVisualProperty(Control control, Dali::Property::Index index, Dali::Property::Key visualPropertyKey);
 
index 9b4bc8c4f2ccc54d42834770f14569e7b76de2a5..5ef6044534a0367fa6e92c865f918b4c477d9719 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
@@ -130,6 +130,7 @@ AnimatedGradientVisualPtr AnimatedGradientVisual::New( VisualFactoryCache& facto
 {
   AnimatedGradientVisualPtr animatedGradientVisualPtr( new AnimatedGradientVisual( factoryCache ) );
   animatedGradientVisualPtr->SetProperties( properties );
+  animatedGradientVisualPtr->Initialize();
   return animatedGradientVisualPtr;
 }
 
@@ -474,7 +475,6 @@ void AnimatedGradientVisual::OnSetTransform()
 
 void AnimatedGradientVisual::DoSetOnScene( Actor& actor )
 {
-  InitializeRenderer();
   actor.AddRenderer( mImpl->mRenderer );
   SetupAnimation();
   PlayAnimation();
@@ -488,7 +488,6 @@ void AnimatedGradientVisual::DoSetOffScene( Actor& actor )
 
   StopAnimation();
   actor.RemoveRenderer( mImpl->mRenderer );
-  mImpl->mRenderer.Reset();
 }
 
 void AnimatedGradientVisual::DoCreatePropertyMap( Property::Map& map ) const
@@ -664,7 +663,7 @@ Shader AnimatedGradientVisual::CreateShader()
   return shader;
 }
 
-void AnimatedGradientVisual::InitializeRenderer()
+void AnimatedGradientVisual::OnInitialize()
 {
   Geometry geometry = mFactoryCache.GetGeometry( VisualFactoryCache::QUAD_GEOMETRY );
   VisualFactoryCache::ShaderType shaderType = GetShaderType( mGradientType, mUnitType, mSpreadType );
index bca20c214849b7eda47e198a4e632ee212f1d9a4..96ea9ab88faeadfb6b1fb3e013ead82d292e0c8c 100755 (executable)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_INTERNAL_ANIMATED_GRADIENT_VISUAL_H
 
 /*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
@@ -195,6 +195,10 @@ protected:
   virtual ~AnimatedGradientVisual();
 
 protected: //from Visual
+  /**
+   * @copydoc Visual::Base::OnInitialize
+   */
+  void OnInitialize() override;
 
   /**
    * @copydoc Visual::Base::DoSetProperties
@@ -223,11 +227,6 @@ private:
    */
   void SetupDefaultValue();
 
-  /**
-   * @brief Initialize the rendere with the geometry from the cache, and shader which made by CreateShader()
-   */
-  void InitializeRenderer();
-
   /**
    * @brief Make animations with GradientAnimationData
    */
index 09cad557adbcc4a40e9644d53489bbb6b6d31e18..db1be0846803466df455de3c1d2b8f87e60c7106 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
@@ -119,6 +119,8 @@ AnimatedImageVisualPtr AnimatedImageVisual::New( VisualFactoryCache& factoryCach
     visual->LoadFirstBatch();
   }
 
+  visual->Initialize();
+
   return visual;
 }
 
@@ -143,6 +145,8 @@ AnimatedImageVisualPtr AnimatedImageVisual::New( VisualFactoryCache& factoryCach
     visual->LoadFirstBatch();
   }
 
+  visual->Initialize();
+
   return visual;
 }
 
@@ -156,6 +160,8 @@ AnimatedImageVisualPtr AnimatedImageVisual::New( VisualFactoryCache& factoryCach
     visual->LoadFirstBatch();
   }
 
+  visual->Initialize();
+
   return visual;
 }
 
@@ -487,7 +493,6 @@ void AnimatedImageVisual::DoSetOnScene( Actor& actor )
 {
   mPlacementActor = actor;
   TextureSet textureSet = PrepareTextureSet();
-  CreateRenderer(); // Always create a renderer when on stage
 
   if( textureSet ) // if the image loading is successful
   {
@@ -510,7 +515,6 @@ void AnimatedImageVisual::DoSetOffScene( Actor& actor )
   }
 
   actor.RemoveRenderer( mImpl->mRenderer );
-  mImpl->mRenderer.Reset();
   mPlacementActor.Reset();
   mStartFirstFrame = false;
 }
@@ -523,7 +527,7 @@ void AnimatedImageVisual::OnSetTransform()
   }
 }
 
-void AnimatedImageVisual::CreateRenderer()
+void AnimatedImageVisual::OnInitialize()
 {
   bool defaultWrapMode = mWrapModeU <= WrapMode::CLAMP_TO_EDGE && mWrapModeV <= WrapMode::CLAMP_TO_EDGE;
   bool atlasing = false;
index 862dbb80b41719550bf967a75c12c1873191c4e6..3858f6d104dc0206f4ec761cfb21f5ff17ce3f9a 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_INTERNAL_ANIMATED_IMAGE_VISUAL_H
 
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
@@ -156,6 +156,11 @@ protected:
    */
   ~AnimatedImageVisual() override;
 
+  /**
+   * @copydoc Visual::Base::OnInitialize
+   */
+  void OnInitialize() override;
+
   /**
    * @copydoc Visual::Base::DoSetProperties
    */
index db97880ad0f2636fa713ce88e3e9c6717792e83e..805b43053f6881661b0da7634f6be17fe72c3a6a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
@@ -72,14 +72,14 @@ AnimatedVectorImageVisualPtr AnimatedVectorImageVisual::New( VisualFactoryCache&
 {
   AnimatedVectorImageVisualPtr visual( new AnimatedVectorImageVisual( factoryCache, shaderFactory, imageUrl ) );
   visual->SetProperties( properties );
-
+  visual->Initialize();
   return visual;
 }
 
 AnimatedVectorImageVisualPtr AnimatedVectorImageVisual::New( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl )
 {
   AnimatedVectorImageVisualPtr visual( new AnimatedVectorImageVisual( factoryCache, shaderFactory, imageUrl ) );
-
+  visual->Initialize();
   return visual;
 }
 
@@ -279,7 +279,7 @@ void AnimatedVectorImageVisual::DoSetProperty( Property::Index index, const Prop
   }
 }
 
-void AnimatedVectorImageVisual::DoSetOnScene( Actor& actor )
+void AnimatedVectorImageVisual::OnInitialize(void)
 {
   Shader shader;
 
@@ -305,7 +305,10 @@ void AnimatedVectorImageVisual::DoSetOnScene( Actor& actor )
 
   // Register transform properties
   mImpl->mTransform.RegisterUniforms( mImpl->mRenderer, Direction::LEFT_TO_RIGHT );
+}
 
+void AnimatedVectorImageVisual::DoSetOnScene(Actor& actor)
+{
   // Defer the rasterisation task until we get given a size (by Size Negotiation algorithm)
 
   // Hold the weak handle of the placement actor and delay the adding of renderer until the rasterization is finished.
@@ -339,8 +342,6 @@ void AnimatedVectorImageVisual::DoSetOffScene( Actor& actor )
   if( mImpl->mRenderer )
   {
     actor.RemoveRenderer( mImpl->mRenderer );
-    mImpl->mRenderer.Reset();
-
     mRendererAdded = false;
   }
 
index 5bf0f4e2d642183ceae79faad0f5e8ce9f117a68..9afd18eaa8676bb818149f8e9f7bda7ae262321f 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_INTERNAL_ANIMATED_VECTOR_IMAGE_VISUAL_H
 
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
@@ -120,6 +120,11 @@ protected:
    */
   ~AnimatedVectorImageVisual() override;
 
+  /**
+   * @copydoc Visual::Base::OnInitialize
+   */
+  void OnInitialize() override;
+
   /**
    * @copydoc Visual::Base::DoSetProperties
    */
index be58a9f869be50e84bf7b233db46d46b53feb13d..029cd714d3a960224205cc06e34577f8f5f9f883 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
@@ -54,6 +54,7 @@ ArcVisualPtr ArcVisual::New( VisualFactoryCache& factoryCache, const Property::M
 {
   ArcVisualPtr arcVisualPtr( new ArcVisual( factoryCache ) );
   arcVisualPtr->SetProperties( properties );
+  arcVisualPtr->Initialize();
   return arcVisualPtr;
 }
 
@@ -139,8 +140,6 @@ void ArcVisual::DoSetProperties( const Property::Map& propertyMap )
 
 void ArcVisual::DoSetOnScene( Actor& actor )
 {
-  InitializeRenderer();
-
   actor.AddRenderer( mImpl->mRenderer );
 
   // Arc Visual generated and ready to display
@@ -149,20 +148,7 @@ void ArcVisual::DoSetOnScene( Actor& actor )
 
 void ArcVisual::DoSetOffScene(Actor& actor)
 {
-  if(mImpl->mRenderer)
-  {
-    // Update values from Renderer
-    mThickness  = mImpl->mRenderer.GetProperty<float>(mThicknessIndex);
-    mStartAngle = mImpl->mRenderer.GetProperty<float>(mStartAngleIndex);
-    mSweepAngle = mImpl->mRenderer.GetProperty<float>(mSweepAngleIndex);
-  }
-
   actor.RemoveRenderer(mImpl->mRenderer);
-  mImpl->mRenderer.Reset();
-
-  mThicknessIndex  = Property::INVALID_INDEX;
-  mStartAngleIndex = Property::INVALID_INDEX;
-  mSweepAngleIndex = Property::INVALID_INDEX;
 }
 
 void ArcVisual::DoCreatePropertyMap( Property::Map& map ) const
@@ -223,7 +209,7 @@ void ArcVisual::OnDoAction( const Property::Index actionId, const Property::Valu
   }
 }
 
-void ArcVisual::InitializeRenderer()
+void ArcVisual::OnInitialize()
 {
   Geometry geometry = mFactoryCache.GetGeometry( VisualFactoryCache::QUAD_GEOMETRY );
 
index 15f57d34fa229571d5bbbd8b90d260a090aa3dbd..9a8b1c583b65a96b21a5d34afde146f7b1b443e6 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_INTERNAL_ARC_VISUAL_H
 
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
@@ -88,6 +88,11 @@ protected:
    */
   virtual ~ArcVisual();
 
+  /**
+   * @copydoc Visual::Base::OnInitialize
+   */
+  void OnInitialize() override;
+
   /**
    * @copydoc Visual::Base::DoSetProperties
    */
@@ -113,13 +118,6 @@ protected:
    */
   void OnDoAction( const Property::Index actionId, const Property::Value& attributes ) override;
 
-private:
-
-  /**
-   * @brief Initialize the renderer with the geometry and shader from the cache, if not available, create and save to the cache for sharing.
-   */
-  void InitializeRenderer();
-
 private:
 
   // Undefined
index f62afc3b04e3d4588e4ff4937e02b426675c7c05..4146b8012158b1a7ecec66ba43aceb743078c661 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
@@ -51,6 +51,7 @@ BorderVisualPtr BorderVisual::New( VisualFactoryCache& factoryCache, const Prope
 {
   BorderVisualPtr borderVisualPtr( new BorderVisual( factoryCache ) );
   borderVisualPtr->SetProperties( properties );
+  borderVisualPtr->Initialize();
   return borderVisualPtr;
 }
 
@@ -129,8 +130,6 @@ void BorderVisual::DoSetProperty( Dali::Property::Index index,
 
 void BorderVisual::DoSetOnScene( Actor& actor )
 {
-  InitializeRenderer();
-
   mBorderColorIndex = mImpl->mRenderer.RegisterProperty( Toolkit::BorderVisual::Property::COLOR, COLOR_NAME, mBorderColor );
   if( mBorderColor.a < 1.f || mAntiAliasing )
   {
@@ -166,7 +165,7 @@ void BorderVisual::OnSetTransform()
   }
 }
 
-void BorderVisual::InitializeRenderer()
+void BorderVisual::OnInitialize()
 {
   Geometry geometry = mFactoryCache.GetGeometry( VisualFactoryCache::BORDER_GEOMETRY );
   if( !geometry )
index aa7a69b5dcd6a3194abf559e3afad006a61f02c3..15cb5bf573c5f5e883aec58ae5fe071b55f20024 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_INTERNAL_BORDER_VISUAL_H
 
 /*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
@@ -75,6 +75,11 @@ protected:
    */
   virtual ~BorderVisual();
 
+  /**
+   * @copydoc Visual::Base::OnInitialize
+   */
+  void OnInitialize() override;
+
   /**
    * @copydoc Visual::Base::DoSetProperties
    */
@@ -102,11 +107,6 @@ protected:
 
 private:
 
-  /**
-   * @brief Initialize the renderer with the geometry and shader from the cache, if not available, create and save to the cache for sharing.
-   */
-  void InitializeRenderer();
-
   /**
    * Request the border shader from the factory cache. If fail, create tha shader and add it to cache.
    * @return The border shader.
index 492f20330a4f5eef68bbd2ae7a1853eaed849bf8..77b0be066d7487b36478e14b59b3fd5deb04353b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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,6 +46,7 @@ ColorVisualPtr ColorVisual::New( VisualFactoryCache& factoryCache, const Propert
 {
   ColorVisualPtr colorVisualPtr( new ColorVisual( factoryCache ) );
   colorVisualPtr->SetProperties( properties );
+  colorVisualPtr->Initialize();
   return colorVisualPtr;
 }
 
@@ -110,8 +111,6 @@ void ColorVisual::DoSetProperties( const Property::Map& propertyMap )
 
 void ColorVisual::DoSetOnScene( Actor& actor )
 {
-  InitializeRenderer();
-
   // Only add the renderer if it's not fully transparent
   // We cannot avoid creating a renderer as it's used in the base class
   if( mRenderIfTransparent || mImpl->mMixColor.a > 0.0f )
@@ -125,15 +124,7 @@ void ColorVisual::DoSetOnScene( Actor& actor )
 
 void ColorVisual::DoSetOffScene(Actor& actor)
 {
-  if(mImpl->mRenderer && mBlurRadiusIndex != Property::INVALID_INDEX)
-  {
-    // Update values from Renderer
-    mBlurRadius = mImpl->mRenderer.GetProperty<float>(mBlurRadiusIndex);
-  }
-
   actor.RemoveRenderer(mImpl->mRenderer);
-  mImpl->mRenderer.Reset();
-  mBlurRadiusIndex = Property::INVALID_INDEX;
 }
 
 void ColorVisual::DoCreatePropertyMap( Property::Map& map ) const
@@ -194,7 +185,7 @@ void ColorVisual::UpdateShader()
   }
 }
 
-void ColorVisual::InitializeRenderer()
+void ColorVisual::OnInitialize()
 {
   Geometry geometry = mFactoryCache.GetGeometry( VisualFactoryCache::QUAD_GEOMETRY );
 
index bf28d25a410c62c60e0720cc3c51f05a42708fe8..11e43d326662bf00a0e0e28a1e6cf683f5aad17d 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_INTERNAL_COLOR_VISUAL_H
 
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
@@ -84,6 +84,11 @@ protected:
    */
   virtual ~ColorVisual();
 
+  /**
+   * @copydoc Visual::Base::OnInitialize
+   */
+  void OnInitialize() override;
+
   /**
    * @copydoc Visual::Base::DoSetProperties
    */
@@ -120,10 +125,6 @@ protected:
   Dali::Property OnGetPropertyObject(Dali::Property::Key key) override;
 
 private:
-  /**
-   * @brief Initialize the renderer with the geometry and shader from the cache, if not available, create and save to the cache for sharing.
-   */
-  void InitializeRenderer();
 
   /**
    * @brief Get a shader for the current properties.
index 504b0e0542203fa2e36bbdf60bb74cf736508f12..96f9f85dc9d41e2171c9219bd7bdbd14c4089df0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
@@ -147,6 +147,7 @@ GradientVisualPtr GradientVisual::New( VisualFactoryCache& factoryCache, const P
 {
   GradientVisualPtr gradientVisualPtr( new GradientVisual( factoryCache ) );
   gradientVisualPtr->SetProperties( properties );
+  gradientVisualPtr->Initialize();
   return gradientVisualPtr;
 }
 
@@ -199,8 +200,6 @@ void GradientVisual::OnSetTransform()
 
 void GradientVisual::DoSetOnScene( Actor& actor )
 {
-  InitializeRenderer();
-
   actor.AddRenderer( mImpl->mRenderer );
 
   // Gradient Visual generated and ready to display
@@ -264,7 +263,7 @@ void GradientVisual::DoCreateInstancePropertyMap( Property::Map& map ) const
   // Do nothing
 }
 
-void GradientVisual::InitializeRenderer()
+void GradientVisual::OnInitialize()
 {
   Geometry geometry = mFactoryCache.GetGeometry( VisualFactoryCache::QUAD_GEOMETRY );
   Shader   shader   = GetShader();
index 71ae1d6a683e0d0652b07e8b883db0911e9b1200..fdd458b383bcae5fb8f93e55f16bf2db9ffeca4b 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_INTERNAL_GRADIENT_VISUAL_H
 
 /*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
@@ -119,6 +119,11 @@ protected:
    */
   virtual ~GradientVisual();
 
+  /**
+   * @copydoc Visual::Base::OnInitialize
+   */
+  void OnInitialize() override;
+
   /**
    * @copydoc Visual::Base::DoSetProperties
    */
@@ -141,11 +146,6 @@ protected:
 
 private:
 
-  /**
-   * @brief Initialize the renderer with the geometry and shader from the cache, if not available, create and save to the cache for sharing.
-   */
-  void InitializeRenderer();
-
   /**
    * New a gradient object with the given property map.
    *
index 3a9178459a9afc84fe33b9f66cc0f2ffb1da2258..028773d11c4539ccb17d6f8423ddde09b57c49c5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
@@ -130,6 +130,7 @@ ImageVisualPtr ImageVisual::New( VisualFactoryCache& factoryCache,
 {
   ImageVisualPtr imageVisualPtr( new ImageVisual( factoryCache, shaderFactory, imageUrl, size, fittingMode, samplingMode ) );
   imageVisualPtr->SetProperties( properties );
+  imageVisualPtr->Initialize();
   return imageVisualPtr;
 }
 
@@ -140,7 +141,9 @@ ImageVisualPtr ImageVisual::New( VisualFactoryCache& factoryCache,
                                  FittingMode::Type fittingMode,
                                  Dali::SamplingMode::Type samplingMode )
 {
-  return new ImageVisual( factoryCache, shaderFactory, imageUrl, size, fittingMode, samplingMode );
+  ImageVisualPtr imageVisualPtr(new ImageVisual(factoryCache, shaderFactory, imageUrl, size, fittingMode, samplingMode));
+  imageVisualPtr->Initialize();
+  return imageVisualPtr;
 }
 
 ImageVisual::ImageVisual(VisualFactoryCache&       factoryCache,
@@ -510,7 +513,7 @@ void ImageVisual::GetNaturalSize( Vector2& naturalSize )
   naturalSize = Vector2::ZERO;
 }
 
-void ImageVisual::CreateRenderer( TextureSet& textureSet )
+void ImageVisual::OnInitialize()
 {
   Geometry geometry;
 
@@ -538,19 +541,12 @@ void ImageVisual::CreateRenderer( TextureSet& textureSet )
   // Create the renderer
   mImpl->mRenderer = Renderer::New( geometry, shader );
 
-  if( textureSet )
-  {
-    mImpl->mRenderer.SetTextures( textureSet );
-  }
-  // else still waiting for texture load to finish.
-
   //Register transform properties
   mImpl->mTransform.RegisterUniforms( mImpl->mRenderer, Direction::LEFT_TO_RIGHT );
 
   EnablePreMultipliedAlpha( IsPreMultipliedAlphaEnabled() );
 }
 
-
 void ImageVisual::LoadTexture( bool& atlasing, Vector4& atlasRect, TextureSet& textures, bool orientationCorrection,
                                TextureManager::ReloadPolicy forceReload )
 {
@@ -635,8 +631,11 @@ void ImageVisual::InitializeRenderer()
     }
   }
 
-  CreateRenderer( mTextures );
-  mTextures.Reset(); // Visual should not keep a handle to the texture after this point.
+  if(mTextures)
+  {
+    mImpl->mRenderer.SetTextures(mTextures);
+    mTextures.Reset(); // Visual should not keep a handle to the texture after this point.
+  }
 
   if( attemptAtlasing ) // the texture is packed inside atlas
   {
@@ -706,17 +705,19 @@ void ImageVisual::DoSetOffScene( Actor& actor )
 {
   // Visual::Base::SetOffScene only calls DoSetOffScene if mRenderer exists (is on onstage)
 
-  // Image release is dependent on the ReleasePolicy, renderer is destroyed.
+  // Image release is dependent on the ReleasePolicy, renderer is removed.
   actor.RemoveRenderer( mImpl->mRenderer);
   if( mReleasePolicy == Toolkit::ImageVisual::ReleasePolicy::DETACHED )
   {
     RemoveTexture(); // If INVALID_TEXTURE_ID then removal will be attempted on atlas
     mImpl->mResourceStatus = Toolkit::Visual::ResourceStatus::PREPARING;
 
+    TextureSet textureSet = TextureSet::New();
+    mImpl->mRenderer.SetTextures(textureSet);
+
     mLoadState = TextureManager::LoadState::NOT_STARTED;
   }
 
-  mImpl->mRenderer.Reset();
   mPlacementActor.Reset();
 }
 
@@ -932,7 +933,6 @@ void ImageVisual::RemoveTexture()
     }
 
     TextureSet textureSet = mImpl->mRenderer.GetTextures();
-    mImpl->mRenderer.Reset();
 
     if( index != Property::INVALID_INDEX )
     {
index fb1a529cb28bd36f2ac7632c627faaefb1c1f230..f40cf70ae2b6ee20c119ef24e0efee2b3dddc4ae 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_INTERNAL_IMAGE_VISUAL_H
 
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
@@ -204,6 +204,11 @@ protected:
    */
   virtual ~ImageVisual();
 
+  /**
+   * @copydoc Visual::Base::OnInitialize
+   */
+  void OnInitialize() override;
+
   /**
    * @copydoc Visual::Base::DoSetProperties
    */
@@ -289,12 +294,6 @@ private:
    */
   void InitializeRenderer();
 
-  /**
-   * @brief Creates the Dali::Renderer (potentially from the renderer cache), initializing it
-   * @param[in] textures to use
-   */
-  void CreateRenderer( TextureSet& textures );
-
   /**
    * Creates the texture set and adds the texture to it
    * @param[out] textureRect The texture area of the texture in the atlas.
index f34f66c8319021b486dd589a3acf7061763148c2..6a1215c791fd1f60041b823bbe5da395c779ca30 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
@@ -101,6 +101,7 @@ MeshVisualPtr MeshVisual::New( VisualFactoryCache& factoryCache, const Property:
 {
   MeshVisualPtr meshVisualPtr( new MeshVisual( factoryCache ) );
   meshVisualPtr->SetProperties( properties );
+  meshVisualPtr->Initialize();
   return meshVisualPtr;
 }
 
@@ -245,8 +246,6 @@ void MeshVisual::OnSetTransform()
 
 void MeshVisual::DoSetOnScene( Actor& actor )
 {
-  InitializeRenderer();
-
   actor.AddRenderer( mImpl->mRenderer );
 
   // Mesh loaded and ready to display
@@ -271,7 +270,7 @@ void MeshVisual::DoCreateInstancePropertyMap( Property::Map& map ) const
   // Do nothing
 }
 
-void MeshVisual::InitializeRenderer()
+void MeshVisual::OnInitialize()
 {
   //Try to load the geometry from the file.
   if( !LoadGeometry() )
index 852d7efbad0805a860d13f9c42f743ff141c882b..3cc1d669736ba09b410f946b12032a9ce6b02b3c 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_INTERNAL_MESH_VISUAL_H
 
 /*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
@@ -94,6 +94,11 @@ protected:
    */
   virtual ~MeshVisual();
 
+  /**
+   * @copydoc Visual::Base::OnInitialize
+   */
+  void OnInitialize() override;
+
   /**
    * @copydoc Visual::Base::DoSetProperties
    */
@@ -117,11 +122,6 @@ private:
    */
   void SupplyEmptyGeometry();
 
-  /**
-   * @brief Initialize the visual with the geometry and shader from the cache, if not available, create and save to the cache for sharing.
-   */
-  void InitializeRenderer();
-
   /**
    * @brief Create a shader for the object to use.
    */
index 8bbdb09b12131f69d2bd984d8b0584f9540a2a29..ccee97d321a1f8a06489b03fee77e70645e7b7ff 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
-#include <dali-toolkit/public-api/visuals/visual-properties.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
+#include <dali-toolkit/internal/visuals/image-visual-shader-factory.h>
 #include <dali-toolkit/internal/visuals/npatch-loader.h>
-#include <dali-toolkit/internal/visuals/visual-factory-impl.h>
+#include <dali-toolkit/internal/visuals/rendering-addon.h>
+#include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
+#include <dali-toolkit/internal/visuals/visual-base-impl.h>
 #include <dali-toolkit/internal/visuals/visual-factory-cache.h>
+#include <dali-toolkit/internal/visuals/visual-factory-impl.h>
 #include <dali-toolkit/internal/visuals/visual-string-constants.h>
-#include <dali-toolkit/internal/visuals/visual-base-impl.h>
-#include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
-#include <dali-toolkit/internal/visuals/rendering-addon.h>
-#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
+#include <dali-toolkit/public-api/visuals/visual-properties.h>
 
 namespace Dali
 {
@@ -134,20 +135,20 @@ void RegisterStretchProperties( Renderer& renderer, const char * uniformName, co
 
 /////////////////NPatchVisual////////////////
 
-NPatchVisualPtr NPatchVisual::New( VisualFactoryCache& factoryCache, const VisualUrl& imageUrl, const Property::Map& properties )
+NPatchVisualPtr NPatchVisual::New(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, const Property::Map& properties)
 {
-  NPatchVisualPtr nPatchVisual( new NPatchVisual( factoryCache ) );
+  NPatchVisualPtr nPatchVisual(new NPatchVisual(factoryCache, shaderFactory));
   nPatchVisual->mImageUrl = imageUrl;
   nPatchVisual->SetProperties( properties );
-
+  nPatchVisual->Initialize();
   return nPatchVisual;
 }
 
-NPatchVisualPtr NPatchVisual::New( VisualFactoryCache& factoryCache, const VisualUrl& imageUrl )
+NPatchVisualPtr NPatchVisual::New(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl)
 {
-  NPatchVisualPtr nPatchVisual( new NPatchVisual( factoryCache ) );
+  NPatchVisualPtr nPatchVisual(new NPatchVisual(factoryCache, shaderFactory));
   nPatchVisual->mImageUrl = imageUrl;
-
+  nPatchVisual->Initialize();
   return nPatchVisual;
 }
 
@@ -283,7 +284,8 @@ void NPatchVisual::DoSetOnScene( Actor& actor )
     Geometry geometry = CreateGeometry();
     Shader shader = CreateShader();
 
-    mImpl->mRenderer = Renderer::New( geometry, shader );
+    mImpl->mRenderer.SetGeometry(geometry);
+    mImpl->mRenderer.SetShader(shader);
 
     mPlacementActor = actor;
     if( data->GetLoadingState() != NPatchData::LoadingState::LOADING )
@@ -313,7 +315,6 @@ void NPatchVisual::DoSetOffScene( Actor& actor )
   }
 
   actor.RemoveRenderer( mImpl->mRenderer );
-  mImpl->mRenderer.Reset();
   mPlacementActor.Reset();
 }
 
@@ -352,17 +353,18 @@ void NPatchVisual::DoCreateInstancePropertyMap( Property::Map& map ) const
   }
 }
 
-NPatchVisual::NPatchVisual( VisualFactoryCache& factoryCache )
-: Visual::Base( factoryCache, Visual::FittingMode::FILL, Toolkit::Visual::N_PATCH ),
+NPatchVisual::NPatchVisual(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory)
+: Visual::Base(factoryCache, Visual::FittingMode::FILL, Toolkit::Visual::N_PATCH),
   mPlacementActor(),
-  mLoader( factoryCache.GetNPatchLoader() ),
+  mLoader(factoryCache.GetNPatchLoader()),
+  mImageVisualShaderFactory(shaderFactory),
   mImageUrl(),
   mAuxiliaryUrl(),
   mId(NPatchData::INVALID_NPATCH_DATA_ID),
-  mBorderOnly( false ),
+  mBorderOnly(false),
   mBorder(),
-  mAuxiliaryImageAlpha( 0.0f ),
-  mReleasePolicy( Toolkit::ImageVisual::ReleasePolicy::DETACHED )
+  mAuxiliaryImageAlpha(0.0f),
+  mReleasePolicy(Toolkit::ImageVisual::ReleasePolicy::DETACHED)
 {
   EnablePreMultipliedAlpha( mFactoryCache.GetPreMultiplyOnLoad() );
 }
@@ -376,6 +378,18 @@ NPatchVisual::~NPatchVisual()
   }
 }
 
+void NPatchVisual::OnInitialize()
+{
+  // Get basic geometry and shader
+  Geometry geometry = mFactoryCache.GetGeometry(VisualFactoryCache::QUAD_GEOMETRY);
+  Shader   shader   = mImageVisualShaderFactory.GetShader(mFactoryCache, false, true, false);
+
+  mImpl->mRenderer = Renderer::New(geometry, shader);
+
+  //Register transform properties
+  mImpl->mTransform.RegisterUniforms(mImpl->mRenderer, Direction::LEFT_TO_RIGHT);
+}
+
 Geometry NPatchVisual::CreateGeometry()
 {
   Geometry geometry;
index 19bdaff8493643d690a3b7fd8b15bf40a4019886..e89d9e00a08d74868638ace87edd7f72df7edcd4 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_INTERNAL_N_PATCH_VISUAL_H
 
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
@@ -40,7 +40,7 @@ namespace Toolkit
 
 namespace Internal
 {
-
+class ImageVisualShaderFactory;
 class NPatchVisual;
 typedef IntrusivePtr< NPatchVisual > NPatchVisualPtr;
 
@@ -60,18 +60,18 @@ typedef IntrusivePtr< NPatchVisual > NPatchVisualPtr;
 class NPatchVisual: public Visual::Base, public TextureUploadObserver
 {
 public:
-
   /**
    * @brief Create an N-patch visual using an image URL.
    *
    * The visual will load the image synchronously when the associated actor is put on stage, and destroy the image when it is off stage
    *
    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
+   * @param[in] shaderFactory The ImageVisualShaderFactory object
    * @param[in] imageUrl The URL to 9 patch image resource to use
    * @param[in] properties A Property::Map containing settings for this visual
    * @return A smart-pointer to the newly allocated visual.
    */
-  static NPatchVisualPtr New( VisualFactoryCache& factoryCache, const VisualUrl& imageUrl, const Property::Map& properties );
+  static NPatchVisualPtr New(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, const Property::Map& properties);
 
   /**
    * @brief Create an N-patch visual using an image URL.
@@ -79,10 +79,11 @@ public:
    * The visual will load the image synchronously when the associated actor is put on stage, and destroy the image when it is off stage
    *
    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
+   * @param[in] shaderFactory The ImageVisualShaderFactory object
    * @param[in] imageUrl The URL to 9 patch image resource to use
    * @return A smart-pointer to the newly allocated visual.
    */
-  static NPatchVisualPtr New( VisualFactoryCache& factoryCache, const VisualUrl& imageUrl );
+  static NPatchVisualPtr New(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl);
 
 public:  // from Visual
 
@@ -108,13 +109,18 @@ protected:
    *
    * @param[in] factoryCache Reference to the VisualFactoryCache object
    */
-  NPatchVisual( VisualFactoryCache& factoryCache );
+  NPatchVisual(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory);
 
   /**
    * @brief A reference counted object may only be deleted by calling Unreference().
    */
   virtual ~NPatchVisual();
 
+  /**
+   * @copydoc Visual::Base::OnInitialize
+   */
+  void OnInitialize() override;
+
   /**
    * @copydoc Visual::Base::DoSetProperties
    */
@@ -223,15 +229,16 @@ private:
   void LoadComplete( bool loadSuccess, Devel::PixelBuffer pixelBuffer, const VisualUrl& url, bool preMultiplied ) override;
 
 private:
-  WeakHandle<Actor>        mPlacementActor;                 ///< Weakhandle to contain Actor during texture loading
-  NPatchLoader&            mLoader;                         ///< reference to N patch loader for fast access
-  VisualUrl                mImageUrl;                       ///< The url to the N patch to load
-  VisualUrl                mAuxiliaryUrl;                   ///< An auxiliary image that can be displayed on top of the N-Patch
-  NPatchData::NPatchDataId mId;                             ///< id of the N patch (from loader/cache)
-  Devel::PixelBuffer       mAuxiliaryPixelBuffer;           ///< pixel buffer of the auxiliary mask image
-  bool                     mBorderOnly;                     ///< if only border is desired
-  Rect<int>                mBorder;                         ///< The size of the border
-  float                    mAuxiliaryImageAlpha;            ///< The alpha value for the auxiliary image only
+  WeakHandle<Actor>                         mPlacementActor; ///< Weakhandle to contain Actor during texture loading
+  NPatchLoader&                             mLoader;         ///< reference to N patch loader for fast access
+  ImageVisualShaderFactory&                 mImageVisualShaderFactory;
+  VisualUrl                                 mImageUrl;             ///< The url to the N patch to load
+  VisualUrl                                 mAuxiliaryUrl;         ///< An auxiliary image that can be displayed on top of the N-Patch
+  NPatchData::NPatchDataId                  mId;                   ///< id of the N patch (from loader/cache)
+  Devel::PixelBuffer                        mAuxiliaryPixelBuffer; ///< pixel buffer of the auxiliary mask image
+  bool                                      mBorderOnly;           ///< if only border is desired
+  Rect<int>                                 mBorder;               ///< The size of the border
+  float                                     mAuxiliaryImageAlpha;  ///< The alpha value for the auxiliary image only
   Toolkit::ImageVisual::ReleasePolicy::Type mReleasePolicy; ///< The release policy to determine when an image should no longer be cached.
 };
 
index 7ad7bf5e5e983e78c331d682b59f2c85e4b0f893..48f8fa456c2e1015fb64e7cd78639e483b38499f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
@@ -99,6 +99,7 @@ PrimitiveVisualPtr PrimitiveVisual::New( VisualFactoryCache& factoryCache, const
 {
   PrimitiveVisualPtr primitiveVisualPtr( new PrimitiveVisual( factoryCache ) );
   primitiveVisualPtr->SetProperties( properties );
+  primitiveVisualPtr->Initialize();
   return primitiveVisualPtr;
 }
 
@@ -333,8 +334,6 @@ void PrimitiveVisual::GetNaturalSize( Vector2& naturalSize )
 
 void PrimitiveVisual::DoSetOnScene( Actor& actor )
 {
-  InitializeRenderer();
-
   actor.AddRenderer( mImpl->mRenderer );
 
   // Primitive generated and ready to display
@@ -372,7 +371,7 @@ void PrimitiveVisual::OnSetTransform()
   }
 }
 
-void PrimitiveVisual::InitializeRenderer()
+void PrimitiveVisual::OnInitialize()
 {
   if( !mGeometry )
   {
index 806f5946b36faf90ec1958653e54738b56e19e8b..a3facd0e311568b6986b94275eb981a6ef8e1de7 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_INTERNAL_PRIMITIVE_VISUAL_H
 
 /*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
@@ -141,6 +141,11 @@ protected:
    */
   virtual ~PrimitiveVisual();
 
+  /**
+   * @copydoc Visual::Base::OnInitialize
+   */
+  void OnInitialize() override;
+
   /**
    * @copydoc Visual::Base::DoSetProperties
    */
index bce5c2731826a5d4e2522db85bab46021d634482..8ccb63b0ba72e60ae4541e9e2c4d8715ee84f4aa 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
@@ -52,6 +52,7 @@ SvgVisualPtr SvgVisual::New( VisualFactoryCache& factoryCache, ImageVisualShader
   SvgVisualPtr svgVisual( new SvgVisual( factoryCache, shaderFactory, imageUrl ) );
   svgVisual->Load();
   svgVisual->SetProperties(properties);
+  svgVisual->Initialize();
   return svgVisual;
 }
 
@@ -59,6 +60,7 @@ SvgVisualPtr SvgVisual::New( VisualFactoryCache& factoryCache, ImageVisualShader
 {
   SvgVisualPtr svgVisual( new SvgVisual( factoryCache, shaderFactory, imageUrl ) );
   svgVisual->Load();
+  svgVisual->Initialize();
   return svgVisual;
 }
 
@@ -83,6 +85,26 @@ SvgVisual::~SvgVisual()
 {
 }
 
+void SvgVisual::OnInitialize()
+{
+  Shader shader;
+  if(!mImpl->mCustomShader)
+  {
+    shader = mImageVisualShaderFactory.GetShader(mFactoryCache, mAttemptAtlasing, true, IsRoundedCornerRequired());
+  }
+  else
+  {
+    shader = Shader::New(mImpl->mCustomShader->mVertexShader.empty() ? mImageVisualShaderFactory.GetVertexShaderSource().data() : mImpl->mCustomShader->mVertexShader,
+                         mImpl->mCustomShader->mFragmentShader.empty() ? mImageVisualShaderFactory.GetFragmentShaderSource().data() : mImpl->mCustomShader->mFragmentShader,
+                         mImpl->mCustomShader->mHints);
+
+    shader.RegisterProperty(PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT);
+  }
+
+  Geometry geometry = mFactoryCache.GetGeometry(VisualFactoryCache::QUAD_GEOMETRY);
+  mImpl->mRenderer  = Renderer::New(geometry, shader);
+}
+
 void SvgVisual::DoSetProperties( const Property::Map& propertyMap )
 {
   // url already passed in from constructor
@@ -138,23 +160,7 @@ void SvgVisual::DoSetProperty( Property::Index index, const Property::Value& val
 
 void SvgVisual::DoSetOnScene( Actor& actor )
 {
-  Shader shader;
-  if( !mImpl->mCustomShader )
-  {
-    shader = mImageVisualShaderFactory.GetShader( mFactoryCache, mAttemptAtlasing, true, IsRoundedCornerRequired() );
-  }
-  else
-  {
-    shader = Shader::New( mImpl->mCustomShader->mVertexShader.empty() ? mImageVisualShaderFactory.GetVertexShaderSource().data() : mImpl->mCustomShader->mVertexShader,
-                          mImpl->mCustomShader->mFragmentShader.empty() ? mImageVisualShaderFactory.GetFragmentShaderSource().data() : mImpl->mCustomShader->mFragmentShader,
-                          mImpl->mCustomShader->mHints );
-
-    shader.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT );
-  }
-
-  Geometry geometry = mFactoryCache.GetGeometry( VisualFactoryCache::QUAD_GEOMETRY );
   TextureSet textureSet = TextureSet::New();
-  mImpl->mRenderer = Renderer::New( geometry, shader );
   mImpl->mRenderer.SetTextures( textureSet );
 
   // Register transform properties
@@ -174,7 +180,6 @@ void SvgVisual::DoSetOffScene( Actor& actor )
   mFactoryCache.GetSVGRasterizationThread()->RemoveTask( this );
 
   actor.RemoveRenderer( mImpl->mRenderer );
-  mImpl->mRenderer.Reset();
   mPlacementActor.Reset();
 
   // Reset the visual size to zero so that when adding the actor back to stage the SVG rasterization is forced
index 814fc675d146208a217d3d4a42aac697d20e6456..b7582b9a4a26f4b9d4c2829367ac687585850b7d 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_INTERNAL_SVG_VISUAL_H
 
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
@@ -113,6 +113,11 @@ protected:
    */
   virtual ~SvgVisual();
 
+  /**
+   * @copydoc Visual::Base::OnInitialize
+   */
+  void OnInitialize() override;
+
   /**
    * @copydoc Visual::Base::DoSetProperties
    */
index 29b18a18a0a6e6b7bd0efba24b4c15a0f560aefe..56d3a8d56e668be5d655c763aa9c96f0e53ce382 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
@@ -152,9 +152,10 @@ void OpacityConstraint( float& current, const PropertyInputContainer& inputs )
 
 TextVisualPtr TextVisual::New( VisualFactoryCache& factoryCache, const Property::Map& properties )
 {
-  TextVisualPtr TextVisualPtr( new TextVisual( factoryCache ) );
-  TextVisualPtr->SetProperties( properties );
-  return TextVisualPtr;
+  TextVisualPtr textVisualPtr(new TextVisual(factoryCache));
+  textVisualPtr->SetProperties(properties);
+  textVisualPtr->Initialize();
+  return textVisualPtr;
 }
 
 Property::Map TextVisual::ConvertStringKeysToIndexKeys( const Property::Map& propertyMap )
@@ -252,6 +253,14 @@ TextVisual::~TextVisual()
 {
 }
 
+void TextVisual::OnInitialize()
+{
+  Geometry geometry = mFactoryCache.GetGeometry(VisualFactoryCache::QUAD_GEOMETRY);
+  Shader   shader   = GetTextShader(mFactoryCache, TextType::SINGLE_COLOR_TEXT, TextType::NO_EMOJI, TextType::NO_STYLES);
+
+  mImpl->mRenderer = Renderer::New(geometry, shader);
+}
+
 void TextVisual::DoSetProperties( const Property::Map& propertyMap )
 {
   for( Property::Map::SizeType index = 0u, count = propertyMap.Count(); index < count; ++index )
@@ -282,10 +291,6 @@ void TextVisual::DoSetOnScene( Actor& actor )
 {
   mControl = actor;
 
-  Geometry geometry = mFactoryCache.GetGeometry( VisualFactoryCache::QUAD_GEOMETRY );
-  Shader shader = GetTextShader(mFactoryCache, TextType::SINGLE_COLOR_TEXT, TextType::NO_EMOJI, TextType::NO_STYLES);
-
-  mImpl->mRenderer = Renderer::New( geometry, shader );
   mImpl->mRenderer.SetProperty( Dali::Renderer::Property::DEPTH_INDEX, Toolkit::DepthIndex::CONTENT );
 
   // Enable the pre-multiplied alpha to improve the text quality
@@ -337,9 +342,6 @@ void TextVisual::DoSetOffScene( Actor& actor )
 {
   RemoveRenderer( actor );
 
-  // Resets the renderer.
-  mImpl->mRenderer.Reset();
-
   // Resets the control handle.
   mControl.Reset();
 }
index 136a23f23e894bfaf24a2df8ee6197eafc78cdcc..881fc3b99db389b84f5c0d495ab742abf50b0424 100755 (executable)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_INTERNAL_TEXT_VISUAL_H
 
 /*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
@@ -160,6 +160,11 @@ protected:
    */
   virtual ~TextVisual();
 
+  /**
+   * @copydoc Visual::Base::OnInitialize
+   */
+  void OnInitialize() override;
+
   // from Visual::Base
 
   /**
index e8e984f07ba45621b92de1937aadc9cf741a0066..a814d6b06bfdda66c7923807f0bc22ef6f5b421c 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
@@ -77,6 +77,25 @@ Visual::Base::~Base()
   delete mImpl;
 }
 
+void Visual::Base::Initialize()
+{
+  // The Renderer should be created inside derived class here.
+  OnInitialize();
+
+  if(mImpl->mRenderer)
+  {
+    RegisterMixColor();
+
+    if(IsRoundedCornerRequired())
+    {
+      mImpl->mCornerRadiusIndex = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::CORNER_RADIUS, CORNER_RADIUS, mImpl->mCornerRadius);
+      mImpl->mRenderer.RegisterProperty(CORNER_RADIUS_POLICY, mImpl->mCornerRadiusPolicy);
+
+      mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
+    }
+  }
+}
+
 void Visual::Base::SetCustomShader( const Property::Map& shaderMap )
 {
   if( mImpl->mCustomShader )
@@ -87,6 +106,9 @@ void Visual::Base::SetCustomShader( const Property::Map& shaderMap )
   {
     mImpl->mCustomShader = new Impl::CustomShader( shaderMap );
   }
+
+  // Let derived class know
+  UpdateShader();
 }
 
 void Visual::Base::SetProperties( const Property::Map& propertyMap )
@@ -317,22 +339,13 @@ void Visual::Base::SetOnScene( Actor& actor )
     // Thus the calling of actor.AddRenderer() should happen inside derived class as base class does not know the exact timing.
     DoSetOnScene( actor );
 
-    if( mImpl->mRenderer )
+    if(mImpl->mRenderer)
     {
-      RegisterMixColor();
-
-      if( IsRoundedCornerRequired() )
-      {
-        mImpl->mCornerRadiusIndex = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::CORNER_RADIUS, CORNER_RADIUS, mImpl->mCornerRadius);
-        mImpl->mRenderer.RegisterProperty( CORNER_RADIUS_POLICY, mImpl->mCornerRadiusPolicy );
-
-        mImpl->mRenderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON );
-      }
-
-      mImpl->mRenderer.SetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, IsPreMultipliedAlphaEnabled());
-      mImpl->mRenderer.SetProperty( Renderer::Property::DEPTH_INDEX, mImpl->mDepthIndex );
-      mImpl->mFlags |= Impl::IS_ON_SCENE; // Only sets the flag if renderer exists
+      mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, IsPreMultipliedAlphaEnabled());
+      mImpl->mRenderer.SetProperty(Renderer::Property::DEPTH_INDEX, mImpl->mDepthIndex);
     }
+
+    mImpl->mFlags |= Impl::IS_ON_SCENE;
   }
 }
 
@@ -340,28 +353,7 @@ void Visual::Base::SetOffScene( Actor& actor )
 {
   if( IsOnScene() )
   {
-    if(mImpl->mRenderer)
-    {
-      // Update values from Renderer
-      mImpl->mMixColor   = mImpl->mRenderer.GetProperty<Vector3>(mImpl->mMixColorIndex);
-      mImpl->mMixColor.a = mImpl->mRenderer.GetProperty<float>(DevelRenderer::Property::OPACITY);
-      if(mImpl->mTransform.mOffsetIndex != Property::INVALID_INDEX)
-      {
-        mImpl->mTransform.mOffset = mImpl->mRenderer.GetProperty<Vector2>(mImpl->mTransform.mOffsetIndex);
-      }
-      if(mImpl->mTransform.mSizeIndex != Property::INVALID_INDEX)
-      {
-        mImpl->mTransform.mSize = mImpl->mRenderer.GetProperty<Vector2>(mImpl->mTransform.mSizeIndex);
-      }
-      if(mImpl->mCornerRadiusIndex != Property::INVALID_INDEX)
-      {
-        mImpl->mCornerRadius = mImpl->mRenderer.GetProperty<float>(mImpl->mCornerRadiusIndex);
-      }
-    }
-
     DoSetOffScene( actor );
-    mImpl->mMixColorIndex = Property::INVALID_INDEX;
-    mImpl->mCornerRadiusIndex = Property::INVALID_INDEX;
     mImpl->mFlags &= ~Impl::IS_ON_SCENE;
   }
 }
@@ -422,9 +414,6 @@ void Visual::Base::CreateInstancePropertyMap( Property::Map& map ) const
   {
     mImpl->mCustomShader->CreatePropertyMap( map );
   }
-
-  //map.Insert( Toolkit::Visual::Property::DEPTH_INDEX, mImpl->mDepthIndex );
-  //map.Insert( Toolkit::Visual::Property::ENABLED, (bool) mImpl->mRenderer );
 }
 
 
@@ -454,7 +443,6 @@ bool Visual::Base::IsPreMultipliedAlphaEnabled() const
 void Visual::Base::DoSetOffScene( Actor& actor )
 {
   actor.RemoveRenderer( mImpl->mRenderer );
-  mImpl->mRenderer.Reset();
 }
 
 bool Visual::Base::IsOnScene() const
index 8b0132ef770eeaca5c7a4305eb5a7c9dd2e22233..3b23e5ced5dbd704e32d0ada6b9c21cca0b86e42 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_INTERNAL_VISUAL_H
 
 /*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
@@ -296,7 +296,16 @@ protected:
    */
   ~Base() override;
 
+  /**
+   * @brief Second-phase constructor.
+   */
+  void Initialize();
+
 protected:
+  /**
+   * @brief Called by Initialize() allowing sub classes to initialize them.
+   */
+  virtual void OnInitialize() = 0;
 
   /**
    * @brief Called by CreatePropertyMap() allowing sub classes to respond to the CreatePropertyMap event
index 9e5238da552759d0523b1fbeae427c88c383a7bb..598f73d870c00d82b7da5122c4a28a22aaa56821 100644 (file)
@@ -1,5 +1,5 @@
- /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+/*
+ * Copyright (c) 2021 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.
@@ -155,7 +155,7 @@ Toolkit::Visual::Base VisualFactory::CreateVisual( const Property::Map& property
             {
               case VisualUrl::N_PATCH:
               {
-                visualPtr = NPatchVisual::New( GetFactoryCache(), visualUrl, propertyMap );
+                visualPtr = NPatchVisual::New(GetFactoryCache(), GetImageVisualShaderFactory(), visualUrl, propertyMap);
                 break;
               }
               case VisualUrl::SVG:
@@ -224,7 +224,7 @@ Toolkit::Visual::Base VisualFactory::CreateVisual( const Property::Map& property
       std::string imageUrl;
       if( imageURLValue && imageURLValue->Get( imageUrl ) )
       {
-        visualPtr = NPatchVisual::New( GetFactoryCache(), imageUrl, propertyMap );
+        visualPtr = NPatchVisual::New(GetFactoryCache(), GetImageVisualShaderFactory(), imageUrl, propertyMap);
       }
       break;
     }
@@ -326,7 +326,7 @@ Toolkit::Visual::Base VisualFactory::CreateVisual( const std::string& url, Image
     {
       case VisualUrl::N_PATCH:
       {
-        visualPtr = NPatchVisual::New( GetFactoryCache(), visualUrl );
+        visualPtr = NPatchVisual::New(GetFactoryCache(), GetImageVisualShaderFactory(), visualUrl);
         break;
       }
       case VisualUrl::SVG:
index f563fc1e744db5bfee82d91c4f95bbbb593f354f..ead87c0db16832ecd815aae867e1619f8df412e1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
@@ -15,7 +15,6 @@
  *
  */
 
-
 // CLASS HEADER
 #include "wireframe-visual.h"
 
@@ -51,7 +50,9 @@ WireframeVisualPtr WireframeVisual::New( VisualFactoryCache& factoryCache, const
 
 WireframeVisualPtr WireframeVisual::New( VisualFactoryCache& factoryCache, Visual::BasePtr actualVisual )
 {
-  return new WireframeVisual( factoryCache, actualVisual );
+  WireframeVisualPtr wireframeVisual(new WireframeVisual(factoryCache, actualVisual));
+  wireframeVisual->Initialize();
+  return wireframeVisual;
 }
 
 WireframeVisualPtr WireframeVisual::New( VisualFactoryCache& factoryCache, Visual::BasePtr actualVisual, const Property::Map& properties )
@@ -65,7 +66,7 @@ WireframeVisualPtr WireframeVisual::New( VisualFactoryCache& factoryCache, Visua
   {
     wireframeVisual->SetTransformAndSize( transformMap, Vector2::ZERO );
   }
-
+  wireframeVisual->Initialize();
   return wireframeVisual;
 }
 
@@ -134,15 +135,13 @@ void WireframeVisual::DoSetProperties( const Property::Map& propertyMap )
 
 void WireframeVisual::DoSetOnScene( Actor& actor )
 {
-  InitializeRenderer();
-
   actor.AddRenderer( mImpl->mRenderer );
 
   // Wireframe generated and ready to display
   ResourceReady( Toolkit::Visual::ResourceStatus::READY );
 }
 
-void WireframeVisual::InitializeRenderer()
+void WireframeVisual::OnInitialize()
 {
   Shader shader = mFactoryCache.GetShader( VisualFactoryCache::WIREFRAME_SHADER );
   if( !shader )
index 23b16f5e6383a332f31b5e23fc8673dc5a252a11..12ebfe586b83731e4108643cc7a194d386bd2629 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_INTERNAL_WIREFRAME_VISUAL_H
 
 /*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
@@ -92,6 +92,10 @@ protected:
   virtual ~WireframeVisual();
 
 protected: // from Visual::Base
+  /**
+   * @copydoc Visual::Base::OnInitialize
+   */
+  void OnInitialize() override;
 
   /**
    * @copydoc Visual::Base::GetHeightForWidth()
@@ -142,11 +146,6 @@ private:
    */
   Geometry CreateQuadWireframeGeometry();
 
-  /**
-   * @brief Initialise the renderer from the cache, if not available, create and save to the cache for sharing.
-   */
-  void InitializeRenderer();
-
   // Undefined
   WireframeVisual( const WireframeVisual& visual);