#include <string.h>
// INTERNAL INCLUDES
+#include "gles-graphics-reflection.h"
#include "gles-graphics-resource.h"
namespace Dali::Graphics::GLES
{
-using PipelineResource = Resource<Graphics::Pipeline, Graphics::PipelineCreateInfo>;
+class PipelineCache;
+class Program;
/**
- * @brief PipelineWrapper is the object
- * returned to the client-side
+ * @brief PipelineImpl is the implementation of Pipeline
+ *
+ * PipelineImpl is owned by the pipeline cache. The client-side
+ * will receive Graphics::Pipeline objects which are only
+ * wrappers for this implementation. The lifecycle of
+ * PipelineImpl is managed by the PipelineCache.
*/
class PipelineImpl
{
* @brief Constructor
* @param[in] createInfo valid TextureCreateInfo structure
* @param[in] controller Reference to the Controller
+ * @param[in] pipelineCache Reference to valid pipeline cache
*/
- PipelineImpl(const Graphics::PipelineCreateInfo& createInfo, Graphics::EglGraphicsController& controller);
+ PipelineImpl(const Graphics::PipelineCreateInfo& createInfo, Graphics::EglGraphicsController& controller, PipelineCache& pipelineCache);
/**
* @brief Destructor
~PipelineImpl();
/**
- * @brief Destroys all the low-level resources used by the class
+ * @brief Binds pipeline
+ *
+ * Binds Pipeline by binding GL program and flushing state.
+ *
+ * @param[in] glProgram The GL program to be bound
*/
- void DestroyResource();
+ void Bind(const uint32_t glProgram) const;
/**
- * @brief Initializes low-level resources
- *
- * @return Tron success
+ * @brief Increases ref count
*/
- bool InitializeResource();
+ void Retain();
/**
- * @brief Discards object
+ * @brief Decreases ref count
*/
- void DiscardResource();
+ void Release();
/**
- * @brief returns GL program id
- * @return GL program id
+ * @brief Retrieves ref count
+ * @return Refcount value
*/
- [[nodiscard]] uint32_t GetGLProgram() const;
+ [[nodiscard]] uint32_t GetRefCount() const;
/**
- * @brief Binds pipeline
- *
- * Binds Pipeline by binding GL program and flushing state.
- *
- * If previous pipeline specified, it will be used in order to
- * avoid redundant state swiches.
+ * @brief Returns PipelineCreateInfo structure
*
- * @param[in] prevPipeline previous pipeline
+ * @return PipelineCreateInfo structure
*/
- void Bind(GLES::PipelineImpl* prevPipeline);
+ [[nodiscard]] const PipelineCreateInfo& GetCreateInfo() const;
/**
- * Executes state change function if condition met
+ * @brief Returns controller
+ *
+ * @return Reference to the Controller
*/
- template<typename FUNC, typename STATE>
- void ExecuteStateChange(FUNC& func, const STATE* prevPipelineState, const STATE* thisPipelineState)
- {
- if(!prevPipelineState)
- {
- func();
- }
- else
- {
- // binary test and execute when different
- if(memcmp(prevPipelineState, thisPipelineState, sizeof(STATE)) != 0)
- {
- func();
- }
- }
- }
-
- void Retain();
-
- void Release();
-
- [[nodiscard]] uint32_t GetRefCount() const;
-
- [[nodiscard]] const PipelineCreateInfo& GetCreateInfo() const;
-
[[nodiscard]] auto& GetController() const;
private:
}
}
- // Pipeline state is stored as a copy of create info
- // data.
+ // Pipeline state is store locally so any assigned pointers on a
+ // client-side may go safely out of scope.
struct PipelineState;
std::unique_ptr<PipelineState> mPipelineState;
EglGraphicsController& mController;
PipelineCreateInfo mCreateInfo;
- uint32_t mGlProgram{0u};
-
uint32_t mRefCount{0u};
};
/**
- * @brief Pipeline class wraps a unique pipeline object
- *
+ * @brief Pipeline class wraps the PipelineImpl
*/
class Pipeline : public Graphics::Pipeline
{
public:
Pipeline() = delete;
+ /**
+ * @brief Constructor
+ * @param pipeline Pipeline implementation
+ */
explicit Pipeline(GLES::PipelineImpl& pipeline)
: mPipeline(pipeline)
{
mPipeline.Retain();
}
- ~Pipeline() override
- {
- // decrease refcount
- mPipeline.Release();
- }
+ /**
+ * @brief Destructor
+ */
+ ~Pipeline() override;
+ /**
+ * @brief Returns pipeline implementation
+ *
+ * @return Valid pipeline implementation
+ */
[[nodiscard]] auto& GetPipeline() const
{
return mPipeline;
}
+ /**
+ * @brief Returns create info structure
+ *
+ * @return Valid create info structure
+ */
[[nodiscard]] const PipelineCreateInfo& GetCreateInfo() const;
+ /**
+ * @brief Returns controller
+ *
+ * @return reference to Controller
+ */
[[nodiscard]] EglGraphicsController& GetController() const;
+ bool operator==(const PipelineImpl* impl) const
+ {
+ return &mPipeline == impl;
+ }
+
+ /**
+ * @brief Run by UniquePtr to discard resource
+ */
+ void DiscardResource();
+
+ /**
+ * @brief Destroy resource
+ *
+ * Despite this class doesn't inherit Resource it must provide
+ * (so it won't duplicate same data) same set of functions
+ * so it can work with resource management functions of Controller.
+ */
+ void DestroyResource()
+ {
+ // Nothing to do here
+ }
+
private:
GLES::PipelineImpl& mPipeline;
};