Remove Gesture container as there is only ever one pan gesture scene object 63/128363/1
authorKimmo Hoikka <kimmo.hoikka@samsung.com>
Tue, 9 May 2017 12:20:18 +0000 (13:20 +0100)
committerKimmo Hoikka <kimmo.hoikka@samsung.com>
Tue, 9 May 2017 12:20:18 +0000 (13:20 +0100)
- scene pan gesture is created in core construction and never dies so no need to send an add/remove message or have a container to iterate; just ownerpointer is enough

Change-Id: Idd7b8be54cade3206778382410287d8e3a290b7f

automated-tests/src/dali/utc-Dali-PanGestureDetector.cpp
dali/internal/common/core-impl.cpp
dali/internal/event/events/gesture-event-processor.cpp
dali/internal/event/events/gesture-event-processor.h
dali/internal/event/events/pan-gesture-processor.cpp
dali/internal/event/events/pan-gesture-processor.h
dali/internal/update/gestures/scene-graph-pan-gesture.h
dali/internal/update/manager/update-manager.cpp
dali/internal/update/manager/update-manager.h

index 276c833..e387d63 100644 (file)
@@ -294,7 +294,7 @@ int UtcDaliPanGestureDetectorCopyConstructorP(void)
 {
   TestApplication application;
 
-  PanGestureDetector detector = PanGestureDetector::New();;
+  PanGestureDetector detector = PanGestureDetector::New();
 
   PanGestureDetector copy( detector );
   DALI_TEST_CHECK( detector );
@@ -305,7 +305,7 @@ int UtcDaliPanGestureDetectorAssignmentOperatorP(void)
 {
   TestApplication application;
 
-  PanGestureDetector detector = PanGestureDetector::New();;
+  PanGestureDetector detector = PanGestureDetector::New();
 
   PanGestureDetector assign;
   assign = detector;
index 4e11b13..d176f70 100644 (file)
@@ -124,8 +124,8 @@ Core::Core( RenderController& renderController, PlatformAbstraction& platform,
 
   mStage->Initialize();
 
-  mGestureEventProcessor = new GestureEventProcessor(*mStage, gestureManager, mRenderController);
-  mEventProcessor = new EventProcessor(*mStage, *mNotificationManager, *mGestureEventProcessor);
+  mGestureEventProcessor = new GestureEventProcessor( *mStage, *mUpdateManager, gestureManager, mRenderController );
+  mEventProcessor = new EventProcessor( *mStage, *mNotificationManager, *mGestureEventProcessor );
 
   mShaderFactory = new ShaderFactory();
   mUpdateManager->SetShaderSaver( *mShaderFactory );
index 0482b19..a6ad63a 100644 (file)
@@ -37,14 +37,14 @@ namespace Dali
 namespace Internal
 {
 
-GestureEventProcessor::GestureEventProcessor(Stage& stage, Integration::GestureManager& gestureManager, Integration::RenderController& renderController)
-: mStage(stage),
-  mGestureManager(gestureManager),
-  mLongPressGestureProcessor(stage, gestureManager),
-  mPanGestureProcessor(stage, gestureManager),
-  mPinchGestureProcessor(stage, gestureManager),
-  mTapGestureProcessor(stage, gestureManager),
-  mRenderController(renderController),
+GestureEventProcessor::GestureEventProcessor( Stage& stage, SceneGraph::UpdateManager& updateManager, Integration::GestureManager& gestureManager, Integration::RenderController& renderController )
+: mStage( stage ),
+  mGestureManager( gestureManager ),
+  mLongPressGestureProcessor( stage, gestureManager ),
+  mPanGestureProcessor( stage, gestureManager, updateManager ),
+  mPinchGestureProcessor( stage, gestureManager ),
+  mTapGestureProcessor( stage, gestureManager ),
+  mRenderController( renderController ),
   mUpdateRequired( false )
 {
 }
index 285a597..4ff8199 100644 (file)
@@ -2,7 +2,7 @@
 #define __DALI_INTERNAL_GESTURE_EVENT_PROCESSOR_H__
 
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 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.
@@ -38,6 +38,11 @@ class GestureManager;
 class RenderController;
 }
 
+namespace SceneGraph
+{
+class UpdateManager;
+}
+
 namespace Internal
 {
 
@@ -56,10 +61,11 @@ public:
   /**
    * Create a gesture event processor.
    * @param[in] stage The stage.
+   * @param[in] updateManager The update manager
    * @param[in] gestureManager The gesture manager
    * @param[in] renderController The render controller
    */
-  GestureEventProcessor(Stage& stage, Integration::GestureManager& gestureManager, Integration::RenderController& renderController);
+  GestureEventProcessor( Stage& stage, SceneGraph::UpdateManager& updateManager, Integration::GestureManager& gestureManager, Integration::RenderController& renderController );
 
   /**
    * Non-virtual destructor; GestureProcessor is not a base class
index 8bbc6f8..0943066 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 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,7 +101,7 @@ struct IsNotAttachedAndOutsideTouchesRangeFunctor
 
 } // unnamed namespace
 
-PanGestureProcessor::PanGestureProcessor( Stage& stage, Integration::GestureManager& gestureManager )
+PanGestureProcessor::PanGestureProcessor( Stage& stage, Integration::GestureManager& gestureManager, SceneGraph::UpdateManager& updateManager )
 : GestureProcessor( Gesture::Pan ),
   mStage( stage ),
   mGestureManager( gestureManager ),
@@ -114,17 +114,13 @@ PanGestureProcessor::PanGestureProcessor( Stage& stage, Integration::GestureMana
   mCurrentPanEvent( NULL ),
   mSceneObject( SceneGraph::PanGesture::New() ) // Create scene object to store pan information.
 {
-  // Pass ownership to scene-graph
-  AddGestureMessage( mStage.GetUpdateManager(), mSceneObject );
+  // Pass ownership to scene-graph; scene object lives for the lifecycle of UpdateManager
+  updateManager.SetPanGestureProcessor( mSceneObject );
 }
 
 PanGestureProcessor::~PanGestureProcessor()
 {
-  if( Stage::IsInstalled() && ( mSceneObject != NULL ) )
-  {
-    RemoveGestureMessage( mStage.GetUpdateManager(), mSceneObject );
-    mSceneObject = NULL; // mSceneObject is about to be destroyed
-  }
+  mSceneObject = NULL; // mSceneObject is owned and destroyed by update manager (there is only one of these for now)
 }
 
 void PanGestureProcessor::Process( const Integration::PanGestureEvent& panEvent )
index f09bda3..dd31276 100644 (file)
@@ -2,7 +2,7 @@
 #define __DALI_INTERNAL_PAN_GESTURE_EVENT_PROCESSOR_H__
 
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 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.
@@ -41,6 +41,7 @@ class Stage;
 namespace SceneGraph
 {
 class PanGesture;
+class UpdateManager;
 }
 
 /**
@@ -61,13 +62,14 @@ public:
    * Create a pan gesture processor.
    * @param[in] stage The stage.
    * @param[in] gestureManager The gesture manager
+   * @param[in] updateManager The Update Manager
    */
-  PanGestureProcessor( Stage& stage, Integration::GestureManager& gestureManager );
+  PanGestureProcessor( Stage& stage, Integration::GestureManager& gestureManager, SceneGraph::UpdateManager& updateManager );
 
   /**
-   * Non-virtual destructor; PanGestureProcessor is not a base class
+   * Destructor
    */
-  ~PanGestureProcessor();
+  virtual ~PanGestureProcessor();
 
 public: // To be called by GestureEventProcessor
 
index c511f7c..459c8fe 100644 (file)
@@ -235,7 +235,7 @@ public:
    * @param[in]  nextRenderTime  The estimated time of the next render (in milliseconds).
    * @return true, if properties were updated.
    */
-  virtual bool UpdateProperties( unsigned int lastRenderTime, unsigned int nextRenderTime );
+  bool UpdateProperties( unsigned int lastRenderTime, unsigned int nextRenderTime );
 
   /**
    * Retrieves a reference to the panning flag property.
@@ -333,6 +333,12 @@ public:
    */
   void EnableProfiling();
 
+  /**
+   * Reset default properties, custom ones not supported due to this being the only object in scene side
+   * @param updateBufferIndex index to use
+   */
+  void ResetDefaultProperties( BufferIndex updateBufferIndex );
+
 private:
 
   /**
@@ -346,9 +352,6 @@ private:
   // Undefined
   PanGesture& operator=(const PanGesture&);
 
-  // PropertyOwner
-  virtual void ResetDefaultProperties( BufferIndex updateBufferIndex );
-
   // Defines information to be gathered by the gesture reading code.
   struct FrameGestureInfo
   {
index 1327074..0fcddea 100644 (file)
@@ -151,9 +151,6 @@ typedef TextureSetOwner::Iterator              TextureSetIter;
 typedef OwnerContainer<Renderer*>              RendererOwner;
 typedef RendererOwner::Iterator                RendererIter;
 
-typedef OwnerContainer<PanGesture*>            GestureOwner;
-typedef GestureOwner::Iterator                 GestureIter;
-
 typedef OwnerContainer< Camera* >              CameraOwner;
 typedef OwnerContainer< PropertyOwner* >       CustomObjectOwner;
 
@@ -192,7 +189,7 @@ struct UpdateManager::Impl
     renderers(),
     textureSets(),
     shaders(),
-    gestures(),
+    panGestureProcessor( NULL ),
     messageQueue( renderController, sceneGraphBuffers ),
     keepRenderingSeconds( 0.0f ),
     nodeDirtyFlags( TransformFlag ), // set to TransformFlag to ensure full update the first time through Update()
@@ -288,7 +285,7 @@ struct UpdateManager::Impl
   RendererOwner                       renderers;                     ///< A container of owned renderers
   TextureSetOwner                     textureSets;                   ///< A container of owned texture sets
   ShaderOwner                         shaders;                       ///< A container of owned shaders
-  GestureOwner                        gestures;                      ///< A container of owned gesture detectors
+  OwnerPointer<PanGesture>            panGestureProcessor;           ///< Owned pan gesture processor; it lives for the lifecycle of UpdateManager
 
   MessageQueue                        messageQueue;                  ///< The messages queued from the event-thread
   ShaderDataBinaryQueue               renderCompiledShaders;         ///< Shaders compiled on Render thread are inserted here for update thread to pass on to event thread.
@@ -594,27 +591,11 @@ void UpdateManager::RemoveRenderer( Renderer* renderer )
   EraseUsingDiscardQueue( mImpl->renderers, renderer, mImpl->discardQueue, mSceneGraphBuffers.GetUpdateBufferIndex() );
 }
 
-void UpdateManager::AddGesture( PanGesture* gesture )
+void UpdateManager::SetPanGestureProcessor( PanGesture* panGestureProcessor )
 {
-  DALI_ASSERT_DEBUG( NULL != gesture );
+  DALI_ASSERT_DEBUG( NULL != panGestureProcessor );
 
-  mImpl->gestures.PushBack( gesture );
-}
-
-void UpdateManager::RemoveGesture( PanGesture* gesture )
-{
-  DALI_ASSERT_DEBUG( gesture != NULL );
-
-  // Find the gesture and destroy it
-  GestureOwner& gestures = mImpl->gestures;
-  for ( GestureIter iter = gestures.Begin(), endIter = gestures.End(); iter != endIter; ++iter )
-  {
-    if ( *iter == gesture )
-    {
-      gestures.Erase( iter );
-      return;
-    }
-  }
+  mImpl->panGestureProcessor = panGestureProcessor;
 }
 
 void UpdateManager::AddTextureSet( TextureSet* textureSet )
@@ -713,14 +694,11 @@ bool UpdateManager::ProcessGestures( BufferIndex bufferIndex, unsigned int lastV
 {
   bool gestureUpdated( false );
 
-  // constrain gestures... (in construction order)
-  GestureOwner& gestures = mImpl->gestures;
-
-  for ( GestureIter iter = gestures.Begin(), endIter = gestures.End(); iter != endIter; ++iter )
+  if( mImpl->panGestureProcessor )
   {
-    PanGesture& gesture = **iter;
-    gesture.ResetToBaseValues( bufferIndex ); // Needs to be done every time as gesture data is written directly to an update-buffer rather than via a message
-    gestureUpdated |= gesture.UpdateProperties( lastVSyncTimeMilliseconds, nextVSyncTimeMilliseconds );
+    // gesture processor only supports default properties
+    mImpl->panGestureProcessor->ResetDefaultProperties( bufferIndex ); // Needs to be done every time as gesture data is written directly to an update-buffer rather than via a message
+    gestureUpdated |= mImpl->panGestureProcessor->UpdateProperties( lastVSyncTimeMilliseconds, nextVSyncTimeMilliseconds );
   }
 
   return gestureUpdated;
index a1712a4..6496987 100644 (file)
@@ -316,19 +316,12 @@ public:
   // Gestures
 
   /**
-   * Add a newly created gesture.
-   * @param[in] gesture The gesture to add.
-   * @post The gesture is owned by the UpdateManager.
+   * Set the pan gesture processor.
+   * Pan Gesture processor lives for the lifetime of UpdateManager
+   * @param[in] gesture The gesture processor.
+   * @post The gestureProcessor is owned by the UpdateManager.
    */
-  void AddGesture( PanGesture* gesture );
-
-  /**
-   * Remove a gesture.
-   * @pre The gesture has been added to the UpdateManager.
-   * @param[in] gesture The gesture to remove.
-   * @post The gesture is destroyed.
-   */
-  void RemoveGesture( PanGesture* gesture );
+  void SetPanGestureProcessor( PanGesture* gestureProcessor );
 
   // Textures
 
@@ -964,29 +957,6 @@ inline void SetLayerDepthsMessage( UpdateManager& manager, const std::vector< La
   new (slot) LocalType( &manager, &UpdateManager::SetLayerDepths, layers, systemLevel );
 }
 
-inline void AddGestureMessage( UpdateManager& manager, PanGesture* gesture )
-{
-  // Message has ownership of PanGesture while in transit from event -> update
-  typedef MessageValue1< UpdateManager, OwnerPointer< PanGesture > > LocalType;
-
-  // Reserve some memory inside the message queue
-  unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
-
-  // Construct message in the message queue memory; note that delete should not be called on the return value
-  new (slot) LocalType( &manager, &UpdateManager::AddGesture, gesture );
-}
-
-inline void RemoveGestureMessage( UpdateManager& manager, PanGesture* gesture )
-{
-  typedef MessageValue1< UpdateManager, PanGesture* > LocalType;
-
-  // Reserve some memory inside the message queue
-  unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
-
-  // Construct message in the message queue memory; note that delete should not be called on the return value
-  new (slot) LocalType( &manager, &UpdateManager::RemoveGesture, gesture );
-}
-
 inline void AddRendererMessage( UpdateManager& manager, Renderer& object )
 {
   typedef MessageValue1< UpdateManager, OwnerPointer< Renderer > > LocalType;