Merge "(Vector) Change event processing" into devel/master
authorHeeyong Song <heeyong.song@samsung.com>
Tue, 18 Aug 2020 08:54:01 +0000 (08:54 +0000)
committerGerrit Code Review <gerrit@review>
Tue, 18 Aug 2020 08:54:01 +0000 (08:54 +0000)
12 files changed:
dali-toolkit/internal/controls/web-view/web-view-impl.cpp
dali-toolkit/internal/file.list
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/animated-vector-image/vector-animation-manager.cpp [new file with mode: 0644]
dali-toolkit/internal/visuals/animated-vector-image/vector-animation-manager.h [new file with mode: 0644]
dali-toolkit/internal/visuals/animated-vector-image/vector-animation-task.cpp
dali-toolkit/internal/visuals/svg/svg-visual.cpp
dali-toolkit/internal/visuals/visual-base-impl.cpp
dali-toolkit/internal/visuals/visual-factory-cache.cpp
dali-toolkit/internal/visuals/visual-factory-cache.h

index f252318..80314dc 100644 (file)
@@ -31,6 +31,7 @@
 #include <dali-toolkit/devel-api/controls/control-devel.h>
 #include <dali-toolkit/devel-api/image-loader/texture-manager.h>
 #include <dali-toolkit/internal/visuals/visual-factory-impl.h>
+#include <dali-toolkit/public-api/visuals/image-visual-properties.h>
 
 namespace Dali
 {
index 246ba89..f35ae3f 100644 (file)
@@ -19,6 +19,7 @@ SET( toolkit_src_files
    ${toolkit_src_dir}/visuals/animated-image/rolling-image-cache.cpp
    ${toolkit_src_dir}/visuals/animated-image/rolling-animated-image-cache.cpp
    ${toolkit_src_dir}/visuals/animated-vector-image/animated-vector-image-visual.cpp
+   ${toolkit_src_dir}/visuals/animated-vector-image/vector-animation-manager.cpp
    ${toolkit_src_dir}/visuals/animated-vector-image/vector-animation-task.cpp
    ${toolkit_src_dir}/visuals/animated-vector-image/vector-animation-thread.cpp
    ${toolkit_src_dir}/visuals/animated-vector-image/vector-rasterize-thread.cpp
index e937c27..70419d0 100755 (executable)
@@ -31,6 +31,7 @@
 #include <dali-toolkit/internal/visuals/visual-url.h>
 #include <dali-toolkit/internal/visuals/animated-image/image-cache.h>
 #include <dali-toolkit/devel-api/visuals/animated-image-visual-actions-devel.h>
+#include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
 
 namespace Dali
 {
index 7b263e1..453f14e 100644 (file)
@@ -22,7 +22,6 @@
 #include <dali/devel-api/common/stage.h>
 #include <dali/devel-api/rendering/renderer-devel.h>
 #include <dali/devel-api/adaptor-framework/window-devel.h>
-#include <dali/integration-api/adaptor-framework/adaptor.h>
 #include <dali/integration-api/debug.h>
 
 // INTERNAL INCLUDES
@@ -34,6 +33,7 @@
 #include <dali-toolkit/internal/visuals/visual-factory-cache.h>
 #include <dali-toolkit/internal/visuals/visual-string-constants.h>
 #include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
+#include <dali-toolkit/internal/visuals/animated-vector-image/vector-animation-manager.h>
 
 namespace Dali
 {
@@ -93,8 +93,8 @@ AnimatedVectorImageVisual::AnimatedVectorImageVisual( VisualFactoryCache& factor
   mVisualScale( Vector2::ONE ),
   mPlacementActor(),
   mPlayState( DevelImageVisual::PlayState::STOPPED ),
-  mRendererAdded( false ),
-  mRasterizationTriggered( false )
+  mEventCallback( nullptr ),
+  mRendererAdded( false )
 {
   // the rasterized image is with pre-multiplied alpha format
   mImpl->mFlags |= Impl::IS_PREMULTIPLIED_ALPHA;
@@ -105,9 +105,9 @@ AnimatedVectorImageVisual::AnimatedVectorImageVisual( VisualFactoryCache& factor
 
 AnimatedVectorImageVisual::~AnimatedVectorImageVisual()
 {
-  if( mRasterizationTriggered && Adaptor::IsAvailable() )
+  if( mEventCallback )
   {
-    Adaptor::Get().UnregisterProcessor( *this );
+    mFactoryCache.GetVectorAnimationManager().UnregisterEventCallback( mEventCallback );
   }
 
   // Finalize animation task and disconnect the signal in the main thread
@@ -418,15 +418,6 @@ void AnimatedVectorImageVisual::OnDoAction( const Property::Index actionId, cons
   TriggerVectorRasterization();
 }
 
-void AnimatedVectorImageVisual::Process()
-{
-  SendAnimationData();
-
-  mRasterizationTriggered = false;
-
-  Adaptor::Get().UnregisterProcessor( *this );
-}
-
 void AnimatedVectorImageVisual::OnUploadCompleted()
 {
   // If weak handle is holding a placement actor, it is the time to add the renderer to actor.
@@ -509,12 +500,11 @@ void AnimatedVectorImageVisual::StopAnimation()
 
 void AnimatedVectorImageVisual::TriggerVectorRasterization()
 {
-  if( !mRasterizationTriggered )
+  if( !mEventCallback )
   {
+    mEventCallback = MakeCallback( this, &AnimatedVectorImageVisual::OnProcessEvents );
+    mFactoryCache.GetVectorAnimationManager().RegisterEventCallback( mEventCallback );
     Stage::GetCurrent().KeepRendering( 0.0f );  // Trigger event processing
-
-    Adaptor::Get().RegisterProcessor( *this );
-    mRasterizationTriggered = true;
   }
 }
 
@@ -576,6 +566,13 @@ void AnimatedVectorImageVisual::OnWindowVisibilityChanged( Window window, bool v
   }
 }
 
+void AnimatedVectorImageVisual::OnProcessEvents()
+{
+  SendAnimationData();
+
+  mEventCallback = nullptr;  // The callback will be deleted in the VectorAnimationManager
+}
+
 } // namespace Internal
 
 } // namespace Toolkit
index 11b3b1c..e7ba945 100644 (file)
@@ -24,7 +24,6 @@
 #include <dali/public-api/object/property-notification.h>
 #include <dali/public-api/adaptor-framework/window.h>
 #include <dali/devel-api/actors/actor-devel.h>
-#include <dali/integration-api/processor-interface.h>
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
@@ -56,7 +55,7 @@ using AnimatedVectorImageVisualPtr = IntrusivePtr< AnimatedVectorImageVisual >;
  * | url                      | STRING           |
  *
  */
-class AnimatedVectorImageVisual: public Visual::Base, public ConnectionTracker, public Integration::Processor
+class AnimatedVectorImageVisual: public Visual::Base, public ConnectionTracker
 {
 public:
 
@@ -139,13 +138,6 @@ protected:
    */
   void OnDoAction( const Property::Index actionId, const Property::Value& attributes ) override;
 
-protected: // Implementation of Processor
-
-  /**
-   * @copydoc Dali::Integration::Processor::Process()
-   */
-  void Process() override;
-
 private:
 
   /**
@@ -205,6 +197,11 @@ private:
    */
   void OnWindowVisibilityChanged( Window window, bool visible );
 
+  /**
+   * @brief Callback when the event is processed.
+   */
+  void OnProcessEvents();
+
   // Undefined
   AnimatedVectorImageVisual( const AnimatedVectorImageVisual& visual ) = delete;
 
@@ -222,8 +219,8 @@ private:
   Vector2                                      mVisualScale;
   WeakHandle< Actor >                          mPlacementActor;
   DevelImageVisual::PlayState::Type            mPlayState;
+  CallbackBase*                                mEventCallback;    // Not owned
   bool                                         mRendererAdded;
-  bool                                         mRasterizationTriggered;
 };
 
 } // namespace Internal
diff --git a/dali-toolkit/internal/visuals/animated-vector-image/vector-animation-manager.cpp b/dali-toolkit/internal/visuals/animated-vector-image/vector-animation-manager.cpp
new file mode 100644 (file)
index 0000000..8e47d81
--- /dev/null
@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 2020 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include <dali-toolkit/internal/visuals/animated-vector-image/vector-animation-manager.h>
+
+// EXTERNAL INCLUDES
+#include <dali/integration-api/debug.h>
+#include <dali/integration-api/adaptor-framework/adaptor.h>
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/internal/visuals/animated-vector-image/vector-animation-thread.h>
+
+namespace Dali
+{
+
+namespace Toolkit
+{
+
+namespace Internal
+{
+
+namespace
+{
+
+#if defined(DEBUG_ENABLED)
+Debug::Filter* gVectorAnimationLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_VECTOR_ANIMATION" );
+#endif
+
+} // unnamed namespace
+
+VectorAnimationManager::VectorAnimationManager()
+: mEventCallbacks(),
+  mVectorAnimationThread( nullptr ),
+  mProcessorRegistered( false )
+{
+}
+
+VectorAnimationManager::~VectorAnimationManager()
+{
+  for( auto&& iter : mEventCallbacks )
+  {
+    delete iter;
+  }
+  mEventCallbacks.clear();
+
+  if( mProcessorRegistered )
+  {
+    Adaptor::Get().UnregisterProcessor( *this );
+  }
+}
+
+VectorAnimationThread& VectorAnimationManager::GetVectorAnimationThread()
+{
+  if( !mVectorAnimationThread )
+  {
+    mVectorAnimationThread = std::unique_ptr< VectorAnimationThread >( new VectorAnimationThread() );
+    mVectorAnimationThread->Start();
+  }
+  return *mVectorAnimationThread;
+}
+
+void VectorAnimationManager::RegisterEventCallback( CallbackBase* callback )
+{
+  mEventCallbacks.push_back( callback );
+
+  if( !mProcessorRegistered )
+  {
+    Adaptor::Get().RegisterProcessor( *this );
+    mProcessorRegistered = true;
+  }
+}
+
+void VectorAnimationManager::UnregisterEventCallback( CallbackBase* callback )
+{
+  auto iter = std::find( mEventCallbacks.begin(), mEventCallbacks.end(), callback );
+  if( iter != mEventCallbacks.end() )
+  {
+    mEventCallbacks.erase( iter );
+
+    if( mEventCallbacks.empty() )
+    {
+      if( Adaptor::IsAvailable() )
+      {
+        Adaptor::Get().UnregisterProcessor( *this );
+        mProcessorRegistered = false;
+      }
+    }
+  }
+}
+
+void VectorAnimationManager::Process()
+{
+  for( auto&& iter : mEventCallbacks )
+  {
+    CallbackBase::Execute( *iter );
+    delete iter;
+  }
+  mEventCallbacks.clear();
+
+  Adaptor::Get().UnregisterProcessor( *this );
+  mProcessorRegistered = false;
+}
+
+} // namespace Internal
+
+} // namespace Toolkit
+
+} // namespace Dali
diff --git a/dali-toolkit/internal/visuals/animated-vector-image/vector-animation-manager.h b/dali-toolkit/internal/visuals/animated-vector-image/vector-animation-manager.h
new file mode 100644 (file)
index 0000000..2b36c7d
--- /dev/null
@@ -0,0 +1,106 @@
+#ifndef DALI_TOOLKIT_INTERNAL_VECTOR_ANIMATION_MANAGER_H
+#define DALI_TOOLKIT_INTERNAL_VECTOR_ANIMATION_MANAGER_H
+
+/*
+ * Copyright (c) 2020 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <dali/public-api/signals/callback.h>
+#include <dali/public-api/common/vector-wrapper.h>
+#include <dali/integration-api/processor-interface.h>
+#include <memory>
+
+// INTERNAL INCLUDES
+
+namespace Dali
+{
+
+namespace Toolkit
+{
+
+namespace Internal
+{
+
+class VectorAnimationThread;
+
+/**
+ * @brief Vector animation manager
+ */
+class VectorAnimationManager: public Integration::Processor
+{
+public:
+
+  /**
+   * @brief Constructor.
+   */
+  VectorAnimationManager();
+
+  /**
+   * @brief Destructor.
+   */
+  virtual ~VectorAnimationManager();
+
+  /**
+   * Get the vector animation thread.
+   * @return A raw pointer pointing to the vector animation thread.
+   */
+  VectorAnimationThread& GetVectorAnimationThread();
+
+  /**
+   * @brief Register a callback.
+   *
+   * @param callback The callback to register
+   * @note Ownership of the callback is passed onto this class.
+   */
+  void RegisterEventCallback( CallbackBase* callback );
+
+  /**
+   * @brief Unregister a previously registered callback
+   *
+   * @param callback The callback to unregister
+   */
+  void UnregisterEventCallback( CallbackBase* callback );
+
+protected: // Implementation of Processor
+
+  /**
+   * @copydoc Dali::Integration::Processor::Process()
+   */
+  void Process() override;
+
+private:
+
+  // Undefined
+  VectorAnimationManager( const VectorAnimationManager& manager ) = delete;
+
+  // Undefined
+  VectorAnimationManager& operator=( const VectorAnimationManager& manager ) = delete;
+
+private:
+
+  std::vector< CallbackBase* >             mEventCallbacks;
+  std::unique_ptr< VectorAnimationThread > mVectorAnimationThread;
+  bool                                     mProcessorRegistered;
+};
+
+} // namespace Internal
+
+} // namespace Toolkit
+
+} // namespace Dali
+
+#endif // DALI_TOOLKIT_INTERNAL_VECTOR_ANIMATION_MANAGER_H
index bae4fbc..c5978d6 100644 (file)
@@ -26,6 +26,7 @@
 // INTERNAL INCLUDES
 #include <dali-toolkit/internal/visuals/image-visual-shader-factory.h>
 #include <dali-toolkit/internal/visuals/animated-vector-image/vector-animation-thread.h>
+#include <dali-toolkit/internal/visuals/animated-vector-image/vector-animation-manager.h>
 
 namespace Dali
 {
@@ -52,7 +53,7 @@ VectorAnimationTask::VectorAnimationTask( VisualFactoryCache& factoryCache, cons
 : mUrl( url ),
   mVectorRenderer(),
   mAnimationData(),
-  mVectorAnimationThread( factoryCache.GetVectorAnimationThread() ),
+  mVectorAnimationThread( factoryCache.GetVectorAnimationManager().GetVectorAnimationThread() ),
   mConditionalWait(),
   mAnimationFinishedTrigger(),
   mPlayState( PlayState::STOPPED ),
index 27ca01c..a9989c0 100644 (file)
 #include <dali-toolkit/internal/visuals/visual-string-constants.h>
 #include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
 #include <dali-toolkit/internal/visuals/image-visual-shader-factory.h>
-#include <dali/devel-api/adaptor-framework/file-loader.h>
+#include <dali-toolkit/public-api/visuals/image-visual-properties.h>
 
 // EXTERNAL INCLUDES
 #include <dali/devel-api/common/stage.h>
+#include <dali/devel-api/adaptor-framework/file-loader.h>
 #include <dali/integration-api/debug.h>
 
 namespace Dali
@@ -209,6 +210,7 @@ void SvgVisual::DoCreatePropertyMap( Property::Map& map ) const
     map.Insert( Toolkit::ImageVisual::Property::URL, mImageUrl.GetUrl() );
     map.Insert( Toolkit::ImageVisual::Property::ATLASING, mAttemptAtlasing );
   }
+  map.Insert( Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, IsSynchronousLoadingRequired() );
 }
 
 void SvgVisual::DoCreateInstancePropertyMap( Property::Map& map ) const
index 69e859b..c47cfca 100755 (executable)
@@ -368,7 +368,6 @@ void Visual::Base::CreatePropertyMap( Property::Map& map ) const
   // which is ok, because they have a different key value range.
   map.Insert( Toolkit::Visual::Property::MIX_COLOR, mImpl->mMixColor ); // vec4
   map.Insert( Toolkit::Visual::Property::OPACITY, mImpl->mMixColor.a );
-  map.Insert( Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, IsSynchronousLoadingRequired() );
 
   auto fittingModeString = Scripting::GetLinearEnumerationName< FittingMode >(
     mImpl->mFittingMode, VISUAL_FITTING_MODE_TABLE, VISUAL_FITTING_MODE_TABLE_COUNT );
index 2db3a57..7044e6d 100644 (file)
@@ -25,6 +25,7 @@
 #include <dali-toolkit/internal/visuals/color/color-visual.h>
 #include <dali-toolkit/internal/visuals/svg/svg-visual.h>
 #include <dali-toolkit/internal/visuals/image-atlas-manager.h>
+#include <dali-toolkit/internal/visuals/animated-vector-image/vector-animation-manager.h>
 
 namespace Dali
 {
@@ -37,7 +38,7 @@ namespace Internal
 
 VisualFactoryCache::VisualFactoryCache( bool preMultiplyOnLoad )
 : mSvgRasterizeThread( NULL ),
-  mVectorAnimationThread(),
+  mVectorAnimationManager(),
   mBrokenImageUrl(""),
   mPreMultiplyOnLoad( preMultiplyOnLoad )
 {
@@ -130,14 +131,13 @@ SvgRasterizeThread* VisualFactoryCache::GetSVGRasterizationThread()
   return mSvgRasterizeThread;
 }
 
-VectorAnimationThread& VisualFactoryCache::GetVectorAnimationThread()
+VectorAnimationManager& VisualFactoryCache::GetVectorAnimationManager()
 {
-  if( !mVectorAnimationThread )
+  if( !mVectorAnimationManager )
   {
-    mVectorAnimationThread = std::unique_ptr< VectorAnimationThread >( new VectorAnimationThread() );
-    mVectorAnimationThread->Start();
+    mVectorAnimationManager = std::unique_ptr< VectorAnimationManager >( new VectorAnimationManager() );
   }
-  return *mVectorAnimationThread;
+  return *mVectorAnimationManager;
 }
 
 void VisualFactoryCache::ApplyRasterizedSVGToSampler()
index 18d4abc..5fab354 100644 (file)
@@ -28,7 +28,6 @@
 #include <dali-toolkit/internal/visuals/npatch-loader.h>
 #include <dali-toolkit/internal/visuals/svg/svg-rasterize-thread.h>
 #include <dali-toolkit/internal/visuals/texture-manager-impl.h>
-#include <dali-toolkit/internal/visuals/animated-vector-image/vector-animation-thread.h>
 
 namespace Dali
 {
@@ -42,6 +41,7 @@ namespace Internal
 class ImageAtlasManager;
 class NPatchLoader;
 class TextureManager;
+class VectorAnimationManager;
 
 typedef IntrusivePtr<ImageAtlasManager> ImageAtlasManagerPtr;
 
@@ -215,10 +215,10 @@ public:
   SvgRasterizeThread* GetSVGRasterizationThread();
 
   /**
-   * Get the vector animation thread.
-   * @return A raw pointer pointing to the vector animation thread.
+   * Get the vector animation manager.
+   * @return A reference to the vector animation manager.
    */
-  VectorAnimationThread& GetVectorAnimationThread();
+  VectorAnimationManager& GetVectorAnimationManager();
 
 private: // for svg rasterization thread
 
@@ -243,14 +243,14 @@ private:
   Geometry mGeometry[GEOMETRY_TYPE_MAX+1];
   Shader mShader[SHADER_TYPE_MAX+1];
 
-  ImageAtlasManagerPtr                     mAtlasManager;
-  TextureManager                           mTextureManager;
-  NPatchLoader                             mNPatchLoader;
-  Texture                                  mBrokenImageTexture;
-  SvgRasterizeThread*                      mSvgRasterizeThread;
-  std::unique_ptr< VectorAnimationThread > mVectorAnimationThread;
-  std::string                              mBrokenImageUrl;
-  bool                                     mPreMultiplyOnLoad;
+  ImageAtlasManagerPtr                      mAtlasManager;
+  TextureManager                            mTextureManager;
+  NPatchLoader                              mNPatchLoader;
+  Texture                                   mBrokenImageTexture;
+  SvgRasterizeThread*                       mSvgRasterizeThread;
+  std::unique_ptr< VectorAnimationManager > mVectorAnimationManager;
+  std::string                               mBrokenImageUrl;
+  bool                                      mPreMultiplyOnLoad;
 };
 
 } // namespace Internal