[Tizen] Support asan build option
[platform/core/uifw/dali-core.git] / dali / internal / event / rendering / shader-impl.h
index a1b25cf..0f597d1 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_SHADER_H
 
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 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/common/dali-common.h> // DALI_ASSERT_ALWAYS
-#include <dali/public-api/common/intrusive-ptr.h> // Dali::IntrusivePtr
-#include <dali/devel-api/rendering/shader.h> // Dali::Shader
+#include <dali/internal/common/shader-data.h>            // ShaderPtr
 #include <dali/internal/event/common/object-connector.h> // Dali::Internal::ObjectConnector
-#include <dali/internal/event/common/object-impl.h> // Dali::Internal::Object
-#include <dali/internal/event/resources/resource-ticket.h> // Dali::Internal::ResourceTicketPtr
+#include <dali/internal/event/common/object-impl.h>      // Dali::Internal::Object
+#include <dali/public-api/common/dali-common.h>          // DALI_ASSERT_ALWAYS
+#include <dali/public-api/common/intrusive-ptr.h>        // Dali::IntrusivePtr
+#include <dali/public-api/rendering/shader.h>            // Dali::Shader
 
 namespace Dali
 {
@@ -36,7 +36,7 @@ class Shader;
 }
 
 class Shader;
-typedef IntrusivePtr<Shader> ShaderPtr;
+using ShaderPtr = IntrusivePtr<Shader>;
 
 /**
  * Shader is an object that contains an array of structures of values that
@@ -45,129 +45,116 @@ typedef IntrusivePtr<Shader> ShaderPtr;
 class Shader : public Object
 {
 public:
-
   /**
    * @copydoc Dali::Shader::New()
    */
-  static ShaderPtr New( const std::string& vertexShader,
-                        const std::string& fragmentShader,
-                        Dali::Shader::ShaderHints hints );
-
-  /**
-   * @brief Get the shader scene object
-   *
-   * @return the shader scene object
-   */
-  const SceneGraph::Shader* GetShaderSceneObject() const;
-
-public: // Default property extensions from Object
-
-  /**
-   * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
-   */
-  virtual unsigned int GetDefaultPropertyCount() const;
+  static ShaderPtr New(std::string_view          vertexShader,
+                       std::string_view          fragmentShader,
+                       Dali::Shader::Hint::Value hints,
+                       std::string_view          shaderName);
 
   /**
-   * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
-   */
-  virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
-
-  /**
-   * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
+   * @copydoc Dali::Shader::New()
    */
-  virtual const char* GetDefaultPropertyName(Property::Index index) const;
+  static ShaderPtr New(Dali::Property::Value shaderMap);
 
   /**
-   * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
+   * Retrieve the scene-graph shader added by this object.
+   * @return A pointer to the shader.
    */
-  virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
+  const SceneGraph::Shader& GetShaderSceneObject() const;
 
+public: // Default property extensions from Object
   /**
-   * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
+   * @copydoc Dali::Internal::Object::SetDefaultProperty()
    */
-  virtual bool IsDefaultPropertyWritable(Property::Index index) const;
+  void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue) override;
 
   /**
-   * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
+   * @copydoc Dali::Internal::Object::GetDefaultProperty()
    */
-  virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
+  Property::Value GetDefaultProperty(Property::Index index) const override;
 
   /**
-   * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
+   * @copydoc Dali::Internal::Object::GetDefaultPropertyCurrentValue()
    */
-  virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
+  Property::Value GetDefaultPropertyCurrentValue(Property::Index index) const override;
 
+private: // implementation
   /**
-   * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
+   * Constructor
+   *
+   * @param[in] sceneObject the scene object
    */
-  virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
+  Shader(const SceneGraph::Shader* sceneObject);
 
   /**
-   * @copydoc Dali::Internal::Object::SetDefaultProperty()
+   * @brief Update Shader Data
+   * If a ShaderData of the same renderPassTag is already exist, it is replaced,
+   * if not, new ShaderData is added.
+   * @param[in] vertexShader Vertex shader code for the effect.
+   * @param[in] fragmentShader Fragment Shader code for the effect.
+   * @param[in] renderPassTag render pass tag of this shader data
+   * @param[in] hints Hints to define the geometry of the rendered object
+   * @param[in] name The name of shader data.
    */
-  virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
+  void UpdateShaderData(std::string_view vertexShader, std::string_view fragmentShader, uint32_t renderPassTag, Dali::Shader::Hint::Value hints, std::string_view name);
 
   /**
-   * @copydoc Dali::Internal::Object::SetSceneGraphProperty()
+   * @brief Sets shader data from shaderMap.
+   * The shaderMap should be Property::Map or Property::Array.
+   * @param[in] shaderMap shader property map.
    */
-  virtual void SetSceneGraphProperty( Property::Index index, const PropertyMetadata& entry, const Property::Value& value );
+  void SetShaderProperty(const Dali::Property::Value& shaderMap);
 
+protected:
   /**
-   * @copydoc Dali::Internal::Object::GetDefaultProperty()
+   * A reference counted object may only be deleted by calling Unreference()
    */
-  virtual Property::Value GetDefaultProperty( Property::Index index ) const;
+  ~Shader() override;
 
-  /**
-   * @copydoc Dali::Internal::Object::GetPropertyOwner()
-   */
-  virtual const SceneGraph::PropertyOwner* GetPropertyOwner() const;
+private: // unimplemented methods
+  Shader()              = delete;
+  Shader(const Shader&) = delete;
+  Shader& operator=(const Shader&) = delete;
 
-  /**
-   * @copydoc Dali::Internal::Object::GetSceneObject()
-   */
-  virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
+private:
+  std::vector<Internal::ShaderDataPtr> mShaderDataList;
 
+public:
   /**
-   * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
+   * @copydoc Dali::Shader::GetShaderLanguageVersion()
    */
-  virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
+  static uint32_t GetShaderLanguageVersion();
 
   /**
-   * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
+   * @copydoc Dali::Shader::GetShaderVersionPrefix()
    */
-  virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
+  static std::string GetShaderVersionPrefix();
 
   /**
-   * @copydoc Dali::Internal::Object::GetPropertyComponentIndex()
+   * @copydoc Dali::Shader::GetVertexShaderPrefix()
    */
-  virtual int GetPropertyComponentIndex( Property::Index index ) const;
-
-private: // implementation
-  Shader();
+  static std::string GetVertexShaderPrefix();
 
   /**
-   * Second stage initialization
+   * @copydoc Dali::Shader::GetFragmentShaderPrefix()
    */
-  void Initialize( const std::string& vertexShader, const std::string& fragmentShader, Dali::Shader::ShaderHints hints );
+  static std::string GetFragmentShaderPrefix();
 
-protected:
+public:
   /**
-   * A reference counted object may only be deleted by calling Unreference()
+   * Generates tag 'legacy-prefix-end' with end position of
+   * prefix text to make shader code parsing easier.
+   * Function is public to be testable
    */
-  virtual ~Shader();
-
-private: // unimplemented methods
-  Shader( const Shader& );
-  Shader& operator=( const Shader& );
-
-private:
-  SceneGraph::Shader* mSceneObject;
+  static std::string GenerateTaggedShaderPrefix(const std::string& shaderPrefix);
 };
 
 } // namespace Internal
 
 // Helpers for public-api forwarding methods
-inline Internal::Shader& GetImplementation( Dali::Shader& handle )
+inline Internal::Shader& GetImplementation(Dali::Shader& handle)
 {
   DALI_ASSERT_ALWAYS(handle && "Shader handle is empty");
 
@@ -176,7 +163,7 @@ inline Internal::Shader& GetImplementation( Dali::Shader& handle )
   return static_cast<Internal::Shader&>(object);
 }
 
-inline const Internal::Shader& GetImplementation( const Dali::Shader& handle )
+inline const Internal::Shader& GetImplementation(const Dali::Shader& handle)
 {
   DALI_ASSERT_ALWAYS(handle && "Shader handle is empty");