1 #ifndef DALI_GRAPHICS_GLES_PIPELINE_H
2 #define DALI_GRAPHICS_GLES_PIPELINE_H
5 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/graphics-api/graphics-pipeline-create-info.h>
23 #include <dali/graphics-api/graphics-pipeline.h>
27 #include "gles-graphics-reflection.h"
28 #include "gles-graphics-resource.h"
30 namespace Dali::Graphics::GLES
35 * @brief PipelineImpl is the implementation of Pipeline
37 * PipelineImpl is owned by the pipeline cache. The client-side
38 * will receive Graphics::Pipeline objects which are only
39 * wrappers for this implementation. The lifecycle of
40 * PipelineImpl is managed by the PipelineCache.
47 * @param[in] createInfo valid TextureCreateInfo structure
48 * @param[in] controller Reference to the Controller
49 * @param[in] pipelineCache Reference to valid pipeline cache
51 PipelineImpl(const Graphics::PipelineCreateInfo& createInfo, Graphics::EglGraphicsController& controller, PipelineCache& pipelineCache);
59 * @brief Binds pipeline
61 * Binds Pipeline by binding GL program and flushing state.
63 * If previous pipeline specified, it will be used in order to
64 * avoid redundant state swiches.
66 * @param[in] prevPipeline previous pipeline
68 void Bind(GLES::PipelineImpl* prevPipeline);
71 * @brief Increases ref count
76 * @brief Decreases ref count
81 * @brief Retrieves ref count
82 * @return Refcount value
84 [[nodiscard]] uint32_t GetRefCount() const;
87 * @brief Returns PipelineCreateInfo structure
89 * @return PipelineCreateInfo structure
91 [[nodiscard]] const PipelineCreateInfo& GetCreateInfo() const;
94 * @brief Returns controller
96 * @return Reference to the Controller
98 [[nodiscard]] auto& GetController() const;
102 * @brief Helper function. Copies state if pointer is set
105 void CopyStateIfSet(const T* sourceState, T& copyState, T** destState)
107 *destState = nullptr;
110 copyState = *sourceState;
111 *destState = ©State;
116 * @brief Helper function. Copies const state if pointer is set
119 void CopyStateIfSet(const T* sourceState, T& copyState, const T** destState)
121 *destState = nullptr;
124 copyState = *sourceState;
125 *destState = ©State;
129 // Pipeline state is store locally so any assigned pointers on a
130 // client-side may go safely out of scope.
131 struct PipelineState;
132 std::unique_ptr<PipelineState> mPipelineState;
134 EglGraphicsController& mController;
135 PipelineCreateInfo mCreateInfo;
137 uint32_t mRefCount{0u};
141 * @brief Pipeline class wraps the PipelineImpl
143 class Pipeline : public Graphics::Pipeline
150 * @param pipeline Pipeline implementation
152 explicit Pipeline(GLES::PipelineImpl& pipeline)
153 : mPipeline(pipeline)
162 ~Pipeline() override;
165 * @brief Returns pipeline implementation
167 * @return Valid pipeline implementation
169 [[nodiscard]] auto& GetPipeline() const
175 * @brief Returns create info structure
177 * @return Valid create info structure
179 [[nodiscard]] const PipelineCreateInfo& GetCreateInfo() const;
182 * @brief Returns controller
184 * @return reference to Controller
186 [[nodiscard]] EglGraphicsController& GetController() const;
188 bool operator==(const PipelineImpl* impl) const
190 return &mPipeline == impl;
194 * @brief Run by UniquePtr to discard resource
196 void DiscardResource();
199 * @brief Destroy resource
201 * Despite this class doesn't inherit Resource it must provide
202 * (so it won't duplicate same data) same set of functions
203 * so it can work with resource management functions of Controller.
205 void DestroyResource()
207 // Nothing to do here
211 GLES::PipelineImpl& mPipeline;
214 } // namespace Dali::Graphics::GLES