From 1aff17d33fb52d32156a83a913de8f175c63d340 Mon Sep 17 00:00:00 2001 From: David Steele Date: Fri, 24 Mar 2023 12:51:01 +0000 Subject: [PATCH] Fixed auto-conversion of RGB source images into RGBA textures Added test case for this conversion, and updated some other tests to cover more of the graphics backend. Change-Id: I372cad38eeaf5d685a7e48801ad848b67b347364 --- automated-tests/src/dali-graphics/CMakeLists.txt | 13 +--- .../dali-graphics/utc-Dali-GraphicsFramebuffer.cpp | 55 ++++++++------ .../src/dali-graphics/utc-Dali-GraphicsTexture.cpp | 85 ++++++++++++++++++++++ .../graphics/gles-impl/egl-graphics-controller.cpp | 2 +- 4 files changed, 121 insertions(+), 34 deletions(-) create mode 100644 automated-tests/src/dali-graphics/utc-Dali-GraphicsTexture.cpp diff --git a/automated-tests/src/dali-graphics/CMakeLists.txt b/automated-tests/src/dali-graphics/CMakeLists.txt index 4f9d368..329f8d4 100644 --- a/automated-tests/src/dali-graphics/CMakeLists.txt +++ b/automated-tests/src/dali-graphics/CMakeLists.txt @@ -12,6 +12,7 @@ SET(TC_SOURCES utc-Dali-GraphicsNativeImage.cpp utc-Dali-GraphicsProgram.cpp utc-Dali-GraphicsSampler.cpp + utc-Dali-GraphicsTexture.cpp ) LIST(APPEND TC_SOURCES @@ -21,18 +22,10 @@ LIST(APPEND TC_SOURCES ../dali-adaptor/dali-test-suite-utils/test-actor-utils.cpp ../dali-adaptor/dali-test-suite-utils/test-graphics-application.cpp ../dali-adaptor/dali-test-suite-utils/test-gl-abstraction.cpp + ../dali-adaptor/dali-test-suite-utils/test-graphics-sync-impl.cpp ../dali-adaptor/dali-test-suite-utils/test-graphics-sync-object.cpp - ../dali-adaptor/dali-test-suite-utils/test-graphics-buffer.cpp - ../dali-adaptor/dali-test-suite-utils/test-graphics-command-buffer.cpp - ../dali-adaptor/dali-test-suite-utils/test-graphics-controller.cpp - ../dali-adaptor/dali-test-suite-utils/test-graphics-framebuffer.cpp - ../dali-adaptor/dali-test-suite-utils/test-graphics-texture.cpp - ../dali-adaptor/dali-test-suite-utils/test-graphics-sampler.cpp - ../dali-adaptor/dali-test-suite-utils/test-graphics-pipeline.cpp - ../dali-adaptor/dali-test-suite-utils/test-graphics-reflection.cpp - ../dali-adaptor/dali-test-suite-utils/test-graphics-shader.cpp - ../dali-adaptor/dali-test-suite-utils/test-graphics-program.cpp + ../dali-adaptor/dali-test-suite-utils/test-native-image.cpp ../dali-adaptor/dali-test-suite-utils/test-platform-abstraction.cpp ../dali-adaptor/dali-test-suite-utils/test-render-controller.cpp diff --git a/automated-tests/src/dali-graphics/utc-Dali-GraphicsFramebuffer.cpp b/automated-tests/src/dali-graphics/utc-Dali-GraphicsFramebuffer.cpp index 4ba7f19..733a8ec 100644 --- a/automated-tests/src/dali-graphics/utc-Dali-GraphicsFramebuffer.cpp +++ b/automated-tests/src/dali-graphics/utc-Dali-GraphicsFramebuffer.cpp @@ -1,5 +1,5 @@ /* - * 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. @@ -226,35 +226,44 @@ int UtcDaliGraphicsFramebufferAttachDepthStencilTexture(void) auto& gl = app.GetGlAbstraction(); - uint32_t width = 16u; - uint32_t height = 24u; + { + uint32_t width = 16u; + uint32_t height = 24u; - FrameBuffer framebuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::STENCIL); + FrameBuffer framebuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::STENCIL); - DALI_TEST_CHECK(framebuffer); + DALI_TEST_CHECK(framebuffer); - Texture dummyColorTexture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height); - Texture dummyDepthStencilTexture = CreateTexture(TextureType::TEXTURE_2D, Pixel::DEPTH_STENCIL, width, height); - Actor dummyActor = CreateRenderableActor(dummyColorTexture); - framebuffer.AttachColorTexture(dummyColorTexture); - DevelFrameBuffer::AttachDepthStencilTexture(framebuffer, dummyDepthStencilTexture); + Texture dummyColorTexture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height); + Texture dummyDepthStencilTexture = CreateTexture(TextureType::TEXTURE_2D, Pixel::DEPTH_STENCIL, width, height); + Actor dummyActor = CreateRenderableActor(dummyColorTexture); + framebuffer.AttachColorTexture(dummyColorTexture); + DevelFrameBuffer::AttachDepthStencilTexture(framebuffer, dummyDepthStencilTexture); - app.GetScene().Add(dummyActor); + app.GetScene().Add(dummyActor); - auto renderTask = CreateRenderTask(app, framebuffer); + auto renderTask = CreateRenderTask(app, framebuffer); - DALI_TEST_CHECK(renderTask); + DALI_TEST_CHECK(renderTask); - app.SendNotification(); - app.Render(16); // The above actor will get rendered and drawn once. + app.SendNotification(); + app.Render(16); // The above actor will get rendered and drawn once. - DALI_TEST_EQUALS(gl.CheckFramebufferColorAttachmentCount(), 1u, TEST_LOCATION); - DALI_TEST_EQUALS(gl.CheckFramebufferDepthAttachmentCount(), 1u, TEST_LOCATION); - DALI_TEST_EQUALS(gl.CheckFramebufferStencilAttachmentCount(), 1u, TEST_LOCATION); - DALI_TEST_EQUALS(gl.CheckFramebufferDepthStencilAttachmentCount(), 1u, TEST_LOCATION); - DALI_TEST_EQUALS(gl.CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION); - DALI_TEST_EQUALS(gl.CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION); - DALI_TEST_EQUALS(gl.CheckFramebufferDepthStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION); // Check whether renderbuffer attached by DEPTH_STENCIL. + DALI_TEST_EQUALS(gl.CheckFramebufferColorAttachmentCount(), 1u, TEST_LOCATION); + DALI_TEST_EQUALS(gl.CheckFramebufferDepthAttachmentCount(), 1u, TEST_LOCATION); + DALI_TEST_EQUALS(gl.CheckFramebufferStencilAttachmentCount(), 1u, TEST_LOCATION); + DALI_TEST_EQUALS(gl.CheckFramebufferDepthStencilAttachmentCount(), 1u, TEST_LOCATION); + DALI_TEST_EQUALS(gl.CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION); + DALI_TEST_EQUALS(gl.CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION); + DALI_TEST_EQUALS(gl.CheckFramebufferDepthStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION); // Check whether renderbuffer attached by DEPTH_STENCIL. + + UnparentAndReset(dummyActor); + } + // Ensure some cleanup happens! + app.SendNotification(); + app.Render(16); + app.SendNotification(); + app.Render(16); END_TEST; } @@ -298,4 +307,4 @@ int UtcDaliGraphicsFramebufferAttachStencilAndDepthTexture(void) DALI_TEST_EQUALS(gl.CheckFramebufferDepthStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION); // Check whether renderbuffer attached by DEPTH_STENCIL. END_TEST; -} \ No newline at end of file +} diff --git a/automated-tests/src/dali-graphics/utc-Dali-GraphicsTexture.cpp b/automated-tests/src/dali-graphics/utc-Dali-GraphicsTexture.cpp new file mode 100644 index 0000000..62864ac --- /dev/null +++ b/automated-tests/src/dali-graphics/utc-Dali-GraphicsTexture.cpp @@ -0,0 +1,85 @@ +/* + * 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 +#include + +#include +#include +#include +#include + +using namespace Dali; + +namespace +{ +} // namespace + +void utc_dali_texture_startup(void) +{ + test_return_value = TET_UNDEF; +} +void utc_dali_texture_cleanup(void) +{ + test_return_value = TET_PASS; +} + +int UtcDaliTextureConvertUpload(void) +{ + TestGraphicsApplication app; + tet_infoline("UtcDaliGraphicsConvertUpload - Test that an RGB image is converted to RGBA after upload"); + + auto& gl = app.GetGlAbstraction(); + gl.EnableTextureCallTrace(true); + gl.EnableTexParameterCallTrace(true); + + int size = 200; + Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, size, size); + + int bufferSize = size * size * 3; + uint8_t* buffer = reinterpret_cast(malloc(bufferSize)); + PixelData pixelData = PixelData::New(buffer, bufferSize, size, size, Pixel::RGB888, PixelData::FREE); + texture.Upload(pixelData, 0u, 0u, 0u, 0u, size, size); + + Sampler sampler = Sampler::New(); + sampler.SetFilterMode(FilterMode::LINEAR, FilterMode::LINEAR); + + TextureSet textureSet = TextureSet::New(); + textureSet.SetTexture(0u, texture); + textureSet.SetSampler(0u, sampler); + + Actor dummyActor = CreateRenderableActor2(textureSet, "", ""); + app.GetScene().Add(dummyActor); + + app.SendNotification(); + app.Render(16); + + // Check that TexImage2D was called with right format + auto& textureTrace = gl.GetTextureTrace(); + auto& texParameterTrace = gl.GetTexParameterTrace(); + TraceCallStack::NamedParams namedParams; + DALI_TEST_CHECK(textureTrace.FindMethodAndGetParameters("TexImage2D", namedParams)); + std::stringstream s; + s << std::hex << GL_RGBA; + + DALI_TEST_EQUALS(texParameterTrace.CountMethod("TexParameteri"), 4, TEST_LOCATION); + std::stringstream out; + out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_MIN_FILTER << ", " << GL_LINEAR; + DALI_TEST_EQUALS(texParameterTrace.TestMethodAndParams(0, "TexParameteri", out.str()), true, TEST_LOCATION); + + DALI_TEST_EQUALS(namedParams["format"].str(), s.str(), TEST_LOCATION); + END_TEST; +} diff --git a/dali/internal/graphics/gles-impl/egl-graphics-controller.cpp b/dali/internal/graphics/gles-impl/egl-graphics-controller.cpp index c3026bc..fa90dba 100644 --- a/dali/internal/graphics/gles-impl/egl-graphics-controller.cpp +++ b/dali/internal/graphics/gles-impl/egl-graphics-controller.cpp @@ -717,7 +717,7 @@ void EglGraphicsController::ProcessTextureUpdateQueue() if(mGlAbstraction->TextureRequiresConverting(srcFormat, destFormat, isSubImage)) { // Convert RGB to RGBA if necessary. - if(texture->TryConvertPixelData(source.memorySource.memory, info.srcFormat, createInfo.format, info.srcSize, info.srcStride, info.srcExtent2D.width, info.srcExtent2D.height, tempBuffer)) + if(texture->TryConvertPixelData(sourceBuffer, info.srcFormat, createInfo.format, info.srcSize, info.srcStride, info.srcExtent2D.width, info.srcExtent2D.height, tempBuffer)) { sourceBuffer = &tempBuffer[0]; sourceStride = 0u; // Converted buffer compacted. make stride as 0. -- 2.7.4