[Tizen] Create Texture by ResourceId + Set Texture size and format internally. accepted/tizen/unified/20230726.163507
authorjmm <j0064423.lee@samsung.com>
Tue, 25 Jul 2023 06:59:55 +0000 (15:59 +0900)
committerjmm <j0064423.lee@samsung.com>
Tue, 25 Jul 2023 07:02:33 +0000 (16:02 +0900)
Change-Id: I7ae8d502183d8e1f0dd2ccf91c6b1f78f9bb9a08

20 files changed:
automated-tests/src/dali-internal/CMakeLists.txt
automated-tests/src/dali-internal/utc-Dali-Internal-Texture.cpp [new file with mode: 0644]
automated-tests/src/dali/dali-test-suite-utils/test-graphics-controller.cpp
automated-tests/src/dali/dali-test-suite-utils/test-graphics-controller.h
automated-tests/src/dali/utc-Dali-Texture.cpp
dali/graphics-api/file.list
dali/graphics-api/graphics-controller.h
dali/graphics-api/graphics-texture-upload-helper.h [new file with mode: 0644]
dali/integration-api/file.list
dali/integration-api/texture-integ.cpp [new file with mode: 0644]
dali/integration-api/texture-integ.h [new file with mode: 0644]
dali/internal/common/type-abstraction-enums.h
dali/internal/event/rendering/texture-impl.cpp
dali/internal/event/rendering/texture-impl.h
dali/internal/render/common/render-manager.cpp
dali/internal/render/common/render-manager.h
dali/internal/render/renderers/render-texture.cpp
dali/internal/render/renderers/render-texture.h
dali/internal/update/manager/update-manager.cpp
dali/internal/update/manager/update-manager.h

index 5655364..e902727 100644 (file)
@@ -28,6 +28,7 @@ SET(TC_SOURCES
         utc-Dali-Internal-RotationGesture.cpp
         utc-Dali-Internal-TapGesture.cpp
         utc-Dali-Internal-TapGestureProcessor.cpp
+        utc-Dali-Internal-Texture.cpp
         utc-Dali-Internal-TransformManagerProperty.cpp
 )
 
diff --git a/automated-tests/src/dali-internal/utc-Dali-Internal-Texture.cpp b/automated-tests/src/dali-internal/utc-Dali-Internal-Texture.cpp
new file mode 100644 (file)
index 0000000..4c14207
--- /dev/null
@@ -0,0 +1,134 @@
+/*
+ * Copyright (c) 2023 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <dali-test-suite-utils.h>
+#include <dali/devel-api/rendering/texture-devel.h>
+#include <dali/integration-api/pixel-data-integ.h>
+#include <dali/integration-api/texture-integ.h>
+#include <dali/public-api/dali-core.h>
+
+using namespace Dali;
+
+void utc_dali_internal_texture_set_startup(void)
+{
+  test_return_value = TET_UNDEF;
+}
+
+void utc_dali_internal_texture_set_cleanup(void)
+{
+  test_return_value = TET_PASS;
+}
+
+int UtcDaliTextureUploadByResourceId(void)
+{
+  TestApplication application;
+
+  uint32_t  width(4);
+  uint32_t  height(4);
+  uint32_t  bufferSize(width * height * 4);
+  uint8_t*  buffer    = reinterpret_cast<unsigned char*>(malloc(bufferSize));
+  PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
+
+  // Run two cases.
+  for(int tc = 0; tc < 2; tc++)
+  {
+    uint32_t expectResourceId = 11u + tc;
+
+    Texture texture = Integration::NewTextureWithResourceId(TextureType::TEXTURE_2D, expectResourceId);
+    Actor   actor   = CreateRenderableActor(texture);
+
+    application.GetScene().Add(actor);
+
+    DALI_TEST_CHECK(texture);
+
+    uint32_t currentResourceId = Integration::GetTextureResourceId(texture);
+
+    DALI_TEST_EQUALS(currentResourceId, expectResourceId, TEST_LOCATION);
+
+    if(tc == 0)
+    {
+      // Scene on before upload.
+      application.SendNotification();
+      application.Render(16);
+    }
+
+    auto& graphicsController = application.GetGraphicsController();
+
+    Graphics::Texture* graphicsTexture = nullptr;
+
+    tet_printf("CreateTextureByResourceId\n");
+    {
+      auto createInfo = Graphics::TextureCreateInfo();
+      createInfo
+        .SetTextureType(Dali::Graphics::ConvertTextureType(Dali::TextureType::TEXTURE_2D))
+        .SetUsageFlags(static_cast<Graphics::TextureUsageFlags>(Graphics::TextureUsageFlagBits::SAMPLE))
+        .SetFormat(Dali::Graphics::ConvertPixelFormat(pixelData.GetPixelFormat()))
+        .SetSize({pixelData.GetWidth(), pixelData.GetHeight()})
+        .SetLayout(Graphics::TextureLayout::LINEAR)
+        .SetData(nullptr)
+        .SetDataSize(0u)
+        .SetNativeImage(nullptr)
+        .SetMipMapFlag(Graphics::TextureMipMapFlag::DISABLED);
+
+      graphicsTexture = graphicsController.CreateTextureByResourceId(currentResourceId, createInfo);
+    }
+
+    DALI_TEST_CHECK(graphicsTexture != nullptr);
+
+    tet_printf("Upload\n");
+    if(graphicsTexture)
+    {
+      Graphics::TextureUpdateInfo info{};
+
+      info.dstTexture   = graphicsTexture;
+      info.dstOffset2D  = {0u, 0u};
+      info.layer        = 0u;
+      info.level        = 0u;
+      info.srcReference = 0;
+      info.srcExtent2D  = {pixelData.GetWidth(), pixelData.GetHeight()};
+      info.srcOffset    = 0;
+      info.srcSize      = Dali::Integration::GetPixelDataBuffer(pixelData).bufferSize;
+      info.srcStride    = pixelData.GetStride();
+      info.srcFormat    = Dali::Graphics::ConvertPixelFormat(pixelData.GetPixelFormat());
+
+      Graphics::TextureUpdateSourceInfo updateSourceInfo{};
+      updateSourceInfo.sourceType                = Graphics::TextureUpdateSourceInfo::Type::PIXEL_DATA;
+      updateSourceInfo.pixelDataSource.pixelData = pixelData;
+
+      graphicsController.UpdateTextures({info}, {updateSourceInfo});
+    }
+
+    tet_printf("Flush\n");
+    {
+      Graphics::SubmitInfo submitInfo;
+      submitInfo.cmdBuffer.clear(); // Only flush
+      submitInfo.flags = 0 | Graphics::SubmitFlagBits::FLUSH;
+      graphicsController.SubmitCommandBuffers(submitInfo);
+    }
+
+    if(tc == 1)
+    {
+      // Scene on after upload.
+      application.SendNotification();
+      application.Render(16);
+    }
+
+    actor.Unparent();
+  }
+
+  END_TEST;
+}
\ No newline at end of file
index 4bac7a6..527b9f4 100644 (file)
@@ -1409,4 +1409,71 @@ bool TestGraphicsController::GetProgramParameter(Graphics::Program& program, uin
   return graphicsProgram->GetParameter(parameterId, outData);
 }
 
+Graphics::Texture* TestGraphicsController::CreateTextureByResourceId(uint32_t resourceId, const Graphics::TextureCreateInfo& createInfo)
+{
+  Graphics::Texture*                     ret = nullptr;
+  Graphics::UniquePtr<Graphics::Texture> texture;
+  TraceCallStack::NamedParams            namedParams;
+  namedParams["resourceId"] << resourceId;
+
+  auto iter = mTextureUploadBindMapper.find(resourceId);
+  DALI_ASSERT_ALWAYS(iter == mTextureUploadBindMapper.end());
+
+  // Create new graphics texture.
+  texture = CreateTexture(createInfo, std::move(texture));
+  ret     = texture.get();
+
+  mTextureUploadBindMapper.insert(std::make_pair(resourceId, std::move(texture)));
+
+  mCallStack.PushCall("CreateTextureByResourceId", "", namedParams);
+  return ret;
+}
+
+void TestGraphicsController::DiscardTextureFromResourceId(uint32_t resourceId)
+{
+  TraceCallStack::NamedParams namedParams;
+  namedParams["resourceId"] << resourceId;
+
+  mTextureUploadBindMapper.erase(resourceId);
+
+  mCallStack.PushCall("DiscardTextureFromResourceId", "", namedParams);
+}
+
+Graphics::Texture* TestGraphicsController::GetTextureFromResourceId(uint32_t resourceId)
+{
+  TraceCallStack::NamedParams namedParams;
+  namedParams["resourceId"] << resourceId;
+
+  Graphics::Texture* ret = nullptr;
+
+  auto iter = mTextureUploadBindMapper.find(resourceId);
+  if(iter != mTextureUploadBindMapper.end())
+  {
+    ret = iter->second.get();
+  }
+
+  mCallStack.PushCall("GetTextureFromResourceId", "", namedParams);
+
+  return ret;
+}
+
+Graphics::UniquePtr<Graphics::Texture> TestGraphicsController::ReleaseTextureFromResourceId(uint32_t resourceId)
+{
+  TraceCallStack::NamedParams namedParams;
+  namedParams["resourceId"] << resourceId;
+
+  Graphics::UniquePtr<Graphics::Texture> texture;
+
+  auto iter = mTextureUploadBindMapper.find(resourceId);
+  if(iter != mTextureUploadBindMapper.end())
+  {
+    texture = std::move(iter->second);
+    mTextureUploadBindMapper.erase(iter);
+  }
+
+  mCallStack.PushCall("ReleaseTextureFromResourceId", "", namedParams);
+
+  return texture;
+}
+
 } // namespace Dali
index ade48d7..9540c3e 100644 (file)
@@ -18,6 +18,7 @@
  */
 
 #include <dali/graphics-api/graphics-controller.h>
+#include <unordered_map>
 #include "test-gl-abstraction.h"
 #include "test-gl-context-helper-abstraction.h"
 #include "test-graphics-command-buffer.h"
@@ -375,6 +376,53 @@ public:
    */
   bool PipelineEquals(const Graphics::Pipeline& pipeline0, const Graphics::Pipeline& pipeline1) const override;
 
+  /**
+   * @brief Retrieves program parameters
+   *
+   * This function can be used to retrieve data from internal implementation
+   *
+   * @param[in] program Valid program object
+   * @param[in] parameterId Integer parameter id
+   * @param[out] outData Pointer to output memory
+   * @return True on success
+   */
+  bool GetProgramParameter(Graphics::Program& program, uint32_t parameterId, void* outData) override;
+
+public: // ResourceId relative API.
+  /**
+   * @brief Create Graphics::Texture as resourceId.
+   * The ownership of Graphics::Texture will be hold on this controller.
+   * @note If some Graphics::Texture already created before, assert.
+   * @post DiscardTextureFromResourceId() or ReleaseTextureFromResourceId() should be called when we don't use resourceId texture anymore.
+   *
+   * @param[in] resourceId The unique id of resouces.
+   * @return Pointer of Graphics::Texture, or nullptr if we fail to create.
+   */
+  Graphics::Texture* CreateTextureByResourceId(uint32_t resourceId, const Graphics::TextureCreateInfo& createInfo) override;
+
+  /**
+   * @brief Discard Graphics::Texture as resourceId.
+   *
+   * @param[in] resourceId The unique id of resouces.
+   */
+  void DiscardTextureFromResourceId(uint32_t resourceId) override;
+
+  /**
+   * @brief Get the Graphics::Texture as resourceId.
+   *
+   * @param[in] resourceId The unique id of resouces.
+   * @return Pointer of Graphics::Texture, or nullptr if there is no valid objects.
+   */
+  Graphics::Texture* GetTextureFromResourceId(uint32_t resourceId) override;
+
+  /**
+   * @brief Get the ownership of Graphics::Texture as resourceId.
+   *
+   * @param[in] resourceId The unique id of resouces.
+   * @return Pointer of Graphics::Texture.
+   */
+  Graphics::UniquePtr<Graphics::Texture> ReleaseTextureFromResourceId(uint32_t resourceId) override;
+
 public: // Test Functions
   void SetVertexFormats(Property::Array& vfs)
   {
@@ -396,18 +444,6 @@ public: // Test Functions
     mSubmitStack.clear();
   }
 
-  /**
-   * @brief Retrieves program parameters
-   *
-   * This function can be used to retrieve data from internal implementation
-   *
-   * @param[in] program Valid program object
-   * @param[in] parameterId Integer parameter id
-   * @param[out] outData Pointer to output memory
-   * @return True on success
-   */
-  bool GetProgramParameter(Graphics::Program& program, uint32_t parameterId, void* outData) override;
-
   void ProcessCommandBuffer(TestGraphicsCommandBuffer& commandBuffer);
 
   void BindPipeline(TestGraphicsPipeline* pipeline);
@@ -436,6 +472,8 @@ public:
 
   std::vector<TestGraphicsBuffer*> mAllocatedBuffers;
 
+  std::unordered_map<uint32_t, Graphics::UniquePtr<Graphics::Texture>> mTextureUploadBindMapper;
+
   struct PipelineCache
   {
   };
index 443bbb0..de5ea96 100644 (file)
@@ -17,6 +17,7 @@
 
 #include <dali-test-suite-utils.h>
 #include <dali/devel-api/rendering/texture-devel.h>
+#include <dali/integration-api/texture-integ.h>
 #include <dali/public-api/dali-core.h>
 #include <test-native-image.h>
 
@@ -80,6 +81,23 @@ int UtcDaliTextureNew04(void)
   END_TEST;
 }
 
+int UtcDaliTextureNew05(void)
+{
+  TestApplication application;
+
+  uint32_t expectResourceId = 11u;
+
+  Texture texture = Integration::NewTextureWithResourceId(TextureType::TEXTURE_2D, expectResourceId);
+
+  DALI_TEST_CHECK(texture);
+
+  uint32_t currentResourceId = Integration::GetTextureResourceId(texture);
+
+  DALI_TEST_EQUALS(currentResourceId, expectResourceId, TEST_LOCATION);
+
+  END_TEST;
+}
+
 int UtcDaliTextureCopyConstructor(void)
 {
   TestApplication application;
@@ -1079,6 +1097,68 @@ int UtcDaliTextureGetHeight(void)
   END_TEST;
 }
 
+int UtcDaliTextureGetTextureType(void)
+{
+  TestApplication application;
+  unsigned int    width(64);
+  unsigned int    height(64);
+
+  Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
+  DALI_TEST_EQUALS(Integration::GetTextureType(texture), TextureType::TEXTURE_2D, TEST_LOCATION);
+
+  texture = CreateTexture(TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height);
+  DALI_TEST_EQUALS(Integration::GetTextureType(texture), TextureType::TEXTURE_CUBE, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliTextureSetSize(void)
+{
+  TestApplication application;
+  unsigned int    width(64);
+  unsigned int    height(64);
+
+  Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
+  DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
+  DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
+  DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
+
+  width += 11u;
+  height += 22u;
+
+  Integration::SetTextureSize(texture, ImageDimensions(width, height));
+  DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
+  DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
+  DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
+
+  application.SendNotification();
+  application.Render();
+
+  END_TEST;
+}
+
+int UtcDaliTextureSetPixelFormat(void)
+{
+  TestApplication application;
+  unsigned int    width(64);
+  unsigned int    height(64);
+
+  Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
+  DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
+  DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
+  DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
+
+  Integration::SetTexturePixelFormat(texture, Pixel::BGRA5551);
+  DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
+  DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
+  DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::BGRA5551, TEST_LOCATION);
+
+  application.SendNotification();
+  application.Render();
+
+  END_TEST;
+}
+
 int UtcDaliTextureContextLoss(void)
 {
   tet_infoline("UtcDaliTextureContextLoss\n");
index 6836fbd..92f6134 100644 (file)
@@ -28,6 +28,7 @@ SET( GRAPHICS_API_HEADERS ${GRAPHICS_API_HEADERS}
    ${graphics_src_dir}/graphics-sync-object-create-info.h
    ${graphics_src_dir}/graphics-sync-object.h
    ${graphics_src_dir}/graphics-texture-create-info.h
+   ${graphics_src_dir}/graphics-texture-upload-helper.h
    ${graphics_src_dir}/graphics-texture.h
    ${graphics_src_dir}/graphics-types.h
 )
index bba245a..1395671 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_GRAPHICS_CONTROLLER_H
 
 /*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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,8 +19,8 @@
  */
 
 // EXTERNAL INCLUDES
+#include <dali/public-api/common/vector-wrapper.h>
 #include <memory>
-#include <vector>
 
 // INTERNAL INCLUDES
 #include "graphics-buffer-create-info.h"
@@ -36,6 +36,7 @@
 #include "graphics-shader-create-info.h"
 #include "graphics-sync-object-create-info.h"
 #include "graphics-texture-create-info.h"
+#include "graphics-texture-upload-helper.h"
 
 namespace Dali
 {
@@ -380,6 +381,41 @@ public:
    */
   virtual bool GetProgramParameter(Graphics::Program& program, uint32_t parameterId, void* outData) = 0;
 
+public: // ResourceId relative API.
+  /**
+   * @brief Create Graphics::Texture as resourceId.
+   * The ownership of Graphics::Texture will be hold on this controller.
+   * @note If some Graphics::Texture already created before, assert.
+   * @post DiscardTextureFromResourceId() or ReleaseTextureFromResourceId() should be called when we don't use resourceId texture anymore.
+   *
+   * @param[in] resourceId The unique id of resouces.
+   * @return Pointer of Graphics::Texture, or nullptr if we fail to create.
+   */
+  virtual Graphics::Texture* CreateTextureByResourceId(uint32_t resourceId, const Graphics::TextureCreateInfo& createInfo) = 0;
+
+  /**
+   * @brief Discard Graphics::Texture as resourceId.
+   *
+   * @param[in] resourceId The unique id of resouces.
+   */
+  virtual void DiscardTextureFromResourceId(uint32_t resourceId) = 0;
+
+  /**
+   * @brief Get the Graphics::Texture as resourceId.
+   *
+   * @param[in] resourceId The unique id of resouces.
+   * @return Pointer of Graphics::Texture, or nullptr if there is no valid objects.
+   */
+  virtual Graphics::Texture* GetTextureFromResourceId(uint32_t resourceId) = 0;
+
+  /**
+   * @brief Get the ownership of Graphics::Texture as resourceId.
+   *
+   * @param[in] resourceId The unique id of resouces.
+   * @return Pointer of Graphics::Texture.
+   */
+  virtual UniquePtr<Graphics::Texture> ReleaseTextureFromResourceId(uint32_t resourceId) = 0;
+
 protected:
   /**
    * Creates controller
diff --git a/dali/graphics-api/graphics-texture-upload-helper.h b/dali/graphics-api/graphics-texture-upload-helper.h
new file mode 100644 (file)
index 0000000..3decece
--- /dev/null
@@ -0,0 +1,225 @@
+#ifndef DALI_GRAPHICS_TEXTURE_UPLOAD_INTERFACE_H
+#define DALI_GRAPHICS_TEXTURE_UPLOAD_INTERFACE_H
+
+/*
+ * Copyright (c) 2023 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <dali/public-api/rendering/texture.h>
+
+// INTERNAL INCLUDES
+#include "graphics-types.h"
+
+namespace Dali
+{
+namespace Graphics
+{
+/**
+ * @brief Structure used to pass parameters to the Upload method
+ */
+struct UploadParams
+{
+  uint32_t dataXOffset; ///< Specifies a pixeldata offset in the x direction within the pixeldata buffer.
+  uint32_t dataYOffset; ///< Specifies a pixeldata offset in the y direction within the pixeldata buffer.
+  uint16_t dataWidth;   ///< Specifies the width of the pixeldata subimage.
+  uint16_t dataHeight;  ///< Specifies the height of the pixeldata subimage.
+  uint16_t layer;       ///< Specifies the layer of a cube map or array texture
+  uint16_t mipmap;      ///< Specifies the level-of-detail number. Level 0 is the base image level. Level n is the nth mipmap reduction image.
+  uint16_t xOffset;     ///< Specifies a texel offset in the x direction within the texture array.
+  uint16_t yOffset;     ///< Specifies a texel offset in the y direction within the texture array.
+  uint16_t width;       ///< Specifies the width of the texture subimage
+  uint16_t height;      ///< Specifies the height of the texture subimage.
+};
+
+/**
+ * @brief Converts DALi pixel format to Graphics::Format.
+ * @param[in] format Dali::Pixel::Format.
+ * @return Converted Graphics::Format.
+ */
+constexpr Graphics::Format ConvertPixelFormat(Dali::Pixel::Format format)
+{
+  switch(format)
+  {
+    case Pixel::INVALID:
+      return Graphics::Format::UNDEFINED;
+    case Pixel::A8:
+      return Graphics::Format::R8_UNORM;
+
+    case Pixel::L8:
+      return Graphics::Format::L8;
+    case Pixel::LA88:
+      return Graphics::Format::L8A8;
+    case Pixel::RGB565:
+      return Graphics::Format::R5G6B5_UNORM_PACK16;
+    case Pixel::BGR565:
+      return Graphics::Format::B5G6R5_UNORM_PACK16;
+    case Pixel::RGBA4444:
+      return Graphics::Format::R4G4B4A4_UNORM_PACK16;
+
+    case Pixel::BGRA4444:
+      return Graphics::Format::B4G4R4A4_UNORM_PACK16;
+    case Pixel::RGBA5551:
+      return Graphics::Format::R5G5B5A1_UNORM_PACK16;
+    case Pixel::BGRA5551:
+      return Graphics::Format::B5G5R5A1_UNORM_PACK16;
+    case Pixel::RGB888:
+      return Graphics::Format::R8G8B8_UNORM;
+    case Pixel::RGB8888:
+      return Graphics::Format::R8G8B8A8_UNORM;
+    case Pixel::BGR8888:
+      return Graphics::Format::B8G8R8A8_UNORM;
+    case Pixel::RGBA8888:
+      return Graphics::Format::R8G8B8A8_UNORM;
+    case Pixel::BGRA8888:
+      return Graphics::Format::B8G8R8A8_UNORM;
+
+    case Pixel::DEPTH_UNSIGNED_INT:
+      return Graphics::Format::D16_UNORM;
+    case Pixel::DEPTH_FLOAT:
+      return Graphics::Format::D32_SFLOAT;
+    case Pixel::DEPTH_STENCIL:
+      return Graphics::Format::D24_UNORM_S8_UINT;
+
+    // EAC
+    case Pixel::COMPRESSED_R11_EAC:
+      return Graphics::Format::EAC_R11_UNORM_BLOCK;
+    case Pixel::COMPRESSED_SIGNED_R11_EAC:
+      return Graphics::Format::EAC_R11_SNORM_BLOCK;
+    case Pixel::COMPRESSED_RG11_EAC:
+      return Graphics::Format::EAC_R11G11_UNORM_BLOCK;
+    case Pixel::COMPRESSED_SIGNED_RG11_EAC:
+      return Graphics::Format::EAC_R11G11_SNORM_BLOCK;
+
+    // ETC
+    case Pixel::COMPRESSED_RGB8_ETC2:
+      return Graphics::Format::ETC2_R8G8B8_UNORM_BLOCK;
+    case Pixel::COMPRESSED_SRGB8_ETC2:
+      return Graphics::Format::ETC2_R8G8B8_SRGB_BLOCK;
+
+    case Pixel::COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
+      return Graphics::Format::ETC2_R8G8B8A1_UNORM_BLOCK; // no 'punchthrough' format
+
+    case Pixel::COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
+      return Graphics::Format::ETC2_R8G8B8A1_SRGB_BLOCK; // no 'punchthrough' format
+
+    case Pixel::COMPRESSED_RGBA8_ETC2_EAC:
+      return Graphics::Format::ETC2_R8G8B8A8_UNORM_BLOCK;
+
+    case Pixel::COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
+      return Graphics::Format::ETC2_R8G8B8A8_SRGB_BLOCK;
+
+    case Pixel::COMPRESSED_RGB8_ETC1:
+      return Graphics::Format::ETC2_R8G8B8_UNORM_BLOCK; // doesn't seem to be supported at all
+
+    case Pixel::COMPRESSED_RGB_PVRTC_4BPPV1:
+      return Graphics::Format::PVRTC1_4BPP_UNORM_BLOCK_IMG; // or SRGB?
+
+    // ASTC
+    case Pixel::COMPRESSED_RGBA_ASTC_4x4_KHR:
+      return Graphics::Format::ASTC_4x4_UNORM_BLOCK; // or SRGB?
+    case Pixel::COMPRESSED_RGBA_ASTC_5x4_KHR:
+      return Graphics::Format::ASTC_5x4_UNORM_BLOCK;
+    case Pixel::COMPRESSED_RGBA_ASTC_5x5_KHR:
+      return Graphics::Format::ASTC_5x5_UNORM_BLOCK;
+    case Pixel::COMPRESSED_RGBA_ASTC_6x5_KHR:
+      return Graphics::Format::ASTC_6x5_UNORM_BLOCK;
+    case Pixel::COMPRESSED_RGBA_ASTC_6x6_KHR:
+      return Graphics::Format::ASTC_6x6_UNORM_BLOCK;
+    case Pixel::COMPRESSED_RGBA_ASTC_8x5_KHR:
+      return Graphics::Format::ASTC_8x5_UNORM_BLOCK;
+    case Pixel::COMPRESSED_RGBA_ASTC_8x6_KHR:
+      return Graphics::Format::ASTC_8x6_UNORM_BLOCK;
+    case Pixel::COMPRESSED_RGBA_ASTC_8x8_KHR:
+      return Graphics::Format::ASTC_8x8_UNORM_BLOCK;
+    case Pixel::COMPRESSED_RGBA_ASTC_10x5_KHR:
+      return Graphics::Format::ASTC_10x5_UNORM_BLOCK;
+    case Pixel::COMPRESSED_RGBA_ASTC_10x6_KHR:
+      return Graphics::Format::ASTC_10x6_UNORM_BLOCK;
+    case Pixel::COMPRESSED_RGBA_ASTC_10x8_KHR:
+      return Graphics::Format::ASTC_10x8_UNORM_BLOCK;
+    case Pixel::COMPRESSED_RGBA_ASTC_10x10_KHR:
+      return Graphics::Format::ASTC_10x10_UNORM_BLOCK;
+    case Pixel::COMPRESSED_RGBA_ASTC_12x10_KHR:
+      return Graphics::Format::ASTC_12x10_UNORM_BLOCK;
+    case Pixel::COMPRESSED_RGBA_ASTC_12x12_KHR:
+      return Graphics::Format::ASTC_12x12_UNORM_BLOCK;
+    case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
+      return Graphics::Format::ASTC_4x4_SRGB_BLOCK; // not type with alpha, but likely to use SRGB
+    case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:
+      return Graphics::Format::ASTC_5x4_SRGB_BLOCK;
+    case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:
+      return Graphics::Format::ASTC_5x5_SRGB_BLOCK;
+    case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:
+      return Graphics::Format::ASTC_6x5_SRGB_BLOCK;
+    case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:
+      return Graphics::Format::ASTC_6x6_SRGB_BLOCK;
+    case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:
+      return Graphics::Format::ASTC_8x5_SRGB_BLOCK;
+    case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:
+      return Graphics::Format::ASTC_8x6_UNORM_BLOCK;
+    case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:
+      return Graphics::Format::ASTC_8x8_SRGB_BLOCK;
+    case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:
+      return Graphics::Format::ASTC_10x5_SRGB_BLOCK;
+    case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:
+      return Graphics::Format::ASTC_10x6_SRGB_BLOCK;
+    case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:
+      return Graphics::Format::ASTC_10x8_SRGB_BLOCK;
+    case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:
+      return Graphics::Format::ASTC_10x10_SRGB_BLOCK;
+    case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:
+      return Graphics::Format::ASTC_12x10_SRGB_BLOCK;
+    case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:
+      return Graphics::Format::ASTC_12x12_SRGB_BLOCK;
+
+    case Pixel::RGB16F:
+      return Graphics::Format::R16G16B16_SFLOAT;
+    case Pixel::RGB32F:
+      return Graphics::Format::R32G32B32_SFLOAT;
+    case Pixel::R11G11B10F:
+      return Graphics::Format::R11G11B10_UFLOAT_PACK32;
+
+    case Pixel::CHROMINANCE_U:
+      return Graphics::Format::L8;
+    case Pixel::CHROMINANCE_V:
+      return Graphics::Format::L8;
+  }
+  return Graphics::Format::UNDEFINED;
+}
+
+/**
+ * @brief Converts DALi texture type to Graphics::TextureType.
+ *
+ * @param[in] type Dali::Texture::Type.
+ * @return converted Graphics::TextureType.
+ */
+constexpr Graphics::TextureType ConvertTextureType(Dali::TextureType::Type type)
+{
+  switch(type)
+  {
+    case Dali::TextureType::TEXTURE_2D:
+      return Graphics::TextureType::TEXTURE_2D;
+    case Dali::TextureType::TEXTURE_CUBE:
+      return Graphics::TextureType::TEXTURE_CUBEMAP;
+  }
+  return Graphics::TextureType::TEXTURE_2D;
+}
+
+} // namespace Graphics
+} // namespace Dali
+
+#endif // DALI_GRAPHICS_TEXTURE_UPLOAD_INTERFACE_H
\ No newline at end of file
index 3e4f3d1..1059719 100644 (file)
@@ -13,6 +13,7 @@ SET( platform_abstraction_src_files
    ${platform_abstraction_src_dir}/profiling.cpp
    ${platform_abstraction_src_dir}/render-task-list-integ.cpp
    ${platform_abstraction_src_dir}/scene.cpp
+   ${platform_abstraction_src_dir}/texture-integ.cpp
    ${platform_abstraction_src_dir}/trace.cpp
 )
 
@@ -50,6 +51,7 @@ SET( platform_abstraction_header_files
    ${platform_abstraction_src_dir}/resource-policies.h
    ${platform_abstraction_src_dir}/resource-types.h
    ${platform_abstraction_src_dir}/scene.h
+   ${platform_abstraction_src_dir}/texture-integ.h
    ${platform_abstraction_src_dir}/trace.h
 )
 
diff --git a/dali/integration-api/texture-integ.cpp b/dali/integration-api/texture-integ.cpp
new file mode 100644 (file)
index 0000000..f36b69a
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2023 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// FILE HEADER
+#include <dali/integration-api/texture-integ.h>
+
+// INTERNAL INCLUDES
+#include <dali/internal/event/rendering/texture-impl.h>
+
+namespace Dali::Integration
+{
+Dali::Texture NewTextureWithResourceId(Dali::TextureType::Type type, uint32_t resourceId)
+{
+  Internal::TexturePtr texture = Internal::Texture::New(type, resourceId);
+  return Texture(texture.Get());
+}
+
+uint32_t GetTextureResourceId(Dali::Texture texture)
+{
+  return GetImplementation(texture).GetResourceId();
+}
+
+Dali::TextureType::Type GetTextureType(Dali::Texture texture)
+{
+  return GetImplementation(texture).GetTextureType();
+}
+
+void SetTextureSize(Dali::Texture texture, const Dali::ImageDimensions& size)
+{
+  GetImplementation(texture).SetSize(size);
+}
+
+void SetTexturePixelFormat(Dali::Texture texture, Dali::Pixel::Format format)
+{
+  GetImplementation(texture).SetPixelFormat(format);
+}
+
+} // namespace Dali::Integration
diff --git a/dali/integration-api/texture-integ.h b/dali/integration-api/texture-integ.h
new file mode 100644 (file)
index 0000000..54bbb46
--- /dev/null
@@ -0,0 +1,78 @@
+#ifndef DALI_TEXTURE_INTEG_H
+#define DALI_TEXTURE_INTEG_H
+
+/*
+ * Copyright (c) 2023 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <cstdint> ///< for uint32_t
+
+// INTERNAL INCLUDES
+#include <dali/public-api/images/image-operations.h>
+#include <dali/public-api/rendering/texture.h>
+
+namespace Dali::Integration
+{
+/**
+ * @brief Create new Dali::Texture with resourceId that Graphics::Controller can use.
+ *
+ * @SINCE_2_2.37
+ * @param[in] type The type of the texture
+ * @param[in] resourceId The unique id of this texture combinded with Graphics::Controller.
+ * @return A handle to a newly allocated Texture
+ */
+DALI_CORE_API Dali::Texture NewTextureWithResourceId(Dali::TextureType::Type type, uint32_t resourceId);
+
+/**
+ * @brief Get the resource id for this texture.
+ *
+ * @SINCE_2_2.37
+ * @param[in] texture The texture to get resource id.
+ * @return The resource id what given texture has.
+ */
+DALI_CORE_API uint32_t GetTextureResourceId(Dali::Texture texture);
+
+/**
+ * @brief Get the type for this texture.
+ *
+ * @SINCE_2_2.37
+ * @param[in] texture The texture to get texture type.
+ * @return The texture type what given texture has.
+ */
+DALI_CORE_API Dali::TextureType::Type GetTextureType(Dali::Texture texture);
+
+/**
+ * @brief Set the size of texture.
+ *
+ * @SINCE_2_2.37
+ * @param[in,out] texture The texture to set size.
+ * @param[in] size The size of texture to set.
+ */
+DALI_CORE_API void SetTextureSize(Dali::Texture texture, const Dali::ImageDimensions& size);
+
+/**
+ * @brief Set the pixel format of texture.
+ *
+ * @SINCE_2_2.37
+ * @param[in,out] texture The texture to set format.
+ * @param[in] format The format of texture to set.
+ */
+DALI_CORE_API void SetTexturePixelFormat(Dali::Texture texture, Dali::Pixel::Format format);
+
+} // namespace Dali::Integration
+
+#endif // DALI_TEXTURE_INTEG_H
index e2ba0a6..6a320da 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_TYPE_ABSTRACTION_ENUMS_H
 
 /*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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.
@@ -73,6 +73,10 @@ template<>
 struct ParameterType<Dali::DevelCameraActor::ProjectionDirection> : public BasicType<Dali::DevelCameraActor::ProjectionDirection>
 {
 };
+template<>
+struct ParameterType<Dali::Pixel::Format> : public BasicType<Dali::Pixel::Format>
+{
+};
 
 } //namespace Internal
 
index e582632..7488fc5 100644 (file)
@@ -43,6 +43,13 @@ TexturePtr Texture::New(NativeImageInterface& nativeImageInterface)
   return texture;
 }
 
+TexturePtr Texture::New(TextureType::Type type, uint32_t resourceId)
+{
+  TexturePtr texture(new Texture(type, resourceId));
+  texture->Initialize();
+  return texture;
+}
+
 Render::TextureKey Texture::GetRenderTextureKey() const
 {
   return mTextureKey;
@@ -55,6 +62,7 @@ Texture::Texture(TextureType::Type type, Pixel::Format format, ImageDimensions s
   mSize(size),
   mType(type),
   mFormat(format),
+  mResourceId(0u),
   mUseUploadedParameter(mSize.GetWidth() == 0u && mSize.GetHeight() == 0u && mFormat == Pixel::INVALID)
 {
 }
@@ -66,10 +74,23 @@ Texture::Texture(NativeImageInterfacePtr nativeImageInterface)
   mSize(nativeImageInterface->GetWidth(), nativeImageInterface->GetHeight()),
   mType(TextureType::TEXTURE_2D),
   mFormat(Pixel::RGB888),
+  mResourceId(0u),
   mUseUploadedParameter(false)
 {
 }
 
+Texture::Texture(TextureType::Type type, uint32_t resourceId)
+: mEventThreadServices(EventThreadServices::Get()),
+  mTextureKey{},
+  mNativeImage(),
+  mSize(),
+  mType(type),
+  mFormat(Pixel::INVALID),
+  mResourceId(resourceId),
+  mUseUploadedParameter(true)
+{
+}
+
 void Texture::Initialize()
 {
   if(EventThreadServices::IsCoreRunning())
@@ -80,7 +101,14 @@ void Texture::Initialize()
     }
     else
     {
-      mTextureKey = Render::Texture::NewKey(mType, mFormat, mSize);
+      if(mResourceId != 0u)
+      {
+        mTextureKey = Render::Texture::NewKey(mType, mResourceId);
+      }
+      else
+      {
+        mTextureKey = Render::Texture::NewKey(mType, mFormat, mSize);
+      }
     }
 
     AddTextureMessage(mEventThreadServices.GetUpdateManager(), mTextureKey);
@@ -148,6 +176,10 @@ bool Texture::UploadSubPixelData(PixelDataPtr pixelData,
     {
       DALI_LOG_ERROR("OpenGL ES does not support uploading data to native texture\n");
     }
+    else if(mResourceId != 0u)
+    {
+      DALI_LOG_ERROR("ResourceId using case does not support uploading data\n");
+    }
     else
     {
       uint32_t pixelDataSize = dataWidth * dataHeight;
@@ -192,16 +224,16 @@ bool Texture::UploadSubPixelData(PixelDataPtr pixelData,
             }
 
             //Parameters are correct. Send message to upload data to the texture
-            UploadParams params = {static_cast<uint32_t>(dataXOffset),
-                                   static_cast<uint32_t>(dataYOffset),
-                                   static_cast<uint16_t>(dataWidth),
-                                   static_cast<uint16_t>(dataHeight),
-                                   static_cast<uint16_t>(layer),
-                                   static_cast<uint16_t>(mipmap),
-                                   static_cast<uint16_t>(xOffset),
-                                   static_cast<uint16_t>(yOffset),
-                                   static_cast<uint16_t>(width),
-                                   static_cast<uint16_t>(height)};
+            Graphics::UploadParams params = {static_cast<uint32_t>(dataXOffset),
+                                             static_cast<uint32_t>(dataYOffset),
+                                             static_cast<uint16_t>(dataWidth),
+                                             static_cast<uint16_t>(dataHeight),
+                                             static_cast<uint16_t>(layer),
+                                             static_cast<uint16_t>(mipmap),
+                                             static_cast<uint16_t>(xOffset),
+                                             static_cast<uint16_t>(yOffset),
+                                             static_cast<uint16_t>(width),
+                                             static_cast<uint16_t>(height)};
             UploadTextureMessage(mEventThreadServices.GetUpdateManager(), mTextureKey, pixelData, params);
 
             result = true;
@@ -241,6 +273,34 @@ Pixel::Format Texture::GetPixelFormat() const
   return mFormat;
 }
 
+uint32_t Texture::GetResourceId() const
+{
+  return mResourceId;
+}
+
+Dali::TextureType::Type Texture::GetTextureType() const
+{
+  return mType;
+}
+
+void Texture::SetSize(const ImageDimensions& size)
+{
+  mSize = size;
+  if(EventThreadServices::IsCoreRunning() && mTextureKey)
+  {
+    SetTextureSizeMessage(mEventThreadServices.GetUpdateManager(), mTextureKey, mSize);
+  }
+}
+
+void Texture::SetPixelFormat(Pixel::Format format)
+{
+  mFormat = format;
+  if(EventThreadServices::IsCoreRunning() && mTextureKey)
+  {
+    SetTextureFormatMessage(mEventThreadServices.GetUpdateManager(), mTextureKey, mFormat);
+  }
+}
+
 bool Texture::IsNative() const
 {
   return static_cast<bool>(mNativeImage);
index f97fd5a..4d3a133 100644 (file)
@@ -40,23 +40,6 @@ class Texture : public BaseObject
 {
 public:
   /**
-   * @brief Structure used to pass parameters to the Upload method
-   */
-  struct UploadParams
-  {
-    uint32_t dataXOffset; ///< Specifies a pixeldata offset in the x direction within the pixeldata buffer.
-    uint32_t dataYOffset; ///< Specifies a pixeldata offset in the y direction within the pixeldata buffer.
-    uint16_t dataWidth;   ///< Specifies the width of the pixeldata subimage.
-    uint16_t dataHeight;  ///< Specifies the height of the pixeldata subimage.
-    uint16_t layer;       ///< Specifies the layer of a cube map or array texture
-    uint16_t mipmap;      ///< Specifies the level-of-detail number. Level 0 is the base image level. Level n is the nth mipmap reduction image.
-    uint16_t xOffset;     ///< Specifies a texel offset in the x direction within the texture array.
-    uint16_t yOffset;     ///< Specifies a texel offset in the y direction within the texture array.
-    uint16_t width;       ///< Specifies the width of the texture subimage
-    uint16_t height;      ///< Specifies the height of the texture subimage.
-  };
-
-  /**
    * @brief Create a new Texture.
    *
    * @param[in] type The type of the texture
@@ -75,6 +58,15 @@ public:
   static TexturePtr New(NativeImageInterface& nativeImageInterface);
 
   /**
+   * @brief Create a new Texture with resourceId.
+   *
+   * @param[in] type The type of the texture
+   * @param[in] resourceId The unique id of this texture combind with TextureUploadManager
+   * @return A smart-pointer to the newly allocated Texture.
+   */
+  static TexturePtr New(TextureType::Type type, uint32_t resourceId);
+
+  /**
    * @brief Get the texture render object
    *
    * @return the texture render object
@@ -142,6 +134,26 @@ public:
   Pixel::Format GetPixelFormat() const;
 
   /**
+   * @copydoc Dali::Integration::GetTextureResourceId()
+   */
+  uint32_t GetResourceId() const;
+
+  /**
+   * @copydoc Dali::Integration::GetTextureType()
+   */
+  Dali::TextureType::Type GetTextureType() const;
+
+  /**
+   * @copydoc Dali::Integration::SetTextureSize()
+   */
+  void SetSize(const ImageDimensions& size);
+
+  /**
+   * @copydoc Dali::Integration::SetTexturePixelFormat()
+   */
+  void SetPixelFormat(Pixel::Format format);
+
+  /**
    * @brief Determine if the texture is a native image
    *
    * @return true if the texture has been initialized with a native image
@@ -172,6 +184,13 @@ private: // implementation
   Texture(NativeImageInterfacePtr nativeImageInterface);
 
   /**
+   * Constructor from resource id
+   * @param[in] type The type of the texture
+   * @param[in] resourceId The resouce id for texture upload manager using
+   */
+  Texture(TextureType::Type type, uint32_t resourceId);
+
+  /**
    * Second stage initialization of the Texture
    */
   void Initialize();
@@ -195,6 +214,8 @@ private:                                               // data
   Dali::TextureType::Type mType;        ///< Texture type (cached)
   Pixel::Format           mFormat;      ///< Pixel format
 
+  uint32_t mResourceId;
+
   bool mUseUploadedParameter : 1; ///< Whether ths texture size and format depend on uploaded image or not.
 };
 
index b0198a3..70e3d82 100644 (file)
@@ -274,7 +274,7 @@ void RenderManager::AddTexture(const Render::TextureKey& textureKey)
 {
   DALI_ASSERT_DEBUG(textureKey && "Trying to add empty texture key");
 
-  textureKey->Initialize(mImpl->graphicsController);
+  textureKey->Initialize(mImpl->graphicsController, *this);
   mImpl->textureContainer.PushBack(textureKey);
   mImpl->updatedTextures.PushBack(textureKey);
 }
@@ -293,7 +293,7 @@ void RenderManager::RemoveTexture(const Render::TextureKey& textureKey)
   }
 }
 
-void RenderManager::UploadTexture(const Render::TextureKey& textureKey, PixelDataPtr pixelData, const Texture::UploadParams& params)
+void RenderManager::UploadTexture(const Render::TextureKey& textureKey, PixelDataPtr pixelData, const Graphics::UploadParams& params)
 {
   DALI_ASSERT_DEBUG(textureKey && "Trying to upload to empty texture key");
   textureKey->Upload(pixelData, params);
@@ -309,6 +309,23 @@ void RenderManager::GenerateMipmaps(const Render::TextureKey& textureKey)
   mImpl->updatedTextures.PushBack(textureKey);
 }
 
+void RenderManager::SetTextureSize(const Render::TextureKey& textureKey, const Dali::ImageDimensions& size)
+{
+  DALI_ASSERT_DEBUG(textureKey && "Trying to set size on empty texture key");
+  textureKey->SetWidth(size.GetWidth());
+  textureKey->SetHeight(size.GetHeight());
+
+  mImpl->updatedTextures.PushBack(textureKey);
+}
+
+void RenderManager::SetTextureFormat(const Render::TextureKey& textureKey, Dali::Pixel::Format pixelFormat)
+{
+  DALI_ASSERT_DEBUG(textureKey && "Trying to set pixel format on empty texture key");
+  textureKey->SetPixelFormat(pixelFormat);
+
+  mImpl->updatedTextures.PushBack(textureKey);
+}
+
 void RenderManager::SetTextureUpdated(const Render::TextureKey& textureKey)
 {
   DALI_ASSERT_DEBUG(textureKey && "Trying to set updated on empty texture key");
index eb23b29..9793f8a 100644 (file)
@@ -27,6 +27,8 @@
 #include <dali/internal/render/renderers/render-vertex-buffer.h>
 #include <dali/public-api/math/rect.h>
 
+#include <dali/graphics-api/graphics-texture-upload-helper.h> // for Graphics::UploadParams
+
 namespace Dali
 {
 namespace Integration
@@ -252,7 +254,7 @@ public:
    * @param[in] pixelData The pixel data object
    * @param[in] params The parameters for the upload
    */
-  void UploadTexture(const Render::TextureKey& texture, PixelDataPtr pixelData, const Texture::UploadParams& params);
+  void UploadTexture(const Render::TextureKey& texture, PixelDataPtr pixelData, const Graphics::UploadParams& params);
 
   /**
    * Generates mipmaps for a given texture
@@ -261,6 +263,20 @@ public:
   void GenerateMipmaps(const Render::TextureKey& texture);
 
   /**
+   * Set the texture size for a given texture
+   * @param[in] texture The texture
+   * @param[in] size The texture size
+   */
+  void SetTextureSize(const Render::TextureKey& texture, const Dali::ImageDimensions& size);
+
+  /**
+   * Set the texture pixel format for a given texture
+   * @param[in] texture The texture
+   * @param[in] pixelFormat The texture pixel format
+   */
+  void SetTextureFormat(const Render::TextureKey& texture, Dali::Pixel::Format pixelFormat);
+
+  /**
    * Sets the updated flag of a texture
    * @param[in] texture The updated texture
    */
index a38ede9..26f2699 100644 (file)
@@ -23,6 +23,7 @@
 // INTERNAL INCLUDES
 #include <dali/integration-api/debug.h>
 #include <dali/internal/common/memory-pool-object-allocator.h>
+#include <dali/internal/render/common/render-manager.h>
 
 namespace Dali
 {
@@ -43,174 +44,6 @@ MemoryPoolObjectAllocator<Texture>& GetTextureMemoryPool()
   return gTextureMemoryPool;
 }
 
-/**
- * Converts DALi pixel format to Graphics::Format
- * @param format
- * @return
- */
-constexpr Graphics::Format ConvertPixelFormat(Pixel::Format format)
-{
-  switch(format)
-  {
-    case Pixel::INVALID:
-      return Graphics::Format::UNDEFINED;
-    case Pixel::A8:
-      return Graphics::Format::R8_UNORM;
-
-    case Pixel::L8:
-      return Graphics::Format::L8;
-    case Pixel::LA88:
-      return Graphics::Format::L8A8;
-    case Pixel::RGB565:
-      return Graphics::Format::R5G6B5_UNORM_PACK16;
-    case Pixel::BGR565:
-      return Graphics::Format::B5G6R5_UNORM_PACK16;
-    case Pixel::RGBA4444:
-      return Graphics::Format::R4G4B4A4_UNORM_PACK16;
-
-    case Pixel::BGRA4444:
-      return Graphics::Format::B4G4R4A4_UNORM_PACK16;
-    case Pixel::RGBA5551:
-      return Graphics::Format::R5G5B5A1_UNORM_PACK16;
-    case Pixel::BGRA5551:
-      return Graphics::Format::B5G5R5A1_UNORM_PACK16;
-    case Pixel::RGB888:
-      return Graphics::Format::R8G8B8_UNORM;
-    case Pixel::RGB8888:
-      return Graphics::Format::R8G8B8A8_UNORM;
-    case Pixel::BGR8888:
-      return Graphics::Format::B8G8R8A8_UNORM;
-    case Pixel::RGBA8888:
-      return Graphics::Format::R8G8B8A8_UNORM;
-    case Pixel::BGRA8888:
-      return Graphics::Format::B8G8R8A8_UNORM;
-
-    case Pixel::DEPTH_UNSIGNED_INT:
-      return Graphics::Format::D16_UNORM;
-    case Pixel::DEPTH_FLOAT:
-      return Graphics::Format::D32_SFLOAT;
-    case Pixel::DEPTH_STENCIL:
-      return Graphics::Format::D24_UNORM_S8_UINT;
-
-    // EAC
-    case Pixel::COMPRESSED_R11_EAC:
-      return Graphics::Format::EAC_R11_UNORM_BLOCK;
-    case Pixel::COMPRESSED_SIGNED_R11_EAC:
-      return Graphics::Format::EAC_R11_SNORM_BLOCK;
-    case Pixel::COMPRESSED_RG11_EAC:
-      return Graphics::Format::EAC_R11G11_UNORM_BLOCK;
-    case Pixel::COMPRESSED_SIGNED_RG11_EAC:
-      return Graphics::Format::EAC_R11G11_SNORM_BLOCK;
-
-    // ETC
-    case Pixel::COMPRESSED_RGB8_ETC2:
-      return Graphics::Format::ETC2_R8G8B8_UNORM_BLOCK;
-    case Pixel::COMPRESSED_SRGB8_ETC2:
-      return Graphics::Format::ETC2_R8G8B8_SRGB_BLOCK;
-
-    case Pixel::COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
-      return Graphics::Format::ETC2_R8G8B8A1_UNORM_BLOCK; // no 'punchthrough' format
-
-    case Pixel::COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
-      return Graphics::Format::ETC2_R8G8B8A1_SRGB_BLOCK; // no 'punchthrough' format
-
-    case Pixel::COMPRESSED_RGBA8_ETC2_EAC:
-      return Graphics::Format::ETC2_R8G8B8A8_UNORM_BLOCK;
-
-    case Pixel::COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
-      return Graphics::Format::ETC2_R8G8B8A8_SRGB_BLOCK;
-
-    case Pixel::COMPRESSED_RGB8_ETC1:
-      return Graphics::Format::ETC2_R8G8B8_UNORM_BLOCK; // doesn't seem to be supported at all
-
-    case Pixel::COMPRESSED_RGB_PVRTC_4BPPV1:
-      return Graphics::Format::PVRTC1_4BPP_UNORM_BLOCK_IMG; // or SRGB?
-
-    // ASTC
-    case Pixel::COMPRESSED_RGBA_ASTC_4x4_KHR:
-      return Graphics::Format::ASTC_4x4_UNORM_BLOCK; // or SRGB?
-    case Pixel::COMPRESSED_RGBA_ASTC_5x4_KHR:
-      return Graphics::Format::ASTC_5x4_UNORM_BLOCK;
-    case Pixel::COMPRESSED_RGBA_ASTC_5x5_KHR:
-      return Graphics::Format::ASTC_5x5_UNORM_BLOCK;
-    case Pixel::COMPRESSED_RGBA_ASTC_6x5_KHR:
-      return Graphics::Format::ASTC_6x5_UNORM_BLOCK;
-    case Pixel::COMPRESSED_RGBA_ASTC_6x6_KHR:
-      return Graphics::Format::ASTC_6x6_UNORM_BLOCK;
-    case Pixel::COMPRESSED_RGBA_ASTC_8x5_KHR:
-      return Graphics::Format::ASTC_8x5_UNORM_BLOCK;
-    case Pixel::COMPRESSED_RGBA_ASTC_8x6_KHR:
-      return Graphics::Format::ASTC_8x6_UNORM_BLOCK;
-    case Pixel::COMPRESSED_RGBA_ASTC_8x8_KHR:
-      return Graphics::Format::ASTC_8x8_UNORM_BLOCK;
-    case Pixel::COMPRESSED_RGBA_ASTC_10x5_KHR:
-      return Graphics::Format::ASTC_10x5_UNORM_BLOCK;
-    case Pixel::COMPRESSED_RGBA_ASTC_10x6_KHR:
-      return Graphics::Format::ASTC_10x6_UNORM_BLOCK;
-    case Pixel::COMPRESSED_RGBA_ASTC_10x8_KHR:
-      return Graphics::Format::ASTC_10x8_UNORM_BLOCK;
-    case Pixel::COMPRESSED_RGBA_ASTC_10x10_KHR:
-      return Graphics::Format::ASTC_10x10_UNORM_BLOCK;
-    case Pixel::COMPRESSED_RGBA_ASTC_12x10_KHR:
-      return Graphics::Format::ASTC_12x10_UNORM_BLOCK;
-    case Pixel::COMPRESSED_RGBA_ASTC_12x12_KHR:
-      return Graphics::Format::ASTC_12x12_UNORM_BLOCK;
-    case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
-      return Graphics::Format::ASTC_4x4_SRGB_BLOCK; // not type with alpha, but likely to use SRGB
-    case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:
-      return Graphics::Format::ASTC_5x4_SRGB_BLOCK;
-    case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:
-      return Graphics::Format::ASTC_5x5_SRGB_BLOCK;
-    case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:
-      return Graphics::Format::ASTC_6x5_SRGB_BLOCK;
-    case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:
-      return Graphics::Format::ASTC_6x6_SRGB_BLOCK;
-    case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:
-      return Graphics::Format::ASTC_8x5_SRGB_BLOCK;
-    case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:
-      return Graphics::Format::ASTC_8x6_UNORM_BLOCK;
-    case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:
-      return Graphics::Format::ASTC_8x8_SRGB_BLOCK;
-    case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:
-      return Graphics::Format::ASTC_10x5_SRGB_BLOCK;
-    case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:
-      return Graphics::Format::ASTC_10x6_SRGB_BLOCK;
-    case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:
-      return Graphics::Format::ASTC_10x8_SRGB_BLOCK;
-    case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:
-      return Graphics::Format::ASTC_10x10_SRGB_BLOCK;
-    case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:
-      return Graphics::Format::ASTC_12x10_SRGB_BLOCK;
-    case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:
-      return Graphics::Format::ASTC_12x12_SRGB_BLOCK;
-
-    case Pixel::RGB16F:
-      return Graphics::Format::R16G16B16_SFLOAT;
-    case Pixel::RGB32F:
-      return Graphics::Format::R32G32B32_SFLOAT;
-    case Pixel::R11G11B10F:
-      return Graphics::Format::R11G11B10_UFLOAT_PACK32;
-
-    case Pixel::CHROMINANCE_U:
-      return Graphics::Format::L8;
-    case Pixel::CHROMINANCE_V:
-      return Graphics::Format::L8;
-  }
-  return Graphics::Format::UNDEFINED;
-}
-
-constexpr Graphics::TextureType ConvertType(Texture::Type type)
-{
-  switch(type)
-  {
-    case TextureType::TEXTURE_2D:
-      return Graphics::TextureType::TEXTURE_2D;
-    case TextureType::TEXTURE_CUBE:
-      return Graphics::TextureType::TEXTURE_CUBEMAP;
-  }
-  return Graphics::TextureType::TEXTURE_2D;
-}
-
 } //Unnamed namespace
 
 TextureKey Texture::NewKey(Type type, Pixel::Format format, ImageDimensions size)
@@ -231,6 +64,15 @@ TextureKey Texture::NewKey(NativeImageInterfacePtr nativeImageInterface)
   return TextureKey(key);
 }
 
+TextureKey Texture::NewKey(Type type, uint32_t resourceId)
+{
+  void* ptr = GetTextureMemoryPool().AllocateRawThreadSafe();
+  auto  key = GetTextureMemoryPool().GetKeyFromPtr(static_cast<Texture*>(ptr));
+  new(ptr) Texture(type, resourceId);
+
+  return TextureKey(key);
+}
+
 Texture::Texture(Type type, Pixel::Format format, ImageDimensions size)
 : mGraphicsController(nullptr),
   mGraphicsTexture(nullptr),
@@ -239,6 +81,7 @@ Texture::Texture(Type type, Pixel::Format format, ImageDimensions size)
   mPixelFormat(format),
   mWidth(size.GetWidth()),
   mHeight(size.GetHeight()),
+  mResourceId(0u),
   mType(type),
   mHasAlpha(HasAlpha(format)),
   mUpdated(true),
@@ -254,6 +97,7 @@ Texture::Texture(NativeImageInterfacePtr nativeImageInterface)
   mPixelFormat(Pixel::RGBA8888),
   mWidth(static_cast<uint16_t>(nativeImageInterface->GetWidth())),   // ignoring overflow, not happening in practice
   mHeight(static_cast<uint16_t>(nativeImageInterface->GetHeight())), // ignoring overflow, not happening in practice
+  mResourceId(0u),
   mType(TextureType::TEXTURE_2D),
   mHasAlpha(nativeImageInterface->RequiresBlending()),
   mUpdated(true),
@@ -261,6 +105,22 @@ Texture::Texture(NativeImageInterfacePtr nativeImageInterface)
 {
 }
 
+Texture::Texture(Type type, uint32_t resourceId)
+: mGraphicsController(nullptr),
+  mGraphicsTexture(nullptr),
+  mNativeImage(),
+  mSampler(),
+  mPixelFormat(Pixel::INVALID),
+  mWidth(0u),
+  mHeight(0u),
+  mResourceId(resourceId),
+  mType(type),
+  mHasAlpha(true), ///< Since we don't assume what kind of texture will be uploaded in this case.
+  mUpdated(true),
+  mUseUploadedParameter(true)
+{
+}
+
 Texture::~Texture() = default;
 
 void Texture::operator delete(void* ptr)
@@ -273,25 +133,64 @@ Render::Texture* Texture::Get(TextureKey::KeyType key)
   return GetTextureMemoryPool().GetPtrFromKey(key);
 }
 
-void Texture::Initialize(Graphics::Controller& graphicsController)
+void Texture::Initialize(Graphics::Controller& graphicsController, SceneGraph::RenderManager& renderManager)
 {
   mGraphicsController = &graphicsController;
+  mRenderManager      = &renderManager;
   if(mNativeImage)
   {
     Create(static_cast<uint32_t>(Graphics::TextureUsageFlagBits::SAMPLE));
   }
+
+  if(mResourceId != 0u && mGraphicsController->GetTextureFromResourceId(mResourceId))
+  {
+    // Take ownership from graphics controller
+    mGraphicsTexture = std::move(mGraphicsController->ReleaseTextureFromResourceId(mResourceId));
+    // Now we take on the Graphics::Texture ownership. We don't need to keep mResourceId anymore.
+    mResourceId = 0u;
+  }
 }
 
 void Texture::Destroy()
 {
+  if(mResourceId != 0u && mGraphicsTexture.get() == nullptr)
+  {
+    // We still don't take texture ownership from controller before.
+    // Discard graphics object now.
+    mGraphicsController->DiscardTextureFromResourceId(mResourceId);
+    mResourceId = 0u;
+  }
+
   mGraphicsTexture.reset();
 }
 
-Graphics::Texture* Texture::GetGraphicsObject() const
+Graphics::Texture* Texture::GetGraphicsObject()
 {
-  DALI_LOG_INFO(gTextureFilter, Debug::General, "SC::Texture(%p)::GetGraphicsObject() = %p\n", this, mGraphicsTexture.get());
+  if(mResourceId != 0u && mGraphicsTexture.get() == nullptr)
+  {
+    // The ownership of Graphics::Texture is on Graphics::Controller. Ask to controller.
+    Graphics::Texture* graphicsTexturePtr = nullptr;
+    if(mGraphicsController)
+    {
+      graphicsTexturePtr = mGraphicsController->GetTextureFromResourceId(mResourceId);
+
+      if(graphicsTexturePtr)
+      {
+        // Take ownership from graphics controller
+        mGraphicsTexture = std::move(mGraphicsController->ReleaseTextureFromResourceId(mResourceId));
+        // (Partial update) Do not make mResourceId as 0 until we update mLatestUsedGraphicsTexture.
+      }
+    }
+    DALI_LOG_INFO(gTextureFilter, Debug::General, "SC::Texture(%p)::GetGraphicsObject() = %p [with resource id : %u]\n", this, graphicsTexturePtr, mResourceId);
+
+    return graphicsTexturePtr;
+  }
+  else
+  {
+    DALI_LOG_INFO(gTextureFilter, Debug::General, "SC::Texture(%p)::GetGraphicsObject() = %p\n", this, mGraphicsTexture.get());
 
-  return mGraphicsTexture.get();
+    return mGraphicsTexture.get();
+  }
 }
 
 void Texture::Create(Graphics::TextureUsageFlags usage)
@@ -303,9 +202,9 @@ void Texture::CreateWithData(Graphics::TextureUsageFlags usage, uint8_t* data, u
 {
   auto createInfo = Graphics::TextureCreateInfo();
   createInfo
-    .SetTextureType(ConvertType(mType))
+    .SetTextureType(Dali::Graphics::ConvertTextureType(mType))
     .SetUsageFlags(usage)
-    .SetFormat(ConvertPixelFormat(mPixelFormat))
+    .SetFormat(Dali::Graphics::ConvertPixelFormat(mPixelFormat))
     .SetSize({mWidth, mHeight})
     .SetLayout(Graphics::TextureLayout::LINEAR)
     .SetData(data)
@@ -316,9 +215,10 @@ void Texture::CreateWithData(Graphics::TextureUsageFlags usage, uint8_t* data, u
   mGraphicsTexture = mGraphicsController->CreateTexture(createInfo, std::move(mGraphicsTexture));
 }
 
-void Texture::Upload(PixelDataPtr pixelData, const Internal::Texture::UploadParams& params)
+void Texture::Upload(PixelDataPtr pixelData, const Graphics::UploadParams& params)
 {
   DALI_ASSERT_ALWAYS(!mNativeImage);
+  DALI_ASSERT_ALWAYS(mResourceId == 0u);
 
   const uint32_t srcStride = pixelData->GetStride();
   uint32_t       srcOffset = 0u;
@@ -392,7 +292,7 @@ void Texture::Upload(PixelDataPtr pixelData, const Internal::Texture::UploadPara
   info.srcOffset    = srcOffset;
   info.srcSize      = srcSize;
   info.srcStride    = srcStride;
-  info.srcFormat    = ConvertPixelFormat(uploadedPixelFormat);
+  info.srcFormat    = Dali::Graphics::ConvertPixelFormat(uploadedPixelFormat);
 
   mUpdatedArea = Rect<uint16_t>(params.xOffset, params.yOffset, params.width, params.height);
 
@@ -415,6 +315,19 @@ bool Texture::HasAlphaChannel() const
   return alpha;
 }
 
+bool Texture::IsGraphicsObjectChanged()
+{
+  return mLatestUsedGraphicsTexture != GetGraphicsObject();
+}
+
+void Texture::NotifyTextureUpdated()
+{
+  if(mRenderManager)
+  {
+    mRenderManager->SetTextureUpdated(TextureKey(GetTextureMemoryPool().GetKeyFromPtr(this)));
+  }
+}
+
 void Texture::GenerateMipmaps()
 {
   if(!mGraphicsTexture)
@@ -428,6 +341,17 @@ void Texture::GenerateMipmaps()
 void Texture::OnRenderFinished()
 {
   SetUpdated(false);
+
+  if(mResourceId != 0u)
+  {
+    mLatestUsedGraphicsTexture = GetGraphicsObject();
+    if(mLatestUsedGraphicsTexture != nullptr)
+    {
+      // We don't need to keep mResourceId anymore.
+      mResourceId = 0u;
+    }
+  }
+
   mUpdatedArea = Rect<uint16_t>{0, 0, 0, 0};
 }
 
index 8895cfc..bbe7c86 100644 (file)
@@ -28,6 +28,7 @@
 
 #include <dali/graphics-api/graphics-controller.h>
 #include <dali/graphics-api/graphics-texture-create-info.h>
+#include <dali/graphics-api/graphics-texture-upload-helper.h>
 #include <dali/graphics-api/graphics-texture.h>
 #include <dali/graphics-api/graphics-types.h>
 #include <dali/internal/event/rendering/texture-impl.h>
@@ -37,6 +38,11 @@ namespace Dali
 {
 namespace Internal
 {
+namespace SceneGraph
+{
+class RenderManager;
+} // namespace SceneGraph
+
 namespace Render
 {
 struct Sampler;
@@ -57,6 +63,11 @@ public:
   static TextureKey NewKey(NativeImageInterfacePtr nativeImageInterface);
 
   /**
+   * Factory method to return a new texture accessed by key.
+   */
+  static TextureKey NewKey(Type type, uint32_t resourceId);
+
+  /**
    * Constructor
    * @param[in] type The type of the texture
    * @param[in] format The format of the pixel data
@@ -71,6 +82,13 @@ public:
   explicit Texture(NativeImageInterfacePtr nativeImageInterface);
 
   /**
+   * Constructor from resource id
+   * @param[in] type The type of the texture
+   * @param[in] resourceId The resouce id for texture upload manager using
+   */
+  explicit Texture(Type type, uint32_t resourceId);
+
+  /**
    * Destructor
    */
   ~Texture();
@@ -101,8 +119,9 @@ public:
    * Stores the graphics controller for use when required.
    *
    * @param[in] graphicsController The graphics controller to use
+   * @param[in] renderManager The render manager to be used.
    */
-  void Initialize(Graphics::Controller& graphicsController);
+  void Initialize(Graphics::Controller& graphicsController, SceneGraph::RenderManager& renderManager);
 
   /**
    * Create the texture without a buffer
@@ -120,7 +139,7 @@ public:
    * @param[in] pixelData A pixel data object
    * @param[in] params Upload parameters. See UploadParams
    */
-  void Upload(PixelDataPtr pixelData, const Internal::Texture::UploadParams& params);
+  void Upload(PixelDataPtr pixelData, const Graphics::UploadParams& params);
 
   /**
    * Auto generates mipmaps for the texture
@@ -136,7 +155,7 @@ public:
   /**
    * Get the graphics object associated with this texture
    */
-  [[nodiscard]] Graphics::Texture* GetGraphicsObject() const;
+  [[nodiscard]] Graphics::Texture* GetGraphicsObject();
 
   /**
    * Get the type of the texture
@@ -178,12 +197,39 @@ public:
    * Return the height of the texture
    * @return The height of the texture
    */
-  uint32_t GetHeight() const
+  uint16_t GetHeight() const
   {
     return mHeight;
   }
 
   /**
+   * Set the pixel format of the texture
+   * @param[in] pixelFormat The pixel format of the texture data.
+   */
+  void SetPixelFormat(Pixel::Format pixelFormat)
+  {
+    mPixelFormat = pixelFormat;
+  }
+
+  /**
+   * Set the width of the texture
+   * @param[in] width The width of the texture
+   */
+  void SetWidth(uint16_t width)
+  {
+    mWidth = width;
+  }
+
+  /**
+   * Set the height of the texture
+   * @param[in] height The height of the texture
+   */
+  void SetHeight(uint16_t height)
+  {
+    mHeight = height;
+  }
+
+  /**
    * Called from RenderManager to notify the texture that current rendering pass has finished.
    */
   void OnRenderFinished();
@@ -207,6 +253,12 @@ public:
     {
       return true;
     }
+    else if(mResourceId > 0u && IsGraphicsObjectChanged())
+    {
+      // Let we make call OnRenderFinished();
+      NotifyTextureUpdated();
+      return true;
+    }
     return false;
   }
 
@@ -232,8 +284,21 @@ private:
    */
   void CreateWithData(Graphics::TextureUsageFlags usage, uint8_t* buffer, uint32_t bufferSize);
 
+  /**
+   * @brief Check whether graphics object pointer were changed what we know before.
+   *
+   * @return True if graphics object created newly. False otherwised.
+   */
+  bool IsGraphicsObjectChanged();
+
+  /**
+   * @brief Notify to RenderManager that this texture has been updated.
+   */
+  void NotifyTextureUpdated();
+
 private:
   Graphics::Controller*                  mGraphicsController;
+  SceneGraph::RenderManager*             mRenderManager;
   Graphics::UniquePtr<Graphics::Texture> mGraphicsTexture;
 
   NativeImageInterfacePtr mNativeImage; ///< Pointer to native image
@@ -245,6 +310,9 @@ private:
   uint16_t      mWidth;       ///< Width of the texture
   uint16_t      mHeight;      ///< Height of the texture
 
+  uint32_t           mResourceId;
+  Graphics::Texture* mLatestUsedGraphicsTexture{nullptr};
+
   Type mType : 3;     ///< Type of the texture
   bool mHasAlpha : 1; ///< Whether the format has an alpha channel
   bool mUpdated : 1;  ///< Whether the texture is updated
index 7e06c61..a01e9be 100644 (file)
@@ -1546,9 +1546,9 @@ void UpdateManager::RemoveTexture(const Render::TextureKey& texture)
   new(slot) DerivedType(&mImpl->renderManager, &RenderManager::RemoveTexture, texture);
 }
 
-void UpdateManager::UploadTexture(const Render::TextureKey& texture, PixelDataPtr pixelData, const Texture::UploadParams& params)
+void UpdateManager::UploadTexture(const Render::TextureKey& texture, PixelDataPtr pixelData, const Graphics::UploadParams& params)
 {
-  using DerivedType = MessageValue3<RenderManager, Render::TextureKey, PixelDataPtr, Texture::UploadParams>;
+  using DerivedType = MessageValue3<RenderManager, Render::TextureKey, PixelDataPtr, Graphics::UploadParams>;
 
   // Reserve some memory inside the message queue
   uint32_t* slot = mImpl->renderQueue.ReserveMessageSlot(mSceneGraphBuffers.GetUpdateBufferIndex(), sizeof(DerivedType));
@@ -1568,6 +1568,28 @@ void UpdateManager::GenerateMipmaps(const Render::TextureKey& texture)
   new(slot) DerivedType(&mImpl->renderManager, &RenderManager::GenerateMipmaps, texture);
 }
 
+void UpdateManager::SetTextureSize(const Render::TextureKey& texture, const Dali::ImageDimensions& size)
+{
+  using DerivedType = MessageValue2<RenderManager, Render::TextureKey, Dali::ImageDimensions>;
+
+  // Reserve some memory inside the render queue
+  uint32_t* slot = mImpl->renderQueue.ReserveMessageSlot(mSceneGraphBuffers.GetUpdateBufferIndex(), sizeof(DerivedType));
+
+  // Construct message in the render queue memory; note that delete should not be called on the return value
+  new(slot) DerivedType(&mImpl->renderManager, &RenderManager::SetTextureSize, texture, size);
+}
+
+void UpdateManager::SetTextureFormat(const Render::TextureKey& texture, Dali::Pixel::Format pixelFormat)
+{
+  using DerivedType = MessageValue2<RenderManager, Render::TextureKey, Dali::Pixel::Format>;
+
+  // Reserve some memory inside the render queue
+  uint32_t* slot = mImpl->renderQueue.ReserveMessageSlot(mSceneGraphBuffers.GetUpdateBufferIndex(), sizeof(DerivedType));
+
+  // Construct message in the render queue memory; note that delete should not be called on the return value
+  new(slot) DerivedType(&mImpl->renderManager, &RenderManager::SetTextureFormat, texture, pixelFormat);
+}
+
 void UpdateManager::AddFrameBuffer(OwnerPointer<Render::FrameBuffer>& frameBuffer)
 {
   using DerivedType = MessageValue1<RenderManager, OwnerPointer<Render::FrameBuffer>>;
index 48deab7..673ae9f 100644 (file)
@@ -50,6 +50,8 @@
 #include <dali/internal/update/rendering/scene-graph-renderer.h>    // for OwnerPointer< Renderer >
 #include <dali/internal/update/rendering/scene-graph-texture-set.h> // for OwnerPointer< TextureSet >
 
+#include <dali/graphics-api/graphics-texture-upload-helper.h> // for Graphics::UploadParams
+
 // EXTERNAL INCLUDES
 #include <cstddef>
 
@@ -560,7 +562,7 @@ public:
    * @param[in] pixelData The pixel data object
    * @param[in] params The parameters for the upload
    */
-  void UploadTexture(const Render::TextureKey& texture, PixelDataPtr pixelData, const Texture::UploadParams& params);
+  void UploadTexture(const Render::TextureKey& texture, PixelDataPtr pixelData, const Graphics::UploadParams& params);
 
   /**
    * Generates mipmaps for a texture owned by the RenderManager
@@ -569,6 +571,20 @@ public:
   void GenerateMipmaps(const Render::TextureKey& texture);
 
   /**
+   * Set the texture size owned by the RenderManager
+   * @param[in] texture The texture
+   * @param[in] size The texture size
+   */
+  void SetTextureSize(const Render::TextureKey& texture, const Dali::ImageDimensions& size);
+
+  /**
+   * Set the texture pixel format owned by the RenderManager
+   * @param[in] texture The texture
+   * @param[in] pixelFormat The texture pixel format
+   */
+  void SetTextureFormat(const Render::TextureKey& texture, Dali::Pixel::Format pixelFormat);
+
+  /**
    * Adds a framebuffer to the render manager
    * @param[in] frameBuffer The framebuffer to add
    * The framebuffer will be owned by RenderManager
@@ -1444,9 +1460,9 @@ inline void RemoveTextureMessage(UpdateManager& manager, const Render::TextureKe
   new(slot) LocalType(&manager, &UpdateManager::RemoveTexture, texture);
 }
 
-inline void UploadTextureMessage(UpdateManager& manager, Render::TextureKey texture, PixelDataPtr pixelData, const Texture::UploadParams& params)
+inline void UploadTextureMessage(UpdateManager& manager, Render::TextureKey texture, PixelDataPtr pixelData, const Graphics::UploadParams& params)
 {
-  using LocalType = MessageValue3<UpdateManager, Render::TextureKey, PixelDataPtr, Texture::UploadParams>;
+  using LocalType = MessageValue3<UpdateManager, Render::TextureKey, PixelDataPtr, Graphics::UploadParams>;
 
   // Reserve some memory inside the message queue
   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
@@ -1466,6 +1482,28 @@ inline void GenerateMipmapsMessage(UpdateManager& manager, Render::TextureKey te
   new(slot) LocalType(&manager, &UpdateManager::GenerateMipmaps, texture);
 }
 
+inline void SetTextureSizeMessage(UpdateManager& manager, Render::TextureKey texture, const Dali::ImageDimensions& size)
+{
+  using LocalType = MessageValue2<UpdateManager, Render::TextureKey, Dali::ImageDimensions>;
+
+  // Reserve some memory inside the message queue
+  uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
+
+  // Construct message in the message queue memory; note that delete should not be called on the return value
+  new(slot) LocalType(&manager, &UpdateManager::SetTextureSize, texture, size);
+}
+
+inline void SetTextureFormatMessage(UpdateManager& manager, Render::TextureKey texture, Dali::Pixel::Format pixelFormat)
+{
+  using LocalType = MessageValue2<UpdateManager, Render::TextureKey, Dali::Pixel::Format>;
+
+  // Reserve some memory inside the message queue
+  uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
+
+  // Construct message in the message queue memory; note that delete should not be called on the return value
+  new(slot) LocalType(&manager, &UpdateManager::SetTextureFormat, texture, pixelFormat);
+}
+
 inline void AddFrameBuffer(UpdateManager& manager, OwnerPointer<Render::FrameBuffer>& frameBuffer)
 {
   using LocalType = MessageValue1<UpdateManager, OwnerPointer<Render::FrameBuffer>>;