[Tizen] Change GetTextureProperties
[platform/core/uifw/dali-adaptor.git] / dali / internal / graphics / gles-impl / egl-graphics-controller.cpp
index d7b8d33..be7a0c3 100644 (file)
@@ -109,6 +109,12 @@ const uint32_t TEXTURE_UPLOAD_MAX_BUFER_SIZE_MB = 1;
 
 } // namespace
 
+EglGraphicsController::EglGraphicsController()
+: mTextureDependencyChecker(*this),
+  mSyncPool(*this)
+{
+}
+
 EglGraphicsController::~EglGraphicsController()
 {
   while(!mPresentationCommandBuffers.empty())
@@ -190,6 +196,12 @@ void EglGraphicsController::ResolvePresentRenderTarget(GLES::RenderTarget* rende
   }
 }
 
+void EglGraphicsController::PostRender()
+{
+  mTextureDependencyChecker.Reset();
+  mSyncPool.AgeSyncObjects();
+}
+
 Integration::GlAbstraction& EglGraphicsController::GetGlAbstraction()
 {
   DALI_ASSERT_DEBUG(mGlAbstraction && "Graphics controller not initialized");
@@ -290,6 +302,21 @@ Graphics::UniquePtr<SyncObject> EglGraphicsController::CreateSyncObject(const Sy
   }
 }
 
+TextureProperties EglGraphicsController::GetTextureProperties(const Texture& texture)
+{
+  const GLES::Texture* glesTexture = static_cast<const GLES::Texture*>(&texture);
+  auto                 createInfo  = glesTexture->GetCreateInfo();
+
+  TextureProperties properties{};
+  properties.format       = createInfo.format;
+  properties.compressed   = glesTexture->IsCompressed();
+  properties.extent2D     = createInfo.size;
+  properties.nativeHandle = glesTexture->GetGLTexture();
+  //TODO: Skip format1, emulated, packed, directWriteAccessEnabled of TextureProperties for now
+
+  return properties;
+}
+
 const Graphics::Reflection& EglGraphicsController::GetProgramReflection(const Graphics::Program& program)
 {
   return static_cast<const Graphics::GLES::Program*>(&program)->GetReflection();
@@ -316,7 +343,10 @@ void EglGraphicsController::ActivateResourceContext()
   if(!mSharedContext)
   {
     auto eglGraphics = dynamic_cast<Dali::Internal::Adaptor::EglGraphics*>(mGraphics);
-    mSharedContext   = eglGraphics->GetEglImplementation().GetContext();
+    if(eglGraphics)
+    {
+      mSharedContext = eglGraphics->GetEglImplementation().GetContext();
+    }
   }
 }
 
@@ -448,17 +478,17 @@ void EglGraphicsController::ProcessCommandBuffer(const GLES::CommandBuffer& comm
       }
       case GLES::CommandType::DRAW:
       {
-        mCurrentContext->Flush(false, cmd.draw);
+        mCurrentContext->Flush(false, cmd.draw, mTextureDependencyChecker);
         break;
       }
       case GLES::CommandType::DRAW_INDEXED:
       {
-        mCurrentContext->Flush(false, cmd.draw);
+        mCurrentContext->Flush(false, cmd.draw, mTextureDependencyChecker);
         break;
       }
       case GLES::CommandType::DRAW_INDEXED_INDIRECT:
       {
-        mCurrentContext->Flush(false, cmd.draw);
+        mCurrentContext->Flush(false, cmd.draw, mTextureDependencyChecker);
         break;
       }
       case GLES::CommandType::SET_SCISSOR: // @todo Consider correcting for orientation here?
@@ -554,12 +584,15 @@ void EglGraphicsController::ProcessCommandBuffer(const GLES::CommandBuffer& comm
         }
 
         mCurrentContext->BeginRenderPass(cmd.beginRenderPass);
+
         break;
       }
       case GLES::CommandType::END_RENDERPASS:
       {
-        mCurrentContext->EndRenderPass();
+        mCurrentContext->EndRenderPass(mTextureDependencyChecker);
 
+        // This sync object is to enable cpu to wait for rendering to complete, not gpu.
+        // It's only needed for reading the framebuffer texture in the client.
         auto syncObject = const_cast<GLES::SyncObject*>(static_cast<const GLES::SyncObject*>(cmd.endRenderPass.syncObject));
         if(syncObject)
         {
@@ -656,14 +689,19 @@ void EglGraphicsController::ProcessTextureUpdateQueue()
                             info.srcExtent2D.height != (createInfo.size.height / (1 << info.level)));
 
       auto*                sourceBuffer = reinterpret_cast<uint8_t*>(source.memorySource.memory);
+      auto                 sourceStride = info.srcStride;
       std::vector<uint8_t> tempBuffer;
+
       if(mGlAbstraction->TextureRequiresConverting(srcFormat, destFormat, isSubImage))
       {
         // Convert RGB to RGBA if necessary.
-        texture->TryConvertPixelData(source.memorySource.memory, info.srcFormat, createInfo.format, info.srcSize, info.srcExtent2D.width, info.srcExtent2D.height, tempBuffer);
-        sourceBuffer = &tempBuffer[0];
-        srcFormat    = destFormat;
-        srcType      = GLES::GLTextureFormatType(createInfo.format).type;
+        if(texture->TryConvertPixelData(source.memorySource.memory, info.srcFormat, createInfo.format, info.srcSize, info.srcStride, info.srcExtent2D.width, info.srcExtent2D.height, tempBuffer))
+        {
+          sourceBuffer = &tempBuffer[0];
+          sourceStride = 0u; // Converted buffer compacted. make stride as 0.
+          srcFormat    = destFormat;
+          srcType      = GLES::GLTextureFormatType(createInfo.format).type;
+        }
       }
 
       // Calculate the maximum mipmap level for the texture
@@ -679,7 +717,7 @@ void EglGraphicsController::ProcessTextureUpdateQueue()
       }
 
       mGlAbstraction->PixelStorei(GL_UNPACK_ALIGNMENT, 1);
-      mGlAbstraction->PixelStorei(GL_UNPACK_ROW_LENGTH, info.srcStride);
+      mGlAbstraction->PixelStorei(GL_UNPACK_ROW_LENGTH, sourceStride);
 
       mCurrentContext->BindTexture(bindTarget, texture->GetTextureTypeId(), texture->GetGLTexture());
 
@@ -767,10 +805,11 @@ void EglGraphicsController::UpdateTextures(const std::vector<TextureUpdateInfo>&
         // TODO: using PBO with GLES3, this is just naive
         // oldschool way
 
-        char* stagingBuffer = reinterpret_cast<char*>(malloc(info.srcSize));
-        std::copy(&reinterpret_cast<char*>(source.memorySource.memory)[info.srcOffset],
-                  reinterpret_cast<char*>(source.memorySource.memory) + info.srcSize,
-                  stagingBuffer);
+        uint8_t* stagingBuffer = reinterpret_cast<uint8_t*>(malloc(info.srcSize));
+
+        uint8_t* srcMemory = &reinterpret_cast<uint8_t*>(source.memorySource.memory)[info.srcOffset];
+
+        std::copy(srcMemory, srcMemory + info.srcSize, stagingBuffer);
 
         mTextureUploadTotalCPUMemoryUsed += info.srcSize;