Cleaned up some of the circular dependency between GLES::Context & GLES::GraphicsCont...
[platform/core/uifw/dali-adaptor.git] / dali / internal / graphics / gles-impl / gles-context.h
index c9df90f..f4cde6d 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_GRAPHICS_GLES_CONTEXT_H
 
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 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.
@@ -19,6 +19,7 @@
  */
 
 #include <dali/graphics-api/graphics-command-buffer.h>
+#include "gles-context-state-cache.h"
 #include "gles-graphics-types.h"
 
 namespace Dali::Graphics
@@ -29,13 +30,16 @@ namespace GLES
 class Pipeline;
 class RenderPass;
 class RenderTarget;
+class Texture;
+class TextureDependencyChecker;
+
 /**
  * @brief Context represents single GLES context
  */
 class Context
 {
 public:
-  explicit Context(EglGraphicsController& controller);
+  explicit Context(EglGraphicsController& controller, Integration::GlAbstraction* glAbstraction);
 
   ~Context();
 
@@ -43,11 +47,14 @@ public:
    * @brief Flushes the context
    *
    * Flushes the context by issuing GL calls to set the required
-   * state.
+   * state. Causes a glWaitSync if any drawn textures are dependent
+   * on another context.
    *
    * @param[in] reset If true then state is reset unconditionally
+   * @param[in] drawCall the draws that need flushing
+   * @param[in] dependencyChecker The texture dependecy checker
    */
-  void Flush(bool reset, const GLES::DrawCallDescriptor& drawCall);
+  void Flush(bool reset, const GLES::DrawCallDescriptor& drawCall, GLES::TextureDependencyChecker& dependencyChecker);
 
   /**
    * @brief Returns context Id
@@ -69,7 +76,7 @@ public:
    * @param[in] bindings List of bindings
    *
    */
-  void BindTextures(const std::vector<Graphics::TextureBinding>& bindings);
+  void BindTextures(const Graphics::TextureBinding* bindings, uint32_t count);
 
   /**
    * @brief Vertex buffers to bind
@@ -78,7 +85,7 @@ public:
    * currently processed and copied into the local storage.
    */
 
-  void BindVertexBuffers(const std::vector<GLES::VertexBufferBindingDescriptor>& bindings);
+  void BindVertexBuffers(const GLES::VertexBufferBindingDescriptor* bindings, uint32_t count);
 
   /**
    * @brief Binds index buffer
@@ -99,7 +106,7 @@ public:
    * @param[in] uboBindings real UBO binfins
    * @param[in] standaloneBindings emulated (legacy) UBO object
    */
-  void BindUniformBuffers(const std::vector<UniformBufferBindingDescriptor>& uboBindings, const UniformBufferBindingDescriptor& standaloneBindings);
+  void BindUniformBuffers(const UniformBufferBindingDescriptor* uboBindings, uint32_t uboCount, const UniformBufferBindingDescriptor& standaloneBindings);
 
   /**
    * @brief Resolves blend state on the currently attached pipeline
@@ -122,10 +129,14 @@ public:
   void ResolveStandaloneUniforms();
 
   /**
-   * @brief Begins render pass for sepcified render target
+   * @brief Resolves GPU-based uniform buffers
+   */
+  void ResolveGpuUniformBuffers();
+
+  /**
+   * @brief Begins render pass for specified render target
    *
    * @param[in] renderPass render pass object to begin
-   * @param[in] renderTarget render target to be drawn onto
    */
   void BeginRenderPass(const BeginRenderPassDescriptor& renderPassBegin);
 
@@ -133,13 +144,73 @@ public:
    * @brief Ends render pass
    *
    * Ending render pass is necessary in order to ensure
-   * proper implicit synchronization is in place
+   * proper explicit synchronization is in place
+   */
+  void EndRenderPass(TextureDependencyChecker& checker);
+
+  /**
+   * @brief Returns the cache of GL state in the context
+   * @return the reference of GL state cache (which can be modified)
+   */
+  GLStateCache& GetGLStateCache();
+
+  /**
+   * @brief Called when the GL context has been created.
+   */
+  void GlContextCreated();
+
+  /**
+   * @brief Called when the GL context has been destroyed.
+   */
+  void GlContextDestroyed();
+
+  /**
+   * @brief Invalidates the cached pipeline object in the context if it matches
+   * This is called before the pipeline is deleted
+   *
+   * @param[in] pipeline The pipeline
+   */
+  void InvalidateCachedPipeline(GLES::Pipeline* pipeline);
+
+  /**
+   * @brief Sets up EGL context for native rendering
+   *
+   * - The native rendering uses dedicated context
+   * - There is one EGL native rendering context per GLES::Context object
+   * - Native rendering context is compatible with the window/surface context
+   * - Native rendering context dies with GLES::Context object
+   *
+   * When native rendering is about to be executed, the dedicated EGL context
+   * is acquired (created or reused) and made current. The Window/Surface context
+   * is cached to be restored afterwards.
+   */
+  void PrepareForNativeRendering();
+
+  /**
+   * @brief Restores window/surface context after native rendering.
+   */
+  void RestoreFromNativeRendering();
+
+  void ActiveTexture(uint32_t textureBindingIndex);
+  void BindTexture(GLenum target, BoundTextureType textureTypeId, uint32_t textureId);
+  void GenerateMipmap(GLenum target);
+
+  /**
+   * Binds the buffer.
+   * @return true if the buffer was actually bound, false if it's cached
    */
-  void EndRenderPass();
+  bool BindBuffer(GLenum target, uint32_t bufferId);
 
+  void DrawBuffers(uint32_t count, const GLenum* buffers);
+  void BindFrameBuffer(GLenum target, uint32_t bufferId);
+  void GenFramebuffers(uint32_t count, uint32_t* framebuffers);
+  void DeleteFramebuffers(uint32_t count, uint32_t* framebuffers);
   void ColorMask(bool enabled);
   void ClearStencilBuffer();
   void ClearDepthBuffer();
+  void ClearBuffer(uint32_t mask, bool forceClear);
+  void InvalidateDepthStencilBuffers();
+  void SetScissorTestEnabled(bool scissorEnabled);
   void SetStencilTestEnable(bool stencilEnable);
   void StencilMask(uint32_t writeMask);
   void StencilFunc(Graphics::CompareOp compareOp,