Merge "Added shader support to pipeline cache" into devel/master
[platform/core/uifw/dali-adaptor.git] / dali / internal / graphics / gles-impl / gles-graphics-shader.h
index d96223f..28c7370 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_GRAPHICS_GLES_SHADER_H
 
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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.
@@ -27,9 +27,7 @@
 
 namespace Dali::Graphics::GLES
 {
-using ShaderResource = Resource<Graphics::Shader, Graphics::ShaderCreateInfo>;
-
-class Shader : public ShaderResource
+class ShaderImpl
 {
 public:
   /**
@@ -37,51 +35,112 @@ public:
    * @param[in] createInfo Valid createInfo structure
    * @param[in] controller Reference to the controller
    */
-  Shader(const Graphics::ShaderCreateInfo& createInfo, Graphics::EglGraphicsController& controller);
+  ShaderImpl(const Graphics::ShaderCreateInfo& createInfo, Graphics::EglGraphicsController& controller);
+  ~ShaderImpl();
+
+  uint32_t Retain();
+
+  uint32_t Release();
+
+  [[nodiscard]] uint32_t GetRefCount() const;
 
   /**
-   * @brief Destructor
+   * Whilst unreferenced, increase the flush count and return it
+   *
+   * @return The new flush count
    */
-  ~Shader() override = default;
+  [[nodiscard]] uint32_t IncreaseFlushCount();
 
   /**
-   * @brief Called when GL resources are destroyed
+   * Get the flush count whilst unreferenced
+   *
+   * @return the flush count
    */
-  void DestroyResource() override
-  {
-    // TODO: Implement destroying the resource
-  }
+  [[nodiscard]] uint32_t GetFlushCount() const;
 
   /**
-   * @brief Called when initializing the resource
+   * @brief Compiles shader
    *
    * @return True on success
    */
-  bool InitializeResource() override
+  [[nodiscard]] bool Compile() const;
+
+  /**
+   * @brief Destroys GL shader
+   */
+  void Destroy();
+
+  uint32_t GetGLShader() const;
+
+  [[nodiscard]] const ShaderCreateInfo& GetCreateInfo() const;
+
+  [[nodiscard]] EglGraphicsController& GetController() const;
+
+private:
+  friend class Shader;
+  struct Impl;
+  std::unique_ptr<Impl> mImpl{nullptr};
+};
+
+class Shader : public Graphics::Shader
+{
+public:
+  /**
+   * @brief Constructor
+   *
+   * @param[in] impl Pointer to valid implementation
+   */
+  explicit Shader(ShaderImpl* impl)
+  : mShader(impl)
   {
-    // TODO: Implement initializing resource
-    return {};
+    mShader->Retain();
   }
 
   /**
-   * @brief Compiles shader
-   * @return
+   * @brief Destructor
    */
-  bool Compile() const;
+  ~Shader() override;
+
+  [[nodiscard]] ShaderImpl* GetImplementation() const
+  {
+    return mShader;
+  }
+
+  [[nodiscard]] const ShaderCreateInfo& GetCreateInfo() const;
+
+  bool operator==(const GLES::Shader& shader) const
+  {
+    return (shader.mShader == mShader);
+  }
+
+  bool operator==(const GLES::ShaderImpl* shaderImpl) const
+  {
+    return (shaderImpl == mShader);
+  }
+
+  bool operator!=(const GLES::Shader& shader) const
+  {
+    return (shader.mShader != mShader);
+  }
+
+  /**
+   * @brief Called when UniquePtr<> on client-side dies.
+   */
+  void DiscardResource();
 
   /**
-   * @brief Called when UniquePtr<> on client-side dies
+   * @brief Destroying GL resources
+   *
+   * This function is kept for compatibility with Resource<> class
+   * so can the object can be use with templated functions.
    */
-  void DiscardResource() override
+  void DestroyResource()
   {
-    // TODO: Implement moving to the discard queue
+    // nothing to do here
   }
 
-  uint32_t GetGLShader() const;
-
 private:
-  struct Impl;
-  std::unique_ptr<Impl> mImpl;
+  ShaderImpl* mShader{nullptr};
 };
 
 } // namespace Dali::Graphics::GLES