Added direct injection of native draw command into DALi pipeline. 90/305990/7
authorAdam Bialogonski <adam.b@samsung.com>
Wed, 14 Feb 2024 14:36:15 +0000 (14:36 +0000)
committerAdam Bialogonski <adam.b@samsung.com>
Wed, 21 Feb 2024 10:15:09 +0000 (10:15 +0000)
Needed by direct rendering feature. Now, it's possible to execute GL calls without creating additional context.

Change-Id: I7a21f82d57e2edbaecedcf7ff98c01471b0497a3

dali/internal/graphics/gles-impl/egl-graphics-controller.cpp
dali/internal/graphics/gles-impl/gles-context.cpp
dali/internal/graphics/gles-impl/gles-context.h

index 3d7979a..1200699 100644 (file)
@@ -695,7 +695,13 @@ void EglGraphicsController::ProcessCommandBuffer(const GLES::CommandBuffer& comm
       {
         auto* info = &cmd.drawNative.drawNativeInfo;
 
-        mCurrentContext->PrepareForNativeRendering();
+        // ISOLATED execution mode will isolate GL graphics context from
+        // DALi renderning pipeline which is the safest way of rendering
+        // the 'injected' code.
+        if(info->executionMode == DrawNativeExecutionMode::ISOLATED)
+        {
+          mCurrentContext->PrepareForNativeRendering();
+        }
 
         if(info->glesNativeInfo.eglSharedContextStoragePointer)
         {
@@ -704,8 +710,21 @@ void EglGraphicsController::ProcessCommandBuffer(const GLES::CommandBuffer& comm
         }
 
         CallbackBase::ExecuteReturn<bool>(*info->callback, info->userData);
-
-        mCurrentContext->RestoreFromNativeRendering();
+        if(info->executionMode == DrawNativeExecutionMode::ISOLATED)
+        {
+          mCurrentContext->RestoreFromNativeRendering();
+        }
+        else
+        {
+          // After native rendering reset all states and caches.
+          // This is going to be called only when DIRECT execution mode is used
+          // and some GL states need to be reset.
+          // This does not guarantee that after execution a custom GL code
+          // the main rendering pipeline will work correctly and it's a responsibility
+          // of developer to make sure the GL states are not interfering with main
+          // rendering pipeline (by restoring/cleaning up GL states after drawing).
+          mCurrentContext->ResetGLESState();
+        }
         break;
       }
     }
index c90b2a8..b7e829b 100644 (file)
@@ -198,7 +198,7 @@ struct Context::Impl
 
   /**
    * Either enables or disables a vertex attribute location in the cache
-   * The cahnges won't take affect until FlushVertexAttributeLocations is called
+   * The changes won't take affect until FlushVertexAttributeLocations is called
    * @param location attribute location
    * @param state attribute state
    */
@@ -1308,6 +1308,27 @@ void Context::PrepareForNativeRendering()
   }
 
   eglMakeCurrent(display, drawSurface, readSurface, mImpl->mNativeDrawContext);
+  // make sure it's current window context
+  eglMakeCurrent(display, mImpl->mCacheDrawWriteSurface, mImpl->mCacheDrawReadSurface, mImpl->mCacheEGLGraphicsContext);
+}
+
+void Context::ResetGLESState()
+{
+  mImpl->mGlStateCache.ResetBufferCache();
+  mImpl->mGlStateCache.ResetTextureCache();
+  mImpl->mCurrentPipeline = nullptr;
+  mImpl->mCurrentUBOBindings.clear();
+  mImpl->mCurrentTextureBindings.clear();
+  mImpl->mCurrentVertexBufferBindings.clear();
+  mImpl->mCurrentRenderTarget = nullptr;
+  mImpl->mCurrentRenderPass = nullptr;
+  mImpl->mVertexBuffersChanged = true;
+  mImpl->mCurrentIndexBufferBinding = {};
+  mImpl->mCurrentSamplerBindings = {};
+  mImpl->mProgramVAOCurrentState = 0;
+
+  ClearState();
+  mImpl->InitializeGlState();
 }
 
 void Context::RestoreFromNativeRendering()
index f4cde6d..d627360 100644 (file)
@@ -223,6 +223,7 @@ public:
   void SetDepthTestEnable(bool depthTestEnable);
   void SetDepthWriteEnable(bool depthWriteEnable);
 
+  void ResetGLESState();
 private:
   /**
    * @brief Clear current state