Remove RenderSurface from Core
[platform/core/uifw/dali-core.git] / dali / integration-api / core.h
index 780d096..f2a9f7a 100644 (file)
@@ -1,8 +1,8 @@
-#ifndef __DALI_INTEGRATION_CORE_H__
-#define __DALI_INTEGRATION_CORE_H__
+#ifndef DALI_INTEGRATION_CORE_H
+#define DALI_INTEGRATION_CORE_H
 
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * 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.
  */
 
 // EXTERNAL INCLUDES
+#include <cstdint> // uint32_t
+
+// INTERNAL INCLUDES
 #include <dali/public-api/common/dali-common.h>
-#include <dali/public-api/common/view-mode.h>
+#include <dali/integration-api/context-notifier.h>
+#include <dali/integration-api/core-enumerations.h>
 
 namespace Dali
 {
 
+class Layer;
+class RenderTaskList;
+
 namespace Internal
 {
 class Core;
@@ -32,39 +39,37 @@ class Core;
 
 namespace Integration
 {
-
 class Core;
-class GestureManager;
 class GlAbstraction;
 class GlSyncAbstraction;
+class GlContextHelperAbstraction;
 class PlatformAbstraction;
+class Processor;
 class RenderController;
-class SystemOverlay;
+class Scene;
 struct Event;
 struct TouchData;
 
+
 /**
  * The reasons why further updates are required.
  */
-namespace KeepUpdating DALI_IMPORT_API
+namespace KeepUpdating
 {
-  extern const unsigned int NOT_REQUESTED; ///< Zero means that no further updates are required
-
-  // Bit-field values
-  extern const unsigned int STAGE_KEEP_RENDERING;   ///< 0x01 - Stage::KeepRendering() is being used
-  extern const unsigned int INCOMING_MESSAGES;      ///< 0x02 - Event-thread is sending messages to update-thread
-  extern const unsigned int ANIMATIONS_RUNNING;     ///< 0x04 - Animations are ongoing
-  extern const unsigned int DYNAMICS_CHANGED;       ///< 0x08 - A dynamics simulation is running
-  extern const unsigned int LOADING_RESOURCES;      ///< 0x10 - Resources are being loaded
-  extern const unsigned int NOTIFICATIONS_PENDING;  ///< 0x20 - Notifications are pending for the event-thread
-  extern const unsigned int MONITORING_PERFORMANCE; ///< 0x40 - The --enable-performance-monitor option is being used
-  extern const unsigned int RENDER_TASK_SYNC;       ///< 0x80 - A render task is waiting for render sync
+enum Reasons
+{
+  NOT_REQUESTED           = 0,    ///< Zero means that no further updates are required
+  STAGE_KEEP_RENDERING    = 1<<1, ///<  - Stage::KeepRendering() is being used
+  ANIMATIONS_RUNNING      = 1<<2, ///< - Animations are ongoing
+  MONITORING_PERFORMANCE  = 1<<3, ///< - The --enable-performance-monitor option is being used
+  RENDER_TASK_SYNC        = 1<<4  ///< - A render task is waiting for render sync
 };
+}
 
 /**
  * The status of the Core::Update operation.
  */
-class DALI_IMPORT_API UpdateStatus
+class UpdateStatus
 {
 public:
 
@@ -74,6 +79,7 @@ public:
   UpdateStatus()
   : keepUpdating(false),
     needsNotification(false),
+    surfaceRectChanged(false),
     secondsFromLastFrame( 0.0f )
   {
   }
@@ -84,7 +90,7 @@ public:
    * Query whether the Core has further frames to update & render e.g. when animations are ongoing.
    * @return A bitmask of KeepUpdating values
    */
-  unsigned int KeepUpdating() { return keepUpdating; }
+  uint32_t KeepUpdating() { return keepUpdating; }
 
   /**
    * Query whether the Core requires an Notification event.
@@ -94,6 +100,12 @@ public:
   bool NeedsNotification() { return needsNotification; }
 
   /**
+   * Query wheter the default surface rect is changed or not.
+   * @return true if the default surface rect is changed.
+   */
+  bool SurfaceRectChanged() { return surfaceRectChanged; }
+
+  /**
    * This method is provided so that FPS can be easily calculated with a release version
    * of Core.
    * @return the seconds from last frame as float
@@ -102,15 +114,16 @@ public:
 
 public:
 
-  unsigned int keepUpdating; ///< A bitmask of KeepUpdating values
+  uint32_t keepUpdating; ///< A bitmask of KeepUpdating values
   bool needsNotification;
+  bool surfaceRectChanged;
   float secondsFromLastFrame;
 };
 
 /**
  * The status of the Core::Render operation.
  */
-class DALI_IMPORT_API RenderStatus
+class RenderStatus
 {
 public:
 
@@ -118,41 +131,55 @@ public:
    * Constructor
    */
   RenderStatus()
-  : needsUpdate(false),
-    hasRendered(false)
+  : needsUpdate( false ),
+    needsPostRender( false )
   {
   }
 
   /**
    * Set whether update needs to run following a render.
-   * This might be because render has sent messages to update, or it has
-   * some textures to upload over several frames.
+   * @param[in] updateRequired Set to true if an update is required to be run
    */
-  void SetNeedsUpdate(bool updateRequired) { needsUpdate = updateRequired; }
+  void SetNeedsUpdate( bool updateRequired )
+  {
+    needsUpdate = updateRequired;
+  }
 
   /**
    * Query the update status following rendering of a frame.
-   * @return true if update should run.
+   * @return True if update is required to be run
    */
-  bool NeedsUpdate() { return needsUpdate; }
+  bool NeedsUpdate() const
+  {
+    return needsUpdate;
+  }
 
   /**
-   * Set whether there were new render instructions.
+   * Sets if a post-render should be run.
+   * If nothing is rendered this frame, we can skip post-render.
+   * @param[in] postRenderRequired Set to True if post-render is required to be run
    */
-  void SetHasRendered(bool rendered) { hasRendered = rendered; }
+  void SetNeedsPostRender( bool postRenderRequired )
+  {
+    needsPostRender = postRenderRequired;
+  }
 
   /**
-   * Query whether there were new render instructions.
-   * @return true if there were render instructions
+   * Queries if a post-render should be run.
+   * @return True if post-render is required to be run
    */
-  bool HasRendered() { return hasRendered; }
+  bool NeedsPostRender() const
+  {
+    return needsPostRender;
+  }
 
 private:
 
-  bool needsUpdate;
-  bool hasRendered;
+  bool needsUpdate      :1;  ///< True if update is required to be run
+  bool needsPostRender  :1;  ///< True if post-render is required to be run.
 };
 
+
 /**
  * Integration::Core is used for integration with the native windowing system.
  * The following integration tasks must be completed:
@@ -171,14 +198,6 @@ private:
  *
  * 6) Provide an implementation of the GlAbstraction interface, used to access OpenGL services.
  *
- * 7) Provide an implementation of the GestureManager interface, used to register gestures provided by the platform.
- *
- * Suspend/Resume behaviour:
- *
- * The Core has no knowledge of the application lifecycle, but can be suspended.
- * In the suspended state, input events will not be processed, and animations will not progress any further.
- * The Core can still render in the suspended state; the same frame will be produced each time.
- *
  * Multi-threading notes:
  *
  * The Dali API methods are not reentrant.  If you access the API from multiple threads simultaneously, then the results
@@ -194,7 +213,7 @@ private:
  * This is the recommended option, so that input processing will not affect the smoothness of animations.
  * Note that the rendering thread must be halted, before destroying the GL context.
  */
-class DALI_IMPORT_API Core
+class DALI_CORE_API Core
 {
 public:
 
@@ -205,23 +224,39 @@ public:
    * @param[in] platformAbstraction The interface providing platform specific services.
    * @param[in] glAbstraction The interface providing OpenGL services.
    * @param[in] glSyncAbstraction The interface providing OpenGL sync objects.
-   * @param[in] gestureManager The interface providing gesture manager services.
+   * @param[in] glContextHelperAbstraction The interface providing OpenGL context helper objects.
+   * @param[in] renderToFboEnabled Whether rendering into the Frame Buffer Object is enabled.
+   * @param[in] depthBufferAvailable Whether the depth buffer is available
+   * @param[in] stencilBufferAvailable Whether the stencil buffer is available
    * @return A newly allocated Core.
    */
-  static Core* New(RenderController& renderController,
-                   PlatformAbstraction& platformAbstraction,
-                   GlAbstraction& glAbstraction,
-                   GlSyncAbstraction& glSyncAbstraction,
-                   GestureManager& gestureManager);
+  static Core* New( RenderController& renderController,
+                    PlatformAbstraction& platformAbstraction,
+                    GlAbstraction& glAbstraction,
+                    GlSyncAbstraction& glSyncAbstraction,
+                    GlContextHelperAbstraction& glContextHelperAbstraction,
+                    RenderToFrameBuffer renderToFboEnabled,
+                    DepthBufferAvailable depthBufferAvailable,
+                    StencilBufferAvailable stencilBufferAvailable );
 
   /**
    * Non-virtual destructor. Core is not intended as a base class.
    */
   ~Core();
 
+  /**
+   * Initialize the core
+   */
+  void Initialize();
+
   // GL Context Lifecycle
 
   /**
+   * Get the object that will notify the application/toolkit when context is lost/regained
+   */
+  ContextNotifierInterface* GetContextNotifier();
+
+  /**
    * Notify the Core that the GL context has been created.
    * The context must be created before the Core can render.
    * Multi-threading note: this method should be called from the rendering thread only
@@ -235,70 +270,29 @@ public:
    * Multi-threading note: this method should be called from the rendering thread only
    * @post The Core is unaware of any GL context.
    */
-  void ContextToBeDestroyed();
-
-  /**
-   * Notify the Core that the GL surface has been resized.
-   * This should be done at least once i.e. after the first call to ContextCreated().
-   * The Core will use the surface size for camera calculations, and to set the GL viewport.
-   * Multi-threading note: this method should be called from the main thread
-   * @param[in] width The new surface width.
-   * @param[in] height The new surface height.
-   */
-  void SurfaceResized(unsigned int width, unsigned int height);
-
-  // Core setters
-
-  /**
-   * Notify the Core about the display's DPI values.
-   * This should be done after the display is initialized and a Core instance is created.
-   * The Core will use the DPI values for font rendering.
-   * Multi-threading note: this method should be called from the main thread
-   * @param[in] dpiHorizontal Horizontal DPI value.
-   * @param[in] dpiVertical   Vertical DPI value.
-   */
-  void SetDpi(unsigned int dpiHorizontal, unsigned int dpiVertical);
+  void ContextDestroyed();
 
   /**
-   * Sets the expected interval between frames used to predict future intervals and the time when the
-   * next render will take place.
+   * Notify the Core that the GL context has been re-created, e.g. after ReplaceSurface
+   * or Context loss.
    *
-   * This is the minimum interval that Core should expect. Core will adapt the predicted interval
-   * accordingly if the expected interval is constantly not met (but will not drop it below this
-   * amount).
+   * In the case of ReplaceSurface, both ContextToBeDestroyed() and ContextCreated() will have
+   * been called on the render thread before this is called on the event thread.
    *
-   * The value provided should be in microseconds.
-   *
-   * @param[in]  interval  The minimum interval between frames (in microseconds).
-   *
-   * Multi-threading note: this method should be called from the render thread
+   * Multi-threading note: this method should be called from the main thread
    */
-  void SetMinimumFrameTimeInterval(unsigned int interval);
+  void RecoverFromContextLoss();
 
   // Core Lifecycle
 
   /**
-   * Put Core into the suspended state.
-   * Any ongoing event processing will be cancelled, for example multi-touch sequences.
-   * The core expects the system has suspended us. Animation time will continue during the suspended
-   * state.
-   * Multi-threading note: this method should be called from the main thread
-   * @post The Core is in the suspended state.
-   */
-  void Suspend();
-
-  /**
-   * Resume the Core from the suspended state.
-   * At the first update, the elapsed time passed to the animations will be equal to the time spent
-   * suspended.
-   * Multi-threading note: this method should be called from the main thread
-   * @post The Core is not in the suspended state.
+   * Notify Core that the scene has been created.
    */
-  void Resume();
+  void SceneCreated();
 
   /**
    * Queue an event with Core.
-   * Pre-processing of events may be benificial e.g. a series of motion events could be throttled, so that only the last event is queued.
+   * Pre-processing of events may be beneficial e.g. a series of motion events could be throttled, so that only the last event is queued.
    * Multi-threading note: this method should be called from the main thread.
    * @param[in] event The new event.
    */
@@ -312,15 +306,6 @@ public:
   void ProcessEvents();
 
   /**
-   * Update external raw touch data in core.
-   * The core will use the touch data to generate Dali Touch/Gesture events for applications to use
-   * in the update thread.
-   * @param[in] touch The raw touch data.
-   * @note This can be called from either the event thread OR a dedicated touch thread.
-   */
-  void UpdateTouchData(const TouchData& touch);
-
-  /**
    * The Core::Update() method prepares a frame for rendering. This method determines how many frames
    * may be prepared, ahead of the rendering.
    * For example if the maximum update count is 2, then Core::Update() for frame N+1 may be processed
@@ -328,7 +313,7 @@ public:
    * the Core::Render() method for frame N has returned.
    * @return The maximum update count (>= 1).
    */
-  unsigned int GetMaximumUpdateCount() const;
+  uint32_t GetMaximumUpdateCount() const;
 
   /**
    * Update the scene for the next frame. This method must be called before each frame is rendered.
@@ -337,76 +322,66 @@ public:
    * However the update-thread must wait until frame N has been rendered, before processing frame N+2.
    * After this method returns, messages may be queued internally for the main thread.
    * In order to process these messages, a notification is sent via the main thread's event loop.
+   * @param[in] elapsedSeconds Number of seconds since the last call
+   * @param[in] lastVSyncTimeMilliseconds The last vsync time in milliseconds
+   * @param[in] nextVSyncTimeMilliseconds The time of the next predicted VSync in milliseconds
    * @param[out] status showing whether further updates are required. This also shows
    * whether a Notification event should be sent, regardless of whether the multi-threading is used.
+   * @param[in] renderToFboEnabled Whether rendering into the Frame Buffer Object is enabled.
+   * @param[in] isRenderingToFbo Whether this frame is being rendered into the Frame Buffer Object.
    */
-  void Update( UpdateStatus& status );
+  void Update( float elapsedSeconds,
+               uint32_t lastVSyncTimeMilliseconds,
+               uint32_t nextVSyncTimeMilliseconds,
+               UpdateStatus& status,
+               bool renderToFboEnabled,
+               bool isRenderingToFbo );
 
   /**
-   * Render the next frame. This method should be preceded by a call up Update.
+   * This is called before rendering any scene in the next frame. This method should be preceded
+   * by a call up Update.
    * Multi-threading note: this method should be called from a dedicated rendering thread.
    * @pre The GL context must have been created, and made current.
    * @param[out] status showing whether update is required to run.
+   * @param[in] forceClear force the Clear on the framebuffer even if nothing is rendered.
+   * @param[in] uploadOnly uploadOnly Upload the resource only without rendering.
    */
-  void Render( RenderStatus& status );
-
-  /**
-   * Tells core that it is about to sleep.
-   * Application is running as normal, but no updates are taking place i.e. no ongoing animations.
-   * This should be called when we choose to stop updating and rendering when there are no screen
-   * updates required.
-   * Multi-threading note: this method should be called from the update-thread.
-   */
-  void Sleep();
-
-  /**
-   * Wakes up core from a sleep state.
-   * At the first update the elapsed time passed to the animations is zero.
-   * Multi-threading note: this method should be called from the update-thread.
-   */
-  void WakeUp();
-
-  /**
-   * Notification of a vertical blank sync
-   * @param[in] frameNumber  The frame number of this vsync. This number will not update
-   *                         while paused.
-   * @param[in] seconds      The timestamp seconds
-   * @param[in] microseconds The timestamp microseconds
-   */
-  void VSync( unsigned int frameNumber, unsigned int seconds, unsigned int microseconds );
-
-  // System-level overlay
+  void PreRender( RenderStatus& status, bool forceClear, bool uploadOnly );
 
   /**
-   * Use the SystemOverlay to draw content for system-level indicators, dialogs etc.
-   * @return The SystemOverlay.
+   * Render a scene in the next frame. This method should be preceded by a call up PreRender.
+   * This method should be called twice. The first pass to render off-screen frame buffers if any,
+   * and the second pass to render the surface.
+   * Multi-threading note: this method should be called from a dedicated rendering thread.
+   * @pre The GL context must have been created, and made current.
+   * @param[in] scene The scene to be rendered.
+   * @param[in] renderToFbo True to render off-screen frame buffers only if any, and False to render the surface only.
    */
-  SystemOverlay& GetSystemOverlay();
+  void RenderScene( Integration::Scene& scene, bool renderToFbo );
 
-  /**
-   * Set the stereoscopic 3D view mode
-   * @param[in] viewMode The new view mode
-   */
-  void SetViewMode( ViewMode viewMode );
 
   /**
-   * Get the current view mode
-   * @return The current view mode
-   * @see SetViewMode.
+   * This is called after rendering all the scenes in the next frame. This method should be
+   * followed by a call up RenderScene.
+   * Multi-threading note: this method should be called from a dedicated rendering thread.
+   * @pre The GL context must have been created, and made current.
+   * @param[in] uploadOnly uploadOnly Upload the resource only without rendering.
    */
-  ViewMode GetViewMode() const;
+  void PostRender( bool uploadOnly );
 
   /**
-   * Set the stereo base (eye seperation) for stereoscopic 3D
-   * @param[in] stereoBase The stereo base (eye seperation) for stereoscopic 3D (mm)
+   * @brief Register a processor
+   *
+   * Note, Core does not take ownership of this processor.
+   * @param[in] processor The process to register
    */
-  void SetStereoBase( float stereoBase );
+  void RegisterProcessor( Processor& processor );
 
   /**
-   * Get the stereo base (eye seperation) for stereoscopic 3D
-   * @return The stereo base (eye seperation) for stereoscopic 3D (mm)
+   * @brief Unregister a processor
+   * @param[in] processor The process to unregister
    */
-  float GetStereoBase() const;
+  void UnregisterProcessor( Processor& processor );
 
 private:
 
@@ -439,4 +414,4 @@ private:
 
 } // namespace Dali
 
-#endif // __DALI_INTEGRATION_CORE_H__
+#endif // DALI_INTEGRATION_CORE_H