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-memory.h"
28 #include "gles-graphics-pipeline-cache.h"
29 #include "gles-graphics-texture.h"
36 class GlSyncAbstraction;
37 class GlContextHelperAbstraction;
38 } // namespace Integration
49 * EGL Implementation of the graphics controller.
51 * Temporarily holds the old GL abstractions whilst dali-core is migrated to the new API.
53 DALI_IMPORT_API class EglGraphicsController : public Graphics::Controller
57 * @brief Deault constructor
59 EglGraphicsController() = default;
64 ~EglGraphicsController() override = default;
67 * Initialize the GLES abstraction. This can be called from the main thread.
69 void InitializeGLES(Integration::GlAbstraction& glAbstraction);
72 * Initialize with a reference to the GL abstractions.
74 * Note, this is now executed in the render thread, after core initialization
76 void Initialize(Integration::GlSyncAbstraction& glSyncAbstraction,
77 Integration::GlContextHelperAbstraction& glContextHelperAbstraction);
79 Integration::GlAbstraction& GetGlAbstraction() override;
80 Integration::GlSyncAbstraction& GetGlSyncAbstraction() override;
81 Integration::GlContextHelperAbstraction& GetGlContextHelperAbstraction() override;
84 * @copydoc Dali::Graphics::SubmitCommandBuffers()
86 void SubmitCommandBuffers(const SubmitInfo& submitInfo) override;
89 * @copydoc Dali::Graphics::PresentRenderTarget()
91 void PresentRenderTarget(RenderTarget* renderTarget) override
96 * @copydoc Dali::Graphics::WaitIdle()
98 void WaitIdle() override
103 * @copydoc Dali::Graphics::Pause()
105 void Pause() override
110 * @copydoc Dali::Graphics::Resume()
112 void Resume() override
117 * @copydoc Dali::Graphics::UpdateTextures()
119 void UpdateTextures(const std::vector<TextureUpdateInfo>& updateInfoList,
120 const std::vector<TextureUpdateSourceInfo>& sourceList) override;
123 * @copydoc Dali::Graphics::EnableDepthStencilBuffer()
125 bool EnableDepthStencilBuffer(bool enableDepth, bool enableStencil) override
131 * @copydoc Dali::Graphics::RunGarbageCollector()
133 void RunGarbageCollector(size_t numberOfDiscardedRenderers) override
138 * @copydoc Dali::Graphics::DiscardUnusedResources()
140 void DiscardUnusedResources() override
145 * @copydoc Dali::Graphics::IsDiscardQueueEmpty()
147 bool IsDiscardQueueEmpty() override
153 * @copydoc Dali::Graphics::IsDrawOnResumeRequired()
155 bool IsDrawOnResumeRequired() override
161 * @copydoc Dali::Graphics::CreateBuffer()
163 Graphics::UniquePtr<Buffer> CreateBuffer(const BufferCreateInfo& bufferCreateInfo, Graphics::UniquePtr<Buffer>&& oldBuffer) override;
166 * @copydoc Dali::Graphics::CreateCommandBuffer()
168 Graphics::UniquePtr<CommandBuffer> CreateCommandBuffer(const CommandBufferCreateInfo& commandBufferCreateInfo, Graphics::UniquePtr<CommandBuffer>&& oldCommandBuffer) override;
171 * @copydoc Dali::Graphics::CreateRenderPass()
173 Graphics::UniquePtr<RenderPass> CreateRenderPass(const RenderPassCreateInfo& renderPassCreateInfo, Graphics::UniquePtr<RenderPass>&& oldRenderPass) override
179 * @copydoc Dali::Graphics::CreateTexture()
181 Graphics::UniquePtr<Texture> CreateTexture(const TextureCreateInfo& textureCreateInfo, Graphics::UniquePtr<Texture>&& oldTexture) override;
184 * @copydoc Dali::Graphics::CreateFramebuffer()
186 Graphics::UniquePtr<Framebuffer> CreateFramebuffer(const FramebufferCreateInfo& framebufferCreateInfo, Graphics::UniquePtr<Framebuffer>&& oldFramebuffer) override
192 * @copydoc Dali::Graphics::CreatePipeline()
194 Graphics::UniquePtr<Pipeline> CreatePipeline(const PipelineCreateInfo& pipelineCreateInfo, Graphics::UniquePtr<Pipeline>&& oldPipeline) override;
197 * @copydoc Dali::Graphics::CreateShader()
199 Graphics::UniquePtr<Shader> CreateShader(const ShaderCreateInfo& shaderCreateInfo, Graphics::UniquePtr<Shader>&& oldShader) override
205 * @copydoc Dali::Graphics::CreateSampler()
207 Graphics::UniquePtr<Sampler> CreateSampler(const SamplerCreateInfo& samplerCreateInfo, Graphics::UniquePtr<Sampler>&& oldSampler) override
213 * @copydoc Dali::Graphics::CreateRenderTarget()
215 Graphics::UniquePtr<RenderTarget> CreateRenderTarget(const RenderTargetCreateInfo& renderTargetCreateInfo, Graphics::UniquePtr<RenderTarget>&& oldRenderTarget) override
221 * @copydoc Dali::Graphics::MapBufferRange()
223 Graphics::UniquePtr<Memory> MapBufferRange(const MapBufferInfo& mapInfo) override;
226 * @copydoc Dali::Graphics::MapTextureRange()
228 Graphics::UniquePtr<Memory> MapTextureRange(const MapTextureInfo& mapInfo) override
234 * @copydoc Dali::Graphics::UnmapMemory()
236 void UnmapMemory(Graphics::UniquePtr<Memory> memory) override
240 * @copydoc Dali::Graphics::GetTextureMemoryRequirements()
242 MemoryRequirements GetTextureMemoryRequirements(Texture& texture) const override
248 * @copydoc Dali::Graphics::GetBufferMemoryRequirements()
250 MemoryRequirements GetBufferMemoryRequirements(Buffer& buffer) const override
256 * @copydoc Dali::Graphics::GetTextureProperties()
258 const TextureProperties& GetTextureProperties(const Texture& texture) override
260 // for compiler not to moan
261 static TextureProperties dummy{};
266 * @copydoc Dali::Graphics::PipelineEquals()
268 [[nodiscard]] bool PipelineEquals(const Pipeline& pipeline0, const Pipeline& pipeline1) const override
273 [[nodiscard]] Integration::GlAbstraction* GetGL() const
275 return mGlAbstraction;
279 void AddTexture(GLES::Texture& texture);
282 * @brief Adds buffer to the creation queue
285 void AddBuffer(GLES::Buffer& buffer);
288 * @brief Pushes Bufer to the discard queue
290 * Function is called from the UniquePtr custom deleter.
292 * @param[in] texture Pointer to the texture
294 void DiscardResource(GLES::Texture* texture)
296 mDiscardTextureQueue.push(texture);
300 * @brief Pushes Buffer to the discard queue
302 * Function is called from the UniquePtr custom deleter.
304 * @param[in] texture Pointer to the texture
306 void DiscardResource(GLES::Buffer* texture)
308 mDiscardBufferQueue.push(texture);
312 * @brief Flushes all pending updates
314 * Function flushes all pending resource constructions,
315 * executes command buffers and empties discard queues.
320 ProcessCreateQueues();
323 ProcessTextureUpdateQueue();
326 ProcessDiscardQueues();
328 // Process main command queue
329 ProcessCommandQueues();
332 // Test update to tick controller, usually it will run own thread
333 void ProcessDiscardQueues();
336 * @brief Processes a create queue for type specified
338 * @param[in,out] queue Reference to the create queue
341 void ProcessCreateQueue(T& queue)
343 while(!queue.empty())
345 auto* object = queue.front();
348 // Initialize texture
349 if(!object->InitializeResource())
351 // TODO: handle error
357 * @brief Processes a create queue for type specified
359 * @param[in,out] queue Reference to the create queue
361 template<class U, class T>
362 void ProcessDiscardQueue(T& queue)
364 while(!queue.empty())
366 auto* object = queue.front();
369 object->DestroyResource();
372 auto* clbk = object->GetCreateInfo().allocationCallbacks;
379 clbk->freeCallback(object, clbk->userData);
390 * @brief Processes all resource create queues
392 void ProcessCreateQueues();
395 * @brief Process command queues and buffers
397 void ProcessCommandQueues();
400 * @brief Executes all pending texture updates
402 void ProcessTextureUpdateQueue();
405 Integration::GlAbstraction* mGlAbstraction{nullptr};
406 Integration::GlSyncAbstraction* mGlSyncAbstraction{nullptr};
407 Integration::GlContextHelperAbstraction* mGlContextHelperAbstraction{nullptr};
409 std::queue<GLES::Texture*> mCreateTextureQueue; ///< Create queue for texture resource
410 std::queue<GLES::Texture*> mDiscardTextureQueue; ///< Discard queue for texture resource
412 std::queue<GLES::Buffer*> mCreateBufferQueue; ///< Create queue for buffer resource
413 std::queue<GLES::Buffer*> mDiscardBufferQueue; ///< Discard queue for buffer resource
415 std::queue<GLES::CommandBuffer*> mCommandQueue; ///< we may have more in the future
417 using TextureUpdateRequest = std::pair<TextureUpdateInfo, TextureUpdateSourceInfo>;
418 std::queue<TextureUpdateRequest> mTextureUpdateRequests;
420 std::unique_ptr<GLES::Context> mContext{nullptr}; ///< Context object handling command buffers execution
422 std::unique_ptr<GLES::PipelineCache> mPipelineCache{nullptr}; ///< Internal pipeline cache
425 } // namespace Graphics
429 #endif //DALI_EGL_GRAPHICS_CONTROLLER_H