Apply Visual's transform + borderline properties for partial update
[platform/core/uifw/dali-core.git] / dali / internal / common / shader-data.h
index 35d6d9a..3d50cfa 100644 (file)
@@ -1,8 +1,8 @@
-#ifndef __DALI_INTERNAL_SHADER_DATA_H__
-#define __DALI_INTERNAL_SHADER_DATA_H__
+#ifndef DALI_INTERNAL_SHADER_DATA_H
+#define DALI_INTERNAL_SHADER_DATA_H
 
 /*
- * Copyright (c) 2015 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.
 #include <string>
 
 // INTERNAL INCLUDES
-#include <dali/public-api/object/ref-object.h>
+#include <dali/graphics-api/graphics-types.h>
 #include <dali/public-api/common/dali-vector.h>
-#include <dali/devel-api/rendering/shader.h> // ShaderHints
+#include <dali/public-api/object/ref-object.h>
+#include <dali/public-api/rendering/shader.h> // ShaderHints
 
 namespace Dali
 {
-
 namespace Internal
 {
-
 class ShaderData;
-typedef IntrusivePtr<ShaderData> ShaderDataPtr;
+using ShaderDataPtr = IntrusivePtr<ShaderData>;
+
+namespace
+{
+static const std::vector<char> emptyShader;
+
+inline std::vector<char> StringToVector(const std::string& str)
+{
+  auto retval = std::vector<char>{};
+  retval.insert(retval.begin(), str.begin(), str.end());
+  retval.push_back('\0');
+  return retval;
+}
+
+} // namespace
 
 /**
  * ShaderData class.
@@ -42,38 +55,54 @@ typedef IntrusivePtr<ShaderData> ShaderDataPtr;
 class ShaderData : public Dali::RefObject
 {
 public:
-
   /**
    * Constructor
    * @param[in] vertexSource   Source code for vertex program
    * @param[in] fragmentSource Source code for fragment program
+   * @param[in] hints          Hints for rendering
    */
-  ShaderData(const std::string& vertexSource, const std::string& fragmentSource, const Dali::Shader::ShaderHints hints)
-  : mShaderHash( -1 ),
+  ShaderData(std::string vertexSource, std::string fragmentSource, const Dali::Shader::Hint::Value hints)
+  : mShaderHash(-1),
+    mVertexShader(StringToVector(vertexSource)),
+    mFragmentShader(StringToVector(fragmentSource)),
+    mHints(hints),
+    mSourceMode(Graphics::ShaderSourceMode::TEXT)
+  {
+  }
+
+  /**
+   * Creates a shader data containing binary content
+   * @param[in] vertexSource   Source code for vertex program
+   * @param[in] fragmentSource Source code for fragment program
+   * @param[in] hints          Hints for rendering
+   */
+  ShaderData(std::vector<char>& vertexSource, std::vector<char>& fragmentSource, const Dali::Shader::Hint::Value hints)
+  : mShaderHash(-1),
     mVertexShader(vertexSource),
     mFragmentShader(fragmentSource),
-    mHints(hints)
-  { }
+    mHints(hints),
+    mSourceMode(Graphics::ShaderSourceMode::BINARY)
+  {
+  }
 
 protected:
   /**
    * Protected Destructor
    * A reference counted object may only be deleted by calling Unreference()
    */
-  virtual ~ShaderData()
+  ~ShaderData() override
   {
     // vector releases its data
   }
 
 public: // API
-
   /**
    * Set hash value which is created with vertex and fragment shader code
    * @param [in] shaderHash  hash key created with vertex and fragment shader code
    */
   void SetHashValue(size_t shaderHash)
   {
-    DALI_ASSERT_DEBUG( shaderHash != size_t(-1) );
+    DALI_ASSERT_DEBUG(shaderHash != size_t(-1));
     mShaderHash = shaderHash;
   }
 
@@ -83,7 +112,7 @@ public: // API
    */
   size_t GetHashValue() const
   {
-    DALI_ASSERT_DEBUG( mShaderHash != size_t(-1) );
+    DALI_ASSERT_DEBUG(mShaderHash != size_t(-1));
     return mShaderHash;
   }
 
@@ -92,7 +121,7 @@ public: // API
    */
   const char* GetVertexShader() const
   {
-    return mVertexShader.c_str();
+    return &mVertexShader[0];
   }
 
   /**
@@ -100,13 +129,35 @@ public: // API
    */
   const char* GetFragmentShader() const
   {
-    return mFragmentShader.c_str();
+    return &mFragmentShader[0];
+  }
+
+  /**
+   * Returns a std::vector containing the shader code associated with particular pipeline stage
+   * @param[in] the graphics pipeline stage
+   * @return the shader code
+   */
+  const std::vector<char>& GetShaderForPipelineStage(Graphics::PipelineStage stage) const
+  {
+    if(stage == Graphics::PipelineStage::VERTEX_SHADER)
+    {
+      return mVertexShader;
+    }
+    else if(stage == Graphics::PipelineStage::FRAGMENT_SHADER)
+    {
+      return mFragmentShader;
+    }
+    else
+    {
+      //      DALI_LOG_ERROR("Unsupported shader stage\n");
+      return emptyShader;
+    }
   }
 
   /**
    * @return the hints
    */
-  Dali::Shader::ShaderHints GetHints() const
+  Dali::Shader::Hint::Value GetHints() const
   {
     return mHints;
   }
@@ -123,16 +174,16 @@ public: // API
    * Allocate a buffer for the compiled binary bytecode
    * @param[in] size  The size of the buffer in bytes
    */
-  void AllocateBuffer( size_t size )
+  void AllocateBuffer(std::size_t size)
   {
-    mBuffer.Resize( size );
+    mBuffer.Resize(size);
   }
 
   /**
    * Get the program buffer
    * @return reference to the buffer
    */
-  size_t GetBufferSize() const
+  std::size_t GetBufferSize() const
   {
     return mBuffer.Size();
   }
@@ -141,9 +192,9 @@ public: // API
    * Get the data that the buffer points to
    * @return raw pointer to the buffer data
    */
-  unsigned char* GetBufferData()
+  uint8_t* GetBufferData()
   {
-    DALI_ASSERT_DEBUG( mBuffer.Size() > 0 );
+    DALI_ASSERT_DEBUG(mBuffer.Size() > 0);
     return &mBuffer[0];
   }
 
@@ -151,27 +202,35 @@ public: // API
    * Get the data that the buffer points to
    * @return raw pointer to the buffer data
    */
-  Dali::Vector<unsigned char>& GetBuffer()
+  Dali::Vector<uint8_t>& GetBuffer()
   {
     return mBuffer;
   }
 
-private: // Not implemented
-
-  ShaderData(const ShaderData& other);            ///< no copying of this object
-  ShaderData& operator= (const ShaderData& rhs);  ///< no copying of this object
-
-private: // Data
+  /**
+   * Get the source mode of shader data
+   * @return the source mode of shader data ( text or binary )
+   */
+  Graphics::ShaderSourceMode GetSourceMode() const
+  {
+    return mSourceMode;
+  }
 
-  size_t                      mShaderHash;     ///< hash key created with vertex and fragment shader code
-  std::string                 mVertexShader;   ///< source code for vertex program
-  std::string                 mFragmentShader; ///< source code for fragment program
-  Dali::Shader::ShaderHints   mHints;    ///< take a hint
-  Dali::Vector<unsigned char> mBuffer;         ///< buffer containing compiled binary bytecode
+private:                                        // Not implemented
+  ShaderData(const ShaderData& other);          ///< no copying of this object
+  ShaderData& operator=(const ShaderData& rhs); ///< no copying of this object
+
+private:                                      // Data
+  std::size_t                mShaderHash;     ///< hash key created with vertex and fragment shader code
+  std::vector<char>          mVertexShader;   ///< source code for vertex program
+  std::vector<char>          mFragmentShader; ///< source code for fragment program
+  Dali::Shader::Hint::Value  mHints;          ///< take a hint
+  Dali::Vector<uint8_t>      mBuffer;         ///< buffer containing compiled binary bytecode
+  Graphics::ShaderSourceMode mSourceMode;     ///< Source mode of shader data ( text or binary )
 };
 
-} // namespace Integration
+} // namespace Internal
 
 } // namespace Dali
 
-#endif // __DALI_INTERNAL_SHADER_DATA_H__
+#endif // DALI_INTERNAL_SHADER_DATA_H