Merge "Updated all code to new format" into devel/master
[platform/core/uifw/dali-core.git] / dali / internal / event / common / stage-impl.h
index a0e9d6a..d62c663 100644 (file)
@@ -1,8 +1,8 @@
-#ifndef __DALI_INTERNAL_STAGE_H__
-#define __DALI_INTERNAL_STAGE_H__
+#ifndef DALI_INTERNAL_STAGE_H
+#define DALI_INTERNAL_STAGE_H
 
 /*
- * Copyright (c) 2014 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/public-api/object/ref-object.h>
-#include <dali/public-api/common/stage.h>
-#include <dali/public-api/object/base-object.h>
+#include <dali/devel-api/common/stage-devel.h>
+#include <dali/devel-api/common/stage.h>
 #include <dali/integration-api/context-notifier.h>
 #include <dali/internal/common/owner-pointer.h>
 #include <dali/internal/event/actors/layer-impl.h>
+#include <dali/internal/event/common/event-thread-services.h>
 #include <dali/internal/event/common/object-registry-impl.h>
 #include <dali/internal/event/common/stage-def.h>
 #include <dali/internal/event/render-tasks/render-task-defaults.h>
+#include <dali/internal/event/render-tasks/render-task-impl.h>
 #include <dali/internal/update/manager/update-manager.h>
-#include <dali/public-api/common/view-mode.h>
 #include <dali/public-api/math/vector2.h>
 #include <dali/public-api/math/vector3.h>
 #include <dali/public-api/math/vector4.h>
-#include <dali/public-api/render-tasks/render-task.h>
-
-#ifdef DYNAMICS_SUPPORT
-#include <dali/internal/event/dynamics/dynamics-declarations.h>
-#include <dali/internal/event/dynamics/dynamics-notifier.h>
-#endif
+#include <dali/public-api/object/base-object.h>
+#include <dali/public-api/object/ref-object.h>
 
 namespace Dali
 {
-
 struct Vector2;
 
 namespace Integration
 {
-class SystemOverlay;
-class DynamicsFactory;
+class RenderController;
 }
 
 namespace Internal
 {
-
 namespace SceneGraph
 {
 class UpdateManager;
@@ -63,41 +56,31 @@ class AnimationPlaylist;
 class PropertyNotificationManager;
 class Layer;
 class LayerList;
-class SystemOverlay;
 class CameraActor;
 class RenderTaskList;
+class Scene;
 
 /**
  * Implementation of Stage
  */
-class Stage : public BaseObject, public RenderTaskDefaults, public Integration::ContextNotifierInterface
+class Stage : public BaseObject, public RenderTaskDefaults, public Integration::ContextNotifierInterface, public ConnectionTracker
 {
 public:
-
   /**
    * Create the stage
-   * @param[in] playlist for animations
-   * @param[in] propertyNotificationManager
    * @param[in] updateManager
-   * @param[in] notificationManager
    */
-  static StagePtr New( AnimationPlaylist& playlist,
-                       PropertyNotificationManager& propertyNotificationManager,
-                       SceneGraph::UpdateManager& updateManager,
-                       NotificationManager& notificationManager );
+  static StagePtr New(SceneGraph::UpdateManager& updateManager);
 
   /**
    * Initialize the stage.
+   * @param[in] scene The default scene (for main window).
    */
-  void Initialize();
-
-  /**
-   * Uninitialize the stage.
-   */
-  void Uninitialize();
+  void Initialize(Scene& scene);
 
   /**
    * @copydoc Dali::Stage::GetCurrent()
+   * @note this version is for internal usage so it does not assert
    */
   static StagePtr GetCurrent();
 
@@ -117,58 +100,17 @@ public:
    */
   Layer& GetRootActor();
 
-  /**
-   * Retrieve the UpdateManager associated with this Stage
-   * @return The UpdateManager.
-   */
-  SceneGraph::UpdateManager& GetUpdateManager();
-
-  /**
-   * Helper for actors, to retrieve the current Event buffer index.
-   * @return The buffer index.
-   */
-  BufferIndex GetEventBufferIndex() const
-  {
-    // inlined as its called often from event thread
-    return mUpdateManager.GetEventBufferIndex();
-  }
-
-  /**
-   * Retrieve the interface for accessing update-thread data.
-   * @return The EventToUpdate interface.
-   */
-  EventToUpdate& GetUpdateInterface();
-
-  /**
-   * Returns the animation playlist.
-   * @return reference to the animation playlist.
-   */
-  AnimationPlaylist& GetAnimationPlaylist();
-
-  /**
-   * Returns the property notification manager.
-   * @return reference to the property notification manager.
-   */
-  PropertyNotificationManager& GetPropertyNotificationManager();
-
   // Root actor accessors
 
   /**
    * @copydoc Dali::Stage::Add()
    */
-  void Add( Actor& actor );
+  void Add(Actor& actor);
 
   /**
    * @copydoc Dali::Stage::Remove()
    */
-  void Remove( Actor& actor );
-
-  /**
-   * Sets the size of the stage and indirectly, the root actor.
-   * @param [in] width  The new width.
-   * @param [in] height The new height.
-   */
-  void SetSize( float width, float height );
+  void Remove(Actor& actor);
 
   /**
    * Returns the size of the Stage in pixels as a Vector.
@@ -184,33 +126,28 @@ public:
   RenderTaskList& GetRenderTaskList() const;
 
   /**
-   * Create a default camera actor
-   */
-  void CreateDefaultCameraActor();
-
-  /**
    * From RenderTaskDefaults; retrieve the default root actor.
    * @return The default root actor.
    */
-  virtual Actor& GetDefaultRootActor();
+  Actor& GetDefaultRootActor() override;
 
   /**
    * From RenderTaskDefaults; retrieve the default camera actor.
    * @return The default camera actor.
    */
-  virtual CameraActor& GetDefaultCameraActor();
+  CameraActor& GetDefaultCameraActor() override;
 
   // Layers
 
   /**
    * @copydoc Dali::Stage::GetLayerCount()
    */
-  unsigned int GetLayerCount() const;
+  uint32_t GetLayerCount() const;
 
   /**
    * @copydoc Dali::Stage::GetLayer()
    */
-  Dali::Layer GetLayer( unsigned int depth ) const;
+  Dali::Layer GetLayer(uint32_t depth) const;
 
   /**
    * @copydoc Dali::Stage::GetRootLayer()
@@ -223,255 +160,202 @@ public:
    */
   LayerList& GetLayerList();
 
-  // System-level overlay actors
+  // Misc
 
   /**
-   * @copydoc Dali::Integration::Core::GetSystemOverlay()
+   * @copydoc Dali::Stage::SetBackgroundColor
    */
-  Integration::SystemOverlay& GetSystemOverlay();
+  void SetBackgroundColor(Vector4 color);
 
   /**
-   * Retrieve the internal implementation of the SystemOverlay.
-   * @return The implementation, or NULL if this has never been requested from Integration API.
+   * @copydoc Dali::Stage::GetBackgroundColor
    */
-  SystemOverlay* GetSystemOverlayInternal();
-
-  // Stereoscopy
+  Vector4 GetBackgroundColor() const;
 
   /**
-   * @copydoc Dali::Integration::Core::SetViewMode()
+   * @copydoc Dali::Stage::GetDpi
    */
-  void SetViewMode( ViewMode viewMode );
+  Vector2 GetDpi() const;
 
   /**
-   * @copydoc Dali::Integration::Core::GetViewMode()
+   * @copydoc Dali::Stage::KeepRendering()
    */
-  ViewMode GetViewMode() const;
+  void KeepRendering(float durationSeconds);
 
   /**
-   * @copydoc Dali::Integration::Core::SetStereoBase()
+   * @copydoc Dali::DevelStage::SetRenderingBehavior()
    */
-  void SetStereoBase( float stereoBase );
+  void SetRenderingBehavior(DevelStage::Rendering renderingBehavior);
 
   /**
-   * @copydoc Dali::Integration::Core::GetStereoBase()
+   * @copydoc Dali::DevelStage::GetRenderingBehavior()
    */
-  float GetStereoBase() const;
-
-  // Keyboard stuff
+  DevelStage::Rendering GetRenderingBehavior() const;
 
   /**
-   * As one virtual keyboard per stage, the stage will hold a pointer to the Actor currently
-   * set to receive keyboard input.
-   * @param[in] actor to receive keyboard input
+   * Callback for Internal::Scene EventProcessingFinished signal
    */
-  void SetKeyboardFocusActor( Actor* actor );
+  void OnEventProcessingFinished();
 
   /**
-   * Get the actor that is currently set to receive keyboard inputs
-   * @return Pointer to the actor set to receive keyboard inputs.
+   * Callback for Internal::Scene KeyEventSignal signal
    */
-  Actor* GetKeyboardFocusActor() const;
+  void OnKeyEvent(const Dali::KeyEvent& event);
 
   /**
-   * Removes the given actor from keyboard focus so it will no longer receive key events from keyboard.
-   * @param [in] actor which should be removed from focus.
+   * Callback for Internal::Scene TouchedSignal signal
    */
-  void RemoveActorFromKeyFocus( Actor* actor );
-
-  // Misc
+  void OnTouchEvent(const Dali::TouchEvent& touch);
 
   /**
-   * @copydoc Dali::Stage::SetBackgroundColor
+   * Callback for Internal::Scene WheelEventSignal signal
    */
-  void SetBackgroundColor(Vector4 color);
+  void OnWheelEvent(const Dali::WheelEvent& event);
 
   /**
-   * @copydoc Dali::Stage::GetBackgroundColor
+   * Used by the EventProcessor to emit key event signals.
+   * @param[in] event The key event.
    */
-  Vector4 GetBackgroundColor() const;
+  void EmitKeyEventSignal(const KeyEvent& event);
 
   /**
-   * @copydoc Dali::Stage::GetDpi
+   * Used by the KeyEventProcessor to emit KeyEventGenerated signals.
+   * @param[in] event The key event.
+   * @return The return is true if KeyEvent is consumed, otherwise false.
    */
-  Vector2 GetDpi() const;
+  bool EmitKeyEventGeneratedSignal(const KeyEvent& event);
 
   /**
-   * Sets horizontal and vertical pixels per inch value that is used by the display
-   * @param[in] dpi Horizontal and vertical dpi value
+   * Emits the event processing finished signal.
+   *
+   * @see Dali::Stage::SignalEventProcessingFinished()
    */
-  void SetDpi( Vector2 dpi );
-
-#ifdef DYNAMICS_SUPPORT
+  void EmitEventProcessingFinishedSignal();
 
   /**
-   * Return the Dynamics Simulation Notifier object
-   * @return The Dynamics Simulation Notifier object
+   * Emits the touched signal.
+   * @param[in] touch The touch event details.
    */
-  DynamicsNotifier& GetDynamicsNotifier();
+  void EmitTouchedSignal(const Dali::TouchEvent& touch);
 
   /**
-   * @copydoc Dali::Stage::InitializeDynamics
+   * Used by the EventProcessor to emit wheel event signals.
+   * @param[in] event The wheel event.
    */
-  DynamicsWorldPtr InitializeDynamics(DynamicsWorldConfigPtr config);
+  void EmitWheelEventSignal(const WheelEvent& event);
 
   /**
-   * @copydoc Dali::Stage::GetDynamicsWorld
+   * Emits the scene created.
    */
-  DynamicsWorldPtr GetDynamicsWorld();
+  void EmitSceneCreatedSignal();
 
   /**
-   * @copydoc Dali::Stage::TerminateDynamics
+   * @copydoc Dali::Stage::KeyEventSignal()
    */
-  void TerminateDynamics();
-
-#endif // DYNAMICS_SUPPORT
-
-  NotificationManager& GetNotificationManager()
-  {
-    return mNotificationManager;
-  }
-
+  Dali::Stage::KeyEventSignalType& KeyEventSignal();
 
   /**
-   * @copydoc Dali::Stage::KeepRendering()
+   * @copydoc Dali::Stage::SignalEventProcessingFinished()
    */
-  void KeepRendering( float durationSeconds );
+  Dali::Stage::EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
 
   /**
-   * Used by the EventProcessor to emit key event signals.
-   * @param[in] event The key event.
+    * @copydoc Dali::Stage::TouchedSignal()
+    */
+  Dali::Stage::TouchEventSignalType& TouchedSignal();
+
+  /**
+   * @copydoc Dali::Stage::WheelEventSignal()
    */
-  void EmitKeyEventSignal(const KeyEvent& event);
+  Dali::Stage::WheelEventSignalType& WheelEventSignal();
 
   /**
-   * Emits the event processing finished signal.
-   *
-   * @see Dali::Stage::SignalEventProcessingFinished()
+   * @copydoc Dali::Stage::ContextLostSignal()
    */
-  void EmitEventProcessingFinishedSignal();
+  Dali::Stage::ContextStatusSignal& ContextLostSignal();
 
   /**
-   * Emits the touched signal.
-   * @param[in] touch The touch event details.
+   * @copydoc Dali::Stage::ContextRegainedSignal()
    */
-  void EmitTouchedSignal( const TouchEvent& touch );
+  Dali::Stage::ContextStatusSignal& ContextRegainedSignal();
 
   /**
-   * @copydoc Dali::Stage::KeyEventSignal()
+   * @copydoc Dali::Stage::SceneCreatedSignal()
    */
-  Dali::Stage::KeyEventSignalV2& KeyEventSignal();
+  Dali::Stage::SceneCreatedSignalType& SceneCreatedSignal();
 
   /**
-   * @copydoc Dali::Stage::SignalEventProcessingFinished()
+   * @copydoc Dali::DevelStage::KeyEventGeneratedSignal()
    */
-  Dali::Stage::EventProcessingFinishedSignalV2& EventProcessingFinishedSignal();
+  Dali::DevelStage::KeyEventGeneratedSignalType& KeyEventGeneratedSignal();
 
   /**
-    * @copydoc Dali::Stage::TouchedSignal()
-    */
-  Dali::Stage::TouchedSignalV2& TouchedSignal();
+   * @copydoc Dali::DevelStage::AddFrameCallback()
+   */
+  void AddFrameCallback(FrameCallbackInterface& frameCallback, Actor& rootActor);
 
   /**
-   * @copydoc Dali::Stage::ContextLostSignal()
+   * @copydoc Dali::DevelStage::RemoveFrameCallback()
    */
-  Dali::Stage::ContextStatusSignal& ContextLostSignal();
+  void RemoveFrameCallback(FrameCallbackInterface& frameCallback);
 
   /**
-   * @copydoc Dali::Stage::ContextRegainedSignal()
+   * Connects a callback function with the object's signals.
+   * @param[in] object The object providing the signal.
+   * @param[in] tracker Used to disconnect the signal.
+   * @param[in] signalName The signal to connect to.
+   * @param[in] functor A newly allocated FunctorDelegate.
+   * @return True if the signal was connected.
+   * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
    */
-  Dali::Stage::ContextStatusSignal& ContextRegainedSignal();
+  static bool DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor);
 
 private: // Implementation of ContextNotificationInterface:
-
   /**
    * @copydoc Dali::Integration::NotifyContextLost();
    */
-  virtual void NotifyContextLost();
+  void NotifyContextLost() override;
 
   /**
    * @copydoc Dali::Integration::NotifyContextRegained();
    */
-  virtual void NotifyContextRegained();
+  void NotifyContextRegained() override;
 
 private:
-
   /**
    * Protected constructor; see also Stage::New()
    */
-  Stage( AnimationPlaylist& playlist,
-         PropertyNotificationManager& propertyNotificationManager,
-         SceneGraph::UpdateManager& updateManager,
-         NotificationManager& notificationManager );
+  Stage(SceneGraph::UpdateManager& updateManager);
 
   /**
    * A reference counted object may only be deleted by calling Unreference()
    */
-  virtual ~Stage();
+  ~Stage() override;
 
 private:
-
-  // For 'Fire and forget' animation support
-  AnimationPlaylist& mAnimationPlaylist;
-
-  PropertyNotificationManager& mPropertyNotificationManager;
-
   SceneGraph::UpdateManager& mUpdateManager;
 
-  NotificationManager& mNotificationManager;
-
-  // The Actual size of the stage.
-  Vector2 mSize;
-
-  // Cached for public GetBackgroundColor()
-  Vector4 mBackgroundColor;
-
-  LayerPtr mRootLayer;
-
-  // Ordered list of currently on-stage layers
-  OwnerPointer<LayerList> mLayerList;
-
-  IntrusivePtr<CameraActor> mDefaultCamera;
-
-  ViewMode mViewMode;
-  float mStereoBase;
-
-  Vector2 mDpi;
-
-  // The object registry
-  ObjectRegistryPtr mObjectRegistry;
-
-#ifdef DYNAMICS_SUPPORT
-
-  DynamicsNotifier mDynamicsNotifier;
-
-  // The Dynamics simulation world object
-  Integration::DynamicsFactory* mDynamicsFactory;   // Not owned pointer to DynamicsFactory (PlatformAbstraction will clean up)
-  DynamicsWorldPtr mDynamicsWorld;
-
-#endif // DYNAMICS_SUPPORT
-
-  // The list of render-tasks
-  IntrusivePtr<RenderTaskList> mRenderTaskList;
-
-  Dali::RenderTask mRightRenderTask;
-  IntrusivePtr<CameraActor> mRightCamera;
-  Dali::RenderTask mLeftRenderTask;
-  IntrusivePtr<CameraActor> mLeftCamera;
-
-  Integration::SystemOverlay* mSystemOverlay; ///< SystemOverlay stage access
+  IntrusivePtr<Scene> mScene;
 
   // The key event signal
-  Dali::Stage::KeyEventSignalV2                 mKeyEventSignalV2;
+  Dali::Stage::KeyEventSignalType               mKeyEventSignal;
+  Dali::DevelStage::KeyEventGeneratedSignalType mKeyEventGeneratedSignal;
 
   // The event processing finished signal
-  Dali::Stage::EventProcessingFinishedSignalV2  mEventProcessingFinishedSignalV2;
+  Dali::Stage::EventProcessingFinishedSignalType mEventProcessingFinishedSignal;
 
   // The touched signal
-  Dali::Stage::TouchedSignalV2                  mTouchedSignalV2;
+  Dali::Stage::TouchEventSignalType mTouchedSignal;
+
+  // The wheel event signal
+  Dali::Stage::WheelEventSignalType mWheelEventSignal;
 
   Dali::Stage::ContextStatusSignal mContextLostSignal;
   Dali::Stage::ContextStatusSignal mContextRegainedSignal;
+
+  Dali::Stage::SceneCreatedSignalType mSceneCreatedSignal;
+
+  DevelStage::Rendering mRenderingBehavior; ///< The rendering behavior
 };
 
 } // namespace Internal
@@ -480,7 +364,7 @@ private:
 
 inline Internal::Stage& GetImplementation(Dali::Stage& stage)
 {
-  DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
+  DALI_ASSERT_ALWAYS(stage && "Stage handle is empty");
 
   BaseObject& handle = stage.GetBaseObject();
 
@@ -489,7 +373,7 @@ inline Internal::Stage& GetImplementation(Dali::Stage& stage)
 
 inline const Internal::Stage& GetImplementation(const Dali::Stage& stage)
 {
-  DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
+  DALI_ASSERT_ALWAYS(stage && "Stage handle is empty");
 
   const BaseObject& handle = stage.GetBaseObject();
 
@@ -498,4 +382,4 @@ inline const Internal::Stage& GetImplementation(const Dali::Stage& stage)
 
 } // namespace Dali
 
-#endif // __DALI_INTERNAL_STAGE_H__
+#endif // DALI_INTERNAL_STAGE_H