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
)
--- /dev/null
+/*
+ * 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
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
*/
#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"
*/
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)
{
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);
std::vector<TestGraphicsBuffer*> mAllocatedBuffers;
+ std::unordered_map<uint32_t, Graphics::UniquePtr<Graphics::Texture>> mTextureUploadBindMapper;
+
struct PipelineCache
{
};
#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>
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;
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");
${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
)
#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.
*/
// EXTERNAL INCLUDES
+#include <dali/public-api/common/vector-wrapper.h>
#include <memory>
-#include <vector>
// INTERNAL INCLUDES
#include "graphics-buffer-create-info.h"
#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
{
*/
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
--- /dev/null
+#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
${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
)
${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
)
--- /dev/null
+/*
+ * 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
--- /dev/null
+#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
#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.
struct ParameterType<Dali::DevelCameraActor::ProjectionDirection> : public BasicType<Dali::DevelCameraActor::ProjectionDirection>
{
};
+template<>
+struct ParameterType<Dali::Pixel::Format> : public BasicType<Dali::Pixel::Format>
+{
+};
} //namespace Internal
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;
mSize(size),
mType(type),
mFormat(format),
+ mResourceId(0u),
mUseUploadedParameter(mSize.GetWidth() == 0u && mSize.GetHeight() == 0u && mFormat == Pixel::INVALID)
{
}
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())
}
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);
{
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;
}
//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;
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);
{
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
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
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
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();
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.
};
{
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);
}
}
}
-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);
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");
#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
* @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
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
*/
// 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
{
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)
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),
mPixelFormat(format),
mWidth(size.GetWidth()),
mHeight(size.GetHeight()),
+ mResourceId(0u),
mType(type),
mHasAlpha(HasAlpha(format)),
mUpdated(true),
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),
{
}
+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)
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)
{
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)
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;
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);
return alpha;
}
+bool Texture::IsGraphicsObjectChanged()
+{
+ return mLatestUsedGraphicsTexture != GetGraphicsObject();
+}
+
+void Texture::NotifyTextureUpdated()
+{
+ if(mRenderManager)
+ {
+ mRenderManager->SetTextureUpdated(TextureKey(GetTextureMemoryPool().GetKeyFromPtr(this)));
+ }
+}
+
void Texture::GenerateMipmaps()
{
if(!mGraphicsTexture)
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};
}
#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>
{
namespace Internal
{
+namespace SceneGraph
+{
+class RenderManager;
+} // namespace SceneGraph
+
namespace Render
{
struct Sampler;
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
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();
* 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
* @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
/**
* Get the graphics object associated with this texture
*/
- [[nodiscard]] Graphics::Texture* GetGraphicsObject() const;
+ [[nodiscard]] Graphics::Texture* GetGraphicsObject();
/**
* Get the type of the texture
* 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();
{
return true;
}
+ else if(mResourceId > 0u && IsGraphicsObjectChanged())
+ {
+ // Let we make call OnRenderFinished();
+ NotifyTextureUpdated();
+ return true;
+ }
return false;
}
*/
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
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
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));
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>>;
#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>
* @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
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
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));
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>>;