Extending the event loop with Processors 61/154061/7
authorDavid Steele <david.steele@samsung.com>
Tue, 26 Sep 2017 15:53:13 +0000 (16:53 +0100)
committerDavid Steele <david.steele@samsung.com>
Thu, 5 Apr 2018 17:12:54 +0000 (18:12 +0100)
It is now possible to add processors to the event loop through
the integration API, allowing Toolkit to run a processor at the
end of the event loop (before sending messages to Update queue)

Change-Id: Ifb14b7b626d5574fe08e9c199746e63d56d82920
Signed-off-by: David Steele <david.steele@samsung.com>
automated-tests/src/dali/CMakeLists.txt
automated-tests/src/dali/utc-Dali-Processors.cpp [new file with mode: 0644]
dali/integration-api/core.cpp
dali/integration-api/core.h
dali/internal/common/core-impl.cpp
dali/internal/common/core-impl.h

index e75f2d2..6fdf651 100644 (file)
@@ -59,6 +59,7 @@ SET(TC_SOURCES
         utc-Dali-PinchGestureDetector.cpp
         utc-Dali-Pixel.cpp
         utc-Dali-PixelData.cpp
+        utc-Dali-Processors.cpp
         utc-Dali-PropertyArray.cpp
         utc-Dali-PropertyBuffer.cpp
         utc-Dali-PropertyMap.cpp
diff --git a/automated-tests/src/dali/utc-Dali-Processors.cpp b/automated-tests/src/dali/utc-Dali-Processors.cpp
new file mode 100644 (file)
index 0000000..0d45357
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2018 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.
+ *
+ */
+
+#include <stdlib.h>
+#include <dali/public-api/dali-core.h>
+#include <dali/integration-api/core.h>
+#include <dali-test-suite-utils.h>
+
+using namespace Dali;
+
+
+class TestProcessor : public Integration::Processor
+{
+public:
+  TestProcessor()
+  : processRun(false)
+  {
+  }
+
+  virtual void Process()
+  {
+    processRun = true;
+  }
+
+  bool processRun;
+};
+
+
+int UtcDaliCoreProcessorP(void)
+{
+  TestApplication application;
+
+  TestProcessor testProcessor;
+  Integration::Core& core = application.GetCore();
+  core.RegisterProcessor( testProcessor );
+
+  tet_infoline("Test that the processor has not been executed yet:");
+  DALI_TEST_CHECK( testProcessor.processRun == false );
+
+  application.SendNotification();
+
+  tet_infoline("Test that the processor has been executed:");
+  DALI_TEST_CHECK( testProcessor.processRun );
+
+  // Clear down for next part of test
+  testProcessor.processRun = false;
+
+  core.UnregisterProcessor( testProcessor );
+  application.SendNotification();
+  tet_infoline("Test that the processor has not been executed again:");
+  DALI_TEST_CHECK( testProcessor.processRun == false );
+
+  END_TEST;
+}
index be0e213..8d34ae3 100644 (file)
@@ -149,6 +149,16 @@ float Core::GetStereoBase() const
   return mImpl->GetStereoBase();
 }
 
+void Core::RegisterProcessor( Processor& processor )
+{
+  mImpl->RegisterProcessor( processor );
+}
+
+void Core::UnregisterProcessor( Processor& processor )
+{
+  mImpl->UnregisterProcessor( processor );
+}
+
 Core::Core()
 : mImpl( NULL )
 {
index 002621c..5d05e85 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTEGRATION_CORE_H
 
 /*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
@@ -168,6 +168,23 @@ private:
 };
 
 /**
+ * Interface to enable classes to be processed after the event loop. Classes are processed
+ * in the order they are registered.
+ */
+class DALI_IMPORT_API Processor
+{
+public:
+  /**
+   * @brief Run the processor
+   */
+  virtual void Process() = 0;
+
+protected:
+  virtual ~Processor() { }
+};
+
+
+/**
  * Integration::Core is used for integration with the native windowing system.
  * The following integration tasks must be completed:
  *
@@ -398,6 +415,20 @@ public:
    */
   float GetStereoBase() const;
 
+  /**
+   * @brief Register a processor
+   *
+   * Note, Core does not take ownership of this processor.
+   * @param[in] processor The process to register
+   */
+  void RegisterProcessor( Processor& processor );
+
+  /**
+   * @brief Unregister a processor
+   * @param[in] processor The process to unregister
+   */
+  void UnregisterProcessor( Processor& processor );
+
 private:
 
   /**
index 79e3e42..74549ac 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
@@ -274,6 +274,9 @@ void Core::ProcessEvents()
   // Run the size negotiation after event processing finished signal
   mRelayoutController->Relayout();
 
+  // Run any registered processors
+  RunProcessors();
+
   // Rebuild depth tree after event processing has finished
   mStage->RebuildDepthTree();
 
@@ -322,6 +325,34 @@ void Core::SetStereoBase( float stereoBase )
   mStage->SetStereoBase( stereoBase );
 }
 
+void Core::RegisterProcessor( Integration::Processor& processor )
+{
+  mProcessors.PushBack(&processor);
+}
+
+void Core::UnregisterProcessor( Integration::Processor& processor )
+{
+  auto iter = std::find( mProcessors.Begin(), mProcessors.End(), &processor );
+  if( iter != mProcessors.End() )
+  {
+    mProcessors.Erase( iter );
+  }
+}
+
+void Core::RunProcessors()
+{
+  // Copy processor pointers to prevent changes to vector affecting loop iterator.
+  Dali::Vector<Integration::Processor*> processors( mProcessors );
+
+  for( auto processor : processors )
+  {
+    if( processor )
+    {
+      processor->Process();
+    }
+  }
+}
+
 float Core::GetStereoBase() const
 {
   return mStage->GetStereoBase();
index 2e063e8..d4d19e2 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_CORE_H
 
 /*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
@@ -19,6 +19,7 @@
  */
 
 // INTERNAL INCLUDES
+#include <dali/public-api/common/dali-vector.h>
 #include <dali/public-api/object/ref-object.h>
 #include <dali/integration-api/context-notifier.h>
 #include <dali/integration-api/core-enumerations.h>
@@ -33,6 +34,7 @@ namespace Dali
 
 namespace Integration
 {
+class Processor;
 class RenderController;
 class PlatformAbstraction;
 class GestureManager;
@@ -187,7 +189,24 @@ public:
    */
   float GetStereoBase() const;
 
-private:  // for use by ThreadLocalStorage
+
+  /**
+   * @copydoc Dali::Integration::Core::RegisterProcessor
+   */
+  void RegisterProcessor( Dali::Integration::Processor& processor );
+
+  /**
+   * @copydoc Dali::Integration::Core::UnregisterProcessor
+   */
+  void UnregisterProcessor( Dali::Integration::Processor& processor );
+
+private:
+  /**
+   * Run each registered processor
+   */
+  void RunProcessors();
+
+  // for use by ThreadLocalStorage
 
   /**
    * Returns the current stage.
@@ -269,6 +288,7 @@ private:
   OwnerPointer<NotificationManager>             mNotificationManager;         ///< Notification manager
   OwnerPointer<GestureEventProcessor>           mGestureEventProcessor;       ///< The gesture event processor
   OwnerPointer<EventProcessor>                  mEventProcessor;              ///< The event processor
+  Dali::Vector<Integration::Processor*>         mProcessors;                  ///< Registered processors (not owned)
 
   friend class ThreadLocalStorage;