Revert "[Tizen] Add codes for Dali Windows Backend"
[platform/core/uifw/dali-core.git] / dali / internal / update / rendering / scene-graph-renderer.h
index 1a86cb9..f1ef2a7 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_SCENE_GRAPH_RENDERER_H
 
 /*
- * Copyright (c) 2016 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.
 #include <dali/internal/update/common/property-owner.h>
 #include <dali/internal/update/common/uniform-map.h>
 #include <dali/internal/update/common/scene-graph-connection-change-propagator.h>
+#include <dali/internal/update/common/animatable-property.h>
 #include <dali/internal/render/data-providers/render-data-provider.h>
 #include <dali/internal/render/renderers/render-renderer.h>
 
 namespace Dali
 {
+
 namespace Internal
 {
 
@@ -58,7 +60,7 @@ class Renderer :  public PropertyOwner,
 {
 public:
 
-  enum Opacity
+  enum OpacityType
   {
     OPAQUE,
     TRANSPARENT,
@@ -118,15 +120,6 @@ public:
   void SetGeometry( Render::Geometry* geometry );
 
   /**
-   * Get the geometry of this renderer
-   * @return the geometry this renderer uses
-   */
-  const Render::Geometry& GetGeometry() const
-  {
-    return *mGeometry;
-  }
-
-  /**
    * Set the depth index
    * @param[in] depthIndex the new depth index to use
    */
@@ -148,64 +141,124 @@ public:
   void SetFaceCullingMode( FaceCullingMode::Type faceCullingMode );
 
   /**
+   * Get face culling mode
+   * @return The face culling mode
+   */
+  FaceCullingMode::Type GetFaceCullingMode() const;
+
+  /**
    * Set the blending mode
    * @param[in] blendingMode to use
    */
   void SetBlendMode( BlendMode::Type blendingMode );
 
   /**
+   * Get the blending mode
+   * @return The the blending mode
+   */
+  BlendMode::Type GetBlendMode() const;
+
+  /**
    * Set the blending options. This should only be called from the update thread.
    * @param[in] options A bitmask of blending options.
    */
   void SetBlendingOptions( unsigned int options );
 
   /**
+   * Get the blending options
+   * @return The the blending mode
+   */
+  unsigned int GetBlendingOptions() const;
+
+  /**
    * Set the blend color for blending operation
    * @param blendColor to pass to GL
    */
   void SetBlendColor( const Vector4& blendColor );
 
   /**
+   * Get the blending color
+   * @return The blend color
+   */
+  Vector4 GetBlendColor() const;
+
+  /**
    * Set the index of first element for indexed draw
    * @param[in] firstElement index of first element to draw
    */
   void SetIndexedDrawFirstElement( size_t firstElement );
 
   /**
+   * Get the index of first element for indexed draw
+   * @return The index of first element for indexed draw
+   */
+  size_t GetIndexedDrawFirstElement() const;
+
+  /**
    * Set the number of elements to draw by indexed draw
    * @param[in] elementsCount number of elements to draw
    */
   void SetIndexedDrawElementsCount( size_t elementsCount );
 
   /**
+   * Get the number of elements to draw by indexed draw
+   * @return The number of elements to draw by indexed draw
+   */
+  size_t GetIndexedDrawElementsCount() const;
+
+  /**
    * @brief Set whether the Pre-multiplied Alpha Blending is required
    * @param[in] preMultipled whether alpha is pre-multiplied.
    */
   void EnablePreMultipliedAlpha( bool preMultipled );
 
   /**
+   * @brief Query whether alpha is pre-multiplied.
+   * @return True is alpha is pre-multiplied, false otherwise.
+   */
+  bool IsPreMultipliedAlphaEnabled() const;
+
+  /**
    * Sets the depth buffer write mode
    * @param[in] depthWriteMode The depth buffer write mode
    */
   void SetDepthWriteMode( DepthWriteMode::Type depthWriteMode );
 
   /**
+   * Get the depth buffer write mode
+   * @return The depth buffer write mode
+   */
+  DepthWriteMode::Type GetDepthWriteMode() const;
+
+  /**
    * Sets the depth buffer test mode
    * @param[in] depthTestMode The depth buffer test mode
    */
   void SetDepthTestMode( DepthTestMode::Type depthTestMode );
 
   /**
+   * Get the depth buffer test mode
+   * @return The depth buffer test mode
+   */
+  DepthTestMode::Type GetDepthTestMode() const;
+
+  /**
    * Sets the depth function
    * @param[in] depthFunction The depth function
    */
   void SetDepthFunction( DepthFunction::Type depthFunction );
 
   /**
-   * Sets the stencil mode
-   * @param[in] mode The stencil function
+   * Get the depth function
+   * @return The depth function
+   */
+  DepthFunction::Type GetDepthFunction() const;
+
+  /**
+   * Sets the render mode
+   * @param[in] mode The render mode
    */
-  void SetStencilMode( StencilMode::Type mode );
+  void SetRenderMode( RenderMode::Type mode );
 
   /**
    * Sets the stencil function
@@ -250,25 +303,24 @@ public:
   void SetStencilOperationOnZPass( StencilOperation::Type stencilOperationOnZPass );
 
   /**
-   * Sets whether or not to write to the color buffer
-   * @param[in] writeToColorBuffer True to write to the color buffer
+   * Gets the stencil parameters
+   * @return The stencil parameters
    */
-  void SetWriteToColorBuffer( bool writeToColorBuffer );
+  const Render::Renderer::StencilParameters& GetStencilParameters() const;
 
   /**
-   * Turns on batching feature for the renderer
-   * @param[in] batchingEnabled if true, enables the batching mode for the renderer
+   * Bakes the opacity
+   * @param[in] updateBufferIndex The current update buffer index.
+   * @param[in] opacity The opacity
    */
-  void SetBatchingEnabled( bool batchingEnabled );
+  void BakeOpacity( BufferIndex updateBufferIndex, float opacity );
 
   /**
-   * Tests whether batching feature is enabled for this renderer
-   * @return batching state
+   * Gets the opacity
+   * @param[in] bufferIndex The buffer to read from.
+   * @return The opacity
    */
-  bool IsBatchingEnabled() const
-  {
-    return mBatchingEnabled;
-  }
+  float GetOpacity( BufferIndex updateBufferIndex ) const;
 
   /**
    * Prepare the object for rendering.
@@ -277,36 +329,29 @@ public:
    */
   void PrepareRender( BufferIndex updateBufferIndex );
 
-  /*
+  /**
    * Retrieve the Render thread renderer
    * @return The associated render thread renderer
    */
   Render::Renderer& GetRenderer();
 
   /**
-   * Check whether the renderer has been marked as ready to render
-   * ready means that renderer has all resources and should produce correct result
-   * complete means all resources have finished loading
-   * It's possible that renderer is complete but not ready,
-   * for example in case of resource load failed
-   * @param[out] ready TRUE if the renderer has resources to render
-   * @param[out] complete TRUE if the renderer resources are complete
-   */
-  void GetReadyAndComplete( bool& ready, bool& complete ) const;
-
-  /**
    * Query whether the renderer is fully opaque, fully transparent or transparent.
    * @param[in] updateBufferIndex The current update buffer index.
    * @return OPAQUE if fully opaque, TRANSPARENT if fully transparent and TRANSLUCENT if in between
    */
-  Opacity GetOpacity( BufferIndex updateBufferIndex, const Node& node ) const;
+  OpacityType GetOpacityType( BufferIndex updateBufferIndex, const Node& node ) const;
 
   /**
    * Called by the TextureSet to notify to the renderer that it has changed
    */
   void TextureSetChanged();
 
-public: // Implementation of ObjectOwnerContainer template methods
+  /**
+   * Called by the TextureSet to notify to the renderer that it is about to be deleted
+   */
+  void TextureSetDeleted();
+
   /**
    * Connect the object to the scene graph
    *
@@ -333,9 +378,6 @@ public: // Implementation of ConnectionChangePropagator
    */
   void RemoveConnectionObserver(ConnectionChangePropagator::Observer& observer){};
 
-public:
-
-
 public: // UniformMap::Observer
   /**
    * @copydoc UniformMap::Observer::UniformMappingsChanged
@@ -385,22 +427,23 @@ private:
   Renderer();
 
   /**
-   * Helper function to create a new render data provider
-   * @return the new (initialized) data provider
+   * Update texture set to the render data provider
    */
-  RenderDataProvider* NewRenderDataProvider();
+  void UpdateTextureSet();
 
 private:
 
   CollectedUniformMap          mCollectedUniformMap[2];           ///< Uniform maps collected by the renderer
+
   SceneController*             mSceneController;                  ///< Used for initializing renderers
   Render::Renderer*            mRenderer;                         ///< Raw pointer to the renderer (that's owned by RenderManager)
   TextureSet*                  mTextureSet;                       ///< The texture set this renderer uses. (Not owned)
   Render::Geometry*            mGeometry;                         ///< The geometry this renderer uses. (Not owned)
   Shader*                      mShader;                           ///< The shader this renderer uses. (Not owned)
-  Vector4*                     mBlendColor;                       ///< The blend color for blending operation
+  RenderDataProvider*          mRenderDataProvider;               ///< The render data provider
+  OwnerPointer< Vector4 >      mBlendColor;                       ///< The blend color for blending operation
 
-  Render::Renderer::StencilParameters mStencilParameters;         ///< Struct containing all stencil related options
+  Dali::Internal::Render::Renderer::StencilParameters mStencilParameters;         ///< Struct containing all stencil related options
 
   size_t                       mIndexedDrawFirstElement;          ///< first element index to be drawn using indexed draw
   size_t                       mIndexedDrawElementsCount;         ///< number of elements to be drawn using indexed draw
@@ -413,17 +456,15 @@ private:
   BlendMode::Type              mBlendMode:2;                      ///< Local copy of the mode of blending
   DepthWriteMode::Type         mDepthWriteMode:2;                 ///< Local copy of the depth write mode
   DepthTestMode::Type          mDepthTestMode:2;                  ///< Local copy of the depth test mode
-  bool                         mWriteToColorBuffer:1;             ///< Local copy of the write to color buffer flag
 
   bool                         mUniformMapChanged[2];             ///< Records if the uniform map has been altered this frame
-  bool                         mResourcesReady;                   ///< Set during the Update algorithm; true if the renderer has resources ready for the current frame.
-  bool                         mFinishedResourceAcquisition;      ///< Set during DoPrepareResources; true if ready & all resource acquisition has finished (successfully or otherwise)
   bool                         mPremultipledAlphaEnabled:1;       ///< Flag indicating whether the Pre-multiplied Alpha Blending is required
 
 public:
 
-  bool                         mBatchingEnabled : 1;              ///< Flag indicating whether the render supports batching
+  AnimatableProperty< float >  mOpacity;                          ///< The opacity value
   int                          mDepthIndex;                       ///< Used only in PrepareRenderInstructions
+
 };
 
 
@@ -572,14 +613,14 @@ inline void SetDepthFunctionMessage( EventThreadServices& eventThreadServices, c
   new (slot) LocalType( &renderer, &Renderer::SetDepthFunction, depthFunction );
 }
 
-inline void SetStencilModeMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, StencilMode::Type mode )
+inline void SetRenderModeMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, RenderMode::Type mode )
 {
-  typedef MessageValue1< Renderer, StencilMode::Type > LocalType;
+  typedef MessageValue1< Renderer, RenderMode::Type > LocalType;
 
   // Reserve some memory inside the message queue
   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
 
-  new (slot) LocalType( &renderer, &Renderer::SetStencilMode, mode );
+  new (slot) LocalType( &renderer, &Renderer::SetRenderMode, mode );
 }
 
 inline void SetStencilFunctionMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, StencilFunction::Type stencilFunction )
@@ -652,24 +693,14 @@ inline void SetStencilOperationOnZPassMessage( EventThreadServices& eventThreadS
   new (slot) LocalType( &renderer, &Renderer::SetStencilOperationOnZPass, stencilOperation );
 }
 
-inline void SetWriteToColorBufferMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, bool writeToColorBuffer )
+inline void BakeOpacityMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, float opacity )
 {
-  typedef MessageValue1< Renderer, bool > LocalType;
-
-  // Reserve some memory inside the message queue
-  unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
-
-  new (slot) LocalType( &renderer, &Renderer::SetWriteToColorBuffer, writeToColorBuffer );
-}
-
-inline void SetBatchingEnabledMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, bool batchable )
-{
-  typedef MessageValue1< Renderer, bool > LocalType;
+  typedef MessageDoubleBuffered1< Renderer, float > LocalType;
 
   // Reserve some memory inside the message queue
   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
 
-  new (slot) LocalType( &renderer, &Renderer::SetBatchingEnabled, batchable );
+  new (slot) LocalType( &renderer, &Renderer::BakeOpacity, opacity );
 }
 
 } // namespace SceneGraph