Merge "Updated all code to new format" into devel/master
[platform/core/uifw/dali-core.git] / dali / internal / event / common / stage-impl.h
index c8b04b8..d62c663 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_STAGE_H
 
 /*
- * Copyright (c) 2017 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/devel-api/common/stage-devel.h>
-#include <dali/public-api/object/base-object.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/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>
+#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 RenderController;
 }
 
 namespace Internal
 {
-
 namespace SceneGraph
 {
 class UpdateManager;
@@ -60,41 +56,27 @@ 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, public EventThreadServices
+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
-   * @param[in] renderController
    */
-  static StagePtr New( AnimationPlaylist& playlist,
-                       PropertyNotificationManager& propertyNotificationManager,
-                       SceneGraph::UpdateManager& updateManager,
-                       NotificationManager& notificationManager,
-                       Integration::RenderController& renderController );
+  static StagePtr New(SceneGraph::UpdateManager& updateManager);
 
   /**
    * Initialize the stage.
-   * @param[in] renderToFbo Whether to render into a Frame Buffer Object.
+   * @param[in] scene The default scene (for main window).
    */
-  void Initialize( bool renderToFbo );
-
-  /**
-   * Uninitialize the stage.
-   */
-  void Uninitialize();
+  void Initialize(Scene& scene);
 
   /**
    * @copydoc Dali::Stage::GetCurrent()
@@ -118,45 +100,17 @@ public:
    */
   Layer& GetRootActor();
 
-  /**
-   * 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 );
-
-  /**
-   * Used to calculate the size of the stage and indirectly, the root actor.
-   * @param [in] width  The new surface width.
-   * @param [in] height The new surface height.
-   */
-  void SurfaceResized( float width, float height );
-
-  /**
-   * Sets the top margin size.
-   * Available stage size is reduced by this size.
-   * The stage is located below the size at the top of the display
-   * initial size is zero before it is assigned
-   * @param[in] margin margin size
-   */
-  void SetTopMargin( unsigned int margin );
+  void Remove(Actor& actor);
 
   /**
    * Returns the size of the Stage in pixels as a Vector.
@@ -172,38 +126,28 @@ public:
   RenderTaskList& GetRenderTaskList() const;
 
   /**
-   * Create a default camera actor
-   */
-  void CreateDefaultCameraActor();
-
-  /**
-   * Set position of default camera for current stage size
-   */
-  void SetDefaultCameraPosition();
-
-  /**
    * 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()
@@ -216,94 +160,57 @@ public:
    */
   LayerList& GetLayerList();
 
-  // System-level overlay actors
-
-  /**
-   * @copydoc Dali::Integration::Core::GetSystemOverlay()
-   */
-  Integration::SystemOverlay& GetSystemOverlay();
-
-  /**
-   * Retrieve the internal implementation of the SystemOverlay.
-   * @return The implementation, or NULL if this has never been requested from Integration API.
-   */
-  SystemOverlay* GetSystemOverlayInternal();
-
-  // Stereoscopy
-
-  /**
-   * @copydoc Dali::Integration::Core::SetViewMode()
-   */
-  void SetViewMode( ViewMode viewMode );
+  // Misc
 
   /**
-   * @copydoc Dali::Integration::Core::GetViewMode()
+   * @copydoc Dali::Stage::SetBackgroundColor
    */
-  ViewMode GetViewMode() const;
+  void SetBackgroundColor(Vector4 color);
 
   /**
-   * @copydoc Dali::Integration::Core::SetStereoBase()
+   * @copydoc Dali::Stage::GetBackgroundColor
    */
-  void SetStereoBase( float stereoBase );
+  Vector4 GetBackgroundColor() const;
 
   /**
-   * @copydoc Dali::Integration::Core::GetStereoBase()
+   * @copydoc Dali::Stage::GetDpi
    */
-  float GetStereoBase() const;
-
-  // Keyboard stuff
+  Vector2 GetDpi() 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
+   * @copydoc Dali::Stage::KeepRendering()
    */
-  void SetKeyboardFocusActor( Actor* actor );
+  void KeepRendering(float durationSeconds);
 
   /**
-   * Get the actor that is currently set to receive keyboard inputs
-   * @return Pointer to the actor set to receive keyboard inputs.
+   * @copydoc Dali::DevelStage::SetRenderingBehavior()
    */
-  Actor* GetKeyboardFocusActor() const;
+  void SetRenderingBehavior(DevelStage::Rendering renderingBehavior);
 
   /**
-   * 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.
+   * @copydoc Dali::DevelStage::GetRenderingBehavior()
    */
-  void RemoveActorFromKeyFocus( Actor* actor );
-
-  // Misc
+  DevelStage::Rendering GetRenderingBehavior() const;
 
   /**
-   * @copydoc Dali::Stage::SetBackgroundColor
+   * Callback for Internal::Scene EventProcessingFinished signal
    */
-  void SetBackgroundColor(Vector4 color);
+  void OnEventProcessingFinished();
 
   /**
-   * @copydoc Dali::Stage::GetBackgroundColor
+   * Callback for Internal::Scene KeyEventSignal signal
    */
-  Vector4 GetBackgroundColor() const;
+  void OnKeyEvent(const Dali::KeyEvent& event);
 
   /**
-   * @copydoc Dali::Stage::GetDpi
+   * Callback for Internal::Scene TouchedSignal signal
    */
-  Vector2 GetDpi() const;
+  void OnTouchEvent(const Dali::TouchEvent& touch);
 
   /**
-   * Sets horizontal and vertical pixels per inch value that is used by the display
-   * @param[in] dpi Horizontal and vertical dpi value
+   * Callback for Internal::Scene WheelEventSignal signal
    */
-  void SetDpi( Vector2 dpi );
-
-  NotificationManager& GetNotificationManager()
-  {
-    return mNotificationManager;
-  }
-
-  /**
-   * @copydoc Dali::Stage::KeepRendering()
-   */
-  void KeepRendering( float durationSeconds );
+  void OnWheelEvent(const Dali::WheelEvent& event);
 
   /**
    * Used by the EventProcessor to emit key event signals.
@@ -327,16 +234,15 @@ public:
 
   /**
    * Emits the touched signal.
-   * @param[in] touchEvent The touch event details (Old API).
    * @param[in] touch The touch event details.
    */
-  void EmitTouchedSignal( const TouchEvent& touchEvent, const Dali::TouchData& touch );
+  void EmitTouchedSignal(const Dali::TouchEvent& touch);
 
   /**
    * Used by the EventProcessor to emit wheel event signals.
    * @param[in] event The wheel event.
    */
-  void EmitWheelEventSignal( const WheelEvent& event );
+  void EmitWheelEventSignal(const WheelEvent& event);
 
   /**
    * Emits the scene created.
@@ -356,12 +262,7 @@ public:
   /**
     * @copydoc Dali::Stage::TouchedSignal()
     */
-  Dali::Stage::TouchedSignalType& TouchedSignal();
-
-  /**
-    * @copydoc Dali::Stage::TouchSignal()
-    */
-  Dali::Stage::TouchSignalType& TouchSignal();
+  Dali::Stage::TouchEventSignalType& TouchedSignal();
 
   /**
    * @copydoc Dali::Stage::WheelEventSignal()
@@ -389,6 +290,16 @@ public:
   Dali::DevelStage::KeyEventGeneratedSignalType& KeyEventGeneratedSignal();
 
   /**
+   * @copydoc Dali::DevelStage::AddFrameCallback()
+   */
+  void AddFrameCallback(FrameCallbackInterface& frameCallback, Actor& rootActor);
+
+  /**
+   * @copydoc Dali::DevelStage::RemoveFrameCallback()
+   */
+  void RemoveFrameCallback(FrameCallbackInterface& frameCallback);
+
+  /**
    * 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.
@@ -397,157 +308,54 @@ public:
    * @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.
    */
-  static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
+  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();
-
-public: // Implementation of EventThreadServices
-
-  /**
-   * @copydoc EventThreadServices::RegisterObject
-   */
-  virtual void RegisterObject( BaseObject* object);
-
-  /**
-   * @copydoc EventThreadServices::UnregisterObject
-   */
-  virtual void UnregisterObject( BaseObject* object);
-
-  /**
-   * @copydoc EventThreadServices::GetUpdateManager
-   */
-  virtual SceneGraph::UpdateManager& GetUpdateManager();
-
-  /**
-   * @copydoc EventThreadServices::GetRenderController
-   */
-  virtual Integration::RenderController& GetRenderController();
-
-  /**
-   * @copydoc EventThreadServices::ReserveMessageSlot
-   */
-  virtual unsigned int* ReserveMessageSlot( std::size_t size, bool updateScene );
-
-  /**
-   * @copydoc EventThreadServices::GetEventBufferIndex
-   */
-  virtual BufferIndex GetEventBufferIndex() const;
-
-  /**
-   * @copydoc EventThreadServices::ForceNextUpdate
-   */
-  virtual void ForceNextUpdate();
-
-  /**
-   * @copydoc EventThreadServices::IsNextUpdateForced
-   */
-  virtual bool IsNextUpdateForced();
-
-  /**
-   * Request that the depth tree is rebuilt
-   */
-  void RequestRebuildDepthTree();
-
-  /**
-   * Rebuilds the depth tree at the end of the event frame if
-   * it was requested this frame.
-   */
-  void RebuildDepthTree();
+  void NotifyContextRegained() override;
 
 private:
-
   /**
    * Protected constructor; see also Stage::New()
    */
-  Stage( AnimationPlaylist& playlist,
-         PropertyNotificationManager& propertyNotificationManager,
-         SceneGraph::UpdateManager& updateManager,
-         NotificationManager& notificationManager,
-         Integration::RenderController& renderController );
+  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;
-
-  Integration::RenderController& mRenderController;
-
-  // The stage-size may be less than surface-size (reduced by top-margin)
-  Vector2 mSize;
-  Vector2 mSurfaceSize;
-
-  // 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;
-
-  unsigned int mTopMargin;
-  Vector2 mDpi;
-
-  // The object registry
-  ObjectRegistryPtr mObjectRegistry;
-
-  // 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::KeyEventSignalType                 mKeyEventSignal;
-  Dali::DevelStage::KeyEventGeneratedSignalType   mKeyEventGeneratedSignal;
+  Dali::Stage::KeyEventSignalType               mKeyEventSignal;
+  Dali::DevelStage::KeyEventGeneratedSignalType mKeyEventGeneratedSignal;
 
   // The event processing finished signal
-  Dali::Stage::EventProcessingFinishedSignalType  mEventProcessingFinishedSignal;
+  Dali::Stage::EventProcessingFinishedSignalType mEventProcessingFinishedSignal;
 
-  // The touched signals
-  Dali::Stage::TouchedSignalType                  mTouchedSignal;
-  Dali::Stage::TouchSignalType                    mTouchSignal;
+  // The touched signal
+  Dali::Stage::TouchEventSignalType mTouchedSignal;
 
   // The wheel event signal
-  Dali::Stage::WheelEventSignalType               mWheelEventSignal;
+  Dali::Stage::WheelEventSignalType mWheelEventSignal;
 
   Dali::Stage::ContextStatusSignal mContextLostSignal;
   Dali::Stage::ContextStatusSignal mContextRegainedSignal;
 
   Dali::Stage::SceneCreatedSignalType mSceneCreatedSignal;
 
-  bool mDepthTreeDirty:1;  ///< True if the depth tree needs recalculating
-  bool mForceNextUpdate:1; ///< True if the next rendering is really required.
-  bool mRenderToFbo:1;     ///< Whether to render to a Frame Buffer Object.
+  DevelStage::Rendering mRenderingBehavior; ///< The rendering behavior
 };
 
 } // namespace Internal
@@ -556,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();
 
@@ -565,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();