1 #ifndef DALI_EGL_GRAPHICS_CONTROLLER_H
2 #define DALI_EGL_GRAPHICS_CONTROLLER_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.
21 #include <dali/graphics-api/graphics-controller.h>
25 #include "gles-context.h"
26 #include "gles-graphics-buffer.h"
27 #include "gles-graphics-pipeline-cache.h"
28 #include "gles-graphics-pipeline.h"
29 #include "gles-graphics-reflection.h"
30 #include "gles-graphics-sampler.h"
31 #include "gles-graphics-texture.h"
32 #include "gles-graphics-types.h"
33 #include "gles2-graphics-memory.h"
40 class GlSyncAbstraction;
41 class GlContextHelperAbstraction;
42 } // namespace Integration
53 * EGL Implementation of the graphics controller.
55 * Temporarily holds the old GL abstractions whilst dali-core is migrated to the new API.
57 DALI_IMPORT_API class EglGraphicsController : public Graphics::Controller
61 * @brief Deault constructor
63 EglGraphicsController() = default;
68 ~EglGraphicsController() override = default;
71 * Initialize the GLES abstraction. This can be called from the main thread.
73 void InitializeGLES(Integration::GlAbstraction& glAbstraction);
76 * Initialize with a reference to the GL abstractions.
78 * Note, this is now executed in the render thread, after core initialization
80 void Initialize(Integration::GlSyncAbstraction& glSyncAbstraction,
81 Integration::GlContextHelperAbstraction& glContextHelperAbstraction);
83 Integration::GlAbstraction& GetGlAbstraction() override;
84 Integration::GlSyncAbstraction& GetGlSyncAbstraction() override;
85 Integration::GlContextHelperAbstraction& GetGlContextHelperAbstraction() override;
88 * @copydoc Dali::Graphics::SubmitCommandBuffers()
90 void SubmitCommandBuffers(const SubmitInfo& submitInfo) override;
93 * @copydoc Dali::Graphics::PresentRenderTarget()
95 void PresentRenderTarget(RenderTarget* renderTarget) override
100 * @copydoc Dali::Graphics::WaitIdle()
102 void WaitIdle() override
107 * @copydoc Dali::Graphics::Pause()
109 void Pause() override
114 * @copydoc Dali::Graphics::Resume()
116 void Resume() override
121 * @copydoc Dali::Graphics::UpdateTextures()
123 void UpdateTextures(const std::vector<TextureUpdateInfo>& updateInfoList,
124 const std::vector<TextureUpdateSourceInfo>& sourceList) override;
127 * @copydoc Dali::Graphics::EnableDepthStencilBuffer()
129 bool EnableDepthStencilBuffer(bool enableDepth, bool enableStencil) override
135 * @copydoc Dali::Graphics::RunGarbageCollector()
137 void RunGarbageCollector(size_t numberOfDiscardedRenderers) override
142 * @copydoc Dali::Graphics::DiscardUnusedResources()
144 void DiscardUnusedResources() override
149 * @copydoc Dali::Graphics::IsDiscardQueueEmpty()
151 bool IsDiscardQueueEmpty() override
157 * @copydoc Dali::Graphics::IsDrawOnResumeRequired()
159 bool IsDrawOnResumeRequired() override
165 * @copydoc Dali::Graphics::CreateBuffer()
167 Graphics::UniquePtr<Buffer> CreateBuffer(const BufferCreateInfo& bufferCreateInfo, Graphics::UniquePtr<Buffer>&& oldBuffer) override;
170 * @copydoc Dali::Graphics::CreateCommandBuffer()
172 Graphics::UniquePtr<CommandBuffer> CreateCommandBuffer(const CommandBufferCreateInfo& commandBufferCreateInfo, Graphics::UniquePtr<CommandBuffer>&& oldCommandBuffer) override;
175 * @copydoc Dali::Graphics::CreateRenderPass()
177 Graphics::UniquePtr<RenderPass> CreateRenderPass(const RenderPassCreateInfo& renderPassCreateInfo, Graphics::UniquePtr<RenderPass>&& oldRenderPass) override
183 * @copydoc Dali::Graphics::CreateTexture()
185 Graphics::UniquePtr<Texture> CreateTexture(const TextureCreateInfo& textureCreateInfo, Graphics::UniquePtr<Texture>&& oldTexture) override;
188 * @copydoc Dali::Graphics::CreateFramebuffer()
190 Graphics::UniquePtr<Framebuffer> CreateFramebuffer(const FramebufferCreateInfo& framebufferCreateInfo, Graphics::UniquePtr<Framebuffer>&& oldFramebuffer) override
196 * @copydoc Dali::Graphics::CreatePipeline()
198 Graphics::UniquePtr<Pipeline> CreatePipeline(const PipelineCreateInfo& pipelineCreateInfo, Graphics::UniquePtr<Pipeline>&& oldPipeline) override;
201 * @copydoc Dali::Graphics::CreateProgram()
203 Graphics::UniquePtr<Program> CreateProgram(const ProgramCreateInfo& programCreateInfo, UniquePtr<Program>&& oldProgram) override;
206 * @copydoc Dali::Graphics::CreateShader()
208 Graphics::UniquePtr<Shader> CreateShader(const ShaderCreateInfo& shaderCreateInfo, Graphics::UniquePtr<Shader>&& oldShader) override;
211 * @copydoc Dali::Graphics::CreateSampler()
213 Graphics::UniquePtr<Sampler> CreateSampler(const SamplerCreateInfo& samplerCreateInfo, Graphics::UniquePtr<Sampler>&& oldSampler) override;
216 * @copydoc Dali::Graphics::CreateRenderTarget()
218 Graphics::UniquePtr<RenderTarget> CreateRenderTarget(const RenderTargetCreateInfo& renderTargetCreateInfo, Graphics::UniquePtr<RenderTarget>&& oldRenderTarget) override
224 * @copydoc Dali::Graphics::MapBufferRange()
226 Graphics::UniquePtr<Memory> MapBufferRange(const MapBufferInfo& mapInfo) override;
229 * @copydoc Dali::Graphics::MapTextureRange()
231 Graphics::UniquePtr<Memory> MapTextureRange(const MapTextureInfo& mapInfo) override
237 * @copydoc Dali::Graphics::UnmapMemory()
239 void UnmapMemory(Graphics::UniquePtr<Memory> memory) override
243 * @copydoc Dali::Graphics::GetTextureMemoryRequirements()
245 MemoryRequirements GetTextureMemoryRequirements(Texture& texture) const override
251 * @copydoc Dali::Graphics::GetBufferMemoryRequirements()
253 MemoryRequirements GetBufferMemoryRequirements(Buffer& buffer) const override
259 * @copydoc Dali::Graphics::GetTextureProperties()
261 const TextureProperties& GetTextureProperties(const Texture& texture) override
263 // for compiler not to moan
264 static TextureProperties dummy{};
269 * @copydoc Dali::Graphics::Controller::GetPipelineReflection()
272 [[nodiscard]] const Reflection& GetProgramReflection(const Graphics::Program& program) override;
275 * @copydoc Dali::Graphics::PipelineEquals()
277 [[nodiscard]] bool PipelineEquals(const Pipeline& pipeline0, const Pipeline& pipeline1) const override
282 [[nodiscard]] Integration::GlAbstraction* GetGL() const
284 return mGlAbstraction;
288 void AddTexture(GLES::Texture& texture);
291 * @brief Adds buffer to the creation queue
294 void AddBuffer(GLES::Buffer& buffer);
297 * @brief Pushes Bufer to the discard queue
299 * Function is called from the UniquePtr custom deleter.
301 * @param[in] texture Pointer to the texture
303 void DiscardResource(GLES::Texture* texture)
305 mDiscardTextureQueue.push(texture);
309 * @brief Pushes Buffer to the discard queue
311 * Function is called from the UniquePtr custom deleter.
313 * @param[in] texture Pointer to the texture
315 void DiscardResource(GLES::Buffer* texture)
317 mDiscardBufferQueue.push(texture);
321 * @brief Pushes Program to the discard queue
323 * Function is called from the UniquePtr custom deleter.
325 * @param[in] program Pointer to the program
327 void DiscardResource(GLES::Program* program)
329 mDiscardProgramQueue.push(program);
333 * @brief Pushes Pipeline to the discard queue
335 * Function is called from the UniquePtr custom deleter.
337 * @param[in] program Pointer to the pipeline
339 void DiscardResource(GLES::Pipeline* pipeline)
341 mDiscardPipelineQueue.push(pipeline);
345 * @brief Flushes all pending updates
347 * Function flushes all pending resource constructions,
348 * executes command buffers and empties discard queues.
353 ProcessCreateQueues();
356 ProcessTextureUpdateQueue();
358 // Process main command queue
359 ProcessCommandQueues();
362 ProcessDiscardQueues();
364 // Flush pipeline cache to remove unused pipelines
367 mPipelineCache->FlushCache();
371 // Test update to tick controller, usually it will run own thread
372 void ProcessDiscardQueues();
375 * @brief Processes a create queue for type specified
377 * @param[in,out] queue Reference to the create queue
380 void ProcessCreateQueue(T& queue)
382 while(!queue.empty())
384 auto* object = queue.front();
387 // Initialize texture
388 if(!object->InitializeResource())
390 // TODO: handle error
396 * @brief Processes a create queue for type specified
398 * @param[in,out] queue Reference to the create queue
400 template<class U, class T>
401 void ProcessDiscardQueue(T& queue)
403 while(!queue.empty())
405 auto* object = queue.front();
408 object->DestroyResource();
411 auto* clbk = object->GetCreateInfo().allocationCallbacks;
418 clbk->freeCallback(object, clbk->userData);
429 * @brief Processes all resource create queues
431 void ProcessCreateQueues();
434 * @brief Process command queues and buffers
436 void ProcessCommandQueues();
439 * @brief Executes all pending texture updates
441 void ProcessTextureUpdateQueue();
444 * @brief Returns program custom parameter
446 * This function can be used as a backdoor in order to retrieve
447 * certain data out of implementation
449 * @param[in] program Valid Program object
450 * @param parameterId Integer id of parameter
451 * @param outData Output data
452 * @return True if parameter retrieved
454 bool GetProgramParameter(Graphics::Program& program, uint32_t parameterId, void* outData) override;
457 * @brief Returns pipeline cache object
459 * @return Valid pipeline cache object
461 [[nodiscard]] GLES::PipelineCache& GetPipelineCache() const;
464 * @brief Returns runtime supported GLES version
466 * @return GLES version enum
468 GLES::GLESVersion GetGLESVersion() const
470 // TODO: return proper version but for now we can
472 return GLES::GLESVersion::GLES_20;
476 Integration::GlAbstraction* mGlAbstraction{nullptr};
477 Integration::GlSyncAbstraction* mGlSyncAbstraction{nullptr};
478 Integration::GlContextHelperAbstraction* mGlContextHelperAbstraction{nullptr};
480 std::queue<GLES::Texture*> mCreateTextureQueue; ///< Create queue for texture resource
481 std::queue<GLES::Texture*> mDiscardTextureQueue; ///< Discard queue for texture resource
483 std::queue<GLES::Buffer*> mCreateBufferQueue; ///< Create queue for buffer resource
484 std::queue<GLES::Buffer*> mDiscardBufferQueue; ///< Discard queue for buffer resource
486 std::queue<GLES::Program*> mDiscardProgramQueue; ///< Discard queue for program resource
488 std::queue<GLES::Pipeline*> mDiscardPipelineQueue; ///< Discard queue of pipelines
490 std::queue<GLES::CommandBuffer*> mCommandQueue; ///< we may have more in the future
492 using TextureUpdateRequest = std::pair<TextureUpdateInfo, TextureUpdateSourceInfo>;
493 std::queue<TextureUpdateRequest> mTextureUpdateRequests;
495 std::unique_ptr<GLES::Context> mContext{nullptr}; ///< Context object handling command buffers execution
497 std::unique_ptr<GLES::PipelineCache> mPipelineCache{nullptr}; ///< Internal pipeline cache
500 } // namespace Graphics
504 #endif //DALI_EGL_GRAPHICS_CONTROLLER_H