[Tizen] Skip Rendering if native texture not prepared 20/317120/1
authorEunki Hong <eunkiki.hong@samsung.com>
Tue, 24 Dec 2024 11:27:50 +0000 (20:27 +0900)
committerEunki Hong <eunkiki.hong@samsung.com>
Tue, 24 Dec 2024 11:31:53 +0000 (20:31 +0900)
We should not render the program if texture was not prepared.
Also, if CreateResource failed, mEglImageExtensions might be nullptr.
So we need to make a nullptr check if CreateResource failed, and try to
call other API, like PrepareTexture().

Change-Id: Ic22ba6500faec496f94e6cc2f0cfdcd502bf3999
Signed-off-by: Eunki Hong <eunkiki.hong@samsung.com>
dali/internal/graphics/gles-impl/gles-context.cpp
dali/internal/imaging/tizen/native-image-source-impl-tizen.cpp

index 17dc2817c90cf80f3bc765ab53554a7267c7bc83..11a45b050fc95226469dc6fc6e855a726730c369 100644 (file)
@@ -361,6 +361,8 @@ void Context::Flush(bool reset, const GLES::DrawCallDescriptor& drawCall, GLES::
   uint32_t currentSampler = 0;
   uint32_t currentElement = 0;
 
+  bool needDraw = true;
+
   // @warning Assume that binding.binding is strictly linear in the same order as mCurrentTextureBindings
   // elements. This avoids having to sort the bindings.
   for(const auto& binding : mImpl->mCurrentTextureBindings)
@@ -376,7 +378,11 @@ void Context::Flush(bool reset, const GLES::DrawCallDescriptor& drawCall, GLES::
     // Texture may not have been initialized yet...(tbm_surface timing issue?)
     if(!texture->GetGLTexture())
     {
-      texture->InitializeResource();
+      if(DALI_UNLIKELY(!texture->InitializeResource()))
+      {
+        DALI_LOG_ERROR("[ERROR] NativeImage might invalid! Do not render it\n");
+        needDraw = false;
+      }
     }
 
     // Warning, this may cause glWaitSync to occur on the GPU, or glClientWaitSync to block the CPU.
@@ -478,70 +484,73 @@ void Context::Flush(bool reset, const GLES::DrawCallDescriptor& drawCall, GLES::
   const auto& ia = pipelineState.inputAssemblyState;
 
   // Resolve draw call
-  switch(drawCall.type)
+  if(DALI_LIKELY(needDraw))
   {
-    case DrawCallDescriptor::Type::DRAW:
+    switch(drawCall.type)
     {
-      mImpl->mGlStateCache.mFrameBufferStateCache.DrawOperation(mImpl->mGlStateCache.mColorMask,
-                                                                mImpl->mGlStateCache.DepthBufferWriteEnabled(),
-                                                                mImpl->mGlStateCache.StencilBufferWriteEnabled());
-      // For GLES3+ we use VAO, for GLES2 internal cache
-      if(!hasGLES3)
+      case DrawCallDescriptor::Type::DRAW:
       {
-        mImpl->FlushVertexAttributeLocations();
-      }
+        mImpl->mGlStateCache.mFrameBufferStateCache.DrawOperation(mImpl->mGlStateCache.mColorMask,
+                                                                  mImpl->mGlStateCache.DepthBufferWriteEnabled(),
+                                                                  mImpl->mGlStateCache.StencilBufferWriteEnabled());
+        // For GLES3+ we use VAO, for GLES2 internal cache
+        if(!hasGLES3)
+        {
+          mImpl->FlushVertexAttributeLocations();
+        }
 
-      if(drawCall.draw.instanceCount == 0)
-      {
-        gl->DrawArrays(GLESTopology(ia->topology),
-                       drawCall.draw.firstVertex,
-                       drawCall.draw.vertexCount);
+        if(drawCall.draw.instanceCount == 0)
+        {
+          gl->DrawArrays(GLESTopology(ia->topology),
+                        drawCall.draw.firstVertex,
+                        drawCall.draw.vertexCount);
+        }
+        else
+        {
+          gl->DrawArraysInstanced(GLESTopology(ia->topology),
+                                  drawCall.draw.firstVertex,
+                                  drawCall.draw.vertexCount,
+                                  drawCall.draw.instanceCount);
+        }
+        break;
       }
-      else
+      case DrawCallDescriptor::Type::DRAW_INDEXED:
       {
-        gl->DrawArraysInstanced(GLESTopology(ia->topology),
-                                drawCall.draw.firstVertex,
-                                drawCall.draw.vertexCount,
-                                drawCall.draw.instanceCount);
-      }
-      break;
-    }
-    case DrawCallDescriptor::Type::DRAW_INDEXED:
-    {
-      const auto& binding = mImpl->mCurrentIndexBufferBinding;
-      BindBuffer(GL_ELEMENT_ARRAY_BUFFER, binding.buffer->GetGLBuffer());
+        const auto& binding = mImpl->mCurrentIndexBufferBinding;
+        BindBuffer(GL_ELEMENT_ARRAY_BUFFER, binding.buffer->GetGLBuffer());
 
-      mImpl->mGlStateCache.mFrameBufferStateCache.DrawOperation(mImpl->mGlStateCache.mColorMask,
-                                                                mImpl->mGlStateCache.DepthBufferWriteEnabled(),
-                                                                mImpl->mGlStateCache.StencilBufferWriteEnabled());
+        mImpl->mGlStateCache.mFrameBufferStateCache.DrawOperation(mImpl->mGlStateCache.mColorMask,
+                                                                  mImpl->mGlStateCache.DepthBufferWriteEnabled(),
+                                                                  mImpl->mGlStateCache.StencilBufferWriteEnabled());
 
-      // For GLES3+ we use VAO, for GLES2 internal cache
-      if(!hasGLES3)
-      {
-        mImpl->FlushVertexAttributeLocations();
-      }
+        // For GLES3+ we use VAO, for GLES2 internal cache
+        if(!hasGLES3)
+        {
+          mImpl->FlushVertexAttributeLocations();
+        }
 
-      auto indexBufferFormat = GLIndexFormat(binding.format).format;
-      if(drawCall.drawIndexed.instanceCount == 0)
-      {
-        gl->DrawElements(GLESTopology(ia->topology),
-                         drawCall.drawIndexed.indexCount,
-                         indexBufferFormat,
-                         reinterpret_cast<void*>(binding.offset));
+        auto indexBufferFormat = GLIndexFormat(binding.format).format;
+        if(drawCall.drawIndexed.instanceCount == 0)
+        {
+          gl->DrawElements(GLESTopology(ia->topology),
+                          drawCall.drawIndexed.indexCount,
+                          indexBufferFormat,
+                          reinterpret_cast<void*>(binding.offset));
+        }
+        else
+        {
+          gl->DrawElementsInstanced(GLESTopology(ia->topology),
+                                    drawCall.drawIndexed.indexCount,
+                                    indexBufferFormat,
+                                    reinterpret_cast<void*>(binding.offset),
+                                    drawCall.drawIndexed.instanceCount);
+        }
+        break;
       }
-      else
+      case DrawCallDescriptor::Type::DRAW_INDEXED_INDIRECT:
       {
-        gl->DrawElementsInstanced(GLESTopology(ia->topology),
-                                  drawCall.drawIndexed.indexCount,
-                                  indexBufferFormat,
-                                  reinterpret_cast<void*>(binding.offset),
-                                  drawCall.drawIndexed.instanceCount);
+        break;
       }
-      break;
-    }
-    case DrawCallDescriptor::Type::DRAW_INDEXED_INDIRECT:
-    {
-      break;
     }
   }
 
index 9f4c91c62dc9992c782c33e298e84896466c7c82..dea39bfb3e490606d610dfe083f78614169a8d54 100644 (file)
@@ -556,6 +556,7 @@ void NativeImageSourceTizen::DestroyResource()
   std::scoped_lock lock(mMutex);
   if(mEglImageKHR)
   {
+    DALI_ASSERT_DEBUG(mEglImageExtensions);
     mEglImageExtensions->DestroyImageKHR(mEglImageKHR);
 
     mEglImageKHR = NULL;
@@ -569,7 +570,10 @@ void NativeImageSourceTizen::DestroyResource()
 
 uint32_t NativeImageSourceTizen::TargetTexture()
 {
-  mEglImageExtensions->TargetTextureKHR(mEglImageKHR);
+  if(DALI_LIKELY(mEglImageExtensions && mEglImageKHR))
+  {
+    mEglImageExtensions->TargetTextureKHR(mEglImageKHR);
+  }
 
   return 0;
 }
@@ -581,8 +585,12 @@ void NativeImageSourceTizen::PrepareTexture()
   {
     // Destroy previous eglImage because use for new one.
     // if mEglImageKHR is not to be NULL here, it will not be updated with a new eglImage.
-    mEglImageExtensions->DestroyImageKHR(mEglImageKHR);
-    mEglImageKHR = NULL;
+    if(mEglImageKHR)
+    {
+      DALI_ASSERT_DEBUG(mEglImageExtensions);
+      mEglImageExtensions->DestroyImageKHR(mEglImageKHR);
+      mEglImageKHR = NULL;
+    }
 
     if(CreateResource())
     {