From 942dc6d0c221800204c5551b57a0ef88cea2c42d Mon Sep 17 00:00:00 2001 From: Heeyong Song Date: Mon, 27 Jun 2022 18:32:09 +0900 Subject: [PATCH] Add GetPixelFormat to Texture Change-Id: Ib9cf0b03f409c909e7c7187d8ea19661296d36d5 --- automated-tests/src/dali/utc-Dali-Texture.cpp | 21 ++++++++++++++++++++ dali/internal/event/rendering/texture-impl.cpp | 27 +++++++++++++++----------- dali/internal/event/rendering/texture-impl.h | 25 ++++++++++++++---------- dali/public-api/rendering/texture.cpp | 7 ++++++- dali/public-api/rendering/texture.h | 10 +++++++++- 5 files changed, 67 insertions(+), 23 deletions(-) diff --git a/automated-tests/src/dali/utc-Dali-Texture.cpp b/automated-tests/src/dali/utc-Dali-Texture.cpp index 650fd8b..5de38f2 100644 --- a/automated-tests/src/dali/utc-Dali-Texture.cpp +++ b/automated-tests/src/dali/utc-Dali-Texture.cpp @@ -1116,3 +1116,24 @@ int UtcDaliTextureApplyFragShaderN2(void) DALI_TEST_CHECK(!baseFragShader.compare(fragShader)); END_TEST; } + +int UtcDaliTextureGetPixelFormat(void) +{ + TestApplication application; + uint32_t width(64); + uint32_t height(64); + + Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height); + DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION); + + texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGB888, width, height); + DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::RGB888, TEST_LOCATION); + + texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::L8, width, height); + DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::L8, TEST_LOCATION); + + texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::CHROMINANCE_U, width, height); + DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::CHROMINANCE_U, TEST_LOCATION); + + END_TEST; +} diff --git a/dali/internal/event/rendering/texture-impl.cpp b/dali/internal/event/rendering/texture-impl.cpp index 234b934..b6c5cc9 100644 --- a/dali/internal/event/rendering/texture-impl.cpp +++ b/dali/internal/event/rendering/texture-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 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. @@ -27,7 +27,7 @@ namespace Dali { namespace Internal { -TexturePtr Texture::New(TextureType::Type type, Pixel::Format format, unsigned int width, unsigned int height) +TexturePtr Texture::New(TextureType::Type type, Pixel::Format format, uint32_t width, uint32_t height) { constexpr auto max_value = std::numeric_limits::max(); DALI_ASSERT_ALWAYS((width < max_value) && (height < max_value) && "Size out of range"); @@ -104,12 +104,12 @@ bool Texture::Upload(PixelDataPtr pixelData) } bool Texture::Upload(PixelDataPtr pixelData, - unsigned int layer, - unsigned int mipmap, - unsigned int xOffset, - unsigned int yOffset, - unsigned int width, - unsigned int height) + uint32_t layer, + uint32_t mipmap, + uint32_t xOffset, + uint32_t yOffset, + uint32_t width, + uint32_t height) { constexpr auto max_value = std::numeric_limits::max(); DALI_ASSERT_ALWAYS(layer < max_value && @@ -129,7 +129,7 @@ bool Texture::Upload(PixelDataPtr pixelData, } else { - unsigned int pixelDataSize = pixelData->GetWidth() * pixelData->GetHeight(); + uint32_t pixelDataSize = pixelData->GetWidth() * pixelData->GetHeight(); if(pixelData->GetBuffer() == nullptr || pixelDataSize == 0) { DALI_LOG_ERROR("PixelData is empty\n"); @@ -185,16 +185,21 @@ void Texture::GenerateMipmaps() } } -unsigned int Texture::GetWidth() const +uint32_t Texture::GetWidth() const { return mSize.GetWidth(); } -unsigned int Texture::GetHeight() const +uint32_t Texture::GetHeight() const { return mSize.GetHeight(); } +Pixel::Format Texture::GetPixelFormat() const +{ + return mFormat; +} + bool Texture::IsNative() const { return static_cast(mNativeImage); diff --git a/dali/internal/event/rendering/texture-impl.h b/dali/internal/event/rendering/texture-impl.h index 57b098d..84faac6 100644 --- a/dali/internal/event/rendering/texture-impl.h +++ b/dali/internal/event/rendering/texture-impl.h @@ -2,7 +2,7 @@ #define DALI_INTERNAL_NEW_TEXTURE_H /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 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. @@ -65,7 +65,7 @@ public: * @param[in] height The height of the texture * @return A smart-pointer to the newly allocated Texture. */ - static TexturePtr New(TextureType::Type type, Pixel::Format format, unsigned int width, unsigned int height); + static TexturePtr New(TextureType::Type type, Pixel::Format format, uint32_t width, uint32_t height); /** * @brief Creates a new Texture from a native image @@ -90,12 +90,12 @@ public: * @copydoc Dali::Texture::Upload() */ bool Upload(PixelDataPtr pixelData, - unsigned int layer, - unsigned int mipmap, - unsigned int xOffset, - unsigned int yOffset, - unsigned int width, - unsigned int height); + uint32_t layer, + uint32_t mipmap, + uint32_t xOffset, + uint32_t yOffset, + uint32_t width, + uint32_t height); /** * @copydoc Dali::Texture::GenerateMipmaps() @@ -105,12 +105,17 @@ public: /** * @copydoc Dali::Texture::GetWidth() */ - unsigned int GetWidth() const; + uint32_t GetWidth() const; /** * @copydoc Dali::Texture::GetHeight() */ - unsigned int GetHeight() const; + uint32_t GetHeight() const; + + /** + * @copydoc Dali::Texture::GetPixelFormat() + */ + Pixel::Format GetPixelFormat() const; /** * @brief Determine if the texture is a native image diff --git a/dali/public-api/rendering/texture.cpp b/dali/public-api/rendering/texture.cpp index da81783..a8925c7 100644 --- a/dali/public-api/rendering/texture.cpp +++ b/dali/public-api/rendering/texture.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 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. @@ -86,6 +86,11 @@ uint32_t Texture::GetHeight() const return GetImplementation(*this).GetHeight(); } +Pixel::Format Texture::GetPixelFormat() const +{ + return GetImplementation(*this).GetPixelFormat(); +} + Texture::Texture(Internal::Texture* pointer) : BaseHandle(pointer) { diff --git a/dali/public-api/rendering/texture.h b/dali/public-api/rendering/texture.h index 8295868..59e14ce 100644 --- a/dali/public-api/rendering/texture.h +++ b/dali/public-api/rendering/texture.h @@ -2,7 +2,7 @@ #define DALI_TEXTURE_H /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 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. @@ -209,6 +209,14 @@ public: */ uint32_t GetHeight() const; + /** + * @brief Returns the pixel format of the texture. + * + * @SINCE_2_1.29 + * @return The pixel format of the texture + */ + Pixel::Format GetPixelFormat() const; + public: /** * @brief The constructor. -- 2.7.4