X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Frender%2Frenderers%2Frender-texture.cpp;h=2a455fdea91d951076d37376565d75166ba40a49;hb=068c5d3906ac2acb845c09e339dfe346bbea89e2;hp=89366f65bf1b43bd60bcc8aa51b69283098d2fd0;hpb=716d916ef3929bbf21238c341f83817354386c22;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/render/renderers/render-texture.cpp b/dali/internal/render/renderers/render-texture.cpp index 89366f6..2a455fd 100644 --- a/dali/internal/render/renderers/render-texture.cpp +++ b/dali/internal/render/renderers/render-texture.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 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. @@ -22,6 +22,7 @@ // INTERNAL INCLUDES #include +#include namespace Dali { @@ -35,6 +36,9 @@ namespace Debug::Filter* gTextureFilter = Debug::Filter::New(Debug::Concise, false, "LOG_TEXTURE"); #endif +// Memory pool used to allocate new textures. Memory used by this pool will be released when shutting down DALi +MemoryPoolObjectAllocator gTextureMemoryPool; + /** * Converts DALi pixel format to Graphics::Format * @param format @@ -107,10 +111,10 @@ constexpr Graphics::Format ConvertPixelFormat(Pixel::Format format) return Graphics::Format::ETC2_R8G8B8A1_SRGB_BLOCK; // no 'punchthrough' format case Pixel::COMPRESSED_RGBA8_ETC2_EAC: - return Graphics::Format::ETC2_R8G8B8_UNORM_BLOCK; // doesn't seem to map onto any format + return Graphics::Format::ETC2_R8G8B8A8_UNORM_BLOCK; case Pixel::COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: - return Graphics::Format::ETC2_R8G8B8A8_SRGB_BLOCK; // doesn't seem to map onto any format + 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 @@ -148,7 +152,6 @@ constexpr Graphics::Format ConvertPixelFormat(Pixel::Format format) 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; @@ -176,12 +179,18 @@ constexpr Graphics::Format ConvertPixelFormat(Pixel::Format format) 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; } @@ -200,6 +209,24 @@ constexpr Graphics::TextureType ConvertType(Texture::Type type) } //Unnamed namespace +TextureKey Texture::NewKey(Type type, Pixel::Format format, ImageDimensions size) +{ + void* ptr = gTextureMemoryPool.AllocateRawThreadSafe(); + auto key = gTextureMemoryPool.GetKeyFromPtr(static_cast(ptr)); + new(ptr) Texture(type, format, size); + + return TextureKey(key); +} + +TextureKey Texture::NewKey(NativeImageInterfacePtr nativeImageInterface) +{ + void* ptr = gTextureMemoryPool.AllocateRawThreadSafe(); + auto key = gTextureMemoryPool.GetKeyFromPtr(static_cast(ptr)); + new(ptr) Texture(nativeImageInterface); + + return TextureKey(key); +} + Texture::Texture(Type type, Pixel::Format format, ImageDimensions size) : mGraphicsController(nullptr), mGraphicsTexture(nullptr), @@ -209,7 +236,8 @@ Texture::Texture(Type type, Pixel::Format format, ImageDimensions size) mWidth(size.GetWidth()), mHeight(size.GetHeight()), mType(type), - mHasAlpha(HasAlpha(format)) + mHasAlpha(HasAlpha(format)), + mUpdated(true) { } @@ -222,12 +250,23 @@ Texture::Texture(NativeImageInterfacePtr nativeImageInterface) mWidth(static_cast(nativeImageInterface->GetWidth())), // ignoring overflow, not happening in practice mHeight(static_cast(nativeImageInterface->GetHeight())), // ignoring overflow, not happening in practice mType(TextureType::TEXTURE_2D), - mHasAlpha(nativeImageInterface->RequiresBlending()) + mHasAlpha(nativeImageInterface->RequiresBlending()), + mUpdated(true) { } Texture::~Texture() = default; +void Texture::operator delete(void* ptr) +{ + gTextureMemoryPool.FreeThreadSafe(static_cast(ptr)); +} + +Render::Texture* Texture::Get(TextureKey::KeyType key) +{ + return gTextureMemoryPool.GetPtrFromKey(key); +} + void Texture::Initialize(Graphics::Controller& graphicsController) { mGraphicsController = &graphicsController; @@ -273,7 +312,7 @@ void Texture::CreateWithData(Graphics::TextureUsageFlags usage, uint8_t* data, u void Texture::Upload(PixelDataPtr pixelData, const Internal::Texture::UploadParams& params) { - DALI_ASSERT_ALWAYS(mNativeImage == nullptr); + DALI_ASSERT_ALWAYS(!mNativeImage); if(!mGraphicsTexture) { @@ -281,14 +320,58 @@ void Texture::Upload(PixelDataPtr pixelData, const Internal::Texture::UploadPara } Graphics::TextureUpdateInfo info{}; + + const uint32_t srcStride = pixelData->GetStride(); + uint32_t srcOffset = 0u; + uint32_t srcSize = pixelData->GetBufferSize(); + + const bool requiredSubPixelData = (!Pixel::IsCompressed(pixelData->GetPixelFormat())) && + ((params.dataXOffset != 0) || + (params.dataYOffset != 0) || + (params.dataWidth != pixelData->GetWidth()) || + (params.dataHeight != pixelData->GetHeight())); + + if(requiredSubPixelData) + { + /** + * TextureUpdateInfo use byte scaled offset / size. + * + * To make we only use sub-data of inputed PixelData, make srcOffset as 'start of SubPixelData. + * + * |---- dataStrideByte -----| + * |-----| <-- dataXOffsetByte + * ........................... + * ......A-----------+........ + * ......| |........ + * ......| |........ + * ......+-----------+C....... + * ......B.................... + * + * A) Start of SubPixelData. offsetByte = dataStrideByte * dataYOffset + dataXOffsetByte. + * B) offsetByte = A).offsetByte + dataStrideByte * dataHeight. Note, It can be out of original PixelData boundary. + * C) End of SubPixelData. offsetByte = B).offsetByte - dataStrideByte + dataWidthByte. + * + * srcOffset = A).offsetByte; + * srcSize = ( C).offsetByte - A).offsetByte ); + */ + const uint32_t bytePerPixel = Pixel::GetBytesPerPixel(pixelData->GetPixelFormat()); + const uint32_t dataStrideByte = (srcStride ? srcStride : static_cast(params.dataWidth)) * bytePerPixel; + const uint32_t dataXOffsetByte = params.dataXOffset * bytePerPixel; + const uint32_t dataWidthByte = static_cast(params.dataWidth) * bytePerPixel; + + srcOffset = params.dataYOffset * dataStrideByte + dataXOffsetByte; + srcSize = static_cast(params.dataHeight) * dataStrideByte - (dataStrideByte - dataWidthByte); + } + info.dstTexture = mGraphicsTexture.get(); info.dstOffset2D = {params.xOffset, params.yOffset}; info.layer = params.layer; info.level = params.mipmap; info.srcReference = 0; - info.srcExtent2D = {params.width, params.height}; - info.srcOffset = 0; - info.srcSize = pixelData->GetBufferSize(); + info.srcExtent2D = {params.dataWidth, params.dataHeight}; + info.srcOffset = srcOffset; + info.srcSize = srcSize; + info.srcStride = srcStride; info.srcFormat = ConvertPixelFormat(pixelData->GetPixelFormat()); Graphics::TextureUpdateSourceInfo updateSourceInfo{}; @@ -296,6 +379,8 @@ void Texture::Upload(PixelDataPtr pixelData, const Internal::Texture::UploadPara updateSourceInfo.memorySource.memory = pixelData->GetBuffer(); mGraphicsController->UpdateTextures({info}, {updateSourceInfo}); + + SetUpdated(true); } bool Texture::HasAlphaChannel() const @@ -318,6 +403,11 @@ void Texture::GenerateMipmaps() mGraphicsController->GenerateTextureMipmaps(*mGraphicsTexture.get()); } +void Texture::OnRenderFinished() +{ + SetUpdated(false); +} + } // namespace Render } // namespace Internal